@dou-ui/flow 0.1.0-alpha.3 → 0.1.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/collaboration/index.js +114 -6
  2. package/dist/collaboration/index.js.map +1 -1
  3. package/dist/comments.js +257 -0
  4. package/dist/comments.js.map +1 -0
  5. package/dist/components/default-node.js.map +1 -1
  6. package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js +4 -4
  7. package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  8. package/dist/components/flow-comments.js +6 -0
  9. package/dist/components/flow-comments.js.map +1 -0
  10. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +218 -0
  11. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
  12. package/dist/components/flow-port.js.map +1 -1
  13. package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js +7 -42
  14. package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js.map +1 -1
  15. package/dist/components/flow-toolbar.js.map +1 -1
  16. package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js +300 -9
  17. package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  18. package/dist/components/node-view.js.map +1 -1
  19. package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js +2 -2
  20. package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js.map +1 -1
  21. package/dist/components/port-view.js +6 -0
  22. package/dist/components/port-view.js.map +1 -0
  23. package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js +60 -0
  24. package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js.map +1 -0
  25. package/dist/context.js.map +1 -1
  26. package/dist/core/extension.js.map +1 -1
  27. package/dist/core/history.js +26 -0
  28. package/dist/core/history.js.map +1 -1
  29. package/dist/core/model.js.map +1 -1
  30. package/dist/core/node-types.js +39 -1
  31. package/dist/core/node-types.js.map +1 -1
  32. package/dist/core/transaction.js +5 -4
  33. package/dist/core/transaction.js.map +1 -1
  34. package/dist/document.js +1 -1
  35. package/dist/export/color.js +49 -6
  36. package/dist/export/color.js.map +1 -1
  37. package/dist/export/context.js +16 -9
  38. package/dist/export/context.js.map +1 -1
  39. package/dist/export/draw.js +6 -5
  40. package/dist/export/draw.js.map +1 -1
  41. package/dist/export/render.js +78 -0
  42. package/dist/export/render.js.map +1 -0
  43. package/dist/flow-editor.js.map +1 -1
  44. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +757 -129
  45. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  46. package/dist/index.js +5 -4
  47. package/dist/index.js.map +1 -1
  48. package/dist/kit.js +1 -1
  49. package/dist/locale.js +102 -3
  50. package/dist/locale.js.map +1 -1
  51. package/dist/style.css +1 -1
  52. package/dist/style.js +2 -1
  53. package/dist/types/collaboration/index.d.ts +32 -4
  54. package/dist/types/comments.d.ts +73 -0
  55. package/dist/types/components/flow-comments.vue.d.ts +35 -0
  56. package/dist/types/components/flow-port.vue.d.ts +8 -2
  57. package/dist/types/components/port-view.vue.d.ts +10 -0
  58. package/dist/types/components/port.d.ts +2 -2
  59. package/dist/types/context.d.ts +48 -1
  60. package/dist/types/core/extension.d.ts +9 -1
  61. package/dist/types/core/history.d.ts +10 -0
  62. package/dist/types/core/menu.d.ts +60 -0
  63. package/dist/types/core/model.d.ts +22 -0
  64. package/dist/types/core/node-types.d.ts +18 -2
  65. package/dist/types/core/transaction.d.ts +2 -1
  66. package/dist/types/export/color.d.ts +6 -1
  67. package/dist/types/export/render.d.ts +27 -0
  68. package/dist/types/flow-editor.vue.d.ts +11 -1
  69. package/dist/types/index.d.ts +36 -7
  70. package/dist/types/locale.d.ts +27 -1
  71. package/dist/types/whiteboard/board-node.vue.d.ts +5 -0
  72. package/dist/types/whiteboard/colors.d.ts +36 -0
  73. package/dist/types/whiteboard/index.d.ts +2 -2
  74. package/dist/types/whiteboard/model.d.ts +24 -14
  75. package/dist/types/whiteboard/state.d.ts +2 -0
  76. package/dist/types/whiteboard/toolbar.d.ts +46 -0
  77. package/dist/whiteboard/board-node.js.map +1 -1
  78. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +76 -20
  79. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  80. package/dist/whiteboard/colors.js +84 -0
  81. package/dist/whiteboard/colors.js.map +1 -0
  82. package/dist/whiteboard/connector.js +47 -13
  83. package/dist/whiteboard/connector.js.map +1 -1
  84. package/dist/whiteboard/draw.js +26 -9
  85. package/dist/whiteboard/draw.js.map +1 -1
  86. package/dist/whiteboard/index.js +2 -1
  87. package/dist/whiteboard/kit.js +65 -8
  88. package/dist/whiteboard/kit.js.map +1 -1
  89. package/dist/whiteboard/model.js +5 -31
  90. package/dist/whiteboard/model.js.map +1 -1
  91. package/dist/whiteboard/state.js +6 -1
  92. package/dist/whiteboard/state.js.map +1 -1
  93. package/dist/whiteboard/toolbar.js +296 -0
  94. package/dist/whiteboard/toolbar.js.map +1 -0
  95. package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
  96. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
  97. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  98. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"draw.js","names":[],"sources":["../../src/whiteboard/draw.ts"],"sourcesContent":["import type { FlowNode } from '../core/model'\nimport type { FlowDrawContext } from '../export/context'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport type { WhiteboardNodeData, WhiteboardShape } from './model'\n\nconst px = (value: string, fallback: number) => {\n const n = Number.parseFloat(value)\n return Number.isFinite(n) ? n : fallback\n}\nconst r = (value: number) => Math.round(value * 100) / 100\n\n/** A board node as SVG, as `board-node.vue` draws it. */\nexport function drawBoardNode(node: FlowNode<WhiteboardNodeData>, draw: FlowDrawContext): string {\n const data = (node.data ?? {}) as WhiteboardNodeData & {\n shape?: WhiteboardShape\n text?: string\n tone?: string\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n }\n const kind = node.type === 'shape' || !node.type ? 'shape' : node.type\n const tone = data.tone ?? (kind === 'sticky' ? 'warning' : 'neutral')\n const shape = data.shape ?? 'rect'\n const nodeClass = `dou-whiteboard-node is-${kind}${kind === 'shape' ? ` is-${shape}` : ''} is-${tone}`\n const { width: w, height: h } = draw\n const parts: string[] = []\n\n if (kind === 'shape') {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__shape')\n const stroke = px(s.strokeWidth, 1.5)\n const i = stroke / 2\n const paint = `fill=\"${draw.color(s.fill)}\" stroke=\"${draw.color(s.stroke)}\" stroke-width=\"${stroke}\" stroke-linejoin=\"round\"`\n if (shape === 'ellipse')\n parts.push(\n `<ellipse cx=\"${r(w / 2)}\" cy=\"${r(h / 2)}\" rx=\"${r(Math.max(0, w / 2 - i))}\" ry=\"${r(Math.max(0, h / 2 - i))}\" ${paint}/>`,\n )\n else if (shape === 'diamond')\n parts.push(\n `<polygon points=\"${r(w / 2)},${1} ${r(w - 1)},${r(h / 2)} ${r(w / 2)},${r(h - 1)} 1,${r(h / 2)}\" ${paint}/>`,\n )\n else\n parts.push(\n `<rect x=\"${i}\" y=\"${i}\" width=\"${r(Math.max(0, w - stroke))}\" height=\"${r(Math.max(0, h - stroke))}\" rx=\"8\" ${paint}/>`,\n )\n } else if (kind === 'sticky') {\n const s = draw.style(nodeClass)\n parts.push(\n `<rect width=\"${r(w)}\" height=\"${r(h)}\" rx=\"${px(s.borderTopLeftRadius, 4)}\" fill=\"${draw.color(s.backgroundColor)}\"/>`,\n )\n } else if (kind === 'ink' && data.points && data.box) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__ink')\n const size = data.size ?? INK_SIZE\n const d = inkOutline(fitInk(unpack(data.points), data.box, w, h, size), size)\n parts.push(`<path d=\"${d}\" fill=\"${draw.color(s.fill)}\"/>`)\n } else if (kind === 'image' && data.src) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__image')\n parts.push(\n draw.image(\n data.src,\n { x: 0, y: 0, width: w, height: h },\n { radius: px(s.borderTopLeftRadius, 4) },\n ),\n )\n }\n\n if (data.text && (kind === 'shape' || kind === 'sticky' || kind === 'text')) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__text')\n const size = px(s.fontSize, 14)\n const top = px(s.paddingTop, 12)\n const side = px(s.paddingLeft, 16)\n const lineHeight = px(s.lineHeight, size * 1.5)\n const centred = kind !== 'text'\n parts.push(\n draw.text(\n data.text,\n { x: side, y: top, width: Math.max(0, w - side * 2), height: Math.max(0, h - top * 2) },\n {\n size,\n lineHeight,\n color: draw.color(draw.style(nodeClass).color),\n align: centred ? 'center' : 'start',\n valign: centred ? 'middle' : 'top',\n },\n ),\n )\n }\n\n const body = parts.join('')\n const rotation = data.rotation\n return rotation ? `<g transform=\"rotate(${rotation} ${r(w / 2)} ${r(h / 2)})\">${body}</g>` : body\n}\n"],"mappings":";;AAKA,IAAM,MAAM,OAAe,aAAqB;CAC9C,MAAM,IAAI,OAAO,WAAW,KAAK;CACjC,OAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC;AACA,IAAM,KAAK,UAAkB,KAAK,MAAM,QAAQ,GAAG,IAAI;;AAGvD,SAAgB,cAAc,MAAoC,MAA+B;CAC/F,MAAM,OAAQ,KAAK,QAAQ,CAAC;CAS5B,MAAM,OAAO,KAAK,SAAS,WAAW,CAAC,KAAK,OAAO,UAAU,KAAK;CAClE,MAAM,OAAO,KAAK,SAAS,SAAS,WAAW,YAAY;CAC3D,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,YAAY,0BAA0B,OAAO,SAAS,UAAU,OAAO,UAAU,GAAG,MAAM;CAChG,MAAM,EAAE,OAAO,GAAG,QAAQ,MAAM;CAChC,MAAM,QAAkB,CAAC;CAEzB,IAAI,SAAS,SAAS;EACpB,MAAM,IAAI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whiteboard/draw.ts"],"sourcesContent":["import type { FlowNode } from '../core/model'\nimport type { FlowDrawContext } from '../export/context'\nimport {\n isNoneColor,\n resolveFillColor,\n resolveStrokeColor,\n resolveTextColor,\n type WhiteboardColor,\n type WhiteboardFill,\n type WhiteboardStroke,\n} from './colors'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport type { WhiteboardNodeData, WhiteboardShape } from './model'\n\nconst px = (value: string, fallback: number) => {\n const n = Number.parseFloat(value)\n return Number.isFinite(n) ? n : fallback\n}\nconst r = (value: number) => Math.round(value * 100) / 100\n\n/** A board node as SVG, as `board-node.vue` draws it. */\nexport function drawBoardNode(node: FlowNode<WhiteboardNodeData>, draw: FlowDrawContext): string {\n const data = (node.data ?? {}) as WhiteboardNodeData & {\n shape?: WhiteboardShape\n text?: string\n tone?: string\n fill?: WhiteboardFill\n stroke?: WhiteboardStroke\n textColor?: WhiteboardColor\n color?: WhiteboardColor\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n }\n const kind = node.type === 'shape' || !node.type ? 'shape' : node.type\n const tone = data.tone ?? (kind === 'sticky' ? 'warning' : 'neutral')\n const shape = data.shape ?? 'rect'\n const nodeClass = `dou-whiteboard-node is-${kind}${kind === 'shape' ? ` is-${shape}` : ''} is-${tone}`\n const { width: w, height: h } = draw\n const parts: string[] = []\n\n if (kind === 'shape') {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__shape')\n const borderless = isNoneColor(data.stroke)\n const customFill = resolveFillColor(data.fill, 'shape')\n const fill =\n customFill === 'none' ? 'none' : (customFill && draw.color(customFill)) || draw.color(s.fill)\n const strokeWidth = borderless ? 0 : px(s.strokeWidth, 1.5)\n const i = strokeWidth / 2\n const diamondInset = borderless ? 0 : 1\n if (!borderless || fill !== 'none') {\n const customStroke = borderless ? undefined : resolveStrokeColor(data.stroke)\n const stroke = (customStroke && draw.color(customStroke)) || draw.color(s.stroke)\n const paint = borderless\n ? `fill=\"${draw.escape(fill)}\" stroke=\"none\"`\n : `fill=\"${draw.escape(fill)}\" stroke=\"${draw.escape(stroke)}\" stroke-width=\"${strokeWidth}\" stroke-linejoin=\"round\"`\n if (shape === 'ellipse')\n parts.push(\n `<ellipse cx=\"${r(w / 2)}\" cy=\"${r(h / 2)}\" rx=\"${r(Math.max(0, w / 2 - i))}\" ry=\"${r(Math.max(0, h / 2 - i))}\" ${paint}/>`,\n )\n else if (shape === 'diamond')\n parts.push(\n `<polygon points=\"${r(w / 2)},${diamondInset} ${r(w - diamondInset)},${r(h / 2)} ${r(w / 2)},${r(h - diamondInset)} ${diamondInset},${r(h / 2)}\" ${paint}/>`,\n )\n else\n parts.push(\n `<rect x=\"${i}\" y=\"${i}\" width=\"${r(Math.max(0, w - strokeWidth))}\" height=\"${r(Math.max(0, h - strokeWidth))}\" rx=\"8\" ${paint}/>`,\n )\n }\n } else if (kind === 'sticky') {\n const s = draw.style(nodeClass)\n const customFill = resolveFillColor(data.fill, 'sticky')\n if (customFill !== 'none') {\n const fill = (customFill && draw.color(customFill)) || draw.color(s.backgroundColor)\n parts.push(\n `<rect width=\"${r(w)}\" height=\"${r(h)}\" rx=\"${px(s.borderTopLeftRadius, 4)}\" fill=\"${draw.escape(fill)}\"/>`,\n )\n }\n } else if (kind === 'ink' && data.points && data.box) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__ink')\n const size = data.size ?? INK_SIZE\n const d = inkOutline(fitInk(unpack(data.points), data.box, w, h, size), size)\n const customStroke = resolveStrokeColor(data.color)\n const fill =\n (customStroke && customStroke !== 'none' && draw.color(customStroke)) || draw.color(s.fill)\n parts.push(`<path d=\"${d}\" fill=\"${draw.escape(fill)}\"/>`)\n } else if (kind === 'image' && data.src) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__image')\n parts.push(\n draw.image(\n data.src,\n { x: 0, y: 0, width: w, height: h },\n { radius: px(s.borderTopLeftRadius, 4) },\n ),\n )\n }\n\n if (data.text && (kind === 'shape' || kind === 'sticky' || kind === 'text')) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__text')\n const size = px(s.fontSize, 14)\n const top = px(s.paddingTop, 12)\n const side = px(s.paddingLeft, 16)\n const lineHeight = px(s.lineHeight, size * 1.5)\n const centred = kind !== 'text'\n const customText = resolveTextColor(kind === 'text' ? data.color : data.textColor)\n const color = (customText && draw.color(customText)) || draw.color(draw.style(nodeClass).color)\n parts.push(\n draw.text(\n data.text,\n { x: side, y: top, width: Math.max(0, w - side * 2), height: Math.max(0, h - top * 2) },\n {\n size,\n lineHeight,\n color,\n align: centred ? 'center' : 'start',\n valign: centred ? 'middle' : 'top',\n },\n ),\n )\n }\n\n const body = parts.join('')\n const rotation = data.rotation\n return rotation ? `<g transform=\"rotate(${rotation} ${r(w / 2)} ${r(h / 2)})\">${body}</g>` : body\n}\n"],"mappings":";;;AAcA,IAAM,MAAM,OAAe,aAAqB;CAC9C,MAAM,IAAI,OAAO,WAAW,KAAK;CACjC,OAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC;AACA,IAAM,KAAK,UAAkB,KAAK,MAAM,QAAQ,GAAG,IAAI;;AAGvD,SAAgB,cAAc,MAAoC,MAA+B;CAC/F,MAAM,OAAQ,KAAK,QAAQ,CAAC;CAa5B,MAAM,OAAO,KAAK,SAAS,WAAW,CAAC,KAAK,OAAO,UAAU,KAAK;CAClE,MAAM,OAAO,KAAK,SAAS,SAAS,WAAW,YAAY;CAC3D,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,YAAY,0BAA0B,OAAO,SAAS,UAAU,OAAO,UAAU,GAAG,MAAM;CAChG,MAAM,EAAE,OAAO,GAAG,QAAQ,MAAM;CAChC,MAAM,QAAkB,CAAC;CAEzB,IAAI,SAAS,SAAS;EACpB,MAAM,IAAI,KAAK,MAAM,WAAW,4BAA4B;EAC5D,MAAM,aAAa,YAAY,KAAK,MAAM;EAC1C,MAAM,aAAa,iBAAiB,KAAK,MAAM,OAAO;EACtD,MAAM,OACJ,eAAe,SAAS,SAAU,cAA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AC9C,MAAM,UAAU,SAAS;EACzB,MAAM,aAAa,iBAAiB,SAAS,SAAS,KAAK,QAAQ,KAAK,SAAS;EACjF,MAAM,QAAS,cAAc,KAAK,MAAM,UAAU,KAAM,KAAK,MAAM,KAAK,MAAM,SAAS,CAAC,CAAC,KAAK;EAC9F,MAAM,KACJ,KAAK,KACH,KAAK,MACL;GAAE,GAAG;GAAM,GAAG;GAAK,OAAO,KAAK,IAAI,GAAG,IAAI,OAAO,CAAC;GAAG,QAAQ,KAAK,IAAI,GAAG,IAAI,MAAM,CAAC;EAAE,GACtF;GACE;GACA;GACA;GACA,OAAO,UAAU,WAAW;GAC5B,QAAQ,UAAU,WAAW;EAC/B,CACF,CACF;CACF;CAEA,MAAM,OAAO,MAAM,KAAK,EAAE;CAC1B,MAAM,WAAW,KAAK;CACtB,OAAO,WAAW,wBAAwB,SAAS,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,QAAQ;AAC/F"}
