@builder.io/sdk-qwik 0.4.6-0 → 0.5.1-0

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.
@@ -38,6 +38,8 @@ const STYLES$3 = `
38
38
  all: unset;
39
39
  }
40
40
  `;
41
+ const builderContext = qwik.createContextId("Builder");
42
+ const ComponentsContext = qwik.createContextId("Components");
41
43
  function getBlockComponentOptions(block) {
42
44
  return {
43
45
  ...block.component?.options,
@@ -45,6 +47,13 @@ function getBlockComponentOptions(block) {
45
47
  builderBlock: block
46
48
  };
47
49
  }
50
+ const MSG_PREFIX = "[Builder.io]: ";
51
+ const logger = {
52
+ log: (...message) => console.log(MSG_PREFIX, ...message),
53
+ error: (...message) => console.error(MSG_PREFIX, ...message),
54
+ warn: (...message) => console.warn(MSG_PREFIX, ...message),
55
+ debug: (...message) => console.debug(MSG_PREFIX, ...message)
56
+ };
48
57
  function isBrowser() {
49
58
  return typeof window !== "undefined" && typeof document !== "undefined";
50
59
  }
@@ -59,13 +68,6 @@ function isNonNodeServer() {
59
68
  const hasNode = () => typeof process !== "undefined" && process?.versions?.node;
60
69
  return !isBrowser() && !hasNode();
61
70
  }
62
- const MSG_PREFIX = "[Builder.io]: ";
63
- const logger = {
64
- log: (...message) => console.log(MSG_PREFIX, ...message),
65
- error: (...message) => console.error(MSG_PREFIX, ...message),
66
- warn: (...message) => console.warn(MSG_PREFIX, ...message),
67
- debug: (...message) => console.debug(MSG_PREFIX, ...message)
68
- };
69
71
  const set = (obj, _path, value) => {
70
72
  if (Object(obj) !== obj)
71
73
  return obj;
@@ -8099,9 +8101,7 @@ const processCode = (code) => {
8099
8101
  const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
8100
8102
  return `
8101
8103
  ${line}
8102
- if (Builder.isNonNodeRuntime) {
8103
- ${setExpr}
8104
- }
8104
+ ${setExpr}
8105
8105
  `;
8106
8106
  }).filter(Boolean).join("\n");
8107
8107
  };
@@ -8158,14 +8158,13 @@ theFunction();
8158
8158
  };
8159
8159
  function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
8160
8160
  if (code === "") {
8161
- console.warn("Skipping evaluation of empty code block.");
8161
+ logger.warn("Skipping evaluation of empty code block.");
8162
8162
  return;
8163
8163
  }
8164
8164
  const builder = {
8165
8165
  isEditing: isEditing(),
8166
8166
  isBrowser: isBrowser(),
8167
- isServer: !isBrowser(),
8168
- isNonNodeRuntime: isNonNodeServer()
8167
+ isServer: !isBrowser()
8169
8168
  };
8170
8169
  const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
8171
8170
  const useCode = useReturn ? `return (${code});` : code;
@@ -8180,21 +8179,21 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
8180
8179
  };
8181
8180
  if (isBrowser())
8182
8181
  return runInBrowser(args);
8183
- return runInNonNode({
8184
- ...args,
8185
- rootState,
8186
- localState,
8187
- rootSetState
8188
- });
8182
+ if (isNonNodeServer())
8183
+ return runInNonNode(args);
8184
+ return runInNode(args);
8189
8185
  }
8190
8186
  const runInBrowser = ({ useCode, builder, context, event, localState, rootSetState, rootState }) => {
8191
8187
  const state = flattenState(rootState, localState, rootSetState);
8192
8188
  try {
8193
8189
  return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
8194
8190
  } catch (e) {
8195
- console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
8191
+ logger.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
8196
8192
  }
8197
8193
  };
8194
+ const runInNode = (args) => {
8195
+ return runInBrowser(args);
8196
+ };
8198
8197
  function flattenState(rootState, localState, rootSetState) {
8199
8198
  if (rootState === localState)
8200
8199
  throw new Error("rootState === localState");
@@ -8670,7 +8669,6 @@ const ComponentRef = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inli
8670
8669
  }, 0, "z6_0") : null
8671
8670
  }, 1, "z6_1");
8672
8671
  }, "ComponentRef_component_tFQoBV6UFdc"));
8673
- const builderContext = qwik.createContextId("Builder");
8674
8672
  const RepeatedBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
