@dou-ui/flow 0.1.0-alpha.1 → 0.1.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/collaboration/index.js +76 -5
  2. package/dist/collaboration/index.js.map +1 -1
  3. package/dist/comments.js +245 -0
  4. package/dist/comments.js.map +1 -0
  5. package/dist/components/default-node2.js.map +1 -1
  6. package/dist/components/flow-comments.js +6 -0
  7. package/dist/components/flow-comments.js.map +1 -0
  8. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +205 -0
  9. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
  10. package/dist/components/port.js +7 -0
  11. package/dist/components/port.js.map +1 -0
  12. package/dist/context.js.map +1 -1
  13. package/dist/core/edge-types.js +107 -3
  14. package/dist/core/edge-types.js.map +1 -1
  15. package/dist/core/extension.js.map +1 -1
  16. package/dist/core/history.js +26 -0
  17. package/dist/core/history.js.map +1 -1
  18. package/dist/core/model.js.map +1 -1
  19. package/dist/core/node-types.js +35 -1
  20. package/dist/core/node-types.js.map +1 -1
  21. package/dist/core/transaction.js +112 -15
  22. package/dist/core/transaction.js.map +1 -1
  23. package/dist/document.js +1 -1
  24. package/dist/export/render.js +78 -0
  25. package/dist/export/render.js.map +1 -0
  26. package/dist/flow-editor.js.map +1 -1
  27. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +454 -36
  28. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  29. package/dist/index.js +6 -6
  30. package/dist/index.js.map +1 -1
  31. package/dist/kit.js +1 -1
  32. package/dist/locale.js +24 -9
  33. package/dist/locale.js.map +1 -1
  34. package/dist/style.css +1 -1
  35. package/dist/style.js +2 -1
  36. package/dist/types/collaboration/index.d.ts +32 -4
  37. package/dist/types/comments.d.ts +73 -0
  38. package/dist/types/components/default-node.d.ts +1 -1
  39. package/dist/types/components/flow-comments.vue.d.ts +35 -0
  40. package/dist/types/components/port.d.ts +7 -0
  41. package/dist/types/context.d.ts +54 -1
  42. package/dist/types/core/extension.d.ts +2 -1
  43. package/dist/types/core/history.d.ts +10 -0
  44. package/dist/types/core/menu.d.ts +5 -0
  45. package/dist/types/core/model.d.ts +19 -0
  46. package/dist/types/core/node-types.d.ts +16 -2
  47. package/dist/types/core/transaction.d.ts +23 -1
  48. package/dist/types/export/render.d.ts +27 -0
  49. package/dist/types/flow-editor.vue.d.ts +11 -0
  50. package/dist/types/index.d.ts +36 -9
  51. package/dist/types/locale.d.ts +13 -3
  52. package/dist/types/whiteboard/image.d.ts +8 -0
  53. package/dist/types/whiteboard/index.d.ts +1 -1
  54. package/dist/types/whiteboard/kit.d.ts +7 -1
  55. package/dist/types/whiteboard/model.d.ts +2 -11
  56. package/dist/types/whiteboard/state.d.ts +5 -1
  57. package/dist/whiteboard/board-node.js.map +1 -1
  58. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +3 -3
  59. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  60. package/dist/whiteboard/connector.js +5 -10
  61. package/dist/whiteboard/connector.js.map +1 -1
  62. package/dist/whiteboard/image.js +17 -6
  63. package/dist/whiteboard/image.js.map +1 -1
  64. package/dist/whiteboard/kit.js +64 -8
  65. package/dist/whiteboard/kit.js.map +1 -1
  66. package/dist/whiteboard/model.js +4 -31
  67. package/dist/whiteboard/model.js.map +1 -1
  68. package/dist/whiteboard/state.js +6 -1
  69. package/dist/whiteboard/state.js.map +1 -1
  70. package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
  71. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
  72. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  73. package/package.json +3 -3
