@syncfusion/ej2-vue-base 25.2.4 → 26.2.4

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.
package/src/template.js CHANGED
@@ -9,27 +9,33 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { setTemplateEngine, getTemplateEngine, getUniqueID, createElement, detach, extend, getValue } from "@syncfusion/ej2-base";
13
- import { aVue as Vue, isExecute } from "./component-base";
14
- // tslint:disable:no-any
12
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */
13
+ import { setTemplateEngine, getTemplateEngine, getUniqueID, createElement, detach, extend, getValue } from '@syncfusion/ej2-base';
14
+ import { aVue as Vue, isExecute } from './component-base';
15
15
  var stringCompiler = getTemplateEngine();
16
+ /**
17
+ * Compiler function that convert the template property to DOM element.
18
+ *
19
+ * @param {any} templateElement - represents value of the template property from the component.
20
+ * @param {Object} helper - represents helper object to utilize on template compilation.
21
+ * @returns {NodeList} template element that append to the component.
22
+ */
16
23
  export function compile(templateElement, helper) {
17
- var that = this;
24
+ var _this = this;
18
25
  return function (data, context, propName, element, root) {
19
- var _a, _b, _c, _d;
20
26
  var returnEle;
21
27
  if (context) {
22
28
  var plugins = context.vueInstance && context.vueInstance.plugins ? { plugins: context.vueInstance.plugins } : {};
23
29
  var vueInstance = context.vueInstance ? context.vueInstance :
24
30
  ((root && root.vueInstance) ? root.vueInstance : null);
25
- var pid = getUniqueID("templateParentDiv");
26
- var id = getUniqueID("templateDiv");
27
- var ele = createElement("div", {
31
+ var pid = getUniqueID('templateParentDiv');
32
+ var id = getUniqueID('templateDiv');
33
+ var ele = createElement('div', {
28
34
  id: pid,
29
- innerHTML: '<div id="' + id + '"></div>',
35
+ innerHTML: '<div id="' + id + '"></div>'
30
36
  });
31
37
  document.body.appendChild(ele);
32
- if (!isExecute && (typeof templateElement === "string" || (templateElement.prototype && templateElement.prototype.CSPTemplate && typeof templateElement === 'function'))) {
38
+ if (!isExecute && (typeof templateElement === 'string' || (templateElement.prototype && templateElement.prototype.CSPTemplate && typeof templateElement === 'function'))) {
33
39
  var vueSlot_1 = getCurrentVueSlot(context.vueInstance, templateElement, root);
34
40
  if (vueSlot_1) {
35
41
  // Compilation for Vue 3 slot template
@@ -42,13 +48,20 @@ export function compile(templateElement, helper) {
42
48
  // Get values for Vue 3 slot template
43
49
  getValues(app, context.vueInstance, root);
44
50
  Vue.render(app, ele);
51
+ returnEle = ele.childNodes;
45
52
  if (vueInstance) {
46
- if (!vueInstance['portals']) {
47
- vueInstance['portals'] = [];
53
+ var templateInstance = vueInstance.templateCollection;
54
+ if (!templateInstance) {
55
+ vueInstance.templateCollection = {};
56
+ templateInstance = vueInstance.templateCollection;
57
+ }
58
+ if (propName) {
59
+ if (!templateInstance["" + propName]) {
60
+ templateInstance["" + propName] = [];
61
+ }
62
+ templateInstance["" + propName].push(ele);
48
63
  }
49
- (_a = vueInstance.portals).push.apply(_a, [].slice.call(ele.children));
50
64
  }
51
- returnEle = ele.childNodes;
52
65
  detach(ele);
53
66
  }
54
67
  else {
@@ -59,12 +72,12 @@ export function compile(templateElement, helper) {
59
72
  }
60
73
  else if (!isExecute) {
61
74
  // Compilation for Vue 3 functional template
62
- var tempObj = templateElement.call(that, {});
75
+ var tempObj = templateElement.call(_this, {});
63
76
  var object = tempObj;
64
- var propsData = getValue("template.propsData", tempObj);
77
+ var propsData = getValue('template.propsData', tempObj);
65
78
  var dataObj_1 = {
66
79
  data: { data: extend(tempObj.data || {}, data) },
67
- parent: context.vueInstance,
80
+ parent: context.vueInstance
68
81
  };
69
82
  if (!object.template) {
70
83
  object.template = object[Object.keys(object)[0]];
@@ -101,9 +114,12 @@ export function compile(templateElement, helper) {
101
114
  var _loop_1 = function (objstring) {
102
115
  var intComponent = templateCompRef.components["" + objstring];
103
116
  if (intComponent && intComponent.data) {
104
- if (!intComponent.__data)
117
+ if (!intComponent.__data) {
105
118
  intComponent.__data = intComponent.data;
106
- intComponent.data = function (proxy) { return Object.assign(intComponent.__data.call(proxy), dataObj_1.data); };
119
+ }
120
+ intComponent.data = function (proxy) {
121
+ return Object.assign(intComponent.__data.call(proxy), dataObj_1.data);
122
+ };
107
123
  }
108
124
  };
109
125
  for (var _i = 0, objkeys_1 = objkeys; _i < objkeys_1.length; _i++) {
@@ -121,41 +137,38 @@ export function compile(templateElement, helper) {
121
137
  // Get values for Vue 3 functional template
122
138
  getValues(app, context.vueInstance, root);
123
139
  Vue.render(app, ele);
124
- if (vueInstance) {
125
- if (!vueInstance['portals']) {
126
- vueInstance['portals'] = [];
127
- }
128
- (_b = vueInstance.portals).push.apply(_b, [].slice.call(ele.children));
129
- }
130
140
  returnEle = ele.childNodes;
131
- if (context.vueInstance) {
132
- var templateInstance = context.vueInstance.templateCollection;
141
+ dataObj_1.parent = null;
142
+ if (vueInstance) {
143
+ var templateInstance = vueInstance.templateCollection;
133
144
  if (!templateInstance) {
134
- context.vueInstance.templateCollection = {};
135
- templateInstance = context.vueInstance.templateCollection;
145
+ vueInstance.templateCollection = {};
146
+ templateInstance = vueInstance.templateCollection;
136
147
  }
137
148
  if (propName) {
138
149
  if (!templateInstance["" + propName]) {
139
150
  templateInstance["" + propName] = [];
140
151
  }
141
- templateInstance["" + propName].push(returnEle[0]);
152
+ templateInstance["" + propName].push(ele);
142
153
  }
143
154
  }
144
155
  detach(ele);
145
156
  }
146
- else if (typeof templateElement === "string" || (templateElement.prototype && templateElement.prototype.CSPTemplate && typeof templateElement === 'function')) {
157
+ else if (typeof templateElement === 'string' || (templateElement.prototype && templateElement.prototype.CSPTemplate && typeof templateElement === 'function')) {
147
158
  var vueSlot_2 = getVueSlot(context.vueInstance, templateElement, root);
148
159
  if (vueSlot_2) {
149
160
  // Get provide values for Vue 2 slot template
150
161
  var provided_1 = {};
151
162
  var getProvideValues_1 = function (vueinstance) {
152
- if (vueinstance['$parent'])
163
+ if (vueinstance['$parent']) {
153
164
  getProvideValues_1(vueinstance.$parent);
165
+ }
154
166
  if (vueinstance['_provided'] && Object.keys(vueinstance['_provided']).length > 0) {
155
167
  provided_1 = __assign({}, provided_1, vueinstance._provided);
156
168
  }
157
169
  };
158
- var vueInstance_1 = context.vueInstance ? context.vueInstance : ((root && root.vueInstance) ? root.vueInstance : null);
170
+ var vueInstance_1 = context.vueInstance ? context.vueInstance :
171
+ ((root && root.vueInstance) ? root.vueInstance : null);
159
172
  if (vueInstance_1) {
160
173
  getProvideValues_1(vueInstance_1);
161
174
  }
@@ -166,14 +179,21 @@ export function compile(templateElement, helper) {
166
179
  return vueSlot_2["" + templateElement]({ data: data });
167
180
  }
168
181
  });
169
- vueTemplate.$mount("#" + id);
182
+ vueTemplate.$mount('#' + id);
183
+ returnEle = ele.childNodes;
170
184
  if (vueInstance_1) {
171
- if (!vueInstance_1['portals']) {
172
- vueInstance_1['portals'] = [];
185
+ var templateInstance = vueInstance_1.templateCollection;
186
+ if (!templateInstance) {
187
+ vueInstance_1.templateCollection = {};
188
+ templateInstance = vueInstance_1.templateCollection;
189
+ }
190
+ if (propName) {
191
+ if (!templateInstance["" + propName]) {
192
+ templateInstance["" + propName] = [];
193
+ }
194
+ templateInstance["" + propName].push(returnEle[0]);
173
195
  }
174
- (_c = vueInstance_1.portals).push.apply(_c, [].slice.call(ele.children));
175
196
  }
176
- returnEle = ele.childNodes;
177
197
  detach(ele);
178
198
  }
179
199
  else {
@@ -184,18 +204,18 @@ export function compile(templateElement, helper) {
184
204
  }
185
205
  else {
186
206
  // Compilation for Vue 2 functional template
187
- var tempObj = templateElement.call(that, {});
207
+ var tempObj = templateElement.call(_this, {});
188
208
  var templateFunction = tempObj.template;
189
- var propsData = getValue("template.propsData", tempObj);
209
+ var propsData = getValue('template.propsData', tempObj);
190
210
  var dataObj = {
191
211
  data: { data: extend(tempObj.data || {}, data) },
192
- parent: context.vueInstance,
212
+ parent: context.vueInstance
193
213
  };
194
214
  if (propsData) {
195
215
  templateFunction = tempObj.template.extends;
196
216
  dataObj.propsData = propsData;
197
217
  }
198
- if (typeof templateFunction !== "function") {
218
+ if (typeof templateFunction !== 'function') {
199
219
  templateFunction = Vue.extend(templateFunction);
200
220
  }
201
221
  if (templateFunction.options.setup) {
@@ -204,19 +224,14 @@ export function compile(templateElement, helper) {
204
224
  var templateVue = new templateFunction(dataObj);
205
225
  // let templateVue = new Vue(tempObj.template);
206
226
  // templateVue.$data.data = extend(tempObj.data, data);
207
- templateVue.$mount("#" + id);
208
- if (vueInstance) {
209
- if (!vueInstance['portals']) {
210
- vueInstance['portals'] = [];
211
- }
212
- (_d = vueInstance.portals).push.apply(_d, [].slice.call(ele.children));
213
- }
227
+ templateVue.$mount('#' + id);
214
228
  returnEle = ele.childNodes;
215
- if (context.vueInstance) {
216
- var templateInstance = context.vueInstance.templateCollection;
229
+ dataObj.parent = null;
230
+ if (vueInstance) {
231
+ var templateInstance = vueInstance.templateCollection;
217
232
  if (!templateInstance) {
218
- context.vueInstance.templateCollection = {};
219
- templateInstance = context.vueInstance.templateCollection;
233
+ vueInstance.templateCollection = {};
234
+ templateInstance = vueInstance.templateCollection;
220
235
  }
221
236
  if (propName) {
222
237
  if (!templateInstance["" + propName]) {
@@ -232,6 +247,14 @@ export function compile(templateElement, helper) {
232
247
  };
233
248
  }
234
249
  setTemplateEngine({ compile: compile });
250
+ /**
251
+ * Collect values from the app instance.
252
+ *
253
+ * @param {any} app - represents global application instance
254
+ * @param {any} cInstance - represents Vue component instance
255
+ * @param {any} root - represents parent component instance
256
+ * @returns {void}
257
+ */
235
258
  function getValues(app, cInstance, root) {
236
259
  var vueInstance = cInstance ? cInstance : ((root && root.vueInstance) ? root.vueInstance : null);
237
260
  if (!vueInstance) {
@@ -242,8 +265,9 @@ function getValues(app, cInstance, root) {
242
265
  // Get provide value from child component.
243
266
  var provided = {};
244
267
  var getProvideValue = function (vueinstance) {
245
- if (vueinstance['$'] && vueinstance['$']['parent'])
268
+ if (vueinstance['$'] && vueinstance['$']['parent']) {
246
269
  getProvideValue(vueinstance.$.parent);
270
+ }
247
271
  if (vueinstance['provides'] && Object.keys(vueinstance['provides']).length > 0) {
248
272
  provided = __assign({}, provided, vueinstance.provides);
249
273
  }
@@ -253,7 +277,14 @@ function getValues(app, cInstance, root) {
253
277
  app.appContext.provides = __assign({}, app.appContext.provides, provided);
254
278
  }
255
279
  }
256
- // Get the Vue2 slot template from the root or current Vue component.
280
+ /**
281
+ * Get the Vue2 slot template from the root or current Vue component.
282
+ *
283
+ * @param {any} vueInstance - represents parent Vue instance.
284
+ * @param {any} templateElement - represents component property value
285
+ * @param {any} root - represents root Vue instance
286
+ * @returns {any} template Vue instance
287
+ */
257
288
  function getVueSlot(vueInstance, templateElement, root) {
258
289
  if (!vueInstance && !(root && root.vueInstance)) {
259
290
  return undefined;
@@ -261,6 +292,13 @@ function getVueSlot(vueInstance, templateElement, root) {
261
292
  var instance = (root && root.vueInstance) ? root.vueInstance : vueInstance;
262
293
  return getVueChildSlot(instance, templateElement);
263
294
  }
295
+ /**
296
+ * Get the Vue2 nested slot template from the root or current Vue component.
297
+ *
298
+ * @param {any} vueInstance - represents parent Vue instance.
299
+ * @param {any} templateElement - represents component property value
300
+ * @returns {any} nested template Vue instance
301
+ */
264
302
  function getVueChildSlot(vueInstance, templateElement) {
265
303
  if (!vueInstance) {
266
304
  return undefined;
@@ -294,12 +332,25 @@ function getVueChildSlot(vueInstance, templateElement) {
294
332
  }
295
333
  return undefined;
296
334
  }
335
+ /**
336
+ * Collect the component slot directive instance.
337
+ *
338
+ * @param {any} vnode - represents Vue components slot instance.
339
+ * @returns {any} the slot instance of the directive.
340
+ */
297
341
  function getSlot(vnode) {
298
342
  var slot = (vnode.componentOptions && vnode.componentOptions.children) ? vnode.componentOptions :
299
343
  (!vnode.data && (vnode.tag === 'e-markersettings' || vnode.tag === 'e-markersetting')) ? vnode : vnode.data;
300
344
  return vnode.componentInstance ? vnode.componentInstance : slot;
301
345
  }
302
- // Get the Vue3 slot template from the root or current Vue component.
346
+ /**
347
+ * Get the Vue3 slot template from the root or current Vue component.
348
+ *
349
+ * @param {any} vueInstance - represents parent Vue instance.
350
+ * @param {any} templateElement - represents component property value
351
+ * @param {any} root - represents root Vue instance
352
+ * @returns {any} slot template instance
353
+ */
303
354
  function getCurrentVueSlot(vueInstance, templateElement, root) {
304
355
  if (!vueInstance && !(root && root.vueInstance)) {
305
356
  return undefined;
@@ -307,6 +358,13 @@ function getCurrentVueSlot(vueInstance, templateElement, root) {
307
358
  var slots = (root && root.vueInstance) ? root.vueInstance.$slots : vueInstance.$slots;
308
359
  return getChildVueSlot(slots, templateElement);
309
360
  }
361
+ /**
362
+ * Get the Vue3 nested slot template from the root or current Vue component.
363
+ *
364
+ * @param {any} slots - represents slot instance.
365
+ * @param {any} templateElement - represents component property value
366
+ * @returns {any} nested template Vue instance
367
+ */
310
368
  function getChildVueSlot(slots, templateElement) {
311
369
  if (slots && slots["" + templateElement]) {
312
370
  return slots;
package/tslint.json ADDED
@@ -0,0 +1,111 @@
1
+ {
2
+ "rules": {
3
+ "chai-vague-errors": true,
4
+ "use-isnan": true,
5
+ "missing-jsdoc": true,
6
+ "missing-optional-annotation": true,
7
+ "no-backbone-get-set-outside-model": true,
8
+ "no-banned-terms": true,
9
+ "no-constant-condition": true,
10
+ "no-control-regex": true,
11
+ "no-cookies": true,
12
+ "no-delete-expression": true,
13
+ "no-document-write": true,
14
+ "no-document-domain": true,
15
+ "no-disable-auto-sanitization": true,
16
+ "no-duplicate-case": true,
17
+ "no-duplicate-parameter-names": true,
18
+ "no-empty-interfaces": true,
19
+ "no-exec-script": true,
20
+ "no-function-constructor-with-string-args": true,
21
+ "no-function-expression": true,
22
+ "no-invalid-regexp": true,
23
+ "no-for-in": true,
24
+ "member-access": true,
25
+ "no-multiline-string": true,
26
+ "no-multiple-var-decl": true,
27
+ "no-unnecessary-bind": true,
28
+ "no-unnecessary-semicolons": true,
29
+ "no-octal-literal": true,
30
+ "no-regex-spaces": true,
31
+ "no-sparse-arrays": true,
32
+ "no-string-based-set-immediate": true,
33
+ "no-string-based-set-interval": true,
34
+ "no-unused-imports": true,
35
+ "no-with-statement": true,
36
+ "prefer-array-literal": true,
37
+ "promise-must-complete": false,
38
+ "react-no-dangerous-html": true,
39
+ "use-named-parameter": true,
40
+ "valid-typeof": true,
41
+ "max-func-body-length": [true, 100, {
42
+ "ignore-parameters-to-function-regex": "describe"
43
+ }],
44
+ "class-name": true,
45
+ "curly": true,
46
+ "eofline": false,
47
+ "forin": true,
48
+ "indent": [
49
+ true,
50
+ "spaces"
51
+ ],
52
+ "label-position": true,
53
+ "max-line-length": [true, 140],
54
+ "no-arg": true,
55
+ "no-console": [true,
56
+ "debug",
57
+ "info",
58
+ "log",
59
+ "time",
60
+ "timeEnd",
61
+ "trace"
62
+ ],
63
+ "no-construct": true,
64
+ "no-parameter-properties": true,
65
+ "no-debugger": true,
66
+ "no-duplicate-variable": true,
67
+ "no-empty": true,
68
+ "no-eval": true,
69
+ "no-string-literal": true,
70
+ "no-switch-case-fall-through": true,
71
+ "trailing-comma": true,
72
+ "no-trailing-whitespace": true,
73
+ "no-unused-expression": true,
74
+ "no-use-before-declare": false,
75
+ "no-var-requires": true,
76
+ "one-line": [true,
77
+ "check-open-brace",
78
+ "check-catch",
79
+ "check-else",
80
+ "check-whitespace"
81
+ ],
82
+ "no-any": true,
83
+ "no-conditional-assignment": true,
84
+ "no-angle-bracket-type-assertion": false,
85
+ "align": [true, "parameters", "arguments", "statements"],
86
+ "no-empty-line-after-opening-brace": false,
87
+ "typedef-whitespace": [false],
88
+ "ban": true,
89
+ "quotemark": [true, "single"],
90
+ "semicolon": true,
91
+ "triple-equals": [true, "allow-null-check"],
92
+ "typedef": [true,
93
+ "call-signature",
94
+ "parameter",
95
+ "property-declaration",
96
+ "variable-declaration",
97
+ "arrow-parameter",
98
+ "member-variable-declaration"],
99
+ "variable-name": true,
100
+ "whitespace": [true,
101
+ "check-branch",
102
+ "check-decl",
103
+ "check-operator",
104
+ "check-separator",
105
+ "check-type"
106
+ ],
107
+ "jsdoc-format": true,
108
+ "no-var-keyword": true,
109
+ "radix": true
110
+ }
111
+ }