@runic-artifex/vite-plugin-runic 0.19.0 → 0.20.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 +532 -12
- package/dist/access.d.ts +46 -0
- package/dist/access.js +123 -0
- package/dist/calls.d.ts +83 -0
- package/dist/calls.js +140 -0
- package/dist/channel.d.ts +58 -1
- package/dist/channel.js +20 -1
- package/dist/client.js +210 -1
- package/dist/dev-session.d.ts +19 -2
- package/dist/dev-session.js +67 -46
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +2 -1
- package/dist/handlers.d.ts +140 -0
- package/dist/handlers.js +773 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +226 -11
- package/dist/inspect-data.d.ts +268 -0
- package/dist/inspect-data.js +442 -0
- package/dist/inspect-edit.d.ts +164 -0
- package/dist/inspect-edit.js +273 -0
- package/dist/inspect-editor.d.ts +34 -0
- package/dist/inspect-editor.js +282 -0
- package/dist/inspect-frameworks.d.ts +72 -0
- package/dist/inspect-frameworks.js +333 -0
- package/dist/inspect-handlers.d.ts +84 -0
- package/dist/inspect-handlers.js +331 -0
- package/dist/inspect.d.ts +42 -0
- package/dist/inspect.js +783 -0
- package/dist/otlp.d.ts +80 -0
- package/dist/otlp.js +254 -0
- package/dist/requests.d.ts +17 -0
- package/dist/requests.js +67 -0
- package/dist/sources.d.ts +135 -0
- package/dist/sources.js +343 -0
- package/dist/timeline.d.ts +12 -0
- package/dist/timeline.js +14 -0
- package/dist/translations-source.d.ts +36 -0
- package/dist/translations-source.js +109 -0
- package/package.json +12 -6
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
// Runic Inspect's data: what the overview of a selected element says, assembled from what the development client
|
|
2
|
+
// learned on the page (the Bridge calls an element made, the Views' states), the development source map
|
|
3
|
+
// (`/__runic/sources`) and the element's framework component. No DOM access here, so the assembly is testable on its
|
|
4
|
+
// own; inspect.ts reads the page and draws the overview.
|
|
5
|
+
const maximumTextLength = 200;
|
|
6
|
+
/**
|
|
7
|
+
* The Runic Translations message markers (its ESM guide, "Message markers"): U+2063, the message ID in U+2061/U+2062
|
|
8
|
+
* bits, U+2064. Only while select mode is on.
|
|
9
|
+
*/
|
|
10
|
+
const markerPattern = /\u2063[\u2061\u2062]{1,24}\u2064/gu;
|
|
11
|
+
/** Text without Runic Translations message markers. */
|
|
12
|
+
export function stripMarkers(text) {
|
|
13
|
+
return text.replace(markerPattern, "");
|
|
14
|
+
}
|
|
15
|
+
/** Collapses whitespace and shortens text for the overview. */
|
|
16
|
+
export function normalizeText(text, maximum = maximumTextLength) {
|
|
17
|
+
const collapsed = text.replace(/\s+/gu, " ").trim();
|
|
18
|
+
return collapsed.length > maximum ? `${collapsed.slice(0, maximum - 1)}…` : collapsed;
|
|
19
|
+
}
|
|
20
|
+
const maximumMessages = 20;
|
|
21
|
+
/**
|
|
22
|
+
* The messages that markers name, once each per catalog, key and locale, in the order they appear, with where each
|
|
23
|
+
* appears (`text` or an attribute name); at most 20.
|
|
24
|
+
*/
|
|
25
|
+
export function groupMessages(found) {
|
|
26
|
+
const messages = new Map();
|
|
27
|
+
for (const { message, in: where } of found) {
|
|
28
|
+
if (typeof message !== "object" || message === null)
|
|
29
|
+
continue;
|
|
30
|
+
const { catalog, key, locale } = message;
|
|
31
|
+
if (typeof catalog !== "string" || typeof key !== "string" || key.length === 0)
|
|
32
|
+
continue;
|
|
33
|
+
const name = `${catalog}\u0000${key}\u0000${String(locale ?? "")}`;
|
|
34
|
+
let entry = messages.get(name);
|
|
35
|
+
if (entry === undefined) {
|
|
36
|
+
if (messages.size === maximumMessages)
|
|
37
|
+
continue;
|
|
38
|
+
messages.set(name, entry = { catalog, key, locale: typeof locale === "string" ? locale : "", in: [] });
|
|
39
|
+
}
|
|
40
|
+
if (!entry.in.includes(where))
|
|
41
|
+
entry.in.push(where);
|
|
42
|
+
}
|
|
43
|
+
return [...messages.values()];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A message's text and source location in its locale, from the Runic Translations dev server's
|
|
47
|
+
* `GET /__runic-translations/message` reply (`{ message: { locales: [{ locale, text, source: { path, line, column } }] } }`).
|
|
48
|
+
* A message without a locale (a runtime that does not tell it) takes the base locale, which the reply lists first.
|
|
49
|
+
*/
|
|
50
|
+
export function messageSource(reply, message) {
|
|
51
|
+
const locales = reply?.message?.locales;
|
|
52
|
+
if (!Array.isArray(locales))
|
|
53
|
+
return {};
|
|
54
|
+
const editable = { editable: locales.some((item) => item?.editable === true) };
|
|
55
|
+
const entry = (locales.find((item) => item?.locale === message.locale)
|
|
56
|
+
?? (message.locale === "" ? locales[0] : undefined));
|
|
57
|
+
if (entry === undefined || entry === null)
|
|
58
|
+
return editable;
|
|
59
|
+
const source = entry.source;
|
|
60
|
+
const valid = typeof source?.path === "string" && source.path.length > 0
|
|
61
|
+
&& Number.isSafeInteger(source.line) && source.line > 0;
|
|
62
|
+
return {
|
|
63
|
+
...(typeof entry.text === "string" ? { source: entry.text.length > maximumTextLength ? `${entry.text.slice(0, maximumTextLength - 1)}…` : entry.text } : {}),
|
|
64
|
+
...(valid ? {
|
|
65
|
+
location: {
|
|
66
|
+
file: source.path, line: source.line,
|
|
67
|
+
column: Number.isSafeInteger(source.column) && source.column > 0 ? source.column : 1,
|
|
68
|
+
editor: "translations",
|
|
69
|
+
message: { catalog: message.catalog, key: message.key, locale: entry.locale ?? message.locale },
|
|
70
|
+
},
|
|
71
|
+
} : {}),
|
|
72
|
+
...editable,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** A JSON-safe, shortened copy of a state value for the overview. */
|
|
76
|
+
export function previewValue(value, depth = 0) {
|
|
77
|
+
if (value === null || typeof value === "boolean")
|
|
78
|
+
return value;
|
|
79
|
+
if (typeof value === "number")
|
|
80
|
+
return Number.isFinite(value) ? value : String(value);
|
|
81
|
+
if (typeof value === "string")
|
|
82
|
+
return value.length > maximumTextLength ? `${value.slice(0, maximumTextLength - 1)}…` : value;
|
|
83
|
+
if (typeof value === "bigint")
|
|
84
|
+
return `${value}n`;
|
|
85
|
+
if (value === undefined || typeof value === "function" || typeof value === "symbol")
|
|
86
|
+
return undefined;
|
|
87
|
+
if (value instanceof Date)
|
|
88
|
+
return value.toISOString();
|
|
89
|
+
if (depth >= 3)
|
|
90
|
+
return Array.isArray(value) ? `[${value.length} items]` : "{…}";
|
|
91
|
+
if (Array.isArray(value)) {
|
|
92
|
+
const items = value.slice(0, 20).map((item) => previewValue(item, depth + 1) ?? null);
|
|
93
|
+
return value.length > 20 ? [...items, `… ${value.length - 20} more`] : items;
|
|
94
|
+
}
|
|
95
|
+
const result = {};
|
|
96
|
+
let count = 0;
|
|
97
|
+
for (const [key, item] of Object.entries(value)) {
|
|
98
|
+
if (count++ === 30) {
|
|
99
|
+
result["…"] = "more";
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
const preview = previewValue(item, depth + 1);
|
|
103
|
+
if (preview !== undefined)
|
|
104
|
+
result[key] = preview;
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
/** Whether a value has the shape of a text reference, as `@runic-artifex/views` checks it. */
|
|
109
|
+
export function isTextReference(value) {
|
|
110
|
+
if (typeof value !== "object" || value === null)
|
|
111
|
+
return false;
|
|
112
|
+
const candidate = value;
|
|
113
|
+
return Number.isInteger(candidate["version"]) && candidate["version"] >= 1
|
|
114
|
+
&& typeof candidate["catalog"] === "string" && typeof candidate["contractFingerprint"] === "string"
|
|
115
|
+
&& typeof candidate["key"] === "string" && candidate["key"].length > 0
|
|
116
|
+
&& typeof candidate["arguments"] === "object" && candidate["arguments"] !== null
|
|
117
|
+
&& (candidate["fallbackText"] === undefined || candidate["fallbackText"] === null || typeof candidate["fallbackText"] === "string");
|
|
118
|
+
}
|
|
119
|
+
/** The text references in a state, with their paths, at most 4 levels and 200 references deep. */
|
|
120
|
+
export function findTextReferences(state) {
|
|
121
|
+
const found = [];
|
|
122
|
+
const visit = (value, path, depth) => {
|
|
123
|
+
if (found.length >= 200 || typeof value !== "object" || value === null)
|
|
124
|
+
return;
|
|
125
|
+
if (isTextReference(value)) {
|
|
126
|
+
found.push({ path, reference: value });
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (depth >= 4)
|
|
130
|
+
return;
|
|
131
|
+
const entries = Array.isArray(value) ? value.slice(0, 100).map((item, index) => [String(index), item])
|
|
132
|
+
: Object.entries(value);
|
|
133
|
+
for (const [key, item] of entries)
|
|
134
|
+
visit(item, path === "" ? key : `${path}.${key}`, depth + 1);
|
|
135
|
+
};
|
|
136
|
+
visit(state, "", 0);
|
|
137
|
+
return found;
|
|
138
|
+
}
|
|
139
|
+
/** The member kind a Bridge call kind reaches in the source map, in the order to look it up. */
|
|
140
|
+
export function memberKinds(callKind) {
|
|
141
|
+
switch (callKind) {
|
|
142
|
+
case "command":
|
|
143
|
+
case "can":
|
|
144
|
+
case "operation": return ["command"];
|
|
145
|
+
case "set":
|
|
146
|
+
case "write": return ["setter", "state"];
|
|
147
|
+
default: return ["command", "state", "request", "interaction"];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export function indexSourceMap(map) {
|
|
151
|
+
const viewModels = new Map(map.viewModels.map((viewModel) => [viewModel.id, viewModel]));
|
|
152
|
+
const members = new Map(map.members.map((member) => [member.id, member]));
|
|
153
|
+
const stateMembers = new Map();
|
|
154
|
+
for (const member of map.members) {
|
|
155
|
+
if (member.kind !== "state" && member.kind !== "commandState")
|
|
156
|
+
continue;
|
|
157
|
+
let names = stateMembers.get(member.viewModel);
|
|
158
|
+
if (names === undefined)
|
|
159
|
+
stateMembers.set(member.viewModel, names = new Set());
|
|
160
|
+
names.add(member.member);
|
|
161
|
+
}
|
|
162
|
+
return { viewModels, members, stateMembers, map };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The ViewModel of a route: by the contract its calls carried, else by the route `connect<Name>()` connects, else the
|
|
166
|
+
* one ViewModel whose state members are exactly the route's state keys (a View presented as content connects a route
|
|
167
|
+
* of its own, such as `content1`).
|
|
168
|
+
*/
|
|
169
|
+
export function viewModelForRoute(index, route, contract, state) {
|
|
170
|
+
if (contract !== undefined) {
|
|
171
|
+
const byContract = index.viewModels.get(contract.split(":", 1)[0]);
|
|
172
|
+
if (byContract !== undefined)
|
|
173
|
+
return byContract;
|
|
174
|
+
}
|
|
175
|
+
const byRoute = index.map.viewModels.filter((viewModel) => viewModel.route === route);
|
|
176
|
+
if (byRoute.length === 1)
|
|
177
|
+
return byRoute[0];
|
|
178
|
+
if (typeof state !== "object" || state === null)
|
|
179
|
+
return undefined;
|
|
180
|
+
const keys = Object.keys(state);
|
|
181
|
+
if (keys.length === 0)
|
|
182
|
+
return undefined;
|
|
183
|
+
const matches = index.map.viewModels.filter((viewModel) => {
|
|
184
|
+
const names = index.stateMembers.get(viewModel.id);
|
|
185
|
+
return names !== undefined && names.size === keys.length && keys.every((key) => names.has(key));
|
|
186
|
+
});
|
|
187
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
188
|
+
}
|
|
189
|
+
function runicLocation(entry) {
|
|
190
|
+
const location = entry.location;
|
|
191
|
+
return location === undefined ? undefined
|
|
192
|
+
: { file: location.file, line: location.line, column: location.column, editor: "runic", id: entry.id };
|
|
193
|
+
}
|
|
194
|
+
function frontendLocation(call) {
|
|
195
|
+
return { file: call.file, line: call.line, column: call.column, editor: "vite" };
|
|
196
|
+
}
|
|
197
|
+
function capitalize(name) {
|
|
198
|
+
return name.length === 0 ? name : name[0].toUpperCase() + name.slice(1);
|
|
199
|
+
}
|
|
200
|
+
function stateValue(state, member) {
|
|
201
|
+
return typeof state === "object" && state !== null && Object.hasOwn(state, member)
|
|
202
|
+
? previewValue(state[member]) : undefined;
|
|
203
|
+
}
|
|
204
|
+
/** Assembles the overview of an element from what was read for it. */
|
|
205
|
+
export function assembleDescription(input) {
|
|
206
|
+
const index = input.sourceMap === undefined ? undefined : indexSourceMap(input.sourceMap);
|
|
207
|
+
const viewModels = new Map();
|
|
208
|
+
const resolved = new Map();
|
|
209
|
+
const viewModelOf = (route) => {
|
|
210
|
+
if (!resolved.has(route)) {
|
|
211
|
+
resolved.set(route, index === undefined ? undefined
|
|
212
|
+
: viewModelForRoute(index, route, input.contracts.get(route), input.states.get(route)));
|
|
213
|
+
}
|
|
214
|
+
return resolved.get(route);
|
|
215
|
+
};
|
|
216
|
+
const useRoute = (route) => {
|
|
217
|
+
const viewModel = viewModelOf(route);
|
|
218
|
+
if (!viewModels.has(route)) {
|
|
219
|
+
const contract = input.contracts.get(route) ?? viewModel?.contract;
|
|
220
|
+
const location = viewModel === undefined ? undefined : runicLocation(viewModel);
|
|
221
|
+
viewModels.set(route, {
|
|
222
|
+
route,
|
|
223
|
+
...(viewModel === undefined ? {} : { id: viewModel.id, name: viewModel.name }),
|
|
224
|
+
...(contract === undefined ? {} : { contract }),
|
|
225
|
+
...(location === undefined ? {} : { location }),
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return viewModel;
|
|
229
|
+
};
|
|
230
|
+
const sourceMember = (viewModel, kinds, member) => {
|
|
231
|
+
if (index === undefined || viewModel === undefined)
|
|
232
|
+
return undefined;
|
|
233
|
+
for (const kind of kinds) {
|
|
234
|
+
const entry = index.members.get(`${viewModel.id}/${kind}/${member}`);
|
|
235
|
+
if (entry !== undefined)
|
|
236
|
+
return entry;
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
};
|
|
240
|
+
const members = [];
|
|
241
|
+
const commands = [];
|
|
242
|
+
const memberKeys = new Set();
|
|
243
|
+
const addMember = (member) => {
|
|
244
|
+
const key = `${member.route}\u0000${member.member}`;
|
|
245
|
+
if (memberKeys.has(key))
|
|
246
|
+
return;
|
|
247
|
+
memberKeys.add(key);
|
|
248
|
+
members.push(member);
|
|
249
|
+
};
|
|
250
|
+
// What the element's calls show: exact.
|
|
251
|
+
for (const binding of input.learned) {
|
|
252
|
+
const viewModel = useRoute(binding.route);
|
|
253
|
+
const kinds = memberKinds(binding.kind);
|
|
254
|
+
const entry = sourceMember(viewModel, kinds, binding.member);
|
|
255
|
+
const state = input.states.get(binding.route);
|
|
256
|
+
const location = entry === undefined ? undefined : runicLocation(entry);
|
|
257
|
+
if (kinds[0] === "command") {
|
|
258
|
+
if (commands.some((command) => command.route === binding.route && command.member === binding.member))
|
|
259
|
+
continue;
|
|
260
|
+
const canName = `can${capitalize(binding.member)}`;
|
|
261
|
+
const canExecute = stateValue(state, canName);
|
|
262
|
+
const call = input.source?.calls.find((candidate) => candidate.member === binding.member);
|
|
263
|
+
commands.push({
|
|
264
|
+
route: binding.route,
|
|
265
|
+
...(viewModel === undefined ? {} : { viewModel: viewModel.id }),
|
|
266
|
+
member: binding.member,
|
|
267
|
+
evidence: "call",
|
|
268
|
+
...(call === undefined ? {} : { frontend: frontendLocation(call), via: call.via }),
|
|
269
|
+
...(entry === undefined ? {} : { symbol: entry.symbol }),
|
|
270
|
+
...(entry?.property === undefined ? {} : { property: entry.property }),
|
|
271
|
+
...(location === undefined ? {} : { location }),
|
|
272
|
+
...(canExecute === undefined ? {} : { canExecute }),
|
|
273
|
+
calls: input.calls.filter((call) => call.route === binding.route && call.member === binding.member
|
|
274
|
+
&& memberKinds(call.kind)[0] === "command").length,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const value = stateValue(state, binding.member);
|
|
279
|
+
addMember({
|
|
280
|
+
route: binding.route,
|
|
281
|
+
...(viewModel === undefined ? {} : { viewModel: viewModel.id }),
|
|
282
|
+
member: binding.member,
|
|
283
|
+
kind: entry?.kind ?? kinds[0],
|
|
284
|
+
evidence: "call",
|
|
285
|
+
...(value === undefined ? {} : { value }),
|
|
286
|
+
...(entry === undefined ? {} : { symbol: entry.symbol }),
|
|
287
|
+
...(location === undefined ? {} : { location }),
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// What the element's handlers reach in the source, before any call: the client calls that are commands of a
|
|
292
|
+
// ViewModel of the page (an open route's), else of the source map.
|
|
293
|
+
const sourceCommands = [];
|
|
294
|
+
for (const call of input.source?.calls ?? []) {
|
|
295
|
+
if (index === undefined)
|
|
296
|
+
break;
|
|
297
|
+
if (commands.some((command) => command.member === call.member))
|
|
298
|
+
continue;
|
|
299
|
+
const isCommand = (viewModel) => viewModel !== undefined && index.members.has(`${viewModel.id}/command/${call.member}`);
|
|
300
|
+
let routes = [...input.states.keys()].filter((route) => isCommand(viewModelOf(route)));
|
|
301
|
+
if (routes.length === 0) {
|
|
302
|
+
routes = [...new Set(index.map.viewModels.filter((viewModel) => isCommand(viewModel)).map((viewModel) => viewModel.route))];
|
|
303
|
+
}
|
|
304
|
+
for (const route of routes) {
|
|
305
|
+
const viewModel = input.states.has(route) ? useRoute(route)
|
|
306
|
+
: index.map.viewModels.find((candidate) => candidate.route === route && isCommand(candidate));
|
|
307
|
+
if (viewModel === undefined)
|
|
308
|
+
continue;
|
|
309
|
+
if (input.states.has(route) === false)
|
|
310
|
+
useRoute(route);
|
|
311
|
+
const entry = sourceMember(viewModel, ["command"], call.member);
|
|
312
|
+
const location = entry === undefined ? undefined : runicLocation(entry);
|
|
313
|
+
const canExecute = stateValue(input.states.get(route), `can${capitalize(call.member)}`);
|
|
314
|
+
commands.push({
|
|
315
|
+
route, viewModel: viewModel.id, member: call.member, evidence: "source",
|
|
316
|
+
frontend: frontendLocation(call), via: call.via,
|
|
317
|
+
...(entry === undefined ? {} : { symbol: entry.symbol }),
|
|
318
|
+
...(entry?.property === undefined ? {} : { property: entry.property }),
|
|
319
|
+
...(location === undefined ? {} : { location }),
|
|
320
|
+
...(canExecute === undefined ? {} : { canExecute }),
|
|
321
|
+
calls: 0,
|
|
322
|
+
});
|
|
323
|
+
sourceCommands.push(call.member);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// What the element shows: a state value as its text or a control's value. A match, so only for short text.
|
|
327
|
+
const ownText = normalizeText(input.element.ownText);
|
|
328
|
+
for (const [route, state] of input.states) {
|
|
329
|
+
if (typeof state !== "object" || state === null)
|
|
330
|
+
continue;
|
|
331
|
+
for (const [member, raw] of Object.entries(state)) {
|
|
332
|
+
if (typeof raw !== "string" && typeof raw !== "number" && typeof raw !== "bigint")
|
|
333
|
+
continue;
|
|
334
|
+
const text = String(raw);
|
|
335
|
+
if (text.trim().length === 0)
|
|
336
|
+
continue;
|
|
337
|
+
const evidence = ownText.length > 0 && normalizeText(text) === ownText ? "text"
|
|
338
|
+
: input.element.value !== undefined && input.element.value === text ? "value" : undefined;
|
|
339
|
+
if (evidence === undefined)
|
|
340
|
+
continue;
|
|
341
|
+
const viewModel = useRoute(route);
|
|
342
|
+
const entry = sourceMember(viewModel, ["state", "commandState"], member);
|
|
343
|
+
const location = entry === undefined ? undefined : runicLocation(entry);
|
|
344
|
+
addMember({
|
|
345
|
+
route,
|
|
346
|
+
...(viewModel === undefined ? {} : { viewModel: viewModel.id }),
|
|
347
|
+
member,
|
|
348
|
+
kind: entry?.kind ?? "state",
|
|
349
|
+
evidence,
|
|
350
|
+
value: previewValue(raw),
|
|
351
|
+
...(entry === undefined ? {} : { symbol: entry.symbol }),
|
|
352
|
+
...(location === undefined ? {} : { location }),
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
// Texts the ViewModel sent as references that the element shows.
|
|
357
|
+
const texts = [];
|
|
358
|
+
const elementText = input.element.text;
|
|
359
|
+
if (elementText.length > 0) {
|
|
360
|
+
for (const [route, state] of input.states) {
|
|
361
|
+
for (const { path, reference } of findTextReferences(state)) {
|
|
362
|
+
const formatted = input.resolveText?.(reference);
|
|
363
|
+
const text = formatted?.text ?? reference.fallbackText ?? undefined;
|
|
364
|
+
if (text === undefined || normalizeText(text).length === 0 || !elementText.includes(normalizeText(text)))
|
|
365
|
+
continue;
|
|
366
|
+
useRoute(route);
|
|
367
|
+
texts.push({
|
|
368
|
+
route, path, catalog: reference.catalog, key: reference.key,
|
|
369
|
+
...(formatted?.locale === undefined ? {} : { locale: formatted.locale }),
|
|
370
|
+
text: normalizeText(text), arguments: previewValue(reference.arguments),
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const notes = [];
|
|
376
|
+
const allowHint = "to use Runic Inspect from another machine, list it or its network in runic({ allow }) or RUNIC_DEV_ALLOW on the development server.";
|
|
377
|
+
if (input.sourceMapStatus === "missing") {
|
|
378
|
+
notes.push("No Bridge source map, so no C# locations: build the .NET project (`dotnet runic dev` passes the map to Vite), or check runic({ sourceMap }).");
|
|
379
|
+
}
|
|
380
|
+
else if (input.sourceMapStatus === "unavailable") {
|
|
381
|
+
notes.push("This development server does not serve the Bridge source map (/__runic/sources), so no C# locations.");
|
|
382
|
+
}
|
|
383
|
+
else if (input.sourceMapStatus === "forbidden") {
|
|
384
|
+
notes.push(`The development server refused this machine the Bridge source map (403), so no C# locations: ${allowHint}`);
|
|
385
|
+
}
|
|
386
|
+
if (input.handlersStatus === "forbidden") {
|
|
387
|
+
notes.push(`The development server refused this machine the handler analysis (/__runic/handlers, 403): ${allowHint}`);
|
|
388
|
+
}
|
|
389
|
+
if (input.remote === true) {
|
|
390
|
+
notes.push("This page is opened from another machine: editor links show where things are, but do not open them. " +
|
|
391
|
+
"/__runic/open launches the editor on the development machine and answers its own pages (localhost) only.");
|
|
392
|
+
}
|
|
393
|
+
const external = input.source?.external ?? [];
|
|
394
|
+
if (input.element.interactive && input.learned.length === 0 && sourceCommands.length === 0) {
|
|
395
|
+
if (external.length > 0) {
|
|
396
|
+
notes.push(`Its handler uses ${external.slice(0, 3).map((entry) => `${entry.name} from ${entry.source}`).join(", ")}: `
|
|
397
|
+
+ "a command reached through another file is learned on first click. Use it once outside Runic Inspect.");
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
notes.push("No Bridge call from this element yet: use it once outside Runic Inspect, and the overview shows the command or setter it calls.");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else if (sourceCommands.length > 0 && input.learned.length === 0) {
|
|
404
|
+
notes.push("Commands found in the component's source before any click; calls through other files are learned on first click.");
|
|
405
|
+
}
|
|
406
|
+
if (input.component === undefined) {
|
|
407
|
+
notes.push("No framework component found for this element (React, Vue, Svelte or Angular in development mode).");
|
|
408
|
+
}
|
|
409
|
+
const messages = input.messages ?? [];
|
|
410
|
+
if (input.element.text.length > 0 && messages.length === 0) {
|
|
411
|
+
if (input.markerStatus === "off") {
|
|
412
|
+
notes.push("Message keys of m.*() calls show in select mode (Alt+Shift+X, or toggle(true) before describe), which marks their text.");
|
|
413
|
+
}
|
|
414
|
+
else if (input.markerStatus === "unsupported") {
|
|
415
|
+
notes.push("No message keys for m.*() calls: they need @runic-artifex/vite-plugin-runic-translations 0.12 or later under vite dev.");
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (input.messageSourcesStatus === "forbidden") {
|
|
419
|
+
notes.push("The Translations dev server refused this machine its message API (403), so no .rmf2 locations and no editing: " +
|
|
420
|
+
"start the dev server with RUNIC_DEV_ALLOW listing this machine or its network (or runicTranslations({ inPageEditing: { allow } })).");
|
|
421
|
+
}
|
|
422
|
+
else if (input.messageSourcesStatus === "unavailable" && messages.some((message) => message.location === undefined)) {
|
|
423
|
+
notes.push("No .rmf2 locations: the Translations dev server's message API (/__runic-translations/message, plugin 0.12 or later in project mode with inPageEditing) did not answer.");
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
element: {
|
|
427
|
+
tag: input.element.tag,
|
|
428
|
+
...(input.element.id === undefined ? {} : { id: input.element.id }),
|
|
429
|
+
classes: input.element.classes,
|
|
430
|
+
...(input.element.role === undefined ? {} : { role: input.element.role }),
|
|
431
|
+
text: input.element.text,
|
|
432
|
+
},
|
|
433
|
+
...(input.component === undefined ? {} : { component: input.component }),
|
|
434
|
+
viewModels: [...viewModels.values()],
|
|
435
|
+
members,
|
|
436
|
+
commands,
|
|
437
|
+
calls: input.calls,
|
|
438
|
+
texts,
|
|
439
|
+
messages,
|
|
440
|
+
notes,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/** A compiler diagnostic of a refused text (RTR codes), located in the edited source. */
|
|
2
|
+
export interface EditDiagnostic {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly severity: string;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
readonly path?: string;
|
|
7
|
+
readonly line?: number;
|
|
8
|
+
readonly column?: number;
|
|
9
|
+
readonly helpUri?: string;
|
|
10
|
+
}
|
|
11
|
+
/** The authoring projection of a locale's text: inputs, selectors and variants (`locales[].structure`). */
|
|
12
|
+
export interface EditStructure {
|
|
13
|
+
readonly supported: boolean;
|
|
14
|
+
readonly inputs: readonly {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly type?: string;
|
|
17
|
+
readonly function?: string;
|
|
18
|
+
}[];
|
|
19
|
+
readonly selectors: readonly string[];
|
|
20
|
+
readonly selectorFunctions: readonly string[];
|
|
21
|
+
readonly variants: readonly {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly keys: readonly string[];
|
|
24
|
+
readonly pattern: string;
|
|
25
|
+
}[];
|
|
26
|
+
readonly pluralCategories: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
/** One locale of a message, as the API returns it. */
|
|
29
|
+
export interface EditLocale {
|
|
30
|
+
readonly locale: string;
|
|
31
|
+
readonly fallback?: string;
|
|
32
|
+
/** `catalog`, `override`, `library` or `missing` (no text of its own). */
|
|
33
|
+
readonly origin: string;
|
|
34
|
+
/** The whole MF2 message as authored; null for a locale without text of its own. */
|
|
35
|
+
readonly text: string | null;
|
|
36
|
+
readonly source?: {
|
|
37
|
+
readonly path: string;
|
|
38
|
+
readonly line: number;
|
|
39
|
+
readonly column: number;
|
|
40
|
+
};
|
|
41
|
+
/** The file a write changes, with the hash a write must name. */
|
|
42
|
+
readonly file: {
|
|
43
|
+
readonly path: string;
|
|
44
|
+
readonly exists: boolean;
|
|
45
|
+
readonly hash: string;
|
|
46
|
+
};
|
|
47
|
+
readonly editable: boolean;
|
|
48
|
+
readonly reason?: string;
|
|
49
|
+
readonly structure?: EditStructure;
|
|
50
|
+
}
|
|
51
|
+
/** A message in every locale, base locale first. */
|
|
52
|
+
export interface EditMessage {
|
|
53
|
+
readonly catalog: string;
|
|
54
|
+
readonly kind: string;
|
|
55
|
+
readonly package?: string;
|
|
56
|
+
readonly key: string;
|
|
57
|
+
readonly logicalKey?: string;
|
|
58
|
+
readonly baseLocale: string;
|
|
59
|
+
readonly content?: string;
|
|
60
|
+
readonly structured: boolean;
|
|
61
|
+
readonly inputs: readonly {
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly type?: string;
|
|
64
|
+
}[];
|
|
65
|
+
readonly markup: readonly string[];
|
|
66
|
+
readonly locales: readonly EditLocale[];
|
|
67
|
+
}
|
|
68
|
+
/** What the panel shows: */
|
|
69
|
+
export type EditStatus = "loading" | "ready" | "saving" | "saved" | "invalid" | "conflict" | "forbidden" | "failed";
|
|
70
|
+
export interface EditState {
|
|
71
|
+
readonly status: EditStatus;
|
|
72
|
+
readonly catalog: string;
|
|
73
|
+
readonly key: string;
|
|
74
|
+
/** The locale being edited. */
|
|
75
|
+
readonly locale: string;
|
|
76
|
+
readonly message?: EditMessage;
|
|
77
|
+
/** The text being edited, per locale; a locale not listed has the text as read. */
|
|
78
|
+
readonly drafts: Readonly<Record<string, string>>;
|
|
79
|
+
/** The file hash each locale was read with, which a write must name. */
|
|
80
|
+
readonly hashes: Readonly<Record<string, string>>;
|
|
81
|
+
readonly diagnostics: readonly EditDiagnostic[];
|
|
82
|
+
/** For `conflict`: the locale's text and hash in the file now. */
|
|
83
|
+
readonly conflict?: {
|
|
84
|
+
readonly locale: string;
|
|
85
|
+
readonly text: string;
|
|
86
|
+
readonly hash: string;
|
|
87
|
+
readonly message: EditMessage;
|
|
88
|
+
} | undefined;
|
|
89
|
+
/** The server's explanation of a refusal or failure. */
|
|
90
|
+
readonly detail?: string | undefined;
|
|
91
|
+
/** For `saved`: the files the write changed. */
|
|
92
|
+
readonly written?: readonly string[] | undefined;
|
|
93
|
+
}
|
|
94
|
+
/** An HTTP reply as the panel sees it: the status (0 when the request failed) and the JSON body, if any. */
|
|
95
|
+
export interface EditReply {
|
|
96
|
+
readonly status: number;
|
|
97
|
+
readonly body?: unknown;
|
|
98
|
+
}
|
|
99
|
+
export type EditEvent = {
|
|
100
|
+
readonly type: "read";
|
|
101
|
+
readonly reply: EditReply;
|
|
102
|
+
}
|
|
103
|
+
/** A read after the page's text changed (`read` without leaving the current status or the edited text). */
|
|
104
|
+
| {
|
|
105
|
+
readonly type: "refreshed";
|
|
106
|
+
readonly reply: EditReply;
|
|
107
|
+
} | {
|
|
108
|
+
readonly type: "locale";
|
|
109
|
+
readonly locale: string;
|
|
110
|
+
} | {
|
|
111
|
+
readonly type: "input";
|
|
112
|
+
readonly text: string;
|
|
113
|
+
} | {
|
|
114
|
+
readonly type: "save";
|
|
115
|
+
} | {
|
|
116
|
+
readonly type: "saved";
|
|
117
|
+
readonly reply: EditReply;
|
|
118
|
+
}
|
|
119
|
+
/** After a conflict: keep the edited text and write it over the current file. */
|
|
120
|
+
| {
|
|
121
|
+
readonly type: "reapply";
|
|
122
|
+
}
|
|
123
|
+
/** After a conflict: take the current text, dropping the edit. */
|
|
124
|
+
| {
|
|
125
|
+
readonly type: "discard";
|
|
126
|
+
}
|
|
127
|
+
/** Back to the text as read. */
|
|
128
|
+
| {
|
|
129
|
+
readonly type: "revert";
|
|
130
|
+
};
|
|
131
|
+
/** The panel's first state, for a message the overview lists; `locale` is the one the page shows. */
|
|
132
|
+
export declare function startEdit(message: {
|
|
133
|
+
readonly catalog: string;
|
|
134
|
+
readonly key: string;
|
|
135
|
+
readonly locale?: string;
|
|
136
|
+
}): EditState;
|
|
137
|
+
/** The locale's text as read: its source, or empty for a locale without text of its own. */
|
|
138
|
+
export declare function readText(state: EditState, locale?: string): string;
|
|
139
|
+
/** The text being edited in a locale. */
|
|
140
|
+
export declare function draftText(state: EditState, locale?: string): string;
|
|
141
|
+
/** Whether a locale's text differs from what was read. */
|
|
142
|
+
export declare function isDirty(state: EditState, locale?: string): boolean;
|
|
143
|
+
/** Whether any locale has an edited text that was not saved. */
|
|
144
|
+
export declare function hasEdits(state: EditState): boolean;
|
|
145
|
+
/** The locale entry being edited. */
|
|
146
|
+
export declare function currentLocale(state: EditState): EditLocale | undefined;
|
|
147
|
+
/** Whether Save does something now. */
|
|
148
|
+
export declare function canSave(state: EditState): boolean;
|
|
149
|
+
/** The POST body for the current locale. */
|
|
150
|
+
export declare function saveRequest(state: EditState): {
|
|
151
|
+
catalog: string;
|
|
152
|
+
key: string;
|
|
153
|
+
locale: string;
|
|
154
|
+
text: string;
|
|
155
|
+
expectedHash: string;
|
|
156
|
+
};
|
|
157
|
+
export declare function editReducer(state: EditState, event: EditEvent): EditState;
|
|
158
|
+
/** The API's `message`, with the members the panel uses checked; undefined for anything else. */
|
|
159
|
+
export declare function parseEditMessage(value: unknown): EditMessage | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* What the structure of a locale's text is, in short lines for the panel: its inputs, how it selects (plural or
|
|
162
|
+
* selector, with the plural categories of the locale), its variants' keys and the markup it uses.
|
|
163
|
+
*/
|
|
164
|
+
export declare function describeStructure(message: EditMessage, locale: EditLocale): string[];
|