@saltcorn/builder 0.0.1-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.
Files changed (38) hide show
  1. package/.babelrc +3 -0
  2. package/CHANGELOG.md +8 -0
  3. package/dist/builder_bundle.js +80 -0
  4. package/package.json +47 -0
  5. package/src/components/Builder.js +477 -0
  6. package/src/components/Library.js +224 -0
  7. package/src/components/RenderNode.js +203 -0
  8. package/src/components/Toolbox.js +688 -0
  9. package/src/components/context.js +9 -0
  10. package/src/components/elements/Action.js +204 -0
  11. package/src/components/elements/Aggregation.js +179 -0
  12. package/src/components/elements/BoxModelEditor.js +398 -0
  13. package/src/components/elements/Card.js +152 -0
  14. package/src/components/elements/Column.js +63 -0
  15. package/src/components/elements/Columns.js +201 -0
  16. package/src/components/elements/Container.js +947 -0
  17. package/src/components/elements/DropDownFilter.js +154 -0
  18. package/src/components/elements/DropMenu.js +156 -0
  19. package/src/components/elements/Empty.js +30 -0
  20. package/src/components/elements/Field.js +239 -0
  21. package/src/components/elements/HTMLCode.js +61 -0
  22. package/src/components/elements/Image.js +320 -0
  23. package/src/components/elements/JoinField.js +206 -0
  24. package/src/components/elements/LineBreak.js +46 -0
  25. package/src/components/elements/Link.js +305 -0
  26. package/src/components/elements/SearchBar.js +141 -0
  27. package/src/components/elements/Tabs.js +347 -0
  28. package/src/components/elements/Text.js +330 -0
  29. package/src/components/elements/ToggleFilter.js +243 -0
  30. package/src/components/elements/View.js +189 -0
  31. package/src/components/elements/ViewLink.js +225 -0
  32. package/src/components/elements/boxmodel.html +253 -0
  33. package/src/components/elements/faicons.js +1643 -0
  34. package/src/components/elements/utils.js +1217 -0
  35. package/src/components/preview_context.js +9 -0
  36. package/src/components/storage.js +506 -0
  37. package/src/index.js +73 -0
  38. package/webpack.config.js +21 -0
