inlaycms 0.2.0 → 0.4.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.
Files changed (122) hide show
  1. package/README.md +334 -1
  2. package/assets/admin/admin.css +1 -1
  3. package/assets/admin/admin.js +1 -1
  4. package/assets/admin/editor.js +59 -44
  5. package/dist/adapters/admin/screens/redirects.js +12 -3
  6. package/dist/adapters/admin/views/layout.js +27 -7
  7. package/dist/adapters/cli/remote.js +9 -1
  8. package/dist/adapters/mcp/tools/redirects.js +16 -2
  9. package/dist/adapters/site/assets.d.ts +11 -0
  10. package/dist/adapters/site/assets.js +71 -0
  11. package/dist/adapters/site/cache.d.ts +2 -1
  12. package/dist/adapters/site/cache.js +6 -1
  13. package/dist/adapters/site/context.d.ts +6 -0
  14. package/dist/adapters/site/context.js +38 -13
  15. package/dist/adapters/site/head.d.ts +30 -7
  16. package/dist/adapters/site/head.js +145 -20
  17. package/dist/adapters/site/headers.d.ts +5 -0
  18. package/dist/adapters/site/headers.js +31 -0
  19. package/dist/adapters/site/plugin.d.ts +2 -0
  20. package/dist/adapters/site/plugin.js +32 -9
  21. package/dist/adapters/site/public.js +7 -24
  22. package/dist/adapters/site/render.d.ts +5 -0
  23. package/dist/adapters/site/render.js +23 -8
  24. package/dist/adapters/site/routes.d.ts +6 -0
  25. package/dist/adapters/site/routes.js +8 -3
  26. package/dist/adapters/site/seo.d.ts +20 -0
  27. package/dist/adapters/site/seo.js +45 -0
  28. package/dist/adapters/site/sitemap.d.ts +1 -1
  29. package/dist/adapters/site/sitemap.js +1 -1
  30. package/dist/config.js +3 -2
  31. package/dist/core/agent/format.js +1 -1
  32. package/dist/core/agent/schema.js +3 -0
  33. package/dist/core/boot.js +7 -0
  34. package/dist/core/check.js +6 -1
  35. package/dist/core/content/dry-run.d.ts +7 -6
  36. package/dist/core/content/dry-run.js +8 -8
  37. package/dist/core/content/publish.d.ts +1 -1
  38. package/dist/core/content/publish.js +5 -3
  39. package/dist/core/content/read.d.ts +3 -0
  40. package/dist/core/content/reader.js +3 -2
  41. package/dist/core/content/refs.js +1 -1
  42. package/dist/core/content/search.js +2 -2
  43. package/dist/core/content/shipped-images.d.ts +32 -0
  44. package/dist/core/content/shipped-images.js +62 -0
  45. package/dist/core/content/shipped-input.d.ts +9 -3
  46. package/dist/core/content/shipped-input.js +165 -28
  47. package/dist/core/content/shipped.js +8 -3
  48. package/dist/core/content/validate.js +7 -1
  49. package/dist/core/core.d.ts +5 -1
  50. package/dist/core/core.js +5 -4
  51. package/dist/core/db/connection.d.ts +6 -0
  52. package/dist/core/db/connection.js +13 -1
  53. package/dist/core/db/migrate.js +2 -0
  54. package/dist/core/db/migrations/0007_published_at.d.ts +3 -0
  55. package/dist/core/db/migrations/0007_published_at.js +16 -0
  56. package/dist/core/db/schema.d.ts +1 -0
  57. package/dist/core/export/export.js +3 -1
  58. package/dist/core/export/format.d.ts +8 -1
  59. package/dist/core/export/format.js +3 -2
  60. package/dist/core/export/read.js +7 -0
  61. package/dist/core/export/stage.d.ts +1 -1
  62. package/dist/core/export/stage.js +24 -1
  63. package/dist/core/fields/builtins.d.ts +28 -0
  64. package/dist/core/fields/builtins.js +103 -11
  65. package/dist/core/fields/define.d.ts +6 -0
  66. package/dist/core/fields/widgets.d.ts +7 -0
  67. package/dist/core/fields/widgets.js +77 -28
  68. package/dist/core/media/library.js +2 -2
  69. package/dist/core/messages/en.d.ts +72 -6
  70. package/dist/core/messages/en.js +72 -6
  71. package/dist/core/redirects/collapse.d.ts +17 -1
  72. package/dist/core/redirects/collapse.js +19 -3
  73. package/dist/core/redirects/redirects.d.ts +13 -12
  74. package/dist/core/redirects/redirects.js +141 -53
  75. package/dist/core/redirects/rule.d.ts +25 -0
  76. package/dist/core/redirects/rule.js +55 -0
  77. package/dist/core/registry/define.d.ts +40 -0
  78. package/dist/core/registry/define.js +3 -0
  79. package/dist/core/registry/registry.d.ts +21 -0
  80. package/dist/core/registry/registry.js +114 -6
  81. package/dist/core/registry/render.d.ts +37 -1
  82. package/dist/core/registry/route.d.ts +4 -0
  83. package/dist/core/release/bundle.js +30 -5
  84. package/dist/core/release/manifest.d.ts +14 -0
  85. package/dist/core/release/manifest.js +42 -17
  86. package/dist/core/release/markdown-file.d.ts +21 -0
  87. package/dist/core/release/markdown-file.js +172 -0
  88. package/dist/core/release/pack.js +2 -2
  89. package/dist/core/release/read.js +4 -1
  90. package/dist/core/release/site-dir.d.ts +4 -0
  91. package/dist/core/release/site-dir.js +8 -0
  92. package/dist/core/report.d.ts +8 -2
  93. package/dist/core/richtext/html.d.ts +3 -1
  94. package/dist/core/richtext/html.js +18 -4
  95. package/dist/core/richtext/inline.d.ts +22 -0
  96. package/dist/core/richtext/inline.js +33 -0
  97. package/dist/core/richtext/markdown.d.ts +19 -1
  98. package/dist/core/richtext/markdown.js +187 -22
  99. package/dist/core/richtext/schema.d.ts +22 -5
  100. package/dist/core/richtext/schema.js +81 -4
  101. package/dist/core/site/live.d.ts +1 -0
  102. package/dist/core/site/live.js +1 -0
  103. package/dist/core/site/paths.d.ts +6 -0
  104. package/dist/core/site/paths.js +13 -0
  105. package/dist/core/site/resolve.d.ts +1 -1
  106. package/dist/core/site/resolve.js +119 -30
  107. package/dist/core/site/sitemap.d.ts +1 -1
  108. package/dist/core/site/sitemap.js +4 -0
  109. package/dist/core/types.d.ts +28 -3
  110. package/dist/host/app.d.ts +5 -0
  111. package/dist/host/app.js +10 -1
  112. package/dist/host/dev.js +3 -7
  113. package/dist/host/diff.d.ts +19 -1
  114. package/dist/host/diff.js +32 -2
  115. package/dist/index.d.ts +2 -2
  116. package/dist/markdown-modules.d.ts +8 -0
  117. package/dist/markdown-modules.js +1 -0
  118. package/dist/site.d.ts +8 -3
  119. package/dist/site.js +6 -0
  120. package/dist/testing.d.ts +22 -0
  121. package/dist/testing.js +155 -0
  122. package/package.json +7 -1
