vite-plugin-taro-runtime 0.7.12-beta.0 → 0.7.12
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/dist/api/dist/tools.d.ts +1 -1
- package/dist/api/dist/tools.js +1 -1
- package/dist/api/dist/tools.js.map +1 -1
- package/dist/components/dist/components/taro-image-core.js +13 -12
- package/dist/components/dist/components/taro-scroll-view-core.js +8 -3
- package/dist/components/dist/components/taro-web-view-core.js +48 -1
- package/dist/components/types/Button.d.ts +7 -0
- package/dist/components/types/Image.d.ts +6 -0
- package/dist/components/types/Input.d.ts +1 -1
- package/dist/components/types/ScrollView.d.ts +5 -0
- package/dist/components/types/Textarea.d.ts +1 -1
- package/dist/components/types/common.d.ts +24 -1
- package/dist/plugin-framework-react/runtime.js +29 -67
- package/dist/plugin-framework-react/runtime.js.map +1 -1
- package/dist/plugin-platform-h5/definition.json +3 -5
- package/dist/plugin-platform-weapp/runtime-utils.js +1 -0
- package/dist/plugin-platform-weapp/runtime-utils.js.map +1 -1
- package/dist/plugin-platform-weapp/runtime.js +1 -0
- package/dist/plugin-platform-weapp/runtime.js.map +1 -1
- package/dist/plugin-platform-weapp/types/components.d.ts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/react.esm.js +12 -113
- package/dist/react/renderer-host.d.ts +8 -0
- package/dist/runtime/bom/document.js +1 -1
- package/dist/runtime/dom/element.d.ts +4 -0
- package/dist/runtime/dom/element.js +9 -1
- package/dist/runtime/dom/element.js.map +1 -1
- package/dist/runtime/dom/nearest-ctx.d.ts +9 -0
- package/dist/runtime/dom/nearest-ctx.js +49 -0
- package/dist/runtime/dom/nearest-ctx.js.map +1 -0
- package/dist/runtime/dom/node.d.ts +15 -2
- package/dist/runtime/dom/node.js +71 -59
- package/dist/runtime/dom/node.js.map +1 -1
- package/dist/runtime/dom/root.d.ts +2 -0
- package/dist/runtime/dom/root.js +12 -14
- package/dist/runtime/dom/root.js.map +1 -1
- package/dist/runtime/dom/style.d.ts +2 -0
- package/dist/runtime/dom/style.js +15 -14
- package/dist/runtime/dom/style.js.map +1 -1
- package/dist/runtime/dom/text.d.ts +5 -0
- package/dist/runtime/dom/text.js +8 -4
- package/dist/runtime/dsl/common.d.ts +1 -1
- package/dist/runtime/dsl/common.js +18 -9
- package/dist/runtime/dsl/common.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/runtime.esm.d.ts +9 -2
- package/dist/runtime/runtime.esm.js +81 -13
- package/dist/runtime/runtime.esm.js.map +1 -1
- package/dist/taro/package.json +9 -9
- package/dist/taro/types/api/device/clipboard.d.ts +5 -0
- package/dist/taro/types/api/network/request.d.ts +7 -3
- package/dist/taro/types/api/network/upload.d.ts +21 -1
- package/dist/taro/types/api/payment/index.d.ts +58 -0
- package/dist/taro/types/compile/compiler.d.ts +13 -0
- package/dist/taro/types/compile/hooks.d.ts +1 -0
- package/dist/taro/types/taro.config.d.ts +64 -0
- package/dist/taro-h5/dist/api/base/weapp/app-event.js +15 -5
- package/dist/taro-h5/dist/api/base/weapp/app-event.js.map +1 -1
- package/dist/taro-h5/dist/api/device/clipboard.js +10 -6
- package/dist/taro-h5/dist/api/device/clipboard.js.map +1 -1
- package/dist/taro-h5/dist/api/media/map.d.ts +14 -1
- package/dist/taro-h5/dist/api/media/map.js +72 -2
- package/dist/taro-h5/dist/api/media/map.js.map +1 -1
- package/dist/taro-h5/dist/api/taro.d.ts +1 -1
- package/dist/taro-h5/dist/api/taro.js +3 -3
- package/dist/taro-h5/dist/api/taro.js.map +1 -1
- package/dist/taro-h5/dist/api/wxml/IntersectionObserver.js +3 -0
- package/dist/taro-h5/dist/api/wxml/IntersectionObserver.js.map +1 -1
- package/package.json +22 -16
- package/types/tt-document.d.ts +38 -0
package/dist/runtime/dom/node.js
CHANGED
|
@@ -6,6 +6,7 @@ import { hydrate } from '../hydrate.js';
|
|
|
6
6
|
import { incrementId, isComment, extend } from '../utils/index.js';
|
|
7
7
|
import { eventSource } from './event-source.js';
|
|
8
8
|
import { TaroEventTarget } from './event-target.js';
|
|
9
|
+
import { getNearestCtx, bumpNearestCtxEpochForRoot } from './nearest-ctx.js';
|
|
9
10
|
|
|
10
11
|
const CHILDNODES = "cn" /* Shortcuts.Childnodes */;
|
|
11
12
|
const nodeId = incrementId();
|
|
@@ -19,7 +20,8 @@ class TaroNode extends TaroEventTarget {
|
|
|
19
20
|
this.sid = this.uid; // dom 节点全局唯一 id,不可被修改
|
|
20
21
|
eventSource.set(this.sid, this);
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
/** Delegates a complete child-list update; the default hydrates lazily or emits an empty list. */
|
|
24
|
+
delegateChildReset(isClean) {
|
|
23
25
|
const cleanChildNodes = () => [];
|
|
24
26
|
const rerenderChildNodes = () => {
|
|
25
27
|
const childNodes = this.childNodes.filter(node => !isComment(node));
|
|
@@ -46,6 +48,9 @@ class TaroNode extends TaroEventTarget {
|
|
|
46
48
|
var _a;
|
|
47
49
|
return ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a._root) || null;
|
|
48
50
|
}
|
|
51
|
+
get _scope() {
|
|
52
|
+
return getNearestCtx(this);
|
|
53
|
+
}
|
|
49
54
|
findIndex(refChild) {
|
|
50
55
|
const index = this.childNodes.indexOf(refChild);
|
|
51
56
|
ensure(index !== -1, 'The node to be replaced is not a child of this node.');
|
|
@@ -97,13 +102,13 @@ class TaroNode extends TaroEventTarget {
|
|
|
97
102
|
this.removeChild(this.firstChild, { doUpdate: false });
|
|
98
103
|
}
|
|
99
104
|
if (text === '') {
|
|
100
|
-
this.
|
|
105
|
+
this.delegateChildReset(true);
|
|
101
106
|
}
|
|
102
107
|
else {
|
|
103
108
|
const newText = env.document.createTextNode(text);
|
|
104
109
|
addedNodes.push(newText);
|
|
105
110
|
this.appendChild(newText);
|
|
106
|
-
this.
|
|
111
|
+
this.delegateChildReset();
|
|
107
112
|
}
|
|
108
113
|
// @Todo: appendChild 会多触发一次
|
|
109
114
|
MutationObserver.record({
|
|
@@ -145,51 +150,11 @@ class TaroNode extends TaroEventTarget {
|
|
|
145
150
|
// appendChild
|
|
146
151
|
this.childNodes.push(newChild);
|
|
147
152
|
}
|
|
148
|
-
|
|
149
|
-
//
|
|
153
|
+
// Delegation runs after the logical insertion, including on detached parents.
|
|
154
|
+
// Its default implementation prepares template payloads; native hosts can replace it before any serialization work.
|
|
155
|
+
this.delegateChildInsertion(newChild, refChild, index, isReplace);
|
|
150
156
|
if (this._root) {
|
|
151
|
-
|
|
152
|
-
// appendChild
|
|
153
|
-
const isOnlyChild = childNodesLength === 1;
|
|
154
|
-
if (isOnlyChild) {
|
|
155
|
-
this.updateChildNodes();
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
this.enqueueUpdate({
|
|
159
|
-
path: newChild._path,
|
|
160
|
-
value: this.hydrate(newChild)
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else if (isReplace) {
|
|
165
|
-
// replaceChild
|
|
166
|
-
this.enqueueUpdate({
|
|
167
|
-
path: newChild._path,
|
|
168
|
-
value: this.hydrate(newChild)
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
// insertBefore 有两种更新模式
|
|
173
|
-
// 比方说有 A B C 三个节点,现在要在 C 前插入 D
|
|
174
|
-
// 1. 插入 D,然后更新整个父节点的 childNodes 数组
|
|
175
|
-
// setData({ cn: [A, B, D, C] })
|
|
176
|
-
// 2. 插入 D,然后更新 D 以及 D 之后每个节点的数据
|
|
177
|
-
// setData ({
|
|
178
|
-
// cn.[2]: D,
|
|
179
|
-
// cn.[3]: C,
|
|
180
|
-
// })
|
|
181
|
-
// 由于微信解析 ’cn.[2]‘ 这些路径的时候也需要消耗时间,
|
|
182
|
-
// 所以根据 insertBefore 插入的位置来做不同的处理
|
|
183
|
-
const mark = childNodesLength * 2 / 3;
|
|
184
|
-
if (mark > index) {
|
|
185
|
-
// 如果 insertBefore 的位置在 childNodes 的 2/3 前,则为了避免解析路径消耗过多的时间,采用第一种方式
|
|
186
|
-
this.updateChildNodes();
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
// 如果 insertBefore 的位置在 childNodes 的 2/3 之后,则采用第二种方式,避免 childNodes 的全量更新
|
|
190
|
-
this.updateSingleChild(index);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
157
|
+
bumpNearestCtxEpochForRoot(this._root);
|
|
193
158
|
}
|
|
194
159
|
MutationObserver.record({
|
|
195
160
|
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
@@ -263,12 +228,68 @@ class TaroNode extends TaroEventTarget {
|
|
|
263
228
|
if (cleanRef !== false) {
|
|
264
229
|
eventSource.removeNodeTree(child);
|
|
265
230
|
}
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
-
|
|
231
|
+
// Forward every removal. doUpdate controls template batching, not whether the logical child was removed.
|
|
232
|
+
this.delegateChildRemoval(child, options);
|
|
233
|
+
if (this._root) {
|
|
234
|
+
bumpNearestCtxEpochForRoot(this._root);
|
|
269
235
|
}
|
|
270
236
|
return child;
|
|
271
237
|
}
|
|
238
|
+
/** Delegates an insertion after Taro has updated parentNode and childNodes. */
|
|
239
|
+
delegateChildInsertion(newChild, refChild, index, isReplace) {
|
|
240
|
+
const childNodesLength = this.childNodes.length;
|
|
241
|
+
// Serialization
|
|
242
|
+
if (this._root) {
|
|
243
|
+
if (!refChild) {
|
|
244
|
+
// appendChild
|
|
245
|
+
const isOnlyChild = childNodesLength === 1;
|
|
246
|
+
if (isOnlyChild) {
|
|
247
|
+
this.delegateChildReset();
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
this.enqueueUpdate({
|
|
251
|
+
path: newChild._path,
|
|
252
|
+
value: this.hydrate(newChild)
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (isReplace) {
|
|
257
|
+
// replaceChild
|
|
258
|
+
this.enqueueUpdate({
|
|
259
|
+
path: newChild._path,
|
|
260
|
+
value: this.hydrate(newChild)
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
// insertBefore 有两种更新模式
|
|
265
|
+
// 比方说有 A B C 三个节点,现在要在 C 前插入 D
|
|
266
|
+
// 1. 插入 D,然后更新整个父节点的 childNodes 数组
|
|
267
|
+
// setData({ cn: [A, B, D, C] })
|
|
268
|
+
// 2. 插入 D,然后更新 D 以及 D 之后每个节点的数据
|
|
269
|
+
// setData ({
|
|
270
|
+
// cn.[2]: D,
|
|
271
|
+
// cn.[3]: C,
|
|
272
|
+
// })
|
|
273
|
+
// 由于微信解析 ’cn.[2]‘ 这些路径的时候也需要消耗时间,
|
|
274
|
+
// 所以根据 insertBefore 插入的位置来做不同的处理
|
|
275
|
+
const mark = childNodesLength * 2 / 3;
|
|
276
|
+
if (mark > index) {
|
|
277
|
+
// 如果 insertBefore 的位置在 childNodes 的 2/3 前,则为了避免解析路径消耗过多的时间,采用第一种方式
|
|
278
|
+
this.delegateChildReset();
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
// 如果 insertBefore 的位置在 childNodes 的 2/3 之后,则采用第二种方式,避免 childNodes 的全量更新
|
|
282
|
+
this.updateSingleChild(index);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/** Delegates a removal after logical detachment and event identity cleanup. */
|
|
288
|
+
delegateChildRemoval(_child, options) {
|
|
289
|
+
if (this._root && options.doUpdate !== false) {
|
|
290
|
+
this.delegateChildReset();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
272
293
|
remove(options) {
|
|
273
294
|
var _a;
|
|
274
295
|
(_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this, options);
|
|
@@ -277,15 +298,6 @@ class TaroNode extends TaroEventTarget {
|
|
|
277
298
|
return this.childNodes.length > 0;
|
|
278
299
|
}
|
|
279
300
|
enqueueUpdate(payload) {
|
|
280
|
-
/*
|
|
281
|
-
* The outlet is the structural boundary between singleton App hosts and Page roots in Taro's in-memory tree. Its
|
|
282
|
-
* children must remain attached there for React ancestry, event ownership, unmounting, and Taro parent links, while
|
|
283
|
-
* each Page root independently schedules its own page.* native updates. Allowing outlet child mutations to bubble
|
|
284
|
-
* into the App scheduler would fan Page topology out as app.* data and duplicate work across every mounted Page.
|
|
285
|
-
* Suppress only this native update propagation; do not change the in-memory childNodes relationship.
|
|
286
|
-
*/
|
|
287
|
-
if (this.nodeName === 'vpt_page_outlet')
|
|
288
|
-
return;
|
|
289
301
|
var _a;
|
|
290
302
|
(_a = this._root) === null || _a === void 0 ? void 0 : _a.enqueueUpdate(payload);
|
|
291
303
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sources":["../../../src/dom/node.ts"],"sourcesContent":["import { ensure, hooks, Shortcuts } from '@tarojs/shared'\n\nimport { DOCUMENT_FRAGMENT } from '../constants'\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer'\nimport env from '../env'\nimport { hydrate } from '../hydrate'\nimport { extend, incrementId, isComment } from '../utils'\nimport { eventSource } from './event-source'\nimport { TaroEventTarget } from './event-target'\nimport { NodeType } from './node_types'\n\nimport type { TFunc, UpdatePayload } from '../interface'\nimport type { TaroDocument } from './document'\nimport type { TaroElement } from './element'\nimport type { TaroRootElement } from './root'\n\ninterface RemoveChildOptions {\n cleanRef?: boolean\n doUpdate?: boolean\n}\n\nconst CHILDNODES = Shortcuts.Childnodes\nconst nodeId = incrementId()\n\nexport class TaroNode extends TaroEventTarget {\n public uid: string\n public sid: string\n public nodeType: NodeType\n public nodeName: string\n public parentNode: TaroNode | null = null\n public childNodes: TaroNode[] = []\n\n public constructor () {\n super()\n this.uid = '_' + nodeId() // dom 节点 id,开发者可修改\n this.sid = this.uid // dom 节点全局唯一 id,不可被修改\n eventSource.set(this.sid, this)\n }\n\n private hydrate = (node: TaroNode) => () => hydrate(node as TaroElement)\n\n private updateChildNodes (isClean?: boolean) {\n const cleanChildNodes = () => []\n const rerenderChildNodes = () => {\n const childNodes = this.childNodes.filter(node => !isComment(node))\n return childNodes.map(hydrate)\n }\n\n this.enqueueUpdate({\n path: `${this._path}.${CHILDNODES}`,\n value: isClean ? cleanChildNodes : rerenderChildNodes\n })\n }\n\n private updateSingleChild (index: number) {\n this.childNodes.forEach((child, childIndex) => {\n if (isComment(child)) return\n\n if (index && childIndex < index) return\n\n this.enqueueUpdate({\n path: child._path,\n value: this.hydrate(child)\n })\n })\n }\n\n public get _root (): TaroRootElement | null {\n return this.parentNode?._root || null\n }\n\n protected findIndex (refChild: TaroNode): number {\n const index = this.childNodes.indexOf(refChild)\n\n ensure(index !== -1, 'The node to be replaced is not a child of this node.')\n\n return index\n }\n\n public get _path (): string {\n const parentNode = this.parentNode\n\n if (parentNode) {\n // 计算路径时,先过滤掉 comment 节点\n const list = parentNode.childNodes.filter(node => !isComment(node))\n const indexOfNode = list.indexOf(this)\n const index = hooks.call('getPathIndex', indexOfNode)\n\n return `${parentNode._path}.${CHILDNODES}.${index}`\n }\n\n return ''\n }\n\n public get nextSibling (): TaroNode | null {\n const parentNode = this.parentNode\n return parentNode?.childNodes[parentNode.findIndex(this) + 1] || null\n }\n\n public get previousSibling (): TaroNode | null {\n const parentNode = this.parentNode\n return parentNode?.childNodes[parentNode.findIndex(this) - 1] || null\n }\n\n public get parentElement (): TaroElement | null {\n const parentNode = this.parentNode\n if (parentNode?.nodeType === NodeType.ELEMENT_NODE) {\n return parentNode as TaroElement\n }\n return null\n }\n\n public get firstChild (): TaroNode | null {\n return this.childNodes[0] || null\n }\n\n public get lastChild (): TaroNode | null {\n const childNodes = this.childNodes\n return childNodes[childNodes.length - 1] || null\n }\n\n /**\n * @textContent 目前只能置空子元素\n * @TODO 等待完整 innerHTML 实现\n */\n // eslint-disable-next-line accessor-pairs\n public set textContent (text: string) {\n const removedNodes = this.childNodes.slice()\n const addedNodes: TaroNode[] = []\n\n // Handle old children' data structure & ref\n while (this.firstChild) {\n this.removeChild(this.firstChild, { doUpdate: false })\n }\n\n if (text === '') {\n this.updateChildNodes(true)\n } else {\n const newText = env.document.createTextNode(text)\n addedNodes.push(newText)\n this.appendChild(newText)\n this.updateChildNodes()\n }\n\n // @Todo: appendChild 会多触发一次\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n removedNodes,\n addedNodes\n })\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/insertBefore\n * @scenario\n * [A,B,C]\n * 1. insert D before C, D has no parent\n * 2. insert D before C, D has the same parent of C\n * 3. insert D before C, D has the different parent of C\n */\n public insertBefore<T extends TaroNode> (newChild: T, refChild?: TaroNode | null, isReplace?: boolean): T {\n if (newChild.nodeName === DOCUMENT_FRAGMENT) {\n newChild.childNodes.reduceRight((previousValue, currentValue) => {\n this.insertBefore(currentValue, previousValue)\n return currentValue\n }, refChild)\n return newChild\n }\n\n // Parent release newChild\n // - cleanRef: false (No need to clean eventSource, because newChild is about to be inserted)\n // - update: true (Need to update parent.childNodes, because parent.childNodes is reordered)\n newChild.remove({ cleanRef: false })\n\n let index = 0\n // Data structure\n newChild.parentNode = this\n if (refChild) {\n // insertBefore & replaceChild\n index = this.findIndex(refChild)\n this.childNodes.splice(index, 0, newChild)\n } else {\n // appendChild\n this.childNodes.push(newChild)\n }\n\n const childNodesLength = this.childNodes.length\n // Serialization\n if (this._root) {\n if (!refChild) {\n // appendChild\n const isOnlyChild = childNodesLength === 1\n if (isOnlyChild) {\n this.updateChildNodes()\n } else {\n this.enqueueUpdate({\n path: newChild._path,\n value: this.hydrate(newChild)\n })\n }\n } else if (isReplace) {\n // replaceChild\n this.enqueueUpdate({\n path: newChild._path,\n value: this.hydrate(newChild)\n })\n } else {\n // insertBefore 有两种更新模式\n // 比方说有 A B C 三个节点,现在要在 C 前插入 D\n // 1. 插入 D,然后更新整个父节点的 childNodes 数组\n // setData({ cn: [A, B, D, C] })\n // 2. 插入 D,然后更新 D 以及 D 之后每个节点的数据\n // setData ({\n // cn.[2]: D,\n // cn.[3]: C,\n // })\n // 由于微信解析 ’cn.[2]‘ 这些路径的时候也需要消耗时间,\n // 所以根据 insertBefore 插入的位置来做不同的处理\n const mark = childNodesLength * 2 / 3\n if (mark > index) {\n // 如果 insertBefore 的位置在 childNodes 的 2/3 前,则为了避免解析路径消耗过多的时间,采用第一种方式\n this.updateChildNodes()\n } else {\n // 如果 insertBefore 的位置在 childNodes 的 2/3 之后,则采用第二种方式,避免 childNodes 的全量更新\n this.updateSingleChild(index)\n }\n }\n }\n\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n addedNodes: [newChild],\n removedNodes: isReplace\n ? [refChild as TaroNode] /** replaceChild */\n : [],\n nextSibling: isReplace\n ? (refChild as TaroNode).nextSibling /** replaceChild */\n : (refChild || null), /** insertBefore & appendChild */\n previousSibling: newChild.previousSibling\n })\n\n return newChild\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/appendChild\n * @scenario\n * [A,B,C]\n * 1. append C, C has no parent\n * 2. append C, C has the same parent of B\n * 3. append C, C has the different parent of B\n */\n public appendChild (newChild: TaroNode) {\n return this.insertBefore(newChild)\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/replaceChild\n * @scenario\n * [A,B,C]\n * 1. replace B with C, C has no parent\n * 2. replace B with C, C has no parent, C has the same parent of B\n * 3. replace B with C, C has no parent, C has the different parent of B\n */\n public replaceChild (newChild: TaroNode, oldChild: TaroNode) {\n if (oldChild.parentNode !== this) return\n\n // Insert the newChild\n this.insertBefore(newChild, oldChild, true)\n\n // Destroy the oldChild\n // - cleanRef: true (Need to clean eventSource, because the oldChild was detached from the DOM tree)\n // - update: false (No need to update parent.childNodes, because replace will not cause the parent.childNodes being reordered)\n oldChild.remove({ doUpdate: false })\n\n return oldChild\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/removeChild\n * @scenario\n * [A,B,C]\n * 1. remove A or B\n * 2. remove C\n */\n public removeChild<T extends TaroNode> (child: T, options: RemoveChildOptions = {}): T {\n const { cleanRef, doUpdate } = options\n\n if (cleanRef !== false && doUpdate !== false) {\n // appendChild/replaceChild/insertBefore 不应该触发\n // @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n removedNodes: [child],\n nextSibling: child.nextSibling,\n previousSibling: child.previousSibling\n })\n }\n\n // Data Structure\n const index = this.findIndex(child)\n this.childNodes.splice(index, 1)\n child.parentNode = null\n\n // Set eventSource\n if (cleanRef !== false) {\n eventSource.removeNodeTree(child)\n }\n\n // Serialization\n if (this._root && doUpdate !== false) {\n this.updateChildNodes()\n }\n\n return child\n }\n\n public remove (options?: RemoveChildOptions) {\n this.parentNode?.removeChild(this, options)\n }\n\n public hasChildNodes () {\n return this.childNodes.length > 0\n }\n\n public enqueueUpdate (payload: UpdatePayload) {\n this._root?.enqueueUpdate(payload)\n }\n\n public get ownerDocument (): TaroDocument {\n return env.document\n }\n\n static extend (methodName: string, options: TFunc | Record<string, any>) {\n extend(TaroNode, methodName, options)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAqBA,MAAM,UAAU;AAChB,MAAM,MAAM,GAAG,WAAW,EAAE;AAEtB,MAAO,QAAS,SAAQ,eAAe,CAAA;AAQ3C,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;QAJF,IAAU,CAAA,UAAA,GAAoB,IAAI;QAClC,IAAU,CAAA,UAAA,GAAe,EAAE;AAS1B,QAAA,IAAA,CAAA,OAAO,GAAG,CAAC,IAAc,KAAK,MAAM,OAAO,CAAC,IAAmB,CAAC;QALtE,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,MAAM,EAAE,CAAA;QACzB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA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C;AACxB,aAAA,CAAC;;;QAIJ,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;QACnC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;AAChC,QAAA,KAAK,CAAC,UAAU,GAAG,IAAI;;AAGvB,QAAA,IAAI,QAAQ,KAAK,KAAK,EAAE;AACtB,YAAA,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC;;;QAInC,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,KAAK,KAAK,EAAE;YACpC,IAAI,CAAC,gBAAgB,EAAE;;AAGzB,QAAA,OAAO,KAAK;;AAGP,IAAA,MAAM,CAAE,OAA4B,EAAA;;QACzC,CAAA,EAAA,GAAA,IAAI,CAAC,UAAU,MAAE,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAA,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC;;IAGtC,aAAa,GAAA;AAClB,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;;AAG5B,IAAA,aAAa,CAAE,OAAsB,EAAA;;QAC1C,CAAA,EAAA,GAAA,IAAI,CAAC,KAAK,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAE,aAAa,CAAC,OAAO,CAAC;;AAGpC,IAAA,IAAW,aAAa,GAAA;QACtB,OAAO,GAAG,CAAC,QAAQ;;AAGrB,IAAA,OAAO,MAAM,CAAE,UAAkB,EAAE,OAAoC,EAAA;AACrE,QAAA,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC;;AAExC;;;;"}
|
|
1
|
+
{"version":3,"file":"node.js","sources":["../../../src/dom/node.ts"],"sourcesContent":["import { ensure, hooks, Shortcuts } from '@tarojs/shared'\n\nimport { DOCUMENT_FRAGMENT } from '../constants'\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer'\nimport env from '../env'\nimport { hydrate } from '../hydrate'\nimport { extend, incrementId, isComment } from '../utils'\nimport { eventSource } from './event-source'\nimport { TaroEventTarget } from './event-target'\nimport { bumpNearestCtxEpochForRoot, getNearestCtx } from './nearest-ctx'\nimport { NodeType } from './node_types'\n\nimport type { MpInstance, TFunc, UpdatePayload } from '../interface'\nimport type { TaroDocument } from './document'\nimport type { TaroElement } from './element'\nimport type { TaroRootElement } from './root'\n\ninterface RemoveChildOptions {\n cleanRef?: boolean\n doUpdate?: boolean\n}\n\nconst CHILDNODES = Shortcuts.Childnodes\nconst nodeId = incrementId()\n\nexport class TaroNode extends TaroEventTarget {\n public uid: string\n public sid: string\n public nodeType: NodeType\n public nodeName: string\n public parentNode: TaroNode | null = null\n public childNodes: TaroNode[] = []\n\n public constructor () {\n super()\n this.uid = '_' + nodeId() // dom 节点 id,开发者可修改\n this.sid = this.uid // dom 节点全局唯一 id,不可被修改\n eventSource.set(this.sid, this)\n }\n\n private hydrate = (node: TaroNode) => () => hydrate(node as TaroElement)\n\n private updateChildNodes (isClean?: boolean) {\n const cleanChildNodes = () => []\n const rerenderChildNodes = () => {\n const childNodes = this.childNodes.filter(node => !isComment(node))\n return childNodes.map(hydrate)\n }\n\n this.enqueueUpdate({\n path: `${this._path}.${CHILDNODES}`,\n value: isClean ? cleanChildNodes : rerenderChildNodes\n })\n }\n\n private updateSingleChild (index: number) {\n this.childNodes.forEach((child, childIndex) => {\n if (isComment(child)) return\n\n if (index && childIndex < index) return\n\n this.enqueueUpdate({\n path: child._path,\n value: this.hydrate(child)\n })\n })\n }\n\n public get _root (): TaroRootElement | null {\n return this.parentNode?._root || null\n }\n\n public get _scope (): MpInstance | null | undefined {\n return getNearestCtx(this)\n }\n\n protected findIndex (refChild: TaroNode): number {\n const index = this.childNodes.indexOf(refChild)\n\n ensure(index !== -1, 'The node to be replaced is not a child of this node.')\n\n return index\n }\n\n public get _path (): string {\n const parentNode = this.parentNode\n\n if (parentNode) {\n // 计算路径时,先过滤掉 comment 节点\n const list = parentNode.childNodes.filter(node => !isComment(node))\n const indexOfNode = list.indexOf(this)\n const index = hooks.call('getPathIndex', indexOfNode)\n\n return `${parentNode._path}.${CHILDNODES}.${index}`\n }\n\n return ''\n }\n\n public get nextSibling (): TaroNode | null {\n const parentNode = this.parentNode\n return parentNode?.childNodes[parentNode.findIndex(this) + 1] || null\n }\n\n public get previousSibling (): TaroNode | null {\n const parentNode = this.parentNode\n return parentNode?.childNodes[parentNode.findIndex(this) - 1] || null\n }\n\n public get parentElement (): TaroElement | null {\n const parentNode = this.parentNode\n if (parentNode?.nodeType === NodeType.ELEMENT_NODE) {\n return parentNode as TaroElement\n }\n return null\n }\n\n public get firstChild (): TaroNode | null {\n return this.childNodes[0] || null\n }\n\n public get lastChild (): TaroNode | null {\n const childNodes = this.childNodes\n return childNodes[childNodes.length - 1] || null\n }\n\n /**\n * @textContent 目前只能置空子元素\n * @TODO 等待完整 innerHTML 实现\n */\n // eslint-disable-next-line accessor-pairs\n public set textContent (text: string) {\n const removedNodes = this.childNodes.slice()\n const addedNodes: TaroNode[] = []\n\n // Handle old children' data structure & ref\n while (this.firstChild) {\n this.removeChild(this.firstChild, { doUpdate: false })\n }\n\n if (text === '') {\n this.updateChildNodes(true)\n } else {\n const newText = env.document.createTextNode(text)\n addedNodes.push(newText)\n this.appendChild(newText)\n this.updateChildNodes()\n }\n\n // @Todo: appendChild 会多触发一次\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n removedNodes,\n addedNodes\n })\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/insertBefore\n * @scenario\n * [A,B,C]\n * 1. insert D before C, D has no parent\n * 2. insert D before C, D has the same parent of C\n * 3. insert D before C, D has the different parent of C\n */\n public insertBefore<T extends TaroNode> (newChild: T, refChild?: TaroNode | null, isReplace?: boolean): T {\n if (newChild.nodeName === DOCUMENT_FRAGMENT) {\n newChild.childNodes.reduceRight((previousValue, currentValue) => {\n this.insertBefore(currentValue, previousValue)\n return currentValue\n }, refChild)\n return newChild\n }\n\n // Parent release newChild\n // - cleanRef: false (No need to clean eventSource, because newChild is about to be inserted)\n // - update: true (Need to update parent.childNodes, because parent.childNodes is reordered)\n newChild.remove({ cleanRef: false })\n\n let index = 0\n // Data structure\n newChild.parentNode = this\n if (refChild) {\n // insertBefore & replaceChild\n index = this.findIndex(refChild)\n this.childNodes.splice(index, 0, newChild)\n } else {\n // appendChild\n this.childNodes.push(newChild)\n }\n\n const childNodesLength = this.childNodes.length\n // Serialization\n if (this._root) {\n if (!refChild) {\n // appendChild\n const isOnlyChild = childNodesLength === 1\n if (isOnlyChild) {\n this.updateChildNodes()\n } else {\n this.enqueueUpdate({\n path: newChild._path,\n value: this.hydrate(newChild)\n })\n }\n } else if (isReplace) {\n // replaceChild\n this.enqueueUpdate({\n path: newChild._path,\n value: this.hydrate(newChild)\n })\n } else {\n // insertBefore 有两种更新模式\n // 比方说有 A B C 三个节点,现在要在 C 前插入 D\n // 1. 插入 D,然后更新整个父节点的 childNodes 数组\n // setData({ cn: [A, B, D, C] })\n // 2. 插入 D,然后更新 D 以及 D 之后每个节点的数据\n // setData ({\n // cn.[2]: D,\n // cn.[3]: C,\n // })\n // 由于微信解析 ’cn.[2]‘ 这些路径的时候也需要消耗时间,\n // 所以根据 insertBefore 插入的位置来做不同的处理\n const mark = childNodesLength * 2 / 3\n if (mark > index) {\n // 如果 insertBefore 的位置在 childNodes 的 2/3 前,则为了避免解析路径消耗过多的时间,采用第一种方式\n this.updateChildNodes()\n } else {\n // 如果 insertBefore 的位置在 childNodes 的 2/3 之后,则采用第二种方式,避免 childNodes 的全量更新\n this.updateSingleChild(index)\n }\n }\n }\n\n if (this._root) {\n bumpNearestCtxEpochForRoot(this._root)\n }\n\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n addedNodes: [newChild],\n removedNodes: isReplace\n ? [refChild as TaroNode] /** replaceChild */\n : [],\n nextSibling: isReplace\n ? (refChild as TaroNode).nextSibling /** replaceChild */\n : (refChild || null), /** insertBefore & appendChild */\n previousSibling: newChild.previousSibling\n })\n\n return newChild\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/appendChild\n * @scenario\n * [A,B,C]\n * 1. append C, C has no parent\n * 2. append C, C has the same parent of B\n * 3. append C, C has the different parent of B\n */\n public appendChild (newChild: TaroNode) {\n return this.insertBefore(newChild)\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/replaceChild\n * @scenario\n * [A,B,C]\n * 1. replace B with C, C has no parent\n * 2. replace B with C, C has no parent, C has the same parent of B\n * 3. replace B with C, C has no parent, C has the different parent of B\n */\n public replaceChild (newChild: TaroNode, oldChild: TaroNode) {\n if (oldChild.parentNode !== this) return\n\n // Insert the newChild\n this.insertBefore(newChild, oldChild, true)\n\n // Destroy the oldChild\n // - cleanRef: true (Need to clean eventSource, because the oldChild was detached from the DOM tree)\n // - update: false (No need to update parent.childNodes, because replace will not cause the parent.childNodes being reordered)\n oldChild.remove({ doUpdate: false })\n\n return oldChild\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/removeChild\n * @scenario\n * [A,B,C]\n * 1. remove A or B\n * 2. remove C\n */\n public removeChild<T extends TaroNode> (child: T, options: RemoveChildOptions = {}): T {\n const { cleanRef, doUpdate } = options\n\n if (cleanRef !== false && doUpdate !== false) {\n // appendChild/replaceChild/insertBefore 不应该触发\n // @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n removedNodes: [child],\n nextSibling: child.nextSibling,\n previousSibling: child.previousSibling\n })\n }\n\n // Data Structure\n const index = this.findIndex(child)\n this.childNodes.splice(index, 1)\n child.parentNode = null\n\n // Set eventSource\n if (cleanRef !== false) {\n eventSource.removeNodeTree(child)\n }\n\n // Serialization\n if (this._root && doUpdate !== false) {\n this.updateChildNodes()\n }\n\n if (this._root) {\n bumpNearestCtxEpochForRoot(this._root)\n }\n\n return child\n }\n\n public remove (options?: RemoveChildOptions) {\n this.parentNode?.removeChild(this, options)\n }\n\n public hasChildNodes () {\n return this.childNodes.length > 0\n }\n\n public enqueueUpdate (payload: UpdatePayload) {\n this._root?.enqueueUpdate(payload)\n }\n\n public get ownerDocument (): TaroDocument {\n return env.document\n }\n\n static extend (methodName: string, options: TFunc | Record<string, any>) {\n extend(TaroNode, methodName, options)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAsBA,MAAM,UAAU;AAChB,MAAM,MAAM,GAAG,WAAW,EAAE;AAEtB,MAAO,QAAS,SAAQ,eAAe,CAAA;AAQ3C,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;QAJF,IAAU,CAAA,UAAA,GAAoB,IAAI;QAClC,IAAU,CAAA,UAAA,GAAe,EAAE;AAS1B,QAAA,IAAA,CAAA,OAAO,GAAG,CAAC,IAAc,KAAK,MAAM,OAAO,CAAC,IAAmB,CAAC;QALtE,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,MAAM,EAAE,CAAA;QACzB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;QACnB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;;AAKzB,IAAA,gBAAgB,CAAE,OAAiB,EAAA;AACzC,QAAA,MAAM,eAAe,GAAG,MAAM,EAAE;QAChC,MAAM,kBAAkB,GAAG,MAAK;AAC9B,YAAA,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACnE,YAAA,OAAO,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC;AAChC,SAAC;QAED,IAAI,CAAC,aAAa,CAAC;AACjB,YAAA,IAAI,EAAE,CAAG,EAAA,IAAI,CAAC,KAAK,CAAA,CAAA,EAAI,UAAU,CAAE,CAAA;YACnC,KAAK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Q,KAAK,KAAK,EAAE;YACpC,IAAI,CAAC,gBAAgB,EAAE;;AAGzB,QAAA,IAAI,IAAI,CAAC,KAAK,EAAE;AACd,YAAA,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC;;AAGxC,QAAA,OAAO,KAAK;;AAGP,IAAA,MAAM,CAAE,OAA4B,EAAA;;QACzC,CAAA,EAAA,GAAA,IAAI,CAAC,UAAU,MAAE,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAA,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC;;IAGtC,aAAa,GAAA;AAClB,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;;AAG5B,IAAA,aAAa,CAAE,OAAsB,EAAA;;QAC1C,CAAA,EAAA,GAAA,IAAI,CAAC,KAAK,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAE,aAAa,CAAC,OAAO,CAAC;;AAGpC,IAAA,IAAW,aAAa,GAAA;QACtB,OAAO,GAAG,CAAC,QAAQ;;AAGrB,IAAA,OAAO,MAAM,CAAE,UAAkB,EAAE,OAAoC,EAAA;AACrE,QAAA,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC;;AAExC;;;;"}
|
|
@@ -8,9 +8,11 @@ declare class TaroRootElement extends TaroElement {
|
|
|
8
8
|
private updateCallbacks;
|
|
9
9
|
pendingUpdate: boolean;
|
|
10
10
|
ctx: null | MpInstance;
|
|
11
|
+
nearestCtxEpoch: number;
|
|
11
12
|
constructor();
|
|
12
13
|
get _path(): string;
|
|
13
14
|
get _root(): TaroRootElement;
|
|
15
|
+
bumpNearestCtxEpoch(): void;
|
|
14
16
|
scheduleTask(fn: TFunc): void;
|
|
15
17
|
enqueueUpdate(payload: UpdatePayload): void;
|
|
16
18
|
performUpdate(initRender?: boolean, prerender?: TFunc): void;
|
package/dist/runtime/dom/root.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hooks, isFunction, isArray, isUndefined } from '@tarojs/shared';
|
|
2
|
-
import { ROOT_STR, SET_DATA, PAGE_INIT, CUSTOM_WRAPPER
|
|
2
|
+
import { ROOT_STR, SET_DATA, PAGE_INIT, CUSTOM_WRAPPER } from '../constants/index.js';
|
|
3
3
|
import { options } from '../options.js';
|
|
4
4
|
import { perf } from '../perf.js';
|
|
5
5
|
import { isComment, customWrapperCache } from '../utils/index.js';
|
|
@@ -45,22 +45,19 @@ class TaroRootElement extends TaroElement {
|
|
|
45
45
|
this.updateCallbacks = [];
|
|
46
46
|
this.pendingUpdate = false;
|
|
47
47
|
this.ctx = null;
|
|
48
|
+
this.nearestCtxEpoch = 0;
|
|
48
49
|
this.nodeName = ROOT_STR;
|
|
49
50
|
this.tagName = ROOT_STR.toUpperCase();
|
|
50
51
|
}
|
|
51
52
|
get _path() {
|
|
52
|
-
|
|
53
|
-
* Both the singleton App host and every Page host are now real TaroRootElement schedulers. Their structural parent
|
|
54
|
-
* distinguishes ownership without a mode flag: the App root is the sole root directly below the document's
|
|
55
|
-
* <container>, while Page roots live below vpt_page_outlet. Every descendant derives its setData path from this one
|
|
56
|
-
* prefix, yielding direct app.* and page.* payloads without host overrides or per-update path translation. nodeName
|
|
57
|
-
* remains root in both cases, preserving Taro's host, event, and scheduler semantics.
|
|
58
|
-
*/
|
|
59
|
-
return this.parentNode && this.parentNode.nodeName === CONTAINER ? 'app' : 'page';
|
|
53
|
+
return ROOT_STR;
|
|
60
54
|
}
|
|
61
55
|
get _root() {
|
|
62
56
|
return this;
|
|
63
57
|
}
|
|
58
|
+
bumpNearestCtxEpoch() {
|
|
59
|
+
this.nearestCtxEpoch++;
|
|
60
|
+
}
|
|
64
61
|
scheduleTask(fn) {
|
|
65
62
|
// 这里若使用微任务可略微提前setData的执行时机,但在部分场景下可能会出现连续setData两次,造成更大的性能问题
|
|
66
63
|
setTimeout(fn);
|
|
@@ -79,13 +76,14 @@ class TaroRootElement extends TaroElement {
|
|
|
79
76
|
perf.start(setDataMark);
|
|
80
77
|
const data = Object.create(null);
|
|
81
78
|
/*
|
|
82
|
-
* During the first render Taro replaces the leading child
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
79
|
+
* During the first render Taro replaces the leading child and removes redundant descendant writes from that
|
|
80
|
+
* same batch. Reset paths must use the root's actual _path, just like ordinary descendant payloads: VPT's App
|
|
81
|
+
* and Page schedulers use app.* and page.*, while the default root uses root.*. Recognize both indexed-path
|
|
82
|
+
* spellings so descendant writes are discarded before their lazy values are evaluated. Initial and
|
|
83
|
+
* steady-state scheduling therefore share one namespace for every root.
|
|
86
84
|
*/
|
|
87
85
|
const resetPaths = new Set(initRender
|
|
88
|
-
? [
|
|
86
|
+
? [`${this._path}.cn.[0]`, `${this._path}.cn[0]`]
|
|
89
87
|
: []);
|
|
90
88
|
while (this.updatePayloads.length > 0) {
|
|
91
89
|
const { path, value } = this.updatePayloads.shift();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","sources":["../../../src/dom/root.ts"],"sourcesContent":["import { hooks, isArray, isFunction, isUndefined, Shortcuts } from '@tarojs/shared'\n\nimport {\n CUSTOM_WRAPPER,\n PAGE_INIT,\n ROOT_STR,\n SET_DATA\n} from '../constants'\nimport { options } from '../options'\nimport { perf } from '../perf'\nimport { customWrapperCache, isComment } from '../utils'\nimport { TaroElement } from './element'\n\nimport type { HydratedData, MpInstance, TFunc, UpdatePayload, UpdatePayloadValue } from '../interface'\n\nfunction findCustomWrapper (root: TaroRootElement, dataPathArr: string[]) {\n // ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']\n const list = dataPathArr.slice(1)\n let currentData: any = root\n let customWrapper: Record<string, any> | undefined\n let splitedPath = ''\n\n list.some((item, i) => {\n const key = item\n // '[0]' => '0'\n .replace(/^\\[(.+)\\]$/, '$1')\n // 'cn' => 'childNodes'\n .replace(/\\bcn\\b/g, 'childNodes')\n\n currentData = currentData[key]\n\n if (isArray(currentData)) {\n currentData = currentData.filter(el => !isComment(el))\n }\n\n if (isUndefined(currentData)) return true\n\n if (currentData.nodeName === CUSTOM_WRAPPER) {\n const res = customWrapperCache.get(currentData.sid)\n if (res) {\n customWrapper = res\n splitedPath = dataPathArr.slice(i + 2).join('.')\n }\n }\n })\n\n if (customWrapper) {\n return {\n customWrapper,\n splitedPath\n }\n }\n}\n\nexport class TaroRootElement extends TaroElement {\n private updatePayloads: UpdatePayload[] = []\n\n private updateCallbacks: TFunc[] = []\n\n public pendingUpdate = false\n\n public ctx: null | MpInstance = null\n\n public constructor () {\n super()\n this.nodeName = ROOT_STR\n this.tagName = ROOT_STR.toUpperCase()\n }\n\n public get _path (): string {\n return ROOT_STR\n }\n\n public get _root (): TaroRootElement {\n return this\n }\n\n public scheduleTask(fn: TFunc) {\n // 这里若使用微任务可略微提前setData的执行时机,但在部分场景下可能会出现连续setData两次,造成更大的性能问题\n setTimeout(fn)\n }\n\n public enqueueUpdate (payload: UpdatePayload): void {\n this.updatePayloads.push(payload)\n\n if (!this.pendingUpdate && this.ctx) {\n this.performUpdate()\n }\n }\n\n public performUpdate (initRender = false, prerender?: TFunc) {\n this.pendingUpdate = true\n\n const ctx = hooks.call('proxyToRaw', this.ctx)!\n\n this.scheduleTask(() => {\n const setDataMark = `${SET_DATA} 开始时间戳 ${Date.now()}`\n perf.start(setDataMark)\n const data: Record<string, UpdatePayloadValue | ReturnType<HydratedData>> = Object.create(null)\n const resetPaths = new Set<string>(\n initRender\n ? ['root.cn.[0]', 'root.cn[0]']\n : []\n )\n\n while (this.updatePayloads.length > 0) {\n const { path, value } = this.updatePayloads.shift()!\n if (path.endsWith(Shortcuts.Childnodes)) {\n resetPaths.add(path)\n }\n data[path] = value\n }\n\n for (const path in data) {\n resetPaths.forEach(p => {\n // 已经重置了数组,就不需要分别再设置了\n if (path.includes(p) && path !== p) {\n delete data[path]\n }\n })\n\n const value = data[path]\n if (isFunction(value)) {\n data[path] = value()\n }\n }\n\n // 预渲染\n if (isFunction(prerender)) return prerender(data)\n\n // 正常渲染\n this.pendingUpdate = false\n let normalUpdate = {}\n const customWrapperMap: Map<Record<any, any>, Record<string, any>> = new Map()\n\n if (initRender) {\n // 初次渲染,使用页面级别的 setData\n normalUpdate = data\n } else {\n // 更新渲染,区分 CustomWrapper 与页面级别的 setData\n for (const p in data) {\n const dataPathArr = p.split('.')\n const found = findCustomWrapper(this, dataPathArr)\n if (found) {\n // 此项数据使用 CustomWrapper 去更新\n const { customWrapper, splitedPath } = found\n // 合并同一个 customWrapper 的相关更新到一次 setData 中\n customWrapperMap.set(customWrapper, {\n ...(customWrapperMap.get(customWrapper) || {}),\n [`i.${splitedPath}`]: data[p]\n })\n } else {\n // 此项数据使用页面去更新\n normalUpdate[p] = data[p]\n }\n }\n }\n\n const customWrapperCount = customWrapperMap.size\n const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0\n const updateArrLen = customWrapperCount + (isNeedNormalUpdate ? 1 : 0)\n let executeTime = 0\n\n const cb = () => {\n if (++executeTime === updateArrLen) {\n perf.stop(setDataMark)\n this.flushUpdateCallback()\n initRender && perf.stop(PAGE_INIT)\n }\n }\n\n // custom-wrapper setData\n if (customWrapperCount) {\n customWrapperMap.forEach((data, ctx) => {\n if (process.env.NODE_ENV !== 'production' && options.debug) {\n // eslint-disable-next-line no-console\n console.log('custom wrapper setData: ', data)\n }\n ctx.setData(data, cb)\n })\n }\n\n // page setData\n if (isNeedNormalUpdate) {\n if (process.env.NODE_ENV !== 'production' && options.debug) {\n // eslint-disable-next-line no-console\n console.log('page setData:', normalUpdate)\n }\n ctx.setData(normalUpdate, cb)\n }\n })\n }\n\n public enqueueUpdateCallback (cb: TFunc, ctx?: Record<string, any>) {\n this.updateCallbacks.push(() => {\n ctx ? cb.call(ctx) : cb()\n })\n }\n\n public flushUpdateCallback () {\n const updateCallbacks = this.updateCallbacks\n if (!updateCallbacks.length) return\n\n const copies = updateCallbacks.slice(0)\n this.updateCallbac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AA,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC;;AAE5C,gBAAA,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;;AAEjC,SAAC,CAAC;;IAGG,qBAAqB,CAAE,EAAS,EAAE,GAAyB,EAAA;AAChE,QAAA,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAK;AAC7B,YAAA,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE;AAC3B,SAAC,CAAC;;IAGG,mBAAmB,GAAA;AACxB,QAAA,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe;QAC5C,IAAI,CAAC,eAAe,CAAC,MAAM;YAAE;QAE7B,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;AACvC,QAAA,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC;AAC/B,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACtC,YAAA,MAAM,CAAC,CAAC,CAAC,EAAE;;;AAGhB;;;;"}
|
|
1
|
+
{"version":3,"file":"root.js","sources":["../../../src/dom/root.ts"],"sourcesContent":["import { hooks, isArray, isFunction, isUndefined, Shortcuts } from '@tarojs/shared'\n\nimport {\n CUSTOM_WRAPPER,\n PAGE_INIT,\n ROOT_STR,\n SET_DATA\n} from '../constants'\nimport { options } from '../options'\nimport { perf } from '../perf'\nimport { customWrapperCache, isComment } from '../utils'\nimport { TaroElement } from './element'\n\nimport type { HydratedData, MpInstance, TFunc, UpdatePayload, UpdatePayloadValue } from '../interface'\n\nfunction findCustomWrapper (root: TaroRootElement, dataPathArr: string[]) {\n // ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']\n const list = dataPathArr.slice(1)\n let currentData: any = root\n let customWrapper: Record<string, any> | undefined\n let splitedPath = ''\n\n list.some((item, i) => {\n const key = item\n // '[0]' => '0'\n .replace(/^\\[(.+)\\]$/, '$1')\n // 'cn' => 'childNodes'\n .replace(/\\bcn\\b/g, 'childNodes')\n\n currentData = currentData[key]\n\n if (isArray(currentData)) {\n currentData = currentData.filter(el => !isComment(el))\n }\n\n if (isUndefined(currentData)) return true\n\n if (currentData.nodeName === CUSTOM_WRAPPER) {\n const res = customWrapperCache.get(currentData.sid)\n if (res) {\n customWrapper = res\n splitedPath = dataPathArr.slice(i + 2).join('.')\n }\n }\n })\n\n if (customWrapper) {\n return {\n customWrapper,\n splitedPath\n }\n }\n}\n\nexport class TaroRootElement extends TaroElement {\n private updatePayloads: UpdatePayload[] = []\n\n private updateCallbacks: TFunc[] = []\n\n public pendingUpdate = false\n\n public ctx: null | MpInstance = null\n\n public nearestCtxEpoch = 0\n\n public constructor () {\n super()\n this.nodeName = ROOT_STR\n this.tagName = ROOT_STR.toUpperCase()\n }\n\n public get _path (): string {\n return ROOT_STR\n }\n\n public get _root (): TaroRootElement {\n return this\n }\n\n public bumpNearestCtxEpoch () {\n this.nearestCtxEpoch++\n }\n\n public scheduleTask(fn: TFunc) {\n // 这里若使用微任务可略微提前setData的执行时机,但在部分场景下可能会出现连续setData两次,造成更大的性能问题\n setTimeout(fn)\n }\n\n public enqueueUpdate (payload: UpdatePayload): void {\n this.updatePayloads.push(payload)\n\n if (!this.pendingUpdate && this.ctx) {\n this.performUpdate()\n }\n }\n\n public performUpdate (initRender = false, prerender?: TFunc) {\n this.pendingUpdate = true\n\n const ctx = hooks.call('proxyToRaw', this.ctx)!\n\n this.scheduleTask(() => {\n const setDataMark = `${SET_DATA} 开始时间戳 ${Date.now()}`\n perf.start(setDataMark)\n const data: Record<string, UpdatePayloadValue | ReturnType<HydratedData>> = Object.create(null)\n const resetPaths = new Set<string>(\n initRender\n ? ['root.cn.[0]', 'root.cn[0]']\n : []\n )\n\n while (this.updatePayloads.length > 0) {\n const { path, value } = this.updatePayloads.shift()!\n if (path.endsWith(Shortcuts.Childnodes)) {\n resetPaths.add(path)\n }\n data[path] = value\n }\n\n for (const path in data) {\n resetPaths.forEach(p => {\n // 已经重置了数组,就不需要分别再设置了\n if (path.includes(p) && path !== p) {\n delete data[path]\n }\n })\n\n const value = data[path]\n if (isFunction(value)) {\n data[path] = value()\n }\n }\n\n // 预渲染\n if (isFunction(prerender)) return prerender(data)\n\n // 正常渲染\n this.pendingUpdate = false\n let normalUpdate = {}\n const customWrapperMap: Map<Record<any, any>, Record<string, any>> = new Map()\n\n if (initRender) {\n // 初次渲染,使用页面级别的 setData\n normalUpdate = data\n } else {\n // 更新渲染,区分 CustomWrapper 与页面级别的 setData\n for (const p in data) {\n const dataPathArr = p.split('.')\n const found = findCustomWrapper(this, dataPathArr)\n if (found) {\n // 此项数据使用 CustomWrapper 去更新\n const { customWrapper, splitedPath } = found\n // 合并同一个 customWrapper 的相关更新到一次 setData 中\n customWrapperMap.set(customWrapper, {\n ...(customWrapperMap.get(customWrapper) || {}),\n [`i.${splitedPath}`]: data[p]\n })\n } else {\n // 此项数据使用页面去更新\n normalUpdate[p] = data[p]\n }\n }\n }\n\n const customWrapperCount = customWrapperMap.size\n const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0\n const updateArrLen = customWrapperCount + (isNeedNormalUpdate ? 1 : 0)\n let executeTime = 0\n\n const cb = () => {\n if (++executeTime === updateArrLen) {\n perf.stop(setDataMark)\n this.flushUpdateCallback()\n initRender && perf.stop(PAGE_INIT)\n }\n }\n\n // custom-wrapper setData\n if (customWrapperCount) {\n customWrapperMap.forEach((data, ctx) => {\n if (process.env.NODE_ENV !== 'production' && options.debug) {\n // eslint-disable-next-line no-console\n console.log('custom wrapper setData: ', data)\n }\n ctx.setData(data, cb)\n })\n }\n\n // page setData\n if (isNeedNormalUpdate) {\n if (process.env.NODE_ENV !== 'production' && options.debug) {\n // eslint-disable-next-line no-console\n console.log('page setData:', normalUpdate)\n }\n ctx.setData(normalUpdate, cb)\n }\n })\n }\n\n public enqueueUpdateCallback (cb: TFunc, ctx?: Record<string, any>) {\n this.updateCallbacks.push(() => {\n ctx ? cb.call(ctx) : cb()\n })\n }\n\n public flushUpdateCallback () {\n const updateCallbacks = this.updateCallbacks\n if (!updateCallbacks.length) return\n\n const copies = updateCallbacks.slice(0)\n this.updateCallbacks.length = 0\n for (let i = 0; i < copies.length; i++) {\n copies[i]()\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;AAeA,SAAS,iBAAiB,CAAE,IAAqB,EAAE,WAAqB,EAAA;;IAEtE,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IACjC,IAAI,WAAW,GAAQ,IAAI;AAC3B,IAAA,IAAI,aAA8C;IAClD,IAAI,WAAW,GAAG,EAAE;IAEpB,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,KAAI;QACpB,MAAM,GAAG,GAAG;;AAET,aAAA,OAAO,CAAC,YAAY,EAAE,IAAI;;AAE1B,aAAA,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC;AAEnC,QAAA,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC;AAE9B,QAAA,IAAI,OAAO,CAAC,WAAW,CAAC,EAAE;AACxB,YAAA,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;;QAGxD,IAAI,WAAW,CAAC,WAAW,CAAC;AAAE,YAAA,OAAO,IAAI;AAEzC,QAAA,IAAI,WAAW,CAAC,QAAQ,KAAK,cAAc,EAAE;YAC3C,MAAM,GAAG,GAAG,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC;YACnD,IAAI,GAAG,EAAE;gBACP,aAAa,GAAG,GAAG;AACnB,gBAAA,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;;AAGtD,KAAC,CAAC;IAEF,IAAI,aAAa,EAAE;QACjB,OAAO;YACL,a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C,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC;;AAE/C,oBAAA,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;AACvB,iBAAC,CAAC;;;YAIJ,IAAI,kBAAkB,EAAE;AACtB,gBAAA,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,OAAO,CAAC,KAAK,EAAE;;AAE1D,oBAAA,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC;;AAE5C,gBAAA,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;;AAEjC,SAAC,CAAC;;IAGG,qBAAqB,CAAE,EAAS,EAAE,GAAyB,EAAA;AAChE,QAAA,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAK;AAC7B,YAAA,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE;AAC3B,SAAC,CAAC;;IAGG,mBAAmB,GAAA;AACxB,QAAA,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe;QAC5C,IAAI,CAAC,eAAe,CAAC,MAAM;YAAE;QAE7B,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;AACvC,QAAA,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC;AAC/B,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACtC,YAAA,MAAM,CAAC,CAAC,CAAC,EAAE;;;AAGhB;;;;"}
|
|
@@ -9,6 +9,8 @@ declare class Style {
|
|
|
9
9
|
private setCssVariables;
|
|
10
10
|
get cssText(): string;
|
|
11
11
|
set cssText(str: string);
|
|
12
|
+
/** Delegates after logical style changes and cssText batching, before the default template payload is prepared. */
|
|
13
|
+
delegateStyleUpdate(): void;
|
|
12
14
|
setProperty(propertyName: string, value?: string | null): void;
|
|
13
15
|
removeProperty(propertyName: string): string;
|
|
14
16
|
getPropertyValue(propertyName: string): any;
|
|
@@ -11,15 +11,6 @@ function recordCss(obj) {
|
|
|
11
11
|
oldValue: obj.cssText
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
function enqueueUpdate(obj) {
|
|
15
|
-
const element = obj._element;
|
|
16
|
-
if (element._root) {
|
|
17
|
-
element.enqueueUpdate({
|
|
18
|
-
path: `${element._path}.${"st" /* Shortcuts.Style */}`,
|
|
19
|
-
value: obj.cssText
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
14
|
function setStyle(newVal, styleKey) {
|
|
24
15
|
process.env.NODE_ENV !== 'production' && warn(isString(newVal) && newVal.length > PROPERTY_THRESHOLD, `Style 属性 ${styleKey} 的值数据量过大,可能会影响渲染性能,考虑使用 CSS 类或其它方案替代。`);
|
|
25
16
|
const old = this[styleKey];
|
|
@@ -34,7 +25,7 @@ function setStyle(newVal, styleKey) {
|
|
|
34
25
|
this._usedStyleProp.add(styleKey);
|
|
35
26
|
this._value[styleKey] = newVal;
|
|
36
27
|
}
|
|
37
|
-
!this._pending &&
|
|
28
|
+
!this._pending && this.delegateStyleUpdate();
|
|
38
29
|
}
|
|
39
30
|
function initStyle(ctor, styleProperties) {
|
|
40
31
|
const properties = {};
|
|
@@ -99,7 +90,7 @@ class Style {
|
|
|
99
90
|
});
|
|
100
91
|
if (str === '' || isUndefined(str) || isNull(str)) {
|
|
101
92
|
this._pending = false;
|
|
102
|
-
|
|
93
|
+
this.delegateStyleUpdate();
|
|
103
94
|
return;
|
|
104
95
|
}
|
|
105
96
|
const rules = str.split(';');
|
|
@@ -117,7 +108,17 @@ class Style {
|
|
|
117
108
|
this.setProperty(propName.trim(), val.trim());
|
|
118
109
|
}
|
|
119
110
|
this._pending = false;
|
|
120
|
-
|
|
111
|
+
this.delegateStyleUpdate();
|
|
112
|
+
}
|
|
113
|
+
/** Delegates the completed style mutation; cssText assignments finish their synchronous batch before calling it. */
|
|
114
|
+
delegateStyleUpdate() {
|
|
115
|
+
const element = this._element;
|
|
116
|
+
if (element._root) {
|
|
117
|
+
element.enqueueUpdate({
|
|
118
|
+
path: `${element._path}.${"st" /* Shortcuts.Style */}`,
|
|
119
|
+
value: this.cssText
|
|
120
|
+
});
|
|
121
|
+
}
|
|
121
122
|
}
|
|
122
123
|
setProperty(propertyName, value) {
|
|
123
124
|
if (propertyName[0] === '-') {
|
|
@@ -135,7 +136,7 @@ class Style {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
removeProperty(propertyName) {
|
|
138
|
-
propertyName = toCamelCase(propertyName);
|
|
139
|
+
propertyName = isCssVariable(propertyName) ? propertyName : toCamelCase(propertyName);
|
|
139
140
|
if (!this._usedStyleProp.has(propertyName)) {
|
|
140
141
|
return '';
|
|
141
142
|
}
|
|
@@ -144,7 +145,7 @@ class Style {
|
|
|
144
145
|
return value;
|
|
145
146
|
}
|
|
146
147
|
getPropertyValue(propertyName) {
|
|
147
|
-
propertyName = toCamelCase(propertyName);
|
|
148
|
+
propertyName = isCssVariable(propertyName) ? propertyName : toCamelCase(propertyName);
|
|
148
149
|
const value = this[propertyName];
|
|
149
150
|
if (!value) {
|
|
150
151
|
return '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sources":["../../../src/dom/style.ts"],"sourcesContent":["import { hooks, isArray, isNull, isString, isUndefined, Shortcuts, toCamelCase, toDashed, warn } from '@tarojs/shared'\n\nimport { PROPERTY_THRESHOLD } from '../constants'\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer'\nimport { TaroElement } from './element'\nimport { styleProperties } from './style_properties'\n\nfunction recordCss (obj: Style) {\n MutationObserver.record({\n type: MutationRecordType.ATTRIBUTES,\n target: obj._element,\n attributeName: 'style',\n oldValue: obj.cssText\n })\n}\n\nfunction enqueueUpdate (obj: Style) {\n const element = obj._element\n if (element._root) {\n element.enqueueUpdate({\n path: `${element._path}.${Shortcuts.Style}`,\n value: obj.cssText\n })\n }\n}\n\nfunction setStyle (this: Style, newVal: string, styleKey: string) {\n process.env.NODE_ENV !== 'production' && warn(\n isString(newVal) && newVal.length > PROPERTY_THRESHOLD,\n `Style 属性 ${styleKey} 的值数据量过大,可能会影响渲染性能,考虑使用 CSS 类或其它方案替代。`\n )\n\n const old = this[styleKey]\n\n if (old === newVal) return\n\n !this._pending && recordCss(this)\n\n if (isNull(newVal) || isUndefined(newVal) || newVal === '') {\n this._usedStyleProp.delete(styleKey)\n delete this._value[styleKey]\n } else {\n this._usedStyleProp.add(styleKey)\n this._value[styleKey] = newVal\n }\n\n !this._pending && enqueueUpdate(this)\n}\n\nfunction initStyle (ctor: typeof Style, styleProperties: string[]) {\n const properties = {}\n\n for (let i = 0; i < styleProperties.length; i++) {\n const styleKey = styleProperties[i]\n\n if (ctor[styleKey]) return\n\n properties[styleKey] = {\n get (this: Style) {\n const val = this._value[styleKey]\n return isNull(val) || isUndefined(val) ? '' : val\n },\n set (this: Style, newVal: string) {\n setStyle.call(this, newVal, styleKey)\n }\n }\n }\n\n Object.defineProperties(ctor.prototype, properties)\n}\n\nfunction isCssVariable (propertyName) {\n return /^--/.test(propertyName)\n}\n\nexport class Style {\n public _pending: boolean\n\n public _usedStyleProp: Set<string>\n\n public _value: Partial<CSSStyleDeclaration>\n\n public _element: TaroElement\n\n public constructor (element: TaroElement) {\n this._element = element\n this._usedStyleProp = new Set()\n this._value = {}\n }\n\n private setCssVariables (styleKey: string) {\n this.hasOwnProperty(styleKey) || Object.defineProperty(this, styleKey, {\n enumerable: true,\n configurable: true,\n get: () => {\n return this._value[styleKey] || ''\n },\n set: (newVal: string) => {\n setStyle.call(this, newVal, styleKey)\n }\n })\n }\n\n public get cssText () {\n if (!this._usedStyleProp.size) return ''\n\n const texts: string[] = []\n this._usedStyleProp.forEach(key => {\n const val = this[key]\n if (isNull(val) || isUndefined(val)) return\n let styleName = isCssVariable(key) ? key : toDashed(key)\n if (styleName.indexOf('webkit') === 0 || styleName.indexOf('Webkit') === 0) {\n styleName = `-${styleName}`\n }\n texts.push(`${styleName}: ${val};`)\n })\n return texts.join(' ')\n }\n\n public set cssText (str: string) {\n this._pending = true\n recordCss(this)\n\n this._usedStyleProp.forEach(prop => {\n this.removeProperty(prop)\n })\n\n if (str === '' || isUndefined(str) || isNull(str)) {\n this._pending = false\n enqueueUpdate(this)\n return\n }\n\n const rules = str.split(';')\n\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i].trim()\n if (rule === '') {\n continue\n }\n\n // 可能存在 'background: url(http:x/y/z)' 的情况\n const [propName, ...valList] = rule.split(':')\n const val = valList.join(':')\n\n if (isUndefined(val)) {\n continue\n }\n this.setProperty(propName.trim(), val.trim())\n }\n\n this._pending = false\n enqueueUpdate(this)\n }\n\n public setProperty (propertyName: string, value?: string | null) {\n if (propertyName[0] === '-') {\n // 支持 webkit 属性或 css 变量\n this.setCssVariables(propertyName)\n } else {\n propertyName = toCamelCase(propertyName)\n }\n\n if (isNull(value) || isUndefined(value)) {\n this.removeProperty(propertyName)\n } else {\n this[propertyName] = value\n }\n }\n\n public removeProperty (propertyName: string): string {\n propertyName = toCamelCase(propertyName)\n if (!this._usedStyleProp.has(propertyName)) {\n return ''\n }\n\n const value = this[propertyName]\n this[propertyName] = undefined\n return value\n }\n\n public getPropertyValue (propertyName: string) {\n propertyName = toCamelCase(propertyName)\n const value = this[propertyName]\n if (!value) {\n return ''\n }\n\n return value\n }\n}\n\ninitStyle(Style, styleProperties)\n\nhooks.tap('injectNewStyleProperties', (newStyleProperties: string[]) => {\n if (isArray(newStyleProperties)) {\n initStyle(Style, newStyleProperties)\n } else {\n if (typeof newStyleProperties !== 'string') return\n\n initStyle(Style, [newStyleProperties])\n }\n})\n"],"names":[],"mappings":";;;;;AAOA,SAAS,SAAS,CAAE,GAAU,EAAA;IAC5B,gBAAgB,CAAC,MAAM,CAAC;AACtB,QAAA,IAAI,EAA+B,YAAA;QACnC,MAAM,EAAE,GAAG,CAAC,QAAQ;AACp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AACzC,QAAA,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;AAC1C,YAAA,OAAO,EAAE;;AAGX,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;AAChC,QAAA,IAAI,CAAC,YAAY,CAAC,GAAG,SAAS;AAC9B,QAAA,OAAO,KAAK;;AAGP,IAAA,gBAAgB,CAAE,YAAoB,EAAA;AAC3C,QAAA,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC;AACxC,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;QAChC,IAAI,CAAC,KAAK,EAAE;AACV,YAAA,OAAO,EAAE;;AAGX,QAAA,OAAO,KAAK;;AAEf;AAED,SAAS,CAAC,KAAK,EAAE,eAAe,CAAC;AAEjC,KAAK,CAAC,GAAG,CAAC,0BAA0B,EAAE,CAAC,kBAA4B,KAAI;AACrE,IAAA,IAAI,OAAO,CAAC,kBAAkB,CAAC,EAAE;AAC/B,QAAA,SAAS,CAAC,KAAK,EAAE,kBAAkB,CAAC;;SAC/B;QACL,IAAI,OAAO,kBAAkB,KAAK,QAAQ;YAAE;AAE5C,QAAA,SAAS,CAAC,KAAK,EAAE,CAAC,kBAAkB,CAAC,CAAC;;AAE1C,CAAC,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"style.js","sources":["../../../src/dom/style.ts"],"sourcesContent":["import { hooks, isArray, isNull, isString, isUndefined, Shortcuts, toCamelCase, toDashed, warn } from '@tarojs/shared'\n\nimport { PROPERTY_THRESHOLD } from '../constants'\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer'\nimport { TaroElement } from './element'\nimport { styleProperties } from './style_properties'\n\nfunction recordCss (obj: Style) {\n MutationObserver.record({\n type: MutationRecordType.ATTRIBUTES,\n target: obj._element,\n attributeName: 'style',\n oldValue: obj.cssText\n })\n}\n\nfunction enqueueUpdate (obj: Style) {\n const element = obj._element\n if (element._root) {\n element.enqueueUpdate({\n path: `${element._path}.${Shortcuts.Style}`,\n value: obj.cssText\n })\n }\n}\n\nfunction setStyle (this: Style, newVal: string, styleKey: string) {\n process.env.NODE_ENV !== 'production' && warn(\n isString(newVal) && newVal.length > PROPERTY_THRESHOLD,\n `Style 属性 ${styleKey} 的值数据量过大,可能会影响渲染性能,考虑使用 CSS 类或其它方案替代。`\n )\n\n const old = this[styleKey]\n\n if (old === newVal) return\n\n !this._pending && recordCss(this)\n\n if (isNull(newVal) || isUndefined(newVal) || newVal === '') {\n this._usedStyleProp.delete(styleKey)\n delete this._value[styleKey]\n } else {\n this._usedStyleProp.add(styleKey)\n this._value[styleKey] = newVal\n }\n\n !this._pending && enqueueUpdate(this)\n}\n\nfunction initStyle (ctor: typeof Style, styleProperties: string[]) {\n const properties = {}\n\n for (let i = 0; i < styleProperties.length; i++) {\n const styleKey = styleProperties[i]\n\n if (ctor[styleKey]) return\n\n properties[styleKey] = {\n get (this: Style) {\n const val = this._value[styleKey]\n return isNull(val) || isUndefined(val) ? '' : val\n },\n set (this: Style, newVal: string) {\n setStyle.call(this, newVal, styleKey)\n }\n }\n }\n\n Object.defineProperties(ctor.prototype, properties)\n}\n\nfunction isCssVariable (propertyName) {\n return /^--/.test(propertyName)\n}\n\nexport class Style {\n public _pending: boolean\n\n public _usedStyleProp: Set<string>\n\n public _value: Partial<CSSStyleDeclaration>\n\n public _element: TaroElement\n\n public constructor (element: TaroElement) {\n this._element = element\n this._usedStyleProp = new Set()\n this._value = {}\n }\n\n private setCssVariables (styleKey: string) {\n this.hasOwnProperty(styleKey) || Object.defineProperty(this, styleKey, {\n enumerable: true,\n configurable: true,\n get: () => {\n return this._value[styleKey] || ''\n },\n set: (newVal: string) => {\n setStyle.call(this, newVal, styleKey)\n }\n })\n }\n\n public get cssText () {\n if (!this._usedStyleProp.size) return ''\n\n const texts: string[] = []\n this._usedStyleProp.forEach(key => {\n const val = this[key]\n if (isNull(val) || isUndefined(val)) return\n let styleName = isCssVariable(key) ? key : toDashed(key)\n if (styleName.indexOf('webkit') === 0 || styleName.indexOf('Webkit') === 0) {\n styleName = `-${styleName}`\n }\n texts.push(`${styleName}: ${val};`)\n })\n return texts.join(' ')\n }\n\n public set cssText (str: string) {\n this._pending = true\n recordCss(this)\n\n this._usedStyleProp.forEach(prop => {\n this.removeProperty(prop)\n })\n\n if (str === '' || isUndefined(str) || isNull(str)) {\n this._pending = false\n enqueueUpdate(this)\n return\n }\n\n const rules = str.split(';')\n\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i].trim()\n if (rule === '') {\n continue\n }\n\n // 可能存在 'background: url(http:x/y/z)' 的情况\n const [propName, ...valList] = rule.split(':')\n const val = valList.join(':')\n\n if (isUndefined(val)) {\n continue\n }\n this.setProperty(propName.trim(), val.trim())\n }\n\n this._pending = false\n enqueueUpdate(this)\n }\n\n public setProperty (propertyName: string, value?: string | null) {\n if (propertyName[0] === '-') {\n // 支持 webkit 属性或 css 变量\n this.setCssVariables(propertyName)\n } else {\n propertyName = toCamelCase(propertyName)\n }\n\n if (isNull(value) || isUndefined(value)) {\n this.removeProperty(propertyName)\n } else {\n this[propertyName] = value\n }\n }\n\n public removeProperty (propertyName: string): string {\n propertyName = isCssVariable(propertyName) ? propertyName : toCamelCase(propertyName)\n if (!this._usedStyleProp.has(propertyName)) {\n return ''\n }\n\n const value = this[propertyName]\n this[propertyName] = undefined\n return value\n }\n\n public getPropertyValue (propertyName: string) {\n propertyName = isCssVariable(propertyName) ? propertyName : toCamelCase(propertyName)\n const value = this[propertyName]\n if (!value) {\n return ''\n }\n\n return value\n }\n}\n\ninitStyle(Style, styleProperties)\n\nhooks.tap('injectNewStyleProperties', (newStyleProperties: string[]) => {\n if (isArray(newStyleProperties)) {\n initStyle(Style, newStyleProperties)\n } else {\n if (typeof newStyleProperties !== 'string') return\n\n initStyle(Style, [newStyleProperties])\n }\n})\n"],"names":[],"mappings":";;;;;AAOA,SAAS,SAA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CAAC,cAAc,CAAC,YAAY,CAAC;;aAC5B;AACL,YAAA,IAAI,CAAC,YAAY,CAAC,GAAG,KAAK;;;AAIvB,IAAA,cAAc,CAAE,YAAoB,EAAA;AACzC,QAAA,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC,GAAG,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC;QACrF,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;AAC1C,YAAA,OAAO,EAAE;;AAGX,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;AAChC,QAAA,IAAI,CAAC,YAAY,CAAC,GAAG,SAAS;AAC9B,QAAA,OAAO,KAAK;;AAGP,IAAA,gBAAgB,CAAE,YAAoB,EAAA;AAC3C,QAAA,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC,GAAG,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC;AACrF,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;QAChC,IAAI,CAAC,KAAK,EAAE;AACV,YAAA,OAAO,EAAE;;AAGX,QAAA,OAAO,KAAK;;AAEf;AAED,SAAS,CAAC,KAAK,EAAE,eAAe,CAAC;AAEjC,KAAK,CAAC,GAAG,CAAC,0BAA0B,EAAE,CAAC,kBAA4B,KAAI;AACrE,IAAA,IAAI,OAAO,CAAC,kBAAkB,CAAC,EAAE;AAC/B,QAAA,SAAS,CAAC,KAAK,EAAE,kBAAkB,CAAC;;SAC/B;QACL,IAAI,OAAO,kBAAkB,KAAK,QAAQ;YAAE;AAE5C,QAAA,SAAS,CAAC,KAAK,EAAE,CAAC,kBAAkB,CAAC,CAAC;;AAE1C,CAAC,CAAC;;;;"}
|
|
@@ -12,6 +12,11 @@ declare class TaroText extends TaroNode {
|
|
|
12
12
|
get nodeValue(): string;
|
|
13
13
|
set data(text: string);
|
|
14
14
|
get data(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Delegates a text update after Taro records the mutation and stores the logical value.
|
|
17
|
+
* The default prepares the template payload; textContent, nodeValue and data share this boundary.
|
|
18
|
+
*/
|
|
19
|
+
delegateTextUpdate(text: string): void;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export { TaroText };
|
package/dist/runtime/dom/text.js
CHANGED
|
@@ -15,10 +15,7 @@ class TaroText extends TaroNode {
|
|
|
15
15
|
oldValue: this._value
|
|
16
16
|
});
|
|
17
17
|
this._value = text;
|
|
18
|
-
this.
|
|
19
|
-
path: `${this._path}.${"v" /* Shortcuts.Text */}`,
|
|
20
|
-
value: text
|
|
21
|
-
});
|
|
18
|
+
this.delegateTextUpdate(text);
|
|
22
19
|
}
|
|
23
20
|
get textContent() {
|
|
24
21
|
return this._value;
|
|
@@ -35,6 +32,13 @@ class TaroText extends TaroNode {
|
|
|
35
32
|
get data() {
|
|
36
33
|
return this._value;
|
|
37
34
|
}
|
|
35
|
+
/** Delegates the logical value after its mutation record; hosts can replace template payload preparation. */
|
|
36
|
+
delegateTextUpdate(text) {
|
|
37
|
+
this.enqueueUpdate({
|
|
38
|
+
path: `${this._path}.${"v" /* Shortcuts.Text */}`,
|
|
39
|
+
value: text
|
|
40
|
+
});
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export { TaroText };
|
|
@@ -12,6 +12,6 @@ declare function getOnShowEventKey(path: string): string;
|
|
|
12
12
|
declare function getOnHideEventKey(path: string): string;
|
|
13
13
|
declare function createPageConfig(component: any, pageName?: string, data?: Record<string, unknown>, pageConfig?: PageConfig): PageInstance;
|
|
14
14
|
declare function createComponentConfig(component: React.ComponentClass, componentName?: string, data?: Record<string, unknown>): any;
|
|
15
|
-
declare function createRecursiveComponentConfig(componentName?: string): any;
|
|
15
|
+
declare function createRecursiveComponentConfig(componentName?: string, forceCustomWrapper?: boolean): any;
|
|
16
16
|
|
|
17
17
|
export { createComponentConfig, createPageConfig, createRecursiveComponentConfig, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, injectPageInstance, removePageInstance, safeExecute, stringify };
|