@kubohiroya/turbowarp-plus-editor-code-views 0.21.2 → 0.22.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.
Files changed (52) hide show
  1. package/EDITOR-MIGRATION.md +5 -0
  2. package/README.ja.md +16 -1
  3. package/dist/code-pane.d.ts +7 -1
  4. package/dist/code-pane.js +45 -3
  5. package/dist/code-popout.d.ts +10 -0
  6. package/dist/code-popout.js +402 -0
  7. package/dist/context-menu-icons.d.ts +15 -0
  8. package/dist/context-menu-icons.js +204 -0
  9. package/dist/desktop-code.d.ts +11 -0
  10. package/dist/desktop-code.js +47 -0
  11. package/dist/horizontal-block-palette.d.ts +39 -0
  12. package/dist/horizontal-block-palette.js +774 -0
  13. package/dist/palette-delete-preview.d.ts +3 -0
  14. package/dist/palette-delete-preview.js +73 -0
  15. package/dist/script-arrows.js +106 -12
  16. package/dist/script-layout-view.js +122 -6
  17. package/dist/script-layout-workspace.js +7 -2
  18. package/dist/script-layout.d.ts +1 -1
  19. package/dist/script-layout.js +3 -3
  20. package/dist/script-projection.d.ts +8 -0
  21. package/dist/script-projection.js +10 -0
  22. package/dist/script-view-menu.d.ts +1 -0
  23. package/dist/script-view-menu.js +4 -2
  24. package/dist/serial-script-editor.d.ts +4 -0
  25. package/dist/serial-script-editor.js +43 -0
  26. package/dist/workspace-overview.js +67 -25
  27. package/dist/workspace.d.ts +1 -0
  28. package/dist/workspace.js +3 -2
  29. package/package.json +27 -3
  30. package/src/code-pane.ts +41 -3
  31. package/src/code-popout.tsx +399 -0
  32. package/src/context-menu-icons.css +14 -0
  33. package/src/context-menu-icons.ts +215 -0
  34. package/src/desktop-code.ts +45 -0
  35. package/src/horizontal-block-palette.css +111 -0
  36. package/src/horizontal-block-palette.ts +765 -0
  37. package/src/palette-delete-preview.css +21 -0
  38. package/src/palette-delete-preview.ts +79 -0
  39. package/src/pin-off.svg +6 -0
  40. package/src/pin.svg +5 -0
  41. package/src/script-arrows.ts +98 -12
  42. package/src/script-layout-view.ts +114 -6
  43. package/src/script-layout-workspace.ts +7 -2
  44. package/src/script-layout.ts +4 -3
  45. package/src/script-projection.ts +12 -0
  46. package/src/script-view-menu.ts +5 -2
  47. package/src/serial-script-editor.ts +41 -0
  48. package/src/styles.css +80 -5
  49. package/src/trash.svg +3 -0
  50. package/src/workspace-overview.ts +63 -22
  51. package/src/workspace.ts +3 -2
  52. package/tsconfig.json +87 -1
package/src/styles.css CHANGED
@@ -603,17 +603,19 @@
603
603
  stroke-opacity: 1;
604
604
  }
605
605
 
