@builder.io/sdk-qwik 0.0.5 → 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.
@@ -14,20 +14,17 @@ import {
14
14
  createRegisterComponentMessage,
15
15
  } from "../../functions/register-component.js";
16
16
  import { track } from "../../functions/track.js";
17
- import {
18
- registerInsertMenu,
19
- setupBrowserForEditing,
20
- } from "../../scripts/init-editing.js";
21
17
  import RenderBlocks from "../render-blocks";
22
18
  import RenderContentStyles from "./components/render-styles";
23
19
  import {
24
20
  Fragment,
25
- Host,
21
+ _useMutableProps,
26
22
  component$,
27
23
  h,
28
24
  useCleanup$,
29
25
  useClientEffect$,
30
26
  useContextProvider,
27
+ useHostElement,
31
28
  useStore,
32
29
  useWatch$,
33
30
  } from "@builder.io/qwik";
@@ -187,6 +184,7 @@ export const shouldRenderContentStyles = function shouldRenderContentStyles(
187
184
  );
188
185
  };
189
186
  export const RenderContent = component$((props) => {
187
+ const hostElement = useHostElement();
190
188
  const state = useStore({
191
189
  overrideContent: null,
192
190
  update: 0,
@@ -215,8 +213,7 @@ export const RenderContent = component$((props) => {
215
213
  useClientEffect$(() => {
216
214
  if (isBrowser()) {
217
215
  if (isEditing()) {
218
- registerInsertMenu();
219
- setupBrowserForEditing();
216
+ _useMutableProps(hostElement, true);
220
217
  Object.values(allRegisteredComponents(props, state)).forEach(
221
218
  (registeredComponent) => {
222
219
  const message = createRegisterComponentMessage(registeredComponent);
@@ -292,7 +289,7 @@ export const RenderContent = component$((props) => {
292
289
  }
293
290
  });
294
291
  return (
295
- <Host q:host-pseudo="">
292
+ <>
296
293
  {useContent(props, state) ? (
297
294
  <div
298
295
  onClick$={(event) => onClick(props, state, event)}
@@ -309,7 +306,7 @@ export const RenderContent = component$((props) => {
309
306
  ></RenderBlocks>
310
307
  </div>
311
308
  ) : null}
312
- </Host>
309
+ </>
313
310
  );
314
311
  });
315
312
  export default RenderContent;
@@ -370,13 +367,6 @@ export const COMPONENT = {
370
367
  },
371
368
  path: "../../functions/is-previewing.js",
372
369
  },
373
- {
374
- imports: {
375
- registerInsertMenu: "registerInsertMenu",
376
- setupBrowserForEditing: "setupBrowserForEditing",
377
- },
378
- path: "../../scripts/init-editing.js",
379
- },
380
370
  {
381
371
  imports: {
382
372
  components: "components",
@@ -405,7 +395,22 @@ export const COMPONENT = {
405
395
  ],
406
396
  exports: {},
407
397
  inputs: [],
408
- meta: {},
398
+ meta: {
399
+ useMetadata: {
400
+ qwik: {
401
+ component: {
402
+ useHostElement: true,
403
+ },
404
+ replace: {
405
+ "// QWIK-REPLACE: _useMutableProps":
406
+ "_useMutableProps(hostElement, true);",
407
+ },
408
+ imports: {
409
+ _useMutableProps: "@builder.io/qwik",
410
+ },
411
+ },
412
+ },
413
+ },
409
414
  refs: {},
410
415
  state: {
411
416
  useContent:
@@ -441,23 +446,40 @@ export const COMPONENT = {
441
446
  children: [
442
447
  {
443
448
  "@type": "@builder.io/mitosis/node",
444
- name: "Host",
449
+ name: "Show",
445
450
  meta: {},
446
451
  scope: {},
447
- properties: {
448
- "q:host-pseudo": "",
452
+ properties: {},
453
+ bindings: {
454
+ when: {
455
+ code: "useContent(props,state)",
456
+ },
449
457
  },
450
- bindings: {},
451
458
  children: [
452
459
  {
453
460
  "@type": "@builder.io/mitosis/node",
454
- name: "Show",
461
+ name: "div",
462
+ meta: {},
463
+ scope: {},
464
+ properties: {
465
+ _text: "\n ",
466
+ },
467
+ bindings: {},
468
+ children: [],
469
+ },
470
+ {
471
+ "@type": "@builder.io/mitosis/node",
472
+ name: "div",
455
473
  meta: {},
456
474
  scope: {},
457
475
  properties: {},
458
476
  bindings: {
459
- when: {
460
- code: "useContent(props,state)",
477
+ onClick: {
478
+ code: "onClick(props,state,event)",
479
+ arguments: ["event"],
480
+ },
481
+ "builder-content-id": {
482
+ code: "useContent(props,state)?.id",
461
483
  },
462
484
  },
463
485
  children: [
@@ -467,101 +489,37 @@ export const COMPONENT = {
467
489
  meta: {},
468
490
  scope: {},
469
491
  properties: {
470
- _text: "\n ",
492
+ _text: "\n ",
471
493
  },
472
494
  bindings: {},
473
495
  children: [],
474
496
  },
475
497
  {
476
498
  "@type": "@builder.io/mitosis/node",
477
- name: "div",
499
+ name: "Show",
478
500
  meta: {},
479
501
  scope: {},
480
502
  properties: {},
481
503
  bindings: {
482
- onClick: {
483
- code: "onClick(props,state,event)",
484
- arguments: ["event"],
485
- },
486
- "builder-content-id": {
487
- code: "useContent(props,state)?.id",
504
+ when: {
505
+ code: "shouldRenderContentStyles(props,state)",
488
506
  },
489
507
  },
490
508
  children: [
491
509
  {
492
510
  "@type": "@builder.io/mitosis/node",
493
- name: "div",
494
- meta: {},
495
- scope: {},
496
- properties: {
497
- _text: "\n ",
498
- },
499
- bindings: {},
500
- children: [],
501
- },
502
- {
503
- "@type": "@builder.io/mitosis/node",
504
- name: "Show",
511
+ name: "RenderContentStyles",
505
512
  meta: {},
506
513
  scope: {},
507
514
  properties: {},
508
515
  bindings: {
509
- when: {
510
- code: "shouldRenderContentStyles(props,state)",
516
+ cssCode: {
517
+ code: "useContent(props,state)?.data?.cssCode",
511
518
  },
512
- },
513
- children: [
514
- {
515
- "@type": "@builder.io/mitosis/node",
516
- name: "RenderContentStyles",
517
- meta: {},
518
- scope: {},
519
- properties: {},
520
- bindings: {
521
- cssCode: {
522
- code: "useContent(props,state)?.data?.cssCode",
523
- },
524
- customFonts: {
525
- code: "useContent(props,state)?.data?.customFonts",
526
- },
527
- },
528
- children: [],
519
+ customFonts: {
520
+ code: "useContent(props,state)?.data?.customFonts",
529
521
  },
530
- ],
531
- },
532
- {
533
- "@type": "@builder.io/mitosis/node",
534
- name: "div",
535
- meta: {},
536
- scope: {},
537
- properties: {
538
- _text: "\n ",
539
522
  },
540
- bindings: {},
541
- children: [],
542
- },
543
- {
544
- "@type": "@builder.io/mitosis/node",
545
- name: "RenderBlocks",
546
- meta: {},
547
- scope: {},
548
- properties: {},
549
- bindings: {
550
- blocks: {
551
- code: "useContent(props,state)?.data?.blocks",
552
- },
553
- },
554
- children: [],
555
- },
556
- {
557
- "@type": "@builder.io/mitosis/node",
558
- name: "div",
559
- meta: {},
560
- scope: {},
561
- properties: {
562
- _text: "\n ",
563
- },
564
- bindings: {},
565
523
  children: [],
566
524
  },
567
525
  ],
@@ -572,19 +530,54 @@ export const COMPONENT = {
572
530
  meta: {},
573
531
  scope: {},
574
532
  properties: {
575
- _text: "\n ",
533
+ _text: "\n ",
534
+ },
535
+ bindings: {},
536
+ children: [],
537
+ },
538
+ {
539
+ "@type": "@builder.io/mitosis/node",
540
+ name: "RenderBlocks",
541
+ meta: {},
542
+ scope: {},
543
+ properties: {},
544
+ bindings: {
545
+ blocks: {
546
+ code: "useContent(props,state)?.data?.blocks",
547
+ },
548
+ },
549
+ children: [],
550
+ },
551
+ {
552
+ "@type": "@builder.io/mitosis/node",
553
+ name: "div",
554
+ meta: {},
555
+ scope: {},
556
+ properties: {
557
+ _text: "\n ",
576
558
  },
577
559
  bindings: {},
578
560
  children: [],
579
561
  },
580
562
  ],
581
563
  },
564
+ {
565
+ "@type": "@builder.io/mitosis/node",
566
+ name: "div",
567
+ meta: {},
568
+ scope: {},
569
+ properties: {
570
+ _text: "\n ",
571
+ },
572
+ bindings: {},
573
+ children: [],
574
+ },
582
575
  ],
583
576
  },
584
577
  ],
585
578
  hooks: {
586
579
  onMount: {
587
- code: "\n if (isBrowser()) {\n if (isEditing()) {\n registerInsertMenu();\n setupBrowserForEditing();\n Object.values(allRegisteredComponents(props,state)).forEach(registeredComponent => {\n const message = createRegisterComponentMessage(registeredComponent);\n window.parent?.postMessage(message, '*');\n });\n window.addEventListener('message', processMessage.bind(null,props,state));\n window.addEventListener('builder:component:stateChangeListenerActivated', emitStateUpdate.bind(null,props,state));\n }\n\n if (useContent(props,state) && props.canTrack !== false) {\n track('impression', {\n contentId: useContent(props,state).id\n });\n } // override normal content in preview mode\n\n\n if (isPreviewing()) {\n const searchParams = new URL(location.href).searchParams;\n\n if (props.model && searchParams.get('builder.preview') === props.model) {\n const previewApiKey = searchParams.get('apiKey') || searchParams.get('builder.space');\n\n if (previewApiKey) {\n getContent({\n model: props.model,\n apiKey: previewApiKey\n }).then(content => {\n if (content) {\n state.overrideContent = content;\n }\n });\n }\n }\n }\n\n evaluateJsCode(props,state,);\n runHttpRequests(props,state,);\n emitStateUpdate(props,state,);\n }\n",
580
+ code: "\n if (isBrowser()) {\n if (isEditing()) {\n _useMutableProps(hostElement, true);\n Object.values(allRegisteredComponents(props,state)).forEach(registeredComponent => {\n const message = createRegisterComponentMessage(registeredComponent);\n window.parent?.postMessage(message, '*');\n });\n window.addEventListener('message', processMessage.bind(null,props,state));\n window.addEventListener('builder:component:stateChangeListenerActivated', emitStateUpdate.bind(null,props,state));\n }\n\n if (useContent(props,state) && props.canTrack !== false) {\n track('impression', {\n contentId: useContent(props,state).id\n });\n } // override normal content in preview mode\n\n\n if (isPreviewing()) {\n const searchParams = new URL(location.href).searchParams;\n\n if (props.model && searchParams.get('builder.preview') === props.model) {\n const previewApiKey = searchParams.get('apiKey') || searchParams.get('builder.space');\n\n if (previewApiKey) {\n getContent({\n model: props.model,\n apiKey: previewApiKey\n }).then(content => {\n if (content) {\n state.overrideContent = content;\n }\n });\n }\n }\n }\n\n evaluateJsCode(props,state,);\n runHttpRequests(props,state,);\n emitStateUpdate(props,state,);\n }\n",
588
581
  },
589
582
  onUpdate: [
590
583
  {
@@ -1,7 +1,7 @@
1
1
  // GENERATED BY MITOSIS
2
2
 
3
3
  import { TARGET } from "../constants/target.js";
4
- import { Fragment, Host, component$, h } from "@builder.io/qwik";
4
+ import { Fragment, component$, h } from "@builder.io/qwik";
5
5
  export const injectedStyleScript = function injectedStyleScript(props, state) {
6
6
  return `<${tagName(props, state)}>${props.styles}</${tagName(props, state)}>`;
7
7
  };
@@ -13,13 +13,13 @@ export const tagName = function tagName(props, state) {
13
13
  export const RenderInlinedStyles = component$((props) => {
14
14
  const state = {};
15
15
  return (
16
- <Host q:host-pseudo="">
16
+ <>
17
17
  {TARGET === "svelte" ? (
18
18
  <div dangerouslySetInnerHTML={injectedStyleScript(props, state)}></div>
19
19
  ) : (
20
20
  <state.tagName>{props.styles}</state.tagName>
21
21
  )}
22
- </Host>
22
+ </>
23
23
  );
24
24
  });
25
25
  export default RenderInlinedStyles;
@@ -46,72 +46,16 @@ export const COMPONENT = {
46
46
  children: [
47
47
  {
48
48
  "@type": "@builder.io/mitosis/node",
49
- name: "Host",
50
- meta: {},
51
- scope: {},
52
- properties: {
53
- "q:host-pseudo": "",
54
- },
55
- bindings: {},
56
- children: [
57
- {
49
+ name: "Show",
50
+ meta: {
51
+ else: {
58
52
  "@type": "@builder.io/mitosis/node",
59
- name: "Show",
60
- meta: {
61
- else: {
62
- "@type": "@builder.io/mitosis/node",
63
- name: "state.tagName",
64
- meta: {},
65
- scope: {},
66
- properties: {},
67
- bindings: {},
68
- children: [
69
- {
70
- "@type": "@builder.io/mitosis/node",
71
- name: "div",
72
- meta: {},
73
- scope: {},
74
- properties: {},
75
- bindings: {
76
- _text: {
77
- code: "props.styles",
78
- },
79
- },
80
- children: [],
81
- },
82
- ],
83
- },
84
- },
53
+ name: "state.tagName",
54
+ meta: {},
85
55
  scope: {},
86
56
  properties: {},
87
- bindings: {
88
- when: {
89
- code: "TARGET === 'svelte'",
90
- },
91
- },
57
+ bindings: {},
92
58
  children: [
93
- {
94
- "@type": "@builder.io/mitosis/node",
95
- name: "div",
96
- meta: {},
97
- scope: {},
98
- properties: {
99
- _text: "\n ",
100
- },
101
- bindings: {},
102
- children: [],
103
- },
104
- {
105
- "@type": "@builder.io/mitosis/node",
106
- name: "div",
107
- meta: {},
108
- scope: {},
109
- properties: {
110
- _text: "\n ",
111
- },
112
- bindings: {},
113
- children: [],
114
- },
115
59
  {
116
60
  "@type": "@builder.io/mitosis/node",
117
61
  name: "div",
@@ -119,25 +63,69 @@ export const COMPONENT = {
119
63
  scope: {},
120
64
  properties: {},
121
65
  bindings: {
122
- innerHTML: {
123
- code: "injectedStyleScript(props,state)",
66
+ _text: {
67
+ code: "props.styles",
124
68
  },
125
69
  },
126
70
  children: [],
127
71
  },
128
- {
129
- "@type": "@builder.io/mitosis/node",
130
- name: "div",
131
- meta: {},
132
- scope: {},
133
- properties: {
134
- _text: "\n ",
135
- },
136
- bindings: {},
137
- children: [],
138
- },
139
72
  ],
140
73
  },
74
+ },
75
+ scope: {},
76
+ properties: {},
77
+ bindings: {
78
+ when: {
79
+ code: "TARGET === 'svelte'",
80
+ },
81
+ },
82
+ children: [
83
+ {
84
+ "@type": "@builder.io/mitosis/node",
85
+ name: "div",
86
+ meta: {},
87
+ scope: {},
88
+ properties: {
89
+ _text: "\n ",
90
+ },
91
+ bindings: {},
92
+ children: [],
93
+ },
94
+ {
95
+ "@type": "@builder.io/mitosis/node",
96
+ name: "div",
97
+ meta: {},
98
+ scope: {},
99
+ properties: {
100
+ _text: "\n ",
101
+ },
102
+ bindings: {},
103
+ children: [],
104
+ },
105
+ {
106
+ "@type": "@builder.io/mitosis/node",
107
+ name: "div",
108
+ meta: {},
109
+ scope: {},
110
+ properties: {},
111
+ bindings: {
112
+ innerHTML: {
113
+ code: "injectedStyleScript(props,state)",
114
+ },
115
+ },
116
+ children: [],
117
+ },
118
+ {
119
+ "@type": "@builder.io/mitosis/node",
120
+ name: "div",
121
+ meta: {},
122
+ scope: {},
123
+ properties: {
124
+ _text: "\n ",
125
+ },
126
+ bindings: {},
127
+ children: [],
128
+ },
141
129
  ],
142
130
  },
143
131
  ],
@@ -80,9 +80,6 @@ function getAllContent(options) {
80
80
  return __async(this, null, function* () {
81
81
  const url = generateContentUrl(options);
82
82
  const fetch = yield fetch$;
83
- if (!fetch) {
84
- throw new Error("Please install a fetch polyfill");
85
- }
86
83
  const content = yield fetch(url.href).then((res) => res.json());
87
84
  if (options.testGroups) {
88
85
  for (const item of content.results) {
@@ -23,7 +23,8 @@ function getFetch() {
23
23
  return __async(this, null, function* () {
24
24
  const globalFetch = getGlobalThis().fetch;
25
25
  if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
26
- return import("node-fetch").then((d) => d.default || d);
26
+ const nodeFetch = import("node-fetch").then((d) => d.default);
27
+ return nodeFetch.default || nodeFetch;
27
28
  }
28
29
  return globalFetch.default || globalFetch;
29
30
  });
@@ -1,5 +1,6 @@
1
1
  import { TARGET } from "../constants/target.js";
2
2
  import { isBrowser } from "../functions/is-browser.js";
3
+ import { isEditing } from "../functions/is-editing.js";
3
4
  import { register } from "../functions/register.js";
4
5
  const registerInsertMenu = () => {
5
6
  register("insertMenu", {
@@ -73,7 +74,7 @@ const setupBrowserForEditing = () => {
73
74
  });
74
75
  }
75
76
  };
76
- export {
77
- registerInsertMenu,
78
- setupBrowserForEditing
79
- };
77
+ if (isEditing()) {
78
+ registerInsertMenu();
79
+ setupBrowserForEditing();
80
+ }
package/tsconfig.json CHANGED
@@ -105,6 +105,6 @@
105
105
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
106
106
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
107
107
  },
108
- "include": ["types-hacks.d.ts", "src"],
108
+ "include": ["types.d.ts", "src"],
109
109
  "exclude": ["src/blocks/form/form.tsx"]
110
110
  }
package/types.d.ts CHANGED
@@ -1,8 +1,13 @@
1
- declare module '@builder.io/sdk-qwik' {
2
- const getContent: (options: {
3
- model: string;
4
- apiKey: string;
5
- userAttributes: Record<string, string>;
6
- }) => Promise<any>;
7
- const RenderContent: any;
1
+ type Dictionary<T> = Record<string, T>;
2
+ type BuilderContent = any;
3
+ type BuilderBlock = any;
4
+ type RegisteredComponent = any;
5
+ type RegisteredComponents = any;
6
+ declare const builder: { env: 'dev'; apiKey: string };
7
+ // TODO(misko): HACKS to be removed
8
+ declare const get: (obj: any, key: string) => any;
9
+ declare const set: (obj: any, key: string, value: any) => void;
10
+ interface CSSProperties {
11
+ flexDirection: any;
8
12
  }
13
+ declare const BuilderBlocks: (props: any) => any;