@wailsio/runtime 3.0.0-alpha.9 → 3.0.0-alpha.95

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 (71) hide show
  1. package/dist/android.js +39 -0
  2. package/{src → dist}/application.js +32 -46
  3. package/dist/browser.js +20 -0
  4. package/dist/callable.js +144 -0
  5. package/dist/calls.js +114 -0
  6. package/dist/cancellable.js +792 -0
  7. package/dist/clipboard.js +30 -0
  8. package/dist/contextmenu.js +83 -0
  9. package/dist/create.js +99 -0
  10. package/dist/dialogs.js +69 -0
  11. package/dist/drag.js +268 -0
  12. package/dist/environment.js +17 -0
  13. package/dist/event_types.js +292 -0
  14. package/dist/events.js +119 -0
  15. package/dist/flags.js +23 -0
  16. package/dist/index.js +88 -0
  17. package/dist/ios.js +28 -0
  18. package/dist/listener.js +44 -0
  19. package/dist/nanoid.js +38 -0
  20. package/dist/plugins/vite.js +64 -0
  21. package/dist/runtime.js +198 -0
  22. package/dist/screens.js +58 -0
  23. package/dist/system.js +158 -0
  24. package/dist/updater.js +74 -0
  25. package/dist/utils.js +98 -0
  26. package/dist/window.js +734 -0
  27. package/dist/wml.js +179 -0
  28. package/package.json +71 -26
  29. package/types/android.d.ts +21 -0
  30. package/types/application.d.ts +3 -10
  31. package/types/browser.d.ts +4 -4
  32. package/types/callable.d.ts +3 -0
  33. package/types/calls.d.ts +52 -24
  34. package/types/cancellable.d.ts +433 -0
  35. package/types/clipboard.d.ts +6 -5
  36. package/types/contextmenu.d.ts +1 -1
  37. package/types/create.d.ts +36 -0
  38. package/types/dialogs.d.ts +132 -20
  39. package/types/drag.d.ts +1 -4
  40. package/types/environment.d.ts +8 -0
  41. package/types/event_types.d.ts +281 -0
  42. package/types/events.d.ts +70 -33
  43. package/types/flags.d.ts +3 -3
  44. package/types/index.d.ts +32 -48
  45. package/types/ios.d.ts +13 -0
  46. package/types/listener.d.ts +9 -0
  47. package/types/nanoid.d.ts +1 -0
  48. package/types/plugins/vite.d.ts +10 -0
  49. package/types/runtime.d.ts +61 -22
  50. package/types/screens.d.ts +64 -7
  51. package/types/system.d.ts +74 -39
  52. package/types/updater.d.ts +65 -0
  53. package/types/utils.d.ts +21 -0
  54. package/types/window.d.ts +327 -13
  55. package/types/wml.d.ts +5 -3
  56. package/src/browser.js +0 -24
  57. package/src/calls.js +0 -123
  58. package/src/clipboard.js +0 -35
  59. package/src/contextmenu.js +0 -98
  60. package/src/dialogs.js +0 -138
  61. package/src/drag.js +0 -125
  62. package/src/events.js +0 -134
  63. package/src/flags.js +0 -63
  64. package/src/index.d.ts +0 -136
  65. package/src/index.js +0 -58
  66. package/src/runtime.js +0 -122
  67. package/src/screens.js +0 -45
  68. package/src/system.js +0 -122
  69. package/src/window.js +0 -122
  70. package/src/wml.js +0 -151
  71. package/tsconfig.json +0 -20
