@bettercms-ai/kit 3.0.2 → 3.1.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 (155) hide show
  1. package/dist/brand/logo.js +18 -67
  2. package/dist/brand/logo.js.map +1 -1
  3. package/dist/context.js +3 -8
  4. package/dist/context.js.map +1 -1
  5. package/dist/controls/button.js +134 -451
  6. package/dist/controls/button.js.map +1 -1
  7. package/dist/controls/choice.js +95 -336
  8. package/dist/controls/choice.js.map +1 -1
  9. package/dist/controls/code.js +72 -245
  10. package/dist/controls/code.js.map +1 -1
  11. package/dist/controls/color.js +31 -108
  12. package/dist/controls/color.js.map +1 -1
  13. package/dist/controls/date.js +83 -268
  14. package/dist/controls/date.js.map +1 -1
  15. package/dist/controls/form-picker.js +9 -26
  16. package/dist/controls/form-picker.js.map +1 -1
  17. package/dist/controls/icon.js +100 -341
  18. package/dist/controls/icon.js.map +1 -1
  19. package/dist/controls/json.js +7 -20
  20. package/dist/controls/json.js.map +1 -1
  21. package/dist/controls/link.js +156 -561
  22. package/dist/controls/link.js.map +1 -1
  23. package/dist/controls/location.js +35 -124
  24. package/dist/controls/location.js.map +1 -1
  25. package/dist/controls/media.js +267 -928
  26. package/dist/controls/media.js.map +1 -1
  27. package/dist/controls/number.js +23 -80
  28. package/dist/controls/number.js.map +1 -1
  29. package/dist/controls/reference.js +155 -516
  30. package/dist/controls/reference.js.map +1 -1
  31. package/dist/controls/rich-text/article-shell.js +86 -327
  32. package/dist/controls/rich-text/article-shell.js.map +1 -1
  33. package/dist/controls/rich-text/author.js +21 -78
  34. package/dist/controls/rich-text/author.js.map +1 -1
  35. package/dist/controls/rich-text/blocks.js +317 -1086
  36. package/dist/controls/rich-text/blocks.js.map +1 -1
  37. package/dist/controls/rich-text/button.js +10 -31
  38. package/dist/controls/rich-text/button.js.map +1 -1
  39. package/dist/controls/rich-text/catalog.js +51 -168
  40. package/dist/controls/rich-text/catalog.js.map +1 -1
  41. package/dist/controls/rich-text/columns.js +31 -104
  42. package/dist/controls/rich-text/columns.js.map +1 -1
  43. package/dist/controls/rich-text/component-card.js +209 -790
  44. package/dist/controls/rich-text/component-card.js.map +1 -1
  45. package/dist/controls/rich-text/component-panel.js +40 -102
  46. package/dist/controls/rich-text/component-panel.js.map +1 -1
  47. package/dist/controls/rich-text/control.js +32 -101
  48. package/dist/controls/rich-text/control.js.map +1 -1
  49. package/dist/controls/rich-text/editor.js +108 -369
  50. package/dist/controls/rich-text/editor.js.map +1 -1
  51. package/dist/controls/rich-text/embed.js +51 -184
  52. package/dist/controls/rich-text/embed.js.map +1 -1
  53. package/dist/controls/rich-text/floating.js +42 -171
  54. package/dist/controls/rich-text/floating.js.map +1 -1
  55. package/dist/controls/rich-text/footnote.js +28 -89
  56. package/dist/controls/rich-text/footnote.js.map +1 -1
  57. package/dist/controls/rich-text/gallery.js +27 -88
  58. package/dist/controls/rich-text/gallery.js.map +1 -1
  59. package/dist/controls/rich-text/link-form.d.ts +10 -0
  60. package/dist/controls/rich-text/link-form.js +16 -204
  61. package/dist/controls/rich-text/link-form.js.map +1 -1
  62. package/dist/controls/rich-text/plain.js +3 -8
  63. package/dist/controls/rich-text/plain.js.map +1 -1
  64. package/dist/controls/rich-text/related.js +25 -86
  65. package/dist/controls/rich-text/related.js.map +1 -1
  66. package/dist/controls/rich-text/toc.js +15 -48
  67. package/dist/controls/rich-text/toc.js.map +1 -1
  68. package/dist/controls/rich-text/toolbar.js +105 -402
  69. package/dist/controls/rich-text/toolbar.js.map +1 -1
  70. package/dist/controls/scale.js +52 -169
  71. package/dist/controls/scale.js.map +1 -1
  72. package/dist/controls/slot.js +73 -238
  73. package/dist/controls/slot.js.map +1 -1
  74. package/dist/controls/table/table-editor.js +500 -1766
  75. package/dist/controls/table/table-editor.js.map +1 -1
  76. package/dist/controls/table/table-link.js +41 -121
  77. package/dist/controls/table/table-link.js.map +1 -1
  78. package/dist/controls/table/table.js +9 -26
  79. package/dist/controls/table/table.js.map +1 -1
  80. package/dist/controls/text.js +68 -221
  81. package/dist/controls/text.js.map +1 -1
  82. package/dist/controls/unknown-value.js +22 -79
  83. package/dist/controls/unknown-value.js.map +1 -1
  84. package/dist/engine/array.js +228 -821
  85. package/dist/engine/array.js.map +1 -1
  86. package/dist/engine/bits.js +13 -38
  87. package/dist/engine/bits.js.map +1 -1
  88. package/dist/engine/breadcrumb.js +8 -25
  89. package/dist/engine/breadcrumb.js.map +1 -1
  90. package/dist/engine/expand.js +13 -38
  91. package/dist/engine/expand.js.map +1 -1
  92. package/dist/engine/field-list.js +5 -14
  93. package/dist/engine/field-list.js.map +1 -1
  94. package/dist/engine/field-shell.js +244 -849
  95. package/dist/engine/field-shell.js.map +1 -1
  96. package/dist/engine/frame.js +78 -275
  97. package/dist/engine/frame.js.map +1 -1
  98. package/dist/engine/grouping.js +193 -630
  99. package/dist/engine/grouping.js.map +1 -1
  100. package/dist/engine/item-list.js +50 -187
  101. package/dist/engine/item-list.js.map +1 -1
  102. package/dist/engine/kit-field.js +95 -320
  103. package/dist/engine/kit-field.js.map +1 -1
  104. package/dist/engine/schema-form.js +32 -101
  105. package/dist/engine/schema-form.js.map +1 -1
  106. package/dist/engine/slot.js +45 -146
  107. package/dist/engine/slot.js.map +1 -1
  108. package/dist/lib/icons.js +5 -14
  109. package/dist/lib/icons.js.map +1 -1
  110. package/dist/styles.css +1 -5821
  111. package/dist/table/table-view.js +16 -49
  112. package/dist/table/table-view.js.map +1 -1
  113. package/dist/testing/test-form.js +5 -14
  114. package/dist/testing/test-form.js.map +1 -1
  115. package/dist/theme.js +3 -8
  116. package/dist/theme.js.map +1 -1
  117. package/dist/ui/action-tray.js +24 -97
  118. package/dist/ui/action-tray.js.map +1 -1
  119. package/dist/ui/autocomplete.js +38 -135
  120. package/dist/ui/autocomplete.js.map +1 -1
  121. package/dist/ui/button.js +31 -108
  122. package/dist/ui/button.js.map +1 -1
  123. package/dist/ui/choice-switch.js +5 -14
  124. package/dist/ui/choice-switch.js.map +1 -1
  125. package/dist/ui/controls.js +86 -279
  126. package/dist/ui/controls.js.map +1 -1
  127. package/dist/ui/display.js +116 -401
  128. package/dist/ui/display.js.map +1 -1
  129. package/dist/ui/expanded-editor-modal.js +27 -100
  130. package/dist/ui/expanded-editor-modal.js.map +1 -1
  131. package/dist/ui/floating-panel.js +37 -130
  132. package/dist/ui/floating-panel.js.map +1 -1
  133. package/dist/ui/input.js +59 -196
  134. package/dist/ui/input.js.map +1 -1
  135. package/dist/ui/mode-bar.js +11 -32
  136. package/dist/ui/mode-bar.js.map +1 -1
  137. package/dist/ui/overlay.js +176 -613
  138. package/dist/ui/overlay.js.map +1 -1
  139. package/dist/ui/path-crumbs.js +113 -374
  140. package/dist/ui/path-crumbs.js.map +1 -1
  141. package/dist/ui/select.js +78 -311
  142. package/dist/ui/select.js.map +1 -1
  143. package/dist/ui/shortcut-hint.js +6 -19
  144. package/dist/ui/shortcut-hint.js.map +1 -1
  145. package/dist/ui/spinner.js +7 -20
  146. package/dist/ui/spinner.js.map +1 -1
  147. package/dist/ui/split-button.js +10 -35
  148. package/dist/ui/split-button.js.map +1 -1
  149. package/dist/ui/tab.js +17 -50
  150. package/dist/ui/tab.js.map +1 -1
  151. package/dist/ui/toast.js +30 -107
  152. package/dist/ui/toast.js.map +1 -1
  153. package/dist/ui/tooltip-root.js +7 -24
  154. package/dist/ui/tooltip-root.js.map +1 -1
  155. package/package.json +2 -2
