@makeswift/runtime 0.28.3-canary.4 → 0.28.3-canary.5
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/client.js +2 -4
- package/dist/cjs/api/client.js.map +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/client/index.js +15 -18
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js +11 -7
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-store.js +9 -2
- package/dist/cjs/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/cjs/runtimes/react/host-api-client.js +2 -2
- package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
- package/dist/cjs/runtimes/react/react-runtime-core.js +2 -2
- package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/react-runtime.js.map +1 -1
- package/dist/cjs/runtimes/react/runtime-core.js +62 -26
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-only-actions.js +1 -15
- package/dist/cjs/state/actions/internal/read-only-actions.js.map +1 -1
- package/dist/cjs/state/makeswift-api-client.js +3 -27
- package/dist/cjs/state/makeswift-api-client.js.map +1 -1
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js +3 -0
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
- package/dist/cjs/state/modules/locale.js +0 -3
- package/dist/cjs/state/modules/locale.js.map +1 -1
- package/dist/cjs/state/modules/site-version.js +0 -3
- package/dist/cjs/state/modules/site-version.js.map +1 -1
- package/dist/cjs/state/read-only-state.js +8 -1
- package/dist/cjs/state/read-only-state.js.map +1 -1
- package/dist/cjs/state/store.js +75 -48
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/cjs/unstable-framework-support/index.js.map +1 -1
- package/dist/cjs/utils/ref-counted-map.js +111 -0
- package/dist/cjs/utils/ref-counted-map.js.map +1 -0
- package/dist/esm/api/client.js +2 -4
- package/dist/esm/api/client.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/index.js +15 -18
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/esm/runtimes/react/components/RuntimeProvider.js +12 -8
- package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-store.js +8 -2
- package/dist/esm/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/esm/runtimes/react/host-api-client.js +2 -2
- package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
- package/dist/esm/runtimes/react/react-runtime-core.js +2 -2
- package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/react-runtime.js.map +1 -1
- package/dist/esm/runtimes/react/runtime-core.js +65 -30
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/state/actions/internal/read-only-actions.js +1 -13
- package/dist/esm/state/actions/internal/read-only-actions.js.map +1 -1
- package/dist/esm/state/makeswift-api-client.js +4 -28
- package/dist/esm/state/makeswift-api-client.js.map +1 -1
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js +3 -0
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
- package/dist/esm/state/modules/locale.js +0 -3
- package/dist/esm/state/modules/locale.js.map +1 -1
- package/dist/esm/state/modules/site-version.js +0 -3
- package/dist/esm/state/modules/site-version.js.map +1 -1
- package/dist/esm/state/read-only-state.js +7 -1
- package/dist/esm/state/read-only-state.js.map +1 -1
- package/dist/esm/state/store.js +74 -47
- package/dist/esm/state/store.js.map +1 -1
- package/dist/esm/unstable-framework-support/index.js.map +1 -1
- package/dist/esm/utils/ref-counted-map.js +87 -0
- package/dist/esm/utils/ref-counted-map.js.map +1 -0
- package/dist/types/api/client.d.ts +2 -2
- package/dist/types/api/client.d.ts.map +1 -1
- package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts +6 -6
- package/dist/types/api-handler/handlers/webhook/types.d.ts +20 -20
- package/dist/types/client/index.d.ts +1 -0
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-store.d.ts +29 -0
- package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
- package/dist/types/runtimes/react/react-runtime.d.ts +1 -0
- package/dist/types/runtimes/react/react-runtime.d.ts.map +1 -1
- package/dist/types/runtimes/react/runtime-core.d.ts +15 -13
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/state/__tests__/test-store.d.ts +4 -2
- package/dist/types/state/__tests__/test-store.d.ts.map +1 -1
- package/dist/types/state/actions/index.d.ts +0 -2
- package/dist/types/state/actions/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/index.d.ts +0 -2
- package/dist/types/state/actions/internal/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-only-actions.d.ts +1 -13
- package/dist/types/state/actions/internal/read-only-actions.d.ts.map +1 -1
- package/dist/types/state/makeswift-api-client.d.ts +2 -2
- package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
- package/dist/types/state/middleware/read-write/builder-api/initialize-connection.d.ts.map +1 -1
- package/dist/types/state/modules/locale.d.ts.map +1 -1
- package/dist/types/state/modules/site-version.d.ts.map +1 -1
- package/dist/types/state/read-only-state.d.ts +6 -2
- package/dist/types/state/read-only-state.d.ts.map +1 -1
- package/dist/types/state/read-write-state.d.ts +4 -2
- package/dist/types/state/read-write-state.d.ts.map +1 -1
- package/dist/types/state/store.d.ts +47 -14
- package/dist/types/state/store.d.ts.map +1 -1
- package/dist/types/unstable-framework-support/index.d.ts +1 -1
- package/dist/types/unstable-framework-support/index.d.ts.map +1 -1
- package/dist/types/utils/__tests__/ref-counted-map.test.d.ts +2 -0
- package/dist/types/utils/__tests__/ref-counted-map.test.d.ts.map +1 -0
- package/dist/types/utils/ref-counted-map.d.ts +26 -0
- package/dist/types/utils/ref-counted-map.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport * as MakeswiftApiClient from '../../state/makeswift-api-client'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport * as MakeswiftApiClient from '../../state/makeswift-api-client'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {\n configureProtoStore,\n configureReadWriteStore,\n type ProtoStore,\n type Store,\n} from '../../state/store'\n\nimport { RefCountedMap } from '../../utils/ref-counted-map'\nimport { isServer } from '../../utils/is-server'\n\nexport type StoreKey = {\n siteVersion: SiteVersion | null\n locale: string | undefined\n}\n\nconst VERSION_TAG_LIVE = 'ref:live'\n\nexport class RuntimeCore {\n // The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays\n // in the map. If an entry expires and is removed from the map before React commits, the store remains retained\n // via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of\n // reusing the existing one, reducing cache efficiency.\n private readonly activeStores = new RefCountedMap<string | null, Store>({\n unownedEntryTtlMs: 1000,\n // Checking on retain/release is sufficient on the client, and we don't need to check on get on the server\n // as the only scenario in which we add the store to the map is when the runtime is already bound to the\n // requested site version, which should be the only site version for which the store is requested\n ttlCheck: RefCountedMap.TTLCheck.ON_RETAIN | RefCountedMap.TTLCheck.ON_RELEASE,\n })\n\n readonly protoStore: ProtoStore\n readonly appOrigin: string\n readonly apiOrigin: string\n readonly requestKey: StoreKey | undefined\n readonly fetch: MakeswiftApiClient.HttpFetch\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n requestKey,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n requestKey?: StoreKey\n fetch: MakeswiftApiClient.HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n this.requestKey = requestKey\n this.fetch = fetch\n\n this.protoStore = configureProtoStore({\n name: 'Runtime proto-store',\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n getOrCreateStore({ siteVersion, locale }: StoreKey): Store {\n const key = storeCacheKey({ siteVersion, locale })\n\n const createStore = () => {\n // host API client includes an in-memory cache of the site's resources and thus also has to be versioned\n const hostApiClient = new MakeswiftHostApiClient({\n uri: new URL('graphql', this.apiOrigin).href,\n fetch: this.fetch,\n preloadedState: { siteVersion, locale },\n })\n\n // TODO: we need to decouple editability from the site version; specifically, previewing\n // a draft version of the site should not lead to switching to the read-write state\n const isReadOnly = siteVersion == null\n\n return configureReadWriteStore({\n name: `Runtime read-write store (site version: ${key})`,\n appOrigin: this.appOrigin,\n hostApiClient,\n preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale },\n })\n }\n\n // On the server, stores are ephemeral by default so SSR does not retain them in a long-lived runtime.\n // The exception is a runtime that is already bound to the requested site version & locale, where we\n // can safely reuse the store across multiple root regions and benefit from the host API client's\n // in-memory cache.\n //\n // On the client, stores are reference-counted by site version so multiple root regions can share a store\n // instance, which preserves the pre-v0.17 per-site-version store behavior without requiring a separate\n // runtime per root.\n const usePersistentStore = this.shouldUsePersistentStore(key)\n return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore()\n }\n\n retainStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to retain an ephemeral store', { key })\n return\n }\n\n this.activeStores.retain(key, store)\n }\n\n releaseStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to release an ephemeral store', { key })\n return\n }\n\n this.activeStores.release(key, store)\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.protoStore.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.protoStore.getState())\n }\n\n private shouldUsePersistentStore(key: string): boolean {\n // don't persist stores on the server unless the runtime instance is bound to a request\n // and the requested store matches the request's site version and locale\n return !isServer() || (this.requestKey !== undefined && storeCacheKey(this.requestKey) === key)\n }\n}\n\nconst storeCacheKey = ({ siteVersion, locale }: StoreKey): string =>\n `${siteVersionTag(siteVersion)}/${locale ?? 'default'}`\n\nconst siteVersionTag = (siteVersion: SiteVersion | null): string =>\n siteVersion?.version ?? VERSION_TAG_LIVE\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime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A,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
|
|
@@ -15,11 +15,7 @@ const ReadOnlyActionTypes = {
|
|
|
15
15
|
REGISTER_REACT_COMPONENT: "REGISTER_REACT_COMPONENT",
|
|
16
16
|
UNREGISTER_REACT_COMPONENT: "UNREGISTER_REACT_COMPONENT",
|
|
17
17
|
SET_IS_IN_BUILDER: "SET_IS_IN_BUILDER",
|
|
18
|
-
SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
|
|
19
|
-
SET_SITE_VERSION: "SET_SITE_VERSION",
|
|
20
|
-
// TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`
|
|
21
|
-
// (requires changes to the builder to handle null locales)
|
|
22
|
-
RESET_LOCALE_STATE: "RESET_LOCALE_STATE"
|
|
18
|
+
SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
|
|
23
19
|
};
|
|
24
20
|
function apiResourceFulfilled(resourceType, resourceId, resource, locale) {
|
|
25
21
|
return {
|
|
@@ -117,12 +113,6 @@ function setIsInBuilder(isInBuilder) {
|
|
|
117
113
|
function setIsReadOnly(isReadOnly) {
|
|
118
114
|
return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly };
|
|
119
115
|
}
|
|
120
|
-
function setSiteVersion(siteVersion) {
|
|
121
|
-
return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion };
|
|
122
|
-
}
|
|
123
|
-
function resetLocaleState() {
|
|
124
|
-
return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE };
|
|
125
|
-
}
|
|
126
116
|
export {
|
|
127
117
|
ReadOnlyActionTypes,
|
|
128
118
|
apiResourceFulfilled,
|
|
@@ -135,10 +125,8 @@ export {
|
|
|
135
125
|
registerPropControllers,
|
|
136
126
|
registerPropControllersHandle,
|
|
137
127
|
registerReactComponentEffect,
|
|
138
|
-
resetLocaleState,
|
|
139
128
|
setIsInBuilder,
|
|
140
129
|
setIsReadOnly,
|
|
141
|
-
setSiteVersion,
|
|
142
130
|
unregisterComponent,
|
|
143
131
|
unregisterPropControllers,
|
|
144
132
|
unregisterPropControllersHandle
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/state/actions/internal/read-only-actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../../api/types'\nimport { type SiteVersion } from '../../../api/site-version'\nimport { type Descriptor as PropControllerDescriptor } from '../../../prop-controllers/descriptors'\n\nimport { type ComponentMeta } from '../../modules/components-meta'\nimport { type PropControllersHandle } from '../../modules/prop-controller-handles'\nimport { type ComponentType } from '../../modules/react-components'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\n\nexport const ReadOnlyActionTypes = {\n // TODO: this one should be a read-write action and we should refuse\n // to fetch resources on the client in read-only mode\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n SET_IS_READ_ONLY: 'SET_IS_READ_ONLY',\n SET_SITE_VERSION: 'SET_SITE_VERSION',\n\n // TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`\n // (requires changes to the builder to handle null locales)\n RESET_LOCALE_STATE: 'RESET_LOCALE_STATE',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof ReadOnlyActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof ReadOnlyActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof ReadOnlyActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\nexport type RegisterComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype SetIsReadOnlyAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_READ_ONLY\n payload: boolean\n}\n\ntype SetSiteVersionAction = {\n type: typeof ReadOnlyActionTypes.SET_SITE_VERSION\n payload: SiteVersion | null\n}\n\ntype ResetLocaleStateAction = {\n type: typeof ReadOnlyActionTypes.RESET_LOCALE_STATE\n}\n\nexport type ReadOnlyAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | SetIsReadOnlyAction\n | SetSiteVersionAction\n | ResetLocaleStateAction\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: ReadOnlyActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: ReadOnlyActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: ReadOnlyActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: ReadOnlyActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function setIsReadOnly(isReadOnly: boolean): SetIsReadOnlyAction {\n return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly }\n}\n\nexport function setSiteVersion(siteVersion: SiteVersion | null): SetSiteVersionAction {\n return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion }\n}\n\nexport function resetLocaleState(): ResetLocaleStateAction {\n return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE }\n}\n"],"mappings":"AAiBO,MAAM,sBAAsB;AAAA;AAAA;AAAA,EAGjC,wBAAwB;AAAA,EAExB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EAErB,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,kCAAkC;AAAA,EAClC,oCAAoC;AAAA,EAEpC,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAE5B,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,kBAAkB;AAAA;AAAA;AAAA,EAIlB,oBAAoB;AACtB;AAsHO,SAAS,qBACd,cACA,YACA,UACA,QAC4B;AAC5B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,cAAc,YAAY,UAAU,OAAO;AAAA,EACxD;AACF;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO,EAAE,MAAM,oBAAoB,qBAAqB,QAAQ;AAClE;AAEO,SAAS,kBACd,MACA,MACA,2BACyB;AACzB,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,MAAM,MAAM,0BAA0B;AAAA,EACnD;AACF;AAEO,SAAS,oBAAoB,MAAyC;AAC3E,SAAO,EAAE,MAAM,oBAAoB,sBAAsB,SAAS,EAAE,KAAK,EAAE;AAC7E;AAEO,SAAS,wBACd,MACA,MACA,2BAC2D;AAC3D,SAAO,cAAY;AACjB,aAAS,kBAAkB,MAAM,MAA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,EAAE,KAAK,EAAE;AACnF;AAEO,SAAS,6BACd,MACA,WAC2D;AAC3D,SAAO,cAAY;AACjB,aAAS,uBAAuB,MAAM,SAAS,CAAC;AAEhD,WAAO,MAAM;AACX,eAAS,yBAAyB,IAAI,CAAC;AAAA,IACzC;AAAA,EACF;AACF;AAEO,SAAS,eAAe,aAA4C;AACzE,SAAO,EAAE,MAAM,oBAAoB,mBAAmB,SAAS,YAAY;AAC7E;AAEO,SAAS,cAAc,YAA0C;AACtE,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,WAAW;AAC3E;AAEO,SAAS,eAAe,aAAuD;AACpF,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,YAAY;AAC5E;AAEO,SAAS,mBAA2C;AACzD,SAAO,EAAE,MAAM,oBAAoB,mBAAmB;AACxD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/state/actions/internal/read-only-actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../../api/types'\nimport { type Descriptor as PropControllerDescriptor } from '../../../prop-controllers/descriptors'\n\nimport { type ComponentMeta } from '../../modules/components-meta'\nimport { type PropControllersHandle } from '../../modules/prop-controller-handles'\nimport { type ComponentType } from '../../modules/react-components'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\n\nexport const ReadOnlyActionTypes = {\n // TODO: this one should be a read-write action and we should refuse\n // to fetch resources on the client in read-only mode\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n SET_IS_READ_ONLY: 'SET_IS_READ_ONLY',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof ReadOnlyActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof ReadOnlyActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof ReadOnlyActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\nexport type RegisterComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype SetIsReadOnlyAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_READ_ONLY\n payload: boolean\n}\n\nexport type ReadOnlyAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | SetIsReadOnlyAction\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: ReadOnlyActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: ReadOnlyActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: ReadOnlyActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: ReadOnlyActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function setIsReadOnly(isReadOnly: boolean): SetIsReadOnlyAction {\n return { type: ReadOnlyActionTypes.SET_IS_READ_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e,aAA4C;AACzE,SAAO,EAAE,MAAM,oBAAoB,mBAAmB,SAAS,YAAY;AAC7E;AAEO,SAAS,cAAc,YAA0C;AACtE,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,WAAW;AAC3E;","names":[]}
|
|
@@ -8,8 +8,7 @@ import * as LocaleState from "./modules/locale";
|
|
|
8
8
|
import * as APIResources from "./modules/api-resources";
|
|
9
9
|
import * as LocalizedResourcesMap from "./modules/localized-resources-map";
|
|
10
10
|
import { ActionTypes } from "./actions";
|
|
11
|
-
import { apiResourceFulfilled
|
|
12
|
-
import { clearAPIClientCache } from "./actions/internal/read-write-actions";
|
|
11
|
+
import { apiResourceFulfilled } from "./actions/internal/read-only-actions";
|
|
13
12
|
import { setLocalizedResourceId } from "./host-api";
|
|
14
13
|
import { actionMiddleware, middlewareOptions, devToolsConfig } from "./toolkit";
|
|
15
14
|
import {
|
|
@@ -156,34 +155,11 @@ function defaultLocaleMiddleware() {
|
|
|
156
155
|
};
|
|
157
156
|
});
|
|
158
157
|
}
|
|
159
|
-
function
|
|
160
|
-
return actionMiddleware(({ getState, dispatch }) => (next) => {
|
|
161
|
-
return (action) => {
|
|
162
|
-
switch (action.type) {
|
|
163
|
-
case ReadOnlyActionTypes.SET_SITE_VERSION: {
|
|
164
|
-
const cacheVersion = SiteVersionState.getSiteVersion(getState().siteVersion);
|
|
165
|
-
if (cacheVersion?.version !== action.payload?.version) {
|
|
166
|
-
dispatch(clearAPIClientCache());
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return next(action);
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
function configureStore({ serializedState }) {
|
|
158
|
+
function configureStore({ preloadedState }) {
|
|
175
159
|
return configureReduxStore({
|
|
176
160
|
reducer,
|
|
177
|
-
preloadedState
|
|
178
|
-
|
|
179
|
-
localizedResourcesMap: LocalizedResourcesMap.getInitialState(
|
|
180
|
-
serializedState?.localizedResourcesMap
|
|
181
|
-
)
|
|
182
|
-
},
|
|
183
|
-
middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareOptions).concat(
|
|
184
|
-
defaultLocaleMiddleware(),
|
|
185
|
-
cacheVersioningMiddleware()
|
|
186
|
-
),
|
|
161
|
+
preloadedState,
|
|
162
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware()),
|
|
187
163
|
devTools: devToolsConfig({
|
|
188
164
|
name: `API client store (${(/* @__PURE__ */ new Date()).toISOString()})`,
|
|
189
165
|
actionsDenylist: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../api/site-version'\n\nimport * as SiteVersionState from './modules/site-version'\nimport * as LocaleState from './modules/locale'\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\n\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled, ReadOnlyActionTypes } from './actions/internal/read-only-actions'\nimport { clearAPIClientCache } from './actions/internal/read-write-actions'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n siteVersion: SiteVersionState.reducer,\n locale: LocaleState.reducer,\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(({ getState }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: {\n ...action.payload,\n locale: locale ?? LocaleState.getLocale(getState().locale),\n },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nfunction cacheVersioningMiddleware(): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(({ getState, dispatch }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ReadOnlyActionTypes.SET_SITE_VERSION: {\n const cacheVersion = SiteVersionState.getSiteVersion(getState().siteVersion)\n if (cacheVersion?.version !== action.payload?.version) {\n dispatch(clearAPIClientCache())\n }\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({ serializedState }: { serializedState?: SerializedState }) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(\n defaultLocaleMiddleware(),\n cacheVersioningMiddleware(),\n ),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n 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ACP,GAAG,OAAO;AAAA,cACV,QAAQ,UAAU,YAAY,UAAU,SAAS,EAAE,MAAM;AAAA,YAC3D;AAAA,UACF,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEA,SAAS,4BAAmE;AAC1E,SAAO,iBAAiB,CAAC,EAAE,UAAU,SAAS,MAAM,UAAQ;AAC1D,WAAO,CAAC,WAAmB;AACzB,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,oBAAoB,kBAAkB;AACzC,gBAAM,eAAe,iBAAiB,eAAe,SAAS,EAAE,WAAW;AAC3E,cAAI,cAAc,YAAY,OAAO,SAAS,SAAS;AACrD,qBAAS,oBAAoB,CAAC;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe,EAAE,gBAAgB,GAA0C;AACzF,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA,gBAAgB;AAAA,MACd,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE;AAAA,MACtC,wBAAwB;AAAA,MACxB,0BAA0B;AAAA,IAC5B;AAAA,IAEF,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../api/site-version'\n\nimport * as SiteVersionState from './modules/site-version'\nimport * as LocaleState from './modules/locale'\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\n\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled } from './actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n siteVersion: SiteVersionState.reducer,\n locale: LocaleState.reducer,\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(({ getState }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: {\n ...action.payload,\n locale: locale ?? LocaleState.getLocale(getState().locale),\n },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({ preloadedState }: { preloadedState: Partial<State> }) {\n return configureReduxStore({\n reducer,\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware()),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,OAKK;AAEP,SAA2B,mBAAmB,4BAA4B;AAE1E,YAAY,sBAAsB;AAClC,YAAY,iBAAiB;AAC7B,YAAY,kBAAkB;AAC9B,YAAY,2BAA2B;AAEvC,SAAsB,mBAAmB;AACzC,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AACvC,SAAS,kBAAkB,mBAAmB,sBAAsB;AAEpE;AAAA,EACE;AAAA,OAUK;AAEP,MAAM,UAAU,gBAAgB;AAAA,EAC9B,aAAa,iBAAiB;AAAA,EAC9B,QAAQ,YAAY;AAAA,EACpB,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAWD,SAAS,uBACP,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBACd,OACA,cACA,YACA,QACS;AACT,UAAQ,cAAc;AAAA,IACpB,KAAK,gBAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aACE,eAAe,QACf,aAAa,kBAAkB,MAAM,cAAc,cAAc,aAAa,MAAM;AAAA,IAGxF;AACE,aAAO,aAAa,kBAAkB,MAAM,cAAc,cAAc,YAAY,MAAM;AAA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AO,CAAC,WAAmB;AACzB,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY,2BAA2B;AAC1C,gBAAM,EAAE,OAAO,IAAI,OAAO;AAC1B,iBAAO,KAAK;AAAA,YACV,GAAG;AAAA,YACH,SAAS;AAAA,cACP,GAAG,OAAO;AAAA,cACV,QAAQ,UAAU,YAAY,UAAU,SAAS,EAAE,MAAM;AAAA,YAC3D;AAAA,UACF,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe,EAAE,eAAe,GAAuC;AACrF,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE,OAAO,wBAAwB,CAAC;AAAA,IAE1E,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -230,6 +230,9 @@ function initializeBuilderConnection(builderProxy) {
|
|
|
230
230
|
const unregisterBuilderComponents = dispatch(registerBuilderComponents());
|
|
231
231
|
const breakpoints = ReadOnlyState.getBreakpoints(getState());
|
|
232
232
|
dispatch(Builder.setBreakpoints(breakpoints));
|
|
233
|
+
const locale = ReadOnlyState.getLocale(getState());
|
|
234
|
+
if (locale != null)
|
|
235
|
+
dispatch(Builder.setLocale(new Intl.Locale(locale)));
|
|
233
236
|
dispatch(ReadOnly.setIsInBuilder(true));
|
|
234
237
|
builderProxy.dispatchBuffered();
|
|
235
238
|
return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/state/middleware/read-write/builder-api/initialize-connection.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport deepEqual from '../../../../utils/deepEqual'\n\nimport * as BoxModels from '../../../modules/read-write/box-models'\nimport * as BuilderEditMode from '../../../modules/builder-edit-mode'\n\nimport { type Action } from '../../../actions'\n\nimport * as ReadOnly from '../../../actions/internal/read-only-actions'\nimport * as Builder from '../../../builder-api/actions'\n\nimport { serializeControls } from '../../../../builder'\nimport { type BuilderAPIProxy } from '../../../builder-api/proxy'\n\nimport * as ReadOnlyState from '../../../read-only-state'\nimport {\n type State,\n getDocuments,\n getMeasurables,\n getBoxModels,\n getBoxModel,\n getElementImperativeHandlesContainingElement,\n getPointer,\n} from '../../../read-write-state'\n\nimport { type ElementSize, getElementSize } from './element-size'\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.BoxDisplayModel>>()\n\n measurables.forEach((documentMeasurables, documentKey) => {\n const measuredDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel>()\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.BoxDisplayModel | null>>()\n\n currentBoxModels.forEach((currentDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel | 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.BoxDisplayModel | 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(Builder.changeElementBoxModels(changedBoxModels))\n }\n}\n\nfunction 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\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(Builder.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(Builder.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 (\n ReadOnlyState.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT\n ) {\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 (\n ReadOnlyState.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT\n ) {\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: ElementSize\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(Builder.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 = ReadOnlyState.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(Builder.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 = ReadOnlyState.getComponentsMeta(state)\n\n componentsMeta.forEach((meta, type) => {\n const descriptors = ReadOnlyState.getComponentPropControllerDescriptors(state, type)\n if (descriptors != null) {\n const [serializedControls, transferables] = serializeControls(descriptors)\n dispatch(\n Builder.registerBuilderComponent({ type, meta, serializedControls }, transferables),\n )\n }\n })\n\n return () => {\n componentsMeta.forEach((_, type) => {\n dispatch(Builder.unregisterBuilderComponent({ type }))\n })\n }\n }\n}\n\nfunction registerBuilderDocuments(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const documents = getDocuments(getState())\n\n documents.forEach(document => {\n dispatch(Builder.registerBuilderDocument(document))\n })\n\n return () => {\n documents.forEach((_document, documentKey) => {\n dispatch(Builder.unregisterBuilderDocument(documentKey))\n })\n }\n }\n}\n\nexport function initializeBuilderConnection(\n builderProxy: BuilderAPIProxy,\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 = ReadOnlyState.getBreakpoints(getState())\n dispatch(Builder.setBreakpoints(breakpoints))\n dispatch(ReadOnly.setIsInBuilder(true))\n builderProxy.dispatchBuffered()\n\n return () => {\n unregisterBuilderDocuments()\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n stopPollingElementFromPoint()\n unregisterBuilderComponents()\n dispatch(ReadOnly.setIsInBuilder(false))\n }\n }\n}\n"],"mappings":"AAEA,OAAO,eAAe;AAEtB,YAAY,eAAe;AAC3B,YAAY,qBAAqB;AAIjC,YAAY,cAAc;AAC1B,YAAY,aAAa;AAEzB,SAAS,yBAAyB;AAGlC,YAAY,mBAAmB;AAC/B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAA2B,sBAAsB;AAEjD,SAAS,kBAA6D;AACpE,SAAO,CAAC,UAAU,aAAa;AAC7B,UAAM,cAAc,eAAe,SAAS,CAAC;AAC7C,UAAM,mBAAmB,aAAa,SAAS,CAAC;AAChD,UAAM,oBAAoB,oBAAI,IAAoD;AAElF,gBAAY,QAAQ,CAAC,qBAAqB,gBAAgB;AACxD,YAAM,4BAA4B,oBAAI,IAAuC;AAE7E,0BAAoB,QAAQ,CAAC,YAAY,eAAe;AACt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pD,CAAC;AAED,WAAO,MAAM;AACX,gBAAU,QAAQ,CAAC,WAAW,gBAAgB;AAC5C,iBAAS,QAAQ,0BAA0B,WAAW,CAAC;AAAA,MACzD,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,4BACd,cACiD;AACjD,SAAO,CAAC,UAAU,aAAa;AAC7B,UAAM,6BAA6B,SAAS,yBAAyB,CAAC;AACtE,UAAM,wBAAwB,SAAS,uBAAuB,CAAC;AAC/D,UAAM,+BAA+B,SAAS,8BAA8B,CAAC;AAC7E,UAAM,yBAAyB,SAAS,yBAAyB,CAAC;AAClE,UAAM,uBAAuB,SAAS,mBAAmB,CAAC;AAC1D,UAAM,+BAA+B,SAAS,8BAA8B,CAAC;AAC7E,UAAM,8BAA8B,SAAS,6BAA6B,CAAC;AAC3E,UAAM,8BAA8B,SAAS,0BAA0B,CAAC;AAExE,UAAM,cAAc,cAAc,eAAe,SAAS,CAAC;AAC3D,aAAS,QAAQ,eAAe,WAAW,CAAC;AAC5C,aAAS,SAAS,eAAe,IAAI,CAAC;AACtC,iBAAa,iBAAiB;AAE9B,WAAO,MAAM;AACX,iCAA2B;AAC3B,4BAAsB;AACtB,mCAA6B;AAC7B,6BAAuB;AACvB,2BAAqB;AACrB,mCAA6B;AAC7B,kCAA4B;AAC5B,kCAA4B;AAC5B,eAAS,SAAS,eAAe,KAAK,CAAC;AAAA,IACzC;AAAA,EACF;AACF;","names":["document"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/state/middleware/read-write/builder-api/initialize-connection.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport deepEqual from '../../../../utils/deepEqual'\n\nimport * as BoxModels from '../../../modules/read-write/box-models'\nimport * as BuilderEditMode from '../../../modules/builder-edit-mode'\n\nimport { type Action } from '../../../actions'\n\nimport * as ReadOnly from '../../../actions/internal/read-only-actions'\nimport * as Builder from '../../../builder-api/actions'\n\nimport { serializeControls } from '../../../../builder'\nimport { type BuilderAPIProxy } from '../../../builder-api/proxy'\n\nimport * as ReadOnlyState from '../../../read-only-state'\nimport {\n type State,\n getDocuments,\n getMeasurables,\n getBoxModels,\n getBoxModel,\n getElementImperativeHandlesContainingElement,\n getPointer,\n} from '../../../read-write-state'\n\nimport { type ElementSize, getElementSize } from './element-size'\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.BoxDisplayModel>>()\n\n measurables.forEach((documentMeasurables, documentKey) => {\n const measuredDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel>()\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.BoxDisplayModel | null>>()\n\n currentBoxModels.forEach((currentDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel | 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.BoxDisplayModel | 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(Builder.changeElementBoxModels(changedBoxModels))\n }\n}\n\nfunction 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\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(Builder.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(Builder.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 (\n ReadOnlyState.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT\n ) {\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 (\n ReadOnlyState.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT\n ) {\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: ElementSize\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(Builder.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 = ReadOnlyState.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(Builder.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 = ReadOnlyState.getComponentsMeta(state)\n\n componentsMeta.forEach((meta, type) => {\n const descriptors = ReadOnlyState.getComponentPropControllerDescriptors(state, type)\n if (descriptors != null) {\n const [serializedControls, transferables] = serializeControls(descriptors)\n dispatch(\n Builder.registerBuilderComponent({ type, meta, serializedControls }, transferables),\n )\n }\n })\n\n return () => {\n componentsMeta.forEach((_, type) => {\n dispatch(Builder.unregisterBuilderComponent({ type }))\n })\n }\n }\n}\n\nfunction registerBuilderDocuments(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const documents = getDocuments(getState())\n\n documents.forEach(document => {\n dispatch(Builder.registerBuilderDocument(document))\n })\n\n return () => {\n documents.forEach((_document, documentKey) => {\n dispatch(Builder.unregisterBuilderDocument(documentKey))\n })\n }\n }\n}\n\nexport function initializeBuilderConnection(\n builderProxy: BuilderAPIProxy,\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 = ReadOnlyState.getBreakpoints(getState())\n dispatch(Builder.setBreakpoints(breakpoints))\n\n const locale = ReadOnlyState.getLocale(getState())\n if (locale != null) dispatch(Builder.setLocale(new Intl.Locale(locale)))\n\n dispatch(ReadOnly.setIsInBuilder(true))\n builderProxy.dispatchBuffered()\n\n return () => {\n unregisterBuilderDocuments()\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n stopPollingElementFromPoint()\n unregisterBuilderComponents()\n dispatch(ReadOnly.setIsInBuilder(false))\n }\n }\n}\n"],"mappings":"AAEA,OAAO,eAAe;AAEtB,YAAY,eAAe;AAC3B,YAAY,qBAAqB;AAIjC,YAAY,cAAc;AAC1B,YAAY,aAAa;AAEzB,SAAS,yBAAyB;AAGlC,YAAY,mBAAmB;AAC/B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAA2B,sBAAsB;AAEjD,SAAS,kBAA6D;AACpE,SAAO,CAAC,UAAU,aAAa;AAC7B,UAAM,cAAc,eAAe,SAAS,CAAC;AAC7C,UAAM,mBAAmB,aAAa,SAAS,CAAC;AAChD,UAAM,oBAAoB,oBAAI,IAAoD;AAElF,gBAAY,QAAQ,CAAC,qBAAqB,gBAAgB;AACxD,YAAM,4BAA4B,oBAAI,IAAuC;AAE7E,0BAAoB,QAAQ,CAAC,YAAY,eAAe;AACtD,cAAM,WAAW,UAAU,QAAQ,UAAU;AAE7C,YAAI,YAAY;AAAM,oCAA0B,IAAI,YAAY,QAAQ;AAAA,MAC1E,CAAC;AAED,UAAI,0BAA0B,OAAO,GAAG;AACtC,0BAAkB,IAAI,aAAa,yBAAyB;AAAA,MAC9D;AAAA,IACF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UAAU,aAAa;AAC7B,UAAM,6BAA6B,SAAS,yBAAyB,CAAC;AACtE,UAAM,wBAAwB,SAAS,uBAAuB,CAAC;AAC/D,UAAM,+BAA+B,SAAS,8BAA8B,CAAC;AAC7E,UAAM,yBAAyB,SAAS,yBAAyB,CAAC;AAClE,UAAM,uBAAuB,SAAS,mBAAmB,CAAC;AAC1D,UAAM,+BAA+B,SAAS,8BAA8B,CAAC;AAC7E,UAAM,8BAA8B,SAAS,6BAA6B,CAAC;AAC3E,UAAM,8BAA8B,SAAS,0BAA0B,CAAC;AAExE,UAAM,cAAc,cAAc,eAAe,SAAS,CAAC;AAC3D,aAAS,QAAQ,eAAe,WAAW,CAAC;AAE5C,UAAM,SAAS,cAAc,UAAU,SAAS,CAAC;AACjD,QAAI,UAAU;AAAM,eAAS,QAAQ,UAAU,IAAI,KAAK,OAAO,MAAM,CAAC,CAAC;AAEvE,aAAS,SAAS,eAAe,IAAI,CAAC;AACtC,iBAAa,iBAAiB;AAE9B,WAAO,MAAM;AACX,iCAA2B;AAC3B,4BAAsB;AACtB,mCAA6B;AAC7B,6BAAuB;AACvB,2BAAqB;AACrB,mCAA6B;AAC7B,kCAA4B;AAC5B,kCAA4B;AAC5B,eAAS,SAAS,eAAe,KAAK,CAAC;AAAA,IACzC;AAAA,EACF;AACF;","names":["document"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isKnownAction } from "../actions";
|
|
2
2
|
import { SharedActionTypes } from "../shared-api";
|
|
3
|
-
import { ReadOnlyActionTypes } from "../actions/internal/read-only-actions";
|
|
4
3
|
function getInitialState(locale = null) {
|
|
5
4
|
return locale;
|
|
6
5
|
}
|
|
@@ -13,8 +12,6 @@ function reducer(state = getInitialState(), action) {
|
|
|
13
12
|
switch (action.type) {
|
|
14
13
|
case SharedActionTypes.SET_LOCALE:
|
|
15
14
|
return action.payload.locale;
|
|
16
|
-
case ReadOnlyActionTypes.RESET_LOCALE_STATE:
|
|
17
|
-
return getInitialState();
|
|
18
15
|
default:
|
|
19
16
|
return state;
|
|
20
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/locale.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { SharedActionTypes } from '../shared-api'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/locale.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { SharedActionTypes } from '../shared-api'\n\nexport type State = string | null\n\nexport function getInitialState(locale: string | null = null): State {\n return locale\n}\n\nexport function getLocale(state: State): string | null {\n return state\n}\n\nexport function reducer(state = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case SharedActionTypes.SET_LOCALE:\n return action.payload.locale\n\n default:\n return state\n }\n}\n"],"mappings":"AAAA,SAA0C,qBAAqB;AAC/D,SAAS,yBAAyB;AAI3B,SAAS,gBAAgB,SAAwB,MAAa;AACnE,SAAO;AACT;AAEO,SAAS,UAAU,OAA6B;AACrD,SAAO;AACT;AAEO,SAAS,QAAQ,QAAQ,gBAAgB,GAAG,QAAuC;AACxF,MAAI,CAAC,cAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,kBAAkB;AACrB,aAAO,OAAO,QAAQ;AAAA,IAExB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isKnownAction } from "../actions";
|
|
2
|
-
import { ReadOnlyActionTypes } from "../actions/internal/read-only-actions";
|
|
3
2
|
function getInitialState(siteVersion = null) {
|
|
4
3
|
return siteVersion;
|
|
5
4
|
}
|
|
@@ -10,8 +9,6 @@ function reducer(state = getInitialState(), action) {
|
|
|
10
9
|
if (!isKnownAction(action))
|
|
11
10
|
return state;
|
|
12
11
|
switch (action.type) {
|
|
13
|
-
case ReadOnlyActionTypes.SET_SITE_VERSION:
|
|
14
|
-
return action.payload;
|
|
15
12
|
default:
|
|
16
13
|
return state;
|
|
17
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/site-version.ts"],"sourcesContent":["import { type SiteVersion } from '../../api/site-version'\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/site-version.ts"],"sourcesContent":["import { type SiteVersion } from '../../api/site-version'\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\n\nexport type State = SiteVersion | null\n\nexport function getInitialState(siteVersion: SiteVersion | null = null): State {\n return siteVersion\n}\n\nexport function getSiteVersion(state: State): SiteVersion | null {\n return state\n}\n\nexport function reducer(state = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n default:\n return state\n }\n}\n"],"mappings":"AACA,SAA0C,qBAAqB;AAIxD,SAAS,gBAAgB,cAAkC,MAAa;AAC7E,SAAO;AACT;AAEO,SAAS,eAAe,OAAkC;AAC/D,SAAO;AACT;AAEO,SAAS,QAAQ,QAAQ,gBAAgB,GAAG,QAAuC;AACxF,MAAI,CAAC,cAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSelector } from "reselect";
|
|
2
2
|
import * as SiteVersion from "./modules/site-version";
|
|
3
|
+
import * as Locale from "./modules/locale";
|
|
3
4
|
import * as Documents from "./modules/read-only-documents";
|
|
4
5
|
import * as ElementTrees from "./modules/element-trees";
|
|
5
6
|
import * as ReactComponents from "./modules/react-components";
|
|
@@ -17,8 +18,9 @@ import {
|
|
|
17
18
|
isElementReference
|
|
18
19
|
} from "./modules/read-only-documents";
|
|
19
20
|
const reducers = {
|
|
20
|
-
isReadOnly: IsReadOnly.reducer,
|
|
21
21
|
siteVersion: SiteVersion.reducer,
|
|
22
|
+
isReadOnly: IsReadOnly.reducer,
|
|
23
|
+
locale: Locale.reducer,
|
|
22
24
|
documents: Documents.reducer,
|
|
23
25
|
elementTrees: ElementTrees.reducer,
|
|
24
26
|
reactComponents: ReactComponents.reducer,
|
|
@@ -130,6 +132,9 @@ function getBuilderEditMode(state) {
|
|
|
130
132
|
function getBreakpoints(state) {
|
|
131
133
|
return state.breakpoints;
|
|
132
134
|
}
|
|
135
|
+
function getLocale(state) {
|
|
136
|
+
return state.locale;
|
|
137
|
+
}
|
|
133
138
|
export {
|
|
134
139
|
createBaseDocument,
|
|
135
140
|
createDocumentReference,
|
|
@@ -147,6 +152,7 @@ export {
|
|
|
147
152
|
getElements,
|
|
148
153
|
getIsInBuilder,
|
|
149
154
|
getIsReadOnly,
|
|
155
|
+
getLocale,
|
|
150
156
|
getPropController,
|
|
151
157
|
getPropControllerDescriptors,
|
|
152
158
|
getPropControllers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/read-only-state.ts"],"sourcesContent":["import { type ThunkDispatch } from '@reduxjs/toolkit'\n\nimport { createSelector } from 'reselect'\n\nimport * as SiteVersion from './modules/site-version'\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 IsReadOnly from './modules/is-read-only'\nimport * as BuilderEditMode from './modules/builder-edit-mode'\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { type Action } from './actions'\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\nexport const reducers = {\n isReadOnly: IsReadOnly.reducer,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/state/read-only-state.ts"],"sourcesContent":["import { type ThunkDispatch } from '@reduxjs/toolkit'\n\nimport { createSelector } from 'reselect'\n\nimport * as SiteVersion from './modules/site-version'\nimport * as Locale from './modules/locale'\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 IsReadOnly from './modules/is-read-only'\nimport * as BuilderEditMode from './modules/builder-edit-mode'\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { type Action } from './actions'\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\nexport const reducers = {\n siteVersion: SiteVersion.reducer,\n isReadOnly: IsReadOnly.reducer,\n locale: Locale.reducer,\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 builderEditMode: BuilderEditMode.reducer,\n breakpoints: Breakpoints.reducer,\n}\n\nexport type State = {\n siteVersion: SiteVersion.State\n isReadOnly: IsReadOnly.State\n locale: Locale.State\n documents: Documents.State\n elementTrees: ElementTrees.State\n reactComponents: ReactComponents.State\n componentsMeta: ComponentsMeta.State\n propControllers: PropControllers.State\n propControllerHandles: PropControllerHandles.State\n isInBuilder: IsInBuilder.State\n builderEditMode: BuilderEditMode.State\n breakpoints: Breakpoints.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 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 getComponentsMeta(state: State): Map<string, ComponentsMeta.ComponentMeta> {\n return ComponentsMeta.getComponentsMeta(getComponentsMetaStateSlice(state))\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(\n state: State,\n { documentKey, elementKey }: { documentKey: string; elementKey: string },\n) {\n return PropControllerHandles.getPropControllers(\n getPropControllerHandlesStateSlice(state),\n documentKey,\n elementKey,\n )\n}\n\nexport function getPropControllersHandle(\n state: State,\n { documentKey, elementKey }: { documentKey: string; elementKey: string },\n) {\n return PropControllerHandles.getPropControllersHandle(\n getPropControllerHandlesStateSlice(state),\n documentKey,\n elementKey,\n )\n}\n\nexport function getPropController(\n state: State,\n {\n documentKey,\n elementKey,\n propName,\n }: { documentKey: string; elementKey: string; propName: string },\n) {\n return PropControllerHandles.getPropController(\n getPropControllerHandlesStateSlice(state),\n documentKey,\n elementKey,\n propName,\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 getIsInBuilder(state: State): boolean {\n return state.isInBuilder\n}\n\nexport function getIsReadOnly(state: State): boolean {\n return state.isReadOnly\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 getLocale(state: State): string | null {\n return state.locale\n}\n"],"mappings":"AAEA,SAAS,sBAAsB;AAE/B,YAAY,iBAAiB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