@spcsn/taro-runtime 0.1.0
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/LICENSE +174 -0
- package/README.md +49 -0
- package/dist/bom/URL.d.ts +51 -0
- package/dist/bom/URL.js +188 -0
- package/dist/bom/URL.js.map +1 -0
- package/dist/bom/URLSearchParams.d.ts +1 -0
- package/dist/bom/URLSearchParams.js +103 -0
- package/dist/bom/URLSearchParams.js.map +1 -0
- package/dist/bom/document.d.ts +3 -0
- package/dist/bom/document.js +93 -0
- package/dist/bom/document.js.map +1 -0
- package/dist/bom/getComputedStyle.d.ts +4 -0
- package/dist/bom/getComputedStyle.js +9 -0
- package/dist/bom/getComputedStyle.js.map +1 -0
- package/dist/bom/history.d.ts +30 -0
- package/dist/bom/history.js +108 -0
- package/dist/bom/history.js.map +1 -0
- package/dist/bom/location.d.ts +37 -0
- package/dist/bom/location.js +200 -0
- package/dist/bom/location.js.map +1 -0
- package/dist/bom/navigator.d.ts +1 -0
- package/dist/bom/navigator.js +22 -0
- package/dist/bom/navigator.js.map +1 -0
- package/dist/bom/raf.d.ts +4 -0
- package/dist/bom/raf.js +28 -0
- package/dist/bom/raf.js.map +1 -0
- package/dist/bom/window.d.ts +23 -0
- package/dist/bom/window.js +74 -0
- package/dist/bom/window.js.map +1 -0
- package/dist/constants/index.d.ts +57 -0
- package/dist/constants/index.js +63 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/current.d.ts +19 -0
- package/dist/current.js +11 -0
- package/dist/current.js.map +1 -0
- package/dist/dom/anchor-element.d.ts +13 -0
- package/dist/dom/anchor-element.js +42 -0
- package/dist/dom/anchor-element.js.map +1 -0
- package/dist/dom/class-list.d.ts +16 -0
- package/dist/dom/class-list.js +79 -0
- package/dist/dom/class-list.js.map +1 -0
- package/dist/dom/document.d.ts +21 -0
- package/dist/dom/document.js +74 -0
- package/dist/dom/document.js.map +1 -0
- package/dist/dom/element.d.ts +39 -0
- package/dist/dom/element.js +261 -0
- package/dist/dom/element.js.map +1 -0
- package/dist/dom/event-source.d.ts +7 -0
- package/dist/dom/event-source.js +18 -0
- package/dist/dom/event-source.js.map +1 -0
- package/dist/dom/event-target.d.ts +8 -0
- package/dist/dom/event-target.js +72 -0
- package/dist/dom/event-target.js.map +1 -0
- package/dist/dom/event.d.ts +24 -0
- package/dist/dom/event.js +124 -0
- package/dist/dom/event.js.map +1 -0
- package/dist/dom/form.d.ts +9 -0
- package/dist/dom/form.js +30 -0
- package/dist/dom/form.js.map +1 -0
- package/dist/dom/node.d.ts +76 -0
- package/dist/dom/node.js +213 -0
- package/dist/dom/node.js.map +1 -0
- package/dist/dom/node_types.d.ts +10 -0
- package/dist/dom/root.d.ts +16 -0
- package/dist/dom/root.js +127 -0
- package/dist/dom/root.js.map +1 -0
- package/dist/dom/style.d.ts +14 -0
- package/dist/dom/style.js +138 -0
- package/dist/dom/style.js.map +1 -0
- package/dist/dom/style_properties.d.ts +3 -0
- package/dist/dom/style_properties.js +374 -0
- package/dist/dom/style_properties.js.map +1 -0
- package/dist/dom/svg.d.ts +3 -0
- package/dist/dom/svg.js +7 -0
- package/dist/dom/svg.js.map +1 -0
- package/dist/dom/text.d.ts +14 -0
- package/dist/dom/text.js +43 -0
- package/dist/dom/text.js.map +1 -0
- package/dist/dom/transfer.d.ts +7 -0
- package/dist/dom/transfer.js +16 -0
- package/dist/dom/transfer.js.map +1 -0
- package/dist/dom/tree.d.ts +4 -0
- package/dist/dom/tree.js +31 -0
- package/dist/dom/tree.js.map +1 -0
- package/dist/dom-external/element.d.ts +3 -0
- package/dist/dom-external/index.d.ts +1 -0
- package/dist/dom-external/mutation-observer/implements.d.ts +52 -0
- package/dist/dom-external/mutation-observer/implements.js +101 -0
- package/dist/dom-external/mutation-observer/implements.js.map +1 -0
- package/dist/dom-external/mutation-observer/index.d.ts +13 -0
- package/dist/dom-external/mutation-observer/index.js +32 -0
- package/dist/dom-external/mutation-observer/index.js.map +1 -0
- package/dist/dom-external/mutation-observer/record.d.ts +24 -0
- package/dist/dom-external/node.d.ts +5 -0
- package/dist/dsl/common.d.ts +14 -0
- package/dist/dsl/common.js +278 -0
- package/dist/dsl/common.js.map +1 -0
- package/dist/dsl/instance.d.ts +92 -0
- package/dist/emitter/emitter.d.ts +4 -0
- package/dist/emitter/emitter.js +7 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/env.d.ts +7 -0
- package/dist/env.js +10 -0
- package/dist/env.js.map +1 -0
- package/dist/hydrate.d.ts +10 -0
- package/dist/hydrate.js +62 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index.cjs.d.ts +35 -0
- package/dist/index.cjs.js +3776 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +34 -0
- package/dist/interface/animate.d.ts +81 -0
- package/dist/interface/element.d.ts +4 -0
- package/dist/interface/event-target.d.ts +11 -0
- package/dist/interface/event.d.ts +15 -0
- package/dist/interface/hydrate.d.ts +30 -0
- package/dist/interface/index.d.ts +8 -0
- package/dist/interface/node.d.ts +7 -0
- package/dist/interface/options.d.ts +5 -0
- package/dist/interface/utils.d.ts +2 -0
- package/dist/next-tick.d.ts +2 -0
- package/dist/next-tick.js +35 -0
- package/dist/next-tick.js.map +1 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +9 -0
- package/dist/options.js.map +1 -0
- package/dist/perf.d.ts +9 -0
- package/dist/perf.js +36 -0
- package/dist/perf.js.map +1 -0
- package/dist/polyfill/array.d.ts +2 -0
- package/dist/polyfill/array.js +36 -0
- package/dist/polyfill/array.js.map +1 -0
- package/dist/polyfill/index.d.ts +2 -0
- package/dist/polyfill/index.js +20 -0
- package/dist/polyfill/index.js.map +1 -0
- package/dist/polyfill/intersection-observer.d.ts +1 -0
- package/dist/polyfill/intersection-observer.js +494 -0
- package/dist/polyfill/intersection-observer.js.map +1 -0
- package/dist/polyfill/object.d.ts +3 -0
- package/dist/polyfill/object.js +63 -0
- package/dist/polyfill/object.js.map +1 -0
- package/dist/runtime.esm.d.ts +35 -0
- package/dist/runtime.esm.js +3644 -0
- package/dist/runtime.esm.js.map +1 -0
- package/dist/utils/cache.d.ts +12 -0
- package/dist/utils/cache.js +26 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/index.d.ts +25 -0
- package/dist/utils/index.js +82 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/lodash.d.ts +2 -0
- package/dist/utils/lodash.js +33 -0
- package/dist/utils/lodash.js.map +1 -0
- package/dist/utils/router.d.ts +7 -0
- package/dist/utils/router.js +19 -0
- package/dist/utils/router.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//#region src/dom-external/mutation-observer/implements.ts
|
|
2
|
+
const observers = [];
|
|
3
|
+
/**
|
|
4
|
+
* The MutationObserver provides the ability
|
|
5
|
+
* to watch for changes being made to the DOM tree.
|
|
6
|
+
* It will invoke a specified callback function
|
|
7
|
+
* when DOM changes occur.
|
|
8
|
+
* @see https://dom.spec.whatwg.org/#mutationobserver
|
|
9
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
|
|
10
|
+
*/
|
|
11
|
+
var MutationObserverImpl = class {
|
|
12
|
+
constructor(callback) {
|
|
13
|
+
this.records = [];
|
|
14
|
+
this.callback = callback;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configures the MutationObserver
|
|
18
|
+
* to begin receiving notifications
|
|
19
|
+
* through its callback function
|
|
20
|
+
* when DOM changes matching the given options occur.
|
|
21
|
+
*
|
|
22
|
+
* Options matching is to be implemented.
|
|
23
|
+
*/
|
|
24
|
+
observe(target, options) {
|
|
25
|
+
this.disconnect();
|
|
26
|
+
this.target = target;
|
|
27
|
+
this.options = options || {};
|
|
28
|
+
observers.push(this);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Stop the MutationObserver instance
|
|
32
|
+
* from receiving further notifications
|
|
33
|
+
* until and unless observe() is called again.
|
|
34
|
+
*/
|
|
35
|
+
disconnect() {
|
|
36
|
+
this.target = null;
|
|
37
|
+
const index = observers.indexOf(this);
|
|
38
|
+
if (index >= 0) observers.splice(index, 1);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Removes all pending notifications
|
|
42
|
+
* from the MutationObserver's notification queue
|
|
43
|
+
* and returns them in a new Array of MutationRecord objects.
|
|
44
|
+
*/
|
|
45
|
+
takeRecords() {
|
|
46
|
+
return this.records.splice(0, this.records.length);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/** Match two TaroNodes by sid. */
|
|
50
|
+
const sidMatches = (observerTarget, target) => {
|
|
51
|
+
return !!observerTarget && observerTarget.sid === target?.sid;
|
|
52
|
+
};
|
|
53
|
+
const isConcerned = (record, options) => {
|
|
54
|
+
const { characterData, characterDataOldValue, attributes, attributeOldValue, childList } = options;
|
|
55
|
+
switch (record.type) {
|
|
56
|
+
case "characterData":
|
|
57
|
+
if (characterData) {
|
|
58
|
+
if (!characterDataOldValue) record.oldValue = null;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
case "attributes":
|
|
63
|
+
if (attributes) {
|
|
64
|
+
if (!attributeOldValue) record.oldValue = null;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
case "childList":
|
|
69
|
+
if (childList) return true;
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
let pendingMuatations = false;
|
|
74
|
+
function logMutation(observer, record) {
|
|
75
|
+
observer.records.push(record);
|
|
76
|
+
if (!pendingMuatations) {
|
|
77
|
+
pendingMuatations = true;
|
|
78
|
+
Promise.resolve().then(() => {
|
|
79
|
+
pendingMuatations = false;
|
|
80
|
+
observers.forEach((observer) => {
|
|
81
|
+
return observer.callback(observer.takeRecords());
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function recordMutation(record) {
|
|
87
|
+
observers.forEach((observer) => {
|
|
88
|
+
const { options } = observer;
|
|
89
|
+
for (let t = record.target; t; t = t.parentNode) {
|
|
90
|
+
if (sidMatches(observer.target, t) && isConcerned(record, options)) {
|
|
91
|
+
logMutation(observer, record);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (!options.subtree) break;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { MutationObserverImpl, recordMutation };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=implements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"implements.js","names":[],"sources":["../../../src/dom-external/mutation-observer/implements.ts"],"sourcesContent":["import { MutationRecordType } from './record';\n\nimport type { TaroNode } from '../../dom/node';\nimport type { MutationRecord } from './record';\n\nexport type MutationCallback = (mutations: MutationRecord[]) => any;\n\n/**\n * @see https://dom.spec.whatwg.org/#dictdef-mutationobserverinit\n */\nexport interface MutationObserverInit {\n attributeFilter?: string[];\n attributeOldValue?: boolean;\n attributes?: boolean;\n characterData?: boolean;\n characterDataOldValue?: boolean;\n childList?: boolean;\n subtree?: boolean;\n}\n\nconst observers: MutationObserverImpl[] = [];\n\n/**\n * The MutationObserver provides the ability\n * to watch for changes being made to the DOM tree.\n * It will invoke a specified callback function\n * when DOM changes occur.\n * @see https://dom.spec.whatwg.org/#mutationobserver\n * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver\n */\nexport class MutationObserverImpl {\n public callback: MutationCallback;\n public target: TaroNode | null;\n public options: MutationObserverInit;\n public records: MutationRecord[] = [];\n\n constructor(callback: MutationCallback) {\n this.callback = callback;\n }\n\n /**\n * Configures the MutationObserver\n * to begin receiving notifications\n * through its callback function\n * when DOM changes matching the given options occur.\n *\n * Options matching is to be implemented.\n */\n observe(target: TaroNode, options?: MutationObserverInit): void {\n this.disconnect();\n this.target = target;\n this.options = options || {};\n\n observers.push(this);\n }\n\n /**\n * Stop the MutationObserver instance\n * from receiving further notifications\n * until and unless observe() is called again.\n */\n disconnect(): void {\n this.target = null;\n\n const index = observers.indexOf(this);\n if (index >= 0) {\n observers.splice(index, 1);\n }\n }\n\n /**\n * Removes all pending notifications\n * from the MutationObserver's notification queue\n * and returns them in a new Array of MutationRecord objects.\n */\n takeRecords(): MutationRecord[] {\n return this.records.splice(0, this.records.length);\n }\n}\n\n/** Match two TaroNodes by sid. */\nconst sidMatches = (observerTarget: TaroNode | null, target: TaroNode | null): boolean => {\n return !!observerTarget && observerTarget.sid === target?.sid;\n};\n\nconst isConcerned = (record: MutationRecord, options: MutationObserverInit) => {\n const { characterData, characterDataOldValue, attributes, attributeOldValue, childList } = options;\n switch (record.type) {\n case MutationRecordType.CHARACTER_DATA:\n if (characterData) {\n if (!characterDataOldValue) record.oldValue = null;\n return true;\n }\n return false;\n case MutationRecordType.ATTRIBUTES:\n if (attributes) {\n if (!attributeOldValue) record.oldValue = null;\n return true;\n }\n return false;\n case MutationRecordType.CHILD_LIST:\n if (childList) {\n return true;\n }\n return false;\n }\n};\n\nlet pendingMuatations = false;\n\nfunction logMutation(observer: MutationObserverImpl, record: MutationRecord) {\n observer.records.push(record);\n if (!pendingMuatations) {\n pendingMuatations = true;\n Promise.resolve().then(() => {\n pendingMuatations = false;\n observers.forEach((observer) => {\n return observer.callback(observer.takeRecords());\n });\n });\n }\n}\n\nexport function recordMutation(record: MutationRecord) {\n observers.forEach((observer) => {\n const { options } = observer;\n for (let t: TaroNode | null = record.target; t; t = t.parentNode) {\n if (sidMatches(observer.target, t) && isConcerned(record, options)) {\n logMutation(observer, record);\n break;\n }\n if (!options.subtree) break;\n }\n });\n}\n"],"mappings":";AAoBA,MAAM,YAAoC,CAAC;;;;;;;;;AAU3C,IAAa,uBAAb,MAAkC;CAMhC,YAAY,UAA4B;iBAFL,CAAC;EAGlC,KAAK,WAAW;CAClB;;;;;;;;;CAUA,QAAQ,QAAkB,SAA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QAAQ,OAAO,GAAG;IAClE,YAAY,UAAU,MAAM;IAC5B;GACF;GACA,IAAI,CAAC,QAAQ,SAAS;EACxB;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MutationObserverImpl } from './implements';
|
|
2
|
+
import { MutationRecord, MutationRecordType } from './record';
|
|
3
|
+
import type { TaroNode } from '../../dom/node';
|
|
4
|
+
import type { MutationCallback, MutationObserverInit } from './implements';
|
|
5
|
+
export declare class MutationObserver {
|
|
6
|
+
core: Pick<MutationObserverImpl, 'observe' | 'disconnect' | 'takeRecords'>;
|
|
7
|
+
constructor(callback: MutationCallback);
|
|
8
|
+
observe(...args: [TaroNode, MutationObserverInit?]): void;
|
|
9
|
+
disconnect(): void;
|
|
10
|
+
takeRecords(): MutationRecord[];
|
|
11
|
+
static record(record: MutationRecord): void;
|
|
12
|
+
}
|
|
13
|
+
export { MutationRecordType };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MutationObserverImpl, recordMutation } from "./implements.js";
|
|
2
|
+
import { noop } from "@spcsn/taro-shared";
|
|
3
|
+
//#region src/dom-external/mutation-observer/index.ts
|
|
4
|
+
var MutationObserver = class {
|
|
5
|
+
constructor(callback) {
|
|
6
|
+
if (ENABLE_MUTATION_OBSERVER) this.core = new MutationObserverImpl(callback);
|
|
7
|
+
else {
|
|
8
|
+
console.warn("[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 'mini.runtime.enableMutationObserver: true'");
|
|
9
|
+
this.core = {
|
|
10
|
+
observe: noop,
|
|
11
|
+
disconnect: noop,
|
|
12
|
+
takeRecords: noop
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
observe(...args) {
|
|
17
|
+
this.core.observe(...args);
|
|
18
|
+
}
|
|
19
|
+
disconnect() {
|
|
20
|
+
this.core.disconnect();
|
|
21
|
+
}
|
|
22
|
+
takeRecords() {
|
|
23
|
+
return this.core.takeRecords();
|
|
24
|
+
}
|
|
25
|
+
static record(record) {
|
|
26
|
+
recordMutation(record);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { MutationObserver };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/dom-external/mutation-observer/index.ts"],"sourcesContent":["import { noop } from '@spcsn/taro-shared';\n\nimport { MutationObserverImpl, recordMutation } from './implements';\nimport { MutationRecord, MutationRecordType } from './record';\n\nimport type { TaroNode } from '../../dom/node';\nimport type { MutationCallback, MutationObserverInit } from './implements';\n\ndeclare const ENABLE_MUTATION_OBSERVER: boolean;\n\nexport class MutationObserver {\n core: Pick<MutationObserverImpl, 'observe' | 'disconnect' | 'takeRecords'>;\n\n constructor(callback: MutationCallback) {\n if (ENABLE_MUTATION_OBSERVER) {\n this.core = new MutationObserverImpl(callback);\n } else {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n \"[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 'mini.runtime.enableMutationObserver: true'\",\n );\n }\n this.core = {\n observe: noop,\n disconnect: noop,\n takeRecords: noop as () => any,\n };\n }\n }\n\n public observe(...args: [TaroNode, MutationObserverInit?]) {\n this.core.observe(...args);\n }\n\n public disconnect() {\n this.core.disconnect();\n }\n\n public takeRecords() {\n return this.core.takeRecords();\n }\n\n static record(record: MutationRecord) {\n recordMutation(record);\n }\n}\n\nexport { MutationRecordType };\n"],"mappings":";;;AAUA,IAAa,mBAAb,MAA8B;CAG5B,YAAY,UAA4B;EACtC,IAAI,0BACF,KAAK,OAAO,IAAI,qBAAqB,QAAQ;OACxC;GAEH,QAAQ,KACN,kGACF;GAEF,KAAK,OAAO;IACV,SAAS;IACT,YAAY;IACZ,aAAa;GACf;EACF;CACF;CAEA,QAAe,GAAG,MAAyC;EACzD,KAAK,KAAK,QAAQ,GAAG,IAAI;CAC3B;CAEA,aAAoB;EAClB,KAAK,KAAK,WAAW;CACvB;CAEA,cAAqB;EACnB,OAAO,KAAK,KAAK,YAAY;CAC/B;CAEA,OAAO,OAAO,QAAwB;EACpC,eAAe,MAAM;CACvB;AACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TaroNode } from '../../dom/node';
|
|
2
|
+
/**
|
|
3
|
+
* A MutationRecord represents an individual DOM mutation.
|
|
4
|
+
* It is the object that is passed to MutationObserver's callback.
|
|
5
|
+
* @see https://dom.spec.whatwg.org/#interface-mutationrecord
|
|
6
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationRecord
|
|
7
|
+
*/
|
|
8
|
+
export interface MutationRecord {
|
|
9
|
+
readonly target: TaroNode;
|
|
10
|
+
readonly addedNodes?: TaroNode[];
|
|
11
|
+
readonly removedNodes?: TaroNode[];
|
|
12
|
+
readonly previousSibling?: TaroNode | null;
|
|
13
|
+
readonly nextSibling?: TaroNode | null;
|
|
14
|
+
readonly attributeName?: string | null;
|
|
15
|
+
readonly attributeNamespace?: string | null;
|
|
16
|
+
oldValue?: string | null;
|
|
17
|
+
readonly type: MutationRecordType;
|
|
18
|
+
readonly value?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export declare const enum MutationRecordType {
|
|
21
|
+
ATTRIBUTES = "attributes",
|
|
22
|
+
CHARACTER_DATA = "characterData",
|
|
23
|
+
CHILD_LIST = "childList"
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PageConfig } from '../interface';
|
|
2
|
+
import type { Instance, PageInstance, PageProps } from './instance';
|
|
3
|
+
export declare function injectPageInstance(inst: Instance<PageProps>, id: string): void;
|
|
4
|
+
export declare function getPageInstance(id: string): Instance | undefined;
|
|
5
|
+
export declare function removePageInstance(id: string): void;
|
|
6
|
+
export declare function safeExecute(path: string, lifecycle: string, ...args: unknown[]): any;
|
|
7
|
+
export declare function stringify(obj?: Record<string, unknown>): string;
|
|
8
|
+
export declare function getPath(id: string, options?: Record<string, unknown>): string;
|
|
9
|
+
export declare function getOnReadyEventKey(path: string): string;
|
|
10
|
+
export declare function getOnShowEventKey(path: string): string;
|
|
11
|
+
export declare function getOnHideEventKey(path: string): string;
|
|
12
|
+
export declare function createPageConfig(component: any, pageName?: string, data?: Record<string, unknown>, pageConfig?: PageConfig): PageInstance;
|
|
13
|
+
export declare function createComponentConfig(component: React.ComponentClass, componentName?: string, data?: Record<string, unknown>): any;
|
|
14
|
+
export declare function createRecursiveComponentConfig(componentName?: string): any;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { BEHAVIORS, CUSTOM_WRAPPER, EXTERNAL_CLASSES, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, VIEW } from "../constants/index.js";
|
|
2
|
+
import { eventCenter } from "../emitter/emitter.js";
|
|
3
|
+
import env from "../env.js";
|
|
4
|
+
import { Current } from "../current.js";
|
|
5
|
+
import { _raf } from "../bom/raf.js";
|
|
6
|
+
import { taroWindowProvider } from "../bom/window.js";
|
|
7
|
+
import { addLeadingSlash } from "../utils/router.js";
|
|
8
|
+
import { customWrapperCache, incrementId } from "../utils/index.js";
|
|
9
|
+
import { eventHandler } from "../dom/event.js";
|
|
10
|
+
import { perf } from "../perf.js";
|
|
11
|
+
import { EMPTY_OBJ, EventChannel, Shortcuts, ensure, getComponentsAlias, hooks, internalComponents, isArray, isEnableTTDom, isFunction, isString, isUndefined } from "@spcsn/taro-shared";
|
|
12
|
+
//#region src/dsl/common.ts
|
|
13
|
+
const instances = /* @__PURE__ */ new Map();
|
|
14
|
+
const pageId = incrementId();
|
|
15
|
+
function injectPageInstance(inst, id) {
|
|
16
|
+
hooks.call("mergePageInstance", instances.get(id), inst);
|
|
17
|
+
instances.set(id, inst);
|
|
18
|
+
}
|
|
19
|
+
function getPageInstance(id) {
|
|
20
|
+
return instances.get(id);
|
|
21
|
+
}
|
|
22
|
+
function removePageInstance(id) {
|
|
23
|
+
instances.delete(id);
|
|
24
|
+
}
|
|
25
|
+
function safeExecute(path, lifecycle, ...args) {
|
|
26
|
+
const instance = instances.get(path);
|
|
27
|
+
if (instance == null) return;
|
|
28
|
+
const func = hooks.call("getLifecycle", instance, lifecycle);
|
|
29
|
+
if (isArray(func)) return func.map((fn) => fn.apply(instance, args))[0];
|
|
30
|
+
if (!isFunction(func)) return;
|
|
31
|
+
return func.apply(instance, args);
|
|
32
|
+
}
|
|
33
|
+
function stringify(obj) {
|
|
34
|
+
if (obj == null) return "";
|
|
35
|
+
const path = Object.keys(obj).map((key) => {
|
|
36
|
+
return key + "=" + obj[key];
|
|
37
|
+
}).join("&");
|
|
38
|
+
return path === "" ? path : "?" + path;
|
|
39
|
+
}
|
|
40
|
+
function getPath(id, options) {
|
|
41
|
+
const idx = id.indexOf("?");
|
|
42
|
+
if (process.env.TARO_PLATFORM === "web") return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options?.stamp ? { stamp: options.stamp } : {})}`;
|
|
43
|
+
else return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options)}`;
|
|
44
|
+
}
|
|
45
|
+
function getOnReadyEventKey(path) {
|
|
46
|
+
return path + "." + ON_READY;
|
|
47
|
+
}
|
|
48
|
+
function getOnShowEventKey(path) {
|
|
49
|
+
return path + "." + ON_SHOW;
|
|
50
|
+
}
|
|
51
|
+
function getOnHideEventKey(path) {
|
|
52
|
+
return path + "." + ON_HIDE;
|
|
53
|
+
}
|
|
54
|
+
function createPageConfig(component, pageName, data, pageConfig) {
|
|
55
|
+
const id = pageName ?? `taro_page_${pageId()}`;
|
|
56
|
+
const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES, SIDE_EFFECT_LIFECYCLES] = hooks.call("getMiniLifecycleImpl").page;
|
|
57
|
+
let pageElement = null;
|
|
58
|
+
let unmounting = false;
|
|
59
|
+
let prepareMountList = [];
|
|
60
|
+
function setCurrentRouter(page) {
|
|
61
|
+
const router = process.env.TARO_PLATFORM === "web" ? page.$taroPath : page.route || page.__route__ || page.$taroPath;
|
|
62
|
+
Current.router = {
|
|
63
|
+
params: page.$taroParams,
|
|
64
|
+
path: addLeadingSlash(router),
|
|
65
|
+
$taroPath: page.$taroPath,
|
|
66
|
+
onReady: getOnReadyEventKey(id),
|
|
67
|
+
onShow: getOnShowEventKey(id),
|
|
68
|
+
onHide: getOnHideEventKey(id)
|
|
69
|
+
};
|
|
70
|
+
if (!isUndefined(page.exitState)) Current.router.exitState = page.exitState;
|
|
71
|
+
}
|
|
72
|
+
let loadResolver;
|
|
73
|
+
let hasLoaded;
|
|
74
|
+
const config = {
|
|
75
|
+
[ONLOAD](options = {}, cb) {
|
|
76
|
+
hasLoaded = new Promise((resolve) => {
|
|
77
|
+
loadResolver = resolve;
|
|
78
|
+
});
|
|
79
|
+
perf.start(PAGE_INIT);
|
|
80
|
+
Current.page = this;
|
|
81
|
+
this.config = pageConfig || {};
|
|
82
|
+
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() });
|
|
83
|
+
const $taroPath = this.$taroPath = getPath(id, uniqueOptions);
|
|
84
|
+
if (process.env.TARO_PLATFORM === "web") config.path = $taroPath;
|
|
85
|
+
if (this.$taroParams == null) this.$taroParams = uniqueOptions;
|
|
86
|
+
setCurrentRouter(this);
|
|
87
|
+
if (process.env.TARO_PLATFORM !== "web") taroWindowProvider.trigger("0", $taroPath);
|
|
88
|
+
const mount = () => {
|
|
89
|
+
Current.app.mount(component, $taroPath, () => {
|
|
90
|
+
if (process.env.TARO_ENV === "tt" && isEnableTTDom()) pageElement = env.document.getPageDocumentById(this.__webviewId__);
|
|
91
|
+
else pageElement = env.document.getElementById($taroPath);
|
|
92
|
+
ensure(pageElement !== null, "没有找到页面实例。");
|
|
93
|
+
safeExecute($taroPath, ON_LOAD, this.$taroParams);
|
|
94
|
+
loadResolver();
|
|
95
|
+
if (process.env.TARO_PLATFORM !== "web") {
|
|
96
|
+
pageElement.ctx = this;
|
|
97
|
+
if (process.env.TARO_ENV === "tt" && isEnableTTDom()) pageElement.sync();
|
|
98
|
+
else pageElement.performUpdate(true, cb);
|
|
99
|
+
} else isFunction(cb) && cb();
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
if (unmounting) prepareMountList.push(mount);
|
|
103
|
+
else mount();
|
|
104
|
+
},
|
|
105
|
+
[ONUNLOAD]() {
|
|
106
|
+
const $taroPath = this.$taroPath;
|
|
107
|
+
if (process.env.TARO_PLATFORM !== "web") taroWindowProvider.trigger("3", $taroPath);
|
|
108
|
+
safeExecute($taroPath, ONUNLOAD);
|
|
109
|
+
unmounting = true;
|
|
110
|
+
Current.app.unmount($taroPath, () => {
|
|
111
|
+
unmounting = false;
|
|
112
|
+
instances.delete($taroPath);
|
|
113
|
+
if (pageElement) {
|
|
114
|
+
pageElement.ctx = null;
|
|
115
|
+
pageElement = null;
|
|
116
|
+
}
|
|
117
|
+
if (prepareMountList.length) {
|
|
118
|
+
prepareMountList.forEach((fn) => fn());
|
|
119
|
+
prepareMountList = [];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
[ONREADY]() {
|
|
124
|
+
hasLoaded.then(() => {
|
|
125
|
+
safeExecute(this.$taroPath, ON_READY);
|
|
126
|
+
_raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
127
|
+
this.onReady.called = true;
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
[ONSHOW](options = {}) {
|
|
131
|
+
hasLoaded.then(() => {
|
|
132
|
+
Current.page = this;
|
|
133
|
+
setCurrentRouter(this);
|
|
134
|
+
if (process.env.TARO_PLATFORM !== "web") taroWindowProvider.trigger("2", this.$taroPath);
|
|
135
|
+
safeExecute(this.$taroPath, ON_SHOW, options);
|
|
136
|
+
_raf(() => eventCenter.trigger(getOnShowEventKey(id)));
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
[ONHIDE]() {
|
|
140
|
+
if (process.env.TARO_PLATFORM !== "web") taroWindowProvider.trigger("1", this.$taroPath);
|
|
141
|
+
if (Current.page === this) {
|
|
142
|
+
Current.page = null;
|
|
143
|
+
Current.router = null;
|
|
144
|
+
}
|
|
145
|
+
safeExecute(this.$taroPath, ON_HIDE);
|
|
146
|
+
eventCenter.trigger(getOnHideEventKey(id));
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
if (process.env.TARO_PLATFORM === "web") config.getOpenerEventChannel = () => {
|
|
150
|
+
return EventChannel.pageChannel;
|
|
151
|
+
};
|
|
152
|
+
const isSWAN = process.env.TARO_ENV === "swan";
|
|
153
|
+
LIFECYCLES.forEach((lifecycle) => {
|
|
154
|
+
let isDefer = false;
|
|
155
|
+
let isEvent = false;
|
|
156
|
+
lifecycle = lifecycle.replace(/^defer:/, () => {
|
|
157
|
+
isDefer = true;
|
|
158
|
+
return "";
|
|
159
|
+
});
|
|
160
|
+
lifecycle = lifecycle.replace(/^events:/, () => {
|
|
161
|
+
isEvent = true;
|
|
162
|
+
return "";
|
|
163
|
+
});
|
|
164
|
+
if (isEvent && process.env.TARO_ENV === "alipay") {
|
|
165
|
+
if (!config.events) config.events = {};
|
|
166
|
+
config.events[lifecycle] = function() {
|
|
167
|
+
return safeExecute(this.$taroPath, lifecycle, ...arguments);
|
|
168
|
+
};
|
|
169
|
+
} else config[lifecycle] = function() {
|
|
170
|
+
const exec = () => safeExecute(this.$taroPath, lifecycle, ...arguments);
|
|
171
|
+
if (isSWAN) return exec();
|
|
172
|
+
if (isDefer) hasLoaded.then(exec);
|
|
173
|
+
else return exec();
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
SIDE_EFFECT_LIFECYCLES.forEach((lifecycle) => {
|
|
177
|
+
if (component[lifecycle] || component.prototype?.[lifecycle] || component[lifecycle.replace(/^on/, "enable")] || pageConfig?.[lifecycle.replace(/^on/, "enable")]) config[lifecycle] = function(...args) {
|
|
178
|
+
const target = args[0]?.target;
|
|
179
|
+
if (target?.id) {
|
|
180
|
+
const id = target.id;
|
|
181
|
+
const element = env.document.getElementById(id);
|
|
182
|
+
if (element) target.dataset = element.dataset;
|
|
183
|
+
}
|
|
184
|
+
return safeExecute(this.$taroPath, lifecycle, ...args);
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
config.eh = eventHandler;
|
|
188
|
+
if (!isUndefined(data)) config.data = data;
|
|
189
|
+
hooks.call("modifyPageObject", config);
|
|
190
|
+
return config;
|
|
191
|
+
}
|
|
192
|
+
function createComponentConfig(component, componentName, data) {
|
|
193
|
+
const id = componentName ?? `taro_component_${pageId()}`;
|
|
194
|
+
let componentElement = null;
|
|
195
|
+
const [ATTACHED, DETACHED] = hooks.call("getMiniLifecycleImpl").component;
|
|
196
|
+
const config = {
|
|
197
|
+
[ATTACHED]() {
|
|
198
|
+
perf.start(PAGE_INIT);
|
|
199
|
+
this.pageIdCache = this.getPageId?.() || pageId();
|
|
200
|
+
const path = getPath(id, { id: this.pageIdCache });
|
|
201
|
+
Current.app.mount(component, path, () => {
|
|
202
|
+
componentElement = env.document.getElementById(path);
|
|
203
|
+
ensure(componentElement !== null, "没有找到组件实例。");
|
|
204
|
+
this.$taroInstances = instances.get(path);
|
|
205
|
+
safeExecute(path, ON_LOAD);
|
|
206
|
+
if (process.env.TARO_PLATFORM !== "web") {
|
|
207
|
+
componentElement.ctx = this;
|
|
208
|
+
if (process.env.TARO_ENV !== "tt" || !isEnableTTDom()) componentElement.performUpdate(true);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
[DETACHED]() {
|
|
213
|
+
const path = getPath(id, { id: this.pageIdCache });
|
|
214
|
+
Current.app.unmount(path, () => {
|
|
215
|
+
instances.delete(path);
|
|
216
|
+
if (componentElement) componentElement.ctx = null;
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
methods: { eh: eventHandler }
|
|
220
|
+
};
|
|
221
|
+
if (!isUndefined(data)) config.data = data;
|
|
222
|
+
[
|
|
223
|
+
OPTIONS,
|
|
224
|
+
EXTERNAL_CLASSES,
|
|
225
|
+
BEHAVIORS
|
|
226
|
+
].forEach((key) => {
|
|
227
|
+
config[key] = component[key] ?? EMPTY_OBJ;
|
|
228
|
+
});
|
|
229
|
+
return config;
|
|
230
|
+
}
|
|
231
|
+
function createRecursiveComponentConfig(componentName) {
|
|
232
|
+
const isCustomWrapper = componentName === CUSTOM_WRAPPER;
|
|
233
|
+
const [ATTACHED, DETACHED] = hooks.call("getMiniLifecycleImpl").component;
|
|
234
|
+
const lifeCycles = isCustomWrapper ? {
|
|
235
|
+
[ATTACHED]() {
|
|
236
|
+
if (process.env.TARO_ENV === "tt" && isEnableTTDom()) return;
|
|
237
|
+
const componentId = this.data.i?.sid || this.props.i?.sid;
|
|
238
|
+
if (isString(componentId)) {
|
|
239
|
+
customWrapperCache.set(componentId, this);
|
|
240
|
+
const el = env.document.getElementById(componentId);
|
|
241
|
+
if (el) el.ctx = this;
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
[DETACHED]() {
|
|
245
|
+
if (process.env.TARO_ENV === "tt" && isEnableTTDom()) return;
|
|
246
|
+
const componentId = this.data.i?.sid || this.props.i?.sid;
|
|
247
|
+
if (isString(componentId)) {
|
|
248
|
+
customWrapperCache.delete(componentId);
|
|
249
|
+
const el = env.document.getElementById(componentId);
|
|
250
|
+
if (el) el.ctx = null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
} : EMPTY_OBJ;
|
|
254
|
+
const extraOptions = {};
|
|
255
|
+
if (process.env.TARO_ENV === "jd") extraOptions.addGlobalClass = true;
|
|
256
|
+
return hooks.call("modifyRecursiveComponentConfig", {
|
|
257
|
+
properties: {
|
|
258
|
+
i: {
|
|
259
|
+
type: Object,
|
|
260
|
+
value: { [Shortcuts.NodeName]: getComponentsAlias(internalComponents)[VIEW]._num }
|
|
261
|
+
},
|
|
262
|
+
l: {
|
|
263
|
+
type: String,
|
|
264
|
+
value: ""
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
options: {
|
|
268
|
+
...extraOptions,
|
|
269
|
+
virtualHost: !isCustomWrapper
|
|
270
|
+
},
|
|
271
|
+
methods: { eh: eventHandler },
|
|
272
|
+
...lifeCycles
|
|
273
|
+
}, { isCustomWrapper });
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
export { createComponentConfig, createPageConfig, createRecursiveComponentConfig, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, injectPageInstance, removePageInstance, safeExecute, stringify };
|
|
277
|
+
|
|
278
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","names":[],"sources":["../../src/dsl/common.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {\n EMPTY_OBJ,\n ensure,\n EventChannel,\n getComponentsAlias,\n hooks,\n internalComponents,\n isArray,\n isEnableTTDom,\n isFunction,\n isString,\n isUndefined,\n Shortcuts,\n} from '@spcsn/taro-shared';\n\nimport { raf } from '../bom/raf';\nimport { taroWindowProvider } from '../bom/window';\nimport {\n BEHAVIORS,\n CONTEXT_ACTIONS,\n CUSTOM_WRAPPER,\n EXTERNAL_CLASSES,\n ON_HIDE,\n ON_LOAD,\n ON_READY,\n ON_SHOW,\n OPTIONS,\n PAGE_INIT,\n VIEW,\n} from '../constants';\nimport { Current } from '../current';\nimport { eventHandler } from '../dom/event';\nimport { eventCenter } from '../emitter/emitter';\nimport env from '../env';\nimport { perf } from '../perf';\nimport { customWrapperCache, incrementId } from '../utils';\nimport { addLeadingSlash } from '../utils/router';\n\nimport type { TaroRootElement } from '../dom/root';\nimport type { MpInstance, PageConfig, TFunc } from '../interface';\nimport type { Instance, PageInstance, PageProps } from './instance';\n\nconst instances = new Map<string, Instance>();\nconst pageId = incrementId();\n\nexport function injectPageInstance(inst: Instance<PageProps>, id: string) {\n hooks.call('mergePageInstance', instances.get(id), inst);\n instances.set(id, inst);\n}\n\nexport function getPageInstance(id: string): Instance | undefined {\n return instances.get(id);\n}\n\nexport function removePageInstance(id: string) {\n instances.delete(id);\n}\n\nexport function safeExecute(path: string, lifecycle: string, ...args: unknown[]) {\n const instance = instances.get(path);\n\n if (instance == null) {\n return;\n }\n\n const func = hooks.call('getLifecycle', instance, lifecycle as keyof PageInstance);\n\n if (isArray(func)) {\n const res = func.map((fn) => fn.apply(instance, args));\n return res[0];\n }\n\n if (!isFunction(func)) {\n return;\n }\n\n return func.apply(instance, args);\n}\n\nexport function stringify(obj?: Record<string, unknown>) {\n if (obj == null) {\n return '';\n }\n const path = Object.keys(obj)\n .map((key) => {\n return key + '=' + obj[key];\n })\n .join('&');\n return path === '' ? path : '?' + path;\n}\n\nexport function getPath(id: string, options?: Record<string, unknown>): string {\n const idx = id.indexOf('?');\n if (process.env.TARO_PLATFORM === 'web') {\n return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options?.stamp ? { stamp: options.stamp } : {})}`;\n } else {\n return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options)}`;\n }\n}\n\nexport function getOnReadyEventKey(path: string) {\n return path + '.' + ON_READY;\n}\n\nexport function getOnShowEventKey(path: string) {\n return path + '.' + ON_SHOW;\n}\n\nexport function getOnHideEventKey(path: string) {\n return path + '.' + ON_HIDE;\n}\n\nexport function createPageConfig(\n component: any,\n pageName?: string,\n data?: Record<string, unknown>,\n pageConfig?: PageConfig,\n) {\n // 小程序 Page 构造器是一个傲娇小公主,不能把复杂的对象挂载到参数上\n const id = pageName ?? `taro_page_${pageId()}`;\n const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES, SIDE_EFFECT_LIFECYCLES] =\n hooks.call('getMiniLifecycleImpl')!.page;\n let pageElement: TaroRootElement | null = null;\n let unmounting = false;\n let prepareMountList: (() => void)[] = [];\n\n function setCurrentRouter(page: MpInstance) {\n const router =\n process.env.TARO_PLATFORM === 'web' ? page.$taroPath : page.route || page.__route__ || page.$taroPath;\n Current.router = {\n params: page.$taroParams!,\n path: addLeadingSlash(router),\n $taroPath: page.$taroPath,\n onReady: getOnReadyEventKey(id),\n onShow: getOnShowEventKey(id),\n onHide: getOnHideEventKey(id),\n };\n if (!isUndefined(page.exitState)) {\n Current.router.exitState = page.exitState;\n }\n }\n let loadResolver: (...args: unknown[]) => void;\n let hasLoaded: Promise<void>;\n const config: PageInstance = {\n [ONLOAD](this: MpInstance, options: Readonly<Record<string, unknown>> = {}, cb?: TFunc) {\n hasLoaded = new Promise((resolve) => {\n loadResolver = resolve;\n });\n\n perf.start(PAGE_INIT);\n\n Current.page = this as any;\n this.config = pageConfig || {};\n\n // this.$taroPath 是页面唯一标识\n const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() });\n const $taroPath = (this.$taroPath = getPath(id, uniqueOptions));\n if (process.env.TARO_PLATFORM === 'web') {\n config.path = $taroPath;\n }\n // this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改\n if (this.$taroParams == null) {\n this.$taroParams = uniqueOptions;\n }\n\n setCurrentRouter(this);\n\n // 初始化当前页面的上下文信息\n if (process.env.TARO_PLATFORM !== 'web') {\n taroWindowProvider.trigger(CONTEXT_ACTIONS.INIT, $taroPath);\n }\n\n const mount = () => {\n Current.app!.mount!(component, $taroPath, () => {\n if (process.env.TARO_ENV === 'tt' && isEnableTTDom()) {\n pageElement = (env.document as any).getPageDocumentById(this.__webviewId__);\n } else {\n pageElement = env.document.getElementById<TaroRootElement>($taroPath);\n }\n\n ensure(pageElement !== null, '没有找到页面实例。');\n safeExecute($taroPath, ON_LOAD, this.$taroParams);\n loadResolver();\n if (process.env.TARO_PLATFORM !== 'web') {\n pageElement.ctx = this;\n if (process.env.TARO_ENV === 'tt' && isEnableTTDom()) {\n (pageElement as any).sync();\n } else {\n pageElement.performUpdate(true, cb);\n }\n } else {\n isFunction(cb) && cb();\n }\n });\n };\n if (unmounting) {\n prepareMountList.push(mount);\n } else {\n mount();\n }\n },\n [ONUNLOAD]() {\n const $taroPath = this.$taroPath;\n // 销毁当前页面的上下文信息\n if (process.env.TARO_PLATFORM !== 'web') {\n taroWindowProvider.trigger(CONTEXT_ACTIONS.DESTROY, $taroPath);\n }\n // 触发onUnload生命周期\n safeExecute($taroPath, ONUNLOAD);\n unmounting = true;\n Current.app!.unmount!($taroPath, () => {\n unmounting = false;\n instances.delete($taroPath);\n if (pageElement) {\n pageElement.ctx = null;\n pageElement = null;\n }\n if (prepareMountList.length) {\n prepareMountList.forEach((fn) => fn());\n prepareMountList = [];\n }\n });\n },\n [ONREADY]() {\n hasLoaded.then(() => {\n // 触发生命周期\n safeExecute(this.$taroPath, ON_READY);\n // 通过事件触发子组件的生命周期\n raf(() => eventCenter.trigger(getOnReadyEventKey(id)));\n this.onReady.called = true;\n });\n },\n [ONSHOW](options = {}) {\n hasLoaded.then(() => {\n // 设置 Current 的 page 和 router\n Current.page = this as any;\n setCurrentRouter(this);\n // 恢复上下文信息\n if (process.env.TARO_PLATFORM !== 'web') {\n taroWindowProvider.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath);\n }\n // 触发生命周期\n safeExecute(this.$taroPath, ON_SHOW, options);\n // 通过事件触发子组件的生命周期\n raf(() => eventCenter.trigger(getOnShowEventKey(id)));\n });\n },\n [ONHIDE]() {\n // 缓存当前页面上下文信息\n if (process.env.TARO_PLATFORM !== 'web') {\n taroWindowProvider.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath);\n }\n // 设置 Current 的 page 和 router\n if (Current.page === this) {\n Current.page = null;\n Current.router = null;\n }\n // 触发生命周期\n safeExecute(this.$taroPath, ON_HIDE);\n // 通过事件触发子组件的生命周期\n eventCenter.trigger(getOnHideEventKey(id));\n },\n };\n\n if (process.env.TARO_PLATFORM === 'web') {\n config.getOpenerEventChannel = () => {\n return EventChannel.pageChannel;\n };\n }\n\n const isSWAN = process.env.TARO_ENV === 'swan'; // 百度小程序\n LIFECYCLES.forEach((lifecycle) => {\n let isDefer = false;\n let isEvent = false;\n lifecycle = lifecycle.replace(/^defer:/, () => {\n isDefer = true;\n return '';\n });\n lifecycle = lifecycle.replace(/^events:/, () => {\n isEvent = true;\n return '';\n });\n\n if (isEvent && process.env.TARO_ENV === 'alipay') {\n // 初始化 config.events 对象\n if (!config.events) config.events = {};\n config.events[lifecycle] = function () {\n return safeExecute(this.$taroPath, lifecycle, ...arguments);\n };\n } else {\n config[lifecycle] = function () {\n const exec = () => safeExecute(this.$taroPath, lifecycle, ...arguments);\n if (isSWAN) {\n return exec();\n }\n\n if (isDefer) {\n hasLoaded.then(exec);\n } else {\n return exec();\n }\n };\n }\n });\n\n // onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。\n SIDE_EFFECT_LIFECYCLES.forEach((lifecycle) => {\n if (\n component[lifecycle] ||\n component.prototype?.[lifecycle] ||\n component[lifecycle.replace(/^on/, 'enable')] ||\n pageConfig?.[lifecycle.replace(/^on/, 'enable')]\n ) {\n config[lifecycle] = function (...args) {\n const target = args[0]?.target;\n if (target?.id) {\n const id = target.id;\n const element = env.document.getElementById(id);\n if (element) {\n target.dataset = element.dataset;\n }\n }\n return safeExecute(this.$taroPath, lifecycle, ...args);\n };\n }\n });\n\n config.eh = eventHandler;\n\n if (!isUndefined(data)) {\n config.data = data;\n }\n\n hooks.call('modifyPageObject', config);\n\n return config;\n}\n\nexport function createComponentConfig(\n component: React.ComponentClass,\n componentName?: string,\n data?: Record<string, unknown>,\n) {\n const id = componentName ?? `taro_component_${pageId()}`;\n let componentElement: TaroRootElement | null = null;\n const [ATTACHED, DETACHED] = hooks.call('getMiniLifecycleImpl')!.component;\n\n const config: any = {\n [ATTACHED]() {\n perf.start(PAGE_INIT);\n this.pageIdCache = this.getPageId?.() || pageId();\n\n const path = getPath(id, { id: this.pageIdCache });\n\n Current.app!.mount!(component, path, () => {\n componentElement = env.document.getElementById<TaroRootElement>(path);\n ensure(componentElement !== null, '没有找到组件实例。');\n this.$taroInstances = instances.get(path);\n safeExecute(path, ON_LOAD);\n if (process.env.TARO_PLATFORM !== 'web') {\n componentElement.ctx = this;\n if (process.env.TARO_ENV !== 'tt' || !isEnableTTDom()) {\n componentElement.performUpdate(true);\n }\n }\n });\n },\n [DETACHED]() {\n const path = getPath(id, { id: this.pageIdCache });\n\n Current.app!.unmount!(path, () => {\n instances.delete(path);\n if (componentElement) {\n componentElement.ctx = null;\n }\n });\n },\n methods: {\n eh: eventHandler,\n },\n };\n\n if (!isUndefined(data)) {\n config.data = data;\n }\n\n [OPTIONS, EXTERNAL_CLASSES, BEHAVIORS].forEach((key) => {\n config[key] = component[key] ?? EMPTY_OBJ;\n });\n\n return config;\n}\n\nexport function createRecursiveComponentConfig(componentName?: string) {\n const isCustomWrapper = componentName === CUSTOM_WRAPPER;\n const [ATTACHED, DETACHED] = hooks.call('getMiniLifecycleImpl')!.component;\n\n const lifeCycles = isCustomWrapper\n ? {\n [ATTACHED]() {\n if (process.env.TARO_ENV === 'tt' && isEnableTTDom()) {\n return;\n }\n\n const componentId = this.data.i?.sid || this.props.i?.sid;\n if (isString(componentId)) {\n customWrapperCache.set(componentId, this);\n const el = env.document.getElementById(componentId);\n if (el) {\n el.ctx = this;\n }\n }\n },\n [DETACHED]() {\n if (process.env.TARO_ENV === 'tt' && isEnableTTDom()) {\n return;\n }\n\n const componentId = this.data.i?.sid || this.props.i?.sid;\n if (isString(componentId)) {\n customWrapperCache.delete(componentId);\n const el = env.document.getElementById(componentId);\n if (el) {\n el.ctx = null;\n }\n }\n },\n }\n : EMPTY_OBJ;\n\n // 不同平台的个性化配置\n const extraOptions: { [key: string]: any } = {};\n if (process.env.TARO_ENV === 'jd') {\n extraOptions.addGlobalClass = true;\n }\n\n return hooks.call(\n 'modifyRecursiveComponentConfig',\n {\n properties: {\n i: {\n type: Object,\n value: {\n [Shortcuts.NodeName]: getComponentsAlias(internalComponents)[VIEW]._num,\n },\n },\n l: {\n type: String,\n value: '',\n },\n },\n options: {\n ...extraOptions,\n virtualHost: !isCustomWrapper,\n },\n methods: {\n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aACN;EACA,GAAG;CACL,GACA,EAAE,gBAAgB,CACpB;AACF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Component, ComponentClass } from 'react';
|
|
2
|
+
import type { TaroElement } from '../dom/element';
|
|
3
|
+
import type { KeyFrame, MpEvent, ScrollTimelineOption, TFunc } from '../interface';
|
|
4
|
+
export interface Instance<T = Record<string, any>> extends Component<T>, Show, PageInstance {
|
|
5
|
+
tid?: string;
|
|
6
|
+
node?: TaroElement;
|
|
7
|
+
$forceUpdate?(): void;
|
|
8
|
+
$nextTick?(cb: () => void): void;
|
|
9
|
+
$options: Instance;
|
|
10
|
+
}
|
|
11
|
+
export interface PageProps {
|
|
12
|
+
tid?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ReactPageComponent<T = PageProps> extends ComponentClass<T>, PageInstance {
|
|
15
|
+
}
|
|
16
|
+
export interface ReactPageInstance<T = PageProps> extends Component<T>, PageInstance {
|
|
17
|
+
componentDidShow?(): void;
|
|
18
|
+
componentDidHide?(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface ReactAppInstance<T = AppInstance> extends Component<T>, AppInstance {
|
|
21
|
+
}
|
|
22
|
+
export interface PageLifeCycle extends Show {
|
|
23
|
+
eh?(event: MpEvent): void;
|
|
24
|
+
onAddToFavorites?(): void;
|
|
25
|
+
onLoad?(options: Record<string, unknown>, cb?: TFunc): void;
|
|
26
|
+
onOptionMenuClick?(): void;
|
|
27
|
+
onKeyboardHeight?(obj: {
|
|
28
|
+
height: number;
|
|
29
|
+
}): void;
|
|
30
|
+
onPageScroll?(obj: {
|
|
31
|
+
scrollTop: number;
|
|
32
|
+
}): void;
|
|
33
|
+
onPullDownRefresh?(): void;
|
|
34
|
+
onPullIntercept?(): void;
|
|
35
|
+
onPopMenuClick?(): void;
|
|
36
|
+
onReachBottom?(): void;
|
|
37
|
+
onReady?(): void;
|
|
38
|
+
onResize?(options: unknown): void;
|
|
39
|
+
onSaveExitState?(): void;
|
|
40
|
+
onShareAppMessage?(obj: {
|
|
41
|
+
from: string;
|
|
42
|
+
target?: TaroElement;
|
|
43
|
+
webViewUrl: string;
|
|
44
|
+
}): void;
|
|
45
|
+
onShareTimeline?(): void;
|
|
46
|
+
onTabItemTap?(obj: {
|
|
47
|
+
index: string;
|
|
48
|
+
pagePath: string;
|
|
49
|
+
text: string;
|
|
50
|
+
}): void;
|
|
51
|
+
onTitleClick?(): void;
|
|
52
|
+
onUnload?(): void;
|
|
53
|
+
}
|
|
54
|
+
export interface PageInstance extends PageLifeCycle {
|
|
55
|
+
/** 页面的初始数据 */
|
|
56
|
+
data?: Record<string, unknown>;
|
|
57
|
+
/** 页面路径 */
|
|
58
|
+
path?: string;
|
|
59
|
+
/** 页面的组件选项 */
|
|
60
|
+
options?: Record<string, unknown>;
|
|
61
|
+
/** 页面渲染引擎类型 */
|
|
62
|
+
renderer?: 'webview' | 'skyline';
|
|
63
|
+
/** 页面事件对象,支付宝小程序特有,详见[events](https://opendocs.alipay.com/mini/framework/page-detail#events) */
|
|
64
|
+
events?: Record<string, (...args: any[]) => any>;
|
|
65
|
+
/** 获得一个 EventChannel 对象,用于页面间通讯 */
|
|
66
|
+
getOpenerEventChannel?(): Record<string, any>;
|
|
67
|
+
/** 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html) */
|
|
68
|
+
animate?(selector: string, keyFrames: KeyFrame[], duration: number, callback: () => void): void;
|
|
69
|
+
/** 滚动驱动的动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html) */
|
|
70
|
+
animate?(selector: string, keyFrames: KeyFrame[], duration: number, scrollTimeline: ScrollTimelineOption): void;
|
|
71
|
+
}
|
|
72
|
+
interface Show {
|
|
73
|
+
componentDidShow?(): void;
|
|
74
|
+
componentDidHide?(): void;
|
|
75
|
+
onShow?(): void;
|
|
76
|
+
onHide?(): void;
|
|
77
|
+
}
|
|
78
|
+
export interface AppInstance extends Show {
|
|
79
|
+
componentDidShow?(options?: Record<string, unknown>): void;
|
|
80
|
+
mount?(component: React.ComponentClass, id: string, cb: (...args: any[]) => void): void;
|
|
81
|
+
mount?(component: React.ComponentClass, id: string, getCtx: (...args: any[]) => void, cb: (...args: any[]) => void): void;
|
|
82
|
+
onError?(error: string): void;
|
|
83
|
+
onLaunch?(options?: Record<string, unknown>): void;
|
|
84
|
+
onPageNotFound?(res: any): void;
|
|
85
|
+
onUnhandledRejection?(error: any): void;
|
|
86
|
+
onShow?(options?: Record<string, unknown>): void;
|
|
87
|
+
onHide?(options?: Record<string, unknown>): void;
|
|
88
|
+
unmount?(id: string, cb?: () => void): void;
|
|
89
|
+
taroGlobalData?: Record<any, any>;
|
|
90
|
+
config?: Record<any, any>;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.js","names":[],"sources":["../../src/emitter/emitter.ts"],"sourcesContent":["import { Events, hooks } from '@spcsn/taro-shared';\n\nconst eventCenter = hooks.call('getEventCenter', Events)!;\n\nexport type EventsType = typeof Events;\nexport { eventCenter, Events };\n"],"mappings":";;AAEA,MAAM,cAAc,MAAM,KAAK,kBAAkB,MAAM"}
|