@@ -11,7 +11,7 @@ import { editorRoundTrip } from "./dom.js";
11
11
  import { RichTextEditor } from "./editor.js";
12
12
  import { paragraphsHtml, plainParagraphs, usePlainRichText } from "./plain.js";
13
13
  import * as React from "react";
14
- import { jsxDEV } from "react/jsx-dev-runtime";
14
+ import { jsx, jsxs } from "react/jsx-runtime";
15
15
  import { IconArrowsMaximize } from "@tabler/icons-react";
16
16
  //#region src/controls/rich-text/control.tsx
17
17
  /**
@@ -29,7 +29,6 @@ import { IconArrowsMaximize } from "@tabler/icons-react";
29
29
  * - probe: a value the editor cannot carry unchanged (open → no edit → write ≠ stored) is not opened here at all: the
30
30
  * host's own control edits it (LegacyFallback), with the reason above it. Opening never writes.
31
31
  */
32
- var _jsxFileName = "D:/Github/bettercms/bettercms-backend/packages/kit/src/controls/rich-text/control.tsx";
33
32
  var openKey = null;
34
33
  var subs = /* @__PURE__ */ new Set();
35
34
  function setFullEditor(key) {
@@ -108,19 +107,11 @@ function openValue(codec, value, at) {
108
107
  }
109
108
  function RichTextControl(props) {
110
109
  const { richText } = useKitServices();
111
- if (!richText) return /* @__PURE__ */ jsxDEV(LegacyFallback, { ...props }, void 0, false, {
112
- fileName: _jsxFileName,
113
- lineNumber: 121,
114
- columnNumber: 25
115
- }, this);
116
- return /* @__PURE__ */ jsxDEV(CodecRichText, {
110
+ if (!richText) return /* @__PURE__ */ jsx(LegacyFallback, { ...props });
111
+ return /* @__PURE__ */ jsx(CodecRichText, {
117
112
  codec: richText,
118
113
  ...props
119
- }, void 0, false, {
120
- fileName: _jsxFileName,
121
- lineNumber: 122,
122
- columnNumber: 10
123
- }, this);
114
+ });
124
115
  }
125
116
  function CodecRichText({ codec, field, value, onChange, readOnly, path, id, invalid }) {
126
117
  const env = useKitEnv();
@@ -159,9 +150,9 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
159
150
  setHandedOff(docKey, !opened.ok);
160
151
  if (!opened.ok && openKey === docKey) setFullEditor(null);
161
152
  }, [docKey, opened.ok]);
