@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.js CHANGED
@@ -304,6 +304,38 @@ var LayerManager = class {
304
304
  this.emitChanged();
305
305
  this.onPropertyChanged?.();
306
306
  }
307
+ /**
308
+ * Patch a layer's host metadata. A key whose value is `undefined` is removed.
309
+ *
310
+ * `meta` is part of `LayerData` and is serialized, so a host that assigns
311
+ * `layer.meta.x` directly gets neither of the two things every other setter
312
+ * here provides: `layers:changed` (so `useLayers()` keeps returning the old
313
+ * meta) and the history checkpoint (so an undo silently reverts the write —
314
+ * the state IS versioned, it was just never committed at the moment it
315
+ * changed). Going through this method is what makes metadata behave like
316
+ * every other layer property.
317
+ */
318
+ setMeta(id, patch) {
319
+ const layer = this.get(id);
320
+ if (!layer) return;
321
+ const next = { ...layer.meta };
322
+ let changed = false;
323
+ for (const [key, value] of Object.entries(patch)) {
324
+ if (value === void 0) {
325
+ if (key in next) {
326
+ delete next[key];
327
+ changed = true;
328
+ }
329
+ continue;
330
+ }
331
+ if (next[key] !== value) changed = true;
332
+ next[key] = value;
333
+ }
334
+ if (!changed) return;
335
+ layer.meta = next;
336
+ this.emitChanged();
337
+ this.onPropertyChanged?.();
338
+ }
307
339
  clear() {
308
340
  for (const layer of this.layers) {
309
341
  this.canvas.remove(layer.fabricObject);