@playcanvas/inspector 0.1.0 → 0.3.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 +47 -26
- package/package.json +12 -6
- package/src/asset-view.js +24 -17
- package/src/camera-view.js +5 -3
- package/src/context-menu.js +231 -0
- package/src/copy-json.js +692 -0
- package/src/describe.js +51 -2
- package/src/frame-graph-view.js +1 -0
- package/src/hierarchy-view.js +29 -3
- package/src/inspector.js +406 -59
- package/src/list-view.js +118 -12
- package/src/material-view.js +7 -6
- package/src/memory-view.js +224 -66
- package/src/mesh-view.js +6 -5
- package/src/model.js +24 -2
- package/src/node-model.js +78 -9
- package/src/property-view.js +159 -5
- package/src/render-target-view.js +3 -3
- package/src/script-view.js +21 -12
- package/src/styles.js +196 -2
- package/src/texture-view.js +4 -4
- package/src/transform-tool.js +185 -0
- package/types/asset-usage.d.ts +2 -0
- package/types/asset-view.d.ts +17 -10
- package/types/camera-view.d.ts +12 -6
- package/types/context-menu.d.ts +90 -0
- package/types/copy-json.d.ts +69 -0
- package/types/describe.d.ts +3 -2
- package/types/entity-inspector-script.d.ts +2 -2
- package/types/frame-graph-view.d.ts +6 -2
- package/types/hierarchy-view.d.ts +25 -11
- package/types/input/fly-controller.d.ts +4 -4
- package/types/input/input.d.ts +2 -2
- package/types/input/orbit-controller.d.ts +6 -6
- package/types/input/pose.d.ts +9 -7
- package/types/inspector.d.ts +144 -22
- package/types/instance-survey.d.ts +3 -1
- package/types/list-view.d.ts +44 -3
- package/types/material-view.d.ts +13 -6
- package/types/memory-view.d.ts +37 -30
- package/types/mesh-view.d.ts +12 -5
- package/types/model.d.ts +21 -3
- package/types/node-model.d.ts +30 -6
- package/types/physics-debug.d.ts +9 -5
- package/types/physics-view.d.ts +8 -6
- package/types/picker/picker.d.ts +15 -6
- package/types/picker/render-pass-picker.d.ts +16 -10
- package/types/property-view.d.ts +41 -0
- package/types/render-target-view.d.ts +10 -7
- package/types/renderers/texture-renderer-shaders.d.ts +1 -1
- package/types/renderers/texture-renderer.d.ts +11 -5
- package/types/renderers/wire-renderer.d.ts +14 -5
- package/types/script-view.d.ts +10 -4
- package/types/shader-view.d.ts +10 -6
- package/types/texture-view.d.ts +8 -5
- package/types/transform-tool.d.ts +92 -0
- package/types/viewport-tools.d.ts +25 -18
package/src/mesh-view.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Mesh, VertexBuffer } from 'playcanvas';
|
|
|
3
3
|
import { describeValue } from './describe.js';
|
|
4
4
|
import { collectMeshInstances } from './instance-survey.js';
|
|
5
5
|
import { nodeLabel } from './memory-view.js';
|
|
6
|
-
import { formatBytes, makeSection, push } from './model.js';
|
|
6
|
+
import { formatBytes, makeSection, makeUsageSection, push } from './model.js';
|
|
7
7
|
import { meshInstanceRows, meshRows } from './node-model.js';
|
|
8
8
|
|
|
9
9
|
/** @import { AppBase } from 'playcanvas' */
|
|
@@ -200,17 +200,18 @@ function meshNote(survey) {
|
|
|
200
200
|
* format, and what uses it, with each mesh instance opening in place.
|
|
201
201
|
*
|
|
202
202
|
* @param {Mesh} mesh - The mesh.
|
|
203
|
-
* @param {{ app: AppBase }} ctx - The app, to find the mesh's users
|
|
203
|
+
* @param {{ app: AppBase, backlinks?: boolean }} ctx - The app, to find the mesh's users, and
|
|
204
|
+
* whether to find them at all, which a copy has no use for.
|
|
204
205
|
* @returns {PropertySection[]} The sections.
|
|
205
206
|
*/
|
|
206
207
|
function buildMeshModel(mesh, ctx) {
|
|
207
|
-
const users = surveyMeshes(ctx.app).users.get(mesh) ?? [];
|
|
208
|
-
|
|
209
208
|
const general = makeSection('mesh', `Mesh #${mesh.id}`);
|
|
210
209
|
push(general, 'size', { text: formatBytes(meshBytes(mesh)), cls: 'num' });
|
|
211
210
|
general.rows.push(...meshRows(mesh));
|
|
211
|
+
if (ctx.backlinks === false) return [general];
|
|
212
212
|
|
|
213
|
-
const
|
|
213
|
+
const users = surveyMeshes(ctx.app).users.get(mesh) ?? [];
|
|
214
|
+
const usage = makeUsageSection('users', 'Used by');
|
|
214
215
|
const instances = instanceCount(users);
|
|
215
216
|
push(usage, 'users', {
|
|
216
217
|
text: users.length ?
|
package/src/model.js
CHANGED
|
@@ -25,6 +25,8 @@ import { collectProperties, describeValue } from './describe.js';
|
|
|
25
25
|
* @property {string} title - The title.
|
|
26
26
|
* @property {PropertyRow[]} rows - The rows.
|
|
27
27
|
* @property {boolean} [collapsed] - Whether the section starts out collapsed.
|
|
28
|
+
* @property {boolean} [backlink] - Whether the section lists what uses the subject, which copies
|
|
29
|
+
* leave out, see {@link Described#backlink}.
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -37,6 +39,26 @@ function makeSection(key, title, collapsed = false) {
|
|
|
37
39
|
return { key, title, rows: [], collapsed };
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} key - The section key.
|
|
44
|
+
* @param {string} title - The section title.
|
|
45
|
+
* @returns {PropertySection} An empty section listing what uses the subject, which copies leave out.
|
|
46
|
+
*/
|
|
47
|
+
function makeUsageSection(key, title) {
|
|
48
|
+
return { key, title, rows: [], collapsed: false, backlink: true };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Marks a value as referring back to what holds or uses the subject, which copies leave out.
|
|
53
|
+
*
|
|
54
|
+
* @param {Described} value - The value.
|
|
55
|
+
* @returns {Described} The same value.
|
|
56
|
+
*/
|
|
57
|
+
function backlink(value) {
|
|
58
|
+
value.backlink = true;
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
|
|
40
62
|
/**
|
|
41
63
|
* Reads a property, turning a throwing getter into an error value rather than a broken panel.
|
|
42
64
|
*
|
|
@@ -165,6 +187,6 @@ function renderTargetSummary(rt, device) {
|
|
|
165
187
|
}
|
|
166
188
|
|
|
167
189
|
export {
|
|
168
|
-
attachmentsText, formatBytes, formatName, makeSection, passDisplayName, push, pushRow,
|
|
169
|
-
reflectRows, renderTargetSummary
|
|
190
|
+
attachmentsText, backlink, formatBytes, formatName, makeSection, makeUsageSection, passDisplayName, push, pushRow,
|
|
191
|
+
read, reflectInto, reflectRows, renderTargetSummary
|
|
170
192
|
};
|
package/src/node-model.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
import { pushAssetRows } from './asset-view.js';
|
|
6
6
|
import { collectProperties, describeValue } from './describe.js';
|
|
7
|
-
import { formatBytes, makeSection, push, pushRow, read, reflectInto, reflectRows } from './model.js';
|
|
7
|
+
import { backlink, formatBytes, makeSection, push, pushRow, read, reflectInto, reflectRows } from './model.js';
|
|
8
8
|
|
|
9
9
|
/** @import { LayerComposition } from 'playcanvas' */
|
|
10
10
|
/** @import { Material } from 'playcanvas' */
|
|
@@ -68,24 +68,76 @@ function nodeSection(node) {
|
|
|
68
68
|
push(section, 'enabled in hierarchy', describeValue(node.enabled));
|
|
69
69
|
push(section, 'tags', describeValue(node.tags.list()));
|
|
70
70
|
push(section, 'path', describeValue(node.path));
|
|
71
|
-
push(section, 'parent', describeValue(node.parent));
|
|
71
|
+
push(section, 'parent', backlink(describeValue(node.parent)));
|
|
72
72
|
push(section, 'children', describeValue(node.children.length));
|
|
73
73
|
|
|
74
74
|
return section;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
+
* @param {string} text - Numbers, separated by commas or spaces, optionally in brackets.
|
|
79
|
+
* @returns {number[]|null} The numbers, or null when any of them is not a finite number.
|
|
80
|
+
*/
|
|
81
|
+
function parseNumbers(text) {
|
|
82
|
+
const numbers = text.split(/[\s,;()[\]]+/).filter(Boolean).map(Number);
|
|
83
|
+
return numbers.every(Number.isFinite) ? numbers : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Moves the physics body of a node to where the node now is. A dynamic or kinematic body would
|
|
88
|
+
* otherwise put the node back where the body is on the next step of the simulation.
|
|
89
|
+
*
|
|
90
|
+
* @param {GraphNode} node - A node whose transform was changed.
|
|
91
|
+
*/
|
|
92
|
+
function syncBody(node) {
|
|
93
|
+
const body = /** @type {any} */ (node).c?.rigidbody;
|
|
94
|
+
if (body?.enabled && body.body) body.teleport(node.getPosition(), node.getRotation());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Makes a vector of a node's transform editable as its components, separated by commas. The text
|
|
99
|
+
* holds every digit of each, so a component that is not touched is set back exactly as it was.
|
|
100
|
+
*
|
|
101
|
+
* @param {Described} value - The described vector.
|
|
78
102
|
* @param {GraphNode} node - The node.
|
|
79
|
-
* @
|
|
103
|
+
* @param {import('playcanvas').Vec3} vector - The vector.
|
|
104
|
+
* @param {(x: number, y: number, z: number) => void} set - Sets it on the node.
|
|
105
|
+
* @param {boolean} [uniform] - Whether a single number sets all three components, as for a scale.
|
|
106
|
+
* @returns {Described} The value, editable.
|
|
107
|
+
*/
|
|
108
|
+
function editVector(value, node, vector, set, uniform = false) {
|
|
109
|
+
value.edit = {
|
|
110
|
+
text: `${vector.x}, ${vector.y}, ${vector.z}`,
|
|
111
|
+
apply: (text) => {
|
|
112
|
+
const numbers = parseNumbers(text);
|
|
113
|
+
if (uniform && numbers?.length === 1) numbers.push(numbers[0], numbers[0]);
|
|
114
|
+
if (numbers?.length !== 3) return false;
|
|
115
|
+
set(numbers[0], numbers[1], numbers[2]);
|
|
116
|
+
syncBody(node);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @param {GraphNode} node - The node.
|
|
125
|
+
* @returns {PropertySection} The transform section. Its positions, rotations and local scale are
|
|
126
|
+
* editable; the world scale only follows from the scales of the node and its ancestors.
|
|
80
127
|
*/
|
|
81
128
|
function transformSection(node) {
|
|
82
129
|
const section = makeSection('transform', 'Transform');
|
|
83
130
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
131
|
+
const localPosition = node.getLocalPosition();
|
|
132
|
+
const localRotation = node.getLocalEulerAngles();
|
|
133
|
+
const localScale = node.getLocalScale();
|
|
134
|
+
const position = node.getPosition();
|
|
135
|
+
const rotation = node.getEulerAngles();
|
|
136
|
+
push(section, 'local position', editVector(describeValue(localPosition), node, localPosition, (x, y, z) => node.setLocalPosition(x, y, z)));
|
|
137
|
+
push(section, 'local rotation', editVector(describeValue(localRotation), node, localRotation, (x, y, z) => node.setLocalEulerAngles(x, y, z)));
|
|
138
|
+
push(section, 'local scale', editVector(describeValue(localScale), node, localScale, (x, y, z) => node.setLocalScale(x, y, z), true));
|
|
139
|
+
push(section, 'world position', editVector(describeValue(position), node, position, (x, y, z) => node.setPosition(x, y, z)));
|
|
140
|
+
push(section, 'world rotation', editVector(describeValue(rotation), node, rotation, (x, y, z) => node.setEulerAngles(x, y, z)));
|
|
89
141
|
push(section, 'world scale', describeValue(node.getScale()));
|
|
90
142
|
push(section, 'forward', describeValue(node.forward));
|
|
91
143
|
|
|
@@ -401,4 +453,21 @@ function buildNodeModel(node) {
|
|
|
401
453
|
return sections;
|
|
402
454
|
}
|
|
403
455
|
|
|
404
|
-
|
|
456
|
+
/**
|
|
457
|
+
* The sections a component shows under its entity, for a component reached on its own, such as
|
|
458
|
+
* through a link.
|
|
459
|
+
*
|
|
460
|
+
* @param {Component} component - The component.
|
|
461
|
+
* @returns {PropertySection[]} Its section, followed by one per script instance of a script component.
|
|
462
|
+
*/
|
|
463
|
+
function buildComponentModel(component) {
|
|
464
|
+
const name = /** @type {any} */ (component).system?.id ?? component.constructor.name;
|
|
465
|
+
const sections = [componentSection(name, component)];
|
|
466
|
+
if (name === 'script') sections.push(...scriptSections(/** @type {any} */ (component)));
|
|
467
|
+
return sections;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export {
|
|
471
|
+
buildComponentModel, buildNodeModel, layersValue, materialRows, materialTextures, meshInstanceRows, meshRows,
|
|
472
|
+
scriptInstanceRows, syncBody, vertexFormatValue
|
|
473
|
+
};
|
package/src/property-view.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
import { copyRow, copySection, copySubject } from './copy-json.js';
|
|
2
|
+
import { describeValue } from './describe.js';
|
|
1
3
|
import { INDENT_COLORS } from './styles.js';
|
|
2
4
|
import { setTip } from './tooltip.js';
|
|
3
5
|
|
|
6
|
+
/** @import { CopyOptions, CopyResult } from './copy-json.js' */
|
|
4
7
|
/** @import { Described } from './describe.js' */
|
|
5
8
|
/** @import { PropertyRow, PropertySection } from './model.js' */
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Something a context menu of the panel can copy.
|
|
12
|
+
*
|
|
13
|
+
* @typedef {object} CopyTarget
|
|
14
|
+
* @ignore
|
|
15
|
+
* @property {string} title - What is copied, as the menu names it.
|
|
16
|
+
* @property {(options: CopyOptions) => CopyResult} copy - Makes the copy.
|
|
17
|
+
*/
|
|
18
|
+
|
|
7
19
|
/**
|
|
8
20
|
* @typedef {object} RowElements
|
|
9
21
|
* @ignore
|
|
@@ -25,6 +37,9 @@ import { setTip } from './tooltip.js';
|
|
|
25
37
|
* @property {Described['actions']|null} actions - The actions the buttons run, kept current each refresh.
|
|
26
38
|
* @property {HTMLElement} caretEl - The caret of a row that expands, its own click target.
|
|
27
39
|
* @property {(() => void)|null} select - What clicking the row chooses, kept current each refresh.
|
|
40
|
+
* @property {PropertyRow|null} row - The row last rendered, which a copy of it is made from.
|
|
41
|
+
* @property {Described['edit']|null} edit - The edit of the value, kept current each refresh.
|
|
42
|
+
* @property {HTMLInputElement|null} editEl - The text field the value is edited in, while it is.
|
|
28
43
|
*/
|
|
29
44
|
|
|
30
45
|
/**
|
|
@@ -34,8 +49,12 @@ import { setTip } from './tooltip.js';
|
|
|
34
49
|
* @property {HTMLElement} titleEl - The clickable title.
|
|
35
50
|
* @property {HTMLElement} rowsEl - The container the rows live in.
|
|
36
51
|
* @property {Map<string, RowElements>} rows - The rows by key.
|
|
52
|
+
* @property {PropertySection|null} section - The section last rendered, which a copy of it is made from.
|
|
37
53
|
*/
|
|
38
54
|
|
|
55
|
+
// the tooltip of an editable value
|
|
56
|
+
const EDIT_TIP = 'Click to edit. Enter applies, Esc cancels';
|
|
57
|
+
|
|
39
58
|
// where the first indent guide sits, and how far apart the levels are, in CSS pixels
|
|
40
59
|
const INDENT_BASE = 8;
|
|
41
60
|
const INDENT_STEP = 14;
|
|
@@ -186,6 +205,14 @@ class PropertyView {
|
|
|
186
205
|
*/
|
|
187
206
|
_emptyEl = null;
|
|
188
207
|
|
|
208
|
+
/**
|
|
209
|
+
* The rows and sections by the elements showing them, to find what a menu was opened on.
|
|
210
|
+
*
|
|
211
|
+
* @type {WeakMap<Element, RowElements|SectionElements>}
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
_byElement = new WeakMap();
|
|
215
|
+
|
|
189
216
|
/**
|
|
190
217
|
* @param {HTMLElement} container - The element to render into.
|
|
191
218
|
* @param {(target: *) => void} onSelect - The value link callback.
|
|
@@ -252,6 +279,45 @@ class PropertyView {
|
|
|
252
279
|
return top ?? 0;
|
|
253
280
|
}
|
|
254
281
|
|
|
282
|
+
/**
|
|
283
|
+
* What a copy made from an element of the panel copies: the row or the section title the
|
|
284
|
+
* element is in, and anywhere else the subject itself.
|
|
285
|
+
*
|
|
286
|
+
* @param {Node} node - The element, such as the target of a context menu event.
|
|
287
|
+
* @returns {CopyTarget|null} What to copy, or null when the element is not in the panel or
|
|
288
|
+
* nothing is shown.
|
|
289
|
+
*/
|
|
290
|
+
copyTargetAt(node) {
|
|
291
|
+
if (!this.container.contains(node)) return null;
|
|
292
|
+
// the node type rather than instanceof, as the element may come from another window's realm
|
|
293
|
+
let element = node.nodeType === 1 ? /** @type {Element} */ (node) : node.parentElement;
|
|
294
|
+
for (; element && element !== this.container; element = element.parentElement) {
|
|
295
|
+
const found = this._byElement.get(element);
|
|
296
|
+
if (!found) continue;
|
|
297
|
+
if ('row' in found && found.row) {
|
|
298
|
+
const row = found.row;
|
|
299
|
+
const text = row.value.text;
|
|
300
|
+
return { title: row.label ? `${row.label}: ${text}` : text, copy: options => copyRow(row, options) };
|
|
301
|
+
}
|
|
302
|
+
if ('section' in found && found.section) {
|
|
303
|
+
const section = found.section;
|
|
304
|
+
return { title: section.title, copy: options => copySection(section, options) };
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return this.subjectCopyTarget();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @returns {CopyTarget|null} A copy of the subject, rebuilt when it is made so it reads the
|
|
312
|
+
* live object, or null when nothing is shown.
|
|
313
|
+
*/
|
|
314
|
+
subjectCopyTarget() {
|
|
315
|
+
const subject = this._subject;
|
|
316
|
+
const buildModel = this._buildModel;
|
|
317
|
+
if (!subject || !buildModel) return null;
|
|
318
|
+
return { title: describeValue(subject, 1).text, copy: options => copySubject(subject, buildModel(subject), options) };
|
|
319
|
+
}
|
|
320
|
+
|
|
255
321
|
/**
|
|
256
322
|
* Re-reads every shown property and updates the text that changed.
|
|
257
323
|
*/
|
|
@@ -280,6 +346,7 @@ class PropertyView {
|
|
|
280
346
|
|
|
281
347
|
for (const section of model) {
|
|
282
348
|
const elements = this._sections.get(section.key) ?? this._createSection(section);
|
|
349
|
+
elements.section = section;
|
|
283
350
|
seen.add(section.key);
|
|
284
351
|
|
|
285
352
|
if (elements.titleEl.textContent !== section.title) {
|
|
@@ -317,6 +384,7 @@ class PropertyView {
|
|
|
317
384
|
|
|
318
385
|
for (const row of this._flatten(section.key, rows, 0, '')) {
|
|
319
386
|
const elements = section.rows.get(row.key) ?? this._createRow(section, row);
|
|
387
|
+
elements.row = row;
|
|
320
388
|
seen.add(row.key);
|
|
321
389
|
|
|
322
390
|
if (elements.labelEl.textContent !== row.label) {
|
|
@@ -350,7 +418,13 @@ class PropertyView {
|
|
|
350
418
|
const expanded = expandable && this._expanded.has(`${section.key}\0${row.key}`);
|
|
351
419
|
const caret = expandable ? `${expanded ? '▾' : '▸'} ` : '';
|
|
352
420
|
if (elements.caretEl.textContent !== caret) elements.caretEl.textContent = caret;
|
|
353
|
-
|
|
421
|
+
elements.edit = row.value.edit ?? null;
|
|
422
|
+
elements.el.classList.toggle('pci-editable', !!elements.edit);
|
|
423
|
+
const tip = elements.edit ? EDIT_TIP : '';
|
|
424
|
+
if ((elements.valueEl.dataset.tip ?? '') !== tip) setTip(elements.valueEl, tip);
|
|
425
|
+
if (elements.editEl && !elements.edit) this._endEdit(elements);
|
|
426
|
+
// the text field being typed in is left alone until it is done with
|
|
427
|
+
if (elements.text !== text && !elements.editEl) {
|
|
354
428
|
elements.text = text;
|
|
355
429
|
elements.valueEl.lastChild.textContent = text;
|
|
356
430
|
}
|
|
@@ -523,6 +597,7 @@ class PropertyView {
|
|
|
523
597
|
|
|
524
598
|
if (!elements.codeEl) {
|
|
525
599
|
elements.codeEl = el('pre', 'pci-code');
|
|
600
|
+
this._byElement.set(elements.codeEl, elements);
|
|
526
601
|
elements.code = '';
|
|
527
602
|
section.rowsEl.insertBefore(elements.codeEl, elements.el.nextSibling);
|
|
528
603
|
}
|
|
@@ -550,9 +625,11 @@ class PropertyView {
|
|
|
550
625
|
el: el('div', 'pci-section'),
|
|
551
626
|
titleEl: el('div', 'pci-section-title'),
|
|
552
627
|
rowsEl: el('div', 'pci-rows'),
|
|
553
|
-
rows: new Map()
|
|
628
|
+
rows: new Map(),
|
|
629
|
+
section: null
|
|
554
630
|
};
|
|
555
631
|
elements.el.append(elements.titleEl, elements.rowsEl);
|
|
632
|
+
this._byElement.set(elements.titleEl, elements);
|
|
556
633
|
if (section.collapsed) this._collapsed.add(section.key);
|
|
557
634
|
elements.titleEl.addEventListener('click', () => {
|
|
558
635
|
if (this._collapsed.has(section.key)) this._collapsed.delete(section.key);
|
|
@@ -588,8 +665,12 @@ class PropertyView {
|
|
|
588
665
|
actionsSignature: '',
|
|
589
666
|
actions: null,
|
|
590
667
|
caretEl: el('span', 'pci-caret'),
|
|
591
|
-
select: null
|
|
668
|
+
select: null,
|
|
669
|
+
row: null,
|
|
670
|
+
edit: null,
|
|
671
|
+
editEl: null
|
|
592
672
|
};
|
|
673
|
+
this._byElement.set(elements.el, elements);
|
|
593
674
|
elements.valueEl.append(elements.caretEl, document.createTextNode(''));
|
|
594
675
|
elements.el.append(elements.labelEl, elements.valueEl);
|
|
595
676
|
// the whole row takes the click, so a choice can be made anywhere on it
|
|
@@ -598,6 +679,8 @@ class PropertyView {
|
|
|
598
679
|
});
|
|
599
680
|
elements.valueEl.addEventListener('pointerleave', () => this.onHover?.(null, null));
|
|
600
681
|
elements.el.addEventListener('click', (e) => {
|
|
682
|
+
// a click in the open text field is the field's own
|
|
683
|
+
if (elements.editEl) return;
|
|
601
684
|
const expandable = elements.el.classList.contains('pci-expandable');
|
|
602
685
|
const toggle = () => {
|
|
603
686
|
const key = `${section.key}\0${row.key}`;
|
|
@@ -606,8 +689,10 @@ class PropertyView {
|
|
|
606
689
|
this.refresh();
|
|
607
690
|
};
|
|
608
691
|
// the caret always opens; elsewhere a choice wins over a link, and a link over opening,
|
|
609
|
-
// which only the value reacts to
|
|
610
|
-
if (
|
|
692
|
+
// which only the value reacts to. An editable value opens its text field
|
|
693
|
+
if (elements.edit && elements.valueEl.contains(/** @type {Node} */ (e.target))) {
|
|
694
|
+
this._startEdit(elements);
|
|
695
|
+
} else if (expandable && e.target === elements.caretEl) {
|
|
611
696
|
toggle();
|
|
612
697
|
} else if (elements.select) {
|
|
613
698
|
elements.select();
|
|
@@ -623,6 +708,75 @@ class PropertyView {
|
|
|
623
708
|
section.rows.set(row.key, elements);
|
|
624
709
|
return elements;
|
|
625
710
|
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Opens the text field of an editable value. Enter hands the text to the edit and closes the
|
|
714
|
+
* field once the edit takes it, or marks the text as not taken; leaving the field does the
|
|
715
|
+
* same, and gives up on text that is not taken; Escape closes it without a change.
|
|
716
|
+
*
|
|
717
|
+
* @param {RowElements} elements - The row.
|
|
718
|
+
* @private
|
|
719
|
+
*/
|
|
720
|
+
_startEdit(elements) {
|
|
721
|
+
const start = elements.edit?.text;
|
|
722
|
+
if (start === undefined) return;
|
|
723
|
+
|
|
724
|
+
const input = /** @type {HTMLInputElement} */ (el('input', 'pci-edit'));
|
|
725
|
+
input.type = 'text';
|
|
726
|
+
input.spellcheck = false;
|
|
727
|
+
input.value = start;
|
|
728
|
+
elements.valueEl.lastChild.textContent = '';
|
|
729
|
+
elements.text = '';
|
|
730
|
+
elements.valueEl.appendChild(input);
|
|
731
|
+
elements.editEl = input;
|
|
732
|
+
elements.el.classList.add('pci-editing');
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* @param {boolean} commit - Whether to hand the text to the edit.
|
|
736
|
+
* @returns {boolean} Whether the field closed.
|
|
737
|
+
*/
|
|
738
|
+
const finish = (commit) => {
|
|
739
|
+
if (elements.editEl !== input) return true;
|
|
740
|
+
// an untouched field changes nothing, as its text is only what the value read when it opened
|
|
741
|
+
if (commit && input.value !== start && !elements.edit?.apply(input.value)) {
|
|
742
|
+
input.classList.add('pci-invalid');
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
this._endEdit(elements);
|
|
746
|
+
this.refresh();
|
|
747
|
+
return true;
|
|
748
|
+
};
|
|
749
|
+
input.addEventListener('keydown', (e) => {
|
|
750
|
+
if (e.key === 'Enter') {
|
|
751
|
+
e.preventDefault();
|
|
752
|
+
finish(true);
|
|
753
|
+
} else if (e.key === 'Escape') {
|
|
754
|
+
e.preventDefault();
|
|
755
|
+
e.stopPropagation();
|
|
756
|
+
finish(false);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
input.addEventListener('input', () => input.classList.remove('pci-invalid'));
|
|
760
|
+
input.addEventListener('blur', () => {
|
|
761
|
+
if (!finish(true)) finish(false);
|
|
762
|
+
});
|
|
763
|
+
input.focus();
|
|
764
|
+
input.select();
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Closes the text field of a value, which shows its text again on the next refresh.
|
|
769
|
+
*
|
|
770
|
+
* @param {RowElements} elements - The row.
|
|
771
|
+
* @private
|
|
772
|
+
*/
|
|
773
|
+
_endEdit(elements) {
|
|
774
|
+
const input = elements.editEl;
|
|
775
|
+
if (!input) return;
|
|
776
|
+
elements.editEl = null;
|
|
777
|
+
elements.el.classList.remove('pci-editing');
|
|
778
|
+
input.remove();
|
|
779
|
+
}
|
|
626
780
|
}
|
|
627
781
|
|
|
628
782
|
export { PropertyView };
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from 'playcanvas';
|
|
4
4
|
|
|
5
5
|
import { describeValue } from './describe.js';
|
|
6
|
-
import { attachmentsText, formatName, makeSection, passDisplayName, push, read, reflectRows } from './model.js';
|
|
6
|
+
import { attachmentsText, backlink, formatName, makeSection, passDisplayName, push, read, reflectRows } from './model.js';
|
|
7
7
|
|
|
8
8
|
/** @import { GraphicsDevice } from 'playcanvas' */
|
|
9
9
|
/** @import { RenderTarget } from 'playcanvas' */
|
|
@@ -141,11 +141,11 @@ function buildRenderTargetModel(rt, ctx) {
|
|
|
141
141
|
push(general, 'initialized', read(rt, 'initialized'));
|
|
142
142
|
|
|
143
143
|
const uses = frame?.usage.get(rt) ?? [];
|
|
144
|
-
push(general, 'used by', {
|
|
144
|
+
push(general, 'used by', backlink({
|
|
145
145
|
text: uses.length ? `${uses.length} pass${uses.length === 1 ? '' : 'es'} this frame` : 'no pass this frame',
|
|
146
146
|
cls: uses.length ? 'obj' : 'null',
|
|
147
147
|
items: uses.map(entry => ({ label: `#${entry.index}`, text: passDisplayName(entry.pass), cls: 'ref', target: entry.pass }))
|
|
148
|
-
});
|
|
148
|
+
}));
|
|
149
149
|
sections.push(general);
|
|
150
150
|
|
|
151
151
|
const attachments = makeSection('attachments', 'Attachments');
|
package/src/script-view.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Script, ScriptType } from 'playcanvas';
|
|
|
2
2
|
|
|
3
3
|
import { describeValue } from './describe.js';
|
|
4
4
|
import { nodeLabel } from './memory-view.js';
|
|
5
|
-
import { makeSection, push } from './model.js';
|
|
5
|
+
import { makeSection, makeUsageSection, push } from './model.js';
|
|
6
6
|
import { scriptInstanceRows } from './node-model.js';
|
|
7
7
|
|
|
8
8
|
/** @import { AppBase } from 'playcanvas' */
|
|
@@ -228,7 +228,8 @@ function scriptListRows(survey) {
|
|
|
228
228
|
* using it, each instance opening in place into its attributes, and its source.
|
|
229
229
|
*
|
|
230
230
|
* @param {Function} cls - The script class.
|
|
231
|
-
* @param {{ app: AppBase }} ctx - The app
|
|
231
|
+
* @param {{ app: AppBase, backlinks?: boolean }} ctx - The app, and whether to list the entities
|
|
232
|
+
* using the class, which a copy has no use for.
|
|
232
233
|
* @returns {PropertySection[]} The sections.
|
|
233
234
|
*/
|
|
234
235
|
function buildScriptModel(cls, ctx) {
|
|
@@ -257,8 +258,24 @@ function buildScriptModel(cls, ctx) {
|
|
|
257
258
|
});
|
|
258
259
|
}
|
|
259
260
|
sections.push(general);
|
|
261
|
+
if (ctx.backlinks !== false) sections.push(instancesSection(instances));
|
|
260
262
|
|
|
261
|
-
const
|
|
263
|
+
const source = scriptSource(cls, name);
|
|
264
|
+
const code = makeSection('source', 'Source');
|
|
265
|
+
const lines = source.split('\n').length;
|
|
266
|
+
push(code, 'source', { text: `${lines} line${lines === 1 ? '' : 's'}`, cls: 'num', code: source });
|
|
267
|
+
sections.push(code);
|
|
268
|
+
|
|
269
|
+
return sections;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @param {{ script: ScriptType|Script, entity: Entity }[]} instances - The instances of a script
|
|
274
|
+
* class, with the entities they are on.
|
|
275
|
+
* @returns {PropertySection} The section listing them, each opening in place into its attributes.
|
|
276
|
+
*/
|
|
277
|
+
function instancesSection(instances) {
|
|
278
|
+
const usage = makeUsageSection('instances', 'Used by');
|
|
262
279
|
const running = instances.filter(({ script, entity }) => isRunning(script, entity)).length;
|
|
263
280
|
push(usage, 'instances', {
|
|
264
281
|
text: instances.length ? `${instances.length} instance${instances.length === 1 ? '' : 's'}, ${running} running` : 'none',
|
|
@@ -274,15 +291,7 @@ function buildScriptModel(cls, ctx) {
|
|
|
274
291
|
if (instances.length > MAX_INSTANCES) {
|
|
275
292
|
usage.rows.push({ key: 'more', label: '', value: { text: `… ${instances.length - MAX_INSTANCES} more`, cls: 'null' }, depth: 1 });
|
|
276
293
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const source = scriptSource(cls, name);
|
|
280
|
-
const code = makeSection('source', 'Source');
|
|
281
|
-
const lines = source.split('\n').length;
|
|
282
|
-
push(code, 'source', { text: `${lines} line${lines === 1 ? '' : 's'}`, cls: 'num', code: source });
|
|
283
|
-
sections.push(code);
|
|
284
|
-
|
|
285
|
-
return sections;
|
|
294
|
+
return usage;
|
|
286
295
|
}
|
|
287
296
|
|
|
288
297
|
export { buildScriptModel, isScriptClass, scriptListRows, surveyScripts };
|