@dimina-kit/devtools 0.3.1-dev.20260518114324 → 0.3.2-dev.20260522085907

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.
Files changed (89) hide show
  1. package/README.md +33 -71
  2. package/dist/main/app/app.js +5 -0
  3. package/dist/main/app/bootstrap.js +2 -1
  4. package/dist/main/app/launch.d.ts +1 -1
  5. package/dist/main/app/launch.js +6 -7
  6. package/dist/main/index.bundle.js +306 -317
  7. package/dist/main/ipc/panels.js +3 -5
  8. package/dist/main/ipc/projects.d.ts +1 -1
  9. package/dist/main/ipc/projects.js +5 -5
  10. package/dist/main/ipc/settings.d.ts +1 -1
  11. package/dist/main/ipc/settings.js +14 -1
  12. package/dist/main/ipc/simulator.d.ts +1 -1
  13. package/dist/main/ipc/simulator.js +1 -10
  14. package/dist/main/services/automation/exec.d.ts +2 -0
  15. package/dist/main/services/automation/exec.js +7 -9
  16. package/dist/main/services/automation/handlers/app.js +37 -51
  17. package/dist/main/services/automation/handlers/element.js +27 -41
  18. package/dist/main/services/default-adapter.js +3 -3
  19. package/dist/main/services/mcp/index.d.ts +1 -0
  20. package/dist/main/services/mcp/index.js +1 -0
  21. package/dist/main/services/mcp/server.js +5 -0
  22. package/dist/main/services/mcp/status.d.ts +10 -0
  23. package/dist/main/services/mcp/status.js +14 -0
  24. package/dist/main/services/mcp/target-manager.js +2 -1
  25. package/dist/main/services/notifications/renderer-notifier.d.ts +3 -3
  26. package/dist/main/services/notifications/renderer-notifier.js +3 -6
  27. package/dist/main/services/projects/local-provider.js +3 -3
  28. package/dist/main/services/projects/project-repository.d.ts +0 -1
  29. package/dist/main/services/settings/index.js +2 -1
  30. package/dist/main/services/simulator-storage/index.js +47 -77
  31. package/dist/main/services/views/view-manager.d.ts +3 -7
  32. package/dist/main/services/views/view-manager.js +20 -27
  33. package/dist/main/services/window-service.d.ts +3 -3
  34. package/dist/main/services/workbench-context.d.ts +3 -6
  35. package/dist/main/services/workbench-context.js +1 -3
  36. package/dist/main/services/workspace/workspace-service.js +8 -24
  37. package/dist/main/utils/theme.d.ts +24 -0
  38. package/dist/main/utils/theme.js +38 -1
  39. package/dist/preload/index.d.ts +5 -2
  40. package/dist/preload/index.js +3 -2
  41. package/dist/preload/instrumentation/app-data.d.ts +32 -2
  42. package/dist/preload/instrumentation/app-data.js +187 -172
  43. package/dist/preload/instrumentation/index.d.ts +2 -2
  44. package/dist/preload/instrumentation/index.js +2 -2
  45. package/dist/preload/instrumentation/wxml.d.ts +16 -4
  46. package/dist/preload/instrumentation/wxml.js +188 -178
  47. package/dist/preload/miniapp-snapshot/host.d.ts +12 -0
  48. package/dist/preload/miniapp-snapshot/host.js +117 -0
  49. package/dist/preload/miniapp-snapshot/types.d.ts +62 -0
  50. package/dist/preload/miniapp-snapshot/types.js +15 -0
  51. package/dist/preload/runtime/bridge.js +5 -24
  52. package/dist/preload/runtime/custom-apis.d.ts +1 -1
  53. package/dist/preload/runtime/custom-apis.js +3 -7
  54. package/dist/preload/shared/expose.d.ts +15 -0
  55. package/dist/preload/shared/expose.js +33 -0
  56. package/dist/preload/shared/page-iframe.d.ts +3 -0
  57. package/dist/preload/shared/page-iframe.js +6 -0
  58. package/dist/preload/shared/types.d.ts +2 -0
  59. package/dist/preload/windows/simulator.js +400 -348
  60. package/dist/renderer/assets/constants-DI382mTP.js +2 -0
  61. package/dist/renderer/assets/index-D8VFYBh-.js +46 -0
  62. package/dist/renderer/assets/{input-DqVQNCx_.js → input-CoWcfa8u.js} +2 -2
  63. package/dist/renderer/assets/ipc-transport-Cd2xPrsa.js +9 -0
  64. package/dist/renderer/assets/popover-Nq5gT9DO.js +2 -0
  65. package/dist/renderer/assets/select-By5KH-UG.js +2 -0
  66. package/dist/renderer/assets/{settings-BFNfnYvU.js → settings-Dj_N70qR.js} +2 -2
  67. package/dist/renderer/assets/settings-api-Do0_Smq1.js +2 -0
  68. package/dist/renderer/assets/workbenchSettings-CazSLGYt.js +8 -0
  69. package/dist/renderer/entries/main/index.html +5 -4
  70. package/dist/renderer/entries/popover/index.html +5 -4
  71. package/dist/renderer/entries/settings/index.html +4 -4
  72. package/dist/renderer/entries/workbench-settings/index.html +4 -3
  73. package/dist/shared/ipc-channels.d.ts +4 -12
  74. package/dist/shared/ipc-channels.js +10 -14
  75. package/dist/shared/simulator-route.d.ts +72 -0
  76. package/dist/shared/simulator-route.js +169 -0
  77. package/dist/shared/types.d.ts +2 -10
  78. package/dist/simulator/assets/simulator-DJCozrU5.js +9 -0
  79. package/dist/simulator/simulator.html +6 -43
  80. package/package.json +4 -4
  81. package/dist/preload/instrumentation/disposable.d.ts +0 -11
  82. package/dist/preload/instrumentation/disposable.js +0 -15
  83. package/dist/renderer/assets/index-Czz_bp6b.js +0 -46
  84. package/dist/renderer/assets/ipc-transport-CCHrCtDr.js +0 -9
  85. package/dist/renderer/assets/popover-BRg4XI_w.js +0 -2
  86. package/dist/renderer/assets/select-CvILHHZU.js +0 -2
  87. package/dist/renderer/assets/settings-api-DOAgmBst.js +0 -2
  88. package/dist/renderer/assets/workbenchSettings-DjVMgMMH.js +0 -8
  89. package/dist/simulator/assets/simulator-DL6kOCq-.js +0 -9
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Single source of truth for the simulator URL format.
3
+ *
4
+ * Upstream dimina (didi/dimina, since commit 68310fe) encodes the page route
5
+ * as query params: `?appId={id}&entry={spec}&page={spec}` where each spec is
6
+ * `pagePath?key=val&…`. HashRouter.syncStack rewrites the URL after every
7
+ * navigation; before mount, parent code consumes whatever URL it received.
8
+ *
9
+ * Every URL-building or URL-parsing site in devtools should go through this
10
+ * module — if upstream changes the contract again it's a single-file diff.
11
+ */
12
+ import type { CompileConfig } from './types.js';
13
+ export interface PageSpec {
14
+ pagePath: string;
15
+ /** Per-page query parsed out of `pagePath?k=v&…`. */
16
+ query: Record<string, string>;
17
+ }
18
+ export interface SimulatorRoute {
19
+ appId: string;
20
+ entry: PageSpec;
21
+ /** Defaults to `entry` when the URL has only one segment. */
22
+ current: PageSpec;
23
+ }
24
+ /**
25
+ * Encode a search-param value but leave `/` and `,` un-escaped for
26
+ * readability. Upstream `HashRouter._encodeSearchValue` only spares `/`;
27
+ * we also spare `,` so CSV-style extras (e.g. `apiNamespaces=qd,mt`) stay
28
+ * legible in the URL. Both characters are safe in a query string.
29
+ */
30
+ export declare function encodeRouteValue(value: string): string;
31
+ /** Encode `{ pagePath, query }` as `pagePath?k1=v1&k2=v2` (no trailing `?` when empty). */
32
+ export declare function encodePageSpec(spec: PageSpec): string;
33
+ /** Decode `pagePath?k=v` into `{ pagePath, query }`. Tolerates missing query. */
34
+ export declare function decodePageSpec(value: string): PageSpec;
35
+ /**
36
+ * Build the search-params string (without a leading `?`) for a route where
37
+ * `entry === current`. `extras` is appended verbatim (e.g. `apiNamespaces`).
38
+ */
39
+ export declare function buildRouteSearch(appId: string, page: PageSpec, extras?: Record<string, string>): string;
40
+ /**
41
+ * Build a full simulator URL. The default `host`/`pathname` match what the
42
+ * devkit dev server serves; both are overridable for tests.
43
+ */
44
+ export declare function buildSimulatorUrlFromSpec(opts: {
45
+ appId: string;
46
+ page: PageSpec;
47
+ port: number;
48
+ host?: string;
49
+ pathname?: string;
50
+ extras?: Record<string, string>;
51
+ }): string;
52
+ /**
53
+ * Renderer-facing convenience: build a simulator URL from devtools'
54
+ * `CompileConfig` shape (startPage / scene / queryParams).
55
+ */
56
+ export declare function buildSimulatorUrl(appId: string, compileConfig: CompileConfig, port: number, apiNamespaces?: string[]): string;
57
+ /**
58
+ * Parse `location.search` (the query route `?appId=&entry=&page=`) into a
59
+ * `SimulatorRoute`. Returns `null` when no recognisable route is present.
60
+ */
61
+ export declare function parseLocationRoute(search: string): SimulatorRoute | null;
62
+ /** Parse a full URL string into a `SimulatorRoute`, or `null`. */
63
+ export declare function parseRoute(url: string): SimulatorRoute | null;
64
+ /** Return the current page path (no query) from a URL, or `''` if unparseable. */
65
+ export declare function getCurrentPagePath(url: string): string;
66
+ /**
67
+ * Rewrite the URL so `entry === current`. Used before a hot-reload so the
68
+ * container boots at just the top page — avoids merged-bundle requests for a
69
+ * multi-page stack that the incremental compiler never emits.
70
+ */
71
+ export declare function collapseRouteToTopPage(url: string): string;
72
+ //# sourceMappingURL=simulator-route.d.ts.map
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Single source of truth for the simulator URL format.
3
+ *
4
+ * Upstream dimina (didi/dimina, since commit 68310fe) encodes the page route
5
+ * as query params: `?appId={id}&entry={spec}&page={spec}` where each spec is
6
+ * `pagePath?key=val&…`. HashRouter.syncStack rewrites the URL after every
7
+ * navigation; before mount, parent code consumes whatever URL it received.
8
+ *
9
+ * Every URL-building or URL-parsing site in devtools should go through this
10
+ * module — if upstream changes the contract again it's a single-file diff.
11
+ */
12
+ const ROUTE_KEYS = ['appId', 'entry', 'page'];
13
+ // ── Low-level encode / decode ────────────────────────────────────────────────
14
+ /**
15
+ * Encode a search-param value but leave `/` and `,` un-escaped for
16
+ * readability. Upstream `HashRouter._encodeSearchValue` only spares `/`;
17
+ * we also spare `,` so CSV-style extras (e.g. `apiNamespaces=qd,mt`) stay
18
+ * legible in the URL. Both characters are safe in a query string.
19
+ */
20
+ export function encodeRouteValue(value) {
21
+ return encodeURIComponent(value).replace(/%2F/g, '/').replace(/%2C/g, ',');
22
+ }
23
+ /** Encode `{ pagePath, query }` as `pagePath?k1=v1&k2=v2` (no trailing `?` when empty). */
24
+ export function encodePageSpec(spec) {
25
+ const keys = Object.keys(spec.query);
26
+ if (keys.length === 0)
27
+ return spec.pagePath;
28
+ const qs = keys
29
+ .map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(spec.query[k] ?? '')}`)
30
+ .join('&');
31
+ return `${spec.pagePath}?${qs}`;
32
+ }
33
+ /** Decode `pagePath?k=v` into `{ pagePath, query }`. Tolerates missing query. */
34
+ export function decodePageSpec(value) {
35
+ const qIdx = value.indexOf('?');
36
+ if (qIdx < 0)
37
+ return { pagePath: value, query: {} };
38
+ const pagePath = value.slice(0, qIdx);
39
+ const query = {};
40
+ for (const pair of value.slice(qIdx + 1).split('&')) {
41
+ if (!pair)
42
+ continue;
43
+ const eqIdx = pair.indexOf('=');
44
+ const k = eqIdx >= 0 ? pair.slice(0, eqIdx) : pair;
45
+ const v = eqIdx >= 0 ? pair.slice(eqIdx + 1) : '';
46
+ if (k)
47
+ query[decodeURIComponent(k)] = decodeURIComponent(v);
48
+ }
49
+ return { pagePath, query };
50
+ }
51
+ // ── Build ────────────────────────────────────────────────────────────────────
52
+ /**
53
+ * Build the search-params string (without a leading `?`) for a route where
54
+ * `entry === current`. `extras` is appended verbatim (e.g. `apiNamespaces`).
55
+ */
56
+ export function buildRouteSearch(appId, page, extras = {}) {
57
+ const spec = encodePageSpec(page);
58
+ const params = [
59
+ `appId=${encodeRouteValue(appId)}`,
60
+ `entry=${encodeRouteValue(spec)}`,
61
+ `page=${encodeRouteValue(spec)}`,
62
+ ];
63
+ for (const [k, v] of Object.entries(extras)) {
64
+ if (ROUTE_KEYS.includes(k))
65
+ continue;
66
+ params.push(`${encodeURIComponent(k)}=${encodeRouteValue(v)}`);
67
+ }
68
+ return params.join('&');
69
+ }
70
+ /**
71
+ * Build a full simulator URL. The default `host`/`pathname` match what the
72
+ * devkit dev server serves; both are overridable for tests.
73
+ */
74
+ export function buildSimulatorUrlFromSpec(opts) {
75
+ const host = opts.host ?? 'localhost';
76
+ const pathname = opts.pathname ?? '/simulator.html';
77
+ const search = buildRouteSearch(opts.appId, opts.page, opts.extras ?? {});
78
+ return `http://${host}:${opts.port}${pathname}?${search}`;
79
+ }
80
+ /**
81
+ * Renderer-facing convenience: build a simulator URL from devtools'
82
+ * `CompileConfig` shape (startPage / scene / queryParams).
83
+ */
84
+ export function buildSimulatorUrl(appId, compileConfig, port, apiNamespaces) {
85
+ const pagePath = compileConfig.startPage || 'pages/index/index';
86
+ const query = {};
87
+ for (const p of compileConfig.queryParams ?? []) {
88
+ if (p.key)
89
+ query[p.key] = p.value;
90
+ }
91
+ query.scene = String(compileConfig.scene ?? 1001);
92
+ const extras = {};
93
+ if (apiNamespaces?.length)
94
+ extras.apiNamespaces = apiNamespaces.join(',');
95
+ return buildSimulatorUrlFromSpec({
96
+ appId,
97
+ page: { pagePath, query },
98
+ port,
99
+ extras,
100
+ });
101
+ }
102
+ // ── Parse ────────────────────────────────────────────────────────────────────
103
+ /**
104
+ * Parse `location.search` (the query route `?appId=&entry=&page=`) into a
105
+ * `SimulatorRoute`. Returns `null` when no recognisable route is present.
106
+ */
107
+ export function parseLocationRoute(search) {
108
+ const params = new URLSearchParams(search.startsWith('?') ? search.slice(1) : search);
109
+ const appId = params.get('appId');
110
+ const entryRaw = params.get('entry');
111
+ if (!appId || !entryRaw)
112
+ return null;
113
+ const entry = decodePageSpec(entryRaw);
114
+ const pageRaw = params.get('page');
115
+ const current = pageRaw && pageRaw !== entryRaw ? decodePageSpec(pageRaw) : entry;
116
+ return { appId, entry, current };
117
+ }
118
+ /** Parse a full URL string into a `SimulatorRoute`, or `null`. */
119
+ export function parseRoute(url) {
120
+ if (!url)
121
+ return null;
122
+ try {
123
+ const u = new URL(url);
124
+ return parseLocationRoute(u.search);
125
+ }
126
+ catch {
127
+ return null;
128
+ }
129
+ }
130
+ // ── Convenience helpers ──────────────────────────────────────────────────────
131
+ /** Return the current page path (no query) from a URL, or `''` if unparseable. */
132
+ export function getCurrentPagePath(url) {
133
+ const route = parseRoute(url);
134
+ return route?.current.pagePath ?? '';
135
+ }
136
+ /**
137
+ * Rewrite the URL so `entry === current`. Used before a hot-reload so the
138
+ * container boots at just the top page — avoids merged-bundle requests for a
139
+ * multi-page stack that the incremental compiler never emits.
140
+ */
141
+ export function collapseRouteToTopPage(url) {
142
+ if (!url)
143
+ return url;
144
+ let u;
145
+ try {
146
+ u = new URL(url);
147
+ }
148
+ catch {
149
+ return url;
150
+ }
151
+ const route = parseLocationRoute(u.search);
152
+ if (!route)
153
+ return url;
154
+ if (route.entry.pagePath === route.current.pagePath
155
+ && encodePageSpec(route.entry) === encodePageSpec(route.current)) {
156
+ return url;
157
+ }
158
+ // Preserve non-route extras (apiNamespaces etc.) from the query portion;
159
+ // a non-route fragment in `u.hash`, if any, is carried through verbatim.
160
+ const searchParams = new URLSearchParams(u.search.startsWith('?') ? u.search.slice(1) : u.search);
161
+ const extras = {};
162
+ for (const [k, v] of searchParams) {
163
+ if (!ROUTE_KEYS.includes(k))
164
+ extras[k] = v;
165
+ }
166
+ const search = buildRouteSearch(route.appId, route.current, extras);
167
+ return `${u.origin}${u.pathname}?${search}${u.hash}`;
168
+ }
169
+ //# sourceMappingURL=simulator-route.js.map
@@ -1,3 +1,4 @@
1
+ import type { OpenProjectOptions } from '@dimina-kit/devkit';
1
2
  export interface AppInfo {
2
3
  appName?: string;
3
4
  [key: string]: unknown;
@@ -8,16 +9,7 @@ export interface ProjectSession {
8
9
  appInfo: AppInfo | unknown;
9
10
  }
10
11
  export interface CompilationAdapter {
11
- openProject(opts: {
12
- projectPath: string;
13
- port?: number;
14
- sourcemap?: boolean;
15
- simulatorDir?: string;
16
- /** When false, skip the file-watcher / auto-recompile loop. Default true. */
17
- watch?: boolean;
18
- onRebuild?: () => void;
19
- onBuildError?: (err: unknown) => void;
20
- }): Promise<ProjectSession>;
12
+ openProject(opts: Omit<OpenProjectOptions, 'containerDir' | 'outputDir'>): Promise<ProjectSession>;
21
13
  }
22
14
  export type BuiltinPanelId = 'wxml' | 'console' | 'appdata' | 'storage';
23
15
  export type BuiltinModuleId = 'projects' | 'session' | 'simulator' | 'popover' | 'settings';