@@ -1,5 +1,6 @@
1
+ import { isWhiteboardColor, whiteboardColors } from "./colors.js";
1
2
  import { imageKey, whiteboardKeys } from "./model.js";
2
3
  import { insertImages, pickImages } from "./image.js";
3
4
  import { connectorEdge } from "./connector.js";
4
5
  import { imageNode, inkNode, shapeNode, stickyNode, textNode, whiteboardKit } from "./kit.js";
5
- export { connectorEdge, imageKey, imageNode, inkNode, insertImages, pickImages, shapeNode, stickyNode, textNode, whiteboardKeys, whiteboardKit };
6
+ export { connectorEdge, imageKey, imageNode, inkNode, insertImages, isWhiteboardColor, pickImages, shapeNode, stickyNode, textNode, whiteboardColors, whiteboardKeys, whiteboardKit };
@@ -1,13 +1,15 @@
1
+ import { turn } from "../core/geometry.js";
1
2
  import { defineNodeType } from "../core/node-types.js";
2
- import { defineFlowExtension } from "../core/extension.js";
3
3
  import { format } from "../locale.js";
4
+ import { defineFlowExtension } from "../core/extension.js";
4
5
  import { createId } from "../core/model.js";
5
- import { anchorPorts, whiteboardKeys } from "./model.js";
6
- import { boardState } from "./state.js";
6
+ import { whiteboardKeys } from "./model.js";
7
+ import { boardState, usable } from "./state.js";
7
8
  import board_node_default from "./board-node.js";
