@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.
Files changed (98) hide show
  1. package/dist/collaboration/index.js +114 -6
  2. package/dist/collaboration/index.js.map +1 -1
  3. package/dist/comments.js +257 -0
  4. package/dist/comments.js.map +1 -0
  5. package/dist/components/default-node.js.map +1 -1
  6. package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js +4 -4
  7. package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  8. package/dist/components/flow-comments.js +6 -0
  9. package/dist/components/flow-comments.js.map +1 -0
  10. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +218 -0
  11. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
  12. package/dist/components/flow-port.js.map +1 -1
  13. package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js +7 -42
  14. package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js.map +1 -1
  15. package/dist/components/flow-toolbar.js.map +1 -1
  16. package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js +300 -9
  17. package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  18. package/dist/components/node-view.js.map +1 -1
  19. package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js +2 -2
  20. package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js.map +1 -1
  21. package/dist/components/port-view.js +6 -0
  22. package/dist/components/port-view.js.map +1 -0
  23. package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js +60 -0
  24. package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js.map +1 -0
  25. package/dist/context.js.map +1 -1
  26. package/dist/core/extension.js.map +1 -1
  27. package/dist/core/history.js +26 -0
  28. package/dist/core/history.js.map +1 -1
  29. package/dist/core/model.js.map +1 -1
  30. package/dist/core/node-types.js +39 -1
  31. package/dist/core/node-types.js.map +1 -1
  32. package/dist/core/transaction.js +5 -4
  33. package/dist/core/transaction.js.map +1 -1
  34. package/dist/document.js +1 -1
  35. package/dist/export/color.js +49 -6
  36. package/dist/export/color.js.map +1 -1
  37. package/dist/export/context.js +16 -9
  38. package/dist/export/context.js.map +1 -1
  39. package/dist/export/draw.js +6 -5
  40. package/dist/export/draw.js.map +1 -1
  41. package/dist/export/render.js +78 -0
  42. package/dist/export/render.js.map +1 -0
  43. package/dist/flow-editor.js.map +1 -1
  44. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +757 -129
  45. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  46. package/dist/index.js +5 -4
  47. package/dist/index.js.map +1 -1
  48. package/dist/kit.js +1 -1
  49. package/dist/locale.js +102 -3
  50. package/dist/locale.js.map +1 -1
  51. package/dist/style.css +1 -1
  52. package/dist/style.js +2 -1
  53. package/dist/types/collaboration/index.d.ts +32 -4
  54. package/dist/types/comments.d.ts +73 -0
  55. package/dist/types/components/flow-comments.vue.d.ts +35 -0
  56. package/dist/types/components/flow-port.vue.d.ts +8 -2
  57. package/dist/types/components/port-view.vue.d.ts +10 -0
  58. package/dist/types/components/port.d.ts +2 -2
  59. package/dist/types/context.d.ts +48 -1
  60. package/dist/types/core/extension.d.ts +9 -1
  61. package/dist/types/core/history.d.ts +10 -0
  62. package/dist/types/core/menu.d.ts +60 -0
  63. package/dist/types/core/model.d.ts +22 -0
  64. package/dist/types/core/node-types.d.ts +18 -2
  65. package/dist/types/core/transaction.d.ts +2 -1
  66. package/dist/types/export/color.d.ts +6 -1
  67. package/dist/types/export/render.d.ts +27 -0
  68. package/dist/types/flow-editor.vue.d.ts +11 -1
  69. package/dist/types/index.d.ts +36 -7
  70. package/dist/types/locale.d.ts +27 -1
  71. package/dist/types/whiteboard/board-node.vue.d.ts +5 -0
  72. package/dist/types/whiteboard/colors.d.ts +36 -0
  73. package/dist/types/whiteboard/index.d.ts +2 -2
  74. package/dist/types/whiteboard/model.d.ts +24 -14
  75. package/dist/types/whiteboard/state.d.ts +2 -0
  76. package/dist/types/whiteboard/toolbar.d.ts +46 -0
  77. package/dist/whiteboard/board-node.js.map +1 -1
  78. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +76 -20
  79. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  80. package/dist/whiteboard/colors.js +84 -0
  81. package/dist/whiteboard/colors.js.map +1 -0
  82. package/dist/whiteboard/connector.js +47 -13
  83. package/dist/whiteboard/connector.js.map +1 -1
  84. package/dist/whiteboard/draw.js +26 -9
  85. package/dist/whiteboard/draw.js.map +1 -1
  86. package/dist/whiteboard/index.js +2 -1
  87. package/dist/whiteboard/kit.js +65 -8
  88. package/dist/whiteboard/kit.js.map +1 -1
  89. package/dist/whiteboard/model.js +5 -31
  90. package/dist/whiteboard/model.js.map +1 -1
  91. package/dist/whiteboard/state.js +6 -1
  92. package/dist/whiteboard/state.js.map +1 -1
  93. package/dist/whiteboard/toolbar.js +296 -0
  94. package/dist/whiteboard/toolbar.js.map +1 -0
  95. package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
  96. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
  97. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  98. package/package.json +3 -3
