@timeax/digital-service-engine 0.1.0 → 0.2.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.
@@ -9936,68 +9936,43 @@ function useCanvasFromExisting(api) {
9936
9936
  }
9937
9937
  var NO_SNAPSHOT_HYDRATION_KEY = "__no_snapshot__";
9938
9938
  function useHydrateEditorSnapshot(api, snapshot) {
9939
- const targetHydrationKey = (0, import_react2.useMemo)(() => {
9939
+ const fallbackIdentityRef = (0, import_react2.useRef)(
9940
+ `snapshot:fallback:${Math.random().toString(36).slice(2)}`
9941
+ );
9942
+ const hydratedIdentityRef = (0, import_react2.useRef)(NO_SNAPSHOT_HYDRATION_KEY);
9943
+ const [hydrationReady, setHydrationReady] = (0, import_react2.useState)(false);
9944
+ const targetHydrationIdentity = (0, import_react2.useMemo)(() => {
9940
9945
  if (!(snapshot == null ? void 0 : snapshot.props)) return NO_SNAPSHOT_HYDRATION_KEY;
9941
- return getSnapshotHydrationKey(snapshot);
9946
+ return getSnapshotHydrationIdentity(snapshot, fallbackIdentityRef.current);
9942
9947
  }, [snapshot]);
9943
- const [hydratedKey, setHydratedKey] = (0, import_react2.useState)(
9944
- NO_SNAPSHOT_HYDRATION_KEY
9945
- );
9946
9948
  (0, import_react2.useLayoutEffect)(() => {
9947
- if (hydratedKey === targetHydrationKey) return;
9948
9949
  if (snapshot == null ? void 0 : snapshot.props) {
9949
- hydrateEditorFromSnapshot(api, snapshot);
9950
+ const shouldHydrate = hydratedIdentityRef.current !== targetHydrationIdentity;
9951
+ if (shouldHydrate) {
9952
+ hydrateEditorFromSnapshot(api, snapshot);
9953
+ hydratedIdentityRef.current = targetHydrationIdentity;
9954
+ }
9950
9955
  }
9951
- setHydratedKey(targetHydrationKey);
9952
- }, [api, hydratedKey, snapshot, targetHydrationKey]);
9953
- return hydratedKey === targetHydrationKey;
9956
+ if (!hydrationReady) {
9957
+ setHydrationReady(true);
9958
+ }
9959
+ }, [api, hydrationReady, snapshot, targetHydrationIdentity]);
9960
+ return hydrationReady;
9954
9961
  }
9955
- function getSnapshotHydrationKey(snapshot) {
9956
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
9962
+ function getSnapshotHydrationIdentity(snapshot, fallbackIdentity) {
9963
+ var _a, _b, _c;
9957
9964
  const meta = snapshot.meta;
9958
- const metaKey = [
9959
- (_b = (_a = meta == null ? void 0 : meta.snapshot_id) != null ? _a : meta == null ? void 0 : meta.snapshotId) != null ? _b : "",
9960
- (_d = (_c = meta == null ? void 0 : meta.version_id) != null ? _c : meta == null ? void 0 : meta.versionId) != null ? _d : "",
9961
- (_f = (_e = meta == null ? void 0 : meta.branch_id) != null ? _e : meta == null ? void 0 : meta.branchId) != null ? _f : ""
9962
- ].join("|");
9963
- const layout = (_g = snapshot.layout) == null ? void 0 : _g.canvas;
9964
- const positionKeys = (layout == null ? void 0 : layout.positions) ? Object.keys(layout.positions).sort().join("|") : "";
9965
- const viewport = (layout == null ? void 0 : layout.viewport) ? `${layout.viewport.x}:${layout.viewport.y}:${layout.viewport.zoom}` : "";
9966
- const selection = (layout == null ? void 0 : layout.selection) ? Array.from(layout.selection).sort().join("|") : "";
9967
- const catalogKey = serializeForHydration(snapshot.catalog);
9968
- return [
9969
- metaKey,
9970
- String(((_i = (_h = snapshot.props) == null ? void 0 : _h.fields) != null ? _i : []).length),
9971
- String(((_k = (_j = snapshot.props) == null ? void 0 : _j.filters) != null ? _k : []).length),
9972
- positionKeys,
9973
- viewport,
9974
- selection,
9975
- catalogKey
9976
- ].join("::");
9977
- }
9978
- function serializeForHydration(value) {
9979
- if (value == null) return "";
9980
- try {
9981
- return JSON.stringify(sortForHydration(value));
9982
- } catch {
9983
- return "__unserializable__";
9984
- }
9985
- }
9986
- function sortForHydration(value) {
9987
- if (Array.isArray(value)) {
9988
- return value.map((entry) => sortForHydration(entry));
9989
- }
9990
- if (value && typeof value === "object") {
9991
- const entries = Object.entries(value).sort(
9992
- ([a], [b]) => a.localeCompare(b)
9993
- );
9994
- const next = {};
9995
- for (const [key, entry] of entries) {
9996
- next[key] = sortForHydration(entry);
9997
- }
9998
- return next;
9965
+ const snapshotId = (_a = meta == null ? void 0 : meta.snapshot_id) != null ? _a : meta == null ? void 0 : meta.snapshotId;
9966
+ const versionId = (_b = meta == null ? void 0 : meta.version_id) != null ? _b : meta == null ? void 0 : meta.versionId;
9967
+ const branchId = (_c = meta == null ? void 0 : meta.branch_id) != null ? _c : meta == null ? void 0 : meta.branchId;
9968
+ if (snapshotId != null || versionId != null || branchId != null) {
9969
+ return [
9970
+ String(snapshotId != null ? snapshotId : ""),
9971
+ String(versionId != null ? versionId : ""),
9972
+ String(branchId != null ? branchId : "")
9973
+ ].join("|");
9999
9974
  }
10000
- return value;
9975
+ return fallbackIdentity;
10001
9976
  }
10002
9977
  function hydrateEditorFromSnapshot(api, snapshot) {
10003
9978
  var _a;