@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.
package/dist/workspace/index.js
CHANGED
|
@@ -9893,68 +9893,43 @@ function useCanvasFromExisting(api) {
|
|
|
9893
9893
|
}
|
|
9894
9894
|
var NO_SNAPSHOT_HYDRATION_KEY = "__no_snapshot__";
|
|
9895
9895
|
function useHydrateEditorSnapshot(api, snapshot) {
|
|
9896
|
-
const
|
|
9896
|
+
const fallbackIdentityRef = useRef6(
|
|
9897
|
+
`snapshot:fallback:${Math.random().toString(36).slice(2)}`
|
|
9898
|
+
);
|
|
9899
|
+
const hydratedIdentityRef = useRef6(NO_SNAPSHOT_HYDRATION_KEY);
|
|
9900
|
+
const [hydrationReady, setHydrationReady] = useState11(false);
|
|
9901
|
+
const targetHydrationIdentity = useMemo13(() => {
|
|
9897
9902
|
if (!(snapshot == null ? void 0 : snapshot.props)) return NO_SNAPSHOT_HYDRATION_KEY;
|
|
9898
|
-
return
|
|
9903
|
+
return getSnapshotHydrationIdentity(snapshot, fallbackIdentityRef.current);
|
|
9899
9904
|
}, [snapshot]);
|
|
9900
|
-
const [hydratedKey, setHydratedKey] = useState11(
|
|
9901
|
-
NO_SNAPSHOT_HYDRATION_KEY
|
|
9902
|
-
);
|
|
9903
9905
|
useLayoutEffect(() => {
|
|
9904
|
-
if (hydratedKey === targetHydrationKey) return;
|
|
9905
9906
|
if (snapshot == null ? void 0 : snapshot.props) {
|
|
9906
|
-
|
|
9907
|
+
const shouldHydrate = hydratedIdentityRef.current !== targetHydrationIdentity;
|
|
9908
|
+
if (shouldHydrate) {
|
|
9909
|
+
hydrateEditorFromSnapshot(api, snapshot);
|
|
9910
|
+
hydratedIdentityRef.current = targetHydrationIdentity;
|
|
9911
|
+
}
|
|
9907
9912
|
}
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9913
|
+
if (!hydrationReady) {
|
|
9914
|
+
setHydrationReady(true);
|
|
9915
|
+
}
|
|
9916
|
+
}, [api, hydrationReady, snapshot, targetHydrationIdentity]);
|
|
9917
|
+
return hydrationReady;
|
|
9911
9918
|
}
|
|
9912
|
-
function
|
|
9913
|
-
var _a, _b, _c
|
|
9919
|
+
function getSnapshotHydrationIdentity(snapshot, fallbackIdentity) {
|
|
9920
|
+
var _a, _b, _c;
|
|
9914
9921
|
const meta = snapshot.meta;
|
|
9915
|
-
const
|
|
9916
|
-
|
|
9917
|
-
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
9923
|
-
|
|
9924
|
-
const catalogKey = serializeForHydration(snapshot.catalog);
|
|
9925
|
-
return [
|
|
9926
|
-
metaKey,
|
|
9927
|
-
String(((_i = (_h = snapshot.props) == null ? void 0 : _h.fields) != null ? _i : []).length),
|
|
9928
|
-
String(((_k = (_j = snapshot.props) == null ? void 0 : _j.filters) != null ? _k : []).length),
|
|
9929
|
-
positionKeys,
|
|
9930
|
-
viewport,
|
|
9931
|
-
selection,
|
|
9932
|
-
catalogKey
|
|
9933
|
-
].join("::");
|
|
9934
|
-
}
|
|
9935
|
-
function serializeForHydration(value) {
|
|
9936
|
-
if (value == null) return "";
|
|
9937
|
-
try {
|
|
9938
|
-
return JSON.stringify(sortForHydration(value));
|
|
9939
|
-
} catch {
|
|
9940
|
-
return "__unserializable__";
|
|
9941
|
-
}
|
|
9942
|
-
}
|
|
9943
|
-
function sortForHydration(value) {
|
|
9944
|
-
if (Array.isArray(value)) {
|
|
9945
|
-
return value.map((entry) => sortForHydration(entry));
|
|
9946
|
-
}
|
|
9947
|
-
if (value && typeof value === "object") {
|
|
9948
|
-
const entries = Object.entries(value).sort(
|
|
9949
|
-
([a], [b]) => a.localeCompare(b)
|
|
9950
|
-
);
|
|
9951
|
-
const next = {};
|
|
9952
|
-
for (const [key, entry] of entries) {
|
|
9953
|
-
next[key] = sortForHydration(entry);
|
|
9954
|
-
}
|
|
9955
|
-
return next;
|
|
9922
|
+
const snapshotId = (_a = meta == null ? void 0 : meta.snapshot_id) != null ? _a : meta == null ? void 0 : meta.snapshotId;
|
|
9923
|
+
const versionId = (_b = meta == null ? void 0 : meta.version_id) != null ? _b : meta == null ? void 0 : meta.versionId;
|
|
9924
|
+
const branchId = (_c = meta == null ? void 0 : meta.branch_id) != null ? _c : meta == null ? void 0 : meta.branchId;
|
|
9925
|
+
if (snapshotId != null || versionId != null || branchId != null) {
|
|
9926
|
+
return [
|
|
9927
|
+
String(snapshotId != null ? snapshotId : ""),
|
|
9928
|
+
String(versionId != null ? versionId : ""),
|
|
9929
|
+
String(branchId != null ? branchId : "")
|
|
9930
|
+
].join("|");
|
|
9956
9931
|
}
|
|
9957
|
-
return
|
|
9932
|
+
return fallbackIdentity;
|
|
9958
9933
|
}
|
|
9959
9934
|
function hydrateEditorFromSnapshot(api, snapshot) {
|
|
9960
9935
|
var _a;
|