@builder.io/sdk-qwik 0.18.13 → 0.18.15

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.
Files changed (40) hide show
  1. package/lib/browser/blocks/form/form/form.qwik.cjs +30 -9
  2. package/lib/browser/blocks/form/form/form.qwik.mjs +30 -9
  3. package/lib/browser/blocks/personalization-container/helpers.qwik.cjs +4 -2
  4. package/lib/browser/blocks/personalization-container/helpers.qwik.mjs +4 -2
  5. package/lib/browser/blocks/personalization-container/personalization-container.qwik.cjs +18 -14
  6. package/lib/browser/blocks/personalization-container/personalization-container.qwik.mjs +20 -16
  7. package/lib/browser/constants/sdk-version.qwik.cjs +1 -1
  8. package/lib/browser/constants/sdk-version.qwik.mjs +1 -1
  9. package/lib/browser/helpers/no-serialize-wrapper.qwik.cjs +7 -0
  10. package/lib/browser/helpers/no-serialize-wrapper.qwik.mjs +7 -0
  11. package/lib/browser/helpers/user-attributes.qwik.cjs +15 -4
  12. package/lib/browser/helpers/user-attributes.qwik.mjs +15 -4
  13. package/lib/edge/blocks/form/form/form.qwik.cjs +30 -9
  14. package/lib/edge/blocks/form/form/form.qwik.mjs +30 -9
  15. package/lib/edge/blocks/personalization-container/helpers.qwik.cjs +4 -2
  16. package/lib/edge/blocks/personalization-container/helpers.qwik.mjs +4 -2
  17. package/lib/edge/blocks/personalization-container/personalization-container.qwik.cjs +18 -14
  18. package/lib/edge/blocks/personalization-container/personalization-container.qwik.mjs +20 -16
  19. package/lib/edge/constants/sdk-version.qwik.cjs +1 -1
  20. package/lib/edge/constants/sdk-version.qwik.mjs +1 -1
  21. package/lib/edge/helpers/no-serialize-wrapper.qwik.cjs +7 -0
  22. package/lib/edge/helpers/no-serialize-wrapper.qwik.mjs +7 -0
  23. package/lib/edge/helpers/user-attributes.qwik.cjs +15 -4
  24. package/lib/edge/helpers/user-attributes.qwik.mjs +15 -4
  25. package/lib/node/blocks/form/form/form.qwik.cjs +30 -9
  26. package/lib/node/blocks/form/form/form.qwik.mjs +30 -9
  27. package/lib/node/blocks/personalization-container/helpers.qwik.cjs +4 -2
  28. package/lib/node/blocks/personalization-container/helpers.qwik.mjs +4 -2
  29. package/lib/node/blocks/personalization-container/personalization-container.qwik.cjs +18 -14
  30. package/lib/node/blocks/personalization-container/personalization-container.qwik.mjs +20 -16
  31. package/lib/node/constants/sdk-version.qwik.cjs +1 -1
  32. package/lib/node/constants/sdk-version.qwik.mjs +1 -1
  33. package/lib/node/helpers/no-serialize-wrapper.qwik.cjs +7 -0
  34. package/lib/node/helpers/no-serialize-wrapper.qwik.mjs +7 -0
  35. package/lib/node/helpers/user-attributes.qwik.cjs +15 -4
  36. package/lib/node/helpers/user-attributes.qwik.mjs +15 -4
  37. package/package.json +1 -1
  38. package/types/src/constants/sdk-version.d.ts +1 -1
  39. package/types/src/helpers/no-serialize-wrapper.d.ts +1 -0
  40. package/types/src/helpers/user-attributes.d.ts +6 -2
@@ -99,6 +99,15 @@ const onSubmit = function onSubmit2(props, state, formRef, event) {
99
99
  return;
100
100
  }
101
101
  state.formState = "sending";
102
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
103
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
104
+ console.error(message);
105
+ state.formState = "error";
106
+ mergeNewRootState(props, state, formRef, {
107
+ formErrorMessage: message
108
+ });
109
+ return;
110
+ }
102
111
  const formUrl = `${getEnv.getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(props.sendSubmissionsToEmail || "")}&name=${encodeURIComponent(props.name || "")}`;
103
112
  const url = props.sendSubmissionsTo === "email" ? formUrl : props.action;
104
113
  logFetch.logFetch(url);