8675
8673
  const state = qwik.useStore({
8676
8674
  store: props.repeatContext
@@ -8974,6 +8972,8 @@ const STYLES$2 = `
8974
8972
  }
8975
8973
  `;
8976
8974
  const Blocks = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
8975
+ const builderContext$1 = qwik.useContext(builderContext);
8976
+ const componentsContext = qwik.useContext(ComponentsContext);
8977
8977
  return /* @__PURE__ */ qwik._jsxC(BlocksWrapper, {
8978
8978
  get blocks() {
8979
8979
  return props.blocks;
@@ -8992,18 +8992,20 @@ const Blocks = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl
8992
8992
  return /* @__PURE__ */ qwik._jsxC(Block, {
8993
8993
  block,
8994
8994
  get context() {
8995
- return props.context;
8995
+ return props.context || builderContext$1;
8996
8996
  },
8997
8997
  get registeredComponents() {
8998
- return props.registeredComponents;
8998
+ return props.registeredComponents || componentsContext.registeredComponents;
8999
8999
  },
9000
9000
  [qwik._IMMUTABLE]: {
9001
- context: qwik._fnSignal((p0) => p0.context, [
9001
+ context: qwik._fnSignal((p0, p1) => p1.context || p0, [
9002
+ builderContext$1,
9002
9003
  props
9003
- ], "p0.context"),
9004
- registeredComponents: qwik._fnSignal((p0) => p0.registeredComponents, [
9004
+ ], "p1.context||p0"),
9005
+ registeredComponents: qwik._fnSignal((p0, p1) => p1.registeredComponents || p0.registeredComponents, [
9006
+ componentsContext,
9005
9007
  props
9006
- ], "p0.registeredComponents")
9008
+ ], "p1.registeredComponents||p0.registeredComponents")
9007
9009
  }
9008
9010
  }, 3, "render-block-" + block.id);
9009
9011
  }) : null,
@@ -9011,12 +9013,13 @@ const Blocks = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl
9011
9013
  return /* @__PURE__ */ qwik._jsxC(BlockStyles, {
9012
9014
  block,
9013
9015
  get context() {
9014
- return props.context;
9016
+ return props.context || builderContext$1;
9015
9017
  },
9016
9018
  [qwik._IMMUTABLE]: {
9017
- context: qwik._fnSignal((p0) => p0.context, [
9019
+ context: qwik._fnSignal((p0, p1) => p1.context || p0, [
9020
+ builderContext$1,
9018
9021
  props
9019
- ], "p0.context")
9022
+ ], "p1.context||p0")
9020
9023
  }
9021
9024
  }, 3, "block-style-" + block.id);
9022
9025
  }) : null
@@ -10825,7 +10828,7 @@ async function getContent(options) {
10825
10828
  ...options,
10826
10829
  limit: 1
10827
10830
  });
10828
- if (allContent && checkContentHasResults(allContent))
10831
+ if (allContent)
10829
10832
  return allContent.results[0] || null;
10830
10833
  return null;
10831
10834
  }
@@ -10865,7 +10868,7 @@ async function getAllContent(options) {
10865
10868
  content,
10866
10869
  options
10867
10870
  });
10868
- return content;
10871
+ return null;
10869
10872
  }
10870
10873
  return processContentResult(options, content);
10871
10874
  } catch (error) {
@@ -11112,7 +11115,7 @@ const getInteractionPropertiesForEvent = (event) => {
11112
11115
  }
11113
11116
  };
11114
11117
  };
11115
- const SDK_VERSION = "0.4.6-0";
11118
+ const SDK_VERSION = "0.5.1-0";
11116
11119
  const registry = {};
11117
11120
  function register(type, info) {
11118
11121
  let typeList = registry[type];
@@ -11658,6 +11661,9 @@ const ContentComponent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.
11658
11661
  }, {
11659
11662
  deep: true
11660
11663
  });
