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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/collaboration/index.js +39 -2
  2. package/dist/collaboration/index.js.map +1 -1
  3. package/dist/components/default-node.js.map +1 -1
  4. package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js +4 -4
  5. package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  6. package/dist/components/flow-port.js.map +1 -1
  7. package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js +7 -42
  8. package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js.map +1 -1
  9. package/dist/components/node-view.js.map +1 -1
  10. package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js +2 -2
  11. package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js.map +1 -1
  12. package/dist/components/port-view.js +6 -0
  13. package/dist/components/port-view.js.map +1 -0
  14. package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js +60 -0
  15. package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js.map +1 -0
  16. package/dist/core/model.js.map +1 -1
  17. package/dist/core/node-types.js +6 -2
  18. package/dist/core/node-types.js.map +1 -1
  19. package/dist/flow-editor.js.map +1 -1
  20. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +24 -0
  21. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/style.css +1 -1
  24. package/dist/types/components/flow-port.vue.d.ts +8 -2
  25. package/dist/types/components/port-view.vue.d.ts +10 -0
  26. package/dist/types/components/port.d.ts +2 -2
  27. package/dist/types/core/model.d.ts +9 -0
  28. package/dist/types/core/node-types.d.ts +2 -0
  29. package/dist/types/index.d.ts +1 -1
  30. package/dist/whiteboard/board-node.js.map +1 -1
  31. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +27 -11
  32. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  33. package/package.json +3 -3
@@ -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=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,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"}
@@ -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 * 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\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":";AAwHA,IAAa,uBAAqC;CAAE,SAAS;CAAG,OAAO,CAAC;CAAG,OAAO,CAAC;AAAE;AACrF,IAAa,wBAAuC;CAAE,OAAO,CAAC;CAAG,OAAO,CAAC;AAAE;AAE3E,IAAI,UAAU;;AAGd,SAAgB,SAAS,SAAS,KAAK;CACrC,WAAW,UAAU,KAAK;CAC1B,MAAM,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CAC7C,MAAM,SAAS,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;CACpD,OAAO,GAAG,SAAS,OAAO,QAAQ,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,IAAI;AACpE"}
1
+ {"version":3,"file":"model.js","names":[],"sources":["../../src/core/model.ts"],"sourcesContent":["/*\n * The document a flow editor edits: plain, serialisable data, bound with\n * `v-model`. Positions are canvas coordinates in px, from the top left of a\n * node. Ports are not stored; a node type declares them, and edges refer to\n * them by id.\n */\n\nexport type FlowData = Record<string, unknown>\n\nexport interface FlowNode<Data extends FlowData = FlowData> {\n id: string\n /** A registered node type; `'default'` when left out. */\n type?: string\n x: number\n y: number\n /** Only stored for nodes that can be resized; otherwise the content decides. */\n width?: number\n height?: number\n data?: Data\n /** A locked node cannot be moved or deleted. */\n locked?: boolean\n /**\n * The container node, e.g. a group, this node sits in. Its `x` and `y`\n * stay canvas coordinates; moving the container moves it along.\n */\n parent?: string\n /**\n * Stacking order among nodes that aren't containers: higher is drawn on\n * top. Nodes without it count as `0`; equal ones keep the document order.\n */\n z?: number\n /**\n * The ids of the comment threads about this node, see the editor's\n * `comments`. Kept when the node is deleted and brought back by undo.\n */\n comments?: string[]\n /**\n * 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"}
@@ -9,6 +9,8 @@ var portSide = (port) => port.side ?? (port.kind === "input" ? "left" : "right")
9
9
  /**
10
10
  * The ports of `ports: 'sides'`: an output and an input in the middle of
11
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.
12
14
  * `right` and `left-in` come first, so a node added after another joins it
13
15
  * left to right.
14
16
  */
@@ -20,7 +22,8 @@ var sidePorts = [...[
20
22
  ].map((side) => ({
21
23
  id: side,
22
24
  kind: "output",
23
- side
25
+ side,
26
+ visible: "hover"
24
27
  })), ...[
25
28
  "left",
26
29
  "top",
@@ -30,7 +33,8 @@ var sidePorts = [...[
30
33
  id: `${side}-in`,
31
34
  kind: "input",
32
35
  side,
33
- max: Number.POSITIVE_INFINITY
36
+ max: Number.POSITIVE_INFINITY,
37
+ visible: "connecting"
34
38
  }))];
35
39
  function portsOf(spec, node) {
36
40
  const ports = spec?.ports;
@@ -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 /**\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 * `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 })),\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 })),\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;;;;;;;AAQjD,IAAa,YAAqC,CAChD,GAAI;CAAC;CAAS;CAAU;CAAQ;AAAK,CAAC,CAAW,KAAK,UAAU;CAC9D,IAAI;CACJ,MAAM;CACN;AACF,EAAE,GACF,GAAI;CAAC;CAAQ;CAAO;CAAS;AAAQ,CAAC,CAAW,KAAK,UAAU;CAC9D,IAAI,GAAG,KAAK;CACZ,MAAM;CACN;CACA,KAAK,OAAO;AACd,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"}
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,E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