@makeswift/runtime 0.22.0 → 0.22.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/next/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/state/actions.js +29 -4
- package/dist/cjs/state/actions.js.map +1 -1
- package/dist/cjs/state/modules/element-trees.js +281 -0
- package/dist/cjs/state/modules/element-trees.js.map +1 -0
- package/dist/cjs/state/modules/prop-controllers.js.map +1 -1
- package/dist/cjs/state/modules/read-only-documents.js.map +1 -1
- package/dist/cjs/state/modules/read-write-documents.js.map +1 -1
- package/dist/cjs/state/react-builder-preview.js +83 -41
- package/dist/cjs/state/react-builder-preview.js.map +1 -1
- package/dist/cjs/state/react-page.js +31 -76
- package/dist/cjs/state/react-page.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/state/actions.js +26 -4
- package/dist/esm/state/actions.js.map +1 -1
- package/dist/esm/state/modules/element-trees.js +249 -0
- package/dist/esm/state/modules/element-trees.js.map +1 -0
- package/dist/esm/state/modules/prop-controllers.js.map +1 -1
- package/dist/esm/state/modules/read-only-documents.js.map +1 -1
- package/dist/esm/state/modules/read-write-documents.js.map +1 -1
- package/dist/esm/state/react-builder-preview.js +64 -20
- package/dist/esm/state/react-builder-preview.js.map +1 -1
- package/dist/esm/state/react-page.js +30 -81
- package/dist/esm/state/react-page.js.map +1 -1
- package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts +4 -4
- package/dist/types/locale.d.ts +1 -1
- package/dist/types/state/__tests__/fixtures/operations.d.ts +8 -0
- package/dist/types/state/__tests__/fixtures/operations.d.ts.map +1 -0
- package/dist/types/state/__tests__/fixtures/root-elements.d.ts +4 -0
- package/dist/types/state/__tests__/fixtures/root-elements.d.ts.map +1 -0
- package/dist/types/state/__tests__/react-builder-preview.test.d.ts.map +1 -0
- package/dist/types/state/__tests__/react-page.test.d.ts.map +1 -0
- package/dist/types/state/actions.d.ts +40 -10
- package/dist/types/state/actions.d.ts.map +1 -1
- package/dist/types/state/modules/__tests__/element-trees.test.d.ts +2 -0
- package/dist/types/state/modules/__tests__/element-trees.test.d.ts.map +1 -0
- package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts +1545 -0
- package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts.map +1 -0
- package/dist/types/state/modules/element-trees.d.ts +25 -0
- package/dist/types/state/modules/element-trees.d.ts.map +1 -0
- package/dist/types/state/modules/prop-controllers.d.ts +7 -5
- package/dist/types/state/modules/prop-controllers.d.ts.map +1 -1
- package/dist/types/state/modules/read-only-documents.d.ts +1 -1
- package/dist/types/state/modules/read-only-documents.d.ts.map +1 -1
- package/dist/types/state/modules/read-write-documents.d.ts +2 -2
- package/dist/types/state/modules/read-write-documents.d.ts.map +1 -1
- package/dist/types/state/react-builder-preview.d.ts +8 -5
- package/dist/types/state/react-builder-preview.d.ts.map +1 -1
- package/dist/types/state/react-page.d.ts +12 -10
- package/dist/types/state/react-page.d.ts.map +1 -1
- package/package.json +4 -3
- package/dist/types/state/react-builder-preview.test.d.ts.map +0 -1
- package/dist/types/state/react-page.test.d.ts.map +0 -1
- /package/dist/types/state/{react-builder-preview.test.d.ts → __tests__/react-builder-preview.test.d.ts} +0 -0
- /package/dist/types/state/{react-page.test.d.ts → __tests__/react-page.test.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/read-write-documents.ts"],"sourcesContent":["import { Operation } from 'ot-json0'\nimport { removeIn, setIn } from 'immutable'\n\nimport * as ReadOnlyDocuments from './read-only-documents'\nimport { Action, ActionTypes } from '../actions'\n\nexport type { Document, Element, ElementData, ElementReference } from './read-only-documents'\nexport { isElementReference } from './read-only-documents'\nexport type { Operation }\n\nfunction apply(data: ReadOnlyDocuments.Element, operation: Operation): ReadOnlyDocuments.Element {\n let applied = data\n\n operation.forEach(component => {\n // @ts-expect-error: `ld` isn't in all possible values of `component`\n if (component.ld != null) applied = removeIn(applied, component.p)\n\n // @ts-expect-error: `od` isn't in all possible values of `component`\n if (component.od != null) applied = removeIn(applied, component.p)\n\n // @ts-expect-error: `li` isn't in all possible values of `component`\n if (component.li != null) applied = setIn(applied, component.p, component.li)\n\n // @ts-expect-error: `oi` isn't in all possible values of `component`\n if (component.oi != null) applied = setIn(applied, component.p, component.oi)\n })\n\n return applied\n}\n\nexport type State = ReadOnlyDocuments.State\n\nexport function getInitialState({\n rootElements,\n}: {\n rootElements?: Map<string, ReadOnlyDocuments.Element>\n} = {}): State {\n return ReadOnlyDocuments.getInitialState({ rootElements })\n}\n\nfunction getReadOnlyDocumentsStateSlice(state: State): ReadOnlyDocuments.State {\n return state\n}\n\nexport function getDocument(state: State, documentKey: string): ReadOnlyDocuments.Document | null {\n return ReadOnlyDocuments.getDocument(getReadOnlyDocumentsStateSlice(state), documentKey)\n}\n\nexport function getDocuments(state: State): ReadOnlyDocuments.State {\n return ReadOnlyDocuments.getDocuments(getReadOnlyDocumentsStateSlice(state))\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n const nextState = ReadOnlyDocuments.reducer(state, action)\n\n switch (action.type) {\n case ActionTypes.CHANGE_DOCUMENT: {\n const currentRootElement = getDocument(nextState, action.payload.documentKey)?.rootElement\n\n if (currentRootElement == null) return nextState\n\n const nextRootElement = apply(currentRootElement, action.payload.operation)\n\n return currentRootElement === nextRootElement\n ? nextState\n : new Map(nextState).set(\n action.payload.documentKey,\n ReadOnlyDocuments.createDocument(action.payload.documentKey, nextRootElement),\n )\n }\n\n default:\n return nextState\n }\n}\n"],"mappings":"AACA,SAAS,UAAU,aAAa;AAEhC,YAAY,uBAAuB;AACnC,
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/read-write-documents.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { removeIn, setIn } from 'immutable'\n\nimport * as ReadOnlyDocuments from './read-only-documents'\nimport { type Action, ActionTypes } from '../actions'\n\nexport type { Document, Element, ElementData, ElementReference } from './read-only-documents'\nexport { isElementReference } from './read-only-documents'\nexport type { Operation }\n\nfunction apply(data: ReadOnlyDocuments.Element, operation: Operation): ReadOnlyDocuments.Element {\n let applied = data\n\n operation.forEach(component => {\n // @ts-expect-error: `ld` isn't in all possible values of `component`\n if (component.ld != null) applied = removeIn(applied, component.p)\n\n // @ts-expect-error: `od` isn't in all possible values of `component`\n if (component.od != null) applied = removeIn(applied, component.p)\n\n // @ts-expect-error: `li` isn't in all possible values of `component`\n if (component.li != null) applied = setIn(applied, component.p, component.li)\n\n // @ts-expect-error: `oi` isn't in all possible values of `component`\n if (component.oi != null) applied = setIn(applied, component.p, component.oi)\n })\n\n return applied\n}\n\nexport type State = ReadOnlyDocuments.State\n\nexport function getInitialState({\n rootElements,\n}: {\n rootElements?: Map<string, ReadOnlyDocuments.Element>\n} = {}): State {\n return ReadOnlyDocuments.getInitialState({ rootElements })\n}\n\nfunction getReadOnlyDocumentsStateSlice(state: State): ReadOnlyDocuments.State {\n return state\n}\n\nexport function getDocument(state: State, documentKey: string): ReadOnlyDocuments.Document | null {\n return ReadOnlyDocuments.getDocument(getReadOnlyDocumentsStateSlice(state), documentKey)\n}\n\nexport function getDocuments(state: State): ReadOnlyDocuments.State {\n return ReadOnlyDocuments.getDocuments(getReadOnlyDocumentsStateSlice(state))\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n const nextState = ReadOnlyDocuments.reducer(state, action)\n\n switch (action.type) {\n case ActionTypes.CHANGE_DOCUMENT: {\n const currentRootElement = getDocument(nextState, action.payload.documentKey)?.rootElement\n\n if (currentRootElement == null) return nextState\n\n const nextRootElement = apply(currentRootElement, action.payload.operation)\n\n return currentRootElement === nextRootElement\n ? nextState\n : new Map(nextState).set(\n action.payload.documentKey,\n ReadOnlyDocuments.createDocument(action.payload.documentKey, nextRootElement),\n )\n }\n\n default:\n return nextState\n }\n}\n"],"mappings":"AACA,SAAS,UAAU,aAAa;AAEhC,YAAY,uB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AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import thunk from "redux-thunk";
|
|
8
8
|
import deepEqual from "../utils/deepEqual";
|
|
9
9
|
import * as Documents from "./modules/read-write-documents";
|
|
10
|
+
import * as ElementTrees from "./modules/element-trees";
|
|
10
11
|
import * as ReactComponents from "./modules/react-components";
|
|
11
12
|
import * as BoxModels from "./modules/box-models";
|
|
12
13
|
import * as ComponentsMeta from "./modules/components-meta";
|
|
@@ -20,31 +21,34 @@ import * as ElementImperativeHandles from "./modules/element-imperative-handles"
|
|
|
20
21
|
import * as Breakpoints from "./modules/breakpoints";
|
|
21
22
|
import * as ReactPage from "./react-page";
|
|
22
23
|
import {
|
|
24
|
+
ActionTypes,
|
|
23
25
|
changeDocumentElementSize,
|
|
24
26
|
changeElementBoxModels,
|
|
27
|
+
changeElementTree,
|
|
25
28
|
elementFromPointChange,
|
|
26
29
|
handleWheel,
|
|
27
30
|
handlePointerMove,
|
|
28
31
|
messageBuilderPropController,
|
|
29
32
|
registerBuilderComponent,
|
|
30
|
-
|
|
33
|
+
createElementTree,
|
|
31
34
|
registerMeasurable,
|
|
32
35
|
registerPropControllers,
|
|
33
36
|
registerPropControllersHandle,
|
|
34
37
|
setBreakpoints,
|
|
35
38
|
setIsInBuilder,
|
|
36
39
|
unregisterBuilderComponent,
|
|
37
|
-
|
|
40
|
+
unregisterBuilderDocument,
|
|
41
|
+
deleteElementTree,
|
|
38
42
|
unregisterMeasurable,
|
|
39
43
|
unregisterPropControllers,
|
|
40
44
|
registerBuilderDocument
|
|
41
45
|
} from "./actions";
|
|
42
|
-
import { ActionTypes } from "./actions";
|
|
43
46
|
import { createPropController } from "../prop-controllers/instances";
|
|
44
47
|
import { serializeControls } from "../builder";
|
|
45
48
|
import { createBox, getBox, parse } from "./modules/box-models";
|
|
46
49
|
const reducer = combineReducers({
|
|
47
50
|
documents: Documents.reducer,
|
|
51
|
+
elementTrees: ElementTrees.reducer,
|
|
48
52
|
reactComponents: ReactComponents.reducer,
|
|
49
53
|
boxModels: BoxModels.reducer,
|
|
50
54
|
componentsMeta: ComponentsMeta.reducer,
|
|
@@ -60,6 +64,9 @@ const reducer = combineReducers({
|
|
|
60
64
|
function getDocumentsStateSlice(state) {
|
|
61
65
|
return state.documents;
|
|
62
66
|
}
|
|
67
|
+
function getDocument(state, documentKey) {
|
|
68
|
+
return Documents.getDocument(getDocumentsStateSlice(state), documentKey);
|
|
69
|
+
}
|
|
63
70
|
function getBoxModelsStateSlice(state) {
|
|
64
71
|
return state.boxModels;
|
|
65
72
|
}
|
|
@@ -257,8 +264,8 @@ function elementKeysFromElementFromPoint(elementFromPoint) {
|
|
|
257
264
|
getState(),
|
|
258
265
|
elementFromPoint
|
|
259
266
|
);
|
|
260
|
-
const
|
|
261
|
-
const descendingDepthDocumentKeys =
|
|
267
|
+
const ascendingDepthDocumentKeys = ReactPage.getDocumentKeysSortedByDepth(getState());
|
|
268
|
+
const descendingDepthDocumentKeys = ascendingDepthDocumentKeys.slice().reverse();
|
|
262
269
|
let currentElement = elementFromPoint;
|
|
263
270
|
let keys = null;
|
|
264
271
|
while (currentElement != null) {
|
|
@@ -301,14 +308,15 @@ function registerBuilderComponents() {
|
|
|
301
308
|
const state = getState();
|
|
302
309
|
const componentsMeta = getComponentsMeta(state);
|
|
303
310
|
componentsMeta.forEach((meta, type) => {
|
|
304
|
-
const
|
|
305
|
-
if (
|
|
306
|
-
|
|
311
|
+
const descriptors = getComponentPropControllerDescriptors(state, type);
|
|
312
|
+
if (descriptors != null) {
|
|
313
|
+
const [serializedControls, transferables] = serializeControls(descriptors);
|
|
314
|
+
dispatch(registerBuilderComponent({ type, meta, serializedControls }, transferables));
|
|
307
315
|
}
|
|
308
316
|
});
|
|
309
317
|
return () => {
|
|
310
|
-
componentsMeta.forEach((_,
|
|
311
|
-
dispatch(
|
|
318
|
+
componentsMeta.forEach((_, type) => {
|
|
319
|
+
dispatch(unregisterBuilderComponent({ type }));
|
|
312
320
|
});
|
|
313
321
|
};
|
|
314
322
|
};
|
|
@@ -321,7 +329,7 @@ function registerBuilderDocuments() {
|
|
|
321
329
|
});
|
|
322
330
|
return () => {
|
|
323
331
|
documents.forEach((_document, documentKey) => {
|
|
324
|
-
dispatch(
|
|
332
|
+
dispatch(unregisterBuilderDocument(documentKey));
|
|
325
333
|
});
|
|
326
334
|
};
|
|
327
335
|
};
|
|
@@ -400,17 +408,13 @@ function messageChannelMiddleware(client, channel) {
|
|
|
400
408
|
case ActionTypes.UNREGISTER_BUILDER_DOCUMENT:
|
|
401
409
|
channel.postMessage(action);
|
|
402
410
|
break;
|
|
403
|
-
case ActionTypes.
|
|
404
|
-
const {
|
|
405
|
-
|
|
406
|
-
channel.postMessage(
|
|
407
|
-
registerBuilderComponent(type, meta, serializedControls),
|
|
408
|
-
transferables
|
|
409
|
-
);
|
|
411
|
+
case ActionTypes.REGISTER_BUILDER_COMPONENT: {
|
|
412
|
+
const { transferables, ...forwardedAction } = action;
|
|
413
|
+
channel.postMessage(forwardedAction, transferables);
|
|
410
414
|
break;
|
|
411
415
|
}
|
|
412
|
-
case ActionTypes.
|
|
413
|
-
channel.postMessage(
|
|
416
|
+
case ActionTypes.UNREGISTER_BUILDER_COMPONENT:
|
|
417
|
+
channel.postMessage(action);
|
|
414
418
|
break;
|
|
415
419
|
case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP:
|
|
416
420
|
window.document.documentElement.scrollTop = action.payload.scrollTop;
|
|
@@ -502,6 +506,43 @@ function propControllerHandlesMiddleware() {
|
|
|
502
506
|
};
|
|
503
507
|
};
|
|
504
508
|
}
|
|
509
|
+
function elementTreeMiddleware() {
|
|
510
|
+
return ({ dispatch, getState }) => (next) => {
|
|
511
|
+
return (action) => {
|
|
512
|
+
switch (action.type) {
|
|
513
|
+
case ActionTypes.REGISTER_DOCUMENT:
|
|
514
|
+
dispatch(
|
|
515
|
+
createElementTree({
|
|
516
|
+
document: action.payload.document,
|
|
517
|
+
descriptors: ReactPage.getPropControllerDescriptors(getState())
|
|
518
|
+
})
|
|
519
|
+
);
|
|
520
|
+
break;
|
|
521
|
+
case ActionTypes.CHANGE_DOCUMENT: {
|
|
522
|
+
const { documentKey, operation } = action.payload;
|
|
523
|
+
const oldDocument = getDocument(getState(), documentKey);
|
|
524
|
+
const result = next(action);
|
|
525
|
+
const newDocument = getDocument(getState(), documentKey);
|
|
526
|
+
if (oldDocument != null && newDocument != null && newDocument !== oldDocument) {
|
|
527
|
+
dispatch(
|
|
528
|
+
changeElementTree({
|
|
529
|
+
oldDocument,
|
|
530
|
+
newDocument,
|
|
531
|
+
descriptors: ReactPage.getPropControllerDescriptors(getState()),
|
|
532
|
+
operation
|
|
533
|
+
})
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
return result;
|
|
537
|
+
}
|
|
538
|
+
case ActionTypes.UNREGISTER_DOCUMENT:
|
|
539
|
+
dispatch(deleteElementTree(action.payload));
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
return next(action);
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
}
|
|
505
546
|
function makeswiftApiClientSyncMiddleware(client) {
|
|
506
547
|
return () => (next) => {
|
|
507
548
|
return (action) => {
|
|
@@ -560,6 +601,7 @@ function configureStore({
|
|
|
560
601
|
const initialState = {
|
|
561
602
|
...preloadedState,
|
|
562
603
|
documents: Documents.getInitialState({ rootElements }),
|
|
604
|
+
elementTrees: ElementTrees.getInitialState(rootElements, preloadedState?.propControllers),
|
|
563
605
|
isPreview: IsPreview.getInitialState(true)
|
|
564
606
|
};
|
|
565
607
|
const channel = new MessageChannel();
|
|
@@ -576,6 +618,7 @@ function configureStore({
|
|
|
576
618
|
),
|
|
577
619
|
applyMiddleware(
|
|
578
620
|
thunk,
|
|
621
|
+
elementTreeMiddleware(),
|
|
579
622
|
measureBoxModelsMiddleware(),
|
|
580
623
|
messageChannelMiddleware(client, channel),
|
|
581
624
|
propControllerHandlesMiddleware(),
|
|
@@ -588,6 +631,7 @@ function configureStore({
|
|
|
588
631
|
export {
|
|
589
632
|
configureStore,
|
|
590
633
|
createBox,
|
|
634
|
+
elementTreeMiddleware,
|
|
591
635
|
getBox,
|
|
592
636
|
initialize,
|
|
593
637
|
messageChannelMiddleware,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/react-builder-preview.ts"],"sourcesContent":["import {\n applyMiddleware,\n combineReducers,\n createStore,\n compose,\n Dispatch as ReduxDispatch,\n Middleware,\n MiddlewareAPI,\n PreloadedState,\n Store as ReduxStore,\n StoreEnhancer,\n} from 'redux'\nimport thunk, { ThunkAction, ThunkDispatch } from 'redux-thunk'\nimport { ControlInstance } from '@makeswift/controls'\n\nimport deepEqual from '../utils/deepEqual'\n\nimport * as Documents from './modules/read-write-documents'\nimport * as ReactComponents from './modules/react-components'\nimport * as BoxModels from './modules/box-models'\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 Pointer from './modules/pointer'\nimport * as ElementImperativeHandles from './modules/element-imperative-handles'\nimport * as Breakpoints from './modules/breakpoints'\nimport * as ReactPage from './react-page'\nimport {\n Action,\n changeDocumentElementSize,\n changeElementBoxModels,\n elementFromPointChange,\n handleWheel,\n handlePointerMove,\n messageBuilderPropController,\n registerBuilderComponent,\n registerComponent,\n registerMeasurable,\n registerPropControllers,\n registerPropControllersHandle,\n setBreakpoints,\n setIsInBuilder,\n unregisterBuilderComponent,\n unregisterComponent,\n unregisterMeasurable,\n unregisterPropControllers,\n registerBuilderDocument,\n} from './actions'\nimport { ActionTypes } from './actions'\nimport { createPropController } from '../prop-controllers/instances'\nimport { serializeControls } from '../builder'\nimport { MakeswiftHostApiClient } from '../api/react'\nimport { ElementImperativeHandle } from '../runtimes/react/element-imperative-handle'\n\nexport type { Operation } from './modules/read-write-documents'\nexport type { BoxModelHandle } from './modules/box-models'\nexport { createBox, getBox, parse } from './modules/box-models'\n\nexport const reducer = combineReducers({\n documents: Documents.reducer,\n reactComponents: ReactComponents.reducer,\n boxModels: BoxModels.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 pointer: Pointer.reducer,\n elementImperativeHandles: ElementImperativeHandles.reducer,\n breakpoints: Breakpoints.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\n\nfunction getDocumentsStateSlice(state: State): Documents.State {\n return state.documents\n}\n\nfunction getBoxModelsStateSlice(state: State): BoxModels.State {\n return state.boxModels\n}\n\nfunction getMeasurables(state: State): Map<string, Map<string, BoxModels.Measurable>> {\n return BoxModels.getMeasurables(getBoxModelsStateSlice(state))\n}\n\nfunction getBoxModels(state: State): Map<string, Map<string, BoxModels.BoxModel>> {\n return BoxModels.getBoxModels(getBoxModelsStateSlice(state))\n}\n\nfunction getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModels.BoxModel | null {\n return BoxModels.getBoxModel(getBoxModelsStateSlice(state), documentKey, elementKey)\n}\n\nfunction getComponentsMetaStateSlice(state: State): ComponentsMeta.State {\n return state.componentsMeta\n}\n\nfunction getComponentsMeta(state: State): Map<string, ComponentsMeta.ComponentMeta> {\n return ComponentsMeta.getComponentsMeta(getComponentsMetaStateSlice(state))\n}\n\nfunction getPropControllersStateSlice(state: State): PropControllers.State {\n return state.propControllers\n}\n\nfunction getComponentPropControllerDescriptors(\n state: State,\n componentType: string,\n): Record<string, PropControllers.PropControllerDescriptor> | 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\nfunction getPointer(state: State): Pointer.Point | null {\n return Pointer.getPointer(state.pointer)\n}\n\nfunction getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return ElementImperativeHandles.getElementImperativeHandles(state.elementImperativeHandles)\n}\n\nfunction 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\nfunction measureElements(): ThunkAction<void, State, unknown, Action> {\n return (dispatch, getState) => {\n const measurables = getMeasurables(getState())\n const currentBoxModels = getBoxModels(getState())\n const measuredBoxModels = new Map<string, Map<string, BoxModels.BoxModel>>()\n\n measurables.forEach((documentMeasurables, documentKey) => {\n const measuredDocumentBoxModels = new Map<string, BoxModels.BoxModel>()\n\n documentMeasurables.forEach((measurable, elementKey) => {\n const boxModel = BoxModels.measure(measurable)\n\n if (boxModel != null) measuredDocumentBoxModels.set(elementKey, boxModel)\n })\n\n if (measuredDocumentBoxModels.size > 0) {\n measuredBoxModels.set(documentKey, measuredDocumentBoxModels)\n }\n })\n\n const changedBoxModels = new Map<string, Map<string, BoxModels.BoxModel | null>>()\n\n currentBoxModels.forEach((currentDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxModel | null>()\n\n currentDocumentBoxModels.forEach((_boxModel, elementKey) => {\n if (!measuredBoxModels.get(documentKey)?.has(elementKey)) {\n changedDocumentBoxModels.set(elementKey, null)\n }\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n })\n\n measuredBoxModels.forEach((measuredDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxModel | null>()\n\n measuredDocumentBoxModels.forEach((measuredBoxModel, elementKey) => {\n const currentBoxModel = getBoxModel(getState(), documentKey, elementKey)\n\n if (currentBoxModel == null || !deepEqual(currentBoxModel, measuredBoxModel)) {\n changedDocumentBoxModels.set(elementKey, measuredBoxModel)\n }\n })\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n\n if (changedBoxModels.size > 0) dispatch(changeElementBoxModels(changedBoxModels))\n }\n}\n\nexport function startMeasuringElements(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n dispatch(measureElements())\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nexport type Size = {\n offsetWidth: number\n offsetHeight: number\n clientWidth: number\n clientHeight: number\n scrollWidth: number\n scrollHeight: number\n scrollTop: number\n scrollLeft: number\n}\n\nfunction getElementSize(element: HTMLElement): Size {\n return {\n offsetWidth: element.offsetWidth,\n offsetHeight: element.offsetHeight,\n clientWidth: element.clientWidth,\n clientHeight: element.clientHeight,\n scrollWidth: element.scrollWidth,\n scrollHeight: element.scrollHeight,\n scrollTop: element.scrollTop,\n scrollLeft: element.scrollLeft,\n }\n}\n\nfunction lockDocumentScroll(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n const lastDocumentOverflow = window.document.documentElement.style.overflow\n window.document.documentElement.style.overflow = 'hidden'\n\n window.document.documentElement.addEventListener('wheel', handleWheelEvent)\n\n return () => {\n window.document.documentElement.style.overflow = lastDocumentOverflow\n window.document.documentElement.removeEventListener('wheel', handleWheelEvent)\n }\n\n function handleWheelEvent({ deltaX, deltaY }: WheelEvent) {\n dispatch(handleWheel({ deltaX, deltaY }))\n }\n }\n}\n\nfunction startHandlingPointerMoveEvent(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n window.document.documentElement.addEventListener('pointermove', handlePointerMoveEvent)\n\n return () => {\n window.document.documentElement.removeEventListener('pointermove', handlePointerMoveEvent)\n }\n\n function handlePointerMoveEvent({ clientX, clientY }: PointerEvent) {\n dispatch(handlePointerMove({ clientX, clientY }))\n }\n }\n}\n\nfunction startHandlingFocusEvents(): ThunkAction<() => void, State, unknown, Action> {\n return (_dispatch, getState) => {\n window.addEventListener('focusin', handleFocusIn)\n window.addEventListener('focusout', handleFocusOut)\n\n return () => {\n window.removeEventListener('focusin', handleFocusIn)\n window.removeEventListener('focusout', handleFocusOut)\n }\n\n function handleFocusIn(event: FocusEvent) {\n if (ReactPage.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT) {\n return\n }\n\n if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {\n window.parent.focus()\n }\n }\n\n function handleFocusOut(event: FocusEvent) {\n if (ReactPage.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT) {\n return\n }\n\n if (\n !(event.relatedTarget instanceof window.HTMLElement) ||\n !event.relatedTarget.isContentEditable\n ) {\n window.parent.focus()\n }\n }\n }\n}\n\nfunction startMeasuringDocumentElement(): ThunkAction<() => void, unknown, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n let lastSize: Size\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n const nextSize = getElementSize(window.document.documentElement)\n\n if (!deepEqual(lastSize, nextSize)) {\n lastSize = nextSize\n\n dispatch(changeDocumentElementSize(nextSize))\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction elementKeysFromElementFromPoint(\n elementFromPoint: Element | null,\n): ThunkAction<{ documentKey: string; elementKey: string } | null, State, unknown, Action> {\n return (_dispatch, getState) => {\n if (elementFromPoint == null) return null\n\n const elementImperativeHandles = getElementImperativeHandlesContainingElement(\n getState(),\n elementFromPoint,\n )\n const acendingDepthDocumentKeys = ReactPage.getDocumentKeysSortedByDepth(getState())\n const descendingDepthDocumentKeys = acendingDepthDocumentKeys.slice().reverse()\n\n let currentElement: Element | null = elementFromPoint\n let keys = null\n\n while (currentElement != null) {\n for (const documentKey of descendingDepthDocumentKeys) {\n const byElementKey = elementImperativeHandles.get(documentKey)\n\n if (byElementKey == null) continue\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n if (elementImperativeHandle.getDomNode() === currentElement) {\n return { documentKey, elementKey }\n }\n }\n }\n\n currentElement = currentElement.parentElement\n }\n\n return keys\n }\n}\n\nfunction startPollingElementFromPoint(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n let lastElementFromPoint: Element | null = null\n let animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameRequestId)\n }\n\n function handleAnimationFrameRequest() {\n const pointer = getPointer(getState())\n const elementFromPoint =\n pointer == null ? null : document.elementFromPoint(pointer.x, pointer.y)\n\n if (elementFromPoint !== lastElementFromPoint) {\n lastElementFromPoint = elementFromPoint\n\n const keys = dispatch(elementKeysFromElementFromPoint(elementFromPoint))\n\n dispatch(elementFromPointChange(keys))\n }\n\n animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction registerBuilderComponents(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const state = getState()\n const componentsMeta = getComponentsMeta(state)\n\n componentsMeta.forEach((meta, type) => {\n const propControllerDescriptors = getComponentPropControllerDescriptors(state, type)\n if (propControllerDescriptors != null) {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n }\n })\n\n return () => {\n componentsMeta.forEach((_, componentType) => {\n dispatch(unregisterComponent(componentType))\n })\n }\n }\n}\n\nfunction registerBuilderDocuments(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const documents = Documents.getDocuments(getDocumentsStateSlice(getState()))\n\n documents.forEach(document => {\n dispatch(registerBuilderDocument(document))\n })\n\n return () => {\n documents.forEach((_document, documentKey) => {\n dispatch(unregisterBuilderComponent(documentKey))\n })\n }\n }\n}\n\nexport interface IMessageChannel {\n postMessage(message: any, transferables?: Transferable[]): void\n dispatchBuffered(): void\n}\n\nexport function initialize(\n channel: IMessageChannel,\n): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const unregisterBuilderDocuments = dispatch(registerBuilderDocuments())\n const stopMeasuringElements = dispatch(startMeasuringElements())\n const stopMeasuringDocumentElement = dispatch(startMeasuringDocumentElement())\n const stopHandlingFocusEvent = dispatch(startHandlingFocusEvents())\n const unlockDocumentScroll = dispatch(lockDocumentScroll())\n const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent())\n const stopPollingElementFromPoint = dispatch(startPollingElementFromPoint())\n const unregisterBuilderComponents = dispatch(registerBuilderComponents())\n\n const breakpoints = ReactPage.getBreakpoints(getState())\n dispatch(setBreakpoints(breakpoints))\n dispatch(setIsInBuilder(true))\n channel.dispatchBuffered()\n\n return () => {\n unregisterBuilderDocuments()\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n stopPollingElementFromPoint()\n unregisterBuilderComponents()\n dispatch(setIsInBuilder(false))\n }\n }\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nfunction measureBoxModelsMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch }: MiddlewareAPI<Dispatch>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE: {\n if (BoxModels.isMeasurable(action.payload.componentHandle)) {\n dispatch(\n registerMeasurable(\n action.payload.documentKey,\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n }\n\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE:\n dispatch(unregisterMeasurable(action.payload.documentKey, action.payload.elementKey))\n break\n }\n\n return next(action)\n }\n }\n}\n\nexport function messageChannelMiddleware(\n client: MakeswiftHostApiClient,\n channel: IMessageChannel,\n): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n if (typeof window === 'undefined') return () => {}\n\n let cleanUp = () => {}\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.CHANGE_ELEMENT_BOX_MODELS:\n case ActionTypes.MOUNT_COMPONENT:\n case ActionTypes.UNMOUNT_COMPONENT:\n case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE:\n case ActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER:\n case ActionTypes.HANDLE_WHEEL:\n case ActionTypes.HANDLE_POINTER_MOVE:\n case ActionTypes.ELEMENT_FROM_POINT_CHANGE:\n case ActionTypes.SET_LOCALE:\n case ActionTypes.SET_BREAKPOINTS:\n case ActionTypes.REGISTER_BUILDER_DOCUMENT:\n case ActionTypes.UNREGISTER_BUILDER_DOCUMENT:\n channel.postMessage(action)\n break\n\n case ActionTypes.REGISTER_COMPONENT: {\n const { type, meta, propControllerDescriptors } = action.payload\n const [serializedControls, transferables] = serializeControls(propControllerDescriptors)\n\n channel.postMessage(\n registerBuilderComponent(type, meta, serializedControls),\n transferables,\n )\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT:\n channel.postMessage(unregisterBuilderComponent(action.payload.type))\n break\n\n case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP:\n window.document.documentElement.scrollTop = action.payload.scrollTop\n break\n\n case ActionTypes.SCROLL_DOCUMENT_ELEMENT:\n window.document.documentElement.scrollTop += action.payload.scrollTopDelta\n break\n\n case ActionTypes.SET_BUILDER_EDIT_MODE:\n channel.postMessage(action)\n window.getSelection()?.removeAllRanges()\n break\n\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n client.setLocalizedResourceId(action.payload)\n break\n }\n\n case ActionTypes.INIT:\n // dispatched by the parent window after establishing the connection\n cleanUp = dispatch(initialize(channel))\n break\n\n case ActionTypes.CLEAN_UP:\n // dispatched by the parent window on disconnect\n cleanUp()\n break\n }\n\n return next(action)\n }\n }\n}\n\nfunction createAndRegisterPropControllers(\n documentKey: string,\n elementKey: string,\n): ThunkAction<Record<string, ControlInstance> | null, State, unknown, Action> {\n return (dispatch, getState) => {\n const descriptors = ReactPage.getElementPropControllerDescriptors(\n getState(),\n documentKey,\n elementKey,\n )\n\n if (descriptors == null) return null\n\n const propControllers = Object.entries(descriptors).reduce(\n (acc, [propName, descriptor]) => {\n const propController = createPropController(descriptor, message =>\n dispatch(messageBuilderPropController(documentKey, elementKey, propName, message)),\n ) as ControlInstance\n\n return { ...acc, [propName]: propController }\n },\n {} as Record<string, ControlInstance>,\n )\n\n dispatch(registerPropControllers(documentKey, elementKey, propControllers))\n\n return propControllers\n }\n}\n\nexport function propControllerHandlesMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch, getState }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey, componentHandle } = action.payload\n const element = ReactPage.getElement(getState(), documentKey, elementKey)\n const propControllers = dispatch(\n createAndRegisterPropControllers(documentKey, elementKey),\n )\n\n if (\n element != null &&\n !ReactPage.isElementReference(element) &&\n PropControllerHandles.isPropControllersHandle(componentHandle)\n ) {\n dispatch(registerPropControllersHandle(documentKey, elementKey, componentHandle))\n componentHandle.setPropControllers(propControllers)\n }\n\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey } = action.payload\n const handle = PropControllerHandles.getPropControllersHandle(\n getPropControllerHandlesStateSlice(getState()),\n documentKey,\n elementKey,\n )\n\n handle?.setPropControllers(null)\n\n dispatch(unregisterPropControllers(documentKey, elementKey))\n\n break\n }\n\n case ActionTypes.MESSAGE_HOST_PROP_CONTROLLER: {\n const propController = PropControllerHandles.getPropController(\n getPropControllerHandlesStateSlice(getState()),\n action.payload.documentKey,\n action.payload.elementKey,\n action.payload.propName,\n )\n\n if (propController) propController.recv(action.payload.message)\n }\n }\n\n return next(action)\n }\n }\n}\n\nfunction makeswiftApiClientSyncMiddleware(\n client: MakeswiftHostApiClient,\n): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n client.makeswiftApiClient.dispatch(action)\n\n return next(action)\n }\n }\n}\n\nclass MessageChannel {\n private channel: MessagePort | null = null\n private bufferedMessages: [Action, Transferable[]?][] = []\n\n public postMessage(message: any, transferables?: Transferable[]) {\n if (this.channel) {\n this.channel.postMessage(message, transferables ?? [])\n } else {\n this.bufferedMessages.push([message, transferables])\n }\n }\n\n public setup(onMessage: (event: MessageEvent<Action>) => void) {\n const channel = new window.MessageChannel()\n channel.port1.onmessage = onMessage\n\n // connect channel to the parent window, see\n // https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API\n window.parent.postMessage(channel.port2, '*', [channel.port2])\n\n this.channel = channel.port1\n }\n\n public dispatchBuffered() {\n console.assert(this.channel != null, 'channel is not setup')\n\n this.bufferedMessages.forEach(([message, transferables]) => {\n this.channel?.postMessage(message, transferables ?? [])\n })\n\n this.bufferedMessages = []\n }\n\n public teardown() {\n if (this.channel) {\n this.channel.onmessage = null\n this.channel.close()\n }\n }\n}\n\nfunction setupMessageChannel(channel: MessageChannel): ThunkAction<void, State, unknown, Action> {\n return dispatch => {\n channel.setup((event: MessageEvent<Action>) => dispatch(event.data))\n }\n}\n\ninterface SetupTeardownMixin {\n setup: () => void\n teardown: () => void\n}\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch } & SetupTeardownMixin\n\nfunction withSetupTeardown(\n setup: () => void,\n teardown: () => void,\n): StoreEnhancer<SetupTeardownMixin> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n setup,\n teardown,\n })\n}\n\nexport function configureStore({\n rootElements,\n preloadedState,\n client,\n}: {\n rootElements?: Map<string, Documents.Element>\n preloadedState?: PreloadedState<State>\n client: MakeswiftHostApiClient\n}): Store {\n const initialState: PreloadedState<State> = {\n ...preloadedState,\n documents: Documents.getInitialState({ rootElements }),\n isPreview: IsPreview.getInitialState(true),\n }\n\n const channel = new MessageChannel()\n const store = createStore(\n reducer,\n initialState,\n compose(\n withSetupTeardown(\n () => {\n const dispatch = store.dispatch as Dispatch\n dispatch(setupMessageChannel(channel))\n },\n () => channel.teardown(),\n ),\n applyMiddleware(\n thunk,\n measureBoxModelsMiddleware(),\n messageChannelMiddleware(client, channel),\n propControllerHandlesMiddleware(),\n makeswiftApiClientSyncMiddleware(client),\n ),\n ),\n )\n\n return store\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP,OAAO,WAA2C;AAGlD,OAAO,eAAe;AAEtB,YAAY,eAAe;AAC3B,YAAY,qBAAqB;AACjC,YAAY,eAAe;AAC3B,YAAY,oBAAoB;AAChC,YAAY,qBAAqB;AACjC,YAAY,2BAA2B;AACvC,YAAY,iBAAiB;AAC7B,YAAY,eAAe;AAC3B,YAAY,qBAAqB;AACjC,YAAY,aAAa;AACzB,YAAY,8BAA8B;AAC1C,YAAY,iBAAiB;AAC7B,YAAY,eAAe;AAC3B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA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AAS,aAAa,MAAM;AAC1D,WAAK,SAAS,YAAY,SAAS,iBAAiB,CAAC,CAAC;AAAA,IACxD,CAAC;AAED,SAAK,mBAAmB,CAAC;AAAA,EAC3B;AAAA,EAEO,WAAW;AAChB,QAAI,KAAK,SAAS;AAChB,WAAK,QAAQ,YAAY;AACzB,WAAK,QAAQ,MAAM;AAAA,IACrB;AAAA,EACF;AACF;AAEA,SAAS,oBAAoB,SAAoE;AAC/F,SAAO,cAAY;AACjB,YAAQ,MAAM,CAAC,UAAgC,SAAS,MAAM,IAAI,CAAC;AAAA,EACrE;AACF;AASA,SAAS,kBACP,OACA,UACmC;AACnC,SAAO,UAAQ,CAACC,UAAS,oBAAqB;AAAA,IAC5C,GAAG,KAAKA,UAAS,cAAc;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACF,GAIU;AACR,QAAM,eAAsC;AAAA,IAC1C,GAAG;AAAA,IACH,WAAW,UAAU,gBAAgB,EAAE,aAAa,CAAC;AAAA,IACrD,WAAW,UAAU,gBAAgB,IAAI;AAAA,EAC3C;AAEA,QAAM,UAAU,IAAI,eAAe;AACnC,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,MACE;AAAA,QACE,MAAM;AACJ,gBAAM,WAAW,MAAM;AACvB,mBAAS,oBAAoB,OAAO,CAAC;AAAA,QACvC;AAAA,QACA,MAAM,QAAQ,SAAS;AAAA,MACzB;AAAA,MACA;AAAA,QACE;AAAA,QACA,2BAA2B;AAAA,QAC3B,yBAAyB,QAAQ,OAAO;AAAA,QACxC,gCAAgC;AAAA,QAChC,iCAAiC,MAAM;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":["document","reducer"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/react-builder-preview.ts"],"sourcesContent":["import {\n applyMiddleware,\n combineReducers,\n createStore,\n compose,\n type Dispatch as ReduxDispatch,\n type Middleware,\n type MiddlewareAPI,\n type Store as ReduxStore,\n type StoreEnhancer,\n} from 'redux'\nimport thunk, { type ThunkAction, type ThunkDispatch } from 'redux-thunk'\nimport { ControlInstance } from '@makeswift/controls'\n\nimport deepEqual from '../utils/deepEqual'\n\nimport * as Documents from './modules/read-write-documents'\nimport * as ElementTrees from './modules/element-trees'\nimport * as ReactComponents from './modules/react-components'\nimport * as BoxModels from './modules/box-models'\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 Pointer from './modules/pointer'\nimport * as ElementImperativeHandles from './modules/element-imperative-handles'\nimport * as Breakpoints from './modules/breakpoints'\nimport * as ReactPage from './react-page'\nimport {\n type Action,\n ActionTypes,\n changeDocumentElementSize,\n changeElementBoxModels,\n changeElementTree,\n elementFromPointChange,\n handleWheel,\n handlePointerMove,\n messageBuilderPropController,\n registerBuilderComponent,\n createElementTree,\n registerMeasurable,\n registerPropControllers,\n registerPropControllersHandle,\n setBreakpoints,\n setIsInBuilder,\n unregisterBuilderComponent,\n unregisterBuilderDocument,\n deleteElementTree,\n unregisterMeasurable,\n unregisterPropControllers,\n registerBuilderDocument,\n} from './actions'\n\nimport { createPropController } from '../prop-controllers/instances'\nimport { serializeControls } from '../builder'\nimport { MakeswiftHostApiClient } from '../api/react'\nimport { ElementImperativeHandle } from '../runtimes/react/element-imperative-handle'\n\nexport type { Operation } from './modules/read-write-documents'\nexport type { BoxModelHandle } from './modules/box-models'\nexport { createBox, getBox, parse } from './modules/box-models'\n\nexport const reducer = combineReducers({\n documents: Documents.reducer,\n elementTrees: ElementTrees.reducer,\n reactComponents: ReactComponents.reducer,\n boxModels: BoxModels.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 pointer: Pointer.reducer,\n elementImperativeHandles: ElementImperativeHandles.reducer,\n breakpoints: Breakpoints.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\n\nfunction getDocumentsStateSlice(state: State): Documents.State {\n return state.documents\n}\n\nfunction 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\nfunction getMeasurables(state: State): Map<string, Map<string, BoxModels.Measurable>> {\n return BoxModels.getMeasurables(getBoxModelsStateSlice(state))\n}\n\nfunction getBoxModels(state: State): Map<string, Map<string, BoxModels.BoxModel>> {\n return BoxModels.getBoxModels(getBoxModelsStateSlice(state))\n}\n\nfunction getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModels.BoxModel | null {\n return BoxModels.getBoxModel(getBoxModelsStateSlice(state), documentKey, elementKey)\n}\n\nfunction getComponentsMetaStateSlice(state: State): ComponentsMeta.State {\n return state.componentsMeta\n}\n\nfunction getComponentsMeta(state: State): Map<string, ComponentsMeta.ComponentMeta> {\n return ComponentsMeta.getComponentsMeta(getComponentsMetaStateSlice(state))\n}\n\nfunction getPropControllersStateSlice(state: State): PropControllers.State {\n return state.propControllers\n}\n\nfunction getComponentPropControllerDescriptors(\n state: State,\n componentType: string,\n): Record<string, PropControllers.PropControllerDescriptor> | 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\nfunction getPointer(state: State): Pointer.Point | null {\n return Pointer.getPointer(state.pointer)\n}\n\nfunction getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return ElementImperativeHandles.getElementImperativeHandles(state.elementImperativeHandles)\n}\n\nfunction 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\nfunction measureElements(): ThunkAction<void, State, unknown, Action> {\n return (dispatch, getState) => {\n const measurables = getMeasurables(getState())\n const currentBoxModels = getBoxModels(getState())\n const measuredBoxModels = new Map<string, Map<string, BoxModels.BoxModel>>()\n\n measurables.forEach((documentMeasurables, documentKey) => {\n const measuredDocumentBoxModels = new Map<string, BoxModels.BoxModel>()\n\n documentMeasurables.forEach((measurable, elementKey) => {\n const boxModel = BoxModels.measure(measurable)\n\n if (boxModel != null) measuredDocumentBoxModels.set(elementKey, boxModel)\n })\n\n if (measuredDocumentBoxModels.size > 0) {\n measuredBoxModels.set(documentKey, measuredDocumentBoxModels)\n }\n })\n\n const changedBoxModels = new Map<string, Map<string, BoxModels.BoxModel | null>>()\n\n currentBoxModels.forEach((currentDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxModel | null>()\n\n currentDocumentBoxModels.forEach((_boxModel, elementKey) => {\n if (!measuredBoxModels.get(documentKey)?.has(elementKey)) {\n changedDocumentBoxModels.set(elementKey, null)\n }\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n })\n\n measuredBoxModels.forEach((measuredDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxModel | null>()\n\n measuredDocumentBoxModels.forEach((measuredBoxModel, elementKey) => {\n const currentBoxModel = getBoxModel(getState(), documentKey, elementKey)\n\n if (currentBoxModel == null || !deepEqual(currentBoxModel, measuredBoxModel)) {\n changedDocumentBoxModels.set(elementKey, measuredBoxModel)\n }\n })\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n\n if (changedBoxModels.size > 0) dispatch(changeElementBoxModels(changedBoxModels))\n }\n}\n\nexport function startMeasuringElements(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n dispatch(measureElements())\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nexport type Size = {\n offsetWidth: number\n offsetHeight: number\n clientWidth: number\n clientHeight: number\n scrollWidth: number\n scrollHeight: number\n scrollTop: number\n scrollLeft: number\n}\n\nfunction getElementSize(element: HTMLElement): Size {\n return {\n offsetWidth: element.offsetWidth,\n offsetHeight: element.offsetHeight,\n clientWidth: element.clientWidth,\n clientHeight: element.clientHeight,\n scrollWidth: element.scrollWidth,\n scrollHeight: element.scrollHeight,\n scrollTop: element.scrollTop,\n scrollLeft: element.scrollLeft,\n }\n}\n\nfunction lockDocumentScroll(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n const lastDocumentOverflow = window.document.documentElement.style.overflow\n window.document.documentElement.style.overflow = 'hidden'\n\n window.document.documentElement.addEventListener('wheel', handleWheelEvent)\n\n return () => {\n window.document.documentElement.style.overflow = lastDocumentOverflow\n window.document.documentElement.removeEventListener('wheel', handleWheelEvent)\n }\n\n function handleWheelEvent({ deltaX, deltaY }: WheelEvent) {\n dispatch(handleWheel({ deltaX, deltaY }))\n }\n }\n}\n\nfunction startHandlingPointerMoveEvent(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n window.document.documentElement.addEventListener('pointermove', handlePointerMoveEvent)\n\n return () => {\n window.document.documentElement.removeEventListener('pointermove', handlePointerMoveEvent)\n }\n\n function handlePointerMoveEvent({ clientX, clientY }: PointerEvent) {\n dispatch(handlePointerMove({ clientX, clientY }))\n }\n }\n}\n\nfunction startHandlingFocusEvents(): ThunkAction<() => void, State, unknown, Action> {\n return (_dispatch, getState) => {\n window.addEventListener('focusin', handleFocusIn)\n window.addEventListener('focusout', handleFocusOut)\n\n return () => {\n window.removeEventListener('focusin', handleFocusIn)\n window.removeEventListener('focusout', handleFocusOut)\n }\n\n function handleFocusIn(event: FocusEvent) {\n if (ReactPage.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT) {\n return\n }\n\n if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {\n window.parent.focus()\n }\n }\n\n function handleFocusOut(event: FocusEvent) {\n if (ReactPage.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT) {\n return\n }\n\n if (\n !(event.relatedTarget instanceof window.HTMLElement) ||\n !event.relatedTarget.isContentEditable\n ) {\n window.parent.focus()\n }\n }\n }\n}\n\nfunction startMeasuringDocumentElement(): ThunkAction<() => void, unknown, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n let lastSize: Size\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n const nextSize = getElementSize(window.document.documentElement)\n\n if (!deepEqual(lastSize, nextSize)) {\n lastSize = nextSize\n\n dispatch(changeDocumentElementSize(nextSize))\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction elementKeysFromElementFromPoint(\n elementFromPoint: Element | null,\n): ThunkAction<{ documentKey: string; elementKey: string } | null, State, unknown, Action> {\n return (_dispatch, getState) => {\n if (elementFromPoint == null) return null\n\n const elementImperativeHandles = getElementImperativeHandlesContainingElement(\n getState(),\n elementFromPoint,\n )\n const ascendingDepthDocumentKeys = ReactPage.getDocumentKeysSortedByDepth(getState())\n const descendingDepthDocumentKeys = ascendingDepthDocumentKeys.slice().reverse()\n\n let currentElement: Element | null = elementFromPoint\n let keys = null\n\n while (currentElement != null) {\n for (const documentKey of descendingDepthDocumentKeys) {\n const byElementKey = elementImperativeHandles.get(documentKey)\n\n if (byElementKey == null) continue\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n if (elementImperativeHandle.getDomNode() === currentElement) {\n return { documentKey, elementKey }\n }\n }\n }\n\n currentElement = currentElement.parentElement\n }\n\n return keys\n }\n}\n\nfunction startPollingElementFromPoint(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n let lastElementFromPoint: Element | null = null\n let animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameRequestId)\n }\n\n function handleAnimationFrameRequest() {\n const pointer = getPointer(getState())\n const elementFromPoint =\n pointer == null ? null : document.elementFromPoint(pointer.x, pointer.y)\n\n if (elementFromPoint !== lastElementFromPoint) {\n lastElementFromPoint = elementFromPoint\n\n const keys = dispatch(elementKeysFromElementFromPoint(elementFromPoint))\n\n dispatch(elementFromPointChange(keys))\n }\n\n animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction registerBuilderComponents(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const state = getState()\n const componentsMeta = getComponentsMeta(state)\n\n componentsMeta.forEach((meta, type) => {\n const descriptors = getComponentPropControllerDescriptors(state, type)\n if (descriptors != null) {\n const [serializedControls, transferables] = serializeControls(descriptors)\n dispatch(registerBuilderComponent({ type, meta, serializedControls }, transferables))\n }\n })\n\n return () => {\n componentsMeta.forEach((_, type) => {\n dispatch(unregisterBuilderComponent({ type }))\n })\n }\n }\n}\n\nfunction registerBuilderDocuments(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const documents = Documents.getDocuments(getDocumentsStateSlice(getState()))\n\n documents.forEach(document => {\n dispatch(registerBuilderDocument(document))\n })\n\n return () => {\n documents.forEach((_document, documentKey) => {\n dispatch(unregisterBuilderDocument(documentKey))\n })\n }\n }\n}\n\nexport interface IMessageChannel {\n postMessage(message: any, transferables?: Transferable[]): void\n dispatchBuffered(): void\n}\n\nexport function initialize(\n channel: IMessageChannel,\n): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const unregisterBuilderDocuments = dispatch(registerBuilderDocuments())\n const stopMeasuringElements = dispatch(startMeasuringElements())\n const stopMeasuringDocumentElement = dispatch(startMeasuringDocumentElement())\n const stopHandlingFocusEvent = dispatch(startHandlingFocusEvents())\n const unlockDocumentScroll = dispatch(lockDocumentScroll())\n const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent())\n const stopPollingElementFromPoint = dispatch(startPollingElementFromPoint())\n const unregisterBuilderComponents = dispatch(registerBuilderComponents())\n\n const breakpoints = ReactPage.getBreakpoints(getState())\n dispatch(setBreakpoints(breakpoints))\n dispatch(setIsInBuilder(true))\n channel.dispatchBuffered()\n\n return () => {\n unregisterBuilderDocuments()\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n stopPollingElementFromPoint()\n unregisterBuilderComponents()\n dispatch(setIsInBuilder(false))\n }\n }\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nfunction measureBoxModelsMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch }: MiddlewareAPI<Dispatch>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE: {\n if (BoxModels.isMeasurable(action.payload.componentHandle)) {\n dispatch(\n registerMeasurable(\n action.payload.documentKey,\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n }\n\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE:\n dispatch(unregisterMeasurable(action.payload.documentKey, action.payload.elementKey))\n break\n }\n\n return next(action)\n }\n }\n}\n\nexport function messageChannelMiddleware(\n client: MakeswiftHostApiClient,\n channel: IMessageChannel,\n): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n if (typeof window === 'undefined') return () => {}\n\n let cleanUp = () => {}\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.CHANGE_ELEMENT_BOX_MODELS:\n case ActionTypes.MOUNT_COMPONENT:\n case ActionTypes.UNMOUNT_COMPONENT:\n case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE:\n case ActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER:\n case ActionTypes.HANDLE_WHEEL:\n case ActionTypes.HANDLE_POINTER_MOVE:\n case ActionTypes.ELEMENT_FROM_POINT_CHANGE:\n case ActionTypes.SET_LOCALE:\n case ActionTypes.SET_BREAKPOINTS:\n case ActionTypes.REGISTER_BUILDER_DOCUMENT:\n case ActionTypes.UNREGISTER_BUILDER_DOCUMENT:\n channel.postMessage(action)\n break\n\n case ActionTypes.REGISTER_BUILDER_COMPONENT: {\n const { transferables, ...forwardedAction } = action\n channel.postMessage(forwardedAction, transferables)\n break\n }\n\n case ActionTypes.UNREGISTER_BUILDER_COMPONENT:\n channel.postMessage(action)\n break\n\n case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP:\n window.document.documentElement.scrollTop = action.payload.scrollTop\n break\n\n case ActionTypes.SCROLL_DOCUMENT_ELEMENT:\n window.document.documentElement.scrollTop += action.payload.scrollTopDelta\n break\n\n case ActionTypes.SET_BUILDER_EDIT_MODE:\n channel.postMessage(action)\n window.getSelection()?.removeAllRanges()\n break\n\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n client.setLocalizedResourceId(action.payload)\n break\n }\n\n case ActionTypes.INIT:\n // dispatched by the parent window after establishing the connection\n cleanUp = dispatch(initialize(channel))\n break\n\n case ActionTypes.CLEAN_UP:\n // dispatched by the parent window on disconnect\n cleanUp()\n break\n }\n\n return next(action)\n }\n }\n}\n\nfunction createAndRegisterPropControllers(\n documentKey: string,\n elementKey: string,\n): ThunkAction<Record<string, ControlInstance> | null, State, unknown, Action> {\n return (dispatch, getState) => {\n const descriptors = ReactPage.getElementPropControllerDescriptors(\n getState(),\n documentKey,\n elementKey,\n )\n\n if (descriptors == null) return null\n\n const propControllers = Object.entries(descriptors).reduce(\n (acc, [propName, descriptor]) => {\n const propController = createPropController(descriptor, message =>\n dispatch(messageBuilderPropController(documentKey, elementKey, propName, message)),\n ) as ControlInstance\n\n return { ...acc, [propName]: propController }\n },\n {} as Record<string, ControlInstance>,\n )\n\n dispatch(registerPropControllers(documentKey, elementKey, propControllers))\n\n return propControllers\n }\n}\n\nexport function propControllerHandlesMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch, getState }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey, componentHandle } = action.payload\n const element = ReactPage.getElement(getState(), documentKey, elementKey)\n const propControllers = dispatch(\n createAndRegisterPropControllers(documentKey, elementKey),\n )\n\n if (\n element != null &&\n !ReactPage.isElementReference(element) &&\n PropControllerHandles.isPropControllersHandle(componentHandle)\n ) {\n dispatch(registerPropControllersHandle(documentKey, elementKey, componentHandle))\n componentHandle.setPropControllers(propControllers)\n }\n\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey } = action.payload\n const handle = PropControllerHandles.getPropControllersHandle(\n getPropControllerHandlesStateSlice(getState()),\n documentKey,\n elementKey,\n )\n\n handle?.setPropControllers(null)\n\n dispatch(unregisterPropControllers(documentKey, elementKey))\n\n break\n }\n\n case ActionTypes.MESSAGE_HOST_PROP_CONTROLLER: {\n const propController = PropControllerHandles.getPropController(\n getPropControllerHandlesStateSlice(getState()),\n action.payload.documentKey,\n action.payload.elementKey,\n action.payload.propName,\n )\n\n if (propController) propController.recv(action.payload.message)\n }\n }\n\n return next(action)\n }\n }\n}\n\nexport function elementTreeMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch, getState }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_DOCUMENT:\n dispatch(\n createElementTree({\n document: action.payload.document,\n descriptors: ReactPage.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: ReactPage.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\nfunction makeswiftApiClientSyncMiddleware(\n client: MakeswiftHostApiClient,\n): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n client.makeswiftApiClient.dispatch(action)\n\n return next(action)\n }\n }\n}\n\nclass MessageChannel {\n private channel: MessagePort | null = null\n private bufferedMessages: [Action, Transferable[]?][] = []\n\n public postMessage(message: any, transferables?: Transferable[]) {\n if (this.channel) {\n this.channel.postMessage(message, transferables ?? [])\n } else {\n this.bufferedMessages.push([message, transferables])\n }\n }\n\n public setup(onMessage: (event: MessageEvent<Action>) => void) {\n const channel = new window.MessageChannel()\n channel.port1.onmessage = onMessage\n\n // connect channel to the parent window, see\n // https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API\n window.parent.postMessage(channel.port2, '*', [channel.port2])\n\n this.channel = channel.port1\n }\n\n public dispatchBuffered() {\n console.assert(this.channel != null, 'channel is not setup')\n\n this.bufferedMessages.forEach(([message, transferables]) => {\n this.channel?.postMessage(message, transferables ?? [])\n })\n\n this.bufferedMessages = []\n }\n\n public teardown() {\n if (this.channel) {\n this.channel.onmessage = null\n this.channel.close()\n }\n }\n}\n\nfunction setupMessageChannel(channel: MessageChannel): ThunkAction<void, State, unknown, Action> {\n return dispatch => {\n channel.setup((event: MessageEvent<Action>) => dispatch(event.data))\n }\n}\n\ninterface SetupTeardownMixin {\n setup: () => void\n teardown: () => void\n}\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch } & SetupTeardownMixin\n\nfunction withSetupTeardown(\n setup: () => void,\n teardown: () => void,\n): StoreEnhancer<SetupTeardownMixin> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n setup,\n teardown,\n })\n}\n\nexport function configureStore({\n rootElements,\n preloadedState,\n client,\n}: {\n rootElements?: Map<string, Documents.Element>\n preloadedState?: Partial<State>\n client: MakeswiftHostApiClient\n}): Store {\n const initialState: Partial<State> = {\n ...preloadedState,\n documents: Documents.getInitialState({ rootElements }),\n elementTrees: ElementTrees.getInitialState(rootElements, preloadedState?.propControllers),\n isPreview: IsPreview.getInitialState(true),\n }\n\n const channel = new MessageChannel()\n const store = createStore(\n reducer,\n initialState,\n compose(\n withSetupTeardown(\n () => {\n const dispatch = store.dispatch as Dispatch\n dispatch(setupMessageChannel(channel))\n },\n () => channel.teardown(),\n ),\n applyMiddleware(\n thunk,\n elementTreeMiddleware(),\n measureBoxModelsMiddleware(),\n messageChannelMiddleware(client, channel),\n propControllerHandlesMiddleware(),\n makeswiftApiClientSyncMiddleware(client),\n ),\n ),\n )\n\n return store\n}\n"],"mappings":"AAAA;AAAA,E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;AAAA,QACxC,gCAAgC;AAAA,QAChC,iCAAiC,MAAM;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":["document","reducer"]}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
createStore,
|
|
4
|
-
combineReducers
|
|
5
|
-
} from "redux";
|
|
1
|
+
import { applyMiddleware, createStore, combineReducers } from "redux";
|
|
2
|
+
import { createSelector } from "reselect";
|
|
6
3
|
import thunk from "redux-thunk";
|
|
7
4
|
import {
|
|
8
5
|
createReplacementContext
|
|
9
6
|
} from "@makeswift/controls";
|
|
10
7
|
import * as Documents from "./modules/read-only-documents";
|
|
8
|
+
import * as ElementTrees from "./modules/element-trees";
|
|
11
9
|
import * as ReactComponents from "./modules/react-components";
|
|
12
10
|
import * as ComponentsMeta from "./modules/components-meta";
|
|
13
11
|
import * as PropControllers from "./modules/prop-controllers";
|
|
@@ -16,7 +14,6 @@ import * as IsInBuilder from "./modules/is-in-builder";
|
|
|
16
14
|
import * as IsPreview from "./modules/is-preview";
|
|
17
15
|
import * as BuilderEditMode from "./modules/builder-edit-mode";
|
|
18
16
|
import * as Breakpoints from "./modules/breakpoints";
|
|
19
|
-
import * as Introspection from "../prop-controllers/introspection";
|
|
20
17
|
import { copyElementReference } from "../prop-controllers/copy";
|
|
21
18
|
import {
|
|
22
19
|
copy as copyFromControl,
|
|
@@ -31,6 +28,7 @@ import {
|
|
|
31
28
|
} from "./modules/read-only-documents";
|
|
32
29
|
const reducer = combineReducers({
|
|
33
30
|
documents: Documents.reducer,
|
|
31
|
+
elementTrees: ElementTrees.reducer,
|
|
34
32
|
reactComponents: ReactComponents.reducer,
|
|
35
33
|
componentsMeta: ComponentsMeta.reducer,
|
|
36
34
|
propControllers: PropControllers.reducer,
|
|
@@ -46,6 +44,15 @@ function getDocumentsStateSlice(state) {
|
|
|
46
44
|
function getDocument(state, documentKey) {
|
|
47
45
|
return Documents.getDocument(getDocumentsStateSlice(state), documentKey);
|
|
48
46
|
}
|
|
47
|
+
function getElementTreesSlice(state) {
|
|
48
|
+
return state.elementTrees;
|
|
49
|
+
}
|
|
50
|
+
function getElements(state, documentKey) {
|
|
51
|
+
return ElementTrees.getElements(getElementTreesSlice(state), documentKey);
|
|
52
|
+
}
|
|
53
|
+
function getElementIds(state, documentKey) {
|
|
54
|
+
return ElementTrees.getElementIds(getElementTreesSlice(state), documentKey);
|
|
55
|
+
}
|
|
49
56
|
function getReactComponentsStateSlice(state) {
|
|
50
57
|
return state.reactComponents;
|
|
51
58
|
}
|
|
@@ -74,46 +81,17 @@ function getPropControllers(state, documentKey, elementKey) {
|
|
|
74
81
|
elementKey
|
|
75
82
|
);
|
|
76
83
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
while (current = remaining.pop()) {
|
|
82
|
-
elements.set(current.key, current);
|
|
83
|
-
if (Documents.isElementReference(current))
|
|
84
|
-
continue;
|
|
85
|
-
const elementDescriptors = descriptors.get(current.type);
|
|
86
|
-
if (elementDescriptors == null)
|
|
87
|
-
continue;
|
|
88
|
-
const parent = current;
|
|
89
|
-
const children = Object.entries(elementDescriptors).reduce((acc, [propName, descriptor]) => {
|
|
90
|
-
return [...acc, ...Introspection.getElementChildren(descriptor, parent.props[propName])];
|
|
91
|
-
}, []);
|
|
92
|
-
remaining.push(...children);
|
|
84
|
+
const getDocumentKeysSortedByDepth = createSelector(
|
|
85
|
+
[getDocumentsStateSlice, getElementTreesSlice],
|
|
86
|
+
(documents, elementTrees) => {
|
|
87
|
+
return [...documents.keys()].sort((a, b) => elementTrees.get(a)?.elements.has(b) ? -1 : 1);
|
|
93
88
|
}
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
function getDocumentElements(state, documentKey) {
|
|
97
|
-
const document = getDocument(state, documentKey);
|
|
98
|
-
const descriptors = getPropControllerDescriptors(state);
|
|
99
|
-
if (document == null)
|
|
100
|
-
return /* @__PURE__ */ new Map();
|
|
101
|
-
return normalizeElement(document.rootElement, descriptors);
|
|
102
|
-
}
|
|
103
|
-
function getDocumentKeysSortedByDepth(state) {
|
|
104
|
-
const documents = Documents.getDocuments(getDocumentsStateSlice(state));
|
|
105
|
-
const keys = Array.from(documents.keys());
|
|
106
|
-
if (keys.length < 2)
|
|
107
|
-
return keys;
|
|
108
|
-
const elements = /* @__PURE__ */ new Map();
|
|
109
|
-
keys.forEach((key) => {
|
|
110
|
-
elements.set(key, getDocumentElements(state, key));
|
|
111
|
-
});
|
|
112
|
-
keys.sort((a, b) => elements.get(a)?.has(b) ? -1 : 1);
|
|
113
|
-
return keys;
|
|
114
|
-
}
|
|
89
|
+
);
|
|
115
90
|
function getElement(state, documentKey, elementKey) {
|
|
116
|
-
return
|
|
91
|
+
return ElementTrees.getElement(getElementTreesSlice(state), documentKey, elementKey);
|
|
92
|
+
}
|
|
93
|
+
function getElementId(state, documentKey, elementKey) {
|
|
94
|
+
return ElementTrees.getElementId(getElementTreesSlice(state), documentKey, elementKey);
|
|
117
95
|
}
|
|
118
96
|
function getElementPropControllerDescriptors(state, documentKey, elementKey) {
|
|
119
97
|
const element = getElement(state, documentKey, elementKey);
|
|
@@ -121,23 +99,6 @@ function getElementPropControllerDescriptors(state, documentKey, elementKey) {
|
|
|
121
99
|
return null;
|
|
122
100
|
return getComponentPropControllerDescriptors(state, element.type);
|
|
123
101
|
}
|
|
124
|
-
function getElementId(state, documentKey, elementKey) {
|
|
125
|
-
const element = getElement(state, documentKey, elementKey);
|
|
126
|
-
if (element == null || Documents.isElementReference(element))
|
|
127
|
-
return null;
|
|
128
|
-
const descriptors = getComponentPropControllerDescriptors(state, element.type);
|
|
129
|
-
if (descriptors == null)
|
|
130
|
-
return null;
|
|
131
|
-
const elementId = Object.entries(descriptors).reduce(
|
|
132
|
-
(acc, [propName, descriptor]) => {
|
|
133
|
-
if (acc != null)
|
|
134
|
-
return acc;
|
|
135
|
-
return Introspection.getElementId(descriptor, element.props[propName]);
|
|
136
|
-
},
|
|
137
|
-
null
|
|
138
|
-
);
|
|
139
|
-
return elementId;
|
|
140
|
-
}
|
|
141
102
|
function copyElementTree(state, elementTree, replacementContext) {
|
|
142
103
|
function copyElementTreeNode(state2, replacementContext2) {
|
|
143
104
|
return function(node) {
|
|
@@ -160,31 +121,16 @@ function copyElementTree(state, elementTree, replacementContext) {
|
|
|
160
121
|
const copy = JSON.parse(JSON.stringify(elementTree));
|
|
161
122
|
return copyElementTreeNode(state, createReplacementContext(replacementContext))(copy);
|
|
162
123
|
}
|
|
163
|
-
function* traverseElementTree(state, elementTree) {
|
|
164
|
-
yield elementTree;
|
|
165
|
-
if (Documents.isElementReference(elementTree))
|
|
166
|
-
return;
|
|
167
|
-
const descriptors = getComponentPropControllerDescriptors(state, elementTree.type);
|
|
168
|
-
if (descriptors == null)
|
|
169
|
-
return;
|
|
170
|
-
for (const [propKey, descriptor] of Object.entries(descriptors)) {
|
|
171
|
-
const children = Introspection.getElementChildren(descriptor, elementTree.props[propKey]);
|
|
172
|
-
for (const child of children) {
|
|
173
|
-
if (!Documents.isElementReference(child))
|
|
174
|
-
yield* traverseElementTree(state, child);
|
|
175
|
-
yield child;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
124
|
function getElementTreeTranslatableData(state, elementTree) {
|
|
180
125
|
const translatableData = {};
|
|
181
|
-
|
|
126
|
+
const descriptors = getPropControllerDescriptors(state);
|
|
127
|
+
for (const element of ElementTrees.traverseElementTree(elementTree, descriptors)) {
|
|
182
128
|
if (Documents.isElementReference(element))
|
|
183
129
|
continue;
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
130
|
+
const elementPescriptors = descriptors.get(element.type);
|
|
131
|
+
if (elementPescriptors == null)
|
|
186
132
|
continue;
|
|
187
|
-
Object.entries(
|
|
133
|
+
Object.entries(elementPescriptors).forEach(([propName, descriptor]) => {
|
|
188
134
|
const translatablePropData = getTranslatableData(descriptor, element.props[propName]);
|
|
189
135
|
if (translatablePropData != null) {
|
|
190
136
|
translatableData[`${element.key}:${propName}`] = translatablePropData;
|
|
@@ -276,6 +222,7 @@ function configureStore({
|
|
|
276
222
|
{
|
|
277
223
|
...preloadedState,
|
|
278
224
|
documents: Documents.getInitialState({ rootElements }),
|
|
225
|
+
elementTrees: ElementTrees.getInitialState(rootElements, preloadedState?.propControllers),
|
|
279
226
|
breakpoints: Breakpoints.getInitialState(breakpoints ?? preloadedState?.breakpoints)
|
|
280
227
|
},
|
|
281
228
|
applyMiddleware(thunk)
|
|
@@ -293,8 +240,10 @@ export {
|
|
|
293
240
|
getDocumentKeysSortedByDepth,
|
|
294
241
|
getElement,
|
|
295
242
|
getElementId,
|
|
243
|
+
getElementIds,
|
|
296
244
|
getElementPropControllerDescriptors,
|
|
297
245
|
getElementTreeTranslatableData,
|
|
246
|
+
getElements,
|
|
298
247
|
getIsInBuilder,
|
|
299
248
|
getIsPreview,
|
|
300
249
|
getPropControllerDescriptors,
|