@wailsio/runtime 3.0.0-alpha.7 → 3.0.0-alpha.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/{application.js → dist/application.js} +32 -46
  2. package/dist/browser.js +20 -0
  3. package/dist/callable.js +144 -0
  4. package/dist/calls.js +194 -0
  5. package/dist/cancellable.js +792 -0
  6. package/dist/clipboard.js +30 -0
  7. package/dist/contextmenu.js +80 -0
  8. package/dist/create.js +94 -0
  9. package/dist/dialogs.js +134 -0
  10. package/dist/drag.js +222 -0
  11. package/dist/event_types.js +232 -0
  12. package/dist/events.js +114 -0
  13. package/dist/flags.js +23 -0
  14. package/dist/index.js +38 -0
  15. package/dist/listener.js +44 -0
  16. package/dist/nanoid.js +38 -0
  17. package/dist/runtime.js +63 -0
  18. package/{screens.js → dist/screens.js} +38 -45
  19. package/dist/system.js +146 -0
  20. package/dist/utils.js +95 -0
  21. package/dist/window.js +570 -0
  22. package/dist/wml.js +179 -0
  23. package/package.json +62 -18
  24. package/types/application.d.ts +12 -0
  25. package/types/browser.d.ts +6 -0
  26. package/types/callable.d.ts +3 -0
  27. package/types/calls.d.ts +63 -0
  28. package/types/cancellable.d.ts +434 -0
  29. package/types/clipboard.d.ts +13 -0
  30. package/types/contextmenu.d.ts +1 -0
  31. package/types/create.d.ts +31 -0
  32. package/types/dialogs.d.ts +140 -0
  33. package/types/drag.d.ts +1 -0
  34. package/types/event_types.d.ts +221 -0
  35. package/types/events.d.ts +67 -0
  36. package/types/flags.d.ts +7 -0
  37. package/types/index.d.ts +16 -0
  38. package/types/listener.d.ts +9 -0
  39. package/types/nanoid.d.ts +1 -0
  40. package/types/runtime.d.ts +22 -0
  41. package/types/screens.d.ts +60 -0
  42. package/types/system.d.ts +92 -0
  43. package/types/utils.d.ts +21 -0
  44. package/types/window.d.ts +306 -0
  45. package/types/wml.d.ts +8 -0
  46. package/browser.js +0 -24
  47. package/calls.js +0 -123
  48. package/clipboard.js +0 -35
  49. package/contextmenu.js +0 -98
  50. package/dialogs.js +0 -138
  51. package/drag.js +0 -125
  52. package/events.js +0 -134
  53. package/flags.js +0 -63
  54. package/index.js +0 -56
  55. package/runtime.js +0 -122
  56. package/system.js +0 -122
  57. package/types.d.ts +0 -135
  58. package/window.js +0 -122
  59. package/wml.js +0 -151
