@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.cjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
9950
|
+
const shouldHydrate = hydratedIdentityRef.current !== targetHydrationIdentity;
|
|
9951
|
+
if (shouldHydrate) {
|
|
9952
|
+
hydrateEditorFromSnapshot(api, snapshot);
|
|
9953
|
+
hydratedIdentityRef.current = targetHydrationIdentity;
|
|
9954
|
+
}
|
|
9950
9955
|
}
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9956
|
+
if (!hydrationReady) {
|
|
9957
|
+
setHydrationReady(true);
|
|
9958
|
+
}
|
|
9959
|
+
}, [api, hydrationReady, snapshot, targetHydrationIdentity]);
|
|
9960
|
+
return hydrationReady;
|
|
9954
9961
|
}
|
|
9955
|
-
function
|
|
9956
|
-
var _a, _b, _c
|
|
9962
|
+
function getSnapshotHydrationIdentity(snapshot, fallbackIdentity) {
|
|
9963
|
+
var _a, _b, _c;
|
|
9957
9964
|
const meta = snapshot.meta;
|
|
9958
|
-
const
|
|
9959
|
-
|
|
9960
|
-
|
|
9961
|
-
|
|
9962
|
-
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
|
|
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
|
|
9975
|
+
return fallbackIdentity;
|
|
10001
9976
|
}
|
|
10002
9977
|
function hydrateEditorFromSnapshot(api, snapshot) {
|
|
10003
9978
|
var _a;
|