@dou-ui/flow 0.1.0-alpha.1 → 0.1.0-alpha.11

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 (73) hide show
  1. package/dist/collaboration/index.js +76 -5
  2. package/dist/collaboration/index.js.map +1 -1
  3. package/dist/comments.js +245 -0
  4. package/dist/comments.js.map +1 -0
  5. package/dist/components/default-node2.js.map +1 -1
  6. package/dist/components/flow-comments.js +6 -0
  7. package/dist/components/flow-comments.js.map +1 -0
  8. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +205 -0
  9. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
  10. package/dist/components/port.js +7 -0
  11. package/dist/components/port.js.map +1 -0
  12. package/dist/context.js.map +1 -1
  13. package/dist/core/edge-types.js +107 -3
  14. package/dist/core/edge-types.js.map +1 -1
  15. package/dist/core/extension.js.map +1 -1
  16. package/dist/core/history.js +26 -0
  17. package/dist/core/history.js.map +1 -1
  18. package/dist/core/model.js.map +1 -1
  19. package/dist/core/node-types.js +35 -1
  20. package/dist/core/node-types.js.map +1 -1
  21. package/dist/core/transaction.js +112 -15
  22. package/dist/core/transaction.js.map +1 -1
  23. package/dist/document.js +1 -1
  24. package/dist/export/render.js +78 -0
  25. package/dist/export/render.js.map +1 -0
  26. package/dist/flow-editor.js.map +1 -1
  27. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +454 -36
  28. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  29. package/dist/index.js +6 -6
  30. package/dist/index.js.map +1 -1
  31. package/dist/kit.js +1 -1
  32. package/dist/locale.js +24 -9
  33. package/dist/locale.js.map +1 -1
  34. package/dist/style.css +1 -1
  35. package/dist/style.js +2 -1
  36. package/dist/types/collaboration/index.d.ts +32 -4
  37. package/dist/types/comments.d.ts +73 -0
  38. package/dist/types/components/default-node.d.ts +1 -1
  39. package/dist/types/components/flow-comments.vue.d.ts +35 -0
  40. package/dist/types/components/port.d.ts +7 -0
  41. package/dist/types/context.d.ts +54 -1
  42. package/dist/types/core/extension.d.ts +2 -1
  43. package/dist/types/core/history.d.ts +10 -0
  44. package/dist/types/core/menu.d.ts +5 -0
  45. package/dist/types/core/model.d.ts +19 -0
  46. package/dist/types/core/node-types.d.ts +16 -2
  47. package/dist/types/core/transaction.d.ts +23 -1
  48. package/dist/types/export/render.d.ts +27 -0
  49. package/dist/types/flow-editor.vue.d.ts +11 -0
  50. package/dist/types/index.d.ts +36 -9
  51. package/dist/types/locale.d.ts +13 -3
  52. package/dist/types/whiteboard/image.d.ts +8 -0
  53. package/dist/types/whiteboard/index.d.ts +1 -1
  54. package/dist/types/whiteboard/kit.d.ts +7 -1
  55. package/dist/types/whiteboard/model.d.ts +2 -11
  56. package/dist/types/whiteboard/state.d.ts +5 -1
  57. package/dist/whiteboard/board-node.js.map +1 -1
  58. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +3 -3
  59. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  60. package/dist/whiteboard/connector.js +5 -10
  61. package/dist/whiteboard/connector.js.map +1 -1
  62. package/dist/whiteboard/image.js +17 -6
  63. package/dist/whiteboard/image.js.map +1 -1
  64. package/dist/whiteboard/kit.js +64 -8
  65. package/dist/whiteboard/kit.js.map +1 -1
  66. package/dist/whiteboard/model.js +4 -31
  67. package/dist/whiteboard/model.js.map +1 -1
  68. package/dist/whiteboard/state.js +6 -1
  69. package/dist/whiteboard/state.js.map +1 -1
  70. package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
  71. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
  72. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  73. package/package.json +3 -3