@@ -0,0 +1,73 @@
1
+ import { type CommentAction, type CommentAuthor, type CommentThread } from 'dou-ui';
2
+ import { type ComputedRef, type Ref, type ShallowRef } from 'vue';
3
+ import type { FlowCommentAnchor, FlowEditorEmits, FlowEditorProps } from './context';
4
+ import { type FlowExtension } from './core/extension';
5
+ import type { FlowDocument, FlowSelection, Point } from './core/model';
6
+ import type { FlowTransaction, FlowTransactionMeta } from './core/transaction';
7
+ import type { FlowMessages } from './locale';
8
+ type Emit = <K extends keyof FlowEditorEmits>(event: K, ...args: FlowEditorEmits[K]) => void;
9
+ /** The comments, as the editor's parts see them. */
10
+ export interface FlowComments {
11
+ enabled: ComputedRef<boolean>;
12
+ /** Threads can be started and replied to. */
13
+ writable: ComputedRef<boolean>;
14
+ threads: ComputedRef<readonly CommentThread[]>;
15
+ author: ComputedRef<CommentAuthor | undefined>;
16
+ /** The thread open now. */
17
+ active: ComputedRef<string | null>;
18
+ /** What a thread being started is about, until its first comment is sent. */
19
+ pending: ShallowRef<FlowCommentAnchor | null>;
20
+ /** Whether the reply box of the thread being started takes the focus. */
21
+ pendingFocus: ShallowRef<boolean>;
22
+ /** Goes up when the open thread should take the focus, ready for a reply. */
23
+ focusRequest: ShallowRef<number>;
24
+ /**
25
+ * The open threads on each node and edge, oldest first; a node's leave
26
+ * out those pinned to a point on it, which are in `pins`.
27
+ */
28
+ openOn: ComputedRef<{
29
+ nodes: Map<string, string[]>;
30
+ edges: Map<string, string[]>;
31
+ pins: FlowCommentPin[];
32
+ }>;
33
+ start: (anchor?: FlowCommentAnchor | null, focus?: boolean) => boolean;
34
+ /** Opens a thread, with the focus in its reply box when `focus`. */
35
+ show: (id: string, focus: boolean) => void;
36
+ apply: (action: CommentAction) => void;
37
+ open: (id: string | null) => void;
38
+ close: () => void;
39
+ /** Whether this editor opened the thread `id`, rather than the app. */
40
+ openedHere: (id: string | null) => boolean;
41
+ }
42
+ /** An open thread pinned to a point on a node. */
43
+ export interface FlowCommentPin {
44
+ thread: string;
45
+ node: string;
46
+ at: Point;
47
+ /** Its number on the node: its place among the node's pins, from 1, oldest first, resolved ones counted. */
48
+ number: number;
49
+ }
50
+ type MarkPatch = {
51
+ comments: string[] | undefined;
52
+ commentPins?: Record<string, Point> | undefined;
53
+ };
54
+ /** A point within a node, kept between 0 and 1; `null` when it isn't one. */
55
+ export declare function pinPoint(at: unknown): Point | null;
56
+ export declare function useFlowComments(options: {
57
+ props: FlowEditorProps;
58
+ emit: Emit;
59
+ doc: Ref<FlowDocument>;
60
+ selection: Ref<FlowSelection>;
61
+ messages: ComputedRef<FlowMessages>;
62
+ transact: (fn: (tr: FlowTransaction) => void, meta?: FlowTransactionMeta) => FlowTransaction;
63
+ /** Keeps a change kept out of undo on a node or edge as undo and redo bring it back. */
64
+ carry: (anchor: FlowCommentAnchor, patch: MarkPatch) => void;
65
+ /** The open threads a node's marker counts: a collapsed container's take in those inside it. */
66
+ shownOn: (anchor: FlowCommentAnchor) => string[] | undefined;
67
+ }): {
68
+ comments: FlowComments;
69
+ extension: FlowExtension;
70
+ anchors: () => Record<string, FlowCommentAnchor | null>;
71
+ anchorOf: (id: string) => FlowCommentAnchor | null;
72
+ };
73
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { FlowComments } from '../comments';
2
+ import type { FlowCommentAnchor } from '../context';
3
+ import { type FlowMessages } from '../locale';
4
+ export interface FlowCommentMarker {
5
+ key: string;
6
+ anchor: FlowCommentAnchor;
7
+ /** The open threads there, oldest first, counted on the marker; empty for a thread being started. */
8
+ threads: string[];
9
+ /** The threads its card shows: the open ones, and a resolved one opened from outside. */
10
+ shown: string[];
11
+ /** A thread is being started here. */
12
+ pending: boolean;
13
+ /** Where it goes, in px within the editor. */
14
+ x: number;
15
+ y: number;
16
+ /** Above an edge's label: a finger's target keeps clear of the label. */
17
+ lifted: boolean;
18
+ /**
19
+ * A pin on a point of a node: its place among the open pins there, from
20
+ * 1; `0` for one being started or a resolved one opened from outside.
21
+ */
22
+ number?: number;
23
+ /** The name of the node it is on, for screen readers. */
24
+ node?: string;
25
+ }
26
+ type __VLS_Props = {
27
+ comments: FlowComments;
28
+ markers: FlowCommentMarker[];
29
+ messages: FlowMessages;
30
+ /** Gives the focus back to what a thread is about, after the card closes. */
31
+ restore: (anchor: FlowCommentAnchor | null) => void;
32
+ };
33
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
34
+ declare const _default: typeof __VLS_export;
35
+ export default _default;
@@ -1,8 +1,14 @@
1
+ import type { FlowPortVisible } from '../core/model';
1
2
  type __VLS_Props = {
2
3
  /** The id of one of the node's ports. */
3
4
  id: string;
4
- /** @internal placed by the editor, not by the node's component */
5
- auto?: boolean;
5
+ /**
6
+ * When the port shows: `always`; `hover`, on a hovered or selected node,
7
+ * or one with the keyboard focus in it (a field being typed in);
8
+ * or `connecting`, only while an edge is drawn. Never shown in a
9
+ * readonly editor. Defaults to the port's own `visible`, else `always`.
10
+ */
11
+ visible?: FlowPortVisible;
6
12
  };