package/dist/wml.js ADDED
@@ -0,0 +1,179 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { OpenURL } from "./browser.js";
11
+ import { Question } from "./dialogs.js";
12
+ import { Emit } from "./events.js";
13
+ import { canAbortListeners, whenReady } from "./utils.js";
14
+ import Window from "./window.js";
15
+ /**
16
+ * Sends an event with the given name and optional data.
17
+ *
18
+ * @param eventName - - The name of the event to send.
19
+ * @param [data=null] - - Optional data to send along with the event.
20
+ */
21
+ function sendEvent(eventName, data = null) {
22
+ Emit(eventName, data);
23
+ }
24
+ /**
25
+ * Calls a method on a specified window.
26
+ *
27
+ * @param windowName - The name of the window to call the method on.
28
+ * @param methodName - The name of the method to call.
29
+ */
30
+ function callWindowMethod(windowName, methodName) {
31
+ const targetWindow = Window.Get(windowName);
32
+ const method = targetWindow[methodName];
33
+ if (typeof method !== "function") {
34
+ console.error(`Window method '${methodName}' not found`);
35
+ return;
36
+ }
37
+ try {
38
+ method.call(targetWindow);
39
+ }
40
+ catch (e) {
41
+ console.error(`Error calling window method '${methodName}': `, e);
42
+ }
43
+ }
44
+ /**
45
+ * Responds to a triggering event by running appropriate WML actions for the current target.
46
+ */
47
+ function onWMLTriggered(ev) {
48
+ const element = ev.currentTarget;
49
+ function runEffect(choice = "Yes") {
50
+ if (choice !== "Yes")
51
+ return;
52
+ const eventType = element.getAttribute('wml-event') || element.getAttribute('data-wml-event');
53
+ const targetWindow = element.getAttribute('wml-target-window') || element.getAttribute('data-wml-target-window') || "";
54
+ const windowMethod = element.getAttribute('wml-window') || element.getAttribute('data-wml-window');
55
+ const url = element.getAttribute('wml-openurl') || element.getAttribute('data-wml-openurl');
56
+ if (eventType !== null)
57
+ sendEvent(eventType);
58
+ if (windowMethod !== null)
59
+ callWindowMethod(targetWindow, windowMethod);
60
+ if (url !== null)
61
+ void OpenURL(url);
62
+ }
63
+ const confirm = element.getAttribute('wml-confirm') || element.getAttribute('data-wml-confirm');
64
+ if (confirm) {
65
+ Question({
66
+ Title: "Confirm",
67
+ Message: confirm,
68
+ Detached: false,
69
+ Buttons: [
70
+ { Label: "Yes" },
71
+ { Label: "No", IsDefault: true }
72
+ ]
73
+ }).then(runEffect);
74
+ }
75
+ else {
76
+ runEffect();
77
+ }
78
+ }
79
+ // Private field names.
80
+ const controllerSym = Symbol("controller");
81
+ const triggerMapSym = Symbol("triggerMap");
82
+ const elementCountSym = Symbol("elementCount");
83
+ /**
84
+ * AbortControllerRegistry does not actually remember active event listeners: instead
85
+ * it ties them to an AbortSignal and uses an AbortController to remove them all at once.
86
+ */
87
+ class AbortControllerRegistry {
88
+ constructor() {
89
+ this[controllerSym] = new AbortController();
90
+ }
91
+ /**
92
+ * Returns an options object for addEventListener that ties the listener
93
+ * to the AbortSignal from the current AbortController.
94
+ *
95
+ * @param element - An HTML element
96
+ * @param triggers - The list of active WML trigger events for the specified elements
97
+ */
98
+ set(element, triggers) {
99
+ return { signal: this[controllerSym].signal };
100
+ }
101
+ /**
102
+ * Removes all registered event listeners and resets the registry.
103
+ */
104
+ reset() {
105
+ this[controllerSym].abort();
106
+ this[controllerSym] = new AbortController();
107
+ }
108
+ }
109
+ /**
110
+ * WeakMapRegistry maps active trigger events to each DOM element through a WeakMap.
111
+ * This ensures that the mapping remains private to this module, while still allowing garbage
112
+ * collection of the involved elements.
113
+ */
114
+ class WeakMapRegistry {
115
+ constructor() {
116
+ this[triggerMapSym] = new WeakMap();
117
+ this[elementCountSym] = 0;
118
+ }
119
+ /**
120
+ * Sets active triggers for the specified element.
121
+ *
122
+ * @param element - An HTML element
123
+ * @param triggers - The list of active WML trigger events for the specified element
124
+ */
125
+ set(element, triggers) {
126
+ if (!this[triggerMapSym].has(element)) {
127
+ this[elementCountSym]++;
128
+ }
129
+ this[triggerMapSym].set(element, triggers);
130
+ return {};
131
+ }
132
+ /**
133
+ * Removes all registered event listeners.
134
+ */
135
+ reset() {
136
+ if (this[elementCountSym] <= 0)
137
+ return;
138
+ for (const element of document.body.querySelectorAll('*')) {
139
+ if (this[elementCountSym] <= 0)
140
+ break;
141
+ const triggers = this[triggerMapSym].get(element);
142
+ if (triggers != null) {
143
+ this[elementCountSym]--;
144
+ }
145
+ for (const trigger of triggers || [])
146
+ element.removeEventListener(trigger, onWMLTriggered);
147
+ }
148
+ this[triggerMapSym] = new WeakMap();
149
+ this[elementCountSym] = 0;
150
+ }
151
+ }
152
+ const triggerRegistry = canAbortListeners() ? new AbortControllerRegistry() : new WeakMapRegistry();
153
+ /**
154
+ * Adds event listeners to the specified element.
155
+ */
156
+ function addWMLListeners(element) {
157
+ const triggerRegExp = /\S+/g;
158
+ const triggerAttr = (element.getAttribute('wml-trigger') || element.getAttribute('data-wml-trigger') || "click");
159
+ const triggers = [];
160
+ let match;
161
+ while ((match = triggerRegExp.exec(triggerAttr)) !== null)
162
+ triggers.push(match[0]);
163
+ const options = triggerRegistry.set(element, triggers);
164
+ for (const trigger of triggers)
165
+ element.addEventListener(trigger, onWMLTriggered, options);
166
+ }
167
+ /**
168
+ * Schedules an automatic reload of WML to be performed as soon as the document is fully loaded.
169
+ */
170
+ export function Enable() {
171
+ whenReady(Reload);
172
+ }
173
+ /**
174
+ * Reloads the WML page by adding necessary event listeners and browser listeners.
175
+ */
176
+ export function Reload() {
177
+ triggerRegistry.reset();
178
+ document.body.querySelectorAll('[wml-event], [wml-window], [wml-openurl], [data-wml-event], [data-wml-window], [data-wml-openurl]').forEach(addWMLListeners);
179
+ }
package/package.json CHANGED
@@ -1,26 +1,71 @@
1
- {
2
- "name": "@wailsio/runtime",
3
- "version": "3.0.0-alpha.9",
4
- "description": "Wails Runtime",
5
- "main": "src/index.js",
6
- "types": "types/index.d.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/wailsapp/wails.git"
10
- },
11
- "scripts": {
12
- "prebuild:types": "rimraf ./types",
13
- "build:types": "npx -p typescript tsc src/index.js --declaration --allowJs --emitDeclarationOnly --outDir types"
14
- },
15
- "author": "The Wails Team",
16
- "license": "MIT",
17
- "bugs": {
18
- "url": "https://github.com/wailsapp/wails/issues"
19
- },
20
- "homepage": "https://wails.io",
21
- "private": false,
22
- "devDependencies": {
23
- "rimraf": "^5.0.5",
24
- "typescript": "^5.3.3"
25
- }
26
- }
1
+ {
2
+ "name": "@wailsio/runtime",
3
+ "type": "module",
4
+ "version": "3.0.0-alpha.95",
5
+ "description": "Wails Runtime",
6
+ "types": "types/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./types/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./plugins/*": {
13
+ "types": "./types/plugins/*.d.ts",
14
+ "default": "./dist/plugins/*.js"
15
+ }
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/wailsapp/wails.git",
20
+ "directory": "v3/internal/runtime/desktop/@wailsio/runtime"
21
+ },
22
+ "author": "The Wails Team",
23
+ "license": "MIT",
24
+ "homepage": "https://v3.wails.io",
25
+ "bugs": {
26
+ "url": "https://github.com/wailsapp/wails/issues"
27
+ },
28
+ "files": [
29
+ "./dist",
30
+ "./types"
31
+ ],
32
+ "sideEffects": [
33
+ "./dist/index.js",
34
+ "./dist/contextmenu.js",
35
+ "./dist/drag.js"
36
+ ],
37
+ "scripts": {
38
+ "check": "npx tsc --noEmit",
39
+ "test": "npx vitest run",
40
+ "clean": "npx rimraf ./dist ./docs ./types ./tsconfig.tsbuildinfo",
41
+ "generate:events": "task generate:events",
42
+ "generate": "npm run generate:events",
43
+ "prebuild": "npm run clean && npm run generate",
44
+ "build:code": "npx tsc",
45
+ "build:docs": "npx typedoc --gitRevision master --plugin typedoc-plugin-mdn-links --plugin typedoc-plugin-missing-exports ./src/index.ts",
46
+ "build:docs:md": "npx typedoc --gitRevision master --plugin typedoc-plugin-markdown --plugin typedoc-plugin-mdn-links --plugin typedoc-plugin-missing-exports ./src/index.ts",
47
+ "build": "npm run build:code & npm run build:docs & wait",
48
+ "prepack": "npm run build"
49
+ },
50
+ "devDependencies": {
51
+ "happy-dom": "^20.9.0",
52
+ "promises-aplus-tests": "2.1.2",
53
+ "rimraf": "^6.0.1",
54
+ "typedoc": "^0.28.0",
55
+ "typedoc-plugin-markdown": "^4.4.2",
56
+ "typedoc-plugin-mdn-links": "^5.1.1",
57
+ "typedoc-plugin-missing-exports": "^4.1.3",
58
+ "typescript": "^5.7.3",
59
+ "vite": "^8.0.13",
60
+ "vitest": "^4.1.0"
61
+ },
62
+ "overrides": {
63
+ "promises-aplus-tests": {
64
+ "mocha": "^11.1.0",
65
+ "sinon": "^19.0.2",
66
+ "underscore": "^1.13.7"
67
+ },
68
+ "serialize-javascript": "^7.0.5",
69
+ "diff": "^8.0.2"
70
+ }
71
+ }
@@ -0,0 +1,21 @@
1
+ export declare namespace Haptics {
2
+ /** Vibrate the device for the given duration in milliseconds. */
3
+ function Vibrate(durationMs?: number): Promise<void>;
4
+ }
5
+ export declare namespace Device {
6
+ interface Info {
7
+ platform: string;
8
+ manufacturer: string;
9
+ brand: string;
10
+ model: string;
11
+ device: string;
12
+ version: string;
13
+ sdkInt: number;
14
+ }
15
+ /** Return information about the Android device. */
16
+ function Info(): Promise<Info>;
17
+ }
18
+ export declare namespace Toast {
19
+ /** Show a short Android toast message. */
20
+ function Show(message: string): Promise<void>;
21
+ }
@@ -1,19 +1,12 @@
1
1
  /**
2
2
  * Hides a certain method by calling the HideMethod function.
3
- *
4
- * @return {Promise<void>}
5
- *
6
3
  */
