@namroodinc/liquid-editorial 0.1.0 → 0.1.2

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 (72) hide show
  1. package/README.md +62 -1
  2. package/dist/chunks/EntryEditor-BF808OZR.js +181 -0
  3. package/dist/chunks/EntryEditor-BF808OZR.js.map +1 -0
  4. package/dist/chunks/EntryEditor-cjDk4vdH.cjs +2 -0
  5. package/dist/chunks/EntryEditor-cjDk4vdH.cjs.map +1 -0
  6. package/dist/chunks/RichTextEditor-DRt-kibg.js +248 -0
  7. package/dist/chunks/RichTextEditor-DRt-kibg.js.map +1 -0
  8. package/dist/chunks/RichTextEditor-tFkISOvq.cjs +2 -0
  9. package/dist/chunks/RichTextEditor-tFkISOvq.cjs.map +1 -0
  10. package/dist/components/EntryEditor/index.cjs +1 -0
  11. package/dist/components/EntryEditor/index.d.cts +21 -0
  12. package/dist/components/EntryEditor/index.d.cts.map +1 -0
  13. package/dist/components/EntryEditor/index.d.ts +21 -0
  14. package/dist/components/EntryEditor/index.d.ts.map +1 -0
  15. package/dist/components/EntryEditor/index.js +6 -0
  16. package/dist/components/EntryEditor/model.d.cts +33 -0
  17. package/dist/components/EntryEditor/model.d.cts.map +1 -0
  18. package/dist/components/EntryEditor/model.d.ts +33 -0
  19. package/dist/components/EntryEditor/model.d.ts.map +1 -0
  20. package/dist/components/EntryEditor/style.css +8 -0
  21. package/dist/components/EntryPicker/index.cjs +1 -1
  22. package/dist/components/EntryPicker/index.cjs.map +1 -1
  23. package/dist/components/EntryPicker/index.d.cts.map +1 -1
  24. package/dist/components/EntryPicker/index.d.ts.map +1 -1
  25. package/dist/components/EntryPicker/index.js +15 -12
  26. package/dist/components/EntryPicker/index.js.map +1 -1
  27. package/dist/components/Field/index.cjs +1 -1
  28. package/dist/components/Field/index.cjs.map +1 -1
  29. package/dist/components/Field/index.d.cts +4 -1
  30. package/dist/components/Field/index.d.cts.map +1 -1
  31. package/dist/components/Field/index.d.ts +4 -1
  32. package/dist/components/Field/index.d.ts.map +1 -1
  33. package/dist/components/Field/index.js +29 -23
  34. package/dist/components/Field/index.js.map +1 -1
  35. package/dist/components/Field/style.css +12 -0
  36. package/dist/components/Modal/style.css +1 -0
  37. package/dist/components/NumberField/index.cjs +1 -1
  38. package/dist/components/NumberField/index.cjs.map +1 -1
  39. package/dist/components/NumberField/index.d.cts +1 -1
  40. package/dist/components/NumberField/index.d.cts.map +1 -1
  41. package/dist/components/NumberField/index.d.ts +1 -1
  42. package/dist/components/NumberField/index.d.ts.map +1 -1
  43. package/dist/components/NumberField/index.js +1 -1
  44. package/dist/components/NumberField/index.js.map +1 -1
  45. package/dist/components/RichTextEditor/document.d.cts +10 -0
  46. package/dist/components/RichTextEditor/document.d.cts.map +1 -0
  47. package/dist/components/RichTextEditor/document.d.ts +10 -0
  48. package/dist/components/RichTextEditor/document.d.ts.map +1 -0
  49. package/dist/components/RichTextEditor/index.cjs +1 -2
  50. package/dist/components/RichTextEditor/index.d.cts +21 -6
  51. package/dist/components/RichTextEditor/index.d.cts.map +1 -1
  52. package/dist/components/RichTextEditor/index.d.ts +21 -6
  53. package/dist/components/RichTextEditor/index.d.ts.map +1 -1
  54. package/dist/components/RichTextEditor/index.js +1 -175
  55. package/dist/components/SortableList/index.cjs +1 -1
  56. package/dist/components/SortableList/index.cjs.map +1 -1
  57. package/dist/components/SortableList/index.d.cts +4 -3
  58. package/dist/components/SortableList/index.d.cts.map +1 -1
  59. package/dist/components/SortableList/index.d.ts +4 -3
  60. package/dist/components/SortableList/index.d.ts.map +1 -1
  61. package/dist/components/SortableList/index.js +55 -48
  62. package/dist/components/SortableList/index.js.map +1 -1
  63. package/dist/index.cjs +1 -1
  64. package/dist/index.d.cts +3 -1
  65. package/dist/index.d.cts.map +1 -1
  66. package/dist/index.d.ts +3 -1
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +36 -35
  69. package/dist/styles.css +1 -0
  70. package/package.json +37 -11
  71. package/dist/components/RichTextEditor/index.cjs.map +0 -1
  72. package/dist/components/RichTextEditor/index.js.map +0 -1
package/README.md CHANGED
@@ -35,6 +35,36 @@ import { Button } from "@namroodinc/liquid-editorial/components/Button";
35
35
 
36
36
  If an application only needs the design tokens, import `@namroodinc/liquid-editorial/tokens.css`. A small global normalization is available separately at `@namroodinc/liquid-editorial/reset.css`; it is never included automatically.
37
37
 
38
+ ## Content models
39
+
40
+ `EntryEditor` renders editable fields in the order defined by a JSON model:
41
+
42
+ ```tsx
43
+ import { useState } from "react";
44
+ import { EntryEditor, validateEntryValues, type ContentModel, type EntryValues } from "@namroodinc/liquid-editorial";
45
+
46
+ const model: ContentModel = {
47
+ fields: [
48
+ { id: "title", type: "shortText", label: "Title", required: true },
49
+ { id: "gallery", type: "asset", label: "Gallery", multiple: true },
50
+ ],
51
+ };
52
+
53
+ export function ContentEditor() {
54
+ const [value, setValue] = useState<EntryValues>({});
55
+ return <EntryEditor model={model} value={value} onValueChange={setValue}
56
+ pickerItems={{ gallery: [{ id: "image-1", title: "Cover.jpg" }] }} />;
57
+ }
58
+
59
+ // Before saving: validateEntryValues(model, value) returns errors keyed by field ID.
60
+ ```
61
+
62
+ Supported types are `shortText`, `longText`, `richText`, `number`, `boolean`, `dateTime`, `asset`, and `reference`. Rich text stores a TipTap JSON document rooted at `doc`, using the editor's existing StarterKit and Link schema. Dates are edited in UTC and emitted as ISO-8601 strings ending in `Z`. Assets store `{ assetId }`; references store `{ entryId }`. Set `multiple: true` for an ordered array of these objects.
63
+
64
+ Use `defaultValue` for an uncontrolled editor, `errors` for app-specific messages, `showAllErrors` after a submit attempt, and `isDisabled` to disable editing. Required errors appear after a field changes; `false` and `0` are populated values. Missing keys render empty controls without emitting changes. Clearing a number, date, or single selection removes its key; empty text, rich-text documents, and lists keep their typed values. Unrelated entry keys are preserved.
65
+
66
+ `RichTextEditor` also supports `format="json"` with `value`/`defaultValue` and an `onChange` callback receiving the document. HTML remains its default format. Unsupported JSON content produces an error and cannot be edited until corrected.
67
+
38
68
  ## Themes and fonts
39
69
 