@@ -113,16 +122,28 @@ const onSubmit = function onSubmit2(props, state, formRef, event) {
113
122
  body2 = await res.json();
114
123
  else
115
124
  body2 = await res.text();
116
- if (!res.ok && props.errorMessagePath) {
117
- let message = get.get(body2, props.errorMessagePath);
118
- if (message) {
119
- if (typeof message !== "string")
120
- message = JSON.stringify(message);
121
- state.formErrorMessage = message;
122
- mergeNewRootState(props, state, formRef, {
123
- formErrorMessage: message
124
- });
125
+ if (!res.ok) {
126
+ const submitErrorEvent = new CustomEvent("submit:error", {
127
+ detail: {
128
+ error: body2,
129
+ status: res.status
130
+ }
131
+ });
132
+ if (formRef.value.nativeElement) {
133
+ formRef.value.nativeElement.dispatchEvent(submitErrorEvent);
134
+ if (submitErrorEvent.defaultPrevented)
135
+ return;
125
136
  }
137
+ state.responseData = body2;
138
+ state.formState = "error";
139
+ let message = props.errorMessagePath ? get.get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
140
+ if (typeof message !== "string")
141
+ message = JSON.stringify(message);
142
+ state.formErrorMessage = message;
143
+ mergeNewRootState(props, state, formRef, {
144
+ formErrorMessage: message
145
+ });
146
+ return;
126
147
  }
127
148
  state.responseData = body2;
128
149
  state.formState = res.ok ? "success" : "error";
@@ -97,6 +97,15 @@ const onSubmit = function onSubmit2(props, state, formRef, event) {
97
97
  return;
98
98
  }
99
99
  state.formState = "sending";
100
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
101
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
102
+ console.error(message);
103
+ state.formState = "error";
104
+ mergeNewRootState(props, state, formRef, {
105
+ formErrorMessage: message
106
+ });
107
+ return;
108
+ }
100
109
  const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(props.sendSubmissionsToEmail || "")}&name=${encodeURIComponent(props.name || "")}`;
101
110
  const url = props.sendSubmissionsTo === "email" ? formUrl : props.action;
102
111
  logFetch(url);
@@ -111,16 +120,28 @@ const onSubmit = function onSubmit2(props, state, formRef, event) {
111
120
  body2 = await res.json();
112
121
  else
113
122
  body2 = await res.text();
114
- if (!res.ok && props.errorMessagePath) {
115
- let message = get(body2, props.errorMessagePath);
116
- if (message) {
117
- if (typeof message !== "string")
118
- message = JSON.stringify(message);
119
- state.formErrorMessage = message;
120
- mergeNewRootState(props, state, formRef, {
121
- formErrorMessage: message
122
- });
123
+ if (!res.ok) {
124
+ const submitErrorEvent = new CustomEvent("submit:error", {
125
+ detail: {
126
+ error: body2,
127
+ status: res.status
128
+ }
129
+ });
130
+ if (formRef.value.nativeElement) {
131
+ formRef.value.nativeElement.dispatchEvent(submitErrorEvent);
132
+ if (submitErrorEvent.defaultPrevented)
133
+ return;
123
134
  }
135
+ state.responseData = body2;
136
+ state.formState = "error";
137
+ let message = props.errorMessagePath ? get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
138
+ if (typeof message !== "string")
139
+ message = JSON.stringify(message);
140
+ state.formErrorMessage = message;
141
+ mergeNewRootState(props, state, formRef, {
142
+ formErrorMessage: message
143
+ });
144
+ return;
124
145
  }
125
146
  state.responseData = body2;
126
147
  state.formState = res.ok ? "success" : "error";
@@ -11,11 +11,13 @@ const UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
11
11
  const SDKS_SUPPORTING_PERSONALIZATION = [
12
12
  "react",
13
13
  "vue",
14
- "svelte"
14
+ "svelte",
15
+ "qwik"
15
16
  ];
16
17
  const SDKS_REQUIRING_RESET_APPROACH = [
17
18
  "vue",
18
- "svelte"
19
+ "svelte",
20
+ "qwik"
19
21
  ];
20
22
  function checkShouldRenderVariants(variants, canTrack) {
21
23
  const hasVariants = variants && variants.length > 0;
@@ -10,11 +10,13 @@ const UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
10
10
  const SDKS_SUPPORTING_PERSONALIZATION = [
11
11
  "react",
12
12
  "vue",
13
- "svelte"
13
+ "svelte",
14
+ "qwik"
14
15
  ];
15
16
  const SDKS_REQUIRING_RESET_APPROACH = [
16
17
  "vue",
17
- "svelte"
18
+ "svelte",
19
+ "qwik"
18
20
  ];
19
21
  function checkShouldRenderVariants(variants, canTrack) {
20
22
  const hasVariants = variants && variants.length > 0;
@@ -16,6 +16,14 @@ const inlinedFns = require("./helpers/inlined-fns.qwik.cjs");
16
16
  const PersonalizationContainer = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
17
17
  var _a, _b, _c, _d, _e, _f, _g, _h;
18
18
  qwik._jsxBranch();
19
+ const state = qwik.useStore({
20
+ scriptStr: helpers.getPersonalizationScript(props.variants, ((_a = props.builderBlock) == null ? void 0 : _a.id) || "none", (_c = (_b = props.builderContext) == null ? void 0 : _b.rootState) == null ? void 0 : _c.locale),
21
+ shouldRenderVariants: helpers.checkShouldRenderVariants(props.variants, canTrack.getDefaultCanTrack((_d = props.builderContext) == null ? void 0 : _d.canTrack)),
22
+ shouldResetVariants: false,
23
+ unsubscribers: [],
24
+ updateVisibilityStylesScript: helpers.getUpdateVisibilityStylesScript(props.variants, ((_e = props.builderBlock) == null ? void 0 : _e.id) || "none", (_g = (_f = props.builderContext) == null ? void 0 : _f.rootState) == null ? void 0 : _g.locale),
25
+ userAttributes: userAttributes.userAttributesService.getUserAttributes()
26
+ });
19
27
  const attrs = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
20
28
  const [props2] = qwik.useLexicalScope();
21
29
  return {
@@ -26,32 +34,34 @@ const PersonalizationContainer = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__
26
34
  props
27
35
  ]));
28
36
  const filteredVariants = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
29
- const [props2] = qwik.useLexicalScope();
37
+ const [props2, state2] = qwik.useLexicalScope();
30
38
  return (props2.variants || []).filter((variant) => {
31
39
  var _a2, _b2, _c2, _d2;
32
40
  return inlinedFns.filterWithCustomTargeting({
33
41
  ...((_b2 = (_a2 = props2.builderContext) == null ? void 0 : _a2.rootState) == null ? void 0 : _b2.locale) ? {
34
42
  locale: (_d2 = (_c2 = props2.builderContext) == null ? void 0 : _c2.rootState) == null ? void 0 : _d2.locale
35
43
  } : {},
36
- ...state.userAttributes
44
+ ...state2.userAttributes
37
45
  }, variant.query, variant.startDate, variant.endDate);
38
46
  });
39
47
  }, "PersonalizationContainer_component_filteredVariants_useComputed_0jlgEflkxcQ", [
40
- props
48
+ props,
49
+ state
41
50
  ]));
42
51
  const blocksToRender = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
43
52
  var _a2;
44
- const [filteredVariants2, props2] = qwik.useLexicalScope();
53
+ const [filteredVariants2, props2, state2] = qwik.useLexicalScope();
45
54
  return helpers.getBlocksToRender({
46
55
  variants: props2.variants,
47
56
  fallbackBlocks: (_a2 = props2.builderBlock) == null ? void 0 : _a2.children,
48
- isHydrated: state.shouldResetVariants,
57
+ isHydrated: state2.shouldResetVariants,
49
58
  filteredVariants: filteredVariants2.value,
50
59
  previewingIndex: props2.previewingIndex
51
60
  });
52
61
  }, "PersonalizationContainer_component_blocksToRender_useComputed_aZOAYVB7Svg", [
53
62
  filteredVariants,
54
- props
63
+ props,
64
+ state
55
65
  ]));
56
66
  const hideVariantsStyleString = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
57
67
  const [props2] = qwik.useLexicalScope();
@@ -63,20 +73,14 @@ const PersonalizationContainer = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__
63
73
  props
64
74
  ]));
65
75
  const rootRef = qwik.useSignal();
66
- const state = qwik.useStore({
67
- scriptStr: helpers.getPersonalizationScript(props.variants, ((_a = props.builderBlock) == null ? void 0 : _a.id) || "none", (_c = (_b = props.builderContext) == null ? void 0 : _b.rootState) == null ? void 0 : _c.locale),
68
- shouldRenderVariants: helpers.checkShouldRenderVariants(props.variants, canTrack.getDefaultCanTrack((_d = props.builderContext) == null ? void 0 : _d.canTrack)),
69
- shouldResetVariants: false,
70
- unsubscribers: [],
71
- updateVisibilityStylesScript: helpers.getUpdateVisibilityStylesScript(props.variants, ((_e = props.builderBlock) == null ? void 0 : _e.id) || "none", (_g = (_f = props.builderContext) == null ? void 0 : _f.rootState) == null ? void 0 : _g.locale),
72
- userAttributes: userAttributes.userAttributesService.getUserAttributes()
73
- });
74
76
  qwik.useVisibleTaskQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
75
77
  var _a2;
76
78
  const [filteredVariants2, props2, rootRef2, state2] = qwik.useLexicalScope();
77
79
  state2.shouldResetVariants = true;
78
80
  const unsub = userAttributes.userAttributesService.subscribeOnUserAttributesChange((attrs2) => {
79
81
  state2.userAttributes = attrs2;
82
+ }, {
83
+ fireImmediately: target.TARGET === "qwik"
80
84
  });
81
85
  if (!(isEditing.isEditing() || isPreviewing.isPreviewing())) {
82
86
  const variant = filteredVariants2.value[0];
@@ -1,4 +1,4 @@
1
- import { componentQrl, inlinedQrl, _jsxBranch, useComputedQrl, useLexicalScope, useSignal, useStore, useVisibleTaskQrl, _jsxS, _jsxC, _IMMUTABLE, _fnSignal, _wrapProp } from "@builder.io/qwik";
1
+ import { componentQrl, inlinedQrl, _jsxBranch, useStore, useComputedQrl, useLexicalScope, useSignal, useVisibleTaskQrl, _jsxS, _jsxC, _IMMUTABLE, _fnSignal, _wrapProp } from "@builder.io/qwik";
2
2
  import { Fragment } from "@builder.io/qwik/jsx-runtime";
3
3
  import { Blocks } from "../../components/blocks/blocks.qwik.mjs";
4
4
  import { InlinedScript } from "../../components/inlined-script.qwik.mjs";
@@ -9,11 +9,19 @@ import { isEditing } from "../../functions/is-editing.qwik.mjs";
9
9
  import { isPreviewing } from "../../functions/is-previewing.qwik.mjs";
10
10
  import { getDefaultCanTrack } from "../../helpers/canTrack.qwik.mjs";
11
11
  import { userAttributesService } from "../../helpers/user-attributes.qwik.mjs";
12
- import { getBlocksToRender, getPersonalizationScript, checkShouldRenderVariants, getUpdateVisibilityStylesScript, DEFAULT_INDEX, SDKS_REQUIRING_RESET_APPROACH } from "./helpers.qwik.mjs";
12
+ import { getPersonalizationScript, checkShouldRenderVariants, getUpdateVisibilityStylesScript, getBlocksToRender, DEFAULT_INDEX, SDKS_REQUIRING_RESET_APPROACH } from "./helpers.qwik.mjs";
13
13
  import { filterWithCustomTargeting } from "./helpers/inlined-fns.qwik.mjs";
14
14
  const PersonalizationContainer = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
15
15
  var _a, _b, _c, _d, _e, _f, _g, _h;
16
16
  _jsxBranch();
17
+ const state = useStore({
18
+ scriptStr: getPersonalizationScript(props.variants, ((_a = props.builderBlock) == null ? void 0 : _a.id) || "none", (_c = (_b = props.builderContext) == null ? void 0 : _b.rootState) == null ? void 0 : _c.locale),
19
+ shouldRenderVariants: checkShouldRenderVariants(props.variants, getDefaultCanTrack((_d = props.builderContext) == null ? void 0 : _d.canTrack)),
20
+ shouldResetVariants: false,
21
+ unsubscribers: [],
22
+ updateVisibilityStylesScript: getUpdateVisibilityStylesScript(props.variants, ((_e = props.builderBlock) == null ? void 0 : _e.id) || "none", (_g = (_f = props.builderContext) == null ? void 0 : _f.rootState) == null ? void 0 : _g.locale),
23
+ userAttributes: userAttributesService.getUserAttributes()
24
+ });
17
25
  const attrs = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
18
26
  const [props2] = useLexicalScope();
19
27
  return {
@@ -24,32 +32,34 @@ const PersonalizationContainer = /* @__PURE__ */ componentQrl(/* @__PURE__ */ in
24
32
  props
25
33
  ]));
26
34
  const filteredVariants = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
27
- const [props2] = useLexicalScope();
35
+ const [props2, state2] = useLexicalScope();
28
36
  return (props2.variants || []).filter((variant) => {
29
37
  var _a2, _b2, _c2, _d2;
30
38
  return filterWithCustomTargeting({
31
39
  ...((_b2 = (_a2 = props2.builderContext) == null ? void 0 : _a2.rootState) == null ? void 0 : _b2.locale) ? {
32
40
  locale: (_d2 = (_c2 = props2.builderContext) == null ? void 0 : _c2.rootState) == null ? void 0 : _d2.locale
33
41
  } : {},
34
- ...state.userAttributes
42
+ ...state2.userAttributes
35
43
  }, variant.query, variant.startDate, variant.endDate);
36
44
  });
37
45
  }, "PersonalizationContainer_component_filteredVariants_useComputed_0jlgEflkxcQ", [
38
- props
46
+ props,
47
+ state
39
48
  ]));
40
49
  const blocksToRender = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
41
50
  var _a2;
42
- const [filteredVariants2, props2] = useLexicalScope();
51
+ const [filteredVariants2, props2, state2] = useLexicalScope();
43
52
  return getBlocksToRender({
44
53
  variants: props2.variants,
45
54
  fallbackBlocks: (_a2 = props2.builderBlock) == null ? void 0 : _a2.children,
46
- isHydrated: state.shouldResetVariants,
55
+ isHydrated: state2.shouldResetVariants,
47
56
  filteredVariants: filteredVariants2.value,
48
57
  previewingIndex: props2.previewingIndex
49
58
  });
50
59
  }, "PersonalizationContainer_component_blocksToRender_useComputed_aZOAYVB7Svg", [
51
60
  filteredVariants,
52
- props
61
+ props,
62
+ state
53
63
  ]));
54
64
  const hideVariantsStyleString = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
55
65
  const [props2] = useLexicalScope();
@@ -61,20 +71,14 @@ const PersonalizationContainer = /* @__PURE__ */ componentQrl(/* @__PURE__ */ in
61
71
  props
62
72
  ]));
63
73
  const rootRef = useSignal();
64
- const state = useStore({
65
- scriptStr: getPersonalizationScript(props.variants, ((_a = props.builderBlock) == null ? void 0 : _a.id) || "none", (_c = (_b = props.builderContext) == null ? void 0 : _b.rootState) == null ? void 0 : _c.locale),
66
- shouldRenderVariants: checkShouldRenderVariants(props.variants, getDefaultCanTrack((_d = props.builderContext) == null ? void 0 : _d.canTrack)),
67
- shouldResetVariants: false,
68
- unsubscribers: [],
69
- updateVisibilityStylesScript: getUpdateVisibilityStylesScript(props.variants, ((_e = props.builderBlock) == null ? void 0 : _e.id) || "none", (_g = (_f = props.builderContext) == null ? void 0 : _f.rootState) == null ? void 0 : _g.locale),
70
- userAttributes: userAttributesService.getUserAttributes()
71
- });
72
74
  useVisibleTaskQrl(/* @__PURE__ */ inlinedQrl(() => {
73
75
  var _a2;
74
76
  const [filteredVariants2, props2, rootRef2, state2] = useLexicalScope();
75
77
  state2.shouldResetVariants = true;
76
78
  const unsub = userAttributesService.subscribeOnUserAttributesChange((attrs2) => {
77
79
  state2.userAttributes = attrs2;
80
+ }, {
81
+ fireImmediately: TARGET === "qwik"
78
82
  });
79
83
  if (!(isEditing() || isPreviewing())) {
80
84
  const variant = filteredVariants2.value[0];
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const SDK_VERSION = "0.18.13";
3
+ const SDK_VERSION = "0.18.15";
4
4
  exports.SDK_VERSION = SDK_VERSION;
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = "0.18.13";
1
+ const SDK_VERSION = "0.18.15";
2
2
  export {
3
3
  SDK_VERSION
4
4
  };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const qwik = require("@builder.io/qwik");
4
+ function noSerializeWrapper(fn) {
5
+ return qwik.noSerialize(fn);
6
+ }
7
+ exports.noSerializeWrapper = noSerializeWrapper;
@@ -0,0 +1,7 @@
1
+ import { noSerialize } from "@builder.io/qwik";
2
+ function noSerializeWrapper(fn) {
3
+ return noSerialize(fn);
4
+ }
5
+ export {
6
+ noSerializeWrapper
7
+ };
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const target = require("../constants/target.qwik.cjs");
3
4
  const isBrowser = require("../functions/is-browser.qwik.cjs");
4
5
  const cookie = require("./cookie.qwik.cjs");
6
+ const noSerializeWrapper = require("./no-serialize-wrapper.qwik.cjs");
5
7
  const USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
6
8
  function createUserAttributesService() {
7
9
  let canTrack = true;
@@ -29,18 +31,27 @@ function createUserAttributesService() {
29
31
  canTrack
30
32
  }) || "{}");
31
33
  },
32
- subscribeOnUserAttributesChange(callback) {
34
+ subscribeOnUserAttributesChange(callback, { fireImmediately } = {}) {
33
35
  subscribers.add(callback);
34
- return () => {
36
+ if (fireImmediately)
37
+ callback(this.getUserAttributes());
38
+ return noSerializeWrapper.noSerializeWrapper(function() {
35
39
  subscribers.delete(callback);
36
- };
40
+ });
37
41
  },
38
42
  setCanTrack(value) {
39
43
  canTrack = value;
40
44
  }
41
45
  };
42
46
  }
43
- const userAttributesService = createUserAttributesService();
47
+ let _userAttributesService;
48
+ if (isBrowser.isBrowser() && target.TARGET === "qwik") {
49
+ if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__)
50
+ window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
51
+ _userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
52
+ } else
53
+ _userAttributesService = createUserAttributesService();
54
+ const userAttributesService = _userAttributesService;
44
55
  const setClientUserAttributes = (attributes) => {
45
56
  userAttributesService.setUserAttributes(attributes);
46
57
  };
@@ -1,5 +1,7 @@
1
+ import { TARGET } from "../constants/target.qwik.mjs";
1
2
  import { isBrowser } from "../functions/is-browser.qwik.mjs";
2
3
  import { setCookie, getCookieSync } from "./cookie.qwik.mjs";
4
+ import { noSerializeWrapper } from "./no-serialize-wrapper.qwik.mjs";
3
5
  const USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
4
6
  function createUserAttributesService() {
5
7
  let canTrack = true;
@@ -27,18 +29,27 @@ function createUserAttributesService() {
27
29
  canTrack
28
30
  }) || "{}");
29
31
  },
30
- subscribeOnUserAttributesChange(callback) {
32
+ subscribeOnUserAttributesChange(callback, { fireImmediately } = {}) {
31
33
  subscribers.add(callback);
32
- return () => {
34
+ if (fireImmediately)
35
+ callback(this.getUserAttributes());
36
+ return noSerializeWrapper(function() {
33
37
  subscribers.delete(callback);
34
- };
38
+ });
35
39
  },
36
40
  setCanTrack(value) {
37
41
  canTrack = value;
38
42
  }
39
43
  };
40
44
  }
41
- const userAttributesService = createUserAttributesService();
45
+ let _userAttributesService;
46
+ if (isBrowser() && TARGET === "qwik") {
47
+ if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__)
48
+ window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
49
+ _userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
50
+ } else
51
+ _userAttributesService = createUserAttributesService();
52
+ const userAttributesService = _userAttributesService;
42
53
  const setClientUserAttributes = (attributes) => {
43
54
  userAttributesService.setUserAttributes(attributes);
44
55
  };
@@ -99,6 +99,15 @@ const onSubmit = function onSubmit2(props, state, formRef, event) {
99
99
  return;
100
100
  }
101
101
  state.formState = "sending";
102
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
103
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
104
+ console.error(message);
105
+ state.formState = "error";
106
+ mergeNewRootState(props, state, formRef, {
107
+ formErrorMessage: message
108
+ });
109
+ return;
110
+ }
102
111
  const formUrl = `${getEnv.getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(props.sendSubmissionsToEmail || "")}&name=${encodeURIComponent(props.name || "")}`;
103
112
  const url = props.sendSubmissionsTo === "email" ? formUrl : props.action;
104
113
  logFetch.logFetch(url);
@@ -113,16 +122,28 @@ const onSubmit = function onSubmit2(props, state, formRef, event) {
113
122
  body2 = await res.json();
114
123
  else
115
124
  body2 = await res.text();
116
- if (!res.ok && props.errorMessagePath) {
117
- let message = get.get(body2, props.errorMessagePath);
118
- if (message) {
119
- if (typeof message !== "string")
120
- message = JSON.stringify(message);
121
- state.formErrorMessage = message;
122
- mergeNewRootState(props, state, formRef, {
123
- formErrorMessage: message
124
- });
125
+ if (!res.ok) {
126
+ const submitErrorEvent = new CustomEvent("submit:error", {
127
+ detail: {
128
+ error: body2,
129
+ status: res.status
130
+ }
131
+ });
132
+ if (formRef.value.nativeElement) {
133
+ formRef.value.nativeElement.dispatchEvent(submitErrorEvent);
134
+ if (submitErrorEvent.defaultPrevented)
135
+ return;
125
136
  }
137
+ state.responseData = body2;
138
+ state.formState = "error";
139
+ let message = props.errorMessagePath ? get.get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
140
+ if (typeof message !== "string")
141
+ message = JSON.stringify(message);
142
+ state.formErrorMessage = message;
143
+ mergeNewRootState(props, state, formRef, {
144
+ formErrorMessage: message
145
+ });
146
+ return;
126
147
  }
127
148
  state.responseData = body2;
128
149
  state.formState = res.ok ? "success" : "error";
@@ -97,6 +97,15 @@ const onSubmit = function onSubmit2(props, state, formRef, event) {
97
97
  return;
98
98
  }
99
99
  state.formState = "sending";
100
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
101
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
102
+ console.error(message);
103
+ state.formState = "error";
104
+ mergeNewRootState(props, state, formRef, {
105
+ formErrorMessage: message
106
+ });
107
+ return;
108
+ }
100
109
  const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(props.sendSubmissionsToEmail || "")}&name=${encodeURIComponent(props.name || "")}`;
101
110
  const url = props.sendSubmissionsTo === "email" ? formUrl : props.action;
102
111
  logFetch(url);
@@ -111,16 +120,28 @@ const onSubmit = function onSubmit2(props, state, formRef, event) {
111
120
  body2 = await res.json();
112
121
  else
113
122
  body2 = await res.text();
114
- if (!res.ok && props.errorMessagePath) {
115
- let message = get(body2, props.errorMessagePath);
116
- if (message) {
117
- if (typeof message !== "string")
118
- message = JSON.stringify(message);
119
- state.formErrorMessage = message;
120
- mergeNewRootState(props, state, formRef, {
121
- formErrorMessage: message
122
- });
123
+ if (!res.ok) {
124
+ const submitErrorEvent = new CustomEvent("submit:error", {
125
+ detail: {
126
+ error: body2,
127
+ status: res.status
128
+ }
129
+ });
130
+ if (formRef.value.nativeElement) {
131
+ formRef.value.nativeElement.dispatchEvent(submitErrorEvent);
132
+ if (submitErrorEvent.defaultPrevented)
133
+ return;
123
134
  }
135
+ state.responseData = body2;
136
+ state.formState = "error";
137
+ let message = props.errorMessagePath ? get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
138
+ if (typeof message !== "string")
139
+ message = JSON.stringify(message);
140
+ state.formErrorMessage = message;
141
+ mergeNewRootState(props, state, formRef, {
142
+ formErrorMessage: message
143
+ });
144
+ return;
124
145
  }
125
146
  state.responseData = body2;
126
147
  state.formState = res.ok ? "success" : "error";
@@ -11,11 +11,13 @@ const UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
11
11
  const SDKS_SUPPORTING_PERSONALIZATION = [
12
12
  "react",
13
13
  "vue",
14
- "svelte"
14
+ "svelte",
15
+ "qwik"
15
16
  ];
16
17
  const SDKS_REQUIRING_RESET_APPROACH = [
17
18
  "vue",
18
- "svelte"
19
+ "svelte",
20
+ "qwik"
19
21
  ];
20
22
  function checkShouldRenderVariants(variants, canTrack) {
21
23
  const hasVariants = variants && variants.length > 0;
@@ -10,11 +10,13 @@ const UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
10
10
  const SDKS_SUPPORTING_PERSONALIZATION = [
11
11
  "react",
12
12
  "vue",
13
- "svelte"
13
+ "svelte",
14
+ "qwik"
14
15
  ];
15
16
  const SDKS_REQUIRING_RESET_APPROACH = [
16
17
  "vue",
17
- "svelte"
18
+ "svelte",
19
+ "qwik"
18
20
  ];
19
21
  function checkShouldRenderVariants(variants, canTrack) {
20
22
  const hasVariants = variants && variants.length > 0;
@@ -16,6 +16,14 @@ const inlinedFns = require("./helpers/inlined-fns.qwik.cjs");
16
16
  const PersonalizationContainer = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
17
17
  var _a, _b, _c, _d, _e, _f, _g, _h;
18
18
  qwik._jsxBranch();
19
+ const state = qwik.useStore({
20
+ scriptStr: helpers.getPersonalizationScript(props.variants, ((_a = props.builderBlock) == null ? void 0 : _a.id) || "none", (_c = (_b = props.builderContext) == null ? void 0 : _b.rootState) == null ? void 0 : _c.locale),
21
+ shouldRenderVariants: helpers.checkShouldRenderVariants(props.variants, canTrack.getDefaultCanTrack((_d = props.builderContext) == null ? void 0 : _d.canTrack)),
22
+ shouldResetVariants: false,
23
+ unsubscribers: [],
24
+ updateVisibilityStylesScript: helpers.getUpdateVisibilityStylesScript(props.variants, ((_e = props.builderBlock) == null ? void 0 : _e.id) || "none", (_g = (_f = props.builderContext) == null ? void 0 : _f.rootState) == null ? void 0 : _g.locale),
25
+ userAttributes: userAttributes.userAttributesService.getUserAttributes()
26
+ });
19
27
  const attrs = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
20
28
  const [props2] = qwik.useLexicalScope();
21
29
  return {
@@ -26,32 +34,34 @@ const PersonalizationContainer = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__
26
34
  props
27
35
  ]));
28
36
  const filteredVariants = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
29
- const [props2] = qwik.useLexicalScope();
37
+ const [props2, state2] = qwik.useLexicalScope();
30
38
  return (props2.variants || []).filter((variant) => {
31
39
  var _a2, _b2, _c2, _d2;
32
40
  return inlinedFns.filterWithCustomTargeting({
33
41
  ...((_b2 = (_a2 = props2.builderContext) == null ? void 0 : _a2.rootState) == null ? void 0 : _b2.locale) ? {
34
42
  locale: (_d2 = (_c2 = props2.builderContext) == null ? void 0 : _c2.rootState) == null ? void 0 : _d2.locale
35
43
  } : {},
36
- ...state.userAttributes
44
+ ...state2.userAttributes
37
45
  }, variant.query, variant.startDate, variant.endDate);
38
46
  });
39
47
  }, "PersonalizationContainer_component_filteredVariants_useComputed_0jlgEflkxcQ", [
40
- props
48
+ props,
49
+ state
41
50
  ]));
42
51
  const blocksToRender = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
43
52
  var _a2;
44
- const [filteredVariants2, props2] = qwik.useLexicalScope();
53
+ const [filteredVariants2, props2, state2] = qwik.useLexicalScope();
45
54
  return helpers.getBlocksToRender({
46
55
  variants: props2.variants,
47
56
  fallbackBlocks: (_a2 = props2.builderBlock) == null ? void 0 : _a2.children,
48
- isHydrated: state.shouldResetVariants,
57
+ isHydrated: state2.shouldResetVariants,
49
58
  filteredVariants: filteredVariants2.value,
50
59
  previewingIndex: props2.previewingIndex
51
60
  });
52
61
  }, "PersonalizationContainer_component_blocksToRender_useComputed_aZOAYVB7Svg", [
53
62
  filteredVariants,
54
- props
63
+ props,
64
+ state
55
65
  ]));