11664
+ qwik.useContextProvider(ComponentsContext, qwik.useStore({
11665
+ registeredComponents: state.registeredComponents
11666
+ }));
11661
11667
  return /* @__PURE__ */ qwik._jsxC(EnableEditor, {
11662
11668
  get content() {
11663
11669
  return props.content;
@@ -1,4 +1,4 @@
1
- import { componentQrl, inlinedQrl, useStylesScopedQrl, _jsxC, _jsxS, _fnSignal, _jsxQ, _jsxBranch, useStore, useComputedQrl, useLexicalScope, _IMMUTABLE, Slot, createContextId, useContextProvider, _wrapProp, createElement, Fragment as Fragment$1, useSignal, useTaskQrl, useVisibleTaskQrl } from "@builder.io/qwik";
1
+ import { componentQrl, inlinedQrl, useStylesScopedQrl, _jsxC, _jsxS, _fnSignal, createContextId, _jsxQ, _jsxBranch, useStore, useComputedQrl, useLexicalScope, _IMMUTABLE, Slot, useContextProvider, _wrapProp, useContext, createElement, Fragment as Fragment$1, useSignal, useTaskQrl, useVisibleTaskQrl } from "@builder.io/qwik";
2
2
  import { Fragment } from "@builder.io/qwik/jsx-runtime";
3
3
  const Button = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
4
4
  useStylesScopedQrl(/* @__PURE__ */ inlinedQrl(STYLES$3, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
@@ -36,6 +36,8 @@ const STYLES$3 = `
36
36
  all: unset;
37
37
  }
38
38
  `;
39
+ const builderContext = createContextId("Builder");
40
+ const ComponentsContext = createContextId("Components");
39
41
  function getBlockComponentOptions(block) {
40
42
  return {
41
43
  ...block.component?.options,
@@ -43,6 +45,13 @@ function getBlockComponentOptions(block) {
43
45
  builderBlock: block
44
46
  };
45
47
  }
48
+ const MSG_PREFIX = "[Builder.io]: ";
49
+ const logger = {
50
+ log: (...message) => console.log(MSG_PREFIX, ...message),
51
+ error: (...message) => console.error(MSG_PREFIX, ...message),
52
+ warn: (...message) => console.warn(MSG_PREFIX, ...message),
53
+ debug: (...message) => console.debug(MSG_PREFIX, ...message)
54
+ };
46
55
  function isBrowser() {
47
56
  return typeof window !== "undefined" && typeof document !== "undefined";
48
57
  }
@@ -57,13 +66,6 @@ function isNonNodeServer() {
57
66
  const hasNode = () => typeof process !== "undefined" && process?.versions?.node;
58
67
  return !isBrowser() && !hasNode();
59
68
  }
60
- const MSG_PREFIX = "[Builder.io]: ";
61
- const logger = {
62
- log: (...message) => console.log(MSG_PREFIX, ...message),
63
- error: (...message) => console.error(MSG_PREFIX, ...message),
64
- warn: (...message) => console.warn(MSG_PREFIX, ...message),
65
- debug: (...message) => console.debug(MSG_PREFIX, ...message)
66
- };
67
69
  const set = (obj, _path, value) => {
68
70
  if (Object(obj) !== obj)
69
71
  return obj;
@@ -8097,9 +8099,7 @@ const processCode = (code) => {
8097
8099
  const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
8098
8100
  return `
8099
8101
  ${line}
8100
- if (Builder.isNonNodeRuntime) {
8101
- ${setExpr}
8102
- }
8102
+ ${setExpr}
8103
8103
  `;
8104
8104
  }).filter(Boolean).join("\n");
8105
8105
  };
@@ -8156,14 +8156,13 @@ theFunction();
8156
8156
  };
8157
8157
  function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
8158
8158
  if (code === "") {
8159
- console.warn("Skipping evaluation of empty code block.");
8159
+ logger.warn("Skipping evaluation of empty code block.");
8160
8160
  return;
8161
8161
  }
8162
8162
  const builder = {
8163
8163
  isEditing: isEditing(),
8164
8164
  isBrowser: isBrowser(),
8165
- isServer: !isBrowser(),
8166
- isNonNodeRuntime: isNonNodeServer()
8165
+ isServer: !isBrowser()
8167
8166
  };
8168
8167
  const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
8169
8168
  const useCode = useReturn ? `return (${code});` : code;
@@ -8178,21 +8177,21 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
8178
8177
  };
8179
8178
  if (isBrowser())
8180
8179
  return runInBrowser(args);
8181
- return runInNonNode({
8182
- ...args,
8183
- rootState,
8184
- localState,
8185
- rootSetState
8186
- });
8180
+ if (isNonNodeServer())
8181
+ return runInNonNode(args);
8182
+ return runInNode(args);
8187
8183
  }
8188
8184
  const runInBrowser = ({ useCode, builder, context, event, localState, rootSetState, rootState }) => {
8189
8185
  const state = flattenState(rootState, localState, rootSetState);
8190
8186
  try {
8191
8187
  return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
8192
8188
  } catch (e) {
8193
- console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
8189
+ logger.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
8194
8190
  }
8195
8191
  };
8192
+ const runInNode = (args) => {
8193
+ return runInBrowser(args);
8194
+ };
8196
8195
  function flattenState(rootState, localState, rootSetState) {
8197
8196
  if (rootState === localState)
8198
8197
  throw new Error("rootState === localState");
@@ -8668,7 +8667,6 @@ const ComponentRef = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pr
8668
8667
  }, 0, "z6_0") : null
8669
8668
  }, 1, "z6_1");
