@dou-ui/flow 0.1.0-alpha.6 → 0.1.0-alpha.8
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/core/node-types.js +28 -1
- package/dist/core/node-types.js.map +1 -1
- package/dist/flow-editor.js.map +1 -1
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +141 -10
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/core/node-types.d.ts +14 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/whiteboard/model.d.ts +0 -9
- package/dist/whiteboard/connector.js +5 -10
- package/dist/whiteboard/connector.js.map +1 -1
- package/dist/whiteboard/kit.js +5 -5
- package/dist/whiteboard/kit.js.map +1 -1
- package/dist/whiteboard/model.js +2 -30
- package/dist/whiteboard/model.js.map +1 -1
- package/package.json +3 -3
package/dist/core/node-types.js
CHANGED
|
@@ -6,9 +6,36 @@ 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
|
+
* `right` and `left-in` come first, so a node added after another joins it
|
|
13
|
+
* left to right.
|
|
14
|
+
*/
|
|
15
|
+
var sidePorts = [...[
|
|
16
|
+
"right",
|
|
17
|
+
"bottom",
|
|
18
|
+
"left",
|
|
19
|
+
"top"
|
|
20
|
+
].map((side) => ({
|
|
21
|
+
id: side,
|
|
22
|
+
kind: "output",
|
|
23
|
+
side
|
|
24
|
+
})), ...[
|
|
25
|
+
"left",
|
|
26
|
+
"top",
|
|
27
|
+
"right",
|
|
28
|
+
"bottom"
|
|
29
|
+
].map((side) => ({
|
|
30
|
+
id: `${side}-in`,
|
|
31
|
+
kind: "input",
|
|
32
|
+
side,
|
|
33
|
+
max: Number.POSITIVE_INFINITY
|
|
34
|
+
}))];
|
|
9
35
|
function portsOf(spec, node) {
|
|
10
36
|
const ports = spec?.ports;
|
|
11
37
|
if (!ports) return [];
|
|
38
|
+
if (ports === "sides") return sidePorts;
|
|
12
39
|
return typeof ports === "function" ? ports(node) : ports;
|
|
13
40
|
}
|
|
14
41
|
/** Whether a node can be resized, and its smallest size; `null` when it can't. */
|
|
@@ -34,6 +61,6 @@ function warnUnknownNodeType(type) {
|
|
|
34
61
|
unknownWarned.add(type);
|
|
35
62
|
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)`);
|
|
36
63
|
}
|
|
37
|
-
export { defineNodeType, labelOf, nodeBounds, portSide, portsOf, resizeOf, warnUnknownNodeType };
|
|
64
|
+
export { defineNodeType, labelOf, nodeBounds, portSide, portsOf, resizeOf, sidePorts, warnUnknownNodeType };
|
|
38
65
|
|
|
39
66
|
//# 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 * `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,GAC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