@saltcorn/builder 1.6.0-alpha.0 → 1.6.0-alpha.10

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 (40) hide show
  1. package/dist/builder_bundle.js +4126 -2
  2. package/dist/builder_bundle.js.LICENSE.txt +18 -51
  3. package/package.json +31 -27
  4. package/src/components/Builder.js +334 -122
  5. package/src/components/Library.js +25 -13
  6. package/src/components/RenderNode.js +19 -8
  7. package/src/components/Toolbox.js +333 -269
  8. package/src/components/elements/Action.js +144 -29
  9. package/src/components/elements/Aggregation.js +20 -23
  10. package/src/components/elements/ArrayManager.js +7 -5
  11. package/src/components/elements/BoxModelEditor.js +19 -17
  12. package/src/components/elements/Card.js +47 -34
  13. package/src/components/elements/Clone.js +74 -2
  14. package/src/components/elements/Column.js +1 -1
  15. package/src/components/elements/Columns.js +27 -25
  16. package/src/components/elements/Container.js +170 -90
  17. package/src/components/elements/DropDownFilter.js +10 -8
  18. package/src/components/elements/DropMenu.js +18 -9
  19. package/src/components/elements/Field.js +9 -7
  20. package/src/components/elements/HTMLCode.js +3 -1
  21. package/src/components/elements/Image.js +20 -15
  22. package/src/components/elements/JoinField.js +15 -11
  23. package/src/components/elements/Link.js +18 -16
  24. package/src/components/elements/ListColumn.js +7 -3
  25. package/src/components/elements/ListColumns.js +4 -1
  26. package/src/components/elements/MonacoEditor.js +4 -2
  27. package/src/components/elements/Page.js +7 -4
  28. package/src/components/elements/RelationBadges.js +16 -11
  29. package/src/components/elements/RelationOnDemandPicker.js +18 -12
  30. package/src/components/elements/SearchBar.js +37 -10
  31. package/src/components/elements/Table.js +72 -65
  32. package/src/components/elements/Tabs.js +18 -15
  33. package/src/components/elements/Text.js +19 -14
  34. package/src/components/elements/ToggleFilter.js +28 -25
  35. package/src/components/elements/View.js +36 -18
  36. package/src/components/elements/ViewLink.js +15 -11
  37. package/src/components/elements/utils.js +224 -55
  38. package/src/components/storage.js +27 -129
  39. package/src/hooks/useTranslation.js +11 -0
  40. package/src/index.js +6 -3
@@ -26,10 +26,10 @@ import { Link } from "./elements/Link";
26
26
  import { View } from "./elements/View";
27
27
  import { Page } from "./elements/Page";
28
28
  import { SearchBar } from "./elements/SearchBar";
29
- import { Container } from "./elements/Container";
30
29
  import { DropDownFilter } from "./elements/DropDownFilter";
31
30
  import { ToggleFilter } from "./elements/ToggleFilter";
32
31
  import { DropMenu } from "./elements/DropMenu";
32
+ import { Container } from "./elements/Container";
33
33
  import { rand_ident } from "./elements/utils";
34
34
 