8670
8669
  }, "ComponentRef_component_tFQoBV6UFdc"));
8671
- const builderContext = createContextId("Builder");
8672
8670
  const RepeatedBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
8673
8671
  const state = useStore({
8674
8672
  store: props.repeatContext
@@ -8972,6 +8970,8 @@ const STYLES$2 = `
8972
8970
  }
8973
8971
  `;
8974
8972
  const Blocks = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
8973
+ const builderContext$1 = useContext(builderContext);
8974
+ const componentsContext = useContext(ComponentsContext);
8975
8975
  return /* @__PURE__ */ _jsxC(BlocksWrapper, {
8976
8976
  get blocks() {
8977
8977
  return props.blocks;
@@ -8990,18 +8990,20 @@ const Blocks = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) =
8990
8990
  return /* @__PURE__ */ _jsxC(Block, {
8991
8991
  block,
8992
8992
  get context() {
8993
- return props.context;
8993
+ return props.context || builderContext$1;
8994
8994
  },
8995
8995
  get registeredComponents() {
8996
- return props.registeredComponents;
8996
+ return props.registeredComponents || componentsContext.registeredComponents;
8997
8997
  },
8998
8998
  [_IMMUTABLE]: {
8999
- context: _fnSignal((p0) => p0.context, [
8999
+ context: _fnSignal((p0, p1) => p1.context || p0, [
9000
+ builderContext$1,
9000
9001
  props
9001
- ], "p0.context"),
9002
- registeredComponents: _fnSignal((p0) => p0.registeredComponents, [
9002
+ ], "p1.context||p0"),
9003
+ registeredComponents: _fnSignal((p0, p1) => p1.registeredComponents || p0.registeredComponents, [
9004
+ componentsContext,
9003
9005
  props
9004
- ], "p0.registeredComponents")
9006
+ ], "p1.registeredComponents||p0.registeredComponents")
9005
9007
  }
9006
9008
  }, 3, "render-block-" + block.id);
9007
9009
  }) : null,
@@ -9009,12 +9011,13 @@ const Blocks = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) =
9009
9011
  return /* @__PURE__ */ _jsxC(BlockStyles, {
9010
9012
  block,
9011
9013
  get context() {
9012
- return props.context;
9014
+ return props.context || builderContext$1;
9013
9015
  },
9014
9016
  [_IMMUTABLE]: {
9015
- context: _fnSignal((p0) => p0.context, [
9017
+ context: _fnSignal((p0, p1) => p1.context || p0, [
9018
+ builderContext$1,
9016
9019
  props
9017
- ], "p0.context")
9020
+ ], "p1.context||p0")
9018
9021
  }
9019
9022
  }, 3, "block-style-" + block.id);
9020
9023
  }) : null
@@ -10823,7 +10826,7 @@ async function getContent(options) {
10823
10826
  ...options,
10824
10827
  limit: 1
10825
10828
  });
10826
- if (allContent && checkContentHasResults(allContent))
10829
+ if (allContent)
10827
10830
  return allContent.results[0] || null;
10828
10831
  return null;
10829
10832
  }
@@ -10863,7 +10866,7 @@ async function getAllContent(options) {
10863
10866
  content,
10864
10867
  options
10865
10868
  });
10866
- return content;
10869
+ return null;
10867
10870
  }
10868
10871
  return processContentResult(options, content);
10869
10872
  } catch (error) {
@@ -11110,7 +11113,7 @@ const getInteractionPropertiesForEvent = (event) => {
11110
11113
  }
11111
11114
  };
11112
11115
  };
11113
- const SDK_VERSION = "0.4.6-0";
11116
+ const SDK_VERSION = "0.5.1-0";
11114
11117
  const registry = {};
11115
11118
  function register(type, info) {
11116
11119
  let typeList = registry[type];
@@ -11656,6 +11659,9 @@ const ContentComponent = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl
11656
11659
  }, {
11657
11660
  deep: true
11658
11661
  });
