@prunellejs/cms 0.7.2 → 0.7.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.
package/llms.txt CHANGED
@@ -48,7 +48,7 @@ Extracts JSON Schema from each collection's Standard Schema (`~standard.jsonSche
48
48
  - `enum` (`<select>` for string or number enums)
49
49
  - `boolean` (accessible `<input type="checkbox" role="switch">`)
50
50
  - `number` / `integer` (`<input type="number">` with `min`, `max`, `step`)
51
- - `array` of `string` (tags input)
51
+ - `array` of `string` (comma-separated tags input; tags containing commas or quotes are CSV-quoted)
52
52
  - nested `object` (`<fieldset>` with dotted field names like `author.name`)
53
53
  - `array` of `object` (repeatable rows like `items[0].title` with no-JS Add/Remove/Move buttons)
54
54
  - Markdown body (`<textarea name="__body">` with progressive live preview)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prunellejs/cms",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "Schema-driven dev-only CMS plugin for Prunelle Markdown content collections",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,6 +21,6 @@
21
21
  "directory": "packages/plugin-cms"
22
22
  },
23
23
  "peerDependencies": {
24
- "prunelle": "^0.7.2"
24
+ "prunelle": "^0.7.3"
25
25
  }
26
26
  }
package/src/form-data.ts CHANGED
@@ -15,6 +15,65 @@ const UNSAFE_SLUG_CHAR_RE = /[\0-\x1F\x7F\\]/
15
15
  const MAX_SLUG_SEGMENT_BYTES = 252 // 255 minus the `.md` suffix
16
16
  const MAX_ENTRY_PATH_BYTES = 4000 // PATH_MAX 4096 minus room for the temp file of a save
17
17
  const MAX_REPEATABLE_ROWS = 500
