@makeswift/runtime 0.28.7-canary.1 → 0.28.7-canary.3
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/api-resources-client.js +160 -0
- package/dist/cjs/api/api-resources-client.js.map +1 -0
- package/dist/cjs/api/client.js +20 -182
- 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 +3 -3
- package/dist/cjs/controls/index.js +2 -2
- package/dist/cjs/controls/index.js.map +1 -1
- package/dist/cjs/next/api-handler/config/pages-router.js +1 -1
- package/dist/cjs/next/api-handler/config/pages-router.js.map +1 -1
- package/dist/cjs/next/fetch.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js +1 -1
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +11 -32
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/cjs/runtimes/react/resource-resolver.js +52 -0
- package/dist/cjs/runtimes/react/resource-resolver.js.map +1 -0
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/slate/InlinePlugin/index.js +1 -1
- package/dist/cjs/slate/InlinePlugin/index.js.map +1 -1
- package/dist/cjs/slate/InlinePlugin/types.js +3 -3
- package/dist/cjs/slate/InlinePlugin/types.js.map +1 -1
- package/dist/cjs/slate/TextAlignPlugin/index.js +5 -5
- package/dist/cjs/slate/TextAlignPlugin/index.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-write-actions.js.map +1 -1
- package/dist/cjs/state/api-client/client-store.js +81 -0
- package/dist/cjs/state/api-client/client-store.js.map +1 -0
- package/dist/cjs/state/{makeswift-api-client.js → api-client/fetch-api-resource.js} +15 -101
- package/dist/cjs/state/api-client/fetch-api-resource.js.map +1 -0
- package/dist/cjs/state/api-client/state.js +89 -0
- package/dist/cjs/state/api-client/state.js.map +1 -0
- package/dist/cjs/state/api-client/store.js +36 -0
- package/dist/cjs/state/api-client/store.js.map +1 -0
- package/dist/cjs/state/middleware/makeswift-api-client-sync.js +1 -1
- package/dist/cjs/state/middleware/makeswift-api-client-sync.js.map +1 -1
- package/dist/esm/api/api-resources-client.js +127 -0
- package/dist/esm/api/api-resources-client.js.map +1 -0
- package/dist/esm/api/client.js +19 -171
- 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 +3 -3
- package/dist/esm/controls/index.js +2 -2
- package/dist/esm/controls/index.js.map +1 -1
- package/dist/esm/next/api-handler/config/pages-router.js +1 -1
- package/dist/esm/next/api-handler/config/pages-router.js.map +1 -1
- package/dist/esm/next/fetch.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-cache-data.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +11 -22
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/esm/runtimes/react/resource-resolver.js +28 -0
- package/dist/esm/runtimes/react/resource-resolver.js.map +1 -0
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/slate/InlinePlugin/index.js +2 -2
- package/dist/esm/slate/InlinePlugin/index.js.map +1 -1
- package/dist/esm/slate/InlinePlugin/types.js +4 -4
- package/dist/esm/slate/InlinePlugin/types.js.map +1 -1
- package/dist/esm/slate/TextAlignPlugin/index.js +6 -6
- package/dist/esm/slate/TextAlignPlugin/index.js.map +1 -1
- package/dist/esm/state/actions/internal/read-write-actions.js.map +1 -1
- package/dist/esm/state/api-client/client-store.js +49 -0
- package/dist/esm/state/api-client/client-store.js.map +1 -0
- package/dist/esm/state/api-client/fetch-api-resource.js +93 -0
- package/dist/esm/state/api-client/fetch-api-resource.js.map +1 -0
- package/dist/esm/state/api-client/state.js +52 -0
- package/dist/esm/state/api-client/state.js.map +1 -0
- package/dist/esm/state/api-client/store.js +12 -0
- package/dist/esm/state/api-client/store.js.map +1 -0
- package/dist/esm/state/middleware/makeswift-api-client-sync.js +1 -1
- package/dist/esm/state/middleware/makeswift-api-client-sync.js.map +1 -1
- package/dist/types/api/api-resources-client.d.ts +57 -0
- package/dist/types/api/api-resources-client.d.ts.map +1 -0
- package/dist/types/api/client.d.ts +10 -42
- package/dist/types/api/client.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +9 -9
- package/dist/types/controls/index.d.ts +1 -1
- package/dist/types/controls/index.d.ts.map +1 -1
- package/dist/types/next/fetch.d.ts +1 -1
- package/dist/types/next/fetch.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts.map +1 -1
- package/dist/types/runtimes/react/resource-resolver.d.ts +10 -0
- package/dist/types/runtimes/react/resource-resolver.d.ts.map +1 -0
- package/dist/types/runtimes/react/runtime-core.d.ts +3 -3
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/slate/InlinePlugin/types.d.ts +3 -3
- package/dist/types/slate/InlinePlugin/types.d.ts.map +1 -1
- package/dist/types/slate/TextAlignPlugin/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-write-actions.d.ts +1 -1
- package/dist/types/state/actions/internal/read-write-actions.d.ts.map +1 -1
- package/dist/types/state/api-client/client-store.d.ts +6 -0
- package/dist/types/state/api-client/client-store.d.ts.map +1 -0
- package/dist/types/state/api-client/fetch-api-resource.d.ts +11 -0
- package/dist/types/state/api-client/fetch-api-resource.d.ts.map +1 -0
- package/dist/types/state/api-client/state.d.ts +30 -0
- package/dist/types/state/api-client/state.d.ts.map +1 -0
- package/dist/types/state/api-client/store.d.ts +18 -0
- package/dist/types/state/api-client/store.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/cjs/state/makeswift-api-client.js.map +0 -1
- package/dist/esm/state/makeswift-api-client.js +0 -179
- package/dist/esm/state/makeswift-api-client.js.map +0 -1
- package/dist/types/state/makeswift-api-client.d.ts +0 -51
- package/dist/types/state/makeswift-api-client.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/config/pages-router.ts"],"sourcesContent":["import { P } from 'ts-pattern'\nimport { NextApiRequest, NextApiResponse } from 'next'\n\nimport { type ApiResponse } from '../../../api-handler/request-response'\nimport { toApiRequest, pipeResponseTo } from '../../../api-handler/node-request-response'\n\nimport { pagesRouterRedirectPreviewHandler } from '../handlers/pages-router-redirect-preview'\nimport { PRERENDER_BYPASS_COOKIE, PREVIEW_DATA_COOKIE } from '../preview'\n\nimport { validateApiRoute, type ApiHandlerConfig } from './base'\nimport { MakeswiftClient } from '../../../client'\n\nexport type ApiHandlerArgs = [NextApiRequest, NextApiResponse]\nexport const argsPattern = [P.any, P.any] as const\n\nexport async function config({\n req,\n res,\n client,\n}: {\n req: NextApiRequest\n res: NextApiResponse\n client: MakeswiftClient\n}): Promise<ApiHandlerConfig> {\n return {\n req: toApiRequest(req),\n route: validateApiRoute(await apiRequestParams(req)),\n previewCookieNames: [PRERENDER_BYPASS_COOKIE, PREVIEW_DATA_COOKIE],\n\n sendResponse: (apiResponse: ApiResponse): Promise<Response | void> =>\n pipeResponseTo(apiResponse, res),\n\n revalidationHandler: async (path?: string): Promise<void> => {\n if (path != null) {\n res.revalidate(path)\n } else {\n // No-op, Pages Router does not support tag-based revalidation\n }\n },\n\n customRoutes: async (route: string) => {\n if (route === '/redirect-preview') {\n return { res: await pagesRouterRedirectPreviewHandler(req, res, client) }\n }\n\n return null\n },\n }\n}\n\nfunction apiRequestParams(request: NextApiRequest): Promise<NextApiRequest['query']> {\n // `NextApiRequest.query` prop became async in Next.js 15, but it's not reflected in the type definition;\n // force-casting it to a `Promise` manually\n return Promise.resolve(request.query)\n}\n"],"mappings":"AAAA,SAAS,SAAS;AAIlB,SAAS,cAAc,sBAAsB;AAE7C,SAAS,yCAAyC;AAClD,SAAS,yBAAyB,2BAA2B;AAE7D,SAAS,wBAA+C;AAIjD,MAAM,cAAc,CAAC,EAAE,KAAK,EAAE,GAAG;AAExC,eAAsB,OAAO;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,GAI8B;AAC5B,SAAO;AAAA,IACL,KAAK,aAAa,GAAG;AAAA,IACrB,OAAO,iBAAiB,MAAM,iBAAiB,GAAG,CAAC;AAAA,IACnD,oBAAoB,CAAC,yBAAyB,mBAAmB;AAAA,IAEjE,cAAc,CAAC,gBACb,eAAe,aAAa,GAAG;AAAA,IAEjC,qBAAqB,OAAO,SAAiC;AAC3D,UAAI,QAAQ,MAAM;AAChB,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/config/pages-router.ts"],"sourcesContent":["import { P } from 'ts-pattern'\nimport { NextApiRequest, NextApiResponse } from 'next'\n\nimport { type ApiResponse } from '../../../api-handler/request-response'\nimport { toApiRequest, pipeResponseTo } from '../../../api-handler/node-request-response'\n\nimport { pagesRouterRedirectPreviewHandler } from '../handlers/pages-router-redirect-preview'\nimport { PRERENDER_BYPASS_COOKIE, PREVIEW_DATA_COOKIE } from '../preview'\n\nimport { validateApiRoute, type ApiHandlerConfig } from './base'\nimport { MakeswiftClient } from '../../../client'\n\nexport type ApiHandlerArgs = [NextApiRequest, NextApiResponse]\nexport const argsPattern = [P.any, P.any] as const\n\nexport async function config({\n req,\n res,\n client,\n}: {\n req: NextApiRequest\n res: NextApiResponse\n client: MakeswiftClient\n}): Promise<ApiHandlerConfig> {\n return {\n req: toApiRequest(req),\n route: validateApiRoute(await apiRequestParams(req)),\n previewCookieNames: [PRERENDER_BYPASS_COOKIE, PREVIEW_DATA_COOKIE],\n\n sendResponse: (apiResponse: ApiResponse): Promise<Response | void> =>\n pipeResponseTo(apiResponse, res),\n\n revalidationHandler: async (path?: string): Promise<void> => {\n if (path != null) {\n await res.revalidate(path)\n } else {\n // No-op, Pages Router does not support tag-based revalidation\n }\n },\n\n customRoutes: async (route: string) => {\n if (route === '/redirect-preview') {\n return { res: await pagesRouterRedirectPreviewHandler(req, res, client) }\n }\n\n return null\n },\n }\n}\n\nfunction apiRequestParams(request: NextApiRequest): Promise<NextApiRequest['query']> {\n // `NextApiRequest.query` prop became async in Next.js 15, but it's not reflected in the type definition;\n // force-casting it to a `Promise` manually\n return Promise.resolve(request.query)\n}\n"],"mappings":"AAAA,SAAS,SAAS;AAIlB,SAAS,cAAc,sBAAsB;AAE7C,SAAS,yCAAyC;AAClD,SAAS,yBAAyB,2BAA2B;AAE7D,SAAS,wBAA+C;AAIjD,MAAM,cAAc,CAAC,EAAE,KAAK,EAAE,GAAG;AAExC,eAAsB,OAAO;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,GAI8B;AAC5B,SAAO;AAAA,IACL,KAAK,aAAa,GAAG;AAAA,IACrB,OAAO,iBAAiB,MAAM,iBAAiB,GAAG,CAAC;AAAA,IACnD,oBAAoB,CAAC,yBAAyB,mBAAmB;AAAA,IAEjE,cAAc,CAAC,gBACb,eAAe,aAAa,GAAG;AAAA,IAEjC,qBAAqB,OAAO,SAAiC;AAC3D,UAAI,QAAQ,MAAM;AAChB,cAAM,IAAI,WAAW,IAAI;AAAA,MAC3B,OAAO;AAAA,MAEP;AAAA,IACF;AAAA,IAEA,cAAc,OAAO,UAAkB;AACrC,UAAI,UAAU,qBAAqB;AACjC,eAAO,EAAE,KAAK,MAAM,kCAAkC,KAAK,KAAK,MAAM,EAAE;AAAA,MAC1E;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,SAAS,iBAAiB,SAA2D;AAGnF,SAAO,QAAQ,QAAQ,QAAQ,KAAK;AACtC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/next/fetch.ts"],"sourcesContent":["import { type HttpFetch } from '../state/
|
|
1
|
+
{"version":3,"sources":["../../../src/next/fetch.ts"],"sourcesContent":["import { type HttpFetch } from '../state/api-client/fetch-api-resource'\n\nimport { MAKESWIFT_CACHE_TAG } from './cache'\n\nexport const fetch: HttpFetch = (url, init) =>\n globalThis.fetch(url, { ...init, next: { tags: [MAKESWIFT_CACHE_TAG] } })\n"],"mappings":"AAEA,SAAS,2BAA2B;AAE7B,MAAM,QAAmB,CAAC,KAAK,SACpC,WAAW,MAAM,KAAK,EAAE,GAAG,MAAM,MAAM,EAAE,MAAM,CAAC,mBAAmB,EAAE,EAAE,CAAC;","names":[]}
|
|
@@ -2,7 +2,7 @@ import { useMemo } from "react";
|
|
|
2
2
|
import { updateAPIClientCache } from "../../../state/actions/internal/read-write-actions";
|
|
3
3
|
import { useMakeswiftHostApiClient } from "../host-api-client";
|
|
4
4
|
function useCacheData(cacheData) {
|
|
5
|
-
const {
|
|
5
|
+
const { store: apiStore } = useMakeswiftHostApiClient();
|
|
6
6
|
useMemo(() => apiStore.dispatch(updateAPIClientCache(cacheData)), [cacheData]);
|
|
7
7
|
}
|
|
8
8
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-cache-data.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type CacheData } from '../../../api/client'\nimport { updateAPIClientCache } from '../../../state/actions/internal/read-write-actions'\n\nimport { useMakeswiftHostApiClient } from '../host-api-client'\n\nexport function useCacheData(cacheData: CacheData) {\n const {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-cache-data.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type CacheData } from '../../../api/client'\nimport { updateAPIClientCache } from '../../../state/actions/internal/read-write-actions'\n\nimport { useMakeswiftHostApiClient } from '../host-api-client'\n\nexport function useCacheData(cacheData: CacheData) {\n const { store: apiStore } = useMakeswiftHostApiClient()\n\n // We perform cache hydration immediately on render - this is safe to do per\n // render because updating the API cache is idempotent. For precedence, see:\n //\n // https://github.com/TanStack/query/blob/8f9f183f11df3709a1a38c4efce1452788041f88/packages/react-query/src/HydrationBoundary.tsx#L41\n useMemo(() => apiStore.dispatch(updateAPIClientCache(cacheData)), [cacheData])\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAExB,SAAS,4BAA4B;AAErC,SAAS,iCAAiC;AAEnC,SAAS,aAAa,WAAsB;AACjD,QAAM,EAAE,OAAO,SAAS,IAAI,0BAA0B;AAMtD,UAAQ,MAAM,SAAS,SAAS,qBAAqB,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/E;","names":[]}
|
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import * as ReactPage from "../../../state/read-only-state";
|
|
3
2
|
import { useMakeswiftHostApiClient } from "../host-api-client";
|
|
3
|
+
import { createResourceResolver } from "../resource-resolver";
|
|
4
4
|
import { useStore } from "./use-store";
|
|
5
5
|
import { useDocumentKey, useDocumentLocale } from "./use-document-context";
|
|
6
6
|
function useResourceResolver() {
|
|
7
7
|
const store = useStore();
|
|
8
|
-
const
|
|
8
|
+
const apiClient = useMakeswiftHostApiClient();
|
|
9
9
|
const documentKey = useDocumentKey();
|
|
10
10
|
const locale = useDocumentLocale();
|
|
11
|
-
return useMemo(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
name: `element-id:${documentKey}:${elementKey}`,
|
|
22
|
-
readStable: () => lastValue = read(),
|
|
23
|
-
subscribe: (onUpdate) => store.subscribe(() => {
|
|
24
|
-
if (read() !== lastValue)
|
|
25
|
-
onUpdate();
|
|
26
|
-
})
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}, [client, store, documentKey, locale]);
|
|
11
|
+
return useMemo(
|
|
12
|
+
() => createResourceResolver({
|
|
13
|
+
store,
|
|
14
|
+
apiClient,
|
|
15
|
+
documentKey,
|
|
16
|
+
locale
|
|
17
|
+
}),
|
|
18
|
+
[store, apiClient, documentKey, locale]
|
|
19
|
+
);
|
|
31
20
|
}
|
|
32
21
|
export {
|
|
33
22
|
useResourceResolver
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport { useMakeswiftHostApiClient } from '../host-api-client'\nimport { createResourceResolver } from '../resource-resolver'\n\nimport { useStore } from './use-store'\nimport { useDocumentKey, useDocumentLocale } from './use-document-context'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const apiClient = useMakeswiftHostApiClient()\n\n const documentKey = useDocumentKey()\n const locale = useDocumentLocale()\n\n return useMemo<ResourceResolver>(\n () =>\n createResourceResolver({\n store,\n apiClient,\n documentKey,\n locale,\n }),\n [store, apiClient, documentKey, locale],\n )\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAGxB,SAAS,iCAAiC;AAC1C,SAAS,8BAA8B;AAEvC,SAAS,gBAAgB;AACzB,SAAS,gBAAgB,yBAAyB;AAE3C,SAAS,sBAAwC;AACtD,QAAM,QAAQ,SAAS;AACvB,QAAM,YAAY,0BAA0B;AAE5C,QAAM,cAAc,eAAe;AACnC,QAAM,SAAS,kBAAkB;AAEjC,SAAO;AAAA,IACL,MACE,uBAAuB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,OAAO,WAAW,aAAa,MAAM;AAAA,EACxC;AACF;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getElementId } from "../../state/read-only-state";
|
|
2
|
+
const createResourceResolver = ({
|
|
3
|
+
store,
|
|
4
|
+
apiClient,
|
|
5
|
+
documentKey,
|
|
6
|
+
locale
|
|
7
|
+
}) => ({
|
|
8
|
+
resolveSwatch: (swatchId) => apiClient.resolveSwatch(swatchId),
|
|
9
|
+
resolveFile: (fileId) => apiClient.resolveFile(fileId),
|
|
10
|
+
resolveTypography: (typographyId) => apiClient.resolveTypography(typographyId),
|
|
11
|
+
resolvePagePathnameSlice: (pageId) => apiClient.resolvePagePathnameSlice({ pageId, locale }),
|
|
12
|
+
resolveElementId: (elementKey) => {
|
|
13
|
+
const read = () => documentKey == null ? null : getElementId(store.getState(), documentKey, elementKey);
|
|
14
|
+
let lastValue = null;
|
|
15
|
+
return {
|
|
16
|
+
name: `element-id:${documentKey}:${elementKey}`,
|
|
17
|
+
readStable: () => lastValue = read(),
|
|
18
|
+
subscribe: (onUpdate) => store.subscribe(() => {
|
|
19
|
+
if (read() !== lastValue)
|
|
20
|
+
onUpdate();
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
export {
|
|
26
|
+
createResourceResolver
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=resource-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/resource-resolver.ts"],"sourcesContent":["import { type ResourceResolver } from '@makeswift/controls'\n\nimport { getElementId } from '../../state/read-only-state'\nimport { ApiResourcesClient } from '../../api/api-resources-client'\nimport { Store } from '../../state/store'\n\nexport const createResourceResolver = ({\n store,\n apiClient,\n documentKey,\n locale,\n}: {\n store: Store\n apiClient: ApiResourcesClient\n documentKey: string | null\n locale: string | null\n}): ResourceResolver => ({\n resolveSwatch: swatchId => apiClient.resolveSwatch(swatchId),\n resolveFile: fileId => apiClient.resolveFile(fileId),\n resolveTypography: typographyId => apiClient.resolveTypography(typographyId),\n resolvePagePathnameSlice: pageId => apiClient.resolvePagePathnameSlice({ pageId, locale }),\n resolveElementId: elementKey => {\n const read = () =>\n documentKey == null ? null : getElementId(store.getState(), documentKey, elementKey)\n\n let lastValue: string | null = null\n return {\n name: `element-id:${documentKey}:${elementKey}`,\n readStable: () => (lastValue = read()),\n subscribe: (onUpdate: () => void) =>\n store.subscribe(() => {\n if (read() !== lastValue) onUpdate()\n }),\n }\n },\n})\n"],"mappings":"AAEA,SAAS,oBAAoB;AAItB,MAAM,yBAAyB,CAAC;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,OAKyB;AAAA,EACvB,eAAe,cAAY,UAAU,cAAc,QAAQ;AAAA,EAC3D,aAAa,YAAU,UAAU,YAAY,MAAM;AAAA,EACnD,mBAAmB,kBAAgB,UAAU,kBAAkB,YAAY;AAAA,EAC3E,0BAA0B,YAAU,UAAU,yBAAyB,EAAE,QAAQ,OAAO,CAAC;AAAA,EACzF,kBAAkB,gBAAc;AAC9B,UAAM,OAAO,MACX,eAAe,OAAO,OAAO,aAAa,MAAM,SAAS,GAAG,aAAa,UAAU;AAErF,QAAI,YAA2B;AAC/B,WAAO;AAAA,MACL,MAAM,cAAc,WAAW,IAAI,UAAU;AAAA,MAC7C,YAAY,MAAO,YAAY,KAAK;AAAA,MACpC,WAAW,CAAC,aACV,MAAM,UAAU,MAAM;AACpB,YAAI,KAAK,MAAM;AAAW,mBAAS;AAAA,MACrC,CAAC;AAAA,IACL;AAAA,EACF;AACF;","names":[]}
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport { type HttpFetch } from '../../state/api-client/fetch-api-resource'\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: 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: HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n this.requestKey = requestKey\n this.fetch = fetch\n\n this.protoStore = configureProtoStore({\n name: 'Runtime proto-store',\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n getOrCreateStore({ siteVersion, locale }: StoreKey): Store {\n const key = storeCacheKey({ siteVersion, locale })\n\n const createStore = () => {\n // host API client includes an in-memory cache of the site's resources and thus also has to be versioned\n const hostApiClient = new MakeswiftHostApiClient({\n uri: new URL('graphql', this.apiOrigin).href,\n fetch: this.fetch,\n preloadedState: { siteVersion, locale },\n })\n\n // TODO: we need to decouple editability from the site version; specifically, previewing\n // a draft version of the site should not lead to switching to the read-write state\n const isReadOnly = siteVersion == null\n\n return configureReadWriteStore({\n name: `Runtime read-write store (site version: ${key})`,\n appOrigin: this.appOrigin,\n hostApiClient,\n preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale },\n })\n }\n\n // On the server, stores are ephemeral by default so SSR does not retain them in a long-lived runtime.\n // The exception is a runtime that is already bound to the requested site version & locale, where we\n // can safely reuse the store across multiple root regions and benefit from the host API client's\n // in-memory cache.\n //\n // On the client, stores are reference-counted by site version so multiple root regions can share a store\n // instance, which preserves the pre-v0.17 per-site-version store behavior without requiring a separate\n // runtime per root.\n const usePersistentStore = this.shouldUsePersistentStore(key)\n return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore()\n }\n\n retainStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to retain an ephemeral store', { key })\n return\n }\n\n if (this.activeStores.retain(key, store)) {\n store.startBreakpointWatch()\n }\n }\n\n releaseStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to release an ephemeral store', { key })\n return\n }\n\n if (this.activeStores.release(key, store)) {\n store.stopBreakpointWatch()\n }\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.protoStore.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.protoStore.getState())\n }\n\n private shouldUsePersistentStore(key: string): boolean {\n // don't persist stores on the server unless the runtime instance is bound to a request\n // and the requested store matches the request's site version and locale\n return !isServer() || (this.requestKey !== undefined && storeCacheKey(this.requestKey) === key)\n }\n}\n\nconst storeCacheKey = ({ siteVersion, locale }: StoreKey): string =>\n `${siteVersionTag(siteVersion)}/${locale ?? 'default'}`\n\nconst siteVersionTag = (siteVersion: SiteVersion | null): string =>\n siteVersion?.version ?? VERSION_TAG_LIVE\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime received an invalid \\`${name}\\` parameter: \"${url}\".`)\n }\n}\n"],"mappings":"AAEA,SAAS,8BAA8B;AAIvC;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,uBAAuB;AAEhC,SAAS,sBAAsD;AAC/D;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAOzB,MAAM,mBAAmB;AAElB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,eAAe,IAAI,cAAoC;AAAA,IACtE,mBAAmB;AAAA;AAAA;AAAA;AAAA,IAInB,UAAU,cAAc,SAAS,YAAY,cAAc,SAAS;AAAA,EACtE,CAAC;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAMG;AACD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,aAAa;AAClB,SAAK,QAAQ;AAEb,SAAK,aAAa,oBAAoB;AAAA,MACpC,MAAM;AAAA,MACN,aAAa,cAAc,sBAAsB,WAAW,IAAI;AAAA,IAClE,CAAC;AAAA,EACH;AAAA,EAEA,iBAAiB,EAAE,aAAa,OAAO,GAAoB;AACzD,UAAM,MAAM,cAAc,EAAE,aAAa,OAAO,CAAC;AAEjD,UAAM,cAAc,MAAM;AAExB,YAAM,gBAAgB,IAAI,uBAAuB;AAAA,QAC/C,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,aAAO,wBAAwB;AAAA,QAC7B,MAAM,2CAA2C,GAAG;AAAA,QACpD,WAAW,KAAK;AAAA,QAChB;AAAA,QACA,gBAAgB,EAAE,GAAG,KAAK,WAAW,SAAS,GAAG,aAAa,YAAY,OAAO;AAAA,MACnF,CAAC;AAAA,IACH;AAUA,UAAM,qBAAqB,KAAK,yBAAyB,GAAG;AAC5D,WAAO,qBAAqB,KAAK,aAAa,YAAY,KAAK,WAAW,IAAI,YAAY;AAAA,EAC5F;AAAA,EAEA,YAAY,EAAE,aAAa,OAAO,GAAa,OAAoB;AACjE,UAAM,MAAM,cAAc,EAAE,aAAa,OAAO,CAAC;AAEjD,QAAI,CAAC,KAAK,yBAAyB,GAAG,GAAG;AACvC,cAAQ,MAAM,qDAAqD,EAAE,IAAI,CAAC;AAC1E;AAAA,IACF;AAEA,QAAI,KAAK,aAAa,OAAO,KAAK,KAAK,GAAG;AACxC,YAAM,qBAAqB;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,aAAa,EAAE,aAAa,OAAO,GAAa,OAAoB;AAClE,UAAM,MAAM,cAAc,EAAE,aAAa,OAAO,CAAC;AAEjD,QAAI,CAAC,KAAK,yBAAyB,GAAG,GAAG;AACvC,cAAQ,MAAM,sDAAsD,EAAE,IAAI,CAAC;AAC3E;AAAA,IACF;AAEA,QAAI,KAAK,aAAa,QAAQ,KAAK,KAAK,GAAG;AACzC,YAAM,oBAAoB;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,gBACE,aACA,oBACS;AACT,WAAO,gBAAgB,KAAK,WAAW,SAAS,GAAG,aAAa,kBAAkB;AAAA,EACpF;AAAA,EAEA,iBAA8B;AAC5B,WAAO,eAAe,KAAK,WAAW,SAAS,CAAC;AAAA,EAClD;AAAA,EAEQ,yBAAyB,KAAsB;AAGrD,WAAO,CAAC,SAAS,KAAM,KAAK,eAAe,UAAa,cAAc,KAAK,UAAU,MAAM;AAAA,EAC7F;AACF;AAEA,MAAM,gBAAgB,CAAC,EAAE,aAAa,OAAO,MAC3C,GAAG,eAAe,WAAW,CAAC,IAAI,UAAU,SAAS;AAEvD,MAAM,iBAAiB,CAAC,gBACtB,aAAa,WAAW;AAE1B,SAAS,eAAe,KAAa,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { IconRadioGroup, Slate } from "@makeswift/controls";
|
|
3
3
|
import { Plugin } from "../../controls/rich-text-v2/plugin";
|
|
4
4
|
import { supportedInlineOptions, isSupportedInlineNode } from "./types";
|
|
5
5
|
import { onChange } from "./onChange";
|
|
@@ -14,7 +14,7 @@ const withInline = (editor) => {
|
|
|
14
14
|
function InlinePlugin() {
|
|
15
15
|
return Plugin({
|
|
16
16
|
control: {
|
|
17
|
-
definition:
|
|
17
|
+
definition: IconRadioGroup({
|
|
18
18
|
label: "Inline",
|
|
19
19
|
options: supportedInlineOptions
|
|
20
20
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/slate/InlinePlugin/index.tsx"],"sourcesContent":["import { type Editor, type Element } from 'slate'\nimport { type RenderElementProps } from 'slate-react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/slate/InlinePlugin/index.tsx"],"sourcesContent":["import { type Editor, type Element } from 'slate'\nimport { type RenderElementProps } from 'slate-react'\nimport { IconRadioGroup, Slate } from '@makeswift/controls'\n\nimport { type RenderElement, Plugin } from '../../controls/rich-text-v2/plugin'\n\nimport { supportedInlineOptions, isSupportedInlineNode } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withInline = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return Slate.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nexport function InlinePlugin() {\n return Plugin({\n control: {\n definition: IconRadioGroup({\n label: 'Inline',\n options: supportedInlineOptions,\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) =>\n isSupportedInlineNode(element) ? element.type : undefined,\n },\n withPlugin: withInline,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n\nfunction InlinePluginComponent({\n renderElement,\n ...props\n}: RenderElementProps & { renderElement: RenderElement }) {\n switch (props.element.type) {\n case Slate.InlineType.Code:\n return <code {...props.attributes}>{renderElement(props)}</code>\n\n case Slate.InlineType.SuperScript:\n return <sup {...props.attributes}>{renderElement(props)}</sup>\n\n case Slate.InlineType.SubScript:\n return <sub {...props.attributes}>{renderElement(props)}</sub>\n\n default:\n return <>{renderElement(props)}</>\n }\n}\n"],"mappings":"AAkCa,SAoBA,UApBA;AAhCb,SAAS,gBAAgB,aAAa;AAEtC,SAA6B,cAAc;AAE3C,SAAS,wBAAwB,6BAA6B;AAC9D,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AAElB,MAAM,aAAa,CAAC,WAAmB;AAC5C,QAAM,EAAE,SAAS,IAAI;AAErB,SAAO,WAAW,WAAS;AACzB,WAAO,MAAM,SAAS,KAAK,KAAK,SAAS,KAAK;AAAA,EAChD;AAEA,SAAO;AACT;AAEO,SAAS,eAAe;AAC7B,SAAO,OAAO;AAAA,IACZ,SAAS;AAAA,MACP,YAAY,eAAe;AAAA,QACzB,OAAO;AAAA,QACP,SAAS;AAAA,MACX,CAAC;AAAA,MACD;AAAA,MACA;AAAA,MACA,iBAAiB,CAAC,YAChB,sBAAsB,OAAO,IAAI,QAAQ,OAAO;AAAA,IACpD;AAAA,IACA,YAAY;AAAA,IACZ,eAAe,mBAAiB,WAAS;AACvC,aAAO,oBAAC,yBAAuB,GAAG,OAAO,eAA8B;AAAA,IACzE;AAAA,EACF,CAAC;AACH;AAEA,SAAS,sBAAsB;AAAA,EAC7B;AAAA,EACA,GAAG;AACL,GAA0D;AACxD,UAAQ,MAAM,QAAQ,MAAM;AAAA,IAC1B,KAAK,MAAM,WAAW;AACpB,aAAO,oBAAC,UAAM,GAAG,MAAM,YAAa,wBAAc,KAAK,GAAE;AAAA,IAE3D,KAAK,MAAM,WAAW;AACpB,aAAO,oBAAC,SAAK,GAAG,MAAM,YAAa,wBAAc,KAAK,GAAE;AAAA,IAE1D,KAAK,MAAM,WAAW;AACpB,aAAO,oBAAC,SAAK,GAAG,MAAM,YAAa,wBAAc,KAAK,GAAE;AAAA,IAE1D;AACE,aAAO,gCAAG,wBAAc,KAAK,GAAE;AAAA,EACnC;AACF;","names":[]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Slate,
|
|
1
|
+
import { Slate, IconRadioGroup } from "@makeswift/controls";
|
|
2
2
|
const supportedInlineOptions = [
|
|
3
3
|
{
|
|
4
|
-
icon:
|
|
4
|
+
icon: IconRadioGroup.Icon.Superscript,
|
|
5
5
|
label: "Superscript",
|
|
6
6
|
value: "superscript"
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
|
-
icon:
|
|
9
|
+
icon: IconRadioGroup.Icon.Subscript,
|
|
10
10
|
label: "Subscript",
|
|
11
11
|
value: "subscript"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
icon:
|
|
14
|
+
icon: IconRadioGroup.Icon.Code,
|
|
15
15
|
label: "Code",
|
|
16
16
|
value: "code"
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/slate/InlinePlugin/types.ts"],"sourcesContent":["import { Slate,
|
|
1
|
+
{"version":3,"sources":["../../../../src/slate/InlinePlugin/types.ts"],"sourcesContent":["import { Slate, IconRadioGroup } from '@makeswift/controls'\nimport { Node, NodeEntry } from 'slate'\n\nexport type SupportedInlineType = Exclude<Slate.InlineType, 'link'>\nexport type SupportedInline = Exclude<Slate.Inline, Slate.LinkElement>\n\nexport const supportedInlineOptions = [\n {\n icon: IconRadioGroup.Icon.Superscript,\n label: 'Superscript',\n value: 'superscript',\n },\n {\n icon: IconRadioGroup.Icon.Subscript,\n label: 'Subscript',\n value: 'subscript',\n },\n {\n icon: IconRadioGroup.Icon.Code,\n label: 'Code',\n value: 'code',\n },\n] as const\n\nexport function isSupportedInlineType(inline: Slate.InlineType): inline is SupportedInlineType {\n return supportedInlineOptions.findIndex(option => option.value === inline) !== -1\n}\n\nexport function isSupportedInlineNode(node: Node): node is SupportedInline {\n return Slate.isInline(node) && isSupportedInlineType(node.type)\n}\n\nexport function isSupportedInlineEntry(\n entry: NodeEntry<Node>,\n): entry is NodeEntry<SupportedInline> {\n return isSupportedInlineNode(entry[0])\n}\n"],"mappings":"AAAA,SAAS,OAAO,sBAAsB;AAM/B,MAAM,yBAAyB;AAAA,EACpC;AAAA,IACE,MAAM,eAAe,KAAK;AAAA,IAC1B,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,MAAM,eAAe,KAAK;AAAA,IAC1B,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,MAAM,eAAe,KAAK;AAAA,IAC1B,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AACF;AAEO,SAAS,sBAAsB,QAAyD;AAC7F,SAAO,uBAAuB,UAAU,YAAU,OAAO,UAAU,MAAM,MAAM;AACjF;AAEO,SAAS,sBAAsB,MAAqC;AACzE,SAAO,MAAM,SAAS,IAAI,KAAK,sBAAsB,KAAK,IAAI;AAChE;AAEO,SAAS,uBACd,OACqC;AACrC,SAAO,sBAAsB,MAAM,CAAC,CAAC;AACvC;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IconRadioGroup, Slate } from "@makeswift/controls";
|
|
2
2
|
import { unstable_StyleV2 } from "../../controls/style-v2/style-v2";
|
|
3
3
|
import { normalizeResponsiveValue, setResponsiveValue } from "../utils/responsive";
|
|
4
4
|
import { getValue } from "./getValue";
|
|
@@ -20,26 +20,26 @@ function TextAlignPlugin() {
|
|
|
20
20
|
return Plugin({
|
|
21
21
|
control: {
|
|
22
22
|
definition: unstable_StyleV2({
|
|
23
|
-
type:
|
|
23
|
+
type: IconRadioGroup({
|
|
24
24
|
label: "Alignment",
|
|
25
25
|
options: [
|
|
26
26
|
{
|
|
27
|
-
icon:
|
|
27
|
+
icon: IconRadioGroup.Icon.TextAlignLeft,
|
|
28
28
|
label: "Left Align",
|
|
29
29
|
value: "left"
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
|
-
icon:
|
|
32
|
+
icon: IconRadioGroup.Icon.TextAlignCenter,
|
|
33
33
|
label: "Center Align",
|
|
34
34
|
value: "center"
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
|
-
icon:
|
|
37
|
+
icon: IconRadioGroup.Icon.TextAlignRight,
|
|
38
38
|
label: "Right Align",
|
|
39
39
|
value: "right"
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
|
-
icon:
|
|
42
|
+
icon: IconRadioGroup.Icon.TextAlignJustify,
|
|
43
43
|
label: "Justify",
|
|
44
44
|
value: "justify"
|
|
45
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/slate/TextAlignPlugin/index.tsx"],"sourcesContent":["import { Editor, Element, NodeEntry } from 'slate'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/slate/TextAlignPlugin/index.tsx"],"sourcesContent":["import { Editor, Element, NodeEntry } from 'slate'\nimport { IconRadioGroup, Slate } from '@makeswift/controls'\n\nimport { unstable_StyleV2 } from '../../controls/style-v2/style-v2'\nimport { normalizeResponsiveValue, setResponsiveValue } from '../utils/responsive'\nimport { getValue } from './getValue'\nimport { Plugin } from '../../controls/rich-text-v2/plugin'\n\nconst TEXT_ALIGN_KEY = 'textAlign'\n\nexport const withTextAlign = (editor: Editor) => {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n if (\n normalizeResponsiveValue(editor, TEXT_ALIGN_KEY, { match: Slate.isRootBlock })(\n entry as NodeEntry<Slate.RootBlock>,\n )\n ) {\n return\n }\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TextAlignPlugin() {\n return Plugin({\n control: {\n definition: unstable_StyleV2({\n type: IconRadioGroup({\n label: 'Alignment',\n options: [\n {\n icon: IconRadioGroup.Icon.TextAlignLeft,\n label: 'Left Align',\n value: 'left',\n },\n {\n icon: IconRadioGroup.Icon.TextAlignCenter,\n label: 'Center Align',\n value: 'center',\n },\n {\n icon: IconRadioGroup.Icon.TextAlignRight,\n label: 'Right Align',\n value: 'right',\n },\n {\n icon: IconRadioGroup.Icon.TextAlignJustify,\n label: 'Justify',\n value: 'justify',\n },\n ],\n defaultValue: 'left',\n }),\n getStyle(textAlign) {\n return { textAlign }\n },\n }),\n onChange: (editor, value) =>\n setResponsiveValue(editor, TEXT_ALIGN_KEY, value, {\n match: Slate.isRootBlock,\n split: false,\n }),\n getValue,\n getElementValue: (element: Element) => {\n return Slate.isRootBlock(element) ? element.textAlign : undefined\n },\n },\n withPlugin: withTextAlign,\n renderElement: (renderElement, className) => props => {\n return renderElement({\n ...props,\n element: {\n ...props.element,\n className,\n },\n })\n },\n })\n}\n"],"mappings":"AACA,SAAS,gBAAgB,aAAa;AAEtC,SAAS,wBAAwB;AACjC,SAAS,0BAA0B,0BAA0B;AAC7D,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB,MAAM,iBAAiB;AAEhB,MAAM,gBAAgB,CAAC,WAAmB;AAC/C,QAAM,EAAE,cAAc,IAAI;AAC1B,SAAO,gBAAgB,WAAS;AAC9B,QACE,yBAAyB,QAAQ,gBAAgB,EAAE,OAAO,MAAM,YAAY,CAAC;AAAA,MAC3E;AAAA,IACF,GACA;AACA;AAAA,IACF;AACA,kBAAc,KAAK;AAAA,EACrB;AAEA,SAAO;AACT;AAEO,SAAS,kBAAkB;AAChC,SAAO,OAAO;AAAA,IACZ,SAAS;AAAA,MACP,YAAY,iBAAiB;AAAA,QAC3B,MAAM,eAAe;AAAA,UACnB,OAAO;AAAA,UACP,SAAS;AAAA,YACP;AAAA,cACE,MAAM,eAAe,KAAK;AAAA,cAC1B,OAAO;AAAA,cACP,OAAO;AAAA,YACT;AAAA,YACA;AAAA,cACE,MAAM,eAAe,KAAK;AAAA,cAC1B,OAAO;AAAA,cACP,OAAO;AAAA,YACT;AAAA,YACA;AAAA,cACE,MAAM,eAAe,KAAK;AAAA,cAC1B,OAAO;AAAA,cACP,OAAO;AAAA,YACT;AAAA,YACA;AAAA,cACE,MAAM,eAAe,KAAK;AAAA,cAC1B,OAAO;AAAA,cACP,OAAO;AAAA,YACT;AAAA,UACF;AAAA,UACA,cAAc;AAAA,QAChB,CAAC;AAAA,QACD,SAAS,WAAW;AAClB,iBAAO,EAAE,UAAU;AAAA,QACrB;AAAA,MACF,CAAC;AAAA,MACD,UAAU,CAAC,QAAQ,UACjB,mBAAmB,QAAQ,gBAAgB,OAAO;AAAA,QAChD,OAAO,MAAM;AAAA,QACb,OAAO;AAAA,MACT,CAAC;AAAA,MACH;AAAA,MACA,iBAAiB,CAAC,YAAqB;AACrC,eAAO,MAAM,YAAY,OAAO,IAAI,QAAQ,YAAY;AAAA,MAC1D;AAAA,IACF;AAAA,IACA,YAAY;AAAA,IACZ,eAAe,CAAC,eAAe,cAAc,WAAS;AACpD,aAAO,cAAc;AAAA,QACnB,GAAG;AAAA,QACH,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/state/actions/internal/read-write-actions.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type Measurable } from '../../modules/read-write/box-models'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\nimport { type SerializedState as APIClientCache } from '../../
|
|
1
|
+
{"version":3,"sources":["../../../../../src/state/actions/internal/read-write-actions.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type Measurable } from '../../modules/read-write/box-models'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\nimport { type SerializedState as APIClientCache } from '../../api-client/state'\n\nexport const ReadWriteActionTypes = {\n CHANGE_ELEMENT_TREE: 'CHANGE_ELEMENT_TREE',\n REGISTER_MEASURABLE: 'REGISTER_MEASURABLE',\n UNREGISTER_MEASURABLE: 'UNREGISTER_MEASURABLE',\n\n UPDATE_API_CLIENT_CACHE: 'UPDATE_API_CLIENT_CACHE',\n CLEAR_API_CLIENT_CACHE: 'CLEAR_API_CLIENT_CACHE',\n} as const\n\ntype ChangeElementTreeAction = {\n type: typeof ReadWriteActionTypes.CHANGE_ELEMENT_TREE\n payload: {\n oldDocument: DocumentPayload\n newDocument: DocumentPayload\n descriptors: DescriptorsByComponentType\n operation: Operation\n }\n}\n\ntype RegisterMeasurableAction = {\n type: typeof ReadWriteActionTypes.REGISTER_MEASURABLE\n payload: { documentKey: string; elementKey: string; measurable: Measurable }\n}\n\ntype UnregisterMeasurableAction = {\n type: typeof ReadWriteActionTypes.UNREGISTER_MEASURABLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype UpdateAPIClientCache = {\n type: typeof ReadWriteActionTypes.UPDATE_API_CLIENT_CACHE\n payload: APIClientCache\n}\n\ntype ClearAPIClientCache = {\n type: typeof ReadWriteActionTypes.CLEAR_API_CLIENT_CACHE\n}\n\nexport type ReadWriteAction =\n | ChangeElementTreeAction\n | RegisterMeasurableAction\n | UnregisterMeasurableAction\n | UpdateAPIClientCache\n | ClearAPIClientCache\n\nexport function changeElementTree(\n payload: ChangeElementTreeAction['payload'],\n): ChangeElementTreeAction {\n return {\n type: ReadWriteActionTypes.CHANGE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function registerMeasurable(\n documentKey: string,\n elementKey: string,\n measurable: Measurable,\n): RegisterMeasurableAction {\n return {\n type: ReadWriteActionTypes.REGISTER_MEASURABLE,\n payload: { documentKey, elementKey, measurable },\n }\n}\n\nexport function unregisterMeasurable(\n documentKey: string,\n elementKey: string,\n): UnregisterMeasurableAction {\n return { type: ReadWriteActionTypes.UNREGISTER_MEASURABLE, payload: { documentKey, elementKey } }\n}\n\nexport function registerMeasurableEffect(\n documentKey: string,\n elementKey: string,\n measurable: Measurable,\n): ThunkAction<() => void, unknown, unknown, ReadWriteAction> {\n return dispatch => {\n dispatch(registerMeasurable(documentKey, elementKey, measurable))\n\n return () => {\n dispatch(unregisterMeasurable(documentKey, elementKey))\n }\n }\n}\n\nexport function updateAPIClientCache(payload: APIClientCache): UpdateAPIClientCache {\n return { type: ReadWriteActionTypes.UPDATE_API_CLIENT_CACHE, payload }\n}\n\nexport function clearAPIClientCache(): ClearAPIClientCache {\n return { type: ReadWriteActionTypes.CLEAR_API_CLIENT_CACHE }\n}\n"],"mappings":"AASO,MAAM,uBAAuB;AAAA,EAClC,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EACrB,uBAAuB;AAAA,EAEvB,yBAAyB;AAAA,EACzB,wBAAwB;AAC1B;AAsCO,SAAS,kBACd,SACyB;AACzB,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B;AAAA,EACF;AACF;AAEO,SAAS,mBACd,aACA,YACA,YAC0B;AAC1B,SAAO;AAAA,IACL,MAAM,qBAAqB;AAAA,IAC3B,SAAS,EAAE,aAAa,YAAY,WAAW;AAAA,EACjD;AACF;AAEO,SAAS,qBACd,aACA,YAC4B;AAC5B,SAAO,EAAE,MAAM,qBAAqB,uBAAuB,SAAS,EAAE,aAAa,WAAW,EAAE;AAClG;AAEO,SAAS,yBACd,aACA,YACA,YAC4D;AAC5D,SAAO,cAAY;AACjB,aAAS,mBAAmB,aAAa,YAAY,UAAU,CAAC;AAEhE,WAAO,MAAM;AACX,eAAS,qBAAqB,aAAa,UAAU,CAAC;AAAA,IACxD;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,SAA+C;AAClF,SAAO,EAAE,MAAM,qBAAqB,yBAAyB,QAAQ;AACvE;AAEO,SAAS,sBAA2C;AACzD,SAAO,EAAE,MAAM,qBAAqB,uBAAuB;AAC7D;","names":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configureStore as configureReduxStore
|
|
3
|
+
} from "@reduxjs/toolkit";
|
|
4
|
+
import * as LocaleState from "../modules/locale";
|
|
5
|
+
import { ActionTypes } from "../actions";
|
|
6
|
+
import { actionMiddleware, middlewareOptions, devToolsConfig } from "../toolkit";
|
|
7
|
+
import { reducer } from "./state";
|
|
8
|
+
function defaultLocaleMiddleware() {
|
|
9
|
+
return actionMiddleware(({ getState }) => (next) => {
|
|
10
|
+
return (action) => {
|
|
11
|
+
switch (action.type) {
|
|
12
|
+
case ActionTypes.CHANGE_API_RESOURCE:
|
|
13
|
+
case ActionTypes.EVICT_API_RESOURCE:
|
|
14
|
+
case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {
|
|
15
|
+
const { locale } = action.payload;
|
|
16
|
+
return next({
|
|
17
|
+
...action,
|
|
18
|
+
payload: {
|
|
19
|
+
...action.payload,
|
|
20
|
+
locale: locale ?? LocaleState.getLocale(getState().locale)
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return next(action);
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function configureClientStore({
|
|
30
|
+
preloadedState
|
|
31
|
+
}) {
|
|
32
|
+
return configureReduxStore({
|
|
33
|
+
reducer,
|
|
34
|
+
preloadedState,
|
|
35
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware()),
|
|
36
|
+
devTools: devToolsConfig({
|
|
37
|
+
name: `API client store (${(/* @__PURE__ */ new Date()).toISOString()})`,
|
|
38
|
+
actionsDenylist: [
|
|
39
|
+
ActionTypes.BUILDER_POINTER_MOVE,
|
|
40
|
+
ActionTypes.HANDLE_POINTER_MOVE,
|
|
41
|
+
ActionTypes.ELEMENT_FROM_POINT_CHANGE
|
|
42
|
+
]
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
configureClientStore
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=client-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/api-client/client-store.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n type ThunkMiddleware,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport * as LocaleState from '../modules/locale'\n\nimport { type Action, ActionTypes } from '../actions'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from '../toolkit'\n\nimport { type State, reducer } from './state'\nimport { type Store } from './store'\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 configureClientStore({\n preloadedState,\n}: {\n preloadedState: Partial<State>\n}): Store {\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"],"mappings":"AAAA;AAAA,EACE,kBAAkB;AAAA,OAGb;AAEP,YAAY,iBAAiB;AAE7B,SAAsB,mBAAmB;AACzC,SAAS,kBAAkB,mBAAmB,sBAAsB;AAEpE,SAAqB,eAAe;AAKpC,SAAS,0BAAiE;AACxE,SAAO,iBAAiB,CAAC,EAAE,SAAS,MAAM,UAAQ;AAChD,WAAO,CAAC,WAAmB;AACzB,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY,2BAA2B;AAC1C,gBAAM,EAAE,OAAO,IAAI,OAAO;AAC1B,iBAAO,KAAK;AAAA,YACV,GAAG;AAAA,YACH,SAAS;AAAA,cACP,GAAG,OAAO;AAAA,cACV,QAAQ,UAAU,YAAY,UAAU,SAAS,EAAE,MAAM;AAAA,YAC3D;AAAA,UACF,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,qBAAqB;AAAA,EACnC;AACF,GAEU;AACR,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE,OAAO,wBAAwB,CAAC;AAAA,IAE1E,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ApiHandlerHeaders, serializeSiteVersion } from "../../api/site-version";
|
|
2
|
+
import * as SiteVersionState from "../modules/site-version";
|
|
3
|
+
import { apiResourceFulfilled } from "../actions/internal/read-only-actions";
|
|
4
|
+
import { setLocalizedResourceId } from "../host-api";
|
|
5
|
+
import {
|
|
6
|
+
APIResourceType
|
|
7
|
+
} from "../../api";
|
|
8
|
+
import { getHasAPIResource, getAPIResource, getLocalizedResourceId } from "./state";
|
|
9
|
+
function fetchAPIResource(resourceType, resourceId, fetch, locale) {
|
|
10
|
+
const fetchVersioned = async (url, version) => {
|
|
11
|
+
const response = await fetch(url, {
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
...version != null ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) } : {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
if (response.status === 404)
|
|
18
|
+
return null;
|
|
19
|
+
if (!response.ok)
|
|
20
|
+
throw new Error(response.statusText);
|
|
21
|
+
if (response.headers.get("content-type")?.includes("application/json") !== true) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Expected JSON response from "${url}" but got "${response.headers.get("content-type")}"`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return response.json();
|
|
27
|
+
};
|
|
28
|
+
return async (dispatch, getState) => {
|
|
29
|
+
const state = getState();
|
|
30
|
+
const version = SiteVersionState.getSiteVersion(state.siteVersion);
|
|
31
|
+
if (getHasAPIResource(state, resourceType, resourceId, locale)) {
|
|
32
|
+
return getAPIResource(state, resourceType, resourceId, locale);
|
|
33
|
+
}
|
|
34
|
+
let resource;
|
|
35
|
+
switch (resourceType) {
|
|
36
|
+
case APIResourceType.Swatch:
|
|
37
|
+
resource = await fetchVersioned(`/api/makeswift/swatches/${resourceId}`, version);
|
|
38
|
+
break;
|
|
39
|
+
case APIResourceType.File:
|
|
40
|
+
resource = await fetchVersioned(`/api/makeswift/files/${resourceId}`, version);
|
|
41
|
+
break;
|
|
42
|
+
case APIResourceType.Typography:
|
|
43
|
+
resource = await fetchVersioned(
|
|
44
|
+
`/api/makeswift/typographies/${resourceId}`,
|
|
45
|
+
version
|
|
46
|
+
);
|
|
47
|
+
break;
|
|
48
|
+
case APIResourceType.GlobalElement:
|
|
49
|
+
resource = await fetchVersioned(
|
|
50
|
+
`/api/makeswift/global-elements/${resourceId}`,
|
|
51
|
+
version
|
|
52
|
+
);
|
|
53
|
+
break;
|
|
54
|
+
case APIResourceType.LocalizedGlobalElement: {
|
|
55
|
+
if (locale == null)
|
|
56
|
+
throw new Error("Locale is required to fetch LocalizedGlobalElement");
|
|
57
|
+
if (getLocalizedResourceId(state, locale, resourceId) === null) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
resource = await fetchVersioned(
|
|
61
|
+
`/api/makeswift/localized-global-elements/${resourceId}/${locale}`,
|
|
62
|
+
version
|
|
63
|
+
);
|
|
64
|
+
dispatch(
|
|
65
|
+
setLocalizedResourceId({
|
|
66
|
+
locale,
|
|
67
|
+
resourceId,
|
|
68
|
+
localizedResourceId: resource?.id ?? null
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case APIResourceType.PagePathnameSlice: {
|
|
74
|
+
const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
|
|
75
|
+
if (locale != null)
|
|
76
|
+
url.searchParams.set("locale", locale);
|
|
77
|
+
resource = await fetchVersioned(url.pathname + url.search, version);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case APIResourceType.Table:
|
|
81
|
+
resource = await fetchVersioned(`/api/makeswift/tables/${resourceId}`, version);
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
resource = null;
|
|
85
|
+
}
|
|
86
|
+
dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale));
|
|
87
|
+
return resource;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
fetchAPIResource
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=fetch-api-resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/api-client/fetch-api-resource.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../../api/site-version'\n\nimport * as SiteVersionState from '../modules/site-version'\n\nimport { type Action } from '../actions'\nimport { apiResourceFulfilled } from '../actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from '../host-api'\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\nimport { type State, getHasAPIResource, getAPIResource, getLocalizedResourceId } from './state'\n\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\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"],"mappings":"AAEA,SAA2B,mBAAmB,4BAA4B;AAE1E,YAAY,sBAAsB;AAGlC,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AAEvC;AAAA,EACE;AAAA,OAUK;AAEP,SAAqB,mBAAmB,gBAAgB,8BAA8B;AAM/E,SAAS,iBACd,cACA,YACA,OACA,QACgE;AAChE,QAAM,iBAAiB,OAAU,KAAa,YAAmD;AAC/F,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,GAAI,WAAW,OACX,EAAE,CAAC,kBAAkB,WAAW,GAAG,qBAAqB,OAAO,EAAE,IACjE,CAAC;AAAA,MACP;AAAA,IACF,CAAC;AAED,QAAI,SAAS,WAAW;AAAK,aAAO;AACpC,QAAI,CAAC,SAAS;AAAI,YAAM,IAAI,MAAM,SAAS,UAAU;AAErD,QAAI,SAAS,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,MAAM,MAAM;AAC/E,YAAM,IAAI;AAAA,QACR,gCAAgC,GAAG,cAAc,SAAS,QAAQ,IAAI,cAAc,CAAC;AAAA,MACvF;AAAA,IACF;AAEA,WAAO,SAAS,KAAK;AAAA,EACvB;AAEA,SAAO,OAAO,UAAU,aAAa;AACnC,UAAM,QAAQ,SAAS;AACvB,UAAM,UAAU,iBAAiB,eAAe,MAAM,WAAW;AAEjE,QAAI,kBAAkB,OAAO,cAAc,YAAY,MAAM,GAAG;AAC9D,aAAO,eAAe,OAAO,cAAc,YAAY,MAAM;AAAA,IAC/D;AAEA,QAAI;AAEJ,YAAQ,cAAc;AAAA,MACpB,KAAK,gBAAgB;AACnB,mBAAW,MAAM,eAAuB,2BAA2B,UAAU,IAAI,OAAO;AACxF;AAAA,MAEF,KAAK,gBAAgB;AACnB,mBAAW,MAAM,eAAqB,wBAAwB,UAAU,IAAI,OAAO;AACnF;AAAA,MAEF,KAAK,gBAAgB;AACnB,mBAAW,MAAM;AAAA,UACf,+BAA+B,UAAU;AAAA,UACzC;AAAA,QACF;AACA;AAAA,MAEF,KAAK,gBAAgB;AACnB,mBAAW,MAAM;AAAA,UACf,kCAAkC,UAAU;AAAA,UAC5C;AAAA,QACF;AACA;AAAA,MAEF,KAAK,gBAAgB,wBAAwB;AAC3C,YAAI,UAAU;AAAM,gBAAM,IAAI,MAAM,oDAAoD;AAIxF,YAAI,uBAAuB,OAAO,QAAQ,UAAU,MAAM,MAAM;AAC9D,iBAAO;AAAA,QACT;AAEA,mBAAW,MAAM;AAAA,UACf,4CAA4C,UAAU,IAAI,MAAM;AAAA,UAChE;AAAA,QACF;AAEA;AAAA,UACE,uBAAuB;AAAA,YACrB;AAAA,YACA;AAAA,YACA,qBAAqB,UAAU,MAAM;AAAA,UACvC,CAAC;AAAA,QACH;AAEA;AAAA,MACF;AAAA,MAEA,KAAK,gBAAgB,mBAAmB;AACtC,cAAM,MAAM,IAAI,IAAI,uCAAuC,UAAU,IAAI,UAAU;AAEnF,YAAI,UAAU;AAAM,cAAI,aAAa,IAAI,UAAU,MAAM;AAEzD,mBAAW,MAAM,eAAkC,IAAI,WAAW,IAAI,QAAQ,OAAO;AACrF;AAAA,MACF;AAAA,MAEA,KAAK,gBAAgB;AACnB,mBAAW,MAAM,eAAsB,yBAAyB,UAAU,IAAI,OAAO;AACrF;AAAA,MAEF;AACE,mBAAW;AAAA,IACf;AAEA,aAAS,qBAAqB,cAAc,YAAY,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { combineReducers } from "@reduxjs/toolkit";
|
|
2
|
+
import * as SiteVersionState from "../modules/site-version";
|
|
3
|
+
import * as LocaleState from "../modules/locale";
|
|
4
|
+
import * as APIResources from "../modules/api-resources";
|
|
5
|
+
import * as LocalizedResourcesMap from "../modules/localized-resources-map";
|
|
6
|
+
import { APIResourceType } from "../../api";
|
|
7
|
+
const reducer = combineReducers({
|
|
8
|
+
siteVersion: SiteVersionState.reducer,
|
|
9
|
+
locale: LocaleState.reducer,
|
|
10
|
+
apiResources: APIResources.reducer,
|
|
11
|
+
localizedResourcesMap: LocalizedResourcesMap.reducer
|
|
12
|
+
});
|
|
13
|
+
function getLocalizedResourceId(state, locale, resourceId) {
|
|
14
|
+
return LocalizedResourcesMap.getLocalizedResourceId(
|
|
15
|
+
state.localizedResourcesMap,
|
|
16
|
+
locale,
|
|
17
|
+
resourceId
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function getHasAPIResource(state, resourceType, resourceId, locale) {
|
|
21
|
+
switch (resourceType) {
|
|
22
|
+
case APIResourceType.LocalizedGlobalElement:
|
|
23
|
+
if (locale == null) {
|
|
24
|
+
console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`);
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const localizedId = getLocalizedResourceId(state, locale, resourceId);
|
|
28
|
+
return localizedId != null && APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale);
|
|
29
|
+
default:
|
|
30
|
+
return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function getAPIResource(state, resourceType, resourceId, locale) {
|
|
34
|
+
switch (resourceType) {
|
|
35
|
+
case APIResourceType.LocalizedGlobalElement:
|
|
36
|
+
if (locale == null) {
|
|
37
|
+
console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const localizedId = getLocalizedResourceId(state, locale, resourceId);
|
|
41
|
+
return localizedId != null ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale) : null;
|
|
42
|
+
default:
|
|
43
|
+
return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
getAPIResource,
|
|
48
|
+
getHasAPIResource,
|
|
49
|
+
getLocalizedResourceId,
|
|
50
|
+
reducer
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/api-client/state.ts"],"sourcesContent":["import { combineReducers, type ThunkDispatch } from '@reduxjs/toolkit'\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 } from '../actions'\n\nimport { APIResourceType, type APIResource, type APIResourceLocale } from '../../api'\n\nexport const 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>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nexport function 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"],"mappings":"AAAA,SAAS,uBAA2C;AAEpD,YAAY,sBAAsB;AAClC,YAAY,iBAAiB;AAC7B,YAAY,kBAAkB;AAC9B,YAAY,2BAA2B;AAIvC,SAAS,uBAAiE;AAEnE,MAAM,UAAU,gBAAgB;AAAA,EACrC,aAAa,iBAAiB;AAAA,EAC9B,QAAQ,YAAY;AAAA,EACpB,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAUM,SAAS,uBACd,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBACd,OACA,cACA,YACA,QACS;AACT,UAAQ,cAAc;AAAA,IACpB,KAAK,gBAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aACE,eAAe,QACf,aAAa,kBAAkB,MAAM,cAAc,cAAc,aAAa,MAAM;AAAA,IAGxF;AACE,aAAO,aAAa,kBAAkB,MAAM,cAAc,cAAc,YAAY,MAAM;AAAA,EAC9F;AACF;AAEO,SAAS,eACd,OACA,cACA,YACA,QACgD;AAChD,UAAQ,cAAc;AAAA,IACpB,KAAK,gBAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aAAO,eAAe,OAClB,aAAa,eAAe,MAAM,cAAc,cAAc,aAAa,MAAM,IACjF;AAAA,IAEN;AACE,aAAO,aAAa,eAAe,MAAM,cAAc,cAAc,YAAY,MAAM;AAAA,EAC3F;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { configureStore as configureReduxStore } from "@reduxjs/toolkit";
|
|
2
|
+
import { reducer } from "./state";
|
|
3
|
+
function configureStore({ preloadedState }) {
|
|
4
|
+
return configureReduxStore({
|
|
5
|
+
reducer,
|
|
6
|
+
preloadedState
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
configureStore
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/api-client/store.ts"],"sourcesContent":["import { configureStore as configureReduxStore } from '@reduxjs/toolkit'\n\nimport { type State, reducer } from './state'\n\nexport function configureStore({ preloadedState }: { preloadedState: Partial<State> }) {\n return configureReduxStore({\n reducer,\n preloadedState,\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA,SAAS,kBAAkB,2BAA2B;AAEtD,SAAqB,eAAe;AAE7B,SAAS,eAAe,EAAE,eAAe,GAAuC;AACrF,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -2,7 +2,7 @@ import { actionMiddleware } from "../toolkit";
|
|
|
2
2
|
function makeswiftApiClientSyncMiddleware(client) {
|
|
3
3
|
return actionMiddleware(() => (next) => {
|
|
4
4
|
return (action) => {
|
|
5
|
-
client.
|
|
5
|
+
client.store.dispatch(action);
|
|
6
6
|
return next(action);
|
|
7
7
|
};
|
|
8
8
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport { type Action } from '../actions'\nimport { actionMiddleware } from '../toolkit'\nimport { type State, type Dispatch } from '../unified-state'\n\nexport function makeswiftApiClientSyncMiddleware(\n client: MakeswiftHostApiClient,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n client.
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport { type Action } from '../actions'\nimport { actionMiddleware } from '../toolkit'\nimport { type State, type Dispatch } from '../unified-state'\n\nexport function makeswiftApiClientSyncMiddleware(\n client: MakeswiftHostApiClient,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n client.store.dispatch(action)\n\n return next(action)\n }\n })\n}\n"],"mappings":"AAKA,SAAS,wBAAwB;AAG1B,SAAS,iCACd,QACuC;AACvC,SAAO,iBAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,aAAO,MAAM,SAAS,MAAM;AAE5B,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;","names":[]}
|