@bettercms-ai/sdk 1.27.0 → 1.29.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 +59 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -2
- package/dist/index.d.ts +72 -2
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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";
|
|
@@ -1984,6 +2036,7 @@ function shouldShowField(field, values) {
|
|
|
1984
2036
|
function formInitialValues(form, prefill = {}) {
|
|
1985
2037
|
const values = {};
|
|
1986
2038
|
for (const field of form.fields) {
|
|
2039
|
+
if (field.type === "step") continue;
|
|
1987
2040
|
if (field.type === "checkbox" || field.type === "consent") {
|
|
1988
2041
|
values[field.key] = false;
|
|
1989
2042
|
} else if (field.type === "checkboxes") {
|
|
@@ -2035,12 +2088,15 @@ var import_types = require("@bettercms-ai/types");
|
|
|
2035
2088
|
BetterCMSDeliveryClient,
|
|
2036
2089
|
BetterCMSError,
|
|
2037
2090
|
BetterCMSManagementClient,
|
|
2091
|
+
CONTENT_APPLIED,
|
|
2038
2092
|
ErrorCodes,
|
|
2039
2093
|
PORTABLE_TEXT_FORMAT,
|
|
2094
|
+
STEGA_OPEN,
|
|
2040
2095
|
addModelFields,
|
|
2041
2096
|
addPageFields,
|
|
2042
2097
|
asStringArray,
|
|
2043
2098
|
commandManagedLayout,
|
|
2099
|
+
contentApplied,
|
|
2044
2100
|
createApiKey,
|
|
2045
2101
|
createClient,
|
|
2046
2102
|
createEntry,
|
|
@@ -2088,6 +2144,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
2088
2144
|
listPages,
|
|
2089
2145
|
listSubmissions,
|
|
2090
2146
|
listWorkspaces,
|
|
2147
|
+
onContentApplied,
|
|
2091
2148
|
plain,
|
|
2092
2149
|
portableText,
|
|
2093
2150
|
publishManagedLayout,
|
|
@@ -2099,6 +2156,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
2099
2156
|
removeMember,
|
|
2100
2157
|
resetPublishedContentCache,
|
|
2101
2158
|
resolveSeo,
|
|
2159
|
+
resolveStega,
|
|
2102
2160
|
revokeApiKey,
|
|
2103
2161
|
rich,
|
|
2104
2162
|
search,
|
|
@@ -2108,6 +2166,7 @@ var import_types = require("@bettercms-ai/types");
|
|
|
2108
2166
|
signInWithGithub,
|
|
2109
2167
|
signInWithGoogle,
|
|
2110
2168
|
signUp,
|
|
2169
|
+
stegaClean,
|
|
2111
2170
|
stripStega,
|
|
2112
2171
|
submitForm,
|
|
2113
2172
|
toggleOption,
|