@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
package/dist/types/index.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
7
7
|
}> & Readonly<{
|
|
8
8
|
onTransaction?: ((tr: import("./index.js").FlowTransaction) => any) | undefined;
|
|
9
9
|
onTransactionCancel?: ((tr: import("./index.js").FlowTransaction) => any) | undefined;
|
|
10
|
+
"onUpdate:comments"?: ((threads: import("dou-ui").CommentThread[]) => any) | undefined;
|
|
11
|
+
"onUpdate:activeComment"?: ((id: string | null) => any) | undefined;
|
|
12
|
+
onCommentAction?: ((action: import("dou-ui").CommentAction) => any) | undefined;
|
|
10
13
|
onNodeClick?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
11
14
|
onNodeDblclick?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
12
15
|
onNodeContextmenu?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
@@ -22,6 +25,9 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
22
25
|
}>, import("./context").FlowEditorExpose, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
23
26
|
transaction: (tr: import("./index.js").FlowTransaction) => any;
|
|
24
27
|
transactionCancel: (tr: import("./index.js").FlowTransaction) => any;
|
|
28
|
+
"update:comments": (threads: import("dou-ui").CommentThread[]) => any;
|
|
29
|
+
"update:activeComment": (id: string | null) => any;
|
|
30
|
+
commentAction: (action: import("dou-ui").CommentAction) => any;
|
|
25
31
|
nodeClick: (node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
|
|
26
32
|
nodeDblclick: (node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
|
|
27
33
|
nodeContextmenu: (node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
|
|
@@ -35,10 +41,13 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
35
41
|
"update:selection": (value: import("./index.js").FlowSelection) => any;
|
|
36
42
|
"update:viewport": (value: import("./index.js").FlowViewport) => any;
|
|
37
43
|
}, import("vue").PublicProps, {
|
|
44
|
+
comments: import("dou-ui").CommentThread[];
|
|
38
45
|
direction: "horizontal" | "vertical";
|
|
39
46
|
grid: number;
|
|
40
47
|
edgeType: string;
|
|
41
48
|
readonly: boolean;
|
|
49
|
+
author: import("dou-ui").CommentAuthor;
|
|
50
|
+
bordered: boolean;
|
|
42
51
|
simpleZoom: number;
|
|
43
52
|
guides: boolean;
|
|
44
53
|
minZoom: number;
|
|
@@ -47,7 +56,8 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
47
56
|
fitMinZoom: number;
|
|
48
57
|
searchable: boolean;
|
|
49
58
|
panOnScroll: boolean;
|
|
50
|
-
|
|
59
|
+
activeComment: string | null;
|
|
60
|
+
commentable: boolean;
|
|
51
61
|
}, false, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
|
|
52
62
|
P: {};
|
|
53
63
|
B: {};
|
|
@@ -62,6 +72,9 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
62
72
|
}> & Readonly<{
|
|
63
73
|
onTransaction?: ((tr: import("./index.js").FlowTransaction) => any) | undefined;
|
|
64
74
|
onTransactionCancel?: ((tr: import("./index.js").FlowTransaction) => any) | undefined;
|
|
75
|
+
"onUpdate:comments"?: ((threads: import("dou-ui").CommentThread[]) => any) | undefined;
|
|
76
|
+
"onUpdate:activeComment"?: ((id: string | null) => any) | undefined;
|
|
77
|
+
onCommentAction?: ((action: import("dou-ui").CommentAction) => any) | undefined;
|
|
65
78
|
onNodeClick?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
66
79
|
onNodeDblclick?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
67
80
|
onNodeContextmenu?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
@@ -75,10 +88,13 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
75
88
|
"onUpdate:selection"?: ((value: import("./index.js").FlowSelection) => any) | undefined;
|
|
76
89
|
"onUpdate:viewport"?: ((value: import("./index.js").FlowViewport) => any) | undefined;
|
|
77
90
|
}>, import("./context").FlowEditorExpose, {}, {}, {}, {
|
|
91
|
+
comments: import("dou-ui").CommentThread[];
|
|
78
92
|
direction: "horizontal" | "vertical";
|
|
79
93
|
grid: number;
|
|
80
94
|
edgeType: string;
|
|
81
95
|
readonly: boolean;
|
|
96
|
+
author: import("dou-ui").CommentAuthor;
|
|
97
|
+
bordered: boolean;
|
|
82
98
|
simpleZoom: number;
|
|
83
99
|
guides: boolean;
|
|
84
100
|
minZoom: number;
|
|
@@ -87,7 +103,8 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
87
103
|
fitMinZoom: number;
|
|
88
104
|
searchable: boolean;
|
|
89
105
|
panOnScroll: boolean;
|
|
90
|
-
|
|
106
|
+
activeComment: string | null;
|
|
107
|
+
commentable: boolean;
|
|
91
108
|
}>;
|
|
92
109
|
__isFragment?: never;
|
|
93
110
|
__isTeleport?: never;
|
|
@@ -99,6 +116,9 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
99
116
|
}> & Readonly<{
|
|
100
117
|
onTransaction?: ((tr: import("./index.js").FlowTransaction) => any) | undefined;
|
|
101
118
|
onTransactionCancel?: ((tr: import("./index.js").FlowTransaction) => any) | undefined;
|
|
119
|
+
"onUpdate:comments"?: ((threads: import("dou-ui").CommentThread[]) => any) | undefined;
|
|
120
|
+
"onUpdate:activeComment"?: ((id: string | null) => any) | undefined;
|
|
121
|
+
onCommentAction?: ((action: import("dou-ui").CommentAction) => any) | undefined;
|
|
102
122
|
onNodeClick?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
103
123
|
onNodeDblclick?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
104
124
|
onNodeContextmenu?: ((node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any) | undefined;
|
|
@@ -114,6 +134,9 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
114
134
|
}>, import("./context").FlowEditorExpose, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
115
135
|
transaction: (tr: import("./index.js").FlowTransaction) => any;
|
|
116
136
|
transactionCancel: (tr: import("./index.js").FlowTransaction) => any;
|
|
137
|
+
"update:comments": (threads: import("dou-ui").CommentThread[]) => any;
|
|
138
|
+
"update:activeComment": (id: string | null) => any;
|
|
139
|
+
commentAction: (action: import("dou-ui").CommentAction) => any;
|
|
117
140
|
nodeClick: (node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
|
|
118
141
|
nodeDblclick: (node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
|
|
119
142
|
nodeContextmenu: (node: import("./index.js").FlowNode<import("./index.js").FlowData>, event: MouseEvent) => any;
|
|
@@ -127,10 +150,13 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
127
150
|
"update:selection": (value: import("./index.js").FlowSelection) => any;
|
|
128
151
|
"update:viewport": (value: import("./index.js").FlowViewport) => any;
|
|
129
152
|
}, string, {
|
|
153
|
+
comments: import("dou-ui").CommentThread[];
|
|
130
154
|
direction: "horizontal" | "vertical";
|
|
131
155
|
grid: number;
|
|
132
156
|
edgeType: string;
|
|
133
157
|
readonly: boolean;
|
|
158
|
+
author: import("dou-ui").CommentAuthor;
|
|
159
|
+
bordered: boolean;
|
|
134
160
|
simpleZoom: number;
|
|
135
161
|
guides: boolean;
|
|
136
162
|
minZoom: number;
|
|
@@ -139,7 +165,8 @@ export declare const DouFlowEditor: import("dou-ui").WithInstall<{
|
|
|
139
165
|
fitMinZoom: number;
|
|
140
166
|
searchable: boolean;
|
|
141
167
|
panOnScroll: boolean;
|
|
142
|
-
|
|
168
|
+
activeComment: string | null;
|
|
169
|
+
commentable: boolean;
|
|
143
170
|
}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
144
171
|
$slots: import("./context").FlowEditorSlots;
|
|
145
172
|
}), import("vue").HTMLAttributes>;
|
|
@@ -156,7 +183,7 @@ export declare const DouFlowMinimap: import("dou-ui").WithInstall<import("vue").
|
|
|
156
183
|
export { DouFlowPort };
|
|
157
184
|
export default DouFlowEditor;
|
|
158
185
|
export { useFlowEditor } from './context';
|
|
159
|
-
export type { FlowControlsProps, FlowEditorContext, FlowEditorEmits, FlowEditorExpose, FlowEditorProps, FlowInsertOptions, FlowMinimapProps, FlowNodePreview, FlowEditorSlots, FlowPanelPlacement, FlowSearchQuery, NodeMetrics, PortAnchor, PortState, } from './context';
|
|
186
|
+
export type { FlowCommentAnchor, FlowControlsProps, FlowEditorContext, FlowEditorEmits, FlowEditorExpose, FlowEditorProps, FlowInsertOptions, FlowMinimapProps, FlowNodePreview, FlowEditorSlots, FlowPanelPlacement, FlowSearchQuery, NodeMetrics, PortAnchor, PortState, } from './context';
|
|
160
187
|
export { flowLocales, useFlowMessages } from './locale';
|
|
161
188
|
export type { FlowMessages, FlowMessagesOverride } from './locale';
|
|
162
189
|
export { defaultNode } from './components/default-node';
|
|
@@ -164,11 +191,11 @@ export type { DefaultNodeData } from './components/default-node';
|
|
|
164
191
|
export { groupNode } from './components/group-node';
|
|
165
192
|
export type { GroupNodeData } from './components/group-node';
|
|
166
193
|
export { containerAt, FlowTree } from './core/groups';
|
|
167
|
-
export { defineNodeType, labelOf, portSide, portsOf, resizeOf } from './core/node-types';
|
|
194
|
+
export { defineNodeType, labelOf, portSide, portsOf, resizeOf, sidePorts } from './core/node-types';
|
|
168
195
|
export type { NodePaletteSpec, NodeResize, NodeTypeSpec, NodeViewProps } from './core/node-types';
|
|
169
|
-
export type { FlowMenuTarget, FlowToolbarItem } from './core/menu';
|
|
196
|
+
export type { FlowMenuTarget, FlowToolbarColor, FlowToolbarColorPreset, FlowToolbarItem, } from './core/menu';
|
|
170
197
|
export { createId, emptyDocument, emptySelection } from './core/model';
|
|
171
|
-
export type { FlowData, FlowDocument, FlowEdge, FlowEndpoint, FlowNode, FlowPortSpec, FlowSelection, FlowViewport, Point, PortSide, Rect, } from './core/model';
|
|
198
|
+
export type { FlowData, FlowDocument, FlowEdge, FlowEndpoint, FlowNode, FlowPortSpec, FlowPortVisible, FlowSelection, FlowViewport, Point, PortSide, Rect, } from './core/model';
|
|
172
199
|
export { checkDocument, migrateDocument } from './document';
|
|
173
200
|
export type { CheckDocumentOptions, DocumentProblem } from './document';
|
|
174
201
|
export { applyFlowSteps, compactFlowSteps, FlowTransaction } from './core/transaction';
|
|
@@ -180,6 +207,8 @@ export { flowKit } from './kit';
|
|
|
180
207
|
export type { FlowKitOptions } from './kit';
|
|
181
208
|
export { moveLayer } from './layers';
|
|
182
209
|
export { drawCard } from './export/draw';
|
|
210
|
+
export { renderFlowPNG, renderFlowSVG } from './export/render';
|
|
211
|
+
export type { RenderFlowImageOptions, RenderFlowOptions } from './export/render';
|
|
183
212
|
export type { FlowExportOptions, FlowImageOptions } from './export/draw';
|
|
184
213
|
export type { FlowDrawContext, FlowDrawTextOptions } from './export/context';
|
|
185
214
|
export type { LayerMove } from './layers';
|
package/dist/types/locale.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { WhiteboardArrow, WhiteboardDash, WhiteboardRoute } from './whiteboard/model';
|
|
1
|
+
import type { WhiteboardArrow, WhiteboardDash, WhiteboardPaletteColor, WhiteboardRoute } from './whiteboard/model';
|
|
2
|
+
import { type Tone } from 'dou-ui';
|
|
2
3
|
import { type MaybeRefOrGetter } from 'vue';
|
|
3
4
|
export interface FlowMessages {
|
|
4
5
|
/** The canvas's accessible description. */
|
|
@@ -98,6 +99,12 @@ export interface FlowMessages {
|
|
|
98
99
|
noTarget: string;
|
|
99
100
|
/** `{count}` edges no longer fit their ports. */
|
|
100
101
|
stale: string;
|
|
102
|
+
/** Starts a discussion about a node or an edge. */
|
|
103
|
+
comment: string;
|
|
104
|
+
/** The marker of the discussions on a node or an edge; `{count}` of them are open. */
|
|
105
|
+
comments: string;
|
|
106
|
+
/** A thread pinned to a point on a node; `{number}` is its number there, `{node}` the node's name. */
|
|
107
|
+
commentPin: string;
|
|
101
108
|
/** Why an edge was refused, announced when it is dropped. */
|
|
102
109
|
refused: {
|
|
103
110
|
direction: string;
|
|
@@ -131,6 +138,8 @@ export interface FlowMessages {
|
|
|
131
138
|
named: string;
|
|
132
139
|
pen: string;
|
|
133
140
|
eraser: string;
|
|
141
|
+
/** The tool that pins a comment where a node is clicked. */
|
|
142
|
+
comment: string;
|
|
134
143
|
/** The toolbar button that inserts an image. */
|
|
135
144
|
image: string;
|
|
136
145
|
/** A pen stroke. */
|
|
@@ -158,6 +167,23 @@ export interface FlowMessages {
|
|
|
158
167
|
routeSet: string;
|
|
159
168
|
dashSet: string;
|
|
160
169
|
arrowSet: string;
|
|
170
|
+
/** Color buttons' names; `{value}` is the current color, default, none or mixed. */
|
|
171
|
+
fillOf: string;
|
|
172
|
+
strokeOf: string;
|
|
173
|
+
textColorOf: string;
|
|
174
|
+
lineColorOf: string;
|
|
175
|
+
/** Announced after changing a color; `{value}` is the new label. */
|
|
176
|
+
fillSet: string;
|
|
177
|
+
strokeSet: string;
|
|
178
|
+
textColorSet: string;
|
|
179
|
+
lineColorSet: string;
|
|
180
|
+
/** Swatch labels inside the color popover. */
|
|
181
|
+
colorDefault: string;
|
|
182
|
+
colorCustom: string;
|
|
183
|
+
fillNone: string;
|
|
184
|
+
borderNone: string;
|
|
185
|
+
colors: Record<WhiteboardPaletteColor, string>;
|
|
186
|
+
tones: Record<Tone, string>;
|
|
161
187
|
};
|
|
162
188
|
}
|
|
163
189
|
export declare const flowLocales: Record<string, FlowMessages>;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { NodeViewProps } from '../core/node-types';
|
|
2
2
|
import type { Tone } from 'dou-ui';
|
|
3
|
+
import { type WhiteboardColor, type WhiteboardFill, type WhiteboardStroke } from './colors';
|
|
3
4
|
import { type WhiteboardShape } from './model';
|
|
4
5
|
type BoardData = {
|
|
5
6
|
[key: string]: unknown;
|
|
6
7
|
text?: string;
|
|
7
8
|
shape?: WhiteboardShape;
|
|
8
9
|
tone?: Tone;
|
|
10
|
+
fill?: WhiteboardFill;
|
|
11
|
+
stroke?: WhiteboardStroke;
|
|
12
|
+
textColor?: WhiteboardColor;
|
|
13
|
+
color?: WhiteboardColor;
|
|
9
14
|
rotation?: number;
|
|
10
15
|
points?: number[];
|
|
11
16
|
box?: [number, number];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Tone } from 'dou-ui';
|
|
2
|
+
import type { FlowMessages } from '../locale';
|
|
3
|
+
/**
|
|
4
|
+
* The built-in whiteboard palette names; their values follow the light or dark
|
|
5
|
+
* color mode for readable contrast on the board.
|
|
6
|
+
*/
|
|
7
|
+
export declare const whiteboardColors: readonly ["gray", "red", "orange", "yellow", "green", "blue", "purple", "pink"];
|
|
8
|
+
export type WhiteboardPaletteColor = (typeof whiteboardColors)[number];
|
|
9
|
+
/**
|
|
10
|
+
* A color on the whiteboard: a palette name (adapts to light and dark mode),
|
|
11
|
+
* a DouUI `Tone`, or any CSS color string (such as `#3b6ea8` or `rgba(...)`).
|
|
12
|
+
*/
|
|
13
|
+
export type WhiteboardColor = WhiteboardPaletteColor | Tone | (string & {});
|
|
14
|
+
/** A background fill color, or `'none'` / `'transparent'` for a transparent fill. */
|
|
15
|
+
export type WhiteboardFill = WhiteboardColor | 'none' | 'transparent';
|
|
16
|
+
/** A border color, or `'none'` (or `'transparent'`) for a borderless shape. */
|
|
17
|
+
export type WhiteboardStroke = WhiteboardColor | 'none';
|
|
18
|
+
export declare const isWhiteboardColor: (value: unknown) => value is WhiteboardPaletteColor;
|
|
19
|
+
export declare const isToneColor: (value: unknown) => value is Tone;
|
|
20
|
+
/** Whether a color value explicitly disables painting (`'none'` or `'transparent'`). */
|
|
21
|
+
export declare const isNoneColor: (value: unknown) => boolean;
|
|
22
|
+
/** Trims a color value; maps `'none'` / `'transparent'` to `'none'`, empty strings to `undefined`. */
|
|
23
|
+
export declare function normalizeColorValue(value: unknown): string | undefined;
|
|
24
|
+
/** Like `normalizeColorValue`, dropping `'none'`/`'transparent'` for channels that stay painted. */
|
|
25
|
+
export declare function normalizeOpaqueColor(value: unknown): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Turns a fill color into a CSS / SVG paint value.
|
|
28
|
+
* Returns `'none'` for transparent fills (use `'transparent'` for CSS `background-color`).
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveFillColor(value: WhiteboardFill | undefined, kind?: 'shape' | 'sticky'): string | undefined;
|
|
31
|
+
/** Turns a border, connector or ink color into a CSS / SVG stroke/fill paint value. */
|
|
32
|
+
export declare function resolveStrokeColor(value: WhiteboardStroke | undefined): string | undefined;
|
|
33
|
+
/** Turns a text color into a CSS / SVG color value. */
|
|
34
|
+
export declare function resolveTextColor(value: WhiteboardColor | undefined): string | undefined;
|
|
35
|
+
/** Human-readable name for a color value in tooltips and screen-reader announcements. */
|
|
36
|
+
export declare function colorDisplayName(value: string | null | undefined, t: FlowMessages['board'], noneLabel?: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { connectorEdge, imageNode, inkNode, shapeNode, stickyNode, textNode, whiteboardKit, } from './kit';
|
|
2
|
-
export { imageKey, whiteboardKeys } from './model';
|
|
2
|
+
export { imageKey, isWhiteboardColor, whiteboardColors, whiteboardKeys } from './model';
|
|
3
3
|
export { insertImages, pickImages } from './image';
|
|
4
4
|
export type { WhiteboardKitOptions } from './kit';
|
|
5
5
|
export type { WhiteboardImageOptions, WhiteboardUpload, WhiteboardUploaded, WhiteboardUploadErrorHandler, } from './image';
|
|
6
|
-
export type { WhiteboardImageData, WhiteboardInkData, WhiteboardNodeData, WhiteboardShape, WhiteboardShapeData, WhiteboardShapeTool, WhiteboardStickyData, WhiteboardTextData, WhiteboardTool, WhiteboardArrow, WhiteboardConnectorData, WhiteboardDash, WhiteboardRoute, } from './model';
|
|
6
|
+
export type { WhiteboardColor, WhiteboardFill, WhiteboardImageData, WhiteboardInkData, WhiteboardNodeData, WhiteboardPaletteColor, WhiteboardShape, WhiteboardShapeData, WhiteboardShapeTool, WhiteboardStickyData, WhiteboardStroke, WhiteboardTextData, WhiteboardTool, WhiteboardArrow, WhiteboardConnectorData, WhiteboardDash, WhiteboardRoute, } from './model';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Tone } from 'dou-ui';
|
|
2
|
-
import type {
|
|
2
|
+
import type { WhiteboardColor, WhiteboardFill, WhiteboardStroke } from './colors';
|
|
3
|
+
export { whiteboardColors, isWhiteboardColor } from './colors';
|
|
4
|
+
export type { WhiteboardColor, WhiteboardFill, WhiteboardPaletteColor, WhiteboardStroke, } from './colors';
|
|
3
5
|
/** What a press on the board does. */
|
|
4
|
-
export type WhiteboardTool = 'select' | 'hand' | 'rect' | 'ellipse' | 'diamond' | 'sticky' | 'text' | 'pen' | 'eraser';
|
|
6
|
+
export type WhiteboardTool = 'select' | 'hand' | 'rect' | 'ellipse' | 'diamond' | 'sticky' | 'text' | 'pen' | 'eraser' | 'comment';
|
|
5
7
|
/** The tools that put down a node with a box. */
|
|
6
|
-
export type WhiteboardShapeTool = Exclude<WhiteboardTool, 'select' | 'hand' | 'pen' | 'eraser'>;
|
|
8
|
+
export type WhiteboardShapeTool = Exclude<WhiteboardTool, 'select' | 'hand' | 'pen' | 'eraser' | 'comment'>;
|
|
7
9
|
export type WhiteboardShape = 'rect' | 'ellipse' | 'diamond';
|
|
8
10
|
/** What every board node can carry. */
|
|
9
11
|
export interface WhiteboardNodeData {
|
|
@@ -14,16 +16,28 @@ export interface WhiteboardNodeData {
|
|
|
14
16
|
export interface WhiteboardShapeData extends WhiteboardNodeData {
|
|
15
17
|
shape: WhiteboardShape;
|
|
16
18
|
text?: string;
|
|
17
|
-
/** `neutral` by default. */
|
|
19
|
+
/** `neutral` by default; kept for compatibility when `fill` / `stroke` are omitted. */
|
|
18
20
|
tone?: Tone;
|
|
21
|
+
/** Background fill color, or `'none'` / `'transparent'` for no fill. */
|
|
22
|
+
fill?: WhiteboardFill;
|
|
23
|
+
/** Border color, or `'none'` for a borderless shape. */
|
|
24
|
+
stroke?: WhiteboardStroke;
|
|
25
|
+
/** Text color inside the shape. */
|
|
26
|
+
textColor?: WhiteboardColor;
|
|
19
27
|
}
|
|
20
28
|
export interface WhiteboardStickyData extends WhiteboardNodeData {
|
|
21
29
|
text?: string;
|
|
22
|
-
/** `warning` (yellow) by default. */
|
|
30
|
+
/** `warning` (yellow) by default; kept for compatibility when `fill` is omitted. */
|
|
23
31
|
tone?: Tone;
|
|
32
|
+
/** Background color of the sticky note. */
|
|
33
|
+
fill?: WhiteboardFill;
|
|
34
|
+
/** Text color inside the sticky note. */
|
|
35
|
+
textColor?: WhiteboardColor;
|
|
24
36
|
}
|
|
25
37
|
export interface WhiteboardTextData extends WhiteboardNodeData {
|
|
26
38
|
text?: string;
|
|
39
|
+
/** Text color. */
|
|
40
|
+
color?: WhiteboardColor;
|
|
27
41
|
}
|
|
28
42
|
/** A pen stroke. */
|
|
29
43
|
export interface WhiteboardInkData extends WhiteboardNodeData {
|
|
@@ -39,8 +53,10 @@ export interface WhiteboardInkData extends WhiteboardNodeData {
|
|
|
39
53
|
* makes it 0.4 to 1.6 times as wide as it presses lighter or harder.
|
|
40
54
|
*/
|
|
41
55
|
size?: number;
|
|
42
|
-
/** The text color when left out. */
|
|
56
|
+
/** The text color when left out; kept for compatibility when `color` is omitted. */
|
|
43
57
|
tone?: Tone;
|
|
58
|
+
/** Stroke color. */
|
|
59
|
+
color?: WhiteboardColor;
|
|
44
60
|
}
|
|
45
61
|
/** How a connector runs: one straight line, right-angled turns, or a smooth curve. */
|
|
46
62
|
export type WhiteboardRoute = 'straight' | 'elbow' | 'curve';
|
|
@@ -56,6 +72,8 @@ export interface WhiteboardConnectorData {
|
|
|
56
72
|
dash?: WhiteboardDash;
|
|
57
73
|
/** `end` by default. */
|
|
58
74
|
arrow?: WhiteboardArrow;
|
|
75
|
+
/** Line and arrowhead color. */
|
|
76
|
+
color?: WhiteboardColor;
|
|
59
77
|
/** Where an `elbow` connector's middle run sits, from 0 to 1; set by dragging it. */
|
|
60
78
|
bend?: number;
|
|
61
79
|
}
|
|
@@ -68,12 +86,4 @@ export interface WhiteboardImageData extends WhiteboardNodeData {
|
|
|
68
86
|
export declare const whiteboardKeys: Record<WhiteboardTool, string>;
|
|
69
87
|
/** The key that inserts an image. */
|
|
70
88
|
export declare const imageKey = "i";
|
|
71
|
-
/**
|
|
72
|
-
* Four anchors, one on each side. Each is an output and an input at the
|
|
73
|
-
* same spot, so a connector can start and end on any of them. Edges in
|
|
74
|
-
* data go from an output (`right`) to an input (`left-in`). The order puts
|
|
75
|
-
* `right` and `left-in` first, so a node added after another joins it left
|
|
76
|
-
* to right.
|
|
77
|
-
*/
|
|
78
|
-
export declare const anchorPorts: FlowPortSpec[];
|
|
79
89
|
export declare const anchorSides: readonly ["top", "right", "bottom", "left"];
|
|
@@ -37,3 +37,5 @@ export interface WhiteboardState {
|
|
|
37
37
|
}
|
|
38
38
|
/** The board's state in an editor, made on first use. */
|
|
39
39
|
export declare function boardState(context: FlowEditorContext): WhiteboardState;
|
|
40
|
+
/** Whether a tool can be used now: while read-only only select, hand and comment; comment while threads can be started. */
|
|
41
|
+
export declare function usable(ctx: FlowEditorContext, tool: WhiteboardTool): boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Component } from 'vue';
|
|
2
|
+
import type { FlowEditorContext } from '../context';
|
|
3
|
+
import type { FlowToolbarColorPreset, FlowToolbarItem } from '../core/menu';
|
|
4
|
+
import type { FlowData, FlowNode } from '../core/model';
|
|
5
|
+
import { type FlowMessages } from '../locale';
|
|
6
|
+
/** Merges `patch` into `base`, omitting keys set to `undefined` for clean JSON data. */
|
|
7
|
+
export declare function cleanData(base: FlowData | undefined, patch: Record<string, unknown>): Record<string, unknown>;
|
|
8
|
+
/** Shallow-compares two optional data objects so no-op color picks skip empty history steps. */
|
|
9
|
+
export declare function sameData(a: FlowData | undefined, b: FlowData | undefined): boolean;
|
|
10
|
+
/** Shared value across a selection, or `null` when items disagree (mixed). */
|
|
11
|
+
export declare function sharedValue(values: (string | undefined)[]): string | null | undefined;
|
|
12
|
+
/** Allocates or closes a transaction group so live drags in `DouColorPanel` undo as one step. */
|
|
13
|
+
export declare function colorTransactionMeta(ctx: FlowEditorContext, scope: string, live: boolean): {
|
|
14
|
+
group?: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
/** Drops any unclosed live-drag group when the popover closes or selection changes. */
|
|
17
|
+
export declare function resetColorGroup(ctx: FlowEditorContext, scope?: string): void;
|
|
18
|
+
export declare function palettePresets(kind: 'fill' | 'stroke' | 'text', t: FlowMessages['board']): FlowToolbarColorPreset[];
|
|
19
|
+
export interface ColorToolbarOptions {
|
|
20
|
+
ctx: FlowEditorContext;
|
|
21
|
+
key: string;
|
|
22
|
+
/** Scope including the selected targets so live drags on different items never merge. */
|
|
23
|
+
scope?: string;
|
|
24
|
+
kind: 'fill' | 'stroke' | 'text';
|
|
25
|
+
icon: Component;
|
|
26
|
+
value: string | null | undefined;
|
|
27
|
+
swatch: string | undefined;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
labelOf: string;
|
|
30
|
+
announceSet: string;
|
|
31
|
+
noneOption?: {
|
|
32
|
+
value: string;
|
|
33
|
+
label: string;
|
|
34
|
+
icon?: Component;
|
|
35
|
+
};
|
|
36
|
+
apply: (value: string | undefined, meta?: {
|
|
37
|
+
group?: string;
|
|
38
|
+
}) => void;
|
|
39
|
+
}
|
|
40
|
+
/** Builds one color-picker toolbar item shared by board nodes and connectors. */
|
|
41
|
+
export declare function colorToolbarItem(options: ColorToolbarOptions): FlowToolbarItem;
|
|
42
|
+
/**
|
|
43
|
+
* Fill, border (with borderless toggle), text color and ink color controls
|
|
44
|
+
* over the selected whiteboard nodes.
|
|
45
|
+
*/
|
|
46
|
+
export declare function boardNodeToolbar(ctx: FlowEditorContext, nodes: FlowNode[]): FlowToolbarItem[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-node.js","names":["_sfc_main"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport { DouFlowPort } from '../components/port'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const rect = ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 }\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${rect.x}px ${rect.y}px`,\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"transform\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span class=\"dou-whiteboard-node__turn\" data-dou-nodrag @pointerdown=\"startTurn\">\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n class=\"dou-whiteboard-node__corner\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"board-node.js","names":["_sfc_main"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport { DouFlowPort } from '../components/port'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport {\n isNoneColor,\n resolveFillColor,\n resolveStrokeColor,\n resolveTextColor,\n type WhiteboardColor,\n type WhiteboardFill,\n type WhiteboardStroke,\n} from './colors'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n fill?: WhiteboardFill\n stroke?: WhiteboardStroke\n textColor?: WhiteboardColor\n color?: WhiteboardColor\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst borderless = computed(() => kind.value === 'shape' && isNoneColor(props.data.stroke))\nconst transparentSticky = computed(() => kind.value === 'sticky' && isNoneColor(props.data.fill))\nconst colorStyle = computed(() => {\n const vars: Record<string, string> = {}\n if (kind.value === 'shape') {\n const fill = resolveFillColor(props.data.fill, 'shape')\n if (fill) vars['--dou-whiteboard-shape-fill'] = fill\n if (!borderless.value) {\n const stroke = resolveStrokeColor(props.data.stroke)\n if (stroke && stroke !== 'none') vars['--dou-whiteboard-shape-stroke'] = stroke\n }\n const textColor = resolveTextColor(props.data.textColor)\n if (textColor) vars['--dou-whiteboard-text-color'] = textColor\n } else if (kind.value === 'sticky') {\n const fill = resolveFillColor(props.data.fill, 'sticky')\n if (fill) vars['--dou-whiteboard-sticky-fill'] = fill === 'none' ? 'transparent' : fill\n const textColor = resolveTextColor(props.data.textColor)\n if (textColor) vars['--dou-whiteboard-text-color'] = textColor\n } else if (kind.value === 'text') {\n const textColor = resolveTextColor(props.data.color)\n if (textColor) vars['--dou-whiteboard-text-color'] = textColor\n } else if (kind.value === 'ink') {\n const stroke = resolveStrokeColor(props.data.color)\n if (stroke && stroke !== 'none') vars['--dou-whiteboard-ink-color'] = stroke\n }\n return vars\n})\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\nconst rect = computed(\n () => ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 },\n)\n/**\n * The node's size, for the anchors and the corner handles to share the\n * corners of a small node: each keeps short of the other.\n */\nconst sizeStyle = computed(() => ({\n '--dou-whiteboard-frame-width': `${rect.value.width}px`,\n '--dou-whiteboard-frame-height': `${rect.value.height}px`,\n}))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const box = rect.value\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${box.x}px ${box.y}px`,\n width: `${box.width}px`,\n height: `${box.height}px`,\n ...sizeStyle.value,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge (0 when borderless)\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst shapeInset = computed(() => (borderless.value ? 0 : 0.75))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = borderless.value ? 0 : 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n 'is-borderless': borderless,\n 'is-transparent': transparentSticky,\n },\n ]\"\n :style=\"[transform, sizeStyle, colorStyle]\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n :x=\"shapeInset\"\n :y=\"shapeInset\"\n :width=\"Math.max(0, shown.w - shapeInset * 2)\"\n :height=\"Math.max(0, shown.h - shapeInset * 2)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - shapeInset)\"\n :ry=\"Math.max(0, shown.h / 2 - shapeInset)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span\n class=\"dou-whiteboard-node__turn\"\n data-flow-handle\n data-dou-nodrag\n @pointerdown=\"startTurn\"\n >\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"[\n 'dou-whiteboard-node__corner',\n handle.x < 0 ? 'is-left' : 'is-right',\n handle.y < 0 ? 'is-top' : 'is-bottom',\n ]\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-flow-handle\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":""}
|