@widgetic/canvas 0.5.47 → 0.5.48
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 +2 -0
- package/dist/canvas/DomCanvas.svelte +4 -1
- package/dist/canvas/DomCanvas.svelte.d.ts +1 -0
- package/dist/canvas/eventScope.js +7 -1
- package/dist/canvas/host/CanvasHost.d.ts +5 -0
- package/dist/canvas/host/CanvasHost.js +12 -7
- package/dist/canvas/ui/CanvasToolbar.svelte +17 -14
- package/dist/canvas/view/SelectionOverlay.svelte +3 -3
- package/dist/canvas/view/WidgetChromeLayer.svelte +10 -2
- package/dist/engine/input/keyboard.js +7 -3
- package/dist/settings/rememberedTool.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -240,6 +240,8 @@ Each prints one line per check and exits 1 when one fails. `__docs/dom-canvas.md
|
|
|
240
240
|
|
|
241
241
|
GitLab CI on `main` publishes this package. Bump `version` in `package.json` and push `main`. The job is an npm Trusted Publisher (`NPM_ID_TOKEN`) and skips a version that is already on npm. A laptop publish is the fallback when CI minutes are gone. The token stays in `~/.npmrc` and is never committed.
|
|
242
242
|
|
|
243
|
+
**A laptop publish is made from a clean clone, never from the checkout you work in.** Clone this repository (in a folder named `canvas`) and `dev-tools` side by side, outside your checkouts, run `git config push.pushOption ci.skip` in the clone, and run `npm ci`, `npm run check` and `npm test` there. Then `npm run publish-to-npm` raises the patch version, builds, publishes, commits `chore: publish <version>`, tags it and pushes `main`, all from the clone: the checkout where you test, with its uncommitted files and its dev server, is not touched. Bring that checkout level afterwards, when you want to, with the steps of the release guide ("Bring a checkout level with `origin` after a release"), and delete the clones once the version is on npm (`npm view @widgetic/canvas version --prefer-online`, which can take 3 to 9 minutes to show it).
|
|
244
|
+
|
|
243
245
|
## License
|
|
244
246
|
|
|
245
247
|
This package is licensed under the Widgetic Integration License (see the `LICENSE` file in the package): you may use it to integrate Widgetic into your own application, and for nothing else. It is not open source. For any other use, write to support@widgetic.com.
|
|
@@ -88,6 +88,8 @@
|
|
|
88
88
|
|
|
89
89
|
/** The selector's indicator at the top of the board: shown while the page says so (a widget stands on the board and the hint is not closed). */
|
|
90
90
|
export let showElementSelector: CanvasHostProps['showElementSelector'] = DEFAULT_HOST_PROPS.showElementSelector;
|
|
91
|
+
/** The toolbar card (Select, Shapes, undo). Independent of the sketch tools. */
|
|
92
|
+
export let showToolbar: CanvasHostProps['showToolbar'] = DEFAULT_HOST_PROPS.showToolbar;
|
|
91
93
|
/** The drawing toolbar. The page keeps it for as long as the board is drawn on, widget or not. */
|
|
92
94
|
export let showDrawingTools: CanvasHostProps['showDrawingTools'] = DEFAULT_HOST_PROPS.showDrawingTools;
|
|
93
95
|
/** The page's element selector is picking now: the indicator says "Selector on", and the arrow keys are the selector's. */
|
|
@@ -273,6 +275,7 @@
|
|
|
273
275
|
wireframeMode,
|
|
274
276
|
advancedFeatures,
|
|
275
277
|
showElementSelector,
|
|
278
|
+
showToolbar,
|
|
276
279
|
showDrawingTools,
|
|
277
280
|
elementSelectorActive,
|
|
278
281
|
onToggleElementSelector,
|
|
@@ -365,7 +368,7 @@
|
|
|
365
368
|
// Where the two cards of the chrome stand. Each names one of eight anchors; two named for the same one share a slot, side by side.
|
|
366
369
|
$: toolbarAnchor = normalizeToolbarPosition(toolbarPosition);
|
|
367
370
|
$: zoomAnchor = normalizePanZoomPosition(panZoomPosition);
|
|
368
|
-
$: slots = chromeSlots(toolbarAnchor, zoomAnchor, { toolbar:
|
|
371
|
+
$: slots = chromeSlots(toolbarAnchor, zoomAnchor, { toolbar: showToolbar, zoom: showZoomControl });
|
|
369
372
|
$: zoomVisibleMinWidth = zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor);
|
|
370
373
|
// The selector's indicator stands at the top centre, below a card the page put there. Closing it hides it at once; it shows
|
|
371
374
|
// again when the page turns `showElementSelector` off and on (the next widget), or says nothing and keeps it on.
|
|
@@ -29,6 +29,7 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
|
|
|
29
29
|
wireframeMode?: CanvasHostProps["wireframeMode"];
|
|
30
30
|
advancedFeatures?: CanvasHostProps["advancedFeatures"];
|
|
31
31
|
/** The selector's indicator at the top of the board: shown while the page says so (a widget stands on the board and the hint is not closed). */ showElementSelector?: CanvasHostProps["showElementSelector"];
|
|
32
|
+
/** The toolbar card (Select, Shapes, undo). Independent of the sketch tools. */ showToolbar?: CanvasHostProps["showToolbar"];
|
|
32
33
|
/** The drawing toolbar. The page keeps it for as long as the board is drawn on, widget or not. */ showDrawingTools?: CanvasHostProps["showDrawingTools"];
|
|
33
34
|
/** The page's element selector is picking now: the indicator says "Selector on", and the arrow keys are the selector's. */ elementSelectorActive?: CanvasHostProps["elementSelectorActive"];
|
|
34
35
|
/** Accepted for the pages that set it: the Select tool turns the selector on and off now. */ onToggleElementSelector?: CanvasHostProps["onToggleElementSelector"];
|
|
@@ -47,7 +47,13 @@ export function getFocusedElementIn(scopeNode) {
|
|
|
47
47
|
*/
|
|
48
48
|
export function getEventOrigin(event) {
|
|
49
49
|
const first = event.composedPath()[0] ?? event.target;
|
|
50
|
-
|
|
50
|
+
if (!first)
|
|
51
|
+
return null;
|
|
52
|
+
const node = first;
|
|
53
|
+
if (node.nodeType === 1)
|
|
54
|
+
return node;
|
|
55
|
+
// A caret in a field is often a text node. Cmd+A and the rest of typing must still see the field, not the board.
|
|
56
|
+
return node.parentElement ?? null;
|
|
51
57
|
}
|
|
52
58
|
/**
|
|
53
59
|
* Whether an event went through `element`, from inside it or on it. The answer for a click on a menu is the same in a
|
|
@@ -70,6 +70,11 @@ export interface CanvasHostProps {
|
|
|
70
70
|
* not closed it (see `onDismissElementSelectorHint`). The toolbar is not affected: it stays as `showDrawingTools` says.
|
|
71
71
|
*/
|
|
72
72
|
showElementSelector: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Shows the toolbar card (Select, Shapes, undo). Independent of `showDrawingTools`, so a simple board can keep Select
|
|
75
|
+
* after the first generation while the sketch tools leave.
|
|
76
|
+
*/
|
|
77
|
+
showToolbar: boolean;
|
|
73
78
|
showDrawingTools: boolean;
|
|
74
79
|
/**
|
|
75
80
|
* The page's element selector is picking elements of the widget now (the Select tool is chosen and the page has not paused
|
|
@@ -27,10 +27,10 @@ import { registerWorkspaceFonts } from '../../fonts/workspaceFonts.js';
|
|
|
27
27
|
import { isCanvasOwnedTarget } from '../outsideClickDeselect.js';
|
|
28
28
|
import { flushWorkspaceToolSettingsPending, loadWorkspaceToolSettings, saveWorkspaceToolSettingsDebounced } from '../../settings/workspaceToolSettings.js';
|
|
29
29
|
import { rememberedStylesOfSettings, settingsOfRememberedStyles } from '../../settings/rememberedStyles.js';
|
|
30
|
-
import {
|
|
30
|
+
import { readRememberedToolId, toolTheBoardOpensWith, toolToRemember } from '../../settings/rememberedTool.js';
|
|
31
31
|
import { canvasLog, canvasWarn, isCanvasLogsEnabled, setCanvasLogsEnabled } from '../canvasLogger.js';
|
|
32
32
|
import { CANVAS_OPEN_MARKS, markCanvasOpenStep } from '../openMarks.js';
|
|
33
|
-
import { eventIsForScope, getEventOrigin, shouldTakeFocusBack } from '../eventScope.js';
|
|
33
|
+
import { eventIsForScope, getEventOrigin, getFocusedElementIn, shouldTakeFocusBack } from '../eventScope.js';
|
|
34
34
|
import { getShapeImageStore, shapeImageRef } from '../shapes/shapeImageStore.js';
|
|
35
35
|
import { BOARD_FILE_KINDS, applyLibraryFile, normalizeLibraryFiles } from './boardFiles.js';
|
|
36
36
|
import { chooseImageFiles, createBrowserMeasureText, createBrowserRasterServices, readImageFile, readLibraryPicture } from './browserServices.js';
|
|
@@ -56,6 +56,7 @@ export const DEFAULT_HOST_PROPS = Object.freeze({
|
|
|
56
56
|
wireframeMode: true,
|
|
57
57
|
advancedFeatures: false,
|
|
58
58
|
showElementSelector: false,
|
|
59
|
+
showToolbar: true,
|
|
59
60
|
showDrawingTools: true,
|
|
60
61
|
elementSelectorActive: false,
|
|
61
62
|
onToggleElementSelector: null,
|
|
@@ -172,7 +173,11 @@ const isEditableTarget = (element) => {
|
|
|
172
173
|
if (!element)
|
|
173
174
|
return false;
|
|
174
175
|
const tag = element.tagName;
|
|
175
|
-
|
|
176
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT')
|
|
177
|
+
return true;
|
|
178
|
+
if (element.isContentEditable === true)
|
|
179
|
+
return true;
|
|
180
|
+
return Boolean(element.closest?.('input, textarea, select, [contenteditable="true"], [contenteditable=""]'));
|
|
176
181
|
};
|
|
177
182
|
/** Whether two lists hold the same entries in the same order (a page may pass a new array with the same content each time). */
|
|
178
183
|
const hasSameEntries = (first, second) => first.length === second.length && first.every((entry, index) => entry === second[index]);
|
|
@@ -495,14 +500,14 @@ export class CanvasHost {
|
|
|
495
500
|
}
|
|
496
501
|
/**
|
|
497
502
|
* A tool whose button the page hides must not stay armed: once the page takes the drawing tools off (after the first
|
|
498
|
-
* generation) the pencil, the eraser, the arrow and the
|
|
499
|
-
* ignored for them as well (see `tools`).
|
|
503
|
+
* generation) the pencil, the eraser, the arrow, the text and the Shapes menu go, and the Select tool takes over.
|
|
504
|
+
* The letter keys are ignored for them as well (see `tools`).
|
|
500
505
|
*/
|
|
501
506
|
#dropToolsThePageHides() {
|
|
502
507
|
if (this.props.showDrawingTools)
|
|
503
508
|
return;
|
|
504
509
|
const { tool } = this.engine.state;
|
|
505
|
-
if (
|
|
510
|
+
if (tool === 'select' || tool === 'pan')
|
|
506
511
|
return;
|
|
507
512
|
// Select takes over because the page took the button off, which is not the person's choice: the tool that was kept stays kept.
|
|
508
513
|
this.#toolChangeIsNotAChoice = true;
|
|
@@ -1036,7 +1041,7 @@ export class CanvasHost {
|
|
|
1036
1041
|
controller: this.controller,
|
|
1037
1042
|
actions: this.#keyboardActions(),
|
|
1038
1043
|
tools: this.tools,
|
|
1039
|
-
typingInField: isEditableTarget(origin),
|
|
1044
|
+
typingInField: isEditableTarget(origin) || isEditableTarget(getFocusedElementIn(this.#root)),
|
|
1040
1045
|
hasTextSelection,
|
|
1041
1046
|
// The arrow keys are the selector's while it is picking, whether or not its indicator is shown (the person may have closed it).
|
|
1042
1047
|
selectorHintOpen: this.props.elementSelectorActive
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
Left to right: the drawing group (select, draw, erase, arrow, text), a divider, the Shapes menu, a divider and the history
|
|
6
6
|
group (undo, redo). Every button is the design system's Icon Button with a tooltip, 36 px square, and the tool in use has
|
|
7
|
-
the brand tint. The page's `showDrawingTools` hides the
|
|
8
|
-
|
|
7
|
+
the brand tint. The page's `showDrawingTools` hides the sketch tools (draw, erase, arrow, text) and their letters. Select
|
|
8
|
+
stays on the bar: that is how the person turns the widget's element selector on after the first generation. The Shapes
|
|
9
|
+
menu and the history group are always on the bar: a page that wants a leaner canvas hides the bar itself (`showToolbar`). On a
|
|
9
10
|
board narrower than the whole bar and its edges (381 px, so Figma's 358 px phone) the history group leaves the bar.
|
|
10
11
|
|
|
11
12
|
The bar stands where the page's `toolbarPosition` says. On the left or the right edge it stands upright: the same groups
|
|
@@ -57,10 +58,10 @@
|
|
|
57
58
|
class="canvas-toolbar-el pointer-events-auto 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"
|
|
58
59
|
data-canvas-ui
|
|
59
60
|
>
|
|
61
|
+
<ToolButton toggle label={$t('canvas.tool.select')} shortcut={TOOL_KEYS.select} alternateShortcut={TOOL_DIGIT_KEYS.select} active={state.tool === 'select'} onclick={() => host.onSelectSelectTool()}>
|
|
62
|
+
<IconPointer />
|
|
63
|
+
</ToolButton>
|
|
60
64
|
{#if showDrawingTools}
|
|
61
|
-
<ToolButton toggle label={$t('canvas.tool.select')} shortcut={TOOL_KEYS.select} alternateShortcut={TOOL_DIGIT_KEYS.select} active={state.tool === 'select'} onclick={() => host.onSelectSelectTool()}>
|
|
62
|
-
<IconPointer />
|
|
63
|
-
</ToolButton>
|
|
64
65
|
<ToolButton toggle label={$t('canvas.tool.draw')} shortcut={TOOL_KEYS.draw} alternateShortcut={TOOL_DIGIT_KEYS.draw} active={state.tool === 'draw'} onclick={() => host.onSelectDrawTool()}>
|
|
65
66
|
<IconPencil />
|
|
66
67
|
</ToolButton>
|
|
@@ -73,18 +74,20 @@
|
|
|
73
74
|
<ToolButton toggle label={$t('canvas.tool.text')} shortcut={TOOL_KEYS.text} alternateShortcut={TOOL_DIGIT_KEYS.text} active={state.tool === 'text'} onclick={() => host.onSelectTextTool()}>
|
|
74
75
|
<IconTypography />
|
|
75
76
|
</ToolButton>
|
|
77
|
+
{/if}
|
|
76
78
|
|
|
79
|
+
{#if showDrawingTools}
|
|
77
80
|
<Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
|
|
78
|
-
{/if}
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
<ShapesMenu
|
|
83
|
+
{host}
|
|
84
|
+
tool={state.tool}
|
|
85
|
+
libraryShapeKey={state.libraryShapeKey}
|
|
86
|
+
open={ui.shapesMenuOpen}
|
|
87
|
+
imageShortcut={TOOL_KEYS.image}
|
|
88
|
+
{showFiles}
|
|
89
|
+
/>
|
|
90
|
+
{/if}
|
|
88
91
|
|
|
89
92
|
<!-- The history group is the first thing a board too narrow for the whole bar gives up (Figma's phone): undo and redo stay on the keys. An upright bar is as long as the board is tall, so it keeps them. -->
|
|
90
93
|
<div
|
|
@@ -387,9 +387,9 @@
|
|
|
387
387
|
{/if}
|
|
388
388
|
{#each shownHandles as handle (handle)}
|
|
389
389
|
{#if layer === 'above-widgets'}
|
|
390
|
-
<!--
|
|
390
|
+
<!-- The drawn square stays the 8 px one. The 10 px box around it is only the hit, centred on the same corner. -->
|
|
391
391
|
<span
|
|
392
|
-
class="pointer-events-auto absolute flex size-
|
|
392
|
+
class="pointer-events-auto absolute flex size-[10px] -translate-x-1/2 -translate-y-1/2 touch-none items-center justify-center"
|
|
393
393
|
style="{handleStyle(handle)}cursor:{handleCursor(handle)};"
|
|
394
394
|
data-canvas-handle={handle}
|
|
395
395
|
role="presentation"
|
|
@@ -398,7 +398,7 @@
|
|
|
398
398
|
onpointerup={passReleaseToHost}
|
|
399
399
|
onpointercancel={passReleaseToHost}
|
|
400
400
|
>
|
|
401
|
-
<span class="size-2 rounded-[2px] border-[1.5px] border-ring bg-background"></span>
|
|
401
|
+
<span class="pointer-events-none size-2 rounded-[2px] border-[1.5px] border-ring bg-background"></span>
|
|
402
402
|
</span>
|
|
403
403
|
{:else}
|
|
404
404
|
<span
|
|
@@ -86,10 +86,18 @@
|
|
|
86
86
|
});
|
|
87
87
|
</script>
|
|
88
88
|
|
|
89
|
-
<Portal {target} style="z-index:
|
|
89
|
+
<Portal {target} style="z-index: 100000000; pointer-events: none;">
|
|
90
90
|
<!-- rtl-ok: physical left: 0 origin probe for getBoundingClientRect() -->
|
|
91
91
|
<span bind:this={fixedOriginEl} class="pointer-events-none fixed left-0 top-0 size-0" aria-hidden="true"></span>
|
|
92
|
-
|
|
92
|
+
<!-- data-canvas-ui: this layer is portaled above the live widgets, outside the canvas root. Without the mark, a press on a corner is an "outside" press and the selection is cleared before the resize starts. -->
|
|
93
|
+
<div class="canvas-widget-selection-layer pointer-events-none fixed overflow-visible" dir="ltr" data-canvas-widget-chrome data-canvas-ui style={layerStyle}>
|
|
93
94
|
<SelectionOverlay state={engineState} {host} {gestureKind} {advancedFeatures} layer="above-widgets" />
|
|
94
95
|
</div>
|
|
95
96
|
</Portal>
|
|
97
|
+
|
|
98
|
+
<style>
|
|
99
|
+
/* The portal turns pointer events on for its direct child. This layer covers the board, so only the handles may take a press. */
|
|
100
|
+
:global(.portal-contents) > .canvas-widget-selection-layer {
|
|
101
|
+
pointer-events: none !important;
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
@@ -56,8 +56,8 @@ export const TOOL_DIGITS = Object.freeze({
|
|
|
56
56
|
'4': 'arrow',
|
|
57
57
|
'5': 'text'
|
|
58
58
|
});
|
|
59
|
-
/**
|
|
60
|
-
const DRAWING_TOOLS = new Set(['
|
|
59
|
+
/** Sketch tools of the drawing bar: hidden (and so are their letters) when the host turns `showDrawingTools` off. Select stays. */
|
|
60
|
+
const DRAWING_TOOLS = new Set(['erase', 'draw', 'arrow', 'text']);
|
|
61
61
|
const ARROW_STEPS = Object.freeze({
|
|
62
62
|
ArrowUp: [0, -1],
|
|
63
63
|
ArrowDown: [0, 1],
|
|
@@ -266,7 +266,11 @@ function handleLayerKey(input, host) {
|
|
|
266
266
|
}
|
|
267
267
|
/** Whether the host lets the person use a tool (and so answers its letter). */
|
|
268
268
|
export function toolIsAvailable(tool, tools) {
|
|
269
|
-
|
|
269
|
+
if (tool === 'select' || tool === 'pan')
|
|
270
|
+
return true;
|
|
271
|
+
if (DRAWING_TOOLS.has(tool) || SHAPE_SHORTCUTS.has(tool) || tool === 'image')
|
|
272
|
+
return tools.drawing;
|
|
273
|
+
return true;
|
|
270
274
|
}
|
|
271
275
|
/**
|
|
272
276
|
* A key was pressed. Returns whether the board used it: the shell then calls `preventDefault()` so the browser
|
|
@@ -42,8 +42,9 @@ export function toolTheBoardOpensWith(options) {
|
|
|
42
42
|
const { rememberedToolId, showDrawingTools } = options;
|
|
43
43
|
if (!isRememberedTool(rememberedToolId))
|
|
44
44
|
return defaultFirstTool(showDrawingTools);
|
|
45
|
-
if (!showDrawingTools && isDrawingGroupTool(rememberedToolId))
|
|
45
|
+
if (!showDrawingTools && (isDrawingGroupTool(rememberedToolId) || SHAPE_TOOL_IDS.includes(rememberedToolId))) {
|
|
46
46
|
return defaultFirstTool(showDrawingTools);
|
|
47
|
+
}
|
|
47
48
|
return rememberedToolId;
|
|
48
49
|
}
|
|
49
50
|
/** The tool kept for this workspace and person, or null (nothing kept, no workspace to keep it for, a store that refuses, or a value that is no tool). */
|