@syncfusion/ej2-vue-base 34.1.29 → 34.1.32

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
@@ -13,6 +13,137 @@ var __assign = (this && this.__assign) || function () {
13
13
  import { setTemplateEngine, getTemplateEngine, getUniqueID, createElement, detach, extend, getValue } from '@syncfusion/ej2-base';
14
14
  import { aVue as Vue, isExecute } from './component-base';
15
15
  var stringCompiler = getTemplateEngine();
16
+ /**
17
+ * Returns true if the given Vue 3 component instance is inside a keep-alive.
18
+ *
19
+ * @param {any} vueInstance - Vue component instance.
20
+ * @returns {boolean} Returns true when inside keep-alive.
21
+ */
22
+ function isInsideKeepAlive(vueInstance) {
23
+ var parent = vueInstance && vueInstance.$ && vueInstance.$.parent;
24
+ while (parent) {
25
+ if (parent.type && parent.type.__isKeepAlive) {
26
+ return true;
27
+ }
28
+ parent = parent.parent;
29
+ }
30
+ return false;
31
+ }
32
+ /**
33
+ * Collect activated/deactivated hooks from rendered vnode tree.
34
+ *
35
+ * @param {any} vnode - VNode instance.
36
+ * @param {any[]} out - Collection of hooks.
37
+ * @returns {void}
38
+ */
39
+ function collectHooks(vnode, out) {
40
+ if (!vnode) {
41
+ return;
42
+ }
43
+ var ci = vnode.component;
44
+ if (ci && ci.type && ci.proxy && !ci.isUnmounted) {
45
+ if (typeof ci.type.activated === 'function' ||
46
+ typeof ci.type.deactivated === 'function') {
47
+ out.push({
48
+ activated: ci.type.activated ?
49
+ ci.type.activated.bind(ci.proxy) : null,
50
+ deactivated: ci.type.deactivated ?
51
+ ci.type.deactivated.bind(ci.proxy) : null
52
+ });
53
+ }
54
+ collectHooks(ci.subTree, out);
55
+ }
56
+ if (Array.isArray(vnode.children)) {
57
+ for (var i = 0; i < vnode.children.length; i++) {
58
+ // eslint-disable-next-line security/detect-object-injection
59
+ collectHooks(vnode.children[i], out);
60
+ }
61
+ }
62
+ }
63
+ /**
64
+ * Collect hooks from template collection.
65
+ *
66
+ * @param {any} proxy - Vue component proxy.
67
+ * @returns {any[]} Returns collected hooks.
68
+ */
69
+ function collectFromTemplates(proxy) {
70
+ var hooks = [];
71
+ var tc = proxy.templateCollection;
72
+ if (!tc) {
73
+ return hooks;
74
+ }
75
+ var keys = Object.keys(tc);
76
+ for (var k = 0; k < keys.length; k++) {
77
+ // eslint-disable-next-line security/detect-object-injection
78
+ var key = keys[k];
79
+ // eslint-disable-next-line security/detect-object-injection
80
+ var elems = tc[key];
81
+ for (var i = 0; i < elems.length; i++) {
82
+ // eslint-disable-next-line security/detect-object-injection
83
+ var ele = elems[i];
84
+ if (ele && ele._vnode) {
85
+ collectHooks(ele._vnode, hooks);
86
+ }
87
+ }
88
+ }
89
+ return hooks;
90
+ }
91
+ /**
92
+ * Patch keep-alive lifecycle handling for slot templates.
93
+ *
94
+ * @param {any} vueInstance - Vue component instance.
95
+ * @param {any} app - Rendered vnode.
96
+ * @returns {void}
97
+ */
98
+ function patchKeepAlive(vueInstance, app) {
99
+ // Walk up to find the direct child of keep-alive.
100
+ var start = vueInstance.$;
101
+ var cur = start;
102
+ var keepAliveChild = null;
103
+ while (cur) {
104
+ if (cur.parent &&
105
+ cur.parent.type &&
106
+ cur.parent.type.__isKeepAlive) {
107
+ keepAliveChild = cur;
108
+ break;
109
+ }
110
+ cur = cur.parent;
111
+ }
112
+ if (!keepAliveChild) {
113
+ return;
114
+ }
115
+ // templateCollection is on ejs-grid vueInstance
116
+ var gridProxy = vueInstance;
117
+ if (!keepAliveChild.isDeactivated) {
118
+ var immediateHooks = [];
119
+ collectHooks(app, immediateHooks);
120
+ immediateHooks.forEach(function (h) {
121
+ var activated = h.activated;
122
+ if (activated) {
123
+ activated();
124
+ }
125
+ });
126
+ }
127
+ if (!keepAliveChild._sfPatched) {
128
+ keepAliveChild._sfPatched = true;
129
+ (keepAliveChild.a || (keepAliveChild.a = [])).push(function () {
130
+ collectFromTemplates(gridProxy).forEach(function (h) {
131
+ var activated = h.activated;
132
+ if (activated) {
133
+ activated();
134
+ }
135
+ });
136
+ });
137
+ (keepAliveChild.da || (keepAliveChild.da = [])).push(function () {
138
+ collectFromTemplates(gridProxy).forEach(function (h) {
139
+ var deactivated = h.deactivated;
140
+ if (deactivated) {
141
+ deactivated();
142
+ }
143
+ });
144
+ });
145
+ }
146
+ }
16
147
  /**
17
148
  * Compiler function that convert the template property to DOM element.
18
149
  *
@@ -61,6 +192,10 @@ export function compile(templateElement, helper) {
61
192
  }
62
193
  templateInstance["" + propName].push(ele);
63
194
  }
195
+ // Keep-alive support for Vue 3 slot templates.
196
+ if (isInsideKeepAlive(vueInstance)) {
197
+ patchKeepAlive(vueInstance, app);
198
+ }
64
199
  }
65
200
  detach(ele);
66
201
  }