@nanahoshi/mona-ui 0.36.1 → 0.38.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 (91) hide show
  1. package/docs/api/common.md +1 -1
  2. package/docs/api/dropdown-list.md +2 -0
  3. package/docs/api/dropdown-tree.md +81 -0
  4. package/docs/api/dropdowns.md +34 -8
  5. package/docs/api/editor.md +67 -0
  6. package/docs/api/file-upload.md +1 -1
  7. package/docs/api/i18n.md +49 -4
  8. package/docs/api/list.md +1 -1
  9. package/docs/api/locales.md +14 -14
  10. package/docs/api/multi-select-tree.md +75 -0
  11. package/docs/api/multi-select.md +3 -1
  12. package/docs/api/popup.md +1 -1
  13. package/docs/api/tree-view.md +2 -2
  14. package/docs/auto-complete.md +2 -0
  15. package/docs/combo-box.md +2 -0
  16. package/docs/dropdown-list.md +52 -0
  17. package/docs/dropdown-tree.md +427 -0
  18. package/docs/editor.md +238 -9
  19. package/docs/multi-select-tree.md +353 -0
  20. package/docs/multi-select.md +6 -0
  21. package/dropdown-tree/package.json +4 -0
  22. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +40 -5
  23. package/fesm2022/nanahoshi-mona-ui-dropdown-tree.mjs +1061 -0
  24. package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +701 -60
  25. package/fesm2022/nanahoshi-mona-ui-editor.mjs +1356 -192
  26. package/fesm2022/nanahoshi-mona-ui-file-upload.mjs +28 -94
  27. package/fesm2022/nanahoshi-mona-ui-filter.mjs +2 -0
  28. package/fesm2022/nanahoshi-mona-ui-grid.mjs +2 -0
  29. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +63 -1
  30. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +80 -37
  31. package/fesm2022/nanahoshi-mona-ui-internal.mjs +83 -2
  32. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +66 -1
  33. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +30 -1
  34. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +42 -1
  35. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +42 -1
  36. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +24 -1
  37. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +42 -1
  38. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +24 -1
  39. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +24 -1
  40. package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +64 -1
  41. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +42 -1
  42. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +64 -1
  43. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +24 -1
  44. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +24 -1
  45. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +24 -1
  46. package/fesm2022/nanahoshi-mona-ui-multi-select-tree.mjs +1179 -0
  47. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +42 -7
  48. package/fesm2022/nanahoshi-mona-ui-pager.mjs +3 -1
  49. package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +2 -1
  50. package/i18n/catalogs/en-US.messages.json +26 -1
  51. package/llms.txt +7 -3
  52. package/locales/ar-sa/ar-sa.messages.json +26 -1
  53. package/locales/de-de/de-de.messages.json +26 -1
  54. package/locales/es-es/es-es.messages.json +26 -1
  55. package/locales/fr-fr/fr-fr.messages.json +26 -1
  56. package/locales/id-id/id-id.messages.json +26 -1
  57. package/locales/it-it/it-it.messages.json +26 -1
  58. package/locales/ja-jp/ja-jp.messages.json +26 -1
  59. package/locales/ko-kr/ko-kr.messages.json +26 -1
  60. package/locales/pl-pl/pl-pl.messages.json +26 -1
  61. package/locales/pt-br/pt-br.messages.json +26 -1
  62. package/locales/ru-ru/ru-ru.messages.json +26 -1
  63. package/locales/tr-tr/tr-tr.messages.json +26 -1
  64. package/locales/zh-cn/zh-cn.messages.json +26 -1
  65. package/locales/zh-tw/zh-tw.messages.json +26 -1
  66. package/multi-select-tree/package.json +4 -0
  67. package/package.json +9 -1
  68. package/types/nanahoshi-mona-ui-dropdown-list.d.ts +33 -5
  69. package/types/nanahoshi-mona-ui-dropdown-tree.d.ts +414 -0
  70. package/types/nanahoshi-mona-ui-dropdowns.d.ts +198 -8
  71. package/types/nanahoshi-mona-ui-editor.d.ts +124 -2
  72. package/types/nanahoshi-mona-ui-file-upload.d.ts +1 -0
  73. package/types/nanahoshi-mona-ui-i18n.d.ts +44 -0
  74. package/types/nanahoshi-mona-ui-internal-tree.d.ts +36 -0
  75. package/types/nanahoshi-mona-ui-internal.d.ts +37 -0
  76. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +25 -0
  77. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +25 -0
  78. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +25 -0
  79. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +25 -0
  80. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +25 -0
  81. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +25 -0
  82. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +25 -0
  83. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +25 -0
  84. package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +25 -0
  85. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +25 -0
  86. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +25 -0
  87. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +25 -0
  88. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +25 -0
  89. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +25 -0
  90. package/types/nanahoshi-mona-ui-multi-select-tree.d.ts +456 -0
  91. package/types/nanahoshi-mona-ui-multi-select.d.ts +43 -7
package/docs/editor.md CHANGED
@@ -16,13 +16,13 @@ Give it a name with a `<label>` and `aria-labelledby`, or with `aria-label`. A p
16
16
 
17
17
  Use Editor when people write formatted text: headings, lists, links, images and tables. For plain text, use `mona-text-area`.
18
18
 
