@widgetic/canvas 0.5.21 → 0.5.23
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 -0
- package/dist/canvas/Canvas.svelte +76 -25
- package/dist/canvas/Canvas.svelte.d.ts +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -155,3 +155,7 @@ reads the language of that canvas, so two canvases on one page can speak two lan
|
|
|
155
155
|
- Simplified the edit lifecycle: Fabric now handles hover/edit visuals, while we ensure placeholders restore after `editing:exited` and outside clicks call `exitEditing()`.
|
|
156
156
|
- Kept textbox focusing logic lightweight—just focus the hidden textarea and rely on Fabric’s built-in selection/caret behaviour.
|
|
157
157
|
- Resolved previous lint warnings in `src/lib/canvas/tools/ToolController.ts` by tightening event typings and removing unused overlay helpers.
|
|
158
|
+
|
|
159
|
+
## Publishing
|
|
160
|
+
|
|
161
|
+
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.
|
|
@@ -216,6 +216,10 @@
|
|
|
216
216
|
// Lower = more frequent saves, higher = less API pressure. Default: 3000ms.
|
|
217
217
|
export let autosaveDelayMs: number = 3000;
|
|
218
218
|
|
|
219
|
+
// While set, a due autosave waits another delay instead of serializing.
|
|
220
|
+
// Serializing during code generation blocks the page thread for the whole save.
|
|
221
|
+
export let suspendAutosave: boolean = false;
|
|
222
|
+
|
|
219
223
|
// Show a save button in the bottom-right corner of the canvas.
|
|
220
224
|
// Displays a dirty indicator (●) when unsaved changes exist.
|
|
221
225
|
export let showSaveButton: boolean = false;
|
|
@@ -306,6 +310,12 @@
|
|
|
306
310
|
* suffixes below encode that lifecycle contract (init → teardown).
|
|
307
311
|
*/
|
|
308
312
|
let canvas: Canvas | null = null;
|
|
313
|
+
// One overlay move per turn. Hiding the Fabric image asks for another paint;
|
|
314
|
+
// that paint must not move the overlay again, or the turn never ends.
|
|
315
|
+
let overlaySyncQueued = false;
|
|
316
|
+
let applyingOverlaySync = false;
|
|
317
|
+
let ignoreOverlayAfterRender = false;
|
|
318
|
+
let overlayPaintAfterSync = false;
|
|
309
319
|
|
|
310
320
|
// The language of everything on the canvas: the toolbar, the panels and the menu read their words from it, and the
|
|
311
321
|
// shapes read the words they draw onto the canvas itself (see i18n/shapeWords.ts).
|
|
@@ -1423,6 +1433,33 @@
|
|
|
1423
1433
|
}
|
|
1424
1434
|
}
|
|
1425
1435
|
|
|
1436
|
+
/**
|
|
1437
|
+
* Move the live iframes on a later frame, at most once per turn.
|
|
1438
|
+
* A paint that this move itself requested is ignored, so after:render
|
|
1439
|
+
* cannot call back into the move before the browser gets another turn.
|
|
1440
|
+
*/
|
|
1441
|
+
function queueWidgetPreviewOverlaySync(): void {
|
|
1442
|
+
if (!onAfterRender || overlaySyncQueued || applyingOverlaySync) return;
|
|
1443
|
+
overlaySyncQueued = true;
|
|
1444
|
+
requestAnimationFrame(() => {
|
|
1445
|
+
overlaySyncQueued = false;
|
|
1446
|
+
if (!onAfterRender || applyingOverlaySync) return;
|
|
1447
|
+
applyingOverlaySync = true;
|
|
1448
|
+
try {
|
|
1449
|
+
onAfterRender();
|
|
1450
|
+
} catch (err) {
|
|
1451
|
+
canvasWarn('Canvas: onAfterRender failed', err);
|
|
1452
|
+
} finally {
|
|
1453
|
+
applyingOverlaySync = false;
|
|
1454
|
+
}
|
|
1455
|
+
if (overlayPaintAfterSync && canvas) {
|
|
1456
|
+
overlayPaintAfterSync = false;
|
|
1457
|
+
ignoreOverlayAfterRender = true;
|
|
1458
|
+
canvas.requestRenderAll();
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1426
1463
|
/**
|
|
1427
1464
|
* Hide (or restore) the Fabric screenshot under a live HTML WidgetShape overlay
|
|
1428
1465
|
* so the old image does not ghost in the iframe padding.
|
|
@@ -1439,6 +1476,13 @@
|
|
|
1439
1476
|
const nextHidden = !!hidden;
|
|
1440
1477
|
if ((obj as any)._hideImageForLivePreview === nextHidden) return;
|
|
1441
1478
|
(obj as any)._hideImageForLivePreview = nextHidden;
|
|
1479
|
+
(obj as any).dirty = true;
|
|
1480
|
+
// The overlay sync runs because a paint just finished. Painting again
|
|
1481
|
+
// from that same turn fires after:render, which moves the overlay again.
|
|
1482
|
+
if (applyingOverlaySync) {
|
|
1483
|
+
overlayPaintAfterSync = true;
|
|
1484
|
+
return;
|
|
1485
|
+
}
|
|
1442
1486
|
canvas.requestRenderAll();
|
|
1443
1487
|
canvasLog('Canvas: setWidgetShapeLivePreviewHiddenImage', widgetId.substring(0, 8), nextHidden);
|
|
1444
1488
|
}
|
|
@@ -2496,15 +2540,9 @@
|
|
|
2496
2540
|
}
|
|
2497
2541
|
});
|
|
2498
2542
|
|
|
2499
|
-
// Listen for scaling updates during drag
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
try {
|
|
2503
|
-
onAfterRender();
|
|
2504
|
-
} catch (err) {
|
|
2505
|
-
canvasWarn('Canvas: onAfterRender failed', err);
|
|
2506
|
-
}
|
|
2507
|
-
};
|
|
2543
|
+
// Listen for scaling updates during drag.
|
|
2544
|
+
// The overlay sync lives in queueWidgetPreviewOverlaySync, outside
|
|
2545
|
+
// this handler, so a paint started by the sync cannot re-enter it.
|
|
2508
2546
|
|
|
2509
2547
|
canvas.on('object:scaling', (opt: any) => {
|
|
2510
2548
|
isCurrentlyScaling = true;
|
|
@@ -2581,11 +2619,14 @@
|
|
|
2581
2619
|
currentScalingCorner = null;
|
|
2582
2620
|
});
|
|
2583
2621
|
|
|
2584
|
-
// Also reset on mouse:up in case object:scaled doesn't fire
|
|
2622
|
+
// Also reset on mouse:up in case object:scaled doesn't fire.
|
|
2623
|
+
// Clear the flag in this turn. A deferred clear left after:render
|
|
2624
|
+
// flushing the overlay synchronously, and that flush never returned.
|
|
2585
2625
|
canvas.on('mouse:up', () => {
|
|
2586
|
-
|
|
2626
|
+
const wasScaling = isCurrentlyScaling;
|
|
2627
|
+
isCurrentlyScaling = false;
|
|
2587
2628
|
setTimeout(() => {
|
|
2588
|
-
if (
|
|
2629
|
+
if (wasScaling) {
|
|
2589
2630
|
// Clean up _originalCorners on the target
|
|
2590
2631
|
if (scalingTarget?._originalCorners) {
|
|
2591
2632
|
delete scalingTarget._originalCorners;
|
|
@@ -3197,7 +3238,7 @@
|
|
|
3197
3238
|
// object:modified fires once at mouseup — ideal for undo snapshots.
|
|
3198
3239
|
// Also fires after arrow-key nudges.
|
|
3199
3240
|
canvas.on('object:modified', () => {
|
|
3200
|
-
|
|
3241
|
+
queueWidgetPreviewOverlaySync();
|
|
3201
3242
|
takeHistorySnapshot();
|
|
3202
3243
|
});
|
|
3203
3244
|
|
|
@@ -5012,20 +5053,15 @@
|
|
|
5012
5053
|
canvas.on('selection:updated', handleSelectionUpdated);
|
|
5013
5054
|
canvas.on('selection:cleared', handleSelectionCleared);
|
|
5014
5055
|
|
|
5015
|
-
// Live HTML overlays (WidgetShape iframes)
|
|
5016
|
-
let afterRenderRaf = 0;
|
|
5056
|
+
// Live HTML overlays (WidgetShape iframes). Never in this paint's turn.
|
|
5017
5057
|
canvas.on('after:render', () => {
|
|
5018
5058
|
if (!onAfterRender) return;
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
flushWidgetPreviewOverlay();
|
|
5059
|
+
if (ignoreOverlayAfterRender) {
|
|
5060
|
+
ignoreOverlayAfterRender = false;
|
|
5022
5061
|
return;
|
|
5023
5062
|
}
|
|
5024
|
-
if (
|
|
5025
|
-
|
|
5026
|
-
afterRenderRaf = 0;
|
|
5027
|
-
flushWidgetPreviewOverlay();
|
|
5028
|
-
});
|
|
5063
|
+
if (applyingOverlaySync) return;
|
|
5064
|
+
queueWidgetPreviewOverlaySync();
|
|
5029
5065
|
});
|
|
5030
5066
|
|
|
5031
5067
|
// Double-click handler:
|
|
@@ -8102,6 +8138,10 @@ function checkAndAddNewShapeToFrame(shape: any) {
|
|
|
8102
8138
|
if (!obj || obj._allowBodyDrag === allowed) return;
|
|
8103
8139
|
obj._allowBodyDrag = allowed;
|
|
8104
8140
|
lockWidgetShapeBodyDrag(obj);
|
|
8141
|
+
if (applyingOverlaySync) {
|
|
8142
|
+
overlayPaintAfterSync = true;
|
|
8143
|
+
return;
|
|
8144
|
+
}
|
|
8105
8145
|
canvas.requestRenderAll();
|
|
8106
8146
|
}
|
|
8107
8147
|
|
|
@@ -8176,8 +8216,9 @@ function checkAndAddNewShapeToFrame(shape: any) {
|
|
|
8176
8216
|
function setHoveredWidgetShape(widgetId: string | null): void {
|
|
8177
8217
|
if (hoveredWidgetShapeId === widgetId) return;
|
|
8178
8218
|
hoveredWidgetShapeId = widgetId;
|
|
8179
|
-
//
|
|
8180
|
-
|
|
8219
|
+
// Hover only changes the HTML bar. A canvas paint here moved the iframe
|
|
8220
|
+
// in the paint that the move itself had requested.
|
|
8221
|
+
queueWidgetPreviewOverlaySync();
|
|
8181
8222
|
}
|
|
8182
8223
|
|
|
8183
8224
|
export function selectWidgetShapeById(widgetId: string): boolean {
|
|
@@ -9423,6 +9464,16 @@ function checkAndAddNewShapeToFrame(shape: any) {
|
|
|
9423
9464
|
if (_autoSaveTimer) clearTimeout(_autoSaveTimer);
|
|
9424
9465
|
_autoSaveTimer = setTimeout(() => {
|
|
9425
9466
|
_autoSaveTimer = null;
|
|
9467
|
+
if (suspendAutosave) {
|
|
9468
|
+
if (import.meta.env.DEV) {
|
|
9469
|
+
fetch('http://localhost:3000/health?probe=autosave&status=deferred').catch(() => {});
|
|
9470
|
+
}
|
|
9471
|
+
scheduleAutoSave();
|
|
9472
|
+
return;
|
|
9473
|
+
}
|
|
9474
|
+
if (import.meta.env.DEV) {
|
|
9475
|
+
fetch('http://localhost:3000/health?probe=autosave&status=run').catch(() => {});
|
|
9476
|
+
}
|
|
9426
9477
|
const json = saveCanvas();
|
|
9427
9478
|
onAutoSave?.(json);
|
|
9428
9479
|
_hasUnsavedChanges = false;
|
|
@@ -31,6 +31,7 @@ declare const __propDef: {
|
|
|
31
31
|
onBeforeUnmount?: ((json: string | null) => void) | null;
|
|
32
32
|
onAutoSave?: ((json: string | null) => void) | null;
|
|
33
33
|
autosaveDelayMs?: number;
|
|
34
|
+
suspendAutosave?: boolean;
|
|
34
35
|
showSaveButton?: boolean;
|
|
35
36
|
onCanvasDirty?: (() => void) | null;
|
|
36
37
|
onCanvasCleared?: (() => void) | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/canvas",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"svelte": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"dev-sv": "NODE_ENV=development vite dev",
|
|
52
52
|
"build": "vite build && npm run package",
|
|
53
53
|
"package": "NODE_ENV=production svelte-package",
|
|
54
|
+
"publish-to-npm": "npm version patch --no-git-tag-version && npm run package && npm publish --ignore-scripts --access public",
|
|
54
55
|
"package:watch": "NODE_ENV=development svelte-package --watch",
|
|
55
56
|
"test": "node --test \"scripts/*.test.ts\" \"tests/*.test.mjs\"",
|
|
56
57
|
"preview": "vite preview",
|