@bettercms-ai/sdk 1.30.0 → 1.31.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
@@ -38,6 +38,7 @@ __export(index_exports, {
38
38
  BetterCMSError: () => BetterCMSError,
39
39
  BetterCMSManagementClient: () => BetterCMSManagementClient,
40
40
  CONTENT_APPLIED: () => CONTENT_APPLIED,
41
+ EDITOR_FRAME_NAME: () => EDITOR_FRAME_NAME,
41
42
  ErrorCodes: () => ErrorCodes,
42
43
  PORTABLE_TEXT_FORMAT: () => PORTABLE_TEXT_FORMAT,
43
44
  STEGA_OPEN: () => STEGA_OPEN,
@@ -79,10 +80,12 @@ __export(index_exports, {
79
80
  imageUrlBuilder: () => import_image_url.default,
80
81
  imageValueObjectPosition: () => import_image_url.imageValueObjectPosition,
81
82
  imageValueUrl: () => import_image_url.imageValueUrl,
83
+ inEditor: () => inEditor,
82
84
  inviteMember: () => inviteMember,
83
85
  isBlock: () => import_types.isBlock,
84
86
  isMultiValueField: () => isMultiValueField,
85
87
  isRichText: () => isRichText,
88
+ lines: () => lines,
86
89
  listApiKeys: () => listApiKeys,
87
90
  listEntries: () => listEntries,
88
91
  listForms: () => listForms2,
@@ -1594,6 +1597,15 @@ function rich(value, fallback = "") {
1594
1597
  const html = (typeof value === "string" ? escapeHtml(value) : isRichText(value) ? value.html ?? "" : "").trim();
1595
1598
  return html ? unwrapLoneBlock(html) : escapeHtml(fallback);
1596
1599
  }
1600
+ function lines(value, fallback = "") {
1601
+ const html = rich(value, fallback);
1602
+ const block = /<(p|h[1-6])(?:\s[^>]*)?>([\s\S]*?)<\/\1>/gi;
1603
+ if (html.length > 1e4) return html;
1604
+ const found = [...html.matchAll(block)];
1605
+ if (found.length < 2 || html.replace(block, "").trim() !== "") return html;
1606
+ const shown = found.map((m) => m[2].trim()).filter((line) => line.replace(/<br\s*\/?>/gi, "").trim() !== "");
1607
+ return shown.length ? shown.join("<br>") : html;
1608
+ }
1597
1609
  function unwrapLoneBlock(html) {
1598
1610
  const m = html.match(/^<(p|div|h[1-6])(?:\s[^>]*)?>([\s\S]*)<\/\1>$/i);
1599
1611
  return m && !new RegExp(`</${m[1]}>`, "i").test(m[2]) ? m[2] : html;
@@ -2079,6 +2091,16 @@ async function submitForm(opts) {
2079
2091
 
2080
2092
  // src/index.ts
2081
2093
  var import_types = require("@bettercms-ai/types");
2094
+
2095
+ // src/in-editor.ts
2096
+ var EDITOR_FRAME_NAME = "bcms-editor";
2097
+ function inEditor(win = globalThis.window) {
2098
+ try {
2099
+ return !!win && win.name === EDITOR_FRAME_NAME && win.self !== win.top;
2100
+ } catch {
2101
+ return false;
2102
+ }
2103
+ }
2082
2104
  // Annotate the CommonJS export names for ESM import in node:
2083
2105
  0 && (module.exports = {
2084
2106
  BCMSClientError,
@@ -2089,6 +2111,7 @@ var import_types = require("@bettercms-ai/types");
2089
2111
  BetterCMSError,
2090
2112
  BetterCMSManagementClient,
2091
2113
  CONTENT_APPLIED,
2114
+ EDITOR_FRAME_NAME,
2092
2115
  ErrorCodes,
2093
2116
  PORTABLE_TEXT_FORMAT,
2094
2117
  STEGA_OPEN,
@@ -2130,10 +2153,12 @@ var import_types = require("@bettercms-ai/types");
2130
2153
  imageUrlBuilder,
2131
2154
  imageValueObjectPosition,
2132
2155
  imageValueUrl,
2156
+ inEditor,
2133
2157
  inviteMember,
2134
2158
  isBlock,
2135
2159
  isMultiValueField,
2136
2160
  isRichText,
2161
+ lines,
2137
2162
  listApiKeys,
2138
2163
  listEntries,
2139
2164
  listForms,