@@ -424,17 +424,7 @@ global.MonsieurBizRichEditorManager = class {
424424 ) {
425425 continue ;
426426 }
427- let append = true ;
428- if ( this . tags . length > 0 ) {
429- append = ! this . tagsAreExclusive ;
430- for ( let tagIndex in this . tags ) { // We proceed tag by tag, excluding and including for every tag, so the order matters!
431- let realTag = this . tags [ tagIndex ] . replace ( / ^ ( - | \+ ) / , '' ) ;
432- if ( 0 <= this . config . uielements [ elementCode ] . tags . indexOf ( realTag ) ) { // The element is tagged
433- append = ! this . tags [ tagIndex ] . startsWith ( '-' ) ; // Append only if the tag is not excluded
434- }
435- }
436- }
437- if ( append ) {
427+ if ( this . elementIsAllowed ( this . tags , this . config . uielements [ elementCode ] . tags , this . tagsAreExclusive ) ) {
438428 cardsContainer . append ( this . getNewUiElementCard ( this . config . uielements [ elementCode ] , position ) ) ;
439429 }
440430 }
@@ -696,12 +686,26 @@ global.MonsieurBizRichEditorManager = class {
696686 pasteUiElementsFromClipboard ( ) {
697687 const clipboard = window . localStorage . getItem ( 'monsieurBizRichEditorElementsClipboard' ) ;
698688 if ( clipboard !== null ) {
699- const pastedUiElement = JSON . parse ( clipboard ) ;
689+ const pastedUiElements = JSON . parse ( clipboard ) ;
690+ let allowed = true ;
691+ pastedUiElements . forEach ( ( pastedUiElement ) => {
692+ let uiElementCode = pastedUiElement . code ;
693+ if ( ! this . elementIsAllowed ( this . tags , this . config . uielements [ uiElementCode ] . tags , this . tagsAreExclusive ) ) {
694+ allowed = false ;
695+ return ;
696+ }
697+ } ) ;
698+
699+ // Show alert message if at least one element is not allowed
700+ if ( ! allowed ) {
701+ alert ( this . config . unallowedUiElementMessage ) ;
702+ return ;
703+ }
700704
701705 if ( this . uiElements . length > 0 ) {
702- this . loadUiConfirmationModal ( ( ) => { this . initUiElements ( pastedUiElement , ( ) => { this . write ( ) ; } ) } )
706+ this . loadUiConfirmationModal ( ( ) => { this . initUiElements ( pastedUiElements , ( ) => { this . write ( ) ; } ) } )
703707 } else {
704- this . initUiElements ( pastedUiElement , ( ) => { this . write ( ) ; } ) ;
708+ this . initUiElements ( pastedUiElements , ( ) => { this . write ( ) ; } ) ;
705709 }
706710 }
707711 }
@@ -730,13 +734,7 @@ global.MonsieurBizRichEditorManager = class {
730734 let uiElement = manager . config . findUiElementByCode ( pastedUiElement . code ) ;
731735 if ( null !== uiElement ) {
732736 if ( manager . tags . length > 0 ) {
733- let copy = false ;
734- for ( let tagIndex in manager . tags ) {
735- if ( 0 <= manager . config . uielements [ uiElement . code ] . tags . indexOf ( manager . tags [ tagIndex ] ) ) {
736- copy = true ;
737- }
738- }
739- if ( copy ) {
737+ if ( manager . elementIsAllowed ( manager . tags , manager . config . uielements [ uiElement . code ] . tags , manager . tagsAreExclusive ) ) {
740738 manager . create ( uiElement . code , pastedUiElement . data , elementHtml , futurePosition ) ;
741739 } else {
742740 alert ( manager . config . unallowedUiElementMessage ) ;
@@ -750,6 +748,21 @@ global.MonsieurBizRichEditorManager = class {
750748 }
751749 }
752750
751+ elementIsAllowed ( managerTags , elementTags , tagsAreExclusive ) {
752+ let allowed = true ;
753+ if ( managerTags . length > 0 ) {
754+ allowed = ! tagsAreExclusive ;
755+ for ( let tagIndex in managerTags ) { // We proceed tag by tag, excluding and including for every tag, so the order matters!
756+ let realTag = managerTags [ tagIndex ] . replace ( / ^ ( - | \+ ) / , '' ) ;
757+ if ( 0 <= elementTags . indexOf ( realTag ) ) { // The element is tagged
758+ allowed = ! managerTags [ tagIndex ] . startsWith ( '-' ) ; // Authorize only if the tag is not excluded
759+ }
760+ }
761+ }
762+
763+ return allowed ;
764+ }
765+
753766 dispatchInitFormEvent ( form , manager ) {
754767 document . dispatchEvent ( new CustomEvent ( 'monsieurBizRichEditorInitForm' , {
755768 'detail' : { 'form' : form , 'manager' : manager }
0 commit comments