@kubohiroya/turbowarp-plus-editor-code-views 0.26.4 → 0.26.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +25 -5
- package/dist/workspace.js +6 -1
- package/package.json +5 -5
- package/src/index.ts +22 -4
- package/src/workspace.ts +6 -1
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ export function createCodeSession({ vm, workspace, ScratchBlocks, document, loca
|
|
|
53
53
|
const histories = new Map();
|
|
54
54
|
const views = new Set();
|
|
55
55
|
const dirty = new Set();
|
|
56
|
+
const externalDirty = new Set();
|
|
56
57
|
const thumbnails = new WeakMap();
|
|
57
58
|
let catalog = [];
|
|
58
59
|
let activeView;
|
|
@@ -158,11 +159,30 @@ export function createCodeSession({ vm, workspace, ScratchBlocks, document, loca
|
|
|
158
159
|
updateRelations();
|
|
159
160
|
}
|
|
160
161
|
function flushParent() {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
const targets = new Set([...dirty, ...externalDirty]);
|
|
163
|
+
for (const target of targets) {
|
|
164
|
+
if (exists(target) && histories.get(target)?.commit()) {
|
|
165
|
+
// Parent workspace events already drew the edit. Direct VM edits also need that view refreshed.
|
|
166
|
+
publish(target, null, externalDirty.has(target) && !dirty.has(target));
|
|
167
|
+
}
|
|
164
168
|
}
|
|
165
169
|
dirty.clear();
|
|
170
|
+
externalDirty.clear();
|
|
171
|
+
}
|
|
172
|
+
function projectChanged() {
|
|
173
|
+
if (disposed)
|
|
174
|
+
return;
|
|
175
|
+
updateRelations();
|
|
176
|
+
// Function creation and single-script editors can change the VM without parent Blockly events.
|
|
177
|
+
// Wait for the whole synchronous edit before comparing snapshots; normal edits commit themselves.
|
|
178
|
+
const pending = externalDirty.size > 0;
|
|
179
|
+
for (const target of histories.keys())
|
|
180
|
+
externalDirty.add(target);
|
|
181
|
+
if (!pending && externalDirty.size)
|
|
182
|
+
queueMicrotask(() => {
|
|
183
|
+
if (!disposed)
|
|
184
|
+
flushParent();
|
|
185
|
+
});
|
|
166
186
|
}
|
|
167
187
|
function observeParent(event) {
|
|
168
188
|
if (projecting || switchingWorkspace || disposed || dropJob?.running)
|
|
@@ -750,7 +770,7 @@ export function createCodeSession({ vm, workspace, ScratchBlocks, document, loca
|
|
|
750
770
|
vm.on('workspaceUpdate', flushWorkspaceProjection);
|
|
751
771
|
vm.on('EXTENSION_ADDED', extensionsUpdated);
|
|
752
772
|
vm.on('BLOCKSINFO_UPDATE', extensionsUpdated);
|
|
753
|
-
vm.runtime.on?.('PROJECT_CHANGED',
|
|
773
|
+
vm.runtime.on?.('PROJECT_CHANGED', projectChanged);
|
|
754
774
|
return { attach, flush, setCanDuplicate(available) {
|
|
755
775
|
if (available === canDuplicate)
|
|
756
776
|
return;
|
|
@@ -777,7 +797,7 @@ export function createCodeSession({ vm, workspace, ScratchBlocks, document, loca
|
|
|
777
797
|
parent.removeEventListener('focus', parentFocus);
|
|
778
798
|
vm.removeListener('targetsUpdate', targetsUpdated);
|
|
779
799
|
vm.removeListener('workspaceUpdate', flushWorkspaceProjection);
|
|
780
|
-
vm.runtime.removeListener?.('PROJECT_CHANGED',
|
|
800
|
+
vm.runtime.removeListener?.('PROJECT_CHANGED', projectChanged);
|
|
781
801
|
vm.removeListener('EXTERNAL_BLOCKS_RELOADED', externalBlocksReloaded);
|
|
782
802
|
vm.removeListener('EXTENSION_ADDED', extensionsUpdated);
|
|
783
803
|
vm.removeListener('BLOCKSINFO_UPDATE', extensionsUpdated);
|
package/dist/workspace.js
CHANGED
|
@@ -421,13 +421,18 @@ export function attachCodeWorkspace({ vm, ScratchBlocks: blocks, workspace, opti
|
|
|
421
421
|
frontView.presentation = presentation;
|
|
422
422
|
}
|
|
423
423
|
let parentFrame = null;
|
|
424
|
+
const parentTargets = new Set();
|
|
424
425
|
// Show edits made in a function editor in the code area when it displays the same target.
|
|
425
426
|
function refreshParent(target) {
|
|
427
|
+
parentTargets.add(target);
|
|
426
428
|
if (parentFrame !== null)
|
|
427
429
|
return;
|
|
428
430
|
parentFrame = requestAnimationFrame(() => {
|
|
429
431
|
parentFrame = null;
|
|
430
|
-
|
|
432
|
+
const target = vm.editingTarget;
|
|
433
|
+
const pending = parentTargets.has(target);
|
|
434
|
+
parentTargets.clear();
|
|
435
|
+
if (!pending || vm.runtime.getTargetById(target?.id) !== target)
|
|
431
436
|
return;
|
|
432
437
|
withoutEvents(blocks, () => vm.emit('workspaceUpdate', { xml: workspaceXML(vm, target) }));
|
|
433
438
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-code-views",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.6",
|
|
4
4
|
"description": "Code views for TurboWarp Plus Editor: code in tabs and windows, the detached block palette, script layout and block field editing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -152,15 +152,15 @@
|
|
|
152
152
|
"matter-js": "0.20.0"
|
|
153
153
|
},
|
|
154
154
|
"peerDependencies": {
|
|
155
|
-
"@kubohiroya/turbowarp-extension-security-dialog": ">=0.9.0 <0.10.0 || 0.10.0 || 0.13.0 || 0.13.1",
|
|
155
|
+
"@kubohiroya/turbowarp-extension-security-dialog": ">=0.9.0 <0.10.0 || 0.10.0 || 0.13.0 || 0.13.1 || 0.14.2",
|
|
156
156
|
"@kubohiroya/turbowarp-plus-editor-windows": ">=0.2.0 <0.3.0",
|
|
157
157
|
"react": ">=16.14",
|
|
158
158
|
"react-dom": ">=16.14"
|
|
159
159
|
},
|
|
160
160
|
"devDependencies": {
|
|
161
|
-
"@kubohiroya/turbowarp-extension-security-dialog": "0.
|
|
162
|
-
"@kubohiroya/turbowarp-plus-editor-test-runtime": "0.3.
|
|
163
|
-
"@kubohiroya/turbowarp-plus-editor-windows": "0.2.
|
|
161
|
+
"@kubohiroya/turbowarp-extension-security-dialog": "0.14.2",
|
|
162
|
+
"@kubohiroya/turbowarp-plus-editor-test-runtime": "0.3.3",
|
|
163
|
+
"@kubohiroya/turbowarp-plus-editor-windows": "0.2.3",
|
|
164
164
|
"@playwright/test": "1.64.1",
|
|
165
165
|
"@types/matter-js": "0.20.2",
|
|
166
166
|
"@types/react": "18.3.31",
|
package/src/index.ts
CHANGED
|
@@ -75,6 +75,7 @@ export function createCodeSession({vm, workspace, ScratchBlocks, document, local
|
|
|
75
75
|
};
|
|
76
76
|
const views = new Set<CodeView>();
|
|
77
77
|
const dirty = new Set();
|
|
78
|
+
const externalDirty = new Set();
|
|
78
79
|
const thumbnails = new WeakMap();
|
|
79
80
|
let catalog = [];
|
|
80
81
|
let activeView;
|
|
@@ -175,10 +176,27 @@ export function createCodeSession({vm, workspace, ScratchBlocks, document, local
|
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
function flushParent() {
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
const targets = new Set([...dirty, ...externalDirty]);
|
|
180
|
+
for (const target of targets) {
|
|
181
|
+
if (exists(target) && histories.get(target)?.commit()) {
|
|
182
|
+
// Parent workspace events already drew the edit. Direct VM edits also need that view refreshed.
|
|
183
|
+
publish(target, null, externalDirty.has(target) && !dirty.has(target));
|
|
184
|
+
}
|
|
180
185
|
}
|
|
181
186
|
dirty.clear();
|
|
187
|
+
externalDirty.clear();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function projectChanged() {
|
|
191
|
+
if (disposed) return;
|
|
192
|
+
updateRelations();
|
|
193
|
+
// Function creation and single-script editors can change the VM without parent Blockly events.
|
|
194
|
+
// Wait for the whole synchronous edit before comparing snapshots; normal edits commit themselves.
|
|
195
|
+
const pending = externalDirty.size > 0;
|
|
196
|
+
for (const target of histories.keys()) externalDirty.add(target);
|
|
197
|
+
if (!pending && externalDirty.size) queueMicrotask(() => {
|
|
198
|
+
if (!disposed) flushParent();
|
|
199
|
+
});
|
|
182
200
|
}
|
|
183
201
|
|
|
184
202
|
function observeParent(event) {
|
|
@@ -700,7 +718,7 @@ export function createCodeSession({vm, workspace, ScratchBlocks, document, local
|
|
|
700
718
|
vm.on('workspaceUpdate', flushWorkspaceProjection);
|
|
701
719
|
vm.on('EXTENSION_ADDED', extensionsUpdated);
|
|
702
720
|
vm.on('BLOCKSINFO_UPDATE', extensionsUpdated);
|
|
703
|
-
vm.runtime.on?.('PROJECT_CHANGED',
|
|
721
|
+
vm.runtime.on?.('PROJECT_CHANGED', projectChanged);
|
|
704
722
|
|
|
705
723
|
return {attach, flush, setCanDuplicate(available) {
|
|
706
724
|
if (available === canDuplicate) return;
|
|
@@ -723,7 +741,7 @@ export function createCodeSession({vm, workspace, ScratchBlocks, document, local
|
|
|
723
741
|
parent.removeEventListener('focus', parentFocus);
|
|
724
742
|
vm.removeListener('targetsUpdate', targetsUpdated);
|
|
725
743
|
vm.removeListener('workspaceUpdate', flushWorkspaceProjection);
|
|
726
|
-
vm.runtime.removeListener?.('PROJECT_CHANGED',
|
|
744
|
+
vm.runtime.removeListener?.('PROJECT_CHANGED', projectChanged);
|
|
727
745
|
vm.removeListener('EXTERNAL_BLOCKS_RELOADED', externalBlocksReloaded);
|
|
728
746
|
vm.removeListener('EXTENSION_ADDED', extensionsUpdated);
|
|
729
747
|
vm.removeListener('BLOCKSINFO_UPDATE', extensionsUpdated);
|
package/src/workspace.ts
CHANGED
|
@@ -463,12 +463,17 @@ export function attachCodeWorkspace({vm, ScratchBlocks: blocks, workspace, optio
|
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
let parentFrame = null;
|
|
466
|
+
const parentTargets = new Set();
|
|
466
467
|
// Show edits made in a function editor in the code area when it displays the same target.
|
|
467
468
|
function refreshParent(target) {
|
|
469
|
+
parentTargets.add(target);
|
|
468
470
|
if (parentFrame !== null) return;
|
|
469
471
|
parentFrame = requestAnimationFrame(() => {
|
|
470
472
|
parentFrame = null;
|
|
471
|
-
|
|
473
|
+
const target = vm.editingTarget;
|
|
474
|
+
const pending = parentTargets.has(target);
|
|
475
|
+
parentTargets.clear();
|
|
476
|
+
if (!pending || vm.runtime.getTargetById(target?.id) !== target) return;
|
|
472
477
|
withoutEvents(blocks, () => vm.emit('workspaceUpdate', {xml: workspaceXML(vm, target)}));
|
|
473
478
|
});
|
|
474
479
|
}
|