@uniformdev/canvas-sveltekit 20.48.1-alpha.17
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/LICENSE.txt +2 -0
- package/README.md +3 -0
- package/dist/components/UniformRichText.svelte +49 -0
- package/dist/components/UniformRichText.svelte.d.ts +16 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/resolvePathFromParams.d.ts +19 -0
- package/dist/helpers/resolvePathFromParams.js +19 -0
- package/dist/hooks/createUniformHandle.d.ts +41 -0
- package/dist/hooks/createUniformHandle.js +43 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +16 -0
- package/dist/isr/config.d.ts +49 -0
- package/dist/isr/config.js +30 -0
- package/dist/isr/createRevalidateHandler.d.ts +33 -0
- package/dist/isr/createRevalidateHandler.js +50 -0
- package/dist/isr/index.d.ts +2 -0
- package/dist/isr/index.js +2 -0
- package/dist/logging/index.d.ts +6 -0
- package/dist/logging/index.js +6 -0
- package/dist/logging/logCompositionIssues.d.ts +19 -0
- package/dist/logging/logCompositionIssues.js +49 -0
- package/dist/logging/logCompositionResponse.d.ts +5 -0
- package/dist/logging/logCompositionResponse.js +40 -0
- package/dist/logging/logCompositionRouteResponse.d.ts +5 -0
- package/dist/logging/logCompositionRouteResponse.js +20 -0
- package/dist/logging/logNotFoundRouteResponse.d.ts +5 -0
- package/dist/logging/logNotFoundRouteResponse.js +8 -0
- package/dist/logging/logRedirectRouteResponse.d.ts +5 -0
- package/dist/logging/logRedirectRouteResponse.js +8 -0
- package/dist/logging/logRouteResponse.d.ts +5 -0
- package/dist/logging/logRouteResponse.js +17 -0
- package/dist/models.d.ts +61 -0
- package/dist/models.js +4 -0
- package/dist/preview/createPreviewHandler.d.ts +29 -0
- package/dist/preview/createPreviewHandler.js +35 -0
- package/dist/preview/index.d.ts +4 -0
- package/dist/preview/index.js +4 -0
- package/dist/preview/previewCookie.d.ts +33 -0
- package/dist/preview/previewCookie.js +58 -0
- package/dist/preview/previewHandlerGet.d.ts +29 -0
- package/dist/preview/previewHandlerGet.js +138 -0
- package/dist/preview/previewHandlerPost.d.ts +29 -0
- package/dist/preview/previewHandlerPost.js +44 -0
- package/dist/route/createRouteFetcher.d.ts +20 -0
- package/dist/route/createRouteFetcher.js +90 -0
- package/dist/route/createUniformEntries.d.ts +26 -0
- package/dist/route/createUniformEntries.js +72 -0
- package/dist/route/createUniformLoad.d.ts +33 -0
- package/dist/route/createUniformLoad.js +71 -0
- package/dist/route/index.d.ts +4 -0
- package/dist/route/index.js +3 -0
- package/dist/route/types.d.ts +69 -0
- package/dist/route/types.js +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE } from '@uniformdev/canvas';
|
|
2
|
+
import { ProjectMapClient } from '@uniformdev/project-map';
|
|
3
|
+
import { RedirectClient } from '@uniformdev/redirect';
|
|
4
|
+
/**
|
|
5
|
+
* Finds redirect definitions that are children of a given path.
|
|
6
|
+
*/
|
|
7
|
+
async function findChildRedirects(allRedirects, parentPath) {
|
|
8
|
+
const children = [];
|
|
9
|
+
let redirect = await allRedirects.next();
|
|
10
|
+
while (!redirect.done) {
|
|
11
|
+
const index = parentPath ? redirect.value.redirect.sourceUrl.indexOf(parentPath) : 0;
|
|
12
|
+
if (index > -1) {
|
|
13
|
+
children.push(redirect.value);
|
|
14
|
+
}
|
|
15
|
+
redirect = await allRedirects.next();
|
|
16
|
+
}
|
|
17
|
+
return children;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a SvelteKit entries function for prerendering routes from the project map.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // In +page.server.ts with [...path] route
|
|
24
|
+
* import { createUniformEntries } from '@uniformdev/canvas-sveltekit/route';
|
|
25
|
+
*
|
|
26
|
+
* export const prerender = true;
|
|
27
|
+
* export const entries = createUniformEntries();
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // With custom options
|
|
31
|
+
* export const entries = createUniformEntries({
|
|
32
|
+
* rootPath: '/blog',
|
|
33
|
+
* prefix: '/blog',
|
|
34
|
+
* preview: false,
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
export function createUniformEntries(options) {
|
|
38
|
+
return async function entries() {
|
|
39
|
+
const projectMapId = options?.projectMapId ?? process.env.UNIFORM_PROJECT_MAP_ID;
|
|
40
|
+
const projectMapClient = options?.client ??
|
|
41
|
+
new ProjectMapClient({
|
|
42
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
43
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
44
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
45
|
+
});
|
|
46
|
+
const redirectClient = options?.redirectClient ??
|
|
47
|
+
new RedirectClient({
|
|
48
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
49
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
50
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
51
|
+
});
|
|
52
|
+
const [response, redirectResponse] = await Promise.all([
|
|
53
|
+
projectMapClient.getNodes({
|
|
54
|
+
...options?.requestOptions,
|
|
55
|
+
path: options?.rootPath,
|
|
56
|
+
projectMapId: projectMapId,
|
|
57
|
+
state: options?.preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE,
|
|
58
|
+
}),
|
|
59
|
+
redirectClient.getAllRedirects(),
|
|
60
|
+
]);
|
|
61
|
+
const nodes = options?.callback ? await options.callback(response.nodes) : response.nodes;
|
|
62
|
+
const redirectSources = (await findChildRedirects(redirectResponse, options?.rootPath)).map((r) => r.redirect.sourceUrl);
|
|
63
|
+
const paths = nodes
|
|
64
|
+
?.filter((node) => Boolean(node.compositionId))
|
|
65
|
+
.map((node) => `${options?.prefix ?? ''}${node.path}`) ?? [];
|
|
66
|
+
// Convert paths to SvelteKit entry format
|
|
67
|
+
// For [...path] routes, strip the leading slash
|
|
68
|
+
return [...paths, ...redirectSources].map((path) => ({
|
|
69
|
+
path: path.startsWith('/') ? path.slice(1) : path,
|
|
70
|
+
}));
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ServerLoadEvent } from '@sveltejs/kit';
|
|
2
|
+
import { type RootComponentInstance } from '@uniformdev/canvas';
|
|
3
|
+
import type { CreateUniformLoadOptions } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Result type for the load function.
|
|
6
|
+
*/
|
|
7
|
+
export type UniformLoadResult = {
|
|
8
|
+
data: RootComponentInstance;
|
|
9
|
+
matchedRoute: string;
|
|
10
|
+
dynamicInputs: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Creates a SvelteKit load function that fetches compositions from the Uniform Route API.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // In +page.server.ts
|
|
17
|
+
* import { createUniformLoad } from '@uniformdev/canvas-sveltekit/route';
|
|
18
|
+
*
|
|
19
|
+
* export const load = createUniformLoad({
|
|
20
|
+
* param: 'path', // matches [...path] route param
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // With custom options
|
|
25
|
+
* export const load = createUniformLoad({
|
|
26
|
+
* param: 'slug',
|
|
27
|
+
* silent: true,
|
|
28
|
+
* requestOptions: {
|
|
29
|
+
* skipEnhance: false,
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
export declare function createUniformLoad(options?: CreateUniformLoadOptions): (event: ServerLoadEvent) => Promise<UniformLoadResult>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { error, redirect } from '@sveltejs/kit';
|
|
2
|
+
import { CANVAS_DRAFT_STATE } from '@uniformdev/canvas';
|
|
3
|
+
import { getTargetVariableExpandedUrl } from '@uniformdev/redirect';
|
|
4
|
+
import { resolvePathFromParams } from '../helpers/resolvePathFromParams.js';
|
|
5
|
+
import { getPreviewData } from '../preview/previewCookie.js';
|
|
6
|
+
import { createRouteFetcher } from './createRouteFetcher.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a SvelteKit load function that fetches compositions from the Uniform Route API.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // In +page.server.ts
|
|
12
|
+
* import { createUniformLoad } from '@uniformdev/canvas-sveltekit/route';
|
|
13
|
+
*
|
|
14
|
+
* export const load = createUniformLoad({
|
|
15
|
+
* param: 'path', // matches [...path] route param
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // With custom options
|
|
20
|
+
* export const load = createUniformLoad({
|
|
21
|
+
* param: 'slug',
|
|
22
|
+
* silent: true,
|
|
23
|
+
* requestOptions: {
|
|
24
|
+
* skipEnhance: false,
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
export function createUniformLoad(options) {
|
|
29
|
+
const defaultHandleRedirect = (requestUrl, matched, event) => {
|
|
30
|
+
if (matched.redirect.targetStatusCode > 400) {
|
|
31
|
+
error(404, 'Not Found');
|
|
32
|
+
}
|
|
33
|
+
const absoluteUrl = `${event.url.protocol}//${event.url.host}${requestUrl}`;
|
|
34
|
+
const destination = getTargetVariableExpandedUrl(absoluteUrl, matched.redirect);
|
|
35
|
+
redirect(matched.redirect.targetStatusCode, destination);
|
|
36
|
+
};
|
|
37
|
+
const defaultHandleNotFound = () => {
|
|
38
|
+
error(404, 'Not Found');
|
|
39
|
+
};
|
|
40
|
+
const defaultHandleComposition = async (matched) => {
|
|
41
|
+
return {
|
|
42
|
+
data: matched.compositionApiResponse.composition,
|
|
43
|
+
matchedRoute: matched.matchedRoute,
|
|
44
|
+
dynamicInputs: matched.dynamicInputs ?? {},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const routeFetcher = createRouteFetcher({
|
|
48
|
+
...options,
|
|
49
|
+
defaultHandleComposition,
|
|
50
|
+
defaultHandleNotFound,
|
|
51
|
+
defaultHandleRedirect,
|
|
52
|
+
parseContext(event) {
|
|
53
|
+
const previewData = getPreviewData(event.cookies);
|
|
54
|
+
return {
|
|
55
|
+
contextualEditingCompositionId: previewData?.isUniformContextualEditing
|
|
56
|
+
? previewData?.compositionId
|
|
57
|
+
: undefined,
|
|
58
|
+
contextualEditingPath: previewData?.isUniformContextualEditing
|
|
59
|
+
? previewData?.compositionPath
|
|
60
|
+
: undefined,
|
|
61
|
+
resolvedUrl: resolvePathFromParams({
|
|
62
|
+
params: event.params,
|
|
63
|
+
param: options?.param ?? 'path',
|
|
64
|
+
}),
|
|
65
|
+
// Auto-engage draft content when in preview mode
|
|
66
|
+
defaultFetchState: previewData ? CANVAS_DRAFT_STATE : undefined,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
return routeFetcher;
|
|
71
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ServerLoadEvent } from '@sveltejs/kit';
|
|
2
|
+
import type { RootComponentInstance, RouteClient, RouteGetParameters, RouteGetResponseEdgehancedComposition, RouteGetResponseNotFound, RouteGetResponseRedirect } from '@uniformdev/canvas';
|
|
3
|
+
/**
|
|
4
|
+
* Handler function for composition route responses.
|
|
5
|
+
*/
|
|
6
|
+
export type HandleRouteCompositionFunction<TContext, TResult> = (composition: RouteGetResponseEdgehancedComposition, context: TContext, defaultHandler: (composition: RouteGetResponseEdgehancedComposition) => Promise<TResult | null> | TResult | null, duration: number) => Promise<TResult | null> | TResult | null;
|
|
7
|
+
/**
|
|
8
|
+
* Handler function for not found route responses.
|
|
9
|
+
*/
|
|
10
|
+
export type HandleRouteNotFoundFunction<TContext, TResult> = (result: RouteGetResponseNotFound, context: TContext, defaultHandler: (result: RouteGetResponseNotFound) => TResult, duration: number) => TResult;
|
|
11
|
+
/**
|
|
12
|
+
* Handler function for redirect route responses.
|
|
13
|
+
*/
|
|
14
|
+
export type HandleRouteRedirectFunction<TContext, TResult> = (requestUrl: string, redirect: RouteGetResponseRedirect, context: TContext, defaultHandler: (redirect: RouteGetResponseRedirect) => TResult, duration: number) => TResult;
|
|
15
|
+
/**
|
|
16
|
+
* Options for configuring route handling behavior.
|
|
17
|
+
*/
|
|
18
|
+
export type RouteHandlerOptions<TContext, TResult, TSuccessResult> = {
|
|
19
|
+
/** Override the default RouteClient instance */
|
|
20
|
+
client?: RouteClient;
|
|
21
|
+
/** Strip this prefix from the resolved URL before fetching */
|
|
22
|
+
prefix?: string;
|
|
23
|
+
/** Modify the path before passing to the API */
|
|
24
|
+
modifyPath?: (path: string, context: TContext) => string;
|
|
25
|
+
/** The project map ID to use. Defaults to UNIFORM_PROJECT_MAP_ID env var */
|
|
26
|
+
projectMapId?: string;
|
|
27
|
+
/** Override getRoute request parameters */
|
|
28
|
+
requestOptions?: Partial<RouteGetParameters> | ((context: TContext) => Partial<RouteGetParameters>);
|
|
29
|
+
/** Disable logging of response information and timings */
|
|
30
|
+
silent?: boolean;
|
|
31
|
+
/** Override handling of a composition route response. Return null to signal not found. */
|
|
32
|
+
handleComposition?: HandleRouteCompositionFunction<TContext, TSuccessResult>;
|
|
33
|
+
/** Override handling of a redirect route response */
|
|
34
|
+
handleRedirect?: HandleRouteRedirectFunction<TContext, TResult>;
|
|
35
|
+
/** Override handling of a not found route response */
|
|
36
|
+
handleNotFound?: HandleRouteNotFoundFunction<TContext, TResult>;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Options for creating a SvelteKit load function.
|
|
40
|
+
*/
|
|
41
|
+
export type CreateUniformLoadOptions = RouteHandlerOptions<ServerLoadEvent, never, {
|
|
42
|
+
data: RootComponentInstance;
|
|
43
|
+
matchedRoute: string;
|
|
44
|
+
dynamicInputs: Record<string, string>;
|
|
45
|
+
}> & {
|
|
46
|
+
/** Name of the route parameter containing the path segments (default: 'path') */
|
|
47
|
+
param?: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Options for creating a SvelteKit entries function.
|
|
51
|
+
*/
|
|
52
|
+
export type CreateUniformEntriesOptions = {
|
|
53
|
+
/** The project map ID to use */
|
|
54
|
+
projectMapId?: string;
|
|
55
|
+
/** Starting path to fetch nodes from */
|
|
56
|
+
rootPath?: string;
|
|
57
|
+
/** Prefix to prepend to paths returned by the project map */
|
|
58
|
+
prefix?: string;
|
|
59
|
+
/** Include draft compositions */
|
|
60
|
+
preview?: boolean;
|
|
61
|
+
/** Override getNodes request parameters */
|
|
62
|
+
requestOptions?: Partial<import('@uniformdev/project-map').ProjectMapNodeGetRequest>;
|
|
63
|
+
/** Modify the list of nodes before building paths */
|
|
64
|
+
callback?: (nodes: import('@uniformdev/project-map').ProjectMapNodeGetResponse['nodes']) => Promise<import('@uniformdev/project-map').ProjectMapNodeGetResponse['nodes']>;
|
|
65
|
+
/** Override the default ProjectMapClient instance */
|
|
66
|
+
client?: import('@uniformdev/project-map').ProjectMapClient;
|
|
67
|
+
/** Override the default RedirectClient instance */
|
|
68
|
+
redirectClient?: import('@uniformdev/redirect').RedirectClient;
|
|
69
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uniformdev/canvas-sveltekit",
|
|
3
|
+
"version": "20.48.1-alpha.17+0e73d5d0a0",
|
|
4
|
+
"description": "SvelteKit SDK for Uniform Canvas",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite dev",
|
|
8
|
+
"build": "vite build && npm run prepack",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"prepare": "svelte-kit sync || echo ''",
|
|
11
|
+
"prepack": "svelte-kit sync && svelte-package && publint",
|
|
12
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
13
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"!dist/**/*.test.*",
|
|
18
|
+
"!dist/**/*.spec.*"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": [
|
|
21
|
+
"**/*.css"
|
|
22
|
+
],
|
|
23
|
+
"svelte": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"svelte": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./route": {
|
|
32
|
+
"types": "./dist/route/index.d.ts",
|
|
33
|
+
"svelte": "./dist/route/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./preview": {
|
|
36
|
+
"types": "./dist/preview/index.d.ts",
|
|
37
|
+
"svelte": "./dist/preview/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@sveltejs/kit": "^2.0.0",
|
|
42
|
+
"svelte": "^5.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@uniformdev/canvas": "20.48.1-alpha.17+0e73d5d0a0",
|
|
46
|
+
"@uniformdev/canvas-svelte": "20.48.1-alpha.17+0e73d5d0a0",
|
|
47
|
+
"@uniformdev/context": "20.48.1-alpha.17+0e73d5d0a0",
|
|
48
|
+
"@uniformdev/project-map": "20.48.1-alpha.17+0e73d5d0a0",
|
|
49
|
+
"@uniformdev/redirect": "20.48.1-alpha.17+0e73d5d0a0",
|
|
50
|
+
"@uniformdev/richtext": "20.48.1-alpha.17+0e73d5d0a0",
|
|
51
|
+
"colorette": "2.0.20"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@sveltejs/adapter-auto": "^7.0.0",
|
|
55
|
+
"@sveltejs/adapter-vercel": "^5.7.2",
|
|
56
|
+
"@sveltejs/kit": "^2.49.1",
|
|
57
|
+
"@sveltejs/package": "^2.5.7",
|
|
58
|
+
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
|
59
|
+
"publint": "^0.3.15",
|
|
60
|
+
"svelte": "^5.45.6",
|
|
61
|
+
"svelte-check": "^4.3.4",
|
|
62
|
+
"typescript": "^5.9.3",
|
|
63
|
+
"vite": "^7.2.6"
|
|
64
|
+
},
|
|
65
|
+
"keywords": [
|
|
66
|
+
"svelte",
|
|
67
|
+
"sveltekit",
|
|
68
|
+
"uniform",
|
|
69
|
+
"canvas"
|
|
70
|
+
],
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"gitHead": "0e73d5d0a0289425228453d1107da1fa198d5d3a"
|
|
75
|
+
}
|