@makeswift/runtime 0.27.1-canary.0 → 0.27.2
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/dist/cjs/api/react.js +256 -0
- package/dist/cjs/api/react.js.map +1 -0
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/builder/serialization/control-serialization.js +10 -7
- package/dist/cjs/builder/serialization/control-serialization.js.map +1 -1
- package/dist/cjs/client/index.js +35 -6
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/controls/visitors/message-port-serializer/function-serialization.js.map +1 -1
- package/dist/cjs/next/api-handler/config/app-router.js +10 -1
- package/dist/cjs/next/api-handler/config/app-router.js.map +1 -1
- package/dist/cjs/runtimes/react/components/GoogleFontLink.js +56 -0
- package/dist/cjs/runtimes/react/components/GoogleFontLink.js.map +1 -0
- package/dist/cjs/runtimes/react/components/LiveProvider.js +50 -0
- package/dist/cjs/runtimes/react/components/LiveProvider.js.map +1 -0
- package/dist/cjs/runtimes/react/components/PreviewProvider.js +63 -0
- package/dist/cjs/runtimes/react/components/PreviewProvider.js.map +1 -0
- package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js +62 -0
- package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-is-preview.js +33 -0
- package/dist/cjs/runtimes/react/hooks/use-is-preview.js.map +1 -0
- package/dist/cjs/runtimes/react/utils/google-fonts-url.js +49 -0
- package/dist/cjs/runtimes/react/utils/google-fonts-url.js.map +1 -0
- package/dist/cjs/state/actions/internal.js +205 -0
- package/dist/cjs/state/actions/internal.js.map +1 -0
- package/dist/cjs/state/builder-api/message-channel.js +33 -28
- package/dist/cjs/state/builder-api/message-channel.js.map +1 -1
- package/dist/cjs/state/builder-api/proxy.js +11 -9
- package/dist/cjs/state/builder-api/proxy.js.map +1 -1
- package/dist/cjs/state/mixins/setup-teardown.js +35 -0
- package/dist/cjs/state/mixins/setup-teardown.js.map +1 -0
- package/dist/cjs/state/modules/box-models.js +127 -0
- package/dist/cjs/state/modules/box-models.js.map +1 -0
- package/dist/cjs/state/modules/element-imperative-handles.js +60 -0
- package/dist/cjs/state/modules/element-imperative-handles.js.map +1 -0
- package/dist/cjs/state/modules/is-preview.js +47 -0
- package/dist/cjs/state/modules/is-preview.js.map +1 -0
- package/dist/cjs/state/modules/pointer.js +47 -0
- package/dist/cjs/state/modules/pointer.js.map +1 -0
- package/dist/cjs/state/modules/read-write-documents.js +98 -0
- package/dist/cjs/state/modules/read-write-documents.js.map +1 -0
- package/dist/cjs/state/react-builder-preview.js +586 -0
- package/dist/cjs/state/react-builder-preview.js.map +1 -0
- package/dist/cjs/state/react-page.js +313 -0
- package/dist/cjs/state/react-page.js.map +1 -0
- package/dist/cjs/state/read-write-state.js +1 -1
- package/dist/cjs/state/read-write-state.js.map +1 -1
- package/dist/cjs/state/store.js +2 -2
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/cjs/state/translations/get.js +10 -9
- package/dist/cjs/state/translations/get.js.map +1 -1
- package/dist/cjs/state/translations/merge.js +10 -12
- package/dist/cjs/state/translations/merge.js.map +1 -1
- package/dist/cjs/translations/index.js +32 -0
- package/dist/cjs/translations/index.js.map +1 -0
- package/dist/cjs/unstable-framework-support/index.js +3 -0
- package/dist/cjs/unstable-framework-support/index.js.map +1 -1
- package/dist/esm/api/react.js +223 -0
- package/dist/esm/api/react.js.map +1 -0
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/builder/serialization/control-serialization.js +12 -8
- package/dist/esm/builder/serialization/control-serialization.js.map +1 -1
- package/dist/esm/client/index.js +37 -8
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/controls/visitors/message-port-serializer/function-serialization.js.map +1 -1
- package/dist/esm/next/api-handler/config/app-router.js +10 -1
- package/dist/esm/next/api-handler/config/app-router.js.map +1 -1
- package/dist/esm/runtimes/react/components/GoogleFontLink.js +36 -0
- package/dist/esm/runtimes/react/components/GoogleFontLink.js.map +1 -0
- package/dist/esm/runtimes/react/components/LiveProvider.js +20 -0
- package/dist/esm/runtimes/react/components/LiveProvider.js.map +1 -0
- package/dist/esm/runtimes/react/components/PreviewProvider.js +33 -0
- package/dist/esm/runtimes/react/components/PreviewProvider.js.map +1 -0
- package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js +38 -0
- package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-is-preview.js +9 -0
- package/dist/esm/runtimes/react/hooks/use-is-preview.js.map +1 -0
- package/dist/esm/runtimes/react/utils/google-fonts-url.js +23 -0
- package/dist/esm/runtimes/react/utils/google-fonts-url.js.map +1 -0
- package/dist/esm/state/actions/internal.js +162 -0
- package/dist/esm/state/actions/internal.js.map +1 -0
- package/dist/esm/state/builder-api/message-channel.js +33 -28
- package/dist/esm/state/builder-api/message-channel.js.map +1 -1
- package/dist/esm/state/builder-api/proxy.js +11 -9
- package/dist/esm/state/builder-api/proxy.js.map +1 -1
- package/dist/esm/state/mixins/setup-teardown.js +11 -0
- package/dist/esm/state/mixins/setup-teardown.js.map +1 -0
- package/dist/esm/state/modules/box-models.js +98 -0
- package/dist/esm/state/modules/box-models.js.map +1 -0
- package/dist/esm/state/modules/element-imperative-handles.js +35 -0
- package/dist/esm/state/modules/element-imperative-handles.js.map +1 -0
- package/dist/esm/state/modules/is-preview.js +21 -0
- package/dist/esm/state/modules/is-preview.js.map +1 -0
- package/dist/esm/state/modules/pointer.js +22 -0
- package/dist/esm/state/modules/pointer.js.map +1 -0
- package/dist/esm/state/modules/read-write-documents.js +60 -0
- package/dist/esm/state/modules/read-write-documents.js.map +1 -0
- package/dist/esm/state/react-builder-preview.js +547 -0
- package/dist/esm/state/react-builder-preview.js.map +1 -0
- package/dist/esm/state/react-page.js +268 -0
- package/dist/esm/state/react-page.js.map +1 -0
- package/dist/esm/state/read-write-state.js +1 -1
- package/dist/esm/state/read-write-state.js.map +1 -1
- package/dist/esm/state/store.js +2 -2
- package/dist/esm/state/store.js.map +1 -1
- package/dist/esm/state/translations/get.js +9 -8
- package/dist/esm/state/translations/get.js.map +1 -1
- package/dist/esm/state/translations/merge.js +9 -11
- package/dist/esm/state/translations/merge.js.map +1 -1
- package/dist/esm/translations/index.js +7 -0
- package/dist/esm/translations/index.js.map +1 -0
- package/dist/esm/unstable-framework-support/index.js +2 -0
- package/dist/esm/unstable-framework-support/index.js.map +1 -1
- package/dist/types/api/react.d.ts +82 -0
- package/dist/types/api/react.d.ts.map +1 -0
- package/dist/types/builder/serialization/control-serialization.d.ts +10 -6
- package/dist/types/builder/serialization/control-serialization.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +25 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/tests/client.get-fonts.test.d.ts +2 -0
- package/dist/types/client/tests/client.get-fonts.test.d.ts.map +1 -0
- package/dist/types/next/api-handler/config/app-router.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/GoogleFontLink.d.ts +14 -0
- package/dist/types/runtimes/react/components/GoogleFontLink.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/LiveProvider.d.ts +3 -0
- package/dist/types/runtimes/react/components/LiveProvider.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/PreviewProvider.d.ts +5 -0
- package/dist/types/runtimes/react/components/PreviewProvider.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts +4 -0
- package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-is-preview.d.ts +2 -0
- package/dist/types/runtimes/react/hooks/use-is-preview.d.ts.map +1 -0
- package/dist/types/runtimes/react/utils/google-fonts-url.d.ts +6 -0
- package/dist/types/runtimes/react/utils/google-fonts-url.d.ts.map +1 -0
- package/dist/types/state/__tests__/fixtures/serialized-descriptors-from-builder.d.ts +5 -0
- package/dist/types/state/__tests__/fixtures/serialized-descriptors-from-builder.d.ts.map +1 -0
- package/dist/types/state/__tests__/fixtures/translatable-content-sample.d.ts +3 -0
- package/dist/types/state/__tests__/fixtures/translatable-content-sample.d.ts.map +1 -0
- package/dist/types/state/__tests__/get-translatable-content.test.d.ts +2 -0
- package/dist/types/state/__tests__/get-translatable-content.test.d.ts.map +1 -0
- package/dist/types/state/__tests__/react-page.test.d.ts +2 -0
- package/dist/types/state/__tests__/react-page.test.d.ts.map +1 -0
- package/dist/types/state/actions/internal.d.ts +181 -0
- package/dist/types/state/actions/internal.d.ts.map +1 -0
- package/dist/types/state/builder-api/message-channel.d.ts +3 -6
- package/dist/types/state/builder-api/message-channel.d.ts.map +1 -1
- package/dist/types/state/builder-api/proxy.d.ts +1 -2
- package/dist/types/state/builder-api/proxy.d.ts.map +1 -1
- package/dist/types/state/mixins/setup-teardown.d.ts +7 -0
- package/dist/types/state/mixins/setup-teardown.d.ts.map +1 -0
- package/dist/types/state/modules/box-models.d.ts +23 -0
- package/dist/types/state/modules/box-models.d.ts.map +1 -0
- package/dist/types/state/modules/element-imperative-handles.d.ts +7 -0
- package/dist/types/state/modules/element-imperative-handles.d.ts.map +1 -0
- package/dist/types/state/modules/is-preview.d.ts +6 -0
- package/dist/types/state/modules/is-preview.d.ts.map +1 -0
- package/dist/types/state/modules/pointer.d.ts +12 -0
- package/dist/types/state/modules/pointer.d.ts.map +1 -0
- package/dist/types/state/modules/read-write-documents.d.ts +14 -0
- package/dist/types/state/modules/read-write-documents.d.ts.map +1 -0
- package/dist/types/state/react-builder-preview.d.ts +108 -0
- package/dist/types/state/react-builder-preview.d.ts.map +1 -0
- package/dist/types/state/react-page.d.ts +149 -0
- package/dist/types/state/react-page.d.ts.map +1 -0
- package/dist/types/state/read-write-state.d.ts +1 -1
- package/dist/types/state/read-write-state.d.ts.map +1 -1
- package/dist/types/state/translations/get.d.ts +2 -2
- package/dist/types/state/translations/get.d.ts.map +1 -1
- package/dist/types/state/translations/merge.d.ts +2 -2
- package/dist/types/state/translations/merge.d.ts.map +1 -1
- package/dist/types/translations/index.d.ts +6 -0
- package/dist/types/translations/index.d.ts.map +1 -0
- package/dist/types/unstable-framework-support/index.d.ts +1 -0
- package/dist/types/unstable-framework-support/index.d.ts.map +1 -1
- package/package.json +9 -3
- package/translations/package.json +5 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configureStore as configureReduxStore,
|
|
3
|
+
combineReducers
|
|
4
|
+
} from "@reduxjs/toolkit";
|
|
5
|
+
import { createSelector } from "reselect";
|
|
6
|
+
import {
|
|
7
|
+
createReplacementContext,
|
|
8
|
+
replaceResourceIfNeeded,
|
|
9
|
+
ContextResource
|
|
10
|
+
} from "@makeswift/controls";
|
|
11
|
+
import { copy as copyFromControl, merge } from "../controls/control";
|
|
12
|
+
import * as Documents from "./modules/read-only-documents";
|
|
13
|
+
import * as ElementTrees from "./modules/element-trees";
|
|
14
|
+
import * as ReactComponents from "./modules/react-components";
|
|
15
|
+
import * as ComponentsMeta from "./modules/components-meta";
|
|
16
|
+
import * as PropControllers from "./modules/prop-controllers";
|
|
17
|
+
import * as PropControllerHandles from "./modules/prop-controller-handles";
|
|
18
|
+
import * as IsInBuilder from "./modules/is-in-builder";
|
|
19
|
+
import * as IsPreview from "./modules/is-preview";
|
|
20
|
+
import * as BuilderEditMode from "./modules/builder-edit-mode";
|
|
21
|
+
import * as Breakpoints from "./modules/breakpoints";
|
|
22
|
+
import { ActionTypes } from "./actions";
|
|
23
|
+
import { changeElementTree, createElementTree, deleteElementTree } from "./actions/internal";
|
|
24
|
+
import { actionMiddleware, middlewareOptions, devToolsConfig } from "./toolkit";
|
|
25
|
+
import { withSetupTeardown } from "./mixins/setup-teardown";
|
|
26
|
+
import {
|
|
27
|
+
createBaseDocument,
|
|
28
|
+
createDocumentReference,
|
|
29
|
+
getRootElement,
|
|
30
|
+
isElementReference
|
|
31
|
+
} from "./modules/read-only-documents";
|
|
32
|
+
const reducer = combineReducers({
|
|
33
|
+
documents: Documents.reducer,
|
|
34
|
+
elementTrees: ElementTrees.reducer,
|
|
35
|
+
reactComponents: ReactComponents.reducer,
|
|
36
|
+
componentsMeta: ComponentsMeta.reducer,
|
|
37
|
+
propControllers: PropControllers.reducer,
|
|
38
|
+
propControllerHandles: PropControllerHandles.reducer,
|
|
39
|
+
isInBuilder: IsInBuilder.reducer,
|
|
40
|
+
isPreview: IsPreview.reducer,
|
|
41
|
+
builderEditMode: BuilderEditMode.reducer,
|
|
42
|
+
breakpoints: Breakpoints.reducer
|
|
43
|
+
});
|
|
44
|
+
function getDocumentsStateSlice(state) {
|
|
45
|
+
return state.documents;
|
|
46
|
+
}
|
|
47
|
+
function getDocument(state, documentKey) {
|
|
48
|
+
return Documents.getDocument(getDocumentsStateSlice(state), documentKey);
|
|
49
|
+
}
|
|
50
|
+
function getElementTreesSlice(state) {
|
|
51
|
+
return state.elementTrees;
|
|
52
|
+
}
|
|
53
|
+
function getElements(state, documentKey) {
|
|
54
|
+
return ElementTrees.getElements(getElementTreesSlice(state), documentKey);
|
|
55
|
+
}
|
|
56
|
+
function getElementIds(state, documentKey) {
|
|
57
|
+
return ElementTrees.getElementIds(getElementTreesSlice(state), documentKey);
|
|
58
|
+
}
|
|
59
|
+
function getReactComponentsStateSlice(state) {
|
|
60
|
+
return state.reactComponents;
|
|
61
|
+
}
|
|
62
|
+
function getReactComponent(state, type) {
|
|
63
|
+
return ReactComponents.getReactComponent(getReactComponentsStateSlice(state), type);
|
|
64
|
+
}
|
|
65
|
+
function getComponentsMetaStateSlice(state) {
|
|
66
|
+
return state.componentsMeta;
|
|
67
|
+
}
|
|
68
|
+
function getComponentMeta(state, type) {
|
|
69
|
+
return ComponentsMeta.getComponentMeta(getComponentsMetaStateSlice(state), type);
|
|
70
|
+
}
|
|
71
|
+
function getPropControllersStateSlice(state) {
|
|
72
|
+
return state.propControllers;
|
|
73
|
+
}
|
|
74
|
+
function getPropControllerDescriptors(state) {
|
|
75
|
+
return PropControllers.getPropControllerDescriptors(getPropControllersStateSlice(state));
|
|
76
|
+
}
|
|
77
|
+
function getComponentPropControllerDescriptors(state, componentType) {
|
|
78
|
+
return PropControllers.getComponentPropControllerDescriptors(
|
|
79
|
+
getPropControllersStateSlice(state),
|
|
80
|
+
componentType
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
function getPropControllerHandlesStateSlice(state) {
|
|
84
|
+
return state.propControllerHandles;
|
|
85
|
+
}
|
|
86
|
+
function getPropControllers(state, documentKey, elementKey) {
|
|
87
|
+
return PropControllerHandles.getPropControllers(
|
|
88
|
+
getPropControllerHandlesStateSlice(state),
|
|
89
|
+
documentKey,
|
|
90
|
+
elementKey
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const getDocumentKeysSortedByDepth = createSelector(
|
|
94
|
+
[getDocumentsStateSlice, getElementTreesSlice],
|
|
95
|
+
(documents, elementTrees) => {
|
|
96
|
+
return [...documents.keys()].sort((a, b) => elementTrees.get(a)?.elements.has(b) ? -1 : 1);
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
function getElement(state, documentKey, elementKey) {
|
|
100
|
+
return ElementTrees.getElement(getElementTreesSlice(state), documentKey, elementKey);
|
|
101
|
+
}
|
|
102
|
+
function getElementId(state, documentKey, elementKey) {
|
|
103
|
+
return ElementTrees.getElementId(getElementTreesSlice(state), documentKey, elementKey);
|
|
104
|
+
}
|
|
105
|
+
function getElementPropControllerDescriptors(state, documentKey, elementKey) {
|
|
106
|
+
const element = getElement(state, documentKey, elementKey);
|
|
107
|
+
if (element == null || Documents.isElementReference(element))
|
|
108
|
+
return null;
|
|
109
|
+
return getComponentPropControllerDescriptors(state, element.type);
|
|
110
|
+
}
|
|
111
|
+
function copyElementTree(state, elementTree, replacementContext) {
|
|
112
|
+
function copyElementTreeNode(state2, replacementContext2) {
|
|
113
|
+
return function(node) {
|
|
114
|
+
const context = {
|
|
115
|
+
replacementContext: replacementContext2,
|
|
116
|
+
copyElement: copyElementTreeNode(state2, replacementContext2)
|
|
117
|
+
};
|
|
118
|
+
if (Documents.isElementReference(node)) {
|
|
119
|
+
return {
|
|
120
|
+
...node,
|
|
121
|
+
value: replaceResourceIfNeeded(ContextResource.GlobalElement, node.value, context)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const descriptors = getComponentPropControllerDescriptors(state2, node.type);
|
|
125
|
+
if (descriptors == null)
|
|
126
|
+
return node;
|
|
127
|
+
for (const [propKey, descriptor] of Object.entries(descriptors)) {
|
|
128
|
+
node.props[propKey] = copyFromControl(descriptor, node.props[propKey], context);
|
|
129
|
+
}
|
|
130
|
+
return node;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const copy = JSON.parse(JSON.stringify(elementTree));
|
|
134
|
+
return copyElementTreeNode(state, createReplacementContext(replacementContext))(copy);
|
|
135
|
+
}
|
|
136
|
+
function mergeElement(state, baseElement, overrideElement) {
|
|
137
|
+
if (baseElement.type !== overrideElement.type || baseElement.key !== overrideElement.key) {
|
|
138
|
+
throw new Error(`Can't merge elements of different types or keys`);
|
|
139
|
+
}
|
|
140
|
+
if (Documents.isElementReference(overrideElement))
|
|
141
|
+
return overrideElement;
|
|
142
|
+
if (Documents.isElementReference(baseElement))
|
|
143
|
+
return baseElement;
|
|
144
|
+
const elementDescriptors = getPropControllerDescriptors(state);
|
|
145
|
+
const descriptors = elementDescriptors.get(baseElement.type);
|
|
146
|
+
if (descriptors == null) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Can't merge element of type "${baseElement.type}" because it has no descriptors`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
const mergedProps = {};
|
|
152
|
+
for (const propName of Object.keys(descriptors)) {
|
|
153
|
+
const descriptor = descriptors[propName];
|
|
154
|
+
const context = {
|
|
155
|
+
mergeElement(base, override) {
|
|
156
|
+
return mergeElement(state, base, override);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
mergedProps[propName] = merge(
|
|
160
|
+
descriptor,
|
|
161
|
+
baseElement.props[propName],
|
|
162
|
+
overrideElement.props[propName],
|
|
163
|
+
context
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return { ...baseElement, props: mergedProps };
|
|
167
|
+
}
|
|
168
|
+
function getIsInBuilder(state) {
|
|
169
|
+
return state.isInBuilder;
|
|
170
|
+
}
|
|
171
|
+
function getIsPreview(state) {
|
|
172
|
+
return IsPreview.getIsPreview(state.isPreview);
|
|
173
|
+
}
|
|
174
|
+
function getBuilderEditMode(state) {
|
|
175
|
+
return state.builderEditMode;
|
|
176
|
+
}
|
|
177
|
+
function getBreakpoints(state) {
|
|
178
|
+
return state.breakpoints;
|
|
179
|
+
}
|
|
180
|
+
function elementTreeMiddleware() {
|
|
181
|
+
return actionMiddleware(({ dispatch, getState }) => (next) => {
|
|
182
|
+
return (action) => {
|
|
183
|
+
switch (action.type) {
|
|
184
|
+
case ActionTypes.REGISTER_DOCUMENT:
|
|
185
|
+
dispatch(
|
|
186
|
+
createElementTree({
|
|
187
|
+
document: action.payload.document,
|
|
188
|
+
descriptors: getPropControllerDescriptors(getState())
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
break;
|
|
192
|
+
case ActionTypes.CHANGE_DOCUMENT: {
|
|
193
|
+
const { documentKey, operation } = action.payload;
|
|
194
|
+
const oldDocument = getDocument(getState(), documentKey);
|
|
195
|
+
const result = next(action);
|
|
196
|
+
const newDocument = getDocument(getState(), documentKey);
|
|
197
|
+
if (oldDocument != null && newDocument != null && newDocument !== oldDocument) {
|
|
198
|
+
dispatch(
|
|
199
|
+
changeElementTree({
|
|
200
|
+
oldDocument,
|
|
201
|
+
newDocument,
|
|
202
|
+
descriptors: getPropControllerDescriptors(getState()),
|
|
203
|
+
operation
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
case ActionTypes.UNREGISTER_DOCUMENT:
|
|
210
|
+
dispatch(deleteElementTree(action.payload));
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
return next(action);
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function configureStore({
|
|
218
|
+
name,
|
|
219
|
+
preloadedState,
|
|
220
|
+
breakpoints
|
|
221
|
+
}) {
|
|
222
|
+
return configureReduxStore({
|
|
223
|
+
reducer,
|
|
224
|
+
preloadedState: {
|
|
225
|
+
...preloadedState,
|
|
226
|
+
breakpoints: Breakpoints.getInitialState(breakpoints ?? preloadedState?.breakpoints)
|
|
227
|
+
},
|
|
228
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareOptions).concat(elementTreeMiddleware()),
|
|
229
|
+
enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat(
|
|
230
|
+
withSetupTeardown(
|
|
231
|
+
() => {
|
|
232
|
+
},
|
|
233
|
+
() => {
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
),
|
|
237
|
+
devTools: devToolsConfig({
|
|
238
|
+
name: `${name} (${(/* @__PURE__ */ new Date()).toISOString()})`
|
|
239
|
+
})
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
export {
|
|
243
|
+
configureStore,
|
|
244
|
+
copyElementTree,
|
|
245
|
+
createBaseDocument,
|
|
246
|
+
createDocumentReference,
|
|
247
|
+
elementTreeMiddleware,
|
|
248
|
+
getBreakpoints,
|
|
249
|
+
getBuilderEditMode,
|
|
250
|
+
getComponentMeta,
|
|
251
|
+
getComponentPropControllerDescriptors,
|
|
252
|
+
getDocument,
|
|
253
|
+
getDocumentKeysSortedByDepth,
|
|
254
|
+
getElement,
|
|
255
|
+
getElementId,
|
|
256
|
+
getElementIds,
|
|
257
|
+
getElementPropControllerDescriptors,
|
|
258
|
+
getElements,
|
|
259
|
+
getIsInBuilder,
|
|
260
|
+
getIsPreview,
|
|
261
|
+
getPropControllerDescriptors,
|
|
262
|
+
getPropControllers,
|
|
263
|
+
getReactComponent,
|
|
264
|
+
getRootElement,
|
|
265
|
+
isElementReference,
|
|
266
|
+
mergeElement
|
|
267
|
+
};
|
|
268
|
+
//# sourceMappingURL=react-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/state/react-page.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkDispatch,\n type Middleware,\n} from '@reduxjs/toolkit'\n\nimport { createSelector } from 'reselect'\n\nimport {\n createReplacementContext,\n type SerializableReplacementContext,\n type ReplacementContext,\n type MergeContext,\n CopyContext,\n replaceResourceIfNeeded,\n ContextResource,\n} from '@makeswift/controls'\n\nimport { copy as copyFromControl, merge } from '../controls/control'\n\nimport * as Documents from './modules/read-only-documents'\nimport * as ElementTrees from './modules/element-trees'\nimport * as ReactComponents from './modules/react-components'\nimport * as ComponentsMeta from './modules/components-meta'\nimport * as PropControllers from './modules/prop-controllers'\nimport * as PropControllerHandles from './modules/prop-controller-handles'\nimport * as IsInBuilder from './modules/is-in-builder'\nimport * as IsPreview from './modules/is-preview'\nimport * as BuilderEditMode from './modules/builder-edit-mode'\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { type Action, ActionTypes } from './actions'\nimport { changeElementTree, createElementTree, deleteElementTree } from './actions/internal'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport { withSetupTeardown } from './mixins/setup-teardown'\n\nexport type {\n Data,\n Document,\n DocumentReference,\n Element,\n ElementData,\n ElementReference,\n} from './modules/read-only-documents'\n\nexport {\n createBaseDocument,\n createDocumentReference,\n getRootElement,\n isElementReference,\n} from './modules/read-only-documents'\n\nexport type { ComponentType } from './modules/react-components'\nexport type { ComponentMeta } from './modules/components-meta'\n\nconst reducer = combineReducers({\n documents: Documents.reducer,\n elementTrees: ElementTrees.reducer,\n reactComponents: ReactComponents.reducer,\n componentsMeta: ComponentsMeta.reducer,\n propControllers: PropControllers.reducer,\n propControllerHandles: PropControllerHandles.reducer,\n isInBuilder: IsInBuilder.reducer,\n isPreview: IsPreview.reducer,\n builderEditMode: BuilderEditMode.reducer,\n breakpoints: Breakpoints.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nfunction getDocumentsStateSlice(state: State): Documents.State {\n return state.documents\n}\n\nexport function getDocument(state: State, documentKey: string): Documents.Document | null {\n return Documents.getDocument(getDocumentsStateSlice(state), documentKey)\n}\n\nfunction getElementTreesSlice(state: State): ElementTrees.State {\n return state.elementTrees\n}\n\nexport function getElements(\n state: State,\n documentKey: string,\n): ElementTrees.ElementTree['elements'] {\n return ElementTrees.getElements(getElementTreesSlice(state), documentKey)\n}\n\nexport function getElementIds(\n state: State,\n documentKey: string,\n): ElementTrees.ElementTree['elementIds'] {\n return ElementTrees.getElementIds(getElementTreesSlice(state), documentKey)\n}\n\nfunction getReactComponentsStateSlice(state: State): ReactComponents.State {\n return state.reactComponents\n}\n\nexport function getReactComponent(\n state: State,\n type: string,\n): ReactComponents.ComponentType | null {\n return ReactComponents.getReactComponent(getReactComponentsStateSlice(state), type)\n}\n\nfunction getComponentsMetaStateSlice(state: State): ComponentsMeta.State {\n return state.componentsMeta\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentsMeta.ComponentMeta | null {\n return ComponentsMeta.getComponentMeta(getComponentsMetaStateSlice(state), type)\n}\n\nfunction getPropControllersStateSlice(state: State): PropControllers.State {\n return state.propControllers\n}\n\nexport function getPropControllerDescriptors(state: State): PropControllers.State {\n return PropControllers.getPropControllerDescriptors(getPropControllersStateSlice(state))\n}\n\nexport function getComponentPropControllerDescriptors(\n state: State,\n componentType: string,\n): PropControllers.DescriptorsByProp | null {\n return PropControllers.getComponentPropControllerDescriptors(\n getPropControllersStateSlice(state),\n componentType,\n )\n}\n\nfunction getPropControllerHandlesStateSlice(state: State): PropControllerHandles.State {\n return state.propControllerHandles\n}\n\nexport function getPropControllers(state: State, documentKey: string, elementKey: string) {\n return PropControllerHandles.getPropControllers(\n getPropControllerHandlesStateSlice(state),\n documentKey,\n elementKey,\n )\n}\n\n/**\n * Returns all document keys sorted by depth, i.e., parent documents come before child documents.\n */\nexport const getDocumentKeysSortedByDepth: (state: State) => string[] = createSelector(\n [getDocumentsStateSlice, getElementTreesSlice],\n (documents, elementTrees) => {\n return [...documents.keys()].sort((a, b) => (elementTrees.get(a)?.elements.has(b) ? -1 : 1))\n },\n)\n\nexport function getElement(\n state: State,\n documentKey: string,\n elementKey: string,\n): Documents.Element | null {\n return ElementTrees.getElement(getElementTreesSlice(state), documentKey, elementKey)\n}\n\nexport function getElementId(state: State, documentKey: string, elementKey: string): string | null {\n return ElementTrees.getElementId(getElementTreesSlice(state), documentKey, elementKey)\n}\n\nexport function getElementPropControllerDescriptors(\n state: State,\n documentKey: string,\n elementKey: string,\n): Record<string, PropControllers.PropControllerDescriptor> | null {\n const element = getElement(state, documentKey, elementKey)\n\n if (element == null || Documents.isElementReference(element)) return null\n\n return getComponentPropControllerDescriptors(state, element.type)\n}\n\nexport function copyElementTree(\n state: State,\n elementTree: Documents.ElementData,\n replacementContext: SerializableReplacementContext,\n) {\n /*\n * This is structured a bit weird.\n *\n * This is done so that we can pass a callable function into some of the copy functions\n * themselves, to enable mutual recursion.\n *\n * Consider the slot control. It has to iterate through its elements, and for each of them,\n * call some version of the below function.\n *\n * That is how the recursing through the tree happens.\n */\n function copyElementTreeNode(state: State, replacementContext: ReplacementContext) {\n return function (node: Documents.Element) {\n const context: CopyContext = {\n replacementContext,\n copyElement: copyElementTreeNode(state, replacementContext),\n }\n\n if (Documents.isElementReference(node)) {\n return {\n ...node,\n value: replaceResourceIfNeeded(ContextResource.GlobalElement, node.value, context),\n }\n }\n\n const descriptors = getComponentPropControllerDescriptors(state, node.type)\n\n if (descriptors == null) return node\n\n for (const [propKey, descriptor] of Object.entries(descriptors)) {\n node.props[propKey] = copyFromControl(descriptor, node.props[propKey], context)\n }\n\n return node\n }\n }\n\n const copy = JSON.parse(JSON.stringify(elementTree)) as Documents.ElementData\n\n return copyElementTreeNode(state, createReplacementContext(replacementContext))(copy)\n}\n\nexport function mergeElement(\n state: State,\n baseElement: Documents.Element,\n overrideElement: Documents.Element,\n): Documents.Element {\n if (baseElement.type !== overrideElement.type || baseElement.key !== overrideElement.key) {\n throw new Error(`Can't merge elements of different types or keys`)\n }\n\n if (Documents.isElementReference(overrideElement)) return overrideElement\n\n if (Documents.isElementReference(baseElement)) return baseElement\n\n const elementDescriptors = getPropControllerDescriptors(state)\n const descriptors = elementDescriptors.get(baseElement.type)\n\n if (descriptors == null) {\n throw new Error(\n `Can't merge element of type \"${baseElement.type}\" because it has no descriptors`,\n )\n }\n\n const mergedProps = {} as Record<string, Documents.Data>\n\n for (const propName of Object.keys(descriptors)) {\n const descriptor = descriptors[propName]\n const context: MergeContext = {\n mergeElement(base, override) {\n return mergeElement(state, base, override)\n },\n }\n\n mergedProps[propName] = merge(\n descriptor,\n baseElement.props[propName],\n overrideElement.props[propName],\n context,\n )\n }\n\n return { ...baseElement, props: mergedProps }\n}\n\nexport function getIsInBuilder(state: State): boolean {\n return state.isInBuilder\n}\n\nexport function getIsPreview(state: State): boolean {\n return IsPreview.getIsPreview(state.isPreview)\n}\n\nexport function getBuilderEditMode(state: State): BuilderEditMode.State {\n return state.builderEditMode\n}\n\nexport function getBreakpoints(state: State): Breakpoints.State {\n return state.breakpoints\n}\n\nexport function elementTreeMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(({ dispatch, getState }) => next => {\n return action => {\n switch (action.type) {\n case ActionTypes.REGISTER_DOCUMENT:\n dispatch(\n createElementTree({\n document: action.payload.document,\n descriptors: getPropControllerDescriptors(getState()),\n }),\n )\n break\n\n case ActionTypes.CHANGE_DOCUMENT: {\n const { documentKey, operation } = action.payload\n\n const oldDocument = getDocument(getState(), documentKey)\n const result = next(action)\n const newDocument = getDocument(getState(), documentKey)\n\n if (oldDocument != null && newDocument != null && newDocument !== oldDocument) {\n dispatch(\n changeElementTree({\n oldDocument,\n newDocument,\n descriptors: getPropControllerDescriptors(getState()),\n operation,\n }),\n )\n }\n\n return result\n }\n\n case ActionTypes.UNREGISTER_DOCUMENT:\n dispatch(deleteElementTree(action.payload))\n break\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({\n name,\n preloadedState,\n breakpoints,\n}: {\n name: string\n preloadedState: Partial<State> | null\n breakpoints?: Breakpoints.State\n}) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n ...preloadedState,\n breakpoints: Breakpoints.getInitialState(breakpoints ?? preloadedState?.breakpoints),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(elementTreeMiddleware()),\n\n enhancers: getDefaultEnhancers =>\n getDefaultEnhancers().concat(\n withSetupTeardown(\n () => {},\n () => {},\n ),\n ),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,OAGK;AAEP,SAAS,sBAAsB;AAE/B;AAAA,EACE;AAAA,EAKA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,QAAQ,iBAAiB,aAAa;AAE/C,YAAY,eAAe;AAC3B,YAAY,kBAAkB;AAC9B,YAAY,qBAAqB;AACjC,YAAY,oBAAoB;AAChC,YAAY,qBAAqB;AACjC,YAAY,2BAA2B;AACvC,YAAY,iBAAiB;AAC7B,YAAY,eAAe;AAC3B,YAAY,qBAAqB;AACjC,YAAY,iBAAiB;AAE7B,SAAsB,mBAAmB;AACzC,SAAS,mBAAmB,mBAAmB,yBAAyB;AAExE,SAAS,kBAAkB,mBAAmB,sBAAsB;AAEpE,SAAS,yBAAyB;AAWlC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKP,MAAM,UAAU,gBAAgB;AAAA,EAC9B,WAAW,UAAU;AAAA,EACrB,cAAc,aAAa;AAAA,EAC3B,iB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AI,MAAK,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,IAC5C,CAAC;AAAA,EACH,CAAC;AACH;","names":["state","replacementContext"]}
|
|
@@ -61,7 +61,7 @@ function getElementImperativeHandlesContainingElement(state, element) {
|
|
|
61
61
|
}
|
|
62
62
|
function setupBuilderProxy(builderProxy) {
|
|
63
63
|
return (dispatch) => {
|
|
64
|
-
builderProxy.setup({ onHostAction: (action) => dispatch(action) });
|
|
64
|
+
return builderProxy.setup({ onHostAction: (action) => dispatch(action) });
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/read-write-state.ts"],"sourcesContent":["import { combineReducers, type ThunkAction, type ThunkDispatch } from '@reduxjs/toolkit'\n\nimport * as Documents from './modules/read-write/read-write-documents'\nimport * as BoxModels from './modules/read-write/box-models'\nimport * as Pointer from './modules/read-write/pointer'\nimport * as ElementImperativeHandles from './modules/read-write/element-imperative-handles'\n\nimport { type Action } from './actions'\n\nimport { ElementImperativeHandle } from '../runtimes/react/element-imperative-handle'\n\nimport { BuilderAPIProxy } from './builder-api/proxy'\nimport * as ReadOnlyState from './read-only-state'\n\nexport type { Operation } from './modules/read-write/read-write-documents'\nexport type { BoxModelHandle } from './modules/read-write/box-models'\nexport { createBox, getBox, parse } from './modules/read-write/box-models'\n\nconst reducers = {\n ...ReadOnlyState.reducers,\n documents: Documents.reducer,\n boxModels: BoxModels.reducer,\n pointer: Pointer.reducer,\n elementImperativeHandles: ElementImperativeHandles.reducer,\n}\n\nexport function createRootReducer() {\n return combineReducers(reducers)\n}\n\nexport type State = Omit<ReadOnlyState.State, 'documents'> & {\n documents: Documents.State\n boxModels: BoxModels.State\n pointer: Pointer.State\n elementImperativeHandles: ElementImperativeHandles.State\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nfunction getDocumentsStateSlice(state: State): Documents.State {\n return state.documents\n}\n\nexport function getDocuments(state: State): Documents.State {\n return Documents.getDocuments(getDocumentsStateSlice(state))\n}\n\nexport function getDocument(state: State, documentKey: string): Documents.Document | null {\n return Documents.getDocument(getDocumentsStateSlice(state), documentKey)\n}\n\nfunction getBoxModelsStateSlice(state: State): BoxModels.State {\n return state.boxModels\n}\n\nexport function getMeasurables(state: State): Map<string, Map<string, BoxModels.Measurable>> {\n return BoxModels.getMeasurables(getBoxModelsStateSlice(state))\n}\n\nexport function getBoxModels(state: State): Map<string, Map<string, BoxModels.BoxModel>> {\n return BoxModels.getBoxModels(getBoxModelsStateSlice(state))\n}\n\nexport function getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModels.BoxModel | null {\n return BoxModels.getBoxModel(getBoxModelsStateSlice(state), documentKey, elementKey)\n}\n\nexport function getPointer(state: State): Pointer.Point | null {\n return Pointer.getPointer(state.pointer)\n}\n\nexport function getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return ElementImperativeHandles.getElementImperativeHandles(state.elementImperativeHandles)\n}\n\nexport function getElementImperativeHandlesContainingElement(\n state: State,\n element: Element,\n): Map<string, Map<string, ElementImperativeHandle>> {\n const elementImperativeHandles = getElementImperativeHandles(state)\n const filteredElementImperativeHandles = new Map<string, Map<string, ElementImperativeHandle>>()\n\n for (const [documentKey, byElementKey] of elementImperativeHandles) {\n const filteredByElementKey = new Map<string, ElementImperativeHandle>()\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n const handleElement = elementImperativeHandle.getDomNode()\n\n if (handleElement?.contains(element)) {\n filteredByElementKey.set(elementKey, elementImperativeHandle)\n }\n }\n\n if (filteredByElementKey.size > 0) {\n filteredElementImperativeHandles.set(documentKey, filteredByElementKey)\n }\n }\n\n return filteredElementImperativeHandles\n}\n\nexport function setupBuilderProxy(\n builderProxy: BuilderAPIProxy,\n): ThunkAction<
|
|
1
|
+
{"version":3,"sources":["../../../src/state/read-write-state.ts"],"sourcesContent":["import { combineReducers, type ThunkAction, type ThunkDispatch } from '@reduxjs/toolkit'\n\nimport * as Documents from './modules/read-write/read-write-documents'\nimport * as BoxModels from './modules/read-write/box-models'\nimport * as Pointer from './modules/read-write/pointer'\nimport * as ElementImperativeHandles from './modules/read-write/element-imperative-handles'\n\nimport { type Action } from './actions'\n\nimport { ElementImperativeHandle } from '../runtimes/react/element-imperative-handle'\n\nimport { BuilderAPIProxy } from './builder-api/proxy'\nimport * as ReadOnlyState from './read-only-state'\n\nexport type { Operation } from './modules/read-write/read-write-documents'\nexport type { BoxModelHandle } from './modules/read-write/box-models'\nexport { createBox, getBox, parse } from './modules/read-write/box-models'\n\nconst reducers = {\n ...ReadOnlyState.reducers,\n documents: Documents.reducer,\n boxModels: BoxModels.reducer,\n pointer: Pointer.reducer,\n elementImperativeHandles: ElementImperativeHandles.reducer,\n}\n\nexport function createRootReducer() {\n return combineReducers(reducers)\n}\n\nexport type State = Omit<ReadOnlyState.State, 'documents'> & {\n documents: Documents.State\n boxModels: BoxModels.State\n pointer: Pointer.State\n elementImperativeHandles: ElementImperativeHandles.State\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nfunction getDocumentsStateSlice(state: State): Documents.State {\n return state.documents\n}\n\nexport function getDocuments(state: State): Documents.State {\n return Documents.getDocuments(getDocumentsStateSlice(state))\n}\n\nexport function getDocument(state: State, documentKey: string): Documents.Document | null {\n return Documents.getDocument(getDocumentsStateSlice(state), documentKey)\n}\n\nfunction getBoxModelsStateSlice(state: State): BoxModels.State {\n return state.boxModels\n}\n\nexport function getMeasurables(state: State): Map<string, Map<string, BoxModels.Measurable>> {\n return BoxModels.getMeasurables(getBoxModelsStateSlice(state))\n}\n\nexport function getBoxModels(state: State): Map<string, Map<string, BoxModels.BoxModel>> {\n return BoxModels.getBoxModels(getBoxModelsStateSlice(state))\n}\n\nexport function getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModels.BoxModel | null {\n return BoxModels.getBoxModel(getBoxModelsStateSlice(state), documentKey, elementKey)\n}\n\nexport function getPointer(state: State): Pointer.Point | null {\n return Pointer.getPointer(state.pointer)\n}\n\nexport function getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return ElementImperativeHandles.getElementImperativeHandles(state.elementImperativeHandles)\n}\n\nexport function getElementImperativeHandlesContainingElement(\n state: State,\n element: Element,\n): Map<string, Map<string, ElementImperativeHandle>> {\n const elementImperativeHandles = getElementImperativeHandles(state)\n const filteredElementImperativeHandles = new Map<string, Map<string, ElementImperativeHandle>>()\n\n for (const [documentKey, byElementKey] of elementImperativeHandles) {\n const filteredByElementKey = new Map<string, ElementImperativeHandle>()\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n const handleElement = elementImperativeHandle.getDomNode()\n\n if (handleElement?.contains(element)) {\n filteredByElementKey.set(elementKey, elementImperativeHandle)\n }\n }\n\n if (filteredByElementKey.size > 0) {\n filteredElementImperativeHandles.set(documentKey, filteredByElementKey)\n }\n }\n\n return filteredElementImperativeHandles\n}\n\nexport function setupBuilderProxy(\n builderProxy: BuilderAPIProxy,\n): ThunkAction<VoidFunction, State, unknown, Action> {\n return dispatch => {\n return builderProxy.setup({ onHostAction: action => dispatch(action) })\n }\n}\n"],"mappings":"AAAA,SAAS,uBAA6D;AAEtE,YAAY,eAAe;AAC3B,YAAY,eAAe;AAC3B,YAAY,aAAa;AACzB,YAAY,8BAA8B;AAO1C,YAAY,mBAAmB;AAI/B,SAAS,WAAW,QAAQ,aAAa;AAEzC,MAAM,WAAW;AAAA,EACf,GAAG,cAAc;AAAA,EACjB,WAAW,UAAU;AAAA,EACrB,WAAW,UAAU;AAAA,EACrB,SAAS,QAAQ;AAAA,EACjB,0BAA0B,yBAAyB;AACrD;AAEO,SAAS,oBAAoB;AAClC,SAAO,gBAAgB,QAAQ;AACjC;AAWA,SAAS,uBAAuB,OAA+B;AAC7D,SAAO,MAAM;AACf;AAEO,SAAS,aAAa,OAA+B;AAC1D,SAAO,UAAU,aAAa,uBAAuB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= new BuilderAPIProxy({ appOrigin });
|
|
85
85
|
readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy });
|
|
86
86
|
const dispatch = store.dispatch;
|
|
87
|
-
dispatch(setupBuilderProxy(builderProxy));
|
|
87
|
+
const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy));
|
|
88
88
|
readWriteCleanup = () => {
|
|
89
89
|
readWriteMiddlewareRef.current = null;
|
|
90
|
-
|
|
90
|
+
builderProxyCleanup();
|
|
91
91
|
};
|
|
92
92
|
})();
|
|
93
93
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../api/client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\n\nimport { type Action } from './actions'\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\n\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\ninterface ReadWriteStateMixin {\n loadReadWriteState: ({ isReadOnly }: { isReadOnly: boolean }) => Promise<() => void>\n}\n\nfunction withReadWriteState(\n loadReadWriteState: ReadWriteStateMixin['loadReadWriteState'],\n): StoreEnhancer<ReadWriteStateMixin> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n loadReadWriteState,\n })\n}\n\nexport function configureStore({\n name,\n appOrigin,\n hostApiClient,\n preloadedState,\n breakpoints,\n}: {\n name: string\n appOrigin: string\n hostApiClient: MakeswiftHostApiClient\n preloadedState: Partial<State> | null\n breakpoints?: Breakpoints.State\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxy.teardown()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n\n preloadedState: {\n ...preloadedState,\n breakpoints: Breakpoints.getInitialState(breakpoints ?? preloadedState?.breakpoints),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n makeswiftApiClientSyncMiddleware(hostApiClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ]),\n\n enhancers: getDefaultEnhancers =>\n getDefaultEnhancers().concat(\n withReadWriteState(async ({ isReadOnly }) => {\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', {\n isReadOnly,\n refCount,\n })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n }),\n ),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EAIE,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,OACK;AAIP,SAAS,kBAAkB,mBAAmB,sBAAsB;AACpE,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAEhC,YAAY,iBAAiB;AAE7B,SAAS,qCAAqC;AAI9C,YAAY,mBAAmB;AAQ/B,SAAS,wCAAwC;AAU1C,SAAS,+BACd,eACuC;AACvC,MAAI,wBAAkC,CAAC;AACvC,MAAI,cAA0C;AAC9C,MAAI,mBAAoC;AAExC,SAAO,iBAAiB,CAAC,EAAE,UAAU,SAAS,MAAM,UAAQ;AAC1D,WAAO,CAAC,WAAmB;AACzB,YAAM,QAAQ,SAAS;AAEvB,UAAI,cAAc,WAAW,MAAM;AACjC,YAAI,CAAC,MAAM,YAAY;AAIrB,gCAAsB,KAAK,MAAM;AAAA,QACnC;AAEA,eAAO,KAAK,MAAM;AAAA,MACpB;AAEA,UAAI,MAAM,YAAY;AACpB,gBAAQ,MAAM,6BAA6B;AAAA,UACzC,YAAY,MAAM;AAAA,UAClB,eAAe,cAAc;AAAA,UAC7B,aAAa,MAAM;AAAA,QACrB,CAAC;AAAA,MACH;AAGA,UAAI,oBAAoB,QAAQ,gBAAgB,cAAc,SAAS;AACrE,sBAAc,cAAc;AAE5B,cAAM,gBAAgB,EAAE,UAAU,SAAS;AAK3C,2BAAmB,QAAkB,GAAG,YAAY,IAAI,QAAM,GAA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,IACF,GAAG;AAEH,QAAI;AACF,YAAM;AAAA,IACR,UAAE;AACA,8BAAwB;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,QAAQ,oBAAoB;AAAA,IAChC,SAAS,gBAAgB,cAAc,QAAQ;AAAA,IAE/C,gBAAgB;AAAA,MACd,GAAG;AAAA,MACH,aAAa,YAAY,gBAAgB,eAAe,gBAAgB,WAAW;AAAA,IACrF;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE,OAAO;AAAA,MAC7C,8BAA8B;AAAA,MAC9B,iCAAiC,aAAa;AAAA,MAC9C,+BAA+B,sBAAsB;AAAA,IACvD,CAAC;AAAA,IAEH,WAAW,yBACT,oBAAoB,EAAE;AAAA,MACpB,mBAAmB,OAAO,EAAE,WAAW,MAAM;AAC3C,YAAI,YAAY;AACd,cAAI,WAAW,GAAG;AAChB,oBAAQ,MAAM,6BAA6B;AAAA,cACzC;AAAA,cACA;AAAA,YACF,CAAC;AAAA,UACH;AAEA,iBAAO,MAAM;AAAA,UAAC;AAAA,QAChB;AAEA,cAAM,mBAAmB;AACzB,oBAAY;AAEZ,YAAI,aAAa;AACjB,eAAO,MAAM;AACX,cAAI,YAAY;AACd;AAAA,UACF;AAEA,uBAAa;AACb,sBAAY;AACZ,cAAI,aAAa,KAAK,oBAAoB,MAAM;AAC9C,6BAAiB;AACjB,+BAAmB;AAAA,UACrB;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEF,UAAU,eAAe;AAAA,MACvB,MAAM,GAAG,IAAI,MAAK,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MAC1C,iBAAiB;AAAA,QACf,gBAAgB;AAAA,QAChB,mBAAmB;AAAA,QACnB,mBAAmB;AAAA,MACrB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../api/client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\n\nimport { type Action } from './actions'\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\n\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\ninterface ReadWriteStateMixin {\n loadReadWriteState: ({ isReadOnly }: { isReadOnly: boolean }) => Promise<() => void>\n}\n\nfunction withReadWriteState(\n loadReadWriteState: ReadWriteStateMixin['loadReadWriteState'],\n): StoreEnhancer<ReadWriteStateMixin> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n loadReadWriteState,\n })\n}\n\nexport function configureStore({\n name,\n appOrigin,\n hostApiClient,\n preloadedState,\n breakpoints,\n}: {\n name: string\n appOrigin: string\n hostApiClient: MakeswiftHostApiClient\n preloadedState: Partial<State> | null\n breakpoints?: Breakpoints.State\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n\n preloadedState: {\n ...preloadedState,\n breakpoints: Breakpoints.getInitialState(breakpoints ?? preloadedState?.breakpoints),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n makeswiftApiClientSyncMiddleware(hostApiClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ]),\n\n enhancers: getDefaultEnhancers =>\n getDefaultEnhancers().concat(\n withReadWriteState(async ({ isReadOnly }) => {\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', {\n isReadOnly,\n refCount,\n })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n }),\n ),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EAIE,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,OACK;AAIP,SAAS,kBAAkB,m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W,yBACT,oBAAoB,EAAE;AAAA,MACpB,mBAAmB,OAAO,EAAE,WAAW,MAAM;AAC3C,YAAI,YAAY;AACd,cAAI,WAAW,GAAG;AAChB,oBAAQ,MAAM,6BAA6B;AAAA,cACzC;AAAA,cACA;AAAA,YACF,CAAC;AAAA,UACH;AAEA,iBAAO,MAAM;AAAA,UAAC;AAAA,QAChB;AAEA,cAAM,mBAAmB;AACzB,oBAAY;AAEZ,YAAI,aAAa;AACjB,eAAO,MAAM;AACX,cAAI,YAAY;AACd;AAAA,UACF;AAEA,uBAAa;AACb,sBAAY;AACZ,cAAI,aAAa,KAAK,oBAAoB,MAAM;AAC9C,6BAAiB;AACjB,+BAAmB;AAAA,UACrB;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEF,UAAU,eAAe;AAAA,MACvB,MAAM,GAAG,IAAI,MAAK,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MAC1C,iBAAiB;AAAA,QACf,gBAAgB;AAAA,QAChB,mBAAmB;AAAA,QACnB,mBAAmB;AAAA,MACrB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { getPropControllerDescriptors } from "../read-only-state";
|
|
2
1
|
import * as Documents from "../modules/read-only-documents";
|
|
3
2
|
import * as ElementTrees from "../modules/element-trees";
|
|
4
3
|
import { getTranslatableData } from "../../controls/control";
|
|
5
|
-
function
|
|
4
|
+
function getTranslatableContent(descriptors, elementTree) {
|
|
6
5
|
const translatableData = {};
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
for (const element of ElementTrees.traverseElementTree(
|
|
7
|
+
elementTree,
|
|
8
|
+
descriptors
|
|
9
|
+
)) {
|
|
9
10
|
if (Documents.isElementReference(element))
|
|
10
11
|
continue;
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
12
|
+
const elementDescriptors = descriptors.get(element.type);
|
|
13
|
+
if (elementDescriptors == null)
|
|
13
14
|
continue;
|
|
14
|
-
Object.entries(
|
|
15
|
+
Object.entries(elementDescriptors).forEach(([propName, descriptor]) => {
|
|
15
16
|
const translatablePropData = getTranslatableData(descriptor, element.props[propName]);
|
|
16
17
|
if (translatablePropData != null) {
|
|
17
18
|
translatableData[`${element.key}:${propName}`] = translatablePropData;
|
|
@@ -21,6 +22,6 @@ function getElementTreeTranslatableData(state, elementTree) {
|
|
|
21
22
|
return translatableData;
|
|
22
23
|
}
|
|
23
24
|
export {
|
|
24
|
-
|
|
25
|
+
getTranslatableContent
|
|
25
26
|
};
|
|
26
27
|
//# sourceMappingURL=get.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/translations/get.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/translations/get.ts"],"sourcesContent":["import * as Documents from '../modules/read-only-documents'\nimport * as ElementTrees from '../modules/element-trees'\nimport { getTranslatableData } from '../../controls/control'\nimport type {DescriptorsByComponentType} from '../modules/prop-controllers'\n\nexport function getTranslatableContent(\n descriptors: DescriptorsByComponentType,\n elementTree: Documents.ElementData,\n): Record<string, Documents.Data> {\n const translatableData: Record<string, Documents.Data> = {}\n\n for (const element of ElementTrees.traverseElementTree(\n elementTree,\n descriptors,\n )) {\n if (Documents.isElementReference(element)) continue\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) continue\n\n Object.entries(elementDescriptors).forEach(([propName, descriptor]) => {\n const translatablePropData = getTranslatableData(descriptor, element.props[propName])\n\n if (translatablePropData != null) {\n translatableData[`${element.key}:${propName}`] = translatablePropData\n }\n })\n }\n\n return translatableData\n}\n"],"mappings":"AAAA,YAAY,eAAe;AAC3B,YAAY,kBAAkB;AAC9B,SAAS,2BAA2B;AAG7B,SAAS,uBACd,aACA,aACgC;AAChC,QAAM,mBAAmD,CAAC;AAE1D,aAAW,WAAW,aAAa;AAAA,IACjC;AAAA,IACA;AAAA,EACF,GAAG;AACD,QAAI,UAAU,mBAAmB,OAAO;AAAG;AAE3C,UAAM,qBAAqB,YAAY,IAAI,QAAQ,IAAI;AACvD,QAAI,sBAAsB;AAAM;AAEhC,WAAO,QAAQ,kBAAkB,EAAE,QAAQ,CAAC,CAAC,UAAU,UAAU,MAAM;AACrE,YAAM,uBAAuB,oBAAoB,YAAY,QAAQ,MAAM,QAAQ,CAAC;AAEpF,UAAI,wBAAwB,MAAM;AAChC,yBAAiB,GAAG,QAAQ,GAAG,IAAI,QAAQ,EAAE,IAAI;AAAA,MACnD;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getPropControllerDescriptors } from "../read-only-state";
|
|
2
1
|
import * as Documents from "../modules/read-only-documents";
|
|
3
2
|
import {
|
|
4
3
|
mergeGridPropControllerTranslatedData,
|
|
@@ -6,23 +5,22 @@ import {
|
|
|
6
5
|
} from "@makeswift/prop-controllers";
|
|
7
6
|
import { ReactMergeTranslationsVisitor } from "../../controls/visitors/merge-translations-visitor";
|
|
8
7
|
import { isLegacyDescriptor } from "../../prop-controllers/descriptors";
|
|
9
|
-
function
|
|
10
|
-
function merge(
|
|
8
|
+
function mergeTranslatedContent(descriptors, elementTree, translatedData) {
|
|
9
|
+
function merge(descriptorsByType, translatedData2) {
|
|
11
10
|
return function(node) {
|
|
12
11
|
if (Documents.isElementReference(node))
|
|
13
12
|
return node;
|
|
14
|
-
const elementDescriptors =
|
|
15
|
-
|
|
16
|
-
if (descriptors == null) {
|
|
13
|
+
const elementDescriptors = descriptorsByType.get(node.type);
|
|
14
|
+
if (elementDescriptors == null) {
|
|
17
15
|
throw new Error(`Can't merge element of type "${node.type}" because it has no descriptors`);
|
|
18
16
|
}
|
|
19
17
|
const context = {
|
|
20
18
|
translatedData: translatedData2,
|
|
21
|
-
mergeTranslatedData: merge(
|
|
19
|
+
mergeTranslatedData: merge(descriptorsByType, translatedData2)
|
|
22
20
|
};
|
|
23
21
|
const props = {};
|
|
24
|
-
for (const propName of Object.keys(
|
|
25
|
-
const descriptor =
|
|
22
|
+
for (const propName of Object.keys(elementDescriptors)) {
|
|
23
|
+
const descriptor = elementDescriptors[propName];
|
|
26
24
|
props[propName] = mergeTranslatedData(
|
|
27
25
|
descriptor,
|
|
28
26
|
node.props[propName],
|
|
@@ -33,7 +31,7 @@ function mergeElementTreeTranslatedData(state, elementTree, translatedData) {
|
|
|
33
31
|
return { ...node, props };
|
|
34
32
|
};
|
|
35
33
|
}
|
|
36
|
-
return merge(
|
|
34
|
+
return merge(descriptors, translatedData)(elementTree);
|
|
37
35
|
}
|
|
38
36
|
function mergeTranslatedData(definition, data, translatedData, context) {
|
|
39
37
|
if (data == null)
|
|
@@ -55,7 +53,7 @@ function mergeTranslatedData(definition, data, translatedData, context) {
|
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
export {
|
|
58
|
-
|
|
56
|
+
mergeTranslatedContent,
|
|
59
57
|
mergeTranslatedData
|
|
60
58
|
};
|
|
61
59
|
//# sourceMappingURL=merge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/translations/merge.ts"],"sourcesContent":["import { MergeTranslatableDataContext, type TranslationDto, type Data } from '@makeswift/controls'\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/translations/merge.ts"],"sourcesContent":["import { MergeTranslatableDataContext, type TranslationDto, type Data } from '@makeswift/controls'\nimport * as Documents from '../modules/read-only-documents'\nimport {\n GridPropControllerData,\n mergeGridPropControllerTranslatedData,\n Types as PropControllerTypes,\n} from '@makeswift/prop-controllers'\nimport { ReactMergeTranslationsVisitor } from '../../controls/visitors/merge-translations-visitor'\nimport { isLegacyDescriptor } from '../../prop-controllers/descriptors'\nimport { Descriptor as PropControllerDescriptor } from '../../prop-controllers/descriptors'\nimport type { DescriptorsByComponentType } from '../modules/prop-controllers'\n\nexport function mergeTranslatedContent(\n descriptors: DescriptorsByComponentType,\n elementTree: Documents.ElementData,\n translatedData: TranslationDto,\n): Documents.Element {\n function merge(descriptorsByType: DescriptorsByComponentType, translatedData: TranslationDto) {\n return function (node: Documents.Element): Documents.Element {\n if (Documents.isElementReference(node)) return node\n\n const elementDescriptors = descriptorsByType.get(node.type)\n\n if (elementDescriptors == null) {\n throw new Error(`Can't merge element of type \"${node.type}\" because it has no descriptors`)\n }\n\n const context: MergeTranslatableDataContext = {\n translatedData: translatedData,\n mergeTranslatedData: merge(descriptorsByType, translatedData),\n }\n const props = {} as Record<string, Documents.Data>\n\n for (const propName of Object.keys(elementDescriptors)) {\n const descriptor = elementDescriptors[propName]\n\n props[propName] = mergeTranslatedData(\n descriptor,\n node.props[propName],\n translatedData[`${node.key}:${propName}`],\n context,\n )\n }\n\n return { ...node, props }\n }\n }\n return merge(descriptors, translatedData)(elementTree)\n}\n\nexport function mergeTranslatedData(\n definition: PropControllerDescriptor,\n data: Data,\n translatedData: Data,\n context: MergeTranslatableDataContext,\n): Data {\n if (data == null) return data\n if (!isLegacyDescriptor(definition)) {\n const mergeTranslationsVisitor = new ReactMergeTranslationsVisitor(context)\n return definition.accept(mergeTranslationsVisitor, data, translatedData)\n }\n\n switch (definition.type) {\n case PropControllerTypes.TextInput:\n case PropControllerTypes.TextArea:\n if (translatedData == null) return data\n return translatedData\n\n case PropControllerTypes.Grid:\n return mergeGridPropControllerTranslatedData(data as GridPropControllerData, context)\n\n default:\n return data\n }\n}\n"],"mappings":"AACA,YAAY,eAAe;AAC3B;AAAA,EAEE;AAAA,EACA,SAAS;AAAA,OACJ;AACP,SAAS,qCAAqC;AAC9C,SAAS,0BAA0B;AAI5B,SAAS,uBACd,aACA,aACA,gBACmB;AACnB,WAAS,MAAM,mBAA+CA,iBAAgC;AAC5F,WAAO,SAAU,MAA4C;AAC3D,UAAI,UAAU,mBAAmB,IAAI;AAAG,eAAO;AAE/C,YAAM,qBAAqB,kBAAkB,IAAI,KAAK,IAAI;AAE1D,UAAI,sBAAsB,MAAM;AAC9B,cAAM,IAAI,MAAM,gCAAgC,KAAK,IAAI,iCAAiC;AAAA,MAC5F;AAEA,YAAM,UAAwC;AAAA,QAC5C,gBAAgBA;AAAA,QAChB,qBAAqB,MAAM,mBAAmBA,eAAc;AAAA,MAC9D;AACA,YAAM,QAAQ,CAAC;AAEf,iBAAW,YAAY,OAAO,KAAK,kBAAkB,GAAG;AACtD,cAAM,aAAa,mBAAmB,QAAQ;AAE9C,cAAM,QAAQ,IAAI;AAAA,UAChB;AAAA,UACA,KAAK,MAAM,QAAQ;AAAA,UACnBA,gBAAe,GAAG,KAAK,GAAG,IAAI,QAAQ,EAAE;AAAA,UACxC;AAAA,QACF;AAAA,MACF;AAEA,aAAO,EAAE,GAAG,MAAM,MAAM;AAAA,IAC1B;AAAA,EACF;AACA,SAAO,MAAM,aAAa,cAAc,EAAE,WAAW;AACvD;AAEO,SAAS,oBACd,YACA,MACA,gBACA,SACM;AACN,MAAI,QAAQ;AAAM,WAAO;AACzB,MAAI,CAAC,mBAAmB,UAAU,GAAG;AACnC,UAAM,2BAA2B,IAAI,8BAA8B,OAAO;AAC1E,WAAO,WAAW,OAAO,0BAA0B,MAAM,cAAc;AAAA,EACzE;AAEA,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK,oBAAoB;AAAA,IACzB,KAAK,oBAAoB;AACvB,UAAI,kBAAkB;AAAM,eAAO;AACnC,aAAO;AAAA,IAET,KAAK,oBAAoB;AACvB,aAAO,sCAAsC,MAAgC,OAAO;AAAA,IAEtF;AACE,aAAO;AAAA,EACX;AACF;","names":["translatedData"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/translations/index.ts"],"sourcesContent":["export { getTranslatableContent } from '../state/translations/get'\nexport { mergeTranslatedContent } from '../state/translations/merge'\nexport type { DescriptorsByComponentType, DescriptorsByProp } from '../state/modules/prop-controllers'\nexport type { ElementData, Data, Element } from '../state/read-only-state'\nexport type { TranslationDto } from '@makeswift/controls'\n"],"mappings":"AAAA,SAAS,8BAA8B;AACvC,SAAS,8BAA8B;","names":[]}
|
|
@@ -19,6 +19,7 @@ import { MakeswiftComponent } from "../runtimes/react/components/MakeswiftCompon
|
|
|
19
19
|
import { Page } from "../runtimes/react/components/page";
|
|
20
20
|
import { RuntimeProvider } from "../runtimes/react/components/RuntimeProvider";
|
|
21
21
|
import { Slot } from "../runtimes/react/components/Slot";
|
|
22
|
+
import { GoogleFontLink } from "../runtimes/react/components/GoogleFontLink";
|
|
22
23
|
import {
|
|
23
24
|
createRootStyleCache,
|
|
24
25
|
RootStyleRegistry,
|
|
@@ -31,6 +32,7 @@ export {
|
|
|
31
32
|
DefaultHeadSnippet,
|
|
32
33
|
DefaultImage,
|
|
33
34
|
FrameworkContext,
|
|
35
|
+
GoogleFontLink,
|
|
34
36
|
MAKESWIFT_SITE_VERSION_COOKIE,
|
|
35
37
|
MakeswiftClient,
|
|
36
38
|
MakeswiftComponent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/unstable-framework-support/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n serializeSiteVersion,\n deserializeSiteVersion,\n secondsUntilSiteVersionExpiration,\n} from '../api/site-version'\n\nexport { type ApiHandlerUserConfig, createApiHandler } from '../api-handler'\nexport { SET_COOKIE_HEADER, cookieSettingOptions } from '../api-handler/cookies'\nexport { REDIRECT_SEARCH_PARAM, redirectLiveHandler } from '../api-handler/handlers/redirect-live'\nexport { toApiRequest, pipeResponseTo } from '../api-handler/node-request-response'\nexport { MAKESWIFT_SITE_VERSION_COOKIE, SearchParams } from '../api-handler/preview'\n\nexport { MakeswiftClient } from '../client'\n\nexport { type BreakpointsInput as Breakpoints } from '../state/modules/breakpoints'\n\nexport {\n FrameworkContext,\n DefaultHead,\n DefaultHeadSnippet,\n DefaultImage,\n} from '../runtimes/react/components/framework-context'\n\nexport { MakeswiftComponent } from '../runtimes/react/components/MakeswiftComponent'\nexport { Page } from '../runtimes/react/components/page'\nexport { RuntimeProvider } from '../runtimes/react/components/RuntimeProvider'\nexport { Slot } from '../runtimes/react/components/Slot'\n\nexport {\n createRootStyleCache,\n RootStyleRegistry,\n styleTagHtml,\n StyleTagSSR,\n type RootStyleProps,\n} from '../runtimes/react/root-style-registry'\n\nexport { ReactRuntime } from '../runtimes/react/react-runtime'\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAoC,wBAAwB;AAC5D,SAAS,mBAAmB,4BAA4B;AACxD,SAAS,uBAAuB,2BAA2B;AAC3D,SAAS,cAAc,sBAAsB;AAC7C,SAAS,+BAA+B,oBAAoB;AAE5D,SAAS,uBAAuB;AAIhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AACnC,SAAS,YAAY;AACrB,SAAS,uBAAuB;AAChC,SAAS,YAAY;AAErB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,oBAAoB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/unstable-framework-support/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n serializeSiteVersion,\n deserializeSiteVersion,\n secondsUntilSiteVersionExpiration,\n} from '../api/site-version'\n\nexport { type ApiHandlerUserConfig, createApiHandler } from '../api-handler'\nexport { SET_COOKIE_HEADER, cookieSettingOptions } from '../api-handler/cookies'\nexport { REDIRECT_SEARCH_PARAM, redirectLiveHandler } from '../api-handler/handlers/redirect-live'\nexport { toApiRequest, pipeResponseTo } from '../api-handler/node-request-response'\nexport { MAKESWIFT_SITE_VERSION_COOKIE, SearchParams } from '../api-handler/preview'\n\nexport { MakeswiftClient } from '../client'\n\nexport { type BreakpointsInput as Breakpoints } from '../state/modules/breakpoints'\n\nexport {\n FrameworkContext,\n DefaultHead,\n DefaultHeadSnippet,\n DefaultImage,\n} from '../runtimes/react/components/framework-context'\n\nexport { MakeswiftComponent } from '../runtimes/react/components/MakeswiftComponent'\nexport { Page } from '../runtimes/react/components/page'\nexport { RuntimeProvider } from '../runtimes/react/components/RuntimeProvider'\nexport { Slot } from '../runtimes/react/components/Slot'\n\nexport { GoogleFontLink } from '../runtimes/react/components/GoogleFontLink'\n\nexport {\n createRootStyleCache,\n RootStyleRegistry,\n styleTagHtml,\n StyleTagSSR,\n type RootStyleProps,\n} from '../runtimes/react/root-style-registry'\n\nexport { ReactRuntime } from '../runtimes/react/react-runtime'\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAoC,wBAAwB;AAC5D,SAAS,mBAAmB,4BAA4B;AACxD,SAAS,uBAAuB,2BAA2B;AAC3D,SAAS,cAAc,sBAAsB;AAC7C,SAAS,+BAA+B,oBAAoB;AAE5D,SAAS,uBAAuB;AAIhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AACnC,SAAS,YAAY;AACrB,SAAS,uBAAuB;AAChC,SAAS,YAAY;AAErB,SAAS,sBAAsB;AAE/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,oBAAoB;","names":[]}
|