2021-04-10 05:40:50 +02:00
|
|
|
<template>
|
2023-05-10 22:20:52 +02:00
|
|
|
<aside class="efzpzdvf" :aria-label="i18n.ts._deck._columns.widgets">
|
2023-04-08 02:01:42 +02:00
|
|
|
<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"
|
|
|
|
/>
|
|
|
|
<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-05-10 22:20:52 +02:00
|
|
|
</aside>
|
2021-04-10 05:40:50 +02:00
|
|
|
</template>
|
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { onMounted } from "vue";
|
|
|
|
import XWidgets from "@/components/MkWidgets.vue";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { defaultStore } from "@/store";
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
const emit = defineEmits<{
|
2023-04-08 02:01:42 +02:00
|
|
|
(ev: "mounted", el: Element): void;
|
2022-03-20 19:11:14 +01:00
|
|
|
}>();
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
let editMode = $ref(false);
|
|
|
|
let rootEl = $ref<HTMLDivElement>();
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
onMounted(() => {
|
2023-04-08 02:01:42 +02:00
|
|
|
emit("mounted", rootEl);
|
2022-03-20 19:11:14 +01:00
|
|
|
});
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
function addWidget(widget) {
|
2023-04-08 02:01:42 +02:00
|
|
|
defaultStore.set("widgets", [
|
|
|
|
{
|
|
|
|
...widget,
|
|
|
|
place: null,
|
|
|
|
},
|
|
|
|
...defaultStore.state.widgets,
|
|
|
|
]);
|
2022-03-20 19:11:14 +01:00
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
function removeWidget(widget) {
|
2023-04-08 02:01:42 +02:00
|
|
|
defaultStore.set(
|
|
|
|
"widgets",
|
|
|
|
defaultStore.state.widgets.filter((w) => w.id !== widget.id)
|
|
|
|
);
|
2022-03-20 19:11:14 +01:00
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
function updateWidget({ id, data }) {
|
2023-04-08 02:01:42 +02:00
|
|
|
defaultStore.set(
|
|
|
|
"widgets",
|
|
|
|
defaultStore.state.widgets.map((w) =>
|
|
|
|
w.id === id
|
|
|
|
? {
|
|
|
|
...w,
|
|
|
|
data,
|
|
|
|
}
|
|
|
|
: w
|
|
|
|
)
|
|
|
|
);
|
2022-03-20 19:11:14 +01:00
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
function updateWidgets(widgets) {
|
2023-04-08 02:01:42 +02:00
|
|
|
defaultStore.set("widgets", widgets);
|
2022-03-20 19:11:14 +01:00
|
|
|
}
|
2021-04-10 05:40:50 +02: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>
|