2021-04-10 06:40:50 +03:00
|
|
|
<template>
|
2022-12-27 07:55:11 +02:00
|
|
|
<div class="efzpzdvf" :class="{ universal: !classic, classic }">
|
|
|
|
<XWidgets :edit="editMode" :widgets="widgets" @add-widget="addWidget" @remove-widget="removeWidget" @update-widget="updateWidget" @update-widgets="updateWidgets" @exit="editMode = false"/>
|
2021-04-10 06:40:50 +03:00
|
|
|
|
2022-12-19 12:01:30 +02:00
|
|
|
<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 mk-widget-edit" style="font-size: 0.9em;" @click="editMode = true"><i class="ti ti-pencil"></i> {{ i18n.ts.editWidgets }}</button>
|
2021-04-10 06:40:50 +03:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-12-27 07:55:11 +02:00
|
|
|
<script lang="ts">
|
|
|
|
let editMode = $ref(false);
|
|
|
|
</script>
|
2022-03-20 20:11:14 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted } from 'vue';
|
2022-08-30 18:24:33 +03:00
|
|
|
import XWidgets from '@/components/MkWidgets.vue';
|
2022-03-20 20:11:14 +02:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { defaultStore } from '@/store';
|
2021-04-10 06:40:50 +03:00
|
|
|
|
2022-12-27 07:55:11 +02:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
// null = 全てのウィジェットを表示
|
|
|
|
// left = place: leftだけを表示
|
|
|
|
// right = rightとnullを表示
|
|
|
|
place?: 'left' | null | 'right';
|
|
|
|
classic?: boolean;
|
|
|
|
}>(), {
|
|
|
|
place: null,
|
|
|
|
classic: false,
|
|
|
|
});
|
|
|
|
|
2022-03-20 20:11:14 +02:00
|
|
|
const emit = defineEmits<{
|
2022-12-27 07:55:11 +02:00
|
|
|
(ev: 'mounted', el?: Element): void;
|
2022-03-20 20:11:14 +02:00
|
|
|
}>();
|
2021-04-10 06:40:50 +03:00
|
|
|
|
2023-01-03 03:12:37 +02:00
|
|
|
let rootEl = $shallowRef<HTMLDivElement>();
|
2021-04-10 06:40:50 +03:00
|
|
|
|
2022-12-27 07:55:11 +02:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2022-03-20 20:11:14 +02:00
|
|
|
onMounted(() => {
|
|
|
|
emit('mounted', rootEl);
|
|
|
|
});
|
2021-04-10 06:40:50 +03:00
|
|
|
|
2022-03-20 20:11:14 +02:00
|
|
|
function addWidget(widget) {
|
|
|
|
defaultStore.set('widgets', [{
|
|
|
|
...widget,
|
2022-12-27 07:55:11 +02:00
|
|
|
place: props.place,
|
2022-03-20 20:11:14 +02:00
|
|
|
}, ...defaultStore.state.widgets]);
|
|
|
|
}
|
2021-04-10 06:40:50 +03:00
|
|
|
|
2022-03-20 20:11:14 +02:00
|
|
|
function removeWidget(widget) {
|
2022-05-26 16:53:09 +03:00
|
|
|
defaultStore.set('widgets', defaultStore.state.widgets.filter(w => w.id !== widget.id));
|
2022-03-20 20:11:14 +02:00
|
|
|
}
|
2021-04-10 06:40:50 +03:00
|
|
|
|
2022-03-20 20:11:14 +02:00
|
|
|
function updateWidget({ id, data }) {
|
|
|
|
defaultStore.set('widgets', defaultStore.state.widgets.map(w => w.id === id ? {
|
|
|
|
...w,
|
2022-05-26 16:53:09 +03:00
|
|
|
data,
|
2022-12-27 07:55:11 +02:00
|
|
|
place: props.place,
|
2022-03-20 20:11:14 +02:00
|
|
|
} : w));
|
|
|
|
}
|
2021-04-10 06:40:50 +03:00
|
|
|
|
2022-12-27 07:55:11 +02:00
|
|
|
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' })),
|
|
|
|
]);
|
2022-03-20 20:11:14 +02:00
|
|
|
}
|
2021-04-10 06:40:50 +03:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 11:29:39 +02:00
|
|
|
<style lang="scss" scoped>
|
2021-04-10 06:40:50 +03:00
|
|
|
.efzpzdvf {
|
|
|
|
position: sticky;
|
|
|
|
height: min-content;
|
|
|
|
min-height: 100vh;
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
2022-12-27 07:55:11 +02:00
|
|
|
&.universal {
|
2022-12-29 02:36:41 +02:00
|
|
|
padding-top: var(--margin);
|
|
|
|
|
2022-12-27 07:55:11 +02:00
|
|
|
> * {
|
|
|
|
margin: var(--margin) 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-10 06:40:50 +03:00
|
|
|
> * {
|
|
|
|
width: 300px;
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .add {
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|