@dou-ui/form-builder 0.1.0-alpha.2 → 0.1.0-alpha.21
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/builder/extension.js.map +1 -1
- package/dist/builder/form-builder.js.map +1 -1
- package/dist/builder/form-builder.vue_vue_type_script_setup_true_lang.js +6 -1
- package/dist/builder/form-builder.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/builder/inspector.js.map +1 -1
- package/dist/builder/inspector.vue_vue_type_script_setup_true_lang.js +7 -7
- package/dist/builder/inspector.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/builder/menu.js +1 -0
- package/dist/builder/menu.js.map +1 -1
- package/dist/builder/preview.js.map +1 -1
- package/dist/builder/preview.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/builder/preview.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/builder/settings.js +2 -2
- package/dist/builder/settings.js.map +1 -1
- package/dist/collaboration/index.js +2 -2
- package/dist/collaboration/index.js.map +1 -1
- package/dist/renderer/containers.js +1 -1
- package/dist/renderer/containers.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/builder/extension.d.ts +2 -0
- package/dist/types/builder/form-builder.vue.d.ts +1 -0
- package/dist/types/builder/index.d.ts +3 -0
- package/dist/types/builder/menu.d.ts +1 -0
- package/dist/types/builder/types.d.ts +6 -0
- package/dist/types/collaboration/index.d.ts +5 -1
- package/package.json +5 -5
package/dist/builder/menu.js
CHANGED
package/dist/builder/menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","names":[],"sources":["../../src/builder/menu.ts"],"sourcesContent":["import { h } from 'vue'\nimport type { Component, VNode } from 'vue'\nimport { DouDropdownItem } from 'dou-ui'\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CopyIcon,\n CornerLeftUpIcon,\n SquareDashedIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport type { FormNode } from '../core/types'\nimport type { BuilderState } from './context'\nimport { formNodePlaces } from './core/transaction'\n\n/** An item of a node's menu, built in or from an extension. */\nexport interface NodeMenuEntry {\n key: string\n label: string\n icon?: Component\n run: () => void\n disabled?: boolean\n tone?: 'neutral' | 'danger'\n /** The key that does the same, shown at the end of the item. */\n shortcut?: string\n /** A line above it, between the built-in items and an extension's. */\n divided?: boolean\n}\n\n/**\n * The menu of some nodes: move, copy, group and delete them, then the\n * extensions' items. A read-only builder keeps only going to the parent\n * and the extensions' items.\n */\nexport function nodeMenu(state: BuilderState, ids: readonly string[]): NodeMenuEntry[] {\n const messages = state.messages\n const map = formNodePlaces(state.document)\n const places = ids.flatMap((id) => {\n const place = map.get(id)\n return place ? [place] : []\n })\n if (!places.length) return []\n const parents = new Set(places.map((place) => place.parent?.id ?? null))\n const one = places.length === 1 ? places[0]! : undefined\n const siblings = one?.parent ? one.parent.children.length : state.document.nodes.length\n const pages = places.some((place) => place.node.type === 'page')\n const entries: NodeMenuEntry[] = []\n if (one?.parent)\n entries.push({\n key: 'parent',\n label: messages.actions.parent,\n shortcut: 'escape',\n icon: CornerLeftUpIcon,\n run: () => state.selectParent(),\n })\n if (!state.readonly) {\n entries.push(\n {\n key: 'up',\n label: messages.actions.up,\n shortcut: 'mod+arrowup',\n icon: ArrowUpIcon,\n run: () => state.moveBy(-1, ids),\n disabled: !!one && !one.index,\n },\n {\n key: 'down',\n label: messages.actions.down,\n shortcut: 'mod+arrowdown',\n icon: ArrowDownIcon,\n run: () => state.moveBy(1, ids),\n disabled: !!one && one.index >= siblings - 1,\n },\n {\n key: 'duplicate',\n label: messages.actions.duplicate,\n shortcut: 'mod+d',\n icon: CopyIcon,\n run: () => state.duplicate(ids),\n },\n )\n if (parents.size === 1 && !pages)\n entries.push({\n key: 'wrap',\n label: messages.actions.wrap,\n shortcut: 'mod+g',\n icon: SquareDashedIcon,\n run: () => state.wrap(ids),\n })\n entries.push({\n key: 'remove',\n label: messages.actions.remove,\n shortcut: 'delete',\n icon: TrashIcon,\n run: () => state.remove(ids),\n tone: 'danger',\n })\n }\n const nodes: FormNode[] = places.map((place) => place.node)\n const extra = state.extensions().menus.flatMap((menu) => menu(state, nodes))\n extra.forEach((item, index) => entries.push({ ...item, divided: index === 0 }))\n return entries\n}\n\n/** The entries as items of a dropdown or a context menu. */\nexport function menuItems(entries: readonly NodeMenuEntry[]): VNode[] {\n return entries.map((entry) =>\n h(\n DouDropdownItem,\n {\n key: entry.key,\n disabled: entry.disabled,\n tone: entry.tone ?? 'neutral',\n divided: entry.divided,\n shortcut: entry.shortcut,\n onClick: entry.run,\n },\n { prefix: entry.icon ? () => h(entry.icon!) : undefined, default: () => entry.label },\n ),\n )\n}\n"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"menu.js","names":[],"sources":["../../src/builder/menu.ts"],"sourcesContent":["import { h } from 'vue'\nimport type { Component, VNode } from 'vue'\nimport { DouDropdownItem } from 'dou-ui'\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CopyIcon,\n CornerLeftUpIcon,\n SquareDashedIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport type { FormNode } from '../core/types'\nimport type { BuilderState } from './context'\nimport { formNodePlaces } from './core/transaction'\n\n/** An item of a node's menu, built in or from an extension. */\nexport interface NodeMenuEntry {\n key: string\n label: string\n description?: string\n icon?: Component\n run: () => void\n disabled?: boolean\n tone?: 'neutral' | 'danger'\n /** The key that does the same, shown at the end of the item. */\n shortcut?: string\n /** A line above it, between the built-in items and an extension's. */\n divided?: boolean\n}\n\n/**\n * The menu of some nodes: move, copy, group and delete them, then the\n * extensions' items. A read-only builder keeps only going to the parent\n * and the extensions' items.\n */\nexport function nodeMenu(state: BuilderState, ids: readonly string[]): NodeMenuEntry[] {\n const messages = state.messages\n const map = formNodePlaces(state.document)\n const places = ids.flatMap((id) => {\n const place = map.get(id)\n return place ? [place] : []\n })\n if (!places.length) return []\n const parents = new Set(places.map((place) => place.parent?.id ?? null))\n const one = places.length === 1 ? places[0]! : undefined\n const siblings = one?.parent ? one.parent.children.length : state.document.nodes.length\n const pages = places.some((place) => place.node.type === 'page')\n const entries: NodeMenuEntry[] = []\n if (one?.parent)\n entries.push({\n key: 'parent',\n label: messages.actions.parent,\n shortcut: 'escape',\n icon: CornerLeftUpIcon,\n run: () => state.selectParent(),\n })\n if (!state.readonly) {\n entries.push(\n {\n key: 'up',\n label: messages.actions.up,\n shortcut: 'mod+arrowup',\n icon: ArrowUpIcon,\n run: () => state.moveBy(-1, ids),\n disabled: !!one && !one.index,\n },\n {\n key: 'down',\n label: messages.actions.down,\n shortcut: 'mod+arrowdown',\n icon: ArrowDownIcon,\n run: () => state.moveBy(1, ids),\n disabled: !!one && one.index >= siblings - 1,\n },\n {\n key: 'duplicate',\n label: messages.actions.duplicate,\n shortcut: 'mod+d',\n icon: CopyIcon,\n run: () => state.duplicate(ids),\n },\n )\n if (parents.size === 1 && !pages)\n entries.push({\n key: 'wrap',\n label: messages.actions.wrap,\n shortcut: 'mod+g',\n icon: SquareDashedIcon,\n run: () => state.wrap(ids),\n })\n entries.push({\n key: 'remove',\n label: messages.actions.remove,\n shortcut: 'delete',\n icon: TrashIcon,\n run: () => state.remove(ids),\n tone: 'danger',\n })\n }\n const nodes: FormNode[] = places.map((place) => place.node)\n const extra = state.extensions().menus.flatMap((menu) => menu(state, nodes))\n extra.forEach((item, index) => entries.push({ ...item, divided: index === 0 }))\n return entries\n}\n\n/** The entries as items of a dropdown or a context menu. */\nexport function menuItems(entries: readonly NodeMenuEntry[]): VNode[] {\n return entries.map((entry) =>\n h(\n DouDropdownItem,\n {\n key: entry.key,\n disabled: entry.disabled,\n tone: entry.tone ?? 'neutral',\n divided: entry.divided,\n shortcut: entry.shortcut,\n description: entry.description,\n onClick: entry.run,\n },\n { prefix: entry.icon ? () => h(entry.icon!) : undefined, default: () => entry.label },\n ),\n )\n}\n"],"mappings":";;;;;;;;;;AAmCA,SAAgB,SAAS,OAAqB,KAAyC;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M,KAAK,GAAG;EAC3B,CAAC;EACH,QAAQ,KAAK;GACX,KAAK;GACL,OAAO,SAAS,QAAQ;GACxB,UAAU;GACV,MAAM;GACN,WAAW,MAAM,OAAO,GAAG;GAC3B,MAAM;EACR,CAAC;CACH;CACA,MAAM,QAAoB,OAAO,KAAK,UAAU,MAAM,IAAI;CAE1D,MADoB,WAAW,CAAC,CAAC,MAAM,SAAS,SAAS,KAAK,OAAO,KAAK,CAC1E,CAAA,CAAM,SAAS,MAAM,UAAU,QAAQ,KAAK;EAAE,GAAG;EAAM,SAAS,UAAU;CAAE,CAAC,CAAC;CAC9E,OAAO;AACT;;AAGA,SAAgB,UAAU,SAA4C;CACpE,OAAO,QAAQ,KAAK,UAClB,EACE,iBACA;EACE,KAAK,MAAM;EACX,UAAU,MAAM;EAChB,MAAM,MAAM,QAAQ;EACpB,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,aAAa,MAAM;EACnB,SAAS,MAAM;CACjB,GACA;EAAE,QAAQ,MAAM,aAAa,EAAE,MAAM,IAAK,IAAI,KAAA;EAAW,eAAe,MAAM;CAAM,CACtF,CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.js","names":["_sfc_main"],"sources":["../../src/builder/preview.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, reactive, shallowRef, watch } from 'vue'\nimport { DouButton, DouSegmentedControl } from 'dou-ui'\nimport type { FormModel } from 'dou-ui'\nimport { CheckCircleIcon, MonitorIcon, SmartphoneIcon, TabletIcon } from '@dou-ui/icons'\nimport FormRenderer from '../renderer
|
|
1
|
+
{"version":3,"file":"preview.js","names":["_sfc_main"],"sources":["../../src/builder/preview.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, reactive, shallowRef, watch } from 'vue'\nimport { DouButton, DouSegmentedControl } from 'dou-ui'\nimport type { FormModel } from 'dou-ui'\nimport { CheckCircleIcon, MonitorIcon, SmartphoneIcon, TabletIcon } from '@dou-ui/icons'\nimport { DouFormRenderer as FormRenderer } from '../renderer'\nimport { useBuilderState } from './context'\n\n/**\n * The form as people will fill it in, at the width of a desktop, a tablet\n * or a phone. The values are kept while the form is edited, so switching\n * back and forth does not lose them; submitting shows what would be sent.\n */\ndefineOptions({ name: 'DouFormBuilderPreview' })\n\ntype Device = 'desktop' | 'tablet' | 'phone'\n\nconst state = useBuilderState()\nconst messages = computed(() => state.messages.preview)\nconst fields = computed(() => [...state.fields.values()])\n\nconst device = shallowRef<Device>('desktop')\nconst widths: Record<Device, number | undefined> = { desktop: undefined, tablet: 768, phone: 375 }\nconst icons = { desktop: MonitorIcon, tablet: TabletIcon, phone: SmartphoneIcon }\nconst devices = computed(() =>\n (['desktop', 'tablet', 'phone'] as const).map((value) => ({\n value,\n label: messages.value.devices[value],\n })),\n)\n\nconst model = reactive<FormModel>({})\nconst result = shallowRef<FormModel | null>(null)\nwatch(\n () => state.document,\n () => (result.value = null),\n)\nconst shown = computed(() => (result.value ? JSON.stringify(result.value, null, 2) : ''))\n</script>\n\n<template>\n <div class=\"dou-form-builder__preview\" role=\"region\" :aria-label=\"messages.label\">\n <div class=\"dou-form-builder__preview-bar\">\n <DouSegmentedControl\n v-model=\"device\"\n :options=\"devices\"\n :aria-label=\"messages.device\"\n size=\"sm\"\n class=\"dou-form-builder__preview-devices\"\n >\n <template #option=\"{ option }\">\n <span class=\"dou-form-builder__preview-device\">\n <component :is=\"icons[option.value as Device]\" />\n <span>{{ option.label }}</span>\n </span>\n </template>\n </DouSegmentedControl>\n </div>\n <div class=\"dou-form-builder__preview-scroll\">\n <div\n class=\"dou-form-builder__preview-frame\"\n :data-device=\"device\"\n :style=\"widths[device] ? { width: `${widths[device]}px` } : undefined\"\n >\n <FormRenderer\n :form=\"state.document\"\n :model=\"model\"\n :fields=\"fields\"\n :functions=\"state.functions()\"\n :sources=\"state.sources()\"\n :validators=\"state.validators()\"\n @submit=\"result = $event\"\n @invalid=\"result = null\"\n @reset=\"result = null\"\n >\n <div class=\"dou-form-builder__preview-footer\">\n <DouButton native-type=\"submit\" tone=\"primary\">{{ messages.submit }}</DouButton>\n <DouButton native-type=\"reset\" variant=\"outline\">{{ messages.reset }}</DouButton>\n </div>\n </FormRenderer>\n <div v-if=\"result\" class=\"dou-form-builder__preview-result\" role=\"status\">\n <div class=\"dou-form-builder__preview-result-title\">\n <CheckCircleIcon />\n <span>{{ messages.passed }}</span>\n </div>\n <pre class=\"dou-form-builder__preview-result-code\">{{ shown }}</pre>\n </div>\n </div>\n </div>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DouFormRenderer } from "../renderer/index.js";
|
|
2
2
|
import { useBuilderState } from "./context.js";
|
|
3
3
|
import { DouButton, DouSegmentedControl } from "dou-ui";
|
|
4
4
|
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeStyle, openBlock, reactive, resolveDynamicComponent, shallowRef, toDisplayString, unref, watch, withCtx } from "vue";
|
|
@@ -70,7 +70,7 @@ var preview_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
70
70
|
class: "dou-form-builder__preview-frame",
|
|
71
71
|
"data-device": device.value,
|
|
72
72
|
style: normalizeStyle(widths[device.value] ? { width: `${widths[device.value]}px` } : void 0)
|
|
73
|
-
}, [createVNode(
|
|
73
|
+
}, [createVNode(unref(DouFormRenderer), {
|
|
74
74
|
form: unref(state).document,
|
|
75
75
|
model,
|
|
76
76
|
fields: fields.value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_createElementVNode","_createVNode","_unref","_withCtx","_createBlock","_resolveDynamicComponent","_toDisplayString","_normalizeStyle","FormRenderer","_createTextVNode","_createCommentVNode"],"sources":["../../src/builder/preview.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, reactive, shallowRef, watch } from 'vue'\nimport { DouButton, DouSegmentedControl } from 'dou-ui'\nimport type { FormModel } from 'dou-ui'\nimport { CheckCircleIcon, MonitorIcon, SmartphoneIcon, TabletIcon } from '@dou-ui/icons'\nimport FormRenderer from '../renderer
|
|
1
|
+
{"version":3,"file":"preview.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_createElementVNode","_createVNode","_unref","_withCtx","_createBlock","_resolveDynamicComponent","_toDisplayString","_normalizeStyle","FormRenderer","_createTextVNode","_createCommentVNode"],"sources":["../../src/builder/preview.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, reactive, shallowRef, watch } from 'vue'\nimport { DouButton, DouSegmentedControl } from 'dou-ui'\nimport type { FormModel } from 'dou-ui'\nimport { CheckCircleIcon, MonitorIcon, SmartphoneIcon, TabletIcon } from '@dou-ui/icons'\nimport { DouFormRenderer as FormRenderer } from '../renderer'\nimport { useBuilderState } from './context'\n\n/**\n * The form as people will fill it in, at the width of a desktop, a tablet\n * or a phone. The values are kept while the form is edited, so switching\n * back and forth does not lose them; submitting shows what would be sent.\n */\ndefineOptions({ name: 'DouFormBuilderPreview' })\n\ntype Device = 'desktop' | 'tablet' | 'phone'\n\nconst state = useBuilderState()\nconst messages = computed(() => state.messages.preview)\nconst fields = computed(() => [...state.fields.values()])\n\nconst device = shallowRef<Device>('desktop')\nconst widths: Record<Device, number | undefined> = { desktop: undefined, tablet: 768, phone: 375 }\nconst icons = { desktop: MonitorIcon, tablet: TabletIcon, phone: SmartphoneIcon }\nconst devices = computed(() =>\n (['desktop', 'tablet', 'phone'] as const).map((value) => ({\n value,\n label: messages.value.devices[value],\n })),\n)\n\nconst model = reactive<FormModel>({})\nconst result = shallowRef<FormModel | null>(null)\nwatch(\n () => state.document,\n () => (result.value = null),\n)\nconst shown = computed(() => (result.value ? JSON.stringify(result.value, null, 2) : ''))\n</script>\n\n<template>\n <div class=\"dou-form-builder__preview\" role=\"region\" :aria-label=\"messages.label\">\n <div class=\"dou-form-builder__preview-bar\">\n <DouSegmentedControl\n v-model=\"device\"\n :options=\"devices\"\n :aria-label=\"messages.device\"\n size=\"sm\"\n class=\"dou-form-builder__preview-devices\"\n >\n <template #option=\"{ option }\">\n <span class=\"dou-form-builder__preview-device\">\n <component :is=\"icons[option.value as Device]\" />\n <span>{{ option.label }}</span>\n </span>\n </template>\n </DouSegmentedControl>\n </div>\n <div class=\"dou-form-builder__preview-scroll\">\n <div\n class=\"dou-form-builder__preview-frame\"\n :data-device=\"device\"\n :style=\"widths[device] ? { width: `${widths[device]}px` } : undefined\"\n >\n <FormRenderer\n :form=\"state.document\"\n :model=\"model\"\n :fields=\"fields\"\n :functions=\"state.functions()\"\n :sources=\"state.sources()\"\n :validators=\"state.validators()\"\n @submit=\"result = $event\"\n @invalid=\"result = null\"\n @reset=\"result = null\"\n >\n <div class=\"dou-form-builder__preview-footer\">\n <DouButton native-type=\"submit\" tone=\"primary\">{{ messages.submit }}</DouButton>\n <DouButton native-type=\"reset\" variant=\"outline\">{{ messages.reset }}</DouButton>\n </div>\n </FormRenderer>\n <div v-if=\"result\" class=\"dou-form-builder__preview-result\" role=\"status\">\n <div class=\"dou-form-builder__preview-result-title\">\n <CheckCircleIcon />\n <span>{{ messages.passed }}</span>\n </div>\n <pre class=\"dou-form-builder__preview-result-code\">{{ shown }}</pre>\n </div>\n </div>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;EAiBA,MAAM,QAAQ,gBAAgB;EAC9B,MAAM,WAAW,eAAe,MAAM,SAAS,OAAO;EACtD,MAAM,SAAS,eAAe,CAAC,GAAG,MAAM,OAAO,OAAO,CAAC,CAAC;EAExD,MAAM,SAAS,WAAmB,SAAS;EAC3C,MAAM,SAA6C;GAAE,SAAS,KAAA;GAAW,QAAQ;GAAK,OAAO;EAAI;EACjG,MAAM,QAAQ;GAAE,SAAS;GAAa,QAAQ;GAAY,OAAO;EAAe;EAChF,MAAM,UAAU,eACb;GAAC;GAAW;G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AAS;IACjB,WAAO,OAAA,OAAA,OAAA,MAAA,WAAE,OAAA,QAAM;IACf,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,OAAA,QAAM;;IAEd,SAAAC,cAGM,CAHNH,mBAGM,OAHN,YAGM,CAFJC,YAAgFC,MAAA,SAAA,GAAA;KAArE,eAAY;KAAS,MAAK;;KAAU,SAAAC,cAAqB,CAAlBM,gBAAAH,gBAAA,SAAA,MAAS,MAAM,GAAA,CAAA,C;;I,IACjEL,YAAiFC,MAAA,SAAA,GAAA;KAAtE,eAAY;KAAQ,SAAQ;;KAAU,SAAAC,cAAoB,CAAjBM,gBAAAH,gBAAA,SAAA,MAAS,KAAK,GAAA,CAAA,C;;;;;;;;;;;G,IAG3D,OAAA,SAAXR,UAAA,GAAAC,mBAMM,OANN,YAMM,CALJC,mBAGM,OAHN,YAGM,CAFJC,YAAmBC,MAAA,eAAA,CAAA,GACnBF,mBAAkC,QAAA,MAAAM,gBAAzB,SAAA,MAAS,MAAM,GAAA,CAAA,C,IAE1BN,mBAAoE,OAApE,YAAoEM,gBAAd,MAAA,KAAK,GAAA,CAAA,C"}
|
package/dist/builder/settings.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { markRaw } from "vue";
|
|
2
|
-
import { CalendarIcon, CheckSquareIcon, ChevronDownSquareIcon, ClockIcon, HashIcon, InfoSquareIcon, LayoutIcon, LayoutListIcon, ListChecksIcon, ListTreeIcon, OtpIcon, PaletteIcon,
|
|
2
|
+
import { CalendarIcon, CheckSquareIcon, ChevronDownSquareIcon, CircleDotIcon, ClockIcon, HashIcon, InfoSquareIcon, LayoutIcon, LayoutListIcon, ListChecksIcon, ListTreeIcon, OtpIcon, PaletteIcon, SegmentedControlIcon, SeparatorHorizontalIcon, SlidersIcon, SquareDashedIcon, StarIcon, StepsIcon, TabsIcon, TagsIcon, TextAlignLeftIcon, TextCursorIcon, ToggleRightIcon, TreeStructureIcon, TypeIcon, UploadIcon } from "@dou-ui/icons";
|
|
3
3
|
// src/builder/settings.ts
|
|
4
4
|
/** The palette groups in the order they are listed; groups of other names follow. */
|
|
5
5
|
var paletteGroups = [
|
|
@@ -37,7 +37,7 @@ var builtinLooks = {
|
|
|
37
37
|
group: "choice"
|
|
38
38
|
},
|
|
39
39
|
"radio-group": {
|
|
40
|
-
icon: raw(
|
|
40
|
+
icon: raw(CircleDotIcon),
|
|
41
41
|
group: "choice"
|
|
42
42
|
},
|
|
43
43
|
"checkbox-group": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.js","names":[],"sources":["../../src/builder/settings.ts"],"sourcesContent":["import {\n CalendarIcon,\n CheckSquareIcon,\n ChevronDownSquareIcon,\n ClockIcon,\n HashIcon,\n InfoSquareIcon,\n LayoutIcon,\n LayoutListIcon,\n ListChecksIcon,\n ListTreeIcon,\n OtpIcon,\n PaletteIcon,\n RadioIcon,\n SegmentedControlIcon,\n SeparatorHorizontalIcon,\n SlidersIcon,\n SquareDashedIcon,\n StarIcon,\n StepsIcon,\n TabsIcon,\n TagsIcon,\n TextAlignLeftIcon,\n TextCursorIcon,\n ToggleRightIcon,\n TreeStructureIcon,\n TypeIcon,\n UploadIcon,\n} from '@dou-ui/icons'\nimport { markRaw } from 'vue'\nimport type { Component } from 'vue'\nimport type { FormDocument, FormFieldNode, FormListNode, FormNode } from '../core/types'\nimport type { FormFieldType } from '../fields/define'\nimport type { FormBuilderMessages } from './locale'\n\n/** The palette groups in the order they are listed; groups of other names follow. */\nexport const paletteGroups = ['input', 'choice', 'more', 'display', 'layout']\n\nconst raw = (icon: Component) => markRaw(icon)\n\n/** Icons and groups of the built-in types, kept out of the renderer's entry. */\nconst builtinLooks: Record<string, { icon: Component; group: string }> = {\n input: { icon: raw(TextCursorIcon), group: 'input' },\n textarea: { icon: raw(TextAlignLeftIcon), group: 'input' },\n 'input-number': { icon: raw(HashIcon), group: 'input' },\n 'input-tag': { icon: raw(TagsIcon), group: 'input' },\n 'input-otp': { icon: raw(OtpIcon), group: 'input' },\n select: { icon: raw(ChevronDownSquareIcon), group: 'choice' },\n 'radio-group': { icon: raw(RadioIcon), group: 'choice' },\n 'checkbox-group': { icon: raw(ListChecksIcon), group: 'choice' },\n checkbox: { icon: raw(CheckSquareIcon), group: 'choice' },\n switch: { icon: raw(ToggleRightIcon), group: 'choice' },\n 'segmented-control': { icon: raw(SegmentedControlIcon), group: 'choice' },\n cascader: { icon: raw(ListTreeIcon), group: 'choice' },\n 'tree-select': { icon: raw(TreeStructureIcon), group: 'choice' },\n slider: { icon: raw(SlidersIcon), group: 'more' },\n rate: { icon: raw(StarIcon), group: 'more' },\n 'date-picker': { icon: raw(CalendarIcon), group: 'more' },\n 'time-picker': { icon: raw(ClockIcon), group: 'more' },\n 'color-picker': { icon: raw(PaletteIcon), group: 'more' },\n upload: { icon: raw(UploadIcon), group: 'more' },\n text: { icon: raw(TypeIcon), group: 'display' },\n divider: { icon: raw(SeparatorHorizontalIcon), group: 'display' },\n alert: { icon: raw(InfoSquareIcon), group: 'display' },\n section: { icon: raw(SquareDashedIcon), group: 'layout' },\n tabs: { icon: raw(TabsIcon), group: 'layout' },\n steps: { icon: raw(StepsIcon), group: 'layout' },\n list: { icon: raw(LayoutListIcon), group: 'layout' },\n page: { icon: raw(LayoutIcon), group: 'layout' },\n}\n\n/** The containers the palette offers, after the field types. */\nexport const containerTypes = ['section', 'tabs', 'steps', 'list']\n\n/** A type's icon: its own, else the built-in one, else a plain box. */\nexport function iconOf(type: string, spec?: FormFieldType): Component {\n return spec?.icon ?? builtinLooks[type]?.icon ?? builtinLooks.section!.icon\n}\n\nexport function groupOf(type: string, spec?: FormFieldType): string {\n return spec?.group ?? builtinLooks[type]?.group ?? 'more'\n}\n\n/** A type's name for people: its own `label`, else the locale's. */\nexport function labelOf(\n type: string,\n spec: FormFieldType | undefined,\n messages: FormBuilderMessages,\n) {\n return spec?.label ?? messages.types[type] ?? type\n}\n\n/** What a node is called in the outline and the inspector's heading. */\nexport function nodeTitle(\n node: FormNode,\n fields: ReadonlyMap<string, FormFieldType>,\n messages: FormBuilderMessages,\n): string {\n const record = node as unknown as Record<string, unknown>\n const own = (record.label ?? record.title) as string | undefined\n if (own) return own\n if ('name' in node && node.name) return node.name\n return labelOf(node.type, fields.get(node.type), messages)\n}\n\n// Settings ----------------------------------------------------------------------\n\ntype Setting = Record<string, unknown>\n\nexport const field = (type: string, name: string, label: string, extra: Setting = {}): FormNode =>\n ({ id: `setting-${name}`, type, name, label, ...extra }) as FormFieldNode\n\nconst sw = (name: string, label: string, extra: Setting = {}) => field('switch', name, label, extra)\nexport const text = (name: string, label: string, extra: Setting = {}) =>\n field('input', name, label, { ...extra, props: { clearable: true, ...(extra.props as Setting) } })\nexport const number = (name: string, label: string, props: Setting = {}, extra: Setting = {}) =>\n field('input-number', name, label, { ...extra, props: { controls: false, ...props } })\n\nexport function choices(\n messages: FormBuilderMessages,\n key: string,\n values: readonly (string | boolean)[],\n): { value: string | boolean; label: string }[] {\n const labels = messages.choices[key] ?? {}\n return values.map((value) => ({ value, label: labels[String(value)] ?? String(value) }))\n}\n\nexport const segmented = (\n messages: FormBuilderMessages,\n name: string,\n values: readonly string[],\n fallback: string,\n extra: Setting = {},\n key = name,\n) =>\n field('segmented-control', name, messages.settings[key] ?? name, {\n default: fallback,\n props: { options: choices(messages, key, values), block: true },\n ...extra,\n })\n\nfunction optionList(messages: FormBuilderMessages, name = 'options'): FormListNode {\n const s = messages.settings\n return {\n id: `setting-${name}`,\n type: 'list',\n name,\n label: s.options,\n columns: 12,\n children: [\n field('input', 'label', s.optionLabel!, { span: 6 }),\n field('input', 'value', s.optionValue!, { span: 6 }),\n ],\n }\n}\n\n/** Settings of the built-in types, edited in a node's `props`. */\nexport function builtinSettings(type: string, messages: FormBuilderMessages): FormNode[] {\n const s = messages.settings as Record<string, string>\n const placeholder = text('placeholder', s.placeholder!)\n const clearable = sw('clearable', s.clearable!)\n const multiple = sw('multiple', s.multiple!)\n const filterable = sw('filterable', s.filterable!)\n const options = optionList(messages)\n const direction = segmented(messages, 'direction', ['horizontal', 'vertical'], 'horizontal')\n switch (type) {\n case 'input':\n return [\n placeholder,\n clearable,\n number('maxlength', s.maxlength!, { min: 1 }),\n sw('showCount', s.showCount!),\n ]\n case 'textarea':\n return [\n placeholder,\n number('rows', s.rows!, { min: 1, placeholder: '3' }),\n sw('autosize', s.autosize!),\n number('maxlength', s.maxlength!, { min: 1 }),\n sw('showCount', s.showCount!),\n ]\n case 'input-number':\n return [\n placeholder,\n number('min', s.min!, {}, { span: 6 }),\n number('max', s.max!, {}, { span: 6 }),\n number('step', s.step!, { min: 0, placeholder: '1' }, { span: 6 }),\n number('precision', s.precision!, { min: 0, precision: 0 }, { span: 6 }),\n sw('controls', s.controls!, { default: true }),\n ]\n case 'select':\n return [options, placeholder, multiple, filterable, clearable]\n case 'radio-group':\n case 'checkbox-group':\n return [options, direction]\n case 'segmented-control':\n return [options]\n case 'checkbox':\n return [text('text', s.text!)]\n case 'slider':\n return [\n number('min', s.min!, {}, { span: 6, default: 0 }),\n number('max', s.max!, {}, { span: 6, default: 100 }),\n number('step', s.step!, { min: 0 }, { default: 1 }),\n sw('range', s.range!),\n ]\n case 'rate':\n return [\n number('max', s.count!, { min: 1, max: 10, precision: 0 }, { default: 5 }),\n sw('allowHalf', s.allowHalf!),\n ]\n case 'date-picker':\n return [\n field('select', 'type', s.dateType!, {\n default: 'date',\n props: {\n options: choices(messages, 'dateType', [\n 'date',\n 'week',\n 'month',\n 'quarter',\n 'year',\n 'datetime',\n ]),\n },\n }),\n sw('range', s.range!, { visibleWhen: \"values.type != 'week'\" }),\n placeholder,\n clearable,\n ]\n case 'time-picker':\n return [sw('range', s.range!), placeholder, clearable]\n case 'color-picker':\n return [sw('showAlpha', s.showAlpha!), clearable]\n case 'cascader':\n case 'tree-select':\n return [placeholder, multiple, filterable, clearable]\n case 'input-tag':\n return [placeholder, number('max', s.maxTags!, { min: 1, precision: 0 }), clearable]\n case 'input-otp':\n return [\n number('length', s.length!, { min: 1, max: 12, precision: 0 }, { default: 6 }),\n sw('mask', s.mask!),\n ]\n case 'upload':\n return [\n text('accept', s.accept!, { props: { placeholder: 'image/*, .pdf' } }),\n multiple,\n number('maxCount', s.maxCount!, { min: 1, precision: 0 }),\n sw('dropzone', s.dropzone!),\n ]\n case 'text':\n return [\n field('textarea', 'content', s.content!, {\n props: { autosize: { minRows: 2, maxRows: 8 } },\n }),\n segmented(messages, 'variant', ['title', 'body', 'caption'], 'body'),\n ]\n case 'divider':\n return [text('text', s.content!), sw('dashed', s.dashed!)]\n case 'alert':\n return [\n field('select', 'tone', s.tone!, {\n default: 'neutral',\n props: {\n options: choices(messages, 'tone', [\n 'neutral',\n 'primary',\n 'success',\n 'warning',\n 'danger',\n ]),\n },\n }),\n text('title', s.title!),\n field('textarea', 'content', s.content!, {\n props: { autosize: { minRows: 2, maxRows: 8 } },\n }),\n ]\n default:\n return []\n }\n}\n\n/** What the node-level settings of a node depend on. */\nexport interface NodeSettingsContext {\n messages: FormBuilderMessages\n /** Columns of the grid the node sits on. */\n columns: number\n /** Whether the node sits in a list item, so its name is a key of the item. */\n inItem: boolean\n /** The node's type, for a field. */\n type?: FormFieldType\n}\n\n/** The builder's own type for a node's width: a number of columns, or one per breakpoint. */\nexport const SPAN_TYPE = 'dou-builder-span'\n/** The builder's own type for expression text, with completions and problems. */\nexport const EXPRESSION_TYPE = 'dou-builder-expression'\n/** The builder's own type for a condition, edited as rows or as text. */\nexport const CONDITION_TYPE = 'dou-builder-condition'\n\nfunction spanSetting(context: NodeSettingsContext): FormNode {\n // The field draws its own label, with the \"by form width\" switch on the same row.\n const node = field(SPAN_TYPE, 'span', '', {\n default: context.columns,\n props: { columns: context.columns },\n }) as FormFieldNode\n delete node.label\n return node\n}\n\n/** The settings of a node itself, besides its type's: name, label, width and so on. */\nexport function nodeSettings(node: FormNode, context: NodeSettingsContext): FormNode[] {\n const s = context.messages.settings as Record<string, string>\n const span = spanSetting(context)\n const name = text('name', context.inItem ? s.itemName! : s.name!, {\n help: context.inItem ? s.itemNameHelp : s.nameHelp,\n props: { clearable: false },\n })\n const columns = number('columns', s.columns!, {\n min: 1,\n max: 24,\n precision: 0,\n placeholder: String(context.columns),\n })\n switch (node.type) {\n case 'section':\n return [\n text('title', s.title!),\n field('textarea', 'description', s.description!, {\n props: { autosize: { minRows: 1, maxRows: 6 } },\n }),\n sw('bordered', s.bordered!),\n columns,\n span,\n ]\n case 'page':\n return [\n text('title', s.title!),\n field('textarea', 'description', s.description!, {\n props: { autosize: { minRows: 1, maxRows: 6 } },\n }),\n columns,\n ]\n case 'tabs':\n case 'steps':\n return [span]\n case 'list':\n return [\n name,\n text('label', s.label!),\n text('help', s.help!),\n span,\n number('min', s.minItems!, { min: 0, precision: 0 }, { span: 6 }),\n number('max', s.maxItems!, { min: 1, precision: 0 }, { span: 6 }),\n text('addText', s.addText!),\n sw('sortable', s.sortable!, { default: true }),\n sw('required', s.required!),\n columns,\n ]\n default: {\n const type = context.type\n if (type?.kind === 'display') return [span]\n const own = node as FormFieldNode\n const result: FormNode[] = [name, text('label', s.label!), text('help', s.help!), span]\n if (type && own.type !== 'upload')\n result.push({\n id: 'setting-default',\n type: own.type,\n name: 'default',\n label: s.default,\n props: own.props,\n } as FormFieldNode)\n result.push(sw('required', s.required!))\n return result\n }\n }\n}\n\n/** The settings of the document itself. */\nexport function documentSettings(messages: FormBuilderMessages): FormNode[] {\n const s = messages.settings as Record<string, string>\n const horizontal = \"values.layout == 'horizontal'\"\n return [\n segmented(messages, 'layout', ['vertical', 'horizontal', 'inline'], 'vertical'),\n segmented(messages, 'labelAlign', ['start', 'end'], 'start', { visibleWhen: horizontal }),\n number(\n 'labelWidth',\n s.labelWidth!,\n { min: 40, max: 400, step: 8, precision: 0 },\n { default: 96, visibleWhen: horizontal },\n ),\n segmented(messages, 'size', ['sm', 'md', 'lg'], 'md'),\n field('radio-group', 'requiredMark', s.requiredMark!, {\n default: true,\n props: { options: choices(messages, 'requiredMark', [true, 'optional', false]) },\n }),\n number('columns', s.columns!, { min: 1, max: 24, precision: 0 }, { default: 12 }),\n ]\n}\n\n/** A settings form: the nodes in a vertical, compact document. */\nexport function settingsDocument(nodes: FormNode[]): FormDocument {\n return { version: 1, size: 'sm', columns: 12, requiredMark: false, nodes }\n}\n"],"mappings":";;;;AAoCA,IAAa,gBAAgB;CAAC;CAAS;CAAU;CAAQ;CAAW;AAAQ;AAE5E,IAAM,OAAO,SAAoB,QAAQ,IAAI;;AAG7C,IAAM,eAAmE;CACvE,OAAO;EAAE,MAAM,IAAI,cAAc;EAAG,OAAO;CAAQ;CACnD,UAAU;EAAE,MAAM,IAAI,iBAAiB;EAAG,OAAO;CAAQ;CACzD,gBAAgB;EAAE,MAAM,IAAI,QAAQ;EAAG,OAAO;CAAQ;CACtD,aAAa;EAAE,MAAM,IAAI,QAAQ;EAAG,OAAO;CAAQ;CACnD,aAAa;EAAE,MAAM,IAAI,OAAO;EAAG,OAAO;CAAQ;CAClD,QAAQ;EAAE,MAAM,IAAI,qBAAqB;EAAG,OAAO;CAAS;CAC5D,eAAe;EAAE,MAAM,IAAI,SAAS;EAAG,OAAO;CAAS;CACvD,kBAAkB;EAAE,MAAM,IAAI,cAAc;EAAG,OAAO;CAAS;CAC/D,UAAU;EAAE,MAAM,IAAI,eAAe;EAAG,OAAO;CAAS;CACxD,QAAQ;EAAE,MAAM,IAAI,eAAe;EAAG,OAAO;CAAS;CACtD,qBAAqB;EAAE,MAAM,IAAI,oBAAoB;EAAG,OAAO;CAAS;CACxE,UAAU;EAAE,MAAM,IAAI,YAAY;EAAG,OAAO;CAAS;CACrD,eAAe;EAAE,MAAM,IAAI,iBAAiB;EAAG,OAAO;CAAS;CAC/D,QAAQ;EAAE,MAAM,IAAI,WAAW;EAAG,OAAO;CAAO;CAChD,MAAM;EAAE,MAAM,IAAI,QAAQ;EAAG,OAAO;CAAO;CAC3C,eAAe;EAAE,MAAM,IAAI,YAAY;EAAG,OAAO;CAAO;CACxD,eAA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IACN,OAAO,EAAE;IACT,OAAO,IAAI;GACb,CAAkB;GACpB,OAAO,KAAK,GAAG,YAAY,EAAE,QAAS,CAAC;GACvC,OAAO;EACT;CACF;AACF;;AAGA,SAAgB,iBAAiB,UAA2C;CAC1E,MAAM,IAAI,SAAS;CACnB,MAAM,aAAa;CACnB,OAAO;EACL,UAAU,UAAU,UAAU;GAAC;GAAY;GAAc;EAAQ,GAAG,UAAU;EAC9E,UAAU,UAAU,cAAc,CAAC,SAAS,KAAK,GAAG,SAAS,EAAE,aAAa,WAAW,CAAC;EACxF,OACE,cACA,EAAE,YACF;GAAE,KAAK;GAAI,KAAK;GAAK,MAAM;GAAG,WAAW;EAAE,GAC3C;GAAE,SAAS;GAAI,aAAa;EAAW,CACzC;EACA,UAAU,UAAU,QAAQ;GAAC;GAAM;GAAM;EAAI,GAAG,IAAI;EACpD,MAAM,eAAe,gBAAgB,EAAE,cAAe;GACpD,SAAS;GACT,OAAO,EAAE,SAAS,QAAQ,UAAU,gBAAgB;IAAC;IAAM;IAAY;GAAK,CAAC,EAAE;EACjF,CAAC;EACD,OAAO,WAAW,EAAE,SAAU;GAAE,KAAK;GAAG,KAAK;GAAI,WAAW;EAAE,GAAG,EAAE,SAAS,GAAG,CAAC;CAClF;AACF;;AAGA,SAAgB,iBAAiB,OAAiC;CAChE,OAAO;EAAE,SAAS;EAAG,MAAM;EAAM,SAAS;EAAI,cAAc;EAAO;CAAM;AAC3E"}
|
|
1
|
+
{"version":3,"file":"settings.js","names":[],"sources":["../../src/builder/settings.ts"],"sourcesContent":["import {\n CalendarIcon,\n CheckSquareIcon,\n ChevronDownSquareIcon,\n CircleDotIcon,\n ClockIcon,\n HashIcon,\n InfoSquareIcon,\n LayoutIcon,\n LayoutListIcon,\n ListChecksIcon,\n ListTreeIcon,\n OtpIcon,\n PaletteIcon,\n SegmentedControlIcon,\n SeparatorHorizontalIcon,\n SlidersIcon,\n SquareDashedIcon,\n StarIcon,\n StepsIcon,\n TabsIcon,\n TagsIcon,\n TextAlignLeftIcon,\n TextCursorIcon,\n ToggleRightIcon,\n TreeStructureIcon,\n TypeIcon,\n UploadIcon,\n} from '@dou-ui/icons'\nimport { markRaw } from 'vue'\nimport type { Component } from 'vue'\nimport type { FormDocument, FormFieldNode, FormListNode, FormNode } from '../core/types'\nimport type { FormFieldType } from '../fields/define'\nimport type { FormBuilderMessages } from './locale'\n\n/** The palette groups in the order they are listed; groups of other names follow. */\nexport const paletteGroups = ['input', 'choice', 'more', 'display', 'layout']\n\nconst raw = (icon: Component) => markRaw(icon)\n\n/** Icons and groups of the built-in types, kept out of the renderer's entry. */\nconst builtinLooks: Record<string, { icon: Component; group: string }> = {\n input: { icon: raw(TextCursorIcon), group: 'input' },\n textarea: { icon: raw(TextAlignLeftIcon), group: 'input' },\n 'input-number': { icon: raw(HashIcon), group: 'input' },\n 'input-tag': { icon: raw(TagsIcon), group: 'input' },\n 'input-otp': { icon: raw(OtpIcon), group: 'input' },\n select: { icon: raw(ChevronDownSquareIcon), group: 'choice' },\n 'radio-group': { icon: raw(CircleDotIcon), group: 'choice' },\n 'checkbox-group': { icon: raw(ListChecksIcon), group: 'choice' },\n checkbox: { icon: raw(CheckSquareIcon), group: 'choice' },\n switch: { icon: raw(ToggleRightIcon), group: 'choice' },\n 'segmented-control': { icon: raw(SegmentedControlIcon), group: 'choice' },\n cascader: { icon: raw(ListTreeIcon), group: 'choice' },\n 'tree-select': { icon: raw(TreeStructureIcon), group: 'choice' },\n slider: { icon: raw(SlidersIcon), group: 'more' },\n rate: { icon: raw(StarIcon), group: 'more' },\n 'date-picker': { icon: raw(CalendarIcon), group: 'more' },\n 'time-picker': { icon: raw(ClockIcon), group: 'more' },\n 'color-picker': { icon: raw(PaletteIcon), group: 'more' },\n upload: { icon: raw(UploadIcon), group: 'more' },\n text: { icon: raw(TypeIcon), group: 'display' },\n divider: { icon: raw(SeparatorHorizontalIcon), group: 'display' },\n alert: { icon: raw(InfoSquareIcon), group: 'display' },\n section: { icon: raw(SquareDashedIcon), group: 'layout' },\n tabs: { icon: raw(TabsIcon), group: 'layout' },\n steps: { icon: raw(StepsIcon), group: 'layout' },\n list: { icon: raw(LayoutListIcon), group: 'layout' },\n page: { icon: raw(LayoutIcon), group: 'layout' },\n}\n\n/** The containers the palette offers, after the field types. */\nexport const containerTypes = ['section', 'tabs', 'steps', 'list']\n\n/** A type's icon: its own, else the built-in one, else a plain box. */\nexport function iconOf(type: string, spec?: FormFieldType): Component {\n return spec?.icon ?? builtinLooks[type]?.icon ?? builtinLooks.section!.icon\n}\n\nexport function groupOf(type: string, spec?: FormFieldType): string {\n return spec?.group ?? builtinLooks[type]?.group ?? 'more'\n}\n\n/** A type's name for people: its own `label`, else the locale's. */\nexport function labelOf(\n type: string,\n spec: FormFieldType | undefined,\n messages: FormBuilderMessages,\n) {\n return spec?.label ?? messages.types[type] ?? type\n}\n\n/** What a node is called in the outline and the inspector's heading. */\nexport function nodeTitle(\n node: FormNode,\n fields: ReadonlyMap<string, FormFieldType>,\n messages: FormBuilderMessages,\n): string {\n const record = node as unknown as Record<string, unknown>\n const own = (record.label ?? record.title) as string | undefined\n if (own) return own\n if ('name' in node && node.name) return node.name\n return labelOf(node.type, fields.get(node.type), messages)\n}\n\n// Settings ----------------------------------------------------------------------\n\ntype Setting = Record<string, unknown>\n\nexport const field = (type: string, name: string, label: string, extra: Setting = {}): FormNode =>\n ({ id: `setting-${name}`, type, name, label, ...extra }) as FormFieldNode\n\nconst sw = (name: string, label: string, extra: Setting = {}) => field('switch', name, label, extra)\nexport const text = (name: string, label: string, extra: Setting = {}) =>\n field('input', name, label, { ...extra, props: { clearable: true, ...(extra.props as Setting) } })\nexport const number = (name: string, label: string, props: Setting = {}, extra: Setting = {}) =>\n field('input-number', name, label, { ...extra, props: { controls: false, ...props } })\n\nexport function choices(\n messages: FormBuilderMessages,\n key: string,\n values: readonly (string | boolean)[],\n): { value: string | boolean; label: string }[] {\n const labels = messages.choices[key] ?? {}\n return values.map((value) => ({ value, label: labels[String(value)] ?? String(value) }))\n}\n\nexport const segmented = (\n messages: FormBuilderMessages,\n name: string,\n values: readonly string[],\n fallback: string,\n extra: Setting = {},\n key = name,\n) =>\n field('segmented-control', name, messages.settings[key] ?? name, {\n default: fallback,\n props: { options: choices(messages, key, values), block: true },\n ...extra,\n })\n\nfunction optionList(messages: FormBuilderMessages, name = 'options'): FormListNode {\n const s = messages.settings\n return {\n id: `setting-${name}`,\n type: 'list',\n name,\n label: s.options,\n columns: 12,\n children: [\n field('input', 'label', s.optionLabel!, { span: 6 }),\n field('input', 'value', s.optionValue!, { span: 6 }),\n ],\n }\n}\n\n/** Settings of the built-in types, edited in a node's `props`. */\nexport function builtinSettings(type: string, messages: FormBuilderMessages): FormNode[] {\n const s = messages.settings as Record<string, string>\n const placeholder = text('placeholder', s.placeholder!)\n const clearable = sw('clearable', s.clearable!)\n const multiple = sw('multiple', s.multiple!)\n const filterable = sw('filterable', s.filterable!)\n const options = optionList(messages)\n const direction = segmented(messages, 'direction', ['horizontal', 'vertical'], 'horizontal')\n switch (type) {\n case 'input':\n return [\n placeholder,\n clearable,\n number('maxlength', s.maxlength!, { min: 1 }),\n sw('showCount', s.showCount!),\n ]\n case 'textarea':\n return [\n placeholder,\n number('rows', s.rows!, { min: 1, placeholder: '3' }),\n sw('autosize', s.autosize!),\n number('maxlength', s.maxlength!, { min: 1 }),\n sw('showCount', s.showCount!),\n ]\n case 'input-number':\n return [\n placeholder,\n number('min', s.min!, {}, { span: 6 }),\n number('max', s.max!, {}, { span: 6 }),\n number('step', s.step!, { min: 0, placeholder: '1' }, { span: 6 }),\n number('precision', s.precision!, { min: 0, precision: 0 }, { span: 6 }),\n sw('controls', s.controls!, { default: true }),\n ]\n case 'select':\n return [options, placeholder, multiple, filterable, clearable]\n case 'radio-group':\n case 'checkbox-group':\n return [options, direction]\n case 'segmented-control':\n return [options]\n case 'checkbox':\n return [text('text', s.text!)]\n case 'slider':\n return [\n number('min', s.min!, {}, { span: 6, default: 0 }),\n number('max', s.max!, {}, { span: 6, default: 100 }),\n number('step', s.step!, { min: 0 }, { default: 1 }),\n sw('range', s.range!),\n ]\n case 'rate':\n return [\n number('max', s.count!, { min: 1, max: 10, precision: 0 }, { default: 5 }),\n sw('allowHalf', s.allowHalf!),\n ]\n case 'date-picker':\n return [\n field('select', 'type', s.dateType!, {\n default: 'date',\n props: {\n options: choices(messages, 'dateType', [\n 'date',\n 'week',\n 'month',\n 'quarter',\n 'year',\n 'datetime',\n ]),\n },\n }),\n sw('range', s.range!, { visibleWhen: \"values.type != 'week'\" }),\n placeholder,\n clearable,\n ]\n case 'time-picker':\n return [sw('range', s.range!), placeholder, clearable]\n case 'color-picker':\n return [sw('showAlpha', s.showAlpha!), clearable]\n case 'cascader':\n case 'tree-select':\n return [placeholder, multiple, filterable, clearable]\n case 'input-tag':\n return [placeholder, number('max', s.maxTags!, { min: 1, precision: 0 }), clearable]\n case 'input-otp':\n return [\n number('length', s.length!, { min: 1, max: 12, precision: 0 }, { default: 6 }),\n sw('mask', s.mask!),\n ]\n case 'upload':\n return [\n text('accept', s.accept!, { props: { placeholder: 'image/*, .pdf' } }),\n multiple,\n number('maxCount', s.maxCount!, { min: 1, precision: 0 }),\n sw('dropzone', s.dropzone!),\n ]\n case 'text':\n return [\n field('textarea', 'content', s.content!, {\n props: { autosize: { minRows: 2, maxRows: 8 } },\n }),\n segmented(messages, 'variant', ['title', 'body', 'caption'], 'body'),\n ]\n case 'divider':\n return [text('text', s.content!), sw('dashed', s.dashed!)]\n case 'alert':\n return [\n field('select', 'tone', s.tone!, {\n default: 'neutral',\n props: {\n options: choices(messages, 'tone', [\n 'neutral',\n 'primary',\n 'success',\n 'warning',\n 'danger',\n ]),\n },\n }),\n text('title', s.title!),\n field('textarea', 'content', s.content!, {\n props: { autosize: { minRows: 2, maxRows: 8 } },\n }),\n ]\n default:\n return []\n }\n}\n\n/** What the node-level settings of a node depend on. */\nexport interface NodeSettingsContext {\n messages: FormBuilderMessages\n /** Columns of the grid the node sits on. */\n columns: number\n /** Whether the node sits in a list item, so its name is a key of the item. */\n inItem: boolean\n /** The node's type, for a field. */\n type?: FormFieldType\n}\n\n/** The builder's own type for a node's width: a number of columns, or one per breakpoint. */\nexport const SPAN_TYPE = 'dou-builder-span'\n/** The builder's own type for expression text, with completions and problems. */\nexport const EXPRESSION_TYPE = 'dou-builder-expression'\n/** The builder's own type for a condition, edited as rows or as text. */\nexport const CONDITION_TYPE = 'dou-builder-condition'\n\nfunction spanSetting(context: NodeSettingsContext): FormNode {\n // The field draws its own label, with the \"by form width\" switch on the same row.\n const node = field(SPAN_TYPE, 'span', '', {\n default: context.columns,\n props: { columns: context.columns },\n }) as FormFieldNode\n delete node.label\n return node\n}\n\n/** The settings of a node itself, besides its type's: name, label, width and so on. */\nexport function nodeSettings(node: FormNode, context: NodeSettingsContext): FormNode[] {\n const s = context.messages.settings as Record<string, string>\n const span = spanSetting(context)\n const name = text('name', context.inItem ? s.itemName! : s.name!, {\n help: context.inItem ? s.itemNameHelp : s.nameHelp,\n props: { clearable: false },\n })\n const columns = number('columns', s.columns!, {\n min: 1,\n max: 24,\n precision: 0,\n placeholder: String(context.columns),\n })\n switch (node.type) {\n case 'section':\n return [\n text('title', s.title!),\n field('textarea', 'description', s.description!, {\n props: { autosize: { minRows: 1, maxRows: 6 } },\n }),\n sw('bordered', s.bordered!),\n columns,\n span,\n ]\n case 'page':\n return [\n text('title', s.title!),\n field('textarea', 'description', s.description!, {\n props: { autosize: { minRows: 1, maxRows: 6 } },\n }),\n columns,\n ]\n case 'tabs':\n case 'steps':\n return [span]\n case 'list':\n return [\n name,\n text('label', s.label!),\n text('help', s.help!),\n span,\n number('min', s.minItems!, { min: 0, precision: 0 }, { span: 6 }),\n number('max', s.maxItems!, { min: 1, precision: 0 }, { span: 6 }),\n text('addText', s.addText!),\n sw('sortable', s.sortable!, { default: true }),\n sw('required', s.required!),\n columns,\n ]\n default: {\n const type = context.type\n if (type?.kind === 'display') return [span]\n const own = node as FormFieldNode\n const result: FormNode[] = [name, text('label', s.label!), text('help', s.help!), span]\n if (type && own.type !== 'upload')\n result.push({\n id: 'setting-default',\n type: own.type,\n name: 'default',\n label: s.default,\n props: own.props,\n } as FormFieldNode)\n result.push(sw('required', s.required!))\n return result\n }\n }\n}\n\n/** The settings of the document itself. */\nexport function documentSettings(messages: FormBuilderMessages): FormNode[] {\n const s = messages.settings as Record<string, string>\n const horizontal = \"values.layout == 'horizontal'\"\n return [\n segmented(messages, 'layout', ['vertical', 'horizontal', 'inline'], 'vertical'),\n segmented(messages, 'labelAlign', ['start', 'end'], 'start', { visibleWhen: horizontal }),\n number(\n 'labelWidth',\n s.labelWidth!,\n { min: 40, max: 400, step: 8, precision: 0 },\n { default: 96, visibleWhen: horizontal },\n ),\n segmented(messages, 'size', ['sm', 'md', 'lg'], 'md'),\n field('radio-group', 'requiredMark', s.requiredMark!, {\n default: true,\n props: { options: choices(messages, 'requiredMark', [true, 'optional', false]) },\n }),\n number('columns', s.columns!, { min: 1, max: 24, precision: 0 }, { default: 12 }),\n ]\n}\n\n/** A settings form: the nodes in a vertical, compact document. */\nexport function settingsDocument(nodes: FormNode[]): FormDocument {\n return { version: 1, size: 'sm', columns: 12, requiredMark: false, nodes }\n}\n"],"mappings":";;;;AAoCA,IAAa,gBAAgB;CAAC;CAAS;CAAU;CAAQ;CAAW;AAAQ;AAE5E,IAAM,OAAO,SAAoB,QAAQ,IAAI;;AAG7C,IAAM,eAAmE;CACvE,OAAO;EAAE,MAAM,IAAI,cAAc;EAAG,OAAO;CAAQ;CACnD,UAAU;EAAE,MAAM,IAAI,iBAAiB;EAAG,OAAO;CAAQ;CACzD,gBAAgB;EAAE,MAAM,IAAI,QAAQ;EAAG,OAAO;CAAQ;CACtD,aAAa;EAAE,MAAM,IAAI,QAAQ;EAAG,OAAO;CAAQ;CACnD,aAAa;EAAE,MAAM,IAAI,OAAO;EAAG,OAAO;CAAQ;CAClD,QAAQ;EAAE,MAAM,IAAI,qBAAqB;EAAG,OA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C,EAAE;EACjF,CAAC;EACD,OAAO,WAAW,EAAE,SAAU;GAAE,KAAK;GAAG,KAAK;GAAI,WAAW;EAAE,GAAG,EAAE,SAAS,GAAG,CAAC;CAClF;AACF;;AAGA,SAAgB,iBAAiB,OAAiC;CAChE,OAAO;EAAE,SAAS;EAAG,MAAM;EAAM,SAAS;EAAI,cAAc;EAAO;CAAM;AAC3E"}
|
|
@@ -74,7 +74,7 @@ function writeOrder(map, parent, children) {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
/** Writes a form into empty maps, e.g. when a form so far saved as JSON starts being edited together. */
|
|
77
|
-
function fillMaps(maps, document) {
|
|
77
|
+
function fillMaps(maps, document, options = {}) {
|
|
78
78
|
const fill = () => {
|
|
79
79
|
for (const node of walkNodes(document.nodes)) writeNode(maps.nodes, node);
|
|
80
80
|
writeOrder(maps.nodes, null, document.nodes);
|
|
@@ -82,7 +82,7 @@ function fillMaps(maps, document) {
|
|
|
82
82
|
for (const [key, value] of Object.entries(document)) if (key !== "nodes" && key !== "version" && value !== void 0) maps.settings.set(key, value);
|
|
83
83
|
};
|
|
84
84
|
const ydoc = maps.nodes.doc;
|
|
85
|
-
if (ydoc) ydoc.transact(fill);
|
|
85
|
+
if (ydoc) ydoc.transact(fill, options.origin ?? null);
|
|
86
86
|
else fill();
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/collaboration/index.ts"],"sourcesContent":["import { collaborationColors } from 'dou-ui'\nimport { computed, shallowRef, watch } from 'vue'\nimport * as Y from 'yjs'\nimport { isContainer, walkNodes } from '../core/document'\nimport type { FormContainerNode, FormDocument, FormNode } from '../core/types'\nimport type { FormBuilderContext } from '../builder/context'\nimport { replaceDocument } from '../builder/core/commands'\nimport { canContainFormNode, formNodePlaces } from '../builder/core/transaction'\nimport type { FormBuilderTransaction } from '../builder/core/transaction'\nimport { defineFormBuilderExtension } from '../builder/extension'\nimport type { FormBuilderExtension, FormBuilderNodeMark } from '../builder/extension'\nimport { orderKeys } from './order'\n\n/** The part of an `Awareness` (`y-protocols/awareness`) the builder uses. */\nexport interface AwarenessLike {\n clientID: number\n getLocalState(): Record<string, unknown> | null\n setLocalStateField(field: string, value: unknown): void\n getStates(): Map<number, Record<string, unknown>>\n on(event: 'change', listener: (...args: unknown[]) => void): void\n off(event: 'change', listener: (...args: unknown[]) => void): void\n}\n\n/** How the people editing together see each other. */\nexport interface CollaborationUser {\n name: string\n /** The color of this user's marks, any CSS color. Picked from the client id when left out. */\n color?: string\n}\n\nexport interface CollaborationOptions {\n /** Where the nodes live, e.g. `ydoc.getMap('nodes')`. */\n nodes: Y.Map<unknown>\n /** Where the form's own settings live, e.g. `ydoc.getMap('settings')`; in the same `Y.Doc` as `nodes`. */\n settings: Y.Map<unknown>\n /** Shares what each person has selected (`y-protocols/awareness`). */\n awareness?: AwarenessLike\n /** This user, shown to the others. Needs `awareness`. */\n user?: CollaborationUser\n}\n\n/** What each person shares under the awareness field `formBuilder`. */\nexport interface FormBuilderPresence {\n selection: string[]\n}\n\nexport { collaborationColors }\n\ntype Shared = Y.Map<unknown>\ntype Item = Record<string, unknown>\n\n/** The container a node is in (`null`: the top of the form) and its place there, kept beside its keys. */\nconst PARENT = '$parent'\nconst ORDER = '$order'\n\nconst same = (a: unknown, b: unknown) =>\n a === b ||\n (typeof a === 'object' && typeof b === 'object' && JSON.stringify(a) === JSON.stringify(b))\n\n/** Where in `value` something JSON can't carry sits, e.g. a component or a function. */\nfunction unshareable(value: unknown, path: string): string | null {\n if (value === null || ['string', 'number', 'boolean', 'undefined'].includes(typeof value))\n return null\n if (typeof value !== 'object') return path\n if (Array.isArray(value)) {\n for (const [i, item] of value.entries()) {\n const found = unshareable(item, `${path}[${i}]`)\n if (found) return found\n }\n return null\n }\n const proto = Object.getPrototypeOf(value)\n if (proto !== Object.prototype && proto !== null) return path\n for (const [key, item] of Object.entries(value)) {\n const found = unshareable(item, `${path}.${key}`)\n if (found) return found\n }\n return null\n}\n\nconst warned = new Set<string>()\n/** Others would get a broken copy of such a value while this builder shows it fine. */\nfunction warnUnshareable(id: string, key: string, value: unknown) {\n // the app's bundler replaces this, as for Vue's own warnings\n if (process.env.NODE_ENV === 'production') return\n const path = unshareable(value, key)\n if (!path || warned.has(`${id}:${path}`)) return\n warned.add(`${id}:${path}`)\n console.warn(\n `[@dou-ui/form-builder] \"${id}\" has ${path}, which can't be shared: only JSON values reach the others. Store a name and look the component or function up where it is used.`,\n )\n}\n\n/** Writes a node's keys besides its place, only those that changed; `keys` limits which. */\nfunction writeNode(map: Shared, node: FormNode, keys?: Set<string>) {\n const existing = map.get(node.id)\n const fields: Shared = existing instanceof Y.Map ? existing : new Y.Map<unknown>()\n const fresh = existing !== fields\n const item = node as unknown as Item\n for (const [key, value] of Object.entries(item)) {\n if (key === 'id' || key === 'children' || value === undefined) continue\n if (keys && !fresh && !keys.has(key)) continue\n warnUnshareable(node.id, key, value)\n // a new map can't be read before it is in the document\n if (fresh || !same(fields.get(key), value)) fields.set(key, value)\n }\n if (fresh) return void map.set(node.id, fields)\n for (const key of Array.from(fields.keys()))\n if (key[0] !== '$' && item[key] === undefined && (!keys || keys.has(key))) fields.delete(key)\n}\n\n/** Writes the place of each child of a container, giving new order keys only where it must. */\nfunction writeOrder(map: Shared, parent: string | null, children: readonly FormNode[]) {\n const shared = children.map((child) => {\n const fields = map.get(child.id)\n return fields instanceof Y.Map ? fields : null\n })\n const current = shared.map((fields) =>\n fields && (fields.get(PARENT) ?? null) === parent\n ? ((fields.get(ORDER) as string | undefined) ?? null)\n : null,\n )\n const keys = orderKeys(current)\n shared.forEach((fields, index) => {\n if (!fields) return\n if ((fields.get(PARENT) ?? null) !== parent) fields.set(PARENT, parent)\n if (fields.get(ORDER) !== keys[index]) fields.set(ORDER, keys[index])\n })\n}\n\n/** Writes a form into empty maps, e.g. when a form so far saved as JSON starts being edited together. */\nexport function fillMaps(\n maps: { nodes: Y.Map<unknown>; settings: Y.Map<unknown> },\n document: FormDocument,\n) {\n const fill = () => {\n for (const node of walkNodes(document.nodes)) writeNode(maps.nodes, node)\n writeOrder(maps.nodes, null, document.nodes)\n for (const node of walkNodes(document.nodes))\n if (isContainer(node)) writeOrder(maps.nodes, node.id, node.children)\n for (const [key, value] of Object.entries(document))\n if (key !== 'nodes' && key !== 'version' && value !== undefined) maps.settings.set(key, value)\n }\n const ydoc = maps.nodes.doc\n if (ydoc) ydoc.transact(fill)\n else fill()\n}\n\ninterface Entry {\n node: FormNode\n parent: string | null\n order: string\n}\n\n/**\n * The form the maps hold. A node whose container is gone, e.g. one moved\n * into a section while another person deleted the section, goes to the top\n * of the form. So do containers two people moved into each other at once:\n * the one with the smallest id goes to the top, the same for everyone.\n * Both are listed in `lifted`.\n */\nexport function readMaps(maps: { nodes: Y.Map<unknown>; settings: Y.Map<unknown> }): {\n document: FormDocument\n lifted: string[]\n} {\n const entries = new Map<string, Entry>()\n maps.nodes.forEach((value, id) => {\n if (!(value instanceof Y.Map)) return\n const { [PARENT]: parent, [ORDER]: order, ...rest } = value.toJSON() as Item\n entries.set(id, {\n node: { ...rest, id } as unknown as FormNode,\n parent: typeof parent === 'string' ? parent : null,\n order: typeof order === 'string' ? order : '',\n })\n })\n\n const lifted: string[] = []\n const reached = new Set<string>()\n // Walk up from each node until the top or a node already reached.\n const reach = (id: string) => {\n const path: string[] = []\n let current: string | null = id\n while (current !== null && !reached.has(current)) {\n const entry: Entry = entries.get(current)!\n const loop = path.indexOf(current)\n if (loop >= 0) {\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a copy\n const top = path.slice(loop).sort()[0]!\n entries.get(top)!.parent = null\n lifted.push(top)\n return reach(id)\n }\n path.push(current)\n if (entry.parent !== null && !entries.has(entry.parent)) {\n entry.parent = null\n lifted.push(current)\n }\n current = entry.parent\n }\n for (const each of path) reached.add(each)\n }\n for (const id of entries.keys()) if (!reached.has(id)) reach(id)\n\n const byParent = new Map<string | null, Entry[]>()\n for (const entry of entries.values()) {\n const list = byParent.get(entry.parent)\n if (list) list.push(entry)\n else byParent.set(entry.parent, [entry])\n }\n const build = (parent: FormNode | null): FormNode[] => {\n const list = byParent.get(parent?.id ?? null) ?? []\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts the list built here\n list.sort((a, b) =>\n a.order < b.order ? -1 : a.order > b.order ? 1 : a.node.id < b.node.id ? -1 : 1,\n )\n const nodes: FormNode[] = []\n for (const { node } of list) {\n // A node that can't be here, e.g. a field among pages, waits until it can.\n if (!canContainFormNode(parent, node)) continue\n nodes.push(\n isContainer(node)\n ? ({ ...node, children: build(node) } as FormContainerNode)\n : (node as FormNode),\n )\n }\n return nodes\n }\n const settings = maps.settings.toJSON() as Item\n delete settings.nodes\n delete settings.version\n return {\n document: { ...settings, version: 1, nodes: build(null) } as FormDocument,\n lifted,\n }\n}\n\n/** The nodes, places and settings a transaction changed, written to the maps. */\nfunction writeChanges(maps: { nodes: Shared; settings: Shared }, tr: FormBuilderTransaction) {\n const after = formNodePlaces(tr.doc)\n const touched = new Map<string, Set<string> | true>()\n const parents = new Set<string | null>()\n const settings = new Set<string>()\n let removed = false\n const mark = (id: string, keys: string[] | true) => {\n const current = touched.get(id)\n if (current === true) return\n if (keys === true) return void touched.set(id, true)\n const set = current ?? new Set<string>()\n for (const key of keys) set.add(key)\n touched.set(id, set)\n }\n for (const step of tr.steps) {\n if (step.type === 'insert') {\n parents.add(step.parent)\n for (const node of walkNodes([step.node])) {\n mark(node.id, true)\n if (isContainer(node)) parents.add(node.id)\n }\n } else if (step.type === 'remove') removed = true\n else if (step.type === 'update') mark(step.id, Object.keys(step.patch))\n else if (step.type === 'move') parents.add(step.parent)\n else for (const key of Object.keys(step.patch)) settings.add(key)\n }\n\n if (removed)\n for (const id of formNodePlaces(tr.before).keys()) if (!after.has(id)) maps.nodes.delete(id)\n for (const [id, keys] of touched) {\n const node = after.get(id)?.node\n if (node) writeNode(maps.nodes, node, keys === true ? undefined : keys)\n }\n for (const parent of parents) {\n if (parent === null) writeOrder(maps.nodes, null, tr.doc.nodes)\n else {\n const node = after.get(parent)?.node\n if (node && isContainer(node)) writeOrder(maps.nodes, parent, node.children)\n }\n }\n const document = tr.doc as unknown as Item\n for (const key of settings) {\n const value = document[key]\n if (value === undefined) maps.settings.delete(key)\n else if (!same(maps.settings.get(key), value)) maps.settings.set(key, value)\n }\n}\n\ninterface Peer {\n client: number\n name: string\n color: string\n selection: string[]\n}\n\n/**\n * Edit a form together through a Yjs document. Each node lives in `nodes`\n * as its own `Y.Map`, each key on its own, with its container and an order\n * key beside them; so two people changing different keys of one field both\n * keep their change, and moving a node only writes that node. The form's\n * settings live in `settings`. The builder's `v-model` only mirrors them:\n * a form set through `v-model` from outside is not written back. Undo only\n * takes back this user's own changes. With `awareness`, each person sees\n * what the others have selected, marked in their colors.\n */\nexport function collaboration(options: CollaborationOptions): FormBuilderExtension {\n const { nodes, settings, awareness, user } = options\n const ydoc = nodes.doc\n if (!ydoc || settings.doc !== ydoc)\n throw new Error('[@dou-ui/form-builder] nodes and settings must be maps of the same Y.Doc')\n if (awareness && user) {\n const color = user.color ?? collaborationColors[ydoc.clientID % collaborationColors.length]\n awareness.setLocalStateField('user', { name: user.name, color })\n }\n const maps = { nodes, settings }\n\n /** This builder's own changes, which undo can take back. */\n const tracked = { formBuilder: 'tracked' }\n /** Changes undo leaves alone, e.g. filling the maps or lifting nodes out of deleted containers. */\n const untracked = { formBuilder: 'untracked' }\n const undoManager = new Y.UndoManager([nodes, settings], {\n trackedOrigins: new Set([tracked]),\n captureTimeout: 500,\n })\n let context: FormBuilderContext | undefined\n /** Set while shared changes are applied to the builder, so they aren't written back. */\n let applying = false\n /** What undo or redo is running, to name the change. */\n let travelling: 'undo' | 'redo' | null = null\n /** The selection to go back to once undo or redo has run. */\n let restore: string[] | undefined\n let lastGroup: string | undefined\n\n // Each step of undo keeps the selection from before it, and each step of redo the one after.\n undoManager.on('stack-item-added', (event: { stackItem: { meta: Map<string, unknown> } }) => {\n event.stackItem.meta.set('selection', context?.selection.slice() ?? [])\n })\n undoManager.on('stack-item-popped', (event: { stackItem: { meta: Map<string, unknown> } }) => {\n restore = event.stackItem.meta.get('selection') as string[] | undefined\n })\n\n /** Brings the builder in line with the maps. */\n function pull() {\n if (!context) return\n const { document, lifted } = readMaps(maps)\n const tr = context.transaction()\n try {\n replaceDocument(tr, document)\n } catch (error) {\n console.error('[@dou-ui/form-builder] could not apply a shared change', error)\n return\n }\n if (tr.changed) {\n tr.setMeta('history', false)\n tr.setMeta('origin', travelling ?? 'remote')\n applying = true\n try {\n context.dispatch(tr)\n } finally {\n applying = false\n }\n }\n // Everyone works these out alike; writing them keeps the maps tidy.\n if (lifted.length)\n queueMicrotask(() =>\n ydoc!.transact(() => {\n for (const id of lifted) {\n const fields = nodes.get(id)\n if (fields instanceof Y.Map && fields.get(PARENT) !== null) fields.set(PARENT, null)\n }\n }, untracked),\n )\n }\n\n function run(action: 'undo' | 'redo') {\n const stack = action === 'undo' ? undoManager.undoStack : undoManager.redoStack\n if (!stack.length) return false\n travelling = action\n restore = undefined\n try {\n undoManager[action]()\n } finally {\n travelling = null\n }\n if (restore && context) context.select(restore)\n restore = undefined\n return true\n }\n\n const peers = shallowRef<Peer[]>([])\n /** The others who have each node selected. */\n const marksByNode = computed(() => {\n const map = new Map<string, FormBuilderNodeMark[]>()\n for (const peer of peers.value)\n for (const id of peer.selection) {\n const mark = { key: `peer-${peer.client}`, label: peer.name, color: peer.color }\n const list = map.get(id)\n if (list) list.push(mark)\n else map.set(id, [mark])\n }\n return map\n })\n\n return defineFormBuilderExtension({\n name: 'collaboration',\n // after the other extensions, so it writes what they added\n priority: 0,\n transaction(tr) {\n if (applying) return\n const tracking = tr.meta.history !== false\n // like the builder's own history: only changes of one group undo together\n if (tracking && (!tr.meta.group || tr.meta.group !== lastGroup)) undoManager.stopCapturing()\n if (tracking) lastGroup = tr.meta.group\n ydoc.transact(() => writeChanges(maps, tr), tracking ? tracked : untracked)\n },\n history: () => ({\n undo: () => run('undo'),\n redo: () => run('redo'),\n canUndo: () => undoManager.undoStack.length > 0,\n canRedo: () => undoManager.redoStack.length > 0,\n }),\n marks: awareness ? (_context, node) => marksByNode.value.get(node.id) ?? [] : undefined,\n setup(builder) {\n context = builder\n // the first one to open the form brings its nodes; everyone else reads the maps\n if (!nodes.size && !settings.size)\n ydoc.transact(() => fillMaps(maps, builder.document), untracked)\n pull()\n\n // changes from others, and from undo: applied once per Yjs transaction\n let dirty = false\n const observe = (_events: unknown, transaction: Y.Transaction) => {\n if (transaction.origin !== tracked && transaction.origin !== untracked) dirty = true\n }\n const flush = () => {\n if (!dirty) return\n dirty = false\n pull()\n }\n nodes.observeDeep(observe)\n settings.observeDeep(observe)\n ydoc.on('afterTransaction', flush)\n\n let stopPresence: (() => void) | undefined\n let readPeers: (() => void) | undefined\n if (awareness) {\n readPeers = () => {\n const list: Peer[] = []\n awareness.getStates().forEach((state, client) => {\n if (client === awareness.clientID) return\n const who = state.user as { name?: string; color?: string } | undefined\n const presence = state.formBuilder as FormBuilderPresence | null | undefined\n if (!who || !presence?.selection?.length) return\n list.push({\n client,\n name: who.name ?? '',\n color: who.color ?? 'currentColor',\n selection: presence.selection,\n })\n })\n peers.value = list\n }\n readPeers()\n awareness.on('change', readPeers)\n stopPresence = watch(\n () => builder.selection,\n (selection) =>\n awareness.setLocalStateField('formBuilder', {\n selection: selection.slice(0, 100),\n } satisfies FormBuilderPresence),\n { immediate: true },\n )\n }\n\n return () => {\n nodes.unobserveDeep(observe)\n settings.unobserveDeep(observe)\n ydoc.off('afterTransaction', flush)\n stopPresence?.()\n if (readPeers) awareness?.off('change', readPeers)\n awareness?.setLocalStateField('formBuilder', null)\n context = undefined\n }\n },\n })\n}\n"],"mappings":";;;;;;;;;;AAoDA,IAAM,SAAS;AACf,IAAM,QAAQ;AAEd,IAAM,QAAQ,GAAY,MACxB,MAAM,KACL,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,KAAK,U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AW,SAAS;MACtB,CAAC;KACH,CAAC;KACD,MAAM,QAAQ;IAChB;IACA,UAAU;IACV,UAAU,GAAG,UAAU,SAAS;IAChC,eAAe,YACP,QAAQ,YACb,cACC,UAAU,mBAAmB,eAAe,EAC1C,WAAW,UAAU,MAAM,GAAG,GAAG,EACnC,CAA+B,GACjC,EAAE,WAAW,KAAK,CACpB;GACF;GAEA,aAAa;IACX,MAAM,cAAc,OAAO;IAC3B,SAAS,cAAc,OAAO;IAC9B,KAAK,IAAI,oBAAoB,KAAK;IAClC,eAAe;IACf,IAAI,WAAW,WAAW,IAAI,UAAU,SAAS;IACjD,WAAW,mBAAmB,eAAe,IAAI;IACjD,UAAU,KAAA;GACZ;EACF;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/collaboration/index.ts"],"sourcesContent":["import { collaborationColors } from 'dou-ui'\nimport { computed, shallowRef, watch } from 'vue'\nimport * as Y from 'yjs'\nimport { isContainer, walkNodes } from '../core/document'\nimport type { FormContainerNode, FormDocument, FormNode } from '../core/types'\nimport type { FormBuilderContext } from '../builder/context'\nimport { replaceDocument } from '../builder/core/commands'\nimport { canContainFormNode, formNodePlaces } from '../builder/core/transaction'\nimport type { FormBuilderTransaction } from '../builder/core/transaction'\nimport { defineFormBuilderExtension } from '../builder/extension'\nimport type { FormBuilderExtension, FormBuilderNodeMark } from '../builder/extension'\nimport { orderKeys } from './order'\n\n/** The part of an `Awareness` (`y-protocols/awareness`) the builder uses. */\nexport interface AwarenessLike {\n clientID: number\n getLocalState(): Record<string, unknown> | null\n setLocalStateField(field: string, value: unknown): void\n getStates(): Map<number, Record<string, unknown>>\n on(event: 'change', listener: (...args: unknown[]) => void): void\n off(event: 'change', listener: (...args: unknown[]) => void): void\n}\n\n/** How the people editing together see each other. */\nexport interface CollaborationUser {\n name: string\n /** The color of this user's marks, any CSS color. Picked from the client id when left out. */\n color?: string\n}\n\nexport interface CollaborationOptions {\n /** Where the nodes live, e.g. `ydoc.getMap('nodes')`. */\n nodes: Y.Map<unknown>\n /** Where the form's own settings live, e.g. `ydoc.getMap('settings')`; in the same `Y.Doc` as `nodes`. */\n settings: Y.Map<unknown>\n /** Shares what each person has selected (`y-protocols/awareness`). */\n awareness?: AwarenessLike\n /** This user, shown to the others. Needs `awareness`. */\n user?: CollaborationUser\n}\n\n/** What each person shares under the awareness field `formBuilder`. */\nexport interface FormBuilderPresence {\n selection: string[]\n}\n\nexport { collaborationColors }\n\ntype Shared = Y.Map<unknown>\ntype Item = Record<string, unknown>\n\n/** The container a node is in (`null`: the top of the form) and its place there, kept beside its keys. */\nconst PARENT = '$parent'\nconst ORDER = '$order'\n\nconst same = (a: unknown, b: unknown) =>\n a === b ||\n (typeof a === 'object' && typeof b === 'object' && JSON.stringify(a) === JSON.stringify(b))\n\n/** Where in `value` something JSON can't carry sits, e.g. a component or a function. */\nfunction unshareable(value: unknown, path: string): string | null {\n if (value === null || ['string', 'number', 'boolean', 'undefined'].includes(typeof value))\n return null\n if (typeof value !== 'object') return path\n if (Array.isArray(value)) {\n for (const [i, item] of value.entries()) {\n const found = unshareable(item, `${path}[${i}]`)\n if (found) return found\n }\n return null\n }\n const proto = Object.getPrototypeOf(value)\n if (proto !== Object.prototype && proto !== null) return path\n for (const [key, item] of Object.entries(value)) {\n const found = unshareable(item, `${path}.${key}`)\n if (found) return found\n }\n return null\n}\n\nconst warned = new Set<string>()\n/** Others would get a broken copy of such a value while this builder shows it fine. */\nfunction warnUnshareable(id: string, key: string, value: unknown) {\n // the app's bundler replaces this, as for Vue's own warnings\n if (process.env.NODE_ENV === 'production') return\n const path = unshareable(value, key)\n if (!path || warned.has(`${id}:${path}`)) return\n warned.add(`${id}:${path}`)\n console.warn(\n `[@dou-ui/form-builder] \"${id}\" has ${path}, which can't be shared: only JSON values reach the others. Store a name and look the component or function up where it is used.`,\n )\n}\n\n/** Writes a node's keys besides its place, only those that changed; `keys` limits which. */\nfunction writeNode(map: Shared, node: FormNode, keys?: Set<string>) {\n const existing = map.get(node.id)\n const fields: Shared = existing instanceof Y.Map ? existing : new Y.Map<unknown>()\n const fresh = existing !== fields\n const item = node as unknown as Item\n for (const [key, value] of Object.entries(item)) {\n if (key === 'id' || key === 'children' || value === undefined) continue\n if (keys && !fresh && !keys.has(key)) continue\n warnUnshareable(node.id, key, value)\n // a new map can't be read before it is in the document\n if (fresh || !same(fields.get(key), value)) fields.set(key, value)\n }\n if (fresh) return void map.set(node.id, fields)\n for (const key of Array.from(fields.keys()))\n if (key[0] !== '$' && item[key] === undefined && (!keys || keys.has(key))) fields.delete(key)\n}\n\n/** Writes the place of each child of a container, giving new order keys only where it must. */\nfunction writeOrder(map: Shared, parent: string | null, children: readonly FormNode[]) {\n const shared = children.map((child) => {\n const fields = map.get(child.id)\n return fields instanceof Y.Map ? fields : null\n })\n const current = shared.map((fields) =>\n fields && (fields.get(PARENT) ?? null) === parent\n ? ((fields.get(ORDER) as string | undefined) ?? null)\n : null,\n )\n const keys = orderKeys(current)\n shared.forEach((fields, index) => {\n if (!fields) return\n if ((fields.get(PARENT) ?? null) !== parent) fields.set(PARENT, parent)\n if (fields.get(ORDER) !== keys[index]) fields.set(ORDER, keys[index])\n })\n}\n\nexport interface FillMapsOptions {\n /** The origin of the Yjs transaction, so the others can tell who wrote it. */\n origin?: unknown\n}\n\n/** Writes a form into empty maps, e.g. when a form so far saved as JSON starts being edited together. */\nexport function fillMaps(\n maps: { nodes: Y.Map<unknown>; settings: Y.Map<unknown> },\n document: FormDocument,\n options: FillMapsOptions = {},\n) {\n const fill = () => {\n for (const node of walkNodes(document.nodes)) writeNode(maps.nodes, node)\n writeOrder(maps.nodes, null, document.nodes)\n for (const node of walkNodes(document.nodes))\n if (isContainer(node)) writeOrder(maps.nodes, node.id, node.children)\n for (const [key, value] of Object.entries(document))\n if (key !== 'nodes' && key !== 'version' && value !== undefined) maps.settings.set(key, value)\n }\n const ydoc = maps.nodes.doc\n if (ydoc) ydoc.transact(fill, options.origin ?? null)\n else fill()\n}\n\ninterface Entry {\n node: FormNode\n parent: string | null\n order: string\n}\n\n/**\n * The form the maps hold. A node whose container is gone, e.g. one moved\n * into a section while another person deleted the section, goes to the top\n * of the form. So do containers two people moved into each other at once:\n * the one with the smallest id goes to the top, the same for everyone.\n * Both are listed in `lifted`.\n */\nexport function readMaps(maps: { nodes: Y.Map<unknown>; settings: Y.Map<unknown> }): {\n document: FormDocument\n lifted: string[]\n} {\n const entries = new Map<string, Entry>()\n maps.nodes.forEach((value, id) => {\n if (!(value instanceof Y.Map)) return\n const { [PARENT]: parent, [ORDER]: order, ...rest } = value.toJSON() as Item\n entries.set(id, {\n node: { ...rest, id } as unknown as FormNode,\n parent: typeof parent === 'string' ? parent : null,\n order: typeof order === 'string' ? order : '',\n })\n })\n\n const lifted: string[] = []\n const reached = new Set<string>()\n // Walk up from each node until the top or a node already reached.\n const reach = (id: string) => {\n const path: string[] = []\n let current: string | null = id\n while (current !== null && !reached.has(current)) {\n const entry: Entry = entries.get(current)!\n const loop = path.indexOf(current)\n if (loop >= 0) {\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a copy\n const top = path.slice(loop).sort()[0]!\n entries.get(top)!.parent = null\n lifted.push(top)\n return reach(id)\n }\n path.push(current)\n if (entry.parent !== null && !entries.has(entry.parent)) {\n entry.parent = null\n lifted.push(current)\n }\n current = entry.parent\n }\n for (const each of path) reached.add(each)\n }\n for (const id of entries.keys()) if (!reached.has(id)) reach(id)\n\n const byParent = new Map<string | null, Entry[]>()\n for (const entry of entries.values()) {\n const list = byParent.get(entry.parent)\n if (list) list.push(entry)\n else byParent.set(entry.parent, [entry])\n }\n const build = (parent: FormNode | null): FormNode[] => {\n const list = byParent.get(parent?.id ?? null) ?? []\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts the list built here\n list.sort((a, b) =>\n a.order < b.order ? -1 : a.order > b.order ? 1 : a.node.id < b.node.id ? -1 : 1,\n )\n const nodes: FormNode[] = []\n for (const { node } of list) {\n // A node that can't be here, e.g. a field among pages, waits until it can.\n if (!canContainFormNode(parent, node)) continue\n nodes.push(\n isContainer(node)\n ? ({ ...node, children: build(node) } as FormContainerNode)\n : (node as FormNode),\n )\n }\n return nodes\n }\n const settings = maps.settings.toJSON() as Item\n delete settings.nodes\n delete settings.version\n return {\n document: { ...settings, version: 1, nodes: build(null) } as FormDocument,\n lifted,\n }\n}\n\n/** The nodes, places and settings a transaction changed, written to the maps. */\nfunction writeChanges(maps: { nodes: Shared; settings: Shared }, tr: FormBuilderTransaction) {\n const after = formNodePlaces(tr.doc)\n const touched = new Map<string, Set<string> | true>()\n const parents = new Set<string | null>()\n const settings = new Set<string>()\n let removed = false\n const mark = (id: string, keys: string[] | true) => {\n const current = touched.get(id)\n if (current === true) return\n if (keys === true) return void touched.set(id, true)\n const set = current ?? new Set<string>()\n for (const key of keys) set.add(key)\n touched.set(id, set)\n }\n for (const step of tr.steps) {\n if (step.type === 'insert') {\n parents.add(step.parent)\n for (const node of walkNodes([step.node])) {\n mark(node.id, true)\n if (isContainer(node)) parents.add(node.id)\n }\n } else if (step.type === 'remove') removed = true\n else if (step.type === 'update') mark(step.id, Object.keys(step.patch))\n else if (step.type === 'move') parents.add(step.parent)\n else for (const key of Object.keys(step.patch)) settings.add(key)\n }\n\n if (removed)\n for (const id of formNodePlaces(tr.before).keys()) if (!after.has(id)) maps.nodes.delete(id)\n for (const [id, keys] of touched) {\n const node = after.get(id)?.node\n if (node) writeNode(maps.nodes, node, keys === true ? undefined : keys)\n }\n for (const parent of parents) {\n if (parent === null) writeOrder(maps.nodes, null, tr.doc.nodes)\n else {\n const node = after.get(parent)?.node\n if (node && isContainer(node)) writeOrder(maps.nodes, parent, node.children)\n }\n }\n const document = tr.doc as unknown as Item\n for (const key of settings) {\n const value = document[key]\n if (value === undefined) maps.settings.delete(key)\n else if (!same(maps.settings.get(key), value)) maps.settings.set(key, value)\n }\n}\n\ninterface Peer {\n client: number\n name: string\n color: string\n selection: string[]\n}\n\n/**\n * Edit a form together through a Yjs document. Each node lives in `nodes`\n * as its own `Y.Map`, each key on its own, with its container and an order\n * key beside them; so two people changing different keys of one field both\n * keep their change, and moving a node only writes that node. The form's\n * settings live in `settings`. The builder's `v-model` only mirrors them:\n * a form set through `v-model` from outside is not written back. Undo only\n * takes back this user's own changes. With `awareness`, each person sees\n * what the others have selected, marked in their colors.\n */\nexport function collaboration(options: CollaborationOptions): FormBuilderExtension {\n const { nodes, settings, awareness, user } = options\n const ydoc = nodes.doc\n if (!ydoc || settings.doc !== ydoc)\n throw new Error('[@dou-ui/form-builder] nodes and settings must be maps of the same Y.Doc')\n if (awareness && user) {\n const color = user.color ?? collaborationColors[ydoc.clientID % collaborationColors.length]\n awareness.setLocalStateField('user', { name: user.name, color })\n }\n const maps = { nodes, settings }\n\n /** This builder's own changes, which undo can take back. */\n const tracked = { formBuilder: 'tracked' }\n /** Changes undo leaves alone, e.g. filling the maps or lifting nodes out of deleted containers. */\n const untracked = { formBuilder: 'untracked' }\n const undoManager = new Y.UndoManager([nodes, settings], {\n trackedOrigins: new Set([tracked]),\n captureTimeout: 500,\n })\n let context: FormBuilderContext | undefined\n /** Set while shared changes are applied to the builder, so they aren't written back. */\n let applying = false\n /** What undo or redo is running, to name the change. */\n let travelling: 'undo' | 'redo' | null = null\n /** The selection to go back to once undo or redo has run. */\n let restore: string[] | undefined\n let lastGroup: string | undefined\n\n // Each step of undo keeps the selection from before it, and each step of redo the one after.\n undoManager.on('stack-item-added', (event: { stackItem: { meta: Map<string, unknown> } }) => {\n event.stackItem.meta.set('selection', context?.selection.slice() ?? [])\n })\n undoManager.on('stack-item-popped', (event: { stackItem: { meta: Map<string, unknown> } }) => {\n restore = event.stackItem.meta.get('selection') as string[] | undefined\n })\n\n /** Brings the builder in line with the maps. */\n function pull() {\n if (!context) return\n const { document, lifted } = readMaps(maps)\n const tr = context.transaction()\n try {\n replaceDocument(tr, document)\n } catch (error) {\n console.error('[@dou-ui/form-builder] could not apply a shared change', error)\n return\n }\n if (tr.changed) {\n tr.setMeta('history', false)\n tr.setMeta('origin', travelling ?? 'remote')\n applying = true\n try {\n context.dispatch(tr)\n } finally {\n applying = false\n }\n }\n // Everyone works these out alike; writing them keeps the maps tidy.\n if (lifted.length)\n queueMicrotask(() =>\n ydoc!.transact(() => {\n for (const id of lifted) {\n const fields = nodes.get(id)\n if (fields instanceof Y.Map && fields.get(PARENT) !== null) fields.set(PARENT, null)\n }\n }, untracked),\n )\n }\n\n function run(action: 'undo' | 'redo') {\n const stack = action === 'undo' ? undoManager.undoStack : undoManager.redoStack\n if (!stack.length) return false\n travelling = action\n restore = undefined\n try {\n undoManager[action]()\n } finally {\n travelling = null\n }\n if (restore && context) context.select(restore)\n restore = undefined\n return true\n }\n\n const peers = shallowRef<Peer[]>([])\n /** The others who have each node selected. */\n const marksByNode = computed(() => {\n const map = new Map<string, FormBuilderNodeMark[]>()\n for (const peer of peers.value)\n for (const id of peer.selection) {\n const mark = { key: `peer-${peer.client}`, label: peer.name, color: peer.color }\n const list = map.get(id)\n if (list) list.push(mark)\n else map.set(id, [mark])\n }\n return map\n })\n\n return defineFormBuilderExtension({\n name: 'collaboration',\n // after the other extensions, so it writes what they added\n priority: 0,\n transaction(tr) {\n if (applying) return\n const tracking = tr.meta.history !== false\n // like the builder's own history: only changes of one group undo together\n if (tracking && (!tr.meta.group || tr.meta.group !== lastGroup)) undoManager.stopCapturing()\n if (tracking) lastGroup = tr.meta.group\n ydoc.transact(() => writeChanges(maps, tr), tracking ? tracked : untracked)\n },\n history: () => ({\n undo: () => run('undo'),\n redo: () => run('redo'),\n canUndo: () => undoManager.undoStack.length > 0,\n canRedo: () => undoManager.redoStack.length > 0,\n }),\n marks: awareness ? (_context, node) => marksByNode.value.get(node.id) ?? [] : undefined,\n setup(builder) {\n context = builder\n // the first one to open the form brings its nodes; everyone else reads the maps\n if (!nodes.size && !settings.size)\n ydoc.transact(() => fillMaps(maps, builder.document), untracked)\n pull()\n\n // changes from others, and from undo: applied once per Yjs transaction\n let dirty = false\n const observe = (_events: unknown, transaction: Y.Transaction) => {\n if (transaction.origin !== tracked && transaction.origin !== untracked) dirty = true\n }\n const flush = () => {\n if (!dirty) return\n dirty = false\n pull()\n }\n nodes.observeDeep(observe)\n settings.observeDeep(observe)\n ydoc.on('afterTransaction', flush)\n\n let stopPresence: (() => void) | undefined\n let readPeers: (() => void) | undefined\n if (awareness) {\n readPeers = () => {\n const list: Peer[] = []\n awareness.getStates().forEach((state, client) => {\n if (client === awareness.clientID) return\n const who = state.user as { name?: string; color?: string } | undefined\n const presence = state.formBuilder as FormBuilderPresence | null | undefined\n if (!who || !presence?.selection?.length) return\n list.push({\n client,\n name: who.name ?? '',\n color: who.color ?? 'currentColor',\n selection: presence.selection,\n })\n })\n peers.value = list\n }\n readPeers()\n awareness.on('change', readPeers)\n stopPresence = watch(\n () => builder.selection,\n (selection) =>\n awareness.setLocalStateField('formBuilder', {\n selection: selection.slice(0, 100),\n } satisfies FormBuilderPresence),\n { immediate: true },\n )\n }\n\n return () => {\n nodes.unobserveDeep(observe)\n settings.unobserveDeep(observe)\n ydoc.off('afterTransaction', flush)\n stopPresence?.()\n if (readPeers) awareness?.off('change', readPeers)\n awareness?.setLocalStateField('formBuilder', null)\n context = undefined\n }\n },\n })\n}\n"],"mappings":";;;;;;;;;;AAoDA,IAAM,SAAS;AACf,IAAM,QAAQ;AAEd,IAAM,QAAQ,GAAY,MACxB,MAAM,KACL,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;;AAG3F,SAAS,YAAY,OAAgB,MAA6B;CAChE,IAAI,UAAU,QAAQ;EAAC;EAAU;EAAU;EAAW;CAAW,CAAC,CAAC,SAAS,OAAO,KAAK,GACtF,OAAO;CACT,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,KAAK,MAAM,CAAC,GAAG,SAAS,MAAM,QAAQ,GAAG;GACvC,MAAM,QA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O;IAC3B,SAAS,cAAc,OAAO;IAC9B,KAAK,IAAI,oBAAoB,KAAK;IAClC,eAAe;IACf,IAAI,WAAW,WAAW,IAAI,UAAU,SAAS;IACjD,WAAW,mBAAmB,eAAe,IAAI;IACjD,UAAU,KAAA;GACZ;EACF;CACF,CAAC;AACH"}
|
|
@@ -164,7 +164,7 @@ function stepsView(kit, props, renderer, scope, disabled, condition) {
|
|
|
164
164
|
h(DouSteps, {
|
|
165
165
|
items,
|
|
166
166
|
current: index,
|
|
167
|
-
status: failed.value ? "error" : "
|
|
167
|
+
status: failed.value ? "error" : "running",
|
|
168
168
|
clickable: true,
|
|
169
169
|
"onUpdate:current": (at) => {
|
|
170
170
|
if (at <= reached.value) go(at);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"containers.js","names":[],"sources":["../../src/renderer/containers.ts"],"sourcesContent":["import {\n computed,\n defineComponent,\n h,\n inject,\n nextTick,\n onScopeDispose,\n provide,\n shallowRef,\n toRaw,\n useId,\n watch,\n} from 'vue'\nimport type { PropType, VNodeChild } from 'vue'\nimport {\n DouButton,\n DouFormItem,\n DouSortable,\n DouSortableHandle,\n DouSteps,\n DouTabPanel,\n DouTabs,\n} from 'dou-ui'\nimport type { FormItemExpose, FormRule, StepItem } from 'dou-ui'\nimport { PlusIcon, TrashIcon } from '@dou-ui/icons'\nimport { getPath, isList, setPath, valueNodes } from '../core/document'\nimport { rulesOf } from '../core/rules'\nimport type {\n FormListNode,\n FormNode,\n FormPageNode,\n FormStepsNode,\n FormTabsNode,\n} from '../core/types'\nimport { emptyItem } from '../core/values'\nimport { formatMessage } from '../locale'\nimport { rendererKey, scopeKey } from './context'\nimport type { NodeScope, RendererContext } from './context'\nimport { disabledKey, pathIn } from './context'\nimport type { Condition, NodeKit, NodeProps } from './context'\n\ntype Flag = { readonly value: boolean }\n\n/** Whether a field at `path` sits among `nodes`, inside a list item included. */\nexport function holdsPath(nodes: readonly FormNode[], path: string, prefix = ''): boolean {\n return valueNodes(nodes).some((node) => {\n const own = prefix + node.name!\n return own === path || (isList(node) && path.startsWith(`${own}.`))\n })\n}\n\n/** The paths of every field among `nodes`, the fields of each list item included. */\nexport function valuePaths(nodes: readonly FormNode[], model: unknown, prefix = ''): string[] {\n const paths: string[] = []\n for (const node of valueNodes(nodes)) {\n const own = prefix + node.name!\n paths.push(own)\n if (!isList(node)) continue\n const items = getPath(model, own)\n if (Array.isArray(items))\n items.forEach((_, index) =>\n paths.push(...valuePaths(node.children, model, `${own}.${index}.`)),\n )\n }\n return paths\n}\n\n/** The pages of tabs or steps that show, as the node's own view decides them. */\nfunction shownPages(props: NodeProps, condition: Condition) {\n return computed(() =>\n (props.node as FormTabsNode | FormStepsNode).children.filter(\n (child) => !!child && condition(child.visibleWhen, true, child),\n ),\n )\n}\n\n/** One page of tabs or steps: its description and its own grid. */\nconst pageOf = (kit: NodeKit, node: FormPageNode, props: NodeProps) =>\n h(kit.view, {\n key: node.id,\n node,\n columns: props.columns,\n inset: props.inset,\n asPage: true,\n })\n\nexport function tabsView(\n kit: NodeKit,\n props: NodeProps,\n renderer: RendererContext,\n scope: NodeScope,\n disabled: Flag,\n condition: Condition,\n) {\n provide(disabledKey, () => disabled.value)\n const pages = shownPages(props, condition)\n const chosen = shallowRef<string>()\n const selected = computed(() =>\n pages.value.some((shown) => shown.id === chosen.value) ? chosen.value : pages.value[0]?.id,\n )\n // A field with an error on another tab: switch to the tab.\n onScopeDispose(\n renderer.addRevealer((path) => {\n const found = pages.value.find((shown) => holdsPath(shown.children, path, scope.prefix()))\n if (found) chosen.value = found.id\n return !!found\n }),\n )\n return () =>\n h(\n DouTabs,\n {\n class: 'dou-form-renderer__tabs',\n modelValue: selected.value,\n 'onUpdate:modelValue': (value: string | number | undefined) => {\n if (value !== undefined) chosen.value = String(value)\n },\n },\n () =>\n pages.value.map((node) =>\n h(\n DouTabPanel,\n { key: node.id, value: node.id, label: node.title, eager: true },\n {\n default: () => pageOf(kit, node, props),\n // A page with errors gets a dot, read out as \"has errors\". Worked\n // out in the slot, so the tab list follows the errors itself.\n label: () => {\n const failed = renderer\n .errorPaths()\n .some((path) => holdsPath(node.children, path, scope.prefix()))\n return h('span', { class: 'dou-form-renderer__tab-title' }, [\n node.title,\n failed\n ? h('span', { class: 'dou-form-renderer__tab-error' }, [\n h(\n 'span',\n { class: 'dou-form-renderer__sr-only' },\n `(${renderer.messages().invalid})`,\n ),\n ])\n : null,\n ])\n },\n },\n ),\n ),\n )\n}\n\nexport function stepsView(\n kit: NodeKit,\n props: NodeProps,\n renderer: RendererContext,\n scope: NodeScope,\n disabled: Flag,\n condition: Condition,\n) {\n provide(disabledKey, () => disabled.value)\n const pages = shownPages(props, condition)\n // Read-only, there is nothing to fill in step by step: every page shows, under its title.\n if (renderer.readonly()) {\n const uid = useId()\n return () =>\n h(\n 'div',\n { class: 'dou-form-renderer__steps is-readonly' },\n pages.value.map((node) => {\n const titleId = `dou-form-step-${uid}-${node.id}`\n return h(\n 'div',\n {\n key: node.id,\n class: 'dou-form-renderer__section',\n role: 'group',\n 'aria-labelledby': titleId,\n },\n [\n h('div', { class: 'dou-form-renderer__section-header' }, [\n h('div', { id: titleId, class: 'dou-form-renderer__section-title' }, node.title),\n ]),\n pageOf(kit, node, props),\n ],\n )\n }),\n )\n }\n const chosen = shallowRef<string>()\n /** How far people got: the steps up to here can be opened again. */\n const reached = shallowRef(0)\n const failed = shallowRef(false)\n const checking = shallowRef(false)\n const current = computed(() => {\n const index = pages.value.findIndex((shown) => shown.id === chosen.value)\n return index < 0 ? 0 : index\n })\n watch(current, () => (failed.value = false))\n watch(renderer.resets, () => {\n chosen.value = undefined\n reached.value = 0\n failed.value = false\n })\n\n function go(index: number) {\n const target = pages.value[index]\n if (!target) return\n chosen.value = target.id\n reached.value = Math.max(reached.value, index)\n }\n\n // Back and Next take focus to the page they open, which names its step:\n // the button pressed may be gone, and a screen reader hears where it is.\n const stepEls = new Map<string, HTMLElement>()\n function turn(index: number) {\n go(index)\n const id = pages.value[index]?.id\n if (id) void nextTick(() => stepEls.get(id)?.focus({ preventScroll: true }))\n }\n\n async function next() {\n const shown = pages.value[current.value]\n if (!shown || checking.value) return\n checking.value = true\n try {\n const paths = valuePaths(shown.children, renderer.model(), scope.prefix())\n const { valid, errors } = await renderer.validate(paths)\n if (!valid) {\n failed.value = true\n const first = Object.keys(errors)[0]\n if (first) renderer.scrollToField(first)\n return\n }\n turn(current.value + 1)\n } finally {\n checking.value = false\n }\n }\n\n // A field with an error on another step, e.g. on submit: open its step.\n onScopeDispose(\n renderer.addRevealer((path) => {\n const index = pages.value.findIndex((page) => holdsPath(page.children, path, scope.prefix()))\n if (index >= 0) go(index)\n return index >= 0\n }),\n )\n\n return () => {\n const list = pages.value\n const index = current.value\n const messages = renderer.messages()\n const last = index >= list.length - 1\n // A step holding errors, e.g. ones set after submit, is marked like a tab.\n const errorPaths = renderer.errorPaths()\n const failing = new Set(\n list\n .filter((step) => errorPaths.some((path) => holdsPath(step.children, path, scope.prefix())))\n .map((step) => step.id),\n )\n const items: StepItem[] = list.map((step, at) => ({\n title: step.title,\n disabled: at > reached.value,\n status: failing.has(step.id) ? 'error' : undefined,\n }))\n const footer: VNodeChild[] = []\n if (index > 0)\n footer.push(\n h(\n DouButton,\n { key: 'prev', variant: 'outline', onClick: () => turn(index - 1) },\n () => messages.prev,\n ),\n )\n if (!last)\n footer.push(\n h(\n DouButton,\n { key: 'next', tone: 'primary', loading: checking.value, onClick: next },\n () => messages.next,\n ),\n )\n else if (renderer.footerOwner() === props.node.id) footer.push(renderer.footer() as VNodeChild)\n return h('div', { class: 'dou-form-renderer__steps' }, [\n // A step's status is read out with its title, \"error\" included.\n h(DouSteps, {\n items,\n current: index,\n status: failed.value ? 'error' : 'process',\n clickable: true,\n 'onUpdate:current': (at: number) => {\n if (at <= reached.value) go(at)\n },\n }),\n ...list.map((node, at) =>\n h(\n 'div',\n {\n key: node.id,\n ref: (el: unknown) => {\n if (el) stepEls.set(node.id, el as HTMLElement)\n else stepEls.delete(node.id)\n },\n class: 'dou-form-renderer__step',\n hidden: at !== index || undefined,\n role: 'group',\n tabindex: -1,\n 'aria-label': formatMessage(messages.step, {\n index: at + 1,\n count: list.length,\n title: node.title ?? '',\n }),\n },\n [pageOf(kit, node, props)],\n ),\n ),\n h('div', { class: 'dou-form-renderer__steps-footer' }, footer),\n ])\n }\n}\n\n/** Ids of list items, by the item object, so each keeps its view while the list is reordered. */\nconst itemIds = new WeakMap<object, string>()\nlet nextItem = 0\nfunction itemKey(item: unknown) {\n if (item === null || typeof item !== 'object') return `v:${String(item)}`\n const raw = toRaw(item)\n let id = itemIds.get(raw)\n if (!id) itemIds.set(raw, (id = `i${++nextItem}`))\n return id\n}\n\n/**\n * The copy of an item that follows the pointer. It sits on `body`, away\n * from the form whose width picks the columns, whose classes set the layout\n * and whose surroundings may change the gaps (the designer's settings panel\n * narrows them), so it is wrapped in an element with the form's classes and\n * every grid in it keeps the columns and gaps it has now, in pixels.\n */\nfunction listGhost(el: HTMLElement): HTMLElement {\n const clone = el.cloneNode(true) as HTMLElement\n freezeGrids(el, clone)\n const form = el.closest<HTMLElement>('.dou-form')\n if (!form) return clone\n const wrapper = document.createElement('div')\n wrapper.className = `${form.className} dou-form-renderer__list-ghost`\n // The wrapper takes the size the copy is given, not the form's container sizing.\n wrapper.style.containerType = 'normal'\n wrapper.append(clone)\n return wrapper\n}\n\n/** Writes the computed grid tracks, gaps and cell placement of `source` onto its copy. */\nfunction freezeGrids(source: HTMLElement, copy: HTMLElement) {\n const from = [source, ...source.querySelectorAll<HTMLElement>('*')]\n const to = [copy, ...copy.querySelectorAll<HTMLElement>('*')]\n from.forEach((element, index) => {\n const target = to[index]\n if (!target) return\n const style = getComputedStyle(element)\n if (style.display === 'grid' || style.display === 'inline-grid') {\n target.style.gridTemplateColumns = style.gridTemplateColumns\n target.style.columnGap = style.columnGap\n target.style.rowGap = style.rowGap\n }\n if (element.classList.contains('dou-form-renderer__cell')) {\n target.style.gridColumn = style.gridColumn\n }\n })\n}\n\n/** The rules of a list itself: its own, and its bounds on the number of items. */\nfunction listRules(node: FormListNode, renderer: RendererContext, path: () => string): FormRule[] {\n const rules = rulesOf(node, {\n functions: renderer.functions(),\n validators: renderer.validators(),\n path,\n })\n const bounds: FormRule = {}\n if (node.min !== undefined && node.min > 0) bounds.min = node.min\n if (node.max !== undefined) bounds.max = node.max\n return bounds.min === undefined && bounds.max === undefined ? rules : [...rules, bounds]\n}\n\nexport function listView(\n kit: NodeKit,\n props: NodeProps,\n renderer: RendererContext,\n scope: NodeScope,\n disabled: Flag,\n) {\n provide(disabledKey, () => disabled.value)\n const uid = useId()\n const list = () => props.node as FormListNode\n const path = () => pathIn(scope, list().name)\n const items = computed(() => {\n const value = getPath(renderer.model(), path())\n return Array.isArray(value) ? (value as Record<string, unknown>[]) : []\n })\n const rules = computed(() => listRules(list(), renderer, path))\n\n function write(next: Record<string, unknown>[]) {\n const name = path()\n setPath(renderer.model(), name, next)\n renderer.changed(name, getPath(renderer.model(), name))\n }\n const root = shallowRef<HTMLElement>()\n const footer = shallowRef<FormItemExpose>()\n onScopeDispose(renderer.trackError(path, () => footer.value?.error))\n\n /** The items of this list, not of lists inside it nor ones still animating out. */\n const itemElements = () =>\n [...(root.value?.querySelectorAll<HTMLElement>('.dou-form-renderer__list-item') ?? [])].filter(\n (el) =>\n el.closest('.dou-form-renderer__list') === root.value && !el.closest('[class*=\"-leave-\"]'),\n )\n /** Focus the first field of an item, or the add button when there is none. */\n async function focusItem(index: number) {\n // The sortable list renders its items a tick after the value changes.\n await nextTick()\n await nextTick()\n const elements = itemElements()\n const target = elements[Math.min(index, elements.length - 1)]\n const control = target?.querySelector<HTMLElement>(\n ':scope > .dou-form-renderer__grid :is(input, textarea, select, button, [tabindex=\"0\"]):not([disabled])',\n )\n ;(control ?? root.value?.querySelector<HTMLElement>('.dou-form-renderer__list-add'))?.focus()\n }\n function add() {\n write([...items.value, emptyItem(list(), renderer.fields())])\n void focusItem(items.value.length - 1)\n }\n function remove(index: number) {\n write(items.value.filter((_, at) => at !== index))\n void focusItem(index)\n }\n\n return () => {\n const node = list()\n const rows = items.value\n const messages = renderer.messages()\n // Read-only controls (a read-only builder's settings) show the items without the buttons too.\n const readonly = renderer.readonly() || renderer.controlsReadonly()\n const off = disabled.value\n const canAdd = !off && (node.max === undefined || rows.length < node.max)\n const canRemove = !off && rows.length > (node.min ?? 0)\n const sortable = node.sortable !== false && !off && !readonly && rows.length > 1\n const labelId = node.label ? `dou-form-list-${uid}` : undefined\n const required = node.required || rules.value.some((rule) => rule.required)\n return h(\n 'div',\n {\n ref: root,\n class: ['dou-form-renderer__list', off && 'is-disabled', readonly && 'is-readonly'],\n role: 'group',\n 'aria-labelledby': labelId,\n 'aria-disabled': off || undefined,\n },\n [\n node.label || node.help\n ? h('div', { class: 'dou-form-renderer__section-header' }, [\n node.label &&\n h(\n 'div',\n {\n id: labelId,\n class: ['dou-form-renderer__section-title', required && 'is-required'],\n },\n node.label,\n ),\n node.help && h('div', { class: 'dou-form-renderer__section-description' }, node.help),\n ])\n : null,\n rows.length\n ? h(\n DouSortable,\n {\n class: 'dou-form-renderer__list-items',\n modelValue: rows,\n 'onUpdate:modelValue': (next: unknown[]) =>\n write(next as Record<string, unknown>[]),\n itemKey,\n ghost: listGhost,\n handle: true,\n disabled: !sortable,\n itemLabel: (_item: unknown, index: number) =>\n formatMessage(messages.item, { index: index + 1 }),\n },\n {\n default: ({ item, index }: { item: Record<string, unknown>; index: number }) => {\n // While dragging, `index` is the place the item is shown at;\n // its fields still read and write the place it holds in the value.\n const raw = toRaw(item)\n const at = rows.findIndex((row) => toRaw(row) === raw)\n return h(ListItemView, {\n list: node,\n render: kit.renderNodes,\n path: path(),\n item,\n index: at < 0 ? index : at,\n position: index,\n columns: node.columns ?? props.columns,\n inset: props.inset + 1,\n sortable,\n canRemove,\n readonly,\n onRemove: () => remove(at < 0 ? index : at),\n })\n },\n },\n )\n : h(\n 'div',\n { class: 'dou-form-renderer__list-empty' },\n readonly ? messages.noValue : messages.empty,\n ),\n // After the items, so a reset puts their values back before the\n // list puts back its own items; its errors show under the button.\n readonly\n ? null\n : h(\n DouFormItem,\n {\n ref: footer,\n class: 'dou-form-renderer__list-footer',\n prop: path(),\n rules: rules.value,\n },\n () =>\n h(\n DouButton,\n {\n class: 'dou-form-renderer__list-add',\n variant: 'outline',\n disabled: !canAdd,\n onClick: add,\n },\n { leading: () => h(PlusIcon), default: () => node.addText ?? messages.add },\n ),\n ),\n ],\n )\n }\n}\n\n/** One item of a list: its fields read and write the item. */\nconst ListItemView = defineComponent({\n name: 'DouFormListItem',\n props: {\n list: { type: Object as PropType<FormListNode>, required: true },\n render: { type: Function as PropType<NodeKit['renderNodes']>, required: true },\n path: { type: String, required: true },\n item: { type: Object as PropType<Record<string, unknown>>, required: true },\n /** Where the item is in the value. */\n index: { type: Number, required: true },\n /** Where the item is shown, which differs while it is dragged. */\n position: { type: Number, required: true },\n columns: { type: Number, required: true },\n inset: { type: Number, required: true },\n sortable: Boolean,\n canRemove: Boolean,\n /** Without the remove button. */\n readonly: Boolean,\n },\n emits: ['remove'],\n setup(props, { emit }) {\n const renderer = inject(rendererKey)!\n provide(scopeKey, {\n prefix: () => `${props.path}.${props.index}.`,\n item: () => props.item,\n })\n return () => {\n const messages = renderer.messages()\n const number = props.position + 1\n return h('div', { class: 'dou-form-renderer__list-item' }, [\n h('div', { class: 'dou-form-renderer__list-item-header' }, [\n props.sortable\n ? h(DouSortableHandle, {\n class: 'dou-form-renderer__list-handle',\n label: formatMessage(messages.move, { index: number }),\n })\n : null,\n h(\n 'span',\n { class: 'dou-form-renderer__list-item-title' },\n formatMessage(messages.item, { index: number }),\n ),\n props.readonly\n ? null\n : h(\n DouButton,\n {\n class: 'dou-form-renderer__list-remove',\n variant: 'ghost',\n size: 'sm',\n disabled: !props.canRemove,\n 'aria-label': formatMessage(messages.remove, { index: number }),\n onClick: () => emit('remove'),\n },\n { leading: () => h(TrashIcon) },\n ),\n ]),\n h(\n 'div',\n { class: 'dou-form-renderer__grid', style: { '--dou-form-columns': props.columns } },\n props.render(props.list.children, props.columns, props.inset),\n ),\n ])\n }\n },\n})\n"],"mappings":";;;;;;;;;;AA4CA,SAAgB,UAAU,OAA4B,MAAc,SAAS,IAAa;CACxF,OAAO,WAAW,KAAK,CAAC,CAAC,MAAM,SAAS;EACtC,MAAM,MAAM,SAAS,KAAK;EAC1B,OAAO,QAAQ,QAAS,OAAO,IAAI,KAAK,KAAK,WAAW,GAAG,IAAI,EAAE;CACnE,CAAC;AACH;;AAGA,SAAgB,WAAW,OAA4B,OAAgB,SAAS,IAAc;CAC5F,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,WAAW,KAAK,GAAG;EACpC,MAAM,MAAM,SAAS,KAAK;EAC1B,MAAM,KAAK,GAAG;EACd,IAAI,CAAC,OAAO,IAAI,GAAG;EACnB,MAAM,QAAQ,QAAQ,OAAO,GAAG;EAChC,IAAI,MAAM,QAAQ,KAAK,GACrB,MAAM,SAAS,GAAG,UAChB,MAAM,KAAK,GAAG,WAAW,KAAK,UAAU,OAAO,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC,CACpE;CACJ;CACA,OAAO;AACT;;AAGA,SAAS,WAAW,OAAkB,WAAsB;CAC1D,OAAO,eACJ,MAAM,KAAsC,SAAS,QACnD,UAAU,CAAC,CAAC,SAAS,UAAU,MAAM,aAAa,MAAM,KAAK,CAChE,CACF;AACF;;AAGA,IAAM,UAAU,KAAc,MAAoB,UAChD,EAAE,IAAI,MAAM;CACV,KAAK,KAAK;CACV;CACA,SAAS,MAAM;CACf,OAAO,MAAM;CACb,QAAQ;AACV,CAAC;AAEH,SAAgB,SACd,KACA,OACA,UACA,OACA,UACA,WACA;CACA,QAAQ,mBAAmB,SAAS,KAAK;CACzC,MAAM,QAAQ,WAAW,OAAO,SAAS;CACzC,MAAM,SAAS,WAAmB;CAClC,MAAM,WAAW,eACf,MAAM,MAAM,MAAM,UAAU,MAAM,OAAO,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,WACF,EAAE,mBAAmB;KACnB,OAAO;KACP,OAAO,cAAc,SAAS,MAAM,EAAE,OAAO,OAAO,CAAC;IACvD,CAAC,IACD;IACJ,EACE,QACA,EAAE,OAAO,qCAAqC,GAC9C,cAAc,SAAS,MAAM,EAAE,OAAO,OAAO,CAAC,CAChD;IACA,MAAM,WACF,OACA,EACE,WACA;KACE,OAAO;KACP,SAAS;KACT,MAAM;KACN,UAAU,CAAC,MAAM;KACjB,cAAc,cAAc,SAAS,QAAQ,EAAE,OAAO,OAAO,CAAC;KAC9D,eAAe,KAAK,QAAQ;IAC9B,GACA,EAAE,eAAe,EAAE,SAAS,EAAE,CAChC;GACN,CAAC,GACD,EACE,OACA;IAAE,OAAO;IAA2B,OAAO,EAAE,sBAAsB,MAAM,QAAQ;GAAE,GACnF,MAAM,OAAO,MAAM,KAAK,UAAU,MAAM,SAAS,MAAM,KAAK,CAC9D,CACF,CAAC;EACH;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"containers.js","names":[],"sources":["../../src/renderer/containers.ts"],"sourcesContent":["import {\n computed,\n defineComponent,\n h,\n inject,\n nextTick,\n onScopeDispose,\n provide,\n shallowRef,\n toRaw,\n useId,\n watch,\n} from 'vue'\nimport type { PropType, VNodeChild } from 'vue'\nimport {\n DouButton,\n DouFormItem,\n DouSortable,\n DouSortableHandle,\n DouSteps,\n DouTabPanel,\n DouTabs,\n} from 'dou-ui'\nimport type { FormItemExpose, FormRule, StepItem } from 'dou-ui'\nimport { PlusIcon, TrashIcon } from '@dou-ui/icons'\nimport { getPath, isList, setPath, valueNodes } from '../core/document'\nimport { rulesOf } from '../core/rules'\nimport type {\n FormListNode,\n FormNode,\n FormPageNode,\n FormStepsNode,\n FormTabsNode,\n} from '../core/types'\nimport { emptyItem } from '../core/values'\nimport { formatMessage } from '../locale'\nimport { rendererKey, scopeKey } from './context'\nimport type { NodeScope, RendererContext } from './context'\nimport { disabledKey, pathIn } from './context'\nimport type { Condition, NodeKit, NodeProps } from './context'\n\ntype Flag = { readonly value: boolean }\n\n/** Whether a field at `path` sits among `nodes`, inside a list item included. */\nexport function holdsPath(nodes: readonly FormNode[], path: string, prefix = ''): boolean {\n return valueNodes(nodes).some((node) => {\n const own = prefix + node.name!\n return own === path || (isList(node) && path.startsWith(`${own}.`))\n })\n}\n\n/** The paths of every field among `nodes`, the fields of each list item included. */\nexport function valuePaths(nodes: readonly FormNode[], model: unknown, prefix = ''): string[] {\n const paths: string[] = []\n for (const node of valueNodes(nodes)) {\n const own = prefix + node.name!\n paths.push(own)\n if (!isList(node)) continue\n const items = getPath(model, own)\n if (Array.isArray(items))\n items.forEach((_, index) =>\n paths.push(...valuePaths(node.children, model, `${own}.${index}.`)),\n )\n }\n return paths\n}\n\n/** The pages of tabs or steps that show, as the node's own view decides them. */\nfunction shownPages(props: NodeProps, condition: Condition) {\n return computed(() =>\n (props.node as FormTabsNode | FormStepsNode).children.filter(\n (child) => !!child && condition(child.visibleWhen, true, child),\n ),\n )\n}\n\n/** One page of tabs or steps: its description and its own grid. */\nconst pageOf = (kit: NodeKit, node: FormPageNode, props: NodeProps) =>\n h(kit.view, {\n key: node.id,\n node,\n columns: props.columns,\n inset: props.inset,\n asPage: true,\n })\n\nexport function tabsView(\n kit: NodeKit,\n props: NodeProps,\n renderer: RendererContext,\n scope: NodeScope,\n disabled: Flag,\n condition: Condition,\n) {\n provide(disabledKey, () => disabled.value)\n const pages = shownPages(props, condition)\n const chosen = shallowRef<string>()\n const selected = computed(() =>\n pages.value.some((shown) => shown.id === chosen.value) ? chosen.value : pages.value[0]?.id,\n )\n // A field with an error on another tab: switch to the tab.\n onScopeDispose(\n renderer.addRevealer((path) => {\n const found = pages.value.find((shown) => holdsPath(shown.children, path, scope.prefix()))\n if (found) chosen.value = found.id\n return !!found\n }),\n )\n return () =>\n h(\n DouTabs,\n {\n class: 'dou-form-renderer__tabs',\n modelValue: selected.value,\n 'onUpdate:modelValue': (value: string | number | undefined) => {\n if (value !== undefined) chosen.value = String(value)\n },\n },\n () =>\n pages.value.map((node) =>\n h(\n DouTabPanel,\n { key: node.id, value: node.id, label: node.title, eager: true },\n {\n default: () => pageOf(kit, node, props),\n // A page with errors gets a dot, read out as \"has errors\". Worked\n // out in the slot, so the tab list follows the errors itself.\n label: () => {\n const failed = renderer\n .errorPaths()\n .some((path) => holdsPath(node.children, path, scope.prefix()))\n return h('span', { class: 'dou-form-renderer__tab-title' }, [\n node.title,\n failed\n ? h('span', { class: 'dou-form-renderer__tab-error' }, [\n h(\n 'span',\n { class: 'dou-form-renderer__sr-only' },\n `(${renderer.messages().invalid})`,\n ),\n ])\n : null,\n ])\n },\n },\n ),\n ),\n )\n}\n\nexport function stepsView(\n kit: NodeKit,\n props: NodeProps,\n renderer: RendererContext,\n scope: NodeScope,\n disabled: Flag,\n condition: Condition,\n) {\n provide(disabledKey, () => disabled.value)\n const pages = shownPages(props, condition)\n // Read-only, there is nothing to fill in step by step: every page shows, under its title.\n if (renderer.readonly()) {\n const uid = useId()\n return () =>\n h(\n 'div',\n { class: 'dou-form-renderer__steps is-readonly' },\n pages.value.map((node) => {\n const titleId = `dou-form-step-${uid}-${node.id}`\n return h(\n 'div',\n {\n key: node.id,\n class: 'dou-form-renderer__section',\n role: 'group',\n 'aria-labelledby': titleId,\n },\n [\n h('div', { class: 'dou-form-renderer__section-header' }, [\n h('div', { id: titleId, class: 'dou-form-renderer__section-title' }, node.title),\n ]),\n pageOf(kit, node, props),\n ],\n )\n }),\n )\n }\n const chosen = shallowRef<string>()\n /** How far people got: the steps up to here can be opened again. */\n const reached = shallowRef(0)\n const failed = shallowRef(false)\n const checking = shallowRef(false)\n const current = computed(() => {\n const index = pages.value.findIndex((shown) => shown.id === chosen.value)\n return index < 0 ? 0 : index\n })\n watch(current, () => (failed.value = false))\n watch(renderer.resets, () => {\n chosen.value = undefined\n reached.value = 0\n failed.value = false\n })\n\n function go(index: number) {\n const target = pages.value[index]\n if (!target) return\n chosen.value = target.id\n reached.value = Math.max(reached.value, index)\n }\n\n // Back and Next take focus to the page they open, which names its step:\n // the button pressed may be gone, and a screen reader hears where it is.\n const stepEls = new Map<string, HTMLElement>()\n function turn(index: number) {\n go(index)\n const id = pages.value[index]?.id\n if (id) void nextTick(() => stepEls.get(id)?.focus({ preventScroll: true }))\n }\n\n async function next() {\n const shown = pages.value[current.value]\n if (!shown || checking.value) return\n checking.value = true\n try {\n const paths = valuePaths(shown.children, renderer.model(), scope.prefix())\n const { valid, errors } = await renderer.validate(paths)\n if (!valid) {\n failed.value = true\n const first = Object.keys(errors)[0]\n if (first) renderer.scrollToField(first)\n return\n }\n turn(current.value + 1)\n } finally {\n checking.value = false\n }\n }\n\n // A field with an error on another step, e.g. on submit: open its step.\n onScopeDispose(\n renderer.addRevealer((path) => {\n const index = pages.value.findIndex((page) => holdsPath(page.children, path, scope.prefix()))\n if (index >= 0) go(index)\n return index >= 0\n }),\n )\n\n return () => {\n const list = pages.value\n const index = current.value\n const messages = renderer.messages()\n const last = index >= list.length - 1\n // A step holding errors, e.g. ones set after submit, is marked like a tab.\n const errorPaths = renderer.errorPaths()\n const failing = new Set(\n list\n .filter((step) => errorPaths.some((path) => holdsPath(step.children, path, scope.prefix())))\n .map((step) => step.id),\n )\n const items: StepItem[] = list.map((step, at) => ({\n title: step.title,\n disabled: at > reached.value,\n status: failing.has(step.id) ? 'error' : undefined,\n }))\n const footer: VNodeChild[] = []\n if (index > 0)\n footer.push(\n h(\n DouButton,\n { key: 'prev', variant: 'outline', onClick: () => turn(index - 1) },\n () => messages.prev,\n ),\n )\n if (!last)\n footer.push(\n h(\n DouButton,\n { key: 'next', tone: 'primary', loading: checking.value, onClick: next },\n () => messages.next,\n ),\n )\n else if (renderer.footerOwner() === props.node.id) footer.push(renderer.footer() as VNodeChild)\n return h('div', { class: 'dou-form-renderer__steps' }, [\n // A step's status is read out with its title, \"error\" included.\n h(DouSteps, {\n items,\n current: index,\n status: failed.value ? 'error' : 'running',\n clickable: true,\n 'onUpdate:current': (at: number) => {\n if (at <= reached.value) go(at)\n },\n }),\n ...list.map((node, at) =>\n h(\n 'div',\n {\n key: node.id,\n ref: (el: unknown) => {\n if (el) stepEls.set(node.id, el as HTMLElement)\n else stepEls.delete(node.id)\n },\n class: 'dou-form-renderer__step',\n hidden: at !== index || undefined,\n role: 'group',\n tabindex: -1,\n 'aria-label': formatMessage(messages.step, {\n index: at + 1,\n count: list.length,\n title: node.title ?? '',\n }),\n },\n [pageOf(kit, node, props)],\n ),\n ),\n h('div', { class: 'dou-form-renderer__steps-footer' }, footer),\n ])\n }\n}\n\n/** Ids of list items, by the item object, so each keeps its view while the list is reordered. */\nconst itemIds = new WeakMap<object, string>()\nlet nextItem = 0\nfunction itemKey(item: unknown) {\n if (item === null || typeof item !== 'object') return `v:${String(item)}`\n const raw = toRaw(item)\n let id = itemIds.get(raw)\n if (!id) itemIds.set(raw, (id = `i${++nextItem}`))\n return id\n}\n\n/**\n * The copy of an item that follows the pointer. It sits on `body`, away\n * from the form whose width picks the columns, whose classes set the layout\n * and whose surroundings may change the gaps (the designer's settings panel\n * narrows them), so it is wrapped in an element with the form's classes and\n * every grid in it keeps the columns and gaps it has now, in pixels.\n */\nfunction listGhost(el: HTMLElement): HTMLElement {\n const clone = el.cloneNode(true) as HTMLElement\n freezeGrids(el, clone)\n const form = el.closest<HTMLElement>('.dou-form')\n if (!form) return clone\n const wrapper = document.createElement('div')\n wrapper.className = `${form.className} dou-form-renderer__list-ghost`\n // The wrapper takes the size the copy is given, not the form's container sizing.\n wrapper.style.containerType = 'normal'\n wrapper.append(clone)\n return wrapper\n}\n\n/** Writes the computed grid tracks, gaps and cell placement of `source` onto its copy. */\nfunction freezeGrids(source: HTMLElement, copy: HTMLElement) {\n const from = [source, ...source.querySelectorAll<HTMLElement>('*')]\n const to = [copy, ...copy.querySelectorAll<HTMLElement>('*')]\n from.forEach((element, index) => {\n const target = to[index]\n if (!target) return\n const style = getComputedStyle(element)\n if (style.display === 'grid' || style.display === 'inline-grid') {\n target.style.gridTemplateColumns = style.gridTemplateColumns\n target.style.columnGap = style.columnGap\n target.style.rowGap = style.rowGap\n }\n if (element.classList.contains('dou-form-renderer__cell')) {\n target.style.gridColumn = style.gridColumn\n }\n })\n}\n\n/** The rules of a list itself: its own, and its bounds on the number of items. */\nfunction listRules(node: FormListNode, renderer: RendererContext, path: () => string): FormRule[] {\n const rules = rulesOf(node, {\n functions: renderer.functions(),\n validators: renderer.validators(),\n path,\n })\n const bounds: FormRule = {}\n if (node.min !== undefined && node.min > 0) bounds.min = node.min\n if (node.max !== undefined) bounds.max = node.max\n return bounds.min === undefined && bounds.max === undefined ? rules : [...rules, bounds]\n}\n\nexport function listView(\n kit: NodeKit,\n props: NodeProps,\n renderer: RendererContext,\n scope: NodeScope,\n disabled: Flag,\n) {\n provide(disabledKey, () => disabled.value)\n const uid = useId()\n const list = () => props.node as FormListNode\n const path = () => pathIn(scope, list().name)\n const items = computed(() => {\n const value = getPath(renderer.model(), path())\n return Array.isArray(value) ? (value as Record<string, unknown>[]) : []\n })\n const rules = computed(() => listRules(list(), renderer, path))\n\n function write(next: Record<string, unknown>[]) {\n const name = path()\n setPath(renderer.model(), name, next)\n renderer.changed(name, getPath(renderer.model(), name))\n }\n const root = shallowRef<HTMLElement>()\n const footer = shallowRef<FormItemExpose>()\n onScopeDispose(renderer.trackError(path, () => footer.value?.error))\n\n /** The items of this list, not of lists inside it nor ones still animating out. */\n const itemElements = () =>\n [...(root.value?.querySelectorAll<HTMLElement>('.dou-form-renderer__list-item') ?? [])].filter(\n (el) =>\n el.closest('.dou-form-renderer__list') === root.value && !el.closest('[class*=\"-leave-\"]'),\n )\n /** Focus the first field of an item, or the add button when there is none. */\n async function focusItem(index: number) {\n // The sortable list renders its items a tick after the value changes.\n await nextTick()\n await nextTick()\n const elements = itemElements()\n const target = elements[Math.min(index, elements.length - 1)]\n const control = target?.querySelector<HTMLElement>(\n ':scope > .dou-form-renderer__grid :is(input, textarea, select, button, [tabindex=\"0\"]):not([disabled])',\n )\n ;(control ?? root.value?.querySelector<HTMLElement>('.dou-form-renderer__list-add'))?.focus()\n }\n function add() {\n write([...items.value, emptyItem(list(), renderer.fields())])\n void focusItem(items.value.length - 1)\n }\n function remove(index: number) {\n write(items.value.filter((_, at) => at !== index))\n void focusItem(index)\n }\n\n return () => {\n const node = list()\n const rows = items.value\n const messages = renderer.messages()\n // Read-only controls (a read-only builder's settings) show the items without the buttons too.\n const readonly = renderer.readonly() || renderer.controlsReadonly()\n const off = disabled.value\n const canAdd = !off && (node.max === undefined || rows.length < node.max)\n const canRemove = !off && rows.length > (node.min ?? 0)\n const sortable = node.sortable !== false && !off && !readonly && rows.length > 1\n const labelId = node.label ? `dou-form-list-${uid}` : undefined\n const required = node.required || rules.value.some((rule) => rule.required)\n return h(\n 'div',\n {\n ref: root,\n class: ['dou-form-renderer__list', off && 'is-disabled', readonly && 'is-readonly'],\n role: 'group',\n 'aria-labelledby': labelId,\n 'aria-disabled': off || undefined,\n },\n [\n node.label || node.help\n ? h('div', { class: 'dou-form-renderer__section-header' }, [\n node.label &&\n h(\n 'div',\n {\n id: labelId,\n class: ['dou-form-renderer__section-title', required && 'is-required'],\n },\n node.label,\n ),\n node.help && h('div', { class: 'dou-form-renderer__section-description' }, node.help),\n ])\n : null,\n rows.length\n ? h(\n DouSortable,\n {\n class: 'dou-form-renderer__list-items',\n modelValue: rows,\n 'onUpdate:modelValue': (next: unknown[]) =>\n write(next as Record<string, unknown>[]),\n itemKey,\n ghost: listGhost,\n handle: true,\n disabled: !sortable,\n itemLabel: (_item: unknown, index: number) =>\n formatMessage(messages.item, { index: index + 1 }),\n },\n {\n default: ({ item, index }: { item: Record<string, unknown>; index: number }) => {\n // While dragging, `index` is the place the item is shown at;\n // its fields still read and write the place it holds in the value.\n const raw = toRaw(item)\n const at = rows.findIndex((row) => toRaw(row) === raw)\n return h(ListItemView, {\n list: node,\n render: kit.renderNodes,\n path: path(),\n item,\n index: at < 0 ? index : at,\n position: index,\n columns: node.columns ?? props.columns,\n inset: props.inset + 1,\n sortable,\n canRemove,\n readonly,\n onRemove: () => remove(at < 0 ? index : at),\n })\n },\n },\n )\n : h(\n 'div',\n { class: 'dou-form-renderer__list-empty' },\n readonly ? messages.noValue : messages.empty,\n ),\n // After the items, so a reset puts their values back before the\n // list puts back its own items; its errors show under the button.\n readonly\n ? null\n : h(\n DouFormItem,\n {\n ref: footer,\n class: 'dou-form-renderer__list-footer',\n prop: path(),\n rules: rules.value,\n },\n () =>\n h(\n DouButton,\n {\n class: 'dou-form-renderer__list-add',\n variant: 'outline',\n disabled: !canAdd,\n onClick: add,\n },\n { leading: () => h(PlusIcon), default: () => node.addText ?? messages.add },\n ),\n ),\n ],\n )\n }\n}\n\n/** One item of a list: its fields read and write the item. */\nconst ListItemView = defineComponent({\n name: 'DouFormListItem',\n props: {\n list: { type: Object as PropType<FormListNode>, required: true },\n render: { type: Function as PropType<NodeKit['renderNodes']>, required: true },\n path: { type: String, required: true },\n item: { type: Object as PropType<Record<string, unknown>>, required: true },\n /** Where the item is in the value. */\n index: { type: Number, required: true },\n /** Where the item is shown, which differs while it is dragged. */\n position: { type: Number, required: true },\n columns: { type: Number, required: true },\n inset: { type: Number, required: true },\n sortable: Boolean,\n canRemove: Boolean,\n /** Without the remove button. */\n readonly: Boolean,\n },\n emits: ['remove'],\n setup(props, { emit }) {\n const renderer = inject(rendererKey)!\n provide(scopeKey, {\n prefix: () => `${props.path}.${props.index}.`,\n item: () => props.item,\n })\n return () => {\n const messages = renderer.messages()\n const number = props.position + 1\n return h('div', { class: 'dou-form-renderer__list-item' }, [\n h('div', { class: 'dou-form-renderer__list-item-header' }, [\n props.sortable\n ? h(DouSortableHandle, {\n class: 'dou-form-renderer__list-handle',\n label: formatMessage(messages.move, { index: number }),\n })\n : null,\n h(\n 'span',\n { class: 'dou-form-renderer__list-item-title' },\n formatMessage(messages.item, { index: number }),\n ),\n props.readonly\n ? null\n : h(\n DouButton,\n {\n class: 'dou-form-renderer__list-remove',\n variant: 'ghost',\n size: 'sm',\n disabled: !props.canRemove,\n 'aria-label': formatMessage(messages.remove, { index: number }),\n onClick: () => emit('remove'),\n },\n { leading: () => h(TrashIcon) },\n ),\n ]),\n h(\n 'div',\n { class: 'dou-form-renderer__grid', style: { '--dou-form-columns': props.columns } },\n props.render(props.list.children, props.columns, props.inset),\n ),\n ])\n }\n },\n})\n"],"mappings":";;;;;;;;;;AA4CA,SAAgB,UAAU,OAA4B,MAAc,SAAS,IAAa;CACxF,OAAO,WAAW,KAAK,CAAC,CAAC,MAAM,SAAS;EACtC,MAAM,MAAM,SAAS,KAAK;EAC1B,OAAO,QAAQ,QAAS,OAAO,IAAI,KAAK,KAAK,WAAW,GAAG,IAAI,EAAE;CACnE,CAAC;AACH;;AAGA,SAAgB,WAAW,OAA4B,OAAgB,SAAS,IAAc;CAC5F,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,WAAW,KAAK,GAAG;EACpC,MAAM,MAAM,SAAS,KAAK;EAC1B,MAAM,KAAK,GAAG;EACd,IAAI,CAAC,OAAO,IAAI,GAAG;EACnB,MAAM,QAAQ,QAAQ,OAAO,GAAG;EAChC,IAAI,MAAM,QAAQ,KAAK,GACrB,MAAM,SAAS,GAAG,UAChB,MAAM,KAAK,GAAG,WAAW,KAAK,UAAU,OAAO,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC,CACpE;CACJ;CACA,OAAO;AACT;;AAGA,SAAS,WAAW,OAAkB,WAAsB;CAC1D,OAAO,eACJ,MAAM,KAAsC,SAAS,QACnD,UAAU,CAAC,CAAC,SAAS,UAAU,MAAM,aAAa,MAAM,KAAK,CAChE,CACF;AACF;;AAGA,IAAM,UAAU,KAAc,MAAoB,UAChD,EAAE,IAAI,MAAM;CACV,KAAK,KAAK;CACV;CACA,SAAS,MAAM;CACf,OAAO,MAAM;CACb,QAAQ;AACV,CAAC;AAEH,SAAgB,SACd,KACA,OACA,UACA,OACA,UACA,WACA;CACA,QAAQ,mBAAmB,SAAS,KAAK;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