@widgetic/canvas 0.5.44 → 0.5.46
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/README.md +1 -1
- package/dist/canvas/DomCanvas.svelte +52 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
- package/dist/canvas/host/CanvasHost.d.ts +74 -3
- package/dist/canvas/host/CanvasHost.js +278 -16
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +9 -1
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +139 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +58 -0
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
- package/dist/canvas/ui/SelectionPanel.svelte +78 -17
- package/dist/canvas/ui/ShapesMenu.svelte +65 -31
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
- package/dist/canvas/ui/ToolButton.svelte +34 -55
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +26 -4
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +26 -1
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
- package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
- package/dist/canvas/view/CanvasStage.svelte +7 -2
- package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
- package/dist/canvas/view/SelectionOverlay.svelte +17 -10
- package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +1 -1
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +129 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +15 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/engine/EngineCore.d.ts +46 -4
- package/dist/engine/EngineCore.js +85 -16
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +25 -2
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +24 -12
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +10 -3
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +10 -6
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +10 -2
- package/dist/engine/core/cameraMove.d.ts +6 -0
- package/dist/engine/core/cameraMove.js +6 -0
- package/dist/engine/core/defaults.js +2 -0
- package/dist/engine/core/scene.d.ts +22 -0
- package/dist/engine/core/scene.js +86 -1
- package/dist/engine/core/style.d.ts +10 -0
- package/dist/engine/core/style.js +19 -3
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +9 -0
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +70 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +41 -10
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +100 -5
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +10 -0
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +44 -29
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +6 -0
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +16 -12
- package/dist/index.d.ts +2 -1
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +138 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +226 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +89 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +122 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +14 -0
- package/dist/settings/workspaceToolSettings.js +21 -10
- package/dist/tools/definitions.js +26 -4
- package/dist/tools/executors.js +81 -5
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +2 -0
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +91 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The drawing toolbar as it stands before the canvas is there.
|
|
3
|
+
|
|
4
|
+
The toolbar is the same every time: the same tools, in the same order, in the same place, and the tool that is on is the one the
|
|
5
|
+
board opens with: the tool the person had last in this workspace, else the pencil (a board that shows the drawing tools opens ready
|
|
6
|
+
for a sketch). `CanvasHost.#start` and this file take it from the same rule (`settings/rememberedTool.ts`), from the same storage, so
|
|
7
|
+
a refresh does not show the pencil for a moment and then Select. Nothing else about it needs the saved board, so it does not have
|
|
8
|
+
to wait for the canvas code (the biggest chunk of the page) to be downloaded: a host draws this look-alike next to its empty board,
|
|
9
|
+
at first paint, and the real toolbar takes its place when the canvas mounts, in the same spot and at the same size, so the swap is
|
|
10
|
+
not seen.
|
|
11
|
+
|
|
12
|
+
It is only a picture: no tooltips, no menu, no handlers, and it is hidden from the accessibility tree and the tab order (the real
|
|
13
|
+
toolbar, which has them all, follows within a moment). It is drawn at the 60% of the chrome of a board that is still loading (the
|
|
14
|
+
canvas dims its toolbar the same way while its data comes in), so it does not brighten at the hand-over and dim again.
|
|
15
|
+
|
|
16
|
+
It is made of the same parts as the real one (`floatingCard.ts`, `chromeLayout.ts`, the same icons and the design system's Icon
|
|
17
|
+
Button) and `tests/ui/toolbarPlaceholder.test.mjs` holds the two together: the tools, their order, the sizes and the
|
|
18
|
+
place. When the toolbar changes, change this file with it (the test says what drifted).
|
|
19
|
+
|
|
20
|
+
The placement classes come from `chromeLayout.ts`, so the toolbar is where `toolbarPosition` says. It fills the board it is in: put it in
|
|
21
|
+
a positioned element that has the size of the board.
|
|
22
|
+
-->
|
|
23
|
+
<script lang="ts">
|
|
24
|
+
import { IconButton, Separator } from '@widgetic/design-system/components';
|
|
25
|
+
import { chromeSlots, isSideAnchor } from '../canvas/chromeLayout.js';
|
|
26
|
+
import { normalizeToolbarPosition } from '../canvas/toolbarPosition.js';
|
|
27
|
+
import { SHAPE_TOOL_IDS, firstToolOfBoard } from '../settings/rememberedTool.js';
|
|
28
|
+
import { FLOATING_CARD_CLASSES, TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES, TOOLBAR_ICON_STROKE_CLASSES } from '../canvas/ui/floatingCard.js';
|
|
29
|
+
import {
|
|
30
|
+
IconArrowBackUp,
|
|
31
|
+
IconArrowForwardUp,
|
|
32
|
+
IconArrowUpRight,
|
|
33
|
+
IconCategory,
|
|
34
|
+
IconChevronDown,
|
|
35
|
+
IconEraser,
|
|
36
|
+
IconPencil,
|
|
37
|
+
IconPointer,
|
|
38
|
+
IconTypography
|
|
39
|
+
} from '../canvas/ui/icons.js';
|
|
40
|
+
|
|
41
|
+
interface Props {
|
|
42
|
+
/** Where the toolbar stands: one of the eight places of `toolbarPosition` (anything else is the bottom centre, as in the canvas). */
|
|
43
|
+
toolbarPosition?: string | null;
|
|
44
|
+
/** The same option the canvas has: false draws nothing, as the canvas draws no toolbar then. */
|
|
45
|
+
showDrawingTools?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The workspace and the person the canvas is given (its `workspaceId` and `userId`): where the tool that was last chosen is kept.
|
|
48
|
+
* Without a workspace nothing is kept, and the pencil is the tool that is on, as for a board where none was chosen yet.
|
|
49
|
+
*/
|
|
50
|
+
workspaceId?: string | null;
|
|
51
|
+
userId?: string | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let { toolbarPosition = null, showDrawingTools = true, workspaceId = null, userId = null }: Props = $props();
|
|
55
|
+
|
|
56
|
+
const anchor = $derived(normalizeToolbarPosition(toolbarPosition));
|
|
57
|
+
const vertical = $derived(isSideAnchor(anchor));
|
|
58
|
+
// The slot the canvas would put the toolbar in: its place on the board and the layout of what is inside it.
|
|
59
|
+
const slotClasses = $derived(chromeSlots(anchor, anchor, { toolbar: showDrawingTools, zoom: false })[0]?.classes ?? null);
|
|
60
|
+
|
|
61
|
+
// The tools, in the order of the canvas's toolbar.
|
|
62
|
+
const tools = [IconPointer, IconPencil, IconEraser, IconArrowUpRight, IconTypography];
|
|
63
|
+
// The tool in use when the board opens: the one the person had last in this workspace, else the pencil (this card is not drawn at all
|
|
64
|
+
// without the drawing tools). The canvas chooses it by the same rule; one of the shapes lights the Shapes button instead of a tool.
|
|
65
|
+
const openingTool = $derived(firstToolOfBoard({ workspaceId, userId, showDrawingTools }));
|
|
66
|
+
const toolIcons: Record<string, typeof IconPencil | undefined> = { select: IconPointer, draw: IconPencil, erase: IconEraser, arrow: IconArrowUpRight, text: IconTypography };
|
|
67
|
+
const activeToolIcon = $derived(toolIcons[openingTool] ?? null);
|
|
68
|
+
const shapeIsActive = $derived((SHAPE_TOOL_IDS as readonly string[]).includes(openingTool));
|
|
69
|
+
|
|
70
|
+
// Written out in full, as `ToolButton.svelte` does, so that the stylesheet of a page that installs the canvas picks every class up.
|
|
71
|
+
const TOOL_BUTTON_CLASSES = `size-9 data-[active]:bg-brand-subtle data-[active]:text-foreground ${TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} pointer-events-none`;
|
|
72
|
+
// The Shapes menu's button, as `ShapesMenu.svelte` draws it (the brand tint is for a shape being the tool: `data-active`, below).
|
|
73
|
+
const SHAPES_BUTTON_CLASSES = 'flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground data-[active]:bg-brand-subtle [&_svg]:size-4';
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
{#if slotClasses}
|
|
77
|
+
<!-- `@container`: the history group leaves a board narrower than 384 px, as it does in the canvas (see the style below). -->
|
|
78
|
+
<div
|
|
79
|
+
class="canvas-toolbar-placeholder-root pointer-events-none absolute inset-0 z-10 @container opacity-60"
|
|
80
|
+
data-canvas-toolbar-placeholder
|
|
81
|
+
aria-hidden="true"
|
|
82
|
+
inert
|
|
83
|
+
>
|
|
84
|
+
<div class={slotClasses}>
|
|
85
|
+
<div
|
|
86
|
+
class="canvas-toolbar-placeholder-card flex items-center gap-1 {vertical ? 'max-h-full flex-col overflow-y-auto' : 'max-w-full'} {FLOATING_CARD_CLASSES} {TOOLBAR_ICON_STROKE_CLASSES} [&_svg]:size-4"
|
|
87
|
+
>
|
|
88
|
+
{#each tools as Tool, position (position)}
|
|
89
|
+
<IconButton label="" tabindex={-1} data-active={Tool === activeToolIcon ? '' : undefined} class={TOOL_BUTTON_CLASSES}>
|
|
90
|
+
<Tool />
|
|
91
|
+
</IconButton>
|
|
92
|
+
{/each}
|
|
93
|
+
|
|
94
|
+
<Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
|
|
95
|
+
|
|
96
|
+
<div class={SHAPES_BUTTON_CLASSES} data-active={shapeIsActive ? '' : undefined}>
|
|
97
|
+
<IconCategory />
|
|
98
|
+
<IconChevronDown />
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
<div class="canvas-toolbar-placeholder-history items-center gap-1 {vertical ? 'flex flex-col is-upright' : ''}">
|
|
102
|
+
<Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
|
|
103
|
+
<!-- Nothing has been done yet, so there is nothing to undo or redo: both are dimmed, as the canvas dims them. -->
|
|
104
|
+
<IconButton label="" tabindex={-1} disabled class="size-9">
|
|
105
|
+
<IconArrowBackUp class="rtl:-scale-x-100" />
|
|
106
|
+
</IconButton>
|
|
107
|
+
<IconButton label="" tabindex={-1} disabled class="size-9">
|
|
108
|
+
<IconArrowForwardUp class="rtl:-scale-x-100" />
|
|
109
|
+
</IconButton>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
{/if}
|
|
115
|
+
|
|
116
|
+
<style>
|
|
117
|
+
/* The canvas's own rule: the history group is the first thing a board too narrow for the whole bar gives up (Figma's phone). An upright bar keeps it. */
|
|
118
|
+
.canvas-toolbar-placeholder-history {
|
|
119
|
+
display: none;
|
|
120
|
+
}
|
|
121
|
+
.canvas-toolbar-placeholder-history.is-upright {
|
|
122
|
+
display: flex;
|
|
123
|
+
}
|
|
124
|
+
@container (min-width: 384px) {
|
|
125
|
+
.canvas-toolbar-placeholder-history:not(.is-upright) {
|
|
126
|
+
display: flex;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** Where the toolbar stands: one of the eight places of `toolbarPosition` (anything else is the bottom centre, as in the canvas). */
|
|
3
|
+
toolbarPosition?: string | null;
|
|
4
|
+
/** The same option the canvas has: false draws nothing, as the canvas draws no toolbar then. */
|
|
5
|
+
showDrawingTools?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* The workspace and the person the canvas is given (its `workspaceId` and `userId`): where the tool that was last chosen is kept.
|
|
8
|
+
* Without a workspace nothing is kept, and the pencil is the tool that is on, as for a board where none was chosen yet.
|
|
9
|
+
*/
|
|
10
|
+
workspaceId?: string | null;
|
|
11
|
+
userId?: string | null;
|
|
12
|
+
}
|
|
13
|
+
declare const CanvasToolbarPlaceholder: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type CanvasToolbarPlaceholder = ReturnType<typeof CanvasToolbarPlaceholder>;
|
|
15
|
+
export default CanvasToolbarPlaceholder;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the loader of an empty board may first be seen.
|
|
3
|
+
*
|
|
4
|
+
* A board that opens fast (its code and its saved text are already in the browser) should show no loader at all: a spinner
|
|
5
|
+
* that flashes for a tenth of a second reads as a stutter, not as progress. So the loader of a placeholder waits for
|
|
6
|
+
* `BOARD_LOADER_DELAY_MS`, counted from the moment the opening began, and a board that is there before that never shows one.
|
|
7
|
+
*
|
|
8
|
+
* Opening a board draws up to three placeholders, one after the other: the page's own (while the creator downloads), the
|
|
9
|
+
* creator's (while the canvas code downloads) and the canvas's (while its saved text loads). If each counted from its own start,
|
|
10
|
+
* the loader would go away and come back again at every hand-over, and the wait would be three times as long. They share one
|
|
11
|
+
* count instead: the time since the first of them was drawn. The count is kept for `BOARD_LOADER_HANDOVER_MS` after the last one
|
|
12
|
+
* is gone, so that the next one, drawn in the same moment, continues it; after that the next placeholder starts a new opening.
|
|
13
|
+
*
|
|
14
|
+
* The count lives on `globalThis` under a registered symbol, not in this module: the page's placeholder and the creator's can come
|
|
15
|
+
* from two copies of this file (one for each bundle that has it), and two copies would each start their own count.
|
|
16
|
+
*/
|
|
17
|
+
/** How long an opening may take before its loader is first seen, in milliseconds. */
|
|
18
|
+
export declare const BOARD_LOADER_DELAY_MS = 400;
|
|
19
|
+
/** How long after its last placeholder is gone an opening is still the same one, in milliseconds. */
|
|
20
|
+
export declare const BOARD_LOADER_HANDOVER_MS = 300;
|
|
21
|
+
/** One placeholder's place in the opening. */
|
|
22
|
+
export interface BoardLoaderClaim {
|
|
23
|
+
/** How long this placeholder waits before its loader is first seen: what is left of `BOARD_LOADER_DELAY_MS`, never below 0. */
|
|
24
|
+
delayMs: number;
|
|
25
|
+
/** The placeholder is gone. Can be called more than once. */
|
|
26
|
+
release: () => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A placeholder asks when its loader may be seen, and tells when it is gone. `now` is the clock; tests pass their own.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const claim = claimBoardLoader();
|
|
33
|
+
* // show the loader after claim.delayMs
|
|
34
|
+
* claim.release(); // when the placeholder goes away
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function claimBoardLoader(now?: () => number): BoardLoaderClaim;
|
|
38
|
+
/** Forgets the opening of this page. For tests: a page never needs it. */
|
|
39
|
+
export declare function resetBoardLoaderOpening(): void;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the loader of an empty board may first be seen.
|
|
3
|
+
*
|
|
4
|
+
* A board that opens fast (its code and its saved text are already in the browser) should show no loader at all: a spinner
|
|
5
|
+
* that flashes for a tenth of a second reads as a stutter, not as progress. So the loader of a placeholder waits for
|
|
6
|
+
* `BOARD_LOADER_DELAY_MS`, counted from the moment the opening began, and a board that is there before that never shows one.
|
|
7
|
+
*
|
|
8
|
+
* Opening a board draws up to three placeholders, one after the other: the page's own (while the creator downloads), the
|
|
9
|
+
* creator's (while the canvas code downloads) and the canvas's (while its saved text loads). If each counted from its own start,
|
|
10
|
+
* the loader would go away and come back again at every hand-over, and the wait would be three times as long. They share one
|
|
11
|
+
* count instead: the time since the first of them was drawn. The count is kept for `BOARD_LOADER_HANDOVER_MS` after the last one
|
|
12
|
+
* is gone, so that the next one, drawn in the same moment, continues it; after that the next placeholder starts a new opening.
|
|
13
|
+
*
|
|
14
|
+
* The count lives on `globalThis` under a registered symbol, not in this module: the page's placeholder and the creator's can come
|
|
15
|
+
* from two copies of this file (one for each bundle that has it), and two copies would each start their own count.
|
|
16
|
+
*/
|
|
17
|
+
/** How long an opening may take before its loader is first seen, in milliseconds. */
|
|
18
|
+
export const BOARD_LOADER_DELAY_MS = 400;
|
|
19
|
+
/** How long after its last placeholder is gone an opening is still the same one, in milliseconds. */
|
|
20
|
+
export const BOARD_LOADER_HANDOVER_MS = 300;
|
|
21
|
+
const OPENING_KEY = Symbol.for('widgetic.canvas.boardLoaderOpening');
|
|
22
|
+
/** The clock of the page, in milliseconds, that never goes back. */
|
|
23
|
+
function pageClock() {
|
|
24
|
+
return typeof performance !== 'undefined' && typeof performance.now === 'function' ? performance.now() : Date.now();
|
|
25
|
+
}
|
|
26
|
+
/** The one record of this page, made the first time it is asked for. */
|
|
27
|
+
function openingOfPage() {
|
|
28
|
+
const shared = globalThis;
|
|
29
|
+
const existing = shared[OPENING_KEY];
|
|
30
|
+
if (existing)
|
|
31
|
+
return existing;
|
|
32
|
+
const fresh = { openedAt: Number.NEGATIVE_INFINITY, claims: 0, lastReleasedAt: Number.NEGATIVE_INFINITY };
|
|
33
|
+
shared[OPENING_KEY] = fresh;
|
|
34
|
+
return fresh;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A placeholder asks when its loader may be seen, and tells when it is gone. `now` is the clock; tests pass their own.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* const claim = claimBoardLoader();
|
|
41
|
+
* // show the loader after claim.delayMs
|
|
42
|
+
* claim.release(); // when the placeholder goes away
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function claimBoardLoader(now = pageClock) {
|
|
46
|
+
const opening = openingOfPage();
|
|
47
|
+
const claimedAt = now();
|
|
48
|
+
// Nothing is drawn and the last placeholder went a while ago: this is a new opening
|
|
49
|
+
if (opening.claims === 0 && claimedAt - opening.lastReleasedAt > BOARD_LOADER_HANDOVER_MS) {
|
|
50
|
+
opening.openedAt = claimedAt;
|
|
51
|
+
}
|
|
52
|
+
opening.claims += 1;
|
|
53
|
+
const delayMs = Math.max(0, BOARD_LOADER_DELAY_MS - (claimedAt - opening.openedAt));
|
|
54
|
+
let released = false;
|
|
55
|
+
return {
|
|
56
|
+
delayMs,
|
|
57
|
+
release: () => {
|
|
58
|
+
if (released)
|
|
59
|
+
return;
|
|
60
|
+
released = true;
|
|
61
|
+
opening.claims = Math.max(0, opening.claims - 1);
|
|
62
|
+
if (opening.claims === 0)
|
|
63
|
+
opening.lastReleasedAt = now();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Forgets the opening of this page. For tests: a page never needs it. */
|
|
68
|
+
export function resetBoardLoaderOpening() {
|
|
69
|
+
const shared = globalThis;
|
|
70
|
+
delete shared[OPENING_KEY];
|
|
71
|
+
}
|
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { default as Tooltip } from './Tooltip.svelte';
|
|
7
7
|
export { default as CanvasBoardPlaceholder, CANVAS_BOARD_BACKGROUND } from './CanvasBoardPlaceholder.svelte';
|
|
8
|
+
export { default as CanvasToolbarPlaceholder } from './CanvasToolbarPlaceholder.svelte';
|
|
9
|
+
export { default as CanvasBoardPoster } from './CanvasBoardPoster.svelte';
|
|
10
|
+
export { createBoardPoster, parseBoardPoster, boardPostersMatch, BOARD_POSTER_VERSION, BOARD_POSTER_STORAGE_KIND, DEFAULT_POSTER_SURFACE } from '../poster/boardPoster.js';
|
|
11
|
+
export type { BoardPoster, BoardPosterOptions, ParsedBoardPoster } from '../poster/boardPoster.js';
|
|
12
|
+
export type { PosterPictureResolver } from '../poster/posterPictures.js';
|
|
13
|
+
export { BOARD_PLACEMENT_STORAGE_KEY, boardLayoutOf, measureBoardPlacement, rememberBoardPlacement, recallBoardPlacement } from '../poster/boardPlacement.js';
|
|
14
|
+
export type { BoardPlacement, BoardPlacementDetails, BoardLayoutClass } from '../poster/boardPlacement.js';
|
|
8
15
|
export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './preferenceStorage';
|
|
9
16
|
export type { CanvasPreferenceStorage } from './preferenceStorage';
|
|
10
17
|
export { default as ColorIC } from './input-controls/ColorIC.svelte';
|
package/dist/components/index.js
CHANGED
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
export { default as Tooltip } from './Tooltip.svelte';
|
|
8
8
|
// The empty board: shown while the canvas code downloads
|
|
9
9
|
export { default as CanvasBoardPlaceholder, CANVAS_BOARD_BACKGROUND } from './CanvasBoardPlaceholder.svelte';
|
|
10
|
+
// The drawing toolbar as it stands before the canvas is there: a host draws it next to the empty board so the bar is there at first paint
|
|
11
|
+
export { default as CanvasToolbarPlaceholder } from './CanvasToolbarPlaceholder.svelte';
|
|
12
|
+
// The poster of the board: the objects of the saved view, drawn from the first frame while the canvas code is on its way.
|
|
13
|
+
// A host keeps one with `createBoardPoster` at every save, reads it back with `parseBoardPoster`, and draws it with <CanvasBoardPoster>.
|
|
14
|
+
export { default as CanvasBoardPoster } from './CanvasBoardPoster.svelte';
|
|
15
|
+
export { createBoardPoster, parseBoardPoster, boardPostersMatch, BOARD_POSTER_VERSION, BOARD_POSTER_STORAGE_KIND, DEFAULT_POSTER_SURFACE } from '../poster/boardPoster.js';
|
|
16
|
+
// Where the board stands in its host's page, remembered so the next visit draws the poster and the toolbar in place at first paint
|
|
17
|
+
export { BOARD_PLACEMENT_STORAGE_KEY, boardLayoutOf, measureBoardPlacement, rememberBoardPlacement, recallBoardPlacement } from '../poster/boardPlacement.js';
|
|
10
18
|
// Where the canvas keeps a visitor's choices (the host can install a store of its own)
|
|
11
19
|
export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './preferenceStorage';
|
|
12
20
|
// Input Controllers
|
|
@@ -18,7 +18,7 @@ import type { ReorderMode, Scene } from './core/scene.js';
|
|
|
18
18
|
import type { StylePatch } from './core/style.js';
|
|
19
19
|
import type { SelectionFrame } from './core/transform.js';
|
|
20
20
|
import type { ObjectId, Point, Rect, RectObject, SceneObject, ShapeObject, Size, TextObject, Viewport, WidgetObject } from './core/types.js';
|
|
21
|
-
import type { EngineOverlay, EngineState, PendingWidgetState, ToolId, WidgetRuntime } from './state.js';
|
|
21
|
+
import type { EngineOverlay, EngineState, PendingWidgetState, PenStyle, ToolId, WidgetRuntime } from './state.js';
|
|
22
22
|
import type { MeasureText } from './text/layoutText.js';
|
|
23
23
|
/** How many undo steps the board keeps (as the canvas it replaces did). */
|
|
24
24
|
export declare const HISTORY_LIMIT = 50;
|
|
@@ -47,6 +47,11 @@ export interface EngineServices {
|
|
|
47
47
|
* in its place at once instead of easing it there.
|
|
48
48
|
*/
|
|
49
49
|
prefersReducedMotion?: () => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Says something worth following about what the person did (once per action, never per frame): the canvas passes its console
|
|
52
|
+
* logger. The engine says nothing when no function is given, as in the tests.
|
|
53
|
+
*/
|
|
54
|
+
log?: (message: string, details?: Record<string, unknown>) => void;
|
|
50
55
|
}
|
|
51
56
|
/** A place to look at: the point of the world that goes to the middle of the board element, and the zoom to arrive at. */
|
|
52
57
|
export interface ViewTarget {
|
|
@@ -58,6 +63,11 @@ export interface ViewTarget {
|
|
|
58
63
|
export interface ViewMoveOptions {
|
|
59
64
|
/** How long the move takes, in milliseconds. Left out: worked out from how far the view goes, and always under a second. */
|
|
60
65
|
duration?: number;
|
|
66
|
+
/**
|
|
67
|
+
* How much of the worked-out time the move takes: 0.5 is twice as quick, 2 is twice as slow. Only used when `duration` is left
|
|
68
|
+
* out (a duration that is given is the time of the move, exactly). A value that is not above 0 is taken for 1.
|
|
69
|
+
*/
|
|
70
|
+
durationScale?: number;
|
|
61
71
|
/**
|
|
62
72
|
* The shape of the move: how much of the way is done (0 to 1) when this much of the time has passed (0 to 1), for the
|
|
63
73
|
* position and the zoom together. Left out: slow start, quick middle, slow end.
|
|
@@ -86,6 +96,8 @@ export interface ViewObjectsMoveOptions extends ViewMoveOptions {
|
|
|
86
96
|
*/
|
|
87
97
|
zoom?: number | 'fit' | 'keep';
|
|
88
98
|
}
|
|
99
|
+
/** Why the board is empty when `onCleared` is called: the page cleared it (`'clear-all'`) or the person deleted its last objects (`'deleted'`). */
|
|
100
|
+
export type BoardClearCause = 'clear-all' | 'deleted';
|
|
89
101
|
/** What the engine tells the host shell. Every hook is optional and read at the moment it is needed. */
|
|
90
102
|
export interface EngineHooks {
|
|
91
103
|
/** The person changed the board: it needs saving. */
|
|
@@ -97,12 +109,19 @@ export interface EngineHooks {
|
|
|
97
109
|
* empty new text is dropped after something was typed in it (the save that held the typed letters is out of date).
|
|
98
110
|
*/
|
|
99
111
|
onDraftChange?: () => void;
|
|
100
|
-
/**
|
|
101
|
-
|
|
112
|
+
/**
|
|
113
|
+
* The board was emptied, and why: `'clear-all'` (the page asked for it, `clearAll()`) or `'deleted'` (the person's delete or cut took
|
|
114
|
+
* the last object off the board). The eraser and an undo that end on an empty board are not told: they are not a clear. A page that
|
|
115
|
+
* eases the view back to the start (`flyToContent`) does it for the cleared board, and waits for the person's own clear: a page
|
|
116
|
+
* clears the board itself when it opens another one, and then it is the board that opens that sets the view.
|
|
117
|
+
*/
|
|
118
|
+
onCleared?: (cause: BoardClearCause) => void;
|
|
102
119
|
/** The selection changed (a selection, a deselection, after a delete or an undo). */
|
|
103
120
|
onSelectionChange?: (selectedIds: readonly ObjectId[]) => void;
|
|
104
121
|
/** Widget cards are about to be deleted: one question per widget, and one `false` cancels the whole delete. */
|
|
105
122
|
confirmWidgetDeletion?: ((widgetId: string) => Promise<boolean> | boolean) | null;
|
|
123
|
+
/** Whether widget cards may be duplicated/pasted on the board. Defaults to true. */
|
|
124
|
+
canDuplicateWidget?: () => boolean;
|
|
106
125
|
/** A widget card was duplicated or pasted: the host makes a copy of the widget and links it with `linkObjectToWidget`. */
|
|
107
126
|
onWidgetDuplicated?: ((sourceWidgetId: string, clone: WidgetObject) => void) | null;
|
|
108
127
|
/** Something went wrong in a hook the host supplied. */
|
|
@@ -308,13 +327,26 @@ export declare class EngineCore {
|
|
|
308
327
|
text?: Partial<Pick<TextObject, 'fontFamily' | 'fontSize' | 'fontWeight' | 'fontStyle' | 'color' | 'align' | 'underline'>> | null;
|
|
309
328
|
paint?: Partial<Pick<RectObject, 'fill' | 'stroke' | 'strokeWidth' | 'strokeStyle' | 'opacity' | 'roundness'>> | null;
|
|
310
329
|
}): void;
|
|
330
|
+
/**
|
|
331
|
+
* Changes how the Draw tool draws: the lines drawn from now on take the colour, the width and the opacity that are asked for. A key
|
|
332
|
+
* that is left out stays as it was; a value that cannot be a line's (a width under 1 or above 200, an opacity out of range, a
|
|
333
|
+
* colour that is not a word, a number that is not a number) is brought to what a line can be, or ignored when it is not a value
|
|
334
|
+
* at all. Nothing on the board changes (that is `setStyle`, for the selection), and nothing is added to the history. Returns
|
|
335
|
+
* whether the pen came out different.
|
|
336
|
+
*/
|
|
337
|
+
setPenStyle(patch: Partial<PenStyle>): boolean;
|
|
311
338
|
workspacePaintForNewShape(wireframe: boolean): Partial<RectObject>;
|
|
312
339
|
/**
|
|
313
340
|
* Makes a text object, puts it on the board and starts editing it. A click makes a label whose width follows its
|
|
314
341
|
* text; a width makes a box whose lines wrap. Nothing is recorded until the editing ends with text in it.
|
|
342
|
+
*
|
|
343
|
+
* `placeholder: true` is the text the Text tool puts on the board the moment it is chosen: its box (as wide as the placeholder
|
|
344
|
+
* prompt) is centred on `point` instead of starting there, and a press elsewhere on the board while it is still empty keeps the
|
|
345
|
+
* tool, so that press (or drag) places the text there (see `endTextEdit`).
|
|
315
346
|
*/
|
|
316
347
|
createText(point: Point, options?: {
|
|
317
348
|
width?: number;
|
|
349
|
+
placeholder?: boolean;
|
|
318
350
|
}): ObjectId;
|
|
319
351
|
/** Starts editing the text of an existing text object. */
|
|
320
352
|
beginTextEdit(id: ObjectId): boolean;
|
|
@@ -323,8 +355,14 @@ export declare class EngineCore {
|
|
|
323
355
|
/**
|
|
324
356
|
* Finishes the edit. An empty text is removed (a new one leaves nothing behind, not even an undo step);
|
|
325
357
|
* otherwise creation and typing together are one undo step.
|
|
358
|
+
*
|
|
359
|
+
* `keepPlaceholderTool` is for a press on the board that ends the edit: when what ends is the empty placeholder the Text tool
|
|
360
|
+
* put on the board (see `createText`), the tool is not left, so the press goes on to be a press of the Text tool and puts the
|
|
361
|
+
* text where the person pressed. Any other end of the edit leaves the Text tool, as before.
|
|
326
362
|
*/
|
|
327
|
-
endTextEdit(
|
|
363
|
+
endTextEdit(options?: {
|
|
364
|
+
keepPlaceholderTool?: boolean;
|
|
365
|
+
}): ObjectId | null;
|
|
328
366
|
/** Changes how the selection looks. `commit: false` is for a slider that is still being dragged: call `commit()` when it ends. */
|
|
329
367
|
setStyle(patch: StylePatch, options?: {
|
|
330
368
|
commit?: boolean;
|
|
@@ -343,6 +381,10 @@ export declare class EngineCore {
|
|
|
343
381
|
nudgeSelection(deltaX: number, deltaY: number): boolean;
|
|
344
382
|
alignSelection(mode: AlignMode): boolean;
|
|
345
383
|
distributeSelection(axis: DistributeAxis): boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Puts the selection in front of or behind the others (`front` and `back` all the way, `forward` and `backward` one step).
|
|
386
|
+
* Shapes that arrows tie together are one diagram: what is joined to the selection by arrows, at any distance, goes with it.
|
|
387
|
+
*/
|
|
346
388
|
reorderSelection(mode: ReorderMode): boolean;
|
|
347
389
|
/** Puts the selected units in a group, which becomes the selection. */
|
|
348
390
|
groupSelection(): boolean;
|
|
@@ -18,12 +18,14 @@ import { reconcileArrowBindings } from './core/arrowBinding.js';
|
|
|
18
18
|
import { createImageObject, createObjectId, createRectObject, createTextObject, createWidgetObject, TEXT_DEFAULTS } from './core/defaults.js';
|
|
19
19
|
import { HistoryStack } from './core/history.js';
|
|
20
20
|
import { hitTestPoint, hitTestRect, hitTestStack } from './core/hitTest.js';
|
|
21
|
-
import { addObjectsBehindWidgetCards, boardVisualBounds, boundsOfObjects, duplicateObjects, groupObjects, indexScene, leafShapesOf, normalizeScene, normalizeSelection, removeObjects as removeFromScene, reorderObjects, replaceObject, sameIds, translateObjects, ungroupObjects, withDescendantIds } from './core/scene.js';
|
|
22
|
-
import {
|
|
21
|
+
import { addObjectsBehindWidgetCards, boardVisualBounds, boundsOfObjects, duplicateObjects, groupObjects, indexScene, leafShapesOf, normalizeScene, normalizeSelection, removeObjects as removeFromScene, reorderObjects, replaceObject, sameIds, translateObjects, ungroupObjects, withConnectedObjects, withDescendantIds } from './core/scene.js';
|
|
22
|
+
import { MIN_BRUSH_WIDTH } from './core/brush.js';
|
|
23
|
+
import { clampNumber } from './core/geometry.js';
|
|
24
|
+
import { MAX_STROKE_WIDTH, applyStylePatch } from './core/style.js';
|
|
23
25
|
import { Scribble } from './core/scribble.js';
|
|
24
26
|
import { selectionFrameOf } from './core/transform.js';
|
|
25
27
|
import { INITIAL_VIEWPORT, clampZoom, fitViewportToRect, nextZoomStep, panViewport, sanitizeViewport, screenToWorld, visibleWorldRect, zoomAtPoint } from './core/viewport.js';
|
|
26
|
-
import { DEFAULT_WIDGET_RUNTIME, EMPTY_OVERLAY, createInitialState } from './state.js';
|
|
28
|
+
import { DEFAULT_WIDGET_RUNTIME, EMPTY_OVERLAY, MIN_PEN_OPACITY, createInitialState } from './state.js';
|
|
27
29
|
import { createFixedAdvanceMeasure, fitTextObject } from './text/layoutText.js';
|
|
28
30
|
/** How many undo steps the board keeps (as the canvas it replaces did). */
|
|
29
31
|
export const HISTORY_LIMIT = 50;
|
|
@@ -82,6 +84,7 @@ export class EngineCore {
|
|
|
82
84
|
measureText: services.measureText ?? createFixedAdvanceMeasure(),
|
|
83
85
|
now: services.now ?? (() => Date.now()),
|
|
84
86
|
random: services.random ?? Math.random,
|
|
87
|
+
log: services.log ?? (() => { }),
|
|
85
88
|
prefersReducedMotion: services.prefersReducedMotion ??
|
|
86
89
|
(() => typeof globalThis.matchMedia === 'function' && globalThis.matchMedia('(prefers-reduced-motion: reduce)').matches),
|
|
87
90
|
requestAnimationFrame: services.requestAnimationFrame ??
|
|
@@ -429,7 +432,9 @@ export class EngineCore {
|
|
|
429
432
|
return false;
|
|
430
433
|
}
|
|
431
434
|
}
|
|
432
|
-
|
|
435
|
+
const removed = this.removeObjects(wanted);
|
|
436
|
+
this.#tellHostWhenPersonEmptiedBoard(removed);
|
|
437
|
+
return removed;
|
|
433
438
|
}
|
|
434
439
|
async deleteSelection() {
|
|
435
440
|
return this.deleteObjects(this.#state.selectedIds);
|
|
@@ -441,7 +446,13 @@ export class EngineCore {
|
|
|
441
446
|
return;
|
|
442
447
|
this.applyScene([], 'push');
|
|
443
448
|
this.#set({ selectedIds: [], enteredGroupId: null, hoverId: null });
|
|
444
|
-
this.#callHook(() => this.hooks.onCleared?.(), 'cleared hook');
|
|
449
|
+
this.#callHook(() => this.hooks.onCleared?.('clear-all'), 'cleared hook');
|
|
450
|
+
}
|
|
451
|
+
/** After what the person removed (delete, cut): when it took the last object off the board, the host hears `onCleared('deleted')`. */
|
|
452
|
+
#tellHostWhenPersonEmptiedBoard(removed) {
|
|
453
|
+
if (!removed || this.#state.scene.length > 0)
|
|
454
|
+
return;
|
|
455
|
+
this.#callHook(() => this.hooks.onCleared?.('deleted'), 'cleared hook');
|
|
445
456
|
}
|
|
446
457
|
// ──────────────────────────────────────────────────────── selection
|
|
447
458
|
/** Selects units (a group counts once). Everything else is deselected unless `additive`. */
|
|
@@ -727,7 +738,9 @@ export class EngineCore {
|
|
|
727
738
|
return false;
|
|
728
739
|
}
|
|
729
740
|
const path = createCameraPath(startView, endView, viewSize, options.path);
|
|
730
|
-
|
|
741
|
+
// The time of the move: the one given, or the one its length gives, made quicker or slower by `durationScale` (which has to be a number above 0).
|
|
742
|
+
const durationScale = typeof options.durationScale === 'number' && Number.isFinite(options.durationScale) && options.durationScale > 0 ? options.durationScale : 1;
|
|
743
|
+
const duration = options.duration ?? (path?.duration ?? 0) * durationScale;
|
|
731
744
|
if (!path || !(duration > 0) || this.services.prefersReducedMotion()) {
|
|
732
745
|
// No time to move in, or a person who asked their system for no motion: the view is in its place at once.
|
|
733
746
|
this.#writeViewport(endViewport);
|
|
@@ -854,6 +867,23 @@ export class EngineCore {
|
|
|
854
867
|
if (settings.text?.fontFamily)
|
|
855
868
|
this.#preferredTextFontFamily = settings.text.fontFamily;
|
|
856
869
|
}
|
|
870
|
+
/**
|
|
871
|
+
* Changes how the Draw tool draws: the lines drawn from now on take the colour, the width and the opacity that are asked for. A key
|
|
872
|
+
* that is left out stays as it was; a value that cannot be a line's (a width under 1 or above 200, an opacity out of range, a
|
|
873
|
+
* colour that is not a word, a number that is not a number) is brought to what a line can be, or ignored when it is not a value
|
|
874
|
+
* at all. Nothing on the board changes (that is `setStyle`, for the selection), and nothing is added to the history. Returns
|
|
875
|
+
* whether the pen came out different.
|
|
876
|
+
*/
|
|
877
|
+
setPenStyle(patch) {
|
|
878
|
+
const current = this.#state.penStyle;
|
|
879
|
+
const color = typeof patch.color === 'string' && patch.color.trim() !== '' ? patch.color.trim() : current.color;
|
|
880
|
+
const width = typeof patch.width === 'number' && Number.isFinite(patch.width) ? clampNumber(patch.width, MIN_BRUSH_WIDTH, MAX_STROKE_WIDTH) : current.width;
|
|
881
|
+
const opacity = typeof patch.opacity === 'number' && Number.isFinite(patch.opacity) ? clampNumber(patch.opacity, MIN_PEN_OPACITY, 1) : current.opacity;
|
|
882
|
+
if (color === current.color && width === current.width && opacity === current.opacity)
|
|
883
|
+
return false;
|
|
884
|
+
this.#set({ penStyle: Object.freeze({ color, width, opacity }) });
|
|
885
|
+
return true;
|
|
886
|
+
}
|
|
857
887
|
workspacePaintForNewShape(wireframe) {
|
|
858
888
|
if (!this.#workspacePaintDefaults)
|
|
859
889
|
return {};
|
|
@@ -871,6 +901,10 @@ export class EngineCore {
|
|
|
871
901
|
/**
|
|
872
902
|
* Makes a text object, puts it on the board and starts editing it. A click makes a label whose width follows its
|
|
873
903
|
* text; a width makes a box whose lines wrap. Nothing is recorded until the editing ends with text in it.
|
|
904
|
+
*
|
|
905
|
+
* `placeholder: true` is the text the Text tool puts on the board the moment it is chosen: its box (as wide as the placeholder
|
|
906
|
+
* prompt) is centred on `point` instead of starting there, and a press elsewhere on the board while it is still empty keeps the
|
|
907
|
+
* tool, so that press (or drag) places the text there (see `endTextEdit`).
|
|
874
908
|
*/
|
|
875
909
|
createText(point, options = {}) {
|
|
876
910
|
this.endTextEdit();
|
|
@@ -884,11 +918,13 @@ export class EngineCore {
|
|
|
884
918
|
fontFamily: this.#preferredTextFontFamily ?? this.#workspaceTextDefaults?.fontFamily ?? TEXT_DEFAULTS.fontFamily,
|
|
885
919
|
...this.#workspaceTextDefaults
|
|
886
920
|
});
|
|
887
|
-
const
|
|
921
|
+
const fitted = this.#fitText(base);
|
|
922
|
+
// The placeholder is centred on the point it is asked for, whatever its size (a bigger font makes a bigger prompt).
|
|
923
|
+
const text = options.placeholder ? { ...fitted, x: point.x - fitted.width / 2, y: point.y - fitted.height / 2 } : fitted;
|
|
888
924
|
const sceneBefore = this.#state.scene;
|
|
889
925
|
// A text typed after a widget stands goes behind it, like every other drawing.
|
|
890
926
|
this.applyScene(addObjectsBehindWidgetCards(sceneBefore, [text]), 'transient');
|
|
891
|
-
this.#textSession = { id: text.id, isNew: true, sceneBefore, typed: false };
|
|
927
|
+
this.#textSession = { id: text.id, isNew: true, sceneBefore, typed: false, placeholder: options.placeholder === true };
|
|
892
928
|
this.#set({ editingTextId: text.id, selectedIds: [text.id], enteredGroupId: null });
|
|
893
929
|
return text.id;
|
|
894
930
|
}
|
|
@@ -900,7 +936,7 @@ export class EngineCore {
|
|
|
900
936
|
if (this.#textSession?.id === id)
|
|
901
937
|
return true;
|
|
902
938
|
this.endTextEdit();
|
|
903
|
-
this.#textSession = { id, isNew: false, sceneBefore: this.#state.scene, typed: false };
|
|
939
|
+
this.#textSession = { id, isNew: false, sceneBefore: this.#state.scene, typed: false, placeholder: false };
|
|
904
940
|
this.#set({ editingTextId: id, selectedIds: [id] });
|
|
905
941
|
return true;
|
|
906
942
|
}
|
|
@@ -925,8 +961,12 @@ export class EngineCore {
|
|
|
925
961
|
/**
|
|
926
962
|
* Finishes the edit. An empty text is removed (a new one leaves nothing behind, not even an undo step);
|
|
927
963
|
* otherwise creation and typing together are one undo step.
|
|
964
|
+
*
|
|
965
|
+
* `keepPlaceholderTool` is for a press on the board that ends the edit: when what ends is the empty placeholder the Text tool
|
|
966
|
+
* put on the board (see `createText`), the tool is not left, so the press goes on to be a press of the Text tool and puts the
|
|
967
|
+
* text where the person pressed. Any other end of the edit leaves the Text tool, as before.
|
|
928
968
|
*/
|
|
929
|
-
endTextEdit() {
|
|
969
|
+
endTextEdit(options = {}) {
|
|
930
970
|
const session = this.#textSession;
|
|
931
971
|
if (!session)
|
|
932
972
|
return null;
|
|
@@ -934,11 +974,14 @@ export class EngineCore {
|
|
|
934
974
|
const object = this.getObject(session.id);
|
|
935
975
|
this.#set({ editingTextId: null });
|
|
936
976
|
let kept = null;
|
|
977
|
+
// The placeholder of the Text tool ended without a letter in it.
|
|
978
|
+
let emptyPlaceholderDropped = false;
|
|
937
979
|
if (object && object.type === 'text') {
|
|
938
980
|
if (object.text.trim() === '') {
|
|
939
981
|
if (session.isNew) {
|
|
940
982
|
this.applyScene(session.sceneBefore, 'transient');
|
|
941
983
|
this.#set({ selectedIds: [] });
|
|
984
|
+
emptyPlaceholderDropped = session.placeholder;
|
|
942
985
|
// A save may have taken the letters that were typed before they were all deleted: it has to be told they are gone.
|
|
943
986
|
if (session.typed)
|
|
944
987
|
this.#callHook(() => this.hooks.onDraftChange?.(), 'draft change hook');
|
|
@@ -953,7 +996,8 @@ export class EngineCore {
|
|
|
953
996
|
}
|
|
954
997
|
}
|
|
955
998
|
// The Text tool is used once: the board goes back to Select when the typing is over (unless the tool is kept).
|
|
956
|
-
|
|
999
|
+
const keepsTool = this.#state.stickyTool || (options.keepPlaceholderTool === true && emptyPlaceholderDropped);
|
|
1000
|
+
if (this.#state.tool === 'text' && !keepsTool)
|
|
957
1001
|
this.setTool('select', { keepSelection: true });
|
|
958
1002
|
return kept;
|
|
959
1003
|
}
|
|
@@ -1065,8 +1109,23 @@ export class EngineCore {
|
|
|
1065
1109
|
this.applyScene(next, 'push');
|
|
1066
1110
|
return true;
|
|
1067
1111
|
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Puts the selection in front of or behind the others (`front` and `back` all the way, `forward` and `backward` one step).
|
|
1114
|
+
* Shapes that arrows tie together are one diagram: what is joined to the selection by arrows, at any distance, goes with it.
|
|
1115
|
+
*/
|
|
1068
1116
|
reorderSelection(mode) {
|
|
1069
|
-
return this.#arrange((scene, ids) =>
|
|
1117
|
+
return this.#arrange((scene, ids) => {
|
|
1118
|
+
try {
|
|
1119
|
+
const withConnected = withConnectedObjects(scene, ids);
|
|
1120
|
+
this.services.log('Canvas: layer order', { mode, selected: ids.length, moved: withConnected.length });
|
|
1121
|
+
return reorderObjects(scene, withConnected, mode);
|
|
1122
|
+
}
|
|
1123
|
+
catch (error) {
|
|
1124
|
+
// A board that cannot be followed through its arrows still moves what is selected, which is what the person asked for.
|
|
1125
|
+
this.services.log('Canvas: the shapes tied by arrows could not be followed, only the selection is moved', { mode, error: String(error) });
|
|
1126
|
+
return reorderObjects(scene, ids, mode);
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1070
1129
|
}
|
|
1071
1130
|
/** Puts the selected units in a group, which becomes the selection. */
|
|
1072
1131
|
groupSelection() {
|
|
@@ -1108,6 +1167,7 @@ export class EngineCore {
|
|
|
1108
1167
|
const removed = this.removeObjects(this.#state.selectedIds);
|
|
1109
1168
|
if (removed)
|
|
1110
1169
|
this.#set({ selectedIds: [] });
|
|
1170
|
+
this.#tellHostWhenPersonEmptiedBoard(removed);
|
|
1111
1171
|
return removed;
|
|
1112
1172
|
}
|
|
1113
1173
|
/** Puts a copy of the clipboard on the board, centred on `at` (or shifted a little from the original). Returns the new ids. */
|
|
@@ -1141,13 +1201,22 @@ export class EngineCore {
|
|
|
1141
1201
|
return this.#insertCopies(scene, rootIds, { x: 0, y: 0 }, 'transient');
|
|
1142
1202
|
}
|
|
1143
1203
|
#insertCopies(source, rootIds, offset, mode = 'push') {
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1204
|
+
const widgetDuplicationAllowed = this.hooks.canDuplicateWidget ? this.hooks.canDuplicateWidget() : true;
|
|
1205
|
+
const allowedRootIds = widgetDuplicationAllowed
|
|
1206
|
+
? rootIds
|
|
1207
|
+
: rootIds.filter((id) => source.find((o) => o.id === id)?.type !== 'widget');
|
|
1208
|
+
if (allowedRootIds.length === 0)
|
|
1209
|
+
return [];
|
|
1210
|
+
const { objects, idMap } = duplicateObjects(source, allowedRootIds, offset, (type) => this.services.createId(type === 'group' ? 'group' : 'obj'));
|
|
1211
|
+
const filteredObjects = widgetDuplicationAllowed
|
|
1212
|
+
? objects
|
|
1213
|
+
: objects.filter((o) => o.type !== 'widget');
|
|
1214
|
+
if (filteredObjects.length === 0)
|
|
1146
1215
|
return [];
|
|
1147
1216
|
const duplicatesWidgets = this.hooks.onWidgetDuplicated ?? null;
|
|
1148
1217
|
const pending = { ...this.#state.pending };
|
|
1149
1218
|
const widgetClones = [];
|
|
1150
|
-
const prepared =
|
|
1219
|
+
const prepared = filteredObjects.map((object) => {
|
|
1151
1220
|
if (object.type !== 'widget')
|
|
1152
1221
|
return object;
|
|
1153
1222
|
if (duplicatesWidgets) {
|
|
@@ -1162,7 +1231,7 @@ export class EngineCore {
|
|
|
1162
1231
|
// A copy of a member goes into the group of the original; if that group is gone it is repaired to the top level.
|
|
1163
1232
|
this.applyScene(normalizeScene([...this.#state.scene, ...prepared.map((object) => this.#fitText(object))]), mode);
|
|
1164
1233
|
this.#set({ pending: Object.freeze(pending) });
|
|
1165
|
-
const rootCopyIds =
|
|
1234
|
+
const rootCopyIds = allowedRootIds.map((id) => idMap.get(id)).filter((id) => !!id);
|
|
1166
1235
|
const selectable = rootCopyIds.filter((id) => !pending[id]);
|
|
1167
1236
|
this.#setSelection(selectable);
|
|
1168
1237
|
for (const { sourceWidgetId, clone } of widgetClones) {
|