@saltcorn/builder 1.6.0-alpha.12 → 1.6.0-alpha.13
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/dist/builder_bundle.js +4 -4
- package/package.json +2 -2
- package/src/components/Builder.js +121 -9
- package/src/components/Toolbox.js +78 -1
- package/src/components/elements/BoxModelEditor.js +24 -23
- package/src/components/elements/Card.js +26 -1
- package/src/components/elements/Columns.js +51 -10
- package/src/components/elements/Container.js +27 -5
- package/src/components/elements/Prompt.js +285 -0
- package/src/components/elements/Text.js +58 -14
- package/src/components/elements/utils.js +3 -1
- package/src/components/storage.js +24 -0
- package/src/utils/responsive_utils.js +139 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the active alignment value for the current preview device.
|
|
3
|
+
* Used in the builder to show the correct alignment per device.
|
|
4
|
+
*
|
|
5
|
+
* @param {string[]} aligns - Desktop alignment array (per column)
|
|
6
|
+
* @param {string[]} mobileAligns - Mobile alignment array (per column)
|
|
7
|
+
* @param {string[]} tabletAligns - Tablet alignment array (per column)
|
|
8
|
+
* @param {number} ix - Column index
|
|
9
|
+
* @param {string} previewDevice - Current preview device ("desktop"|"tablet"|"mobile")
|
|
10
|
+
* @returns {string} CSS class like "text-start" or ""
|
|
11
|
+
*/
|
|
12
|
+
export const getAlignClass = (aligns, mobileAligns, tabletAligns, ix, previewDevice) => {
|
|
13
|
+
const desktop = aligns?.[ix];
|
|
14
|
+
const tablet = tabletAligns?.[ix];
|
|
15
|
+
const mobile = mobileAligns?.[ix];
|
|
16
|
+
|
|
17
|
+
if (previewDevice === "mobile" && mobile) return `text-${mobile}`;
|
|
18
|
+
if (previewDevice === "tablet" && tablet) return `text-${tablet}`;
|
|
19
|
+
if (desktop) return `text-${desktop}`;
|
|
20
|
+
return "";
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Generate Bootstrap responsive text alignment classes for runtime rendering.
|
|
25
|
+
* Uses mobile-first approach: base class for smallest, then breakpoint overrides.
|
|
26
|
+
*
|
|
27
|
+
* @param {string[]} aligns - Desktop alignment array (per column)
|
|
28
|
+
* @param {string[]} mobileAligns - Mobile alignment array (per column)
|
|
29
|
+
* @param {string[]} tabletAligns - Tablet alignment array (per column)
|
|
30
|
+
* @param {number} ix - Column index
|
|
31
|
+
* @returns {string} Space-separated CSS classes like "text-start text-md-center text-lg-end"
|
|
32
|
+
*/
|
|
33
|
+
export const getAlignClassRuntime = (aligns, mobileAligns, tabletAligns, ix) => {
|
|
34
|
+
const desktop = aligns?.[ix];
|
|
35
|
+
const tablet = tabletAligns?.[ix];
|
|
36
|
+
const mobile = mobileAligns?.[ix];
|
|
37
|
+
|
|
38
|
+
if (!mobile && !tablet) {
|
|
39
|
+
return desktop ? `text-${desktop}` : "";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const classes = [];
|
|
43
|
+
|
|
44
|
+
const base = mobile || desktop;
|
|
45
|
+
if (base) classes.push(`text-${base}`);
|
|
46
|
+
if (tablet && tablet !== base) classes.push(`text-md-${tablet}`);
|
|
47
|
+
if (desktop && desktop !== (tablet || base))
|
|
48
|
+
classes.push(`text-lg-${desktop}`);
|
|
49
|
+
return classes.join(" ");
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get the active value for a per-device setting based on the preview device.
|
|
54
|
+
* Generic helper for any setting that supports per-device overrides.
|
|
55
|
+
*
|
|
56
|
+
* @param {*} desktopValue - Desktop value
|
|
57
|
+
* @param {*} tabletValue - Tablet override (optional)
|
|
58
|
+
* @param {*} mobileValue - Mobile override (optional)
|
|
59
|
+
* @param {string} previewDevice - Current preview device
|
|
60
|
+
* @returns {*} The active value for the current device
|
|
61
|
+
*/
|
|
62
|
+
export const getDeviceValue = (desktopValue, tabletValue, mobileValue, previewDevice) => {
|
|
63
|
+
if (previewDevice === "mobile" && mobileValue != null) return mobileValue;
|
|
64
|
+
if (previewDevice === "tablet" && tabletValue != null) return tabletValue;
|
|
65
|
+
return desktopValue;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the device-specific property name for a given base property.
|
|
70
|
+
* E.g. getDevicePropName("width", "mobile") => "mobileWidth"
|
|
71
|
+
*
|
|
72
|
+
* @param {string} propName - Base property name (e.g. "width", "height")
|
|
73
|
+
* @param {string} previewDevice - Current preview device ("mobile"|"tablet")
|
|
74
|
+
* @returns {string} Device-specific property name
|
|
75
|
+
*/
|
|
76
|
+
export const getDevicePropName = (propName, previewDevice) => {
|
|
77
|
+
const cap = propName.charAt(0).toUpperCase() + propName.slice(1);
|
|
78
|
+
return previewDevice === "mobile" ? `mobile${cap}` : `tablet${cap}`;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create a proxied node object that reads width/height from device-specific props
|
|
83
|
+
* as if they were in the style object. Used by BoxModelEditor for per-device size editing.
|
|
84
|
+
*
|
|
85
|
+
* @param {object} node - The Craft.js node props
|
|
86
|
+
* @param {string} propName - "width" or "height"
|
|
87
|
+
* @param {string} previewDevice - Current preview device
|
|
88
|
+
* @returns {object} Proxied node with device value in style[propName]
|
|
89
|
+
*/
|
|
90
|
+
export const getDeviceSizeNode = (node, propName, previewDevice) => {
|
|
91
|
+
const deviceProp = getDevicePropName(propName, previewDevice);
|
|
92
|
+
return {
|
|
93
|
+
...node,
|
|
94
|
+
style: { ...(node.style || {}), [propName]: node[deviceProp] || "" },
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create a proxied setProp function that writes to device-specific props
|
|
100
|
+
* instead of the style object. Used by BoxModelEditor for per-device size editing.
|
|
101
|
+
*
|
|
102
|
+
* @param {function} setProp - The Craft.js setProp function
|
|
103
|
+
* @param {string} propName - "width" or "height"
|
|
104
|
+
* @param {string} previewDevice - Current preview device
|
|
105
|
+
* @returns {function} Proxied setProp that intercepts style writes
|
|
106
|
+
*/
|
|
107
|
+
export const getDeviceSizeSetProp = (setProp, propName, previewDevice) => {
|
|
108
|
+
const deviceProp = getDevicePropName(propName, previewDevice);
|
|
109
|
+
return (fn) => {
|
|
110
|
+
const proxy = { style: {} };
|
|
111
|
+
fn(proxy);
|
|
112
|
+
const val = proxy.style[propName];
|
|
113
|
+
if (val !== undefined) {
|
|
114
|
+
setProp((prop) => { prop[deviceProp] = val; });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get the display value for width/height in the box model visual,
|
|
121
|
+
* taking into account the current preview device and sizeWithStyle mode.
|
|
122
|
+
*
|
|
123
|
+
* @param {object} node - The Craft.js node props
|
|
124
|
+
* @param {string} propName - "width" or "height"
|
|
125
|
+
* @param {string} previewDevice - Current preview device
|
|
126
|
+
* @param {boolean} sizeWithStyle - Whether size is stored in style object
|
|
127
|
+
* @returns {string} Display value like "200px" or ""
|
|
128
|
+
*/
|
|
129
|
+
export const getDisplaySize = (node, propName, previewDevice, sizeWithStyle) => {
|
|
130
|
+
const isDesktop = !previewDevice || previewDevice === "desktop";
|
|
131
|
+
if (!isDesktop) {
|
|
132
|
+
const deviceProp = getDevicePropName(propName, previewDevice);
|
|
133
|
+
if (node[deviceProp]) return node[deviceProp];
|
|
134
|
+
}
|
|
135
|
+
if (sizeWithStyle) return (node.style || {})[propName];
|
|
136
|
+
const val = node[propName];
|
|
137
|
+
const unit = node[propName + "Unit"];
|
|
138
|
+
return val ? `${val}${unit || "px"}` : "";
|
|
139
|
+
};
|