@widgetic/canvas 0.5.46 → 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 +4 -1
- package/dist/canvas/DomCanvas.svelte +5 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +1 -0
- package/dist/canvas/eventScope.js +7 -1
- package/dist/canvas/host/CanvasHost.d.ts +5 -3
- package/dist/canvas/host/CanvasHost.js +114 -74
- package/dist/canvas/host/pauseCollector.d.ts +18 -0
- package/dist/canvas/host/pauseCollector.js +45 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
- package/dist/canvas/ui/CanvasHint.svelte +10 -9
- package/dist/canvas/ui/CanvasToolbar.svelte +17 -14
- package/dist/canvas/ui/SelectionPanel.svelte +14 -12
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
- package/dist/canvas/ui/ShapesMenu.svelte +6 -4
- package/dist/canvas/ui/ToolButton.svelte +7 -6
- package/dist/canvas/ui/floatingCard.d.ts +28 -8
- package/dist/canvas/ui/floatingCard.js +28 -8
- package/dist/canvas/ui/selectionTraits.d.ts +8 -4
- package/dist/canvas/ui/selectionTraits.js +10 -18
- package/dist/canvas/view/SelectionOverlay.svelte +5 -5
- package/dist/canvas/view/WidgetChromeLayer.svelte +10 -2
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +1 -1
- package/dist/components/input-controls/ColorIC.svelte +1 -1
- package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
- package/dist/engine/EngineCore.d.ts +33 -8
- package/dist/engine/EngineCore.js +66 -30
- package/dist/engine/core/brush.d.ts +24 -0
- package/dist/engine/core/brush.js +145 -13
- package/dist/engine/core/shapeTools.d.ts +23 -18
- package/dist/engine/core/shapeTools.js +45 -17
- package/dist/engine/core/style.d.ts +18 -2
- package/dist/engine/core/style.js +57 -25
- package/dist/engine/core/styleMemory.d.ts +88 -0
- package/dist/engine/core/styleMemory.js +189 -0
- package/dist/engine/input/gestures.d.ts +8 -3
- package/dist/engine/input/gestures.js +123 -48
- package/dist/engine/input/keyboard.js +14 -5
- package/dist/poster/boardPlacement.d.ts +4 -1
- package/dist/poster/boardPlacement.js +6 -3
- package/dist/settings/rememberedStyles.d.ts +22 -0
- package/dist/settings/rememberedStyles.js +47 -0
- package/dist/settings/rememberedTool.js +2 -1
- package/dist/settings/workspaceToolSettings.d.ts +17 -0
- package/dist/settings/workspaceToolSettings.js +4 -1
- package/dist/tools/hostAdapter.js +0 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -173,7 +173,8 @@ The saved canvas is a versioned document (`CANVAS_DOCUMENT_VERSION = 2`): a flat
|
|
|
173
173
|
empty with a notice and is left as it is until something new is added.
|
|
174
174
|
|
|
175
175
|
**The pencil is a brush.** A stroke is thicker where the hand slows down (a pen's own pressure draws it when the device reports
|
|
176
|
-
one), a click is a round dot, **Shift**
|
|
176
|
+
one), a click is a round dot, **Shift** held while drawing makes a straight line from where the pointer was when it went down (let
|
|
177
|
+
go, the line is kept and the stroke goes on by hand), and a resize makes a stroke longer, never fatter. A board saves
|
|
177
178
|
each stroke as its line and its pressures (`ink`) and draws the outline again when it is read.
|
|
178
179
|
|
|
179
180
|
**An arrow is two points and a bend.** Its open head keeps its size when the arrow is stretched, a selected arrow has a handle
|
|
@@ -239,6 +240,8 @@ Each prints one line per check and exits 1 when one fails. `__docs/dom-canvas.md
|
|
|
239
240
|
|
|
240
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.
|
|
241
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
|
+
|
|
242
245
|
## License
|
|
243
246
|
|
|
244
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.
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
// selector's indicator is a card of its own at the top.)
|
|
79
79
|
export let toolbarPosition: ToolbarPosition = DEFAULT_TOOLBAR_POSITION;
|
|
80
80
|
|
|
81
|
-
// Wireframe mode:
|
|
81
|
+
// Wireframe mode: new objects start white with a dark stroke (the colour fields of the selection panel are there in either look)
|
|
82
82
|
export let wireframeMode: CanvasHostProps['wireframeMode'] = DEFAULT_HOST_PROPS.wireframeMode;
|
|
83
83
|
|
|
84
84
|
// The advanced chrome of a widget card: with it on a card can be turned, and the primary widget has its ring. With it off
|
|
@@ -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.
|
|
@@ -529,7 +532,6 @@
|
|
|
529
532
|
{host}
|
|
530
533
|
state={engineState}
|
|
531
534
|
ui={uiState}
|
|
532
|
-
{wireframeMode}
|
|
533
535
|
canCapture={!!onObjectClick}
|
|
534
536
|
canConvert={!!(onWidgetRename || onRefreshScreenshot || onWidgetImageClick || onSetPrimaryWidget)}
|
|
535
537
|
canRename={!!onWidgetRename}
|
|
@@ -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
|
|
@@ -20,7 +20,6 @@ import type { EngineState, PenStyle, ToolId } from '../../engine/state.js';
|
|
|
20
20
|
import { ConversionRegistry } from '../../engine/widgets.js';
|
|
21
21
|
import type { WidgetMetadata } from '../../engine/widgets.js';
|
|
22
22
|
import { type WorkspaceCanvasFont } from '../../fonts/workspaceFonts.js';
|
|
23
|
-
import type { StylePatch } from '../../engine/core/style.js';
|
|
24
23
|
import type { PanZoomPosition } from '../panZoomPosition.js';
|
|
25
24
|
import type { ToolbarPosition } from '../toolbarPosition.js';
|
|
26
25
|
import type { Translate as CatalogTranslate } from '@widgetic/design-system/i18n';
|
|
@@ -71,6 +70,11 @@ export interface CanvasHostProps {
|
|
|
71
70
|
* not closed it (see `onDismissElementSelectorHint`). The toolbar is not affected: it stays as `showDrawingTools` says.
|
|
72
71
|
*/
|
|
73
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;
|
|
74
78
|
showDrawingTools: boolean;
|
|
75
79
|
/**
|
|
76
80
|
* The page's element selector is picking elements of the widget now (the Select tool is chosen and the page has not paused
|
|
@@ -234,8 +238,6 @@ export declare class CanvasHost {
|
|
|
234
238
|
constructor(initialProps?: Partial<CanvasHostProps>);
|
|
235
239
|
/** The page changed some props. */
|
|
236
240
|
setProps(patch: Partial<CanvasHostProps>): void;
|
|
237
|
-
/** Persists tool style changes for this workspace (called from the selection panel). */
|
|
238
|
-
persistWorkspaceStyle(patch: StylePatch): void;
|
|
239
241
|
/**
|
|
240
242
|
* Sets the pen, the line the Draw tool draws next (its colour, its width, how much of the board shows through it), and keeps it
|
|
241
243
|
* for this workspace, so the pen is the same when the page is opened again. The settings panel calls it while the Draw tool is
|
|
@@ -26,10 +26,11 @@ import { ensureInterFontLoaded } from '../../fonts/interFont.js';
|
|
|
26
26
|
import { registerWorkspaceFonts } from '../../fonts/workspaceFonts.js';
|
|
27
27
|
import { isCanvasOwnedTarget } from '../outsideClickDeselect.js';
|
|
28
28
|
import { flushWorkspaceToolSettingsPending, loadWorkspaceToolSettings, saveWorkspaceToolSettingsDebounced } from '../../settings/workspaceToolSettings.js';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
29
|
+
import { rememberedStylesOfSettings, settingsOfRememberedStyles } from '../../settings/rememberedStyles.js';
|
|
30
|
+
import { readRememberedToolId, toolTheBoardOpensWith, toolToRemember } from '../../settings/rememberedTool.js';
|
|
31
|
+
import { canvasLog, canvasWarn, isCanvasLogsEnabled, setCanvasLogsEnabled } from '../canvasLogger.js';
|
|
31
32
|
import { CANVAS_OPEN_MARKS, markCanvasOpenStep } from '../openMarks.js';
|
|
32
|
-
import { eventIsForScope, getEventOrigin, shouldTakeFocusBack } from '../eventScope.js';
|
|
33
|
+
import { eventIsForScope, getEventOrigin, getFocusedElementIn, shouldTakeFocusBack } from '../eventScope.js';
|
|
33
34
|
import { getShapeImageStore, shapeImageRef } from '../shapes/shapeImageStore.js';
|
|
34
35
|
import { BOARD_FILE_KINDS, applyLibraryFile, normalizeLibraryFiles } from './boardFiles.js';
|
|
35
36
|
import { chooseImageFiles, createBrowserMeasureText, createBrowserRasterServices, readImageFile, readLibraryPicture } from './browserServices.js';
|
|
@@ -42,6 +43,7 @@ import { createPictureSaveMemory } from './pictureSaves.js';
|
|
|
42
43
|
// `countPicturesInView` is only used by the log of `#resolveStoredImages` that is commented out.
|
|
43
44
|
import { /* countPicturesInView, */ fillPictures, picturesStillMissing, startLoadingPictures, waitUpTo } from './storedPictures.js';
|
|
44
45
|
import { isShapeSnapOn, snapDrawnStroke } from './strokeSnap.js';
|
|
46
|
+
import { createPauseCollector } from './pauseCollector.js';
|
|
45
47
|
import { createCanvasToolHostFromEngine, executeCanvasTool, summarizeScene } from '../../tools/index.js';
|
|
46
48
|
import { isCanvasToolName } from '../../tools/definitions.js';
|
|
47
49
|
/** What each prop is until the page sets it (the values the canvas this one replaces had, but for `panZoomPosition`). */
|
|
@@ -54,6 +56,7 @@ export const DEFAULT_HOST_PROPS = Object.freeze({
|
|
|
54
56
|
wireframeMode: true,
|
|
55
57
|
advancedFeatures: false,
|
|
56
58
|
showElementSelector: false,
|
|
59
|
+
showToolbar: true,
|
|
57
60
|
showDrawingTools: true,
|
|
58
61
|
elementSelectorActive: false,
|
|
59
62
|
onToggleElementSelector: null,
|
|
@@ -170,7 +173,11 @@ const isEditableTarget = (element) => {
|
|
|
170
173
|
if (!element)
|
|
171
174
|
return false;
|
|
172
175
|
const tag = element.tagName;
|
|
173
|
-
|
|
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=""]'));
|
|
174
181
|
};
|
|
175
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). */
|
|
176
183
|
const hasSameEntries = (first, second) => first.length === second.length && first.every((entry, index) => entry === second[index]);
|
|
@@ -210,6 +217,11 @@ const isActivatableTarget = (element) => {
|
|
|
210
217
|
};
|
|
211
218
|
/** The part of the page a paste is not meant for (the creator's own panels and lists). */
|
|
212
219
|
const PASTE_EXCLUDED_SELECTOR = '.widget-details-floating-panel, .widgets-list-panel, [data-widget-details]';
|
|
220
|
+
/**
|
|
221
|
+
* How long the person has to pause before the console says what the next elements start with: as long as the settings of a workspace
|
|
222
|
+
* wait to be written (`workspaceToolSettings.ts`), so a drag of a slider or of a colour picker says it once, and not for every step.
|
|
223
|
+
*/
|
|
224
|
+
const STYLE_LOG_DELAY_MS = 400;
|
|
213
225
|
// ──────────────────────────────────────────────────────────── the host
|
|
214
226
|
export class CanvasHost {
|
|
215
227
|
engine;
|
|
@@ -266,9 +278,14 @@ export class CanvasHost {
|
|
|
266
278
|
#wasEditingText = false;
|
|
267
279
|
/** The board is about to take the keyboard back from a text field that left the page (asked for the next frame). */
|
|
268
280
|
#keyboardReturnQueued = false;
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
281
|
+
/**
|
|
282
|
+
* The workspace and the person whose tool settings (the style the next elements start with, the pen, the font of the texts) were last
|
|
283
|
+
* taken from the storage into the engine (null: none yet), so that they are read once for each. After that the engine is the one that
|
|
284
|
+
* knows: what the person has just chosen may not be in the storage yet.
|
|
285
|
+
*/
|
|
286
|
+
#toolSettingsScopeApplied = null;
|
|
287
|
+
/** The kinds of element whose style changed since the console last said so (the line is written once the person pauses, see `#logStyleRememberedSoon`). */
|
|
288
|
+
#styleChangesToLog = createPauseCollector(STYLE_LOG_DELAY_MS, (kinds) => this.#logStyleRemembered(kinds));
|
|
272
289
|
/** The tool at the last change of the engine (null: none yet), to tell the moment the Draw tool is left from any other change. */
|
|
273
290
|
#toolAtLastEngineState = null;
|
|
274
291
|
/** The animation frame that steps the eraser's trail (null: none asked for), and when the trail was last stepped (null: the clock is idle). */
|
|
@@ -292,6 +309,9 @@ export class CanvasHost {
|
|
|
292
309
|
const preferredTextFontFamily = readPreferredTextFontFamily();
|
|
293
310
|
if (preferredTextFontFamily)
|
|
294
311
|
this.engine.setPreferredTextFontFamily(preferredTextFontFamily);
|
|
312
|
+
// What was kept for this workspace and this person (the style the next elements start with, the pen, the font of the texts): taken
|
|
313
|
+
// now, before anything can be drawn, and again only when the page says it is another workspace or person (see `setProps`).
|
|
314
|
+
this.#applyWorkspaceToolSettings();
|
|
295
315
|
this.controller = new PointerController(this.engine, {
|
|
296
316
|
snapEnabled: () => true,
|
|
297
317
|
onStrokeFinished: (stroke, handLine) => this.#handleStrokeFinished(stroke, handLine),
|
|
@@ -343,6 +363,9 @@ export class CanvasHost {
|
|
|
343
363
|
if (this.props.isExternalDataLoading !== previous.isExternalDataLoading) {
|
|
344
364
|
queueMicrotask(() => this.#syncEmptyHintGate());
|
|
345
365
|
}
|
|
366
|
+
// Another workspace or another person: their tool settings are the board's from now on (read at once, not after the fonts).
|
|
367
|
+
if (this.props.workspaceId !== previous.workspaceId || this.props.userId !== previous.userId)
|
|
368
|
+
this.#applyWorkspaceToolSettings();
|
|
346
369
|
if (this.props.workspaceId !== previous.workspaceId ||
|
|
347
370
|
this.props.userId !== previous.userId ||
|
|
348
371
|
this.props.workspaceFonts !== previous.workspaceFonts) {
|
|
@@ -356,50 +379,48 @@ export class CanvasHost {
|
|
|
356
379
|
});
|
|
357
380
|
}
|
|
358
381
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
382
|
+
/**
|
|
383
|
+
* The person restyled something, and so changed what the next element of some kinds starts with (the engine remembers it, and says
|
|
384
|
+
* which kinds changed: `EngineHooks.onStyleRemembered`). The engine is what makes the next shape, arrow or text start that way, from
|
|
385
|
+
* the very next one; this keeps it for the workspace and the person, so a board opened again starts that way too. The write waits a
|
|
386
|
+
* moment, so a drag of a slider or a colour picker writes once, and is flushed when the page is hidden; each kind is written to its
|
|
387
|
+
* own part of the settings, so restyling an arrow never changes what the shapes or the texts keep. Without a workspace nothing is
|
|
388
|
+
* kept: the engine remembers for as long as the board is open.
|
|
389
|
+
*/
|
|
390
|
+
#onStyleRemembered(kinds) {
|
|
391
|
+
this.#logStyleRememberedSoon(kinds);
|
|
365
392
|
const workspaceId = this.props.workspaceId;
|
|
366
393
|
if (!workspaceId)
|
|
367
394
|
return;
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
patch.strokeWidth !== undefined ||
|
|
388
|
-
patch.strokeStyle !== undefined ||
|
|
389
|
-
patch.opacity !== undefined ||
|
|
390
|
-
patch.roundness !== undefined
|
|
391
|
-
? this.#compactStylePatch({
|
|
392
|
-
fill: patch.fill,
|
|
393
|
-
stroke: patch.stroke,
|
|
394
|
-
strokeWidth: patch.strokeWidth,
|
|
395
|
-
strokeStyle: patch.strokeStyle,
|
|
396
|
-
opacity: patch.opacity,
|
|
397
|
-
roundness: patch.roundness
|
|
398
|
-
})
|
|
399
|
-
: undefined;
|
|
400
|
-
if (!textPatch && !paintPatch)
|
|
395
|
+
try {
|
|
396
|
+
const patchedKinds = kinds.filter((kind) => kind !== 'pen');
|
|
397
|
+
const settings = settingsOfRememberedStyles(this.engine.rememberedStyles, patchedKinds);
|
|
398
|
+
if (Object.keys(settings).length > 0)
|
|
399
|
+
saveWorkspaceToolSettingsDebounced({ workspaceId, userId: this.props.userId }, settings);
|
|
400
|
+
// A line drawn by hand that was restyled is the pen of the Draw tool from then on: kept with the pen's other writes.
|
|
401
|
+
if (kinds.includes('pen'))
|
|
402
|
+
this.#persistPenStyle(this.engine.state.penStyle);
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
canvasWarn('Canvas: the style of the next elements could not be kept', error);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Says in the console, once the person pauses (not for every step of a drag), which kinds of element start differently from now on and
|
|
410
|
+
* with what: one line for a burst of changes. Nothing is gathered when the page has the canvas logs off.
|
|
411
|
+
*/
|
|
412
|
+
#logStyleRememberedSoon(kinds) {
|
|
413
|
+
if (!isCanvasLogsEnabled() || this.#destroyed)
|
|
401
414
|
return;
|
|
402
|
-
|
|
415
|
+
this.#styleChangesToLog.add(kinds);
|
|
416
|
+
}
|
|
417
|
+
/** The line of the console for the kinds that changed (see `#logStyleRememberedSoon`), with what each starts with now. */
|
|
418
|
+
#logStyleRemembered(kinds) {
|
|
419
|
+
if (this.#destroyed)
|
|
420
|
+
return;
|
|
421
|
+
const remembered = this.engine.rememberedStyles;
|
|
422
|
+
const startsWith = Object.fromEntries(kinds.map((kind) => [kind, kind === 'pen' ? { ...this.engine.state.penStyle } : { ...remembered[kind] }]));
|
|
423
|
+
canvasLog('Canvas: the next elements start with the style just chosen', startsWith);
|
|
403
424
|
}
|
|
404
425
|
/**
|
|
405
426
|
* Sets the pen, the line the Draw tool draws next (its colour, its width, how much of the board shows through it), and keeps it
|
|
@@ -436,44 +457,57 @@ export class CanvasHost {
|
|
|
436
457
|
setWorkspaceFontFamilies(fonts.map((font) => font.family));
|
|
437
458
|
await registerWorkspaceFonts(fonts);
|
|
438
459
|
this.engine.notifyFontsChanged();
|
|
460
|
+
// The tool settings of the workspace are taken from the storage when the workspace is known (the constructor, `setProps`), not
|
|
461
|
+
// here: this runs again each time the page passes its fonts, and by now the person may have chosen something the storage does not
|
|
462
|
+
// hold yet. Called all the same, it takes nothing back for a workspace and person it has already read.
|
|
463
|
+
this.#applyWorkspaceToolSettings();
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Takes what was kept for this workspace and this person into the engine: the style the next shapes, arrows and texts start with
|
|
467
|
+
* (what the person last chose for each kind of element), the font the next text uses, and the pen of the Draw tool. A workspace and
|
|
468
|
+
* a person that were never styled start from the standard looks. Done once for each workspace and person: after that the engine is
|
|
469
|
+
* the one that knows, and what the storage holds may be a moment behind (the write waits for the person to pause), so a page that
|
|
470
|
+
* passes its fonts again must not take any of it back. Without a workspace nothing is read, and nothing is kept either.
|
|
471
|
+
*/
|
|
472
|
+
#applyWorkspaceToolSettings() {
|
|
439
473
|
const workspaceId = this.props.workspaceId;
|
|
440
474
|
if (!workspaceId)
|
|
441
475
|
return;
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (penScope !== this.#penScopeApplied) {
|
|
460
|
-
this.#penScopeApplied = penScope;
|
|
461
|
-
// What the storage holds is checked key by key by `setPenStyle`: a key that is no value stays what the standard pen has.
|
|
476
|
+
const scope = `${workspaceId}\u0000${this.props.userId ?? ''}`;
|
|
477
|
+
if (scope === this.#toolSettingsScopeApplied)
|
|
478
|
+
return;
|
|
479
|
+
this.#toolSettingsScopeApplied = scope;
|
|
480
|
+
try {
|
|
481
|
+
const settings = loadWorkspaceToolSettings({ workspaceId, userId: this.props.userId });
|
|
482
|
+
const textFamily = settings?.text?.fontFamily;
|
|
483
|
+
if (textFamily) {
|
|
484
|
+
this.engine.setPreferredTextFontFamily(textFamily);
|
|
485
|
+
writePreferredTextFontFamily(textFamily);
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
this.engine.setPreferredTextFontFamily(TEXT_DEFAULTS.fontFamily);
|
|
489
|
+
}
|
|
490
|
+
// What the storage holds is checked key by key by the engine: a key that is no value of its kind is dropped.
|
|
491
|
+
this.engine.setRememberedStyles(rememberedStylesOfSettings(settings));
|
|
492
|
+
// The pen: the one that was kept, or the standard pen where none was (checked key by key by `setPenStyle` as well).
|
|
462
493
|
this.engine.setPenStyle(DEFAULT_PEN_STYLE);
|
|
463
|
-
if (
|
|
464
|
-
this.engine.setPenStyle(
|
|
494
|
+
if (settings?.pen)
|
|
495
|
+
this.engine.setPenStyle(settings.pen);
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
canvasWarn('Canvas: the tool settings of the workspace could not be read', error);
|
|
465
499
|
}
|
|
466
500
|
}
|
|
467
501
|
/**
|
|
468
502
|
* A tool whose button the page hides must not stay armed: once the page takes the drawing tools off (after the first
|
|
469
|
-
* generation) the pencil, the eraser, the arrow and the
|
|
470
|
-
* 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`).
|
|
471
505
|
*/
|
|
472
506
|
#dropToolsThePageHides() {
|
|
473
507
|
if (this.props.showDrawingTools)
|
|
474
508
|
return;
|
|
475
509
|
const { tool } = this.engine.state;
|
|
476
|
-
if (
|
|
510
|
+
if (tool === 'select' || tool === 'pan')
|
|
477
511
|
return;
|
|
478
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.
|
|
479
513
|
this.#toolChangeIsNotAChoice = true;
|
|
@@ -670,6 +704,9 @@ export class CanvasHost {
|
|
|
670
704
|
cancelAnimationFrame(this.#scribbleFrame);
|
|
671
705
|
this.#scribbleFrame = null;
|
|
672
706
|
this.#scribbleClockLast = null;
|
|
707
|
+
// The console line about the style the person just chose is not written for a board that is gone (what is kept for the workspace
|
|
708
|
+
// is written by the storage's own timer, which outlives the host).
|
|
709
|
+
this.#styleChangesToLog.cancel();
|
|
673
710
|
this.#scheduler.dispose();
|
|
674
711
|
for (const remove of this.#removeListeners)
|
|
675
712
|
remove();
|
|
@@ -1004,7 +1041,7 @@ export class CanvasHost {
|
|
|
1004
1041
|
controller: this.controller,
|
|
1005
1042
|
actions: this.#keyboardActions(),
|
|
1006
1043
|
tools: this.tools,
|
|
1007
|
-
typingInField: isEditableTarget(origin),
|
|
1044
|
+
typingInField: isEditableTarget(origin) || isEditableTarget(getFocusedElementIn(this.#root)),
|
|
1008
1045
|
hasTextSelection,
|
|
1009
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).
|
|
1010
1047
|
selectorHintOpen: this.props.elementSelectorActive
|
|
@@ -1119,6 +1156,8 @@ export class CanvasHost {
|
|
|
1119
1156
|
onDraftChange: () => this.#markDirty(),
|
|
1120
1157
|
onCleared: (cause) => this.#safely(() => this.props.onCanvasCleared?.(cause), 'onCanvasCleared'),
|
|
1121
1158
|
onSelectionChange: (ids) => this.#onSelectionChange(ids),
|
|
1159
|
+
// The person restyled something: the next elements of that kind start that way, and it is kept for the workspace.
|
|
1160
|
+
onStyleRemembered: (kinds) => this.#onStyleRemembered(kinds),
|
|
1122
1161
|
confirmWidgetDeletion: (widgetId) => {
|
|
1123
1162
|
const ask = this.props.onWidgetShapeDeleting;
|
|
1124
1163
|
return ask ? ask(widgetId) : true;
|
|
@@ -1818,7 +1857,8 @@ export class CanvasHost {
|
|
|
1818
1857
|
wireframe: this.engine.wireframeMode,
|
|
1819
1858
|
createId: this.engine.services.createId,
|
|
1820
1859
|
random: this.engine.services.random,
|
|
1821
|
-
|
|
1860
|
+
// What the person last chose for this kind of shape (the panel's last edit), as for a shape dragged out
|
|
1861
|
+
rememberedStyles: this.engine.rememberedStyles
|
|
1822
1862
|
});
|
|
1823
1863
|
}
|
|
1824
1864
|
addRect() {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gathers what happens in a burst (the steps of a drag of a slider, the ticks of a colour picker) and hands it over once, when the burst
|
|
3
|
+
* pauses: the host uses it to say a thing in the console once for a drag and not once for every step of it.
|
|
4
|
+
*
|
|
5
|
+
* It is only a delay and a set: nothing is ever kept past the pause, and a collector that is cancelled (the board is closed) says nothing.
|
|
6
|
+
* The delay is the host's to choose, so the console says it at the moment the settings of the workspace are written (400 ms).
|
|
7
|
+
*/
|
|
8
|
+
export interface PauseCollector<Item> {
|
|
9
|
+
/** Notes what happened and starts the wait again: the pause is counted from the last thing that happened. */
|
|
10
|
+
add(items: readonly Item[]): void;
|
|
11
|
+
/** Forgets what was gathered and says nothing about it (the board is gone). */
|
|
12
|
+
cancel(): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @param delayMs How long nothing may happen before what was gathered is handed over.
|
|
16
|
+
* @param onPause Called once for each burst with what happened in it, each item once, in the order it first happened.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createPauseCollector<Item>(delayMs: number, onPause: (items: Item[]) => void): PauseCollector<Item>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gathers what happens in a burst (the steps of a drag of a slider, the ticks of a colour picker) and hands it over once, when the burst
|
|
3
|
+
* pauses: the host uses it to say a thing in the console once for a drag and not once for every step of it.
|
|
4
|
+
*
|
|
5
|
+
* It is only a delay and a set: nothing is ever kept past the pause, and a collector that is cancelled (the board is closed) says nothing.
|
|
6
|
+
* The delay is the host's to choose, so the console says it at the moment the settings of the workspace are written (400 ms).
|
|
7
|
+
*/
|
|
8
|
+
import { canvasWarn } from '../canvasLogger.js';
|
|
9
|
+
/**
|
|
10
|
+
* @param delayMs How long nothing may happen before what was gathered is handed over.
|
|
11
|
+
* @param onPause Called once for each burst with what happened in it, each item once, in the order it first happened.
|
|
12
|
+
*/
|
|
13
|
+
export function createPauseCollector(delayMs, onPause) {
|
|
14
|
+
const gathered = new Set();
|
|
15
|
+
let timer = null;
|
|
16
|
+
const cancel = () => {
|
|
17
|
+
if (timer !== null)
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
timer = null;
|
|
20
|
+
gathered.clear();
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
add(items) {
|
|
24
|
+
if (items.length === 0)
|
|
25
|
+
return;
|
|
26
|
+
for (const item of items)
|
|
27
|
+
gathered.add(item);
|
|
28
|
+
if (timer !== null)
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
timer = setTimeout(() => {
|
|
31
|
+
timer = null;
|
|
32
|
+
const burst = [...gathered];
|
|
33
|
+
gathered.clear();
|
|
34
|
+
// A handler that fails must not take the page with it: it is a console line.
|
|
35
|
+
try {
|
|
36
|
+
onPause(burst);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
canvasWarn('Canvas: a pause handler failed', error);
|
|
40
|
+
}
|
|
41
|
+
}, delayMs);
|
|
42
|
+
},
|
|
43
|
+
cancel
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -17,7 +17,14 @@
|
|
|
17
17
|
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
18
18
|
import { ariaKeyShortcut, isApplePlatform, menuChordText } from './keyHints.js';
|
|
19
19
|
import type { Chord } from './keyHints.js';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
CANVAS_OVERLAY_Z_CLASS,
|
|
22
|
+
LAYER_MENU_ALIGN_OFFSET_PX,
|
|
23
|
+
LAYER_MENU_PADDING_CLASS,
|
|
24
|
+
MENU_PADDING_CLASS,
|
|
25
|
+
OVERLAY_REDUCED_MOTION_CLASSES,
|
|
26
|
+
SUBMENU_SLIDE_UP_CLASSES
|
|
27
|
+
} from './floatingCard.js';
|
|
21
28
|
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
22
29
|
|
|
23
30
|
interface Props {
|
|
@@ -109,6 +116,31 @@
|
|
|
109
116
|
event.preventDefault();
|
|
110
117
|
host.focusBoard();
|
|
111
118
|
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* How far, in pixels, the mouse must travel from where the menu opened before letting go over an entry is a choice (press,
|
|
122
|
+
* drag to an entry, release: the way a menu of the system works). Less than that is the hand's own shake while it clicks.
|
|
123
|
+
*/
|
|
124
|
+
const RELEASE_TRAVEL_IN_PIXELS = 4;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The right button opens the menu as it goes down (on a Mac and on Linux), so its release comes after the menu is on the page,
|
|
128
|
+
* and the menu can be under the pointer by then: drawn upward, when the press was low on the board, its last entry ("Delete")
|
|
129
|
+
* is at the pointer, and while the design system's menu slides in it is a few pixels lower still. The menu's own handling of a
|
|
130
|
+
* release that was not pressed on an entry is to choose that entry, so a right click low on the board could delete what was
|
|
131
|
+
* selected. A release that has not left the point where the menu opened ends the press that opened it: it is not a choice, and
|
|
132
|
+
* the entry under it is left alone (the touch case is `choose`, above). A release after a real drag onto an entry is a choice.
|
|
133
|
+
*/
|
|
134
|
+
function keepReleaseOfOpeningPressFromChoosing(event: PointerEvent): void {
|
|
135
|
+
try {
|
|
136
|
+
if (event.pointerType === 'touch' || !point || !board) return;
|
|
137
|
+
const rect = board.getBoundingClientRect();
|
|
138
|
+
const travelInPixels = Math.hypot(event.clientX - (rect.left + point.x), event.clientY - (rect.top + point.y));
|
|
139
|
+
if (travelInPixels < RELEASE_TRAVEL_IN_PIXELS) event.preventDefault();
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.warn('[CanvasContextMenu] could not tell the release of the opening press from a choice', error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
112
144
|
</script>
|
|
113
145
|
|
|
114
146
|
<!-- The keys are written beside the name for the eye (hidden from the name a screen reader reads) and given as `aria-keyshortcuts`. -->
|
|
@@ -156,6 +188,7 @@
|
|
|
156
188
|
sideOffset={point?.byTouch ? TOUCH_MENU_OFFSET : 0}
|
|
157
189
|
portalProps={canvasOverlayPortalProps($floatingLayer)}
|
|
158
190
|
onCloseAutoFocus={returnFocusToBoard}
|
|
191
|
+
onpointerupcapture={keepReleaseOfOpeningPressFromChoosing}
|
|
159
192
|
aria-label={$t('canvas.panel.actions')}
|
|
160
193
|
data-canvas-ui
|
|
161
194
|
data-canvas-context-menu
|
|
@@ -173,13 +206,17 @@
|
|
|
173
206
|
<DropdownMenu.SubTrigger class="h-8 min-h-8 gap-2 px-2 py-1.5" disabled={!hasSelection}>
|
|
174
207
|
<span class="flex-1 text-body">{$t('canvas.layer.title')}</span>
|
|
175
208
|
</DropdownMenu.SubTrigger>
|
|
209
|
+
<!--
|
|
210
|
+
The first row of the submenu stands level with "Layer order" (`LAYER_MENU_ALIGN_OFFSET_PX` lifts the card by its border and
|
|
211
|
+
padding), and the submenu fades in and slides up like the Shapes menu (`SUBMENU_SLIDE_UP_CLASSES`).
|
|
212
|
+
-->
|
|
176
213
|
<DropdownMenu.SubContent
|
|
177
214
|
align="start"
|
|
178
|
-
alignOffset={
|
|
215
|
+
alignOffset={LAYER_MENU_ALIGN_OFFSET_PX}
|
|
179
216
|
sideOffset={13}
|
|
180
217
|
aria-label={$t('canvas.layer.title')}
|
|
181
218
|
data-canvas-layer-menu
|
|
182
|
-
class="{CANVAS_OVERLAY_Z_CLASS} w-[220px] rounded-xl border border-border bg-popover {LAYER_MENU_PADDING_CLASS} shadow-floating {OVERLAY_REDUCED_MOTION_CLASSES}"
|
|
219
|
+
class="{CANVAS_OVERLAY_Z_CLASS} w-[220px] rounded-xl border border-border bg-popover {LAYER_MENU_PADDING_CLASS} shadow-floating {SUBMENU_SLIDE_UP_CLASSES} {OVERLAY_REDUCED_MOTION_CLASSES}"
|
|
183
220
|
>
|
|
184
221
|
{#each layerRows as row (row.mode)}
|
|
185
222
|
{@render layerMenuRowView(row)}
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
board and never in the way of the pointer. It is shown while the board holds nothing, and goes the moment something is
|
|
4
4
|
drawn. A page that words the line under the title as an empty message (`messages`) gets the tile and the title only.
|
|
5
5
|
|
|
6
|
-
Where it stands:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
the
|
|
6
|
+
Where it stands: on the middle of the board, at any height and any width. A board that is dragged taller (the sketch card of
|
|
7
|
+
the Home page) keeps the hint half way down, as far from the top as from the bottom; it is not held at a fixed distance from the
|
|
8
|
+
top (the design's 312 px), which left it high on a tall board. The toolbar is 44 px high and stands 16 px from the bottom, so a
|
|
9
|
+
board as short as the 320 px card of the Home page still shows the whole hint above it.
|
|
10
|
+
|
|
11
|
+
Its words are said as the design system's empty state says them ("No widgets yet" in an empty project): the title and the line
|
|
12
|
+
under it in the muted colour. The tile keeps the board's own look: the board is `muted`, so a tile of that colour would vanish.
|
|
10
13
|
-->
|
|
11
14
|
<script lang="ts">
|
|
12
15
|
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
@@ -18,17 +21,15 @@
|
|
|
18
21
|
const hintDescription = $derived($t('canvas.hint.description'));
|
|
19
22
|
</script>
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<div class="max-h-[312px] min-h-0 flex-1 max-md:hidden"></div>
|
|
24
|
+
<!-- The hint is centred on the whole board (the same on a phone); the 24 px at the sides keep it off the edges of a narrow board. -->
|
|
25
|
+
<div class="pointer-events-none absolute inset-0 flex items-center justify-center px-6" data-canvas-hint>
|
|
24
26
|
<div class="flex w-80 max-w-full flex-col items-center gap-2.5 text-center">
|
|
25
27
|
<div class="flex size-9 items-center justify-center rounded-lg border border-border bg-background text-foreground">
|
|
26
28
|
<IconPencil class="size-4 stroke-[1.333]" aria-hidden="true" />
|
|
27
29
|
</div>
|
|
28
|
-
<p class="text-body-medium text-foreground">{$t('canvas.hint.title')}</p>
|
|
30
|
+
<p class="text-body-medium text-muted-foreground">{$t('canvas.hint.title')}</p>
|
|
29
31
|
{#if hintDescription}
|
|
30
32
|
<p class="text-body text-muted-foreground" data-canvas-hint-description>{hintDescription}</p>
|
|
31
33
|
{/if}
|
|
32
34
|
</div>
|
|
33
|
-
<div class="min-h-0 flex-1 max-md:hidden"></div>
|
|
34
35
|
</div>
|