package/dist/window.js ADDED
@@ -0,0 +1,570 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { newRuntimeCaller, objectNames } from "./runtime.js";
11
+ // NEW: Dropzone constants
12
+ const DROPZONE_ATTRIBUTE = 'data-wails-dropzone';
13
+ const DROPZONE_HOVER_CLASS = 'wails-dropzone-hover'; // User can style this class
14
+ let currentHoveredDropzone = null;
15
+ const PositionMethod = 0;
16
+ const CenterMethod = 1;
17
+ const CloseMethod = 2;
18
+ const DisableSizeConstraintsMethod = 3;
19
+ const EnableSizeConstraintsMethod = 4;
20
+ const FocusMethod = 5;
21
+ const ForceReloadMethod = 6;
22
+ const FullscreenMethod = 7;
23
+ const GetScreenMethod = 8;
24
+ const GetZoomMethod = 9;
25
+ const HeightMethod = 10;
26
+ const HideMethod = 11;
27
+ const IsFocusedMethod = 12;
28
+ const IsFullscreenMethod = 13;
29
+ const IsMaximisedMethod = 14;
30
+ const IsMinimisedMethod = 15;
31
+ const MaximiseMethod = 16;
32
+ const MinimiseMethod = 17;
33
+ const NameMethod = 18;
34
+ const OpenDevToolsMethod = 19;
35
+ const RelativePositionMethod = 20;
36
+ const ReloadMethod = 21;
37
+ const ResizableMethod = 22;
38
+ const RestoreMethod = 23;
39
+ const SetPositionMethod = 24;
40
+ const SetAlwaysOnTopMethod = 25;
41
+ const SetBackgroundColourMethod = 26;
42
+ const SetFramelessMethod = 27;
43
+ const SetFullscreenButtonEnabledMethod = 28;
44
+ const SetMaxSizeMethod = 29;
45
+ const SetMinSizeMethod = 30;
46
+ const SetRelativePositionMethod = 31;
47
+ const SetResizableMethod = 32;
48
+ const SetSizeMethod = 33;
49
+ const SetTitleMethod = 34;
50
+ const SetZoomMethod = 35;
51
+ const ShowMethod = 36;
52
+ const SizeMethod = 37;
53
+ const ToggleFullscreenMethod = 38;
54
+ const ToggleMaximiseMethod = 39;
55
+ const ToggleFramelessMethod = 40;
56
+ const UnFullscreenMethod = 41;
57
+ const UnMaximiseMethod = 42;
58
+ const UnMinimiseMethod = 43;
59
+ const WidthMethod = 44;
60
+ const ZoomMethod = 45;
61
+ const ZoomInMethod = 46;
62
+ const ZoomOutMethod = 47;
63
+ const ZoomResetMethod = 48;
64
+ const SnapAssistMethod = 49;
65
+ const WindowDropZoneDropped = 50;
66
+ function getDropzoneElement(element) {
67
+ if (!element) {
68
+ return null;
69
+ }
70
+ // Allow dropzone attribute to be on the element itself or any parent
71
+ return element.closest(`[${DROPZONE_ATTRIBUTE}]`);
72
+ }
73
+ // Private field names.
74
+ const callerSym = Symbol("caller");
75
+ class Window {
76
+ /**
77
+ * Initialises a window object with the specified name.
78
+ *
79
+ * @private
80
+ * @param name - The name of the target window.
81
+ */
82
+ constructor(name = '') {
83
+ this[callerSym] = newRuntimeCaller(objectNames.Window, name);
84
+ // bind instance method to make them easily usable in event handlers
85
+ for (const method of Object.getOwnPropertyNames(Window.prototype)) {
86
+ if (method !== "constructor"
87
+ && typeof this[method] === "function") {
88
+ this[method] = this[method].bind(this);
89
+ }
90
+ }
91
+ }
92
+ /**
93
+ * Gets the specified window.
94
+ *
95
+ * @param name - The name of the window to get.
96
+ * @returns The corresponding window object.
97
+ */
98
+ Get(name) {
99
+ return new Window(name);
100
+ }
101
+ /**
102
+ * Returns the absolute position of the window.
103
+ *
104
+ * @returns The current absolute position of the window.
105
+ */
106
+ Position() {
107
+ return this[callerSym](PositionMethod);
108
+ }
109
+ /**
110
+ * Centers the window on the screen.
111
+ */
112
+ Center() {
113
+ return this[callerSym](CenterMethod);
114
+ }
115
+ /**
116
+ * Closes the window.
117
+ */
118
+ Close() {
119
+ return this[callerSym](CloseMethod);
120
+ }
121
+ /**
122
+ * Disables min/max size constraints.
123
+ */
124
+ DisableSizeConstraints() {
125
+ return this[callerSym](DisableSizeConstraintsMethod);
126
+ }
127
+ /**
128
+ * Enables min/max size constraints.
129
+ */
130
+ EnableSizeConstraints() {
131
+ return this[callerSym](EnableSizeConstraintsMethod);
132
+ }
133
+ /**
134
+ * Focuses the window.
135
+ */
136
+ Focus() {
137
+ return this[callerSym](FocusMethod);
138
+ }
139
+ /**
140
+ * Forces the window to reload the page assets.
141
+ */
142
+ ForceReload() {
143
+ return this[callerSym](ForceReloadMethod);
144
+ }
145
+ /**
146
+ * Switches the window to fullscreen mode.
147
+ */
148
+ Fullscreen() {
149
+ return this[callerSym](FullscreenMethod);
150
+ }
151
+ /**
152
+ * Returns the screen that the window is on.
153
+ *
154
+ * @returns The screen the window is currently on.
155
+ */
156
+ GetScreen() {
157
+ return this[callerSym](GetScreenMethod);
158
+ }
159
+ /**
160
+ * Returns the current zoom level of the window.
161
+ *
162
+ * @returns The current zoom level.
163
+ */
164
+ GetZoom() {
165
+ return this[callerSym](GetZoomMethod);
166
+ }
167
+ /**
168
+ * Returns the height of the window.
169
+ *
170
+ * @returns The current height of the window.
171
+ */
172
+ Height() {
173
+ return this[callerSym](HeightMethod);
174
+ }
175
+ /**
176
+ * Hides the window.
177
+ */
178
+ Hide() {
179
+ return this[callerSym](HideMethod);
180
+ }
181
+ /**
182
+ * Returns true if the window is focused.
183
+ *
184
+ * @returns Whether the window is currently focused.
185
+ */
186
+ IsFocused() {
187
+ return this[callerSym](IsFocusedMethod);
188
+ }
189
+ /**
190
+ * Returns true if the window is fullscreen.
191
+ *
192
+ * @returns Whether the window is currently fullscreen.
193
+ */
194
+ IsFullscreen() {
195
+ return this[callerSym](IsFullscreenMethod);
196
+ }
197
+ /**
198
+ * Returns true if the window is maximised.
199
+ *
200
+ * @returns Whether the window is currently maximised.
201
+ */
202
+ IsMaximised() {
203
+ return this[callerSym](IsMaximisedMethod);
204
+ }
205
+ /**
206
+ * Returns true if the window is minimised.
207
+ *
208
+ * @returns Whether the window is currently minimised.
209
+ */
210
+ IsMinimised() {
211
+ return this[callerSym](IsMinimisedMethod);
212
+ }
213
+ /**
214
+ * Maximises the window.
215
+ */
216
+ Maximise() {
217
+ return this[callerSym](MaximiseMethod);
218
+ }
219
+ /**
220
+ * Minimises the window.
221
+ */
222
+ Minimise() {
223
+ return this[callerSym](MinimiseMethod);
224
+ }
225
+ /**
226
+ * Returns the name of the window.
227
+ *
228
+ * @returns The name of the window.
229
+ */
230
+ Name() {
231
+ return this[callerSym](NameMethod);
232
+ }
233
+ /**
234
+ * Opens the development tools pane.
235
+ */
236
+ OpenDevTools() {
237
+ return this[callerSym](OpenDevToolsMethod);
238
+ }
239
+ /**
240
+ * Returns the relative position of the window to the screen.
241
+ *
242
+ * @returns The current relative position of the window.
243
+ */
244
+ RelativePosition() {
245
+ return this[callerSym](RelativePositionMethod);
246
+ }
247
+ /**
248
+ * Reloads the page assets.
249
+ */
250
+ Reload() {
251
+ return this[callerSym](ReloadMethod);
252
+ }
253
+ /**
254
+ * Returns true if the window is resizable.
255
+ *
256
+ * @returns Whether the window is currently resizable.
257
+ */
258
+ Resizable() {
259
+ return this[callerSym](ResizableMethod);
260
+ }
261
+ /**
262
+ * Restores the window to its previous state if it was previously minimised, maximised or fullscreen.
263
+ */
264
+ Restore() {
265
+ return this[callerSym](RestoreMethod);
266
+ }
267
+ /**
268
+ * Sets the absolute position of the window.
269
+ *
270
+ * @param x - The desired horizontal absolute position of the window.
271
+ * @param y - The desired vertical absolute position of the window.
272
+ */
273
+ SetPosition(x, y) {
274
+ return this[callerSym](SetPositionMethod, { x, y });
275
+ }
276
+ /**
277
+ * Sets the window to be always on top.
278
+ *
279
+ * @param alwaysOnTop - Whether the window should stay on top.
280
+ */
281
+ SetAlwaysOnTop(alwaysOnTop) {
282
+ return this[callerSym](SetAlwaysOnTopMethod, { alwaysOnTop });
283
+ }
284
+ /**
285
+ * Sets the background colour of the window.
286
+ *
287
+ * @param r - The desired red component of the window background.
288
+ * @param g - The desired green component of the window background.
289
+ * @param b - The desired blue component of the window background.
290
+ * @param a - The desired alpha component of the window background.
291
+ */
292
+ SetBackgroundColour(r, g, b, a) {
293
+ return this[callerSym](SetBackgroundColourMethod, { r, g, b, a });
294
+ }
295
+ /**
296
+ * Removes the window frame and title bar.
297
+ *
298
+ * @param frameless - Whether the window should be frameless.
299
+ */
300
+ SetFrameless(frameless) {
301
+ return this[callerSym](SetFramelessMethod, { frameless });
302
+ }
303
+ /**
304
+ * Disables the system fullscreen button.
305
+ *
306
+ * @param enabled - Whether the fullscreen button should be enabled.
307
+ */
308
+ SetFullscreenButtonEnabled(enabled) {
309
+ return this[callerSym](SetFullscreenButtonEnabledMethod, { enabled });
310
+ }
311
+ /**
312
+ * Sets the maximum size of the window.
313
+ *
314
+ * @param width - The desired maximum width of the window.
315
+ * @param height - The desired maximum height of the window.
316
+ */
317
+ SetMaxSize(width, height) {
318
+ return this[callerSym](SetMaxSizeMethod, { width, height });
319
+ }
320
+ /**
321
+ * Sets the minimum size of the window.
322
+ *
323
+ * @param width - The desired minimum width of the window.
324
+ * @param height - The desired minimum height of the window.
325
+ */
326
+ SetMinSize(width, height) {
327
+ return this[callerSym](SetMinSizeMethod, { width, height });
328
+ }
329
+ /**
330
+ * Sets the relative position of the window to the screen.
331
+ *
332
+ * @param x - The desired horizontal relative position of the window.
333
+ * @param y - The desired vertical relative position of the window.
334
+ */
335
+ SetRelativePosition(x, y) {
336
+ return this[callerSym](SetRelativePositionMethod, { x, y });
337
+ }
338
+ /**
339
+ * Sets whether the window is resizable.
340
+ *
341
+ * @param resizable - Whether the window should be resizable.
342
+ */
343
+ SetResizable(resizable) {
344
+ return this[callerSym](SetResizableMethod, { resizable });
345
+ }
346
+ /**
347
+ * Sets the size of the window.
348
+ *
349
+ * @param width - The desired width of the window.
350
+ * @param height - The desired height of the window.
351
+ */
352
+ SetSize(width, height) {
353
+ return this[callerSym](SetSizeMethod, { width, height });
354
+ }
355
+ /**
356
+ * Sets the title of the window.
357
+ *
358
+ * @param title - The desired title of the window.
359
+ */
360
+ SetTitle(title) {
361
+ return this[callerSym](SetTitleMethod, { title });
362
+ }
363
+ /**
364
+ * Sets the zoom level of the window.
365
+ *
366
+ * @param zoom - The desired zoom level.
367
+ */
368
+ SetZoom(zoom) {
369
+ return this[callerSym](SetZoomMethod, { zoom });
370
+ }
371
+ /**
372
+ * Shows the window.
373
+ */
374
+ Show() {
375
+ return this[callerSym](ShowMethod);
376
+ }
377
+ /**
378
+ * Returns the size of the window.
379
+ *
380
+ * @returns The current size of the window.
381
+ */
382
+ Size() {
383
+ return this[callerSym](SizeMethod);
384
+ }
385
+ /**
386
+ * Toggles the window between fullscreen and normal.
387
+ */
388
+ ToggleFullscreen() {
389
+ return this[callerSym](ToggleFullscreenMethod);
390
+ }
391
+ /**
392
+ * Toggles the window between maximised and normal.
393
+ */
394
+ ToggleMaximise() {
395
+ return this[callerSym](ToggleMaximiseMethod);
396
+ }
397
+ /**
398
+ * Toggles the window between frameless and normal.
399
+ */
400
+ ToggleFrameless() {
401
+ return this[callerSym](ToggleFramelessMethod);
402
+ }
403
+ /**
404
+ * Un-fullscreens the window.
405
+ */
406
+ UnFullscreen() {
407
+ return this[callerSym](UnFullscreenMethod);
408
+ }
409
+ /**
410
+ * Un-maximises the window.
411
+ */
412
+ UnMaximise() {
413
+ return this[callerSym](UnMaximiseMethod);
414
+ }
415
+ /**
416
+ * Un-minimises the window.
417
+ */
418
+ UnMinimise() {
419
+ return this[callerSym](UnMinimiseMethod);
420
+ }
421
+ /**
422
+ * Returns the width of the window.
423
+ *
424
+ * @returns The current width of the window.
425
+ */
426
+ Width() {
427
+ return this[callerSym](WidthMethod);
428
+ }
429
+ /**
430
+ * Zooms the window.
431
+ */
432
+ Zoom() {
433
+ return this[callerSym](ZoomMethod);
434
+ }
435
+ /**
436
+ * Increases the zoom level of the webview content.
437
+ */
438
+ ZoomIn() {
439
+ return this[callerSym](ZoomInMethod);
440
+ }
441
+ /**
442
+ * Decreases the zoom level of the webview content.
443
+ */
444
+ ZoomOut() {
445
+ return this[callerSym](ZoomOutMethod);
446
+ }
447
+ /**
448
+ * Resets the zoom level of the webview content.
449
+ */
450
+ ZoomReset() {
451
+ return this[callerSym](ZoomResetMethod);
452
+ }
453
+ /**
454
+ * Handles file drops originating from platform-specific code (e.g., macOS native drag-and-drop).
455
+ * Gathers information about the drop target element and sends it back to the Go backend.
456
+ *
457
+ * @param filenames - An array of file paths (strings) that were dropped.
458
+ * @param x - The x-coordinate of the drop event.
459
+ * @param y - The y-coordinate of the drop event.
460
+ */
461
+ HandlePlatformFileDrop(filenames, x, y) {
462
+ const element = document.elementFromPoint(x, y);
463
+ // NEW: Check if the drop target is a valid dropzone
464
+ const dropzoneTarget = getDropzoneElement(element);
465
+ if (!dropzoneTarget) {
466
+ console.log(`Wails Runtime: Drop on element (or no element) at ${x},${y} which is not a designated dropzone. Ignoring. Element:`, element);
467
+ // No need to call backend if not a valid dropzone target
468
+ return;
469
+ }
470
+ console.log(`Wails Runtime: Drop on designated dropzone. Element at (${x}, ${y}):`, element, 'Effective dropzone:', dropzoneTarget);
471
+ const elementDetails = {
472
+ id: dropzoneTarget.id,
473
+ classList: Array.from(dropzoneTarget.classList),
474
+ attributes: {},
475
+ };
476
+ for (let i = 0; i < dropzoneTarget.attributes.length; i++) {
477
+ const attr = dropzoneTarget.attributes[i];
478
+ elementDetails.attributes[attr.name] = attr.value;
479
+ }
480
+ const payload = {
481
+ filenames,
482
+ x,
483
+ y,
484
+ elementDetails,
485
+ };
486
+ this[callerSym](WindowDropZoneDropped, payload);
487
+ }
488
+ /* Triggers Windows 11 Snap Assist feature (Windows only).
489
+ * This is equivalent to pressing Win+Z and shows snap layout options.
490
+ */
491
+ SnapAssist() {
492
+ return this[callerSym](SnapAssistMethod);
493
+ }
494
+ }
495
+ /**
496
+ * The window within which the script is running.
497
+ */
498
+ const thisWindow = new Window('');
499
+ // NEW: Global Drag Event Listeners
500
+ function setupGlobalDropzoneListeners() {
501
+ const docElement = document.documentElement;
502
+ let dragEnterCounter = 0; // To handle dragenter/dragleave on child elements
503
+ docElement.addEventListener('dragenter', (event) => {
504
+ event.preventDefault();
505
+ if (event.dataTransfer && event.dataTransfer.types.includes('Files')) {
506
+ dragEnterCounter++;
507
+ const targetElement = document.elementFromPoint(event.clientX, event.clientY);
508
+ const dropzone = getDropzoneElement(targetElement);
509
+ // Clear previous hover regardless, then apply new if valid
510
+ if (currentHoveredDropzone && currentHoveredDropzone !== dropzone) {
511
+ currentHoveredDropzone.classList.remove(DROPZONE_HOVER_CLASS);
512
+ }
513
+ if (dropzone) {
514
+ dropzone.classList.add(DROPZONE_HOVER_CLASS);
515
+ event.dataTransfer.dropEffect = 'copy';
516
+ currentHoveredDropzone = dropzone;
517
+ }
518
+ else {
519
+ event.dataTransfer.dropEffect = 'none';
520
+ currentHoveredDropzone = null; // Ensure it's cleared if no dropzone found
521
+ }
522
+ }
523
+ }, false);
524
+ docElement.addEventListener('dragover', (event) => {
525
+ event.preventDefault(); // Necessary to allow drop
526
+ if (event.dataTransfer && event.dataTransfer.types.includes('Files')) {
527
+ // No need to query elementFromPoint again if already handled by dragenter correctly
528
+ // Just ensure dropEffect is continuously set based on currentHoveredDropzone
529
+ if (currentHoveredDropzone) {
530
+ // Re-apply class just in case it was removed by some other JS
531
+ if (!currentHoveredDropzone.classList.contains(DROPZONE_HOVER_CLASS)) {
532
+ currentHoveredDropzone.classList.add(DROPZONE_HOVER_CLASS);
533
+ }
534
+ event.dataTransfer.dropEffect = 'copy';
535
+ }
536
+ else {
537
+ event.dataTransfer.dropEffect = 'none';
538
+ }
539
+ }
540
+ }, false);
541
+ docElement.addEventListener('dragleave', (event) => {
542
+ event.preventDefault();
543
+ if (event.dataTransfer && event.dataTransfer.types.includes('Files')) {
544
+ dragEnterCounter--;
545
+ // Only remove hover if drag truly left the window or the last dropzone
546
+ if (dragEnterCounter === 0 || event.relatedTarget === null || (currentHoveredDropzone && !currentHoveredDropzone.contains(event.relatedTarget))) {
547
+ if (currentHoveredDropzone) {
548
+ currentHoveredDropzone.classList.remove(DROPZONE_HOVER_CLASS);
549
+ currentHoveredDropzone = null;
550
+ }
551
+ dragEnterCounter = 0; // Reset counter if it went negative or left window
552
+ }
553
+ }
554
+ }, false);
555
+ docElement.addEventListener('drop', (event) => {
556
+ event.preventDefault(); // Prevent default browser file handling
557
+ dragEnterCounter = 0; // Reset counter
558
+ if (currentHoveredDropzone) {
559
+ currentHoveredDropzone.classList.remove(DROPZONE_HOVER_CLASS);
560
+ currentHoveredDropzone = null;
561
+ }
562
+ // The actual drop processing is initiated by the native side calling HandlePlatformFileDrop
563
+ // HandlePlatformFileDrop will then check if the drop was on a valid zone.
564
+ }, false);
565
+ }
566
+ // Initialize listeners when the script loads
567
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
568
+ setupGlobalDropzoneListeners();
569
+ }
570
+ export default thisWindow;