@saltcorn/builder 0.7.3-beta.7 → 0.7.4-beta.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.
@@ -13,6 +13,7 @@ import {
13
13
  OrFormula,
14
14
  ButtonOrLinkSettingsRows,
15
15
  DynamicFontAwesomeIcon,
16
+ setAPropGen,
16
17
  } from "./utils";
17
18
  import optionsCtx from "../context";
18
19
 
@@ -111,12 +112,7 @@ const LinkSettings = () => {
111
112
  transfer_state,
112
113
  } = node;
113
114
  const options = useContext(optionsCtx);
114
- const setAProp = (key) => (e) => {
115
- if (e.target) {
116
- const target_value = e.target.value;
117
- setProp((prop) => (prop[key] = target_value));
118
- }
119
- };
115
+ const setAProp = setAPropGen(setProp);
120
116
  return (
121
117
  <div>
122
118
  <table className="w-100">
@@ -144,14 +140,16 @@ const LinkSettings = () => {
144
140
  <select
145
141
  value={link_src}
146
142
  className="form-control form-select"
147
- onChange={(e) =>
143
+ onChange={(e) => {
144
+ if (!e.target) return;
145
+ const value = e.target.value;
148
146
  setProp((prop) => {
149
- prop.link_src = e.target.value;
147
+ prop.link_src = value;
150
148
  if (e.target.value !== "URL") {
151
149
  prop.isFormula.url = false;
152
150
  }
153
- })
154
- }
151
+ });
152
+ }}
155
153
  >
156
154
  <option>URL</option>
157
155
  {(options.pages || []).length > 0 && <option>Page</option>}
