@saltcorn/builder 0.6.0-alpha.0 → 0.6.0-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/builder",
3
- "version": "0.6.0-alpha.0",
3
+ "version": "0.6.0-beta.0",
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",
@@ -56,6 +56,7 @@ const SettingsPanel = () => {
56
56
  selected = {
57
57
  id: currentNodeId,
58
58
  name: state.nodes[currentNodeId].data.name,
59
+ parent: state.nodes[currentNodeId].data.parent,
59
60
  displayName:
60
61
  state.nodes[currentNodeId].data &&
61
62
  state.nodes[currentNodeId].data.displayName,
@@ -77,13 +78,54 @@ const SettingsPanel = () => {
77
78
  const deleteThis = () => {
78
79
  actions.delete(selected.id);
79
80
  };
80
- const handleUserKeyPress = ({ keyCode, target }) => {
81
- if (
82
- (keyCode === 8 || keyCode === 46) &&
83
- target.tagName.toLowerCase() === "body" &&
84
- selected
85
- ) {
86
- deleteThis();
81
+ const otherSibling = (offset) => {
82
+ const siblings = query.node(selected.parent).childNodes();
83
+ const sibIx = siblings.findIndex((sib) => sib === selected.id);
84
+ return siblings[sibIx + offset];
85
+ };
86
+ const handleUserKeyPress = (event) => {
87
+ const { keyCode, target } = event;
88
+ if (target.tagName.toLowerCase() === "body" && selected) {
89
+ //8 backsp, 46 del
90
+ if ((keyCode === 8 || keyCode === 46) && selected.id === "ROOT") {
91
+ deleteChildren();
92
+ }
93
+ if (keyCode === 8) {
94
+ //backspace
95
+ const prevSib = otherSibling(-1);
96
+ const parent = selected.parent;
97
+ deleteThis();
98
+ if (prevSib) actions.selectNode(prevSib);
99
+ else actions.selectNode(parent);
100
+ }
101
+ if (keyCode === 46) {
102
+ //del
103
+ const nextSib = otherSibling(1);
104
+ deleteThis();
105
+ if (nextSib) actions.selectNode(nextSib);
106
+ }
107
+ if (keyCode === 37 && selected.parent)
108
+ //left
109
+ actions.selectNode(selected.parent);
110
+
111
+ if (keyCode === 39) {
112
+ //right
113
+ if (selected.children && selected.children.length > 0) {
114
+ actions.selectNode(selected.children[0]);
115
+ }
116
+ }
117
+ if (keyCode === 38 && selected.parent) {
118
+ //up
119
+ const prevSib = otherSibling(-1);
120
+ if (prevSib) actions.selectNode(prevSib);
121
+ event.preventDefault();
122
+ }
123
+ if (keyCode === 40 && selected.parent) {
124
+ //down
125
+ const nextSib = otherSibling(1);
126
+ if (nextSib) actions.selectNode(nextSib);
127
+ event.preventDefault();
128
+ }
87
129
  }
88
130
  };
89
131
  useEffect(() => {
@@ -275,7 +317,7 @@ const Builder = ({ options, layout, mode }) => {
275
317
  <div className="componets-and-library-accordion toolbox-card">
276
318
  <InitNewElement nodekeys={nodekeys} />
277
319
  <Accordion>
278
- <div className="card " accordiontitle="Components">
320
+ <div className="card mt-1" accordiontitle="Components">
279
321
  {{
280
322
  show: <ToolboxShow />,
281
323
  edit: <ToolboxEdit />,
@@ -0,0 +1,374 @@
1
+ import React, { useContext, Fragment, useState } from "react";
2
+ import { SettingsRow, SettingsSectionHeaderRow, bstyleopt } from "./utils";
3
+ /*
4
+ Contains code from https://github.com/tpaksu/boxmodel
5
+ Copyright (c) 2017 Taha Paksu
6
+ */
7
+ export const BoxModelEditor = ({ setProp, node }) => {
8
+ const [selectedCategory, setSelectedCategory] = useState(false);
9
+ const [selectedDirection, setSelectedDirection] = useState(false);
10
+ const selectedProperty = !selectedCategory
11
+ ? false
12
+ : selectedDirection
13
+ ? `${selectedCategory}-${selectedDirection}`
14
+ : selectedCategory;
15
+ const setCatAndDir = (c, d) => {
16
+ setSelectedCategory(c);
17
+ setSelectedDirection(d);
18
+ };
19
+ //console.log(node.style);
20
+ const style = node.style;
21
+ return (
22
+ <Fragment>
23
+ <div className="w-100 text-center">
24
+ <div className="boxmodel-container boxmodel-chrome-skin mt-2 mx-auto text-center">
25
+ <div className="boxmodel-container">
26
+ <div className="boxmodel-margin">
27
+ <span
28
+ className="boxmodel-text boxmodel-header"
29
+ onClick={() => setCatAndDir("margin", null)}
30
+ >
31
+ Margin
32
+ </span>
33
+ <span
34
+ className="boxmodel-input-container boxmodel-input-direction-left"
35
+ onClick={() => setCatAndDir("margin", "left")}
36
+ >
37
+ <div className="rotate dim-display">
38
+ {style["margin-left"] || style["margin"] || ""}
39
+ </div>
40
+ </span>
41
+ <div className="flex-row">
42
+ <span
43
+ className="boxmodel-input-container boxmodel-input-direction-top"
44
+ onClick={() => setCatAndDir("margin", "top")}
45
+ >
46
+ <input
47
+ disabled
48
+ type="text"
49
+ autoComplete="off"
50
+ name="boxmodel-ex-1_top_margin"
51
+ size="3"
52
+ value={style["margin-top"] || style["margin"] || ""}
53
+ />
54
+ </span>
55
+ <div className="boxmodel-border">
56
+ <span
57
+ className="boxmodel-text boxmodel-header"
58
+ onClick={() => setCatAndDir("border", null)}
59
+ >
60
+ Border
61
+ </span>
62
+ <span
63
+ className="boxmodel-input-container boxmodel-input-direction-left"
64
+ onClick={() => setCatAndDir("border", "left")}
65
+ >
66
+ <div className="rotate dim-display">
67
+ {style["border-left-width"] ||
68
+ style["border-width"] ||
69
+ ""}
70
+ </div>
71
+ </span>
72
+ <div className="flex-row">
73
+ <span
74
+ className="boxmodel-input-container boxmodel-input-direction-top"
75
+ onClick={() => setCatAndDir("border", "top")}
76
+ >
77
+ <input
78
+ disabled
79
+ type="text"
80
+ autoComplete="off"
81
+ name="boxmodel-ex-1_top_border"
82
+ value={
83
+ style["border-top-width"] ||
84
+ style["border-width"] ||
85
+ ""
86
+ }
87
+ size="3"
88
+ />
89
+ </span>
90
+ <div className="boxmodel-padding">
91
+ <span
92
+ className="boxmodel-text boxmodel-header"
93
+ onClick={() => setCatAndDir("padding", null)}
94
+ >
95
+ Padding
96
+ </span>
97
+ <span
98
+ className="boxmodel-input-container boxmodel-input-direction-left"
99
+ onClick={() => setCatAndDir("padding", "left")}
100
+ >
101
+ <div className="rotate dim-display-padding">
102
+ {style["padding-left"] || style["padding"] || ""}
103
+ </div>
104
+ </span>
105
+ <div className="flex-row">
106
+ <span
107
+ className="boxmodel-input-container boxmodel-input-direction-top"
108
+ onClick={() => setCatAndDir("padding", "top")}
109
+ >
110
+ <input
111
+ disabled
112
+ type="text"
113
+ autoComplete="off"
114
+ name="boxmodel-ex-1_top_padding"
115
+ value={
116
+ style["padding-top"] || style["padding"] || ""
117
+ }
118
+ size="3"
119
+ />
120
+ </span>
121
+ <div
122
+ className="boxmodel-content"
123
+ onClick={() => setSelectedCategory("size")}
124
+ >
125
+ <input
126
+ disabled
127
+ type="text"
128
+ autoComplete="off"
129
+ name="boxmodel-ex-1_width"
130
+ size="3"
131
+ value={
132
+ node.width
133
+ ? `${node.width}${node.widthUnits || "px"}`
134
+ : ""
135
+ }
136
+ />
137
+ x
138
+ <input
139
+ disabled
140
+ type="text"
141
+ autoComplete="off"
142
+ name="boxmodel-ex-1_height"
143
+ size="3"
144
+ value={
145
+ node.height
146
+ ? `${node.height}${node.heightUnits || "px"}`
147
+ : ""
148
+ }
149
+ />
150
+ </div>
151
+ <span
152
+ className="boxmodel-input-container boxmodel-input-direction-bottom"
153
+ onClick={() => setCatAndDir("padding", "bottom")}
154
+ >
155
+ <input
156
+ disabled
157
+ type="text"
158
+ autoComplete="off"
159
+ name="boxmodel-ex-1_bottom_padding"
160
+ size="3"
161
+ value={
162
+ style["padding-bottom"] || style["padding"] || ""
163
+ }
164
+ />
165
+ </span>
166
+ </div>
167
+ <span
168
+ className="boxmodel-input-container boxmodel-input-direction-right"
169
+ onClick={() => setCatAndDir("padding", "right")}
170
+ >
171
+ <div className="rotate dim-display-padding">
172
+ {style["padding-right"] || style["padding"] || ""}
173
+ </div>
174
+ </span>
175
+ </div>
176
+ <span
177
+ className="boxmodel-input-container boxmodel-input-direction-bottom"
178
+ onClick={() => setCatAndDir("border", "bottom")}
179
+ >
180
+ <input
181
+ disabled
182
+ type="text"
183
+ autoComplete="off"
184
+ name="boxmodel-ex-1_bottom_border"
185
+ size="3"
186
+ value={
187
+ style["border-bottom-width"] ||
188
+ style["border-width"] ||
189
+ ""
190
+ }
191
+ />
192
+ </span>
193
+ </div>
194
+ <span
195
+ className="boxmodel-input-container boxmodel-input-direction-right"
196
+ onClick={() => setCatAndDir("border", "right")}
197
+ >
198
+ <div className="rotate dim-display">
199
+ {style["border-right-width"] ||
200
+ style["border-width"] ||
201
+ ""}
202
+ </div>
203
+ </span>
204
+ </div>
205
+ <span
206
+ className="boxmodel-input-container boxmodel-input-direction-bottom"
207
+ onClick={() => setCatAndDir("margin", "bottom")}
208
+ >
209
+ <input
210
+ disabled
211
+ type="text"
212
+ autoComplete="off"
213
+ name="boxmodel-ex-1_bottom_margin"
214
+ size="3"
215
+ value={style["margin-bottom"] || style["margin"] || ""}
216
+ />
217
+ </span>
218
+ </div>
219
+ <span
220
+ className="boxmodel-input-container boxmodel-input-direction-right"
221
+ onClick={() => setCatAndDir("margin", "right")}
222
+ >
223
+ <div className="rotate dim-display">
224
+ {style["margin-right"] || style["margin"] || ""}
225
+ </div>
226
+ </span>
227
+ </div>
228
+ </div>
229
+ </div>
230
+ </div>
231
+ <table className="w-100 mt-2">
232
+ <tbody>
233
+ <tr>
234
+ <td width="45%"></td>
235
+ <td></td>
236
+ </tr>
237
+ {selectedProperty &&
238
+ ["margin", "padding"].includes(selectedCategory) && (
239
+ <SettingsRow
240
+ field={{
241
+ name: selectedProperty,
242
+ label: selectedProperty,
243
+ type: "DimUnits",
244
+ autoable: selectedCategory === "margin",
245
+ }}
246
+ node={node}
247
+ setProp={setProp}
248
+ isStyle={true}
249
+ />
250
+ )}
251
+ {selectedCategory === "size" && (
252
+ <Fragment>
253
+ <SettingsRow
254
+ field={{ name: "width", label: "width", type: "DimUnits" }}
255
+ node={node}
256
+ setProp={setProp}
257
+ />
258
+ <SettingsRow
259
+ field={{ name: "height", label: "height", type: "DimUnits" }}
260
+ node={node}
261
+ setProp={setProp}
262
+ />
263
+ <SettingsRow
264
+ field={{
265
+ name: "minHeight",
266
+ label: "min height",
267
+ type: "DimUnits",
268
+ }}
269
+ node={node}
270
+ setProp={setProp}
271
+ />
272
+ </Fragment>
273
+ )}
274
+ {selectedCategory === "border" && (
275
+ <Fragment>
276
+ <SettingsSectionHeaderRow title={selectedProperty} />
277
+ <SettingsRow
278
+ field={{
279
+ name: selectedProperty + "-width",
280
+ label: "width",
281
+ type: "DimUnits",
282
+ }}
283
+ node={node}
284
+ setProp={setProp}
285
+ isStyle={true}
286
+ />
287
+ <SettingsRow
288
+ field={{
289
+ name: selectedProperty + "-style",
290
+ label: "style",
291
+ type: "btn_select",
292
+ btnClass: "btnstylesel",
293
+ options: [
294
+ "solid",
295
+ "dotted",
296
+ "dashed",
297
+ "double",
298
+ "groove",
299
+ "ridge",
300
+ "inset",
301
+ "outset",
302
+ ].map(bstyleopt),
303
+ }}
304
+ node={node}
305
+ isStyle={true}
306
+ setProp={setProp}
307
+ />
308
+ <SettingsRow
309
+ field={{
310
+ name: selectedProperty + "-color",
311
+ label: "color",
312
+ type: "Color",
313
+ }}
314
+ node={node}
315
+ isStyle={true}
316
+ setProp={setProp}
317
+ />
318
+ {!selectedDirection && (
319
+ <SettingsRow
320
+ field={{
321
+ name: selectedProperty + "-radius",
322
+ label: "radius",
323
+ type: "DimUnits",
324
+ }}
325
+ node={node}
326
+ setProp={setProp}
327
+ isStyle={true}
328
+ />
329
+ )}
330
+ {selectedDirection &&
331
+ radiusCornerDirections[selectedDirection].map((corner, ix) => (
332
+ <SettingsRow
333
+ key={ix}
334
+ field={{
335
+ name: `border-${corner}-radius`,
336
+ label: corner.replace("-", " ") + " radius",
337
+ type: "DimUnits",
338
+ }}
339
+ node={node}
340
+ setProp={setProp}
341
+ isStyle={true}
342
+ />
343
+ ))}
344
+ </Fragment>
345
+ )}
346
+ {!selectedProperty && (
347
+ <tr>
348
+ <td colSpan={2}>
349
+ <div>Click above to select a property to adjust.</div>
350
+ <div>
351
+ <small>
352
+ Click a label (margin, border, padding) to adjust all edges.
353
+ </small>
354
+ </div>
355
+ <div>
356
+ <small>Click an edge to adjust that edge.</small>
357
+ </div>
358
+ <div>
359
+ <small>Click center to adjust height and width</small>
360
+ </div>
361
+ </td>
362
+ </tr>
363
+ )}
364
+ </tbody>
365
+ </table>
366
+ </Fragment>
367
+ );
368
+ };
369
+ const radiusCornerDirections = {
370
+ left: ["bottom-left", "top-left"],
371
+ right: ["bottom-right", "top-right"],
372
+ top: ["top-left", "top-right"],
373
+ bottom: ["bottom-left", "bottom-right"],
374
+ };