@makeswift/runtime 0.28.3-canary.4 → 0.28.3-canary.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/client.js +2 -4
- package/dist/cjs/api/client.js.map +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/client/index.js +17 -18
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js +11 -7
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-store.js +9 -2
- package/dist/cjs/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/cjs/runtimes/react/host-api-client.js +2 -2
- package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
- package/dist/cjs/runtimes/react/react-runtime-core.js +2 -2
- package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/react-runtime.js.map +1 -1
- package/dist/cjs/runtimes/react/runtime-core.js +62 -26
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-only-actions.js +1 -15
- package/dist/cjs/state/actions/internal/read-only-actions.js.map +1 -1
- package/dist/cjs/state/makeswift-api-client.js +3 -27
- package/dist/cjs/state/makeswift-api-client.js.map +1 -1
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js +3 -0
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
- package/dist/cjs/state/modules/locale.js +0 -3
- package/dist/cjs/state/modules/locale.js.map +1 -1
- package/dist/cjs/state/modules/site-version.js +0 -3
- package/dist/cjs/state/modules/site-version.js.map +1 -1
- package/dist/cjs/state/read-only-state.js +8 -1
- package/dist/cjs/state/read-only-state.js.map +1 -1
- package/dist/cjs/state/store.js +75 -48
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/cjs/unstable-framework-support/index.js.map +1 -1
- package/dist/cjs/utils/ref-counted-map.js +111 -0
- package/dist/cjs/utils/ref-counted-map.js.map +1 -0
- package/dist/esm/api/client.js +2 -4
- package/dist/esm/api/client.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/index.js +17 -18
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/esm/runtimes/react/components/RuntimeProvider.js +12 -8
- package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-store.js +8 -2
- package/dist/esm/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/esm/runtimes/react/host-api-client.js +2 -2
- package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
- package/dist/esm/runtimes/react/react-runtime-core.js +2 -2
- package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/react-runtime.js.map +1 -1
- package/dist/esm/runtimes/react/runtime-core.js +65 -30
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/state/actions/internal/read-only-actions.js +1 -13
- package/dist/esm/state/actions/internal/read-only-actions.js.map +1 -1
- package/dist/esm/state/makeswift-api-client.js +4 -28
- package/dist/esm/state/makeswift-api-client.js.map +1 -1
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js +3 -0
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
- package/dist/esm/state/modules/locale.js +0 -3
- package/dist/esm/state/modules/locale.js.map +1 -1
- package/dist/esm/state/modules/site-version.js +0 -3
- package/dist/esm/state/modules/site-version.js.map +1 -1
- package/dist/esm/state/read-only-state.js +7 -1
- package/dist/esm/state/read-only-state.js.map +1 -1
- package/dist/esm/state/store.js +74 -47
- package/dist/esm/state/store.js.map +1 -1
- package/dist/esm/unstable-framework-support/index.js.map +1 -1
- package/dist/esm/utils/ref-counted-map.js +87 -0
- package/dist/esm/utils/ref-counted-map.js.map +1 -0
- package/dist/types/api/client.d.ts +2 -2
- package/dist/types/api/client.d.ts.map +1 -1
- package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts +6 -6
- package/dist/types/api-handler/handlers/webhook/types.d.ts +20 -20
- package/dist/types/client/index.d.ts +1 -0
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-store.d.ts +29 -0
- package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
- package/dist/types/runtimes/react/react-runtime.d.ts +1 -0
- package/dist/types/runtimes/react/react-runtime.d.ts.map +1 -1
- package/dist/types/runtimes/react/runtime-core.d.ts +15 -13
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/state/__tests__/test-store.d.ts +4 -2
- package/dist/types/state/__tests__/test-store.d.ts.map +1 -1
- package/dist/types/state/actions/index.d.ts +0 -2
- package/dist/types/state/actions/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/index.d.ts +0 -2
- package/dist/types/state/actions/internal/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-only-actions.d.ts +1 -13
- package/dist/types/state/actions/internal/read-only-actions.d.ts.map +1 -1
- package/dist/types/state/makeswift-api-client.d.ts +2 -2
- package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
- package/dist/types/state/middleware/read-write/builder-api/initialize-connection.d.ts.map +1 -1
- package/dist/types/state/modules/locale.d.ts.map +1 -1
- package/dist/types/state/modules/site-version.d.ts.map +1 -1
- package/dist/types/state/read-only-state.d.ts +6 -2
- package/dist/types/state/read-only-state.d.ts.map +1 -1
- package/dist/types/state/read-write-state.d.ts +4 -2
- package/dist/types/state/read-write-state.d.ts.map +1 -1
- package/dist/types/state/store.d.ts +47 -14
- package/dist/types/state/store.d.ts.map +1 -1
- package/dist/types/unstable-framework-support/index.d.ts +1 -1
- package/dist/types/unstable-framework-support/index.d.ts.map +1 -1
- package/dist/types/utils/__tests__/ref-counted-map.test.d.ts +2 -0
- package/dist/types/utils/__tests__/ref-counted-map.test.d.ts.map +1 -0
- package/dist/types/utils/ref-counted-map.d.ts +26 -0
- package/dist/types/utils/ref-counted-map.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oCAAiC;AAEjC,+BAGO;AAEP,6BAA8B;AAG9B,0BAA4B;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,gCAAY;AAAA,EAChD,kBAKE,WACA;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO,qCAAc;AAAA,IACrB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAcY;AACZ,0BAAsB,MAAM,SAAqC;AAEjE,UAAM,sBAAsB,KAAK,WAAW;AAAA,UAC1C;AAAA,QACE;AAAA,QACA,EAAE,OAAO,MAAM,QAAQ,aAAa,gBAAgB;AAAA,QACpD,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAEA,YAAI,gDAAiB,KAAK,oBAAoB,QAAW;AACvD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,2BAA2B,KAAK,WAAW;AAAA,UAC/C,uDAA6B,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;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0C;AAC1C,gCAAiC;
|
|
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;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0C;AAC1C,gCAAiC;AAI1B,MAAM,qBAAqB,2CAAiB;AAAA,EACjD,eAAe,MAAsD;AACnE,UAAM,GAAG,IAAI;AACb,mDAA0B,IAAI;AAAA,EAChC;AACF;","names":[]}
|
|
@@ -26,53 +26,89 @@ var import_breakpoints = require("../../state/modules/breakpoints");
|
|
|
26
26
|
var import_copy_element_tree = require("../../state/ops/copy-element-tree");
|
|
27
27
|
var import_read_only_state = require("../../state/read-only-state");
|
|
28
28
|
var import_store = require("../../state/store");
|
|
29
|
-
var
|
|
30
|
-
var
|
|
29
|
+
var import_ref_counted_map = require("../../utils/ref-counted-map");
|
|
30
|
+
var import_is_server = require("../../utils/is-server");
|
|
31
|
+
const VERSION_TAG_LIVE = "ref:live";
|
|
31
32
|
class RuntimeCore {
|
|
32
|
-
store
|
|
33
|
-
|
|
33
|
+
// The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays
|
|
34
|
+
// in the map. If an entry expires and is removed from the map before React commits, the store remains retained
|
|
35
|
+
// via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of
|
|
36
|
+
// reusing the existing one, reducing cache efficiency.
|
|
37
|
+
activeStores = new import_ref_counted_map.RefCountedMap({
|
|
38
|
+
unownedEntryTtlMs: 1e3,
|
|
39
|
+
// Checking on retain/release is sufficient on the client, and we don't need to check on get on the server
|
|
40
|
+
// as the only scenario in which we add the store to the map is when the runtime is already bound to the
|
|
41
|
+
// requested site version, which should be the only site version for which the store is requested
|
|
42
|
+
ttlCheck: import_ref_counted_map.RefCountedMap.TTLCheck.ON_RETAIN | import_ref_counted_map.RefCountedMap.TTLCheck.ON_RELEASE
|
|
43
|
+
});
|
|
44
|
+
protoStore;
|
|
34
45
|
appOrigin;
|
|
35
46
|
apiOrigin;
|
|
47
|
+
requestKey;
|
|
48
|
+
fetch;
|
|
36
49
|
constructor({
|
|
37
50
|
appOrigin = "https://app.makeswift.com",
|
|
38
51
|
apiOrigin = "https://api.makeswift.com",
|
|
39
52
|
breakpoints,
|
|
53
|
+
requestKey,
|
|
40
54
|
fetch
|
|
41
55
|
}) {
|
|
42
56
|
this.appOrigin = validateOrigin(appOrigin, "appOrigin");
|
|
43
57
|
this.apiOrigin = validateOrigin(apiOrigin, "apiOrigin");
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.store = (0, import_store.configureStore)({
|
|
49
|
-
name: "Runtime store",
|
|
50
|
-
hostApiClient: this.hostApiClient,
|
|
51
|
-
appOrigin: this.appOrigin,
|
|
52
|
-
preloadedState: null,
|
|
58
|
+
this.requestKey = requestKey;
|
|
59
|
+
this.fetch = fetch;
|
|
60
|
+
this.protoStore = (0, import_store.configureProtoStore)({
|
|
61
|
+
name: "Runtime proto-store",
|
|
53
62
|
breakpoints: breakpoints ? (0, import_breakpoints.parseBreakpointsInput)(breakpoints) : void 0
|
|
54
63
|
});
|
|
55
64
|
}
|
|
56
|
-
|
|
57
|
-
siteVersion,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
getOrCreateStore({ siteVersion, locale }) {
|
|
66
|
+
const key = storeCacheKey({ siteVersion, locale });
|
|
67
|
+
const createStore = () => {
|
|
68
|
+
const hostApiClient = new import_client.MakeswiftHostApiClient({
|
|
69
|
+
uri: new URL("graphql", this.apiOrigin).href,
|
|
70
|
+
fetch: this.fetch,
|
|
71
|
+
preloadedState: { siteVersion, locale }
|
|
72
|
+
});
|
|
73
|
+
const isReadOnly = siteVersion == null;
|
|
74
|
+
return (0, import_store.configureReadWriteStore)({
|
|
75
|
+
name: `Runtime read-write store (site version: ${key})`,
|
|
76
|
+
appOrigin: this.appOrigin,
|
|
77
|
+
hostApiClient,
|
|
78
|
+
preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale }
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const usePersistentStore = this.shouldUsePersistentStore(key);
|
|
82
|
+
return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore();
|
|
64
83
|
}
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
84
|
+
retainStore({ siteVersion, locale }, store) {
|
|
85
|
+
const key = storeCacheKey({ siteVersion, locale });
|
|
86
|
+
if (!this.shouldUsePersistentStore(key)) {
|
|
87
|
+
console.error("RuntimeCore: attempt to retain an ephemeral store", { key });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.activeStores.retain(key, store);
|
|
91
|
+
}
|
|
92
|
+
releaseStore({ siteVersion, locale }, store) {
|
|
93
|
+
const key = storeCacheKey({ siteVersion, locale });
|
|
94
|
+
if (!this.shouldUsePersistentStore(key)) {
|
|
95
|
+
console.error("RuntimeCore: attempt to release an ephemeral store", { key });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.activeStores.release(key, store);
|
|
68
99
|
}
|
|
69
100
|
copyElementTree(elementTree, replacementContext) {
|
|
70
|
-
return (0, import_copy_element_tree.copyElementTree)(this.
|
|
101
|
+
return (0, import_copy_element_tree.copyElementTree)(this.protoStore.getState(), elementTree, replacementContext);
|
|
71
102
|
}
|
|
72
103
|
getBreakpoints() {
|
|
73
|
-
return (0, import_read_only_state.getBreakpoints)(this.
|
|
104
|
+
return (0, import_read_only_state.getBreakpoints)(this.protoStore.getState());
|
|
105
|
+
}
|
|
106
|
+
shouldUsePersistentStore(key) {
|
|
107
|
+
return !(0, import_is_server.isServer)() || this.requestKey !== void 0 && storeCacheKey(this.requestKey) === key;
|
|
74
108
|
}
|
|
75
109
|
}
|
|
110
|
+
const storeCacheKey = ({ siteVersion, locale }) => `${siteVersionTag(siteVersion)}/${locale ?? "default"}`;
|
|
111
|
+
const siteVersionTag = (siteVersion) => siteVersion?.version ?? VERSION_TAG_LIVE;
|
|
76
112
|
function validateOrigin(url, name) {
|
|
77
113
|
try {
|
|
78
114
|
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAuC;AAIvC,yBAIO;AAEP,+BAAgC;AAEhC,6BAA+D;AAC/D,mBAKO;AAEP,6BAA8B;AAC9B,uBAAyB;AAOzB,MAAM,mBAAmB;AAElB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,eAAe,IAAI,qCAAoC;AAAA,IACtE,mBAAmB;AAAA;AAAA;AAAA;AAAA,IAInB,UAAU,qCAAc,SAAS,YAAY,qCAAc,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,iBAAa,kCAAoB;AAAA,MACpC,MAAM;AAAA,MACN,aAAa,kBAAc,0CAAsB,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,qCAAuB;AAAA,QAC/C,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE;AAAA,QACxC,OAAO,KAAK;AAAA,QACZ,gBAAgB,EAAE,aAAa,OAAO;AAAA,MACxC,CAAC;AAID,YAAM,aAAa,eAAe;AAElC,iBAAO,sCAAwB;AAAA,QAC7B,MAAM,2CAA2C,GAAG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MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
|
|
@@ -29,10 +29,8 @@ __export(read_only_actions_exports, {
|
|
|
29
29
|
registerPropControllers: () => registerPropControllers,
|
|
30
30
|
registerPropControllersHandle: () => registerPropControllersHandle,
|
|
31
31
|
registerReactComponentEffect: () => registerReactComponentEffect,
|
|
32
|
-
resetLocaleState: () => resetLocaleState,
|
|
33
32
|
setIsInBuilder: () => setIsInBuilder,
|
|
34
33
|
setIsReadOnly: () => setIsReadOnly,
|
|
35
|
-
setSiteVersion: () => setSiteVersion,
|
|
36
34
|
unregisterComponent: () => unregisterComponent,
|
|
37
35
|
unregisterPropControllers: () => unregisterPropControllers,
|
|
38
36
|
unregisterPropControllersHandle: () => unregisterPropControllersHandle
|
|
@@ -55,11 +53,7 @@ const ReadOnlyActionTypes = {
|
|
|
55
53
|
REGISTER_REACT_COMPONENT: "REGISTER_REACT_COMPONENT",
|
|
56
54
|
UNREGISTER_REACT_COMPONENT: "UNREGISTER_REACT_COMPONENT",
|
|
57
55
|
SET_IS_IN_BUILDER: "SET_IS_IN_BUILDER",
|
|
58
|
-
SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
|
|
59
|
-
SET_SITE_VERSION: "SET_SITE_VERSION",
|
|
60
|
-
// TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`
|
|
61
|
-
// (requires changes to the builder to handle null locales)
|
|
62
|
-
RESET_LOCALE_STATE: "RESET_LOCALE_STATE"
|
|
56
|
+
SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
|
|
63
57
|
};
|
|
64
58
|
function apiResourceFulfilled(resourceType, resourceId, resource, locale) {
|
|
65
59
|
return {
|
|
@@ -157,12 +151,6 @@ function setIsInBuilder(isInBuilder) {
|
|
|
157
151
|
function setIsReadOnly(isReadOnly) {
|
|
158
152
|
return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly };
|
|
159
153
|
}
|
|
160
|
-
function setSiteVersion(siteVersion) {
|
|
161
|
-
return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion };
|
|
162
|
-
}
|
|
163
|
-
function resetLocaleState() {
|
|
164
|
-
return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE };
|
|
165
|
-
}
|
|
166
154
|
// Annotate the CommonJS export names for ESM import in node:
|
|
167
155
|
0 && (module.exports = {
|
|
168
156
|
ReadOnlyActionTypes,
|
|
@@ -176,10 +164,8 @@ function resetLocaleState() {
|
|
|
176
164
|
registerPropControllers,
|
|
177
165
|
registerPropControllersHandle,
|
|
178
166
|
registerReactComponentEffect,
|
|
179
|
-
resetLocaleState,
|
|
180
167
|
setIsInBuilder,
|
|
181
168
|
setIsReadOnly,
|
|
182
|
-
setSiteVersion,
|
|
183
169
|
unregisterComponent,
|
|
184
170
|
unregisterPropControllers,
|
|
185
171
|
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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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/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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,UAC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EAAE,aAAa,YAAY,OAAO;AAAA,EAC7C;AACF;AAEO,SAAS,gCACd,aACA,YACuC;AACvC,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEO,SAAS,wBACd,aACA,YACA,iBAC+B;AAC/B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,YAAY,gBAAgB;AAAA,EACtD;AACF;AAEO,SAAS,0BACd,aACA,YACiC;AACjC,SAAO;AAAA,IACL,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;","names":[]}
|
|
@@ -42,7 +42,6 @@ var APIResources = __toESM(require("./modules/api-resources"));
|
|
|
42
42
|
var LocalizedResourcesMap = __toESM(require("./modules/localized-resources-map"));
|
|
43
43
|
var import_actions = require("./actions");
|
|
44
44
|
var import_read_only_actions = require("./actions/internal/read-only-actions");
|
|
45
|
-
var import_read_write_actions = require("./actions/internal/read-write-actions");
|
|
46
45
|
var import_host_api = require("./host-api");
|
|
47
46
|
var import_toolkit2 = require("./toolkit");
|
|
48
47
|
var import_api = require("../api");
|
|
@@ -187,34 +186,11 @@ function defaultLocaleMiddleware() {
|
|
|
187
186
|
};
|
|
188
187
|
});
|
|
189
188
|
}
|
|
190
|
-
function
|
|
191
|
-
return (0, import_toolkit2.actionMiddleware)(({ getState, dispatch }) => (next) => {
|
|
192
|
-
return (action) => {
|
|
193
|
-
switch (action.type) {
|
|
194
|
-
case import_read_only_actions.ReadOnlyActionTypes.SET_SITE_VERSION: {
|
|
195
|
-
const cacheVersion = SiteVersionState.getSiteVersion(getState().siteVersion);
|
|
196
|
-
if (cacheVersion?.version !== action.payload?.version) {
|
|
197
|
-
dispatch((0, import_read_write_actions.clearAPIClientCache)());
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return next(action);
|
|
202
|
-
};
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
function configureStore({ serializedState }) {
|
|
189
|
+
function configureStore({ preloadedState }) {
|
|
206
190
|
return (0, import_toolkit.configureStore)({
|
|
207
191
|
reducer,
|
|
208
|
-
preloadedState
|
|
209
|
-
|
|
210
|
-
localizedResourcesMap: LocalizedResourcesMap.getInitialState(
|
|
211
|
-
serializedState?.localizedResourcesMap
|
|
212
|
-
)
|
|
213
|
-
},
|
|
214
|
-
middleware: (getDefaultMiddleware) => getDefaultMiddleware(import_toolkit2.middlewareOptions).concat(
|
|
215
|
-
defaultLocaleMiddleware(),
|
|
216
|
-
cacheVersioningMiddleware()
|
|
217
|
-
),
|
|
192
|
+
preloadedState,
|
|
193
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware(import_toolkit2.middlewareOptions).concat(defaultLocaleMiddleware()),
|
|
218
194
|
devTools: (0, import_toolkit2.devToolsConfig)({
|
|
219
195
|
name: `API client store (${(/* @__PURE__ */ new Date()).toISOString()})`,
|
|
220
196
|
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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAOO;AAEP,0BAA0E;AAE1E,uBAAkC;AAClC,kBAA6B;AAC7B,mBAA8B;AAC9B,4BAAuC;AAEvC,qBAAyC;AACzC,+BAA0D;AAC1D,gCAAoC;AACpC,sBAAuC;AACvC,IAAAA,kBAAoE;AAEpE,iBAWO;AAEP,MAAM,cAAU,gCAAgB;AAAA,EAC9B,aAAa,iBAAiB;AAAA,EAC9B,QAAQ,YAAY;AAAA,EACpB,c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AAA,UAChC;AAAA,QACF;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe,EAAE,gBAAgB,GAA0C;AACzF,aAAO,eAAAC,gBAAoB;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,iCAAiB,EAAE;AAAA,MACtC,wBAAwB;AAAA,MACxB,0BAA0B;AAAA,IAC5B;AAAA,IAEF,cAAU,gCAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,2BAAY;AAAA,QACZ,2BAAY;AAAA,QACZ,2BAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":["import_toolkit","configureReduxStore"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../api/site-version'\n\nimport * as SiteVersionState from './modules/site-version'\nimport * as LocaleState from './modules/locale'\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\n\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled } from './actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n siteVersion: SiteVersionState.reducer,\n locale: LocaleState.reducer,\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(({ getState }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: {\n ...action.payload,\n locale: locale ?? LocaleState.getLocale(getState().locale),\n },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({ preloadedState }: { preloadedState: Partial<State> }) {\n return configureReduxStore({\n reducer,\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware()),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAOO;AAEP,0BAA0E;AAE1E,uBAAkC;AAClC,kB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AAA,IACA;AAAA,IAEA,YAAY,0BACV,qBAAqB,iCAAiB,EAAE,OAAO,wBAAwB,CAAC;AAAA,IAE1E,cAAU,gCAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,2BAAY;AAAA,QACZ,2BAAY;AAAA,QACZ,2BAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":["import_toolkit","configureReduxStore"]}
|
|
@@ -256,6 +256,9 @@ function initializeBuilderConnection(builderProxy) {
|
|
|
256
256
|
const unregisterBuilderComponents = dispatch(registerBuilderComponents());
|
|
257
257
|
const breakpoints = ReadOnlyState.getBreakpoints(getState());
|
|
258
258
|
dispatch(Builder.setBreakpoints(breakpoints));
|
|
259
|
+
const locale = ReadOnlyState.getLocale(getState());
|
|
260
|
+
if (locale != null)
|
|
261
|
+
dispatch(Builder.setLocale(new Intl.Locale(locale)));
|
|
259
262
|
dispatch(ReadOnly.setIsInBuilder(true));
|
|
260
263
|
builderProxy.dispatchBuffered();
|
|
261
264
|
return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/state/middleware/read-write/builder-api/initialize-connection.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport deepEqual from '../../../../utils/deepEqual'\n\nimport * as BoxModels from '../../../modules/read-write/box-models'\nimport * as BuilderEditMode from '../../../modules/builder-edit-mode'\n\nimport { type Action } from '../../../actions'\n\nimport * as ReadOnly from '../../../actions/internal/read-only-actions'\nimport * as Builder from '../../../builder-api/actions'\n\nimport { serializeControls } from '../../../../builder'\nimport { type BuilderAPIProxy } from '../../../builder-api/proxy'\n\nimport * as ReadOnlyState from '../../../read-only-state'\nimport {\n type State,\n getDocuments,\n getMeasurables,\n getBoxModels,\n getBoxModel,\n getElementImperativeHandlesContainingElement,\n getPointer,\n} from '../../../read-write-state'\n\nimport { type ElementSize, getElementSize } from './element-size'\n\nfunction measureElements(): ThunkAction<void, State, unknown, Action> {\n return (dispatch, getState) => {\n const measurables = getMeasurables(getState())\n const currentBoxModels = getBoxModels(getState())\n const measuredBoxModels = new Map<string, Map<string, BoxModels.BoxDisplayModel>>()\n\n measurables.forEach((documentMeasurables, documentKey) => {\n const measuredDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel>()\n\n documentMeasurables.forEach((measurable, elementKey) => {\n const boxModel = BoxModels.measure(measurable)\n\n if (boxModel != null) measuredDocumentBoxModels.set(elementKey, boxModel)\n })\n\n if (measuredDocumentBoxModels.size > 0) {\n measuredBoxModels.set(documentKey, measuredDocumentBoxModels)\n }\n })\n\n const changedBoxModels = new Map<string, Map<string, BoxModels.BoxDisplayModel | null>>()\n\n currentBoxModels.forEach((currentDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel | null>()\n\n currentDocumentBoxModels.forEach((_boxModel, elementKey) => {\n if (!measuredBoxModels.get(documentKey)?.has(elementKey)) {\n changedDocumentBoxModels.set(elementKey, null)\n }\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n })\n\n measuredBoxModels.forEach((measuredDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel | null>()\n\n measuredDocumentBoxModels.forEach((measuredBoxModel, elementKey) => {\n const currentBoxModel = getBoxModel(getState(), documentKey, elementKey)\n\n if (currentBoxModel == null || !deepEqual(currentBoxModel, measuredBoxModel)) {\n changedDocumentBoxModels.set(elementKey, measuredBoxModel)\n }\n })\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n\n if (changedBoxModels.size > 0) dispatch(Builder.changeElementBoxModels(changedBoxModels))\n }\n}\n\nfunction startMeasuringElements(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n dispatch(measureElements())\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction lockDocumentScroll(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n const lastDocumentOverflow = window.document.documentElement.style.overflow\n window.document.documentElement.style.overflow = 'hidden'\n\n window.document.documentElement.addEventListener('wheel', handleWheelEvent)\n\n return () => {\n window.document.documentElement.style.overflow = lastDocumentOverflow\n window.document.documentElement.removeEventListener('wheel', handleWheelEvent)\n }\n\n function handleWheelEvent({ deltaX, deltaY }: WheelEvent) {\n dispatch(Builder.handleWheel({ deltaX, deltaY }))\n }\n }\n}\n\nfunction startHandlingPointerMoveEvent(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n window.document.documentElement.addEventListener('pointermove', handlePointerMoveEvent)\n\n return () => {\n window.document.documentElement.removeEventListener('pointermove', handlePointerMoveEvent)\n }\n\n function handlePointerMoveEvent({ clientX, clientY }: PointerEvent) {\n dispatch(Builder.handlePointerMove({ clientX, clientY }))\n }\n }\n}\n\nfunction startHandlingFocusEvents(): ThunkAction<() => void, State, unknown, Action> {\n return (_dispatch, getState) => {\n window.addEventListener('focusin', handleFocusIn)\n window.addEventListener('focusout', handleFocusOut)\n\n return () => {\n window.removeEventListener('focusin', handleFocusIn)\n window.removeEventListener('focusout', handleFocusOut)\n }\n\n function handleFocusIn(event: FocusEvent) {\n if (\n ReadOnlyState.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT\n ) {\n return\n }\n\n if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {\n window.parent.focus()\n }\n }\n\n function handleFocusOut(event: FocusEvent) {\n if (\n ReadOnlyState.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT\n ) {\n return\n }\n\n if (\n !(event.relatedTarget instanceof window.HTMLElement) ||\n !event.relatedTarget.isContentEditable\n ) {\n window.parent.focus()\n }\n }\n }\n}\n\nfunction startMeasuringDocumentElement(): ThunkAction<() => void, unknown, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n let lastSize: ElementSize\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n const nextSize = getElementSize(window.document.documentElement)\n\n if (!deepEqual(lastSize, nextSize)) {\n lastSize = nextSize\n\n dispatch(Builder.changeDocumentElementSize(nextSize))\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction elementKeysFromElementFromPoint(\n elementFromPoint: Element | null,\n): ThunkAction<{ documentKey: string; elementKey: string } | null, State, unknown, Action> {\n return (_dispatch, getState) => {\n if (elementFromPoint == null) return null\n\n const elementImperativeHandles = getElementImperativeHandlesContainingElement(\n getState(),\n elementFromPoint,\n )\n const ascendingDepthDocumentKeys = ReadOnlyState.getDocumentKeysSortedByDepth(getState())\n const descendingDepthDocumentKeys = ascendingDepthDocumentKeys.slice().reverse()\n\n let currentElement: Element | null = elementFromPoint\n let keys = null\n\n while (currentElement != null) {\n for (const documentKey of descendingDepthDocumentKeys) {\n const byElementKey = elementImperativeHandles.get(documentKey)\n\n if (byElementKey == null) continue\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n if (elementImperativeHandle.getDomNode() === currentElement) {\n return { documentKey, elementKey }\n }\n }\n }\n\n currentElement = currentElement.parentElement\n }\n\n return keys\n }\n}\n\nfunction startPollingElementFromPoint(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n let lastElementFromPoint: Element | null = null\n let animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameRequestId)\n }\n\n function handleAnimationFrameRequest() {\n const pointer = getPointer(getState())\n const elementFromPoint =\n pointer == null ? null : document.elementFromPoint(pointer.x, pointer.y)\n\n if (elementFromPoint !== lastElementFromPoint) {\n lastElementFromPoint = elementFromPoint\n\n const keys = dispatch(elementKeysFromElementFromPoint(elementFromPoint))\n\n dispatch(Builder.elementFromPointChange(keys))\n }\n\n animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction registerBuilderComponents(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const state = getState()\n const componentsMeta = ReadOnlyState.getComponentsMeta(state)\n\n componentsMeta.forEach((meta, type) => {\n const descriptors = ReadOnlyState.getComponentPropControllerDescriptors(state, type)\n if (descriptors != null) {\n const [serializedControls, transferables] = serializeControls(descriptors)\n dispatch(\n Builder.registerBuilderComponent({ type, meta, serializedControls }, transferables),\n )\n }\n })\n\n return () => {\n componentsMeta.forEach((_, type) => {\n dispatch(Builder.unregisterBuilderComponent({ type }))\n })\n }\n }\n}\n\nfunction registerBuilderDocuments(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const documents = getDocuments(getState())\n\n documents.forEach(document => {\n dispatch(Builder.registerBuilderDocument(document))\n })\n\n return () => {\n documents.forEach((_document, documentKey) => {\n dispatch(Builder.unregisterBuilderDocument(documentKey))\n })\n }\n }\n}\n\nexport function initializeBuilderConnection(\n builderProxy: BuilderAPIProxy,\n): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const unregisterBuilderDocuments = dispatch(registerBuilderDocuments())\n const stopMeasuringElements = dispatch(startMeasuringElements())\n const stopMeasuringDocumentElement = dispatch(startMeasuringDocumentElement())\n const stopHandlingFocusEvent = dispatch(startHandlingFocusEvents())\n const unlockDocumentScroll = dispatch(lockDocumentScroll())\n const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent())\n const stopPollingElementFromPoint = dispatch(startPollingElementFromPoint())\n const unregisterBuilderComponents = dispatch(registerBuilderComponents())\n\n const breakpoints = ReadOnlyState.getBreakpoints(getState())\n dispatch(Builder.setBreakpoints(breakpoints))\n dispatch(ReadOnly.setIsInBuilder(true))\n builderProxy.dispatchBuffered()\n\n return () => {\n unregisterBuilderDocuments()\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n stopPollingElementFromPoint()\n unregisterBuilderComponents()\n dispatch(ReadOnly.setIsInBuilder(false))\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAAsB;AAEtB,gBAA2B;AAC3B,sBAAiC;AAIjC,eAA0B;AAC1B,cAAyB;AAEzB,qBAAkC;AAGlC,oBAA+B;AAC/B,8BAQO;AAEP,0BAAiD;AAEjD,SAAS,kBAA6D;AACpE,SAAO,CAAC,UAAU,aAAa;AAC7B,UAAM,kBAAc,wCAAe,SAAS,CAAC;AAC7C,UAAM,uBAAmB,sCAAa,SAAS,CAAC;AAChD,UAAM,oBAAoB,oBAAI,IAAoD;AAElF,gBAAY,QAAQ,CAAC,qBAAqB,gBAAgB;AACxD,YAAM,4BAA4B,oBAAI,IAAuC;AAE7E,0BAAoB,QAAQ,CAAC,YAAY,eAAe;AACtD,cAAM,WAAW,UAAU,QAAQ,UAAU;AAE7C,YAAI,YAAY;AAAM,oCAA0B,IAAI,YAAY,QAAQ;AAAA,MAC1E,CAAC;AAED,UAAI,0BAA0B,OAAO,GAAG;AACtC,0BAAkB,IAAI,aAAa,yBAAyB;AAAA,MAC9D;AAAA,IACF,CAAC;AAED,UAAM,mBAAmB,oBAAI,IAA2D;AAExF,qBAAiB,QAAQ,CAAC,0BAA0B,gBAAgB;AAClE,YAAM,2BAA2B,oBAAI,IAA8C;AAEnF,+BAAyB,QAAQ,CAAC,WAAW,eAAe;AAC1D,YAAI,CAAC,kBAAkB,IAAI,WAAW,GAAG,IAAI,UAAU,GAAG;AACxD,mCAAyB,IAAI,YAAY,IAAI;AAAA,QAC/C;AAEA,YAAI,yBAAyB,OAAO,GAA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AA8B,SAAS,6BAA6B,CAAC;AAC3E,UAAM,8BAA8B,SAAS,0BAA0B,CAAC;AAExE,UAAM,cAAc,cAAc,eAAe,SAAS,CAAC;AAC3D,aAAS,QAAQ,eAAe,WAAW,CAAC;AAC5C,aAAS,SAAS,eAAe,IAAI,CAAC;AACtC,iBAAa,iBAAiB;AAE9B,WAAO,MAAM;AACX,iCAA2B;AAC3B,4BAAsB;AACtB,mCAA6B;AAC7B,6BAAuB;AACvB,2BAAqB;AACrB,mCAA6B;AAC7B,kCAA4B;AAC5B,kCAA4B;AAC5B,eAAS,SAAS,eAAe,KAAK,CAAC;AAAA,IACzC;AAAA,EACF;AACF;","names":["deepEqual","document"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/state/middleware/read-write/builder-api/initialize-connection.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport deepEqual from '../../../../utils/deepEqual'\n\nimport * as BoxModels from '../../../modules/read-write/box-models'\nimport * as BuilderEditMode from '../../../modules/builder-edit-mode'\n\nimport { type Action } from '../../../actions'\n\nimport * as ReadOnly from '../../../actions/internal/read-only-actions'\nimport * as Builder from '../../../builder-api/actions'\n\nimport { serializeControls } from '../../../../builder'\nimport { type BuilderAPIProxy } from '../../../builder-api/proxy'\n\nimport * as ReadOnlyState from '../../../read-only-state'\nimport {\n type State,\n getDocuments,\n getMeasurables,\n getBoxModels,\n getBoxModel,\n getElementImperativeHandlesContainingElement,\n getPointer,\n} from '../../../read-write-state'\n\nimport { type ElementSize, getElementSize } from './element-size'\n\nfunction measureElements(): ThunkAction<void, State, unknown, Action> {\n return (dispatch, getState) => {\n const measurables = getMeasurables(getState())\n const currentBoxModels = getBoxModels(getState())\n const measuredBoxModels = new Map<string, Map<string, BoxModels.BoxDisplayModel>>()\n\n measurables.forEach((documentMeasurables, documentKey) => {\n const measuredDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel>()\n\n documentMeasurables.forEach((measurable, elementKey) => {\n const boxModel = BoxModels.measure(measurable)\n\n if (boxModel != null) measuredDocumentBoxModels.set(elementKey, boxModel)\n })\n\n if (measuredDocumentBoxModels.size > 0) {\n measuredBoxModels.set(documentKey, measuredDocumentBoxModels)\n }\n })\n\n const changedBoxModels = new Map<string, Map<string, BoxModels.BoxDisplayModel | null>>()\n\n currentBoxModels.forEach((currentDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel | null>()\n\n currentDocumentBoxModels.forEach((_boxModel, elementKey) => {\n if (!measuredBoxModels.get(documentKey)?.has(elementKey)) {\n changedDocumentBoxModels.set(elementKey, null)\n }\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n })\n\n measuredBoxModels.forEach((measuredDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxDisplayModel | null>()\n\n measuredDocumentBoxModels.forEach((measuredBoxModel, elementKey) => {\n const currentBoxModel = getBoxModel(getState(), documentKey, elementKey)\n\n if (currentBoxModel == null || !deepEqual(currentBoxModel, measuredBoxModel)) {\n changedDocumentBoxModels.set(elementKey, measuredBoxModel)\n }\n })\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n\n if (changedBoxModels.size > 0) dispatch(Builder.changeElementBoxModels(changedBoxModels))\n }\n}\n\nfunction startMeasuringElements(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n dispatch(measureElements())\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction lockDocumentScroll(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n const lastDocumentOverflow = window.document.documentElement.style.overflow\n window.document.documentElement.style.overflow = 'hidden'\n\n window.document.documentElement.addEventListener('wheel', handleWheelEvent)\n\n return () => {\n window.document.documentElement.style.overflow = lastDocumentOverflow\n window.document.documentElement.removeEventListener('wheel', handleWheelEvent)\n }\n\n function handleWheelEvent({ deltaX, deltaY }: WheelEvent) {\n dispatch(Builder.handleWheel({ deltaX, deltaY }))\n }\n }\n}\n\nfunction startHandlingPointerMoveEvent(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n window.document.documentElement.addEventListener('pointermove', handlePointerMoveEvent)\n\n return () => {\n window.document.documentElement.removeEventListener('pointermove', handlePointerMoveEvent)\n }\n\n function handlePointerMoveEvent({ clientX, clientY }: PointerEvent) {\n dispatch(Builder.handlePointerMove({ clientX, clientY }))\n }\n }\n}\n\nfunction startHandlingFocusEvents(): ThunkAction<() => void, State, unknown, Action> {\n return (_dispatch, getState) => {\n window.addEventListener('focusin', handleFocusIn)\n window.addEventListener('focusout', handleFocusOut)\n\n return () => {\n window.removeEventListener('focusin', handleFocusIn)\n window.removeEventListener('focusout', handleFocusOut)\n }\n\n function handleFocusIn(event: FocusEvent) {\n if (\n ReadOnlyState.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT\n ) {\n return\n }\n\n if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {\n window.parent.focus()\n }\n }\n\n function handleFocusOut(event: FocusEvent) {\n if (\n ReadOnlyState.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT\n ) {\n return\n }\n\n if (\n !(event.relatedTarget instanceof window.HTMLElement) ||\n !event.relatedTarget.isContentEditable\n ) {\n window.parent.focus()\n }\n }\n }\n}\n\nfunction startMeasuringDocumentElement(): ThunkAction<() => void, unknown, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n let lastSize: ElementSize\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n const nextSize = getElementSize(window.document.documentElement)\n\n if (!deepEqual(lastSize, nextSize)) {\n lastSize = nextSize\n\n dispatch(Builder.changeDocumentElementSize(nextSize))\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction elementKeysFromElementFromPoint(\n elementFromPoint: Element | null,\n): ThunkAction<{ documentKey: string; elementKey: string } | null, State, unknown, Action> {\n return (_dispatch, getState) => {\n if (elementFromPoint == null) return null\n\n const elementImperativeHandles = getElementImperativeHandlesContainingElement(\n getState(),\n elementFromPoint,\n )\n const ascendingDepthDocumentKeys = ReadOnlyState.getDocumentKeysSortedByDepth(getState())\n const descendingDepthDocumentKeys = ascendingDepthDocumentKeys.slice().reverse()\n\n let currentElement: Element | null = elementFromPoint\n let keys = null\n\n while (currentElement != null) {\n for (const documentKey of descendingDepthDocumentKeys) {\n const byElementKey = elementImperativeHandles.get(documentKey)\n\n if (byElementKey == null) continue\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n if (elementImperativeHandle.getDomNode() === currentElement) {\n return { documentKey, elementKey }\n }\n }\n }\n\n currentElement = currentElement.parentElement\n }\n\n return keys\n }\n}\n\nfunction startPollingElementFromPoint(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n let lastElementFromPoint: Element | null = null\n let animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameRequestId)\n }\n\n function handleAnimationFrameRequest() {\n const pointer = getPointer(getState())\n const elementFromPoint =\n pointer == null ? null : document.elementFromPoint(pointer.x, pointer.y)\n\n if (elementFromPoint !== lastElementFromPoint) {\n lastElementFromPoint = elementFromPoint\n\n const keys = dispatch(elementKeysFromElementFromPoint(elementFromPoint))\n\n dispatch(Builder.elementFromPointChange(keys))\n }\n\n animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nfunction registerBuilderComponents(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const state = getState()\n const componentsMeta = ReadOnlyState.getComponentsMeta(state)\n\n componentsMeta.forEach((meta, type) => {\n const descriptors = ReadOnlyState.getComponentPropControllerDescriptors(state, type)\n if (descriptors != null) {\n const [serializedControls, transferables] = serializeControls(descriptors)\n dispatch(\n Builder.registerBuilderComponent({ type, meta, serializedControls }, transferables),\n )\n }\n })\n\n return () => {\n componentsMeta.forEach((_, type) => {\n dispatch(Builder.unregisterBuilderComponent({ type }))\n })\n }\n }\n}\n\nfunction registerBuilderDocuments(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const documents = getDocuments(getState())\n\n documents.forEach(document => {\n dispatch(Builder.registerBuilderDocument(document))\n })\n\n return () => {\n documents.forEach((_document, documentKey) => {\n dispatch(Builder.unregisterBuilderDocument(documentKey))\n })\n }\n }\n}\n\nexport function initializeBuilderConnection(\n builderProxy: BuilderAPIProxy,\n): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n const unregisterBuilderDocuments = dispatch(registerBuilderDocuments())\n const stopMeasuringElements = dispatch(startMeasuringElements())\n const stopMeasuringDocumentElement = dispatch(startMeasuringDocumentElement())\n const stopHandlingFocusEvent = dispatch(startHandlingFocusEvents())\n const unlockDocumentScroll = dispatch(lockDocumentScroll())\n const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent())\n const stopPollingElementFromPoint = dispatch(startPollingElementFromPoint())\n const unregisterBuilderComponents = dispatch(registerBuilderComponents())\n\n const breakpoints = ReadOnlyState.getBreakpoints(getState())\n dispatch(Builder.setBreakpoints(breakpoints))\n\n const locale = ReadOnlyState.getLocale(getState())\n if (locale != null) dispatch(Builder.setLocale(new Intl.Locale(locale)))\n\n dispatch(ReadOnly.setIsInBuilder(true))\n builderProxy.dispatchBuffered()\n\n return () => {\n unregisterBuilderDocuments()\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n stopPollingElementFromPoint()\n unregisterBuilderComponents()\n dispatch(ReadOn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AAAM,eAAS,QAAQ,UAAU,IAAI,KAAK,OAAO,MAAM,CAAC,CAAC;AAEvE,aAAS,SAAS,eAAe,IAAI,CAAC;AACtC,iBAAa,iBAAiB;AAE9B,WAAO,MAAM;AACX,iCAA2B;AAC3B,4BAAsB;AACtB,mCAA6B;AAC7B,6BAAuB;AACvB,2BAAqB;AACrB,mCAA6B;AAC7B,kCAA4B;AAC5B,kCAA4B;AAC5B,eAAS,SAAS,eAAe,KAAK,CAAC;AAAA,IACzC;AAAA,EACF;AACF;","names":["deepEqual","document"]}
|
|
@@ -25,7 +25,6 @@ __export(locale_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(locale_exports);
|
|
26
26
|
var import_actions = require("../actions");
|
|
27
27
|
var import_shared_api = require("../shared-api");
|
|
28
|
-
var import_read_only_actions = require("../actions/internal/read-only-actions");
|
|
29
28
|
function getInitialState(locale = null) {
|
|
30
29
|
return locale;
|
|
31
30
|
}
|
|
@@ -38,8 +37,6 @@ function reducer(state = getInitialState(), action) {
|
|
|
38
37
|
switch (action.type) {
|
|
39
38
|
case import_shared_api.SharedActionTypes.SET_LOCALE:
|
|
40
39
|
return action.payload.locale;
|
|
41
|
-
case import_read_only_actions.ReadOnlyActionTypes.RESET_LOCALE_STATE:
|
|
42
|
-
return getInitialState();
|
|
43
40
|
default:
|
|
44
41
|
return state;
|
|
45
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/locale.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { SharedActionTypes } from '../shared-api'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/locale.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { SharedActionTypes } from '../shared-api'\n\nexport type State = string | null\n\nexport function getInitialState(locale: string | null = null): State {\n return locale\n}\n\nexport function getLocale(state: State): string | null {\n return state\n}\n\nexport function reducer(state = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case SharedActionTypes.SET_LOCALE:\n return action.payload.locale\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+D;AAC/D,wBAAkC;AAI3B,SAAS,gBAAgB,SAAwB,MAAa;AACnE,SAAO;AACT;AAEO,SAAS,UAAU,OAA6B;AACrD,SAAO;AACT;AAEO,SAAS,QAAQ,QAAQ,gBAAgB,GAAG,QAAuC;AACxF,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,oCAAkB;AACrB,aAAO,OAAO,QAAQ;AAAA,IAExB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -24,7 +24,6 @@ __export(site_version_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(site_version_exports);
|
|
26
26
|
var import_actions = require("../actions");
|
|
27
|
-
var import_read_only_actions = require("../actions/internal/read-only-actions");
|
|
28
27
|
function getInitialState(siteVersion = null) {
|
|
29
28
|
return siteVersion;
|
|
30
29
|
}
|
|
@@ -35,8 +34,6 @@ function reducer(state = getInitialState(), action) {
|
|
|
35
34
|
if (!(0, import_actions.isKnownAction)(action))
|
|
36
35
|
return state;
|
|
37
36
|
switch (action.type) {
|
|
38
|
-
case import_read_only_actions.ReadOnlyActionTypes.SET_SITE_VERSION:
|
|
39
|
-
return action.payload;
|
|
40
37
|
default:
|
|
41
38
|
return state;
|
|
42
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/site-version.ts"],"sourcesContent":["import { type SiteVersion } from '../../api/site-version'\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/site-version.ts"],"sourcesContent":["import { type SiteVersion } from '../../api/site-version'\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\n\nexport type State = SiteVersion | null\n\nexport function getInitialState(siteVersion: SiteVersion | null = null): State {\n return siteVersion\n}\n\nexport function getSiteVersion(state: State): SiteVersion | null {\n return state\n}\n\nexport function reducer(state = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA+D;AAIxD,SAAS,gBAAgB,cAAkC,MAAa;AAC7E,SAAO;AACT;AAEO,SAAS,eAAe,OAAkC;AAC/D,SAAO;AACT;AAEO,SAAS,QAAQ,QAAQ,gBAAgB,GAAG,QAAuC;AACxF,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -44,6 +44,7 @@ __export(read_only_state_exports, {
|
|
|
44
44
|
getElements: () => getElements,
|
|
45
45
|
getIsInBuilder: () => getIsInBuilder,
|
|
46
46
|
getIsReadOnly: () => getIsReadOnly,
|
|
47
|
+
getLocale: () => getLocale,
|
|
47
48
|
getPropController: () => getPropController,
|
|
48
49
|
getPropControllerDescriptors: () => getPropControllerDescriptors,
|
|
49
50
|
getPropControllers: () => getPropControllers,
|
|
@@ -56,6 +57,7 @@ __export(read_only_state_exports, {
|
|
|
56
57
|
module.exports = __toCommonJS(read_only_state_exports);
|
|
57
58
|
var import_reselect = require("reselect");
|
|
58
59
|
var SiteVersion = __toESM(require("./modules/site-version"));
|
|
60
|
+
var Locale = __toESM(require("./modules/locale"));
|
|
59
61
|
var Documents = __toESM(require("./modules/read-only-documents"));
|
|
60
62
|
var ElementTrees = __toESM(require("./modules/element-trees"));
|
|
61
63
|
var ReactComponents = __toESM(require("./modules/react-components"));
|
|
@@ -68,8 +70,9 @@ var BuilderEditMode = __toESM(require("./modules/builder-edit-mode"));
|
|
|
68
70
|
var Breakpoints = __toESM(require("./modules/breakpoints"));
|
|
69
71
|
var import_read_only_documents = require("./modules/read-only-documents");
|
|
70
72
|
const reducers = {
|
|
71
|
-
isReadOnly: IsReadOnly.reducer,
|
|
72
73
|
siteVersion: SiteVersion.reducer,
|
|
74
|
+
isReadOnly: IsReadOnly.reducer,
|
|
75
|
+
locale: Locale.reducer,
|
|
73
76
|
documents: Documents.reducer,
|
|
74
77
|
elementTrees: ElementTrees.reducer,
|
|
75
78
|
reactComponents: ReactComponents.reducer,
|
|
@@ -181,6 +184,9 @@ function getBuilderEditMode(state) {
|
|
|
181
184
|
function getBreakpoints(state) {
|
|
182
185
|
return state.breakpoints;
|
|
183
186
|
}
|
|
187
|
+
function getLocale(state) {
|
|
188
|
+
return state.locale;
|
|
189
|
+
}
|
|
184
190
|
// Annotate the CommonJS export names for ESM import in node:
|
|
185
191
|
0 && (module.exports = {
|
|
186
192
|
createBaseDocument,
|
|
@@ -199,6 +205,7 @@ function getBreakpoints(state) {
|
|
|
199
205
|
getElements,
|
|
200
206
|
getIsInBuilder,
|
|
201
207
|
getIsReadOnly,
|
|
208
|
+
getLocale,
|
|
202
209
|
getPropController,
|
|
203
210
|
getPropControllerDescriptors,
|
|
204
211
|
getPropControllers,
|