@@ -7,12 +7,19 @@ interface BaseOptions {
7
7
  }
8
8
  interface TextOptions extends BaseOptions {
9
9
  maxLength?: number;
10
+ suggestedLength?: number;
10
11
  }
11
12
  /** Marks the issue from text and textarea's non-blank check (in `params.check`). */
12
13
  export declare const NON_BLANK = "nonBlank";
13
14
  /** The `check` param of the refinements that make a date or datetime field reject a malformed value. */
14
15
  export declare const DATE_CHECK = "date";
15
16
  export declare const DATETIME_CHECK = "datetime";
17
+ /** The `check` param of the refinement that holds an inline-text field to its `maxLength` (in `params.max`). */
18
+ export declare const INLINE_TEXT_MAX = "inlineTextMax";
19
+ /** The `check` param of the refinement that makes a title template need exactly one `%s`. */
20
+ export declare const TITLE_TEMPLATE_CHECK = "titleTemplate";
21
+ /** Whether `s` has `%s` exactly once. */
22
+ export declare function isTitleTemplate(s: string): boolean;
16
23
  export declare const f: {
17
24
  text: (o: TextOptions) => z.ZodString;
18
25
  textarea: (o: TextOptions) => z.ZodString;
@@ -23,6 +30,14 @@ export declare const f: {
23
30
  }): z.ZodNumber;
24
31
  boolean: (o: BaseOptions) => z.ZodDefault<z.ZodBoolean>;
25
32
  select<const T extends readonly [string, ...string[]]>(options: T, o: BaseOptions): z.ZodEnum<{ [k in T[number]]: k; } extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never>;
33
+ /**
34
+ * Any of `options`, saved in the options' order without duplicates. `min` and `max` are checked at publish. A
35
+ * stored option the code no longer offers is dropped when the value is read.
36
+ */
37
+ multiSelect<const T extends readonly [string, ...string[]]>(options: T, o: BaseOptions & {
38
+ min?: number;
39
+ max?: number;
40
+ }): z.ZodType<T[number][], T[number][]>;
26
41
  date: (o: BaseOptions) => z.ZodString;
27
42
  datetime: (o: BaseOptions) => z.ZodString;
