@bettercms-ai/nuxt 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 +28 -2
- package/dist/index.d.ts +37 -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,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bettercms-ai/nuxt
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
BetterCMS for Nuxt.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i @bettercms-ai/nuxt
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// server/utils/bcms.ts
|
|
11
|
+
export const bcms = createBcms({ env: process.env });
|
|
12
|
+
|
|
13
|
+
// server/api/sections/[slug].get.ts
|
|
14
|
+
export default defineEventHandler((e) => bcms.sections(getRouterParam(e, "slug")!));
|
|
15
|
+
|
|
16
|
+
// pages/index.vue
|
|
17
|
+
const { data } = await useFetch("/api/sections/home");
|
|
18
|
+
<div v-bcms-sections v-html="sectionsMarkup(data)" />
|
|
19
|
+
|
|
20
|
+
// server/routes/api/draft.get.ts — the path the editor's "Preview on site" opens
|
|
21
|
+
export default defineEventHandler((e) => bcms.draftEnable(toWebRequest(e)));
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Settings: options, then `NUXT_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; `vBcmsSections` runs their scripts after a client-side navigation.
|
|
25
|
+
|
|
26
|
+
Notes:
|
|
27
|
+
|
|
28
|
+
- 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.
|
|
29
|
+
- 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,37 @@
|
|
|
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/nuxt — BetterCMS for Nuxt.
|
|
7
|
+
*
|
|
8
|
+
* // server/utils/bcms.ts
|
|
9
|
+
* export const bcms = createBcms({ env: process.env });
|
|
10
|
+
*
|
|
11
|
+
* // server/api/sections/[slug].get.ts
|
|
12
|
+
* export default defineEventHandler((e) => bcms.sections(getRouterParam(e, "slug")!));
|
|
13
|
+
*
|
|
14
|
+
* // pages/index.vue
|
|
15
|
+
* const { data } = await useFetch("/api/sections/home");
|
|
16
|
+
* <div v-bcms-sections v-html="sectionsMarkup(data)" />
|
|
17
|
+
*
|
|
18
|
+
* // server/routes/api/draft.get.ts — the path the editor's "Preview on site" opens
|
|
19
|
+
* export default defineEventHandler((e) => bcms.draftEnable(toWebRequest(e)));
|
|
20
|
+
*
|
|
21
|
+
* Settings: options, then `NUXT_PUBLIC_BCMS_*`, then `BCMS_*` (the same precedence as every
|
|
22
|
+
* adapter). The sections are the hosted renderer's own markup, so forms, sliders and tabs work as
|
|
23
|
+
* on a BetterCMS-hosted site; `vBcmsSections` runs their scripts after a client-side navigation.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Build the site's BetterCMS access from its settings (pass `process.env` on the server). */
|
|
27
|
+
declare function createBcms(options?: BcmsSiteOptions & {
|
|
28
|
+
env?: Record<string, string | undefined>;
|
|
29
|
+
draftSecret?: string;
|
|
30
|
+
}): BcmsSite;
|
|
31
|
+
/** Vue directive for the element holding `v-html="sectionsMarkup(…)"`: its scripts run on every page. */
|
|
32
|
+
declare const vBcmsSections: {
|
|
33
|
+
mounted: (el: Element) => void;
|
|
34
|
+
updated: (el: Element) => void;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { createBcms, vBcmsSections };
|
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: ["NUXT_PUBLIC_"], adapter: "@bettercms-ai/nuxt" });
|
|
6
|
+
}
|
|
7
|
+
var vBcmsSections = {
|
|
8
|
+
mounted: (el) => runSectionScripts(el),
|
|
9
|
+
updated: (el) => runSectionScripts(el)
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
createBcms,
|
|
13
|
+
sectionsMarkup,
|
|
14
|
+
vBcmsSections
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n/**\n * @bettercms-ai/nuxt — BetterCMS for Nuxt.\n *\n * // server/utils/bcms.ts\n * export const bcms = createBcms({ env: process.env });\n *\n * // server/api/sections/[slug].get.ts\n * export default defineEventHandler((e) => bcms.sections(getRouterParam(e, \"slug\")!));\n *\n * // pages/index.vue\n * const { data } = await useFetch(\"/api/sections/home\");\n * <div v-bcms-sections v-html=\"sectionsMarkup(data)\" />\n *\n * // server/routes/api/draft.get.ts — the path the editor's \"Preview on site\" opens\n * export default defineEventHandler((e) => bcms.draftEnable(toWebRequest(e)));\n *\n * Settings: options, then `NUXT_PUBLIC_BCMS_*`, then `BCMS_*` (the same precedence as every\n * adapter). The sections are the hosted renderer's own markup, so forms, sliders and tabs work as\n * on a BetterCMS-hosted site; `vBcmsSections` 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 `process.env` on the server). */\nexport function createBcms(options: BcmsSiteOptions & { env?: Record<string, string | undefined>; draftSecret?: string } = {}): BcmsSite {\n return createBcmsSite({ ...options, prefixes: [\"NUXT_PUBLIC_\"], adapter: \"@bettercms-ai/nuxt\" });\n}\n\n/** Vue directive for the element holding `v-html=\"sectionsMarkup(…)\"`: its scripts run on every page. */\nexport const vBcmsSections = {\n mounted: (el: Element) => runSectionScripts(el),\n updated: (el: Element) => runSectionScripts(el),\n};\n"],"mappings":";AAqBA,SAAS,gBAAgB,yBAAwC;AAGjE,SAAS,sBAA4D;AAG9D,SAAS,WAAW,UAAgG,CAAC,GAAa;AACvI,SAAO,eAAe,EAAE,GAAG,SAAS,UAAU,CAAC,cAAc,GAAG,SAAS,qBAAqB,CAAC;AACjG;AAGO,IAAM,gBAAgB;AAAA,EAC3B,SAAS,CAAC,OAAgB,kBAAkB,EAAE;AAAA,EAC9C,SAAS,CAAC,OAAgB,kBAAkB,EAAE;AAChD;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettercms-ai/nuxt",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "BetterCMS for Nuxt: settings from NUXT_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
|
+
"vue": ">=3"
|
|
26
|
+
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"vue": {
|
|
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
|
+
}
|