@saltcorn/builder 0.6.3 → 0.6.4-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/builder",
3
- "version": "0.6.3",
3
+ "version": "0.6.4-beta.1",
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",
@@ -15,32 +15,33 @@
15
15
  "author": "Tom Nielsen",
16
16
  "license": "MIT",
17
17
  "devDependencies": {
18
- "@babel/core": "^7.9.6",
19
- "@babel/preset-env": "^7.9.6",
20
- "@babel/preset-react": "^7.9.4",
18
+ "@babel/core": "7.9.6",
19
+ "@babel/preset-env": "7.9.6",
20
+ "@babel/preset-react": "7.9.4",
21
21
  "@craftjs/core": "0.1.0-beta.20",
22
+ "@craftjs/utils": "0.1.0-beta.20",
22
23
  "saltcorn-craft-layers-noeye": "0.1.0-beta.22",
23
- "@fonticonpicker/react-fonticonpicker": "^1.2.0",
24
- "@fortawesome/fontawesome-svg-core": "^1.2.34",
25
- "@fortawesome/free-regular-svg-icons": "^5.15.2",
26
- "@fortawesome/free-solid-svg-icons": "^5.15.2",
27
- "@fortawesome/react-fontawesome": "^0.1.14",
28
- "babel-loader": "^8.1.0",
29
- "ckeditor4-react": "^1.4.0",
30
- "classnames": "^2.2.6",
31
- "prop-types": "^15.7.2",
32
- "react": "^16.13.1",
33
- "react-bootstrap-icons": "^1.5.0",
34
- "react-contenteditable": "^3.3.5",
35
- "react-dom": "^16.13.1",
36
- "react-transition-group": "^4.4.1",
37
- "webpack": "^4.43.0",
38
- "webpack-cli": "^3.3.11"
24
+ "@fonticonpicker/react-fonticonpicker": "1.2.0",
25
+ "@fortawesome/fontawesome-svg-core": "1.2.34",
26
+ "@fortawesome/free-regular-svg-icons": "5.15.2",
27
+ "@fortawesome/free-solid-svg-icons": "5.15.2",
28
+ "@fortawesome/react-fontawesome": "0.1.14",
29
+ "babel-loader": "8.1.0",
30
+ "ckeditor4-react": "1.4.2",
31
+ "classnames": "2.2.6",
32
+ "prop-types": "15.7.2",
33
+ "react": "16.13.1",
34
+ "react-bootstrap-icons": "1.5.0",
35
+ "react-contenteditable": "3.3.5",
36
+ "react-dom": "16.13.1",
37
+ "react-transition-group": "4.4.1",
38
+ "webpack": "4.43.0",
39
+ "webpack-cli": "3.3.11"
39
40
  },
40
41
  "publishConfig": {
41
42
  "access": "public"
42
43
  },
43
44
  "dependencies": {
44
- "styled-components": "^4.4.1"
45
+ "styled-components": "4.4.1"
45
46
  }
46
47
  }
@@ -10,10 +10,11 @@ import optionsCtx from "../context";
10
10
  import previewCtx from "../preview_context";
11
11
  import {
12
12
  blockProps,
13
- BlockSetting,
13
+ BlockOrInlineSetting,
14
14
  TextStyleRow,
15
15
  ConfigForm,
16
16
  setInitialConfig,
17
+ isBlock,
17
18
  fetchFieldPreview,
18
19
  } from "./utils";
19
20
 
@@ -27,9 +28,16 @@ export /**
27
28
  * @returns {div}
28
29
  * @category saltcorn-builder
29
30
  * @subcategory components
30
- * @namespace
31
+ * @namespace
31
32
  */
