@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/state/read-only-state.ts"],"sourcesContent":["import { type ThunkDispatch } from '@reduxjs/toolkit'\n\nimport { createSelector } from 'reselect'\n\nimport * as SiteVersion from './modules/site-version'\nimport * as Documents from './modules/read-only-documents'\nimport * as ElementTrees from './modules/element-trees'\nimport * as ReactComponents from './modules/react-components'\nimport * as ComponentsMeta from './modules/components-meta'\nimport * as PropControllers from './modules/prop-controllers'\nimport * as PropControllerHandles from './modules/prop-controller-handles'\nimport * as IsInBuilder from './modules/is-in-builder'\nimport * as IsReadOnly from './modules/is-read-only'\nimport * as BuilderEditMode from './modules/builder-edit-mode'\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { type Action } from './actions'\n\nexport type {\n Data,\n Document,\n DocumentReference,\n Element,\n ElementData,\n ElementReference,\n} from './modules/read-only-documents'\n\nexport {\n createBaseDocument,\n createDocumentReference,\n getRootElement,\n isElementReference,\n} from './modules/read-only-documents'\n\nexport type { ComponentType } from './modules/react-components'\nexport type { ComponentMeta } from './modules/components-meta'\n\nexport const reducers = {\n isReadOnly: IsReadOnly.reducer,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/state/read-only-state.ts"],"sourcesContent":["import { type ThunkDispatch } from '@reduxjs/toolkit'\n\nimport { createSelector } from 'reselect'\n\nimport * as SiteVersion from './modules/site-version'\nimport * as Locale from './modules/locale'\nimport * as Documents from './modules/read-only-documents'\nimport * as ElementTrees from './modules/element-trees'\nimport * as ReactComponents from './modules/react-components'\nimport * as ComponentsMeta from './modules/components-meta'\nimport * as PropControllers from './modules/prop-controllers'\nimport * as PropControllerHandles from './modules/prop-controller-handles'\nimport * as IsInBuilder from './modules/is-in-builder'\nimport * as IsReadOnly from './modules/is-read-only'\nimport * as BuilderEditMode from './modules/builder-edit-mode'\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { type Action } from './actions'\n\nexport type {\n Data,\n Document,\n DocumentReference,\n Element,\n ElementData,\n ElementReference,\n} from './modules/read-only-documents'\n\nexport {\n createBaseDocument,\n createDocumentReference,\n getRootElement,\n isElementReference,\n} from './modules/read-only-documents'\n\nexport type { ComponentType } from './modules/react-components'\nexport type { ComponentMeta } from './modules/components-meta'\n\nexport const reducers = {\n siteVersion: SiteVersion.reducer,\n isReadOnly: IsReadOnly.reducer,\n locale: Locale.reducer,\n documents: Documents.reducer,\n elementTrees: ElementTrees.reducer,\n reactComponents: ReactComponents.reducer,\n componentsMeta: ComponentsMeta.reducer,\n propControllers: PropControllers.reducer,\n propControllerHandles: PropControllerHandles.reducer,\n isInBuilder: IsInBuilder.reducer,\n builderEditMode: BuilderEditMode.reducer,\n breakpoints: Breakpoints.reducer,\n}\n\nexport type State = {\n siteVersion: SiteVersion.State\n isReadOnly: IsReadOnly.State\n locale: Locale.State\n documents: Documents.State\n elementTrees: ElementTrees.State\n reactComponents: ReactComponents.State\n componentsMeta: ComponentsMeta.State\n propControllers: PropControllers.State\n propControllerHandles: PropControllerHandles.State\n isInBuilder: IsInBuilder.State\n builderEditMode: BuilderEditMode.State\n breakpoints: Breakpoints.State\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nfunction getDocumentsStateSlice(state: State): Documents.State {\n return state.documents\n}\n\nexport function getDocument(state: State, documentKey: string): Documents.Document | null {\n return Documents.getDocument(getDocumentsStateSlice(state), documentKey)\n}\n\nfunction getElementTreesSlice(state: State): ElementTrees.State {\n return state.elementTrees\n}\n\nexport function getElements(\n state: State,\n documentKey: string,\n): ElementTrees.ElementTree['elements'] {\n return ElementTrees.getElements(getElementTreesSlice(state), documentKey)\n}\n\nexport function getElementIds(\n state: State,\n documentKey: string,\n): ElementTrees.ElementTree['elementIds'] {\n return ElementTrees.getElementIds(getElementTreesSlice(state), documentKey)\n}\n\nfunction getReactComponentsStateSlice(state: State): ReactComponents.State {\n return state.reactComponents\n}\n\nexport function getReactComponent(\n state: State,\n type: string,\n): ReactComponents.ComponentType | null {\n return ReactComponents.getReactComponent(getReactComponentsStateSlice(state), type)\n}\n\nfunction getComponentsMetaStateSlice(state: State): ComponentsMeta.State {\n return state.componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentsMeta.ComponentMeta> {\n return ComponentsMeta.getComponentsMeta(getComponentsMetaStateSlice(state))\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentsMeta.ComponentMeta | null {\n return ComponentsMeta.getComponentMeta(getComponentsMetaStateSlice(state), type)\n}\n\nfunction getPropControllersStateSlice(state: State): PropControllers.State {\n return state.propControllers\n}\n\nexport function getPropControllerDescriptors(state: State): PropControllers.State {\n return PropControllers.getPropControllerDescriptors(getPropControllersStateSlice(state))\n}\n\nexport function getComponentPropControllerDescriptors(\n state: State,\n componentType: string,\n): PropControllers.DescriptorsByProp | null {\n return PropControllers.getComponentPropControllerDescriptors(\n getPropControllersStateSlice(state),\n componentType,\n )\n}\n\nfunction getPropControllerHandlesStateSlice(state: State): PropControllerHandles.State {\n return state.propControllerHandles\n}\n\nexport function getPropControllers(\n state: State,\n { documentKey, elementKey }: { documentKey: string; elementKey: string },\n) {\n return PropControllerHandles.getPropControllers(\n getPropControllerHandlesStateSlice(state),\n documentKey,\n elementKey,\n )\n}\n\nexport function getPropControllersHandle(\n state: State,\n { documentKey, elementKey }: { documentKey: string; elementKey: string },\n) {\n return PropControllerHandles.getPropControllersHandle(\n getPropControllerHandlesStateSlice(state),\n documentKey,\n elementKey,\n )\n}\n\nexport function getPropController(\n state: State,\n {\n documentKey,\n elementKey,\n propName,\n }: { documentKey: string; elementKey: string; propName: string },\n) {\n return PropControllerHandles.getPropController(\n getPropControllerHandlesStateSlice(state),\n documentKey,\n elementKey,\n propName,\n )\n}\n\n/**\n * Returns all document keys sorted by depth, i.e., parent documents come before child documents.\n */\nexport const getDocumentKeysSortedByDepth: (state: State) => string[] = createSelector(\n [getDocumentsStateSlice, getElementTreesSlice],\n (documents, elementTrees) => {\n return [...documents.keys()].sort((a, b) => (elementTrees.get(a)?.elements.has(b) ? -1 : 1))\n },\n)\n\nexport function getElement(\n state: State,\n documentKey: string,\n elementKey: string,\n): Documents.Element | null {\n return ElementTrees.getElement(getElementTreesSlice(state), documentKey, elementKey)\n}\n\nexport function getElementId(state: State, documentKey: string, elementKey: string): string | null {\n return ElementTrees.getElementId(getElementTreesSlice(state), documentKey, elementKey)\n}\n\nexport function getElementPropControllerDescriptors(\n state: State,\n documentKey: string,\n elementKey: string,\n): Record<string, PropControllers.PropControllerDescriptor> | null {\n const element = getElement(state, documentKey, elementKey)\n\n if (element == null || Documents.isElementReference(element)) return null\n\n return getComponentPropControllerDescriptors(state, element.type)\n}\n\nexport function getIsInBuilder(state: State): boolean {\n return state.isInBuilder\n}\n\nexport function getIsReadOnly(state: State): boolean {\n return state.isReadOnly\n}\n\nexport function getBuilderEditMode(state: State): BuilderEditMode.State {\n return state.builderEditMode\n}\n\nexport function getBreakpoints(state: State): Breakpoints.State {\n return state.breakpoints\n}\n\nexport function getLocale(state: State): string | null {\n return state.locale\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAA+B;AAE/B,kBAA6B;AAC7B,aAAwB;AACxB,gBAA2B;AAC3B,mBAA8B;AAC9B,sBAAiC;AACjC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AG,WAAO;AAErE,SAAO,sCAAsC,OAAO,QAAQ,IAAI;AAClE;AAEO,SAAS,eAAe,OAAuB;AACpD,SAAO,MAAM;AACf;AAEO,SAAS,cAAc,OAAuB;AACnD,SAAO,MAAM;AACf;AAEO,SAAS,mBAAmB,OAAqC;AACtE,SAAO,MAAM;AACf;AAEO,SAAS,eAAe,OAAiC;AAC9D,SAAO,MAAM;AACf;AAEO,SAAS,UAAU,OAA6B;AACrD,SAAO,MAAM;AACf;","names":[]}
|
package/dist/cjs/state/store.js
CHANGED
|
@@ -29,7 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var store_exports = {};
|
|
30
30
|
__export(store_exports, {
|
|
31
31
|
conditionalReadWriteMiddleware: () => conditionalReadWriteMiddleware,
|
|
32
|
-
|
|
32
|
+
configureProtoStore: () => configureProtoStore,
|
|
33
|
+
configureReadWriteStore: () => configureReadWriteStore
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(store_exports);
|
|
35
36
|
var import_toolkit = require("@reduxjs/toolkit");
|
|
@@ -38,8 +39,45 @@ var import_actions = require("./builder-api/actions");
|
|
|
38
39
|
var import_host_api = require("./host-api");
|
|
39
40
|
var Breakpoints = __toESM(require("./modules/breakpoints"));
|
|
40
41
|
var import_read_only_element_tree = require("./middleware/read-only-element-tree");
|
|
41
|
-
var ReadOnlyState = __toESM(require("./read-only-state"));
|
|
42
42
|
var import_makeswift_api_client_sync = require("./middleware/makeswift-api-client-sync");
|
|
43
|
+
var ReadOnlyState = __toESM(require("./read-only-state"));
|
|
44
|
+
const configureStore = ({
|
|
45
|
+
name,
|
|
46
|
+
preloadedState,
|
|
47
|
+
enhancers,
|
|
48
|
+
middleware
|
|
49
|
+
}) => {
|
|
50
|
+
const store = (0, import_toolkit.configureStore)({
|
|
51
|
+
reducer: (0, import_toolkit.combineReducers)(ReadOnlyState.reducers),
|
|
52
|
+
preloadedState,
|
|
53
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware(import_toolkit2.middlewareOptions).concat([
|
|
54
|
+
(0, import_read_only_element_tree.readOnlyElementTreeMiddleware)(),
|
|
55
|
+
...middleware ? middleware() : []
|
|
56
|
+
]),
|
|
57
|
+
enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat(enhancers()),
|
|
58
|
+
devTools: (0, import_toolkit2.devToolsConfig)({
|
|
59
|
+
name: `${name} (${(/* @__PURE__ */ new Date()).toISOString()})`,
|
|
60
|
+
actionsDenylist: [
|
|
61
|
+
import_host_api.HostActionTypes.BUILDER_POINTER_MOVE,
|
|
62
|
+
import_actions.BuilderActionTypes.HANDLE_POINTER_MOVE,
|
|
63
|
+
import_actions.BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE
|
|
64
|
+
]
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
return store;
|
|
68
|
+
};
|
|
69
|
+
function configureProtoStore({
|
|
70
|
+
name,
|
|
71
|
+
breakpoints
|
|
72
|
+
}) {
|
|
73
|
+
return configureStore({
|
|
74
|
+
name,
|
|
75
|
+
preloadedState: {
|
|
76
|
+
breakpoints: Breakpoints.getInitialState(breakpoints)
|
|
77
|
+
},
|
|
78
|
+
enhancers: () => new import_toolkit.Tuple()
|
|
79
|
+
});
|
|
80
|
+
}
|
|
43
81
|
function conditionalReadWriteMiddleware(middlewareRef) {
|
|
44
82
|
let readWriteActionBuffer = [];
|
|
45
83
|
let middlewares = null;
|
|
@@ -76,18 +114,17 @@ function conditionalReadWriteMiddleware(middlewareRef) {
|
|
|
76
114
|
};
|
|
77
115
|
});
|
|
78
116
|
}
|
|
79
|
-
function
|
|
117
|
+
function withMixin(mixin) {
|
|
80
118
|
return (next) => (reducer, preloadedState) => ({
|
|
81
119
|
...next(reducer, preloadedState),
|
|
82
|
-
|
|
120
|
+
...mixin
|
|
83
121
|
});
|
|
84
122
|
}
|
|
85
|
-
function
|
|
123
|
+
function configureReadWriteStore({
|
|
86
124
|
name,
|
|
87
125
|
appOrigin,
|
|
88
126
|
hostApiClient,
|
|
89
|
-
preloadedState
|
|
90
|
-
breakpoints
|
|
127
|
+
preloadedState
|
|
91
128
|
}) {
|
|
92
129
|
const readWriteMiddlewareRef = {
|
|
93
130
|
current: null
|
|
@@ -126,59 +163,49 @@ function configureStore({
|
|
|
126
163
|
readWriteSetupPromise = null;
|
|
127
164
|
}
|
|
128
165
|
};
|
|
129
|
-
const store =
|
|
130
|
-
|
|
131
|
-
preloadedState
|
|
132
|
-
|
|
133
|
-
breakpoints: Breakpoints.getInitialState(breakpoints ?? preloadedState?.breakpoints)
|
|
134
|
-
},
|
|
135
|
-
middleware: (getDefaultMiddleware) => getDefaultMiddleware(import_toolkit2.middlewareOptions).concat([
|
|
136
|
-
(0, import_read_only_element_tree.readOnlyElementTreeMiddleware)(),
|
|
166
|
+
const store = configureStore({
|
|
167
|
+
name,
|
|
168
|
+
preloadedState,
|
|
169
|
+
middleware: () => [
|
|
137
170
|
(0, import_makeswift_api_client_sync.makeswiftApiClientSyncMiddleware)(hostApiClient),
|
|
138
171
|
conditionalReadWriteMiddleware(readWriteMiddlewareRef)
|
|
139
|
-
]
|
|
140
|
-
enhancers: (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
172
|
+
],
|
|
173
|
+
enhancers: () => new import_toolkit.Tuple(
|
|
174
|
+
withMixin({
|
|
175
|
+
hostApiClient,
|
|
176
|
+
loadReadWriteStateIfNeeded: async () => {
|
|
177
|
+
const { isReadOnly } = store.getState();
|
|
178
|
+
if (isReadOnly) {
|
|
179
|
+
if (refCount > 0) {
|
|
180
|
+
console.error("Read-write state mismatch", { isReadOnly, refCount });
|
|
181
|
+
}
|
|
182
|
+
return () => {
|
|
183
|
+
};
|
|
148
184
|
}
|
|
185
|
+
await loadReadWriteState();
|
|
186
|
+
refCount += 1;
|
|
187
|
+
let didCleanup = false;
|
|
149
188
|
return () => {
|
|
189
|
+
if (didCleanup) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
didCleanup = true;
|
|
193
|
+
refCount -= 1;
|
|
194
|
+
if (refCount === 0 && readWriteCleanup != null) {
|
|
195
|
+
readWriteCleanup();
|
|
196
|
+
readWriteCleanup = null;
|
|
197
|
+
}
|
|
150
198
|
};
|
|
151
199
|
}
|
|
152
|
-
await loadReadWriteState();
|
|
153
|
-
refCount += 1;
|
|
154
|
-
let didCleanup = false;
|
|
155
|
-
return () => {
|
|
156
|
-
if (didCleanup) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
didCleanup = true;
|
|
160
|
-
refCount -= 1;
|
|
161
|
-
if (refCount === 0 && readWriteCleanup != null) {
|
|
162
|
-
readWriteCleanup();
|
|
163
|
-
readWriteCleanup = null;
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
200
|
})
|
|
167
|
-
)
|
|
168
|
-
devTools: (0, import_toolkit2.devToolsConfig)({
|
|
169
|
-
name: `${name} (${(/* @__PURE__ */ new Date()).toISOString()})`,
|
|
170
|
-
actionsDenylist: [
|
|
171
|
-
import_host_api.HostActionTypes.BUILDER_POINTER_MOVE,
|
|
172
|
-
import_actions.BuilderActionTypes.HANDLE_POINTER_MOVE,
|
|
173
|
-
import_actions.BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE
|
|
174
|
-
]
|
|
175
|
-
})
|
|
201
|
+
)
|
|
176
202
|
});
|
|
177
203
|
return store;
|
|
178
204
|
}
|
|
179
205
|
// Annotate the CommonJS export names for ESM import in node:
|
|
180
206
|
0 && (module.exports = {
|
|
181
207
|
conditionalReadWriteMiddleware,
|
|
182
|
-
|
|
208
|
+
configureProtoStore,
|
|
209
|
+
configureReadWriteStore
|
|
183
210
|
});
|
|
184
211
|
//# sourceMappingURL=store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../api/client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\n\nimport { type Action } from './actions'\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\n\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\ninterface ReadWriteStateMixin {\n loadReadWriteState: ({ isReadOnly }: { isReadOnly: boolean }) => Promise<() => void>\n}\n\nfunction withReadWriteState(\n loadReadWriteState: ReadWriteStateMixin['loadReadWriteState'],\n): StoreEnhancer<ReadWriteStateMixin> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n loadReadWriteState,\n })\n}\n\nexport function configureStore({\n name,\n appOrigin,\n hostApiClient,\n preloadedState,\n breakpoints,\n}: {\n name: string\n appOrigin: string\n hostApiClient: MakeswiftHostApiClient\n preloadedState: Partial<State> | null\n breakpoints?: Breakpoints.State\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n\n preloadedState: {\n ...preloadedState,\n breakpoints: Breakpoints.getInitialState(breakpoints ?? preloadedState?.breakpoints),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n makeswiftApiClientSyncMiddleware(hostApiClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ]),\n\n enhancers: getDefaultEnhancers =>\n getDefaultEnhancers().concat(\n withReadWriteState(async ({ isReadOnly }) => {\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', {\n isReadOnly,\n refCount,\n })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n }),\n ),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,q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AoB,EAAE;AAAA,MACpB,mBAAmB,OAAO,EAAE,WAAW,MAAM;AAC3C,YAAI,YAAY;AACd,cAAI,WAAW,GAAG;AAChB,oBAAQ,MAAM,6BAA6B;AAAA,cACzC;AAAA,cACA;AAAA,YACF,CAAC;AAAA,UACH;AAEA,iBAAO,MAAM;AAAA,UAAC;AAAA,QAChB;AAEA,cAAM,mBAAmB;AACzB,oBAAY;AAEZ,YAAI,aAAa;AACjB,eAAO,MAAM;AACX,cAAI,YAAY;AACd;AAAA,UACF;AAEA,uBAAa;AACb,sBAAY;AACZ,cAAI,aAAa,KAAK,oBAAoB,MAAM;AAC9C,6BAAiB;AACjB,+BAAmB;AAAA,UACrB;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEF,cAAU,gCAAe;AAAA,MACvB,MAAM,GAAG,IAAI,MAAK,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MAC1C,iBAAiB;AAAA,QACf,gCAAgB;AAAA,QAChB,kCAAmB;AAAA,QACnB,kCAAmB;AAAA,MACrB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;","names":["import_toolkit","configureReduxStore"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n Tuple,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../api/client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\n\nimport { type Action } from './actions'\n\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\n\nexport { type State } from './unified-state'\n\nconst configureStore = <Items extends readonly StoreEnhancer[] = []>({\n name,\n preloadedState,\n enhancers,\n middleware,\n}: {\n name: string\n preloadedState: Partial<State>\n enhancers: () => Tuple<Items>\n middleware?: () => Middleware[]\n}) => {\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n ...(middleware ? middleware() : []),\n ]),\n\n enhancers: getDefaultEnhancers => getDefaultEnhancers().concat(enhancers()),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport function configureProtoStore({\n name,\n breakpoints,\n}: {\n name: string\n breakpoints: Breakpoints.State | undefined\n}) {\n return configureStore({\n name,\n preloadedState: {\n breakpoints: Breakpoints.getInitialState(breakpoints),\n },\n enhancers: () => new Tuple(),\n })\n}\n\nexport type ProtoStore = ReturnType<typeof configureProtoStore>\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\nexport interface ReadWriteStateMixin {\n readonly hostApiClient: MakeswiftHostApiClient\n\n loadReadWriteStateIfNeeded(): Promise<() => void>\n}\n\nfunction withMixin<M extends {}>(mixin: M): StoreEnhancer<M> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n ...mixin,\n })\n}\n\nexport function configureReadWriteStore({\n name,\n appOrigin,\n hostApiClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n hostApiClient: MakeswiftHostApiClient\n preloadedState: Partial<State>\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureStore({\n name,\n preloadedState,\n\n middleware: () => [\n makeswiftApiClientSyncMiddleware(hostApiClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ],\n\n enhancers: () =>\n new Tuple(\n withMixin<ReadWriteStateMixin>({\n hostApiClient,\n loadReadWriteStateIfNeeded: async () => {\n const { isReadOnly } = store.getState()\n\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', { isReadOnly, refCount })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n },\n }),\n ),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureReadWriteStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAQO;AAIP,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"sources":["../../../src/unstable-framework-support/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n serializeSiteVersion,\n deserializeSiteVersion,\n secondsUntilSiteVersionExpiration,\n} from '../api/site-version'\n\nexport {\n type ApiHandlerUserConfig,\n createApiHandler,\n type SitePublishedWebhookPayloadData,\n} from '../api-handler'\nexport { SET_COOKIE_HEADER, cookieSettingOptions } from '../api-handler/cookies'\nexport { REDIRECT_SEARCH_PARAM, redirectLiveHandler } from '../api-handler/handlers/redirect-live'\nexport { toApiRequest, pipeResponseTo } from '../api-handler/node-request-response'\nexport { MAKESWIFT_SITE_VERSION_COOKIE, SearchParams } from '../api-handler/preview'\n\nexport { MakeswiftClient } from '../client'\n\nexport { type BreakpointsInput as Breakpoints } from '../state/modules/breakpoints'\n\nexport {\n FrameworkContext,\n DefaultHead,\n DefaultHeadSnippet,\n DefaultImage,\n} from '../runtimes/react/components/framework-context'\n\nexport { MakeswiftComponent } from '../runtimes/react/components/MakeswiftComponent'\nexport { Page } from '../runtimes/react/components/page'\nexport { RuntimeProvider } from '../runtimes/react/components/RuntimeProvider'\nexport { Slot } from '../runtimes/react/components/Slot'\n\nexport { GoogleFontLink } from '../runtimes/react/components/GoogleFontLink'\nexport { MakeswiftFonts } from '../runtimes/react/components/MakeswiftFonts'\n\nexport {\n createRootStyleCache,\n RootStyleRegistry,\n styleTagHtml,\n StyleTagSSR,\n type RootStyleProps,\n} from '../runtimes/react/root-style-registry'\n\nexport { ReactRuntime } from '../runtimes/react/react-runtime'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAKO;AAEP,yBAIO;AACP,qBAAwD;AACxD,2BAA2D;AAC3D,mCAA6C;AAC7C,qBAA4D;AAE5D,oBAAgC;AAIhC,+BAKO;AAEP,gCAAmC;AACnC,kBAAqB;AACrB,6BAAgC;AAChC,kBAAqB;AAErB,4BAA+B;AAC/B,4BAA+B;AAE/B,iCAMO;AAEP,
|
|
1
|
+
{"version":3,"sources":["../../../src/unstable-framework-support/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n serializeSiteVersion,\n deserializeSiteVersion,\n secondsUntilSiteVersionExpiration,\n} from '../api/site-version'\n\nexport {\n type ApiHandlerUserConfig,\n createApiHandler,\n type SitePublishedWebhookPayloadData,\n} from '../api-handler'\nexport { SET_COOKIE_HEADER, cookieSettingOptions } from '../api-handler/cookies'\nexport { REDIRECT_SEARCH_PARAM, redirectLiveHandler } from '../api-handler/handlers/redirect-live'\nexport { toApiRequest, pipeResponseTo } from '../api-handler/node-request-response'\nexport { MAKESWIFT_SITE_VERSION_COOKIE, SearchParams } from '../api-handler/preview'\n\nexport { MakeswiftClient } from '../client'\n\nexport { type BreakpointsInput as Breakpoints } from '../state/modules/breakpoints'\n\nexport {\n FrameworkContext,\n DefaultHead,\n DefaultHeadSnippet,\n DefaultImage,\n} from '../runtimes/react/components/framework-context'\n\nexport { MakeswiftComponent } from '../runtimes/react/components/MakeswiftComponent'\nexport { Page } from '../runtimes/react/components/page'\nexport { RuntimeProvider } from '../runtimes/react/components/RuntimeProvider'\nexport { Slot } from '../runtimes/react/components/Slot'\n\nexport { GoogleFontLink } from '../runtimes/react/components/GoogleFontLink'\nexport { MakeswiftFonts } from '../runtimes/react/components/MakeswiftFonts'\n\nexport {\n createRootStyleCache,\n RootStyleRegistry,\n styleTagHtml,\n StyleTagSSR,\n type RootStyleProps,\n} from '../runtimes/react/root-style-registry'\n\nexport { ReactRuntime, type StoreKey } from '../runtimes/react/react-runtime'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAKO;AAEP,yBAIO;AACP,qBAAwD;AACxD,2BAA2D;AAC3D,mCAA6C;AAC7C,qBAA4D;AAE5D,oBAAgC;AAIhC,+BAKO;AAEP,gCAAmC;AACnC,kBAAqB;AACrB,6BAAgC;AAChC,kBAAqB;AAErB,4BAA+B;AAC/B,4BAA+B;AAE/B,iCAMO;AAEP,2BAA4C;","names":[]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var ref_counted_map_exports = {};
|
|
20
|
+
__export(ref_counted_map_exports, {
|
|
21
|
+
RefCountedMap: () => RefCountedMap
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ref_counted_map_exports);
|
|
24
|
+
const TTLCheck = {
|
|
25
|
+
ON_GET: 1 << 0,
|
|
26
|
+
ON_RETAIN: 1 << 1,
|
|
27
|
+
ON_RELEASE: 1 << 2
|
|
28
|
+
};
|
|
29
|
+
class RefCountedMap {
|
|
30
|
+
map = /* @__PURE__ */ new Map();
|
|
31
|
+
unownedEntryTtlMs;
|
|
32
|
+
ttlCheck;
|
|
33
|
+
static TTLCheck = TTLCheck;
|
|
34
|
+
constructor({
|
|
35
|
+
unownedEntryTtlMs,
|
|
36
|
+
ttlCheck = TTLCheck.ON_GET | TTLCheck.ON_RETAIN | TTLCheck.ON_RELEASE
|
|
37
|
+
}) {
|
|
38
|
+
this.unownedEntryTtlMs = unownedEntryTtlMs;
|
|
39
|
+
this.ttlCheck = ttlCheck;
|
|
40
|
+
}
|
|
41
|
+
get size() {
|
|
42
|
+
return this.map.size;
|
|
43
|
+
}
|
|
44
|
+
get(key) {
|
|
45
|
+
return this.map.get(key)?.value;
|
|
46
|
+
}
|
|
47
|
+
getOrCreate(key, init) {
|
|
48
|
+
try {
|
|
49
|
+
const existing = this.map.get(key);
|
|
50
|
+
if (existing) {
|
|
51
|
+
if (isUnowned(existing))
|
|
52
|
+
existing.accessedAt = Date.now();
|
|
53
|
+
return existing.value;
|
|
54
|
+
}
|
|
55
|
+
const value = init();
|
|
56
|
+
this.map.set(key, { value, count: void 0, accessedAt: Date.now() });
|
|
57
|
+
return value;
|
|
58
|
+
} finally {
|
|
59
|
+
if (this.ttlCheck & TTLCheck.ON_GET)
|
|
60
|
+
this.removeExpired();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
retain(key, value) {
|
|
64
|
+
try {
|
|
65
|
+
const existing = this.map.get(key);
|
|
66
|
+
if (existing != null) {
|
|
67
|
+
if (existing.value !== value)
|
|
68
|
+
return;
|
|
69
|
+
existing.count = (existing.count ?? 0) + 1;
|
|
70
|
+
} else {
|
|
71
|
+
this.map.set(key, { value, count: 1 });
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
if (this.ttlCheck & TTLCheck.ON_RETAIN)
|
|
75
|
+
this.removeExpired();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
release(key, value) {
|
|
79
|
+
try {
|
|
80
|
+
const existing = this.map.get(key);
|
|
81
|
+
if (existing == null)
|
|
82
|
+
return;
|
|
83
|
+
if (isUnowned(existing))
|
|
84
|
+
return;
|
|
85
|
+
if (existing.value !== value)
|
|
86
|
+
return;
|
|
87
|
+
if (existing.count > 1) {
|
|
88
|
+
existing.count -= 1;
|
|
89
|
+
} else {
|
|
90
|
+
this.map.delete(key);
|
|
91
|
+
}
|
|
92
|
+
} finally {
|
|
93
|
+
if (this.ttlCheck & TTLCheck.ON_RELEASE)
|
|
94
|
+
this.removeExpired();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
removeExpired() {
|
|
98
|
+
const now = Date.now();
|
|
99
|
+
const isExpired = (entry) => isUnowned(entry) && now - entry.accessedAt > this.unownedEntryTtlMs;
|
|
100
|
+
this.map.forEach((entry, key) => {
|
|
101
|
+
if (isExpired(entry))
|
|
102
|
+
this.map.delete(key);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const isUnowned = (entry) => entry.count === void 0;
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
RefCountedMap
|
|
110
|
+
});
|
|
111
|
+
//# sourceMappingURL=ref-counted-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/ref-counted-map.ts"],"sourcesContent":["type RefCountedMapEntry<V> = {\n value: V\n count: number\n}\n\ntype UnownedMapEntry<V> = {\n value: V\n count: undefined\n accessedAt: number\n}\n\ntype MapEntry<V> = RefCountedMapEntry<V> | UnownedMapEntry<V>\n\nconst TTLCheck = {\n ON_GET: 1 << 0,\n ON_RETAIN: 1 << 1,\n ON_RELEASE: 1 << 2,\n} as const\n\n/**\n * Ref-counted map with explicit retention semantics. Entries are unowned by default and may be evicted after their\n * TTL unless explicitly retained. This provides TTL-based caching for unowned entries, while allowing consumers to\n * opt into stronger lifetime control via explicit retention.\n */\nexport class RefCountedMap<K, V> {\n private readonly map = new Map<K, MapEntry<V>>()\n private readonly unownedEntryTtlMs: number\n private readonly ttlCheck: number\n\n static readonly TTLCheck = TTLCheck\n\n constructor({\n unownedEntryTtlMs,\n ttlCheck = TTLCheck.ON_GET | TTLCheck.ON_RETAIN | TTLCheck.ON_RELEASE,\n }: {\n unownedEntryTtlMs: number\n ttlCheck?: number\n }) {\n this.unownedEntryTtlMs = unownedEntryTtlMs\n this.ttlCheck = ttlCheck\n }\n\n get size(): number {\n return this.map.size\n }\n\n get(key: K): V | undefined {\n return this.map.get(key)?.value\n }\n\n getOrCreate(key: K, init: () => V): V {\n try {\n const existing = this.map.get(key)\n\n if (existing) {\n if (isUnowned(existing)) existing.accessedAt = Date.now()\n return existing.value\n }\n\n const value = init()\n this.map.set(key, { value, count: undefined, accessedAt: Date.now() })\n return value\n } finally {\n if (this.ttlCheck & TTLCheck.ON_GET) this.removeExpired()\n }\n }\n\n retain(key: K, value: V): void {\n try {\n const existing = this.map.get(key)\n\n // `retain` might be called on a unowned entry that has already been evicted from the map due to TTL expiration\n // *and* possibly replaced by a new unowned entry with the same key; handle this gracefully\n if (existing != null) {\n if (existing.value !== value) return\n existing.count = (existing.count ?? 0) + 1\n } else {\n this.map.set(key, { value, count: 1 })\n }\n } finally {\n if (this.ttlCheck & TTLCheck.ON_RETAIN) this.removeExpired()\n }\n }\n\n release(key: K, value: V): void {\n try {\n const existing = this.map.get(key)\n\n // `release` might be called on an entry that remained unowned due being superseded by a new entry with the same\n // key after TTL expiration of the original entry; handle this gracefully\n if (existing == null) return\n if (isUnowned(existing)) return\n if (existing.value !== value) return\n\n if (existing.count > 1) {\n existing.count -= 1\n } else {\n this.map.delete(key)\n }\n } finally {\n if (this.ttlCheck & TTLCheck.ON_RELEASE) this.removeExpired()\n }\n }\n\n private removeExpired(): void {\n const now = Date.now()\n const isExpired = (entry: MapEntry<V>): boolean =>\n isUnowned(entry) && now - entry.accessedAt > this.unownedEntryTtlMs\n\n this.map.forEach((entry, key) => {\n if (isExpired(entry)) this.map.delete(key)\n })\n }\n}\n\nconst isUnowned = <V>(entry: MapEntry<V>): entry is UnownedMapEntry<V> => entry.count === undefined\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,MAAM,WAAW;AAAA,EACf,QAAQ,KAAK;AAAA,EACb,WAAW,KAAK;AAAA,EAChB,YAAY,KAAK;AACnB;AAOO,MAAM,cAAoB;AAAA,EACd,MAAM,oBAAI,IAAoB;AAAA,EAC9B;AAAA,EACA;AAAA,EAEjB,OAAgB,WAAW;AAAA,EAE3B,YAAY;AAAA,IACV;AAAA,IACA,WAAW,SAAS,SAAS,SAAS,YAAY,SAAS;AAAA,EAC7D,GAGG;AACD,SAAK,oBAAoB;AACzB,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK,IAAI;AAAA,EAClB;AAAA,EAEA,IAAI,KAAuB;AACzB,WAAO,KAAK,IAAI,IAAI,GAAG,GAAG;AAAA,EAC5B;AAAA,EAEA,YAAY,KAAQ,MAAkB;AACpC,QAAI;AACF,YAAM,WAAW,KAAK,IAAI,IAAI,GAAG;AAEjC,UAAI,UAAU;AACZ,YAAI,UAAU,QAAQ;AAAG,mBAAS,aAAa,KAAK,IAAI;AACxD,eAAO,SAAS;AAAA,MAClB;AAEA,YAAM,QAAQ,KAAK;AACnB,WAAK,IAAI,IAAI,KAAK,EAAE,OAAO,OAAO,QAAW,YAAY,KAAK,IAAI,EAAE,CAAC;AACrE,aAAO;AAAA,IACT,UAAE;AACA,UAAI,KAAK,WAAW,SAAS;AAAQ,aAAK,cAAc;AAAA,IAC1D;AAAA,EACF;AAAA,EAEA,OAAO,KAAQ,OAAgB;AAC7B,QAAI;AACF,YAAM,WAAW,KAAK,IAAI,IAAI,GAAG;AAIjC,UAAI,YAAY,MAAM;AACpB,YAAI,SAAS,UAAU;AAAO;AAC9B,iBAAS,SAAS,SAAS,SAAS,KAAK;AAAA,MAC3C,OAAO;AACL,aAAK,IAAI,IAAI,KAAK,EAAE,OAAO,OAAO,EAAE,CAAC;AAAA,MACvC;AAAA,IACF,UAAE;AACA,UAAI,KAAK,WAAW,SAAS;AAAW,aAAK,cAAc;AAAA,IAC7D;AAAA,EACF;AAAA,EAEA,QAAQ,KAAQ,OAAgB;AAC9B,QAAI;AACF,YAAM,WAAW,KAAK,IAAI,IAAI,GAAG;AAIjC,UAAI,YAAY;AAAM;AACtB,UAAI,UAAU,QAAQ;AAAG;AACzB,UAAI,SAAS,UAAU;AAAO;AAE9B,UAAI,SAAS,QAAQ,GAAG;AACtB,iBAAS,SAAS;AAAA,MACpB,OAAO;AACL,aAAK,IAAI,OAAO,GAAG;AAAA,MACrB;AAAA,IACF,UAAE;AACA,UAAI,KAAK,WAAW,SAAS;AAAY,aAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AAAA,EAEQ,gBAAsB;AAC5B,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,YAAY,CAAC,UACjB,UAAU,KAAK,KAAK,MAAM,MAAM,aAAa,KAAK;AAEpD,SAAK,IAAI,QAAQ,CAAC,OAAO,QAAQ;AAC/B,UAAI,UAAU,KAAK;AAAG,aAAK,IAAI,OAAO,GAAG;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;AAEA,MAAM,YAAY,CAAI,UAAoD,MAAM,UAAU;","names":[]}
|
package/dist/esm/api/client.js
CHANGED
|
@@ -20,12 +20,10 @@ class MakeswiftHostApiClient {
|
|
|
20
20
|
constructor({
|
|
21
21
|
uri,
|
|
22
22
|
fetch,
|
|
23
|
-
|
|
23
|
+
preloadedState
|
|
24
24
|
}) {
|
|
25
25
|
this.graphqlClient = new GraphQLClient(uri);
|
|
26
|
-
this.makeswiftApiClient = MakeswiftApiClient.configureStore({
|
|
27
|
-
serializedState: cacheData
|
|
28
|
-
});
|
|
26
|
+
this.makeswiftApiClient = MakeswiftApiClient.configureStore({ preloadedState });
|
|
29
27
|
this.fetch = fetch;
|
|
30
28
|
this.subscribe = this.makeswiftApiClient.subscribe;
|
|
31
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\n\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class MakeswiftHostApiClient {\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n fetch: MakeswiftApiClient.HttpFetch\n\n constructor({\n uri,\n fetch,\n cacheData,\n }: {\n uri: string\n fetch: MakeswiftApiClient.HttpFetch\n cacheData?: CacheData\n }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({\n serializedState: cacheData,\n })\n this.fetch = fetch\n this.subscribe = this.makeswiftApiClient.subscribe\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch),\n )\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.fetch),\n )\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch),\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.GlobalElement,\n globalElementId,\n this.fetch,\n ),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n this.fetch,\n locale,\n ),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.PagePathnameSlice,\n pageId,\n this.fetch,\n locale,\n ),\n )\n }\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.fetch),\n )\n }\n\n async createTableRecord(tableId: string, columns: any): Promise<void> {\n await this.graphqlClient.request<\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables\n >(CreateTableRecordMutation, { input: { data: { tableId, columns } } })\n }\n\n readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n}\n"],"mappings":"AAEA,YAAY,wBAAwB;AAEpC;AAAA,EACE;AAAA,OAWK;AACP,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAQnC,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc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BAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,SAAwC;AACvD,WAAO,MAAM,KAAK,mBAAmB;AAAA,MACnC,mBAAmB,iBAAiB,gBAAgB,OAAO,SAAS,KAAK,KAAK;AAAA,IAChF;AAAA,EACF;AAAA,EAEA,MAAM,kBAAkB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,2BAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\n\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class MakeswiftHostApiClient {\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n fetch: MakeswiftApiClient.HttpFetch\n\n constructor({\n uri,\n fetch,\n preloadedState,\n }: {\n uri: string\n fetch: MakeswiftApiClient.HttpFetch\n preloadedState: Partial<MakeswiftApiClient.State>\n }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({ preloadedState })\n this.fetch = fetch\n this.subscribe = this.makeswiftApiClient.subscribe\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch),\n )\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.fetch),\n )\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch),\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.GlobalElement,\n globalElementId,\n this.fetch,\n ),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n this.fetch,\n locale,\n ),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.PagePathnameSlice,\n pageId,\n this.fetch,\n locale,\n ),\n )\n }\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.fetch),\n )\n }\n\n async createTableRecord(tableId: string, columns: any): Promise<void> {\n await this.graphqlClient.request<\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables\n >(CreateTableRecordMutation, { input: { data: { tableId, columns } } })\n }\n\n readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n}\n"],"mappings":"AAEA,YAAY,wBAAwB;AAEpC;AAAA,EACE;AAAA,OAWK;AACP,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAQnC,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAqBO,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,SAAK,gBAAgB,IAAI,cAAc,GAAG;AAC1C,SAAK,qBAAqB,mBAAmB,eAAe,EAAE,eAAe,CAAC;AAC9E,SAAK,QAAQ;AACb,SAAK,YAAY,KAAK,mBAAmB;AAAA,EAC3C;AAAA,EAEA,WAAW,UAAiC;AAC1C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,YAAY,UAA0C;AAC1D,WAAO,MAAM,KAAK,mBAAmB;AAAA,MACnC,mBAAmB,iBAAiB,gBAAgB,QA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ChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -8,7 +8,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
8
8
|
return ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
9
9
|
}
|
|
10
10
|
return ApiResponse.json({
|
|
11
|
-
version: "0.28.3-canary.
|
|
11
|
+
version: "0.28.3-canary.6",
|
|
12
12
|
interactionMode: true,
|
|
13
13
|
clientSideNavigation: false,
|
|
14
14
|
elementFromPoint: false,
|
package/dist/esm/client/index.js
CHANGED
|
@@ -176,10 +176,12 @@ const getPageAPISchema = z.object({
|
|
|
176
176
|
)
|
|
177
177
|
});
|
|
178
178
|
const getFontsAPISchema = z.object({
|
|
179
|
-
googleFonts: z.array(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
googleFonts: z.array(
|
|
180
|
+
z.object({
|
|
181
|
+
family: z.string(),
|
|
182
|
+
variants: z.array(z.string())
|
|
183
|
+
})
|
|
184
|
+
),
|
|
183
185
|
siteId: z.string()
|
|
184
186
|
});
|
|
185
187
|
class MakeswiftClient {
|
|
@@ -195,7 +197,7 @@ Received "${apiKey}" instead.`
|
|
|
195
197
|
}
|
|
196
198
|
this.apiKey = apiKey;
|
|
197
199
|
this.graphqlClient = new GraphQLClient(new URL("graphql", runtime.apiOrigin).href, {
|
|
198
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
200
|
+
"makeswift-runtime-version": "0.28.3-canary.6"
|
|
199
201
|
});
|
|
200
202
|
this.runtime = runtime;
|
|
201
203
|
}
|
|
@@ -207,7 +209,7 @@ Received "${apiKey}" instead.`
|
|
|
207
209
|
const requestHeaders = new Headers({
|
|
208
210
|
"x-api-key": this.apiKey,
|
|
209
211
|
"makeswift-site-api-key": this.apiKey,
|
|
210
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
212
|
+
"makeswift-runtime-version": "0.28.3-canary.6"
|
|
211
213
|
});
|
|
212
214
|
if (siteVersion?.token) {
|
|
213
215
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -313,8 +315,7 @@ Received "${apiKey}" instead.`
|
|
|
313
315
|
return { ...result, swatches };
|
|
314
316
|
}
|
|
315
317
|
async introspect(element, siteVersion, locale) {
|
|
316
|
-
const
|
|
317
|
-
const descriptors = getPropControllerDescriptors(runtime.store.getState());
|
|
318
|
+
const descriptors = this.getElementDescriptors();
|
|
318
319
|
const swatchIds = /* @__PURE__ */ new Set();
|
|
319
320
|
const fileIds = /* @__PURE__ */ new Set();
|
|
320
321
|
const typographyIds = /* @__PURE__ */ new Set();
|
|
@@ -362,6 +363,8 @@ Received "${apiKey}" instead.`
|
|
|
362
363
|
elementData = localizedGlobalElement.data;
|
|
363
364
|
localizedResourcesMap.set(globalElementId, localizedGlobalElement.id);
|
|
364
365
|
localizedGlobalElements.set(localizedGlobalElement.id, localizedGlobalElement);
|
|
366
|
+
} else {
|
|
367
|
+
localizedResourcesMap.set(globalElementId, null);
|
|
365
368
|
}
|
|
366
369
|
}
|
|
367
370
|
globalElements.set(globalElementId, globalElement);
|
|
@@ -647,17 +650,10 @@ Received "${apiKey}" instead.`
|
|
|
647
650
|
return result.table;
|
|
648
651
|
}
|
|
649
652
|
getTranslatableData(elementTree) {
|
|
650
|
-
return getTranslatableContent(
|
|
651
|
-
getPropControllerDescriptors(this.runtime.store.getState()),
|
|
652
|
-
elementTree
|
|
653
|
-
);
|
|
653
|
+
return getTranslatableContent(this.getElementDescriptors(), elementTree);
|
|
654
654
|
}
|
|
655
655
|
mergeTranslatedData(elementTree, translatedData) {
|
|
656
|
-
return mergeTranslatedContent(
|
|
657
|
-
getPropControllerDescriptors(this.runtime.store.getState()),
|
|
658
|
-
elementTree,
|
|
659
|
-
translatedData
|
|
660
|
-
);
|
|
656
|
+
return mergeTranslatedContent(this.getElementDescriptors(), elementTree, translatedData);
|
|
661
657
|
}
|
|
662
658
|
async readPreviewToken(token) {
|
|
663
659
|
const response = await fetch(new URL("v1/preview-tokens/reads", this.apiOrigin).toString(), {
|
|
@@ -665,7 +661,7 @@ Received "${apiKey}" instead.`
|
|
|
665
661
|
headers: {
|
|
666
662
|
"x-api-key": this.apiKey,
|
|
667
663
|
"makeswift-site-api-key": this.apiKey,
|
|
668
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
664
|
+
"makeswift-runtime-version": "0.28.3-canary.6",
|
|
669
665
|
"content-type": "application/json"
|
|
670
666
|
},
|
|
671
667
|
body: JSON.stringify({ token }),
|
|
@@ -713,6 +709,9 @@ Received "${apiKey}" instead.`
|
|
|
713
709
|
}
|
|
714
710
|
return parsed.data;
|
|
715
711
|
}
|
|
712
|
+
getElementDescriptors() {
|
|
713
|
+
return getPropControllerDescriptors(this.runtime.protoStore.getState());
|
|
714
|
+
}
|
|
716
715
|
}
|
|
717
716
|
export {
|
|
718
717
|
MakeswiftClient,
|