18
+ const TAG_NEEDS_QUOTE_RE = /[,"\r\n]|^\s|\s$/
19
+
20
+ /** Formats a tags array for a single text input, CSV-quoting any tag with commas, quotes, line breaks, or outer spaces. */
21
+ export function formatTagsInput(value: unknown): string {
22
+ if (!Array.isArray(value))
23
+ return String(value)
24
+ return value.map((item) => {
25
+ const str = String(item)
26
+ return TAG_NEEDS_QUOTE_RE.test(str) ? `"${str.replaceAll('"', '""')}"` : str
27
+ }).join(', ')
28
+ }
29
+
30
+ /** Parses a comma/newline-separated tags string, honoring RFC 4180 double-quoted tags so commas inside a tag stay intact. */
31
+ export function parseTagsInput(raw: string): string[] {
32
+ const tags: string[] = []
33
+ const len = raw.length
34
+ let i = 0
35
+ while (i < len) {
36
+ while (i < len && (raw[i] === ' ' || raw[i] === '\t' || raw[i] === ',' || raw[i] === '\r' || raw[i] === '\n'))
37
+ i++
38
+ if (i >= len)
39
+ break
40
+ if (raw[i] === '"') {
41
+ i++
42
+ let val = ''
43
+ while (i < len) {
44
+ const ch = raw[i]!
45
+ if (ch === '"') {
46
+ if (raw[i + 1] === '"') {
47
+ val += '"'
48
+ i += 2
49
+ continue
50
+ }
51
+ i++
52
+ break
53
+ }
54
+ val += ch
55
+ i++
56
+ }
57
+ let tail = ''
58
+ while (i < len && raw[i] !== ',' && raw[i] !== '\r' && raw[i] !== '\n') {
59
+ tail += raw[i]!
60
+ i++
61
+ }
62
+ const combined = tail.trim().length > 0 ? `${val}${tail.trimEnd()}` : val
63
+ if (combined.length > 0)
64
+ tags.push(combined)
65
+ }
66
+ else {
67
+ const start = i
68
+ while (i < len && raw[i] !== ',' && raw[i] !== '\r' && raw[i] !== '\n')
69
+ i++
70
+ const clean = raw.slice(start, i).trim()
71
+ if (clean.length > 0)
72
+ tags.push(clean)
73
+ }
74
+ }
75
+ return tags
76
+ }
18
77
 
19
78
  export interface ParsedRowAction {
20
79
  readonly op: 'add' | 'remove' | 'up' | 'down'
@@ -223,13 +282,8 @@ function parseFieldEntry(formData: FormData, field: CmsField, name: string): { v
223
282
  if (all.length === 0)
224
283
  return { value: undefined, present: false }
225
284
  const tags: string[] = []
226
- for (const chunk of all) {
227
- for (const item of chunk.split(/[,\r\n]+/)) {
228
- const clean = item.trim()
229
- if (clean.length > 0)
230
- tags.push(clean)
231
- }
232
- }
285
+ for (const chunk of all)
286
+ tags.push(...parseTagsInput(chunk))
233
287
  return { value: tags, present: tags.length > 0 }
234
288
  }
235
289
  case 'object': {
@@ -23,9 +23,48 @@ export const INLINE_FORM_JS = `
23
23
  return out;
24
24
  }
25
25
 
26
+ function formatTagsValue(value) {
27
+ if (!Array.isArray(value)) return String(value);
28
+ return value.map((item) => {
29
+ const str = String(item);
30
+ return /[,\\"\\r\\n]|^\\s|\\s$/.test(str) ? '"' + str.replaceAll('"', '""') + '"' : str;
31
+ }).join(', ');
32
+ }
33
+
34
+ function parseTagsValue(raw) {
35
+ const tags = [];
36
+ let i = 0;
37
+ while (i < raw.length) {
38
+ while (i < raw.length && ' \\t,\\r\\n'.includes(raw[i])) i++;
39
+ if (i >= raw.length) break;
40
+ if (raw[i] === '"') {
41
+ i++;
42
+ let val = '';
43
+ while (i < raw.length) {
44
+ if (raw[i] === '"') {
45
+ if (raw[i + 1] === '"') { val += '"'; i += 2; continue; }
46
+ i++;
47
+ break;
48
+ }
49
+ val += raw[i++];
50
+ }
51
+ let tail = '';
52
+ while (i < raw.length && raw[i] !== ',' && raw[i] !== '\\r' && raw[i] !== '\\n') tail += raw[i++];
53
+ const combined = tail.trim() ? val + tail.trimEnd() : val;
54
+ if (combined.length > 0) tags.push(combined);
55
+ } else {
56
+ const start = i;
57
+ while (i < raw.length && raw[i] !== ',' && raw[i] !== '\\r' && raw[i] !== '\\n') i++;
58
+ const clean = raw.slice(start, i).trim();
59
+ if (clean.length > 0) tags.push(clean);
60
+ }
61
+ }
62
+ return tags;
63
+ }
64
+
26
65
  function formatFieldValue(field, value) {
27
66
  if (value === undefined || value === null) return '';
28
- if (field.kind === 'tags') return Array.isArray(value) ? value.map(String).join(', ') : String(value);
67
+ if (field.kind === 'tags') return formatTagsValue(value);
29
68
  const str = String(value);
30
69
  if (field.kind === 'date' && /^\\d{4}-\\d{2}-\\d{2}T/.test(str)) return str.slice(0, 10);
31
70
  if (field.kind === 'datetime' && /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}/.test(str)) return str.slice(0, 16);
@@ -48,10 +87,7 @@ export const INLINE_FORM_JS = `
48
87
  const n = Number(t);
49
88
  return Number.isFinite(n) ? n : raw;
50
89
  }
51
- if (field.kind === 'tags') {
52
- const items = raw.split(/[,\\r\\n]+/).map(s => s.trim()).filter(Boolean);
53
- return items;
54
- }
90
+ if (field.kind === 'tags') return parseTagsValue(raw);
55
91
  if (field.kind === 'enum') {
56
92
  if (raw === '' && !field.required) return undefined;
57
93
  if (field.enumType === 'number') {
@@ -295,7 +331,7 @@ export const INLINE_FORM_JS = `
295
331
  });
296
332
  wrap.appendChild(control);
297
333
  const hint = field.kind === 'tags'
298
- ? (field.description ? field.description + ' (comma-separated)' : 'Comma-separated list of tags')
334
+ ? (field.description ? field.description + ' (comma-separated; quote tags containing commas)' : 'Comma-separated list of tags (quote tags containing commas)')
299
335
  : field.description;
300
336
  appendMeta(wrap, id, hint, err);
301
337
  return wrap;
package/src/render.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import type { ContentCollectionDescriptor, ContentCollectionEntrySummary } from 'prunelle/config'
4
4
  import type { CmsField } from './schema'
5
5
  import { esc, escAttr } from 'prunelle/server'
6
- import { serializeFrontmatterYaml } from './form-data'
6
+ import { formatTagsInput, serializeFrontmatterYaml } from './form-data'
7
7
 
8
8
  export interface CollectionCardView {
9
9
  readonly name: string
@@ -236,7 +236,7 @@ function formatInputValue(field: CmsField, value: unknown): string {
236
236
  return value.toISOString()
237
237
  }
238
238
  if (field.kind === 'tags')
239
- return Array.isArray(value) ? value.map(String).join(', ') : String(value)
239
+ return formatTagsInput(value)
240
240
  if (field.kind === 'date' && typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T/.test(value))
241
241
  return value.slice(0, 10)
242
242
  if (field.kind === 'datetime' && typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(value))
@@ -330,7 +330,7 @@ function renderScalarField(
330
330
  const id = fieldDomId(name)
331
331
  const valStr = formatInputValue(field, value)
332
332
  const hint = field.kind === 'tags'
333
- ? (field.description ? `${field.description} (comma-separated)` : 'Comma-separated list of tags')
333
+ ? (field.description ? `${field.description} (comma-separated; quote tags containing commas)` : 'Comma-separated list of tags (quote tags containing commas)')
334
334
  : field.description
335
335
  const invalidAttr = error !== undefined ? ' aria-invalid="true"' : ''
336
336
  const descAttr = describedByAttr(id, hint !== undefined, error !== undefined)