nuxt-atelier 0.1.0 → 0.1.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Nuxt Atelier
2
2
 
3
- [![npm](https://img.shields.io/npm/v/nuxt-atelier/next?label=npm&color=cb3837)](https://www.npmjs.com/package/nuxt-atelier)
3
+ [![npm](https://img.shields.io/npm/v/nuxt-atelier?label=npm&color=cb3837)](https://www.npmjs.com/package/nuxt-atelier)
4
4
  [![JSR](https://jsr.io/badges/@nuxt-atelier/core)](https://jsr.io/@nuxt-atelier/core)
5
5
  [![JSR score](https://jsr.io/badges/@nuxt-atelier/core/score)](https://jsr.io/@nuxt-atelier/core)
6
6
  [![CI](https://github.com/AnoRebel/nuxt-atelier/actions/workflows/ci.yml/badge.svg)](https://github.com/AnoRebel/nuxt-atelier/actions/workflows/ci.yml)
@@ -10,7 +10,7 @@ A production-grade CMS for Nuxt with a visual page builder that renders your sit
10
10
 
11
11
  **[Documentation](https://nuxt-atelier.anorebel.net)** · **[Live demo](https://nuxt-atelier-demo.anorebel.net)** (Rayleigh, a portfolio built on Nuxt Atelier; each visitor gets their own copy to edit)
12
12
 
13
- > **Status:** early development. Nothing is published yet; APIs will change until `1.0.0`.
13
+ > **Status:** early development, released on npm and JSR. APIs will change until `1.0.0`.
14
14
 
15
15
  ## What it is
16
16
 
package/dist/module.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "nuxt": ">=4.6.0",
6
6
  "server": "nuxt"
7
7
  },
8
- "version": "0.1.0",
8
+ "version": "0.1.1",
9
9
  "builder": {
10
10
  "@nuxt/module-builder": "1.0.3",
11
11
  "unbuild": "unknown"
@@ -3,6 +3,7 @@ import { useForm } from "@tanstack/vue-form";
3
3
  import { computed, onMounted, ref, useId } from "vue";
4
4
  import { navigateTo, useFetch } from "#imports";
5
5
  import { optionsOf, submissionSchema } from "../../shared/forms";
6
+ import { csrfHeaders } from "../csrf";
6
7
  const props = defineProps({
7
8
  form: { type: String, required: true },
8
9
  locale: { type: String, required: false }
@@ -41,7 +42,7 @@ const form = useForm({
41
42
  } else {
42
43
  body = JSON.stringify({ ...value, ...extra });
43
44
  }
44
- const response = await fetch(`/api/_atelier/forms/${encodeURIComponent(props.form)}/submit`, { method: "POST", body, headers: withFiles ? {} : { "content-type": "application/json" } });
45
+ const response = await fetch(`/api/_atelier/forms/${encodeURIComponent(props.form)}/submit`, { method: "POST", body, headers: { ...withFiles ? {} : { "content-type": "application/json" }, ...csrfHeaders() } });
45
46
  const result = await response.json().catch(() => ({}));
46
47
  if (response.status === 422 && result.data?.errors) {
47
48
  for (const { path, message } of result.data.errors)
@@ -64,8 +64,8 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
64
64
  }>> & Readonly<{}>, {
65
65
  alt: string;
66
66
  locale: string;
67
- format: ImageFormat;
68
67
  loading: "lazy" | "eager";
68
+ format: ImageFormat;
69
69
  ratio: ImageRatio;
70
70
  sizes: string;
71
71
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -19,9 +19,9 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
19
19
  type: StringConstructor;
20
20
  default: undefined;
21
21
  };
22
- }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
22
+ }>, () => import("vue").VNodeChild[] | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
23
23
  [key: string]: any;
24
- }> | import("vue").VNodeChild[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
24
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
25
25
  value: {
26
26
  type: PropType<RichTextNode | null>;
27
27
  default: null;
@@ -41,9 +41,9 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
41
41
  default: undefined;
42
42
  };
43
43
  }>> & Readonly<{}>, {
44
- value: RichTextNode | null;
45
44
  field: string;
46
- as: string | false;
45
+ value: RichTextNode | null;
47
46
  components: Record<string, Component>;
47
+ as: string | false;
48
48
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
49
49
  export default _default;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The `x-atelier-csrf` header a signed-in browser sends with writes to the CMS API: the `atelier-csrf`
3
+ * cookie's value (none when no one is signed in). Pages send it too, so editors can use the site's forms.
4
+ */
5
+ export declare function csrfHeaders(): Record<string, string>;
@@ -0,0 +1,4 @@
1
+ export function csrfHeaders() {
2
+ const csrf = document.cookie.split("; ").find((c) => c.startsWith("atelier-csrf="))?.slice("atelier-csrf=".length);
3
+ return csrf ? { "x-atelier-csrf": csrf } : {};
4
+ }
@@ -1,13 +1,13 @@
1
1
  import { defineNuxtPlugin, useRoute } from "#imports";
2
+ import { csrfHeaders } from "../csrf.js";
2
3
  export default defineNuxtPlugin({
3
4
  name: "atelier:editor",
4
5
  async setup(nuxtApp) {
5
6
  const query = useRoute().query;
6
7
  if (query._atelier !== "edit" || window.parent === window)
7
8
  return;
8
- const csrf = document.cookie.split("; ").find((c) => c.startsWith("atelier-csrf="))?.slice("atelier-csrf=".length);
9
9
  const token = typeof query._atelier_token === "string" ? query._atelier_token : void 0;
10
- const response = await fetch("/api/_atelier/editor/session", token ? { method: "POST", headers: { "content-type": "application/json", ...csrf ? { "x-atelier-csrf": csrf } : {} }, body: JSON.stringify({ token }) } : {});
10
+ const response = await fetch("/api/_atelier/editor/session", token ? { method: "POST", headers: { "content-type": "application/json", ...csrfHeaders() }, body: JSON.stringify({ token }) } : {});
11
11
  if (!response.ok)
12
12
  return;
13
13
  const { startBridge } = await import("../editor/bridge.js");
@@ -17,9 +17,16 @@ declare const _default: {
17
17
  };
18
18
  readonly fields: import("../../../../../server/index.js").RepeaterField & {
19
19
  readonly fields: {
20
+ readonly label: import("../../../../../server/index.js").TextField & {
21
+ readonly required: true;
22
+ readonly maxLength: 300;
23
+ } & {
24
+ type: "text";
25
+ };
20
26
  readonly name: import("../../../../../server/index.js").TextField & {
21
27
  readonly required: true;
22
28
  readonly maxLength: 64;
29
+ readonly help: "The name submissions are stored under: letters, digits, \"_\" and \"-\"";
23
30
  } & {
24
31
  type: "text";
25
32
  };
@@ -28,45 +35,101 @@ declare const _default: {
28
35
  readonly required: true;
29
36
  readonly default: "text";
30
37
  };
31
- readonly label: import("../../../../../server/index.js").TextField & {
32
- readonly required: true;
33
- readonly maxLength: 300;
34
- } & {
35
- type: "text";
36
- };
37
- readonly labels: import("../../../../../server/index.js").JsonField & {
38
- type: "json";
38
+ readonly labels: import("../../../../../server/index.js").CustomField<{
39
+ [x: string]: string | null | undefined;
40
+ } | null | undefined> & {
41
+ readonly label: "Label in other languages";
39
42
  };
40
43
  readonly help: import("../../../../../server/index.js").TextField & {
44
+ readonly help: "Shown under the field";
45
+ readonly when: {
46
+ field: string;
47
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
48
+ };
49
+ } & {
41
50
  type: "text";
42
51
  };
43
52
  readonly placeholder: import("../../../../../server/index.js").TextField & {
53
+ when: {
54
+ field: string;
55
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
56
+ };
57
+ } & {
44
58
  type: "text";
45
59
  };
46
60
  readonly required: import("../../../../../server/index.js").BooleanField & {
61
+ when: {
62
+ field: string;
63
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
64
+ };
65
+ } & {
47
66
  type: "boolean";
48
67
  };
49
68
  readonly options: import("../../../../../server/index.js").TextareaField & {
69
+ readonly help: "One per line: a value, or value|Label";
70
+ readonly when: {
71
+ field: string;
72
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
73
+ };
74
+ } & {
50
75
  type: "textarea";
51
76
  };
52
77
  readonly min: import("../../../../../server/index.js").NumberField & {
78
+ readonly label: "Minimum";
79
+ readonly help: "The smallest number, or the fewest characters";
80
+ readonly when: {
81
+ field: string;
82
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
83
+ };
84
+ } & {
53
85
  type: "number";
54
86
  };
55
87
  readonly max: import("../../../../../server/index.js").NumberField & {
88
+ readonly label: "Maximum";
89
+ readonly help: "The largest number, or the most characters";
90
+ readonly when: {
91
+ field: string;
92
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
93
+ };
94
+ } & {
56
95
  type: "number";
57
96
  };
58
97
  readonly pattern: import("../../../../../server/index.js").TextField & {
98
+ readonly help: "A regular expression the whole answer must match";
99
+ readonly when: {
100
+ field: string;
101
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
102
+ };
103
+ } & {
59
104
  type: "text";
60
105
  };
61
106
  readonly accept: import("../../../../../server/index.js").TextField & {
107
+ readonly label: "Accepted files";
108
+ readonly help: "Types, like image/*, application/pdf";
109
+ readonly when: {
110
+ field: string;
111
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
112
+ };
113
+ } & {
62
114
  type: "text";
63
115
  };
64
116
  readonly maxSize: import("../../../../../server/index.js").NumberField & {
65
117
  readonly min: 0;
118
+ readonly label: "Largest file (MB)";
119
+ readonly when: {
120
+ field: string;
121
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
122
+ };
66
123
  } & {
67
124
  type: "number";
68
125
  };
69
126
  readonly value: import("../../../../../server/index.js").TextField & {
127
+ readonly help: "Sent with every submission";
128
+ readonly when: {
129
+ field: string;
130
+ in: ("number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent")[];
131
+ };
132
+ } & {
70
133
  type: "text";
71
134
  };
72
135
  };
@@ -1,5 +1,13 @@
1
- import { boolean, defineCollection, json, number, object, repeater, select, text, textarea } from "../../../../../server/define.js";
1
+ import * as v from "valibot";
2
+ import { boolean, defineCollection, defineFieldType, number, object, repeater, select, text, textarea } from "../../../../../server/define.js";
2
3
  import { FORM_FIELD_TYPES } from "../../../../../shared/forms.js";
4
+ const localeTexts = defineFieldType({
5
+ name: "locale-texts",
6
+ storage: "json",
7
+ schema: v.nullish(v.record(v.string(), v.nullish(v.string())))
8
+ });
9
+ const forTypes = (...types) => ({ when: { field: "type", in: types } });
10
+ const ALL_BUT_HIDDEN = FORM_FIELD_TYPES.filter((type) => type !== "hidden");
3
11
  export default defineCollection({
4
12
  versioned: true,
5
13
  labels: { singular: "Form", plural: "Forms" },
@@ -8,20 +16,20 @@ export default defineCollection({
8
16
  title: text({ required: true, maxLength: 120 }),
9
17
  fields: repeater({
10
18
  fields: {
11
- name: text({ required: true, maxLength: 64 }),
12
- type: select({ options: [...FORM_FIELD_TYPES], required: true, default: "text" }),
13
19
  label: text({ required: true, maxLength: 300 }),
14
- labels: json(),
15
- help: text(),
16
- placeholder: text(),
17
- required: boolean(),
18
- options: textarea(),
19
- min: number(),
20
- max: number(),
21
- pattern: text(),
22
- accept: text(),
23
- maxSize: number({ min: 0 }),
24
- value: text()
20
+ name: text({ required: true, maxLength: 64, help: 'The name submissions are stored under: letters, digits, "_" and "-"' }),
21
+ type: select({ options: [...FORM_FIELD_TYPES], required: true, default: "text" }),
22
+ labels: localeTexts({ label: "Label in other languages" }),
23
+ help: text({ ...forTypes(...ALL_BUT_HIDDEN), help: "Shown under the field" }),
24
+ placeholder: text(forTypes("text", "email", "textarea", "number")),
25
+ required: boolean(forTypes(...ALL_BUT_HIDDEN)),
26
+ options: textarea({ ...forTypes("select", "radio"), help: "One per line: a value, or value|Label" }),
27
+ min: number({ ...forTypes("number", "text", "textarea"), label: "Minimum", help: "The smallest number, or the fewest characters" }),
28
+ max: number({ ...forTypes("number", "text", "textarea"), label: "Maximum", help: "The largest number, or the most characters" }),
29
+ pattern: text({ ...forTypes("text", "textarea"), help: "A regular expression the whole answer must match" }),
30
+ accept: text({ ...forTypes("file"), label: "Accepted files", help: "Types, like image/*, application/pdf" }),
31
+ maxSize: number({ ...forTypes("file"), min: 0, label: "Largest file (MB)" }),
32
+ value: text({ ...forTypes("hidden"), help: "Sent with every submission" })
25
33
  }
26
34
  }),
27
35
  submitLabel: text(),
@@ -20,7 +20,7 @@ declare const _default: import("nuxt/server").EventHandler<Promise<string | Resp
20
20
  fields: {
21
21
  label: string;
22
22
  name: string;
23
- type: "number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "file" | "checkbox" | "radio" | "consent";
23
+ type: "number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent";
24
24
  help?: string | null;
25
25
  placeholder?: string | null;
26
26
  required?: boolean | null;
@@ -44,7 +44,7 @@ declare const _default: import("nuxt/server").EventHandler<Promise<string | Resp
44
44
  fields: {
45
45
  name: string;
46
46
  label: string;
47
- type: "number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "file" | "checkbox" | "radio" | "consent";
47
+ type: "number" | "text" | "textarea" | "select" | "date" | "email" | "hidden" | "checkbox" | "radio" | "file" | "consent";
48
48
  }[];
49
49
  deleted?: undefined;
50
50
  id?: undefined;
@@ -54,4 +54,10 @@ export declare const resolveShared: <T>(value: T, lookup: (ref: string) => AnyBl
54
54
  export declare const copyBlocks: <T>(value: T, newId?: () => string) => T;
55
55
  /** Data with the references to `ref` replaced by `replace(reference)`'s blocks (none removes them). */
56
56
  export declare const replaceShared: <T>(value: T, ref: string, replace: (reference: AnyBlock) => AnyBlock | undefined) => T;
57
+ /** A new block of `type`: its fields' and options' defaults, and empty areas. */
58
+ export declare function newBlock(type: string, registry: Record<string, BlockSchema>): {
59
+ id: string;
60
+ type: string;
61
+ props: Record<string, unknown>;
62
+ };
57
63
  export {};
@@ -38,3 +38,14 @@ export const copyBlocks = (value, newId = () => crypto.randomUUID()) => mapBlock
38
38
  return { ...rest, id: newId() };
39
39
  });
40
40
  export const replaceShared = (value, ref, replace) => mapBlocks(value, (block) => block.type === SHARED_BLOCK && block.props.ref === ref ? replace(block) : block);
41
+ export function newBlock(type, registry) {
42
+ const schema = registry[type];
43
+ const props = {};
44
+ for (const [key, field] of Object.entries({ ...schema?.fields, ...schema?.options })) {
45
+ if (field.default !== void 0)
46
+ props[key] = structuredClone(field.default);
47
+ }
48
+ for (const area of Object.keys(schema?.areas ?? {}))
49
+ props[area] = [];
50
+ return { id: crypto.randomUUID(), type, props };
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-atelier",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {