@cocoar/vue-markdown-form 3.1.0-beta.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.
Files changed (41) hide show
  1. package/dist/BlockFieldEmbed.vue.d.ts +9 -0
  2. package/dist/BlockFieldEmbed.vue.d.ts.map +1 -0
  3. package/dist/CoarMarkdownForm.vue.d.ts +28 -0
  4. package/dist/CoarMarkdownForm.vue.d.ts.map +1 -0
  5. package/dist/FieldHost.vue.d.ts +7 -0
  6. package/dist/FieldHost.vue.d.ts.map +1 -0
  7. package/dist/InlineTextRenderer.d.ts +33 -0
  8. package/dist/InlineTextRenderer.d.ts.map +1 -0
  9. package/dist/ParagraphRenderer.d.ts +33 -0
  10. package/dist/ParagraphRenderer.d.ts.map +1 -0
  11. package/dist/context.d.ts +16 -0
  12. package/dist/context.d.ts.map +1 -0
  13. package/dist/field-layout.d.ts +9 -0
  14. package/dist/field-layout.d.ts.map +1 -0
  15. package/dist/fields/BooleanFieldControl.vue.d.ts +9 -0
  16. package/dist/fields/BooleanFieldControl.vue.d.ts.map +1 -0
  17. package/dist/fields/DateFieldControl.vue.d.ts +9 -0
  18. package/dist/fields/DateFieldControl.vue.d.ts.map +1 -0
  19. package/dist/fields/DateTimeFieldControl.vue.d.ts +9 -0
  20. package/dist/fields/DateTimeFieldControl.vue.d.ts.map +1 -0
  21. package/dist/fields/MarkdownFieldControl.vue.d.ts +9 -0
  22. package/dist/fields/MarkdownFieldControl.vue.d.ts.map +1 -0
  23. package/dist/fields/MarkdownFieldReadonly.vue.d.ts +5 -0
  24. package/dist/fields/MarkdownFieldReadonly.vue.d.ts.map +1 -0
  25. package/dist/fields/NumberFieldControl.vue.d.ts +9 -0
  26. package/dist/fields/NumberFieldControl.vue.d.ts.map +1 -0
  27. package/dist/fields/SelectFieldControl.vue.d.ts +9 -0
  28. package/dist/fields/SelectFieldControl.vue.d.ts.map +1 -0
  29. package/dist/fields/TextFieldControl.vue.d.ts +9 -0
  30. package/dist/fields/TextFieldControl.vue.d.ts.map +1 -0
  31. package/dist/index.d.ts +7 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +1027 -0
  34. package/dist/registry.d.ts +4 -0
  35. package/dist/registry.d.ts.map +1 -0
  36. package/dist/template-parser.d.ts +18 -0
  37. package/dist/template-parser.d.ts.map +1 -0
  38. package/dist/types.d.ts +88 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/package.json +59 -0
  41. package/styles/markdown-form.css +177 -0