@@ -0,0 +1,201 @@
1
+ /**
2
+ * @category saltcorn-builder
3
+ * @module components/elements/Columns
4
+ * @subcategory components / elements
5
+ */
6
+
7
+ import React, { Fragment } from "react";
8
+ import { Column } from "./Column";
9
+
10
+ import { Element, useNode } from "@craftjs/core";
11
+ import { Accordion, reactifyStyles } from "./utils";
12
+ import { BoxModelEditor } from "./BoxModelEditor";
13
+
14
+ export /**
15
+ *
16
+ * @param {number} n
17
+ * @param {function} f
18
+ * @returns {object[]}
19
+ */
20
+ const ntimes = (n, f) => {
21
+ var res = [];
22
+ for (let index = 0; index < n; index++) {
23
+ res.push(f(index));
24
+ }
25
+ return res;
26
+ };
27
+
28
+ export /**
29
+ *
30
+ * @param {number[]} xs
31
+ * @returns {number}
32
+ */
33
+ const sum = (xs) => {
34
+ var res = 0;
35
+ for (const x of xs) res += x;
36
+ return res;
37
+ };
38
+
39
+ /**
40
+ * @param {number} ncols
41
+ * @returns {number}
42
+ */
43
+ const resetWidths = (ncols) => ntimes(ncols - 1, () => 12 / ncols);
44
+
45
+ /**
46
+ * @param {number[]} widths
47
+ * @param {number} colix
48
+ * @returns {number}
49
+ */
50
+ const getWidth = (widths, colix) =>
51
+ colix < widths.length ? widths[colix] : 12 - sum(widths);
52
+
53
+ export /**
54
+ * @param {object} opts
55
+ * @param {number[]} opts.widths
56
+ * @param {string[]} opts.contents
57
+ * @param {number} opts.ncols
58
+ * @returns {div}
59
+ * @namespace
60
+ * @category saltcorn-builder
61
+ * @subcategory components
62
+ */
63
+ const Columns = ({ widths, contents, ncols, style }) => {
64
+ const {
65
+ selected,
66
+ connectors: { connect, drag },
67
+ } = useNode((node) => ({ selected: node.events.selected }));
68
+ return (
69
+ <div
70
+ className={`row ${selected ? "selected-node" : ""}`}
71
+ ref={(dom) => connect(drag(dom))}
72
+ style={reactifyStyles(style || {})}
73
+ >
74
+ {ntimes(ncols, (ix) => (
75
+ <div key={ix} className={`split-col col-sm-${getWidth(widths, ix)}`}>
76
+ <Element canvas id={`Col${ix}`} is={Column}>
77
+ {contents[ix]}
78
+ </Element>
79
+ </div>
80
+ ))}
81
+ </div>
82
+ );
83
+ };
84
+
85
+ export /**
86
+ * @returns {div}
87
+ * @namespace
88
+ * @category saltcorn-builder
89
+ * @subcategory components
90
+ */
91
+ const ColumnsSettings = () => {
92
+ const node = useNode((node) => ({
93
+ widths: node.data.props.widths,
94
+ ncols: node.data.props.ncols,
95
+ breakpoints: node.data.props.breakpoints,
96
+ style: node.data.props.style,
97
+ }));
98
+ const {
99
+ actions: { setProp },
100
+ widths,
101
+ ncols,
102
+ breakpoints,
103
+ style,
104
+ } = node;
105
+ return (
106
+ <Accordion>
107
+ <table accordiontitle="Column properties">
108
+ <tbody>
109
+ <tr>
110
+ <td colSpan="3">
111
+ <label>Number of columns</label>
112
+ </td>
113
+ <td>
114
+ <input
115
+ type="number"
116
+ value={ncols}
117
+ className="form-control"
118
+ step="1"
119
+ min="1"
120
+ max="4"
121
+ onChange={(e) =>
122
+ setProp((prop) => {
123
+ prop.ncols = e.target.value;
124
+ prop.widths = resetWidths(e.target.value);
125
+ })
126
+ }
127
+ />
128
+ </td>
129
+ </tr>
130
+ <tr>
131
+ <th colSpan="4">Widths &amp; Breakpoint</th>
132
+ </tr>
133
+ {ntimes(ncols, (ix) => (
134
+ <Fragment key={ix}>
135
+ <tr>
136
+ <th colSpan="4">Column {ix + 1}</th>
137
+ </tr>
138
+ <tr>
139
+ <td>
140
+ <label>Width</label>
141
+ </td>
142
+ <td align="right">
143
+ {ix < ncols - 1 ? (
144
+ <input
145
+ type="number"
146
+ value={widths[ix]}
147
+ className="form-control"
148
+ step="1"
149
+ min="1"
150
+ max={12 - (sum(widths) - widths[ix]) - 1}
151
+ onChange={(e) =>
152
+ setProp((prop) => (prop.widths[ix] = +e.target.value))
153
+ }
154
+ />
155
+ ) : (
156
+ `${12 - sum(widths)}`
157
+ )}
158
+ </td>
159
+ <td>/12</td>
160
+ <td>
161
+ <select
162
+ className="form-control form-select"
163
+ value={breakpoints[ix]}
164
+ onChange={(e) =>
165
+ setProp((prop) => (prop.breakpoints[ix] = e.target.value))
166
+ }
167
+ >
168
+ <option disabled>Breakpoint</option>
169
+ <option value="">None</option>
170
+ <option value="sm">Small</option>
171
+ <option value="md">Medium</option>
172
+ <option value="lg">Large</option>
173
+ </select>
174
+ </td>
175
+ </tr>
176
+ </Fragment>
177
+ ))}
178
+ </tbody>
179
+ </table>
180
+ <div accordiontitle="Box" className="w-100">
181
+ <BoxModelEditor setProp={setProp} node={node} sizeWithStyle={true} />
182
+ </div>
183
+ </Accordion>
184
+ );
185
+ };
186
+
187
+ /**
188
+ * @type {object}
189
+ */
190
+ Columns.craft = {
191
+ displayName: "Columns",
192
+ defaultProps: {
193
+ widths: [6],
194
+ ncols: 2,
195
+ style: {},
196
+ breakpoints: ["sm", "sm"],
197
+ },
198
+ related: {
199
+ settings: ColumnsSettings,
200
+ },
201
+ };