19
- `@nanahoshi/mona-ui/editor` exports `EditorComponent`, the `EDITOR_DEFAULT_MESSAGES` catalog, and the `ContentChangeEvent` and `EditorSettings` types.
19
+ `@nanahoshi/mona-ui/editor` exports `EditorComponent`, the `EDITOR_DEFAULT_MESSAGES` catalog, the `countEditorText` function, and the `ContentChangeEvent`, `EditorMention`, `EditorMentionSearch`, `EditorSettings` and `EditorTextUnit` types.
20
20
 
21
21
  ## Import & Quick Start
22
22
 
23
23
  ```typescript
24
- import { EditorComponent } from "@nanahoshi/mona-ui/editor";
25
- import type { ContentChangeEvent, EditorSettings } from "@nanahoshi/mona-ui/editor";
24
+ import { countEditorText, EditorComponent } from "@nanahoshi/mona-ui/editor";
25
+ import type { ContentChangeEvent, EditorMention, EditorMentionSearch, EditorSettings } from "@nanahoshi/mona-ui/editor";
26
26
  ```
27
27
 
28
28
  ```html
@@ -159,6 +159,199 @@ export class EditorFormsExampleComponent {
159
159
  </div>
160
160
  ```
161
161
 
162
+ ### Image upload
163
+
164
+ `imageUpload` uploads an image file and returns its address, as a promise or an observable. It takes the same function as the file upload's `upload`. With it, images pasted or dropped into the content upload where they land, and the image tool's form takes a file as well as an address. `imageAccept` and `imageMaxFileSize` limit the files it takes.
165
+
166
+ `image-upload-example.component.ts`
167
+
168
+ ```typescript
169
+ import { Component, signal } from "@angular/core";
170
+ import { EditorComponent } from "@nanahoshi/mona-ui/editor";
171
+ import type { FileUploadHandler } from "@nanahoshi/mona-ui/file-upload";
172
+ import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
173
+
174
+ /**
175
+ * Stands in for a server: it takes about a second per image, and returns an address the page can show. A real server
176
+ * returns the address it stored the image at.
177
+ */
178
+ function simulatedImageServer(): FileUploadHandler {
179
+ return (file, { progress, signal }) =>
180
+ new Promise<string>((resolve, reject) => {
181
+ let step = 0;
182
+ const timer = setInterval(() => {
183
+ step++;
184
+ progress(step, 5);
185
+ if (step === 5) {
186
+ clearInterval(timer);
187
+ resolve(URL.createObjectURL(file));
188
+ }
189
+ }, 200);
190
+ signal.addEventListener("abort", () => {
191
+ clearInterval(timer);
192
+ reject(signal.reason);
193
+ });
194
+ });
195
+ }
196
+
197
+ @Component({
198
+ selector: "app-editor-image-upload-example",
199
+ imports: [EditorComponent, FormFieldComponent],
200
+ templateUrl: "./image-upload-example.component.html"
201
+ })
202
+ export class EditorImageUploadExampleComponent {
203
+ protected readonly maxFileSize = 2 * 1024 * 1024;
204
+ protected readonly notes = signal("<p>Paste a screenshot here.</p>");
205
+ protected readonly upload = simulatedImageServer();
206
+ }
207
+ ```
208
+
209
+ `image-upload-example.component.html`
210
+
211
+ ```html
212
+ <mona-form-field label="Release notes" hint="Paste or drop an image, or choose one in the image tool. Up to 2 MB.">
213
+ <mona-editor
214
+ class="h-64 w-full"
215
+ [imageMaxFileSize]="maxFileSize"
216
+ [imageUpload]="upload"
217
+ [settings]="{ table: false }"
218
+ [(value)]="notes" />
219
+ </mona-form-field>
220
+ ```
221
+
222
+ ### Counts and a character limit
223
+
224
+ `showWordCount` and `showCharacterCount` show counts under the content. `characterLimit` shows how many characters are left, then how many are too many. It doesn't stop typing or cut what's pasted, so in a form, check the limit with `countEditorText`, which counts the value as the editor does.
225
+
226
+ `character-limit-example.component.ts`
227
+
228
+ ```typescript
229
+ import { Component, signal } from "@angular/core";
230
+ import { form, FormField, submit, validate } from "@angular/forms/signals";
231
+ import { ButtonDirective } from "@nanahoshi/mona-ui/button";
232
+ import { countEditorText, EditorComponent } from "@nanahoshi/mona-ui/editor";
233
+ import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
234
+
235
+ const LIMIT = 140;
236
+
237
+ @Component({
238
+ selector: "app-editor-character-limit-example",
239
+ imports: [ButtonDirective, EditorComponent, FormField, FormFieldComponent],
240
+ templateUrl: "./character-limit-example.component.html"
241
+ })
242
+ export class EditorCharacterLimitExampleComponent {
243
+ readonly #model = signal({
244
+ post: "<p>The editor now uploads images, counts what you write, and offers mentions.</p>"
245
+ });
246
+ protected readonly limit = LIMIT;
247
+ protected readonly posted = signal(false);
248
+ protected readonly update = form(this.#model, path => {
249
+ // The editor shows the count and lets people type past it; the form keeps a long post from being sent.
250
+ validate(path.post, ({ value }) =>
251
+ countEditorText(value(), "characters") > LIMIT
252
+ ? { kind: "tooLong", message: `Keep the post to ${LIMIT} characters.` }
253
+ : undefined
254
+ );
255
+ });
256
+
257
+ protected onSubmit(event: Event): void {
258
+ event.preventDefault();
259
+ void submit(this.update, async () => {
260
+ this.posted.set(true);
261
+ });
262
+ }
263
+ }
264
+ ```
265
+
266
+ `character-limit-example.component.html`
267
+
268
+ ```html
269
+ <form class="flex flex-col gap-4" novalidate (submit)="onSubmit($event)">
270
+ <mona-form-field label="Status update">
271
+ <mona-editor
272
+ class="h-56 w-full"
273
+ showWordCount
274
+ [characterLimit]="limit"
275
+ [formField]="update.post"
276
+ [settings]="{ headings: false, image: false, table: false }" />
277
+ </mona-form-field>
278
+ <div class="flex items-center gap-3">
279
+ <button monaButton look="primary" type="submit">Post</button>
280
+ @if (posted()) {
281
+ <span class="text-sm" role="status">Posted.</span>
282
+ }
283
+ </div>
284
+ </form>
285
+ ```
286
+
287
+ ### Mentions
288
+
289
+ `mentionSearch` finds what to mention as `@` and a query are typed, such as people. It returns a list, a promise or an observable. A mention is kept in the HTML as `<span data-type="mention" data-id="…" data-label="…">@label</span>`, so your server can find who was mentioned by `data-id`.
290
+
291
+ `mentions-example.component.ts`
292
+
293
+ ```typescript
294
+ import { Component, computed, signal } from "@angular/core";
295
+ import { EditorComponent, type EditorMention, type EditorMentionSearch } from "@nanahoshi/mona-ui/editor";
296
+ import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
297
+
298
+ const TEAM: readonly EditorMention[] = [
299
+ { id: "u1", label: "Ana Lima" },
300
+ { id: "u2", label: "Bo Chen" },
301
+ { id: "u3", label: "Chidi Okafor" },
302
+ { id: "u4", label: "Dana Weiss" },
303
+ { id: "u5", label: "Emre Kaya" },
304
+ { id: "u6", label: "Fatima Zahra" },
305
+ { id: "u7", label: "Giulia Rossi" },
306
+ { id: "u8", label: "Hana Sato" }
307
+ ];
308
+
309
+ @Component({
310
+ selector: "app-editor-mentions-example",
311
+ imports: [EditorComponent, FormFieldComponent],
312
+ templateUrl: "./mentions-example.component.html"
313
+ })
314
+ export class EditorMentionsExampleComponent {
315
+ protected readonly comment = signal(
316
+ '<p>Thanks <span data-type="mention" data-id="u2" data-label="Bo Chen">@Bo Chen</span> for the review.</p>'
317
+ );
318
+
319
+ /** Who the comment mentions, from the `data-id` of each mention in its HTML. */
320
+ protected readonly mentioned = computed(() => {
321
+ const ids = new Set(Array.from(this.comment().matchAll(/data-id="([^"]*)"/gu), match => match[1]));
322
+ return TEAM.filter(person => ids.has(person.id)).map(person => person.label);
323
+ });
324
+
325
+ /** A search can return a promise or an observable too, such as a request to the server. */
326
+ protected readonly search: EditorMentionSearch = query => {
327
+ const text = query.toLocaleLowerCase();
328
+ return TEAM.filter(person => person.label.toLocaleLowerCase().includes(text)).slice(0, 6);
329
+ };
330
+ }
331
+ ```
332
+
333
+ `mentions-example.component.html`
334
+
335
+ ```html
336
+ <div class="flex flex-col gap-3">
337
+ <mona-form-field label="Comment" hint="Type @ and a name to mention someone.">
338
+ <mona-editor
339
+ class="h-56 w-full"
340
+ [mentionSearch]="search"
341
+ [settings]="{ image: false, table: false }"
342
+ [(value)]="comment" />
343
+ </mona-form-field>
344
+ <p class="text-sm text-muted-foreground">
345
+ Mentioned:
346
+ @for (name of mentioned(); track name) {
347
+ {{ name }}{{ $last ? "" : ", " }}
348
+ } @empty {
349
+ nobody
350
+ }
351
+ </p>
352
+ </div>
353
+ ```
354
+
162
355
  ## Behavior
