@wailsio/runtime 3.0.0-alpha.66 → 3.0.0-alpha.69

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.
@@ -203,6 +203,7 @@ export const Types = Object.freeze({
203
203
  Common: Object.freeze({
204
204
  ApplicationOpenedWithFile: "common:ApplicationOpenedWithFile",
205
205
  ApplicationStarted: "common:ApplicationStarted",
206
+ ApplicationLaunchedWithUrl: "common:ApplicationLaunchedWithUrl",
206
207
  ThemeChanged: "common:ThemeChanged",
207
208
  WindowClosing: "common:WindowClosing",
208
209
  WindowDidMove: "common:WindowDidMove",
@@ -215,6 +216,7 @@ export const Types = Object.freeze({
215
216
  WindowLostFocus: "common:WindowLostFocus",
216
217
  WindowMaximise: "common:WindowMaximise",
217
218
  WindowMinimise: "common:WindowMinimise",
219
+ WindowToggleFrameless: "common:WindowToggleFrameless",
218
220
  WindowRestore: "common:WindowRestore",
219
221
  WindowRuntimeReady: "common:WindowRuntimeReady",
220
222
  WindowShow: "common:WindowShow",
@@ -225,5 +227,6 @@ export const Types = Object.freeze({
225
227
  WindowZoomIn: "common:WindowZoomIn",
226
228
  WindowZoomOut: "common:WindowZoomOut",
227
229
  WindowZoomReset: "common:WindowZoomReset",
230
+ WindowDropZoneFilesDropped: "common:WindowDropZoneFilesDropped",
228
231
  }),
229
232
  });
package/dist/events.js CHANGED
@@ -91,11 +91,24 @@ export function OffAll() {
91
91
  eventListeners.clear();
92
92
  }
93
93
  /**
94
- * Emits the given event.
94
+ * Emits an event using the name and data.
95
95
  *
96
- * @param event - The name of the event to emit.
97
96
  * @returns A promise that will be fulfilled once the event has been emitted.
97
+ * @param name - the name of the event to emit.
98
+ * @param data - the data to be sent with the event.
98
99
  */
99
- export function Emit(event) {
100
- return call(EmitMethod, event);
100
+ export function Emit(name, data) {
101
+ let eventName;
102
+ let eventData;
103
+ if (typeof name === 'object' && name !== null && 'name' in name && 'data' in name) {
104
+ // If name is an object with a name property, use it directly
105
+ eventName = name['name'];
106
+ eventData = name['data'];
107
+ }
108
+ else {
109
+ // Otherwise use the standard parameters
110
+ eventName = name;
111
+ eventData = data;
112
+ }
113
+ return call(EmitMethod, { name: eventName, data: eventData });
101
114
  }
package/dist/system.js CHANGED
@@ -11,6 +11,7 @@ import { newRuntimeCaller, objectNames } from "./runtime.js";
11
11
  const call = newRuntimeCaller(objectNames.System);
12
12
  const SystemIsDarkMode = 0;
13
13
  const SystemEnvironment = 1;
14
+ const ApplicationFilesDroppedWithContext = 100; // New method ID for enriched drop event
14
15
  const _invoke = (function () {
15
16
  var _a, _b, _c, _d, _e;
16
17
  try {
@@ -114,3 +115,32 @@ export function IsARM64() {
114
115
  export function IsDebug() {
115
116
  return Boolean(window._wails.environment.Debug);
116
117
  }
118
+ /**
119
+ * Handles file drops originating from platform-specific code (e.g., macOS native drag-and-drop).
120
+ * Gathers information about the drop target element and sends it back to the Go backend.
121
+ *
122
+ * @param filenames - An array of file paths (strings) that were dropped.
123
+ * @param x - The x-coordinate of the drop event.
124
+ * @param y - The y-coordinate of the drop event.
125
+ */
126
+ export function HandlePlatformFileDrop(filenames, x, y) {
127
+ const element = document.elementFromPoint(x, y);
128
+ const elementId = element ? element.id : '';
129
+ const classList = element ? Array.from(element.classList) : [];
130
+ const payload = {
131
+ filenames,
132
+ x,
133
+ y,
134
+ elementId,
135
+ classList,
136
+ };
137
+ call(ApplicationFilesDroppedWithContext, payload)
138
+ .then(() => {
139
+ // Optional: Log success or handle if needed
140
+ console.log("Platform file drop processed and sent to Go.");
141
+ })
142
+ .catch(err => {
143
+ // Optional: Log error
144
+ console.error("Error sending platform file drop to Go:", err);
145
+ });
146
+ }
package/dist/window.js CHANGED
@@ -8,6 +8,10 @@ The electron alternative for Go
8
8
  (c) Lea Anthony 2019-present
9
9
  */
10
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;
11
15
  const PositionMethod = 0;
12
16
  const CenterMethod = 1;
13
17
  const CloseMethod = 2;
@@ -48,14 +52,24 @@ const ShowMethod = 36;
48
52
  const SizeMethod = 37;
49
53
  const ToggleFullscreenMethod = 38;
50
54
  const ToggleMaximiseMethod = 39;
51
- const UnFullscreenMethod = 40;
52
- const UnMaximiseMethod = 41;
53
- const UnMinimiseMethod = 42;
54
- const WidthMethod = 43;
55
- const ZoomMethod = 44;
56
- const ZoomInMethod = 45;
57
- const ZoomOutMethod = 46;
58
- const ZoomResetMethod = 47;
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
+ }
59
73
  // Private field names.
60
74
  const callerSym = Symbol("caller");
61
75
  class Window {
@@ -380,6 +394,12 @@ class Window {
380
394
  ToggleMaximise() {
381
395
  return this[callerSym](ToggleMaximiseMethod);
382
396
  }
397
+ /**
398
+ * Toggles the window between frameless and normal.
399
+ */
400
+ ToggleFrameless() {
401
+ return this[callerSym](ToggleFramelessMethod);
402
+ }
383
403
  /**
384
404
  * Un-fullscreens the window.
385
405
  */
@@ -430,9 +450,121 @@ class Window {
430
450
  ZoomReset() {
431
451
  return this[callerSym](ZoomResetMethod);
432
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
+ }
433
494
  }
434
495
  /**
435
496
  * The window within which the script is running.
436
497
  */
437
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
+ }
438
570
  export default thisWindow;
package/dist/wml.js CHANGED
@@ -9,7 +9,7 @@ The electron alternative for Go
9
9
  */
10
10
  import { OpenURL } from "./browser.js";
11
11
  import { Question } from "./dialogs.js";
12
- import { Emit, WailsEvent } from "./events.js";
12
+ import { Emit } from "./events.js";
13
13
  import { canAbortListeners, whenReady } from "./utils.js";
14
14
  import Window from "./window.js";
15
15
  /**
@@ -19,7 +19,7 @@ import Window from "./window.js";
19
19
  * @param [data=null] - - Optional data to send along with the event.
20
20
  */
21
21
  function sendEvent(eventName, data = null) {
22
- Emit(new WailsEvent(eventName, data));
22
+ Emit(eventName, data);
23
23
  }
24
24
  /**
25
25
  * Calls a method on a specified window.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wailsio/runtime",
3
3
  "type": "module",
4
- "version": "3.0.0-alpha.66",
4
+ "version": "3.0.0-alpha.69",
5
5
  "description": "Wails Runtime",
6
6
  "types": "types/index.d.ts",
7
7
  "exports": {
@@ -36,8 +36,8 @@
36
36
  "generate": "npm run generate:events",
37
37
  "prebuild": "npm run clean && npm run generate",
38
38
  "build:code": "npx tsc",
39
- "build:docs": "npx typedoc --plugin typedoc-plugin-mdn-links --plugin typedoc-plugin-missing-exports ./src/index.ts",
40
- "build:docs:md": "npx typedoc --plugin typedoc-plugin-markdown --plugin typedoc-plugin-mdn-links --plugin typedoc-plugin-missing-exports ./src/index.ts",
39
+ "build:docs": "npx typedoc --gitRevision v3-alpha --plugin typedoc-plugin-mdn-links --plugin typedoc-plugin-missing-exports ./src/index.ts",
40
+ "build:docs:md": "npx typedoc --gitRevision v3-alpha --plugin typedoc-plugin-markdown --plugin typedoc-plugin-mdn-links --plugin typedoc-plugin-missing-exports ./src/index.ts",
41
41
  "build": "npm run build:code & npm run build:docs & wait",
42
42
  "prepack": "npm run build"
43
43
  },
@@ -192,6 +192,7 @@ export declare const Types: Readonly<{
192
192
  Common: Readonly<{
193
193
  ApplicationOpenedWithFile: "common:ApplicationOpenedWithFile";
194
194
  ApplicationStarted: "common:ApplicationStarted";
195
+ ApplicationLaunchedWithUrl: "common:ApplicationLaunchedWithUrl";
195
196
  ThemeChanged: "common:ThemeChanged";
196
197
  WindowClosing: "common:WindowClosing";
197
198
  WindowDidMove: "common:WindowDidMove";
@@ -204,6 +205,7 @@ export declare const Types: Readonly<{
204
205
  WindowLostFocus: "common:WindowLostFocus";
205
206
  WindowMaximise: "common:WindowMaximise";
206
207
  WindowMinimise: "common:WindowMinimise";
208
+ WindowToggleFrameless: "common:WindowToggleFrameless";
207
209
  WindowRestore: "common:WindowRestore";
208
210
  WindowRuntimeReady: "common:WindowRuntimeReady";
209
211
  WindowShow: "common:WindowShow";
@@ -214,5 +216,6 @@ export declare const Types: Readonly<{
214
216
  WindowZoomIn: "common:WindowZoomIn";
215
217
  WindowZoomOut: "common:WindowZoomOut";
216
218
  WindowZoomReset: "common:WindowZoomReset";
219
+ WindowDropZoneFilesDropped: "common:WindowDropZoneFilesDropped";
217
220
  }>;
218
221
  }>;
package/types/events.d.ts CHANGED
@@ -58,9 +58,10 @@ export declare function Off(...eventNames: [string, ...string[]]): void;
58
58
  */
59
59
  export declare function OffAll(): void;
60
60
  /**
61
- * Emits the given event.
61
+ * Emits an event using the name and data.
62
62
  *
63
- * @param event - The name of the event to emit.
64
63
  * @returns A promise that will be fulfilled once the event has been emitted.
64
+ * @param name - the name of the event to emit.
65
+ * @param data - the data to be sent with the event.
65
66
  */
66
- export declare function Emit(event: WailsEvent): Promise<void>;
67
+ export declare function Emit(name: string, data?: any): Promise<void>;
package/types/system.d.ts CHANGED
@@ -81,3 +81,12 @@ export declare function IsARM64(): boolean;
81
81
  * @returns True if the app is being run in debug mode.
82
82
  */
83
83
  export declare function IsDebug(): boolean;
84
+ /**
85
+ * Handles file drops originating from platform-specific code (e.g., macOS native drag-and-drop).
86
+ * Gathers information about the drop target element and sends it back to the Go backend.
87
+ *
88
+ * @param filenames - An array of file paths (strings) that were dropped.
89
+ * @param x - The x-coordinate of the drop event.
90
+ * @param y - The y-coordinate of the drop event.
91
+ */
92
+ export declare function HandlePlatformFileDrop(filenames: string[], x: number, y: number): void;
package/types/window.d.ts CHANGED
@@ -250,6 +250,10 @@ declare class Window {
250
250
  * Toggles the window between maximised and normal.
251
251
  */
252
252
  ToggleMaximise(): Promise<void>;
253
+ /**
254
+ * Toggles the window between frameless and normal.
255
+ */
256
+ ToggleFrameless(): Promise<void>;
253
257
  /**
254
258
  * Un-fullscreens the window.
255
259
  */
@@ -284,6 +288,16 @@ declare class Window {
284
288
  * Resets the zoom level of the webview content.
285
289
  */
286
290
  ZoomReset(): Promise<void>;
291
+ /**
292
+ * Handles file drops originating from platform-specific code (e.g., macOS native drag-and-drop).
293
+ * Gathers information about the drop target element and sends it back to the Go backend.
294
+ *
295
+ * @param filenames - An array of file paths (strings) that were dropped.
296
+ * @param x - The x-coordinate of the drop event.
297
+ * @param y - The y-coordinate of the drop event.
298
+ */
299
+ HandlePlatformFileDrop(filenames: string[], x: number, y: number): void;
300
+ SnapAssist(): Promise<void>;
287
301
  }
288
302
  /**
289
303
  * The window within which the script is running.