@saltcorn/builder 0.9.3-beta.3 → 0.9.3-beta.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/builder",
3
- "version": "0.9.3-beta.3",
3
+ "version": "0.9.3-beta.5",
4
4
  "description": "Drag and drop view builder for Saltcorn, open-source no-code platform",
5
5
  "main": "index.js",
6
6
  "homepage": "https://saltcorn.com",
@@ -7,6 +7,7 @@
7
7
  import React, { Fragment } from "react";
8
8
  import { Text } from "./Text";
9
9
  import { OrFormula, SettingsRow, Accordion, reactifyStyles } from "./utils";
10
+ import { Column } from "./Column";
10
11
 
11
12
  import { Element, useNode } from "@craftjs/core";
12
13
  import { BoxModelEditor } from "./BoxModelEditor";
@@ -25,7 +26,16 @@ export /**
25
26
  * @subcategory components
26
27
  * @namespace
27
28
  */
28
- const Card = ({ children, isFormula, title, shadow, noPadding, style }) => {
29
+ const Card = ({
30
+ children,
31
+ isFormula,
32
+ title,
33
+ shadow,
34
+ noPadding,
35
+ style,
36
+ footer,
37
+ hasFooter,
38
+ }) => {
29
39
  const {
30
40
  selected,
31
41
  connectors: { connect, drag },
@@ -51,6 +61,13 @@ const Card = ({ children, isFormula, title, shadow, noPadding, style }) => {
51
61
  <div className={`card-body ${noPadding ? "p-0" : ""}`}>
52
62
  <div className="canvas">{children}</div>
53
63
  </div>
64
+ {hasFooter ? (
65
+ <div className={`card-footer ${noPadding ? "p-0" : ""}`}>
66
+ <Element canvas id={`cardfooter`} is={Column}>
67
+ {footer}
68
+ </Element>
69
+ </div>
70
+ ) : null}
54
71
  </div>
55
72
  );
56
73
  };
@@ -109,6 +126,11 @@ const CardSettings = () => {
109
126
  node={node}
110
127
  setProp={setProp}
111
128
  />
129
+ <SettingsRow
130
+ field={{ label: "Card footer", name: "hasFooter", type: "Bool" }}
131
+ node={node}
132
+ setProp={setProp}
133
+ />
112
134
  <SettingsRow
113
135
  field={{ label: "Shadow", name: "shadow", type: "Bool" }}
114
136
  node={node}
@@ -147,8 +169,10 @@ const fields = [
147
169
  { label: "URL", name: "url", type: "String", canBeFormula: true },
148
170
  { label: "Class", name: "class", type: "String", canBeFormula: true },
149
171
  { label: "Shadow", name: "shadow", type: "Bool" },
172
+ { label: "Card footer", name: "hasFooter", type: "Bool" },
150
173
  { label: "Save indicator", name: "titleAjaxIndicator", type: "Bool" },
151
174
  { label: "No padding", name: "noPadding", type: "Bool" },
175
+ { label: "Footer", name: "footer", type: "Nodes", nodeID: "cardfooter" },
152
176
  { name: "style", default: {} },
153
177
  ];
154
178
 
@@ -163,6 +187,7 @@ Card.craft = {
163
187
  shadow: true,
164
188
  isFormula: {},
165
189
  style: {},
190
+ footer: [],
166
191
  },
167
192
  displayName: "Card",
168
193
  related: {
@@ -173,6 +173,9 @@ const LinkSettings = () => {
173
173
  ["page", "filter"].includes(options.mode) && (
174
174
  <option>View</option>
175
175
  )}
176
+ {(options.page_groups || []).length > 0 && (
177
+ <option>Page Group</option>
178
+ )}
176
179
  </select>
177
180
  </td>
178
181
  </tr>
@@ -214,6 +217,27 @@ const LinkSettings = () => {
214
217
  </td>
215
218
  </tr>
216
219
  )}
220
+ {link_src === "Page Group" && (
221
+ <tr>
222
+ <td>
223
+ <label>Page Group</label>
224
+ </td>
225
+ <td>
226
+ <select
227
+ value={url}
228
+ className="form-control form-select"
229
+ onChange={setAProp("url")}
230
+ >
231
+ <option></option>
232
+ {(options.page_groups || []).map((p, ix) => (
233
+ <option key={ix} value={`/page/${p.name}`}>
234
+ {p.name}
235
+ </option>
236
+ ))}
237
+ </select>
238
+ </td>
239
+ </tr>
240
+ )}
217
241
  {link_src === "View" && (
218
242
  <tr>
219
243
  <td>
@@ -111,8 +111,13 @@ const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
111
111
  const related = MatchElement.craft.related;
112
112
  const props = {};
113
113
  related.fields.forEach((f) => {
114
- const v = segment[f.segment_name || f.name || f];
115
- props[f.name || f] = typeof v === "undefined" ? f.default : v;
114
+ if (f.type === "Nodes" && f.nodeID) {
115
+ props[f.name || f] = toTag(segment[f.segment_name || f.name || f]);
116
+ //).map(toTag);
117
+ } else {
118
+ const v = segment[f.segment_name || f.name || f];
119
+ props[f.name || f] = typeof v === "undefined" ? f.default : v;
120
+ }
116
121
  });
117
122
  if (related.fields.some((f) => f.canBeFormula))
118
123
  props.isFormula = segment.isFormula;
@@ -360,15 +365,20 @@ export /**
360
365
  const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
361
366
  //console.log(JSON.stringify(nodes, null, 2));
362
367
  var columns = [];
363
-
364
368
  /**
365
369
  * @param {object} node
366
370
  * @returns {void|object}
367
371
  */
372
+ const removeEmpty = ({ above }) => {
373
+ const valids = above.filter(Boolean);
374
+ if (valids.length === 1) return valids[0];
375
+ else return { above: valids };
376
+ };
377
+
368
378
  const get_nodes = (node) => {
369
379
  if (!node.nodes || node.nodes.length == 0) return;
370
380
  else if (node.nodes.length == 1) return go(nodes[node.nodes[0]]);
371
- else return { above: node.nodes.map((nm) => go(nodes[nm])) };
381
+ else return removeEmpty({ above: node.nodes.map((nm) => go(nodes[nm])) });
372
382
  };
373
383
 
374
384
  /**
@@ -389,7 +399,12 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
389
399
  const s = { type: related.segment_type };
390
400
  if (related.hasContents) s.contents = get_nodes(node);
391
401
  related.fields.forEach((f) => {
392
- s[f.segment_name || f.name || f] = node.props[f.name || f];
402
+ if (f.type === "Nodes" && f.nodeID) {
403
+ //console.log("nodetype", node);
404
+ s[f.segment_name || f.name || f] = go(
405
+ nodes[node.linkedNodes[f.nodeID]]
406
+ );
407
+ } else s[f.segment_name || f.name || f] = node.props[f.name || f];
393
408
  });
394
409
  if (related.fields.some((f) => f.canBeFormula))
395
410
  s.isFormula = node.props.isFormula;
@@ -596,6 +611,6 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
596
611
  const layout = go(nodes[startFrom]) || { type: "blank", contents: "" };
597
612
  /*console.log("nodes", JSON.stringify(nodes));
598
613
  console.log("cols", JSON.stringify(columns));
599
- console.log("layout", JSON.stringify(layout));*/
614
+ console.log("layout", JSON.stringify(layout));*/
600
615
  return { columns, layout };
601
616
  };