@nanahoshi/mona-ui 0.36.0 → 0.37.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 (61) hide show
  1. package/docs/api/editor.md +67 -0
  2. package/docs/api/file-upload.md +1 -1
  3. package/docs/api/i18n.md +16 -0
  4. package/docs/api/locales.md +14 -14
  5. package/docs/api/popup.md +1 -1
  6. package/docs/editor.md +238 -9
  7. package/fesm2022/nanahoshi-mona-ui-editor.mjs +1348 -190
  8. package/fesm2022/nanahoshi-mona-ui-file-upload.mjs +28 -94
  9. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +50 -1
  10. package/fesm2022/nanahoshi-mona-ui-internal.mjs +83 -2
  11. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +59 -1
  12. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +23 -1
  13. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +35 -1
  14. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +35 -1
  15. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +17 -1
  16. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +35 -1
  17. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +17 -1
  18. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +17 -1
  19. package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +47 -1
  20. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +35 -1
  21. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +47 -1
  22. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +17 -1
  23. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +17 -1
  24. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +17 -1
  25. package/fesm2022/nanahoshi-mona-ui-popup.mjs +29 -8
  26. package/i18n/catalogs/en-US.messages.json +17 -1
  27. package/llms.txt +1 -1
  28. package/locales/ar-sa/ar-sa.messages.json +17 -1
  29. package/locales/de-de/de-de.messages.json +17 -1
  30. package/locales/es-es/es-es.messages.json +17 -1
  31. package/locales/fr-fr/fr-fr.messages.json +17 -1
  32. package/locales/id-id/id-id.messages.json +17 -1
  33. package/locales/it-it/it-it.messages.json +17 -1
  34. package/locales/ja-jp/ja-jp.messages.json +17 -1
  35. package/locales/ko-kr/ko-kr.messages.json +17 -1
  36. package/locales/pl-pl/pl-pl.messages.json +17 -1
  37. package/locales/pt-br/pt-br.messages.json +17 -1
  38. package/locales/ru-ru/ru-ru.messages.json +17 -1
  39. package/locales/tr-tr/tr-tr.messages.json +17 -1
  40. package/locales/zh-cn/zh-cn.messages.json +17 -1
  41. package/locales/zh-tw/zh-tw.messages.json +17 -1
  42. package/package.json +1 -1
  43. package/types/nanahoshi-mona-ui-editor.d.ts +124 -2
  44. package/types/nanahoshi-mona-ui-file-upload.d.ts +1 -0
  45. package/types/nanahoshi-mona-ui-i18n.d.ts +32 -0
  46. package/types/nanahoshi-mona-ui-internal.d.ts +37 -0
  47. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +16 -0
  48. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +16 -0
  49. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +16 -0
  50. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +16 -0
  51. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +16 -0
  52. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +16 -0
  53. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +16 -0
  54. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +16 -0
  55. package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +16 -0
  56. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +16 -0
  57. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +16 -0
  58. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +16 -0
  59. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +16 -0
  60. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +16 -0
  61. package/types/nanahoshi-mona-ui-popup.d.ts +3 -1
@@ -1,11 +1,18 @@
1
1
  import * as i0 from "@angular/core";
2
- import { Component, DOCUMENT, DestroyRef, Directive, ElementRef, Injectable, Injector, afterEveryRender, afterNextRender, afterRenderEffect, booleanAttribute, computed, effect, inject, input, model, output, signal, untracked, viewChild } from "@angular/core";
2
+ import { Component, DOCUMENT, DestroyRef, Directive, ElementRef, Injectable, Injector, afterEveryRender, afterNextRender, afterRenderEffect, booleanAttribute, computed, effect, inject, input, isDevMode, model, output, signal, untracked, viewChild } from "@angular/core";
3
3
  import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
4
4
  import { MonaI18nService, formatNumber, injectComponentDirection } from "@nanahoshi/mona-ui/i18n";
5
- import { FIELD_ASSOCIATION_BOUNDARY, RovingToolbar, createElementControlId, injectEffectiveDisabled, injectLabelAssociation } from "@nanahoshi/mona-ui/internal";
5
+ import { FIELD_ASSOCIATION_BOUNDARY, RovingToolbar, createElementControlId, injectEffectiveDisabled, injectLabelAssociation, matchesAccept, parseAccept, runUpload, themeOverlaySurfaceClasses } from "@nanahoshi/mona-ui/internal";
6
+ import { injectLiveAnnouncer } from "@nanahoshi/mona-ui/internal/live-announcer";
7
+ import { Subject, catchError, debounceTime, from, fromEvent, isObservable, map, of, switchMap } from "rxjs";
6
8
  import { twMerge } from "tailwind-merge";
