1- import { ChangeDetectionStrategy , Component , effect , ElementRef , forwardRef , inject , input , OnDestroy , signal , viewChildren , ViewContainerRef } from '@angular/core' ;
1+ import { ChangeDetectionStrategy , Component , computed , effect , ElementRef , forwardRef , inject , input , OnDestroy , signal , viewChildren , ViewContainerRef } from '@angular/core' ;
22import { ChipComponent } from '@lucca-front/ng/chip' ;
3- import { intlInputOptions } from '@lucca-front/ng/core' ;
3+ import { intlInputOptions , isNotNil } from '@lucca-front/ng/core' ;
44import { $getNodeByKey , $getRoot , $getSelection , type Klass , type LexicalEditor , type LexicalNode , type NodeKey , SKIP_DOM_SELECTION_TAG } from 'lexical' ;
55import { INITIAL_UPDATE_TAG , RICH_TEXT_PLUGIN_COMPONENT , RichTextPluginComponent } from '../../rich-text-input.component' ;
66import { LU_RICH_TEXT_INPUT_TRANSLATIONS } from '../../rich-text-input.translate' ;
77import { $createTagNode , TagNode } from './tag-node' ;
88import type { Tag } from './tag.model' ;
9+ import { LuSimpleSelectInputComponent } from '@lucca-front/ng/simple-select' ;
10+ import { FilterPillComponent } from '@lucca-front/ng/filter-pills' ;
11+ import { LuOptionDirective , LuOptionGroupDirective } from '@lucca-front/ng/core-select' ;
12+ import { FormControl , ReactiveFormsModule } from '@angular/forms' ;
13+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
914
1015const areSetsEqual = ( a : Set < string > , b : Set < string > ) : boolean => a . size === b . size && [ ...a ] . every ( ( value ) => b . has ( value ) ) ;
1116
@@ -14,7 +19,7 @@ const areSetsEqual = (a: Set<string>, b: Set<string>): boolean => a.size === b.s
1419 changeDetection : ChangeDetectionStrategy . OnPush ,
1520 templateUrl : './tag.component.html' ,
1621 styleUrl : './tag.component.scss' ,
17- imports : [ ChipComponent ] ,
22+ imports : [ ChipComponent , LuSimpleSelectInputComponent , FilterPillComponent , LuOptionGroupDirective , LuOptionDirective , ReactiveFormsModule ] ,
1823 providers : [
1924 {
2025 provide : RICH_TEXT_PLUGIN_COMPONENT ,
@@ -31,6 +36,18 @@ export class RichTextPluginTagComponent implements RichTextPluginComponent, OnDe
3136 readonly focusIndex = signal < number > ( 0 ) ;
3237
3338 readonly focusableElements = viewChildren ( 'tagButton' , { read : ElementRef } ) ;
39+ readonly primaryTags = computed ( ( ) => this . tags ( ) . filter ( ( t ) => ! t . secondary ) ) ;
40+ readonly secondaryTags = computed ( ( ) => this . tags ( ) . filter ( ( t ) => t . secondary ) ) ;
41+ readonly filteredSecondaryTags = computed ( ( ) => {
42+ const search = this . #normalize( this . tagSearch ( ) ) ;
43+ return this . secondaryTags ( ) . filter ( ( t ) => {
44+ const description = t . description ? this . #normalize( t . description ) : '' ;
45+ return ! search || description . includes ( search ) ;
46+ } ) ;
47+ } ) ;
48+ readonly secondaryHasGroup = computed ( ( ) => this . secondaryTags ( ) . some ( ( s ) => isNotNil ( s . group ) ) ) ;
49+ readonly tagSearch = signal < string > ( '' ) ;
50+ readonly selectedTagControl = new FormControl < Tag | null > ( null ) ;
3451
3552 editor : LexicalEditor | null = null ;
3653
@@ -65,6 +82,13 @@ export class RichTextPluginTagComponent implements RichTextPluginComponent, OnDe
6582 { tag : [ SKIP_DOM_SELECTION_TAG , INITIAL_UPDATE_TAG ] } ,
6683 ) ;
6784 } ) ;
85+
86+ this . selectedTagControl . valueChanges . pipe ( takeUntilDestroyed ( ) ) . subscribe ( ( tag ) => {
87+ if ( tag ) {
88+ this . selectedTagControl . reset ( ) ;
89+ this . insertTag ( tag ) ;
90+ }
91+ } ) ;
6892 }
6993
7094 setEditorInstance ( editor : LexicalEditor ) : void {
@@ -127,4 +151,15 @@ export class RichTextPluginTagComponent implements RichTextPluginComponent, OnDe
127151 ngOnDestroy ( ) {
128152 this . #registeredCommands( ) ;
129153 }
154+
155+ groupByTagGroup ( tag : Tag ) {
156+ return tag . group ;
157+ }
158+
159+ #normalize( str : string ) : string {
160+ return str
161+ . normalize ( 'NFD' )
162+ . replace ( / \p{ Diacritic} / gu, '' )
163+ . toLowerCase ( ) ;
164+ }
130165}
0 commit comments