@dou-ui/flow 0.1.0-alpha.3 → 0.1.0-alpha.4

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.
Files changed (42) hide show
  1. package/dist/comments.js +177 -0
  2. package/dist/comments.js.map +1 -0
  3. package/dist/components/flow-comments.js +6 -0
  4. package/dist/components/flow-comments.js.map +1 -0
  5. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +184 -0
  6. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
  7. package/dist/context.js.map +1 -1
  8. package/dist/core/history.js +26 -0
  9. package/dist/core/history.js.map +1 -1
  10. package/dist/core/model.js.map +1 -1
  11. package/dist/core/node-types.js +8 -1
  12. package/dist/core/node-types.js.map +1 -1
  13. package/dist/core/transaction.js +5 -4
  14. package/dist/core/transaction.js.map +1 -1
  15. package/dist/document.js +1 -1
  16. package/dist/export/render.js +78 -0
  17. package/dist/export/render.js.map +1 -0
  18. package/dist/flow-editor.js.map +1 -1
  19. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +220 -15
  20. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  21. package/dist/index.js +4 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/kit.js +1 -1
  24. package/dist/locale.js +6 -0
  25. package/dist/locale.js.map +1 -1
  26. package/dist/style.css +1 -1
  27. package/dist/style.js +1 -1
  28. package/dist/types/comments.d.ts +55 -0
  29. package/dist/types/components/flow-comments.vue.d.ts +28 -0
  30. package/dist/types/context.d.ts +31 -1
  31. package/dist/types/core/history.d.ts +10 -0
  32. package/dist/types/core/menu.d.ts +5 -0
  33. package/dist/types/core/model.d.ts +7 -0
  34. package/dist/types/core/node-types.d.ts +2 -0
  35. package/dist/types/core/transaction.d.ts +2 -1
  36. package/dist/types/export/render.d.ts +27 -0
  37. package/dist/types/flow-editor.vue.d.ts +10 -0
  38. package/dist/types/index.d.ts +30 -1
  39. package/dist/types/locale.d.ts +4 -0
  40. package/dist/whiteboard/connector.js +1 -1
  41. package/dist/whiteboard/kit.js +1 -1
  42. package/package.json +3 -3
