@wervt/cms 0.0.1 → 0.0.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.
Files changed (45) hide show
  1. package/README.md +136 -13
  2. package/dist/editor/assets/Button-BHCKwuIs.js +6 -0
  3. package/dist/editor/assets/RichTextInput-DHmilx6T.js +271 -0
  4. package/dist/editor/assets/Toast-pKrAdYOo.js +13 -0
  5. package/dist/editor/assets/index-JJD_O40W.js +16 -0
  6. package/dist/editor/assets/index-kXxO7vu1.css +2 -0
  7. package/dist/editor/assets/poppins-latin-400-normal-BOb3E3N0.woff +0 -0
  8. package/dist/editor/assets/poppins-latin-400-normal-cpxAROuN.woff2 +0 -0
  9. package/dist/editor/assets/poppins-latin-500-normal-C8OXljZJ.woff2 +0 -0
  10. package/dist/editor/assets/poppins-latin-500-normal-DGXqpDMm.woff +0 -0
  11. package/dist/editor/assets/poppins-latin-600-normal-BJdTmd5m.woff +0 -0
  12. package/dist/editor/assets/poppins-latin-600-normal-zEkxB9Mr.woff2 +0 -0
  13. package/dist/editor/index.html +15 -0
  14. package/dist/editor-theme.d.ts +28 -0
  15. package/dist/editor-theme.js +62 -0
  16. package/dist/module.d.ts +6 -1
  17. package/dist/module.js +97 -11
  18. package/dist/runtime/app/CmsRichText.d.ts +15 -0
  19. package/dist/runtime/app/CmsRichText.js +48 -0
  20. package/dist/runtime/app/useCms.d.ts +9 -2
  21. package/dist/runtime/app/useCms.js +11 -5
  22. package/dist/runtime/fields.d.ts +24 -0
  23. package/dist/runtime/fields.js +109 -0
  24. package/dist/runtime/pages.d.ts +3 -0
  25. package/dist/runtime/pages.js +14 -0
  26. package/dist/runtime/schema.d.ts +108 -0
  27. package/dist/runtime/schema.js +74 -0
  28. package/dist/runtime/server/access.js +1 -1
  29. package/dist/runtime/server/dev-images.d.ts +2 -0
  30. package/dist/runtime/server/dev-images.js +12 -0
  31. package/dist/runtime/server/editor.get.d.ts +2 -0
  32. package/dist/runtime/server/editor.get.js +9 -0
  33. package/dist/runtime/server/entry.get.d.ts +7 -2
  34. package/dist/runtime/server/entry.get.js +11 -1
  35. package/dist/runtime/server/entry.put.js +14 -1
  36. package/dist/runtime/server/images.d.ts +4 -0
  37. package/dist/runtime/server/images.js +30 -0
  38. package/dist/runtime/server/schema.get.d.ts +10 -0
  39. package/dist/runtime/server/schema.get.js +10 -0
  40. package/dist/runtime/server/sniff.d.ts +11 -0
  41. package/dist/runtime/server/sniff.js +53 -0
  42. package/dist/runtime/server/upload.post.d.ts +13 -0
  43. package/dist/runtime/server/upload.post.js +44 -0
  44. package/package.json +29 -5
  45. package/dist/runtime/app/editor.vue +0 -32
@@ -0,0 +1,2 @@
1
+ /** Writes the image and returns the path the app serves it at. */
2
+ export declare function saveDevImage(publicDir: string, data: Uint8Array, extension: string): Promise<string>;
@@ -0,0 +1,12 @@
1
+ import { join } from "node:path";
2
+ import { randomUUID } from "node:crypto";
3
+ import { mkdir, writeFile } from "node:fs/promises";
4
+ // src/runtime/server/dev-images.ts
5
+ /** Writes the image and returns the path the app serves it at. */
6
+ async function saveDevImage(publicDir, data, extension) {
7
+ const name = `${randomUUID()}.${extension}`;
8
+ await mkdir(join(publicDir, "cms"), { recursive: true });
9
+ await writeFile(join(publicDir, "cms", name), data);
10
+ return `/cms/${name}`;
11
+ }
12
+ export { saveDevImage };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/server").EventHandler<Response>;
2
+ export { _default as default };
@@ -0,0 +1,9 @@
1
+ import { defineEventHandler } from "nuxt/server";
2
+ import { html } from "#wervt-cms/editor";
3
+ // src/runtime/server/editor.get.ts
4
+ var editor_get_default = defineEventHandler(() => new Response(html, { headers: {
5
+ "content-type": "text/html; charset=utf-8",
6
+ "cache-control": "no-cache",
7
+ "x-robots-tag": "noindex"
8
+ } }));
9
+ export { editor_get_default as default };
@@ -1,3 +1,8 @@
1
- import { CmsEntry } from "./entries.js";
2
- declare const _default: import("nuxt/server").EventHandler<Promise<CmsEntry | null>>;
1
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
2
+ key: string;
3
+ value: {
4
+ [x: string]: unknown;
5
+ };
6
+ updatedAt: string | null;
7
+ } | null>>;
3
8
  export { _default as default };