@@ -0,0 +1,205 @@
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 = {
16
+ key: 0,
17
+ class: "dou-flow-editor__comment-count"
18
+ };
19
+ var _hoisted_4 = ["aria-label", "data-placement"];
20
+ var flow_comments_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
21
+ __name: "flow-comments",
22
+ props: {
23
+ comments: {},
24
+ markers: {},
25
+ messages: {},
26
+ restore: { type: Function }
27
+ },
28
+ setup(__props) {
29
+ const props = __props;
30
+ const { comments } = props;
31
+ const panel = shallowRef(null);
32
+ const markerEls = /* @__PURE__ */ new Map();
33
+ /** The marker the card belongs to: the active thread's, or the one being started. */
34
+ const current = computed(() => {
35
+ if (comments.pending.value) return props.markers.find((m) => m.pending) ?? null;
36
+ const id = comments.active.value;
37
+ return id && props.markers.find((m) => m.shown.includes(id)) || null;
38
+ });
39
+ /** The threads the card shows: every open one there, or the active one opened from elsewhere. */
40
+ const shown = computed(() => {
41
+ const marker = current.value;
42
+ if (!marker || comments.pending.value) return [];
43
+ const byId = new Map(comments.threads.value.map((t) => [t.id, t]));
44
+ return marker.shown.flatMap((id) => byId.get(id) ?? []);
45
+ });
46
+ const open = computed(() => !!current.value);
47
+ const layer = shallowRef(null);
48
+ /** The marker has been panned out of the editor: the card waits, hidden, until it is back. */
49
+ const away = computed(() => {
50
+ const marker = current.value;
51
+ const el = layer.value;
52
+ if (!marker || !el) return false;
53
+ return marker.x < 0 || marker.y < 0 || marker.x > el.clientWidth || marker.y > el.clientHeight;
54
+ });
55
+ let awayFocus = null;
56
+ watch(away, async (now) => {
57
+ if (now) {
58
+ const el = document.activeElement;
59
+ awayFocus = el instanceof HTMLElement && panel.value?.contains(el) ? el : null;
60
+ return;
61
+ }
62
+ const el = awayFocus;
63
+ awayFocus = null;
64
+ await nextTick();
65
+ const at = document.activeElement;
66
+ if (el?.isConnected && (!at || at === document.body)) el.focus({ preventScroll: true });
67
+ });
68
+ const anchor = { getBoundingClientRect() {
69
+ const marker = current.value;
70
+ const el = marker && markerEls.get(marker.key);
71
+ return el ? el.getBoundingClientRect() : new DOMRect();
72
+ } };
73
+ const { style, placement, update } = useFloating(() => open.value ? anchor : null, panel, {
74
+ open,
75
+ placement: "bottom-start",
76
+ offset: 6
77
+ });
78
+ const { next } = useZIndex();
79
+ const zIndex = shallowRef(0);
80
+ watch(open, (value) => value && (zIndex.value = next()), { immediate: true });
81
+ watch(() => current.value && [current.value.x, current.value.y], () => open.value && void nextTick(update));
82
+ let lastAnchor = null;
83
+ watch(current, (marker) => marker && (lastAnchor = marker.anchor), { immediate: true });
84
+ const focusLost = () => {
85
+ const el = document.activeElement;
86
+ return !el || el === document.body || !!panel.value?.contains(el);
87
+ };
88
+ function close() {
89
+ const refocus = focusLost();
90
+ comments.close();
91
+ if (refocus) props.restore(lastAnchor);
92
+ }
93
+ useLayer({
94
+ open,
95
+ elements: () => [panel.value, ...markerEls.values()],
96
+ onEscape: () => close(),
97
+ onOutside: () => comments.close()
98
+ });
99
+ const views = useTemplateRef("views");
100
+ watch(() => comments.focusRequest.value, async () => {
101
+ await nextTick();
102
+ await nextTick();
103
+ const id = comments.active.value;
104
+ const index = shown.value.findIndex((t) => t.id === id);
105
+ views.value?.[Math.max(0, index)]?.focus();
106
+ });
107
+ function onClosed() {
108
+ const el = document.activeElement;
109
+ if (!el || el === document.body) props.restore(lastAnchor);
110
+ }
111
+ /**
112
+ * When the thread being started was opened. A tap that starts one (the
113
+ * whiteboard's comment tool) is followed by the click the browser makes
114
+ * from it, which lands on the new pin just drawn under the finger: that
115
+ * one doesn't close it.
116
+ */
117
+ let startedAt = -Infinity;
118
+ watch(() => comments.pending.value, (now) => now && (startedAt = performance.now()));
119
+ function press(marker, event) {
120
+ if (marker.pending && performance.now() - startedAt < 500) return;
121
+ if (current.value?.key === marker.key) return comments.close();
122
+ const focus = event.detail === 0;
123
+ const [first] = marker.threads;
124
+ if (first) comments.show(first, focus);
125
+ else comments.start(marker.anchor, focus);
126
+ }
127
+ const label = (marker) => marker.number ? format(props.messages.commentPin, {
128
+ number: marker.number,
129
+ node: marker.node ?? ""
130
+ }) : marker.threads.length ? format(props.messages.comments, { count: marker.threads.length }) : props.messages.comment;
131
+ return (_ctx, _cache) => {
132
+ return openBlock(), createElementBlock(Fragment, null, [createElementVNode("div", {
133
+ ref_key: "layer",
134
+ ref: layer,
135
+ class: "dou-flow-editor__comments"
136
+ }, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.markers, (marker) => {
137
+ return openBlock(), createElementBlock("button", {
138
+ key: marker.key,
139
+ ref_for: true,
140
+ ref: (el) => el ? unref(markerEls).set(marker.key, el) : unref(markerEls).delete(marker.key),
141
+ type: "button",
142
+ class: normalizeClass(["dou-flow-editor__comment", {
143
+ "is-active": current.value?.key === marker.key,
144
+ "is-new": !marker.threads.length,
145
+ "is-node": "node" in marker.anchor && marker.number === void 0,
146
+ "is-pin": marker.number !== void 0,
147
+ "is-lifted": marker.lifted
148
+ }]),
149
+ style: normalizeStyle({ translate: `${marker.x}px ${marker.y}px` }),
150
+ "aria-label": label(marker),
151
+ "aria-expanded": current.value?.key === marker.key,
152
+ onClick: ($event) => press(marker, $event)
153
+ }, [marker.number ? (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(marker.number), 1)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createVNode(unref(MessageCircleIcon), { "aria-hidden": "true" }), marker.number === void 0 && marker.threads.length > 1 ? (openBlock(), createElementBlock("span", _hoisted_3, toDisplayString(marker.threads.length), 1)) : createCommentVNode("", true)], 64))], 14, _hoisted_1);
154
+ }), 128))], 512), createVNode(Transition, {
155
+ name: "dou-floating",
156
+ onAfterLeave: onClosed
157
+ }, {
158
+ default: withCtx(() => [open.value ? (openBlock(), createElementBlock("div", {
159
+ key: 0,
160
+ ref_key: "panel",
161
+ ref: panel,
162
+ class: normalizeClass(["dou-floating dou-flow-editor__comment-card", { "is-away": away.value }]),
163
+ role: "dialog",
164
+ "aria-label": __props.messages.comment,
165
+ style: normalizeStyle([unref(style), { zIndex: zIndex.value }]),
166
+ "data-placement": unref(placement)
167
+ }, [unref(comments).pending.value ? (openBlock(), createBlock(unref(DouCommentThread), {
168
+ ref_key: "views",
169
+ ref: views,
170
+ key: "new",
171
+ thread: null,
172
+ author: unref(comments).author.value,
173
+ autofocus: unref(comments).pendingFocus.value,
174
+ onAction: unref(comments).apply,
175
+ onCancel: close
176
+ }, null, 8, [
177
+ "author",
178
+ "autofocus",
179
+ "onAction"
180
+ ])) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(shown.value, (thread) => {
181
+ return openBlock(), createBlock(unref(DouCommentThread), {
182
+ key: thread.id,
183
+ ref_for: true,
184
+ ref_key: "views",
185
+ ref: views,
186
+ thread,
187
+ author: unref(comments).author.value,
188
+ readonly: !unref(comments).writable.value,
189
+ onAction: unref(comments).apply,
190
+ onCancel: close
191
+ }, null, 8, [
192
+ "thread",
193
+ "author",
194
+ "readonly",
195
+ "onAction"
196
+ ]);
197
+ }), 128))], 14, _hoisted_4)) : createCommentVNode("", true)]),
198
+ _: 1
199
+ })], 64);
200
+ };
201
+ }
202
+ });
203
+ export { flow_comments_vue_vue_type_script_setup_true_lang_default as default };
204
+
205
+ //# 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","_toDisplayString","_createVNode","_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 * A pin on a point of a node: its place among the open pins there, from\n * 1; `0` for one being started or a resolved one opened from outside.\n */\n number?: number\n /** The name of the node it is on, for screen readers. */\n node?: string\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\n/**\n * When the thread being started was opened. A tap that starts one (the\n * whiteboard's comment tool) is followed by the click the browser makes\n * from it, which lands on the new pin just drawn under the finger: that\n * one doesn't close it.\n */\nlet startedAt = -Infinity\nwatch(\n () => comments.pending.value,\n (now) => now && (startedAt = performance.now()),\n)\n\nfunction press(marker: FlowCommentMarker, event: MouseEvent) {\n if (marker.pending && performance.now() - startedAt < 500) return\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 marker.number\n ? format(props.messages.commentPin, { number: marker.number, node: marker.node ?? '' })\n : marker.threads.length\n ? format(props.messages.comments, { count: marker.threads.length })\n : props.messages.comment\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 && marker.number === undefined,\n 'is-pin': marker.number !== undefined,\n 'is-lifted': marker.lifted,\n }\"\n :style=\"{ translate: `${marker.x}px ${marker.y}px` }\"\n :aria-label=\"label(marker)\"\n :aria-expanded=\"current?.key === marker.key\"\n @click=\"press(marker, $event)\"\n >\n <span v-if=\"marker.number\" class=\"dou-flow-editor__comment-count\">{{ marker.number }}</span>\n <template v-else>\n <MessageCircleIcon aria-hidden=\"true\" />\n <span\n v-if=\"marker.number === undefined && marker.threads.length > 1\"\n class=\"dou-flow-editor__comment-count\"\n >{{ marker.threads.length }}</span\n >\n </template>\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=\"comments.pendingFocus.value\"\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4CA,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,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{ withInstall } from "dou-ui";
3
+ // src/components/port.ts
4
+ var DouFlowPort = withInstall(flow_port_default);
5
+ export { DouFlowPort };
6
+
7
+ //# sourceMappingURL=port.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"port.js","names":["FlowPort"],"sources":["../../src/components/port.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport FlowPort from './flow-port.vue'\n\n// 单独成模块:白板(@dou-ui/flow/whiteboard)从这里取包装过的组件,不用引入整个编辑器入口\nexport const DouFlowPort = withInstall(FlowPort)\n"],"mappings":";;;AAIA,IAAa,cAAc,YAAYA,iBAAQ"}
@@ -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 /** 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":";;AA8WA,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/**\n * What a comment thread is about: a node, a point on a node, or an edge.\n * `at` pins the thread to that point, as fractions of the node's width and\n * height from its top left, 0 to 1 (not canvas px, unlike other `at`s).\n * `number` is the pin's number on the node, as drawn: read from\n * `getCommentAnchors`, left out when starting one.\n */\nexport type FlowCommentAnchor = { node: string; at?: Point; number?: number } | { 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. With\n * `at`, it always starts a new thread pinned to that point of the node.\n * `focus: false` leaves the focus where it is instead of putting it in the\n * reply box, for a tap that shouldn't bring up a phone's keyboard.\n */\n comment: (anchor?: FlowCommentAnchor, options?: { focus?: boolean }) => 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 /** See `FlowEditorExpose.comment`. */\n comment: FlowEditorExpose['comment']\n /** Comment threads can be started: the editor has `comments`, an `author` and is `commentable`. */\n canComment: ComputedRef<boolean>\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":";;AA4ZA,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"}
@@ -54,10 +54,66 @@ function bezierPath(from, fromSide, to, toSide, min = 40) {
54
54
  }, min);
55
55
  return `M${fmt(from)}C${fmt(c1)} ${fmt(c2)} ${fmt(to)}`;
56
56
  }
57
+ /** The point halfway along a run of points: a middle one, or between the two middle ones. */
58
+ function middle(points) {
59
+ const a = points[Math.floor((points.length - 1) / 2)];
60
+ const b = points[Math.ceil((points.length - 1) / 2)];
61
+ return {
62
+ x: (a.x + b.x) / 2,
63
+ y: (a.y + b.y) / 2
64
+ };
65
+ }
66
+ /**
67
+ * The side a run between two points leaves the first by and the side it
68
+ * enters the second by, along the axis the flow runs in: the one the
69
+ * source's port faces.
70
+ */
71
+ function sides(a, b, vertical) {
72
+ if (vertical) return b.y >= a.y ? ["bottom", "top"] : ["top", "bottom"];
73
+ return b.x >= a.x ? ["right", "left"] : ["left", "right"];
74
+ }
75
+ /**
76
+ * A curve through the points an edge runs through, as tidying lays them:
77
+ * straight along a rank, curving across the gaps between ranks.
78
+ */
79
+ function bezierThrough(source, target, points) {
80
+ const vertical = isVertical(source.side);
81
+ const all = [
82
+ source,
83
+ ...points.map((p) => ({
84
+ ...p,
85
+ side: source.side
86
+ })),
87
+ target
88
+ ];
89
+ let path = `M${fmt(source)}`;
90
+ for (let i = 1; i < all.length; i++) {
91
+ const a = all[i - 1];
92
+ const b = all[i];
93
+ if ((vertical ? Math.abs(a.x - b.x) < .5 : Math.abs(a.y - b.y) < .5) && i > 1 && i < all.length - 1) {
94
+ path += `L${fmt(b)}`;
95
+ continue;
96
+ }
97
+ const [out, into] = sides(a, b, vertical);
98
+ const [c1, c2] = bezierControls({
99
+ ...a,
100
+ side: i === 1 ? source.side : out
101
+ }, {
102
+ ...b,
103
+ side: i === all.length - 1 ? target.side : into
104
+ }, 0);
105
+ path += `C${fmt(c1)} ${fmt(c2)} ${fmt(b)}`;
106
+ }
107
+ return {
108
+ path,
109
+ label: middle(points)
110
+ };
111
+ }
57
112
  /** The default: a smooth curve out of and into the ports' sides. */