8
9
  import board_draft_default from "./board-draft.js";
9
10
  import { imageFiles, insertImages, pickImages } from "./image.js";
10
11
  import whiteboard_toolbar_default from "./whiteboard-toolbar.js";
12
+ import { boardNodeToolbar } from "./toolbar.js";
11
13
  import { connectorEdge, connectorToolbar } from "./connector.js";
12
14
  import { drawBoardNode } from "./draw.js";
13
15
  import { drawInk, erase } from "./pen.js";
@@ -33,7 +35,7 @@ var turnedBy = (node) => node.data?.rotation ?? 0;
33
35
  var shapeNode = defineNodeType({
34
36
  type: "shape",
35
37
  component: board_node_default,
36
- ports: anchorPorts,
38
+ ports: "sides",
37
39
  frame: false,
38
40
  resizable: {
39
41
  minWidth: 24,
@@ -52,7 +54,7 @@ var shapeNode = defineNodeType({
52
54
  var stickyNode = defineNodeType({
53
55
  type: "sticky",
54
56
  component: board_node_default,
55
- ports: anchorPorts,
57
+ ports: "sides",
56
58
  frame: false,
57
59
  resizable: {
58
60
  minWidth: 64,
@@ -71,7 +73,7 @@ var stickyNode = defineNodeType({
71
73
  var textNode = defineNodeType({
72
74
  type: "text",
73
75
  component: board_node_default,
74
- ports: anchorPorts,
76
+ ports: "sides",
75
77
  frame: false,
76
78
  resizable: {
77
79
  minWidth: 24,
@@ -107,7 +109,7 @@ var inkNode = defineNodeType({
107
109
  var imageNode = defineNodeType({
108
110
  type: "image",
109
111
  component: board_node_default,
110
- ports: anchorPorts,
112
+ ports: "sides",
111
113
  frame: false,
112
114
  resizable: {
113
115
  minWidth: 24,
@@ -166,6 +168,51 @@ var SIZES = {
166
168
  height: 40
167
169
  }
168
170
  };
171
+ /**
172
+ * The comment tool: a click on a node starts a thread pinned where it was
173
+ * clicked, the point turned back with the node. A press on the empty canvas
174
+ * does nothing; a mouse drag does nothing either, so a thread isn't started
175
+ * by mistake, while a finger's drag moves the view, as it does elsewhere.
176
+ */
177
+ function pinComment(ctx, node, start, event) {
178
+ const client = {
179
+ x: event.clientX,
180
+ y: event.clientY
181
+ };
182
+ const origin = { ...ctx.viewport.value };
183
+ const finger = event.pointerType !== "mouse";
184
+ let moved = false;
185
+ return {
186
+ move(_, move) {
187
+ const dx = move.clientX - client.x;
188
+ const dy = move.clientY - client.y;
189
+ if (!moved && Math.hypot(dx, dy) <= 8) return;
190
+ moved = true;
191
+ if (finger) ctx.setViewport({
192
+ ...origin,
193
+ x: origin.x + dx,
194
+ y: origin.y + dy
195
+ });
196
+ },
197
+ end() {
198
+ const rect = node && !moved ? ctx.getNodeRect(node) : null;
199
+ if (!node || !rect || !rect.width || !rect.height) return;
200
+ const centre = {
201
+ x: rect.x + rect.width / 2,
202
+ y: rect.y + rect.height / 2
203
+ };
204
+ const local = turn(start, centre, -ctx.nodeRotation(node));
205
+ const at = {
206
+ x: (local.x - rect.x) / rect.width,
207
+ y: (local.y - rect.y) / rect.height
208
+ };
209
+ ctx.comment({
210
+ node,
211
+ at
212
+ }, { focus: !finger });
213
+ }
214
+ };
215
+ }
169
216
  /** After a tool put down a node: back to select unless kept, and notes and text open to be written in. */
170
217
  function added(ctx, tool, id) {
171
218
  const state = boardState(ctx);
@@ -187,6 +234,7 @@ function whiteboardKit(options = {}) {
187
234
  imageNode
188
235
  ],
189
236
  edgeTypes: [connectorEdge],
237
+ toolbarItems: boardNodeToolbar,
190
238
  edgeToolbarItems: connectorToolbar,
191
239
  edgeType: "connector",
192
240
  layers: { above: [board_draft_default] },
@@ -201,6 +249,7 @@ function whiteboardKit(options = {}) {
201
249
  state.tool.value = outer.value;
202
250
  stops.push(watch(outer, (tool) => state.tool.value = tool), watch(state.tool, (tool) => outer.value = tool));
203
251
  }
252
+ stops.push(watch(() => usable(ctx, state.tool.value), (ok) => !ok && (state.tool.value = "select"), { immediate: true }));
204
253
  stops.push(watch(state.tool, (tool) => {
205
254
  const root = ctx.root.value;
206
255
  if (root) root.dataset.boardTool = tool;
@@ -250,6 +299,8 @@ function whiteboardKit(options = {}) {
250
299
  const state = boardState(ctx);
251
300
  const tool = state.tool.value;
252
301
  if (tool === "select") return;
302
+ if (ctx.readonly.value && tool !== "hand" && tool !== "comment") return;
303
+ if (tool === "comment") return pinComment(ctx, press.node?.id ?? null, press.point, press.event);
253
304
  state.editing.value = null;
254
305
  if (tool === "hand") {
255
306
  const start = {
@@ -353,6 +404,7 @@ function whiteboardKit(options = {}) {
353
404
  keymap(ctx) {
354
405
  const state = boardState(ctx);
355
406
  const pick = (tool) => () => {
407
+ if (!usable(ctx, tool)) return false;
356
408
  state.tool.value = tool;
357
409
  state.locked.value = false;
358
410
  const t = ctx.messages.value.board;
@@ -367,8 +419,13 @@ function whiteboardKit(options = {}) {
367
419
  pickImages(ctx);
368
420
  },
369
421
  enter: () => {
370
- if (ctx.readonly.value) return false;
371
422
  const tool = state.tool.value;
423
+ if (tool === "comment") {
424
+ const { nodes, edges } = ctx.selection.value;
425
+ if (nodes.length !== 1 || edges.length) return false;
426
+ return ctx.comment({ node: nodes[0] }) || false;
427
+ }
428
+ if (ctx.readonly.value) return false;
372
429
  if (tool !== "select" && tool !== "hand" && tool !== "pen" && tool !== "eraser") {
373
430
  const { type, data } = kindOf(tool);
374
431
  const size = tool === "text" ? {
@@ -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 {\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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AAK,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'\nimport { boardNodeToolbar } from './toolbar'\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 toolbarItems: boardNodeToolbar,\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":";;;;;;;;;;;;;;;;;;;AAsCA,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;CACX,OAAO;CACP,OAAO;CACP,WAAW;EAAE,UAAU;EAAI,WAAW;CAAG;CACzC,UAAU;CACV,MAAM;CAC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AI,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,3 +1,4 @@
1
+ import { isWhiteboardColor, whiteboardColors } from "./colors.js";
1
2
  // src/whiteboard/model.ts
2
3
  /** Keys for the tools. */
3
4
  var whiteboardKeys = {
@@ -9,44 +10,17 @@ var whiteboardKeys = {
9
10
  sticky: "s",
10
11
  text: "t",
11
12
  pen: "p",
12
- eraser: "x"
13
+ eraser: "x",
14
+ comment: "m"
13
15
  };
14
16
  /** The key that inserts an image. */
15
17
  var imageKey = "i";
16
- var SIDES = [
18
+ var anchorSides = [
17
19
  "top",
18
20
  "right",
19
21
  "bottom",
20
22
  "left"
21
23
  ];
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 };
24
+ export { anchorSides, imageKey, isWhiteboardColor, whiteboardColors, whiteboardKeys };
51
25
 
52
26
  //# 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'\nimport type { WhiteboardColor, WhiteboardFill, WhiteboardStroke } from './colors'\n\nexport { whiteboardColors, isWhiteboardColor } from './colors'\nexport type {\n WhiteboardColor,\n WhiteboardFill,\n WhiteboardPaletteColor,\n WhiteboardStroke,\n} from './colors'\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; kept for compatibility when `fill` / `stroke` are omitted. */\n tone?: Tone\n /** Background fill color, or `'none'` / `'transparent'` for no fill. */\n fill?: WhiteboardFill\n /** Border color, or `'none'` for a borderless shape. */\n stroke?: WhiteboardStroke\n /** Text color inside the shape. */\n textColor?: WhiteboardColor\n}\n\nexport interface WhiteboardStickyData extends WhiteboardNodeData {\n text?: string\n /** `warning` (yellow) by default; kept for compatibility when `fill` is omitted. */\n tone?: Tone\n /** Background color of the sticky note. */\n fill?: WhiteboardFill\n /** Text color inside the sticky note. */\n textColor?: WhiteboardColor\n}\n\nexport interface WhiteboardTextData extends WhiteboardNodeData {\n text?: string\n /** Text color. */\n color?: WhiteboardColor\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; kept for compatibility when `color` is omitted. */\n tone?: Tone\n /** Stroke color. */\n color?: WhiteboardColor\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 /** Line and arrowhead color. */\n color?: WhiteboardColor\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":";;;AAoHA,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, 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"}
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"}