@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.
- package/{application.js → dist/application.js} +32 -46
- package/dist/browser.js +20 -0
- package/dist/callable.js +144 -0
- package/dist/calls.js +194 -0
- package/dist/cancellable.js +792 -0
- package/dist/clipboard.js +30 -0
- package/dist/contextmenu.js +80 -0
- package/dist/create.js +94 -0
- package/dist/dialogs.js +134 -0
- package/dist/drag.js +222 -0
- package/dist/event_types.js +232 -0
- package/dist/events.js +114 -0
- package/dist/flags.js +23 -0
- package/dist/index.js +38 -0
- package/dist/listener.js +44 -0
- package/dist/nanoid.js +38 -0
- package/dist/runtime.js +63 -0
- package/{screens.js → dist/screens.js} +38 -45
- package/dist/system.js +146 -0
- package/dist/utils.js +95 -0
- package/dist/window.js +570 -0
- package/dist/wml.js +179 -0
- package/package.json +62 -18
- package/types/application.d.ts +12 -0
- package/types/browser.d.ts +6 -0
- package/types/callable.d.ts +3 -0
- package/types/calls.d.ts +63 -0
- package/types/cancellable.d.ts +434 -0
- package/types/clipboard.d.ts +13 -0
- package/types/contextmenu.d.ts +1 -0
- package/types/create.d.ts +31 -0
- package/types/dialogs.d.ts +140 -0
- package/types/drag.d.ts +1 -0
- package/types/event_types.d.ts +221 -0
- package/types/events.d.ts +67 -0
- package/types/flags.d.ts +7 -0
- package/types/index.d.ts +16 -0
- package/types/listener.d.ts +9 -0
- package/types/nanoid.d.ts +1 -0
- package/types/runtime.d.ts +22 -0
- package/types/screens.d.ts +60 -0
- package/types/system.d.ts +92 -0
- package/types/utils.d.ts +21 -0
- package/types/window.d.ts +306 -0
- package/types/wml.d.ts +8 -0
- package/browser.js +0 -24
- package/calls.js +0 -123
- package/clipboard.js +0 -35
- package/contextmenu.js +0 -98
- package/dialogs.js +0 -138
- package/drag.js +0 -125
- package/events.js +0 -134
- package/flags.js +0 -63
- package/index.js +0 -56
- package/runtime.js +0 -122
- package/system.js +0 -122
- package/types.d.ts +0 -135
- package/window.js +0 -122
- package/wml.js +0 -151
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,18 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@wailsio/runtime",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@wailsio/runtime",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "3.0.0-alpha.71",
|
|
5
|
+
"description": "Wails Runtime",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/wailsapp/wails.git",
|
|
14
|
+
"directory": "v3/internal/runtime/desktop/@wailsio/runtime"
|
|
15
|
+
},
|
|
16
|
+
"author": "The Wails Team",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"homepage": "https://v3.wails.io",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/wailsapp/wails/issues"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"./dist",
|
|
24
|
+
"./types"
|
|
25
|
+
],
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"./dist/index.js",
|
|
28
|
+
"./dist/contextmenu.js",
|
|
29
|
+
"./dist/drag.js"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"check": "npx tsc --noEmit",
|
|
33
|
+
"test": "npx vitest run",
|
|
34
|
+
"clean": "npx rimraf ./dist ./docs ./types ./tsconfig.tsbuildinfo",
|
|
35
|
+
"generate:events": "task generate:events",
|
|
36
|
+
"generate": "npm run generate:events",
|
|
37
|
+
"prebuild": "npm run clean && npm run generate",
|
|
38
|
+
"build:code": "npx tsc",
|
|
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
|
+
"build": "npm run build:code & npm run build:docs & wait",
|
|
42
|
+
"prepack": "npm run build"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"happy-dom": "^17.1.1",
|
|
46
|
+
"promises-aplus-tests": "2.1.2",
|
|
47
|
+
"rimraf": "^5.0.5",
|
|
48
|
+
"typedoc": "^0.27.7",
|
|
49
|
+
"typedoc-plugin-markdown": "^4.4.2",
|
|
50
|
+
"typedoc-plugin-mdn-links": "^4.0.13",
|
|
51
|
+
"typedoc-plugin-missing-exports": "^3.1.0",
|
|
52
|
+
"typescript": "^5.7.3",
|
|
53
|
+
"vitest": "^3.0.6"
|
|
54
|
+
},
|
|
55
|
+
"overrides": {
|
|
56
|
+
"promises-aplus-tests": {
|
|
57
|
+
"mocha": "^11.1.0",
|
|
58
|
+
"sinon": "^19.0.2",
|
|
59
|
+
"underscore": "^1.13.7"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hides a certain method by calling the HideMethod function.
|
|
3
|
+
*/
|
|
4
|
+
export declare function Hide(): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Calls the ShowMethod and returns the result.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Show(): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Calls the QuitMethod to terminate the program.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Quit(): Promise<void>;
|
package/types/calls.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CancellablePromise } from "./cancellable.js";
|
|
2
|
+
/**
|
|
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".
|
|
24
|
+
*/
|
|
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
|
+
}
|
|
33
|
+
/**
|
|
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.
|
|
41
|
+
*
|
|
42
|
+
* @param options - A method call descriptor.
|
|
43
|
+
* @returns The result of the call.
|
|
44
|
+
*/
|
|
45
|
+
export declare function Call(options: CallOptions): CancellablePromise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Calls a bound method by name with the specified arguments.
|
|
48
|
+
* See {@link Call} for details.
|
|
49
|
+
*
|
|
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.
|
|
53
|
+
*/
|
|
54
|
+
export declare function ByName(methodName: string, ...args: any[]): CancellablePromise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Calls a method by its numeric ID with the specified arguments.
|
|
57
|
+
* See {@link Call} for details.
|
|
58
|
+
*
|
|
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.
|
|
62
|
+
*/
|
|
63
|
+
export declare function ByID(methodID: number, ...args: any[]): CancellablePromise<any>;
|