56
66
  const hideVariantsStyleString = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
57
67
  const [props2] = qwik.useLexicalScope();
@@ -63,20 +73,14 @@ const PersonalizationContainer = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__
63
73
  props
64
74
  ]));
65
75
  const rootRef = qwik.useSignal();
66
- const state = qwik.useStore({
67
- scriptStr: helpers.getPersonalizationScript(props.variants, ((_a = props.builderBlock) == null ? void 0 : _a.id) || "none", (_c = (_b = props.builderContext) == null ? void 0 : _b.rootState) == null ? void 0 : _c.locale),
68
- shouldRenderVariants: helpers.checkShouldRenderVariants(props.variants, canTrack.getDefaultCanTrack((_d = props.builderContext) == null ? void 0 : _d.canTrack)),
69
- shouldResetVariants: false,
70
- unsubscribers: [],
71
- updateVisibilityStylesScript: helpers.getUpdateVisibilityStylesScript(props.variants, ((_e = props.builderBlock) == null ? void 0 : _e.id) || "none", (_g = (_f = props.builderContext) == null ? void 0 : _f.rootState) == null ? void 0 : _g.locale),
72
- userAttributes: userAttributes.userAttributesService.getUserAttributes()
73
- });
74
76
  qwik.useVisibleTaskQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
75
77
  var _a2;
76
78
  const [filteredVariants2, props2, rootRef2, state2] = qwik.useLexicalScope();
77
79
  state2.shouldResetVariants = true;
78
80
  const unsub = userAttributes.userAttributesService.subscribeOnUserAttributesChange((attrs2) => {
79
81
  state2.userAttributes = attrs2;
82
+ }, {
83
+ fireImmediately: target.TARGET === "qwik"
80
84
  });
81
85
  if (!(isEditing.isEditing() || isPreviewing.isPreviewing())) {
82
86
  const variant = filteredVariants2.value[0];