2021-04-09 21:40:50 -06:00
|
|
|
<template>
|
2023-02-24 04:58:45 -07:00
|
|
|
<div class="efzpzdvf">
|
|
|
|
<MkAd class="a" :prefer="['widget']"/>
|
|
|
|
<XWidgets :edit="editMode" :widgets="defaultStore.reactiveState.widgets.value" @add-widget="addWidget" @remove-widget="removeWidget" @update-widget="updateWidget" @update-widgets="updateWidgets" @exit="editMode = false"/>
|
2023-03-11 14:01:04 -07:00
|
|
|
<button v-if="editMode" class="_textButton" style="font-size: 0.9em;" @click="editMode = false"><i class="ph-check ph-bold ph-lg"></i> {{ i18n.ts.editWidgetsExit }}</button>
|
|
|
|
<button v-else class="_textButton mk-widget-edit" style="font-size: 0.9em;" @click="editMode = true"><i class="ph-pencil ph-bold ph-lg"></i> {{ i18n.ts.editWidgets }}</button>
|
2023-02-24 04:58:45 -07:00
|
|
|
</div>
|
2021-04-09 21:40:50 -06:00
|
|
|
</template>
|
|
|
|
|
2022-03-20 12:11:14 -06:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted } from 'vue';
|
2022-08-30 09:24:33 -06:00
|
|
|
import XWidgets from '@/components/MkWidgets.vue';
|
2022-03-20 12:11:14 -06:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { defaultStore } from '@/store';
|
2021-04-09 21:40:50 -06:00
|
|
|
|
2022-03-20 12:11:14 -06:00
|
|
|
const emit = defineEmits<{
|
2022-05-26 07:53:09 -06:00
|
|
|
(ev: 'mounted', el: Element): void;
|
2022-03-20 12:11:14 -06:00
|
|
|
}>();
|
2021-04-09 21:40:50 -06:00
|
|
|
|
2022-03-20 12:11:14 -06:00
|
|
|
let editMode = $ref(false);
|
|
|
|
let rootEl = $ref<HTMLDivElement>();
|
2021-04-09 21:40:50 -06:00
|
|
|
|
2022-03-20 12:11:14 -06:00
|
|
|
onMounted(() => {
|
|
|
|
emit('mounted', rootEl);
|
|
|
|
});
|
2021-04-09 21:40:50 -06:00
|
|
|
|
2022-03-20 12:11:14 -06:00
|
|
|
function addWidget(widget) {
|
|
|
|
defaultStore.set('widgets', [{
|
|
|
|
...widget,
|
|
|
|
place: null,
|
|
|
|
}, ...defaultStore.state.widgets]);
|
|
|
|
}
|
2021-04-09 21:40:50 -06:00
|
|
|
|
2022-03-20 12:11:14 -06:00
|
|
|
function removeWidget(widget) {
|
2022-05-26 07:53:09 -06:00
|
|
|
defaultStore.set('widgets', defaultStore.state.widgets.filter(w => w.id !== widget.id));
|
2022-03-20 12:11:14 -06:00
|
|
|
}
|
2021-04-09 21:40:50 -06:00
|
|
|
|
2022-03-20 12:11:14 -06:00
|
|
|
function updateWidget({ id, data }) {
|
|
|
|
defaultStore.set('widgets', defaultStore.state.widgets.map(w => w.id === id ? {
|
|
|
|
...w,
|
2022-05-26 07:53:09 -06:00
|
|
|
data,
|
2022-03-20 12:11:14 -06:00
|
|
|
} : w));
|
|
|
|
}
|
2021-04-09 21:40:50 -06:00
|
|
|
|
2022-03-20 12:11:14 -06:00
|
|
|
function updateWidgets(widgets) {
|
|
|
|
defaultStore.set('widgets', widgets);
|
|
|
|
}
|
2021-04-09 21:40:50 -06:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.efzpzdvf {
|
|
|
|
position: sticky;
|
|
|
|
height: min-content;
|
|
|
|
min-height: 100vh;
|
|
|
|
padding: var(--margin) 0;
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
|
|
> * {
|
|
|
|
margin: var(--margin) 0;
|
|
|
|
width: 300px;
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .add {
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|