32
- const Field = ({ name, fieldview, block, textStyle, configuration }) => {
33
+ const Field = ({
34
+ name,
35
+ fieldview,
36
+ block,
37
+ inline,
38
+ textStyle,
39
+ configuration,
40
+ }) => {
33
41
  const {
34
42
  selected,
35
43
  node_id,
@@ -52,7 +60,7 @@ const Field = ({ name, fieldview, block, textStyle, configuration }) => {
52
60
  return (
53
61
  <div
54
62
  className={`${textStyle} ${selected ? "selected-node" : ""} ${
55
- block ? "" : "d-inline-block"
63
+ isBlock(block, inline, textStyle) ? "d-block" : "d-inline-block"
56
64
  }`}
57
65
  ref={(dom) => connect(drag(dom))}
58
66
  >
@@ -80,6 +88,7 @@ const FieldSettings = () => {
80
88
  name,
81
89
  fieldview,
82
90
  block,
91
+ inline,
83
92
  configuration,
84
93
  node_id,
85
94
  textStyle,
@@ -87,6 +96,7 @@ const FieldSettings = () => {
87
96
  name: node.data.props.name,
88
97
  fieldview: node.data.props.fieldview,
89
98
  block: node.data.props.block,
99
+ inline: node.data.props.inline,
90
100
  textStyle: node.data.props.textStyle,
91
101
  configuration: node.data.props.configuration,
92
102
  node_id: node.id,
@@ -177,7 +187,12 @@ const FieldSettings = () => {
177
187
  <tr>
178
188
  <td></td>
179
189
  <td>
180
- <BlockSetting block={block} setProp={setProp} />
190
+ <BlockOrInlineSetting
191
+ block={block}
192
+ inline={inline}
193
+ textStyle={textStyle}
194
+ setProp={setProp}
195
+ />
181
196
  </td>
182
197
  </tr>
183
198
  {!(handlesTextStyle && handlesTextStyle.includes(fieldview)) && (
@@ -197,8 +212,8 @@ const FieldSettings = () => {
197
212
  );
198
213
  };
199
214
 
200
- /**
201
- * @type {object}
215
+ /**
216
+ * @type {object}
202
217
  */
203
218
  Field.craft = {
204
219
  displayName: "Field",
@@ -211,6 +226,7 @@ Field.craft = {
211
226
  "fieldview",
212
227
  "textStyle",
213
228
  "block",
229
+ "inline",
214
230
  { name: "configuration", default: {} },
215
231
  ],
216
232
  },
@@ -8,12 +8,13 @@ import React, { useState, useContext, useEffect, Fragment } from "react";
8
8
  import { useNode } from "@craftjs/core";
9
9
  import {
10
10
  blockProps,
11
- BlockSetting,
11
+ BlockOrInlineSetting,
12
12
  TextStyleSetting,
13
13
  OrFormula,
14
14
  ErrorBoundary,
15
15
  TextStyleRow,
16
16
  DynamicFontAwesomeIcon,
17
+ isBlock,
17
18
  } from "./utils";
18
19
  import ContentEditable from "react-contenteditable";
19
20
  import optionsCtx from "../context";
@@ -53,7 +54,7 @@ const ckConfig = {
53
54
  };
54
55
 
55
56
  /**
56
- * @param {string} str
57
+ * @param {string} str
57
58
  * @returns {string}
58
59
  */
59
60
  function escape_tags(str) {
@@ -73,7 +74,7 @@ export /**
73
74
  * @category saltcorn-builder
74
75
  * @subcategory components
75
76
  */
76
- const Text = ({ text, block, isFormula, textStyle, icon, font }) => {
77
+ const Text = ({ text, block, inline, isFormula, textStyle, icon, font }) => {
77
78
  const {
78
79
  connectors: { connect, drag },
79
80
  selected,
@@ -89,10 +90,11 @@ const Text = ({ text, block, isFormula, textStyle, icon, font }) => {
89
90
  }, [selected]);
90
91
  return (
91
92
  <div
92
- className={`${!block ? "d-inline-block" : ""} ${textStyle} is-text ${
93
- isFormula.text ? "text-monospace" : ""
94
- } ${selected ? "selected-node" : ""}`}
95
- {...blockProps(block)}
93
+ className={`${
94
+ isBlock(block, inline, textStyle) ? "d-block" : "d-inline-block"
95
+ } ${textStyle} is-text ${isFormula.text ? "text-monospace" : ""} ${
96
+ selected ? "selected-node" : ""
97
+ }`}
96
98
  ref={(dom) => connect(drag(dom))}
97
99
  onClick={(e) => selected && setEditable(true)}
98
100
  style={font ? { fontFamily: font } : {}}
@@ -133,11 +135,12 @@ export /**
133
135
  * @namespace
134
136
  * @category saltcorn-builder
135
137
  * @subcategory components
136
- */
138
+ */
137
139
  const TextSettings = () => {
138
140
  const node = useNode((node) => ({
139
141
  text: node.data.props.text,
140
142
  block: node.data.props.block,
143
+ inline: node.data.props.inline,
141
144
  isFormula: node.data.props.isFormula,
142
145
  textStyle: node.data.props.textStyle,
143
146
  labelFor: node.data.props.labelFor,
@@ -148,6 +151,7 @@ const TextSettings = () => {
148
151
  actions: { setProp },
149
152
  text,
150
153
  block,
154
+ inline,
151
155
  textStyle,
152
156
  isFormula,
153
157
  labelFor,
@@ -246,7 +250,12 @@ const TextSettings = () => {
246
250
  </tr>
247
251
  </tbody>
248
252
  </table>
249
- <BlockSetting block={block} setProp={setProp} />
253
+ <BlockOrInlineSetting
254
+ block={block}
255
+ inline={inline}
256
+ textStyle={textStyle}
257
+ setProp={setProp}
258
+ />
250
259
  </div>
251
260
  );
252
261
  };
@@ -258,6 +267,7 @@ Text.craft = {
258
267
  defaultProps: {
259
268
  text: "Click here",
260
269
  block: false,
270
+ inline: false,
261
271
  isFormula: {},
262
272
  textStyle: "",
263
273
  labelFor: "",
@@ -55,6 +55,27 @@ const BlockSetting = ({ block, setProp }) => (
55
55
  </div>
56
56
  );
57
57
 
58
+ export const BlockOrInlineSetting = ({ block, inline, textStyle, setProp }) =>
59
+ !textStyle || !textStyle.startsWith("h") ? (
60
+ <BlockSetting block={block} setProp={setProp} />
61
+ ) : (
62
+ <div className="form-check">
63
+ <input
64
+ className="form-check-input"
65
+ name="inline"
66
+ type="checkbox"
67
+ checked={inline}
68
+ onChange={(e) => {
69
+ if (e.target) {
70
+ const target_value = e.target.checked;
71
+ setProp((prop) => (prop.inline = target_value));
72
+ }
73
+ }}
74
+ />
75
+ <label className="form-check-label">Inline display</label>
76
+ </div>
77
+ );
78
+
58
79
  export /**
59
80
  * @param {object} props
60
81
  * @param {function} props.setProp
@@ -1168,3 +1189,6 @@ export const recursivelyCloneToElems = (query) => (nodeId, ix) => {
1168
1189
  children
1169
1190
  );
1170
1191
  };
1192
+
1193
+ export const isBlock = (block, inline, textStyle) =>
1194
+ !textStyle || !textStyle.startsWith("h") ? block : !inline;
@@ -125,6 +125,7 @@ const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
125
125
  text={segment.contents}
126
126
  isFormula={segment.isFormula || {}}
127
127
  block={segment.block || false}
128
+ inline={segment.inline || false}
128
129
  textStyle={segment.textStyle || ""}
129
130
  labelFor={segment.labelFor || ""}
130
131
  icon={segment.icon}
@@ -387,6 +388,7 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
387
388
  type: "blank",
388
389
  contents: node.props.text,
389
390
  block: node.props.block,
391
+ inline: node.props.inline,
390
392
  textStyle: node.props.textStyle,
391
393
  isFormula: node.props.isFormula,
392
394
  labelFor: node.props.labelFor,