@syncfusion/ej2-lists 20.2.36 → 20.2.38

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,1283 +0,0 @@
1
- /* eslint-disable no-inner-declarations */
2
- import { extend, merge, isNullOrUndefined, getValue } from '@syncfusion/ej2-base';
3
- import { attributes, prepend, isVisible, append, addClass } from '@syncfusion/ej2-base';
4
- import { compile } from '@syncfusion/ej2-base';
5
- import { DataManager, Query } from '@syncfusion/ej2-data';
6
-
7
- export let cssClass: ClassList = {
8
- li: 'e-list-item',
9
- ul: 'e-list-parent e-ul',
10
- group: 'e-list-group-item',
11
- icon: 'e-list-icon',
12
- text: 'e-list-text',
13
- check: 'e-list-check',
14
- checked: 'e-checked',
15
- selected: 'e-selected',
16
- expanded: 'e-expanded',
17
- textContent: 'e-text-content',
18
- hasChild: 'e-has-child',
19
- level: 'e-level',
20
- url: 'e-list-url',
21
- collapsible: 'e-icon-collapsible',
22
- disabled: 'e-disabled',
23
- image: 'e-list-img',
24
- iconWrapper: 'e-icon-wrapper',
25
- anchorWrap: 'e-anchor-wrap',
26
- navigable: 'e-navigable'
27
- };
28
-
29
- /**
30
- * An interface that holds item class list
31
- */
32
- export interface ClassList {
33
- li: string;
34
- ul: string;
35
- group: string;
36
- icon: string;
37
- text: string;
38
- check: string;
39
- checked: string;
40
- selected: string;
41
- expanded: string;
42
- textContent: string;
43
- hasChild: string;
44
- level: string;
45
- url: string;
46
- collapsible: string;
47
- disabled: string;
48
- image: string;
49
- iconWrapper: string;
50
- anchorWrap: string;
51
- navigable: string;
52
- }
53
-
54
-
55
- /**
56
- * Sorting Order
57
- */
58
- export type SortOrder = 'None' | 'Ascending' | 'Descending';
59
-
60
- /**
61
- * Base List Generator
62
- */
63
- // eslint-disable-next-line @typescript-eslint/no-namespace
64
- export namespace ListBase {
65
-
66
- /**
67
- *
68
- * Default mapped fields.
69
- */
70
- export const defaultMappedFields: FieldsMapping = {
71
- id: 'id',
72
- text: 'text',
73
- url: 'url',
74
- value: 'value',
75
- isChecked: 'isChecked',
76
- enabled: 'enabled',
77
- expanded: 'expanded',
78
- selected: 'selected',
79
- iconCss: 'iconCss',
80
- child: 'child',
81
- isVisible: 'isVisible',
82
- hasChildren: 'hasChildren',
83
- tooltip: 'tooltip',
84
- htmlAttributes: 'htmlAttributes',
85
- urlAttributes: 'urlAttributes',
86
- imageAttributes: 'imageAttributes',
87
- imageUrl: 'imageUrl',
88
- groupBy: null,
89
- sortBy: null
90
- };
91
-
92
- const defaultAriaAttributes: AriaAttributesMapping = {
93
- level: 1,
94
- listRole: 'presentation',
95
- itemRole: 'presentation',
96
- groupItemRole: 'group',
97
- itemText: 'list-item',
98
- wrapperRole: 'presentation'
99
- };
100
-
101
- const defaultListBaseOptions: ListBaseOptions = {
102
- showCheckBox: false,
103
- showIcon: false,
104
- enableHtmlSanitizer: false,
105
- expandCollapse: false,
106
- fields: defaultMappedFields,
107
- ariaAttributes: defaultAriaAttributes,
108
- listClass: '',
109
- itemClass: '',
110
- processSubChild: false,
111
- sortOrder: 'None',
112
- template: null,
113
- groupTemplate: null,
114
- headerTemplate: null,
115
- expandIconClass: 'e-icon-collapsible',
116
- moduleName: 'list',
117
- expandIconPosition: 'Right',
118
- itemNavigable: false
119
- };
120
-
121
- /**
122
- * Function helps to created and return the UL Li element based on your data.
123
- *
124
- * @param {createElementParams} createElement - Specifies an array of JSON data.
125
- *
126
- * @param {{Object}[]} dataSource - Specifies an array of JSON data.
127
- *
128
- * @param {ListBaseOptions} options? - Specifies the list options that need to provide.
129
- *
130
- * @param {boolean} isSingleLevel? - Specifies the list options that need to provide.
131
- *
132
- * @param {any} componentInstance? - Specifies the list options that need to provide.
133
- *
134
- * @returns {createElement} createListFromJson - Specifies the list options that need to provide.
135
- */
136
-
137
- export function createList(
138
- createElement: createElementParams, dataSource: { [key: string]: Object }[] | string[] | number[],
139
- // eslint-disable-next-line
140
- options?: ListBaseOptions, isSingleLevel?: boolean, componentInstance?: any):
141
- HTMLElement {
142
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
143
- const ariaAttributes: AriaAttributesMapping = extend({}, defaultAriaAttributes, curOpt.ariaAttributes);
144
- const type: string = typeofData(dataSource).typeof as string;
145
- if (type === 'string' || type === 'number') {
146
- return createListFromArray(createElement, <string[] | number[]>dataSource, isSingleLevel, options, componentInstance);
147
- } else {
148
- return createListFromJson(createElement, <{ [key: string]: Object }[]>dataSource, options,
149
- ariaAttributes.level, isSingleLevel, componentInstance);
150
- }
151
- }
152
-
153
- /**
154
- * Function helps to created an element list based on string array input .
155
- *
156
- * @param {createElementParams} createElement - Specifies an array of JSON data.
157
- *
158
- * @param {{Object}[]} dataSource - Specifies an array of JSON data.
159
- *
160
- * @param {ListBaseOptions} options? - Specifies the list options that need to provide.
161
- *
162
- * @param {boolean} isSingleLevel? - Specifies the list options that need to provide.
163
- *
164
- * @param {any} componentInstance? - Specifies the list options that need to provide.
165
- *
166
- * @returns {createElement} generateUL - returns the list options that need to provide.
167
- */
168
-
169
- export function createListFromArray(
170
- createElement: createElementParams, dataSource: string[] | number[],
171
- // tslint:disable-next-line
172
- // eslint-disable-next-line
173
- isSingleLevel?: boolean, options?: ListBaseOptions, componentInstance?: any): HTMLElement {
174
- const subChild: HTMLElement[] = createListItemFromArray(createElement, dataSource, isSingleLevel, options, componentInstance);
175
- return generateUL(createElement, subChild, null, options);
176
- }
177
- /**
178
- * Function helps to created an element list based on string array input .
179
- *
180
- * @param {createElementParams} createElement - Specifies an array of JSON data.
181
- *
182
- * @param {{Object}[]} dataSource - Specifies an array of JSON data.
183
- *
184
- * @param {ListBaseOptions} options? - Specifies the list options that need to provide.
185
- *
186
- * @param {boolean} isSingleLevel? - Specifies the list options that need to provide.
187
- *
188
- * @param {any} componentInstance? - Specifies the list options that need to provide.
189
- *
190
- * @returns {HTMLElement[]} subChild - returns the list options that need to provide.
191
- */
192
-
193
-
194
- export function createListItemFromArray(
195
- createElement: createElementParams, dataSource: string[] | number[],
196
- // eslint-disable-next-line
197
- isSingleLevel?: boolean, options?: ListBaseOptions, componentInstance?: any): HTMLElement[] {
198
- const subChild: HTMLElement[] = [];
199
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
200
- cssClass = getModuleClass(curOpt.moduleName);
201
- const id: string = generateId(); // generate id for drop-down-list option.
202
- for (let i: number = 0; i < dataSource.length; i++) {
203
- if (isNullOrUndefined(dataSource[i])) {
204
- continue;
205
- }
206
- let li: HTMLElement;
207
- if (curOpt.itemCreating && typeof curOpt.itemCreating === 'function') {
208
- const curData: object = {
209
- dataSource: dataSource,
210
- curData: dataSource[i],
211
- text: dataSource[i],
212
- options: curOpt
213
- };
214
- curOpt.itemCreating(curData);
215
- }
216
-
217
- if (isSingleLevel) {
218
- li = generateSingleLevelLI(createElement, dataSource[i], undefined, null, null, [], null, id, i, options);
219
- } else {
220
- li = generateLI(createElement, dataSource[i], undefined, null, null, options, componentInstance);
221
- }
222
- if (curOpt.itemCreated && typeof curOpt.itemCreated === 'function') {
223
- const curData: Object = {
224
- dataSource: dataSource,
225
- curData: dataSource[i],
226
- text: dataSource[i],
227
- item: li,
228
- options: curOpt
229
- };
230
- curOpt.itemCreated(curData);
231
- }
232
-
233
- subChild.push(li);
234
- }
235
-
236
- return subChild;
237
- }
238
-
239
- /**
240
- * Function helps to created an element list based on array of JSON input .
241
- *
242
- * @param {createElementParams} createElement - Specifies an array of JSON data.
243
- *
244
- * @param {{Object}[]} dataSource - Specifies an array of JSON data.
245
- *
246
- * @param {ListBaseOptions} options? - Specifies the list options that need to provide.
247
- *
248
- * @param {boolean} isSingleLevel? - Specifies the list options that need to provide.
249
- *
250
- * @param {number} level? - Specifies the list options that need to provide.
251
- *
252
- * @param {any} componentInstance? - Specifies the list options that need to provide.
253
- *
254
- * @returns {HTMLElement[]} child - returns the list options that need to provide.
255
- */
256
-
257
-
258
- export function createListItemFromJson(
259
- createElement: createElementParams, dataSource: { [key: string]: Object }[],
260
- // eslint-disable-next-line
261
- options?: ListBaseOptions, level?: number, isSingleLevel?: boolean, componentInstance?: any): HTMLElement[] {
262
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
263
- cssClass = getModuleClass(curOpt.moduleName);
264
- const fields: FieldsMapping = (componentInstance &&
265
- (componentInstance.getModuleName() === 'listview' || componentInstance.getModuleName() === 'multiselect'))
266
- ? curOpt.fields : extend({}, defaultMappedFields, curOpt.fields);
267
- const ariaAttributes: AriaAttributesMapping = extend({}, defaultAriaAttributes, curOpt.ariaAttributes);
268
- let id: string;
269
- let checkboxElement: HTMLElement[] = [];
270
- if (level) {
271
- ariaAttributes.level = level;
272
- }
273
- const child: HTMLElement[] = [];
274
- let li: HTMLElement;
275
- let anchorElement: HTMLElement;
276
- if (dataSource && dataSource.length && !isNullOrUndefined(typeofData(dataSource).item) &&
277
- // eslint-disable-next-line no-prototype-builtins
278
- !typeofData(dataSource).item.hasOwnProperty(fields.id)) {
279
- id = generateId(); // generate id for drop-down-list option.
280
- }
281
- for (let i: number = 0; i < dataSource.length; i++) {
282
- let fieldData: { [key: string]: Object } = <{ [key: string]: Object }>getFieldValues(dataSource[i], fields);
283
- if (isNullOrUndefined(dataSource[i])) { continue; }
284
- if (curOpt.itemCreating && typeof curOpt.itemCreating === 'function') {
285
- const curData: { [key: string]: object | string } = {
286
- dataSource: dataSource,
287
- curData: dataSource[i],
288
- text: fieldData[fields.text],
289
- options: curOpt,
290
- fields: fields
291
- };
292
- curOpt.itemCreating(curData);
293
- }
294
- const curItem: { [key: string]: Object } = dataSource[i];
295
- if (curOpt.itemCreating && typeof curOpt.itemCreating === 'function') {
296
- fieldData = <{ [key: string]: Object }>getFieldValues(dataSource[i], fields);
297
- }
298
- // eslint-disable-next-line no-prototype-builtins
299
- if (fieldData.hasOwnProperty(fields.id) && !isNullOrUndefined(fieldData[fields.id])) {
300
- id = <string>fieldData[fields.id];
301
- }
302
- const innerEle: HTMLElement[] = [];
303
- if (curOpt.showCheckBox) {
304
- if (curOpt.itemNavigable && (fieldData[fields.url] || fieldData[fields.urlAttributes])) {
305
- checkboxElement.push(createElement('input', { className: cssClass.check, attrs: { type: 'checkbox' } }));
306
- } else {
307
- innerEle.push(createElement('input', { className: cssClass.check, attrs: { type: 'checkbox' } }));
308
- }
309
- }
310
- if (isSingleLevel === true) {
311
- // eslint-disable-next-line no-prototype-builtins
312
- if (curOpt.showIcon && fieldData.hasOwnProperty(fields.iconCss) && !isNullOrUndefined(fieldData[fields.iconCss])) {
313
- innerEle.push(createElement('span', { className: cssClass.icon + ' ' + <string>fieldData[fields.iconCss] }));
314
- }
315
- li = generateSingleLevelLI(
316
- createElement,
317
- curItem,
318
- fieldData,
319
- fields,
320
- curOpt.itemClass,
321
- innerEle,
322
- // eslint-disable-next-line no-prototype-builtins
323
- (curItem.hasOwnProperty('isHeader') &&
324
- (curItem as { isHeader: Object } & { [key: string]: Object }).isHeader) ? true : false,
325
- id,
326
- i, options);
327
- anchorElement = li.querySelector('.' + cssClass.anchorWrap);
328
- if (curOpt.itemNavigable && checkboxElement.length) {
329
- prepend(checkboxElement, li.firstElementChild);
330
- }
331
- } else {
332
- li = generateLI(createElement, curItem, fieldData, fields, curOpt.itemClass, options, componentInstance);
333
- li.classList.add(cssClass.level + '-' + ariaAttributes.level);
334
- li.setAttribute('aria-level', ariaAttributes.level.toString());
335
- anchorElement = li.querySelector('.' + cssClass.anchorWrap);
336
- // eslint-disable-next-line no-prototype-builtins
337
- if (fieldData.hasOwnProperty(fields.tooltip)) {
338
- li.setAttribute('title', <string>fieldData[fields.tooltip]);
339
- }
340
- // eslint-disable-next-line no-prototype-builtins
341
- if (fieldData.hasOwnProperty(fields.htmlAttributes) && fieldData[fields.htmlAttributes]) {
342
- setAttribute(li, <{ [key: string]: string }>fieldData[fields.htmlAttributes]);
343
- }
344
- // eslint-disable-next-line no-prototype-builtins
345
- if (fieldData.hasOwnProperty(fields.enabled) && fieldData[fields.enabled] === false) {
346
- li.classList.add(cssClass.disabled);
347
- }
348
- // eslint-disable-next-line no-prototype-builtins
349
- if (fieldData.hasOwnProperty(fields.isVisible) && fieldData[fields.isVisible] === false) {
350
- li.style.display = 'none';
351
- }
352
- // eslint-disable-next-line no-prototype-builtins
353
- if (fieldData.hasOwnProperty(fields.imageUrl) && !isNullOrUndefined(fieldData[fields.imageUrl])
354
- && !curOpt.template) {
355
- const attr: { [key: string]: string } = { src: <string>fieldData[fields.imageUrl] };
356
- merge(attr, fieldData[fields.imageAttributes]);
357
- const imageElemnt: HTMLElement = createElement('img', { className: cssClass.image, attrs: attr });
358
- if (anchorElement) {
359
- anchorElement.insertAdjacentElement('afterbegin', imageElemnt);
360
- } else {
361
- prepend([imageElemnt], li.firstElementChild);
362
- }
363
- }
364
- // eslint-disable-next-line no-prototype-builtins
365
- if (curOpt.showIcon && fieldData.hasOwnProperty(fields.iconCss) &&
366
- !isNullOrUndefined(fieldData[fields.iconCss]) && !curOpt.template) {
367
- const iconElement: HTMLElement = createElement('div', { className: cssClass.icon + ' ' + <string>fieldData[fields.iconCss] });
368
- if (anchorElement) {
369
- anchorElement.insertAdjacentElement('afterbegin', iconElement);
370
- } else {
371
- prepend([iconElement], li.firstElementChild);
372
- }
373
- }
374
- if (innerEle.length) {
375
- prepend(innerEle, li.firstElementChild);
376
- }
377
- if (curOpt.itemNavigable && checkboxElement.length) {
378
- prepend(checkboxElement, li.firstElementChild);
379
- }
380
- processSubChild(createElement, fieldData, fields, dataSource, curOpt, li, ariaAttributes.level);
381
- }
382
- if (anchorElement) {
383
- addClass([li], [cssClass.navigable]);
384
- }
385
- if (curOpt.itemCreated && typeof curOpt.itemCreated === 'function') {
386
- const curData: { [key: string]: object | string } = {
387
- dataSource: dataSource,
388
- curData: dataSource[i],
389
- text: fieldData[fields.text],
390
- item: li,
391
- options: curOpt,
392
- fields: fields
393
- };
394
- curOpt.itemCreated(curData);
395
- }
396
- checkboxElement = [];
397
- child.push(li);
398
- }
399
- return child;
400
- }
401
-
402
- /**
403
- * Function helps to created an element list based on array of JSON input .
404
- *
405
- * @param {createElementParams} createElement - Specifies an array of JSON data.
406
- *
407
- * @param {{Object}[]} dataSource - Specifies an array of JSON data.
408
- *
409
- * @param {ListBaseOptions} options? - Specifies the list options that need to provide.
410
- *
411
- * @param {number} level? - Specifies the list options that need to provide.
412
- *
413
- * @param {boolean} isSingleLevel? - Specifies the list options that need to provide.
414
- *
415
- * @param {any} componentInstance? - Specifies the list options that need to provide.
416
- *
417
- * @returns {createElement} generateUL - Specifies the list options that need to provide.
418
- */
419
-
420
- export function createListFromJson(
421
- createElement: createElementParams, dataSource: { [key: string]: Object }[],
422
- // eslint-disable-next-line
423
- options?: ListBaseOptions, level?: number, isSingleLevel?: boolean, componentInstance?: any): HTMLElement {
424
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
425
- const li: HTMLElement[] = createListItemFromJson(createElement, dataSource, options, level, isSingleLevel, componentInstance);
426
- return generateUL(createElement, li, curOpt.listClass, options);
427
- }
428
-
429
-
430
- /**
431
- * Return the next or previous visible element.
432
- *
433
- * @param {Element[]|NodeList} elementArray - An element array to find next or previous element.
434
- * @param {Element} li - An element to find next or previous after this element.
435
- * @param {boolean} isPrevious? - Specify when the need get previous element from array.
436
- */
437
-
438
- export function getSiblingLI(elementArray: Element[] | NodeList, element: Element, isPrevious?: boolean): Element {
439
-
440
- cssClass = getModuleClass(defaultListBaseOptions.moduleName);
441
- if (!elementArray || !elementArray.length) { return void 0; }
442
- let siblingLI: Element;
443
- let liIndex: number;
444
- const liCollections: Element[] = Array.prototype.slice.call(elementArray);
445
- if (element) {
446
- liIndex = indexOf(element, liCollections);
447
- } else {
448
- liIndex = (isPrevious === true ? liCollections.length : -1);
449
- }
450
- siblingLI = liCollections[liIndex + (isPrevious === true ? -1 : 1)];
451
- while (siblingLI && (!isVisible(siblingLI) || siblingLI.classList.contains(cssClass.disabled))) {
452
- liIndex = liIndex + (isPrevious === true ? -1 : 1);
453
- siblingLI = liCollections[liIndex];
454
- }
455
- return siblingLI;
456
- }
457
-
458
- /**
459
- * Return the index of the li element
460
- *
461
- * @param {Element} item - An element to find next or previous after this element.
462
- * @param {Element[]} elementArray - An element array to find index of given li.
463
- */
464
-
465
- export function indexOf(item: Element, elementArray: Element[] | NodeList): number {
466
- if (!elementArray || !item) { return void 0; } else {
467
- let liCollections: Element[] = <Element[]>elementArray;
468
- liCollections = Array.prototype.slice.call(elementArray);
469
- return liCollections.indexOf(item);
470
- }
471
- }
472
-
473
-
474
- /**
475
- * Returns the grouped data from given dataSource.
476
- *
477
- * @param {{Object}[]} dataSource - The JSON data which is necessary to process.
478
- * @param {FieldsMapping} fields - Fields that are mapped from the data source.
479
- * @param {SortOrder} sortOrder- Specifies final result sort order.
480
- */
481
-
482
- export function groupDataSource(
483
- dataSource: { [key: string]: Object }[],
484
- fields: FieldsMapping,
485
- sortOrder: SortOrder = 'None'): { [key: string]: Object }[] {
486
- const curFields: FieldsMapping = extend({}, defaultMappedFields, fields);
487
- let cusQuery: Query = new Query().group(curFields.groupBy);
488
-
489
- // need to remove once sorting issues fixed in DataManager
490
- cusQuery = addSorting(sortOrder, 'key', cusQuery);
491
-
492
- const ds: { [key: string]: Object }[] = getDataSource(dataSource, cusQuery);
493
- dataSource = [];
494
-
495
- for (let j: number = 0; j < ds.length; j++) {
496
- const itemObj: { [key: string]: Object }[]
497
- = (ds[j] as { items: { [key: string]: Object }[] } & { [key: string]: Object }).items;
498
- const grpItem: { [key: string]: Object } = {};
499
- const hdr: string = 'isHeader';
500
- grpItem[curFields.text] = (ds[j] as { key: string } & { [key: string]: Object }).key;
501
- grpItem[hdr] = true;
502
- let newtext: string = curFields.text;
503
- if (newtext === 'id') {
504
- newtext = 'text';
505
- grpItem[newtext] = ds[j].key;
506
- }
507
- grpItem._id = 'group-list-item-' + ((ds[j] as { [key: string]: Object }).key ?
508
- (ds[j] as { [key: string]: Object }).key.toString().trim() : 'undefined');
509
- grpItem.items = itemObj;
510
- dataSource.push(grpItem);
511
- for (let k: number = 0; k < itemObj.length; k++) {
512
- dataSource.push(itemObj[k]);
513
- }
514
- }
515
- return dataSource;
516
- }
517
-
518
- /**
519
- * Returns a sorted query object.
520
- *
521
- * @param {SortOrder} sortOrder - Specifies that sort order.
522
- * @param {string} sortBy - Specifies sortBy fields.
523
- * @param {Query} query - Pass if any existing query.
524
- */
525
-
526
- export function addSorting(sortOrder: SortOrder, sortBy: string, query: Query = new Query()): Query {
527
- if (sortOrder === 'Ascending') {
528
- query.sortBy(sortBy, 'ascending', true);
529
- } else if (sortOrder === 'Descending') {
530
- query.sortBy(sortBy, 'descending', true);
531
- } else {
532
- for (let i: number = 0; i < query.queries.length; i++) {
533
- if (query.queries[i].fn === 'onSortBy') {
534
- query.queries.splice(i, 1);
535
- }
536
- }
537
- }
538
- return query;
539
- }
540
-
541
-
542
- /**
543
- * Return an array of JSON Data that processed based on queries.
544
- *
545
- * @param {{Object}[]} dataSource - Specifies local JSON data source.
546
- *
547
- * @param {Query} query - Specifies query that need to process.
548
- */
549
-
550
-
551
- export function getDataSource(dataSource: { [key: string]: Object }[], query: Query): { [key: string]: Object }[] {
552
- // eslint-disable-next-line
553
- return <{ [key: string]: Object }[]>new DataManager(<any[]>dataSource)
554
- .executeLocal(query);
555
- }
556
- /**
557
- * Created JSON data based the UL and LI element
558
- *
559
- * @param {HTMLElement|Element} element - UL element that need to convert as a JSON
560
- * @param {ListBaseOptions} options? - Specifies listbase option for fields.
561
- */
562
-
563
- export function createJsonFromElement(
564
- element: HTMLElement | Element, options?: ListBaseOptions): { [key: string]: Object }[] {
565
-
566
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
567
- const fields: FieldsMapping = extend({}, defaultMappedFields, curOpt.fields);
568
- const curEle: HTMLElement = <HTMLElement>element.cloneNode(true);
569
- // eslint-disable-next-line
570
- const jsonAr: { [key: string]: {} }[] = [];
571
-
572
- curEle.classList.add('json-parent');
573
- const childs: HTMLElement[] = <HTMLElement[] & NodeListOf<HTMLElement>>curEle.querySelectorAll('.json-parent>li');
574
- curEle.classList.remove('json-parent');
575
-
576
- for (let i: number = 0; i < childs.length; i++) {
577
- const li: HTMLElement = childs[i];
578
- const anchor: HTMLElement = li.querySelector('a');
579
- const ul: Element = li.querySelector('ul');
580
- // eslint-disable-next-line
581
- const json: { [key: string]: {} } = {};
582
- const childNodes: NodeList = anchor ? anchor.childNodes : li.childNodes;
583
- const keys: string[] = Object.keys(childNodes);
584
- for (let i: number = 0; i < childNodes.length; i++) {
585
- if (!(childNodes[Number(keys[i])]).hasChildNodes()) {
586
- json[fields.text] = childNodes[Number(keys[i])].textContent;
587
- }
588
- }
589
- let attributes: { [key: string]: string } = getAllAttributes(li);
590
- if (attributes.id) {
591
- json[fields.id] = attributes.id;
592
- delete attributes.id;
593
- } else {
594
- json[fields.id] = generateId();
595
- }
596
- if (Object.keys(attributes).length) {
597
- json[fields.htmlAttributes] = attributes;
598
- }
599
- if (anchor) {
600
- attributes = getAllAttributes(anchor);
601
- if (Object.keys(attributes).length) {
602
- json[fields.urlAttributes] = attributes;
603
- }
604
- }
605
- if (ul) {
606
- json[fields.child] = createJsonFromElement(ul, options);
607
- }
608
- jsonAr.push(json);
609
- }
610
-
611
- return jsonAr;
612
-
613
- }
614
-
615
- function typeofData(data: { [key: string]: Object }[] | string[] | number[]): { [key: string]: Object } {
616
- let match: { [key: string]: Object } = <{ [key: string]: Object }>{ typeof: null, item: null };
617
- for (let i: number = 0; i < data.length; i++) {
618
- if (!isNullOrUndefined(data[i])) {
619
- return match = { typeof: typeof data[i], item: data[i] };
620
- }
621
- }
622
- return match;
623
- }
624
-
625
- function setAttribute(element: HTMLElement, elementAttributes: { [key: string]: string }): void {
626
- const attr: { [key: string]: string } = {};
627
- merge(attr, elementAttributes);
628
- if (attr.class) {
629
- addClass([element], attr.class.split(' '));
630
- delete attr.class;
631
- }
632
- attributes(element, attr);
633
- }
634
-
635
- function getAllAttributes(element: HTMLElement): { [key: string]: string } {
636
- const attributes: { [key: string]: string } = {};
637
- const attr: NamedNodeMap = element.attributes;
638
- for (let index: number = 0; index < attr.length; index++) {
639
- attributes[attr[index].nodeName] = attr[index].nodeValue;
640
- }
641
- return attributes;
642
- }
643
-
644
-
645
- /**
646
- * Created UL element from content template.
647
- *
648
- * @param {string} template - that need to convert and generate li element.
649
- * @param {{Object}[]} dataSource - Specifies local JSON data source.
650
- * @param {ListBaseOptions} options? - Specifies listbase option for fields.
651
- */
652
-
653
- export function renderContentTemplate(
654
- createElement: createElementParams, template: string, dataSource: { [key: string]: Object }[] | string[] | number[],
655
- // eslint-disable-next-line
656
- fields?: FieldsMapping, options?: ListBaseOptions, componentInstance?: any): HTMLElement {
657
- cssClass = getModuleClass(defaultListBaseOptions.moduleName);
658
- const ulElement: HTMLElement = createElement('ul', { className: cssClass.ul, attrs: { role: 'presentation' } });
659
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
660
- const curFields: FieldsMapping = extend({}, defaultMappedFields, fields);
661
- // eslint-disable-next-line
662
- const compiledString: Function = compileTemplate(template);
663
- const liCollection: HTMLElement[] = [];
664
- let value: string;
665
- const id: string = generateId(); // generate id for drop-down-list option.
666
- for (let i: number = 0; i < dataSource.length; i++) {
667
- let fieldData: { [key: string]: Object } = <{ [key: string]: Object }>getFieldValues(dataSource[i], curFields);
668
- const curItem: { [key: string]: Object } | string | number = dataSource[i];
669
- const isHeader: Object = (curItem as { isHeader: Object } & { [key: string]: Object }).isHeader;
670
- if (typeof dataSource[i] === 'string' || typeof dataSource[i] === 'number') {
671
- value = curItem as string;
672
- } else {
673
- value = fieldData[curFields.value] as string;
674
- }
675
- if (curOpt.itemCreating && typeof curOpt.itemCreating === 'function') {
676
- const curData: object = {
677
- dataSource: dataSource,
678
- curData: curItem,
679
- text: value,
680
- options: curOpt,
681
- fields: curFields
682
- };
683
- curOpt.itemCreating(curData);
684
- }
685
- if (curOpt.itemCreating && typeof curOpt.itemCreating === 'function') {
686
- fieldData = <{ [key: string]: Object }>getFieldValues(dataSource[i], curFields);
687
- if (typeof dataSource[i] === 'string' || typeof dataSource[i] === 'number') {
688
- value = curItem as string;
689
- } else {
690
- value = fieldData[curFields.value] as string;
691
- }
692
- }
693
- const li: HTMLElement = createElement('li', {
694
- id: id + '-' + i,
695
- className: isHeader ? cssClass.group : cssClass.li, attrs: { role: 'presentation' }
696
- });
697
- if (isHeader) {
698
- if (typeof dataSource[i] === 'string' || typeof dataSource[i] === 'number') {
699
- li.innerText = curItem as string;
700
- } else {
701
- li.innerText = fieldData[curFields.text] as string;
702
- }
703
- } else {
704
- const currentID: string = isHeader ? curOpt.groupTemplateID : curOpt.templateID;
705
- if (isHeader) {
706
- if (componentInstance && componentInstance.getModuleName() != 'listview') {
707
- // eslint-disable-next-line
708
- const compiledElement: any = compiledString(
709
- curItem,
710
- componentInstance,
711
- 'headerTemplate',
712
- currentID,
713
- !!curOpt.isStringTemplate,
714
- null,
715
- li);
716
- if (compiledElement) {
717
- append(compiledElement, li);
718
- }
719
- } else {
720
- append(compiledString(curItem, componentInstance, 'headerTemplate', currentID, !!curOpt.isStringTemplate), li);
721
- }
722
- } else {
723
- if (componentInstance && componentInstance.getModuleName() !== 'listview') {
724
- // eslint-disable-next-line
725
- const compiledElement: any = compiledString(
726
- curItem,
727
- componentInstance,
728
- 'template',
729
- currentID,
730
- !!curOpt.isStringTemplate,
731
- null,
732
- li);
733
- if (compiledElement) {
734
- append(compiledElement, li);
735
- }
736
- } else {
737
- append(compiledString(curItem, componentInstance, 'template', currentID, !!curOpt.isStringTemplate), li);
738
- }
739
- }
740
- li.setAttribute('data-value', isNullOrUndefined(value) ? 'null' : value);
741
- li.setAttribute('role', 'option');
742
- }
743
- if (curOpt.itemCreated && typeof curOpt.itemCreated === 'function') {
744
- const curData: Object = {
745
- dataSource: dataSource,
746
- curData: curItem,
747
- text: value,
748
- item: li,
749
- options: curOpt,
750
- fields: curFields
751
- };
752
- curOpt.itemCreated(curData);
753
- }
754
- liCollection.push(li);
755
- }
756
- append(liCollection, ulElement);
757
- return ulElement;
758
- }
759
- /**
760
- * Created header items from group template.
761
- *
762
- * @param {string} template - that need to convert and generate li element.
763
- *
764
- * @param {{Object}[]} dataSource - Specifies local JSON data source.
765
- *
766
- * @param {FieldsMapping} fields - Specifies fields for mapping the dataSource.
767
- *
768
- * @param {Element[]} headerItems? - Specifies listbase header items.
769
- */
770
-
771
- // tslint:disable-next-line
772
- export function renderGroupTemplate(
773
- groupTemplate: string,
774
- groupDataSource: { [key: string]: Object }[],
775
- fields: FieldsMapping,
776
- // eslint-disable-next-line
777
- headerItems: Element[], options?: ListBaseOptions, componentInstance?: any): Element[] {
778
- // eslint-disable-next-line @typescript-eslint/ban-types
779
- const compiledString: Function = compileTemplate(groupTemplate);
780
- const curFields: FieldsMapping = extend({}, defaultMappedFields, fields);
781
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
782
- const category: string = curFields.groupBy;
783
- for (const header of headerItems) {
784
- const headerData: { [key: string]: string; } = {};
785
- headerData[category] = header.textContent;
786
- header.innerHTML = '';
787
- if (componentInstance && componentInstance.getModuleName() !== "listview") {
788
- // eslint-disable-next-line
789
- const compiledElement: any = compiledString(
790
- headerData,
791
- componentInstance,
792
- 'groupTemplate',
793
- curOpt.groupTemplateID,
794
- !!curOpt.isStringTemplate, null, header);
795
- if (compiledElement) {
796
- append(compiledElement, header);
797
- }
798
- } else {
799
- append(compiledString(headerData, componentInstance, 'groupTemplate', curOpt.groupTemplateID, !!curOpt.isStringTemplate), header);
800
- }
801
- }
802
- return headerItems;
803
- }
804
-
805
- export function generateId(): string {
806
- return Math.floor((1 + Math.random()) * 0x10000)
807
- .toString(16)
808
- .substring(1);
809
- }
810
-
811
- function processSubChild(
812
- createElement: createElementParams, fieldData: { [key: string]: Object }, fields: FieldsMapping, ds: { [key: string]: Object }[],
813
- options: ListBaseOptions, element: HTMLElement, level: number): void {
814
- // Get SubList
815
- const subDS: { [key: string]: Object }[] = <{ [key: string]: Object }[]>fieldData[fields.child] || [];
816
- let hasChildren: boolean = <boolean>fieldData[fields.hasChildren];
817
- //Create Sub child
818
- if (subDS.length) {
819
- hasChildren = true;
820
- element.classList.add(cssClass.hasChild);
821
- if (options.processSubChild) {
822
- const subLi: HTMLElement = <HTMLElement>createListFromJson(createElement, subDS, options, ++level);
823
- element.appendChild(subLi);
824
- }
825
- }
826
-
827
- // Create expand and collapse node
828
- if (!!options.expandCollapse && hasChildren && !options.template) {
829
- element.firstElementChild.classList.add(cssClass.iconWrapper);
830
- // eslint-disable-next-line @typescript-eslint/ban-types
831
- const expandElement: Function = options.expandIconPosition === 'Left' ? prepend : append;
832
- expandElement(
833
- [createElement('div', { className: 'e-icons ' + options.expandIconClass })],
834
- element.querySelector('.' + cssClass.textContent));
835
- }
836
- }
837
-
838
- function generateSingleLevelLI(
839
- createElement: createElementParams, item: string | { [key: string]: Object } | number,
840
- fieldData: { [key: string]: Object }, fields?: FieldsMapping, className?: string, innerElements?: HTMLElement[],
841
- grpLI?: boolean, id?: string, index?: number, options?: ListBaseOptions):
842
- HTMLElement {
843
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
844
- const ariaAttributes: AriaAttributesMapping = extend({}, defaultAriaAttributes, curOpt.ariaAttributes);
845
- let text: string = <string>item;
846
- let value: string = <string>item;
847
- let dataSource: { [key: string]: string } | { [key: string]: object };
848
- if (typeof item !== 'string' && typeof item !== 'number' && typeof item !== 'boolean') {
849
- dataSource = <{ [key: string]: Object }>item;
850
- text = (typeof fieldData[fields.text] === 'boolean' || typeof fieldData[fields.text] === 'number') ?
851
- <string>fieldData[fields.text] : (<string>fieldData[fields.text] || '');
852
- value = <string>fieldData[fields.value];
853
- }
854
- let elementID: string;
855
- if (!isNullOrUndefined(dataSource) && !isNullOrUndefined(fieldData[fields.id])
856
- && fieldData[fields.id] !== '') {
857
- elementID = id;
858
- } else {
859
- elementID = id + '-' + index;
860
- }
861
- const li: HTMLElement = createElement('li', {
862
- className: (grpLI === true ? cssClass.group : cssClass.li) + ' ' + (isNullOrUndefined(className) ? '' : className),
863
- id: elementID, attrs: (ariaAttributes.groupItemRole !== '' && ariaAttributes.itemRole !== '' ?
864
- { role: (grpLI === true ? ariaAttributes.groupItemRole : ariaAttributes.itemRole) } : {})
865
- });
866
- // eslint-disable-next-line no-prototype-builtins
867
- if (dataSource && fieldData.hasOwnProperty(fields.enabled) && fieldData[fields.enabled].toString() === 'false') {
868
- li.classList.add(cssClass.disabled);
869
- }
870
- if (grpLI) {
871
- li.innerText = text;
872
- } else {
873
- li.setAttribute('data-value', isNullOrUndefined(value) ? 'null' : value);
874
-
875
- li.setAttribute('role', 'option');
876
- // eslint-disable-next-line no-prototype-builtins
877
- if (dataSource && fieldData.hasOwnProperty(fields.htmlAttributes) && fieldData[fields.htmlAttributes]) {
878
- setAttribute(li, <{ [key: string]: string }>fieldData[fields.htmlAttributes]);
879
- }
880
-
881
- if (innerElements.length && !curOpt.itemNavigable) { append(innerElements, li); }
882
-
883
- if (dataSource && (fieldData[fields.url] || (fieldData[fields.urlAttributes] &&
884
- (fieldData[fields.urlAttributes] as { [key: string]: Object }).href))) {
885
- li.appendChild(anchorTag(createElement, dataSource, fields, text, innerElements, curOpt.itemNavigable));
886
- } else {
887
- if (innerElements.length && curOpt.itemNavigable) { append(innerElements, li); }
888
- li.appendChild(document.createTextNode(text));
889
- }
890
- }
891
- return li;
892
- }
893
-
894
- function getModuleClass(moduleName: string): ClassList {
895
- let moduleClass: ClassList;
896
- // eslint-disable-next-line
897
- return moduleClass = {
898
- li: `e-${moduleName}-item`,
899
- ul: `e-${moduleName}-parent e-ul`,
900
- group: `e-${moduleName}-group-item`,
901
- icon: `e-${moduleName}-icon`,
902
- text: `e-${moduleName}-text`,
903
- check: `e-${moduleName}-check`,
904
- checked: 'e-checked',
905
- selected: 'e-selected',
906
- expanded: 'e-expanded',
907
- textContent: 'e-text-content',
908
- hasChild: 'e-has-child',
909
- level: 'e-level',
910
- url: `e-${moduleName}-url`,
911
- collapsible: 'e-icon-collapsible',
912
- disabled: 'e-disabled',
913
- image: `e-${moduleName}-img`,
914
- iconWrapper: 'e-icon-wrapper',
915
- anchorWrap: 'e-anchor-wrap',
916
- navigable: 'e-navigable'
917
- };
918
- }
919
-
920
- function anchorTag(
921
- createElement: createElementParams, dataSource: { [key: string]: object } | { [key: string]: string },
922
- fields: FieldsMapping, text: string, innerElements: HTMLElement[], isFullNavigation: boolean): HTMLElement {
923
- const fieldData: { [key: string]: Object } = <{ [key: string]: Object }>getFieldValues(dataSource, fields);
924
- const attr: { [key: string]: string } = { href: <string>fieldData[fields.url] };
925
- // eslint-disable-next-line no-prototype-builtins
926
- if (fieldData.hasOwnProperty(fields.urlAttributes) && fieldData[fields.urlAttributes]) {
927
- merge(attr, fieldData[fields.urlAttributes]);
928
- attr.href = <string>fieldData[fields.url] ? <string>fieldData[fields.url] :
929
- (fieldData[fields.urlAttributes] as { [key: string]: Object }).href as string;
930
- }
931
- let anchorTag: HTMLElement;
932
- if (!isFullNavigation) {
933
- anchorTag = createElement('a', { className: cssClass.text + ' ' + cssClass.url, innerHTML: text });
934
- } else {
935
- anchorTag = createElement('a', { className: cssClass.text + ' ' + cssClass.url });
936
- const anchorWrapper: HTMLElement = createElement('div', { className: cssClass.anchorWrap });
937
- if (innerElements && innerElements.length) {
938
- append(innerElements, anchorWrapper);
939
- }
940
- anchorWrapper.appendChild(document.createTextNode(text));
941
- append([anchorWrapper], anchorTag);
942
- }
943
- setAttribute(anchorTag, attr);
944
- return anchorTag;
945
- }
946
- // tslint:disable-next-line
947
- /* tslint:disable:align */
948
- function generateLI(
949
- createElement: createElementParams, item: string | { [key: string]: Object } | number, fieldData: { [key: string]: Object },
950
- // eslint-disable-next-line
951
- fields: FieldsMapping, className?: string, options?: ListBaseOptions, componentInstance?: any): HTMLElement {
952
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
953
- const ariaAttributes: AriaAttributesMapping = extend({}, defaultAriaAttributes, curOpt.ariaAttributes);
954
- let text: string = <string>item;
955
- let uID: string;
956
- let grpLI: boolean;
957
- let dataSource: { [key: string]: string } | { [key: string]: object };
958
- if (typeof item !== 'string' && typeof item !== 'number') {
959
- dataSource = <{ [key: string]: Object }>item;
960
- text = <string>fieldData[fields.text] || '';
961
- // tslint:disable-next-line
962
- uID = (isNullOrUndefined(<string>fieldData['_id'])) ? <string>fieldData[fields.id] : <string>fieldData['_id'];
963
- // eslint-disable-next-line no-prototype-builtins
964
- grpLI = (item.hasOwnProperty('isHeader') && (item as { isHeader: Object } & { [key: string]: Object }).isHeader)
965
- ? true : false;
966
- }
967
- if (options && options.enableHtmlSanitizer) {
968
- // eslint-disable-next-line no-self-assign
969
- text = text;
970
- }
971
- const li: HTMLElement = createElement('li', {
972
- className: (grpLI === true ? cssClass.group : cssClass.li) + ' ' + (isNullOrUndefined(className) ? '' : className),
973
- attrs: (ariaAttributes.groupItemRole !== '' && ariaAttributes.itemRole !== '' ?
974
- { role: (grpLI === true ? ariaAttributes.groupItemRole : ariaAttributes.itemRole) } : {})
975
- });
976
-
977
- if (!isNullOrUndefined(uID) === true) {
978
- li.setAttribute('data-uid', uID);
979
- }
980
- else {
981
- li.setAttribute('data-uid', generateId());
982
- }
983
- if (grpLI && options && options.groupTemplate) {
984
- // eslint-disable-next-line @typescript-eslint/ban-types
985
- const compiledString: Function = compileTemplate(options.groupTemplate);
986
- if (componentInstance && componentInstance.getModuleName() !== "listview") {
987
- // eslint-disable-next-line
988
- const compiledElement: any = compiledString(
989
- item,
990
- componentInstance,
991
- 'groupTemplate',
992
- curOpt.groupTemplateID,
993
- !!curOpt.isStringTemplate,
994
- null,
995
- li);
996
- if (compiledElement) {
997
- append(compiledElement, li);
998
- }
999
- } else {
1000
- append(compiledString(item, componentInstance, 'groupTemplate', curOpt.groupTemplateID, !!curOpt.isStringTemplate), li);
1001
- }
1002
- } else if (!grpLI && options && options.template) {
1003
- // eslint-disable-next-line @typescript-eslint/ban-types
1004
- const compiledString: Function = compileTemplate(options.template);
1005
- if (componentInstance && componentInstance.getModuleName() !== 'listview') {
1006
- // eslint-disable-next-line
1007
- const compiledElement: any = compiledString(
1008
- item,
1009
- componentInstance,
1010
- 'template',
1011
- curOpt.templateID,
1012
- !!curOpt.isStringTemplate,
1013
- null,
1014
- li);
1015
- if (compiledElement) {
1016
- append(compiledElement, li);
1017
- }
1018
- } else {
1019
- append(compiledString(item, componentInstance, 'template', curOpt.templateID, !!curOpt.isStringTemplate), li);
1020
- }
1021
- } else {
1022
- const innerDiv: HTMLElement = createElement('div', {
1023
- className: cssClass.textContent,
1024
- attrs: (ariaAttributes.wrapperRole !== '' ? { role: ariaAttributes.wrapperRole } : {})
1025
- });
1026
- if (dataSource && (fieldData[fields.url] || (fieldData[fields.urlAttributes] &&
1027
- (fieldData[fields.urlAttributes] as { [key: string]: Object }).href))) {
1028
- innerDiv.appendChild(anchorTag(createElement, dataSource, fields, text, null, curOpt.itemNavigable));
1029
- } else {
1030
- const element: HTMLElement = createElement('span', {
1031
- className: cssClass.text,
1032
- attrs: (ariaAttributes.itemText !== '' ? { role: ariaAttributes.itemText } : {})
1033
- });
1034
- if (options && options.enableHtmlSanitizer) {
1035
- element.innerText = text;
1036
- } else {
1037
- element.innerHTML = text;
1038
- }
1039
- innerDiv.appendChild(element);
1040
- }
1041
- li.appendChild(innerDiv);
1042
- }
1043
- return li;
1044
- }
1045
-
1046
- /**
1047
- * Returns UL element based on the given LI element.
1048
- *
1049
- * @param {HTMLElement[]} liElement - Specifies array of LI element.
1050
- *
1051
- * @param {string} className? - Specifies class name that need to be added in UL element.
1052
- *
1053
- * @param {ListBaseOptions} options? - Specifies ListBase options.
1054
- */
1055
-
1056
- export function generateUL(
1057
- createElement: createElementParams, liElement: HTMLElement[], className?: string, options?: ListBaseOptions): HTMLElement {
1058
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
1059
- const ariaAttributes: AriaAttributesMapping = extend({}, defaultAriaAttributes, curOpt.ariaAttributes);
1060
- cssClass = getModuleClass(curOpt.moduleName);
1061
- const ulElement: HTMLElement = createElement('ul', {
1062
- className: cssClass.ul + ' ' + (isNullOrUndefined(className) ? '' : className),
1063
- attrs: (ariaAttributes.listRole !== '' ? { role: ariaAttributes.listRole } : {})
1064
- });
1065
-
1066
- append(liElement, ulElement);
1067
-
1068
- return ulElement;
1069
- }
1070
-
1071
- /**
1072
- * Returns LI element with additional DIV tag based on the given LI element.
1073
- *
1074
- * @param {liElement} liElement - Specifies LI element.
1075
- *
1076
- * @param {string} className? - Specifies class name that need to be added in created DIV element.
1077
- *
1078
- * @param {ListBaseOptions} options? - Specifies ListBase options.
1079
- */
1080
-
1081
- export function generateIcon(
1082
- createElement: createElementParams, liElement: HTMLElement, className?: string, options?: ListBaseOptions): HTMLElement {
1083
- const curOpt: ListBaseOptions = extend({}, defaultListBaseOptions, options);
1084
- cssClass = getModuleClass(curOpt.moduleName);
1085
- // eslint-disable-next-line @typescript-eslint/ban-types
1086
- const expandElement: Function = curOpt.expandIconPosition === 'Left' ? prepend : append;
1087
- expandElement(
1088
- [createElement('div', {
1089
- className: 'e-icons ' + curOpt.expandIconClass + ' ' +
1090
- (isNullOrUndefined(className) ? '' : className)
1091
- })],
1092
- liElement.querySelector('.' + cssClass.textContent));
1093
-
1094
- return liElement;
1095
- }
1096
-
1097
- }
1098
-
1099
- export type createElementParams = (
1100
- tag: string,
1101
- prop?: { id?: string, className?: string, innerHTML?: string, styles?: string, attrs?: { [key: string]: string } }
1102
- ) => HTMLElement;
1103
-
1104
- /**
1105
- * An interface that holds the field mappings
1106
- */
1107
- export interface FieldsMapping {
1108
- id?: string;
1109
- text?: string;
1110
- value?: string;
1111
- isChecked?: string;
1112
- isVisible?: string;
1113
- url?: string;
1114
- enabled?: string;
1115
- groupBy?: string;
1116
- expanded?: string;
1117
- selected?: string;
1118
- iconCss?: string;
1119
- child?: string;
1120
- tooltip?: string;
1121
- hasChildren?: string;
1122
- htmlAttributes?: string;
1123
- urlAttributes?: string;
1124
- imageUrl?: string;
1125
- imageAttributes?: string;
1126
- sortBy?: string
1127
-
1128
- }
1129
-
1130
- /**
1131
- * An enum type that denotes the Expand Icon Position. Available options are as follows Right, Left;
1132
- */
1133
- export type Position = 'Right' | 'Left';
1134
-
1135
- /**
1136
- * An interface that holds item aria attributes mapping
1137
- */
1138
- export interface AriaAttributesMapping {
1139
- level?: number;
1140
- listRole?: string;
1141
- itemRole?: string;
1142
- groupItemRole?: string;
1143
- itemText?: string;
1144
- wrapperRole?: string;
1145
- }
1146
-
1147
- /**
1148
- * Basic ListBase Options
1149
- */
1150
- export interface ListBaseOptions {
1151
- /**
1152
- * Specifies that fields that mapped in dataSource
1153
- */
1154
- fields?: FieldsMapping;
1155
- /**
1156
- * Specifies the aria attributes
1157
- */
1158
- ariaAttributes?: AriaAttributesMapping;
1159
- /**
1160
- * Specifies to show checkBox
1161
- */
1162
- showCheckBox?: boolean;
1163
- /**
1164
- * Specifies to show icon
1165
- */
1166
- showIcon?: boolean;
1167
- /**
1168
- * Specifies to show collapsible icon
1169
- */
1170
- expandCollapse?: boolean;
1171
- /**
1172
- * Specifies when need to add additional UL list class
1173
- */
1174
- listClass?: string;
1175
- /**
1176
- * Specifies when need to add additional LI item class
1177
- */
1178
- itemClass?: string;
1179
- /**
1180
- * Enables when need process depth child processing.
1181
- */
1182
- processSubChild?: boolean;
1183
- /**
1184
- * Specifies the sort order
1185
- */
1186
- sortOrder?: SortOrder;
1187
- /**
1188
- * Specifies the item template
1189
- */
1190
- template?: string;
1191
- /**
1192
- * Specifies the group header template
1193
- */
1194
- groupTemplate?: string;
1195
- /**
1196
- * Specifies the ListView header template
1197
- */
1198
- headerTemplate?: string;
1199
- /**
1200
- * Specifies the callback function that triggered before each list creation
1201
- */
1202
- // eslint-disable-next-line @typescript-eslint/ban-types
1203
- itemCreating?: Function;
1204
- /**
1205
- * Specifies the callback function that triggered after each list creation
1206
- */
1207
- // eslint-disable-next-line @typescript-eslint/ban-types
1208
- itemCreated?: Function;
1209
- /**
1210
- * Specifies the customizable expand icon class
1211
- */
1212
- expandIconClass?: string;
1213
- /**
1214
- * Specifies the customized class name based on their module name
1215
- */
1216
- moduleName?: string;
1217
- /**
1218
- * Specifies the expand/collapse icon position
1219
- */
1220
- expandIconPosition?: Position;
1221
- /**
1222
- * Specifies the template ID
1223
- */
1224
- templateID?: string;
1225
- /**
1226
- * Specifies the groupTemplate ID
1227
- */
1228
- groupTemplateID?: string;
1229
- /**
1230
- * Force template compiler to compile as string template
1231
- */
1232
- isStringTemplate?: string;
1233
- /**
1234
- * Defines whether to allow the cross scripting site or not.
1235
- */
1236
- enableHtmlSanitizer?: boolean;
1237
- /**
1238
- * If set true to this property then the entire list will be navigate-able instead of text element
1239
- */
1240
- itemNavigable?: boolean;
1241
- }
1242
-
1243
- /**
1244
- * Used to get dataSource item from complex data using fields.
1245
- *
1246
- * @param {Object} dataSource - Specifies an JSON or String data.
1247
- *
1248
- * @param {FieldsMapping} fields - Fields that are mapped from the dataSource.
1249
- */
1250
-
1251
- export function getFieldValues(dataItem: { [key: string]: Object } | string | number, fields: FieldsMapping)
1252
- : { [key: string]: Object } | string | number {
1253
- const fieldData: { [key: string]: Object } = {};
1254
- if (isNullOrUndefined(dataItem) || typeof (dataItem) === 'string' || typeof (dataItem) === 'number'
1255
- || !isNullOrUndefined((<{ [key: string]: Object }>dataItem).isHeader)) {
1256
- return dataItem;
1257
- } else {
1258
- for (const field of Object.keys(fields)) {
1259
- const dataField: string = (<{ [key: string]: Object }>fields)[field] as string;
1260
- const value: { [key: string]: Object } = !isNullOrUndefined(dataField) &&
1261
- typeof (dataField) === 'string' ? getValue(dataField, dataItem) : undefined;
1262
- if (!isNullOrUndefined(value)) {
1263
- fieldData[dataField] = value;
1264
- }
1265
- }
1266
- }
1267
- return fieldData;
1268
- }
1269
-
1270
- function compileTemplate(template: string): Function {
1271
- if (template) {
1272
- try {
1273
- if (document.querySelector(template)) {
1274
- return compile(document.querySelector(template).innerHTML.trim());
1275
- } else {
1276
- return compile(template);
1277
- }
1278
- } catch (e) {
1279
- return compile(template);
1280
- }
1281
- }
1282
- return undefined;
1283
- }