@@ -1 +1 @@
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 { 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,MAAM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C,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, type FlowPressHandler } from '../core/extension'\nimport { turn } from '../core/geometry'\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 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, usable } 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: 'sides',\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: 'sides',\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: 'sides',\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: 'sides',\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/**\n * The comment tool: a click on a node starts a thread pinned where it was\n * clicked, the point turned back with the node. A press on the empty canvas\n * does nothing; a mouse drag does nothing either, so a thread isn't started\n * by mistake, while a finger's drag moves the view, as it does elsewhere.\n */\nfunction pinComment(\n ctx: FlowEditorContext,\n node: string | null,\n start: Point,\n event: PointerEvent,\n): FlowPressHandler {\n const client = { x: event.clientX, y: event.clientY }\n const origin = { ...ctx.viewport.value }\n const finger = event.pointerType !== 'mouse'\n let moved = false\n return {\n move(_, move) {\n const dx = move.clientX - client.x\n const dy = move.clientY - client.y\n if (!moved && Math.hypot(dx, dy) <= 8) return\n moved = true\n if (finger) ctx.setViewport({ ...origin, x: origin.x + dx, y: origin.y + dy })\n },\n end() {\n const rect = node && !moved ? ctx.getNodeRect(node) : null\n if (!node || !rect || !rect.width || !rect.height) return\n const centre = { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 }\n const local = turn(start, centre, -ctx.nodeRotation(node))\n const at = { x: (local.x - rect.x) / rect.width, y: (local.y - rect.y) / rect.height }\n // a tap: the card opens without the focus, so a phone's keyboard doesn't come up\n ctx.comment({ node, at }, { focus: !finger })\n },\n }\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 comment tool goes once threads can't be started, every drawing tool once read-only\n stops.push(\n watch(\n () => usable(ctx, state.tool.value),\n (ok) => !ok && (state.tool.value = 'select'),\n { immediate: true },\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 // while read-only, only moving the view and commenting\n if (ctx.readonly.value && tool !== 'hand' && tool !== 'comment') return\n if (tool === 'comment')\n return pinComment(ctx, press.node?.id ?? null, press.point, press.event)\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 if (!usable(ctx, tool)) return false\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 const tool = state.tool.value\n // with the comment tool, Enter starts a thread on the selected node, about all of it\n if (tool === 'comment') {\n const { nodes, edges } = ctx.selection.value\n if (nodes.length !== 1 || edges.length) return false\n return ctx.comment({ node: nodes[0]! }) || false\n }\n if (ctx.readonly.value) return false\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,MAAM,MAAM,OAAO,EAAE,MAAM,QAAQ,KAAK,MAAM,MAAM,CAAC;AAC/D,CAAC;;AAGD,IAAa,WAAW,eAAmC;CACzD,MAAM;CACN,WAAWA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;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"}
@@ -9,44 +9,17 @@ var whiteboardKeys = {
9
9
  sticky: "s",
10
10
  text: "t",
11
11
  pen: "p",
12
- eraser: "x"
12
+ eraser: "x",
13
+ comment: "m"
13
14
  };
14
15
  /** The key that inserts an image. */
15
16
  var imageKey = "i";
16
- var SIDES = [
17
+ var anchorSides = [
17
18
  "top",
18
19
  "right",
19
20
  "bottom",
20
21
  "left"
21
22
  ];
22
- /**
23
- * Four anchors, one on each side. Each is an output and an input at the
24
- * same spot, so a connector can start and end on any of them. Edges in
25
- * data go from an output (`right`) to an input (`left-in`). The order puts
26
- * `right` and `left-in` first, so a node added after another joins it left
27
- * to right.
28
- */
29
- var anchorPorts = [...[
30
- "right",
31
- "bottom",
32
- "left",
33
- "top"
34
- ].map((side) => ({
35
- id: side,
36
- kind: "output",
37
- side
38
- })), ...[
39
- "left",
40
- "top",
41
- "right",
42
- "bottom"
43
- ].map((side) => ({
44
- id: `${side}-in`,
45
- kind: "input",
46
- side,
47
- max: Number.POSITIVE_INFINITY
48
- }))];
49
- var anchorSides = SIDES;
50
- export { anchorPorts, anchorSides, imageKey, whiteboardKeys };
23
+ export { anchorSides, imageKey, whiteboardKeys };
51
24
 
52
25
  //# sourceMappingURL=model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","names":[],"sources":["../../src/whiteboard/model.ts"],"sourcesContent":["import type { Tone } from 'dou-ui'\nimport type { FlowPortSpec } from '../core/model'\n\n/** What a press on the board does. */\nexport type WhiteboardTool =\n 'select' | 'hand' | 'rect' | 'ellipse' | 'diamond' | 'sticky' | 'text' | 'pen' | 'eraser'\n\n/** The tools that put down a node with a box. */\nexport type WhiteboardShapeTool = Exclude<WhiteboardTool, 'select' | 'hand' | 'pen' | 'eraser'>\n\nexport type WhiteboardShape = 'rect' | 'ellipse' | 'diamond'\n\n/** What every board node can carry. */\nexport interface WhiteboardNodeData {\n [key: string]: unknown\n /** Degrees clockwise around the node's centre. */\n rotation?: number\n}\n\nexport interface WhiteboardShapeData extends WhiteboardNodeData {\n shape: WhiteboardShape\n text?: string\n /** `neutral` by default. */\n tone?: Tone\n}\n\nexport interface WhiteboardStickyData extends WhiteboardNodeData {\n text?: string\n /** `warning` (yellow) by default. */\n tone?: Tone\n}\n\nexport interface WhiteboardTextData extends WhiteboardNodeData {\n text?: string\n}\n\n/** A pen stroke. */\nexport interface WhiteboardInkData extends WhiteboardNodeData {\n /**\n * The points as `x, y, pressure` triples, flat, in the node's own units:\n * `0, 0` is its top left corner when it is `box` in size.\n */\n points: number[]\n /** The size the points were drawn at; the stroke stretches with the node. */\n box: [number, number]\n /**\n * The stroke's width drawn with a mouse or finger. `4` by default; a pen\n * makes it 0.4 to 1.6 times as wide as it presses lighter or harder.\n */\n size?: number\n /** The text color when left out. */\n tone?: Tone\n}\n\n/** How a connector runs: one straight line, right-angled turns, or a smooth curve. */\nexport type WhiteboardRoute = 'straight' | 'elbow' | 'curve'\nexport type WhiteboardDash = 'solid' | 'dashed' | 'dotted' | 'dash-dot'\n/** Which ends of a connector have an arrowhead. */\nexport type WhiteboardArrow = 'none' | 'end' | 'both'\n\n/** A `connector` edge's look. */\nexport interface WhiteboardConnectorData {\n [key: string]: unknown\n /** `straight` by default. */\n route?: WhiteboardRoute\n /** `solid` by default. */\n dash?: WhiteboardDash\n /** `end` by default. */\n arrow?: WhiteboardArrow\n /** Where an `elbow` connector's middle run sits, from 0 to 1; set by dragging it. */\n bend?: number\n}\n\nexport interface WhiteboardImageData extends WhiteboardNodeData {\n src: string\n /** Read by screen readers. */\n alt?: string\n}\n\n/** Keys for the tools. */\nexport const whiteboardKeys: Record<WhiteboardTool, string> = {\n select: 'v',\n hand: 'h',\n rect: 'r',\n ellipse: 'o',\n diamond: 'd',\n sticky: 's',\n text: 't',\n pen: 'p',\n eraser: 'x',\n}\n\n/** The key that inserts an image. */\nexport const imageKey = 'i'\n\nconst SIDES = ['top', 'right', 'bottom', 'left'] as const\n\n/**\n * Four anchors, one on each side. Each is an output and an input at the\n * same spot, so a connector can start and end on any of them. Edges in\n * data go from an output (`right`) to an input (`left-in`). The order puts\n * `right` and `left-in` first, so a node added after another joins it left\n * to right.\n */\nexport const anchorPorts: FlowPortSpec[] = [\n ...(['right', 'bottom', 'left', 'top'] as const).map((side) => ({\n id: side,\n kind: 'output' as const,\n side,\n })),\n ...(['left', 'top', 'right', 'bottom'] as const).map((side) => ({\n id: `${side}-in`,\n kind: 'input' as const,\n side,\n max: Number.POSITIVE_INFINITY,\n })),\n]\n\nexport const anchorSides = SIDES\n"],"mappings":";;AAgFA,IAAa,iBAAiD;CAC5D,QAAQ;CACR,MAAM;CACN,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,MAAM;CACN,KAAK;CACL,QAAQ;AACV;;AAGA,IAAa,WAAW;AAExB,IAAM,QAAQ;CAAC;CAAO;CAAS;CAAU;AAAM;;;;;;;;AAS/C,IAAa,cAA8B,CACzC,GAAI;CAAC;CAAS;CAAU;CAAQ;AAAK,CAAC,CAAW,KAAK,UAAU;CAC9D,IAAI;CACJ,MAAM;CACN;AACF,EAAE,GACF,GAAI;CAAC;CAAQ;CAAO;CAAS;AAAQ,CAAC,CAAW,KAAK,UAAU;CAC9D,IAAI,GAAG,KAAK;CACZ,MAAM;CACN;CACA,KAAK,OAAO;AACd,EAAE,CACJ;AAEA,IAAa,cAAc"}
1
+ {"version":3,"file":"model.js","names":[],"sources":["../../src/whiteboard/model.ts"],"sourcesContent":["import type { Tone } from 'dou-ui'\n\n/** What a press on the board does. */\nexport type WhiteboardTool =\n | 'select'\n | 'hand'\n | 'rect'\n | 'ellipse'\n | 'diamond'\n | 'sticky'\n | 'text'\n | 'pen'\n | 'eraser'\n | 'comment'\n\n/** The tools that put down a node with a box. */\nexport type WhiteboardShapeTool = Exclude<\n WhiteboardTool,\n 'select' | 'hand' | 'pen' | 'eraser' | 'comment'\n>\n\nexport type WhiteboardShape = 'rect' | 'ellipse' | 'diamond'\n\n/** What every board node can carry. */\nexport interface WhiteboardNodeData {\n [key: string]: unknown\n /** Degrees clockwise around the node's centre. */\n rotation?: number\n}\n\nexport interface WhiteboardShapeData extends WhiteboardNodeData {\n shape: WhiteboardShape\n text?: string\n /** `neutral` by default. */\n tone?: Tone\n}\n\nexport interface WhiteboardStickyData extends WhiteboardNodeData {\n text?: string\n /** `warning` (yellow) by default. */\n tone?: Tone\n}\n\nexport interface WhiteboardTextData extends WhiteboardNodeData {\n text?: string\n}\n\n/** A pen stroke. */\nexport interface WhiteboardInkData extends WhiteboardNodeData {\n /**\n * The points as `x, y, pressure` triples, flat, in the node's own units:\n * `0, 0` is its top left corner when it is `box` in size.\n */\n points: number[]\n /** The size the points were drawn at; the stroke stretches with the node. */\n box: [number, number]\n /**\n * The stroke's width drawn with a mouse or finger. `4` by default; a pen\n * makes it 0.4 to 1.6 times as wide as it presses lighter or harder.\n */\n size?: number\n /** The text color when left out. */\n tone?: Tone\n}\n\n/** How a connector runs: one straight line, right-angled turns, or a smooth curve. */\nexport type WhiteboardRoute = 'straight' | 'elbow' | 'curve'\nexport type WhiteboardDash = 'solid' | 'dashed' | 'dotted' | 'dash-dot'\n/** Which ends of a connector have an arrowhead. */\nexport type WhiteboardArrow = 'none' | 'end' | 'both'\n\n/** A `connector` edge's look. */\nexport interface WhiteboardConnectorData {\n [key: string]: unknown\n /** `straight` by default. */\n route?: WhiteboardRoute\n /** `solid` by default. */\n dash?: WhiteboardDash\n /** `end` by default. */\n arrow?: WhiteboardArrow\n /** Where an `elbow` connector's middle run sits, from 0 to 1; set by dragging it. */\n bend?: number\n}\n\nexport interface WhiteboardImageData extends WhiteboardNodeData {\n src: string\n /** Read by screen readers. */\n alt?: string\n}\n\n/** Keys for the tools. */\nexport const whiteboardKeys: Record<WhiteboardTool, string> = {\n select: 'v',\n hand: 'h',\n rect: 'r',\n ellipse: 'o',\n diamond: 'd',\n sticky: 's',\n text: 't',\n pen: 'p',\n eraser: 'x',\n comment: 'm',\n}\n\n/** The key that inserts an image. */\nexport const imageKey = 'i'\n\nconst SIDES = ['top', 'right', 'bottom', 'left'] as const\n\nexport const anchorSides = SIDES\n"],"mappings":";;AA2FA,IAAa,iBAAiD;CAC5D,QAAQ;CACR,MAAM;CACN,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,MAAM;CACN,KAAK;CACL,QAAQ;CACR,SAAS;AACX;;AAGA,IAAa,WAAW;AAIxB,IAAa,cAAc;CAFZ;CAAO;CAAS;CAAU;AAEd"}
@@ -21,6 +21,11 @@ function boardState(context) {
21
21
  }
22
22
  return state;
23
23
  }
24
- export { boardState };
24
+ /** Whether a tool can be used now: while read-only only select, hand and comment; comment while threads can be started. */
25
+ function usable(ctx, tool) {
26
+ if (tool === "comment") return ctx.canComment.value;
27
+ return !ctx.readonly.value || tool === "select" || tool === "hand";
28
+ }
29
+ export { boardState, usable };
25
30
 
26
31
  //# sourceMappingURL=state.js.map
@@ -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":";;AAmCA,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"}
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\n/** Whether a tool can be used now: while read-only only select, hand and comment; comment while threads can be started. */\nexport function usable(ctx: FlowEditorContext, tool: WhiteboardTool) {\n if (tool === 'comment') return ctx.canComment.value\n return !ctx.readonly.value || tool === 'select' || tool === 'hand'\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;;AAGA,SAAgB,OAAO,KAAwB,MAAsB;CACnE,IAAI,SAAS,WAAW,OAAO,IAAI,WAAW;CAC9C,OAAO,CAAC,IAAI,SAAS,SAAS,SAAS,YAAY,SAAS;AAC9D"}
@@ -1 +1 @@
1
- {"version":3,"file":"whiteboard-toolbar.js","names":["_sfc_main"],"sources":["../../src/whiteboard/whiteboard-toolbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n CircleIcon,\n CursorIcon,\n DiamondIcon,\n EraserIcon,\n HandGrabIcon,\n HandIcon,\n ImageIcon,\n PencilIcon,\n SquareIcon,\n StickyNoteIcon,\n TypeIcon,\n} from '@dou-ui/icons'\nimport { DouTooltip, scrollPositionOf } from 'dou-ui'\nimport { computed, onBeforeUnmount, ref, useTemplateRef, watch, type Component } from 'vue'\nimport { useFlowEditor } from '../context'\nimport { pickImages } from './image'\nimport { imageKey, whiteboardKeys, type WhiteboardTool } from './model'\nimport { boardState } from './state'\n\ndefineOptions({ name: 'DouWhiteboardToolbar' })\n\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\nconst t = computed(() => ctx.messages.value.board)\n\nconst groups: { tool: WhiteboardTool; icon: Component }[][] = [\n [\n { tool: 'select', icon: CursorIcon },\n { tool: 'hand', icon: HandIcon },\n ],\n [\n { tool: 'rect', icon: SquareIcon },\n { tool: 'ellipse', icon: CircleIcon },\n { tool: 'diamond', icon: DiamondIcon },\n ],\n [\n { tool: 'sticky', icon: StickyNoteIcon },\n { tool: 'text', icon: TypeIcon },\n ],\n [\n { tool: 'pen', icon: PencilIcon },\n { tool: 'eraser', icon: EraserIcon },\n ],\n]\n\n/** Tools that go back to select after one use, unless kept with a double click. */\nconst once = new Set<WhiteboardTool>(['rect', 'ellipse', 'diamond', 'sticky', 'text'])\n\n// A click picks the tool for one use; a double click keeps it. Focus goes\n// back to the canvas, where the tool is used and its keys work.\nfunction pick(tool: WhiteboardTool, keep: boolean) {\n state.tool.value = tool\n state.locked.value = keep && once.has(tool)\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction insertImage() {\n pickImages(ctx)\n}\n\n// Too narrow for every tool: one row that scrolls sideways, faded at the\n// side with more, and the tool in hand kept in view.\nconst el = useTemplateRef<HTMLElement>('el')\nconst more = ref({ start: false, end: false })\n/** Right to left; read when the row is laid out, not on every scroll. */\nlet rtl = false\nfunction measure() {\n const box = el.value\n if (!box) return\n // from the start, also right to left, and kept in range while the row bounces\n const left = Math.abs(scrollPositionOf(box, rtl).left)\n const rest = box.scrollWidth - box.clientWidth - left\n more.value = { start: left > 1, end: rest > 1 }\n}\nlet observer: ResizeObserver | undefined\nwatch(\n el,\n (box) => {\n observer?.disconnect()\n if (!box || typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(() => {\n rtl = getComputedStyle(box).direction === 'rtl'\n measure()\n })\n observer.observe(box)\n },\n { flush: 'post' },\n)\nonBeforeUnmount(() => observer?.disconnect())\nwatch(\n () => state.tool.value,\n () => {\n const box = el.value\n const button = box?.querySelector<HTMLElement>('[aria-pressed=\"true\"]')\n if (!box || !button || box.scrollWidth <= box.clientWidth) return\n const start = button.offsetLeft - 24\n const end = button.offsetLeft + button.offsetWidth + 24 - box.clientWidth\n if (box.scrollLeft > start) box.scrollLeft = start\n else if (box.scrollLeft < end) box.scrollLeft = end\n },\n { flush: 'post' },\n)\n</script>\n\n<template>\n <div\n v-if=\"!ctx.readonly.value\"\n class=\"dou-whiteboard-toolbar\"\n data-flow-overlay\n role=\"toolbar\"\n :aria-label=\"t.tools\"\n >\n <div\n ref=\"el\"\n class=\"dou-whiteboard-toolbar__scroll\"\n :class=\"{ 'has-more-start': more.start, 'has-more-end': more.end }\"\n @scroll.passive=\"measure\"\n >\n <template v-for=\"(group, i) in groups\" :key=\"i\">\n <span v-if=\"i\" class=\"dou-whiteboard-toolbar__divider\" />\n <DouTooltip\n v-for=\"item in group\"\n :key=\"item.tool\"\n :content=\"t[item.tool]\"\n :shortcut=\"whiteboardKeys[item.tool]\"\n placement=\"bottom\"\n >\n <button\n type=\"button\"\n class=\"dou-whiteboard-toolbar__button\"\n :class=\"{ 'is-locked': state.tool.value === item.tool && state.locked.value }\"\n :aria-pressed=\"state.tool.value === item.tool\"\n :aria-label=\"t[item.tool]\"\n @click=\"pick(item.tool, false)\"\n @dblclick=\"pick(item.tool, true)\"\n >\n <component\n :is=\"item.tool === 'hand' && state.panning.value ? HandGrabIcon : item.icon\"\n />\n </button>\n </DouTooltip>\n </template>\n <DouTooltip :content=\"t.image\" :shortcut=\"imageKey\" placement=\"bottom\">\n <button\n type=\"button\"\n class=\"dou-whiteboard-toolbar__button\"\n :class=\"{ 'is-busy': state.uploading.value > 0 }\"\n :aria-label=\"t.image\"\n :aria-busy=\"state.uploading.value > 0 || undefined\"\n @click=\"insertImage\"\n >\n <ImageIcon />\n </button>\n </DouTooltip>\n </div>\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"whiteboard-toolbar.js","names":["_sfc_main"],"sources":["../../src/whiteboard/whiteboard-toolbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n CircleIcon,\n CursorIcon,\n DiamondIcon,\n EraserIcon,\n HandGrabIcon,\n HandIcon,\n ImageIcon,\n MessagePlusIcon,\n PencilIcon,\n SquareIcon,\n StickyNoteIcon,\n TypeIcon,\n} from '@dou-ui/icons'\nimport { DouTooltip, scrollPositionOf } from 'dou-ui'\nimport { computed, onBeforeUnmount, ref, useTemplateRef, watch, type Component } from 'vue'\nimport { useFlowEditor } from '../context'\nimport { pickImages } from './image'\nimport { imageKey, whiteboardKeys, type WhiteboardTool } from './model'\nimport { boardState, usable } from './state'\n\ndefineOptions({ name: 'DouWhiteboardToolbar' })\n\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\nconst t = computed(() => ctx.messages.value.board)\n\nconst all: { tool: WhiteboardTool; icon: Component }[][] = [\n [\n { tool: 'select', icon: CursorIcon },\n { tool: 'hand', icon: HandIcon },\n ],\n [\n { tool: 'rect', icon: SquareIcon },\n { tool: 'ellipse', icon: CircleIcon },\n { tool: 'diamond', icon: DiamondIcon },\n ],\n [\n { tool: 'sticky', icon: StickyNoteIcon },\n { tool: 'text', icon: TypeIcon },\n ],\n [\n { tool: 'pen', icon: PencilIcon },\n { tool: 'eraser', icon: EraserIcon },\n ],\n [{ tool: 'comment', icon: MessagePlusIcon }],\n]\n\n/** The tools that can be used now: while read-only, select, hand and comment; comment while threads can be started. */\nconst groups = computed(() =>\n all\n .map((group) => group.filter((item) => usable(ctx, item.tool)))\n .filter((group) => group.length),\n)\n\n/** Tools that go back to select after one use, unless kept with a double click. */\nconst once = new Set<WhiteboardTool>(['rect', 'ellipse', 'diamond', 'sticky', 'text'])\n\n// A click picks the tool for one use; a double click keeps it. Focus goes\n// back to the canvas, where the tool is used and its keys work.\nfunction pick(tool: WhiteboardTool, keep: boolean) {\n state.tool.value = tool\n state.locked.value = keep && once.has(tool)\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction insertImage() {\n pickImages(ctx)\n}\n\n// Too narrow for every tool: one row that scrolls sideways, faded at the\n// side with more, and the tool in hand kept in view.\nconst el = useTemplateRef<HTMLElement>('el')\nconst more = ref({ start: false, end: false })\n/** Right to left; read when the row is laid out, not on every scroll. */\nlet rtl = false\nfunction measure() {\n const box = el.value\n if (!box) return\n // from the start, also right to left, and kept in range while the row bounces\n const left = Math.abs(scrollPositionOf(box, rtl).left)\n const rest = box.scrollWidth - box.clientWidth - left\n more.value = { start: left > 1, end: rest > 1 }\n}\nlet observer: ResizeObserver | undefined\nwatch(\n el,\n (box) => {\n observer?.disconnect()\n if (!box || typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(() => {\n rtl = getComputedStyle(box).direction === 'rtl'\n measure()\n })\n observer.observe(box)\n },\n { flush: 'post' },\n)\nonBeforeUnmount(() => observer?.disconnect())\nwatch(\n () => state.tool.value,\n () => {\n const box = el.value\n const button = box?.querySelector<HTMLElement>('[aria-pressed=\"true\"]')\n if (!box || !button || box.scrollWidth <= box.clientWidth) return\n const start = button.offsetLeft - 24\n const end = button.offsetLeft + button.offsetWidth + 24 - box.clientWidth\n if (box.scrollLeft > start) box.scrollLeft = start\n else if (box.scrollLeft < end) box.scrollLeft = end\n },\n { flush: 'post' },\n)\n</script>\n\n<template>\n <div\n v-if=\"!ctx.readonly.value || ctx.canComment.value\"\n class=\"dou-whiteboard-toolbar\"\n data-flow-overlay\n role=\"toolbar\"\n :aria-label=\"t.tools\"\n >\n <div\n ref=\"el\"\n class=\"dou-whiteboard-toolbar__scroll\"\n :class=\"{ 'has-more-start': more.start, 'has-more-end': more.end }\"\n @scroll.passive=\"measure\"\n >\n <template v-for=\"(group, i) in groups\" :key=\"i\">\n <span v-if=\"i\" class=\"dou-whiteboard-toolbar__divider\" />\n <DouTooltip\n v-for=\"item in group\"\n :key=\"item.tool\"\n :content=\"t[item.tool]\"\n :shortcut=\"whiteboardKeys[item.tool]\"\n placement=\"bottom\"\n >\n <button\n type=\"button\"\n class=\"dou-whiteboard-toolbar__button\"\n :class=\"{ 'is-locked': state.tool.value === item.tool && state.locked.value }\"\n :aria-pressed=\"state.tool.value === item.tool\"\n :aria-label=\"t[item.tool]\"\n @click=\"pick(item.tool, false)\"\n @dblclick=\"pick(item.tool, true)\"\n >\n <component\n :is=\"item.tool === 'hand' && state.panning.value ? HandGrabIcon : item.icon\"\n />\n </button>\n </DouTooltip>\n </template>\n <DouTooltip\n v-if=\"!ctx.readonly.value\"\n :content=\"t.image\"\n :shortcut=\"imageKey\"\n placement=\"bottom\"\n >\n <button\n type=\"button\"\n class=\"dou-whiteboard-toolbar__button\"\n :class=\"{ 'is-busy': state.uploading.value > 0 }\"\n :aria-label=\"t.image\"\n :aria-busy=\"state.uploading.value > 0 || undefined\"\n @click=\"insertImage\"\n >\n <ImageIcon />\n </button>\n </DouTooltip>\n </div>\n </div>\n</template>\n"],"mappings":""}
@@ -1,10 +1,10 @@
1
1
  import { useFlowEditor } from "../context.js";
2
2
  import { whiteboardKeys } from "./model.js";
3
- import { boardState } from "./state.js";
3
+ import { boardState, usable } from "./state.js";
4
4
  import { pickImages } from "./image.js";
5
5
  import { DouTooltip, scrollPositionOf } from "dou-ui";
6
6
  import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, onBeforeUnmount, openBlock, ref, renderList, resolveDynamicComponent, unref, useTemplateRef, watch, withCtx } from "vue";
7
- import { CircleIcon, CursorIcon, DiamondIcon, EraserIcon, HandGrabIcon, HandIcon, ImageIcon, PencilIcon, SquareIcon, StickyNoteIcon, TypeIcon } from "@dou-ui/icons";
7
+ import { CircleIcon, CursorIcon, DiamondIcon, EraserIcon, HandGrabIcon, HandIcon, ImageIcon, MessagePlusIcon, PencilIcon, SquareIcon, StickyNoteIcon, TypeIcon } from "@dou-ui/icons";
8
8
  // src/whiteboard/whiteboard-toolbar.vue?vue&type=script&setup=true&lang.ts
9
9
  var _hoisted_1 = ["aria-label"];
10
10
  var _hoisted_2 = {
@@ -25,7 +25,7 @@ var whiteboard_toolbar_vue_vue_type_script_setup_true_lang_default = /*@__PURE__
25
25
  const ctx = useFlowEditor();
26
26
  const state = boardState(ctx);
27
27
  const t = computed(() => ctx.messages.value.board);
28
- const groups = [
28
+ const all = [
29
29
  [{
30
30
  tool: "select",
31
31
  icon: CursorIcon
@@ -60,8 +60,14 @@ var whiteboard_toolbar_vue_vue_type_script_setup_true_lang_default = /*@__PURE__
60
60
  }, {
61
61
  tool: "eraser",
62
62
  icon: EraserIcon
63
+ }],
64
+ [{
65
+ tool: "comment",
66
+ icon: MessagePlusIcon
63
67
  }]
64
68
  ];
69
+ /** The tools that can be used now: while read-only, select, hand and comment; comment while threads can be started. */
70
+ const groups = computed(() => all.map((group) => group.filter((item) => usable(ctx, item.tool))).filter((group) => group.length));
65
71
  /** Tools that go back to select after one use, unless kept with a double click. */
66
72
  const once = /* @__PURE__ */ new Set([
67
73
  "rect",
@@ -116,7 +122,7 @@ var whiteboard_toolbar_vue_vue_type_script_setup_true_lang_default = /*@__PURE__
116
122
  else if (box.scrollLeft < end) box.scrollLeft = end;
117
123
  }, { flush: "post" });
118
124
  return (_ctx, _cache) => {
119
- return !unref(ctx).readonly.value ? (openBlock(), createElementBlock("div", {
125
+ return !unref(ctx).readonly.value || unref(ctx).canComment.value ? (openBlock(), createElementBlock("div", {
120
126
  key: 0,
121
127
  class: "dou-whiteboard-toolbar",
122
128
  "data-flow-overlay": "",
@@ -130,7 +136,7 @@ var whiteboard_toolbar_vue_vue_type_script_setup_true_lang_default = /*@__PURE__
130
136
  "has-more-end": more.value.end
131
137
  }]),
132
138
  onScrollPassive: measure
133
- }, [(openBlock(), createElementBlock(Fragment, null, renderList(groups, (group, i) => {
139
+ }, [(openBlock(true), createElementBlock(Fragment, null, renderList(groups.value, (group, i) => {
134
140
  return openBlock(), createElementBlock(Fragment, { key: i }, [i ? (openBlock(), createElementBlock("span", _hoisted_2)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(group, (item) => {
135
141
  return openBlock(), createBlock(unref(DouTooltip), {
136
142
  key: item.tool,
@@ -149,7 +155,8 @@ var whiteboard_toolbar_vue_vue_type_script_setup_true_lang_default = /*@__PURE__
149
155
  _: 2
150
156
  }, 1032, ["content", "shortcut"]);
151
157
  }), 128))], 64);
152
- }), 64)), createVNode(unref(DouTooltip), {
158
+ }), 128)), !unref(ctx).readonly.value ? (openBlock(), createBlock(unref(DouTooltip), {
159
+ key: 0,
153
160
  content: t.value.image,
154
161
  shortcut: unref("i"),
155
162
  placement: "bottom"
@@ -162,7 +169,7 @@ var whiteboard_toolbar_vue_vue_type_script_setup_true_lang_default = /*@__PURE__
162
169
  onClick: insertImage
163
170
  }, [createVNode(unref(ImageIcon))], 10, _hoisted_4)]),
164
171
  _: 1
165
- }, 8, ["content", "shortcut"])], 34)], 8, _hoisted_1)) : createCommentVNode("", true);
172
+ }, 8, ["content", "shortcut"])) : createCommentVNode("", true)], 34)], 8, _hoisted_1)) : createCommentVNode("", true);
166
173
  };
167
174
  }
168
175
  });
@@ -1 +1 @@
1
- {"version":3,"file":"whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js","names":["_unref","_openBlock","_createElementBlock","_createElementVNode","_normalizeClass","_Fragment","_renderList","_createCommentVNode","_createBlock","_withCtx","_resolveDynamicComponent","_createVNode"],"sources":["../../src/whiteboard/whiteboard-toolbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n CircleIcon,\n CursorIcon,\n DiamondIcon,\n EraserIcon,\n HandGrabIcon,\n HandIcon,\n ImageIcon,\n PencilIcon,\n SquareIcon,\n StickyNoteIcon,\n TypeIcon,\n} from '@dou-ui/icons'\nimport { DouTooltip, scrollPositionOf } from 'dou-ui'\nimport { computed, onBeforeUnmount, ref, useTemplateRef, watch, type Component } from 'vue'\nimport { useFlowEditor } from '../context'\nimport { pickImages } from './image'\nimport { imageKey, whiteboardKeys, type WhiteboardTool } from './model'\nimport { boardState } from './state'\n\ndefineOptions({ name: 'DouWhiteboardToolbar' })\n\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\nconst t = computed(() => ctx.messages.value.board)\n\nconst groups: { tool: WhiteboardTool; icon: Component }[][] = [\n [\n { tool: 'select', icon: CursorIcon },\n { tool: 'hand', icon: HandIcon },\n ],\n [\n { tool: 'rect', icon: SquareIcon },\n { tool: 'ellipse', icon: CircleIcon },\n { tool: 'diamond', icon: DiamondIcon },\n ],\n [\n { tool: 'sticky', icon: StickyNoteIcon },\n { tool: 'text', icon: TypeIcon },\n ],\n [\n { tool: 'pen', icon: PencilIcon },\n { tool: 'eraser', icon: EraserIcon },\n ],\n]\n\n/** Tools that go back to select after one use, unless kept with a double click. */\nconst once = new Set<WhiteboardTool>(['rect', 'ellipse', 'diamond', 'sticky', 'text'])\n\n// A click picks the tool for one use; a double click keeps it. Focus goes\n// back to the canvas, where the tool is used and its keys work.\nfunction pick(tool: WhiteboardTool, keep: boolean) {\n state.tool.value = tool\n state.locked.value = keep && once.has(tool)\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction insertImage() {\n pickImages(ctx)\n}\n\n// Too narrow for every tool: one row that scrolls sideways, faded at the\n// side with more, and the tool in hand kept in view.\nconst el = useTemplateRef<HTMLElement>('el')\nconst more = ref({ start: false, end: false })\n/** Right to left; read when the row is laid out, not on every scroll. */\nlet rtl = false\nfunction measure() {\n const box = el.value\n if (!box) return\n // from the start, also right to left, and kept in range while the row bounces\n const left = Math.abs(scrollPositionOf(box, rtl).left)\n const rest = box.scrollWidth - box.clientWidth - left\n more.value = { start: left > 1, end: rest > 1 }\n}\nlet observer: ResizeObserver | undefined\nwatch(\n el,\n (box) => {\n observer?.disconnect()\n if (!box || typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(() => {\n rtl = getComputedStyle(box).direction === 'rtl'\n measure()\n })\n observer.observe(box)\n },\n { flush: 'post' },\n)\nonBeforeUnmount(() => observer?.disconnect())\nwatch(\n () => state.tool.value,\n () => {\n const box = el.value\n const button = box?.querySelector<HTMLElement>('[aria-pressed=\"true\"]')\n if (!box || !button || box.scrollWidth <= box.clientWidth) return\n const start = button.offsetLeft - 24\n const end = button.offsetLeft + button.offsetWidth + 24 - box.clientWidth\n if (box.scrollLeft > start) box.scrollLeft = start\n else if (box.scrollLeft < end) box.scrollLeft = end\n },\n { flush: 'post' },\n)\n</script>\n\n<template>\n <div\n v-if=\"!ctx.readonly.value\"\n class=\"dou-whiteboard-toolbar\"\n data-flow-overlay\n role=\"toolbar\"\n :aria-label=\"t.tools\"\n >\n <div\n ref=\"el\"\n class=\"dou-whiteboard-toolbar__scroll\"\n :class=\"{ 'has-more-start': more.start, 'has-more-end': more.end }\"\n @scroll.passive=\"measure\"\n >\n <template v-for=\"(group, i) in groups\" :key=\"i\">\n <span v-if=\"i\" class=\"dou-whiteboard-toolbar__divider\" />\n <DouTooltip\n v-for=\"item in group\"\n :key=\"item.tool\"\n :content=\"t[item.tool]\"\n :shortcut=\"whiteboardKeys[item.tool]\"\n placement=\"bottom\"\n >\n <button\n type=\"button\"\n class=\"dou-whiteboard-toolbar__button\"\n :class=\"{ 'is-locked': state.tool.value === item.tool && state.locked.value }\"\n :aria-pressed=\"state.tool.value === item.tool\"\n :aria-label=\"t[item.tool]\"\n @click=\"pick(item.tool, false)\"\n @dblclick=\"pick(item.tool, true)\"\n >\n <component\n :is=\"item.tool === 'hand' && state.panning.value ? HandGrabIcon : item.icon\"\n />\n </button>\n </DouTooltip>\n </template>\n <DouTooltip :content=\"t.image\" :shortcut=\"imageKey\" placement=\"bottom\">\n <button\n type=\"button\"\n class=\"dou-whiteboard-toolbar__button\"\n :class=\"{ 'is-busy': state.uploading.value > 0 }\"\n :aria-label=\"t.image\"\n :aria-busy=\"state.uploading.value > 0 || undefined\"\n @click=\"insertImage\"\n >\n <ImageIcon />\n </button>\n </DouTooltip>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EAuBA,MAAM,MAAM,cAAc;EAC1B,MAAM,QAAQ,WAAW,GAAG;EAC5B,MAAM,IAAI,eAAe,IAAI,SAAS,MAAM,KAAK;EAEjD,MAAM,SAAwD;GAC5D,CACE;IAAE,MAAM;IAAU,MAAM;GAAW,GACnC;IAAE,MAAM;IAAQ,MAAM;GAAS,CACjC;GACA;IACE;KAAE,MAAM;KAAQ,MAAM;IAAW;IACjC;KAAE,MAAM;KAAW,MAAM;IAAW;IACpC;KAAE,MAAM;KAAW,MAAM;IAAY;GACvC;GACA,CACE;IAAE,MAAM;IAAU,MAAM;GAAe,GACvC;IAAE,MAAM;IAAQ,MAAM;GAAS,CACjC;GACA,CACE;IAAE,MAAM;IAAO,MAAM;GAAW,GAChC;IAAE,MAAM;IAAU,MAAM;GAAW,CACrC;EACF;;EAGA,MAAM,uBAAO,IAAI,IAAoB;GAAC;GAAQ;GAAW;GAAW;GAAU;EAAM,CAAC;EAIrF,SAAS,KAAK,MAAsB,MAAe;GACjD,MAAM,KAAK,QAAQ;GACnB,MAAM,OAAO,QAAQ,QAAQ,KAAK,IAAI,IAAI;GAC1C,IAAI,KAAK,OAAO,MAAM,EAAE,eAAe,KAAK,CAAC;EAC/C;EAEA,SAAS,cAAc;GACrB,WAAW,GAAG;EAChB;EAIA,MAAM,KAAK,eAA4B,IAAI;EAC3C,MAAM,OAAO,IAAI;GAAE,OAAO;GAAO,KAAK;EAAM,CAAC;;EAE7C,IAAI,MAAM;EACV,SAAS,UAAU;GACjB,MAAM,MAAM,GAAG;GACf,IAAI,CAAC,KAAK;GAEV,MAAM,OAAO,KAAK,IAAI,iBAAiB,KAAK,GAAG,C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_createElementBlock","_createElementVNode","_normalizeClass","_Fragment","_renderList","_createCommentVNode","_createBlock","_withCtx","_resolveDynamicComponent","_createVNode"],"sources":["../../src/whiteboard/whiteboard-toolbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n CircleIcon,\n CursorIcon,\n DiamondIcon,\n EraserIcon,\n HandGrabIcon,\n HandIcon,\n ImageIcon,\n MessagePlusIcon,\n PencilIcon,\n SquareIcon,\n StickyNoteIcon,\n TypeIcon,\n} from '@dou-ui/icons'\nimport { DouTooltip, scrollPositionOf } from 'dou-ui'\nimport { computed, onBeforeUnmount, ref, useTemplateRef, watch, type Component } from 'vue'\nimport { useFlowEditor } from '../context'\nimport { pickImages } from './image'\nimport { imageKey, whiteboardKeys, type WhiteboardTool } from './model'\nimport { boardState, usable } from './state'\n\ndefineOptions({ name: 'DouWhiteboardToolbar' })\n\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\nconst t = computed(() => ctx.messages.value.board)\n\nconst all: { tool: WhiteboardTool; icon: Component }[][] = [\n [\n { tool: 'select', icon: CursorIcon },\n { tool: 'hand', icon: HandIcon },\n ],\n [\n { tool: 'rect', icon: SquareIcon },\n { tool: 'ellipse', icon: CircleIcon },\n { tool: 'diamond', icon: DiamondIcon },\n ],\n [\n { tool: 'sticky', icon: StickyNoteIcon },\n { tool: 'text', icon: TypeIcon },\n ],\n [\n { tool: 'pen', icon: PencilIcon },\n { tool: 'eraser', icon: EraserIcon },\n ],\n [{ tool: 'comment', icon: MessagePlusIcon }],\n]\n\n/** The tools that can be used now: while read-only, select, hand and comment; comment while threads can be started. */\nconst groups = computed(() =>\n all\n .map((group) => group.filter((item) => usable(ctx, item.tool)))\n .filter((group) => group.length),\n)\n\n/** Tools that go back to select after one use, unless kept with a double click. */\nconst once = new Set<WhiteboardTool>(['rect', 'ellipse', 'diamond', 'sticky', 'text'])\n\n// A click picks the tool for one use; a double click keeps it. Focus goes\n// back to the canvas, where the tool is used and its keys work.\nfunction pick(tool: WhiteboardTool, keep: boolean) {\n state.tool.value = tool\n state.locked.value = keep && once.has(tool)\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction insertImage() {\n pickImages(ctx)\n}\n\n// Too narrow for every tool: one row that scrolls sideways, faded at the\n// side with more, and the tool in hand kept in view.\nconst el = useTemplateRef<HTMLElement>('el')\nconst more = ref({ start: false, end: false })\n/** Right to left; read when the row is laid out, not on every scroll. */\nlet rtl = false\nfunction measure() {\n const box = el.value\n if (!box) return\n // from the start, also right to left, and kept in range while the row bounces\n const left = Math.abs(scrollPositionOf(box, rtl).left)\n const rest = box.scrollWidth - box.clientWidth - left\n more.value = { start: left > 1, end: rest > 1 }\n}\nlet observer: ResizeObserver | undefined\nwatch(\n el,\n (box) => {\n observer?.disconnect()\n if (!box || typeof ResizeObserver === 'undefined') return\n observer = new ResizeObserver(() => {\n rtl = getComputedStyle(box).direction === 'rtl'\n measure()\n })\n observer.observe(box)\n },\n { flush: 'post' },\n)\nonBeforeUnmount(() => observer?.disconnect())\nwatch(\n () => state.tool.value,\n () => {\n const box = el.value\n const button = box?.querySelector<HTMLElement>('[aria-pressed=\"true\"]')\n if (!box || !button || box.scrollWidth <= box.clientWidth) return\n const start = button.offsetLeft - 24\n const end = button.offsetLeft + button.offsetWidth + 24 - box.clientWidth\n if (box.scrollLeft > start) box.scrollLeft = start\n else if (box.scrollLeft < end) box.scrollLeft = end\n },\n { flush: 'post' },\n)\n</script>\n\n<template>\n <div\n v-if=\"!ctx.readonly.value || ctx.canComment.value\"\n class=\"dou-whiteboard-toolbar\"\n data-flow-overlay\n role=\"toolbar\"\n :aria-label=\"t.tools\"\n >\n <div\n ref=\"el\"\n class=\"dou-whiteboard-toolbar__scroll\"\n :class=\"{ 'has-more-start': more.start, 'has-more-end': more.end }\"\n @scroll.passive=\"measure\"\n >\n <template v-for=\"(group, i) in groups\" :key=\"i\">\n <span v-if=\"i\" class=\"dou-whiteboard-toolbar__divider\" />\n <DouTooltip\n v-for=\"item in group\"\n :key=\"item.tool\"\n :content=\"t[item.tool]\"\n :shortcut=\"whiteboardKeys[item.tool]\"\n placement=\"bottom\"\n >\n <button\n type=\"button\"\n class=\"dou-whiteboard-toolbar__button\"\n :class=\"{ 'is-locked': state.tool.value === item.tool && state.locked.value }\"\n :aria-pressed=\"state.tool.value === item.tool\"\n :aria-label=\"t[item.tool]\"\n @click=\"pick(item.tool, false)\"\n @dblclick=\"pick(item.tool, true)\"\n >\n <component\n :is=\"item.tool === 'hand' && state.panning.value ? HandGrabIcon : item.icon\"\n />\n </button>\n </DouTooltip>\n </template>\n <DouTooltip\n v-if=\"!ctx.readonly.value\"\n :content=\"t.image\"\n :shortcut=\"imageKey\"\n placement=\"bottom\"\n >\n <button\n type=\"button\"\n class=\"dou-whiteboard-toolbar__button\"\n :class=\"{ 'is-busy': state.uploading.value > 0 }\"\n :aria-label=\"t.image\"\n :aria-busy=\"state.uploading.value > 0 || undefined\"\n @click=\"insertImage\"\n >\n <ImageIcon />\n </button>\n </DouTooltip>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EAwBA,MAAM,MAAM,cAAc;EAC1B,MAAM,QAAQ,WAAW,GAAG;EAC5B,MAAM,IAAI,eAAe,IAAI,SAAS,MAAM,KAAK;EAEjD,MAAM,MAAqD;GACzD,CACE;IAAE,MAAM;IAAU,MAAM;GAAW,GACnC;IAAE,MAAM;IAAQ,MAAM;GAAS,CACjC;GACA;IACE;KAAE,MAAM;KAAQ,MAAM;IAAW;IACjC;KAAE,MAAM;KAAW,MAAM;IAAW;IACpC;KAAE,MAAM;KAAW,MAAM;IAAY;GACvC;GACA,CACE;IAAE,MAAM;IAAU,MAAM;GAAe,GACvC;IAAE,MAAM;IAAQ,MAAM;GAAS,CACjC;GACA,CACE;IAAE,MAAM;IAAO,MAAM;GAAW,GAChC;IAAE,MAAM;IAAU,MAAM;GAAW,CACrC;GACA,CAAC;IAAE,MAAM;IAAW,MAAM;GAAgB,CAAC;EAC7C;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ACxC,cAAY,EAAA,MAAE,KAAK;OACnB,UAAK,WAAE,KAAK,KAAK,MAAI,KAAA;OACrB,aAAQ,WAAE,KAAK,KAAK,MAAI,IAAA;M,KAEzBC,UAAA,GAAAO,YAEEE,wBADK,KAAK,SAAI,UAAeV,MAAA,KAAA,CAAK,CAAC,QAAQ,QAAQA,MAAA,YAAA,IAAe,KAAK,IAAI,CAAA,E;;;;G,WAM1E,CAAAA,MAAA,GAAA,CAAG,CAAC,SAAS,SADtBC,UAAA,GAAAO,YAgBaR,MAAA,UAAA,GAAA;;IAdV,SAAS,EAAA,MAAE;IACX,UAAUA,MAAAA,GAAA;IACX,WAAU;;IAEV,SAAAS,cASS,CATTN,mBASS,UAAA;KARP,MAAK;KACL,OAAKC,eAAA,CAAC,kCAAgC,EAAA,WACjBJ,MAAA,KAAA,CAAK,CAAC,UAAU,QAAK,EAAA,CAAA,CAAA;KACzC,cAAY,EAAA,MAAE;KACd,aAAWA,MAAA,KAAA,CAAK,CAAC,UAAU,QAAK,KAAQ,KAAA;KACxC,SAAO;I,IAERW,YAAaX,MAAA,SAAA,CAAA,C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dou-ui/flow",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.10",
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.1",
57
+ "dou-ui": "0.1.0-alpha.10",
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.1"
67
+ "@dou-ui/icons": "0.1.0-alpha.10"
68
68
  },
69
69
  "devDependencies": {
70
70
  "y-protocols": "^1.0.7",