58
113
  var bezierEdge = defineEdgeType({
59
114
  type: "bezier",
60
- route(source, target) {
115
+ route(source, target, edge) {
116
+ if (edge?.points?.length) return bezierThrough(source, target, edge.points);
61
117
  const [c1, c2] = bezierControls(source, target);
62
118
  return {
63
119
  path: `M${fmt(source)}C${fmt(c1)} ${fmt(c2)} ${fmt(target)}`,
@@ -70,13 +126,20 @@ var bezierEdge = defineEdgeType({
70
126
  });
71
127
  var straightEdge = defineEdgeType({
72
128
  type: "straight",
73
- route: (source, target) => ({
129
+ route: (source, target, edge) => edge?.points?.length ? {
130
+ path: `M${[
131
+ source,
132
+ ...edge.points,
133
+ target
134
+ ].map(fmt).join("L")}`,
135
+ label: middle(edge.points)
136
+ } : {
74
137
  path: `M${fmt(source)}L${fmt(target)}`,
75
138
  label: {
76
139
  x: (source.x + target.x) / 2,
77
140
  y: (source.y + target.y) / 2
78
141
  }
79
- })
142
+ }
80
143
  });
81
144
  /** How far a step edge runs out of a port before its first turn. */
82
145
  var STUB = 20;
@@ -130,6 +193,7 @@ var flipSide = {
130
193
  var stepEdge = defineEdgeType({
131
194
  type: "step",
132
195
  route(source, target, edge) {
196
+ if (edge?.points?.length) return stepThrough(source, target, edge.points);
133
197
  const turned = isVertical(source.side) && isVertical(target.side);
134
198
  const s = turned ? {
135
199
  ...flip(source),
@@ -235,6 +299,46 @@ var stepEdge = defineEdgeType({
235
299
  };
236
300
  }
237
301
  });
302
+ /**
303
+ * Right angles through the points an edge runs through: along each rank,
304
+ * across each gap between ranks halfway through it.
305
+ */
306
+ function stepThrough(source, target, points) {
307
+ const vertical = isVertical(source.side);
308
+ const all = [
309
+ source,
310
+ ...points,
311
+ target
312
+ ];
313
+ const out = [source];
314
+ for (let i = 1; i < all.length; i++) {
315
+ const a = all[i - 1];
316
+ const b = all[i];
317
+ if (vertical) {
318
+ const y = (a.y + b.y) / 2;
319
+ out.push({
320
+ x: a.x,
321
+ y
322
+ }, {
323
+ x: b.x,
324
+ y
325
+ }, b);
326
+ } else {
327
+ const x = (a.x + b.x) / 2;
328
+ out.push({
329
+ x,
330
+ y: a.y
331
+ }, {
332
+ x,
333
+ y: b.y
334
+ }, b);
335
+ }
336
+ }
337
+ return {
338
+ path: rounded(out),
339
+ label: middle(points)
340
+ };
341
+ }
238
342
  export { bezierEdge, bezierPath, defineEdgeType, stepEdge, straightEdge };
239
343
 
240
344
  //# sourceMappingURL=edge-types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"edge-types.js","names":[],"sources":["../../src/core/edge-types.ts"],"sourcesContent":["import type { CSSProperties } from 'vue'\nimport type { FlowData, FlowEdge, Point, PortSide } from './model'\n\n/** Where an edge leaves or enters a node: a point and the side it faces. */\nexport interface EdgeAnchor extends Point {\n side: PortSide\n}\n\nexport interface EdgeRoute {\n /** The SVG path, in canvas coordinates. */\n path: string\n /** Where the label sits. */\n label: Point\n /**\n * A handle shown on the selected edge that moves part of it, e.g. the\n * middle of a step edge. `axis` is the way it moves; `move` turns the\n * pointer's canvas point into a patch for `edge.data`.\n */\n handle?: { at: Point; axis: 'x' | 'y'; move: (point: Point) => FlowData }\n /**\n * Marks drawn with the edge's stroke but never dashed, e.g. arrowheads:\n * an SVG path in canvas coordinates.\n */\n marks?: string\n}\n\nexport interface EdgeTypeSpec<Data extends FlowData = FlowData> {\n type: string\n /** The edge's path between two anchors. `edge` is absent while one is being drawn. */\n route: (source: EdgeAnchor, target: EdgeAnchor, edge?: FlowEdge<Data>) => EdgeRoute\n /** The edge's own look, e.g. `strokeDasharray`, over what its port type gives it. */\n style?: (edge: FlowEdge<Data>) => CSSProperties | undefined\n}\n\n/** Declares an edge type, with `edge.data` typed. */\nexport function defineEdgeType<Data extends FlowData = FlowData>(\n spec: EdgeTypeSpec<Data>,\n): EdgeTypeSpec<Data> {\n return spec\n}\n\nconst direction: Record<PortSide, Point> = {\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n bottom: { x: 0, y: 1 },\n}\n\nconst round = (value: number) => Math.round(value * 100) / 100\nconst fmt = (p: Point) => `${round(p.x)} ${round(p.y)}`\nconst isVertical = (side: PortSide) => side === 'top' || side === 'bottom'\n\n/**\n * A cubic curve leaving `from` and entering `to` straight out of their\n * sides. The handles are equally long, half the distance along the axis\n * they point in (at least `min`), so a fan of edges from one port is\n * mirror-symmetric and a straight run stays a straight line.\n */\nfunction bezierControls(from: EdgeAnchor, to: EdgeAnchor, min = 40) {\n const a = direction[from.side]\n const b = direction[to.side]\n const span = (dir: Point) => Math.abs(dir.x ? to.x - from.x : to.y - from.y)\n const lenA = Math.max(min, span(a) / 2)\n const lenB = Math.max(min, span(b) / 2)\n return [\n { x: from.x + a.x * lenA, y: from.y + a.y * lenA },\n { x: to.x + b.x * lenB, y: to.y + b.y * lenB },\n ] as const\n}\n\nexport function bezierPath(from: Point, fromSide: PortSide, to: Point, toSide: PortSide, min = 40) {\n const [c1, c2] = bezierControls({ ...from, side: fromSide }, { ...to, side: toSide }, min)\n return `M${fmt(from)}C${fmt(c1)} ${fmt(c2)} ${fmt(to)}`\n}\n\n/** The default: a smooth curve out of and into the ports' sides. */\nexport const bezierEdge = defineEdgeType({\n type: 'bezier',\n route(source, target) {\n const [c1, c2] = bezierControls(source, target)\n return {\n path: `M${fmt(source)}C${fmt(c1)} ${fmt(c2)} ${fmt(target)}`,\n // The curve at its middle.\n label: {\n x: (source.x + 3 * c1.x + 3 * c2.x + target.x) / 8,\n y: (source.y + 3 * c1.y + 3 * c2.y + target.y) / 8,\n },\n }\n },\n})\n\nexport const straightEdge = defineEdgeType({\n type: 'straight',\n route: (source, target) => ({\n path: `M${fmt(source)}L${fmt(target)}`,\n label: { x: (source.x + target.x) / 2, y: (source.y + target.y) / 2 },\n }),\n})\n\n/** How far a step edge runs out of a port before its first turn. */\nconst STUB = 20\nconst RADIUS = 6\n\n/** A polyline with its corners rounded. */\nfunction rounded(points: Point[], radius = RADIUS) {\n // Drop repeated points and points in the middle of a straight run.\n const pts: Point[] = []\n for (const p of points) {\n const last = pts[pts.length - 1]\n if (last && Math.abs(last.x - p.x) < 0.01 && Math.abs(last.y - p.y) < 0.01) continue\n const before = pts[pts.length - 2]\n if (\n before &&\n last &&\n ((Math.abs(before.x - last.x) < 0.01 && Math.abs(last.x - p.x) < 0.01) ||\n (Math.abs(before.y - last.y) < 0.01 && Math.abs(last.y - p.y) < 0.01))\n )\n pts.pop()\n pts.push(p)\n }\n let d = `M${fmt(pts[0]!)}`\n for (let i = 1; i < pts.length - 1; i++) {\n const [a, b, c] = [pts[i - 1]!, pts[i]!, pts[i + 1]!]\n const lenIn = Math.hypot(b.x - a.x, b.y - a.y)\n const lenOut = Math.hypot(c.x - b.x, c.y - b.y)\n const r = Math.min(radius, lenIn / 2, lenOut / 2)\n const p1 = { x: b.x - ((b.x - a.x) / lenIn) * r, y: b.y - ((b.y - a.y) / lenIn) * r }\n const p2 = { x: b.x + ((c.x - b.x) / lenOut) * r, y: b.y + ((c.y - b.y) / lenOut) * r }\n d += `L${fmt(p1)}Q${fmt(b)} ${fmt(p2)}`\n }\n return d + `L${fmt(pts[pts.length - 1]!)}`\n}\n\nconst flip = (p: Point): Point => ({ x: p.y, y: p.x })\nconst flipSide: Record<PortSide, PortSide> = {\n left: 'top',\n right: 'bottom',\n top: 'left',\n bottom: 'right',\n}\n\ninterface StepData extends FlowData {\n /** Where the middle segment sits between the two ends, from 0 to 1. */\n bend?: number\n}\n\n/**\n * Right angles with rounded corners. Between ports that face each other the\n * middle segment can be dragged; its place is kept in `edge.data.bend`.\n */\nexport const stepEdge = defineEdgeType<StepData>({\n type: 'step',\n route(source, target, edge) {\n // Work as if the ports faced left and right, then turn the result back.\n const turned = isVertical(source.side) && isVertical(target.side)\n const s = turned ? { ...flip(source), side: flipSide[source.side] } : source\n const t = turned ? { ...flip(target), side: flipSide[target.side] } : target\n const back = (p: Point) => (turned ? flip(p) : p)\n const ds = direction[s.side]\n const dt = direction[t.side]\n const s1 = { x: s.x + ds.x * STUB, y: s.y + ds.y * STUB }\n const t1 = { x: t.x + dt.x * STUB, y: t.y + dt.y * STUB }\n let points: Point[]\n let label: Point\n let handle: EdgeRoute['handle']\n\n if (ds.x && dt.x && ds.x === -dt.x && (t.x - s.x) * ds.x > 0) {\n // Facing each other: across, along, across.\n const bend = Math.min(0.95, Math.max(0.05, edge?.data?.bend ?? 0.5))\n const mid = s.x + (t.x - s.x) * bend\n points = [s, { x: mid, y: s.y }, { x: mid, y: t.y }, t]\n label = { x: mid, y: (s.y + t.y) / 2 }\n // No handle when the ends line up: the middle segment has no length.\n if (t.x !== s.x && Math.abs(t.y - s.y) >= 1) {\n const span = t.x - s.x\n const at = back(label)\n handle = {\n at,\n axis: turned ? 'y' : 'x',\n move: (point) => {\n const v = turned ? point.y : point.x\n return { bend: Math.min(0.95, Math.max(0.05, (v - s.x) / span)) }\n },\n }\n }\n } else if (ds.x && dt.x) {\n // Facing away, or the same way: out, around through the middle, in.\n const gap = Math.abs(s.y - t.y)\n const my = gap >= STUB * 2 ? (s.y + t.y) / 2 : Math.max(s.y, t.y) + STUB * 2\n const x1 = ds.x === dt.x ? (ds.x > 0 ? Math.max(s1.x, t1.x) : Math.min(s1.x, t1.x)) : s1.x\n const x2 = ds.x === dt.x ? x1 : t1.x\n points = [s, { x: x1, y: s.y }, { x: x1, y: my }, { x: x2, y: my }, { x: x2, y: t.y }, t]\n label = { x: (x1 + x2) / 2, y: my }\n } else {\n // One across, one along: a single corner when the ends allow it.\n const corner = ds.x ? { x: t1.x, y: s1.y } : { x: s1.x, y: t1.y }\n points = [s, s1, corner, t1, t]\n label = corner\n }\n return { path: rounded(points.map(back)), label: back(label), handle }\n },\n})\n"],"mappings":";;AAmCA,SAAgB,eACd,MACoB;CACpB,OAAO;AACT;AAEA,IAAM,YAAqC;CACzC,MAAM;EAAE,GAAG;EAAI,GAAG;CAAE;CACpB,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;CACpB,KAAK;EAAE,GAAG;EAAG,GAAG;CAAG;CACnB,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;AACvB;AAEA,IAAM,SAAS,UAAkB,KAAK,MAAM,QAAQ,GAAG,IAAI;AAC3D,IAAM,OAAO,MAAa,GAAG,MAAM,EA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AE;IAAG;KAAE,GAAG;KAAI,GAAG;IAAG;IAAG;KAAE,GAAG;KAAI,GAAG;IAAG;IAAG;KAAE,GAAG;KAAI,GAAG,EAAE;IAAE;IAAG;GAAC;GACxF,QAAQ;IAAE,IAAI,KAAK,MAAM;IAAG,GAAG;GAAG;EACpC,OAAO;GAEL,MAAM,SAAS,GAAG,IAAI;IAAE,GAAG,GAAG;IAAG,GAAG,GAAG;GAAE,IAAI;IAAE,GAAG,GAAG;IAAG,GAAG,GAAG;GAAE;GAChE,SAAS;IAAC;IAAG;IAAI;IAAQ;IAAI;GAAC;GAC9B,QAAQ;EACV;EACA,OAAO;GAAE,MAAM,QAAQ,OAAO,IAAI,IAAI,CAAC;GAAG,OAAO,KAAK,KAAK;GAAG;EAAO;CACvE;AACF,CAAC"}
1
+ {"version":3,"file":"edge-types.js","names":[],"sources":["../../src/core/edge-types.ts"],"sourcesContent":["import type { CSSProperties } from 'vue'\nimport type { FlowData, FlowEdge, Point, PortSide } from './model'\n\n/** Where an edge leaves or enters a node: a point and the side it faces. */\nexport interface EdgeAnchor extends Point {\n side: PortSide\n}\n\nexport interface EdgeRoute {\n /** The SVG path, in canvas coordinates. */\n path: string\n /** Where the label sits. */\n label: Point\n /**\n * A handle shown on the selected edge that moves part of it, e.g. the\n * middle of a step edge. `axis` is the way it moves; `move` turns the\n * pointer's canvas point into a patch for `edge.data`.\n */\n handle?: { at: Point; axis: 'x' | 'y'; move: (point: Point) => FlowData }\n /**\n * Marks drawn with the edge's stroke but never dashed, e.g. arrowheads:\n * an SVG path in canvas coordinates.\n */\n marks?: string\n}\n\nexport interface EdgeTypeSpec<Data extends FlowData = FlowData> {\n type: string\n /** The edge's path between two anchors. `edge` is absent while one is being drawn. */\n route: (source: EdgeAnchor, target: EdgeAnchor, edge?: FlowEdge<Data>) => EdgeRoute\n /** The edge's own look, e.g. `strokeDasharray`, over what its port type gives it. */\n style?: (edge: FlowEdge<Data>) => CSSProperties | undefined\n}\n\n/** Declares an edge type, with `edge.data` typed. */\nexport function defineEdgeType<Data extends FlowData = FlowData>(\n spec: EdgeTypeSpec<Data>,\n): EdgeTypeSpec<Data> {\n return spec\n}\n\nconst direction: Record<PortSide, Point> = {\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n bottom: { x: 0, y: 1 },\n}\n\nconst round = (value: number) => Math.round(value * 100) / 100\nconst fmt = (p: Point) => `${round(p.x)} ${round(p.y)}`\nconst isVertical = (side: PortSide) => side === 'top' || side === 'bottom'\n\n/**\n * A cubic curve leaving `from` and entering `to` straight out of their\n * sides. The handles are equally long, half the distance along the axis\n * they point in (at least `min`), so a fan of edges from one port is\n * mirror-symmetric and a straight run stays a straight line.\n */\nfunction bezierControls(from: EdgeAnchor, to: EdgeAnchor, min = 40) {\n const a = direction[from.side]\n const b = direction[to.side]\n const span = (dir: Point) => Math.abs(dir.x ? to.x - from.x : to.y - from.y)\n const lenA = Math.max(min, span(a) / 2)\n const lenB = Math.max(min, span(b) / 2)\n return [\n { x: from.x + a.x * lenA, y: from.y + a.y * lenA },\n { x: to.x + b.x * lenB, y: to.y + b.y * lenB },\n ] as const\n}\n\nexport function bezierPath(from: Point, fromSide: PortSide, to: Point, toSide: PortSide, min = 40) {\n const [c1, c2] = bezierControls({ ...from, side: fromSide }, { ...to, side: toSide }, min)\n return `M${fmt(from)}C${fmt(c1)} ${fmt(c2)} ${fmt(to)}`\n}\n\n/** The point halfway along a run of points: a middle one, or between the two middle ones. */\nfunction middle(points: Point[]): Point {\n const a = points[Math.floor((points.length - 1) / 2)]!\n const b = points[Math.ceil((points.length - 1) / 2)]!\n return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }\n}\n\n/**\n * The side a run between two points leaves the first by and the side it\n * enters the second by, along the axis the flow runs in: the one the\n * source's port faces.\n */\nfunction sides(a: Point, b: Point, vertical: boolean): [PortSide, PortSide] {\n if (vertical) return b.y >= a.y ? ['bottom', 'top'] : ['top', 'bottom']\n return b.x >= a.x ? ['right', 'left'] : ['left', 'right']\n}\n\n/**\n * A curve through the points an edge runs through, as tidying lays them:\n * straight along a rank, curving across the gaps between ranks.\n */\nfunction bezierThrough(source: EdgeAnchor, target: EdgeAnchor, points: Point[]): EdgeRoute {\n const vertical = isVertical(source.side)\n const all: EdgeAnchor[] = [source, ...points.map((p) => ({ ...p, side: source.side })), target]\n let path = `M${fmt(source)}`\n for (let i = 1; i < all.length; i++) {\n const a = all[i - 1]!\n const b = all[i]!\n const level = vertical ? Math.abs(a.x - b.x) < 0.5 : Math.abs(a.y - b.y) < 0.5\n if (level && i > 1 && i < all.length - 1) {\n path += `L${fmt(b)}`\n continue\n }\n const [out, into] = sides(a, b, vertical)\n const [c1, c2] = bezierControls(\n { ...a, side: i === 1 ? source.side : out },\n { ...b, side: i === all.length - 1 ? target.side : into },\n 0,\n )\n path += `C${fmt(c1)} ${fmt(c2)} ${fmt(b)}`\n }\n return { path, label: middle(points) }\n}\n\n/** The default: a smooth curve out of and into the ports' sides. */\nexport const bezierEdge = defineEdgeType({\n type: 'bezier',\n route(source, target, edge) {\n if (edge?.points?.length) return bezierThrough(source, target, edge.points)\n const [c1, c2] = bezierControls(source, target)\n return {\n path: `M${fmt(source)}C${fmt(c1)} ${fmt(c2)} ${fmt(target)}`,\n // The curve at its middle.\n label: {\n x: (source.x + 3 * c1.x + 3 * c2.x + target.x) / 8,\n y: (source.y + 3 * c1.y + 3 * c2.y + target.y) / 8,\n },\n }\n },\n})\n\nexport const straightEdge = defineEdgeType({\n type: 'straight',\n route: (source, target, edge) =>\n edge?.points?.length\n ? {\n path: `M${[source, ...edge.points, target].map(fmt).join('L')}`,\n label: middle(edge.points),\n }\n : {\n path: `M${fmt(source)}L${fmt(target)}`,\n label: { x: (source.x + target.x) / 2, y: (source.y + target.y) / 2 },\n },\n})\n\n/** How far a step edge runs out of a port before its first turn. */\nconst STUB = 20\nconst RADIUS = 6\n\n/** A polyline with its corners rounded. */\nfunction rounded(points: Point[], radius = RADIUS) {\n // Drop repeated points and points in the middle of a straight run.\n const pts: Point[] = []\n for (const p of points) {\n const last = pts[pts.length - 1]\n if (last && Math.abs(last.x - p.x) < 0.01 && Math.abs(last.y - p.y) < 0.01) continue\n const before = pts[pts.length - 2]\n if (\n before &&\n last &&\n ((Math.abs(before.x - last.x) < 0.01 && Math.abs(last.x - p.x) < 0.01) ||\n (Math.abs(before.y - last.y) < 0.01 && Math.abs(last.y - p.y) < 0.01))\n )\n pts.pop()\n pts.push(p)\n }\n let d = `M${fmt(pts[0]!)}`\n for (let i = 1; i < pts.length - 1; i++) {\n const [a, b, c] = [pts[i - 1]!, pts[i]!, pts[i + 1]!]\n const lenIn = Math.hypot(b.x - a.x, b.y - a.y)\n const lenOut = Math.hypot(c.x - b.x, c.y - b.y)\n const r = Math.min(radius, lenIn / 2, lenOut / 2)\n const p1 = { x: b.x - ((b.x - a.x) / lenIn) * r, y: b.y - ((b.y - a.y) / lenIn) * r }\n const p2 = { x: b.x + ((c.x - b.x) / lenOut) * r, y: b.y + ((c.y - b.y) / lenOut) * r }\n d += `L${fmt(p1)}Q${fmt(b)} ${fmt(p2)}`\n }\n return d + `L${fmt(pts[pts.length - 1]!)}`\n}\n\nconst flip = (p: Point): Point => ({ x: p.y, y: p.x })\nconst flipSide: Record<PortSide, PortSide> = {\n left: 'top',\n right: 'bottom',\n top: 'left',\n bottom: 'right',\n}\n\ninterface StepData extends FlowData {\n /** Where the middle segment sits between the two ends, from 0 to 1. */\n bend?: number\n}\n\n/**\n * Right angles with rounded corners. Between ports that face each other the\n * middle segment can be dragged; its place is kept in `edge.data.bend`.\n */\nexport const stepEdge = defineEdgeType<StepData>({\n type: 'step',\n route(source, target, edge) {\n if (edge?.points?.length) return stepThrough(source, target, edge.points)\n // Work as if the ports faced left and right, then turn the result back.\n const turned = isVertical(source.side) && isVertical(target.side)\n const s = turned ? { ...flip(source), side: flipSide[source.side] } : source\n const t = turned ? { ...flip(target), side: flipSide[target.side] } : target\n const back = (p: Point) => (turned ? flip(p) : p)\n const ds = direction[s.side]\n const dt = direction[t.side]\n const s1 = { x: s.x + ds.x * STUB, y: s.y + ds.y * STUB }\n const t1 = { x: t.x + dt.x * STUB, y: t.y + dt.y * STUB }\n let points: Point[]\n let label: Point\n let handle: EdgeRoute['handle']\n\n if (ds.x && dt.x && ds.x === -dt.x && (t.x - s.x) * ds.x > 0) {\n // Facing each other: across, along, across.\n const bend = Math.min(0.95, Math.max(0.05, edge?.data?.bend ?? 0.5))\n const mid = s.x + (t.x - s.x) * bend\n points = [s, { x: mid, y: s.y }, { x: mid, y: t.y }, t]\n label = { x: mid, y: (s.y + t.y) / 2 }\n // No handle when the ends line up: the middle segment has no length.\n if (t.x !== s.x && Math.abs(t.y - s.y) >= 1) {\n const span = t.x - s.x\n const at = back(label)\n handle = {\n at,\n axis: turned ? 'y' : 'x',\n move: (point) => {\n const v = turned ? point.y : point.x\n return { bend: Math.min(0.95, Math.max(0.05, (v - s.x) / span)) }\n },\n }\n }\n } else if (ds.x && dt.x) {\n // Facing away, or the same way: out, around through the middle, in.\n const gap = Math.abs(s.y - t.y)\n const my = gap >= STUB * 2 ? (s.y + t.y) / 2 : Math.max(s.y, t.y) + STUB * 2\n const x1 = ds.x === dt.x ? (ds.x > 0 ? Math.max(s1.x, t1.x) : Math.min(s1.x, t1.x)) : s1.x\n const x2 = ds.x === dt.x ? x1 : t1.x\n points = [s, { x: x1, y: s.y }, { x: x1, y: my }, { x: x2, y: my }, { x: x2, y: t.y }, t]\n label = { x: (x1 + x2) / 2, y: my }\n } else {\n // One across, one along: a single corner when the ends allow it.\n const corner = ds.x ? { x: t1.x, y: s1.y } : { x: s1.x, y: t1.y }\n points = [s, s1, corner, t1, t]\n label = corner\n }\n return { path: rounded(points.map(back)), label: back(label), handle }\n },\n})\n\n/**\n * Right angles through the points an edge runs through: along each rank,\n * across each gap between ranks halfway through it.\n */\nfunction stepThrough(source: EdgeAnchor, target: EdgeAnchor, points: Point[]): EdgeRoute {\n const vertical = isVertical(source.side)\n const all = [source, ...points, target]\n const out: Point[] = [source]\n for (let i = 1; i < all.length; i++) {\n const a = all[i - 1]!\n const b = all[i]!\n if (vertical) {\n const y = (a.y + b.y) / 2\n out.push({ x: a.x, y }, { x: b.x, y }, b)\n } else {\n const x = (a.x + b.x) / 2\n out.push({ x, y: a.y }, { x, y: b.y }, b)\n }\n }\n return { path: rounded(out), label: middle(points) }\n}\n"],"mappings":";;AAmCA,SAAgB,eACd,MACoB;CACpB,OAAO;AACT;AAEA,IAAM,YAAqC;CACzC,MAAM;EAAE,GAAG;EAAI,GAAG;CAAE;CACpB,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;CACpB,KAAK;EAAE,GAAG;EAAG,GAAG;CAAG;CACnB,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;AACvB;AAEA,IAAM,SAAS,UAAkB,KAAK,MAAM,QAAQ,GAAG,IAAI;AAC3D,IAAM,OAAO,MAAa,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC;AACpD,IAAM,cAAc,SAAmB,SAAS,SAAS,SAAS;;;;;;;AAQlE,SAAS,eAAe,MAAkB,IAAgB,MAAM,IAAI;CAClE,MAAM,IAAI,UAAU,KAAK;CACzB,MAAM,IAAI,UAAU,GAAG;CACvB,MAAM,QAAQ,QAAe,KAAK,IAAI,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,CAAC;CAC3E,MAAM,OAAO,KAAK,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC;CACtC,MAAM,OAAO,KAAK,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC;CACtC,OAAO,CACL;EAAE,GAAG,KAAK,IAAI,EAAE,IAAI;EAAM,GAAG,KAAK,IAAI,EAAE,IAAI;CAAK,GACjD;EAAE,GAAG,GAAG,IAAI,EAAE,IAAI;EAAM,GAAG,GAAG,IAAI,EAAE,IAAI;CAAK,CAC/C;AACF;AAEA,SAAgB,WAAW,MAAa,UA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;EACpC,OAAO;GAEL,MAAM,SAAS,GAAG,IAAI;IAAE,GAAG,GAAG;IAAG,GAAG,GAAG;GAAE,IAAI;IAAE,GAAG,GAAG;IAAG,GAAG,GAAG;GAAE;GAChE,SAAS;IAAC;IAAG;IAAI;IAAQ;IAAI;GAAC;GAC9B,QAAQ;EACV;EACA,OAAO;GAAE,MAAM,QAAQ,OAAO,IAAI,IAAI,CAAC;GAAG,OAAO,KAAK,KAAK;GAAG;EAAO;CACvE;AACF,CAAC;;;;;AAMD,SAAS,YAAY,QAAoB,QAAoB,QAA4B;CACvF,MAAM,WAAW,WAAW,OAAO,IAAI;CACvC,MAAM,MAAM;EAAC;EAAQ,GAAG;EAAQ;CAAM;CACtC,MAAM,MAAe,CAAC,MAAM;CAC5B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EACnC,MAAM,IAAI,IAAI,IAAI;EAClB,MAAM,IAAI,IAAI;EACd,IAAI,UAAU;GACZ,MAAM,KAAK,EAAE,IAAI,EAAE,KAAK;GACxB,IAAI,KAAK;IAAE,GAAG,EAAE;IAAG;GAAE,GAAG;IAAE,GAAG,EAAE;IAAG;GAAE,GAAG,CAAC;EAC1C,OAAO;GACL,MAAM,KAAK,EAAE,IAAI,EAAE,KAAK;GACxB,IAAI,KAAK;IAAE;IAAG,GAAG,EAAE;GAAE,GAAG;IAAE;IAAG,GAAG,EAAE;GAAE,GAAG,CAAC;EAC1C;CACF;CACA,OAAO;EAAE,MAAM,QAAQ,GAAG;EAAG,OAAO,OAAO,MAAM;CAAE;AACrD"}
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","names":[],"sources":["../../src/core/extension.ts"],"sourcesContent":["import type { ContextMenuItem } from 'dou-ui'\nimport type { Component } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport type { FlowDrawContext } from '../export/context'\nimport type { FlowConnection, PortTypes } from './connect'\nimport type { EdgeTypeSpec } from './edge-types'\nimport type { FlowMenuTarget, FlowToolbarItem } from './menu'\nimport type { FlowDocument, FlowEdge, FlowNode, Point } from './model'\nimport type { NodeTypeSpec } from './node-types'\nimport type { FlowTransaction } from './transaction'\n\n/** What an extension's hooks receive; the same as `useFlowEditor()`. */\nexport type FlowExtensionContext = FlowEditorContext\n\n/**\n * A key handler: return `false` to let the key through to the next handler\n * and the editor's own keys; anything else means it was handled.\n */\nexport type FlowKeyHandler = (event: KeyboardEvent) => boolean | void\n\n/** An undo history that replaces the editor's own, e.g. one that only undoes this user's changes. */\nexport interface FlowHistoryHandler {\n /** `false` when there is nothing to undo. */\n undo: () => boolean\n redo: () => boolean\n canUndo: () => boolean\n canRedo: () => boolean\n}\n\n/** A press on the editor that an extension may take over, e.g. a drawing tool. */\nexport interface FlowPress {\n /** Where it was pressed, in canvas coordinates. */\n point: Point\n /** The node under the pointer, if any. */\n node: FlowNode | null\n event: PointerEvent\n}\n\n/** Follows a press an extension took over, until the pointer is let go. */\nexport interface FlowPressHandler {\n move?: (point: Point, event: PointerEvent) => void\n end?: (point: Point, event: PointerEvent) => void\n /** Escape, a second finger, or the browser took the pointer. */\n cancel?: () => void\n}\n\n/**\n * A piece of the editor: node types, port types, connection rules, keys and\n * extra layers. The default node type comes as an extension too (see\n * `flowKit`), so a third-party extension stands on equal footing with it.\n */\nexport interface FlowExtension {\n name: string\n /** Higher runs first: its keys and rules are asked before others. Defaults to 100. */\n priority?: number\n nodeTypes?: NodeTypeSpec<any>[]\n /** Edge types, used by `edge.type`; `flowKit` brings `bezier`, `step` and `straight`. */\n edgeTypes?: EdgeTypeSpec<any>[]\n /**\n * The edge type of edges without a `type`, unless the editor's `edge-type`\n * prop says otherwise. The last extension that sets it wins.\n */\n edgeType?: string\n /** Looks and connection rules of port types; see the `portTypes` prop. */\n portTypes?: PortTypes\n /**\n * A connection rule, asked after the built-in ones. Return `false` to\n * refuse, or a sentence saying why. Called for every port while dragging.\n */\n canConnect?: (connection: FlowConnection, doc: FlowDocument) => boolean | string\n /** Keys, written as in `useHotkey` (e.g. `mod+g`, `shift+t`), while the canvas has focus. */\n keymap?: (context: FlowExtensionContext) => Record<string, FlowKeyHandler>\n /** Rewrites nodes and edges before they are pasted, e.g. to reset run state. */\n transformPaste?: (data: FlowDocument, context: FlowExtensionContext) => FlowDocument\n /**\n * Components drawn in canvas coordinates: `below` under the edges, `above`\n * over the nodes. They move and zoom with the canvas.\n */\n layers?: { below?: Component[]; above?: Component[] }\n /**\n * What `layers.above` shows, for `exportSVG` and `exportPNG`: SVG markup\n * in canvas coordinates, drawn over the nodes. `nodes` are the ones in the\n * picture; `draw.width` and `draw.height` are the picture's size.\n */\n drawLayer?: (context: FlowExtensionContext, draw: FlowDrawContext, nodes: FlowNode[]) => string\n /**\n * Components drawn over the editor in screen space, e.g. a panel or a\n * popup. They can call `useFlowEditor()`.\n */\n overlays?: Component[]\n /**\n * Items for the menu opened by a right click, a long press on the empty\n * canvas, or the context menu key. Extensions' items follow each other\n * in priority order; an empty list leaves them out.\n */\n contextMenu?: (context: FlowExtensionContext, target: FlowMenuTarget) => ContextMenuItem[]\n /** Buttons for the toolbar that floats above the selected nodes. */\n toolbarItems?: (context: FlowExtensionContext, nodes: FlowNode[]) => FlowToolbarItem[]\n /** Buttons for the toolbar that floats above the selected edges, when no node is selected. */\n edgeToolbarItems?: (context: FlowExtensionContext, edges: FlowEdge[]) => FlowToolbarItem[]\n /**\n * Asked first when the canvas or a node is pressed with the main button or\n * one finger, in priority order. Return handlers to take the press over;\n * the editor then doesn't select, drag or pan for it.\n */\n press?: (context: FlowExtensionContext, press: FlowPress) => FlowPressHandler | void\n /** Runs once the editor is mounted. Return a function to run when it unmounts. */\n setup?: (context: FlowExtensionContext) => void | (() => void)\n /**\n * Sees every change before it reaches the document, in priority order,\n * and may add steps to it. Undo and redo come through here too.\n */\n transaction?: (tr: FlowTransaction, context: FlowExtensionContext) => void\n /** Replaces the editor's undo history; the first extension that has one wins. */\n history?: (context: FlowExtensionContext) => FlowHistoryHandler\n}\n\n/** Declares an extension; only gives it a type. */\nexport function defineFlowExtension(extension: FlowExtension): FlowExtension {\n return extension\n}\n\n/** Everything the extensions contribute, gathered once per list. */\nexport interface ResolvedFlowExtensions {\n extensions: FlowExtension[]\n nodeTypes: Map<string, NodeTypeSpec>\n edgeTypes: Map<string, EdgeTypeSpec>\n edgeType: string | undefined\n portTypes: PortTypes\n rules: NonNullable<FlowExtension['canConnect']>[]\n keymaps: NonNullable<FlowExtension['keymap']>[]\n pasteTransforms: NonNullable<FlowExtension['transformPaste']>[]\n below: Component[]\n above: Component[]\n overlays: Component[]\n menus: NonNullable<FlowExtension['contextMenu']>[]\n toolbars: NonNullable<FlowExtension['toolbarItems']>[]\n edgeToolbars: NonNullable<FlowExtension['edgeToolbarItems']>[]\n drawLayers: NonNullable<FlowExtension['drawLayer']>[]\n setups: NonNullable<FlowExtension['setup']>[]\n transactions: NonNullable<FlowExtension['transaction']>[]\n history: FlowExtension['history']\n presses: NonNullable<FlowExtension['press']>[]\n}\n\ntype ExtensionList = readonly (FlowExtension | readonly FlowExtension[])[]\n\nfunction flatten(list: ExtensionList): FlowExtension[] {\n const out: FlowExtension[] = []\n for (const item of list) {\n if (Array.isArray(item)) out.push(...flatten(item))\n else out.push(item as FlowExtension)\n }\n return out\n}\n\n/** Sorts the extensions by priority and collects what they add. */\nexport function resolveFlowExtensions(list: ExtensionList): ResolvedFlowExtensions {\n const extensions = flatten(list)\n .map((extension, index) => ({ extension, index }))\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a fresh array\n .sort(\n (a, b) => (b.extension.priority ?? 100) - (a.extension.priority ?? 100) || a.index - b.index,\n )\n .map((entry) => entry.extension)\n\n const names = new Set<string>()\n const nodeTypes = new Map<string, NodeTypeSpec>()\n const edgeTypes = new Map<string, EdgeTypeSpec>()\n const portTypes: PortTypes = {}\n for (const extension of extensions) {\n if (names.has(extension.name))\n throw new Error(`[@dou-ui/flow] the extension \"${extension.name}\" is added twice`)\n names.add(extension.name)\n for (const spec of extension.nodeTypes ?? []) {\n if (nodeTypes.has(spec.type))\n throw new Error(\n `[@dou-ui/flow] node type \"${spec.type}\" from \"${extension.name}\" is already defined`,\n )\n nodeTypes.set(spec.type, spec)\n }\n for (const spec of extension.edgeTypes ?? []) {\n if (edgeTypes.has(spec.type))\n throw new Error(\n `[@dou-ui/flow] edge type \"${spec.type}\" from \"${extension.name}\" is already defined`,\n )\n edgeTypes.set(spec.type, spec)\n }\n for (const [name, spec] of Object.entries(extension.portTypes ?? {})) {\n if (name in portTypes)\n throw new Error(\n `[@dou-ui/flow] port type \"${name}\" from \"${extension.name}\" is already defined`,\n )\n portTypes[name] = spec\n }\n }\n\n const pick = <K extends keyof FlowExtension>(key: K) =>\n extensions.flatMap((e) => (e[key] ? [e[key]] : [])) as NonNullable<FlowExtension[K]>[]\n\n return {\n extensions,\n nodeTypes,\n edgeTypes,\n edgeType: extensions.reduce<string | undefined>((type, e) => e.edgeType ?? type, undefined),\n portTypes,\n rules: pick('canConnect'),\n keymaps: pick('keymap'),\n pasteTransforms: pick('transformPaste'),\n below: extensions.flatMap((e) => e.layers?.below ?? []),\n above: extensions.flatMap((e) => e.layers?.above ?? []),\n overlays: extensions.flatMap((e) => e.overlays ?? []),\n menus: pick('contextMenu'),\n presses: pick('press'),\n toolbars: pick('toolbarItems'),\n edgeToolbars: pick('edgeToolbarItems'),\n drawLayers: pick('drawLayer'),\n setups: pick('setup'),\n transactions: pick('transaction'),\n history: extensions.find((e) => e.history)?.history,\n }\n}\n"],"mappings":";;AAsHA,SAAgB,oBAAoB,WAAyC;CAC3E,OAAO;AACT;AA2BA,SAAS,QAAQ,MAAsC;CACrD,MAAM,MAAuB,CAAC;CAC9B,KAAK,MAAM,QAAQ,MACjB,IAAI,MAAM,QAAQ,IAAI,GAAG,IAAI,KAAK,GAAG,QAAQ,IAAI,CAAC;MAC7C,IAAI,KAAK,IAAqB;CAErC,OAAO;AACT;;AAGA,SAAgB,sBAAsB,MAA6C;CACjF,MAAM,aAAa,QAAQ,IAAI,CAAC,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AS;EAC1F;EACA,OAAO,KAAK,YAAY;EACxB,SAAS,KAAK,QAAQ;EACtB,iBAAiB,KAAK,gBAAgB;EACtC,OAAO,WAAW,SAAS,MAAM,EAAE,QAAQ,SAAS,CAAC,CAAC;EACtD,OAAO,WAAW,SAAS,MAAM,EAAE,QAAQ,SAAS,CAAC,CAAC;EACtD,UAAU,WAAW,SAAS,MAAM,EAAE,YAAY,CAAC,CAAC;EACpD,OAAO,KAAK,aAAa;EACzB,SAAS,KAAK,OAAO;EACrB,UAAU,KAAK,cAAc;EAC7B,cAAc,KAAK,kBAAkB;EACrC,YAAY,KAAK,WAAW;EAC5B,QAAQ,KAAK,OAAO;EACpB,cAAc,KAAK,aAAa;EAChC,SAAS,WAAW,MAAM,MAAM,EAAE,OAAO,CAAC,EAAE;CAC9C;AACF"}
1
+ {"version":3,"file":"extension.js","names":[],"sources":["../../src/core/extension.ts"],"sourcesContent":["import type { ContextMenuItem } from 'dou-ui'\nimport type { Component } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport type { FlowDrawContext } from '../export/context'\nimport type { FlowConnection, PortTypes } from './connect'\nimport type { EdgeTypeSpec } from './edge-types'\nimport type { FlowMenuTarget, FlowToolbarItem } from './menu'\nimport type { FlowDocument, FlowEdge, FlowNode, Point } from './model'\nimport type { NodeTypeSpec } from './node-types'\nimport type { FlowTransaction } from './transaction'\n\n/** What an extension's hooks receive; the same as `useFlowEditor()`. */\nexport type FlowExtensionContext = FlowEditorContext\n\n/**\n * A key handler: return `false` to let the key through to the next handler\n * and the editor's own keys; anything else means it was handled.\n */\nexport type FlowKeyHandler = (event: KeyboardEvent) => boolean | void\n\n/** An undo history that replaces the editor's own, e.g. one that only undoes this user's changes. */\nexport interface FlowHistoryHandler {\n /** `false` when there is nothing to undo. */\n undo: () => boolean\n redo: () => boolean\n canUndo: () => boolean\n canRedo: () => boolean\n}\n\n/** A press on the editor that an extension may take over, e.g. a drawing tool. */\nexport interface FlowPress {\n /** Where it was pressed, in canvas coordinates. */\n point: Point\n /** The node under the pointer, if any. */\n node: FlowNode | null\n event: PointerEvent\n}\n\n/** Follows a press an extension took over, until the pointer is let go. */\nexport interface FlowPressHandler {\n move?: (point: Point, event: PointerEvent) => void\n end?: (point: Point, event: PointerEvent) => void\n /** Escape, a second finger, or the browser took the pointer. */\n cancel?: () => void\n}\n\n/**\n * A piece of the editor: node types, port types, connection rules, keys and\n * extra layers. The default node type comes as an extension too (see\n * `flowKit`), so a third-party extension stands on equal footing with it.\n */\nexport interface FlowExtension {\n name: string\n /** Higher runs first: its keys and rules are asked before others. Defaults to 100. */\n priority?: number\n nodeTypes?: NodeTypeSpec<any>[]\n /** Edge types, used by `edge.type`; `flowKit` brings `bezier`, `step` and `straight`. */\n edgeTypes?: EdgeTypeSpec<any>[]\n /**\n * The edge type of edges without a `type`, unless the editor's `edge-type`\n * prop says otherwise. The last extension that sets it wins.\n */\n edgeType?: string\n /** Looks and connection rules of port types; see the `portTypes` prop. */\n portTypes?: PortTypes\n /**\n * A connection rule, asked after the built-in ones. Return `false` to\n * refuse, or a sentence saying why. Called for every port while dragging.\n */\n canConnect?: (connection: FlowConnection, doc: FlowDocument) => boolean | string\n /** Keys, written as in `useHotkey` (e.g. `mod+g`, `shift+t`), while the canvas has focus. */\n keymap?: (context: FlowExtensionContext) => Record<string, FlowKeyHandler>\n /** Rewrites nodes and edges before they are pasted, e.g. to reset run state. */\n transformPaste?: (data: FlowDocument, context: FlowExtensionContext) => FlowDocument\n /**\n * Components drawn in canvas coordinates: `below` under the edges, `above`\n * over the nodes. They move and zoom with the canvas.\n */\n layers?: { below?: Component[]; above?: Component[] }\n /**\n * What `layers.above` shows, for `exportSVG` and `exportPNG`: SVG markup\n * in canvas coordinates, drawn over the nodes. `nodes` are the ones in the\n * picture; `draw.width` and `draw.height` are the picture's size.\n */\n drawLayer?: (context: FlowExtensionContext, draw: FlowDrawContext, nodes: FlowNode[]) => string\n /**\n * Components drawn over the editor in screen space, e.g. a panel or a\n * popup. They can call `useFlowEditor()`.\n */\n overlays?: Component[]\n /**\n * Items for the menu opened by a right click, a long press on the empty\n * canvas, or the context menu key. Extensions' items follow each other\n * in priority order; an empty list leaves them out.\n */\n contextMenu?: (context: FlowExtensionContext, target: FlowMenuTarget) => ContextMenuItem[]\n /** Buttons for the toolbar that floats above the selected nodes. */\n toolbarItems?: (context: FlowExtensionContext, nodes: FlowNode[]) => FlowToolbarItem[]\n /** Buttons for the toolbar that floats above the selected edges, when no node is selected. */\n edgeToolbarItems?: (context: FlowExtensionContext, edges: FlowEdge[]) => FlowToolbarItem[]\n /**\n * Asked first when the canvas or a node is pressed with the main button or\n * one finger, in priority order. Return handlers to take the press over;\n * the editor then doesn't select, drag or pan for it. Asked while\n * read-only too: check `context.readonly` before changing the document.\n */\n press?: (context: FlowExtensionContext, press: FlowPress) => FlowPressHandler | void\n /** Runs once the editor is mounted. Return a function to run when it unmounts. */\n setup?: (context: FlowExtensionContext) => void | (() => void)\n /**\n * Sees every change before it reaches the document, in priority order,\n * and may add steps to it. Undo and redo come through here too.\n */\n transaction?: (tr: FlowTransaction, context: FlowExtensionContext) => void\n /** Replaces the editor's undo history; the first extension that has one wins. */\n history?: (context: FlowExtensionContext) => FlowHistoryHandler\n}\n\n/** Declares an extension; only gives it a type. */\nexport function defineFlowExtension(extension: FlowExtension): FlowExtension {\n return extension\n}\n\n/** Everything the extensions contribute, gathered once per list. */\nexport interface ResolvedFlowExtensions {\n extensions: FlowExtension[]\n nodeTypes: Map<string, NodeTypeSpec>\n edgeTypes: Map<string, EdgeTypeSpec>\n edgeType: string | undefined\n portTypes: PortTypes\n rules: NonNullable<FlowExtension['canConnect']>[]\n keymaps: NonNullable<FlowExtension['keymap']>[]\n pasteTransforms: NonNullable<FlowExtension['transformPaste']>[]\n below: Component[]\n above: Component[]\n overlays: Component[]\n menus: NonNullable<FlowExtension['contextMenu']>[]\n toolbars: NonNullable<FlowExtension['toolbarItems']>[]\n edgeToolbars: NonNullable<FlowExtension['edgeToolbarItems']>[]\n drawLayers: NonNullable<FlowExtension['drawLayer']>[]\n setups: NonNullable<FlowExtension['setup']>[]\n transactions: NonNullable<FlowExtension['transaction']>[]\n history: FlowExtension['history']\n presses: NonNullable<FlowExtension['press']>[]\n}\n\ntype ExtensionList = readonly (FlowExtension | readonly FlowExtension[])[]\n\nfunction flatten(list: ExtensionList): FlowExtension[] {\n const out: FlowExtension[] = []\n for (const item of list) {\n if (Array.isArray(item)) out.push(...flatten(item))\n else out.push(item as FlowExtension)\n }\n return out\n}\n\n/** Sorts the extensions by priority and collects what they add. */\nexport function resolveFlowExtensions(list: ExtensionList): ResolvedFlowExtensions {\n const extensions = flatten(list)\n .map((extension, index) => ({ extension, index }))\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a fresh array\n .sort(\n (a, b) => (b.extension.priority ?? 100) - (a.extension.priority ?? 100) || a.index - b.index,\n )\n .map((entry) => entry.extension)\n\n const names = new Set<string>()\n const nodeTypes = new Map<string, NodeTypeSpec>()\n const edgeTypes = new Map<string, EdgeTypeSpec>()\n const portTypes: PortTypes = {}\n for (const extension of extensions) {\n if (names.has(extension.name))\n throw new Error(`[@dou-ui/flow] the extension \"${extension.name}\" is added twice`)\n names.add(extension.name)\n for (const spec of extension.nodeTypes ?? []) {\n if (nodeTypes.has(spec.type))\n throw new Error(\n `[@dou-ui/flow] node type \"${spec.type}\" from \"${extension.name}\" is already defined`,\n )\n nodeTypes.set(spec.type, spec)\n }\n for (const spec of extension.edgeTypes ?? []) {\n if (edgeTypes.has(spec.type))\n throw new Error(\n `[@dou-ui/flow] edge type \"${spec.type}\" from \"${extension.name}\" is already defined`,\n )\n edgeTypes.set(spec.type, spec)\n }\n for (const [name, spec] of Object.entries(extension.portTypes ?? {})) {\n if (name in portTypes)\n throw new Error(\n `[@dou-ui/flow] port type \"${name}\" from \"${extension.name}\" is already defined`,\n )\n portTypes[name] = spec\n }\n }\n\n const pick = <K extends keyof FlowExtension>(key: K) =>\n extensions.flatMap((e) => (e[key] ? [e[key]] : [])) as NonNullable<FlowExtension[K]>[]\n\n return {\n extensions,\n nodeTypes,\n edgeTypes,\n edgeType: extensions.reduce<string | undefined>((type, e) => e.edgeType ?? type, undefined),\n portTypes,\n rules: pick('canConnect'),\n keymaps: pick('keymap'),\n pasteTransforms: pick('transformPaste'),\n below: extensions.flatMap((e) => e.layers?.below ?? []),\n above: extensions.flatMap((e) => e.layers?.above ?? []),\n overlays: extensions.flatMap((e) => e.overlays ?? []),\n menus: pick('contextMenu'),\n presses: pick('press'),\n toolbars: pick('toolbarItems'),\n edgeToolbars: pick('edgeToolbarItems'),\n drawLayers: pick('drawLayer'),\n setups: pick('setup'),\n transactions: pick('transaction'),\n history: extensions.find((e) => e.history)?.history,\n }\n}\n"],"mappings":";;AAuHA,SAAgB,oBAAoB,WAAyC;CAC3E,OAAO;AACT;AA2BA,SAAS,QAAQ,MAAsC;CACrD,MAAM,MAAuB,CAAC;CAC9B,KAAK,MAAM,QAAQ,MACjB,IAAI,MAAM,QAAQ,IAAI,GAAG,IAAI,KAAK,GAAG,QAAQ,IAAI,CAAC;MAC7C,IAAI,KAAK,IAAqB;CAErC,OAAO;AACT;;AAGA,SAAgB,sBAAsB,MAA6C;CACjF,MAAM,aAAa,QAAQ,IAAI,CAAC,CAC7B,KAAK,WAAW,WAAW;EAAE;EAAW;CAAM,EAAE,CAAC,CAEjD,MACE,GAAG,OAAO,EAAE,UAAU,YAAY,QAAQ,EAAE,UAAU,YAAY,QAAQ,EAAE,QAAQ,EAAE,KACzF,CAAC,CACA,KAAK,UAAU,MAAM,SAAS;CAEjC,MAAM,wBAAQ,IAAI,IAAY;CAC9B,MAAM,4BAAY,IAAI,IAA0B;CAChD,MAAM,4BAAY,IAAI,IAA0B;CAChD,MAAM,YAAuB,CAAC;CAC9B,KAAK,MAAM,aAAa,YAAY;EAClC,IAAI,MAAM,IAAI,UAAU,IAAI,GAC1B,MAAM,IAAI,MAAM,iCAAiC,UAAU,KAAK,iBAAiB;EACnF,MAAM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