sitepong 0.2.10 → 0.2.11

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.
@@ -3430,33 +3430,35 @@ function attrDiff(id, prev, next) {
3430
3430
  }
3431
3431
  function diff(prev, next, mirror) {
3432
3432
  const { next: nextIndex, order } = indexTree(next, mirror);
3433
- const messages = [];
3434
- const removed = /* @__PURE__ */ new Set();
3435
- for (const id of prev.keys()) if (!nextIndex.has(id)) removed.add(id);
3436
- for (const id of removed) {
3437
- const rec = prev.get(id);
3438
- if (!removed.has(rec.parentId)) messages.push(RemoveNode(id));
3439
- }
3433
+ const creates = [];
3434
+ const updates = [];
3440
3435
  for (const id of order) {
3441
3436
  const rec = nextIndex.get(id);
3442
3437
  const before = prev.get(id);
3443
3438
  if (!before) {
3444
3439
  if (rec.tag === "#text") {
3445
- messages.push(CreateTextNode(id, rec.parentId, rec.index));
3440
+ creates.push(CreateTextNode(id, rec.parentId, rec.index));
3446
3441
  } else {
3447
- messages.push(CreateElementNode(id, rec.parentId, rec.index, rec.tag));
3442
+ creates.push(CreateElementNode(id, rec.parentId, rec.index, rec.tag));
3448
3443
  }
3449
- for (const k of Object.keys(rec.attrs)) messages.push(SetNodeAttribute(id, k, rec.attrs[k]));
3450
- if (rec.text !== void 0 && rec.text !== "") messages.push(SetNodeData(id, rec.text));
3444
+ for (const k of Object.keys(rec.attrs)) creates.push(SetNodeAttribute(id, k, rec.attrs[k]));
3445
+ if (rec.text !== void 0 && rec.text !== "") creates.push(SetNodeData(id, rec.text));
3451
3446
  } else {
3452
3447
  if (before.parentId !== rec.parentId || before.index !== rec.index) {
3453
- messages.push(MoveNode(id, rec.parentId, rec.index));
3448
+ updates.push(MoveNode(id, rec.parentId, rec.index));
3454
3449
  }
3455
- messages.push(...attrDiff(id, before.attrs, rec.attrs));
3456
- if ((before.text ?? "") !== (rec.text ?? "")) messages.push(SetNodeData(id, rec.text ?? ""));
3450
+ updates.push(...attrDiff(id, before.attrs, rec.attrs));
3451
+ if ((before.text ?? "") !== (rec.text ?? "")) updates.push(SetNodeData(id, rec.text ?? ""));
3457
3452
  }
3458
3453
  }
3459
- return { messages, index: nextIndex };
3454
+ const removed = /* @__PURE__ */ new Set();
3455
+ for (const id of prev.keys()) if (!nextIndex.has(id)) removed.add(id);
3456
+ const removes = [];
3457
+ for (const id of removed) {
3458
+ const rec = prev.get(id);
3459
+ if (!removed.has(rec.parentId)) removes.push(RemoveNode(id));
3460
+ }
3461
+ return { messages: [...creates, ...updates, ...removes], index: nextIndex };
3460
3462
  }
3461
3463
  function stableAnchor(step) {
3462
3464
  if (step.attrs.testID) return `@${step.attrs.testID}`;
@@ -4776,9 +4778,30 @@ function StructuralCaptureProvider({ children, ...cfg }) {
4776
4778
  cfgRef.current = cfg;
4777
4779
  const rootRef = React2.useRef(null);
4778
4780
  React2.useEffect(() => {
4779
- structuralCapture.start(cfgRef.current);
4780
- structuralCapture.setRootInstance(rootRef.current);
4781
+ let cancelled = false;
4782
+ let poll = null;
4783
+ const begin = (sessionId) => {
4784
+ if (cancelled) return;
4785
+ structuralCapture.start({ ...cfgRef.current, sessionId });
4786
+ structuralCapture.setRootInstance(rootRef.current);
4787
+ };
4788
+ const explicit = cfgRef.current.sessionId;
4789
+ if (explicit) {
4790
+ begin(explicit);
4791
+ } else {
4792
+ let tries = 0;
4793
+ const resolve = () => {
4794
+ if (cancelled) return;
4795
+ const wt = getWatchtowerSessionId();
4796
+ if (wt) return begin(wt);
4797
+ if (++tries >= 25) return begin(void 0);
4798
+ poll = setTimeout(resolve, 200);
4799
+ };
4800
+ resolve();
4801
+ }
4781
4802
  return () => {
4803
+ cancelled = true;
4804
+ if (poll) clearTimeout(poll);
4782
4805
  void structuralCapture.stop();
4783
4806
  };
4784
4807
  }, []);