@builder.io/sdk-qwik 0.0.8 → 0.0.9
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/README.md +65 -2
- package/lib/index.qwik.cjs +104 -7
- package/lib/index.qwik.mjs +104 -7
- package/package.json +1 -1
- package/src/blocks/button/button.jsx +197 -0
- package/src/blocks/button/component-info.js +41 -0
- package/src/blocks/columns/columns.jsx +267 -0
- package/src/blocks/columns/component-info.js +242 -0
- package/src/blocks/custom-code/component-info.js +31 -0
- package/src/blocks/custom-code/custom-code.jsx +130 -0
- package/src/blocks/embed/component-info.js +44 -0
- package/src/blocks/embed/embed.jsx +130 -0
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/builder-blocks.jsx +86 -0
- package/src/blocks/form/component-info.js +262 -0
- package/src/blocks/form/form.jsx +782 -0
- package/src/blocks/fragment/component-info.js +11 -0
- package/src/blocks/fragment/fragment.jsx +59 -0
- package/src/blocks/image/component-info.js +151 -0
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.jsx +554 -0
- package/src/blocks/img/component-info.js +20 -0
- package/src/blocks/img/img.jsx +76 -0
- package/src/blocks/input/component-info.js +74 -0
- package/src/blocks/input/input.jsx +87 -0
- package/src/blocks/raw-text/component-info.js +16 -0
- package/src/blocks/raw-text/raw-text.jsx +53 -0
- package/src/blocks/section/component-info.js +49 -0
- package/src/blocks/section/section.jsx +97 -0
- package/src/blocks/select/component-info.js +59 -0
- package/src/blocks/select/select.jsx +149 -0
- package/src/blocks/submit-button/component-info.js +28 -0
- package/src/blocks/submit-button/submit-button.jsx +87 -0
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.jsx +211 -0
- package/src/blocks/text/component-info.js +24 -0
- package/src/blocks/text/text.jsx +46 -0
- package/src/blocks/textarea/component-info.js +47 -0
- package/src/blocks/textarea/textarea.jsx +65 -0
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/component-info.js +106 -0
- package/src/blocks/video/video.jsx +103 -0
- package/src/components/render-block/block-styles.jsx +174 -0
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.jsx +733 -0
- package/src/components/render-block/render-component.jsx +245 -0
- package/src/components/render-block/render-repeated-block.jsx +104 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +387 -0
- package/src/components/render-content/components/render-styles.jsx +126 -0
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +650 -0
- package/src/components/render-inlined-styles.jsx +141 -0
- package/src/constants/builder-registered-components.js +48 -0
- package/src/constants/device-sizes.js +21 -0
- package/src/constants/target.js +4 -0
- package/src/context/builder.context.js +5 -0
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/evaluate.js +28 -0
- package/src/functions/event-handler-name.js +7 -0
- package/src/functions/get-block-actions.js +23 -0
- package/src/functions/get-block-component-options.js +28 -0
- package/src/functions/get-block-properties.js +29 -0
- package/src/functions/get-block-styles.js +34 -0
- package/src/functions/get-block-tag.js +6 -0
- package/src/functions/get-builder-search-params/fn.test.js +13 -0
- package/src/functions/get-builder-search-params/index.js +33 -0
- package/src/functions/get-content/ab-testing.js +38 -0
- package/src/functions/get-content/fn.test.js +31 -0
- package/src/functions/get-content/index.js +96 -0
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +34 -0
- package/src/functions/get-global-this.js +18 -0
- package/src/functions/get-processed-block.js +53 -0
- package/src/functions/get-processed-block.test.js +32 -0
- package/src/functions/if-target.js +15 -0
- package/src/functions/is-browser.js +6 -0
- package/src/functions/is-editing.js +7 -0
- package/src/functions/is-iframe.js +7 -0
- package/src/functions/is-previewing.js +14 -0
- package/src/functions/on-change.js +27 -0
- package/src/functions/on-change.test.js +19 -0
- package/src/functions/register-component.js +72 -0
- package/src/functions/register.js +29 -0
- package/src/functions/sanitize-styles.js +5 -0
- package/src/functions/set-editor-settings.js +15 -0
- package/src/functions/set.js +11 -0
- package/src/functions/set.test.js +16 -0
- package/src/functions/track.js +22 -0
- package/src/functions/transform-block.js +6 -0
- package/src/helpers/css.js +12 -0
- package/src/helpers/flatten.js +34 -0
- package/src/index-helpers/blocks-exports.js +22 -0
- package/src/index-helpers/top-of-file.js +4 -0
- package/src/index.js +10 -0
- package/src/scripts/init-editing.js +79 -0
- package/src/types/builder-block.js +0 -0
- package/src/types/builder-content.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/deep-partial.js +0 -0
- package/src/types/element.js +0 -0
- package/src/types/targets.js +0 -0
- package/src/types/typescript.js +0 -0
- package/types.d.ts +7 -12
- package/root.json +0 -1176
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import BuilderContext from "../context/builder.context";
|
|
4
|
+
import { isEditing } from "../functions/is-editing.js";
|
|
5
|
+
import BlockStyles from "./render-block/block-styles";
|
|
6
|
+
import RenderBlock from "./render-block/render-block";
|
|
7
|
+
import {
|
|
8
|
+
Fragment,
|
|
9
|
+
Host,
|
|
10
|
+
component$,
|
|
11
|
+
h,
|
|
12
|
+
useContext,
|
|
13
|
+
useStylesScoped$,
|
|
14
|
+
} from "@builder.io/qwik";
|
|
15
|
+
export const className = function className(props, state, builderContext) {
|
|
16
|
+
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
17
|
+
};
|
|
18
|
+
export const onClick = function onClick(props, state, builderContext) {
|
|
19
|
+
if (isEditing() && !props.blocks?.length) {
|
|
20
|
+
window.parent?.postMessage(
|
|
21
|
+
{
|
|
22
|
+
type: "builder.clickEmptyBlocks",
|
|
23
|
+
data: {
|
|
24
|
+
parentElementId: props.parent,
|
|
25
|
+
dataPath: props.path,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
"*"
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const onMouseEnter = function onMouseEnter(
|
|
33
|
+
props,
|
|
34
|
+
state,
|
|
35
|
+
builderContext
|
|
36
|
+
) {
|
|
37
|
+
if (isEditing() && !props.blocks?.length) {
|
|
38
|
+
window.parent?.postMessage(
|
|
39
|
+
{
|
|
40
|
+
type: "builder.hoverEmptyBlocks",
|
|
41
|
+
data: {
|
|
42
|
+
parentElementId: props.parent,
|
|
43
|
+
dataPath: props.path,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
"*"
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export const RenderBlocks = component$(
|
|
51
|
+
(props) => {
|
|
52
|
+
useStylesScoped$(STYLES);
|
|
53
|
+
const builderContext = useContext(BuilderContext);
|
|
54
|
+
const state = {};
|
|
55
|
+
return (
|
|
56
|
+
<Host
|
|
57
|
+
class={className(props, state, builderContext) + " div-RenderBlocks"}
|
|
58
|
+
builder-path={props.path}
|
|
59
|
+
builder-parent-id={props.parent}
|
|
60
|
+
dataSet={{
|
|
61
|
+
class: className(props, state, builderContext),
|
|
62
|
+
}}
|
|
63
|
+
onClick$={(event) => onClick(props, state, builderContext)}
|
|
64
|
+
onMouseEnter$={(event) => onMouseEnter(props, state, builderContext)}
|
|
65
|
+
>
|
|
66
|
+
<>
|
|
67
|
+
{props.blocks
|
|
68
|
+
? (props.blocks || []).map((block) => {
|
|
69
|
+
return (
|
|
70
|
+
<RenderBlock
|
|
71
|
+
key={"render-block-" + block.id}
|
|
72
|
+
block={block}
|
|
73
|
+
context={builderContext}
|
|
74
|
+
></RenderBlock>
|
|
75
|
+
);
|
|
76
|
+
})
|
|
77
|
+
: null}
|
|
78
|
+
{props.blocks
|
|
79
|
+
? (props.blocks || []).map((block) => {
|
|
80
|
+
return (
|
|
81
|
+
<BlockStyles
|
|
82
|
+
key={"block-style-" + block.id}
|
|
83
|
+
block={block}
|
|
84
|
+
context={builderContext}
|
|
85
|
+
></BlockStyles>
|
|
86
|
+
);
|
|
87
|
+
})
|
|
88
|
+
: null}
|
|
89
|
+
</>
|
|
90
|
+
</Host>
|
|
91
|
+
);
|
|
92
|
+
},
|
|
93
|
+
{ tagName: "div" }
|
|
94
|
+
);
|
|
95
|
+
export default RenderBlocks;
|
|
96
|
+
export const STYLES = `.div-RenderBlocks {
|
|
97
|
+
display: flex;
|
|
98
|
+
flex-direction: column;
|
|
99
|
+
align-items: stretch; }`;
|
|
100
|
+
export const COMPONENT = {
|
|
101
|
+
"@type": "@builder.io/mitosis/component",
|
|
102
|
+
imports: [
|
|
103
|
+
{
|
|
104
|
+
imports: {
|
|
105
|
+
BuilderContext: "default",
|
|
106
|
+
},
|
|
107
|
+
path: "../context/builder.context.lite",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
imports: {
|
|
111
|
+
isEditing: "isEditing",
|
|
112
|
+
},
|
|
113
|
+
path: "../functions/is-editing.js",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
imports: {
|
|
117
|
+
BlockStyles: "default",
|
|
118
|
+
},
|
|
119
|
+
path: "./render-block/block-styles.lite",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
imports: {
|
|
123
|
+
RenderBlock: "default",
|
|
124
|
+
},
|
|
125
|
+
path: "./render-block/render-block.lite",
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
exports: {},
|
|
129
|
+
inputs: [],
|
|
130
|
+
meta: {
|
|
131
|
+
useMetadata: {
|
|
132
|
+
qwik: {
|
|
133
|
+
component: {
|
|
134
|
+
isLight: false,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
refs: {},
|
|
140
|
+
state: {
|
|
141
|
+
className:
|
|
142
|
+
"@builder.io/mitosis/method:get className() {\n return 'builder-blocks' + (!props.blocks?.length ? ' no-blocks' : '');\n}",
|
|
143
|
+
onClick:
|
|
144
|
+
"@builder.io/mitosis/method:onClick() {\n if (isEditing() && !props.blocks?.length) {\n window.parent?.postMessage({\n type: 'builder.clickEmptyBlocks',\n data: {\n parentElementId: props.parent,\n dataPath: props.path\n }\n }, '*');\n }\n}",
|
|
145
|
+
onMouseEnter:
|
|
146
|
+
"@builder.io/mitosis/method:onMouseEnter() {\n if (isEditing() && !props.blocks?.length) {\n window.parent?.postMessage({\n type: 'builder.hoverEmptyBlocks',\n data: {\n parentElementId: props.parent,\n dataPath: props.path\n }\n }, '*');\n }\n}",
|
|
147
|
+
},
|
|
148
|
+
children: [
|
|
149
|
+
{
|
|
150
|
+
"@type": "@builder.io/mitosis/node",
|
|
151
|
+
name: "Host",
|
|
152
|
+
meta: {},
|
|
153
|
+
scope: {},
|
|
154
|
+
properties: {},
|
|
155
|
+
bindings: {
|
|
156
|
+
class: {
|
|
157
|
+
code: "className(props,state,builderContext) + ' div-RenderBlocks'",
|
|
158
|
+
},
|
|
159
|
+
"builder-path": {
|
|
160
|
+
code: "props.path",
|
|
161
|
+
},
|
|
162
|
+
"builder-parent-id": {
|
|
163
|
+
code: "props.parent",
|
|
164
|
+
},
|
|
165
|
+
dataSet: {
|
|
166
|
+
code: "{\n class: className(props,state,builderContext)\n}",
|
|
167
|
+
},
|
|
168
|
+
onClick: {
|
|
169
|
+
code: "onClick(props,state,builderContext,)",
|
|
170
|
+
arguments: ["event"],
|
|
171
|
+
},
|
|
172
|
+
onMouseEnter: {
|
|
173
|
+
code: "onMouseEnter(props,state,builderContext,)",
|
|
174
|
+
arguments: ["event"],
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
children: [
|
|
178
|
+
{
|
|
179
|
+
"@type": "@builder.io/mitosis/node",
|
|
180
|
+
name: "div",
|
|
181
|
+
meta: {},
|
|
182
|
+
scope: {},
|
|
183
|
+
properties: {
|
|
184
|
+
_text: "\n ",
|
|
185
|
+
},
|
|
186
|
+
bindings: {},
|
|
187
|
+
children: [],
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"@type": "@builder.io/mitosis/node",
|
|
191
|
+
name: "div",
|
|
192
|
+
meta: {},
|
|
193
|
+
scope: {},
|
|
194
|
+
properties: {
|
|
195
|
+
_text: "\n ",
|
|
196
|
+
},
|
|
197
|
+
bindings: {},
|
|
198
|
+
children: [],
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"@type": "@builder.io/mitosis/node",
|
|
202
|
+
name: "Show",
|
|
203
|
+
meta: {},
|
|
204
|
+
scope: {},
|
|
205
|
+
properties: {},
|
|
206
|
+
bindings: {
|
|
207
|
+
when: {
|
|
208
|
+
code: "props.blocks",
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
children: [
|
|
212
|
+
{
|
|
213
|
+
"@type": "@builder.io/mitosis/node",
|
|
214
|
+
name: "div",
|
|
215
|
+
meta: {},
|
|
216
|
+
scope: {},
|
|
217
|
+
properties: {
|
|
218
|
+
_text: "\n ",
|
|
219
|
+
},
|
|
220
|
+
bindings: {},
|
|
221
|
+
children: [],
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"@type": "@builder.io/mitosis/node",
|
|
225
|
+
name: "For",
|
|
226
|
+
meta: {},
|
|
227
|
+
scope: {
|
|
228
|
+
For: ["block"],
|
|
229
|
+
},
|
|
230
|
+
properties: {
|
|
231
|
+
_forName: "block",
|
|
232
|
+
},
|
|
233
|
+
bindings: {
|
|
234
|
+
each: {
|
|
235
|
+
code: "props.blocks",
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
children: [
|
|
239
|
+
{
|
|
240
|
+
"@type": "@builder.io/mitosis/node",
|
|
241
|
+
name: "RenderBlock",
|
|
242
|
+
meta: {},
|
|
243
|
+
scope: {},
|
|
244
|
+
properties: {},
|
|
245
|
+
bindings: {
|
|
246
|
+
key: {
|
|
247
|
+
code: "'render-block-' + block.id",
|
|
248
|
+
},
|
|
249
|
+
block: {
|
|
250
|
+
code: "block",
|
|
251
|
+
},
|
|
252
|
+
context: {
|
|
253
|
+
code: "builderContext",
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
children: [],
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
"@type": "@builder.io/mitosis/node",
|
|
262
|
+
name: "div",
|
|
263
|
+
meta: {},
|
|
264
|
+
scope: {},
|
|
265
|
+
properties: {
|
|
266
|
+
_text: "\n ",
|
|
267
|
+
},
|
|
268
|
+
bindings: {},
|
|
269
|
+
children: [],
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
"@type": "@builder.io/mitosis/node",
|
|
275
|
+
name: "div",
|
|
276
|
+
meta: {},
|
|
277
|
+
scope: {},
|
|
278
|
+
properties: {
|
|
279
|
+
_text: "\n ",
|
|
280
|
+
},
|
|
281
|
+
bindings: {},
|
|
282
|
+
children: [],
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
"@type": "@builder.io/mitosis/node",
|
|
286
|
+
name: "Show",
|
|
287
|
+
meta: {},
|
|
288
|
+
scope: {},
|
|
289
|
+
properties: {},
|
|
290
|
+
bindings: {
|
|
291
|
+
when: {
|
|
292
|
+
code: "props.blocks",
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
children: [
|
|
296
|
+
{
|
|
297
|
+
"@type": "@builder.io/mitosis/node",
|
|
298
|
+
name: "div",
|
|
299
|
+
meta: {},
|
|
300
|
+
scope: {},
|
|
301
|
+
properties: {
|
|
302
|
+
_text: "\n ",
|
|
303
|
+
},
|
|
304
|
+
bindings: {},
|
|
305
|
+
children: [],
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
"@type": "@builder.io/mitosis/node",
|
|
309
|
+
name: "For",
|
|
310
|
+
meta: {},
|
|
311
|
+
scope: {
|
|
312
|
+
For: ["block"],
|
|
313
|
+
},
|
|
314
|
+
properties: {
|
|
315
|
+
_forName: "block",
|
|
316
|
+
},
|
|
317
|
+
bindings: {
|
|
318
|
+
each: {
|
|
319
|
+
code: "props.blocks",
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
children: [
|
|
323
|
+
{
|
|
324
|
+
"@type": "@builder.io/mitosis/node",
|
|
325
|
+
name: "BlockStyles",
|
|
326
|
+
meta: {},
|
|
327
|
+
scope: {},
|
|
328
|
+
properties: {},
|
|
329
|
+
bindings: {
|
|
330
|
+
key: {
|
|
331
|
+
code: "'block-style-' + block.id",
|
|
332
|
+
},
|
|
333
|
+
block: {
|
|
334
|
+
code: "block",
|
|
335
|
+
},
|
|
336
|
+
context: {
|
|
337
|
+
code: "builderContext",
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
children: [],
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"@type": "@builder.io/mitosis/node",
|
|
346
|
+
name: "div",
|
|
347
|
+
meta: {},
|
|
348
|
+
scope: {},
|
|
349
|
+
properties: {
|
|
350
|
+
_text: "\n ",
|
|
351
|
+
},
|
|
352
|
+
bindings: {},
|
|
353
|
+
children: [],
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
"@type": "@builder.io/mitosis/node",
|
|
359
|
+
name: "div",
|
|
360
|
+
meta: {},
|
|
361
|
+
scope: {},
|
|
362
|
+
properties: {
|
|
363
|
+
_text: "\n ",
|
|
364
|
+
},
|
|
365
|
+
bindings: {},
|
|
366
|
+
children: [],
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
hooks: {},
|
|
372
|
+
context: {
|
|
373
|
+
get: {
|
|
374
|
+
builderContext: {
|
|
375
|
+
name: "BuilderContext",
|
|
376
|
+
path: "../context/builder.context.lite:default",
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
set: {},
|
|
380
|
+
},
|
|
381
|
+
name: "RenderBlocks",
|
|
382
|
+
subComponents: [],
|
|
383
|
+
types: [
|
|
384
|
+
"export type RenderBlockProps = {\n blocks?: BuilderBlock[];\n parent?: string;\n path?: string;\n};",
|
|
385
|
+
],
|
|
386
|
+
propsTypeRef: "RenderBlockProps",
|
|
387
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import RenderInlinedStyles from "../../render-inlined-styles";
|
|
4
|
+
import { Fragment, component$, h } from "@builder.io/qwik";
|
|
5
|
+
export const getCssFromFont = function getCssFromFont(props, state, font) {
|
|
6
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
7
|
+
const family =
|
|
8
|
+
font.family +
|
|
9
|
+
(font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
10
|
+
const name = family.split(",")[0];
|
|
11
|
+
const url = font.fileUrl ?? font?.files?.regular;
|
|
12
|
+
let str = "";
|
|
13
|
+
|
|
14
|
+
if (url && family && name) {
|
|
15
|
+
str += `
|
|
16
|
+
@font-face {
|
|
17
|
+
font-family: "${family}";
|
|
18
|
+
src: local("${name}"), url('${url}') format('woff2');
|
|
19
|
+
font-display: fallback;
|
|
20
|
+
font-weight: 400;
|
|
21
|
+
}
|
|
22
|
+
`.trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (font.files) {
|
|
26
|
+
for (const weight in font.files) {
|
|
27
|
+
const isNumber = String(Number(weight)) === weight;
|
|
28
|
+
|
|
29
|
+
if (!isNumber) {
|
|
30
|
+
continue;
|
|
31
|
+
} // TODO: maybe limit number loaded
|
|
32
|
+
|
|
33
|
+
const weightUrl = font.files[weight];
|
|
34
|
+
|
|
35
|
+
if (weightUrl && weightUrl !== url) {
|
|
36
|
+
str += `
|
|
37
|
+
@font-face {
|
|
38
|
+
font-family: "${family}";
|
|
39
|
+
src: url('${weightUrl}') format('woff2');
|
|
40
|
+
font-display: fallback;
|
|
41
|
+
font-weight: ${weight};
|
|
42
|
+
}
|
|
43
|
+
`.trim();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return str;
|
|
49
|
+
};
|
|
50
|
+
export const getFontCss = function getFontCss(props, state, { customFonts }) {
|
|
51
|
+
// TODO: flag for this
|
|
52
|
+
// if (!this.builder.allowCustomFonts) {
|
|
53
|
+
// return '';
|
|
54
|
+
// }
|
|
55
|
+
// TODO: separate internal data from external
|
|
56
|
+
return (
|
|
57
|
+
customFonts?.map((font) => getCssFromFont(props, state, font))?.join(" ") ||
|
|
58
|
+
""
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
export const injectedStyles = function injectedStyles(props, state) {
|
|
62
|
+
return `
|
|
63
|
+
${props.cssCode || ""}
|
|
64
|
+
${getFontCss(props, state, {
|
|
65
|
+
customFonts: props.customFonts,
|
|
66
|
+
})}`;
|
|
67
|
+
};
|
|
68
|
+
export const RenderContentStyles = component$((props) => {
|
|
69
|
+
const state = {};
|
|
70
|
+
return (
|
|
71
|
+
<RenderInlinedStyles
|
|
72
|
+
styles={injectedStyles(props, state)}
|
|
73
|
+
></RenderInlinedStyles>
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
export default RenderContentStyles;
|
|
77
|
+
export const COMPONENT = {
|
|
78
|
+
"@type": "@builder.io/mitosis/component",
|
|
79
|
+
imports: [
|
|
80
|
+
{
|
|
81
|
+
imports: {
|
|
82
|
+
RenderInlinedStyles: "default",
|
|
83
|
+
},
|
|
84
|
+
path: "../../render-inlined-styles.lite",
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
exports: {},
|
|
88
|
+
inputs: [],
|
|
89
|
+
meta: {},
|
|
90
|
+
refs: {},
|
|
91
|
+
state: {
|
|
92
|
+
getCssFromFont:
|
|
93
|
+
"@builder.io/mitosis/method:getCssFromFont(font: CustomFont) {\n // TODO: compute what font sizes are used and only load those.......\n const family = font.family + (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');\n const name = family.split(',')[0];\n const url = font.fileUrl ?? font?.files?.regular;\n let str = '';\n\n if (url && family && name) {\n str += `\n @font-face {\n font-family: \"${family}\";\n src: local(\"${name}\"), url('${url}') format('woff2');\n font-display: fallback;\n font-weight: 400;\n }\n `.trim();\n }\n\n if (font.files) {\n for (const weight in font.files) {\n const isNumber = String(Number(weight)) === weight;\n\n if (!isNumber) {\n continue;\n } // TODO: maybe limit number loaded\n\n\n const weightUrl = font.files[weight];\n\n if (weightUrl && weightUrl !== url) {\n str += `\n @font-face {\n font-family: \"${family}\";\n src: url('${weightUrl}') format('woff2');\n font-display: fallback;\n font-weight: ${weight};\n }\n `.trim();\n }\n }\n }\n\n return str;\n}",
|
|
94
|
+
getFontCss:
|
|
95
|
+
"@builder.io/mitosis/method:getFontCss({\n customFonts\n}: {\n customFonts?: CustomFont[];\n}) {\n // TODO: flag for this\n // if (!this.builder.allowCustomFonts) {\n // return '';\n // }\n // TODO: separate internal data from external\n return customFonts?.map(font => getCssFromFont(props,state,font))?.join(' ') || '';\n}",
|
|
96
|
+
injectedStyles:
|
|
97
|
+
"@builder.io/mitosis/method:get injectedStyles() {\n return `\n${props.cssCode || ''}\n${getFontCss(props,state,{\n customFonts: props.customFonts\n })}`;\n}",
|
|
98
|
+
},
|
|
99
|
+
children: [
|
|
100
|
+
{
|
|
101
|
+
"@type": "@builder.io/mitosis/node",
|
|
102
|
+
name: "RenderInlinedStyles",
|
|
103
|
+
meta: {},
|
|
104
|
+
scope: {},
|
|
105
|
+
properties: {},
|
|
106
|
+
bindings: {
|
|
107
|
+
styles: {
|
|
108
|
+
code: "injectedStyles(props,state)",
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
children: [],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
hooks: {},
|
|
115
|
+
context: {
|
|
116
|
+
get: {},
|
|
117
|
+
set: {},
|
|
118
|
+
},
|
|
119
|
+
name: "RenderContentStyles",
|
|
120
|
+
subComponents: [],
|
|
121
|
+
interfaces: [
|
|
122
|
+
"interface CustomFont {\n family?: string;\n kind?: string;\n fileUrl?: string;\n files?: {\n [key: string]: string;\n };\n}",
|
|
123
|
+
"interface Props {\n cssCode?: string;\n customFonts?: CustomFont[];\n}",
|
|
124
|
+
],
|
|
125
|
+
propsTypeRef: "Props",
|
|
126
|
+
};
|