@ohhwells/bridge 0.1.86-next.256 → 0.1.86-next.257

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/index.cjs CHANGED
@@ -837,6 +837,22 @@ function getPageSectionOrderEntries(raw, currentPath) {
837
837
  return [];
838
838
  }
839
839
  }
840
+ function mergePageSectionOrder(raw, currentPath, pageEntries) {
841
+ let all = [];
842
+ if (raw) {
843
+ try {
844
+ const parsed = JSON.parse(raw);
845
+ if (Array.isArray(parsed)) all = parsed;
846
+ } catch {
847
+ }
848
+ }
849
+ const otherPages = all.filter((e) => e && e.pagePath && e.pagePath !== currentPath);
850
+ const pageIds = new Set(pageEntries.map((e) => e.instanceId));
851
+ const removedHere = all.filter(
852
+ (e) => e && (!e.pagePath || e.pagePath === currentPath) && e.removed && !pageIds.has(e.instanceId)
853
+ );
854
+ return [...otherPages, ...removedHere, ...pageEntries];
855
+ }
840
856
  function rekeySectionSubtree(root, instanceId) {
841
857
  const suffix = `::${instanceId}`;
842
858
  const pairs = [];
@@ -14637,7 +14653,9 @@ function useSectionDrag({
14637
14653
  clearSectionDragVisuals();
14638
14654
  return;
14639
14655
  }
14640
- const orderJson = JSON.stringify(entries);
14656
+ const orderJson = JSON.stringify(
14657
+ mergePageSectionOrder(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname, entries)
14658
+ );
14641
14659
  editContentRef.current = { ...editContentRef.current, [SECTION_ORDER_KEY]: orderJson };
14642
14660
  setAiSectionOrder(orderJson, window.location.pathname);
14643
14661
  postToParentRef.current({ type: "ow:change", nodes: [{ key: SECTION_ORDER_KEY, text: orderJson }] });
@@ -20939,7 +20957,9 @@ function OhhwellsBridge() {
20939
20957
  if (!instanceId || !direction) return;
20940
20958
  const entries = moveSectionInstance(instanceId, direction, window.location.pathname);
20941
20959
  if (!entries) return;
20942
- const orderJson = JSON.stringify(entries);
20960
+ const orderJson = JSON.stringify(
20961
+ mergePageSectionOrder(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname, entries)
20962
+ );
20943
20963
  editContentRef.current = { ...editContentRef.current, [SECTION_ORDER_KEY]: orderJson };
20944
20964
  setAiSectionOrder(orderJson, window.location.pathname);
20945
20965
  postToParentRef.current({ type: "ow:change", nodes: [{ key: SECTION_ORDER_KEY, text: orderJson }] });
@@ -20959,7 +20979,9 @@ function OhhwellsBridge() {
20959
20979
  const currentEntries = getPageSectionOrderEntries(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname);
20960
20980
  const entries = deleteSectionInstance(instanceId, window.location.pathname, currentEntries);
20961
20981
  if (!entries) return;
20962
- const orderJson = JSON.stringify(entries);
20982
+ const orderJson = JSON.stringify(
20983
+ mergePageSectionOrder(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname, entries)
20984
+ );
20963
20985
  editContentRef.current = { ...editContentRef.current, [SECTION_ORDER_KEY]: orderJson };
20964
20986
  setAiSectionOrder(orderJson, window.location.pathname);
20965
20987
  postToParentRef.current({ type: "ow:change", nodes: [{ key: SECTION_ORDER_KEY, text: orderJson }] });
@@ -20978,7 +21000,9 @@ function OhhwellsBridge() {
20978
21000
  );
20979
21001
  const restored = restoreSectionInstance(instanceId, window.location.pathname, restoredEntries);
20980
21002
  if (!restored) return;
20981
- const restoredJson = JSON.stringify(restored);
21003
+ const restoredJson = JSON.stringify(
21004
+ mergePageSectionOrder(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname, restored)
21005
+ );
20982
21006
  editContentRef.current = { ...editContentRef.current, [SECTION_ORDER_KEY]: restoredJson };
20983
21007
  setAiSectionOrder(restoredJson, window.location.pathname);
20984
21008
  postToParentRef.current({ type: "ow:change", nodes: [{ key: SECTION_ORDER_KEY, text: restoredJson }] });
@@ -21006,7 +21030,9 @@ function OhhwellsBridge() {
21006
21030
  const result = duplicateSectionInstance(instanceId, newId, window.location.pathname, currentEntries);
21007
21031
  if (!result) return;
21008
21032
  const { entries, keyRekeys } = result;
21009
- const orderJson = JSON.stringify(entries);
21033
+ const orderJson = JSON.stringify(
21034
+ mergePageSectionOrder(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname, entries)
21035
+ );
21010
21036
  const nodes = [{ key: SECTION_ORDER_KEY, text: orderJson }];
21011
21037
  for (const { from, to } of keyRekeys) {
21012
21038
  const inherited = editContentRef.current[from];