7
- export function Hide(): Promise<void>;
4
+ export declare function Hide(): Promise<void>;
8
5
  /**
9
6
  * Calls the ShowMethod and returns the result.
10
- *
11
- * @return {Promise<void>}
12
7
  */
13
- export function Show(): Promise<void>;
8
+ export declare function Show(): Promise<void>;
14
9
  /**
15
10
  * Calls the QuitMethod to terminate the program.
16
- *
17
- * @return {Promise<void>}
18
11
  */
19
- export function Quit(): Promise<void>;
12
+ export declare function Quit(): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Open a browser window to the given URL
3
- * @param {string} url - The URL to open
4
- * @returns {Promise<string>}
2
+ * Open a browser window to the given URL.
3
+ *
4
+ * @param url - The URL to open
5
5
  */
6
- export function OpenURL(url: string): Promise<string>;
6
+ export declare function OpenURL(url: string | URL): Promise<void>;
@@ -0,0 +1,3 @@
1
+ declare function isCallableRefApply<T>(value: T | unknown): value is (...args: any[]) => any;
2
+ declare const _default: typeof isCallableRefApply;
3
+ export default _default;
package/types/calls.d.ts CHANGED
@@ -1,35 +1,63 @@
1
- export function resultHandler(id: any, data: any, isJSON: any): void;
2
- export function errorHandler(id: any, message: any): void;
1
+ import { CancellablePromise } from "./cancellable.js";
3
2
  /**
4
- * Call method.
5
- *
6
- * @param {Object} options - The options for the method.
7
- * @returns {Object} - The result of the call.
3
+ * Holds all required information for a binding call.
4
+ * May provide either a method ID or a method name, but not both.
5
+ */
6
+ export type CallOptions = {
7
+ /** The numeric ID of the bound method to call. */
8
+ methodID: number;
9
+ /** The fully qualified name of the bound method to call. */
10
+ methodName?: never;
11
+ /** Arguments to be passed into the bound method. */
12
+ args: any[];
13
+ } | {
14
+ /** The numeric ID of the bound method to call. */
15
+ methodID?: never;
16
+ /** The fully qualified name of the bound method to call. */
17
+ methodName: string;
18
+ /** Arguments to be passed into the bound method. */
19
+ args: any[];
20
+ };
21
+ /**
22
+ * Exception class that will be thrown in case the bound method returns an error.
23
+ * The value of the {@link RuntimeError#name} property is "RuntimeError".
8
24
  */
9
- export function Call(options: any): any;
25
+ export declare class RuntimeError extends Error {
26
+ /**
27
+ * Constructs a new RuntimeError instance.
28
+ * @param message - The error message.
29
+ * @param options - Options to be forwarded to the Error constructor.
30
+ */
31
+ constructor(message?: string, options?: ErrorOptions);
32
+ }
10
33
  /**
11
- * Executes a method by name.
34
+ * Call a bound method according to the given call options.
35
+ *
36
+ * In case of failure, the returned promise will reject with an exception
37
+ * among ReferenceError (unknown method), TypeError (wrong argument count or type),
38
+ * {@link RuntimeError} (method returned an error), or other (network or internal errors).
39
+ * The exception might have a "cause" field with the value returned
40
+ * by the application- or service-level error marshaling functions.
12
41
  *
13
- * @param {string} name - The name of the method in the format 'package.struct.method'.
14
- * @param {...*} args - The arguments to pass to the method.
15
- * @throws {Error} If the name is not a string or is not in the correct format.
16
- * @returns {*} The result of the method execution.
42
+ * @param options - A method call descriptor.
43
+ * @returns The result of the call.
17
44
  */
18
- export function ByName(name: string, ...args: any[]): any;
45
+ export declare function Call(options: CallOptions): CancellablePromise<any>;
19
46
  /**
20
- * Calls a method by its ID with the specified arguments.
47
+ * Calls a bound method by name with the specified arguments.
48
+ * See {@link Call} for details.
21
49
  *
22
- * @param {string} methodID - The ID of the method to call.
23
- * @param {...*} args - The arguments to pass to the method.
24
- * @return {*} - The result of the method call.
50
+ * @param methodName - The name of the method in the format 'package.struct.method'.
51
+ * @param args - The arguments to pass to the method.
52
+ * @returns The result of the method call.
25
53
  */
26
- export function ByID(methodID: string, ...args: any[]): any;
54
+ export declare function ByName(methodName: string, ...args: any[]): CancellablePromise<any>;
27
55
  /**
28
- * Calls a method on a plugin.
56
+ * Calls a method by its numeric ID with the specified arguments.
57
+ * See {@link Call} for details.
29
58
  *
30
- * @param {string} pluginName - The name of the plugin.
31
- * @param {string} methodName - The name of the method to call.
32
- * @param {...*} args - The arguments to pass to the method.
33
- * @returns {*} - The result of the method call.
59
+ * @param methodID - The ID of the method to call.
60
+ * @param args - The arguments to pass to the method.
61
+ * @return The result of the method call.
34
62
  */
35
- export function Plugin(pluginName: string, methodName: string, ...args: any[]): any;
63
+ export declare function ByID(methodID: number, ...args: any[]): CancellablePromise<any>;