40
70
  Set `data-theme` on the document root to `light`, `dark`, `cherry-glaze`, or `black-hawaii`. The default font tokens use system stacks and can be overridden by the consumer without downloading bundled font files:
@@ -61,7 +91,38 @@ Storybook is the component catalogue and documentation surface. Stories and test
61
91
 
62
92
  ## Publishing
63
93
 
64
- Run `npm run validate`, inspect `npm pack --dry-run`, and confirm access to the `@namroodinc` npm scope. Publication itself is intentionally not automated by this repository.
94
+ Publishing a GitHub Release runs [the release workflow](.github/workflows/release.yml): it checks the release version, runs `npm run validate`, then publishes `@namroodinc/liquid-editorial` to npm. The release tag must be `v` followed by the exact version in both `package.json` and `package-lock.json`. Stable versions publish to `latest`; versions such as `0.2.0-beta.1` must be marked as GitHub prereleases and publish to `next`. Branch pushes and draft releases run no publishing step.
95
+
96
+ ### One-time npm setup
97
+
98
+ After pushing the workflow to GitHub, open [the package settings](https://www.npmjs.com/package/@namroodinc/liquid-editorial/access) and add a GitHub Actions trusted publisher with:
99
+
100
+ - Organization or user: `namroodinc`
101
+ - Repository: `liquid-editorial`
102
+ - Workflow filename: `release.yml`
103
+ - Environment: leave empty
104
+ - Allowed action: enable direct publishing with `npm publish`
105
+
106
+ Alternatively, with npm 11.15 or newer and an authenticated maintainer account, run:
107
+
108
+ ```sh
109
+ npm trust github @namroodinc/liquid-editorial --repo namroodinc/liquid-editorial --file release.yml --allow-publish
110
+ ```
111
+
112
+ npm requires two-factor verification for this setup. The workflow subsequently authenticates through OIDC without an `NPM_TOKEN` secret. Complete the first workflow publish within two days of adding the trusted publisher to avoid configuration expiry. See [npm's trusted publishing guide](https://docs.npmjs.com/trusted-publishers/) for the current setup requirements.
113
+
114
+ ### Create a release
115
+
116
+ For the next patch release after `0.1.0`:
117
+
118
+ ```sh
119
+ npm version patch --no-git-tag-version
120
+ git add package.json package-lock.json
121
+ git commit -m "chore: release v0.1.1"
122
+ git push origin main
123
+ ```
124
+
125
+ On GitHub, publish a Release with tag `v0.1.1` targeting that commit. GitHub can create the tag when publishing the release. For later releases, use the version produced by `npm version`; for a prerelease, use a version such as `0.2.0-beta.1` and select **Set as a pre-release**. Publishing an already-published npm version fails, so every release needs a new version.
65
126
 
66
127
  ## License
67
128
 
@@ -0,0 +1,181 @@
1
+ import { n as e, r as t, t as n } from "./RichTextEditor-DRt-kibg.js";
2
+ import { EntryPicker as r } from "../components/EntryPicker/index.js";
3
+ import { Field as i } from "../components/Field/index.js";
4
+ import { NumberField as a } from "../components/NumberField/index.js";
5
+ import { Switch as o } from "../components/Switch/index.js";
6
+ import { TextArea as s, TextField as c } from "../components/TextField/index.js";
7
+ import { useState as l } from "react";
8
+ import { jsx as u } from "react/jsx-runtime";
9
+ //#region src/components/EntryEditor/model.ts
10
+ var d = /* @__PURE__ */ new Set([
11
+ "shortText",
12
+ "longText",
13
+ "richText",
14
+ "number",
15
+ "boolean",
16
+ "dateTime",
17
+ "asset",
18
+ "reference"
19
+ ]);
20
+ function f(e) {
21
+ let t = /* @__PURE__ */ new Set();
22
+ for (let n of e.fields) {
23
+ if (!n.id?.trim() || t.has(n.id)) throw Error("Content model field IDs must be nonempty and unique.");
24
+ if (!d.has(n.type)) throw Error(`Unsupported content field type: ${n.type}`);
25
+ t.add(n.id);
26
+ }
27
+ }
28
+ function p(e) {
29
+ if (typeof e != "string") return;
30
+ let t = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(?:Z|\+00:00)$/.exec(e);
31
+ if (!t) return;
32
+ let n = `${t[1]}:${t[2] ?? "00"}.${(t[3] ?? "").padEnd(3, "0")}Z`, r = new Date(n);
33
+ if (Number.isFinite(r.getTime()) && r.toISOString() === n) return n;
34
+ }
35
+ function m(e, t) {
36
+ return !!e && typeof e == "object" && t in e && typeof e[t] == "string" && e[t].trim().length > 0;
37
+ }
38
+ function h(e) {
39
+ return !!e.text?.trim() || e.type === "horizontalRule" || !!e.content?.some(h);
40
+ }
41
+ function g(t, n) {
42
+ return f(t), Object.fromEntries(t.fields.flatMap((t) => {
43
+ let r = Object.hasOwn(n, t.id) ? n[t.id] : void 0, i;
44
+ if (r === void 0) t.required && (i = `${t.label} is required.`);
45
+ else switch (t.type) {
46
+ case "shortText":
47
+ case "longText":
48
+ typeof r == "string" ? t.required && !r.trim() && (i = `${t.label} is required.`) : i = "Enter text.";
49
+ break;
50
+ case "richText":
51
+ i = e(r), !i && t.required && !h(r) && (i = `${t.label} is required.`);
52
+ break;
53
+ case "number":
54
+ (typeof r != "number" || !Number.isFinite(r)) && (i = "Enter a finite number.");
55
+ break;
56
+ case "boolean":
57
+ typeof r != "boolean" && (i = "Choose a boolean value.");
58
+ break;
59
+ case "dateTime":
60
+ p(r) || (i = "Enter a valid UTC date and time.");
61
+ break;
62
+ case "asset":
63
+ case "reference": {
64
+ let e = t.type === "asset" ? "assetId" : "entryId";
65
+ (t.multiple ? !Array.isArray(r) || !r.every((t) => m(t, e)) : !m(r, e)) ? i = t.multiple ? `Choose a list of ${t.type === "asset" ? "assets" : "entries"}.` : `Choose an ${t.type === "asset" ? "asset" : "entry"}.` : t.required && Array.isArray(r) && r.length === 0 && (i = `${t.label} is required.`);
66
+ break;
67
+ }
68
+ }
69
+ return i ? [[t.id, i]] : [];
70
+ }));
71
+ }
72
+ //#endregion
73
+ //#region src/components/EntryEditor/index.tsx
74
+ function _(e, t) {
75
+ let n = e.type === "asset" ? "assetId" : "entryId";
76
+ return (Array.isArray(t) ? t : t === void 0 ? [] : [t]).flatMap((e) => {
77
+ if (!e || typeof e != "object" || !(n in e)) return [];
78
+ let t = e[n];
79
+ return typeof t == "string" ? [t] : [];
80
+ });
81
+ }
82
+ function v({ model: e, value: d, defaultValue: f = {}, onValueChange: m, pickerItems: h = {}, errors: v = {}, isDisabled: y = !1, showAllErrors: b = !1, className: x, ...S }) {
83
+ let [C, w] = l(f), [T, E] = l(() => /* @__PURE__ */ new Set()), D = d ?? C, O = g(e, D), k = (e, t) => {
84
+ if (y) return;
85
+ let n = { ...D };
86
+ t === void 0 ? delete n[e] : n[e] = t, d === void 0 && w(n), E((t) => new Set(t).add(e)), m?.(n);
87
+ };
88
+ return /* @__PURE__ */ u("div", {
89
+ className: ["ds-entry-editor", x].filter(Boolean).join(" "),
90
+ ...S,
91
+ children: e.fields.map((e) => {
92
+ let l = Object.hasOwn(D, e.id) ? D[e.id] : void 0, d = e.type === "asset" || e.type === "reference", f = e.type === "dateTime" ? `${e.label} (UTC)` : e.label, m = v[e.id] ?? (b || T.has(e.id) ? O[e.id] : void 0);
93
+ return /* @__PURE__ */ u(i, {
94
+ label: f,
95
+ hint: e.hint,
96
+ error: m,
97
+ isRequired: e.required,
98
+ isGroup: d,
99
+ children: ({ required: i, ...d }) => {
100
+ switch (e.type) {
101
+ case "shortText":
102
+ case "longText": {
103
+ let t = e.type === "shortText" ? c : s;
104
+ return /* @__PURE__ */ u(t, {
105
+ ...d,
106
+ required: i,
107
+ disabled: y,
108
+ placeholder: e.placeholder,
109
+ value: typeof l == "string" ? l : "",
110
+ onChange: (t) => k(e.id, t.target.value)
111
+ });
112
+ }
113
+ case "number": return /* @__PURE__ */ u(a, {
114
+ ...d,
115
+ required: i,
116
+ isDisabled: y,
117
+ placeholder: e.placeholder,
118
+ step: "any",
119
+ hasSteppers: !1,
120
+ value: typeof l == "number" && Number.isFinite(l) ? l : "",
121
+ onValueChange: (t) => {
122
+ (t === "" || Number.isFinite(t)) && k(e.id, t === "" ? void 0 : t);
123
+ }
124
+ });
125
+ case "boolean": return /* @__PURE__ */ u(o, {
126
+ ...d,
127
+ isDisabled: y,
128
+ isSelected: l === !0,
129
+ onSelectedChange: (t) => k(e.id, t)
130
+ });
131
+ case "dateTime": return /* @__PURE__ */ u(c, {
132
+ ...d,
133
+ required: i,
134
+ disabled: y,
135
+ type: "datetime-local",
136
+ step: "0.001",
137
+ value: p(l)?.slice(0, -1) ?? "",
138
+ onChange: (t) => k(e.id, p(`${t.target.value}Z`))
139
+ });
140
+ case "richText": return /* @__PURE__ */ u(n, {
141
+ ...d,
142
+ label: e.label,
143
+ isRequired: i,
144
+ isDisabled: y,
145
+ placeholder: e.placeholder,
146
+ format: "json",
147
+ value: l === void 0 ? t : l,
148
+ onChange: (t) => k(e.id, t)
149
+ });
150
+ case "asset":
151
+ case "reference": return /* @__PURE__ */ u("div", {
152
+ ...d,
153
+ role: "group",
154
+ children: /* @__PURE__ */ u(r, {
155
+ items: h[e.id] ?? [],
156
+ value: _(e, l),
157
+ label: e.type === "asset" ? "Assets" : "Entries",
158
+ addLabel: `Choose ${e.label}`,
159
+ mode: e.multiple ? "multiple" : "single",
160
+ isDisabled: y,
161
+ onValueChange: (t) => {
162
+ if (e.type === "asset") {
163
+ let n = t.map((e) => ({ assetId: e }));
164
+ k(e.id, e.multiple ? n : n[0]);
165
+ } else {
166
+ let n = t.map((e) => ({ entryId: e }));
167
+ k(e.id, e.multiple ? n : n[0]);
168
+ }
169
+ }
170
+ })
171
+ });
172
+ }
173
+ }
174
+ }, e.id);
175
+ })
176
+ });
177
+ }
178
+ //#endregion
179
+ export { g as n, v as t };
180
+
181
+ //# sourceMappingURL=EntryEditor-BF808OZR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntryEditor-BF808OZR.js","names":["documentError","emptyDocument","RichTextEditor","fieldTypes","assertModel","ids","field","model","parseUtcDateTime","value","match","canonical","date","isLink","key","hasRichText","node","validateEntryValues","values","error","item","selectedIds","link","id","EntryEditor","rest","internal","setInternal","useState","defaultValue","changed","setChanged","current","validation","commit","isDisabled","next","previous","onValueChange","className","stored","isPicker","label","errors","showAllErrors","Field","accessibility","Control","TextField","TextArea","event","NumberField","Switch","required","EntryPicker","pickerItems","links"],"sources":["../../src/components/EntryEditor/model.ts","../../src/components/EntryEditor/index.tsx"],"sourcesContent":["import type { JSONContent } from \"@tiptap/react\";\nimport { documentError } from \"../RichTextEditor/document\";\nimport type { RichTextDocument } from \"../RichTextEditor\";\n\ninterface ContentFieldBase {\n id: string;\n label: string;\n hint?: string;\n placeholder?: string;\n required?: boolean;\n}\n\nexport type ContentField = ContentFieldBase & (\n | { type: \"shortText\" | \"longText\" | \"richText\" | \"number\" | \"boolean\" | \"dateTime\"; multiple?: never }\n | { type: \"asset\" | \"reference\"; multiple?: boolean }\n);\n\nexport interface ContentModel {\n fields: readonly ContentField[];\n}\n\nexport interface AssetValue { assetId: string }\nexport interface ReferenceValue { entryId: string }\nexport type EntryFieldValue = string | number | boolean | RichTextDocument | AssetValue | ReferenceValue | AssetValue[] | ReferenceValue[];\nexport type EntryValues = Record<string, EntryFieldValue | undefined>;\nexport type EntryErrors = Partial<Record<string, string>>;\n\nconst fieldTypes = new Set([\"shortText\", \"longText\", \"richText\", \"number\", \"boolean\", \"dateTime\", \"asset\", \"reference\"]);\n\nfunction assertModel(model: ContentModel) {\n const ids = new Set<string>();\n for (const field of model.fields) {\n if (!field.id?.trim() || ids.has(field.id)) throw new Error(\"Content model field IDs must be nonempty and unique.\");\n if (!fieldTypes.has(field.type)) throw new Error(`Unsupported content field type: ${field.type}`);\n ids.add(field.id);\n }\n}\n\n/** Accept UTC ISO strings without rolling invalid dates into the next month. */\nexport function parseUtcDateTime(value: unknown): string | undefined {\n if (typeof value !== \"string\") return;\n const match = /^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2})(?::(\\d{2})(?:\\.(\\d{1,3}))?)?(?:Z|\\+00:00)$/.exec(value);\n if (!match) return;\n const canonical = `${match[1]}:${match[2] ?? \"00\"}.${(match[3] ?? \"\").padEnd(3, \"0\")}Z`;\n const date = new Date(canonical);\n if (Number.isFinite(date.getTime()) && date.toISOString() === canonical) return canonical;\n}\n\nfunction isLink(value: unknown, key: \"assetId\" | \"entryId\"): boolean {\n return !!value && typeof value === \"object\" && key in value &&\n typeof (value as Record<string, unknown>)[key] === \"string\" &&\n ((value as Record<string, string>)[key]).trim().length > 0;\n}\n\nfunction hasRichText(node: JSONContent): boolean {\n return !!node.text?.trim() || node.type === \"horizontalRule\" || !!node.content?.some(hasRichText);\n}\n\n/** Validate data loaded from JSON as well as values emitted by EntryEditor. */\nexport function validateEntryValues(model: ContentModel, values: Record<string, unknown>): EntryErrors {\n assertModel(model);\n return Object.fromEntries(model.fields.flatMap((field): [string, string][] => {\n const value = Object.hasOwn(values, field.id) ? values[field.id] : undefined;\n let error: string | undefined;\n if (value === undefined) {\n if (field.required) error = `${field.label} is required.`;\n } else {\n switch (field.type) {\n case \"shortText\":\n case \"longText\":\n if (typeof value !== \"string\") error = \"Enter text.\";\n else if (field.required && !value.trim()) error = `${field.label} is required.`;\n break;\n case \"richText\":\n error = documentError(value);\n if (!error && field.required && !hasRichText(value as RichTextDocument)) error = `${field.label} is required.`;\n break;\n case \"number\":\n if (typeof value !== \"number\" || !Number.isFinite(value)) error = \"Enter a finite number.\";\n break;\n case \"boolean\":\n if (typeof value !== \"boolean\") error = \"Choose a boolean value.\";\n break;\n case \"dateTime\":\n if (!parseUtcDateTime(value)) error = \"Enter a valid UTC date and time.\";\n break;\n case \"asset\":\n case \"reference\": {\n const key = field.type === \"asset\" ? \"assetId\" : \"entryId\";\n if (field.multiple ? !Array.isArray(value) || !value.every((item) => isLink(item, key)) : !isLink(value, key)) {\n error = field.multiple\n ? `Choose a list of ${field.type === \"asset\" ? \"assets\" : \"entries\"}.`\n : `Choose an ${field.type === \"asset\" ? \"asset\" : \"entry\"}.`;\n } else if (field.required && Array.isArray(value) && value.length === 0) error = `${field.label} is required.`;\n break;\n }\n }\n }\n return error ? [[field.id, error]] : [];\n }));\n}\n","import { useState, type HTMLAttributes, type ReactNode } from \"react\";\nimport { EntryPicker, type EntryItem } from \"../EntryPicker\";\nimport { Field } from \"../Field\";\nimport { NumberField } from \"../NumberField\";\nimport { RichTextEditor, type RichTextDocument } from \"../RichTextEditor\";\nimport { emptyDocument } from \"../RichTextEditor/document\";\nimport { Switch } from \"../Switch\";\nimport { TextArea, TextField } from \"../TextField\";\nimport { parseUtcDateTime, validateEntryValues, type ContentField, type ContentModel, type EntryErrors, type EntryFieldValue, type EntryValues } from \"./model\";\nimport \"./style.css\";\n\nexport { validateEntryValues } from \"./model\";\nexport type { AssetValue, ContentField, ContentModel, EntryErrors, EntryFieldValue, EntryValues, ReferenceValue } from \"./model\";\n\nexport interface EntryEditorProps extends Omit<HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\"> {\n model: ContentModel;\n value?: EntryValues;\n defaultValue?: EntryValues;\n onValueChange?: (values: EntryValues) => void;\n /** Available assets or entries, keyed by content field ID. */\n pickerItems?: Record<string, EntryItem[]>;\n /** App-provided messages take precedence over built-in validation. */\n errors?: EntryErrors;\n isDisabled?: boolean;\n /** Reveal validation for untouched fields, for example after a submit attempt. */\n showAllErrors?: boolean;\n}\n\nfunction selectedIds(field: ContentField, value: EntryFieldValue | undefined): string[] {\n const key = field.type === \"asset\" ? \"assetId\" : \"entryId\";\n const links = Array.isArray(value) ? value : value === undefined ? [] : [value];\n return links.flatMap((link) => {\n if (!link || typeof link !== \"object\" || !(key in link)) return [];\n const id = (link as unknown as Record<string, unknown>)[key];\n return typeof id === \"string\" ? [id] : [];\n });\n}\n\n/** An ordered set of content inputs; submission and persistence belong to the app. */\nexport function EntryEditor({\n model,\n value,\n defaultValue = {},\n onValueChange,\n pickerItems = {},\n errors = {},\n isDisabled = false,\n showAllErrors = false,\n className,\n ...rest\n}: EntryEditorProps) {\n const [internal, setInternal] = useState<EntryValues>(defaultValue);\n const [changed, setChanged] = useState<Set<string>>(() => new Set());\n const current = value ?? internal;\n const validation = validateEntryValues(model, current);\n\n const commit = (id: string, next: EntryFieldValue | undefined) => {\n if (isDisabled) return;\n const values = { ...current };\n if (next === undefined) delete values[id];\n else values[id] = next;\n if (value === undefined) setInternal(values);\n setChanged((previous) => new Set(previous).add(id));\n onValueChange?.(values);\n };\n\n return (\n <div className={[\"ds-entry-editor\", className].filter(Boolean).join(\" \")} {...rest}>\n {model.fields.map((field) => {\n const stored = Object.hasOwn(current, field.id) ? current[field.id] : undefined;\n const isPicker = field.type === \"asset\" || field.type === \"reference\";\n const label = field.type === \"dateTime\" ? `${field.label} (UTC)` : field.label;\n const error = errors[field.id] ?? (showAllErrors || changed.has(field.id) ? validation[field.id] : undefined);\n return (\n <Field key={field.id} label={label} hint={field.hint} error={error} isRequired={field.required} isGroup={isPicker}>\n {({ required, ...accessibility }): ReactNode => {\n switch (field.type) {\n case \"shortText\":\n case \"longText\": {\n const Control = field.type === \"shortText\" ? TextField : TextArea;\n return <Control {...accessibility} required={required} disabled={isDisabled} placeholder={field.placeholder}\n value={typeof stored === \"string\" ? stored : \"\"} onChange={(event) => commit(field.id, event.target.value)} />;\n }\n case \"number\":\n return <NumberField {...accessibility} required={required} isDisabled={isDisabled} placeholder={field.placeholder} step=\"any\"\n hasSteppers={false} value={typeof stored === \"number\" && Number.isFinite(stored) ? stored : \"\"}\n onValueChange={(next) => { if (next === \"\" || Number.isFinite(next)) commit(field.id, next === \"\" ? undefined : next); }} />;\n case \"boolean\":\n return <Switch {...accessibility} isDisabled={isDisabled} isSelected={stored === true}\n onSelectedChange={(next) => commit(field.id, next)} />;\n case \"dateTime\":\n return <TextField {...accessibility} required={required} disabled={isDisabled} type=\"datetime-local\" step=\"0.001\"\n value={parseUtcDateTime(stored)?.slice(0, -1) ?? \"\"}\n onChange={(event) => commit(field.id, parseUtcDateTime(`${event.target.value}Z`))} />;\n case \"richText\":\n return <RichTextEditor {...accessibility} label={field.label} isRequired={required} isDisabled={isDisabled}\n placeholder={field.placeholder} format=\"json\" value={stored === undefined ? emptyDocument : stored as RichTextDocument}\n onChange={(next) => commit(field.id, next)} />;\n case \"asset\":\n case \"reference\":\n return <div {...accessibility} role=\"group\">\n <EntryPicker items={pickerItems[field.id] ?? []} value={selectedIds(field, stored)}\n label={field.type === \"asset\" ? \"Assets\" : \"Entries\"} addLabel={`Choose ${field.label}`}\n mode={field.multiple ? \"multiple\" : \"single\"} isDisabled={isDisabled}\n onValueChange={(ids) => {\n if (field.type === \"asset\") {\n const links = ids.map((assetId) => ({ assetId }));\n commit(field.id, field.multiple ? links : links[0]);\n } else {\n const links = ids.map((entryId) => ({ entryId }));\n commit(field.id, field.multiple ? links : links[0]);\n }\n }} />\n </div>;\n }\n }}\n </Field>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AA2BA,IAAMG,oBAAa,IAAI,IAAI;CAAC;CAAa;CAAY;CAAY;CAAU;CAAW;CAAY;CAAS;AAAW,CAAC;AAEvH,SAASC,EAAY,GAAqB;CACxC,IAAMC,oBAAM,IAAI,IAAY;CAC5B,KAAK,IAAMC,KAASC,EAAM,QAAQ;EAChC,IAAI,CAACD,EAAM,IAAI,KAAK,KAAKD,EAAI,IAAIC,EAAM,EAAE,GAAG,MAAU,MAAM,sDAAsD;EAClH,IAAI,CAACH,EAAW,IAAIG,EAAM,IAAI,GAAG,MAAU,MAAM,mCAAmCA,EAAM,MAAM;EAChG,EAAI,IAAIA,EAAM,EAAE;CAClB;AACF;AAGA,SAAgBE,EAAiB,GAAoC;CACnE,IAAI,OAAOC,KAAU,UAAU;CAC/B,IAAMC,IAAQ,8EAA8E,KAAKD,CAAK;CACtG,IAAI,CAACC,GAAO;CACZ,IAAMC,IAAY,GAAGD,EAAM,GAAG,GAAGA,EAAM,MAAM,KAAK,IAAIA,EAAM,MAAM,GAAA,CAAI,OAAO,GAAG,GAAG,EAAE,IAC/EE,IAAO,IAAI,KAAKD,CAAS;CAC/B,IAAI,OAAO,SAASC,EAAK,QAAQ,CAAC,KAAKA,EAAK,YAAY,MAAMD,GAAW,OAAOA;AAClF;AAEA,SAASE,EAAO,GAAgB,GAAqC;CACnE,OAAO,CAAC,CAACJ,KAAS,OAAOA,KAAU,YAAYK,KAAOL,KACpD,OAAQA,EAAkCK,MAAS,YACjDL,EAAiCK,EAAI,CAAE,KAAK,CAAC,CAAC,SAAS;AAC7D;AAEA,SAASC,EAAY,GAA4B;CAC/C,OAAO,CAAC,CAACC,EAAK,MAAM,KAAK,KAAKA,EAAK,SAAS,oBAAo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"),n=require("../components/Field/index.cjs"),r=require("../components/NumberField/index.cjs"),i=require("../components/Switch/index.cjs"),a=require("../components/TextField/index.cjs");let o=require("react"),s=require("react/jsx-runtime");var c=new Set([`shortText`,`longText`,`richText`,`number`,`boolean`,`dateTime`,`asset`,`reference`]);function l(e){let t=new Set;for(let n of e.fields){if(!n.id?.trim()||t.has(n.id))throw Error(`Content model field IDs must be nonempty and unique.`);if(!c.has(n.type))throw Error(`Unsupported content field type: ${n.type}`);t.add(n.id)}}function u(e){if(typeof e!=`string`)return;let t=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(?:Z|\+00:00)$/.exec(e);if(!t)return;let n=`${t[1]}:${t[2]??`00`}.${(t[3]??``).padEnd(3,`0`)}Z`,r=new Date(n);if(Number.isFinite(r.getTime())&&r.toISOString()===n)return n}function d(e,t){return!!e&&typeof e==`object`&&t in e&&typeof e[t]==`string`&&e[t].trim().length>0}function f(e){return!!e.text?.trim()||e.type===`horizontalRule`||!!e.content?.some(f)}function p(t,n){return l(t),Object.fromEntries(t.fields.flatMap(t=>{let r=Object.hasOwn(n,t.id)?n[t.id]:void 0,i;if(r===void 0)t.required&&(i=`${t.label} is required.`);else switch(t.type){case`shortText`:case`longText`:typeof r==`string`?t.required&&!r.trim()&&(i=`${t.label} is required.`):i=`Enter text.`;break;case`richText`:i=e.n(r),!i&&t.required&&!f(r)&&(i=`${t.label} is required.`);break;case`number`:(typeof r!=`number`||!Number.isFinite(r))&&(i=`Enter a finite number.`);break;case`boolean`:typeof r!=`boolean`&&(i=`Choose a boolean value.`);break;case`dateTime`:u(r)||(i=`Enter a valid UTC date and time.`);break;case`asset`:case`reference`:{let e=t.type===`asset`?`assetId`:`entryId`;(t.multiple?!Array.isArray(r)||!r.every(t=>d(t,e)):!d(r,e))?i=t.multiple?`Choose a list of ${t.type===`asset`?`assets`:`entries`}.`:`Choose an ${t.type===`asset`?`asset`:`entry`}.`:t.required&&Array.isArray(r)&&r.length===0&&(i=`${t.label} is required.`);break}}return i?[[t.id,i]]:[]}))}function m(e,t){let n=e.type===`asset`?`assetId`:`entryId`;return(Array.isArray(t)?t:t===void 0?[]:[t]).flatMap(e=>{if(!e||typeof e!=`object`||!(n in e))return[];let t=e[n];return typeof t==`string`?[t]:[]})}function h({model:c,value:l,defaultValue:d={},onValueChange:f,pickerItems:h={},errors:g={},isDisabled:_=!1,showAllErrors:v=!1,className:y,...b}){let[x,S]=(0,o.useState)(d),[C,w]=(0,o.useState)(()=>new Set),T=l??x,E=p(c,T),D=(e,t)=>{if(_)return;let n={...T};t===void 0?delete n[e]:n[e]=t,l===void 0&&S(n),w(t=>new Set(t).add(e)),f?.(n)};return(0,s.jsx)(`div`,{className:[`ds-entry-editor`,y].filter(Boolean).join(` `),...b,children:c.fields.map(o=>{let c=Object.hasOwn(T,o.id)?T[o.id]:void 0,l=o.type===`asset`||o.type===`reference`,d=o.type===`dateTime`?`${o.label} (UTC)`:o.label,f=g[o.id]??(v||C.has(o.id)?E[o.id]:void 0);return(0,s.jsx)(n.Field,{label:d,hint:o.hint,error:f,isRequired:o.required,isGroup:l,children:({required:n,...l})=>{switch(o.type){case`shortText`:case`longText`:{let e=o.type===`shortText`?a.TextField:a.TextArea;return(0,s.jsx)(e,{...l,required:n,disabled:_,placeholder:o.placeholder,value:typeof c==`string`?c:``,onChange:e=>D(o.id,e.target.value)})}case`number`:return(0,s.jsx)(r.NumberField,{...l,required:n,isDisabled:_,placeholder:o.placeholder,step:`any`,hasSteppers:!1,value:typeof c==`number`&&Number.isFinite(c)?c:``,onValueChange:e=>{(e===``||Number.isFinite(e))&&D(o.id,e===``?void 0:e)}});case`boolean`:return(0,s.jsx)(i.Switch,{...l,isDisabled:_,isSelected:c===!0,onSelectedChange:e=>D(o.id,e)});case`dateTime`:return(0,s.jsx)(a.TextField,{...l,required:n,disabled:_,type:`datetime-local`,step:`0.001`,value:u(c)?.slice(0,-1)??``,onChange:e=>D(o.id,u(`${e.target.value}Z`))});case`richText`:return(0,s.jsx)(e.t,{...l,label:o.label,isRequired:n,isDisabled:_,placeholder:o.placeholder,format:`json`,value:c===void 0?e.r:c,onChange:e=>D(o.id,e)});case`asset`:case`reference`:return(0,s.jsx)(`div`,{...l,role:`group`,children:(0,s.jsx)(t.EntryPicker,{items:h[o.id]??[],value:m(o,c),label:o.type===`asset`?`Assets`:`Entries`,addLabel:`Choose ${o.label}`,mode:o.multiple?`multiple`:`single`,isDisabled:_,onValueChange:e=>{if(o.type===`asset`){let t=e.map(e=>({assetId:e}));D(o.id,o.multiple?t:t[0])}else{let t=e.map(e=>({entryId:e}));D(o.id,o.multiple?t:t[0])}}})})}}},o.id)})})}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return h}});
2
+ //# sourceMappingURL=EntryEditor-cjDk4vdH.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntryEditor-cjDk4vdH.cjs","names":["documentError","useState","Field","TextField","TextArea","NumberField","Switch","RichTextEditor","emptyDocument","EntryPicker","require_RichTextEditor","require_components_EntryPicker_index","require_components_Field_index","require_components_NumberField_index","require_components_Switch_index","require_components_TextField_index","react","react_jsx_runtime","fieldTypes","assertModel","ids","field","model","parseUtcDateTime","value","match","canonical","date","isLink","key","hasRichText","node","validateEntryValues","values","error","item","selectedIds","link","id","EntryEditor","rest","internal","setInternal","defaultValue","changed","setChanged","current","validation","commit","isDisabled","next","previous","onValueChange","className","stored","isPicker","label","errors","showAllErrors","accessibility","Control","event","required","pickerItems","links"],"sources":["../../src/components/EntryEditor/model.ts","../../src/components/EntryEditor/index.tsx"],"sourcesContent":["import type { JSONContent } from \"@tiptap/react\";\nimport { documentError } from \"../RichTextEditor/document\";\nimport type { RichTextDocument } from \"../RichTextEditor\";\n\ninterface ContentFieldBase {\n id: string;\n label: string;\n hint?: string;\n placeholder?: string;\n required?: boolean;\n}\n\nexport type ContentField = ContentFieldBase & (\n | { type: \"shortText\" | \"longText\" | \"richText\" | \"number\" | \"boolean\" | \"dateTime\"; multiple?: never }\n | { type: \"asset\" | \"reference\"; multiple?: boolean }\n);\n\nexport interface ContentModel {\n fields: readonly ContentField[];\n}\n\nexport interface AssetValue { assetId: string }\nexport interface ReferenceValue { entryId: string }\nexport type EntryFieldValue = string | number | boolean | RichTextDocument | AssetValue | ReferenceValue | AssetValue[] | ReferenceValue[];\nexport type EntryValues = Record<string, EntryFieldValue | undefined>;\nexport type EntryErrors = Partial<Record<string, string>>;\n\nconst fieldTypes = new Set([\"shortText\", \"longText\", \"richText\", \"number\", \"boolean\", \"dateTime\", \"asset\", \"reference\"]);\n\nfunction assertModel(model: ContentModel) {\n const ids = new Set<string>();\n for (const field of model.fields) {\n if (!field.id?.trim() || ids.has(field.id)) throw new Error(\"Content model field IDs must be nonempty and unique.\");\n if (!fieldTypes.has(field.type)) throw new Error(`Unsupported content field type: ${field.type}`);\n ids.add(field.id);\n }\n}\n\n/** Accept UTC ISO strings without rolling invalid dates into the next month. */\nexport function parseUtcDateTime(value: unknown): string | undefined {\n if (typeof value !== \"string\") return;\n const match = /^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2})(?::(\\d{2})(?:\\.(\\d{1,3}))?)?(?:Z|\\+00:00)$/.exec(value);\n if (!match) return;\n const canonical = `${match[1]}:${match[2] ?? \"00\"}.${(match[3] ?? \"\").padEnd(3, \"0\")}Z`;\n const date = new Date(canonical);\n if (Number.isFinite(date.getTime()) && date.toISOString() === canonical) return canonical;\n}\n\nfunction isLink(value: unknown, key: \"assetId\" | \"entryId\"): boolean {\n return !!value && typeof value === \"object\" && key in value &&\n typeof (value as Record<string, unknown>)[key] === \"string\" &&\n ((value as Record<string, string>)[key]).trim().length > 0;\n}\n\nfunction hasRichText(node: JSONContent): boolean {\n return !!node.text?.trim() || node.type === \"horizontalRule\" || !!node.content?.some(hasRichText);\n}\n\n/** Validate data loaded from JSON as well as values emitted by EntryEditor. */\nexport function validateEntryValues(model: ContentModel, values: Record<string, unknown>): EntryErrors {\n assertModel(model);\n return Object.fromEntries(model.fields.flatMap((field): [string, string][] => {\n const value = Object.hasOwn(values, field.id) ? values[field.id] : undefined;\n let error: string | undefined;\n if (value === undefined) {\n if (field.required) error = `${field.label} is required.`;\n } else {\n switch (field.type) {\n case \"shortText\":\n case \"longText\":\n if (typeof value !== \"string\") error = \"Enter text.\";\n else if (field.required && !value.trim()) error = `${field.label} is required.`;\n break;\n case \"richText\":\n error = documentError(value);\n if (!error && field.required && !hasRichText(value as RichTextDocument)) error = `${field.label} is required.`;\n break;\n case \"number\":\n if (typeof value !== \"number\" || !Number.isFinite(value)) error = \"Enter a finite number.\";\n break;\n case \"boolean\":\n if (typeof value !== \"boolean\") error = \"Choose a boolean value.\";\n break;\n case \"dateTime\":\n if (!parseUtcDateTime(value)) error = \"Enter a valid UTC date and time.\";\n break;\n case \"asset\":\n case \"reference\": {\n const key = field.type === \"asset\" ? \"assetId\" : \"entryId\";\n if (field.multiple ? !Array.isArray(value) || !value.every((item) => isLink(item, key)) : !isLink(value, key)) {\n error = field.multiple\n ? `Choose a list of ${field.type === \"asset\" ? \"assets\" : \"entries\"}.`\n : `Choose an ${field.type === \"asset\" ? \"asset\" : \"entry\"}.`;\n } else if (field.required && Array.isArray(value) && value.length === 0) error = `${field.label} is required.`;\n break;\n }\n }\n }\n return error ? [[field.id, error]] : [];\n }));\n}\n","import { useState, type HTMLAttributes, type ReactNode } from \"react\";\nimport { EntryPicker, type EntryItem } from \"../EntryPicker\";\nimport { Field } from \"../Field\";\nimport { NumberField } from \"../NumberField\";\nimport { RichTextEditor, type RichTextDocument } from \"../RichTextEditor\";\nimport { emptyDocument } from \"../RichTextEditor/document\";\nimport { Switch } from \"../Switch\";\nimport { TextArea, TextField } from \"../TextField\";\nimport { parseUtcDateTime, validateEntryValues, type ContentField, type ContentModel, type EntryErrors, type EntryFieldValue, type EntryValues } from \"./model\";\nimport \"./style.css\";\n\nexport { validateEntryValues } from \"./model\";\nexport type { AssetValue, ContentField, ContentModel, EntryErrors, EntryFieldValue, EntryValues, ReferenceValue } from \"./model\";\n\nexport interface EntryEditorProps extends Omit<HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\"> {\n model: ContentModel;\n value?: EntryValues;\n defaultValue?: EntryValues;\n onValueChange?: (values: EntryValues) => void;\n /** Available assets or entries, keyed by content field ID. */\n pickerItems?: Record<string, EntryItem[]>;\n /** App-provided messages take precedence over built-in validation. */\n errors?: EntryErrors;\n isDisabled?: boolean;\n /** Reveal validation for untouched fields, for example after a submit attempt. */\n showAllErrors?: boolean;\n}\n\nfunction selectedIds(field: ContentField, value: EntryFieldValue | undefined): string[] {\n const key = field.type === \"asset\" ? \"assetId\" : \"entryId\";\n const links = Array.isArray(value) ? value : value === undefined ? [] : [value];\n return links.flatMap((link) => {\n if (!link || typeof link !== \"object\" || !(key in link)) return [];\n const id = (link as unknown as Record<string, unknown>)[key];\n return typeof id === \"string\" ? [id] : [];\n });\n}\n\n/** An ordered set of content inputs; submission and persistence belong to the app. */\nexport function EntryEditor({\n model,\n value,\n defaultValue = {},\n onValueChange,\n pickerItems = {},\n errors = {},\n isDisabled = false,\n showAllErrors = false,\n className,\n ...rest\n}: EntryEditorProps) {\n const [internal, setInternal] = useState<EntryValues>(defaultValue);\n const [changed, setChanged] = useState<Set<string>>(() => new Set());\n const current = value ?? internal;\n const validation = validateEntryValues(model, current);\n\n const commit = (id: string, next: EntryFieldValue | undefined) => {\n if (isDisabled) return;\n const values = { ...current };\n if (next === undefined) delete values[id];\n else values[id] = next;\n if (value === undefined) setInternal(values);\n setChanged((previous) => new Set(previous).add(id));\n onValueChange?.(values);\n };\n\n return (\n <div className={[\"ds-entry-editor\", className].filter(Boolean).join(\" \")} {...rest}>\n {model.fields.map((field) => {\n const stored = Object.hasOwn(current, field.id) ? current[field.id] : undefined;\n const isPicker = field.type === \"asset\" || field.type === \"reference\";\n const label = field.type === \"dateTime\" ? `${field.label} (UTC)` : field.label;\n const error = errors[field.id] ?? (showAllErrors || changed.has(field.id) ? validation[field.id] : undefined);\n return (\n <Field key={field.id} label={label} hint={field.hint} error={error} isRequired={field.required} isGroup={isPicker}>\n {({ required, ...accessibility }): ReactNode => {\n switch (field.type) {\n case \"shortText\":\n case \"longText\": {\n const Control = field.type === \"shortText\" ? TextField : TextArea;\n return <Control {...accessibility} required={required} disabled={isDisabled} placeholder={field.placeholder}\n value={typeof stored === \"string\" ? stored : \"\"} onChange={(event) => commit(field.id, event.target.value)} />;\n }\n case \"number\":\n return <NumberField {...accessibility} required={required} isDisabled={isDisabled} placeholder={field.placeholder} step=\"any\"\n hasSteppers={false} value={typeof stored === \"number\" && Number.isFinite(stored) ? stored : \"\"}\n onValueChange={(next) => { if (next === \"\" || Number.isFinite(next)) commit(field.id, next === \"\" ? undefined : next); }} />;\n case \"boolean\":\n return <Switch {...accessibility} isDisabled={isDisabled} isSelected={stored === true}\n onSelectedChange={(next) => commit(field.id, next)} />;\n case \"dateTime\":\n return <TextField {...accessibility} required={required} disabled={isDisabled} type=\"datetime-local\" step=\"0.001\"\n value={parseUtcDateTime(stored)?.slice(0, -1) ?? \"\"}\n onChange={(event) => commit(field.id, parseUtcDateTime(`${event.target.value}Z`))} />;\n case \"richText\":\n return <RichTextEditor {...accessibility} label={field.label} isRequired={required} isDisabled={isDisabled}\n placeholder={field.placeholder} format=\"json\" value={stored === undefined ? emptyDocument : stored as RichTextDocument}\n onChange={(next) => commit(field.id, next)} />;\n case \"asset\":\n case \"reference\":\n return <div {...accessibility} role=\"group\">\n <EntryPicker items={pickerItems[field.id] ?? []} value={selectedIds(field, stored)}\n label={field.type === \"asset\" ? \"Assets\" : \"Entries\"} addLabel={`Choose ${field.label}`}\n mode={field.multiple ? \"multiple\" : \"single\"} isDisabled={isDisabled}\n onValueChange={(ids) => {\n if (field.type === \"asset\") {\n const links = ids.map((assetId) => ({ assetId }));\n commit(field.id, field.multiple ? links : links[0]);\n } else {\n const links = ids.map((ent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AI,CAAA,CACH,CAAA,CACT,CACF,CACK,EA1CK3C,EAAM,EA0CX,CAEX,CAAC,CACE,CAAA,CAET,C"}
@@ -0,0 +1,248 @@
1
+ import { Button as e } from "../components/Button/index.js";
2
+ import { ButtonGroup as t } from "../components/ButtonGroup/index.js";
3
+ /* empty css */
4
+ import { forwardRef as n, useCallback as r, useEffect as i, useId as a, useMemo as o, useState as s } from "react";
5
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
6
+ import { EditorContent as u, createDocument as d, getSchema as f, useEditor as p, useEditorState as m } from "@tiptap/react";
7
+ import { Placeholder as h } from "@tiptap/extension-placeholder";
8
+ import { StarterKit as g } from "@tiptap/starter-kit";
9
+ import { Link as _ } from "@tiptap/extension-link";
10
+ //#region src/components/RichTextEditor/document.ts
11
+ var v = {
12
+ type: "doc",
13
+ content: [{ type: "paragraph" }]
14
+ };
15
+ function y() {
16
+ return [g.configure({ link: !1 }), _.configure({
17
+ openOnClick: !1,
18
+ autolink: !0
19
+ })];
20
+ }
21
+ var b = f(y());
22
+ function x(e) {
23
+ return e.content?.length ? e : {
24
+ ...e,
25
+ content: v.content
26
+ };
27
+ }
28
+ function S(e) {
29
+ try {
30
+ if (!e || typeof e != "object" || !("type" in e) || e.type !== "doc") throw Error();
31
+ let t = (e) => {
32
+ let n = b.nodes[e.type ?? ""];
33
+ if (!n || Object.keys(e).some((e) => ![
34
+ "type",
35
+ "attrs",
36
+ "content",
37
+ "marks",
38
+ "text"
39
+ ].includes(e)) || e.text !== void 0 && e.type !== "text" || e.attrs && Object.keys(e.attrs).some((e) => !Object.hasOwn(n.spec.attrs ?? {}, e))) throw Error();
40
+ for (let t of e.marks ?? []) {
41
+ let e = b.marks[t.type];
42
+ if (!e || Object.keys(t).some((e) => !["type", "attrs"].includes(e)) || Object.keys(t.attrs ?? {}).some((t) => !Object.hasOwn(e.spec.attrs ?? {}, t))) throw Error();
43
+ }
44
+ e.content?.forEach(t);
45
+ }, n = e;
46
+ t(n), b.nodeFromJSON(x(n)).check();
47
+ } catch {
48
+ return "Unsupported or invalid rich-text document.";
49
+ }
50
+ }
51
+ //#endregion
52
+ //#region src/components/RichTextEditor/index.tsx
53
+ var C = [
54
+ [
55
+ {
56
+ id: "bold",
57
+ icon: "bold",
58
+ label: "Bold",
59
+ run: (e) => e.chain().focus().toggleBold().run(),
60
+ active: (e) => e.isActive("bold")
61
+ },
62
+ {
63
+ id: "italic",
64
+ icon: "italic",
65
+ label: "Italic",
66
+ run: (e) => e.chain().focus().toggleItalic().run(),
67
+ active: (e) => e.isActive("italic")
68
+ },
69
+ {
70
+ id: "strike",
71
+ icon: "strikethrough",
72
+ label: "Strikethrough",
73
+ run: (e) => e.chain().focus().toggleStrike().run(),
74
+ active: (e) => e.isActive("strike")
75
+ },
76
+ {
77
+ id: "code",
78
+ icon: "code",
79
+ label: "Inline code",
80
+ run: (e) => e.chain().focus().toggleCode().run(),
81
+ active: (e) => e.isActive("code")
82
+ }
83
+ ],
84
+ [
85
+ {
86
+ id: "h2",
87
+ icon: "heading-2",
88
+ label: "Heading",
89
+ run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run(),
90
+ active: (e) => e.isActive("heading", { level: 2 })
91
+ },
92
+ {
93
+ id: "h3",
94
+ icon: "heading-3",
95
+ label: "Subheading",
96
+ run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run(),
97
+ active: (e) => e.isActive("heading", { level: 3 })
98
+ },
99
+ {
100
+ id: "quote",
101
+ icon: "quote",
102
+ label: "Quote",
103
+ run: (e) => e.chain().focus().toggleBlockquote().run(),
104
+ active: (e) => e.isActive("blockquote")
105
+ }
106
+ ],
107
+ [{
108
+ id: "ul",
109
+ icon: "list",
110
+ label: "Bulleted list",
111
+ run: (e) => e.chain().focus().toggleBulletList().run(),
112
+ active: (e) => e.isActive("bulletList")
113
+ }, {
114
+ id: "ol",
115
+ icon: "list-ordered",
116
+ label: "Numbered list",
117
+ run: (e) => e.chain().focus().toggleOrderedList().run(),
118
+ active: (e) => e.isActive("orderedList")
119
+ }],
120
+ [{
121
+ id: "undo",
122
+ icon: "undo",
123
+ label: "Undo",
124
+ run: (e) => e.chain().focus().undo().run()
125
+ }, {
126
+ id: "redo",
127
+ icon: "redo",
128
+ label: "Redo",
129
+ run: (e) => e.chain().focus().redo().run()
130
+ }]
131
+ ], w = n(function(n, f) {
132
+ let { placeholder: g = "Write something…", size: _ = "md", isDisabled: b = !1, isInvalid: w = !1, label: T = "Rich text editor", className: E, toolbarExtra: D, id: O, isRequired: k, "aria-labelledby": A, "aria-describedby": j, "aria-invalid": M } = n, [N, P] = s(!1), [F] = s(() => n.defaultValue ?? (n.format === "json" ? v : "")), I = n.value === void 0 ? F : n.value, L = o(() => n.format === "json" ? S(I) : void 0, [n.format, I]), R = a(), z = w || !!L || M, B = b || !!L, V = o(() => ({
133
+ role: "textbox",
134
+ "aria-label": T,
135
+ "aria-multiline": "true",
136
+ ...O ? { id: O } : {},
137
+ ...A ? { "aria-labelledby": A } : {},
138
+ ...j ? { "aria-describedby": j } : {},
139
+ ...z ? { "aria-invalid": String(z) } : {},
140
+ ...k ? { "aria-required": "true" } : {}
141
+ }), [
142
+ T,
143
+ O,
144
+ A,
145
+ j,
146
+ z,
147
+ k
148
+ ]), H = p({
149
+ immediatelyRender: !1,
150
+ editable: !B,
151
+ content: L ? v : typeof I == "string" ? I : x(I),
152
+ extensions: [...y(), h.configure({ placeholder: g })],
153
+ editorProps: { attributes: V },
154
+ onFocus: () => P(!0),
155
+ onBlur: () => P(!1),
156
+ onUpdate: ({ editor: e }) => {
157
+ B || (n.format === "json" ? n.onChange?.(e.getJSON()) : n.onChange?.(e.getHTML()));
158
+ }
159
+ });
160
+ i(() => {
161
+ H && (H.setEditable(!B, !1), H.setOptions({ editorProps: { attributes: V } }));
162
+ }, [
163
+ H,
164
+ B,
165
+ V
166
+ ]), i(() => {
167
+ if (!H || n.value === void 0 || L) return;
168
+ let e = typeof n.value == "string" ? d(n.value, H.schema) : H.schema.nodeFromJSON(x(n.value));
169
+ e.eq(H.state.doc) || H.commands.setContent(e, { emitUpdate: !1 });
170
+ }, [
171
+ H,
172
+ n.value,
173
+ L
174
+ ]);
175
+ let U = m({
176
+ editor: H,
177
+ selector: ({ editor: e }) => e ? {
178
+ active: Object.fromEntries(C.flat().map((t) => [t.id, t.active?.(e) ?? !1])),
179
+ linkActive: e.isActive("link")
180
+ } : null
181
+ }), W = r(() => {
182
+ if (!H) return;
183
+ if (H.isActive("link")) {
184
+ H.chain().focus().unsetLink().run();
185
+ return;
186
+ }
187
+ let e = window.prompt("Link to");
188
+ e && H.chain().focus().extendMarkRange("link").setLink({ href: e }).run();
189
+ }, [H]);
190
+ return /* @__PURE__ */ l("div", {
191
+ ref: f,
192
+ className: ["ds-rte", E].filter(Boolean).join(" "),
193
+ "data-focused": N || void 0,
194
+ "data-disabled": B || void 0,
195
+ "aria-invalid": z || void 0,
196
+ children: [L && /* @__PURE__ */ c("p", {
197
+ id: R,
198
+ role: "alert",
199
+ className: "ds-field__error",
200
+ children: L
201
+ }), /* @__PURE__ */ l("div", {
202
+ hidden: !!L,
203
+ children: [/* @__PURE__ */ l("div", {
204
+ className: "ds-rte__toolbar",
205
+ role: "toolbar",
206
+ "aria-label": `${T} formatting`,
207
+ children: [
208
+ C.map((n, r) => /* @__PURE__ */ c(t, {
209
+ "aria-label": `Formatting ${r + 1}`,
210
+ children: n.map((t) => /* @__PURE__ */ c(e, {
211
+ size: "sm",
212
+ isIconOnly: !0,
213
+ iconStart: t.icon,
214
+ "aria-label": t.label,
215
+ title: t.label,
216
+ "aria-pressed": t.active ? U?.active[t.id] : void 0,
217
+ variant: U?.active[t.id] ? "active" : "neutral",
218
+ isDisabled: B || !H,
219
+ onClick: () => H && t.run(H)
220
+ }, t.id))
221
+ }, r)),
222
+ /* @__PURE__ */ c(t, {
223
+ "aria-label": "Link",
224
+ children: /* @__PURE__ */ c(e, {
225
+ size: "sm",
226
+ isIconOnly: !0,
227
+ iconStart: U?.linkActive ? "link-off" : "link",
228
+ "aria-label": U?.linkActive ? "Remove link" : "Add link",
229
+ title: U?.linkActive ? "Remove link" : "Add link",
230
+ variant: U?.linkActive ? "active" : "neutral",
231
+ isDisabled: B || !H,
232
+ onClick: W
233
+ })
234
+ }),
235
+ D
236
+ ]
237
+ }), /* @__PURE__ */ c("div", {
238
+ className: "ds-rte__content",
239
+ "data-size": _,
240
+ children: /* @__PURE__ */ c(u, { editor: H })
241
+ })]
242
+ })]
243
+ });
244
+ });
245
+ //#endregion
246
+ export { S as n, v as r, w as t };
247
+
248
+ //# sourceMappingURL=RichTextEditor-DRt-kibg.js.map