mindoodb-app-sdk 0.0.43 → 0.0.45
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 +30 -0
- package/dist/{chunk-7RAKZZA6.js → chunk-ZO7UE6B2.js} +430 -0
- package/dist/index.d.ts +54 -3
- package/dist/index.js +35 -2
- package/dist/testing/index.d.ts +3 -1
- package/dist/testing/index.js +40 -2
- package/dist/{types-DALNnPXo.d.ts → types-M3RwHErO.d.ts} +123 -2
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +76 -54
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -229,6 +229,32 @@ Important constraints:
|
|
|
229
229
|
- Call `session.menus.hide()` if your app needs to explicitly dismiss a pending host menu.
|
|
230
230
|
- Host-rendered menus are intended for `runtime === "iframe"`. Window-mode apps can usually show local menus instead.
|
|
231
231
|
|
|
232
|
+
### Host-owned drag
|
|
233
|
+
|
|
234
|
+
When two apps run as visible workspace chicklets, native HTML5 drag dies at the iframe boundary. The SDK therefore hands the gesture to Haven: the source starts it, Haven draws a PNG ghost above every frame, and the target hit-tests the drop.
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
await session.drag.setProfile({
|
|
238
|
+
accepts: ["text/plain", "text/markdown", "application/json", "application/x-mindoo-document"],
|
|
239
|
+
onOver: (event) => {
|
|
240
|
+
const zone = document.elementFromPoint(event.x, event.y)?.closest("[data-drop-zone]");
|
|
241
|
+
return { accept: Boolean(zone), effect: zone ? "copy" : "forbidden" };
|
|
242
|
+
},
|
|
243
|
+
onDrop: (event) => {
|
|
244
|
+
console.log(event.items["text/markdown"]);
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const unbind = session.drag.bindSource(cardEl, {
|
|
249
|
+
offers: () => [
|
|
250
|
+
{ type: "text/plain", data: "Hello" },
|
|
251
|
+
{ type: "text/markdown", data: "**Hello**" },
|
|
252
|
+
],
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
`bindSource` starts after an 8px mouse/pen move, or a 400ms long-press on touch (so lists can still scroll). You can also call `session.drag.start` yourself with a PNG `ArrayBuffer` preview. v1 is **copy-only** and **iframe-only**. Well-known types: `text/plain`, `text/markdown`, `application/json`, `application/x-mindoo-document`.
|
|
257
|
+
|
|
232
258
|
### Databases and capabilities
|
|
233
259
|
|
|
234
260
|
Each database mapped to your app carries a set of **capabilities** that Haven controls. Your app should check capabilities before attempting operations and adapt its UI accordingly.
|
|
@@ -1573,6 +1599,10 @@ Connect options: `launchId?`, `targetOrigin?`, `connectTimeoutMs?`.
|
|
|
1573
1599
|
| `closeSealedChannel(channelId)` | `Promise<void>` |
|
|
1574
1600
|
| `menus.show(input)` | `Promise<MindooDBAppShowMenuResult>` |
|
|
1575
1601
|
| `menus.hide()` | `Promise<void>` |
|
|
1602
|
+
| `drag.setProfile(profile)` | `Promise<void>` |
|
|
1603
|
+
| `drag.start(input)` | `Promise<MindooDBAppDragStartResult>` |
|
|
1604
|
+
| `drag.cancel()` | `Promise<void>` |
|
|
1605
|
+
| `drag.bindSource(el, options)` | `() => void` (unbind) |
|
|
1576
1606
|
| `storage` | `MindooDBAppStorageApi` |
|
|
1577
1607
|
| `onThemeChange(listener)` | `() => void` (unsubscribe) |
|
|
1578
1608
|
| `onViewportChange(listener)` | `() => void` (unsubscribe) |
|
|
@@ -1,3 +1,344 @@
|
|
|
1
|
+
// src/drag.ts
|
|
2
|
+
var MINDOODB_APP_MAX_DRAG_TYPES = 8;
|
|
3
|
+
var MINDOODB_APP_MAX_DRAG_PAYLOAD_BYTES = 32 * 1024;
|
|
4
|
+
var MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES = 256 * 1024;
|
|
5
|
+
var MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE = 512;
|
|
6
|
+
var DEFAULT_DRAG_LONG_PRESS_MS = 400;
|
|
7
|
+
var DEFAULT_DRAG_POINTER_THRESHOLD_PX = 8;
|
|
8
|
+
var MINIMAL_DRAG_PREVIEW_PNG = Uint8Array.from(
|
|
9
|
+
atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="),
|
|
10
|
+
(character) => character.charCodeAt(0)
|
|
11
|
+
);
|
|
12
|
+
var DRAG_TYPE_PATTERN = /^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/i;
|
|
13
|
+
var MindooDBAppDragInputError = class extends Error {
|
|
14
|
+
name = "invalid-drag-input";
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
function isMindooDBAppDragType(type) {
|
|
20
|
+
return DRAG_TYPE_PATTERN.test(type);
|
|
21
|
+
}
|
|
22
|
+
function utf8ByteLength(value) {
|
|
23
|
+
return new TextEncoder().encode(value).length;
|
|
24
|
+
}
|
|
25
|
+
function requireFiniteNumber(value, fieldPath) {
|
|
26
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
27
|
+
throw new MindooDBAppDragInputError(`Expected ${fieldPath} to be a finite number.`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function toPreviewArrayBuffer(value) {
|
|
32
|
+
if (value instanceof ArrayBuffer) {
|
|
33
|
+
return value.slice(0);
|
|
34
|
+
}
|
|
35
|
+
if (ArrayBuffer.isView(value)) {
|
|
36
|
+
return value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function normalizeDragType(value, fieldPath) {
|
|
41
|
+
if (typeof value !== "string" || !isMindooDBAppDragType(value)) {
|
|
42
|
+
throw new MindooDBAppDragInputError(`Expected ${fieldPath} to be a MIME-like type string.`);
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
function normalizeOffers(value) {
|
|
47
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
48
|
+
throw new MindooDBAppDragInputError("A drag must offer at least one type.");
|
|
49
|
+
}
|
|
50
|
+
if (value.length > MINDOODB_APP_MAX_DRAG_TYPES) {
|
|
51
|
+
throw new MindooDBAppDragInputError(
|
|
52
|
+
`A drag supports at most ${MINDOODB_APP_MAX_DRAG_TYPES} types.`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const seen = /* @__PURE__ */ new Set();
|
|
56
|
+
return value.map((entry, index) => {
|
|
57
|
+
if (!entry || typeof entry !== "object") {
|
|
58
|
+
throw new MindooDBAppDragInputError(`Expected offers[${index}] to be an object.`);
|
|
59
|
+
}
|
|
60
|
+
const candidate = entry;
|
|
61
|
+
const type = normalizeDragType(candidate.type, `offers[${index}].type`);
|
|
62
|
+
if (seen.has(type)) {
|
|
63
|
+
throw new MindooDBAppDragInputError(`Duplicate drag type "${type}".`);
|
|
64
|
+
}
|
|
65
|
+
seen.add(type);
|
|
66
|
+
if (typeof candidate.data !== "string") {
|
|
67
|
+
throw new MindooDBAppDragInputError(`Expected offers[${index}].data to be a string.`);
|
|
68
|
+
}
|
|
69
|
+
if (utf8ByteLength(candidate.data) > MINDOODB_APP_MAX_DRAG_PAYLOAD_BYTES) {
|
|
70
|
+
throw new MindooDBAppDragInputError(
|
|
71
|
+
`offers[${index}].data exceeds ${MINDOODB_APP_MAX_DRAG_PAYLOAD_BYTES} bytes.`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return { type, data: candidate.data };
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function normalizeDragAccepts(value) {
|
|
78
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
79
|
+
throw new MindooDBAppDragInputError("A drag profile must accept at least one type.");
|
|
80
|
+
}
|
|
81
|
+
if (value.length > MINDOODB_APP_MAX_DRAG_TYPES) {
|
|
82
|
+
throw new MindooDBAppDragInputError(
|
|
83
|
+
`A drag profile supports at most ${MINDOODB_APP_MAX_DRAG_TYPES} types.`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const seen = /* @__PURE__ */ new Set();
|
|
87
|
+
const accepts = [];
|
|
88
|
+
value.forEach((entry, index) => {
|
|
89
|
+
const type = normalizeDragType(entry, `accepts[${index}]`);
|
|
90
|
+
if (seen.has(type)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
seen.add(type);
|
|
94
|
+
accepts.push(type);
|
|
95
|
+
});
|
|
96
|
+
return accepts;
|
|
97
|
+
}
|
|
98
|
+
function normalizePreview(value) {
|
|
99
|
+
if (!value || typeof value !== "object") {
|
|
100
|
+
throw new MindooDBAppDragInputError("A drag preview is required.");
|
|
101
|
+
}
|
|
102
|
+
const candidate = value;
|
|
103
|
+
const pngBuffer = toPreviewArrayBuffer(candidate.png);
|
|
104
|
+
if (!pngBuffer) {
|
|
105
|
+
throw new MindooDBAppDragInputError("preview.png must be an ArrayBuffer.");
|
|
106
|
+
}
|
|
107
|
+
if (pngBuffer.byteLength === 0 || pngBuffer.byteLength > MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES) {
|
|
108
|
+
throw new MindooDBAppDragInputError(
|
|
109
|
+
`preview.png must be between 1 and ${MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES} bytes.`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const width = requireFiniteNumber(candidate.width, "preview.width");
|
|
113
|
+
const height = requireFiniteNumber(candidate.height, "preview.height");
|
|
114
|
+
if (width <= 0 || height <= 0 || width > MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE * 4 || height > MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE * 4) {
|
|
115
|
+
throw new MindooDBAppDragInputError("preview width/height are out of range.");
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
png: pngBuffer,
|
|
119
|
+
width,
|
|
120
|
+
height,
|
|
121
|
+
hotspotX: requireFiniteNumber(candidate.hotspotX, "preview.hotspotX"),
|
|
122
|
+
hotspotY: requireFiniteNumber(candidate.hotspotY, "preview.hotspotY")
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function normalizeDragStartInput(value) {
|
|
126
|
+
if (!value || typeof value !== "object") {
|
|
127
|
+
throw new MindooDBAppDragInputError("drag.start requires a payload object.");
|
|
128
|
+
}
|
|
129
|
+
const candidate = value;
|
|
130
|
+
if (!candidate.pointer || typeof candidate.pointer !== "object") {
|
|
131
|
+
throw new MindooDBAppDragInputError("pointer is required.");
|
|
132
|
+
}
|
|
133
|
+
const pointer = candidate.pointer;
|
|
134
|
+
let allowedEffects;
|
|
135
|
+
if (candidate.allowedEffects !== void 0) {
|
|
136
|
+
if (!Array.isArray(candidate.allowedEffects) || candidate.allowedEffects.length === 0 || candidate.allowedEffects.some((effect) => effect !== "copy")) {
|
|
137
|
+
throw new MindooDBAppDragInputError('allowedEffects may only include "copy".');
|
|
138
|
+
}
|
|
139
|
+
allowedEffects = ["copy"];
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
offers: normalizeOffers(candidate.offers),
|
|
143
|
+
preview: normalizePreview(candidate.preview),
|
|
144
|
+
pointer: {
|
|
145
|
+
x: requireFiniteNumber(pointer.x, "pointer.x"),
|
|
146
|
+
y: requireFiniteNumber(pointer.y, "pointer.y")
|
|
147
|
+
},
|
|
148
|
+
allowedEffects
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function canvasToPng(canvas) {
|
|
152
|
+
if (typeof canvas.toBlob === "function") {
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
canvas.toBlob((blob) => {
|
|
155
|
+
if (!blob) {
|
|
156
|
+
reject(new Error("Could not encode the drag preview as PNG."));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
void blob.arrayBuffer().then(resolve, reject);
|
|
160
|
+
}, "image/png");
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (typeof canvas.toDataURL !== "function") {
|
|
164
|
+
return Promise.resolve(MINIMAL_DRAG_PREVIEW_PNG.buffer.slice(0));
|
|
165
|
+
}
|
|
166
|
+
const dataUrl = canvas.toDataURL("image/png");
|
|
167
|
+
const encoded = dataUrl.split(",")[1];
|
|
168
|
+
if (!encoded) {
|
|
169
|
+
return Promise.resolve(MINIMAL_DRAG_PREVIEW_PNG.buffer.slice(0));
|
|
170
|
+
}
|
|
171
|
+
const binary = atob(encoded);
|
|
172
|
+
const bytes = new Uint8Array(binary.length);
|
|
173
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
174
|
+
bytes[index] = binary.charCodeAt(index);
|
|
175
|
+
}
|
|
176
|
+
return Promise.resolve(bytes.buffer);
|
|
177
|
+
}
|
|
178
|
+
function drawFallbackCard(element, width, height) {
|
|
179
|
+
if (typeof document === "undefined") {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const canvas = document.createElement("canvas");
|
|
183
|
+
canvas.width = width;
|
|
184
|
+
canvas.height = height;
|
|
185
|
+
const context = canvas.getContext("2d");
|
|
186
|
+
if (!context) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
context.fillStyle = "#1c2333";
|
|
190
|
+
context.fillRect(0, 0, width, height);
|
|
191
|
+
context.strokeStyle = "#6ea8fe";
|
|
192
|
+
context.strokeRect(0.5, 0.5, width - 1, height - 1);
|
|
193
|
+
context.fillStyle = "#f4f7fb";
|
|
194
|
+
context.font = "12px sans-serif";
|
|
195
|
+
const label = (element.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 48);
|
|
196
|
+
context.fillText(label || "Drag", 8, Math.min(20, height - 6));
|
|
197
|
+
return canvas;
|
|
198
|
+
}
|
|
199
|
+
function scaledPreviewSize(width, height) {
|
|
200
|
+
const safeWidth = Math.max(1, Math.round(width));
|
|
201
|
+
const safeHeight = Math.max(1, Math.round(height));
|
|
202
|
+
const scale = Math.min(1, MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE / Math.max(safeWidth, safeHeight));
|
|
203
|
+
return {
|
|
204
|
+
width: Math.max(1, Math.round(safeWidth * scale)),
|
|
205
|
+
height: Math.max(1, Math.round(safeHeight * scale))
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
async function snapshotElementToPng(element) {
|
|
209
|
+
const bounds = element.getBoundingClientRect();
|
|
210
|
+
const size = scaledPreviewSize(bounds.width || 160, bounds.height || 72);
|
|
211
|
+
const canvas = drawFallbackCard(element, size.width, size.height);
|
|
212
|
+
const png = canvas ? await canvasToPng(canvas) : MINIMAL_DRAG_PREVIEW_PNG.buffer.slice(0);
|
|
213
|
+
if (png.byteLength > MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES) {
|
|
214
|
+
throw new MindooDBAppDragInputError(
|
|
215
|
+
`Drag preview exceeds ${MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES} bytes.`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
png,
|
|
220
|
+
width: size.width,
|
|
221
|
+
height: size.height,
|
|
222
|
+
hotspotX: size.width / 2,
|
|
223
|
+
hotspotY: size.height / 2
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function pointerDistance(origin, event) {
|
|
227
|
+
const dx = event.clientX - origin.x;
|
|
228
|
+
const dy = event.clientY - origin.y;
|
|
229
|
+
return Math.hypot(dx, dy);
|
|
230
|
+
}
|
|
231
|
+
function readOffers(options) {
|
|
232
|
+
return typeof options.offers === "function" ? options.offers() : options.offers;
|
|
233
|
+
}
|
|
234
|
+
function readPreviewElement(source, options) {
|
|
235
|
+
if (!options.preview) {
|
|
236
|
+
return source;
|
|
237
|
+
}
|
|
238
|
+
return typeof options.preview === "function" ? options.preview() : options.preview;
|
|
239
|
+
}
|
|
240
|
+
function bindDragSource(element, options, start) {
|
|
241
|
+
const longPressMs = options.longPressMs ?? DEFAULT_DRAG_LONG_PRESS_MS;
|
|
242
|
+
const thresholdPx = options.pointerThresholdPx ?? DEFAULT_DRAG_POINTER_THRESHOLD_PX;
|
|
243
|
+
let active = null;
|
|
244
|
+
const reset = () => {
|
|
245
|
+
if (active?.timer != null) {
|
|
246
|
+
clearTimeout(active.timer);
|
|
247
|
+
}
|
|
248
|
+
active = null;
|
|
249
|
+
};
|
|
250
|
+
const beginHostDrag = async (event) => {
|
|
251
|
+
if (!active || active.started) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
active.started = true;
|
|
255
|
+
if (active.timer != null) {
|
|
256
|
+
clearTimeout(active.timer);
|
|
257
|
+
active.timer = null;
|
|
258
|
+
}
|
|
259
|
+
const offers = readOffers(options);
|
|
260
|
+
if (offers.length === 0) {
|
|
261
|
+
reset();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
const preview = await active.preview;
|
|
266
|
+
const hotX = event.clientX - element.getBoundingClientRect().left;
|
|
267
|
+
const hotY = event.clientY - element.getBoundingClientRect().top;
|
|
268
|
+
await start({
|
|
269
|
+
offers,
|
|
270
|
+
preview: {
|
|
271
|
+
...preview,
|
|
272
|
+
hotspotX: hotX,
|
|
273
|
+
hotspotY: hotY
|
|
274
|
+
},
|
|
275
|
+
pointer: { x: event.clientX, y: event.clientY },
|
|
276
|
+
allowedEffects: ["copy"]
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
const onPointerDown = (event) => {
|
|
280
|
+
if (event.button !== 0) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
reset();
|
|
284
|
+
const previewElement = readPreviewElement(element, options);
|
|
285
|
+
active = {
|
|
286
|
+
pointerId: event.pointerId,
|
|
287
|
+
origin: { x: event.clientX, y: event.clientY },
|
|
288
|
+
pointerType: event.pointerType,
|
|
289
|
+
preview: snapshotElementToPng(previewElement).catch(() => ({
|
|
290
|
+
png: MINIMAL_DRAG_PREVIEW_PNG.buffer.slice(0),
|
|
291
|
+
width: Math.max(1, Math.round(previewElement.getBoundingClientRect().width) || 160),
|
|
292
|
+
height: Math.max(1, Math.round(previewElement.getBoundingClientRect().height) || 72),
|
|
293
|
+
hotspotX: 0,
|
|
294
|
+
hotspotY: 0
|
|
295
|
+
})),
|
|
296
|
+
timer: null,
|
|
297
|
+
started: false
|
|
298
|
+
};
|
|
299
|
+
if (event.pointerType === "touch") {
|
|
300
|
+
active.timer = setTimeout(() => {
|
|
301
|
+
if (!active || active.started) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
void beginHostDrag(event);
|
|
305
|
+
}, longPressMs);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const onPointerMove = (event) => {
|
|
309
|
+
if (!active || event.pointerId !== active.pointerId || active.started) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const distance = pointerDistance(active.origin, event);
|
|
313
|
+
if (active.pointerType === "touch") {
|
|
314
|
+
if (distance > thresholdPx) {
|
|
315
|
+
reset();
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (distance >= thresholdPx) {
|
|
320
|
+
void beginHostDrag(event);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
const onPointerUp = (event) => {
|
|
324
|
+
if (!active || event.pointerId !== active.pointerId) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
reset();
|
|
328
|
+
};
|
|
329
|
+
element.addEventListener("pointerdown", onPointerDown);
|
|
330
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
331
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
332
|
+
window.addEventListener("pointercancel", onPointerUp);
|
|
333
|
+
return () => {
|
|
334
|
+
reset();
|
|
335
|
+
element.removeEventListener("pointerdown", onPointerDown);
|
|
336
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
337
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
338
|
+
window.removeEventListener("pointercancel", onPointerUp);
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
1
342
|
// src/hostShortcuts.ts
|
|
2
343
|
var DEFAULT_HAVEN_HOST_SHORTCUTS = [
|
|
3
344
|
{ action: "open-workspace", code: "Enter", shiftKey: true, metaOrCtrl: true },
|
|
@@ -287,6 +628,15 @@ function isUiPreferencesChangedMessage(message) {
|
|
|
287
628
|
function isLocaleChangedMessage(message) {
|
|
288
629
|
return message.kind === "locale-changed";
|
|
289
630
|
}
|
|
631
|
+
function isDragOverMessage(message) {
|
|
632
|
+
return message.kind === "drag-over";
|
|
633
|
+
}
|
|
634
|
+
function isDragLeaveMessage(message) {
|
|
635
|
+
return message.kind === "drag-leave";
|
|
636
|
+
}
|
|
637
|
+
function isDragDropMessage(message) {
|
|
638
|
+
return message.kind === "drag-drop";
|
|
639
|
+
}
|
|
290
640
|
function toStreamError(message) {
|
|
291
641
|
const error = new Error(message.error.message);
|
|
292
642
|
error.name = message.error.code || "MindooDBAppBridgeStreamError";
|
|
@@ -1163,6 +1513,70 @@ var MindooDBAppDatabaseImpl = class {
|
|
|
1163
1513
|
});
|
|
1164
1514
|
}
|
|
1165
1515
|
};
|
|
1516
|
+
var MindooDBAppDragApiImpl = class {
|
|
1517
|
+
constructor(rpc) {
|
|
1518
|
+
this.rpc = rpc;
|
|
1519
|
+
this.rpc.addMessageListener((message) => {
|
|
1520
|
+
if (isDragOverMessage(message)) {
|
|
1521
|
+
const result = this.profile?.onOver?.({
|
|
1522
|
+
x: message.x,
|
|
1523
|
+
y: message.y,
|
|
1524
|
+
types: message.types
|
|
1525
|
+
});
|
|
1526
|
+
const accept = result?.accept ?? true;
|
|
1527
|
+
void this.rpc.call("drag.reportHover", {
|
|
1528
|
+
accept,
|
|
1529
|
+
effect: accept ? result?.effect ?? "copy" : "forbidden"
|
|
1530
|
+
}).catch((error) => {
|
|
1531
|
+
console.warn("[mindoodb-app-sdk] Could not report a drag hover.", error);
|
|
1532
|
+
});
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
if (isDragLeaveMessage(message)) {
|
|
1536
|
+
this.profile?.onLeave?.();
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
if (isDragDropMessage(message)) {
|
|
1540
|
+
this.profile?.onDrop?.({
|
|
1541
|
+
x: message.x,
|
|
1542
|
+
y: message.y,
|
|
1543
|
+
items: message.items
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
rpc;
|
|
1549
|
+
profile = null;
|
|
1550
|
+
unbindSources = /* @__PURE__ */ new Set();
|
|
1551
|
+
async setProfile(profile) {
|
|
1552
|
+
this.profile = profile;
|
|
1553
|
+
await this.rpc.call("drag.setProfile", {
|
|
1554
|
+
accepts: normalizeDragAccepts(profile.accepts)
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
async start(input) {
|
|
1558
|
+
return await this.rpc.call(
|
|
1559
|
+
"drag.start",
|
|
1560
|
+
normalizeDragStartInput(input)
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
async cancel() {
|
|
1564
|
+
await this.rpc.call("drag.cancel", {});
|
|
1565
|
+
}
|
|
1566
|
+
bindSource(element, options) {
|
|
1567
|
+
const unbind = bindDragSource(element, options, (input) => this.start(input));
|
|
1568
|
+
this.unbindSources.add(unbind);
|
|
1569
|
+
return () => {
|
|
1570
|
+
unbind();
|
|
1571
|
+
this.unbindSources.delete(unbind);
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
dispose() {
|
|
1575
|
+
this.unbindSources.forEach((unbind) => unbind());
|
|
1576
|
+
this.unbindSources.clear();
|
|
1577
|
+
this.profile = null;
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1166
1580
|
var MindooDBAppSessionImpl = class {
|
|
1167
1581
|
constructor(rpc, onDisconnect, hostShortcutsEnabled = true) {
|
|
1168
1582
|
this.rpc = rpc;
|
|
@@ -1173,6 +1587,7 @@ var MindooDBAppSessionImpl = class {
|
|
|
1173
1587
|
await this.rpc.call("menus.hide", {});
|
|
1174
1588
|
}
|
|
1175
1589
|
};
|
|
1590
|
+
this.drag = new MindooDBAppDragApiImpl(this.rpc);
|
|
1176
1591
|
this.storage = {
|
|
1177
1592
|
snapshot: async (options) => await this.rpc.call("appStorage.snapshot", {
|
|
1178
1593
|
prefixes: options?.prefixes
|
|
@@ -1221,6 +1636,7 @@ var MindooDBAppSessionImpl = class {
|
|
|
1221
1636
|
rpc;
|
|
1222
1637
|
onDisconnect;
|
|
1223
1638
|
menus;
|
|
1639
|
+
drag;
|
|
1224
1640
|
storage;
|
|
1225
1641
|
beforeCloseListeners = /* @__PURE__ */ new Set();
|
|
1226
1642
|
hostShortcuts = DEFAULT_HAVEN_HOST_SHORTCUTS;
|
|
@@ -1363,6 +1779,7 @@ var MindooDBAppSessionImpl = class {
|
|
|
1363
1779
|
/** Disconnects from the host and always disposes the underlying port client. */
|
|
1364
1780
|
async disconnect() {
|
|
1365
1781
|
this.stopHostShortcuts();
|
|
1782
|
+
this.drag.dispose();
|
|
1366
1783
|
try {
|
|
1367
1784
|
await this.rpc.call("session.disconnect", {});
|
|
1368
1785
|
} finally {
|
|
@@ -1415,6 +1832,19 @@ function createMindooDBAppBridge() {
|
|
|
1415
1832
|
}
|
|
1416
1833
|
|
|
1417
1834
|
export {
|
|
1835
|
+
MINDOODB_APP_MAX_DRAG_TYPES,
|
|
1836
|
+
MINDOODB_APP_MAX_DRAG_PAYLOAD_BYTES,
|
|
1837
|
+
MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES,
|
|
1838
|
+
MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE,
|
|
1839
|
+
DEFAULT_DRAG_LONG_PRESS_MS,
|
|
1840
|
+
DEFAULT_DRAG_POINTER_THRESHOLD_PX,
|
|
1841
|
+
MINIMAL_DRAG_PREVIEW_PNG,
|
|
1842
|
+
MindooDBAppDragInputError,
|
|
1843
|
+
isMindooDBAppDragType,
|
|
1844
|
+
normalizeDragAccepts,
|
|
1845
|
+
normalizeDragStartInput,
|
|
1846
|
+
snapshotElementToPng,
|
|
1847
|
+
bindDragSource,
|
|
1418
1848
|
DEFAULT_HAVEN_HOST_SHORTCUTS,
|
|
1419
1849
|
matchHostShortcut,
|
|
1420
1850
|
isHostShortcutAction,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MindooDBAppAttachmentPreviewMode, a as
|
|
2
|
-
export {
|
|
1
|
+
import { M as MindooDBAppAttachmentPreviewMode, a as MindooDBAppDragBindSourceOptions, b as MindooDBAppDragStartInput, c as MindooDBAppDragStartResult, d as MindooDBAppDragPreview, e as MindooDBAppBridge, f as MindooDBAppHostShortcutBinding, g as MindooDBAppHostShortcutAction, h as MindooDBAppHostingMode, i as MindooDBAppDatabase, j as MindooDBAppDocument, k as MindooDBAppRichTextSpan, l as MindooDBAppRichTextSnapshot } from './types-M3RwHErO.js';
|
|
2
|
+
export { m as MINDOODB_APP_SEAL_SIGNING_DOMAIN, n as MINDOODB_APP_WELL_KNOWN_DRAG_TYPES, o as MindooDBAppAccessDecision, p as MindooDBAppAccessTier, q as MindooDBAppAttachmentApi, r as MindooDBAppAttachmentChunk, s as MindooDBAppAttachmentInfo, t as MindooDBAppAttachmentPreviewOptions, u as MindooDBAppAttachmentPreviewSession, v as MindooDBAppAutomergeChangesPatch, w as MindooDBAppAutomergeChangesSince, x as MindooDBAppAutomergeGetOptions, y as MindooDBAppAutomergePatchResult, z as MindooDBAppAutomergeSnapshot, A as MindooDBAppBridgeBeforeCloseAck, B as MindooDBAppBridgeBeforeCloseMessage, C as MindooDBAppBridgeConnectMessage, D as MindooDBAppBridgeConnectOptions, E as MindooDBAppBridgeConnectedMessage, F as MindooDBAppBridgeDragDropMessage, G as MindooDBAppBridgeDragLeaveMessage, H as MindooDBAppBridgeDragOverMessage, I as MindooDBAppBridgeErrorPayload, J as MindooDBAppBridgeHandshakeErrorMessage, K as MindooDBAppBridgeLocaleChangedMessage, L as MindooDBAppBridgePortMessage, N as MindooDBAppBridgeQueryResultMessage, O as MindooDBAppBridgeRpcError, P as MindooDBAppBridgeRpcMessage, Q as MindooDBAppBridgeRpcRequest, R as MindooDBAppBridgeRpcSuccess, S as MindooDBAppBridgeShortcutInvokedMessage, T as MindooDBAppBridgeShortcutsChangedMessage, U as MindooDBAppBridgeStreamAbortRequest, V as MindooDBAppBridgeStreamAck, W as MindooDBAppBridgeStreamCloseRequest, X as MindooDBAppBridgeStreamError, Y as MindooDBAppBridgeStreamMessage, Z as MindooDBAppBridgeStreamOpenResult, _ as MindooDBAppBridgeStreamReadRequest, $ as MindooDBAppBridgeStreamWriteRequest, a0 as MindooDBAppBridgeThemeChangedMessage, a1 as MindooDBAppBridgeUiPreferencesChangedMessage, a2 as MindooDBAppBridgeViewChangedMessage, a3 as MindooDBAppBridgeViewportChangedMessage, a4 as MindooDBAppCapability, a5 as MindooDBAppConfiguredViewCategorizationStyle, a6 as MindooDBAppConfiguredViewColumn, a7 as MindooDBAppConfiguredViewColumnRole, a8 as MindooDBAppConfiguredViewExpressionMode, a9 as MindooDBAppConfiguredViewFieldExpression, aa as MindooDBAppConfiguredViewFilterDefinition, ab as MindooDBAppConfiguredViewFilterMode, ac as MindooDBAppConfiguredViewFilterRule, ad as MindooDBAppConfiguredViewFormulaExpression, ae as MindooDBAppConfiguredViewFormulaFilterDefinition, af as MindooDBAppConfiguredViewPreviewMode, ag as MindooDBAppConfiguredViewRuleFilterDefinition, ah as MindooDBAppConfiguredViewRuleMatchMode, ai as MindooDBAppConfiguredViewRuleOperator, aj as MindooDBAppConfiguredViewValueExpression, ak as MindooDBAppCreateDocumentInput, al as MindooDBAppCreateKeyInfo, am as MindooDBAppCreateViewInput, an as MindooDBAppCreateViewNavigatorInput, ao as MindooDBAppDatabaseInfo, ap as MindooDBAppDirectoryApi, aq as MindooDBAppDirectoryEntry, ar as MindooDBAppDocumentApi, as as MindooDBAppDocumentHeadCursorResult, at as MindooDBAppDocumentHistoryEntry, au as MindooDBAppDocumentListQuery, av as MindooDBAppDocumentListResult, aw as MindooDBAppDocumentQuery, ax as MindooDBAppDocumentRevisionId, ay as MindooDBAppDocumentScanPreset, az as MindooDBAppDocumentSummary, aA as MindooDBAppDragApi, aB as MindooDBAppDragCancelReason, aC as MindooDBAppDragDropEvent, aD as MindooDBAppDragEffect, aE as MindooDBAppDragHoverResult, aF as MindooDBAppDragOffer, aG as MindooDBAppDragOverEvent, aH as MindooDBAppDragPointer, aI as MindooDBAppDragProfile, aJ as MindooDBAppEntryAttachmentRef, aK as MindooDBAppEntryProvenance, aL as MindooDBAppExtractDocumentTextInput, aM as MindooDBAppExtractDocumentTextResult, aN as MindooDBAppExtractTextFormat, aO as MindooDBAppExtractionSetup, aP as MindooDBAppFulltextSetup, aQ as MindooDBAppHistoricalDocument, aR as MindooDBAppHistoryQuery, aS as MindooDBAppHostTheme, aT as MindooDBAppIdentityApi, aU as MindooDBAppInaccessibleDocument, aV as MindooDBAppInaccessibleDocumentListQuery, aW as MindooDBAppInaccessibleDocumentListResult, aX as MindooDBAppJsonListDeletePatch, aY as MindooDBAppJsonListInsertPatch, aZ as MindooDBAppJsonPatch, a_ as MindooDBAppJsonSetPatch, a$ as MindooDBAppJsonTextMarkPatch, b0 as MindooDBAppJsonTextSplicePatch, b1 as MindooDBAppJsonTextUnmarkPatch, b2 as MindooDBAppJsonUnsetPatch, b3 as MindooDBAppLaunchContext, b4 as MindooDBAppLiveQuerySubscription, b5 as MindooDBAppMenuAnchor, b6 as MindooDBAppMenuApi, b7 as MindooDBAppMenuCommandItem, b8 as MindooDBAppMenuDismissReason, b9 as MindooDBAppMenuDismissedResult, ba as MindooDBAppMenuItem, bb as MindooDBAppMenuKind, bc as MindooDBAppMenuPlacement, bd as MindooDBAppMenuPointAnchor, be as MindooDBAppMenuRect, bf as MindooDBAppMenuRectAnchor, bg as MindooDBAppMenuSelectionResult, bh as MindooDBAppMenuSeparatorItem, bi as MindooDBAppQueryCoverage, bj as MindooDBAppQueryResult, bk as MindooDBAppQueryRow, bl as MindooDBAppQuerySortKey, bm as MindooDBAppQueryTextClause, bn as MindooDBAppReadableAttachmentStream, bo as MindooDBAppRecipientOptions, bp as MindooDBAppResolvedViewDefinition, bq as MindooDBAppResolvedViewSource, br as MindooDBAppRevisionPhase, bs as MindooDBAppRevisionVerification, bt as MindooDBAppRichTextBlockSpan, bu as MindooDBAppRichTextGetOptions, bv as MindooDBAppRichTextImmutableString, bw as MindooDBAppRichTextMarkRange, bx as MindooDBAppRichTextMaterializeValue, by as MindooDBAppRichTextPatch, bz as MindooDBAppRichTextScalar, bA as MindooDBAppRichTextSpliceStep, bB as MindooDBAppRichTextStep, bC as MindooDBAppRichTextStepPatch, bD as MindooDBAppRichTextTextSpan, bE as MindooDBAppRuntime, bF as MindooDBAppScanAttachmentOptions, bG as MindooDBAppScanAttachmentResult, bH as MindooDBAppScopedDocId, bI as MindooDBAppScopedDocumentSummary, bJ as MindooDBAppSealIntent, bK as MindooDBAppSealedChannelOpenInput, bL as MindooDBAppSealedChannelOpenResult, bM as MindooDBAppSealedChannelRequestInput, bN as MindooDBAppSession, bO as MindooDBAppShowMenuInput, bP as MindooDBAppShowMenuResult, bQ as MindooDBAppSignPreview, bR as MindooDBAppSignPreviewScope, bS as MindooDBAppSignStatementInput, bT as MindooDBAppSignStatementResult, bU as MindooDBAppStorageApi, bV as MindooDBAppTextEdit, bW as MindooDBAppTextPatch, bX as MindooDBAppThemeMode, bY as MindooDBAppTimestampApi, bZ as MindooDBAppTimestampInput, b_ as MindooDBAppTimestampProvider, b$ as MindooDBAppTimestampResult, c0 as MindooDBAppUiPreferences, c1 as MindooDBAppUpdateDocumentInput, c2 as MindooDBAppViewCursorDocumentListResult, c3 as MindooDBAppViewCursorResult, c4 as MindooDBAppViewEntry, c5 as MindooDBAppViewEntryKind, c6 as MindooDBAppViewNavigator, c7 as MindooDBAppViewNavigatorExpansionState, c8 as MindooDBAppViewNavigatorOpenOptions, c9 as MindooDBAppViewNavigatorPageOptions, ca as MindooDBAppViewNavigatorPageResult, cb as MindooDBAppViewNavigatorRangeQuery, cc as MindooDBAppViewNavigatorSelectionState, cd as MindooDBAppViewUpdateStats, ce as MindooDBAppViewport, cf as MindooDBAppWellKnownDragType, cg as MindooDBAppWritableAttachmentStream } from './types-M3RwHErO.js';
|
|
3
3
|
export { M as MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME, a as MINDOODB_APP_BUNDLE_MANIFEST_FILE_NAME, b as MINDOODB_APP_BUNDLE_MANIFEST_FORMAT, c as MINDOODB_APP_BUNDLE_MANIFEST_VERSION, d as MindooDBAppBundleArchive, e as MindooDBAppBundleFileEntry, f as MindooDBAppBundleHash, g as MindooDBAppBundleManifest, h as MindooDBAppBundleManifestValidation, i as buildMindooDBAppBundleContentHashInput, j as isMindooDBAppBundleHash, n as normalizeMindooDBAppBundlePath, v as validateMindooDBAppBundleManifest } from './appBundleManifest-B0xfpaXG.js';
|
|
4
4
|
import { MindooDBAppBooleanExpression } from 'mindoodb-view-language';
|
|
5
5
|
export { MindooDBAppBooleanExpression, MindooDBAppExpression, MindooDBAppFilterDefinition, MindooDBAppViewCategoryChildrenPageRequest, MindooDBAppViewColumn, MindooDBAppViewColumnRole, MindooDBAppViewDefinition, MindooDBAppViewExpansionState, MindooDBAppViewExpressionBase, MindooDBAppViewExpressionDatePart, MindooDBAppViewExpressionOperation, MindooDBAppViewFieldExpression, MindooDBAppViewIfExpression, MindooDBAppViewLetExpression, MindooDBAppViewLiteralExpression, MindooDBAppViewLookupByPath, MindooDBAppViewOperationExpression, MindooDBAppViewOriginExpression, MindooDBAppViewPageRequest, MindooDBAppViewPageResult, MindooDBAppViewRow, MindooDBAppViewSortDirection, MindooDBAppViewTotalMode, MindooDBAppViewValueExpressionRef, MindooDBAppViewVariableExpression, createViewLanguage } from 'mindoodb-view-language';
|
|
@@ -31,6 +31,57 @@ declare function abbreviateCanonicalName(value: string): string;
|
|
|
31
31
|
*/
|
|
32
32
|
declare function expandAbbreviatedName(value: string): string;
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Client helpers for host-owned cross-iframe drag.
|
|
36
|
+
*
|
|
37
|
+
* Validation lives here so the SDK rejects bad `start` / `setProfile`
|
|
38
|
+
* payloads before they cross the bridge. Haven re-validates the same
|
|
39
|
+
* limits on untyped JSON. `bindDragSource` and `snapshotElementToPng`
|
|
40
|
+
* stay in the app document: Haven only ever receives PNG bytes and
|
|
41
|
+
* string snapshots.
|
|
42
|
+
*
|
|
43
|
+
* @module drag
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/** Maximum number of types in one profile or start payload. */
|
|
47
|
+
declare const MINDOODB_APP_MAX_DRAG_TYPES = 8;
|
|
48
|
+
/** Maximum UTF-8 size of one offer string. */
|
|
49
|
+
declare const MINDOODB_APP_MAX_DRAG_PAYLOAD_BYTES: number;
|
|
50
|
+
/** Maximum encoded PNG size for the host ghost. */
|
|
51
|
+
declare const MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES: number;
|
|
52
|
+
/** Longest CSS-pixel edge Haven will display for a ghost. */
|
|
53
|
+
declare const MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE = 512;
|
|
54
|
+
/** Touch hold before the host takes over. */
|
|
55
|
+
declare const DEFAULT_DRAG_LONG_PRESS_MS = 400;
|
|
56
|
+
/** Mouse/pen start distance, and touch scroll-cancel slop. */
|
|
57
|
+
declare const DEFAULT_DRAG_POINTER_THRESHOLD_PX = 8;
|
|
58
|
+
/**
|
|
59
|
+
* 1×1 PNG used when the browser cannot snapshot a node. Haven still
|
|
60
|
+
* sizes the ghost from `preview.width` / `preview.height`.
|
|
61
|
+
*/
|
|
62
|
+
declare const MINIMAL_DRAG_PREVIEW_PNG: Uint8Array<ArrayBuffer>;
|
|
63
|
+
/** Structured validation failure. `name` is the bridge error code. */
|
|
64
|
+
declare class MindooDBAppDragInputError extends Error {
|
|
65
|
+
name: string;
|
|
66
|
+
constructor(message: string);
|
|
67
|
+
}
|
|
68
|
+
/** True when `type` is a MIME-like token Haven will accept. */
|
|
69
|
+
declare function isMindooDBAppDragType(type: string): boolean;
|
|
70
|
+
/** Project and validate the `accepts` list sent with `drag.setProfile`. */
|
|
71
|
+
declare function normalizeDragAccepts(value: unknown): string[];
|
|
72
|
+
/** Project and validate a `drag.start` payload. */
|
|
73
|
+
declare function normalizeDragStartInput(value: unknown): MindooDBAppDragStartInput;
|
|
74
|
+
/**
|
|
75
|
+
* Snapshot an element in the app document. Failures fall back to a labeled
|
|
76
|
+
* card or a 1×1 PNG — Haven must never receive HTML.
|
|
77
|
+
*/
|
|
78
|
+
declare function snapshotElementToPng(element: HTMLElement): Promise<MindooDBAppDragPreview>;
|
|
79
|
+
/**
|
|
80
|
+
* Start a host drag from a pointer gesture. Mouse/pen use a move threshold;
|
|
81
|
+
* touch waits for a long-press so lists can still scroll.
|
|
82
|
+
*/
|
|
83
|
+
declare function bindDragSource(element: HTMLElement, options: MindooDBAppDragBindSourceOptions, start: (input: MindooDBAppDragStartInput) => Promise<MindooDBAppDragStartResult>): () => void;
|
|
84
|
+
|
|
34
85
|
/**
|
|
35
86
|
* Drops memoised sessions so the next `connect()` performs a fresh handshake.
|
|
36
87
|
*
|
|
@@ -306,4 +357,4 @@ declare function createMindooDBTextBuffer(options: CreateMindooDBTextBufferOptio
|
|
|
306
357
|
*/
|
|
307
358
|
declare function queryDocuments(db: Pick<MindooDB, "query">, filter: MindooDBAppBooleanExpression | string, sortBy?: MindooQuerySortKey[], options?: MindooQueryOptions): Promise<MindooQueryResult>;
|
|
308
359
|
|
|
309
|
-
export { type CreateMindooDBRichTextHandleOptions, type CreateMindooDBTextBufferOptions, DEFAULT_HAVEN_HOST_SHORTCUTS, type HavenStorageShimHandle, type InstallHavenStorageShimOptions, MINDOODB_APP_HOSTING_QUERY_PARAM, MindooDBAppAttachmentPreviewMode, MindooDBAppBridge, MindooDBAppDatabase, MindooDBAppDocument, MindooDBAppHostShortcutAction, MindooDBAppHostShortcutBinding, MindooDBAppHostingMode, MindooDBAppRichTextSnapshot, MindooDBAppRichTextSpan, MindooDBRichTextHandle, type MindooDBRichTextHandleChangeListener, type MindooDBRichTextHandleFlushResult, MindooDBTextBuffer, type MindooDBTextBufferFlushResult, abbreviateCanonicalName, applyHostedDocumentOverscrollContain, canPreviewAttachment, createMindooDBAppBridge, createMindooDBRichTextHandle, createMindooDBTextBuffer, expandAbbreviatedName, installHavenStorageShim, installHostShortcutCapture, isHostShortcutAction, isHostedBundleRuntime, matchHostShortcut, queryDocuments, readMindooDBAppHostingMode, releaseMindooDBAppBridgeSessions, sanitizeHostShortcutBindings };
|
|
360
|
+
export { type CreateMindooDBRichTextHandleOptions, type CreateMindooDBTextBufferOptions, DEFAULT_DRAG_LONG_PRESS_MS, DEFAULT_DRAG_POINTER_THRESHOLD_PX, DEFAULT_HAVEN_HOST_SHORTCUTS, type HavenStorageShimHandle, type InstallHavenStorageShimOptions, MINDOODB_APP_HOSTING_QUERY_PARAM, MINDOODB_APP_MAX_DRAG_PAYLOAD_BYTES, MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES, MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE, MINDOODB_APP_MAX_DRAG_TYPES, MINIMAL_DRAG_PREVIEW_PNG, MindooDBAppAttachmentPreviewMode, MindooDBAppBridge, MindooDBAppDatabase, MindooDBAppDocument, MindooDBAppDragBindSourceOptions, MindooDBAppDragInputError, MindooDBAppDragPreview, MindooDBAppDragStartInput, MindooDBAppDragStartResult, MindooDBAppHostShortcutAction, MindooDBAppHostShortcutBinding, MindooDBAppHostingMode, MindooDBAppRichTextSnapshot, MindooDBAppRichTextSpan, MindooDBRichTextHandle, type MindooDBRichTextHandleChangeListener, type MindooDBRichTextHandleFlushResult, MindooDBTextBuffer, type MindooDBTextBufferFlushResult, abbreviateCanonicalName, applyHostedDocumentOverscrollContain, bindDragSource, canPreviewAttachment, createMindooDBAppBridge, createMindooDBRichTextHandle, createMindooDBTextBuffer, expandAbbreviatedName, installHavenStorageShim, installHostShortcutCapture, isHostShortcutAction, isHostedBundleRuntime, isMindooDBAppDragType, matchHostShortcut, normalizeDragAccepts, normalizeDragStartInput, queryDocuments, readMindooDBAppHostingMode, releaseMindooDBAppBridgeSessions, sanitizeHostShortcutBindings, snapshotElementToPng };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_DRAG_LONG_PRESS_MS,
|
|
3
|
+
DEFAULT_DRAG_POINTER_THRESHOLD_PX,
|
|
2
4
|
DEFAULT_HAVEN_HOST_SHORTCUTS,
|
|
5
|
+
MINDOODB_APP_MAX_DRAG_PAYLOAD_BYTES,
|
|
6
|
+
MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES,
|
|
7
|
+
MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE,
|
|
8
|
+
MINDOODB_APP_MAX_DRAG_TYPES,
|
|
9
|
+
MINIMAL_DRAG_PREVIEW_PNG,
|
|
10
|
+
MindooDBAppDragInputError,
|
|
3
11
|
applyHostedDocumentOverscrollContain,
|
|
12
|
+
bindDragSource,
|
|
4
13
|
createMindooDBAppBridge,
|
|
5
14
|
installHostShortcutCapture,
|
|
6
15
|
isHostShortcutAction,
|
|
16
|
+
isMindooDBAppDragType,
|
|
7
17
|
matchHostShortcut,
|
|
18
|
+
normalizeDragAccepts,
|
|
19
|
+
normalizeDragStartInput,
|
|
8
20
|
releaseMindooDBAppBridgeSessions,
|
|
9
|
-
sanitizeHostShortcutBindings
|
|
10
|
-
|
|
21
|
+
sanitizeHostShortcutBindings,
|
|
22
|
+
snapshotElementToPng
|
|
23
|
+
} from "./chunk-ZO7UE6B2.js";
|
|
11
24
|
import {
|
|
12
25
|
MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME,
|
|
13
26
|
MINDOODB_APP_BUNDLE_MANIFEST_FILE_NAME,
|
|
@@ -20,6 +33,12 @@ import {
|
|
|
20
33
|
} from "./chunk-LT4FK6LU.js";
|
|
21
34
|
|
|
22
35
|
// src/types.ts
|
|
36
|
+
var MINDOODB_APP_WELL_KNOWN_DRAG_TYPES = [
|
|
37
|
+
"text/plain",
|
|
38
|
+
"text/markdown",
|
|
39
|
+
"application/json",
|
|
40
|
+
"application/x-mindoo-document"
|
|
41
|
+
];
|
|
23
42
|
var MINDOODB_APP_SEAL_SIGNING_DOMAIN = "mindoodb-seal/v1";
|
|
24
43
|
|
|
25
44
|
// src/attachmentPreview.ts
|
|
@@ -753,17 +772,27 @@ async function queryDocuments(db, filter, sortBy, options) {
|
|
|
753
772
|
return db.query({ filter: expression, sortBy }, options);
|
|
754
773
|
}
|
|
755
774
|
export {
|
|
775
|
+
DEFAULT_DRAG_LONG_PRESS_MS,
|
|
776
|
+
DEFAULT_DRAG_POINTER_THRESHOLD_PX,
|
|
756
777
|
DEFAULT_HAVEN_HOST_SHORTCUTS,
|
|
757
778
|
MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME,
|
|
758
779
|
MINDOODB_APP_BUNDLE_MANIFEST_FILE_NAME,
|
|
759
780
|
MINDOODB_APP_BUNDLE_MANIFEST_FORMAT,
|
|
760
781
|
MINDOODB_APP_BUNDLE_MANIFEST_VERSION,
|
|
761
782
|
MINDOODB_APP_HOSTING_QUERY_PARAM,
|
|
783
|
+
MINDOODB_APP_MAX_DRAG_PAYLOAD_BYTES,
|
|
784
|
+
MINDOODB_APP_MAX_DRAG_PREVIEW_BYTES,
|
|
785
|
+
MINDOODB_APP_MAX_DRAG_PREVIEW_EDGE,
|
|
786
|
+
MINDOODB_APP_MAX_DRAG_TYPES,
|
|
762
787
|
MINDOODB_APP_SEAL_SIGNING_DOMAIN,
|
|
788
|
+
MINDOODB_APP_WELL_KNOWN_DRAG_TYPES,
|
|
789
|
+
MINIMAL_DRAG_PREVIEW_PNG,
|
|
790
|
+
MindooDBAppDragInputError,
|
|
763
791
|
MindooDBRichTextHandle,
|
|
764
792
|
MindooDBTextBuffer,
|
|
765
793
|
abbreviateCanonicalName,
|
|
766
794
|
applyHostedDocumentOverscrollContain,
|
|
795
|
+
bindDragSource,
|
|
767
796
|
buildMindooDBAppBundleContentHashInput,
|
|
768
797
|
canPreviewAttachment,
|
|
769
798
|
createMindooDBAppBridge,
|
|
@@ -776,11 +805,15 @@ export {
|
|
|
776
805
|
isHostShortcutAction,
|
|
777
806
|
isHostedBundleRuntime,
|
|
778
807
|
isMindooDBAppBundleHash,
|
|
808
|
+
isMindooDBAppDragType,
|
|
779
809
|
matchHostShortcut,
|
|
810
|
+
normalizeDragAccepts,
|
|
811
|
+
normalizeDragStartInput,
|
|
780
812
|
normalizeMindooDBAppBundlePath,
|
|
781
813
|
queryDocuments,
|
|
782
814
|
readMindooDBAppHostingMode,
|
|
783
815
|
releaseMindooDBAppBridgeSessions,
|
|
784
816
|
sanitizeHostShortcutBindings,
|
|
817
|
+
snapshotElementToPng,
|
|
785
818
|
validateMindooDBAppBundleManifest
|
|
786
819
|
};
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { an as MindooDBAppCreateViewNavigatorInput, c6 as MindooDBAppViewNavigator, b3 as MindooDBAppLaunchContext, ao as MindooDBAppDatabaseInfo, ar as MindooDBAppDocumentApi, c8 as MindooDBAppViewNavigatorOpenOptions, q as MindooDBAppAttachmentApi, aT as MindooDBAppIdentityApi, bY as MindooDBAppTimestampApi, ap as MindooDBAppDirectoryApi, j as MindooDBAppDocument, aP as MindooDBAppFulltextSetup, aO as MindooDBAppExtractionSetup, e as MindooDBAppBridge, bN as MindooDBAppSession, Q as MindooDBAppBridgeRpcRequest, aS as MindooDBAppHostTheme, ce as MindooDBAppViewport, c0 as MindooDBAppUiPreferences, bj as MindooDBAppQueryResult, cd as MindooDBAppViewUpdateStats, L as MindooDBAppBridgePortMessage, c as MindooDBAppDragStartResult, aI as MindooDBAppDragProfile } from '../types-M3RwHErO.js';
|
|
2
2
|
import * as mindoodb from 'mindoodb';
|
|
3
3
|
import 'mindoodb-view-language';
|
|
4
4
|
|
|
@@ -115,6 +115,8 @@ interface MockMindooDBAppSessionController {
|
|
|
115
115
|
emitLocaleChange(locale: string): void;
|
|
116
116
|
/** Runs the app's `onBeforeClose` listeners, as the host does before a teardown. */
|
|
117
117
|
emitBeforeClose(): Promise<void>;
|
|
118
|
+
resolveDrag(result: MindooDBAppDragStartResult): void;
|
|
119
|
+
getDragProfile(): MindooDBAppDragProfile | null;
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
declare function createMockMindooDBAppSession(options?: CreateMockMindooDBAppSessionOptions): MockMindooDBAppSessionController;
|
package/dist/testing/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
releaseMindooDBAppBridgeSessions
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-ZO7UE6B2.js";
|
|
4
4
|
|
|
5
5
|
// src/testing/index.ts
|
|
6
6
|
import * as Automerge from "@automerge/automerge";
|
|
@@ -1857,6 +1857,8 @@ function createMockSessionState(options = {}) {
|
|
|
1857
1857
|
const databaseViewApis = /* @__PURE__ */ new Map();
|
|
1858
1858
|
const sessionViews = /* @__PURE__ */ new Map();
|
|
1859
1859
|
let activeMenuResolve = null;
|
|
1860
|
+
let activeDragResolve = null;
|
|
1861
|
+
let dragProfile = null;
|
|
1860
1862
|
let databaseInfos = [];
|
|
1861
1863
|
const openSealedChannels = /* @__PURE__ */ new Map();
|
|
1862
1864
|
const appStorage = new Map(Object.entries(options.storage ?? {}));
|
|
@@ -1871,6 +1873,32 @@ function createMockSessionState(options = {}) {
|
|
|
1871
1873
|
);
|
|
1872
1874
|
}
|
|
1873
1875
|
};
|
|
1876
|
+
const drag = {
|
|
1877
|
+
async setProfile(profile) {
|
|
1878
|
+
dragProfile = profile;
|
|
1879
|
+
},
|
|
1880
|
+
async start(_input) {
|
|
1881
|
+
if (activeDragResolve) {
|
|
1882
|
+
activeDragResolve({
|
|
1883
|
+
action: "cancelled",
|
|
1884
|
+
reason: "replaced"
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
return await new Promise((resolve) => {
|
|
1888
|
+
activeDragResolve = resolve;
|
|
1889
|
+
});
|
|
1890
|
+
},
|
|
1891
|
+
async cancel() {
|
|
1892
|
+
activeDragResolve?.({
|
|
1893
|
+
action: "cancelled",
|
|
1894
|
+
reason: "source_cancelled"
|
|
1895
|
+
});
|
|
1896
|
+
activeDragResolve = null;
|
|
1897
|
+
},
|
|
1898
|
+
bindSource() {
|
|
1899
|
+
return () => void 0;
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1874
1902
|
const menus = {
|
|
1875
1903
|
async show(_input) {
|
|
1876
1904
|
if (activeMenuResolve) {
|
|
@@ -2023,6 +2051,7 @@ function createMockSessionState(options = {}) {
|
|
|
2023
2051
|
return view;
|
|
2024
2052
|
},
|
|
2025
2053
|
menus,
|
|
2054
|
+
drag,
|
|
2026
2055
|
storage: {
|
|
2027
2056
|
async snapshot(snapshotOptions) {
|
|
2028
2057
|
const prefixes = snapshotOptions?.prefixes;
|
|
@@ -2146,6 +2175,13 @@ function createMockSessionState(options = {}) {
|
|
|
2146
2175
|
},
|
|
2147
2176
|
async emitBeforeClose() {
|
|
2148
2177
|
await Promise.all([...beforeCloseListeners].map(async (listener) => listener()));
|
|
2178
|
+
},
|
|
2179
|
+
resolveDrag(result) {
|
|
2180
|
+
activeDragResolve?.(result);
|
|
2181
|
+
activeDragResolve = null;
|
|
2182
|
+
},
|
|
2183
|
+
getDragProfile() {
|
|
2184
|
+
return dragProfile;
|
|
2149
2185
|
}
|
|
2150
2186
|
};
|
|
2151
2187
|
}
|
|
@@ -2163,7 +2199,9 @@ function createMockMindooDBAppSession(options = {}) {
|
|
|
2163
2199
|
emitViewportChange: state.emitViewportChange,
|
|
2164
2200
|
emitUiPreferencesChange: state.emitUiPreferencesChange,
|
|
2165
2201
|
emitLocaleChange: state.emitLocaleChange,
|
|
2166
|
-
emitBeforeClose: state.emitBeforeClose
|
|
2202
|
+
emitBeforeClose: state.emitBeforeClose,
|
|
2203
|
+
resolveDrag: state.resolveDrag,
|
|
2204
|
+
getDragProfile: state.getDragProfile
|
|
2167
2205
|
};
|
|
2168
2206
|
}
|
|
2169
2207
|
function createMockMindooDBAppBridge(options = {}) {
|
|
@@ -979,7 +979,7 @@ interface MindooDBAppBridgeShortcutInvokedMessage {
|
|
|
979
979
|
action: MindooDBAppHostShortcutAction;
|
|
980
980
|
}
|
|
981
981
|
/** Any message that can travel across the dedicated bridge MessagePort. */
|
|
982
|
-
type MindooDBAppBridgePortMessage = MindooDBAppBridgeRpcMessage | MindooDBAppBridgeStreamMessage | MindooDBAppBridgeThemeChangedMessage | MindooDBAppBridgeViewportChangedMessage | MindooDBAppBridgeUiPreferencesChangedMessage | MindooDBAppBridgeLocaleChangedMessage | MindooDBAppBridgeQueryResultMessage | MindooDBAppBridgeViewChangedMessage | MindooDBAppBridgeBeforeCloseMessage | MindooDBAppBridgeBeforeCloseAck | MindooDBAppBridgeShortcutsChangedMessage | MindooDBAppBridgeShortcutInvokedMessage;
|
|
982
|
+
type MindooDBAppBridgePortMessage = MindooDBAppBridgeRpcMessage | MindooDBAppBridgeStreamMessage | MindooDBAppBridgeThemeChangedMessage | MindooDBAppBridgeViewportChangedMessage | MindooDBAppBridgeUiPreferencesChangedMessage | MindooDBAppBridgeLocaleChangedMessage | MindooDBAppBridgeQueryResultMessage | MindooDBAppBridgeViewChangedMessage | MindooDBAppBridgeBeforeCloseMessage | MindooDBAppBridgeBeforeCloseAck | MindooDBAppBridgeShortcutsChangedMessage | MindooDBAppBridgeShortcutInvokedMessage | MindooDBAppBridgeDragOverMessage | MindooDBAppBridgeDragLeaveMessage | MindooDBAppBridgeDragDropMessage;
|
|
983
983
|
/** Placement hint for a host-rendered overlay menu. */
|
|
984
984
|
type MindooDBAppMenuPlacement = "auto" | "bottom-start" | "bottom-end" | "top-start" | "top-end" | "right-start" | "left-start";
|
|
985
985
|
/** Semantic hint allowing Haven to tune menu behavior or styling. */
|
|
@@ -1053,6 +1053,125 @@ type MindooDBAppShowMenuResult = MindooDBAppMenuSelectionResult | MindooDBAppMen
|
|
|
1053
1053
|
* data-only (no HTML/CSS/script crosses the bridge). Intended for
|
|
1054
1054
|
* `runtime === "iframe"`; window-mode apps can usually render local menus.
|
|
1055
1055
|
*/
|
|
1056
|
+
/** Well-known copy payloads for host-owned cross-iframe drag. */
|
|
1057
|
+
declare const MINDOODB_APP_WELL_KNOWN_DRAG_TYPES: readonly ["text/plain", "text/markdown", "application/json", "application/x-mindoo-document"];
|
|
1058
|
+
/** One of the documented interchange types apps should prefer. */
|
|
1059
|
+
type MindooDBAppWellKnownDragType = (typeof MINDOODB_APP_WELL_KNOWN_DRAG_TYPES)[number];
|
|
1060
|
+
/** Copy is the only effect in v1. `forbidden` is a hover result, not an offer. */
|
|
1061
|
+
type MindooDBAppDragEffect = "copy" | "forbidden";
|
|
1062
|
+
/** One typed string snapshot offered at `drag.start`. */
|
|
1063
|
+
interface MindooDBAppDragOffer {
|
|
1064
|
+
type: string;
|
|
1065
|
+
data: string;
|
|
1066
|
+
}
|
|
1067
|
+
/** PNG ghost sent to Haven. Haven never receives HTML. */
|
|
1068
|
+
interface MindooDBAppDragPreview {
|
|
1069
|
+
png: ArrayBuffer;
|
|
1070
|
+
width: number;
|
|
1071
|
+
height: number;
|
|
1072
|
+
hotspotX: number;
|
|
1073
|
+
hotspotY: number;
|
|
1074
|
+
}
|
|
1075
|
+
/** Iframe-viewport pointer at the moment the host should take over. */
|
|
1076
|
+
interface MindooDBAppDragPointer {
|
|
1077
|
+
x: number;
|
|
1078
|
+
y: number;
|
|
1079
|
+
}
|
|
1080
|
+
/** Input for a host-owned drag gesture. Iframe-only, copy-only. */
|
|
1081
|
+
interface MindooDBAppDragStartInput {
|
|
1082
|
+
offers: MindooDBAppDragOffer[];
|
|
1083
|
+
preview: MindooDBAppDragPreview;
|
|
1084
|
+
pointer: MindooDBAppDragPointer;
|
|
1085
|
+
allowedEffects?: Array<"copy">;
|
|
1086
|
+
}
|
|
1087
|
+
/** Why a host drag ended without a copy. */
|
|
1088
|
+
type MindooDBAppDragCancelReason = "escape" | "pointercancel" | "gap" | "replaced" | "hide" | "source_cancelled";
|
|
1089
|
+
/** Result of `session.drag.start`. */
|
|
1090
|
+
type MindooDBAppDragStartResult = {
|
|
1091
|
+
action: "copied";
|
|
1092
|
+
} | {
|
|
1093
|
+
action: "cancelled";
|
|
1094
|
+
reason: MindooDBAppDragCancelReason;
|
|
1095
|
+
};
|
|
1096
|
+
/** Coordinates and offered types pushed to a potential drop target. */
|
|
1097
|
+
interface MindooDBAppDragOverEvent {
|
|
1098
|
+
x: number;
|
|
1099
|
+
y: number;
|
|
1100
|
+
types: string[];
|
|
1101
|
+
}
|
|
1102
|
+
/** Target answer after hit-testing a `drag-over`. */
|
|
1103
|
+
interface MindooDBAppDragHoverResult {
|
|
1104
|
+
accept: boolean;
|
|
1105
|
+
effect?: MindooDBAppDragEffect;
|
|
1106
|
+
}
|
|
1107
|
+
/** Copy payloads delivered to the target on drop. */
|
|
1108
|
+
interface MindooDBAppDragDropEvent {
|
|
1109
|
+
x: number;
|
|
1110
|
+
y: number;
|
|
1111
|
+
items: Record<string, string>;
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* What this launch can receive, plus in-app callbacks. `accepts` is sent to
|
|
1115
|
+
* Haven; the callbacks stay in the SDK and run from host push events.
|
|
1116
|
+
*/
|
|
1117
|
+
interface MindooDBAppDragProfile {
|
|
1118
|
+
accepts: string[];
|
|
1119
|
+
onOver?: (event: MindooDBAppDragOverEvent) => MindooDBAppDragHoverResult | void;
|
|
1120
|
+
onLeave?: () => void;
|
|
1121
|
+
onDrop?: (event: MindooDBAppDragDropEvent) => void;
|
|
1122
|
+
}
|
|
1123
|
+
/** Options for `session.drag.bindSource`. */
|
|
1124
|
+
interface MindooDBAppDragBindSourceOptions {
|
|
1125
|
+
offers: MindooDBAppDragOffer[] | (() => MindooDBAppDragOffer[]);
|
|
1126
|
+
/** Touch only: hold this long before Haven takes over. Default 400. */
|
|
1127
|
+
longPressMs?: number;
|
|
1128
|
+
/** Mouse/pen move, or the scroll-cancel slop on touch. Default 8. */
|
|
1129
|
+
pointerThresholdPx?: number;
|
|
1130
|
+
/** Element to snapshot; defaults to the bound source element. */
|
|
1131
|
+
preview?: HTMLElement | (() => HTMLElement);
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Host-owned drag across iframe chicklets. Haven renders the ghost above
|
|
1135
|
+
* every frame; apps only start the gesture and hit-test drops.
|
|
1136
|
+
*/
|
|
1137
|
+
interface MindooDBAppDragApi {
|
|
1138
|
+
/** Tell Haven which types this launch can receive. */
|
|
1139
|
+
setProfile(profile: MindooDBAppDragProfile): Promise<void>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Hand the gesture to Haven. Resolves when the copy completes or the
|
|
1142
|
+
* user cancels. Iframe-only.
|
|
1143
|
+
*/
|
|
1144
|
+
start(input: MindooDBAppDragStartInput): Promise<MindooDBAppDragStartResult>;
|
|
1145
|
+
/** Abort a gesture this app started. */
|
|
1146
|
+
cancel(): Promise<void>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Pointer helper: mouse/pen starts after a small move; touch starts after
|
|
1149
|
+
* a long-press. Each element can be bound independently; the returned
|
|
1150
|
+
* function unbinds only that element.
|
|
1151
|
+
*/
|
|
1152
|
+
bindSource(element: HTMLElement, options: MindooDBAppDragBindSourceOptions): () => void;
|
|
1153
|
+
}
|
|
1154
|
+
/** Host → target: pointer is over this iframe. */
|
|
1155
|
+
interface MindooDBAppBridgeDragOverMessage {
|
|
1156
|
+
protocol: "mindoodb-app-bridge";
|
|
1157
|
+
kind: "drag-over";
|
|
1158
|
+
x: number;
|
|
1159
|
+
y: number;
|
|
1160
|
+
types: string[];
|
|
1161
|
+
}
|
|
1162
|
+
/** Host → previous target: pointer left this iframe. */
|
|
1163
|
+
interface MindooDBAppBridgeDragLeaveMessage {
|
|
1164
|
+
protocol: "mindoodb-app-bridge";
|
|
1165
|
+
kind: "drag-leave";
|
|
1166
|
+
}
|
|
1167
|
+
/** Host → target: copy payloads for the types this launch accepts. */
|
|
1168
|
+
interface MindooDBAppBridgeDragDropMessage {
|
|
1169
|
+
protocol: "mindoodb-app-bridge";
|
|
1170
|
+
kind: "drag-drop";
|
|
1171
|
+
x: number;
|
|
1172
|
+
y: number;
|
|
1173
|
+
items: Record<string, string>;
|
|
1174
|
+
}
|
|
1056
1175
|
interface MindooDBAppMenuApi {
|
|
1057
1176
|
/**
|
|
1058
1177
|
* Show a host-rendered menu at the given anchor (iframe-relative
|
|
@@ -2191,6 +2310,8 @@ interface MindooDBAppSession {
|
|
|
2191
2310
|
*/
|
|
2192
2311
|
openViewNavigator(viewId: string, options?: MindooDBAppViewNavigatorOpenOptions): Promise<MindooDBAppViewNavigator>;
|
|
2193
2312
|
menus: MindooDBAppMenuApi;
|
|
2313
|
+
/** Host-owned cross-iframe drag. Iframe-only; copy-only in v1. */
|
|
2314
|
+
drag: MindooDBAppDragApi;
|
|
2194
2315
|
/**
|
|
2195
2316
|
* Host-backed key/value storage for this app registration. Usable in both hosting
|
|
2196
2317
|
* modes; required in `"hosted"` mode, where `localStorage` throws.
|
|
@@ -2248,4 +2369,4 @@ interface MindooDBAppBridge {
|
|
|
2248
2369
|
connect(options?: MindooDBAppBridgeConnectOptions): Promise<MindooDBAppSession>;
|
|
2249
2370
|
}
|
|
2250
2371
|
|
|
2251
|
-
export { type
|
|
2372
|
+
export { type MindooDBAppBridgeStreamWriteRequest as $, type MindooDBAppBridgeBeforeCloseAck as A, type MindooDBAppBridgeBeforeCloseMessage as B, type MindooDBAppBridgeConnectMessage as C, type MindooDBAppBridgeConnectOptions as D, type MindooDBAppBridgeConnectedMessage as E, type MindooDBAppBridgeDragDropMessage as F, type MindooDBAppBridgeDragLeaveMessage as G, type MindooDBAppBridgeDragOverMessage as H, type MindooDBAppBridgeErrorPayload as I, type MindooDBAppBridgeHandshakeErrorMessage as J, type MindooDBAppBridgeLocaleChangedMessage as K, type MindooDBAppBridgePortMessage as L, type MindooDBAppAttachmentPreviewMode as M, type MindooDBAppBridgeQueryResultMessage as N, type MindooDBAppBridgeRpcError as O, type MindooDBAppBridgeRpcMessage as P, type MindooDBAppBridgeRpcRequest as Q, type MindooDBAppBridgeRpcSuccess as R, type MindooDBAppBridgeShortcutInvokedMessage as S, type MindooDBAppBridgeShortcutsChangedMessage as T, type MindooDBAppBridgeStreamAbortRequest as U, type MindooDBAppBridgeStreamAck as V, type MindooDBAppBridgeStreamCloseRequest as W, type MindooDBAppBridgeStreamError as X, type MindooDBAppBridgeStreamMessage as Y, type MindooDBAppBridgeStreamOpenResult as Z, type MindooDBAppBridgeStreamReadRequest as _, type MindooDBAppDragBindSourceOptions as a, type MindooDBAppJsonTextMarkPatch as a$, type MindooDBAppBridgeThemeChangedMessage as a0, type MindooDBAppBridgeUiPreferencesChangedMessage as a1, type MindooDBAppBridgeViewChangedMessage as a2, type MindooDBAppBridgeViewportChangedMessage as a3, type MindooDBAppCapability as a4, type MindooDBAppConfiguredViewCategorizationStyle as a5, type MindooDBAppConfiguredViewColumn as a6, type MindooDBAppConfiguredViewColumnRole as a7, type MindooDBAppConfiguredViewExpressionMode as a8, type MindooDBAppConfiguredViewFieldExpression as a9, type MindooDBAppDragApi as aA, type MindooDBAppDragCancelReason as aB, type MindooDBAppDragDropEvent as aC, type MindooDBAppDragEffect as aD, type MindooDBAppDragHoverResult as aE, type MindooDBAppDragOffer as aF, type MindooDBAppDragOverEvent as aG, type MindooDBAppDragPointer as aH, type MindooDBAppDragProfile as aI, type MindooDBAppEntryAttachmentRef as aJ, type MindooDBAppEntryProvenance as aK, type MindooDBAppExtractDocumentTextInput as aL, type MindooDBAppExtractDocumentTextResult as aM, type MindooDBAppExtractTextFormat as aN, type MindooDBAppExtractionSetup as aO, type MindooDBAppFulltextSetup as aP, type MindooDBAppHistoricalDocument as aQ, type MindooDBAppHistoryQuery as aR, type MindooDBAppHostTheme as aS, type MindooDBAppIdentityApi as aT, type MindooDBAppInaccessibleDocument as aU, type MindooDBAppInaccessibleDocumentListQuery as aV, type MindooDBAppInaccessibleDocumentListResult as aW, type MindooDBAppJsonListDeletePatch as aX, type MindooDBAppJsonListInsertPatch as aY, type MindooDBAppJsonPatch as aZ, type MindooDBAppJsonSetPatch as a_, type MindooDBAppConfiguredViewFilterDefinition as aa, type MindooDBAppConfiguredViewFilterMode as ab, type MindooDBAppConfiguredViewFilterRule as ac, type MindooDBAppConfiguredViewFormulaExpression as ad, type MindooDBAppConfiguredViewFormulaFilterDefinition as ae, type MindooDBAppConfiguredViewPreviewMode as af, type MindooDBAppConfiguredViewRuleFilterDefinition as ag, type MindooDBAppConfiguredViewRuleMatchMode as ah, type MindooDBAppConfiguredViewRuleOperator as ai, type MindooDBAppConfiguredViewValueExpression as aj, type MindooDBAppCreateDocumentInput as ak, type MindooDBAppCreateKeyInfo as al, type MindooDBAppCreateViewInput as am, type MindooDBAppCreateViewNavigatorInput as an, type MindooDBAppDatabaseInfo as ao, type MindooDBAppDirectoryApi as ap, type MindooDBAppDirectoryEntry as aq, type MindooDBAppDocumentApi as ar, type MindooDBAppDocumentHeadCursorResult as as, type MindooDBAppDocumentHistoryEntry as at, type MindooDBAppDocumentListQuery as au, type MindooDBAppDocumentListResult as av, type MindooDBAppDocumentQuery as aw, type MindooDBAppDocumentRevisionId as ax, type MindooDBAppDocumentScanPreset as ay, type MindooDBAppDocumentSummary as az, type MindooDBAppDragStartInput as b, type MindooDBAppTimestampResult as b$, type MindooDBAppJsonTextSplicePatch as b0, type MindooDBAppJsonTextUnmarkPatch as b1, type MindooDBAppJsonUnsetPatch as b2, type MindooDBAppLaunchContext as b3, type MindooDBAppLiveQuerySubscription as b4, type MindooDBAppMenuAnchor as b5, type MindooDBAppMenuApi as b6, type MindooDBAppMenuCommandItem as b7, type MindooDBAppMenuDismissReason as b8, type MindooDBAppMenuDismissedResult as b9, type MindooDBAppRichTextSpliceStep as bA, type MindooDBAppRichTextStep as bB, type MindooDBAppRichTextStepPatch as bC, type MindooDBAppRichTextTextSpan as bD, type MindooDBAppRuntime as bE, type MindooDBAppScanAttachmentOptions as bF, type MindooDBAppScanAttachmentResult as bG, type MindooDBAppScopedDocId as bH, type MindooDBAppScopedDocumentSummary as bI, type MindooDBAppSealIntent as bJ, type MindooDBAppSealedChannelOpenInput as bK, type MindooDBAppSealedChannelOpenResult as bL, type MindooDBAppSealedChannelRequestInput as bM, type MindooDBAppSession as bN, type MindooDBAppShowMenuInput as bO, type MindooDBAppShowMenuResult as bP, type MindooDBAppSignPreview as bQ, type MindooDBAppSignPreviewScope as bR, type MindooDBAppSignStatementInput as bS, type MindooDBAppSignStatementResult as bT, type MindooDBAppStorageApi as bU, type MindooDBAppTextEdit as bV, type MindooDBAppTextPatch as bW, type MindooDBAppThemeMode as bX, type MindooDBAppTimestampApi as bY, type MindooDBAppTimestampInput as bZ, type MindooDBAppTimestampProvider as b_, type MindooDBAppMenuItem as ba, type MindooDBAppMenuKind as bb, type MindooDBAppMenuPlacement as bc, type MindooDBAppMenuPointAnchor as bd, type MindooDBAppMenuRect as be, type MindooDBAppMenuRectAnchor as bf, type MindooDBAppMenuSelectionResult as bg, type MindooDBAppMenuSeparatorItem as bh, type MindooDBAppQueryCoverage as bi, type MindooDBAppQueryResult as bj, type MindooDBAppQueryRow as bk, type MindooDBAppQuerySortKey as bl, type MindooDBAppQueryTextClause as bm, type MindooDBAppReadableAttachmentStream as bn, type MindooDBAppRecipientOptions as bo, type MindooDBAppResolvedViewDefinition as bp, type MindooDBAppResolvedViewSource as bq, type MindooDBAppRevisionPhase as br, type MindooDBAppRevisionVerification as bs, type MindooDBAppRichTextBlockSpan as bt, type MindooDBAppRichTextGetOptions as bu, type MindooDBAppRichTextImmutableString as bv, type MindooDBAppRichTextMarkRange as bw, type MindooDBAppRichTextMaterializeValue as bx, type MindooDBAppRichTextPatch as by, type MindooDBAppRichTextScalar as bz, type MindooDBAppDragStartResult as c, type MindooDBAppUiPreferences as c0, type MindooDBAppUpdateDocumentInput as c1, type MindooDBAppViewCursorDocumentListResult as c2, type MindooDBAppViewCursorResult as c3, type MindooDBAppViewEntry as c4, type MindooDBAppViewEntryKind as c5, type MindooDBAppViewNavigator as c6, type MindooDBAppViewNavigatorExpansionState as c7, type MindooDBAppViewNavigatorOpenOptions as c8, type MindooDBAppViewNavigatorPageOptions as c9, type MindooDBAppViewNavigatorPageResult as ca, type MindooDBAppViewNavigatorRangeQuery as cb, type MindooDBAppViewNavigatorSelectionState as cc, type MindooDBAppViewUpdateStats as cd, type MindooDBAppViewport as ce, type MindooDBAppWellKnownDragType as cf, type MindooDBAppWritableAttachmentStream as cg, type MindooDBAppDragPreview as d, type MindooDBAppBridge as e, type MindooDBAppHostShortcutBinding as f, type MindooDBAppHostShortcutAction as g, type MindooDBAppHostingMode as h, type MindooDBAppDatabase as i, type MindooDBAppDocument as j, type MindooDBAppRichTextSpan as k, type MindooDBAppRichTextSnapshot as l, MINDOODB_APP_SEAL_SIGNING_DOMAIN as m, MINDOODB_APP_WELL_KNOWN_DRAG_TYPES as n, type MindooDBAppAccessDecision as o, type MindooDBAppAccessTier as p, type MindooDBAppAttachmentApi as q, type MindooDBAppAttachmentChunk as r, type MindooDBAppAttachmentInfo as s, type MindooDBAppAttachmentPreviewOptions as t, type MindooDBAppAttachmentPreviewSession as u, type MindooDBAppAutomergeChangesPatch as v, type MindooDBAppAutomergeChangesSince as w, type MindooDBAppAutomergeGetOptions as x, type MindooDBAppAutomergePatchResult as y, type MindooDBAppAutomergeSnapshot as z };
|
package/dist/vite/index.d.ts
CHANGED
package/dist/vite/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
// src/vite/index.ts
|
|
10
10
|
import { createHash } from "crypto";
|
|
11
|
-
import { readdir, readFile, writeFile } from "fs/promises";
|
|
11
|
+
import { access, readdir, readFile, writeFile } from "fs/promises";
|
|
12
12
|
import path from "path";
|
|
13
13
|
|
|
14
14
|
// src/vite/zip.ts
|
|
@@ -155,6 +155,14 @@ var DEFAULT_EXCLUDED_ROOT_FILES = /* @__PURE__ */ new Set([
|
|
|
155
155
|
MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME
|
|
156
156
|
]);
|
|
157
157
|
var WORKBOX_RUNTIME_PATTERN = /^workbox-[a-z0-9]+\.js(\.map)?$/i;
|
|
158
|
+
async function directoryExists(dir) {
|
|
159
|
+
try {
|
|
160
|
+
await access(dir);
|
|
161
|
+
return true;
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
158
166
|
function sha256(data) {
|
|
159
167
|
return `sha256-${createHash("sha256").update(data).digest("hex")}`;
|
|
160
168
|
}
|
|
@@ -223,66 +231,80 @@ async function readPackageMetadata(root) {
|
|
|
223
231
|
}
|
|
224
232
|
function havenBundle(options = {}) {
|
|
225
233
|
let resolvedConfig = null;
|
|
234
|
+
let emitted = false;
|
|
235
|
+
async function emitBundle() {
|
|
236
|
+
if (emitted) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!resolvedConfig) {
|
|
240
|
+
throw new Error("[haven-bundle] Plugin ran without a resolved Vite config.");
|
|
241
|
+
}
|
|
242
|
+
const outDir = path.resolve(resolvedConfig.root, resolvedConfig.build.outDir);
|
|
243
|
+
if (!await directoryExists(outDir)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const allPaths = await collectFiles(outDir);
|
|
247
|
+
const bundlePaths = allPaths.filter((candidate) => !isExcluded(candidate, options));
|
|
248
|
+
if (!bundlePaths.length) {
|
|
249
|
+
throw new Error(`[haven-bundle] No bundle files found in "${outDir}".`);
|
|
250
|
+
}
|
|
251
|
+
const entry = resolveEntryPath(bundlePaths, options.entry);
|
|
252
|
+
const packageMetadata = await readPackageMetadata(resolvedConfig.root);
|
|
253
|
+
const appId = options.appId ?? packageMetadata.name;
|
|
254
|
+
const version = options.version ?? packageMetadata.version;
|
|
255
|
+
if (!appId) {
|
|
256
|
+
throw new Error("[haven-bundle] Unable to determine appId \u2014 pass it explicitly.");
|
|
257
|
+
}
|
|
258
|
+
if (!version) {
|
|
259
|
+
throw new Error("[haven-bundle] Unable to determine version \u2014 pass it explicitly.");
|
|
260
|
+
}
|
|
261
|
+
const files = [];
|
|
262
|
+
const archiveEntries = [];
|
|
263
|
+
for (const relativePath of bundlePaths) {
|
|
264
|
+
const data = await readFile(path.join(outDir, relativePath));
|
|
265
|
+
files.push({ path: relativePath, hash: sha256(data), size: data.byteLength });
|
|
266
|
+
archiveEntries.push({ path: relativePath, data });
|
|
267
|
+
}
|
|
268
|
+
const archive = createZipArchive(archiveEntries);
|
|
269
|
+
const manifest = {
|
|
270
|
+
format: MINDOODB_APP_BUNDLE_MANIFEST_FORMAT,
|
|
271
|
+
formatVersion: MINDOODB_APP_BUNDLE_MANIFEST_VERSION,
|
|
272
|
+
appId,
|
|
273
|
+
version,
|
|
274
|
+
entry,
|
|
275
|
+
archive: {
|
|
276
|
+
path: MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME,
|
|
277
|
+
hash: sha256(archive),
|
|
278
|
+
size: archive.byteLength
|
|
279
|
+
},
|
|
280
|
+
contentHash: sha256(buildMindooDBAppBundleContentHashInput(files)),
|
|
281
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
282
|
+
files
|
|
283
|
+
};
|
|
284
|
+
await writeFile(path.join(outDir, MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME), archive);
|
|
285
|
+
await writeFile(
|
|
286
|
+
path.join(outDir, MINDOODB_APP_BUNDLE_MANIFEST_FILE_NAME),
|
|
287
|
+
`${JSON.stringify(manifest, null, 2)}
|
|
288
|
+
`,
|
|
289
|
+
"utf8"
|
|
290
|
+
);
|
|
291
|
+
const totalBytes = files.reduce((sum, file) => sum + file.size, 0);
|
|
292
|
+
console.log(
|
|
293
|
+
`[haven-bundle] ${files.length} files (${(totalBytes / 1024 / 1024).toFixed(2)} MB) \u2192 ${MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME} (${(archive.byteLength / 1024 / 1024).toFixed(2)} MB), contentHash ${manifest.contentHash.slice(7, 19)}`
|
|
294
|
+
);
|
|
295
|
+
emitted = true;
|
|
296
|
+
}
|
|
226
297
|
return {
|
|
227
298
|
name: "haven-bundle",
|
|
228
299
|
apply: "build",
|
|
229
300
|
configResolved(config) {
|
|
230
301
|
resolvedConfig = config;
|
|
231
302
|
},
|
|
303
|
+
async writeBundle() {
|
|
304
|
+
await emitBundle();
|
|
305
|
+
},
|
|
232
306
|
async closeBundle() {
|
|
233
|
-
|
|
234
|
-
throw new Error("[haven-bundle] Plugin ran without a resolved Vite config.");
|
|
235
|
-
}
|
|
236
|
-
const outDir = path.resolve(resolvedConfig.root, resolvedConfig.build.outDir);
|
|
237
|
-
const allPaths = await collectFiles(outDir);
|
|
238
|
-
const bundlePaths = allPaths.filter((candidate) => !isExcluded(candidate, options));
|
|
239
|
-
if (!bundlePaths.length) {
|
|
240
|
-
throw new Error(`[haven-bundle] No bundle files found in "${outDir}".`);
|
|
241
|
-
}
|
|
242
|
-
const entry = resolveEntryPath(bundlePaths, options.entry);
|
|
243
|
-
const packageMetadata = await readPackageMetadata(resolvedConfig.root);
|
|
244
|
-
const appId = options.appId ?? packageMetadata.name;
|
|
245
|
-
const version = options.version ?? packageMetadata.version;
|
|
246
|
-
if (!appId) {
|
|
247
|
-
throw new Error("[haven-bundle] Unable to determine appId \u2014 pass it explicitly.");
|
|
248
|
-
}
|
|
249
|
-
if (!version) {
|
|
250
|
-
throw new Error("[haven-bundle] Unable to determine version \u2014 pass it explicitly.");
|
|
251
|
-
}
|
|
252
|
-
const files = [];
|
|
253
|
-
const archiveEntries = [];
|
|
254
|
-
for (const relativePath of bundlePaths) {
|
|
255
|
-
const data = await readFile(path.join(outDir, relativePath));
|
|
256
|
-
files.push({ path: relativePath, hash: sha256(data), size: data.byteLength });
|
|
257
|
-
archiveEntries.push({ path: relativePath, data });
|
|
258
|
-
}
|
|
259
|
-
const archive = createZipArchive(archiveEntries);
|
|
260
|
-
const manifest = {
|
|
261
|
-
format: MINDOODB_APP_BUNDLE_MANIFEST_FORMAT,
|
|
262
|
-
formatVersion: MINDOODB_APP_BUNDLE_MANIFEST_VERSION,
|
|
263
|
-
appId,
|
|
264
|
-
version,
|
|
265
|
-
entry,
|
|
266
|
-
archive: {
|
|
267
|
-
path: MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME,
|
|
268
|
-
hash: sha256(archive),
|
|
269
|
-
size: archive.byteLength
|
|
270
|
-
},
|
|
271
|
-
contentHash: sha256(buildMindooDBAppBundleContentHashInput(files)),
|
|
272
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
273
|
-
files
|
|
274
|
-
};
|
|
275
|
-
await writeFile(path.join(outDir, MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME), archive);
|
|
276
|
-
await writeFile(
|
|
277
|
-
path.join(outDir, MINDOODB_APP_BUNDLE_MANIFEST_FILE_NAME),
|
|
278
|
-
`${JSON.stringify(manifest, null, 2)}
|
|
279
|
-
`,
|
|
280
|
-
"utf8"
|
|
281
|
-
);
|
|
282
|
-
const totalBytes = files.reduce((sum, file) => sum + file.size, 0);
|
|
283
|
-
console.log(
|
|
284
|
-
`[haven-bundle] ${files.length} files (${(totalBytes / 1024 / 1024).toFixed(2)} MB) \u2192 ${MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME} (${(archive.byteLength / 1024 / 1024).toFixed(2)} MB), contentHash ${manifest.contentHash.slice(7, 19)}`
|
|
285
|
-
);
|
|
307
|
+
await emitBundle();
|
|
286
308
|
}
|
|
287
309
|
};
|
|
288
310
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindoodb-app-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.45",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22.13.0"
|
|
6
6
|
},
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"@automerge/automerge": "^3.3.2",
|
|
60
60
|
"mindoodb": "^0.0.58",
|
|
61
61
|
"@types/node": "25.5.0",
|
|
62
|
+
"jsdom": "^29.0.1",
|
|
62
63
|
"tsup": "^8.5.1",
|
|
63
64
|
"typescript": "^6.0.2",
|
|
64
65
|
"vitest": "^4.1.2"
|