@builder.io/sdk-qwik 0.12.7 → 0.13.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.
- package/lib/browser/index.qwik.cjs +76 -36
- package/lib/browser/index.qwik.mjs +76 -36
- package/lib/edge/index.qwik.cjs +76 -36
- package/lib/edge/index.qwik.mjs +76 -36
- package/lib/node/index.qwik.cjs +76 -36
- package/lib/node/index.qwik.mjs +76 -36
- package/package.json +1 -1
- package/types/src/components/content-variants/helpers.d.ts +1 -1
- package/types/src/constants/sdk-version.d.ts +1 -1
- package/types/src/functions/get-content/types.d.ts +2 -2
- package/types/src/helpers/subscribe-to-editor.d.ts +35 -0
- package/types/src/server-index.d.ts +18 -3
- package/types/src/types/api-version.d.ts +1 -1
|
@@ -3253,10 +3253,9 @@ const generateContentUrl = (options) => {
|
|
|
3253
3253
|
if (!apiKey)
|
|
3254
3254
|
throw new Error("Missing API key");
|
|
3255
3255
|
if (![
|
|
3256
|
-
"v2",
|
|
3257
3256
|
"v3"
|
|
3258
3257
|
].includes(apiVersion))
|
|
3259
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
3258
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
3260
3259
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
3261
3260
|
noTraverse = true;
|
|
3262
3261
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
@@ -3352,17 +3351,6 @@ async function fetchEntries(options) {
|
|
|
3352
3351
|
}
|
|
3353
3352
|
}
|
|
3354
3353
|
const getAllContent = fetchEntries;
|
|
3355
|
-
const DEFAULT_TRUSTED_HOSTS = [
|
|
3356
|
-
"*.beta.builder.io",
|
|
3357
|
-
"beta.builder.io",
|
|
3358
|
-
"builder.io",
|
|
3359
|
-
"localhost",
|
|
3360
|
-
"qa.builder.io"
|
|
3361
|
-
];
|
|
3362
|
-
function isFromTrustedHost(trustedHosts, e) {
|
|
3363
|
-
const url = new URL(e.origin), hostname = url.hostname;
|
|
3364
|
-
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
3365
|
-
}
|
|
3366
3354
|
function isPreviewing() {
|
|
3367
3355
|
if (!isBrowser())
|
|
3368
3356
|
return false;
|
|
@@ -3562,7 +3550,18 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
3562
3550
|
}
|
|
3563
3551
|
};
|
|
3564
3552
|
};
|
|
3565
|
-
const
|
|
3553
|
+
const DEFAULT_TRUSTED_HOSTS = [
|
|
3554
|
+
"*.beta.builder.io",
|
|
3555
|
+
"beta.builder.io",
|
|
3556
|
+
"builder.io",
|
|
3557
|
+
"localhost",
|
|
3558
|
+
"qa.builder.io"
|
|
3559
|
+
];
|
|
3560
|
+
function isFromTrustedHost(trustedHosts, e) {
|
|
3561
|
+
const url = new URL(e.origin), hostname = url.hostname;
|
|
3562
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
3563
|
+
}
|
|
3564
|
+
const SDK_VERSION = "0.13.0";
|
|
3566
3565
|
const registry = {};
|
|
3567
3566
|
function register(type, info) {
|
|
3568
3567
|
let typeList = registry[type];
|
|
@@ -3698,6 +3697,53 @@ const setupBrowserForEditing = (options = {}) => {
|
|
|
3698
3697
|
});
|
|
3699
3698
|
}
|
|
3700
3699
|
};
|
|
3700
|
+
const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
3701
|
+
return (event) => {
|
|
3702
|
+
if (!isFromTrustedHost(trustedHosts, event))
|
|
3703
|
+
return;
|
|
3704
|
+
const { data } = event;
|
|
3705
|
+
if (data)
|
|
3706
|
+
switch (data.type) {
|
|
3707
|
+
case "builder.configureSdk":
|
|
3708
|
+
callbacks.configureSdk(data.data);
|
|
3709
|
+
break;
|
|
3710
|
+
case "builder.triggerAnimation":
|
|
3711
|
+
callbacks.animation(data.data);
|
|
3712
|
+
break;
|
|
3713
|
+
case "builder.contentUpdate": {
|
|
3714
|
+
const messageContent = data.data;
|
|
3715
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
3716
|
+
const contentData = messageContent.data;
|
|
3717
|
+
if (key === model)
|
|
3718
|
+
callbacks.contentUpdate(contentData);
|
|
3719
|
+
break;
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
};
|
|
3723
|
+
};
|
|
3724
|
+
const subscribeToEditor = (model, callback, options) => {
|
|
3725
|
+
if (!isBrowser) {
|
|
3726
|
+
logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
|
|
3727
|
+
return () => {
|
|
3728
|
+
};
|
|
3729
|
+
}
|
|
3730
|
+
setupBrowserForEditing();
|
|
3731
|
+
const listener = createEditorListener({
|
|
3732
|
+
callbacks: {
|
|
3733
|
+
contentUpdate: callback,
|
|
3734
|
+
animation: () => {
|
|
3735
|
+
},
|
|
3736
|
+
configureSdk: () => {
|
|
3737
|
+
}
|
|
3738
|
+
},
|
|
3739
|
+
model,
|
|
3740
|
+
trustedHosts: options == null ? void 0 : options.trustedHosts
|
|
3741
|
+
});
|
|
3742
|
+
window.addEventListener("message", listener);
|
|
3743
|
+
return () => {
|
|
3744
|
+
window.removeEventListener("message", listener);
|
|
3745
|
+
};
|
|
3746
|
+
};
|
|
3701
3747
|
const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
|
|
3702
3748
|
var _a, _b;
|
|
3703
3749
|
const combinedState = {
|
|
@@ -3727,40 +3773,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
|
|
|
3727
3773
|
props.builderContextSignal.content = newContentValue;
|
|
3728
3774
|
};
|
|
3729
3775
|
const processMessage = function processMessage2(props, state, elementRef, event) {
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
case "builder.configureSdk": {
|
|
3737
|
-
const messageContent = data.data;
|
|
3776
|
+
return createEditorListener({
|
|
3777
|
+
model: props.model,
|
|
3778
|
+
trustedHosts: props.trustedHosts,
|
|
3779
|
+
callbacks: {
|
|
3780
|
+
configureSdk: (messageContent) => {
|
|
3781
|
+
var _a;
|
|
3738
3782
|
const { breakpoints, contentId } = messageContent;
|
|
3739
3783
|
if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
|
|
3740
3784
|
return;
|
|
3741
|
-
if (breakpoints)
|
|
3785
|
+
if (breakpoints) {
|
|
3742
3786
|
mergeNewContent(props, state, elementRef, {
|
|
3743
3787
|
meta: {
|
|
3744
3788
|
breakpoints
|
|
3745
3789
|
}
|
|
3746
3790
|
});
|
|
3747
|
-
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3748
|
-
break;
|
|
3749
|
-
}
|
|
3750
|
-
case "builder.triggerAnimation":
|
|
3751
|
-
triggerAnimation(data.data);
|
|
3752
|
-
break;
|
|
3753
|
-
case "builder.contentUpdate": {
|
|
3754
|
-
const messageContent = data.data;
|
|
3755
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
3756
|
-
const contentData = messageContent.data;
|
|
3757
|
-
if (key === props.model) {
|
|
3758
|
-
mergeNewContent(props, state, elementRef, contentData);
|
|
3759
3791
|
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3760
3792
|
}
|
|
3761
|
-
|
|
3793
|
+
},
|
|
3794
|
+
animation: (animation) => {
|
|
3795
|
+
triggerAnimation(animation);
|
|
3796
|
+
},
|
|
3797
|
+
contentUpdate: (newContent) => {
|
|
3798
|
+
mergeNewContent(props, state, elementRef, newContent);
|
|
3799
|
+
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3762
3800
|
}
|
|
3763
3801
|
}
|
|
3802
|
+
})(event);
|
|
3764
3803
|
};
|
|
3765
3804
|
const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
|
|
3766
3805
|
var _a, _b;
|
|
@@ -4893,4 +4932,5 @@ exports.isEditing = isEditing;
|
|
|
4893
4932
|
exports.isPreviewing = isPreviewing;
|
|
4894
4933
|
exports.register = register;
|
|
4895
4934
|
exports.setEditorSettings = setEditorSettings;
|
|
4935
|
+
exports.subscribeToEditor = subscribeToEditor;
|
|
4896
4936
|
exports.track = track;
|
|
@@ -3251,10 +3251,9 @@ const generateContentUrl = (options) => {
|
|
|
3251
3251
|
if (!apiKey)
|
|
3252
3252
|
throw new Error("Missing API key");
|
|
3253
3253
|
if (![
|
|
3254
|
-
"v2",
|
|
3255
3254
|
"v3"
|
|
3256
3255
|
].includes(apiVersion))
|
|
3257
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
3256
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
3258
3257
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
3259
3258
|
noTraverse = true;
|
|
3260
3259
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
@@ -3350,17 +3349,6 @@ async function fetchEntries(options) {
|
|
|
3350
3349
|
}
|
|
3351
3350
|
}
|
|
3352
3351
|
const getAllContent = fetchEntries;
|
|
3353
|
-
const DEFAULT_TRUSTED_HOSTS = [
|
|
3354
|
-
"*.beta.builder.io",
|
|
3355
|
-
"beta.builder.io",
|
|
3356
|
-
"builder.io",
|
|
3357
|
-
"localhost",
|
|
3358
|
-
"qa.builder.io"
|
|
3359
|
-
];
|
|
3360
|
-
function isFromTrustedHost(trustedHosts, e) {
|
|
3361
|
-
const url = new URL(e.origin), hostname = url.hostname;
|
|
3362
|
-
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
3363
|
-
}
|
|
3364
3352
|
function isPreviewing() {
|
|
3365
3353
|
if (!isBrowser())
|
|
3366
3354
|
return false;
|
|
@@ -3560,7 +3548,18 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
3560
3548
|
}
|
|
3561
3549
|
};
|
|
3562
3550
|
};
|
|
3563
|
-
const
|
|
3551
|
+
const DEFAULT_TRUSTED_HOSTS = [
|
|
3552
|
+
"*.beta.builder.io",
|
|
3553
|
+
"beta.builder.io",
|
|
3554
|
+
"builder.io",
|
|
3555
|
+
"localhost",
|
|
3556
|
+
"qa.builder.io"
|
|
3557
|
+
];
|
|
3558
|
+
function isFromTrustedHost(trustedHosts, e) {
|
|
3559
|
+
const url = new URL(e.origin), hostname = url.hostname;
|
|
3560
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
3561
|
+
}
|
|
3562
|
+
const SDK_VERSION = "0.13.0";
|
|
3564
3563
|
const registry = {};
|
|
3565
3564
|
function register(type, info) {
|
|
3566
3565
|
let typeList = registry[type];
|
|
@@ -3696,6 +3695,53 @@ const setupBrowserForEditing = (options = {}) => {
|
|
|
3696
3695
|
});
|
|
3697
3696
|
}
|
|
3698
3697
|
};
|
|
3698
|
+
const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
3699
|
+
return (event) => {
|
|
3700
|
+
if (!isFromTrustedHost(trustedHosts, event))
|
|
3701
|
+
return;
|
|
3702
|
+
const { data } = event;
|
|
3703
|
+
if (data)
|
|
3704
|
+
switch (data.type) {
|
|
3705
|
+
case "builder.configureSdk":
|
|
3706
|
+
callbacks.configureSdk(data.data);
|
|
3707
|
+
break;
|
|
3708
|
+
case "builder.triggerAnimation":
|
|
3709
|
+
callbacks.animation(data.data);
|
|
3710
|
+
break;
|
|
3711
|
+
case "builder.contentUpdate": {
|
|
3712
|
+
const messageContent = data.data;
|
|
3713
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
3714
|
+
const contentData = messageContent.data;
|
|
3715
|
+
if (key === model)
|
|
3716
|
+
callbacks.contentUpdate(contentData);
|
|
3717
|
+
break;
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
};
|
|
3721
|
+
};
|
|
3722
|
+
const subscribeToEditor = (model, callback, options) => {
|
|
3723
|
+
if (!isBrowser) {
|
|
3724
|
+
logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
|
|
3725
|
+
return () => {
|
|
3726
|
+
};
|
|
3727
|
+
}
|
|
3728
|
+
setupBrowserForEditing();
|
|
3729
|
+
const listener = createEditorListener({
|
|
3730
|
+
callbacks: {
|
|
3731
|
+
contentUpdate: callback,
|
|
3732
|
+
animation: () => {
|
|
3733
|
+
},
|
|
3734
|
+
configureSdk: () => {
|
|
3735
|
+
}
|
|
3736
|
+
},
|
|
3737
|
+
model,
|
|
3738
|
+
trustedHosts: options == null ? void 0 : options.trustedHosts
|
|
3739
|
+
});
|
|
3740
|
+
window.addEventListener("message", listener);
|
|
3741
|
+
return () => {
|
|
3742
|
+
window.removeEventListener("message", listener);
|
|
3743
|
+
};
|
|
3744
|
+
};
|
|
3699
3745
|
const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
|
|
3700
3746
|
var _a, _b;
|
|
3701
3747
|
const combinedState = {
|
|
@@ -3725,40 +3771,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
|
|
|
3725
3771
|
props.builderContextSignal.content = newContentValue;
|
|
3726
3772
|
};
|
|
3727
3773
|
const processMessage = function processMessage2(props, state, elementRef, event) {
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
case "builder.configureSdk": {
|
|
3735
|
-
const messageContent = data.data;
|
|
3774
|
+
return createEditorListener({
|
|
3775
|
+
model: props.model,
|
|
3776
|
+
trustedHosts: props.trustedHosts,
|
|
3777
|
+
callbacks: {
|
|
3778
|
+
configureSdk: (messageContent) => {
|
|
3779
|
+
var _a;
|
|
3736
3780
|
const { breakpoints, contentId } = messageContent;
|
|
3737
3781
|
if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
|
|
3738
3782
|
return;
|
|
3739
|
-
if (breakpoints)
|
|
3783
|
+
if (breakpoints) {
|
|
3740
3784
|
mergeNewContent(props, state, elementRef, {
|
|
3741
3785
|
meta: {
|
|
3742
3786
|
breakpoints
|
|
3743
3787
|
}
|
|
3744
3788
|
});
|
|
3745
|
-
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3746
|
-
break;
|
|
3747
|
-
}
|
|
3748
|
-
case "builder.triggerAnimation":
|
|
3749
|
-
triggerAnimation(data.data);
|
|
3750
|
-
break;
|
|
3751
|
-
case "builder.contentUpdate": {
|
|
3752
|
-
const messageContent = data.data;
|
|
3753
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
3754
|
-
const contentData = messageContent.data;
|
|
3755
|
-
if (key === props.model) {
|
|
3756
|
-
mergeNewContent(props, state, elementRef, contentData);
|
|
3757
3789
|
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3758
3790
|
}
|
|
3759
|
-
|
|
3791
|
+
},
|
|
3792
|
+
animation: (animation) => {
|
|
3793
|
+
triggerAnimation(animation);
|
|
3794
|
+
},
|
|
3795
|
+
contentUpdate: (newContent) => {
|
|
3796
|
+
mergeNewContent(props, state, elementRef, newContent);
|
|
3797
|
+
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3760
3798
|
}
|
|
3761
3799
|
}
|
|
3800
|
+
})(event);
|
|
3762
3801
|
};
|
|
3763
3802
|
const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
|
|
3764
3803
|
var _a, _b;
|
|
@@ -4892,5 +4931,6 @@ export {
|
|
|
4892
4931
|
isPreviewing,
|
|
4893
4932
|
register,
|
|
4894
4933
|
setEditorSettings,
|
|
4934
|
+
subscribeToEditor,
|
|
4895
4935
|
track
|
|
4896
4936
|
};
|
package/lib/edge/index.qwik.cjs
CHANGED
|
@@ -6484,10 +6484,9 @@ const generateContentUrl = (options) => {
|
|
|
6484
6484
|
if (!apiKey)
|
|
6485
6485
|
throw new Error("Missing API key");
|
|
6486
6486
|
if (![
|
|
6487
|
-
"v2",
|
|
6488
6487
|
"v3"
|
|
6489
6488
|
].includes(apiVersion))
|
|
6490
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
6489
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
6491
6490
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
6492
6491
|
noTraverse = true;
|
|
6493
6492
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
@@ -6583,17 +6582,6 @@ async function fetchEntries(options) {
|
|
|
6583
6582
|
}
|
|
6584
6583
|
}
|
|
6585
6584
|
const getAllContent = fetchEntries;
|
|
6586
|
-
const DEFAULT_TRUSTED_HOSTS = [
|
|
6587
|
-
"*.beta.builder.io",
|
|
6588
|
-
"beta.builder.io",
|
|
6589
|
-
"builder.io",
|
|
6590
|
-
"localhost",
|
|
6591
|
-
"qa.builder.io"
|
|
6592
|
-
];
|
|
6593
|
-
function isFromTrustedHost(trustedHosts, e) {
|
|
6594
|
-
const url = new URL(e.origin), hostname = url.hostname;
|
|
6595
|
-
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
6596
|
-
}
|
|
6597
6585
|
function isPreviewing() {
|
|
6598
6586
|
if (!isBrowser())
|
|
6599
6587
|
return false;
|
|
@@ -6793,7 +6781,18 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
6793
6781
|
}
|
|
6794
6782
|
};
|
|
6795
6783
|
};
|
|
6796
|
-
const
|
|
6784
|
+
const DEFAULT_TRUSTED_HOSTS = [
|
|
6785
|
+
"*.beta.builder.io",
|
|
6786
|
+
"beta.builder.io",
|
|
6787
|
+
"builder.io",
|
|
6788
|
+
"localhost",
|
|
6789
|
+
"qa.builder.io"
|
|
6790
|
+
];
|
|
6791
|
+
function isFromTrustedHost(trustedHosts, e) {
|
|
6792
|
+
const url = new URL(e.origin), hostname = url.hostname;
|
|
6793
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
6794
|
+
}
|
|
6795
|
+
const SDK_VERSION = "0.13.0";
|
|
6797
6796
|
const registry = {};
|
|
6798
6797
|
function register(type, info) {
|
|
6799
6798
|
let typeList = registry[type];
|
|
@@ -6929,6 +6928,53 @@ const setupBrowserForEditing = (options = {}) => {
|
|
|
6929
6928
|
});
|
|
6930
6929
|
}
|
|
6931
6930
|
};
|
|
6931
|
+
const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
6932
|
+
return (event) => {
|
|
6933
|
+
if (!isFromTrustedHost(trustedHosts, event))
|
|
6934
|
+
return;
|
|
6935
|
+
const { data } = event;
|
|
6936
|
+
if (data)
|
|
6937
|
+
switch (data.type) {
|
|
6938
|
+
case "builder.configureSdk":
|
|
6939
|
+
callbacks.configureSdk(data.data);
|
|
6940
|
+
break;
|
|
6941
|
+
case "builder.triggerAnimation":
|
|
6942
|
+
callbacks.animation(data.data);
|
|
6943
|
+
break;
|
|
6944
|
+
case "builder.contentUpdate": {
|
|
6945
|
+
const messageContent = data.data;
|
|
6946
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
6947
|
+
const contentData = messageContent.data;
|
|
6948
|
+
if (key === model)
|
|
6949
|
+
callbacks.contentUpdate(contentData);
|
|
6950
|
+
break;
|
|
6951
|
+
}
|
|
6952
|
+
}
|
|
6953
|
+
};
|
|
6954
|
+
};
|
|
6955
|
+
const subscribeToEditor = (model, callback, options) => {
|
|
6956
|
+
if (!isBrowser) {
|
|
6957
|
+
logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
|
|
6958
|
+
return () => {
|
|
6959
|
+
};
|
|
6960
|
+
}
|
|
6961
|
+
setupBrowserForEditing();
|
|
6962
|
+
const listener = createEditorListener({
|
|
6963
|
+
callbacks: {
|
|
6964
|
+
contentUpdate: callback,
|
|
6965
|
+
animation: () => {
|
|
6966
|
+
},
|
|
6967
|
+
configureSdk: () => {
|
|
6968
|
+
}
|
|
6969
|
+
},
|
|
6970
|
+
model,
|
|
6971
|
+
trustedHosts: options == null ? void 0 : options.trustedHosts
|
|
6972
|
+
});
|
|
6973
|
+
window.addEventListener("message", listener);
|
|
6974
|
+
return () => {
|
|
6975
|
+
window.removeEventListener("message", listener);
|
|
6976
|
+
};
|
|
6977
|
+
};
|
|
6932
6978
|
const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
|
|
6933
6979
|
var _a, _b;
|
|
6934
6980
|
const combinedState = {
|
|
@@ -6958,40 +7004,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
|
|
|
6958
7004
|
props.builderContextSignal.content = newContentValue;
|
|
6959
7005
|
};
|
|
6960
7006
|
const processMessage = function processMessage2(props, state, elementRef, event) {
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
case "builder.configureSdk": {
|
|
6968
|
-
const messageContent = data.data;
|
|
7007
|
+
return createEditorListener({
|
|
7008
|
+
model: props.model,
|
|
7009
|
+
trustedHosts: props.trustedHosts,
|
|
7010
|
+
callbacks: {
|
|
7011
|
+
configureSdk: (messageContent) => {
|
|
7012
|
+
var _a;
|
|
6969
7013
|
const { breakpoints, contentId } = messageContent;
|
|
6970
7014
|
if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
|
|
6971
7015
|
return;
|
|
6972
|
-
if (breakpoints)
|
|
7016
|
+
if (breakpoints) {
|
|
6973
7017
|
mergeNewContent(props, state, elementRef, {
|
|
6974
7018
|
meta: {
|
|
6975
7019
|
breakpoints
|
|
6976
7020
|
}
|
|
6977
7021
|
});
|
|
6978
|
-
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
6979
|
-
break;
|
|
6980
|
-
}
|
|
6981
|
-
case "builder.triggerAnimation":
|
|
6982
|
-
triggerAnimation(data.data);
|
|
6983
|
-
break;
|
|
6984
|
-
case "builder.contentUpdate": {
|
|
6985
|
-
const messageContent = data.data;
|
|
6986
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
6987
|
-
const contentData = messageContent.data;
|
|
6988
|
-
if (key === props.model) {
|
|
6989
|
-
mergeNewContent(props, state, elementRef, contentData);
|
|
6990
7022
|
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
6991
7023
|
}
|
|
6992
|
-
|
|
7024
|
+
},
|
|
7025
|
+
animation: (animation) => {
|
|
7026
|
+
triggerAnimation(animation);
|
|
7027
|
+
},
|
|
7028
|
+
contentUpdate: (newContent) => {
|
|
7029
|
+
mergeNewContent(props, state, elementRef, newContent);
|
|
7030
|
+
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
6993
7031
|
}
|
|
6994
7032
|
}
|
|
7033
|
+
})(event);
|
|
6995
7034
|
};
|
|
6996
7035
|
const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
|
|
6997
7036
|
var _a, _b;
|
|
@@ -8124,4 +8163,5 @@ exports.isEditing = isEditing;
|
|
|
8124
8163
|
exports.isPreviewing = isPreviewing;
|
|
8125
8164
|
exports.register = register;
|
|
8126
8165
|
exports.setEditorSettings = setEditorSettings;
|
|
8166
|
+
exports.subscribeToEditor = subscribeToEditor;
|
|
8127
8167
|
exports.track = track;
|
package/lib/edge/index.qwik.mjs
CHANGED
|
@@ -6482,10 +6482,9 @@ const generateContentUrl = (options) => {
|
|
|
6482
6482
|
if (!apiKey)
|
|
6483
6483
|
throw new Error("Missing API key");
|
|
6484
6484
|
if (![
|
|
6485
|
-
"v2",
|
|
6486
6485
|
"v3"
|
|
6487
6486
|
].includes(apiVersion))
|
|
6488
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
6487
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
6489
6488
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
6490
6489
|
noTraverse = true;
|
|
6491
6490
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
@@ -6581,17 +6580,6 @@ async function fetchEntries(options) {
|
|
|
6581
6580
|
}
|
|
6582
6581
|
}
|
|
6583
6582
|
const getAllContent = fetchEntries;
|
|
6584
|
-
const DEFAULT_TRUSTED_HOSTS = [
|
|
6585
|
-
"*.beta.builder.io",
|
|
6586
|
-
"beta.builder.io",
|
|
6587
|
-
"builder.io",
|
|
6588
|
-
"localhost",
|
|
6589
|
-
"qa.builder.io"
|
|
6590
|
-
];
|
|
6591
|
-
function isFromTrustedHost(trustedHosts, e) {
|
|
6592
|
-
const url = new URL(e.origin), hostname = url.hostname;
|
|
6593
|
-
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
6594
|
-
}
|
|
6595
6583
|
function isPreviewing() {
|
|
6596
6584
|
if (!isBrowser())
|
|
6597
6585
|
return false;
|
|
@@ -6791,7 +6779,18 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
6791
6779
|
}
|
|
6792
6780
|
};
|
|
6793
6781
|
};
|
|
6794
|
-
const
|
|
6782
|
+
const DEFAULT_TRUSTED_HOSTS = [
|
|
6783
|
+
"*.beta.builder.io",
|
|
6784
|
+
"beta.builder.io",
|
|
6785
|
+
"builder.io",
|
|
6786
|
+
"localhost",
|
|
6787
|
+
"qa.builder.io"
|
|
6788
|
+
];
|
|
6789
|
+
function isFromTrustedHost(trustedHosts, e) {
|
|
6790
|
+
const url = new URL(e.origin), hostname = url.hostname;
|
|
6791
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
6792
|
+
}
|
|
6793
|
+
const SDK_VERSION = "0.13.0";
|
|
6795
6794
|
const registry = {};
|
|
6796
6795
|
function register(type, info) {
|
|
6797
6796
|
let typeList = registry[type];
|
|
@@ -6927,6 +6926,53 @@ const setupBrowserForEditing = (options = {}) => {
|
|
|
6927
6926
|
});
|
|
6928
6927
|
}
|
|
6929
6928
|
};
|
|
6929
|
+
const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
6930
|
+
return (event) => {
|
|
6931
|
+
if (!isFromTrustedHost(trustedHosts, event))
|
|
6932
|
+
return;
|
|
6933
|
+
const { data } = event;
|
|
6934
|
+
if (data)
|
|
6935
|
+
switch (data.type) {
|
|
6936
|
+
case "builder.configureSdk":
|
|
6937
|
+
callbacks.configureSdk(data.data);
|
|
6938
|
+
break;
|
|
6939
|
+
case "builder.triggerAnimation":
|
|
6940
|
+
callbacks.animation(data.data);
|
|
6941
|
+
break;
|
|
6942
|
+
case "builder.contentUpdate": {
|
|
6943
|
+
const messageContent = data.data;
|
|
6944
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
6945
|
+
const contentData = messageContent.data;
|
|
6946
|
+
if (key === model)
|
|
6947
|
+
callbacks.contentUpdate(contentData);
|
|
6948
|
+
break;
|
|
6949
|
+
}
|
|
6950
|
+
}
|
|
6951
|
+
};
|
|
6952
|
+
};
|
|
6953
|
+
const subscribeToEditor = (model, callback, options) => {
|
|
6954
|
+
if (!isBrowser) {
|
|
6955
|
+
logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
|
|
6956
|
+
return () => {
|
|
6957
|
+
};
|
|
6958
|
+
}
|
|
6959
|
+
setupBrowserForEditing();
|
|
6960
|
+
const listener = createEditorListener({
|
|
6961
|
+
callbacks: {
|
|
6962
|
+
contentUpdate: callback,
|
|
6963
|
+
animation: () => {
|
|
6964
|
+
},
|
|
6965
|
+
configureSdk: () => {
|
|
6966
|
+
}
|
|
6967
|
+
},
|
|
6968
|
+
model,
|
|
6969
|
+
trustedHosts: options == null ? void 0 : options.trustedHosts
|
|
6970
|
+
});
|
|
6971
|
+
window.addEventListener("message", listener);
|
|
6972
|
+
return () => {
|
|
6973
|
+
window.removeEventListener("message", listener);
|
|
6974
|
+
};
|
|
6975
|
+
};
|
|
6930
6976
|
const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
|
|
6931
6977
|
var _a, _b;
|
|
6932
6978
|
const combinedState = {
|
|
@@ -6956,40 +7002,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
|
|
|
6956
7002
|
props.builderContextSignal.content = newContentValue;
|
|
6957
7003
|
};
|
|
6958
7004
|
const processMessage = function processMessage2(props, state, elementRef, event) {
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
case "builder.configureSdk": {
|
|
6966
|
-
const messageContent = data.data;
|
|
7005
|
+
return createEditorListener({
|
|
7006
|
+
model: props.model,
|
|
7007
|
+
trustedHosts: props.trustedHosts,
|
|
7008
|
+
callbacks: {
|
|
7009
|
+
configureSdk: (messageContent) => {
|
|
7010
|
+
var _a;
|
|
6967
7011
|
const { breakpoints, contentId } = messageContent;
|
|
6968
7012
|
if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
|
|
6969
7013
|
return;
|
|
6970
|
-
if (breakpoints)
|
|
7014
|
+
if (breakpoints) {
|
|
6971
7015
|
mergeNewContent(props, state, elementRef, {
|
|
6972
7016
|
meta: {
|
|
6973
7017
|
breakpoints
|
|
6974
7018
|
}
|
|
6975
7019
|
});
|
|
6976
|
-
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
6977
|
-
break;
|
|
6978
|
-
}
|
|
6979
|
-
case "builder.triggerAnimation":
|
|
6980
|
-
triggerAnimation(data.data);
|
|
6981
|
-
break;
|
|
6982
|
-
case "builder.contentUpdate": {
|
|
6983
|
-
const messageContent = data.data;
|
|
6984
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
6985
|
-
const contentData = messageContent.data;
|
|
6986
|
-
if (key === props.model) {
|
|
6987
|
-
mergeNewContent(props, state, elementRef, contentData);
|
|
6988
7020
|
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
6989
7021
|
}
|
|
6990
|
-
|
|
7022
|
+
},
|
|
7023
|
+
animation: (animation) => {
|
|
7024
|
+
triggerAnimation(animation);
|
|
7025
|
+
},
|
|
7026
|
+
contentUpdate: (newContent) => {
|
|
7027
|
+
mergeNewContent(props, state, elementRef, newContent);
|
|
7028
|
+
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
6991
7029
|
}
|
|
6992
7030
|
}
|
|
7031
|
+
})(event);
|
|
6993
7032
|
};
|
|
6994
7033
|
const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
|
|
6995
7034
|
var _a, _b;
|
|
@@ -8123,5 +8162,6 @@ export {
|
|
|
8123
8162
|
isPreviewing,
|
|
8124
8163
|
register,
|
|
8125
8164
|
setEditorSettings,
|
|
8165
|
+
subscribeToEditor,
|
|
8126
8166
|
track
|
|
8127
8167
|
};
|
package/lib/node/index.qwik.cjs
CHANGED
|
@@ -3354,10 +3354,9 @@ const generateContentUrl = (options) => {
|
|
|
3354
3354
|
if (!apiKey)
|
|
3355
3355
|
throw new Error("Missing API key");
|
|
3356
3356
|
if (![
|
|
3357
|
-
"v2",
|
|
3358
3357
|
"v3"
|
|
3359
3358
|
].includes(apiVersion))
|
|
3360
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
3359
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
3361
3360
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
3362
3361
|
noTraverse = true;
|
|
3363
3362
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
@@ -3453,17 +3452,6 @@ async function fetchEntries(options) {
|
|
|
3453
3452
|
}
|
|
3454
3453
|
}
|
|
3455
3454
|
const getAllContent = fetchEntries;
|
|
3456
|
-
const DEFAULT_TRUSTED_HOSTS = [
|
|
3457
|
-
"*.beta.builder.io",
|
|
3458
|
-
"beta.builder.io",
|
|
3459
|
-
"builder.io",
|
|
3460
|
-
"localhost",
|
|
3461
|
-
"qa.builder.io"
|
|
3462
|
-
];
|
|
3463
|
-
function isFromTrustedHost(trustedHosts, e) {
|
|
3464
|
-
const url = new URL(e.origin), hostname = url.hostname;
|
|
3465
|
-
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
3466
|
-
}
|
|
3467
3455
|
function isPreviewing() {
|
|
3468
3456
|
if (!isBrowser())
|
|
3469
3457
|
return false;
|
|
@@ -3663,7 +3651,18 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
3663
3651
|
}
|
|
3664
3652
|
};
|
|
3665
3653
|
};
|
|
3666
|
-
const
|
|
3654
|
+
const DEFAULT_TRUSTED_HOSTS = [
|
|
3655
|
+
"*.beta.builder.io",
|
|
3656
|
+
"beta.builder.io",
|
|
3657
|
+
"builder.io",
|
|
3658
|
+
"localhost",
|
|
3659
|
+
"qa.builder.io"
|
|
3660
|
+
];
|
|
3661
|
+
function isFromTrustedHost(trustedHosts, e) {
|
|
3662
|
+
const url = new URL(e.origin), hostname = url.hostname;
|
|
3663
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
3664
|
+
}
|
|
3665
|
+
const SDK_VERSION = "0.13.0";
|
|
3667
3666
|
const registry = {};
|
|
3668
3667
|
function register(type, info) {
|
|
3669
3668
|
let typeList = registry[type];
|
|
@@ -3799,6 +3798,53 @@ const setupBrowserForEditing = (options = {}) => {
|
|
|
3799
3798
|
});
|
|
3800
3799
|
}
|
|
3801
3800
|
};
|
|
3801
|
+
const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
3802
|
+
return (event) => {
|
|
3803
|
+
if (!isFromTrustedHost(trustedHosts, event))
|
|
3804
|
+
return;
|
|
3805
|
+
const { data } = event;
|
|
3806
|
+
if (data)
|
|
3807
|
+
switch (data.type) {
|
|
3808
|
+
case "builder.configureSdk":
|
|
3809
|
+
callbacks.configureSdk(data.data);
|
|
3810
|
+
break;
|
|
3811
|
+
case "builder.triggerAnimation":
|
|
3812
|
+
callbacks.animation(data.data);
|
|
3813
|
+
break;
|
|
3814
|
+
case "builder.contentUpdate": {
|
|
3815
|
+
const messageContent = data.data;
|
|
3816
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
3817
|
+
const contentData = messageContent.data;
|
|
3818
|
+
if (key === model)
|
|
3819
|
+
callbacks.contentUpdate(contentData);
|
|
3820
|
+
break;
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
};
|
|
3824
|
+
};
|
|
3825
|
+
const subscribeToEditor = (model, callback, options) => {
|
|
3826
|
+
if (!isBrowser) {
|
|
3827
|
+
logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
|
|
3828
|
+
return () => {
|
|
3829
|
+
};
|
|
3830
|
+
}
|
|
3831
|
+
setupBrowserForEditing();
|
|
3832
|
+
const listener = createEditorListener({
|
|
3833
|
+
callbacks: {
|
|
3834
|
+
contentUpdate: callback,
|
|
3835
|
+
animation: () => {
|
|
3836
|
+
},
|
|
3837
|
+
configureSdk: () => {
|
|
3838
|
+
}
|
|
3839
|
+
},
|
|
3840
|
+
model,
|
|
3841
|
+
trustedHosts: options == null ? void 0 : options.trustedHosts
|
|
3842
|
+
});
|
|
3843
|
+
window.addEventListener("message", listener);
|
|
3844
|
+
return () => {
|
|
3845
|
+
window.removeEventListener("message", listener);
|
|
3846
|
+
};
|
|
3847
|
+
};
|
|
3802
3848
|
const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
|
|
3803
3849
|
var _a, _b;
|
|
3804
3850
|
const combinedState = {
|
|
@@ -3828,40 +3874,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
|
|
|
3828
3874
|
props.builderContextSignal.content = newContentValue;
|
|
3829
3875
|
};
|
|
3830
3876
|
const processMessage = function processMessage2(props, state, elementRef, event) {
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
case "builder.configureSdk": {
|
|
3838
|
-
const messageContent = data.data;
|
|
3877
|
+
return createEditorListener({
|
|
3878
|
+
model: props.model,
|
|
3879
|
+
trustedHosts: props.trustedHosts,
|
|
3880
|
+
callbacks: {
|
|
3881
|
+
configureSdk: (messageContent) => {
|
|
3882
|
+
var _a;
|
|
3839
3883
|
const { breakpoints, contentId } = messageContent;
|
|
3840
3884
|
if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
|
|
3841
3885
|
return;
|
|
3842
|
-
if (breakpoints)
|
|
3886
|
+
if (breakpoints) {
|
|
3843
3887
|
mergeNewContent(props, state, elementRef, {
|
|
3844
3888
|
meta: {
|
|
3845
3889
|
breakpoints
|
|
3846
3890
|
}
|
|
3847
3891
|
});
|
|
3848
|
-
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3849
|
-
break;
|
|
3850
|
-
}
|
|
3851
|
-
case "builder.triggerAnimation":
|
|
3852
|
-
triggerAnimation(data.data);
|
|
3853
|
-
break;
|
|
3854
|
-
case "builder.contentUpdate": {
|
|
3855
|
-
const messageContent = data.data;
|
|
3856
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
3857
|
-
const contentData = messageContent.data;
|
|
3858
|
-
if (key === props.model) {
|
|
3859
|
-
mergeNewContent(props, state, elementRef, contentData);
|
|
3860
3892
|
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3861
3893
|
}
|
|
3862
|
-
|
|
3894
|
+
},
|
|
3895
|
+
animation: (animation) => {
|
|
3896
|
+
triggerAnimation(animation);
|
|
3897
|
+
},
|
|
3898
|
+
contentUpdate: (newContent) => {
|
|
3899
|
+
mergeNewContent(props, state, elementRef, newContent);
|
|
3900
|
+
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3863
3901
|
}
|
|
3864
3902
|
}
|
|
3903
|
+
})(event);
|
|
3865
3904
|
};
|
|
3866
3905
|
const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
|
|
3867
3906
|
var _a, _b;
|
|
@@ -4994,4 +5033,5 @@ exports.isEditing = isEditing;
|
|
|
4994
5033
|
exports.isPreviewing = isPreviewing;
|
|
4995
5034
|
exports.register = register;
|
|
4996
5035
|
exports.setEditorSettings = setEditorSettings;
|
|
5036
|
+
exports.subscribeToEditor = subscribeToEditor;
|
|
4997
5037
|
exports.track = track;
|
package/lib/node/index.qwik.mjs
CHANGED
|
@@ -3352,10 +3352,9 @@ const generateContentUrl = (options) => {
|
|
|
3352
3352
|
if (!apiKey)
|
|
3353
3353
|
throw new Error("Missing API key");
|
|
3354
3354
|
if (![
|
|
3355
|
-
"v2",
|
|
3356
3355
|
"v3"
|
|
3357
3356
|
].includes(apiVersion))
|
|
3358
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
3357
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
3359
3358
|
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
|
|
3360
3359
|
noTraverse = true;
|
|
3361
3360
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
@@ -3451,17 +3450,6 @@ async function fetchEntries(options) {
|
|
|
3451
3450
|
}
|
|
3452
3451
|
}
|
|
3453
3452
|
const getAllContent = fetchEntries;
|
|
3454
|
-
const DEFAULT_TRUSTED_HOSTS = [
|
|
3455
|
-
"*.beta.builder.io",
|
|
3456
|
-
"beta.builder.io",
|
|
3457
|
-
"builder.io",
|
|
3458
|
-
"localhost",
|
|
3459
|
-
"qa.builder.io"
|
|
3460
|
-
];
|
|
3461
|
-
function isFromTrustedHost(trustedHosts, e) {
|
|
3462
|
-
const url = new URL(e.origin), hostname = url.hostname;
|
|
3463
|
-
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
3464
|
-
}
|
|
3465
3453
|
function isPreviewing() {
|
|
3466
3454
|
if (!isBrowser())
|
|
3467
3455
|
return false;
|
|
@@ -3661,7 +3649,18 @@ const getInteractionPropertiesForEvent = (event) => {
|
|
|
3661
3649
|
}
|
|
3662
3650
|
};
|
|
3663
3651
|
};
|
|
3664
|
-
const
|
|
3652
|
+
const DEFAULT_TRUSTED_HOSTS = [
|
|
3653
|
+
"*.beta.builder.io",
|
|
3654
|
+
"beta.builder.io",
|
|
3655
|
+
"builder.io",
|
|
3656
|
+
"localhost",
|
|
3657
|
+
"qa.builder.io"
|
|
3658
|
+
];
|
|
3659
|
+
function isFromTrustedHost(trustedHosts, e) {
|
|
3660
|
+
const url = new URL(e.origin), hostname = url.hostname;
|
|
3661
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
3662
|
+
}
|
|
3663
|
+
const SDK_VERSION = "0.13.0";
|
|
3665
3664
|
const registry = {};
|
|
3666
3665
|
function register(type, info) {
|
|
3667
3666
|
let typeList = registry[type];
|
|
@@ -3797,6 +3796,53 @@ const setupBrowserForEditing = (options = {}) => {
|
|
|
3797
3796
|
});
|
|
3798
3797
|
}
|
|
3799
3798
|
};
|
|
3799
|
+
const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
3800
|
+
return (event) => {
|
|
3801
|
+
if (!isFromTrustedHost(trustedHosts, event))
|
|
3802
|
+
return;
|
|
3803
|
+
const { data } = event;
|
|
3804
|
+
if (data)
|
|
3805
|
+
switch (data.type) {
|
|
3806
|
+
case "builder.configureSdk":
|
|
3807
|
+
callbacks.configureSdk(data.data);
|
|
3808
|
+
break;
|
|
3809
|
+
case "builder.triggerAnimation":
|
|
3810
|
+
callbacks.animation(data.data);
|
|
3811
|
+
break;
|
|
3812
|
+
case "builder.contentUpdate": {
|
|
3813
|
+
const messageContent = data.data;
|
|
3814
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
3815
|
+
const contentData = messageContent.data;
|
|
3816
|
+
if (key === model)
|
|
3817
|
+
callbacks.contentUpdate(contentData);
|
|
3818
|
+
break;
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
};
|
|
3822
|
+
};
|
|
3823
|
+
const subscribeToEditor = (model, callback, options) => {
|
|
3824
|
+
if (!isBrowser) {
|
|
3825
|
+
logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
|
|
3826
|
+
return () => {
|
|
3827
|
+
};
|
|
3828
|
+
}
|
|
3829
|
+
setupBrowserForEditing();
|
|
3830
|
+
const listener = createEditorListener({
|
|
3831
|
+
callbacks: {
|
|
3832
|
+
contentUpdate: callback,
|
|
3833
|
+
animation: () => {
|
|
3834
|
+
},
|
|
3835
|
+
configureSdk: () => {
|
|
3836
|
+
}
|
|
3837
|
+
},
|
|
3838
|
+
model,
|
|
3839
|
+
trustedHosts: options == null ? void 0 : options.trustedHosts
|
|
3840
|
+
});
|
|
3841
|
+
window.addEventListener("message", listener);
|
|
3842
|
+
return () => {
|
|
3843
|
+
window.removeEventListener("message", listener);
|
|
3844
|
+
};
|
|
3845
|
+
};
|
|
3800
3846
|
const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
|
|
3801
3847
|
var _a, _b;
|
|
3802
3848
|
const combinedState = {
|
|
@@ -3826,40 +3872,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
|
|
|
3826
3872
|
props.builderContextSignal.content = newContentValue;
|
|
3827
3873
|
};
|
|
3828
3874
|
const processMessage = function processMessage2(props, state, elementRef, event) {
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
case "builder.configureSdk": {
|
|
3836
|
-
const messageContent = data.data;
|
|
3875
|
+
return createEditorListener({
|
|
3876
|
+
model: props.model,
|
|
3877
|
+
trustedHosts: props.trustedHosts,
|
|
3878
|
+
callbacks: {
|
|
3879
|
+
configureSdk: (messageContent) => {
|
|
3880
|
+
var _a;
|
|
3837
3881
|
const { breakpoints, contentId } = messageContent;
|
|
3838
3882
|
if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
|
|
3839
3883
|
return;
|
|
3840
|
-
if (breakpoints)
|
|
3884
|
+
if (breakpoints) {
|
|
3841
3885
|
mergeNewContent(props, state, elementRef, {
|
|
3842
3886
|
meta: {
|
|
3843
3887
|
breakpoints
|
|
3844
3888
|
}
|
|
3845
3889
|
});
|
|
3846
|
-
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3847
|
-
break;
|
|
3848
|
-
}
|
|
3849
|
-
case "builder.triggerAnimation":
|
|
3850
|
-
triggerAnimation(data.data);
|
|
3851
|
-
break;
|
|
3852
|
-
case "builder.contentUpdate": {
|
|
3853
|
-
const messageContent = data.data;
|
|
3854
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
3855
|
-
const contentData = messageContent.data;
|
|
3856
|
-
if (key === props.model) {
|
|
3857
|
-
mergeNewContent(props, state, elementRef, contentData);
|
|
3858
3890
|
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3859
3891
|
}
|
|
3860
|
-
|
|
3892
|
+
},
|
|
3893
|
+
animation: (animation) => {
|
|
3894
|
+
triggerAnimation(animation);
|
|
3895
|
+
},
|
|
3896
|
+
contentUpdate: (newContent) => {
|
|
3897
|
+
mergeNewContent(props, state, elementRef, newContent);
|
|
3898
|
+
state.forceReRenderCount = state.forceReRenderCount + 1;
|
|
3861
3899
|
}
|
|
3862
3900
|
}
|
|
3901
|
+
})(event);
|
|
3863
3902
|
};
|
|
3864
3903
|
const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
|
|
3865
3904
|
var _a, _b;
|
|
@@ -4993,5 +5032,6 @@ export {
|
|
|
4993
5032
|
isPreviewing,
|
|
4994
5033
|
register,
|
|
4995
5034
|
setEditorSettings,
|
|
5035
|
+
subscribeToEditor,
|
|
4996
5036
|
track
|
|
4997
5037
|
};
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ export declare const getVariants: (content: Nullable<BuilderContent>) => {
|
|
|
6
6
|
data?: {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
title?: string | undefined;
|
|
9
|
-
blocks?: import("../../
|
|
9
|
+
blocks?: import("../../server-index.js").BuilderBlock[] | undefined;
|
|
10
10
|
inputs?: import("../../types/input.js").Input[] | undefined;
|
|
11
11
|
state?: {
|
|
12
12
|
[key: string]: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.13.0";
|
|
@@ -76,9 +76,9 @@ export interface GetContentOptions {
|
|
|
76
76
|
/**
|
|
77
77
|
* If provided, sets the Builder API version used to fetch content.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
79
|
+
* Currently, the only available API version is `v3`.
|
|
80
80
|
*/
|
|
81
|
-
apiVersion?: '
|
|
81
|
+
apiVersion?: 'v3';
|
|
82
82
|
/**
|
|
83
83
|
* Only include these fields.
|
|
84
84
|
* Note: 'omit' takes precedence over 'fields'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ContentProps } from '../components/content/content.types.js';
|
|
2
|
+
import type { BuilderAnimation } from '../types/builder-block.js';
|
|
3
|
+
import type { BuilderContent } from '../types/builder-content.js';
|
|
4
|
+
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
5
|
+
callbacks: {
|
|
6
|
+
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
7
|
+
animation: (updatedContent: BuilderAnimation) => void;
|
|
8
|
+
configureSdk: (updatedContent: any) => void;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const createEditorListener: ({ model, trustedHosts, callbacks }: ContentListener) => (event: MessageEvent<any>) => void;
|
|
12
|
+
type SubscribeToEditor = (
|
|
13
|
+
/**
|
|
14
|
+
* The Builder `model` to subscribe to
|
|
15
|
+
*/
|
|
16
|
+
model: string,
|
|
17
|
+
/**
|
|
18
|
+
* The callback function to call when the content is updated.
|
|
19
|
+
*/
|
|
20
|
+
callback: (updatedContent: BuilderContent) => void,
|
|
21
|
+
/**
|
|
22
|
+
* Extra options for the listener.
|
|
23
|
+
*/
|
|
24
|
+
options?: {
|
|
25
|
+
/**
|
|
26
|
+
* List of hosts to allow editing content from.
|
|
27
|
+
*/
|
|
28
|
+
trustedHosts?: string[] | undefined;
|
|
29
|
+
}) => () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
|
|
32
|
+
* Sends the updated `content` to the `callback` function.
|
|
33
|
+
*/
|
|
34
|
+
export declare const subscribeToEditor: SubscribeToEditor;
|
|
35
|
+
export {};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
/**
|
|
3
|
+
* Component Prop types
|
|
4
|
+
*/
|
|
2
5
|
export type { ButtonProps } from './blocks/button/button.types.js';
|
|
3
6
|
export type { ColumnProps } from './blocks/columns/columns.types.js';
|
|
4
7
|
export type { FragmentProps } from './blocks/fragment/fragment.types.js';
|
|
@@ -9,6 +12,16 @@ export type { TextProps } from './blocks/text/text.types.js';
|
|
|
9
12
|
export type { VideoProps } from './blocks/video/video.types.js';
|
|
10
13
|
export type { BlocksProps } from './components/blocks/blocks.types.js';
|
|
11
14
|
export type { ContentVariantsPrps as ContentProps } from './components/content-variants/content-variants.types.js';
|
|
15
|
+
/**
|
|
16
|
+
* General Builder types
|
|
17
|
+
*/
|
|
18
|
+
export type { RegisteredComponent } from './context/types.js';
|
|
19
|
+
export type { BuilderBlock } from './types/builder-block.js';
|
|
20
|
+
export type { BuilderContent } from './types/builder-content.js';
|
|
21
|
+
export type { ComponentInfo } from './types/components.js';
|
|
22
|
+
/**
|
|
23
|
+
* Helper functions
|
|
24
|
+
*/
|
|
12
25
|
export { isEditing } from './functions/is-editing.js';
|
|
13
26
|
export { isPreviewing } from './functions/is-previewing.js';
|
|
14
27
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
@@ -16,9 +29,11 @@ export { register } from './functions/register.js';
|
|
|
16
29
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
17
30
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
18
31
|
export type { Settings } from './functions/set-editor-settings.js';
|
|
19
|
-
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
20
32
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
21
33
|
export { track } from './functions/track/index.js';
|
|
22
|
-
export
|
|
23
|
-
|
|
34
|
+
export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
|
|
35
|
+
/**
|
|
36
|
+
* Content fetching
|
|
37
|
+
*/
|
|
24
38
|
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
|
39
|
+
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type ApiVersion = '
|
|
1
|
+
export type ApiVersion = 'v3';
|
|
2
2
|
export declare const DEFAULT_API_VERSION: ApiVersion;
|