11662
+ useContextProvider(ComponentsContext, useStore({
11663
+ registeredComponents: state.registeredComponents
11664
+ }));
11659
11665
  return /* @__PURE__ */ _jsxC(EnableEditor, {
11660
11666
  get content() {
11661
11667
  return props.content;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.4.6-0",
3
+ "version": "0.5.1-0",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
6
  "main": "./lib/index.qwik.cjs",
@@ -1,7 +1,7 @@
1
1
  import type { BuilderContextInterface, RegisteredComponents } from '../../../../context/types.js';
2
2
  import type { BuilderBlock } from '../../../../types/builder-block.js';
3
3
  import type { PropsWithBuilderData } from '../../../../types/builder-props.js';
4
- import type { InteractiveElementProps } from '../interactive-element';
4
+ import type { InteractiveElementProps } from '../interactive-element.js';
5
5
  type ComponentOptions = PropsWithBuilderData<{
6
6
  [index: string]: any;
7
7
  attributes?: {
@@ -1,8 +1,8 @@
1
1
  import { BuilderContextInterface, RegisteredComponents } from "../../context/types.js";
2
2
  import { BlocksWrapperProps } from "./blocks-wrapper";
3
3
  export type BlocksProps = Partial<BlocksWrapperProps> & {
4
- context: BuilderContextInterface;
5
- registeredComponents: RegisteredComponents;
4
+ context?: BuilderContextInterface;
5
+ registeredComponents?: RegisteredComponents;
6
6
  };
7
7
  export declare const Blocks: import("@builder.io/qwik").Component<BlocksProps>;
8
8
  export default Blocks;
@@ -1 +1 @@
1
- export { default } from './content';
1
+ export { default } from './content.js';
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.4.6-0";
1
+ export declare const SDK_VERSION = "0.5.1-0";
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@builder.io/qwik").ContextId<any>;
2
+ export default _default;
@@ -1,6 +1,5 @@
1
1
  import type { BuilderContextInterface, BuilderRenderState } from '../../context/types.js';
2
2
  import type { ExecutorArgs } from './types.js';
3
- export declare const isNode: () => boolean;
4
3
  export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: {
5
4
  code: string;
6
5
  event?: Event;
@@ -4,13 +4,9 @@ export declare function getContent(options: GetContentOptions): Promise<BuilderC
4
4
  type ContentResults = {
5
5
  results: BuilderContent[];
6
6
  };
7
- type ContentResponse = ContentResults | {
8
- status: number;
9
- message: string;
10
- };
11
7
  /**
12
8
  * Exported only for testing purposes. Should not be used directly.
13
9
  */
14
10
  export declare const processContentResult: (options: GetContentOptions, content: ContentResults, url?: URL) => Promise<ContentResults>;
15
- export declare function getAllContent(options: GetContentOptions): Promise<ContentResponse | null>;
11
+ export declare function getAllContent(options: GetContentOptions): Promise<ContentResults | null>;
16
12
  export {};
@@ -1,10 +1,10 @@
1
- export { default as Button } from '../blocks/button/button';
2
- export { default as Columns } from '../blocks/columns/columns';
3
- export { default as Fragment } from '../blocks/fragment/fragment';
4
- export { default as Image } from '../blocks/image/image';
5
- export { default as RenderBlocks } from '../components/blocks/blocks';
6
- export { default as Section } from '../blocks/section/section';
7
- export { default as Symbol } from '../blocks/symbol/symbol';
8
- export { default as Text } from '../blocks/text/text';
9
- export { default as Video } from '../blocks/video/video';
10
- export { default as RenderContent } from '../components/content-variants/content-variants';
1
+ export { default as Button } from '../blocks/button/button.js';
2
+ export { default as Columns } from '../blocks/columns/columns.js';
3
+ export { default as Fragment } from '../blocks/fragment/fragment.js';
4
+ export { default as Image } from '../blocks/image/image.js';
5
+ export { default as RenderBlocks } from '../components/blocks/blocks.js';
6
+ export { default as Section } from '../blocks/section/section.js';
7
+ export { default as Symbol } from '../blocks/symbol/symbol.js';
8
+ export { default as Text } from '../blocks/text/text.js';
9
+ export { default as Video } from '../blocks/video/video.js';
10
+ export { default as RenderContent } from '../components/content-variants/content-variants.js';