@simple-builder/react 1.3.1 → 1.3.2
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/build-container-client-5QC5KVS3.mjs +8 -0
- package/dist/build-container-client-7Z6WZVBX.js +2291 -0
- package/dist/build-container-client-DWKVE65B.mjs +2258 -0
- package/dist/build-container-client-FN3PZMM7.mjs +2253 -0
- package/dist/build-container-client-GV52F5RP.js +2294 -0
- package/dist/build-container-client-J56NWFBF.mjs +2257 -0
- package/dist/build-container-client-L3WD4CG7.mjs +2255 -0
- package/dist/build-container-client-NXIMV3RF.js +8 -0
- package/dist/build-container-client-THZHNQ5S.mjs +2260 -0
- package/dist/build-container-client-WGVIYK47.css +1968 -0
- package/dist/build-container-client-WHIUDBOZ.mjs +2259 -0
- package/dist/build-container-client-WIGFVNOW.css +1971 -0
- package/dist/build-container-client-WYIHRPSW.js +2295 -0
- package/dist/build-container-client-XOHYMPBB.js +2289 -0
- package/dist/build-container-client-YDRPPWCU.js +2293 -0
- package/dist/build-container-client-YWNDWXO2.css +1967 -0
- package/dist/build-container-client-ZXO66OL5.js +2296 -0
- package/dist/builder-content-2MA6BKJ5.js +42 -0
- package/dist/builder-content-2ZXIEMS3.js +42 -0
- package/dist/builder-content-73ZKCEIT.mjs +20 -0
- package/dist/builder-content-BKE4JZ75.js +42 -0
- package/dist/builder-content-BU4BXER7.mjs +20 -0
- package/dist/builder-content-CP5VLMVD.mjs +20 -0
- package/dist/builder-content-CY43LFAA.js +42 -0
- package/dist/builder-content-FMTTH7R2.js +42 -0
- package/dist/builder-content-GJ4HYIOA.mjs +20 -0
- package/dist/builder-content-HQXSXBFZ.mjs +20 -0
- package/dist/builder-content-MI55X5HA.css +1971 -0
- package/dist/builder-content-PWV6LNFT.mjs +20 -0
- package/dist/builder-content-RROSPBT4.css +1968 -0
- package/dist/builder-content-RV3DPWFH.js +42 -0
- package/dist/builder-content-V2MDRHJI.css +1967 -0
- package/dist/chunk-2GOYHVMW.mjs +123 -0
- package/dist/chunk-2OHBCAZQ.mjs +244 -0
- package/dist/chunk-2OYBZSJQ.mjs +123 -0
- package/dist/chunk-3QWMKMTN.js +269 -0
- package/dist/chunk-454D7NIH.js +153 -0
- package/dist/chunk-4TVSMCQU.js +42 -0
- package/dist/chunk-5Q4KJW4A.mjs +20 -0
- package/dist/chunk-6GCMYFBT.mjs +20 -0
- package/dist/chunk-6KNCX5O5.mjs +123 -0
- package/dist/chunk-6VINC5E2.mjs +244 -0
- package/dist/chunk-C5GHD62W.mjs +20 -0
- package/dist/chunk-CARNMQP6.mjs +20 -0
- package/dist/chunk-CJNSRJNF.js +42 -0
- package/dist/chunk-DZLUIOVD.js +153 -0
- package/dist/chunk-EVMN5SX2.js +269 -0
- package/dist/chunk-EZFQOJHG.mjs +244 -0
- package/dist/chunk-H357GPTV.mjs +244 -0
- package/dist/chunk-H6OM2V2U.mjs +20 -0
- package/dist/chunk-HCM5NR6G.js +269 -0
- package/dist/chunk-IQX5LONG.js +153 -0
- package/dist/chunk-MBISMJDL.js +269 -0
- package/dist/chunk-NDE4WSBA.js +269 -0
- package/dist/chunk-OWZPAOR6.mjs +244 -0
- package/dist/chunk-PADTJYXB.mjs +20 -0
- package/dist/chunk-QZQRUNAY.js +153 -0
- package/dist/chunk-RZFAIM2Q.mjs +123 -0
- package/dist/chunk-SFYJAJOD.js +42 -0
- package/dist/chunk-SLWJHIVH.mjs +123 -0
- package/dist/chunk-TMDKQB2L.js +153 -0
- package/dist/chunk-VCXFPTGD.js +42 -0
- package/dist/chunk-VNNNLYSW.js +42 -0
- package/dist/chunk-WA7TKN6M.js +42 -0
- package/dist/chunk-WPBR7BJZ.js +269 -0
- package/dist/chunk-X5A4S44V.mjs +244 -0
- package/dist/chunk-XZNO7DXS.js +153 -0
- package/dist/chunk-ZZT7HGAM.mjs +123 -0
- package/dist/index.css +3 -0
- package/dist/index.js +6 -6
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React3 from 'react';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import NextImage from 'next/image';
|
|
4
|
+
import { clsx } from 'clsx';
|
|
5
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
6
|
+
import { createTV } from 'tailwind-variants';
|
|
7
|
+
|
|
8
|
+
// src/lib/builder.ts
|
|
9
|
+
var builder = /* @__PURE__ */ (() => {
|
|
10
|
+
const components = [];
|
|
11
|
+
return {
|
|
12
|
+
register: (component, config) => {
|
|
13
|
+
if (components.find(({ name }) => name === config.name)) {
|
|
14
|
+
console.log(
|
|
15
|
+
`[simple-builder]: Component ${config.name} already registered.`
|
|
16
|
+
);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
components.push({
|
|
20
|
+
component,
|
|
21
|
+
...config
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
getComponents: () => components,
|
|
25
|
+
getComponent: (name) => {
|
|
26
|
+
return components.find((c) => c.name === name);
|
|
27
|
+
},
|
|
28
|
+
bindComponent: ({ content, ...block }, edit) => {
|
|
29
|
+
const component = components.find(({ name }) => name === block.component);
|
|
30
|
+
if (!component) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`[simple-builder]: Component ${block.component} not found`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const Element = createElement(component.component, {
|
|
36
|
+
key: block.id,
|
|
37
|
+
builder: { id: block.id, content, edit },
|
|
38
|
+
...block.props
|
|
39
|
+
});
|
|
40
|
+
return Element;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
var Image = (props) => {
|
|
45
|
+
if (typeof NextImage !== "undefined") {
|
|
46
|
+
return /* @__PURE__ */ React3.createElement(NextImage, { ...props });
|
|
47
|
+
}
|
|
48
|
+
return /* @__PURE__ */ React3.createElement("img", { ...props });
|
|
49
|
+
};
|
|
50
|
+
var twMerge = extendTailwindMerge({
|
|
51
|
+
prefix: "sb-"
|
|
52
|
+
});
|
|
53
|
+
function cn(...inputs) {
|
|
54
|
+
return twMerge(clsx(inputs));
|
|
55
|
+
}
|
|
56
|
+
var tv = createTV({
|
|
57
|
+
twMergeConfig: {
|
|
58
|
+
prefix: "sb-"
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
var insertAt = (items, index, item) => {
|
|
62
|
+
return Array.isArray(items) ? [...items.slice(0, index), item, ...items.slice(index)] : [item];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/components/design-wrapper.tsx
|
|
66
|
+
var DesignWrapper = (props) => {
|
|
67
|
+
const { children, className, building = false } = props;
|
|
68
|
+
const { background } = props.styles?.desktop ?? {};
|
|
69
|
+
const matches = typeof background === "string" ? background.match(/url\(["']?(.*?)["']?\)/) : void 0;
|
|
70
|
+
const src = matches ? matches[1] : void 0;
|
|
71
|
+
const desktopStyles = props.styles?.desktop ?? {};
|
|
72
|
+
const mobileStyles = props.styles?.mobile ?? {};
|
|
73
|
+
const container = props.styles?.container ?? true;
|
|
74
|
+
const hidden = props.styles?.hidden ?? "never";
|
|
75
|
+
const id = React3.useId().replace(/[^a-zA-Z0-9]/g, "");
|
|
76
|
+
let hiddenClass = "";
|
|
77
|
+
switch (hidden) {
|
|
78
|
+
case "always":
|
|
79
|
+
hiddenClass = building ? "sb:opacity-30" : "sb:hidden";
|
|
80
|
+
break;
|
|
81
|
+
case "mobile":
|
|
82
|
+
hiddenClass = building ? "sb:max-md:opacity-30" : "sb:max-md:hidden";
|
|
83
|
+
break;
|
|
84
|
+
case "desktop":
|
|
85
|
+
hiddenClass = building ? "sb:md:opacity-30" : "sb:md:hidden";
|
|
86
|
+
break;
|
|
87
|
+
case "never":
|
|
88
|
+
hiddenClass = "";
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
return /* @__PURE__ */ React3.createElement("div", { id, className: cn("sb:relative", className, hiddenClass) }, src && /* @__PURE__ */ React3.createElement(
|
|
92
|
+
Image,
|
|
93
|
+
{
|
|
94
|
+
src,
|
|
95
|
+
alt: "",
|
|
96
|
+
fill: true,
|
|
97
|
+
className: "sb:object-cover sb:absolute sb:inset-0 sb:pointer-events-none sb:-z-1"
|
|
98
|
+
}
|
|
99
|
+
), container ? /* @__PURE__ */ React3.createElement("div", { className: "container sb:mx-auto" }, children) : children, /* @__PURE__ */ React3.createElement("style", null, `
|
|
100
|
+
#${id} {
|
|
101
|
+
${Object.entries(desktopStyles).filter(([key]) => !(key === "background" && src)).map(([key, value]) => `${key}: ${value};`).join(" ")}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@media (max-width: 1024px) {
|
|
105
|
+
#${id} {
|
|
106
|
+
${Object.entries(mobileStyles).filter(([key]) => !(key === "background" && src)).map(([key, value]) => `${key}: ${value}; `).join(" ")}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
`.replace(/\s\s+/g, " ")));
|
|
110
|
+
};
|
|
111
|
+
var BuildContainerInner = React3.lazy(
|
|
112
|
+
() => import('./build-container-client-DWKVE65B.mjs')
|
|
113
|
+
);
|
|
114
|
+
var BuildContainer = (props) => {
|
|
115
|
+
const { content, edit, name } = props;
|
|
116
|
+
const items = Array.isArray(content) ? content : content?.[name] || [];
|
|
117
|
+
if (!edit) {
|
|
118
|
+
return items.map((item) => /* @__PURE__ */ React3.createElement(DesignWrapper, { styles: item.styles }, builder.bindComponent(item, true)));
|
|
119
|
+
}
|
|
120
|
+
return /* @__PURE__ */ React3.createElement(React3.Suspense, { fallback: /* @__PURE__ */ React3.createElement("div", null, "Loading...") }, /* @__PURE__ */ React3.createElement(BuildContainerInner, { ...props }));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export { BuildContainer, DesignWrapper, Image, builder, cn, insertAt, tv };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { cn, builder, insertAt } from './chunk-ZZT7HGAM.mjs';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
4
|
+
import { cva } from 'class-variance-authority';
|
|
5
|
+
|
|
6
|
+
var BuilderContext = React.createContext(
|
|
7
|
+
null
|
|
8
|
+
);
|
|
9
|
+
var BuilderProvider = (props) => {
|
|
10
|
+
const url = props.url ?? "/api/simple-builder";
|
|
11
|
+
const [content, setContent] = React.useState(
|
|
12
|
+
props.content ?? []
|
|
13
|
+
);
|
|
14
|
+
const getItem = React.useCallback(
|
|
15
|
+
(id) => {
|
|
16
|
+
return findRecursive(content, (item) => item.id === id);
|
|
17
|
+
},
|
|
18
|
+
[content]
|
|
19
|
+
);
|
|
20
|
+
const patchItem = React.useCallback(
|
|
21
|
+
(id, patch) => {
|
|
22
|
+
setContent(
|
|
23
|
+
(content2) => mapRecursive(content2, (item) => {
|
|
24
|
+
if (item.id === id) {
|
|
25
|
+
return {
|
|
26
|
+
...item,
|
|
27
|
+
...patch
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return item;
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
[setContent, mapRecursive]
|
|
35
|
+
);
|
|
36
|
+
const addContent = React.useCallback(
|
|
37
|
+
(name, container, parent, index = 0) => {
|
|
38
|
+
const component = builder.getComponent(name);
|
|
39
|
+
if (!component) {
|
|
40
|
+
throw new Error(`[simple-builder]: Component "${name}" not found`);
|
|
41
|
+
}
|
|
42
|
+
const entry = {
|
|
43
|
+
id: crypto.randomUUID(),
|
|
44
|
+
component: component.name,
|
|
45
|
+
...parent && { parent },
|
|
46
|
+
...component.inputs && {
|
|
47
|
+
props: component.inputs.reduce(
|
|
48
|
+
(acc, input) => ({
|
|
49
|
+
...acc,
|
|
50
|
+
[input.name]: input.defaultValue
|
|
51
|
+
}),
|
|
52
|
+
{}
|
|
53
|
+
)
|
|
54
|
+
},
|
|
55
|
+
...component.defaultStyles && {
|
|
56
|
+
styles: component.defaultStyles
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
if (!parent) {
|
|
60
|
+
setContent((content2) => insertAt(content2, index, entry));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
setContent(
|
|
64
|
+
(content2) => mapRecursive(content2, (item) => {
|
|
65
|
+
if (item.id === parent) {
|
|
66
|
+
return {
|
|
67
|
+
...item,
|
|
68
|
+
content: {
|
|
69
|
+
...item.content,
|
|
70
|
+
[container]: insertAt(item.content?.[container], index, entry)
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return item;
|
|
75
|
+
})
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
[setContent, mapRecursive]
|
|
79
|
+
);
|
|
80
|
+
const deleteContent = React.useCallback(
|
|
81
|
+
(id) => setContent((prev) => filterRecursive(prev, (item) => item.id !== id)),
|
|
82
|
+
[setContent, filterRecursive]
|
|
83
|
+
);
|
|
84
|
+
const bringUp = React.useCallback(
|
|
85
|
+
(id) => {
|
|
86
|
+
setContent(
|
|
87
|
+
(content2) => mapRecursive(content2, (item, index, arr) => {
|
|
88
|
+
if (item.id === id && index > 0) {
|
|
89
|
+
return arr[index - 1];
|
|
90
|
+
}
|
|
91
|
+
if (arr[index + 1]?.id === id) {
|
|
92
|
+
return arr[index + 1];
|
|
93
|
+
}
|
|
94
|
+
return item;
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
[setContent, mapRecursive]
|
|
99
|
+
);
|
|
100
|
+
const bringDown = React.useCallback(
|
|
101
|
+
(id) => {
|
|
102
|
+
setContent(
|
|
103
|
+
(content2) => mapRecursive(content2, (item, index, arr) => {
|
|
104
|
+
if (item.id === id && index < arr.length - 1) {
|
|
105
|
+
return arr[index + 1];
|
|
106
|
+
}
|
|
107
|
+
if (arr[index - 1]?.id === id) {
|
|
108
|
+
return arr[index - 1];
|
|
109
|
+
}
|
|
110
|
+
return item;
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
[setContent, mapRecursive]
|
|
115
|
+
);
|
|
116
|
+
const save = React.useCallback(async () => {
|
|
117
|
+
const slug = window.location.pathname;
|
|
118
|
+
try {
|
|
119
|
+
await fetch(`${url}/page/update`, {
|
|
120
|
+
method: "POST",
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
slug,
|
|
123
|
+
content
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
alert("Pagina opgeslagen!");
|
|
127
|
+
} catch (e) {
|
|
128
|
+
console.error("[simple-builder]: Failed to save content", e);
|
|
129
|
+
alert("Er is iets fout gegaan. Bekijk de console voor meer info.");
|
|
130
|
+
}
|
|
131
|
+
}, [content]);
|
|
132
|
+
return /* @__PURE__ */ React.createElement(
|
|
133
|
+
BuilderContext.Provider,
|
|
134
|
+
{
|
|
135
|
+
value: {
|
|
136
|
+
url,
|
|
137
|
+
content,
|
|
138
|
+
setContent,
|
|
139
|
+
getItem,
|
|
140
|
+
patchItem,
|
|
141
|
+
addContent,
|
|
142
|
+
bringUp,
|
|
143
|
+
bringDown,
|
|
144
|
+
deleteContent,
|
|
145
|
+
save
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
props.children
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
var useBuilder = () => {
|
|
152
|
+
const context = React.useContext(BuilderContext);
|
|
153
|
+
if (!context) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
"[simple-builder]: useBuilder must be used within a BuilderProvider"
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
return context;
|
|
159
|
+
};
|
|
160
|
+
var filterRecursive = (items, predicate, key = "content") => {
|
|
161
|
+
return items.filter(predicate).map((item) => ({
|
|
162
|
+
...item,
|
|
163
|
+
...item[key] && {
|
|
164
|
+
[key]: Object.entries(item[key] ?? {}).reduce(
|
|
165
|
+
(acc, [name, content]) => ({
|
|
166
|
+
...acc,
|
|
167
|
+
[name]: filterRecursive(content, predicate, key)
|
|
168
|
+
}),
|
|
169
|
+
{}
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
}));
|
|
173
|
+
};
|
|
174
|
+
var mapRecursive = (items, predicate, key = "content") => {
|
|
175
|
+
return items.map(predicate).map((item) => ({
|
|
176
|
+
...item,
|
|
177
|
+
...item[key] && {
|
|
178
|
+
[key]: Object.entries(item[key] ?? {}).reduce(
|
|
179
|
+
(acc, [name, content]) => ({
|
|
180
|
+
...acc,
|
|
181
|
+
[name]: mapRecursive(content, predicate, key)
|
|
182
|
+
}),
|
|
183
|
+
{}
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
}));
|
|
187
|
+
};
|
|
188
|
+
var findRecursive = (items, predicate, key = "content") => {
|
|
189
|
+
for (const item of items) {
|
|
190
|
+
if (predicate(item)) {
|
|
191
|
+
return item;
|
|
192
|
+
}
|
|
193
|
+
if (item[key]) {
|
|
194
|
+
const keys = Object.keys(item[key] ?? {});
|
|
195
|
+
for (const x of keys) {
|
|
196
|
+
const found = findRecursive(item[key][x], predicate, key);
|
|
197
|
+
if (found) {
|
|
198
|
+
return found;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var buttonVariants = cva(
|
|
205
|
+
"sb:inline-flex sb:items-center sb:justify-center sb:gap-2 sb:whitespace-nowrap sb:rounded-md sb:text-sm sb:font-medium sb:transition-colors sb:focus-visible:outline-hidden sb:focus-visible:ring-1 sb:focus-visible:ring-ring sb:disabled:pointer-events-none sb:disabled:opacity-50 sb:[&_svg]:pointer-events-none sb:[&_svg]:size-4 sb:[&_svg]:shrink-0",
|
|
206
|
+
{
|
|
207
|
+
variants: {
|
|
208
|
+
variant: {
|
|
209
|
+
default: "sb:bg-primary sb:text-primary-foreground sb:shadow sb:hover:bg-primary/90",
|
|
210
|
+
destructive: "sb:bg-destructive sb:text-destructive-foreground sb:shadow-sm sb:hover:bg-destructive/90",
|
|
211
|
+
outline: "sb:border sb:border-input sb:bg-background sb:shadow-sm sb:hover:bg-accent sb:hover:text-accent-foreground",
|
|
212
|
+
secondary: "sb:bg-secondary sb:text-secondary-foreground sb:shadow-sm sb:hover:bg-secondary/80",
|
|
213
|
+
ghost: "sb:hover:bg-accent sb:hover:text-accent-foreground",
|
|
214
|
+
link: "sb:text-primary sb:underline-offset-4 sb:hover:underline"
|
|
215
|
+
},
|
|
216
|
+
size: {
|
|
217
|
+
default: "sb:h-9 sb:px-4 sb:py-2",
|
|
218
|
+
sm: "sb:h-8 sb:rounded-md sb:px-3 sb:text-xs",
|
|
219
|
+
lg: "sb:h-10 sb:rounded-md sb:px-8",
|
|
220
|
+
icon: "sb:h-9 sb:w-9"
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
defaultVariants: {
|
|
224
|
+
variant: "default",
|
|
225
|
+
size: "default"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
var Button = React.forwardRef(
|
|
230
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
231
|
+
const Comp = asChild ? Slot : "button";
|
|
232
|
+
return /* @__PURE__ */ React.createElement(
|
|
233
|
+
Comp,
|
|
234
|
+
{
|
|
235
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
236
|
+
ref,
|
|
237
|
+
...props
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
Button.displayName = "Button";
|
|
243
|
+
|
|
244
|
+
export { BuilderProvider, Button, buttonVariants, useBuilder };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React3 from 'react';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import NextImage from 'next/image';
|
|
4
|
+
import { clsx } from 'clsx';
|
|
5
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
6
|
+
import { createTV } from 'tailwind-variants';
|
|
7
|
+
|
|
8
|
+
// src/lib/builder.ts
|
|
9
|
+
var builder = /* @__PURE__ */ (() => {
|
|
10
|
+
const components = [];
|
|
11
|
+
return {
|
|
12
|
+
register: (component, config) => {
|
|
13
|
+
if (components.find(({ name }) => name === config.name)) {
|
|
14
|
+
console.log(
|
|
15
|
+
`[simple-builder]: Component ${config.name} already registered.`
|
|
16
|
+
);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
components.push({
|
|
20
|
+
component,
|
|
21
|
+
...config
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
getComponents: () => components,
|
|
25
|
+
getComponent: (name) => {
|
|
26
|
+
return components.find((c) => c.name === name);
|
|
27
|
+
},
|
|
28
|
+
bindComponent: ({ content, ...block }, edit) => {
|
|
29
|
+
const component = components.find(({ name }) => name === block.component);
|
|
30
|
+
if (!component) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`[simple-builder]: Component ${block.component} not found`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const Element = createElement(component.component, {
|
|
36
|
+
key: block.id,
|
|
37
|
+
builder: { id: block.id, content, edit },
|
|
38
|
+
...block.props
|
|
39
|
+
});
|
|
40
|
+
return Element;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
var Image = (props) => {
|
|
45
|
+
if (typeof NextImage !== "undefined") {
|
|
46
|
+
return /* @__PURE__ */ React3.createElement(NextImage, { ...props });
|
|
47
|
+
}
|
|
48
|
+
return /* @__PURE__ */ React3.createElement("img", { ...props });
|
|
49
|
+
};
|
|
50
|
+
var twMerge = extendTailwindMerge({
|
|
51
|
+
prefix: "sb-"
|
|
52
|
+
});
|
|
53
|
+
function cn(...inputs) {
|
|
54
|
+
return twMerge(clsx(inputs));
|
|
55
|
+
}
|
|
56
|
+
var tv = createTV({
|
|
57
|
+
twMergeConfig: {
|
|
58
|
+
prefix: "sb-"
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
var insertAt = (items, index, item) => {
|
|
62
|
+
return Array.isArray(items) ? [...items.slice(0, index), item, ...items.slice(index)] : [item];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/components/design-wrapper.tsx
|
|
66
|
+
var DesignWrapper = (props) => {
|
|
67
|
+
const { children, className, building = false } = props;
|
|
68
|
+
const { background } = props.styles?.desktop ?? {};
|
|
69
|
+
const matches = typeof background === "string" ? background.match(/url\(["']?(.*?)["']?\)/) : void 0;
|
|
70
|
+
const src = matches ? matches[1] : void 0;
|
|
71
|
+
const desktopStyles = props.styles?.desktop ?? {};
|
|
72
|
+
const mobileStyles = props.styles?.mobile ?? {};
|
|
73
|
+
const container = props.styles?.container ?? true;
|
|
74
|
+
const hidden = props.styles?.hidden ?? "never";
|
|
75
|
+
const id = React3.useId().replace(/[^a-zA-Z0-9]/g, "");
|
|
76
|
+
let hiddenClass = "";
|
|
77
|
+
switch (hidden) {
|
|
78
|
+
case "always":
|
|
79
|
+
hiddenClass = building ? "sb:opacity-30" : "sb:hidden";
|
|
80
|
+
break;
|
|
81
|
+
case "mobile":
|
|
82
|
+
hiddenClass = building ? "sb:max-md:opacity-30" : "sb:max-md:hidden";
|
|
83
|
+
break;
|
|
84
|
+
case "desktop":
|
|
85
|
+
hiddenClass = building ? "sb:md:opacity-30" : "sb:md:hidden";
|
|
86
|
+
break;
|
|
87
|
+
case "never":
|
|
88
|
+
hiddenClass = "";
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
return /* @__PURE__ */ React3.createElement("div", { id, className: cn("sb:relative", className, hiddenClass) }, src && /* @__PURE__ */ React3.createElement(
|
|
92
|
+
Image,
|
|
93
|
+
{
|
|
94
|
+
src,
|
|
95
|
+
alt: "",
|
|
96
|
+
fill: true,
|
|
97
|
+
className: "sb:object-cover sb:absolute sb:inset-0 sb:pointer-events-none sb:-z-1"
|
|
98
|
+
}
|
|
99
|
+
), container ? /* @__PURE__ */ React3.createElement("div", { className: "container sb:mx-auto" }, children) : children, /* @__PURE__ */ React3.createElement("style", null, `
|
|
100
|
+
#${id} {
|
|
101
|
+
${Object.entries(desktopStyles).filter(([key]) => !(key === "background" && src)).map(([key, value]) => `${key}: ${value};`).join(" ")}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@media (max-width: 1024px) {
|
|
105
|
+
#${id} {
|
|
106
|
+
${Object.entries(mobileStyles).filter(([key]) => !(key === "background" && src)).map(([key, value]) => `${key}: ${value}; `).join(" ")}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
`.replace(/\s\s+/g, " ")));
|
|
110
|
+
};
|
|
111
|
+
var BuildContainerInner = React3.lazy(
|
|
112
|
+
() => import('./build-container-client-L3WD4CG7.mjs')
|
|
113
|
+
);
|
|
114
|
+
var BuildContainer = (props) => {
|
|
115
|
+
const { content, edit, name } = props;
|
|
116
|
+
const items = Array.isArray(content) ? content : content?.[name] || [];
|
|
117
|
+
if (!edit) {
|
|
118
|
+
return items.map((item) => /* @__PURE__ */ React3.createElement(DesignWrapper, { styles: item.styles }, builder.bindComponent(item, true)));
|
|
119
|
+
}
|
|
120
|
+
return /* @__PURE__ */ React3.createElement(React3.Suspense, { fallback: /* @__PURE__ */ React3.createElement("div", null, "Loading...") }, /* @__PURE__ */ React3.createElement(BuildContainerInner, { ...props }));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export { BuildContainer, DesignWrapper, Image, builder, cn, insertAt, tv };
|