@makeswift/runtime 0.28.4 → 0.28.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.
Files changed (79) hide show
  1. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  2. package/dist/cjs/client/index.js +3 -3
  3. package/dist/cjs/components/hooks/useMediaQuery.js +5 -29
  4. package/dist/cjs/components/hooks/useMediaQuery.js.map +1 -1
  5. package/dist/cjs/runtimes/react/hooks/use-breakpoints.js.map +1 -1
  6. package/dist/cjs/runtimes/react/hooks/use-current-breakpoint.js +39 -0
  7. package/dist/cjs/runtimes/react/hooks/use-current-breakpoint.js.map +1 -0
  8. package/dist/cjs/runtimes/react/runtime-core.js +6 -2
  9. package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
  10. package/dist/cjs/runtimes/react/testing/react-runtime.js +2 -2
  11. package/dist/cjs/runtimes/react/testing/react-runtime.js.map +1 -1
  12. package/dist/cjs/state/actions/internal/read-only-actions.js +8 -2
  13. package/dist/cjs/state/actions/internal/read-only-actions.js.map +1 -1
  14. package/dist/cjs/state/mixins/breakpoint-watch.js +72 -0
  15. package/dist/cjs/state/mixins/breakpoint-watch.js.map +1 -0
  16. package/dist/cjs/state/modules/breakpoints.js +37 -2
  17. package/dist/cjs/state/modules/breakpoints.js.map +1 -1
  18. package/dist/cjs/state/read-only-state.js +14 -1
  19. package/dist/cjs/state/read-only-state.js.map +1 -1
  20. package/dist/cjs/state/store.js +8 -0
  21. package/dist/cjs/state/store.js.map +1 -1
  22. package/dist/cjs/utils/ref-counted-map.js +20 -11
  23. package/dist/cjs/utils/ref-counted-map.js.map +1 -1
  24. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  25. package/dist/esm/client/index.js +3 -3
  26. package/dist/esm/components/hooks/useMediaQuery.js +7 -35
  27. package/dist/esm/components/hooks/useMediaQuery.js.map +1 -1
  28. package/dist/esm/runtimes/react/hooks/use-breakpoints.js.map +1 -1
  29. package/dist/esm/runtimes/react/hooks/use-current-breakpoint.js +15 -0
  30. package/dist/esm/runtimes/react/hooks/use-current-breakpoint.js.map +1 -0
  31. package/dist/esm/runtimes/react/runtime-core.js +6 -2
  32. package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
  33. package/dist/esm/runtimes/react/testing/react-runtime.js +2 -2
  34. package/dist/esm/runtimes/react/testing/react-runtime.js.map +1 -1
  35. package/dist/esm/state/actions/internal/read-only-actions.js +6 -1
  36. package/dist/esm/state/actions/internal/read-only-actions.js.map +1 -1
  37. package/dist/esm/state/mixins/breakpoint-watch.js +48 -0
  38. package/dist/esm/state/mixins/breakpoint-watch.js.map +1 -0
  39. package/dist/esm/state/modules/breakpoints.js +38 -2
  40. package/dist/esm/state/modules/breakpoints.js.map +1 -1
  41. package/dist/esm/state/read-only-state.js +12 -1
  42. package/dist/esm/state/read-only-state.js.map +1 -1
  43. package/dist/esm/state/store.js +8 -0
  44. package/dist/esm/state/store.js.map +1 -1
  45. package/dist/esm/utils/ref-counted-map.js +20 -11
  46. package/dist/esm/utils/ref-counted-map.js.map +1 -1
  47. package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts +6 -6
  48. package/dist/types/api-handler/handlers/webhook/types.d.ts +20 -20
  49. package/dist/types/components/hooks/__tests__/useMediaQuery.test.d.ts +3 -0
  50. package/dist/types/components/hooks/__tests__/useMediaQuery.test.d.ts.map +1 -0
  51. package/dist/types/components/hooks/useMediaQuery.d.ts.map +1 -1
  52. package/dist/types/runtimes/react/hooks/use-breakpoints.d.ts +1 -1
  53. package/dist/types/runtimes/react/hooks/use-breakpoints.d.ts.map +1 -1
  54. package/dist/types/runtimes/react/hooks/use-current-breakpoint.d.ts +3 -0
  55. package/dist/types/runtimes/react/hooks/use-current-breakpoint.d.ts.map +1 -0
  56. package/dist/types/runtimes/react/hooks/use-store.d.ts +3 -3
  57. package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
  58. package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
  59. package/dist/types/runtimes/react/testing/react-runtime.d.ts +4 -1
  60. package/dist/types/runtimes/react/testing/react-runtime.d.ts.map +1 -1
  61. package/dist/types/state/__tests__/test-store.d.ts +2 -2
  62. package/dist/types/state/actions/index.d.ts +1 -0
  63. package/dist/types/state/actions/index.d.ts.map +1 -1
  64. package/dist/types/state/actions/internal/index.d.ts +1 -0
  65. package/dist/types/state/actions/internal/index.d.ts.map +1 -1
  66. package/dist/types/state/actions/internal/read-only-actions.d.ts +6 -1
  67. package/dist/types/state/actions/internal/read-only-actions.d.ts.map +1 -1
  68. package/dist/types/state/mixins/breakpoint-watch.d.ts +11 -0
  69. package/dist/types/state/mixins/breakpoint-watch.d.ts.map +1 -0
  70. package/dist/types/state/modules/breakpoints.d.ts +11 -2
  71. package/dist/types/state/modules/breakpoints.d.ts.map +1 -1
  72. package/dist/types/state/read-only-state.d.ts +3 -1
  73. package/dist/types/state/read-only-state.d.ts.map +1 -1
  74. package/dist/types/state/read-write-state.d.ts +2 -2
  75. package/dist/types/state/store.d.ts +7 -6
  76. package/dist/types/state/store.d.ts.map +1 -1
  77. package/dist/types/utils/ref-counted-map.d.ts +8 -2
  78. package/dist/types/utils/ref-counted-map.d.ts.map +1 -1
  79. package/package.json +2 -1