@@ -0,0 +1,177 @@
1
+ import { defineFlowExtension } from "./core/extension.js";
2
+ import { applyCommentAction } from "dou-ui";
3
+ import { computed, shallowRef } from "vue";
4
+ import { MessagePlusIcon } from "@dou-ui/icons";
5
+ // src/comments.ts
6
+ var KEY = "mod+alt+m";
7
+ /** The thread ids on a node or edge; nothing when a hand-written document has something else there. */
8
+ var idsOf = (item) => Array.isArray(item.comments) ? item.comments.filter((id) => typeof id === "string") : [];
9
+ function useFlowComments(options) {
10
+ const { props, emit, doc, selection, messages, transact, carry, shownOn } = options;
11
+ const threads = computed(() => props.comments ?? []);
12
+ const enabled = computed(() => props.comments !== void 0);
13
+ const writable = computed(() => enabled.value && !!props.author && props.commentable !== false);
14
+ const innerActive = shallowRef(null);
15
+ const active = computed(() => props.activeComment === void 0 ? innerActive.value : props.activeComment);
16
+ /** The last thread this editor opened, so a `v-model:activeComment` echoing it isn't taken for one from outside. */
17
+ let ownOpen = null;
18
+ function open(id) {
19
+ if (id === active.value) return;
20
+ innerActive.value = id;
21
+ ownOpen = id;
22
+ emit("update:activeComment", id);
23
+ }
24
+ const openedHere = (id) => id === ownOpen;
25
+ const pending = shallowRef(null);
26
+ const focusRequest = shallowRef(0);
27
+ const openOn = computed(() => {
28
+ const live = new Set(threads.value.filter((t) => !t.resolved).map((t) => t.id));
29
+ const collect = (items) => {
30
+ const out = /* @__PURE__ */ new Map();
31
+ for (const item of items) {
32
+ const ids = idsOf(item).filter((id) => live.has(id));
33
+ if (ids.length) out.set(item.id, ids);
34
+ }
35
+ return out;
36
+ };
37
+ return {
38
+ nodes: collect(doc.value.nodes),
39
+ edges: collect(doc.value.edges)
40
+ };
41
+ });
42
+ const threadsOf = (anchor) => ("node" in anchor ? openOn.value.nodes.get(anchor.node) : openOn.value.edges.get(anchor.edge)) ?? [];
43
+ /** The open threads on a node or edge, with those its marker shows for what it hides. */
44
+ const openThere = (anchor) => shownOn(anchor) ?? threadsOf(anchor);
45
+ /** The one node or edge selected. */
46
+ function selected() {
47
+ const { nodes, edges } = selection.value;
48
+ if (nodes.length === 1 && !edges.length) return { node: nodes[0] };
49
+ if (edges.length === 1 && !nodes.length) return { edge: edges[0] };
50
+ return null;
51
+ }
52
+ function show(id, focus) {
53
+ pending.value = null;
54
+ open(id);
55
+ if (focus) focusRequest.value++;
56
+ }
57
+ /**
58
+ * Opens the threads on a node or edge, the selected one by default, or
59
+ * the box to start one there. `focus` puts the focus in the reply box:
60
+ * from the keyboard, not from a tap, which would bring up the keyboard
61
+ * on a phone.
62
+ */
63
+ function start(anchor = selected(), focus = true) {
64
+ if (!enabled.value || !anchor) return false;
65
+ if (!("node" in anchor ? doc.value.nodes.some((n) => n.id === anchor.node) : doc.value.edges.some((e) => e.id === anchor.edge))) return false;
66
+ const [first] = openThere(anchor);
67
+ if (first) {
68
+ show(first, focus);
69
+ return true;
70
+ }
71
+ if (!writable.value) return false;
72
+ open(null);
73
+ pending.value = anchor;
74
+ focusRequest.value++;
75
+ return true;
76
+ }
77
+ function close() {
78
+ pending.value = null;
79
+ open(null);
80
+ }
81
+ /** Adds or takes away a thread's id on what it is about; not an undo step. */
82
+ function mark(anchor, id, add) {
83
+ let patch = null;
84
+ transact((tr) => {
85
+ const item = "node" in anchor ? tr.getNode(anchor.node) : tr.getEdge(anchor.edge);
86
+ if (!item) return;
87
+ const had = idsOf(item);
88
+ const next = add ? [...had.filter((x) => x !== id), id] : had.filter((x) => x !== id);
89
+ patch = { comments: next.length ? next : void 0 };
90
+ if ("node" in anchor) tr.updateNode(anchor.node, patch);
91
+ else tr.updateEdge(anchor.edge, patch);
92
+ }, {
93
+ history: false,
94
+ origin: "comment"
95
+ });
96
+ if (patch) carry(anchor, patch);
97
+ }
98
+ function anchorOf(id) {
99
+ const node = doc.value.nodes.find((n) => idsOf(n).includes(id));
100
+ if (node) return { node: node.id };
101
+ const edge = doc.value.edges.find((e) => idsOf(e).includes(id));
102
+ return edge ? { edge: edge.id } : null;
103
+ }
104
+ function apply(action) {
105
+ if (action.type === "create") {
106
+ const anchor = pending.value;
107
+ if (!anchor) return;
108
+ mark(anchor, action.thread.id, true);
109
+ pending.value = null;
110
+ } else if (action.type === "remove") {
111
+ const anchor = anchorOf(action.threadId);
112
+ if (anchor) mark(anchor, action.threadId, false);
113
+ }
114
+ emit("update:comments", applyCommentAction(threads.value, action));
115
+ emit("commentAction", action);
116
+ if (action.type === "create") {
117
+ open(action.thread.id);
118
+ focusRequest.value++;
119
+ } else if (action.type === "remove" || action.type === "resolve") open(null);
120
+ }
121
+ function anchors() {
122
+ return Object.fromEntries(threads.value.map((thread) => [thread.id, anchorOf(thread.id)]));
123
+ }
124
+ /** Whether `anchor` has something to offer: a thread to open, or one to start. */
125
+ const offered = (anchor) => enabled.value && (writable.value || openThere(anchor).length > 0);
126
+ const item = (anchor) => ({
127
+ key: "comment",
128
+ label: messages.value.comment,
129
+ icon: MessagePlusIcon,
130
+ shortcut: KEY,
131
+ showWhenReadonly: true,
132
+ run: () => void start(anchor)
133
+ });
134
+ const extension = defineFlowExtension({
135
+ name: "comments",
136
+ keymap: () => ({ [KEY]: () => start() }),
137
+ contextMenu(_, target) {
138
+ if (target.kind === "canvas") return [];
139
+ const anchor = target.kind === "node" ? { node: target.node.id } : { edge: target.edge.id };
140
+ return offered(anchor) ? [item(anchor)] : [];
141
+ },
142
+ toolbarItems(_, nodes) {
143
+ if (nodes.length !== 1) return [];
144
+ const anchor = { node: nodes[0].id };
145
+ return offered(anchor) ? [item(anchor)] : [];
146
+ },
147
+ edgeToolbarItems(_, edges) {
148
+ if (edges.length !== 1) return [];
149
+ const anchor = { edge: edges[0].id };
150
+ return offered(anchor) ? [item(anchor)] : [];
151
+ }
152
+ });
153
+ return {
154
+ comments: {
155
+ enabled,
156
+ writable,
157
+ threads,
158
+ author: computed(() => props.author),
159
+ active,
160
+ pending,
161
+ focusRequest,
162
+ openOn,
163
+ start,
164
+ show,
165
+ apply,
166
+ open,
167
+ close,
168
+ openedHere
169
+ },
170
+ extension,
171
+ anchors,
172
+ anchorOf
173
+ };
174
+ }
175
+ export { useFlowComments };
176
+
177
+ //# sourceMappingURL=comments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comments.js","names":[],"sources":["../src/comments.ts"],"sourcesContent":["import { MessagePlusIcon } from '@dou-ui/icons'\nimport {\n applyCommentAction,\n type CommentAction,\n type CommentAuthor,\n type CommentThread,\n type ContextMenuItem,\n} from 'dou-ui'\nimport { computed, shallowRef, type ComputedRef, type Ref, type ShallowRef } from 'vue'\nimport type { FlowCommentAnchor, FlowEditorEmits, FlowEditorProps } from './context'\nimport { defineFlowExtension, type FlowExtension } from './core/extension'\nimport type { FlowToolbarItem } from './core/menu'\nimport type { FlowDocument, FlowSelection } from './core/model'\nimport type { FlowTransaction, FlowTransactionMeta } from './core/transaction'\nimport type { FlowMessages } from './locale'\n\ntype Emit = <K extends keyof FlowEditorEmits>(event: K, ...args: FlowEditorEmits[K]) => void\n\n/** The comments, as the editor's parts see them. */\nexport interface FlowComments {\n enabled: ComputedRef<boolean>\n /** Threads can be started and replied to. */\n writable: ComputedRef<boolean>\n threads: ComputedRef<readonly CommentThread[]>\n author: ComputedRef<CommentAuthor | undefined>\n /** The thread open now. */\n active: ComputedRef<string | null>\n /** What a thread being started is about, until its first comment is sent. */\n pending: ShallowRef<FlowCommentAnchor | null>\n /** Goes up when the open thread should take the focus, ready for a reply. */\n focusRequest: ShallowRef<number>\n /** The open threads on each node and edge, oldest first. */\n openOn: ComputedRef<{ nodes: Map<string, string[]>; edges: Map<string, string[]> }>\n start: (anchor?: FlowCommentAnchor | null, focus?: boolean) => boolean\n /** Opens a thread, with the focus in its reply box when `focus`. */\n show: (id: string, focus: boolean) => void\n apply: (action: CommentAction) => void\n open: (id: string | null) => void\n close: () => void\n /** Whether this editor opened the thread `id`, rather than the app. */\n openedHere: (id: string | null) => boolean\n}\n\nconst KEY = 'mod+alt+m'\n\n/** The thread ids on a node or edge; nothing when a hand-written document has something else there. */\nconst idsOf = (item: { comments?: unknown }): string[] =>\n Array.isArray(item.comments) ? item.comments.filter((id) => typeof id === 'string') : []\n\nexport function useFlowComments(options: {\n props: FlowEditorProps\n emit: Emit\n doc: ComputedRef<FlowDocument>\n selection: Ref<FlowSelection>\n messages: ComputedRef<FlowMessages>\n transact: (fn: (tr: FlowTransaction) => void, meta?: FlowTransactionMeta) => FlowTransaction\n /** Keeps a change kept out of undo on a node or edge as undo and redo bring it back. */\n carry: (anchor: FlowCommentAnchor, patch: { comments: string[] | undefined }) => void\n /** The open threads a node's marker counts: a collapsed container's take in those inside it. */\n shownOn: (anchor: FlowCommentAnchor) => string[] | undefined\n}) {\n const { props, emit, doc, selection, messages, transact, carry, shownOn } = options\n\n const threads = computed<readonly CommentThread[]>(() => props.comments ?? [])\n const enabled = computed(() => props.comments !== undefined)\n const writable = computed(() => enabled.value && !!props.author && props.commentable !== false)\n\n const innerActive = shallowRef<string | null>(null)\n const active = computed(() =>\n props.activeComment === undefined ? innerActive.value : props.activeComment,\n )\n /** The last thread this editor opened, so a `v-model:activeComment` echoing it isn't taken for one from outside. */\n let ownOpen: string | null = null\n function open(id: string | null) {\n if (id === active.value) return\n innerActive.value = id\n ownOpen = id\n emit('update:activeComment', id)\n }\n const openedHere = (id: string | null) => id === ownOpen\n\n const pending = shallowRef<FlowCommentAnchor | null>(null)\n const focusRequest = shallowRef(0)\n\n const openOn = computed(() => {\n const live = new Set(threads.value.filter((t) => !t.resolved).map((t) => t.id))\n const collect = (items: readonly { id: string; comments?: unknown }[]) => {\n const out = new Map<string, string[]>()\n for (const item of items) {\n const ids = idsOf(item).filter((id) => live.has(id))\n if (ids.length) out.set(item.id, ids)\n }\n return out\n }\n return { nodes: collect(doc.value.nodes), edges: collect(doc.value.edges) }\n })\n\n const threadsOf = (anchor: FlowCommentAnchor) =>\n ('node' in anchor\n ? openOn.value.nodes.get(anchor.node)\n : openOn.value.edges.get(anchor.edge)) ?? []\n\n /** The open threads on a node or edge, with those its marker shows for what it hides. */\n const openThere = (anchor: FlowCommentAnchor) => shownOn(anchor) ?? threadsOf(anchor)\n\n /** The one node or edge selected. */\n function selected(): FlowCommentAnchor | null {\n const { nodes, edges } = selection.value\n if (nodes.length === 1 && !edges.length) return { node: nodes[0]! }\n if (edges.length === 1 && !nodes.length) return { edge: edges[0]! }\n return null\n }\n\n function show(id: string, focus: boolean) {\n pending.value = null\n open(id)\n if (focus) focusRequest.value++\n }\n\n /**\n * Opens the threads on a node or edge, the selected one by default, or\n * the box to start one there. `focus` puts the focus in the reply box:\n * from the keyboard, not from a tap, which would bring up the keyboard\n * on a phone.\n */\n function start(anchor: FlowCommentAnchor | null = selected(), focus = true): boolean {\n if (!enabled.value || !anchor) return false\n const there =\n 'node' in anchor\n ? doc.value.nodes.some((n) => n.id === anchor.node)\n : doc.value.edges.some((e) => e.id === anchor.edge)\n if (!there) return false\n // one already there, or shown there: open it\n const [first] = openThere(anchor)\n if (first) {\n show(first, focus)\n return true\n }\n if (!writable.value) return false\n open(null)\n pending.value = anchor\n focusRequest.value++\n return true\n }\n\n function close() {\n pending.value = null\n open(null)\n }\n\n /** Adds or takes away a thread's id on what it is about; not an undo step. */\n function mark(anchor: FlowCommentAnchor, id: string, add: boolean) {\n let patch: { comments: string[] | undefined } | null = null\n transact(\n (tr) => {\n const item = 'node' in anchor ? tr.getNode(anchor.node) : tr.getEdge(anchor.edge)\n if (!item) return\n const had = idsOf(item)\n const next = add ? [...had.filter((x) => x !== id), id] : had.filter((x) => x !== id)\n patch = { comments: next.length ? next : undefined }\n if ('node' in anchor) tr.updateNode(anchor.node, patch)\n else tr.updateEdge(anchor.edge, patch)\n },\n { history: false, origin: 'comment' },\n )\n if (patch) carry(anchor, patch)\n }\n\n function anchorOf(id: string): FlowCommentAnchor | null {\n const node = doc.value.nodes.find((n) => idsOf(n).includes(id))\n if (node) return { node: node.id }\n const edge = doc.value.edges.find((e) => idsOf(e).includes(id))\n return edge ? { edge: edge.id } : null\n }\n\n function apply(action: CommentAction) {\n if (action.type === 'create') {\n const anchor = pending.value\n if (!anchor) return\n mark(anchor, action.thread.id, true)\n pending.value = null\n } else if (action.type === 'remove') {\n const anchor = anchorOf(action.threadId)\n if (anchor) mark(anchor, action.threadId, false)\n }\n emit('update:comments', applyCommentAction(threads.value, action))\n emit('commentAction', action)\n if (action.type === 'create') {\n open(action.thread.id)\n focusRequest.value++\n } else if (action.type === 'remove' || action.type === 'resolve') open(null)\n }\n\n function anchors(): Record<string, FlowCommentAnchor | null> {\n return Object.fromEntries(threads.value.map((thread) => [thread.id, anchorOf(thread.id)]))\n }\n\n /** Whether `anchor` has something to offer: a thread to open, or one to start. */\n const offered = (anchor: FlowCommentAnchor) =>\n enabled.value && (writable.value || openThere(anchor).length > 0)\n\n const item = (anchor: FlowCommentAnchor): FlowToolbarItem & ContextMenuItem => ({\n key: 'comment',\n label: messages.value.comment,\n icon: MessagePlusIcon,\n shortcut: KEY,\n showWhenReadonly: true,\n run: () => void start(anchor),\n })\n\n const extension: FlowExtension = defineFlowExtension({\n name: 'comments',\n keymap: () => ({ [KEY]: () => start() }),\n contextMenu(_, target) {\n if (target.kind === 'canvas') return []\n const anchor = target.kind === 'node' ? { node: target.node.id } : { edge: target.edge.id }\n return offered(anchor) ? [item(anchor)] : []\n },\n toolbarItems(_, nodes) {\n if (nodes.length !== 1) return []\n const anchor = { node: nodes[0]!.id }\n return offered(anchor) ? [item(anchor)] : []\n },\n edgeToolbarItems(_, edges) {\n if (edges.length !== 1) return []\n const anchor = { edge: edges[0]!.id }\n return offered(anchor) ? [item(anchor)] : []\n },\n })\n\n const comments: FlowComments = {\n enabled,\n writable,\n threads,\n author: computed(() => props.author),\n active,\n pending,\n focusRequest,\n openOn,\n start,\n show,\n apply,\n open,\n close,\n openedHere,\n }\n\n return { comments, extension, anchors, anchorOf }\n}\n"],"mappings":";;;;;AA2CA,IAAM,MAAM;;AA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_vue_vue_type_script_setup_true_lang_default from "./flow-comments.vue_vue_type_script_setup_true_lang.js";
2
+ // src/components/flow-comments.vue
3
+ var flow_comments_default = flow_comments_vue_vue_type_script_setup_true_lang_default;
4
+ export { flow_comments_default as default };
5
+
6
+ //# sourceMappingURL=flow-comments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-comments.js","names":["_sfc_main"],"sources":["../../src/components/flow-comments.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { MessageCircleIcon } from '@dou-ui/icons'\nimport {\n DouCommentThread,\n useFloating,\n useLayer,\n useZIndex,\n type CommentThread,\n type VirtualElement,\n} from 'dou-ui'\nimport { computed, nextTick, shallowRef, useTemplateRef, watch } from 'vue'\nimport type { FlowComments } from '../comments'\nimport type { FlowCommentAnchor } from '../context'\nimport { format, type FlowMessages } from '../locale'\n\n/*\n * The comments over the canvas: a marker on each node and edge with open\n * threads, and the card with the threads of the one opened, or the box\n * for a thread being started.\n */\n\nexport interface FlowCommentMarker {\n key: string\n anchor: FlowCommentAnchor\n /** The open threads there, oldest first, counted on the marker; empty for a thread being started. */\n threads: string[]\n /** The threads its card shows: the open ones, and a resolved one opened from outside. */\n shown: string[]\n /** A thread is being started here. */\n pending: boolean\n /** Where it goes, in px within the editor. */\n x: number\n y: number\n /** Above an edge's label: a finger's target keeps clear of the label. */\n lifted: boolean\n}\n\nconst props = defineProps<{\n comments: FlowComments\n markers: FlowCommentMarker[]\n messages: FlowMessages\n /** Gives the focus back to what a thread is about, after the card closes. */\n restore: (anchor: FlowCommentAnchor | null) => void\n}>()\n\nconst { comments } = props\nconst panel = shallowRef<HTMLElement | null>(null)\nconst markerEls = new Map<string, HTMLElement>()\n\n/** The marker the card belongs to: the active thread's, or the one being started. */\nconst current = computed<FlowCommentMarker | null>(() => {\n if (comments.pending.value) return props.markers.find((m) => m.pending) ?? null\n const id = comments.active.value\n return (id && props.markers.find((m) => m.shown.includes(id))) || null\n})\n\n/** The threads the card shows: every open one there, or the active one opened from elsewhere. */\nconst shown = computed<CommentThread[]>(() => {\n const marker = current.value\n if (!marker || comments.pending.value) return []\n const byId = new Map(comments.threads.value.map((t) => [t.id, t]))\n return marker.shown.flatMap((id) => byId.get(id) ?? [])\n})\n\nconst open = computed(() => !!current.value)\n\nconst layer = shallowRef<HTMLElement | null>(null)\n/** The marker has been panned out of the editor: the card waits, hidden, until it is back. */\nconst away = computed(() => {\n const marker = current.value\n const el = layer.value\n if (!marker || !el) return false\n return marker.x < 0 || marker.y < 0 || marker.x > el.clientWidth || marker.y > el.clientHeight\n})\n\n// Hiding the card drops the focus in it: give it back when the card returns.\nlet awayFocus: HTMLElement | null = null\nwatch(away, async (now) => {\n if (now) {\n const el = document.activeElement\n awayFocus = el instanceof HTMLElement && panel.value?.contains(el) ? el : null\n return\n }\n const el = awayFocus\n awayFocus = null\n await nextTick()\n const at = document.activeElement\n if (el?.isConnected && (!at || at === document.body)) el.focus({ preventScroll: true })\n})\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const marker = current.value\n const el = marker && markerEls.get(marker.key)\n return el ? el.getBoundingClientRect() : new DOMRect()\n },\n}\n\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'bottom-start',\n offset: 6,\n})\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\n// follows its marker as the canvas pans and zooms\nwatch(\n () => current.value && [current.value.x, current.value.y],\n () => open.value && void nextTick(update),\n)\n\nlet lastAnchor: FlowCommentAnchor | null = null\nwatch(current, (marker) => marker && (lastAnchor = marker.anchor), { immediate: true })\n\nconst focusLost = () => {\n const el = document.activeElement\n return !el || el === document.body || !!panel.value?.contains(el)\n}\n\nfunction close() {\n const refocus = focusLost()\n comments.close()\n if (refocus) props.restore(lastAnchor)\n}\n\nuseLayer({\n open,\n elements: () => [panel.value, ...markerEls.values()],\n onEscape: () => close(),\n onOutside: () => comments.close(),\n})\n\nconst views = useTemplateRef<InstanceType<typeof DouCommentThread>[]>('views')\n// asked to (the keyboard shortcut, or a thread just started): the reply box\nwatch(\n () => comments.focusRequest.value,\n async () => {\n await nextTick()\n await nextTick()\n const id = comments.active.value\n const index = shown.value.findIndex((t) => t.id === id)\n views.value?.[Math.max(0, index)]?.focus()\n },\n)\n\n// a thread resolved or removed from the card: back to what it is about,\n// once the card is gone\nfunction onClosed() {\n const el = document.activeElement\n if (!el || el === document.body) props.restore(lastAnchor)\n}\n\nfunction press(marker: FlowCommentMarker, event: MouseEvent) {\n if (current.value?.key === marker.key) return comments.close()\n // pressed from the keyboard (no clicks counted): straight into the reply box;\n // a click or tap only shows the threads, without bringing up a phone's keyboard\n const focus = event.detail === 0\n const [first] = marker.threads\n if (first) comments.show(first, focus)\n else comments.start(marker.anchor, focus)\n}\n\nconst label = (marker: FlowCommentMarker) =>\n format(props.messages.comments, { count: marker.threads.length })\n</script>\n\n<template>\n <div ref=\"layer\" class=\"dou-flow-editor__comments\">\n <button\n v-for=\"marker in markers\"\n :key=\"marker.key\"\n :ref=\"\n (el) => (el ? markerEls.set(marker.key, el as HTMLElement) : markerEls.delete(marker.key))\n \"\n type=\"button\"\n class=\"dou-flow-editor__comment\"\n :class=\"{\n 'is-active': current?.key === marker.key,\n 'is-new': !marker.threads.length,\n 'is-node': 'node' in marker.anchor,\n 'is-lifted': marker.lifted,\n }\"\n :style=\"{ translate: `${marker.x}px ${marker.y}px` }\"\n :aria-label=\"marker.threads.length ? label(marker) : messages.comment\"\n :aria-expanded=\"current?.key === marker.key\"\n @click=\"press(marker, $event)\"\n >\n <MessageCircleIcon aria-hidden=\"true\" />\n <span v-if=\"marker.threads.length > 1\" class=\"dou-flow-editor__comment-count\">{{\n marker.threads.length\n }}</span>\n </button>\n </div>\n <Transition name=\"dou-floating\" @after-leave=\"onClosed\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-flow-editor__comment-card\"\n :class=\"{ 'is-away': away }\"\n role=\"dialog\"\n :aria-label=\"messages.comment\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n >\n <template v-if=\"comments.pending.value\">\n <DouCommentThread\n ref=\"views\"\n key=\"new\"\n :thread=\"null\"\n :author=\"comments.author.value\"\n autofocus\n @action=\"comments.apply\"\n @cancel=\"close\"\n />\n </template>\n <template v-else>\n <DouCommentThread\n v-for=\"thread in shown\"\n :key=\"thread.id\"\n ref=\"views\"\n :thread=\"thread\"\n :author=\"comments.author.value\"\n :readonly=\"!comments.writable.value\"\n @action=\"comments.apply\"\n @cancel=\"close\"\n />\n </template>\n </div>\n </Transition>\n</template>\n"],"mappings":""}
@@ -0,0 +1,184 @@
1
+ import { format } from "../locale.js";
2
+ import { DouCommentThread, useFloating, useLayer, useZIndex } from "dou-ui";
3
+ import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, nextTick, normalizeClass, normalizeStyle, openBlock, renderList, shallowRef, toDisplayString, unref, useTemplateRef, watch, withCtx } from "vue";
4
+ import { MessageCircleIcon } from "@dou-ui/icons";
5
+ // src/components/flow-comments.vue?vue&type=script&setup=true&lang.ts
6
+ var _hoisted_1 = [
7
+ "aria-label",
8
+ "aria-expanded",
9
+ "onClick"
10
+ ];
11
+ var _hoisted_2 = {
12
+ key: 0,
13
+ class: "dou-flow-editor__comment-count"
14
+ };
15
+ var _hoisted_3 = ["aria-label", "data-placement"];
16
+ var flow_comments_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
17
+ __name: "flow-comments",
18
+ props: {
19
+ comments: {},
20
+ markers: {},
21
+ messages: {},
22
+ restore: { type: Function }
23
+ },
24
+ setup(__props) {
25
+ const props = __props;
26
+ const { comments } = props;
27
+ const panel = shallowRef(null);
28
+ const markerEls = /* @__PURE__ */ new Map();
29
+ /** The marker the card belongs to: the active thread's, or the one being started. */
30
+ const current = computed(() => {
31
+ if (comments.pending.value) return props.markers.find((m) => m.pending) ?? null;
32
+ const id = comments.active.value;
33
+ return id && props.markers.find((m) => m.shown.includes(id)) || null;
34
+ });
35
+ /** The threads the card shows: every open one there, or the active one opened from elsewhere. */
36
+ const shown = computed(() => {
37
+ const marker = current.value;
38
+ if (!marker || comments.pending.value) return [];
39
+ const byId = new Map(comments.threads.value.map((t) => [t.id, t]));
40
+ return marker.shown.flatMap((id) => byId.get(id) ?? []);
41
+ });
42
+ const open = computed(() => !!current.value);
43
+ const layer = shallowRef(null);
44
+ /** The marker has been panned out of the editor: the card waits, hidden, until it is back. */
45
+ const away = computed(() => {
46
+ const marker = current.value;
47
+ const el = layer.value;
48
+ if (!marker || !el) return false;
49
+ return marker.x < 0 || marker.y < 0 || marker.x > el.clientWidth || marker.y > el.clientHeight;
50
+ });
51
+ let awayFocus = null;
52
+ watch(away, async (now) => {
53
+ if (now) {
54
+ const el = document.activeElement;
55
+ awayFocus = el instanceof HTMLElement && panel.value?.contains(el) ? el : null;
56
+ return;
57
+ }
58
+ const el = awayFocus;
59
+ awayFocus = null;
60
+ await nextTick();
61
+ const at = document.activeElement;
62
+ if (el?.isConnected && (!at || at === document.body)) el.focus({ preventScroll: true });
63
+ });
64
+ const anchor = { getBoundingClientRect() {
65
+ const marker = current.value;
66
+ const el = marker && markerEls.get(marker.key);
67
+ return el ? el.getBoundingClientRect() : new DOMRect();
68
+ } };
69
+ const { style, placement, update } = useFloating(() => open.value ? anchor : null, panel, {
70
+ open,
71
+ placement: "bottom-start",
72
+ offset: 6
73
+ });
74
+ const { next } = useZIndex();
75
+ const zIndex = shallowRef(0);
76
+ watch(open, (value) => value && (zIndex.value = next()), { immediate: true });
77
+ watch(() => current.value && [current.value.x, current.value.y], () => open.value && void nextTick(update));
78
+ let lastAnchor = null;
79
+ watch(current, (marker) => marker && (lastAnchor = marker.anchor), { immediate: true });
80
+ const focusLost = () => {
81
+ const el = document.activeElement;
82
+ return !el || el === document.body || !!panel.value?.contains(el);
83
+ };
84
+ function close() {
85
+ const refocus = focusLost();
86
+ comments.close();
87
+ if (refocus) props.restore(lastAnchor);
88
+ }
89
+ useLayer({
90
+ open,
91
+ elements: () => [panel.value, ...markerEls.values()],
92
+ onEscape: () => close(),
93
+ onOutside: () => comments.close()
94
+ });
95
+ const views = useTemplateRef("views");
96
+ watch(() => comments.focusRequest.value, async () => {
97
+ await nextTick();
98
+ await nextTick();
99
+ const id = comments.active.value;
100
+ const index = shown.value.findIndex((t) => t.id === id);
101
+ views.value?.[Math.max(0, index)]?.focus();
102
+ });
103
+ function onClosed() {
104
+ const el = document.activeElement;
105
+ if (!el || el === document.body) props.restore(lastAnchor);
106
+ }
107
+ function press(marker, event) {
108
+ if (current.value?.key === marker.key) return comments.close();
109
+ const focus = event.detail === 0;
110
+ const [first] = marker.threads;
111
+ if (first) comments.show(first, focus);
112
+ else comments.start(marker.anchor, focus);
113
+ }
114
+ const label = (marker) => format(props.messages.comments, { count: marker.threads.length });
115
+ return (_ctx, _cache) => {
116
+ return openBlock(), createElementBlock(Fragment, null, [createElementVNode("div", {
117
+ ref_key: "layer",
118
+ ref: layer,
119
+ class: "dou-flow-editor__comments"
120
+ }, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.markers, (marker) => {
121
+ return openBlock(), createElementBlock("button", {
122
+ key: marker.key,
123
+ ref_for: true,
124
+ ref: (el) => el ? unref(markerEls).set(marker.key, el) : unref(markerEls).delete(marker.key),
125
+ type: "button",
126
+ class: normalizeClass(["dou-flow-editor__comment", {
127
+ "is-active": current.value?.key === marker.key,
128
+ "is-new": !marker.threads.length,
129
+ "is-node": "node" in marker.anchor,
130
+ "is-lifted": marker.lifted
131
+ }]),
132
+ style: normalizeStyle({ translate: `${marker.x}px ${marker.y}px` }),
133
+ "aria-label": marker.threads.length ? label(marker) : __props.messages.comment,
134
+ "aria-expanded": current.value?.key === marker.key,
135
+ onClick: ($event) => press(marker, $event)
136
+ }, [createVNode(unref(MessageCircleIcon), { "aria-hidden": "true" }), marker.threads.length > 1 ? (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(marker.threads.length), 1)) : createCommentVNode("", true)], 14, _hoisted_1);
137
+ }), 128))], 512), createVNode(Transition, {
138
+ name: "dou-floating",
139
+ onAfterLeave: onClosed
140
+ }, {
141
+ default: withCtx(() => [open.value ? (openBlock(), createElementBlock("div", {
142
+ key: 0,
143
+ ref_key: "panel",
144
+ ref: panel,
145
+ class: normalizeClass(["dou-floating dou-flow-editor__comment-card", { "is-away": away.value }]),
146
+ role: "dialog",
147
+ "aria-label": __props.messages.comment,
148
+ style: normalizeStyle([unref(style), { zIndex: zIndex.value }]),
149
+ "data-placement": unref(placement)
150
+ }, [unref(comments).pending.value ? (openBlock(), createBlock(unref(DouCommentThread), {
151
+ ref_key: "views",
152
+ ref: views,
153
+ key: "new",
154
+ thread: null,
155
+ author: unref(comments).author.value,
156
+ autofocus: "",
157
+ onAction: unref(comments).apply,
158
+ onCancel: close
159
+ }, null, 8, ["author", "onAction"])) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(shown.value, (thread) => {
160
+ return openBlock(), createBlock(unref(DouCommentThread), {
161
+ key: thread.id,
162
+ ref_for: true,
163
+ ref_key: "views",
164
+ ref: views,
165
+ thread,
166
+ author: unref(comments).author.value,
167
+ readonly: !unref(comments).writable.value,
168
+ onAction: unref(comments).apply,
169
+ onCancel: close
170
+ }, null, 8, [
171
+ "thread",
172
+ "author",
173
+ "readonly",
174
+ "onAction"
175
+ ]);
176
+ }), 128))], 14, _hoisted_3)) : createCommentVNode("", true)]),
177
+ _: 1
178
+ })], 64);
179
+ };
180
+ }
181
+ });
182
+ export { flow_comments_vue_vue_type_script_setup_true_lang_default as default };
183
+
184
+ //# sourceMappingURL=flow-comments.vue_vue_type_script_setup_true_lang.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-comments.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_createElementVNode","_renderList","_unref","_normalizeClass","_normalizeStyle","_createVNode","_toDisplayString","_createCommentVNode","_Transition","_withCtx","_createBlock"],"sources":["../../src/components/flow-comments.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { MessageCircleIcon } from '@dou-ui/icons'\nimport {\n DouCommentThread,\n useFloating,\n useLayer,\n useZIndex,\n type CommentThread,\n type VirtualElement,\n} from 'dou-ui'\nimport { computed, nextTick, shallowRef, useTemplateRef, watch } from 'vue'\nimport type { FlowComments } from '../comments'\nimport type { FlowCommentAnchor } from '../context'\nimport { format, type FlowMessages } from '../locale'\n\n/*\n * The comments over the canvas: a marker on each node and edge with open\n * threads, and the card with the threads of the one opened, or the box\n * for a thread being started.\n */\n\nexport interface FlowCommentMarker {\n key: string\n anchor: FlowCommentAnchor\n /** The open threads there, oldest first, counted on the marker; empty for a thread being started. */\n threads: string[]\n /** The threads its card shows: the open ones, and a resolved one opened from outside. */\n shown: string[]\n /** A thread is being started here. */\n pending: boolean\n /** Where it goes, in px within the editor. */\n x: number\n y: number\n /** Above an edge's label: a finger's target keeps clear of the label. */\n lifted: boolean\n}\n\nconst props = defineProps<{\n comments: FlowComments\n markers: FlowCommentMarker[]\n messages: FlowMessages\n /** Gives the focus back to what a thread is about, after the card closes. */\n restore: (anchor: FlowCommentAnchor | null) => void\n}>()\n\nconst { comments } = props\nconst panel = shallowRef<HTMLElement | null>(null)\nconst markerEls = new Map<string, HTMLElement>()\n\n/** The marker the card belongs to: the active thread's, or the one being started. */\nconst current = computed<FlowCommentMarker | null>(() => {\n if (comments.pending.value) return props.markers.find((m) => m.pending) ?? null\n const id = comments.active.value\n return (id && props.markers.find((m) => m.shown.includes(id))) || null\n})\n\n/** The threads the card shows: every open one there, or the active one opened from elsewhere. */\nconst shown = computed<CommentThread[]>(() => {\n const marker = current.value\n if (!marker || comments.pending.value) return []\n const byId = new Map(comments.threads.value.map((t) => [t.id, t]))\n return marker.shown.flatMap((id) => byId.get(id) ?? [])\n})\n\nconst open = computed(() => !!current.value)\n\nconst layer = shallowRef<HTMLElement | null>(null)\n/** The marker has been panned out of the editor: the card waits, hidden, until it is back. */\nconst away = computed(() => {\n const marker = current.value\n const el = layer.value\n if (!marker || !el) return false\n return marker.x < 0 || marker.y < 0 || marker.x > el.clientWidth || marker.y > el.clientHeight\n})\n\n// Hiding the card drops the focus in it: give it back when the card returns.\nlet awayFocus: HTMLElement | null = null\nwatch(away, async (now) => {\n if (now) {\n const el = document.activeElement\n awayFocus = el instanceof HTMLElement && panel.value?.contains(el) ? el : null\n return\n }\n const el = awayFocus\n awayFocus = null\n await nextTick()\n const at = document.activeElement\n if (el?.isConnected && (!at || at === document.body)) el.focus({ preventScroll: true })\n})\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const marker = current.value\n const el = marker && markerEls.get(marker.key)\n return el ? el.getBoundingClientRect() : new DOMRect()\n },\n}\n\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'bottom-start',\n offset: 6,\n})\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\n// follows its marker as the canvas pans and zooms\nwatch(\n () => current.value && [current.value.x, current.value.y],\n () => open.value && void nextTick(update),\n)\n\nlet lastAnchor: FlowCommentAnchor | null = null\nwatch(current, (marker) => marker && (lastAnchor = marker.anchor), { immediate: true })\n\nconst focusLost = () => {\n const el = document.activeElement\n return !el || el === document.body || !!panel.value?.contains(el)\n}\n\nfunction close() {\n const refocus = focusLost()\n comments.close()\n if (refocus) props.restore(lastAnchor)\n}\n\nuseLayer({\n open,\n elements: () => [panel.value, ...markerEls.values()],\n onEscape: () => close(),\n onOutside: () => comments.close(),\n})\n\nconst views = useTemplateRef<InstanceType<typeof DouCommentThread>[]>('views')\n// asked to (the keyboard shortcut, or a thread just started): the reply box\nwatch(\n () => comments.focusRequest.value,\n async () => {\n await nextTick()\n await nextTick()\n const id = comments.active.value\n const index = shown.value.findIndex((t) => t.id === id)\n views.value?.[Math.max(0, index)]?.focus()\n },\n)\n\n// a thread resolved or removed from the card: back to what it is about,\n// once the card is gone\nfunction onClosed() {\n const el = document.activeElement\n if (!el || el === document.body) props.restore(lastAnchor)\n}\n\nfunction press(marker: FlowCommentMarker, event: MouseEvent) {\n if (current.value?.key === marker.key) return comments.close()\n // pressed from the keyboard (no clicks counted): straight into the reply box;\n // a click or tap only shows the threads, without bringing up a phone's keyboard\n const focus = event.detail === 0\n const [first] = marker.threads\n if (first) comments.show(first, focus)\n else comments.start(marker.anchor, focus)\n}\n\nconst label = (marker: FlowCommentMarker) =>\n format(props.messages.comments, { count: marker.threads.length })\n</script>\n\n<template>\n <div ref=\"layer\" class=\"dou-flow-editor__comments\">\n <button\n v-for=\"marker in markers\"\n :key=\"marker.key\"\n :ref=\"\n (el) => (el ? markerEls.set(marker.key, el as HTMLElement) : markerEls.delete(marker.key))\n \"\n type=\"button\"\n class=\"dou-flow-editor__comment\"\n :class=\"{\n 'is-active': current?.key === marker.key,\n 'is-new': !marker.threads.length,\n 'is-node': 'node' in marker.anchor,\n 'is-lifted': marker.lifted,\n }\"\n :style=\"{ translate: `${marker.x}px ${marker.y}px` }\"\n :aria-label=\"marker.threads.length ? label(marker) : messages.comment\"\n :aria-expanded=\"current?.key === marker.key\"\n @click=\"press(marker, $event)\"\n >\n <MessageCircleIcon aria-hidden=\"true\" />\n <span v-if=\"marker.threads.length > 1\" class=\"dou-flow-editor__comment-count\">{{\n marker.threads.length\n }}</span>\n </button>\n </div>\n <Transition name=\"dou-floating\" @after-leave=\"onClosed\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-flow-editor__comment-card\"\n :class=\"{ 'is-away': away }\"\n role=\"dialog\"\n :aria-label=\"messages.comment\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n >\n <template v-if=\"comments.pending.value\">\n <DouCommentThread\n ref=\"views\"\n key=\"new\"\n :thread=\"null\"\n :author=\"comments.author.value\"\n autofocus\n @action=\"comments.apply\"\n @cancel=\"close\"\n />\n </template>\n <template v-else>\n <DouCommentThread\n v-for=\"thread in shown\"\n :key=\"thread.id\"\n ref=\"views\"\n :thread=\"thread\"\n :author=\"comments.author.value\"\n :readonly=\"!comments.writable.value\"\n @action=\"comments.apply\"\n @cancel=\"close\"\n />\n </template>\n </div>\n </Transition>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EAqCA,MAAM,QAAQ;EAQd,MAAM,EAAE,aAAa;EACrB,MAAM,QAAQ,WAA+B,IAAI;EACjD,MAAM,4BAAY,IAAI,IAAyB;;EAG/C,MAAM,UAAU,eAAyC;GACvD,IAAI,SAAS,QAAQ,OAAO,OAAO,MAAM,QAAQ,MAAM,MAAM,EAAE,OAAO,KAAK;GAC3E,MAAM,KAAK,SAAS,OAAO;GAC3B,OAAQ,MAAM,MAAM,QAAQ,MAAM,MAAM,EAAE,MAAM,SAAS,EAAE,CAAC,KAAM;EACpE,CAAC;;EAGD,MAAM,QAAQ,eAAgC;GAC5C,MAAM,SAAS,QAAQ;GACvB,IAAI,CAAC,UAAU,SAAS,QAAQ,OAAO,OAAO,CAAC;GAC/C,MAAM,OAAO,IAAI,IAAI,SAAS,QAAQ,MAAM,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;GACjE,OAAO,OAAO,MAAM,SAAS,OAAO,KAAK,IAAI,EAAE,KAAK,CAAC,CAAC;EACxD,CAAC;EAED,MAAM,OAAO,eAAe,CAAC,CAAC,QAAQ,KAAK;EAE3C,MAAM,QAAQ,WAA+B,IAAI;;EAEjD,MAAM,OAAO,eAAe;GAC1B,MAAM,SAAS,QAAQ;GACvB,MAAM,KAAK,MAAM;GACjB,IAAI,CAAC,UAAU,CAAC,IAAI,OAAO;GAC3B,OAAO,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,OAAO,IAAI,GAAG,eAAe,OAAO,IAAI,GAAG;EACpF,CAAC;EAGD,IAAI,YAAgC;EACpC,MAAM,MAAM,OAAO,QAAQ;GACzB,IAAI,KAAK;IACP,MAAM,KAAK,SAAS;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AAGA,MAAA,QAAA,CAAQ,CAAC,SAAS;MAC7B,UAAQA,MAAA,QAAA,CAAQ,CAAC;MACjB,UAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { ContextMenuItem } from 'dou-ui'\nimport type { FlowExportOptions, FlowImageOptions } from './export/draw'\nimport type { FlowTree } from './core/groups'\nimport { inject, type ComputedRef, type InjectionKey, type Ref, type ShallowRef } from 'vue'\nimport type { FlowMessages, FlowMessagesOverride } from './locale'\nimport type {\n FlowData,\n FlowDocument,\n FlowEndpoint,\n FlowNode,\n FlowPortSpec,\n FlowSelection,\n FlowViewport,\n Point,\n PortSide,\n Rect,\n} from './core/model'\nimport type { FlowConnection, PortTypes, PortTypeSpec } from './core/connect'\nimport type { EdgeTypeSpec } from './core/edge-types'\nimport type { FlowExtension } from './core/extension'\nimport type { FlowMenuTarget } from './core/menu'\nimport type { NodeTypeSpec } from './core/node-types'\nimport type { FlowTransaction, FlowTransactionMeta } from './core/transaction'\n\nexport type FlowPanelPlacement = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n\nexport interface FlowControlsProps {\n /** Corner of the editor to sit in. */\n placement?: FlowPanelPlacement\n /** Show undo and redo. */\n history?: boolean\n /** Show the tidy button, which lays the nodes out along their edges. */\n tidy?: boolean\n}\n\nexport interface FlowMinimapProps {\n /** Corner of the editor to sit in. */\n placement?: FlowPanelPlacement\n /** Size of the map in px. */\n width?: number\n height?: number\n}\n\n/** What the find panel looks for: text in the nodes' names. */\nexport interface FlowSearchQuery {\n search: string\n /** Tell capital letters from small ones. */\n caseSensitive?: boolean\n}\n\nexport interface FlowEditorProps {\n /**\n * What the editor is made of: node types, port types, rules, keys and\n * layers. `flowKit()` by default.\n */\n extensions?: (FlowExtension | FlowExtension[])[]\n /** Node types besides the extensions'; they win over an extension's type of the same name. */\n nodeTypes?: NodeTypeSpec<any>[]\n /** Edge types besides the extensions'; they win over an extension's type of the same name. */\n edgeTypes?: EdgeTypeSpec<any>[]\n /** The type of edges without `type`, new ones included. `bezier` by default. */\n edgeType?: string\n /**\n * Below this zoom nodes are drawn as plain boxes with their names, which\n * keeps a large flow quick; see the `simple` slot. `0` never does. `0.4` by default.\n */\n simpleZoom?: number\n /** Grid step for snapping and arrow keys, in px. `0` turns snapping to the grid off. */\n grid?: number\n /** Line nodes up with their neighbours while dragging. */\n guides?: boolean\n minZoom?: number\n maxZoom?: number\n /**\n * Which way the flow runs: `horizontal` left to right, `vertical` top to\n * bottom. Tidying lays nodes out this way.\n */\n direction?: 'horizontal' | 'vertical'\n /** Fit all nodes into view once they are measured. */\n fitView?: boolean\n /**\n * The furthest `fit-view` zooms out, so text stays readable; a larger flow\n * starts at its top left and is panned to. `0` always fits everything.\n */\n fitMinZoom?: number\n /** View, select and pan, but not change anything. */\n readonly?: boolean\n /** The built-in find panel (`Ctrl/⌘+F`). Off, the keys are left to the page. On by default. */\n searchable?: boolean\n /** Scrolling pans the canvas; with Ctrl / ⌘ it zooms. Off, only Ctrl / ⌘ + scroll zooms. */\n panOnScroll?: boolean\n /** Looks and connection rules of port types, by the name used in `dataType`. */\n portTypes?: PortTypes\n /** Refuse edges that would close a cycle. */\n acyclic?: boolean\n /**\n * The last check before an edge is made. Return `false` to refuse it, or a\n * sentence saying why. Called for every port while an edge is dragged.\n */\n canConnect?: (connection: FlowConnection, doc: FlowDocument) => boolean | string\n /**\n * The hairline frame and rounded corners. Off, the canvas takes no\n * border at all, for a panel or page region that already has an edge.\n * On by default.\n */\n bordered?: boolean\n /** Accessible name of the canvas. */\n ariaLabel?: string\n /** Texts to change; only the ones given are replaced. */\n messages?: FlowMessagesOverride\n}\n\nexport interface FlowEditorEmits {\n /** Every change to the document, with its steps; `update:modelValue` follows. */\n transaction: [tr: FlowTransaction]\n /**\n * An extension's `transaction` hook cancelled a change; `tr.cancelReason`\n * says why, and the editor shows it and reads it out.\n */\n transactionCancel: [tr: FlowTransaction]\n nodeClick: [node: FlowNode, event: MouseEvent]\n nodeDblclick: [node: FlowNode, event: MouseEvent]\n nodeContextmenu: [node: FlowNode, event: MouseEvent]\n edgeClick: [edge: FlowDocument['edges'][number], event: MouseEvent]\n edgeContextmenu: [edge: FlowDocument['edges'][number], event: MouseEvent]\n /** Clicking the empty canvas; `point` is in canvas coordinates. */\n canvasClick: [point: Point, event: MouseEvent]\n /**\n * Right click or long press on the empty canvas. The context menu events\n * come before the editor's own menu; `event.preventDefault()` keeps it closed.\n */\n canvasContextmenu: [point: Point, event: MouseEvent]\n /** An edge was drawn, or moved to another port. */\n connect: [edge: FlowDocument['edges'][number]]\n /**\n * A new edge was dropped on empty canvas; `point` is where, in canvas\n * coordinates. The editor then offers the node types that can take the\n * edge; `event.preventDefault()` handles it yourself instead.\n */\n connectToCanvas: [from: Required<FlowEndpoint>, point: Point, event: MouseEvent]\n}\n\nexport interface FlowEditorExpose {\n /** Applies changes as one transaction, one undo step. */\n transact: (fn: (tr: FlowTransaction) => void, meta?: FlowTransactionMeta) => FlowTransaction\n undo: () => boolean\n redo: () => boolean\n readonly canUndo: boolean\n readonly canRedo: boolean\n /** Shows all nodes, or the given ones. */\n fit: (ids?: string[]) => void\n zoomTo: (zoom: number) => void\n zoomIn: () => void\n zoomOut: () => void\n /** Centers a node in view without changing the zoom. */\n centerNode: (id: string) => void\n /** Opens the find panel (`Ctrl/⌘+F`), with a query put in; `false` when `searchable` is off. */\n openSearch: (query?: Partial<FlowSearchQuery>) => boolean\n /** Closes the find panel; `false` when it was not open. */\n closeSearch: () => boolean\n /** The ids of the nodes whose names contain the search, in reading order. */\n findNodes: (query: FlowSearchQuery) => string[]\n /**\n * Moves the view like the user's pans do: no further than having the nodes\n * just leave it. `v-model:viewport` goes anywhere.\n */\n setViewport: (viewport: FlowViewport, animate?: boolean) => void\n /** Converts a point on screen (client coordinates) to canvas coordinates. */\n toCanvas: (point: Point) => Point\n /** A node's measured box in canvas coordinates. */\n getNodeRect: (id: string) => Rect | null\n /**\n * The flow as an SVG document, as it looks now: every node and edge, what\n * is in view, or the selected ones (it throws when nothing is selected). Colors are written as `rgb(…)`, `rgba(…)` or `#rrggbb`, so\n * vector editors read them; nodes are drawn by their type's `draw`.\n */\n exportSVG: (options?: FlowExportOptions) => string\n /** The flow as a PNG image, with images embedded where their address can be read. */\n exportPNG: (options?: FlowImageOptions) => Promise<Blob>\n /**\n * Lays nodes out in columns along their edges, as one undo step: the given\n * ones, the selection when two or more nodes are selected, or all.\n */\n tidy: (ids?: string[]) => void\n /**\n * Ids of edges whose ports no longer fit: a port is gone, or the types of\n * its two ends don't match any more. They are drawn red and dashed.\n */\n readonly staleEdges: string[]\n /** Removes the stale edges as one undo step; returns how many. */\n removeStaleEdges: () => number\n /**\n * Adds a node of a type with its defaults and selects it, as one undo\n * step; returns its id. See `FlowInsertOptions` for where it goes.\n */\n insertNode: (type: string, options?: FlowInsertOptions) => string | null\n /**\n * Starts dragging a new node of a type from `event`, a `pointerdown` on\n * any element on the page; letting go over the canvas adds it there, and\n * Escape cancels. The click that ends a drag is stopped. Returns `false`\n * when nothing was started.\n */\n startInsertDrag: (type: string, event: PointerEvent) => boolean\n /** Node types with a `palette` entry, in the order they were given. */\n readonly paletteTypes: NodeTypeSpec[]\n /** Selects an edge and opens the text field on its label. */\n editLabel: (id: string) => void\n /**\n * Puts nodes, the selected ones by default, into a new container of\n * `type` (`'group'` by default) drawn around them, as one undo step;\n * returns its id, or `null` when nothing was grouped.\n */\n groupNodes: (ids?: string[], type?: string) => string | null\n /** Removes a container and keeps the nodes inside, as one undo step. */\n ungroupNode: (id: string) => boolean\n /**\n * Takes nodes, the selected ones by default, out of their groups and puts\n * them just below, as one undo step; returns how many moved.\n */\n leaveGroup: (ids?: string[]) => number\n}\n\nexport interface FlowEditorSlots {\n /** Panels over the canvas, e.g. `DouFlowControls`. */\n default?: () => unknown\n /** What follows the pointer while a new node is dragged in. */\n ghost?: (props: { spec: NodeTypeSpec; over: boolean }) => unknown\n /** Replaces the list offered when an edge is dropped on the empty canvas. */\n quickAdd?: (props: {\n types: NodeTypeSpec[]\n choose: (type: string) => void\n close: () => void\n }) => unknown\n /** A node's content while zoomed out past `simple-zoom`; its name by default. */\n simple?: (props: { node: FlowNode }) => unknown\n}\n\nexport interface FlowInsertOptions {\n /**\n * Where the node goes, in canvas coordinates: its centre, or with `from`,\n * the port that takes the edge. Without it the node goes after the one\n * selected node, connected to it when it can be, or else in the middle\n * of the view; either way clear of other nodes.\n */\n at?: Point\n /** Connect the new node to this port, through the first port that can take it. */\n from?: Required<FlowEndpoint>\n /** Move focus to the new node, so keys such as undo act on it. `true` by default. */\n focus?: boolean\n /** Merged over the type's `defaults()`. */\n data?: FlowData\n /** The node's size instead of the type's `size`. */\n size?: { width?: number; height?: number }\n}\n\n/** Where a port's centre is, from its node's top left corner. */\nexport interface PortAnchor extends Point {\n side: PortSide\n}\n\nexport interface NodeMetrics {\n width: number\n height: number\n ports: Map<string, PortAnchor>\n}\n\n/** What `previewNode` can show changed: the box, and the data. */\nexport type FlowNodePreview = Partial<Pick<FlowNode, 'x' | 'y' | 'width' | 'height' | 'data'>>\n\n/** How a port shows while an edge is being drawn. */\nexport type PortState = 'active' | 'valid' | 'candidate' | 'refused'\n\nexport interface FlowEditorContext {\n doc: Ref<FlowDocument>\n selection: Ref<FlowSelection>\n viewport: Ref<FlowViewport>\n /** See `FlowEditorExpose.setViewport`; writing `viewport` goes anywhere. */\n setViewport: FlowEditorExpose['setViewport']\n readonly: ComputedRef<boolean>\n messages: ComputedRef<FlowMessages>\n minZoom: ComputedRef<number>\n maxZoom: ComputedRef<number>\n transact: FlowEditorExpose['transact']\n undo: () => boolean\n redo: () => boolean\n canUndo: Ref<boolean>\n canRedo: Ref<boolean>\n fit: FlowEditorExpose['fit']\n zoomTo: FlowEditorExpose['zoomTo']\n zoomIn: () => void\n zoomOut: () => void\n /** The registered type of a port, if any. */\n portTypeOf: (port: FlowPortSpec) => PortTypeSpec | undefined\n /** A port type's color as CSS. */\n colorOf: (spec: PortTypeSpec | undefined) => string | undefined\n getNodeRect: FlowEditorExpose['getNodeRect']\n exportSVG: FlowEditorExpose['exportSVG']\n exportPNG: FlowEditorExpose['exportPNG']\n tidy: FlowEditorExpose['tidy']\n centerNode: FlowEditorExpose['centerNode']\n /** Says `text` to screen readers. */\n announce: (text: string) => void\n /** The editor's size on screen, in px. */\n size: Ref<{ width: number; height: number }>\n selectedNodes: ComputedRef<Set<string>>\n insertNode: FlowEditorExpose['insertNode']\n /** Node types with a `palette` entry, in the order they were given. */\n paletteTypes: ComputedRef<NodeTypeSpec[]>\n startInsertDrag: FlowEditorExpose['startInsertDrag']\n editLabel: FlowEditorExpose['editLabel']\n groupNodes: FlowEditorExpose['groupNodes']\n ungroupNode: FlowEditorExpose['ungroupNode']\n leaveGroup: FlowEditorExpose['leaveGroup']\n /** Which node is inside which, from the nodes' `parent`. */\n tree: ComputedRef<FlowTree>\n /** Whether the node's type can hold other nodes. */\n isContainer: (node: FlowNode) => boolean\n /** How far the node is drawn turned about its centre, from its type's `rotation`. */\n nodeRotation: (id: string) => number\n /**\n * While nodes are moved or resized, or an edge is bent: the document\n * changes on every frame until the pointer is let go.\n */\n gesturing: ComputedRef<boolean>\n /**\n * Shows a node as if `patch` were applied, without changing the document:\n * its frame, ports, edges and `getNodeRect` all follow. For handles that\n * change the document once, when let go; `null` shows it as it is again,\n * and must be passed when the drag ends or is cancelled. `patch.data`\n * replaces the node's data, it is not merged. Only this editor shows it:\n * peers see the change once it is committed. A preview is dropped when\n * its node leaves the document.\n */\n previewNode: (id: string, patch: FlowNodePreview | null) => void\n /** The edge being drawn, as an SVG path in canvas coordinates. */\n connectingPath: ComputedRef<string | null>\n /** The editor's element. */\n root: Readonly<ShallowRef<HTMLElement | null>>\n /**\n * Opens the context menu for a target at a point on screen; `false` when\n * no extension has items for it. Pass the button that opens it as `from`:\n * the menu then opens below the button instead of at the point, or above\n * it when there is no room, and pressing the button again closes it.\n */\n openMenu: (target: FlowMenuTarget, client: Point, from?: Element) => boolean\n /** The items the context menu has for a target, as `openMenu` shows them. */\n menuItems: (target: FlowMenuTarget) => ContextMenuItem[]\n /**\n * Opens the editor's menu with these items, e.g. the choices behind a\n * toolbar button; `from` works as in `openMenu`.\n */\n showMenu: (\n items: ContextMenuItem[],\n client: Point,\n from?: Element,\n options?: { focusChecked?: boolean },\n ) => boolean\n /** The element that opened the menu, while it is open, e.g. to mark a button expanded. */\n menuFrom: Readonly<ShallowRef<Element | null>>\n toCanvas: (point: Point) => Point\n /** Copies the selected nodes to the clipboard; `false` when none are selected. */\n copy: () => boolean\n cut: () => boolean\n /** Pastes what was copied, at `at` (canvas coordinates) or next to the original. */\n paste: (at?: Point) => Promise<boolean>\n /** Adds a copy of the selected nodes next to them. */\n duplicate: () => void\n /** Deletes the selected nodes and edges, except locked nodes. */\n deleteSelection: () => void\n selectAll: () => void\n}\n\nexport const flowEditorKey: InjectionKey<FlowEditorContext> = Symbol('dou-flow-editor')\n\n/** The surrounding flow editor; for controls and panels placed in its default slot. */\nexport function useFlowEditor() {\n const context = inject(flowEditorKey, null)\n if (!context)\n throw new Error('[@dou-ui/flow] useFlowEditor() must be called inside <DouFlowEditor>')\n return context\n}\n\nexport interface FlowNodeContext {\n node: ComputedRef<FlowNode>\n ports: ComputedRef<FlowPortSpec[]>\n /** Port ids with at least one edge. */\n connected: ComputedRef<Set<string>>\n /** While an edge is being drawn, how each port shows; `null` otherwise. */\n portStates: ComputedRef<Map<string, PortState> | null>\n registerPort: (id: string, el: HTMLElement, auto?: boolean) => void\n unregisterPort: (id: string, auto?: boolean) => void\n}\n\nexport const flowNodeKey: InjectionKey<FlowNodeContext> = Symbol('dou-flow-node')\n"],"mappings":";;AAoXA,IAAa,gBAAiD,OAAO,iBAAiB;;AAGtF,SAAgB,gBAAgB;CAC9B,MAAM,UAAU,OAAO,eAAe,IAAI;CAC1C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sEAAsE;CACxF,OAAO;AACT;AAaA,IAAa,cAA6C,OAAO,eAAe"}
1
+ {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { CommentAction, CommentAuthor, CommentThread, ContextMenuItem } from 'dou-ui'\nimport type { FlowExportOptions, FlowImageOptions } from './export/draw'\nimport type { FlowTree } from './core/groups'\nimport { inject, type ComputedRef, type InjectionKey, type Ref, type ShallowRef } from 'vue'\nimport type { FlowMessages, FlowMessagesOverride } from './locale'\nimport type {\n FlowData,\n FlowDocument,\n FlowEndpoint,\n FlowNode,\n FlowPortSpec,\n FlowSelection,\n FlowViewport,\n Point,\n PortSide,\n Rect,\n} from './core/model'\nimport type { FlowConnection, PortTypes, PortTypeSpec } from './core/connect'\nimport type { EdgeTypeSpec } from './core/edge-types'\nimport type { FlowExtension } from './core/extension'\nimport type { FlowMenuTarget } from './core/menu'\nimport type { NodeTypeSpec } from './core/node-types'\nimport type { FlowTransaction, FlowTransactionMeta } from './core/transaction'\n\nexport type FlowPanelPlacement = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n\nexport interface FlowControlsProps {\n /** Corner of the editor to sit in. */\n placement?: FlowPanelPlacement\n /** Show undo and redo. */\n history?: boolean\n /** Show the tidy button, which lays the nodes out along their edges. */\n tidy?: boolean\n}\n\nexport interface FlowMinimapProps {\n /** Corner of the editor to sit in. */\n placement?: FlowPanelPlacement\n /** Size of the map in px. */\n width?: number\n height?: number\n}\n\n/** What the find panel looks for: text in the nodes' names. */\nexport interface FlowSearchQuery {\n search: string\n /** Tell capital letters from small ones. */\n caseSensitive?: boolean\n}\n\nexport interface FlowEditorProps {\n /**\n * What the editor is made of: node types, port types, rules, keys and\n * layers. `flowKit()` by default.\n */\n extensions?: (FlowExtension | FlowExtension[])[]\n /** Node types besides the extensions'; they win over an extension's type of the same name. */\n nodeTypes?: NodeTypeSpec<any>[]\n /** Edge types besides the extensions'; they win over an extension's type of the same name. */\n edgeTypes?: EdgeTypeSpec<any>[]\n /** The type of edges without `type`, new ones included. `bezier` by default. */\n edgeType?: string\n /**\n * Below this zoom nodes are drawn as plain boxes with their names, which\n * keeps a large flow quick; see the `simple` slot. `0` never does. `0.4` by default.\n */\n simpleZoom?: number\n /** Grid step for snapping and arrow keys, in px. `0` turns snapping to the grid off. */\n grid?: number\n /** Line nodes up with their neighbours while dragging. */\n guides?: boolean\n minZoom?: number\n maxZoom?: number\n /**\n * Which way the flow runs: `horizontal` left to right, `vertical` top to\n * bottom. Tidying lays nodes out this way.\n */\n direction?: 'horizontal' | 'vertical'\n /** Fit all nodes into view once they are measured. */\n fitView?: boolean\n /**\n * The furthest `fit-view` zooms out, so text stays readable; a larger flow\n * starts at its top left and is panned to. `0` always fits everything.\n */\n fitMinZoom?: number\n /** View, select and pan, but not change anything. */\n readonly?: boolean\n /** The built-in find panel (`Ctrl/⌘+F`). Off, the keys are left to the page. On by default. */\n searchable?: boolean\n /** Scrolling pans the canvas; with Ctrl / ⌘ it zooms. Off, only Ctrl / ⌘ + scroll zooms. */\n panOnScroll?: boolean\n /** Looks and connection rules of port types, by the name used in `dataType`. */\n portTypes?: PortTypes\n /** Refuse edges that would close a cycle. */\n acyclic?: boolean\n /**\n * The last check before an edge is made. Return `false` to refuse it, or a\n * sentence saying why. Called for every port while an edge is dragged.\n */\n canConnect?: (connection: FlowConnection, doc: FlowDocument) => boolean | string\n /**\n * The hairline frame and rounded corners. Off, the canvas takes no\n * border at all, for a panel or page region that already has an edge.\n * On by default.\n */\n bordered?: boolean\n /** Accessible name of the canvas. */\n ariaLabel?: string\n /** Texts to change; only the ones given are replaced. */\n messages?: FlowMessagesOverride\n /**\n * The comment threads, bound with `v-model:comments`. The node or edge a\n * thread is about keeps the thread's id in its `comments`. Left out,\n * there are no comments.\n */\n comments?: CommentThread[]\n /** Who is commenting. Without it comments can be read but not written. */\n author?: CommentAuthor\n /** The thread open now, bound with `v-model:activeComment`. */\n activeComment?: string | null\n /** Threads can be started and replied to; also while `readonly`. On by default. */\n commentable?: boolean\n}\n\n/** What a comment thread is about: a node or an edge. */\nexport type FlowCommentAnchor = { node: string } | { edge: string }\n\nexport interface FlowEditorEmits {\n /** Every change to the document, with its steps; `update:modelValue` follows. */\n transaction: [tr: FlowTransaction]\n /**\n * An extension's `transaction` hook cancelled a change; `tr.cancelReason`\n * says why, and the editor shows it and reads it out.\n */\n transactionCancel: [tr: FlowTransaction]\n 'update:comments': [threads: CommentThread[]]\n 'update:activeComment': [id: string | null]\n /** A change to the comments made here: to send to a server, notify people, keep a log. */\n commentAction: [action: CommentAction]\n nodeClick: [node: FlowNode, event: MouseEvent]\n nodeDblclick: [node: FlowNode, event: MouseEvent]\n nodeContextmenu: [node: FlowNode, event: MouseEvent]\n edgeClick: [edge: FlowDocument['edges'][number], event: MouseEvent]\n edgeContextmenu: [edge: FlowDocument['edges'][number], event: MouseEvent]\n /** Clicking the empty canvas; `point` is in canvas coordinates. */\n canvasClick: [point: Point, event: MouseEvent]\n /**\n * Right click or long press on the empty canvas. The context menu events\n * come before the editor's own menu; `event.preventDefault()` keeps it closed.\n */\n canvasContextmenu: [point: Point, event: MouseEvent]\n /** An edge was drawn, or moved to another port. */\n connect: [edge: FlowDocument['edges'][number]]\n /**\n * A new edge was dropped on empty canvas; `point` is where, in canvas\n * coordinates. The editor then offers the node types that can take the\n * edge; `event.preventDefault()` handles it yourself instead.\n */\n connectToCanvas: [from: Required<FlowEndpoint>, point: Point, event: MouseEvent]\n}\n\nexport interface FlowEditorExpose {\n /** Applies changes as one transaction, one undo step. */\n transact: (fn: (tr: FlowTransaction) => void, meta?: FlowTransactionMeta) => FlowTransaction\n undo: () => boolean\n redo: () => boolean\n readonly canUndo: boolean\n readonly canRedo: boolean\n /** Shows all nodes, or the given ones. */\n fit: (ids?: string[]) => void\n zoomTo: (zoom: number) => void\n zoomIn: () => void\n zoomOut: () => void\n /** Centers a node in view without changing the zoom. */\n centerNode: (id: string) => void\n /** Opens the find panel (`Ctrl/⌘+F`), with a query put in; `false` when `searchable` is off. */\n openSearch: (query?: Partial<FlowSearchQuery>) => boolean\n /** Closes the find panel; `false` when it was not open. */\n closeSearch: () => boolean\n /** The ids of the nodes whose names contain the search, in reading order. */\n findNodes: (query: FlowSearchQuery) => string[]\n /**\n * Moves the view like the user's pans do: no further than having the nodes\n * just leave it. `v-model:viewport` goes anywhere.\n */\n setViewport: (viewport: FlowViewport, animate?: boolean) => void\n /** Converts a point on screen (client coordinates) to canvas coordinates. */\n toCanvas: (point: Point) => Point\n /** A node's measured box in canvas coordinates. */\n getNodeRect: (id: string) => Rect | null\n /**\n * The flow as an SVG document, as it looks now: every node and edge, what\n * is in view, or the selected ones (it throws when nothing is selected). Colors are written as `rgb(…)`, `rgba(…)` or `#rrggbb`, so\n * vector editors read them; nodes are drawn by their type's `draw`.\n */\n exportSVG: (options?: FlowExportOptions) => string\n /** The flow as a PNG image, with images embedded where their address can be read. */\n exportPNG: (options?: FlowImageOptions) => Promise<Blob>\n /**\n * Lays nodes out in columns along their edges, as one undo step: the given\n * ones, the selection when two or more nodes are selected, or all.\n */\n tidy: (ids?: string[]) => void\n /**\n * Ids of edges whose ports no longer fit: a port is gone, or the types of\n * its two ends don't match any more. They are drawn red and dashed.\n */\n readonly staleEdges: string[]\n /** Removes the stale edges as one undo step; returns how many. */\n removeStaleEdges: () => number\n /**\n * Opens the open thread on a node or edge (the selected one when left\n * out), ready to reply, or starts one there; `false` when there is no such\n * node or edge, or nothing to open and comments can't be written.\n */\n comment: (anchor?: FlowCommentAnchor) => boolean\n /** What each thread is about; `null` when its node or edge is gone. Not reactive. */\n getCommentAnchors: () => Record<string, FlowCommentAnchor | null>\n /**\n * Adds a node of a type with its defaults and selects it, as one undo\n * step; returns its id. See `FlowInsertOptions` for where it goes.\n */\n insertNode: (type: string, options?: FlowInsertOptions) => string | null\n /**\n * Starts dragging a new node of a type from `event`, a `pointerdown` on\n * any element on the page; letting go over the canvas adds it there, and\n * Escape cancels. The click that ends a drag is stopped. Returns `false`\n * when nothing was started.\n */\n startInsertDrag: (type: string, event: PointerEvent) => boolean\n /** Node types with a `palette` entry, in the order they were given. */\n readonly paletteTypes: NodeTypeSpec[]\n /** Selects an edge and opens the text field on its label. */\n editLabel: (id: string) => void\n /**\n * Puts nodes, the selected ones by default, into a new container of\n * `type` (`'group'` by default) drawn around them, as one undo step;\n * returns its id, or `null` when nothing was grouped.\n */\n groupNodes: (ids?: string[], type?: string) => string | null\n /** Removes a container and keeps the nodes inside, as one undo step. */\n ungroupNode: (id: string) => boolean\n /**\n * Takes nodes, the selected ones by default, out of their groups and puts\n * them just below, as one undo step; returns how many moved.\n */\n leaveGroup: (ids?: string[]) => number\n}\n\nexport interface FlowEditorSlots {\n /** Panels over the canvas, e.g. `DouFlowControls`. */\n default?: () => unknown\n /** What follows the pointer while a new node is dragged in. */\n ghost?: (props: { spec: NodeTypeSpec; over: boolean }) => unknown\n /** Replaces the list offered when an edge is dropped on the empty canvas. */\n quickAdd?: (props: {\n types: NodeTypeSpec[]\n choose: (type: string) => void\n close: () => void\n }) => unknown\n /** A node's content while zoomed out past `simple-zoom`; its name by default. */\n simple?: (props: { node: FlowNode }) => unknown\n}\n\nexport interface FlowInsertOptions {\n /**\n * Where the node goes, in canvas coordinates: its centre, or with `from`,\n * the port that takes the edge. Without it the node goes after the one\n * selected node, connected to it when it can be, or else in the middle\n * of the view; either way clear of other nodes.\n */\n at?: Point\n /** Connect the new node to this port, through the first port that can take it. */\n from?: Required<FlowEndpoint>\n /** Move focus to the new node, so keys such as undo act on it. `true` by default. */\n focus?: boolean\n /** Merged over the type's `defaults()`. */\n data?: FlowData\n /** The node's size instead of the type's `size`. */\n size?: { width?: number; height?: number }\n}\n\n/** Where a port's centre is, from its node's top left corner. */\nexport interface PortAnchor extends Point {\n side: PortSide\n}\n\nexport interface NodeMetrics {\n width: number\n height: number\n ports: Map<string, PortAnchor>\n}\n\n/** What `previewNode` can show changed: the box, and the data. */\nexport type FlowNodePreview = Partial<Pick<FlowNode, 'x' | 'y' | 'width' | 'height' | 'data'>>\n\n/** How a port shows while an edge is being drawn. */\nexport type PortState = 'active' | 'valid' | 'candidate' | 'refused'\n\nexport interface FlowEditorContext {\n doc: Ref<FlowDocument>\n selection: Ref<FlowSelection>\n viewport: Ref<FlowViewport>\n /** See `FlowEditorExpose.setViewport`; writing `viewport` goes anywhere. */\n setViewport: FlowEditorExpose['setViewport']\n readonly: ComputedRef<boolean>\n messages: ComputedRef<FlowMessages>\n minZoom: ComputedRef<number>\n maxZoom: ComputedRef<number>\n transact: FlowEditorExpose['transact']\n undo: () => boolean\n redo: () => boolean\n canUndo: Ref<boolean>\n canRedo: Ref<boolean>\n fit: FlowEditorExpose['fit']\n zoomTo: FlowEditorExpose['zoomTo']\n zoomIn: () => void\n zoomOut: () => void\n /** The registered type of a port, if any. */\n portTypeOf: (port: FlowPortSpec) => PortTypeSpec | undefined\n /** A port type's color as CSS. */\n colorOf: (spec: PortTypeSpec | undefined) => string | undefined\n getNodeRect: FlowEditorExpose['getNodeRect']\n exportSVG: FlowEditorExpose['exportSVG']\n exportPNG: FlowEditorExpose['exportPNG']\n tidy: FlowEditorExpose['tidy']\n centerNode: FlowEditorExpose['centerNode']\n /** Says `text` to screen readers. */\n announce: (text: string) => void\n /** The editor's size on screen, in px. */\n size: Ref<{ width: number; height: number }>\n selectedNodes: ComputedRef<Set<string>>\n insertNode: FlowEditorExpose['insertNode']\n /** Node types with a `palette` entry, in the order they were given. */\n paletteTypes: ComputedRef<NodeTypeSpec[]>\n startInsertDrag: FlowEditorExpose['startInsertDrag']\n editLabel: FlowEditorExpose['editLabel']\n groupNodes: FlowEditorExpose['groupNodes']\n ungroupNode: FlowEditorExpose['ungroupNode']\n leaveGroup: FlowEditorExpose['leaveGroup']\n /** Which node is inside which, from the nodes' `parent`. */\n tree: ComputedRef<FlowTree>\n /** Whether the node's type can hold other nodes. */\n isContainer: (node: FlowNode) => boolean\n /** How far the node is drawn turned about its centre, from its type's `rotation`. */\n nodeRotation: (id: string) => number\n /**\n * While nodes are moved or resized, or an edge is bent: the document\n * changes on every frame until the pointer is let go.\n */\n gesturing: ComputedRef<boolean>\n /**\n * Shows a node as if `patch` were applied, without changing the document:\n * its frame, ports, edges and `getNodeRect` all follow. For handles that\n * change the document once, when let go; `null` shows it as it is again,\n * and must be passed when the drag ends or is cancelled. `patch.data`\n * replaces the node's data, it is not merged. Only this editor shows it:\n * peers see the change once it is committed. A preview is dropped when\n * its node leaves the document.\n */\n previewNode: (id: string, patch: FlowNodePreview | null) => void\n /** The edge being drawn, as an SVG path in canvas coordinates. */\n connectingPath: ComputedRef<string | null>\n /** The editor's element. */\n root: Readonly<ShallowRef<HTMLElement | null>>\n /**\n * Opens the context menu for a target at a point on screen; `false` when\n * no extension has items for it. Pass the button that opens it as `from`:\n * the menu then opens below the button instead of at the point, or above\n * it when there is no room, and pressing the button again closes it.\n */\n openMenu: (target: FlowMenuTarget, client: Point, from?: Element) => boolean\n /** The items the context menu has for a target, as `openMenu` shows them. */\n menuItems: (target: FlowMenuTarget) => ContextMenuItem[]\n /**\n * Opens the editor's menu with these items, e.g. the choices behind a\n * toolbar button; `from` works as in `openMenu`.\n */\n showMenu: (\n items: ContextMenuItem[],\n client: Point,\n from?: Element,\n options?: { focusChecked?: boolean },\n ) => boolean\n /** The element that opened the menu, while it is open, e.g. to mark a button expanded. */\n menuFrom: Readonly<ShallowRef<Element | null>>\n toCanvas: (point: Point) => Point\n /** Copies the selected nodes to the clipboard; `false` when none are selected. */\n copy: () => boolean\n cut: () => boolean\n /** Pastes what was copied, at `at` (canvas coordinates) or next to the original. */\n paste: (at?: Point) => Promise<boolean>\n /** Adds a copy of the selected nodes next to them. */\n duplicate: () => void\n /** Deletes the selected nodes and edges, except locked nodes. */\n deleteSelection: () => void\n selectAll: () => void\n}\n\nexport const flowEditorKey: InjectionKey<FlowEditorContext> = Symbol('dou-flow-editor')\n\n/** The surrounding flow editor; for controls and panels placed in its default slot. */\nexport function useFlowEditor() {\n const context = inject(flowEditorKey, null)\n if (!context)\n throw new Error('[@dou-ui/flow] useFlowEditor() must be called inside <DouFlowEditor>')\n return context\n}\n\nexport interface FlowNodeContext {\n node: ComputedRef<FlowNode>\n ports: ComputedRef<FlowPortSpec[]>\n /** Port ids with at least one edge. */\n connected: ComputedRef<Set<string>>\n /** While an edge is being drawn, how each port shows; `null` otherwise. */\n portStates: ComputedRef<Map<string, PortState> | null>\n registerPort: (id: string, el: HTMLElement, auto?: boolean) => void\n unregisterPort: (id: string, auto?: boolean) => void\n}\n\nexport const flowNodeKey: InjectionKey<FlowNodeContext> = Symbol('dou-flow-node')\n"],"mappings":";;AA+YA,IAAa,gBAAiD,OAAO,iBAAiB;;AAGtF,SAAgB,gBAAgB;CAC9B,MAAM,UAAU,OAAO,eAAe,IAAI;CAC1C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sEAAsE;CACxF,OAAO;AACT;AAaA,IAAa,cAA6C,OAAO,eAAe"}
@@ -69,6 +69,32 @@ var FlowHistory = class {
69
69
  selection: entry.selectionAfter
70
70
  };
71
71
  }