9
+ import { DOCUMENT as DOCUMENT$1 } from "@angular/common";
10
+ import { FileUploadComponent, formatFileSize } from "@nanahoshi/mona-ui/file-upload";
11
+ import { Editor, Extension, Node, mergeAttributes } from "@tiptap/core";
12
+ import { AllSelection, NodeSelection, Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
13
+ import { Decoration, DecorationSet } from "@tiptap/pm/view";
14
+ import { cva } from "class-variance-authority";
7
15
  import { ImmutableSet, List, any, range } from "@mirei/ts-collections";
8
- import { Editor, Extension } from "@tiptap/core";
9
16
  import { Highlight } from "@tiptap/extension-highlight";
10
17
  import { TaskItem, TaskList } from "@tiptap/extension-list";
11
18
  import { Subscript } from "@tiptap/extension-subscript";
@@ -14,10 +21,8 @@ import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table
14
21
  import { TextAlign } from "@tiptap/extension-text-align";
15
22
  import { Color, FontFamily, TextStyle } from "@tiptap/extension-text-style";
16
23
  import { StarterKit } from "@tiptap/starter-kit";
17
- import { Subject } from "rxjs";
18
24
  import { Image } from "@tiptap/extension-image";
19
- import { AllSelection, TextSelection } from "@tiptap/pm/state";
20
- import { cva } from "class-variance-authority";
25
+ import { PopupDataInjectionToken, PopupService } from "@nanahoshi/mona-ui/popup";
21
26
  import { ButtonDirective } from "@nanahoshi/mona-ui/button";
22
27
  import { ButtonGroupComponent } from "@nanahoshi/mona-ui/button-group";
23
28
  import { ColorPickerComponent, ColorPickerValueTemplateDirective } from "@nanahoshi/mona-ui/color-picker";
@@ -33,6 +38,10 @@ import { PopoverComponent } from "@nanahoshi/mona-ui/popover";
33
38
  function localizeNumber(value, options) {
34
39
  return formatNumber(value, "en-US", options);
35
40
  }
41
+ const PLURAL_RULES = new Intl.PluralRules("en-US");
42
+ function plural(category, forms) {
43
+ return (forms[category] ?? forms.other)();
44
+ }
36
45
  const EDITOR_DEFAULT_MESSAGES = {
37
46
  addColumnAfter: "Add column after",
38
47
  addColumnBefore: "Add column before",
@@ -50,6 +59,22 @@ const EDITOR_DEFAULT_MESSAGES = {
50
59
  backgroundColor: "Background color",
51
60
  bold: "Bold",
52
61
  cancel: "Cancel",
62
+ characterCount: (count) => plural(PLURAL_RULES.select(count), {
63
+ one: () => `${localizeNumber(count)} character`,
64
+ other: () => `${localizeNumber(count)} characters`
65
+ }),
66
+ characterLimitHint: (limit) => `You can enter up to ${plural(PLURAL_RULES.select(limit), {
67
+ one: () => `${localizeNumber(limit)} character`,
68
+ other: () => `${localizeNumber(limit)} characters`
69
+ })}.`,
70
+ charactersLeft: (count) => plural(PLURAL_RULES.select(count), {
71
+ one: () => `${localizeNumber(count)} character left`,
72
+ other: () => `${localizeNumber(count)} characters left`
73
+ }),
74
+ charactersOver: (count) => plural(PLURAL_RULES.select(count), {
75
+ one: () => `${localizeNumber(count)} character too many`,
76
+ other: () => `${localizeNumber(count)} characters too many`
77
+ }),
53
78
  codeBlock: "Code block",
54
79
  color: "Color",
55
80
  contentLabel: "Rich text editor",
@@ -57,6 +82,7 @@ const EDITOR_DEFAULT_MESSAGES = {
57
82
  deleteColumn: "Delete column",
58
83
  deleteRow: "Delete row",
59
84
  deleteTable: "Delete table",
85
+ editImage: "Edit image",
60
86
  editLink: "Edit link",
61
87
  enterUrl: "Enter the URL",
62
88
  fontSize: "Font size",
@@ -64,6 +90,11 @@ const EDITOR_DEFAULT_MESSAGES = {
64
90
  heading: (level) => `Heading ${localizeNumber(level)}`,
65
91
  heightPx: "Height (px)",
66
92
  historyGroup: "History",
93
+ imageFile: "Image file",
94
+ imageInserted: (name) => `${name} inserted.`,
95
+ imageTooLarge: (name, size) => `${name} wasn't added. The file is larger than ${size}.`,
96
+ imageUploadFailed: (name) => `${name} couldn't be uploaded.`,
97
+ imageUploading: (name) => `Uploading ${name}`,
67
98
  imageUrl: "Image URL",
68
99
  indent: "Indent",
69
100
  indentGroup: "Indentation",
@@ -79,12 +110,20 @@ const EDITOR_DEFAULT_MESSAGES = {
79
110
  justify: "Justify",
80
111
  linkGroup: "Link",
81
112
  listGroup: "Lists",
113
+ mentionNoResults: "No matches",
114
+ mentionResults: (count) => plural(PLURAL_RULES.select(count), {
115
+ one: () => `${localizeNumber(count)} suggestion`,
116
+ other: () => `${localizeNumber(count)} suggestions`
117
+ }),
118
+ mentionSearching: "Searching…",
119
+ mentionSuggestions: "Suggestions",
82
120
  mergeCells: "Merge selected cells",
83
121
  outdent: "Outdent",
84
122
  paragraph: "Paragraph",
85
123
  quotation: "Quotation",
86
124
  redo: "Redo",
87
125
  removeLink: "Remove link",
126
+ save: "Save",
88
127
  selectFontFamily: "Select font family",
89
128
  selectFontSize: "Select font size",
90
129
  splitCell: "Split cell",
@@ -98,8 +137,309 @@ const EDITOR_DEFAULT_MESSAGES = {
98
137
  toolbar: "Formatting",
99
138
  underline: "Underline",
100
139
  undo: "Undo",
101
- widthPx: "Width (px)"
140
+ widthPx: "Width (px)",
141
+ wordCount: (count) => plural(PLURAL_RULES.select(count), {
142
+ one: () => `${localizeNumber(count)} word`,
143
+ other: () => `${localizeNumber(count)} words`
144
+ })
102
145
  };
146
+ const PLACEHOLDER_KEY = new PluginKey("monaImageUploadPlaceholders");
147
+ function insertionEnd(tr) {
148
+ let end = null;
149
+ tr.mapping.maps.at(-1)?.forEach((_from, _to, _newFrom, newTo) => {
150
+ end = newTo;
151
+ });
152
+ return end;
153
+ }
154
+ function filesOf(transfer) {
155
+ return transfer ? Array.from(transfer.files) : [];
156
+ }
157
+ function addImagePlaceholder(view, id, position, element) {
158
+ const action = { add: {
159
+ element,
160
+ id,
161
+ position
162
+ } };
163
+ view.dispatch(view.state.tr.setMeta(PLACEHOLDER_KEY, action).setMeta("addToHistory", false));
164
+ }
165
+ function findImagePlaceholder(state, id) {
166
+ return PLACEHOLDER_KEY.getState(state)?.find((placeholder) => placeholder.id === id)?.position ?? null;
167
+ }
168
+ function removeImagePlaceholder(view, id) {
169
+ const action = { remove: id };
170
+ view.dispatch(view.state.tr.setMeta(PLACEHOLDER_KEY, action).setMeta("addToHistory", false));
171
+ }
172
+ function imagePlaceholderRemoval(id) {
173
+ return {
174
+ key: PLACEHOLDER_KEY,
175
+ value: { remove: id }
176
+ };
177
+ }
178
+ const ImageUpload = Extension.create({
179
+ name: "monaImageUpload",
180
+ addOptions() {
181
+ return {
182
+ accepted: () => [],
183
+ upload: () => void 0
184
+ };
185
+ },
186
+ addProseMirrorPlugins() {
187
+ const options = this.options;
188
+ return [new Plugin({
189
+ key: PLACEHOLDER_KEY,
190
+ state: {
191
+ init: () => [],
192
+ apply: (tr, placeholders) => {
193
+ const action = tr.getMeta(PLACEHOLDER_KEY);
194
+ const removedIndex = action && "remove" in action ? placeholders.findIndex((placeholder) => placeholder.id === action.remove) : -1;
195
+ const removed = removedIndex < 0 ? null : placeholders[removedIndex];
196
+ const end = removed && tr.docChanged ? insertionEnd(tr) : null;
197
+ let next = !tr.docChanged ? placeholders : placeholders.flatMap((placeholder, index) => {
198
+ if (end !== null && index > removedIndex && placeholder.position === removed?.position) return [{
199
+ ...placeholder,
200
+ position: end
201
+ }];
202
+ const mapped = tr.mapping.mapResult(placeholder.position, -1);
203
+ return mapped.deletedAcross ? [] : [{
204
+ ...placeholder,
205
+ position: mapped.pos
206
+ }];
207
+ });
208
+ if (action && "add" in action) next = [...next, action.add];
209
+ else if (action && "remove" in action) next = next.filter((placeholder) => placeholder.id !== action.remove);
210
+ return next;
211
+ }
212
+ },
213
+ props: {
214
+ decorations: (state) => {
215
+ const placeholders = PLACEHOLDER_KEY.getState(state) ?? [];
216
+ if (placeholders.length === 0) return null;
217
+ return DecorationSet.create(state.doc, placeholders.map(({ element, id, position }) => Decoration.widget(position, element, {
218
+ id,
219
+ key: id,
220
+ side: -1
221
+ })));
222
+ },
223
+ handleDrop: (view, event, _slice, moved) => {
224
+ if (moved) return false;
225
+ const files = options.accepted(filesOf(event.dataTransfer));
226
+ if (files.length === 0) return false;
227
+ event.preventDefault();
228
+ const target = view.posAtCoords({
229
+ left: event.clientX,
230
+ top: event.clientY
231
+ });
232
+ options.upload(view, files, target?.pos ?? view.state.selection.from);
233
+ return true;
234
+ },
235
+ handlePaste: (view, event) => {
236
+ if (event.clipboardData?.getData("text/html")) return false;
237
+ const files = options.accepted(filesOf(event.clipboardData));
238
+ if (files.length === 0) return false;
239
+ event.preventDefault();
240
+ if (!view.state.selection.empty) view.dispatch(view.state.tr.deleteSelection());
241
+ options.upload(view, files, view.state.selection.from);
242
+ return true;
243
+ }
244
+ }
245
+ })];
246
+ }
247
+ });
248
+ const editorBaseThemeVariants = cva(`
249
+ flex flex-col
250
+ bg-surface text-foreground
251
+ border border-border
252
+ transition-[border-color,box-shadow] duration-150 ease-in
253
+ focus-within:border-focus-indicator
254
+ focus-within:ring-2 focus-within:ring-focus-indicator/35
255
+
256
+ data-[disabled='true']:cursor-not-allowed
257
+ data-[disabled='true']:border-disabled-border
258
+ data-[disabled='true']:text-disabled-foreground
259
+ data-[invalid='true']:border-error
260
+ data-[invalid='true']:ring-2 data-[invalid='true']:ring-error/35
261
+ data-[invalid='true']:focus-within:border-error
262
+ data-[invalid='true']:focus-within:ring-error/35
263
+
264
+ prose prose-neutral max-w-none
265
+ prose-headings:text-foreground prose-headings:font-bold
266
+ prose-headings:mt-1 prose-headings:mb-1
267
+ prose-p:text-foreground prose-p:my-1
268
+ prose-strong:text-inherit
269
+ [&_span[style*=color]_mark]:text-inherit
270
+ prose-a:text-[var(--mona-primary-text-color,var(--color-primary))]
271
+
272
+ [&_ol]:ps-8 [&_ul]:ps-8
273
+
274
+ [&_blockquote]:border-s-4
275
+ [&_blockquote]:border-s-solid
276
+ [&_blockquote]:border-s-border-control-hover
277
+ [&_blockquote]:px-4 [&_blockquote]:py-2
278
+ [&_blockquote]:ms-4
279
+ [&_blockquote]:bg-surface-muted
280
+
281
+ [&_hr]:my-1 [&_hr]:bg-border-subtle
282
+ [&_hr]:border [&_hr]:border-border-subtle
283
+
284
+ [&_ul[data-type='taskList']_li]:flex
285
+ [&_ul[data-type='taskList']_li]:py-0.5
286
+ [&_ul[data-type='taskList']_li>label]:grow-0
287
+ [&_ul[data-type='taskList']_li>label]:shrink-0
288
+ [&_ul[data-type='taskList']_li>label]:basis-auto
289
+ [&_ul[data-type='taskList']_li>div]:grow-1
290
+ [&_ul[data-type='taskList']_li>div]:shrink-1
291
+ [&_ul[data-type='taskList']_li>div]:basis-auto
292
+ [&_ul[data-type='taskList']_input[type='checkbox']]:me-2!
293
+
294
+ [&_img]:max-w-full
295
+ [&_img]:h-auto
296
+ [&_img.ProseMirror-selectednode]:outline-3
297
+ [&_img.ProseMirror-selectednode]:outline-focus-indicator
298
+
299
+ [&_span[data-type='mention']]:rounded-sm
300
+ [&_span[data-type='mention']]:bg-primary-subtle
301
+ [&_span[data-type='mention']]:px-0.5
302
+ [&_span[data-type='mention']]:font-medium
303
+ [&_span[data-type='mention']]:text-primary-subtle-foreground
304
+ [&_span[data-type='mention']]:[box-decoration-break:clone]
305
+
306
+ [&_pre]:bg-surface-muted
307
+ [&_pre]:border [&_pre]:border-border-subtle
308
+ [&_pre]:whitespace-pre-wrap
309
+ [&_pre]:font-mono
310
+ [&_pre_code]:p-0
311
+ [&_pre_code]:text-sm
312
+ [&_pre_code]:bg-none
313
+
314
+ [&.ProseMirror-gapcursor]:after:border-foreground!
315
+
316
+ [&_table]:border-collapse
317
+ [&_table]:m-0
318
+ [&_table]:overflow-hidden
319
+ [&_table]:table-fixed
320
+ [&_table]:w-full
321
+ [&_table_td]:border [&_table_td]:border-border-subtle
322
+ [&_table_td]:p-2 [&_table_td]:align-top [&_table_td]:relative
323
+ [&_table_th]:border [&_table_th]:border-border-subtle
324
+ [&_table_th]:p-2 [&_table_th]:align-top [&_table_th]:relative
325
+
326
+ [&_table_th]:bg-surface-muted [&_table_th]:text-foreground [&_table_th]:font-bold
327
+
328
+ [&_.selectedCell]:after:content-[''] [&_.selectedCell]:after:absolute [&_.selectedCell]:after:inset-0
329
+ [&_.selectedCell]:after:pointer-events-none
330
+ [&_.selectedCell]:after:z-2
331
+ [&_.selectedCell]:after:bg-active/70
332
+
333
+ [&_.column-resize-handle]:absolute
334
+ [&_.column-resize-handle]:bg-focus-indicator
335
+ [&_.column-resize-handle]:w-1
336
+ [&_.column-resize-handle]:pointer-events-none
337
+ [&_.column-resize-handle]:top-0
338
+ [&_.column-resize-handle]:-bottom-0.5
339
+ [&_.column-resize-handle]:-end-0.5
340
+
341
+ [&_.ProseMirror.resize-cursor]:cursor-ew-resize
342
+
343
+ `);
344
+ const editorContainerThemeVariants = cva(`
345
+ h-full w-full bg-surface
346
+ [&>.ProseMirror]:p-1.5
347
+ [&>.ProseMirror]:text-foreground
348
+ [&>.ProseMirror]:border-none
349
+ [&>.ProseMirror]:outline-none [&>.ProseMirror:focus-visible]:outline-hidden
350
+ [&>.ProseMirror]:w-full
351
+ [&>.ProseMirror]:h-full
352
+ [&>.ProseMirror]:overflow-auto
353
+ [&>.ProseMirror]:resize-none
354
+ [&>.ProseMirror]:[scrollbar-color:var(--color-scrollbar-thumb)_var(--color-scrollbar-track)]
355
+ [&>.ProseMirror]:[scrollbar-width:thin]
356
+ `, {
357
+ variants: { disabled: {
358
+ true: "bg-disabled-background [&>.ProseMirror]:text-disabled-foreground",
359
+ false: ""
360
+ } },
361
+ defaultVariants: { disabled: false }
362
+ });
363
+ const editorFontColorPreviewThemeVariants = cva(`
364
+ w-full flex h-[2px]
365
+ `);
366
+ const editorFontColorValueThemeVariants = cva(`
367
+ flex flex-col items-center justify-center
368
+ gap-0.5 ps-1.25 text-sm
369
+ `);
370
+ const editorFontFamilyDropdownListThemeVariants = cva(`
371
+ w-[12em]
372
+ `);
373
+ const editorFontHighlightPreviewThemeVariants = cva(`
374
+ w-full flex h-[2px]
375
+ `);
376
+ const editorFontHighlightValueThemeVariants = cva(`
377
+ flex flex-col items-center justify-center
378
+ gap-0.5 ps-1.25 text-sm
379
+ `);
380
+ const editorFontSizeDropdownListThemeVariants = cva(`
381
+ w-[8em]
382
+ `);
383
+ const editorHeadingsDropdownListThemeVariants = cva(`
384
+ w-[14em]
385
+ `);
386
+ const editorImageInserterActionsThemeVariants = cva(`
387
+ flex justify-end gap-1 px-2 py-1
388
+ bg-surface-muted
389
+ border-t border-t-border-subtle
390
+ `);
391
+ const editorImageInserterFormThemeVariants = cva(`
392
+ flex flex-col gap-1.5 pt-2
393
+ `);
394
+ const editorImageInserterRowLabelThemeVariants = cva(`
395
+ mb-0.5 ps-0.5 text-sm font-semibold
396
+ `);
397
+ const editorImageInserterRowThemeVariants = cva(`
398
+ flex flex-col justify-center px-2
399
+ `);
400
+ const editorPlaceholderThemeVariants = cva(`
401
+ pointer-events-none absolute top-0 start-0 px-1.5 py-2.5
402
+ text-muted-foreground select-none
403
+ `);
404
+ const editorTableCreatorThemeVariants = cva(`
405
+ grid grid-cols-8 gap-0.5 p-1
406
+ `);
407
+ const editorTableCreatorCellThemeVariants = cva(`
408
+ flex h-6 w-6 p-0 cursor-pointer
409
+ bg-surface-muted border border-input-border
410
+ data-[highlighted]:bg-primary data-[highlighted]:border-primary
411
+ focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-focus-indicator
412
+ `);
413
+ const editorToolbarThemeVariants = cva(`
414
+ flex flex-wrap items-center justify-start gap-1 p-1
415
+ bg-surface-muted text-foreground border-b border-b-border-subtle
416
+ `, {
417
+ variants: { disabled: {
418
+ true: "opacity-50",
419
+ false: ""
420
+ } },
421
+ defaultVariants: { disabled: false }
422
+ });
423
+ const EDITOR_IMAGE_UPLOAD_CLASSES = "relative flex w-fit max-w-full flex-col gap-1";
424
+ const EDITOR_IMAGE_UPLOAD_PREVIEW_CLASSES = "m-0! max-h-40 max-w-full opacity-60";
425
+ const EDITOR_IMAGE_UPLOAD_TRACK_CLASSES = "block h-1 w-full overflow-hidden rounded-full bg-surface-muted forced-colors:border forced-colors:border-[CanvasText]";
426
+ const EDITOR_IMAGE_UPLOAD_BAR_CLASSES = "block h-full bg-primary forced-colors:bg-[Highlight]";
427
+ const EDITOR_FOOTER_CLASSES = "not-prose flex flex-wrap justify-end gap-x-3 border-t border-border-subtle px-2 py-1 text-xs text-muted-foreground";
428
+ const EDITOR_COUNT_OVER_CLASSES = "font-medium text-error";
429
+ const EDITOR_MENTION_LIST_CLASSES = `
430
+ not-prose flex max-h-60 min-w-48 flex-col overflow-auto
431
+ rounded-md border border-border py-1 text-sm text-foreground shadow-(--shadow-overlay)
432
+ [scrollbar-color:var(--color-scrollbar-thumb)_var(--color-scrollbar-track)] [scrollbar-width:thin]
433
+ ${themeOverlaySurfaceClasses}
434
+ `;
435
+ const EDITOR_MENTION_STATUS_CLASSES = "px-3 py-1 text-muted-foreground";
436
+ const editorMentionOptionThemeVariants = cva("flex cursor-pointer select-none items-center px-3 py-1 text-foreground hover:bg-hover", {
437
+ variants: { highlighted: {
438
+ true: "bg-hover inset-ring-2 inset-ring-focus-indicator forced-colors:bg-[Highlight] forced-colors:text-[HighlightText]",
439
+ false: ""
440
+ } },
441
+ defaultVariants: { highlighted: false }
442
+ });
103
443
  const ExtendedImage = Image.extend({
104
444
  name: "extendedImage",
105
445
  addAttributes() {
@@ -255,6 +595,122 @@ const Indent = Extension.create({
255
595
  };
256
596
  }
257
597
  });
598
+ const MENTION_KEY = new PluginKey("monaMention");
599
+ const QUERY_PATTERN = /(?:^|[\s(])@([^\s@]{0,50})$/u;
600
+ function findQuery(state) {
601
+ const { selection } = state;
602
+ if (!selection.empty) return null;
603
+ const $from = selection.$from;
604
+ if (!$from.parent.isTextblock || $from.parent.type.spec.code) return null;
605
+ const code = state.schema.marks["code"];
606
+ if (code && $from.marks().some((mark) => mark.type === code)) return null;
607
+ const start = Math.max(0, $from.parentOffset - 60);
608
+ const textBefore = $from.parent.textBetween(start, $from.parentOffset, void 0, "");
609
+ const match = QUERY_PATTERN.exec(textBefore);
610
+ if (!match) return null;
611
+ const query = match[1] ?? "";
612
+ return {
613
+ from: $from.pos - query.length - 1,
614
+ query,
615
+ to: $from.pos
616
+ };
617
+ }
618
+ function sameQuery(a, b) {
619
+ return a?.from === b?.from && a?.query === b?.query && a?.to === b?.to;
620
+ }
621
+ const Mention = Node.create({
622
+ name: "mention",
623
+ group: "inline",
624
+ inline: true,
625
+ atom: true,
626
+ selectable: false,
627
+ addOptions() {
628
+ return {
629
+ enabled: () => false,
630
+ onKeyDown: () => false,
631
+ onQuery: () => void 0
632
+ };
633
+ },
634
+ addAttributes() {
635
+ return {
636
+ id: {
637
+ default: null,
638
+ parseHTML: (element) => element.getAttribute("data-id"),
639
+ renderHTML: (attributes) => attributes["id"] ? { "data-id": attributes["id"] } : {}
640
+ },
641
+ label: {
642
+ default: null,
643
+ parseHTML: (element) => element.getAttribute("data-label") ?? element.textContent?.replace(/^@/u, "") ?? null,
644
+ renderHTML: (attributes) => attributes["label"] ? { "data-label": attributes["label"] } : {}
645
+ }
646
+ };
647
+ },
648
+ parseHTML() {
649
+ return [{ tag: "span[data-type=\"mention\"]" }];
650
+ },
651
+ renderHTML({ HTMLAttributes: attributes, node }) {
652
+ const label = String(node.attrs["label"] ?? node.attrs["id"] ?? "");
653
+ return [
654
+ "span",
655
+ mergeAttributes({ "data-type": "mention" }, attributes),
656
+ `@${label}`
657
+ ];
658
+ },
659
+ renderText({ node }) {
660
+ return `@${String(node.attrs["label"] ?? node.attrs["id"] ?? "")}`;
661
+ },
662
+ addProseMirrorPlugins() {
663
+ const options = this.options;
664
+ return [new Plugin({
665
+ key: MENTION_KEY,
666
+ state: {
667
+ init: () => ({
668
+ dismissed: null,
669
+ query: null
670
+ }),
671
+ apply: (tr, previous, _oldState, newState) => {
672
+ const dismissed = tr.getMeta(MENTION_KEY)?.dismiss ?? (previous.dismissed === null ? null : tr.mapping.map(previous.dismissed));
673
+ const query = options.enabled() ? findQuery(newState) : null;
674
+ if (query === null) return {
675
+ dismissed: null,
676
+ query: null
677
+ };
678
+ return {
679
+ dismissed,
680
+ query: query.from === dismissed ? null : query
681
+ };
682
+ }
683
+ },
684
+ view: (view) => {
685
+ let current = null;
686
+ return {
687
+ update: (updated) => {
688
+ const next = MENTION_KEY.getState(updated.state)?.query ?? null;
689
+ if (!sameQuery(current, next)) {
690
+ current = next;
691
+ options.onQuery(updated, next);
692
+ }
693
+ },
694
+ destroy: () => {
695
+ if (current !== null) {
696
+ current = null;
697
+ options.onQuery(view, null);
698
+ }
699
+ }
700
+ };
701
+ },
702
+ props: { handleKeyDown: (view, event) => {
703
+ const query = MENTION_KEY.getState(view.state)?.query;
704
+ if (!query || event.isComposing) return false;
705
+ if (event.key === "Escape") {
706
+ view.dispatch(view.state.tr.setMeta(MENTION_KEY, { dismiss: query.from }));
707
+ return true;
708
+ }
709
+ return options.onKeyDown(event);
710
+ } }
711
+ })];
712
+ }
713
+ });
258
714
  const DEFAULT_FONTS = [
259
715
  "Arial",
260
716
  "Comic Sans MS",
@@ -302,6 +758,7 @@ const DEFAULT_SETTINGS = {
302
758
  italic: true,
303
759
  link: true,
304
760
  list: true,
761
+ mention: true,
305
762
  strikethrough: true,
306
763
  subscript: true,
307
764
  superscript: true,
@@ -335,6 +792,8 @@ var EditorService = class EditorService {
335
792
  this.settings = signal({}, ...ngDevMode ? [{ debugName: "settings" }] : /* istanbul ignore next */ []);
336
793
  this.state = this.#state.asReadonly();
337
794
  this.update$ = new Subject();
795
+ this.imageUploader = null;
796
+ this.mentionController = null;
338
797
  }
339
798
  #ready;
340
799
  #state;
@@ -410,7 +869,18 @@ var EditorService = class EditorService {
410
869
  if (settings.fontFamily) extensions.add(FontFamily);
411
870
  if (settings.fontHighlight) extensions.add(Highlight.configure({ multicolor: true }));
412
871
  if (settings.fontSize) extensions.add(FontSize);
413
- if (settings.image) extensions.add(ExtendedImage);
872
+ if (settings.image) {
873
+ extensions.add(ExtendedImage);
874
+ extensions.add(ImageUpload.configure({
875
+ accepted: (files) => this.imageUploader?.accepted(files) ?? [],
876
+ upload: (view, files, position) => this.imageUploader?.upload(view, files, position)
877
+ }));
878
+ }
879
+ if (settings.mention) extensions.add(Mention.configure({
880
+ enabled: () => this.mentionController?.enabled() ?? false,
881
+ onKeyDown: (event) => this.mentionController?.onKeyDown(event) ?? false,
882
+ onQuery: (view, query) => this.mentionController?.onQuery(view, query)
883
+ }));
414
884
  if (settings.indent) extensions.add(Indent);
415
885
  if (settings.subscript) extensions.add(Subscript);
416
886
  if (settings.superscript) extensions.add(Superscript);
@@ -477,174 +947,515 @@ i0.ɵɵngDeclareClassMetadata({
477
947
  type: EditorService,
478
948
  decorators: [{ type: Injectable }]
479
949
  });
480
- const editorBaseThemeVariants = cva(`
481
- flex flex-col
482
- bg-surface text-foreground
483
- border border-border
484
- transition-[border-color,box-shadow] duration-150 ease-in
485
- focus-within:border-focus-indicator
486
- focus-within:ring-2 focus-within:ring-focus-indicator/35
487
-
488
- data-[disabled='true']:cursor-not-allowed
489
- data-[disabled='true']:border-disabled-border
490
- data-[disabled='true']:text-disabled-foreground
491
- data-[invalid='true']:border-error
492
- data-[invalid='true']:ring-2 data-[invalid='true']:ring-error/35
493
- data-[invalid='true']:focus-within:border-error
494
- data-[invalid='true']:focus-within:ring-error/35
495
-
496
- prose prose-neutral max-w-none
497
- prose-headings:text-foreground prose-headings:font-bold
498
- prose-headings:mt-1 prose-headings:mb-1
499
- prose-p:text-foreground prose-p:my-1
500
- prose-strong:text-inherit
501
- [&_span[style*=color]_mark]:text-inherit
502
- prose-a:text-[var(--mona-primary-text-color,var(--color-primary))]
503
-
504
- [&_ol]:ps-8 [&_ul]:ps-8
505
-
506
- [&_blockquote]:border-s-4
507
- [&_blockquote]:border-s-solid
508
- [&_blockquote]:border-s-border-control-hover
509
- [&_blockquote]:px-4 [&_blockquote]:py-2
510
- [&_blockquote]:ms-4
511
- [&_blockquote]:bg-surface-muted
512
-
513
- [&_hr]:my-1 [&_hr]:bg-border-subtle
514
- [&_hr]:border [&_hr]:border-border-subtle
515
-
516
- [&_ul[data-type='taskList']_li]:flex
517
- [&_ul[data-type='taskList']_li]:py-0.5
518
- [&_ul[data-type='taskList']_li>label]:grow-0
519
- [&_ul[data-type='taskList']_li>label]:shrink-0
520
- [&_ul[data-type='taskList']_li>label]:basis-auto
521
- [&_ul[data-type='taskList']_li>div]:grow-1
522
- [&_ul[data-type='taskList']_li>div]:shrink-1
523
- [&_ul[data-type='taskList']_li>div]:basis-auto
524
- [&_ul[data-type='taskList']_input[type='checkbox']]:me-2!
525
-
526
- [&_img]:max-w-full
527
- [&_img]:h-auto
528
- [&_img.ProseMirror-selectednode]:outline-3
529
- [&_img.ProseMirror-selectednode]:outline-focus-indicator
530
-
531
- [&_pre]:bg-surface-muted
532
- [&_pre]:border [&_pre]:border-border-subtle
533
- [&_pre]:whitespace-pre-wrap
534
- [&_pre]:font-mono
535
- [&_pre_code]:p-0
536
- [&_pre_code]:text-sm
537
- [&_pre_code]:bg-none
538
-
539
- [&.ProseMirror-gapcursor]:after:border-foreground!
540
-
541
- [&_table]:border-collapse
542
- [&_table]:m-0
543
- [&_table]:overflow-hidden
544
- [&_table]:table-fixed
545
- [&_table]:w-full
546
- [&_table_td]:border [&_table_td]:border-border-subtle
547
- [&_table_td]:p-2 [&_table_td]:align-top [&_table_td]:relative
548
- [&_table_th]:border [&_table_th]:border-border-subtle
549
- [&_table_th]:p-2 [&_table_th]:align-top [&_table_th]:relative
550
-
551
- [&_table_th]:bg-surface-muted [&_table_th]:text-foreground [&_table_th]:font-bold
552
-
553
- [&_.selectedCell]:after:content-[''] [&_.selectedCell]:after:absolute [&_.selectedCell]:after:inset-0
554
- [&_.selectedCell]:after:pointer-events-none
555
- [&_.selectedCell]:after:z-2
556
- [&_.selectedCell]:after:bg-active/70
557
-
558
- [&_.column-resize-handle]:absolute
559
- [&_.column-resize-handle]:bg-focus-indicator
560
- [&_.column-resize-handle]:w-1
561
- [&_.column-resize-handle]:pointer-events-none
562
- [&_.column-resize-handle]:top-0
563
- [&_.column-resize-handle]:-bottom-0.5
564
- [&_.column-resize-handle]:-end-0.5
565
-
566
- [&_.ProseMirror.resize-cursor]:cursor-ew-resize
567
-
568
- `);
569
- const editorContainerThemeVariants = cva(`
570
- h-full w-full bg-surface
571
- [&>.ProseMirror]:p-1.5
572
- [&>.ProseMirror]:text-foreground
573
- [&>.ProseMirror]:border-none
574
- [&>.ProseMirror]:outline-none [&>.ProseMirror:focus-visible]:outline-hidden
575
- [&>.ProseMirror]:w-full
576
- [&>.ProseMirror]:h-full
577
- [&>.ProseMirror]:overflow-auto
578
- [&>.ProseMirror]:resize-none
579
- [&>.ProseMirror]:[scrollbar-color:var(--color-scrollbar-thumb)_var(--color-scrollbar-track)]
580
- [&>.ProseMirror]:[scrollbar-width:thin]
581
- `, {
582
- variants: { disabled: {
583
- true: "bg-disabled-background [&>.ProseMirror]:text-disabled-foreground",
584
- false: ""
585
- } },
586
- defaultVariants: { disabled: false }
950
+ var EditorImageUploadService = class EditorImageUploadService {
951
+ #announcer;
952
+ #document;
953
+ #editorService;
954
+ #i18n;
955
+ #messages;
956
+ #uploads;
957
+ #nextId;
958
+ constructor() {
959
+ this.#announcer = injectLiveAnnouncer();
960
+ this.#document = inject(DOCUMENT$1);
961
+ this.#editorService = inject(EditorService);
962
+ this.#i18n = inject(MonaI18nService);
963
+ this.#messages = this.#i18n.componentMessages("editor", EDITOR_DEFAULT_MESSAGES);
964
+ this.#uploads = /* @__PURE__ */ new Map();
965
+ this.#nextId = 0;
966
+ this.options = signal({
967
+ accept: "image/*",
968
+ handler: null,
969
+ maxFileSize: null
970
+ }, ...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
971
+ this.#editorService.imageUploader = this;
972
+ inject(DestroyRef).onDestroy(() => {
973
+ for (const abort of [...this.#uploads.values()]) abort();
974
+ this.#uploads.clear();
975
+ });
976
+ }
977
+ accepted(files) {
978
+ const { accept, handler } = untracked(this.options);
979
+ if (handler == null) return [];
980
+ const tokens = parseAccept(accept);
981
+ return files.filter((file) => matchesAccept(file, tokens));
982
+ }
983
+ upload(view, files, position) {
984
+ for (const file of files) this.#upload(view, file, position);
985
+ }
986
+ #announce(message) {
987
+ this.#announcer.announce(message, "polite");
988
+ }
989
+ #placeholder(previewUrl, label) {
990
+ const element = this.#document.createElement("span");
991
+ element.className = EDITOR_IMAGE_UPLOAD_CLASSES;
992
+ element.contentEditable = "false";
993
+ element.setAttribute("role", "img");
994
+ element.setAttribute("aria-label", label);
995
+ const preview = this.#document.createElement("img");
996
+ preview.className = EDITOR_IMAGE_UPLOAD_PREVIEW_CLASSES;
997
+ preview.alt = "";
998
+ preview.src = previewUrl;
999
+ const track = this.#document.createElement("span");
1000
+ track.className = EDITOR_IMAGE_UPLOAD_TRACK_CLASSES;
1001
+ const bar = this.#document.createElement("span");
1002
+ bar.className = EDITOR_IMAGE_UPLOAD_BAR_CLASSES;
1003
+ bar.style.inlineSize = "0%";
1004
+ track.append(bar);
1005
+ element.append(preview, track);
1006
+ return {
1007
+ bar,
1008
+ element
1009
+ };
1010
+ }
1011
+ #upload(view, file, position) {
1012
+ const { handler, maxFileSize } = untracked(this.options);
1013
+ if (handler == null) return;
1014
+ const messages = untracked(this.#messages);
1015
+ if (maxFileSize != null && file.size > maxFileSize) {
1016
+ const size = formatFileSize(maxFileSize, untracked(this.#i18n.localeId));
1017
+ this.#announce(messages.imageTooLarge(file.name, size));
1018
+ return;
1019
+ }
1020
+ const id = `mona-image-upload-${this.#nextId++}`;
1021
+ const previewUrl = URL.createObjectURL(file);
1022
+ const { bar, element } = this.#placeholder(previewUrl, messages.imageUploading(file.name));
1023
+ addImagePlaceholder(view, id, position, element);
1024
+ this.#announce(messages.imageUploading(file.name));
1025
+ const finish = () => {
1026
+ this.#uploads.delete(id);
1027
+ URL.revokeObjectURL(previewUrl);
1028
+ };
1029
+ const fail = () => {
1030
+ if (!view.isDestroyed) removeImagePlaceholder(view, id);
1031
+ this.#announce(untracked(this.#messages).imageUploadFailed(file.name));
1032
+ };
1033
+ let abort = null;
1034
+ this.#uploads.set(id, () => {
1035
+ abort?.();
1036
+ finish();
1037
+ });
1038
+ abort = runUpload(handler, file, {
1039
+ failure: () => {
1040
+ finish();
1041
+ fail();
1042
+ },
1043
+ progress: (fraction) => {
1044
+ bar.style.inlineSize = `${Math.round(fraction * 100)}%`;
1045
+ },
1046
+ success: (response) => {
1047
+ finish();
1048
+ if (typeof response !== "string" || response === "") {
1049
+ if (isDevMode()) console.warn("[Mona Editor] imageUpload should return the image's address as a string, but it returned:", response);
1050
+ fail();
1051
+ return;
1052
+ }
1053
+ this.#insert(view, id, response, file.name);
1054
+ }
1055
+ });
1056
+ }
1057
+ #insert(view, id, src, name) {
1058
+ if (view.isDestroyed || !this.#editorService.ready() || this.#editorService.editor.view !== view) return;
1059
+ const position = findImagePlaceholder(view.state, id);
1060
+ if (position === null) return;
1061
+ const removal = imagePlaceholderRemoval(id);
1062
+ this.#editorService.editor.chain().command(({ tr }) => {
1063
+ tr.setMeta(removal.key, removal.value);
1064
+ return true;
1065
+ }).insertContentAt(position, {
1066
+ attrs: { src },
1067
+ type: "extendedImage"
1068
+ }, { updateSelection: false }).run();
1069
+ this.#announce(untracked(this.#messages).imageInserted(name));
1070
+ }
1071
+ static {
1072
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1073
+ minVersion: "12.0.0",
1074
+ version: "22.2.6",
1075
+ ngImport: i0,
1076
+ type: EditorImageUploadService,
1077
+ deps: [],
1078
+ target: i0.ɵɵFactoryTarget.Injectable
1079
+ });
1080
+ }
1081
+ static {
1082
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
1083
+ minVersion: "12.0.0",
1084
+ version: "22.2.6",
1085
+ ngImport: i0,
1086
+ type: EditorImageUploadService
1087
+ });
1088
+ }
1089
+ };
1090
+ i0.ɵɵngDeclareClassMetadata({
1091
+ minVersion: "12.0.0",
1092
+ version: "22.2.6",
1093
+ ngImport: i0,
1094
+ type: EditorImageUploadService,
1095
+ decorators: [{ type: Injectable }],
1096
+ ctorParameters: () => []
587
1097
  });
588
- const editorFontColorPreviewThemeVariants = cva(`
589
- w-full flex h-[2px]
590
- `);
591
- const editorFontColorValueThemeVariants = cva(`
592
- flex flex-col items-center justify-center
593
- gap-0.5 ps-1.25 text-sm
594
- `);
595
- const editorFontFamilyDropdownListThemeVariants = cva(`
596
- w-[12em]
597
- `);
598
- const editorFontHighlightPreviewThemeVariants = cva(`
599
- w-full flex h-[2px]
600
- `);
601
- const editorFontHighlightValueThemeVariants = cva(`
602
- flex flex-col items-center justify-center
603
- gap-0.5 ps-1.25 text-sm
604
- `);
605
- const editorFontSizeDropdownListThemeVariants = cva(`
606
- w-[8em]
607
- `);
608
- const editorHeadingsDropdownListThemeVariants = cva(`
609
- w-[14em]
610
- `);
611
- const editorImageInserterActionsThemeVariants = cva(`
612
- flex justify-end gap-1 px-2 py-1
613
- bg-surface-muted
614
- border-t border-t-border-subtle
615
- `);
616
- const editorImageInserterFormThemeVariants = cva(`
617
- flex flex-col gap-1.5 pt-2
618
- `);
619
- const editorImageInserterRowLabelThemeVariants = cva(`
620
- mb-0.5 ps-0.5 text-sm font-semibold
621
- `);
622
- const editorImageInserterRowThemeVariants = cva(`
623
- flex flex-col justify-center px-2
624
- `);
625
- const editorPlaceholderThemeVariants = cva(`
626
- pointer-events-none absolute top-0 start-0 px-1.5 py-2.5
627
- text-muted-foreground select-none
628
- `);
629
- const editorTableCreatorThemeVariants = cva(`
630
- grid grid-cols-8 gap-0.5 p-1
631
- `);
632
- const editorTableCreatorCellThemeVariants = cva(`
633
- flex h-6 w-6 p-0 cursor-pointer
634
- bg-surface-muted border border-input-border
635
- data-[highlighted]:bg-primary data-[highlighted]:border-primary
636
- focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-focus-indicator
637
- `);
638
- const editorToolbarThemeVariants = cva(`
639
- flex flex-wrap items-center justify-start gap-1 p-1
640
- bg-surface-muted text-foreground border-b border-b-border-subtle
641
- `, {
642
- variants: { disabled: {
643
- true: "opacity-50",
644
- false: ""
645
- } },
646
- defaultVariants: { disabled: false }
1098
+ var EditorMentionListComponent = class EditorMentionListComponent {
1099
+ constructor() {
1100
+ this.#i18n = inject(MonaI18nService);
1101
+ this.listClass = EDITOR_MENTION_LIST_CLASSES;
1102
+ this.mention = inject(PopupDataInjectionToken);
1103
+ this.messages = this.#i18n.componentMessages("editor", EDITOR_DEFAULT_MESSAGES);
1104
+ this.options = computed(() => {
1105
+ const highlighted = this.mention.highlightedIndex();
1106
+ return this.mention.items().map((item, index) => ({
1107
+ class: editorMentionOptionThemeVariants({ highlighted: index === highlighted }),
1108
+ highlighted: index === highlighted,
1109
+ id: this.mention.optionId(index),
1110
+ index,
1111
+ label: item.label
1112
+ }));
1113
+ }, ...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
1114
+ this.statusClass = EDITOR_MENTION_STATUS_CLASSES;
1115
+ }
1116
+ #i18n;
1117
+ onOptionClick(index) {
1118
+ this.mention.select(index);
1119
+ }
1120
+ onOptionPointerDown(event) {
1121
+ event.preventDefault();
1122
+ }
1123
+ onOptionPointerEnter(index) {
1124
+ this.mention.highlightedIndex.set(index);
1125
+ }
1126
+ static {
1127
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1128
+ minVersion: "12.0.0",
1129
+ version: "22.2.6",
1130
+ ngImport: i0,
1131
+ type: EditorMentionListComponent,
1132
+ deps: [],
1133
+ target: i0.ɵɵFactoryTarget.Component
1134
+ });
1135
+ }
1136
+ static {
1137
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
1138
+ minVersion: "17.0.0",
1139
+ version: "22.2.6",
1140
+ type: EditorMentionListComponent,
1141
+ isStandalone: true,
1142
+ selector: "mona-editor-mention-list",
1143
+ ngImport: i0,
1144
+ template: "<div [class]=\"listClass\">\n @if (options().length > 0) {\n <ul\n role=\"listbox\"\n class=\"m-0 list-none p-0\"\n [id]=\"mention.listId\"\n [attr.aria-label]=\"messages().mentionSuggestions\">\n @for (option of options(); track option.id) {\n <li\n role=\"option\"\n [id]=\"option.id\"\n [class]=\"option.class\"\n [attr.aria-selected]=\"option.highlighted\"\n (click)=\"onOptionClick(option.index)\"\n (pointerdown)=\"onOptionPointerDown($event)\"\n (pointerenter)=\"onOptionPointerEnter(option.index)\">\n {{ option.label }}\n </li>\n }\n </ul>\n } @else if (mention.loading()) {\n <div [class]=\"statusClass\">{{ messages().mentionSearching }}</div>\n } @else {\n <div [class]=\"statusClass\">{{ messages().mentionNoResults }}</div>\n }\n</div>\n"
1145
+ });
1146
+ }
1147
+ };
1148
+ i0.ɵɵngDeclareClassMetadata({
1149
+ minVersion: "12.0.0",
1150
+ version: "22.2.6",
1151
+ ngImport: i0,
1152
+ type: EditorMentionListComponent,
1153
+ decorators: [{
1154
+ type: Component,
1155
+ args: [{
1156
+ selector: "mona-editor-mention-list",
1157
+ template: "<div [class]=\"listClass\">\n @if (options().length > 0) {\n <ul\n role=\"listbox\"\n class=\"m-0 list-none p-0\"\n [id]=\"mention.listId\"\n [attr.aria-label]=\"messages().mentionSuggestions\">\n @for (option of options(); track option.id) {\n <li\n role=\"option\"\n [id]=\"option.id\"\n [class]=\"option.class\"\n [attr.aria-selected]=\"option.highlighted\"\n (click)=\"onOptionClick(option.index)\"\n (pointerdown)=\"onOptionPointerDown($event)\"\n (pointerenter)=\"onOptionPointerEnter(option.index)\">\n {{ option.label }}\n </li>\n }\n </ul>\n } @else if (mention.loading()) {\n <div [class]=\"statusClass\">{{ messages().mentionSearching }}</div>\n } @else {\n <div [class]=\"statusClass\">{{ messages().mentionNoResults }}</div>\n }\n</div>\n"
1158
+ }]
1159
+ }]
1160
+ });
1161
+ function toMentions(result) {
1162
+ if (isObservable(result)) return result.pipe(map((mentions) => Array.from(mentions)));
1163
+ if (typeof result.then === "function") return from(result).pipe(map((mentions) => Array.from(mentions)));
1164
+ return of(Array.from(result));
1165
+ }
1166
+ var EditorMentionService = class EditorMentionService {
1167
+ #announcer;
1168
+ #destroyRef;
1169
+ #document;
1170
+ #editorService;
1171
+ #i18n;
1172
+ #injector;
1173
+ #messages;
1174
+ #popupService;
1175
+ #searches;
1176
+ #popupRef;
1177
+ #query;
1178
+ #view;
1179
+ constructor() {
1180
+ this.#announcer = injectLiveAnnouncer();
1181
+ this.#destroyRef = inject(DestroyRef);
1182
+ this.#document = inject(DOCUMENT$1);
1183
+ this.#editorService = inject(EditorService);
1184
+ this.#i18n = inject(MonaI18nService);
1185
+ this.#injector = inject(Injector);
1186
+ this.#messages = this.#i18n.componentMessages("editor", EDITOR_DEFAULT_MESSAGES);
1187
+ this.#popupService = inject(PopupService);
1188
+ this.#searches = new Subject();
1189
+ this.#popupRef = null;
1190
+ this.#query = null;
1191
+ this.#view = null;
1192
+ this.activeDescendant = computed(() => this.open() && this.items().length > 0 ? this.optionId(this.highlightedIndex()) : null, ...ngDevMode ? [{ debugName: "activeDescendant" }] : /* istanbul ignore next */ []);
1193
+ this.highlightedIndex = signal(0, ...ngDevMode ? [{ debugName: "highlightedIndex" }] : /* istanbul ignore next */ []);
1194
+ this.items = signal([], ...ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []);
1195
+ this.listId = createElementControlId();
1196
+ this.loading = signal(false, ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
1197
+ this.open = signal(false, ...ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []);
1198
+ this.search = signal(null, ...ngDevMode ? [{ debugName: "search" }] : /* istanbul ignore next */ []);
1199
+ this.#editorService.mentionController = this;
1200
+ this.#searches.pipe(switchMap((query) => {
1201
+ const search = untracked(this.search);
1202
+ if (query === null || search === null) return of(null);
1203
+ this.loading.set(true);
1204
+ let result;
1205
+ try {
1206
+ result = search(query);
1207
+ } catch {
1208
+ return of([]);
1209
+ }
1210
+ return toMentions(result).pipe(catchError(() => of([])));
1211
+ }), takeUntilDestroyed(this.#destroyRef)).subscribe((items) => {
1212
+ this.loading.set(false);
1213
+ if (items === null) return;
1214
+ this.items.set(items);
1215
+ this.highlightedIndex.set(0);
1216
+ const messages = untracked(this.#messages);
1217
+ this.#announce(items.length > 0 ? messages.mentionResults(items.length) : messages.mentionNoResults);
1218
+ });
1219
+ this.#editorService.blur$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => this.#dismiss());
1220
+ fromEvent(this.#document, "scroll", {
1221
+ capture: true,
1222
+ passive: true
1223
+ }).pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => this.#reposition());
1224
+ this.#destroyRef.onDestroy(() => this.#close());
1225
+ }
1226
+ enabled() {
1227
+ return untracked(this.search) !== null;
1228
+ }
1229
+ highlight(index) {
1230
+ const count = this.items().length;
1231
+ if (count === 0) return;
1232
+ this.highlightedIndex.set((index % count + count) % count);
1233
+ this.#document.getElementById(this.optionId(this.highlightedIndex()))?.scrollIntoView({ block: "nearest" });
1234
+ }
1235
+ onKeyDown(event) {
1236
+ if (!this.open() || this.items().length === 0 || event.altKey || event.ctrlKey || event.metaKey) return false;
1237
+ switch (event.key) {
1238
+ case "ArrowDown":
1239
+ this.highlight(this.highlightedIndex() + 1);
1240
+ return true;
1241
+ case "ArrowUp":
1242
+ this.highlight(this.highlightedIndex() - 1);
1243
+ return true;
1244
+ case "Enter":
1245
+ case "Tab":
1246
+ if (event.shiftKey) return false;
1247
+ this.select(this.highlightedIndex());
1248
+ return true;
1249
+ default: return false;
1250
+ }
1251
+ }
1252
+ onQuery(view, query) {
1253
+ const previous = this.#query;
1254
+ this.#query = query;
1255
+ this.#view = query ? view : null;
1256
+ if (query === null) {
1257
+ this.#searches.next(null);
1258
+ this.#close();
1259
+ return;
1260
+ }
1261
+ if (previous?.query !== query.query || previous.from !== query.from) this.#searches.next(query.query);
1262
+ if (this.#popupRef === null) this.#openPopup(view, query);
1263
+ else this.#reposition();
1264
+ }
1265
+ optionId(index) {
1266
+ return `${this.listId}-${index}`;
1267
+ }
1268
+ select(index) {
1269
+ const item = this.items()[index];
1270
+ const query = this.#query;
1271
+ const view = this.#view;
1272
+ if (!item || !query || !view || view.isDestroyed || this.#editorService.editor.view !== view) return;
1273
+ this.#editorService.editor.chain().focus().insertContentAt({
1274
+ from: query.from,
1275
+ to: query.to
1276
+ }, [{
1277
+ attrs: {
1278
+ id: item.id,
1279
+ label: item.label
1280
+ },
1281
+ type: "mention"
1282
+ }, {
1283
+ text: " ",
1284
+ type: "text"
1285
+ }]).run();
1286
+ }
1287
+ #anchor(view, position) {
1288
+ const coords = view.coordsAtPos(position);
1289
+ return {
1290
+ height: coords.bottom - coords.top,
1291
+ width: 1,
1292
+ x: coords.left,
1293
+ y: coords.top
1294
+ };
1295
+ }
1296
+ #announce(message) {
1297
+ this.#announcer.announce(message, "polite");
1298
+ }
1299
+ #close() {
1300
+ const popupRef = this.#popupRef;
1301
+ this.#popupRef = null;
1302
+ this.open.set(false);
1303
+ this.items.set([]);
1304
+ this.loading.set(false);
1305
+ popupRef?.close();
1306
+ }
1307
+ #dismiss() {
1308
+ const view = this.#view;
1309
+ const query = this.#query;
1310
+ if (view && query && !view.isDestroyed) view.dispatch(view.state.tr.setMeta(MENTION_KEY, { dismiss: query.from }));
1311
+ }
1312
+ #openPopup(view, query) {
1313
+ const popupRef = this.#popupService.create({
1314
+ anchor: this.#anchor(view, query.from),
1315
+ anchorConnectionPoint: "bottomleft",
1316
+ closeOnEscape: false,
1317
+ closeOnOutsideClick: false,
1318
+ content: EditorMentionListComponent,
1319
+ data: this,
1320
+ injector: this.#injector,
1321
+ offset: {
1322
+ horizontal: 0,
1323
+ vertical: 4
1324
+ },
1325
+ popupConnectionPoint: "topleft",
1326
+ restoreFocus: false,
1327
+ withPush: true,
1328
+ withScrollTracking: false
1329
+ });
1330
+ this.#popupRef = popupRef;
1331
+ this.open.set(true);
1332
+ popupRef.closed.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
1333
+ if (this.#popupRef === popupRef) {
1334
+ this.#popupRef = null;
1335
+ this.open.set(false);
1336
+ }
1337
+ });
1338
+ }
1339
+ #reposition() {
1340
+ const popupRef = this.#popupRef;
1341
+ const view = this.#view;
1342
+ const query = this.#query;
1343
+ if (!popupRef || !view || !query || view.isDestroyed) return;
1344
+ popupRef.overlayRef.getConfig().positionStrategy?.setOrigin(this.#anchor(view, query.from));
1345
+ popupRef.overlayRef.updatePosition();
1346
+ }
1347
+ static {
1348
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1349
+ minVersion: "12.0.0",
1350
+ version: "22.2.6",
1351
+ ngImport: i0,
1352
+ type: EditorMentionService,
1353
+ deps: [],
1354
+ target: i0.ɵɵFactoryTarget.Injectable
1355
+ });
1356
+ }
1357
+ static {
1358
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
1359
+ minVersion: "12.0.0",
1360
+ version: "22.2.6",
1361
+ ngImport: i0,
1362
+ type: EditorMentionService
1363
+ });
1364
+ }
1365
+ };
1366
+ i0.ɵɵngDeclareClassMetadata({
1367
+ minVersion: "12.0.0",
1368
+ version: "22.2.6",
1369
+ ngImport: i0,
1370
+ type: EditorMentionService,
1371
+ decorators: [{ type: Injectable }],
1372
+ ctorParameters: () => []
647
1373
  });