@@ -237,9 +235,7 @@ const LinkSettings = () => {
237
235
  name="block"
238
236
  type="checkbox"
239
237
  checked={nofollow}
240
- onChange={(e) =>
241
- setProp((prop) => (prop.nofollow = e.target.checked))
242
- }
238
+ onChange={setAProp("nofollow", { checked: true })}
243
239
  />
244
240
  <label className="form-check-label">Nofollow</label>
245
241
  </div>
@@ -249,9 +245,7 @@ const LinkSettings = () => {
249
245
  name="block"
250
246
  type="checkbox"
251
247
  checked={target_blank}
252
- onChange={(e) =>
253
- setProp((prop) => (prop.target_blank = e.target.checked))
254
- }
248
+ onChange={setAProp("target_blank", { checked: true })}
255
249
  />
256
250
  <label className="form-check-label">Open in new tab</label>
257
251
  </div>
@@ -261,9 +255,7 @@ const LinkSettings = () => {
261
255
  name="block"
262
256
  type="checkbox"
263
257
  checked={in_modal}
264
- onChange={(e) =>
265
- setProp((prop) => (prop.in_modal = e.target.checked))
266
- }
258
+ onChange={setAProp("in_modal", { checked: true })}
267
259
  />
268
260
  <label className="form-check-label">Open in popup modal?</label>
269
261
  </div>
@@ -275,9 +267,7 @@ const LinkSettings = () => {
275
267
  name="block"
276
268
  type="checkbox"
277
269
  checked={transfer_state}
278
- onChange={(e) =>
279
- setProp((prop) => (prop.transfer_state = e.target.checked))
280
- }
270
+ onChange={setAProp("transfer_state", { checked: true })}
281
271
  />
282
272
  <label className="form-check-label">Transfer state</label>
283
273
  </div>
@@ -9,6 +9,7 @@ import { Element, useNode } from "@craftjs/core";
9
9
  import { Column } from "./Column";
10
10
  import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
11
11
  import { faCaretDown } from "@fortawesome/free-solid-svg-icons";
12
+ import { setAPropGen } from "./utils";
12
13
 
13
14
  export /**
14
15
  * @param {object} props
@@ -92,6 +93,7 @@ const SearchBarSettings = () => {
92
93
  has_dropdown: node.data.props.has_dropdown,
93
94
  show_badges: node.data.props.show_badges,
94
95
  }));
96
+ const setAProp = setAPropGen(setProp);
95
97
 
96
98
  return (
97
99
  <div>
@@ -101,9 +103,7 @@ const SearchBarSettings = () => {
101
103
  name="block"
102
104
  type="checkbox"
103
105
  checked={has_dropdown}
104
- onChange={(e) =>
105
- setProp((prop) => (prop.has_dropdown = e.target.checked))
106
- }
106
+ onChange={setAProp("has_dropdown", { checked: true })}
107
107
  />
108
108
  <label className="form-check-label">Has Dropdown</label>
109
109
  </div>
@@ -113,9 +113,7 @@ const SearchBarSettings = () => {
113
113
  name="block"
114
114
  type="checkbox"
115
115
  checked={show_badges}
116
- onChange={(e) =>
117
- setProp((prop) => (prop.show_badges = e.target.checked))
118
- }
116
+ onChange={setAProp("show_badges", { checked: true })}
119
117
  />
120
118
  <label className="form-check-label">Show current state badges</label>
121
119
  </div>
@@ -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,8 @@ import {
15
15
  MinRoleSetting,
16
16
  fetchViewPreview,
17
17
  ConfigForm,
18
+ setAPropGen,
19
+ FormulaTooltip,
18
20
  } from "./utils";
19
21
 
20
22
  export /**
@@ -99,18 +101,17 @@ const ViewSettings = () => {
99
101
  options.fixed_state_fields && options.fixed_state_fields[view];
100
102
  const { setPreviews } = useContext(previewCtx);
101
103
 
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
- };
104
+ const setAProp = setAPropGen(setProp);
108
105
  let errorString = false;
109
106
  try {
110
107
  Function("return " + extra_state_fml);
111
108
  } catch (error) {
112
109
  errorString = error.message;
113
110
  }
111
+ let viewname = view;
112
+ if (viewname && viewname.includes(":")) viewname = viewname.split(":")[1];
113
+ if (viewname && viewname.includes(".")) viewname = viewname.split(".")[0];
114
+
114
115
  return (
115
116
  <div>
116
117
  <div>
@@ -118,9 +119,7 @@ const ViewSettings = () => {
118
119
  <select
119
120
  value={view}
120
121
  className="form-control form-select"
121
- onChange={(e) => {
122
- setProp((prop) => (prop.view = e.target.value));
123
- }}
122
+ onChange={setAProp("view")}
124
123
  >
125
124
  {views.map((f, ix) => (
126
125
  <option key={ix} value={f.name}>
@@ -160,14 +159,12 @@ const ViewSettings = () => {
160
159
  {(state === "shared" || options.mode === "page") && (
161
160
  <Fragment>
162
161
  {" "}
163
- <label>Extra state Formula</label>
162
+ <label>Extra state Formula <FormulaTooltip /></label>
164
163
  <input
165
164
  type="text"
166
165
  className="viewlink-label form-control"
167
166
  value={extra_state_fml}
168
- onChange={(e) =>
169
- setProp((prop) => (prop.extra_state_fml = e.target.value))
170
- }
167
+ onChange={setAProp("extra_state_fml")}
171
168
  />
172
169
  {errorString ? (
173
170
  <small className="text-danger font-monospace d-block">
@@ -180,7 +177,7 @@ const ViewSettings = () => {
180
177
  <a
181
178
  className="d-block mt-2"
182
179
  target="_blank"
183
- href={`/viewedit/config/${view}`}
180
+ href={`/viewedit/config/${viewname}`}
184
181
  >
185
182
  Configure this view
186
183
  </a>
@@ -14,6 +14,8 @@ import {
14
14
  OrFormula,
15
15
  TextStyleSetting,
16
16
  ButtonOrLinkSettingsRows,
17
+ setAPropGen,
18
+ FormulaTooltip,
17
19
  } from "./utils";
18
20
 
19
21
  export /**
@@ -119,6 +121,8 @@ const ViewLinkSettings = () => {
119
121
  } catch (error) {
120
122
  errorString = error.message;
121
123
  }
124
+ const setAProp = setAPropGen(setProp);
125
+
122
126
  return (
123
127
  <div>
124
128
  <table className="w-100">
@@ -129,9 +133,7 @@ const ViewLinkSettings = () => {
129
133
  <select
130
134
  value={name}
131
135
  className="form-control form-select"
132
- onChange={(e) =>
133
- setProp((prop) => (prop.name = e.target.value))
134
- }
136
+ onChange={setAProp("name")}
135
137
  >
136
138
  {options.link_view_opts.map((f, ix) => (
137
139
  <option key={ix} value={f.name}>
@@ -149,23 +151,19 @@ const ViewLinkSettings = () => {
149
151
  type="text"
150
152
  className="viewlink-label form-control"
151
153
  value={label}
152
- onChange={(e) =>
153
- setProp((prop) => (prop.label = e.target.value))
154
- }
154
+ onChange={setAProp("label")}
155
155
  />
156
156
  </OrFormula>
157
157
  </td>
158
158
  </tr>
159
159
  <tr>
160
160
  <td colSpan="2">
161
- <label>Extra state Formula</label>
161
+ <label>Extra state Formula <FormulaTooltip /></label>
162
162
  <input
163
163
  type="text"
164
164
  className="viewlink-label form-control"
165
165
  value={extra_state_fml}
166
- onChange={(e) =>
167
- setProp((prop) => (prop.extra_state_fml = e.target.value))
168
- }
166
+ onChange={setAProp("extra_state_fml")}
169
167
  />
170
168
  {errorString ? (
171
169
  <small className="text-danger font-monospace d-block">
@@ -190,7 +188,7 @@ const ViewLinkSettings = () => {
190
188
  name="block"
191
189
  type="checkbox"
192
190
  checked={inModal}
193
- onChange={(e) => setProp((prop) => (prop.inModal = e.target.checked))}
191
+ onChange={setAProp("inModal", { checked: true })}
194
192
  />
195
193
  <label className="form-check-label">Open in popup modal?</label>
196
194
  </div>