@saltcorn/builder 0.5.6-rc.0 → 0.6.0-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.
@@ -10,6 +10,8 @@ import {
10
10
  SelectUnits,
11
11
  SettingsSectionHeaderRow,
12
12
  SettingsRow,
13
+ reactifyStyles,
14
+ bstyleopt,
13
15
  } from "./utils";
14
16
  import {
15
17
  BorderOuter,
@@ -34,6 +36,7 @@ import {
34
36
  } from "react-bootstrap-icons";
35
37
  import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
36
38
  import { faScroll, faRobot } from "@fortawesome/free-solid-svg-icons";
39
+ import { BoxModelEditor } from "./BoxModelEditor";
37
40
 
38
41
  function capitalizeFirstLetter(string) {
39
42
  return string.charAt(0).toUpperCase() + string.slice(1);
@@ -41,8 +44,6 @@ function capitalizeFirstLetter(string) {
41
44
 
42
45
  export const Container = ({
43
46
  children,
44
- borderWidth,
45
- borderStyle,
46
47
  minHeight,
47
48
  height,
48
49
  width,
@@ -54,7 +55,7 @@ export const Container = ({
54
55
  bgFileId,
55
56
  imageSize,
56
57
  bgType,
57
- block,
58
+ display,
58
59
  bgColor,
59
60
  setTextColor,
60
61
  textColor,
@@ -63,36 +64,32 @@ export const Container = ({
63
64
  margin,
64
65
  padding,
65
66
  minScreenWidth,
66
- borderRadius,
67
- borderRadiusUnit,
68
- borderDirection,
69
- borderColor,
70
67
  gradStartColor,
71
68
  gradEndColor,
72
69
  gradDirection,
73
70
  rotate,
71
+ style,
74
72
  }) => {
75
73
  const {
76
74
  selected,
77
75
  connectors: { connect, drag },
78
76
  } = useNode((node) => ({ selected: node.events.selected }));
77
+ //console.log("container style", style);
79
78
  return (
80
79
  <div
81
80
  ref={(dom) => connect(drag(dom))}
82
- className={`${customClass || ""} text-${hAlign} ${
81
+ className={`${customClass || ""} canvas text-${hAlign} ${
83
82
  vAlign === "middle" ? "d-flex align-items-center" : ""
84
83
  } ${
85
84
  vAlign === "middle" && hAlign === "center" && "justify-content-center"
86
85
  } ${selected ? "selected-node" : ""}`}
87
86
  style={{
88
87
  ...parseStyles(customCSS || ""),
89
- padding: padding.map((p) => p + "px").join(" "),
90
- margin: margin.map((p) => p + "px").join(" "),
88
+ ...reactifyStyles(style),
89
+ display,
90
+ //padding: padding.map((p) => p + "px").join(" "),
91
+ //margin: margin.map((p) => p + "px").join(" "),
91
92
  minHeight: `${Math.max(minHeight, 15)}${minHeightUnit || "px"}`,
92
- [`border${
93
- borderDirection ? `${capitalizeFirstLetter(borderDirection)}` : ""
94
- }`]: `${borderWidth}px ${borderStyle} ${borderColor || "black"}`,
95
- ...(block === false ? { display: "inline-block" } : {}),
96
93
  ...(bgType === "Image" && bgFileId && +bgFileId
97
94
  ? {
98
95
  backgroundImage: `url('/files/serve/${bgFileId}')`,
@@ -122,11 +119,6 @@ export const Container = ({
122
119
  height: `${height}${heightUnit || "px"}`,
123
120
  }
124
121
  : {}),
125
- ...(typeof borderRadius !== "undefined"
126
- ? {
127
- borderRadius: `${borderRadius}${borderRadiusUnit || "px"}`,
128
- }
129
- : {}),
130
122
  ...(typeof width !== "undefined"
131
123
  ? {
132
124
  width: `${width}${widthUnit || "px"}`,
@@ -139,19 +131,13 @@ export const Container = ({
139
131
  : {}),
140
132
  }}
141
133
  >
142
- <div className="canvas">{children}</div>
134
+ {children}
143
135
  </div>
144
136
  );
145
137
  };
146
138
 
147
139
  export const ContainerSettings = () => {
148
140
  const node = useNode((node) => ({
149
- borderWidth: node.data.props.borderWidth,
150
- borderStyle: node.data.props.borderStyle,
151
- borderRadius: node.data.props.borderRadius,
152
- borderRadiusUnit: node.data.props.borderRadiusUnit,
153
- borderDirection: node.data.props.borderDirection,
154
- borderColor: node.data.props.borderColor,
155
141
  minHeight: node.data.props.minHeight,
156
142
  height: node.data.props.height,
157
143
  width: node.data.props.width,
@@ -165,7 +151,6 @@ export const ContainerSettings = () => {
165
151
  imageSize: node.data.props.imageSize,
166
152
  vAlign: node.data.props.vAlign,
167
153
  hAlign: node.data.props.hAlign,
168
- block: node.data.props.block,
169
154
  fullPageWidth: node.data.props.fullPageWidth,
170
155
  showIfFormula: node.data.props.showIfFormula,
171
156
  setTextColor: node.data.props.setTextColor,
@@ -185,15 +170,15 @@ export const ContainerSettings = () => {
185
170
  gradDirection: node.data.props.gradDirection,
186
171
  overflow: node.data.props.overflow,
187
172
  rotate: node.data.props.rotate,
173
+ display: node.data.props.display,
174
+ style: node.data.props.style,
188
175
  }));
189
176
  const {
190
177
  actions: { setProp },
191
- borderWidth,
192
- borderColor,
193
178
  bgFileId,
194
179
  imageSize,
195
180
  bgType,
196
- block,
181
+ display,
197
182
  bgColor,
198
183
  setTextColor,
199
184
  textColor,
@@ -217,20 +202,7 @@ export const ContainerSettings = () => {
217
202
  } = node;
218
203
  const options = useContext(optionsCtx);
219
204
  const ownership = !!options.ownership;
220
- const bstyleopt = (style) => ({
221
- value: style,
222
- title: style,
223
- label: (
224
- <div
225
- style={{
226
- borderLeftStyle: style,
227
- borderTopStyle: style,
228
- height: "15px",
229
- width: "6px",
230
- }}
231
- ></div>
232
- ),
233
- });
205
+
234
206
  const setAProp = (key) => (e) => {
235
207
  if (e.target) {
236
208
  const target_value = e.target.value;
@@ -239,108 +211,58 @@ export const ContainerSettings = () => {
239
211
  };
240
212
  return (
241
213
  <Accordion>
242
- <table className="w-100" accordiontitle="Placement">
214
+ <div accordiontitle="Box" className="w-100">
215
+ <BoxModelEditor setProp={setProp} node={node} />
216
+ <table className="w-100">
217
+ <tbody>
218
+ <tr>
219
+ <td colSpan="2"></td>
220
+ </tr>
221
+ </tbody>
222
+ </table>
223
+ </div>
224
+ <table className="w-100" accordiontitle="Display">
243
225
  <tbody>
244
- <SettingsSectionHeaderRow title="Border" />
245
- <tr>
246
- <td>
247
- <label>Width</label>
248
- </td>
249
- <td>
250
- <div className="input-group input-group-sm w-100">
251
- <input
252
- type="number"
253
- value={borderWidth}
254
- step="1"
255
- className="form-control w-50"
256
- min="0"
257
- max="20"
258
- onChange={setAProp("borderWidth")}
259
- />
260
- <div className="input-group-append w-50 d-inline">
261
- <span className="input-group-text">px</span>
262
- </div>
263
- </div>
264
- </td>
265
- </tr>
266
226
  <SettingsRow
267
227
  field={{
268
- name: "borderStyle",
269
- label: "Style",
270
- type: "btn_select",
271
- btnClass: "btnstylesel",
228
+ name: "display",
229
+ label: "Display",
230
+ type: "select",
272
231
  options: [
273
- "solid",
274
- "dotted",
275
- "dashed",
276
- "double",
277
- "groove",
278
- "ridge",
279
- "inset",
280
- "outset",
281
- ].map(bstyleopt),
232
+ "block",
233
+ "inline",
234
+ "inline-block",
235
+ "none",
236
+ "flex",
237
+ "inline-flex",
238
+ ],
282
239
  }}
283
240
  node={node}
284
241
  setProp={setProp}
285
242
  />
286
243
  <SettingsRow
287
244
  field={{
288
- name: "borderDirection",
289
- label: "Direction",
245
+ name: "overflow",
246
+ label: "Overflow",
290
247
  type: "btn_select",
291
- btnClass: "btnstylesel",
292
248
  options: [
293
- { value: "", title: "None", label: <BorderAll /> },
294
- { value: "top", title: "Top", label: <BorderTop /> },
295
- { value: "bottom", title: "Bottom", label: <BorderBottom /> },
296
- { value: "left", title: "Left", label: <BorderLeft /> },
297
- { value: "right", title: "Right", label: <BorderRight /> },
249
+ { value: "visible", title: "Visible", label: <EyeFill /> },
250
+ { value: "hidden", title: "Hidden", label: <EyeSlashFill /> },
251
+ {
252
+ value: "scroll",
253
+ title: "Scroll",
254
+ label: <FontAwesomeIcon icon={faScroll} />,
255
+ },
256
+ {
257
+ value: "auto",
258
+ title: "Auto",
259
+ label: <FontAwesomeIcon icon={faRobot} />,
260
+ },
298
261
  ],
299
262
  }}
300
263
  node={node}
301
264
  setProp={setProp}
302
265
  />
303
-
304
- <tr>
305
- <td>
306
- <label>Color</label>
307
- </td>
308
- <td>
309
- <input
310
- type="color"
311
- value={borderColor}
312
- className="form-control-sm w-50 mr-2"
313
- onChange={setAProp("borderColor")}
314
- />
315
- <small>{borderColor}</small>
316
- </td>
317
- </tr>
318
- <SettingsRow
319
- field={{ name: "borderRadius", label: "Radius", type: "DimUnits" }}
320
- node={node}
321
- setProp={setProp}
322
- />
323
- <SettingsSectionHeaderRow title="Size" />
324
- <SettingsRow
325
- field={{ name: "minHeight", label: "Min height", type: "DimUnits" }}
326
- node={node}
327
- setProp={setProp}
328
- />
329
- <SettingsRow
330
- field={{ name: "height", label: "Height", type: "DimUnits" }}
331
- node={node}
332
- setProp={setProp}
333
- />
334
- <SettingsRow
335
- field={{ name: "width", label: "Widths", type: "DimUnits" }}
336
- node={node}
337
- setProp={setProp}
338
- />
339
- <tr>
340
- <td colSpan="2">
341
- <BlockSetting block={block} setProp={setProp} />
342
- </td>
343
- </tr>
344
266
  <tr>
345
267
  <td colSpan="2">
346
268
  <div className="form-check">
@@ -361,47 +283,6 @@ export const ContainerSettings = () => {
361
283
  </tr>
362
284
  </tbody>
363
285
  </table>
364
- <table className="w-100" accordiontitle="Spacing">
365
- <tbody>
366
- <tr>
367
- <th></th>
368
- <th>Margin</th>
369
- <th>Padding</th>
370
- </tr>
371
- {["Top", "Right", "Bottom", "Left"].map((direction, ix) => (
372
- <tr key={ix}>
373
- <td>{direction}</td>
374
- <td>
375
- <input
376
- type="number"
377
- value={margin[ix]}
378
- step="1"
379
- className="form-control-sm w-100"
380
- onChange={(e) =>
381
- setProp((prop) => {
382
- prop.margin[ix] = e.target.value;
383
- })
384
- }
385
- />
386
- </td>
387
- <td>
388
- <input
389
- type="number"
390
- value={padding[ix]}
391
- step="1"
392
- className="form-control-sm w-100"
393
- onChange={(e) =>
394
- setProp((prop) => {
395
- prop.padding[ix] = e.target.value;
396
- })
397
- }
398
- />
399
- </td>
400
- <td>px</td>
401
- </tr>
402
- ))}
403
- </tbody>
404
- </table>
405
286
  <table className="w-100" accordiontitle="Contents">
406
287
  <tbody>
407
288
  <SettingsRow
@@ -443,29 +324,6 @@ export const ContainerSettings = () => {
443
324
  node={node}
444
325
  setProp={setProp}
445
326
  />
446
- <SettingsRow
447
- field={{
448
- name: "overflow",
449
- label: "Overflow",
450
- type: "btn_select",
451
- options: [
452
- { value: "visible", title: "Visible", label: <EyeFill /> },
453
- { value: "hidden", title: "Hidden", label: <EyeSlashFill /> },
454
- {
455
- value: "scroll",
456
- title: "Scroll",
457
- label: <FontAwesomeIcon icon={faScroll} />,
458
- },
459
- {
460
- value: "auto",
461
- title: "Auto",
462
- label: <FontAwesomeIcon icon={faRobot} />,
463
- },
464
- ],
465
- }}
466
- node={node}
467
- setProp={setProp}
468
- />
469
327
  <SettingsSectionHeaderRow title="Background" />
470
328
  <SettingsRow
471
329
  field={{
@@ -628,6 +486,117 @@ export const ContainerSettings = () => {
628
486
  )}
629
487
  </tbody>
630
488
  </table>
489
+ <table className="w-100" accordiontitle="Flex properties">
490
+ <tbody>
491
+ <SettingsSectionHeaderRow title="Flex item" />
492
+ <SettingsRow
493
+ field={{ name: "flex-grow", label: "Grow", type: "Float" }}
494
+ node={node}
495
+ setProp={setProp}
496
+ />
497
+ <SettingsRow
498
+ field={{ name: "flex-shrink", label: "Shrink", type: "Float" }}
499
+ node={node}
500
+ setProp={setProp}
501
+ />
502
+ {display && display.includes("flex") && (
503
+ <Fragment>
504
+ <SettingsSectionHeaderRow title="Flex container" />
505
+ <SettingsRow
506
+ field={{
507
+ name: "flex-direction",
508
+ label: "Direction",
509
+ type: "select",
510
+ options: ["row", "row-reverse", "column", "column-reverse"],
511
+ }}
512
+ node={node}
513
+ setProp={setProp}
514
+ isStyle={true}
515
+ />
516
+ <SettingsRow
517
+ field={{
518
+ name: "flex-wrap",
519
+ label: "Wrap",
520
+ type: "select",
521
+ options: ["nowrap", "wrap", "wrap-reverse"],
522
+ }}
523
+ node={node}
524
+ setProp={setProp}
525
+ isStyle={true}
526
+ />
527
+ <SettingsRow
528
+ field={{
529
+ name: "justify-content",
530
+ label: "Justify content",
531
+ type: "select",
532
+ options: [
533
+ "flex-start",
534
+ "flex-end",
535
+ "center",
536
+ "space-between",
537
+ "space-around",
538
+ "space-evenly",
539
+ "start",
540
+ "end",
541
+ "left",
542
+ "right",
543
+ ],
544
+ }}
545
+ node={node}
546
+ setProp={setProp}
547
+ isStyle={true}
548
+ />
549
+ <SettingsRow
550
+ field={{
551
+ name: "align-items",
552
+ label: "Align items",
553
+ type: "select",
554
+ options: [
555
+ "stretch",
556
+ "flex-start",
557
+ "flex-end",
558
+ "center",
559
+ "baseline",
560
+ "first baseline",
561
+ "last baseline",
562
+ "start",
563
+ "end",
564
+ "self-start",
565
+ "self-end",
566
+ ],
567
+ }}
568
+ node={node}
569
+ setProp={setProp}
570
+ isStyle={true}
571
+ />
572
+ <SettingsRow
573
+ field={{
574
+ name: "align-content",
575
+ label: "Align content",
576
+ type: "select",
577
+ options: [
578
+ "flex-start",
579
+ "flex-end",
580
+ "center",
581
+ "space-between",
582
+ "space-around",
583
+ "space-evenly",
584
+ "stretch",
585
+ "start",
586
+ "end",
587
+ "baseline",
588
+ "first baseline",
589
+ "last baseline",
590
+ ],
591
+ }}
592
+ node={node}
593
+ setProp={setProp}
594
+ isStyle={true}
595
+ />
596
+ </Fragment>
597
+ )}
598
+ </tbody>
599
+ </table>
631
600
  <table className="w-100" accordiontitle="Show if...">
632
601
  <tbody>
633
602
  {["show", "edit"].includes(options.mode) && (
@@ -784,8 +753,6 @@ export const ContainerSettings = () => {
784
753
  Container.craft = {
785
754
  displayName: "Container",
786
755
  props: {
787
- borderWidth: 0,
788
- borderStyle: "solid",
789
756
  minHeight: 0,
790
757
  vAlign: "top",
791
758
  hAlign: "left",
@@ -793,7 +760,6 @@ Container.craft = {
793
760
  rotate: 0,
794
761
  isFormula: {},
795
762
  bgType: "None",
796
- block: true,
797
763
  fullPageWidth: false,
798
764
  bgColor: "#ffffff",
799
765
  borderColor: "#000000",
@@ -808,7 +774,9 @@ Container.craft = {
808
774
  margin: [0, 0, 0, 0],
809
775
  padding: [0, 0, 0, 0],
810
776
  minScreenWidth: "",
777
+ display: "block",
811
778
  show_for_owner: false,
779
+ style: {},
812
780
  },
813
781
  rules: {
814
782
  canDrag: () => true,