@dou-ui/flow 0.1.0-alpha.0 → 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.
- package/dist/collaboration/index.js +76 -5
- package/dist/collaboration/index.js.map +1 -1
- package/dist/comments.js +245 -0
- package/dist/comments.js.map +1 -0
- package/dist/components/default-node2.js.map +1 -1
- package/dist/components/flow-comments.js +6 -0
- package/dist/components/flow-comments.js.map +1 -0
- package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +205 -0
- package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/port.js +7 -0
- package/dist/components/port.js.map +1 -0
- package/dist/context.js.map +1 -1
- package/dist/core/edge-types.js +107 -3
- package/dist/core/edge-types.js.map +1 -1
- package/dist/core/extension.js.map +1 -1
- package/dist/core/history.js +26 -0
- package/dist/core/history.js.map +1 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/node-types.js +35 -1
- package/dist/core/node-types.js.map +1 -1
- package/dist/core/transaction.js +112 -15
- package/dist/core/transaction.js.map +1 -1
- package/dist/document.js +1 -1
- package/dist/export/render.js +78 -0
- package/dist/export/render.js.map +1 -0
- package/dist/flow-editor.js.map +1 -1
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +454 -36
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/kit.js +1 -1
- package/dist/locale.js +24 -9
- package/dist/locale.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +2 -1
- package/dist/types/collaboration/index.d.ts +32 -4
- package/dist/types/comments.d.ts +73 -0
- package/dist/types/components/default-node.d.ts +1 -1
- package/dist/types/components/flow-comments.vue.d.ts +35 -0
- package/dist/types/components/port.d.ts +7 -0
- package/dist/types/context.d.ts +54 -1
- package/dist/types/core/extension.d.ts +2 -1
- package/dist/types/core/history.d.ts +10 -0
- package/dist/types/core/menu.d.ts +5 -0
- package/dist/types/core/model.d.ts +19 -0
- package/dist/types/core/node-types.d.ts +16 -2
- package/dist/types/core/transaction.d.ts +23 -1
- package/dist/types/export/render.d.ts +27 -0
- package/dist/types/flow-editor.vue.d.ts +11 -0
- package/dist/types/index.d.ts +36 -9
- package/dist/types/locale.d.ts +13 -3
- package/dist/types/whiteboard/image.d.ts +8 -0
- package/dist/types/whiteboard/index.d.ts +1 -1
- package/dist/types/whiteboard/kit.d.ts +7 -1
- package/dist/types/whiteboard/model.d.ts +2 -11
- package/dist/types/whiteboard/state.d.ts +5 -1
- package/dist/whiteboard/board-node.js.map +1 -1
- package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/whiteboard/connector.js +5 -10
- package/dist/whiteboard/connector.js.map +1 -1
- package/dist/whiteboard/image.js +17 -6
- package/dist/whiteboard/image.js.map +1 -1
- package/dist/whiteboard/kit.js +64 -8
- package/dist/whiteboard/kit.js.map +1 -1
- package/dist/whiteboard/model.js +4 -31
- package/dist/whiteboard/model.js.map +1 -1
- package/dist/whiteboard/state.js +6 -1
- package/dist/whiteboard/state.js.map +1 -1
- package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
- package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
- package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Ref, type ShallowRef } from 'vue';
|
|
2
2
|
import type { FlowEditorContext } from '../context';
|
|
3
3
|
import type { Point, Rect } from '../core/model';
|
|
4
|
-
import type { WhiteboardUpload } from './image';
|
|
4
|
+
import type { WhiteboardUpload, WhiteboardUploadErrorHandler } from './image';
|
|
5
5
|
import type { InkPoint } from './ink';
|
|
6
6
|
import type { WhiteboardShapeTool, WhiteboardTool } from './model';
|
|
7
7
|
/** What the board's pieces share within one editor. */
|
|
@@ -32,6 +32,10 @@ export interface WhiteboardState {
|
|
|
32
32
|
uploading: Ref<number>;
|
|
33
33
|
/** The kit's `upload` option. */
|
|
34
34
|
upload?: WhiteboardUpload;
|
|
35
|
+
/** The kit's `onUploadError` option. */
|
|
36
|
+
onUploadError?: WhiteboardUploadErrorHandler;
|
|
35
37
|
}
|
|
36
38
|
/** The board's state in an editor, made on first use. */
|
|
37
39
|
export declare function boardState(context: FlowEditorContext): WhiteboardState;
|
|
40
|
+
/** Whether a tool can be used now: while read-only only select, hand and comment; comment while threads can be started. */
|
|
41
|
+
export declare function usable(ctx: FlowEditorContext, tool: WhiteboardTool): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-node.js","names":["_sfc_main"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport DouFlowPort from '../components/flow-port.vue'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const rect = ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 }\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${rect.x}px ${rect.y}px`,\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"transform\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span class=\"dou-whiteboard-node__turn\" data-dou-nodrag @pointerdown=\"startTurn\">\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n class=\"dou-whiteboard-node__corner\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"board-node.js","names":["_sfc_main"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport { DouFlowPort } from '../components/port'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const rect = ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 }\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${rect.x}px ${rect.y}px`,\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"transform\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span class=\"dou-whiteboard-node__turn\" data-dou-nodrag @pointerdown=\"startTurn\">\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n class=\"dou-whiteboard-node__corner\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useFlowEditor } from "../context.js";
|
|
2
|
-
import
|
|
2
|
+
import { DouFlowPort } from "../components/port.js";
|
|
3
3
|
import { fitInk, inkOutline, unpack } from "./ink.js";
|
|
4
4
|
import { anchorSides } from "./model.js";
|
|
5
5
|
import { boardState } from "./state.js";
|
|
@@ -273,10 +273,10 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
273
273
|
textContent: toDisplayString(__props.data.text)
|
|
274
274
|
}, null, 12, _hoisted_11)) : createCommentVNode("", true),
|
|
275
275
|
kind.value !== "ink" ? (openBlock(), createElementBlock("div", _hoisted_12, [(openBlock(true), createElementBlock(Fragment, null, renderList(unref(anchorSides), (side) => {
|
|
276
|
-
return openBlock(), createElementBlock(Fragment, { key: side }, [createVNode(
|
|
276
|
+
return openBlock(), createElementBlock(Fragment, { key: side }, [createVNode(unref(DouFlowPort), {
|
|
277
277
|
id: `${side}-in`,
|
|
278
278
|
class: "dou-whiteboard-node__anchor"
|
|
279
|
-
}, null, 8, ["id"]), createVNode(
|
|
279
|
+
}, null, 8, ["id"]), createVNode(unref(DouFlowPort), {
|
|
280
280
|
id: side,
|
|
281
281
|
class: "dou-whiteboard-node__anchor"
|
|
282
282
|
}, null, 8, ["id"])], 64);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-node.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_withModifiers","_createElementVNode","_createVNode","_createCommentVNode","_withDirectives","_vModelText","_toDisplayString","_Fragment","_renderList","DouFlowPort","_createBlock","_Teleport"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport DouFlowPort from '../components/flow-port.vue'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const rect = ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 }\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${rect.x}px ${rect.y}px`,\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"transform\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span class=\"dou-whiteboard-node__turn\" data-dou-nodrag @pointerdown=\"startTurn\">\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n class=\"dou-whiteboard-node__corner\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BA,MAAM,QAAQ;EACd,MAAM,MAAM,cAAc;EAC1B,MAAM,QAAQ,WAAW,GAAG;EAE5B,MAAM,QAAyB;GAAC;GAAU;GAAQ;GAAO;EAAO;;EAEhE,MAAM,OAAO,eAAqB,MAAM,MAAM,MAAM,MAAM,MAAM,KAAK,IAAI,KAAK,OAAO;EACrF,MAAM,QAAQ,eAAgC,MAAM,KAAK,SAAS,MAAM;EACxE,MAAM,OAAO,eACL,MAAM,KAAK,SAAS,KAAK,UAAU,WAAW,YAAY,UAClE;EACA,MAAM,WAAW,eAAe;GAAC;GAAS;GAAU;EAAM,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC;EAEhF,MAAM,MAA4B;GAAE,OAAO;GAAI,QAAQ;GAAI,MAAM;GAAI,KAAK;GAAG,OAAO;EAAG;EACvF,MAAM,WAAW,eAAe,MAAM,KAAK,YAAY,CAAC;EACxD,MAAM,EAAE,SAAS,WAAW,gBAAgB,oBAC1C,KACA,MAAM,OAAO,MAAM,GACnB,UACA;GAAE,OAAO,IAAI,KAAK;GAAQ,QAAQ,IAAI,KAAK;EAAO,CACpD;EAMA,MAAM,YAAY,eAAgB,SAAS,QAAQ,EAAE,QAAQ,GAAG,SAAS,MAAM,KAAK,IAAI,KAAA,CAAU;;;;;;EAMlG,MAAM,gBAAgB,eACpB,KAAK,UAAU,UACX,eAAe,QAAQ,MAAM,EAAE,KAAK,EAAE,CAAC,IACvC,KAAK,UAAU,SACb,eAAe,QAAQ,MAAM,EAAE,CAAC,IAChC,cACR;EACA,MAAM,cAAc,eAAe,cAAc,MAAM,QAAQ,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;EAClF,MAAM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_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_withModifiers","_createElementVNode","_createVNode","_createCommentVNode","_withDirectives","_vModelText","_toDisplayString","_Fragment","_renderList","_createBlock","_Teleport"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport { DouFlowPort } from '../components/port'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const rect = ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 }\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${rect.x}px ${rect.y}px`,\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"transform\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span class=\"dou-whiteboard-node__turn\" data-dou-nodrag @pointerdown=\"startTurn\">\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n class=\"dou-whiteboard-node__corner\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BA,MAAM,QAAQ;EACd,MAAM,MAAM,cAAc;EAC1B,MAAM,QAAQ,WAAW,GAAG;EAE5B,MAAM,QAAyB;GAAC;GAAU;GAAQ;GAAO;EAAO;;EAEhE,MAAM,OAAO,eAAqB,MAAM,MAAM,MAAM,MAAM,MAAM,KAAK,IAAI,KAAK,OAAO;EACrF,MAAM,QAAQ,eAAgC,MAAM,KAAK,SAAS,MAAM;EACxE,MAAM,OAAO,eACL,MAAM,KAAK,SAAS,KAAK,UAAU,WAAW,YAAY,UAClE;EACA,MAAM,WAAW,eAAe;GAAC;GAAS;GAAU;EAAM,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC;EAEhF,MAAM,MAA4B;GAAE,OAAO;GAAI,QAAQ;GAAI,MAAM;GAAI,KAAK;GAAG,OAAO;EAAG;EACvF,MAAM,WAAW,eAAe,MAAM,KAAK,YAAY,CAAC;EACxD,MAAM,EAAE,SAAS,WAAW,gBAAgB,oBAC1C,KACA,MAAM,OAAO,MAAM,GACnB,UACA;GAAE,OAAO,IAAI,KAAK;GAAQ,QAAQ,IAAI,KAAK;EAAO,CACpD;EAMA,MAAM,YAAY,eAAgB,SAA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,UAAA,GAAAC,mBAQE,QAAA;MANC,KAAG,GAAK,OAAO,EAAC,GAAI,OAAO;MAC5B,OAAM;MACL,OAAKG,eAAA;OAAA,MAAU,MAAM,OAAO,CAAC;OAAA,KAAQ,MAAM,OAAO,CAAC;OAAA,QAAW,SAAS,MAAM;MAAA,CAAA;MAC7E,eAAW,GAAK,OAAO,EAAC,GAAI,OAAO;MACpC,mBAAA;MACC,gBAAW,WAAE,SAAS,QAAQ,MAAM"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { bezierEdge, defineEdgeType, stepEdge } from "../core/edge-types.js";
|
|
2
1
|
import { format } from "../locale.js";
|
|
2
|
+
import { bezierEdge, defineEdgeType, stepEdge, straightEdge } from "../core/edge-types.js";
|
|
3
3
|
import { ArrowEndsIcon, ArrowLeftRightIcon, ArrowRightIcon, ConnectorCurveIcon, ConnectorElbowIcon, ConnectorStraightIcon, LineDashDotIcon, LineDashedIcon, LineDottedIcon, LineSolidIcon, LineStyleIcon, MinusIcon, RouteIcon } from "@dou-ui/icons";
|
|
4
4
|
// src/whiteboard/connector.ts
|
|
5
5
|
var ARROW = {
|
|
@@ -59,17 +59,12 @@ var connectorEdge = defineEdgeType({
|
|
|
59
59
|
const data = edge?.data ?? {};
|
|
60
60
|
const route = data.route ?? "straight";
|
|
61
61
|
const straight = route === "straight";
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
label: {
|
|
65
|
-
x: (source.x + target.x) / 2,
|
|
66
|
-
y: (source.y + target.y) / 2
|
|
67
|
-
}
|
|
68
|
-
} : (route === "elbow" ? stepEdge : bezierEdge).route(source, target, edge);
|
|
62
|
+
const points = edge?.points ?? [];
|
|
63
|
+
const base = straight ? straightEdge.route(source, target, edge) : (route === "elbow" ? stepEdge : bezierEdge).route(source, target, edge);
|
|
69
64
|
const arrow = data.arrow ?? "end";
|
|
70
65
|
let marks = "";
|
|
71
|
-
if (arrow !== "none") marks += arrowhead(target, arrival(target, source, straight));
|
|
72
|
-
if (arrow === "both") marks += arrowhead(source, arrival(source, target, straight));
|
|
66
|
+
if (arrow !== "none") marks += arrowhead(target, arrival(target, points.at(-1) ?? source, straight));
|
|
67
|
+
if (arrow === "both") marks += arrowhead(source, arrival(source, points[0] ?? target, straight));
|
|
73
68
|
return {
|
|
74
69
|
...base,
|
|
75
70
|
marks: marks || void 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.js","names":[],"sources":["../../src/whiteboard/connector.ts"],"sourcesContent":["import {\n ArrowEndsIcon,\n ArrowLeftRightIcon,\n ArrowRightIcon,\n ConnectorCurveIcon,\n ConnectorElbowIcon,\n ConnectorStraightIcon,\n LineDashDotIcon,\n LineDashedIcon,\n LineDottedIcon,\n LineSolidIcon,\n LineStyleIcon,\n MinusIcon,\n RouteIcon,\n} from '@dou-ui/icons'\nimport type { Component } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport {
|
|
1
|
+
{"version":3,"file":"connector.js","names":[],"sources":["../../src/whiteboard/connector.ts"],"sourcesContent":["import {\n ArrowEndsIcon,\n ArrowLeftRightIcon,\n ArrowRightIcon,\n ConnectorCurveIcon,\n ConnectorElbowIcon,\n ConnectorStraightIcon,\n LineDashDotIcon,\n LineDashedIcon,\n LineDottedIcon,\n LineSolidIcon,\n LineStyleIcon,\n MinusIcon,\n RouteIcon,\n} from '@dou-ui/icons'\nimport type { Component } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport {\n bezierEdge,\n defineEdgeType,\n stepEdge,\n straightEdge,\n type EdgeAnchor,\n} from '../core/edge-types'\nimport type { FlowToolbarItem } from '../core/menu'\nimport type { FlowEdge, Point, PortSide } from '../core/model'\nimport { format } from '../locale'\nimport type {\n WhiteboardArrow,\n WhiteboardConnectorData,\n WhiteboardDash,\n WhiteboardRoute,\n} from './model'\n\nconst ARROW = { length: 10, spread: 0.45 }\nconst r2 = (v: number) => Math.round(v * 100) / 100\nconst p = (pt: Point) => `${r2(pt.x)} ${r2(pt.y)}`\n\n/** Out of a side, away from the node. */\nconst outward: Record<PortSide, Point> = {\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n bottom: { x: 0, y: 1 },\n}\n\n/** An open arrowhead with its tip at `tip`, pointing along `angle`. */\nfunction arrowhead(tip: Point, angle: number) {\n const wing = (spread: number) => ({\n x: tip.x - ARROW.length * Math.cos(angle + spread),\n y: tip.y - ARROW.length * Math.sin(angle + spread),\n })\n return `M${p(wing(ARROW.spread))}L${p(tip)}L${p(wing(-ARROW.spread))}`\n}\n\n/** The way a run arrives at `end`: straight from `from`, or into the side it faces. */\nfunction arrival(end: EdgeAnchor, from: Point, straight: boolean) {\n if (straight) return Math.atan2(end.y - from.y, end.x - from.x)\n const out = outward[end.side]\n return Math.atan2(-out.y, -out.x)\n}\n\n/** Dash patterns, in px of a 1.5px stroke with round ends: a 0 dash is a dot. */\nconst DASHES: Record<WhiteboardDash, string | undefined> = {\n solid: undefined,\n dashed: '6 5',\n dotted: '0 4',\n 'dash-dot': '8 4 0 4',\n}\n\n/**\n * The whiteboard's line: straight, with right-angled turns or curved\n * (`data.route`), solid or dashed (`data.dash`), with arrowheads at the end,\n * both ends or neither (`data.arrow`).\n */\nexport const connectorEdge = defineEdgeType<WhiteboardConnectorData>({\n type: 'connector',\n route(source, target, edge) {\n const data = edge?.data ?? {}\n const route = data.route ?? 'straight'\n const straight = route === 'straight'\n // Tidying lays points between the nodes in the way of a long connector.\n const points = edge?.points ?? []\n const base = straight\n ? straightEdge.route(source, target, edge as FlowEdge)\n : (route === 'elbow' ? stepEdge : bezierEdge).route(source, target, edge as FlowEdge)\n const arrow = data.arrow ?? 'end'\n let marks = ''\n if (arrow !== 'none')\n marks += arrowhead(target, arrival(target, points.at(-1) ?? source, straight))\n if (arrow === 'both') marks += arrowhead(source, arrival(source, points[0] ?? target, straight))\n return { ...base, marks: marks || undefined }\n },\n style(edge) {\n const dash = DASHES[edge.data?.dash ?? 'solid']\n return dash ? { strokeDasharray: dash } : undefined\n },\n})\n\nconst ROUTES: { value: WhiteboardRoute; icon: Component }[] = [\n { value: 'straight', icon: ConnectorStraightIcon },\n { value: 'elbow', icon: ConnectorElbowIcon },\n { value: 'curve', icon: ConnectorCurveIcon },\n]\nconst DASH_CHOICES: { value: WhiteboardDash; icon: Component }[] = [\n { value: 'solid', icon: LineSolidIcon },\n { value: 'dashed', icon: LineDashedIcon },\n { value: 'dotted', icon: LineDottedIcon },\n { value: 'dash-dot', icon: LineDashDotIcon },\n]\nconst ARROWS: { value: WhiteboardArrow; icon: Component }[] = [\n { value: 'none', icon: MinusIcon },\n { value: 'end', icon: ArrowRightIcon },\n { value: 'both', icon: ArrowLeftRightIcon },\n]\n\nconst data = (edge: FlowEdge) => (edge.data ?? {}) as WhiteboardConnectorData\nconst isConnector = (edge: FlowEdge) => (edge.type ?? 'connector') === 'connector'\n\n/** Route, dash and arrow choices over the selected connectors. */\nexport function connectorToolbar(ctx: FlowEditorContext, edges: FlowEdge[]): FlowToolbarItem[] {\n if (!edges.every(isConnector)) return []\n const t = ctx.messages.value.board\n\n /**\n * One button: its label and icon say the value in use, or that the\n * selected connectors differ; its menu sets one value on all of them.\n */\n function choice<V extends string>(\n key: 'route' | 'dash' | 'arrow',\n fallback: V,\n options: { value: V; icon: Component }[],\n names: Record<V, string>,\n text: { of: string; set: string },\n mixedIcon: Component,\n ): FlowToolbarItem {\n const values = new Set(edges.map((edge) => (data(edge)[key] as V | undefined) ?? fallback))\n const only = values.size === 1 ? [...values][0]! : null\n return {\n key,\n label: format(text.of, { value: only ? names[only] : t.mixed }),\n icon: only ? options.find((item) => item.value === only)!.icon : mixedIcon,\n children: options.map((item) => ({\n key: `${key}-${item.value}`,\n label: names[item.value],\n icon: item.icon,\n checked: item.value === only,\n run() {\n ctx.transact((tr) => {\n for (const edge of edges)\n tr.updateEdge(edge.id, { data: { ...edge.data, [key]: item.value } })\n })\n ctx.announce(format(text.set, { value: names[item.value] }))\n },\n })),\n }\n }\n\n return [\n choice('route', 'straight', ROUTES, t.routes, { of: t.routeOf, set: t.routeSet }, RouteIcon),\n choice(\n 'dash',\n 'solid',\n DASH_CHOICES,\n t.dashes,\n { of: t.dashOf, set: t.dashSet },\n LineStyleIcon,\n ),\n choice('arrow', 'end', ARROWS, t.arrows, { of: t.arrowOf, set: t.arrowSet }, ArrowEndsIcon),\n ]\n}\n"],"mappings":";;;;AAkCA,IAAM,QAAQ;CAAE,QAAQ;CAAI,QAAQ;AAAK;AACzC,IAAM,MAAM,MAAc,KAAK,MAAM,IAAI,GAAG,IAAI;AAChD,IAAM,KAAK,OAAc,GAAG,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;;AAG/C,IAAM,UAAmC;CACvC,MAAM;EAAE,GAAG;EAAI,GAAG;CAAE;CACpB,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;CACpB,KAAK;EAAE,GAAG;EAAG,GAAG;CAAG;CACnB,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;AACvB;;AAGA,SAAS,UAAU,KAAY,OAAe;CAC5C,MAAM,QAAQ,YAAoB;EAChC,GAAG,IAAI,IAAI,MAAM,SAAS,KAAK,IAAI,QAAQ,MAAM;EACjD,GAAG,IAAI,IAAI,MAAM,SAAS,KAAK,IAAI,QAAQ,MAAM;CACnD;CACA,OAAO,IAAI,EAAE,KAAK,MAAM,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,MAAM,MAAM,CAAC;AACrE;;AAGA,SAAS,QAAQ,KAAiB,MAAa,UAAmB;CAChE,IAAI,UAAU,OAAO,KAAK,MAAM,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,CAAC;CAC9D,MAAM,MAAM,QAAQ,IAAI;CACxB,OAAO,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC;AAClC;;AAGA,IAAM,SAAqD;CACzD,OAAO,KAAA;CACP,QAAQ;CACR,QAAQ;CACR,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AS,OAAO,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,aAAa;CAC5F;AACF"}
|
package/dist/whiteboard/image.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { format } from "../locale.js";
|
|
2
2
|
import { boardState } from "./state.js";
|
|
3
|
+
import { toast } from "dou-ui";
|
|
3
4
|
// src/whiteboard/image.ts
|
|
4
5
|
/** Without an upload, images are kept in the document as data URLs. */
|
|
5
6
|
var readAsDataUrl = (file) => new Promise((resolve, reject) => {
|
|
@@ -31,6 +32,7 @@ var imageFiles = (files) => [...files ?? []].filter((file) => file.type.startsWi
|
|
|
31
32
|
async function insertImages(ctx, files, options = {}) {
|
|
32
33
|
const state = boardState(ctx);
|
|
33
34
|
const upload = options.upload ?? state.upload ?? readAsDataUrl;
|
|
35
|
+
const onUploadError = options.onUploadError ?? state.onUploadError;
|
|
34
36
|
const at = options.at;
|
|
35
37
|
const t = ctx.messages.value.board;
|
|
36
38
|
const root = ctx.root.value;
|
|
@@ -42,19 +44,27 @@ async function insertImages(ctx, files, options = {}) {
|
|
|
42
44
|
});
|
|
43
45
|
state.uploading.value += files.length;
|
|
44
46
|
const ids = [];
|
|
47
|
+
const failed = [];
|
|
45
48
|
try {
|
|
46
49
|
await Promise.all(files.map(async (file, i) => {
|
|
47
50
|
let src;
|
|
48
51
|
let alt = file.name.replace(/\.[^.]+$/, "");
|
|
49
52
|
try {
|
|
50
53
|
const done = await upload(file);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
src
|
|
54
|
-
|
|
54
|
+
const given = typeof done === "string" ? done : done?.src;
|
|
55
|
+
if (typeof given !== "string" || !given) {
|
|
56
|
+
if (process.env.NODE_ENV !== "production") console.warn(`[@dou-ui/flow] upload returned no src for "${file.name}"; return a URL or { src, alt }`);
|
|
57
|
+
throw new Error("[@dou-ui/flow] upload returned no src");
|
|
58
|
+
}
|
|
59
|
+
src = given;
|
|
60
|
+
if (typeof done === "object" && done.alt !== void 0) alt = done.alt;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
failed.push(file);
|
|
63
|
+
try {
|
|
64
|
+
onUploadError?.(file, error);
|
|
65
|
+
} catch (thrown) {
|
|
66
|
+
console.error("[@dou-ui/flow] onUploadError threw", thrown);
|
|
55
67
|
}
|
|
56
|
-
} catch {
|
|
57
|
-
ctx.announce(format(t.imageFailed, { name: file.name }));
|
|
58
68
|
return;
|
|
59
69
|
}
|
|
60
70
|
const size = await naturalSize(src) ?? {
|
|
@@ -82,6 +92,7 @@ async function insertImages(ctx, files, options = {}) {
|
|
|
82
92
|
} finally {
|
|
83
93
|
state.uploading.value -= files.length;
|
|
84
94
|
}
|
|
95
|
+
if (failed.length && !onUploadError) toast.danger(failed.length === 1 ? format(t.imageFailed, { name: failed[0].name }) : format(t.imagesFailed, { count: failed.length }), { placement: "bottom" });
|
|
85
96
|
if (ids.length > 1) ctx.selection.value = {
|
|
86
97
|
nodes: ids,
|
|
87
98
|
edges: []
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","names":[],"sources":["../../src/whiteboard/image.ts"],"sourcesContent":["import type { FlowEditorContext } from '../context'\nimport type { Point } from '../core/model'\nimport { format } from '../locale'\nimport { boardState } from './state'\n\n/**\n * Turns a file into the `src` an image node keeps, e.g. by uploading it.\n * Return `{ src, alt }` to give the image its description; it is the file's\n * name otherwise.\n */\nexport type WhiteboardUpload = (file: File) => WhiteboardUploaded | Promise<WhiteboardUploaded>\n\n/** An image's address, or its address and description. */\nexport type WhiteboardUploaded = string | { src: string; alt?: string }\n\nexport interface WhiteboardImageOptions {\n /** Where the images go, in canvas units; the middle of the view by default. */\n at?: Point\n /** Overrides the kit's `upload` option for these images. */\n upload?: WhiteboardUpload\n}\n\n/** Without an upload, images are kept in the document as data URLs. */\nconst readAsDataUrl: WhiteboardUpload = (file) =>\n new Promise((resolve, reject) => {\n const reader = new FileReader()\n reader.addEventListener('load', () => resolve(String(reader.result)))\n reader.addEventListener('error', () => reject(reader.error))\n reader.readAsDataURL(file)\n })\n\n/** An image's own size, or `null` when it can't be loaded. */\nfunction naturalSize(src: string): Promise<{ width: number; height: number } | null> {\n return new Promise((resolve) => {\n const img = new Image()\n img.addEventListener('load', () =>\n resolve({ width: img.naturalWidth, height: img.naturalHeight }),\n )\n img.addEventListener('error', () => resolve(null))\n // an image that never answers gets the default size\n setTimeout(() => resolve(null), 4000)\n img.src = src\n })\n}\n\n/** New images are at most this wide or tall, in canvas units. */\nconst MAX_SIDE = 320\n\nexport const imageFiles = (files: Iterable<File> | null | undefined) =>\n [...(files ?? [])].filter((file) => file.type.startsWith('image/'))\n\n/**\n * Adds an image node for each file, centred on `at` and stepped down and\n * right when there are several. Files go through the kit's `upload` option.\n */\nexport async function insertImages(\n ctx: FlowEditorContext,\n files: File[],\n options: WhiteboardImageOptions = {},\n) {\n const state = boardState(ctx)\n const upload = options.upload ?? state.upload ?? readAsDataUrl\n const at = options.at\n const t = ctx.messages.value.board\n const root = ctx.root.value\n if (!root || ctx.readonly.value) return\n const box = root.getBoundingClientRect()\n const centre = at ?? ctx.toCanvas({ x: box.left + box.width / 2, y: box.top + box.height / 2 })\n state.uploading.value += files.length\n const ids: string[] = []\n try {\n await Promise.all(\n files.map(async (file, i) => {\n let src: string\n let alt = file.name.replace(/\\.[^.]+$/, '')\n try {\n const done = await upload(file)\n
|
|
1
|
+
{"version":3,"file":"image.js","names":[],"sources":["../../src/whiteboard/image.ts"],"sourcesContent":["import { toast } from 'dou-ui'\nimport type { FlowEditorContext } from '../context'\nimport type { Point } from '../core/model'\nimport { format } from '../locale'\nimport { boardState } from './state'\n\n/**\n * Turns a file into the `src` an image node keeps, e.g. by uploading it.\n * Return `{ src, alt }` to give the image its description; it is the file's\n * name otherwise.\n */\nexport type WhiteboardUpload = (file: File) => WhiteboardUploaded | Promise<WhiteboardUploaded>\n\n/** An image's address, or its address and description. */\nexport type WhiteboardUploaded = string | { src: string; alt?: string }\n\n/**\n * Called for each image whose upload threw or rejected, with the file and\n * what it threw. Giving it replaces the built-in error toast, and the app\n * then tells the user, screen readers included, in its own way.\n */\nexport type WhiteboardUploadErrorHandler = (file: File, error: unknown) => void\n\nexport interface WhiteboardImageOptions {\n /** Where the images go, in canvas units; the middle of the view by default. */\n at?: Point\n /** Overrides the kit's `upload` option for these images. */\n upload?: WhiteboardUpload\n /** Overrides the kit's `onUploadError` option for these images. */\n onUploadError?: WhiteboardUploadErrorHandler\n}\n\n/** Without an upload, images are kept in the document as data URLs. */\nconst readAsDataUrl: WhiteboardUpload = (file) =>\n new Promise((resolve, reject) => {\n const reader = new FileReader()\n reader.addEventListener('load', () => resolve(String(reader.result)))\n reader.addEventListener('error', () => reject(reader.error))\n reader.readAsDataURL(file)\n })\n\n/** An image's own size, or `null` when it can't be loaded. */\nfunction naturalSize(src: string): Promise<{ width: number; height: number } | null> {\n return new Promise((resolve) => {\n const img = new Image()\n img.addEventListener('load', () =>\n resolve({ width: img.naturalWidth, height: img.naturalHeight }),\n )\n img.addEventListener('error', () => resolve(null))\n // an image that never answers gets the default size\n setTimeout(() => resolve(null), 4000)\n img.src = src\n })\n}\n\n/** New images are at most this wide or tall, in canvas units. */\nconst MAX_SIDE = 320\n\nexport const imageFiles = (files: Iterable<File> | null | undefined) =>\n [...(files ?? [])].filter((file) => file.type.startsWith('image/'))\n\n/**\n * Adds an image node for each file, centred on `at` and stepped down and\n * right when there are several. Files go through the kit's `upload` option.\n */\nexport async function insertImages(\n ctx: FlowEditorContext,\n files: File[],\n options: WhiteboardImageOptions = {},\n) {\n const state = boardState(ctx)\n const upload = options.upload ?? state.upload ?? readAsDataUrl\n const onUploadError = options.onUploadError ?? state.onUploadError\n const at = options.at\n const t = ctx.messages.value.board\n const root = ctx.root.value\n if (!root || ctx.readonly.value) return\n const box = root.getBoundingClientRect()\n const centre = at ?? ctx.toCanvas({ x: box.left + box.width / 2, y: box.top + box.height / 2 })\n state.uploading.value += files.length\n const ids: string[] = []\n const failed: File[] = []\n try {\n await Promise.all(\n files.map(async (file, i) => {\n let src: string\n let alt = file.name.replace(/\\.[^.]+$/, '')\n try {\n const done = await upload(file)\n const given = typeof done === 'string' ? done : done?.src\n if (typeof given !== 'string' || !given) {\n // a broken image would go in otherwise\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[@dou-ui/flow] upload returned no src for \"${file.name}\"; return a URL or { src, alt }`,\n )\n }\n throw new Error('[@dou-ui/flow] upload returned no src')\n }\n src = given\n if (typeof done === 'object' && done.alt !== undefined) alt = done.alt\n } catch (error) {\n failed.push(file)\n try {\n onUploadError?.(file, error)\n } catch (thrown) {\n // the other images still go in\n console.error('[@dou-ui/flow] onUploadError threw', thrown)\n }\n return\n }\n const size = (await naturalSize(src)) ?? { width: MAX_SIDE, height: MAX_SIDE * 0.75 }\n const scale = Math.min(1, MAX_SIDE / Math.max(size.width, size.height))\n const id = ctx.insertNode('image', {\n at: { x: centre.x + i * 24, y: centre.y + i * 24 },\n data: { src, alt },\n size: { width: Math.round(size.width * scale), height: Math.round(size.height * scale) },\n focus: false,\n })\n if (id) ids.push(id)\n }),\n )\n } finally {\n state.uploading.value -= files.length\n }\n // one toast for the whole drop; it is an alert, so screen readers hear it\n // too. At the bottom, so it never covers the board's toolbar for a retry.\n if (failed.length && !onUploadError) {\n toast.danger(\n failed.length === 1\n ? format(t.imageFailed, { name: failed[0]!.name })\n : format(t.imagesFailed, { count: failed.length }),\n { placement: 'bottom' },\n )\n }\n if (ids.length > 1) ctx.selection.value = { nodes: ids, edges: [] }\n}\n\n/** Opens the file picker and inserts what is picked, as `insertImages` does. */\nexport function pickImages(ctx: FlowEditorContext, options: WhiteboardImageOptions = {}) {\n const input = document.createElement('input')\n input.type = 'file'\n input.accept = 'image/*'\n input.multiple = true\n input.addEventListener('change', () => {\n const files = imageFiles(input.files)\n if (files.length) void insertImages(ctx, files, options)\n })\n input.click()\n}\n"],"mappings":";;;;;AAiCA,IAAM,iBAAmC,SACvC,IAAI,SAA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,cAAc,EAAE,OAAO,OAAO,OAAO,CAAC,GACnD,EAAE,WAAW,SAAS,CACxB;CAEF,IAAI,IAAI,SAAS,GAAG,IAAI,UAAU,QAAQ;EAAE,OAAO;EAAK,OAAO,CAAC;CAAE;AACpE;;AAGA,SAAgB,WAAW,KAAwB,UAAkC,CAAC,GAAG;CACvF,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,OAAO;CACb,MAAM,SAAS;CACf,MAAM,WAAW;CACjB,MAAM,iBAAiB,gBAAgB;EACrC,MAAM,QAAQ,WAAW,MAAM,KAAK;EACpC,IAAI,MAAM,QAAQ,aAAkB,KAAK,OAAO,OAAO;CACzD,CAAC;CACD,MAAM,MAAM;AACd"}
|
package/dist/whiteboard/kit.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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 {
|
|
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";
|
|
@@ -33,7 +34,7 @@ var turnedBy = (node) => node.data?.rotation ?? 0;
|
|
|
33
34
|
var shapeNode = defineNodeType({
|
|
34
35
|
type: "shape",
|
|
35
36
|
component: board_node_default,
|
|
36
|
-
ports:
|
|
37
|
+
ports: "sides",
|
|
37
38
|
frame: false,
|
|
38
39
|
resizable: {
|
|
39
40
|
minWidth: 24,
|
|
@@ -52,7 +53,7 @@ var shapeNode = defineNodeType({
|
|
|
52
53
|
var stickyNode = defineNodeType({
|
|
53
54
|
type: "sticky",
|
|
54
55
|
component: board_node_default,
|
|
55
|
-
ports:
|
|
56
|
+
ports: "sides",
|
|
56
57
|
frame: false,
|
|
57
58
|
resizable: {
|
|
58
59
|
minWidth: 64,
|
|
@@ -71,7 +72,7 @@ var stickyNode = defineNodeType({
|
|
|
71
72
|
var textNode = defineNodeType({
|
|
72
73
|
type: "text",
|
|
73
74
|
component: board_node_default,
|
|
74
|
-
ports:
|
|
75
|
+
ports: "sides",
|
|
75
76
|
frame: false,
|
|
76
77
|
resizable: {
|
|
77
78
|
minWidth: 24,
|
|
@@ -107,7 +108,7 @@ var inkNode = defineNodeType({
|
|
|
107
108
|
var imageNode = defineNodeType({
|
|
108
109
|
type: "image",
|
|
109
110
|
component: board_node_default,
|
|
110
|
-
ports:
|
|
111
|
+
ports: "sides",
|
|
111
112
|
frame: false,
|
|
112
113
|
resizable: {
|
|
113
114
|
minWidth: 24,
|
|
@@ -166,6 +167,51 @@ var SIZES = {
|
|
|
166
167
|
height: 40
|
|
167
168
|
}
|
|
168
169
|
};
|
|
170
|
+
/**
|
|
171
|
+
* The comment tool: a click on a node starts a thread pinned where it was
|
|
172
|
+
* clicked, the point turned back with the node. A press on the empty canvas
|
|
173
|
+
* does nothing; a mouse drag does nothing either, so a thread isn't started
|
|
174
|
+
* by mistake, while a finger's drag moves the view, as it does elsewhere.
|
|
175
|
+
*/
|
|
176
|
+
function pinComment(ctx, node, start, event) {
|
|
177
|
+
const client = {
|
|
178
|
+
x: event.clientX,
|
|
179
|
+
y: event.clientY
|
|
180
|
+
};
|
|
181
|
+
const origin = { ...ctx.viewport.value };
|
|
182
|
+
const finger = event.pointerType !== "mouse";
|
|
183
|
+
let moved = false;
|
|
184
|
+
return {
|
|
185
|
+
move(_, move) {
|
|
186
|
+
const dx = move.clientX - client.x;
|
|
187
|
+
const dy = move.clientY - client.y;
|
|
188
|
+
if (!moved && Math.hypot(dx, dy) <= 8) return;
|
|
189
|
+
moved = true;
|
|
190
|
+
if (finger) ctx.setViewport({
|
|
191
|
+
...origin,
|
|
192
|
+
x: origin.x + dx,
|
|
193
|
+
y: origin.y + dy
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
end() {
|
|
197
|
+
const rect = node && !moved ? ctx.getNodeRect(node) : null;
|
|
198
|
+
if (!node || !rect || !rect.width || !rect.height) return;
|
|
199
|
+
const centre = {
|
|
200
|
+
x: rect.x + rect.width / 2,
|
|
201
|
+
y: rect.y + rect.height / 2
|
|
202
|
+
};
|
|
203
|
+
const local = turn(start, centre, -ctx.nodeRotation(node));
|
|
204
|
+
const at = {
|
|
205
|
+
x: (local.x - rect.x) / rect.width,
|
|
206
|
+
y: (local.y - rect.y) / rect.height
|
|
207
|
+
};
|
|
208
|
+
ctx.comment({
|
|
209
|
+
node,
|
|
210
|
+
at
|
|
211
|
+
}, { focus: !finger });
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
169
215
|
/** After a tool put down a node: back to select unless kept, and notes and text open to be written in. */
|
|
170
216
|
function added(ctx, tool, id) {
|
|
171
217
|
const state = boardState(ctx);
|
|
@@ -194,12 +240,14 @@ function whiteboardKit(options = {}) {
|
|
|
194
240
|
setup(ctx) {
|
|
195
241
|
const state = boardState(ctx);
|
|
196
242
|
state.upload = options.upload;
|
|
243
|
+
state.onUploadError = options.onUploadError;
|
|
197
244
|
const stops = [];
|
|
198
245
|
if (options.tool) {
|
|
199
246
|
const outer = options.tool;
|
|
200
247
|
state.tool.value = outer.value;
|
|
201
248
|
stops.push(watch(outer, (tool) => state.tool.value = tool), watch(state.tool, (tool) => outer.value = tool));
|
|
202
249
|
}
|
|
250
|
+
stops.push(watch(() => usable(ctx, state.tool.value), (ok) => !ok && (state.tool.value = "select"), { immediate: true }));
|
|
203
251
|
stops.push(watch(state.tool, (tool) => {
|
|
204
252
|
const root = ctx.root.value;
|
|
205
253
|
if (root) root.dataset.boardTool = tool;
|
|
@@ -249,6 +297,8 @@ function whiteboardKit(options = {}) {
|
|
|
249
297
|
const state = boardState(ctx);
|
|
250
298
|
const tool = state.tool.value;
|
|
251
299
|
if (tool === "select") return;
|
|
300
|
+
if (ctx.readonly.value && tool !== "hand" && tool !== "comment") return;
|
|
301
|
+
if (tool === "comment") return pinComment(ctx, press.node?.id ?? null, press.point, press.event);
|
|
252
302
|
state.editing.value = null;
|
|
253
303
|
if (tool === "hand") {
|
|
254
304
|
const start = {
|
|
@@ -352,6 +402,7 @@ function whiteboardKit(options = {}) {
|
|
|
352
402
|
keymap(ctx) {
|
|
353
403
|
const state = boardState(ctx);
|
|
354
404
|
const pick = (tool) => () => {
|
|
405
|
+
if (!usable(ctx, tool)) return false;
|
|
355
406
|
state.tool.value = tool;
|
|
356
407
|
state.locked.value = false;
|
|
357
408
|
const t = ctx.messages.value.board;
|
|
@@ -366,8 +417,13 @@ function whiteboardKit(options = {}) {
|
|
|
366
417
|
pickImages(ctx);
|
|
367
418
|
},
|
|
368
419
|
enter: () => {
|
|
369
|
-
if (ctx.readonly.value) return false;
|
|
370
420
|
const tool = state.tool.value;
|
|
421
|
+
if (tool === "comment") {
|
|
422
|
+
const { nodes, edges } = ctx.selection.value;
|
|
423
|
+
if (nodes.length !== 1 || edges.length) return false;
|
|
424
|
+
return ctx.comment({ node: nodes[0] }) || false;
|
|
425
|
+
}
|
|
426
|
+
if (ctx.readonly.value) return false;
|
|
371
427
|
if (tool !== "select" && tool !== "hand" && tool !== "pen" && tool !== "eraser") {
|
|
372
428
|
const { type, data } = kindOf(tool);
|
|
373
429
|
const size = tool === "text" ? {
|