@saltcorn/builder 0.6.1-beta.0 → 0.6.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.
Files changed (33) hide show
  1. package/dist/builder_bundle.js +9 -9
  2. package/package.json +1 -1
  3. package/src/components/Builder.js +77 -0
  4. package/src/components/Library.js +43 -3
  5. package/src/components/RenderNode.js +17 -1
  6. package/src/components/Toolbox.js +207 -5
  7. package/src/components/context.js +6 -0
  8. package/src/components/elements/Action.js +38 -2
  9. package/src/components/elements/Aggregation.js +29 -2
  10. package/src/components/elements/BoxModelEditor.js +18 -1
  11. package/src/components/elements/Card.js +31 -2
  12. package/src/components/elements/Column.js +28 -2
  13. package/src/components/elements/Columns.js +50 -4
  14. package/src/components/elements/Container.js +119 -3
  15. package/src/components/elements/DropDownFilter.js +27 -2
  16. package/src/components/elements/Empty.js +18 -1
  17. package/src/components/elements/Field.js +29 -2
  18. package/src/components/elements/HTMLCode.js +18 -2
  19. package/src/components/elements/Image.js +29 -2
  20. package/src/components/elements/JoinField.js +28 -2
  21. package/src/components/elements/LineBreak.js +17 -1
  22. package/src/components/elements/Link.js +34 -2
  23. package/src/components/elements/SearchBar.js +29 -2
  24. package/src/components/elements/Tabs.js +29 -2
  25. package/src/components/elements/Text.js +36 -2
  26. package/src/components/elements/ToggleFilter.js +31 -2
  27. package/src/components/elements/View.js +27 -2
  28. package/src/components/elements/ViewLink.js +36 -2
  29. package/src/components/elements/faicons.js +481 -0
  30. package/src/components/elements/utils.js +279 -16
  31. package/src/components/preview_context.js +6 -1
  32. package/src/components/storage.js +59 -2
  33. package/src/index.js +12 -0
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/utils
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { Fragment, useContext, useState } from "react";
2
8
  import optionsCtx from "../context";
3
9
  import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -15,10 +21,23 @@ export const DynamicFontAwesomeIcon = ({ icon, className }) => {
15
21
  return <i className={`${icon} ${className || ""}`}></i>;
16
22
  };
17
23
 
18
- export const blockProps = (is_block) =>
24
+ export /**
25
+ * @param {boolean} is_block
26
+ * @returns {object}
27
+ */
28
+ const blockProps = (is_block) =>
19
29
  is_block ? { style: { display: "block" } } : {};
20
30
 
