@syncfusion/ej2-vue-base 31.2.2 → 31.2.5

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,361 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */
2
- import { setTemplateEngine, getTemplateEngine, getUniqueID, createElement, detach, extend, getValue } from '@syncfusion/ej2-base';
3
- import { aVue as Vue, isExecute } from './component-base';
4
-
5
- const stringCompiler: (template: string, helper?: object) => (data: Object | JSON) => string = getTemplateEngine();
6
-
7
- /**
8
- * Compiler function that convert the template property to DOM element.
9
- *
10
- * @param {any} templateElement - represents value of the template property from the component.
11
- * @param {Object} helper - represents helper object to utilize on template compilation.
12
- * @returns {NodeList} template element that append to the component.
13
- */
14
- export function compile(
15
- templateElement: any,
16
- helper?: Object
17
- ): (data: Object | JSON, component?: any, propName?: any, element?: any, root?: any) => Object {
18
- return (data: any, context: any, propName: any, element: any, root: any): any => {
19
- let returnEle: any;
20
- if (context) {
21
- let plugins: any = context.vueInstance && context.vueInstance.plugins ? { plugins: context.vueInstance.plugins } : {};
22
- const vueInstance: any = context.vueInstance ? context.vueInstance :
23
- ((root && root.vueInstance) ? root.vueInstance : null);
24
- const pid: string = getUniqueID('templateParentDiv');
25
- const id: string = getUniqueID('templateDiv');
26
- const ele: HTMLElement = createElement('div', {
27
- id: pid,
28
- innerHTML: '<div id="' + id + '"></div>'
29
- });
30
- document.body.appendChild(ele);
31
- if (!isExecute && (typeof templateElement === 'string' || (templateElement.prototype && templateElement.prototype.CSPTemplate && typeof templateElement === 'function'))) {
32
- const vueSlot: any = getCurrentVueSlot(context.vueInstance, templateElement, root);
33
- if (vueSlot) {
34
- // Compilation for Vue 3 slot template
35
- const app: any = Vue.createVNode({
36
- render(): any {
37
- return vueSlot[`${templateElement}`]({ data: data });
38
- }
39
- }, plugins);
40
- ele.innerHTML = '';
41
- // Get values for Vue 3 slot template
42
- getValues(app, context.vueInstance, root);
43
- Vue.render(app, ele);
44
- returnEle = ele.childNodes;
45
- if (vueInstance) {
46
- let templateInstance: any = vueInstance.templateCollection;
47
- if (!templateInstance) {
48
- vueInstance.templateCollection = {};
49
- templateInstance = vueInstance.templateCollection;
50
- }
51
- if (propName) {
52
- if (!templateInstance[`${propName}`]) {
53
- templateInstance[`${propName}`] = [];
54
- }
55
- templateInstance[`${propName}`].push(ele);
56
- }
57
- }
58
- detach(ele);
59
- } else {
60
- // Compilation for Vue 3 string template
61
- detach(ele);
62
- return stringCompiler(templateElement, helper)(data);
63
- }
64
- } else if (!isExecute) {
65
- // Compilation for Vue 3 functional template
66
- const tempObj: any = templateElement.call(this, {});
67
- const object: any = tempObj;
68
- const propsData: any = getValue('template.propsData', tempObj);
69
- const dataObj: any = {
70
- data: { data: extend(tempObj.data || {}, data) },
71
- parent: context.vueInstance
72
- };
73
- if (!object.template) {
74
- object.template = object[Object.keys(object)[0]];
75
- }
76
- let templateCompRef: any;
77
- if (object.template.extends) {
78
- templateCompRef = object.template.extends._context.components.template;
79
- } else {
80
- templateCompRef = object.template._context.components[templateElement.name];
81
- if (!templateCompRef) {
82
- const key: any = Object.keys(object.template._context.components)[0];
83
- templateCompRef = object.template._context.components[`${key}`];
84
- }
85
- }
86
- let tempRef: any;
87
- if (propsData) {
88
- if (templateCompRef.setup) {
89
- tempRef = (<any>Object).assign({}, propsData);
90
- } else {
91
- tempRef = (<any>Object).assign(templateCompRef.data(), propsData);
92
- }
93
- }
94
- else {
95
- if (templateCompRef.setup) {
96
- tempRef = (<any>Object).assign({}, dataObj.data);
97
- } else {
98
- tempRef = (<any>Object).assign(templateCompRef.data(), dataObj.data);
99
- }
100
- if (templateCompRef.components) {
101
- const objkeys: any = Object.keys(templateCompRef.components) || [];
102
- for (const objstring of objkeys) {
103
- const intComponent: any = templateCompRef.components[`${objstring}`];
104
- if (intComponent && intComponent.data) {
105
- if (!intComponent.__data) { intComponent.__data = intComponent.data; }
106
- intComponent.data = function (proxy: any): Object {
107
- return (Object as any).assign(intComponent.__data.call(proxy), dataObj.data);
108
- };
109
- }
110
- }
111
- }
112
- }
113
- if (templateCompRef.setup) {
114
- plugins = (<any>Object).assign(plugins, data);
115
- }
116
- templateCompRef.data = function (): any { return tempRef; };
117
- const app: any = Vue.createVNode(templateCompRef, plugins);
118
- ele.innerHTML = '';
119
- // Get values for Vue 3 functional template
120
- getValues(app, context.vueInstance, root);
121
- Vue.render(app, ele);
122
- returnEle = ele.childNodes;
123
- dataObj.parent = null;
124
- if (vueInstance) {
125
- let templateInstance: any = vueInstance.templateCollection;
126
- if (!templateInstance) {
127
- vueInstance.templateCollection = {};
128
- templateInstance = vueInstance.templateCollection;
129
- }
130
- if (propName) {
131
- if (!templateInstance[`${propName}`]) {
132
- templateInstance[`${propName}`] = [];
133
- }
134
- templateInstance[`${propName}`].push(ele);
135
- }
136
- }
137
- detach(ele);
138
- } else if (typeof templateElement === 'string' || (templateElement.prototype && templateElement.prototype.CSPTemplate && typeof templateElement === 'function')) {
139
- const vueSlot: any = getVueSlot(context.vueInstance, templateElement, root);
140
- if (vueSlot) {
141
- // Get provide values for Vue 2 slot template
142
- let provided: any = {};
143
- const getProvideValues: any = (vueinstance: any) => {
144
- if (vueinstance['$parent']) { getProvideValues(vueinstance.$parent); }
145
- if (vueinstance['_provided'] && Object.keys(vueinstance['_provided']).length > 0) {
146
- provided = { ...provided, ...vueinstance._provided };
147
- }
148
- };
149
- const vueInstance: any = context.vueInstance ? context.vueInstance :
150
- ((root && root.vueInstance) ? root.vueInstance : null);
151
- if (vueInstance) {
152
- getProvideValues(vueInstance);
153
- }
154
- // Compilation for Vue 2 slot template
155
- const vueTemplate: any = new Vue({
156
- provide: { ...provided },
157
- render(): any {
158
- return vueSlot[`${templateElement}`]({ data: data });
159
- }
160
- });
161
- vueTemplate.$mount('#' + id);
162
- returnEle = ele.childNodes;
163
- if (vueInstance) {
164
- let templateInstance: any = vueInstance.templateCollection;
165
- if (!templateInstance) {
166
- vueInstance.templateCollection = {};
167
- templateInstance = vueInstance.templateCollection;
168
- }
169
- if (propName) {
170
- if (!templateInstance[`${propName}`]) {
171
- templateInstance[`${propName}`] = [];
172
- }
173
- templateInstance[`${propName}`].push(returnEle[0]);
174
- }
175
- }
176
- detach(ele);
177
- } else {
178
- // Compilation for Vue 2 string template
179
- detach(ele);
180
- return stringCompiler(templateElement, helper)(data);
181
- }
182
- } else {
183
- // Compilation for Vue 2 functional template
184
- const tempObj: any = templateElement.call(this, {});
185
- let templateFunction: any = tempObj.template;
186
- const propsData: any = getValue('template.propsData', tempObj);
187
- const dataObj: any = {
188
- data: { data: extend(tempObj.data || {}, data) },
189
- parent: context.vueInstance
190
- };
191
- if (propsData) {
192
- templateFunction = tempObj.template.extends;
193
- dataObj.propsData = propsData;
194
- }
195
- if (typeof templateFunction !== 'function') {
196
- templateFunction = Vue.extend(templateFunction);
197
- }
198
- if (templateFunction.options.setup) {
199
- dataObj.propsData = (<any>Object).assign(dataObj.propsData || {}, data);
200
- }
201
- const templateVue: any = new templateFunction(dataObj);
202
- // let templateVue = new Vue(tempObj.template);
203
- // templateVue.$data.data = extend(tempObj.data, data);
204
- templateVue.$mount('#' + id);
205
- returnEle = ele.childNodes;
206
- dataObj.parent = null;
207
- if (vueInstance) {
208
- let templateInstance: any = vueInstance.templateCollection;
209
- if (!templateInstance) {
210
- vueInstance.templateCollection = {};
211
- templateInstance = vueInstance.templateCollection;
212
- }
213
- if (propName) {
214
- if (!templateInstance[`${propName}`]) {
215
- templateInstance[`${propName}`] = [];
216
- }
217
- templateInstance[`${propName}`].push(returnEle[0]);
218
- }
219
- }
220
- detach(ele);
221
- }
222
- }
223
- return returnEle || [];
224
- };
225
- }
226
-
227
- setTemplateEngine({ compile: compile as any });
228
-
229
- /**
230
- * Collect values from the app instance.
231
- *
232
- * @param {any} app - represents global application instance
233
- * @param {any} cInstance - represents Vue component instance
234
- * @param {any} root - represents parent component instance
235
- * @returns {void}
236
- */
237
- function getValues(app: any, cInstance: any, root: any): void {
238
- const vueInstance: any = cInstance ? cInstance : ((root && root.vueInstance) ? root.vueInstance : null);
239
- if (!vueInstance) {
240
- return;
241
- }
242
- // Get globally defined variables.
243
- app['appContext'] = vueInstance['$']['appContext'];
244
- // Get provide value from child component.
245
- let provided: any = {};
246
- const getProvideValue: any = (vueinstance: any) => {
247
- if (vueinstance['$'] && vueinstance['$']['parent']) { getProvideValue(vueinstance.$.parent); }
248
- if (vueinstance['provides'] && Object.keys(vueinstance['provides']).length > 0) {
249
- provided = { ...provided, ...vueinstance.provides };
250
- }
251
- };
252
- getProvideValue(vueInstance);
253
- if (app['appContext']['provides']) {
254
- app.appContext.provides = { ...app.appContext.provides, ...provided };
255
- }
256
- }
257
-
258
- /**
259
- * Get the Vue2 slot template from the root or current Vue component.
260
- *
261
- * @param {any} vueInstance - represents parent Vue instance.
262
- * @param {any} templateElement - represents component property value
263
- * @param {any} root - represents root Vue instance
264
- * @returns {any} template Vue instance
265
- */
266
- function getVueSlot(vueInstance: any, templateElement: any, root: any): any {
267
- if (!vueInstance && !(root && root.vueInstance)) {
268
- return undefined;
269
- }
270
- const instance: any = (root && root.vueInstance) ? root.vueInstance : vueInstance;
271
- return getVueChildSlot(instance, templateElement);
272
- }
273
-
274
- /**
275
- * Get the Vue2 nested slot template from the root or current Vue component.
276
- *
277
- * @param {any} vueInstance - represents parent Vue instance.
278
- * @param {any} templateElement - represents component property value
279
- * @returns {any} nested template Vue instance
280
- */
281
- function getVueChildSlot(vueInstance: any, templateElement: any): any {
282
- if (!vueInstance) {
283
- return undefined;
284
- }
285
- const slots: any = vueInstance.$slots;
286
- const scopedSlots: any = vueInstance.$scopedSlots;
287
- const vSlots: any = vueInstance.scopedSlots;
288
- const children: any = vueInstance.children;
289
- if (scopedSlots && scopedSlots[`${templateElement}`]) {
290
- return scopedSlots;
291
- } else if (slots && slots.default) {
292
- const childSlots: any = slots.default;
293
- for (let i: number = 0; i < childSlots.length; i++) {
294
- const slot: any = getVueChildSlot(getSlot(childSlots[parseInt(i.toString(), 10)]), templateElement);
295
- if (slot) {
296
- return slot;
297
- }
298
- }
299
- } else if (vSlots && vSlots[`${templateElement}`]) {
300
- return vSlots;
301
- } else if (children) {
302
- for (let i: number = 0; i < children.length; i++) {
303
- const slot: any = getVueChildSlot(getSlot(children[parseInt(i.toString(), 10)]), templateElement);
304
- if (slot) {
305
- return slot;
306
- }
307
- }
308
- }
309
- return undefined;
310
- }
311
-
312
- /**
313
- * Collect the component slot directive instance.
314
- *
315
- * @param {any} vnode - represents Vue components slot instance.
316
- * @returns {any} the slot instance of the directive.
317
- */
318
- function getSlot(vnode: any): any {
319
- const slot: any = (vnode.componentOptions && vnode.componentOptions.children) ? vnode.componentOptions :
320
- (!vnode.data && (vnode.tag === 'e-markersettings' || vnode.tag === 'e-markersetting')) ? vnode : vnode.data;
321
- return vnode.componentInstance ? vnode.componentInstance : slot;
322
- }
323
-
324
- /**
325
- * Get the Vue3 slot template from the root or current Vue component.
326
- *
327
- * @param {any} vueInstance - represents parent Vue instance.
328
- * @param {any} templateElement - represents component property value
329
- * @param {any} root - represents root Vue instance
330
- * @returns {any} slot template instance
331
- */
332
- function getCurrentVueSlot(vueInstance: any, templateElement: any, root: any): any {
333
- if (!vueInstance && !(root && root.vueInstance)) {
334
- return undefined;
335
- }
336
- const slots: any = (root && root.vueInstance) ? root.vueInstance.$slots : vueInstance.$slots;
337
- return getChildVueSlot(slots, templateElement);
338
- }
339
-
340
- /**
341
- * Get the Vue3 nested slot template from the root or current Vue component.
342
- *
343
- * @param {any} slots - represents slot instance.
344
- * @param {any} templateElement - represents component property value
345
- * @returns {any} nested template Vue instance
346
- */
347
- function getChildVueSlot(slots: any, templateElement: any): any {
348
- if (slots && slots[`${templateElement}`]) {
349
- return slots;
350
- } else if (slots && slots.default) {
351
- let childSlots: any = slots.default();
352
- childSlots = childSlots.flatMap((item: any) => Array.isArray(item.children) ? item.children : item);
353
- for (let i: number = 0; i < childSlots.length; i++) {
354
- const slot: any = getChildVueSlot(childSlots[parseInt(i.toString(), 10)].children, templateElement);
355
- if (slot) {
356
- return slot;
357
- }
358
- }
359
- }
360
- return undefined;
361
- }
@@ -1,15 +0,0 @@
1
- // @ts-ignore
2
- import Vue, { VueConstructor } from 'vue';
3
- // @ts-ignore
4
- import { DefineComponent } from 'vue';
5
-
6
- interface CommonProps {
7
- isLazyUpdate?: Boolean,
8
- plugins?: any[]
9
- }
10
-
11
- // @ts-ignore
12
- export type DefineVueComponent<Props> = typeof Vue.compile extends (template: string) => Function ? DefineComponent<Props & CommonProps, any, {}, {}, {}, {}, {}, {}, string, Props & CommonProps, Props & CommonProps, {}> : VueConstructor<Vue<{}, Props & CommonProps>>;
13
-
14
- //@ts-ignore
15
- export type DefineVueDirective<Props> = typeof Vue.compile extends (template: string) => Function ? DefineComponent<Props, any, {}, {}, {}, {}, {}, {}, string, Props, Props, {}> : VueConstructor<Vue<{}, Props>>;