@overtone-art/canvas-editor-core 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -231,6 +231,38 @@ var LayerManager = class {
|
|
|
231
231
|
this.emitChanged();
|
|
232
232
|
this.onPropertyChanged?.();
|
|
233
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Patch a layer's host metadata. A key whose value is `undefined` is removed.
|
|
236
|
+
*
|
|
237
|
+
* `meta` is part of `LayerData` and is serialized, so a host that assigns
|
|
238
|
+
* `layer.meta.x` directly gets neither of the two things every other setter
|
|
239
|
+
* here provides: `layers:changed` (so `useLayers()` keeps returning the old
|
|
240
|
+
* meta) and the history checkpoint (so an undo silently reverts the write —
|
|
241
|
+
* the state IS versioned, it was just never committed at the moment it
|
|
242
|
+
* changed). Going through this method is what makes metadata behave like
|
|
243
|
+
* every other layer property.
|
|
244
|
+
*/
|
|
245
|
+
setMeta(id, patch) {
|
|
246
|
+
const layer = this.get(id);
|
|
247
|
+
if (!layer) return;
|
|
248
|
+
const next = { ...layer.meta };
|
|
249
|
+
let changed = false;
|
|
250
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
251
|
+
if (value === void 0) {
|
|
252
|
+
if (key in next) {
|
|
253
|
+
delete next[key];
|
|
254
|
+
changed = true;
|
|
255
|
+
}
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (next[key] !== value) changed = true;
|
|
259
|
+
next[key] = value;
|
|
260
|
+
}
|
|
261
|
+
if (!changed) return;
|
|
262
|
+
layer.meta = next;
|
|
263
|
+
this.emitChanged();
|
|
264
|
+
this.onPropertyChanged?.();
|
|
265
|
+
}
|
|
234
266
|
clear() {
|
|
235
267
|
for (const layer of this.layers) {
|
|
236
268
|
this.canvas.remove(layer.fabricObject);
|