@saltcorn/builder 0.7.4-beta.1 → 0.7.4-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/builder",
3
- "version": "0.7.4-beta.1",
3
+ "version": "0.7.4-beta.3",
4
4
  "description": "Drag and drop view builder for Saltcorn, open-source no-code platform",
5
5
  "main": "index.js",
6
6
  "homepage": "https://saltcorn.com",
@@ -34,44 +34,43 @@ export /**
34
34
  * @category saltcorn-builder
35
35
  * @subcategory components
36
36
  */
37
- const Link = ({
38
- text,
39
- block,
40
- isFormula,
41
- textStyle,
42
- link_style,
43
- link_size,
44
- link_icon,
45
- link_bgcol,
46
- link_bordercol,
47
- link_textcol,
48
- }) => {
49
- const {
50
- selected,
51
- connectors: { connect, drag },
52
- } = useNode((node) => ({ selected: node.events.selected }));
53
- return (
54
- <span
55
- className={`${textStyle} is-builder-link ${
56
- selected ? "selected-node" : ""
57
- } ${isFormula?.text ? "font-monospace" : ""} ${link_style} ${link_size}`}
58
- {...blockProps(block)}
59
- ref={(dom) => connect(drag(dom))}
60
- style={
61
- link_style === "btn btn-custom-color"
62
- ? {
37
+ const Link = ({
38
+ text,
39
+ block,
40
+ isFormula,
41
+ textStyle,
42
+ link_style,
43
+ link_size,
44
+ link_icon,
45
+ link_bgcol,
46
+ link_bordercol,
47
+ link_textcol,
48
+ }) => {
49
+ const {
50
+ selected,
51
+ connectors: { connect, drag },
52
+ } = useNode((node) => ({ selected: node.events.selected }));
53
+ return (
54
+ <span
55
+ className={`${textStyle} is-builder-link ${selected ? "selected-node" : ""
56
+ } ${isFormula?.text ? "font-monospace" : ""} ${link_style} ${link_size}`}
57
+ {...blockProps(block)}
58
+ ref={(dom) => connect(drag(dom))}
59
+ style={
60
+ link_style === "btn btn-custom-color"
61
+ ? {
63
62
  backgroundColor: link_bgcol || "#000000",
64
63
  borderColor: link_bordercol || "#000000",
65
64
  color: link_textcol || "#000000",
66
65
  }
67
- : {}
68
- }
69
- >
70
- <DynamicFontAwesomeIcon icon={link_icon} className="me-1" />
71
- {isFormula?.text ? `=${text}` : text}
72
- </span>
73
- );
74
- };
66
+ : {}
67
+ }
68
+ >
69
+ <DynamicFontAwesomeIcon icon={link_icon} className="me-1" />
70
+ {isFormula?.text ? `=${text}` : text}
71
+ </span>
72
+ );
73
+ };
75
74
 
76
75
  export /**
77
76
  * @returns {div}
@@ -79,205 +78,222 @@ export /**
79
78
  * @category saltcorn-builder
80
79
  * @subcategory components
81
80
  */
82
- const LinkSettings = () => {
83
- const node = useNode((node) => ({
84
- text: node.data.props.text,
85
- url: node.data.props.url,
86
- block: node.data.props.block,
87
- isFormula: node.data.props.isFormula,
88
- textStyle: node.data.props.textStyle,
89
- nofollow: node.data.props.nofollow,
90
- in_modal: node.data.props.in_modal,
91
- link_src: node.data.props.link_src,
92
- target_blank: node.data.props.target_blank,
93
- link_style: node.data.props.link_style,
94
- link_size: node.data.props.link_size,
95
- link_icon: node.data.props.link_icon,
96
- link_bgcol: node.data.props.link_bgcol,
97
- link_bordercol: node.data.props.link_bordercol,
98
- link_textcol: node.data.props.link_textcol,
99
- transfer_state: node.data.props.transfer_state,
100
- }));
101
- const {
102
- actions: { setProp },
103
- text,
104
- url,
105
- block,
106
- isFormula,
107
- textStyle,
108
- nofollow,
109
- target_blank,
110
- link_src,
111
- in_modal,
112
- transfer_state,
113
- } = node;
114
- const options = useContext(optionsCtx);
115
- const setAProp = setAPropGen(setProp);
116
- return (
117
- <div>
118
- <table className="w-100">
119
- <tbody>
120
- <tr>
121
- <td>
122
- <label>Text to display</label>
123
- </td>
124
- <td>
125
- <OrFormula nodekey="text" {...{ setProp, isFormula, node }}>
126
- <input
127
- type="text"
128
- className="form-control text-to-display"
129
- value={text}
130
- onChange={setAProp("text")}
131
- />
132
- </OrFormula>
133
- </td>
134
- </tr>
135
- <tr>
136
- <td>
137
- <label>Link source</label>
138
- </td>
139
- <td>
140
- <select
141
- value={link_src}
142
- className="form-control form-select"
143
- onChange={(e) => {
144
- if (!e.target) return;
145
- const value = e.target.value;
146
- setProp((prop) => {
147
- prop.link_src = value;
148
- if (e.target.value !== "URL") {
149
- prop.isFormula.url = false;
150
- }
151
- });
152
- }}
153
- >
154
- <option>URL</option>
155
- {(options.pages || []).length > 0 && <option>Page</option>}
156
- {(options.views || []).length > 0 &&
157
- ["page", "filter"].includes(options.mode) && (
158
- <option>View</option>
159
- )}
160
- </select>
161
- </td>
162
- </tr>
163
- {link_src === "URL" && (
81
+ const LinkSettings = () => {
82
+ const node = useNode((node) => ({
83
+ text: node.data.props.text,
84
+ url: node.data.props.url,
85
+ block: node.data.props.block,
86
+ isFormula: node.data.props.isFormula,
87
+ textStyle: node.data.props.textStyle,
88
+ nofollow: node.data.props.nofollow,
89
+ in_modal: node.data.props.in_modal,
90
+ view_state_fml: node.data.props.view_state_fml,
91
+ link_src: node.data.props.link_src,
92
+ target_blank: node.data.props.target_blank,
93
+ link_style: node.data.props.link_style,
94
+ link_size: node.data.props.link_size,
95
+ link_icon: node.data.props.link_icon,
96
+ link_bgcol: node.data.props.link_bgcol,
97
+ link_bordercol: node.data.props.link_bordercol,
98
+ link_textcol: node.data.props.link_textcol,
99
+ transfer_state: node.data.props.transfer_state,
100
+ }));
101
+ const {
102
+ actions: { setProp },
103
+ text,
104
+ url,
105
+ block,
106
+ isFormula,
107
+ textStyle,
108
+ nofollow,
109
+ target_blank,
110
+ link_src,
111
+ in_modal,
112
+ transfer_state,
113
+ view_state_fml
114
+ } = node;
115
+ const options = useContext(optionsCtx);
116
+ const setAProp = setAPropGen(setProp);
117
+ return (
118
+ <div>
119
+ <table className="w-100">
120
+ <tbody>
164
121
  <tr>
165
122
  <td>
166
- <label>URL</label>
123
+ <label>Text to display</label>
167
124
  </td>
168
125
  <td>
169
- <OrFormula nodekey="url" {...{ setProp, isFormula, node }}>
126
+ <OrFormula nodekey="text" {...{ setProp, isFormula, node }}>
170
127
  <input
171
128
  type="text"
172
- className="form-control "
173
- value={url}
174
- onChange={setAProp("url")}
129
+ className="form-control text-to-display"
130
+ value={text}
131
+ onChange={setAProp("text")}
175
132
  />
176
133
  </OrFormula>
177
134
  </td>
178
135
  </tr>
179
- )}
180
- {link_src === "Page" && (
181
- <tr>
182
- <td>
183
- <label>Page</label>
184
- </td>
185
- <td>
186
- <select
187
- value={url}
188
- className="form-control form-select"
189
- onChange={setAProp("url")}
190
- >
191
- <option></option>
192
- {(options.pages || []).map((p, ix) => (
193
- <option key={ix} value={`/page/${p.name}`}>
194
- {p.name}
195
- </option>
196
- ))}
197
- </select>
198
- </td>
199
- </tr>
200
- )}
201
- {link_src === "View" && (
202
136
  <tr>
203
137
  <td>
204
- <label>View</label>
138
+ <label>Link source</label>
205
139
  </td>
206
140
  <td>
207
141
  <select
208
- value={url}
142
+ value={link_src}
209
143
  className="form-control form-select"
210
- onChange={setAProp("url")}
144
+ onChange={(e) => {
145
+ if (!e.target) return;
146
+ const value = e.target.value;
147
+ setProp((prop) => {
148
+ prop.link_src = value;
149
+ if (value !== "URL" && prop.isFormula) {
150
+ prop.isFormula.url = false;
151
+ }
152
+ });
153
+ }}
211
154
  >
212
- <option></option>
213
- {(options.views || []).map((p, ix) => (
214
- <option key={ix} value={`/view/${p.name}`}>
215
- {p.name} [{p.viewtemplate}]
216
- </option>
217
- ))}
155
+ <option>URL</option>
156
+ {(options.pages || []).length > 0 && <option>Page</option>}
157
+ {(options.views || []).length > 0 &&
158
+ ["page", "filter"].includes(options.mode) && (
159
+ <option>View</option>
160
+ )}
218
161
  </select>
219
162
  </td>
220
163
  </tr>
221
- )}
222
- <ButtonOrLinkSettingsRows
223
- setProp={setProp}
224
- keyPrefix="link_"
225
- btnClass="btn"
226
- values={node}
227
- linkFirst={true}
228
- />
229
- </tbody>
230
- </table>
231
-
232
- <div className="form-check">
233
- <input
234
- className="form-check-input"
235
- name="block"
236
- type="checkbox"
237
- checked={nofollow}
238
- onChange={setAProp("nofollow", { checked: true })}
239
- />
240
- <label className="form-check-label">Nofollow</label>
241
- </div>
242
- <div className="form-check">
243
- <input
244
- className="form-check-input"
245
- name="block"
246
- type="checkbox"
247
- checked={target_blank}
248
- onChange={setAProp("target_blank", { checked: true })}
249
- />
250
- <label className="form-check-label">Open in new tab</label>
251
- </div>
252
- <div className="form-check">
253
- <input
254
- className="form-check-input"
255
- name="block"
256
- type="checkbox"
257
- checked={in_modal}
258
- onChange={setAProp("in_modal", { checked: true })}
259
- />
260
- <label className="form-check-label">Open in popup modal?</label>
261
- </div>
164
+ {link_src === "URL" && (
165
+ <tr>
166
+ <td>
167
+ <label>URL</label>
168
+ </td>
169
+ <td>
170
+ <OrFormula nodekey="url" {...{ setProp, isFormula, node }}>
171
+ <input
172
+ type="text"
173
+ className="form-control "
174
+ value={url}
175
+ onChange={setAProp("url")}
176
+ />
177
+ </OrFormula>
178
+ </td>
179
+ </tr>
180
+ )}
181
+ {link_src === "Page" && (
182
+ <tr>
183
+ <td>
184
+ <label>Page</label>
185
+ </td>
186
+ <td>
187
+ <select
188
+ value={url}
189
+ className="form-control form-select"
190
+ onChange={setAProp("url")}
191
+ >
192
+ <option></option>
193
+ {(options.pages || []).map((p, ix) => (
194
+ <option key={ix} value={`/page/${p.name}`}>
195
+ {p.name}
196
+ </option>
197
+ ))}
198
+ </select>
199
+ </td>
200
+ </tr>
201
+ )}
202
+ {link_src === "View" && (
203
+ <tr>
204
+ <td>
205
+ <label>View</label>
206
+ </td>
207
+ <td>
208
+ <select
209
+ value={url}
210
+ className="form-control form-select"
211
+ onChange={setAProp("url")}
212
+ >
213
+ <option></option>
214
+ {(options.views || []).map((p, ix) => (
215
+ <option key={ix} value={`/view/${p.name}`}>
216
+ {p.name} [{p.viewtemplate}]
217
+ </option>
218
+ ))}
219
+ </select>
220
+ </td>
221
+ </tr>
222
+ )}
223
+ {link_src === "View" && (
224
+ <tr>
225
+ <td>
226
+ <label>State Formula</label>
227
+ </td>
228
+ <td>
229
+ <input
230
+ type="text"
231
+ className="form-control"
232
+ value={view_state_fml}
233
+ onChange={setAProp("view_state_fml")}
234
+ />
235
+ </td>
236
+ </tr>
237
+ )}
238
+ <ButtonOrLinkSettingsRows
239
+ setProp={setProp}
240
+ keyPrefix="link_"
241
+ btnClass="btn"
242
+ values={node}
243
+ linkFirst={true}
244
+ />
245
+ </tbody>
246
+ </table>
262
247
 
263
- {["filter", "page"].includes(options.mode) && (
264
248
  <div className="form-check">
265
249
  <input
266
250
  className="form-check-input"
267
251
  name="block"
268
252
  type="checkbox"
269
- checked={transfer_state}
270
- onChange={setAProp("transfer_state", { checked: true })}
253
+ checked={nofollow}
254
+ onChange={setAProp("nofollow", { checked: true })}
271
255
  />
272
- <label className="form-check-label">Transfer state</label>
256
+ <label className="form-check-label">Nofollow</label>
257
+ </div>
258
+ <div className="form-check">
259
+ <input
260
+ className="form-check-input"
261
+ name="block"
262
+ type="checkbox"
263
+ checked={target_blank}
264
+ onChange={setAProp("target_blank", { checked: true })}
265
+ />
266
+ <label className="form-check-label">Open in new tab</label>
267
+ </div>
268
+ <div className="form-check">
269
+ <input
270
+ className="form-check-input"
271
+ name="block"
272
+ type="checkbox"
273
+ checked={in_modal}
274
+ onChange={setAProp("in_modal", { checked: true })}
275
+ />
276
+ <label className="form-check-label">Open in popup modal?</label>
273
277
  </div>
274
- )}
275
278
 
276
- <BlockSetting block={block} setProp={setProp} />
277
- <TextStyleSetting textStyle={textStyle} setProp={setProp} />
278
- </div>
279
- );
280
- };
279
+ {["filter", "page"].includes(options.mode) && (
280
+ <div className="form-check">
281
+ <input
282
+ className="form-check-input"
283
+ name="block"
284
+ type="checkbox"
285
+ checked={transfer_state}
286
+ onChange={setAProp("transfer_state", { checked: true })}
287
+ />
288
+ <label className="form-check-label">Transfer state</label>
289
+ </div>
290
+ )}
291
+
292
+ <BlockSetting block={block} setProp={setProp} />
293
+ <TextStyleSetting textStyle={textStyle} setProp={setProp} />
294
+ </div>
295
+ );
296
+ };
281
297
 
282
298
  /**
283
299
  * @type {object}
@@ -313,6 +329,8 @@ Link.craft = {
313
329
  "link_textcol",
314
330
  "in_modal",
315
331
  "transfer_state",
332
+ "view_state_fml"
333
+
316
334
  ],
317
335
  },
318
336
  };