@makeswift/runtime 0.28.3-canary.3 → 0.28.3-canary.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/client.js +2 -4
- package/dist/cjs/api/client.js.map +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/builder/core/index.js.map +1 -1
- package/dist/cjs/client/index.js +15 -18
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/components/builtin/Box/Box.js +2 -1
- package/dist/cjs/components/builtin/Box/Box.js.map +1 -1
- package/dist/cjs/controls/rich-text/control.js.map +1 -1
- package/dist/cjs/controls/rich-text-v2/control.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/cjs/prop-controllers/instances.js.map +1 -1
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js +11 -7
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/element-imperative-handle.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-store.js +9 -2
- package/dist/cjs/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
- package/dist/cjs/runtimes/react/host-api-client.js +2 -2
- package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
- package/dist/cjs/runtimes/react/poll-box-model.js.map +1 -1
- package/dist/cjs/runtimes/react/react-runtime-core.js +2 -2
- package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/react-runtime.js.map +1 -1
- package/dist/cjs/runtimes/react/runtime-core.js +62 -26
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-only-actions.js +1 -15
- package/dist/cjs/state/actions/internal/read-only-actions.js.map +1 -1
- package/dist/cjs/state/builder-api/actions.js.map +1 -1
- package/dist/cjs/state/makeswift-api-client.js +3 -27
- package/dist/cjs/state/makeswift-api-client.js.map +1 -1
- package/dist/cjs/state/middleware/read-write/builder-api/index.js +8 -2
- package/dist/cjs/state/middleware/read-write/builder-api/index.js.map +1 -1
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js +6 -8
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
- package/dist/cjs/state/modules/locale.js +0 -3
- package/dist/cjs/state/modules/locale.js.map +1 -1
- package/dist/cjs/state/modules/read-write/box-models.js +17 -2
- package/dist/cjs/state/modules/read-write/box-models.js.map +1 -1
- package/dist/cjs/state/modules/site-version.js +0 -3
- package/dist/cjs/state/modules/site-version.js.map +1 -1
- package/dist/cjs/state/read-only-state.js +8 -1
- package/dist/cjs/state/read-only-state.js.map +1 -1
- package/dist/cjs/state/read-write-state.js.map +1 -1
- package/dist/cjs/state/store.js +75 -48
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/cjs/unstable-framework-support/index.js.map +1 -1
- package/dist/cjs/utils/ref-counted-map.js +111 -0
- package/dist/cjs/utils/ref-counted-map.js.map +1 -0
- package/dist/esm/api/client.js +2 -4
- package/dist/esm/api/client.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/builder/core/index.js.map +1 -1
- package/dist/esm/client/index.js +15 -18
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/components/builtin/Box/Box.js +7 -2
- package/dist/esm/components/builtin/Box/Box.js.map +1 -1
- package/dist/esm/controls/rich-text/control.js.map +1 -1
- package/dist/esm/controls/rich-text-v2/control.js.map +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/esm/prop-controllers/instances.js.map +1 -1
- package/dist/esm/runtimes/react/components/RuntimeProvider.js +12 -8
- package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/esm/runtimes/react/element-imperative-handle.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-store.js +8 -2
- package/dist/esm/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
- package/dist/esm/runtimes/react/host-api-client.js +2 -2
- package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
- package/dist/esm/runtimes/react/poll-box-model.js.map +1 -1
- package/dist/esm/runtimes/react/react-runtime-core.js +2 -2
- package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/react-runtime.js.map +1 -1
- package/dist/esm/runtimes/react/runtime-core.js +65 -30
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/state/actions/internal/read-only-actions.js +1 -13
- package/dist/esm/state/actions/internal/read-only-actions.js.map +1 -1
- package/dist/esm/state/builder-api/actions.js.map +1 -1
- package/dist/esm/state/makeswift-api-client.js +4 -28
- package/dist/esm/state/makeswift-api-client.js.map +1 -1
- package/dist/esm/state/middleware/read-write/builder-api/index.js +8 -2
- package/dist/esm/state/middleware/read-write/builder-api/index.js.map +1 -1
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js +6 -8
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
- package/dist/esm/state/modules/locale.js +0 -3
- package/dist/esm/state/modules/locale.js.map +1 -1
- package/dist/esm/state/modules/read-write/box-models.js +16 -2
- package/dist/esm/state/modules/read-write/box-models.js.map +1 -1
- package/dist/esm/state/modules/site-version.js +0 -3
- package/dist/esm/state/modules/site-version.js.map +1 -1
- package/dist/esm/state/read-only-state.js +7 -1
- package/dist/esm/state/read-only-state.js.map +1 -1
- package/dist/esm/state/read-write-state.js.map +1 -1
- package/dist/esm/state/store.js +74 -47
- package/dist/esm/state/store.js.map +1 -1
- package/dist/esm/unstable-framework-support/index.js.map +1 -1
- package/dist/esm/utils/ref-counted-map.js +87 -0
- package/dist/esm/utils/ref-counted-map.js.map +1 -0
- package/dist/types/api/client.d.ts +2 -2
- package/dist/types/api/client.d.ts.map +1 -1
- package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts +6 -6
- package/dist/types/api-handler/handlers/webhook/types.d.ts +20 -20
- package/dist/types/builder/core/index.d.ts +1 -1
- package/dist/types/builder/core/index.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -0
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/components/builtin/Box/Box.d.ts.map +1 -1
- package/dist/types/controls/rich-text/control.d.ts +3 -3
- package/dist/types/controls/rich-text/control.d.ts.map +1 -1
- package/dist/types/controls/rich-text-v2/control.d.ts +3 -3
- package/dist/types/controls/rich-text-v2/control.d.ts.map +1 -1
- package/dist/types/prop-controllers/instances.d.ts +5 -6
- package/dist/types/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/element-imperative-handle.d.ts +2 -3
- package/dist/types/runtimes/react/element-imperative-handle.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-store.d.ts +29 -0
- package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
- package/dist/types/runtimes/react/poll-box-model.d.ts +2 -2
- package/dist/types/runtimes/react/poll-box-model.d.ts.map +1 -1
- package/dist/types/runtimes/react/react-runtime.d.ts +1 -0
- package/dist/types/runtimes/react/react-runtime.d.ts.map +1 -1
- package/dist/types/runtimes/react/runtime-core.d.ts +15 -13
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/state/__tests__/test-store.d.ts +4 -2
- package/dist/types/state/__tests__/test-store.d.ts.map +1 -1
- package/dist/types/state/actions/index.d.ts +0 -2
- package/dist/types/state/actions/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/index.d.ts +0 -2
- package/dist/types/state/actions/internal/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-only-actions.d.ts +1 -13
- package/dist/types/state/actions/internal/read-only-actions.d.ts.map +1 -1
- package/dist/types/state/builder-api/actions.d.ts +3 -3
- package/dist/types/state/builder-api/actions.d.ts.map +1 -1
- package/dist/types/state/makeswift-api-client.d.ts +2 -2
- package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
- package/dist/types/state/middleware/read-write/builder-api/index.d.ts.map +1 -1
- package/dist/types/state/middleware/read-write/builder-api/initialize-connection.d.ts.map +1 -1
- package/dist/types/state/modules/locale.d.ts.map +1 -1
- package/dist/types/state/modules/read-write/box-models.d.ts +12 -9
- package/dist/types/state/modules/read-write/box-models.d.ts.map +1 -1
- package/dist/types/state/modules/site-version.d.ts.map +1 -1
- package/dist/types/state/read-only-state.d.ts +6 -2
- package/dist/types/state/read-only-state.d.ts.map +1 -1
- package/dist/types/state/read-write-state.d.ts +6 -4
- package/dist/types/state/read-write-state.d.ts.map +1 -1
- package/dist/types/state/store.d.ts +47 -14
- package/dist/types/state/store.d.ts.map +1 -1
- package/dist/types/unstable-framework-support/index.d.ts +1 -1
- package/dist/types/unstable-framework-support/index.d.ts.map +1 -1
- package/dist/types/utils/__tests__/ref-counted-map.test.d.ts +2 -0
- package/dist/types/utils/__tests__/ref-counted-map.test.d.ts.map +1 -0
- package/dist/types/utils/ref-counted-map.d.ts +26 -0
- package/dist/types/utils/ref-counted-map.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type BoxDisplayModel,\n type Breakpoints,\n type Stylesheet,\n type ResolvedStyle,\n type ResolvedStyleV2,\n type ResolvedTypographyStyle,\n isNotNil,\n getBaseBreakpoint,\n getBreakpointMediaQuery,\n} from '@makeswift/controls'\n\nimport { useCache } from '../root-style-registry'\nimport { styleV1Css } from '../controls/style'\nimport { typographyCss } from '../controls/typography'\n\nimport { useBreakpoints } from './use-breakpoints'\nimport { useCssId } from './use-css-id'\nimport { useStyles, serializedStyleClassName } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport type StylesheetFactory = {\n get(propName: string): Stylesheet\n useDefinedStyles(): void\n}\n\nexport function useStylesheetFactory(): StylesheetFactory {\n const breakpoints = useBreakpoints()\n const cache = useCache()\n const componentUid = useCssId()\n\n const computedStyles = useRef<Record<string, SerializedStyles>>({}).current\n const boxModelCallbacks = useRef<Record<string, (boxModel: BoxDisplayModel | null) => void>>({}).current\n\n return useMemo(() => {\n const getStylesheet = (styleSheetId: string): Stylesheet => ({\n breakpoints(): Breakpoints {\n return breakpoints\n },\n\n defineStyle(\n style: ResolvedStyle,\n onBoxModelChange?: (boxModel: BoxDisplayModel | null) => void,\n ): string {\n const serialized = serializeStyle(breakpoints, style, cache)\n const uid = `u-${componentUid}-${styleSheetId}`\n computedStyles[uid] = serialized\n\n const className = serializedStyleClassName(cache, serialized)\n if (!onBoxModelChange) return className\n\n boxModelCallbacks[uid] = onBoxModelChange\n return `${className} ${uid}`\n },\n\n child(id: string): Stylesheet {\n return getStylesheet(`${styleSheetId}-${id}`)\n },\n })\n\n return {\n get(propName: string): Stylesheet {\n return getStylesheet(propName)\n },\n\n useDefinedStyles() {\n useStyles(cache, Object.values(computedStyles))\n\n useEffect(() => {\n const unsubscribes = Object.entries(boxModelCallbacks)\n .map(([uid, callback]) =>\n callback != null\n ? pollBoxModel({\n element: document.querySelector(`.${uid}`),\n onBoxModelChange: callback,\n })\n : undefined,\n )\n .filter(isNotNil)\n\n return () => unsubscribes.forEach(fn => fn())\n }, [Object.keys(boxModelCallbacks).join(' ')])\n },\n }\n }, [breakpoints, cache, componentUid])\n}\n\nfunction isTypographyStyle(style: ResolvedStyle): style is ResolvedTypographyStyle {\n return Array.isArray(style)\n}\n\nfunction isStyleV2(style: ResolvedStyle): style is ResolvedStyleV2 {\n return typeof style === 'object' && 'getStyle' in style && typeof style.getStyle === 'function'\n}\n\nfunction styleV2Css(breakpoints: Breakpoints, style: ResolvedStyleV2<CSSObject>): CSSObject {\n return {\n ...style.getStyle(getBaseBreakpoint(breakpoints)),\n ...breakpoints.reduce(\n (styles, breakpoint) => ({\n ...styles,\n [getBreakpointMediaQuery(breakpoint)]: style.getStyle(breakpoint),\n }),\n {},\n ),\n }\n}\n\nfunction resolvedStyleToCss(breakpoints: Breakpoints, style: ResolvedStyle) {\n if (isTypographyStyle(style)) {\n return typographyCss(breakpoints, style)\n }\n\n if (isStyleV2(style)) {\n return styleV2Css(breakpoints, style as ResolvedStyleV2<CSSObject>)\n }\n\n const { properties, styleData } = style\n return styleV1Css(breakpoints, styleData, properties)\n}\n\nfunction serializeStyle(\n breakpoints: Breakpoints,\n style: ResolvedStyle,\n cache: EmotionCache,\n): SerializedStyles {\n const css = resolvedStyleToCss(breakpoints, style)\n return serializeStyles([css], cache.registered)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,cAAc;AAC3C,SAAyB,uBAAuB;AAIhD;AAAA,EAOE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAE9B,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,WAAW,gCAAgC;AACpD,SAAS,oBAAoB;AAOtB,SAAS,uBAA0C;AACxD,QAAM,cAAc,eAAe;AACnC,QAAM,QAAQ,SAAS;AACvB,QAAM,eAAe,SAAS;AAE9B,QAAM,iBAAi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UAAU,OAAgD;AACjE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,OAAO,MAAM,aAAa;AACvF;AAEA,SAAS,WAAW,aAA0B,OAA8C;AAC1F,SAAO;AAAA,IACL,GAAG,MAAM,SAAS,kBAAkB,WAAW,CAAC;AAAA,IAChD,GAAG,YAAY;AAAA,MACb,CAAC,QAAQ,gBAAgB;AAAA,QACvB,GAAG;AAAA,QACH,CAAC,wBAAwB,UAAU,CAAC,GAAG,MAAM,SAAS,UAAU;AAAA,MAClE;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,mBAAmB,aAA0B,OAAsB;AAC1E,MAAI,kBAAkB,KAAK,GAAG;AAC5B,WAAO,cAAc,aAAa,KAAK;AAAA,EACzC;AAEA,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO,WAAW,aAAa,KAAmC;AAAA,EACpE;AAEA,QAAM,EAAE,YAAY,UAAU,IAAI;AAClC,SAAO,WAAW,aAAa,WAAW,UAAU;AACtD;AAEA,SAAS,eACP,aACA,OACA,OACkB;AAClB,QAAM,MAAM,mBAAmB,aAAa,KAAK;AACjD,SAAO,gBAAgB,CAAC,GAAG,GAAG,MAAM,UAAU;AAChD;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useStore } from "./hooks/use-store";
|
|
3
3
|
function useMakeswiftHostApiClient() {
|
|
4
|
-
return
|
|
4
|
+
return useStore().hostApiClient;
|
|
5
5
|
}
|
|
6
6
|
export {
|
|
7
7
|
useMakeswiftHostApiClient
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport { useStore } from './hooks/use-store'\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useStore().hostApiClient\n}\n"],"mappings":";AAIA,SAAS,gBAAgB;AAElB,SAAS,4BAAoD;AAClE,SAAO,SAAS,EAAE;AACpB;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/poll-box-model.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/poll-box-model.ts"],"sourcesContent":["import { BoxDisplayModel, getBox } from '../../state/modules/read-write/box-models'\nimport deepEqual from '../../utils/deepEqual'\n\nexport function pollBoxModel({\n element,\n onBoxModelChange,\n}: {\n element: Element | null\n onBoxModelChange(boxModel: BoxDisplayModel | null): void\n}): () => void {\n let currentBoxModel: BoxDisplayModel | null = null\n\n const handleAnimationFrameRequest = () => {\n const measuredBoxModel = element == null ? null : getBox(element)\n\n if (!deepEqual(currentBoxModel, measuredBoxModel)) {\n currentBoxModel = measuredBoxModel\n\n onBoxModelChange(currentBoxModel)\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n\n onBoxModelChange(null)\n }\n}\n"],"mappings":"AAAA,SAA0B,cAAc;AACxC,OAAO,eAAe;AAEf,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGe;AACb,MAAI,kBAA0C;AAE9C,QAAM,8BAA8B,MAAM;AACxC,UAAM,mBAAmB,WAAW,OAAO,OAAO,OAAO,OAAO;AAEhE,QAAI,CAAC,UAAU,iBAAiB,gBAAgB,GAAG;AACjD,wBAAkB;AAElB,uBAAiB,eAAe;AAAA,IAClC;AAEA,2BAAuB,sBAAsB,2BAA2B;AAAA,EAC1E;AAEA,MAAI,uBAAuB,sBAAsB,2BAA2B;AAE5E,SAAO,MAAM;AACX,yBAAqB,oBAAoB;AAEzC,qBAAiB,IAAI;AAAA,EACvB;AACF;","names":[]}
|
|
@@ -24,7 +24,7 @@ class ReactRuntimeCore extends RuntimeCore {
|
|
|
24
24
|
props
|
|
25
25
|
}) {
|
|
26
26
|
validateComponentType(type, component);
|
|
27
|
-
const unregisterComponent = this.
|
|
27
|
+
const unregisterComponent = this.protoStore.dispatch(
|
|
28
28
|
registerComponentEffect(
|
|
29
29
|
type,
|
|
30
30
|
{ label, icon, hidden, description, builtinSuspense },
|
|
@@ -36,7 +36,7 @@ class ReactRuntimeCore extends RuntimeCore {
|
|
|
36
36
|
"builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>."
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
const unregisterReactComponent = this.
|
|
39
|
+
const unregisterReactComponent = this.protoStore.dispatch(
|
|
40
40
|
registerReactComponentEffect(type, component)
|
|
41
41
|
);
|
|
42
42
|
return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"sourcesContent":["import { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls'\n\nimport { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors'\n\nimport { supportsActivity } from './components/activity-with-fallback'\n\nimport {\n registerComponentEffect,\n registerReactComponentEffect,\n} from '../../state/actions/internal/read-only-actions'\n\nimport { ComponentIcon } from '../../state/modules/components-meta'\nimport type { ComponentType } from '../../state/read-only-state'\n\nimport { RuntimeCore } from './runtime-core'\n\nfunction validateComponentType(type: string, component?: ComponentType): void {\n const componentName = component?.name ?? 'Component'\n if (typeof type !== 'string' || type === '') {\n throw new Error(\n `${componentName}: A non-empty string \\`type\\` is required for component registration, got ${type}`,\n )\n }\n}\n\nexport class ReactRuntimeCore extends RuntimeCore {\n registerComponent<\n ControlDef extends UnifiedControlDefinition,\n P extends Record<string, LegacyDescriptor | ControlDef>,\n C extends ComponentType<{ [K in keyof P]: DescriptorValueType<P[K]> }>,\n >(\n component: C,\n {\n type,\n label,\n icon = ComponentIcon.Cube,\n hidden = false,\n description,\n builtinSuspense,\n props,\n }: {\n type: string\n label: string\n icon?: ComponentIcon\n hidden?: boolean\n description?: string\n /**\n * In React <= 19.1, controls the default `<Suspense>` boundary.\n * Ignored in React >= 19.2; components are always wrapped in `<Activity>`.\n * Defaults to `true`.\n */\n builtinSuspense?: boolean\n props?: P\n },\n ): () => void {\n validateComponentType(type, component as unknown as ComponentType)\n\n const unregisterComponent = this.
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"sourcesContent":["import { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls'\n\nimport { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors'\n\nimport { supportsActivity } from './components/activity-with-fallback'\n\nimport {\n registerComponentEffect,\n registerReactComponentEffect,\n} from '../../state/actions/internal/read-only-actions'\n\nimport { ComponentIcon } from '../../state/modules/components-meta'\nimport type { ComponentType } from '../../state/read-only-state'\n\nimport { RuntimeCore } from './runtime-core'\n\nfunction validateComponentType(type: string, component?: ComponentType): void {\n const componentName = component?.name ?? 'Component'\n if (typeof type !== 'string' || type === '') {\n throw new Error(\n `${componentName}: A non-empty string \\`type\\` is required for component registration, got ${type}`,\n )\n }\n}\n\nexport class ReactRuntimeCore extends RuntimeCore {\n registerComponent<\n ControlDef extends UnifiedControlDefinition,\n P extends Record<string, LegacyDescriptor | ControlDef>,\n C extends ComponentType<{ [K in keyof P]: DescriptorValueType<P[K]> }>,\n >(\n component: C,\n {\n type,\n label,\n icon = ComponentIcon.Cube,\n hidden = false,\n description,\n builtinSuspense,\n props,\n }: {\n type: string\n label: string\n icon?: ComponentIcon\n hidden?: boolean\n description?: string\n /**\n * In React <= 19.1, controls the default `<Suspense>` boundary.\n * Ignored in React >= 19.2; components are always wrapped in `<Activity>`.\n * Defaults to `true`.\n */\n builtinSuspense?: boolean\n props?: P\n },\n ): () => void {\n validateComponentType(type, component as unknown as ComponentType)\n\n const unregisterComponent = this.protoStore.dispatch(\n registerComponentEffect(\n type,\n { label, icon, hidden, description, builtinSuspense },\n props ?? {},\n ),\n )\n\n if (supportsActivity() && builtinSuspense !== undefined) {\n console.warn(\n 'builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>.',\n )\n }\n\n const unregisterReactComponent = this.protoStore.dispatch(\n registerReactComponentEffect(type, component as unknown as ComponentType),\n )\n\n return () => {\n unregisterComponent()\n unregisterReactComponent()\n }\n }\n}\n"],"mappings":"AAIA,SAAS,wBAAwB;AAEjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB;AAG9B,SAAS,mBAAmB;AAE5B,SAAS,sBAAsB,MAAc,WAAiC;AAC5E,QAAM,gBAAgB,WAAW,QAAQ;AACzC,MAAI,OAAO,SAAS,YAAY,SAAS,IAAI;AAC3C,UAAM,IAAI;AAAA,MACR,GAAG,aAAa,6EAA6E,IAAI;AAAA,IACnG;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,YAAY;AAAA,EAChD,kBAKE,WACA;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAcY;AACZ,0BAAsB,MAAM,SAAqC;AAEjE,UAAM,sBAAsB,KAAK,WAAW;AAAA,MAC1C;AAAA,QACE;AAAA,QACA,EAAE,OAAO,MAAM,QAAQ,aAAa,gBAAgB;AAAA,QACpD,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAEA,QAAI,iBAAiB,KAAK,oBAAoB,QAAW;AACvD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,2BAA2B,KAAK,WAAW;AAAA,MAC/C,6BAA6B,MAAM,SAAqC;AAAA,IAC1E;AAEA,WAAO,MAAM;AACX,0BAAoB;AACpB,+BAAyB;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/react-runtime.ts"],"sourcesContent":["import { registerBuiltinComponents } from '../../components/builtin/register'\nimport { ReactRuntimeCore } from './react-runtime-core'\n\nexport class ReactRuntime extends ReactRuntimeCore {\n constructor(...args: ConstructorParameters<typeof ReactRuntimeCore>) {\n super(...args)\n registerBuiltinComponents(this)\n }\n}\n"],"mappings":"AAAA,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/react-runtime.ts"],"sourcesContent":["import { registerBuiltinComponents } from '../../components/builtin/register'\nimport { ReactRuntimeCore } from './react-runtime-core'\n\nexport { type StoreKey } from './runtime-core'\n\nexport class ReactRuntime extends ReactRuntimeCore {\n constructor(...args: ConstructorParameters<typeof ReactRuntimeCore>) {\n super(...args)\n registerBuiltinComponents(this)\n }\n}\n"],"mappings":"AAAA,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;AAI1B,MAAM,qBAAqB,iBAAiB;AAAA,EACjD,eAAe,MAAsD;AACnE,UAAM,GAAG,IAAI;AACb,8BAA0B,IAAI;AAAA,EAChC;AACF;","names":[]}
|
|
@@ -4,58 +4,93 @@ import {
|
|
|
4
4
|
} from "../../state/modules/breakpoints";
|
|
5
5
|
import { copyElementTree } from "../../state/ops/copy-element-tree";
|
|
6
6
|
import { getBreakpoints } from "../../state/read-only-state";
|
|
7
|
-
import { configureStore } from "../../state/store";
|
|
8
|
-
import { setLocale } from "../../builder";
|
|
9
7
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "../../
|
|
8
|
+
configureProtoStore,
|
|
9
|
+
configureReadWriteStore
|
|
10
|
+
} from "../../state/store";
|
|
11
|
+
import { RefCountedMap } from "../../utils/ref-counted-map";
|
|
12
|
+
import { isServer } from "../../utils/is-server";
|
|
13
|
+
const VERSION_TAG_LIVE = "ref:live";
|
|
14
14
|
class RuntimeCore {
|
|
15
|
-
store
|
|
16
|
-
|
|
15
|
+
// The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays
|
|
16
|
+
// in the map. If an entry expires and is removed from the map before React commits, the store remains retained
|
|
17
|
+
// via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of
|
|
18
|
+
// reusing the existing one, reducing cache efficiency.
|
|
19
|
+
activeStores = new RefCountedMap({
|
|
20
|
+
unownedEntryTtlMs: 1e3,
|
|
21
|
+
// Checking on retain/release is sufficient on the client, and we don't need to check on get on the server
|
|
22
|
+
// as the only scenario in which we add the store to the map is when the runtime is already bound to the
|
|
23
|
+
// requested site version, which should be the only site version for which the store is requested
|
|
24
|
+
ttlCheck: RefCountedMap.TTLCheck.ON_RETAIN | RefCountedMap.TTLCheck.ON_RELEASE
|
|
25
|
+
});
|
|
26
|
+
protoStore;
|
|
17
27
|
appOrigin;
|
|
18
28
|
apiOrigin;
|
|
29
|
+
requestKey;
|
|
30
|
+
fetch;
|
|
19
31
|
constructor({
|
|
20
32
|
appOrigin = "https://app.makeswift.com",
|
|
21
33
|
apiOrigin = "https://api.makeswift.com",
|
|
22
34
|
breakpoints,
|
|
35
|
+
requestKey,
|
|
23
36
|
fetch
|
|
24
37
|
}) {
|
|
25
38
|
this.appOrigin = validateOrigin(appOrigin, "appOrigin");
|
|
26
39
|
this.apiOrigin = validateOrigin(apiOrigin, "apiOrigin");
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.store = configureStore({
|
|
32
|
-
name: "Runtime store",
|
|
33
|
-
hostApiClient: this.hostApiClient,
|
|
34
|
-
appOrigin: this.appOrigin,
|
|
35
|
-
preloadedState: null,
|
|
40
|
+
this.requestKey = requestKey;
|
|
41
|
+
this.fetch = fetch;
|
|
42
|
+
this.protoStore = configureProtoStore({
|
|
43
|
+
name: "Runtime proto-store",
|
|
36
44
|
breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : void 0
|
|
37
45
|
});
|
|
38
46
|
}
|
|
39
|
-
|
|
40
|
-
siteVersion,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
getOrCreateStore({ siteVersion, locale }) {
|
|
48
|
+
const key = storeCacheKey({ siteVersion, locale });
|
|
49
|
+
const createStore = () => {
|
|
50
|
+
const hostApiClient = new MakeswiftHostApiClient({
|
|
51
|
+
uri: new URL("graphql", this.apiOrigin).href,
|
|
52
|
+
fetch: this.fetch,
|
|
53
|
+
preloadedState: { siteVersion, locale }
|
|
54
|
+
});
|
|
55
|
+
const isReadOnly = siteVersion == null;
|
|
56
|
+
return configureReadWriteStore({
|
|
57
|
+
name: `Runtime read-write store (site version: ${key})`,
|
|
58
|
+
appOrigin: this.appOrigin,
|
|
59
|
+
hostApiClient,
|
|
60
|
+
preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale }
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const usePersistentStore = this.shouldUsePersistentStore(key);
|
|
64
|
+
return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore();
|
|
47
65
|
}
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
66
|
+
retainStore({ siteVersion, locale }, store) {
|
|
67
|
+
const key = storeCacheKey({ siteVersion, locale });
|
|
68
|
+
if (!this.shouldUsePersistentStore(key)) {
|
|
69
|
+
console.error("RuntimeCore: attempt to retain an ephemeral store", { key });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.activeStores.retain(key, store);
|
|
73
|
+
}
|
|
74
|
+
releaseStore({ siteVersion, locale }, store) {
|
|
75
|
+
const key = storeCacheKey({ siteVersion, locale });
|
|
76
|
+
if (!this.shouldUsePersistentStore(key)) {
|
|
77
|
+
console.error("RuntimeCore: attempt to release an ephemeral store", { key });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.activeStores.release(key, store);
|
|
51
81
|
}
|
|
52
82
|
copyElementTree(elementTree, replacementContext) {
|
|
53
|
-
return copyElementTree(this.
|
|
83
|
+
return copyElementTree(this.protoStore.getState(), elementTree, replacementContext);
|
|
54
84
|
}
|
|
55
85
|
getBreakpoints() {
|
|
56
|
-
return getBreakpoints(this.
|
|
86
|
+
return getBreakpoints(this.protoStore.getState());
|
|
87
|
+
}
|
|
88
|
+
shouldUsePersistentStore(key) {
|
|
89
|
+
return !isServer() || this.requestKey !== void 0 && storeCacheKey(this.requestKey) === key;
|
|
57
90
|
}
|
|
58
91
|
}
|
|
92
|
+
const storeCacheKey = ({ siteVersion, locale }) => `${siteVersionTag(siteVersion)}/${locale ?? "default"}`;
|
|
93
|
+
const siteVersionTag = (siteVersion) => siteVersion?.version ?? VERSION_TAG_LIVE;
|
|
59
94
|
function validateOrigin(url, name) {
|
|
60
95
|
try {
|
|
61
96
|
return new URL(url).origin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport * as MakeswiftApiClient from '../../state/makeswift-api-client'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport * as MakeswiftApiClient from '../../state/makeswift-api-client'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {\n configureProtoStore,\n configureReadWriteStore,\n type ProtoStore,\n type Store,\n} from '../../state/store'\n\nimport { RefCountedMap } from '../../utils/ref-counted-map'\nimport { isServer } from '../../utils/is-server'\n\nexport type StoreKey = {\n siteVersion: SiteVersion | null\n locale: string | undefined\n}\n\nconst VERSION_TAG_LIVE = 'ref:live'\n\nexport class RuntimeCore {\n // The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays\n // in the map. If an entry expires and is removed from the map before React commits, the store remains retained\n // via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of\n // reusing the existing one, reducing cache efficiency.\n private readonly activeStores = new RefCountedMap<string | null, Store>({\n unownedEntryTtlMs: 1000,\n // Checking on retain/release is sufficient on the client, and we don't need to check on get on the server\n // as the only scenario in which we add the store to the map is when the runtime is already bound to the\n // requested site version, which should be the only site version for which the store is requested\n ttlCheck: RefCountedMap.TTLCheck.ON_RETAIN | RefCountedMap.TTLCheck.ON_RELEASE,\n })\n\n readonly protoStore: ProtoStore\n readonly appOrigin: string\n readonly apiOrigin: string\n readonly requestKey: StoreKey | undefined\n readonly fetch: MakeswiftApiClient.HttpFetch\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n requestKey,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n requestKey?: StoreKey\n fetch: MakeswiftApiClient.HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n this.requestKey = requestKey\n this.fetch = fetch\n\n this.protoStore = configureProtoStore({\n name: 'Runtime proto-store',\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n getOrCreateStore({ siteVersion, locale }: StoreKey): Store {\n const key = storeCacheKey({ siteVersion, locale })\n\n const createStore = () => {\n // host API client includes an in-memory cache of the site's resources and thus also has to be versioned\n const hostApiClient = new MakeswiftHostApiClient({\n uri: new URL('graphql', this.apiOrigin).href,\n fetch: this.fetch,\n preloadedState: { siteVersion, locale },\n })\n\n // TODO: we need to decouple editability from the site version; specifically, previewing\n // a draft version of the site should not lead to switching to the read-write state\n const isReadOnly = siteVersion == null\n\n return configureReadWriteStore({\n name: `Runtime read-write store (site version: ${key})`,\n appOrigin: this.appOrigin,\n hostApiClient,\n preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale },\n })\n }\n\n // On the server, stores are ephemeral by default so SSR does not retain them in a long-lived runtime.\n // The exception is a runtime that is already bound to the requested site version & locale, where we\n // can safely reuse the store across multiple root regions and benefit from the host API client's\n // in-memory cache.\n //\n // On the client, stores are reference-counted by site version so multiple root regions can share a store\n // instance, which preserves the pre-v0.17 per-site-version store behavior without requiring a separate\n // runtime per root.\n const usePersistentStore = this.shouldUsePersistentStore(key)\n return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore()\n }\n\n retainStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to retain an ephemeral store', { key })\n return\n }\n\n this.activeStores.retain(key, store)\n }\n\n releaseStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to release an ephemeral store', { key })\n return\n }\n\n this.activeStores.release(key, store)\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.protoStore.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.protoStore.getState())\n }\n\n private shouldUsePersistentStore(key: string): boolean {\n // don't persist stores on the server unless the runtime instance is bound to a request\n // and the requested store matches the request's site version and locale\n return !isServer() || (this.requestKey !== undefined && storeCacheKey(this.requestKey) === key)\n }\n}\n\nconst storeCacheKey = ({ siteVersion, locale }: StoreKey): string =>\n `${siteVersionTag(siteVersion)}/${locale ?? 'default'}`\n\nconst siteVersionTag = (siteVersion: SiteVersion | null): string =>\n siteVersion?.version ?? VERSION_TAG_LIVE\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime 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,MAAM;AAAA,MACN,aAAa,cAAc,sBAAsB,WAAW,IAAI;AAAA,IAClE,CAAC;AAAA,EACH;AAAA,EAEA,iBAAiB,EAAE,aAAa,OAAO,GAAoB;AACzD,UAAM,MAAM,cAAc,EAAE,aAAa,OAAO,CAAC;AAEjD,UAAM,cAAc,MAAM;AAExB,YAAM,gBAAgB,IAAI,uBAAuB;AAAA,QAC/C,K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AAU,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":[]}
|
|
@@ -15,11 +15,7 @@ const ReadOnlyActionTypes = {
|
|
|
15
15
|
REGISTER_REACT_COMPONENT: "REGISTER_REACT_COMPONENT",
|
|
16
16
|
UNREGISTER_REACT_COMPONENT: "UNREGISTER_REACT_COMPONENT",
|
|
17
17
|
SET_IS_IN_BUILDER: "SET_IS_IN_BUILDER",
|
|
18
|
-
SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
|
|
19
|
-
SET_SITE_VERSION: "SET_SITE_VERSION",
|
|
20
|
-
// TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`
|
|
21
|
-
// (requires changes to the builder to handle null locales)
|
|
22
|
-
RESET_LOCALE_STATE: "RESET_LOCALE_STATE"
|
|
18
|
+
SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
|
|
23
19
|
};
|
|
24
20
|
function apiResourceFulfilled(resourceType, resourceId, resource, locale) {
|
|
25
21
|
return {
|
|
@@ -117,12 +113,6 @@ function setIsInBuilder(isInBuilder) {
|
|
|
117
113
|
function setIsReadOnly(isReadOnly) {
|
|
118
114
|
return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly };
|
|
119
115
|
}
|
|
120
|
-
function setSiteVersion(siteVersion) {
|
|
121
|
-
return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion };
|
|
122
|
-
}
|
|
123
|
-
function resetLocaleState() {
|
|
124
|
-
return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE };
|
|
125
|
-
}
|
|
126
116
|
export {
|
|
127
117
|
ReadOnlyActionTypes,
|
|
128
118
|
apiResourceFulfilled,
|
|
@@ -135,10 +125,8 @@ export {
|
|
|
135
125
|
registerPropControllers,
|
|
136
126
|
registerPropControllersHandle,
|
|
137
127
|
registerReactComponentEffect,
|
|
138
|
-
resetLocaleState,
|
|
139
128
|
setIsInBuilder,
|
|
140
129
|
setIsReadOnly,
|
|
141
|
-
setSiteVersion,
|
|
142
130
|
unregisterComponent,
|
|
143
131
|
unregisterPropControllers,
|
|
144
132
|
unregisterPropControllersHandle
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/state/actions/internal/read-only-actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../../api/types'\nimport { type SiteVersion } from '../../../api/site-version'\nimport { type Descriptor as PropControllerDescriptor } from '../../../prop-controllers/descriptors'\n\nimport { type ComponentMeta } from '../../modules/components-meta'\nimport { type PropControllersHandle } from '../../modules/prop-controller-handles'\nimport { type ComponentType } from '../../modules/react-components'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\n\nexport const ReadOnlyActionTypes = {\n // TODO: this one should be a read-write action and we should refuse\n // to fetch resources on the client in read-only mode\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n SET_IS_READ_ONLY: 'SET_IS_READ_ONLY',\n SET_SITE_VERSION: 'SET_SITE_VERSION',\n\n // TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`\n // (requires changes to the builder to handle null locales)\n RESET_LOCALE_STATE: 'RESET_LOCALE_STATE',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof ReadOnlyActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof ReadOnlyActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof ReadOnlyActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\nexport type RegisterComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype SetIsReadOnlyAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_READ_ONLY\n payload: boolean\n}\n\ntype SetSiteVersionAction = {\n type: typeof ReadOnlyActionTypes.SET_SITE_VERSION\n payload: SiteVersion | null\n}\n\ntype ResetLocaleStateAction = {\n type: typeof ReadOnlyActionTypes.RESET_LOCALE_STATE\n}\n\nexport type ReadOnlyAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | SetIsReadOnlyAction\n | SetSiteVersionAction\n | ResetLocaleStateAction\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: ReadOnlyActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: ReadOnlyActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: ReadOnlyActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: ReadOnlyActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function setIsReadOnly(isReadOnly: boolean): SetIsReadOnlyAction {\n return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly }\n}\n\nexport function setSiteVersion(siteVersion: SiteVersion | null): SetSiteVersionAction {\n return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion }\n}\n\nexport function resetLocaleState(): ResetLocaleStateAction {\n return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE }\n}\n"],"mappings":"AAiBO,MAAM,sBAAsB;AAAA;AAAA;AAAA,EAGjC,wBAAwB;AAAA,EAExB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EAErB,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,kCAAkC;AAAA,EAClC,oCAAoC;AAAA,EAEpC,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAE5B,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,kBAAkB;AAAA;AAAA;AAAA,EAIlB,oBAAoB;AACtB;AAsHO,SAAS,qBACd,cACA,YACA,UACA,QAC4B;AAC5B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,cAAc,YAAY,UAAU,OAAO;AAAA,EACxD;AACF;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO,EAAE,MAAM,oBAAoB,qBAAqB,QAAQ;AAClE;AAEO,SAAS,kBACd,MACA,MACA,2BACyB;AACzB,SAAO;AAAA,IACL,MAAM,oBAA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MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEA,SAAS,uBACP,MACA,WAC8B;AAC9B,SAAO,EAAE,MAAM,oBAAoB,0BAA0B,SAAS,EAAE,MAAM,UAAU,EAAE;AAC5F;AAEA,SAAS,yBAAyB,MAA8C;AAC9E,SAAO,EAAE,MAAM,oBAAoB,4BAA4B,SAAS,EAAE,KAAK,EAAE;AACnF;AAEO,SAAS,6BACd,MACA,WAC2D;AAC3D,SAAO,cAAY;AACjB,aAAS,uBAAuB,MAAM,SAAS,CAAC;AAEhD,WAAO,MAAM;AACX,eAAS,yBAAyB,IAAI,CAAC;AAAA,IACzC;AAAA,EACF;AACF;AAEO,SAAS,eAAe,aAA4C;AACzE,SAAO,EAAE,MAAM,oBAAoB,mBAAmB,SAAS,YAAY;AAC7E;AAEO,SAAS,cAAc,YAA0C;AACtE,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,WAAW;AAC3E;AAEO,SAAS,eAAe,aAAuD;AACpF,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,YAAY;AAC5E;AAEO,SAAS,mBAA2C;AACzD,SAAO,EAAE,MAAM,oBAAoB,mBAAmB;AACxD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/state/actions/internal/read-only-actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../../api/types'\nimport { type Descriptor as PropControllerDescriptor } from '../../../prop-controllers/descriptors'\n\nimport { type ComponentMeta } from '../../modules/components-meta'\nimport { type PropControllersHandle } from '../../modules/prop-controller-handles'\nimport { type ComponentType } from '../../modules/react-components'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\n\nexport const ReadOnlyActionTypes = {\n // TODO: this one should be a read-write action and we should refuse\n // to fetch resources on the client in read-only mode\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n SET_IS_READ_ONLY: 'SET_IS_READ_ONLY',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof ReadOnlyActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof ReadOnlyActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof ReadOnlyActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\nexport type RegisterComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype SetIsReadOnlyAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_READ_ONLY\n payload: boolean\n}\n\nexport type ReadOnlyAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | SetIsReadOnlyAction\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: ReadOnlyActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: ReadOnlyActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: ReadOnlyActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: ReadOnlyActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function setIsReadOnly(isReadOnly: boolean): SetIsReadOnlyAction {\n return { type: ReadOnlyActionTypes.SET_IS_READ_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;AAC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AC9E,SAAO,EAAE,MAAM,oBAAoB,4BAA4B,SAAS,EAAE,KAAK,EAAE;AACnF;AAEO,SAAS,6BACd,MACA,WAC2D;AAC3D,SAAO,cAAY;AACjB,aAAS,uBAAuB,MAAM,SAAS,CAAC;AAEhD,WAAO,MAAM;AACX,eAAS,yBAAyB,IAAI,CAAC;AAAA,IACzC;AAAA,EACF;AACF;AAEO,SAAS,eAAe,aAA4C;AACzE,SAAO,EAAE,MAAM,oBAAoB,mBAAmB,SAAS,YAAY;AAC7E;AAEO,SAAS,cAAc,YAA0C;AACtE,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,WAAW;AAC3E;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/builder-api/actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SerializedControl } from '../../builder'\nimport { type PropControllerMessage } from '../../prop-controllers/instances'\n\nimport { type Document } from '../modules/read-only-documents'\nimport { type ComponentMeta } from '../modules/components-meta'\nimport { type BoxModel } from '../modules/read-write/box-models'\n\nimport { type ElementSize } from '../middleware/read-write/builder-api/element-size'\nimport { type DocumentPayload, type SharedAction, SharedActionTypes } from '../shared-api'\n\nimport { type HostNavigationEvent } from './api'\n\nexport * from '../shared-api'\n\n// actions dispatched by the host to the builder (\"Builder API\")\n// note that some of these actions, in addition to being dispatched to the builder,\n// might also be internally intercepted by the host as a part of maintaining the\n// runtime's \"read-write\" state\nexport const BuilderActionTypes = {\n ...SharedActionTypes,\n\n MAKESWIFT_CONNECTION_CHECK: 'MAKESWIFT_CONNECTION_CHECK',\n\n MOUNT_COMPONENT: 'MOUNT_COMPONENT',\n UNMOUNT_COMPONENT: 'UNMOUNT_COMPONENT',\n\n CHANGE_DOCUMENT_ELEMENT_SIZE: 'CHANGE_DOCUMENT_ELEMENT_SIZE',\n CHANGE_ELEMENT_BOX_MODELS: 'CHANGE_ELEMENT_BOX_MODELS',\n\n MESSAGE_BUILDER_PROP_CONTROLLER: 'MESSAGE_BUILDER_PROP_CONTROLLER',\n\n HANDLE_WHEEL: 'HANDLE_WHEEL',\n HANDLE_POINTER_MOVE: 'HANDLE_POINTER_MOVE',\n\n ELEMENT_FROM_POINT_CHANGE: 'ELEMENT_FROM_POINT_CHANGE',\n\n REGISTER_BUILDER_DOCUMENT: 'REGISTER_BUILDER_DOCUMENT',\n UNREGISTER_BUILDER_DOCUMENT: 'UNREGISTER_BUILDER_DOCUMENT',\n\n REGISTER_BUILDER_COMPONENT: 'REGISTER_BUILDER_COMPONENT',\n UNREGISTER_BUILDER_COMPONENT: 'UNREGISTER_BUILDER_COMPONENT',\n\n HANDLE_HOST_NAVIGATE: 'HANDLE_HOST_NAVIGATE',\n} as const\n\ntype ActionWithTransferables<A> = A & {\n transferables?: Transferable[]\n}\n\ntype MakeswiftConnectionCheckAction = {\n type: typeof BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK\n}\n\ntype MountComponentAction = {\n type: typeof BuilderActionTypes.MOUNT_COMPONENT\n payload: { documentKey: string; elementKey: string }\n}\n\ntype UnmountComponentAction = {\n type: typeof BuilderActionTypes.UNMOUNT_COMPONENT\n payload: { documentKey: string; elementKey: string }\n}\n\ntype ChangeDocumentElementSizeAction = {\n type: typeof BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE\n payload: { size: ElementSize }\n}\n\ntype ChangeElementBoxModelsAction = {\n type: typeof BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS\n payload: { changedElementBoxModels: Map<string, Map<string, BoxModel | null>> }\n}\n\ntype MessageBuilderPropControllerAction<T = PropControllerMessage> = {\n type: typeof BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER\n payload: { documentKey: string; elementKey: string; propName: string; message: T }\n}\n\ntype HandleWheelAction = {\n type: typeof BuilderActionTypes.HANDLE_WHEEL\n payload: { deltaX: number; deltaY: number }\n}\n\ntype HandlePointerMoveAction = {\n type: typeof BuilderActionTypes.HANDLE_POINTER_MOVE\n payload: { clientX: number; clientY: number }\n}\n\ntype ElementFromPointChangeAction = {\n type: typeof BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE\n payload: { keys: { documentKey: string; elementKey: string } | null }\n}\n\ntype RegisterBuilderDocumentAction = {\n type: typeof BuilderActionTypes.REGISTER_BUILDER_DOCUMENT\n payload: { documentKey: string; document: DocumentPayload }\n}\n\ntype UnregisterBuilderDocumentAction = {\n type: typeof BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT\n payload: { documentKey: string }\n}\n\ntype RegisterBuilderComponentAction = {\n type: typeof BuilderActionTypes.REGISTER_BUILDER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n serializedControls: Record<string, SerializedControl>\n }\n}\n\ntype UnregisterBuilderComponentAction = {\n type: typeof BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT\n payload: { type: string }\n}\n\ntype HandleHostNavigateAction = {\n type: typeof BuilderActionTypes.HANDLE_HOST_NAVIGATE\n payload: HostNavigationEvent\n}\n\nexport type BuilderAction =\n | SharedAction\n | MakeswiftConnectionCheckAction\n | MountComponentAction\n | UnmountComponentAction\n | ChangeDocumentElementSizeAction\n | ChangeElementBoxModelsAction\n | MessageBuilderPropControllerAction\n | HandleWheelAction\n | HandlePointerMoveAction\n | ElementFromPointChangeAction\n | RegisterBuilderDocumentAction\n | UnregisterBuilderDocumentAction\n | RegisterBuilderComponentAction\n | UnregisterBuilderComponentAction\n | HandleHostNavigateAction\n\nexport function makeswiftConnectionCheck(): MakeswiftConnectionCheckAction {\n return { type: BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK }\n}\n\nexport function mountComponent(documentKey: string, elementKey: string): MountComponentAction {\n return { type: BuilderActionTypes.MOUNT_COMPONENT, payload: { documentKey, elementKey } }\n}\n\nexport function unmountComponent(documentKey: string, elementKey: string): UnmountComponentAction {\n return { type: BuilderActionTypes.UNMOUNT_COMPONENT, payload: { documentKey, elementKey } }\n}\n\nexport function mountComponentEffect(\n documentKey: string,\n elementKey: string,\n): ThunkAction<() => void, unknown, unknown, BuilderAction> {\n return dispatch => {\n dispatch(mountComponent(documentKey, elementKey))\n\n return () => {\n dispatch(unmountComponent(documentKey, elementKey))\n }\n }\n}\n\nexport function changeDocumentElementSize(size: ElementSize): ChangeDocumentElementSizeAction {\n return { type: BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE, payload: { size } }\n}\n\nexport function changeElementBoxModels(\n changedElementBoxModels: Map<string, Map<string, BoxModel | null>>,\n): ChangeElementBoxModelsAction {\n return {\n type: BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS,\n payload: { changedElementBoxModels },\n }\n}\n\nexport function messageBuilderPropController<T>(\n documentKey: string,\n elementKey: string,\n propName: string,\n message: T,\n): MessageBuilderPropControllerAction<T> {\n return {\n type: BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER,\n payload: { documentKey, elementKey, propName, message },\n }\n}\n\nexport function handleWheel(payload: { deltaX: number; deltaY: number }): HandleWheelAction {\n return { type: BuilderActionTypes.HANDLE_WHEEL, payload }\n}\n\nexport function handlePointerMove(payload: {\n clientX: number\n clientY: number\n}): HandlePointerMoveAction {\n return { type: BuilderActionTypes.HANDLE_POINTER_MOVE, payload }\n}\n\nexport function elementFromPointChange(\n keys: {\n documentKey: string\n elementKey: string\n } | null,\n): ElementFromPointChangeAction {\n return { type: BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE, payload: { keys } }\n}\n\nexport function registerBuilderDocument(document: Document): RegisterBuilderDocumentAction {\n return {\n type: BuilderActionTypes.REGISTER_BUILDER_DOCUMENT,\n payload: { documentKey: document.key, document },\n }\n}\n\nexport function unregisterBuilderDocument(documentKey: string): UnregisterBuilderDocumentAction {\n return { type: BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT, payload: { documentKey } }\n}\n\nexport function registerBuilderDocumentsEffect(\n documents: Document[],\n): ThunkAction<() => void, unknown, unknown, BuilderAction> {\n return dispatch => {\n documents.forEach(document => dispatch(registerBuilderDocument(document)))\n\n return () => {\n documents.forEach(document => dispatch(unregisterBuilderDocument(document.key)))\n }\n }\n}\n\nexport function registerBuilderComponent(\n payload: RegisterBuilderComponentAction['payload'],\n transferables?: Transferable[],\n): ActionWithTransferables<RegisterBuilderComponentAction> {\n return {\n type: BuilderActionTypes.REGISTER_BUILDER_COMPONENT,\n payload,\n transferables,\n }\n}\n\nexport function unregisterBuilderComponent(\n payload: UnregisterBuilderComponentAction['payload'],\n): UnregisterBuilderComponentAction {\n return { type: BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT, payload }\n}\n\nexport function hasTransferables<A extends BuilderAction>(\n action: A,\n): action is ActionWithTransferables<A> {\n return 'transferables' in action && Array.isArray(action.transferables)\n}\n"],"mappings":"AAUA,SAAkD,yBAAyB;AAI3E,cAAc;AAMP,MAAM,qBAAqB;AAAA,EAChC,GAAG;AAAA,EAEH,4BAA4B;AAAA,EAE5B,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EAEnB,8BAA8B;AAAA,EAC9B,2BAA2B;AAAA,EAE3B,iCAAiC;AAAA,EAEjC,cAAc;AAAA,EACd,qBAAqB;AAAA,EAErB,2BAA2B;AAAA,EAE3B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,4BAA4B;AAAA,EAC5B,8BAA8B;AAAA,EAE9B,sBAAsB;AACxB;AAgGO,SAAS,2BAA2D;AACzE,SAAO,EAAE,MAAM,mBAAmB,2BAA2B;AAC/D;AAEO,SAAS,eAAe,aAAqB,YAA0C;AAC5F,SAAO,EAAE,MAAM,mBAAmB,iBAAiB,SAAS,EAAE,aAAa,WAAW,EAAE;AAC1F;AAEO,SAAS,iBAAiB,aAAqB,YAA4C;AAChG,SAAO,EAAE,MAAM,mBAAmB,mBAAmB,SAAS,EAAE,aAAa,WAAW,EAAE;AAC5F;AAEO,SAAS,qBACd,aACA,YAC0D;AAC1D,SAAO,cAAY;AACjB,aAAS,eAAe,aAAa,UAAU,CAA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ACA;AAAA,EACF;AACF;AAEO,SAAS,2BACd,SACkC;AAClC,SAAO,EAAE,MAAM,mBAAmB,8BAA8B,QAAQ;AAC1E;AAEO,SAAS,iBACd,QACsC;AACtC,SAAO,mBAAmB,UAAU,MAAM,QAAQ,OAAO,aAAa;AACxE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/builder-api/actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SerializedControl } from '../../builder'\nimport { type PropControllerMessage } from '../../prop-controllers/instances'\n\nimport { type Document } from '../modules/read-only-documents'\nimport { type ComponentMeta } from '../modules/components-meta'\nimport { type BoxDisplayModel } from '../modules/read-write/box-models'\n\nimport { type ElementSize } from '../middleware/read-write/builder-api/element-size'\nimport { type DocumentPayload, type SharedAction, SharedActionTypes } from '../shared-api'\n\nimport { type HostNavigationEvent } from './api'\n\nexport * from '../shared-api'\n\n// actions dispatched by the host to the builder (\"Builder API\")\n// note that some of these actions, in addition to being dispatched to the builder,\n// might also be internally intercepted by the host as a part of maintaining the\n// runtime's \"read-write\" state\nexport const BuilderActionTypes = {\n ...SharedActionTypes,\n\n MAKESWIFT_CONNECTION_CHECK: 'MAKESWIFT_CONNECTION_CHECK',\n\n MOUNT_COMPONENT: 'MOUNT_COMPONENT',\n UNMOUNT_COMPONENT: 'UNMOUNT_COMPONENT',\n\n CHANGE_DOCUMENT_ELEMENT_SIZE: 'CHANGE_DOCUMENT_ELEMENT_SIZE',\n CHANGE_ELEMENT_BOX_MODELS: 'CHANGE_ELEMENT_BOX_MODELS',\n\n MESSAGE_BUILDER_PROP_CONTROLLER: 'MESSAGE_BUILDER_PROP_CONTROLLER',\n\n HANDLE_WHEEL: 'HANDLE_WHEEL',\n HANDLE_POINTER_MOVE: 'HANDLE_POINTER_MOVE',\n\n ELEMENT_FROM_POINT_CHANGE: 'ELEMENT_FROM_POINT_CHANGE',\n\n REGISTER_BUILDER_DOCUMENT: 'REGISTER_BUILDER_DOCUMENT',\n UNREGISTER_BUILDER_DOCUMENT: 'UNREGISTER_BUILDER_DOCUMENT',\n\n REGISTER_BUILDER_COMPONENT: 'REGISTER_BUILDER_COMPONENT',\n UNREGISTER_BUILDER_COMPONENT: 'UNREGISTER_BUILDER_COMPONENT',\n\n HANDLE_HOST_NAVIGATE: 'HANDLE_HOST_NAVIGATE',\n} as const\n\ntype ActionWithTransferables<A> = A & {\n transferables?: Transferable[]\n}\n\ntype MakeswiftConnectionCheckAction = {\n type: typeof BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK\n}\n\ntype MountComponentAction = {\n type: typeof BuilderActionTypes.MOUNT_COMPONENT\n payload: { documentKey: string; elementKey: string }\n}\n\ntype UnmountComponentAction = {\n type: typeof BuilderActionTypes.UNMOUNT_COMPONENT\n payload: { documentKey: string; elementKey: string }\n}\n\ntype ChangeDocumentElementSizeAction = {\n type: typeof BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE\n payload: { size: ElementSize }\n}\n\ntype ChangeElementBoxModelsAction = {\n type: typeof BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS\n payload: { changedElementBoxModels: Map<string, Map<string, BoxDisplayModel | null>> }\n}\n\ntype MessageBuilderPropControllerAction<T = PropControllerMessage> = {\n type: typeof BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER\n payload: { documentKey: string; elementKey: string; propName: string; message: T }\n}\n\ntype HandleWheelAction = {\n type: typeof BuilderActionTypes.HANDLE_WHEEL\n payload: { deltaX: number; deltaY: number }\n}\n\ntype HandlePointerMoveAction = {\n type: typeof BuilderActionTypes.HANDLE_POINTER_MOVE\n payload: { clientX: number; clientY: number }\n}\n\ntype ElementFromPointChangeAction = {\n type: typeof BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE\n payload: { keys: { documentKey: string; elementKey: string } | null }\n}\n\ntype RegisterBuilderDocumentAction = {\n type: typeof BuilderActionTypes.REGISTER_BUILDER_DOCUMENT\n payload: { documentKey: string; document: DocumentPayload }\n}\n\ntype UnregisterBuilderDocumentAction = {\n type: typeof BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT\n payload: { documentKey: string }\n}\n\ntype RegisterBuilderComponentAction = {\n type: typeof BuilderActionTypes.REGISTER_BUILDER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n serializedControls: Record<string, SerializedControl>\n }\n}\n\ntype UnregisterBuilderComponentAction = {\n type: typeof BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT\n payload: { type: string }\n}\n\ntype HandleHostNavigateAction = {\n type: typeof BuilderActionTypes.HANDLE_HOST_NAVIGATE\n payload: HostNavigationEvent\n}\n\nexport type BuilderAction =\n | SharedAction\n | MakeswiftConnectionCheckAction\n | MountComponentAction\n | UnmountComponentAction\n | ChangeDocumentElementSizeAction\n | ChangeElementBoxModelsAction\n | MessageBuilderPropControllerAction\n | HandleWheelAction\n | HandlePointerMoveAction\n | ElementFromPointChangeAction\n | RegisterBuilderDocumentAction\n | UnregisterBuilderDocumentAction\n | RegisterBuilderComponentAction\n | UnregisterBuilderComponentAction\n | HandleHostNavigateAction\n\nexport function makeswiftConnectionCheck(): MakeswiftConnectionCheckAction {\n return { type: BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK }\n}\n\nexport function mountComponent(documentKey: string, elementKey: string): MountComponentAction {\n return { type: BuilderActionTypes.MOUNT_COMPONENT, payload: { documentKey, elementKey } }\n}\n\nexport function unmountComponent(documentKey: string, elementKey: string): UnmountComponentAction {\n return { type: BuilderActionTypes.UNMOUNT_COMPONENT, payload: { documentKey, elementKey } }\n}\n\nexport function mountComponentEffect(\n documentKey: string,\n elementKey: string,\n): ThunkAction<() => void, unknown, unknown, BuilderAction> {\n return dispatch => {\n dispatch(mountComponent(documentKey, elementKey))\n\n return () => {\n dispatch(unmountComponent(documentKey, elementKey))\n }\n }\n}\n\nexport function changeDocumentElementSize(size: ElementSize): ChangeDocumentElementSizeAction {\n return { type: BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE, payload: { size } }\n}\n\nexport function changeElementBoxModels(\n changedElementBoxModels: Map<string, Map<string, BoxDisplayModel | null>>,\n): ChangeElementBoxModelsAction {\n return {\n type: BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS,\n payload: { changedElementBoxModels },\n }\n}\n\nexport function messageBuilderPropController<T>(\n documentKey: string,\n elementKey: string,\n propName: string,\n message: T,\n): MessageBuilderPropControllerAction<T> {\n return {\n type: BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER,\n payload: { documentKey, elementKey, propName, message },\n }\n}\n\nexport function handleWheel(payload: { deltaX: number; deltaY: number }): HandleWheelAction {\n return { type: BuilderActionTypes.HANDLE_WHEEL, payload }\n}\n\nexport function handlePointerMove(payload: {\n clientX: number\n clientY: number\n}): HandlePointerMoveAction {\n return { type: BuilderActionTypes.HANDLE_POINTER_MOVE, payload }\n}\n\nexport function elementFromPointChange(\n keys: {\n documentKey: string\n elementKey: string\n } | null,\n): ElementFromPointChangeAction {\n return { type: BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE, payload: { keys } }\n}\n\nexport function registerBuilderDocument(document: Document): RegisterBuilderDocumentAction {\n return {\n type: BuilderActionTypes.REGISTER_BUILDER_DOCUMENT,\n payload: { documentKey: document.key, document },\n }\n}\n\nexport function unregisterBuilderDocument(documentKey: string): UnregisterBuilderDocumentAction {\n return { type: BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT, payload: { documentKey } }\n}\n\nexport function registerBuilderDocumentsEffect(\n documents: Document[],\n): ThunkAction<() => void, unknown, unknown, BuilderAction> {\n return dispatch => {\n documents.forEach(document => dispatch(registerBuilderDocument(document)))\n\n return () => {\n documents.forEach(document => dispatch(unregisterBuilderDocument(document.key)))\n }\n }\n}\n\nexport function registerBuilderComponent(\n payload: RegisterBuilderComponentAction['payload'],\n transferables?: Transferable[],\n): ActionWithTransferables<RegisterBuilderComponentAction> {\n return {\n type: BuilderActionTypes.REGISTER_BUILDER_COMPONENT,\n payload,\n transferables,\n }\n}\n\nexport function unregisterBuilderComponent(\n payload: UnregisterBuilderComponentAction['payload'],\n): UnregisterBuilderComponentAction {\n return { type: BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT, payload }\n}\n\nexport function hasTransferables<A extends BuilderAction>(\n action: A,\n): action is ActionWithTransferables<A> {\n return 'transferables' in action && Array.isArray(action.transferables)\n}\n"],"mappings":"AAUA,SAAkD,yBAAyB;AAI3E,cAAc;AAMP,MAAM,qBAAqB;AAAA,EAChC,GAAG;AAAA,EAEH,4BAA4B;AAAA,EAE5B,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EAEnB,8BAA8B;AAAA,EAC9B,2BAA2B;AAAA,EAE3B,iCAAiC;AAAA,EAEjC,cAAc;AAAA,EACd,qBAAqB;AAAA,EAErB,2BAA2B;AAAA,EAE3B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,4BAA4B;AAAA,EAC5B,8BAA8B;AAAA,EAE9B,sBAAsB;AACxB;AAgGO,SAAS,2BAA2D;AACzE,SAAO,EAAE,MAAM,mBAAmB,2BAA2B;AAC/D;AAEO,SAAS,eAAe,aAAqB,YAA0C;AAC5F,SAAO,EAAE,MAAM,mBAAmB,iBAAiB,SAAS,EAAE,aAAa,WAAW,EAAE;AAC1F;AAEO,SAAS,iBAAiB,aAAqB,YAA4C;AAChG,SAAO,EAAE,MAAM,mBAAmB,mBAAmB,SAAS,EAAE,aAAa,WAAW,EAAE;AAC5F;AAEO,SAAS,qBACd,aACA,YAC0D;AAC1D,SAAO,cAAY;AACjB,aAAS,eAAe,aAAa,UAAU,CAAC;AAEhD,WAAO,MAAM;AACX,eAAS,iBAAiB,aAAa,UAAU,CAAC;AAAA,IACpD;AAAA,EACF;AACF;AAEO,SAAS,0BAA0B,MAAoD;AAC5F,SAAO,EAAE,MAAM,mBAAmB,8BAA8B,SAAS,EAAE,KAAK,EAAE;AACpF;AAEO,SAAS,uBACd,yBAC8B;AAC9B,SAAO;AAAA,IAC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|
|
|
8
8
|
import * as APIResources from "./modules/api-resources";
|
|
9
9
|
import * as LocalizedResourcesMap from "./modules/localized-resources-map";
|
|
10
10
|
import { ActionTypes } from "./actions";
|
|
11
|
-
import { apiResourceFulfilled
|
|
12
|
-
import { clearAPIClientCache } from "./actions/internal/read-write-actions";
|
|
11
|
+
import { apiResourceFulfilled } from "./actions/internal/read-only-actions";
|
|
13
12
|
import { setLocalizedResourceId } from "./host-api";
|
|
14
13
|
import { actionMiddleware, middlewareOptions, devToolsConfig } from "./toolkit";
|
|
15
14
|
import {
|
|
@@ -156,34 +155,11 @@ function defaultLocaleMiddleware() {
|
|
|
156
155
|
};
|
|
157
156
|
});
|
|
158
157
|
}
|
|
159
|
-
function
|
|
160
|
-
return actionMiddleware(({ getState, dispatch }) => (next) => {
|
|
161
|
-
return (action) => {
|
|
162
|
-
switch (action.type) {
|
|
163
|
-
case ReadOnlyActionTypes.SET_SITE_VERSION: {
|
|
164
|
-
const cacheVersion = SiteVersionState.getSiteVersion(getState().siteVersion);
|
|
165
|
-
if (cacheVersion?.version !== action.payload?.version) {
|
|
166
|
-
dispatch(clearAPIClientCache());
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return next(action);
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
function configureStore({ serializedState }) {
|
|
158
|
+
function configureStore({ preloadedState }) {
|
|
175
159
|
return configureReduxStore({
|
|
176
160
|
reducer,
|
|
177
|
-
preloadedState
|
|
178
|
-
|
|
179
|
-
localizedResourcesMap: LocalizedResourcesMap.getInitialState(
|
|
180
|
-
serializedState?.localizedResourcesMap
|
|
181
|
-
)
|
|
182
|
-
},
|
|
183
|
-
middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareOptions).concat(
|
|
184
|
-
defaultLocaleMiddleware(),
|
|
185
|
-
cacheVersioningMiddleware()
|
|
186
|
-
),
|
|
161
|
+
preloadedState,
|
|
162
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware()),
|
|
187
163
|
devTools: devToolsConfig({
|
|
188
164
|
name: `API client store (${(/* @__PURE__ */ new Date()).toISOString()})`,
|
|
189
165
|
actionsDenylist: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../api/site-version'\n\nimport * as SiteVersionState from './modules/site-version'\nimport * as LocaleState from './modules/locale'\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\n\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled, ReadOnlyActionTypes } from './actions/internal/read-only-actions'\nimport { clearAPIClientCache } from './actions/internal/read-write-actions'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n siteVersion: SiteVersionState.reducer,\n locale: LocaleState.reducer,\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(({ getState }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: {\n ...action.payload,\n locale: locale ?? LocaleState.getLocale(getState().locale),\n },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nfunction cacheVersioningMiddleware(): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(({ getState, dispatch }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ReadOnlyActionTypes.SET_SITE_VERSION: {\n const cacheVersion = SiteVersionState.getSiteVersion(getState().siteVersion)\n if (cacheVersion?.version !== action.payload?.version) {\n dispatch(clearAPIClientCache())\n }\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({ serializedState }: { serializedState?: SerializedState }) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(\n defaultLocaleMiddleware(),\n cacheVersioningMiddleware(),\n ),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,OAKK;AAEP,SAA2B,mBAAmB,4BAA4B;AAE1E,YAAY,sBAAsB;AAClC,YAAY,iBAAiB;AAC7B,YAAY,kBAAkB;AAC9B,YAAY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AO,iBAAiB,CAAC,EAAE,UAAU,SAAS,MAAM,UAAQ;AAC1D,WAAO,CAAC,WAAmB;AACzB,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,oBAAoB,kBAAkB;AACzC,gBAAM,eAAe,iBAAiB,eAAe,SAAS,EAAE,WAAW;AAC3E,cAAI,cAAc,YAAY,OAAO,SAAS,SAAS;AACrD,qBAAS,oBAAoB,CAAC;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe,EAAE,gBAAgB,GAA0C;AACzF,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA,gBAAgB;AAAA,MACd,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE;AAAA,MACtC,wBAAwB;AAAA,MACxB,0BAA0B;AAAA,IAC5B;AAAA,IAEF,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../api/site-version'\n\nimport * as SiteVersionState from './modules/site-version'\nimport * as LocaleState from './modules/locale'\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\n\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled } from './actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n siteVersion: SiteVersionState.reducer,\n locale: LocaleState.reducer,\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(({ getState }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: {\n ...action.payload,\n locale: locale ?? LocaleState.getLocale(getState().locale),\n },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({ preloadedState }: { preloadedState: Partial<State> }) {\n return configureReduxStore({\n reducer,\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware()),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MO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SAAS;AAAA,cACP,GAAG,OAAO;AAAA,cACV,QAAQ,UAAU,YAAY,UAAU,SAAS,EAAE,MAAM;AAAA,YAC3D;AAAA,UACF,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe,EAAE,eAAe,GAAuC;AACrF,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE,OAAO,wBAAwB,CAAC;AAAA,IAE1E,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -27,10 +27,16 @@ function builderAPIMiddleware(builderProxy) {
|
|
|
27
27
|
builderProxy.execute(action);
|
|
28
28
|
break;
|
|
29
29
|
case HostActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP:
|
|
30
|
-
window.document.documentElement.
|
|
30
|
+
window.document.documentElement.scrollTo({
|
|
31
|
+
top: action.payload.scrollTop,
|
|
32
|
+
behavior: "instant"
|
|
33
|
+
});
|
|
31
34
|
break;
|
|
32
35
|
case HostActionTypes.SCROLL_DOCUMENT_ELEMENT:
|
|
33
|
-
window.document.documentElement.
|
|
36
|
+
window.document.documentElement.scrollBy({
|
|
37
|
+
top: action.payload.scrollTopDelta,
|
|
38
|
+
behavior: "instant"
|
|
39
|
+
});
|
|
34
40
|
break;
|
|
35
41
|
case HostActionTypes.SET_BUILDER_EDIT_MODE:
|
|
36
42
|
window.getSelection()?.removeAllRanges();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/state/middleware/read-write/builder-api/index.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { type Action } from '../../../actions'\n\nimport { BuilderActionTypes } from '../../../builder-api/actions'\n\nimport { actionMiddleware } from '../../../toolkit'\n\nimport { type BuilderAPIProxy } from '../../../builder-api/proxy'\nimport { HostActionTypes } from '../../../host-api'\n\nimport { type State, type Dispatch } from '../../../read-write-state'\nimport { initializeBuilderConnection } from './initialize-connection'\n\nexport function builderAPIMiddleware(\n builderProxy: BuilderAPIProxy,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(({ dispatch }) => next => {\n if (typeof window === 'undefined') return (action: Action) => next(action)\n\n let cleanUp = () => {}\n return (action: Action) => {\n switch (action.type) {\n case BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS:\n case BuilderActionTypes.MOUNT_COMPONENT:\n case BuilderActionTypes.UNMOUNT_COMPONENT:\n case BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE:\n case BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER:\n case BuilderActionTypes.HANDLE_WHEEL:\n case BuilderActionTypes.HANDLE_POINTER_MOVE:\n case BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE:\n case BuilderActionTypes.SET_LOCALE:\n case BuilderActionTypes.SET_BREAKPOINTS:\n case BuilderActionTypes.REGISTER_BUILDER_DOCUMENT:\n case BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT:\n case BuilderActionTypes.REGISTER_BUILDER_COMPONENT:\n case BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT:\n builderProxy.execute(action)\n break\n\n case HostActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP:\n window.document.documentElement.
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/state/middleware/read-write/builder-api/index.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { type Action } from '../../../actions'\n\nimport { BuilderActionTypes } from '../../../builder-api/actions'\n\nimport { actionMiddleware } from '../../../toolkit'\n\nimport { type BuilderAPIProxy } from '../../../builder-api/proxy'\nimport { HostActionTypes } from '../../../host-api'\n\nimport { type State, type Dispatch } from '../../../read-write-state'\nimport { initializeBuilderConnection } from './initialize-connection'\n\nexport function builderAPIMiddleware(\n builderProxy: BuilderAPIProxy,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(({ dispatch }) => next => {\n if (typeof window === 'undefined') return (action: Action) => next(action)\n\n let cleanUp = () => {}\n return (action: Action) => {\n switch (action.type) {\n case BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS:\n case BuilderActionTypes.MOUNT_COMPONENT:\n case BuilderActionTypes.UNMOUNT_COMPONENT:\n case BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE:\n case BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER:\n case BuilderActionTypes.HANDLE_WHEEL:\n case BuilderActionTypes.HANDLE_POINTER_MOVE:\n case BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE:\n case BuilderActionTypes.SET_LOCALE:\n case BuilderActionTypes.SET_BREAKPOINTS:\n case BuilderActionTypes.REGISTER_BUILDER_DOCUMENT:\n case BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT:\n case BuilderActionTypes.REGISTER_BUILDER_COMPONENT:\n case BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT:\n builderProxy.execute(action)\n break\n\n case HostActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP:\n window.document.documentElement.scrollTo({\n top: action.payload.scrollTop,\n behavior: 'instant',\n })\n break\n\n case HostActionTypes.SCROLL_DOCUMENT_ELEMENT:\n window.document.documentElement.scrollBy({\n top: action.payload.scrollTopDelta,\n behavior: 'instant',\n })\n break\n\n case HostActionTypes.SET_BUILDER_EDIT_MODE:\n window.getSelection()?.removeAllRanges()\n break\n\n case HostActionTypes.INIT:\n // dispatched by the parent window after establishing the connection\n // and in response to host's client-side navigation\n cleanUp() // cleanup existing connection setup, if any\n cleanUp = dispatch(initializeBuilderConnection(builderProxy))\n break\n\n case HostActionTypes.CLEAN_UP:\n // dispatched by the parent window on disconnect\n cleanUp()\n cleanUp = () => {}\n break\n }\n\n return next(action)\n }\n })\n}\n"],"mappings":"AAIA,SAAS,0BAA0B;AAEnC,SAAS,wBAAwB;AAGjC,SAAS,uBAAuB;AAGhC,SAAS,mCAAmC;AAErC,SAAS,qBACd,cACuC;AACvC,SAAO,iBAAiB,CAAC,EAAE,SAAS,MAAM,UAAQ;AAChD,QAAI,OAAO,WAAW;AAAa,aAAO,CAAC,WAAmB,KAAK,MAAM;AAEzE,QAAI,UAAU,MAAM;AAAA,IAAC;AACrB,WAAO,CAAC,WAAmB;AACzB,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AAAA,QACxB,KAAK,mBAAmB;AACtB,uBAAa,QAAQ,MAAM;AAC3B;AAAA,QAEF,KAAK,gBAAgB;AACnB,iBAAO,SAAS,gBAAgB,SAAS;AAAA,YACvC,KAAK,OAAO,QAAQ;AAAA,YACpB,UAAU;AAAA,UACZ,CAAC;AACD;AAAA,QAEF,KAAK,gBAAgB;AACnB,iBAAO,SAAS,gBAAgB,SAAS;AAAA,YACvC,KAAK,OAAO,QAAQ;AAAA,YACpB,UAAU;AAAA,UACZ,CAAC;AACD;AAAA,QAEF,KAAK,gBAAgB;AACnB,iBAAO,aAAa,GAAG,gBAAgB;AACvC;AAAA,QAEF,KAAK,gBAAgB;AAGnB,kBAAQ;AACR,oBAAU,SAAS,4BAA4B,YAAY,CAAC;AAC5D;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