21
- export const BlockSetting = ({ block, setProp }) => (
31
+ export /**
32
+ * @param {object} props
33
+ * @param {boolean} props.block
34
+ * @param {function} props.setProp
35
+ * @returns {div}
36
+ * @category saltcorn-builder
37
+ * @subcategory components / elements / utils
38
+ * @namespace
39
+ */
40
+ const BlockSetting = ({ block, setProp }) => (
22
41
  <div className="form-check">
23
42
  <input
24
43
  className="form-check-input"
@@ -36,8 +55,24 @@ export const BlockSetting = ({ block, setProp }) => (
36
55
  </div>
37
56
  );
38
57
 
39
- export const OrFormula = ({ setProp, isFormula, node, nodekey, children }) => {
58
+ export /**
59
+ * @param {object} props
60
+ * @param {function} props.setProp
61
+ * @param {object} props.isFormula
62
+ * @param {object} props.node
63
+ * @param {string} props.nodekey
64
+ * @param {string} props.children
65
+ * @returns {Fragment}
66
+ * @namespace
67
+ * @category saltcorn-builder
68
+ * @subcategory components / elements / utils
69
+ */
70
+ const OrFormula = ({ setProp, isFormula, node, nodekey, children }) => {
40
71
  const { mode } = useContext(optionsCtx);
72
+
73
+ /**
74
+ * @returns {void}
75
+ */
41
76
  const switchIsFml = () => {
42
77
  const isFmlAfter = !isFormula[nodekey];
43
78
  setProp((prop) => {
@@ -95,7 +130,17 @@ export const OrFormula = ({ setProp, isFormula, node, nodekey, children }) => {
95
130
  </Fragment>
96
131
  );
97
132
  };
98
- export const MinRoleSetting = ({ minRole, setProp }) => {
133
+
134
+ export /**
135
+ * @param {object} props
136
+ * @param {string} props.minRole
137
+ * @param {function} props.setProp
138
+ * @returns {div}
139
+ * @namespace
140
+ * @category saltcorn-builder
141
+ * @subcategory components / elements / utils
142
+ */
143
+ const MinRoleSetting = ({ minRole, setProp }) => {
99
144
  const options = useContext(optionsCtx);
100
145
  return (
101
146
  <div>
@@ -118,7 +163,17 @@ export const MinRoleSetting = ({ minRole, setProp }) => {
118
163
  </div>
119
164
  );
120
165
  };
121
- export const MinRoleSettingRow = ({ minRole, setProp }) => {
166
+
167
+ export /**
168
+ * @param {object} props
169
+ * @param {string} props.minRole
170
+ * @param {function} props.setProp
171
+ * @returns {tr}
172
+ * @namespace
173
+ * @category saltcorn-builder
174
+ * @subcategory components / elements / utils
175
+ */
176
+ const MinRoleSettingRow = ({ minRole, setProp }) => {
122
177
  const options = useContext(optionsCtx);
123
178
  return (
124
179
  <tr>
@@ -146,6 +201,16 @@ export const MinRoleSettingRow = ({ minRole, setProp }) => {
146
201
  </tr>
147
202
  );
148
203
  };
204
+
205
+ /**
206
+ * @param {object} props
207
+ * @param {string} props.textStyle
208
+ * @param {function} props.setProp
209
+ * @returns {select}
210
+ * @namespace
211
+ * @category saltcorn-builder
212
+ * @subcategory components / elements / utils
213
+ */
149
214
  const TextStyleSelect = ({ textStyle, setProp }) => {
150
215
  return (
151
216
  <select
@@ -174,7 +239,17 @@ const TextStyleSelect = ({ textStyle, setProp }) => {
174
239
  </select>
175
240
  );
176
241
  };
177
- export const TextStyleSetting = ({ textStyle, setProp }) => {
242
+
243
+ export /**
244
+ * @param {object} props
245
+ * @param {string} props.textStyle
246
+ * @param {function} props.setProp
247
+ * @returns {div}
248
+ * @namespace
249
+ * @category saltcorn-builder
250
+ * @subcategory components / elements / utils
251
+ */
252
+ const TextStyleSetting = ({ textStyle, setProp }) => {
178
253
  return (
179
254
  <div>
180
255
  <label>Text Style</label>
@@ -182,7 +257,17 @@ export const TextStyleSetting = ({ textStyle, setProp }) => {
182
257
  </div>
183
258
  );
184
259
  };
185
- export const TextStyleRow = ({ textStyle, setProp }) => {
260
+
261
+ export /**
262
+ * @param {object} props
263
+ * @param {string} props.textStyle
264
+ * @param {function} props.setProp
265
+ * @returns {tr}
266
+ * @namespace
267
+ * @category saltcorn-builder
268
+ * @subcategory components / elements / utils
269
+ */
270
+ const TextStyleRow = ({ textStyle, setProp }) => {
186
271
  return (
187
272
  <tr>
188
273
  <td>
@@ -195,7 +280,16 @@ export const TextStyleRow = ({ textStyle, setProp }) => {
195
280
  );
196
281
  };
197
282
 
198
- export const Accordion = ({ titles, children }) => {
283
+ export /**
284
+ * @param {object} props
285
+ * @param {string[]} [props.titles]
286
+ * @param {object[]} props.children
287
+ * @returns {Fragment}
288
+ * @category saltcorn-builder
289
+ * @subcategory components / elements / utils
290
+ * @namespace
291
+ */
292
+ const Accordion = ({ titles, children }) => {
199
293
  const [currentTab, setCurrentTab] = useState(0);
200
294
  return (
201
295
  <Fragment>
@@ -225,6 +319,17 @@ export const Accordion = ({ titles, children }) => {
225
319
  </Fragment>
226
320
  );
227
321
  };
322
+
323
+ /**
324
+ * @param {object} opts
325
+ * @param {string} opts.url
326
+ * @param {object} opts.body
327
+ * @param {object} opts.options
328
+ * @param {function} opts.setPreviews
329
+ * @param {*} opts.node_id
330
+ * @param {boolean} opts.isView
331
+ * @returns {void}
332
+ */
228
333
  const fetchPreview = ({ url, body, options, setPreviews, node_id, isView }) => {
229
334
  fetch(url, {
230
335
  method: "POST",
@@ -255,6 +360,12 @@ const fetchPreview = ({ url, body, options, setPreviews, node_id, isView }) => {
255
360
  setPreviews((prevState) => ({ ...prevState, [node_id]: newHtml }));
256
361
  });
257
362
  };
363
+
364
+ /**
365
+ * @function
366
+ * @param {object} [args = {}]
367
+ * @return {function}
368
+ */
258
369
  export const fetchFieldPreview = (args = {}) => (changes = {}) => {
259
370
  const { node_id, options, name, fieldview, setPreviews } = {
260
371
  ...args,
@@ -273,6 +384,11 @@ export const fetchFieldPreview = (args = {}) => (changes = {}) => {
273
384
  });
274
385
  };
275
386
 
387
+ /**
388
+ * @function
389
+ * @param {object} [args = {}]
390
+ * @return {function}
391
+ */
276
392
  export const fetchViewPreview = (args = {}) => (changes = {}) => {
277
393
  const { node_id, options, view, setPreviews } = {
278
394
  ...args,
@@ -298,7 +414,17 @@ export const fetchViewPreview = (args = {}) => (changes = {}) => {
298
414
  });
299
415
  };
300
416
 
301
- export const SelectUnits = ({ vert, autoable, ...props }) => (
417
+ export /**
418
+ * @param {object} props
419
+ * @param {boolean} props.vert
420
+ * @param {string} [props.autoable]
421
+ * @param {...*} props.props
422
+ * @returns {select}
423
+ * @category saltcorn-builder
424
+ * @subcategory components / elements / utils
425
+ * @namespace
426
+ */
427
+ const SelectUnits = ({ vert, autoable, ...props }) => (
302
428
  <select {...props}>
303
429
  <option>px</option>
304
430
  <option>%</option>
@@ -309,6 +435,11 @@ export const SelectUnits = ({ vert, autoable, ...props }) => (
309
435
  </select>
310
436
  );
311
437
 
438
+ /**
439
+ * @function
440
+ * @param {string} [styles]
441
+ * @returns {string}
442
+ */
312
443
  export const parseStyles = (styles) =>
313
444
  (styles || "")
314
445
  .split("\n")
@@ -330,6 +461,11 @@ export const parseStyles = (styles) =>
330
461
  {}
331
462
  );
332
463
 
464
+ /**
465
+ * @function
466
+ * @param {object} styles
467
+ * @returns {object}
468
+ */
333
469
  export const reactifyStyles = (styles) => {
334
470
  const toCamel = (s) => {
335
471
  return s.replace(/([-][a-z])/gi, ($1) => {
@@ -342,8 +478,21 @@ export const reactifyStyles = (styles) => {
342
478
  });
343
479
  return reactified;
344
480
  };
481
+
482
+ /**
483
+ * @param {object} f
484
+ * @returns {boolean}
485
+ */
345
486
  const isCheckbox = (f) =>
346
487
  f && f.type && (f.type === "Bool" || f.type.name === "Bool");
488
+
489
+ /**
490
+ * @function
491
+ * @param {function} setProp
492
+ * @param {*} fieldview
493
+ * @param {object[]} [fields]
494
+ * @returns {void}
495
+ */
347
496
  export const setInitialConfig = (setProp, fieldview, fields) => {
348
497
  (fields || []).forEach((f, ix) => {
349
498
  if (f.input_type === "select")
@@ -354,6 +503,15 @@ export const setInitialConfig = (setProp, fieldview, fields) => {
354
503
  });
355
504
  };
356
505
 
506
+ /**
507
+ * @param {object} props
508
+ * @param {string} props.value
509
+ * @param {function} props.onChange
510
+ * @category saltcorn-builder
511
+ * @subcategory components / elements / utils
512
+ * @namespace
513
+ * @returns {input|button}
514
+ */
357
515
  const ColorInput = ({ value, onChange }) =>
358
516
  value ? (
359
517
  <input
@@ -371,7 +529,19 @@ const ColorInput = ({ value, onChange }) =>
371
529
  </button>
372
530
  );
373
531
 
374
- export const ConfigForm = ({
532
+ export /**
533
+ * @param {object} props
534
+ * @param {object[]} props.fields
535
+ * @param {object} props.configuration
536
+ * @param {function} props.setProp
537
+ * @param {object} props.node
538
+ * @param {function} props.onChange
539
+ * @returns {div}
540
+ * @category saltcorn-builder
541
+ * @subcategory components / elements / utils
542
+ * @namespace
543
+ */
544
+ const ConfigForm = ({
375
545
  fields,
376
546
  configuration,
377
547
  setProp,
@@ -408,9 +578,28 @@ export const ConfigForm = ({
408
578
  </div>
409
579
  );
410
580
 
581
+ /**
582
+ * @param {object|undefined} x
583
+ * @param {object} y
584
+ * @returns {object}
585
+ */
411
586
  const or_if_undef = (x, y) => (typeof x === "undefined" ? y : x);
412
587
 
413
- export const ConfigField = ({
588
+
589
+ export /**
590
+ * @param {object} props
591
+ * @param {object} props.field
592
+ * @param {object} [props.configuration]
593
+ * @param {function} props.setProp
594
+ * @param {function} props.onChange
595
+ * @param {object} props.props
596
+ * @param {boolean} props.isStyle
597
+ * @returns {select|input}
598
+ * @category saltcorn-builder
599
+ * @subcategory components / elements / utils
600
+ * @namespace
601
+ */
602
+ const ConfigField = ({
414
603
  field,
415
604
  configuration,
416
605
  setProp,
@@ -418,6 +607,10 @@ export const ConfigField = ({
418
607
  props,
419
608
  isStyle,
420
609
  }) => {
610
+ /**
611
+ * @param {object} v
612
+ * @returns {void}
613
+ */
421
614
  const myOnChange = (v) => {
422
615
  setProp((prop) => {
423
616
  if (configuration) {
@@ -481,7 +674,9 @@ export const ConfigField = ({
481
674
  <input
482
675
  type="number"
483
676
  className="form-control"
484
- step={1}
677
+ step={field.step || 1}
678
+ min={field.min}
679
+ max={field.max}
485
680
  value={value || ""}
486
681
  onChange={(e) => e.target && myOnChange(e.target.value)}
487
682
  />
@@ -624,7 +819,14 @@ export const ConfigField = ({
624
819
  return f ? f() : null;
625
820
  };
626
821
 
627
- export const SettingsFromFields = (fields) => () => {
822
+ export /**
823
+ * @param {object[]} fields
824
+ * @category saltcorn-builder
825
+ * @subcategory components / elements / utils
826
+ * @namespace
827
+ * @returns {table}
828
+ */
829
+ const SettingsFromFields = (fields) => () => {
628
830
  const node = useNode((node) => {
629
831
  const ps = {};
630
832
  fields.forEach((f) => {
@@ -649,13 +851,33 @@ export const SettingsFromFields = (fields) => () => {
649
851
  );
650
852
  };
651
853
 
652
- export const SettingsSectionHeaderRow = ({ title }) => (
854
+ export /**
855
+ * @param {object} props
856
+ * @param {string} props.title
857
+ * @returns {tr}
858
+ * @category saltcorn-builder
859
+ * @subcategory components / elements / utils
860
+ * @namespace
861
+ */
862
+ const SettingsSectionHeaderRow = ({ title }) => (
653
863
  <tr>
654
864
  <th colSpan="2">{title}</th>
655
865
  </tr>
656
866
  );
657
867
 
658
- export const SettingsRow = ({ field, node, setProp, onChange, isStyle }) => {
868
+ export /**
869
+ * @param {object} props
870
+ * @param {string} props.field
871
+ * @param {object} props.node
872
+ * @param {function} props.setProp
873
+ * @param {function} props.onChange
874
+ * @param {boolean} props.isStyle
875
+ * @returns {tr}
876
+ * @category saltcorn-builder
877
+ * @subcategory components / elements / utils
878
+ * @namespace
879
+ */
880
+ const SettingsRow = ({ field, node, setProp, onChange, isStyle }) => {
659
881
  const fullWidth = ["String", "Bool", "textarea"].includes(field.type);
660
882
  const needLabel = field.type !== "Bool";
661
883
  const inner = field.canBeFormula ? (
@@ -698,15 +920,35 @@ export const SettingsRow = ({ field, node, setProp, onChange, isStyle }) => {
698
920
  </tr>
699
921
  );
700
922
  };
923
+
924
+ /**
925
+ * @category saltcorn-builder
926
+ * @extends React.Component
927
+ */
701
928
  export class ErrorBoundary extends React.Component {
929
+ /**
930
+ * ErrorBoundary constructor
931
+ * @param {object} props
932
+ */
702
933
  constructor(props) {
703
934
  super(props);
704
935
  this.state = { hasError: false };
705
936
  }
937
+
938
+ /**
939
+ * @param {*} error
940
+ * @returns {object}
941
+ */
706
942
  static getDerivedStateFromError(error) {
707
943
  // Update state so the next render will show the fallback UI.
708
944
  return { hasError: true };
709
945
  }
946
+
947
+ /**
948
+ * @param {object} error
949
+ * @param {object} errorInfo
950
+ * @returns {void}
951
+ */
710
952
  componentDidCatch(error, errorInfo) {
711
953
  // You can also log the error to an error reporting service
712
954
  //logErrorToMyService(error, errorInfo);
@@ -717,12 +959,27 @@ export class ErrorBoundary extends React.Component {
717
959
  );
718
960
  }
719
961
 
962
+ /**
963
+ * @returns {object}
964
+ */
720
965
  render() {
721
966
  return this.props.children;
722
967
  }
723
968
  }
724
969
 
725
- export const ButtonOrLinkSettingsRows = ({
970
+ export /**
971
+ * @param {object} props
972
+ * @param {function} props.setProp
973
+ * @param {string} [props.btnClass = null]
974
+ * @param {string} [props.keyPrefix = ""]
975
+ * @param {object} props.values
976
+ * @param {boolean} [props.linkFirst = false]
977
+ * @returns {tr}
978
+ * @category saltcorn-builder
979
+ * @subcategory components / elements / utils
980
+ * @namespace
981
+ */
982
+ const ButtonOrLinkSettingsRows = ({
726
983
  setProp,
727
984
  btnClass = null,
728
985
  keyPrefix = "",
@@ -847,6 +1104,12 @@ export const ButtonOrLinkSettingsRows = ({
847
1104
  : []),
848
1105
  ];
849
1106
  };
1107
+
1108
+ /**
1109
+ * @function
1110
+ * @param {string} style
1111
+ * @returns {object}
1112
+ */
850
1113
  export const bstyleopt = (style) => ({
851
1114
  value: style,
852
1115
  title: style,
@@ -1,4 +1,9 @@
1
- import { createContext } from "react";
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/preview_context
4
+ * @subcategory components
5
+ */
2
6
 
7
+ import { createContext } from "react";
3
8
 
4
9
  export default createContext({});
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/storage
4
+ * @subcategory components
5
+ */
6
+
1
7
  import React, { Fragment } from "react";
2
8
  import { Element } from "@craftjs/core";
3
9
  import { Text } from "./elements/Text";
@@ -20,6 +26,10 @@ import { Container } from "./elements/Container";
20
26
  import { DropDownFilter } from "./elements/DropDownFilter";
21
27
  import { ToggleFilter } from "./elements/ToggleFilter";
22
28
 
29
+ /**
30
+ * @param {object} segment
31
+ * @returns {number}
32
+ */
23
33
  const getColWidths = (segment) => {
24
34
  if (!segment.widths)
25
35
  return ntimes(
@@ -31,6 +41,11 @@ const getColWidths = (segment) => {
31
41
  widths.pop();
32
42
  return widths;
33
43
  };
44
+
45
+ /**
46
+ * @param {object} segment
47
+ * @returns {object[]}
48
+ */
34
49
  const default_breakpoints = (segment) =>
35
50
  ntimes(segment.besides.length, () => segment.breakpoint || "");
36
51
 
@@ -56,8 +71,23 @@ const allElements = [
56
71
  ToggleFilter,
57
72
  ];
58
73
 
59
- export const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
74
+ export /**
75
+ * @param {object} layout
76
+ * @param {object} query
77
+ * @param {object} actions
78
+ * @param {string} [parent = "ROOT"]
79
+ * @returns {Text|View|Action|Element|Tabs|Columns}
80
+ * @category saltcorn-builder
81
+ * @subcategory components
82
+ * @namespace
83
+ */
84
+ const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
60
85
  //console.log("layoutToNodes", JSON.stringify(layout));
86
+ /**
87
+ * @param {object} segment
88
+ * @param {string} ix
89
+ * @returns {Element|Text|View|Action|Tabs|Columns}
90
+ */
61
91
  function toTag(segment, ix) {
62
92
  if (!segment) return <Empty key={ix} />;
63
93
 
@@ -211,6 +241,12 @@ export const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
211
241
  return segment.above.map((e, ix) => toTag(e, ix));
212
242
  }
213
243
  }
244
+
245
+ /**
246
+ * @param {object} segment
247
+ * @param {object} parent
248
+ * @returns {void}
249
+ */
214
250
  function go(segment, parent) {
215
251
  if (!segment) return;
216
252
  if (segment.above) {
@@ -243,16 +279,37 @@ export const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
243
279
  go(layout, parent);
244
280
  };
245
281
 
282
+ /**
283
+ * @returns {number}
284
+ */
246
285
  const rand_ident = () => Math.floor(Math.random() * 16777215).toString(16);
247
286
 
248
- export const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
287
+ export /**
288
+ * @param {object[]} nodes
289
+ * @param {string} [startFrom = "ROOT" ]
290
+ * @returns {object}
291
+ * @category saltcorn-builder
292
+ * @subcategory components
293
+ * @namespace
294
+ */
295
+ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
249
296
  //console.log(JSON.stringify(nodes, null, 2));
250
297
  var columns = [];
298
+
299
+ /**
300
+ * @param {object} node
301
+ * @returns {void|object}
302
+ */
251
303
  const get_nodes = (node) => {
252
304
  if (!node.nodes || node.nodes.length == 0) return;
253
305
  else if (node.nodes.length == 1) return go(nodes[node.nodes[0]]);
254
306
  else return { above: node.nodes.map((nm) => go(nodes[nm])) };
255
307
  };
308
+
309
+ /**
310
+ * @param {object} node
311
+ * @returns {object}
312
+ */
256
313
  const go = (node) => {
257
314
  const matchElement = allElements.find(
258
315
  (e) =>
package/src/index.js CHANGED
@@ -1,7 +1,19 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module saltcorn-builder/index
4
+ */
5
+
1
6
  import React from "react";
2
7
  import Builder from "./components/Builder";
3
8
  import ReactDOM from "react-dom";
4
9
 
10
+ /**
11
+ *
12
+ * @param {object} id
13
+ * @param {object} options
14
+ * @param {object} layout
15
+ * @param {string} mode
16
+ */
5
17
  function renderBuilder(id, options, layout, mode) {
6
18
  ReactDOM.render(
7
19
  <Builder