@@ -1,4 +1,7 @@
1
1
  import { isEntryKey } from "./entries.js";
2
+ import { resolveValue } from "../fields.js";
3
+ import { pages } from "../pages.js";
4
+ import { serverImages } from "./images.js";
2
5
  import { readEntry } from "./store.js";
3
6
  import { createError, defineEventHandler, getRouterParam } from "nuxt/server";
4
7
  // src/runtime/server/entry.get.ts
@@ -8,6 +11,13 @@ var entry_get_default = defineEventHandler(async (event) => {
8
11
  status: 400,
9
12
  message: "Invalid key"
10
13
  });
11
- return await readEntry(key) ?? null;
14
+ const entry = await readEntry(key);
15
+ const page = pages.get(key);
16
+ if (!page) return entry ?? null;
17
+ return {
18
+ key,
19
+ value: resolveValue(page.fields, entry?.value, serverImages),
20
+ updatedAt: entry?.updatedAt ?? null
21
+ };
12
22
  });
13
23
  export { entry_get_default as default };
@@ -1,4 +1,6 @@
1
1
  import { isEntryKey } from "./entries.js";
2
+ import { InvalidValue, normalizeValue } from "../fields.js";
3
+ import { pages } from "../pages.js";
2
4
  import { requireEditor } from "./access.js";
3
5
  import { writeEntry } from "./store.js";
4
6
  import { createError, defineEventHandler, getRouterParam, readBody } from "nuxt/server";
@@ -15,7 +17,18 @@ var entry_put_default = defineEventHandler(async (event) => {
15
17
  status: 400,
16
18
  message: "Expected an object"
17
19
  });
18
- await writeEntry(key, body);
20
+ const page = pages.get(key);
21
+ let value = body;
22
+ try {
23
+ if (page) value = normalizeValue(page.fields, body);
24
+ } catch (error) {
25
+ if (error instanceof InvalidValue) throw createError({
26
+ status: 400,
27
+ message: error.message
28
+ });
29
+ throw error;
30
+ }
31
+ await writeEntry(key, value);
19
32
  return { ok: true };
20
33
  });
21
34
  export { entry_put_default as default };
