@bettercms-ai/sdk 1.28.0 → 1.30.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/index.cjs CHANGED
@@ -37,12 +37,15 @@ __export(index_exports, {
37
37
  BetterCMSDeliveryClient: () => BetterCMSDeliveryClient,
38
38
  BetterCMSError: () => BetterCMSError,
39
39
  BetterCMSManagementClient: () => BetterCMSManagementClient,
40
+ CONTENT_APPLIED: () => CONTENT_APPLIED,
40
41
  ErrorCodes: () => ErrorCodes,
41
42
  PORTABLE_TEXT_FORMAT: () => PORTABLE_TEXT_FORMAT,
43
+ STEGA_OPEN: () => STEGA_OPEN,
42
44
  addModelFields: () => addModelFields,
43
45
  addPageFields: () => addPageFields,
44
46
  asStringArray: () => asStringArray,
45
47
  commandManagedLayout: () => commandManagedLayout,
48
+ contentApplied: () => contentApplied,
46
49
  createApiKey: () => createApiKey,
47
50
  createClient: () => createClient,
48
51
  createEntry: () => createEntry,
@@ -90,6 +93,7 @@ __export(index_exports, {
90
93
  listPages: () => listPages,
91
94
  listSubmissions: () => listSubmissions,
92
95
  listWorkspaces: () => listWorkspaces,
96
+ onContentApplied: () => onContentApplied,
93
97
  plain: () => plain,
94
98
  portableText: () => portableText,
95
99
  publishManagedLayout: () => publishManagedLayout,
@@ -101,6 +105,7 @@ __export(index_exports, {
101
105
  removeMember: () => removeMember,
102
106
  resetPublishedContentCache: () => resetPublishedContentCache,
103
107
  resolveSeo: () => resolveSeo,
108
+ resolveStega: () => resolveStega,
104
109
  revokeApiKey: () => revokeApiKey,
105
110
  rich: () => rich,
106
111
  search: () => search,
@@ -110,6 +115,7 @@ __export(index_exports, {
110
115
  signInWithGithub: () => signInWithGithub,
111
116
  signInWithGoogle: () => signInWithGoogle,
112
117
  signUp: () => signUp,
118
+ stegaClean: () => stegaClean,
113
119
  stripStega: () => stripStega,
114
120
  submitForm: () => submitForm,
115
121
  toggleOption: () => toggleOption,
@@ -1522,6 +1528,52 @@ function decodeStega(value) {
1522
1528
  function stripStega(value) {
1523
1529
  return value.replace(FRAME, "");
1524
1530
  }
1531
+ var STEGA_OPEN = `${START}${END}`;
1532
+ var FRAMES = new RegExp(`${START}([${ZERO}${ONE}]*)${END}`, "g");
1533
+ function stegaClean(value) {
1534
+ return value.replace(FRAMES, "");
1535
+ }
1536
+ function resolveStega(node) {
1537
+ let offset = 0;
1538
+ const length = node.textContent?.length ?? 0;
1539
+ for (let cur = node, up = node.parentNode; up; cur = up, up = up.parentNode) {
1540
+ for (const sibling of Array.from(up.childNodes ?? [])) {
1541
+ if (sibling === cur) break;
1542
+ offset += sibling.textContent?.length ?? 0;
1543
+ }
1544
+ const text = up.textContent ?? "";
1545
+ const opens = [];
1546
+ for (const frame of text.matchAll(FRAMES)) {
1547
+ if (!frame[1]) {
1548
+ opens.push(frame.index);
1549
+ continue;
1550
+ }
1551
+ const open = opens.pop();
1552
+ if (frame.index + frame[0].length <= offset || open === void 0 || open >= offset + length) continue;
1553
+ try {
1554
+ return { payload: JSON.parse(fromBits(frame[1])), element: up };
1555
+ } catch {
1556
+ break;
1557
+ }
1558
+ }
1559
+ }
1560
+ return null;
1561
+ }
1562
+
1563
+ // src/content-applied.ts
1564
+ var CONTENT_APPLIED = "bcms:content-applied";
1565
+ var contentApplied = (fields = []) => ({ type: CONTENT_APPLIED, fields: [...fields] });
1566
+ function onContentApplied(handler, target = globalThis.window) {
1567
+ if (!target) return () => {
1568
+ };
1569
+ const listener = (event) => {
1570
+ const data = event.data;
1571
+ if (!data || typeof data !== "object" || data.type !== CONTENT_APPLIED) return;
1572
+ handler({ type: CONTENT_APPLIED, fields: Array.isArray(data.fields) ? data.fields.filter((f) => typeof f === "string") : [] });
1573
+ };
1574
+ target.addEventListener("message", listener);
1575
+ return () => target.removeEventListener("message", listener);
1576
+ }
1525
1577
 
1526
1578
  // src/richtext.ts
1527
1579
  var PORTABLE_TEXT_FORMAT = "portable-text-1";
@@ -2036,12 +2088,15 @@ var import_types = require("@bettercms-ai/types");
2036
2088
  BetterCMSDeliveryClient,
2037
2089
  BetterCMSError,
2038
2090
  BetterCMSManagementClient,
2091
+ CONTENT_APPLIED,
2039
2092
  ErrorCodes,
2040
2093
  PORTABLE_TEXT_FORMAT,
2094
+ STEGA_OPEN,
2041
2095
  addModelFields,
2042
2096
  addPageFields,
2043
2097
  asStringArray,
2044
2098
  commandManagedLayout,
2099
+ contentApplied,
2045
2100
  createApiKey,
2046
2101
  createClient,
2047
2102
  createEntry,
@@ -2089,6 +2144,7 @@ var import_types = require("@bettercms-ai/types");
2089
2144
  listPages,
2090
2145
  listSubmissions,
2091
2146
  listWorkspaces,
2147
+ onContentApplied,
2092
2148
  plain,
2093
2149
  portableText,
2094
2150
  publishManagedLayout,
@@ -2100,6 +2156,7 @@ var import_types = require("@bettercms-ai/types");
2100
2156
  removeMember,
2101
2157
  resetPublishedContentCache,
2102
2158
  resolveSeo,
2159
+ resolveStega,
2103
2160
  revokeApiKey,
2104
2161
  rich,
2105
2162
  search,
@@ -2109,6 +2166,7 @@ var import_types = require("@bettercms-ai/types");
2109
2166
  signInWithGithub,
2110
2167
  signInWithGoogle,
2111
2168
  signUp,
2169
+ stegaClean,
2112
2170
  stripStega,
2113
2171
  submitForm,
2114
2172
  toggleOption,