1 | /* |
2 | Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/ |
3 | |
4 | This program is free software; |
5 | you can redistribute it and/or modify it under the terms of the |
6 | GNU General Public License as published by the Free Software Foundation; |
7 | either version 3 of the License, or any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | /* |
19 | Changes: |
20 | - v4.0.0: |
21 | - created from v3.6.0 |
22 | Doc reviewed 202208 |
23 | */ |
24 | |
25 | import theHTMLSanitizer from '../../../core/htmlSanitizer/HTMLSanitizer.js'; |
26 | |
27 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
28 | /** |
29 | Simple container for buttons data of the NoteDialogToolbar |
30 | */ |
31 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
32 | |
33 | class EditionButtonData { |
34 | |
35 | /** |
36 | The text to be displayed on the button. Can be HTML |
37 | @type {String} |
38 | */ |
39 | |
40 | #title; |
41 | |
42 | /** |
43 | The text to be inserted before the cursor when clicking on the button |
44 | @type {String} |
45 | */ |
46 | |
47 | #htmlBefore; |
48 | |
49 | /** |
50 | The text to be inserted after the cursor when clicking on the button. Optional |
51 | @type {String} |
52 | */ |
53 | |
54 | #htmlAfter; |
55 | |
56 | /** |
57 | The constructor |
58 | @param {JsonObject} jsonEditionButton A json object with the data for the EditionButton |
59 | */ |
60 | |
61 | constructor ( jsonEditionButton ) { |
62 | Object.freeze ( this ); |
63 | if ( |
64 | 'string' !== typeof ( jsonEditionButton?.title ) |
65 | || |
66 | 'string' !== typeof ( jsonEditionButton?.htmlBefore ) |
67 | || |
68 | ( jsonEditionButton.htmlAfter && 'string' !== typeof ( jsonEditionButton.htmlAfter ) ) |
69 | ) { |
70 | throw new Error ( 'Invalid toolbar button' ); |
71 | } |
72 | let htmlString = ( jsonEditionButton.htmlBefore || '' ) + ( jsonEditionButton.htmlAfter || '' ); |
73 | let errorString = theHTMLSanitizer.sanitizeToHtmlString ( htmlString ).errorsString; |
74 | if ( '' === errorString ) { |
75 | this.#title = theHTMLSanitizer.sanitizeToHtmlString ( jsonEditionButton.title ).htmlString; |
76 | if ( '' === this.title ) { |
77 | this.title = '?'; |
78 | } |
79 | this.#htmlBefore = jsonEditionButton.htmlBefore || ''; |
80 | this.#htmlAfter = jsonEditionButton.htmlAfter || ''; |
81 | } |
82 | else { |
83 | throw new Error ( 'Invalid toolbar button : ' + htmlString + errorString ); |
84 | } |
85 | } |
86 | |
87 | /** |
88 | The text to be displayed on the button. Can be HTML |
89 | @type {String} |
90 | */ |
91 | |
92 | get title ( ) { return this.#title; } |
93 | |
94 | /** |
95 | The text to be inserted before the cursor when clicking on the button |
96 | @type {String} |
97 | */ |
98 | |
99 | get htmlBefore ( ) { return this.#htmlBefore; } |
100 | |
101 | /** |
102 | The text to be inserted after the cursor when clicking on the button. Optional |
103 | @type {String} |
104 | */ |
105 | |
106 | get htmlAfter ( ) { return this.#htmlAfter; } |
107 | } |
108 | export default EditionButtonData; |
109 | |
110 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
111 |