@saltcorn/builder 0.7.3-beta.3 → 0.7.3

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.
@@ -8,6 +8,7 @@ import React, { Fragment, useState, useContext, useEffect } from "react";
8
8
  import { ntimes } from "./Columns";
9
9
  import { Column } from "./Column";
10
10
  import optionsCtx from "../context";
11
+ import { setAPropGen } from "./utils";
11
12
 
12
13
  import { Element, useNode } from "@craftjs/core";
13
14
 
@@ -194,6 +195,8 @@ const TabsSettings = () => {
194
195
  }
195
196
  });
196
197
  }, [field]);
198
+ const setAProp = setAPropGen(setProp);
199
+
197
200
  return (
198
201
  <table className="w-100" accordiontitle="Placement">
199
202
  <tbody>
@@ -205,11 +208,7 @@ const TabsSettings = () => {
205
208
  <select
206
209
  value={tabsStyle}
207
210
  className="form-control form-select"
208
- onChange={(e) =>
209
- setProp((prop) => {
210
- prop.tabsStyle = e.target.value;
211
- })
212
- }
211
+ onChange={setAProp("tabsStyle")}
213
212
  >
214
213
  <option>Tabs</option>
215
214
  <option>Pills</option>
@@ -229,9 +228,7 @@ const TabsSettings = () => {
229
228
  <select
230
229
  value={field}
231
230
  className="form-control form-select"
232
- onChange={(e) => {
233
- setProp((prop) => (prop.field = e.target.value));
234
- }}
231
+ onChange={setAProp("field")}
235
232
  >
236
233
  {options.fields.map((f, ix) => (
237
234
  <option key={ix} value={f.name}>
@@ -255,9 +252,7 @@ const TabsSettings = () => {
255
252
  step="1"
256
253
  min="0"
257
254
  max="20"
258
- onChange={(e) =>
259
- setProp((prop) => (prop.ntabs = e.target.value))
260
- }
255
+ onChange={setAProp("ntabs")}
261
256
  />
262
257
  </td>
263
258
  </tr>
@@ -272,9 +267,11 @@ const TabsSettings = () => {
272
267
  type="text"
273
268
  className="form-control text-to-display"
274
269
  value={titles[ix]}
275
- onChange={(e) =>
276
- setProp((prop) => (prop.titles[ix] = e.target.value))
277
- }
270
+ onChange={(e) => {
271
+ if (!e.target) return;
272
+ const value = e.target.value;
273
+ setProp((prop) => (prop.titles[ix] = value));
274
+ }}
278
275
  />
279
276
  </td>
280
277
  </tr>
@@ -288,13 +285,7 @@ const TabsSettings = () => {
288
285
  name="block"
289
286
  type="checkbox"
290
287
  checked={independent}
291
- onChange={(e) => {
292
- if (e.target) {
293
- setProp(
294
- (prop) => (prop.independent = e.target.checked)
295
- );
296
- }
297
- }}
288
+ onChange={setAProp("independent", { checked: true })}
298
289
  />
299
290
  <label className="form-check-label">
300
291
  Open independently
@@ -311,11 +302,7 @@ const TabsSettings = () => {
311
302
  name="block"
312
303
  type="checkbox"
313
304
  checked={deeplink}
314
- onChange={(e) => {
315
- if (e.target) {
316
- setProp((prop) => (prop.deeplink = e.target.checked));
317
- }
318
- }}
305
+ onChange={setAProp("deeplink", { checked: true })}
319
306
  />
320
307
  <label className="form-check-label">Deep link</label>
321
308
  </div>
@@ -17,6 +17,7 @@ import {
17
17
  isBlock,
18
18
  reactifyStyles,
19
19
  SettingsRow,
20
+ setAPropGen,
20
21
  } from "./utils";
21
22
  import ContentEditable from "react-contenteditable";
22
23
  import optionsCtx from "../context";
@@ -121,7 +122,9 @@ const Text = ({
121
122
  html={text}
122
123
  style={{ display: "inline" }}
123
124
  disabled={!editable}
124
- onChange={(e) => setProp((props) => (props.text = e.target.value))}
125
+ onChange={(e) =>
126
+ e?.target && setProp((props) => (props.text = e.target.value))
127
+ }
125
128
  />
126
129
  </Fragment>
127
130
  ) : editable ? (
@@ -175,12 +178,7 @@ const TextSettings = () => {
175
178
  style,
176
179
  } = node;
177
180
  const { mode, fields } = useContext(optionsCtx);
178
- const setAProp = (key) => (e) => {
179
- if (e.target) {
180
- const target_value = e.target.value;
181
- setProp((prop) => (prop[key] = target_value));
182
- }
183
- };
181
+ const setAProp = setAPropGen(setProp);
184
182
  return (
185
183
  <div>
186
184
  {mode === "show" && (
@@ -189,9 +187,11 @@ const TextSettings = () => {
189
187
  type="checkbox"
190
188
  className="form-check-input"
191
189
  checked={isFormula.text}
192
- onChange={(e) =>
193
- setProp((prop) => (prop.isFormula.text = e.target.checked))
194
- }
190
+ onChange={(e) => {
191
+ if (!e.target) return;
192
+ const checked = e.target.checked;
193
+ setProp((prop) => (prop.isFormula.text = checked));
194
+ }}
195
195
  />
196
196
  <label className="form-check-label">Formula?</label>
197
197
  </div>
@@ -7,7 +7,7 @@
7
7
  import React, { useContext, Fragment } from "react";
8
8
  import { useNode } from "@craftjs/core";
9
9
  import optionsCtx from "../context";
10
- import { blockProps, BlockSetting, TextStyleRow } from "./utils";
10
+ import { blockProps, BlockSetting, TextStyleRow, setAPropGen } from "./utils";
11
11
 
12
12
  export /**
13
13
  * @param {object} props
@@ -78,12 +78,7 @@ const ToggleFilterSettings = () => {
78
78
  const field = options.fields.find((f) => f.name === name);
79
79
  const preset_options = field.preset_options;
80
80
  const isBool = field && field.type.name === "Bool";
81
- const setAProp = (key) => (e) => {
82
- if (e.target) {
83
- const target_value = e.target.value;
84
- setProp((prop) => (prop[key] = target_value));
85
- }
86
- };
81
+ const setAProp = setAPropGen(setProp);
87
82
  return (
88
83
  <table className="w-100">
89
84
  <tbody>
@@ -96,13 +91,15 @@ const ToggleFilterSettings = () => {
96
91
  value={name}
97
92
  className="form-control form-select"
98
93
  onChange={(e) => {
99
- setProp((prop) => (prop.name = e.target.value));
100
- const field = options.fields.find(
101
- (f) => f.name === e.target.value
102
- );
103
- const isBool = field && field.type.name === "Bool";
104
- if (isBool) setProp((prop) => (prop.value = "on"));
105
- setProp((prop) => (prop.preset_value = ""));
94
+ if (e?.target) {
95
+ if (!e.target) return;
96
+ const value = e.target.value;
97
+ setProp((prop) => (prop.name = value));
98
+ const field = options.fields.find((f) => f.name === value);
99
+ const isBool = field && field.type.name === "Bool";
100
+ if (isBool) setProp((prop) => (prop.value = "on"));
101
+ setProp((prop) => (prop.preset_value = ""));
102
+ }
106
103
  }}
107
104
  >
108
105
  {options.fields.map((f, ix) => (
@@ -15,6 +15,7 @@ import {
15
15
  MinRoleSetting,
16
16
  fetchViewPreview,
17
17
  ConfigForm,
18
+ setAPropGen,
18
19
  } from "./utils";
19
20
 
20
21
  export /**
@@ -99,18 +100,17 @@ const ViewSettings = () => {
99
100
  options.fixed_state_fields && options.fixed_state_fields[view];
100
101
  const { setPreviews } = useContext(previewCtx);
101
102
 
102
- const setAProp = (key) => (e) => {
103
- if (e.target) {
104
- const target_value = e.target.value;
105
- setProp((prop) => (prop[key] = target_value));
106
- }
107
- };
103
+ const setAProp = setAPropGen(setProp);
108
104
  let errorString = false;
109
105
  try {
110
106
  Function("return " + extra_state_fml);
111
107
  } catch (error) {
112
108
  errorString = error.message;
113
109
  }
110
+ let viewname = view;
111
+ if (viewname && viewname.includes(":")) viewname = viewname.split(":")[1];
112
+ if (viewname && viewname.includes(".")) viewname = viewname.split(".")[0];
113
+
114
114
  return (
115
115
  <div>
116
116
  <div>
@@ -118,9 +118,7 @@ const ViewSettings = () => {
118
118
  <select
119
119
  value={view}
120
120
  className="form-control form-select"
121
- onChange={(e) => {
122
- setProp((prop) => (prop.view = e.target.value));
123
- }}
121
+ onChange={setAProp("view")}
124
122
  >
125
123
  {views.map((f, ix) => (
126
124
  <option key={ix} value={f.name}>
@@ -165,9 +163,7 @@ const ViewSettings = () => {
165
163
  type="text"
166
164
  className="viewlink-label form-control"
167
165
  value={extra_state_fml}
168
- onChange={(e) =>
169
- setProp((prop) => (prop.extra_state_fml = e.target.value))
170
- }
166
+ onChange={setAProp("extra_state_fml")}
171
167
  />
172
168
  {errorString ? (
173
169
  <small className="text-danger font-monospace d-block">
@@ -180,7 +176,7 @@ const ViewSettings = () => {
180
176
  <a
181
177
  className="d-block mt-2"
182
178
  target="_blank"
183
- href={`/viewedit/config/${view}`}
179
+ href={`/viewedit/config/${viewname}`}
184
180
  >
185
181
  Configure this view
186
182
  </a>
@@ -14,6 +14,7 @@ import {
14
14
  OrFormula,
15
15
  TextStyleSetting,
16
16
  ButtonOrLinkSettingsRows,
17
+ setAPropGen,
17
18
  } from "./utils";
18
19
 
19
20
  export /**
@@ -119,6 +120,8 @@ const ViewLinkSettings = () => {
119
120
  } catch (error) {
120
121
  errorString = error.message;
121
122
  }
123
+ const setAProp = setAPropGen(setProp);
124
+
122
125
  return (
123
126
  <div>
124
127
  <table className="w-100">
@@ -129,9 +132,7 @@ const ViewLinkSettings = () => {
129
132
  <select
130
133
  value={name}
131
134
  className="form-control form-select"
132
- onChange={(e) =>
133
- setProp((prop) => (prop.name = e.target.value))
134
- }
135
+ onChange={setAProp("name")}
135
136
  >
136
137
  {options.link_view_opts.map((f, ix) => (
137
138
  <option key={ix} value={f.name}>
@@ -149,9 +150,7 @@ const ViewLinkSettings = () => {
149
150
  type="text"
150
151
  className="viewlink-label form-control"
151
152
  value={label}
152
- onChange={(e) =>
153
- setProp((prop) => (prop.label = e.target.value))
154
- }
153
+ onChange={setAProp("label")}
155
154
  />
156
155
  </OrFormula>
157
156
  </td>
@@ -163,9 +162,7 @@ const ViewLinkSettings = () => {
163
162
  type="text"
164
163
  className="viewlink-label form-control"
165
164
  value={extra_state_fml}
166
- onChange={(e) =>
167
- setProp((prop) => (prop.extra_state_fml = e.target.value))
168
- }
165
+ onChange={setAProp("extra_state_fml")}
169
166
  />
170
167
  {errorString ? (
171
168
  <small className="text-danger font-monospace d-block">
@@ -190,7 +187,7 @@ const ViewLinkSettings = () => {
190
187
  name="block"
191
188
  type="checkbox"
192
189
  checked={inModal}
193
- onChange={(e) => setProp((prop) => (prop.inModal = e.target.checked))}
190
+ onChange={setAProp("inModal", { checked: true })}
194
191
  />
195
192
  <label className="form-check-label">Open in popup modal?</label>
196
193
  </div>
@@ -820,6 +820,7 @@ const ConfigField = ({
820
820
  className="w-50 form-control-sm d-inline dimunit"
821
821
  disabled={field.autoable && styleDim === "auto"}
822
822
  onChange={(e) =>
823
+ e?.target &&
823
824
  myOnChange(
824
825
  isStyle
825
826
  ? `${e.target.value}${styleDim || "px"}`
@@ -1053,12 +1054,7 @@ const ButtonOrLinkSettingsRows = ({
1053
1054
  values,
1054
1055
  linkFirst = false,
1055
1056
  }) => {
1056
- const setAProp = (key) => (e) => {
1057
- if (e.target) {
1058
- const target_value = e.target.value;
1059
- setProp((prop) => (prop[key] = target_value));
1060
- }
1061
- };
1057
+ const setAProp = setAPropGen(setProp);
1062
1058
  const addBtnClass = (s) => (btnClass ? `${btnClass} ${s}` : s);
1063
1059
  return [
1064
1060
  <tr key="btnstyle">
@@ -1228,3 +1224,13 @@ export const recursivelyCloneToElems = (query) => (nodeId, ix) => {
1228
1224
 
1229
1225
  export const isBlock = (block, inline, textStyle) =>
1230
1226
  !textStyle || !textStyle.startsWith("h") ? block : !inline;
1227
+
1228
+ export const setAPropGen =
1229
+ (setProp) =>
1230
+ (key, opts = {}) =>
1231
+ (e) => {
1232
+ if (e.target) {
1233
+ const target_value = opts?.checked ? e.target.checked : e.target.value;
1234
+ setProp((prop) => (prop[key] = target_value));
1235
+ }
1236
+ };