35
35
  /**
@@ -67,11 +67,11 @@ const allElements = [
67
67
  LineBreak,
68
68
  Aggregation,
69
69
  Card,
70
+ Container,
70
71
  Image,
71
72
  Link,
72
73
  View,
73
74
  SearchBar,
74
- Container,
75
75
  DropDownFilter,
76
76
  Tabs,
77
77
  ToggleFilter,
@@ -100,7 +100,6 @@ const layoutToNodes = (
100
100
  options,
101
101
  index = false
102
102
  ) => {
103
- //console.log("layoutToNodes", JSON.stringify(layout));
104
103
  /**
105
104
  * @param {object} segment
106
105
  * @param {string} ix
@@ -109,6 +108,24 @@ const layoutToNodes = (
109
108
  function toTag(segment, ix) {
110
109
  if (!segment) return <Empty key={ix} />;
111
110
 
111
+ if (
112
+ (segment.type === "card" || segment.type === "container") &&
113
+ typeof segment.contents === "string"
114
+ ) {
115
+ segment.contents = {
116
+ type: "blank",
117
+ contents: segment.contents,
118
+ };
119
+ }
120
+
121
+ if (segment.type === "container" && typeof segment.display === "undefined") {
122
+ segment.display = segment.block === true
123
+ ? "block"
124
+ : segment.block === false
125
+ ? "inline-block"
126
+ : "block";
127
+ }
128
+
112
129
  const MatchElement = allElements.find(
113
130
  (e) =>
114
131
  e.craft.related &&
@@ -123,8 +140,10 @@ const layoutToNodes = (
123
140
  const props = {};
124
141
  related.fields.forEach((f) => {
125
142
  if (f.type === "Nodes" && f.nodeID) {
126
- props[f.name || f] = toTag(segment[f.segment_name || f.name || f]);
127
- //).map(toTag);
143
+ const v = segment[f.segment_name || f.name || f];
144
+ if (typeof v !== "undefined") {
145
+ props[f.name || f] = toTag(v);
146
+ }
128
147
  } else {
129
148
  const v = segment[f.segment_name || f.name || f];
130
149
  props[f.name || f] = typeof v === "undefined" ? f.default : v;
@@ -212,72 +231,6 @@ const layoutToNodes = (
212
231
  isFormula={segment.isFormula || {}}
213
232
  />
214
233
  );
215
- } else if (segment.type === "container") {
216
- return (
217
- <Element
218
- key={ix}
219
- custom={segment._custom || {}}
220
- canvas
221
- gradStartColor={segment.gradStartColor}
222
- gradEndColor={segment.gradEndColor}
223
- gradDirection={segment.gradDirection}
224
- rotate={segment.rotate || 0}
225
- animateName={segment.animateName}
226
- animateDuration={segment.animateDuration}
227
- animateDelay={segment.animateDelay}
228
- animateInitialHide={segment.animateInitialHide}
229
- customClass={segment.customClass}
230
- customId={segment.customId}
231
- customCSS={segment.customCSS}
232
- overflow={segment.overflow}
233
- margin={segment.margin || [0, 0, 0, 0]}
234
- padding={segment.padding || [0, 0, 0, 0]}
235
- minHeight={segment.minHeight}
236
- height={segment.height}
237
- width={segment.width}
238
- click_action={segment.click_action}
239
- url={segment.url}
240
- hoverColor={segment.hoverColor}
241
- minHeightUnit={segment.minHeightUnit || "px"}
242
- heightUnit={segment.heightUnit || "px"}
243
- widthUnit={segment.widthUnit || "px"}
244
- vAlign={segment.vAlign}
245
- hAlign={segment.hAlign}
246
- htmlElement={segment.htmlElement || "div"}
247
- display={
248
- segment.display ||
249
- (segment.block === true
250
- ? "block"
251
- : segment.block === false
252
- ? "inline-block"
253
- : "block")
254
- }
255
- fullPageWidth={
256
- typeof segment.fullPageWidth === "undefined"
257
- ? false
258
- : segment.fullPageWidth
259
- }
260
- bgFileId={segment.bgFileId}
261
- bgField={segment.bgField}
262
- imageSize={segment.imageSize || "contain"}
263
- imgResponsiveWidths={segment.imgResponsiveWidths}
264
- bgType={segment.bgType || "None"}
265
- style={segment.style || {}}
266
- transform={segment.transform || {}}
267
- bgColor={segment.bgColor || "#ffffff"}
268
- setTextColor={!!segment.setTextColor}
269
- textColor={segment.textColor || "#000000"}
270
- isFormula={segment.isFormula || {}}
271
- showIfFormula={segment.showIfFormula || ""}
272
- showForRole={segment.showForRole || []}
273
- minScreenWidth={segment.minScreenWidth || ""}
274
- maxScreenWidth={segment.maxScreenWidth || ""}
275
- show_for_owner={!!segment.show_for_owner}
276
- is={Container}
277
- >
278
- {toTag(segment.contents)}
279
- </Element>
280
- );
281
234
  } else if (segment.type === "tabs") {
282
235
  let contentsArray = segment.contents.map(toTag);
283
236
  let contents;
@@ -412,18 +365,14 @@ const layoutToNodes = (
412
365
  if (Array.isArray(tag)) {
413
366
  tag.forEach((t) => {
414
367
  const node = query.parseReactElement(t).toNodeTree();
415
- //console.log("other", node);
416
368
  actions.addNodeTree(node, parent, ix);
417
369
  });
418
370
  } else if (tag) {
419
371
  const node = query.parseReactElement(tag).toNodeTree();
420
- //console.log("other", node);
421
372
  actions.addNodeTree(node, parent, ix);
422
373
  }
423
374
  }
424
375
  }
425
- //const node1 = query.createNode(toTag(layout));
426
- //actions.add(node1, );
427
376
  go(layout, parent, index);
428
377
  };
429
378
 
@@ -440,12 +389,12 @@ export /**
440
389
  * @namespace
441
390
  */
