@weaverse/hydrogen 5.19.1 → 5.20.0

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.mjs CHANGED
@@ -899,6 +899,50 @@ var WeaverseHydrogenItem = class extends WeaverseItemStore {
899
899
  get Element() {
900
900
  return super.Element;
901
901
  }
902
+ /**
903
+ * Override setData to flatten serialized `data` the same way the constructor
904
+ * does. Core's `initProject()` reuses item stores keyed by item id (identical
905
+ * ids across locales), and the inherited setData only shallow-merges the raw
906
+ * item — fresh settings would land under `_store.data` while the stale
907
+ * flattened values keep rendering.
908
+ *
909
+ * Schema defaults are re-applied ahead of incoming settings because a
910
+ * serialized payload can omit fields — or the optional `data` object itself —
911
+ * when values equal schema defaults. The stored nested `data` is also replaced
912
+ * so the public serialized state does not retain the previous locale payload.
913
+ *
914
+ * An empty update is the context-only refresh from `syncReusedInstance`: swap
915
+ * the store reference so memoized subscribers re-render, and leave the
916
+ * settings untouched.
917
+ */
918
+ setData = (update) => {
919
+ let source = update ?? {};
920
+ let { data, ...rest } = source;
921
+ let isEmptyUpdate = Object.keys(source).length === 0;
922
+ if (isEmptyUpdate) {
923
+ this._store = { ...this._store };
924
+ } else {
925
+ let type = source.type ?? this._store.type;
926
+ let schema2 = this.weaverse.elementRegistry.get(type)?.schema;
927
+ let isSerializedItem = "id" in source && "type" in source;
928
+ let shouldNormalize = data !== void 0 || isSerializedItem;
929
+ if (schema2 && shouldNormalize) {
930
+ let { data: _previousData, ...store } = this._store;
931
+ let schemaData = generateDataFromSchema(schema2);
932
+ this._store = {
933
+ ...store,
934
+ ...data === void 0 ? {} : { data },
935
+ ...schemaData,
936
+ ...data,
937
+ ...rest
938
+ };
939
+ } else {
940
+ this._store = { ...this._store, ...source };
941
+ }
942
+ }
943
+ this.triggerUpdate();
944
+ return this.data;
945
+ };
902
946
  /**
903
947
  * Override getSnapShot to merge translation data when in translation mode.
904
948
  * Memoizes the result: returns the same object reference as long as