28
43
  link(o: BaseOptions): z.ZodUnion<readonly [z.ZodObject<{
@@ -48,6 +63,9 @@ export declare const f: {
48
63
  features?: RichTextFeature[];
49
64
  headings?: number[];
50
65
  }): z.ZodPipe<z.ZodCustom<unknown, unknown>, z.ZodTransform<RichTextDoc, unknown>>;
66
+ inlineText(o: BaseOptions & {
67
+ maxLength?: number;
68
+ }): z.ZodPipe<z.ZodCustom<unknown, unknown>, z.ZodTransform<RichTextDoc, unknown>>;
51
69
  list<T extends z.ZodObject>(item: T, o: BaseOptions & {
52
70
  min?: number;
53
71
  max?: number;
@@ -66,5 +84,15 @@ export declare const f: {
66
84
  alt: z.ZodOptional<z.ZodString>;
67
85
  }, z.core.$strip>>;
68
86
  }, z.core.$strip>;
87
+ seoDefaults(o?: {
88
+ label?: string;
89
+ }): z.ZodObject<{
90
+ titleTemplate: z.ZodOptional<z.ZodString>;
91
+ description: z.ZodOptional<z.ZodString>;
92
+ image: z.ZodOptional<z.ZodObject<{
93
+ media: z.ZodString;
94
+ alt: z.ZodOptional<z.ZodString>;
95
+ }, z.core.$strip>>;
96
+ }, z.core.$strip>;
69
97
  };
70
98
  export {};
@@ -2,10 +2,11 @@ import { z } from 'zod';
2
2
  import { InlayError } from '../errors.js';
3
3
  import { missingMediaLabel } from '../media/labels.js';
4
4
  import { t } from '../messages/index.js';
5
+ import { INLINE_TEXT, markdownToInlineText, parseInlineText } from '../richtext/inline.js';
5
6
  import { markdownToRichText, richTextToMarkdown } from '../richtext/markdown.js';
6
- import { DEFAULT_RICH_TEXT, parseRichText, RICH_TEXT_FEATURES, richTextIsBlank, richTextRefs, } from '../richtext/schema.js';
7
+ import { DEFAULT_RICH_TEXT, parseRichText, RICH_TEXT_FEATURES, richTextIsBlank, richTextRefs, richTextText, } from '../richtext/schema.js';
7
8
  import { defineField, isSafeUrl } from './define.js';
8
- import { booleanWidget, datetimeWidget, dateWidget, fileWidget, imageWidget, linkWidget, numberWidget, refsWidget, refWidget, richTextWidget, selectWidget, textareaWidget, textWidget, } from './widgets.js';
9
+ import { booleanWidget, datetimeWidget, dateWidget, fileWidget, imageWidget, inlineTextWidget, linkWidget, multiSelectWidget, numberWidget, refsWidget, refWidget, richTextWidget, selectWidget, textareaWidget, textWidget, } from './widgets.js';
9
10
  import { isRecord } from './zod-internals.js';
10
11
  function base(o) {
11
12
  return {
@@ -29,14 +30,25 @@ export const NON_BLANK = 'nonBlank';
29
30
  /** The `check` param of the refinements that make a date or datetime field reject a malformed value. */
30
31
  export const DATE_CHECK = 'date';
31
32
  export const DATETIME_CHECK = 'datetime';
32
- function stringField(kind, o) {
33
+ /** The `check` param of the refinement that holds an inline-text field to its `maxLength` (in `params.max`). */
34
+ export const INLINE_TEXT_MAX = 'inlineTextMax';
35
+ /** The `check` param of the refinement that makes a title template need exactly one `%s`. */
36
+ export const TITLE_TEMPLATE_CHECK = 'titleTemplate';
37
+ /** Whether `s` has `%s` exactly once. */
38
+ export function isTitleTemplate(s) {
39
+ return s.split('%s').length === 2;
40
+ }
41
+ function stringField(kind, o, also) {
33
42
  let draft = z.string();
34
43
  if (o.maxLength !== undefined)
35
44
  draft = draft.max(o.maxLength);
45
+ if (also)
46
+ draft = draft.refine(also.test, { params: { check: also.check } });
36
47
  const strict = draft.refine((s) => s.trim().length > 0, { params: { check: NON_BLANK } });
37
48
  return defineField(strict, {
38
49
  kind,
39
50
  ...base(o),
51
+ ...(o.suggestedLength !== undefined && { suggestedLength: o.suggestedLength }),
40
52
  draft,
41
53
  admin: kind === 'text' ? textWidget : textareaWidget,
42
54
  empty: '',
@@ -166,18 +178,39 @@ function linkCodec() {
166
178
  },
167
179
  };
168
180
  }
169
- /** What a rich-text field accepts, in plain words: "Markdown. Allowed: bold text, links, headings of level 2, 3 (…)." */
170
- function richTextDescription(opts) {
171
- const allowed = RICH_TEXT_FEATURES.filter((feature) => opts.features.includes(feature)).flatMap((feature) => {
181
+ /** Several options as an array of them, as stored. */
182
+ function multiSelectCodec(options, min, max) {
183
+ return {
184
+ schema: {
185
+ type: 'array',
186
+ items: { enum: [...options] },
187
+ uniqueItems: true,
188
+ ...(min !== undefined && { minItems: min }),
189
+ ...(max !== undefined && { maxItems: max }),
190
+ },
191
+ read: (value) => value,
192
+ write: unchanged,
193
+ };
194
+ }
195
+ /** The formatting `opts` allows, in plain words: "bold text, links, headings of level 2, 3 (…)". */
196
+ function allowedFeatures(opts) {
197
+ return RICH_TEXT_FEATURES.filter((feature) => opts.features.includes(feature)).flatMap((feature) => {
172
198
  if (feature !== 'heading')
173
199
  return [t(`richtext.feature.${feature}`)];
174
200
  return opts.headings.length > 0 ? [t('agent.richTextHeadings', { levels: opts.headings.join(', ') })] : [];
175
201
  });
202
+ }
203
+ /** What a rich-text field accepts, in plain words: "Markdown. Allowed: bold text, links, headings of level 2, 3 (…)." */
204
+ function richTextDescription(opts) {
205
+ const allowed = allowedFeatures(opts);
176
206
  return allowed.length > 0 ? t('agent.richText', { features: allowed.join(', ') }) : t('agent.richTextNone');
177
207
  }
178
- function richTextCodec(opts) {
208
+ function richTextCodec(opts, inline = false) {
209
+ const description = inline
210
+ ? t('agent.inlineText', { features: allowedFeatures(opts).join(', ') })
211
+ : richTextDescription(opts);
179
212
  return {
180
- schema: { type: 'string', contentMediaType: 'text/markdown', description: richTextDescription(opts) },
213
+ schema: { type: 'string', contentMediaType: 'text/markdown', description },
181
214
  read(value) {
182
215
  if (!isRecord(value))
183
216
  return value;
@@ -191,7 +224,7 @@ function richTextCodec(opts) {
191
224
  write(value) {
192
225
  if (typeof value !== 'string')
193
226
  return unchanged(value);
194
- const result = markdownToRichText(value, opts);
227
+ const result = inline ? markdownToInlineText(value) : markdownToRichText(value, opts);
195
228
  return result.ok ? unchanged(result.doc) : { ok: false, problems: result.problems.map((p) => p.message) };
196
229
  },
197
230
  };
@@ -213,6 +246,35 @@ export const f = {
213
246
  select(options, o) {
214
247
  return defineField(z.enum(options), { kind: 'select', ...base(o), options, admin: selectWidget, empty: options[0] });
215
248
  },
249
+ /**
250
+ * Any of `options`, saved in the options' order without duplicates. `min` and `max` are checked at publish. A
251
+ * stored option the code no longer offers is dropped when the value is read.
252
+ */
253
+ multiSelect(options, o) {
254
+ const offered = options;
255
+ const item = z.enum(options);
256
+ const canonical = (v) => {
257
+ const chosen = v;
258
+ return offered.filter((x) => chosen.includes(x));
259
+ };
260
+ const draft = z.array(item).transform(canonical);
261
+ let checked = z.array(item);
262
+ if (o.min !== undefined)
263
+ checked = checked.min(o.min);
264
+ if (o.max !== undefined)
265
+ checked = checked.max(o.max);
266
+ return defineField(draft.pipe(checked), {
267
+ kind: 'multiSelect',
268
+ ...base(o),
269
+ options,
270
+ many: true,
271
+ draft,
272
+ agent: multiSelectCodec(options, o.min, o.max),
273
+ admin: multiSelectWidget,
274
+ empty: [],
275
+ readStored: (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string' && offered.includes(x)) : v),
276
+ });
277
+ },
216
278
  date: (o) => defineField(z.string().refine(isRealDate, { params: { check: DATE_CHECK } }), { kind: 'date', ...base(o), admin: dateWidget, empty: '' }),
217
279
  datetime: (o) => defineField(z
218
280
  .string()
@@ -306,6 +368,27 @@ export const f = {
306
368
  refs: (v) => (isRecord(v) ? richTextRefs(v) : []),
307
369
  });
308
370
  },
371
+ inlineText(o) {
372
+ const parsed = z
373
+ .custom((v) => parseInlineText(v).ok)
374
+ .meta({ inlineText: { features: [...INLINE_TEXT.features] } })
375
+ .transform((v) => parseInlineText(v).doc);
376
+ const max = o.maxLength;
377
+ const draft = max === undefined
378
+ ? parsed
379
+ : parsed.refine((doc) => richTextText(doc).length <= max, { params: { check: INLINE_TEXT_MAX, max } });
380
+ const strict = draft.refine((doc) => !richTextIsBlank(doc), { params: { check: NON_BLANK } });
381
+ return defineField(strict, {
382
+ kind: 'inlineText',
383
+ ...base(o),
384
+ draft,
385
+ richText: INLINE_TEXT,
386
+ agent: richTextCodec(INLINE_TEXT, true),
387
+ admin: inlineTextWidget,
388
+ empty: { type: 'doc', content: [] },
389
+ refs: (v) => (isRecord(v) ? richTextRefs(v) : []),
390
+ });
391
+ },
309
392
  list(item, o) {
310
393
  let arr = z.array(item);
311
394
  if (o.min !== undefined)
@@ -327,9 +410,18 @@ export const f = {
327
410
  },
328
411
  seo(o = {}) {
329
412
  return f.group({
330
- title: f.text({ label: t('label.seo.title'), maxLength: 70 }).optional(),
331
- description: f.textarea({ label: t('label.seo.description'), maxLength: 160 }).optional(),
413
+ title: f.text({ label: t('label.seo.title'), suggestedLength: 70, maxLength: 300 }).optional(),
414
+ description: f.textarea({ label: t('label.seo.description'), suggestedLength: 160, maxLength: 500 }).optional(),
332
415
  image: f.image({ label: t('label.seo.image') }).optional(),
333
416
  }, { label: o.label ?? t('label.seo'), seo: true });
334
417
  },
418
+ seoDefaults(o = {}) {
419
+ return defineField(z.object({
420
+ titleTemplate: stringField('text', { label: t('label.seoDefaults.titleTemplate'), help: t('label.seoDefaults.titleTemplateHelp'), maxLength: 100 }, { test: isTitleTemplate, check: TITLE_TEMPLATE_CHECK }).optional(),
421
+ description: f
422
+ .textarea({ label: t('label.seoDefaults.description'), suggestedLength: 160, maxLength: 500 })
423
+ .optional(),
424
+ image: f.image({ label: t('label.seoDefaults.image') }).optional(),
425
+ }), { kind: 'group', label: o.label ?? t('label.seoDefaults'), seoDefaults: true });
426
+ },
335
427
  };
@@ -61,8 +61,12 @@ export interface FieldMeta {
61
61
  label: string;
62
62
  help?: string;
63
63
  setting?: boolean;
64
+ /** A soft limit the admin and assistants are told about; going past it never fails validation. */
65
+ suggestedLength?: number;
64
66
  /** Marks the group whose values fill the page's SEO tags. */
65
67
  seo?: true;
68
+ /** Marks the group holding the site's search and sharing defaults. */
69
+ seoDefaults?: true;
66
70
  draft?: z.ZodType;
67
71
  refs?: (value: unknown) => ContentRef[];
68
72
  options?: readonly string[];
@@ -74,6 +78,8 @@ export interface FieldMeta {
74
78
  admin?: AdminWidget;
75
79
  /** The value a required field renders with when it has none (spec §6.2). Cloned before use. */
76
80
  empty?: unknown;
81
+ /** Applied by the reader to a stored value before it is checked, such as dropping options the code no longer offers. */
82
+ readStored?: (value: unknown) => unknown;
77
83
  }
78
84
  export declare const fieldRegistry: z.core.$ZodRegistry<FieldMeta>;
79
85
  export declare function fieldMeta(schema: z.ZodType): FieldMeta | undefined;
@@ -4,6 +4,11 @@ export declare const textareaWidget: AdminWidget;
4
4
  export declare const numberWidget: AdminWidget;
5
5
  export declare const booleanWidget: AdminWidget;
6
6
  export declare const selectWidget: AdminWidget;
7
+ /**
8
+ * Any of the options, as one checkbox each. A hidden `<name>.many` marks a stored list or a required field, so
9
+ * nothing ticked is saved as `[]` there and an absent optional value stays absent.
10
+ */
11
+ export declare const multiSelectWidget: AdminWidget;
7
12
  export declare const dateWidget: AdminWidget;
8
13
  export declare const datetimeWidget: AdminWidget;
9
14
  /** The fallback for fields without a widget of their own: the value as JSON. */
@@ -25,3 +30,5 @@ export declare const linkWidget: AdminWidget;
25
30
  * an optional field → absent, unless a hidden `<name>._present` marks a stored value, which keeps it.
26
31
  */
27
32
  export declare const richTextWidget: AdminWidget;
33
+ /** One line of formatted text: the rich-text editor marked `data-inline`, one line tall, holding one paragraph. */
34
+ export declare const inlineTextWidget: AdminWidget;
@@ -2,6 +2,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-
2
2
  import { isRasterImage } from '../media/detect.js';
3
3
  import { missingMediaLabel } from '../media/labels.js';
4
4
  import { t } from '../messages/index.js';
5
+ import { parseInlineText } from '../richtext/inline.js';
5
6
  import { DEFAULT_RICH_TEXT, parseRichText, RICH_TEXT_FEATURES, richTextIsBlank } from '../richtext/schema.js';
6
7
  import { isRecord } from './zod-internals.js';
7
8
  /** The attributes every control shares. */
@@ -42,18 +43,31 @@ function parseNonEmpty(form, name) {
42
43
  }
43
44
  /** A one-line text input, which browsers would strip of newlines, as a free text box with the stored value as it is. */
44
45
  const plainInput = (p, value) => _jsx("input", { type: "text", value: value, class: "input input-bordered w-full", ...control(p) });
46
+ /** The control's attributes, with the counter's id added to what describes it when there is a counter. */
47
+ const countedControl = (p) => p.meta.suggestedLength === undefined ? control(p) : { ...control(p), 'aria-describedby': [p.describedBy, `${p.id}-length`].filter((x) => x !== undefined).join(' ') };
48
+ /** A live character count under a control, with a hint that shows once the text is past the suggested length. */
49
+ function LengthCounter({ p, value }) {
50
+ const n = p.meta.suggestedLength;
51
+ if (n === undefined)
52
+ return null;
53
+ const length = value.length;
54
+ return (_jsxs("p", { id: `${p.id}-length`, "data-length-for": p.id, "data-suggested-length": n, "data-label": t('admin.form.length', { count: '{count}', suggested: n }), "aria-live": "polite", class: "text-sm text-base-content/70", children: [_jsx("span", { "data-length-count": true, children: t('admin.form.length', { count: length, suggested: n }) }), ' ', _jsx("span", { "data-length-hint": true, hidden: length <= n, children: t('admin.form.lengthOver', { suggested: n }) })] }));
55
+ }
45
56
  export const textWidget = {
46
57
  render(p) {
47
58
  const value = asText(p.value);
59
+ const attrs = countedControl(p);
48
60
  // A one-line input would drop the newlines of a stored value, so it gets a text box instead.
49
- if (!/[\r\n]/.test(value))
50
- return plainInput(p, value);
51
- return (_jsx("textarea", { rows: "3", class: "textarea textarea-bordered w-full", ...control(p), children: textareaBody(value) }));
61
+ const input = /[\r\n]/.test(value) ? (_jsx("textarea", { rows: "3", class: "textarea textarea-bordered w-full", ...attrs, children: textareaBody(value) })) : (_jsx("input", { type: "text", value: value, class: "input input-bordered w-full", ...attrs }));
62
+ return (_jsxs(_Fragment, { children: [input, _jsx(LengthCounter, { p: p, value: value })] }));
52
63
  },
53
64
  parse: (form, name, _meta, optional) => parseText(form, name, optional),
54
65
  };
55
66
  export const textareaWidget = {
56
- render: (p) => (_jsx("textarea", { rows: "4", class: "textarea textarea-bordered w-full", ...control(p), children: textareaBody(asText(p.value)) })),
67
+ render(p) {
68
+ const value = asText(p.value);
69
+ return (_jsxs(_Fragment, { children: [_jsx("textarea", { rows: "4", class: "textarea textarea-bordered w-full", ...countedControl(p), children: textareaBody(value) }), _jsx(LengthCounter, { p: p, value: value })] }));
70
+ },
57
71
  parse: (form, name, _meta, optional) => parseText(form, name, optional),
58
72
  };
59
73
  /** HTML's valid floating-point number: what a `type=number` input keeps; it blanks anything else. */
@@ -88,6 +102,24 @@ export const selectWidget = {
88
102
  },
89
103
  parse: (form, name) => parseNonEmpty(form, name),
90
104
  };
105
+ /**
106
+ * Any of the options, as one checkbox each. A hidden `<name>.many` marks a stored list or a required field, so
107
+ * nothing ticked is saved as `[]` there and an absent optional value stays absent.
108
+ */
109
+ export const multiSelectWidget = {
110
+ fieldset: true,
111
+ render(p) {
112
+ const options = p.meta.options ?? [];
113
+ const chosen = Array.isArray(p.value) ? p.value : [];
114
+ return (_jsxs("div", { class: "flex flex-wrap gap-x-6 gap-y-2", children: [(Array.isArray(p.value) || !p.optional) && _jsx("input", { type: "hidden", name: `${p.name}.many`, value: "", disabled: p.readOnly }), options.map((o, i) => (_jsxs("label", { class: "flex items-center gap-2", children: [_jsx("input", { type: "checkbox", value: o, checked: chosen.includes(o), class: "checkbox checkbox-sm", ...control(p), id: i === 0 ? p.id : `${p.id}-${i}` }), _jsx("span", { children: o })] })))] }));
115
+ },
116
+ parse(form, name) {
117
+ const values = form.all(name).filter((v) => v !== '');
118
+ if (values.length > 0)
119
+ return values;
120
+ return form.get(`${name}.many`) === undefined ? undefined : [];
121
+ },
122
+ };
91
123
  /** Whether `text` is HTML's valid date string (`YYYY-MM-DD`, a real day), which a `type=date` input keeps. */
92
124
  function isDateInput(text) {
93
125
  const m = /^(\d{4,})-(\d{2})-(\d{2})$/.exec(text);
@@ -288,14 +320,47 @@ function toolbarLabels(headings) {
288
320
  ...Object.fromEntries(headings.map((level) => [`heading${level}`, t('admin.richtext.heading', { level })])),
289
321
  bold: t('admin.richtext.bold'),
290
322
  italic: t('admin.richtext.italic'),
323
+ code: t('admin.richtext.code'),
291
324
  link: t('admin.richtext.link'),
292
325
  bulletList: t('admin.richtext.bulletList'),
293
326
  orderedList: t('admin.richtext.orderedList'),
294
327
  blockquote: t('admin.richtext.blockquote'),
295
328
  image: t('admin.richtext.image'),
296
329
  hardBreak: t('admin.richtext.hardBreak'),
330
+ table: t('admin.richtext.table'),
331
+ addRowAfter: t('admin.richtext.addRowAfter'),
332
+ addColumnAfter: t('admin.richtext.addColumnAfter'),
333
+ deleteRow: t('admin.richtext.deleteRow'),
334
+ deleteColumn: t('admin.richtext.deleteColumn'),
335
+ deleteTable: t('admin.richtext.deleteTable'),
297
336
  };
298
337
  }
338
+ const RICH_TEXT_MOUNT = 'min-h-40 [&_.ProseMirror]:min-h-40 [&_.ProseMirror]:p-3';
339
+ const INLINE_TEXT_MOUNT = 'min-h-10 [&_.ProseMirror]:min-h-10 [&_.ProseMirror]:px-3 [&_.ProseMirror]:py-2';
340
+ function renderRichText(p, inline) {
341
+ const opts = p.meta.richText ?? DEFAULT_RICH_TEXT;
342
+ const features = RICH_TEXT_FEATURES.filter((feature) => opts.features.includes(feature));
343
+ const value = p.value === undefined ? '' : typeof p.value === 'string' ? p.value : JSON.stringify(p.value);
344
+ const links = `/admin/pick/documents?${new URLSearchParams({ locale: p.locale, web: '1' }).toString()}`;
345
+ return (_jsxs(_Fragment, { children: [p.value !== undefined && _jsx("input", { type: "hidden", name: `${p.name}._present`, value: "", disabled: p.readOnly }), _jsxs("div", { "data-richtext": true, "data-inline": inline, "data-name": p.name, "data-features": features.join(' '), "data-headings": opts.headings.join(' '), "data-labels": JSON.stringify(toolbarLabels(opts.headings)), "data-readonly": p.readOnly, "data-pick-link": links, "data-pick-image": "/admin/pick/media?kind=image", class: "flex flex-col rounded-box border border-base-300 bg-base-100", children: [_jsx("div", { role: "toolbar", "aria-label": t('admin.richtext.toolbar', { field: p.meta.label }), "aria-controls": p.id, class: "flex flex-wrap gap-1 border-b border-base-300 p-1 empty:hidden" }), _jsx("div", { "data-richtext-mount": true, role: "group", id: p.id, "aria-label": p.meta.label, "aria-describedby": p.describedBy, "aria-invalid": p.invalid ? 'true' : undefined, class: `${inline ? INLINE_TEXT_MOUNT : RICH_TEXT_MOUNT} [&_.ProseMirror]:outline-none [&_.ProseMirror-focused]:ring-2 [&_.ProseMirror-focused]:ring-primary [&_p]:my-2 [&_h2]:my-3 [&_h2]:text-2xl [&_h2]:font-bold [&_h3]:my-3 [&_h3]:text-xl [&_h3]:font-bold [&_h4]:my-2 [&_h4]:text-lg [&_h4]:font-semibold [&_h5]:font-semibold [&_h6]:font-semibold [&_h1]:text-3xl [&_h1]:font-bold [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:list-decimal [&_ol]:pl-6 [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_a]:text-primary [&_a]:underline [&_code]:rounded [&_code]:bg-base-200 [&_code]:px-1 [&_code]:font-mono [&_code]:text-[0.9em] [&_table]:my-2 [&_table]:border-collapse [&_th]:border [&_th]:border-base-300 [&_th]:px-2 [&_th]:text-left [&_th]:font-semibold [&_td]:border [&_td]:border-base-300 [&_td]:px-2 [&_img]:inline-block [&_img]:max-h-40 [&_img]:rounded [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-primary` }), _jsx("p", { "data-richtext-error": true, hidden: true, class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.richtext.unreadable') }), _jsx("input", { type: "hidden", name: p.name, value: value, disabled: p.readOnly }), _jsx("noscript", { children: _jsx("p", { class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.form.needsJs') }) })] })] }));
346
+ }
347
+ function parseRichTextForm(form, name, optional, parse) {
348
+ const raw = form.get(name);
349
+ if (raw === undefined || raw === '')
350
+ return undefined;
351
+ let value;
352
+ try {
353
+ value = JSON.parse(raw);
354
+ }
355
+ catch {
356
+ return raw;
357
+ }
358
+ const parsed = parse(value);
359
+ if (!parsed.ok)
360
+ return value;
361
+ const stored = form.get(`${name}._present`) !== undefined;
362
+ return optional && !stored && richTextIsBlank(parsed.doc) ? undefined : parsed.doc;
363
+ }
299
364
  /**
300
365
  * Formatted text. Without JavaScript only the stored JSON is kept. Parse: the stored form of a valid doc; text
301
366
  * that isn't JSON, or JSON that isn't a doc the field allows, as it is, so validation reports it; a blank doc on
@@ -303,28 +368,12 @@ function toolbarLabels(headings) {
303
368
  */
304
369
  export const richTextWidget = {
305
370
  fieldset: true,
306
- render(p) {
307
- const opts = p.meta.richText ?? DEFAULT_RICH_TEXT;
308
- const features = RICH_TEXT_FEATURES.filter((feature) => opts.features.includes(feature));
309
- const value = p.value === undefined ? '' : typeof p.value === 'string' ? p.value : JSON.stringify(p.value);
310
- const links = `/admin/pick/documents?${new URLSearchParams({ locale: p.locale, web: '1' }).toString()}`;
311
- return (_jsxs(_Fragment, { children: [p.value !== undefined && _jsx("input", { type: "hidden", name: `${p.name}._present`, value: "", disabled: p.readOnly }), _jsxs("div", { "data-richtext": true, "data-name": p.name, "data-features": features.join(' '), "data-headings": opts.headings.join(' '), "data-labels": JSON.stringify(toolbarLabels(opts.headings)), "data-readonly": p.readOnly, "data-pick-link": links, "data-pick-image": "/admin/pick/media?kind=image", class: "flex flex-col rounded-box border border-base-300 bg-base-100", children: [_jsx("div", { role: "toolbar", "aria-label": t('admin.richtext.toolbar', { field: p.meta.label }), "aria-controls": p.id, class: "flex flex-wrap gap-1 border-b border-base-300 p-1 empty:hidden" }), _jsx("div", { "data-richtext-mount": true, role: "group", id: p.id, "aria-label": p.meta.label, "aria-describedby": p.describedBy, "aria-invalid": p.invalid ? 'true' : undefined, class: "min-h-40 [&_.ProseMirror]:min-h-40 [&_.ProseMirror]:p-3 [&_.ProseMirror]:outline-none [&_.ProseMirror-focused]:ring-2 [&_.ProseMirror-focused]:ring-primary [&_p]:my-2 [&_h2]:my-3 [&_h2]:text-2xl [&_h2]:font-bold [&_h3]:my-3 [&_h3]:text-xl [&_h3]:font-bold [&_h4]:my-2 [&_h4]:text-lg [&_h4]:font-semibold [&_h5]:font-semibold [&_h6]:font-semibold [&_h1]:text-3xl [&_h1]:font-bold [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:list-decimal [&_ol]:pl-6 [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_a]:text-primary [&_a]:underline [&_img]:inline-block [&_img]:max-h-40 [&_img]:rounded [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-primary" }), _jsx("p", { "data-richtext-error": true, hidden: true, class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.richtext.unreadable') }), _jsx("input", { type: "hidden", name: p.name, value: value, disabled: p.readOnly }), _jsx("noscript", { children: _jsx("p", { class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.form.needsJs') }) })] })] }));
312
- },
313
- parse(form, name, meta, optional) {
314
- const raw = form.get(name);
315
- if (raw === undefined || raw === '')
316
- return undefined;
317
- let value;
318
- try {
319
- value = JSON.parse(raw);
320
- }
321
- catch {
322
- return raw;
323
- }
324
- const parsed = parseRichText(value, meta.richText ?? DEFAULT_RICH_TEXT);
325
- if (!parsed.ok)
326
- return value;
327
- const stored = form.get(`${name}._present`) !== undefined;
328
- return optional && !stored && richTextIsBlank(parsed.doc) ? undefined : parsed.doc;
329
- },
371
+ render: (p) => renderRichText(p, false),
372
+ parse: (form, name, meta, optional) => parseRichTextForm(form, name, optional, (value) => parseRichText(value, meta.richText ?? DEFAULT_RICH_TEXT)),
373
+ };
374
+ /** One line of formatted text: the rich-text editor marked `data-inline`, one line tall, holding one paragraph. */
375
+ export const inlineTextWidget = {
376
+ fieldset: true,
377
+ render: (p) => renderRichText(p, true),
378
+ parse: (form, name, _meta, optional) => parseRichTextForm(form, name, optional, parseInlineText),
330
379
  };
@@ -72,8 +72,8 @@ export async function inspectUpload(deps, bytes, filename) {
72
72
  const meta = await sharp(bytes).metadata();
73
73
  if (!meta.width || !meta.height)
74
74
  throw new Error('no size');
75
- // Force a full decode so truncated files are caught.
76
- await sharp(bytes).rotate().toBuffer();
75
+ // Force a full decode so truncated files are caught. One raw channel: no encoding, little memory.
76
+ await sharp(bytes).extractChannel(0).raw().toBuffer();
77
77
  const swap = (meta.orientation ?? 1) >= 5;
78
78
  width = swap ? meta.height : meta.width;
79
79
  height = swap ? meta.width : meta.height;