163
356
 
164
357
  - The form inputs (`disabled`, `invalid`, `readonly`, `required`, `touched`) are set by the form when the editor is bound with `[formField]`.
@@ -168,7 +361,7 @@ export class EditorFormsExampleComponent {
168
361
 
169
362
  Every tool is on by default. Pass only what you want to change, as in the toolbar example.
170
363
 
171
- `alignment`, `blockquote`, `bold`, `code`, `fontColor`, `fontFamily`, `fontHighlight`, `fontSize`, `headings`, `history`, `horizontalRule`, `image`, `indent`, `italic`, `link`, `list`, `strikethrough`, `subscript`, `superscript`, `table`, `taskList` and `underline` are booleans. `code: false` also turns off the code block.
364
+ `alignment`, `blockquote`, `bold`, `code`, `fontColor`, `fontFamily`, `fontHighlight`, `fontSize`, `headings`, `history`, `horizontalRule`, `image`, `indent`, `italic`, `link`, `list`, `mention`, `strikethrough`, `subscript`, `superscript`, `table`, `taskList` and `underline` are booleans. `code: false` also turns off the code block, and `image: false` image upload. `mention` has no tool: it keeps the mentions of the content, and offers them as `@` is typed when `mentionSearch` is set. Without it, mentions stay as text.
172
365
 
173
366
  | Setting | Type | Default | Description |
174
367
  | :------------- | :----------------- | :------ | :--------------------------------------------------------------------------------------------------------------------- |
@@ -179,20 +372,49 @@ If you remove a tool, content that used it stays as text.
179
372
 
180
373
  The text color and highlight pickers show the color of the selection. They show none when the selected text has no color or several, so any color you pick applies to all of it.
181
374
 
375
+ ### Image Upload
376
+
377
+ - While an image uploads, a placeholder shows where it goes, with a preview and the progress. The placeholder isn't content: the value changes once the image is in.
378
+ - The image goes where it was pasted or dropped, even as text is typed or deleted next to it. If a deletion takes the placeholder with it, the image isn't added. The images of one paste or drop go in their order, whichever finishes first.
379
+ - The upload returns the image's address as a string. If it fails, or returns anything else, the placeholder goes and the editor says the image couldn't be uploaded.
380
+ - A paste that carries HTML too, such as an image copied from a web page, is pasted as it is, with the image's own address.
381
+ - A file larger than `imageMaxFileSize` isn't uploaded, and the editor says so.
382
+ - When the editor is destroyed, its uploads stop: the upload's `signal` is aborted.
383
+ - With an image selected, the image tool edits it: its address, alt text and size.
384
+
385
+ ### Counts
386
+
387
+ - Characters are counted as people see them: an emoji or a letter with an accent counts once. Markup, images and line breaks don't count, and a mention counts as its `@label`.
388
+ - Words are found by the rules of the library locale, so text without spaces, such as Japanese, counts its words.
389
+ - Over the limit, the editor shows as invalid, as it does with `invalid`.
390
+
391
+ ### Mentions
392
+
393
+ - The suggestions open for an `@` at the start of a line or after a space, so an email address doesn't open them, and not in code.
394
+ - Each change to the query searches again. A late result for an earlier query is dropped, and a failed search shows no matches.
395
+ - Escape closes the suggestions until a new `@` is typed. They close when the content loses focus too.
396
+ - A mention is one piece: Backspace removes it at once.
397
+
182
398
  ### Content and Safety
183
399
 
184
400
  The editor reads HTML through its schema, so tags and attributes it doesn't know are dropped. Links typed in the link dialog keep `http:`, `https:`, `mailto:`, `tel:` and relative URLs, get `https://` when they are a bare host, and are refused with any other scheme, such as `javascript:`.
185
401
 
402
+ An uploaded image's address goes in as the upload returns it.
403
+
186
404
  These checks protect the editor, not your application. The value is user-written HTML: sanitize it on the server before you store it, and again before you render it anywhere else.
187
405
 
188
406
  ### Localization and Direction
189
407
 
190
- Toolbar labels and the default content name come from the `editor` messages (`EDITOR_DEFAULT_MESSAGES`), and follow the library locale. In right-to-left, the toolbar order mirrors and start and end alignment follow the direction.
408
+ Toolbar labels, the default content name, the counts and what the editor announces come from the `editor` messages (`EDITOR_DEFAULT_MESSAGES`), and follow the library locale. In right-to-left, the toolbar order mirrors and start and end alignment follow the direction.
191
409
 
192
410
  ## Accessibility
193
411
 
194
412
  The content has `role="textbox"` with `aria-multiline`, its name, and `aria-disabled`, `aria-readonly`, `aria-required` and `aria-invalid` when they apply. Link an error message or hint with `aria-describedby`. The toolbar is named and its toggle buttons report `aria-pressed`.
195
413
 
414
+ - While an image uploads, its placeholder is an image named for it, such as "Uploading chart.png". The editor announces when an upload starts and when the image is in, fails or is too large.
415
+ - With `characterLimit`, the content is described by the limit too, after your own `aria-describedby`. Once typing stops for a second, the editor announces how many characters are left or too many, while the content has focus. The counts under the content aren't announced as they change.
416
+ - Focus stays in the content while mention suggestions show. The content has `aria-autocomplete="list"`, `aria-controls` for the list and `aria-activedescendant` for the highlighted suggestion, and how many suggestions there are is announced.
417
+
196
418
  ### Keyboard Navigation
197
419
 
198
420
  The toolbar is one Tab stop.
@@ -206,14 +428,18 @@ The toolbar is one Tab stop.
206
428
  | `Tab` | Elsewhere in the content | Leaves the editor. |
207
429
  | `Ctrl` + `]` / `Ctrl` + `[` | Content | Indents or outdents. Use `Cmd` on macOS. |
208
430
  | `Escape`, then `Tab` | List in the content | Leaves the editor, so the keyboard isn't stuck in a long list. |
431
+ | `ArrowDown` / `ArrowUp` | Mention suggestions | Moves the highlight, wrapping at the ends. |
432
+ | `Enter` / `Tab` | Mention suggestions | Puts the highlighted suggestion in, with a space after it. |
433
+ | `Escape` | Mention suggestions | Closes them until a new `@` is typed. |
209
434
 
210
435
  ## API
211
436
 
212
437
  Everything below is imported from `@nanahoshi/mona-ui/editor`. Each name links to its reference page, with every input, output, property and method.
213
438
 
214
- | Name | Kind |
215
- | --- | --- |
216
- | [`EditorComponent`](api/editor.md#editorcomponent) | Component |
439
+ | Name | Kind | Description |
440
+ | --- | --- | --- |
441
+ | [`EditorComponent`](api/editor.md#editorcomponent) | Component | |
442
+ | [`countEditorText`](api/editor.md#counteditortext) | Function | Counts the characters or words of the editor's HTML value, as the editor's own count does: the text people see, without the markup. |
217
443
 
218
444
  ### Types
219
445
 
@@ -221,6 +447,9 @@ Everything below is imported from `@nanahoshi/mona-ui/editor`. Each name links t
221
447
  | --- | --- | --- |
222
448
  | [`EDITOR_DEFAULT_MESSAGES`](api/editor.md#editor-default-messages) | Constant | |
223
449
  | [`ContentChangeEvent`](api/editor.md#contentchangeevent) | Interface | The content of the editor after a user change, emitted by `EditorComponent.update`. |
450
+ | [`EditorMention`](api/editor.md#editormention) | Interface | Someone, or something, the content can mention. |
224
451
  | [`EditorSettings`](api/editor.md#editorsettings) | Interface | The features of an editor. |
452
+ | [`EditorMentionSearch`](api/editor.md#editormentionsearch) | Type alias | Finds the mentions to offer for the text typed after `@`, which is empty right after the `@`. |
453
+ | [`EditorTextUnit`](api/editor.md#editortextunit) | Type alias | What `countEditorText` counts: characters as people see them, or words. |
225
454
 
226
- **Related types:** [`MonaEditorMessages`](api/i18n.md#monaeditormessages)
455
+ **Related types:** [`FileUploadHandler`](api/file-upload.md#fileuploadhandler), [`MonaEditorMessages`](api/i18n.md#monaeditormessages)
@@ -0,0 +1,353 @@
1
+ # Multi Select Tree
2
+
3
+ > A control that opens a tree with checkboxes and shows the checked items as removable tags.
4
+
5
+ Entry point: `@nanahoshi/mona-ui/multi-select-tree`
6
+
7
+ **Selector:** `mona-multi-select-tree`
8
+
9
+ `MultiSelectTreeComponent` is a combobox that opens a tree with checkboxes and shows the checked items as removable tags. Checking an item checks its children too, and an item whose children are all checked is checked itself, so a whole branch can be chosen at once.
10
+
11
+ ## Overview
12
+
13
+ Multi Select Tree renders a combobox whose popup is a tree with checkboxes. The checked items show as removable tags in the field, and the value lists them. The popup opens on click, `Enter`, `Space`, `ArrowDown` or `Alt+ArrowDown`, and stays open while items are checked.
14
+
15
+ Checking follows the tree:
16
+
17
+ - **`checkChildren`** (on by default): checking an item checks its children, and unchecking it unchecks them.
18
+ - **`checkParents`** (on by default): an item is checked when all its children are, and unchecked when one isn't. An item with some of its children checked shows a mixed checkbox.
19
+
20
+ The data takes the shapes of the [dropdown tree](dropdown-tree.md): hierarchical, with `children`, or flat, with `mode="flat"`, `idField` and `parentIdField`.
21
+
22
+ **Use Multi Select Tree when:**
23
+
24
+ - More than one item can be chosen from a hierarchy, such as permissions, regions or folders.
25
+
26
+ **Use `DropdownTree` instead when:**
27
+
28
+ - Exactly one item is chosen.
29
+
30
+ **Use `MultiSelect` instead when:**
31
+
32
+ - The options are a flat list.
33
+
34
+ ## Import & Quick Start
35
+
36
+ ```typescript
37
+ import { MultiSelectTreeComponent } from "@nanahoshi/mona-ui/multi-select-tree";
38
+ ```
39
+
40
+ ```typescript
41
+ protected readonly regions = [
42
+ {
43
+ code: "EU",
44
+ name: "Europe",
45
+ countries: [
46
+ { code: "DE", name: "Germany" },
47
+ { code: "FR", name: "France" }
48
+ ]
49
+ }
50
+ ];
51
+
52
+ protected readonly countries = signal<string[]>([]);
53
+ ```
54
+
55
+ ```html
56
+ <mona-form-field label="Ships to">
57
+ <mona-multi-select-tree
58
+ children="countries"
59
+ textField="name"
60
+ valueField="code"
61
+ [data]="regions"
62
+ [valuePrimitive]="true"
63
+ [(value)]="countries" />
64
+ </mona-form-field>
65
+ ```
66
+
67
+ ## Anatomy
68
+
69
+ Each template below is an `ng-template` placed inside `<mona-multi-select-tree>`.
70
+
71
+ | Directive | Selector | Template context | Replaces |
72
+ |------------------------------------------|--------------------------------------------------|------------------------------------------|-------------------------------------------------|
73
+ | `DropdownItemTemplateDirective` | `ng-template[monaMultiSelectTreeItemTemplate]` | `{ $implicit: TData }` (the node's item) | Each node's text in the popup |
74
+ | `MultiSelectTagTemplateDirective` | `ng-template[monaMultiSelectTagTemplate]` | `{ $implicit: TData }` (the tag's item) | Each tag's text |
75
+ | `MultiSelectSummaryTagTemplateDirective` | `ng-template[monaMultiSelectSummaryTagTemplate]` | `{ $implicit: value, tagCount: number }` | The summary tag's "+ n items" |
76
+ | `DropdownHeaderTemplateDirective` | `ng-template[monaMultiSelectTreeHeaderTemplate]` | None | No default; renders above the tree |
77
+ | `DropdownFooterTemplateDirective` | `ng-template[monaMultiSelectTreeFooterTemplate]` | None | No default; renders below the tree |
78
+ | `DropdownNoDataTemplateDirective` | `ng-template[monaMultiSelectTreeNoDataTemplate]` | None | "No data", or "No matching items" when filtered |
79
+ | `DropdownPrefixTemplateDirective` | `ng-template[monaDropdownPrefixTemplate]` | None | No default; renders before the tags |
80
+
81
+ The tag and summary tag directives, and `MultiSelectSummaryTagDirective`, come from `@nanahoshi/mona-ui/multi-select`, and the others from `@nanahoshi/mona-ui/dropdowns`. With a value whose items aren't loaded (and `valuePrimitive`), the tag template gets the value itself.
82
+
83
+ ## Examples
84
+
85
+ ### Granting permissions
86
+
87
+ Checking a group grants every permission in it, and a group whose permissions are all granted is checked itself. `monaMultiSelectSummaryTag` shows three tags and sums up the rest, and the filter box finds a permission by name. With `adaptiveMode="auto"`, the popup opens as a bottom sheet on a phone.
88
+
89
+ `permissions-example.component.ts`
90
+
91
+ ```typescript
92
+ import { Component, signal } from "@angular/core";
93
+ import { DropdownFilterableDirective } from "@nanahoshi/mona-ui/dropdowns";
94
+ import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
95
+ import { MultiSelectSummaryTagDirective } from "@nanahoshi/mona-ui/multi-select";
96
+ import { MultiSelectTreeComponent } from "@nanahoshi/mona-ui/multi-select-tree";
97
+
98
+ interface Permission {
99
+ readonly id: string;
100
+ readonly label: string;
101
+ readonly permissions?: readonly Permission[];
102
+ }
103
+
104
+ @Component({
105
+ selector: "app-multi-select-tree-permissions-example",
106
+ imports: [
107
+ DropdownFilterableDirective,
108
+ FormFieldComponent,
109
+ MultiSelectSummaryTagDirective,
110
+ MultiSelectTreeComponent
111
+ ],
112
+ templateUrl: "./permissions-example.component.html"
113
+ })
114
+ export class MultiSelectTreePermissionsExampleComponent {
115
+ protected readonly granted = signal<string[]>(["orders.view", "orders.refund"]);
116
+ protected readonly permissions: readonly Permission[] = [
117
+ {
118
+ id: "orders",
119
+ label: "Orders",
120
+ permissions: [
121
+ { id: "orders.view", label: "View orders" },
122
+ { id: "orders.edit", label: "Edit orders" },
123
+ { id: "orders.refund", label: "Issue refunds" }
124
+ ]
125
+ },
126
+ {
127
+ id: "products",
128
+ label: "Products",
129
+ permissions: [
130
+ { id: "products.view", label: "View products" },
131
+ { id: "products.edit", label: "Edit products" },
132
+ { id: "products.prices", label: "Change prices" }
133
+ ]
134
+ },
135
+ {
136
+ id: "team",
137
+ label: "Team",
138
+ permissions: [
139
+ { id: "team.invite", label: "Invite members" },
140
+ { id: "team.roles", label: "Change roles" }
141
+ ]
142
+ }
143
+ ];
144
+ }
145
+ ```
146
+
147
+ `permissions-example.component.html`
148
+
149
+ ```html
150
+ <div class="flex max-w-md flex-col gap-2">
151
+ <mona-form-field label="Permissions" hint="Checking a group grants everything in it.">
152
+ <mona-multi-select-tree
153
+ adaptiveMode="auto"
154
+ children="permissions"
155
+ monaDropDownFilterable
156
+ placeholder="Grant permissions"
157
+ textField="label"
158
+ valueField="id"
159
+ [data]="permissions"
160
+ [monaMultiSelectSummaryTag]="3"
161
+ [showClearButton]="true"
162
+ [valuePrimitive]="true"
163
+ [(value)]="granted" />
164
+ </mona-form-field>
165
+ <span class="text-sm">Granted: {{ granted().join(", ") || "nothing" }}</span>
166
+ </div>
167
+ ```
168
+
169
+ ### Signal Forms integration
170
+
171
+ A `minLength` rule on the field asks for at least one country, and the form field shows its message once the field is touched. With `checkParents` off, checking every country of a region leaves the region itself unchecked. Checking the region still checks its countries, and adds the region to the value too.
172
+
173
+ `forms-example.component.ts`
174
+
175
+ ```typescript
176
+ import { Component, signal } from "@angular/core";
177
+ import { form, FormField, minLength } from "@angular/forms/signals";
178
+ import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
179
+ import { MultiSelectTreeComponent } from "@nanahoshi/mona-ui/multi-select-tree";
180
+
181
+ interface Region {
182
+ readonly code: string;
183
+ readonly countries?: readonly Region[];
184
+ readonly name: string;
185
+ }
186
+
187
+ interface ShippingModel {
188
+ countries: string[];
189
+ }
190
+
191
+ @Component({
192
+ selector: "app-multi-select-tree-forms-example",
193
+ imports: [FormField, FormFieldComponent, MultiSelectTreeComponent],
194
+ templateUrl: "./forms-example.component.html"
195
+ })
196
+ export class MultiSelectTreeFormsExampleComponent {
197
+ readonly #model = signal<ShippingModel>({ countries: [] });
198
+ protected readonly regions: readonly Region[] = [
199
+ {
200
+ code: "EU",
201
+ name: "Europe",
202
+ countries: [
203
+ { code: "DE", name: "Germany" },
204
+ { code: "FR", name: "France" },
205
+ { code: "IT", name: "Italy" },
206
+ { code: "PL", name: "Poland" }
207
+ ]
208
+ },
209
+ {
210
+ code: "AS",
211
+ name: "Asia",
212
+ countries: [
213
+ { code: "JP", name: "Japan" },
214
+ { code: "KR", name: "South Korea" },
215
+ { code: "TR", name: "Türkiye" }
216
+ ]
217
+ }
218
+ ];
219
+ protected readonly shipping = form(this.#model, path => {
220
+ minLength(path.countries, 1, { message: "Choose at least one country." });
221
+ });
222
+ }
223
+ ```
224
+
225
+ `forms-example.component.html`
226
+
227
+ ```html
228
+ <mona-form-field class="max-w-md" label="Ships to" hint="Choose a region to ship to all its countries.">
229
+ <mona-multi-select-tree
230
+ children="countries"
231
+ textField="name"
232
+ valueField="code"
233
+ [checkParents]="false"
234
+ [data]="regions"
235
+ [formField]="shipping.countries"
236
+ [valuePrimitive]="true" />
237
+ </mona-form-field>
238
+ ```
239
+
240
+ ## Appearance & Styling
241
+
242
+ The multi-select tree has the sizes, corner roundings and states of the [multi-select](multi-select.md): `size` is `small`, `medium` (default) or `large`, and `rounded` is `none`, `small`, `medium` (default), `large` or `full`. The tags wrap onto more lines as items are checked, and the popup moves with the field's bottom edge.
243
+
244
+ | Input | What it does |
245
+ |-------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
246
+ | `popupHeight` | The popup's maximum height; 200 pixels when unset. Shorter trees shrink to fit. |
247
+ | `popupWidth` | The popup's width; the field's width when unset. |
248
+ | `popupClass` | Classes added to the popup. |
249
+ | `showClearButton` | A button in the field that unchecks every item. |
250
+ | `adaptiveMode` | `"auto"` opens the popup as a bottom sheet on a small screen, as described for the [dropdown tree](dropdown-tree.md#on-a-phone). |
251
+
252
+ ## Behavior
253
+
254
+ ### The value's order
255
+
256
+ A change the user makes lists the checked items in the tree's order. A value set from code keeps its own order until the next change, and a value item whose node isn't loaded yet stays in the value, after the loaded ones.
257
+
258
+ ### Tags
259
+
260
+ Each checked item has a tag. A tag's remove button unchecks its item as the tree does, so removing a group's tag unchecks the group's items with `checkChildren`. The summary tag's remove button unchecks only the items it stands for. `Backspace` in the field unchecks the item of the last tag.
261
+
262
+ ### Clicking a node checks it
263
+
264
+ A click anywhere on a node's row checks or unchecks it, as a click on its checkbox does, and the popup stays open. The arrow on a node opens and closes it. A disabled item (`itemDisabled`) can't be checked or opened, and checking its parent leaves it as it is.
265
+
266
+ ### Derived parents
267
+
268
+ With `checkParents`, an item whose children are all in a value set from code shows checked in the tree, but it joins the value only with the user's next change.
269
+
270
+ ### `open` and `close` are cancelable
271
+
272
+ `open` and `close` emit a `PreventableEvent`; calling `preventDefault()` keeps the popup as it is. `opened` and `closed` follow once it has opened or closed.
273
+
274
+ ## Forms Integration
275
+
276
+ The multi-select tree implements `FormValueControl<Iterable<TValue>>`, so `[formField]` binds it to a signal form field, which then sets `disabled`, `readonly`, `required`, `invalid` and `touched`. With `required`, it's invalid while nothing is checked. It also works with `[(ngModel)]` and reactive forms; a `null` value means nothing is checked.
277
+
278
+ ## Accessibility
279
+
280
+ ### Keyboard
281
+
282
+ | Key | When | Action |
283
+ |-----------------------------------------------------------|--------|---------------------------------------------------------------------------------|
284
+ | `Enter`, `Space`, `ArrowDown`, `ArrowUp`, `Alt+ArrowDown` | Closed | Opens the popup |
285
+ | `ArrowDown` / `ArrowUp` | Open | Moves to the next or previous visible node |
286
+ | `ArrowRight` | Open | Opens a closed node, or moves to its first child (`ArrowLeft` in right-to-left) |
287
+ | `ArrowLeft` | Open | Closes an open node, or moves to its parent (`ArrowRight` in right-to-left) |
288
+ | `Home` / `End` | Open | Moves to the first or last visible node |
289
+ | `*` | Open | Opens the active node's siblings |
290
+ | Letters and digits | Open | Moves to the next node whose text starts with them |
291
+ | `Enter` / `Space` | Open | Checks or unchecks the active node |
292
+ | `Backspace` | Any | Unchecks the item of the last tag |
293
+ | `Escape`, `Alt+ArrowUp` | Open | Closes the popup |
294
+ | `Tab` | Open | Closes the popup and moves focus on |
295
+
296
+ In the filter box, `ArrowDown`, `ArrowUp` and `Enter` work as above, and the other keys edit the text.
297
+
298
+ ### Focus
299
+
300
+ Focus stays on the field while the popup is open; the active node is shown with a focus ring and announced through `aria-activedescendant`. With a filter box, focus moves into it when the popup opens, and returns to the field when the popup closes. Tags and their remove buttons aren't Tab stops: `Backspace` removes tags from the keyboard.
301
+
302
+ ### ARIA
303
+
304
+ - The field has `role="combobox"`, `aria-haspopup="tree"`, `aria-expanded`, and `aria-controls` pointing at the tree. It's named by `aria-label`, `aria-labelledby`, a form field's label or, failing those, the placeholder.
305
+ - The popup's tree has `role="tree"` and the field's name. Its nodes are `treeitem`s with `aria-checked` (`mixed` for a partly checked parent), `aria-level`, `aria-setsize`, `aria-posinset` and `aria-expanded` on nodes with children. A disabled node has `aria-disabled`.
306
+ - Each tag's remove button is named "Remove" and the item's text, and the summary tag's "Remove n more items".
307
+ - The filter box is a combobox too, named "Filter" and the field's name. How many items match is announced as the filter changes.
308
+
309
+ ## API
310
+
311
+ Everything below is imported from `@nanahoshi/mona-ui/multi-select-tree`, unless a table names another entry point. Each name links to its reference page, with every input, output, property and method.
312
+
313
+ | Name | Kind |
314
+ | --- | --- |
315
+ | [`MultiSelectTreeComponent`](api/multi-select-tree.md#multiselecttreecomponent) | Component |
316
+
317
+ From `@nanahoshi/mona-ui/dropdowns`:
318
+
319
+ | Name | Kind |
320
+ | --- | --- |
321
+ | [`DropdownFilterableDirective`](api/dropdowns.md#dropdownfilterabledirective) | Directive |
322
+ | [`DropdownGroupableDirective`](api/dropdowns.md#dropdowngroupabledirective) | Directive |
323
+ | [`DropdownVirtualScrollDirective`](api/dropdowns.md#dropdownvirtualscrolldirective) | Directive |
324
+ | [`DropdownDataHandlerDirective`](api/dropdowns.md#dropdowndatahandlerdirective) | Directive |
325
+ | [`DropdownFooterTemplateDirective`](api/dropdowns.md#dropdownfootertemplatedirective) | Directive |
326
+ | [`DropdownGroupHeaderTemplateDirective`](api/dropdowns.md#dropdowngroupheadertemplatedirective) | Directive |
327
+ | [`DropdownHeaderTemplateDirective`](api/dropdowns.md#dropdownheadertemplatedirective) | Directive |
328
+ | [`DropdownItemTemplateDirective`](api/dropdowns.md#dropdownitemtemplatedirective) | Directive |
329
+ | [`DropdownListPopupHandlerDirective`](api/dropdowns.md#dropdownlistpopuphandlerdirective) | Directive |
330
+ | [`DropdownNoDataTemplateDirective`](api/dropdowns.md#dropdownnodatatemplatedirective) | Directive |
331
+ | [`DropdownPrefixTemplateDirective`](api/dropdowns.md#dropdownprefixtemplatedirective) | Directive |
332
+ | [`DropdownSuffixTemplateDirective`](api/dropdowns.md#dropdownsuffixtemplatedirective) | Directive |
333
+ | [`DropdownListService`](api/dropdowns.md#dropdownlistservice) | Service |
334
+
335
+ ### Types
336
+
337
+ | Type | Kind |
338
+ | --- | --- |
339
+ | [`MULTI_SELECT_TREE_DEFAULT_MESSAGES`](api/multi-select-tree.md#multi-select-tree-default-messages) | Constant |
340
+
341
+ From `@nanahoshi/mona-ui/dropdowns`:
342
+
343
+ | Type | Kind | Description |
344
+ | --- | --- | --- |
345
+ | [`DropdownDataInputToken`](api/dropdowns.md#dropdowndatainputtoken) | Constant | **Deprecated.** Use `DROPDOWN_DATA_INPUT_TOKEN`. |
346
+ | [`DROPDOWNS_DEFAULT_MESSAGES`](api/dropdowns.md#dropdowns-default-messages) | Constant | |
347
+ | [`DropdownDataInput`](api/dropdowns.md#dropdowndatainput) | Interface | |
348
+ | [`DropdownSheetData`](api/dropdowns.md#dropdownsheetdata) | Interface | What a dropdown passes to the bottom sheet its popup opens as. |
349
+ | [`AdaptiveMode`](api/dropdowns.md#adaptivemode) | Type alias | How a dropdown's popup adapts to a small screen: `"auto"` opens it as a sheet along the bottom of the screen when the screen is narrower than 640 pixels, and `"none"` always opens it under the field. |
350
+ | [`DropdownFieldPredicateType`](api/dropdowns.md#dropdownfieldpredicatetype) | Type alias | |
351
+ | [`DropdownFieldSelectorType`](api/dropdowns.md#dropdownfieldselectortype) | Type alias | |
352
+
353
+ **Related types:** [`ChildrenSelector`](api/tree-view.md#childrenselector), [`DataStructure`](api/tree-view.md#datastructure), [`FilterableOptions`](api/common.md#filterableoptions), [`FilterChangeEvent`](api/common.md#filterchangeevent), [`GroupableOptions`](api/grid.md#groupableoptions), [`ListItem`](api/list.md#listitem), [`ListSizeInputType`](api/list.md#listsizeinputtype), [`ListSizeType`](api/list.md#listsizetype), [`MonaDropdownsMessages`](api/i18n.md#monadropdownsmessages), [`MonaMultiSelectTreeMessages`](api/i18n.md#monamultiselecttreemessages), [`PopupCloseEvent`](api/popup.md#popupcloseevent), [`PreventableEvent`](api/common.md#preventableevent), [`VirtualScrollOptions`](api/common.md#virtualscrolloptions)