7
13
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
14
  declare const _default: typeof __VLS_export;
@@ -0,0 +1,10 @@
1
+ import type { FlowPortVisible } from '../core/model';
2
+ type __VLS_Props = {
3
+ id: string;
4
+ visible?: FlowPortVisible;
5
+ /** placed by the editor, not by the node's component */
6
+ auto?: boolean;
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const _default: typeof __VLS_export;
10
+ export default _default;
@@ -1,7 +1,7 @@
1
1
  export declare const DouFlowPort: import("dou-ui").WithInstall<import("vue").DefineComponent<{
2
2
  id: string;
3
- auto?: boolean;
3
+ visible?: import("../index.js").FlowPortVisible;
4
4
  }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
5
5
  id: string;
6
- auto?: boolean;
6
+ visible?: import("../index.js").FlowPortVisible;
7
7
  }> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, import("vue").HTMLAttributes>;
@@ -1,4 +1,4 @@
1
- import type { ContextMenuItem } from 'dou-ui';
1
+ import type { CommentAction, CommentAuthor, CommentThread, ContextMenuItem } from 'dou-ui';
2
2
  import type { FlowExportOptions, FlowImageOptions } from './export/draw';
3
3
  import type { FlowTree } from './core/groups';
4
4
  import { type ComputedRef, type InjectionKey, type Ref, type ShallowRef } from 'vue';
