@webiny/website-builder-sdk 0.0.0-unstable.0156a4c312
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/BindingsApi.d.ts +25 -0
- package/BindingsApi.js +35 -0
- package/BindingsApi.js.map +1 -0
- package/BindingsProcessor.d.ts +11 -0
- package/BindingsProcessor.js +40 -0
- package/BindingsProcessor.js.map +1 -0
- package/BindingsProcessor.test.d.ts +1 -0
- package/BindingsProcessor.test.js +91 -0
- package/BindingsProcessor.test.js.map +1 -0
- package/BindingsResolver.d.ts +23 -0
- package/BindingsResolver.js +104 -0
- package/BindingsResolver.js.map +1 -0
- package/BindingsResolver.test.d.ts +1 -0
- package/BindingsResolver.test.js +419 -0
- package/BindingsResolver.test.js.map +1 -0
- package/ComponentInputTraverser.d.ts +18 -0
- package/ComponentInputTraverser.js +39 -0
- package/ComponentInputTraverser.js.map +1 -0
- package/ComponentManifestToAstConverter.d.ts +13 -0
- package/ComponentManifestToAstConverter.js +23 -0
- package/ComponentManifestToAstConverter.js.map +1 -0
- package/ComponentRegistry.d.ts +16 -0
- package/ComponentRegistry.js +43 -0
- package/ComponentRegistry.js.map +1 -0
- package/ComponentResolver.d.ts +17 -0
- package/ComponentResolver.js +37 -0
- package/ComponentResolver.js.map +1 -0
- package/ConstraintEvaluator.d.ts +36 -0
- package/ConstraintEvaluator.js +302 -0
- package/ConstraintEvaluator.js.map +1 -0
- package/ConstraintEvaluator.test.d.ts +1 -0
- package/ConstraintEvaluator.test.js +1738 -0
- package/ConstraintEvaluator.test.js.map +1 -0
- package/ContentSdk.d.ts +118 -0
- package/ContentSdk.js +194 -0
- package/ContentSdk.js.map +1 -0
- package/DocumentStore.d.ts +15 -0
- package/DocumentStore.js +55 -0
- package/DocumentStore.js.map +1 -0
- package/DocumentStoreManager.d.ts +18 -0
- package/DocumentStoreManager.js +42 -0
- package/DocumentStoreManager.js.map +1 -0
- package/EditingSdk.d.ts +37 -0
- package/EditingSdk.js +131 -0
- package/EditingSdk.js.map +1 -0
- package/ElementBindings.d.ts +28 -0
- package/ElementBindings.js +88 -0
- package/ElementBindings.js.map +1 -0
- package/ElementBindings.test.d.ts +1 -0
- package/ElementBindings.test.js +127 -0
- package/ElementBindings.test.js.map +1 -0
- package/ElementFactory.d.ts +62 -0
- package/ElementFactory.js +179 -0
- package/ElementFactory.js.map +1 -0
- package/ElementFactory.test.d.ts +1 -0
- package/ElementFactory.test.js +353 -0
- package/ElementFactory.test.js.map +1 -0
- package/ElementSelection.d.ts +20 -0
- package/ElementSelection.js +32 -0
- package/ElementSelection.js.map +1 -0
- package/ElementSelection.test.d.ts +1 -0
- package/ElementSelection.test.js +73 -0
- package/ElementSelection.test.js.map +1 -0
- package/Environment.d.ts +13 -0
- package/Environment.js +23 -0
- package/Environment.js.map +1 -0
- package/Environment.test.d.ts +1 -0
- package/Environment.test.js +35 -0
- package/Environment.test.js.map +1 -0
- package/FunctionConverter.d.ts +6 -0
- package/FunctionConverter.js +12 -0
- package/FunctionConverter.js.map +1 -0
- package/GlobalComponentLanguage.d.ts +31 -0
- package/GlobalComponentLanguage.js +37 -0
- package/GlobalComponentLanguage.js.map +1 -0
- package/HashObject.d.ts +6 -0
- package/HashObject.js +16 -0
- package/HashObject.js.map +1 -0
- package/HotkeyManager.d.ts +6 -0
- package/HotkeyManager.js +51 -0
- package/HotkeyManager.js.map +1 -0
- package/IBindingsUpdater.d.ts +6 -0
- package/IBindingsUpdater.js +0 -0
- package/IRedirects.d.ts +5 -0
- package/IRedirects.js +0 -0
- package/InheritanceProcessor.d.ts +29 -0
- package/InheritanceProcessor.js +107 -0
- package/InheritanceProcessor.js.map +1 -0
- package/InheritanceProcessor.test.d.ts +1 -0
- package/InheritanceProcessor.test.js +192 -0
- package/InheritanceProcessor.test.js.map +1 -0
- package/InheritedValueResolver.d.ts +10 -0
- package/InheritedValueResolver.js +19 -0
- package/InheritedValueResolver.js.map +1 -0
- package/InputBindingsProcessor.d.ts +38 -0
- package/InputBindingsProcessor.js +204 -0
- package/InputBindingsProcessor.js.map +1 -0
- package/InputsBindingsProcessor.test.d.ts +1 -0
- package/InputsBindingsProcessor.test.js +359 -0
- package/InputsBindingsProcessor.test.js.map +1 -0
- package/InputsUpdater.d.ts +12 -0
- package/InputsUpdater.js +32 -0
- package/InputsUpdater.js.map +1 -0
- package/LICENSE +21 -0
- package/LayoutContentArea.d.ts +68 -0
- package/LayoutContentArea.js +78 -0
- package/LayoutContentArea.js.map +1 -0
- package/LayoutContentArea.test.d.ts +1 -0
- package/LayoutContentArea.test.js +111 -0
- package/LayoutContentArea.test.js.map +1 -0
- package/LiveSdk.d.ts +10 -0
- package/LiveSdk.js +21 -0
- package/LiveSdk.js.map +1 -0
- package/Logger.d.ts +2 -0
- package/Logger.js +14 -0
- package/Logger.js.map +1 -0
- package/MouseTracker.d.ts +39 -0
- package/MouseTracker.js +87 -0
- package/MouseTracker.js.map +1 -0
- package/NullSdk.d.ts +10 -0
- package/NullSdk.js +28 -0
- package/NullSdk.js.map +1 -0
- package/PreviewDocument.d.ts +10 -0
- package/PreviewDocument.js +35 -0
- package/PreviewDocument.js.map +1 -0
- package/PreviewSdk.d.ts +12 -0
- package/PreviewSdk.js +28 -0
- package/PreviewSdk.js.map +1 -0
- package/PreviewViewport.d.ts +13 -0
- package/PreviewViewport.js +65 -0
- package/PreviewViewport.js.map +1 -0
- package/PreviewViewport.test.d.ts +1 -0
- package/PreviewViewport.test.js +27 -0
- package/PreviewViewport.test.js.map +1 -0
- package/README.md +11 -0
- package/ResizeObserver.d.ts +5 -0
- package/ResizeObserver.js +34 -0
- package/ResizeObserver.js.map +1 -0
- package/StylesBindingsProcessor.d.ts +33 -0
- package/StylesBindingsProcessor.js +53 -0
- package/StylesBindingsProcessor.js.map +1 -0
- package/StylesUpdater.d.ts +10 -0
- package/StylesUpdater.js +32 -0
- package/StylesUpdater.js.map +1 -0
- package/Theme.d.ts +4 -0
- package/Theme.js +34 -0
- package/Theme.js.map +1 -0
- package/ViewportManager.d.ts +36 -0
- package/ViewportManager.js +98 -0
- package/ViewportManager.js.map +1 -0
- 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/constants.d.ts +7 -0
- package/constants.js +10 -0
- package/constants.js.map +1 -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/createElement.d.ts +10 -0
- package/createElement.js +7 -0
- package/createElement.js.map +1 -0
- package/createGlobalElementDocument.d.ts +6 -0
- package/createGlobalElementDocument.js +23 -0
- package/createGlobalElementDocument.js.map +1 -0
- package/createInput.d.ts +133 -0
- package/createInput.js +109 -0
- package/createInput.js.map +1 -0
- package/createTheme.d.ts +3 -0
- package/createTheme.js +4 -0
- package/createTheme.js.map +1 -0
- package/dataProviders/ApiClient.d.ts +23 -0
- package/dataProviders/ApiClient.js +45 -0
- package/dataProviders/ApiClient.js.map +1 -0
- package/dataProviders/DefaultDataProvider.d.ts +19 -0
- package/dataProviders/DefaultDataProvider.js +110 -0
- package/dataProviders/DefaultDataProvider.js.map +1 -0
- package/dataProviders/DefaultDataProvider.test.d.ts +1 -0
- package/dataProviders/DefaultDataProvider.test.js +81 -0
- package/dataProviders/DefaultDataProvider.test.js.map +1 -0
- 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_LAYOUT_BY_SLUG.d.ts +1 -0
- package/dataProviders/GET_LAYOUT_BY_SLUG.js +27 -0
- package/dataProviders/GET_LAYOUT_BY_SLUG.js.map +1 -0
- package/dataProviders/GET_PAGE_BY_ID.d.ts +1 -0
- package/dataProviders/GET_PAGE_BY_ID.js +31 -0
- package/dataProviders/GET_PAGE_BY_ID.js.map +1 -0
- package/dataProviders/GET_PAGE_BY_PATH.d.ts +1 -0
- package/dataProviders/GET_PAGE_BY_PATH.js +31 -0
- package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -0
- 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/LIST_PUBLISHED_PAGES.d.ts +1 -0
- package/dataProviders/LIST_PUBLISHED_PAGES.js +33 -0
- package/dataProviders/LIST_PUBLISHED_PAGES.js.map +1 -0
- package/dataProviders/NullDataProvider.d.ts +20 -0
- package/dataProviders/NullDataProvider.js +36 -0
- package/dataProviders/NullDataProvider.js.map +1 -0
- package/dataProviders/RedirectsProvider.d.ts +11 -0
- package/dataProviders/RedirectsProvider.js +29 -0
- package/dataProviders/RedirectsProvider.js.map +1 -0
- package/dataProviders/queries.test.d.ts +1 -0
- package/dataProviders/queries.test.js +53 -0
- package/dataProviders/queries.test.js.map +1 -0
- package/defaultBreakpoints.d.ts +2 -0
- package/defaultBreakpoints.js +46 -0
- package/defaultBreakpoints.js.map +1 -0
- package/documentOperations/$addElementReferenceToParent.d.ts +9 -0
- package/documentOperations/$addElementReferenceToParent.js +35 -0
- package/documentOperations/$addElementReferenceToParent.js.map +1 -0
- package/documentOperations/AddElement.d.ts +7 -0
- package/documentOperations/AddElement.js +11 -0
- package/documentOperations/AddElement.js.map +1 -0
- package/documentOperations/AddToParent.d.ts +8 -0
- package/documentOperations/AddToParent.js +18 -0
- package/documentOperations/AddToParent.js.map +1 -0
- package/documentOperations/IDocumentOperation.d.ts +4 -0
- package/documentOperations/IDocumentOperation.js +0 -0
- package/documentOperations/RemoveElement.d.ts +7 -0
- package/documentOperations/RemoveElement.js +13 -0
- package/documentOperations/RemoveElement.js.map +1 -0
- package/documentOperations/SetGlobalInputBinding.d.ts +9 -0
- package/documentOperations/SetGlobalInputBinding.js +26 -0
- package/documentOperations/SetGlobalInputBinding.js.map +1 -0
- package/documentOperations/SetGlobalStyleBinding.d.ts +9 -0
- package/documentOperations/SetGlobalStyleBinding.js +26 -0
- package/documentOperations/SetGlobalStyleBinding.js.map +1 -0
- package/documentOperations/SetInputBindingOverride.d.ts +10 -0
- package/documentOperations/SetInputBindingOverride.js +34 -0
- package/documentOperations/SetInputBindingOverride.js.map +1 -0
- package/documentOperations/SetStyleBindingOverride.d.ts +10 -0
- package/documentOperations/SetStyleBindingOverride.js +34 -0
- package/documentOperations/SetStyleBindingOverride.js.map +1 -0
- package/documentOperations/index.d.ts +17 -0
- package/documentOperations/index.js +19 -0
- package/documentOperations/index.js.map +1 -0
- 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/findMatchingAstNode.d.ts +2 -0
- package/findMatchingAstNode.js +15 -0
- package/findMatchingAstNode.js.map +1 -0
- package/generateElementId.d.ts +1 -0
- package/generateElementId.js +7 -0
- package/generateElementId.js.map +1 -0
- package/globalElements.d.ts +43 -0
- package/globalElements.js +79 -0
- package/globalElements.js.map +1 -0
- package/globalElements.test.d.ts +1 -0
- package/globalElements.test.js +343 -0
- package/globalElements.test.js.map +1 -0
- package/headersProvider.d.ts +3 -0
- package/headersProvider.js +8 -0
- package/headersProvider.js.map +1 -0
- 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 +49 -0
- package/index.js +48 -0
- package/jsonPatch.d.ts +6 -0
- package/jsonPatch.js +8 -0
- package/jsonPatch.js.map +1 -0
- package/messages.d.ts +13 -0
- package/messages.js +16 -0
- package/messages.js.map +1 -0
- package/messenger/MessageOrigin.d.ts +7 -0
- package/messenger/MessageOrigin.js +15 -0
- package/messenger/MessageOrigin.js.map +1 -0
- package/messenger/Messenger.d.ts +22 -0
- package/messenger/Messenger.js +69 -0
- package/messenger/Messenger.js.map +1 -0
- package/messenger/index.d.ts +2 -0
- package/messenger/index.js +2 -0
- package/package.json +50 -0
- package/registerComponentGroup.d.ts +2 -0
- package/registerComponentGroup.js +9 -0
- package/registerComponentGroup.js.map +1 -0
- package/types/ShorthandCssProperties.d.ts +1 -0
- package/types/ShorthandCssProperties.js +0 -0
- package/types/WebsiteBuilderTheme.d.ts +101 -0
- package/types/WebsiteBuilderTheme.js +0 -0
- package/types.d.ts +607 -0
- package/types.js +0 -0
- package/withGlobalElementDefaults.d.ts +8 -0
- package/withGlobalElementDefaults.js +60 -0
- package/withGlobalElementDefaults.js.map +1 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { BindingsResolver } from "./BindingsResolver.js";
|
|
3
|
+
import { createSlotInput, createTextInput } from "./createInput.js";
|
|
4
|
+
import { ComponentManifestToAstConverter } from "./ComponentManifestToAstConverter.js";
|
|
5
|
+
describe("BindingsResolver", ()=>{
|
|
6
|
+
const baseElement = {
|
|
7
|
+
id: "test1",
|
|
8
|
+
type: "Webiny/Element",
|
|
9
|
+
component: {
|
|
10
|
+
name: "Webiny/Text"
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const rootElement = {
|
|
14
|
+
id: "root",
|
|
15
|
+
type: "Webiny/Element",
|
|
16
|
+
component: {
|
|
17
|
+
name: "Webiny/Root"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
it("resolves input with expression binding", ()=>{
|
|
21
|
+
const state = {
|
|
22
|
+
user: {
|
|
23
|
+
name: "Alice"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const bindings = {
|
|
27
|
+
inputs: {
|
|
28
|
+
text: {
|
|
29
|
+
id: "text",
|
|
30
|
+
type: "text",
|
|
31
|
+
expression: "$state.user.name",
|
|
32
|
+
static: "Static fallback"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
styles: {
|
|
36
|
+
paddingTop: {
|
|
37
|
+
static: "10px"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const inputs = [
|
|
42
|
+
createTextInput({
|
|
43
|
+
name: "text"
|
|
44
|
+
})
|
|
45
|
+
];
|
|
46
|
+
const inputAst = ComponentManifestToAstConverter.convert(inputs);
|
|
47
|
+
const resolver = new BindingsResolver(state);
|
|
48
|
+
const [resolved] = resolver.resolveElement({
|
|
49
|
+
element: baseElement,
|
|
50
|
+
inputAst,
|
|
51
|
+
elementBindings: bindings
|
|
52
|
+
});
|
|
53
|
+
expect(resolved.inputs.text).toBe("Alice");
|
|
54
|
+
expect(resolved.styles).toEqual({
|
|
55
|
+
paddingTop: "10px"
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it("resolves nested objects", ()=>{
|
|
59
|
+
const state = {};
|
|
60
|
+
const bindings = {
|
|
61
|
+
root: {
|
|
62
|
+
inputs: {
|
|
63
|
+
children: {
|
|
64
|
+
id: "children",
|
|
65
|
+
type: "slot",
|
|
66
|
+
list: true,
|
|
67
|
+
static: [
|
|
68
|
+
"qizw1hgqjvj8g5a43szzc"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
qizw1hgqjvj8g5a43szzc: {
|
|
74
|
+
inputs: {
|
|
75
|
+
title: {
|
|
76
|
+
id: "title",
|
|
77
|
+
static: "Default Columns Title",
|
|
78
|
+
type: "text"
|
|
79
|
+
},
|
|
80
|
+
"leftColumn/0": {
|
|
81
|
+
id: "slot",
|
|
82
|
+
static: [
|
|
83
|
+
"7znyr9z2cpizegnrk2rhu"
|
|
84
|
+
],
|
|
85
|
+
type: "slot",
|
|
86
|
+
list: true
|
|
87
|
+
},
|
|
88
|
+
"rightColumn/0": {
|
|
89
|
+
id: "slot",
|
|
90
|
+
static: [
|
|
91
|
+
"cwld8kxy0qhhtaql42lr5"
|
|
92
|
+
],
|
|
93
|
+
type: "slot",
|
|
94
|
+
list: true
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
styles: {
|
|
98
|
+
paddingTop: {
|
|
99
|
+
static: "20px"
|
|
100
|
+
},
|
|
101
|
+
backgroundColor: {
|
|
102
|
+
static: "#5c9a12"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"7znyr9z2cpizegnrk2rhu": {
|
|
107
|
+
inputs: {
|
|
108
|
+
title: {
|
|
109
|
+
id: "title",
|
|
110
|
+
static: "Left Column Title",
|
|
111
|
+
type: "text"
|
|
112
|
+
},
|
|
113
|
+
children: {
|
|
114
|
+
id: "slot",
|
|
115
|
+
static: [],
|
|
116
|
+
type: "slot",
|
|
117
|
+
list: true
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
styles: {
|
|
121
|
+
backgroundColor: {
|
|
122
|
+
static: "red"
|
|
123
|
+
},
|
|
124
|
+
marginTop: {
|
|
125
|
+
static: "20px"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
cwld8kxy0qhhtaql42lr5: {
|
|
130
|
+
inputs: {
|
|
131
|
+
title: {
|
|
132
|
+
id: "title",
|
|
133
|
+
static: "Right Column Title",
|
|
134
|
+
type: "text"
|
|
135
|
+
},
|
|
136
|
+
children: {
|
|
137
|
+
id: "slot",
|
|
138
|
+
static: [],
|
|
139
|
+
type: "slot",
|
|
140
|
+
list: true
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
styles: {
|
|
144
|
+
backgroundColor: {
|
|
145
|
+
static: "blue"
|
|
146
|
+
},
|
|
147
|
+
marginTop: {
|
|
148
|
+
static: "20px"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const elements = {
|
|
154
|
+
root: {
|
|
155
|
+
type: "Webiny/Element",
|
|
156
|
+
id: "root",
|
|
157
|
+
component: {
|
|
158
|
+
name: "Webiny/Root"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
qizw1hgqjvj8g5a43szzc: {
|
|
162
|
+
type: "Webiny/Element",
|
|
163
|
+
id: "qizw1hgqjvj8g5a43szzc",
|
|
164
|
+
parent: {
|
|
165
|
+
id: "root",
|
|
166
|
+
slot: "children"
|
|
167
|
+
},
|
|
168
|
+
component: {
|
|
169
|
+
name: "Webiny/TwoColumns"
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
"7znyr9z2cpizegnrk2rhu": {
|
|
173
|
+
type: "Webiny/Element",
|
|
174
|
+
id: "7znyr9z2cpizegnrk2rhu",
|
|
175
|
+
parent: {
|
|
176
|
+
id: "qizw1hgqjvj8g5a43szzc",
|
|
177
|
+
slot: "leftColumn/0"
|
|
178
|
+
},
|
|
179
|
+
component: {
|
|
180
|
+
name: "Webiny/TextWithDropzone"
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
cwld8kxy0qhhtaql42lr5: {
|
|
184
|
+
type: "Webiny/Element",
|
|
185
|
+
id: "cwld8kxy0qhhtaql42lr5",
|
|
186
|
+
parent: {
|
|
187
|
+
id: "qizw1hgqjvj8g5a43szzc",
|
|
188
|
+
slot: "rightColumn/0"
|
|
189
|
+
},
|
|
190
|
+
component: {
|
|
191
|
+
name: "Webiny/TextWithDropzone"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const inputs = [
|
|
196
|
+
{
|
|
197
|
+
type: "text",
|
|
198
|
+
renderer: "Webiny/Input",
|
|
199
|
+
name: "title",
|
|
200
|
+
label: "Title",
|
|
201
|
+
fields: []
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
type: "slot",
|
|
205
|
+
list: true,
|
|
206
|
+
renderer: "Webiny/Slot",
|
|
207
|
+
name: "leftColumn",
|
|
208
|
+
fields: []
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
type: "slot",
|
|
212
|
+
list: true,
|
|
213
|
+
renderer: "Webiny/Slot",
|
|
214
|
+
name: "rightColumn",
|
|
215
|
+
fields: []
|
|
216
|
+
}
|
|
217
|
+
];
|
|
218
|
+
const inputAst = ComponentManifestToAstConverter.convert(inputs);
|
|
219
|
+
const resolver = new BindingsResolver(state);
|
|
220
|
+
const [resolved] = resolver.resolveElement({
|
|
221
|
+
element: elements["qizw1hgqjvj8g5a43szzc"],
|
|
222
|
+
inputAst,
|
|
223
|
+
elementBindings: bindings["qizw1hgqjvj8g5a43szzc"]
|
|
224
|
+
});
|
|
225
|
+
expect(resolved.inputs.title).toBe("Default Columns Title");
|
|
226
|
+
expect(resolved.inputs.leftColumn).toEqual([
|
|
227
|
+
[
|
|
228
|
+
"7znyr9z2cpizegnrk2rhu"
|
|
229
|
+
]
|
|
230
|
+
]);
|
|
231
|
+
expect(resolved.inputs.rightColumn).toEqual([
|
|
232
|
+
[
|
|
233
|
+
"cwld8kxy0qhhtaql42lr5"
|
|
234
|
+
]
|
|
235
|
+
]);
|
|
236
|
+
});
|
|
237
|
+
it("falls back to static if no expression is provided", ()=>{
|
|
238
|
+
const state = {};
|
|
239
|
+
const bindings = {
|
|
240
|
+
inputs: {
|
|
241
|
+
text: {
|
|
242
|
+
id: "text",
|
|
243
|
+
type: "text",
|
|
244
|
+
static: "Static only"
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const inputs = [
|
|
249
|
+
createTextInput({
|
|
250
|
+
name: "text"
|
|
251
|
+
})
|
|
252
|
+
];
|
|
253
|
+
const inputAst = ComponentManifestToAstConverter.convert(inputs);
|
|
254
|
+
const resolver = new BindingsResolver(state);
|
|
255
|
+
const [resolved] = resolver.resolveElement({
|
|
256
|
+
element: baseElement,
|
|
257
|
+
inputAst,
|
|
258
|
+
elementBindings: bindings
|
|
259
|
+
});
|
|
260
|
+
expect(resolved.inputs.text).toBe("Static only");
|
|
261
|
+
});
|
|
262
|
+
it("uses undefined if expression fails and no static exists", ()=>{
|
|
263
|
+
const state = {};
|
|
264
|
+
const bindings = {
|
|
265
|
+
inputs: {
|
|
266
|
+
text: {
|
|
267
|
+
id: "text",
|
|
268
|
+
type: "text",
|
|
269
|
+
static: "Fallback",
|
|
270
|
+
expression: "$.unknown.value"
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
const inputs = [
|
|
275
|
+
createTextInput({
|
|
276
|
+
name: "text"
|
|
277
|
+
})
|
|
278
|
+
];
|
|
279
|
+
const inputAst = ComponentManifestToAstConverter.convert(inputs);
|
|
280
|
+
const resolver = new BindingsResolver(state);
|
|
281
|
+
const [resolved] = resolver.resolveElement({
|
|
282
|
+
element: baseElement,
|
|
283
|
+
inputAst,
|
|
284
|
+
elementBindings: bindings
|
|
285
|
+
});
|
|
286
|
+
expect(resolved.inputs.text).toBeUndefined();
|
|
287
|
+
});
|
|
288
|
+
it("uses input's `defaultValue` if binding doesn't exist", ()=>{
|
|
289
|
+
const state = {};
|
|
290
|
+
const bindings = {
|
|
291
|
+
inputs: {}
|
|
292
|
+
};
|
|
293
|
+
const inputs = [
|
|
294
|
+
createSlotInput({
|
|
295
|
+
name: "children",
|
|
296
|
+
defaultValue: []
|
|
297
|
+
})
|
|
298
|
+
];
|
|
299
|
+
const inputAst = ComponentManifestToAstConverter.convert(inputs);
|
|
300
|
+
const resolver = new BindingsResolver(state);
|
|
301
|
+
const [resolved] = resolver.resolveElement({
|
|
302
|
+
element: rootElement,
|
|
303
|
+
inputAst,
|
|
304
|
+
elementBindings: bindings,
|
|
305
|
+
onResolved (value, input) {
|
|
306
|
+
if ("slot" === input.type) return "slot";
|
|
307
|
+
return value;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
expect(resolved.inputs.children).toEqual("slot");
|
|
311
|
+
});
|
|
312
|
+
it("handles $repeat using expression and maps items", ()=>{
|
|
313
|
+
const state = {
|
|
314
|
+
products: [
|
|
315
|
+
{
|
|
316
|
+
title: "Shirt"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
title: "Hat"
|
|
320
|
+
}
|
|
321
|
+
]
|
|
322
|
+
};
|
|
323
|
+
const bindings = {
|
|
324
|
+
$repeat: {
|
|
325
|
+
expression: "$state.products"
|
|
326
|
+
},
|
|
327
|
+
inputs: {
|
|
328
|
+
text: {
|
|
329
|
+
id: "text",
|
|
330
|
+
type: "text",
|
|
331
|
+
expression: "$.title",
|
|
332
|
+
static: "Unnamed"
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
const inputs = [
|
|
337
|
+
createTextInput({
|
|
338
|
+
name: "text"
|
|
339
|
+
})
|
|
340
|
+
];
|
|
341
|
+
const inputAst = ComponentManifestToAstConverter.convert(inputs);
|
|
342
|
+
const resolver = new BindingsResolver(state);
|
|
343
|
+
const resolved = resolver.resolveElement({
|
|
344
|
+
element: baseElement,
|
|
345
|
+
inputAst,
|
|
346
|
+
elementBindings: bindings
|
|
347
|
+
});
|
|
348
|
+
expect(resolved).toHaveLength(2);
|
|
349
|
+
expect(resolved[0].inputs.text).toBe("Shirt");
|
|
350
|
+
expect(resolved[1].inputs.text).toBe("Hat");
|
|
351
|
+
});
|
|
352
|
+
it("returns empty array if $repeat doesn't resolve to an array", ()=>{
|
|
353
|
+
const state = {
|
|
354
|
+
invalid: 42
|
|
355
|
+
};
|
|
356
|
+
const bindings = {
|
|
357
|
+
$repeat: {
|
|
358
|
+
expression: "$state.invalid"
|
|
359
|
+
},
|
|
360
|
+
inputs: {
|
|
361
|
+
text: {
|
|
362
|
+
id: "text",
|
|
363
|
+
type: "text",
|
|
364
|
+
static: "Should not be used"
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const inputs = [
|
|
369
|
+
createTextInput({
|
|
370
|
+
name: "text"
|
|
371
|
+
})
|
|
372
|
+
];
|
|
373
|
+
const inputAst = ComponentManifestToAstConverter.convert(inputs);
|
|
374
|
+
const resolver = new BindingsResolver(state);
|
|
375
|
+
const resolved = resolver.resolveElement({
|
|
376
|
+
element: baseElement,
|
|
377
|
+
inputAst,
|
|
378
|
+
elementBindings: bindings
|
|
379
|
+
});
|
|
380
|
+
expect(resolved).toEqual([]);
|
|
381
|
+
});
|
|
382
|
+
it("resolves binding that refers to a specific array index", ()=>{
|
|
383
|
+
const state = {
|
|
384
|
+
list: [
|
|
385
|
+
{
|
|
386
|
+
text: "First item text"
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
text: "Second item text"
|
|
390
|
+
}
|
|
391
|
+
]
|
|
392
|
+
};
|
|
393
|
+
const bindings = {
|
|
394
|
+
inputs: {
|
|
395
|
+
text: {
|
|
396
|
+
id: "text",
|
|
397
|
+
type: "text",
|
|
398
|
+
static: "Static fallback",
|
|
399
|
+
expression: "$state.list.0.text"
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
const inputs = [
|
|
404
|
+
createTextInput({
|
|
405
|
+
name: "text"
|
|
406
|
+
})
|
|
407
|
+
];
|
|
408
|
+
const inputAst = ComponentManifestToAstConverter.convert(inputs);
|
|
409
|
+
const resolver = new BindingsResolver(state);
|
|
410
|
+
const [resolved] = resolver.resolveElement({
|
|
411
|
+
element: baseElement,
|
|
412
|
+
inputAst,
|
|
413
|
+
elementBindings: bindings
|
|
414
|
+
});
|
|
415
|
+
expect(resolved.inputs.text).toBe("First item text");
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
//# sourceMappingURL=BindingsResolver.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BindingsResolver.test.js","sources":["../src/BindingsResolver.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { BindingsResolver } from \"./BindingsResolver.js\";\nimport type {\n DocumentElement,\n DocumentState,\n DocumentElementBindings,\n DocumentBindings\n} from \"~/types.js\";\nimport { createSlotInput, createTextInput } from \"~/createInput.js\";\nimport { ComponentManifestToAstConverter } from \"~/ComponentManifestToAstConverter.js\";\n\ndescribe(\"BindingsResolver\", () => {\n const baseElement: DocumentElement = {\n id: \"test1\",\n type: \"Webiny/Element\",\n component: {\n name: \"Webiny/Text\"\n }\n };\n\n const rootElement: DocumentElement = {\n id: \"root\",\n type: \"Webiny/Element\",\n component: {\n name: \"Webiny/Root\"\n }\n };\n\n it(\"resolves input with expression binding\", () => {\n const state: DocumentState = {\n user: { name: \"Alice\" }\n };\n\n const bindings: DocumentElementBindings = {\n inputs: {\n text: {\n id: \"text\",\n type: \"text\",\n expression: \"$state.user.name\",\n static: \"Static fallback\"\n }\n },\n styles: {\n paddingTop: {\n static: \"10px\"\n }\n }\n };\n\n const inputs = [createTextInput({ name: \"text\" })];\n const inputAst = ComponentManifestToAstConverter.convert(inputs);\n const resolver = new BindingsResolver(state);\n const [resolved] = resolver.resolveElement({\n element: baseElement,\n inputAst,\n elementBindings: bindings\n });\n\n expect(resolved.inputs.text).toBe(\"Alice\");\n expect(resolved.styles).toEqual({ paddingTop: \"10px\" });\n });\n\n it(\"resolves nested objects\", () => {\n const state: DocumentState = {};\n\n const bindings: DocumentBindings = {\n root: {\n inputs: {\n children: {\n id: \"children\",\n type: \"slot\",\n list: true,\n static: [\"qizw1hgqjvj8g5a43szzc\"]\n }\n }\n },\n qizw1hgqjvj8g5a43szzc: {\n inputs: {\n title: {\n id: \"title\",\n static: \"Default Columns Title\",\n type: \"text\"\n },\n \"leftColumn/0\": {\n id: \"slot\",\n static: [\"7znyr9z2cpizegnrk2rhu\"],\n type: \"slot\",\n list: true\n },\n \"rightColumn/0\": {\n id: \"slot\",\n static: [\"cwld8kxy0qhhtaql42lr5\"],\n type: \"slot\",\n list: true\n }\n },\n styles: {\n paddingTop: {\n static: \"20px\"\n },\n backgroundColor: {\n static: \"#5c9a12\"\n }\n }\n },\n \"7znyr9z2cpizegnrk2rhu\": {\n inputs: {\n title: {\n id: \"title\",\n static: \"Left Column Title\",\n type: \"text\"\n },\n children: {\n id: \"slot\",\n static: [],\n type: \"slot\",\n list: true\n }\n },\n styles: {\n backgroundColor: {\n static: \"red\"\n },\n marginTop: {\n static: \"20px\"\n }\n }\n },\n cwld8kxy0qhhtaql42lr5: {\n inputs: {\n title: {\n id: \"title\",\n static: \"Right Column Title\",\n type: \"text\"\n },\n children: {\n id: \"slot\",\n static: [],\n type: \"slot\",\n list: true\n }\n },\n styles: {\n backgroundColor: {\n static: \"blue\"\n },\n marginTop: {\n static: \"20px\"\n }\n }\n }\n };\n\n const elements = {\n root: {\n type: \"Webiny/Element\",\n id: \"root\",\n component: {\n name: \"Webiny/Root\"\n }\n },\n qizw1hgqjvj8g5a43szzc: {\n type: \"Webiny/Element\",\n id: \"qizw1hgqjvj8g5a43szzc\",\n parent: {\n id: \"root\",\n slot: \"children\"\n },\n component: {\n name: \"Webiny/TwoColumns\"\n }\n },\n \"7znyr9z2cpizegnrk2rhu\": {\n type: \"Webiny/Element\",\n id: \"7znyr9z2cpizegnrk2rhu\",\n parent: {\n id: \"qizw1hgqjvj8g5a43szzc\",\n slot: \"leftColumn/0\"\n },\n component: {\n name: \"Webiny/TextWithDropzone\"\n }\n },\n cwld8kxy0qhhtaql42lr5: {\n type: \"Webiny/Element\",\n id: \"cwld8kxy0qhhtaql42lr5\",\n parent: {\n id: \"qizw1hgqjvj8g5a43szzc\",\n slot: \"rightColumn/0\"\n },\n component: {\n name: \"Webiny/TextWithDropzone\"\n }\n }\n };\n\n const inputs = [\n {\n type: \"text\",\n renderer: \"Webiny/Input\",\n name: \"title\",\n label: \"Title\",\n fields: []\n },\n {\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n name: \"leftColumn\",\n fields: []\n },\n {\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n name: \"rightColumn\",\n fields: []\n }\n ];\n const inputAst = ComponentManifestToAstConverter.convert(inputs);\n const resolver = new BindingsResolver(state);\n const [resolved] = resolver.resolveElement({\n element: elements[\"qizw1hgqjvj8g5a43szzc\"] as DocumentElement,\n inputAst,\n elementBindings: bindings[\"qizw1hgqjvj8g5a43szzc\"]\n });\n\n expect(resolved.inputs.title).toBe(\"Default Columns Title\");\n expect(resolved.inputs.leftColumn).toEqual([[\"7znyr9z2cpizegnrk2rhu\"]]);\n expect(resolved.inputs.rightColumn).toEqual([[\"cwld8kxy0qhhtaql42lr5\"]]);\n });\n\n it(\"falls back to static if no expression is provided\", () => {\n const state: DocumentState = {};\n\n const bindings: DocumentElementBindings = {\n inputs: {\n text: {\n id: \"text\",\n type: \"text\",\n static: \"Static only\"\n }\n }\n };\n\n const inputs = [createTextInput({ name: \"text\" })];\n const inputAst = ComponentManifestToAstConverter.convert(inputs);\n const resolver = new BindingsResolver(state);\n const [resolved] = resolver.resolveElement({\n element: baseElement,\n inputAst,\n elementBindings: bindings\n });\n\n expect(resolved.inputs.text).toBe(\"Static only\");\n });\n\n it(\"uses undefined if expression fails and no static exists\", () => {\n const state: DocumentState = {};\n\n const bindings: DocumentElementBindings = {\n inputs: {\n text: {\n id: \"text\",\n type: \"text\",\n static: \"Fallback\",\n expression: \"$.unknown.value\"\n }\n }\n };\n\n const inputs = [createTextInput({ name: \"text\" })];\n const inputAst = ComponentManifestToAstConverter.convert(inputs);\n const resolver = new BindingsResolver(state);\n const [resolved] = resolver.resolveElement({\n element: baseElement,\n inputAst,\n elementBindings: bindings\n });\n\n expect(resolved.inputs.text).toBeUndefined();\n });\n\n it(\"uses input's `defaultValue` if binding doesn't exist\", () => {\n const state: DocumentState = {};\n\n const bindings: DocumentElementBindings = {\n inputs: {}\n };\n\n const inputs = [createSlotInput({ name: \"children\", defaultValue: [] })];\n const inputAst = ComponentManifestToAstConverter.convert(inputs);\n const resolver = new BindingsResolver(state);\n const [resolved] = resolver.resolveElement({\n element: rootElement,\n inputAst,\n elementBindings: bindings,\n onResolved(value, input) {\n if (input.type === \"slot\") {\n return \"slot\";\n }\n\n return value;\n }\n });\n\n expect(resolved.inputs.children).toEqual(\"slot\");\n });\n\n it(\"handles $repeat using expression and maps items\", () => {\n const state: DocumentState = {\n products: [{ title: \"Shirt\" }, { title: \"Hat\" }]\n };\n\n const bindings: DocumentElementBindings = {\n $repeat: {\n expression: \"$state.products\"\n },\n inputs: {\n text: {\n id: \"text\",\n type: \"text\",\n expression: \"$.title\",\n static: \"Unnamed\"\n }\n }\n };\n\n const inputs = [createTextInput({ name: \"text\" })];\n const inputAst = ComponentManifestToAstConverter.convert(inputs);\n const resolver = new BindingsResolver(state);\n const resolved = resolver.resolveElement({\n element: baseElement,\n inputAst,\n elementBindings: bindings\n });\n\n expect(resolved).toHaveLength(2);\n expect(resolved[0].inputs.text).toBe(\"Shirt\");\n expect(resolved[1].inputs.text).toBe(\"Hat\");\n });\n\n it(\"returns empty array if $repeat doesn't resolve to an array\", () => {\n const state: DocumentState = {\n invalid: 42\n };\n\n const bindings: DocumentElementBindings = {\n $repeat: {\n expression: \"$state.invalid\"\n },\n inputs: {\n text: {\n id: \"text\",\n type: \"text\",\n static: \"Should not be used\"\n }\n }\n };\n\n const inputs = [createTextInput({ name: \"text\" })];\n const inputAst = ComponentManifestToAstConverter.convert(inputs);\n const resolver = new BindingsResolver(state);\n const resolved = resolver.resolveElement({\n element: baseElement,\n inputAst,\n elementBindings: bindings\n });\n\n expect(resolved).toEqual([]);\n });\n\n it(\"resolves binding that refers to a specific array index\", () => {\n const state: DocumentState = {\n list: [{ text: \"First item text\" }, { text: \"Second item text\" }]\n };\n\n const bindings: DocumentElementBindings = {\n inputs: {\n text: {\n id: \"text\",\n type: \"text\",\n static: \"Static fallback\",\n expression: \"$state.list.0.text\"\n }\n }\n };\n\n const inputs = [createTextInput({ name: \"text\" })];\n const inputAst = ComponentManifestToAstConverter.convert(inputs);\n const resolver = new BindingsResolver(state);\n const [resolved] = resolver.resolveElement({\n element: baseElement,\n inputAst,\n elementBindings: bindings\n });\n\n expect(resolved.inputs.text).toBe(\"First item text\");\n });\n});\n"],"names":["describe","baseElement","rootElement","it","state","bindings","inputs","createTextInput","inputAst","ComponentManifestToAstConverter","resolver","BindingsResolver","resolved","expect","elements","createSlotInput","value","input"],"mappings":";;;;AAWAA,SAAS,oBAAoB;IACzB,MAAMC,cAA+B;QACjC,IAAI;QACJ,MAAM;QACN,WAAW;YACP,MAAM;QACV;IACJ;IAEA,MAAMC,cAA+B;QACjC,IAAI;QACJ,MAAM;QACN,WAAW;YACP,MAAM;QACV;IACJ;IAEAC,GAAG,0CAA0C;QACzC,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,MAAMC,QAAuB;YACzB,SAAS;QACb;QAEA,MAAMC,WAAoC;YACtC,SAAS;gBACL,YAAY;YAChB;YACA,QAAQ;gBACJ,MAAM;oBACF,IAAI;oBACJ,MAAM;oBACN,QAAQ;gBACZ;YACJ;QACJ;QAEA,MAAMC,SAAS;YAACC,gBAAgB;gBAAE,MAAM;YAAO;SAAG;QAClD,MAAMC,WAAWC,gCAAgC,OAAO,CAACH;QACzD,MAAMI,WAAW,IAAIC,iBAAiBP;QACtC,MAAMQ,WAAWF,SAAS,cAAc,CAAC;YACrC,SAAST;YACTO;YACA,iBAAiBH;QACrB;QAEAQ,OAAOD,UAAU,OAAO,CAAC,EAAE;IAC/B;IAEAT,GAAG,0DAA0D;QACzD,MAAMC,QAAuB;YACzB,MAAM;gBAAC;oBAAE,MAAM;gBAAkB;gBAAG;oBAAE,MAAM;gBAAmB;aAAE;QACrE;QAEA,MAAMC,WAAoC;YACtC,QAAQ;gBACJ,MAAM;oBACF,IAAI;oBACJ,MAAM;oBACN,QAAQ;oBACR,YAAY;gBAChB;YACJ;QACJ;QAEA,MAAMC,SAAS;YAACC,gBAAgB;gBAAE,MAAM;YAAO;SAAG;QAClD,MAAMC,WAAWC,gCAAgC,OAAO,CAACH;QACzD,MAAMI,WAAW,IAAIC,iBAAiBP;QACtC,MAAM,CAACQ,SAAS,GAAGF,SAAS,cAAc,CAAC;YACvC,SAAST;YACTO;YACA,iBAAiBH;QACrB;QAEAQ,OAAOD,SAAS,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC;IACtC;AACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { InputAstNode } from "./ComponentManifestToAstConverter.js";
|
|
2
|
+
export type InputVisitor = (node: InputAstNode, path: string, value: any) => void;
|
|
3
|
+
/**
|
|
4
|
+
* ComponentInputTraverser
|
|
5
|
+
*
|
|
6
|
+
* Walks an input AST and a matching data object,
|
|
7
|
+
* invoking `visitor` for each leaf value found.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ComponentInputTraverser {
|
|
10
|
+
private readonly ast;
|
|
11
|
+
constructor(ast: InputAstNode[]);
|
|
12
|
+
/**
|
|
13
|
+
* Traverse the given `data` object according to the AST,
|
|
14
|
+
* calling `visitor(node, path, value)` for each leaf.
|
|
15
|
+
*/
|
|
16
|
+
traverse(data: Record<string, any>, visitor: InputVisitor): void;
|
|
17
|
+
private traverseNode;
|
|
18
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class ComponentInputTraverser {
|
|
2
|
+
constructor(ast){
|
|
3
|
+
this.ast = ast;
|
|
4
|
+
}
|
|
5
|
+
traverse(data, visitor) {
|
|
6
|
+
for (const node of this.ast){
|
|
7
|
+
const rootValue = data[node.name];
|
|
8
|
+
this.traverseNode(node, rootValue, node.name, visitor);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
traverseNode(node, value, currentPath, visitor) {
|
|
12
|
+
if (node.list) {
|
|
13
|
+
value = value ?? [];
|
|
14
|
+
if (0 === value.length) visitor(node, currentPath, value);
|
|
15
|
+
if (0 === node.children.length && "slot" !== node.type) {
|
|
16
|
+
if (value.length > 0) visitor(node, currentPath, value);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
value.forEach((item, index)=>{
|
|
20
|
+
if (node.children.length > 0) {
|
|
21
|
+
const itemPath = `${currentPath}/${index}`;
|
|
22
|
+
for (const child of node.children){
|
|
23
|
+
const childValue = item?.[child.name];
|
|
24
|
+
const childPath = `${itemPath}/${child.name}`;
|
|
25
|
+
this.traverseNode(child, childValue, childPath, visitor);
|
|
26
|
+
}
|
|
27
|
+
} else visitor(node, currentPath, item);
|
|
28
|
+
});
|
|
29
|
+
} else if (node.children.length > 0) for (const child of node.children){
|
|
30
|
+
const childValue = value?.[child.name];
|
|
31
|
+
const childPath = `${currentPath}/${child.name}`;
|
|
32
|
+
this.traverseNode(child, childValue, childPath, visitor);
|
|
33
|
+
}
|
|
34
|
+
else visitor(node, currentPath, value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export { ComponentInputTraverser };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=ComponentInputTraverser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComponentInputTraverser.js","sources":["../src/ComponentInputTraverser.ts"],"sourcesContent":["import type { InputAstNode } from \"./ComponentManifestToAstConverter.js\";\n\n// Visitor signature: called for every resolved leaf\nexport type InputVisitor = (node: InputAstNode, path: string, value: any) => void;\n\n/**\n * ComponentInputTraverser\n *\n * Walks an input AST and a matching data object,\n * invoking `visitor` for each leaf value found.\n */\nexport class ComponentInputTraverser {\n private readonly ast: InputAstNode[];\n\n constructor(ast: InputAstNode[]) {\n this.ast = ast;\n }\n\n /**\n * Traverse the given `data` object according to the AST,\n * calling `visitor(node, path, value)` for each leaf.\n */\n public traverse(data: Record<string, any>, visitor: InputVisitor): void {\n for (const node of this.ast) {\n const rootValue = data[node.name];\n this.traverseNode(node, rootValue, node.name, visitor);\n }\n }\n\n private traverseNode(\n node: InputAstNode,\n value: any,\n currentPath: string,\n visitor: InputVisitor\n ): void {\n if (node.list) {\n value = value ?? [];\n\n if (value.length === 0) {\n visitor(node, currentPath, value);\n }\n\n // A list of primitives (e.g. tags) is a single leaf: its value is the whole array.\n // Visiting each item would write every item to the same path, leaving only the last.\n // Slot lists are still visited per item, as each item creates its own element.\n if (node.children.length === 0 && node.type !== \"slot\") {\n if (value.length > 0) {\n visitor(node, currentPath, value);\n }\n return;\n }\n\n value.forEach((item: any, index: number) => {\n if (node.children.length > 0) {\n const itemPath = `${currentPath}/${index}`;\n for (const child of node.children) {\n const childValue = item?.[child.name];\n const childPath = `${itemPath}/${child.name}`;\n this.traverseNode(child, childValue, childPath, visitor);\n }\n } else {\n visitor(node, currentPath, item);\n }\n });\n } else {\n if (node.children.length > 0) {\n for (const child of node.children) {\n const childValue = value?.[child.name];\n const childPath = `${currentPath}/${child.name}`;\n this.traverseNode(child, childValue, childPath, visitor);\n }\n } else {\n visitor(node, currentPath, value);\n }\n }\n }\n}\n"],"names":["ComponentInputTraverser","ast","data","visitor","node","rootValue","value","currentPath","item","index","itemPath","child","childValue","childPath"],"mappings":"AAWO,MAAMA;IAGT,YAAYC,GAAmB,CAAE;QAC7B,IAAI,CAAC,GAAG,GAAGA;IACf;IAMO,SAASC,IAAyB,EAAEC,OAAqB,EAAQ;QACpE,KAAK,MAAMC,QAAQ,IAAI,CAAC,GAAG,CAAE;YACzB,MAAMC,YAAYH,IAAI,CAACE,KAAK,IAAI,CAAC;YACjC,IAAI,CAAC,YAAY,CAACA,MAAMC,WAAWD,KAAK,IAAI,EAAED;QAClD;IACJ;IAEQ,aACJC,IAAkB,EAClBE,KAAU,EACVC,WAAmB,EACnBJ,OAAqB,EACjB;QACJ,IAAIC,KAAK,IAAI,EAAE;YACXE,QAAQA,SAAS,EAAE;YAEnB,IAAIA,AAAiB,MAAjBA,MAAM,MAAM,EACZH,QAAQC,MAAMG,aAAaD;YAM/B,IAAIF,AAAyB,MAAzBA,KAAK,QAAQ,CAAC,MAAM,IAAUA,AAAc,WAAdA,KAAK,IAAI,EAAa;gBACpD,IAAIE,MAAM,MAAM,GAAG,GACfH,QAAQC,MAAMG,aAAaD;gBAE/B;YACJ;YAEAA,MAAM,OAAO,CAAC,CAACE,MAAWC;gBACtB,IAAIL,KAAK,QAAQ,CAAC,MAAM,GAAG,GAAG;oBAC1B,MAAMM,WAAW,GAAGH,YAAY,CAAC,EAAEE,OAAO;oBAC1C,KAAK,MAAME,SAASP,KAAK,QAAQ,CAAE;wBAC/B,MAAMQ,aAAaJ,MAAM,CAACG,MAAM,IAAI,CAAC;wBACrC,MAAME,YAAY,GAAGH,SAAS,CAAC,EAAEC,MAAM,IAAI,EAAE;wBAC7C,IAAI,CAAC,YAAY,CAACA,OAAOC,YAAYC,WAAWV;oBACpD;gBACJ,OACIA,QAAQC,MAAMG,aAAaC;YAEnC;QACJ,OACI,IAAIJ,KAAK,QAAQ,CAAC,MAAM,GAAG,GACvB,KAAK,MAAMO,SAASP,KAAK,QAAQ,CAAE;YAC/B,MAAMQ,aAAaN,OAAO,CAACK,MAAM,IAAI,CAAC;YACtC,MAAME,YAAY,GAAGN,YAAY,CAAC,EAAEI,MAAM,IAAI,EAAE;YAChD,IAAI,CAAC,YAAY,CAACA,OAAOC,YAAYC,WAAWV;QACpD;aAEAA,QAAQC,MAAMG,aAAaD;IAGvC;AACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComponentInput } from "./types.js";
|
|
2
|
+
export type InputAstNode = {
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
list: boolean;
|
|
6
|
+
path: string;
|
|
7
|
+
children: InputAstNode[];
|
|
8
|
+
input: ComponentInput;
|
|
9
|
+
};
|
|
10
|
+
export declare class ComponentManifestToAstConverter {
|
|
11
|
+
static convert(inputs: ComponentInput[]): InputAstNode[];
|
|
12
|
+
private static buildAst;
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class ComponentManifestToAstConverter {
|
|
2
|
+
static convert(inputs) {
|
|
3
|
+
return this.buildAst(inputs);
|
|
4
|
+
}
|
|
5
|
+
static buildAst(inputs, basePath = "") {
|
|
6
|
+
return inputs.map((input)=>{
|
|
7
|
+
const path = basePath ? `${basePath}/${input.name}` : input.name;
|
|
8
|
+
const node = {
|
|
9
|
+
name: input.name,
|
|
10
|
+
type: input.type,
|
|
11
|
+
list: input.list || false,
|
|
12
|
+
path,
|
|
13
|
+
children: [],
|
|
14
|
+
input
|
|
15
|
+
};
|
|
16
|
+
if ("object" === input.type && input.fields) node.children = this.buildAst(input.fields, path);
|
|
17
|
+
return node;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export { ComponentManifestToAstConverter };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=ComponentManifestToAstConverter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComponentManifestToAstConverter.js","sources":["../src/ComponentManifestToAstConverter.ts"],"sourcesContent":["import type { ComponentInput } from \"./types.js\";\n\nexport type InputAstNode = {\n name: string;\n type: string;\n list: boolean;\n path: string;\n children: InputAstNode[];\n input: ComponentInput;\n};\n\nexport class ComponentManifestToAstConverter {\n static convert(inputs: ComponentInput[]): InputAstNode[] {\n return this.buildAst(inputs);\n }\n\n private static buildAst(inputs: ComponentInput[], basePath = \"\"): InputAstNode[] {\n return inputs.map(input => {\n const path = basePath ? `${basePath}/${input.name}` : input.name;\n const node: InputAstNode = {\n name: input.name,\n type: input.type,\n list: input.list || false,\n path,\n children: [],\n input\n };\n\n if (input.type === \"object\" && input.fields) {\n node.children = this.buildAst(input.fields, path);\n }\n\n return node;\n });\n }\n}\n"],"names":["ComponentManifestToAstConverter","inputs","basePath","input","path","node"],"mappings":"AAWO,MAAMA;IACT,OAAO,QAAQC,MAAwB,EAAkB;QACrD,OAAO,IAAI,CAAC,QAAQ,CAACA;IACzB;IAEA,OAAe,SAASA,MAAwB,EAAEC,WAAW,EAAE,EAAkB;QAC7E,OAAOD,OAAO,GAAG,CAACE,CAAAA;YACd,MAAMC,OAAOF,WAAW,GAAGA,SAAS,CAAC,EAAEC,MAAM,IAAI,EAAE,GAAGA,MAAM,IAAI;YAChE,MAAME,OAAqB;gBACvB,MAAMF,MAAM,IAAI;gBAChB,MAAMA,MAAM,IAAI;gBAChB,MAAMA,MAAM,IAAI,IAAI;gBACpBC;gBACA,UAAU,EAAE;gBACZD;YACJ;YAEA,IAAIA,AAAe,aAAfA,MAAM,IAAI,IAAiBA,MAAM,MAAM,EACvCE,KAAK,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAACF,MAAM,MAAM,EAAEC;YAGhD,OAAOC;QACX;IACJ;AACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Component, ComponentManifest } from "./types.js";
|
|
2
|
+
type Registration = {
|
|
3
|
+
name: string;
|
|
4
|
+
component: Component;
|
|
5
|
+
};
|
|
6
|
+
export declare class ComponentRegistry {
|
|
7
|
+
private registry;
|
|
8
|
+
private listeners;
|
|
9
|
+
register(component: Component): void;
|
|
10
|
+
get(name: string): Component | undefined;
|
|
11
|
+
getManifests(): Record<string, ComponentManifest>;
|
|
12
|
+
/** subscribe to *all* registrations */
|
|
13
|
+
onRegister(fn: (reg: Registration) => void): () => boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const componentRegistry: ComponentRegistry;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { functionConverter } from "./FunctionConverter.js";
|
|
2
|
+
class ComponentRegistry {
|
|
3
|
+
register(component) {
|
|
4
|
+
const name = component.manifest.name;
|
|
5
|
+
component.manifest.tags = component.manifest.tags ?? [];
|
|
6
|
+
if (component.manifest.constraints) component.manifest.constraints = component.manifest.constraints.map((fn)=>functionConverter.serialize(fn));
|
|
7
|
+
if (component.manifest.descendantConstraints) component.manifest.descendantConstraints = component.manifest.descendantConstraints.map((fn)=>functionConverter.serialize(fn));
|
|
8
|
+
if (component.manifest.canDelete && "function" == typeof component.manifest.canDelete) component.manifest.canDelete = functionConverter.serialize(component.manifest.canDelete);
|
|
9
|
+
if (component.manifest.onChange) component.manifest.onChange = serializeHandlers(component.manifest.onChange);
|
|
10
|
+
if (component.manifest.onDescendantChange) component.manifest.onDescendantChange = serializeHandlers(component.manifest.onDescendantChange);
|
|
11
|
+
this.registry.set(name, component);
|
|
12
|
+
this.listeners.forEach((fn)=>fn({
|
|
13
|
+
name,
|
|
14
|
+
component
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
get(name) {
|
|
18
|
+
return this.registry.get(name);
|
|
19
|
+
}
|
|
20
|
+
getManifests() {
|
|
21
|
+
const manifests = {};
|
|
22
|
+
this.registry.forEach((component, name)=>{
|
|
23
|
+
manifests[name] = component.manifest;
|
|
24
|
+
});
|
|
25
|
+
return manifests;
|
|
26
|
+
}
|
|
27
|
+
onRegister(fn) {
|
|
28
|
+
this.listeners.add(fn);
|
|
29
|
+
return ()=>this.listeners.delete(fn);
|
|
30
|
+
}
|
|
31
|
+
constructor(){
|
|
32
|
+
this.registry = new Map();
|
|
33
|
+
this.listeners = new Set();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function serializeHandlers(handler) {
|
|
37
|
+
if (Array.isArray(handler)) return handler.map((h)=>functionConverter.serialize(h));
|
|
38
|
+
return functionConverter.serialize(handler);
|
|
39
|
+
}
|
|
40
|
+
const componentRegistry = new ComponentRegistry();
|
|
41
|
+
export { ComponentRegistry, componentRegistry };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=ComponentRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComponentRegistry.js","sources":["../src/ComponentRegistry.ts"],"sourcesContent":["import type { Component, ComponentManifest } from \"~/types.js\";\nimport { functionConverter } from \"~/FunctionConverter.js\";\n\ntype Registration = { name: string; component: Component };\n\nexport class ComponentRegistry {\n private registry = new Map<string, Component>();\n private listeners = new Set<(reg: Registration) => void>();\n\n public register(component: Component) {\n const name = component.manifest.name;\n // Normalize optional fields so downstream code never sees undefined.\n component.manifest.tags = component.manifest.tags ?? [];\n // Serialize constraint and handler functions for cross-boundary transport\n if (component.manifest.constraints) {\n // @ts-expect-error Serialized form is string[], but type expects function[].\n component.manifest.constraints = component.manifest.constraints.map(fn =>\n functionConverter.serialize(fn)\n );\n }\n if (component.manifest.descendantConstraints) {\n // @ts-expect-error Serialized form is string[], but type expects function[].\n component.manifest.descendantConstraints = component.manifest.descendantConstraints.map(\n fn => functionConverter.serialize(fn)\n );\n }\n if (component.manifest.canDelete && typeof component.manifest.canDelete === \"function\") {\n // @ts-expect-error Serialized form is a string, but type expects a function.\n component.manifest.canDelete = functionConverter.serialize(\n component.manifest.canDelete\n );\n }\n if (component.manifest.onChange) {\n // @ts-expect-error Serialized form is a string (or string[]), but type expects a function.\n component.manifest.onChange = serializeHandlers(component.manifest.onChange);\n }\n if (component.manifest.onDescendantChange) {\n // @ts-expect-error Serialized form is a string (or string[]), but type expects a function.\n component.manifest.onDescendantChange = serializeHandlers(\n component.manifest.onDescendantChange\n );\n }\n this.registry.set(name, component);\n // notify subscribers\n this.listeners.forEach(fn => fn({ name, component }));\n }\n\n public get(name: string) {\n return this.registry.get(name);\n }\n\n public getManifests(): Record<string, ComponentManifest> {\n const manifests: Record<string, ComponentManifest> = {};\n this.registry.forEach((component, name) => {\n manifests[name] = component.manifest;\n });\n return manifests;\n }\n\n /** subscribe to *all* registrations */\n public onRegister(fn: (reg: Registration) => void) {\n this.listeners.add(fn);\n return () => this.listeners.delete(fn);\n }\n}\n\nfunction serializeHandlers(\n handler: ((...args: any[]) => any) | ((...args: any[]) => any)[]\n): string | string[] {\n if (Array.isArray(handler)) {\n return handler.map(h => functionConverter.serialize(h));\n }\n return functionConverter.serialize(handler);\n}\n\nexport const componentRegistry = new ComponentRegistry();\n"],"names":["ComponentRegistry","component","name","fn","functionConverter","serializeHandlers","manifests","Map","Set","handler","Array","h","componentRegistry"],"mappings":";AAKO,MAAMA;IAIF,SAASC,SAAoB,EAAE;QAClC,MAAMC,OAAOD,UAAU,QAAQ,CAAC,IAAI;QAEpCA,UAAU,QAAQ,CAAC,IAAI,GAAGA,UAAU,QAAQ,CAAC,IAAI,IAAI,EAAE;QAEvD,IAAIA,UAAU,QAAQ,CAAC,WAAW,EAE9BA,UAAU,QAAQ,CAAC,WAAW,GAAGA,UAAU,QAAQ,CAAC,WAAW,CAAC,GAAG,CAACE,CAAAA,KAChEC,kBAAkB,SAAS,CAACD;QAGpC,IAAIF,UAAU,QAAQ,CAAC,qBAAqB,EAExCA,UAAU,QAAQ,CAAC,qBAAqB,GAAGA,UAAU,QAAQ,CAAC,qBAAqB,CAAC,GAAG,CACnFE,CAAAA,KAAMC,kBAAkB,SAAS,CAACD;QAG1C,IAAIF,UAAU,QAAQ,CAAC,SAAS,IAAI,AAAwC,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
import type { DocumentCache, DocumentElement, DocumentElementBindings, DocumentState, ResolvedComponent } from "./types.js";
|
|
3
|
+
import type { OnResolved } from "./BindingsResolver.js";
|
|
4
|
+
import type { ContentEntryCache } from "./contentEntry/ContentEntryCache.js";
|
|
5
|
+
export type ResolveElementParams = {
|
|
6
|
+
element: DocumentElement;
|
|
7
|
+
elementBindings: DocumentElementBindings;
|
|
8
|
+
state: DocumentState;
|
|
9
|
+
cache?: DocumentCache;
|
|
10
|
+
onResolved?: OnResolved;
|
|
11
|
+
};
|
|
12
|
+
export declare class ComponentResolver {
|
|
13
|
+
private components;
|
|
14
|
+
private contentEntryCache;
|
|
15
|
+
constructor(registry: ComponentRegistry, cache?: ContentEntryCache);
|
|
16
|
+
resolve({ element, elementBindings, onResolved, state, cache }: ResolveElementParams): ResolvedComponent[] | null;
|
|
17
|
+
}
|