@webiny/website-builder-sdk 0.0.0-unstable.7be00a75a9 → 0.0.0-unstable.7c2def32a7
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/BindingsResolver.d.ts +4 -1
- package/BindingsResolver.js.map +1 -1
- package/ComponentInputTraverser.js +4 -0
- package/ComponentInputTraverser.js.map +1 -1
- package/ComponentResolver.d.ts +6 -3
- package/ComponentResolver.js +9 -4
- package/ComponentResolver.js.map +1 -1
- package/ContentSdk.d.ts +67 -1
- package/ContentSdk.js +90 -8
- package/ContentSdk.js.map +1 -1
- package/DocumentStoreManager.d.ts +9 -2
- package/DocumentStoreManager.js +24 -5
- package/DocumentStoreManager.js.map +1 -1
- package/EditingSdk.d.ts +7 -1
- package/EditingSdk.js +5 -3
- package/EditingSdk.js.map +1 -1
- package/ElementFactory.js +7 -2
- package/ElementFactory.js.map +1 -1
- package/ElementFactory.test.js +102 -0
- package/ElementFactory.test.js.map +1 -1
- package/LiveSdk.d.ts +3 -1
- package/LiveSdk.js +3 -2
- package/LiveSdk.js.map +1 -1
- package/PreviewDocument.d.ts +3 -1
- package/PreviewDocument.js +5 -2
- package/PreviewDocument.js.map +1 -1
- package/PreviewSdk.d.ts +4 -1
- package/PreviewSdk.js +6 -2
- package/PreviewSdk.js.map +1 -1
- package/ResizeObserver.js +1 -1
- package/ResizeObserver.js.map +1 -1
- package/StylesBindingsProcessor.js +3 -2
- package/StylesBindingsProcessor.js.map +1 -1
- package/Theme.js +2 -1
- package/Theme.js.map +1 -1
- package/asset/deliveryUrl.d.ts +41 -0
- package/asset/deliveryUrl.js +34 -0
- package/asset/deliveryUrl.js.map +1 -0
- package/asset/deliveryUrl.test.d.ts +1 -0
- package/asset/deliveryUrl.test.js +127 -0
- package/asset/deliveryUrl.test.js.map +1 -0
- package/asset/geometry.d.ts +7 -0
- package/asset/geometry.js +10 -0
- package/asset/geometry.js.map +1 -0
- package/asset/imageSrcSet.d.ts +63 -0
- package/asset/imageSrcSet.js +98 -0
- package/asset/imageSrcSet.js.map +1 -0
- package/asset/imageSrcSet.test.d.ts +1 -0
- package/asset/imageSrcSet.test.js +103 -0
- package/asset/imageSrcSet.test.js.map +1 -0
- package/asset/index.d.ts +5 -0
- package/asset/index.js +5 -0
- package/asset/normalize.d.ts +24 -0
- package/asset/normalize.js +106 -0
- package/asset/normalize.js.map +1 -0
- package/asset/normalize.test.d.ts +1 -0
- package/asset/normalize.test.js +263 -0
- package/asset/normalize.test.js.map +1 -0
- package/asset/types.d.ts +2 -0
- package/asset/types.js +0 -0
- package/componentLoader/ComponentLoader.d.ts +16 -0
- package/componentLoader/ComponentLoader.js +0 -0
- package/componentLoader/RegistryOnlyComponentLoader.d.ts +9 -0
- package/componentLoader/RegistryOnlyComponentLoader.js +8 -0
- package/componentLoader/RegistryOnlyComponentLoader.js.map +1 -0
- package/componentLoader/createComponentLoader.d.ts +7 -0
- package/componentLoader/createComponentLoader.js +10 -0
- package/componentLoader/createComponentLoader.js.map +1 -0
- package/componentLoader/defaultComponentLoader.d.ts +7 -0
- package/componentLoader/defaultComponentLoader.js +8 -0
- package/componentLoader/defaultComponentLoader.js.map +1 -0
- package/componentLoader/index.d.ts +3 -0
- package/componentLoader/index.js +3 -0
- package/contentClientState.test.d.ts +1 -0
- package/contentClientState.test.js +384 -0
- package/contentClientState.test.js.map +1 -0
- package/contentEntry/ContentEntryBindingsResolver.d.ts +33 -0
- package/contentEntry/ContentEntryBindingsResolver.js +52 -0
- package/contentEntry/ContentEntryBindingsResolver.js.map +1 -0
- package/contentEntry/ContentEntryCache.d.ts +49 -0
- package/contentEntry/ContentEntryCache.js +51 -0
- package/contentEntry/ContentEntryCache.js.map +1 -0
- package/contentEntry/resolveContentEntry.d.ts +74 -0
- package/contentEntry/resolveContentEntry.js +53 -0
- package/contentEntry/resolveContentEntry.js.map +1 -0
- package/contentEntry/resolveContentEntry.test.d.ts +1 -0
- package/contentEntry/resolveContentEntry.test.js +213 -0
- package/contentEntry/resolveContentEntry.test.js.map +1 -0
- package/createComponent.d.ts +5 -0
- package/createComponent.js +32 -0
- package/createComponent.js.map +1 -0
- package/createContentClient.d.ts +17 -0
- package/createContentClient.js +16 -0
- package/createContentClient.js.map +1 -0
- package/createContentClient.test.d.ts +1 -0
- package/createContentClient.test.js +165 -0
- package/createContentClient.test.js.map +1 -0
- package/createInput.d.ts +10 -2
- package/createInput.js +8 -1
- package/createInput.js.map +1 -1
- package/dataProviders/ApiClient.d.ts +10 -5
- package/dataProviders/ApiClient.js +10 -10
- package/dataProviders/ApiClient.js.map +1 -1
- package/dataProviders/DefaultDataProvider.d.ts +4 -0
- package/dataProviders/DefaultDataProvider.js +35 -0
- package/dataProviders/DefaultDataProvider.js.map +1 -1
- package/dataProviders/GET_EXPERIMENT_PAUSED.d.ts +1 -0
- package/dataProviders/GET_EXPERIMENT_PAUSED.js +17 -0
- package/dataProviders/GET_EXPERIMENT_PAUSED.js.map +1 -0
- package/dataProviders/GET_PAGE_BY_ID.d.ts +1 -1
- package/dataProviders/GET_PAGE_BY_ID.js +2 -0
- package/dataProviders/GET_PAGE_BY_ID.js.map +1 -1
- package/dataProviders/GET_PAGE_BY_PATH.d.ts +1 -1
- package/dataProviders/GET_PAGE_BY_PATH.js +2 -0
- package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -1
- package/dataProviders/GET_PAGE_EXPERIMENT.d.ts +1 -0
- package/dataProviders/GET_PAGE_EXPERIMENT.js +32 -0
- package/dataProviders/GET_PAGE_EXPERIMENT.js.map +1 -0
- package/dataProviders/GET_VARIANT_CONTENT.d.ts +1 -0
- package/dataProviders/GET_VARIANT_CONTENT.js +24 -0
- package/dataProviders/GET_VARIANT_CONTENT.js.map +1 -0
- package/dataProviders/NullDataProvider.d.ts +4 -0
- package/dataProviders/NullDataProvider.js +9 -0
- package/dataProviders/NullDataProvider.js.map +1 -1
- package/dataProviders/queries.test.d.ts +1 -0
- package/dataProviders/queries.test.js +45 -0
- package/dataProviders/queries.test.js.map +1 -0
- package/defaultBreakpoints.js +23 -3
- package/defaultBreakpoints.js.map +1 -1
- package/experiments/PostHogAnalyticsProvider.d.ts +31 -0
- package/experiments/PostHogAnalyticsProvider.js +28 -0
- package/experiments/PostHogAnalyticsProvider.js.map +1 -0
- package/experiments/analyticsProvider.d.ts +4 -0
- package/experiments/analyticsProvider.js +11 -0
- package/experiments/analyticsProvider.js.map +1 -0
- package/experiments/bucketing.d.ts +27 -0
- package/experiments/bucketing.js +91 -0
- package/experiments/bucketing.js.map +1 -0
- package/experiments/bucketing.test.d.ts +1 -0
- package/experiments/bucketing.test.js +183 -0
- package/experiments/bucketing.test.js.map +1 -0
- package/experiments/index.d.ts +5 -0
- package/experiments/index.js +5 -0
- package/experiments/render.d.ts +82 -0
- package/experiments/render.js +149 -0
- package/experiments/render.js.map +1 -0
- package/experiments/types.d.ts +108 -0
- package/experiments/types.js +4 -0
- package/experiments/types.js.map +1 -0
- package/headersProvider.d.ts +1 -2
- package/headersProvider.js.map +1 -1
- package/image/geometry.d.ts +54 -0
- package/image/geometry.js +112 -0
- package/image/geometry.js.map +1 -0
- package/image/geometry.test.d.ts +1 -0
- package/image/geometry.test.js +190 -0
- package/image/geometry.test.js.map +1 -0
- package/image/index.d.ts +3 -0
- package/image/index.js +3 -0
- package/image/presets.d.ts +6 -0
- package/image/presets.js +20 -0
- package/image/presets.js.map +1 -0
- package/image/types.d.ts +10 -0
- package/image/types.js +0 -0
- package/index.d.ts +12 -0
- package/index.js +12 -0
- package/jsonPatch.js +3 -3
- package/package.json +7 -6
- package/types/WebsiteBuilderTheme.d.ts +5 -0
- package/types.d.ts +75 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
function getAssetCategory(mimeType) {
|
|
2
|
+
if ("string" == typeof mimeType) {
|
|
3
|
+
if (mimeType.startsWith("image/")) return "image";
|
|
4
|
+
if (mimeType.startsWith("video/")) return "video";
|
|
5
|
+
}
|
|
6
|
+
return "document";
|
|
7
|
+
}
|
|
8
|
+
const isObject = (value)=>"object" == typeof value && null !== value;
|
|
9
|
+
const asNumber = (value)=>"number" != typeof value || Number.isNaN(value) ? void 0 : value;
|
|
10
|
+
const asString = (value)=>"string" == typeof value ? value : void 0;
|
|
11
|
+
function assetImageFromLegacyEdit(edit, dimensions) {
|
|
12
|
+
const image = {};
|
|
13
|
+
const width = asNumber(dimensions?.width);
|
|
14
|
+
const height = asNumber(dimensions?.height);
|
|
15
|
+
if (void 0 !== width) image.width = width;
|
|
16
|
+
if (void 0 !== height) image.height = height;
|
|
17
|
+
if (edit?.crop) image.crop = {
|
|
18
|
+
top: edit.crop.top ?? 0,
|
|
19
|
+
left: edit.crop.left ?? 0,
|
|
20
|
+
bottom: edit.crop.bottom ?? 0,
|
|
21
|
+
right: edit.crop.right ?? 0
|
|
22
|
+
};
|
|
23
|
+
if (edit?.hotspot) image.focalPoint = {
|
|
24
|
+
x: edit.hotspot.x,
|
|
25
|
+
y: edit.hotspot.y
|
|
26
|
+
};
|
|
27
|
+
if (edit?.alt) image.alt = edit.alt;
|
|
28
|
+
if (edit?.caption) image.caption = edit.caption;
|
|
29
|
+
return Object.keys(image).length > 0 ? image : void 0;
|
|
30
|
+
}
|
|
31
|
+
const normalizeAssetImage = (raw)=>{
|
|
32
|
+
if (!isObject(raw)) return;
|
|
33
|
+
const image = {};
|
|
34
|
+
const width = asNumber(raw.width);
|
|
35
|
+
const height = asNumber(raw.height);
|
|
36
|
+
if (void 0 !== width) image.width = width;
|
|
37
|
+
if (void 0 !== height) image.height = height;
|
|
38
|
+
if (isObject(raw.crop)) image.crop = {
|
|
39
|
+
top: asNumber(raw.crop.top) ?? 0,
|
|
40
|
+
left: asNumber(raw.crop.left) ?? 0,
|
|
41
|
+
bottom: asNumber(raw.crop.bottom) ?? 0,
|
|
42
|
+
right: asNumber(raw.crop.right) ?? 0
|
|
43
|
+
};
|
|
44
|
+
if (isObject(raw.focalPoint)) {
|
|
45
|
+
const x = asNumber(raw.focalPoint.x);
|
|
46
|
+
const y = asNumber(raw.focalPoint.y);
|
|
47
|
+
if (void 0 !== x && void 0 !== y) image.focalPoint = {
|
|
48
|
+
x,
|
|
49
|
+
y
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const alt = asString(raw.alt);
|
|
53
|
+
if (alt) image.alt = alt;
|
|
54
|
+
const caption = asString(raw.caption);
|
|
55
|
+
if (caption) image.caption = caption;
|
|
56
|
+
return Object.keys(image).length > 0 ? image : void 0;
|
|
57
|
+
};
|
|
58
|
+
const buildBase = (raw, mimeType)=>{
|
|
59
|
+
const src = asString(raw.src) ?? "";
|
|
60
|
+
return {
|
|
61
|
+
id: asString(raw.id) ?? "",
|
|
62
|
+
src,
|
|
63
|
+
url: asString(raw.url) ?? src,
|
|
64
|
+
name: asString(raw.name) ?? "",
|
|
65
|
+
mimeType,
|
|
66
|
+
size: asNumber(raw.size) ?? 0
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const syncImageDimensions = (asset)=>{
|
|
70
|
+
if (!asset.image) return asset;
|
|
71
|
+
if (void 0 !== asset.image.width) asset.width = asset.image.width;
|
|
72
|
+
if (void 0 !== asset.image.height) asset.height = asset.image.height;
|
|
73
|
+
return asset;
|
|
74
|
+
};
|
|
75
|
+
function normalizeToAsset(input) {
|
|
76
|
+
if (!isObject(input)) return null;
|
|
77
|
+
const hasTypedSubObject = isObject(input.image) || isObject(input.document) || isObject(input.video);
|
|
78
|
+
const mimeType = asString(input.mimeType) ?? "";
|
|
79
|
+
const asset = buildBase(input, mimeType);
|
|
80
|
+
const category = getAssetCategory(mimeType);
|
|
81
|
+
if (!hasTypedSubObject) {
|
|
82
|
+
if ("image" === category) {
|
|
83
|
+
const image = assetImageFromLegacyEdit(input.edit, {
|
|
84
|
+
width: asNumber(input.width),
|
|
85
|
+
height: asNumber(input.height)
|
|
86
|
+
});
|
|
87
|
+
if (image) asset.image = image;
|
|
88
|
+
}
|
|
89
|
+
return syncImageDimensions(asset);
|
|
90
|
+
}
|
|
91
|
+
if ("image" === category) {
|
|
92
|
+
const image = normalizeAssetImage(input.image);
|
|
93
|
+
if (image) asset.image = image;
|
|
94
|
+
} else if ("video" === category) {
|
|
95
|
+
if (isObject(input.video)) asset.video = {
|
|
96
|
+
autoplay: "boolean" == typeof input.video.autoplay ? input.video.autoplay : void 0,
|
|
97
|
+
poster: asString(input.video.poster)
|
|
98
|
+
};
|
|
99
|
+
} else if (isObject(input.document)) asset.document = {
|
|
100
|
+
pages: asNumber(input.document.pages)
|
|
101
|
+
};
|
|
102
|
+
return syncImageDimensions(asset);
|
|
103
|
+
}
|
|
104
|
+
export { assetImageFromLegacyEdit, getAssetCategory, normalizeToAsset };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset/normalize.js","sources":["../../src/asset/normalize.ts"],"sourcesContent":["import type { Asset, AssetCategory, AssetImage } from \"./types.js\";\n\nexport function getAssetCategory(mimeType?: string | null): AssetCategory {\n if (typeof mimeType === \"string\") {\n if (mimeType.startsWith(\"image/\")) {\n return \"image\";\n }\n if (mimeType.startsWith(\"video/\")) {\n return \"video\";\n }\n }\n return \"document\";\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> => {\n return typeof value === \"object\" && value !== null;\n};\n\nconst asNumber = (value: unknown): number | undefined => {\n return typeof value === \"number\" && !Number.isNaN(value) ? value : undefined;\n};\n\nconst asString = (value: unknown): string | undefined => {\n return typeof value === \"string\" ? value : undefined;\n};\n\ninterface LegacyImageEdit {\n crop?: { top: number; left: number; bottom: number; right: number };\n hotspot?: { x: number; y: number; width?: number; height?: number };\n alt?: string;\n caption?: string;\n}\n\nexport function assetImageFromLegacyEdit(\n edit?: LegacyImageEdit | null,\n dimensions?: { width?: number | null; height?: number | null }\n): AssetImage | undefined {\n const image: AssetImage = {};\n\n const width = asNumber(dimensions?.width);\n const height = asNumber(dimensions?.height);\n if (width !== undefined) {\n image.width = width;\n }\n if (height !== undefined) {\n image.height = height;\n }\n\n if (edit?.crop) {\n image.crop = {\n top: edit.crop.top ?? 0,\n left: edit.crop.left ?? 0,\n bottom: edit.crop.bottom ?? 0,\n right: edit.crop.right ?? 0\n };\n }\n if (edit?.hotspot) {\n image.focalPoint = { x: edit.hotspot.x, y: edit.hotspot.y };\n }\n if (edit?.alt) {\n image.alt = edit.alt;\n }\n if (edit?.caption) {\n image.caption = edit.caption;\n }\n\n return Object.keys(image).length > 0 ? image : undefined;\n}\n\nconst normalizeAssetImage = (raw: unknown): AssetImage | undefined => {\n if (!isObject(raw)) {\n return undefined;\n }\n const image: AssetImage = {};\n const width = asNumber(raw.width);\n const height = asNumber(raw.height);\n if (width !== undefined) {\n image.width = width;\n }\n if (height !== undefined) {\n image.height = height;\n }\n if (isObject(raw.crop)) {\n image.crop = {\n top: asNumber(raw.crop.top) ?? 0,\n left: asNumber(raw.crop.left) ?? 0,\n bottom: asNumber(raw.crop.bottom) ?? 0,\n right: asNumber(raw.crop.right) ?? 0\n };\n }\n if (isObject(raw.focalPoint)) {\n const x = asNumber(raw.focalPoint.x);\n const y = asNumber(raw.focalPoint.y);\n if (x !== undefined && y !== undefined) {\n image.focalPoint = { x, y };\n }\n }\n const alt = asString(raw.alt);\n if (alt) {\n image.alt = alt;\n }\n const caption = asString(raw.caption);\n if (caption) {\n image.caption = caption;\n }\n return Object.keys(image).length > 0 ? image : undefined;\n};\n\nconst buildBase = (raw: Record<string, unknown>, mimeType: string): Asset => {\n const src = asString(raw.src) ?? \"\";\n return {\n id: asString(raw.id) ?? \"\",\n src,\n url: asString(raw.url) ?? src,\n name: asString(raw.name) ?? \"\",\n mimeType,\n size: asNumber(raw.size) ?? 0\n };\n};\n\n/**\n * Keeps the image dimensions in both places: `image.width`/`image.height` for current code,\n * and the root `width`/`height` that 6.4 frontends read.\n */\nconst syncImageDimensions = (asset: Asset): Asset => {\n if (!asset.image) {\n return asset;\n }\n if (asset.image.width !== undefined) {\n asset.width = asset.image.width;\n }\n if (asset.image.height !== undefined) {\n asset.height = asset.image.height;\n }\n return asset;\n};\n\nexport function normalizeToAsset(input: unknown): Asset | null {\n if (!isObject(input)) {\n return null;\n }\n\n const hasTypedSubObject =\n isObject(input.image) || isObject(input.document) || isObject(input.video);\n\n const mimeType = asString(input.mimeType) ?? \"\";\n const asset = buildBase(input, mimeType);\n const category = getAssetCategory(mimeType);\n\n if (!hasTypedSubObject) {\n if (category === \"image\") {\n const image = assetImageFromLegacyEdit(input.edit as LegacyImageEdit | undefined, {\n width: asNumber(input.width),\n height: asNumber(input.height)\n });\n if (image) {\n asset.image = image;\n }\n }\n return syncImageDimensions(asset);\n }\n\n if (category === \"image\") {\n const image = normalizeAssetImage(input.image);\n if (image) {\n asset.image = image;\n }\n } else if (category === \"video\") {\n if (isObject(input.video)) {\n asset.video = {\n autoplay:\n typeof input.video.autoplay === \"boolean\" ? input.video.autoplay : undefined,\n poster: asString(input.video.poster)\n };\n }\n } else if (isObject(input.document)) {\n asset.document = { pages: asNumber(input.document.pages) };\n }\n return syncImageDimensions(asset);\n}\n"],"names":["getAssetCategory","mimeType","isObject","value","asNumber","Number","undefined","asString","assetImageFromLegacyEdit","edit","dimensions","image","width","height","Object","normalizeAssetImage","raw","x","y","alt","caption","buildBase","src","syncImageDimensions","asset","normalizeToAsset","input","hasTypedSubObject","category"],"mappings":"AAEO,SAASA,iBAAiBC,QAAwB;IACrD,IAAI,AAAoB,YAApB,OAAOA,UAAuB;QAC9B,IAAIA,SAAS,UAAU,CAAC,WACpB,OAAO;QAEX,IAAIA,SAAS,UAAU,CAAC,WACpB,OAAO;IAEf;IACA,OAAO;AACX;AAEA,MAAMC,WAAW,CAACC,QACP,AAAiB,YAAjB,OAAOA,SAAsBA,AAAU,SAAVA;AAGxC,MAAMC,WAAW,CAACD,QACP,AAAiB,YAAjB,OAAOA,SAAuBE,OAAO,KAAK,CAACF,SAAiBG,SAARH;AAG/D,MAAMI,WAAW,CAACJ,QACP,AAAiB,YAAjB,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wB,MAAM,KAAK,KAAKxB,SAASwB,MAAM,QAAQ,KAAKxB,SAASwB,MAAM,KAAK;IAE7E,MAAMzB,WAAWM,SAASmB,MAAM,QAAQ,KAAK;IAC7C,MAAMF,QAAQH,UAAUK,OAAOzB;IAC/B,MAAM2B,WAAW5B,iBAAiBC;IAElC,IAAI,CAAC0B,mBAAmB;QACpB,IAAIC,AAAa,YAAbA,UAAsB;YACtB,MAAMjB,QAAQH,yBAAyBkB,MAAM,IAAI,EAAiC;gBAC9E,OAAOtB,SAASsB,MAAM,KAAK;gBAC3B,QAAQtB,SAASsB,MAAM,MAAM;YACjC;YACA,IAAIf,OACAa,MAAM,KAAK,GAAGb;QAEtB;QACA,OAAOY,oBAAoBC;IAC/B;IAEA,IAAII,AAAa,YAAbA,UAAsB;QACtB,MAAMjB,QAAQI,oBAAoBW,MAAM,KAAK;QAC7C,IAAIf,OACAa,MAAM,KAAK,GAAGb;IAEtB,OAAO,IAAIiB,AAAa,YAAbA,UACP;QAAA,IAAI1B,SAASwB,MAAM,KAAK,GACpBF,MAAM,KAAK,GAAG;YACV,UACI,AAAgC,aAAhC,OAAOE,MAAM,KAAK,CAAC,QAAQ,GAAiBA,MAAM,KAAK,CAAC,QAAQ,GAAGpB;YACvE,QAAQC,SAASmB,MAAM,KAAK,CAAC,MAAM;QACvC;IACJ,OACG,IAAIxB,SAASwB,MAAM,QAAQ,GAC9BF,MAAM,QAAQ,GAAG;QAAE,OAAOpB,SAASsB,MAAM,QAAQ,CAAC,KAAK;IAAE;IAE7D,OAAOH,oBAAoBC;AAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { assetImageFromLegacyEdit, getAssetCategory, normalizeToAsset } from "./normalize.js";
|
|
3
|
+
import { resolveAssetImage } from "../image/geometry.js";
|
|
4
|
+
describe("getAssetCategory", ()=>{
|
|
5
|
+
it("buckets by MIME prefix", ()=>{
|
|
6
|
+
expect(getAssetCategory("image/jpeg")).toBe("image");
|
|
7
|
+
expect(getAssetCategory("image/svg+xml")).toBe("image");
|
|
8
|
+
expect(getAssetCategory("video/mp4")).toBe("video");
|
|
9
|
+
});
|
|
10
|
+
it("treats everything else as a document", ()=>{
|
|
11
|
+
expect(getAssetCategory("application/pdf")).toBe("document");
|
|
12
|
+
expect(getAssetCategory("application/zip")).toBe("document");
|
|
13
|
+
expect(getAssetCategory("")).toBe("document");
|
|
14
|
+
expect(getAssetCategory(void 0)).toBe("document");
|
|
15
|
+
expect(getAssetCategory(null)).toBe("document");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe("assetImageFromLegacyEdit", ()=>{
|
|
19
|
+
it("maps hotspot -> focalPoint and keeps crop/alt/caption", ()=>{
|
|
20
|
+
const image = assetImageFromLegacyEdit({
|
|
21
|
+
crop: {
|
|
22
|
+
top: 0.1,
|
|
23
|
+
left: 0,
|
|
24
|
+
bottom: 0.1,
|
|
25
|
+
right: 0
|
|
26
|
+
},
|
|
27
|
+
hotspot: {
|
|
28
|
+
x: 0.3,
|
|
29
|
+
y: 0.7,
|
|
30
|
+
width: 0.5,
|
|
31
|
+
height: 0.5
|
|
32
|
+
},
|
|
33
|
+
alt: "A cat",
|
|
34
|
+
caption: "Meow"
|
|
35
|
+
}, {
|
|
36
|
+
width: 800,
|
|
37
|
+
height: 600
|
|
38
|
+
});
|
|
39
|
+
expect(image).toEqual({
|
|
40
|
+
width: 800,
|
|
41
|
+
height: 600,
|
|
42
|
+
crop: {
|
|
43
|
+
top: 0.1,
|
|
44
|
+
left: 0,
|
|
45
|
+
bottom: 0.1,
|
|
46
|
+
right: 0
|
|
47
|
+
},
|
|
48
|
+
focalPoint: {
|
|
49
|
+
x: 0.3,
|
|
50
|
+
y: 0.7
|
|
51
|
+
},
|
|
52
|
+
alt: "A cat",
|
|
53
|
+
caption: "Meow"
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
it("returns undefined when there is nothing to store", ()=>{
|
|
57
|
+
expect(assetImageFromLegacyEdit(void 0, {})).toBeUndefined();
|
|
58
|
+
expect(assetImageFromLegacyEdit(null, {
|
|
59
|
+
width: null,
|
|
60
|
+
height: void 0
|
|
61
|
+
})).toBeUndefined();
|
|
62
|
+
});
|
|
63
|
+
it("keeps dimensions even without an edit", ()=>{
|
|
64
|
+
expect(assetImageFromLegacyEdit(void 0, {
|
|
65
|
+
width: 100,
|
|
66
|
+
height: 50
|
|
67
|
+
})).toEqual({
|
|
68
|
+
width: 100,
|
|
69
|
+
height: 50
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("normalizeToAsset — legacy Website Builder image value", ()=>{
|
|
74
|
+
const legacy = {
|
|
75
|
+
id: "file-1",
|
|
76
|
+
name: "cat.jpg",
|
|
77
|
+
size: 1234,
|
|
78
|
+
mimeType: "image/jpeg",
|
|
79
|
+
src: "https://cdn/x/cat.jpg",
|
|
80
|
+
width: 800,
|
|
81
|
+
height: 600,
|
|
82
|
+
edit: {
|
|
83
|
+
crop: {
|
|
84
|
+
top: 0.1,
|
|
85
|
+
left: 0.1,
|
|
86
|
+
bottom: 0.1,
|
|
87
|
+
right: 0.1
|
|
88
|
+
},
|
|
89
|
+
hotspot: {
|
|
90
|
+
x: 0.25,
|
|
91
|
+
y: 0.75,
|
|
92
|
+
width: 1,
|
|
93
|
+
height: 1
|
|
94
|
+
},
|
|
95
|
+
alt: "A cat"
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
it("keeps mimeType, maps edit -> image, and mirrors dimensions at the root", ()=>{
|
|
99
|
+
const asset = normalizeToAsset(legacy);
|
|
100
|
+
expect(asset).toEqual({
|
|
101
|
+
id: "file-1",
|
|
102
|
+
src: "https://cdn/x/cat.jpg",
|
|
103
|
+
url: "https://cdn/x/cat.jpg",
|
|
104
|
+
name: "cat.jpg",
|
|
105
|
+
mimeType: "image/jpeg",
|
|
106
|
+
size: 1234,
|
|
107
|
+
width: 800,
|
|
108
|
+
height: 600,
|
|
109
|
+
image: {
|
|
110
|
+
width: 800,
|
|
111
|
+
height: 600,
|
|
112
|
+
crop: {
|
|
113
|
+
top: 0.1,
|
|
114
|
+
left: 0.1,
|
|
115
|
+
bottom: 0.1,
|
|
116
|
+
right: 0.1
|
|
117
|
+
},
|
|
118
|
+
focalPoint: {
|
|
119
|
+
x: 0.25,
|
|
120
|
+
y: 0.75
|
|
121
|
+
},
|
|
122
|
+
alt: "A cat"
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
it("handles a legacy value with no edit (dimensions only)", ()=>{
|
|
127
|
+
const asset = normalizeToAsset({
|
|
128
|
+
...legacy,
|
|
129
|
+
edit: void 0
|
|
130
|
+
});
|
|
131
|
+
expect(asset?.image).toEqual({
|
|
132
|
+
width: 800,
|
|
133
|
+
height: 600
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
it("upgrades a flat 6.4 file value (mimeType + top-level dims, no edit)", ()=>{
|
|
137
|
+
const asset = normalizeToAsset({
|
|
138
|
+
id: "f",
|
|
139
|
+
src: "https://cdn/x.jpg",
|
|
140
|
+
name: "x.jpg",
|
|
141
|
+
mimeType: "image/jpeg",
|
|
142
|
+
size: 10,
|
|
143
|
+
width: 800,
|
|
144
|
+
height: 600
|
|
145
|
+
});
|
|
146
|
+
expect(asset).toEqual({
|
|
147
|
+
id: "f",
|
|
148
|
+
src: "https://cdn/x.jpg",
|
|
149
|
+
url: "https://cdn/x.jpg",
|
|
150
|
+
name: "x.jpg",
|
|
151
|
+
mimeType: "image/jpeg",
|
|
152
|
+
size: 10,
|
|
153
|
+
width: 800,
|
|
154
|
+
height: 600,
|
|
155
|
+
image: {
|
|
156
|
+
width: 800,
|
|
157
|
+
height: 600
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
it("does not attach image data for a non-image legacy value", ()=>{
|
|
162
|
+
const asset = normalizeToAsset({
|
|
163
|
+
...legacy,
|
|
164
|
+
mimeType: "application/pdf",
|
|
165
|
+
edit: void 0,
|
|
166
|
+
width: void 0,
|
|
167
|
+
height: void 0
|
|
168
|
+
});
|
|
169
|
+
expect(asset?.mimeType).toBe("application/pdf");
|
|
170
|
+
expect(asset?.width).toBeUndefined();
|
|
171
|
+
expect(asset?.image).toBeUndefined();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
describe("normalizeToAsset — already-unified asset", ()=>{
|
|
175
|
+
it("is idempotent for a well-formed image asset", ()=>{
|
|
176
|
+
const asset = {
|
|
177
|
+
id: "f2",
|
|
178
|
+
src: "https://cdn/y/pic.png",
|
|
179
|
+
url: "https://cdn/y/pic.png",
|
|
180
|
+
name: "pic.png",
|
|
181
|
+
mimeType: "image/png",
|
|
182
|
+
size: 9,
|
|
183
|
+
width: 400,
|
|
184
|
+
height: 300,
|
|
185
|
+
image: {
|
|
186
|
+
width: 400,
|
|
187
|
+
height: 300,
|
|
188
|
+
crop: {
|
|
189
|
+
top: 0,
|
|
190
|
+
left: 0.2,
|
|
191
|
+
bottom: 0,
|
|
192
|
+
right: 0.2
|
|
193
|
+
},
|
|
194
|
+
focalPoint: {
|
|
195
|
+
x: 0.5,
|
|
196
|
+
y: 0.5
|
|
197
|
+
},
|
|
198
|
+
alt: "Pic"
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
expect(normalizeToAsset(asset)).toEqual(asset);
|
|
202
|
+
});
|
|
203
|
+
it("preserves video data", ()=>{
|
|
204
|
+
const asset = normalizeToAsset({
|
|
205
|
+
id: "v1",
|
|
206
|
+
src: "https://cdn/v/clip.mp4",
|
|
207
|
+
name: "clip.mp4",
|
|
208
|
+
mimeType: "video/mp4",
|
|
209
|
+
size: 42,
|
|
210
|
+
video: {
|
|
211
|
+
autoplay: true,
|
|
212
|
+
poster: "https://cdn/v/poster.jpg"
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
expect(asset?.video).toEqual({
|
|
216
|
+
autoplay: true,
|
|
217
|
+
poster: "https://cdn/v/poster.jpg"
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
it("returns null for invalid input", ()=>{
|
|
221
|
+
expect(normalizeToAsset(null)).toBeNull();
|
|
222
|
+
expect(normalizeToAsset(void 0)).toBeNull();
|
|
223
|
+
expect(normalizeToAsset("nope")).toBeNull();
|
|
224
|
+
expect(normalizeToAsset(42)).toBeNull();
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
describe("resolveAssetImage", ()=>{
|
|
228
|
+
it("prefers override per property, falling back to base", ()=>{
|
|
229
|
+
const merged = resolveAssetImage({
|
|
230
|
+
crop: {
|
|
231
|
+
top: 0.1,
|
|
232
|
+
left: 0,
|
|
233
|
+
bottom: 0,
|
|
234
|
+
right: 0
|
|
235
|
+
}
|
|
236
|
+
}, {
|
|
237
|
+
crop: {
|
|
238
|
+
top: 0.5,
|
|
239
|
+
left: 0,
|
|
240
|
+
bottom: 0,
|
|
241
|
+
right: 0
|
|
242
|
+
},
|
|
243
|
+
focalPoint: {
|
|
244
|
+
x: 0.2,
|
|
245
|
+
y: 0.2
|
|
246
|
+
},
|
|
247
|
+
alt: "base"
|
|
248
|
+
});
|
|
249
|
+
expect(merged.crop).toEqual({
|
|
250
|
+
top: 0.1,
|
|
251
|
+
left: 0,
|
|
252
|
+
bottom: 0,
|
|
253
|
+
right: 0
|
|
254
|
+
});
|
|
255
|
+
expect(merged.focalPoint).toEqual({
|
|
256
|
+
x: 0.2,
|
|
257
|
+
y: 0.2
|
|
258
|
+
});
|
|
259
|
+
expect(merged.alt).toBe("base");
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
//# sourceMappingURL=normalize.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset/normalize.test.js","sources":["../../src/asset/normalize.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { assetImageFromLegacyEdit, getAssetCategory, normalizeToAsset } from \"./normalize.js\";\nimport { resolveAssetImage } from \"../image/geometry.js\";\n\ndescribe(\"getAssetCategory\", () => {\n it(\"buckets by MIME prefix\", () => {\n expect(getAssetCategory(\"image/jpeg\")).toBe(\"image\");\n expect(getAssetCategory(\"image/svg+xml\")).toBe(\"image\");\n expect(getAssetCategory(\"video/mp4\")).toBe(\"video\");\n });\n\n it(\"treats everything else as a document\", () => {\n expect(getAssetCategory(\"application/pdf\")).toBe(\"document\");\n expect(getAssetCategory(\"application/zip\")).toBe(\"document\");\n expect(getAssetCategory(\"\")).toBe(\"document\");\n expect(getAssetCategory(undefined)).toBe(\"document\");\n expect(getAssetCategory(null)).toBe(\"document\");\n });\n});\n\ndescribe(\"assetImageFromLegacyEdit\", () => {\n it(\"maps hotspot -> focalPoint and keeps crop/alt/caption\", () => {\n const image = assetImageFromLegacyEdit(\n {\n crop: { top: 0.1, left: 0, bottom: 0.1, right: 0 },\n hotspot: { x: 0.3, y: 0.7, width: 0.5, height: 0.5 },\n alt: \"A cat\",\n caption: \"Meow\"\n },\n { width: 800, height: 600 }\n );\n expect(image).toEqual({\n width: 800,\n height: 600,\n crop: { top: 0.1, left: 0, bottom: 0.1, right: 0 },\n focalPoint: { x: 0.3, y: 0.7 },\n alt: \"A cat\",\n caption: \"Meow\"\n });\n });\n\n it(\"returns undefined when there is nothing to store\", () => {\n expect(assetImageFromLegacyEdit(undefined, {})).toBeUndefined();\n expect(assetImageFromLegacyEdit(null, { width: null, height: undefined })).toBeUndefined();\n });\n\n it(\"keeps dimensions even without an edit\", () => {\n expect(assetImageFromLegacyEdit(undefined, { width: 100, height: 50 })).toEqual({\n width: 100,\n height: 50\n });\n });\n});\n\ndescribe(\"normalizeToAsset — legacy Website Builder image value\", () => {\n const legacy = {\n id: \"file-1\",\n name: \"cat.jpg\",\n size: 1234,\n mimeType: \"image/jpeg\",\n src: \"https://cdn/x/cat.jpg\",\n width: 800,\n height: 600,\n edit: {\n crop: { top: 0.1, left: 0.1, bottom: 0.1, right: 0.1 },\n hotspot: { x: 0.25, y: 0.75, width: 1, height: 1 },\n alt: \"A cat\"\n }\n };\n\n it(\"keeps mimeType, maps edit -> image, and mirrors dimensions at the root\", () => {\n const asset = normalizeToAsset(legacy);\n expect(asset).toEqual({\n id: \"file-1\",\n src: \"https://cdn/x/cat.jpg\",\n url: \"https://cdn/x/cat.jpg\",\n name: \"cat.jpg\",\n mimeType: \"image/jpeg\",\n size: 1234,\n width: 800,\n height: 600,\n image: {\n width: 800,\n height: 600,\n crop: { top: 0.1, left: 0.1, bottom: 0.1, right: 0.1 },\n focalPoint: { x: 0.25, y: 0.75 },\n alt: \"A cat\"\n }\n });\n });\n\n it(\"handles a legacy value with no edit (dimensions only)\", () => {\n const asset = normalizeToAsset({ ...legacy, edit: undefined });\n expect(asset?.image).toEqual({ width: 800, height: 600 });\n });\n\n it(\"upgrades a flat 6.4 file value (mimeType + top-level dims, no edit)\", () => {\n // The shape released 6.x versions store: flat, no image sub-object.\n const asset = normalizeToAsset({\n id: \"f\",\n src: \"https://cdn/x.jpg\",\n name: \"x.jpg\",\n mimeType: \"image/jpeg\",\n size: 10,\n width: 800,\n height: 600\n });\n expect(asset).toEqual({\n id: \"f\",\n src: \"https://cdn/x.jpg\",\n url: \"https://cdn/x.jpg\",\n name: \"x.jpg\",\n mimeType: \"image/jpeg\",\n size: 10,\n width: 800,\n height: 600,\n image: { width: 800, height: 600 }\n });\n });\n\n it(\"does not attach image data for a non-image legacy value\", () => {\n const asset = normalizeToAsset({\n ...legacy,\n mimeType: \"application/pdf\",\n edit: undefined,\n width: undefined,\n height: undefined\n });\n expect(asset?.mimeType).toBe(\"application/pdf\");\n expect(asset?.width).toBeUndefined();\n expect(asset?.image).toBeUndefined();\n });\n});\n\ndescribe(\"normalizeToAsset — already-unified asset\", () => {\n it(\"is idempotent for a well-formed image asset\", () => {\n const asset = {\n id: \"f2\",\n src: \"https://cdn/y/pic.png\",\n url: \"https://cdn/y/pic.png\",\n name: \"pic.png\",\n mimeType: \"image/png\",\n size: 9,\n width: 400,\n height: 300,\n image: {\n width: 400,\n height: 300,\n crop: { top: 0, left: 0.2, bottom: 0, right: 0.2 },\n focalPoint: { x: 0.5, y: 0.5 },\n alt: \"Pic\"\n }\n };\n expect(normalizeToAsset(asset)).toEqual(asset);\n });\n\n it(\"preserves video data\", () => {\n const asset = normalizeToAsset({\n id: \"v1\",\n src: \"https://cdn/v/clip.mp4\",\n name: \"clip.mp4\",\n mimeType: \"video/mp4\",\n size: 42,\n video: { autoplay: true, poster: \"https://cdn/v/poster.jpg\" }\n });\n expect(asset?.video).toEqual({ autoplay: true, poster: \"https://cdn/v/poster.jpg\" });\n });\n\n it(\"returns null for invalid input\", () => {\n expect(normalizeToAsset(null)).toBeNull();\n expect(normalizeToAsset(undefined)).toBeNull();\n expect(normalizeToAsset(\"nope\")).toBeNull();\n expect(normalizeToAsset(42)).toBeNull();\n });\n});\n\ndescribe(\"resolveAssetImage\", () => {\n it(\"prefers override per property, falling back to base\", () => {\n const merged = resolveAssetImage(\n { crop: { top: 0.1, left: 0, bottom: 0, right: 0 } },\n {\n crop: { top: 0.5, left: 0, bottom: 0, right: 0 },\n focalPoint: { x: 0.2, y: 0.2 },\n alt: \"base\"\n }\n );\n expect(merged.crop).toEqual({ top: 0.1, left: 0, bottom: 0, right: 0 });\n expect(merged.focalPoint).toEqual({ x: 0.2, y: 0.2 });\n expect(merged.alt).toBe(\"base\");\n });\n});\n"],"names":["describe","it","expect","getAssetCategory","undefined","image","assetImageFromLegacyEdit","legacy","asset","normalizeToAsset","merged","resolveAssetImage"],"mappings":";;;AAIAA,SAAS,oBAAoB;IACzBC,GAAG,0BAA0B;QACzBC,OAAOC,iBAAiB,eAAe,IAAI,CAAC;QAC5CD,OAAOC,iBAAiB,kBAAkB,IAAI,CAAC;QAC/CD,OAAOC,iBAAiB,cAAc,IAAI,CAAC;IAC/C;IAEAF,GAAG,wCAAwC;QACvCC,OAAOC,iBAAiB,oBAAoB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types.d.ts
ADDED
package/asset/types.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Component, ElementComponent } from "../types.js";
|
|
2
|
+
import type { ApiClient } from "../dataProviders/ApiClient.js";
|
|
3
|
+
import type { ApiConfig } from "../ContentSdk.js";
|
|
4
|
+
/**
|
|
5
|
+
* Loads a component that a document references but the content client has no registration for.
|
|
6
|
+
* This is the seam for fetching components per tenant and for caching them. The content client
|
|
7
|
+
* creates one loader per client and caches nothing itself.
|
|
8
|
+
*/
|
|
9
|
+
export interface ComponentLoader {
|
|
10
|
+
loadComponent(ref: ElementComponent): Promise<Component | null>;
|
|
11
|
+
}
|
|
12
|
+
export type ComponentLoaderFactoryParams = {
|
|
13
|
+
apiClient: ApiClient;
|
|
14
|
+
config: ApiConfig;
|
|
15
|
+
};
|
|
16
|
+
export type ComponentLoaderFactory = (params: ComponentLoaderFactoryParams) => ComponentLoader;
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Component } from "../types.js";
|
|
2
|
+
import type { ComponentLoader } from "./ComponentLoader.js";
|
|
3
|
+
/**
|
|
4
|
+
* The loader used when neither the config nor a framework integration provides one. It loads
|
|
5
|
+
* nothing, so only components registered with `registerComponent` render.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RegistryOnlyComponentLoader implements ComponentLoader {
|
|
8
|
+
loadComponent(): Promise<Component | null>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentLoader/RegistryOnlyComponentLoader.js","sources":["../../src/componentLoader/RegistryOnlyComponentLoader.ts"],"sourcesContent":["import type { Component } from \"~/types.js\";\nimport type { ComponentLoader } from \"./ComponentLoader.js\";\n\n/**\n * The loader used when neither the config nor a framework integration provides one. It loads\n * nothing, so only components registered with `registerComponent` render.\n */\nexport class RegistryOnlyComponentLoader implements ComponentLoader {\n async loadComponent(): Promise<Component | null> {\n return null;\n }\n}\n"],"names":["RegistryOnlyComponentLoader"],"mappings":"AAOO,MAAMA;IACT,MAAM,gBAA2C;QAC7C,OAAO;IACX;AACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComponentLoader, ComponentLoaderFactory } from "./ComponentLoader.js";
|
|
2
|
+
import type { ComponentLoaderFactoryParams } from "./ComponentLoader.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a content client's loader: its own factory if it has one, else the default set with
|
|
5
|
+
* `setDefaultComponentLoader`, else a loader that loads nothing.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createComponentLoader(factory: ComponentLoaderFactory | undefined, params: ComponentLoaderFactoryParams): ComponentLoader;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getDefaultComponentLoader } from "./defaultComponentLoader.js";
|
|
2
|
+
import { RegistryOnlyComponentLoader } from "./RegistryOnlyComponentLoader.js";
|
|
3
|
+
function createComponentLoader(factory, params) {
|
|
4
|
+
const resolved = factory ?? getDefaultComponentLoader();
|
|
5
|
+
if (!resolved) return new RegistryOnlyComponentLoader();
|
|
6
|
+
return resolved(params);
|
|
7
|
+
}
|
|
8
|
+
export { createComponentLoader };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=createComponentLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentLoader/createComponentLoader.js","sources":["../../src/componentLoader/createComponentLoader.ts"],"sourcesContent":["import type { ComponentLoader, ComponentLoaderFactory } from \"./ComponentLoader.js\";\nimport type { ComponentLoaderFactoryParams } from \"./ComponentLoader.js\";\nimport { getDefaultComponentLoader } from \"./defaultComponentLoader.js\";\nimport { RegistryOnlyComponentLoader } from \"./RegistryOnlyComponentLoader.js\";\n\n/**\n * Create a content client's loader: its own factory if it has one, else the default set with\n * `setDefaultComponentLoader`, else a loader that loads nothing.\n */\nexport function createComponentLoader(\n factory: ComponentLoaderFactory | undefined,\n params: ComponentLoaderFactoryParams\n): ComponentLoader {\n const resolved = factory ?? getDefaultComponentLoader();\n if (!resolved) {\n return new RegistryOnlyComponentLoader();\n }\n return resolved(params);\n}\n"],"names":["createComponentLoader","factory","params","resolved","getDefaultComponentLoader","RegistryOnlyComponentLoader"],"mappings":";;AASO,SAASA,sBACZC,OAA2C,EAC3CC,MAAoC;IAEpC,MAAMC,WAAWF,WAAWG;IAC5B,IAAI,CAACD,UACD,OAAO,IAAIE;IAEf,OAAOF,SAASD;AACpB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComponentLoaderFactory } from "./ComponentLoader.js";
|
|
2
|
+
/**
|
|
3
|
+
* Set the component loader that content clients use when their config has none. A framework
|
|
4
|
+
* integration sets it on import, the way it sets the headers provider.
|
|
5
|
+
*/
|
|
6
|
+
export declare const setDefaultComponentLoader: (factory: ComponentLoaderFactory | undefined) => void;
|
|
7
|
+
export declare const getDefaultComponentLoader: () => ComponentLoaderFactory | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
let defaultComponentLoader;
|
|
2
|
+
const setDefaultComponentLoader = (factory)=>{
|
|
3
|
+
defaultComponentLoader = factory;
|
|
4
|
+
};
|
|
5
|
+
const getDefaultComponentLoader = ()=>defaultComponentLoader;
|
|
6
|
+
export { getDefaultComponentLoader, setDefaultComponentLoader };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=defaultComponentLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentLoader/defaultComponentLoader.js","sources":["../../src/componentLoader/defaultComponentLoader.ts"],"sourcesContent":["import type { ComponentLoaderFactory } from \"./ComponentLoader.js\";\n\nlet defaultComponentLoader: ComponentLoaderFactory | undefined;\n\n/**\n * Set the component loader that content clients use when their config has none. A framework\n * integration sets it on import, the way it sets the headers provider.\n */\nexport const setDefaultComponentLoader = (factory: ComponentLoaderFactory | undefined) => {\n defaultComponentLoader = factory;\n};\n\nexport const getDefaultComponentLoader = () => defaultComponentLoader;\n"],"names":["defaultComponentLoader","setDefaultComponentLoader","factory","getDefaultComponentLoader"],"mappings":"AAEA,IAAIA;AAMG,MAAMC,4BAA4B,CAACC;IACtCF,yBAAyBE;AAC7B;AAEO,MAAMC,4BAA4B,IAAMH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|