72
+ /**
73
+ * Gives a change kept out of undo to a node or edge as undo and redo
74
+ * bring it back, too: comments started on a new node stay on it when its
75
+ * adding is undone and redone.
76
+ */
77
+ carry(target, patch) {
78
+ const merge = (item) => {
79
+ const next = {
80
+ ...item,
81
+ ...patch
82
+ };
83
+ for (const [key, value] of Object.entries(patch)) if (value === void 0) delete next[key];
84
+ return next;
85
+ };
86
+ const fix = (steps) => steps.map((step) => "node" in target && step.type === "addNode" && step.node.id === target.node ? {
87
+ ...step,
88
+ node: merge(step.node)
89
+ } : "edge" in target && step.type === "addEdge" && step.edge.id === target.edge ? {
90
+ ...step,
91
+ edge: merge(step.edge)
92
+ } : step);
93
+ for (const entry of [...this.done, ...this.undone]) {
94
+ entry.steps = fix(entry.steps);
95
+ entry.inverse = fix(entry.inverse);
96
+ }
97
+ }
72
98
  clear() {
73
99
  this.done = [];
74
100
  this.undone = [];
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","names":[],"sources":["../../src/core/history.ts"],"sourcesContent":["import type { FlowDocument, FlowSelection } from './model'\nimport {\n applyFlowSteps,\n compactFlowSteps,\n type FlowStep,\n type FlowTransaction,\n} from './transaction'\n\ninterface Entry {\n steps: FlowStep[]\n inverse: FlowStep[]\n group?: string\n time: number\n selectionBefore: FlowSelection\n selectionAfter: FlowSelection\n}\n\n/** Transactions in one group merge when they come within this many ms. */\nconst GROUP_WINDOW = 1000\n\nexport class FlowHistory {\n private done: Entry[] = []\n private undone: Entry[] = []\n\n constructor(private depth = 100) {}\n\n get canUndo() {\n return this.done.length > 0\n }\n\n get canRedo() {\n return this.undone.length > 0\n }\n\n record(\n tr: FlowTransaction,\n selectionBefore: FlowSelection,\n selectionAfter: FlowSelection,\n now = Date.now(),\n ) {\n if (!tr.changed || tr.meta.history === false) return\n this.undone = []\n const last = this.done[this.done.length - 1]\n const group = tr.meta.group\n if (last && group && last.group === group && now - last.time < GROUP_WINDOW) {\n last.steps = compactFlowSteps([...last.steps, ...tr.steps])\n last.inverse = compactFlowSteps([...tr.inverse, ...last.inverse])\n last.time = now\n last.selectionAfter = selectionAfter\n return\n }\n this.done.push({\n steps: tr.steps.slice(),\n inverse: tr.inverse.slice(),\n group,\n time: now,\n selectionBefore,\n selectionAfter,\n })\n if (this.done.length > this.depth) this.done.shift()\n }\n\n /** Ends the current group, so the next change starts a new undo step. */\n close() {\n const last = this.done[this.done.length - 1]\n if (last) last.group = undefined\n }\n\n /** Forgets the last entry if it belongs to `group`, e.g. after a cancelled drag. */\n drop(group: string) {\n const last = this.done[this.done.length - 1]\n if (last?.group === group) this.done.pop()\n }\n\n undo(doc: FlowDocument) {\n const entry = this.done.pop()\n if (!entry) return null\n const tr = applyFlowSteps(doc, entry.inverse)\n this.undone.push(entry)\n return { tr, selection: entry.selectionBefore }\n }\n\n redo(doc: FlowDocument) {\n const entry = this.undone.pop()\n if (!entry) return null\n const tr = applyFlowSteps(doc, entry.steps)\n this.done.push({ ...entry, group: undefined })\n return { tr, selection: entry.selectionAfter }\n }\n\n clear() {\n this.done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I,CAAC,OAAO,OAAO;EACnB,MAAM,KAAK,eAAe,KAAK,MAAM,OAAO;EAC5C,KAAK,OAAO,KAAK,KAAK;EACtB,OAAO;GAAE;GAAI,WAAW,MAAM;EAAgB;CAChD;CAEA,KAAK,KAAmB;EACtB,MAAM,QAAQ,KAAK,OAAO,IAAI;EAC9B,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,KAAK,eAAe,KAAK,MAAM,KAAK;EAC1C,KAAK,KAAK,KAAK;GAAE,GAAG;GAAO,OAAO,KAAA;EAAU,CAAC;EAC7C,OAAO;GAAE;GAAI,WAAW,MAAM;EAAe;CAC/C;CAEA,QAAQ;EACN,KAAK,OAAO,CAAC;EACb,KAAK,SAAS,CAAC;CACjB;AACF"}
1
+ {"version":3,"file":"history.js","names":[],"sources":["../../src/core/history.ts"],"sourcesContent":["import type { FlowDocument, FlowSelection } from './model'\nimport {\n applyFlowSteps,\n compactFlowSteps,\n type FlowStep,\n type FlowTransaction,\n} from './transaction'\n\ninterface Entry {\n steps: FlowStep[]\n inverse: FlowStep[]\n group?: string\n time: number\n selectionBefore: FlowSelection\n selectionAfter: FlowSelection\n}\n\n/** Transactions in one group merge when they come within this many ms. */\nconst GROUP_WINDOW = 1000\n\nexport class FlowHistory {\n private done: Entry[] = []\n private undone: Entry[] = []\n\n constructor(private depth = 100) {}\n\n get canUndo() {\n return this.done.length > 0\n }\n\n get canRedo() {\n return this.undone.length > 0\n }\n\n record(\n tr: FlowTransaction,\n selectionBefore: FlowSelection,\n selectionAfter: FlowSelection,\n now = Date.now(),\n ) {\n if (!tr.changed || tr.meta.history === false) return\n this.undone = []\n const last = this.done[this.done.length - 1]\n const group = tr.meta.group\n if (last && group && last.group === group && now - last.time < GROUP_WINDOW) {\n last.steps = compactFlowSteps([...last.steps, ...tr.steps])\n last.inverse = compactFlowSteps([...tr.inverse, ...last.inverse])\n last.time = now\n last.selectionAfter = selectionAfter\n return\n }\n this.done.push({\n steps: tr.steps.slice(),\n inverse: tr.inverse.slice(),\n group,\n time: now,\n selectionBefore,\n selectionAfter,\n })\n if (this.done.length > this.depth) this.done.shift()\n }\n\n /** Ends the current group, so the next change starts a new undo step. */\n close() {\n const last = this.done[this.done.length - 1]\n if (last) last.group = undefined\n }\n\n /** Forgets the last entry if it belongs to `group`, e.g. after a cancelled drag. */\n drop(group: string) {\n const last = this.done[this.done.length - 1]\n if (last?.group === group) this.done.pop()\n }\n\n undo(doc: FlowDocument) {\n const entry = this.done.pop()\n if (!entry) return null\n const tr = applyFlowSteps(doc, entry.inverse)\n this.undone.push(entry)\n return { tr, selection: entry.selectionBefore }\n }\n\n redo(doc: FlowDocument) {\n const entry = this.undone.pop()\n if (!entry) return null\n const tr = applyFlowSteps(doc, entry.steps)\n this.done.push({ ...entry, group: undefined })\n return { tr, selection: entry.selectionAfter }\n }\n\n /**\n * Gives a change kept out of undo to a node or edge as undo and redo\n * bring it back, too: comments started on a new node stay on it when its\n * adding is undone and redone.\n */\n carry(target: { node: string } | { edge: string }, patch: Record<string, unknown>) {\n const merge = <T extends object>(item: T): T => {\n const next: Record<string, unknown> = { ...item, ...patch }\n for (const [key, value] of Object.entries(patch)) if (value === undefined) delete next[key]\n return next as T\n }\n const fix = (steps: FlowStep[]) =>\n steps.map((step) =>\n 'node' in target && step.type === 'addNode' && step.node.id === target.node\n ? { ...step, node: merge(step.node) }\n : 'edge' in target && step.type === 'addEdge' && step.edge.id === target.edge\n ? { ...step, edge: merge(step.edge) }\n : step,\n )\n for (const entry of [...this.done, ...this.undone]) {\n entry.steps = fix(entry.steps)\n entry.inverse = fix(entry.inverse)\n }\n }\n\n clear() {\n this.done = []\n this.undone = []\n }\n}\n"],"mappings":";;;AAkBA,IAAM,eAAe;AAErB,IAAa,cAAb,MAAyB;CAIH;CAHpB,OAAwB,CAAC;CACzB,SAA0B,CAAC;CAE3B,YAAY,QAAgB,KAAK;EAAb,KAAA,QAAA;CAAc;CAElC,IAAI,UAAU;EACZ,OAAO,KAAK,KAAK,SAAS;C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,OAAO;EACnB,MAAM,KAAK,eAAe,KAAK,MAAM,KAAK;EAC1C,KAAK,KAAK,KAAK;GAAE,GAAG;GAAO,OAAO,KAAA;EAAU,CAAC;EAC7C,OAAO;GAAE;GAAI,WAAW,MAAM;EAAe;CAC/C;;;;;;CAOA,MAAM,QAA6C,OAAgC;EACjF,MAAM,SAA2B,SAAe;GAC9C,MAAM,OAAgC;IAAE,GAAG;IAAM,GAAG;GAAM;GAC1D,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAAG,IAAI,UAAU,KAAA,GAAW,OAAO,KAAK;GACvF,OAAO;EACT;EACA,MAAM,OAAO,UACX,MAAM,KAAK,SACT,UAAU,UAAU,KAAK,SAAS,aAAa,KAAK,KAAK,OAAO,OAAO,OACnE;GAAE,GAAG;GAAM,MAAM,MAAM,KAAK,IAAI;EAAE,IAClC,UAAU,UAAU,KAAK,SAAS,aAAa,KAAK,KAAK,OAAO,OAAO,OACrE;GAAE,GAAG;GAAM,MAAM,MAAM,KAAK,IAAI;EAAE,IAClC,IACR;EACF,KAAK,MAAM,SAAS,CAAC,GAAG,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG;GAClD,MAAM,QAAQ,IAAI,MAAM,KAAK;GAC7B,MAAM,UAAU,IAAI,MAAM,OAAO;EACnC;CACF;CAEA,QAAQ;EACN,KAAK,OAAO,CAAC;EACb,KAAK,SAAS,CAAC;CACjB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","names":[],"sources":["../../src/core/model.ts"],"sourcesContent":["/*\n * The document a flow editor edits: plain, serialisable data, bound with\n * `v-model`. Positions are canvas coordinates in px, from the top left of a\n * node. Ports are not stored; a node type declares them, and edges refer to\n * them by id.\n */\n\nexport type FlowData = Record<string, unknown>\n\nexport interface FlowNode<Data extends FlowData = FlowData> {\n id: string\n /** A registered node type; `'default'` when left out. */\n type?: string\n x: number\n y: number\n /** Only stored for nodes that can be resized; otherwise the content decides. */\n width?: number\n height?: number\n data?: Data\n /** A locked node cannot be moved or deleted. */\n locked?: boolean\n /**\n * The container node, e.g. a group, this node sits in. Its `x` and `y`\n * stay canvas coordinates; moving the container moves it along.\n */\n parent?: string\n /**\n * Stacking order among nodes that aren't containers: higher is drawn on\n * top. Nodes without it count as `0`; equal ones keep the document order.\n */\n z?: number\n}\n\nexport interface FlowEndpoint {\n node: string\n /** Leave out to attach to the node itself. */\n port?: string\n}\n\nexport interface FlowEdge<Data extends FlowData = FlowData> {\n id: string\n source: FlowEndpoint\n target: FlowEndpoint\n /** The edge type: `bezier`, `step`, `straight` or one added by an extension. The editor's `edge-type` when left out. */\n type?: string\n /** Text shown on the edge. */\n label?: string\n /** Dashes run along the edge in its direction, e.g. while data flows through it. */\n animated?: boolean\n /**\n * Points on the canvas the edge runs through on its way, in order. Tidying\n * sets them on an edge that spans several ranks, so it passes between\n * the nodes in its way; moving either end clears them.\n */\n points?: Point[]\n data?: Data\n}\n\nexport interface FlowDocument {\n /** The version of the format; see `migrateDocument`. */\n version: 1\n nodes: FlowNode[]\n edges: FlowEdge[]\n}\n\nexport type PortSide = 'left' | 'right' | 'top' | 'bottom'\n\nexport interface FlowPortSpec {\n id: string\n /** Inputs receive edges, outputs start them. */\n kind: 'input' | 'output'\n /** Where the port sits; inputs default to the left, outputs to the right. */\n side?: PortSide\n label?: string\n /** What the port carries. Two ports connect when they share a type, or either is `'any'`. */\n dataType?: string | string[]\n /**\n * The most edges the port takes. Inputs take one by default, outputs any\n * number. A new edge on a full port replaces its oldest edge.\n */\n max?: number\n}\n\n/** Where the canvas is shown: `x` and `y` are the screen offset of the canvas origin. */\nexport interface FlowViewport {\n x: number\n y: number\n zoom: number\n}\n\nexport interface FlowSelection {\n nodes: string[]\n edges: string[]\n}\n\nexport interface Point {\n x: number\n y: number\n}\n\nexport interface Rect {\n x: number\n y: number\n width: number\n height: number\n}\n\nexport const emptyDocument = (): FlowDocument => ({ version: 1, nodes: [], edges: [] })\nexport const emptySelection = (): FlowSelection => ({ nodes: [], edges: [] })\n\nlet counter = 0\n\n/** A short id, unique within this page and very likely across clients. */\nexport function createId(prefix = 'n') {\n counter = (counter + 1) % 1296\n const time = Date.now().toString(36).slice(-5)\n const random = Math.random().toString(36).slice(2, 6)\n return `${prefix}${time}${counter.toString(36).padStart(2, '0')}${random}`\n}\n"],"mappings":";AA2GA,IAAa,uBAAqC;CAAE,SAAS;CAAG,OAAO,CAAC;CAAG,OAAO,CAAC;AAAE;AACrF,IAAa,wBAAuC;CAAE,OAAO,CAAC;CAAG,OAAO,CAAC;AAAE;AAE3E,IAAI,UAAU;;AAGd,SAAgB,SAAS,SAAS,KAAK;CACrC,WAAW,UAAU,KAAK;CAC1B,MAAM,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CAC7C,MAAM,SAAS,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;CACpD,OAAO,GAAG,SAAS,OAAO,QAAQ,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,IAAI;AACpE"}
1
+ {"version":3,"file":"model.js","names":[],"sources":["../../src/core/model.ts"],"sourcesContent":["/*\n * The document a flow editor edits: plain, serialisable data, bound with\n * `v-model`. Positions are canvas coordinates in px, from the top left of a\n * node. Ports are not stored; a node type declares them, and edges refer to\n * them by id.\n */\n\nexport type FlowData = Record<string, unknown>\n\nexport interface FlowNode<Data extends FlowData = FlowData> {\n id: string\n /** A registered node type; `'default'` when left out. */\n type?: string\n x: number\n y: number\n /** Only stored for nodes that can be resized; otherwise the content decides. */\n width?: number\n height?: number\n data?: Data\n /** A locked node cannot be moved or deleted. */\n locked?: boolean\n /**\n * The container node, e.g. a group, this node sits in. Its `x` and `y`\n * stay canvas coordinates; moving the container moves it along.\n */\n parent?: string\n /**\n * Stacking order among nodes that aren't containers: higher is drawn on\n * top. Nodes without it count as `0`; equal ones keep the document order.\n */\n z?: number\n /**\n * The ids of the comment threads about this node, see the editor's\n * `comments`. Kept when the node is deleted and brought back by undo.\n */\n comments?: string[]\n}\n\nexport interface FlowEndpoint {\n node: string\n /** Leave out to attach to the node itself. */\n port?: string\n}\n\nexport interface FlowEdge<Data extends FlowData = FlowData> {\n id: string\n source: FlowEndpoint\n target: FlowEndpoint\n /** The edge type: `bezier`, `step`, `straight` or one added by an extension. The editor's `edge-type` when left out. */\n type?: string\n /** Text shown on the edge. */\n label?: string\n /** Dashes run along the edge in its direction, e.g. while data flows through it. */\n animated?: boolean\n /**\n * Points on the canvas the edge runs through on its way, in order. Tidying\n * sets them on an edge that spans several ranks, so it passes between\n * the nodes in its way; moving either end clears them.\n */\n points?: Point[]\n data?: Data\n /** The ids of the comment threads about this edge, see the editor's `comments`. */\n comments?: string[]\n}\n\nexport interface FlowDocument {\n /** The version of the format; see `migrateDocument`. */\n version: 1\n nodes: FlowNode[]\n edges: FlowEdge[]\n}\n\nexport type PortSide = 'left' | 'right' | 'top' | 'bottom'\n\nexport interface FlowPortSpec {\n id: string\n /** Inputs receive edges, outputs start them. */\n kind: 'input' | 'output'\n /** Where the port sits; inputs default to the left, outputs to the right. */\n side?: PortSide\n label?: string\n /** What the port carries. Two ports connect when they share a type, or either is `'any'`. */\n dataType?: string | string[]\n /**\n * The most edges the port takes. Inputs take one by default, outputs any\n * number. A new edge on a full port replaces its oldest edge.\n */\n max?: number\n}\n\n/** Where the canvas is shown: `x` and `y` are the screen offset of the canvas origin. */\nexport interface FlowViewport {\n x: number\n y: number\n zoom: number\n}\n\nexport interface FlowSelection {\n nodes: string[]\n edges: string[]\n}\n\nexport interface Point {\n x: number\n y: number\n}\n\nexport interface Rect {\n x: number\n y: number\n width: number\n height: number\n}\n\nexport const emptyDocument = (): FlowDocument => ({ version: 1, nodes: [], edges: [] })\nexport const emptySelection = (): FlowSelection => ({ nodes: [], edges: [] })\n\nlet counter = 0\n\n/** A short id, unique within this page and very likely across clients. */\nexport function createId(prefix = 'n') {\n counter = (counter + 1) % 1296\n const time = Date.now().toString(36).slice(-5)\n const random = Math.random().toString(36).slice(2, 6)\n return `${prefix}${time}${counter.toString(36).padStart(2, '0')}${random}`\n}\n"],"mappings":";AAkHA,IAAa,uBAAqC;CAAE,SAAS;CAAG,OAAO,CAAC;CAAG,OAAO,CAAC;AAAE;AACrF,IAAa,wBAAuC;CAAE,OAAO,CAAC;CAAG,OAAO,CAAC;AAAE;AAE3E,IAAI,UAAU;;AAGd,SAAgB,SAAS,SAAS,KAAK;CACrC,WAAW,UAAU,KAAK;CAC1B,MAAM,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CAC7C,MAAM,SAAS,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;CACpD,OAAO,GAAG,SAAS,OAAO,QAAQ,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,IAAI;AACpE"}