@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/Action
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { Fragment, useContext } from "react";
2
8
  import { useNode } from "@craftjs/core";
3
9
  import optionsCtx from "../context";
@@ -12,7 +18,25 @@ import {
12
18
  DynamicFontAwesomeIcon,
13
19
  } from "./utils";
14
20
 
15
- export const Action = ({
21
+ export /**
22
+ *
23
+ * @param {object} props
24
+ * @param {string} props.name
25
+ * @param {string} props.block
26
+ * @param {string} props.action_label
27
+ * @param {string} props.action_style
28
+ * @param {string} props.action_icon
29
+ * @param {string} props.action_size
30
+ * @param {string} props.action_bgcol
31
+ * @param {string} props.action_bordercol
32
+ * @param {string} props.action_textcol
33
+ * @returns {span|btn}
34
+ * @category saltcorn-builder
35
+ * @subcategory components
36
+ * @namespace
37
+ */
38
+ const Action =
39
+ ({
16
40
  name,
17
41
  block,
18
42
  action_label,
@@ -28,6 +52,9 @@ export const Action = ({
28
52
  connectors: { connect, drag },
29
53
  } = useNode((node) => ({ selected: node.events.selected }));
30
54
 
55
+ /**
56
+ * @type {object}
57
+ */
31
58
  const btn = (
32
59
  <button
33
60
  className={`btn ${action_style || "btn-primary"} ${action_size || ""}`}
@@ -50,7 +77,13 @@ export const Action = ({
50
77
  return selected ? <span className={"selected-node"}>{btn}</span> : btn;
51
78
  };
52
79
 
53
- export const ActionSettings = () => {
80
+ export /**
81
+ * @category saltcorn-builder
82
+ * @subcategory components
83
+ * @namespace
84
+ * @returns {div}
85
+ */
86
+ const ActionSettings = () => {
54
87
  const node = useNode((node) => ({
55
88
  name: node.data.props.name,
56
89
  block: node.data.props.block,
@@ -162,6 +195,9 @@ export const ActionSettings = () => {
162
195
  );
163
196
  };
164
197
 
198
+ /**
199
+ * @type {object}
200
+ */
165
201
  Action.craft = {
166
202
  displayName: "Action",
167
203
  related: {
@@ -1,9 +1,27 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/Aggregation
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { useContext } from "react";
2
8
  import { useNode } from "@craftjs/core";
3
9
  import optionsCtx from "../context";
4
10
  import { blockProps, BlockSetting, TextStyleRow } from "./utils";
5
11
 
6
- export const Aggregation = ({
12
+ export /**
13
+ * @param {object} props
14
+ * @param {string} props.agg_relation
15
+ * @param {string} props.agg_field
16
+ * @param {string} props.stat
17
+ * @param {boolean} props.block
18
+ * @param {string} props.textStyle
19
+ * @returns {span}
20
+ * @category saltcorn-builder
21
+ * @subcategory components
22
+ * @namespace
23
+ */
24
+ const Aggregation = ({
7
25
  agg_relation,
8
26
  agg_field,
9
27
  stat,
@@ -25,7 +43,13 @@ export const Aggregation = ({
25
43
  );
26
44
  };
27
45
 
28
- export const AggregationSettings = () => {
46
+ export /**
47
+ * @returns {table}
48
+ * @category saltcorn-builder
49
+ * @subcategory components
50
+ * @namespace
51
+ */
52
+ const AggregationSettings = () => {
29
53
  const {
30
54
  actions: { setProp },
31
55
  agg_relation,
@@ -139,6 +163,9 @@ export const AggregationSettings = () => {
139
163
  );
140
164
  };
141
165
 
166
+ /**
167
+ * @type {object}
168
+ */
142
169
  Aggregation.craft = {
143
170
  displayName: "Aggregation",
144
171
  related: {
@@ -1,10 +1,27 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/BoxModelEditor
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { useContext, Fragment, useState } from "react";
2
8
  import { SettingsRow, SettingsSectionHeaderRow, bstyleopt } from "./utils";
3
9
  /*
4
10
  Contains code from https://github.com/tpaksu/boxmodel
5
11
  Copyright (c) 2017 Taha Paksu
6
12
  */
7
- export const BoxModelEditor = ({ setProp, node }) => {
13
+
14
+ export /**
15
+ *
16
+ * @param {object} props
17
+ * @param {function} props.setProp
18
+ * @param {object} props.node
19
+ * @returns {Fragment}
20
+ * @category saltcorn-builder
21
+ * @subcategory components
22
+ * @namespace
23
+ */
24
+ const BoxModelEditor = ({ setProp, node }) => {
8
25
  const [selectedCategory, setSelectedCategory] = useState(false);
9
26
  const [selectedDirection, setSelectedDirection] = useState(false);
10
27
  const selectedProperty = !selectedCategory
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/Card
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { Fragment } from "react";
2
8
  import { Text } from "./Text";
3
9
  import { OrFormula, SettingsRow, Accordion, reactifyStyles } from "./utils";
@@ -5,7 +11,21 @@ import { OrFormula, SettingsRow, Accordion, reactifyStyles } from "./utils";
5
11
  import { Element, useNode } from "@craftjs/core";
6
12
  import { BoxModelEditor } from "./BoxModelEditor";
7
13
  import { bstyleopt } from "./utils";
8
- export const Card = ({
14
+
15
+ export /**
16
+ * @param {object} props
17
+ * @param {string} props.children
18
+ * @param {object} props.isFormula
19
+ * @param {string} [props.title]
20
+ * @param {string} props.shadow
21
+ * @param {boolean} props.noPadding
22
+ * @param {object} props.style
23
+ * @returns {div}
24
+ * @category saltcorn-builder
25
+ * @subcategory components
26
+ * @namespace
27
+ */
28
+ const Card = ({
9
29
  children,
10
30
  isFormula,
11
31
  title,
@@ -42,7 +62,13 @@ export const Card = ({
42
62
  );
43
63
  };
44
64
 
45
- export const CardSettings = () => {
65
+ export /**
66
+ * @returns {Accordion}
67
+ * @category saltcorn-builder
68
+ * @subcategory components
69
+ * @namespace
70
+ */
71
+ const CardSettings = () => {
46
72
  const node = useNode((node) => {
47
73
  const ps = {};
48
74
  fields.forEach((f) => {
@@ -112,6 +138,9 @@ const fields = [
112
138
  { name: "style", default: {} },
113
139
  ];
114
140
 
141
+ /**
142
+ * @type {object}
143
+ */
115
144
  Card.craft = {
116
145
  props: {
117
146
  title: "",
@@ -1,9 +1,25 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/Column
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { useContext, Fragment } from "react";
2
8
 
3
9
  import { Element, useNode } from "@craftjs/core";
4
10
  import optionsCtx from "../context";
5
11
 
6
- export const Column = ({ children, align }) => {
12
+ export /**
13
+ *
14
+ * @param {object} props
15
+ * @param {string} props.children
16
+ * @param {*} props.align
17
+ * @returns {div}
18
+ * @category saltcorn-builder
19
+ * @subcategory components
20
+ * @namespace
21
+ */
22
+ const Column = ({ children, align }) => {
7
23
  const {
8
24
  selected,
9
25
  id,
@@ -21,10 +37,20 @@ export const Column = ({ children, align }) => {
21
37
  );
22
38
  };
23
39
 
24
- export const ColumnSettings = () => {
40
+ export /**
41
+ * @returns {div}
42
+ * @category saltcorn-builder
43
+ * @subcategory components
44
+ * @namespace
45
+ */
46
+ const ColumnSettings = () => {
25
47
  const {} = useNode((node) => ({}));
26
48
  return <div></div>;
27
49
  };
50
+
51
+ /**
52
+ * @type {object}
53
+ */
28
54
  Column.craft = {
29
55
  displayName: "Column",
30
56
  props: {},
@@ -1,9 +1,21 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/Columns
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { Fragment } from "react";
2
8
  import { Column } from "./Column";
3
9
 
4
10
  import { Element, useNode } from "@craftjs/core";
5
11
 
6
- export const ntimes = (n, f) => {
12
+ export /**
13
+ *
14
+ * @param {number} n
15
+ * @param {function} f
16
+ * @returns {object[]}
17
+ */
18
+ const ntimes = (n, f) => {
7
19
  var res = [];
8
20
  for (let index = 0; index < n; index++) {
9
21
  res.push(f(index));
@@ -11,18 +23,42 @@ export const ntimes = (n, f) => {
11
23
  return res;
12
24
  };
13
25
 
14
- export const sum = (xs) => {
26
+ export /**
27
+ *
28
+ * @param {number[]} xs
29
+ * @returns {number}
30
+ */
31
+ const sum = (xs) => {
15
32
  var res = 0;
16
33
  for (const x of xs) res += x;
17
34
  return res;
18
35
  };
19
36
 
37
+ /**
38
+ * @param {number} ncols
39
+ * @returns {number}
40
+ */
20
41
  const resetWidths = (ncols) => ntimes(ncols - 1, () => 12 / ncols);
21
42
 
43
+ /**
44
+ * @param {number[]} widths
45
+ * @param {number} colix
46
+ * @returns {number}
47
+ */
22
48
  const getWidth = (widths, colix) =>
23
49
  colix < widths.length ? widths[colix] : 12 - sum(widths);
24
50
 
25
- export const Columns = ({ widths, contents, ncols }) => {
51
+ export /**
52
+ * @param {object} opts
53
+ * @param {number[]} opts.widths
54
+ * @param {string[]} opts.contents
55
+ * @param {number} opts.ncols
56
+ * @returns {div}
57
+ * @namespace
58
+ * @category saltcorn-builder
59
+ * @subcategory components
60
+ */
61
+ const Columns = ({ widths, contents, ncols }) => {
26
62
  const {
27
63
  selected,
28
64
  connectors: { connect, drag },
@@ -43,7 +79,13 @@ export const Columns = ({ widths, contents, ncols }) => {
43
79
  );
44
80
  };
45
81
 
46
- export const ColumnsSettings = () => {
82
+ export /**
83
+ * @returns {div}
84
+ * @namespace
85
+ * @category saltcorn-builder
86
+ * @subcategory components
87
+ */
88
+ const ColumnsSettings = () => {
47
89
  const {
48
90
  actions: { setProp },
49
91
  widths,
@@ -132,6 +174,10 @@ export const ColumnsSettings = () => {
132
174
  </div>
133
175
  );
134
176
  };
177
+
178
+ /**
179
+ * @type {object}
180
+ */
135
181
  Columns.craft = {
136
182
  displayName: "Columns",
137
183
  defaultProps: {
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/Container
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { useContext, Fragment } from "react";
2
8
 
3
9
  import { Element, useNode } from "@craftjs/core";
@@ -37,12 +43,52 @@ import {
37
43
  import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
38
44
  import { faScroll, faRobot } from "@fortawesome/free-solid-svg-icons";
39
45
  import { BoxModelEditor } from "./BoxModelEditor";
46
+ import previewCtx from "../preview_context";
40
47
 
48
+ /**
49
+ *
50
+ * @param {string} string
51
+ * @returns {string}
52
+ */
41
53
  function capitalizeFirstLetter(string) {
42
54
  return string.charAt(0).toUpperCase() + string.slice(1);
43
55
  }
44
56
 
45
- export const Container = ({
57
+ export /**
58
+ * @param {object} props
59
+ * @param {*} props.children
60
+ * @param {*} props.minHeight
61
+ * @param {*} props.height
62
+ * @param {*} props.width
63
+ * @param {*} props.minHeightUnit
64
+ * @param {*} props.heightUnit
65
+ * @param {*} props.widthUnit
66
+ * @param {*} props.vAlign
67
+ * @param {*} props.hAlign
68
+ * @param {*} props.bgFileId
69
+ * @param {*} props.imageSize
70
+ * @param {*} props.bgType
71
+ * @param {*} props.display
72
+ * @param {*} props.bgColor
73
+ * @param {*} props.setTextColor
74
+ * @param {*} props.textColor
75
+ * @param {*} props.customClass
76
+ * @param {*} props.customCSS
77
+ * @param {*} props.margin
78
+ * @param {*} props.padding
79
+ * @param {*} props.minScreenWidth
80
+ * @param {*} props.gradStartColor
81
+ * @param {*} props.gradEndColor
82
+ * @param {*} props.gradDirection
83
+ * @param {*} props.rotate
84
+ * @param {*} props.style
85
+ * @param {*} props.htmlElement
86
+ * @returns {DetailedReactHTMLElement}
87
+ * @namespace
88
+ * @category saltcorn-builder
89
+ * @subcategory components
90
+ */
91
+ const Container = ({
46
92
  children,
47
93
  minHeight,
48
94
  height,
@@ -139,7 +185,15 @@ export const Container = ({
139
185
  );
140
186
  };
141
187
 
142
- export const ContainerSettings = () => {
188
+
189
+ export /**
190
+ * @returns {div}
191
+ * @returns {Accordion}
192
+ * @namespace
193
+ * @category saltcorn-builder
194
+ * @subcategory components
195
+ */
196
+ const ContainerSettings = () => {
143
197
  const node = useNode((node) => ({
144
198
  minHeight: node.data.props.minHeight,
145
199
  height: node.data.props.height,
@@ -206,8 +260,14 @@ export const ContainerSettings = () => {
206
260
  htmlElement,
207
261
  } = node;
208
262
  const options = useContext(optionsCtx);
263
+ const { uploadedFiles } = useContext(previewCtx);
264
+
209
265
  const ownership = !!options.ownership;
210
266
 
267
+ /**
268
+ * @param {string} key
269
+ * @returns {function}
270
+ */
211
271
  const setAProp = (key) => (e) => {
212
272
  if (e.target) {
213
273
  const target_value = e.target.value;
@@ -361,7 +421,8 @@ export const ContainerSettings = () => {
361
421
  setProp((prop) => {
362
422
  prop.bgFileId =
363
423
  prop.bgFileId ||
364
- (options.images.length > 0 && options.images[0].id);
424
+ (options.images.length + uploadedFiles.length > 0 &&
425
+ options.images[0].id);
365
426
  })
366
427
  }
367
428
  />
@@ -436,6 +497,11 @@ export const ContainerSettings = () => {
436
497
  {f.filename}
437
498
  </option>
438
499
  ))}
500
+ {(uploadedFiles || []).map((uf, ix) => (
501
+ <option key={ix} value={uf.id}>
502
+ {uf.filename}
503
+ </option>
504
+ ))}{" "}
439
505
  </select>
440
506
  </td>
441
507
  </tr>
@@ -473,6 +539,50 @@ export const ContainerSettings = () => {
473
539
  </td>
474
540
  </tr>
475
541
  )}
542
+ <SettingsSectionHeaderRow title="Typography" />
543
+ <SettingsRow
544
+ field={{
545
+ name: "font-family",
546
+ label: "Font family",
547
+ type: "String",
548
+ }}
549
+ node={node}
550
+ setProp={setProp}
551
+ isStyle={true}
552
+ />
553
+ <SettingsRow
554
+ field={{
555
+ name: "font-size",
556
+ label: "Font size",
557
+ type: "DimUnits",
558
+ }}
559
+ node={node}
560
+ setProp={setProp}
561
+ isStyle={true}
562
+ />
563
+ <SettingsRow
564
+ field={{
565
+ name: "font-weight",
566
+ label: "Weight",
567
+ type: "Integer",
568
+ min: 100,
569
+ max: 900,
570
+ step: 100,
571
+ }}
572
+ node={node}
573
+ setProp={setProp}
574
+ isStyle={true}
575
+ />
576
+ <SettingsRow
577
+ field={{
578
+ name: "line-height",
579
+ label: "Line height",
580
+ type: "DimUnits",
581
+ }}
582
+ node={node}
583
+ setProp={setProp}
584
+ isStyle={true}
585
+ />
476
586
  <tr>
477
587
  <td colSpan="2">
478
588
  <label>
@@ -512,11 +622,13 @@ export const ContainerSettings = () => {
512
622
  field={{ name: "flex-grow", label: "Grow", type: "Float" }}
513
623
  node={node}
514
624
  setProp={setProp}
625
+ isStyle={true}
515
626
  />
516
627
  <SettingsRow
517
628
  field={{ name: "flex-shrink", label: "Shrink", type: "Float" }}
518
629
  node={node}
519
630
  setProp={setProp}
631
+ isStyle={true}
520
632
  />
521
633
  {display && display.includes("flex") && (
522
634
  <Fragment>
@@ -769,6 +881,10 @@ export const ContainerSettings = () => {
769
881
  </Accordion>
770
882
  );
771
883
  };
884
+
885
+ /**
886
+ * @type {object}
887
+ */
772
888
  Container.craft = {
773
889
  displayName: "Container",
774
890
  props: {
@@ -1,9 +1,25 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/DropDownFilter
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { useContext, Fragment } from "react";
2
8
  import { useNode } from "@craftjs/core";
3
9
  import optionsCtx from "../context";
4
10
  import { blockProps, BlockSetting, TextStyleRow } from "./utils";
5
11
 
6
- export const DropDownFilter = ({ name, block, full_width }) => {
12
+ export /**
13
+ * @param {object} props
14
+ * @param {string} props.name
15
+ * @param {boolean} props.block
16
+ * @param {boolean} props.full_width
17
+ * @returns {span}
18
+ * @namespace
19
+ * @category saltcorn-builder
20
+ * @subcategory components
21
+ */
22
+ const DropDownFilter = ({ name, block, full_width }) => {
7
23
  const {
8
24
  selected,
9
25
  connectors: { connect, drag },
@@ -21,7 +37,13 @@ export const DropDownFilter = ({ name, block, full_width }) => {
21
37
  );
22
38
  };
23
39
 
24
- export const DropDownFilterSettings = () => {
40
+ export /**
41
+ * @returns {table}
42
+ * @namespace
43
+ * @category saltcorn-builder
44
+ * @subcategory components
45
+ */
46
+ const DropDownFilterSettings = () => {
25
47
  const {
26
48
  actions: { setProp },
27
49
  name,
@@ -112,6 +134,9 @@ export const DropDownFilterSettings = () => {
112
134
  );
113
135
  };
114
136
 
137
+ /**
138
+ * @type {object}
139
+ */
115
140
  DropDownFilter.craft = {
116
141
  displayName: "DropDownFilter",
117
142
  related: {
@@ -1,13 +1,30 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/Empty
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { Fragment } from "react";
2
8
  import { useNode } from "@craftjs/core";
3
9
 
4
- export const Empty = ({}) => {
10
+ export /**
11
+ * @param {object} [props = {}]
12
+ * @returns {Fragment}
13
+ * @namespace
14
+ * @category saltcorn-builder
15
+ * @subcategory components
16
+ */
17
+ const Empty = ({}) => {
5
18
  const {
6
19
  selected,
7
20
  connectors: { connect, drag },
8
21
  } = useNode((node) => ({ selected: node.events.selected }));
9
22
  return null;
10
23
  };
24
+
25
+ /**
26
+ * @type {object}
27
+ */
11
28
  Empty.craft = {
12
29
  displayName: "Empty",
13
30
  };
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/Field
4
+ * @subcategory components / elements
5
+ */
6
+
1
7
  import React, { useContext, useEffect, Fragment } from "react";
2
8
  import { useNode } from "@craftjs/core";
3
9
  import optionsCtx from "../context";
@@ -11,7 +17,19 @@ import {
11
17
  fetchFieldPreview,
12
18
  } from "./utils";
13
19
 
14
- export const Field = ({ name, fieldview, block, textStyle, configuration }) => {
20
+ export /**
21
+ * @param {object} props
22
+ * @param {string} props.name
23
+ * @param {string} props.fieldview
24
+ * @param {boolean} props.block
25
+ * @param {string} props.textStyle
26
+ * @param {object} props.configuration
27
+ * @returns {div}
28
+ * @category saltcorn-builder
29
+ * @subcategory components
30
+ * @namespace
31
+ */
32
+ const Field = ({ name, fieldview, block, textStyle, configuration }) => {
15
33
  const {
16
34
  selected,
17
35
  node_id,
@@ -50,7 +68,13 @@ export const Field = ({ name, fieldview, block, textStyle, configuration }) => {
50
68
  );
51
69
  };
52
70
 
53
- export const FieldSettings = () => {
71
+ export /**
72
+ * @returns {Fragment}
73
+ * @namespace
74
+ * @category saltcorn-builder
75
+ * @subcategory components
76
+ */
77
+ const FieldSettings = () => {
54
78
  const {
55
79
  actions: { setProp },
56
80
  name,
@@ -173,6 +197,9 @@ export const FieldSettings = () => {
173
197
  );
174
198
  };
175
199
 
200
+ /**
201
+ * @type {object}
202
+ */
176
203
  Field.craft = {
177
204
  displayName: "Field",
178
205
  related: {