@bettercms-ai/sdk 1.9.0 → 1.10.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
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  ErrorCodes: () => ErrorCodes,
41
41
  addModelFields: () => addModelFields,
42
42
  addPageFields: () => addPageFields,
43
+ asStringArray: () => asStringArray,
43
44
  createApiKey: () => createApiKey,
44
45
  createClient: () => createClient,
45
46
  createEntry: () => createEntry,
@@ -71,6 +72,7 @@ __export(index_exports, {
71
72
  imageUrlBuilder: () => import_image_url.default,
72
73
  inviteMember: () => inviteMember,
73
74
  isBlock: () => import_types.isBlock,
75
+ isMultiValueField: () => isMultiValueField,
74
76
  isRichText: () => isRichText,
75
77
  listApiKeys: () => listApiKeys,
76
78
  listEntries: () => listEntries,
@@ -98,6 +100,7 @@ __export(index_exports, {
98
100
  signUp: () => signUp,
99
101
  stripStega: () => stripStega,
100
102
  submitForm: () => submitForm,
103
+ toggleOption: () => toggleOption,
101
104
  updateApiKey: () => updateApiKey,
102
105
  updateEntry: () => updateEntry,
103
106
  updateForm: () => updateForm2,
@@ -1568,16 +1571,33 @@ async function removeMember(client, workspaceId, memberId) {
1568
1571
  }
1569
1572
 
1570
1573
  // src/forms.ts
1574
+ function isMultiValueField(type) {
1575
+ return type === "checkboxes";
1576
+ }
1577
+ function asStringArray(value) {
1578
+ if (Array.isArray(value)) return value;
1579
+ return value ? [String(value)] : [];
1580
+ }
1581
+ function toggleOption(value, option, on) {
1582
+ const current = asStringArray(value);
1583
+ if (on) return current.includes(option) ? current : [...current, option];
1584
+ return current.filter((v) => v !== option);
1585
+ }
1571
1586
  var DEFAULT_BASE_URL5 = "https://api.bettercms.ai";
1572
1587
  function shouldShowField(field, values) {
1573
1588
  if (!field.showIf) return true;
1574
- return String(values[field.showIf.field] ?? "") === field.showIf.equals;
1589
+ const trigger = values[field.showIf.field];
1590
+ if (Array.isArray(trigger)) return trigger.includes(field.showIf.equals);
1591
+ return String(trigger ?? "") === field.showIf.equals;
1575
1592
  }
1576
1593
  function formInitialValues(form, prefill = {}) {
1577
1594
  const values = {};
1578
1595
  for (const field of form.fields) {
1579
1596
  if (field.type === "checkbox" || field.type === "consent") {
1580
1597
  values[field.key] = false;
1598
+ } else if (field.type === "checkboxes") {
1599
+ const seed = prefill[field.key] ?? field.defaultValue ?? "";
1600
+ values[field.key] = seed ? seed.split(",").map((v) => v.trim()).filter(Boolean) : [];
1581
1601
  } else {
1582
1602
  values[field.key] = prefill[field.key] ?? field.defaultValue ?? "";
1583
1603
  }
@@ -1627,6 +1647,7 @@ var import_types = require("@bettercms-ai/types");
1627
1647
  ErrorCodes,
1628
1648
  addModelFields,
1629
1649
  addPageFields,
1650
+ asStringArray,
1630
1651
  createApiKey,
1631
1652
  createClient,
1632
1653
  createEntry,
@@ -1658,6 +1679,7 @@ var import_types = require("@bettercms-ai/types");
1658
1679
  imageUrlBuilder,
1659
1680
  inviteMember,
1660
1681
  isBlock,
1682
+ isMultiValueField,
1661
1683
  isRichText,
1662
1684
  listApiKeys,
1663
1685
  listEntries,
@@ -1685,6 +1707,7 @@ var import_types = require("@bettercms-ai/types");
1685
1707
  signUp,
1686
1708
  stripStega,
1687
1709
  submitForm,
1710
+ toggleOption,
1688
1711
  updateApiKey,
1689
1712
  updateEntry,
1690
1713
  updateForm,