@bettercms-ai/sveltekit 0.0.0-stage → 0.2.0
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/README.md +29 -2
- package/dist/index.d.ts +41 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -4
package/README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bettercms-ai/sveltekit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
BetterCMS for SvelteKit.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i @bettercms-ai/sveltekit
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// src/lib/bcms.ts
|
|
11
|
+
import { env as pub } from "$env/dynamic/public";
|
|
12
|
+
import { env as priv } from "$env/dynamic/private";
|
|
13
|
+
export const bcms = createBcms({ env: { ...pub, ...priv } });
|
|
14
|
+
|
|
15
|
+
// src/routes/+page.server.ts
|
|
16
|
+
export const load = async ({ fetch }) => ({ sections: await bcms.sections("home", fetch) });
|
|
17
|
+
|
|
18
|
+
// src/routes/+page.svelte
|
|
19
|
+
<div use:bcmsSections={data.sections}>{@html sectionsMarkup(data.sections)}</div>
|
|
20
|
+
|
|
21
|
+
// src/routes/api/draft/+server.ts — the path the editor's "Preview on site" opens
|
|
22
|
+
export const GET = ({ request }) => bcms.draftEnable(request);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Settings: options, then `PUBLIC_BCMS_*`, then `BCMS_*` (the same precedence as every adapter). The sections are the hosted renderer's own markup, so forms, sliders and tabs work as on a BetterCMS-hosted site; `bcmsSections` runs their scripts after a client-side navigation.
|
|
26
|
+
|
|
27
|
+
Notes:
|
|
28
|
+
|
|
29
|
+
- The sections run small inline scripts (forms, sliders, tabs). They are safe to run more than once, and the action/directive runs every `<script>` inside its element, so give it an element that holds only the sections. A Content-Security-Policy must allow inline scripts for them.
|
|
30
|
+
- Sections are the PUBLISHED page. Draft mode switches the read client (`await bcms.client(request)`) to drafts; the sections fragment shows drafts in a later release.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BcmsSite } from '@bettercms-ai/sdk/sections';
|
|
2
|
+
export { BcmsSite, SectionsFragment, sectionsMarkup } from '@bettercms-ai/sdk/sections';
|
|
3
|
+
import { BcmsSiteOptions } from '@bettercms-ai/sdk/config';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @bettercms-ai/sveltekit — BetterCMS for SvelteKit.
|
|
7
|
+
*
|
|
8
|
+
* // src/lib/bcms.ts
|
|
9
|
+
* import { env as pub } from "$env/dynamic/public";
|
|
10
|
+
* import { env as priv } from "$env/dynamic/private";
|
|
11
|
+
* export const bcms = createBcms({ env: { ...pub, ...priv } });
|
|
12
|
+
*
|
|
13
|
+
* // src/routes/+page.server.ts
|
|
14
|
+
* export const load = async ({ fetch }) => ({ sections: await bcms.sections("home", fetch) });
|
|
15
|
+
*
|
|
16
|
+
* // src/routes/+page.svelte
|
|
17
|
+
* <div use:bcmsSections={data.sections}>{@html sectionsMarkup(data.sections)}</div>
|
|
18
|
+
*
|
|
19
|
+
* // src/routes/api/draft/+server.ts — the path the editor's "Preview on site" opens
|
|
20
|
+
* export const GET = ({ request }) => bcms.draftEnable(request);
|
|
21
|
+
*
|
|
22
|
+
* Settings: options, then `PUBLIC_BCMS_*`, then `BCMS_*` (the same precedence as every adapter).
|
|
23
|
+
* The sections are the hosted renderer's own markup, so forms, sliders and tabs work as on a
|
|
24
|
+
* BetterCMS-hosted site; `bcmsSections` runs their scripts after a client-side navigation.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** Build the site's BetterCMS access from its settings (pass `{ ...publicEnv, ...privateEnv }`). */
|
|
28
|
+
declare function createBcms(options?: BcmsSiteOptions & {
|
|
29
|
+
env?: Record<string, string | undefined>;
|
|
30
|
+
draftSecret?: string;
|
|
31
|
+
}): BcmsSite;
|
|
32
|
+
/**
|
|
33
|
+
* Svelte action for the element holding `{@html sectionsMarkup(…)}`: its scripts run on every page.
|
|
34
|
+
* Pass the sections as its parameter (`use:bcmsSections={data.sections}`): Svelte calls `update`
|
|
35
|
+
* only when the parameter changes, which is how a move between two pages of one route reruns them.
|
|
36
|
+
*/
|
|
37
|
+
declare function bcmsSections(node: Element, _sections?: unknown): {
|
|
38
|
+
update(): void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { bcmsSections, createBcms };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createBcmsSite, runSectionScripts } from "@bettercms-ai/sdk/sections";
|
|
3
|
+
import { sectionsMarkup } from "@bettercms-ai/sdk/sections";
|
|
4
|
+
function createBcms(options = {}) {
|
|
5
|
+
return createBcmsSite({ ...options, prefixes: ["PUBLIC_"], adapter: "@bettercms-ai/sveltekit" });
|
|
6
|
+
}
|
|
7
|
+
function bcmsSections(node, _sections) {
|
|
8
|
+
runSectionScripts(node);
|
|
9
|
+
return { update: () => queueMicrotask(() => runSectionScripts(node)) };
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
bcmsSections,
|
|
13
|
+
createBcms,
|
|
14
|
+
sectionsMarkup
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n/**\n * @bettercms-ai/sveltekit — BetterCMS for SvelteKit.\n *\n * // src/lib/bcms.ts\n * import { env as pub } from \"$env/dynamic/public\";\n * import { env as priv } from \"$env/dynamic/private\";\n * export const bcms = createBcms({ env: { ...pub, ...priv } });\n *\n * // src/routes/+page.server.ts\n * export const load = async ({ fetch }) => ({ sections: await bcms.sections(\"home\", fetch) });\n *\n * // src/routes/+page.svelte\n * <div use:bcmsSections={data.sections}>{@html sectionsMarkup(data.sections)}</div>\n *\n * // src/routes/api/draft/+server.ts — the path the editor's \"Preview on site\" opens\n * export const GET = ({ request }) => bcms.draftEnable(request);\n *\n * Settings: options, then `PUBLIC_BCMS_*`, then `BCMS_*` (the same precedence as every adapter).\n * The sections are the hosted renderer's own markup, so forms, sliders and tabs work as on a\n * BetterCMS-hosted site; `bcmsSections` runs their scripts after a client-side navigation.\n */\nimport { createBcmsSite, runSectionScripts, type BcmsSite } from \"@bettercms-ai/sdk/sections\";\nimport type { BcmsSiteOptions } from \"@bettercms-ai/sdk/config\";\n\nexport { sectionsMarkup, type SectionsFragment, type BcmsSite } from \"@bettercms-ai/sdk/sections\";\n\n/** Build the site's BetterCMS access from its settings (pass `{ ...publicEnv, ...privateEnv }`). */\nexport function createBcms(options: BcmsSiteOptions & { env?: Record<string, string | undefined>; draftSecret?: string } = {}): BcmsSite {\n return createBcmsSite({ ...options, prefixes: [\"PUBLIC_\"], adapter: \"@bettercms-ai/sveltekit\" });\n}\n\n/**\n * Svelte action for the element holding `{@html sectionsMarkup(…)}`: its scripts run on every page.\n * Pass the sections as its parameter (`use:bcmsSections={data.sections}`): Svelte calls `update`\n * only when the parameter changes, which is how a move between two pages of one route reruns them.\n */\nexport function bcmsSections(node: Element, _sections?: unknown): { update(): void } {\n runSectionScripts(node);\n // After Svelte has written the new markup.\n return { update: () => queueMicrotask(() => runSectionScripts(node)) };\n}\n"],"mappings":";AAsBA,SAAS,gBAAgB,yBAAwC;AAGjE,SAAS,sBAA4D;AAG9D,SAAS,WAAW,UAAgG,CAAC,GAAa;AACvI,SAAO,eAAe,EAAE,GAAG,SAAS,UAAU,CAAC,SAAS,GAAG,SAAS,0BAA0B,CAAC;AACjG;AAOO,SAAS,aAAa,MAAe,WAAyC;AACnF,oBAAkB,IAAI;AAEtB,SAAO,EAAE,QAAQ,MAAM,eAAe,MAAM,kBAAkB,IAAI,CAAC,EAAE;AACvE;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettercms-ai/sveltekit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "BetterCMS for SvelteKit: settings from PUBLIC_BCMS_*, the read client per request with draft mode, the editor's draft routes, and the page sections server-rendered by BetterCMS.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@bettercms-ai/sdk": "^1.35.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"svelte": ">=4"
|
|
26
|
+
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"svelte": {
|
|
29
|
+
"optional": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"build": "tsup",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"prepublishOnly": "bun run build"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^20",
|
|
40
|
+
"tsup": "^8.5.1",
|
|
41
|
+
"typescript": "^5",
|
|
42
|
+
"vitest": "^4.1.4"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
}
|
|
48
|
+
}
|