@dou-ui/flow 0.1.0-alpha.0 → 0.1.0-alpha.2
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/locale.js +3 -0
- package/dist/locale.js.map +1 -1
- package/dist/style.js +1 -0
- package/dist/types/locale.d.ts +2 -0
- package/dist/types/whiteboard/image.d.ts +8 -0
- package/dist/types/whiteboard/index.d.ts +1 -1
- package/dist/types/whiteboard/kit.d.ts +7 -1
- package/dist/types/whiteboard/state.d.ts +3 -1
- package/dist/whiteboard/image.js +17 -6
- package/dist/whiteboard/image.js.map +1 -1
- package/dist/whiteboard/kit.js +1 -0
- package/dist/whiteboard/kit.js.map +1 -1
- package/dist/whiteboard/state.js.map +1 -1
- package/package.json +3 -3
package/dist/locale.js
CHANGED
|
@@ -102,6 +102,7 @@ var zhCN = {
|
|
|
102
102
|
image: "图片",
|
|
103
103
|
ink: "笔迹",
|
|
104
104
|
imageFailed: "{name} 没能添加",
|
|
105
|
+
imagesFailed: "{count} 张图片没能添加",
|
|
105
106
|
erased: "已擦除 {count} 条笔迹",
|
|
106
107
|
rotate: "顺时针旋转 90°",
|
|
107
108
|
unrotate: "取消旋转",
|
|
@@ -232,6 +233,7 @@ var zhTW = {
|
|
|
232
233
|
image: "圖片",
|
|
233
234
|
ink: "筆跡",
|
|
234
235
|
imageFailed: "{name} 未能新增",
|
|
236
|
+
imagesFailed: "{count} 張圖片未能新增",
|
|
235
237
|
erased: "已擦除 {count} 條筆跡",
|
|
236
238
|
rotate: "順時針旋轉 90°",
|
|
237
239
|
unrotate: "取消旋轉",
|
|
@@ -362,6 +364,7 @@ var en = {
|
|
|
362
364
|
image: "Image",
|
|
363
365
|
ink: "Stroke",
|
|
364
366
|
imageFailed: "{name} could not be added",
|
|
367
|
+
imagesFailed: "{count} images could not be added",
|
|
365
368
|
erased: "Erased {count} strokes",
|
|
366
369
|
rotate: "Rotate 90° clockwise",
|
|
367
370
|
unrotate: "Reset rotation",
|
package/dist/locale.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale.js","names":[],"sources":["../src/locale.ts"],"sourcesContent":["import type { WhiteboardArrow, WhiteboardDash, WhiteboardRoute } from './whiteboard/model'\nimport { useLocale } from 'dou-ui'\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue'\n\nexport interface FlowMessages {\n /** The canvas's accessible description. */\n canvas: string\n /** What a node is called to screen readers. */\n node: string\n /** Describes a node's ports; `{inputs}`, `{outputs}` and `{connected}` are counts. */\n ports: string\n input: string\n output: string\n zoomIn: string\n zoomOut: string\n /** `{value}` is the zoom in percent. */\n zoomLevel: string\n /** The tip on the zoom level, which resets it. */\n zoomReset: string\n fit: string\n tidy: string\n minimap: string\n undo: string\n redo: string\n controls: string\n /** The context menu and the floating toolbar. */\n menu: string\n toolbar: string\n copy: string\n cut: string\n paste: string\n duplicate: string\n delete: string\n selectAll: string\n more: string\n /** Editing an edge's text. */\n editLabel: string\n label: string\n /** The list offered when an edge is dropped on the canvas. */\n search: string\n noTypes: string\n /** Announcements; `{count}` is a number. */\n deleted: string\n tidied: string\n undone: string\n /** Said when an extension cancels a change without saying why. */\n changeCancelled: string\n redone: string\n connected: string\n /** An edge selected from the keyboard; `{from}` and `{to}` are node names. */\n edge: string\n /** Follows `edge` when it has a label. */\n edgeLabel: string\n noEdges: string\n labelSaved: string\n /** Groups. */\n group: string\n groupName: string\n makeGroup: string\n ungroup: string\n /** Takes a node out of the group it is in. */\n leaveGroup: string\n /**\n * Moving nodes up and down the stack. `top` and `bottom` say nothing moved\n * because the nodes already are there; `noneAbove` and `noneBelow`, that\n * no other node overlaps them that way.\n */\n layers: {\n front: string\n forward: string\n backward: string\n back: string\n top: string\n bottom: string\n noneAbove: string\n noneBelow: string\n }\n expand: string\n collapse: string\n /** Between parts of a node's description. */\n separator: string\n /** `{group}` is the group's name. */\n inGroup: string\n /** `{count}` nodes inside a group. */\n groupSize: string\n /** Announced; `{group}` is the group's name. */\n joinedGroup: string\n leftGroup: string\n ungrouped: string\n expanded: string\n collapsed: string\n /** After resizing from the keyboard; `{node}`, `{width}` and `{height}`. */\n resized: string\n /** Why the selection can't be grouped. */\n groupMixed: string\n /** `{node}` is the new node's name. */\n added: string\n /** While connecting from the keyboard; `{node}` and `{port}` are names. */\n connectTo: string\n noTarget: string\n /** `{count}` edges no longer fit their ports. */\n stale: string\n /** Why an edge was refused, announced when it is dropped. */\n refused: {\n direction: string\n self: string\n type: string\n duplicate: string\n cycle: string\n custom: string\n }\n status: { wait: string; process: string; finish: string; error: string }\n /** The whiteboard's toolbar and nodes. */\n board: {\n tools: string\n select: string\n hand: string\n rect: string\n ellipse: string\n diamond: string\n sticky: string\n text: string\n /** The field for a node's text. */\n editText: string\n /** Announced when a tool is picked; `{tool}` is its name. */\n picked: string\n /** A node's name when it has text; `{kind}` is what it is, as `rect` or `sticky`. */\n named: string\n pen: string\n eraser: string\n /** The toolbar button that inserts an image. */\n image: string\n /** A pen stroke. */\n ink: string\n /** `{name}` is the file's name. */\n imageFailed: string\n /** `{count}` strokes were erased. */\n erased: string\n rotate: string\n unrotate: string\n /** `{degrees}` is the node's new turn. */\n turned: string\n /** The connector buttons' names; `{value}` is the current choice. */\n routeOf: string\n dashOf: string\n arrowOf: string\n routes: Record<WhiteboardRoute, string>\n dashes: Record<WhiteboardDash, string>\n arrows: Record<WhiteboardArrow, string>\n /** The connector buttons' `{value}` when the selected connectors differ. */\n mixed: string\n /** Announced after a choice; `{value}` is the new one. */\n routeSet: string\n dashSet: string\n arrowSet: string\n }\n}\n\nconst zhCN: FlowMessages = {\n canvas:\n '流程画布。方向键移动选中的节点,Tab 在节点之间切换,C 从选中的节点连线,E 选中它的连线,Delete 删除。',\n node: '节点',\n ports: '{inputs} 个输入,{outputs} 个输出,已连接 {connected} 条',\n input: '输入',\n output: '输出',\n zoomIn: '放大',\n zoomOut: '缩小',\n zoomLevel: '缩放 {value}%,点击恢复 100%',\n zoomReset: '恢复 100%',\n fit: '适应画布',\n tidy: '整理',\n minimap: '小地图,点击或拖动移动画布',\n undo: '撤销',\n redo: '重做',\n controls: '画布控制',\n menu: '菜单',\n toolbar: '选中节点的操作',\n copy: '复制',\n cut: '剪切',\n paste: '粘贴',\n duplicate: '复制一份',\n delete: '删除',\n selectAll: '全选',\n more: '更多',\n editLabel: '编辑标签',\n label: '连线标签',\n search: '搜索节点',\n noTypes: '没有能接上的节点',\n deleted: '已删除 {count} 项',\n tidied: '已整理 {count} 个节点',\n undone: '已撤销',\n changeCancelled: '这次修改没有生效',\n redone: '已重做',\n connected: '已连接',\n edge: '连线:{from} → {to}',\n edgeLabel: ',标签:{label}',\n noEdges: '这个节点没有连线',\n labelSaved: '已保存标签',\n group: '分组',\n groupName: '分组名称',\n makeGroup: '放进分组',\n ungroup: '取消分组',\n leaveGroup: '移出分组',\n layers: {\n front: '置于顶层',\n forward: '上移一层',\n backward: '下移一层',\n back: '置于底层',\n top: '已经在最上层',\n bottom: '已经在最底层',\n noneAbove: '上面没有和它重叠的节点',\n noneBelow: '下面没有和它重叠的节点',\n },\n expand: '展开',\n collapse: '收起',\n separator: ',',\n inGroup: '在“{group}”里',\n groupSize: '有 {count} 个节点',\n joinedGroup: '已放进“{group}”',\n leftGroup: '已移出“{group}”',\n ungrouped: '已取消“{group}”',\n expanded: '已展开“{group}”',\n collapsed: '已收起“{group}”',\n resized: '{node},宽 {width},高 {height}',\n groupMixed: '选中的节点不在同一个分组里,不能一起放进分组',\n added: '已添加{node}',\n connectTo: '连接到 {node} 的 {port},方向键换一个,Enter 确认',\n noTarget: '没有可以连接的端口',\n stale: '{count} 条连线的端口类型已经对不上',\n refused: {\n direction: '只能从输出连到输入',\n self: '不能连到同一个节点',\n type: '端口类型不匹配',\n duplicate: '这两个端口已经连上了',\n cycle: '这样会连成环',\n custom: '不能连到这个端口',\n },\n status: { wait: '等待', process: '运行中', finish: '已完成', error: '失败' },\n board: {\n tools: '白板工具',\n select: '选择',\n hand: '移动画布',\n rect: '矩形',\n ellipse: '椭圆',\n diamond: '菱形',\n sticky: '便签',\n text: '文字',\n editText: '编辑文字',\n picked: '已选择{tool}工具',\n named: '{kind}:{text}',\n pen: '画笔',\n eraser: '橡皮',\n image: '图片',\n ink: '笔迹',\n imageFailed: '{name} 没能添加',\n erased: '已擦除 {count} 条笔迹',\n rotate: '顺时针旋转 90°',\n unrotate: '取消旋转',\n turned: '已旋转到 {degrees}°',\n routeOf: '走向:{value}',\n dashOf: '线型:{value}',\n arrowOf: '箭头:{value}',\n routes: { straight: '直线', elbow: '折线', curve: '曲线' },\n dashes: { solid: '实线', dashed: '虚线', dotted: '点线', 'dash-dot': '点划线' },\n arrows: { none: '无箭头', end: '终点箭头', both: '两端箭头' },\n mixed: '多种',\n routeSet: '已改为{value}',\n dashSet: '已改为{value}',\n arrowSet: '已改为{value}',\n },\n}\n\nconst zhTW: FlowMessages = {\n canvas:\n '流程畫布。方向鍵移動選取的節點,Tab 在節點之間切換,C 從選取的節點連線,E 選取它的連線,Delete 刪除。',\n node: '節點',\n ports: '{inputs} 個輸入,{outputs} 個輸出,已連接 {connected} 條',\n input: '輸入',\n output: '輸出',\n zoomIn: '放大',\n zoomOut: '縮小',\n zoomLevel: '縮放 {value}%,點擊恢復 100%',\n zoomReset: '恢復 100%',\n fit: '適應畫布',\n tidy: '整理',\n minimap: '小地圖,點擊或拖曳移動畫布',\n undo: '復原',\n redo: '重做',\n controls: '畫布控制',\n menu: '選單',\n toolbar: '選取節點的操作',\n copy: '複製',\n cut: '剪下',\n paste: '貼上',\n duplicate: '複製一份',\n delete: '刪除',\n selectAll: '全選',\n more: '更多',\n editLabel: '編輯標籤',\n label: '連線標籤',\n search: '搜尋節點',\n noTypes: '沒有能接上的節點',\n deleted: '已刪除 {count} 項',\n tidied: '已整理 {count} 個節點',\n undone: '已復原',\n changeCancelled: '這次修改沒有生效',\n redone: '已重做',\n connected: '已連接',\n edge: '連線:{from} → {to}',\n edgeLabel: ',標籤:{label}',\n noEdges: '這個節點沒有連線',\n labelSaved: '已儲存標籤',\n group: '群組',\n groupName: '群組名稱',\n makeGroup: '放進群組',\n ungroup: '取消群組',\n leaveGroup: '移出群組',\n layers: {\n front: '移到最上層',\n forward: '上移一層',\n backward: '下移一層',\n back: '移到最下層',\n top: '已經在最上層',\n bottom: '已經在最下層',\n noneAbove: '上面沒有和它重疊的節點',\n noneBelow: '下面沒有和它重疊的節點',\n },\n expand: '展開',\n collapse: '收合',\n separator: ',',\n inGroup: '在「{group}」裡',\n groupSize: '有 {count} 個節點',\n joinedGroup: '已放進「{group}」',\n leftGroup: '已移出「{group}」',\n ungrouped: '已取消「{group}」',\n expanded: '已展開「{group}」',\n collapsed: '已收合「{group}」',\n resized: '{node},寬 {width},高 {height}',\n groupMixed: '選取的節點不在同一個群組裡,不能一起放進群組',\n added: '已新增{node}',\n connectTo: '連接到 {node} 的 {port},方向鍵換一個,Enter 確認',\n noTarget: '沒有可以連接的連接埠',\n stale: '{count} 條連線的連接埠類型已經對不上',\n refused: {\n direction: '只能從輸出連到輸入',\n self: '不能連到同一個節點',\n type: '連接埠類型不符',\n duplicate: '這兩個連接埠已經連上了',\n cycle: '這樣會連成環',\n custom: '不能連到這個連接埠',\n },\n status: { wait: '等待', process: '執行中', finish: '已完成', error: '失敗' },\n board: {\n tools: '白板工具',\n select: '選取',\n hand: '移動畫布',\n rect: '矩形',\n ellipse: '橢圓',\n diamond: '菱形',\n sticky: '便利貼',\n text: '文字',\n editText: '編輯文字',\n picked: '已選取{tool}工具',\n named: '{kind}:{text}',\n pen: '畫筆',\n eraser: '橡皮擦',\n image: '圖片',\n ink: '筆跡',\n imageFailed: '{name} 未能新增',\n erased: '已擦除 {count} 條筆跡',\n rotate: '順時針旋轉 90°',\n unrotate: '取消旋轉',\n turned: '已旋轉到 {degrees}°',\n routeOf: '走向:{value}',\n dashOf: '線型:{value}',\n arrowOf: '箭頭:{value}',\n routes: { straight: '直線', elbow: '折線', curve: '曲線' },\n dashes: { solid: '實線', dashed: '虛線', dotted: '點線', 'dash-dot': '點劃線' },\n arrows: { none: '無箭頭', end: '終點箭頭', both: '兩端箭頭' },\n mixed: '多種',\n routeSet: '已改為{value}',\n dashSet: '已改為{value}',\n arrowSet: '已改為{value}',\n },\n}\n\nconst en: FlowMessages = {\n canvas:\n 'Flow canvas. Arrow keys move the selected nodes, Tab moves between nodes, C draws an edge from the selected node, E selects its edges, Delete removes.',\n node: 'node',\n ports: '{inputs} inputs, {outputs} outputs, {connected} connected',\n input: 'Input',\n output: 'Output',\n zoomIn: 'Zoom in',\n zoomOut: 'Zoom out',\n zoomLevel: 'Zoom {value}%, click to reset to 100%',\n zoomReset: 'Reset to 100%',\n fit: 'Fit to view',\n tidy: 'Tidy up',\n minimap: 'Minimap; click or drag to move the canvas',\n undo: 'Undo',\n redo: 'Redo',\n controls: 'Canvas controls',\n menu: 'Menu',\n toolbar: 'Selected node actions',\n copy: 'Copy',\n cut: 'Cut',\n paste: 'Paste',\n duplicate: 'Duplicate',\n delete: 'Delete',\n selectAll: 'Select all',\n more: 'More',\n editLabel: 'Edit label',\n label: 'Edge label',\n search: 'Search nodes',\n noTypes: 'No node can take this edge',\n deleted: '{count} deleted',\n tidied: '{count} nodes tidied up',\n undone: 'Undone',\n changeCancelled: \"That change wasn't made\",\n redone: 'Redone',\n connected: 'Connected',\n edge: 'Edge: {from} → {to}',\n edgeLabel: ', label: {label}',\n noEdges: 'This node has no edges',\n labelSaved: 'Label saved',\n group: 'Group',\n groupName: 'Group name',\n makeGroup: 'Group',\n ungroup: 'Ungroup',\n leaveGroup: 'Remove from group',\n layers: {\n front: 'Bring to front',\n forward: 'Bring forward',\n backward: 'Send backward',\n back: 'Send to back',\n top: 'Already at the front',\n bottom: 'Already at the back',\n noneAbove: 'No node above overlaps it',\n noneBelow: 'No node below overlaps it',\n },\n expand: 'Expand',\n collapse: 'Collapse',\n separator: ', ',\n inGroup: 'in {group}',\n groupSize: '{count} nodes',\n joinedGroup: 'Added to {group}',\n leftGroup: 'Removed from {group}',\n ungrouped: 'Ungrouped {group}',\n expanded: 'Expanded {group}',\n collapsed: 'Collapsed {group}',\n resized: '{node}, {width} wide, {height} high',\n groupMixed: 'The selected nodes are in different groups and can’t be grouped together',\n added: 'Added {node}',\n connectTo: 'Connect to {port} of {node}; arrow keys pick another, Enter confirms',\n noTarget: 'No port to connect to',\n stale: '{count} edges no longer match their ports',\n refused: {\n direction: 'Edges go from an output to an input',\n self: 'A node can’t connect to itself',\n type: 'The port types don’t match',\n duplicate: 'These ports are already connected',\n cycle: 'This would make a cycle',\n custom: 'Can’t connect to this port',\n },\n status: { wait: 'Waiting', process: 'Running', finish: 'Done', error: 'Failed' },\n board: {\n tools: 'Whiteboard tools',\n select: 'Select',\n hand: 'Hand',\n rect: 'Rectangle',\n ellipse: 'Ellipse',\n diamond: 'Diamond',\n sticky: 'Sticky note',\n text: 'Text',\n editText: 'Edit text',\n picked: '{tool} tool',\n named: '{kind}: {text}',\n pen: 'Pen',\n eraser: 'Eraser',\n image: 'Image',\n ink: 'Stroke',\n imageFailed: '{name} could not be added',\n erased: 'Erased {count} strokes',\n rotate: 'Rotate 90° clockwise',\n unrotate: 'Reset rotation',\n turned: 'Rotated to {degrees}°',\n routeOf: 'Route: {value}',\n dashOf: 'Line: {value}',\n arrowOf: 'Arrows: {value}',\n routes: { straight: 'Straight', elbow: 'Elbow', curve: 'Curved' },\n dashes: { solid: 'Solid', dashed: 'Dashed', dotted: 'Dotted', 'dash-dot': 'Dash-dot' },\n arrows: { none: 'No arrows', end: 'Arrow at end', both: 'Arrows at both ends' },\n mixed: 'Mixed',\n routeSet: 'Changed to {value}',\n dashSet: 'Changed to {value}',\n arrowSet: 'Changed to {value}',\n },\n}\n\nexport const flowLocales: Record<string, FlowMessages> = { 'zh-CN': zhCN, 'zh-TW': zhTW, en }\n\n/** Texts to change; nested groups are merged, so only the ones given are replaced. */\nexport type FlowMessagesOverride = {\n [K in keyof FlowMessages]?: FlowMessages[K] extends string ? string : Partial<FlowMessages[K]>\n}\n\n/**\n * The flow editor's texts, picked by the name of DouUI's current locale.\n * Pass `messages` to override any of them.\n */\nexport function useFlowMessages(override?: MaybeRefOrGetter<FlowMessagesOverride | undefined>) {\n const { locale } = useLocale()\n return computed<FlowMessages>(() => {\n const name = locale.value.name\n const base =\n flowLocales[name] ?? flowLocales[name.split('-')[0]!] ?? (name.startsWith('zh') ? zhCN : en)\n const extra = toValue(override)\n if (!extra) return base\n const out = { ...base } as Record<string, unknown>\n for (const [key, value] of Object.entries(extra)) {\n if (value === undefined) continue\n const own = out[key]\n out[key] = typeof own === 'object' && own ? { ...own, ...(value as object) } : value\n }\n return out as unknown as FlowMessages\n })\n}\n\n/** Fills `{name}` placeholders. */\nexport const format = (text: string, params: Record<string, string | number>) =>\n text.replace(/\\{(\\w+)\\}/g, (match, key: string) => String(params[key] ?? match))\n"],"mappings":";;;AA8JA,IAAM,OAAqB;CACzB,QACE;CACF,MAAM;CACN,OAAO;CACP,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,WAAW;CACX,WAAW;CACX,KAAK;CACL,MAAM;CACN,SAAS;CACT,MAAM;CACN,MAAM;CACN,UAAU;CACV,MAAM;CACN,SAAS;CACT,MAAM;CACN,KAAK;CACL,OAAO;CACP,WAAW;CACX,QAAQ;CACR,WAAW;CACX,MAAM;CACN,WAAW;CACX,OAAO;CACP,QAAQ;CACR,SAAS;CACT,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,iBAAiB;CACjB,QAAQ;CACR,WAAW;CACX,MAAM;CACN,WAAW;CACX,SAAS;CACT,YAAY;CACZ,OAAO;CACP,WAAW;CACX,WAAW;CACX,SAAS;CACT,YAAY;CACZ,QAAQ;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,MAAM;EACN,KAAK;EACL,QAAQ;EACR,WAAW;EACX,WAAW;CACb;CACA,QAAQ;CACR,UAAU;CACV,WAAW;CACX,SAAS;CACT,WAAW;CACX,aAAa;CACb,WAAW;CACX,WA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,gBAAgB,UAA+D;CAC7F,MAAM,EAAE,WAAW,UAAU;CAC7B,OAAO,eAA6B;EAClC,MAAM,OAAO,OAAO,MAAM;EAC1B,MAAM,OACJ,YAAY,SAAS,YAAY,KAAK,MAAM,GAAG,CAAC,CAAC,QAAS,KAAK,WAAW,IAAI,IAAI,OAAO;EAC3F,MAAM,QAAQ,QAAQ,QAAQ;EAC9B,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,MAAM,EAAE,GAAG,KAAK;EACtB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAAG;GAChD,IAAI,UAAU,KAAA,GAAW;GACzB,MAAM,MAAM,IAAI;GAChB,IAAI,OAAO,OAAO,QAAQ,YAAY,MAAM;IAAE,GAAG;IAAK,GAAI;GAAiB,IAAI;EACjF;EACA,OAAO;CACT,CAAC;AACH;;AAGA,IAAa,UAAU,MAAc,WACnC,KAAK,QAAQ,eAAe,OAAO,QAAgB,OAAO,OAAO,QAAQ,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"locale.js","names":[],"sources":["../src/locale.ts"],"sourcesContent":["import type { WhiteboardArrow, WhiteboardDash, WhiteboardRoute } from './whiteboard/model'\nimport { useLocale } from 'dou-ui'\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue'\n\nexport interface FlowMessages {\n /** The canvas's accessible description. */\n canvas: string\n /** What a node is called to screen readers. */\n node: string\n /** Describes a node's ports; `{inputs}`, `{outputs}` and `{connected}` are counts. */\n ports: string\n input: string\n output: string\n zoomIn: string\n zoomOut: string\n /** `{value}` is the zoom in percent. */\n zoomLevel: string\n /** The tip on the zoom level, which resets it. */\n zoomReset: string\n fit: string\n tidy: string\n minimap: string\n undo: string\n redo: string\n controls: string\n /** The context menu and the floating toolbar. */\n menu: string\n toolbar: string\n copy: string\n cut: string\n paste: string\n duplicate: string\n delete: string\n selectAll: string\n more: string\n /** Editing an edge's text. */\n editLabel: string\n label: string\n /** The list offered when an edge is dropped on the canvas. */\n search: string\n noTypes: string\n /** Announcements; `{count}` is a number. */\n deleted: string\n tidied: string\n undone: string\n /** Said when an extension cancels a change without saying why. */\n changeCancelled: string\n redone: string\n connected: string\n /** An edge selected from the keyboard; `{from}` and `{to}` are node names. */\n edge: string\n /** Follows `edge` when it has a label. */\n edgeLabel: string\n noEdges: string\n labelSaved: string\n /** Groups. */\n group: string\n groupName: string\n makeGroup: string\n ungroup: string\n /** Takes a node out of the group it is in. */\n leaveGroup: string\n /**\n * Moving nodes up and down the stack. `top` and `bottom` say nothing moved\n * because the nodes already are there; `noneAbove` and `noneBelow`, that\n * no other node overlaps them that way.\n */\n layers: {\n front: string\n forward: string\n backward: string\n back: string\n top: string\n bottom: string\n noneAbove: string\n noneBelow: string\n }\n expand: string\n collapse: string\n /** Between parts of a node's description. */\n separator: string\n /** `{group}` is the group's name. */\n inGroup: string\n /** `{count}` nodes inside a group. */\n groupSize: string\n /** Announced; `{group}` is the group's name. */\n joinedGroup: string\n leftGroup: string\n ungrouped: string\n expanded: string\n collapsed: string\n /** After resizing from the keyboard; `{node}`, `{width}` and `{height}`. */\n resized: string\n /** Why the selection can't be grouped. */\n groupMixed: string\n /** `{node}` is the new node's name. */\n added: string\n /** While connecting from the keyboard; `{node}` and `{port}` are names. */\n connectTo: string\n noTarget: string\n /** `{count}` edges no longer fit their ports. */\n stale: string\n /** Why an edge was refused, announced when it is dropped. */\n refused: {\n direction: string\n self: string\n type: string\n duplicate: string\n cycle: string\n custom: string\n }\n status: { wait: string; process: string; finish: string; error: string }\n /** The whiteboard's toolbar and nodes. */\n board: {\n tools: string\n select: string\n hand: string\n rect: string\n ellipse: string\n diamond: string\n sticky: string\n text: string\n /** The field for a node's text. */\n editText: string\n /** Announced when a tool is picked; `{tool}` is its name. */\n picked: string\n /** A node's name when it has text; `{kind}` is what it is, as `rect` or `sticky`. */\n named: string\n pen: string\n eraser: string\n /** The toolbar button that inserts an image. */\n image: string\n /** A pen stroke. */\n ink: string\n /** `{name}` is the file's name. */\n imageFailed: string\n /** `{count}` images in one drop or pick could not be added. */\n imagesFailed: string\n /** `{count}` strokes were erased. */\n erased: string\n rotate: string\n unrotate: string\n /** `{degrees}` is the node's new turn. */\n turned: string\n /** The connector buttons' names; `{value}` is the current choice. */\n routeOf: string\n dashOf: string\n arrowOf: string\n routes: Record<WhiteboardRoute, string>\n dashes: Record<WhiteboardDash, string>\n arrows: Record<WhiteboardArrow, string>\n /** The connector buttons' `{value}` when the selected connectors differ. */\n mixed: string\n /** Announced after a choice; `{value}` is the new one. */\n routeSet: string\n dashSet: string\n arrowSet: string\n }\n}\n\nconst zhCN: FlowMessages = {\n canvas:\n '流程画布。方向键移动选中的节点,Tab 在节点之间切换,C 从选中的节点连线,E 选中它的连线,Delete 删除。',\n node: '节点',\n ports: '{inputs} 个输入,{outputs} 个输出,已连接 {connected} 条',\n input: '输入',\n output: '输出',\n zoomIn: '放大',\n zoomOut: '缩小',\n zoomLevel: '缩放 {value}%,点击恢复 100%',\n zoomReset: '恢复 100%',\n fit: '适应画布',\n tidy: '整理',\n minimap: '小地图,点击或拖动移动画布',\n undo: '撤销',\n redo: '重做',\n controls: '画布控制',\n menu: '菜单',\n toolbar: '选中节点的操作',\n copy: '复制',\n cut: '剪切',\n paste: '粘贴',\n duplicate: '复制一份',\n delete: '删除',\n selectAll: '全选',\n more: '更多',\n editLabel: '编辑标签',\n label: '连线标签',\n search: '搜索节点',\n noTypes: '没有能接上的节点',\n deleted: '已删除 {count} 项',\n tidied: '已整理 {count} 个节点',\n undone: '已撤销',\n changeCancelled: '这次修改没有生效',\n redone: '已重做',\n connected: '已连接',\n edge: '连线:{from} → {to}',\n edgeLabel: ',标签:{label}',\n noEdges: '这个节点没有连线',\n labelSaved: '已保存标签',\n group: '分组',\n groupName: '分组名称',\n makeGroup: '放进分组',\n ungroup: '取消分组',\n leaveGroup: '移出分组',\n layers: {\n front: '置于顶层',\n forward: '上移一层',\n backward: '下移一层',\n back: '置于底层',\n top: '已经在最上层',\n bottom: '已经在最底层',\n noneAbove: '上面没有和它重叠的节点',\n noneBelow: '下面没有和它重叠的节点',\n },\n expand: '展开',\n collapse: '收起',\n separator: ',',\n inGroup: '在“{group}”里',\n groupSize: '有 {count} 个节点',\n joinedGroup: '已放进“{group}”',\n leftGroup: '已移出“{group}”',\n ungrouped: '已取消“{group}”',\n expanded: '已展开“{group}”',\n collapsed: '已收起“{group}”',\n resized: '{node},宽 {width},高 {height}',\n groupMixed: '选中的节点不在同一个分组里,不能一起放进分组',\n added: '已添加{node}',\n connectTo: '连接到 {node} 的 {port},方向键换一个,Enter 确认',\n noTarget: '没有可以连接的端口',\n stale: '{count} 条连线的端口类型已经对不上',\n refused: {\n direction: '只能从输出连到输入',\n self: '不能连到同一个节点',\n type: '端口类型不匹配',\n duplicate: '这两个端口已经连上了',\n cycle: '这样会连成环',\n custom: '不能连到这个端口',\n },\n status: { wait: '等待', process: '运行中', finish: '已完成', error: '失败' },\n board: {\n tools: '白板工具',\n select: '选择',\n hand: '移动画布',\n rect: '矩形',\n ellipse: '椭圆',\n diamond: '菱形',\n sticky: '便签',\n text: '文字',\n editText: '编辑文字',\n picked: '已选择{tool}工具',\n named: '{kind}:{text}',\n pen: '画笔',\n eraser: '橡皮',\n image: '图片',\n ink: '笔迹',\n imageFailed: '{name} 没能添加',\n imagesFailed: '{count} 张图片没能添加',\n erased: '已擦除 {count} 条笔迹',\n rotate: '顺时针旋转 90°',\n unrotate: '取消旋转',\n turned: '已旋转到 {degrees}°',\n routeOf: '走向:{value}',\n dashOf: '线型:{value}',\n arrowOf: '箭头:{value}',\n routes: { straight: '直线', elbow: '折线', curve: '曲线' },\n dashes: { solid: '实线', dashed: '虚线', dotted: '点线', 'dash-dot': '点划线' },\n arrows: { none: '无箭头', end: '终点箭头', both: '两端箭头' },\n mixed: '多种',\n routeSet: '已改为{value}',\n dashSet: '已改为{value}',\n arrowSet: '已改为{value}',\n },\n}\n\nconst zhTW: FlowMessages = {\n canvas:\n '流程畫布。方向鍵移動選取的節點,Tab 在節點之間切換,C 從選取的節點連線,E 選取它的連線,Delete 刪除。',\n node: '節點',\n ports: '{inputs} 個輸入,{outputs} 個輸出,已連接 {connected} 條',\n input: '輸入',\n output: '輸出',\n zoomIn: '放大',\n zoomOut: '縮小',\n zoomLevel: '縮放 {value}%,點擊恢復 100%',\n zoomReset: '恢復 100%',\n fit: '適應畫布',\n tidy: '整理',\n minimap: '小地圖,點擊或拖曳移動畫布',\n undo: '復原',\n redo: '重做',\n controls: '畫布控制',\n menu: '選單',\n toolbar: '選取節點的操作',\n copy: '複製',\n cut: '剪下',\n paste: '貼上',\n duplicate: '複製一份',\n delete: '刪除',\n selectAll: '全選',\n more: '更多',\n editLabel: '編輯標籤',\n label: '連線標籤',\n search: '搜尋節點',\n noTypes: '沒有能接上的節點',\n deleted: '已刪除 {count} 項',\n tidied: '已整理 {count} 個節點',\n undone: '已復原',\n changeCancelled: '這次修改沒有生效',\n redone: '已重做',\n connected: '已連接',\n edge: '連線:{from} → {to}',\n edgeLabel: ',標籤:{label}',\n noEdges: '這個節點沒有連線',\n labelSaved: '已儲存標籤',\n group: '群組',\n groupName: '群組名稱',\n makeGroup: '放進群組',\n ungroup: '取消群組',\n leaveGroup: '移出群組',\n layers: {\n front: '移到最上層',\n forward: '上移一層',\n backward: '下移一層',\n back: '移到最下層',\n top: '已經在最上層',\n bottom: '已經在最下層',\n noneAbove: '上面沒有和它重疊的節點',\n noneBelow: '下面沒有和它重疊的節點',\n },\n expand: '展開',\n collapse: '收合',\n separator: ',',\n inGroup: '在「{group}」裡',\n groupSize: '有 {count} 個節點',\n joinedGroup: '已放進「{group}」',\n leftGroup: '已移出「{group}」',\n ungrouped: '已取消「{group}」',\n expanded: '已展開「{group}」',\n collapsed: '已收合「{group}」',\n resized: '{node},寬 {width},高 {height}',\n groupMixed: '選取的節點不在同一個群組裡,不能一起放進群組',\n added: '已新增{node}',\n connectTo: '連接到 {node} 的 {port},方向鍵換一個,Enter 確認',\n noTarget: '沒有可以連接的連接埠',\n stale: '{count} 條連線的連接埠類型已經對不上',\n refused: {\n direction: '只能從輸出連到輸入',\n self: '不能連到同一個節點',\n type: '連接埠類型不符',\n duplicate: '這兩個連接埠已經連上了',\n cycle: '這樣會連成環',\n custom: '不能連到這個連接埠',\n },\n status: { wait: '等待', process: '執行中', finish: '已完成', error: '失敗' },\n board: {\n tools: '白板工具',\n select: '選取',\n hand: '移動畫布',\n rect: '矩形',\n ellipse: '橢圓',\n diamond: '菱形',\n sticky: '便利貼',\n text: '文字',\n editText: '編輯文字',\n picked: '已選取{tool}工具',\n named: '{kind}:{text}',\n pen: '畫筆',\n eraser: '橡皮擦',\n image: '圖片',\n ink: '筆跡',\n imageFailed: '{name} 未能新增',\n imagesFailed: '{count} 張圖片未能新增',\n erased: '已擦除 {count} 條筆跡',\n rotate: '順時針旋轉 90°',\n unrotate: '取消旋轉',\n turned: '已旋轉到 {degrees}°',\n routeOf: '走向:{value}',\n dashOf: '線型:{value}',\n arrowOf: '箭頭:{value}',\n routes: { straight: '直線', elbow: '折線', curve: '曲線' },\n dashes: { solid: '實線', dashed: '虛線', dotted: '點線', 'dash-dot': '點劃線' },\n arrows: { none: '無箭頭', end: '終點箭頭', both: '兩端箭頭' },\n mixed: '多種',\n routeSet: '已改為{value}',\n dashSet: '已改為{value}',\n arrowSet: '已改為{value}',\n },\n}\n\nconst en: FlowMessages = {\n canvas:\n 'Flow canvas. Arrow keys move the selected nodes, Tab moves between nodes, C draws an edge from the selected node, E selects its edges, Delete removes.',\n node: 'node',\n ports: '{inputs} inputs, {outputs} outputs, {connected} connected',\n input: 'Input',\n output: 'Output',\n zoomIn: 'Zoom in',\n zoomOut: 'Zoom out',\n zoomLevel: 'Zoom {value}%, click to reset to 100%',\n zoomReset: 'Reset to 100%',\n fit: 'Fit to view',\n tidy: 'Tidy up',\n minimap: 'Minimap; click or drag to move the canvas',\n undo: 'Undo',\n redo: 'Redo',\n controls: 'Canvas controls',\n menu: 'Menu',\n toolbar: 'Selected node actions',\n copy: 'Copy',\n cut: 'Cut',\n paste: 'Paste',\n duplicate: 'Duplicate',\n delete: 'Delete',\n selectAll: 'Select all',\n more: 'More',\n editLabel: 'Edit label',\n label: 'Edge label',\n search: 'Search nodes',\n noTypes: 'No node can take this edge',\n deleted: '{count} deleted',\n tidied: '{count} nodes tidied up',\n undone: 'Undone',\n changeCancelled: \"That change wasn't made\",\n redone: 'Redone',\n connected: 'Connected',\n edge: 'Edge: {from} → {to}',\n edgeLabel: ', label: {label}',\n noEdges: 'This node has no edges',\n labelSaved: 'Label saved',\n group: 'Group',\n groupName: 'Group name',\n makeGroup: 'Group',\n ungroup: 'Ungroup',\n leaveGroup: 'Remove from group',\n layers: {\n front: 'Bring to front',\n forward: 'Bring forward',\n backward: 'Send backward',\n back: 'Send to back',\n top: 'Already at the front',\n bottom: 'Already at the back',\n noneAbove: 'No node above overlaps it',\n noneBelow: 'No node below overlaps it',\n },\n expand: 'Expand',\n collapse: 'Collapse',\n separator: ', ',\n inGroup: 'in {group}',\n groupSize: '{count} nodes',\n joinedGroup: 'Added to {group}',\n leftGroup: 'Removed from {group}',\n ungrouped: 'Ungrouped {group}',\n expanded: 'Expanded {group}',\n collapsed: 'Collapsed {group}',\n resized: '{node}, {width} wide, {height} high',\n groupMixed: 'The selected nodes are in different groups and can’t be grouped together',\n added: 'Added {node}',\n connectTo: 'Connect to {port} of {node}; arrow keys pick another, Enter confirms',\n noTarget: 'No port to connect to',\n stale: '{count} edges no longer match their ports',\n refused: {\n direction: 'Edges go from an output to an input',\n self: 'A node can’t connect to itself',\n type: 'The port types don’t match',\n duplicate: 'These ports are already connected',\n cycle: 'This would make a cycle',\n custom: 'Can’t connect to this port',\n },\n status: { wait: 'Waiting', process: 'Running', finish: 'Done', error: 'Failed' },\n board: {\n tools: 'Whiteboard tools',\n select: 'Select',\n hand: 'Hand',\n rect: 'Rectangle',\n ellipse: 'Ellipse',\n diamond: 'Diamond',\n sticky: 'Sticky note',\n text: 'Text',\n editText: 'Edit text',\n picked: '{tool} tool',\n named: '{kind}: {text}',\n pen: 'Pen',\n eraser: 'Eraser',\n image: 'Image',\n ink: 'Stroke',\n imageFailed: '{name} could not be added',\n imagesFailed: '{count} images could not be added',\n erased: 'Erased {count} strokes',\n rotate: 'Rotate 90° clockwise',\n unrotate: 'Reset rotation',\n turned: 'Rotated to {degrees}°',\n routeOf: 'Route: {value}',\n dashOf: 'Line: {value}',\n arrowOf: 'Arrows: {value}',\n routes: { straight: 'Straight', elbow: 'Elbow', curve: 'Curved' },\n dashes: { solid: 'Solid', dashed: 'Dashed', dotted: 'Dotted', 'dash-dot': 'Dash-dot' },\n arrows: { none: 'No arrows', end: 'Arrow at end', both: 'Arrows at both ends' },\n mixed: 'Mixed',\n routeSet: 'Changed to {value}',\n dashSet: 'Changed to {value}',\n arrowSet: 'Changed to {value}',\n },\n}\n\nexport const flowLocales: Record<string, FlowMessages> = { 'zh-CN': zhCN, 'zh-TW': zhTW, en }\n\n/** Texts to change; nested groups are merged, so only the ones given are replaced. */\nexport type FlowMessagesOverride = {\n [K in keyof FlowMessages]?: FlowMessages[K] extends string ? string : Partial<FlowMessages[K]>\n}\n\n/**\n * The flow editor's texts, picked by the name of DouUI's current locale.\n * Pass `messages` to override any of them.\n */\nexport function useFlowMessages(override?: MaybeRefOrGetter<FlowMessagesOverride | undefined>) {\n const { locale } = useLocale()\n return computed<FlowMessages>(() => {\n const name = locale.value.name\n const base =\n flowLocales[name] ?? flowLocales[name.split('-')[0]!] ?? (name.startsWith('zh') ? zhCN : en)\n const extra = toValue(override)\n if (!extra) return base\n const out = { ...base } as Record<string, unknown>\n for (const [key, value] of Object.entries(extra)) {\n if (value === undefined) continue\n const own = out[key]\n out[key] = typeof own === 'object' && own ? { ...own, ...(value as object) } : value\n }\n return out as unknown as FlowMessages\n })\n}\n\n/** Fills `{name}` placeholders. */\nexport const format = (text: string, params: Record<string, string | number>) =>\n text.replace(/\\{(\\w+)\\}/g, (match, key: string) => String(params[key] ?? match))\n"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;EACjF;EACA,OAAO;CACT,CAAC;AACH;;AAGA,IAAa,UAAU,MAAc,WACnC,KAAK,QAAQ,eAAe,OAAO,QAAgB,OAAO,OAAO,QAAQ,KAAK,CAAC"}
|
package/dist/style.js
CHANGED
|
@@ -4,5 +4,6 @@ import 'dou-ui/components/dropdown/style'
|
|
|
4
4
|
import 'dou-ui/components/context-menu/style'
|
|
5
5
|
import 'dou-ui/components/node-graph/style'
|
|
6
6
|
import 'dou-ui/components/toggle/style'
|
|
7
|
+
import 'dou-ui/components/toast/style'
|
|
7
8
|
import 'dou-ui/components/find-replace/style'
|
|
8
9
|
import './style.css'
|
package/dist/types/locale.d.ts
CHANGED
|
@@ -137,6 +137,8 @@ export interface FlowMessages {
|
|
|
137
137
|
ink: string;
|
|
138
138
|
/** `{name}` is the file's name. */
|
|
139
139
|
imageFailed: string;
|
|
140
|
+
/** `{count}` images in one drop or pick could not be added. */
|
|
141
|
+
imagesFailed: string;
|
|
140
142
|
/** `{count}` strokes were erased. */
|
|
141
143
|
erased: string;
|
|
142
144
|
rotate: string;
|
|
@@ -11,11 +11,19 @@ export type WhiteboardUploaded = string | {
|
|
|
11
11
|
src: string;
|
|
12
12
|
alt?: string;
|
|
13
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Called for each image whose upload threw or rejected, with the file and
|
|
16
|
+
* what it threw. Giving it replaces the built-in error toast, and the app
|
|
17
|
+
* then tells the user, screen readers included, in its own way.
|
|
18
|
+
*/
|
|
19
|
+
export type WhiteboardUploadErrorHandler = (file: File, error: unknown) => void;
|
|
14
20
|
export interface WhiteboardImageOptions {
|
|
15
21
|
/** Where the images go, in canvas units; the middle of the view by default. */
|
|
16
22
|
at?: Point;
|
|
17
23
|
/** Overrides the kit's `upload` option for these images. */
|
|
18
24
|
upload?: WhiteboardUpload;
|
|
25
|
+
/** Overrides the kit's `onUploadError` option for these images. */
|
|
26
|
+
onUploadError?: WhiteboardUploadErrorHandler;
|
|
19
27
|
}
|
|
20
28
|
export declare const imageFiles: (files: Iterable<File> | null | undefined) => File[];
|
|
21
29
|
/**
|
|
@@ -2,5 +2,5 @@ export { connectorEdge, imageNode, inkNode, shapeNode, stickyNode, textNode, whi
|
|
|
2
2
|
export { imageKey, whiteboardKeys } from './model';
|
|
3
3
|
export { insertImages, pickImages } from './image';
|
|
4
4
|
export type { WhiteboardKitOptions } from './kit';
|
|
5
|
-
export type { WhiteboardImageOptions, WhiteboardUpload, WhiteboardUploaded } from './image';
|
|
5
|
+
export type { WhiteboardImageOptions, WhiteboardUpload, WhiteboardUploaded, WhiteboardUploadErrorHandler, } from './image';
|
|
6
6
|
export type { WhiteboardImageData, WhiteboardInkData, WhiteboardNodeData, WhiteboardShape, WhiteboardShapeData, WhiteboardShapeTool, WhiteboardStickyData, WhiteboardTextData, WhiteboardTool, WhiteboardArrow, WhiteboardConnectorData, WhiteboardDash, WhiteboardRoute, } from './model';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Ref } from 'vue';
|
|
2
2
|
import { type FlowExtension } from '../core/extension';
|
|
3
3
|
import { type WhiteboardImageData, type WhiteboardInkData, type WhiteboardShapeData, type WhiteboardStickyData, type WhiteboardTextData, type WhiteboardTool } from './model';
|
|
4
|
-
import { type WhiteboardUpload } from './image';
|
|
4
|
+
import { type WhiteboardUpload, type WhiteboardUploadErrorHandler } from './image';
|
|
5
5
|
import { connectorEdge } from './connector';
|
|
6
6
|
/** A rectangle, ellipse or diamond with centred text; `data.shape` says which. */
|
|
7
7
|
export declare const shapeNode: import("..").NodeTypeSpec<WhiteboardShapeData>;
|
|
@@ -27,6 +27,12 @@ export interface WhiteboardKitOptions {
|
|
|
27
27
|
* images are kept in the document as data URLs.
|
|
28
28
|
*/
|
|
29
29
|
upload?: WhiteboardUpload;
|
|
30
|
+
/**
|
|
31
|
+
* Called for each image whose `upload` failed, with the file and the
|
|
32
|
+
* error; the app then tells the user, screen readers included. Without
|
|
33
|
+
* it, a danger toast at the bottom says which images were not added.
|
|
34
|
+
*/
|
|
35
|
+
onUploadError?: WhiteboardUploadErrorHandler;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* The whiteboard: shape, sticky note and text nodes, the `connector` edge,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Ref, type ShallowRef } from 'vue';
|
|
2
2
|
import type { FlowEditorContext } from '../context';
|
|
3
3
|
import type { Point, Rect } from '../core/model';
|
|
4
|
-
import type { WhiteboardUpload } from './image';
|
|
4
|
+
import type { WhiteboardUpload, WhiteboardUploadErrorHandler } from './image';
|
|
5
5
|
import type { InkPoint } from './ink';
|
|
6
6
|
import type { WhiteboardShapeTool, WhiteboardTool } from './model';
|
|
7
7
|
/** What the board's pieces share within one editor. */
|
|
@@ -32,6 +32,8 @@ export interface WhiteboardState {
|
|
|
32
32
|
uploading: Ref<number>;
|
|
33
33
|
/** The kit's `upload` option. */
|
|
34
34
|
upload?: WhiteboardUpload;
|
|
35
|
+
/** The kit's `onUploadError` option. */
|
|
36
|
+
onUploadError?: WhiteboardUploadErrorHandler;
|
|
35
37
|
}
|
|
36
38
|
/** The board's state in an editor, made on first use. */
|
|
37
39
|
export declare function boardState(context: FlowEditorContext): WhiteboardState;
|
package/dist/whiteboard/image.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { format } from "../locale.js";
|
|
2
2
|
import { boardState } from "./state.js";
|
|
3
|
+
import { toast } from "dou-ui";
|
|
3
4
|
// src/whiteboard/image.ts
|
|
4
5
|
/** Without an upload, images are kept in the document as data URLs. */
|
|
5
6
|
var readAsDataUrl = (file) => new Promise((resolve, reject) => {
|
|
@@ -31,6 +32,7 @@ var imageFiles = (files) => [...files ?? []].filter((file) => file.type.startsWi
|
|
|
31
32
|
async function insertImages(ctx, files, options = {}) {
|
|
32
33
|
const state = boardState(ctx);
|
|
33
34
|
const upload = options.upload ?? state.upload ?? readAsDataUrl;
|
|
35
|
+
const onUploadError = options.onUploadError ?? state.onUploadError;
|
|
34
36
|
const at = options.at;
|
|
35
37
|
const t = ctx.messages.value.board;
|
|
36
38
|
const root = ctx.root.value;
|
|
@@ -42,19 +44,27 @@ async function insertImages(ctx, files, options = {}) {
|
|
|
42
44
|
});
|
|
43
45
|
state.uploading.value += files.length;
|
|
44
46
|
const ids = [];
|
|
47
|
+
const failed = [];
|
|
45
48
|
try {
|
|
46
49
|
await Promise.all(files.map(async (file, i) => {
|
|
47
50
|
let src;
|
|
48
51
|
let alt = file.name.replace(/\.[^.]+$/, "");
|
|
49
52
|
try {
|
|
50
53
|
const done = await upload(file);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
src
|
|
54
|
-
|
|
54
|
+
const given = typeof done === "string" ? done : done?.src;
|
|
55
|
+
if (typeof given !== "string" || !given) {
|
|
56
|
+
if (process.env.NODE_ENV !== "production") console.warn(`[@dou-ui/flow] upload returned no src for "${file.name}"; return a URL or { src, alt }`);
|
|
57
|
+
throw new Error("[@dou-ui/flow] upload returned no src");
|
|
58
|
+
}
|
|
59
|
+
src = given;
|
|
60
|
+
if (typeof done === "object" && done.alt !== void 0) alt = done.alt;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
failed.push(file);
|
|
63
|
+
try {
|
|
64
|
+
onUploadError?.(file, error);
|
|
65
|
+
} catch (thrown) {
|
|
66
|
+
console.error("[@dou-ui/flow] onUploadError threw", thrown);
|
|
55
67
|
}
|
|
56
|
-
} catch {
|
|
57
|
-
ctx.announce(format(t.imageFailed, { name: file.name }));
|
|
58
68
|
return;
|
|
59
69
|
}
|
|
60
70
|
const size = await naturalSize(src) ?? {
|
|
@@ -82,6 +92,7 @@ async function insertImages(ctx, files, options = {}) {
|
|
|
82
92
|
} finally {
|
|
83
93
|
state.uploading.value -= files.length;
|
|
84
94
|
}
|
|
95
|
+
if (failed.length && !onUploadError) toast.danger(failed.length === 1 ? format(t.imageFailed, { name: failed[0].name }) : format(t.imagesFailed, { count: failed.length }), { placement: "bottom" });
|
|
85
96
|
if (ids.length > 1) ctx.selection.value = {
|
|
86
97
|
nodes: ids,
|
|
87
98
|
edges: []
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","names":[],"sources":["../../src/whiteboard/image.ts"],"sourcesContent":["import type { FlowEditorContext } from '../context'\nimport type { Point } from '../core/model'\nimport { format } from '../locale'\nimport { boardState } from './state'\n\n/**\n * Turns a file into the `src` an image node keeps, e.g. by uploading it.\n * Return `{ src, alt }` to give the image its description; it is the file's\n * name otherwise.\n */\nexport type WhiteboardUpload = (file: File) => WhiteboardUploaded | Promise<WhiteboardUploaded>\n\n/** An image's address, or its address and description. */\nexport type WhiteboardUploaded = string | { src: string; alt?: string }\n\nexport interface WhiteboardImageOptions {\n /** Where the images go, in canvas units; the middle of the view by default. */\n at?: Point\n /** Overrides the kit's `upload` option for these images. */\n upload?: WhiteboardUpload\n}\n\n/** Without an upload, images are kept in the document as data URLs. */\nconst readAsDataUrl: WhiteboardUpload = (file) =>\n new Promise((resolve, reject) => {\n const reader = new FileReader()\n reader.addEventListener('load', () => resolve(String(reader.result)))\n reader.addEventListener('error', () => reject(reader.error))\n reader.readAsDataURL(file)\n })\n\n/** An image's own size, or `null` when it can't be loaded. */\nfunction naturalSize(src: string): Promise<{ width: number; height: number } | null> {\n return new Promise((resolve) => {\n const img = new Image()\n img.addEventListener('load', () =>\n resolve({ width: img.naturalWidth, height: img.naturalHeight }),\n )\n img.addEventListener('error', () => resolve(null))\n // an image that never answers gets the default size\n setTimeout(() => resolve(null), 4000)\n img.src = src\n })\n}\n\n/** New images are at most this wide or tall, in canvas units. */\nconst MAX_SIDE = 320\n\nexport const imageFiles = (files: Iterable<File> | null | undefined) =>\n [...(files ?? [])].filter((file) => file.type.startsWith('image/'))\n\n/**\n * Adds an image node for each file, centred on `at` and stepped down and\n * right when there are several. Files go through the kit's `upload` option.\n */\nexport async function insertImages(\n ctx: FlowEditorContext,\n files: File[],\n options: WhiteboardImageOptions = {},\n) {\n const state = boardState(ctx)\n const upload = options.upload ?? state.upload ?? readAsDataUrl\n const at = options.at\n const t = ctx.messages.value.board\n const root = ctx.root.value\n if (!root || ctx.readonly.value) return\n const box = root.getBoundingClientRect()\n const centre = at ?? ctx.toCanvas({ x: box.left + box.width / 2, y: box.top + box.height / 2 })\n state.uploading.value += files.length\n const ids: string[] = []\n try {\n await Promise.all(\n files.map(async (file, i) => {\n let src: string\n let alt = file.name.replace(/\\.[^.]+$/, '')\n try {\n const done = await upload(file)\n
|
|
1
|
+
{"version":3,"file":"image.js","names":[],"sources":["../../src/whiteboard/image.ts"],"sourcesContent":["import { toast } from 'dou-ui'\nimport type { FlowEditorContext } from '../context'\nimport type { Point } from '../core/model'\nimport { format } from '../locale'\nimport { boardState } from './state'\n\n/**\n * Turns a file into the `src` an image node keeps, e.g. by uploading it.\n * Return `{ src, alt }` to give the image its description; it is the file's\n * name otherwise.\n */\nexport type WhiteboardUpload = (file: File) => WhiteboardUploaded | Promise<WhiteboardUploaded>\n\n/** An image's address, or its address and description. */\nexport type WhiteboardUploaded = string | { src: string; alt?: string }\n\n/**\n * Called for each image whose upload threw or rejected, with the file and\n * what it threw. Giving it replaces the built-in error toast, and the app\n * then tells the user, screen readers included, in its own way.\n */\nexport type WhiteboardUploadErrorHandler = (file: File, error: unknown) => void\n\nexport interface WhiteboardImageOptions {\n /** Where the images go, in canvas units; the middle of the view by default. */\n at?: Point\n /** Overrides the kit's `upload` option for these images. */\n upload?: WhiteboardUpload\n /** Overrides the kit's `onUploadError` option for these images. */\n onUploadError?: WhiteboardUploadErrorHandler\n}\n\n/** Without an upload, images are kept in the document as data URLs. */\nconst readAsDataUrl: WhiteboardUpload = (file) =>\n new Promise((resolve, reject) => {\n const reader = new FileReader()\n reader.addEventListener('load', () => resolve(String(reader.result)))\n reader.addEventListener('error', () => reject(reader.error))\n reader.readAsDataURL(file)\n })\n\n/** An image's own size, or `null` when it can't be loaded. */\nfunction naturalSize(src: string): Promise<{ width: number; height: number } | null> {\n return new Promise((resolve) => {\n const img = new Image()\n img.addEventListener('load', () =>\n resolve({ width: img.naturalWidth, height: img.naturalHeight }),\n )\n img.addEventListener('error', () => resolve(null))\n // an image that never answers gets the default size\n setTimeout(() => resolve(null), 4000)\n img.src = src\n })\n}\n\n/** New images are at most this wide or tall, in canvas units. */\nconst MAX_SIDE = 320\n\nexport const imageFiles = (files: Iterable<File> | null | undefined) =>\n [...(files ?? [])].filter((file) => file.type.startsWith('image/'))\n\n/**\n * Adds an image node for each file, centred on `at` and stepped down and\n * right when there are several. Files go through the kit's `upload` option.\n */\nexport async function insertImages(\n ctx: FlowEditorContext,\n files: File[],\n options: WhiteboardImageOptions = {},\n) {\n const state = boardState(ctx)\n const upload = options.upload ?? state.upload ?? readAsDataUrl\n const onUploadError = options.onUploadError ?? state.onUploadError\n const at = options.at\n const t = ctx.messages.value.board\n const root = ctx.root.value\n if (!root || ctx.readonly.value) return\n const box = root.getBoundingClientRect()\n const centre = at ?? ctx.toCanvas({ x: box.left + box.width / 2, y: box.top + box.height / 2 })\n state.uploading.value += files.length\n const ids: string[] = []\n const failed: File[] = []\n try {\n await Promise.all(\n files.map(async (file, i) => {\n let src: string\n let alt = file.name.replace(/\\.[^.]+$/, '')\n try {\n const done = await upload(file)\n const given = typeof done === 'string' ? done : done?.src\n if (typeof given !== 'string' || !given) {\n // a broken image would go in otherwise\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[@dou-ui/flow] upload returned no src for \"${file.name}\"; return a URL or { src, alt }`,\n )\n }\n throw new Error('[@dou-ui/flow] upload returned no src')\n }\n src = given\n if (typeof done === 'object' && done.alt !== undefined) alt = done.alt\n } catch (error) {\n failed.push(file)\n try {\n onUploadError?.(file, error)\n } catch (thrown) {\n // the other images still go in\n console.error('[@dou-ui/flow] onUploadError threw', thrown)\n }\n return\n }\n const size = (await naturalSize(src)) ?? { width: MAX_SIDE, height: MAX_SIDE * 0.75 }\n const scale = Math.min(1, MAX_SIDE / Math.max(size.width, size.height))\n const id = ctx.insertNode('image', {\n at: { x: centre.x + i * 24, y: centre.y + i * 24 },\n data: { src, alt },\n size: { width: Math.round(size.width * scale), height: Math.round(size.height * scale) },\n focus: false,\n })\n if (id) ids.push(id)\n }),\n )\n } finally {\n state.uploading.value -= files.length\n }\n // one toast for the whole drop; it is an alert, so screen readers hear it\n // too. At the bottom, so it never covers the board's toolbar for a retry.\n if (failed.length && !onUploadError) {\n toast.danger(\n failed.length === 1\n ? format(t.imageFailed, { name: failed[0]!.name })\n : format(t.imagesFailed, { count: failed.length }),\n { placement: 'bottom' },\n )\n }\n if (ids.length > 1) ctx.selection.value = { nodes: ids, edges: [] }\n}\n\n/** Opens the file picker and inserts what is picked, as `insertImages` does. */\nexport function pickImages(ctx: FlowEditorContext, options: WhiteboardImageOptions = {}) {\n const input = document.createElement('input')\n input.type = 'file'\n input.accept = 'image/*'\n input.multiple = true\n input.addEventListener('change', () => {\n const files = imageFiles(input.files)\n if (files.length) void insertImages(ctx, files, options)\n })\n input.click()\n}\n"],"mappings":";;;;;AAiCA,IAAM,iBAAmC,SACvC,IAAI,SAAS,SAAS,WAAW;CAC/B,MAAM,SAAS,IAAI,WAAW;CAC9B,OAAO,iBAAiB,cAAc,QAAQ,OAAO,OAAO,MAAM,CAAC,CAAC;CACpE,OAAO,iBAAiB,eAAe,OAAO,OAAO,KAAK,CAAC;CAC3D,OAAO,cAAc,IAAI;AAC3B,CAAC;;AAGH,SAAS,YAAY,KAAgE;CACnF,OAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,MAAM,IAAI,MAAM;EACtB,IAAI,iBAAiB,cACnB,QAAQ;GAAE,OAAO,IAAI;GAAc,QAAQ,IAAI;EAAc,CAAC,CAChE;EACA,IAAI,iBAAiB,eAAe,QAAQ,IAAI,CAAC;EAEjD,iBAAiB,QAAQ,IAAI,GAAG,GAAI;EACpC,IAAI,MAAM;CACZ,CAAC;AACH;;AAGA,IAAM,WAAW;AAEjB,IAAa,cAAc,UACzB,CAAC,GAAI,SAAS,CAAC,CAAE,CAAC,CAAC,Q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"],"sourcesContent":["import type { ContextMenuItem } from 'dou-ui'\nimport { RotateCwIcon } from '@dou-ui/icons'\nimport { watch, type Ref } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport { defineFlowExtension, type FlowExtension } from '../core/extension'\nimport { createId, type FlowData, type FlowNode, type Point, type Rect } from '../core/model'\nimport { defineNodeType } from '../core/node-types'\nimport { format, type FlowMessages } from '../locale'\nimport BoardNode from './board-node.vue'\nimport BoardDraft from './board-draft.vue'\nimport WhiteboardToolbar from './whiteboard-toolbar.vue'\nimport {\n anchorPorts,\n imageKey,\n type WhiteboardImageData,\n type WhiteboardInkData,\n type WhiteboardNodeData,\n type WhiteboardShapeData,\n type WhiteboardShapeTool,\n type WhiteboardStickyData,\n type WhiteboardTextData,\n type WhiteboardTool,\n whiteboardKeys,\n} from './model'\nimport { imageFiles, insertImages, pickImages, type WhiteboardUpload } from './image'\nimport { connectorEdge, connectorToolbar } from './connector'\nimport { drawBoardNode } from './draw'\nimport { drawInk, erase } from './pen'\nimport { boardState } from './state'\n\n/** The node types the whiteboard adds; only they turn. */\nconst BOARD_TYPES = new Set(['shape', 'sticky', 'text', 'ink', 'image'])\n\n/** \"Rectangle: text\", or just \"Rectangle\" while it has none. */\nconst nameOf = (kind: string, text: string | undefined, t: FlowMessages) =>\n text ? format(t.board.named, { kind, text }) : kind\n\n/** How far a board node is turned, from `data.rotation`. */\nconst turnedBy = (node: FlowNode<WhiteboardNodeData>) => node.data?.rotation ?? 0\n\n/** A rectangle, ellipse or diamond with centred text; `data.shape` says which. */\nexport const shapeNode = defineNodeType<WhiteboardShapeData>({\n type: 'shape',\n component: BoardNode,\n ports: anchorPorts,\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 160, height: 100 },\n defaults: () => ({ shape: 'rect' }),\n label: (node, t) => nameOf(t.board[node.data?.shape ?? 'rect'], node.data?.text, t),\n})\n\n/** A square note in a soft color. */\nexport const stickyNode = defineNodeType<WhiteboardStickyData>({\n type: 'sticky',\n component: BoardNode,\n ports: anchorPorts,\n frame: false,\n resizable: { minWidth: 64, minHeight: 64 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 160, height: 160 },\n defaults: () => ({}),\n label: (node, t) => nameOf(t.board.sticky, node.data?.text, t),\n})\n\n/** Text on its own; it grows as it is typed. */\nexport const textNode = defineNodeType<WhiteboardTextData>({\n type: 'text',\n component: BoardNode,\n ports: anchorPorts,\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 200, height: 40 },\n defaults: () => ({}),\n label: (node, t) => nameOf(t.board.text, node.data?.text, t),\n})\n\n/** A pen stroke; it stretches with its box. */\nexport const inkNode = defineNodeType<WhiteboardInkData>({\n type: 'ink',\n component: BoardNode,\n frame: false,\n resizable: { minWidth: 8, minHeight: 8 },\n rotation: turnedBy,\n draw: drawBoardNode,\n defaults: () => ({ points: [], box: [0, 0] }),\n label: (_, t) => t.board.ink,\n})\n\n/** An image; `data.src` is its address. */\nexport const imageNode = defineNodeType<WhiteboardImageData>({\n type: 'image',\n component: BoardNode,\n ports: anchorPorts,\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 240, height: 180 },\n defaults: () => ({ src: '' }),\n label: (node, t) => nameOf(t.board.image, node.data?.alt, t),\n})\n\n/** The node type and data each drawing tool adds. */\nfunction kindOf(tool: WhiteboardShapeTool): { type: string; data: FlowData } {\n if (tool === 'sticky' || tool === 'text') return { type: tool, data: {} }\n return { type: 'shape', data: { shape: tool } }\n}\n\nfunction nodeFor(tool: WhiteboardShapeTool, rect: Rect): FlowNode {\n // text grows with what is typed: it keeps no height\n const height = tool === 'text' ? undefined : rect.height\n return { id: createId(), x: rect.x, y: rect.y, width: rect.width, height, ...kindOf(tool) }\n}\n\nconst SIZES: Record<WhiteboardShapeTool, { width: number; height: number }> = {\n rect: { width: 160, height: 100 },\n ellipse: { width: 140, height: 100 },\n diamond: { width: 140, height: 120 },\n sticky: { width: 160, height: 160 },\n text: { width: 200, height: 40 },\n}\n\n/** After a tool put down a node: back to select unless kept, and notes and text open to be written in. */\nfunction added(ctx: FlowEditorContext, tool: WhiteboardShapeTool, id: string) {\n const state = boardState(ctx)\n if (!state.locked.value) state.tool.value = 'select'\n if (tool === 'sticky' || tool === 'text') state.editing.value = id\n}\n\nexport interface WhiteboardKitOptions {\n /**\n * The current tool, to share with your own toolbar. Made inside the kit\n * when left out.\n */\n tool?: Ref<WhiteboardTool>\n /** The built-in toolbar at the top of the editor. Defaults to `true`. */\n toolbar?: boolean\n /**\n * Turns an image file that is dropped, pasted or picked into the `src` it\n * is kept as, e.g. by uploading it and returning its address. Without it,\n * images are kept in the document as data URLs.\n */\n upload?: WhiteboardUpload\n}\n\n/**\n * The whiteboard: shape, sticky note and text nodes, the `connector` edge,\n * the drawing tools with their keys, and a toolbar. Add it after `flowKit()`.\n */\nexport function whiteboardKit(options: WhiteboardKitOptions = {}): FlowExtension {\n return defineFlowExtension({\n name: 'whiteboard',\n nodeTypes: [shapeNode, stickyNode, textNode, inkNode, imageNode],\n edgeTypes: [connectorEdge],\n edgeToolbarItems: connectorToolbar,\n edgeType: 'connector',\n layers: { above: [BoardDraft] },\n overlays: options.toolbar === false ? [] : [WhiteboardToolbar],\n\n setup(ctx) {\n const state = boardState(ctx)\n state.upload = options.upload\n const stops: (() => void)[] = []\n if (options.tool) {\n const outer = options.tool\n state.tool.value = outer.value\n stops.push(\n watch(outer, (tool) => (state.tool.value = tool)),\n watch(state.tool, (tool) => (outer.value = tool)),\n )\n }\n // the cursor says what a press will do\n stops.push(\n watch(\n state.tool,\n (tool) => {\n const root = ctx.root.value\n if (root) root.dataset.boardTool = tool\n },\n { immediate: true },\n ),\n watch(state.panning, (panning) => {\n const root = ctx.root.value\n if (root) root.toggleAttribute('data-board-panning', panning)\n }),\n )\n // images dropped on the board or pasted into it\n const root = ctx.root.value\n const onDragOver = (event: DragEvent) => {\n if (ctx.readonly.value || !event.dataTransfer?.types.includes('Files')) return\n event.preventDefault()\n event.dataTransfer.dropEffect = 'copy'\n }\n const onDrop = (event: DragEvent) => {\n const files = imageFiles(event.dataTransfer?.files)\n if (ctx.readonly.value || !files.length) return\n event.preventDefault()\n const at = ctx.toCanvas({ x: event.clientX, y: event.clientY })\n void insertImages(ctx, files, { at })\n }\n const onPaste = (event: ClipboardEvent) => {\n const active = document.activeElement\n if (ctx.readonly.value || !root || !active || !root.contains(active)) return\n // pasting into a field is the field's\n if (active.closest('input, textarea, [contenteditable]')) return\n const files = imageFiles(event.clipboardData?.files)\n if (!files.length) return\n event.preventDefault()\n event.stopImmediatePropagation()\n void insertImages(ctx, files)\n }\n root?.addEventListener('dragover', onDragOver)\n root?.addEventListener('drop', onDrop)\n // before the editor's own paste, which reads nodes from text\n document.addEventListener('paste', onPaste, true)\n return () => {\n for (const stop of stops) stop()\n root?.removeEventListener('dragover', onDragOver)\n root?.removeEventListener('drop', onDrop)\n document.removeEventListener('paste', onPaste, true)\n delete ctx.root.value?.dataset.boardTool\n ctx.root.value?.removeAttribute('data-board-panning')\n }\n },\n\n press(ctx, press) {\n const state = boardState(ctx)\n const tool = state.tool.value\n if (tool === 'select') return\n // a press puts down whatever text was being typed\n state.editing.value = null\n if (tool === 'hand') {\n const start = { x: press.event.clientX, y: press.event.clientY }\n const origin = { ...ctx.viewport.value }\n state.panning.value = true\n const stop = () => (state.panning.value = false)\n return {\n end: stop,\n cancel: stop,\n move(_, event) {\n ctx.setViewport({\n ...origin,\n x: origin.x + event.clientX - start.x,\n y: origin.y + event.clientY - start.y,\n })\n },\n }\n }\n if (tool === 'pen') return drawInk(ctx, press.event)\n if (tool === 'eraser') return erase(ctx, press.point)\n const start = press.point\n const rectTo = (point: Point, square: boolean) => {\n let width = Math.abs(point.x - start.x)\n let height = Math.abs(point.y - start.y)\n if (square) width = height = Math.max(width, height)\n return {\n x: point.x < start.x ? start.x - width : start.x,\n y: point.y < start.y ? start.y - height : start.y,\n width,\n height,\n }\n }\n const done = (rect: Rect | null) => {\n state.draft.value = null\n if (!rect) return\n const node = nodeFor(tool, rect)\n ctx.transact((tr) => tr.addNode(node))\n ctx.selection.value = { nodes: [node.id], edges: [] }\n ctx.announce(format(ctx.messages.value.added, { node: ctx.messages.value.board[tool] }))\n added(ctx, tool, node.id)\n }\n return {\n move(point, event) {\n state.draft.value = { ...rectTo(point, event.shiftKey), tool }\n },\n end(point, event) {\n const rect = rectTo(point, event.shiftKey)\n const min = 8 / ctx.viewport.value.zoom\n if (rect.width < min && rect.height < min) {\n // a click: the default size, centred where it was clicked\n const size = SIZES[tool]\n done({ x: start.x - size.width / 2, y: start.y - size.height / 2, ...size })\n } else {\n done({\n ...rect,\n width: Math.max(rect.width, 24),\n height: tool === 'text' ? Math.max(rect.height, 40) : Math.max(rect.height, 24),\n })\n }\n },\n cancel: () => done(null),\n }\n },\n\n contextMenu(ctx, target) {\n if (target.kind !== 'node' || ctx.readonly.value) return []\n const t = ctx.messages.value.board\n const items: ContextMenuItem[] = []\n const node = target.node\n if (BOARD_TYPES.has(node.type ?? '') && ctx.selection.value.nodes.length <= 1) {\n const rotation = (node.data?.rotation as number | undefined) ?? 0\n const rotate = (to: number) => {\n ctx.transact((tr) => tr.updateData(node.id, { rotation: to || undefined }))\n ctx.announce(format(t.turned, { degrees: to }))\n }\n items.push(\n {\n key: 'rotate',\n label: t.rotate,\n icon: RotateCwIcon,\n divided: true,\n disabled: !!node.locked,\n run: () => rotate((rotation + 90) % 360),\n },\n {\n key: 'unrotate',\n label: t.unrotate,\n disabled: !rotation || !!node.locked,\n run: () => rotate(0),\n },\n )\n }\n return items\n },\n\n keymap(ctx) {\n const state = boardState(ctx)\n const pick = (tool: WhiteboardTool) => () => {\n state.tool.value = tool\n state.locked.value = false\n const t = ctx.messages.value.board\n ctx.announce(format(t.picked, { tool: t[tool] }))\n }\n const keys: Record<string, () => boolean | void> = {}\n for (const [tool, key] of Object.entries(whiteboardKeys))\n keys[key] = pick(tool as WhiteboardTool)\n return {\n ...keys,\n [imageKey]: () => {\n if (ctx.readonly.value) return false\n pickImages(ctx)\n },\n enter: () => {\n if (ctx.readonly.value) return false\n const tool = state.tool.value\n // with a drawing tool, Enter puts one down: after the selected node, or mid-view\n if (tool !== 'select' && tool !== 'hand' && tool !== 'pen' && tool !== 'eraser') {\n const { type, data } = kindOf(tool)\n // text keeps no height, as when drawn\n const size =\n tool === 'text' ? { width: SIZES.text.width, height: undefined } : SIZES[tool]\n // notes and text take focus in their own field\n const writes = tool === 'sticky' || tool === 'text'\n const id = ctx.insertNode(type, { data, size, focus: !writes })\n if (id) added(ctx, tool, id)\n return\n }\n // otherwise it writes in the selected note or shape\n const { nodes, edges } = ctx.selection.value\n if (nodes.length !== 1 || edges.length || ctx.readonly.value) return false\n const node = ctx.doc.value.nodes.find((n) => n.id === nodes[0])\n if (!node || !['shape', 'sticky', 'text'].includes(node.type ?? '')) return false\n state.editing.value = node.id\n },\n escape: () => {\n if (state.tool.value === 'select') return false\n state.tool.value = 'select'\n },\n }\n },\n })\n}\n\nexport { connectorEdge }\n"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,IAAM,8BAAc,IAAI,IAAI;CAAC;CAAS;CAAU;CAAQ;CAAO;AAAO,CAAC;;AAGvE,IAAM,UAAU,MAAc,MAA0B,MACtD,OAAO,OAAO,EAAE,MAAM,OAAO;CAAE;CAAM;AAAK,CAAC,IAAI;;AAGjD,IAAM,YAAY,SAAuC,KAAK,MAAM,YAAY;;AAGhF,IAAa,YAAY,eAAoC;CAC3D,MAAM;CACN,WAAWA;CACX,OAAO;CACP,OAAO;CACP,WAAW;EAAE,UAAU;EAAI,WAAW;CAAG;CACzC,UAAU;CACV,MAAM;CACN,MAAM;EAAE,OAAO;EAAK,QAAQ;CAAI;CAChC,iBAAiB,EAAE,OAAO,OAAO;CACjC,QAAQ,MAAM,MAAM,OAAO,EAAE,MAAM,KAAK,MAA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ElC,MAAM,OACJ,SAAS,SAAS;OAAE,OAAO,MAAM,KAAK;OAAO,QAAQ,KAAA;MAAU,IAAI,MAAM;MAE3E,MAAM,SAAS,SAAS,YAAY,SAAS;MAC7C,MAAM,KAAK,IAAI,WAAW,MAAM;OAAE;OAAM;OAAM,OAAO,CAAC;MAAO,CAAC;MAC9D,IAAI,IAAI,MAAM,KAAK,MAAM,EAAE;MAC3B;KACF;KAEA,MAAM,EAAE,OAAO,UAAU,IAAI,UAAU;KACvC,IAAI,MAAM,WAAW,KAAK,MAAM,UAAU,IAAI,SAAS,OAAO,OAAO;KACrE,MAAM,OAAO,IAAI,IAAI,MAAM,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE;KAC9D,IAAI,CAAC,QAAQ,CAAC;MAAC;MAAS;MAAU;KAAM,CAAC,CAAC,SAAS,KAAK,QAAQ,EAAE,GAAG,OAAO;KAC5E,MAAM,QAAQ,QAAQ,KAAK;IAC7B;IACA,cAAc;KACZ,IAAI,MAAM,KAAK,UAAU,UAAU,OAAO;KAC1C,MAAM,KAAK,QAAQ;IACrB;GACF;EACF;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"kit.js","names":["BoardNode","BoardDraft","WhiteboardToolbar"],"sources":["../../src/whiteboard/kit.ts"],"sourcesContent":["import type { ContextMenuItem } from 'dou-ui'\nimport { RotateCwIcon } from '@dou-ui/icons'\nimport { watch, type Ref } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport { defineFlowExtension, type FlowExtension } from '../core/extension'\nimport { createId, type FlowData, type FlowNode, type Point, type Rect } from '../core/model'\nimport { defineNodeType } from '../core/node-types'\nimport { format, type FlowMessages } from '../locale'\nimport BoardNode from './board-node.vue'\nimport BoardDraft from './board-draft.vue'\nimport WhiteboardToolbar from './whiteboard-toolbar.vue'\nimport {\n anchorPorts,\n imageKey,\n type WhiteboardImageData,\n type WhiteboardInkData,\n type WhiteboardNodeData,\n type WhiteboardShapeData,\n type WhiteboardShapeTool,\n type WhiteboardStickyData,\n type WhiteboardTextData,\n type WhiteboardTool,\n whiteboardKeys,\n} from './model'\nimport {\n imageFiles,\n insertImages,\n pickImages,\n type WhiteboardUpload,\n type WhiteboardUploadErrorHandler,\n} from './image'\nimport { connectorEdge, connectorToolbar } from './connector'\nimport { drawBoardNode } from './draw'\nimport { drawInk, erase } from './pen'\nimport { boardState } from './state'\n\n/** The node types the whiteboard adds; only they turn. */\nconst BOARD_TYPES = new Set(['shape', 'sticky', 'text', 'ink', 'image'])\n\n/** \"Rectangle: text\", or just \"Rectangle\" while it has none. */\nconst nameOf = (kind: string, text: string | undefined, t: FlowMessages) =>\n text ? format(t.board.named, { kind, text }) : kind\n\n/** How far a board node is turned, from `data.rotation`. */\nconst turnedBy = (node: FlowNode<WhiteboardNodeData>) => node.data?.rotation ?? 0\n\n/** A rectangle, ellipse or diamond with centred text; `data.shape` says which. */\nexport const shapeNode = defineNodeType<WhiteboardShapeData>({\n type: 'shape',\n component: BoardNode,\n ports: anchorPorts,\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 160, height: 100 },\n defaults: () => ({ shape: 'rect' }),\n label: (node, t) => nameOf(t.board[node.data?.shape ?? 'rect'], node.data?.text, t),\n})\n\n/** A square note in a soft color. */\nexport const stickyNode = defineNodeType<WhiteboardStickyData>({\n type: 'sticky',\n component: BoardNode,\n ports: anchorPorts,\n frame: false,\n resizable: { minWidth: 64, minHeight: 64 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 160, height: 160 },\n defaults: () => ({}),\n label: (node, t) => nameOf(t.board.sticky, node.data?.text, t),\n})\n\n/** Text on its own; it grows as it is typed. */\nexport const textNode = defineNodeType<WhiteboardTextData>({\n type: 'text',\n component: BoardNode,\n ports: anchorPorts,\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 200, height: 40 },\n defaults: () => ({}),\n label: (node, t) => nameOf(t.board.text, node.data?.text, t),\n})\n\n/** A pen stroke; it stretches with its box. */\nexport const inkNode = defineNodeType<WhiteboardInkData>({\n type: 'ink',\n component: BoardNode,\n frame: false,\n resizable: { minWidth: 8, minHeight: 8 },\n rotation: turnedBy,\n draw: drawBoardNode,\n defaults: () => ({ points: [], box: [0, 0] }),\n label: (_, t) => t.board.ink,\n})\n\n/** An image; `data.src` is its address. */\nexport const imageNode = defineNodeType<WhiteboardImageData>({\n type: 'image',\n component: BoardNode,\n ports: anchorPorts,\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 240, height: 180 },\n defaults: () => ({ src: '' }),\n label: (node, t) => nameOf(t.board.image, node.data?.alt, t),\n})\n\n/** The node type and data each drawing tool adds. */\nfunction kindOf(tool: WhiteboardShapeTool): { type: string; data: FlowData } {\n if (tool === 'sticky' || tool === 'text') return { type: tool, data: {} }\n return { type: 'shape', data: { shape: tool } }\n}\n\nfunction nodeFor(tool: WhiteboardShapeTool, rect: Rect): FlowNode {\n // text grows with what is typed: it keeps no height\n const height = tool === 'text' ? undefined : rect.height\n return { id: createId(), x: rect.x, y: rect.y, width: rect.width, height, ...kindOf(tool) }\n}\n\nconst SIZES: Record<WhiteboardShapeTool, { width: number; height: number }> = {\n rect: { width: 160, height: 100 },\n ellipse: { width: 140, height: 100 },\n diamond: { width: 140, height: 120 },\n sticky: { width: 160, height: 160 },\n text: { width: 200, height: 40 },\n}\n\n/** After a tool put down a node: back to select unless kept, and notes and text open to be written in. */\nfunction added(ctx: FlowEditorContext, tool: WhiteboardShapeTool, id: string) {\n const state = boardState(ctx)\n if (!state.locked.value) state.tool.value = 'select'\n if (tool === 'sticky' || tool === 'text') state.editing.value = id\n}\n\nexport interface WhiteboardKitOptions {\n /**\n * The current tool, to share with your own toolbar. Made inside the kit\n * when left out.\n */\n tool?: Ref<WhiteboardTool>\n /** The built-in toolbar at the top of the editor. Defaults to `true`. */\n toolbar?: boolean\n /**\n * Turns an image file that is dropped, pasted or picked into the `src` it\n * is kept as, e.g. by uploading it and returning its address. Without it,\n * images are kept in the document as data URLs.\n */\n upload?: WhiteboardUpload\n /**\n * Called for each image whose `upload` failed, with the file and the\n * error; the app then tells the user, screen readers included. Without\n * it, a danger toast at the bottom says which images were not added.\n */\n onUploadError?: WhiteboardUploadErrorHandler\n}\n\n/**\n * The whiteboard: shape, sticky note and text nodes, the `connector` edge,\n * the drawing tools with their keys, and a toolbar. Add it after `flowKit()`.\n */\nexport function whiteboardKit(options: WhiteboardKitOptions = {}): FlowExtension {\n return defineFlowExtension({\n name: 'whiteboard',\n nodeTypes: [shapeNode, stickyNode, textNode, inkNode, imageNode],\n edgeTypes: [connectorEdge],\n edgeToolbarItems: connectorToolbar,\n edgeType: 'connector',\n layers: { above: [BoardDraft] },\n overlays: options.toolbar === false ? [] : [WhiteboardToolbar],\n\n setup(ctx) {\n const state = boardState(ctx)\n state.upload = options.upload\n state.onUploadError = options.onUploadError\n const stops: (() => void)[] = []\n if (options.tool) {\n const outer = options.tool\n state.tool.value = outer.value\n stops.push(\n watch(outer, (tool) => (state.tool.value = tool)),\n watch(state.tool, (tool) => (outer.value = tool)),\n )\n }\n // the cursor says what a press will do\n stops.push(\n watch(\n state.tool,\n (tool) => {\n const root = ctx.root.value\n if (root) root.dataset.boardTool = tool\n },\n { immediate: true },\n ),\n watch(state.panning, (panning) => {\n const root = ctx.root.value\n if (root) root.toggleAttribute('data-board-panning', panning)\n }),\n )\n // images dropped on the board or pasted into it\n const root = ctx.root.value\n const onDragOver = (event: DragEvent) => {\n if (ctx.readonly.value || !event.dataTransfer?.types.includes('Files')) return\n event.preventDefault()\n event.dataTransfer.dropEffect = 'copy'\n }\n const onDrop = (event: DragEvent) => {\n const files = imageFiles(event.dataTransfer?.files)\n if (ctx.readonly.value || !files.length) return\n event.preventDefault()\n const at = ctx.toCanvas({ x: event.clientX, y: event.clientY })\n void insertImages(ctx, files, { at })\n }\n const onPaste = (event: ClipboardEvent) => {\n const active = document.activeElement\n if (ctx.readonly.value || !root || !active || !root.contains(active)) return\n // pasting into a field is the field's\n if (active.closest('input, textarea, [contenteditable]')) return\n const files = imageFiles(event.clipboardData?.files)\n if (!files.length) return\n event.preventDefault()\n event.stopImmediatePropagation()\n void insertImages(ctx, files)\n }\n root?.addEventListener('dragover', onDragOver)\n root?.addEventListener('drop', onDrop)\n // before the editor's own paste, which reads nodes from text\n document.addEventListener('paste', onPaste, true)\n return () => {\n for (const stop of stops) stop()\n root?.removeEventListener('dragover', onDragOver)\n root?.removeEventListener('drop', onDrop)\n document.removeEventListener('paste', onPaste, true)\n delete ctx.root.value?.dataset.boardTool\n ctx.root.value?.removeAttribute('data-board-panning')\n }\n },\n\n press(ctx, press) {\n const state = boardState(ctx)\n const tool = state.tool.value\n if (tool === 'select') return\n // a press puts down whatever text was being typed\n state.editing.value = null\n if (tool === 'hand') {\n const start = { x: press.event.clientX, y: press.event.clientY }\n const origin = { ...ctx.viewport.value }\n state.panning.value = true\n const stop = () => (state.panning.value = false)\n return {\n end: stop,\n cancel: stop,\n move(_, event) {\n ctx.setViewport({\n ...origin,\n x: origin.x + event.clientX - start.x,\n y: origin.y + event.clientY - start.y,\n })\n },\n }\n }\n if (tool === 'pen') return drawInk(ctx, press.event)\n if (tool === 'eraser') return erase(ctx, press.point)\n const start = press.point\n const rectTo = (point: Point, square: boolean) => {\n let width = Math.abs(point.x - start.x)\n let height = Math.abs(point.y - start.y)\n if (square) width = height = Math.max(width, height)\n return {\n x: point.x < start.x ? start.x - width : start.x,\n y: point.y < start.y ? start.y - height : start.y,\n width,\n height,\n }\n }\n const done = (rect: Rect | null) => {\n state.draft.value = null\n if (!rect) return\n const node = nodeFor(tool, rect)\n ctx.transact((tr) => tr.addNode(node))\n ctx.selection.value = { nodes: [node.id], edges: [] }\n ctx.announce(format(ctx.messages.value.added, { node: ctx.messages.value.board[tool] }))\n added(ctx, tool, node.id)\n }\n return {\n move(point, event) {\n state.draft.value = { ...rectTo(point, event.shiftKey), tool }\n },\n end(point, event) {\n const rect = rectTo(point, event.shiftKey)\n const min = 8 / ctx.viewport.value.zoom\n if (rect.width < min && rect.height < min) {\n // a click: the default size, centred where it was clicked\n const size = SIZES[tool]\n done({ x: start.x - size.width / 2, y: start.y - size.height / 2, ...size })\n } else {\n done({\n ...rect,\n width: Math.max(rect.width, 24),\n height: tool === 'text' ? Math.max(rect.height, 40) : Math.max(rect.height, 24),\n })\n }\n },\n cancel: () => done(null),\n }\n },\n\n contextMenu(ctx, target) {\n if (target.kind !== 'node' || ctx.readonly.value) return []\n const t = ctx.messages.value.board\n const items: ContextMenuItem[] = []\n const node = target.node\n if (BOARD_TYPES.has(node.type ?? '') && ctx.selection.value.nodes.length <= 1) {\n const rotation = (node.data?.rotation as number | undefined) ?? 0\n const rotate = (to: number) => {\n ctx.transact((tr) => tr.updateData(node.id, { rotation: to || undefined }))\n ctx.announce(format(t.turned, { degrees: to }))\n }\n items.push(\n {\n key: 'rotate',\n label: t.rotate,\n icon: RotateCwIcon,\n divided: true,\n disabled: !!node.locked,\n run: () => rotate((rotation + 90) % 360),\n },\n {\n key: 'unrotate',\n label: t.unrotate,\n disabled: !rotation || !!node.locked,\n run: () => rotate(0),\n },\n )\n }\n return items\n },\n\n keymap(ctx) {\n const state = boardState(ctx)\n const pick = (tool: WhiteboardTool) => () => {\n state.tool.value = tool\n state.locked.value = false\n const t = ctx.messages.value.board\n ctx.announce(format(t.picked, { tool: t[tool] }))\n }\n const keys: Record<string, () => boolean | void> = {}\n for (const [tool, key] of Object.entries(whiteboardKeys))\n keys[key] = pick(tool as WhiteboardTool)\n return {\n ...keys,\n [imageKey]: () => {\n if (ctx.readonly.value) return false\n pickImages(ctx)\n },\n enter: () => {\n if (ctx.readonly.value) return false\n const tool = state.tool.value\n // with a drawing tool, Enter puts one down: after the selected node, or mid-view\n if (tool !== 'select' && tool !== 'hand' && tool !== 'pen' && tool !== 'eraser') {\n const { type, data } = kindOf(tool)\n // text keeps no height, as when drawn\n const size =\n tool === 'text' ? { width: SIZES.text.width, height: undefined } : SIZES[tool]\n // notes and text take focus in their own field\n const writes = tool === 'sticky' || tool === 'text'\n const id = ctx.insertNode(type, { data, size, focus: !writes })\n if (id) added(ctx, tool, id)\n return\n }\n // otherwise it writes in the selected note or shape\n const { nodes, edges } = ctx.selection.value\n if (nodes.length !== 1 || edges.length || ctx.readonly.value) return false\n const node = ctx.doc.value.nodes.find((n) => n.id === nodes[0])\n if (!node || !['shape', 'sticky', 'text'].includes(node.type ?? '')) return false\n state.editing.value = node.id\n },\n escape: () => {\n if (state.tool.value === 'select') return false\n state.tool.value = 'select'\n },\n }\n },\n })\n}\n\nexport { connectorEdge }\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,IAAM,8BAAc,IAAI,IAAI;CAAC;CAAS;CAAU;CAAQ;CAAO;AAAO,CAAC;;AAGvE,IAAM,UAAU,MAAc,MAA0B,MACtD,OAAO,OAAO,EAAE,MAAM,OAAO;CAAE;CAAM;AAAK,CAAC,IAAI;;AAGjD,IAAM,YAAY,SAAuC,KAAK,MAAM,YAAY;;AAGhF,IAAa,YAAY,eAAoC;CAC3D,MAAM;CACN,WAAWA;CACX,OAAO;CACP,OAAO;CACP,WAAW;EAAE,UAAU;EAAI,WAAW;CAAG;CACzC,UAAU;CACV,MAAM;CACN,MAAM;EAAE,OAAO;EAAK,QAAQ;CAAI;CAChC,iBAAiB,EAAE,OAAO,OAAO;CACjC,QAAQ,MAAM,MAAM,OAAO,EAAE,MAAM,KAAK,MAAM,SAAS,SAAS,KAAK,MAAM,MAAM,CAAC;AACpF,CAAC;;AAGD,IAAa,aAAa,eAAqC;CAC7D,MAAM;CACN,WAAWA;CACX,OAAO;CACP,OAAO;CACP,WAAW;EAAE,UAAU;EAAI,WAAW;CAAG;CACzC,UAAU;CACV,MAAM;CACN,MAAM;EAAE,OAAO;EAAK,QAAQ;CAAI;CAChC,iBAAiB,CAAC;CAClB,QAAQ,M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,MAAM,EAAE;MAC3B;KACF;KAEA,MAAM,EAAE,OAAO,UAAU,IAAI,UAAU;KACvC,IAAI,MAAM,WAAW,KAAK,MAAM,UAAU,IAAI,SAAS,OAAO,OAAO;KACrE,MAAM,OAAO,IAAI,IAAI,MAAM,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE;KAC9D,IAAI,CAAC,QAAQ,CAAC;MAAC;MAAS;MAAU;KAAM,CAAC,CAAC,SAAS,KAAK,QAAQ,EAAE,GAAG,OAAO;KAC5E,MAAM,QAAQ,QAAQ,KAAK;IAC7B;IACA,cAAc;KACZ,IAAI,MAAM,KAAK,UAAU,UAAU,OAAO;KAC1C,MAAM,KAAK,QAAQ;IACrB;GACF;EACF;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","names":[],"sources":["../../src/whiteboard/state.ts"],"sourcesContent":["import { ref, shallowRef, type Ref, type ShallowRef } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport type { Point, Rect } from '../core/model'\nimport type { WhiteboardUpload } from './image'\nimport type { InkPoint } from './ink'\nimport type { WhiteboardShapeTool, WhiteboardTool } from './model'\n\n/** What the board's pieces share within one editor. */\nexport interface WhiteboardState {\n tool: Ref<WhiteboardTool>\n /** Keeps the tool after drawing, instead of going back to select. */\n locked: Ref<boolean>\n /** The hand is dragging the view. */\n panning: Ref<boolean>\n /** The node whose text is being typed. */\n editing: ShallowRef<string | null>\n /** The box being drawn, with the tool drawing it. */\n draft: ShallowRef<(Rect & { tool: WhiteboardShapeTool }) | null>\n /** The stroke being drawn with the pen, in canvas coordinates. */\n ink: ShallowRef<InkPoint[] | null>\n /** Strokes the eraser has touched, removed once it lets go. */\n erasing: ShallowRef<ReadonlySet<string>>\n /** Where the eraser is, while it is pressed. */\n eraser: ShallowRef<Point | null>\n /**\n * Where the turn and corner handles of the selected node are drawn: a\n * layer above every node, so a neighbour never covers them.\n */\n handles: ShallowRef<HTMLElement | null>\n /** Images being uploaded. */\n uploading: Ref<number>\n /** The kit's `upload` option. */\n upload?: WhiteboardUpload\n}\n\nconst states = new WeakMap<FlowEditorContext, WhiteboardState>()\n\n/** The board's state in an editor, made on first use. */\nexport function boardState(context: FlowEditorContext): WhiteboardState {\n let state = states.get(context)\n if (!state) {\n state = {\n tool: ref('select'),\n locked: ref(false),\n panning: ref(false),\n editing: shallowRef(null),\n draft: shallowRef(null),\n ink: shallowRef(null),\n erasing: shallowRef(new Set()),\n eraser: shallowRef(null),\n handles: shallowRef(null),\n uploading: ref(0),\n }\n states.set(context, state)\n }\n return state\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"state.js","names":[],"sources":["../../src/whiteboard/state.ts"],"sourcesContent":["import { ref, shallowRef, type Ref, type ShallowRef } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport type { Point, Rect } from '../core/model'\nimport type { WhiteboardUpload, WhiteboardUploadErrorHandler } from './image'\nimport type { InkPoint } from './ink'\nimport type { WhiteboardShapeTool, WhiteboardTool } from './model'\n\n/** What the board's pieces share within one editor. */\nexport interface WhiteboardState {\n tool: Ref<WhiteboardTool>\n /** Keeps the tool after drawing, instead of going back to select. */\n locked: Ref<boolean>\n /** The hand is dragging the view. */\n panning: Ref<boolean>\n /** The node whose text is being typed. */\n editing: ShallowRef<string | null>\n /** The box being drawn, with the tool drawing it. */\n draft: ShallowRef<(Rect & { tool: WhiteboardShapeTool }) | null>\n /** The stroke being drawn with the pen, in canvas coordinates. */\n ink: ShallowRef<InkPoint[] | null>\n /** Strokes the eraser has touched, removed once it lets go. */\n erasing: ShallowRef<ReadonlySet<string>>\n /** Where the eraser is, while it is pressed. */\n eraser: ShallowRef<Point | null>\n /**\n * Where the turn and corner handles of the selected node are drawn: a\n * layer above every node, so a neighbour never covers them.\n */\n handles: ShallowRef<HTMLElement | null>\n /** Images being uploaded. */\n uploading: Ref<number>\n /** The kit's `upload` option. */\n upload?: WhiteboardUpload\n /** The kit's `onUploadError` option. */\n onUploadError?: WhiteboardUploadErrorHandler\n}\n\nconst states = new WeakMap<FlowEditorContext, WhiteboardState>()\n\n/** The board's state in an editor, made on first use. */\nexport function boardState(context: FlowEditorContext): WhiteboardState {\n let state = states.get(context)\n if (!state) {\n state = {\n tool: ref('select'),\n locked: ref(false),\n panning: ref(false),\n editing: shallowRef(null),\n draft: shallowRef(null),\n ink: shallowRef(null),\n erasing: shallowRef(new Set()),\n eraser: shallowRef(null),\n handles: shallowRef(null),\n uploading: ref(0),\n }\n states.set(context, state)\n }\n return state\n}\n"],"mappings":";;AAqCA,IAAM,yBAAS,IAAI,QAA4C;;AAG/D,SAAgB,WAAW,SAA6C;CACtE,IAAI,QAAQ,OAAO,IAAI,OAAO;CAC9B,IAAI,CAAC,OAAO;EACV,QAAQ;GACN,MAAM,IAAI,QAAQ;GAClB,QAAQ,IAAI,KAAK;GACjB,SAAS,IAAI,KAAK;GAClB,SAAS,WAAW,IAAI;GACxB,OAAO,WAAW,IAAI;GACtB,KAAK,WAAW,IAAI;GACpB,SAAS,2BAAW,IAAI,IAAI,CAAC;GAC7B,QAAQ,WAAW,IAAI;GACvB,SAAS,WAAW,IAAI;GACxB,WAAW,IAAI,CAAC;EAClB;EACA,OAAO,IAAI,SAAS,KAAK;CAC3B;CACA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dou-ui/flow",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"description": "DouUI 的流程编辑器:在无限画布上拖动节点、连接端口",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"build": "vite build && vue-tsc -p tsconfig.build.json && bun scripts/build-style.ts"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"dou-ui": "0.1.0-alpha.
|
|
57
|
+
"dou-ui": "0.1.0-alpha.2",
|
|
58
58
|
"vue": "^3.5.0",
|
|
59
59
|
"yjs": "^13.6.0"
|
|
60
60
|
},
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@dou-ui/icons": "0.1.0-alpha.
|
|
67
|
+
"@dou-ui/icons": "0.1.0-alpha.2"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"y-protocols": "^1.0.7",
|