@mcpview/compose 0.12.0 → 0.13.1
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/CHANGELOG.md +22 -0
- package/README.md +104 -1
- package/esm/_dnt.polyfills.d.ts +49 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +36 -0
- package/esm/src/code-mode/board.d.ts +21 -1
- package/esm/src/code-mode/board.d.ts.map +1 -1
- package/esm/src/code-mode/board.js +76 -2
- package/esm/src/code-mode/chain.d.ts +2 -0
- package/esm/src/code-mode/chain.d.ts.map +1 -1
- package/esm/src/code-mode/chain.js +34 -8
- package/esm/src/code-mode/connections.d.ts +1 -0
- package/esm/src/code-mode/connections.d.ts.map +1 -1
- package/esm/src/code-mode/connections.js +1 -0
- package/esm/src/code-mode/layout-publisher.d.ts +69 -0
- package/esm/src/code-mode/layout-publisher.d.ts.map +1 -0
- package/esm/src/code-mode/layout-publisher.js +85 -0
- package/esm/src/code-mode/layout-runs.d.ts +35 -0
- package/esm/src/code-mode/layout-runs.d.ts.map +1 -0
- package/esm/src/code-mode/layout-runs.js +130 -0
- package/esm/src/code-mode/layout.d.ts +20 -0
- package/esm/src/code-mode/layout.d.ts.map +1 -0
- package/esm/src/code-mode/layout.js +54 -0
- package/esm/src/code-mode/mod.d.ts +1 -0
- package/esm/src/code-mode/mod.d.ts.map +1 -1
- package/esm/src/code-mode/mod.js +1 -0
- package/esm/src/code-mode/panel-contexts.d.ts +25 -0
- package/esm/src/code-mode/panel-contexts.d.ts.map +1 -0
- package/esm/src/code-mode/panel-contexts.js +115 -0
- package/esm/src/code-mode/providers.d.ts +3 -0
- package/esm/src/code-mode/providers.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.js +2 -1
- package/esm/src/code-mode/sync.d.ts +11 -0
- package/esm/src/code-mode/sync.d.ts.map +1 -0
- package/esm/src/code-mode/sync.js +42 -0
- package/esm/src/code-mode/tool.d.ts +1 -1
- package/esm/src/code-mode/tool.d.ts.map +1 -1
- package/esm/src/code-mode/tool.js +12 -0
- package/esm/src/core/collector/collector.d.ts +2 -1
- package/esm/src/core/collector/collector.d.ts.map +1 -1
- package/esm/src/core/collector/collector.js +6 -0
- package/esm/src/core/types/resources.d.ts +4 -0
- package/esm/src/core/types/resources.d.ts.map +1 -1
- package/esm/src/core/types/resources.js +10 -1
- package/esm/src/host/renderer/css/base.d.ts.map +1 -1
- package/esm/src/host/renderer/css/base.js +3 -0
- package/esm/src/host/renderer/css/layouts.d.ts.map +1 -1
- package/esm/src/host/renderer/css/layouts.js +17 -14
- package/esm/src/host/renderer/css/panel-controls.d.ts +3 -0
- package/esm/src/host/renderer/css/panel-controls.d.ts.map +1 -0
- package/esm/src/host/renderer/css/panel-controls.js +89 -0
- package/esm/src/host/renderer/html-generator.d.ts.map +1 -1
- package/esm/src/host/renderer/html-generator.js +38 -42
- package/esm/src/host/renderer/js/card-height.d.ts +3 -0
- package/esm/src/host/renderer/js/card-height.d.ts.map +1 -0
- package/esm/src/host/renderer/js/card-height.js +58 -0
- package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/esm/src/host/renderer/js/event-bus.js +32 -12
- package/esm/src/host/renderer/panel-controls.d.ts +30 -0
- package/esm/src/host/renderer/panel-controls.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-controls.js +6 -0
- package/esm/src/host/renderer/panel-movement.d.ts +8 -0
- package/esm/src/host/renderer/panel-movement.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-movement.js +396 -0
- package/esm/src/host/renderer/panel-reflow.d.ts +17 -0
- package/esm/src/host/renderer/panel-reflow.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-reflow.js +342 -0
- package/esm/src/host/renderer/panel-resizing.d.ts +11 -0
- package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-resizing.js +375 -0
- package/esm/src/host/renderer/panel-snapshot.d.ts +11 -0
- package/esm/src/host/renderer/panel-snapshot.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-snapshot.js +65 -0
- package/esm/src/runtime/compose.d.ts.map +1 -1
- package/esm/src/runtime/compose.js +3 -0
- package/esm/src/runtime/manifest.d.ts.map +1 -1
- package/esm/src/runtime/manifest.js +4 -0
- package/esm/src/runtime/types.d.ts +2 -0
- package/esm/src/runtime/types.d.ts.map +1 -1
- package/esm/src/sdk/mcp-sdk.d.ts +2 -1
- package/esm/src/sdk/mcp-sdk.d.ts.map +1 -1
- package/esm/src/sdk/mcp-sdk.js +2 -2
- package/esm/src/version.d.ts +1 -1
- package/esm/src/version.js +1 -1
- package/package.json +9 -1
- package/script/_dnt.polyfills.d.ts +49 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +36 -0
- package/script/src/code-mode/board.d.ts +21 -1
- package/script/src/code-mode/board.d.ts.map +1 -1
- package/script/src/code-mode/board.js +87 -3
- package/script/src/code-mode/chain.d.ts +2 -0
- package/script/src/code-mode/chain.d.ts.map +1 -1
- package/script/src/code-mode/chain.js +34 -8
- package/script/src/code-mode/connections.d.ts +1 -0
- package/script/src/code-mode/connections.d.ts.map +1 -1
- package/script/src/code-mode/connections.js +1 -0
- package/script/src/code-mode/layout-publisher.d.ts +69 -0
- package/script/src/code-mode/layout-publisher.d.ts.map +1 -0
- package/script/src/code-mode/layout-publisher.js +88 -0
- package/script/src/code-mode/layout-runs.d.ts +35 -0
- package/script/src/code-mode/layout-runs.d.ts.map +1 -0
- package/script/src/code-mode/layout-runs.js +134 -0
- package/script/src/code-mode/layout.d.ts +20 -0
- package/script/src/code-mode/layout.d.ts.map +1 -0
- package/script/src/code-mode/layout.js +57 -0
- package/script/src/code-mode/mod.d.ts +1 -0
- package/script/src/code-mode/mod.d.ts.map +1 -1
- package/script/src/code-mode/mod.js +6 -1
- package/script/src/code-mode/panel-contexts.d.ts +25 -0
- package/script/src/code-mode/panel-contexts.d.ts.map +1 -0
- package/script/src/code-mode/panel-contexts.js +118 -0
- package/script/src/code-mode/providers.d.ts +3 -0
- package/script/src/code-mode/providers.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.js +2 -1
- package/script/src/code-mode/sync.d.ts +11 -0
- package/script/src/code-mode/sync.d.ts.map +1 -0
- package/script/src/code-mode/sync.js +51 -0
- package/script/src/code-mode/tool.d.ts +1 -1
- package/script/src/code-mode/tool.d.ts.map +1 -1
- package/script/src/code-mode/tool.js +12 -0
- package/script/src/core/collector/collector.d.ts +2 -1
- package/script/src/core/collector/collector.d.ts.map +1 -1
- package/script/src/core/collector/collector.js +6 -0
- package/script/src/core/types/resources.d.ts +4 -0
- package/script/src/core/types/resources.d.ts.map +1 -1
- package/script/src/core/types/resources.js +11 -0
- package/script/src/host/renderer/css/base.d.ts.map +1 -1
- package/script/src/host/renderer/css/base.js +3 -0
- package/script/src/host/renderer/css/layouts.d.ts.map +1 -1
- package/script/src/host/renderer/css/layouts.js +17 -14
- package/script/src/host/renderer/css/panel-controls.d.ts +3 -0
- package/script/src/host/renderer/css/panel-controls.d.ts.map +1 -0
- package/script/src/host/renderer/css/panel-controls.js +92 -0
- package/script/src/host/renderer/html-generator.d.ts.map +1 -1
- package/script/src/host/renderer/html-generator.js +38 -42
- package/script/src/host/renderer/js/card-height.d.ts +3 -0
- package/script/src/host/renderer/js/card-height.d.ts.map +1 -0
- package/script/src/host/renderer/js/card-height.js +61 -0
- package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/script/src/host/renderer/js/event-bus.js +32 -12
- package/script/src/host/renderer/panel-controls.d.ts +30 -0
- package/script/src/host/renderer/panel-controls.d.ts.map +1 -0
- package/script/src/host/renderer/panel-controls.js +14 -0
- package/script/src/host/renderer/panel-movement.d.ts +8 -0
- package/script/src/host/renderer/panel-movement.d.ts.map +1 -0
- package/script/src/host/renderer/panel-movement.js +399 -0
- package/script/src/host/renderer/panel-reflow.d.ts +17 -0
- package/script/src/host/renderer/panel-reflow.d.ts.map +1 -0
- package/script/src/host/renderer/panel-reflow.js +345 -0
- package/script/src/host/renderer/panel-resizing.d.ts +11 -0
- package/script/src/host/renderer/panel-resizing.d.ts.map +1 -0
- package/script/src/host/renderer/panel-resizing.js +378 -0
- package/script/src/host/renderer/panel-snapshot.d.ts +11 -0
- package/script/src/host/renderer/panel-snapshot.d.ts.map +1 -0
- package/script/src/host/renderer/panel-snapshot.js +69 -0
- package/script/src/runtime/compose.d.ts.map +1 -1
- package/script/src/runtime/compose.js +3 -0
- package/script/src/runtime/manifest.d.ts.map +1 -1
- package/script/src/runtime/manifest.js +4 -0
- package/script/src/runtime/types.d.ts +2 -0
- package/script/src/runtime/types.d.ts.map +1 -1
- package/script/src/sdk/mcp-sdk.d.ts +2 -1
- package/script/src/sdk/mcp-sdk.d.ts.map +1 -1
- package/script/src/sdk/mcp-sdk.js +2 -2
- package/script/src/version.d.ts +1 -1
- package/script/src/version.js +1 -1
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installPanelMovement = installPanelMovement;
|
|
4
|
+
/**
|
|
5
|
+
* Wire the grips on a Compose board. The standalone host embeds this function
|
|
6
|
+
* as JavaScript, so its implementation must not depend on module-level values.
|
|
7
|
+
* @param {HTMLElement} container
|
|
8
|
+
* @param {AbortSignal} [signal]
|
|
9
|
+
*/
|
|
10
|
+
function installPanelMovement(container, signal) {
|
|
11
|
+
if (signal?.aborted || container.hasAttribute("data-compose-movement-ready"))
|
|
12
|
+
return;
|
|
13
|
+
const panels = Array.from(
|
|
14
|
+
/** @type {NodeListOf<HTMLElement>} */ (container.querySelectorAll(":scope > [data-compose-panel]")));
|
|
15
|
+
if (panels.length < 2) {
|
|
16
|
+
for (const panel of panels) {
|
|
17
|
+
const grip =
|
|
18
|
+
/** @type {HTMLButtonElement | null} */ (panel.querySelector("[data-compose-grip]"));
|
|
19
|
+
if (grip)
|
|
20
|
+
grip.hidden = true;
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
container.setAttribute("data-compose-movement-ready", "");
|
|
25
|
+
const doc = container.ownerDocument;
|
|
26
|
+
const status = doc.createElement("span");
|
|
27
|
+
status.setAttribute("role", "status");
|
|
28
|
+
status.style.cssText =
|
|
29
|
+
"position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)";
|
|
30
|
+
container.append(status);
|
|
31
|
+
const preview = doc.createElement("span");
|
|
32
|
+
preview.setAttribute("data-compose-drop-preview", "");
|
|
33
|
+
preview.setAttribute("aria-hidden", "true");
|
|
34
|
+
/** @type {Map<HTMLElement, HTMLButtonElement>} */
|
|
35
|
+
const grips = new Map();
|
|
36
|
+
const namedAreas = panels.every((panel) => Boolean(panel.dataset.area));
|
|
37
|
+
/** @param {HTMLElement} panel */
|
|
38
|
+
const label = (panel) => panel.dataset.panelLabel || "panel";
|
|
39
|
+
/** @type {HTMLElement | undefined} */
|
|
40
|
+
let selected;
|
|
41
|
+
/** @type {HTMLElement | undefined} */
|
|
42
|
+
let target;
|
|
43
|
+
/** @typedef {{beside: HTMLElement, side: "left" | "right" | "below"}} FreePlace */
|
|
44
|
+
/** @type {FreePlace | undefined} */
|
|
45
|
+
let free;
|
|
46
|
+
/** @type {FreePlace | undefined} */
|
|
47
|
+
let attempted;
|
|
48
|
+
/** @type {ReturnType<typeof measureSlots> | undefined} */
|
|
49
|
+
let slots;
|
|
50
|
+
/** @type {{panel: HTMLElement, grip: HTMLButtonElement, id: number, x: number, y: number, dragged: boolean} | undefined} */
|
|
51
|
+
let press;
|
|
52
|
+
let suppressClick = false;
|
|
53
|
+
/** @param {HTMLElement} [panel] */
|
|
54
|
+
function select(panel) {
|
|
55
|
+
selected?.removeAttribute("data-compose-moving");
|
|
56
|
+
if (selected)
|
|
57
|
+
grips.get(selected)?.setAttribute("aria-pressed", "false");
|
|
58
|
+
selected = panel;
|
|
59
|
+
if (panel) {
|
|
60
|
+
panel.setAttribute("data-compose-moving", "");
|
|
61
|
+
grips.get(panel)?.setAttribute("aria-pressed", "true");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** @param {HTMLElement} [panel] */
|
|
65
|
+
function highlight(panel) {
|
|
66
|
+
if (target === panel || !press)
|
|
67
|
+
return;
|
|
68
|
+
const source = press.panel;
|
|
69
|
+
const previous = target;
|
|
70
|
+
const undo = previous && previous !== source;
|
|
71
|
+
if (undo)
|
|
72
|
+
exchange(source, previous);
|
|
73
|
+
target = panel;
|
|
74
|
+
const project = panel && panel !== source;
|
|
75
|
+
if (project)
|
|
76
|
+
exchange(source, panel);
|
|
77
|
+
if (panel) {
|
|
78
|
+
// The actual viewer keeps its state and contributes its own intrinsic
|
|
79
|
+
// size and responsive layout in the destination. Only its paint is covered.
|
|
80
|
+
source.append(preview);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
preview.remove();
|
|
84
|
+
}
|
|
85
|
+
if (undo || project)
|
|
86
|
+
container.dispatchEvent(new Event("compose-layout-preview"));
|
|
87
|
+
}
|
|
88
|
+
/** @param {HTMLElement} from @param {HTMLElement} to */
|
|
89
|
+
function exchange(from, to) {
|
|
90
|
+
if (namedAreas) {
|
|
91
|
+
const firstArea = from.dataset.area;
|
|
92
|
+
from.dataset.area = to.dataset.area;
|
|
93
|
+
to.dataset.area = firstArea;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const firstOrder = from.style.order;
|
|
97
|
+
from.style.order = to.style.order;
|
|
98
|
+
to.style.order = firstOrder;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** @param {HTMLElement} from @param {HTMLElement} to */
|
|
102
|
+
function swap(from, to) {
|
|
103
|
+
exchange(from, to);
|
|
104
|
+
announceSwap(from, to);
|
|
105
|
+
}
|
|
106
|
+
/** @param {HTMLElement} from @param {HTMLElement} to */
|
|
107
|
+
function announceSwap(from, to) {
|
|
108
|
+
status.textContent = label(from) + " swapped with " + label(to) + ".";
|
|
109
|
+
container.dispatchEvent(new Event("compose-layout-change"));
|
|
110
|
+
container.dispatchEvent(new Event("compose-panel-layout-committed"));
|
|
111
|
+
}
|
|
112
|
+
/** @param {"preview" | "commit" | "cancel"} phase @param {FreePlace} place */
|
|
113
|
+
function placeBeside(phase, place) {
|
|
114
|
+
if (!press)
|
|
115
|
+
return false;
|
|
116
|
+
const detail = { phase, panel: press.panel, ...place, placed: false };
|
|
117
|
+
container.dispatchEvent(new CustomEvent("compose-panel-place", { detail }));
|
|
118
|
+
return detail.placed;
|
|
119
|
+
}
|
|
120
|
+
function cancelFree() {
|
|
121
|
+
if (free)
|
|
122
|
+
placeBeside("cancel", free);
|
|
123
|
+
free = undefined;
|
|
124
|
+
attempted = undefined;
|
|
125
|
+
}
|
|
126
|
+
/** @param {FreePlace} place */
|
|
127
|
+
function offer(place) {
|
|
128
|
+
if (!press || (place.beside === attempted?.beside && place.side === attempted.side))
|
|
129
|
+
return;
|
|
130
|
+
cancelFree();
|
|
131
|
+
highlight(press.panel);
|
|
132
|
+
attempted = place;
|
|
133
|
+
if (placeBeside("preview", place))
|
|
134
|
+
free = place;
|
|
135
|
+
}
|
|
136
|
+
/** @param {HTMLElement} [destination] */
|
|
137
|
+
function finishPress(destination) {
|
|
138
|
+
const previous = press;
|
|
139
|
+
const from = previous?.panel;
|
|
140
|
+
cancelFree();
|
|
141
|
+
const commit = from && destination && destination !== from;
|
|
142
|
+
if (commit) {
|
|
143
|
+
highlight(destination);
|
|
144
|
+
preview.remove();
|
|
145
|
+
target = undefined;
|
|
146
|
+
}
|
|
147
|
+
else
|
|
148
|
+
highlight();
|
|
149
|
+
press = undefined;
|
|
150
|
+
slots = undefined;
|
|
151
|
+
container.removeAttribute("data-compose-dragging");
|
|
152
|
+
doc.removeEventListener("keydown", cancelWithEscape, true);
|
|
153
|
+
if (previous?.grip.hasPointerCapture(previous.id)) {
|
|
154
|
+
previous.grip.releasePointerCapture(previous.id);
|
|
155
|
+
}
|
|
156
|
+
if (commit)
|
|
157
|
+
announceSwap(from, destination);
|
|
158
|
+
}
|
|
159
|
+
/** @param {KeyboardEvent} event */
|
|
160
|
+
function cancelWithEscape(event) {
|
|
161
|
+
if (event.key !== "Escape" || !press)
|
|
162
|
+
return;
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
event.stopPropagation();
|
|
165
|
+
suppressClick = true;
|
|
166
|
+
finishPress();
|
|
167
|
+
select();
|
|
168
|
+
status.textContent = "";
|
|
169
|
+
}
|
|
170
|
+
function measureSlots() {
|
|
171
|
+
const board = container.getBoundingClientRect();
|
|
172
|
+
return {
|
|
173
|
+
board,
|
|
174
|
+
canPlaceBelow: container.hasAttribute("data-compose-resizing-ready") &&
|
|
175
|
+
!container.classList.contains("tab-bar"),
|
|
176
|
+
scrollLeft: container.scrollLeft || 0,
|
|
177
|
+
scrollTop: container.scrollTop || 0,
|
|
178
|
+
panels: panels.map((panel) => ({ panel, rect: panel.getBoundingClientRect() }))
|
|
179
|
+
.filter(({ rect }) => rect.width > 0 && rect.height > 0),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** @param {DOMRect} rect @param {number} x @param {number} y */
|
|
183
|
+
function contains(rect, x, y) {
|
|
184
|
+
return x >= rect.left && x < rect.right && y >= rect.top && y < rect.bottom;
|
|
185
|
+
}
|
|
186
|
+
/** @param {number} pointerX @param {number} pointerY */
|
|
187
|
+
function propose(pointerX, pointerY) {
|
|
188
|
+
if (!press || !slots)
|
|
189
|
+
return;
|
|
190
|
+
const source = press.panel;
|
|
191
|
+
const board = container.getBoundingClientRect();
|
|
192
|
+
// Hit-test the original slots. The preview itself can move the source,
|
|
193
|
+
// the neighbor and even a whole row; none should steal its own drop target.
|
|
194
|
+
const x = pointerX + slots.board.left - board.left + (container.scrollLeft || 0) -
|
|
195
|
+
slots.scrollLeft;
|
|
196
|
+
const y = pointerY + slots.board.top - board.top + (container.scrollTop || 0) - slots.scrollTop;
|
|
197
|
+
const inside = pointerX >= board.left && pointerX < board.right &&
|
|
198
|
+
pointerY >= board.top && pointerY < board.top + Math.max(board.height, slots.board.height);
|
|
199
|
+
const hit = inside && slots.panels.find(({ rect }) => contains(rect, x, y))?.panel;
|
|
200
|
+
if (free?.side === "below" && contains(press.panel.getBoundingClientRect(), pointerX, pointerY)) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// The last native viewer can end exactly at the host iframe's edge. An
|
|
204
|
+
// inner strip makes the new row reachable without pointing outside it.
|
|
205
|
+
// Allow a small overshoot when the pointer continues across the border.
|
|
206
|
+
if (slots.canPlaceBelow && pointerX >= board.left && pointerX < board.right) {
|
|
207
|
+
const below = slots.panels.find(({ panel, rect }) => panel !== source && (!hit || hit === panel || hit === source) &&
|
|
208
|
+
x >= rect.left && x < rect.right &&
|
|
209
|
+
y >= rect.bottom - Math.min(24, rect.height / 4) && y <= rect.bottom + 24);
|
|
210
|
+
if (below) {
|
|
211
|
+
offer({ beside: below.panel, side: "below" });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (hit && hit !== press.panel) {
|
|
216
|
+
cancelFree();
|
|
217
|
+
highlight(hit);
|
|
218
|
+
return hit;
|
|
219
|
+
}
|
|
220
|
+
// In the empty part of a row, offer the nearest edge at the pointer's
|
|
221
|
+
// height. The packer alone knows whether this viewer fits next to it.
|
|
222
|
+
if (inside && !hit) {
|
|
223
|
+
if (target && contains(press.panel.getBoundingClientRect(), pointerX, pointerY)) {
|
|
224
|
+
return free || target === press.panel ? undefined : target;
|
|
225
|
+
}
|
|
226
|
+
let distance = Infinity;
|
|
227
|
+
/** @type {FreePlace | undefined} */
|
|
228
|
+
let nearest;
|
|
229
|
+
for (const { panel, rect } of slots.panels) {
|
|
230
|
+
if (panel === press.panel || y < rect.top || y >= rect.bottom)
|
|
231
|
+
continue;
|
|
232
|
+
const side = x < rect.left ? "left" : "right";
|
|
233
|
+
const gap = side === "left" ? rect.left - x : x - rect.right;
|
|
234
|
+
if (gap >= 0 && gap < distance) {
|
|
235
|
+
distance = gap;
|
|
236
|
+
nearest = { beside: panel, side };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (nearest) {
|
|
240
|
+
offer(nearest);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// The footprint remains visible across vertical gutters and outside the
|
|
245
|
+
// board. Releasing there keeps the viewer in its original slot.
|
|
246
|
+
cancelFree();
|
|
247
|
+
highlight(press.panel);
|
|
248
|
+
}
|
|
249
|
+
/** @param {HTMLElement} from @param {string} key */
|
|
250
|
+
function neighbor(from, key) {
|
|
251
|
+
const current = from.getBoundingClientRect();
|
|
252
|
+
const horizontal = key === "ArrowLeft" || key === "ArrowRight";
|
|
253
|
+
const forward = key === "ArrowRight" || key === "ArrowDown";
|
|
254
|
+
const [start, end, crossStart, crossEnd] = horizontal
|
|
255
|
+
? /** @type {const} */ (["left", "right", "top", "bottom"])
|
|
256
|
+
: /** @type {const} */ (["top", "bottom", "left", "right"]);
|
|
257
|
+
/** @type {HTMLElement | undefined} */
|
|
258
|
+
let best;
|
|
259
|
+
let bestDistance = Infinity;
|
|
260
|
+
for (const panel of panels) {
|
|
261
|
+
if (panel === from)
|
|
262
|
+
continue;
|
|
263
|
+
const rect = panel.getBoundingClientRect();
|
|
264
|
+
const gap = forward ? rect[start] - current[end] : current[start] - rect[end];
|
|
265
|
+
if (!rect.width || !rect.height || gap < -1)
|
|
266
|
+
continue;
|
|
267
|
+
if (rect[crossEnd] <= current[crossStart] || rect[crossStart] >= current[crossEnd])
|
|
268
|
+
continue;
|
|
269
|
+
const offset = (rect[crossStart] + rect[crossEnd] - current[crossStart] - current[crossEnd]) /
|
|
270
|
+
2;
|
|
271
|
+
const distance = Math.hypot(gap, offset);
|
|
272
|
+
if (distance < bestDistance) {
|
|
273
|
+
best = panel;
|
|
274
|
+
bestDistance = distance;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return best;
|
|
278
|
+
}
|
|
279
|
+
for (const [index, panel] of panels.entries()) {
|
|
280
|
+
if (namedAreas)
|
|
281
|
+
panel.dataset.composeTemplateArea ??= panel.dataset.area;
|
|
282
|
+
else
|
|
283
|
+
panel.style.order = String(index);
|
|
284
|
+
let grip = /** @type {HTMLButtonElement | null} */ (panel.querySelector("[data-compose-grip]"));
|
|
285
|
+
if (!grip) {
|
|
286
|
+
grip = doc.createElement("button");
|
|
287
|
+
grip.setAttribute("data-compose-grip", "");
|
|
288
|
+
panel.prepend(grip);
|
|
289
|
+
}
|
|
290
|
+
grips.set(panel, grip);
|
|
291
|
+
grip.type = "button";
|
|
292
|
+
grip.hidden = false;
|
|
293
|
+
grip.setAttribute("aria-pressed", "false");
|
|
294
|
+
grip.setAttribute("aria-label", "Move " + label(panel));
|
|
295
|
+
grip.setAttribute("aria-keyshortcuts", "ArrowLeft ArrowRight ArrowUp ArrowDown Escape");
|
|
296
|
+
grip.title = container.classList.contains("tab-bar")
|
|
297
|
+
? "Drag to swap tabs, use the arrow keys, or select two handles."
|
|
298
|
+
: "Drag beside a viewer to share its row, onto its lower edge to place below, or onto its center to swap. Arrow keys or two handles also swap viewers.";
|
|
299
|
+
grip.addEventListener("click", (event) => {
|
|
300
|
+
if (suppressClick && event.detail !== 0)
|
|
301
|
+
return;
|
|
302
|
+
if (selected && selected !== panel) {
|
|
303
|
+
swap(selected, panel);
|
|
304
|
+
select();
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
select(selected === panel ? undefined : panel);
|
|
308
|
+
status.textContent = selected
|
|
309
|
+
? "Select a destination handle for " + label(panel) + "."
|
|
310
|
+
: "";
|
|
311
|
+
}
|
|
312
|
+
}, { signal });
|
|
313
|
+
grip.addEventListener("keydown", (event) => {
|
|
314
|
+
if (event.key === "Escape") {
|
|
315
|
+
event.preventDefault();
|
|
316
|
+
suppressClick = !!press;
|
|
317
|
+
finishPress();
|
|
318
|
+
select();
|
|
319
|
+
status.textContent = "";
|
|
320
|
+
}
|
|
321
|
+
else if (!press && ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)) {
|
|
322
|
+
event.preventDefault();
|
|
323
|
+
const next = neighbor(panel, event.key);
|
|
324
|
+
if (next) {
|
|
325
|
+
swap(panel, next);
|
|
326
|
+
select();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}, { signal });
|
|
330
|
+
grip.addEventListener("pointerdown", (event) => {
|
|
331
|
+
if (container.hasAttribute("data-compose-dragging") || !event.isPrimary || event.button !== 0)
|
|
332
|
+
return;
|
|
333
|
+
suppressClick = false;
|
|
334
|
+
press = {
|
|
335
|
+
panel,
|
|
336
|
+
grip,
|
|
337
|
+
id: event.pointerId,
|
|
338
|
+
x: event.clientX,
|
|
339
|
+
y: event.clientY,
|
|
340
|
+
dragged: false,
|
|
341
|
+
};
|
|
342
|
+
container.setAttribute("data-compose-dragging", "");
|
|
343
|
+
doc.addEventListener("keydown", cancelWithEscape, true);
|
|
344
|
+
grip.focus({ preventScroll: true });
|
|
345
|
+
grip.setPointerCapture(event.pointerId);
|
|
346
|
+
}, { signal });
|
|
347
|
+
}
|
|
348
|
+
container.addEventListener("pointermove", (event) => {
|
|
349
|
+
if (!press || press.id !== event.pointerId)
|
|
350
|
+
return;
|
|
351
|
+
if (!press.dragged) {
|
|
352
|
+
if (Math.hypot(event.clientX - press.x, event.clientY - press.y) < 4)
|
|
353
|
+
return;
|
|
354
|
+
press.dragged = true;
|
|
355
|
+
slots = measureSlots();
|
|
356
|
+
select(press.panel);
|
|
357
|
+
}
|
|
358
|
+
propose(event.clientX, event.clientY);
|
|
359
|
+
}, { signal });
|
|
360
|
+
container.addEventListener("pointerup", (event) => {
|
|
361
|
+
if (!press || press.id !== event.pointerId)
|
|
362
|
+
return;
|
|
363
|
+
if (press.dragged) {
|
|
364
|
+
suppressClick = true;
|
|
365
|
+
const over = propose(event.clientX, event.clientY);
|
|
366
|
+
const placement = free;
|
|
367
|
+
const from = press.panel;
|
|
368
|
+
const placed = placement && placeBeside("commit", placement);
|
|
369
|
+
if (placed)
|
|
370
|
+
free = undefined;
|
|
371
|
+
finishPress(over);
|
|
372
|
+
if (placed) {
|
|
373
|
+
const where = placement.side === "below" ? " below " : " beside ";
|
|
374
|
+
status.textContent = label(from) + " placed" + where + label(placement.beside) + ".";
|
|
375
|
+
container.dispatchEvent(new Event("compose-layout-change"));
|
|
376
|
+
container.dispatchEvent(new Event("compose-panel-layout-committed"));
|
|
377
|
+
}
|
|
378
|
+
select();
|
|
379
|
+
}
|
|
380
|
+
else
|
|
381
|
+
finishPress();
|
|
382
|
+
}, { signal });
|
|
383
|
+
/** @param {PointerEvent} event */
|
|
384
|
+
function cancelPointer(event) {
|
|
385
|
+
if (press?.id !== event.pointerId)
|
|
386
|
+
return;
|
|
387
|
+
suppressClick = true;
|
|
388
|
+
finishPress();
|
|
389
|
+
select();
|
|
390
|
+
}
|
|
391
|
+
container.addEventListener("pointercancel", cancelPointer, { signal });
|
|
392
|
+
container.addEventListener("lostpointercapture", cancelPointer, { signal });
|
|
393
|
+
signal?.addEventListener("abort", () => {
|
|
394
|
+
finishPress();
|
|
395
|
+
select();
|
|
396
|
+
status.remove();
|
|
397
|
+
container.removeAttribute("data-compose-movement-ready");
|
|
398
|
+
}, { once: true });
|
|
399
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fit each viewer's chosen width into the authored grid. Keep the actual
|
|
3
|
+
* iframe mounted, and move a neighbor below when it cannot fit on its row.
|
|
4
|
+
* This function is also embedded in the standalone host.
|
|
5
|
+
* @param {HTMLElement} container
|
|
6
|
+
*/
|
|
7
|
+
export function createPanelReflow(container: HTMLElement): {
|
|
8
|
+
layout: (choices: ReadonlyMap<HTMLElement, number>, preview?: {
|
|
9
|
+
panel: HTMLElement;
|
|
10
|
+
skeleton: HTMLElement;
|
|
11
|
+
} | undefined, placements?: ReadonlyMap<HTMLElement, {
|
|
12
|
+
beside: HTMLElement;
|
|
13
|
+
side: "left" | "right" | "below";
|
|
14
|
+
}> | undefined) => boolean;
|
|
15
|
+
reset: () => void;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=panel-reflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel-reflow.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/panel-reflow.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,6CAFW,WAAW;sBA6BT,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC;eACxB,WAAW;kBAAY,WAAW;;gBACR,WAAW;cAAQ,MAAM,GAAG,OAAO,GAAG,OAAO;uBAC7E,OAAO;;EA+SrB"}
|