fhdp-extenders 4.10.6-SNAPSHOT-1696607426403 → 4.10.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.
@@ -1,312 +1,312 @@
1
- import {FhContainer, FHML,} from "fh-forms-handler";
2
- import {EVENTS_LIST} from "../constants";
3
- import {Portal} from './PortalProcessHandler';
4
-
5
- type TagMetaType = {
6
- tag: string,
7
- tagConstructor: (...args:any[]) => string,
8
- attr?: any,
9
- noContent?: boolean
10
- };
11
-
12
- const meta: TagMetaType[] = [
13
- {
14
- tag: 'br/',
15
- tagConstructor: (match, contents) => {
16
- var br = document.createElement('br');
17
- return br.outerHTML;
18
- },
19
- noContent: true
20
- },
21
- {
22
- tag: 'className',
23
- tagConstructor: (match, classes, contents) => {
24
- var span = document.createElement('span');
25
- span.classList.add('fhml');
26
- classes.split(',').forEach((cssClass) => {
27
- span.classList.add(cssClass);
28
- });
29
- span.innerHTML = contents;
30
- return span.outerHTML;
31
- },
32
- attr: '([a-zA-Z0-9\-\, ]+)'
33
- },
34
- {
35
- tag: 'del',
36
- tagConstructor: (match, contents) => {
37
- var del = document.createElement('del');
38
- del.innerHTML = contents;
39
- return del.outerHTML;
40
- },
41
- noContent: false
42
- },
43
- {
44
- tag: 's',
45
- tagConstructor: (match, contents) => {
46
- var del = document.createElement('del');
47
- del.innerHTML = contents;
48
- return del.outerHTML;
49
- },
50
- noContent: false
51
- },
52
- {
53
- tag: 'mark',
54
- tagConstructor: (match, contents) => {
55
- var mark = document.createElement('mark');
56
- mark.innerHTML = contents;
57
- return mark.outerHTML;
58
- },
59
- noContent: false
60
- },
61
- {
62
- tag: 'blockquote',
63
- tagConstructor: (match, contents) => {
64
- var blockquote = document.createElement('blockquote');
65
- blockquote.classList.add('blockquote')
66
- blockquote.innerHTML = contents;
67
- return blockquote.outerHTML;
68
- },
69
- noContent: false
70
- },
71
- {
72
- tag: 'q',
73
- tagConstructor: (match, contents) => {
74
- var blockquote = document.createElement('blockquote');
75
- blockquote.classList.add('blockquote')
76
- blockquote.innerHTML = contents;
77
- return blockquote.outerHTML;
78
- },
79
- noContent: false
80
- },
81
- {
82
- tag: 'bqFooter',
83
- tagConstructor: (match, contents) => {
84
- var blockquote = document.createElement('footer');
85
- blockquote.classList.add('blockquote-footer')
86
- blockquote.innerHTML = contents;
87
- return blockquote.outerHTML;
88
- },
89
- noContent: false
90
- },
91
- {
92
- tag: 'ul',
93
- tagConstructor: (match, contents) => {
94
- var ul = document.createElement('ul');
95
- ul.innerHTML = contents;
96
- return ul.outerHTML;
97
- },
98
- noContent: false
99
- },
100
- {
101
- tag: 'li',
102
- tagConstructor: (match, contents) => {
103
- var li = document.createElement('li');
104
- li.innerHTML = contents;
105
- return li.outerHTML;
106
- },
107
- noContent: false
108
- },
109
- {
110
- tag: 'code',
111
- tagConstructor: (match, contents) => {
112
- const fhml = FhContainer.get<FHML>('FHML');
113
- var span = document.createElement('span');
114
- span.classList.add('highlight');
115
- span.style.background = '#dcdce5';
116
- span.style.padding = '5px';
117
- span.style.display = 'inline-block'
118
- span.innerHTML = '<pre><code>' + contents + '</code></pre>';
119
- return span.outerHTML;
120
- },
121
- noContent: false
122
- },
123
- {
124
- tag: 'portal',
125
- tagConstructor: (match, attr) => {
126
- console.warn('THIS PORTAL TAG IS DEPRECATED. PLEASE USE fhportal!');
127
- const attrList = attr.split(',');
128
- const idPart = attrList[0];
129
- const portalId = document.querySelectorAll(`[id^='${idPart}']`)[0].id;
130
- const portalElement = document.getElementById(portalId);
131
- const parentPortalElement = (portalElement.parentNode as HTMLElement);
132
- parentPortalElement.style.display = "none";
133
- const newElement = (portalElement.cloneNode(true) as HTMLElement);
134
- newElement.id = `${portalElement.id}_portal`;
135
-
136
- EVENTS_LIST.forEach(el => {
137
- newElement.setAttribute(`on${el}`, `document.getElementById("${portalElement.id}").${el}();`);
138
- })
139
-
140
- if(attrList.length > 1) {
141
- const stylesList: string[] = attrList[1].split(' ');
142
- stylesList.forEach(styleName => {
143
- newElement.classList.add(styleName);
144
- });
145
- }
146
-
147
- return newElement.outerHTML;
148
- },
149
- attr: '([a-zA-Z0-9\-\, ]+)',
150
- noContent: true
151
- },
152
- {
153
- tag: 'fhportal',
154
- tagConstructor: (match, attr) => {
155
- new Portal();
156
- try {
157
- const parseAttr = (attr: string): {v?:string, layer?: string, wrapped?: string, id? : string, classes? : string, replaceParentId?: string, removeWrapper?: string, searchParent?: string, searchClosestLike?: string} => {
158
- console.log(attr);
159
- const res = {};
160
- const variables = attr.split(';');
161
- for (const variable of variables) {
162
- let [key, value] = variable.split('=')
163
- if (value[0] === '[' && value[value.length - 1] === ']') {
164
- value = value.substr(1);
165
- value = value.substr(0, value.length - 1);
166
- }
167
- if (['id', 'classes', 'wrapped', 'layer', 'v', 'searchClosestLike', 'searchParent', 'replaceParentId', 'removeWrapper'].indexOf(key) > -1) {
168
- res[key] = value
169
- }
170
- }
171
- return res;
172
- }
173
- const meta = parseAttr(attr)
174
- const portal = document.createElement('fh-portal')
175
- portal.setAttribute('used', 'false');
176
- if (meta.id) {
177
- portal.setAttribute('objId', meta.id);
178
- } else {
179
- return '<div>NO fhportal ID!</div>'
180
- }
181
- if (meta.searchClosestLike) {
182
- portal.setAttribute('searchClosestLike', meta.searchClosestLike);
183
- }
184
- if (meta.searchParent) {
185
- portal.setAttribute('searchParent', meta.searchParent);
186
- }
187
- if (meta.classes) {
188
- portal.setAttribute('classes', meta.classes);
189
- }
190
- if (meta.wrapped) {
191
- portal.setAttribute('wrapped', meta.wrapped);
192
- }
193
- if (meta.layer) {
194
- portal.setAttribute('layer', meta.layer);
195
- }
196
- if (meta.v) {
197
- portal.setAttribute('v', meta.v);
198
- }
199
- if(meta.replaceParentId) {
200
- portal.setAttribute('replaceParentId', meta.replaceParentId)
201
- }
202
- if(meta.removeWrapper) {
203
- portal.setAttribute('removeWrapper', meta.removeWrapper)
204
- }
205
- return portal.outerHTML;
206
- } catch (e) {
207
- console.error(e.message);
208
- return '<div>Error portal</div>'
209
- }
210
- },
211
- attr: '(.+)',
212
- noContent: true
213
- },
214
- {
215
- tag: 'nbsp',
216
- tagConstructor: (match, attr) => {
217
- const repTime = Number(attr);
218
- if (!isNaN(repTime)) {
219
- var span = document.createElement('span');
220
- span.style.paddingLeft = `${repTime}em`;
221
- return span.outerHTML;
222
- }
223
- return '';
224
- },
225
- attr: '([a-zA-Z0-9\-\, ]+)',
226
- noContent: true
227
- },
228
- {
229
- tag: 'unescape',
230
- tagConstructor: (match, attr) => {
231
- const code = String(attr);
232
- const span = document.createElement('span');
233
- span.innerHTML += `&#${code};`;
234
- return span.outerHTML;
235
- },
236
- attr: '([a-zA-Z0-9\-\, ]+)',
237
- noContent: true
238
- },
239
- {
240
- tag: 'ahref',
241
- tagConstructor: (match, attr, contents) => {
242
- try {
243
- const parseAttr = (attr: string): {href?:string, alt?: string, target?: string} => {
244
- const res = {};
245
- const variables = attr.split(';');
246
- for (const variable of variables) {
247
- let [key, value] = variable.split('=')
248
- if (value[0] === '[' && value[value.length - 1] === ']') {
249
- value = value.substr(1);
250
- value = value.substr(0, value.length - 1);
251
- }
252
- if (['href', 'alt', 'target'].indexOf(key) > -1) {
253
- res[key] = value
254
- }
255
- }
256
- return res;
257
- }
258
-
259
- const meta = parseAttr(attr)
260
- const aElement = document.createElement('a');
261
-
262
- if (meta.href) {
263
- aElement.href = meta.href;
264
- }
265
- if (meta.alt) {
266
- aElement.setAttribute('alt', meta.alt);
267
- }
268
- if (meta.target) {
269
- aElement.setAttribute('target', meta.target);
270
- }
271
- if (!!contents) {
272
- aElement.innerHTML = contents;
273
- }
274
- return aElement.outerHTML;
275
- } catch (e) {
276
- console.error(e.message);
277
- return ''
278
- }
279
- },
280
- attr: '(.+)',
281
- noContent: false
282
- },
283
- {
284
- tag: 'extAttributes/',
285
- tagConstructor: (match, contents) => {
286
- return '';
287
- },
288
- noContent: true
289
- },
290
- ]
291
-
292
- function registerTags(tagsMeta: TagMetaType[]) {
293
- const fhml = FhContainer.get<FHML>('FHML');
294
- const oldParse = fhml.needParse.bind(fhml);
295
- fhml.needParse = function(str) {
296
- var regexString = '\\[(';
297
- regexString += meta.map(function (tag) {
298
- return tag.tag;
299
- }).join('|');
300
- regexString += ')[=a-zA-Z0-9 #,\.\(\)\'\-\_.*]*\\]';
301
- var res = (str || '').match(new RegExp(regexString));
302
-
303
- return (res && typeof res === 'object') ? !!res.length : oldParse(str);
304
- };
305
- for (const tagMeta of tagsMeta) {
306
- fhml.registerTag(tagMeta.tag, tagMeta.tagConstructor, tagMeta.attr, tagMeta.noContent);
307
- }
308
- }
309
-
310
- export const extendFHML = (): void => {
311
- registerTags(meta)
1
+ import {FhContainer, FHML,} from "fh-forms-handler";
2
+ import {EVENTS_LIST} from "../constants";
3
+ import {Portal} from './PortalProcessHandler';
4
+
5
+ type TagMetaType = {
6
+ tag: string,
7
+ tagConstructor: (...args:any[]) => string,
8
+ attr?: any,
9
+ noContent?: boolean
10
+ };
11
+
12
+ const meta: TagMetaType[] = [
13
+ {
14
+ tag: 'br/',
15
+ tagConstructor: (match, contents) => {
16
+ var br = document.createElement('br');
17
+ return br.outerHTML;
18
+ },
19
+ noContent: true
20
+ },
21
+ {
22
+ tag: 'className',
23
+ tagConstructor: (match, classes, contents) => {
24
+ var span = document.createElement('span');
25
+ span.classList.add('fhml');
26
+ classes.split(',').forEach((cssClass) => {
27
+ span.classList.add(cssClass);
28
+ });
29
+ span.innerHTML = contents;
30
+ return span.outerHTML;
31
+ },
32
+ attr: '([a-zA-Z0-9\-\, ]+)'
33
+ },
34
+ {
35
+ tag: 'del',
36
+ tagConstructor: (match, contents) => {
37
+ var del = document.createElement('del');
38
+ del.innerHTML = contents;
39
+ return del.outerHTML;
40
+ },
41
+ noContent: false
42
+ },
43
+ {
44
+ tag: 's',
45
+ tagConstructor: (match, contents) => {
46
+ var del = document.createElement('del');
47
+ del.innerHTML = contents;
48
+ return del.outerHTML;
49
+ },
50
+ noContent: false
51
+ },
52
+ {
53
+ tag: 'mark',
54
+ tagConstructor: (match, contents) => {
55
+ var mark = document.createElement('mark');
56
+ mark.innerHTML = contents;
57
+ return mark.outerHTML;
58
+ },
59
+ noContent: false
60
+ },
61
+ {
62
+ tag: 'blockquote',
63
+ tagConstructor: (match, contents) => {
64
+ var blockquote = document.createElement('blockquote');
65
+ blockquote.classList.add('blockquote')
66
+ blockquote.innerHTML = contents;
67
+ return blockquote.outerHTML;
68
+ },
69
+ noContent: false
70
+ },
71
+ {
72
+ tag: 'q',
73
+ tagConstructor: (match, contents) => {
74
+ var blockquote = document.createElement('blockquote');
75
+ blockquote.classList.add('blockquote')
76
+ blockquote.innerHTML = contents;
77
+ return blockquote.outerHTML;
78
+ },
79
+ noContent: false
80
+ },
81
+ {
82
+ tag: 'bqFooter',
83
+ tagConstructor: (match, contents) => {
84
+ var blockquote = document.createElement('footer');
85
+ blockquote.classList.add('blockquote-footer')
86
+ blockquote.innerHTML = contents;
87
+ return blockquote.outerHTML;
88
+ },
89
+ noContent: false
90
+ },
91
+ {
92
+ tag: 'ul',
93
+ tagConstructor: (match, contents) => {
94
+ var ul = document.createElement('ul');
95
+ ul.innerHTML = contents;
96
+ return ul.outerHTML;
97
+ },
98
+ noContent: false
99
+ },
100
+ {
101
+ tag: 'li',
102
+ tagConstructor: (match, contents) => {
103
+ var li = document.createElement('li');
104
+ li.innerHTML = contents;
105
+ return li.outerHTML;
106
+ },
107
+ noContent: false
108
+ },
109
+ {
110
+ tag: 'code',
111
+ tagConstructor: (match, contents) => {
112
+ const fhml = FhContainer.get<FHML>('FHML');
113
+ var span = document.createElement('span');
114
+ span.classList.add('highlight');
115
+ span.style.background = '#dcdce5';
116
+ span.style.padding = '5px';
117
+ span.style.display = 'inline-block'
118
+ span.innerHTML = '<pre><code>' + contents + '</code></pre>';
119
+ return span.outerHTML;
120
+ },
121
+ noContent: false
122
+ },
123
+ {
124
+ tag: 'portal',
125
+ tagConstructor: (match, attr) => {
126
+ console.warn('THIS PORTAL TAG IS DEPRECATED. PLEASE USE fhportal!');
127
+ const attrList = attr.split(',');
128
+ const idPart = attrList[0];
129
+ const portalId = document.querySelectorAll(`[id^='${idPart}']`)[0].id;
130
+ const portalElement = document.getElementById(portalId);
131
+ const parentPortalElement = (portalElement.parentNode as HTMLElement);
132
+ parentPortalElement.style.display = "none";
133
+ const newElement = (portalElement.cloneNode(true) as HTMLElement);
134
+ newElement.id = `${portalElement.id}_portal`;
135
+
136
+ EVENTS_LIST.forEach(el => {
137
+ newElement.setAttribute(`on${el}`, `document.getElementById("${portalElement.id}").${el}();`);
138
+ })
139
+
140
+ if(attrList.length > 1) {
141
+ const stylesList: string[] = attrList[1].split(' ');
142
+ stylesList.forEach(styleName => {
143
+ newElement.classList.add(styleName);
144
+ });
145
+ }
146
+
147
+ return newElement.outerHTML;
148
+ },
149
+ attr: '([a-zA-Z0-9\-\, ]+)',
150
+ noContent: true
151
+ },
152
+ {
153
+ tag: 'fhportal',
154
+ tagConstructor: (match, attr) => {
155
+ new Portal();
156
+ try {
157
+ const parseAttr = (attr: string): {v?:string, layer?: string, wrapped?: string, id? : string, classes? : string, replaceParentId?: string, removeWrapper?: string, searchParent?: string, searchClosestLike?: string} => {
158
+ console.log(attr);
159
+ const res = {};
160
+ const variables = attr.split(';');
161
+ for (const variable of variables) {
162
+ let [key, value] = variable.split('=')
163
+ if (value[0] === '[' && value[value.length - 1] === ']') {
164
+ value = value.substr(1);
165
+ value = value.substr(0, value.length - 1);
166
+ }
167
+ if (['id', 'classes', 'wrapped', 'layer', 'v', 'searchClosestLike', 'searchParent', 'replaceParentId', 'removeWrapper'].indexOf(key) > -1) {
168
+ res[key] = value
169
+ }
170
+ }
171
+ return res;
172
+ }
173
+ const meta = parseAttr(attr)
174
+ const portal = document.createElement('fh-portal')
175
+ portal.setAttribute('used', 'false');
176
+ if (meta.id) {
177
+ portal.setAttribute('objId', meta.id);
178
+ } else {
179
+ return '<div>NO fhportal ID!</div>'
180
+ }
181
+ if (meta.searchClosestLike) {
182
+ portal.setAttribute('searchClosestLike', meta.searchClosestLike);
183
+ }
184
+ if (meta.searchParent) {
185
+ portal.setAttribute('searchParent', meta.searchParent);
186
+ }
187
+ if (meta.classes) {
188
+ portal.setAttribute('classes', meta.classes);
189
+ }
190
+ if (meta.wrapped) {
191
+ portal.setAttribute('wrapped', meta.wrapped);
192
+ }
193
+ if (meta.layer) {
194
+ portal.setAttribute('layer', meta.layer);
195
+ }
196
+ if (meta.v) {
197
+ portal.setAttribute('v', meta.v);
198
+ }
199
+ if(meta.replaceParentId) {
200
+ portal.setAttribute('replaceParentId', meta.replaceParentId)
201
+ }
202
+ if(meta.removeWrapper) {
203
+ portal.setAttribute('removeWrapper', meta.removeWrapper)
204
+ }
205
+ return portal.outerHTML;
206
+ } catch (e) {
207
+ console.error(e.message);
208
+ return '<div>Error portal</div>'
209
+ }
210
+ },
211
+ attr: '(.+)',
212
+ noContent: true
213
+ },
214
+ {
215
+ tag: 'nbsp',
216
+ tagConstructor: (match, attr) => {
217
+ const repTime = Number(attr);
218
+ if (!isNaN(repTime)) {
219
+ var span = document.createElement('span');
220
+ span.style.paddingLeft = `${repTime}em`;
221
+ return span.outerHTML;
222
+ }
223
+ return '';
224
+ },
225
+ attr: '([a-zA-Z0-9\-\, ]+)',
226
+ noContent: true
227
+ },
228
+ {
229
+ tag: 'unescape',
230
+ tagConstructor: (match, attr) => {
231
+ const code = String(attr);
232
+ const span = document.createElement('span');
233
+ span.innerHTML += `&#${code};`;
234
+ return span.outerHTML;
235
+ },
236
+ attr: '([a-zA-Z0-9\-\, ]+)',
237
+ noContent: true
238
+ },
239
+ {
240
+ tag: 'ahref',
241
+ tagConstructor: (match, attr, contents) => {
242
+ try {
243
+ const parseAttr = (attr: string): {href?:string, alt?: string, target?: string} => {
244
+ const res = {};
245
+ const variables = attr.split(';');
246
+ for (const variable of variables) {
247
+ let [key, value] = variable.split('=')
248
+ if (value[0] === '[' && value[value.length - 1] === ']') {
249
+ value = value.substr(1);
250
+ value = value.substr(0, value.length - 1);
251
+ }
252
+ if (['href', 'alt', 'target'].indexOf(key) > -1) {
253
+ res[key] = value
254
+ }
255
+ }
256
+ return res;
257
+ }
258
+
259
+ const meta = parseAttr(attr)
260
+ const aElement = document.createElement('a');
261
+
262
+ if (meta.href) {
263
+ aElement.href = meta.href;
264
+ }
265
+ if (meta.alt) {
266
+ aElement.setAttribute('alt', meta.alt);
267
+ }
268
+ if (meta.target) {
269
+ aElement.setAttribute('target', meta.target);
270
+ }
271
+ if (!!contents) {
272
+ aElement.innerHTML = contents;
273
+ }
274
+ return aElement.outerHTML;
275
+ } catch (e) {
276
+ console.error(e.message);
277
+ return ''
278
+ }
279
+ },
280
+ attr: '(.+)',
281
+ noContent: false
282
+ },
283
+ {
284
+ tag: 'extAttributes/',
285
+ tagConstructor: (match, contents) => {
286
+ return '';
287
+ },
288
+ noContent: true
289
+ },
290
+ ]
291
+
292
+ function registerTags(tagsMeta: TagMetaType[]) {
293
+ const fhml = FhContainer.get<FHML>('FHML');
294
+ const oldParse = fhml.needParse.bind(fhml);
295
+ fhml.needParse = function(str) {
296
+ var regexString = '\\[(';
297
+ regexString += meta.map(function (tag) {
298
+ return tag.tag;
299
+ }).join('|');
300
+ regexString += ')[=a-zA-Z0-9 #,\.\(\)\'\-\_.*]*\\]';
301
+ var res = (str || '').match(new RegExp(regexString));
302
+
303
+ return (res && typeof res === 'object') ? !!res.length : oldParse(str);
304
+ };
305
+ for (const tagMeta of tagsMeta) {
306
+ fhml.registerTag(tagMeta.tag, tagMeta.tagConstructor, tagMeta.attr, tagMeta.noContent);
307
+ }
308
+ }
309
+
310
+ export const extendFHML = (): void => {
311
+ registerTags(meta)
312
312
  }