package/dist/index.js ADDED
@@ -0,0 +1,1027 @@
1
+ import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createVNode as o, defineComponent as s, h as c, inject as l, markRaw as u, normalizeClass as d, normalizeStyle as f, openBlock as p, provide as m, renderList as h, resolveDynamicComponent as g, toDisplayString as _, unref as v, useAttrs as y, watch as b, withCtx as x } from "vue";
2
+ import { CoarMarkdown as S, defaultMarkdownRenderers as C } from "@cocoar/vue-markdown";
3
+ import { parse as w, parseEmbedDirective as T, toEmbedProps as E } from "@cocoar/vue-markdown-core";
4
+ import { Temporal as D } from "@js-temporal/polyfill";
5
+ import { CoarCheckbox as O, CoarNumberInput as k, CoarPlainDatePicker as A, CoarPlainDateTimePicker as j, CoarSelect as M, CoarTextInput as N } from "@cocoar/vue-ui";
6
+ import { CoarMarkdownEditor as ee } from "@cocoar/vue-markdown-editor";
7
+ //#region src/field-layout.ts
8
+ var P = new Set([
9
+ "small",
10
+ "medium",
11
+ "large"
12
+ ]), F = /^(\d+(?:\.\d+)?)(ch|rem)$/;
13
+ function I(e, t) {
14
+ let n = e?.trim() || "medium";
15
+ if (P.has(n)) return t[n];
16
+ if (n === "fill" || n === "full") return "100%";
17
+ let r = F.exec(n);
18
+ if (!r) return t.medium;
19
+ let i = Number(r[1]), a = r[2] === "ch" ? 100 : 80;
20
+ return i <= 0 || i > a ? t.medium : n;
21
+ }
22
+ function L(e) {
23
+ if (e === void 0 || e.trim() === "") return;
24
+ let t = Number(e);
25
+ return Number.isFinite(t) ? t : void 0;
26
+ }
27
+ function R(e, t) {
28
+ let n = [], r = "", i = !1;
29
+ for (let a of e) i ? (r += a, i = !1) : a === "\\" ? i = !0 : a === t ? (n.push(r), r = "") : r += a;
30
+ return i && (r += "\\"), n.push(r), n;
31
+ }
32
+ function z(e) {
33
+ return e ? R(e, "|").map((e) => {
34
+ let [t, ...n] = R(e, ":"), r = t.trim();
35
+ return {
36
+ value: r,
37
+ label: n.join(":").trim() || r
38
+ };
39
+ }).filter((e) => e.value.length > 0) : [];
40
+ }
41
+ var B = {
42
+ design: "coar",
43
+ locale: "en",
44
+ widths: {
45
+ small: "10ch",
46
+ medium: "18ch",
47
+ large: "32ch"
48
+ },
49
+ decorations: {
50
+ markdownFrame: !0,
51
+ inlineUnderline: !0
52
+ },
53
+ messages: {
54
+ required: (e) => `${e.props.label || e.id} is required.`,
55
+ missingId: () => "A form field is missing its id.",
56
+ duplicateId: (e) => `Field id "${e.id}" is used more than once.`,
57
+ unknownType: (e) => `Unknown field type "${e.type}".`,
58
+ unsupportedLayout: (e) => `Field type "${e.type}" does not support layout "${e.layout}".`,
59
+ booleanTrue: "Yes",
60
+ booleanFalse: "No",
61
+ empty: "—"
62
+ },
63
+ markdownTools: [
64
+ "bold",
65
+ "italic",
66
+ "strikethrough",
67
+ "inlineCode",
68
+ "headings",
69
+ "divider",
70
+ "bulletList",
71
+ "orderedList",
72
+ "taskList",
73
+ "blockquote",
74
+ "divider",
75
+ "table",
76
+ "image",
77
+ "clearFormatting",
78
+ "divider",
79
+ "undo",
80
+ "redo"
81
+ ]
82
+ };
83
+ function V(e) {
84
+ return {
85
+ ...B,
86
+ ...e,
87
+ widths: {
88
+ ...B.widths,
89
+ ...e?.widths
90
+ },
91
+ decorations: {
92
+ ...B.decorations,
93
+ ...e?.decorations
94
+ },
95
+ messages: {
96
+ ...B.messages,
97
+ ...e?.messages
98
+ },
99
+ markdownTools: e?.markdownTools ?? B.markdownTools
100
+ };
101
+ }
102
+ var H = Symbol("coar:markdown-form-runtime");
103
+ function U() {
104
+ let e = l(H);
105
+ if (!e) throw Error("Markdown form fields require a CoarMarkdownForm parent.");
106
+ return e;
107
+ }
108
+ //#endregion
109
+ //#region src/FieldHost.vue?vue&type=script&setup=true&lang.ts
110
+ var te = {
111
+ key: 0,
112
+ class: "coar-markdown-form-field__invalid"
113
+ }, ne = {
114
+ key: 3,
115
+ class: "coar-markdown-form-field__readonly"
116
+ }, W = /* @__PURE__ */ s({
117
+ __name: "FieldHost",
118
+ props: { field: {} },
119
+ setup(e) {
120
+ let a = e, o = U(), s = t(() => o.registry.value[a.field.type]), c = t(() => {
121
+ let e = o.getValue(a.field.id);
122
+ return e === void 0 ? s.value?.defaultValue?.(a.field) : e;
123
+ }), l = t(() => o.validation.value.errors[a.field.id]), u = t(() => I(a.field.width, o.context.value.widths)), m = t(() => a.field.width === "fill" || a.field.width === "full" ? a.field.width : "fixed"), h = t(() => a.field.source === "block" ? "section" : "span"), y = t(() => s.value ? s.value.formatReadonly?.(c.value, a.field, o.context.value) ?? String(c.value ?? o.context.value.messages.empty) : o.context.value.messages.empty), b = t(() => a.field.id ? s.value ? "" : o.context.value.messages.unknownType(a.field) : o.context.value.messages.missingId(a.field)), S = t(() => a.field.source === "block" && o.mode.value === "readonly" && !o.context.value.decorations.markdownFrame);
124
+ function C(e) {
125
+ o.updateValue(a.field, e);
126
+ }
127
+ return (t, a) => (p(), n(g(h.value), {
128
+ class: d(["coar-markdown-form-field", [
129
+ `coar-markdown-form-field--${e.field.source}`,
130
+ `coar-markdown-form-field--layout-${e.field.layout}`,
131
+ `coar-markdown-form-field--width-${m.value}`,
132
+ {
133
+ "coar-markdown-form-field--readonly": v(o).mode.value === "readonly",
134
+ "coar-markdown-form-field--underlined": v(o).mode.value === "readonly" && e.field.source === "inline" && v(o).context.value.decorations.inlineUnderline,
135
+ "coar-markdown-form-field--frameless": S.value,
136
+ "coar-markdown-form-field--error": v(o).showErrors.value && !!l.value,
137
+ "coar-markdown-form-field--invalid": !!b.value
138
+ }
139
+ ]]),
140
+ style: f(e.field.source === "inline" ? {
141
+ width: u.value,
142
+ maxWidth: "100%"
143
+ } : void 0),
144
+ "data-field-id": e.field.id || void 0,
145
+ "data-field-type": e.field.type,
146
+ "aria-label": e.field.props.label || e.field.id || e.field.type,
147
+ "aria-invalid": v(o).showErrors.value && l.value ? "true" : void 0,
148
+ title: b.value || (v(o).showErrors.value ? l.value : void 0)
149
+ }, {
150
+ default: x(() => [b.value ? (p(), i("span", te, _(b.value), 1)) : v(o).mode.value === "fill" && s.value ? (p(), n(g(s.value.control), {
151
+ key: 1,
152
+ field: e.field,
153
+ "model-value": c.value,
154
+ context: v(o).context.value,
155
+ error: v(o).showErrors.value ? l.value : void 0,
156
+ "onUpdate:modelValue": C
157
+ }, null, 8, [
158
+ "field",
159
+ "model-value",
160
+ "context",
161
+ "error"
162
+ ])) : s.value?.readonly ? (p(), n(g(s.value.readonly), {
163
+ key: 2,
164
+ field: e.field,
165
+ "model-value": c.value,
166
+ context: v(o).context.value
167
+ }, null, 8, [
168
+ "field",
169
+ "model-value",
170
+ "context"
171
+ ])) : (p(), i("span", ne, _(y.value), 1)), v(o).showErrors.value && l.value ? (p(), i("small", {
172
+ key: 4,
173
+ class: d(["coar-markdown-form-field__error", { "coar-markdown-form-field__error--inline": e.field.layout === "inline" }])
174
+ }, _(l.value), 3)) : r("", !0)]),
175
+ _: 1
176
+ }, 8, [
177
+ "class",
178
+ "style",
179
+ "data-field-id",
180
+ "data-field-type",
181
+ "aria-label",
182
+ "aria-invalid",
183
+ "title"
184
+ ]));
185
+ }
186
+ }), G = ":field{", re = new Set([
187
+ "inline",
188
+ "row",
189
+ "stacked",
190
+ "block"
191
+ ]);
192
+ function ie(e, t) {
193
+ let n = 0;
194
+ for (let r = t - 1; r >= 0 && e[r] === "\\"; --r) n += 1;
195
+ return n % 2 == 1;
196
+ }
197
+ function ae(e, t) {
198
+ let n = null, r = !1;
199
+ for (let i = t; i < e.length; i += 1) {
200
+ let t = e[i];
201
+ if (r) {
202
+ r = !1;
203
+ continue;
204
+ }
205
+ if (t === "\\") {
206
+ r = !0;
207
+ continue;
208
+ }
209
+ if (n) {
210
+ t === n && (n = null);
211
+ continue;
212
+ }
213
+ if (t === "\"" || t === "'") {
214
+ n = t;
215
+ continue;
216
+ }
217
+ if (t === "}") return i;
218
+ }
219
+ return -1;
220
+ }
221
+ function oe(e, t) {
222
+ if (!(t in e)) return !1;
223
+ let n = e[t].trim().toLowerCase();
224
+ return n === "" || ![
225
+ "false",
226
+ "0",
227
+ "no",
228
+ "off"
229
+ ].includes(n);
230
+ }
231
+ function K(e, t, n, r = "text") {
232
+ let i = e.layout, a = t === "block" ? "block" : "inline", o = re.has(i) ? i : a;
233
+ return {
234
+ occurrenceId: n,
235
+ id: (e.id ?? "").trim(),
236
+ type: (e.type || r).trim(),
237
+ source: t,
238
+ layout: o,
239
+ width: e.width || (o === "block" || o === "stacked" ? "full" : "medium"),
240
+ required: oe(e, "required"),
241
+ props: e
242
+ };
243
+ }
244
+ function q(e, t = "inline") {
245
+ let n = [], r = 0, i = 0, a = 0;
246
+ for (; i < e.length;) {
247
+ let o = e.indexOf(G, i);
248
+ for (; o >= 0 && ie(e, o);) o = e.indexOf(G, o + 7);
249
+ if (o < 0) break;
250
+ let s = ae(e, o + 7);
251
+ if (s < 0) break;
252
+ let c = T(`:::field{${e.slice(o + 7, s)}}`);
253
+ if (!c) {
254
+ i = s + 1;
255
+ continue;
256
+ }
257
+ o > r && n.push({
258
+ type: "text",
259
+ text: e.slice(r, o)
260
+ }), n.push({
261
+ type: "field",
262
+ field: K(c.props, "inline", `${t}:${o}:${a}`)
263
+ }), a += 1, r = s + 1, i = r;
264
+ }
265
+ return r < e.length && n.push({
266
+ type: "text",
267
+ text: e.slice(r)
268
+ }), n.length > 0 ? n : [{
269
+ type: "text",
270
+ text: e
271
+ }];
272
+ }
273
+ function J(e) {
274
+ if (e.type !== "embed") return null;
275
+ let t = typeof e.attrs?.key == "string" ? e.attrs.key : "";
276
+ return t !== "field" && t !== "markdown-field" ? null : K(E(e.attrs?.props), "block", e.id, t === "markdown-field" ? "markdown" : "text");
277
+ }
278
+ function Y(e) {
279
+ let t = [], n = (e) => {
280
+ let r = J(e);
281
+ if (r && t.push(r), e.type === "text" && e.text) for (let n of q(e.text, e.id)) n.type === "field" && t.push(n.field);
282
+ for (let t of e.children ?? []) n(t);
283
+ };
284
+ for (let t of e.nodes) n(t);
285
+ return t;
286
+ }
287
+ function X(e, t, n) {
288
+ let r = Y(e), i = [], a = /* @__PURE__ */ new Set();
289
+ for (let e of r) {
290
+ if (!e.id) {
291
+ i.push({
292
+ code: "missing-id",
293
+ message: n.missingId(e),
294
+ field: e
295
+ });
296
+ continue;
297
+ }
298
+ a.has(e.id) ? i.push({
299
+ code: "duplicate-id",
300
+ message: n.duplicateId(e),
301
+ field: e
302
+ }) : a.add(e.id);
303
+ let r = t[e.type];
304
+ r ? r.layouts && !r.layouts.includes(e.layout) && i.push({
305
+ code: "unsupported-layout",
306
+ message: n.unsupportedLayout(e),
307
+ field: e
308
+ }) : i.push({
309
+ code: "unknown-type",
310
+ message: n.unknownType(e),
311
+ field: e
312
+ });
313
+ }
314
+ return {
315
+ fields: r,
316
+ issues: i
317
+ };
318
+ }
319
+ //#endregion
320
+ //#region src/BlockFieldEmbed.vue
321
+ var se = /* @__PURE__ */ s({
322
+ __name: "BlockFieldEmbed",
323
+ props: {
324
+ fieldProps: {},
325
+ defaultType: { default: "text" }
326
+ },
327
+ setup(e) {
328
+ let r = e, i = t(() => K(E(r.fieldProps), "block", `block:${String(r.fieldProps.id ?? crypto.randomUUID?.() ?? "field")}`, r.defaultType));
329
+ return (e, t) => (p(), n(W, { field: i.value }, null, 8, ["field"]));
330
+ }
331
+ }), ce = s({
332
+ name: "CoarMarkdownFormTextRenderer",
333
+ props: {
334
+ node: {
335
+ type: Object,
336
+ required: !0
337
+ },
338
+ renderChildren: {
339
+ type: Function,
340
+ required: !0
341
+ },
342
+ renderNodes: {
343
+ type: Function,
344
+ required: !0
345
+ }
346
+ },
347
+ setup(e) {
348
+ return () => c("span", { class: "coar-markdown-form-text-fragment" }, q(e.node.text ?? "", e.node.id).map((e, t) => e.type === "text" ? e.text : c(W, {
349
+ key: `${e.field.occurrenceId}:${t}`,
350
+ field: e.field
351
+ })));
352
+ }
353
+ });
354
+ //#endregion
355
+ //#region src/ParagraphRenderer.ts
356
+ function Z(e) {
357
+ if (e.type === "text" && e.text) {
358
+ for (let t of q(e.text, e.id)) if (t.type === "field" && t.field.layout !== "inline") return t.field.layout;
359
+ }
360
+ for (let t of e.children ?? []) {
361
+ let e = Z(t);
362
+ if (e) return e;
363
+ }
364
+ return null;
365
+ }
366
+ var le = s({
367
+ name: "CoarMarkdownFormParagraphRenderer",
368
+ props: {
369
+ node: {
370
+ type: Object,
371
+ required: !0
372
+ },
373
+ renderChildren: {
374
+ type: Function,
375
+ required: !0
376
+ },
377
+ renderNodes: {
378
+ type: Function,
379
+ required: !0
380
+ }
381
+ },
382
+ setup(e) {
383
+ return () => {
384
+ let t = Z(e.node);
385
+ return c("p", { class: ["coar-markdown-paragraph", t === "row" || t === "stacked" ? `coar-markdown-form-paragraph--${t}` : void 0] }, e.renderChildren());
386
+ };
387
+ }
388
+ }), ue = [
389
+ "id",
390
+ "value",
391
+ "rows",
392
+ "maxlength",
393
+ "placeholder",
394
+ "required",
395
+ "aria-invalid"
396
+ ], de = [
397
+ "id",
398
+ "type",
399
+ "value",
400
+ "maxlength",
401
+ "placeholder",
402
+ "required",
403
+ "aria-invalid"
404
+ ], fe = /* @__PURE__ */ s({
405
+ __name: "TextFieldControl",
406
+ props: {
407
+ field: {},
408
+ modelValue: {},
409
+ context: {},
410
+ error: {}
411
+ },
412
+ emits: ["update:modelValue"],
413
+ setup(e, { emit: r }) {
414
+ let a = e, o = r, s = t(() => typeof a.modelValue == "string" ? a.modelValue : ""), c = t(() => Math.max(1, Math.trunc(L(a.field.props.rows) ?? 1))), l = t(() => L(a.field.props.maxLength)), u = t(() => {
415
+ let e = a.field.props.inputType;
416
+ return e === "email" || e === "url" || e === "tel" || e === "search" ? e : "text";
417
+ });
418
+ function d(e) {
419
+ o("update:modelValue", e.target.value);
420
+ }
421
+ return (t, r) => e.context.design === "coar" ? (p(), n(v(N), {
422
+ key: 0,
423
+ id: `markdown-form-${e.field.id}`,
424
+ "model-value": s.value,
425
+ placeholder: e.field.props.placeholder || e.field.id,
426
+ rows: c.value,
427
+ type: u.value,
428
+ maxlength: l.value,
429
+ required: e.field.required,
430
+ error: !!e.error,
431
+ size: "xs",
432
+ clearable: "",
433
+ "onUpdate:modelValue": r[0] ||= (e) => o("update:modelValue", e)
434
+ }, null, 8, [
435
+ "id",
436
+ "model-value",
437
+ "placeholder",
438
+ "rows",
439
+ "type",
440
+ "maxlength",
441
+ "required",
442
+ "error"
443
+ ])) : c.value > 1 ? (p(), i("textarea", {
444
+ key: 1,
445
+ id: `markdown-form-${e.field.id}`,
446
+ class: "coar-markdown-form-basic-control",
447
+ value: s.value,
448
+ rows: c.value,
449
+ maxlength: l.value,
450
+ placeholder: e.field.props.placeholder || e.field.id,
451
+ required: e.field.required,
452
+ "aria-invalid": e.error ? "true" : void 0,
453
+ onInput: d
454
+ }, null, 40, ue)) : (p(), i("input", {
455
+ key: 2,
456
+ id: `markdown-form-${e.field.id}`,
457
+ class: "coar-markdown-form-basic-control",
458
+ type: u.value,
459
+ value: s.value,
460
+ maxlength: l.value,
461
+ placeholder: e.field.props.placeholder || e.field.id,
462
+ required: e.field.required,
463
+ "aria-invalid": e.error ? "true" : void 0,
464
+ onInput: d
465
+ }, null, 40, de));
466
+ }
467
+ }), pe = [
468
+ "id",
469
+ "value",
470
+ "placeholder",
471
+ "min",
472
+ "max",
473
+ "step",
474
+ "required",
475
+ "aria-invalid"
476
+ ], me = /* @__PURE__ */ s({
477
+ __name: "NumberFieldControl",
478
+ props: {
479
+ field: {},
480
+ modelValue: {},
481
+ context: {},
482
+ error: {}
483
+ },
484
+ emits: ["update:modelValue"],
485
+ setup(e, { emit: r }) {
486
+ let a = e, o = r, s = t(() => typeof a.modelValue == "number" && Number.isFinite(a.modelValue) ? a.modelValue : typeof a.modelValue == "string" ? L(a.modelValue) ?? null : null), c = t(() => L(a.field.props.min)), l = t(() => L(a.field.props.max)), u = t(() => L(a.field.props.step) ?? 1), d = t(() => Math.max(0, Math.trunc(L(a.field.props.decimals) ?? 0)));
487
+ function f(e) {
488
+ let t = e.target.value;
489
+ o("update:modelValue", t === "" ? null : Number(t));
490
+ }
491
+ return (t, r) => e.context.design === "coar" ? (p(), n(v(k), {
492
+ key: 0,
493
+ id: `markdown-form-${e.field.id}`,
494
+ "model-value": s.value,
495
+ placeholder: e.field.props.placeholder || e.field.id,
496
+ min: c.value,
497
+ max: l.value,
498
+ step: u.value,
499
+ decimals: d.value,
500
+ suffix: e.field.props.suffix,
501
+ required: e.field.required,
502
+ error: !!e.error,
503
+ locale: e.context.locale,
504
+ size: "xs",
505
+ "stepper-buttons": "both",
506
+ clearable: "",
507
+ "onUpdate:modelValue": r[0] ||= (e) => o("update:modelValue", e)
508
+ }, null, 8, [
509
+ "id",
510
+ "model-value",
511
+ "placeholder",
512
+ "min",
513
+ "max",
514
+ "step",
515
+ "decimals",
516
+ "suffix",
517
+ "required",
518
+ "error",
519
+ "locale"
520
+ ])) : (p(), i("input", {
521
+ key: 1,
522
+ id: `markdown-form-${e.field.id}`,
523
+ class: "coar-markdown-form-basic-control",
524
+ type: "number",
525
+ value: s.value ?? "",
526
+ placeholder: e.field.props.placeholder || e.field.id,
527
+ min: c.value,
528
+ max: l.value,
529
+ step: u.value,
530
+ required: e.field.required,
531
+ "aria-invalid": e.error ? "true" : void 0,
532
+ onInput: f
533
+ }, null, 40, pe));
534
+ }
535
+ }), he = [
536
+ "id",
537
+ "value",
538
+ "placeholder",
539
+ "min",
540
+ "max",
541
+ "required",
542
+ "aria-invalid"
543
+ ], ge = /* @__PURE__ */ s({
544
+ __name: "DateFieldControl",
545
+ props: {
546
+ field: {},
547
+ modelValue: {},
548
+ context: {},
549
+ error: {}
550
+ },
551
+ emits: ["update:modelValue"],
552
+ setup(e, { emit: r }) {
553
+ let a = e, o = r, s = {
554
+ pattern: "dd.mm.yyyy",
555
+ firstDayOfWeek: 1
556
+ };
557
+ function c(e) {
558
+ if (typeof e != "string" || !e) return null;
559
+ try {
560
+ return D.PlainDate.from(e);
561
+ } catch {
562
+ return null;
563
+ }
564
+ }
565
+ let l = t({
566
+ get: () => c(a.modelValue),
567
+ set: (e) => o("update:modelValue", e?.toString() ?? "")
568
+ }), u = t(() => c(a.field.props.min)), d = t(() => c(a.field.props.max));
569
+ function f(e) {
570
+ o("update:modelValue", e.target.value);
571
+ }
572
+ return (t, r) => e.context.design === "coar" ? (p(), n(v(A), {
573
+ key: 0,
574
+ id: `markdown-form-${e.field.id}`,
575
+ modelValue: l.value,
576
+ "onUpdate:modelValue": r[0] ||= (e) => l.value = e,
577
+ placeholder: e.field.props.placeholder || e.field.id,
578
+ required: e.field.required,
579
+ error: !!e.error,
580
+ locale: e.context.locale,
581
+ "date-format": s,
582
+ min: u.value,
583
+ max: d.value,
584
+ size: "xs",
585
+ clearable: ""
586
+ }, null, 8, [
587
+ "id",
588
+ "modelValue",
589
+ "placeholder",
590
+ "required",
591
+ "error",
592
+ "locale",
593
+ "min",
594
+ "max"
595
+ ])) : (p(), i("input", {
596
+ key: 1,
597
+ id: `markdown-form-${e.field.id}`,
598
+ class: "coar-markdown-form-basic-control",
599
+ type: "date",
600
+ value: typeof e.modelValue == "string" ? e.modelValue : "",
601
+ placeholder: e.field.props.placeholder || e.field.id,
602
+ min: e.field.props.min,
603
+ max: e.field.props.max,
604
+ required: e.field.required,
605
+ "aria-invalid": e.error ? "true" : void 0,
606
+ onInput: f
607
+ }, null, 40, he));
608
+ }
609
+ }), _e = [
610
+ "id",
611
+ "value",
612
+ "placeholder",
613
+ "min",
614
+ "max",
615
+ "required",
616
+ "aria-invalid"
617
+ ], ve = /* @__PURE__ */ s({
618
+ __name: "DateTimeFieldControl",
619
+ props: {
620
+ field: {},
621
+ modelValue: {},
622
+ context: {},
623
+ error: {}
624
+ },
625
+ emits: ["update:modelValue"],
626
+ setup(e, { emit: r }) {
627
+ let a = e, o = r, s = {
628
+ pattern: "dd.mm.yyyy",
629
+ firstDayOfWeek: 1
630
+ };
631
+ function c(e) {
632
+ if (typeof e != "string" || !e) return null;
633
+ try {
634
+ return D.PlainDateTime.from(e);
635
+ } catch {
636
+ return null;
637
+ }
638
+ }
639
+ let l = t({
640
+ get: () => c(a.modelValue),
641
+ set: (e) => o("update:modelValue", e?.toString({ smallestUnit: "minute" }) ?? "")
642
+ }), u = t(() => c(a.field.props.min)), d = t(() => c(a.field.props.max)), f = t(() => {
643
+ let e = L(a.field.props.minuteStep);
644
+ return e === 1 || e === 5 || e === 10 || e === 15 ? e : 15;
645
+ });
646
+ function m(e) {
647
+ o("update:modelValue", e.target.value);
648
+ }
649
+ return (t, r) => e.context.design === "coar" ? (p(), n(v(j), {
650
+ key: 0,
651
+ id: `markdown-form-${e.field.id}`,
652
+ modelValue: l.value,
653
+ "onUpdate:modelValue": r[0] ||= (e) => l.value = e,
654
+ placeholder: e.field.props.placeholder || e.field.id,
655
+ required: e.field.required,
656
+ error: !!e.error,
657
+ locale: e.context.locale,
658
+ "date-format": s,
659
+ min: u.value,
660
+ max: d.value,
661
+ "minute-step": f.value,
662
+ "use24-hour": !0,
663
+ size: "xs",
664
+ clearable: ""
665
+ }, null, 8, [
666
+ "id",
667
+ "modelValue",
668
+ "placeholder",
669
+ "required",
670
+ "error",
671
+ "locale",
672
+ "min",
673
+ "max",
674
+ "minute-step"
675
+ ])) : (p(), i("input", {
676
+ key: 1,
677
+ id: `markdown-form-${e.field.id}`,
678
+ class: "coar-markdown-form-basic-control",
679
+ type: "datetime-local",
680
+ value: typeof e.modelValue == "string" ? e.modelValue : "",
681
+ placeholder: e.field.props.placeholder || e.field.id,
682
+ min: e.field.props.min,
683
+ max: e.field.props.max,
684
+ required: e.field.required,
685
+ "aria-invalid": e.error ? "true" : void 0,
686
+ onInput: m
687
+ }, null, 40, _e));
688
+ }
689
+ }), ye = {
690
+ key: 1,
691
+ class: "coar-markdown-form-basic-checkbox"
692
+ }, be = [
693
+ "id",
694
+ "checked",
695
+ "required",
696
+ "aria-invalid"
697
+ ], xe = { key: 0 }, Se = /* @__PURE__ */ s({
698
+ __name: "BooleanFieldControl",
699
+ props: {
700
+ field: {},
701
+ modelValue: {},
702
+ context: {},
703
+ error: {}
704
+ },
705
+ emits: ["update:modelValue"],
706
+ setup(e, { emit: o }) {
707
+ let s = e, c = o, l = t(() => s.modelValue === !0 || s.modelValue === "true"), u = t(() => s.field.source === "block" && s.field.props.label || "");
708
+ function d(e) {
709
+ c("update:modelValue", e.target.checked);
710
+ }
711
+ return (t, o) => e.context.design === "coar" ? (p(), n(v(O), {
712
+ key: 0,
713
+ id: `markdown-form-${e.field.id}`,
714
+ "model-value": l.value,
715
+ label: u.value,
716
+ required: e.field.required,
717
+ error: !!e.error,
718
+ size: "xs",
719
+ "onUpdate:modelValue": o[0] ||= (e) => c("update:modelValue", e)
720
+ }, null, 8, [
721
+ "id",
722
+ "model-value",
723
+ "label",
724
+ "required",
725
+ "error"
726
+ ])) : (p(), i("label", ye, [a("input", {
727
+ id: `markdown-form-${e.field.id}`,
728
+ type: "checkbox",
729
+ checked: l.value,
730
+ required: e.field.required,
731
+ "aria-invalid": e.error ? "true" : void 0,
732
+ onChange: d
733
+ }, null, 40, be), u.value ? (p(), i("span", xe, _(u.value), 1)) : r("", !0)]));
734
+ }
735
+ }), Ce = [
736
+ "id",
737
+ "value",
738
+ "required",
739
+ "aria-invalid"
740
+ ], we = { value: "" }, Te = ["value"], Ee = /* @__PURE__ */ s({
741
+ __name: "SelectFieldControl",
742
+ props: {
743
+ field: {},
744
+ modelValue: {},
745
+ context: {},
746
+ error: {}
747
+ },
748
+ emits: ["update:modelValue"],
749
+ setup(r, { emit: o }) {
750
+ let s = r, c = o, l = t(() => typeof s.modelValue == "string" ? s.modelValue : null), u = t(() => z(s.field.props.options));
751
+ function d(e) {
752
+ let t = e.target.value;
753
+ c("update:modelValue", t || null);
754
+ }
755
+ return (t, o) => r.context.design === "coar" ? (p(), n(v(M), {
756
+ key: 0,
757
+ id: `markdown-form-${r.field.id}`,
758
+ "model-value": l.value,
759
+ options: u.value,
760
+ placeholder: r.field.props.placeholder || r.field.id,
761
+ error: !!r.error,
762
+ size: "xs",
763
+ clearable: "",
764
+ "onUpdate:modelValue": o[0] ||= (e) => c("update:modelValue", e)
765
+ }, null, 8, [
766
+ "id",
767
+ "model-value",
768
+ "options",
769
+ "placeholder",
770
+ "error"
771
+ ])) : (p(), i("select", {
772
+ key: 1,
773
+ id: `markdown-form-${r.field.id}`,
774
+ class: "coar-markdown-form-basic-control",
775
+ value: l.value ?? "",
776
+ required: r.field.required,
777
+ "aria-invalid": r.error ? "true" : void 0,
778
+ onChange: d
779
+ }, [a("option", we, _(r.field.props.placeholder || "—"), 1), (p(!0), i(e, null, h(u.value, (e) => (p(), i("option", {
780
+ key: e.value,
781
+ value: e.value
782
+ }, _(e.label), 9, Te))), 128))], 40, Ce));
783
+ }
784
+ }), De = /* @__PURE__ */ s({
785
+ __name: "MarkdownFieldControl",
786
+ props: {
787
+ field: {},
788
+ modelValue: {},
789
+ context: {},
790
+ error: {}
791
+ },
792
+ emits: ["update:modelValue"],
793
+ setup(e, { emit: r }) {
794
+ let i = e, a = r, o = t(() => typeof i.modelValue == "string" ? i.modelValue : ""), s = t(() => [...i.context.markdownTools]);
795
+ return (t, r) => (p(), n(v(ee), {
796
+ "model-value": o.value,
797
+ placeholder: e.field.props.placeholder || e.field.id,
798
+ tools: s.value,
799
+ "toolbar-mode": "external",
800
+ "toolbar-position": "top",
801
+ flavor: "gfm",
802
+ "onUpdate:modelValue": r[0] ||= (e) => a("update:modelValue", e)
803
+ }, null, 8, [
804
+ "model-value",
805
+ "placeholder",
806
+ "tools"
807
+ ]));
808
+ }
809
+ }), Oe = {
810
+ key: 1,
811
+ class: "coar-markdown-form-field__empty"
812
+ }, ke = /* @__PURE__ */ s({
813
+ __name: "MarkdownFieldReadonly",
814
+ props: {
815
+ field: {},
816
+ modelValue: {},
817
+ context: {}
818
+ },
819
+ setup(e) {
820
+ let r = e, a = t(() => typeof r.modelValue == "string" ? r.modelValue : ""), o = t(() => w(a.value));
821
+ return (t, r) => a.value ? (p(), n(v(S), {
822
+ key: 0,
823
+ doc: o.value
824
+ }, null, 8, ["doc"])) : (p(), i("span", Oe, _(e.context.messages.empty), 1));
825
+ }
826
+ }), Q = [
827
+ "inline",
828
+ "row",
829
+ "stacked",
830
+ "block"
831
+ ];
832
+ function $(e) {
833
+ return e == null || e === "" || e === !1 || Array.isArray(e) && e.length === 0;
834
+ }
835
+ function Ae(e, t, n) {
836
+ let r = typeof e == "number" ? e : Number(e);
837
+ if (!Number.isFinite(r)) return String(e ?? n.messages.empty);
838
+ let i = Math.max(0, Math.trunc(L(t.props.decimals) ?? 0)), a = new Intl.NumberFormat(n.locale, {
839
+ minimumFractionDigits: i,
840
+ maximumFractionDigits: i
841
+ }).format(r);
842
+ return t.props.suffix ? `${a} ${t.props.suffix}` : a;
843
+ }
844
+ function je(e, t) {
845
+ if (typeof e != "string" || !e) return t.messages.empty;
846
+ try {
847
+ return D.PlainDate.from(e).toLocaleString(t.locale, { dateStyle: "medium" });
848
+ } catch {
849
+ return e;
850
+ }
851
+ }
852
+ function Me(e, t) {
853
+ if (typeof e != "string" || !e) return t.messages.empty;
854
+ try {
855
+ return D.PlainDateTime.from(e).toLocaleString(t.locale, {
856
+ dateStyle: "medium",
857
+ timeStyle: "short"
858
+ });
859
+ } catch {
860
+ return e;
861
+ }
862
+ }
863
+ var Ne = {
864
+ text: {
865
+ control: u(fe),
866
+ valueType: "string",
867
+ layouts: Q,
868
+ defaultValue: () => "",
869
+ isEmpty: $,
870
+ validate: (e, t) => {
871
+ let n = typeof e == "string" ? e : "", r = L(t.props.minLength), i = L(t.props.maxLength);
872
+ return r !== void 0 && n.length < r ? t.props.minLengthMessage || `Enter at least ${r} characters.` : i !== void 0 && n.length > i ? t.props.maxLengthMessage || `Enter no more than ${i} characters.` : null;
873
+ },
874
+ formatReadonly: (e, t, n) => typeof e == "string" && e ? e : n.messages.empty
875
+ },
876
+ number: {
877
+ control: u(me),
878
+ valueType: "number",
879
+ layouts: Q,
880
+ defaultValue: () => null,
881
+ isEmpty: $,
882
+ validate: (e, t) => {
883
+ if (e == null || e === "") return null;
884
+ let n = typeof e == "number" ? e : Number(e);
885
+ if (!Number.isFinite(n)) return t.props.numberMessage || "Enter a valid number.";
886
+ let r = L(t.props.min), i = L(t.props.max);
887
+ return r !== void 0 && n < r ? t.props.minMessage || `Minimum: ${r}.` : i !== void 0 && n > i ? t.props.maxMessage || `Maximum: ${i}.` : null;
888
+ },
889
+ formatReadonly: Ae
890
+ },
891
+ date: {
892
+ control: u(ge),
893
+ valueType: "date",
894
+ layouts: Q,
895
+ defaultValue: () => "",
896
+ isEmpty: $,
897
+ formatReadonly: (e, t, n) => je(e, n)
898
+ },
899
+ datetime: {
900
+ control: u(ve),
901
+ valueType: "datetime",
902
+ layouts: Q,
903
+ defaultValue: () => "",
904
+ isEmpty: $,
905
+ formatReadonly: (e, t, n) => Me(e, n)
906
+ },
907
+ boolean: {
908
+ control: u(Se),
909
+ valueType: "boolean",
910
+ layouts: Q,
911
+ defaultValue: () => !1,
912
+ isEmpty: $,
913
+ formatReadonly: (e, t, n) => e === !0 ? t.props.trueLabel || n.messages.booleanTrue : t.props.falseLabel || n.messages.booleanFalse
914
+ },
915
+ select: {
916
+ control: u(Ee),
917
+ valueType: "string",
918
+ layouts: Q,
919
+ defaultValue: () => null,
920
+ isEmpty: $,
921
+ validate: (e, t) => e == null || e === "" || z(t.props.options).some((t) => t.value === e) ? null : t.props.optionMessage || "Select one of the available options.",
922
+ formatReadonly: (e, t, n) => typeof e != "string" || !e ? n.messages.empty : z(t.props.options).find((t) => t.value === e)?.label ?? e
923
+ },
924
+ markdown: {
925
+ control: u(De),
926
+ readonly: u(ke),
927
+ valueType: "string",
928
+ layouts: ["block"],
929
+ defaultValue: () => "",
930
+ isEmpty: $
931
+ }
932
+ };
933
+ function Pe(e) {
934
+ return {
935
+ ...Ne,
936
+ ...e
937
+ };
938
+ }
939
+ //#endregion
940
+ //#region src/CoarMarkdownForm.vue?vue&type=script&setup=true&lang.ts
941
+ var Fe = {
942
+ key: 0,
943
+ class: "coar-markdown-form__issues",
944
+ role: "alert"
945
+ }, Ie = /* @__PURE__ */ s({
946
+ __name: "CoarMarkdownForm",
947
+ props: {
948
+ template: {},
949
+ values: {},
950
+ mode: { default: "fill" },
951
+ fields: { default: () => ({}) },
952
+ context: { default: () => ({}) },
953
+ embeds: { default: () => ({}) },
954
+ showErrors: {
955
+ type: Boolean,
956
+ default: !1
957
+ }
958
+ },
959
+ emits: ["update:values", "validation"],
960
+ setup(n, { expose: l, emit: f }) {
961
+ let g = n, x = f;
962
+ function T(e) {
963
+ return u(s({
964
+ name: `CoarMarkdownForm${e}Block`,
965
+ inheritAttrs: !1,
966
+ setup() {
967
+ let t = y();
968
+ return () => c(se, {
969
+ fieldProps: E(t),
970
+ defaultType: e
971
+ });
972
+ }
973
+ }));
974
+ }
975
+ let D = t(() => V(g.context)), O = t(() => Pe(g.fields)), k = t(() => w(g.template)), A = t(() => X(k.value, O.value, D.value.messages)), j = t(() => {
976
+ let e = {};
977
+ for (let t of A.value.fields) {
978
+ if (!t.id || e[t.id]) continue;
979
+ let n = O.value[t.type];
980
+ if (!n) continue;
981
+ let r = g.values[t.id], i = r === void 0 ? n.defaultValue?.(t) : r, a = n.isEmpty?.(i, t) ?? (i == null || i === "" || i === !1);
982
+ if (t.required && a) {
983
+ e[t.id] = t.props.requiredMessage || D.value.messages.required(t);
984
+ continue;
985
+ }
986
+ let o = n.validate?.(i, t, g.values, D.value);
987
+ o && (e[t.id] = o);
988
+ }
989
+ return e;
990
+ }), M = t(() => ({
991
+ valid: A.value.issues.length === 0 && Object.keys(j.value).length === 0,
992
+ errors: j.value,
993
+ issues: A.value.issues
994
+ })), N = t(() => g.mode), ee = t(() => g.showErrors), P = {
995
+ ...C,
996
+ paragraph: le,
997
+ text: ce
998
+ }, F = T("text"), I = T("markdown"), L = t(() => ({
999
+ ...g.embeds,
1000
+ field: { viewer: F },
1001
+ "markdown-field": { viewer: I }
1002
+ }));
1003
+ return m(H, {
1004
+ mode: N,
1005
+ context: D,
1006
+ registry: O,
1007
+ validation: M,
1008
+ showErrors: ee,
1009
+ getValue: (e) => g.values[e],
1010
+ updateValue: (e, t) => {
1011
+ g.mode !== "fill" || !e.id || x("update:values", {
1012
+ ...g.values,
1013
+ [e.id]: t
1014
+ });
1015
+ }
1016
+ }), b(M, (e) => x("validation", e), {
1017
+ immediate: !0,
1018
+ deep: !0
1019
+ }), l({ validate: () => M.value }), (t, n) => (p(), i("div", { class: d(["coar-markdown-form", `coar-markdown-form--${N.value}`]) }, [A.value.issues.length ? (p(), i("div", Fe, [n[0] ||= a("strong", null, "Invalid Markdown form template", -1), a("ul", null, [(p(!0), i(e, null, h(A.value.issues, (e) => (p(), i("li", { key: `${e.field.occurrenceId}:${e.code}` }, _(e.message), 1))), 128))])])) : r("", !0), o(v(S), {
1020
+ doc: k.value,
1021
+ renderers: P,
1022
+ embeds: L.value
1023
+ }, null, 8, ["doc", "embeds"])], 2));
1024
+ }
1025
+ });
1026
+ //#endregion
1027
+ export { Ne as BUILTIN_MARKDOWN_FORM_FIELDS, Ie as CoarMarkdownForm, B as DEFAULT_MARKDOWN_FORM_CONTEXT, H as MARKDOWN_FORM_RUNTIME_KEY, X as analyzeMarkdownFormTemplate, Y as collectMarkdownFormFields, K as createMarkdownFormField, J as fieldFromEmbedNode, Pe as mergeMarkdownFormFields, L as parseFiniteNumber, q as parseInlineMarkdownFormFields, z as parseMarkdownFormSelectOptions, V as resolveMarkdownFormContext, I as resolveMarkdownFormFieldWidth, U as useMarkdownFormRuntime };