@@ -92,7 +92,33 @@ export interface FlowEditorProps {
92
92
  ariaLabel?: string;
93
93
  /** Texts to change; only the ones given are replaced. */
94
94
  messages?: FlowMessagesOverride;
95
+ /**
96
+ * The comment threads, bound with `v-model:comments`. The node or edge a
97
+ * thread is about keeps the thread's id in its `comments`. Left out,
98
+ * there are no comments.
99
+ */
100
+ comments?: CommentThread[];
101
+ /** Who is commenting. Without it comments can be read but not written. */
102
+ author?: CommentAuthor;
103
+ /** The thread open now, bound with `v-model:activeComment`. */
104
+ activeComment?: string | null;
105
+ /** Threads can be started and replied to; also while `readonly`. On by default. */
106
+ commentable?: boolean;
95
107
  }
108
+ /**
109
+ * What a comment thread is about: a node, a point on a node, or an edge.
110
+ * `at` pins the thread to that point, as fractions of the node's width and
111
+ * height from its top left, 0 to 1 (not canvas px, unlike other `at`s).
112
+ * `number` is the pin's number on the node, as drawn: read from
113
+ * `getCommentAnchors`, left out when starting one.
114
+ */
115
+ export type FlowCommentAnchor = {
116
+ node: string;
117
+ at?: Point;
118
+ number?: number;
119
+ } | {
120
+ edge: string;
121
+ };
96
122
  export interface FlowEditorEmits {
97
123
  /** Every change to the document, with its steps; `update:modelValue` follows. */
98
124
  transaction: [tr: FlowTransaction];
@@ -101,6 +127,10 @@ export interface FlowEditorEmits {
101
127
  * says why, and the editor shows it and reads it out.
102
128
  */
103
129
  transactionCancel: [tr: FlowTransaction];
130
+ 'update:comments': [threads: CommentThread[]];
131
+ 'update:activeComment': [id: string | null];
132
+ /** A change to the comments made here: to send to a server, notify people, keep a log. */
133
+ commentAction: [action: CommentAction];
104
134
  nodeClick: [node: FlowNode, event: MouseEvent];
105
135
  nodeDblclick: [node: FlowNode, event: MouseEvent];
106
136
  nodeContextmenu: [node: FlowNode, event: MouseEvent];
@@ -171,6 +201,19 @@ export interface FlowEditorExpose {
171
201
  readonly staleEdges: string[];
172
202
  /** Removes the stale edges as one undo step; returns how many. */
173
203
  removeStaleEdges: () => number;
204
+ /**
205
+ * Opens the open thread on a node or edge (the selected one when left
206
+ * out), ready to reply, or starts one there; `false` when there is no such
207
+ * node or edge, or nothing to open and comments can't be written. With
208
+ * `at`, it always starts a new thread pinned to that point of the node.
209
+ * `focus: false` leaves the focus where it is instead of putting it in the
210
+ * reply box, for a tap that shouldn't bring up a phone's keyboard.
211
+ */
212
+ comment: (anchor?: FlowCommentAnchor, options?: {
213
+ focus?: boolean;
214
+ }) => boolean;
215
+ /** What each thread is about; `null` when its node or edge is gone. Not reactive. */
216
+ getCommentAnchors: () => Record<string, FlowCommentAnchor | null>;
174
217
  /**
175
218
  * Adds a node of a type with its defaults and selects it, as one undo
176
219
  * step; returns its id. See `FlowInsertOptions` for where it goes.
@@ -277,6 +320,10 @@ export interface FlowEditorContext {
277
320
  /** A port type's color as CSS. */
278
321
  colorOf: (spec: PortTypeSpec | undefined) => string | undefined;
279
322
  getNodeRect: FlowEditorExpose['getNodeRect'];
323
+ /** See `FlowEditorExpose.comment`. */
324
+ comment: FlowEditorExpose['comment'];
325
+ /** Comment threads can be started: the editor has `comments`, an `author` and is `commentable`. */
326
+ canComment: ComputedRef<boolean>;
280
327
  exportSVG: FlowEditorExpose['exportSVG'];
281
328
  exportPNG: FlowEditorExpose['exportPNG'];
282
329
  tidy: FlowEditorExpose['tidy'];
@@ -22,6 +22,13 @@ export interface FlowHistoryHandler {
22
22
  redo: () => boolean;
23
23
  canUndo: () => boolean;
24
24
  canRedo: () => boolean;
25
+ /**
26
+ * Forget the changes of `group` not yet undone, e.g. a drag cancelled with
27
+ * Escape: the editor has already put them back, outside the history.
28
+ */
29
+ drop?: (group: string) => void;
30
+ /** A gesture ended (a drag, a resize): the next change starts a new undo step. */
31
+ close?: () => void;
25
32
  }
26
33
  /** A press on the editor that an extension may take over, e.g. a drawing tool. */
27
34
  export interface FlowPress {
@@ -98,7 +105,8 @@ export interface FlowExtension {
98
105
  /**
99
106
  * Asked first when the canvas or a node is pressed with the main button or
100
107
  * one finger, in priority order. Return handlers to take the press over;
101
- * the editor then doesn't select, drag or pan for it.
108
+ * the editor then doesn't select, drag or pan for it. Asked while
109
+ * read-only too: check `context.readonly` before changing the document.
102
110
  */
103
111
  press?: (context: FlowExtensionContext, press: FlowPress) => FlowPressHandler | void;
104
112
  /** Runs once the editor is mounted. Return a function to run when it unmounts. */
@@ -20,5 +20,15 @@ export declare class FlowHistory {
20
20
  tr: FlowTransaction;
21
21
  selection: FlowSelection;
22
22
  } | null;
23
+ /**
24
+ * Gives a change kept out of undo to a node or edge as undo and redo
25
+ * bring it back, too: comments started on a new node stay on it when its
26
+ * adding is undone and redone.
27
+ */
28
+ carry(target: {
29
+ node: string;
30
+ } | {
31
+ edge: string;
32
+ }, patch: Record<string, unknown>): void;
23
33
  clear(): void;
24
34
  }
@@ -14,6 +14,56 @@ export type FlowMenuTarget = {
14
14
  kind: 'canvas';
15
15
  point: Point;
16
16
  };
17
+ /** One preset swatch inside a toolbar color popover. */
18
+ export interface FlowToolbarColorPreset {
19
+ /** Stored value passed to `select`, e.g. `'blue'`. */
20
+ value: string;
21
+ /** Accessible name and tooltip, e.g. `'蓝色'`. */
22
+ label: string;
23
+ /** CSS color painted on the swatch. */
24
+ swatch: string;
25
+ }
26
+ /** A color picker popover opened by a toolbar button. */
27
+ export interface FlowToolbarColor {
28
+ /**
29
+ * Current value across the selection:
30
+ * - `undefined`: every selected item uses the default
31
+ * - `null`: selected items differ (mixed)
32
+ * - string: shared preset, none value (e.g. `'none'`), or custom CSS color
33
+ */
34
+ value: string | null | undefined;
35
+ /** How swatches and the button indicator look. Defaults to `'stroke'`. */
36
+ kind?: 'fill' | 'stroke' | 'text';
37
+ /** CSS color shown on the button indicator; omitted for default, none or mixed. */
38
+ swatch?: string;
39
+ /** Whether the selection is explicitly in the "none" state (e.g. borderless or transparent). */
40
+ none?: boolean;
41
+ /** Label for the default swatch that clears the color (`select(undefined)`). */
42
+ defaultLabel: string;
43
+ /** Optional "none" option, such as "无边框" or "无填充". */
44
+ noneOption?: {
45
+ /** Stored value passed to `select`, e.g. `'none'`. */
46
+ value: string;
47
+ /** Visible text and accessible label. */
48
+ label: string;
49
+ /** Optional icon for the none action button. */
50
+ icon?: Component;
51
+ };
52
+ /** One-click preset swatches shown before custom color picking. */
53
+ presets: FlowToolbarColorPreset[];
54
+ /** Label for toggling the custom `DouColorPanel`. */
55
+ customLabel: string;
56
+ /**
57
+ * Applies a chosen color, `'none'`, or `undefined` (default).
58
+ * `options.live` is `true` while dragging in the custom color panel so
59
+ * consecutive updates can share an undo group.
60
+ */
61
+ select: (value: string | undefined, options?: {
62
+ live?: boolean;
63
+ }) => void;
64
+ /** Called when the color popover or custom color panel closes, ending any open live-drag group. */
65
+ close?: () => void;
66
+ }
17
67
  export interface FlowToolbarItem {
18
68
  /** Unique within the toolbar. */
19
69
  key: string;
@@ -37,4 +87,14 @@ export interface FlowToolbarItem {
37
87
  * click. Give the items `checked` to mark the one in use.
38
88
  */
39
89
  children?: ContextMenuItem[];
90
+ /**
91
+ * Color swatches and custom color panel shown in a popover under the button
92
+ * instead of `run` or `children`.
93
+ */
94
+ color?: FlowToolbarColor;
95
+ /**
96
+ * Shown while the editor is `readonly` too, for what doesn't change the
97
+ * flow, such as commenting; the other buttons are left out then.
98
+ */
99
+ showWhenReadonly?: boolean;
40
100
  }
@@ -21,6 +21,17 @@ export interface FlowNode<Data extends FlowData = FlowData> {
21
21
  * top. Nodes without it count as `0`; equal ones keep the document order.
22
22
  */
23
23
  z?: number;
24
+ /**
25
+ * The ids of the comment threads about this node, see the editor's
26
+ * `comments`. Kept when the node is deleted and brought back by undo.
27
+ */
28
+ comments?: string[];
29
+ /**
30
+ * Where on the node each pinned thread is, by thread id: `x` and `y` are
31
+ * fractions of the node's width and height from its top left, 0 to 1, so
32
+ * a pin moves and scales with the node. The ids are in `comments` too.
33
+ */
34
+ commentPins?: Record<string, Point>;
24
35
  }
25
36
  export interface FlowEndpoint {
26
37
  node: string;
@@ -44,6 +55,8 @@ export interface FlowEdge<Data extends FlowData = FlowData> {
44
55
  */
45
56
  points?: Point[];
46
57
  data?: Data;
58
+ /** The ids of the comment threads about this edge, see the editor's `comments`. */
59
+ comments?: string[];
47
60
  }
48
61
  export interface FlowDocument {
49
62
  /** The version of the format; see `migrateDocument`. */
@@ -66,7 +79,16 @@ export interface FlowPortSpec {
66
79
  * number. A new edge on a full port replaces its oldest edge.
67
80
  */
68
81
  max?: number;
82
+ /**
83
+ * When the port shows: `always`; `hover`, on a hovered or selected node,
84
+ * or one with the keyboard focus in it (a field being typed in);
85
+ * or `connecting`, only while an edge is drawn. A `<DouFlowPort visible>`
86
+ * overrides it. Defaults to `always`.
87
+ */
88
+ visible?: FlowPortVisible;
69
89
  }
90
+ /** When a port shows, see `FlowPortSpec.visible`. */
91
+ export type FlowPortVisible = 'always' | 'hover' | 'connecting';
70
92
  /** Where the canvas is shown: `x` and `y` are the screen offset of the canvas origin. */
71
93
  export interface FlowViewport {
72
94
  x: number;
@@ -20,8 +20,13 @@ export interface NodeTypeSpec<Data extends FlowData = FlowData> {
20
20
  * component does not place are spread along their sides.
21
21
  */
22
22
  component?: Component;
23
- /** The node's ports, fixed or worked out from its data. */
24
- ports?: FlowPortSpec[] | ((node: FlowNode<Data>) => FlowPortSpec[]);
23
+ /**
24
+ * The node's ports, fixed or worked out from its data. `'sides'`: an
25
+ * output and an input in the middle of each side, all alike (see
26
+ * `sidePorts`); tidying lays such nodes out the way their edges are
27
+ * drawn and moves the edges' ends onto the sides that face each other.
28
+ */
29
+ ports?: FlowPortSpec[] | 'sides' | ((node: FlowNode<Data>) => FlowPortSpec[]);
25
30
  /** Data for a new node of this type. */
26
31
  defaults?: () => Data;
27
32
  /**
@@ -88,6 +93,15 @@ export interface NodePaletteSpec {
88
93
  /** Declares a node type, with the data type checked against its component. */
89
94
  export declare function defineNodeType<Data extends FlowData = FlowData>(spec: NodeTypeSpec<Data>): NodeTypeSpec<Data>;
90
95
  export declare const portSide: (port: FlowPortSpec) => PortSide;
96
+ /**
97
+ * The ports of `ports: 'sides'`: an output and an input in the middle of
98
+ * each side. Edges go from an output (`right`) to an input (`left-in`).
99
+ * Like a whiteboard shape's anchors, the outputs show on hover and the
100
+ * inputs only while an edge is drawn.
101
+ * `right` and `left-in` come first, so a node added after another joins it
102
+ * left to right.
103
+ */
104
+ export declare const sidePorts: readonly FlowPortSpec[];
91
105
  export declare function portsOf(spec: NodeTypeSpec | undefined, node: FlowNode): FlowPortSpec[];
92
106
  export type NodeResize = boolean | {
93
107
  minWidth?: number;
@@ -101,3 +115,5 @@ export declare function resizeOf(spec: NodeTypeSpec | undefined, node: FlowNode)
101
115
  export declare function labelOf(spec: NodeTypeSpec | undefined, node: FlowNode, messages: FlowMessages): string;
102
116
  /** The box `node` covers on screen, drawn at `rect`. */
103
117
  export declare function nodeBounds(spec: NodeTypeSpec, node: FlowNode, rect: Rect): Rect;
118
+ /** Warns once per page about a node type no one registered. Call only while developing. */
119
+ export declare function warnUnknownNodeType(type: string): void;
@@ -59,7 +59,8 @@ export declare class FlowTransaction {
59
59
  * editor fires `transactionCancel` and says why. For an extension's `transaction`
60
60
  * hook, e.g. to keep people from changing what they may not; hooks after
61
61
  * it don't run. A change kept out of the history (`meta.history: false`),
62
- * such as undo, redo or another person's, can't be cancelled and goes ahead.
62
+ * such as undo, redo, another person's or a comment's (`meta.origin`
63
+ * tells which), can't be cancelled and goes ahead.
63
64
  */
64
65
  cancel(reason?: string): this;
65
66
  /** Whether `cancel` stopped it. */
@@ -1,7 +1,12 @@
1
+ /**
2
+ * Whether `value` has safe CSS color syntax (no quotes, markup, CSS
3
+ * declarations, `url()`, or CSS-wide keywords like `inherit`).
4
+ */
5
+ export declare function isSafeCssColor(value: string): boolean;
1
6
  /**
2
7
  * A computed color as `rgb(…)`, `rgba(…)` or `#rrggbb`, which every SVG reader
3
8
  * understands. A canvas converts most colors as it parses them; colors it
4
9
  * keeps in another space (`oklab(…)`, `color(…)`) are painted on a pixel
5
- * and read back.
10
+ * and read back. Invalid or unsafe values return `''`.
6
11
  */
7
12
  export declare function plainColor(color: string): string;
@@ -0,0 +1,27 @@
1
+ import { type ResolvedColorMode } from 'dou-ui';
2
+ import { type AppContext } from 'vue';
3
+ import type { FlowEditorProps } from '../context';
4
+ import type { FlowDocument } from '../core/model';
5
+ import type { FlowExportOptions } from './draw';
6
+ export interface RenderFlowOptions extends Pick<FlowEditorProps, 'extensions' | 'nodeTypes' | 'edgeTypes' | 'edgeType' | 'portTypes' | 'direction' | 'messages'>, Omit<FlowExportOptions, 'range'> {
7
+ /** Light or dark colors; the page's own color mode by default. */
8
+ colorMode?: ResolvedColorMode;
9
+ /**
10
+ * The app context node components render in, for its locale, plugins and
11
+ * provides, e.g. `getCurrentInstance()!.appContext`. Defaults to the app
12
+ * `app.use(DouUI)` was called on.
13
+ */
14
+ appContext?: AppContext | null;
15
+ }
16
+ export interface RenderFlowImageOptions extends RenderFlowOptions {
17
+ /** Pixels per CSS pixel. Defaults to `2`. */
18
+ pixelRatio?: number;
19
+ }
20
+ /**
21
+ * The document as an SVG document, drawn as `exportSVG` draws it, without an
22
+ * editor on the page: for thumbnails and previews. Give it the same node,
23
+ * edge and port types as the editor that shows the document.
24
+ */
25
+ export declare function renderFlowSVG(document: FlowDocument, options?: RenderFlowOptions): Promise<string>;
26
+ /** The document as a PNG image, as `exportPNG` draws it, without an editor on the page. */
27
+ export declare function renderFlowPNG(document: FlowDocument, options?: RenderFlowImageOptions): Promise<Blob>;
@@ -12,6 +12,9 @@ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
12
12
  declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, FlowEditorExpose, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
13
13
  transaction: (tr: FlowTransaction) => any;
14
14
  transactionCancel: (tr: FlowTransaction) => any;
15
+ "update:comments": (threads: import("dou-ui").CommentThread[]) => any;
16
+ "update:activeComment": (id: string | null) => any;
17
+ commentAction: (action: import("dou-ui").CommentAction) => any;
15
18
  nodeClick: (node: FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
16
19
  nodeDblclick: (node: FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
17
20
  nodeContextmenu: (node: FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
@@ -27,6 +30,9 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, FlowE
27
30
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
28
31
  onTransaction?: ((tr: FlowTransaction) => any) | undefined;
29
32
  onTransactionCancel?: ((tr: FlowTransaction) => any) | undefined;
33
+ "onUpdate:comments"?: ((threads: import("dou-ui").CommentThread[]) => any) | undefined;
34
+ "onUpdate:activeComment"?: ((id: string | null) => any) | undefined;
35
+ onCommentAction?: ((action: import("dou-ui").CommentAction) => any) | undefined;
30
36
  onNodeClick?: ((node: FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
31
37
  onNodeDblclick?: ((node: FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
32
38
  onNodeContextmenu?: ((node: FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
@@ -40,10 +46,13 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, FlowE
40
46
  "onUpdate:selection"?: ((value: FlowSelection) => any) | undefined;
41
47
  "onUpdate:viewport"?: ((value: FlowViewport) => any) | undefined;
42
48
  }>, {
49
+ comments: import("dou-ui").CommentThread[];
43
50
  direction: "horizontal" | "vertical";
44
51
  grid: number;
45
52
  edgeType: string;
46
53
  readonly: boolean;
54
+ author: import("dou-ui").CommentAuthor;
55
+ bordered: boolean;
47
56
  simpleZoom: number;
48
57
  guides: boolean;
49
58
  minZoom: number;
@@ -52,7 +61,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, FlowE
52
61
  fitMinZoom: number;
53
62
  searchable: boolean;
54
63
  panOnScroll: boolean;
55
- bordered: boolean;
64
+ activeComment: string | null;
65
+ commentable: boolean;
56
66
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
57
67
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
58
68
  declare const _default: typeof __VLS_export;