misskey/packages/frontend/src/ui/universal.widgets.vue
Acid Chicken (硫酸鶏) 337dd97b49
perf(#10923): CSS Modules のクラス名をインライン化する (#10930)
* perf(#10923): unwind css module class name

* perf(#10923): support multiple components

* refactor: clean up

* refactor(#10923): avoid `useCssModule()`

* fix(#10923): allow direct literal class name

* fix(#10923): avoid computed class name

* fix(#10923): allow literal keys

* fix(#10923): typo

* fix(#10923): invalid class names

* chore: test

* revert: test

This reverts commit 5c7ef366eceebe8ba260efa4d5d675f6c1775c45.

* fix(#10923): hidden tale

* perf(#10923): also unwind scoped css contained components

* perf(#10923): `normalizeClass` AOT compilation

---------

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-06-01 17:19:46 +09:00

77 lines
2.3 KiB
Vue

<template>
<div>
<XWidgets :edit="editMode" :widgets="widgets" @addWidget="addWidget" @removeWidget="removeWidget" @updateWidget="updateWidget" @updateWidgets="updateWidgets" @exit="editMode = false"/>
<button v-if="editMode" class="_textButton" style="font-size: 0.9em;" @click="editMode = false"><i class="ti ti-check"></i> {{ i18n.ts.editWidgetsExit }}</button>
<button v-else class="_textButton" data-cy-widget-edit :class="$style.edit" style="font-size: 0.9em;" @click="editMode = true"><i class="ti ti-pencil"></i> {{ i18n.ts.editWidgets }}</button>
</div>
</template>
<script lang="ts">
let editMode = $ref(false);
</script>
<script lang="ts" setup>
import { } from 'vue';
import XWidgets from '@/components/MkWidgets.vue';
import { i18n } from '@/i18n';
import { defaultStore } from '@/store';
const props = withDefaults(defineProps<{
// null = 全てのウィジェットを表示
// left = place: leftだけを表示
// right = rightとnullを表示
place?: 'left' | null | 'right';
}>(), {
place: null,
});
const widgets = $computed(() => {
if (props.place === null) return defaultStore.reactiveState.widgets.value;
if (props.place === 'left') return defaultStore.reactiveState.widgets.value.filter(w => w.place === 'left');
return defaultStore.reactiveState.widgets.value.filter(w => w.place !== 'left');
});
function addWidget(widget) {
defaultStore.set('widgets', [{
...widget,
place: props.place,
}, ...defaultStore.state.widgets]);
}
function removeWidget(widget) {
defaultStore.set('widgets', defaultStore.state.widgets.filter(w => w.id !== widget.id));
}
function updateWidget({ id, data }) {
defaultStore.set('widgets', defaultStore.state.widgets.map(w => w.id === id ? {
...w,
data,
place: props.place,
} : w));
}
function updateWidgets(thisWidgets) {
if (props.place === null) {
defaultStore.set('widgets', thisWidgets);
return;
}
if (props.place === 'left') {
defaultStore.set('widgets', [
...thisWidgets.map(w => ({ ...w, place: 'left' })),
...defaultStore.state.widgets.filter(w => w.place !== 'left' && !thisWidgets.some(t => w.id === t.id)),
]);
return;
}
defaultStore.set('widgets', [
...defaultStore.state.widgets.filter(w => w.place === 'left' && !thisWidgets.some(t => w.id === t.id)),
...thisWidgets.map(w => ({ ...w, place: 'right' })),
]);
}
</script>
<style lang="scss" module>
.edit {
width: 100%;
}
</style>