@builder.io/sdk-solid 0.0.3 → 0.0.6
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 +7 -2
- package/src/blocks/button.jsx +8 -0
- package/src/blocks/button.lite.tsx +11 -15
- package/src/blocks/{columns.js → columns.jsx} +39 -81
- package/src/blocks/columns.lite.tsx +28 -23
- package/src/blocks/{custom-code.js → custom-code.jsx} +5 -25
- package/src/blocks/custom-code.lite.tsx +3 -1
- package/src/blocks/{embed.js → embed.jsx} +5 -15
- package/src/blocks/embed.lite.tsx +3 -1
- package/src/blocks/{form.js → form.jsx} +34 -136
- package/src/blocks/form.lite.tsx +7 -2
- package/src/blocks/fragment.jsx +6 -0
- package/src/blocks/fragment.lite.tsx +3 -1
- package/src/blocks/{image.js → image.jsx} +47 -138
- package/src/blocks/image.lite.tsx +3 -1
- package/src/blocks/img.jsx +11 -0
- package/src/blocks/img.lite.tsx +3 -1
- package/src/blocks/input.jsx +8 -0
- package/src/blocks/input.lite.tsx +3 -1
- package/src/blocks/raw-text.jsx +6 -0
- package/src/blocks/raw-text.lite.tsx +3 -1
- package/src/blocks/{section.js → section.jsx} +9 -23
- package/src/blocks/section.lite.tsx +3 -1
- package/src/blocks/select.jsx +17 -0
- package/src/blocks/select.lite.tsx +9 -4
- package/src/blocks/submit-button.jsx +8 -0
- package/src/blocks/submit-button.lite.tsx +3 -1
- package/src/blocks/symbol.jsx +25 -0
- package/src/blocks/symbol.lite.tsx +4 -2
- package/src/blocks/text.jsx +6 -0
- package/src/blocks/text.lite.tsx +3 -1
- package/src/blocks/textarea.jsx +6 -0
- package/src/blocks/textarea.lite.tsx +3 -1
- package/src/blocks/video.jsx +15 -0
- package/src/blocks/video.lite.tsx +3 -1
- package/src/components/block-styles.jsx +5 -0
- package/src/components/block-styles.lite.tsx +3 -1
- package/src/components/error-boundary.jsx +5 -0
- package/src/components/error-boundary.lite.tsx +3 -1
- package/src/components/{render-block.js → render-block.jsx} +30 -70
- package/src/components/render-block.lite.tsx +11 -3
- package/src/components/render-blocks.jsx +57 -0
- package/src/components/render-blocks.lite.tsx +7 -4
- package/src/components/render-content/components/render-styles.jsx +73 -0
- package/src/components/render-content/components/render-styles.lite.tsx +72 -0
- package/src/components/render-content/render-content.jsx +210 -0
- package/src/components/{render-content.lite.tsx → render-content/render-content.lite.tsx} +22 -78
- package/src/constants/target.js +4 -0
- package/src/functions/if-target.js +11 -2
- package/src/functions/track.js +2 -2
- package/src/index-helpers/blocks-exports.js +1 -1
- package/src/scripts/init-editing.js +3 -2
- package/src/types/targets.js +0 -0
- package/src/blocks/button.js +0 -41
- package/src/blocks/fragment.js +0 -15
- package/src/blocks/img.js +0 -39
- package/src/blocks/input.js +0 -45
- package/src/blocks/raw-text.js +0 -25
- package/src/blocks/select.js +0 -57
- package/src/blocks/submit-button.js +0 -18
- package/src/blocks/symbol.js +0 -69
- package/src/blocks/text.js +0 -15
- package/src/blocks/textarea.js +0 -34
- package/src/blocks/video.js +0 -54
- package/src/components/block-styles.js +0 -3
- package/src/components/error-boundary.js +0 -3
- package/src/components/render-blocks.js +0 -104
- package/src/components/render-content.js +0 -314
- package/src/functions/get-target.js +0 -6
- package/src/functions/is-react-native.js +0 -6
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { template as _$template } from "solid-js/web";
|
|
2
|
-
import { delegateEvents as _$delegateEvents } from "solid-js/web";
|
|
3
|
-
import { setAttribute as _$setAttribute } from "solid-js/web";
|
|
4
|
-
import { effect as _$effect } from "solid-js/web";
|
|
5
|
-
import { insert as _$insert } from "solid-js/web";
|
|
6
|
-
import { createComponent as _$createComponent } from "solid-js/web";
|
|
7
|
-
|
|
8
|
-
const _tmpl$ = /*#__PURE__*/_$template(`<div></div>`, 2);
|
|
9
|
-
|
|
10
|
-
import { Show, For } from "solid-js";
|
|
11
|
-
import { createMutable } from "solid-js/store";
|
|
12
|
-
import { css } from "solid-styled-components";
|
|
13
|
-
import { isEditing } from "../functions/is-editing";
|
|
14
|
-
import RenderBlock from "./render-block";
|
|
15
|
-
export default function RenderBlocks(props) {
|
|
16
|
-
const state = createMutable({
|
|
17
|
-
get className() {
|
|
18
|
-
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
onClick() {
|
|
22
|
-
if (isEditing() && !props.blocks?.length) {
|
|
23
|
-
window.parent?.postMessage({
|
|
24
|
-
type: "builder.clickEmptyBlocks",
|
|
25
|
-
data: {
|
|
26
|
-
parentElementId: props.parent,
|
|
27
|
-
dataPath: props.path
|
|
28
|
-
}
|
|
29
|
-
}, "*");
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
onMouseEnter() {
|
|
34
|
-
if (isEditing() && !props.blocks?.length) {
|
|
35
|
-
window.parent?.postMessage({
|
|
36
|
-
type: "builder.hoverEmptyBlocks",
|
|
37
|
-
data: {
|
|
38
|
-
parentElementId: props.parent,
|
|
39
|
-
dataPath: props.path
|
|
40
|
-
}
|
|
41
|
-
}, "*");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
return (() => {
|
|
47
|
-
const _el$ = _tmpl$.cloneNode(true);
|
|
48
|
-
|
|
49
|
-
_el$.addEventListener("mouseenter", event => state.onMouseEnter());
|
|
50
|
-
|
|
51
|
-
_el$.$$click = event => state.onClick();
|
|
52
|
-
|
|
53
|
-
_$insert(_el$, _$createComponent(Show, {
|
|
54
|
-
get when() {
|
|
55
|
-
return props.blocks;
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
get children() {
|
|
59
|
-
return _$createComponent(For, {
|
|
60
|
-
get each() {
|
|
61
|
-
return props.blocks;
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
children: (block, index) => _$createComponent(RenderBlock, {
|
|
65
|
-
get key() {
|
|
66
|
-
return block.id;
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
block: block
|
|
70
|
-
})
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
_$effect(_p$ => {
|
|
77
|
-
const _v$ = state.className + " " + css({
|
|
78
|
-
display: "flex",
|
|
79
|
-
flexDirection: "column",
|
|
80
|
-
alignItems: "stretch"
|
|
81
|
-
}),
|
|
82
|
-
_v$2 = props.path,
|
|
83
|
-
_v$3 = props.parent,
|
|
84
|
-
_v$4 = {
|
|
85
|
-
class: state.className
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
_v$ !== _p$._v$ && (_el$.className = _p$._v$ = _v$);
|
|
89
|
-
_v$2 !== _p$._v$2 && _$setAttribute(_el$, "builder-path", _p$._v$2 = _v$2);
|
|
90
|
-
_v$3 !== _p$._v$3 && _$setAttribute(_el$, "builder-parent-id", _p$._v$3 = _v$3);
|
|
91
|
-
_v$4 !== _p$._v$4 && _$setAttribute(_el$, "dataset", _p$._v$4 = _v$4);
|
|
92
|
-
return _p$;
|
|
93
|
-
}, {
|
|
94
|
-
_v$: undefined,
|
|
95
|
-
_v$2: undefined,
|
|
96
|
-
_v$3: undefined,
|
|
97
|
-
_v$4: undefined
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
return _el$;
|
|
101
|
-
})();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
_$delegateEvents(["click"]);
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { template as _$template } from "solid-js/web";
|
|
2
|
-
import { delegateEvents as _$delegateEvents } from "solid-js/web";
|
|
3
|
-
import { setAttribute as _$setAttribute } from "solid-js/web";
|
|
4
|
-
import { effect as _$effect } from "solid-js/web";
|
|
5
|
-
import { createComponent as _$createComponent } from "solid-js/web";
|
|
6
|
-
import { insert as _$insert } from "solid-js/web";
|
|
7
|
-
import { memo as _$memo } from "solid-js/web";
|
|
8
|
-
|
|
9
|
-
const _tmpl$ = /*#__PURE__*/_$template(`<style></style>`, 2),
|
|
10
|
-
_tmpl$2 = /*#__PURE__*/_$template(`<div></div>`, 2);
|
|
11
|
-
|
|
12
|
-
import { Show, onMount } from "solid-js";
|
|
13
|
-
import { Dynamic } from "solid-js/web";
|
|
14
|
-
import { createMutable } from "solid-js/store";
|
|
15
|
-
import { isBrowser } from "../functions/is-browser";
|
|
16
|
-
import BuilderContext from "../context/builder.context";
|
|
17
|
-
import { track } from "../functions/track";
|
|
18
|
-
import { isReactNative } from "../functions/is-react-native";
|
|
19
|
-
import { isEditing } from "../functions/is-editing";
|
|
20
|
-
import { isPreviewing } from "../functions/is-previewing";
|
|
21
|
-
import { previewingModelName } from "../functions/previewing-model-name";
|
|
22
|
-
import { getContent } from "../functions/get-content";
|
|
23
|
-
import { convertSearchParamsToQueryObject, getBuilderSearchParams } from "../functions/get-builder-search-params";
|
|
24
|
-
import RenderBlocks from "./render-blocks";
|
|
25
|
-
import { evaluate } from "../functions/evaluate";
|
|
26
|
-
import { getFetch } from "../functions/get-fetch";
|
|
27
|
-
export default function RenderContent(props) {
|
|
28
|
-
const state = createMutable({
|
|
29
|
-
get useContent() {
|
|
30
|
-
const mergedContent = { ...props.content,
|
|
31
|
-
...state.overrideContent,
|
|
32
|
-
data: { ...props.content?.data,
|
|
33
|
-
...props.data,
|
|
34
|
-
...state.overrideContent?.data
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
return mergedContent;
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
overrideContent: null,
|
|
41
|
-
update: 0,
|
|
42
|
-
overrideState: {},
|
|
43
|
-
|
|
44
|
-
get state() {
|
|
45
|
-
return { ...props.content?.data?.state,
|
|
46
|
-
...props.data,
|
|
47
|
-
...state.overrideState
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
get context() {
|
|
52
|
-
return {};
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
getCssFromFont(font, data) {
|
|
56
|
-
// TODO: compute what font sizes are used and only load those.......
|
|
57
|
-
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
58
|
-
const name = family.split(",")[0];
|
|
59
|
-
const url = font.fileUrl ?? font?.files?.regular;
|
|
60
|
-
let str = "";
|
|
61
|
-
|
|
62
|
-
if (url && family && name) {
|
|
63
|
-
str += `
|
|
64
|
-
@font-face {
|
|
65
|
-
font-family: "${family}";
|
|
66
|
-
src: local("${name}"), url('${url}') format('woff2');
|
|
67
|
-
font-display: fallback;
|
|
68
|
-
font-weight: 400;
|
|
69
|
-
}
|
|
70
|
-
`.trim();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (font.files) {
|
|
74
|
-
for (const weight in font.files) {
|
|
75
|
-
const isNumber = String(Number(weight)) === weight;
|
|
76
|
-
|
|
77
|
-
if (!isNumber) {
|
|
78
|
-
continue;
|
|
79
|
-
} // TODO: maybe limit number loaded
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const weightUrl = font.files[weight];
|
|
83
|
-
|
|
84
|
-
if (weightUrl && weightUrl !== url) {
|
|
85
|
-
str += `
|
|
86
|
-
@font-face {
|
|
87
|
-
font-family: "${family}";
|
|
88
|
-
src: url('${weightUrl}') format('woff2');
|
|
89
|
-
font-display: fallback;
|
|
90
|
-
font-weight: ${weight};
|
|
91
|
-
}
|
|
92
|
-
`.trim();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return str;
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
getFontCss(data) {
|
|
101
|
-
// TODO: flag for this
|
|
102
|
-
// if (!this.builder.allowCustomFonts) {
|
|
103
|
-
// return '';
|
|
104
|
-
// }
|
|
105
|
-
// TODO: separate internal data from external
|
|
106
|
-
return data?.customFonts?.map(font => this.getCssFromFont(font, data))?.join(" ") || "";
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
processMessage(event) {
|
|
110
|
-
const {
|
|
111
|
-
data
|
|
112
|
-
} = event;
|
|
113
|
-
|
|
114
|
-
if (data) {
|
|
115
|
-
switch (data.type) {
|
|
116
|
-
case "builder.contentUpdate":
|
|
117
|
-
{
|
|
118
|
-
const messageContent = data.data;
|
|
119
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
120
|
-
const contentData = messageContent.data;
|
|
121
|
-
|
|
122
|
-
if (key === props.model) {
|
|
123
|
-
state.overrideContent = contentData;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
case "builder.patchUpdates":
|
|
130
|
-
{
|
|
131
|
-
// TODO
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
evaluateJsCode() {
|
|
139
|
-
// run any dynamic JS code attached to content
|
|
140
|
-
const jsCode = state.useContent?.data?.jsCode;
|
|
141
|
-
|
|
142
|
-
if (jsCode) {
|
|
143
|
-
evaluate({
|
|
144
|
-
code: jsCode,
|
|
145
|
-
context: state.context,
|
|
146
|
-
state: state.state
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
get httpReqsData() {
|
|
152
|
-
return {};
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
evalExpression(expression) {
|
|
156
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
157
|
-
code: group,
|
|
158
|
-
context: state.context,
|
|
159
|
-
state: state.state
|
|
160
|
-
}));
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
handleRequest({
|
|
164
|
-
url,
|
|
165
|
-
key
|
|
166
|
-
}) {
|
|
167
|
-
const fetchAndSetState = async () => {
|
|
168
|
-
const response = await getFetch()(url);
|
|
169
|
-
const json = await response.json();
|
|
170
|
-
const newOverrideState = { ...state.overrideState,
|
|
171
|
-
[key]: json
|
|
172
|
-
};
|
|
173
|
-
state.overrideState = newOverrideState;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
fetchAndSetState();
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
runHttpRequests() {
|
|
180
|
-
const requests = state.useContent?.data?.httpRequests ?? {};
|
|
181
|
-
Object.entries(requests).forEach(([key, url]) => {
|
|
182
|
-
if (url && (!state.httpReqsData[key] || isEditing())) {
|
|
183
|
-
const evaluatedUrl = state.evalExpression(url);
|
|
184
|
-
state.handleRequest({
|
|
185
|
-
url: evaluatedUrl,
|
|
186
|
-
key
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
emitStateUpdate() {
|
|
193
|
-
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
194
|
-
detail: {
|
|
195
|
-
state: state.state,
|
|
196
|
-
ref: {
|
|
197
|
-
name: props.model
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
onMount(() => {
|
|
205
|
-
if (isBrowser()) {
|
|
206
|
-
if (isEditing()) {
|
|
207
|
-
window.addEventListener("message", state.processMessage);
|
|
208
|
-
window.addEventListener("builder:component:stateChangeListenerActivated", state.emitStateUpdate);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (state.useContent) {
|
|
212
|
-
track("impression", {
|
|
213
|
-
contentId: state.useContent.id
|
|
214
|
-
});
|
|
215
|
-
} // override normal content in preview mode
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (isPreviewing()) {
|
|
219
|
-
if (props.model && previewingModelName() === props.model) {
|
|
220
|
-
const currentUrl = new URL(location.href);
|
|
221
|
-
const previewApiKey = currentUrl.searchParams.get("apiKey");
|
|
222
|
-
|
|
223
|
-
if (previewApiKey) {
|
|
224
|
-
getContent({
|
|
225
|
-
model: props.model,
|
|
226
|
-
apiKey: previewApiKey,
|
|
227
|
-
options: getBuilderSearchParams(convertSearchParamsToQueryObject(currentUrl.searchParams))
|
|
228
|
-
}).then(content => {
|
|
229
|
-
if (content) {
|
|
230
|
-
state.overrideContent = content;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
state.evaluateJsCode();
|
|
238
|
-
state.runHttpRequests();
|
|
239
|
-
state.emitStateUpdate();
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
return _$createComponent(Dynamic, {
|
|
243
|
-
value: {
|
|
244
|
-
get content() {
|
|
245
|
-
return state.useContent;
|
|
246
|
-
},
|
|
247
|
-
|
|
248
|
-
get state() {
|
|
249
|
-
return state.state;
|
|
250
|
-
},
|
|
251
|
-
|
|
252
|
-
get context() {
|
|
253
|
-
return state.context;
|
|
254
|
-
},
|
|
255
|
-
|
|
256
|
-
get apiKey() {
|
|
257
|
-
return props.apiKey;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
get component() {
|
|
263
|
-
return BuilderContext.Provider;
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
get children() {
|
|
267
|
-
return _$createComponent(Show, {
|
|
268
|
-
get when() {
|
|
269
|
-
return state.useContent;
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
get children() {
|
|
273
|
-
const _el$ = _tmpl$2.cloneNode(true);
|
|
274
|
-
|
|
275
|
-
_el$.$$click = event => track("click", {
|
|
276
|
-
contentId: state.useContent.id
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
_$insert(_el$, _$createComponent(Show, {
|
|
280
|
-
get when() {
|
|
281
|
-
return _$memo(() => !!(state.useContent?.data?.cssCode || state.useContent?.data?.customFonts?.length), true)() && !isReactNative();
|
|
282
|
-
},
|
|
283
|
-
|
|
284
|
-
get children() {
|
|
285
|
-
const _el$2 = _tmpl$.cloneNode(true);
|
|
286
|
-
|
|
287
|
-
_$insert(_el$2, () => state.useContent.data.cssCode, null);
|
|
288
|
-
|
|
289
|
-
_$insert(_el$2, () => state.getFontCss(state.useContent.data), null);
|
|
290
|
-
|
|
291
|
-
return _el$2;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
}), null);
|
|
295
|
-
|
|
296
|
-
_$insert(_el$, _$createComponent(RenderBlocks, {
|
|
297
|
-
get blocks() {
|
|
298
|
-
return state.useContent?.data?.blocks;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
}), null);
|
|
302
|
-
|
|
303
|
-
_$effect(() => _$setAttribute(_el$, "data-builder-content-id", state.useContent?.id));
|
|
304
|
-
|
|
305
|
-
return _el$;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
_$delegateEvents(["click"]);
|