@dou-ui/flow 0.1.0-alpha.3 → 0.1.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collaboration/index.js +114 -6
- package/dist/collaboration/index.js.map +1 -1
- package/dist/comments.js +257 -0
- package/dist/comments.js.map +1 -0
- package/dist/components/default-node.js.map +1 -1
- package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/flow-comments.js +6 -0
- package/dist/components/flow-comments.js.map +1 -0
- package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +218 -0
- package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/flow-port.js.map +1 -1
- package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js +7 -42
- package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/flow-toolbar.js.map +1 -1
- package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js +300 -9
- package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/node-view.js.map +1 -1
- package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/port-view.js +6 -0
- package/dist/components/port-view.js.map +1 -0
- package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js +60 -0
- package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/context.js.map +1 -1
- package/dist/core/extension.js.map +1 -1
- package/dist/core/history.js +26 -0
- package/dist/core/history.js.map +1 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/node-types.js +39 -1
- package/dist/core/node-types.js.map +1 -1
- package/dist/core/transaction.js +5 -4
- package/dist/core/transaction.js.map +1 -1
- package/dist/document.js +1 -1
- package/dist/export/color.js +49 -6
- package/dist/export/color.js.map +1 -1
- package/dist/export/context.js +16 -9
- package/dist/export/context.js.map +1 -1
- package/dist/export/draw.js +6 -5
- package/dist/export/draw.js.map +1 -1
- package/dist/export/render.js +78 -0
- package/dist/export/render.js.map +1 -0
- package/dist/flow-editor.js.map +1 -1
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +757 -129
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/kit.js +1 -1
- package/dist/locale.js +102 -3
- package/dist/locale.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +2 -1
- package/dist/types/collaboration/index.d.ts +32 -4
- package/dist/types/comments.d.ts +73 -0
- package/dist/types/components/flow-comments.vue.d.ts +35 -0
- package/dist/types/components/flow-port.vue.d.ts +8 -2
- package/dist/types/components/port-view.vue.d.ts +10 -0
- package/dist/types/components/port.d.ts +2 -2
- package/dist/types/context.d.ts +48 -1
- package/dist/types/core/extension.d.ts +9 -1
- package/dist/types/core/history.d.ts +10 -0
- package/dist/types/core/menu.d.ts +60 -0
- package/dist/types/core/model.d.ts +22 -0
- package/dist/types/core/node-types.d.ts +18 -2
- package/dist/types/core/transaction.d.ts +2 -1
- package/dist/types/export/color.d.ts +6 -1
- package/dist/types/export/render.d.ts +27 -0
- package/dist/types/flow-editor.vue.d.ts +11 -1
- package/dist/types/index.d.ts +36 -7
- package/dist/types/locale.d.ts +27 -1
- package/dist/types/whiteboard/board-node.vue.d.ts +5 -0
- package/dist/types/whiteboard/colors.d.ts +36 -0
- package/dist/types/whiteboard/index.d.ts +2 -2
- package/dist/types/whiteboard/model.d.ts +24 -14
- package/dist/types/whiteboard/state.d.ts +2 -0
- package/dist/types/whiteboard/toolbar.d.ts +46 -0
- package/dist/whiteboard/board-node.js.map +1 -1
- package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +76 -20
- package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/whiteboard/colors.js +84 -0
- package/dist/whiteboard/colors.js.map +1 -0
- package/dist/whiteboard/connector.js +47 -13
- package/dist/whiteboard/connector.js.map +1 -1
- package/dist/whiteboard/draw.js +26 -9
- package/dist/whiteboard/draw.js.map +1 -1
- package/dist/whiteboard/index.js +2 -1
- package/dist/whiteboard/kit.js +65 -8
- package/dist/whiteboard/kit.js.map +1 -1
- package/dist/whiteboard/model.js +5 -31
- package/dist/whiteboard/model.js.map +1 -1
- package/dist/whiteboard/state.js +6 -1
- package/dist/whiteboard/state.js.map +1 -1
- package/dist/whiteboard/toolbar.js +296 -0
- package/dist/whiteboard/toolbar.js.map +1 -0
- package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
- package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
- package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { flowEditorKey, flowNodeKey } from "../context.js";
|
|
2
|
+
import { portSide } from "../core/node-types.js";
|
|
3
|
+
import { computed, createCommentVNode, createElementBlock, createElementVNode, defineComponent, inject, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, useTemplateRef } from "vue";
|
|
4
|
+
// src/components/port-view.vue?vue&type=script&setup=true&lang.ts
|
|
5
|
+
var _hoisted_1 = ["data-port", "data-visible"];
|
|
6
|
+
var _hoisted_2 = {
|
|
7
|
+
key: 0,
|
|
8
|
+
viewBox: "0 0 10 10"
|
|
9
|
+
};
|
|
10
|
+
var port_view_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
11
|
+
name: "DouFlowPortView",
|
|
12
|
+
__name: "port-view",
|
|
13
|
+
props: {
|
|
14
|
+
id: {},
|
|
15
|
+
visible: {},
|
|
16
|
+
auto: { type: Boolean }
|
|
17
|
+
},
|
|
18
|
+
setup(__props) {
|
|
19
|
+
const props = __props;
|
|
20
|
+
const node = inject(flowNodeKey, null);
|
|
21
|
+
const el = useTemplateRef("el");
|
|
22
|
+
const port = computed(() => node?.ports.value.find((p) => p.id === props.id));
|
|
23
|
+
const side = computed(() => port.value ? portSide(port.value) : "left");
|
|
24
|
+
const connected = computed(() => !!node?.connected.value.has(props.id));
|
|
25
|
+
const editor = inject(flowEditorKey, null);
|
|
26
|
+
const type = computed(() => port.value ? editor?.portTypeOf(port.value) : void 0);
|
|
27
|
+
const shape = computed(() => type.value?.shape ?? "circle");
|
|
28
|
+
const color = computed(() => editor?.colorOf(type.value));
|
|
29
|
+
const visible = computed(() => props.visible ?? port.value?.visible ?? "always");
|
|
30
|
+
const states = computed(() => node?.portStates.value);
|
|
31
|
+
const state = computed(() => states.value?.get(props.id));
|
|
32
|
+
onMounted(() => {
|
|
33
|
+
if (el.value) node?.registerPort(props.id, el.value, props.auto);
|
|
34
|
+
});
|
|
35
|
+
onBeforeUnmount(() => node?.unregisterPort(props.id, props.auto));
|
|
36
|
+
return (_ctx, _cache) => {
|
|
37
|
+
return openBlock(), createElementBlock("span", {
|
|
38
|
+
ref_key: "el",
|
|
39
|
+
ref: el,
|
|
40
|
+
class: normalizeClass(["dou-flow-port", [
|
|
41
|
+
`is-${side.value}`,
|
|
42
|
+
`is-${port.value?.kind ?? "input"}`,
|
|
43
|
+
`is-${shape.value}`,
|
|
44
|
+
state.value && `is-${state.value}`,
|
|
45
|
+
{
|
|
46
|
+
"is-connected": connected.value,
|
|
47
|
+
"is-unavailable": states.value && !state.value
|
|
48
|
+
}
|
|
49
|
+
]]),
|
|
50
|
+
style: normalizeStyle(color.value ? { "--dou-flow-port-color": color.value } : void 0),
|
|
51
|
+
"data-port": __props.id,
|
|
52
|
+
"data-visible": visible.value === "always" ? void 0 : visible.value,
|
|
53
|
+
"aria-hidden": "true"
|
|
54
|
+
}, [shape.value === "triangle" ? (openBlock(), createElementBlock("svg", _hoisted_2, [..._cache[0] || (_cache[0] = [createElementVNode("path", { d: "M2 1.5 8 5 2 8.5Z" }, null, -1)])])) : createCommentVNode("", true)], 14, _hoisted_1);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
export { port_view_vue_vue_type_script_setup_true_lang_default as default };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=port-view.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port-view.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_createElementVNode","_createCommentVNode"],"sources":["../../src/components/port-view.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, inject, onBeforeUnmount, onMounted, useTemplateRef } from 'vue'\nimport { flowEditorKey, flowNodeKey } from '../context'\nimport type { FlowPortVisible } from '../core/model'\nimport { portSide } from '../core/node-types'\n\ndefineOptions({ name: 'DouFlowPortView' })\n\n// The port itself. `<DouFlowPort>` is the public face; the editor places\n// the ports a node's component leaves out with `auto`.\nconst props = defineProps<{\n id: string\n visible?: FlowPortVisible\n /** placed by the editor, not by the node's component */\n auto?: boolean\n}>()\n\nconst node = inject(flowNodeKey, null)\n\nconst el = useTemplateRef<HTMLElement>('el')\nconst port = computed(() => node?.ports.value.find((p) => p.id === props.id))\nconst side = computed(() => (port.value ? portSide(port.value) : 'left'))\nconst connected = computed(() => !!node?.connected.value.has(props.id))\nconst editor = inject(flowEditorKey, null)\nconst type = computed(() => (port.value ? editor?.portTypeOf(port.value) : undefined))\nconst shape = computed(() => type.value?.shape ?? 'circle')\nconst color = computed(() => editor?.colorOf(type.value))\nconst visible = computed(() => props.visible ?? port.value?.visible ?? 'always')\nconst states = computed(() => node?.portStates.value)\nconst state = computed(() => states.value?.get(props.id))\n\nonMounted(() => {\n if (el.value) node?.registerPort(props.id, el.value, props.auto)\n})\nonBeforeUnmount(() => node?.unregisterPort(props.id, props.auto))\n</script>\n\n<template>\n <span\n ref=\"el\"\n class=\"dou-flow-port\"\n :class=\"[\n `is-${side}`,\n `is-${port?.kind ?? 'input'}`,\n `is-${shape}`,\n state && `is-${state}`,\n { 'is-connected': connected, 'is-unavailable': states && !state },\n ]\"\n :style=\"color ? { '--dou-flow-port-color': color } : undefined\"\n :data-port=\"id\"\n :data-visible=\"visible === 'always' ? undefined : visible\"\n aria-hidden=\"true\"\n >\n <svg v-if=\"shape === 'triangle'\" viewBox=\"0 0 10 10\">\n <path d=\"M2 1.5 8 5 2 8.5Z\" />\n </svg>\n </span>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;EAUA,MAAM,QAAQ;EAOd,MAAM,OAAO,OAAO,aAAa,IAAI;EAErC,MAAM,KAAK,eAA4B,IAAI;EAC3C,MAAM,OAAO,eAAe,MAAM,MAAM,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;EAC5E,MAAM,OAAO,eAAgB,KAAK,QAAQ,SAAS,KAAK,KAAK,IAAI,MAAO;EACxE,MAAM,YAAY,eAAe,CAAC,CAAC,MAAM,UAAU,MAAM,IAAI,MAAM,EAAE,CAAC;EACtE,MAAM,SAAS,OAAO,eAAe,IAAI;EACzC,MAAM,OAAO,eAAgB,KAAK,QAAQ,QAAQ,WAAW,KAAK,KAAK,IAAI,KAAA,CAAU;EACrF,MAAM,QAAQ,eAAe,KAAK,OAAO,SAAS,QAAQ;EAC1D,MAAM,QAAQ,eAAe,QAAQ,QAAQ,KAAK,KAAK,CAAC;EACxD,MAAM,UAAU,eAAe,MAAM,WAAW,KAAK,OAAO,WAAW,QAAQ;EAC/E,MAAM,SAAS,eAAe,MAAM,WAAW,KAAK;EACpD,MAAM,QAAQ,eAAe,OAAO,OAAO,IAAI,MAAM,EAAE,CAAC;EAExD,gBAAgB;GACd,IAAI,GAAG,OAAO,MAAM,aAAa,MAAM,IAAI,GAAG,OAAO,MAAM,IAAI;EACjE,CAAC;EACD,sBAAsB,MAAM,eAAe,MAAM,IAAI,MAAM,IAAI,CAAC;;GAI9D,OAAAA,UAAA,GAAAC,mBAkBO,QAAA;IAjBD,SAAA;IAAJ,KAAI;IACJ,OAAKC,eAAA,CAAC,iBAAe;KACC,MAAA,KAAA;KAAoB,MAAA,KAAA,OAAM,QAAI;KAA2B,MAAA,MAAA;KAAe,MAAA,SAAK,MAAU,MAAA;KAAiC;MAAA,gBAAA,UAAA;MAAS,kBAAoB,OAAA,SAAM,CAAK,MAAA;KAAK;;IAO1L,OAAKC,eAAE,MAAA,QAAK,EAAA,yBAA8B,MAAA,MAAK,IAAK,KAAA,CAAS;IAC7D,aAAW,QAAA;IACX,gBAAc,QAAA,UAAO,WAAgB,KAAA,IAAY,QAAA;IAClD,eAAY;G,IAED,MAAA,UAAK,cAAhBH,UAAA,GAAAC,mBAEM,OAFN,YAEM,CAAA,GAAA,OAAA,OAAA,OAAA,KAAA,CADJG,mBAA8B,QAAA,EAAxB,GAAE,oBAAmB,GAAA,MAAA,EAAA,C"}
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { ContextMenuItem } from 'dou-ui'\nimport type { FlowExportOptions, FlowImageOptions } from './export/draw'\nimport type { FlowTree } from './core/groups'\nimport { inject, type ComputedRef, type InjectionKey, type Ref, type ShallowRef } from 'vue'\nimport type { FlowMessages, FlowMessagesOverride } from './locale'\nimport type {\n FlowData,\n FlowDocument,\n FlowEndpoint,\n FlowNode,\n FlowPortSpec,\n FlowSelection,\n FlowViewport,\n Point,\n PortSide,\n Rect,\n} from './core/model'\nimport type { FlowConnection, PortTypes, PortTypeSpec } from './core/connect'\nimport type { EdgeTypeSpec } from './core/edge-types'\nimport type { FlowExtension } from './core/extension'\nimport type { FlowMenuTarget } from './core/menu'\nimport type { NodeTypeSpec } from './core/node-types'\nimport type { FlowTransaction, FlowTransactionMeta } from './core/transaction'\n\nexport type FlowPanelPlacement = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n\nexport interface FlowControlsProps {\n /** Corner of the editor to sit in. */\n placement?: FlowPanelPlacement\n /** Show undo and redo. */\n history?: boolean\n /** Show the tidy button, which lays the nodes out along their edges. */\n tidy?: boolean\n}\n\nexport interface FlowMinimapProps {\n /** Corner of the editor to sit in. */\n placement?: FlowPanelPlacement\n /** Size of the map in px. */\n width?: number\n height?: number\n}\n\n/** What the find panel looks for: text in the nodes' names. */\nexport interface FlowSearchQuery {\n search: string\n /** Tell capital letters from small ones. */\n caseSensitive?: boolean\n}\n\nexport interface FlowEditorProps {\n /**\n * What the editor is made of: node types, port types, rules, keys and\n * layers. `flowKit()` by default.\n */\n extensions?: (FlowExtension | FlowExtension[])[]\n /** Node types besides the extensions'; they win over an extension's type of the same name. */\n nodeTypes?: NodeTypeSpec<any>[]\n /** Edge types besides the extensions'; they win over an extension's type of the same name. */\n edgeTypes?: EdgeTypeSpec<any>[]\n /** The type of edges without `type`, new ones included. `bezier` by default. */\n edgeType?: string\n /**\n * Below this zoom nodes are drawn as plain boxes with their names, which\n * keeps a large flow quick; see the `simple` slot. `0` never does. `0.4` by default.\n */\n simpleZoom?: number\n /** Grid step for snapping and arrow keys, in px. `0` turns snapping to the grid off. */\n grid?: number\n /** Line nodes up with their neighbours while dragging. */\n guides?: boolean\n minZoom?: number\n maxZoom?: number\n /**\n * Which way the flow runs: `horizontal` left to right, `vertical` top to\n * bottom. Tidying lays nodes out this way.\n */\n direction?: 'horizontal' | 'vertical'\n /** Fit all nodes into view once they are measured. */\n fitView?: boolean\n /**\n * The furthest `fit-view` zooms out, so text stays readable; a larger flow\n * starts at its top left and is panned to. `0` always fits everything.\n */\n fitMinZoom?: number\n /** View, select and pan, but not change anything. */\n readonly?: boolean\n /** The built-in find panel (`Ctrl/⌘+F`). Off, the keys are left to the page. On by default. */\n searchable?: boolean\n /** Scrolling pans the canvas; with Ctrl / ⌘ it zooms. Off, only Ctrl / ⌘ + scroll zooms. */\n panOnScroll?: boolean\n /** Looks and connection rules of port types, by the name used in `dataType`. */\n portTypes?: PortTypes\n /** Refuse edges that would close a cycle. */\n acyclic?: boolean\n /**\n * The last check before an edge is made. Return `false` to refuse it, or a\n * sentence saying why. Called for every port while an edge is dragged.\n */\n canConnect?: (connection: FlowConnection, doc: FlowDocument) => boolean | string\n /**\n * The hairline frame and rounded corners. Off, the canvas takes no\n * border at all, for a panel or page region that already has an edge.\n * On by default.\n */\n bordered?: boolean\n /** Accessible name of the canvas. */\n ariaLabel?: string\n /** Texts to change; only the ones given are replaced. */\n messages?: FlowMessagesOverride\n}\n\nexport interface FlowEditorEmits {\n /** Every change to the document, with its steps; `update:modelValue` follows. */\n transaction: [tr: FlowTransaction]\n /**\n * An extension's `transaction` hook cancelled a change; `tr.cancelReason`\n * says why, and the editor shows it and reads it out.\n */\n transactionCancel: [tr: FlowTransaction]\n nodeClick: [node: FlowNode, event: MouseEvent]\n nodeDblclick: [node: FlowNode, event: MouseEvent]\n nodeContextmenu: [node: FlowNode, event: MouseEvent]\n edgeClick: [edge: FlowDocument['edges'][number], event: MouseEvent]\n edgeContextmenu: [edge: FlowDocument['edges'][number], event: MouseEvent]\n /** Clicking the empty canvas; `point` is in canvas coordinates. */\n canvasClick: [point: Point, event: MouseEvent]\n /**\n * Right click or long press on the empty canvas. The context menu events\n * come before the editor's own menu; `event.preventDefault()` keeps it closed.\n */\n canvasContextmenu: [point: Point, event: MouseEvent]\n /** An edge was drawn, or moved to another port. */\n connect: [edge: FlowDocument['edges'][number]]\n /**\n * A new edge was dropped on empty canvas; `point` is where, in canvas\n * coordinates. The editor then offers the node types that can take the\n * edge; `event.preventDefault()` handles it yourself instead.\n */\n connectToCanvas: [from: Required<FlowEndpoint>, point: Point, event: MouseEvent]\n}\n\nexport interface FlowEditorExpose {\n /** Applies changes as one transaction, one undo step. */\n transact: (fn: (tr: FlowTransaction) => void, meta?: FlowTransactionMeta) => FlowTransaction\n undo: () => boolean\n redo: () => boolean\n readonly canUndo: boolean\n readonly canRedo: boolean\n /** Shows all nodes, or the given ones. */\n fit: (ids?: string[]) => void\n zoomTo: (zoom: number) => void\n zoomIn: () => void\n zoomOut: () => void\n /** Centers a node in view without changing the zoom. */\n centerNode: (id: string) => void\n /** Opens the find panel (`Ctrl/⌘+F`), with a query put in; `false` when `searchable` is off. */\n openSearch: (query?: Partial<FlowSearchQuery>) => boolean\n /** Closes the find panel; `false` when it was not open. */\n closeSearch: () => boolean\n /** The ids of the nodes whose names contain the search, in reading order. */\n findNodes: (query: FlowSearchQuery) => string[]\n /**\n * Moves the view like the user's pans do: no further than having the nodes\n * just leave it. `v-model:viewport` goes anywhere.\n */\n setViewport: (viewport: FlowViewport, animate?: boolean) => void\n /** Converts a point on screen (client coordinates) to canvas coordinates. */\n toCanvas: (point: Point) => Point\n /** A node's measured box in canvas coordinates. */\n getNodeRect: (id: string) => Rect | null\n /**\n * The flow as an SVG document, as it looks now: every node and edge, what\n * is in view, or the selected ones (it throws when nothing is selected). Colors are written as `rgb(…)`, `rgba(…)` or `#rrggbb`, so\n * vector editors read them; nodes are drawn by their type's `draw`.\n */\n exportSVG: (options?: FlowExportOptions) => string\n /** The flow as a PNG image, with images embedded where their address can be read. */\n exportPNG: (options?: FlowImageOptions) => Promise<Blob>\n /**\n * Lays nodes out in columns along their edges, as one undo step: the given\n * ones, the selection when two or more nodes are selected, or all.\n */\n tidy: (ids?: string[]) => void\n /**\n * Ids of edges whose ports no longer fit: a port is gone, or the types of\n * its two ends don't match any more. They are drawn red and dashed.\n */\n readonly staleEdges: string[]\n /** Removes the stale edges as one undo step; returns how many. */\n removeStaleEdges: () => number\n /**\n * Adds a node of a type with its defaults and selects it, as one undo\n * step; returns its id. See `FlowInsertOptions` for where it goes.\n */\n insertNode: (type: string, options?: FlowInsertOptions) => string | null\n /**\n * Starts dragging a new node of a type from `event`, a `pointerdown` on\n * any element on the page; letting go over the canvas adds it there, and\n * Escape cancels. The click that ends a drag is stopped. Returns `false`\n * when nothing was started.\n */\n startInsertDrag: (type: string, event: PointerEvent) => boolean\n /** Node types with a `palette` entry, in the order they were given. */\n readonly paletteTypes: NodeTypeSpec[]\n /** Selects an edge and opens the text field on its label. */\n editLabel: (id: string) => void\n /**\n * Puts nodes, the selected ones by default, into a new container of\n * `type` (`'group'` by default) drawn around them, as one undo step;\n * returns its id, or `null` when nothing was grouped.\n */\n groupNodes: (ids?: string[], type?: string) => string | null\n /** Removes a container and keeps the nodes inside, as one undo step. */\n ungroupNode: (id: string) => boolean\n /**\n * Takes nodes, the selected ones by default, out of their groups and puts\n * them just below, as one undo step; returns how many moved.\n */\n leaveGroup: (ids?: string[]) => number\n}\n\nexport interface FlowEditorSlots {\n /** Panels over the canvas, e.g. `DouFlowControls`. */\n default?: () => unknown\n /** What follows the pointer while a new node is dragged in. */\n ghost?: (props: { spec: NodeTypeSpec; over: boolean }) => unknown\n /** Replaces the list offered when an edge is dropped on the empty canvas. */\n quickAdd?: (props: {\n types: NodeTypeSpec[]\n choose: (type: string) => void\n close: () => void\n }) => unknown\n /** A node's content while zoomed out past `simple-zoom`; its name by default. */\n simple?: (props: { node: FlowNode }) => unknown\n}\n\nexport interface FlowInsertOptions {\n /**\n * Where the node goes, in canvas coordinates: its centre, or with `from`,\n * the port that takes the edge. Without it the node goes after the one\n * selected node, connected to it when it can be, or else in the middle\n * of the view; either way clear of other nodes.\n */\n at?: Point\n /** Connect the new node to this port, through the first port that can take it. */\n from?: Required<FlowEndpoint>\n /** Move focus to the new node, so keys such as undo act on it. `true` by default. */\n focus?: boolean\n /** Merged over the type's `defaults()`. */\n data?: FlowData\n /** The node's size instead of the type's `size`. */\n size?: { width?: number; height?: number }\n}\n\n/** Where a port's centre is, from its node's top left corner. */\nexport interface PortAnchor extends Point {\n side: PortSide\n}\n\nexport interface NodeMetrics {\n width: number\n height: number\n ports: Map<string, PortAnchor>\n}\n\n/** What `previewNode` can show changed: the box, and the data. */\nexport type FlowNodePreview = Partial<Pick<FlowNode, 'x' | 'y' | 'width' | 'height' | 'data'>>\n\n/** How a port shows while an edge is being drawn. */\nexport type PortState = 'active' | 'valid' | 'candidate' | 'refused'\n\nexport interface FlowEditorContext {\n doc: Ref<FlowDocument>\n selection: Ref<FlowSelection>\n viewport: Ref<FlowViewport>\n /** See `FlowEditorExpose.setViewport`; writing `viewport` goes anywhere. */\n setViewport: FlowEditorExpose['setViewport']\n readonly: ComputedRef<boolean>\n messages: ComputedRef<FlowMessages>\n minZoom: ComputedRef<number>\n maxZoom: ComputedRef<number>\n transact: FlowEditorExpose['transact']\n undo: () => boolean\n redo: () => boolean\n canUndo: Ref<boolean>\n canRedo: Ref<boolean>\n fit: FlowEditorExpose['fit']\n zoomTo: FlowEditorExpose['zoomTo']\n zoomIn: () => void\n zoomOut: () => void\n /** The registered type of a port, if any. */\n portTypeOf: (port: FlowPortSpec) => PortTypeSpec | undefined\n /** A port type's color as CSS. */\n colorOf: (spec: PortTypeSpec | undefined) => string | undefined\n getNodeRect: FlowEditorExpose['getNodeRect']\n exportSVG: FlowEditorExpose['exportSVG']\n exportPNG: FlowEditorExpose['exportPNG']\n tidy: FlowEditorExpose['tidy']\n centerNode: FlowEditorExpose['centerNode']\n /** Says `text` to screen readers. */\n announce: (text: string) => void\n /** The editor's size on screen, in px. */\n size: Ref<{ width: number; height: number }>\n selectedNodes: ComputedRef<Set<string>>\n insertNode: FlowEditorExpose['insertNode']\n /** Node types with a `palette` entry, in the order they were given. */\n paletteTypes: ComputedRef<NodeTypeSpec[]>\n startInsertDrag: FlowEditorExpose['startInsertDrag']\n editLabel: FlowEditorExpose['editLabel']\n groupNodes: FlowEditorExpose['groupNodes']\n ungroupNode: FlowEditorExpose['ungroupNode']\n leaveGroup: FlowEditorExpose['leaveGroup']\n /** Which node is inside which, from the nodes' `parent`. */\n tree: ComputedRef<FlowTree>\n /** Whether the node's type can hold other nodes. */\n isContainer: (node: FlowNode) => boolean\n /** How far the node is drawn turned about its centre, from its type's `rotation`. */\n nodeRotation: (id: string) => number\n /**\n * While nodes are moved or resized, or an edge is bent: the document\n * changes on every frame until the pointer is let go.\n */\n gesturing: ComputedRef<boolean>\n /**\n * Shows a node as if `patch` were applied, without changing the document:\n * its frame, ports, edges and `getNodeRect` all follow. For handles that\n * change the document once, when let go; `null` shows it as it is again,\n * and must be passed when the drag ends or is cancelled. `patch.data`\n * replaces the node's data, it is not merged. Only this editor shows it:\n * peers see the change once it is committed. A preview is dropped when\n * its node leaves the document.\n */\n previewNode: (id: string, patch: FlowNodePreview | null) => void\n /** The edge being drawn, as an SVG path in canvas coordinates. */\n connectingPath: ComputedRef<string | null>\n /** The editor's element. */\n root: Readonly<ShallowRef<HTMLElement | null>>\n /**\n * Opens the context menu for a target at a point on screen; `false` when\n * no extension has items for it. Pass the button that opens it as `from`:\n * the menu then opens below the button instead of at the point, or above\n * it when there is no room, and pressing the button again closes it.\n */\n openMenu: (target: FlowMenuTarget, client: Point, from?: Element) => boolean\n /** The items the context menu has for a target, as `openMenu` shows them. */\n menuItems: (target: FlowMenuTarget) => ContextMenuItem[]\n /**\n * Opens the editor's menu with these items, e.g. the choices behind a\n * toolbar button; `from` works as in `openMenu`.\n */\n showMenu: (\n items: ContextMenuItem[],\n client: Point,\n from?: Element,\n options?: { focusChecked?: boolean },\n ) => boolean\n /** The element that opened the menu, while it is open, e.g. to mark a button expanded. */\n menuFrom: Readonly<ShallowRef<Element | null>>\n toCanvas: (point: Point) => Point\n /** Copies the selected nodes to the clipboard; `false` when none are selected. */\n copy: () => boolean\n cut: () => boolean\n /** Pastes what was copied, at `at` (canvas coordinates) or next to the original. */\n paste: (at?: Point) => Promise<boolean>\n /** Adds a copy of the selected nodes next to them. */\n duplicate: () => void\n /** Deletes the selected nodes and edges, except locked nodes. */\n deleteSelection: () => void\n selectAll: () => void\n}\n\nexport const flowEditorKey: InjectionKey<FlowEditorContext> = Symbol('dou-flow-editor')\n\n/** The surrounding flow editor; for controls and panels placed in its default slot. */\nexport function useFlowEditor() {\n const context = inject(flowEditorKey, null)\n if (!context)\n throw new Error('[@dou-ui/flow] useFlowEditor() must be called inside <DouFlowEditor>')\n return context\n}\n\nexport interface FlowNodeContext {\n node: ComputedRef<FlowNode>\n ports: ComputedRef<FlowPortSpec[]>\n /** Port ids with at least one edge. */\n connected: ComputedRef<Set<string>>\n /** While an edge is being drawn, how each port shows; `null` otherwise. */\n portStates: ComputedRef<Map<string, PortState> | null>\n registerPort: (id: string, el: HTMLElement, auto?: boolean) => void\n unregisterPort: (id: string, auto?: boolean) => void\n}\n\nexport const flowNodeKey: InjectionKey<FlowNodeContext> = Symbol('dou-flow-node')\n"],"mappings":";;AAoXA,IAAa,gBAAiD,OAAO,iBAAiB;;AAGtF,SAAgB,gBAAgB;CAC9B,MAAM,UAAU,OAAO,eAAe,IAAI;CAC1C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sEAAsE;CACxF,OAAO;AACT;AAaA,IAAa,cAA6C,OAAO,eAAe"}
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { CommentAction, CommentAuthor, CommentThread, ContextMenuItem } from 'dou-ui'\nimport type { FlowExportOptions, FlowImageOptions } from './export/draw'\nimport type { FlowTree } from './core/groups'\nimport { inject, type ComputedRef, type InjectionKey, type Ref, type ShallowRef } from 'vue'\nimport type { FlowMessages, FlowMessagesOverride } from './locale'\nimport type {\n FlowData,\n FlowDocument,\n FlowEndpoint,\n FlowNode,\n FlowPortSpec,\n FlowSelection,\n FlowViewport,\n Point,\n PortSide,\n Rect,\n} from './core/model'\nimport type { FlowConnection, PortTypes, PortTypeSpec } from './core/connect'\nimport type { EdgeTypeSpec } from './core/edge-types'\nimport type { FlowExtension } from './core/extension'\nimport type { FlowMenuTarget } from './core/menu'\nimport type { NodeTypeSpec } from './core/node-types'\nimport type { FlowTransaction, FlowTransactionMeta } from './core/transaction'\n\nexport type FlowPanelPlacement = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n\nexport interface FlowControlsProps {\n /** Corner of the editor to sit in. */\n placement?: FlowPanelPlacement\n /** Show undo and redo. */\n history?: boolean\n /** Show the tidy button, which lays the nodes out along their edges. */\n tidy?: boolean\n}\n\nexport interface FlowMinimapProps {\n /** Corner of the editor to sit in. */\n placement?: FlowPanelPlacement\n /** Size of the map in px. */\n width?: number\n height?: number\n}\n\n/** What the find panel looks for: text in the nodes' names. */\nexport interface FlowSearchQuery {\n search: string\n /** Tell capital letters from small ones. */\n caseSensitive?: boolean\n}\n\nexport interface FlowEditorProps {\n /**\n * What the editor is made of: node types, port types, rules, keys and\n * layers. `flowKit()` by default.\n */\n extensions?: (FlowExtension | FlowExtension[])[]\n /** Node types besides the extensions'; they win over an extension's type of the same name. */\n nodeTypes?: NodeTypeSpec<any>[]\n /** Edge types besides the extensions'; they win over an extension's type of the same name. */\n edgeTypes?: EdgeTypeSpec<any>[]\n /** The type of edges without `type`, new ones included. `bezier` by default. */\n edgeType?: string\n /**\n * Below this zoom nodes are drawn as plain boxes with their names, which\n * keeps a large flow quick; see the `simple` slot. `0` never does. `0.4` by default.\n */\n simpleZoom?: number\n /** Grid step for snapping and arrow keys, in px. `0` turns snapping to the grid off. */\n grid?: number\n /** Line nodes up with their neighbours while dragging. */\n guides?: boolean\n minZoom?: number\n maxZoom?: number\n /**\n * Which way the flow runs: `horizontal` left to right, `vertical` top to\n * bottom. Tidying lays nodes out this way.\n */\n direction?: 'horizontal' | 'vertical'\n /** Fit all nodes into view once they are measured. */\n fitView?: boolean\n /**\n * The furthest `fit-view` zooms out, so text stays readable; a larger flow\n * starts at its top left and is panned to. `0` always fits everything.\n */\n fitMinZoom?: number\n /** View, select and pan, but not change anything. */\n readonly?: boolean\n /** The built-in find panel (`Ctrl/⌘+F`). Off, the keys are left to the page. On by default. */\n searchable?: boolean\n /** Scrolling pans the canvas; with Ctrl / ⌘ it zooms. Off, only Ctrl / ⌘ + scroll zooms. */\n panOnScroll?: boolean\n /** Looks and connection rules of port types, by the name used in `dataType`. */\n portTypes?: PortTypes\n /** Refuse edges that would close a cycle. */\n acyclic?: boolean\n /**\n * The last check before an edge is made. Return `false` to refuse it, or a\n * sentence saying why. Called for every port while an edge is dragged.\n */\n canConnect?: (connection: FlowConnection, doc: FlowDocument) => boolean | string\n /**\n * The hairline frame and rounded corners. Off, the canvas takes no\n * border at all, for a panel or page region that already has an edge.\n * On by default.\n */\n bordered?: boolean\n /** Accessible name of the canvas. */\n ariaLabel?: string\n /** Texts to change; only the ones given are replaced. */\n messages?: FlowMessagesOverride\n /**\n * The comment threads, bound with `v-model:comments`. The node or edge a\n * thread is about keeps the thread's id in its `comments`. Left out,\n * there are no comments.\n */\n comments?: CommentThread[]\n /** Who is commenting. Without it comments can be read but not written. */\n author?: CommentAuthor\n /** The thread open now, bound with `v-model:activeComment`. */\n activeComment?: string | null\n /** Threads can be started and replied to; also while `readonly`. On by default. */\n commentable?: boolean\n}\n\n/**\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"}
|
|
@@ -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,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,IAAI,UAAU,IAAI;EACxB,KAAK,MAAM,QAAQ,UAAU,aAAa,CAAC,GAAG;GAC5C,IAAI,UAAU,IAAI,KAAK,IAAI,GACzB,MAAM,IAAI,MACR,6BAA6B,KAAK,KAAK,UAAU,UAAU,KAAK,qBAClE;GACF,UAAU,IAAI,KAAK,MAAM,IAAI;EAC/B;EACA,KAAK,MAAM,QAAQ,UAAU,aAAa,CAAC,GAAG;GAC5C,IAAI,UAAU,IAAI,KAAK,IAAI,GACzB,MAAM,IAAI,MACR,6BAA6B,KAAK,KAAK,UAAU,UAAU,KAAK,qBAClE;GACF,UAAU,IAAI,KAAK,MAAM,IAAI;EAC/B;EACA,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,UAAU,aAAa,CAAC,CAAC,GAAG;GACpE,IAAI,QAAQ,WACV,MAAM,IAAI,MACR,6BAA6B,KAAK,UAAU,UAAU,KAAK,qBAC7D;GACF,UAAU,QAAQ;EACpB;CACF;CAEA,MAAM,QAAuC,QAC3C,WAAW,SAAS,MAAO,EAAE,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,CAAE;CAEpD,OAAO;EACL;EACA;EACA;EACA,UAAU,WAAW,QAA4B,MAAM,MAAM,EAAE,YAAY,MAAM,KAAA,CAAS;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 * Forget the changes of `group` not yet undone, e.g. a drag cancelled with\n * Escape: the editor has already put them back, outside the history.\n */\n drop?: (group: string) => void\n /** A gesture ended (a drag, a resize): the next change starts a new undo step. */\n close?: () => void\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":";;AA8HA,SAAgB,oBAAoB,WAAyC;CAC3E,OAAO;AACT;AA2BA,SAAS,QAAQ,MAAsC;CACrD,MAAM,MAAuB,CAAC;CAC9B,KAAK,MAAM,QAAQ,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F;CAEA,MAAM,QAAuC,QAC3C,WAAW,SAAS,MAAO,EAAE,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,CAAE;CAEpD,OAAO;EACL;EACA;EACA;EACA,UAAU,WAAW,QAA4B,MAAM,MAAM,EAAE,YAAY,MAAM,KAAA,CAAS;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"}
|
package/dist/core/history.js
CHANGED
|
@@ -69,6 +69,32 @@ var FlowHistory = class {
|
|
|
69
69
|
selection: entry.selectionAfter
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Gives a change kept out of undo to a node or edge as undo and redo
|
|
74
|
+
* bring it back, too: comments started on a new node stay on it when its
|
|
75
|
+
* adding is undone and redone.
|
|
76
|
+
*/
|
|
77
|
+
carry(target, patch) {
|
|
78
|
+
const merge = (item) => {
|
|
79
|
+
const next = {
|
|
80
|
+
...item,
|
|
81
|
+
...patch
|
|
82
|
+
};
|
|
83
|
+
for (const [key, value] of Object.entries(patch)) if (value === void 0) delete next[key];
|
|
84
|
+
return next;
|
|
85
|
+
};
|
|
86
|
+
const fix = (steps) => steps.map((step) => "node" in target && step.type === "addNode" && step.node.id === target.node ? {
|
|
87
|
+
...step,
|
|
88
|
+
node: merge(step.node)
|
|
89
|
+
} : "edge" in target && step.type === "addEdge" && step.edge.id === target.edge ? {
|
|
90
|
+
...step,
|
|
91
|
+
edge: merge(step.edge)
|
|
92
|
+
} : step);
|
|
93
|
+
for (const entry of [...this.done, ...this.undone]) {
|
|
94
|
+
entry.steps = fix(entry.steps);
|
|
95
|
+
entry.inverse = fix(entry.inverse);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
72
98
|
clear() {
|
|
73
99
|
this.done = [];
|
|
74
100
|
this.undone = [];
|
package/dist/core/history.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","names":[],"sources":["../../src/core/history.ts"],"sourcesContent":["import type { FlowDocument, FlowSelection } from './model'\nimport {\n applyFlowSteps,\n compactFlowSteps,\n type FlowStep,\n type FlowTransaction,\n} from './transaction'\n\ninterface Entry {\n steps: FlowStep[]\n inverse: FlowStep[]\n group?: string\n time: number\n selectionBefore: FlowSelection\n selectionAfter: FlowSelection\n}\n\n/** Transactions in one group merge when they come within this many ms. */\nconst GROUP_WINDOW = 1000\n\nexport class FlowHistory {\n private done: Entry[] = []\n private undone: Entry[] = []\n\n constructor(private depth = 100) {}\n\n get canUndo() {\n return this.done.length > 0\n }\n\n get canRedo() {\n return this.undone.length > 0\n }\n\n record(\n tr: FlowTransaction,\n selectionBefore: FlowSelection,\n selectionAfter: FlowSelection,\n now = Date.now(),\n ) {\n if (!tr.changed || tr.meta.history === false) return\n this.undone = []\n const last = this.done[this.done.length - 1]\n const group = tr.meta.group\n if (last && group && last.group === group && now - last.time < GROUP_WINDOW) {\n last.steps = compactFlowSteps([...last.steps, ...tr.steps])\n last.inverse = compactFlowSteps([...tr.inverse, ...last.inverse])\n last.time = now\n last.selectionAfter = selectionAfter\n return\n }\n this.done.push({\n steps: tr.steps.slice(),\n inverse: tr.inverse.slice(),\n group,\n time: now,\n selectionBefore,\n selectionAfter,\n })\n if (this.done.length > this.depth) this.done.shift()\n }\n\n /** Ends the current group, so the next change starts a new undo step. */\n close() {\n const last = this.done[this.done.length - 1]\n if (last) last.group = undefined\n }\n\n /** Forgets the last entry if it belongs to `group`, e.g. after a cancelled drag. */\n drop(group: string) {\n const last = this.done[this.done.length - 1]\n if (last?.group === group) this.done.pop()\n }\n\n undo(doc: FlowDocument) {\n const entry = this.done.pop()\n if (!entry) return null\n const tr = applyFlowSteps(doc, entry.inverse)\n this.undone.push(entry)\n return { tr, selection: entry.selectionBefore }\n }\n\n redo(doc: FlowDocument) {\n const entry = this.undone.pop()\n if (!entry) return null\n const tr = applyFlowSteps(doc, entry.steps)\n this.done.push({ ...entry, group: undefined })\n return { tr, selection: entry.selectionAfter }\n }\n\n clear() {\n this.done = []\n this.undone = []\n }\n}\n"],"mappings":";;;AAkBA,IAAM,eAAe;AAErB,IAAa,cAAb,MAAyB;CAIH;CAHpB,OAAwB,CAAC;CACzB,SAA0B,CAAC;CAE3B,YAAY,QAAgB,KAAK;EAAb,KAAA,QAAA;CAAc;CAElC,IAAI,UAAU;EACZ,OAAO,KAAK,KAAK,SAAS;CAC5B;CAEA,IAAI,UAAU;EACZ,OAAO,KAAK,OAAO,SAAS;CAC9B;CAEA,OACE,IACA,iBACA,gBACA,MAAM,KAAK,IAAI,GACf;EACA,IAAI,CAAC,GAAG,WAAW,GAAG,KAAK,YAAY,OAAO;EAC9C,KAAK,SAAS,CAAC;EACf,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK,SAAS;EAC1C,MAAM,QAAQ,GAAG,KAAK;EACtB,IAAI,QAAQ,SAAS,KAAK,UAAU,SAAS,MAAM,KAAK,OAAO,cAAc;GAC3E,KAAK,QAAQ,iBAAiB,CAAC,GAAG,KAAK,OAAO,GAAG,GAAG,KAAK,CAAC;GAC1D,KAAK,UAAU,iBAAiB,CAAC,GAAG,GAAG,SAAS,GAAG,KAAK,OAAO,CAAC;GAChE,KAAK,OAAO;GACZ,KAAK,iBAAiB;GACtB;EACF;EACA,KAAK,KAAK,KAAK;GACb,OAAO,GAAG,MAAM,MAAM;GACtB,SAAS,GAAG,QAAQ,MAAM;GAC1B;GACA,MAAM;GACN;GACA;EACF,CAAC;EACD,IAAI,KAAK,KAAK,SAAS,KAAK,OAAO,KAAK,KAAK,MAAM;CACrD;;CAGA,QAAQ;EACN,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK,SAAS;EAC1C,IAAI,MAAM,KAAK,QAAQ,KAAA;CACzB;;CAGA,KAAK,OAAe;EAElB,IADa,KAAK,KAAK,KAAK,KAAK,SAAS,EACtC,EAAM,UAAU,OAAO,KAAK,KAAK,IAAI;CAC3C;CAEA,KAAK,KAAmB;EACtB,MAAM,QAAQ,KAAK,KAAK,IAAI;EAC5B,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,KAAK,eAAe,KAAK,MAAM,OAAO;EAC5C,KAAK,OAAO,KAAK,KAAK;EACtB,OAAO;GAAE;GAAI,WAAW,MAAM;EAAgB;CAChD;CAEA,KAAK,KAAmB;EACtB,MAAM,QAAQ,KAAK,OAAO,IAAI;EAC9B,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,KAAK,eAAe,KAAK,MAAM,KAAK;EAC1C,KAAK,KAAK,KAAK;GAAE,GAAG;GAAO,OAAO,KAAA;EAAU,CAAC;EAC7C,OAAO;GAAE;GAAI,WAAW,MAAM;EAAe;CAC/C;CAEA,QAAQ;EACN,KAAK,OAAO,CAAC;EACb,KAAK,SAAS,CAAC;CACjB;AACF"}
|
|
1
|
+
{"version":3,"file":"history.js","names":[],"sources":["../../src/core/history.ts"],"sourcesContent":["import type { FlowDocument, FlowSelection } from './model'\nimport {\n applyFlowSteps,\n compactFlowSteps,\n type FlowStep,\n type FlowTransaction,\n} from './transaction'\n\ninterface Entry {\n steps: FlowStep[]\n inverse: FlowStep[]\n group?: string\n time: number\n selectionBefore: FlowSelection\n selectionAfter: FlowSelection\n}\n\n/** Transactions in one group merge when they come within this many ms. */\nconst GROUP_WINDOW = 1000\n\nexport class FlowHistory {\n private done: Entry[] = []\n private undone: Entry[] = []\n\n constructor(private depth = 100) {}\n\n get canUndo() {\n return this.done.length > 0\n }\n\n get canRedo() {\n return this.undone.length > 0\n }\n\n record(\n tr: FlowTransaction,\n selectionBefore: FlowSelection,\n selectionAfter: FlowSelection,\n now = Date.now(),\n ) {\n if (!tr.changed || tr.meta.history === false) return\n this.undone = []\n const last = this.done[this.done.length - 1]\n const group = tr.meta.group\n if (last && group && last.group === group && now - last.time < GROUP_WINDOW) {\n last.steps = compactFlowSteps([...last.steps, ...tr.steps])\n last.inverse = compactFlowSteps([...tr.inverse, ...last.inverse])\n last.time = now\n last.selectionAfter = selectionAfter\n return\n }\n this.done.push({\n steps: tr.steps.slice(),\n inverse: tr.inverse.slice(),\n group,\n time: now,\n selectionBefore,\n selectionAfter,\n })\n if (this.done.length > this.depth) this.done.shift()\n }\n\n /** Ends the current group, so the next change starts a new undo step. */\n close() {\n const last = this.done[this.done.length - 1]\n if (last) last.group = undefined\n }\n\n /** Forgets the last entry if it belongs to `group`, e.g. after a cancelled drag. */\n drop(group: string) {\n const last = this.done[this.done.length - 1]\n if (last?.group === group) this.done.pop()\n }\n\n undo(doc: FlowDocument) {\n const entry = this.done.pop()\n if (!entry) return null\n const tr = applyFlowSteps(doc, entry.inverse)\n this.undone.push(entry)\n return { tr, selection: entry.selectionBefore }\n }\n\n redo(doc: FlowDocument) {\n const entry = this.undone.pop()\n if (!entry) return null\n const tr = applyFlowSteps(doc, entry.steps)\n this.done.push({ ...entry, group: undefined })\n return { tr, selection: entry.selectionAfter }\n }\n\n /**\n * Gives a change kept out of undo to a node or edge as undo and redo\n * bring it back, too: comments started on a new node stay on it when its\n * adding is undone and redone.\n */\n carry(target: { node: string } | { edge: string }, patch: Record<string, unknown>) {\n const merge = <T extends object>(item: T): T => {\n const next: Record<string, unknown> = { ...item, ...patch }\n for (const [key, value] of Object.entries(patch)) if (value === undefined) delete next[key]\n return next as T\n }\n const fix = (steps: FlowStep[]) =>\n steps.map((step) =>\n 'node' in target && step.type === 'addNode' && step.node.id === target.node\n ? { ...step, node: merge(step.node) }\n : 'edge' in target && step.type === 'addEdge' && step.edge.id === target.edge\n ? { ...step, edge: merge(step.edge) }\n : step,\n )\n for (const entry of [...this.done, ...this.undone]) {\n entry.steps = fix(entry.steps)\n entry.inverse = fix(entry.inverse)\n }\n }\n\n clear() {\n this.done = []\n this.undone = []\n }\n}\n"],"mappings":";;;AAkBA,IAAM,eAAe;AAErB,IAAa,cAAb,MAAyB;CAIH;CAHpB,OAAwB,CAAC;CACzB,SAA0B,CAAC;CAE3B,YAAY,QAAgB,KAAK;EAAb,KAAA,QAAA;CAAc;CAElC,IAAI,UAAU;EACZ,OAAO,KAAK,KAAK,SAAS;CAC5B;CAEA,IAAI,UAAU;EACZ,OAAO,KAAK,OAAO,SAAS;CAC9B;CAEA,OACE,IACA,iBACA,gBACA,MAAM,KAAK,IAAI,GACf;EACA,IAAI,CAAC,GAAG,WAAW,GAAG,KAAK,YAAY,OAAO;EAC9C,KAAK,SAAS,CAAC;EACf,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK,SAAS;EAC1C,MAAM,QAAQ,GAAG,KAAK;EACtB,IAAI,QAAQ,SAAS,KAAK,UAAU,SAAS,MAAM,KAAK,OAAO,cAAc;GAC3E,KAAK,QAAQ,iBAAiB,CAAC,GAAG,KAAK,OAAO,GAAG,GAAG,KAAK,CAAC;GAC1D,KAAK,UAAU,iBAAiB,CAAC,GAAG,GAAG,SAAS,GAAG,KAAK,OAAO,CAAC;GAChE,KAAK,OAAO;GACZ,KAAK,iBAAiB;GACtB;EACF;EACA,KAAK,KAAK,KAAK;GACb,OAAO,GAAG,MAAM,MAAM;GACtB,SAAS,GAAG,QAAQ,MAAM;GAC1B;GACA,MAAM;GACN;GACA;EACF,CAAC;EACD,IAAI,KAAK,KAAK,SAAS,KAAK,OAAO,KAAK,KAAK,MAAM;CACrD;;CAGA,QAAQ;EACN,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK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AAM,UAAU,IAAI,MAAM,OAAO;EACnC;CACF;CAEA,QAAQ;EACN,KAAK,OAAO,CAAC;EACb,KAAK,SAAS,CAAC;CACjB;AACF"}
|
package/dist/core/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../src/core/model.ts"],"sourcesContent":["/*\n * The document a flow editor edits: plain, serialisable data, bound with\n * `v-model`. Positions are canvas coordinates in px, from the top left of a\n * node. Ports are not stored; a node type declares them, and edges refer to\n * them by id.\n */\n\nexport type FlowData = Record<string, unknown>\n\nexport interface FlowNode<Data extends FlowData = FlowData> {\n id: string\n /** A registered node type; `'default'` when left out. */\n type?: string\n x: number\n y: number\n /** Only stored for nodes that can be resized; otherwise the content decides. */\n width?: number\n height?: number\n data?: Data\n /** A locked node cannot be moved or deleted. */\n locked?: boolean\n /**\n * The container node, e.g. a group, this node sits in. Its `x` and `y`\n * stay canvas coordinates; moving the container moves it along.\n */\n parent?: string\n /**\n * Stacking order among nodes that aren't containers: higher is drawn on\n * top. Nodes without it count as `0`; equal ones keep the document order.\n */\n z?: number\n}\n\nexport interface FlowEndpoint {\n node: string\n /** Leave out to attach to the node itself. */\n port?: string\n}\n\nexport interface FlowEdge<Data extends FlowData = FlowData> {\n id: string\n source: FlowEndpoint\n target: FlowEndpoint\n /** The edge type: `bezier`, `step`, `straight` or one added by an extension. The editor's `edge-type` when left out. */\n type?: string\n /** Text shown on the edge. */\n label?: string\n /** Dashes run along the edge in its direction, e.g. while data flows through it. */\n animated?: boolean\n /**\n * Points on the canvas the edge runs through on its way, in order. Tidying\n * sets them on an edge that spans several ranks, so it passes between\n * the nodes in its way; moving either end clears them.\n */\n points?: Point[]\n data?: Data\n}\n\nexport interface FlowDocument {\n /** The version of the format; see `migrateDocument`. */\n version: 1\n nodes: FlowNode[]\n edges: FlowEdge[]\n}\n\nexport type PortSide = 'left' | 'right' | 'top' | 'bottom'\n\nexport interface FlowPortSpec {\n id: string\n /** Inputs receive edges, outputs start them. */\n kind: 'input' | 'output'\n /** Where the port sits; inputs default to the left, outputs to the right. */\n side?: PortSide\n label?: string\n /** What the port carries. Two ports connect when they share a type, or either is `'any'`. */\n dataType?: string | string[]\n /**\n * The most edges the port takes. Inputs take one by default, outputs any\n * number. A new edge on a full port replaces its oldest edge.\n */\n max?: number\n}\n\n/** Where the canvas is shown: `x` and `y` are the screen offset of the canvas origin. */\nexport interface FlowViewport {\n x: number\n y: number\n zoom: number\n}\n\nexport interface FlowSelection {\n nodes: string[]\n edges: string[]\n}\n\nexport interface Point {\n x: number\n y: number\n}\n\nexport interface Rect {\n x: number\n y: number\n width: number\n height: number\n}\n\nexport const emptyDocument = (): FlowDocument => ({ version: 1, nodes: [], edges: [] })\nexport const emptySelection = (): FlowSelection => ({ nodes: [], edges: [] })\n\nlet counter = 0\n\n/** A short id, unique within this page and very likely across clients. */\nexport function createId(prefix = 'n') {\n counter = (counter + 1) % 1296\n const time = Date.now().toString(36).slice(-5)\n const random = Math.random().toString(36).slice(2, 6)\n return `${prefix}${time}${counter.toString(36).padStart(2, '0')}${random}`\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/core/model.ts"],"sourcesContent":["/*\n * The document a flow editor edits: plain, serialisable data, bound with\n * `v-model`. Positions are canvas coordinates in px, from the top left of a\n * node. Ports are not stored; a node type declares them, and edges refer to\n * them by id.\n */\n\nexport type FlowData = Record<string, unknown>\n\nexport interface FlowNode<Data extends FlowData = FlowData> {\n id: string\n /** A registered node type; `'default'` when left out. */\n type?: string\n x: number\n y: number\n /** Only stored for nodes that can be resized; otherwise the content decides. */\n width?: number\n height?: number\n data?: Data\n /** A locked node cannot be moved or deleted. */\n locked?: boolean\n /**\n * The container node, e.g. a group, this node sits in. Its `x` and `y`\n * stay canvas coordinates; moving the container moves it along.\n */\n parent?: string\n /**\n * Stacking order among nodes that aren't containers: higher is drawn on\n * top. Nodes without it count as `0`; equal ones keep the document order.\n */\n z?: number\n /**\n * The ids of the comment threads about this node, see the editor's\n * `comments`. Kept when the node is deleted and brought back by undo.\n */\n comments?: string[]\n /**\n * Where on the node each pinned thread is, by thread id: `x` and `y` are\n * fractions of the node's width and height from its top left, 0 to 1, so\n * a pin moves and scales with the node. The ids are in `comments` too.\n */\n commentPins?: Record<string, Point>\n}\n\nexport interface FlowEndpoint {\n node: string\n /** Leave out to attach to the node itself. */\n port?: string\n}\n\nexport interface FlowEdge<Data extends FlowData = FlowData> {\n id: string\n source: FlowEndpoint\n target: FlowEndpoint\n /** The edge type: `bezier`, `step`, `straight` or one added by an extension. The editor's `edge-type` when left out. */\n type?: string\n /** Text shown on the edge. */\n label?: string\n /** Dashes run along the edge in its direction, e.g. while data flows through it. */\n animated?: boolean\n /**\n * Points on the canvas the edge runs through on its way, in order. Tidying\n * sets them on an edge that spans several ranks, so it passes between\n * the nodes in its way; moving either end clears them.\n */\n points?: Point[]\n data?: Data\n /** The ids of the comment threads about this edge, see the editor's `comments`. */\n comments?: string[]\n}\n\nexport interface FlowDocument {\n /** The version of the format; see `migrateDocument`. */\n version: 1\n nodes: FlowNode[]\n edges: FlowEdge[]\n}\n\nexport type PortSide = 'left' | 'right' | 'top' | 'bottom'\n\nexport interface FlowPortSpec {\n id: string\n /** Inputs receive edges, outputs start them. */\n kind: 'input' | 'output'\n /** Where the port sits; inputs default to the left, outputs to the right. */\n side?: PortSide\n label?: string\n /** What the port carries. Two ports connect when they share a type, or either is `'any'`. */\n dataType?: string | string[]\n /**\n * The most edges the port takes. Inputs take one by default, outputs any\n * number. A new edge on a full port replaces its oldest edge.\n */\n max?: number\n /**\n * When the port shows: `always`; `hover`, on a hovered or selected node,\n * or one with the keyboard focus in it (a field being typed in);\n * or `connecting`, only while an edge is drawn. A `<DouFlowPort visible>`\n * overrides it. Defaults to `always`.\n */\n visible?: FlowPortVisible\n}\n\n/** When a port shows, see `FlowPortSpec.visible`. */\nexport type FlowPortVisible = 'always' | 'hover' | 'connecting'\n\n/** Where the canvas is shown: `x` and `y` are the screen offset of the canvas origin. */\nexport interface FlowViewport {\n x: number\n y: number\n zoom: number\n}\n\nexport interface FlowSelection {\n nodes: string[]\n edges: string[]\n}\n\nexport interface Point {\n x: number\n y: number\n}\n\nexport interface Rect {\n x: number\n y: number\n width: number\n height: number\n}\n\nexport const emptyDocument = (): FlowDocument => ({ version: 1, nodes: [], edges: [] })\nexport const emptySelection = (): FlowSelection => ({ nodes: [], edges: [] })\n\nlet counter = 0\n\n/** A short id, unique within this page and very likely across clients. */\nexport function createId(prefix = 'n') {\n counter = (counter + 1) % 1296\n const time = Date.now().toString(36).slice(-5)\n const random = Math.random().toString(36).slice(2, 6)\n return `${prefix}${time}${counter.toString(36).padStart(2, '0')}${random}`\n}\n"],"mappings":";AAkIA,IAAa,uBAAqC;CAAE,SAAS;CAAG,OAAO,CAAC;CAAG,OAAO,CAAC;AAAE;AACrF,IAAa,wBAAuC;CAAE,OAAO,CAAC;CAAG,OAAO,CAAC;AAAE;AAE3E,IAAI,UAAU;;AAGd,SAAgB,SAAS,SAAS,KAAK;CACrC,WAAW,UAAU,KAAK;CAC1B,MAAM,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CAC7C,MAAM,SAAS,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;CACpD,OAAO,GAAG,SAAS,OAAO,QAAQ,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,IAAI;AACpE"}
|
package/dist/core/node-types.js
CHANGED
|
@@ -6,9 +6,40 @@ function defineNodeType(spec) {
|
|
|
6
6
|
return spec;
|
|
7
7
|
}
|
|
8
8
|
var portSide = (port) => port.side ?? (port.kind === "input" ? "left" : "right");
|
|
9
|
+
/**
|
|
10
|
+
* The ports of `ports: 'sides'`: an output and an input in the middle of
|
|
11
|
+
* each side. Edges go from an output (`right`) to an input (`left-in`).
|
|
12
|
+
* Like a whiteboard shape's anchors, the outputs show on hover and the
|
|
13
|
+
* inputs only while an edge is drawn.
|
|
14
|
+
* `right` and `left-in` come first, so a node added after another joins it
|
|
15
|
+
* left to right.
|
|
16
|
+
*/
|
|
17
|
+
var sidePorts = [...[
|
|
18
|
+
"right",
|
|
19
|
+
"bottom",
|
|
20
|
+
"left",
|
|
21
|
+
"top"
|
|
22
|
+
].map((side) => ({
|
|
23
|
+
id: side,
|
|
24
|
+
kind: "output",
|
|
25
|
+
side,
|
|
26
|
+
visible: "hover"
|
|
27
|
+
})), ...[
|
|
28
|
+
"left",
|
|
29
|
+
"top",
|
|
30
|
+
"right",
|
|
31
|
+
"bottom"
|
|
32
|
+
].map((side) => ({
|
|
33
|
+
id: `${side}-in`,
|
|
34
|
+
kind: "input",
|
|
35
|
+
side,
|
|
36
|
+
max: Number.POSITIVE_INFINITY,
|
|
37
|
+
visible: "connecting"
|
|
38
|
+
}))];
|
|
9
39
|
function portsOf(spec, node) {
|
|
10
40
|
const ports = spec?.ports;
|
|
11
41
|
if (!ports) return [];
|
|
42
|
+
if (ports === "sides") return sidePorts;
|
|
12
43
|
return typeof ports === "function" ? ports(node) : ports;
|
|
13
44
|
}
|
|
14
45
|
/** Whether a node can be resized, and its smallest size; `null` when it can't. */
|
|
@@ -27,6 +58,13 @@ function labelOf(spec, node, messages) {
|
|
|
27
58
|
function nodeBounds(spec, node, rect) {
|
|
28
59
|
return spec.bounds?.(node, rect) ?? turnedBox(rect, spec.rotation?.(node) ?? 0);
|
|
29
60
|
}
|
|
30
|
-
|
|
61
|
+
var unknownWarned = /* @__PURE__ */ new Set();
|
|
62
|
+
/** Warns once per page about a node type no one registered. Call only while developing. */
|
|
63
|
+
function warnUnknownNodeType(type) {
|
|
64
|
+
if (unknownWarned.has(type)) return;
|
|
65
|
+
unknownWarned.add(type);
|
|
66
|
+
console.warn(`[@dou-ui/flow] node type "${type}" is not registered, so it is drawn as a default node: pass it in nodeTypes (or an extension)`);
|
|
67
|
+
}
|
|
68
|
+
export { defineNodeType, labelOf, nodeBounds, portSide, portsOf, resizeOf, sidePorts, warnUnknownNodeType };
|
|
31
69
|
|
|
32
70
|
//# sourceMappingURL=node-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-types.js","names":[],"sources":["../../src/core/node-types.ts"],"sourcesContent":["import type { FlowDrawContext } from '../export/context'\nimport type { Component } from 'vue'\nimport type { FlowMessages } from '../locale'\nimport { turnedBox } from './geometry'\nimport type { FlowData, FlowNode, FlowPortSpec, PortSide, Rect } from './model'\n\n/** What a node type's component receives. */\nexport interface NodeViewProps<Data extends FlowData = FlowData> {\n node: FlowNode<Data>\n data: Data\n ports: FlowPortSpec[]\n selected: boolean\n readonly: boolean\n /** Merges `patch` into the node's data, as one undo step. */\n updateData: (patch: Partial<Data>) => void\n}\n\nexport interface NodeTypeSpec<Data extends FlowData = FlowData> {\n type: string\n /**\n * Renders the node's content. The editor draws the frame, selection and\n * focus ring around it. Place ports with `<DouFlowPort>`; ports the\n * component does not place are spread along their sides.\n */\n component?: Component\n
|
|
1
|
+
{"version":3,"file":"node-types.js","names":[],"sources":["../../src/core/node-types.ts"],"sourcesContent":["import type { FlowDrawContext } from '../export/context'\nimport type { Component } from 'vue'\nimport type { FlowMessages } from '../locale'\nimport { turnedBox } from './geometry'\nimport type { FlowData, FlowNode, FlowPortSpec, PortSide, Rect } from './model'\n\n/** What a node type's component receives. */\nexport interface NodeViewProps<Data extends FlowData = FlowData> {\n node: FlowNode<Data>\n data: Data\n ports: FlowPortSpec[]\n selected: boolean\n readonly: boolean\n /** Merges `patch` into the node's data, as one undo step. */\n updateData: (patch: Partial<Data>) => void\n}\n\nexport interface NodeTypeSpec<Data extends FlowData = FlowData> {\n type: string\n /**\n * Renders the node's content. The editor draws the frame, selection and\n * focus ring around it. Place ports with `<DouFlowPort>`; ports the\n * component does not place are spread along their sides.\n */\n component?: Component\n /**\n * The node's ports, fixed or worked out from its data. `'sides'`: an\n * output and an input in the middle of each side, all alike (see\n * `sidePorts`); tidying lays such nodes out the way their edges are\n * drawn and moves the edges' ends onto the sides that face each other.\n */\n ports?: FlowPortSpec[] | 'sides' | ((node: FlowNode<Data>) => FlowPortSpec[])\n /** Data for a new node of this type. */\n defaults?: () => Data\n /**\n * The node's accessible name; `data.label` by default. `messages` are the\n * editor's current strings, for names that follow the locale.\n */\n label?: (node: FlowNode<Data>, messages: FlowMessages) => string\n /**\n * How the type is offered by `paletteTypes` and in the list that opens\n * when an edge is dropped on the empty canvas. Types without it aren't offered.\n */\n palette?: NodePaletteSpec\n /**\n * Nodes dropped inside become its children (`parent`) and move with it;\n * with `data.collapsed` they are hidden and their edges end on it.\n * Containers are drawn under edges and other nodes.\n */\n container?: boolean\n /**\n * A handle on the selected node changes its stored `width` and `height`.\n * A function decides per node, e.g. not while it is turned.\n */\n resizable?: NodeResize | ((node: FlowNode<Data>) => NodeResize)\n /** The `width` and `height` a new node starts with. */\n size?: { width: number; height: number }\n /**\n * `false` leaves out the card the editor draws around the component (its\n * border, background and shadow), for nodes that draw their own outline,\n * e.g. a circle. Selection then shows as a thin outline around the box.\n */\n frame?: boolean\n /**\n * How far the node is drawn turned about its centre, in degrees clockwise;\n * `0` by default. The component turns what it draws, and `draw` turns its\n * export; the editor follows: the selection outline, picking with a box,\n * what is drawn in view, the toolbar and other people's outlines. For\n * nodes with `frame: false`. A turned node has no editor resize handle.\n */\n rotation?: (node: FlowNode<Data>) => number\n /**\n * The box the node covers on screen when it draws outside its own `rect`.\n * The toolbar over the selection floats above it. By default the box\n * around `rect` turned by `rotation`.\n */\n bounds?: (node: FlowNode<Data>, rect: Rect) => Rect\n /**\n * Draws the node as SVG markup for `exportSVG` and `exportPNG`, in its\n * own coordinates. Without it the node is drawn as a card with its name.\n */\n draw?: (node: FlowNode<Data>, draw: FlowDrawContext) => string\n}\n\nexport interface NodePaletteSpec {\n label: string\n icon?: Component\n /** Types with the same group are listed together under its name. */\n group?: string\n description?: string\n /** Other words the search should find the type by. */\n keywords?: string[]\n}\n\n/** Declares a node type, with the data type checked against its component. */\nexport function defineNodeType<Data extends FlowData = FlowData>(\n spec: NodeTypeSpec<Data>,\n): NodeTypeSpec<Data> {\n if (process.env.NODE_ENV !== 'production' && spec.rotation && spec.frame !== false)\n console.warn(\n `[@dou-ui/flow] the node type \"${spec.type}\" has rotation but not frame: false: the card the editor draws around it does not turn`,\n )\n return spec\n}\n\nexport const portSide = (port: FlowPortSpec): PortSide =>\n port.side ?? (port.kind === 'input' ? 'left' : 'right')\n\n/**\n * The ports of `ports: 'sides'`: an output and an input in the middle of\n * each side. Edges go from an output (`right`) to an input (`left-in`).\n * Like a whiteboard shape's anchors, the outputs show on hover and the\n * inputs only while an edge is drawn.\n * `right` and `left-in` come first, so a node added after another joins it\n * left to right.\n */\nexport const sidePorts: readonly FlowPortSpec[] = [\n ...(['right', 'bottom', 'left', 'top'] as const).map((side) => ({\n id: side,\n kind: 'output' as const,\n side,\n visible: 'hover' as const,\n })),\n ...(['left', 'top', 'right', 'bottom'] as const).map((side) => ({\n id: `${side}-in`,\n kind: 'input' as const,\n side,\n max: Number.POSITIVE_INFINITY,\n visible: 'connecting' as const,\n })),\n]\n\nexport function portsOf(spec: NodeTypeSpec | undefined, node: FlowNode): FlowPortSpec[] {\n const ports = spec?.ports\n if (!ports) return []\n if (ports === 'sides') return sidePorts as FlowPortSpec[]\n return typeof ports === 'function' ? ports(node) : ports\n}\n\nexport type NodeResize = boolean | { minWidth?: number; minHeight?: number }\n\n/** Whether a node can be resized, and its smallest size; `null` when it can't. */\nexport function resizeOf(\n spec: NodeTypeSpec | undefined,\n node: FlowNode,\n): { minWidth?: number; minHeight?: number } | null {\n // the editor's handle grows a node along the page, not along a turned node's sides\n if (spec?.rotation?.(node)) return null\n const value = typeof spec?.resizable === 'function' ? spec.resizable(node) : spec?.resizable\n if (!value) return null\n return value === true ? {} : value\n}\n\nexport function labelOf(\n spec: NodeTypeSpec | undefined,\n node: FlowNode,\n messages: FlowMessages,\n): string {\n if (spec?.label) return spec.label(node, messages)\n const label = node.data?.label\n return typeof label === 'string' ? label : node.id\n}\n\n/** The box `node` covers on screen, drawn at `rect`. */\nexport function nodeBounds(spec: NodeTypeSpec, node: FlowNode, rect: Rect): Rect {\n return spec.bounds?.(node, rect) ?? turnedBox(rect, spec.rotation?.(node) ?? 0)\n}\n\nconst unknownWarned = new Set<string>()\n/** Warns once per page about a node type no one registered. Call only while developing. */\nexport function warnUnknownNodeType(type: string) {\n if (unknownWarned.has(type)) return\n unknownWarned.add(type)\n console.warn(\n `[@dou-ui/flow] node type \"${type}\" is not registered, so it is drawn as a default node: pass it in nodeTypes (or an extension)`,\n )\n}\n"],"mappings":";;;AA+FA,SAAgB,eACd,MACoB;CACpB,IAAA,QAAA,IAAA,aAA6B,gBAAgB,KAAK,YAAY,KAAK,UAAU,OAC3E,QAAQ,KACN,iCAAiC,KAAK,KAAK,uFAC7C;CACF,OAAO;AACT;AAEA,IAAa,YAAY,SACvB,KAAK,SAAS,KAAK,SAAS,UAAU,SAAS;;;;;;;;;AAUjD,IAAa,YAAqC,CAChD,GAAI;CAAC;CAAS;CAAU;CAAQ;AAAK,CAAC,CAAW,KAAK,UAAU;CAC9D,IAAI;CACJ,MAAM;CACN;CACA,SAAS;AACX,EAAE,GACF,GAAI;CAAC;CAAQ;CAAO;CAAS;AAAQ,CAAC,CAAW,KAAK,UAAU;CAC9D,IAAI,GAAG,KAAK;CACZ,MAAM;CACN;CACA,KAAK,OAAO;CACZ,SAAS;AACX,EAAE,CACJ;AAEA,SAAgB,QAAQ,MAAgC,MAAgC;CACtF,MAAM,QAAQ,MAAM;CACpB,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,IAAI,UAAU,SAAS,OAAO;CAC9B,OAAO,OAAO,UAAU,aAAa,MAAM,IAAI,IAAI;AACrD;;AAKA,SAAgB,SACd,MACA,MACkD;CAElD,IAAI,MAAM,WAAW,IAAI,GAAG,OAAO;CACnC,MAAM,QAAQ,OAAO,MAAM,cAAc,aAAa,KAAK,UAAU,IAAI,IAAI,MAAM;CACnF,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,UAAU,OAAO,CAAC,IAAI;AAC/B;AAEA,SAAgB,QACd,MACA,MACA,UACQ;CACR,IAAI,MAAM,OAAO,OAAO,KAAK,MAAM,MAAM,QAAQ;CACjD,MAAM,QAAQ,KAAK,MAAM;CACzB,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAK;AAClD;;AAGA,SAAgB,WAAW,MAAoB,MAAgB,MAAkB;CAC/E,OAAO,KAAK,SAAS,MAAM,IAAI,KAAK,UAAU,MAAM,KAAK,WAAW,IAAI,KAAK,CAAC;AAChF;AAEA,IAAM,gCAAgB,IAAI,IAAY;;AAEtC,SAAgB,oBAAoB,MAAc;CAChD,IAAI,cAAc,IAAI,IAAI,GAAG;CAC7B,cAAc,IAAI,IAAI;CACtB,QAAQ,KACN,6BAA6B,KAAK,8FACpC;AACF"}
|
package/dist/core/transaction.js
CHANGED
|
@@ -54,11 +54,12 @@ var FlowTransaction = class {
|
|
|
54
54
|
* editor fires `transactionCancel` and says why. For an extension's `transaction`
|
|
55
55
|
* hook, e.g. to keep people from changing what they may not; hooks after
|
|
56
56
|
* it don't run. A change kept out of the history (`meta.history: false`),
|
|
57
|
-
* such as undo, redo
|
|
57
|
+
* such as undo, redo, another person's or a comment's (`meta.origin`
|
|
58
|
+
* tells which), can't be cancelled and goes ahead.
|
|
58
59
|
*/
|
|
59
60
|
cancel(reason) {
|
|
60
61
|
if (this.meta.history !== false) this.stopped = { reason };
|
|
61
|
-
else warnUncancellable();
|
|
62
|
+
else warnUncancellable(this.meta.origin);
|
|
62
63
|
return this;
|
|
63
64
|
}
|
|
64
65
|
/** Whether `cancel` stopped it. */
|
|
@@ -374,10 +375,10 @@ function compactFlowSteps(steps) {
|
|
|
374
375
|
}
|
|
375
376
|
var warnedUncancellable = false;
|
|
376
377
|
/** Says once that cancelling a change kept out of the history does nothing. */
|
|
377
|
-
function warnUncancellable() {
|
|
378
|
+
function warnUncancellable(origin) {
|
|
378
379
|
if (process.env.NODE_ENV === "production" || warnedUncancellable) return;
|
|
379
380
|
warnedUncancellable = true;
|
|
380
|
-
console.warn(
|
|
381
|
+
console.warn(`[@dou-ui/flow] a change kept out of the history can't be cancelled; it goes ahead (meta.origin: ${JSON.stringify(origin ?? null)}). Undo, redo, other people's changes and the marks of comments are such changes: skip them in the hook by meta.origin`);
|
|
381
382
|
}
|
|
382
383
|
export { FlowTransaction, applyFlowSteps, compactFlowSteps };
|
|
383
384
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","names":[],"sources":["../../src/core/transaction.ts"],"sourcesContent":["import type { FlowDocument, FlowEdge, FlowNode } from './model'\n\n/*\n * Every change to a document is a list of steps. Applying a step also\n * gives the step that undoes it, so history, collaboration and the\n * `transaction` event all work on the same small vocabulary.\n */\n\ntype Patch<T> = { [K in keyof T]?: T[K] | undefined }\n\nexport type FlowStep =\n | { type: 'addNode'; node: FlowNode; index?: number }\n | { type: 'removeNode'; id: string }\n | { type: 'updateNode'; id: string; patch: Patch<FlowNode> }\n | { type: 'addEdge'; edge: FlowEdge; index?: number }\n | { type: 'removeEdge'; id: string }\n | { type: 'updateEdge'; id: string; patch: Patch<FlowEdge> }\n\nexport interface FlowTransactionMeta {\n /** Keep out of the undo history, e.g. changes from another client. */\n history?: boolean\n /**\n * Consecutive transactions in the same group within a second undo as\n * one, e.g. the frames of a drag or repeated arrow key nudges.\n */\n group?: string\n /** Who made the change, passed on to the `transaction` event. */\n origin?: string\n}\n\nfunction patched<T extends object>(item: T, patch: Patch<T>): T {\n const next = { ...item } as Record<string, unknown>\n for (const key of Object.keys(patch)) {\n const value = (patch as Record<string, unknown>)[key]\n if (value === undefined) delete next[key]\n else next[key] = value\n }\n return next as T\n}\n\n/** The values `patch` would replace, so applying them restores `item`. */\nfunction previous<T extends object>(item: T, patch: Patch<T>): Patch<T> {\n const old: Record<string, unknown> = {}\n for (const key of Object.keys(patch)) old[key] = (item as Record<string, unknown>)[key]\n return old as Patch<T>\n}\n\nconst sameValue = (a: unknown, b: unknown) => a === b\n\n/**\n * A batch of changes to a document. Steps apply as they are added, so\n * later calls see earlier ones; `doc` is the result.\n */\nexport class FlowTransaction {\n readonly steps: FlowStep[] = []\n /** The steps that undo this transaction, in the order to apply them. */\n readonly inverse: FlowStep[] = []\n meta: FlowTransactionMeta = {}\n private nodes: FlowNode[]\n private edges: FlowEdge[]\n private copied = { nodes: false, edges: false }\n\n constructor(readonly before: FlowDocument) {\n this.nodes = before.nodes\n this.edges = before.edges\n }\n\n get doc(): FlowDocument {\n if (!this.steps.length) return this.before\n return { ...this.before, nodes: this.nodes, edges: this.edges }\n }\n\n /** Whether the change makes any change: it has steps and wasn't cancelled. */\n get changed() {\n return this.steps.length > 0 && !this.stopped\n }\n\n private stopped: { reason?: string } | null = null\n\n /**\n * Stops the change: none of it is applied or kept for undo, and the\n * editor fires `transactionCancel` and says why. For an extension's `transaction`\n * hook, e.g. to keep people from changing what they may not; hooks after\n * it don't run. A change kept out of the history (`meta.history: false`),\n * such as undo, redo or another person's, can't be cancelled and goes ahead.\n */\n cancel(reason?: string) {\n if (this.meta.history !== false) this.stopped = { reason }\n else warnUncancellable()\n return this\n }\n\n /** Whether `cancel` stopped it. */\n get cancelled() {\n return this.stopped !== null\n }\n\n /** What `cancel` was given, to tell people why. */\n get cancelReason() {\n return this.stopped?.reason\n }\n\n // Indexes built when first needed and kept up to date after, so moving\n // or removing many nodes of a large document doesn't search it each time.\n private index: { nodes?: Map<string, number>; edges?: Map<string, number> } = {}\n private incident?: Map<string, string[]>\n private was?: { nodes: Map<string, FlowNode>; edges: Map<string, FlowEdge> }\n\n private nodeIndex(id: string) {\n this.index.nodes ??= new Map(this.nodes.map((node, i) => [node.id, i]))\n return this.index.nodes.get(id) ?? -1\n }\n\n private edgeIndex(id: string) {\n this.index.edges ??= new Map(this.edges.map((edge, i) => [edge.id, i]))\n return this.index.edges.get(id) ?? -1\n }\n\n /** The document as it was before this transaction. */\n private get original() {\n this.was ??= {\n nodes: new Map(this.before.nodes.map((node) => [node.id, node])),\n edges: new Map(this.before.edges.map((edge) => [edge.id, edge])),\n }\n return this.was\n }\n\n getNode(id: string) {\n return this.nodes[this.nodeIndex(id)]\n }\n\n getEdge(id: string) {\n return this.edges[this.edgeIndex(id)]\n }\n\n /** Edges that start or end at a node. */\n edgesOf(id: string) {\n if (!this.incident) {\n this.incident = new Map()\n for (const edge of this.edges) this.attach(edge)\n }\n return (this.incident.get(id) ?? []).flatMap((e) => this.getEdge(e) ?? [])\n }\n\n private attach(edge: FlowEdge) {\n if (!this.incident) return\n for (const end of new Set([edge.source.node, edge.target.node])) {\n const list = this.incident.get(end)\n if (list) list.push(edge.id)\n else this.incident.set(end, [edge.id])\n }\n }\n\n private detach(edge: FlowEdge) {\n if (!this.incident) return\n for (const end of new Set([edge.source.node, edge.target.node])) {\n const list = this.incident.get(end)\n const at = list?.indexOf(edge.id) ?? -1\n if (at >= 0) list!.splice(at, 1)\n }\n }\n\n /** Renumbers an index from `from` on, after an insert or removal there. */\n private reindex(map: Map<string, number> | undefined, list: { id: string }[], from: number) {\n if (!map) return\n for (let i = from; i < list.length; i++) map.set(list[i]!.id, i)\n }\n\n setMeta(meta: FlowTransactionMeta) {\n Object.assign(this.meta, meta)\n return this\n }\n\n step(step: FlowStep) {\n const inverse = this.apply(step)\n if (inverse) {\n this.steps.push(step)\n this.inverse.unshift(inverse)\n }\n return this\n }\n\n addNode(node: FlowNode, index?: number) {\n return this.step({ type: 'addNode', node, index })\n }\n\n /** Removes a node and every edge attached to it. */\n removeNode(id: string) {\n for (const edge of this.edgesOf(id)) this.removeEdge(edge.id)\n return this.step({ type: 'removeNode', id })\n }\n\n /**\n * Changes a node. Moving it moves the points of an edge at it along when\n * the edge's other end has moved just as far in this transaction, and\n * drops them otherwise, as they no longer fit; so does resizing it, as\n * its ports move.\n */\n updateNode(id: string, patch: Patch<FlowNode>) {\n const node = this.getNode(id)\n const changed = (key: 'x' | 'y' | 'width' | 'height') =>\n node !== undefined && key in patch && patch[key] !== node[key]\n const moved = changed('x') || changed('y')\n const resized = changed('width') || changed('height')\n this.step({ type: 'updateNode', id, patch })\n if (moved || resized) this.carryPoints(id, resized)\n return this\n }\n\n moveNode(id: string, x: number, y: number) {\n const node = this.getNode(id)\n if (node && node.x === x && node.y === y) return this\n return this.updateNode(id, { x, y })\n }\n\n /** Moves the points of the edges at a moved node along, or drops them. */\n private carryPoints(id: string, drop: boolean) {\n const shift = this.shiftOf(id)\n for (const edge of this.edgesOf(id)) {\n const before = this.original.edges.get(edge.id)\n const other = this.shiftOf(edge.source.node === id ? edge.target.node : edge.source.node)\n const together = !drop && shift && other && other.x === shift.x && other.y === shift.y\n if (before?.points && together)\n this.updateEdge(edge.id, {\n points: before.points.map((p) => ({ x: p.x + shift!.x, y: p.y + shift!.y })),\n })\n else if (edge.points) this.updateEdge(edge.id, { points: undefined })\n }\n }\n\n /** How far a node has moved in this transaction so far. */\n private shiftOf(id: string) {\n const now = this.getNode(id)\n const was = this.original.nodes.get(id)\n return now && was ? { x: now.x - was.x, y: now.y - was.y } : undefined\n }\n\n /** Merges `patch` into the node's `data`. */\n updateData(id: string, patch: Record<string, unknown>) {\n const node = this.getNode(id)\n if (!node) return this\n return this.updateNode(id, { data: { ...node.data, ...patch } })\n }\n\n addEdge(edge: FlowEdge, index?: number) {\n return this.step({ type: 'addEdge', edge, index })\n }\n\n removeEdge(id: string) {\n return this.step({ type: 'removeEdge', id })\n }\n\n updateEdge(id: string, patch: Patch<FlowEdge>) {\n return this.step({ type: 'updateEdge', id, patch })\n }\n\n private writable(kind: 'nodes' | 'edges') {\n if (!this.copied[kind]) {\n this.copied[kind] = true\n if (kind === 'nodes') this.nodes = this.nodes.slice()\n else this.edges = this.edges.slice()\n }\n return kind === 'nodes' ? this.nodes : this.edges\n }\n\n /** Applies a step and returns its inverse, or `null` when it changes nothing. */\n private apply(step: FlowStep): FlowStep | null {\n switch (step.type) {\n case 'addNode': {\n if (this.getNode(step.node.id)) return null\n const list = this.writable('nodes') as FlowNode[]\n const index = clampIndex(step.index, list.length)\n list.splice(index, 0, step.node)\n this.reindex(this.index.nodes, list, index)\n return { type: 'removeNode', id: step.node.id }\n }\n case 'removeNode': {\n const index = this.nodeIndex(step.id)\n if (index < 0) return null\n const list = this.writable('nodes') as FlowNode[]\n const [node] = list.splice(index, 1)\n this.index.nodes?.delete(step.id)\n this.reindex(this.index.nodes, list, index)\n return { type: 'addNode', node: node!, index }\n }\n case 'updateNode': {\n const index = this.nodeIndex(step.id)\n if (index < 0) return null\n const node = this.nodes[index]!\n const keys = Object.keys(step.patch) as (keyof FlowNode)[]\n if (keys.every((key) => sameValue(node[key], step.patch[key]))) return null\n const list = this.writable('nodes') as FlowNode[]\n list[index] = patched(node, step.patch)\n return { type: 'updateNode', id: step.id, patch: previous(node, step.patch) }\n }\n case 'addEdge': {\n if (this.getEdge(step.edge.id)) return null\n const list = this.writable('edges') as FlowEdge[]\n const index = clampIndex(step.index, list.length)\n list.splice(index, 0, step.edge)\n this.reindex(this.index.edges, list, index)\n this.attach(step.edge)\n return { type: 'removeEdge', id: step.edge.id }\n }\n case 'removeEdge': {\n const index = this.edgeIndex(step.id)\n if (index < 0) return null\n const list = this.writable('edges') as FlowEdge[]\n const [edge] = list.splice(index, 1)\n this.index.edges?.delete(step.id)\n this.reindex(this.index.edges, list, index)\n this.detach(edge!)\n return { type: 'addEdge', edge: edge!, index }\n }\n case 'updateEdge': {\n const index = this.edgeIndex(step.id)\n if (index < 0) return null\n const edge = this.edges[index]!\n const keys = Object.keys(step.patch) as (keyof FlowEdge)[]\n if (keys.every((key) => sameValue(edge[key], step.patch[key]))) return null\n const list = this.writable('edges') as FlowEdge[]\n list[index] = patched(edge, step.patch)\n if ('source' in step.patch || 'target' in step.patch) {\n this.detach(edge)\n this.attach(list[index]!)\n }\n return { type: 'updateEdge', id: step.id, patch: previous(edge, step.patch) }\n }\n }\n }\n}\n\nfunction clampIndex(index: number | undefined, length: number) {\n if (index == null) return length\n return Math.max(0, Math.min(length, index))\n}\n\n/** Applies steps to a document; steps that no longer apply are skipped. */\nexport function applyFlowSteps(doc: FlowDocument, steps: readonly FlowStep[]) {\n const tr = new FlowTransaction(doc)\n for (const step of steps) tr.step(step)\n return tr\n}\n\nconst targetOf = (step: FlowStep) => {\n switch (step.type) {\n case 'addNode':\n return `n:${step.node.id}`\n case 'addEdge':\n return `e:${step.edge.id}`\n case 'removeNode':\n case 'updateNode':\n return `n:${step.id}`\n case 'removeEdge':\n case 'updateEdge':\n return `e:${step.id}`\n }\n}\n\n/**\n * Folds updates of the same node or edge into one, as long as nothing\n * adds or removes it in between. Updates of different targets commute, so\n * the result applies the same as the original list.\n */\nexport function compactFlowSteps(steps: readonly FlowStep[]): FlowStep[] {\n const out: (FlowStep | null)[] = []\n const lastUpdate = new Map<string, number>()\n for (const step of steps) {\n const target = targetOf(step)\n if (step.type === 'updateNode' || step.type === 'updateEdge') {\n const at = lastUpdate.get(target)\n if (at != null) {\n const prev = out[at] as typeof step\n out[at] = { ...prev, patch: { ...prev.patch, ...step.patch } } as FlowStep\n continue\n }\n lastUpdate.set(target, out.length)\n } else {\n lastUpdate.delete(target)\n }\n out.push(step)\n }\n return out.filter((step): step is FlowStep => step != null)\n}\n\nlet warnedUncancellable = false\n/** Says once that cancelling a change kept out of the history does nothing. */\nfunction warnUncancellable() {\n // the app's bundler replaces this, as for Vue's own warnings\n if (process.env.NODE_ENV === 'production' || warnedUncancellable) return\n warnedUncancellable = true\n console.warn(\n \"[@dou-ui/flow] a change kept out of the history (undo, redo or another person's) can't be cancelled; it goes ahead\",\n )\n}\n"],"mappings":";AA8BA,SAAS,QAA0B,MAAS,OAAoB;CAC9D,MAAM,OAAO,EAAE,GAAG,KAAK;CACvB,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAAG;EACpC,MAAM,QAAS,MAAkC;EACjD,IAAI,UAAU,KAAA,GAAW,OAAO,KAA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I,sBAAsB;;AAE1B,SAAS,oBAAoB;CAE3B,IAAA,QAAA,IAAA,aAA6B,gBAAgB,qBAAqB;CAClE,sBAAsB;CACtB,QAAQ,KACN,oHACF;AACF"}
|
|
1
|
+
{"version":3,"file":"transaction.js","names":[],"sources":["../../src/core/transaction.ts"],"sourcesContent":["import type { FlowDocument, FlowEdge, FlowNode } from './model'\n\n/*\n * Every change to a document is a list of steps. Applying a step also\n * gives the step that undoes it, so history, collaboration and the\n * `transaction` event all work on the same small vocabulary.\n */\n\ntype Patch<T> = { [K in keyof T]?: T[K] | undefined }\n\nexport type FlowStep =\n | { type: 'addNode'; node: FlowNode; index?: number }\n | { type: 'removeNode'; id: string }\n | { type: 'updateNode'; id: string; patch: Patch<FlowNode> }\n | { type: 'addEdge'; edge: FlowEdge; index?: number }\n | { type: 'removeEdge'; id: string }\n | { type: 'updateEdge'; id: string; patch: Patch<FlowEdge> }\n\nexport interface FlowTransactionMeta {\n /** Keep out of the undo history, e.g. changes from another client. */\n history?: boolean\n /**\n * Consecutive transactions in the same group within a second undo as\n * one, e.g. the frames of a drag or repeated arrow key nudges.\n */\n group?: string\n /** Who made the change, passed on to the `transaction` event. */\n origin?: string\n}\n\nfunction patched<T extends object>(item: T, patch: Patch<T>): T {\n const next = { ...item } as Record<string, unknown>\n for (const key of Object.keys(patch)) {\n const value = (patch as Record<string, unknown>)[key]\n if (value === undefined) delete next[key]\n else next[key] = value\n }\n return next as T\n}\n\n/** The values `patch` would replace, so applying them restores `item`. */\nfunction previous<T extends object>(item: T, patch: Patch<T>): Patch<T> {\n const old: Record<string, unknown> = {}\n for (const key of Object.keys(patch)) old[key] = (item as Record<string, unknown>)[key]\n return old as Patch<T>\n}\n\nconst sameValue = (a: unknown, b: unknown) => a === b\n\n/**\n * A batch of changes to a document. Steps apply as they are added, so\n * later calls see earlier ones; `doc` is the result.\n */\nexport class FlowTransaction {\n readonly steps: FlowStep[] = []\n /** The steps that undo this transaction, in the order to apply them. */\n readonly inverse: FlowStep[] = []\n meta: FlowTransactionMeta = {}\n private nodes: FlowNode[]\n private edges: FlowEdge[]\n private copied = { nodes: false, edges: false }\n\n constructor(readonly before: FlowDocument) {\n this.nodes = before.nodes\n this.edges = before.edges\n }\n\n get doc(): FlowDocument {\n if (!this.steps.length) return this.before\n return { ...this.before, nodes: this.nodes, edges: this.edges }\n }\n\n /** Whether the change makes any change: it has steps and wasn't cancelled. */\n get changed() {\n return this.steps.length > 0 && !this.stopped\n }\n\n private stopped: { reason?: string } | null = null\n\n /**\n * Stops the change: none of it is applied or kept for undo, and the\n * editor fires `transactionCancel` and says why. For an extension's `transaction`\n * hook, e.g. to keep people from changing what they may not; hooks after\n * it don't run. A change kept out of the history (`meta.history: false`),\n * such as undo, redo, another person's or a comment's (`meta.origin`\n * tells which), can't be cancelled and goes ahead.\n */\n cancel(reason?: string) {\n if (this.meta.history !== false) this.stopped = { reason }\n else warnUncancellable(this.meta.origin)\n return this\n }\n\n /** Whether `cancel` stopped it. */\n get cancelled() {\n return this.stopped !== null\n }\n\n /** What `cancel` was given, to tell people why. */\n get cancelReason() {\n return this.stopped?.reason\n }\n\n // Indexes built when first needed and kept up to date after, so moving\n // or removing many nodes of a large document doesn't search it each time.\n private index: { nodes?: Map<string, number>; edges?: Map<string, number> } = {}\n private incident?: Map<string, string[]>\n private was?: { nodes: Map<string, FlowNode>; edges: Map<string, FlowEdge> }\n\n private nodeIndex(id: string) {\n this.index.nodes ??= new Map(this.nodes.map((node, i) => [node.id, i]))\n return this.index.nodes.get(id) ?? -1\n }\n\n private edgeIndex(id: string) {\n this.index.edges ??= new Map(this.edges.map((edge, i) => [edge.id, i]))\n return this.index.edges.get(id) ?? -1\n }\n\n /** The document as it was before this transaction. */\n private get original() {\n this.was ??= {\n nodes: new Map(this.before.nodes.map((node) => [node.id, node])),\n edges: new Map(this.before.edges.map((edge) => [edge.id, edge])),\n }\n return this.was\n }\n\n getNode(id: string) {\n return this.nodes[this.nodeIndex(id)]\n }\n\n getEdge(id: string) {\n return this.edges[this.edgeIndex(id)]\n }\n\n /** Edges that start or end at a node. */\n edgesOf(id: string) {\n if (!this.incident) {\n this.incident = new Map()\n for (const edge of this.edges) this.attach(edge)\n }\n return (this.incident.get(id) ?? []).flatMap((e) => this.getEdge(e) ?? [])\n }\n\n private attach(edge: FlowEdge) {\n if (!this.incident) return\n for (const end of new Set([edge.source.node, edge.target.node])) {\n const list = this.incident.get(end)\n if (list) list.push(edge.id)\n else this.incident.set(end, [edge.id])\n }\n }\n\n private detach(edge: FlowEdge) {\n if (!this.incident) return\n for (const end of new Set([edge.source.node, edge.target.node])) {\n const list = this.incident.get(end)\n const at = list?.indexOf(edge.id) ?? -1\n if (at >= 0) list!.splice(at, 1)\n }\n }\n\n /** Renumbers an index from `from` on, after an insert or removal there. */\n private reindex(map: Map<string, number> | undefined, list: { id: string }[], from: number) {\n if (!map) return\n for (let i = from; i < list.length; i++) map.set(list[i]!.id, i)\n }\n\n setMeta(meta: FlowTransactionMeta) {\n Object.assign(this.meta, meta)\n return this\n }\n\n step(step: FlowStep) {\n const inverse = this.apply(step)\n if (inverse) {\n this.steps.push(step)\n this.inverse.unshift(inverse)\n }\n return this\n }\n\n addNode(node: FlowNode, index?: number) {\n return this.step({ type: 'addNode', node, index })\n }\n\n /** Removes a node and every edge attached to it. */\n removeNode(id: string) {\n for (const edge of this.edgesOf(id)) this.removeEdge(edge.id)\n return this.step({ type: 'removeNode', id })\n }\n\n /**\n * Changes a node. Moving it moves the points of an edge at it along when\n * the edge's other end has moved just as far in this transaction, and\n * drops them otherwise, as they no longer fit; so does resizing it, as\n * its ports move.\n */\n updateNode(id: string, patch: Patch<FlowNode>) {\n const node = this.getNode(id)\n const changed = (key: 'x' | 'y' | 'width' | 'height') =>\n node !== undefined && key in patch && patch[key] !== node[key]\n const moved = changed('x') || changed('y')\n const resized = changed('width') || changed('height')\n this.step({ type: 'updateNode', id, patch })\n if (moved || resized) this.carryPoints(id, resized)\n return this\n }\n\n moveNode(id: string, x: number, y: number) {\n const node = this.getNode(id)\n if (node && node.x === x && node.y === y) return this\n return this.updateNode(id, { x, y })\n }\n\n /** Moves the points of the edges at a moved node along, or drops them. */\n private carryPoints(id: string, drop: boolean) {\n const shift = this.shiftOf(id)\n for (const edge of this.edgesOf(id)) {\n const before = this.original.edges.get(edge.id)\n const other = this.shiftOf(edge.source.node === id ? edge.target.node : edge.source.node)\n const together = !drop && shift && other && other.x === shift.x && other.y === shift.y\n if (before?.points && together)\n this.updateEdge(edge.id, {\n points: before.points.map((p) => ({ x: p.x + shift!.x, y: p.y + shift!.y })),\n })\n else if (edge.points) this.updateEdge(edge.id, { points: undefined })\n }\n }\n\n /** How far a node has moved in this transaction so far. */\n private shiftOf(id: string) {\n const now = this.getNode(id)\n const was = this.original.nodes.get(id)\n return now && was ? { x: now.x - was.x, y: now.y - was.y } : undefined\n }\n\n /** Merges `patch` into the node's `data`. */\n updateData(id: string, patch: Record<string, unknown>) {\n const node = this.getNode(id)\n if (!node) return this\n return this.updateNode(id, { data: { ...node.data, ...patch } })\n }\n\n addEdge(edge: FlowEdge, index?: number) {\n return this.step({ type: 'addEdge', edge, index })\n }\n\n removeEdge(id: string) {\n return this.step({ type: 'removeEdge', id })\n }\n\n updateEdge(id: string, patch: Patch<FlowEdge>) {\n return this.step({ type: 'updateEdge', id, patch })\n }\n\n private writable(kind: 'nodes' | 'edges') {\n if (!this.copied[kind]) {\n this.copied[kind] = true\n if (kind === 'nodes') this.nodes = this.nodes.slice()\n else this.edges = this.edges.slice()\n }\n return kind === 'nodes' ? this.nodes : this.edges\n }\n\n /** Applies a step and returns its inverse, or `null` when it changes nothing. */\n private apply(step: FlowStep): FlowStep | null {\n switch (step.type) {\n case 'addNode': {\n if (this.getNode(step.node.id)) return null\n const list = this.writable('nodes') as FlowNode[]\n const index = clampIndex(step.index, list.length)\n list.splice(index, 0, step.node)\n this.reindex(this.index.nodes, list, index)\n return { type: 'removeNode', id: step.node.id }\n }\n case 'removeNode': {\n const index = this.nodeIndex(step.id)\n if (index < 0) return null\n const list = this.writable('nodes') as FlowNode[]\n const [node] = list.splice(index, 1)\n this.index.nodes?.delete(step.id)\n this.reindex(this.index.nodes, list, index)\n return { type: 'addNode', node: node!, index }\n }\n case 'updateNode': {\n const index = this.nodeIndex(step.id)\n if (index < 0) return null\n const node = this.nodes[index]!\n const keys = Object.keys(step.patch) as (keyof FlowNode)[]\n if (keys.every((key) => sameValue(node[key], step.patch[key]))) return null\n const list = this.writable('nodes') as FlowNode[]\n list[index] = patched(node, step.patch)\n return { type: 'updateNode', id: step.id, patch: previous(node, step.patch) }\n }\n case 'addEdge': {\n if (this.getEdge(step.edge.id)) return null\n const list = this.writable('edges') as FlowEdge[]\n const index = clampIndex(step.index, list.length)\n list.splice(index, 0, step.edge)\n this.reindex(this.index.edges, list, index)\n this.attach(step.edge)\n return { type: 'removeEdge', id: step.edge.id }\n }\n case 'removeEdge': {\n const index = this.edgeIndex(step.id)\n if (index < 0) return null\n const list = this.writable('edges') as FlowEdge[]\n const [edge] = list.splice(index, 1)\n this.index.edges?.delete(step.id)\n this.reindex(this.index.edges, list, index)\n this.detach(edge!)\n return { type: 'addEdge', edge: edge!, index }\n }\n case 'updateEdge': {\n const index = this.edgeIndex(step.id)\n if (index < 0) return null\n const edge = this.edges[index]!\n const keys = Object.keys(step.patch) as (keyof FlowEdge)[]\n if (keys.every((key) => sameValue(edge[key], step.patch[key]))) return null\n const list = this.writable('edges') as FlowEdge[]\n list[index] = patched(edge, step.patch)\n if ('source' in step.patch || 'target' in step.patch) {\n this.detach(edge)\n this.attach(list[index]!)\n }\n return { type: 'updateEdge', id: step.id, patch: previous(edge, step.patch) }\n }\n }\n }\n}\n\nfunction clampIndex(index: number | undefined, length: number) {\n if (index == null) return length\n return Math.max(0, Math.min(length, index))\n}\n\n/** Applies steps to a document; steps that no longer apply are skipped. */\nexport function applyFlowSteps(doc: FlowDocument, steps: readonly FlowStep[]) {\n const tr = new FlowTransaction(doc)\n for (const step of steps) tr.step(step)\n return tr\n}\n\nconst targetOf = (step: FlowStep) => {\n switch (step.type) {\n case 'addNode':\n return `n:${step.node.id}`\n case 'addEdge':\n return `e:${step.edge.id}`\n case 'removeNode':\n case 'updateNode':\n return `n:${step.id}`\n case 'removeEdge':\n case 'updateEdge':\n return `e:${step.id}`\n }\n}\n\n/**\n * Folds updates of the same node or edge into one, as long as nothing\n * adds or removes it in between. Updates of different targets commute, so\n * the result applies the same as the original list.\n */\nexport function compactFlowSteps(steps: readonly FlowStep[]): FlowStep[] {\n const out: (FlowStep | null)[] = []\n const lastUpdate = new Map<string, number>()\n for (const step of steps) {\n const target = targetOf(step)\n if (step.type === 'updateNode' || step.type === 'updateEdge') {\n const at = lastUpdate.get(target)\n if (at != null) {\n const prev = out[at] as typeof step\n out[at] = { ...prev, patch: { ...prev.patch, ...step.patch } } as FlowStep\n continue\n }\n lastUpdate.set(target, out.length)\n } else {\n lastUpdate.delete(target)\n }\n out.push(step)\n }\n return out.filter((step): step is FlowStep => step != null)\n}\n\nlet warnedUncancellable = false\n/** Says once that cancelling a change kept out of the history does nothing. */\nfunction warnUncancellable(origin: unknown) {\n // the app's bundler replaces this, as for Vue's own warnings\n if (process.env.NODE_ENV === 'production' || warnedUncancellable) return\n warnedUncancellable = true\n console.warn(\n `[@dou-ui/flow] a change kept out of the history can't be cancelled; it goes ahead (meta.origin: ${JSON.stringify(origin ?? null)}). Undo, redo, other people's changes and the marks of comments are such changes: skip them in the hook by meta.origin`,\n )\n}\n"],"mappings":";AA8BA,SAAS,QAA0B,MAAS,OAAoB;CAC9D,MAAM,OAAO,EAAE,GAAG,KAAK;CACvB,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAAG;EACpC,MAAM,QAAS,MAAkC;EACjD,IAAI,UAAU,KAAA,GAAW,OAAO,KAAK;OAChC,KAAK,OAAO;CACnB;CACA,OAAO;AACT;;AAGA,SAAS,SAA2B,MAAS,OAA2B;CACtE,MAAM,MAA+B,CAAC;CACtC,KAAK,MAAM,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AsB;CACtB,QAAQ,KACN,mGAAmG,KAAK,UAAU,UAAU,IAAI,EAAE,uHACpI;AACF"}
|
package/dist/document.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { portsOf } from "./core/node-types.js";
|
|
2
|
-
import { defaultNode } from "./components/default-node2.js";
|
|
3
2
|
import { resolveFlowExtensions } from "./core/extension.js";
|
|
3
|
+
import { defaultNode } from "./components/default-node2.js";
|
|
4
4
|
import { flowKit } from "./kit.js";
|
|
5
5
|
// src/document.ts
|
|
6
6
|
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|