442
391
  const craftToSaltcorn = (nodes, startFrom = "ROOT", options) => {
443
- //console.log(JSON.stringify(nodes, null, 2));
444
392
  var columns = [];
445
393
  /**
446
394
  * @param {object} node
447
395
  * @returns {void|object}
448
396
  */
397
+
449
398
  const removeEmpty = ({ above }) => {
450
399
  const valids = above.filter(Boolean);
451
400
  if (valids.length === 1) return valids[0];
@@ -480,7 +429,6 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT", options) => {
480
429
  if (related.hasContents) s.contents = get_nodes(node);
481
430
  related.fields.forEach((f) => {
482
431
  if (f.type === "Nodes" && f.nodeID) {
483
- //console.log("nodetype", node);
484
432
  s[f.segment_name || f.name || f] = go(
485
433
  nodes[node.linkedNodes[f.nodeID]]
486
434
  );
@@ -525,57 +473,7 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT", options) => {
525
473
  return lc;
526
474
  }
527
475
  if (node.isCanvas) {
528
- if (node.displayName === Container.craft.displayName)
529
- return {
530
- contents: get_nodes(node),
531
- type: "container",
532
- customCSS: node.props.customCSS,
533
- customClass: node.props.customClass,
534
- customId: node.props.customId,
535
- animateName: node.props.animateName,
536
- animateDelay: node.props.animateDelay,
537
- animateDuration: node.props.animateDuration,
538
- animateInitialHide: node.props.animateInitialHide,
539
- minHeight: node.props.minHeight,
540
- height: node.props.height,
541
- width: node.props.width,
542
- url: node.props.url,
543
- hoverColor: node.props.hoverColor,
544
- minHeightUnit: node.props.minHeightUnit,
545
- heightUnit: node.props.heightUnit,
546
- widthUnit: node.props.widthUnit,
547
- vAlign: node.props.vAlign,
548
- hAlign: node.props.hAlign,
549
- htmlElement: node.props.htmlElement,
550
- margin: node.props.margin,
551
- padding: node.props.padding,
552
- overflow: node.props.overflow,
553
- display: node.props.display,
554
- fullPageWidth: node.props.fullPageWidth || false,
555
- bgFileId: node.props.bgFileId,
556
- bgField: node.props.bgField,
557
- bgType: node.props.bgType,
558
- imageSize: node.props.imageSize,
559
- imgResponsiveWidths: node.props.imgResponsiveWidths,
560
- bgColor: node.props.bgColor,
561
- setTextColor: node.props.setTextColor,
562
- textColor: node.props.textColor,
563
- isFormula: node.props.isFormula,
564
- showIfFormula: node.props.showIfFormula,
565
- showForRole: node.props.showForRole,
566
- minScreenWidth: node.props.minScreenWidth,
567
- maxScreenWidth: node.props.maxScreenWidth,
568
- show_for_owner: node.props.show_for_owner,
569
- gradStartColor: node.props.gradStartColor,
570
- gradEndColor: node.props.gradEndColor,
571
- gradDirection: node.props.gradDirection,
572
- click_action: node.props.click_action,
573
- rotate: node.props.rotate,
574
- style: node.props.style,
575
- transform: node.props.transform,
576
- ...customProps,
577
- };
578
- else return get_nodes(node);
476
+ return get_nodes(node);
579
477
  }
580
478
 
581
479
  if (node.displayName === Text.craft.displayName) {
@@ -747,7 +645,7 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT", options) => {
747
645
  };
748
646
  }
749
647
  };
750
- const layout = go(nodes[startFrom]) || { type: "blank", contents: "" };
648
+ const layout = go(nodes[startFrom]) || {};
751
649
  /*console.log("nodes", JSON.stringify(nodes));
752
650
  console.log("cols", JSON.stringify(columns));
753
651
  console.log("layout", JSON.stringify(layout));*/
@@ -0,0 +1,11 @@
1
+ import { useContext } from "react";
2
+ import optionsCtx from "../components/context";
3
+
4
+ const useTranslation = () => {
5
+ const options = useContext(optionsCtx);
6
+ const translations = options.translations || {};
7
+ const t = (phrase) => translations[phrase] || phrase;
8
+ return { t };
9
+ };
10
+
11
+ export default useTranslation;
package/src/index.js CHANGED
@@ -49,8 +49,8 @@
49
49
  */
50
50
 
51
51
  import React from "react";
52
+ import { createRoot } from "react-dom/client";
52
53
  import Builder from "./components/Builder";
53
- import ReactDOM from "react-dom";
54
54
 
55
55
  /**
56
56
  *
@@ -60,13 +60,16 @@ import ReactDOM from "react-dom";
60
60
  * @param {string} mode
61
61
  */
62
62
  function renderBuilder(id, options, layout, mode) {
63
- ReactDOM.render(
63
+ const container = document.getElementById(id);
64
+ if (!container) return;
65
+ const root = container.__scRoot || createRoot(container);
66
+ container.__scRoot = root;
67
+ root.render(
64
68
  <Builder
65
69
  options={JSON.parse(decodeURIComponent(options))}
66
70
  layout={JSON.parse(decodeURIComponent(layout))}
67
71
  mode={mode}
68
72
  />,
69
- document.getElementById(id)
70
73
  );
71
74
  }
72
75