1374
+ const BLOCK_ELEMENTS = /* @__PURE__ */ new Set([
1375
+ "ADDRESS",
1376
+ "ARTICLE",
1377
+ "ASIDE",
1378
+ "BLOCKQUOTE",
1379
+ "BR",
1380
+ "DD",
1381
+ "DIV",
1382
+ "DL",
1383
+ "DT",
1384
+ "FIGCAPTION",
1385
+ "FIGURE",
1386
+ "FOOTER",
1387
+ "H1",
1388
+ "H2",
1389
+ "H3",
1390
+ "H4",
1391
+ "H5",
1392
+ "H6",
1393
+ "HEADER",
1394
+ "HR",
1395
+ "LI",
1396
+ "OL",
1397
+ "P",
1398
+ "PRE",
1399
+ "SECTION",
1400
+ "TABLE",
1401
+ "TD",
1402
+ "TH",
1403
+ "TR",
1404
+ "UL"
1405
+ ]);
1406
+ const segmenters = /* @__PURE__ */ new Map();
1407
+ function createSegmenter(locale, granularity) {
1408
+ try {
1409
+ return typeof Intl.Segmenter === "function" ? new Intl.Segmenter(locale, { granularity }) : null;
1410
+ } catch {
1411
+ return null;
1412
+ }
1413
+ }
1414
+ function segmenter(locale, granularity) {
1415
+ const key = `${locale ?? ""}|${granularity}`;
1416
+ if (!segmenters.has(key)) segmenters.set(key, createSegmenter(locale, granularity));
1417
+ return segmenters.get(key) ?? null;
1418
+ }
1419
+ function countText(text, unit, locale) {
1420
+ if (unit === "characters") {
1421
+ const graphemes = segmenter(locale, "grapheme");
1422
+ if (!graphemes) return Array.from(text).length;
1423
+ let count = 0;
1424
+ for (const _ of graphemes.segment(text)) count++;
1425
+ return count;
1426
+ }
1427
+ const words = segmenter(locale, "word");
1428
+ if (!words) return text.split(/\s+/u).filter((word) => word.length > 0).length;
1429
+ let count = 0;
1430
+ for (const segment of words.segment(text)) if (segment.isWordLike) count++;
1431
+ return count;
1432
+ }
1433
+ function documentText(doc, unit) {
1434
+ const separator = unit === "words" ? "\n" : "";
1435
+ return doc.textBetween(0, doc.content.size, separator, (leaf) => {
1436
+ if (leaf.type.name === "mention") return `@${String(leaf.attrs["label"] ?? leaf.attrs["id"] ?? "")}`;
1437
+ return leaf.type.name === "hardBreak" ? separator : "";
1438
+ });
1439
+ }
1440
+ function htmlText(html, separator) {
1441
+ if (typeof DOMParser === "undefined") return html.replace(/<[^>]*>/gu, separator);
1442
+ const body = new DOMParser().parseFromString(html, "text/html").body;
1443
+ let text = "";
1444
+ const walk = (node) => {
1445
+ if (node.nodeType === 3) {
1446
+ text += node.nodeValue ?? "";
1447
+ return;
1448
+ }
1449
+ if (node.nodeType !== 1) return;
1450
+ if (BLOCK_ELEMENTS.has(node.tagName)) text += separator;
1451
+ node.childNodes.forEach(walk);
1452
+ };
1453
+ body.childNodes.forEach(walk);
1454
+ return text;
1455
+ }
1456
+ function countEditorText(html, unit, locale) {
1457
+ return countText(htmlText(html, unit === "words" ? "\n" : ""), unit, locale);
1458
+ }
648
1459
  var EditorPressedDirective = class EditorPressedDirective {
649
1460
  #host;
650
1461
  constructor() {
@@ -1745,6 +2556,8 @@ i0.ɵɵngDeclareClassMetadata({
1745
2556
  }]
1746
2557
  });
