@timeax/digital-service-engine 0.0.9 → 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.
@@ -1316,7 +1316,6 @@ function useLivePolling(params) {
1316
1316
  live,
1317
1317
  workspaceId,
1318
1318
  actor,
1319
- hasAnyData,
1320
1319
  getCurrentBranchId,
1321
1320
  refreshAll,
1322
1321
  refreshBranchContext,
@@ -1423,11 +1422,6 @@ function useLivePolling(params) {
1423
1422
  disconnect2();
1424
1423
  if (live.mode === "off") {
1425
1424
  setStatus({ connected: false });
1426
- if (!hasAnyData) {
1427
- void (async () => {
1428
- await refreshAll({ strict: false });
1429
- })();
1430
- }
1431
1425
  return;
1432
1426
  }
1433
1427
  const adapter = resolveAdapter();
@@ -1463,7 +1457,6 @@ function useLivePolling(params) {
1463
1457
  }, [
1464
1458
  disconnect2,
1465
1459
  live.mode,
1466
- hasAnyData,
1467
1460
  refreshAll,
1468
1461
  resolveAdapter,
1469
1462
  ctx,
@@ -2817,8 +2810,10 @@ import {
2817
2810
  createContext as createContext2,
2818
2811
  useContext as useContext2,
2819
2812
  useEffect as useEffect7,
2813
+ useLayoutEffect,
2820
2814
  useMemo as useMemo13,
2821
- useRef as useRef6
2815
+ useRef as useRef6,
2816
+ useState as useState11
2822
2817
  } from "react";
2823
2818
 
2824
2819
  // src/react/canvas/events.ts
@@ -9867,8 +9862,8 @@ function CanvasProviderOwned({
9867
9862
  canvasOpts,
9868
9863
  builderOpts
9869
9864
  );
9870
- useHydrateEditorSnapshot(api, initialSnapshot);
9871
- return /* @__PURE__ */ jsx2(Ctx.Provider, { value: api, children });
9865
+ const hydrationReady = useHydrateEditorSnapshot(api, initialSnapshot);
9866
+ return /* @__PURE__ */ jsx2(Ctx.Provider, { value: api, children: hydrationReady ? children : null });
9872
9867
  }
9873
9868
  function useCanvasAPI() {
9874
9869
  const api = useContext2(Ctx);
@@ -9896,41 +9891,45 @@ function useCanvasFromBuilder(builder, opts) {
9896
9891
  function useCanvasFromExisting(api) {
9897
9892
  return api;
9898
9893
  }
9894
+ var NO_SNAPSHOT_HYDRATION_KEY = "__no_snapshot__";
9899
9895
  function useHydrateEditorSnapshot(api, snapshot) {
9900
- const hydratedRef = useRef6(null);
9901
- useEffect7(() => {
9902
- if (!(snapshot == null ? void 0 : snapshot.props)) return;
9903
- const hydrationKey = getSnapshotHydrationKey(snapshot);
9904
- if (hydratedRef.current === hydrationKey) return;
9905
- hydratedRef.current = hydrationKey;
9906
- hydrateEditorFromSnapshot(api, snapshot);
9907
- }, [api, snapshot]);
9908
- }
9909
- function getSnapshotHydrationKey(snapshot) {
9910
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
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(() => {
9902
+ if (!(snapshot == null ? void 0 : snapshot.props)) return NO_SNAPSHOT_HYDRATION_KEY;
9903
+ return getSnapshotHydrationIdentity(snapshot, fallbackIdentityRef.current);
9904
+ }, [snapshot]);
9905
+ useLayoutEffect(() => {
9906
+ if (snapshot == null ? void 0 : snapshot.props) {
9907
+ const shouldHydrate = hydratedIdentityRef.current !== targetHydrationIdentity;
9908
+ if (shouldHydrate) {
9909
+ hydrateEditorFromSnapshot(api, snapshot);
9910
+ hydratedIdentityRef.current = targetHydrationIdentity;
9911
+ }
9912
+ }
9913
+ if (!hydrationReady) {
9914
+ setHydrationReady(true);
9915
+ }
9916
+ }, [api, hydrationReady, snapshot, targetHydrationIdentity]);
9917
+ return hydrationReady;
9918
+ }
9919
+ function getSnapshotHydrationIdentity(snapshot, fallbackIdentity) {
9920
+ var _a, _b, _c;
9911
9921
  const meta = snapshot.meta;
9912
- const preferred = (_e = (_d = (_c = (_b = (_a = meta == null ? void 0 : meta.snapshot_id) != null ? _a : meta == null ? void 0 : meta.snapshotId) != null ? _b : meta == null ? void 0 : meta.version_id) != null ? _c : meta == null ? void 0 : meta.versionId) != null ? _d : meta == null ? void 0 : meta.branch_id) != null ? _e : meta == null ? void 0 : meta.branchId;
9913
- if (preferred != null) {
9914
- return String(preferred);
9915
- }
9916
- const layout = (_f = snapshot.layout) == null ? void 0 : _f.canvas;
9917
- const positionKeys = (layout == null ? void 0 : layout.positions) ? Object.keys(layout.positions).sort().join("|") : "";
9918
- const viewport = (layout == null ? void 0 : layout.viewport) ? `${layout.viewport.x}:${layout.viewport.y}:${layout.viewport.zoom}` : "";
9919
- const selection = (layout == null ? void 0 : layout.selection) ? Array.from(layout.selection).sort().join("|") : "";
9920
- const catalogKey = snapshot.catalog ? JSON.stringify({
9921
- opened: (_g = snapshot.catalog.opened) != null ? _g : null,
9922
- mode: (_h = snapshot.catalog.mode) != null ? _h : null,
9923
- tab: (_i = snapshot.catalog.tab) != null ? _i : null,
9924
- query: (_j = snapshot.catalog.query) != null ? _j : null
9925
- }) : "";
9926
- return [
9927
- String(((_l = (_k = snapshot.props) == null ? void 0 : _k.fields) != null ? _l : []).length),
9928
- String(((_n = (_m = snapshot.props) == null ? void 0 : _m.filters) != null ? _n : []).length),
9929
- positionKeys,
9930
- viewport,
9931
- selection,
9932
- catalogKey
9933
- ].join("::");
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("|");
9931
+ }
9932
+ return fallbackIdentity;
9934
9933
  }
9935
9934
  function hydrateEditorFromSnapshot(api, snapshot) {
9936
9935
  var _a;
@@ -9946,30 +9945,66 @@ function hydrateCatalog(api, snapshot) {
9946
9945
  api.editor.clearCatalog();
9947
9946
  }
9948
9947
  function hydrateCanvasLayout(api, canvas) {
9948
+ var _a;
9949
9949
  if (!canvas) return;
9950
- if (canvas.positions) {
9950
+ const current = api.snapshot();
9951
+ if (canvas.positions && hasPositionDelta(canvas.positions, current.positions)) {
9951
9952
  api.setPositions(canvas.positions);
9952
9953
  }
9953
- if (canvas.viewport) {
9954
+ if (canvas.viewport && !sameViewport(canvas.viewport, current.viewport)) {
9954
9955
  api.setViewport(canvas.viewport);
9955
9956
  }
9957
+ const currentSelection = api.getSelection().map(String);
9956
9958
  if (canvas.selection) {
9957
9959
  const ids = Array.isArray(canvas.selection) ? canvas.selection : Array.from(canvas.selection);
9958
9960
  if (ids.length > 0) {
9959
- api.select(ids);
9960
- } else {
9961
+ if (!sameIdSet(ids.map(String), currentSelection)) {
9962
+ api.select(ids.map(String));
9963
+ }
9964
+ } else if (currentSelection.length > 0) {
9961
9965
  api.clearSelection();
9962
9966
  }
9963
- } else {
9967
+ } else if (currentSelection.length > 0) {
9964
9968
  api.clearSelection();
9965
9969
  }
9966
- if (canvas.highlighted) {
9967
- const ids = Array.isArray(canvas.highlighted) ? canvas.highlighted : Array.from(canvas.highlighted);
9968
- api.setHighlighted(ids);
9970
+ if ("highlighted" in canvas) {
9971
+ const highlighted = canvas.highlighted;
9972
+ const ids = highlighted ? Array.isArray(highlighted) ? highlighted : Array.from(highlighted) : [];
9973
+ const currentIds = Array.from((_a = current.highlighted) != null ? _a : []).map(String);
9974
+ const nextIds = ids.map(String);
9975
+ if (!sameIdSet(nextIds, currentIds)) {
9976
+ api.setHighlighted(nextIds);
9977
+ }
9969
9978
  }
9970
9979
  if ("hoverId" in canvas) {
9971
- api.setHover(canvas.hoverId);
9980
+ const nextHoverId = canvas.hoverId;
9981
+ if (current.hoverId !== nextHoverId) {
9982
+ api.setHover(nextHoverId);
9983
+ }
9984
+ }
9985
+ }
9986
+ function hasPositionDelta(next, current) {
9987
+ for (const id of Object.keys(next)) {
9988
+ const nextPos = next[id];
9989
+ const currentPos = current[id];
9990
+ if (!currentPos || currentPos.x !== nextPos.x || currentPos.y !== nextPos.y) {
9991
+ return true;
9992
+ }
9972
9993
  }
9994
+ return false;
9995
+ }
9996
+ function sameViewport(a, b) {
9997
+ if (!a && !b) return true;
9998
+ if (!a || !b) return false;
9999
+ return a.x === b.x && a.y === b.y && a.zoom === b.zoom;
10000
+ }
10001
+ function sameIdSet(a, b) {
10002
+ if (a.length !== b.length) return false;
10003
+ const set = new Set(a);
10004
+ for (const id of b) {
10005
+ if (!set.has(id)) return false;
10006
+ }
10007
+ return true;
9973
10008
  }
9974
10009
  function WorkspaceBootScreen({
9975
10010
  boot
@@ -11953,12 +11988,12 @@ function Workspace(props) {
11953
11988
  }
11954
11989
 
11955
11990
  // src/react/workspace/components/canvas.tsx
11956
- import { useMemo as useMemo19, useState as useState15 } from "react";
11991
+ import { useMemo as useMemo19, useState as useState16 } from "react";
11957
11992
  import { Background, ConnectionMode, MiniMap, ReactFlow } from "@xyflow/react";
11958
11993
  import "@xyflow/react/dist/style.css";
11959
11994
 
11960
11995
  // src/react/workspace/adapters/reactflow/adapter.ts
11961
- import { useCallback as useCallback16, useEffect as useEffect10, useMemo as useMemo17, useRef as useRef9, useState as useState13 } from "react";
11996
+ import { useCallback as useCallback16, useEffect as useEffect10, useMemo as useMemo17, useRef as useRef9, useState as useState14 } from "react";
11962
11997
  import { applyNodeChanges, applyEdgeChanges } from "@xyflow/react";
11963
11998
  function rafThrottle(fn, minMs = 80) {
11964
11999
  let frame = 0;
@@ -11984,7 +12019,7 @@ function rafThrottle(fn, minMs = 80) {
11984
12019
  });
11985
12020
  }
11986
12021
  var isCommentId = (id) => id.startsWith("c::");
11987
- function sameIdSet(a, b) {
12022
+ function sameIdSet2(a, b) {
11988
12023
  if (a.length !== b.length) return false;
11989
12024
  const s = new Set(a);
11990
12025
  for (const id of b) if (!s.has(id)) return false;
@@ -12062,7 +12097,7 @@ function useReactFlowAdapter(api, options = {}) {
12062
12097
  useEffect10(() => {
12063
12098
  afterConnectRef.current = options.afterConnect;
12064
12099
  }, [options.afterConnect]);
12065
- const [rf, setRF] = useState13(
12100
+ const [rf, setRF] = useState14(
12066
12101
  () => toRF(api.snapshot(), api, { nodeDecorators, edgeDecorators })
12067
12102
  );
12068
12103
  const relRef = useRef9(api.getEdgeRel());
@@ -12173,7 +12208,7 @@ function useReactFlowAdapter(api, options = {}) {
12173
12208
  const next = Array.from(keep);
12174
12209
  const currRaw = api.getSelection();
12175
12210
  const curr = Array.isArray(currRaw) ? currRaw : Array.from(currRaw);
12176
- if (!sameIdSet(next, curr)) {
12211
+ if (!sameIdSet2(next, curr)) {
12177
12212
  api.select(keep);
12178
12213
  }
12179
12214
  }
@@ -12291,7 +12326,7 @@ function useReactFlowAdapter(api, options = {}) {
12291
12326
  const next = nodes.map((n) => n.id);
12292
12327
  const currRaw = api.getSelection();
12293
12328
  const curr = Array.isArray(currRaw) ? currRaw : Array.from(currRaw);
12294
- if (sameIdSet(next, curr)) return;
12329
+ if (sameIdSet2(next, curr)) return;
12295
12330
  api.select(next);
12296
12331
  },
12297
12332
  [api]
@@ -12312,7 +12347,7 @@ function useReactFlowAdapter(api, options = {}) {
12312
12347
  }
12313
12348
 
12314
12349
  // src/react/workspace/adapters/reactflow/toolbar.tsx
12315
- import { useMemo as useMemo18, useState as useState14, useCallback as useCallback17 } from "react";
12350
+ import { useMemo as useMemo18, useState as useState15, useCallback as useCallback17 } from "react";
12316
12351
  import { useReactFlow } from "@xyflow/react";
12317
12352
 
12318
12353
  // src/react/workspace/adapters/reactflow/toolbar/merge.ts
@@ -12417,7 +12452,7 @@ function Toolbar({
12417
12452
  renderButton
12418
12453
  }) {
12419
12454
  const rf = useReactFlow();
12420
- const [openMenuId, setOpenMenuId] = useState14(null);
12455
+ const [openMenuId, setOpenMenuId] = useState15(null);
12421
12456
  const selectionCount = api.getSelection().length;
12422
12457
  const relation = api.getEdgeRel();
12423
12458
  const canUndo = true;
@@ -12948,8 +12983,8 @@ function Canvas({
12948
12983
  toolbarPositionClassName = "left-2 top-2",
12949
12984
  children
12950
12985
  }) {
12951
- const [showGrid, setShowGrid] = useState15(initialShowGrid);
12952
- const [showMiniMap, setShowMiniMap] = useState15(initialShowMiniMap);
12986
+ const [showGrid, setShowGrid] = useState16(initialShowGrid);
12987
+ const [showMiniMap, setShowMiniMap] = useState16(initialShowMiniMap);
12953
12988
  const {
12954
12989
  nodes,
12955
12990
  edges,