@saltcorn/builder 1.6.0-beta.8 → 1.6.0-rc.1

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.
@@ -707,7 +707,8 @@ const fetchPreview = ({ url, body, options, setPreviews, node_id, isView }) => {
707
707
  else return "";
708
708
  })
709
709
  .then(function (html) {
710
- $(".preview-scratchpad").html(html);
710
+ const scratchpad = document.querySelector(".preview-scratchpad");
711
+ if (scratchpad) scratchpad.innerHTML = html;
711
712
  $(".preview-scratchpad").find("iframe").css("pointer-events", "none");
712
713
  $(".preview-scratchpad").find("a").attr("href", "#");
713
714
  $(".preview-scratchpad")
@@ -936,7 +937,7 @@ const ColorInput = ({ value, onChange }) =>
936
937
  </button>
937
938
  );
938
939
 
939
- const CodeFieldWithModal = ({ value, onChange, setProp, mode, label, hideLabel }) => {
940
+ const CodeFieldWithModal = ({ value, onChange, setProp, mode, label, hideLabel, placeholder, nojoins }) => {
940
941
  const [modalOpen, setModalOpen] = useState(false);
941
942
  const { t } = useTranslation();
942
943
  return (
@@ -965,6 +966,8 @@ const CodeFieldWithModal = ({ value, onChange, setProp, mode, label, hideLabel }
965
966
  value={value}
966
967
  onChange={onChange}
967
968
  mode={mode}
969
+ placeholder={placeholder}
970
+ nojoins={nojoins}
968
971
  />
969
972
  {modalOpen ? (
970
973
  <div
@@ -1052,15 +1055,17 @@ const ConfigForm = ({
1052
1055
  if (f.showIf && configuration) {
1053
1056
  let noshow = false;
1054
1057
  Object.entries(f.showIf).forEach(([nm, value]) => {
1058
+ const cfgVal = configuration[nm];
1059
+ const effectiveVal = cfgVal === undefined ? false : cfgVal;
1055
1060
  if (Array.isArray(value))
1056
- noshow = noshow || !value.includes(configuration[nm]);
1057
- else noshow = noshow || value !== configuration[nm];
1061
+ noshow = noshow || !value.includes(effectiveVal);
1062
+ else noshow = noshow || value !== effectiveVal;
1058
1063
  });
1059
1064
  if (noshow) return null;
1060
1065
  }
1061
1066
  return (
1062
1067
  <div key={ix} className="builder-config-field" data-field-name={f.name}>
1063
- {!isCheckbox(f) && f.input_type !== "code" ? (
1068
+ {!isCheckbox(f) && (f.input_type !== "code" || f.attributes?.singleline) ? (
1064
1069
  <label>
1065
1070
  {f.label || f.name}
1066
1071
  {f.help ? (
@@ -1326,19 +1331,11 @@ const ConfigField = ({
1326
1331
  />
1327
1332
  ),
1328
1333
  code: () => {
1329
- if (
1330
- field?.attributes?.expression_type === "row" ||
1331
- field?.attributes?.expression_type === "query"
1332
- ) {
1334
+ if (field?.attributes?.singleline) {
1333
1335
  return (
1334
- <textarea
1335
- rows="6"
1336
- type="text"
1337
- className={`field-${field?.name} form-control`}
1338
- value={value}
1339
- name={field?.name}
1340
- onChange={(e) => e.target && myOnChange(e.target.value)}
1341
- spellCheck={false}
1336
+ <SingleLineEditor
1337
+ value={value || ""}
1338
+ onChange={myOnChange}
1342
1339
  />
1343
1340
  );
1344
1341
  }
@@ -1349,6 +1346,8 @@ const ConfigField = ({
1349
1346
  setProp={setProp}
1350
1347
  mode={field?.attributes?.mode}
1351
1348
  label={field?.label || field?.name || "Code"}
1349
+ placeholder={field?.attributes?.placeholder}
1350
+ nojoins={field?.attributes?.nojoins}
1352
1351
  />
1353
1352
  );
1354
1353
  },
@@ -1382,31 +1381,40 @@ const ConfigField = ({
1382
1381
  styles={reactSelectStyles()}
1383
1382
  ></Select>
1384
1383
  );
1385
- } else
1384
+ } else {
1385
+ const explainerText = field.attributes?.explainers?.[value || ""];
1386
1386
  return (
1387
- <select
1388
- className={`field-${field?.name} form-control form-select`}
1389
- value={value || ""}
1390
- name={field?.name}
1391
- onChange={(e) => e.target && myOnChange(e.target.value)}
1392
- onBlur={(e) => e.target && myOnChange(e.target.value)}
1393
- data-fieldname={field?.name}
1394
- >
1395
- {(field.options || []).map((o, ix) =>
1396
- o.name && o.label ? (
1397
- <option key={ix} value={o.name}>
1398
- {o.label}
1399
- </option>
1400
- ) : o.value && o.label ? (
1401
- <option key={ix} value={o.value}>
1402
- {o.label}
1403
- </option>
1404
- ) : (
1405
- <option key={ix}>{o}</option>
1406
- )
1387
+ <Fragment>
1388
+ <select
1389
+ className={`field-${field?.name} form-control form-select`}
1390
+ value={value || ""}
1391
+ name={field?.name}
1392
+ onChange={(e) => e.target && myOnChange(e.target.value)}
1393
+ onBlur={(e) => e.target && myOnChange(e.target.value)}
1394
+ data-fieldname={field?.name}
1395
+ >
1396
+ {(field.options || []).map((o, ix) =>
1397
+ o.name && o.label ? (
1398
+ <option key={ix} value={o.name}>
1399
+ {o.label}
1400
+ </option>
1401
+ ) : o.value && o.label ? (
1402
+ <option key={ix} value={o.value}>
1403
+ {o.label}
1404
+ </option>
1405
+ ) : (
1406
+ <option key={ix}>{o}</option>
1407
+ )
1408
+ )}
1409
+ </select>
1410
+ {explainerText && (
1411
+ <div className="alert alert-info py-1 px-2 my-1 small">
1412
+ <strong>{value}</strong>: {explainerText}
1413
+ </div>
1407
1414
  )}
1408
- </select>
1415
+ </Fragment>
1409
1416
  );
1417
+ }
1410
1418
  },
1411
1419
  btn_select: () => (
1412
1420
  <div className="btn-group w-100" role="group">
@@ -1543,9 +1551,11 @@ const SettingsFromFields =
1543
1551
  if (f.showIf) {
1544
1552
  let noshow = false;
1545
1553
  Object.entries(f.showIf).forEach(([nm, value]) => {
1554
+ const cfgVal = node[nm];
1555
+ const effectiveVal = cfgVal === undefined ? false : cfgVal;
1546
1556
  if (Array.isArray(value))
1547
- noshow = noshow || !value.includes(node[nm]);
1548
- else noshow = noshow || value !== node[nm];
1557
+ noshow = noshow || !value.includes(effectiveVal);
1558
+ else noshow = noshow || value !== effectiveVal;
1549
1559
  });
1550
1560
  if (noshow) return null;
1551
1561
  }
@@ -1630,7 +1640,7 @@ const SettingsRow = ({
1630
1640
  <tr>
1631
1641
  {fullWidth ? (
1632
1642
  <td colSpan="2">
1633
- {needLabel && field.input_type !== "code" && <label>{field.label}</label>}
1643
+ {needLabel && (field.input_type !== "code" || field.attributes?.singleline) && <label>{field.label}</label>}
1634
1644
  {inner}
1635
1645
  {field.sublabel ? (
1636
1646
  <i
@@ -152,7 +152,7 @@ const layoutToNodes = (
152
152
  }
153
153
  });
154
154
  if (related.fields.some((f) => f.canBeFormula))
155
- props.isFormula = segment.isFormula;
155
+ props.isFormula = segment.isFormula ?? {};
156
156
  if (related.hasContents)
157
157
  return (
158
158
  <Element