@makeswift/runtime 0.28.8-canary.16 → 0.28.8-canary.18
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/graphql-api-client.js +1 -1
- package/dist/cjs/api/rest-api-client.js +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/client/index.js +1 -1
- package/dist/cjs/prop-controllers/instances.js.map +1 -1
- package/dist/cjs/runtimes/react/components/Element.js +18 -8
- package/dist/cjs/runtimes/react/components/Element.js.map +1 -1
- package/dist/cjs/runtimes/react/components/ElementRegistration.js +28 -9
- package/dist/cjs/runtimes/react/components/ElementRegistration.js.map +1 -1
- package/dist/cjs/runtimes/react/components/control-instances-context.js +38 -0
- package/dist/cjs/runtimes/react/components/control-instances-context.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-control-instances.js +2 -13
- package/dist/cjs/runtimes/react/hooks/use-control-instances.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-disable-register-element.js +3 -3
- package/dist/cjs/runtimes/react/hooks/use-disable-register-element.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-write-action-types.js +1 -0
- package/dist/cjs/state/actions/internal/read-write-action-types.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-write-actions.js +55 -0
- package/dist/cjs/state/actions/internal/read-write-actions.js.map +1 -1
- package/dist/cjs/state/middleware/read-write/prop-controller-handles.js +0 -38
- package/dist/cjs/state/middleware/read-write/prop-controller-handles.js.map +1 -1
- package/dist/cjs/state/store.js +2 -0
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/cjs/state/unified-state.js.map +1 -1
- package/dist/cjs/testing/element-data.js +4 -4
- package/dist/cjs/testing/element-data.js.map +1 -1
- package/dist/cjs/testing/read-write-state.js +32 -0
- package/dist/cjs/testing/read-write-state.js.map +1 -0
- package/dist/esm/api/graphql-api-client.js +1 -1
- package/dist/esm/api/rest-api-client.js +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/prop-controllers/instances.js.map +1 -1
- package/dist/esm/runtimes/react/components/Element.js +18 -8
- package/dist/esm/runtimes/react/components/Element.js.map +1 -1
- package/dist/esm/runtimes/react/components/ElementRegistration.js +34 -11
- package/dist/esm/runtimes/react/components/ElementRegistration.js.map +1 -1
- package/dist/esm/runtimes/react/components/control-instances-context.js +13 -0
- package/dist/esm/runtimes/react/components/control-instances-context.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-control-instances.js +1 -12
- package/dist/esm/runtimes/react/hooks/use-control-instances.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-disable-register-element.js +2 -2
- package/dist/esm/runtimes/react/hooks/use-disable-register-element.js.map +1 -1
- package/dist/esm/state/actions/internal/read-write-action-types.js +1 -0
- package/dist/esm/state/actions/internal/read-write-action-types.js.map +1 -1
- package/dist/esm/state/actions/internal/read-write-actions.js +42 -0
- package/dist/esm/state/actions/internal/read-write-actions.js.map +1 -1
- package/dist/esm/state/middleware/read-write/prop-controller-handles.js +1 -44
- package/dist/esm/state/middleware/read-write/prop-controller-handles.js.map +1 -1
- package/dist/esm/state/store.js +2 -0
- package/dist/esm/state/store.js.map +1 -1
- package/dist/esm/state/unified-state.js.map +1 -1
- package/dist/esm/testing/element-data.js +4 -4
- package/dist/esm/testing/element-data.js.map +1 -1
- package/dist/esm/testing/read-write-state.js +8 -0
- package/dist/esm/testing/read-write-state.js.map +1 -0
- package/dist/types/controls/__tests__/slot.test.d.ts +3 -0
- package/dist/types/controls/__tests__/slot.test.d.ts.map +1 -0
- package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/prop-controllers/instances.d.ts +2 -2
- package/dist/types/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/Element.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/ElementRegistration.d.ts +3 -3
- package/dist/types/runtimes/react/components/ElementRegistration.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/__tests__/element-registration.test.d.ts +3 -0
- package/dist/types/runtimes/react/components/__tests__/element-registration.test.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/control-instances-context.d.ts +9 -0
- package/dist/types/runtimes/react/components/control-instances-context.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-control-instances.d.ts +1 -2
- package/dist/types/runtimes/react/hooks/use-control-instances.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-disable-register-element.d.ts +1 -1
- package/dist/types/runtimes/react/hooks/use-disable-register-element.d.ts.map +1 -1
- package/dist/types/slate/InlineModePlugin/index.d.ts +1 -1
- package/dist/types/state/actions/index.d.ts +1 -0
- package/dist/types/state/actions/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/action-types.d.ts +1 -0
- package/dist/types/state/actions/internal/action-types.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-write-action-types.d.ts +1 -0
- package/dist/types/state/actions/internal/read-write-action-types.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-write-actions.d.ts +15 -1
- package/dist/types/state/actions/internal/read-write-actions.d.ts.map +1 -1
- package/dist/types/state/middleware/read-write/prop-controller-handles.d.ts.map +1 -1
- package/dist/types/state/store.d.ts.map +1 -1
- package/dist/types/state/unified-state.d.ts +1 -0
- package/dist/types/state/unified-state.d.ts.map +1 -1
- package/dist/types/testing/element-data.d.ts +9 -5
- package/dist/types/testing/element-data.d.ts.map +1 -1
- package/dist/types/testing/read-write-state.d.ts +3 -0
- package/dist/types/testing/read-write-state.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n Tuple,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { ApiResourcesClient } from '../api/api-resources-client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/action-types'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\nimport { type BreakpointWatch, breakpointWatchMixin } from './mixins/breakpoint-watch'\n\nimport { type Action } from './actions'\n\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\n\nexport { type State } from './unified-state'\n\nconst configureStore = <Items extends readonly StoreEnhancer[] = []>({\n name,\n preloadedState,\n enhancers,\n middleware,\n}: {\n name: string\n preloadedState: Partial<State>\n enhancers: () => Tuple<Items>\n middleware?: () => Middleware[]\n}) => {\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n ...(middleware ? middleware() : []),\n ]),\n\n enhancers: getDefaultEnhancers => getDefaultEnhancers().concat(enhancers()),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport function configureProtoStore({\n name,\n breakpoints,\n}: {\n name: string\n breakpoints: Breakpoints.Breakpoints | undefined\n}) {\n return configureStore({\n name,\n preloadedState: {\n breakpoints: Breakpoints.getInitialState(breakpoints),\n },\n enhancers: () => new Tuple(),\n })\n}\n\nexport type ProtoStore = ReturnType<typeof configureProtoStore>\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\nexport interface ReadWriteStateMixin {\n readonly apiResourcesClient: ApiResourcesClient\n\n loadReadWriteStateIfNeeded(): Promise<() => void>\n}\n\nfunction withMixin<M extends {}>(mixin: M): StoreEnhancer<M> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n ...mixin,\n })\n}\n\nexport function configureReadWriteStore({\n name,\n appOrigin,\n apiResourcesClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n apiResourcesClient: ApiResourcesClient\n preloadedState: Partial<State>\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureStore({\n name,\n preloadedState,\n\n middleware: () => [\n makeswiftApiClientSyncMiddleware(apiResourcesClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ],\n\n enhancers: () =>\n new Tuple(\n withMixin<BreakpointWatch>(\n breakpointWatchMixin({\n dispatch: (...args: Parameters<Dispatch>) => store.dispatch(...args),\n getState: (): State => store.getState(),\n subscribe: (listener): VoidFunction => store.subscribe(listener),\n }),\n ),\n\n withMixin<ReadWriteStateMixin>({\n apiResourcesClient,\n loadReadWriteStateIfNeeded: async () => {\n const { isReadOnly } = store.getState()\n\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', { isReadOnly, refCount })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n },\n }),\n ),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureReadWriteStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAQO;AAIP,IAAAA,kBAAoE;AACpE,0BAAmC;AACnC,sBAAgC;AAEhC,kBAA6B;AAE7B,oCAA8C;AAC9C,uCAAiD;AACjD,8BAA2D;AAK3D,oBAA+B;AAU/B,MAAM,iBAAiB,CAA8C;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,QAAM,YAAQ,eAAAC,gBAAoB;AAAA,IAChC,aAAS,gCAAgB,cAAc,QAAQ;AAAA,IAC/C;AAAA,IAEA,YAAY,0BACV,qBAAqB,iCAAiB,EAAE,OAAO;AAAA,UAC7C,6DAA8B;AAAA,MAC9B,GAAI,aAAa,WAAW,IAAI,CAAC;AAAA,IACnC,CAAC;AAAA,IAEH,WAAW,yBAAuB,oBAAoB,EAAE,OAAO,UAAU,CAAC;AAAA,IAE1E,cAAU,gCAAe;AAAA,MACvB,MAAM,GAAG,IAAI,MAAK,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MAC1C,iBAAiB;AAAA,QACf,gCAAgB;AAAA,QAChB,uCAAmB;AAAA,QACnB,uCAAmB;AAAA,MACrB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;AAEO,SA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,MAAa,MAAM,SAAS;AAAA,UACtC,WAAW,CAAC,aAA2B,MAAM,UAAU,QAAQ;AAAA,QACjE,CAAC;AAAA,MACH;AAAA,MAEA,UAA+B;AAAA,QAC7B;AAAA,QACA,4BAA4B,YAAY;AACtC,gBAAM,EAAE,WAAW,IAAI,MAAM,SAAS;AAEtC,cAAI,YAAY;AACd,gBAAI,WAAW,GAAG;AAChB,sBAAQ,MAAM,6BAA6B,EAAE,YAAY,SAAS,CAAC;AAAA,YACrE;AAEA,mBAAO,MAAM;AAAA,YAAC;AAAA,UAChB;AAEA,gBAAM,mBAAmB;AACzB,sBAAY;AAEZ,cAAI,aAAa;AACjB,iBAAO,MAAM;AACX,gBAAI,YAAY;AACd;AAAA,YACF;AAEA,yBAAa;AACb,wBAAY;AACZ,gBAAI,aAAa,KAAK,oBAAoB,MAAM;AAC9C,+BAAiB;AACjB,iCAAmB;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACJ,CAAC;AAED,SAAO;AACT;","names":["import_toolkit","configureReduxStore"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n Tuple,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { ApiResourcesClient } from '../api/api-resources-client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/action-types'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\nimport { type BreakpointWatch, breakpointWatchMixin } from './mixins/breakpoint-watch'\n\nimport { flushActionBuffer } from './actions/internal/read-write-actions'\nimport { type Action } from './actions'\n\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\n\nexport { type State } from './unified-state'\n\nconst configureStore = <Items extends readonly StoreEnhancer[] = []>({\n name,\n preloadedState,\n enhancers,\n middleware,\n}: {\n name: string\n preloadedState: Partial<State>\n enhancers: () => Tuple<Items>\n middleware?: () => Middleware[]\n}) => {\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n ...(middleware ? middleware() : []),\n ]),\n\n enhancers: getDefaultEnhancers => getDefaultEnhancers().concat(enhancers()),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport function configureProtoStore({\n name,\n breakpoints,\n}: {\n name: string\n breakpoints: Breakpoints.Breakpoints | undefined\n}) {\n return configureStore({\n name,\n preloadedState: {\n breakpoints: Breakpoints.getInitialState(breakpoints),\n },\n enhancers: () => new Tuple(),\n })\n}\n\nexport type ProtoStore = ReturnType<typeof configureProtoStore>\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n // `middlewareRef` is set, but we're still somehow in a read-only state\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\nexport interface ReadWriteStateMixin {\n readonly apiResourcesClient: ApiResourcesClient\n\n loadReadWriteStateIfNeeded(): Promise<() => void>\n}\n\nfunction withMixin<M extends object>(mixin: M): StoreEnhancer<M> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n ...mixin,\n })\n}\n\nexport function configureReadWriteStore({\n name,\n appOrigin,\n apiResourcesClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n apiResourcesClient: ApiResourcesClient\n preloadedState: Partial<State>\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n // trigger a flush of buffered actions in `conditionalReadWriteMiddleware`;\n // the `dispatch(setupBuilderProxy(builderProxy))` call above is not sufficient\n // as it dispatches a thunk action, which is intercepted and handled by the\n // default thunk middleware and never reaches `conditionalReadWriteMiddleware`\n dispatch(flushActionBuffer())\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureStore({\n name,\n preloadedState,\n\n middleware: () => [\n makeswiftApiClientSyncMiddleware(apiResourcesClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ],\n\n enhancers: () =>\n new Tuple(\n withMixin<BreakpointWatch>(\n breakpointWatchMixin({\n dispatch: (...args: Parameters<Dispatch>) => store.dispatch(...args),\n getState: (): State => store.getState(),\n subscribe: (listener): VoidFunction => store.subscribe(listener),\n }),\n ),\n\n withMixin<ReadWriteStateMixin>({\n apiResourcesClient,\n loadReadWriteStateIfNeeded: async () => {\n const { isReadOnly } = store.getState()\n\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', { isReadOnly, refCount })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n },\n }),\n ),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureReadWriteStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAQO;AAIP,IAAAA,kBAAoE;AACpE,0BAAmC;AACnC,sBAAgC;AAEhC,kBAA6B;AAE7B,oCAA8C;AAC9C,uCAAiD;AACjD,8BAA2D;AAE3D,gCAAkC;AAIlC,oBAA+B;AAU/B,MAAM,iBAAiB,CAA8C;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,QAAM,YAAQ,eAAAC,gBAAoB;AAAA,IAChC,aAAS,gCAAgB,cAAc,QAAQ;AAAA,IAC/C;AAAA,IAEA,YAAY,0BACV,qBAAqB,iCAAiB,EAAE,OAAO;AAAA,UAC7C,6DAA8B;AAAA,MAC9B,GAAI,aAAa,WAAW,IAAI,CAAC;AAAA,IACnC,CAAC;AAAA,IAEH,WAAW,yBAAuB,oBAAoB,EAAE,OAAO,UAAU,CAAC;AAAA,IAE1E,cAAU,gCAAe;AAAA,MACvB,MAAM,GAAG,IAAI,MAAK,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MAC1C,iBAAiB;AAAA,QACf,gCAAgB;AAAA,QAChB,uCAAmB;AAAA,QACnB,uCAAmB;AAAA,MACrB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;AAEO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGG;AACD,SAAO,eAAe;AAAA,IACpB;AAAA,IACA,gBAAgB;A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AQ;AAAA,QACjE,CAAC;AAAA,MACH;AAAA,MAEA,UAA+B;AAAA,QAC7B;AAAA,QACA,4BAA4B,YAAY;AACtC,gBAAM,EAAE,WAAW,IAAI,MAAM,SAAS;AAEtC,cAAI,YAAY;AACd,gBAAI,WAAW,GAAG;AAChB,sBAAQ,MAAM,6BAA6B,EAAE,YAAY,SAAS,CAAC;AAAA,YACrE;AAEA,mBAAO,MAAM;AAAA,YAAC;AAAA,UAChB;AAEA,gBAAM,mBAAmB;AACzB,sBAAY;AAEZ,cAAI,aAAa;AACjB,iBAAO,MAAM;AACX,gBAAI,YAAY;AACd;AAAA,YACF;AAEA,yBAAa;AACb,wBAAY;AACZ,gBAAI,aAAa,KAAK,oBAAoB,MAAM;AAC9C,+BAAiB;AACjB,iCAAmB;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACJ,CAAC;AAED,SAAO;AACT;","names":["import_toolkit","configureReduxStore"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/unified-state.ts"],"sourcesContent":["import { type ThunkDispatch, type Reducer } from '@reduxjs/toolkit'\n\nimport { type State as ReadOnlyState } from './read-only-state'\nimport { type State as ReadWriteState } from './read-write-state'\nimport { type Action } from './actions'\n\nexport type State = ReadOnlyState | ReadWriteState\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type ReadOnlyReducer = Reducer<ReadOnlyState>\nexport type ReadWriteDispatch = ThunkDispatch<ReadWriteState, unknown, Action>\n\nexport const isReadWriteState = (state: State): state is ReadWriteState => 'boxModels' in state\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../src/state/unified-state.ts"],"sourcesContent":["import { type ThunkDispatch, type Reducer } from '@reduxjs/toolkit'\n\nimport { type State as ReadOnlyState } from './read-only-state'\nimport { type State as ReadWriteState } from './read-write-state'\nimport { type Action } from './actions'\n\nexport type State = ReadOnlyState | ReadWriteState\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type ReadOnlyReducer = Reducer<ReadOnlyState>\nexport type ReadWriteDispatch = ThunkDispatch<ReadWriteState, unknown, Action>\n\nexport { type ReadWriteState }\nexport const isReadWriteState = (state: State): state is ReadWriteState => 'boxModels' in state\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,MAAM,mBAAmB,CAAC,UAA0C,eAAe;","names":[]}
|
|
@@ -46,16 +46,16 @@ function createRootComponent(elements, rootId) {
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
const isDocument = (
|
|
50
|
-
function createMakeswiftPageSnapshot(
|
|
49
|
+
const isDocument = (elementOrDocument) => "snippets" in elementOrDocument || "fonts" in elementOrDocument || "meta" in elementOrDocument || "seo" in elementOrDocument;
|
|
50
|
+
function createMakeswiftPageSnapshot(elementOrDocument, {
|
|
51
51
|
cacheData = {},
|
|
52
52
|
locale = null
|
|
53
53
|
} = {}) {
|
|
54
54
|
return {
|
|
55
|
-
document: isDocument(
|
|
55
|
+
document: isDocument(elementOrDocument) ? elementOrDocument : {
|
|
56
56
|
id: "test-page-id",
|
|
57
57
|
site: { id: "test-site-id" },
|
|
58
|
-
data:
|
|
58
|
+
data: elementOrDocument,
|
|
59
59
|
snippets: [],
|
|
60
60
|
fonts: [],
|
|
61
61
|
meta: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/testing/element-data.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\n\nimport {\n type MakeswiftPageSnapshot,\n type MakeswiftPageDocument,\n type MakeswiftComponentSnapshot,\n} from '../client'\nimport { CacheData } from '../api/api-resources-client'\nimport { type ElementData } from '../state/read-only-state'\nimport { MakeswiftComponentType } from '../components/builtin/constants'\n\nexport function createRootComponent(elements:
|
|
1
|
+
{"version":3,"sources":["../../../src/testing/element-data.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\n\nimport {\n type MakeswiftPageSnapshot,\n type MakeswiftPageDocument,\n type MakeswiftComponentSnapshot,\n} from '../client'\nimport { CacheData } from '../api/api-resources-client'\nimport { type Element, type ElementData } from '../state/read-only-state'\nimport { MakeswiftComponentType } from '../components/builtin/constants'\n\nexport function createRootComponent(elements: Element[], rootId?: string) {\n return {\n key: rootId ?? uuid(),\n type: MakeswiftComponentType.Root,\n props: {\n children: {\n columns: [\n {\n deviceId: 'desktop',\n value: {\n count: 12,\n spans: elements?.map(() => [12]),\n },\n },\n ],\n elements,\n },\n },\n }\n}\n\nconst isDocument = (\n elementOrDocument: Element | MakeswiftPageDocument,\n): elementOrDocument is MakeswiftPageDocument =>\n 'snippets' in elementOrDocument ||\n 'fonts' in elementOrDocument ||\n 'meta' in elementOrDocument ||\n 'seo' in elementOrDocument\n\nexport function createMakeswiftPageSnapshot(\n elementOrDocument: Element | MakeswiftPageDocument,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftPageSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftPageSnapshot {\n return {\n document: isDocument(elementOrDocument)\n ? elementOrDocument\n : {\n id: 'test-page-id',\n site: { id: 'test-site-id' },\n data: elementOrDocument,\n snippets: [],\n fonts: [],\n meta: {},\n seo: {},\n localizedPages: [],\n locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n\nexport function createMakeswiftComponentSnapshot(\n elementData: ElementData | null,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftComponentSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftComponentSnapshot {\n return {\n key: uuid(),\n document: {\n id: 'test-component-id',\n name: 'Test Component Document',\n siteId: 'test-site-id',\n data: elementData,\n inheritsFromParent: false,\n locale,\n },\n meta: {\n allowLocaleFallback: false,\n requestedLocale: locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n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N,oBAAoB;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,IACnB;AAAA,IACA,WAAW;AAAA,MACT,GAAG,sCAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":["uuid"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var read_write_state_exports = {};
|
|
20
|
+
__export(read_write_state_exports, {
|
|
21
|
+
expectReadWriteState: () => expectReadWriteState
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(read_write_state_exports);
|
|
24
|
+
var import_unified_state = require("../state/unified-state");
|
|
25
|
+
function expectReadWriteState(state) {
|
|
26
|
+
expect((0, import_unified_state.isReadWriteState)(state)).toBe(true);
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
expectReadWriteState
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=read-write-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/testing/read-write-state.ts"],"sourcesContent":["import { type State, type ReadWriteState, isReadWriteState } from '../state/unified-state'\n\nexport function expectReadWriteState(state: State): asserts state is ReadWriteState {\n expect(isReadWriteState(state)).toBe(true)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAkE;AAE3D,SAAS,qBAAqB,OAA+C;AAClF,aAAO,uCAAiB,KAAK,CAAC,EAAE,KAAK,IAAI;AAC3C;","names":[]}
|
|
@@ -9,7 +9,7 @@ class MakeswiftGraphQLApiClient {
|
|
|
9
9
|
graphqlClient;
|
|
10
10
|
constructor({ endpoint }) {
|
|
11
11
|
this.graphqlClient = new GraphQLClient(endpoint, {
|
|
12
|
-
"makeswift-runtime-version": "0.28.8-canary.
|
|
12
|
+
"makeswift-runtime-version": "0.28.8-canary.18"
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
async createTableRecord(tableId, columns) {
|
|
@@ -113,7 +113,7 @@ class MakeswiftRestAPIClient {
|
|
|
113
113
|
const requestHeaders = new Headers({
|
|
114
114
|
"x-api-key": this.apiKey,
|
|
115
115
|
"makeswift-site-api-key": this.apiKey,
|
|
116
|
-
"makeswift-runtime-version": "0.28.8-canary.
|
|
116
|
+
"makeswift-runtime-version": "0.28.8-canary.18"
|
|
117
117
|
});
|
|
118
118
|
if (siteVersion?.token) {
|
|
119
119
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -8,7 +8,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
8
8
|
return ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
9
9
|
}
|
|
10
10
|
return ApiResponse.json({
|
|
11
|
-
version: "0.28.8-canary.
|
|
11
|
+
version: "0.28.8-canary.18",
|
|
12
12
|
interactionMode: true,
|
|
13
13
|
clientSideNavigation: false,
|
|
14
14
|
elementFromPoint: false,
|
package/dist/esm/client/index.js
CHANGED
|
@@ -669,7 +669,7 @@ Received "${apiKey}" instead.`
|
|
|
669
669
|
headers: {
|
|
670
670
|
"x-api-key": this.apiKey,
|
|
671
671
|
"makeswift-site-api-key": this.apiKey,
|
|
672
|
-
"makeswift-runtime-version": "0.28.8-canary.
|
|
672
|
+
"makeswift-runtime-version": "0.28.8-canary.18",
|
|
673
673
|
"content-type": "application/json"
|
|
674
674
|
},
|
|
675
675
|
body: JSON.stringify({ token }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/prop-controllers/instances.ts"],"sourcesContent":["import { type Descriptor, isLegacyDescriptor } from './descriptors'\nimport { Types as PropControllerTypes } from '@makeswift/prop-controllers'\n\nimport {\n type BoxDisplayModel,\n type ControlInstanceArgs,\n type ControlMessage,\n type InstanceType,\n ControlInstance,\n DefaultControlInstance,\n} from '@makeswift/controls'\n\nexport type PropControllerMessage = ControlMessage\n\nexport const TableFormFieldsMessageType = {\n TABLE_FORM_LAYOUT_CHANGE: 'TABLE_FORM_LAYOUT_CHANGE',\n TABLE_FORM_FIELD_LAYOUT_CHANGE: 'TABLE_FORM_FIELD_LAYOUT_CHANGE',\n} as const\n\ntype TableLayoutTableFormFieldsMessage = {\n type: typeof TableFormFieldsMessageType.TABLE_FORM_LAYOUT_CHANGE\n payload: { layout: BoxDisplayModel }\n}\n\ntype TableFieldLayoutTableFormFieldsMessage = {\n type: typeof TableFormFieldsMessageType.TABLE_FORM_FIELD_LAYOUT_CHANGE\n payload: { layout: BoxDisplayModel; index: number }\n}\n\nexport type TableFormFieldsMessage =\n | TableLayoutTableFormFieldsMessage\n | TableFieldLayoutTableFormFieldsMessage\n\nexport class TableFormFieldsPropController extends ControlInstance<TableFormFieldsMessage> {\n recv = () => {}\n\n isCompositeProp(): boolean {\n return false\n }\n\n children(): ControlInstance[] {\n return []\n }\n\n child(_key: string): ControlInstance | undefined {\n return undefined\n }\n\n resolvesToRenderableNode(): boolean {\n return false\n }\n\n tableFormLayoutChange(payload: { layout: BoxDisplayModel }) {\n this.sendMessage({ type: TableFormFieldsMessageType.TABLE_FORM_LAYOUT_CHANGE, payload })\n }\n\n tableFormFieldLayoutChange(payload: { layout: BoxDisplayModel; index: number }) {\n this.sendMessage({ type: TableFormFieldsMessageType.TABLE_FORM_FIELD_LAYOUT_CHANGE, payload })\n }\n}\n\ntype DescriptorPropController<T extends Descriptor> = T extends {\n type: typeof PropControllerTypes.TableFormFields\n}\n ? TableFormFieldsPropController\n : InstanceType<T>\n\nexport type DescriptorsPropControllers<T extends Record<string, Descriptor>> = {\n [K in keyof T]: undefined extends T[K]\n ? DescriptorPropController<Exclude<T[K], undefined>>\n : DescriptorPropController<T[K]>\n}\n\nexport type AnyPropController =
|
|
1
|
+
{"version":3,"sources":["../../../src/prop-controllers/instances.ts"],"sourcesContent":["import { type Descriptor, isLegacyDescriptor } from './descriptors'\nimport { Types as PropControllerTypes } from '@makeswift/prop-controllers'\n\nimport {\n type BoxDisplayModel,\n type ControlInstanceArgs,\n type ControlMessage,\n type InstanceType,\n type AnyControlInstance,\n ControlInstance,\n DefaultControlInstance,\n} from '@makeswift/controls'\n\nexport type PropControllerMessage = ControlMessage\n\nexport const TableFormFieldsMessageType = {\n TABLE_FORM_LAYOUT_CHANGE: 'TABLE_FORM_LAYOUT_CHANGE',\n TABLE_FORM_FIELD_LAYOUT_CHANGE: 'TABLE_FORM_FIELD_LAYOUT_CHANGE',\n} as const\n\ntype TableLayoutTableFormFieldsMessage = {\n type: typeof TableFormFieldsMessageType.TABLE_FORM_LAYOUT_CHANGE\n payload: { layout: BoxDisplayModel }\n}\n\ntype TableFieldLayoutTableFormFieldsMessage = {\n type: typeof TableFormFieldsMessageType.TABLE_FORM_FIELD_LAYOUT_CHANGE\n payload: { layout: BoxDisplayModel; index: number }\n}\n\nexport type TableFormFieldsMessage =\n | TableLayoutTableFormFieldsMessage\n | TableFieldLayoutTableFormFieldsMessage\n\nexport class TableFormFieldsPropController extends ControlInstance<TableFormFieldsMessage> {\n recv = () => {}\n\n isCompositeProp(): boolean {\n return false\n }\n\n children(): ControlInstance[] {\n return []\n }\n\n child(_key: string): ControlInstance | undefined {\n return undefined\n }\n\n resolvesToRenderableNode(): boolean {\n return false\n }\n\n tableFormLayoutChange(payload: { layout: BoxDisplayModel }) {\n this.sendMessage({ type: TableFormFieldsMessageType.TABLE_FORM_LAYOUT_CHANGE, payload })\n }\n\n tableFormFieldLayoutChange(payload: { layout: BoxDisplayModel; index: number }) {\n this.sendMessage({ type: TableFormFieldsMessageType.TABLE_FORM_FIELD_LAYOUT_CHANGE, payload })\n }\n}\n\ntype DescriptorPropController<T extends Descriptor> = T extends {\n type: typeof PropControllerTypes.TableFormFields\n}\n ? TableFormFieldsPropController\n : InstanceType<T>\n\nexport type DescriptorsPropControllers<T extends Record<string, Descriptor>> = {\n [K in keyof T]: undefined extends T[K]\n ? DescriptorPropController<Exclude<T[K], undefined>>\n : DescriptorPropController<T[K]>\n}\n\nexport type AnyPropController = AnyControlInstance | TableFormFieldsPropController\n\nexport function createPropController({\n descriptor,\n ...args\n}: {\n descriptor: Descriptor\n} & ControlInstanceArgs): AnyPropController {\n if (!isLegacyDescriptor(descriptor)) {\n return descriptor.createInstance(args)\n }\n\n switch (descriptor.type) {\n case PropControllerTypes.TableFormFields:\n return new TableFormFieldsPropController(args)\n\n default:\n return new DefaultControlInstance(args)\n }\n}\n"],"mappings":"AAAA,SAA0B,0BAA0B;AACpD,SAAS,SAAS,2BAA2B;AAE7C;AAAA,EAME;AAAA,EACA;AAAA,OACK;AAIA,MAAM,6BAA6B;AAAA,EACxC,0BAA0B;AAAA,EAC1B,gCAAgC;AAClC;AAgBO,MAAM,sCAAsC,gBAAwC;AAAA,EACzF,OAAO,MAAM;AAAA,EAAC;AAAA,EAEd,kBAA2B;AACzB,WAAO;AAAA,EACT;AAAA,EAEA,WAA8B;AAC5B,WAAO,CAAC;AAAA,EACV;AAAA,EAEA,MAAM,MAA2C;AAC/C,WAAO;AAAA,EACT;AAAA,EAEA,2BAAoC;AAClC,WAAO;AAAA,EACT;AAAA,EAEA,sBAAsB,SAAsC;AAC1D,SAAK,YAAY,EAAE,MAAM,2BAA2B,0BAA0B,QAAQ,CAAC;AAAA,EACzF;AAAA,EAEA,2BAA2B,SAAqD;AAC9E,SAAK,YAAY,EAAE,MAAM,2BAA2B,gCAAgC,QAAQ,CAAC;AAAA,EAC/F;AACF;AAgBO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA,GAAG;AACL,GAE4C;AAC1C,MAAI,CAAC,mBAAmB,UAAU,GAAG;AACnC,WAAO,WAAW,eAAe,IAAI;AAAA,EACvC;AAEA,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK,oBAAoB;AACvB,aAAO,IAAI,8BAA8B,IAAI;AAAA,IAE/C;AACE,aAAO,IAAI,uBAAuB,IAAI;AAAA,EAC1C;AACF;","names":[]}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { FallbackComponent } from "../../../components/shared/FallbackComponent";
|
|
15
15
|
import { ErrorBoundary } from "../../../components/shared/ErrorBoundary";
|
|
16
16
|
import { useIsReadOnly } from "../hooks/use-is-read-only";
|
|
17
|
+
import { useIsRegisterElementDisabled } from "../hooks/use-disable-register-element";
|
|
17
18
|
import { ElementImperativeHandle } from "../element-imperative-handle";
|
|
18
19
|
import { FindDomNode } from "../find-dom-node";
|
|
19
20
|
import { ElementReference } from "./ElementReference";
|
|
@@ -33,15 +34,24 @@ const Element = memo(
|
|
|
33
34
|
imperativeHandleRef.current.callback(() => current);
|
|
34
35
|
}, []);
|
|
35
36
|
useImperativeHandle(ref, () => imperativeHandleRef.current, []);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const isRegisterElementDisabled = useIsRegisterElementDisabled();
|
|
38
|
+
const ElementRegistration = useIsReadOnly() || isRegisterElementDisabled ? NoOp : BuilderElementRegistration;
|
|
39
|
+
return /* @__PURE__ */ jsx(
|
|
40
|
+
ElementRegistration,
|
|
39
41
|
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
componentHandle: imperativeHandleRef.current,
|
|
43
|
+
elementKey: element.key,
|
|
44
|
+
componentType: element.type,
|
|
45
|
+
children: /* @__PURE__ */ jsx(FindDomNode, { ref: findDomNodeCallbackRef, children: /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent: ErrorFallback, children: isElementReference(element) ? /* @__PURE__ */ jsx(
|
|
46
|
+
ElementReference,
|
|
47
|
+
{
|
|
48
|
+
ref: elementCallbackRef,
|
|
49
|
+
elementReference: element
|
|
50
|
+
},
|
|
51
|
+
element.key
|
|
52
|
+
) : /* @__PURE__ */ jsx(ElementData, { ref: elementCallbackRef, elementData: element }, element.key) }) })
|
|
53
|
+
}
|
|
54
|
+
);
|
|
45
55
|
})
|
|
46
56
|
);
|
|
47
57
|
function NoOp({ children }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/Element.tsx"],"sourcesContent":["'use client'\n\nimport {\n type ReactNode,\n type Ref,\n type PropsWithChildren,\n forwardRef,\n memo,\n useCallback,\n useImperativeHandle,\n useRef,\n lazy,\n} from 'react'\n\nimport {\n isElementReference,\n type Element as ElementDataOrRef,\n} from '../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../components/shared/FallbackComponent'\nimport { ErrorBoundary } from '../../../components/shared/ErrorBoundary'\n\nimport { useIsReadOnly } from '../hooks/use-is-read-only'\nimport { ElementImperativeHandle } from '../element-imperative-handle'\nimport { FindDomNode } from '../find-dom-node'\n\nimport { ElementReference } from './ElementReference'\nimport { ElementData } from './ElementData'\n\nconst BuilderElementRegistration = lazy(() => import('./ElementRegistration'))\n\ntype Props = {\n element: ElementDataOrRef\n}\n\nexport const Element = memo(\n forwardRef(function Element(\n { element }: Props,\n ref: Ref<ElementImperativeHandle>,\n ): ReactNode | null {\n const useFindDomNodeRef = useRef(true)\n const imperativeHandleRef = useRef(new ElementImperativeHandle())\n\n const findDomNodeCallbackRef = useCallback((current: (() => Element | Text | null) | null) => {\n if (useFindDomNodeRef.current === true) {\n imperativeHandleRef.current.callback(() => current?.() ?? null)\n }\n }, [])\n\n const elementCallbackRef = useCallback((current: unknown | null) => {\n useFindDomNodeRef.current = false\n\n imperativeHandleRef.current.callback(() => current)\n }, [])\n\n useImperativeHandle(ref, () => imperativeHandleRef.current, [])\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/Element.tsx"],"sourcesContent":["'use client'\n\nimport {\n type ReactNode,\n type Ref,\n type PropsWithChildren,\n forwardRef,\n memo,\n useCallback,\n useImperativeHandle,\n useRef,\n lazy,\n} from 'react'\n\nimport {\n isElementReference,\n type Element as ElementDataOrRef,\n} from '../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../components/shared/FallbackComponent'\nimport { ErrorBoundary } from '../../../components/shared/ErrorBoundary'\n\nimport { useIsReadOnly } from '../hooks/use-is-read-only'\nimport { useIsRegisterElementDisabled } from '../hooks/use-disable-register-element'\n\nimport { ElementImperativeHandle } from '../element-imperative-handle'\nimport { FindDomNode } from '../find-dom-node'\n\nimport { ElementReference } from './ElementReference'\nimport { ElementData } from './ElementData'\n\nconst BuilderElementRegistration = lazy(() => import('./ElementRegistration'))\n\ntype Props = {\n element: ElementDataOrRef\n}\n\nexport const Element = memo(\n forwardRef(function Element(\n { element }: Props,\n ref: Ref<ElementImperativeHandle>,\n ): ReactNode | null {\n const useFindDomNodeRef = useRef(true)\n const imperativeHandleRef = useRef(new ElementImperativeHandle())\n\n const findDomNodeCallbackRef = useCallback((current: (() => Element | Text | null) | null) => {\n if (useFindDomNodeRef.current === true) {\n imperativeHandleRef.current.callback(() => current?.() ?? null)\n }\n }, [])\n\n const elementCallbackRef = useCallback((current: unknown | null) => {\n useFindDomNodeRef.current = false\n\n imperativeHandleRef.current.callback(() => current)\n }, [])\n\n useImperativeHandle(ref, () => imperativeHandleRef.current, [])\n\n const isRegisterElementDisabled = useIsRegisterElementDisabled()\n const ElementRegistration =\n useIsReadOnly() || isRegisterElementDisabled ? NoOp : BuilderElementRegistration\n\n return (\n <ElementRegistration\n componentHandle={imperativeHandleRef.current}\n elementKey={element.key}\n componentType={element.type}\n >\n <FindDomNode ref={findDomNodeCallbackRef}>\n <ErrorBoundary FallbackComponent={ErrorFallback}>\n {isElementReference(element) ? (\n <ElementReference\n key={element.key}\n ref={elementCallbackRef}\n elementReference={element}\n />\n ) : (\n <ElementData key={element.key} ref={elementCallbackRef} elementData={element} />\n )}\n </ErrorBoundary>\n </FindDomNode>\n </ElementRegistration>\n )\n }),\n)\n\nfunction NoOp({ children }: PropsWithChildren) {\n return children\n}\n\nfunction ErrorFallback() {\n return <FallbackComponent text={`Error rendering component`} />\n}\n"],"mappings":";AAwEc;AAtEd;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,OAEK;AAEP,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AAC9B,SAAS,oCAAoC;AAE7C,SAAS,+BAA+B;AACxC,SAAS,mBAAmB;AAE5B,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAE5B,MAAM,6BAA6B,KAAK,MAAM,OAAO,uBAAuB,CAAC;AAMtE,MAAM,UAAU;AAAA,EACrB,WAAW,SAASA,SAClB,EAAE,QAAQ,GACV,KACkB;AAClB,UAAM,oBAAoB,OAAO,IAAI;AACrC,UAAM,sBAAsB,OAAO,IAAI,wBAAwB,CAAC;AAEhE,UAAM,yBAAyB,YAAY,CAAC,YAAkD;AAC5F,UAAI,kBAAkB,YAAY,MAAM;AACtC,4BAAoB,QAAQ,SAAS,MAAM,UAAU,KAAK,IAAI;AAAA,MAChE;AAAA,IACF,GAAG,CAAC,CAAC;AAEL,UAAM,qBAAqB,YAAY,CAAC,YAA4B;AAClE,wBAAkB,UAAU;AAE5B,0BAAoB,QAAQ,SAAS,MAAM,OAAO;AAAA,IACpD,GAAG,CAAC,CAAC;AAEL,wBAAoB,KAAK,MAAM,oBAAoB,SAAS,CAAC,CAAC;AAE9D,UAAM,4BAA4B,6BAA6B;AAC/D,UAAM,sBACJ,cAAc,KAAK,4BAA4B,OAAO;AAExD,WACE;AAAA,MAAC;AAAA;AAAA,QACC,iBAAiB,oBAAoB;AAAA,QACrC,YAAY,QAAQ;AAAA,QACpB,eAAe,QAAQ;AAAA,QAEvB,8BAAC,eAAY,KAAK,wBAChB,8BAAC,iBAAc,mBAAmB,eAC/B,6BAAmB,OAAO,IACzB;AAAA,UAAC;AAAA;AAAA,YAEC,KAAK;AAAA,YACL,kBAAkB;AAAA;AAAA,UAFb,QAAQ;AAAA,QAGf,IAEA,oBAAC,eAA8B,KAAK,oBAAoB,aAAa,WAAnD,QAAQ,GAAoD,GAElF,GACF;AAAA;AAAA,IACF;AAAA,EAEJ,CAAC;AACH;AAEA,SAAS,KAAK,EAAE,SAAS,GAAsB;AAC7C,SAAO;AACT;AAEA,SAAS,gBAAgB;AACvB,SAAO,oBAAC,qBAAkB,MAAM,6BAA6B;AAC/D;","names":["Element"]}
|
|
@@ -1,30 +1,53 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { memo, useEffect } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { memo, useMemo, useEffect } from "react";
|
|
4
|
+
import {
|
|
5
|
+
createPropControllers,
|
|
6
|
+
registerComponentHandleEffect,
|
|
7
|
+
registerPropControllersEffect
|
|
8
|
+
} from "../../../state/actions/internal/read-write-actions";
|
|
9
|
+
import { mountComponentEffect } from "../../../state/builder-api/actions";
|
|
4
10
|
import { useDispatch } from "../hooks/use-dispatch";
|
|
5
11
|
import { useDocumentKey } from "../hooks/use-document-context";
|
|
6
|
-
import {
|
|
7
|
-
import { mountComponentEffect } from "../../../state/builder-api/actions";
|
|
8
|
-
import { registerComponentHandleEffect } from "../../../state/actions/internal/read-write-actions";
|
|
12
|
+
import { ControlInstancesProvider } from "./control-instances-context";
|
|
9
13
|
const ElementRegistration = memo(function ElementRegistration2({
|
|
10
14
|
elementKey,
|
|
15
|
+
componentType,
|
|
11
16
|
componentHandle,
|
|
12
17
|
children
|
|
13
18
|
}) {
|
|
14
19
|
const dispatch = useDispatch();
|
|
15
20
|
const documentKey = useDocumentKey();
|
|
16
|
-
const
|
|
21
|
+
const controlInstancesContext = useMemo(
|
|
22
|
+
() => ({
|
|
23
|
+
elementKey,
|
|
24
|
+
instances: documentKey ? dispatch(createPropControllers({ documentKey, elementKey, componentType })) : null
|
|
25
|
+
}),
|
|
26
|
+
[dispatch, documentKey, elementKey, componentType]
|
|
27
|
+
);
|
|
28
|
+
const controlInstances = controlInstancesContext?.instances;
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (controlInstances == null)
|
|
31
|
+
return;
|
|
32
|
+
componentHandle.setPropControllers(controlInstances);
|
|
33
|
+
return () => componentHandle.setPropControllers(null);
|
|
34
|
+
}, [controlInstances, componentHandle]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (documentKey == null || controlInstances == null)
|
|
37
|
+
return;
|
|
38
|
+
return dispatch(registerPropControllersEffect(documentKey, elementKey, controlInstances));
|
|
39
|
+
}, [dispatch, documentKey, elementKey, controlInstances]);
|
|
17
40
|
useEffect(() => {
|
|
18
|
-
if (documentKey == null
|
|
41
|
+
if (documentKey == null)
|
|
19
42
|
return;
|
|
20
43
|
return dispatch(registerComponentHandleEffect(documentKey, elementKey, componentHandle));
|
|
21
|
-
}, [dispatch, documentKey, elementKey,
|
|
44
|
+
}, [dispatch, documentKey, elementKey, componentHandle]);
|
|
22
45
|
useEffect(() => {
|
|
23
|
-
if (documentKey == null
|
|
46
|
+
if (documentKey == null)
|
|
24
47
|
return;
|
|
25
48
|
return dispatch(mountComponentEffect(documentKey, elementKey));
|
|
26
|
-
}, [dispatch, documentKey, elementKey
|
|
27
|
-
return /* @__PURE__ */ jsx(
|
|
49
|
+
}, [dispatch, documentKey, elementKey]);
|
|
50
|
+
return /* @__PURE__ */ jsx(ControlInstancesProvider, { value: controlInstancesContext, children });
|
|
28
51
|
});
|
|
29
52
|
var ElementRegistration_default = ElementRegistration;
|
|
30
53
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/ElementRegistration.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, memo, useEffect } from 'react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/ElementRegistration.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, memo, useMemo, useEffect } from 'react'\n\nimport {\n createPropControllers,\n registerComponentHandleEffect,\n registerPropControllersEffect,\n} from '../../../state/actions/internal/read-write-actions'\nimport { mountComponentEffect } from '../../../state/builder-api/actions'\n\nimport { useDispatch } from '../hooks/use-dispatch'\nimport { useDocumentKey } from '../hooks/use-document-context'\n\nimport { ElementImperativeHandle } from '../element-imperative-handle'\n\nimport { ControlInstancesProvider } from './control-instances-context'\n\nexport const ElementRegistration = memo(function ElementRegistration({\n elementKey,\n componentType,\n componentHandle,\n children,\n}: {\n elementKey: string\n componentHandle: ElementImperativeHandle\n componentType: string\n children?: ReactNode\n}): ReactNode {\n const dispatch = useDispatch()\n const documentKey = useDocumentKey()\n\n // Create control instances on first render and make them available down the React tree\n // through `ControlInstancesProvider`\n const controlInstancesContext = useMemo(\n () => ({\n elementKey,\n instances: documentKey\n ? dispatch(createPropControllers({ documentKey, elementKey, componentType }))\n : null,\n }),\n [dispatch, documentKey, elementKey, componentType],\n )\n\n const controlInstances = controlInstancesContext?.instances\n\n // Set control instances into the corresponding component handle\n useEffect(() => {\n if (controlInstances == null) return\n\n componentHandle.setPropControllers(controlInstances)\n return () => componentHandle.setPropControllers(null)\n }, [controlInstances, componentHandle])\n\n // Register the control instances and component handle in the state\n useEffect(() => {\n if (documentKey == null || controlInstances == null) return\n\n return dispatch(registerPropControllersEffect(documentKey, elementKey, controlInstances))\n }, [dispatch, documentKey, elementKey, controlInstances])\n\n useEffect(() => {\n if (documentKey == null) return\n\n return dispatch(registerComponentHandleEffect(documentKey, elementKey, componentHandle))\n }, [dispatch, documentKey, elementKey, componentHandle])\n\n // Register the element with to the builder\n useEffect(() => {\n if (documentKey == null) return\n\n return dispatch(mountComponentEffect(documentKey, elementKey))\n }, [dispatch, documentKey, elementKey])\n\n return (\n <ControlInstancesProvider value={controlInstancesContext}>{children}</ControlInstancesProvider>\n )\n})\n\nexport default ElementRegistration\n"],"mappings":";AA2EI;AAzEJ,SAAoB,MAAM,SAAS,iBAAiB;AAEpD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AAErC,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAI/B,SAAS,gCAAgC;AAElC,MAAM,sBAAsB,KAAK,SAASA,qBAAoB;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKc;AACZ,QAAM,WAAW,YAAY;AAC7B,QAAM,cAAc,eAAe;AAInC,QAAM,0BAA0B;AAAA,IAC9B,OAAO;AAAA,MACL;AAAA,MACA,WAAW,cACP,SAAS,sBAAsB,EAAE,aAAa,YAAY,cAAc,CAAC,CAAC,IAC1E;AAAA,IACN;AAAA,IACA,CAAC,UAAU,aAAa,YAAY,aAAa;AAAA,EACnD;AAEA,QAAM,mBAAmB,yBAAyB;AAGlD,YAAU,MAAM;AACd,QAAI,oBAAoB;AAAM;AAE9B,oBAAgB,mBAAmB,gBAAgB;AACnD,WAAO,MAAM,gBAAgB,mBAAmB,IAAI;AAAA,EACtD,GAAG,CAAC,kBAAkB,eAAe,CAAC;AAGtC,YAAU,MAAM;AACd,QAAI,eAAe,QAAQ,oBAAoB;AAAM;AAErD,WAAO,SAAS,8BAA8B,aAAa,YAAY,gBAAgB,CAAC;AAAA,EAC1F,GAAG,CAAC,UAAU,aAAa,YAAY,gBAAgB,CAAC;AAExD,YAAU,MAAM;AACd,QAAI,eAAe;AAAM;AAEzB,WAAO,SAAS,8BAA8B,aAAa,YAAY,eAAe,CAAC;AAAA,EACzF,GAAG,CAAC,UAAU,aAAa,YAAY,eAAe,CAAC;AAGvD,YAAU,MAAM;AACd,QAAI,eAAe;AAAM;AAEzB,WAAO,SAAS,qBAAqB,aAAa,UAAU,CAAC;AAAA,EAC/D,GAAG,CAAC,UAAU,aAAa,UAAU,CAAC;AAEtC,SACE,oBAAC,4BAAyB,OAAO,yBAA0B,UAAS;AAExE,CAAC;AAED,IAAO,8BAAQ;","names":["ElementRegistration"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const ControlInstancesContext = createContext(null);
|
|
4
|
+
const ControlInstancesProvider = ControlInstancesContext.Provider;
|
|
5
|
+
function useControlInstances(elementKey) {
|
|
6
|
+
const cx = useContext(ControlInstancesContext);
|
|
7
|
+
return cx && cx.elementKey === elementKey ? cx.instances : null;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
ControlInstancesProvider,
|
|
11
|
+
useControlInstances
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=control-instances-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/control-instances-context.tsx"],"sourcesContent":["'use client'\n\nimport { createContext, useContext } from 'react'\n\nimport { ControlInstance } from '@makeswift/controls'\n\ntype Context = {\n elementKey: string\n instances: Record<string, ControlInstance> | null\n}\n\nconst ControlInstancesContext = createContext<Context | null>(null)\n\nexport const ControlInstancesProvider = ControlInstancesContext.Provider\n\nexport function useControlInstances(elementKey: string): Context['instances'] | null {\n const cx = useContext(ControlInstancesContext)\n return cx && cx.elementKey === elementKey ? cx.instances : null\n}\n"],"mappings":";AAEA,SAAS,eAAe,kBAAkB;AAS1C,MAAM,0BAA0B,cAA8B,IAAI;AAE3D,MAAM,2BAA2B,wBAAwB;AAEzD,SAAS,oBAAoB,YAAiD;AACnF,QAAM,KAAK,WAAW,uBAAuB;AAC7C,SAAO,MAAM,GAAG,eAAe,aAAa,GAAG,YAAY;AAC7D;","names":[]}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isReadWriteState } from "../../../state/unified-state";
|
|
3
|
-
import { useDocumentKey } from "./use-document-context";
|
|
4
|
-
import { useSelector } from "./use-selector";
|
|
5
|
-
function useControlInstances(elementKey) {
|
|
6
|
-
const documentKey = useDocumentKey();
|
|
7
|
-
return useSelector((state) => {
|
|
8
|
-
if (documentKey == null || !isReadWriteState(state))
|
|
9
|
-
return null;
|
|
10
|
-
return getPropControllers(state, { documentKey, elementKey });
|
|
11
|
-
});
|
|
12
|
-
}
|
|
1
|
+
import { useControlInstances } from "../components/control-instances-context";
|
|
13
2
|
export {
|
|
14
3
|
useControlInstances
|
|
15
4
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-control-instances.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-control-instances.ts"],"sourcesContent":["export { useControlInstances } from '../components/control-instances-context'\n"],"mappings":"AAAA,SAAS,2BAA2B;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createContext, useContext } from "react";
|
|
2
2
|
const DisableRegisterElement = createContext(false);
|
|
3
|
-
function
|
|
3
|
+
function useIsRegisterElementDisabled() {
|
|
4
4
|
return useContext(DisableRegisterElement);
|
|
5
5
|
}
|
|
6
6
|
export {
|
|
7
7
|
DisableRegisterElement,
|
|
8
|
-
|
|
8
|
+
useIsRegisterElementDisabled
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=use-disable-register-element.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-disable-register-element.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nexport const DisableRegisterElement = createContext(false)\n\nexport function
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-disable-register-element.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nexport const DisableRegisterElement = createContext(false)\n\nexport function useIsRegisterElementDisabled() {\n return useContext(DisableRegisterElement)\n}\n"],"mappings":"AAAA,SAAS,eAAe,kBAAkB;AAEnC,MAAM,yBAAyB,cAAc,KAAK;AAElD,SAAS,+BAA+B;AAC7C,SAAO,WAAW,sBAAsB;AAC1C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/state/actions/internal/read-write-action-types.ts"],"sourcesContent":["export const ReadWriteActionTypes = {\n CHANGE_ELEMENT_TREE: 'CHANGE_ELEMENT_TREE',\n\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_MEASURABLE: 'REGISTER_MEASURABLE',\n UNREGISTER_MEASURABLE: 'UNREGISTER_MEASURABLE',\n\n UPDATE_API_CLIENT_CACHE: 'UPDATE_API_CLIENT_CACHE',\n CLEAR_API_CLIENT_CACHE: 'CLEAR_API_CLIENT_CACHE',\n} as const\n"],"mappings":"AAAO,MAAM,uBAAuB;AAAA,EAClC,qBAAqB;AAAA,EAErB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,kCAAkC;AAAA,EAClC,oCAAoC;AAAA,EAEpC,qBAAqB;AAAA,EACrB,uBAAuB;AAAA,EAEvB,yBAAyB;AAAA,EACzB,wBAAwB;AAC1B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/state/actions/internal/read-write-action-types.ts"],"sourcesContent":["export const ReadWriteActionTypes = {\n FLUSH_ACTION_BUFFER: 'FLUSH_ACTION_BUFFER',\n\n CHANGE_ELEMENT_TREE: 'CHANGE_ELEMENT_TREE',\n\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_MEASURABLE: 'REGISTER_MEASURABLE',\n UNREGISTER_MEASURABLE: 'UNREGISTER_MEASURABLE',\n\n UPDATE_API_CLIENT_CACHE: 'UPDATE_API_CLIENT_CACHE',\n CLEAR_API_CLIENT_CACHE: 'CLEAR_API_CLIENT_CACHE',\n} as const\n"],"mappings":"AAAO,MAAM,uBAAuB;AAAA,EAClC,qBAAqB;AAAA,EAErB,qBAAqB;AAAA,EAErB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,kCAAkC;AAAA,EAClC,oCAAoC;AAAA,EAEpC,qBAAqB;AAAA,EACrB,uBAAuB;AAAA,EAEvB,yBAAyB;AAAA,EACzB,wBAAwB;AAC1B;","names":[]}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { createPropController } from "../../../prop-controllers/instances";
|
|
2
|
+
import * as Builder from "../../builder-api/actions";
|
|
3
|
+
import { getComponentPropControllerDescriptors } from "../../read-only-state";
|
|
1
4
|
import { ReadWriteActionTypes } from "./read-write-action-types";
|
|
5
|
+
function flushActionBuffer() {
|
|
6
|
+
return { type: ReadWriteActionTypes.FLUSH_ACTION_BUFFER };
|
|
7
|
+
}
|
|
2
8
|
function changeElementTree(payload) {
|
|
3
9
|
return {
|
|
4
10
|
type: ReadWriteActionTypes.CHANGE_ELEMENT_TREE,
|
|
@@ -49,6 +55,14 @@ function unregisterPropControllers(documentKey, elementKey) {
|
|
|
49
55
|
payload: { documentKey, elementKey }
|
|
50
56
|
};
|
|
51
57
|
}
|
|
58
|
+
function registerPropControllersEffect(documentKey, elementKey, propControllers) {
|
|
59
|
+
return (dispatch) => {
|
|
60
|
+
dispatch(registerPropControllers(documentKey, elementKey, propControllers));
|
|
61
|
+
return () => {
|
|
62
|
+
dispatch(unregisterPropControllers(documentKey, elementKey));
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
52
66
|
function registerMeasurable(documentKey, elementKey, measurable) {
|
|
53
67
|
return {
|
|
54
68
|
type: ReadWriteActionTypes.REGISTER_MEASURABLE,
|
|
@@ -72,14 +86,42 @@ function updateAPIClientCache(payload) {
|
|
|
72
86
|
function clearAPIClientCache() {
|
|
73
87
|
return { type: ReadWriteActionTypes.CLEAR_API_CLIENT_CACHE };
|
|
74
88
|
}
|
|
89
|
+
function createPropControllers({
|
|
90
|
+
documentKey,
|
|
91
|
+
elementKey,
|
|
92
|
+
componentType
|
|
93
|
+
}) {
|
|
94
|
+
return (dispatch, getState) => {
|
|
95
|
+
const descriptors = getComponentPropControllerDescriptors(getState(), componentType);
|
|
96
|
+
if (descriptors == null)
|
|
97
|
+
return null;
|
|
98
|
+
const propControllers = Object.entries(descriptors).reduce(
|
|
99
|
+
(acc, [propName, descriptor]) => {
|
|
100
|
+
const propController = createPropController({
|
|
101
|
+
descriptor,
|
|
102
|
+
instanceKey: { elementKey, propPath: propName },
|
|
103
|
+
sendMessage: (message) => dispatch(
|
|
104
|
+
Builder.messageBuilderPropController(documentKey, elementKey, propName, message)
|
|
105
|
+
)
|
|
106
|
+
});
|
|
107
|
+
return { ...acc, [propName]: propController };
|
|
108
|
+
},
|
|
109
|
+
{}
|
|
110
|
+
);
|
|
111
|
+
return propControllers;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
75
114
|
export {
|
|
76
115
|
changeElementTree,
|
|
77
116
|
clearAPIClientCache,
|
|
117
|
+
createPropControllers,
|
|
118
|
+
flushActionBuffer,
|
|
78
119
|
registerComponentHandle,
|
|
79
120
|
registerComponentHandleEffect,
|
|
80
121
|
registerMeasurable,
|
|
81
122
|
registerMeasurableEffect,
|
|
82
123
|
registerPropControllers,
|
|
124
|
+
registerPropControllersEffect,
|
|
83
125
|
registerPropControllersHandle,
|
|
84
126
|
unregisterComponentHandle,
|
|
85
127
|
unregisterMeasurable,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/state/actions/internal/read-write-actions.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type DescriptorsByComponentType } from '../../modules/prop-controller-descriptors'\nimport { type Measurable } from '../../modules/read-write/box-models'\nimport { type PropControllersHandle } from '../../modules/read-write/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\nimport { type SerializedState as APIClientCache } from '../../api-client/state'\n\nimport { ReadWriteActionTypes } from './read-write-action-types'\n\ntype ChangeElementTreeAction = {\n type: typeof ReadWriteActionTypes.CHANGE_ELEMENT_TREE\n payload: {\n oldDocument: DocumentPayload\n newDocument: DocumentPayload\n descriptors: DescriptorsByComponentType\n operation: Operation\n }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadWriteActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadWriteActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadWriteActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterMeasurableAction = {\n type: typeof ReadWriteActionTypes.REGISTER_MEASURABLE\n payload: { documentKey: string; elementKey: string; measurable: Measurable }\n}\n\ntype UnregisterMeasurableAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_MEASURABLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype UpdateAPIClientCache = {\n type: typeof ReadWriteActionTypes.UPDATE_API_CLIENT_CACHE\n payload: APIClientCache\n}\n\ntype ClearAPIClientCache = {\n type: typeof ReadWriteActionTypes.CLEAR_API_CLIENT_CACHE\n}\n\nexport type ReadWriteAction =\n | ChangeElementTreeAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterMeasurableAction\n | UnregisterMeasurableAction\n | UpdateAPIClientCache\n | ClearAPIClientCache\n\nexport function changeElementTree(\n payload: ChangeElementTreeAction['payload'],\n): ChangeElementTreeAction {\n return {\n type: ReadWriteActionTypes.CHANGE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadWriteActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nexport function unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadWriteActionTypes.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, ReadWriteAction> {\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: ReadWriteActionTypes.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: ReadWriteActionTypes.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: ReadWriteActionTypes.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: ReadWriteActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerMeasurable(\n documentKey: string,\n elementKey: string,\n measurable: Measurable,\n): RegisterMeasurableAction {\n return {\n type: ReadWriteActionTypes.REGISTER_MEASURABLE,\n payload: { documentKey, elementKey, measurable },\n }\n}\n\nexport function unregisterMeasurable(\n documentKey: string,\n elementKey: string,\n): UnregisterMeasurableAction {\n return { type: ReadWriteActionTypes.UNREGISTER_MEASURABLE, payload: { documentKey, elementKey } }\n}\n\nexport function registerMeasurableEffect(\n documentKey: string,\n elementKey: string,\n measurable: Measurable,\n): ThunkAction<() => void, unknown, unknown, ReadWriteAction> {\n return dispatch => {\n dispatch(registerMeasurable(documentKey, elementKey, measurable))\n\n return () => {\n dispatch(unregisterMeasurable(documentKey, elementKey))\n }\n }\n}\n\nexport function updateAPIClientCache(payload: APIClientCache): UpdateAPIClientCache {\n return { type: ReadWriteActionTypes.UPDATE_API_CLIENT_CACHE, payload }\n}\n\nexport function clearAPIClientCache(): ClearAPIClientCache {\n return { type: ReadWriteActionTypes.CLEAR_API_CLIENT_CACHE }\n}\n"],"mappings":"AAcA,SAAS,4BAA4B;AA8E9B,SAAS,kBACd,SACyB;AACzB,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B;AAAA,EACF;AACF;AAEO,SAAS,wBACd,aACA,YACA,iBAC+B;AAC/B,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,YAAY,gBAAgB;AAAA,EACtD;AACF;AAEO,SAAS,0BACd,aACA,YACiC;AACjC,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEO,SAAS,8BACd,aACA,YACA,iBAC4D;AAC5D,SAAO,cAAY;AACjB,aAAS,wBAAwB,aAAa,YAAY,eAAe,CAAC;AAE1E,WAAO,MAAM;AACX,eAAS,0BAA0B,aAAa,UAAU,CAAC;AAAA,IAC7D;AAAA,EACF;AACF;AAEO,SAAS,8BACd,aACA,YACA,QACqC;AACrC,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,YAAY,OAAO;AAAA,EAC7C;AACF;AAEO,SAAS,gCACd,aACA,YACuC;AACvC,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEO,SAAS,wBACd,aACA,YACA,iBAC+B;AAC/B,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,YAAY,gBAAgB;AAAA,EACtD;AACF;AAEO,SAAS,0BACd,aACA,YACiC;AACjC,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEO,SAAS,mBACd,aACA,YACA,YAC0B;AAC1B,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,YAAY,WAAW;AAAA,EACjD;AACF;AAEO,SAAS,qBACd,aACA,YAC4B;AAC5B,SAAO,EAAE,MAAM,qBAAqB,uBAAuB,SAAS,EAAE,aAAa,WAAW,EAAE;AAClG;AAEO,SAAS,yBACd,aACA,YACA,YAC4D;AAC5D,SAAO,cAAY;AACjB,aAAS,mBAAmB,aAAa,YAAY,UAAU,CAAC;AAEhE,WAAO,MAAM;AACX,eAAS,qBAAqB,aAAa,UAAU,CAAC;AAAA,IACxD;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,SAA+C;AAClF,SAAO,EAAE,MAAM,qBAAqB,yBAAyB,QAAQ;AACvE;AAEO,SAAS,sBAA2C;AACzD,SAAO,EAAE,MAAM,qBAAqB,uBAAuB;AAC7D;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/state/actions/internal/read-write-actions.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type DescriptorsByComponentType } from '../../modules/prop-controller-descriptors'\nimport { type Measurable } from '../../modules/read-write/box-models'\nimport { type PropControllersHandle } from '../../modules/read-write/prop-controllers'\n\nimport { createPropController } from '../../../prop-controllers/instances'\n\nimport { type Action } from '../../actions'\nimport * as Builder from '../../builder-api/actions'\n\nimport { type DocumentPayload } from '../../shared-api'\nimport { type SerializedState as APIClientCache } from '../../api-client/state'\nimport { getComponentPropControllerDescriptors } from '../../read-only-state'\nimport { type State } from '../../unified-state'\n\nimport { ReadWriteActionTypes } from './read-write-action-types'\n\ntype FlushActionBufferAction = {\n type: typeof ReadWriteActionTypes.FLUSH_ACTION_BUFFER\n}\n\ntype ChangeElementTreeAction = {\n type: typeof ReadWriteActionTypes.CHANGE_ELEMENT_TREE\n payload: {\n oldDocument: DocumentPayload\n newDocument: DocumentPayload\n descriptors: DescriptorsByComponentType\n operation: Operation\n }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadWriteActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadWriteActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadWriteActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterMeasurableAction = {\n type: typeof ReadWriteActionTypes.REGISTER_MEASURABLE\n payload: { documentKey: string; elementKey: string; measurable: Measurable }\n}\n\ntype UnregisterMeasurableAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_MEASURABLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype UpdateAPIClientCache = {\n type: typeof ReadWriteActionTypes.UPDATE_API_CLIENT_CACHE\n payload: APIClientCache\n}\n\ntype ClearAPIClientCache = {\n type: typeof ReadWriteActionTypes.CLEAR_API_CLIENT_CACHE\n}\n\nexport type ReadWriteAction =\n | FlushActionBufferAction\n | ChangeElementTreeAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterMeasurableAction\n | UnregisterMeasurableAction\n | UpdateAPIClientCache\n | ClearAPIClientCache\n\nexport function flushActionBuffer() {\n return { type: ReadWriteActionTypes.FLUSH_ACTION_BUFFER }\n}\n\nexport function changeElementTree(\n payload: ChangeElementTreeAction['payload'],\n): ChangeElementTreeAction {\n return {\n type: ReadWriteActionTypes.CHANGE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadWriteActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nexport function unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadWriteActionTypes.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, ReadWriteAction> {\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: ReadWriteActionTypes.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: ReadWriteActionTypes.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: ReadWriteActionTypes.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: ReadWriteActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllersEffect(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): ThunkAction<() => void, unknown, unknown, ReadWriteAction> {\n return dispatch => {\n dispatch(registerPropControllers(documentKey, elementKey, propControllers))\n\n return () => {\n dispatch(unregisterPropControllers(documentKey, elementKey))\n }\n }\n}\n\nexport function registerMeasurable(\n documentKey: string,\n elementKey: string,\n measurable: Measurable,\n): RegisterMeasurableAction {\n return {\n type: ReadWriteActionTypes.REGISTER_MEASURABLE,\n payload: { documentKey, elementKey, measurable },\n }\n}\n\nexport function unregisterMeasurable(\n documentKey: string,\n elementKey: string,\n): UnregisterMeasurableAction {\n return { type: ReadWriteActionTypes.UNREGISTER_MEASURABLE, payload: { documentKey, elementKey } }\n}\n\nexport function registerMeasurableEffect(\n documentKey: string,\n elementKey: string,\n measurable: Measurable,\n): ThunkAction<() => void, unknown, unknown, ReadWriteAction> {\n return dispatch => {\n dispatch(registerMeasurable(documentKey, elementKey, measurable))\n\n return () => {\n dispatch(unregisterMeasurable(documentKey, elementKey))\n }\n }\n}\n\nexport function updateAPIClientCache(payload: APIClientCache): UpdateAPIClientCache {\n return { type: ReadWriteActionTypes.UPDATE_API_CLIENT_CACHE, payload }\n}\n\nexport function clearAPIClientCache(): ClearAPIClientCache {\n return { type: ReadWriteActionTypes.CLEAR_API_CLIENT_CACHE }\n}\n\nexport function createPropControllers({\n documentKey,\n elementKey,\n componentType,\n}: {\n documentKey: string\n elementKey: string\n componentType: string\n}): ThunkAction<Record<string, ControlInstance> | null, State, unknown, Action> {\n return (dispatch, getState) => {\n const descriptors = getComponentPropControllerDescriptors(getState(), componentType)\n if (descriptors == null) return null\n\n const propControllers = Object.entries(descriptors).reduce(\n (acc, [propName, descriptor]) => {\n const propController = createPropController({\n descriptor,\n instanceKey: { elementKey, propPath: propName },\n sendMessage: message =>\n dispatch(\n Builder.messageBuilderPropController(documentKey, elementKey, propName, message),\n ),\n }) as ControlInstance\n\n return { ...acc, [propName]: propController }\n },\n {} as Record<string, ControlInstance>,\n )\n\n return propControllers\n }\n}\n"],"mappings":"AAWA,SAAS,4BAA4B;AAGrC,YAAY,aAAa;AAIzB,SAAS,6CAA6C;AAGtD,SAAS,4BAA4B;AAmF9B,SAAS,oBAAoB;AAClC,SAAO,EAAE,MAAM,qBAAqB,oBAAoB;AAC1D;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B;AAAA,EACF;AACF;AAEO,SAAS,wBACd,aACA,YACA,iBAC+B;AAC/B,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,YAAY,gBAAgB;AAAA,EACtD;AACF;AAEO,SAAS,0BACd,aACA,YACiC;AACjC,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,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