@mpcore/simulator 0.5.1 → 0.6.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/README.md +20 -0
- package/dist/index.d.mts +45 -15
- package/dist/index.mjs +289 -109
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,3 +24,23 @@
|
|
|
24
24
|
浏览器会话的 `renderCurrentPage().styles` 提供当前页面的 `cssText`、项目相对 `dependencies` 和 `appWxssEnabled`,Web demo 将该结果挂载到页面预览的 Shadow DOM。解析器读取 `app.wxss`、页面 `.wxss` 及递归本地 `@import`,保留导入位置和全局在前、页面在后的层叠顺序;页面 `.wxss` 内联的全局样式快照也会动态加载,并保留其后页面自有样式的覆盖优先级。文件修改后重新渲染会读取最新内容,包括只更新样式的场景,不重建页面或 App 实例。
|
|
25
25
|
|
|
26
26
|
此入口只负责页面样式依赖和 CSS 兼容声明,不实现嵌套组件的完整样式隔离、类名前缀转换或 `rpx` 布局换算。Component 页面的 `page-isolated`、`page-strong-isolated`、`page-apply-shared`、`page-shared` 禁用隐式 `app.wxss`,页面仍可显式导入样式;最终页面 JSON 的 `styleIsolation` 优先于 JS 定义,JSON 未提供该值时才保留 JS 选项。普通 `Page` 注册不应用组件隔离选项,普通 `isolated` 也不等同于 `page-isolated`。缺失依赖、循环导入、非法 CSS 和不支持的导入会抛出明确错误。支持带媒体条件的本地导入;远程导入及 `layer` / `supports` 导入条件不受支持,也不会触发外部请求。
|
|
27
|
+
|
|
28
|
+
## 分块请求 mock
|
|
29
|
+
|
|
30
|
+
`session.mockRequest()` 支持为 `enableChunked: true` 的请求声明分块,默认仍不访问网络:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
session.mockRequest({
|
|
34
|
+
url: 'https://example.test/data',
|
|
35
|
+
response: '',
|
|
36
|
+
delay: 10,
|
|
37
|
+
chunks: [
|
|
38
|
+
{ data: new Uint8Array([65]).buffer, delay: 10 },
|
|
39
|
+
{ data: new Uint8Array([66]).buffer, delay: 10 },
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
顶层 `delay` 控制响应头阶段,每个分块的 `delay` 相对于前一个阶段。请求提供 `onHeadersReceived` / `offHeadersReceived`、`onChunkReceived` / `offChunkReceived`;不传回调的 off 方法移除全部对应监听。取消会停止后续分块并仅触发一次 `fail → complete`。可设置 `error` 模拟已发送分块后的连接失败。
|
|
45
|
+
|
|
46
|
+
分块请求的 `success.data` 按已验证的微信 DevTools 行为返回空字符串;数据只通过 chunk 交付。未设置 `chunks` 时不会将普通 `response` 自动拆分。自定义 driver 仍可只实现 abort,公开监听方法类型为可选,使用前需检测能力。此模型不提供 Streams 或传输反压保证。
|
package/dist/index.d.mts
CHANGED
|
@@ -641,7 +641,10 @@ export interface HeadlessWxRequestSuccessResult {
|
|
|
641
641
|
header: Record<string, string>;
|
|
642
642
|
statusCode: number;
|
|
643
643
|
}
|
|
644
|
-
export interface HeadlessWxRequestOption extends HeadlessWxCallbackOption<HeadlessWxRequestSuccessResult> {
|
|
644
|
+
export interface HeadlessWxRequestOption extends Omit<HeadlessWxCallbackOption<HeadlessWxRequestSuccessResult>, 'complete'> {
|
|
645
|
+
complete?: (result?: HeadlessWxRequestSuccessResult | Error) => void;
|
|
646
|
+
enableChunked?: boolean;
|
|
647
|
+
responseType?: 'text' | 'arraybuffer';
|
|
645
648
|
data?: unknown;
|
|
646
649
|
header?: Record<string, string>;
|
|
647
650
|
method?: string;
|
|
@@ -650,6 +653,21 @@ export interface HeadlessWxRequestOption extends HeadlessWxCallbackOption<Headle
|
|
|
650
653
|
export interface HeadlessWxRequestTask {
|
|
651
654
|
abort: () => void;
|
|
652
655
|
}
|
|
656
|
+
export interface HeadlessWxRequestHeadersResult {
|
|
657
|
+
cookies: string[];
|
|
658
|
+
header: Record<string, string>;
|
|
659
|
+
statusCode: number;
|
|
660
|
+
}
|
|
661
|
+
export interface HeadlessWxRequestChunkResult {
|
|
662
|
+
data: ArrayBuffer;
|
|
663
|
+
}
|
|
664
|
+
export interface HeadlessWxNetworkRequestTask extends HeadlessWxRequestTask {
|
|
665
|
+
/** 自定义传输可仅实现 abort,使用监听前应检测能力。 */
|
|
666
|
+
onHeadersReceived?: (callback: (result: HeadlessWxRequestHeadersResult) => void) => void;
|
|
667
|
+
offHeadersReceived?: (callback?: (result: HeadlessWxRequestHeadersResult) => void) => void;
|
|
668
|
+
onChunkReceived?: (callback: (result: HeadlessWxRequestChunkResult) => void) => void;
|
|
669
|
+
offChunkReceived?: (callback?: (result: HeadlessWxRequestChunkResult) => void) => void;
|
|
670
|
+
}
|
|
653
671
|
export interface HeadlessWxDownloadFileSuccessResult {
|
|
654
672
|
errMsg: string;
|
|
655
673
|
statusCode: number;
|
|
@@ -934,7 +952,7 @@ export interface HeadlessWxDriver extends HeadlessWxDriverCapabilities {
|
|
|
934
952
|
removeSavedFile: (option: HeadlessWxRemoveSavedFileOption) => {
|
|
935
953
|
errMsg: string;
|
|
936
954
|
};
|
|
937
|
-
request: (option: HeadlessWxRequestOption) =>
|
|
955
|
+
request: (option: HeadlessWxRequestOption) => HeadlessWxNetworkRequestTask;
|
|
938
956
|
saveFile: (option: HeadlessWxSaveFileOption) => HeadlessWxSaveFileSuccessResult;
|
|
939
957
|
saveImageToPhotosAlbum: (option: HeadlessWxSaveImageToPhotosAlbumOption) => HeadlessWxSaveImageToPhotosAlbumResult;
|
|
940
958
|
saveVideoToPhotosAlbum: (option: HeadlessWxSaveVideoToPhotosAlbumOption) => HeadlessWxSaveVideoToPhotosAlbumResult;
|
|
@@ -1011,7 +1029,7 @@ export interface HeadlessWx extends HeadlessUniEventBus {
|
|
|
1011
1029
|
removeStorage: (option: HeadlessWxRemoveStorageOption) => HeadlessWxStorageResult | undefined;
|
|
1012
1030
|
removeStorageSync: (key: string) => void;
|
|
1013
1031
|
rpx2px: (value: number) => number;
|
|
1014
|
-
request: (option: HeadlessWxRequestOption) =>
|
|
1032
|
+
request: (option: HeadlessWxRequestOption) => HeadlessWxNetworkRequestTask;
|
|
1015
1033
|
saveFile: (option: HeadlessWxSaveFileOption) => HeadlessWxSaveFileSuccessResult | undefined;
|
|
1016
1034
|
setBackgroundColor: (option: HeadlessWxSetBackgroundColorOption) => {
|
|
1017
1035
|
errMsg: string;
|
|
@@ -1380,6 +1398,7 @@ interface DomNodeLike$5 {
|
|
|
1380
1398
|
attribs?: Record<string, string>;
|
|
1381
1399
|
children?: DomNodeLike$5[];
|
|
1382
1400
|
data?: string;
|
|
1401
|
+
dataset?: Record<string, unknown>;
|
|
1383
1402
|
name?: string;
|
|
1384
1403
|
parent?: DomNodeLike$5 | null;
|
|
1385
1404
|
type?: string;
|
|
@@ -1389,7 +1408,7 @@ interface BrowserRenderScope {
|
|
|
1389
1408
|
alias?: string;
|
|
1390
1409
|
classList?: string[];
|
|
1391
1410
|
data: Record<string, any>;
|
|
1392
|
-
dataset?: Record<string,
|
|
1411
|
+
dataset?: Record<string, unknown>;
|
|
1393
1412
|
eventBindings?: Map<string, {
|
|
1394
1413
|
method: string;
|
|
1395
1414
|
stopAfter: boolean;
|
|
@@ -1457,6 +1476,7 @@ interface DomNodeLike$4 {
|
|
|
1457
1476
|
attribs?: Record<string, string>;
|
|
1458
1477
|
children?: DomNodeLike$4[];
|
|
1459
1478
|
data?: string;
|
|
1479
|
+
dataset?: Record<string, unknown>;
|
|
1460
1480
|
name?: string;
|
|
1461
1481
|
parent?: DomNodeLike$4 | null;
|
|
1462
1482
|
type?: string;
|
|
@@ -1466,7 +1486,7 @@ interface RuntimeRenderScope {
|
|
|
1466
1486
|
alias?: string;
|
|
1467
1487
|
classList?: string[];
|
|
1468
1488
|
data: Record<string, any>;
|
|
1469
|
-
dataset?: Record<string,
|
|
1489
|
+
dataset?: Record<string, unknown>;
|
|
1470
1490
|
eventBindings?: Map<string, {
|
|
1471
1491
|
method: string;
|
|
1472
1492
|
stopAfter: boolean;
|
|
@@ -1567,6 +1587,13 @@ export interface HeadlessWxModalLogEntry {
|
|
|
1567
1587
|
title: string;
|
|
1568
1588
|
}
|
|
1569
1589
|
export interface HeadlessWxRequestMockDefinition {
|
|
1590
|
+
/** enableChunked 请求的显式分块,每个 delay 相对于前一个阶段。 */
|
|
1591
|
+
chunks?: Array<{
|
|
1592
|
+
data: ArrayBuffer;
|
|
1593
|
+
delay?: number;
|
|
1594
|
+
}>;
|
|
1595
|
+
/** 分块发送完成后触发的模拟错误。 */
|
|
1596
|
+
error?: string;
|
|
1570
1597
|
delay?: number;
|
|
1571
1598
|
header?: Record<string, string>;
|
|
1572
1599
|
method?: string;
|
|
@@ -1849,7 +1876,7 @@ export declare function createHeadlessWxState(scheduler?: Pick<RuntimeScheduler,
|
|
|
1849
1876
|
errMsg: string;
|
|
1850
1877
|
};
|
|
1851
1878
|
removeStorageSync(key: string): void;
|
|
1852
|
-
request(option: HeadlessWxRequestOption):
|
|
1879
|
+
request(option: HeadlessWxRequestOption): HeadlessWxNetworkRequestTask;
|
|
1853
1880
|
removeSavedFile(option: HeadlessWxRemoveSavedFileOption): {
|
|
1854
1881
|
errMsg: string;
|
|
1855
1882
|
};
|
|
@@ -2545,14 +2572,14 @@ export declare class BrowserHeadlessSession {
|
|
|
2545
2572
|
callTapBinding(scopeId: string, methodName: string): any;
|
|
2546
2573
|
callTapBindingWithEvent(scopeId: string, methodName: string, event?: {
|
|
2547
2574
|
currentTarget?: {
|
|
2548
|
-
dataset?: Record<string,
|
|
2575
|
+
dataset?: Record<string, unknown>;
|
|
2549
2576
|
id?: string;
|
|
2550
2577
|
};
|
|
2551
|
-
dataset?: Record<string,
|
|
2578
|
+
dataset?: Record<string, unknown>;
|
|
2552
2579
|
id?: string;
|
|
2553
2580
|
mark?: Record<string, unknown>;
|
|
2554
2581
|
target?: {
|
|
2555
|
-
dataset?: Record<string,
|
|
2582
|
+
dataset?: Record<string, unknown>;
|
|
2556
2583
|
id?: string;
|
|
2557
2584
|
};
|
|
2558
2585
|
}): any;
|
|
@@ -2642,25 +2669,26 @@ interface DomNodeLike$3 {
|
|
|
2642
2669
|
attribs?: Record<string, string>;
|
|
2643
2670
|
children?: DomNodeLike$3[];
|
|
2644
2671
|
data?: string;
|
|
2672
|
+
dataset?: Record<string, unknown>;
|
|
2645
2673
|
name?: string;
|
|
2646
2674
|
parent?: DomNodeLike$3 | null;
|
|
2647
2675
|
type?: string;
|
|
2648
2676
|
}
|
|
2649
|
-
interface HeadlessTestingNodeEventInit {
|
|
2677
|
+
export interface HeadlessTestingNodeEventInit {
|
|
2650
2678
|
currentTarget?: {
|
|
2651
|
-
dataset?: Record<string,
|
|
2679
|
+
dataset?: Record<string, unknown>;
|
|
2652
2680
|
id?: string;
|
|
2653
2681
|
};
|
|
2654
|
-
dataset?: Record<string,
|
|
2682
|
+
dataset?: Record<string, unknown>;
|
|
2655
2683
|
detail?: unknown;
|
|
2656
2684
|
id?: string;
|
|
2657
2685
|
mark?: Record<string, unknown>;
|
|
2658
2686
|
target?: {
|
|
2659
|
-
dataset?: Record<string,
|
|
2687
|
+
dataset?: Record<string, unknown>;
|
|
2660
2688
|
id?: string;
|
|
2661
2689
|
};
|
|
2662
2690
|
}
|
|
2663
|
-
interface HeadlessTestingNodeValueEventInit extends HeadlessTestingNodeEventInit {
|
|
2691
|
+
export interface HeadlessTestingNodeValueEventInit extends HeadlessTestingNodeEventInit {
|
|
2664
2692
|
detail?: {
|
|
2665
2693
|
value?: string;
|
|
2666
2694
|
[key: string]: unknown;
|
|
@@ -2688,7 +2716,7 @@ export declare class HeadlessTestingNodeHandle {
|
|
|
2688
2716
|
$$(selector: string): Promise<HeadlessTestingNodeHandle[]>;
|
|
2689
2717
|
getElementsByXpath(expression: string): Promise<HeadlessTestingNodeHandle[]>;
|
|
2690
2718
|
attr(name: string): Promise<string | undefined>;
|
|
2691
|
-
dataset(): Promise<Record<string,
|
|
2719
|
+
dataset(): Promise<Record<string, unknown>>;
|
|
2692
2720
|
scope(): Promise<{
|
|
2693
2721
|
scopeId: string;
|
|
2694
2722
|
snapshot: () => Promise<unknown>;
|
|
@@ -2723,6 +2751,7 @@ interface DomNodeLike$2 {
|
|
|
2723
2751
|
attribs?: Record<string, string>;
|
|
2724
2752
|
children?: DomNodeLike$2[];
|
|
2725
2753
|
data?: string;
|
|
2754
|
+
dataset?: Record<string, unknown>;
|
|
2726
2755
|
name?: string;
|
|
2727
2756
|
parent?: DomNodeLike$2 | null;
|
|
2728
2757
|
type?: string;
|
|
@@ -2738,6 +2767,7 @@ interface DomNodeLike$1 {
|
|
|
2738
2767
|
attribs?: Record<string, string>;
|
|
2739
2768
|
children?: DomNodeLike$1[];
|
|
2740
2769
|
data?: string;
|
|
2770
|
+
dataset?: Record<string, unknown>;
|
|
2741
2771
|
name?: string;
|
|
2742
2772
|
parent?: DomNodeLike$1 | null;
|
|
2743
2773
|
type?: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1776,6 +1776,26 @@ function flushComponentAttachments(instances, attach) {
|
|
|
1776
1776
|
return pending.length > 0;
|
|
1777
1777
|
}
|
|
1778
1778
|
//#endregion
|
|
1779
|
+
//#region src/runtime/componentInstance/discardedReady.ts
|
|
1780
|
+
const discardedReady = /* @__PURE__ */ new WeakMap();
|
|
1781
|
+
/** 初始模板分支被 props 替换时,微信仍发送 ready,但不发送 attached 或 detached。 */
|
|
1782
|
+
function scheduleDiscardedComponentReady(cache, scopeId, instance) {
|
|
1783
|
+
const pending = discardedReady.get(cache) ?? /* @__PURE__ */ new Map();
|
|
1784
|
+
pending.set(scopeId, instance);
|
|
1785
|
+
discardedReady.set(cache, pending);
|
|
1786
|
+
}
|
|
1787
|
+
function flushDiscardedComponentReady(cache, pageScopeId, ready) {
|
|
1788
|
+
const pending = discardedReady.get(cache);
|
|
1789
|
+
if (!pending) return;
|
|
1790
|
+
const current = [...pending].filter(([scopeId]) => scopeId.startsWith(`${pageScopeId}/`));
|
|
1791
|
+
for (const [scopeId, instance] of current) {
|
|
1792
|
+
pending.delete(scopeId);
|
|
1793
|
+
instance.__ready__ = true;
|
|
1794
|
+
}
|
|
1795
|
+
for (const [, instance] of current) ready(instance);
|
|
1796
|
+
if (!pending.size) discardedReady.delete(cache);
|
|
1797
|
+
}
|
|
1798
|
+
//#endregion
|
|
1779
1799
|
//#region src/runtime/pageLifecycle.ts
|
|
1780
1800
|
const loadingPages = /* @__PURE__ */ new WeakSet();
|
|
1781
1801
|
function isPageBeforeReady(page) {
|
|
@@ -1876,13 +1896,13 @@ const BLOCKED_MEMBER_KEYS = /* @__PURE__ */ new Set([
|
|
|
1876
1896
|
"prototype"
|
|
1877
1897
|
]);
|
|
1878
1898
|
const NUMERIC_DOT_PATH_RE = /\.(\d+)(?=[.[\s,}\]]|$)/g;
|
|
1879
|
-
function isMustacheOnly$
|
|
1899
|
+
function isMustacheOnly$3(value) {
|
|
1880
1900
|
const trimmed = value.trim();
|
|
1881
1901
|
return trimmed.startsWith("{{") && trimmed.endsWith("}}") && !trimmed.includes("{{", 2);
|
|
1882
1902
|
}
|
|
1883
1903
|
function unwrapMustacheExpression(expression) {
|
|
1884
1904
|
const normalized = expression.trim();
|
|
1885
|
-
if (isMustacheOnly$
|
|
1905
|
+
if (isMustacheOnly$3(normalized)) return normalized.slice(2, -2).trim();
|
|
1886
1906
|
return normalized;
|
|
1887
1907
|
}
|
|
1888
1908
|
function parseTemplateExpression(expression) {
|
|
@@ -2128,6 +2148,20 @@ function resolveBrowserComponentPageStyleIsolation(files, page, route, miniprogr
|
|
|
2128
2148
|
return isolation === void 0 ? definitionIsolation : typeof isolation === "string" ? isolation : void 0;
|
|
2129
2149
|
}
|
|
2130
2150
|
//#endregion
|
|
2151
|
+
//#region src/runtime/componentInstance/selection.ts
|
|
2152
|
+
function hasExportBehavior(definition, visited = /* @__PURE__ */ new Set()) {
|
|
2153
|
+
if (visited.has(definition)) return false;
|
|
2154
|
+
visited.add(definition);
|
|
2155
|
+
return (Array.isArray(definition.behaviors) ? definition.behaviors : []).some((behavior) => behavior === "wx://component-export" || behavior !== null && typeof behavior === "object" && hasExportBehavior(behavior, visited));
|
|
2156
|
+
}
|
|
2157
|
+
/** 原生选择器尊重组件导出行为;测试桥接继续保留完整组件实例。 */
|
|
2158
|
+
function resolveNativeComponentSelection(instance) {
|
|
2159
|
+
if (!instance) return null;
|
|
2160
|
+
const definition = instance.__definition__;
|
|
2161
|
+
if (!definition || !hasExportBehavior(definition) || typeof instance.export !== "function") return instance;
|
|
2162
|
+
return instance.export();
|
|
2163
|
+
}
|
|
2164
|
+
//#endregion
|
|
2131
2165
|
//#region src/runtime/componentResolution.ts
|
|
2132
2166
|
function resolveMiniProgramComponent(ownerFilePath, request, miniprogramRootPath, hasFile) {
|
|
2133
2167
|
const localPath = request.startsWith("/") ? request.replace(/^\/+/, "") : join(dirname(ownerFilePath), request);
|
|
@@ -2249,6 +2283,21 @@ function resolveSelectorQueryScopeSnapshot(scope, snapshots) {
|
|
|
2249
2283
|
return null;
|
|
2250
2284
|
}
|
|
2251
2285
|
//#endregion
|
|
2286
|
+
//#region src/view/nodeDataset.ts
|
|
2287
|
+
const DATASET_NAME_RE = /-([a-z])/g;
|
|
2288
|
+
function isDatasetAttribute(attributeName) {
|
|
2289
|
+
return attributeName.startsWith("data-") && !attributeName.startsWith("data-sim-");
|
|
2290
|
+
}
|
|
2291
|
+
function toDatasetKey(attributeName) {
|
|
2292
|
+
return attributeName.slice(5).replace(DATASET_NAME_RE, (_match, char) => char.toUpperCase());
|
|
2293
|
+
}
|
|
2294
|
+
function collectNodeDataset(node) {
|
|
2295
|
+
if (node.dataset) return { ...node.dataset };
|
|
2296
|
+
const dataset = {};
|
|
2297
|
+
for (const [key, value] of Object.entries(node.attribs ?? {})) if (isDatasetAttribute(key)) dataset[toDatasetKey(key)] = value;
|
|
2298
|
+
return dataset;
|
|
2299
|
+
}
|
|
2300
|
+
//#endregion
|
|
2252
2301
|
//#region src/view/templateImports.ts
|
|
2253
2302
|
function createImportedTemplateState(root, filePath, loadImport, loadWxs) {
|
|
2254
2303
|
const documents = /* @__PURE__ */ new Map();
|
|
@@ -2278,7 +2327,8 @@ function createImportedTemplateState(root, filePath, loadImport, loadWxs) {
|
|
|
2278
2327
|
return;
|
|
2279
2328
|
}
|
|
2280
2329
|
if (child.name === "import" && child.attribs?.src) {
|
|
2281
|
-
const
|
|
2330
|
+
const source = child.attribs.src;
|
|
2331
|
+
const imported = loadImport(owner, source.endsWith(".wxml") ? source : `${source}.wxml`);
|
|
2282
2332
|
const importedDocument = collect(imported.root, imported.filePath);
|
|
2283
2333
|
for (const [name, definition] of importedDocument.exports) state.definitions.set(name, definition);
|
|
2284
2334
|
}
|
|
@@ -2334,7 +2384,6 @@ function parseWxsTemplateDocument(templateSource) {
|
|
|
2334
2384
|
//#endregion
|
|
2335
2385
|
//#region src/browser/render/shared.ts
|
|
2336
2386
|
const TEMPLATE_INTERPOLATION_RE$2 = /\{\{([^{}]+)\}\}/g;
|
|
2337
|
-
const DATASET_NAME_RE$4 = /-([a-z])/g;
|
|
2338
2387
|
const LEADING_SLASH_RE$5 = /^\/+/;
|
|
2339
2388
|
const EVENT_BINDING_ATTRS$1 = [
|
|
2340
2389
|
"bindtap",
|
|
@@ -2353,19 +2402,16 @@ const STRUCTURAL_ATTRS$1 = [
|
|
|
2353
2402
|
];
|
|
2354
2403
|
const CLASS_SPLIT_RE$1 = /\s+/;
|
|
2355
2404
|
const JS_FILE_RE$1 = /\.js$/;
|
|
2356
|
-
function isMustacheOnly$
|
|
2405
|
+
function isMustacheOnly$2(value) {
|
|
2357
2406
|
const trimmed = value.trim();
|
|
2358
2407
|
return trimmed.startsWith("{{") && trimmed.endsWith("}}") && !trimmed.includes("{{", 2);
|
|
2359
2408
|
}
|
|
2360
|
-
function
|
|
2361
|
-
|
|
2362
|
-
}
|
|
2363
|
-
function collectDataset$4(node, source) {
|
|
2409
|
+
function collectDataset$1(node, source) {
|
|
2410
|
+
if (node.dataset) return collectNodeDataset(node);
|
|
2364
2411
|
const dataset = {};
|
|
2365
2412
|
for (const [key, value] of Object.entries(node.attribs ?? {})) {
|
|
2366
|
-
if (!
|
|
2367
|
-
|
|
2368
|
-
dataset[toDatasetKey$4(key)] = String(resolvedValue ?? "");
|
|
2413
|
+
if (!isDatasetAttribute(key)) continue;
|
|
2414
|
+
dataset[toDatasetKey(key)] = source && isMustacheOnly$2(value) ? resolveTemplateExpression(source, value) : value;
|
|
2369
2415
|
}
|
|
2370
2416
|
return dataset;
|
|
2371
2417
|
}
|
|
@@ -2379,13 +2425,14 @@ function cloneNode$1(node) {
|
|
|
2379
2425
|
return {
|
|
2380
2426
|
...node,
|
|
2381
2427
|
attribs: node.attribs ? { ...node.attribs } : void 0,
|
|
2428
|
+
dataset: node.dataset ? { ...node.dataset } : void 0,
|
|
2382
2429
|
children: node.children?.map((child) => cloneNode$1(child))
|
|
2383
2430
|
};
|
|
2384
2431
|
}
|
|
2385
2432
|
function resolveValueByPath$2(source, expression) {
|
|
2386
2433
|
return resolveTemplateExpression(source, expression) ?? "";
|
|
2387
2434
|
}
|
|
2388
|
-
function resolveRawValueByPath$
|
|
2435
|
+
function resolveRawValueByPath$2(source, expression) {
|
|
2389
2436
|
return resolveTemplateExpression(source, expression);
|
|
2390
2437
|
}
|
|
2391
2438
|
function interpolateTemplate$2(input, data) {
|
|
@@ -2428,16 +2475,16 @@ function isTagNode$1(node) {
|
|
|
2428
2475
|
return node.type === "tag" && typeof node.name === "string";
|
|
2429
2476
|
}
|
|
2430
2477
|
function resolveAttributeValue$1(value, scope) {
|
|
2431
|
-
if (isMustacheOnly$
|
|
2478
|
+
if (isMustacheOnly$2(value)) {
|
|
2432
2479
|
const expression = value.trim().slice(2, -2);
|
|
2433
|
-
return
|
|
2480
|
+
return resolveRawValueByPath$2(wxsScopeData(scope), expression);
|
|
2434
2481
|
}
|
|
2435
2482
|
return interpolateTemplate$2(value, wxsScopeData(scope));
|
|
2436
2483
|
}
|
|
2437
2484
|
function resolveComponentAttributeValue$1(value, scope) {
|
|
2438
|
-
if (isMustacheOnly$
|
|
2485
|
+
if (isMustacheOnly$2(value)) {
|
|
2439
2486
|
const expression = value.trim().slice(2, -2);
|
|
2440
|
-
return resolveRawValueByPath$
|
|
2487
|
+
return resolveRawValueByPath$2(wxsScopeData(scope), expression) ?? null;
|
|
2441
2488
|
}
|
|
2442
2489
|
return interpolateTemplate$2(value, wxsScopeData(scope));
|
|
2443
2490
|
}
|
|
@@ -2449,18 +2496,25 @@ function applyNodeBindings$1(node, scope) {
|
|
|
2449
2496
|
node.attribs ??= {};
|
|
2450
2497
|
node.attribs["data-sim-scope"] = scope.getScopeId();
|
|
2451
2498
|
for (const key of STRUCTURAL_ATTRS$1) delete node.attribs[key];
|
|
2499
|
+
let dataset;
|
|
2452
2500
|
for (const [key, value] of Object.entries({ ...node.attribs })) {
|
|
2453
2501
|
if (EVENT_BINDING_ATTRS$1.includes(key)) {
|
|
2454
2502
|
node.attribs["data-sim-tap"] = value;
|
|
2455
2503
|
continue;
|
|
2456
2504
|
}
|
|
2457
|
-
|
|
2505
|
+
const resolvedValue = typeof value === "string" ? resolveAttributeValue$1(value, scope) : value;
|
|
2506
|
+
node.attribs[key] = String(resolvedValue ?? "");
|
|
2507
|
+
if (isDatasetAttribute(key)) {
|
|
2508
|
+
dataset ??= {};
|
|
2509
|
+
dataset[toDatasetKey(key)] = resolvedValue;
|
|
2510
|
+
}
|
|
2458
2511
|
}
|
|
2512
|
+
node.dataset = dataset;
|
|
2459
2513
|
}
|
|
2460
2514
|
function evaluateConditionalBranch$1(node, scope) {
|
|
2461
2515
|
const condition = node.attribs?.["wx:if"] ?? node.attribs?.["wx:elif"];
|
|
2462
2516
|
if (condition == null) return true;
|
|
2463
|
-
return Boolean(resolveRawValueByPath$
|
|
2517
|
+
return Boolean(resolveRawValueByPath$2(wxsScopeData(scope), condition));
|
|
2464
2518
|
}
|
|
2465
2519
|
function createLoopScope$1(scope, itemName, indexName, item, index) {
|
|
2466
2520
|
return {
|
|
@@ -2534,7 +2588,7 @@ function collectComponentEventBindings$1(hostNode) {
|
|
|
2534
2588
|
return collectMiniProgramEventBindings(hostNode.attribs);
|
|
2535
2589
|
}
|
|
2536
2590
|
function buildComponentTrigger$1(componentScopeId, context, hostNode) {
|
|
2537
|
-
const hostDataset = collectDataset$
|
|
2591
|
+
const hostDataset = collectDataset$1(hostNode);
|
|
2538
2592
|
const hostId = hostNode.attribs?.id ?? "";
|
|
2539
2593
|
return (instance, eventName, detail, triggerOptions) => {
|
|
2540
2594
|
const originScope = context.componentScopes.get(componentScopeId);
|
|
@@ -2596,7 +2650,7 @@ function createComponentScope$1(clonedNode, scope, componentScopeId, componentIn
|
|
|
2596
2650
|
alias: clonedNode.name,
|
|
2597
2651
|
classList: String(clonedNode.attribs?.class ?? "").split(CLASS_SPLIT_RE$1).map((item) => item.trim()).filter(Boolean),
|
|
2598
2652
|
data: { ...componentInstance.data },
|
|
2599
|
-
dataset: collectDataset$
|
|
2653
|
+
dataset: collectDataset$1(clonedNode, wxsScopeData(scope)),
|
|
2600
2654
|
eventBindings: collectComponentEventBindings$1(clonedNode),
|
|
2601
2655
|
getMethod: (methodName) => {
|
|
2602
2656
|
const method = componentInstance?.[methodName];
|
|
@@ -2619,7 +2673,7 @@ function resolveComponentProperties$1(clonedNode, scope, definition) {
|
|
|
2619
2673
|
if (key.startsWith("bind") || key.startsWith("generic:")) continue;
|
|
2620
2674
|
const camelizedKey = key.replace(/-([a-z])/g, (_match, char) => char.toUpperCase());
|
|
2621
2675
|
const propertyKey = key in declaredProperties || !(camelizedKey in declaredProperties) ? key : camelizedKey;
|
|
2622
|
-
if (isMustacheOnly$
|
|
2676
|
+
if (isMustacheOnly$2(String(value))) bindingExpressions[propertyKey] = String(value).trim().slice(2, -2).trim();
|
|
2623
2677
|
nextProperties[propertyKey] = resolveComponentAttributeValue$1(String(value), scope);
|
|
2624
2678
|
}
|
|
2625
2679
|
return {
|
|
@@ -2627,7 +2681,7 @@ function resolveComponentProperties$1(clonedNode, scope, definition) {
|
|
|
2627
2681
|
bindingExpressions
|
|
2628
2682
|
};
|
|
2629
2683
|
}
|
|
2630
|
-
function createBrowserComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId) {
|
|
2684
|
+
function createBrowserComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId, beforeCreated) {
|
|
2631
2685
|
const componentProperties = Object.keys(componentEntry.definition.methods ?? {}).some((key) => key.startsWith("__weapp_vite_")) || Object.hasOwn(componentEntry.definition.properties ?? {}, "__wvSlotOwnerId") ? Object.fromEntries(Object.keys(componentEntry.definition.properties ?? {}).filter((key) => Object.hasOwn(nextProperties, key)).map((key) => [key, nextProperties[key]])) : nextProperties;
|
|
2632
2686
|
const componentInstance = createComponentInstance({
|
|
2633
2687
|
definition: componentEntry.definition,
|
|
@@ -2639,10 +2693,11 @@ function createBrowserComponentInstance(componentScopeId, context, clonedNode, c
|
|
|
2639
2693
|
componentInstance.createIntersectionObserver = (options) => context.session.createIntersectionObserver(componentInstance, options);
|
|
2640
2694
|
componentInstance.createMediaQueryObserver = () => context.session.createMediaQueryObserver(componentInstance);
|
|
2641
2695
|
componentInstance.createSelectorQuery = () => context.moduleLoader.wx.createSelectorQuery().in(componentInstance);
|
|
2642
|
-
componentInstance.selectComponent = (selector) => context.session.selectComponentWithin(componentScopeId, selector);
|
|
2643
|
-
componentInstance.selectAllComponents = (selector) => context.session.selectAllComponentsWithin(componentScopeId, selector);
|
|
2696
|
+
componentInstance.selectComponent = (selector) => resolveNativeComponentSelection(context.session.selectComponentWithin(componentScopeId, selector));
|
|
2697
|
+
componentInstance.selectAllComponents = (selector) => context.session.selectAllComponentsWithin(componentScopeId, selector).map(resolveNativeComponentSelection);
|
|
2644
2698
|
componentInstance.selectOwnerComponent = () => ownerScopeId ? context.componentCache.get(ownerScopeId) ?? null : null;
|
|
2645
2699
|
context.componentCache.set(componentScopeId, componentInstance);
|
|
2700
|
+
beforeCreated?.(componentInstance);
|
|
2646
2701
|
runComponentLifecycle(componentInstance, "created");
|
|
2647
2702
|
componentInstance.__propertySnapshots = Object.fromEntries(Object.entries(componentInstance.properties).map(([key, propertyValue]) => [key, cloneValue(propertyValue)]));
|
|
2648
2703
|
syncComponentProperties$1(componentInstance, componentInstance.__definition__ ?? componentEntry.definition, componentProperties, {}, []);
|
|
@@ -2664,7 +2719,7 @@ function expandNodeByFor$1(node, scope) {
|
|
|
2664
2719
|
scope,
|
|
2665
2720
|
instanceSuffix: ""
|
|
2666
2721
|
}];
|
|
2667
|
-
const items = resolveLoopEntries(resolveRawValueByPath$
|
|
2722
|
+
const items = resolveLoopEntries(resolveRawValueByPath$2(wxsScopeData(scope), forExpression));
|
|
2668
2723
|
const itemName = node.attribs?.["wx:for-item"]?.trim() || "item";
|
|
2669
2724
|
const indexName = node.attribs?.["wx:for-index"]?.trim() || "index";
|
|
2670
2725
|
return items.map(([index, item]) => ({
|
|
@@ -2776,12 +2831,16 @@ function renderNodeTree$1(node, scope, context, ownerJsonPath, ownerFilePath, in
|
|
|
2776
2831
|
const componentScopeId = `${instancePath}/${clonedNode.name}`;
|
|
2777
2832
|
const ownerScopeId = scope.getScopeId().includes("/") ? scope.getScopeId() : void 0;
|
|
2778
2833
|
const { nextProperties, bindingExpressions } = resolveComponentProperties$1(clonedNode, scope, componentEntry.definition);
|
|
2834
|
+
const genericComponents = resolveComponentGenerics$1(context, clonedNode, ownerJsonPath, ownerFilePath, componentEntry.filePath);
|
|
2835
|
+
const slots = collectComponentSlots$1(clonedNode, scope, ownerJsonPath, ownerFilePath, componentScopeId, templateRenderState);
|
|
2779
2836
|
let componentInstance = context.componentCache.get(componentScopeId);
|
|
2780
|
-
if (!componentInstance) componentInstance = createBrowserComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId)
|
|
2837
|
+
if (!componentInstance) componentInstance = createBrowserComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId, (instance) => {
|
|
2838
|
+
const initialScope = createComponentScope$1(clonedNode, scope, componentScopeId, instance, genericComponents, slots);
|
|
2839
|
+
context.componentScopes.set(componentScopeId, initialScope);
|
|
2840
|
+
renderBrowserComponentTemplate(context, componentEntry, renderNodeTree$1, initialScope, componentScopeId, /* @__PURE__ */ new Set());
|
|
2841
|
+
});
|
|
2781
2842
|
else syncComponentProperties$1(componentInstance, componentInstance.__definition__ ?? componentEntry.definition, nextProperties, bindingExpressions, context.changedPageKeys);
|
|
2782
2843
|
seenComponentScopes.add(componentScopeId);
|
|
2783
|
-
const genericComponents = resolveComponentGenerics$1(context, clonedNode, ownerJsonPath, ownerFilePath, componentEntry.filePath);
|
|
2784
|
-
const slots = collectComponentSlots$1(clonedNode, scope, ownerJsonPath, ownerFilePath, componentScopeId, templateRenderState);
|
|
2785
2844
|
const componentScope = createComponentScope$1(clonedNode, scope, componentScopeId, componentInstance, genericComponents, slots);
|
|
2786
2845
|
context.componentScopes.set(componentScopeId, componentScope);
|
|
2787
2846
|
const renderedComponentRoot = renderBrowserComponentTemplate(context, componentEntry, renderNodeTree$1, componentScope, componentScopeId, seenComponentScopes);
|
|
@@ -2791,6 +2850,10 @@ function renderNodeTree$1(node, scope, context, ownerJsonPath, ownerFilePath, in
|
|
|
2791
2850
|
...clonedNode.attribs,
|
|
2792
2851
|
...renderedComponentRoot.attribs
|
|
2793
2852
|
};
|
|
2853
|
+
if (clonedNode.dataset || renderedComponentRoot.dataset) renderedComponentRoot.dataset = {
|
|
2854
|
+
...clonedNode.dataset,
|
|
2855
|
+
...renderedComponentRoot.dataset
|
|
2856
|
+
};
|
|
2794
2857
|
renderedComponentRoot.attribs["data-sim-component"] = clonedNode.name;
|
|
2795
2858
|
renderedComponentRoot.attribs["data-sim-scope"] = componentScopeId;
|
|
2796
2859
|
}
|
|
@@ -2835,7 +2898,8 @@ function renderBrowserPageTree(context, page) {
|
|
|
2835
2898
|
if (instance !== context.componentCache.get(customTabBarScopeId(route))) runComponentPageLifetime(instance, "show");
|
|
2836
2899
|
});
|
|
2837
2900
|
const removed = [...context.componentCache].filter(([scopeId]) => scopeId.startsWith(`${pageScopeId}/`) && !seenComponentScopes.has(scopeId));
|
|
2838
|
-
for (const [, instance] of removed) runComponentLifecycle(instance, "detached");
|
|
2901
|
+
for (const [scopeId, instance] of removed) if (isComponentAttached(instance)) runComponentLifecycle(instance, "detached");
|
|
2902
|
+
else scheduleDiscardedComponentReady(context.componentCache, scopeId, instance);
|
|
2839
2903
|
const instances = [...seenComponentScopes].map((scopeId) => context.componentCache.get(scopeId));
|
|
2840
2904
|
const relationsChanged = !pageAttaching && !hasPendingComponentAttachments(instances) && syncComponentRelations(context.componentCache, seenComponentScopes, pageScopeId);
|
|
2841
2905
|
for (const [scopeId] of removed) {
|
|
@@ -2843,6 +2907,7 @@ function renderBrowserPageTree(context, page) {
|
|
|
2843
2907
|
context.componentScopes.delete(scopeId);
|
|
2844
2908
|
}
|
|
2845
2909
|
if (pageAttached || attached || relationsChanged) return renderBrowserPageTree(context, page);
|
|
2910
|
+
if (!isPageBeforeReady(page)) flushDiscardedComponentReady(context.componentCache, pageScopeId, (instance) => runComponentLifecycle(instance, "ready"));
|
|
2846
2911
|
if (!isPageBeforeReady(page) && flushComponentReady(instances, (instance) => runComponentLifecycle(instance, "ready"))) return renderBrowserPageTree(context, page);
|
|
2847
2912
|
const treeRoot = roots.length > 1 ? {
|
|
2848
2913
|
type: "root",
|
|
@@ -3251,6 +3316,110 @@ function deriveMenuButtonBoundingClientRect(systemInfo) {
|
|
|
3251
3316
|
};
|
|
3252
3317
|
}
|
|
3253
3318
|
//#endregion
|
|
3319
|
+
//#region src/runtime/request/task.ts
|
|
3320
|
+
/** mock 与显式网络桥接共用终止状态;终止后不再分发 headers/chunk。 */
|
|
3321
|
+
function createRequestTask(option, onAbort = () => {}) {
|
|
3322
|
+
const headers = /* @__PURE__ */ new Set();
|
|
3323
|
+
const chunks = /* @__PURE__ */ new Set();
|
|
3324
|
+
let settled = false;
|
|
3325
|
+
function finish(result, success) {
|
|
3326
|
+
if (settled) return;
|
|
3327
|
+
settled = true;
|
|
3328
|
+
headers.clear();
|
|
3329
|
+
chunks.clear();
|
|
3330
|
+
try {
|
|
3331
|
+
if (success) option.success?.(result);
|
|
3332
|
+
else option.fail?.(result);
|
|
3333
|
+
} finally {
|
|
3334
|
+
option.complete?.(result);
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
return {
|
|
3338
|
+
task: {
|
|
3339
|
+
abort() {
|
|
3340
|
+
if (settled) return;
|
|
3341
|
+
const error = Object.assign(/* @__PURE__ */ new Error("request:fail abort"), { errMsg: "request:fail abort" });
|
|
3342
|
+
try {
|
|
3343
|
+
finish(error, false);
|
|
3344
|
+
} finally {
|
|
3345
|
+
onAbort();
|
|
3346
|
+
}
|
|
3347
|
+
},
|
|
3348
|
+
onHeadersReceived(callback) {
|
|
3349
|
+
headers.add(callback);
|
|
3350
|
+
},
|
|
3351
|
+
offHeadersReceived(callback) {
|
|
3352
|
+
if (callback) headers.delete(callback);
|
|
3353
|
+
else headers.clear();
|
|
3354
|
+
},
|
|
3355
|
+
onChunkReceived(callback) {
|
|
3356
|
+
chunks.add(callback);
|
|
3357
|
+
},
|
|
3358
|
+
offChunkReceived(callback) {
|
|
3359
|
+
if (callback) chunks.delete(callback);
|
|
3360
|
+
else chunks.clear();
|
|
3361
|
+
}
|
|
3362
|
+
},
|
|
3363
|
+
get settled() {
|
|
3364
|
+
return settled;
|
|
3365
|
+
},
|
|
3366
|
+
headers(result) {
|
|
3367
|
+
if (settled) return;
|
|
3368
|
+
for (const callback of Array.from(headers)) if (!settled && headers.has(callback)) callback(result);
|
|
3369
|
+
},
|
|
3370
|
+
chunk(data) {
|
|
3371
|
+
if (settled || !option.enableChunked) return;
|
|
3372
|
+
for (const callback of Array.from(chunks)) if (!settled && chunks.has(callback)) callback({ data: data.slice(0) });
|
|
3373
|
+
},
|
|
3374
|
+
succeed(result) {
|
|
3375
|
+
finish(result, true);
|
|
3376
|
+
},
|
|
3377
|
+
fail(error) {
|
|
3378
|
+
finish(Object.assign(error, { errMsg: "errMsg" in error ? error.errMsg : error.message }), false);
|
|
3379
|
+
}
|
|
3380
|
+
};
|
|
3381
|
+
}
|
|
3382
|
+
//#endregion
|
|
3383
|
+
//#region src/runtime/request/mock.ts
|
|
3384
|
+
/** 仅模拟已声明的分块;不进行网络访问,也不把完整 response 拆成假分块。 */
|
|
3385
|
+
function createChunkedMockRequest(option, mock, response, scheduler, onSuccess) {
|
|
3386
|
+
let timer;
|
|
3387
|
+
const request = createRequestTask(option, () => scheduler.clearTimeout(timer));
|
|
3388
|
+
const chunks = (mock.chunks ?? []).map((chunk) => ({
|
|
3389
|
+
...chunk,
|
|
3390
|
+
data: chunk.data.slice(0)
|
|
3391
|
+
}));
|
|
3392
|
+
let index = 0;
|
|
3393
|
+
function next() {
|
|
3394
|
+
if (request.settled) return;
|
|
3395
|
+
const chunk = chunks[index++];
|
|
3396
|
+
if (chunk) timer = scheduler.setTimeout(() => {
|
|
3397
|
+
request.chunk(chunk.data);
|
|
3398
|
+
next();
|
|
3399
|
+
}, Math.max(0, chunk.delay ?? 0));
|
|
3400
|
+
else timer = scheduler.setTimeout(() => {
|
|
3401
|
+
if (request.settled) return;
|
|
3402
|
+
if (mock.error) request.fail(new Error(mock.error));
|
|
3403
|
+
else {
|
|
3404
|
+
onSuccess();
|
|
3405
|
+
request.succeed({
|
|
3406
|
+
...response,
|
|
3407
|
+
data: ""
|
|
3408
|
+
});
|
|
3409
|
+
}
|
|
3410
|
+
}, 0);
|
|
3411
|
+
}
|
|
3412
|
+
timer = scheduler.setTimeout(() => {
|
|
3413
|
+
request.headers({
|
|
3414
|
+
cookies: response.cookies,
|
|
3415
|
+
header: response.header,
|
|
3416
|
+
statusCode: response.statusCode
|
|
3417
|
+
});
|
|
3418
|
+
next();
|
|
3419
|
+
}, Math.max(0, mock.delay ?? 0));
|
|
3420
|
+
return request.task;
|
|
3421
|
+
}
|
|
3422
|
+
//#endregion
|
|
3254
3423
|
//#region src/runtime/wxState.ts
|
|
3255
3424
|
const STORAGE_LIMIT_SIZE = 10240;
|
|
3256
3425
|
const DEFAULT_MODAL_CANCEL_COLOR = "#000000";
|
|
@@ -4572,6 +4741,7 @@ function createHeadlessWxState(scheduler = nativeScheduler, options = {}) {
|
|
|
4572
4741
|
request(option) {
|
|
4573
4742
|
const matchedMock = requestMocks.find((mock) => matchesRequestMock(mock, option));
|
|
4574
4743
|
if (!matchedMock) {
|
|
4744
|
+
const request = createRequestTask(option);
|
|
4575
4745
|
const logEntry = {
|
|
4576
4746
|
data: cloneValue$1(option.data),
|
|
4577
4747
|
header: { ...option.header ?? {} },
|
|
@@ -4582,9 +4752,8 @@ function createHeadlessWxState(scheduler = nativeScheduler, options = {}) {
|
|
|
4582
4752
|
requestLogs.push(logEntry);
|
|
4583
4753
|
const error = /* @__PURE__ */ new Error(`No request mock matched in headless runtime: ${normalizeMethod(option.method)} ${option.url}`);
|
|
4584
4754
|
if (options.strictMocks) throw error;
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
return createNoopTask();
|
|
4755
|
+
request.fail(error);
|
|
4756
|
+
return request.task;
|
|
4588
4757
|
}
|
|
4589
4758
|
const response = resolveRequestResponse(matchedMock, option);
|
|
4590
4759
|
const requestLogEntry = {
|
|
@@ -4596,20 +4765,31 @@ function createHeadlessWxState(scheduler = nativeScheduler, options = {}) {
|
|
|
4596
4765
|
url: option.url
|
|
4597
4766
|
};
|
|
4598
4767
|
const delay = Number.isFinite(matchedMock.delay) ? Math.max(0, Math.trunc(matchedMock.delay ?? 0)) : 0;
|
|
4768
|
+
if (option.enableChunked) return createChunkedMockRequest(option, matchedMock, response, scheduler, () => {
|
|
4769
|
+
requestLogs.push({
|
|
4770
|
+
...requestLogEntry,
|
|
4771
|
+
response: {
|
|
4772
|
+
...response,
|
|
4773
|
+
data: ""
|
|
4774
|
+
}
|
|
4775
|
+
});
|
|
4776
|
+
});
|
|
4777
|
+
const request = createRequestTask(option);
|
|
4599
4778
|
if (delay <= 0) {
|
|
4600
4779
|
requestLogs.push(requestLogEntry);
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
return createNoopTask();
|
|
4780
|
+
request.succeed(response);
|
|
4781
|
+
return request.task;
|
|
4604
4782
|
}
|
|
4605
|
-
|
|
4783
|
+
const delayed = runDelayedTask(delay, () => {
|
|
4606
4784
|
requestLogs.push(requestLogEntry);
|
|
4607
|
-
|
|
4608
|
-
option.complete?.(response);
|
|
4785
|
+
request.succeed(response);
|
|
4609
4786
|
}, (error) => {
|
|
4610
|
-
|
|
4611
|
-
option.complete?.();
|
|
4787
|
+
request.fail(error);
|
|
4612
4788
|
}, "request:fail abort");
|
|
4789
|
+
return {
|
|
4790
|
+
...request.task,
|
|
4791
|
+
abort: delayed.abort
|
|
4792
|
+
};
|
|
4613
4793
|
},
|
|
4614
4794
|
removeSavedFile(option) {
|
|
4615
4795
|
return removeSavedFile(option.filePath);
|
|
@@ -4891,23 +5071,11 @@ function queryXPathElements(root, expression) {
|
|
|
4891
5071
|
}
|
|
4892
5072
|
//#endregion
|
|
4893
5073
|
//#region src/view/nodeHandle.ts
|
|
4894
|
-
const DATASET_NAME_RE$3 = /-([a-z])/g;
|
|
4895
5074
|
function escapeText$2(text) {
|
|
4896
5075
|
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
4897
5076
|
}
|
|
4898
|
-
function toDatasetKey$3(attributeName) {
|
|
4899
|
-
return attributeName.slice(5).replace(DATASET_NAME_RE$3, (_match, char) => char.toUpperCase());
|
|
4900
|
-
}
|
|
4901
|
-
function collectDataset$3(node) {
|
|
4902
|
-
const dataset = {};
|
|
4903
|
-
for (const [key, value] of Object.entries(node.attribs ?? {})) {
|
|
4904
|
-
if (!key.startsWith("data-") || key.startsWith("data-sim-")) continue;
|
|
4905
|
-
dataset[toDatasetKey$3(key)] = value;
|
|
4906
|
-
}
|
|
4907
|
-
return dataset;
|
|
4908
|
-
}
|
|
4909
5077
|
function createEventPayload$1(node, eventName, event) {
|
|
4910
|
-
const dataset =
|
|
5078
|
+
const dataset = collectNodeDataset(node);
|
|
4911
5079
|
const nodeId = node.attribs?.id ?? "";
|
|
4912
5080
|
return {
|
|
4913
5081
|
bubbles: false,
|
|
@@ -4995,7 +5163,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
|
|
|
4995
5163
|
}
|
|
4996
5164
|
async dataset() {
|
|
4997
5165
|
this.assertActive();
|
|
4998
|
-
return
|
|
5166
|
+
return collectNodeDataset(this.node);
|
|
4999
5167
|
}
|
|
5000
5168
|
async scope() {
|
|
5001
5169
|
this.assertActive();
|
|
@@ -5070,13 +5238,19 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
|
|
|
5070
5238
|
//#region src/view/render.ts
|
|
5071
5239
|
const LEADING_SLASH_RE$4 = /^\/+/;
|
|
5072
5240
|
const TEMPLATE_INTERPOLATION_RE$1 = /\{\{([^{}]+)\}\}/g;
|
|
5073
|
-
function
|
|
5241
|
+
function resolveRawValueByPath$1(source, expression) {
|
|
5074
5242
|
const normalized = expression.trim();
|
|
5075
|
-
if (!normalized) return
|
|
5243
|
+
if (!normalized) return;
|
|
5076
5244
|
const segments = normalized.split(".").filter(Boolean);
|
|
5077
5245
|
let current = source;
|
|
5078
|
-
for (const segment of segments)
|
|
5079
|
-
|
|
5246
|
+
for (const segment of segments) {
|
|
5247
|
+
if (current == null || typeof current !== "object" && typeof current !== "function") return;
|
|
5248
|
+
current = Reflect.get(current, segment);
|
|
5249
|
+
}
|
|
5250
|
+
return current;
|
|
5251
|
+
}
|
|
5252
|
+
function resolveValueByPath$1(source, expression) {
|
|
5253
|
+
return resolveRawValueByPath$1(source, expression) ?? "";
|
|
5080
5254
|
}
|
|
5081
5255
|
function interpolateTemplate$1(input, data) {
|
|
5082
5256
|
return input.replace(TEMPLATE_INTERPOLATION_RE$1, (_match, expression) => {
|
|
@@ -5084,6 +5258,10 @@ function interpolateTemplate$1(input, data) {
|
|
|
5084
5258
|
return typeof value === "string" ? value : String(value);
|
|
5085
5259
|
});
|
|
5086
5260
|
}
|
|
5261
|
+
function isMustacheOnly$1(value) {
|
|
5262
|
+
const trimmed = value.trim();
|
|
5263
|
+
return trimmed.startsWith("{{") && trimmed.endsWith("}}") && !trimmed.includes("{{", 2);
|
|
5264
|
+
}
|
|
5087
5265
|
function visitDom(node, visitor) {
|
|
5088
5266
|
visitor(node);
|
|
5089
5267
|
for (const child of node.children ?? []) visitDom(child, visitor);
|
|
@@ -5091,7 +5269,18 @@ function visitDom(node, visitor) {
|
|
|
5091
5269
|
function interpolateDomTree(root, data) {
|
|
5092
5270
|
visitDom(root, (node) => {
|
|
5093
5271
|
if (typeof node.data === "string") node.data = interpolateTemplateText(node.data, data);
|
|
5094
|
-
if (node.attribs)
|
|
5272
|
+
if (node.attribs) {
|
|
5273
|
+
let dataset;
|
|
5274
|
+
for (const [key, value] of Object.entries(node.attribs)) {
|
|
5275
|
+
const resolvedValue = isMustacheOnly$1(value) ? resolveRawValueByPath$1(data, value.trim().slice(2, -2)) : interpolateTemplate$1(value, data);
|
|
5276
|
+
node.attribs[key] = String(resolvedValue ?? "");
|
|
5277
|
+
if (isDatasetAttribute(key)) {
|
|
5278
|
+
dataset ??= {};
|
|
5279
|
+
dataset[toDatasetKey(key)] = resolvedValue;
|
|
5280
|
+
}
|
|
5281
|
+
}
|
|
5282
|
+
node.dataset = dataset;
|
|
5283
|
+
}
|
|
5095
5284
|
});
|
|
5096
5285
|
}
|
|
5097
5286
|
function escapeText$1(text) {
|
|
@@ -5125,21 +5314,9 @@ function renderPageTree(project, page) {
|
|
|
5125
5314
|
}
|
|
5126
5315
|
//#endregion
|
|
5127
5316
|
//#region src/view/selectorQuery.ts
|
|
5128
|
-
const DATASET_NAME_RE$2 = /-([a-z])/g;
|
|
5129
5317
|
const LEADING_MARK_PREFIX_RE = /^mark[:\-]?/;
|
|
5130
5318
|
const MARK_NAME_RE = /[:\-]([a-z])/g;
|
|
5131
5319
|
const NUMERIC_LIKE_VALUE_RE$1 = /-?\d+(?:\.\d+)?/;
|
|
5132
|
-
function toDatasetKey$2(attributeName) {
|
|
5133
|
-
return attributeName.slice(5).replace(DATASET_NAME_RE$2, (_match, char) => char.toUpperCase());
|
|
5134
|
-
}
|
|
5135
|
-
function collectDataset$2(node) {
|
|
5136
|
-
const dataset = {};
|
|
5137
|
-
for (const [key, value] of Object.entries(node.attribs ?? {})) {
|
|
5138
|
-
if (!key.startsWith("data-") || key.startsWith("data-sim-")) continue;
|
|
5139
|
-
dataset[toDatasetKey$2(key)] = value;
|
|
5140
|
-
}
|
|
5141
|
-
return dataset;
|
|
5142
|
-
}
|
|
5143
5320
|
function toMarkKey(attributeName) {
|
|
5144
5321
|
return attributeName.replace(LEADING_MARK_PREFIX_RE, "").replace(MARK_NAME_RE, (_match, char) => char.toUpperCase());
|
|
5145
5322
|
}
|
|
@@ -5216,7 +5393,7 @@ function resolvePropertyValue(node, propertyName) {
|
|
|
5216
5393
|
if (!normalizedPropertyName) return;
|
|
5217
5394
|
if (normalizedPropertyName === "id") return node.attribs?.id ?? "";
|
|
5218
5395
|
if (normalizedPropertyName === "class") return node.attribs?.class ?? "";
|
|
5219
|
-
if (normalizedPropertyName === "dataset") return
|
|
5396
|
+
if (normalizedPropertyName === "dataset") return collectNodeDataset(node);
|
|
5220
5397
|
return node.attribs?.[normalizedPropertyName];
|
|
5221
5398
|
}
|
|
5222
5399
|
function pickProperties(node, propertyNames) {
|
|
@@ -5233,7 +5410,7 @@ function pickComputedStyle(node, propertyNames) {
|
|
|
5233
5410
|
function resolveFieldsResult(node, fields, options) {
|
|
5234
5411
|
const result = {};
|
|
5235
5412
|
if (fields.id) result.id = node.attribs?.id ?? "";
|
|
5236
|
-
if (fields.dataset) result.dataset =
|
|
5413
|
+
if (fields.dataset) result.dataset = collectNodeDataset(node);
|
|
5237
5414
|
if (fields.mark) result.mark = collectMark(node);
|
|
5238
5415
|
if (fields.rect || fields.size) {
|
|
5239
5416
|
const rect = resolveRect$1(node, options.root.name === "page" ? options.windowInfo : void 0);
|
|
@@ -5938,20 +6115,8 @@ function createHeadlessMediaQueryObserver(driver, onDisconnect) {
|
|
|
5938
6115
|
}
|
|
5939
6116
|
//#endregion
|
|
5940
6117
|
//#region src/view/videoContext.ts
|
|
5941
|
-
const DATASET_NAME_RE$1 = /-([a-z])/g;
|
|
5942
|
-
function toDatasetKey$1(attributeName) {
|
|
5943
|
-
return attributeName.slice(5).replace(DATASET_NAME_RE$1, (_match, char) => char.toUpperCase());
|
|
5944
|
-
}
|
|
5945
|
-
function collectDataset$1(node) {
|
|
5946
|
-
const dataset = {};
|
|
5947
|
-
for (const [key, value] of Object.entries(node.attribs ?? {})) {
|
|
5948
|
-
if (!key.startsWith("data-") || key.startsWith("data-sim-")) continue;
|
|
5949
|
-
dataset[toDatasetKey$1(key)] = value;
|
|
5950
|
-
}
|
|
5951
|
-
return dataset;
|
|
5952
|
-
}
|
|
5953
6118
|
function createEventPayload(node, eventName, detail) {
|
|
5954
|
-
const dataset =
|
|
6119
|
+
const dataset = collectNodeDataset(node);
|
|
5955
6120
|
const nodeId = node.attribs?.id ?? "";
|
|
5956
6121
|
return {
|
|
5957
6122
|
bubbles: false,
|
|
@@ -6063,7 +6228,7 @@ function matchesComponentSelector$1(scope, selector) {
|
|
|
6063
6228
|
if (dataAttrMatch) {
|
|
6064
6229
|
const [, key, value] = dataAttrMatch;
|
|
6065
6230
|
const datasetKey = key.replace(DATASET_KEY_RE$1, (_match, char) => char.toUpperCase());
|
|
6066
|
-
return scope.dataset
|
|
6231
|
+
return scope.dataset != null && Object.hasOwn(scope.dataset, datasetKey) && String(scope.dataset[datasetKey] ?? "") === value;
|
|
6067
6232
|
}
|
|
6068
6233
|
return scope.alias === part;
|
|
6069
6234
|
});
|
|
@@ -6934,8 +7099,8 @@ var BrowserHeadlessSession = class {
|
|
|
6934
7099
|
});
|
|
6935
7100
|
pageInstance.createIntersectionObserver = (options) => this.createIntersectionObserver(pageInstance, options);
|
|
6936
7101
|
pageInstance.createMediaQueryObserver = () => this.createMediaQueryObserver(pageInstance);
|
|
6937
|
-
pageInstance.selectComponent = (selector) => this.selectComponent(selector);
|
|
6938
|
-
pageInstance.selectAllComponents = (selector) => this.selectAllComponents(selector);
|
|
7102
|
+
pageInstance.selectComponent = (selector) => resolveNativeComponentSelection(this.selectComponent(selector));
|
|
7103
|
+
pageInstance.selectAllComponents = (selector) => this.selectAllComponents(selector).map(resolveNativeComponentSelection);
|
|
6939
7104
|
pageInstance.getTabBar = () => {
|
|
6940
7105
|
if (this.currentPageInstance === pageInstance) this.renderCurrentPage();
|
|
6941
7106
|
return this.componentCache.get(customTabBarScopeId(pageInstance.route)) ?? null;
|
|
@@ -7277,7 +7442,6 @@ function getRuntimeWxsLoader(owner, artifactSource) {
|
|
|
7277
7442
|
//#endregion
|
|
7278
7443
|
//#region src/runtime/render/shared.ts
|
|
7279
7444
|
const TEMPLATE_INTERPOLATION_RE = /\{\{([^{}]+)\}\}/g;
|
|
7280
|
-
const DATASET_NAME_RE = /-([a-z])/g;
|
|
7281
7445
|
const LEADING_SLASH_RE$2 = /^\/+/;
|
|
7282
7446
|
const EVENT_BINDING_ATTRS = [
|
|
7283
7447
|
"bindtap",
|
|
@@ -7300,15 +7464,12 @@ function isMustacheOnly(value) {
|
|
|
7300
7464
|
const trimmed = value.trim();
|
|
7301
7465
|
return trimmed.startsWith("{{") && trimmed.endsWith("}}") && !trimmed.includes("{{", 2);
|
|
7302
7466
|
}
|
|
7303
|
-
function toDatasetKey(attributeName) {
|
|
7304
|
-
return attributeName.slice(5).replace(DATASET_NAME_RE, (_match, char) => char.toUpperCase());
|
|
7305
|
-
}
|
|
7306
7467
|
function collectDataset(node, source) {
|
|
7468
|
+
if (node.dataset) return collectNodeDataset(node);
|
|
7307
7469
|
const dataset = {};
|
|
7308
7470
|
for (const [key, value] of Object.entries(node.attribs ?? {})) {
|
|
7309
|
-
if (!
|
|
7310
|
-
|
|
7311
|
-
dataset[toDatasetKey(key)] = String(resolvedValue ?? "");
|
|
7471
|
+
if (!isDatasetAttribute(key)) continue;
|
|
7472
|
+
dataset[toDatasetKey(key)] = source && isMustacheOnly(value) ? resolveTemplateExpression(source, value) : value;
|
|
7312
7473
|
}
|
|
7313
7474
|
return dataset;
|
|
7314
7475
|
}
|
|
@@ -7322,6 +7483,7 @@ function cloneNode(node) {
|
|
|
7322
7483
|
return {
|
|
7323
7484
|
...node,
|
|
7324
7485
|
attribs: node.attribs ? { ...node.attribs } : void 0,
|
|
7486
|
+
dataset: node.dataset ? { ...node.dataset } : void 0,
|
|
7325
7487
|
children: node.children?.map((child) => cloneNode(child))
|
|
7326
7488
|
};
|
|
7327
7489
|
}
|
|
@@ -7373,7 +7535,7 @@ function isTagNode(node) {
|
|
|
7373
7535
|
function resolveAttributeValue(value, scope) {
|
|
7374
7536
|
if (isMustacheOnly(value)) {
|
|
7375
7537
|
const expression = value.trim().slice(2, -2);
|
|
7376
|
-
return
|
|
7538
|
+
return resolveRawValueByPath(wxsScopeData(scope), expression);
|
|
7377
7539
|
}
|
|
7378
7540
|
return interpolateTemplate(value, wxsScopeData(scope));
|
|
7379
7541
|
}
|
|
@@ -7392,13 +7554,20 @@ function applyNodeBindings(node, scope) {
|
|
|
7392
7554
|
node.attribs ??= {};
|
|
7393
7555
|
node.attribs["data-sim-scope"] = scope.getScopeId();
|
|
7394
7556
|
for (const key of STRUCTURAL_ATTRS) delete node.attribs[key];
|
|
7557
|
+
let dataset;
|
|
7395
7558
|
for (const [key, value] of Object.entries({ ...node.attribs })) {
|
|
7396
7559
|
if (EVENT_BINDING_ATTRS.includes(key)) {
|
|
7397
7560
|
node.attribs["data-sim-tap"] = value;
|
|
7398
7561
|
continue;
|
|
7399
7562
|
}
|
|
7400
|
-
|
|
7563
|
+
const resolvedValue = typeof value === "string" ? resolveAttributeValue(value, scope) : value;
|
|
7564
|
+
node.attribs[key] = String(resolvedValue ?? "");
|
|
7565
|
+
if (isDatasetAttribute(key)) {
|
|
7566
|
+
dataset ??= {};
|
|
7567
|
+
dataset[toDatasetKey(key)] = resolvedValue;
|
|
7568
|
+
}
|
|
7401
7569
|
}
|
|
7570
|
+
node.dataset = dataset;
|
|
7402
7571
|
}
|
|
7403
7572
|
function evaluateConditionalBranch(node, scope) {
|
|
7404
7573
|
const condition = node.attribs?.["wx:if"] ?? node.attribs?.["wx:elif"];
|
|
@@ -7572,7 +7741,7 @@ function resolveComponentProperties(clonedNode, scope, definition) {
|
|
|
7572
7741
|
bindingExpressions
|
|
7573
7742
|
};
|
|
7574
7743
|
}
|
|
7575
|
-
function createRuntimeComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId) {
|
|
7744
|
+
function createRuntimeComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId, beforeCreated) {
|
|
7576
7745
|
const componentProperties = Object.keys(componentEntry.definition.methods ?? {}).some((key) => key.startsWith("__weapp_vite_")) || Object.hasOwn(componentEntry.definition.properties ?? {}, "__wvSlotOwnerId") ? Object.fromEntries(Object.keys(componentEntry.definition.properties ?? {}).filter((key) => Object.hasOwn(nextProperties, key)).map((key) => [key, nextProperties[key]])) : nextProperties;
|
|
7577
7746
|
const componentInstance = createComponentInstance({
|
|
7578
7747
|
definition: componentEntry.definition,
|
|
@@ -7584,10 +7753,11 @@ function createRuntimeComponentInstance(componentScopeId, context, clonedNode, c
|
|
|
7584
7753
|
componentInstance.createIntersectionObserver = (options) => context.session.createIntersectionObserver(componentInstance, options);
|
|
7585
7754
|
componentInstance.createMediaQueryObserver = () => context.session.createMediaQueryObserver(componentInstance);
|
|
7586
7755
|
componentInstance.createSelectorQuery = () => context.moduleLoader.wx.createSelectorQuery().in(componentInstance);
|
|
7587
|
-
componentInstance.selectComponent = (selector) => context.session.selectComponentWithin(componentScopeId, selector);
|
|
7588
|
-
componentInstance.selectAllComponents = (selector) => context.session.selectAllComponentsWithin(componentScopeId, selector);
|
|
7756
|
+
componentInstance.selectComponent = (selector) => resolveNativeComponentSelection(context.session.selectComponentWithin(componentScopeId, selector));
|
|
7757
|
+
componentInstance.selectAllComponents = (selector) => context.session.selectAllComponentsWithin(componentScopeId, selector).map(resolveNativeComponentSelection);
|
|
7589
7758
|
componentInstance.selectOwnerComponent = () => ownerScopeId ? context.componentCache.get(ownerScopeId) ?? null : null;
|
|
7590
7759
|
context.componentCache.set(componentScopeId, componentInstance);
|
|
7760
|
+
beforeCreated?.(componentInstance);
|
|
7591
7761
|
runComponentLifecycle(componentInstance, "created");
|
|
7592
7762
|
componentInstance.__propertySnapshots = Object.fromEntries(Object.entries(componentInstance.properties).map(([key, propertyValue]) => [key, cloneValue(propertyValue)]));
|
|
7593
7763
|
syncComponentProperties(componentInstance, componentInstance.__definition__ ?? componentEntry.definition, componentProperties, {}, []);
|
|
@@ -7723,12 +7893,16 @@ function renderNodeTree(node, scope, context, ownerJsonPath, ownerFilePath, inst
|
|
|
7723
7893
|
const componentScopeId = `${instancePath}/${clonedNode.name}`;
|
|
7724
7894
|
const ownerScopeId = scope.getScopeId().includes("/") ? scope.getScopeId() : void 0;
|
|
7725
7895
|
const { nextProperties, bindingExpressions } = resolveComponentProperties(clonedNode, scope, componentEntry.definition);
|
|
7896
|
+
const genericComponents = resolveComponentGenerics(context, clonedNode, ownerJsonPath, ownerFilePath, componentEntry.filePath);
|
|
7897
|
+
const slots = collectComponentSlots(clonedNode, scope, ownerJsonPath, ownerFilePath, componentScopeId, templateRenderState);
|
|
7726
7898
|
let componentInstance = context.componentCache.get(componentScopeId);
|
|
7727
|
-
if (!componentInstance) componentInstance = createRuntimeComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId)
|
|
7899
|
+
if (!componentInstance) componentInstance = createRuntimeComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId, (instance) => {
|
|
7900
|
+
const initialScope = createComponentScope(clonedNode, scope, componentScopeId, instance, genericComponents, slots);
|
|
7901
|
+
context.componentScopes.set(componentScopeId, initialScope);
|
|
7902
|
+
renderRuntimeComponentTemplate(context, componentEntry, renderNodeTree, initialScope, componentScopeId, /* @__PURE__ */ new Set());
|
|
7903
|
+
});
|
|
7728
7904
|
else syncComponentProperties(componentInstance, componentInstance.__definition__ ?? componentEntry.definition, nextProperties, bindingExpressions, context.changedPageKeys);
|
|
7729
7905
|
seenComponentScopes.add(componentScopeId);
|
|
7730
|
-
const genericComponents = resolveComponentGenerics(context, clonedNode, ownerJsonPath, ownerFilePath, componentEntry.filePath);
|
|
7731
|
-
const slots = collectComponentSlots(clonedNode, scope, ownerJsonPath, ownerFilePath, componentScopeId, templateRenderState);
|
|
7732
7906
|
const componentScope = createComponentScope(clonedNode, scope, componentScopeId, componentInstance, genericComponents, slots);
|
|
7733
7907
|
context.componentScopes.set(componentScopeId, componentScope);
|
|
7734
7908
|
const renderedComponentRoot = renderRuntimeComponentTemplate(context, componentEntry, renderNodeTree, componentScope, componentScopeId, seenComponentScopes);
|
|
@@ -7738,6 +7912,10 @@ function renderNodeTree(node, scope, context, ownerJsonPath, ownerFilePath, inst
|
|
|
7738
7912
|
...clonedNode.attribs,
|
|
7739
7913
|
...renderedComponentRoot.attribs
|
|
7740
7914
|
};
|
|
7915
|
+
if (clonedNode.dataset || renderedComponentRoot.dataset) renderedComponentRoot.dataset = {
|
|
7916
|
+
...clonedNode.dataset,
|
|
7917
|
+
...renderedComponentRoot.dataset
|
|
7918
|
+
};
|
|
7741
7919
|
renderedComponentRoot.attribs["data-sim-component"] = clonedNode.name;
|
|
7742
7920
|
renderedComponentRoot.attribs["data-sim-node"] = instancePath;
|
|
7743
7921
|
renderedComponentRoot.attribs["data-sim-scope"] = componentScopeId;
|
|
@@ -7781,7 +7959,8 @@ function renderRuntimePageTree(context, page) {
|
|
|
7781
7959
|
const pageAttaching = isComponentPageAttaching(page);
|
|
7782
7960
|
const attached = !pageAttaching && flushComponentAttachments([...seenComponentScopes].map((scopeId) => context.componentCache.get(scopeId)), (instance) => runComponentLifecycle(instance, "attached"));
|
|
7783
7961
|
const removed = [...context.componentCache].filter(([scopeId]) => scopeId.startsWith(`${pageScopeId}/`) && !seenComponentScopes.has(scopeId));
|
|
7784
|
-
for (const [, instance] of removed) runComponentLifecycle(instance, "detached");
|
|
7962
|
+
for (const [scopeId, instance] of removed) if (isComponentAttached(instance)) runComponentLifecycle(instance, "detached");
|
|
7963
|
+
else scheduleDiscardedComponentReady(context.componentCache, scopeId, instance);
|
|
7785
7964
|
const instances = [...seenComponentScopes].map((scopeId) => context.componentCache.get(scopeId));
|
|
7786
7965
|
const relationsChanged = !pageAttaching && !hasPendingComponentAttachments(instances) && syncComponentRelations(context.componentCache, seenComponentScopes, pageScopeId);
|
|
7787
7966
|
for (const [scopeId] of removed) {
|
|
@@ -7789,6 +7968,7 @@ function renderRuntimePageTree(context, page) {
|
|
|
7789
7968
|
context.componentScopes.delete(scopeId);
|
|
7790
7969
|
}
|
|
7791
7970
|
if (pageAttached || attached || relationsChanged) return renderRuntimePageTree(context, page);
|
|
7971
|
+
if (!isPageBeforeReady(page)) flushDiscardedComponentReady(context.componentCache, pageScopeId, (instance) => runComponentLifecycle(instance, "ready"));
|
|
7792
7972
|
if (!isPageBeforeReady(page) && flushComponentReady(instances, (instance) => {
|
|
7793
7973
|
runComponentLifecycle(instance, "ready");
|
|
7794
7974
|
if (instance !== context.componentCache.get(customTabBarScopeId(route))) instance.__definition__?.pageLifetimes?.show?.call(instance);
|
|
@@ -8071,7 +8251,7 @@ function matchesComponentSelector(scope, selector) {
|
|
|
8071
8251
|
if (dataAttrMatch) {
|
|
8072
8252
|
const [, key, value] = dataAttrMatch;
|
|
8073
8253
|
const datasetKey = key.replace(DATASET_KEY_RE, (_match, char) => char.toUpperCase());
|
|
8074
|
-
return scope.dataset
|
|
8254
|
+
return scope.dataset != null && Object.hasOwn(scope.dataset, datasetKey) && String(scope.dataset[datasetKey] ?? "") === value;
|
|
8075
8255
|
}
|
|
8076
8256
|
return scope.alias === part;
|
|
8077
8257
|
});
|
|
@@ -8889,8 +9069,8 @@ var HeadlessSession = class {
|
|
|
8889
9069
|
});
|
|
8890
9070
|
pageInstance.createIntersectionObserver = (options) => this.createIntersectionObserver(pageInstance, options);
|
|
8891
9071
|
pageInstance.createMediaQueryObserver = () => this.createMediaQueryObserver(pageInstance);
|
|
8892
|
-
pageInstance.selectComponent = (selector) => this.selectComponent(selector);
|
|
8893
|
-
pageInstance.selectAllComponents = (selector) => this.selectAllComponents(selector);
|
|
9072
|
+
pageInstance.selectComponent = (selector) => resolveNativeComponentSelection(this.selectComponent(selector));
|
|
9073
|
+
pageInstance.selectAllComponents = (selector) => this.selectAllComponents(selector).map(resolveNativeComponentSelection);
|
|
8894
9074
|
pageInstance.getTabBar = () => {
|
|
8895
9075
|
if (this.currentPageInstance === pageInstance) this.renderCurrentPage();
|
|
8896
9076
|
return this.componentCache.get(customTabBarScopeId(pageInstance.route)) ?? null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpcore/simulator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "Headless mini-program runtime and testing kernel for the weapp-vite ecosystem",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/parser": "^8.0.5",
|
|
47
|
-
"@weapp-core/constants": "0.2.
|
|
47
|
+
"@weapp-core/constants": "0.2.4",
|
|
48
48
|
"css-select": "^7.0.0",
|
|
49
49
|
"css-what": "^8.0.0",
|
|
50
50
|
"fontoxpath": "^3.34.0",
|