@kubohiroya/turbowarp-plus-editor-code-views 0.21.2 → 0.21.3

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.
@@ -0,0 +1,21 @@
1
+ /* SPDX-License-Identifier: MPL-2.0 */
2
+ .preview {
3
+ position: absolute;
4
+ /* Above the toolbox (40) and below the dragged block (50). */
5
+ z-index: 45;
6
+ display: grid;
7
+ place-items: center;
8
+ pointer-events: none;
9
+ -webkit-backdrop-filter: blur(4px);
10
+ backdrop-filter: blur(4px);
11
+ }
12
+
13
+ .preview::before {
14
+ content: "";
15
+ width: 3.5rem;
16
+ height: 3.5rem;
17
+ border: 2px solid white;
18
+ border-radius: 50%;
19
+ background: #a52834 url("./trash.svg") center / 1.75rem no-repeat;
20
+ box-shadow: 0 2px 6px rgb(0 0 0 / 25%);
21
+ }
@@ -0,0 +1,79 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ export function createPaletteDeletePreview(styles: Record<string, string>) {
3
+
4
+ const installed = new WeakSet();
5
+
6
+ const installPaletteDeletePreview = ScratchBlocks => {
7
+ const gesture = ScratchBlocks.Gesture?.prototype;
8
+ if (!gesture?.handleMove || !gesture.dispose || installed.has(gesture)) return;
9
+ installed.add(gesture);
10
+
11
+ const previews = new WeakMap();
12
+ const clear = current => {
13
+ previews.get(current)?.remove();
14
+ previews.delete(current);
15
+ };
16
+ const {handleMove, dispose} = gesture;
17
+ gesture.handleMove = function (event) {
18
+ const result = handleMove.call(this, event);
19
+ const dragger = this.blockDragger_;
20
+ // Reuse the dragger's decision, including deletability and competing connections.
21
+ if (!dragger?.wouldDeleteBlock_ || dragger.deleteArea_ !== ScratchBlocks.DELETE_AREA_TOOLBOX) {
22
+ clear(this);
23
+ return result;
24
+ }
25
+
26
+ const workspace = this.startWorkspace_;
27
+ // Addons can report DELETE_AREA_TOOLBOX for drop targets outside the palette.
28
+ const hitbox = workspace.deleteAreaToolbox_;
29
+ const {clientX, clientY} = event;
30
+ if (!hitbox || clientX < hitbox.left || clientX > hitbox.left + hitbox.width ||
31
+ clientY < hitbox.top || clientY > hitbox.top + hitbox.height) {
32
+ clear(this);
33
+ return result;
34
+ }
35
+ const toolbox = workspace.getToolbox()?.HtmlDiv;
36
+ const flyout = workspace.getFlyout()?.svgBackground_;
37
+ const container = workspace.getInjectionDiv();
38
+ if (!toolbox || !container || workspace.isMutator) {
39
+ clear(this);
40
+ return result;
41
+ }
42
+
43
+ // The hitbox extends offscreen. Use the visible toolbox and flyout for the overlay.
44
+ const bounds = container.getBoundingClientRect();
45
+ const menu = toolbox.getBoundingClientRect();
46
+ const blocks = toolbox.hasAttribute('data-horizontal-block-palette') ? menu : flyout?.getBoundingClientRect();
47
+ if (!blocks?.width || !blocks.height) {
48
+ clear(this);
49
+ return result;
50
+ }
51
+ const left = Math.max(bounds.left, Math.min(menu.left, blocks.left));
52
+ const top = Math.max(bounds.top, Math.min(menu.top, blocks.top));
53
+ const right = Math.min(bounds.right, Math.max(menu.right, blocks.right));
54
+ const bottom = Math.min(bounds.bottom, Math.max(menu.bottom, blocks.bottom));
55
+ if (right <= left || bottom <= top) {
56
+ clear(this);
57
+ return result;
58
+ }
59
+
60
+ let preview = previews.get(this);
61
+ if (!preview) {
62
+ preview = container.ownerDocument.createElement('div');
63
+ preview.className = styles.preview;
64
+ preview.dataset.paletteDeletePreview = '';
65
+ preview.setAttribute('aria-hidden', 'true');
66
+ container.appendChild(preview);
67
+ previews.set(this, preview);
68
+ }
69
+ preview.style.inset = `${top - bounds.top}px ${bounds.right - right}px ${bounds.bottom - bottom}px ${left - bounds.left}px`;
70
+ return result;
71
+ };
72
+ gesture.dispose = function (...args) {
73
+ clear(this);
74
+ return dispose.apply(this, args);
75
+ };
76
+ };
77
+
78
+ return {installPaletteDeletePreview};
79
+ }
@@ -0,0 +1,6 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="black" stroke-width="1.2" stroke-linejoin="round">
2
+ <!-- Matches the unpinned sprite-list control in turbowarp-plus-editor-workbench. -->
3
+ <path d="M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z"/>
4
+ <path d="m7.5 8.5-4 4"/>
5
+ <path d="M2 2l12 12" stroke-linecap="round"/>
6
+ </svg>
package/src/pin.svg ADDED
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="black" stroke-width="1.2" stroke-linejoin="round">
2
+ <!-- Matches the sprite-list pin in turbowarp-plus-editor-workbench. -->
3
+ <path d="M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z"/>
4
+ <path d="m7.5 8.5-4 4"/>
5
+ </svg>
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>
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",