162
- if (!opened.ok) return /* @__PURE__ */ jsxDEV("div", {
153
+ if (!opened.ok) return /* @__PURE__ */ jsxs("div", {
163
154
  className: "flex min-w-0 flex-col gap-1.5",
164
- children: [/* @__PURE__ */ jsxDEV("p", {
155
+ children: [/* @__PURE__ */ jsxs("p", {
165
156
  role: "note",
166
157
  "data-slot": "kit-richtext-handoff",
167
158
  className: "rounded-kit-md bg-kit-subtle px-2.5 py-1.5 text-kit-xs text-kit-fg-2",
@@ -170,11 +161,7 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
170
161
  opened.reason,
171
162
  "."
172
163
  ]
173
- }, void 0, true, {
174
- fileName: _jsxFileName,
175
- lineNumber: 168,
176
- columnNumber: 9
177
- }, this), /* @__PURE__ */ jsxDEV(LegacyFallback, {
164
+ }), /* @__PURE__ */ jsx(LegacyFallback, {
178
165
  field,
179
166
  value,
180
167
  onChange,
@@ -182,16 +169,8 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
182
169
  path,
183
170
  id,
184
171
  invalid
185
- }, void 0, false, {
186
- fileName: _jsxFileName,
187
- lineNumber: 171,
188
- columnNumber: 9
189
- }, this)]
190
- }, void 0, true, {
191
- fileName: _jsxFileName,
192
- lineNumber: 167,
193
- columnNumber: 7
194
- }, this);
172
+ })]
173
+ });
195
174
  const { read, html } = opened;
196
175
  const write = (next) => {
197
176
  let res;
@@ -214,9 +193,9 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
214
193
  onChange(res.value);
215
194
  };
216
195
  const plain = plainScope && !read.losses.length ? plainParagraphs(html) : null;
217
- if (plain !== null) return /* @__PURE__ */ jsxDEV("div", {
196
+ if (plain !== null) return /* @__PURE__ */ jsxs("div", {
218
197
  className: "flex min-w-0 flex-col gap-1.5",
219
- children: [/* @__PURE__ */ jsxDEV(Textarea, {
198
+ children: [/* @__PURE__ */ jsx(Textarea, {
220
199
  id,
221
200
  rows: 3,
222
201
  value: plain,
@@ -225,26 +204,14 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
225
204
  placeholder: field.placeholder,
226
205
  onChange: (e) => write(paragraphsHtml(e.target.value)),
227
206
  className: cn(TEXT_FOCUS, "leading-5")
228
- }, void 0, false, {
229
- fileName: _jsxFileName,
230
- lineNumber: 200,
231
- columnNumber: 9
232
- }, this), refusal ? /* @__PURE__ */ jsxDEV("p", {
207
+ }), refusal ? /* @__PURE__ */ jsx("p", {
233
208
  role: "alert",
234
209
  className: "text-kit-xs text-kit-danger-fg",
235
210
  children: refusal
236
- }, void 0, false, {
237
- fileName: _jsxFileName,
238
- lineNumber: 211,
239
- columnNumber: 11
240
- }, this) : null]
241
- }, void 0, true, {
242
- fileName: _jsxFileName,
243
- lineNumber: 199,
244
- columnNumber: 7
245
- }, this);
246
- return /* @__PURE__ */ jsxDEV("div", { children: [
247
- read.losses.length ? /* @__PURE__ */ jsxDEV("p", {
211
+ }) : null]
212
+ });
213
+ return /* @__PURE__ */ jsxs("div", { children: [
214
+ read.losses.length ? /* @__PURE__ */ jsxs("p", {
248
215
  role: "status",
249
216
  className: "mb-1.5 rounded-kit-md bg-kit-warning-soft px-2.5 py-1.5 text-kit-xs text-kit-warning-fg",
250
217
  children: [
@@ -252,29 +219,17 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
252
219
  read.losses.join(", "),
253
220
  ". Nothing changes until you edit."
254
221
  ]
255
- }, void 0, true, {
256
- fileName: _jsxFileName,
257
- lineNumber: 222,
258
- columnNumber: 9
259
- }, this) : null,
260
- read.undeclared?.length && codec.remap ? /* @__PURE__ */ jsxDEV("div", {
222
+ }) : null,
223
+ read.undeclared?.length && codec.remap ? /* @__PURE__ */ jsx("div", {
261
224
  className: "mb-1.5",
262
- children: /* @__PURE__ */ jsxDEV(UnknownValueNote, {
225
+ children: /* @__PURE__ */ jsx(UnknownValueNote, {
263
226
  items: read.undeclared,
264
227
  onRemap: (key, to) => onChange(codec.remap(value, at, key, to)),
265
228
  onRemove: (key) => onChange(codec.remap(value, at, key, null)),
266
229
  readOnly
267
- }, void 0, false, {
268
- fileName: _jsxFileName,
269
- lineNumber: 228,
270
- columnNumber: 11
271
- }, this)
272
- }, void 0, false, {
273
- fileName: _jsxFileName,
274
- lineNumber: 227,
275
- columnNumber: 9
276
- }, this) : null,
277
- /* @__PURE__ */ jsxDEV(RichTextEditor, {
230
+ })
231
+ }) : null,
232
+ /* @__PURE__ */ jsx(RichTextEditor, {
278
233
  value: html,
279
234
  onChange: write,
280
235
  readOnly,
@@ -293,25 +248,13 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
293
248
  expandedOpen: open,
294
249
  onExpandedOpenChange: (o) => setFullEditor(o ? docKey : null),
295
250
  onComment: env.onComment ? (quote) => env.onComment?.(path, field, quote) : void 0
296
- }, void 0, false, {
297
- fileName: _jsxFileName,
298
- lineNumber: 236,
299
- columnNumber: 7
300
- }, this),
301
- refusal ? /* @__PURE__ */ jsxDEV("p", {
251
+ }),
252
+ refusal ? /* @__PURE__ */ jsx("p", {
302
253
  role: "alert",
303
254
  className: "mt-1.5 text-kit-xs text-kit-danger-fg",
304
255
  children: refusal
305
- }, void 0, false, {
306
- fileName: _jsxFileName,
307
- lineNumber: 258,
308
- columnNumber: 9
309
- }, this) : null
310
- ] }, void 0, true, {
311
- fileName: _jsxFileName,
312
- lineNumber: 220,
313
- columnNumber: 5
314
- }, this);
256
+ }) : null
257
+ ] });
315
258
  }
316
259
  /** Label-row action (at rest): the field's toolbar holds the same button while it's open. */
