@tarojs/runtime 4.1.12-alpha.4 → 4.1.12-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bom/document.js +135 -2
- package/dist/bom/document.js.map +1 -1
- package/dist/dom/event.d.ts +2 -1
- package/dist/dom/event.js +9 -1
- package/dist/dom/event.js.map +1 -1
- package/dist/dom-external/inner-html/html.d.ts +5 -0
- package/dist/dom-external/inner-html/html.js +8 -1
- package/dist/dom-external/inner-html/html.js.map +1 -1
- package/dist/dsl/common.js +22 -4
- package/dist/dsl/common.js.map +1 -1
- package/dist/index.cjs.d.ts +5 -1
- package/dist/index.cjs.js +171 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interface/hydrate.d.ts +1 -0
- package/dist/runtime.esm.d.ts +5 -1
- package/dist/runtime.esm.js +171 -7
- package/dist/runtime.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -3233,7 +3233,13 @@ function setInnerHTML(element, html) {
|
|
|
3233
3233
|
while (element.firstChild) {
|
|
3234
3234
|
element.removeChild(element.firstChild);
|
|
3235
3235
|
}
|
|
3236
|
-
|
|
3236
|
+
let { ownerDocument } = element;
|
|
3237
|
+
if (process.env.TARO_ENV === 'tt' && shared.isEnableTTDom()) {
|
|
3238
|
+
if ('appDocument' in tt) {
|
|
3239
|
+
ownerDocument = tt.appDocument;
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
const children = parser(html, ownerDocument);
|
|
3237
3243
|
for (let i = 0; i < children.length; i++) {
|
|
3238
3244
|
element.appendChild(children[i]);
|
|
3239
3245
|
}
|
|
@@ -3516,6 +3522,14 @@ function eventHandler(event) {
|
|
|
3516
3522
|
}
|
|
3517
3523
|
}
|
|
3518
3524
|
}
|
|
3525
|
+
function eventHandlerTTDom(ele, listener, event) {
|
|
3526
|
+
Object.assign(event, {
|
|
3527
|
+
mpEvent: event,
|
|
3528
|
+
bubbles: true,
|
|
3529
|
+
cancelable: true,
|
|
3530
|
+
});
|
|
3531
|
+
listener(event, ele);
|
|
3532
|
+
}
|
|
3519
3533
|
|
|
3520
3534
|
class FormElement extends TaroElement {
|
|
3521
3535
|
get type() {
|
|
@@ -3947,8 +3961,140 @@ function createDocument() {
|
|
|
3947
3961
|
doc.body = body;
|
|
3948
3962
|
return doc;
|
|
3949
3963
|
}
|
|
3964
|
+
function createTTDomDocument() {
|
|
3965
|
+
var _a;
|
|
3966
|
+
const document = tt === null || tt === void 0 ? void 0 : tt.appDocument;
|
|
3967
|
+
if (!document) {
|
|
3968
|
+
throw new Error('tt.appDocument is not found');
|
|
3969
|
+
}
|
|
3970
|
+
const html = document.createElement(HTML);
|
|
3971
|
+
const head = document.createElement(HEAD);
|
|
3972
|
+
const body = document.createElement(BODY);
|
|
3973
|
+
const app = document.createElement(APP);
|
|
3974
|
+
app.id = APP;
|
|
3975
|
+
const container = document.createElement(CONTAINER);
|
|
3976
|
+
const emptyFunction = () => { };
|
|
3977
|
+
document.childNodes.push(html);
|
|
3978
|
+
html.childNodes.push(head, body);
|
|
3979
|
+
body.childNodes.push(container);
|
|
3980
|
+
container.childNodes.push(app);
|
|
3981
|
+
document.documentElement = html;
|
|
3982
|
+
document.head = head;
|
|
3983
|
+
document.body = body;
|
|
3984
|
+
document.appElement = app;
|
|
3985
|
+
let builtInComponents = (_a = tt === null || tt === void 0 ? void 0 : tt.getBuiltInComponents) === null || _a === void 0 ? void 0 : _a.call(tt);
|
|
3986
|
+
if (Array.isArray(builtInComponents)) {
|
|
3987
|
+
builtInComponents = new Set(builtInComponents);
|
|
3988
|
+
}
|
|
3989
|
+
else if (!(builtInComponents instanceof Set)) {
|
|
3990
|
+
builtInComponents = new Set([...shared.DEFAULT_COMPONENTS, ...shared.TT_SPECIFIC_COMPONENTS]);
|
|
3991
|
+
}
|
|
3992
|
+
document.getElementById = function getElementById(id) {
|
|
3993
|
+
if (id === 'app') {
|
|
3994
|
+
return app;
|
|
3995
|
+
}
|
|
3996
|
+
else {
|
|
3997
|
+
return Object.getPrototypeOf(this).getElementById.call(this, id);
|
|
3998
|
+
}
|
|
3999
|
+
};
|
|
4000
|
+
document.getLastPage = function getLastPage() {
|
|
4001
|
+
let last;
|
|
4002
|
+
for (const v of this._pageDocumentMap.values())
|
|
4003
|
+
last = v;
|
|
4004
|
+
return last;
|
|
4005
|
+
};
|
|
4006
|
+
document.createElement = function (type, ...args) {
|
|
4007
|
+
if (type === 'root') {
|
|
4008
|
+
return this.getLastPage();
|
|
4009
|
+
}
|
|
4010
|
+
else {
|
|
4011
|
+
const el = builtInComponents.has(type)
|
|
4012
|
+
? Object.getPrototypeOf(this).createElement.call(this, type, ...args)
|
|
4013
|
+
: Object.getPrototypeOf(this).createNativeComponent.call(this, type, {
|
|
4014
|
+
__tt__inner__options__: {
|
|
4015
|
+
name: type,
|
|
4016
|
+
},
|
|
4017
|
+
});
|
|
4018
|
+
// 给元素加上 scopeId
|
|
4019
|
+
el.setAttribute('class', '');
|
|
4020
|
+
// 保存原始的 setAttribute 和 removeAttribute
|
|
4021
|
+
const originalSetAttribute = el.setAttribute.bind(el);
|
|
4022
|
+
const originalRemoveAttribute = el.removeAttribute.bind(el);
|
|
4023
|
+
// 拦截 setAttribute 来处理 catchMove
|
|
4024
|
+
el.setAttribute = function (name, value) {
|
|
4025
|
+
const result = originalSetAttribute(name, value);
|
|
4026
|
+
// 处理 catchMove 属性
|
|
4027
|
+
if (name === 'catchMove' && value) {
|
|
4028
|
+
el.addEventListener('catchtouchmove', emptyFunction);
|
|
4029
|
+
}
|
|
4030
|
+
return result;
|
|
4031
|
+
};
|
|
4032
|
+
// 拦截 removeAttribute 来处理 catchMove
|
|
4033
|
+
el.removeAttribute = function (name) {
|
|
4034
|
+
const oldValue = el.getAttribute(name);
|
|
4035
|
+
// 处理 catchMove 属性
|
|
4036
|
+
if (name === 'catchMove' && oldValue) {
|
|
4037
|
+
el.removeEventListener('catchtouchmove', emptyFunction);
|
|
4038
|
+
}
|
|
4039
|
+
return originalRemoveAttribute(name);
|
|
4040
|
+
};
|
|
4041
|
+
if (process.env.FRAMEWORK === 'preact') {
|
|
4042
|
+
const ttEventListener = el.addEventListener.bind(el);
|
|
4043
|
+
const ttRemoveEventListener = el.removeEventListener.bind(el);
|
|
4044
|
+
el.addEventListener = function (type, listener) {
|
|
4045
|
+
if (type === 'click') {
|
|
4046
|
+
type = 'tap';
|
|
4047
|
+
}
|
|
4048
|
+
const bindEventName = type.startsWith('bind') || type.startsWith('catch') ? type : `bind${type}`;
|
|
4049
|
+
// 创建包装函数
|
|
4050
|
+
const wrapper = (event) => {
|
|
4051
|
+
const type = event.type;
|
|
4052
|
+
// 对齐 modifyMpEvent 处理逻辑
|
|
4053
|
+
if (type === 'tap') {
|
|
4054
|
+
event.type = 'click';
|
|
4055
|
+
}
|
|
4056
|
+
else if (type === 'focus') {
|
|
4057
|
+
event.type = 'focusin';
|
|
4058
|
+
}
|
|
4059
|
+
else if (type === 'blur') {
|
|
4060
|
+
event.type = 'focusout';
|
|
4061
|
+
}
|
|
4062
|
+
Object.assign(event, {
|
|
4063
|
+
mpEvent: event,
|
|
4064
|
+
bubbles: true,
|
|
4065
|
+
cancelable: true,
|
|
4066
|
+
});
|
|
4067
|
+
listener.call(el, event);
|
|
4068
|
+
};
|
|
4069
|
+
// 保存包装函数的引用,用于后续移除
|
|
4070
|
+
if (!el.__eventWrappers) {
|
|
4071
|
+
el.__eventWrappers = new WeakMap();
|
|
4072
|
+
}
|
|
4073
|
+
el.__eventWrappers.set(listener, wrapper);
|
|
4074
|
+
ttEventListener(bindEventName, wrapper);
|
|
4075
|
+
};
|
|
4076
|
+
el.removeEventListener = function (type, listener) {
|
|
4077
|
+
var _a;
|
|
4078
|
+
if (type === 'click') {
|
|
4079
|
+
type = 'tap';
|
|
4080
|
+
}
|
|
4081
|
+
const bindEventName = type.startsWith('bind') || type.startsWith('catch') ? type : `bind${type}`;
|
|
4082
|
+
// 获取之前保存的包装函数
|
|
4083
|
+
const wrapper = (_a = el.__eventWrappers) === null || _a === void 0 ? void 0 : _a.get(listener);
|
|
4084
|
+
if (wrapper) {
|
|
4085
|
+
ttRemoveEventListener(bindEventName, wrapper);
|
|
4086
|
+
delete el.__eventWrappers[listener];
|
|
4087
|
+
}
|
|
4088
|
+
};
|
|
4089
|
+
}
|
|
4090
|
+
return el;
|
|
4091
|
+
}
|
|
4092
|
+
};
|
|
4093
|
+
return document;
|
|
4094
|
+
}
|
|
3950
4095
|
// Note: 小程序端 vite 打包成 commonjs,const document = xxx 会报错,所以把 document 改为 taroDocumentProvider
|
|
3951
|
-
const taroDocumentProvider = process.env.TARO_PLATFORM === 'web' ? env.document : (env.document =
|
|
4096
|
+
const taroDocumentProvider = process.env.TARO_PLATFORM === 'web' ? env.document : (env.document =
|
|
4097
|
+
shared.isEnableTTDom() ? createTTDomDocument() : createDocument());
|
|
3952
4098
|
|
|
3953
4099
|
// for Vue3
|
|
3954
4100
|
class SVGElement extends TaroElement {
|
|
@@ -4055,13 +4201,23 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4055
4201
|
}
|
|
4056
4202
|
const mount = () => {
|
|
4057
4203
|
Current.app.mount(component, $taroPath, () => {
|
|
4058
|
-
|
|
4204
|
+
if (process.env.TARO_ENV === 'tt' && shared.isEnableTTDom()) {
|
|
4205
|
+
pageElement = env.document.getPageDocumentById(this.__webviewId__);
|
|
4206
|
+
}
|
|
4207
|
+
else {
|
|
4208
|
+
pageElement = env.document.getElementById($taroPath);
|
|
4209
|
+
}
|
|
4059
4210
|
shared.ensure(pageElement !== null, '没有找到页面实例。');
|
|
4060
4211
|
safeExecute($taroPath, ON_LOAD, this.$taroParams);
|
|
4061
4212
|
loadResolver();
|
|
4062
4213
|
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4063
4214
|
pageElement.ctx = this;
|
|
4064
|
-
|
|
4215
|
+
if (process.env.TARO_ENV === 'tt' && shared.isEnableTTDom()) {
|
|
4216
|
+
pageElement.sync();
|
|
4217
|
+
}
|
|
4218
|
+
else {
|
|
4219
|
+
pageElement.performUpdate(true, cb);
|
|
4220
|
+
}
|
|
4065
4221
|
}
|
|
4066
4222
|
else {
|
|
4067
4223
|
shared.isFunction(cb) && cb();
|
|
@@ -4222,7 +4378,9 @@ function createComponentConfig(component, componentName, data) {
|
|
|
4222
4378
|
safeExecute(path, ON_LOAD);
|
|
4223
4379
|
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4224
4380
|
componentElement.ctx = this;
|
|
4225
|
-
|
|
4381
|
+
if (process.env.TARO_ENV !== 'tt' || !shared.isEnableTTDom()) {
|
|
4382
|
+
componentElement.performUpdate(true);
|
|
4383
|
+
}
|
|
4226
4384
|
}
|
|
4227
4385
|
});
|
|
4228
4386
|
},
|
|
@@ -4255,6 +4413,9 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
4255
4413
|
? {
|
|
4256
4414
|
[ATTACHED]() {
|
|
4257
4415
|
var _a, _b;
|
|
4416
|
+
if (process.env.TARO_ENV === 'tt' && shared.isEnableTTDom()) {
|
|
4417
|
+
return;
|
|
4418
|
+
}
|
|
4258
4419
|
const componentId = ((_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid) || ((_b = this.props.i) === null || _b === void 0 ? void 0 : _b.sid);
|
|
4259
4420
|
if (shared.isString(componentId)) {
|
|
4260
4421
|
customWrapperCache.set(componentId, this);
|
|
@@ -4266,6 +4427,9 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
4266
4427
|
},
|
|
4267
4428
|
[DETACHED]() {
|
|
4268
4429
|
var _a, _b;
|
|
4430
|
+
if (process.env.TARO_ENV === 'tt' && shared.isEnableTTDom()) {
|
|
4431
|
+
return;
|
|
4432
|
+
}
|
|
4269
4433
|
const componentId = ((_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid) || ((_b = this.props.i) === null || _b === void 0 ? void 0 : _b.sid);
|
|
4270
4434
|
if (shared.isString(componentId)) {
|
|
4271
4435
|
customWrapperCache.delete(componentId);
|
|
@@ -5193,6 +5357,7 @@ exports.document = taroDocumentProvider;
|
|
|
5193
5357
|
exports.env = env;
|
|
5194
5358
|
exports.eventCenter = eventCenter;
|
|
5195
5359
|
exports.eventHandler = eventHandler;
|
|
5360
|
+
exports.eventHandlerTTDom = eventHandlerTTDom;
|
|
5196
5361
|
exports.eventSource = eventSource;
|
|
5197
5362
|
exports.extend = extend;
|
|
5198
5363
|
exports.getComponentsAlias = getComponentsAlias;
|
|
@@ -5225,6 +5390,7 @@ exports.perf = perf;
|
|
|
5225
5390
|
exports.removePageInstance = removePageInstance;
|
|
5226
5391
|
exports.requestAnimationFrame = _raf;
|
|
5227
5392
|
exports.safeExecute = safeExecute;
|
|
5393
|
+
exports.setInnerHTML = setInnerHTML;
|
|
5228
5394
|
exports.shortcutAttr = shortcutAttr;
|
|
5229
5395
|
exports.stringify = stringify;
|
|
5230
5396
|
exports.stripBasename = stripBasename;
|