@@ -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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAA+B;AAE/B,kBAA6B;AAC7B,aAAwB;AACxB,gBAA2B;AAC3B,mBAA8B;AAC9B,sBAAiC;AACjC,qBAAgC;AAChC,sBAAiC;AACjC,4BAAuC;AACvC,kBAA6B;AAC7B,iBAA4B;AAC5B,sBAAiC;AACjC,kBAA6B;AAa7B,iCAKO;AAKA,MAAM,WAAW;AAAA,EACtB,aAAa,YAAY;AAAA,EACzB,YAAY,WAAW;AAAA,EACvB,QAAQ,OAAO;AAAA,EACf,WAAW,UAAU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;AAC9D,SAAO,MAAM;AACf;AAEO,SAAS,UAAU,OAA6B;AACrD,SAAO,MAAM;AACf;","names":[]}
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\nfunction getBreakpointsStateSlice(state: State): Breakpoints.State {\n return state.breakpoints\n}\n\nexport function getBreakpoints(state: State): Breakpoints.Breakpoints {\n return getBreakpointsStateSlice(state).breakpoints\n}\n\nexport function getBaseBreakpoint(state: State): Breakpoints.BreakpointId {\n return getBreakpointsStateSlice(state).baseBreakpoint\n}\n\nexport function getClientBreakpoint(state: State): Breakpoints.BreakpointId {\n return getBreakpointsStateSlice(state).clientBreakpoint\n}\n\nexport function getLocale(state: State): string | null {\n return state.locale\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAA+B;AAE/B,kBAA6B;AAC7B,aAAwB;AACxB,gBAA2B;AAC3B,mBAA8B;AAC9B,sBAAiC;AACjC,qBAAgC;AAChC,sBAAiC;AACjC,4BAAuC;AACvC,kBAA6B;AAC7B,iBAA4B;AAC5B,sBAAiC;AACjC,kBAA6B;AAa7B,iCAKO;AAKA,MAAM,WAAW;AAAA,EACtB,aAAa,YAAY;AAAA,EACzB,YAAY,WAAW;AAAA,EACvB,QAAQ,OAAO;AAAA,EACf,WAAW,UAAU;AAAA,EACrB,cAAc,aAAa;AAAA,EAC3B,iBAAiB,gBAAgB;AAAA,EACjC,gBAAgB,eAAe;AAAA,EAC/B,iBAAiB,gBAAgB;AAAA,EACjC,uBAAuB,sBAAsB;AAAA,EAC7C,aAAa,YAAY;AAAA,EACzB,iBAAiB,gBAAgB;AAAA,EACjC,aAAa,YAAY;AAC3B;AAmBA,SAAS,uBAAuB,OAA+B;AAC7D,SAAO,MAAM;AACf;AAEO,SAAS,YAAY,OAAc,aAAgD;AACxF,SAAO,UAAU,YAAY,uBAAuB,KAAK,GAAG,WAAW;AACzE;AAEA,SAAS,qBAAqB,OAAkC;AAC9D,SAAO,MAAM;AACf;AAEO,SAAS,YACd,OACA,aACsC;AACtC,SAAO,aAAa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AAA,EACtE,CAAC,wBAAwB,oBAAoB;AAAA,EAC7C,CAAC,WAAW,iBAAiB;AAC3B,WAAO,CAAC,GAAG,UAAU,KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,MAAO,aAAa,IAAI,CAAC,GAAG,SAAS,IAAI,CAAC,IAAI,KAAK,CAAE;AAAA,EAC7F;AACF;AAEO,SAAS,WACd,OACA,aACA,YAC0B;AAC1B,SAAO,aAAa,WAAW,qBAAqB,KAAK,GAAG,aAAa,UAAU;AACrF;AAEO,SAAS,aAAa,OAAc,aAAqB,YAAmC;AACjG,SAAO,aAAa,aAAa,qBAAqB,KAAK,GAAG,aAAa,UAAU;AACvF;AAEO,SAAS,oCACd,OACA,aACA,YACiE;AACjE,QAAM,UAAU,WAAW,OAAO,aAAa,UAAU;AAEzD,MAAI,WAAW,QAAQ,UAAU,mBAAmB,OAAO;AAAG,WAAO;AAErE,SAAO,sCAAsC,OAAO,QAAQ,IAAI;AAClE;AAEO,SAAS,eAAe,OAAuB;AACpD,SAAO,MAAM;AACf;AAEO,SAAS,cAAc,OAAuB;AACnD,SAAO,MAAM;AACf;AAEO,SAAS,mBAAmB,OAAqC;AACtE,SAAO,MAAM;AACf;AAEA,SAAS,yBAAyB,OAAiC;AACjE,SAAO,MAAM;AACf;AAEO,SAAS,eAAe,OAAuC;AACpE,SAAO,yBAAyB,KAAK,EAAE;AACzC;AAEO,SAAS,kBAAkB,OAAwC;AACxE,SAAO,yBAAyB,KAAK,EAAE;AACzC;AAEO,SAAS,oBAAoB,OAAwC;AAC1E,SAAO,yBAAyB,KAAK,EAAE;AACzC;AAEO,SAAS,UAAU,OAA6B;AACrD,SAAO,MAAM;AACf;","names":[]}
@@ -40,6 +40,7 @@ var import_host_api = require("./host-api");
40
40
  var Breakpoints = __toESM(require("./modules/breakpoints"));
41
41
  var import_read_only_element_tree = require("./middleware/read-only-element-tree");
42
42
  var import_makeswift_api_client_sync = require("./middleware/makeswift-api-client-sync");
43
+ var import_breakpoint_watch = require("./mixins/breakpoint-watch");
43
44
  var ReadOnlyState = __toESM(require("./read-only-state"));
44
45
  const configureStore = ({
45
46
  name,
@@ -171,6 +172,13 @@ function configureReadWriteStore({
171
172
  conditionalReadWriteMiddleware(readWriteMiddlewareRef)
172
173
  ],
173
174
  enhancers: () => new import_toolkit.Tuple(
175
+ withMixin(
176
+ (0, import_breakpoint_watch.breakpointWatchMixin)({
177
+ dispatch: (...args) => store.dispatch(...args),
178
+ getState: () => store.getState(),
179
+ subscribe: (listener) => store.subscribe(listener)
180
+ })
181
+ ),
174
182
  withMixin({
175
183
  hostApiClient,
176
184
  loadReadWriteStateIfNeeded: async () => {
@@ -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 { MakeswiftHostApiClient } from '../api/client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\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.State | 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 hostApiClient: MakeswiftHostApiClient\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 hostApiClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n hostApiClient: MakeswiftHostApiClient\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(hostApiClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ],\n\n enhancers: () =>\n new Tuple(\n withMixin<ReadWriteStateMixin>({\n hostApiClient,\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,qBAAmC;AACnC,sBAAgC;AAEhC,kBAA6B;AAE7B,oCAA8C;AAC9C,uCAAiD;AAKjD,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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UAAU;AACjC,4BAAoB;AAAA,MACtB;AAAA,IACF,GAAG;AAEH,QAAI;AACF,YAAM;AAAA,IACR,UAAE;AACA,8BAAwB;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,QAAQ,eAAe;AAAA,IAC3B;AAAA,IACA;AAAA,IAEA,YAAY,MAAM;AAAA,UAChB,mEAAiC,aAAa;AAAA,MAC9C,+BAA+B,sBAAsB;AAAA,IACvD;AAAA,IAEA,WAAW,MACT,IAAI;AAAA,MACF,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 { MakeswiftHostApiClient } from '../api/client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\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 hostApiClient: MakeswiftHostApiClient\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 hostApiClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n hostApiClient: MakeswiftHostApiClient\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(hostApiClient),\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 hostApiClient,\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,qBAAmC;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,kCAAmB;AAAA,QACnB,kCAAmB;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;AAAA,MACd,aAAa,YAAY,gBAAgB,WAAW;AAAA,IACtD;AAAA,IACA,WAAW,MAAM,I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,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"]}
@@ -60,35 +60,44 @@ class RefCountedMap {
60
60
  this.removeExpired();
61
61
  }
62
62
  }
63
+ /**
64
+ * Returns true on transition from unowned to owned
65
+ */
63
66
  retain(key, value) {
64
67
  try {
65
68
  const existing = this.map.get(key);
66
- if (existing != null) {
67
- if (existing.value !== value)
68
- return;
69
- existing.count = (existing.count ?? 0) + 1;
70
- } else {
69
+ if (existing == null) {
71
70
  this.map.set(key, { value, count: 1 });
71
+ return true;
72
+ }
73
+ if (existing.value === value) {
74
+ existing.count = (existing.count ?? 0) + 1;
75
+ return existing.count === 1;
72
76
  }
77
+ return false;
73
78
  } finally {
74
79
  if (this.ttlCheck & TTLCheck.ON_RETAIN)
75
80
  this.removeExpired();
76
81
  }
77
82
  }
83
+ /**
84
+ * Returns true on transition from owned to unowned
85
+ */
78
86
  release(key, value) {
79
87
  try {
80
88
  const existing = this.map.get(key);
81
89
  if (existing == null)
82
- return;
90
+ return false;
83
91
  if (isUnowned(existing))
84
- return;
92
+ return false;
85
93
  if (existing.value !== value)
86
- return;
87
- if (existing.count > 1) {
88
- existing.count -= 1;
89
- } else {
94
+ return false;
95
+ if (existing.count === 1) {
90
96
  this.map.delete(key);
97
+ return true;
91
98
  }
99
+ existing.count -= 1;
100
+ return false;
92
101
  } finally {
93
102
  if (this.ttlCheck & TTLCheck.ON_RELEASE)
94
103
  this.removeExpired();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/ref-counted-map.ts"],"sourcesContent":["type RefCountedMapEntry<V> = {\n value: V\n count: number\n}\n\ntype UnownedMapEntry<V> = {\n value: V\n count: undefined\n accessedAt: number\n}\n\ntype MapEntry<V> = RefCountedMapEntry<V> | UnownedMapEntry<V>\n\nconst TTLCheck = {\n ON_GET: 1 << 0,\n ON_RETAIN: 1 << 1,\n ON_RELEASE: 1 << 2,\n} as const\n\n/**\n * Ref-counted map with explicit retention semantics. Entries are unowned by default and may be evicted after their\n * TTL unless explicitly retained. This provides TTL-based caching for unowned entries, while allowing consumers to\n * opt into stronger lifetime control via explicit retention.\n */\nexport class RefCountedMap<K, V> {\n private readonly map = new Map<K, MapEntry<V>>()\n private readonly unownedEntryTtlMs: number\n private readonly ttlCheck: number\n\n static readonly TTLCheck = TTLCheck\n\n constructor({\n unownedEntryTtlMs,\n ttlCheck = TTLCheck.ON_GET | TTLCheck.ON_RETAIN | TTLCheck.ON_RELEASE,\n }: {\n unownedEntryTtlMs: number\n ttlCheck?: number\n }) {\n this.unownedEntryTtlMs = unownedEntryTtlMs\n this.ttlCheck = ttlCheck\n }\n\n get size(): number {\n return this.map.size\n }\n\n get(key: K): V | undefined {\n return this.map.get(key)?.value\n }\n\n getOrCreate(key: K, init: () => V): V {\n try {\n const existing = this.map.get(key)\n\n if (existing) {\n if (isUnowned(existing)) existing.accessedAt = Date.now()\n return existing.value\n }\n\n const value = init()\n this.map.set(key, { value, count: undefined, accessedAt: Date.now() })\n return value\n } finally {\n if (this.ttlCheck & TTLCheck.ON_GET) this.removeExpired()\n }\n }\n\n retain(key: K, value: V): void {\n try {\n const existing = this.map.get(key)\n\n // `retain` might be called on a unowned entry that has already been evicted from the map due to TTL expiration\n // *and* possibly replaced by a new unowned entry with the same key; handle this gracefully\n if (existing != null) {\n if (existing.value !== value) return\n existing.count = (existing.count ?? 0) + 1\n } else {\n this.map.set(key, { value, count: 1 })\n }\n } finally {\n if (this.ttlCheck & TTLCheck.ON_RETAIN) this.removeExpired()\n }\n }\n\n release(key: K, value: V): void {\n try {\n const existing = this.map.get(key)\n\n // `release` might be called on an entry that remained unowned due being superseded by a new entry with the same\n // key after TTL expiration of the original entry; handle this gracefully\n if (existing == null) return\n if (isUnowned(existing)) return\n if (existing.value !== value) return\n\n if (existing.count > 1) {\n existing.count -= 1\n } else {\n this.map.delete(key)\n }\n } finally {\n if (this.ttlCheck & TTLCheck.ON_RELEASE) this.removeExpired()\n }\n }\n\n private removeExpired(): void {\n const now = Date.now()\n const isExpired = (entry: MapEntry<V>): boolean =>\n isUnowned(entry) && now - entry.accessedAt > this.unownedEntryTtlMs\n\n this.map.forEach((entry, key) => {\n if (isExpired(entry)) this.map.delete(key)\n })\n }\n}\n\nconst isUnowned = <V>(entry: MapEntry<V>): entry is UnownedMapEntry<V> => entry.count === undefined\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,MAAM,WAAW;AAAA,EACf,QAAQ,KAAK;AAAA,EACb,WAAW,KAAK;AAAA,EAChB,YAAY,KAAK;AACnB;AAOO,MAAM,cAAoB;AAAA,EACd,MAAM,oBAAI,IAAoB;AAAA,EAC9B;AAAA,EACA;AAAA,EAEjB,OAAgB,WAAW;AAAA,EAE3B,YAAY;AAAA,IACV;AAAA,IACA,WAAW,SAAS,SAAS,SAAS,YAAY,SAAS;AAAA,EAC7D,GAGG;AACD,SAAK,oBAAoB;AACzB,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK,IAAI;AAAA,EAClB;AAAA,EAEA,IAAI,KAAuB;AACzB,WAAO,KAAK,IAAI,IAAI,GAAG,GAAG;AAAA,EAC5B;AAAA,EAEA,YAAY,KAAQ,MAAkB;AAC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AAK,IAAI,QAAQ,CAAC,OAAO,QAAQ;AAC/B,UAAI,UAAU,KAAK;AAAG,aAAK,IAAI,OAAO,GAAG;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;AAEA,MAAM,YAAY,CAAI,UAAoD,MAAM,UAAU;","names":[]}
1
+ {"version":3,"sources":["../../../src/utils/ref-counted-map.ts"],"sourcesContent":["type RefCountedMapEntry<V> = {\n value: V\n count: number\n}\n\ntype UnownedMapEntry<V> = {\n value: V\n count: undefined\n accessedAt: number\n}\n\ntype MapEntry<V> = RefCountedMapEntry<V> | UnownedMapEntry<V>\n\nconst TTLCheck = {\n ON_GET: 1 << 0,\n ON_RETAIN: 1 << 1,\n ON_RELEASE: 1 << 2,\n} as const\n\n/**\n * Ref-counted map with explicit retention semantics. Entries are unowned by default and may be evicted after their\n * TTL unless explicitly retained. This provides TTL-based caching for unowned entries, while allowing consumers to\n * opt into stronger lifetime control via explicit retention.\n */\nexport class RefCountedMap<K, V> {\n private readonly map = new Map<K, MapEntry<V>>()\n private readonly unownedEntryTtlMs: number\n private readonly ttlCheck: number\n\n static readonly TTLCheck = TTLCheck\n\n constructor({\n unownedEntryTtlMs,\n ttlCheck = TTLCheck.ON_GET | TTLCheck.ON_RETAIN | TTLCheck.ON_RELEASE,\n }: {\n unownedEntryTtlMs: number\n ttlCheck?: number\n }) {\n this.unownedEntryTtlMs = unownedEntryTtlMs\n this.ttlCheck = ttlCheck\n }\n\n get size(): number {\n return this.map.size\n }\n\n get(key: K): V | undefined {\n return this.map.get(key)?.value\n }\n\n getOrCreate(key: K, init: () => V): V {\n try {\n const existing = this.map.get(key)\n\n if (existing) {\n if (isUnowned(existing)) existing.accessedAt = Date.now()\n return existing.value\n }\n\n const value = init()\n this.map.set(key, { value, count: undefined, accessedAt: Date.now() })\n return value\n } finally {\n if (this.ttlCheck & TTLCheck.ON_GET) this.removeExpired()\n }\n }\n\n /**\n * Returns true on transition from unowned to owned\n */\n retain(key: K, value: V): boolean {\n try {\n const existing = this.map.get(key)\n\n if (existing == null) {\n this.map.set(key, { value, count: 1 })\n return true\n }\n\n // `retain` might be called on a unowned entry that has already been evicted from the map due to TTL expiration\n // *and* possibly replaced by a new unowned entry with the same key; handle this gracefully\n if (existing.value === value) {\n existing.count = (existing.count ?? 0) + 1\n return existing.count === 1\n }\n\n return false\n } finally {\n if (this.ttlCheck & TTLCheck.ON_RETAIN) this.removeExpired()\n }\n }\n\n /**\n * Returns true on transition from owned to unowned\n */\n release(key: K, value: V): boolean {\n try {\n const existing = this.map.get(key)\n\n // `release` might be called on an entry that remained unowned due being superseded by a new entry with the same\n // key after TTL expiration of the original entry; handle this gracefully\n if (existing == null) return false\n if (isUnowned(existing)) return false\n if (existing.value !== value) return false\n\n if (existing.count === 1) {\n this.map.delete(key)\n return true\n }\n\n existing.count -= 1\n return false\n } finally {\n if (this.ttlCheck & TTLCheck.ON_RELEASE) this.removeExpired()\n }\n }\n\n private removeExpired(): void {\n const now = Date.now()\n const isExpired = (entry: MapEntry<V>): boolean =>\n isUnowned(entry) && now - entry.accessedAt > this.unownedEntryTtlMs\n\n this.map.forEach((entry, key) => {\n if (isExpired(entry)) this.map.delete(key)\n })\n }\n}\n\nconst isUnowned = <V>(entry: MapEntry<V>): entry is UnownedMapEntry<V> => entry.count === undefined\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,MAAM,WAAW;AAAA,EACf,QAAQ,KAAK;AAAA,EACb,WAAW,KAAK;AAAA,EAChB,YAAY,KAAK;AACnB;AAOO,MAAM,cAAoB;AAAA,EACd,MAAM,oBAAI,IAAoB;AAAA,EAC9B;AAAA,EACA;AAAA,EAEjB,OAAgB,WAAW;AAAA,EAE3B,YAAY;AAAA,IACV;AAAA,IACA,WAAW,SAAS,SAAS,SAAS,YAAY,SAAS;AAAA,EAC7D,GAGG;AACD,SAAK,oBAAoB;AACzB,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,OAAe;AACjB,W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S,SAAS;AAClB,aAAO;AAAA,IACT,UAAE;AACA,UAAI,KAAK,WAAW,SAAS;AAAY,aAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AAAA,EAEQ,gBAAsB;AAC5B,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,YAAY,CAAC,UACjB,UAAU,KAAK,KAAK,MAAM,MAAM,aAAa,KAAK;AAEpD,SAAK,IAAI,QAAQ,CAAC,OAAO,QAAQ;AAC/B,UAAI,UAAU,KAAK;AAAG,aAAK,IAAI,OAAO,GAAG;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;AAEA,MAAM,YAAY,CAAI,UAAoD,MAAM,UAAU;","names":[]}
@@ -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.4",
11
+ version: "0.28.5",
12
12
  interactionMode: true,
13
13
  clientSideNavigation: false,
14
14
  elementFromPoint: false,
@@ -198,7 +198,7 @@ Received "${apiKey}" instead.`
198
198
  }
199
199
  this.apiKey = apiKey;
200
200
  this.graphqlClient = new GraphQLClient(new URL("graphql", runtime.apiOrigin).href, {
201
- "makeswift-runtime-version": "0.28.4"
201
+ "makeswift-runtime-version": "0.28.5"
202
202
  });
203
203
  this.runtime = runtime;
204
204
  }
@@ -210,7 +210,7 @@ Received "${apiKey}" instead.`
210
210
  const requestHeaders = new Headers({
211
211
  "x-api-key": this.apiKey,
212
212
  "makeswift-site-api-key": this.apiKey,
213
- "makeswift-runtime-version": "0.28.4"
213
+ "makeswift-runtime-version": "0.28.5"
214
214
  });
215
215
  if (siteVersion?.token) {
216
216
  requestUrl.searchParams.set("version", siteVersion.version);
@@ -937,7 +937,7 @@ Received "${apiKey}" instead.`
937
937
  headers: {
938
938
  "x-api-key": this.apiKey,
939
939
  "makeswift-site-api-key": this.apiKey,
940
- "makeswift-runtime-version": "0.28.4",
940
+ "makeswift-runtime-version": "0.28.5",
941
941
  "content-type": "application/json"
942
942
  },
943
943
  body: JSON.stringify({ token }),
@@ -1,42 +1,14 @@
1
- import { useCallback, useSyncExternalStore } from "react";
2
- import {
3
- findBreakpointOverride,
4
- getBaseBreakpoint,
5
- getBreakpointMediaQuery
6
- } from "@makeswift/controls";
1
+ import { useMemo } from "react";
2
+ import { findBreakpointOverride } from "@makeswift/controls";
7
3
  import { useBreakpoints } from "../../runtimes/react/hooks/use-breakpoints";
8
- const getDeviceQueries = (breakpoints) => breakpoints.map((device) => ({
9
- id: device.id,
10
- query: getBreakpointMediaQuery(device).replace("@media", "")
11
- }));
4
+ import { useCurrentBreakpoint } from "../../runtimes/react/hooks/use-current-breakpoint";
12
5
  function useMediaQuery(responsiveValue) {
13
6
  const breakpoints = useBreakpoints();
14
- const baseBreakpointId = getBaseBreakpoint(breakpoints).id;
15
- const subscribe = useCallback(
16
- (notify) => {
17
- const cleanUpFns = getDeviceQueries(breakpoints).map((q) => {
18
- const mediaQueryList = window.matchMedia(q.query);
19
- mediaQueryList.addEventListener("change", notify);
20
- return () => mediaQueryList.removeEventListener("change", notify);
21
- });
22
- return () => cleanUpFns.forEach((fn) => fn());
23
- },
24
- [breakpoints]
7
+ const breakpointId = useCurrentBreakpoint();
8
+ return useMemo(
9
+ () => findBreakpointOverride(breakpoints, responsiveValue, breakpointId)?.value,
10
+ [breakpoints, breakpointId, responsiveValue]
25
11
  );
26
- const getServerSnapshot = () => findBreakpointOverride(breakpoints, responsiveValue, baseBreakpointId)?.value;
27
- function getSnapshot() {
28
- const deviceId = getDeviceQueries(breakpoints).reduce(
29
- (matchedDevice, deviceQueries) => {
30
- if (window.matchMedia(deviceQueries.query).matches) {
31
- return deviceQueries.id;
32
- }
33
- return matchedDevice;
34
- },
35
- baseBreakpointId
36
- );
37
- return findBreakpointOverride(breakpoints, responsiveValue, deviceId)?.value;
38
- }
39
- return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
40
12
  }
41
13
  export {
42
14
  useMediaQuery
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/hooks/useMediaQuery.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react'\nimport {\n type Breakpoints,\n type DeviceOverride,\n findBreakpointOverride,\n getBaseBreakpoint,\n getBreakpointMediaQuery,\n} from '@makeswift/controls'\n\nimport { useBreakpoints } from '../../runtimes/react/hooks/use-breakpoints'\n\nconst getDeviceQueries = (breakpoints: Breakpoints) =>\n breakpoints.map(device => ({\n id: device.id,\n query: getBreakpointMediaQuery(device).replace('@media', ''),\n }))\n\nexport function useMediaQuery<S>(responsiveValue?: Array<DeviceOverride<S>>): S | undefined {\n const breakpoints = useBreakpoints()\n const baseBreakpointId = getBaseBreakpoint(breakpoints).id\n const subscribe = useCallback(\n (notify: () => void) => {\n const cleanUpFns = getDeviceQueries(breakpoints).map(q => {\n const mediaQueryList = window.matchMedia(q.query)\n mediaQueryList.addEventListener('change', notify)\n return () => mediaQueryList.removeEventListener('change', notify)\n })\n return () => cleanUpFns.forEach(fn => fn())\n },\n [breakpoints],\n )\n const getServerSnapshot = () =>\n findBreakpointOverride(breakpoints, responsiveValue, baseBreakpointId)?.value\n\n function getSnapshot() {\n const deviceId: string = getDeviceQueries(breakpoints).reduce(\n (matchedDevice, deviceQueries) => {\n if (window.matchMedia(deviceQueries.query).matches) {\n return deviceQueries.id\n }\n return matchedDevice\n },\n baseBreakpointId,\n )\n return findBreakpointOverride(breakpoints, responsiveValue, deviceId)?.value\n }\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n}\n"],"mappings":"AAAA,SAAS,aAAa,4BAA4B;AAClD;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,sBAAsB;AAE/B,MAAM,mBAAmB,CAAC,gBACxB,YAAY,IAAI,aAAW;AAAA,EACzB,IAAI,OAAO;AAAA,EACX,OAAO,wBAAwB,MAAM,EAAE,QAAQ,UAAU,EAAE;AAC7D,EAAE;AAEG,SAAS,cAAiB,iBAA2D;AAC1F,QAAM,cAAc,eAAe;AACnC,QAAM,mBAAmB,kBAAkB,WAAW,EAAE;AACxD,QAAM,YAAY;AAAA,IAChB,CAAC,WAAuB;AACtB,YAAM,aAAa,iBAAiB,WAAW,EAAE,IAAI,OAAK;AACxD,cAAM,iBAAiB,OAAO,WAAW,EAAE,KAAK;AAChD,uBAAe,iBAAiB,UAAU,MAAM;AAChD,eAAO,MAAM,eAAe,oBAAoB,UAAU,MAAM;AAAA,MAClE,CAAC;AACD,aAAO,MAAM,WAAW,QAAQ,QAAM,GAAG,CAAC;AAAA,IAC5C;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AACA,QAAM,oBAAoB,MACxB,uBAAuB,aAAa,iBAAiB,gBAAgB,GAAG;AAE1E,WAAS,cAAc;AACrB,UAAM,WAAmB,iBAAiB,WAAW,EAAE;AAAA,MACrD,CAAC,eAAe,kBAAkB;AAChC,YAAI,OAAO,WAAW,cAAc,KAAK,EAAE,SAAS;AAClD,iBAAO,cAAc;AAAA,QACvB;AACA,eAAO;AAAA,MACT;AAAA,MACA;AAAA,IACF;AACA,WAAO,uBAAuB,aAAa,iBAAiB,QAAQ,GAAG;AAAA,EACzE;AAEA,SAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/components/hooks/useMediaQuery.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type DeviceOverride, findBreakpointOverride } from '@makeswift/controls'\n\nimport { useBreakpoints } from '../../runtimes/react/hooks/use-breakpoints'\nimport { useCurrentBreakpoint } from '../../runtimes/react/hooks/use-current-breakpoint'\n\nexport function useMediaQuery<S>(responsiveValue?: Array<DeviceOverride<S>>): S | undefined {\n const breakpoints = useBreakpoints()\n const breakpointId = useCurrentBreakpoint()\n return useMemo(\n () => findBreakpointOverride(breakpoints, responsiveValue, breakpointId)?.value,\n [breakpoints, breakpointId, responsiveValue],\n )\n}\n"],"mappings":"AAAA,SAAS,eAAe;AACxB,SAA8B,8BAA8B;AAE5D,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AAE9B,SAAS,cAAiB,iBAA2D;AAC1F,QAAM,cAAc,eAAe;AACnC,QAAM,eAAe,qBAAqB;AAC1C,SAAO;AAAA,IACL,MAAM,uBAAuB,aAAa,iBAAiB,YAAY,GAAG;AAAA,IAC1E,CAAC,aAAa,cAAc,eAAe;AAAA,EAC7C;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-breakpoints.ts"],"sourcesContent":["import { Breakpoints } from '../../../state/modules/breakpoints'\nimport { getBreakpoints } from '../../../state/read-only-state'\nimport { useSelector } from './use-selector'\n\nexport function useBreakpoints(): Breakpoints {\n return useSelector(state => getBreakpoints(state))\n}\n"],"mappings":"AACA,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAErB,SAAS,iBAA8B;AAC5C,SAAO,YAAY,WAAS,eAAe,KAAK,CAAC;AACnD;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-breakpoints.ts"],"sourcesContent":["import { type Breakpoints } from '../../../state/modules/breakpoints'\nimport { getBreakpoints } from '../../../state/read-only-state'\n\nimport { useSelector } from './use-selector'\n\nexport function useBreakpoints(): Breakpoints {\n return useSelector(state => getBreakpoints(state))\n}\n"],"mappings":"AACA,SAAS,sBAAsB;AAE/B,SAAS,mBAAmB;AAErB,SAAS,iBAA8B;AAC5C,SAAO,YAAY,WAAS,eAAe,KAAK,CAAC;AACnD;","names":[]}
@@ -0,0 +1,15 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { getBaseBreakpoint, getClientBreakpoint } from "../../../state/read-only-state";
3
+ import { useStore } from "./use-store";
4
+ function useCurrentBreakpoint() {
5
+ const store = useStore();
6
+ return useSyncExternalStore(
7
+ store.subscribe,
8
+ () => getClientBreakpoint(store.getState()),
9
+ () => getBaseBreakpoint(store.getState())
10
+ );
11
+ }
12
+ export {
13
+ useCurrentBreakpoint
14
+ };
15
+ //# sourceMappingURL=use-current-breakpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-current-breakpoint.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react'\n\nimport { type BreakpointId } from '../../../state/modules/breakpoints'\nimport { getBaseBreakpoint, getClientBreakpoint } from '../../../state/read-only-state'\n\nimport { useStore } from './use-store'\n\nexport function useCurrentBreakpoint(): BreakpointId {\n const store = useStore()\n\n return useSyncExternalStore(\n store.subscribe,\n () => getClientBreakpoint(store.getState()),\n () => getBaseBreakpoint(store.getState()),\n )\n}\n"],"mappings":"AAAA,SAAS,4BAA4B;AAGrC,SAAS,mBAAmB,2BAA2B;AAEvD,SAAS,gBAAgB;AAElB,SAAS,uBAAqC;AACnD,QAAM,QAAQ,SAAS;AAEvB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,oBAAoB,MAAM,SAAS,CAAC;AAAA,IAC1C,MAAM,kBAAkB,MAAM,SAAS,CAAC;AAAA,EAC1C;AACF;","names":[]}
@@ -69,7 +69,9 @@ class RuntimeCore {
69
69
  console.error("RuntimeCore: attempt to retain an ephemeral store", { key });
70
70
  return;
71
71
  }
72
- this.activeStores.retain(key, store);
72
+ if (this.activeStores.retain(key, store)) {
73
+ store.startBreakpointWatch();
74
+ }
73
75
  }
74
76
  releaseStore({ siteVersion, locale }, store) {
75
77
  const key = storeCacheKey({ siteVersion, locale });
@@ -77,7 +79,9 @@ class RuntimeCore {
77
79
  console.error("RuntimeCore: attempt to release an ephemeral store", { key });
78
80
  return;
79
81
  }
80
- this.activeStores.release(key, store);
82
+ if (this.activeStores.release(key, store)) {
83
+ store.stopBreakpointWatch();
84
+ }
81
85
  }
82
86
  copyElementTree(elementTree, replacementContext) {
83
87
  return copyElementTree(this.protoStore.getState(), elementTree, replacementContext);
@@ -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 {\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 received an invalid \\`${name}\\` parameter: \"${url}\".`)\n }\n}\n"],"mappings":"AAEA,SAAS,8BAA8B;AAIvC;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,uBAAuB;AAEhC,SAAS,sBAAsD;AAC/D;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAOzB,MAAM,mBAAmB;AAElB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,eAAe,IAAI,cAAoC;AAAA,IACtE,mBAAmB;AAAA;AAAA;AAAA;AAAA,IAInB,UAAU,cAAc,SAAS,YAAY,cAAc,SAAS;AAAA,EACtE,CAAC;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAMG;AACD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,aAAa;AAClB,SAAK,QAAQ;AAEb,SAAK,aAAa,oBAAoB;AAAA,MACpC,MAA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oBACS;AACT,WAAO,gBAAgB,KAAK,WAAW,SAAS,GAAG,aAAa,kBAAkB;AAAA,EACpF;AAAA,EAEA,iBAA8B;AAC5B,WAAO,eAAe,KAAK,WAAW,SAAS,CAAC;AAAA,EAClD;AAAA,EAEQ,yBAAyB,KAAsB;AAGrD,WAAO,CAAC,SAAS,KAAM,KAAK,eAAe,UAAa,cAAc,KAAK,UAAU,MAAM;AAAA,EAC7F;AACF;AAEA,MAAM,gBAAgB,CAAC,EAAE,aAAa,OAAO,MAC3C,GAAG,eAAe,WAAW,CAAC,IAAI,UAAU,SAAS;AAEvD,MAAM,iBAAiB,CAAC,gBACtB,aAAa,WAAW;AAE1B,SAAS,eAAe,KAAa,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
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 if (this.activeStores.retain(key, store)) {\n store.startBreakpointWatch()\n }\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 if (this.activeStores.release(key, store)) {\n store.stopBreakpointWatch()\n }\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 received an invalid \\`${name}\\` parameter: \"${url}\".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,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import { TestOrigins } from "../../../testing/fixtures";
2
2
  import { ReactRuntime } from "../react-runtime";
3
- function createReactRuntime() {
4
- return new ReactRuntime({ fetch, ...TestOrigins });
3
+ function createReactRuntime({ breakpoints } = {}) {
4
+ return new ReactRuntime({ fetch, breakpoints, ...TestOrigins });
5
5
  }
6
6
  export {
7
7
  createReactRuntime
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import { TestOrigins } from '../../../testing/fixtures'\nimport { ReactRuntime } from '../react-runtime'\n\nexport function createReactRuntime() {\n return new ReactRuntime({ fetch, ...TestOrigins })\n}\n"],"mappings":"AAAA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAEtB,SAAS,qBAAqB;AACnC,SAAO,IAAI,aAAa,EAAE,OAAO,GAAG,YAAY,CAAC;AACnD;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import { type BreakpointsInput } from '../../../state/modules/breakpoints'\nimport { TestOrigins } from '../../../testing/fixtures'\nimport { ReactRuntime } from '../react-runtime'\n\nexport function createReactRuntime({ breakpoints }: { breakpoints?: BreakpointsInput } = {}) {\n return new ReactRuntime({ fetch, breakpoints, ...TestOrigins })\n}\n"],"mappings":"AACA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAEtB,SAAS,mBAAmB,EAAE,YAAY,IAAwC,CAAC,GAAG;AAC3F,SAAO,IAAI,aAAa,EAAE,OAAO,aAAa,GAAG,YAAY,CAAC;AAChE;","names":[]}
@@ -14,6 +14,7 @@ const ReadOnlyActionTypes = {
14
14
  UNREGISTER_PROP_CONTROLLERS_HANDLE: "UNREGISTER_PROP_CONTROLLERS_HANDLE",
15
15
  REGISTER_REACT_COMPONENT: "REGISTER_REACT_COMPONENT",
16
16
  UNREGISTER_REACT_COMPONENT: "UNREGISTER_REACT_COMPONENT",
17
+ UPDATE_CLIENT_BREAKPOINT: "UPDATE_CLIENT_BREAKPOINT",
17
18
  SET_IS_IN_BUILDER: "SET_IS_IN_BUILDER",
18
19
  SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
19
20
  };
@@ -107,6 +108,9 @@ function registerReactComponentEffect(type, component) {
107
108
  };
108
109
  };
109
110
  }
111
+ function updateClientBreakpoint() {
112
+ return { type: ReadOnlyActionTypes.UPDATE_CLIENT_BREAKPOINT };
113
+ }
110
114
  function setIsInBuilder(isInBuilder) {
111
115
  return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder };
112
116
  }
@@ -129,6 +133,7 @@ export {
129
133
  setIsReadOnly,
130
134
  unregisterComponent,
131
135
  unregisterPropControllers,
132
- unregisterPropControllersHandle
136
+ unregisterPropControllersHandle,
137
+ updateClientBreakpoint
133
138
  };
134
139
  //# sourceMappingURL=read-only-actions.js.map
@@ -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 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_ONLY, payload: isReadOnly }\n}\n"],"mappings":"AAgBO,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;AACpB;AA2GO,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,MAAM,yBAAyB,C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,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;","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 UPDATE_CLIENT_BREAKPOINT: 'UPDATE_CLIENT_BREAKPOINT',\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 UpdateClientBreakpointAction = {\n type: typeof ReadOnlyActionTypes.UPDATE_CLIENT_BREAKPOINT\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 | UpdateClientBreakpointAction\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 updateClientBreakpoint(): UpdateClientBreakpointAction {\n return { type: ReadOnlyActionTypes.UPDATE_CLIENT_BREAKPOINT }\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"],"mappings":"AAgBO,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,0BAA0B;AAAA,EAE1B,mBAAmB;AAAA,EACnB,kBAAkB;AACpB;AAgHO,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,MAAM,yBAAyB,CAAC;AAEjE,WAAO,MAAM;AACX,eAAS,oBAAoB,IAAI,CAAC;AAAA,IACpC;AAAA,EACF;AACF;AAEO,SAAS,wBACd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;AAEhD,WAAO,MAAM;AACX,eAAS,yBAAyB,IAAI,CAAC;AAAA,IACzC;AAAA,EACF;AACF;AAEO,SAAS,yBAAuD;AACrE,SAAO,EAAE,MAAM,oBAAoB,yBAAyB;AAC9D;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;","names":[]}
@@ -0,0 +1,48 @@
1
+ import { updateClientBreakpoint } from "../actions/internal/read-only-actions";
2
+ import { getDeviceQueries } from "../modules/breakpoints";
3
+ import { getBreakpoints } from "../read-only-state";
4
+ function breakpointWatchMixin({
5
+ dispatch,
6
+ getState,
7
+ subscribe: storeSubscribe
8
+ }) {
9
+ let mediaQueryUnsubscribes = [];
10
+ let storeUnsubscribe = null;
11
+ let watchedBreakpoints = [];
12
+ const startWatch = (breakpoints) => {
13
+ mediaQueryUnsubscribes.forEach((fn) => fn());
14
+ const updateState = () => dispatch(updateClientBreakpoint());
15
+ mediaQueryUnsubscribes = getDeviceQueries(breakpoints).map((q) => {
16
+ const mediaQueryList = window.matchMedia(q.query);
17
+ mediaQueryList.addEventListener("change", updateState);
18
+ return () => mediaQueryList.removeEventListener("change", updateState);
19
+ });
20
+ watchedBreakpoints = breakpoints;
21
+ updateState();
22
+ };
23
+ return {
24
+ startBreakpointWatch: () => {
25
+ if (storeUnsubscribe !== null) {
26
+ console.warn("Unexpected `BreakpointWatch.startBreakpointWatch` call, already watching");
27
+ return;
28
+ }
29
+ startWatch(getBreakpoints(getState()));
30
+ storeUnsubscribe = storeSubscribe(() => {
31
+ const breakpoints = getBreakpoints(getState());
32
+ if (breakpoints !== watchedBreakpoints) {
33
+ startWatch(breakpoints);
34
+ }
35
+ });
36
+ },
37
+ stopBreakpointWatch: () => {
38
+ mediaQueryUnsubscribes.forEach((fn) => fn());
39
+ mediaQueryUnsubscribes = [];
40
+ storeUnsubscribe?.();
41
+ storeUnsubscribe = null;
42
+ }
43
+ };
44
+ }
45
+ export {
46
+ breakpointWatchMixin
47
+ };
48
+ //# sourceMappingURL=breakpoint-watch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/state/mixins/breakpoint-watch.ts"],"sourcesContent":["import { updateClientBreakpoint } from '../actions/internal/read-only-actions'\nimport { Breakpoints, getDeviceQueries } from '../modules/breakpoints'\n\nimport { type State, type Dispatch } from '../unified-state'\nimport { getBreakpoints } from '../read-only-state'\n\nexport interface BreakpointWatch {\n startBreakpointWatch(): void\n stopBreakpointWatch(): void\n}\n\nexport function breakpointWatchMixin({\n dispatch,\n getState,\n subscribe: storeSubscribe,\n}: {\n dispatch: Dispatch\n getState: () => State\n subscribe: (listener: VoidFunction) => VoidFunction\n}): BreakpointWatch {\n let mediaQueryUnsubscribes: VoidFunction[] = []\n let storeUnsubscribe: VoidFunction | null = null\n let watchedBreakpoints: Breakpoints = []\n\n // client-side breakpoint watch\n const startWatch = (breakpoints: Breakpoints) => {\n mediaQueryUnsubscribes.forEach(fn => fn())\n\n const updateState = () => dispatch(updateClientBreakpoint())\n\n mediaQueryUnsubscribes = getDeviceQueries(breakpoints).map(q => {\n const mediaQueryList = window.matchMedia(q.query)\n mediaQueryList.addEventListener('change', updateState)\n return () => mediaQueryList.removeEventListener('change', updateState)\n })\n\n watchedBreakpoints = breakpoints\n\n // reconcile the store with the current client breakpoint after subscribing;\n // this heals any stale breakpoint state from changes that happened\n // after the store was created or updated but before the listeners were attached\n updateState()\n }\n\n return {\n startBreakpointWatch: () => {\n if (storeUnsubscribe !== null) {\n console.warn('Unexpected `BreakpointWatch.startBreakpointWatch` call, already watching')\n return\n }\n\n startWatch(getBreakpoints(getState()))\n\n storeUnsubscribe = storeSubscribe(() => {\n const breakpoints = getBreakpoints(getState())\n if (breakpoints !== watchedBreakpoints) {\n startWatch(breakpoints)\n }\n })\n },\n\n stopBreakpointWatch: () => {\n mediaQueryUnsubscribes.forEach(fn => fn())\n mediaQueryUnsubscribes = []\n\n storeUnsubscribe?.()\n storeUnsubscribe = null\n },\n }\n}\n"],"mappings":"AAAA,SAAS,8BAA8B;AACvC,SAAsB,wBAAwB;AAG9C,SAAS,sBAAsB;AAOxB,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAIoB;AAClB,MAAI,yBAAyC,CAAC;AAC9C,MAAI,mBAAwC;AAC5C,MAAI,qBAAkC,CAAC;AAGvC,QAAM,aAAa,CAAC,gBAA6B;AAC/C,2BAAuB,QAAQ,QAAM,GAAG,CAAC;AAEzC,UAAM,cAAc,MAAM,SAAS,uBAAuB,CAAC;AAE3D,6BAAyB,iBAAiB,WAAW,EAAE,IAAI,OAAK;AAC9D,YAAM,iBAAiB,OAAO,WAAW,EAAE,KAAK;AAChD,qBAAe,iBAAiB,UAAU,WAAW;AACrD,aAAO,MAAM,eAAe,oBAAoB,UAAU,WAAW;AAAA,IACvE,CAAC;AAED,yBAAqB;AAKrB,gBAAY;AAAA,EACd;AAEA,SAAO;AAAA,IACL,sBAAsB,MAAM;AAC1B,UAAI,qBAAqB,MAAM;AAC7B,gBAAQ,KAAK,0EAA0E;AACvF;AAAA,MACF;AAEA,iBAAW,eAAe,SAAS,CAAC,CAAC;AAErC,yBAAmB,eAAe,MAAM;AACtC,cAAM,cAAc,eAAe,SAAS,CAAC;AAC7C,YAAI,gBAAgB,oBAAoB;AACtC,qBAAW,WAAW;AAAA,QACxB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEA,qBAAqB,MAAM;AACzB,6BAAuB,QAAQ,QAAM,GAAG,CAAC;AACzC,+BAAyB,CAAC;AAE1B,yBAAmB;AACnB,yBAAmB;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}