317
260
  function readsPlain(codec, value, field, path) {
@@ -332,33 +275,21 @@ function RichTextExpandAction({ path, field, value }) {
332
275
  const plainScope = usePlainRichText();
333
276
  if (env.variant === "document" || !richText || handed) return null;
334
277
  if (plainScope && readsPlain(richText, value, field, path)) return null;
335
- return /* @__PURE__ */ jsxDEV(Tooltip, {
278
+ return /* @__PURE__ */ jsx(Tooltip, {
336
279
  content: "Expand editor",
337
280
  shortcut: "⌘↵",
338
- children: /* @__PURE__ */ jsxDEV("button", {
281
+ children: /* @__PURE__ */ jsx("button", {
339
282
  type: "button",
340
283
  "aria-label": `Expand ${field.title}`,
341
284
  onClick: () => setFullEditor(`${env.docId}:${pathKey(path)}`),
342
285
  className: cn("-my-0.5 hidden size-6 items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg", "group-hover/field:inline-flex group-focus-within/field:!hidden [@media(pointer:coarse)]:inline-flex"),
343
- children: /* @__PURE__ */ jsxDEV(IconArrowsMaximize, {
286
+ children: /* @__PURE__ */ jsx(IconArrowsMaximize, {
344
287
  className: "size-3.5",
345
288
  stroke: 1.5,
346
289
  "aria-hidden": true
347
- }, void 0, false, {
348
- fileName: _jsxFileName,
349
- lineNumber: 296,
350
- columnNumber: 9
351
- }, this)
352
- }, void 0, false, {
353
- fileName: _jsxFileName,
354
- lineNumber: 287,
355
- columnNumber: 7
356
- }, this)
357
- }, void 0, false, {
358
- fileName: _jsxFileName,
359
- lineNumber: 286,
360
- columnNumber: 5
361
- }, this);
290
+ })
291
+ })
292
+ });
362
293
  }
363
294
  //#endregion
364
295
  export { RichTextControl, RichTextExpandAction, openValue, setFullEditor };
@@ -1 +1 @@
1
- {"version":3,"file":"control.js","names":[],"sources":["../../../src/controls/rich-text/control.tsx"],"sourcesContent":["/**\n * Rich text field (V2 HEAD controls/richtext.tsx, CPO D49).\n * - The editor stays in place: the document variant is the full editor in the column, the panel variant (inspector)\n * the same editor height-capped.\n * - Expanding (the toolbar's expand button, ⌘↵, or the expand icon in the field's label row at rest) opens the shared\n * ExpandedEditorModal: breadcrumb \"Section › Item › Field\", word count, Done. Esc closes and focus returns.\n *\n * STORAGE. The editor edits HTML; the stored value stays what production stores for the field, through the host's\n * codec (KitServices.richText, see ./codec.ts):\n * - read: stored value → the HTML the editor opens on (+ what the field accepts)\n * - write: edited HTML → the stored value, in the surface's own shape; a write that would drop something is refused,\n * named, and nothing is stored\n * - probe: a value the editor cannot carry unchanged (open → no edit → write ≠ stored) is not opened here at all: the\n * host's own control edits it (LegacyFallback), with the reason above it. Opening never writes.\n */\nimport * as React from \"react\";\nimport { IconArrowsMaximize } from \"@tabler/icons-react\";\nimport { cn } from \"../../lib/cn\";\nimport { useForm, useKitEnv, useKitServices } from \"../../context\";\nimport { resolveFrames } from \"../../lib/frames\";\nimport { pathKey } from \"../../lib/path\";\nimport type { ControlProps } from \"../../types\";\nimport { Tooltip } from \"../../ui/overlay\";\nimport { LegacyFallback } from \"../../engine/kit-field\";\nimport type { KitRichTextCodec, RichTextRead } from \"./codec\";\nimport { editorRoundTrip } from \"./dom\";\nimport { RichTextEditor } from \"./editor\";\nimport { paragraphsHtml, plainParagraphs, usePlainRichText } from \"./plain\";\nimport { Textarea } from \"../../ui/input\";\nimport { TEXT_FOCUS } from \"../text\";\nimport { UnknownValueNote } from \"../unknown-value\";\n\n/* ── which rich-text field (docKey) has its full editor open — shared with the label-row action ── */\nlet openKey: string | null = null;\nconst subs = new Set<() => void>();\nexport function setFullEditor(key: string | null) {\n openKey = key;\n subs.forEach((s) => s());\n}\nfunction useFullEditorKey() {\n return React.useSyncExternalStore(\n (cb) => {\n subs.add(cb);\n return () => subs.delete(cb);\n },\n () => openKey,\n () => openKey,\n );\n}\n\n/* ── fields whose value went to the host's own control: the label-row expand button is not theirs to draw ── */\nconst handedOff = new Set<string>();\nfunction setHandedOff(key: string, on: boolean) {\n if (handedOff.has(key) === on) return;\n if (on) handedOff.add(key);\n else handedOff.delete(key);\n subs.forEach((s) => s());\n}\nfunction useHandedOff(key: string) {\n return React.useSyncExternalStore(\n (cb) => {\n subs.add(cb);\n return () => subs.delete(cb);\n },\n () => handedOff.has(key),\n () => handedOff.has(key),\n );\n}\n\n/** The expanded editor's breadcrumb: the form's frames (root › drilled items) and this field. */\nfunction useExpandCrumbs(fieldTitle: string): string[] {\n const form = useForm();\n const env = useKitEnv();\n if (!form) return [env.docTitle, fieldTitle].filter(Boolean) as string[];\n const { frames } = resolveFrames(form.schema, form.value, form.path, form.resolveSchema);\n const titles = frames.filter((f) => f.kind !== \"history\").map((f, i) => (i === 0 ? env.docTitle || f.title : f.title));\n return [...titles, fieldTitle];\n}\n\n/** A stored block array, or the `{ content }` / `{ format, value }` envelope around one, holding a pull quote block. */\nconst holdsPullQuote = (seed: unknown): boolean =>\n Array.isArray(seed)\n ? seed.some((b) => !!b && typeof b === \"object\" && (b as { _type?: unknown })._type === \"pullQuote\")\n : !!seed && typeof seed === \"object\" && holdsPullQuote((seed as { content?: unknown; value?: unknown }).content ?? (seed as { value?: unknown }).value);\n\n/** What the control decided for one stored value. */\ntype Opened =\n | { ok: true; read: RichTextRead; html: string }\n | { ok: false; reason: string };\n\n/**\n * Open a stored value: read it, then prove the editor carries it unchanged (load → serialize → write === stored).\n * A codec that throws, or a value that does not survive, is handed to the host's own control with the reason.\n */\nexport function openValue(codec: KitRichTextCodec, value: unknown, at: Parameters<KitRichTextCodec[\"read\"]>[1]): Opened {\n let read: RichTextRead;\n try {\n read = codec.read(value, at);\n } catch (err) {\n return { ok: false, reason: `the stored text could not be read (${err instanceof Error ? err.message : String(err)})` };\n }\n // a pull quote (V2 D55 article block) opens as the editor's pull-quote island, but only when the codec renders the\n // stored block as its markup in a field that offers it: a codec that renders nothing for it, or a field with no place\n // for one (a single paragraph), would lose it, so the standard editor edits it\n if (holdsPullQuote(read.seed) && (!/data-rt=\"pullquote\"/.test(read.html) || !read.features.includes(\"pullquote\")))\n return { ok: false, reason: \"it holds a pull quote, which the standard editor edits\" };\n // tables and pull quotes are islands (V2 TableBlock, PullQuote); the probe below proves they survive unchanged\n const html = editorRoundTrip(read.html);\n try {\n const back = codec.write(html, at, value);\n if (back.losses.length) return { ok: false, reason: `this editor would drop ${back.losses.join(\", \")}` };\n if (!codec.same(back.value, read.seed)) return { ok: false, reason: \"it holds formatting this editor cannot keep\" };\n } catch (err) {\n return { ok: false, reason: `the text could not be checked (${err instanceof Error ? err.message : String(err)})` };\n }\n return { ok: true, read, html };\n}\n\nexport function RichTextControl(props: ControlProps) {\n const { richText } = useKitServices();\n if (!richText) return <LegacyFallback {...props} />;\n return <CodecRichText codec={richText} {...props} />;\n}\n\nfunction CodecRichText({ codec, field, value, onChange, readOnly, path, id, invalid }: ControlProps & { codec: KitRichTextCodec }) {\n const env = useKitEnv();\n const docKey = `${env.docId}:${pathKey(path)}`;\n const open = useFullEditorKey() === docKey;\n const crumbs = useExpandCrumbs(field.title);\n const plainScope = usePlainRichText();\n const at = React.useMemo(() => ({ field, path }), [field, path]);\n // the components this field may embed (More components): a hook with one identity for the form's life, so calling it\n // only when the host provides it keeps the hook order fixed\n const { useInsertableComponents } = useKitServices();\n const insertable = useInsertableComponents?.(at);\n /* our own last write: its value comes back as `value`, and the editor keeps the HTML it emitted (no reload, no probe) */\n const mine = React.useRef<{ value: unknown; html: string } | null>(null);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const opened = React.useMemo<Opened>(() => {\n if (mine.current && mine.current.value === value) {\n try {\n return { ok: true, read: codec.read(value, at), html: mine.current.html };\n } catch {\n /* judged afresh below, which names the failure */\n }\n }\n return openValue(codec, value, at);\n // `at` changes identity with the field object; the field's content is what matters\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [codec, value, JSON.stringify(field), pathKey(path)]);\n\n // close when this field goes away (block deselected, drilled elsewhere)\n React.useEffect(\n () => () => {\n if (openKey === docKey) setFullEditor(null);\n setHandedOff(docKey, false);\n },\n [docKey],\n );\n React.useLayoutEffect(() => {\n setHandedOff(docKey, !opened.ok);\n if (!opened.ok && openKey === docKey) setFullEditor(null);\n }, [docKey, opened.ok]);\n\n if (!opened.ok)\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <p role=\"note\" data-slot=\"kit-richtext-handoff\" className=\"rounded-kit-md bg-kit-subtle px-2.5 py-1.5 text-kit-xs text-kit-fg-2\">\n Edited with the standard editor: {opened.reason}.\n </p>\n <LegacyFallback field={field} value={value} onChange={onChange} readOnly={readOnly} path={path} id={id} invalid={invalid} />\n </div>\n );\n\n const { read, html } = opened;\n const write = (next: string) => {\n let res;\n try {\n res = codec.write(next, at, value);\n } catch (err) {\n setRefusal(`Not saved: the text could not be stored (${err instanceof Error ? err.message : String(err)}). Undo the last change with ⌘Z; leaving the field puts back the saved text.`);\n return;\n }\n if (res.losses.length) {\n setRefusal(`Not saved: this field cannot keep ${res.losses.join(\", \")}. Undo the last change with ⌘Z; leaving the field puts back the saved text.`);\n return;\n }\n setRefusal(null);\n if (codec.same(res.value, value)) return;\n mine.current = { value: res.value, html: next };\n onChange(res.value);\n };\n\n // The Values popover (PlainRichTextScope): plain paragraphs are V2's growing textarea (its `text` control), written\n // back through the same codec, one `<p>` per line. Anything richer keeps the editor below.\n const plain = plainScope && !read.losses.length ? plainParagraphs(html) : null;\n if (plain !== null)\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <Textarea\n id={id}\n rows={3}\n value={plain}\n readOnly={readOnly}\n aria-invalid={invalid || !!refusal}\n placeholder={field.placeholder}\n onChange={(e) => write(paragraphsHtml(e.target.value))}\n className={cn(TEXT_FOCUS, \"leading-5\")}\n />\n {refusal ? (\n <p role=\"alert\" className=\"text-kit-xs text-kit-danger-fg\">\n {refusal}\n </p>\n ) : null}\n </div>\n );\n\n /* V2 richtext.tsx:57: the editor sits in a plain <div>; the dash-only notes keep the 6px gap as their own margin */\n return (\n <div>\n {read.losses.length ? (\n <p role=\"status\" className=\"mb-1.5 rounded-kit-md bg-kit-warning-soft px-2.5 py-1.5 text-kit-xs text-kit-warning-fg\">\n Saved by an earlier editor. Editing here would drop {read.losses.join(\", \")}. Nothing changes until you edit.\n </p>\n ) : null}\n {read.undeclared?.length && codec.remap ? (\n <div className=\"mb-1.5\">\n <UnknownValueNote\n items={read.undeclared}\n onRemap={(key, to) => onChange(codec.remap!(value, at, key, to))}\n onRemove={(key) => onChange(codec.remap!(value, at, key, null))}\n readOnly={readOnly}\n />\n </div>\n ) : null}\n <RichTextEditor\n value={html}\n onChange={write}\n readOnly={readOnly}\n placeholder={field.placeholder}\n docKey={docKey}\n id={id}\n invalid={invalid || !!refusal}\n features={read.features}\n references={read.references}\n single={read.single}\n allowNewTab={read.newTab}\n components={insertable && !read.single && !readOnly ? insertable : undefined}\n variant={env.variant === \"document\" ? \"document\" : \"panel\"}\n maxHeight={env.variant === \"document\" ? undefined : 320}\n expandCrumbs={crumbs}\n expandedOpen={open}\n onExpandedOpenChange={(o) => setFullEditor(o ? docKey : null)}\n // select words → Comment in the toolbar: the host's comment popover opens on this field, quoting them\n onComment={env.onComment ? (quote) => env.onComment?.(path, field, quote) : undefined}\n />\n {refusal ? (\n <p role=\"alert\" className=\"mt-1.5 text-kit-xs text-kit-danger-fg\">\n {refusal}\n </p>\n ) : null}\n </div>\n );\n}\n\n/** Label-row action (at rest): the field's toolbar holds the same button while it's open. */\nfunction readsPlain(codec: KitRichTextCodec, value: unknown, field: ControlProps[\"field\"], path: ControlProps[\"path\"]) {\n try {\n const read = codec.read(value, { field, path });\n return !read.losses.length && plainParagraphs(editorRoundTrip(read.html)) !== null;\n } catch {\n return false; // the control names the failure itself\n }\n}\n\nexport function RichTextExpandAction({ path, field, value }: ControlProps) {\n const env = useKitEnv();\n const { richText } = useKitServices();\n const handed = useHandedOff(`${env.docId}:${pathKey(path)}`);\n const plainScope = usePlainRichText();\n // the host's own control (no codec, or a value handed to it) has its own full-screen button\n if (env.variant === \"document\" || !richText || handed) return null;\n // drawn as a plain textarea (V2's `text` control has no ⤢)\n if (plainScope && readsPlain(richText, value, field, path)) return null;\n return (\n <Tooltip content=\"Expand editor\" shortcut=\"⌘↵\">\n <button\n type=\"button\"\n aria-label={`Expand ${field.title}`}\n onClick={() => setFullEditor(`${env.docId}:${pathKey(path)}`)}\n className={cn(\n \"-my-0.5 hidden size-6 items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\",\n \"group-hover/field:inline-flex group-focus-within/field:!hidden [@media(pointer:coarse)]:inline-flex\",\n )}\n >\n <IconArrowsMaximize className=\"size-3.5\" stroke={1.5} aria-hidden />\n </button>\n </Tooltip>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAI,UAAyB;AAC7B,IAAM,uBAAO,IAAI,IAAgB;AACjC,SAAgB,cAAc,KAAoB;CAChD,UAAU;CACV,KAAK,SAAS,MAAM,EAAE,CAAC;AACzB;AACA,SAAS,mBAAmB;CAC1B,OAAO,MAAM,sBACV,OAAO;EACN,KAAK,IAAI,EAAE;EACX,aAAa,KAAK,OAAO,EAAE;CAC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I,GAAG,OAAO;CACnE,OACE,uBAAC,SAAD;EAAS,SAAQ;EAAgB,UAAS;EACxC,UAAA,uBAAC,UAAD;GACE,MAAK;GACL,cAAY,UAAU,MAAM;GAC5B,eAAe,cAAc,GAAG,IAAI,MAAM,GAAG,QAAQ,IAAI,GAAG;GAC5D,WAAW,GACT,uHACA,qGACF;GAEA,UAAA,uBAAC,oBAAD;IAAoB,WAAU;IAAW,QAAQ;IAAK,eAAA;GAAa,GAAA,KAAA,GAAA,OAAA;;;;;EAC7D,GAAA,KAAA,GAAA,OAAA;;;;;CACD,GAAA,KAAA,GAAA,OAAA;;;;;AAEb"}
1
+ {"version":3,"file":"control.js","names":[],"sources":["../../../src/controls/rich-text/control.tsx"],"sourcesContent":["/**\n * Rich text field (V2 HEAD controls/richtext.tsx, CPO D49).\n * - The editor stays in place: the document variant is the full editor in the column, the panel variant (inspector)\n * the same editor height-capped.\n * - Expanding (the toolbar's expand button, ⌘↵, or the expand icon in the field's label row at rest) opens the shared\n * ExpandedEditorModal: breadcrumb \"Section › Item › Field\", word count, Done. Esc closes and focus returns.\n *\n * STORAGE. The editor edits HTML; the stored value stays what production stores for the field, through the host's\n * codec (KitServices.richText, see ./codec.ts):\n * - read: stored value → the HTML the editor opens on (+ what the field accepts)\n * - write: edited HTML → the stored value, in the surface's own shape; a write that would drop something is refused,\n * named, and nothing is stored\n * - probe: a value the editor cannot carry unchanged (open → no edit → write ≠ stored) is not opened here at all: the\n * host's own control edits it (LegacyFallback), with the reason above it. Opening never writes.\n */\nimport * as React from \"react\";\nimport { IconArrowsMaximize } from \"@tabler/icons-react\";\nimport { cn } from \"../../lib/cn\";\nimport { useForm, useKitEnv, useKitServices } from \"../../context\";\nimport { resolveFrames } from \"../../lib/frames\";\nimport { pathKey } from \"../../lib/path\";\nimport type { ControlProps } from \"../../types\";\nimport { Tooltip } from \"../../ui/overlay\";\nimport { LegacyFallback } from \"../../engine/kit-field\";\nimport type { KitRichTextCodec, RichTextRead } from \"./codec\";\nimport { editorRoundTrip } from \"./dom\";\nimport { RichTextEditor } from \"./editor\";\nimport { paragraphsHtml, plainParagraphs, usePlainRichText } from \"./plain\";\nimport { Textarea } from \"../../ui/input\";\nimport { TEXT_FOCUS } from \"../text\";\nimport { UnknownValueNote } from \"../unknown-value\";\n\n/* ── which rich-text field (docKey) has its full editor open — shared with the label-row action ── */\nlet openKey: string | null = null;\nconst subs = new Set<() => void>();\nexport function setFullEditor(key: string | null) {\n openKey = key;\n subs.forEach((s) => s());\n}\nfunction useFullEditorKey() {\n return React.useSyncExternalStore(\n (cb) => {\n subs.add(cb);\n return () => subs.delete(cb);\n },\n () => openKey,\n () => openKey,\n );\n}\n\n/* ── fields whose value went to the host's own control: the label-row expand button is not theirs to draw ── */\nconst handedOff = new Set<string>();\nfunction setHandedOff(key: string, on: boolean) {\n if (handedOff.has(key) === on) return;\n if (on) handedOff.add(key);\n else handedOff.delete(key);\n subs.forEach((s) => s());\n}\nfunction useHandedOff(key: string) {\n return React.useSyncExternalStore(\n (cb) => {\n subs.add(cb);\n return () => subs.delete(cb);\n },\n () => handedOff.has(key),\n () => handedOff.has(key),\n );\n}\n\n/** The expanded editor's breadcrumb: the form's frames (root › drilled items) and this field. */\nfunction useExpandCrumbs(fieldTitle: string): string[] {\n const form = useForm();\n const env = useKitEnv();\n if (!form) return [env.docTitle, fieldTitle].filter(Boolean) as string[];\n const { frames } = resolveFrames(form.schema, form.value, form.path, form.resolveSchema);\n const titles = frames.filter((f) => f.kind !== \"history\").map((f, i) => (i === 0 ? env.docTitle || f.title : f.title));\n return [...titles, fieldTitle];\n}\n\n/** A stored block array, or the `{ content }` / `{ format, value }` envelope around one, holding a pull quote block. */\nconst holdsPullQuote = (seed: unknown): boolean =>\n Array.isArray(seed)\n ? seed.some((b) => !!b && typeof b === \"object\" && (b as { _type?: unknown })._type === \"pullQuote\")\n : !!seed && typeof seed === \"object\" && holdsPullQuote((seed as { content?: unknown; value?: unknown }).content ?? (seed as { value?: unknown }).value);\n\n/** What the control decided for one stored value. */\ntype Opened =\n | { ok: true; read: RichTextRead; html: string }\n | { ok: false; reason: string };\n\n/**\n * Open a stored value: read it, then prove the editor carries it unchanged (load → serialize → write === stored).\n * A codec that throws, or a value that does not survive, is handed to the host's own control with the reason.\n */\nexport function openValue(codec: KitRichTextCodec, value: unknown, at: Parameters<KitRichTextCodec[\"read\"]>[1]): Opened {\n let read: RichTextRead;\n try {\n read = codec.read(value, at);\n } catch (err) {\n return { ok: false, reason: `the stored text could not be read (${err instanceof Error ? err.message : String(err)})` };\n }\n // a pull quote (V2 D55 article block) opens as the editor's pull-quote island, but only when the codec renders the\n // stored block as its markup in a field that offers it: a codec that renders nothing for it, or a field with no place\n // for one (a single paragraph), would lose it, so the standard editor edits it\n if (holdsPullQuote(read.seed) && (!/data-rt=\"pullquote\"/.test(read.html) || !read.features.includes(\"pullquote\")))\n return { ok: false, reason: \"it holds a pull quote, which the standard editor edits\" };\n // tables and pull quotes are islands (V2 TableBlock, PullQuote); the probe below proves they survive unchanged\n const html = editorRoundTrip(read.html);\n try {\n const back = codec.write(html, at, value);\n if (back.losses.length) return { ok: false, reason: `this editor would drop ${back.losses.join(\", \")}` };\n if (!codec.same(back.value, read.seed)) return { ok: false, reason: \"it holds formatting this editor cannot keep\" };\n } catch (err) {\n return { ok: false, reason: `the text could not be checked (${err instanceof Error ? err.message : String(err)})` };\n }\n return { ok: true, read, html };\n}\n\nexport function RichTextControl(props: ControlProps) {\n const { richText } = useKitServices();\n if (!richText) return <LegacyFallback {...props} />;\n return <CodecRichText codec={richText} {...props} />;\n}\n\nfunction CodecRichText({ codec, field, value, onChange, readOnly, path, id, invalid }: ControlProps & { codec: KitRichTextCodec }) {\n const env = useKitEnv();\n const docKey = `${env.docId}:${pathKey(path)}`;\n const open = useFullEditorKey() === docKey;\n const crumbs = useExpandCrumbs(field.title);\n const plainScope = usePlainRichText();\n const at = React.useMemo(() => ({ field, path }), [field, path]);\n // the components this field may embed (More components): a hook with one identity for the form's life, so calling it\n // only when the host provides it keeps the hook order fixed\n const { useInsertableComponents } = useKitServices();\n const insertable = useInsertableComponents?.(at);\n /* our own last write: its value comes back as `value`, and the editor keeps the HTML it emitted (no reload, no probe) */\n const mine = React.useRef<{ value: unknown; html: string } | null>(null);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const opened = React.useMemo<Opened>(() => {\n if (mine.current && mine.current.value === value) {\n try {\n return { ok: true, read: codec.read(value, at), html: mine.current.html };\n } catch {\n /* judged afresh below, which names the failure */\n }\n }\n return openValue(codec, value, at);\n // `at` changes identity with the field object; the field's content is what matters\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [codec, value, JSON.stringify(field), pathKey(path)]);\n\n // close when this field goes away (block deselected, drilled elsewhere)\n React.useEffect(\n () => () => {\n if (openKey === docKey) setFullEditor(null);\n setHandedOff(docKey, false);\n },\n [docKey],\n );\n React.useLayoutEffect(() => {\n setHandedOff(docKey, !opened.ok);\n if (!opened.ok && openKey === docKey) setFullEditor(null);\n }, [docKey, opened.ok]);\n\n if (!opened.ok)\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <p role=\"note\" data-slot=\"kit-richtext-handoff\" className=\"rounded-kit-md bg-kit-subtle px-2.5 py-1.5 text-kit-xs text-kit-fg-2\">\n Edited with the standard editor: {opened.reason}.\n </p>\n <LegacyFallback field={field} value={value} onChange={onChange} readOnly={readOnly} path={path} id={id} invalid={invalid} />\n </div>\n );\n\n const { read, html } = opened;\n const write = (next: string) => {\n let res;\n try {\n res = codec.write(next, at, value);\n } catch (err) {\n setRefusal(`Not saved: the text could not be stored (${err instanceof Error ? err.message : String(err)}). Undo the last change with ⌘Z; leaving the field puts back the saved text.`);\n return;\n }\n if (res.losses.length) {\n setRefusal(`Not saved: this field cannot keep ${res.losses.join(\", \")}. Undo the last change with ⌘Z; leaving the field puts back the saved text.`);\n return;\n }\n setRefusal(null);\n if (codec.same(res.value, value)) return;\n mine.current = { value: res.value, html: next };\n onChange(res.value);\n };\n\n // The Values popover (PlainRichTextScope): plain paragraphs are V2's growing textarea (its `text` control), written\n // back through the same codec, one `<p>` per line. Anything richer keeps the editor below.\n const plain = plainScope && !read.losses.length ? plainParagraphs(html) : null;\n if (plain !== null)\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <Textarea\n id={id}\n rows={3}\n value={plain}\n readOnly={readOnly}\n aria-invalid={invalid || !!refusal}\n placeholder={field.placeholder}\n onChange={(e) => write(paragraphsHtml(e.target.value))}\n className={cn(TEXT_FOCUS, \"leading-5\")}\n />\n {refusal ? (\n <p role=\"alert\" className=\"text-kit-xs text-kit-danger-fg\">\n {refusal}\n </p>\n ) : null}\n </div>\n );\n\n /* V2 richtext.tsx:57: the editor sits in a plain <div>; the dash-only notes keep the 6px gap as their own margin */\n return (\n <div>\n {read.losses.length ? (\n <p role=\"status\" className=\"mb-1.5 rounded-kit-md bg-kit-warning-soft px-2.5 py-1.5 text-kit-xs text-kit-warning-fg\">\n Saved by an earlier editor. Editing here would drop {read.losses.join(\", \")}. Nothing changes until you edit.\n </p>\n ) : null}\n {read.undeclared?.length && codec.remap ? (\n <div className=\"mb-1.5\">\n <UnknownValueNote\n items={read.undeclared}\n onRemap={(key, to) => onChange(codec.remap!(value, at, key, to))}\n onRemove={(key) => onChange(codec.remap!(value, at, key, null))}\n readOnly={readOnly}\n />\n </div>\n ) : null}\n <RichTextEditor\n value={html}\n onChange={write}\n readOnly={readOnly}\n placeholder={field.placeholder}\n docKey={docKey}\n id={id}\n invalid={invalid || !!refusal}\n features={read.features}\n references={read.references}\n single={read.single}\n allowNewTab={read.newTab}\n components={insertable && !read.single && !readOnly ? insertable : undefined}\n variant={env.variant === \"document\" ? \"document\" : \"panel\"}\n maxHeight={env.variant === \"document\" ? undefined : 320}\n expandCrumbs={crumbs}\n expandedOpen={open}\n onExpandedOpenChange={(o) => setFullEditor(o ? docKey : null)}\n // select words → Comment in the toolbar: the host's comment popover opens on this field, quoting them\n onComment={env.onComment ? (quote) => env.onComment?.(path, field, quote) : undefined}\n />\n {refusal ? (\n <p role=\"alert\" className=\"mt-1.5 text-kit-xs text-kit-danger-fg\">\n {refusal}\n </p>\n ) : null}\n </div>\n );\n}\n\n/** Label-row action (at rest): the field's toolbar holds the same button while it's open. */\nfunction readsPlain(codec: KitRichTextCodec, value: unknown, field: ControlProps[\"field\"], path: ControlProps[\"path\"]) {\n try {\n const read = codec.read(value, { field, path });\n return !read.losses.length && plainParagraphs(editorRoundTrip(read.html)) !== null;\n } catch {\n return false; // the control names the failure itself\n }\n}\n\nexport function RichTextExpandAction({ path, field, value }: ControlProps) {\n const env = useKitEnv();\n const { richText } = useKitServices();\n const handed = useHandedOff(`${env.docId}:${pathKey(path)}`);\n const plainScope = usePlainRichText();\n // the host's own control (no codec, or a value handed to it) has its own full-screen button\n if (env.variant === \"document\" || !richText || handed) return null;\n // drawn as a plain textarea (V2's `text` control has no ⤢)\n if (plainScope && readsPlain(richText, value, field, path)) return null;\n return (\n <Tooltip content=\"Expand editor\" shortcut=\"⌘↵\">\n <button\n type=\"button\"\n aria-label={`Expand ${field.title}`}\n onClick={() => setFullEditor(`${env.docId}:${pathKey(path)}`)}\n className={cn(\n \"-my-0.5 hidden size-6 items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\",\n \"group-hover/field:inline-flex group-focus-within/field:!hidden [@media(pointer:coarse)]:inline-flex\",\n )}\n >\n <IconArrowsMaximize className=\"size-3.5\" stroke={1.5} aria-hidden />\n </button>\n </Tooltip>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAI,UAAyB;AAC7B,IAAM,uBAAO,IAAI,IAAgB;AACjC,SAAgB,cAAc,KAAoB;CAChD,UAAU;CACV,KAAK,SAAS,MAAM,EAAE,CAAC;AACzB;AACA,SAAS,mBAAmB;CAC1B,OAAO,MAAM,sBACV,OAAO;EACN,KAAK,IAAI,EAAE;EACX,aAAa,KAAK,OAAO,EAA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