@@ -0,0 +1,4 @@
1
+ import { ImageResolver } from "../fields.js";
2
+ /** The bucket group uploads go to. */
3
+ export declare const IMAGE_GROUP = "cms";
4
+ export declare const serverImages: ImageResolver;
@@ -0,0 +1,30 @@
1
+ import { staticImages } from "../fields.js";
2
+ import { imageUrl } from "@wervt/nuxt/server";
3
+ // src/runtime/server/images.ts
4
+ /** The bucket group uploads go to. */
5
+ const IMAGE_GROUP = "cms";
6
+ const WIDTHS = [
7
+ 640,
8
+ 1024,
9
+ 1600,
10
+ 2400
11
+ ];
12
+ const serverImages = (image) => {
13
+ if ("src" in image) return staticImages(image);
14
+ const file = {
15
+ group: "cms",
16
+ id: image.id
17
+ };
18
+ try {
19
+ return {
20
+ id: image.id,
21
+ alt: image.alt ?? "",
22
+ src: imageUrl(file, { width: 1600 }),
23
+ srcset: WIDTHS.map((width) => `${imageUrl(file, { width })} ${width}w`).join(", ")
24
+ };
25
+ } catch (error) {
26
+ console.error(`[cms] can't show image ${image.id}:`, error);
27
+ return;
28
+ }
29
+ };
30
+ export { IMAGE_GROUP, serverImages };
@@ -0,0 +1,10 @@
1
+ import { CmsFields } from "../schema.js";
2
+ declare const _default: import("nuxt/server").EventHandler<{
3
+ pages: {
4
+ key: string;
5
+ label: string | undefined;
6
+ path: string | undefined;
7
+ fields: CmsFields;
8
+ }[];
9
+ }>;
10
+ export { _default as default };
@@ -0,0 +1,10 @@
1
+ import { pages } from "../pages.js";
2
+ import { defineEventHandler } from "nuxt/server";
3
+ // src/runtime/server/schema.get.ts
4
+ var schema_get_default = defineEventHandler(() => ({ pages: [...pages.values()].map(({ key, label, path, fields }) => ({
5
+ key,
6
+ label,
7
+ path,
8
+ fields
9
+ })) }));
10
+ export { schema_get_default as default };
@@ -0,0 +1,11 @@
1
+ export interface SniffedImage {
2
+ type: string;
3
+ extension: string;
4
+ /** Shown by every browser as a plain file, without the image service. */
5
+ browserSafe: boolean;
6
+ }
7
+ /**
8
+ * The image type the bytes start with. What the browser claims counts for nothing: the file is
9
+ * served from the app's own origin, so an SVG (or HTML calling itself an image) could run script.
10
+ */
11
+ export declare function sniffImage(data: Uint8Array): SniffedImage | undefined;
@@ -0,0 +1,53 @@
1
+ // src/runtime/server/sniff.ts
2
+ const ascii = (data, start, end) => String.fromCharCode(...data.subarray(start, end));
3
+ const HEIF_BRANDS = /* @__PURE__ */ new Set([
4
+ "heic",
5
+ "heix",
6
+ "heim",
7
+ "heis",
8
+ "hevc",
9
+ "hevx",
10
+ "mif1",
11
+ "msf1"
12
+ ]);
13
+ /**
14
+ * The image type the bytes start with. What the browser claims counts for nothing: the file is
15
+ * served from the app's own origin, so an SVG (or HTML calling itself an image) could run script.
16
+ */
17
+ function sniffImage(data) {
18
+ if (data.length < 12) return void 0;
19
+ if (data[0] === 255 && data[1] === 216 && data[2] === 255) return {
20
+ type: "image/jpeg",
21
+ extension: "jpg",
22
+ browserSafe: true
23
+ };
24
+ if (ascii(data, 0, 8) === "‰PNG\r\n\n") return {
25
+ type: "image/png",
26
+ extension: "png",
27
+ browserSafe: true
28
+ };
29
+ if (ascii(data, 0, 6) === "GIF87a" || ascii(data, 0, 6) === "GIF89a") return {
30
+ type: "image/gif",
31
+ extension: "gif",
32
+ browserSafe: true
33
+ };
34
+ if (ascii(data, 0, 4) === "RIFF" && ascii(data, 8, 12) === "WEBP") return {
35
+ type: "image/webp",
36
+ extension: "webp",
37
+ browserSafe: true
38
+ };
39
+ if (ascii(data, 4, 8) === "ftyp") {
40
+ const brand = ascii(data, 8, 12);
41
+ if (brand === "avif" || brand === "avis") return {
42
+ type: "image/avif",
43
+ extension: "avif",
44
+ browserSafe: true
45
+ };
46
+ if (HEIF_BRANDS.has(brand)) return {
47
+ type: "image/heic",
48
+ extension: "heic",
49
+ browserSafe: false
50
+ };
51
+ }
52
+ }
53
+ export { sniffImage };
@@ -0,0 +1,13 @@
1
+ import { CmsImage } from "../schema.js";
2
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
3
+ value: {
4
+ src: string;
5
+ };
6
+ image: CmsImage | undefined;
7
+ } | {
8
+ value: {
9
+ id: string;
10
+ };
11
+ image: CmsImage | null;
12
+ }>>;
13
+ export { _default as default };
@@ -0,0 +1,44 @@
1
+ import { staticImages } from "../fields.js";
2
+ import { requireEditor } from "./access.js";
3
+ import { serverImages } from "./images.js";
4
+ import { sniffImage } from "./sniff.js";
5
+ import { createError, defineEventHandler } from "nuxt/server";
6
+ import { randomUUID } from "node:crypto";
7
+ import { publicDir } from "#wervt-cms/entries";
8
+ import { readUploadedFile, useFileStorage } from "#imports";
9
+ // src/runtime/server/upload.post.ts
10
+ var upload_post_default = defineEventHandler(async (event) => {
11
+ requireEditor(event);
12
+ const devDir = import.meta.dev ? publicDir : void 0;
13
+ const upload = await readUploadedFile(event, {
14
+ types: ["image"],
15
+ maxSize: devDir ? "5MB" : "25MB"
16
+ });
17
+ const sniffed = sniffImage(upload.data);
18
+ if (!sniffed) throw createError({
19
+ status: 415,
20
+ message: "Use a JPEG, PNG, WebP, GIF, AVIF or HEIC image"
21
+ });
22
+ if (devDir) {
23
+ if (!sniffed.browserSafe) throw createError({
24
+ status: 415,
25
+ message: "Use a JPEG, PNG, WebP, GIF or AVIF image"
26
+ });
27
+ const { saveDevImage } = await import("./dev-images.js");
28
+ const value = { src: await saveDevImage(devDir, upload.data, sniffed.extension) };
29
+ return {
30
+ value,
31
+ image: staticImages(value)
32
+ };
33
+ }
34
+ const { id } = await useFileStorage().put("cms", upload.data, {
35
+ contentType: sniffed.type,
36
+ name: `${randomUUID()}.${sniffed.extension}`
37
+ });
38
+ const value = { id };
39
+ return {
40
+ value,
41
+ image: serverImages(value) ?? null
42
+ };
43
+ });
44
+ export { upload_post_default as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wervt/cms",
3
- "version": "0.0.1",
4
- "description": "Editable texts for Nuxt sites on wervt: written to a file in dev, to the app's database once deployed.",
3
+ "version": "0.0.3",
4
+ "description": "Editable texts, images and lists for Nuxt sites on wervt: written to files in dev, to the app's database and bucket once deployed.",
5
5
  "keywords": [
6
6
  "cms",
7
7
  "nuxt",
@@ -25,21 +25,45 @@
25
25
  ".": {
26
26
  "types": "./dist/module.d.ts",
27
27
  "default": "./dist/module.js"
28
+ },
29
+ "./schema": {
30
+ "types": "./dist/runtime/schema.d.ts",
31
+ "default": "./dist/runtime/schema.js"
28
32
  }
29
33
  },
30
34
  "dependencies": {
31
- "@wervt/nuxt": "^0.3.23"
35
+ "@comark/vue": "^0.8.1",
36
+ "@wervt/nuxt": "^0.3.24",
37
+ "ablage": "^0.1.1",
38
+ "comark": "^0.8.1"
32
39
  },
33
40
  "devDependencies": {
41
+ "@fontsource/poppins": "^5.3.0",
42
+ "@golar/vue": "^0.1.11",
43
+ "@iconify-json/lucide": "^1.2.157",
44
+ "@iconify/vue": "^5.0.3",
45
+ "@nuxt/ui": "^4.12.0",
46
+ "@tiptap/core": "3.31.4",
47
+ "@tiptap/extension-image": "3.31.4",
48
+ "@tiptap/extension-list": "3.31.4",
49
+ "@tiptap/extension-table": "3.31.4",
50
+ "@tiptap/pm": "3.31.4",
51
+ "@tiptap/starter-kit": "3.31.4",
52
+ "@tiptap/vue-3": "3.31.4",
53
+ "@vitejs/plugin-vue": "^6.0.11",
54
+ "comark-ui": "^0.8.1",
34
55
  "drizzle-orm": "1.0.0-rc.5",
56
+ "golar": "^0.1.11",
35
57
  "nuxt": "npm:nuxt-nightly@5x",
58
+ "tailwindcss": "^4.3.3",
36
59
  "vue": "^3.5.45"
37
60
  },
38
61
  "peerDependencies": {
39
62
  "drizzle-orm": ">=1.0.0-rc.5 <2",
40
- "nuxt": ">=4.2"
63
+ "nuxt": ">=4.6"
41
64
  },
42
65
  "scripts": {
43
- "build": "vp pack"
66
+ "build": "vp pack && vp build editor",
67
+ "typecheck": "vp build editor && cd editor && golar typecheck"
44
68
  }
45
69
  }
