@flogeez/angular-tiptap-editor 0.2.6 → 0.2.7

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.
@@ -17,7 +17,7 @@ import { DecorationSet, Decoration } from '@tiptap/pm/view';
17
17
  import tippy from 'tippy.js';
18
18
  import { Plugin as Plugin$1, PluginKey as PluginKey$1 } from 'prosemirror-state';
19
19
  import { NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
20
- import { tap } from 'rxjs';
20
+ import { concat, defer, of, tap } from 'rxjs';
21
21
 
22
22
  const ResizableImage = Node.create({
23
23
  name: "resizableImage",
@@ -3615,66 +3615,32 @@ class AngularTiptapEditorComponent {
3615
3615
  // Computed pour les états de l'éditeur
3616
3616
  this.isEditorReady = computed(() => this.editor() !== null);
3617
3617
  // Computed pour la configuration de la toolbar
3618
- this.toolbarConfig = computed(() => {
3619
- const userConfig = this.toolbar();
3620
- // Si aucune configuration n'est fournie, utiliser la configuration par défaut
3621
- if (Object.keys(userConfig).length === 0) {
3622
- return DEFAULT_TOOLBAR_CONFIG;
3623
- }
3624
- // Sinon, utiliser uniquement la configuration fournie par l'utilisateur
3625
- return userConfig;
3626
- });
3618
+ this.toolbarConfig = computed(() => Object.keys(this.toolbar()).length === 0
3619
+ ? DEFAULT_TOOLBAR_CONFIG
3620
+ : this.toolbar());
3627
3621
  // Computed pour la configuration du bubble menu
3628
- this.bubbleMenuConfig = computed(() => {
3629
- const userConfig = this.bubbleMenu();
3630
- // Si aucune configuration n'est fournie, utiliser la configuration par défaut
3631
- if (Object.keys(userConfig).length === 0) {
3632
- return DEFAULT_BUBBLE_MENU_CONFIG;
3633
- }
3634
- // Sinon, fusionner avec la configuration par défaut
3635
- return {
3636
- ...DEFAULT_BUBBLE_MENU_CONFIG,
3637
- ...userConfig,
3638
- };
3639
- });
3622
+ this.bubbleMenuConfig = computed(() => Object.keys(this.bubbleMenu()).length === 0
3623
+ ? DEFAULT_BUBBLE_MENU_CONFIG
3624
+ : { ...DEFAULT_BUBBLE_MENU_CONFIG, ...this.bubbleMenu() });
3640
3625
  // Computed pour la configuration du bubble menu image
3641
- this.imageBubbleMenuConfig = computed(() => {
3642
- const userConfig = this.imageBubbleMenu();
3643
- // Si aucune configuration n'est fournie, utiliser la configuration par défaut
3644
- if (Object.keys(userConfig).length === 0) {
3645
- return DEFAULT_IMAGE_BUBBLE_MENU_CONFIG;
3646
- }
3647
- // Sinon, fusionner avec la configuration par défaut
3648
- return {
3649
- ...DEFAULT_IMAGE_BUBBLE_MENU_CONFIG,
3650
- ...userConfig,
3651
- };
3652
- });
3626
+ this.imageBubbleMenuConfig = computed(() => Object.keys(this.imageBubbleMenu()).length === 0
3627
+ ? DEFAULT_IMAGE_BUBBLE_MENU_CONFIG
3628
+ : { ...DEFAULT_IMAGE_BUBBLE_MENU_CONFIG, ...this.imageBubbleMenu() });
3653
3629
  // Computed pour la configuration de l'upload d'images
3654
- this.imageUploadConfig = computed(() => {
3655
- const userConfig = this.imageUpload();
3656
- return {
3657
- maxSize: 5,
3658
- maxWidth: 1920,
3659
- maxHeight: 1080,
3660
- allowedTypes: ["image/jpeg", "image/png", "image/gif", "image/webp"],
3661
- enableDragDrop: true,
3662
- showPreview: true,
3663
- multiple: false,
3664
- compressImages: true,
3665
- quality: 0.8,
3666
- ...userConfig,
3667
- };
3668
- });
3630
+ this.imageUploadConfig = computed(() => ({
3631
+ maxSize: 5,
3632
+ maxWidth: 1920,
3633
+ maxHeight: 1080,
3634
+ allowedTypes: ["image/jpeg", "image/png", "image/gif", "image/webp"],
3635
+ enableDragDrop: true,
3636
+ showPreview: true,
3637
+ multiple: false,
3638
+ compressImages: true,
3639
+ quality: 0.8,
3640
+ ...this.imageUpload(),
3641
+ }));
3669
3642
  // Computed pour la configuration des slash commands
3670
- this.slashCommandsConfigComputed = computed(() => {
3671
- const userConfig = this.slashCommandsConfig();
3672
- if (userConfig) {
3673
- return userConfig;
3674
- }
3675
- // Configuration par défaut si aucune n'est fournie
3676
- return { commands: undefined }; // Le composant utilisera DEFAULT_SLASH_COMMANDS
3677
- });
3643
+ this.slashCommandsConfigComputed = computed(() => this.slashCommandsConfig() ?? { commands: undefined });
3678
3644
  this._destroyRef = inject(DestroyRef);
3679
3645
  // NgControl pour gérer les FormControls
3680
3646
  this.ngControl = inject(NgControl, { self: true, optional: true });
@@ -3691,7 +3657,12 @@ class AngularTiptapEditorComponent {
3691
3657
  effect(() => {
3692
3658
  const editor = this.editor();
3693
3659
  const content = this.content();
3660
+ const hasFormControl = !!this.ngControl?.control;
3661
+ // Ne pas écraser le contenu si on a un FormControl et que le content est vide
3694
3662
  if (editor && content !== undefined && content !== editor.getHTML()) {
3663
+ if (hasFormControl && !content) {
3664
+ return;
3665
+ }
3695
3666
  this.setContent(content, false);
3696
3667
  }
3697
3668
  });
@@ -3823,11 +3794,6 @@ class AngularTiptapEditorComponent {
3823
3794
  });
3824
3795
  // Stocker la référence de l'éditeur immédiatement
3825
3796
  this.editor.set(newEditor);
3826
- // Vérifier si on a un contenu initial via l'input content()
3827
- const initialContent = this.content();
3828
- if (initialContent) {
3829
- this.setContent(initialContent, false);
3830
- }
3831
3797
  }
3832
3798
  updateCharacterCount(editor) {
3833
3799
  if (this.showCharacterCount() && editor.storage["characterCount"]) {
@@ -3916,30 +3882,14 @@ class AngularTiptapEditorComponent {
3916
3882
  clearContent() {
3917
3883
  this.editor()?.commands.clearContent();
3918
3884
  }
3919
- normalizeHTML(html) {
3920
- if (!html)
3921
- return "";
3922
- // Normaliser les espaces et retours à la ligne pour une comparaison fiable
3923
- return html
3924
- .replace(/\s+/g, " ") // Remplacer espaces multiples par un seul
3925
- .replace(/>\s+</g, "><") // Supprimer espaces entre balises
3926
- .replace(/<br\s*\/?>/gi, "<br>") // Normaliser les <br>
3927
- .trim();
3928
- }
3929
- checkInitialFormValue() {
3930
- // Vérifier si on a une valeur initiale dans le FormControl
3931
- if (this.ngControl?.control?.value) {
3932
- console.log("Found initial FormControl value:", this.ngControl.control.value);
3933
- this.setContent(this.ngControl.control.value, false);
3934
- }
3935
- }
3936
3885
  setupFormControlSubscription() {
3937
3886
  const control = this.ngControl?.control;
3938
3887
  if (control) {
3939
- control.valueChanges
3888
+ const formValue$ = concat(defer(() => of(control.value)), control.valueChanges);
3889
+ formValue$
3940
3890
  .pipe(tap((value) => {
3941
3891
  const editor = this.editor();
3942
- if (editor && value !== editor.getHTML()) {
3892
+ if (editor) {
3943
3893
  this.setContent(value, false);
3944
3894
  }
3945
3895
  }), takeUntilDestroyed(this._destroyRef))