606
+ .tw-script-editor-menu-divider {
607
+ border-top: 1px solid var(--ui-black-transparent, rgb(0 0 0 / 15%));
608
+ margin-block-start: 4px;
609
+ }
610
+
606
611
  .tw-script-relation-script-highlight {
607
612
  fill: light-dark(#3373cc, #93c5fd);
608
613
  fill-opacity: 0.1;
609
- stroke: light-dark(#2563a8, #93c5fd);
610
- stroke-width: 2;
611
- vector-effect: non-scaling-stroke;
614
+ stroke: none;
612
615
  pointer-events: none;
613
616
  }
614
617
 
615
618
  .tw-script-relation-script-highlight[data-emphasis="source"] {
616
- stroke-width: 3;
617
619
  fill-opacity: 0.15;
618
620
  }
619
621
 
@@ -747,13 +749,48 @@
747
749
  display: none;
748
750
  }
749
751
 
752
+ .tw-script-fold-gutter {
753
+ position: absolute;
754
+ z-index: 4;
755
+ width: 28px;
756
+ overflow: hidden;
757
+ pointer-events: none;
758
+ }
759
+
760
+ .tw-script-fold-gutter[hidden] {
761
+ display: none;
762
+ }
763
+
764
+ .tw-script-fold-gutter > button {
765
+ position: absolute;
766
+ left: 2px;
767
+ width: 24px;
768
+ height: 24px;
769
+ padding: 0;
770
+ border: 0;
771
+ border-radius: 4px;
772
+ background: var(--ui-primary, Canvas);
773
+ color: var(--text-primary, CanvasText);
774
+ font: 14px/24px system-ui, sans-serif;
775
+ cursor: pointer;
776
+ pointer-events: auto;
777
+ }
778
+
779
+ .tw-script-fold-gutter > button:is(:hover, :focus-visible) {
780
+ background: var(--ui-tertiary, #e5e7eb);
781
+ outline: 2px solid var(--motion-primary, #4c97ff);
782
+ outline-offset: -2px;
783
+ }
784
+
750
785
  .blocklySvg[data-script-serial] {
751
786
  z-index: 2;
752
787
  background: transparent;
753
788
  pointer-events: none;
754
789
  }
755
790
 
756
- .blocklySvg[data-script-serial] :is(.blocklyMainBackground, .blocklyBlockCanvas, .blocklyBubbleCanvas) {
791
+ .blocklySvg[data-script-serial] :is(.blocklyMainBackground, .blocklyBlockCanvas, .blocklyBubbleCanvas, .blocklyFlyout,
792
+ .blocklyScrollbarVertical, .blocklyScrollbarHorizontal),
793
+ .injectionDiv:has(> [data-script-serial]) > .blocklyFlyout {
757
794
  visibility: hidden;
758
795
  }
759
796
 
@@ -778,6 +815,44 @@
778
815
  cursor: pointer;
779
816
  }
780
817
 
818
+ .tw-serial-script-editor {
819
+ position: fixed;
820
+ inset: 0;
821
+ box-sizing: border-box;
822
+ width: 100vw;
823
+ height: 100vh;
824
+ max-width: none;
825
+ max-height: none;
826
+ margin: 0;
827
+ padding: 1rem;
828
+ border: 0;
829
+ background: var(--ui-primary, Canvas);
830
+ color: var(--text-primary, CanvasText);
831
+ font: 0.9rem/1.4 system-ui, sans-serif;
832
+ }
833
+
834
+ .tw-serial-script-editor[open] {
835
+ display: flex;
836
+ flex-direction: column;
837
+ gap: 0.75rem;
838
+ }
839
+
840
+ .tw-serial-script-editor > h2 {
841
+ margin: 0;
842
+ font-size: 1.1rem;
843
+ }
844
+
845
+ .tw-serial-script-editor > [data-serial-script-editor] {
846
+ position: relative;
847
+ flex: 1;
848
+ min-height: 0;
849
+ }
850
+
851
+ .tw-serial-script-editor > button {
852
+ align-self: flex-end;
853
+ padding: 0.5rem 1.5rem;
854
+ }
855
+
781
856
  .tw-script-layout-dialog {
782
857
  box-sizing: border-box;
783
858
  width: min(44rem, calc(100% - 2rem));
package/src/trash.svg ADDED
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2
+ <path d="M3 6h18M9 6V3h6v3M5 6l1 15h12l1-15M10 10v7m4-7v7"/>
3
+ </svg>
@@ -1,3 +1,5 @@
1
+ import {getScriptProjection} from './script-projection.ts';
2
+
1
3
  type OverviewOptions = {
2
4
  workspace: any;
3
5
  ScratchBlocks: any;
@@ -44,23 +46,42 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
44
46
  function refreshShapes() {
45
47
  const retained = new Set<string>();
46
48
  const additions = document.createDocumentFragment();
47
- for (const block of workspace.getAllBlocks(false)) {
48
- const root = block.getSvgRoot() as SVGElement | null;
49
- if (!root || !canvas.contains(root) || root.closest('[data-tw-plus-hidden]')) continue;
50
- const source = root.querySelector(':scope > .blocklyPath');
51
- const data = source?.getAttribute('d');
52
- if (!data) continue;
53
- retained.add(block.id);
54
- let path = paths.get(block.id);
49
+ const paint = (id: string, data: string, fill: string, transform: string) => {
50
+ retained.add(id);
51
+ let path = paths.get(id);
55
52
  if (!path) {
56
53
  path = element('path');
57
- paths.set(block.id, path);
54
+ paths.set(id, path);
58
55
  additions.append(path);
59
56
  }
60
- const position = block.getRelativeToSurfaceXY();
61
57
  attribute(path, 'd', data);
62
- attribute(path, 'fill', source.getAttribute('fill') || block.getColour());
63
- attribute(path, 'transform', `translate(${position.x} ${position.y})${block.RTL ? ' scale(-1 1)' : ''}`);
58
+ attribute(path, 'fill', fill);
59
+ attribute(path, 'transform', transform);
60
+ };
61
+ const projection = getScriptProjection(workspace);
62
+ if (projection) {
63
+ const inverse = projection.svg.getScreenCTM()?.inverse();
64
+ if (inverse) for (const source of projection.svg.querySelectorAll<SVGPathElement>('.blocklyPath')) {
65
+ if (source.closest('[data-tw-plus-hidden]')) continue;
66
+ const id = source.closest('[data-id]')?.getAttribute('data-id');
67
+ const data = source.getAttribute('d');
68
+ const matrix = source.getScreenCTM();
69
+ if (!id || !data || !matrix) continue;
70
+ const transform = inverse.multiply(matrix);
71
+ paint(id, data, source.getAttribute('fill') || view.getComputedStyle(source).fill,
72
+ `matrix(${transform.a} ${transform.b} ${transform.c} ${transform.d} ${transform.e} ${transform.f})`);
73
+ }
74
+ } else {
75
+ for (const block of workspace.getAllBlocks(false)) {
76
+ const root = block.getSvgRoot() as SVGElement | null;
77
+ if (!root || !canvas.contains(root) || root.closest('[data-tw-plus-hidden]')) continue;
78
+ const source = root.querySelector(':scope > .blocklyPath');
79
+ const data = source?.getAttribute('d');
80
+ if (!data) continue;
81
+ const position = block.getRelativeToSurfaceXY();
82
+ paint(block.id, data, source.getAttribute('fill') || block.getColour(),
83
+ `translate(${position.x} ${position.y})${block.RTL ? ' scale(-1 1)' : ''}`);
84
+ }
64
85
  }
65
86
  for (const [id, path] of paths) if (!retained.has(id)) {path.remove(); paths.delete(id);}
66
87
  if (additions.childNodes.length) shapes.append(additions);
@@ -73,12 +94,17 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
73
94
  const metrics = workspace.isVisible() && workspace.getMetrics();
74
95
  if (!metrics || metrics.viewWidth <= 32 || metrics.viewHeight <= 32) {map.toggleAttribute('hidden', true); return;}
75
96
  const scale = workspace.scale;
76
- const x = metrics.viewLeft / scale, y = metrics.viewTop / scale;
77
- const width = metrics.viewWidth / scale, height = metrics.viewHeight / scale;
97
+ const projection = getScriptProjection(workspace);
98
+ const x = projection ? projection.surface.scrollLeft / scale : metrics.viewLeft / scale;
99
+ const y = projection ? projection.surface.scrollTop / scale : metrics.viewTop / scale;
100
+ const width = (projection ? projection.surface.clientWidth : metrics.viewWidth) / scale;
101
+ const height = (projection ? projection.surface.clientHeight : metrics.viewHeight) / scale;
78
102
  const content = metrics.contentWidth > 0 && metrics.contentHeight > 0;
79
- const area = content ? {x: metrics.contentLeft / scale, y: metrics.contentTop / scale,
103
+ const box = projection?.svg.viewBox.baseVal;
104
+ const area = box ? {x: box.x, y: box.y, width: Math.max(box.width, width), height: Math.max(box.height, height)} :
105
+ content ? {x: metrics.contentLeft / scale, y: metrics.contentTop / scale,
80
106
  width: metrics.contentWidth / scale, height: metrics.contentHeight / scale} : {x, y, width, height};
81
- if (!workspace.scrollbar && content) {
107
+ if (!projection && !workspace.scrollbar && content) {
82
108
  const right = Math.max(x + width, area.x + area.width), bottom = Math.max(y + height, area.y + area.height);
83
109
  area.x = Math.min(x, area.x); area.y = Math.min(y, area.y);
84
110
  area.width = right - area.x; area.height = bottom - area.y;
@@ -98,8 +124,8 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
98
124
  // All layout reads above precede writes. Identical values do not invalidate the editor's styles.
99
125
  if (needsShapes) refreshShapes();
100
126
  map.toggleAttribute('hidden', false);
101
- const box = `${area.x} ${area.y} ${area.width} ${area.height}`;
102
- attribute(map, 'viewBox', box); attribute(clip, 'viewBox', box);
127
+ const viewBox = `${area.x} ${area.y} ${area.width} ${area.height}`;
128
+ attribute(map, 'viewBox', viewBox); attribute(clip, 'viewBox', viewBox);
103
129
  for (const [name, value] of Object.entries(area)) attribute(clip, name, value);
104
130
  for (const [name, value] of Object.entries({x, y, width, height})) attribute(viewport, name, value);
105
131
  style(map, 'width', `${mapWidth}px`); style(map, 'height', `${mapHeight}px`);
@@ -130,10 +156,22 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
130
156
  const resize = new view.ResizeObserver(schedule);
131
157
  resize.observe(container);
132
158
  const events = new view.AbortController();
159
+ let projectedSVG: SVGSVGElement | undefined;
160
+ container.addEventListener('scriptprojectionchange', () => {
161
+ const next = getScriptProjection(workspace)?.svg;
162
+ needsShapes ||= next !== projectedSVG;
163
+ projectedSVG = next;
164
+ schedule();
165
+ }, {signal: events.signal});
133
166
  view.addEventListener('resize', schedule, {signal: events.signal});
134
167
  view.addEventListener('scroll', schedule, {signal: events.signal, passive: true});
135
168
 
136
169
  const moveView = (left: number, top: number) => {
170
+ const projection = getScriptProjection(workspace);
171
+ if (projection) {
172
+ projection.surface.scrollTo(left * workspace.scale, top * workspace.scale);
173
+ return;
174
+ }
137
175
  const metrics = workspace.getMetrics();
138
176
  if (!metrics || !workspace.scrollbar) return;
139
177
  const clamp = (value: number, maximum: number) => Math.max(0, Math.min(value, Math.max(0, maximum)));
@@ -146,12 +184,14 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
146
184
  const point = (event: PointerEvent, inverse: DOMMatrix) =>
147
185
  new view.DOMPoint(event.clientX, event.clientY).matrixTransform(inverse);
148
186
  map.addEventListener('pointerdown', event => {
149
- if (!event.isPrimary || event.button !== 0 || pointer || !workspace.scrollbar) return;
187
+ const projection = getScriptProjection(workspace);
188
+ if (!event.isPrimary || event.button !== 0 || pointer || (!projection && !workspace.scrollbar)) return;
150
189
  const matrix = map.getScreenCTM(), metrics = workspace.getMetrics();
151
190
  if (!matrix || !metrics) return;
152
191
  const inverse = matrix.inverse();
153
192
  pointer = {id: event.pointerId, x: event.clientX, y: event.clientY, start: point(event, inverse), inverse,
154
- left: metrics.viewLeft / workspace.scale, top: metrics.viewTop / workspace.scale,
193
+ left: projection ? projection.surface.scrollLeft / workspace.scale : metrics.viewLeft / workspace.scale,
194
+ top: projection ? projection.surface.scrollTop / workspace.scale : metrics.viewTop / workspace.scale,
155
195
  viewport: event.target === viewport, moved: false};
156
196
  map.setPointerCapture(event.pointerId);
157
197
  }, {signal: events.signal});
@@ -173,8 +213,9 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
173
213
  move(event);
174
214
  if (!pointer.moved) {
175
215
  const current = point(event, pointer.inverse), metrics = workspace.getMetrics();
176
- if (metrics) moveView(current.x - metrics.viewWidth / (2 * workspace.scale),
177
- current.y - metrics.viewHeight / (2 * workspace.scale));
216
+ const projection = getScriptProjection(workspace);
217
+ if (metrics) moveView(current.x - (projection ? projection.surface.clientWidth : metrics.viewWidth) / (2 * workspace.scale),
218
+ current.y - (projection ? projection.surface.clientHeight : metrics.viewHeight) / (2 * workspace.scale));
178
219
  ScratchBlocks.hideChaff(true);
179
220
  }
180
221
  }
package/src/workspace.ts CHANGED
@@ -222,7 +222,7 @@ function attachScriptVisibility({vm, blocks, workspace, homeDocument, onError})
222
222
  const labels = () => japanese() ? {fold: '折りたたみ', unfold: '折りたたみを解除', folded: '折りたたみ中'} :
223
223
  {fold: 'Fold', unfold: 'Unfold', folded: 'Folded'};
224
224
  const vmBlock = (id: string) => vm.editingTarget?.blocks._blocks[id];
225
- const isFolded = (block: StackBlock) => isHatBlock(block) && isFoldedDefinition(vmBlock(block.id));
225
+ const isFolded = (block: StackBlock) => isFoldedDefinition(vmBlock(block.id));
226
226
 
227
227
  let focus: {id: string; extras: Set<string>; onLost?: () => void} | undefined;
228
228
  // The GUI can attach the code area again; what an earlier attachment left on the workspace is not its own.
@@ -404,7 +404,7 @@ function attachScriptVisibility({vm, blocks, workspace, homeDocument, onError})
404
404
  /** Paint the folded scripts of a read-only workspace, such as the preview of a code view. */
405
405
  function paintPreviewFolds(blocks, preview, target, label: string) {
406
406
  for (const top of preview.getTopBlocks(false) as StackBlock[]) {
407
- paintFold(top, isHatBlock(top) && isFoldedDefinition(target.blocks._blocks[top.id]), label);
407
+ paintFold(top, isFoldedDefinition(target.blocks._blocks[top.id]), label);
408
408
  }
409
409
  }
410
410
 
@@ -1008,6 +1008,7 @@ function attachProcedureEditor({vm, blocks, workspace, options, onError, homeDoc
1008
1008
 
1009
1009
  return {
1010
1010
  workspace: editor,
1011
+ flush() {blocks.Events.fireNow_();},
1011
1012
  showBlock(id: string) {
1012
1013
  pendingBlock = id;
1013
1014
  reveal();
package/tsconfig.json CHANGED
@@ -14,7 +14,93 @@
14
14
  "declaration": true,
15
15
  "rootDir": "src",
16
16
  "outDir": "dist",
17
- "rewriteRelativeImportExtensions": true
17
+ "rewriteRelativeImportExtensions": true,
18
+ "paths": {
19
+ "@kubohiroya/turbowarp-plus-editor-code-views": [
20
+ "./src/index.ts"
21
+ ],
22
+ "@kubohiroya/turbowarp-plus-editor-code-views/code-extensions": [
23
+ "./src/code-extensions.ts"
24
+ ],
25
+ "@kubohiroya/turbowarp-plus-editor-code-views/procedure-editor": [
26
+ "./src/procedure-editor.ts"
27
+ ],
28
+ "@kubohiroya/turbowarp-plus-editor-code-views/variable-references": [
29
+ "./src/variable-references.ts"
30
+ ],
31
+ "@kubohiroya/turbowarp-plus-editor-code-views/variable-merge": [
32
+ "./src/variable-merge.ts"
33
+ ],
34
+ "@kubohiroya/turbowarp-plus-editor-code-views/target-combobox": [
35
+ "./src/target-combobox.tsx"
36
+ ],
37
+ "@kubohiroya/turbowarp-plus-editor-code-views/sprite-code-windows": [
38
+ "./src/sprite-code-windows.tsx"
39
+ ],
40
+ "@kubohiroya/turbowarp-plus-editor-code-views/detached-block-palette": [
41
+ "./src/detached-block-palette.ts"
42
+ ],
43
+ "@kubohiroya/turbowarp-plus-editor-code-views/palette-category-reorder": [
44
+ "./src/palette-category-reorder.ts"
45
+ ],
46
+ "@kubohiroya/turbowarp-plus-editor-code-views/palette-category-search": [
47
+ "./src/palette-category-search.ts"
48
+ ],
49
+ "@kubohiroya/turbowarp-plus-editor-code-views/palette-dropdown-resize": [
50
+ "./src/palette-dropdown-resize.ts"
51
+ ],
52
+ "@kubohiroya/turbowarp-plus-editor-code-views/palette-category-groups": [
53
+ "./src/palette-category-groups.ts"
54
+ ],
55
+ "@kubohiroya/turbowarp-plus-editor-code-views/palette-category-visibility": [
56
+ "./src/palette-category-visibility.ts"
57
+ ],
58
+ "@kubohiroya/turbowarp-plus-editor-code-views/palette-visibility-dialog": [
59
+ "./src/palette-visibility-dialog.tsx"
60
+ ],
61
+ "@kubohiroya/turbowarp-plus-editor-code-views/block-argument-text": [
62
+ "./src/block-argument-text.ts"
63
+ ],
64
+ "@kubohiroya/turbowarp-plus-editor-code-views/block-number-input": [
65
+ "./src/block-number-input.ts"
66
+ ],
67
+ "@kubohiroya/turbowarp-plus-editor-code-views/clean-up-comments": [
68
+ "./src/clean-up-comments.ts"
69
+ ],
70
+ "@kubohiroya/turbowarp-plus-editor-code-views/sprite-copy-notice": [
71
+ "./src/sprite-copy-notice.ts"
72
+ ],
73
+ "@kubohiroya/turbowarp-plus-editor-code-views/script-layout": [
74
+ "./src/script-layout-view.ts"
75
+ ],
76
+ "@kubohiroya/turbowarp-plus-editor-code-views/target-undo-history": [
77
+ "./src/target-undo-history.ts"
78
+ ],
79
+ "@kubohiroya/turbowarp-plus-editor-code-views/sprite-restore-history": [
80
+ "./src/sprite-restore-history.ts"
81
+ ],
82
+ "@kubohiroya/turbowarp-plus-editor-code-views/asset-edit-session": [
83
+ "./src/asset-edit-session.ts"
84
+ ],
85
+ "@kubohiroya/turbowarp-plus-editor-code-views/dockview-unsaved": [
86
+ "./src/dockview-unsaved.ts"
87
+ ],
88
+ "@kubohiroya/turbowarp-plus-editor-code-views/horizontal-block-palette": [
89
+ "./src/horizontal-block-palette.ts"
90
+ ],
91
+ "@kubohiroya/turbowarp-plus-editor-code-views/context-menu-icons": [
92
+ "./src/context-menu-icons.ts"
93
+ ],
94
+ "@kubohiroya/turbowarp-plus-editor-code-views/palette-delete-preview": [
95
+ "./src/palette-delete-preview.ts"
96
+ ],
97
+ "@kubohiroya/turbowarp-plus-editor-code-views/code-popout": [
98
+ "./src/code-popout.tsx"
99
+ ],
100
+ "@kubohiroya/turbowarp-plus-editor-code-views/desktop-code": [
101
+ "./src/desktop-code.ts"
102
+ ]
103
+ }
18
104
  },
19
105
  "include": [
20
106
  "src/**/*.ts",