@dou-ui/dashboard 0.1.0-alpha.2 → 0.1.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chart/chart-settings.js.map +1 -1
- package/dist/chart/chart-settings.vue_vue_type_script_setup_true_lang.js +10 -8
- package/dist/chart/chart-settings.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/chart/chart.js.map +1 -1
- package/dist/chart/chart.vue_vue_type_script_setup_true_lang.js +19 -15
- package/dist/chart/chart.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/chart/read-props.js +26 -0
- package/dist/chart/read-props.js.map +1 -0
- package/dist/collaboration/index.js +151 -7
- package/dist/collaboration/index.js.map +1 -1
- package/dist/core/document.js +10 -1
- package/dist/core/document.js.map +1 -1
- package/dist/core/history.js +23 -0
- package/dist/core/history.js.map +1 -1
- package/dist/core/transaction.js +14 -5
- package/dist/core/transaction.js.map +1 -1
- package/dist/dashboard/comment-button.js +6 -0
- package/dist/dashboard/comment-button.js.map +1 -0
- package/dist/dashboard/comment-button.vue_vue_type_script_setup_true_lang.js +59 -0
- package/dist/dashboard/comment-button.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/dashboard/comment-card.js +6 -0
- package/dist/dashboard/comment-card.js.map +1 -0
- package/dist/dashboard/comment-card.vue_vue_type_script_setup_true_lang.js +128 -0
- package/dist/dashboard/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/dashboard/comments.js +144 -0
- package/dist/dashboard/comments.js.map +1 -0
- package/dist/dashboard/dashboard.js.map +1 -1
- package/dist/dashboard/dashboard.vue_vue_type_script_setup_true_lang.js +132 -20
- package/dist/dashboard/dashboard.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/dashboard/error-boundary.js +64 -0
- package/dist/dashboard/error-boundary.js.map +1 -0
- package/dist/dashboard/frame-context.js.map +1 -1
- package/dist/dashboard/widget-body.js.map +1 -1
- package/dist/dashboard/widget-body.vue_vue_type_script_setup_true_lang.js +53 -12
- package/dist/dashboard/widget-body.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/dashboard/widget-frame.js.map +1 -1
- package/dist/dashboard/widget-frame.vue_vue_type_script_setup_true_lang.js +20 -10
- package/dist/dashboard/widget-frame.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/dashboard/widget-settings.js.map +1 -1
- package/dist/dashboard/widget-settings.vue_vue_type_script_setup_true_lang.js +31 -5
- package/dist/dashboard/widget-settings.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/locale.js +12 -0
- package/dist/locale.js.map +1 -1
- package/dist/pivot/pivot-settings.js.map +1 -1
- package/dist/pivot/pivot-settings.vue_vue_type_script_setup_true_lang.js +6 -4
- package/dist/pivot/pivot-settings.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/pivot/pivot.js.map +1 -1
- package/dist/pivot/pivot.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/pivot/pivot.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/pivot/read-props.js +44 -0
- package/dist/pivot/read-props.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/style.js +2 -4
- package/dist/types/chart/read-props.d.ts +3 -0
- package/dist/types/collaboration/index.d.ts +22 -1
- package/dist/types/core/document.d.ts +3 -2
- package/dist/types/core/history.d.ts +7 -1
- package/dist/types/core/transaction.d.ts +11 -2
- package/dist/types/core/types.d.ts +5 -0
- package/dist/types/dashboard/comment-button.vue.d.ts +15 -0
- package/dist/types/dashboard/comment-card.vue.d.ts +13 -0
- package/dist/types/dashboard/comments.d.ts +44 -0
- package/dist/types/dashboard/dashboard.vue.d.ts +12 -0
- package/dist/types/dashboard/error-boundary.d.ts +12 -0
- package/dist/types/dashboard/frame-context.d.ts +4 -0
- package/dist/types/dashboard/types.d.ts +47 -0
- package/dist/types/dashboard/widget-body.vue.d.ts +2 -0
- package/dist/types/dashboard/widget-settings.vue.d.ts +4 -0
- package/dist/types/index.d.ts +22 -1
- package/dist/types/locale.d.ts +8 -0
- package/dist/types/pivot/read-props.d.ts +3 -0
- package/dist/types/widgets/index.d.ts +1 -1
- package/dist/types/widgets/read-props.d.ts +4 -0
- package/dist/types/widgets/shared.d.ts +20 -4
- package/dist/widgets/index.js +2 -2
- package/dist/widgets/index.js.map +1 -1
- package/dist/widgets/read-props.js +52 -0
- package/dist/widgets/read-props.js.map +1 -0
- package/dist/widgets/shared.js +27 -5
- package/dist/widgets/shared.js.map +1 -1
- package/dist/widgets/stat-settings.js.map +1 -1
- package/dist/widgets/stat-settings.vue_vue_type_script_setup_true_lang.js +12 -10
- package/dist/widgets/stat-settings.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/widgets/stat.js.map +1 -1
- package/dist/widgets/stat.vue_vue_type_script_setup_true_lang.js +10 -13
- package/dist/widgets/stat.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/widgets/table-settings.js.map +1 -1
- package/dist/widgets/table-settings.vue_vue_type_script_setup_true_lang.js +6 -4
- package/dist/widgets/table-settings.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/widgets/table.js.map +1 -1
- package/dist/widgets/table.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/widgets/table.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/widgets/text-settings.js.map +1 -1
- package/dist/widgets/text-settings.vue_vue_type_script_setup_true_lang.js +5 -3
- package/dist/widgets/text-settings.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/widgets/text.js.map +1 -1
- package/dist/widgets/text.vue_vue_type_script_setup_true_lang.js +5 -3
- package/dist/widgets/text.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-settings.js","names":["_sfc_main"],"sources":["../../src/chart/chart-settings.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouInput, DouSegmentedControl, DouSwitch } from 'dou-ui'\nimport { computed } from 'vue'\nimport { useDashboardMessages } from '../locale'\nimport { useDashboardWidget } from '../widget/context'\nimport FieldSelect from '../widgets/field-select.vue'\nimport SettingsField from '../widgets/settings-field.vue'\nimport { fieldsOf, numberFieldsOf, rowsOf } from '../widgets/shared'\nimport SourceField from '../widgets/source-field.vue'\nimport type { ChartWidgetProps } from './types'\n\ndefineOptions({ name: 'DouDashboardChartSettings' })\n\nconst model = defineModel<ChartWidgetProps>({ required: true })\nconst messages = useDashboardMessages()\nconst { data } = useDashboardWidget()\nconst rows = computed(() => rowsOf(data.value,
|
|
1
|
+
{"version":3,"file":"chart-settings.js","names":["_sfc_main"],"sources":["../../src/chart/chart-settings.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouInput, DouSegmentedControl, DouSwitch } from 'dou-ui'\nimport { computed } from 'vue'\nimport { useDashboardMessages } from '../locale'\nimport { useDashboardWidget } from '../widget/context'\nimport FieldSelect from '../widgets/field-select.vue'\nimport SettingsField from '../widgets/settings-field.vue'\nimport { fieldsOf, numberFieldsOf, rowsOf } from '../widgets/shared'\nimport SourceField from '../widgets/source-field.vue'\nimport type { ChartWidgetProps } from './types'\nimport { chartPropsOf } from './read-props'\n\ndefineOptions({ name: 'DouDashboardChartSettings' })\n\nconst model = defineModel<ChartWidgetProps>({ required: true })\n// the props as saved may have the wrong types: read them as the widget does\nconst view = computed(() => chartPropsOf(model.value as Record<string, unknown>))\nconst messages = useDashboardMessages()\nconst { data } = useDashboardWidget()\nconst rows = computed(() => rowsOf(data.value, view.value.path))\nconst set = (patch: Partial<ChartWidgetProps>) => (model.value = { ...model.value, ...patch })\nconst kind = computed(() => view.value.kind ?? 'line')\n</script>\n\n<template>\n <div class=\"dou-dashboard__settings\">\n <SourceField :model-value=\"view.source\" @update:model-value=\"(source) => set({ source })\" />\n <SettingsField :label=\"messages.chartKind\">\n <DouSegmentedControl\n :model-value=\"kind\"\n :options=\"[\n { value: 'line', label: messages.chartLine },\n { value: 'area', label: messages.chartArea },\n { value: 'bar', label: messages.chartBar },\n { value: 'pie', label: messages.chartPie },\n ]\"\n :aria-label=\"messages.chartKind\"\n @update:model-value=\"(value) => set({ kind: value as ChartWidgetProps['kind'] })\"\n />\n </SettingsField>\n <FieldSelect\n :model-value=\"view.x\"\n :label=\"messages.xField\"\n :fields=\"fieldsOf(rows)\"\n @update:model-value=\"(x) => set({ x: x as string | undefined })\"\n />\n <FieldSelect\n :model-value=\"kind === 'pie' ? (view.y ?? []).slice(0, 1) : view.y\"\n :label=\"messages.yFields\"\n :fields=\"numberFieldsOf(rows)\"\n :multiple=\"kind !== 'pie'\"\n @update:model-value=\"\n (y) => set({ y: y === undefined ? undefined : Array.isArray(y) ? y : [y] })\n \"\n />\n <div v-if=\"kind === 'bar' || kind === 'area'\" class=\"dou-dashboard__field-row\">\n <DouSwitch\n :model-value=\"!!view.stacked\"\n @update:model-value=\"(stacked) => set({ stacked: stacked || undefined })\"\n >\n {{ messages.stacked }}\n </DouSwitch>\n <DouSwitch\n v-if=\"kind === 'bar'\"\n :model-value=\"!!view.horizontal\"\n @update:model-value=\"(horizontal) => set({ horizontal: horizontal || undefined })\"\n >\n {{ messages.horizontal }}\n </DouSwitch>\n </div>\n <SettingsField :label=\"messages.chartFilter\" :hint=\"messages.chartFilterHint\">\n <DouInput\n :model-value=\"view.filter ?? ''\"\n :aria-label=\"messages.chartFilter\"\n @update:model-value=\"(key) => set({ filter: key.trim() || undefined })\"\n />\n </SettingsField>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -4,6 +4,7 @@ import { fieldsOf, numberFieldsOf, rowsOf } from "../widgets/shared.js";
|
|
|
4
4
|
import settings_field_default from "../widgets/settings-field.js";
|
|
5
5
|
import field_select_default from "../widgets/field-select.js";
|
|
6
6
|
import source_field_default from "../widgets/source-field.js";
|
|
7
|
+
import { chartPropsOf } from "./read-props.js";
|
|
7
8
|
import { DouInput, DouSegmentedControl, DouSwitch } from "dou-ui";
|
|
8
9
|
import { computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, openBlock, toDisplayString, unref, useModel, withCtx } from "vue";
|
|
9
10
|
// src/chart/chart-settings.vue?vue&type=script&setup=true&lang.ts
|
|
@@ -22,18 +23,19 @@ var chart_settings_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
22
23
|
emits: ["update:modelValue"],
|
|
23
24
|
setup(__props) {
|
|
24
25
|
const model = useModel(__props, "modelValue");
|
|
26
|
+
const view = computed(() => chartPropsOf(model.value));
|
|
25
27
|
const messages = useDashboardMessages();
|
|
26
28
|
const { data } = useDashboardWidget();
|
|
27
|
-
const rows = computed(() => rowsOf(data.value,
|
|
29
|
+
const rows = computed(() => rowsOf(data.value, view.value.path));
|
|
28
30
|
const set = (patch) => model.value = {
|
|
29
31
|
...model.value,
|
|
30
32
|
...patch
|
|
31
33
|
};
|
|
32
|
-
const kind = computed(() =>
|
|
34
|
+
const kind = computed(() => view.value.kind ?? "line");
|
|
33
35
|
return (_ctx, _cache) => {
|
|
34
36
|
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
35
37
|
createVNode(source_field_default, {
|
|
36
|
-
"model-value":
|
|
38
|
+
"model-value": view.value.source,
|
|
37
39
|
"onUpdate:modelValue": _cache[0] || (_cache[0] = (source) => set({ source }))
|
|
38
40
|
}, null, 8, ["model-value"]),
|
|
39
41
|
createVNode(settings_field_default, { label: unref(messages).chartKind }, {
|
|
@@ -67,7 +69,7 @@ var chart_settings_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
67
69
|
_: 1
|
|
68
70
|
}, 8, ["label"]),
|
|
69
71
|
createVNode(field_select_default, {
|
|
70
|
-
"model-value":
|
|
72
|
+
"model-value": view.value.x,
|
|
71
73
|
label: unref(messages).xField,
|
|
72
74
|
fields: unref(fieldsOf)(rows.value),
|
|
73
75
|
"onUpdate:modelValue": _cache[2] || (_cache[2] = (x) => set({ x }))
|
|
@@ -77,7 +79,7 @@ var chart_settings_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
77
79
|
"fields"
|
|
78
80
|
]),
|
|
79
81
|
createVNode(field_select_default, {
|
|
80
|
-
"model-value": kind.value === "pie" ? (
|
|
82
|
+
"model-value": kind.value === "pie" ? (view.value.y ?? []).slice(0, 1) : view.value.y,
|
|
81
83
|
label: unref(messages).yFields,
|
|
82
84
|
fields: unref(numberFieldsOf)(rows.value),
|
|
83
85
|
multiple: kind.value !== "pie",
|
|
@@ -89,14 +91,14 @@ var chart_settings_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
89
91
|
"multiple"
|
|
90
92
|
]),
|
|
91
93
|
kind.value === "bar" || kind.value === "area" ? (openBlock(), createElementBlock("div", _hoisted_2, [createVNode(unref(DouSwitch), {
|
|
92
|
-
"model-value": !!
|
|
94
|
+
"model-value": !!view.value.stacked,
|
|
93
95
|
"onUpdate:modelValue": _cache[4] || (_cache[4] = (stacked) => set({ stacked: stacked || void 0 }))
|
|
94
96
|
}, {
|
|
95
97
|
default: withCtx(() => [createTextVNode(toDisplayString(unref(messages).stacked), 1)]),
|
|
96
98
|
_: 1
|
|
97
99
|
}, 8, ["model-value"]), kind.value === "bar" ? (openBlock(), createBlock(unref(DouSwitch), {
|
|
98
100
|
key: 0,
|
|
99
|
-
"model-value": !!
|
|
101
|
+
"model-value": !!view.value.horizontal,
|
|
100
102
|
"onUpdate:modelValue": _cache[5] || (_cache[5] = (horizontal) => set({ horizontal: horizontal || void 0 }))
|
|
101
103
|
}, {
|
|
102
104
|
default: withCtx(() => [createTextVNode(toDisplayString(unref(messages).horizontal), 1)]),
|
|
@@ -107,7 +109,7 @@ var chart_settings_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
107
109
|
hint: unref(messages).chartFilterHint
|
|
108
110
|
}, {
|
|
109
111
|
default: withCtx(() => [createVNode(unref(DouInput), {
|
|
110
|
-
"model-value":
|
|
112
|
+
"model-value": view.value.filter ?? "",
|
|
111
113
|
"aria-label": unref(messages).chartFilter,
|
|
112
114
|
"onUpdate:modelValue": _cache[6] || (_cache[6] = (key) => set({ filter: key.trim() || void 0 }))
|
|
113
115
|
}, null, 8, ["model-value", "aria-label"])]),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-settings.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_openBlock","_createElementBlock","_createVNode","SourceField","SettingsField","_unref","_withCtx","FieldSelect","_createTextVNode","_toDisplayString","_createBlock","_createCommentVNode"],"sources":["../../src/chart/chart-settings.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouInput, DouSegmentedControl, DouSwitch } from 'dou-ui'\nimport { computed } from 'vue'\nimport { useDashboardMessages } from '../locale'\nimport { useDashboardWidget } from '../widget/context'\nimport FieldSelect from '../widgets/field-select.vue'\nimport SettingsField from '../widgets/settings-field.vue'\nimport { fieldsOf, numberFieldsOf, rowsOf } from '../widgets/shared'\nimport SourceField from '../widgets/source-field.vue'\nimport type { ChartWidgetProps } from './types'\n\ndefineOptions({ name: 'DouDashboardChartSettings' })\n\nconst model = defineModel<ChartWidgetProps>({ required: true })\nconst messages = useDashboardMessages()\nconst { data } = useDashboardWidget()\nconst rows = computed(() => rowsOf(data.value,
|
|
1
|
+
{"version":3,"file":"chart-settings.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_openBlock","_createElementBlock","_createVNode","SourceField","SettingsField","_unref","_withCtx","FieldSelect","_createTextVNode","_toDisplayString","_createBlock","_createCommentVNode"],"sources":["../../src/chart/chart-settings.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouInput, DouSegmentedControl, DouSwitch } from 'dou-ui'\nimport { computed } from 'vue'\nimport { useDashboardMessages } from '../locale'\nimport { useDashboardWidget } from '../widget/context'\nimport FieldSelect from '../widgets/field-select.vue'\nimport SettingsField from '../widgets/settings-field.vue'\nimport { fieldsOf, numberFieldsOf, rowsOf } from '../widgets/shared'\nimport SourceField from '../widgets/source-field.vue'\nimport type { ChartWidgetProps } from './types'\nimport { chartPropsOf } from './read-props'\n\ndefineOptions({ name: 'DouDashboardChartSettings' })\n\nconst model = defineModel<ChartWidgetProps>({ required: true })\n// the props as saved may have the wrong types: read them as the widget does\nconst view = computed(() => chartPropsOf(model.value as Record<string, unknown>))\nconst messages = useDashboardMessages()\nconst { data } = useDashboardWidget()\nconst rows = computed(() => rowsOf(data.value, view.value.path))\nconst set = (patch: Partial<ChartWidgetProps>) => (model.value = { ...model.value, ...patch })\nconst kind = computed(() => view.value.kind ?? 'line')\n</script>\n\n<template>\n <div class=\"dou-dashboard__settings\">\n <SourceField :model-value=\"view.source\" @update:model-value=\"(source) => set({ source })\" />\n <SettingsField :label=\"messages.chartKind\">\n <DouSegmentedControl\n :model-value=\"kind\"\n :options=\"[\n { value: 'line', label: messages.chartLine },\n { value: 'area', label: messages.chartArea },\n { value: 'bar', label: messages.chartBar },\n { value: 'pie', label: messages.chartPie },\n ]\"\n :aria-label=\"messages.chartKind\"\n @update:model-value=\"(value) => set({ kind: value as ChartWidgetProps['kind'] })\"\n />\n </SettingsField>\n <FieldSelect\n :model-value=\"view.x\"\n :label=\"messages.xField\"\n :fields=\"fieldsOf(rows)\"\n @update:model-value=\"(x) => set({ x: x as string | undefined })\"\n />\n <FieldSelect\n :model-value=\"kind === 'pie' ? (view.y ?? []).slice(0, 1) : view.y\"\n :label=\"messages.yFields\"\n :fields=\"numberFieldsOf(rows)\"\n :multiple=\"kind !== 'pie'\"\n @update:model-value=\"\n (y) => set({ y: y === undefined ? undefined : Array.isArray(y) ? y : [y] })\n \"\n />\n <div v-if=\"kind === 'bar' || kind === 'area'\" class=\"dou-dashboard__field-row\">\n <DouSwitch\n :model-value=\"!!view.stacked\"\n @update:model-value=\"(stacked) => set({ stacked: stacked || undefined })\"\n >\n {{ messages.stacked }}\n </DouSwitch>\n <DouSwitch\n v-if=\"kind === 'bar'\"\n :model-value=\"!!view.horizontal\"\n @update:model-value=\"(horizontal) => set({ horizontal: horizontal || undefined })\"\n >\n {{ messages.horizontal }}\n </DouSwitch>\n </div>\n <SettingsField :label=\"messages.chartFilter\" :hint=\"messages.chartFilterHint\">\n <DouInput\n :model-value=\"view.filter ?? ''\"\n :aria-label=\"messages.chartFilter\"\n @update:model-value=\"(key) => set({ filter: key.trim() || undefined })\"\n />\n </SettingsField>\n </div>\n</template>\n"],"mappings":"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"}
|
package/dist/chart/chart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart.js","names":["_sfc_main"],"sources":["../../src/chart/chart.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n DouChart,\n DouChartArea,\n DouChartBar,\n DouChartLine,\n DouChartPie,\n DouChartTooltip,\n} from '@dou-ui/chart'\nimport type { ChartPointEvent } from '@dou-ui/chart'\nimport { computed, watch } from 'vue'\nimport { useDashboardWidget } from '../widget/context'\nimport { filterValueOf, rowsOf, rowsToWorkbook } from '../widgets/shared'\nimport
|
|
1
|
+
{"version":3,"file":"chart.js","names":["_sfc_main"],"sources":["../../src/chart/chart.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n DouChart,\n DouChartArea,\n DouChartBar,\n DouChartLine,\n DouChartPie,\n DouChartTooltip,\n} from '@dou-ui/chart'\nimport type { ChartPointEvent } from '@dou-ui/chart'\nimport { computed, watch } from 'vue'\nimport { useDashboardWidget } from '../widget/context'\nimport { filterValueOf, rowsOf, rowsToWorkbook } from '../widgets/shared'\nimport { chartPropsOf } from './read-props'\n\ndefineOptions({ name: 'DouDashboardChartWidget' })\n\nconst { props: raw, data, size, setFilter, ownFilters, widget, setWorkbook } = useDashboardWidget()\nconst props = computed(() => chartPropsOf(raw.value))\nconst rows = computed(() => rowsOf(data.value, props.value.path))\nconst kind = computed(() => props.value.kind ?? 'line')\nconst ys = computed(() => props.value.y ?? [])\nconst x = computed(() => props.value.x)\nconst filter = computed(() => props.value.filter)\nconst nameOf = (key: string) => props.value.labels?.[key] ?? key\n/** The x this widget filters by, if any: the other bars fade. */\nconst picked = computed(() => (filter.value ? ownFilters.value[filter.value] : undefined))\n/** Bars other than the picked one turn gray; a new function when the pick changes, so they draw again. */\nconst barColor = computed(() => {\n const value = picked.value\n const field = x.value ?? ''\n if (!filter.value || value === undefined) return undefined\n return (row: Record<string, unknown>) =>\n filterValueOf(row[field]) === value ? undefined : 'var(--dou-color-border-strong)'\n})\n\n// the export menu writes the chart's data: a column for x, one for each series;\n// a chart without its fields has no menu\nconst seriesKeys = computed(() => (kind.value === 'pie' ? ys.value.slice(0, 1) : ys.value))\nconst exportable = computed(() => !!x.value && seriesKeys.value.length > 0)\nwatch(\n exportable,\n (ok) =>\n setWorkbook(\n ok\n ? () => {\n const field = x.value!\n return rowsToWorkbook(\n '',\n [\n { key: field, title: nameOf(field) },\n ...seriesKeys.value.map((key) => ({ key, title: nameOf(key) })),\n ],\n rows.value,\n )\n }\n : null,\n ),\n { immediate: true },\n)\n\nfunction onSelect(event: ChartPointEvent) {\n const key = filter.value\n if (!key) return\n const value = filterValueOf(event.x)\n if (value === picked.value) setFilter(key, undefined)\n else setFilter(key, value, { label: event.title ?? String(value) })\n}\n</script>\n\n<template>\n <DouChart\n class=\"dou-dashboard-chart\"\n :data=\"rows\"\n :x=\"x\"\n :height=\"size.height.value || 160\"\n :horizontal=\"kind === 'bar' && props.horizontal\"\n :legend=\"kind === 'pie' || ys.length > 1\"\n :aria-label=\"widget.title\"\n v-on=\"filter ? { select: onSelect } : {}\"\n >\n <DouChartPie\n v-if=\"kind === 'pie'\"\n :value=\"ys[0] ?? ''\"\n :name=\"ys[0] ? nameOf(ys[0]) : undefined\"\n :inner-radius=\"0.6\"\n />\n <template v-else>\n <template v-for=\"y in ys\" :key=\"y\">\n <DouChartBar\n v-if=\"kind === 'bar'\"\n :y=\"y\"\n :name=\"nameOf(y)\"\n :stack=\"props.stacked || undefined\"\n :color=\"barColor\"\n />\n <DouChartArea\n v-else-if=\"kind === 'area'\"\n :y=\"y\"\n :name=\"nameOf(y)\"\n :stack=\"props.stacked || undefined\"\n />\n <DouChartLine v-else :y=\"y\" :name=\"nameOf(y)\" />\n </template>\n </template>\n <DouChartTooltip />\n </DouChart>\n</template>\n"],"mappings":""}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useDashboardWidget } from "../widget/context.js";
|
|
2
2
|
import { filterValueOf, rowsOf, rowsToWorkbook } from "../widgets/shared.js";
|
|
3
|
+
import { chartPropsOf } from "./read-props.js";
|
|
3
4
|
import { Fragment, computed, createBlock, createElementBlock, createVNode, defineComponent, mergeProps, openBlock, renderList, toHandlers, unref, watch, withCtx } from "vue";
|
|
4
5
|
import { DouChart, DouChartArea, DouChartBar, DouChartLine, DouChartPie, DouChartTooltip } from "@dou-ui/chart";
|
|
5
6
|
// src/chart/chart.vue?vue&type=script&setup=true&lang.ts
|
|
@@ -7,34 +8,37 @@ var chart_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComp
|
|
|
7
8
|
name: "DouDashboardChartWidget",
|
|
8
9
|
__name: "chart",
|
|
9
10
|
setup(__props) {
|
|
10
|
-
const { props, data, size, setFilter, ownFilters, widget, setWorkbook } = useDashboardWidget();
|
|
11
|
+
const { props: raw, data, size, setFilter, ownFilters, widget, setWorkbook } = useDashboardWidget();
|
|
12
|
+
const props = computed(() => chartPropsOf(raw.value));
|
|
11
13
|
const rows = computed(() => rowsOf(data.value, props.value.path));
|
|
12
14
|
const kind = computed(() => props.value.kind ?? "line");
|
|
13
15
|
const ys = computed(() => props.value.y ?? []);
|
|
16
|
+
const x = computed(() => props.value.x);
|
|
17
|
+
const filter = computed(() => props.value.filter);
|
|
14
18
|
const nameOf = (key) => props.value.labels?.[key] ?? key;
|
|
15
19
|
/** The x this widget filters by, if any: the other bars fade. */
|
|
16
|
-
const picked = computed(() =>
|
|
20
|
+
const picked = computed(() => filter.value ? ownFilters.value[filter.value] : void 0);
|
|
17
21
|
/** Bars other than the picked one turn gray; a new function when the pick changes, so they draw again. */
|
|
18
22
|
const barColor = computed(() => {
|
|
19
23
|
const value = picked.value;
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
return (row) => filterValueOf(row[
|
|
24
|
+
const field = x.value ?? "";
|
|
25
|
+
if (!filter.value || value === void 0) return void 0;
|
|
26
|
+
return (row) => filterValueOf(row[field]) === value ? void 0 : "var(--dou-color-border-strong)";
|
|
23
27
|
});
|
|
24
28
|
const seriesKeys = computed(() => kind.value === "pie" ? ys.value.slice(0, 1) : ys.value);
|
|
25
|
-
const exportable = computed(() => !!
|
|
29
|
+
const exportable = computed(() => !!x.value && seriesKeys.value.length > 0);
|
|
26
30
|
watch(exportable, (ok) => setWorkbook(ok ? () => {
|
|
27
|
-
const
|
|
31
|
+
const field = x.value;
|
|
28
32
|
return rowsToWorkbook("", [{
|
|
29
|
-
key:
|
|
30
|
-
title: nameOf(
|
|
33
|
+
key: field,
|
|
34
|
+
title: nameOf(field)
|
|
31
35
|
}, ...seriesKeys.value.map((key) => ({
|
|
32
36
|
key,
|
|
33
37
|
title: nameOf(key)
|
|
34
38
|
}))], rows.value);
|
|
35
39
|
} : null), { immediate: true });
|
|
36
40
|
function onSelect(event) {
|
|
37
|
-
const key =
|
|
41
|
+
const key = filter.value;
|
|
38
42
|
if (!key) return;
|
|
39
43
|
const value = filterValueOf(event.x);
|
|
40
44
|
if (value === picked.value) setFilter(key, void 0);
|
|
@@ -44,12 +48,12 @@ var chart_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComp
|
|
|
44
48
|
return openBlock(), createBlock(unref(DouChart), mergeProps({
|
|
45
49
|
class: "dou-dashboard-chart",
|
|
46
50
|
data: rows.value,
|
|
47
|
-
x:
|
|
51
|
+
x: x.value,
|
|
48
52
|
height: unref(size).height.value || 160,
|
|
49
|
-
horizontal: kind.value === "bar" &&
|
|
53
|
+
horizontal: kind.value === "bar" && props.value.horizontal,
|
|
50
54
|
legend: kind.value === "pie" || ys.value.length > 1,
|
|
51
55
|
"aria-label": unref(widget).title
|
|
52
|
-
}, toHandlers(
|
|
56
|
+
}, toHandlers(filter.value ? { select: onSelect } : {})), {
|
|
53
57
|
default: withCtx(() => [kind.value === "pie" ? (openBlock(), createBlock(unref(DouChartPie), {
|
|
54
58
|
key: 0,
|
|
55
59
|
value: ys.value[0] ?? "",
|
|
@@ -60,7 +64,7 @@ var chart_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComp
|
|
|
60
64
|
key: 0,
|
|
61
65
|
y,
|
|
62
66
|
name: nameOf(y),
|
|
63
|
-
stack:
|
|
67
|
+
stack: props.value.stacked || void 0,
|
|
64
68
|
color: barColor.value
|
|
65
69
|
}, null, 8, [
|
|
66
70
|
"y",
|
|
@@ -71,7 +75,7 @@ var chart_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComp
|
|
|
71
75
|
key: 1,
|
|
72
76
|
y,
|
|
73
77
|
name: nameOf(y),
|
|
74
|
-
stack:
|
|
78
|
+
stack: props.value.stacked || void 0
|
|
75
79
|
}, null, 8, [
|
|
76
80
|
"y",
|
|
77
81
|
"name",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","_mergeProps","_toHandlers","_withCtx","_createElementBlock","_Fragment","_renderList","_createVNode"],"sources":["../../src/chart/chart.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n DouChart,\n DouChartArea,\n DouChartBar,\n DouChartLine,\n DouChartPie,\n DouChartTooltip,\n} from '@dou-ui/chart'\nimport type { ChartPointEvent } from '@dou-ui/chart'\nimport { computed, watch } from 'vue'\nimport { useDashboardWidget } from '../widget/context'\nimport { filterValueOf, rowsOf, rowsToWorkbook } from '../widgets/shared'\nimport
|
|
1
|
+
{"version":3,"file":"chart.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","_mergeProps","_toHandlers","_withCtx","_createElementBlock","_Fragment","_renderList","_createVNode"],"sources":["../../src/chart/chart.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n DouChart,\n DouChartArea,\n DouChartBar,\n DouChartLine,\n DouChartPie,\n DouChartTooltip,\n} from '@dou-ui/chart'\nimport type { ChartPointEvent } from '@dou-ui/chart'\nimport { computed, watch } from 'vue'\nimport { useDashboardWidget } from '../widget/context'\nimport { filterValueOf, rowsOf, rowsToWorkbook } from '../widgets/shared'\nimport { chartPropsOf } from './read-props'\n\ndefineOptions({ name: 'DouDashboardChartWidget' })\n\nconst { props: raw, data, size, setFilter, ownFilters, widget, setWorkbook } = useDashboardWidget()\nconst props = computed(() => chartPropsOf(raw.value))\nconst rows = computed(() => rowsOf(data.value, props.value.path))\nconst kind = computed(() => props.value.kind ?? 'line')\nconst ys = computed(() => props.value.y ?? [])\nconst x = computed(() => props.value.x)\nconst filter = computed(() => props.value.filter)\nconst nameOf = (key: string) => props.value.labels?.[key] ?? key\n/** The x this widget filters by, if any: the other bars fade. */\nconst picked = computed(() => (filter.value ? ownFilters.value[filter.value] : undefined))\n/** Bars other than the picked one turn gray; a new function when the pick changes, so they draw again. */\nconst barColor = computed(() => {\n const value = picked.value\n const field = x.value ?? ''\n if (!filter.value || value === undefined) return undefined\n return (row: Record<string, unknown>) =>\n filterValueOf(row[field]) === value ? undefined : 'var(--dou-color-border-strong)'\n})\n\n// the export menu writes the chart's data: a column for x, one for each series;\n// a chart without its fields has no menu\nconst seriesKeys = computed(() => (kind.value === 'pie' ? ys.value.slice(0, 1) : ys.value))\nconst exportable = computed(() => !!x.value && seriesKeys.value.length > 0)\nwatch(\n exportable,\n (ok) =>\n setWorkbook(\n ok\n ? () => {\n const field = x.value!\n return rowsToWorkbook(\n '',\n [\n { key: field, title: nameOf(field) },\n ...seriesKeys.value.map((key) => ({ key, title: nameOf(key) })),\n ],\n rows.value,\n )\n }\n : null,\n ),\n { immediate: true },\n)\n\nfunction onSelect(event: ChartPointEvent) {\n const key = filter.value\n if (!key) return\n const value = filterValueOf(event.x)\n if (value === picked.value) setFilter(key, undefined)\n else setFilter(key, value, { label: event.title ?? String(value) })\n}\n</script>\n\n<template>\n <DouChart\n class=\"dou-dashboard-chart\"\n :data=\"rows\"\n :x=\"x\"\n :height=\"size.height.value || 160\"\n :horizontal=\"kind === 'bar' && props.horizontal\"\n :legend=\"kind === 'pie' || ys.length > 1\"\n :aria-label=\"widget.title\"\n v-on=\"filter ? { select: onSelect } : {}\"\n >\n <DouChartPie\n v-if=\"kind === 'pie'\"\n :value=\"ys[0] ?? ''\"\n :name=\"ys[0] ? nameOf(ys[0]) : undefined\"\n :inner-radius=\"0.6\"\n />\n <template v-else>\n <template v-for=\"y in ys\" :key=\"y\">\n <DouChartBar\n v-if=\"kind === 'bar'\"\n :y=\"y\"\n :name=\"nameOf(y)\"\n :stack=\"props.stacked || undefined\"\n :color=\"barColor\"\n />\n <DouChartArea\n v-else-if=\"kind === 'area'\"\n :y=\"y\"\n :name=\"nameOf(y)\"\n :stack=\"props.stacked || undefined\"\n />\n <DouChartLine v-else :y=\"y\" :name=\"nameOf(y)\" />\n </template>\n </template>\n <DouChartTooltip />\n </DouChart>\n</template>\n"],"mappings":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { flagOf, oneOf, recordOf, textOf, textsOf } from "../widgets/shared.js";
|
|
2
|
+
// src/chart/read-props.ts
|
|
3
|
+
/** The chart widget's props as its type says; what isn't the right type counts as not set. */
|
|
4
|
+
function chartPropsOf(props) {
|
|
5
|
+
const labels = {};
|
|
6
|
+
for (const [key, label] of Object.entries(recordOf(props.labels) ?? {})) if (typeof label === "string") labels[key] = label;
|
|
7
|
+
return {
|
|
8
|
+
source: textOf(props.source),
|
|
9
|
+
path: textOf(props.path),
|
|
10
|
+
kind: oneOf(props.kind, [
|
|
11
|
+
"line",
|
|
12
|
+
"area",
|
|
13
|
+
"bar",
|
|
14
|
+
"pie"
|
|
15
|
+
]),
|
|
16
|
+
x: textOf(props.x),
|
|
17
|
+
y: textsOf(props.y),
|
|
18
|
+
labels,
|
|
19
|
+
stacked: flagOf(props.stacked),
|
|
20
|
+
horizontal: flagOf(props.horizontal),
|
|
21
|
+
filter: textOf(props.filter)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export { chartPropsOf };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=read-props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-props.js","names":[],"sources":["../../src/chart/read-props.ts"],"sourcesContent":["import { flagOf, oneOf, recordOf, textOf, textsOf } from '../widgets/shared'\nimport type { ChartWidgetProps } from './types'\n\n/** The chart widget's props as its type says; what isn't the right type counts as not set. */\nexport function chartPropsOf(props: Record<string, unknown>): ChartWidgetProps {\n const labels: Record<string, string> = {}\n for (const [key, label] of Object.entries(recordOf(props.labels) ?? {}))\n if (typeof label === 'string') labels[key] = label\n return {\n source: textOf(props.source),\n path: textOf(props.path),\n kind: oneOf(props.kind, ['line', 'area', 'bar', 'pie'] as const),\n x: textOf(props.x),\n y: textsOf(props.y),\n labels,\n stacked: flagOf(props.stacked),\n horizontal: flagOf(props.horizontal),\n filter: textOf(props.filter),\n }\n}\n"],"mappings":";;;AAIA,SAAgB,aAAa,OAAkD;CAC7E,MAAM,SAAiC,CAAC;CACxC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,MAAM,MAAM,KAAK,CAAC,CAAC,GACpE,IAAI,OAAO,UAAU,UAAU,OAAO,OAAO;CAC/C,OAAO;EACL,QAAQ,OAAO,MAAM,MAAM;EAC3B,MAAM,OAAO,MAAM,IAAI;EACvB,MAAM,MAAM,MAAM,MAAM;GAAC;GAAQ;GAAQ;GAAO;EAAK,CAAU;EAC/D,GAAG,OAAO,MAAM,CAAC;EACjB,GAAG,QAAQ,MAAM,CAAC;EAClB;EACA,SAAS,OAAO,MAAM,OAAO;EAC7B,YAAY,OAAO,MAAM,UAAU;EACnC,QAAQ,OAAO,MAAM,MAAM;CAC7B;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sameValue } from "../core/transaction.js";
|
|
2
|
+
import { keptIndexes, orderKeys } from "./order.js";
|
|
2
3
|
import { collaborationColors } from "dou-ui";
|
|
3
4
|
import { shallowRef } from "vue";
|
|
4
5
|
import * as Y from "yjs";
|
|
@@ -7,7 +8,8 @@ import * as Y from "yjs";
|
|
|
7
8
|
var ORDER = "$order";
|
|
8
9
|
/** The places by breakpoint, a map of their own, so places on two breakpoints don't overwrite each other. */
|
|
9
10
|
var PLACE = "place";
|
|
10
|
-
|
|
11
|
+
/** Whether two JSON values are the same, whatever the order of their keys. */
|
|
12
|
+
var same = sameValue;
|
|
11
13
|
/** Where in `value` something JSON can't carry sits, e.g. a component or a function. */
|
|
12
14
|
function unshareable(value, path) {
|
|
13
15
|
if (value === null || [
|
|
@@ -87,19 +89,159 @@ function writeOrder(map, widgets) {
|
|
|
87
89
|
if (fields && fields.get(ORDER) !== keys[index]) fields.set(ORDER, keys[index]);
|
|
88
90
|
});
|
|
89
91
|
}
|
|
92
|
+
/** Runs `write` as one transaction of the map's document, from `origin`. */
|
|
93
|
+
function transact(map, write, origin) {
|
|
94
|
+
if (map.doc) map.doc.transact(write, origin ?? null);
|
|
95
|
+
else write();
|
|
96
|
+
}
|
|
90
97
|
/**
|
|
91
98
|
* Writes a dashboard into an empty map, e.g. when a dashboard so far saved
|
|
92
99
|
* as JSON starts being edited together. Do it once, where the shared
|
|
93
100
|
* document is created; otherwise the first person to open the dashboard
|
|
94
101
|
* brings theirs.
|
|
95
102
|
*/
|
|
96
|
-
function fillMap(map, document) {
|
|
103
|
+
function fillMap(map, document, options = {}) {
|
|
97
104
|
const fill = () => {
|
|
98
105
|
for (const widget of document.widgets) writeWidget(map, widget);
|
|
99
106
|
writeOrder(map, document.widgets);
|
|
100
107
|
};
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
transact(map, fill, options.origin);
|
|
109
|
+
}
|
|
110
|
+
/** Writes the keys and places that differ between `before` and `after` into a widget's map. */
|
|
111
|
+
function writeDifference(fields, before, after) {
|
|
112
|
+
const a = before;
|
|
113
|
+
const b = after;
|
|
114
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
115
|
+
if (key === "id" || key[0] === "$") continue;
|
|
116
|
+
if (key === PLACE) {
|
|
117
|
+
const from = before.place ?? {};
|
|
118
|
+
const to = after.place ?? {};
|
|
119
|
+
const found = fields.get(PLACE);
|
|
120
|
+
let places = found instanceof Y.Map ? found : null;
|
|
121
|
+
for (const name of /* @__PURE__ */ new Set([...Object.keys(from), ...Object.keys(to)])) {
|
|
122
|
+
if (same(from[name], to[name])) continue;
|
|
123
|
+
if (!places) fields.set(PLACE, places = new Y.Map());
|
|
124
|
+
const place = to[name];
|
|
125
|
+
if (place) places.set(name, { ...place });
|
|
126
|
+
else places.delete(name);
|
|
127
|
+
}
|
|
128
|
+
} else if (!same(a[key], b[key])) {
|
|
129
|
+
if (b[key] === void 0) fields.delete(key);
|
|
130
|
+
else {
|
|
131
|
+
warnUnshareable(after.id, key, b[key]);
|
|
132
|
+
fields.set(key, b[key]);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Gives `placing` (widgets added or moved in `next`) order keys among the
|
|
139
|
+
* widgets as they are ordered in the map now: right after the widget before
|
|
140
|
+
* them in `next`; those before the first widget that stays go right before
|
|
141
|
+
* it, and those after the last one go after all the others. Everyone else
|
|
142
|
+
* keeps their key.
|
|
143
|
+
*/
|
|
144
|
+
function placeOrder(map, next, placing) {
|
|
145
|
+
if (!placing.size) return;
|
|
146
|
+
const list = readMap(map).widgets.map((widget) => widget.id).filter((id) => !placing.has(id));
|
|
147
|
+
const listed = new Set(list);
|
|
148
|
+
const stays = (id) => listed.has(id);
|
|
149
|
+
let last = -1;
|
|
150
|
+
next.forEach((widget, index) => {
|
|
151
|
+
if (stays(widget.id)) last = index;
|
|
152
|
+
});
|
|
153
|
+
const leading = [];
|
|
154
|
+
const trailing = [];
|
|
155
|
+
const after = /* @__PURE__ */ new Map();
|
|
156
|
+
let first = null;
|
|
157
|
+
let previous = null;
|
|
158
|
+
next.forEach((widget, index) => {
|
|
159
|
+
if (stays(widget.id)) {
|
|
160
|
+
first ??= widget.id;
|
|
161
|
+
previous = widget.id;
|
|
162
|
+
} else if (placing.has(widget.id)) {
|
|
163
|
+
if (index > last) trailing.push(widget.id);
|
|
164
|
+
else if (previous === null) leading.push(widget.id);
|
|
165
|
+
else {
|
|
166
|
+
const attached = after.get(previous);
|
|
167
|
+
if (attached) attached.push(widget.id);
|
|
168
|
+
else after.set(previous, [widget.id]);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
const ordered = [];
|
|
173
|
+
for (const id of list) {
|
|
174
|
+
if (id === first) ordered.push(...leading);
|
|
175
|
+
ordered.push(id, ...after.get(id) ?? []);
|
|
176
|
+
}
|
|
177
|
+
ordered.push(...trailing);
|
|
178
|
+
const shared = ordered.map((id) => map.get(id));
|
|
179
|
+
const keys = orderKeys(shared.map((fields, index) => placing.has(ordered[index]) ? null : fields.get(ORDER) ?? null));
|
|
180
|
+
shared.forEach((fields, index) => {
|
|
181
|
+
if (fields.get(ORDER) !== keys[index]) fields.set(ORDER, keys[index]);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* While developing: each widget `readMap` gave, as it was then, to tell a
|
|
186
|
+
* widget of `base` changed in place from one others changed meanwhile.
|
|
187
|
+
*/
|
|
188
|
+
var asRead = /* @__PURE__ */ new WeakMap();
|
|
189
|
+
/** The widgets of `next` that can be written: each id once, each with a type. */
|
|
190
|
+
function writable(next, base) {
|
|
191
|
+
const dev = process.env.NODE_ENV !== "production";
|
|
192
|
+
if (dev && base && (next === base || next.widgets === base.widgets)) console.warn("[@dou-ui/dashboard] updateMap got the same object as `next` and `base`, so nothing is written: change a copy of `base`, e.g. structuredClone(base).");
|
|
193
|
+
else if (dev && base) {
|
|
194
|
+
const kept = new Set(base.widgets);
|
|
195
|
+
for (const widget of next.widgets) {
|
|
196
|
+
const snapshot = kept.has(widget) ? asRead.get(widget) : void 0;
|
|
197
|
+
if (!snapshot || same(snapshot, widget)) continue;
|
|
198
|
+
console.warn(`[@dou-ui/dashboard] updateMap got the widget "${widget.id}" of \`base\` itself in \`next\`, changed in place: the change isn't written. Change a copy of \`base\`, e.g. structuredClone(base).`);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const seen = /* @__PURE__ */ new Set();
|
|
203
|
+
return next.widgets.filter((widget) => {
|
|
204
|
+
if (typeof widget.type !== "string") {
|
|
205
|
+
if (dev) console.warn(`[@dou-ui/dashboard] updateMap skips "${widget.id}": a widget needs a \`type\`.`);
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if (seen.has(widget.id)) {
|
|
209
|
+
if (dev) console.warn(`[@dou-ui/dashboard] updateMap skips the second widget "${widget.id}": ids must be unique.`);
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
seen.add(widget.id);
|
|
213
|
+
return true;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Change a shared map from `options.base` to `next`, without a dashboard,
|
|
218
|
+
* e.g. on the server when a program wrote a new version while people edit
|
|
219
|
+
* the dashboard. Only what differs is written.
|
|
220
|
+
*/
|
|
221
|
+
function updateMap(map, next, options = {}) {
|
|
222
|
+
if (!map.doc) throw new Error("[@dou-ui/dashboard] updateMap needs a map of a Y.Doc");
|
|
223
|
+
const update = () => {
|
|
224
|
+
const base = options.base ?? readMap(map);
|
|
225
|
+
const widgets = writable(next, options.base);
|
|
226
|
+
const before = new Map(base.widgets.map((widget) => [widget.id, widget]));
|
|
227
|
+
const ids = new Set(next.widgets.map((widget) => widget.id));
|
|
228
|
+
for (const id of before.keys()) if (!ids.has(id)) map.delete(id);
|
|
229
|
+
const index = new Map(base.widgets.map((widget, i) => [widget.id, i]));
|
|
230
|
+
const common = widgets.filter((widget) => index.has(widget.id));
|
|
231
|
+
const kept = keptIndexes(common.map((widget) => String(index.get(widget.id)).padStart(10, "0")));
|
|
232
|
+
const placing = new Set(common.filter((_, i) => !kept.has(i)).map((widget) => widget.id));
|
|
233
|
+
for (const widget of widgets) {
|
|
234
|
+
const old = before.get(widget.id);
|
|
235
|
+
const fields = map.get(widget.id);
|
|
236
|
+
if (!old) {
|
|
237
|
+
writeWidget(map, widget);
|
|
238
|
+
placing.add(widget.id);
|
|
239
|
+
} else if (fields instanceof Y.Map) writeDifference(fields, old, widget);
|
|
240
|
+
else placing.delete(widget.id);
|
|
241
|
+
}
|
|
242
|
+
placeOrder(map, widgets, placing);
|
|
243
|
+
};
|
|
244
|
+
transact(map, update, options.origin);
|
|
103
245
|
}
|
|
104
246
|
/** The dashboard the map holds: its widgets by their order keys (then ids, the same for everyone). */
|
|
105
247
|
function readMap(map) {
|
|
@@ -119,9 +261,11 @@ function readMap(map) {
|
|
|
119
261
|
});
|
|
120
262
|
});
|
|
121
263
|
list.sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : a.widget.id < b.widget.id ? -1 : 1);
|
|
264
|
+
const widgets = list.map((entry) => entry.widget);
|
|
265
|
+
if (process.env.NODE_ENV !== "production") for (const widget of widgets) asRead.set(widget, structuredClone(widget));
|
|
122
266
|
return {
|
|
123
267
|
version: 1,
|
|
124
|
-
widgets
|
|
268
|
+
widgets
|
|
125
269
|
};
|
|
126
270
|
}
|
|
127
271
|
/** The widgets and keys a transaction changed, written to the map. */
|
|
@@ -276,6 +420,6 @@ function collaboration(options) {
|
|
|
276
420
|
peers: awareness ? (id) => peersByWidget.value.get(id) ?? NO_PEERS : void 0
|
|
277
421
|
};
|
|
278
422
|
}
|
|
279
|
-
export { collaboration, collaborationColors, fillMap, readMap };
|
|
423
|
+
export { collaboration, collaborationColors, fillMap, readMap, updateMap };
|
|
280
424
|
|
|
281
425
|
//# sourceMappingURL=index.js.map
|