@bettercms-ai/sdk 1.8.1 → 1.9.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
@@ -71,6 +71,7 @@ __export(index_exports, {
71
71
  imageUrlBuilder: () => import_image_url.default,
72
72
  inviteMember: () => inviteMember,
73
73
  isBlock: () => import_types.isBlock,
74
+ isRichText: () => isRichText,
74
75
  listApiKeys: () => listApiKeys,
75
76
  listEntries: () => listEntries,
76
77
  listForms: () => listForms2,
@@ -81,11 +82,13 @@ __export(index_exports, {
81
82
  listPages: () => listPages,
82
83
  listSubmissions: () => listSubmissions,
83
84
  listWorkspaces: () => listWorkspaces,
85
+ plain: () => plain,
84
86
  publishPage: () => publishPage,
85
87
  regenerateApiKey: () => regenerateApiKey,
86
88
  removeMember: () => removeMember,
87
89
  resolveSeo: () => resolveSeo,
88
90
  revokeApiKey: () => revokeApiKey,
91
+ rich: () => rich,
89
92
  search: () => search,
90
93
  setPageContent: () => setPageContent,
91
94
  shouldShowField: () => shouldShowField,
@@ -1258,6 +1261,30 @@ function stripStega(value) {
1258
1261
  return value.replace(FRAME, "");
1259
1262
  }
1260
1263
 
1264
+ // src/richtext.ts
1265
+ function isRichText(value) {
1266
+ return typeof value === "object" && value !== null && !Array.isArray(value) && ("html" in value || "format" in value);
1267
+ }
1268
+ function plain(value) {
1269
+ if (typeof value === "string") return value;
1270
+ if (!isRichText(value) || typeof value.html !== "string") return "";
1271
+ return decodeEntities(value.html.replace(/<[^>]+>/g, "")).trim();
1272
+ }
1273
+ function rich(value, fallback = "") {
1274
+ const html = (typeof value === "string" ? escapeHtml(value) : isRichText(value) ? value.html ?? "" : "").trim();
1275
+ return html ? unwrapLoneBlock(html) : escapeHtml(fallback);
1276
+ }
1277
+ function unwrapLoneBlock(html) {
1278
+ const m = html.match(/^<(p|div|h[1-6])(?:\s[^>]*)?>([\s\S]*)<\/\1>$/i);
1279
+ return m && !new RegExp(`</${m[1]}>`, "i").test(m[2]) ? m[2] : html;
1280
+ }
1281
+ function escapeHtml(s) {
1282
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1283
+ }
1284
+ function decodeEntities(s) {
1285
+ return s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#0?39;/g, "'").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&");
1286
+ }
1287
+
1261
1288
  // src/seo.ts
1262
1289
  function jsonLdNodes(schema) {
1263
1290
  if (!schema) return [];
@@ -1631,6 +1658,7 @@ var import_types = require("@bettercms-ai/types");
1631
1658
  imageUrlBuilder,
1632
1659
  inviteMember,
1633
1660
  isBlock,
1661
+ isRichText,
1634
1662
  listApiKeys,
1635
1663
  listEntries,
1636
1664
  listForms,
@@ -1641,11 +1669,13 @@ var import_types = require("@bettercms-ai/types");
1641
1669
  listPages,
1642
1670
  listSubmissions,
1643
1671
  listWorkspaces,
1672
+ plain,
1644
1673
  publishPage,
1645
1674
  regenerateApiKey,
1646
1675
  removeMember,
1647
1676
  resolveSeo,
1648
1677
  revokeApiKey,
1678
+ rich,
1649
1679
  search,
1650
1680
  setPageContent,
1651
1681
  shouldShowField,