1747
2558
  var EditorImageInserterComponent = class EditorImageInserterComponent {
2559
+ #i18n;
2560
+ #imageFormModel;
1748
2561
  constructor() {
1749
2562
  this.#i18n = inject(MonaI18nService);
1750
2563
  this.#imageFormModel = signal({
@@ -1776,11 +2589,17 @@ var EditorImageInserterComponent = class EditorImageInserterComponent {
1776
2589
  this.rowLabelClass = computed(() => {
1777
2590
  return editorImageInserterRowLabelThemeVariants();
1778
2591
  }, ...ngDevMode ? [{ debugName: "rowLabelClass" }] : /* istanbul ignore next */ []);
2592
+ this.accept = input("image/*", ...ngDevMode ? [{ debugName: "accept" }] : /* istanbul ignore next */ []);
2593
+ this.image = input(null, ...ngDevMode ? [{ debugName: "image" }] : /* istanbul ignore next */ []);
1779
2594
  this.insert = output();
1780
2595
  this.insertCancel = output();
2596
+ this.maxFileSize = input(null, ...ngDevMode ? [{ debugName: "maxFileSize" }] : /* istanbul ignore next */ []);
2597
+ this.upload = input(null, ...ngDevMode ? [{ debugName: "upload" }] : /* istanbul ignore next */ []);
2598
+ effect(() => {
2599
+ const image = this.image();
2600
+ if (image) untracked(() => this.#imageFormModel.set({ ...image }));
2601
+ });
1781
2602
  }
1782
- #i18n;
1783
- #imageFormModel;
1784
2603
  onCancel() {
1785
2604
  this.insertCancel.emit();
1786
2605
  }
@@ -1792,6 +2611,10 @@ var EditorImageInserterComponent = class EditorImageInserterComponent {
1792
2611
  width: this.iForm.width().value()
1793
2612
  });
1794
2613
  }
2614
+ onUploadSuccess(item) {
2615
+ if (typeof item.response === "string" && item.response !== "") this.iForm.link().value.set(item.response);
2616
+ else if (isDevMode()) console.warn("[Mona Editor] imageUpload should return the image's address as a string, but it returned:", item.response);
2617
+ }
1795
2618
  static {
1796
2619
  this.ɵfac = i0.ɵɵngDeclareFactory({
1797
2620
  minVersion: "12.0.0",
@@ -1804,17 +2627,47 @@ var EditorImageInserterComponent = class EditorImageInserterComponent {
1804
2627
  }
1805
2628
  static {
1806
2629
  this.ɵcmp = i0.ɵɵngDeclareComponent({
1807
- minVersion: "14.0.0",
2630
+ minVersion: "17.0.0",
1808
2631
  version: "22.2.6",
1809
2632
  type: EditorImageInserterComponent,
1810
2633
  isStandalone: true,
1811
2634
  selector: "mona-editor-image-inserter",
2635
+ inputs: {
2636
+ accept: {
2637
+ classPropertyName: "accept",
2638
+ publicName: "accept",
2639
+ isSignal: true,
2640
+ isRequired: false,
2641
+ transformFunction: null
2642
+ },
2643
+ image: {
2644
+ classPropertyName: "image",
2645
+ publicName: "image",
2646
+ isSignal: true,
2647
+ isRequired: false,
2648
+ transformFunction: null
2649
+ },
2650
+ maxFileSize: {
2651
+ classPropertyName: "maxFileSize",
2652
+ publicName: "maxFileSize",
2653
+ isSignal: true,
2654
+ isRequired: false,
2655
+ transformFunction: null
2656
+ },
2657
+ upload: {
2658
+ classPropertyName: "upload",
2659
+ publicName: "upload",
2660
+ isSignal: true,
2661
+ isRequired: false,
2662
+ transformFunction: null
2663
+ }
2664
+ },
1812
2665
  outputs: {
1813
2666
  insert: "insert",
1814
2667
  insertCancel: "insertCancel"
1815
2668
  },
1816
2669
  ngImport: i0,
1817
- template: "<form [formRoot]=\"iForm\" [class]=\"formClass()\">\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.link\">{{ messages().imageUrl }}</label>\n <mona-text-box [size]=\"'small'\" [formField]=\"iForm.link\" [aria-labelledby]=\"labelIds.link\"></mona-text-box>\n </div>\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.alt\">{{ messages().altText }}</label>\n <mona-text-box [size]=\"'small'\" [formField]=\"iForm.alt\" [aria-labelledby]=\"labelIds.alt\"></mona-text-box>\n </div>\n <div class=\"flex gap-2\">\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.width\">{{ messages().widthPx }}</label>\n <mona-numeric-text-box\n [size]=\"'small'\"\n [formField]=\"iForm.width\"\n [aria-labelledby]=\"labelIds.width\"></mona-numeric-text-box>\n </div>\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.height\">{{ messages().heightPx }}</label>\n <mona-numeric-text-box\n [size]=\"'small'\"\n [formField]=\"iForm.height\"\n [aria-labelledby]=\"labelIds.height\"></mona-numeric-text-box>\n </div>\n </div>\n <div [class]=\"actionsClass()\">\n <button monaButton [size]=\"'small'\" [disabled]=\"!iForm().valid()\" look=\"primary\" (click)=\"onImageInsert()\">\n {{ messages().insert }}\n </button>\n <button monaButton [size]=\"'small'\" [look]=\"'secondary'\" (click)=\"onCancel()\">{{ messages().cancel }}</button>\n </div>\n</form>\n",
2670
+ template: "<form [formRoot]=\"iForm\" [class]=\"formClass()\">\n @if (upload()) {\n <div [class]=\"rowClass()\">\n <mona-file-upload\n [accept]=\"accept()\"\n [aria-label]=\"messages().imageFile\"\n [maxFileSize]=\"maxFileSize()\"\n [multiple]=\"false\"\n [upload]=\"upload()\"\n (uploadSuccess)=\"onUploadSuccess($event)\"></mona-file-upload>\n </div>\n }\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.link\">{{ messages().imageUrl }}</label>\n <mona-text-box [size]=\"'small'\" [formField]=\"iForm.link\" [aria-labelledby]=\"labelIds.link\"></mona-text-box>\n </div>\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.alt\">{{ messages().altText }}</label>\n <mona-text-box [size]=\"'small'\" [formField]=\"iForm.alt\" [aria-labelledby]=\"labelIds.alt\"></mona-text-box>\n </div>\n <div class=\"flex gap-2\">\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.width\">{{ messages().widthPx }}</label>\n <mona-numeric-text-box\n [size]=\"'small'\"\n [formField]=\"iForm.width\"\n [aria-labelledby]=\"labelIds.width\"></mona-numeric-text-box>\n </div>\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.height\">{{ messages().heightPx }}</label>\n <mona-numeric-text-box\n [size]=\"'small'\"\n [formField]=\"iForm.height\"\n [aria-labelledby]=\"labelIds.height\"></mona-numeric-text-box>\n </div>\n </div>\n <div [class]=\"actionsClass()\">\n <button monaButton [size]=\"'small'\" [disabled]=\"!iForm().valid()\" look=\"primary\" (click)=\"onImageInsert()\">\n {{ image() ? messages().save : messages().insert }}\n </button>\n <button monaButton [size]=\"'small'\" [look]=\"'secondary'\" (click)=\"onCancel()\">{{ messages().cancel }}</button>\n </div>\n</form>\n",
1818
2671
  dependencies: [
1819
2672
  {
1820
2673
  kind: "component",
@@ -1872,6 +2725,38 @@ var EditorImageInserterComponent = class EditorImageInserterComponent {
1872
2725
  ],
1873
2726
  outputs: ["lookChange", "selectedChange"]
1874
2727
  },
2728
+ {
2729
+ kind: "component",
2730
+ type: FileUploadComponent,
2731
+ selector: "mona-file-upload",
2732
+ inputs: [
2733
+ "accept",
2734
+ "aria-describedby",
2735
+ "aria-label",
2736
+ "aria-labelledby",
2737
+ "autoUpload",
2738
+ "disabled",
2739
+ "invalid",
2740
+ "maxFileSize",
2741
+ "maxFiles",
2742
+ "minFileSize",
2743
+ "multiple",
2744
+ "readonly",
2745
+ "required",
2746
+ "touched",
2747
+ "upload",
2748
+ "class",
2749
+ "value"
2750
+ ],
2751
+ outputs: [
2752
+ "remove",
2753
+ "touch",
2754
+ "uploadError",
2755
+ "uploadSuccess",
2756
+ "valueChange"
2757
+ ],
2758
+ exportAs: ["monaFileUpload"]
2759
+ },
1875
2760
  {
1876
2761
  kind: "component",
1877
2762
  type: NumericTextBoxComponent,
@@ -1914,14 +2799,32 @@ i0.ɵɵngDeclareClassMetadata({
1914
2799
  imports: [
1915
2800
  TextBoxComponent,
1916
2801
  ButtonDirective,
2802
+ FileUploadComponent,
1917
2803
  NumericTextBoxComponent,
1918
2804
  FormRoot,
1919
2805
  FormField
1920
2806
  ],
1921
- template: "<form [formRoot]=\"iForm\" [class]=\"formClass()\">\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.link\">{{ messages().imageUrl }}</label>\n <mona-text-box [size]=\"'small'\" [formField]=\"iForm.link\" [aria-labelledby]=\"labelIds.link\"></mona-text-box>\n </div>\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.alt\">{{ messages().altText }}</label>\n <mona-text-box [size]=\"'small'\" [formField]=\"iForm.alt\" [aria-labelledby]=\"labelIds.alt\"></mona-text-box>\n </div>\n <div class=\"flex gap-2\">\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.width\">{{ messages().widthPx }}</label>\n <mona-numeric-text-box\n [size]=\"'small'\"\n [formField]=\"iForm.width\"\n [aria-labelledby]=\"labelIds.width\"></mona-numeric-text-box>\n </div>\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.height\">{{ messages().heightPx }}</label>\n <mona-numeric-text-box\n [size]=\"'small'\"\n [formField]=\"iForm.height\"\n [aria-labelledby]=\"labelIds.height\"></mona-numeric-text-box>\n </div>\n </div>\n <div [class]=\"actionsClass()\">\n <button monaButton [size]=\"'small'\" [disabled]=\"!iForm().valid()\" look=\"primary\" (click)=\"onImageInsert()\">\n {{ messages().insert }}\n </button>\n <button monaButton [size]=\"'small'\" [look]=\"'secondary'\" (click)=\"onCancel()\">{{ messages().cancel }}</button>\n </div>\n</form>\n"
2807
+ template: "<form [formRoot]=\"iForm\" [class]=\"formClass()\">\n @if (upload()) {\n <div [class]=\"rowClass()\">\n <mona-file-upload\n [accept]=\"accept()\"\n [aria-label]=\"messages().imageFile\"\n [maxFileSize]=\"maxFileSize()\"\n [multiple]=\"false\"\n [upload]=\"upload()\"\n (uploadSuccess)=\"onUploadSuccess($event)\"></mona-file-upload>\n </div>\n }\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.link\">{{ messages().imageUrl }}</label>\n <mona-text-box [size]=\"'small'\" [formField]=\"iForm.link\" [aria-labelledby]=\"labelIds.link\"></mona-text-box>\n </div>\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.alt\">{{ messages().altText }}</label>\n <mona-text-box [size]=\"'small'\" [formField]=\"iForm.alt\" [aria-labelledby]=\"labelIds.alt\"></mona-text-box>\n </div>\n <div class=\"flex gap-2\">\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.width\">{{ messages().widthPx }}</label>\n <mona-numeric-text-box\n [size]=\"'small'\"\n [formField]=\"iForm.width\"\n [aria-labelledby]=\"labelIds.width\"></mona-numeric-text-box>\n </div>\n <div [class]=\"rowClass()\">\n <label [class]=\"rowLabelClass()\" [id]=\"labelIds.height\">{{ messages().heightPx }}</label>\n <mona-numeric-text-box\n [size]=\"'small'\"\n [formField]=\"iForm.height\"\n [aria-labelledby]=\"labelIds.height\"></mona-numeric-text-box>\n </div>\n </div>\n <div [class]=\"actionsClass()\">\n <button monaButton [size]=\"'small'\" [disabled]=\"!iForm().valid()\" look=\"primary\" (click)=\"onImageInsert()\">\n {{ image() ? messages().save : messages().insert }}\n </button>\n <button monaButton [size]=\"'small'\" [look]=\"'secondary'\" (click)=\"onCancel()\">{{ messages().cancel }}</button>\n </div>\n</form>\n"
1922
2808
  }]
1923
2809
  }],
2810
+ ctorParameters: () => [],
1924
2811
  propDecorators: {
2812
+ accept: [{
2813
+ type: i0.Input,
2814
+ args: [{
2815
+ isSignal: true,
2816
+ alias: "accept",
2817
+ required: false
2818
+ }]
2819
+ }],
2820
+ image: [{
2821
+ type: i0.Input,
2822
+ args: [{
2823
+ isSignal: true,
2824
+ alias: "image",
2825
+ required: false
2826
+ }]
2827
+ }],
1925
2828
  insert: [{
1926
2829
  type: i0.Output,
1927
2830
  args: ["insert"]
@@ -1929,19 +2832,55 @@ i0.ɵɵngDeclareClassMetadata({
1929
2832
  insertCancel: [{
1930
2833
  type: i0.Output,
1931
2834
  args: ["insertCancel"]
2835
+ }],
2836
+ maxFileSize: [{
2837
+ type: i0.Input,
2838
+ args: [{
2839
+ isSignal: true,
2840
+ alias: "maxFileSize",
2841
+ required: false
2842
+ }]
2843
+ }],
2844
+ upload: [{
2845
+ type: i0.Input,
2846
+ args: [{
2847
+ isSignal: true,
2848
+ alias: "upload",
2849
+ required: false
2850
+ }]
1932
2851
  }]
1933
2852
  }
1934
2853
  });
2854
+ function pixels(value) {
2855
+ const number = Number(value);
2856
+ return value == null || value === "" || !Number.isFinite(number) ? null : number;
2857
+ }
1935
2858
  var EditorImageComponent = class EditorImageComponent {
1936
2859
  constructor() {
1937
2860
  this.#editorService = inject(EditorService);
1938
2861
  this.#i18n = inject(MonaI18nService);
2862
+ this.#selectedImage = computed(() => {
2863
+ const selection = this.#editorService.state()?.selection;
2864
+ if (!(selection instanceof NodeSelection) || selection.node.type.name !== "extendedImage") return null;
2865
+ const attributes = selection.node.attrs;
2866
+ return {
2867
+ alt: String(attributes["alt"] ?? ""),
2868
+ height: pixels(attributes["height"]),
2869
+ link: String(attributes["src"] ?? ""),
2870
+ width: pixels(attributes["width"])
2871
+ };
2872
+ }, ...ngDevMode ? [{ debugName: "#selectedImage" }] : /* istanbul ignore next */ []);
2873
+ this.editedImage = signal(null, ...ngDevMode ? [{ debugName: "editedImage" }] : /* istanbul ignore next */ []);
1939
2874
  this.inserterVisible = signal(false, ...ngDevMode ? [{ debugName: "inserterVisible" }] : /* istanbul ignore next */ []);
2875
+ this.label = computed(() => this.#selectedImage() ? this.messages().editImage : this.messages().insertImage, ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
1940
2876
  this.messages = this.#i18n.componentMessages("editor", EDITOR_DEFAULT_MESSAGES);
2877
+ this.upload = inject(EditorImageUploadService).options;
1941
2878
  }
1942
2879
  #editorService;
1943
2880
  #i18n;
2881
+ #selectedImage;
1944
2882
  onDisplayInserterClick() {
2883
+ this.editedImage.set(this.#selectedImage());
1945
2884
  this.inserterVisible.set(true);
1946
2885
  }
1947
2886
  onImageInsert(event) {
@@ -1958,7 +2897,18 @@ var EditorImageComponent = class EditorImageComponent {
1958
2897
  this.inserterVisible.set(false);
1959
2898
  }
1960
2899
  insertImage(event) {
1961
- this.#editorService.editor.chain().focus().setImage({
2900
+ const chain = this.#editorService.editor.chain().focus();
2901
+ if (this.editedImage() && this.#selectedImage()) {
2902
+ chain.updateAttributes("extendedImage", {
2903
+ alt: event.alt,
2904
+ height: event.height,
2905
+ src: event.link,
2906
+ title: event.alt,
2907
+ width: event.width
2908
+ }).run();
2909
+ return;
2910
+ }
2911
+ chain.setImage({
1962
2912
  alt: event.alt,
1963
2913
  height: event.height ?? void 0,
1964
2914
  src: event.link,
@@ -1984,7 +2934,7 @@ var EditorImageComponent = class EditorImageComponent {
1984
2934
  isStandalone: true,
1985
2935
  selector: "mona-editor-image",
1986
2936
  ngImport: i0,
1987
- template: "<button\n monaButton\n [size]=\"'small'\"\n aria-haspopup=\"dialog\"\n (click)=\"onDisplayInserterClick()\"\n [title]=\"messages().insertImage\">\n <i class=\"ri-image-add-line\"></i>\n</button>\n\n@if (inserterVisible()) {\n <mona-window\n [width]=\"400\"\n [modal]=\"true\"\n [title]=\"messages().insertImage\"\n [minimizable]=\"false\"\n [maximizable]=\"false\"\n (close)=\"onInserterClose()\">\n <ng-template monaWindowContentTemplate>\n <mona-editor-image-inserter\n (insert)=\"onImageInsert($event)\"\n (insertCancel)=\"onInsertCancel()\"></mona-editor-image-inserter>\n </ng-template>\n </mona-window>\n}\n",
2937
+ template: "<button monaButton [size]=\"'small'\" aria-haspopup=\"dialog\" (click)=\"onDisplayInserterClick()\" [title]=\"label()\">\n <i class=\"ri-image-add-line\"></i>\n</button>\n\n@if (inserterVisible()) {\n <mona-window\n [width]=\"400\"\n [modal]=\"true\"\n [title]=\"editedImage() ? messages().editImage : messages().insertImage\"\n [minimizable]=\"false\"\n [maximizable]=\"false\"\n (close)=\"onInserterClose()\">\n <ng-template monaWindowContentTemplate>\n <mona-editor-image-inserter\n [accept]=\"upload().accept\"\n [image]=\"editedImage()\"\n [maxFileSize]=\"upload().maxFileSize\"\n [upload]=\"upload().handler\"\n (insert)=\"onImageInsert($event)\"\n (insertCancel)=\"onInsertCancel()\"></mona-editor-image-inserter>\n </ng-template>\n </mona-window>\n}\n",
1988
2938
  dependencies: [
1989
2939
  {
1990
2940
  kind: "component",
@@ -2028,6 +2978,12 @@ var EditorImageComponent = class EditorImageComponent {
2028
2978
  kind: "component",
2029
2979
  type: EditorImageInserterComponent,
2030
2980
  selector: "mona-editor-image-inserter",
2981
+ inputs: [
2982
+ "accept",
2983
+ "image",
2984
+ "maxFileSize",
2985
+ "upload"
2986
+ ],
2031
2987
  outputs: ["insert", "insertCancel"]
2032
2988
  },
2033
2989
  {
@@ -2075,7 +3031,7 @@ i0.ɵɵngDeclareClassMetadata({
2075
3031
  ButtonDirective,
2076
3032
  WindowContentTemplateDirective
2077
3033
  ],
2078
- template: "<button\n monaButton\n [size]=\"'small'\"\n aria-haspopup=\"dialog\"\n (click)=\"onDisplayInserterClick()\"\n [title]=\"messages().insertImage\">\n <i class=\"ri-image-add-line\"></i>\n</button>\n\n@if (inserterVisible()) {\n <mona-window\n [width]=\"400\"\n [modal]=\"true\"\n [title]=\"messages().insertImage\"\n [minimizable]=\"false\"\n [maximizable]=\"false\"\n (close)=\"onInserterClose()\">\n <ng-template monaWindowContentTemplate>\n <mona-editor-image-inserter\n (insert)=\"onImageInsert($event)\"\n (insertCancel)=\"onInsertCancel()\"></mona-editor-image-inserter>\n </ng-template>\n </mona-window>\n}\n"
3034
+ template: "<button monaButton [size]=\"'small'\" aria-haspopup=\"dialog\" (click)=\"onDisplayInserterClick()\" [title]=\"label()\">\n <i class=\"ri-image-add-line\"></i>\n</button>\n\n@if (inserterVisible()) {\n <mona-window\n [width]=\"400\"\n [modal]=\"true\"\n [title]=\"editedImage() ? messages().editImage : messages().insertImage\"\n [minimizable]=\"false\"\n [maximizable]=\"false\"\n (close)=\"onInserterClose()\">\n <ng-template monaWindowContentTemplate>\n <mona-editor-image-inserter\n [accept]=\"upload().accept\"\n [image]=\"editedImage()\"\n [maxFileSize]=\"upload().maxFileSize\"\n [upload]=\"upload().handler\"\n (insert)=\"onImageInsert($event)\"\n (insertCancel)=\"onInsertCancel()\"></mona-editor-image-inserter>\n </ng-template>\n </mona-window>\n}\n"
2079
3035
  }]
2080
3036
  }]
2081
3037
  });
@@ -3179,18 +4135,29 @@ const EMPTY_DOCUMENT = {
3179
4135
  content: []
3180
4136
  };
3181
4137
  var EditorComponent = class EditorComponent {
4138
+ #announcer;
4139
+ #characters;
3182
4140
  #contentAttributes;
3183
4141
  #destroyRef;
3184
4142
  #direction;
3185
4143
  #editable;
3186
4144
  #i18n;
4145
+ #imageUpload;
3187
4146
  #label;
4147
+ #mention;
3188
4148
  #rendered;
3189
4149
  #toolbar;
4150
+ #words;
3190
4151
  #appliedContent;
3191
4152
  #lastValue;
3192
4153
  #tabLeaves;
3193
4154
  constructor() {
4155
+ this.#announcer = injectLiveAnnouncer();
4156
+ this.#characters = computed(() => {
4157
+ const state = this.editorService.state();
4158
+ if (state === null || this.characterLimit() === null && !this.showCharacterCount()) return null;
4159
+ return countText(documentText(state.doc, "characters"), "characters", this.#i18n.localeId() ?? void 0);
4160
+ }, ...ngDevMode ? [{ debugName: "#characters" }] : /* istanbul ignore next */ []);
3194
4161
  this.#contentAttributes = computed(() => {
3195
4162
  const attributes = {
3196
4163
  "aria-multiline": "true",
@@ -3200,8 +4167,14 @@ var EditorComponent = class EditorComponent {
3200
4167
  const ariaLabelledBy = this.#label.labelledBy();
3201
4168
  if (ariaLabelledBy) attributes["aria-labelledby"] = ariaLabelledBy;
3202
4169
  else attributes["aria-label"] = this.ariaLabel() || this.messages().contentLabel;
3203
- const ariaDescribedBy = this.#label.describedBy();
3204
- if (ariaDescribedBy) attributes["aria-describedby"] = ariaDescribedBy;
4170
+ const describedBy = [this.#label.describedBy(), this.characterLimit() === null ? "" : this.limitHintId].filter((id) => !!id).join(" ");
4171
+ if (describedBy) attributes["aria-describedby"] = describedBy;
4172
+ const activeDescendant = this.#mention.activeDescendant();
4173
+ if (activeDescendant) {
4174
+ attributes["aria-activedescendant"] = activeDescendant;
4175
+ attributes["aria-autocomplete"] = "list";
4176
+ attributes["aria-controls"] = this.#mention.listId;
4177
+ }
3205
4178
  if (this.placeholder()) attributes["aria-placeholder"] = this.placeholder();
3206
4179
  if (this.effectiveDisabled()) attributes["aria-disabled"] = "true";
3207
4180
  if (this.readonly()) attributes["aria-readonly"] = "true";
@@ -3213,6 +4186,7 @@ var EditorComponent = class EditorComponent {
3213
4186
  this.#direction = injectComponentDirection();
3214
4187
  this.#editable = computed(() => !this.effectiveDisabled() && !this.readonly(), ...ngDevMode ? [{ debugName: "#editable" }] : /* istanbul ignore next */ []);
3215
4188
  this.#i18n = inject(MonaI18nService);
4189
+ this.#imageUpload = inject(EditorImageUploadService);
3216
4190
  this.#label = injectLabelAssociation({
3217
4191
  activate: () => this.focus(),
3218
4192
  ariaDescribedBy: () => this.ariaDescribedBy(),
@@ -3220,8 +4194,14 @@ var EditorComponent = class EditorComponent {
3220
4194
  ariaLabelledBy: () => this.ariaLabelledBy(),
3221
4195
  focus: () => this.focus()
3222
4196
  });
4197
+ this.#mention = inject(EditorMentionService);
3223
4198
  this.#rendered = signal(false, ...ngDevMode ? [{ debugName: "#rendered" }] : /* istanbul ignore next */ []);
3224
4199
  this.#toolbar = new RovingToolbar(() => this.toolbarElement()?.nativeElement);
4200
+ this.#words = computed(() => {
4201
+ const state = this.editorService.state();
4202
+ if (state === null || !this.showWordCount()) return null;
4203
+ return countText(documentText(state.doc, "words"), "words", this.#i18n.localeId() ?? void 0);
4204
+ }, ...ngDevMode ? [{ debugName: "#words" }] : /* istanbul ignore next */ []);
3225
4205
  this.#appliedContent = void 0;
3226
4206
  this.#lastValue = null;
3227
4207
  this.#tabLeaves = false;
@@ -3233,11 +4213,49 @@ var EditorComponent = class EditorComponent {
3233
4213
  this.containerClass = computed(() => {
3234
4214
  return editorContainerThemeVariants({ disabled: this.effectiveDisabled() });
3235
4215
  }, ...ngDevMode ? [{ debugName: "containerClass" }] : /* istanbul ignore next */ []);
4216
+ this.countParts = computed(() => {
4217
+ const messages = this.messages();
4218
+ const parts = [];
4219
+ const words = this.#words();
4220
+ if (words !== null) parts.push({
4221
+ class: "",
4222
+ text: messages.wordCount(words)
4223
+ });
4224
+ const limitMessage = this.limitMessage();
4225
+ const characters = this.#characters();
4226
+ if (limitMessage !== null) parts.push({
4227
+ class: this.overLimit() ? EDITOR_COUNT_OVER_CLASSES : "",
4228
+ text: limitMessage
4229
+ });
4230
+ else if (characters !== null) parts.push({
4231
+ class: "",
4232
+ text: messages.characterCount(characters)
4233
+ });
4234
+ return parts;
4235
+ }, ...ngDevMode ? [{ debugName: "countParts" }] : /* istanbul ignore next */ []);
3236
4236
  this.editorContainer = viewChild.required("editorContainer", ...ngDevMode ? [{ debugName: "editorContainer" }] : /* istanbul ignore next */ []);
3237
4237
  this.editorService = inject(EditorService);
3238
4238
  this.effectiveDisabled = injectEffectiveDisabled(() => this.disabled());
3239
- this.invalidState = computed(() => this.touched() && (this.invalid() || this.required() && !this.value()), ...ngDevMode ? [{ debugName: "invalidState" }] : /* istanbul ignore next */ []);
4239
+ this.footerClass = EDITOR_FOOTER_CLASSES;
4240
+ this.invalidState = computed(() => this.touched() && (this.invalid() || this.required() && !this.value()) || this.overLimit(), ...ngDevMode ? [{ debugName: "invalidState" }] : /* istanbul ignore next */ []);
4241
+ this.limitHint = computed(() => {
4242
+ const limit = this.characterLimit();
4243
+ return limit === null ? "" : this.messages().characterLimitHint(limit);
4244
+ }, ...ngDevMode ? [{ debugName: "limitHint" }] : /* istanbul ignore next */ []);
4245
+ this.limitHintId = createElementControlId();
4246
+ this.limitMessage = computed(() => {
4247
+ const limit = this.characterLimit();
4248
+ const characters = this.#characters();
4249
+ if (limit === null || characters === null) return null;
4250
+ const messages = this.messages();
4251
+ return characters <= limit ? messages.charactersLeft(limit - characters) : messages.charactersOver(characters - limit);
4252
+ }, ...ngDevMode ? [{ debugName: "limitMessage" }] : /* istanbul ignore next */ []);
3240
4253
  this.messages = this.#i18n.componentMessages("editor", EDITOR_DEFAULT_MESSAGES);
4254
+ this.overLimit = computed(() => {
4255
+ const limit = this.characterLimit();
4256
+ const characters = this.#characters();
4257
+ return limit !== null && characters !== null && characters > limit;
4258
+ }, ...ngDevMode ? [{ debugName: "overLimit" }] : /* istanbul ignore next */ []);
3241
4259
  this.placeholderClass = computed(() => editorPlaceholderThemeVariants(), ...ngDevMode ? [{ debugName: "placeholderClass" }] : /* istanbul ignore next */ []);
3242
4260
  this.toolbarClass = computed(() => {
3243
4261
  return editorToolbarThemeVariants({ disabled: this.effectiveDisabled() });
@@ -3256,6 +4274,7 @@ var EditorComponent = class EditorComponent {
3256
4274
  alias: "aria-labelledby"
3257
4275
  });
3258
4276
  this.blur = output();
4277
+ this.characterLimit = input(null, ...ngDevMode ? [{ debugName: "characterLimit" }] : /* istanbul ignore next */ []);
3259
4278
  this.content = input(...ngDevMode ? [void 0, { debugName: "content" }] : /* istanbul ignore next */ []);
3260
4279
  this.create = output();
3261
4280
  this.disabled = input(false, {
@@ -3264,10 +4283,14 @@ var EditorComponent = class EditorComponent {
3264
4283
  });
3265
4284
  this.editorBlur = output();
3266
4285
  this.editorFocus = output();
4286
+ this.imageAccept = input("image/*", ...ngDevMode ? [{ debugName: "imageAccept" }] : /* istanbul ignore next */ []);
4287
+ this.imageMaxFileSize = input(null, ...ngDevMode ? [{ debugName: "imageMaxFileSize" }] : /* istanbul ignore next */ []);
4288
+ this.imageUpload = input(null, ...ngDevMode ? [{ debugName: "imageUpload" }] : /* istanbul ignore next */ []);
3267
4289
  this.invalid = input(false, {
3268
4290
  ...ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {},
3269
4291
  transform: booleanAttribute
3270
4292
  });
4293
+ this.mentionSearch = input(null, ...ngDevMode ? [{ debugName: "mentionSearch" }] : /* istanbul ignore next */ []);
3271
4294
  this.placeholder = input("", ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
3272
4295
  this.readonly = input(false, {
3273
4296
  ...ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {},
@@ -3279,6 +4302,14 @@ var EditorComponent = class EditorComponent {
3279
4302
  });
3280
4303
  this.selectionUpdate = output();
3281
4304
  this.settings = input({}, ...ngDevMode ? [{ debugName: "settings" }] : /* istanbul ignore next */ []);
4305
+ this.showCharacterCount = input(false, {
4306
+ ...ngDevMode ? { debugName: "showCharacterCount" } : /* istanbul ignore next */ {},
4307
+ transform: booleanAttribute
4308
+ });
4309
+ this.showWordCount = input(false, {
4310
+ ...ngDevMode ? { debugName: "showWordCount" } : /* istanbul ignore next */ {},
4311
+ transform: booleanAttribute
4312
+ });
3282
4313
  this.touch = output();
3283
4314
  this.touched = input(false, {
3284
4315
  ...ngDevMode ? { debugName: "touched" } : /* istanbul ignore next */ {},
@@ -3310,6 +4341,16 @@ var EditorComponent = class EditorComponent {
3310
4341
  if (!this.editorService.ready()) return;
3311
4342
  untracked(() => this.#applyContent(content));
3312
4343
  });
4344
+ effect(() => {
4345
+ this.#imageUpload.options.set({
4346
+ accept: this.imageAccept(),
4347
+ handler: this.imageUpload(),
4348
+ maxFileSize: this.imageMaxFileSize()
4349
+ });
4350
+ });
4351
+ effect(() => {
4352
+ this.#mention.search.set(this.mentionSearch());
4353
+ });
3313
4354
  effect(() => {
3314
4355
  const editable = this.#editable();
3315
4356
  const attributes = this.#contentAttributes();
@@ -3394,6 +4435,10 @@ var EditorComponent = class EditorComponent {
3394
4435
  this.editorService.selectionUpdate$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
3395
4436
  this.selectionUpdate.emit();
3396
4437
  });
4438
+ this.editorService.update$.pipe(debounceTime(1e3), takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
4439
+ const message = untracked(this.limitMessage);
4440
+ if (message !== null && this.editorService.ready() && this.editorService.editor.isFocused) this.#announcer.announce(message, "polite");
4441
+ });
3397
4442
  this.editorService.update$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
3398
4443
  const value = this.#currentValue();
3399
4444
  this.#lastValue = value;
@@ -3443,6 +4488,13 @@ var EditorComponent = class EditorComponent {
3443
4488
  isRequired: false,
3444
4489
  transformFunction: null
3445
4490
  },
4491
+ characterLimit: {
4492
+ classPropertyName: "characterLimit",
4493
+ publicName: "characterLimit",
4494
+ isSignal: true,
4495
+ isRequired: false,
4496
+ transformFunction: null
4497
+ },
3446
4498
  content: {
3447
4499
  classPropertyName: "content",
3448
4500
  publicName: "content",
@@ -3457,6 +4509,27 @@ var EditorComponent = class EditorComponent {
3457
4509
  isRequired: false,
3458
4510
  transformFunction: null
3459
4511
  },
4512
+ imageAccept: {
4513
+ classPropertyName: "imageAccept",
4514
+ publicName: "imageAccept",
4515
+ isSignal: true,
4516
+ isRequired: false,
4517
+ transformFunction: null
4518
+ },
4519
+ imageMaxFileSize: {
4520
+ classPropertyName: "imageMaxFileSize",
4521
+ publicName: "imageMaxFileSize",
4522
+ isSignal: true,
4523
+ isRequired: false,
4524
+ transformFunction: null
4525
+ },
4526
+ imageUpload: {
4527
+ classPropertyName: "imageUpload",
4528
+ publicName: "imageUpload",
4529
+ isSignal: true,
4530
+ isRequired: false,
4531
+ transformFunction: null
4532
+ },
3460
4533
  invalid: {
3461
4534
  classPropertyName: "invalid",
3462
4535
  publicName: "invalid",
@@ -3464,6 +4537,13 @@ var EditorComponent = class EditorComponent {
3464
4537
  isRequired: false,
3465
4538
  transformFunction: null
3466
4539
  },
4540
+ mentionSearch: {
4541
+ classPropertyName: "mentionSearch",
4542
+ publicName: "mentionSearch",
4543
+ isSignal: true,
4544
+ isRequired: false,
4545
+ transformFunction: null
4546
+ },
3467
4547
  placeholder: {
3468
4548
  classPropertyName: "placeholder",
3469
4549
  publicName: "placeholder",
@@ -3492,6 +4572,20 @@ var EditorComponent = class EditorComponent {
3492
4572
  isRequired: false,
3493
4573
  transformFunction: null
3494
4574
  },
4575
+ showCharacterCount: {
4576
+ classPropertyName: "showCharacterCount",
4577
+ publicName: "showCharacterCount",
4578
+ isSignal: true,
4579
+ isRequired: false,
4580
+ transformFunction: null
4581
+ },
4582
+ showWordCount: {
4583
+ classPropertyName: "showWordCount",
4584
+ publicName: "showWordCount",
4585
+ isSignal: true,
4586
+ isRequired: false,
4587
+ transformFunction: null
4588
+ },
3495
4589
  touched: {
3496
4590
  classPropertyName: "touched",
3497
4591
  publicName: "touched",
@@ -3534,7 +4628,11 @@ var EditorComponent = class EditorComponent {
3534
4628
  "attr.data-readonly": "readonly() || null",
3535
4629
  "attr.data-required": "required() || null"
3536
4630
  } },
3537
- providers: [EditorService],
4631
+ providers: [
4632
+ EditorService,
4633
+ EditorImageUploadService,
4634
+ EditorMentionService
4635
+ ],
3538
4636
  viewQueries: [{
3539
4637
  propertyName: "editorContainer",
3540
4638
  first: true,
@@ -3549,7 +4647,7 @@ var EditorComponent = class EditorComponent {
3549
4647
  isSignal: true
3550
4648
  }],
3551
4649
  ngImport: i0,
3552
- template: "@if (editorService.ready() && !readonly()) {\n <div\n role=\"toolbar\"\n [class]=\"toolbarClass()\"\n [attr.aria-label]=\"messages().toolbar\"\n [attr.inert]=\"effectiveDisabled() || null\"\n (focusin)=\"onToolbarFocusIn($event)\"\n (keydown)=\"onToolbarKeydown($event)\"\n #toolbar>\n <mona-editor-basic-text-styles></mona-editor-basic-text-styles>\n @if (editorService.settings().headings) {\n <mona-editor-headings></mona-editor-headings>\n }\n @if (editorService.settings().alignment) {\n <mona-editor-text-alignments></mona-editor-text-alignments>\n }\n @if (editorService.settings().fontSize) {\n <mona-editor-font-size></mona-editor-font-size>\n }\n @if (editorService.settings().fontFamily) {\n <mona-editor-font-family></mona-editor-font-family>\n }\n @if (editorService.settings().fontColor) {\n <mona-editor-font-color></mona-editor-font-color>\n }\n @if (editorService.settings().fontHighlight) {\n <mona-editor-font-highlight></mona-editor-font-highlight>\n }\n @if (editorService.settings().blockquote) {\n <mona-editor-blockquote></mona-editor-blockquote>\n }\n @if (editorService.settings().code) {\n <mona-editor-code-block></mona-editor-code-block>\n }\n @if (editorService.settings().link) {\n <mona-editor-link></mona-editor-link>\n }\n @if (editorService.settings().list) {\n <mona-editor-list></mona-editor-list>\n }\n @if (editorService.settings().taskList) {\n <mona-editor-task-list></mona-editor-task-list>\n }\n @if (editorService.settings().indent) {\n <mona-editor-indent></mona-editor-indent>\n }\n @if (editorService.settings().history) {\n <mona-editor-history></mona-editor-history>\n }\n @if (editorService.settings().horizontalRule) {\n <mona-editor-horizontal-rule></mona-editor-horizontal-rule>\n }\n @if (editorService.settings().image) {\n <mona-editor-image></mona-editor-image>\n }\n @if (editorService.settings().table) {\n <mona-editor-table></mona-editor-table>\n }\n </div>\n}\n<div class=\"relative min-h-0 w-full flex-1\">\n <div [class]=\"containerClass()\" #editorContainer></div>\n @if (placeholder() && editorService.isEmpty()) {\n <div [class]=\"placeholderClass()\" aria-hidden=\"true\">{{ placeholder() }}</div>\n }\n</div>\n",
4650
+ template: "@if (editorService.ready() && !readonly()) {\n <div\n role=\"toolbar\"\n [class]=\"toolbarClass()\"\n [attr.aria-label]=\"messages().toolbar\"\n [attr.inert]=\"effectiveDisabled() || null\"\n (focusin)=\"onToolbarFocusIn($event)\"\n (keydown)=\"onToolbarKeydown($event)\"\n #toolbar>\n <mona-editor-basic-text-styles></mona-editor-basic-text-styles>\n @if (editorService.settings().headings) {\n <mona-editor-headings></mona-editor-headings>\n }\n @if (editorService.settings().alignment) {\n <mona-editor-text-alignments></mona-editor-text-alignments>\n }\n @if (editorService.settings().fontSize) {\n <mona-editor-font-size></mona-editor-font-size>\n }\n @if (editorService.settings().fontFamily) {\n <mona-editor-font-family></mona-editor-font-family>\n }\n @if (editorService.settings().fontColor) {\n <mona-editor-font-color></mona-editor-font-color>\n }\n @if (editorService.settings().fontHighlight) {\n <mona-editor-font-highlight></mona-editor-font-highlight>\n }\n @if (editorService.settings().blockquote) {\n <mona-editor-blockquote></mona-editor-blockquote>\n }\n @if (editorService.settings().code) {\n <mona-editor-code-block></mona-editor-code-block>\n }\n @if (editorService.settings().link) {\n <mona-editor-link></mona-editor-link>\n }\n @if (editorService.settings().list) {\n <mona-editor-list></mona-editor-list>\n }\n @if (editorService.settings().taskList) {\n <mona-editor-task-list></mona-editor-task-list>\n }\n @if (editorService.settings().indent) {\n <mona-editor-indent></mona-editor-indent>\n }\n @if (editorService.settings().history) {\n <mona-editor-history></mona-editor-history>\n }\n @if (editorService.settings().horizontalRule) {\n <mona-editor-horizontal-rule></mona-editor-horizontal-rule>\n }\n @if (editorService.settings().image) {\n <mona-editor-image></mona-editor-image>\n }\n @if (editorService.settings().table) {\n <mona-editor-table></mona-editor-table>\n }\n </div>\n}\n<div class=\"relative min-h-0 w-full flex-1\">\n <div [class]=\"containerClass()\" #editorContainer></div>\n @if (placeholder() && editorService.isEmpty()) {\n <div [class]=\"placeholderClass()\" aria-hidden=\"true\">{{ placeholder() }}</div>\n }\n</div>\n@if (countParts().length > 0) {\n <div [class]=\"footerClass\">\n @for (part of countParts(); track $index) {\n <span [class]=\"part.class\">{{ part.text }}</span>\n }\n </div>\n}\n@if (limitHint()) {\n <span class=\"sr-only\" [id]=\"limitHintId\">{{ limitHint() }}</span>\n}\n",
3553
4651
  dependencies: [
3554
4652
  {
3555
4653
  kind: "component",
@@ -3669,7 +4767,11 @@ i0.ɵɵngDeclareClassMetadata({
3669
4767
  EditorTableComponent,
3670
4768
  EditorCodeBlockComponent
3671
4769
  ],
3672
- providers: [EditorService],
4770
+ providers: [
4771
+ EditorService,
4772
+ EditorImageUploadService,
4773
+ EditorMentionService
4774
+ ],
3673
4775
  viewProviders: [...FIELD_ASSOCIATION_BOUNDARY],
3674
4776
  host: {
3675
4777
  "[class]": "baseClass()",
@@ -3681,7 +4783,7 @@ i0.ɵɵngDeclareClassMetadata({
3681
4783
  "[attr.data-readonly]": "readonly() || null",
3682
4784
  "[attr.data-required]": "required() || null"
3683
4785
  },
3684
- template: "@if (editorService.ready() && !readonly()) {\n <div\n role=\"toolbar\"\n [class]=\"toolbarClass()\"\n [attr.aria-label]=\"messages().toolbar\"\n [attr.inert]=\"effectiveDisabled() || null\"\n (focusin)=\"onToolbarFocusIn($event)\"\n (keydown)=\"onToolbarKeydown($event)\"\n #toolbar>\n <mona-editor-basic-text-styles></mona-editor-basic-text-styles>\n @if (editorService.settings().headings) {\n <mona-editor-headings></mona-editor-headings>\n }\n @if (editorService.settings().alignment) {\n <mona-editor-text-alignments></mona-editor-text-alignments>\n }\n @if (editorService.settings().fontSize) {\n <mona-editor-font-size></mona-editor-font-size>\n }\n @if (editorService.settings().fontFamily) {\n <mona-editor-font-family></mona-editor-font-family>\n }\n @if (editorService.settings().fontColor) {\n <mona-editor-font-color></mona-editor-font-color>\n }\n @if (editorService.settings().fontHighlight) {\n <mona-editor-font-highlight></mona-editor-font-highlight>\n }\n @if (editorService.settings().blockquote) {\n <mona-editor-blockquote></mona-editor-blockquote>\n }\n @if (editorService.settings().code) {\n <mona-editor-code-block></mona-editor-code-block>\n }\n @if (editorService.settings().link) {\n <mona-editor-link></mona-editor-link>\n }\n @if (editorService.settings().list) {\n <mona-editor-list></mona-editor-list>\n }\n @if (editorService.settings().taskList) {\n <mona-editor-task-list></mona-editor-task-list>\n }\n @if (editorService.settings().indent) {\n <mona-editor-indent></mona-editor-indent>\n }\n @if (editorService.settings().history) {\n <mona-editor-history></mona-editor-history>\n }\n @if (editorService.settings().horizontalRule) {\n <mona-editor-horizontal-rule></mona-editor-horizontal-rule>\n }\n @if (editorService.settings().image) {\n <mona-editor-image></mona-editor-image>\n }\n @if (editorService.settings().table) {\n <mona-editor-table></mona-editor-table>\n }\n </div>\n}\n<div class=\"relative min-h-0 w-full flex-1\">\n <div [class]=\"containerClass()\" #editorContainer></div>\n @if (placeholder() && editorService.isEmpty()) {\n <div [class]=\"placeholderClass()\" aria-hidden=\"true\">{{ placeholder() }}</div>\n }\n</div>\n"
4786
+ template: "@if (editorService.ready() && !readonly()) {\n <div\n role=\"toolbar\"\n [class]=\"toolbarClass()\"\n [attr.aria-label]=\"messages().toolbar\"\n [attr.inert]=\"effectiveDisabled() || null\"\n (focusin)=\"onToolbarFocusIn($event)\"\n (keydown)=\"onToolbarKeydown($event)\"\n #toolbar>\n <mona-editor-basic-text-styles></mona-editor-basic-text-styles>\n @if (editorService.settings().headings) {\n <mona-editor-headings></mona-editor-headings>\n }\n @if (editorService.settings().alignment) {\n <mona-editor-text-alignments></mona-editor-text-alignments>\n }\n @if (editorService.settings().fontSize) {\n <mona-editor-font-size></mona-editor-font-size>\n }\n @if (editorService.settings().fontFamily) {\n <mona-editor-font-family></mona-editor-font-family>\n }\n @if (editorService.settings().fontColor) {\n <mona-editor-font-color></mona-editor-font-color>\n }\n @if (editorService.settings().fontHighlight) {\n <mona-editor-font-highlight></mona-editor-font-highlight>\n }\n @if (editorService.settings().blockquote) {\n <mona-editor-blockquote></mona-editor-blockquote>\n }\n @if (editorService.settings().code) {\n <mona-editor-code-block></mona-editor-code-block>\n }\n @if (editorService.settings().link) {\n <mona-editor-link></mona-editor-link>\n }\n @if (editorService.settings().list) {\n <mona-editor-list></mona-editor-list>\n }\n @if (editorService.settings().taskList) {\n <mona-editor-task-list></mona-editor-task-list>\n }\n @if (editorService.settings().indent) {\n <mona-editor-indent></mona-editor-indent>\n }\n @if (editorService.settings().history) {\n <mona-editor-history></mona-editor-history>\n }\n @if (editorService.settings().horizontalRule) {\n <mona-editor-horizontal-rule></mona-editor-horizontal-rule>\n }\n @if (editorService.settings().image) {\n <mona-editor-image></mona-editor-image>\n }\n @if (editorService.settings().table) {\n <mona-editor-table></mona-editor-table>\n }\n </div>\n}\n<div class=\"relative min-h-0 w-full flex-1\">\n <div [class]=\"containerClass()\" #editorContainer></div>\n @if (placeholder() && editorService.isEmpty()) {\n <div [class]=\"placeholderClass()\" aria-hidden=\"true\">{{ placeholder() }}</div>\n }\n</div>\n@if (countParts().length > 0) {\n <div [class]=\"footerClass\">\n @for (part of countParts(); track $index) {\n <span [class]=\"part.class\">{{ part.text }}</span>\n }\n </div>\n}\n@if (limitHint()) {\n <span class=\"sr-only\" [id]=\"limitHintId\">{{ limitHint() }}</span>\n}\n"
3685
4787
  }]
3686
4788
  }],
3687
4789
  ctorParameters: () => [],
@@ -3722,6 +4824,14 @@ i0.ɵɵngDeclareClassMetadata({
3722
4824
  type: i0.Output,
3723
4825
  args: ["blur"]
3724
4826
  }],
4827
+ characterLimit: [{
4828
+ type: i0.Input,
4829
+ args: [{
4830
+ isSignal: true,
4831
+ alias: "characterLimit",
4832
+ required: false
4833
+ }]
4834
+ }],
3725
4835
  content: [{
3726
4836
  type: i0.Input,
3727
4837
  args: [{
@@ -3750,6 +4860,30 @@ i0.ɵɵngDeclareClassMetadata({
3750
4860
  type: i0.Output,
3751
4861
  args: ["editorFocus"]
3752
4862
  }],
4863
+ imageAccept: [{
4864
+ type: i0.Input,
4865
+ args: [{
4866
+ isSignal: true,
4867
+ alias: "imageAccept",
4868
+ required: false
4869
+ }]
4870
+ }],
4871
+ imageMaxFileSize: [{
4872
+ type: i0.Input,
4873
+ args: [{
4874
+ isSignal: true,
4875
+ alias: "imageMaxFileSize",
4876
+ required: false
4877
+ }]
4878
+ }],
4879
+ imageUpload: [{
4880
+ type: i0.Input,
4881
+ args: [{
4882
+ isSignal: true,
4883
+ alias: "imageUpload",
4884
+ required: false
4885
+ }]
4886
+ }],
3753
4887
  invalid: [{
3754
4888
  type: i0.Input,
3755
4889
  args: [{
@@ -3758,6 +4892,14 @@ i0.ɵɵngDeclareClassMetadata({
3758
4892
  required: false
3759
4893
  }]
3760
4894
  }],
4895
+ mentionSearch: [{
4896
+ type: i0.Input,
4897
+ args: [{
4898
+ isSignal: true,
4899
+ alias: "mentionSearch",
4900
+ required: false
4901
+ }]
4902
+ }],
3761
4903
  placeholder: [{
3762
4904
  type: i0.Input,
3763
4905
  args: [{
@@ -3794,6 +4936,22 @@ i0.ɵɵngDeclareClassMetadata({
3794
4936
  required: false
3795
4937
  }]
3796
4938
  }],
4939
+ showCharacterCount: [{
4940
+ type: i0.Input,
4941
+ args: [{
4942
+ isSignal: true,
4943
+ alias: "showCharacterCount",
4944
+ required: false
4945
+ }]
4946
+ }],
4947
+ showWordCount: [{
4948
+ type: i0.Input,
4949
+ args: [{
4950
+ isSignal: true,
4951
+ alias: "showWordCount",
4952
+ required: false
4953
+ }]
4954
+ }],
3797
4955
  touch: [{
3798
4956
  type: i0.Output,
3799
4957
  args: ["touch"]
@@ -3831,6 +4989,6 @@ i0.ɵɵngDeclareClassMetadata({
3831
4989
  }]
3832
4990
  }
3833
4991
  });
3834
- export { EDITOR_DEFAULT_MESSAGES, EditorComponent };
4992
+ export { EDITOR_DEFAULT_MESSAGES, EditorComponent, countEditorText };
3835
4993
 
3836
4994
  //# sourceMappingURL=nanahoshi-mona-ui-editor.mjs.map