@@ -1,32 +0,0 @@
1
- <script setup lang="ts">
2
- import { ref, watch } from 'vue'
3
- import { useFetch, useRoute } from '#app'
4
-
5
- const key = String(useRoute().query.key ?? 'home')
6
- const { data } = await useFetch<{ value: Record<string, unknown> } | null>(
7
- `/api/_cms/entries/${key}`,
8
- )
9
- const text = ref('{}')
10
- watch(data, (entry) => (text.value = JSON.stringify(entry?.value ?? {}, null, 2)), {
11
- immediate: true,
12
- })
13
- const status = ref('')
14
-
15
- async function save() {
16
- try {
17
- await $fetch(`/api/_cms/entries/${key}`, { method: 'PUT', body: JSON.parse(text.value) })
18
- status.value = 'Saved'
19
- } catch (e) {
20
- status.value = (e as { data?: { message?: string } }).data?.message ?? String(e)
21
- }
22
- }
23
- </script>
24
-
25
- <template>
26
- <main style="max-width: 40rem; margin: 2rem auto; font-family: system-ui">
27
- <h1>Content: {{ key }}</h1>
28
- <textarea v-model="text" rows="12" style="width: 100%; font-family: monospace" />
29
- <button type="button" @click="save">Save</button>
30
- <p data-testid="status">{{ status }}</p>
31
- </main>
32
- </template>