@builder.io/sdk-qwik 0.0.2-0 → 0.0.2-1

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 CHANGED
@@ -1,7 +1,70 @@
1
1
  # Builder.io SDK for Qwik
2
2
 
3
- More info coming soon.
3
+ Use Qwik SDK to connect your Qwik application to Builder.io.
4
+
5
+ ## Installation
6
+
7
+ Installing the Qwik SDK is done in two steps:
8
+
9
+ 1. Set up Qwik-city project.
10
+ 2. Install the Qwik SDK into your Qwik-city project.
11
+
12
+ ### Set up Qwik-city project
13
+
14
+ 1. Follow the instructions on [Qwik-city](https://qwik.builder.io/qwikcity/overview)
15
+
16
+ ```bash
17
+ npm init qwik@latest
18
+ ```
19
+
20
+ Follow instructions for setting up Qwik-city project.
21
+
22
+ ### Install the Qwik SDK into your Qwik-city project
23
+
24
+ Add the following line to your `package.json` file:
25
+
26
+ ```bash
27
+ npm add --save @builder.io/sdk-qwik
28
+ ```
29
+
30
+ Add Qwik SDK code to a particular route (such as `src/routes/index.tsx`)
31
+
32
+ ```typscript
33
+ import { component$, Host, Resource, useResource$ } from "@builder.io/qwik";
34
+ import { DocumentHead, useLocation } from "@builder.io/qwik-city";
35
+ import { getContent, RenderContent } from "@builder.io/sdk-qwik";
36
+
37
+ export const BUILDER_PUBLIC_API_KEY = "YOUR_API_KEY_GOES_HERE"; // ggignore
38
+ export default component$(() => {
39
+ const location = useLocation();
40
+ const builderContentRsrc = useResource$<any>(() => {
41
+ return getContent({
42
+ model: "page",
43
+ apiKey: BUILDER_PUBLIC_API_KEY,
44
+ userAttributes: {
45
+ urlPath: location.pathname || "/",
46
+ },
47
+ });
48
+ });
49
+
50
+ return (
51
+ <Host>
52
+ <Resource
53
+ resource={builderContentRsrc}
54
+ onPending={() => <div>Loading...</div>}
55
+ onResolved={(content) => (
56
+ <RenderContent
57
+ model="page"
58
+ content={content}
59
+ apiKey={BUILDER_PUBLIC_API_KEY}
60
+ />
61
+ )}
62
+ />
63
+ </Host>
64
+ );
65
+ });
66
+ ```
4
67
 
5
68
  ## Mitosis
6
69
 
7
- This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](../../).
70
+ This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](https://github.com/BuilderIO/builder/tree/main/packages/sdks/src).
package/package.json CHANGED
@@ -1,22 +1,24 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.0.2-0",
3
+ "version": "0.0.2-1",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
- "main": "./src/index.js",
7
- "module": "./src/index.js",
6
+ "main": "./lib/index.qwik.cjs",
7
+ "module": "./lib/index.qwik.mjs",
8
+ "qwik": "./lib/index.qwik.mjs",
8
9
  "exports": {
9
10
  ".": {
10
11
  "import": "./lib/index.qwik.mjs",
11
12
  "require": "./lib/index.qwik.cjs"
12
13
  }
13
14
  },
15
+ "types": "./types.d.ts",
14
16
  "scripts": {
15
17
  "build.lib": "vite build --mode lib",
16
18
  "release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
17
19
  },
18
20
  "devDependencies": {
19
- "@builder.io/qwik": "0.0.39",
21
+ "@builder.io/qwik": "0.0.39-dev20220805031634",
20
22
  "@types/node": "latest",
21
23
  "typescript": "4.7.4",
22
24
  "vite": "3.0.2"
@@ -6,7 +6,7 @@ import {
6
6
  Host,
7
7
  component$,
8
8
  h,
9
- useScopedStyles$,
9
+ useStylesScoped$,
10
10
  } from "@builder.io/qwik";
11
11
  export const getGutterSize = function getGutterSize(props, state) {
12
12
  return typeof props.space === "number" ? props.space || 0 : 20;
@@ -65,7 +65,7 @@ export const columnCssVars = function columnCssVars(props, state) {
65
65
  };
66
66
  export const Columns = component$(
67
67
  (props) => {
68
- useScopedStyles$(STYLES);
68
+ useStylesScoped$(STYLES);
69
69
  const state = {};
70
70
  return (
71
71
  <Host
@@ -95,38 +95,17 @@ export const Columns = component$(
95
95
  { tagName: "div" }
96
96
  );
97
97
  export default Columns;
98
- export const STYLES = `
99
- .div-Columns {
100
- display: flex;
101
- align-items: stretch;
102
- line-height: normal;
103
- }
104
- @media (max-width: 999px) {
105
- .div-Columns {
106
- flex-direction: var(--flex-dir-tablet);
107
- }
108
- }
109
- @media (max-width: 639px) {
110
- .div-Columns {
111
- flex-direction: var(--flex-dir);
112
- }
113
- }
114
- .div-Columns-2 {
115
- flex-grow: 1;
116
- }
117
- @media (max-width: 999px) {
118
- .div-Columns-2 {
119
- width: var(--column-width-tablet) !important;
120
- margin-left: var(--column-margin-left-tablet) !important;
121
- }
122
- }
123
- @media (max-width: 639px) {
124
- .div-Columns-2 {
125
- width: var(--column-width) !important;
126
- margin-left: var(--column-margin-left) !important;
127
- }
128
- }
129
- `;
98
+ export const STYLES = `.div-Columns {
99
+ display: flex;
100
+ align-items: stretch;
101
+ line-height: normal; }@media (max-width: 999px) { .div-Columns {
102
+ flex-direction: var(--flex-dir-tablet); } }@media (max-width: 639px) { .div-Columns {
103
+ flex-direction: var(--flex-dir); } }.div-Columns-2 {
104
+ flex-grow: 1; }@media (max-width: 999px) { .div-Columns-2 {
105
+ width: var(--column-width-tablet) !important;
106
+ margin-left: var(--column-margin-left-tablet) !important; } }@media (max-width: 639px) { .div-Columns-2 {
107
+ width: var(--column-width) !important;
108
+ margin-left: var(--column-margin-left) !important; } }`;
130
109
  export const COMPONENT = {
131
110
  "@type": "@builder.io/mitosis/component",
132
111
  imports: [
@@ -47,7 +47,7 @@ export const Embed = component$(
47
47
  scriptsRun: [],
48
48
  ranInitFn: false,
49
49
  });
50
- useWatch$((track) => {
50
+ useWatch$(({ track }) => {
51
51
  state && track(state, "ranInitFn");
52
52
  if (elem && !state.ranInitFn) {
53
53
  state.ranInitFn = true;
@@ -11,8 +11,8 @@ import {
11
11
  h,
12
12
  useContext,
13
13
  useRef,
14
- useScopedStyles$,
15
14
  useStore,
15
+ useStylesScoped$,
16
16
  } from "@builder.io/qwik";
17
17
  export const submissionState = function submissionState(
18
18
  props,
@@ -243,7 +243,7 @@ export const onSubmit = function onSubmit(
243
243
  };
244
244
  export const FormComponent = component$(
245
245
  (props) => {
246
- useScopedStyles$(STYLES);
246
+ useStylesScoped$(STYLES);
247
247
  const builderContext = useContext(BuilderContext);
248
248
  const formRef = useRef();
249
249
  const state = useStore({
@@ -7,7 +7,7 @@ import {
7
7
  Slot,
8
8
  component$,
9
9
  h,
10
- useScopedStyles$,
10
+ useStylesScoped$,
11
11
  } from "@builder.io/qwik";
12
12
  export const srcSetToUse = function srcSetToUse(props, state) {
13
13
  const imageToUse = props.image || props.src;
@@ -41,7 +41,7 @@ export const webpSrcSet = function webpSrcSet(props, state) {
41
41
  };
42
42
  export const Image = component$(
43
43
  (props) => {
44
- useScopedStyles$(STYLES);
44
+ useStylesScoped$(STYLES);
45
45
  const state = {};
46
46
  return (
47
47
  <Host class="div-Image">
@@ -26,13 +26,13 @@ export const Symbol = component$(
26
26
  useClientEffect$(() => {
27
27
  state.content = props.symbol?.content;
28
28
  });
29
- useWatch$((track) => {
29
+ useWatch$(({ track }) => {
30
30
  props && track(props, "symbol");
31
31
  state.symbolContent = props.symbol?.content || null;
32
32
  state.symbolModel = props.symbol?.model || null;
33
33
  state.symbolEntry = props.symbol?.entry || null;
34
34
  });
35
- useWatch$((track) => {
35
+ useWatch$(({ track }) => {
36
36
  state && track(state, "symbolContent");
37
37
  state && track(state, "symbolModel");
38
38
  state && track(state, "symbolEntry");
@@ -10,7 +10,7 @@ import {
10
10
  component$,
11
11
  h,
12
12
  useContext,
13
- useScopedStyles$,
13
+ useStylesScoped$,
14
14
  } from "@builder.io/qwik";
15
15
  export const className = function className(props, state, builderContext) {
16
16
  return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
@@ -49,7 +49,7 @@ export const onMouseEnter = function onMouseEnter(
49
49
  };
50
50
  export const RenderBlocks = component$(
51
51
  (props) => {
52
- useScopedStyles$(STYLES);
52
+ useStylesScoped$(STYLES);
53
53
  const builderContext = useContext(BuilderContext);
54
54
  const state = {};
55
55
  return (
@@ -267,15 +267,15 @@ export const RenderContent = component$((props) => {
267
267
  emitStateUpdate(props, state);
268
268
  }
269
269
  });
270
- useWatch$((track) => {
270
+ useWatch$(({ track }) => {
271
271
  state.useContent?.data && track(state.useContent?.data, "jsCode");
272
272
  evaluateJsCode(props, state);
273
273
  });
274
- useWatch$((track) => {
274
+ useWatch$(({ track }) => {
275
275
  state.useContent?.data && track(state.useContent?.data, "httpRequests");
276
276
  runHttpRequests(props, state);
277
277
  });
278
- useWatch$((track) => {
278
+ useWatch$(({ track }) => {
279
279
  state && track(state, "contentState");
280
280
  emitStateUpdate(props, state);
281
281
  });
@@ -1,33 +1,28 @@
1
- import { isBrowser } from './is-browser.js';
2
- import { isEditing } from './is-editing.js';
3
- function evaluate({ code, context, state, event }) {
4
- if (code === '') {
5
- console.warn('Skipping evaluation of empty code block.');
1
+ import { isBrowser } from "./is-browser.js";
2
+ import { isEditing } from "./is-editing.js";
3
+ function evaluate({
4
+ code,
5
+ context,
6
+ state,
7
+ event
8
+ }) {
9
+ if (code === "") {
10
+ console.warn("Skipping evaluation of empty code block.");
6
11
  return;
7
12
  }
8
13
  const builder = {
9
14
  isEditing: isEditing(),
10
15
  isBrowser: isBrowser(),
11
- isServer: !isBrowser(),
16
+ isServer: !isBrowser()
12
17
  };
13
- const useReturn = !(
14
- code.includes(';') ||
15
- code.includes(' return ') ||
16
- code.trim().startsWith('return ')
17
- );
18
+ const useReturn = !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
18
19
  const useCode = useReturn ? `return (${code});` : code;
19
20
  try {
20
- return new Function(
21
- 'builder',
22
- 'Builder',
23
- 'state',
24
- 'context',
25
- 'event',
26
- useCode
27
- )(builder, builder, state, context, event);
21
+ return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
28
22
  } catch (e) {
29
- debugger;
30
- console.warn('Builder custom code error: ', e);
23
+ console.warn("Builder custom code error: ", e);
31
24
  }
32
25
  }
33
- export { evaluate };
26
+ export {
27
+ evaluate
28
+ };
@@ -80,6 +80,9 @@ 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
+ }
83
86
  const content = yield fetch(url.href).then((res) => res.json());
84
87
  if (options.testGroups) {
85
88
  for (const item of content.results) {
@@ -23,8 +23,7 @@ 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
- const nodeFetch = import("node-fetch").then((d) => d.default);
27
- return nodeFetch.default || nodeFetch;
26
+ return import("node-fetch").then((d) => d.default || d);
28
27
  }
29
28
  return globalFetch.default || globalFetch;
30
29
  });
@@ -11,8 +11,8 @@ function register(type, info) {
11
11
  type: "builder.register",
12
12
  data: {
13
13
  type,
14
- info,
15
- },
14
+ info
15
+ }
16
16
  };
17
17
  try {
18
18
  parent.postMessage(message, "*");
@@ -24,4 +24,6 @@ function register(type, info) {
24
24
  }
25
25
  }
26
26
  }
27
- export { register };
27
+ export {
28
+ register
29
+ };
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.d.ts", "src"],
108
+ "include": ["types-hacks.d.ts", "src"],
109
109
  "exclude": ["src/blocks/form/form.tsx"]
110
110
  }
@@ -0,0 +1,13 @@
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;
12
+ }
13
+ declare const BuilderBlocks: (props: any) => any;
package/types.d.ts CHANGED
@@ -1,13 +1,8 @@
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;
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;
12
8
  }
13
- declare const BuilderBlocks: (props: any) => any;
package/vite.config.ts CHANGED
@@ -10,6 +10,7 @@ export default defineConfig(() => {
10
10
  formats: ['es', 'cjs'],
11
11
  fileName: (format) => `index.qwik.${format === 'es' ? 'mjs' : 'cjs'}`,
12
12
  },
13
+ minify: false,
13
14
  },
14
15
  plugins: [qwikVite()],
15
16
  };