@wailsio/runtime 3.0.0-alpha.4 → 3.0.0-alpha.40
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/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/icons.js +15 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1415 -0
- package/docs/classes/Events.WailsEvent.html +4 -0
- package/docs/functions/Application.Hide.html +2 -0
- package/docs/functions/Application.Quit.html +2 -0
- package/docs/functions/Application.Show.html +2 -0
- package/docs/functions/Browser.OpenURL.html +3 -0
- package/docs/functions/Call.ByID.html +7 -0
- package/docs/functions/Call.ByName.html +6 -0
- package/docs/functions/Call.Call.html +6 -0
- package/docs/functions/Call.Plugin.html +8 -0
- package/docs/functions/Clipboard.SetText.html +6 -0
- package/docs/functions/Clipboard.Text.html +3 -0
- package/docs/functions/Dialogs.Error.html +5 -0
- package/docs/functions/Dialogs.Info.html +5 -0
- package/docs/functions/Dialogs.OpenFile.html +3 -0
- package/docs/functions/Dialogs.Question.html +5 -0
- package/docs/functions/Dialogs.SaveFile.html +3 -0
- package/docs/functions/Dialogs.Warning.html +5 -0
- package/docs/functions/Events.Emit.html +6 -0
- package/docs/functions/Events.Off.html +4 -0
- package/docs/functions/Events.OffAll.html +3 -0
- package/docs/functions/Events.On.html +7 -0
- package/docs/functions/Events.OnMultiple.html +8 -0
- package/docs/functions/Events.Once.html +7 -0
- package/docs/functions/Events.setup.html +1 -0
- package/docs/functions/Flags.GetFlag.html +6 -0
- package/docs/functions/Screens.GetAll.html +3 -0
- package/docs/functions/Screens.GetCurrent.html +3 -0
- package/docs/functions/Screens.GetPrimary.html +3 -0
- package/docs/functions/System.Capabilities.html +4 -0
- package/docs/functions/System.Environment.html +5 -0
- package/docs/functions/System.IsAMD64.html +3 -0
- package/docs/functions/System.IsARM.html +3 -0
- package/docs/functions/System.IsARM64.html +5 -0
- package/docs/functions/System.IsDarkMode.html +5 -0
- package/docs/functions/System.IsDebug.html +1 -0
- package/docs/functions/System.IsLinux.html +3 -0
- package/docs/functions/System.IsMac.html +3 -0
- package/docs/functions/System.IsWindows.html +3 -0
- package/docs/functions/System.invoke.html +1 -0
- package/docs/functions/WML.Enable.html +2 -0
- package/docs/functions/WML.Reload.html +2 -0
- package/docs/index.html +5 -0
- package/docs/interfaces/Dialogs.Button.html +7 -0
- package/docs/interfaces/Dialogs.FileFilter.html +5 -0
- package/docs/interfaces/Dialogs.MessageDialogOptions.html +9 -0
- package/docs/interfaces/Dialogs.OpenFileDialogOptions.html +33 -0
- package/docs/interfaces/Dialogs.SaveFileDialogOptions.html +35 -0
- package/docs/interfaces/Screens.Position.html +5 -0
- package/docs/interfaces/Screens.Rect.html +9 -0
- package/docs/interfaces/Screens.Screen.html +19 -0
- package/docs/interfaces/Screens.Size.html +5 -0
- package/docs/interfaces/System.EnvironmentInfo.html +11 -0
- package/docs/interfaces/System.OSInfo.html +9 -0
- package/docs/modules/Application.html +4 -0
- package/docs/modules/Browser.html +2 -0
- package/docs/modules/Call.html +5 -0
- package/docs/modules/Clipboard.html +3 -0
- package/docs/modules/Dialogs.html +12 -0
- package/docs/modules/Events.html +10 -0
- package/docs/modules/Flags.html +2 -0
- package/docs/modules/Screens.html +8 -0
- package/docs/modules/System.html +14 -0
- package/docs/modules/WML.html +3 -0
- package/docs/modules.html +12 -0
- package/docs/variables/Events.Types.html +1 -0
- package/docs/variables/Window.html +2 -0
- package/package.json +38 -17
- package/{application.js → src/application.js} +46 -46
- package/{browser.js → src/browser.js} +24 -24
- package/src/calls.js +174 -0
- package/{clipboard.js → src/clipboard.js} +35 -35
- package/{contextmenu.js → src/contextmenu.js} +97 -96
- package/src/create.js +125 -0
- package/src/dialogs.js +200 -0
- package/{drag.js → src/drag.js} +119 -125
- package/src/event_types.js +217 -0
- package/{events.js → src/events.js} +140 -134
- package/src/flags.js +25 -0
- package/src/index.js +60 -0
- package/src/nanoid.js +42 -0
- package/{runtime.js → src/runtime.js} +123 -122
- package/src/screens.js +71 -0
- package/{system.js → src/system.js} +143 -118
- package/src/utils.js +86 -0
- package/src/window.js +638 -0
- package/src/wml.js +250 -0
- package/tsconfig.json +20 -0
- package/types/application.d.ts +19 -0
- package/types/browser.d.ts +6 -0
- package/types/calls.d.ts +33 -0
- package/types/clipboard.d.ts +12 -0
- package/types/create.d.ts +45 -0
- package/types/dialogs.d.ts +184 -0
- package/types/event_types.d.ts +217 -0
- package/types/events.d.ts +239 -0
- package/types/flags.d.ts +7 -0
- package/types/index.d.ts +13 -0
- package/types/runtime.d.ts +30 -0
- package/types/screens.d.ts +94 -0
- package/types/system.d.ts +112 -0
- package/types/utils.d.ts +14 -0
- package/types/window.d.ts +407 -0
- package/types/wml.d.ts +12 -0
- package/calls.js +0 -123
- package/dialogs.js +0 -138
- package/flags.js +0 -63
- package/index.js +0 -56
- package/screens.js +0 -45
- package/types.d.ts +0 -130
- package/window.js +0 -122
- package/wml.js +0 -148
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/*
|
|
2
|
-
_ __ _ __
|
|
3
|
-
| | / /___ _(_) /____
|
|
4
|
-
| | /| / / __ `/ / / ___/
|
|
5
|
-
| |/ |/ / /_/ / / (__ )
|
|
6
|
-
|__/|__/\__,_/_/_/____/
|
|
7
|
-
The electron alternative for Go
|
|
8
|
-
(c) Lea Anthony 2019-present
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/* jshint esversion: 9 */
|
|
12
|
-
|
|
13
|
-
import { newRuntimeCallerWithID, objectNames } from "./runtime";
|
|
14
|
-
const call = newRuntimeCallerWithID(objectNames.Application);
|
|
15
|
-
|
|
16
|
-
const HideMethod = 0;
|
|
17
|
-
const ShowMethod = 1;
|
|
18
|
-
const QuitMethod = 2;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Hides a certain method by calling the HideMethod function.
|
|
22
|
-
*
|
|
23
|
-
* @return {Promise<void>}
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
export function Hide() {
|
|
27
|
-
return call(HideMethod);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Calls the ShowMethod and returns the result.
|
|
32
|
-
*
|
|
33
|
-
* @return {Promise<void>}
|
|
34
|
-
*/
|
|
35
|
-
export function Show() {
|
|
36
|
-
return call(ShowMethod);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Calls the QuitMethod to terminate the program.
|
|
41
|
-
*
|
|
42
|
-
* @return {Promise<void>}
|
|
43
|
-
*/
|
|
44
|
-
export function Quit() {
|
|
45
|
-
return call(QuitMethod);
|
|
46
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* jshint esversion: 9 */
|
|
12
|
+
|
|
13
|
+
import { newRuntimeCallerWithID, objectNames } from "./runtime";
|
|
14
|
+
const call = newRuntimeCallerWithID(objectNames.Application, '');
|
|
15
|
+
|
|
16
|
+
const HideMethod = 0;
|
|
17
|
+
const ShowMethod = 1;
|
|
18
|
+
const QuitMethod = 2;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hides a certain method by calling the HideMethod function.
|
|
22
|
+
*
|
|
23
|
+
* @return {Promise<void>}
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
export function Hide() {
|
|
27
|
+
return call(HideMethod);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Calls the ShowMethod and returns the result.
|
|
32
|
+
*
|
|
33
|
+
* @return {Promise<void>}
|
|
34
|
+
*/
|
|
35
|
+
export function Show() {
|
|
36
|
+
return call(ShowMethod);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Calls the QuitMethod to terminate the program.
|
|
41
|
+
*
|
|
42
|
+
* @return {Promise<void>}
|
|
43
|
+
*/
|
|
44
|
+
export function Quit() {
|
|
45
|
+
return call(QuitMethod);
|
|
46
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/*
|
|
2
|
-
_ __ _ __
|
|
3
|
-
| | / /___ _(_) /____
|
|
4
|
-
| | /| / / __ `/ / / ___/
|
|
5
|
-
| |/ |/ / /_/ / / (__ )
|
|
6
|
-
|__/|__/\__,_/_/_/____/
|
|
7
|
-
The electron alternative for Go
|
|
8
|
-
(c) Lea Anthony 2019-present
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/* jshint esversion: 9 */
|
|
12
|
-
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
13
|
-
|
|
14
|
-
const call = newRuntimeCallerWithID(objectNames.Browser, '');
|
|
15
|
-
const BrowserOpenURL = 0;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Open a browser window to the given URL
|
|
19
|
-
* @param {string} url - The URL to open
|
|
20
|
-
* @returns {Promise<string>}
|
|
21
|
-
*/
|
|
22
|
-
export function OpenURL(url) {
|
|
23
|
-
return call(BrowserOpenURL, {url});
|
|
24
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* jshint esversion: 9 */
|
|
12
|
+
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
13
|
+
|
|
14
|
+
const call = newRuntimeCallerWithID(objectNames.Browser, '');
|
|
15
|
+
const BrowserOpenURL = 0;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Open a browser window to the given URL
|
|
19
|
+
* @param {string} url - The URL to open
|
|
20
|
+
* @returns {Promise<string>}
|
|
21
|
+
*/
|
|
22
|
+
export function OpenURL(url) {
|
|
23
|
+
return call(BrowserOpenURL, {url});
|
|
24
|
+
}
|
package/src/calls.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* jshint esversion: 9 */
|
|
12
|
+
import { newRuntimeCallerWithID, objectNames } from "./runtime";
|
|
13
|
+
import { nanoid } from './nanoid.js';
|
|
14
|
+
|
|
15
|
+
// Setup
|
|
16
|
+
window._wails = window._wails || {};
|
|
17
|
+
window._wails.callResultHandler = resultHandler;
|
|
18
|
+
window._wails.callErrorHandler = errorHandler;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const CallBinding = 0;
|
|
22
|
+
const call = newRuntimeCallerWithID(objectNames.Call, '');
|
|
23
|
+
const cancelCall = newRuntimeCallerWithID(objectNames.CancelCall, '');
|
|
24
|
+
let callResponses = new Map();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generates a unique ID using the nanoid library.
|
|
28
|
+
*
|
|
29
|
+
* @return {string} - A unique ID that does not exist in the callResponses set.
|
|
30
|
+
*/
|
|
31
|
+
function generateID() {
|
|
32
|
+
let result;
|
|
33
|
+
do {
|
|
34
|
+
result = nanoid();
|
|
35
|
+
} while (callResponses.has(result));
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Handles the result of a call request.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} id - The id of the request to handle the result for.
|
|
43
|
+
* @param {string} data - The result data of the request.
|
|
44
|
+
* @param {boolean} isJSON - Indicates whether the data is JSON or not.
|
|
45
|
+
*
|
|
46
|
+
* @return {undefined} - This method does not return any value.
|
|
47
|
+
*/
|
|
48
|
+
function resultHandler(id, data, isJSON) {
|
|
49
|
+
const promiseHandler = getAndDeleteResponse(id);
|
|
50
|
+
if (promiseHandler) {
|
|
51
|
+
promiseHandler.resolve(isJSON ? JSON.parse(data) : data);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Handles the error from a call request.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} id - The id of the promise handler.
|
|
59
|
+
* @param {string} message - The error message to reject the promise handler with.
|
|
60
|
+
*
|
|
61
|
+
* @return {void}
|
|
62
|
+
*/
|
|
63
|
+
function errorHandler(id, message) {
|
|
64
|
+
const promiseHandler = getAndDeleteResponse(id);
|
|
65
|
+
if (promiseHandler) {
|
|
66
|
+
promiseHandler.reject(message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves and removes the response associated with the given ID from the callResponses map.
|
|
72
|
+
*
|
|
73
|
+
* @param {any} id - The ID of the response to be retrieved and removed.
|
|
74
|
+
*
|
|
75
|
+
* @returns {any} The response object associated with the given ID.
|
|
76
|
+
*/
|
|
77
|
+
function getAndDeleteResponse(id) {
|
|
78
|
+
const response = callResponses.get(id);
|
|
79
|
+
callResponses.delete(id);
|
|
80
|
+
return response;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Executes a call using the provided type and options.
|
|
85
|
+
*
|
|
86
|
+
* @param {string|number} type - The type of call to execute.
|
|
87
|
+
* @param {Object} [options={}] - Additional options for the call.
|
|
88
|
+
* @return {Promise} - A promise that will be resolved or rejected based on the result of the call. It also has a cancel method to cancel a long running request.
|
|
89
|
+
*/
|
|
90
|
+
function callBinding(type, options = {}) {
|
|
91
|
+
const id = generateID();
|
|
92
|
+
const doCancel = () => { return cancelCall(type, {"call-id": id}) };
|
|
93
|
+
let queuedCancel = false, callRunning = false;
|
|
94
|
+
let p = new Promise((resolve, reject) => {
|
|
95
|
+
options["call-id"] = id;
|
|
96
|
+
callResponses.set(id, { resolve, reject });
|
|
97
|
+
call(type, options).
|
|
98
|
+
then((_) => {
|
|
99
|
+
callRunning = true;
|
|
100
|
+
if (queuedCancel) {
|
|
101
|
+
return doCancel();
|
|
102
|
+
}
|
|
103
|
+
}).
|
|
104
|
+
catch((error) => {
|
|
105
|
+
reject(error);
|
|
106
|
+
callResponses.delete(id);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
p.cancel = () => {
|
|
110
|
+
if (callRunning) {
|
|
111
|
+
return doCancel();
|
|
112
|
+
} else {
|
|
113
|
+
queuedCancel = true;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return p;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Call method.
|
|
122
|
+
*
|
|
123
|
+
* @param {Object} options - The options for the method.
|
|
124
|
+
* @returns {Object} - The result of the call.
|
|
125
|
+
*/
|
|
126
|
+
export function Call(options) {
|
|
127
|
+
return callBinding(CallBinding, options);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Executes a method by name.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} methodName - The name of the method in the format 'package.struct.method'.
|
|
134
|
+
* @param {...*} args - The arguments to pass to the method.
|
|
135
|
+
* @throws {Error} If the name is not a string or is not in the correct format.
|
|
136
|
+
* @returns {*} The result of the method execution.
|
|
137
|
+
*/
|
|
138
|
+
export function ByName(methodName, ...args) {
|
|
139
|
+
return callBinding(CallBinding, {
|
|
140
|
+
methodName,
|
|
141
|
+
args
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Calls a method by its ID with the specified arguments.
|
|
147
|
+
*
|
|
148
|
+
* @param {number} methodID - The ID of the method to call.
|
|
149
|
+
* @param {...*} args - The arguments to pass to the method.
|
|
150
|
+
* @return {*} - The result of the method call.
|
|
151
|
+
*/
|
|
152
|
+
export function ByID(methodID, ...args) {
|
|
153
|
+
return callBinding(CallBinding, {
|
|
154
|
+
methodID,
|
|
155
|
+
args
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Calls a method on a plugin.
|
|
161
|
+
*
|
|
162
|
+
* @param {string} pluginName - The name of the plugin.
|
|
163
|
+
* @param {string} methodName - The name of the method to call.
|
|
164
|
+
* @param {...*} args - The arguments to pass to the method.
|
|
165
|
+
* @returns {*} - The result of the method call.
|
|
166
|
+
*/
|
|
167
|
+
export function Plugin(pluginName, methodName, ...args) {
|
|
168
|
+
return callBinding(CallBinding, {
|
|
169
|
+
packageName: "wails-plugins",
|
|
170
|
+
structName: pluginName,
|
|
171
|
+
methodName,
|
|
172
|
+
args
|
|
173
|
+
});
|
|
174
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
/*
|
|
2
|
-
_ __ _ __
|
|
3
|
-
| | / /___ _(_) /____
|
|
4
|
-
| | /| / / __ `/ / / ___/
|
|
5
|
-
| |/ |/ / /_/ / / (__ )
|
|
6
|
-
|__/|__/\__,_/_/_/____/
|
|
7
|
-
The electron alternative for Go
|
|
8
|
-
(c) Lea Anthony 2019-present
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/* jshint esversion: 9 */
|
|
12
|
-
|
|
13
|
-
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
14
|
-
|
|
15
|
-
const call = newRuntimeCallerWithID(objectNames.Clipboard, '');
|
|
16
|
-
const ClipboardSetText = 0;
|
|
17
|
-
const ClipboardText = 1;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Sets the text to the Clipboard.
|
|
21
|
-
*
|
|
22
|
-
* @param {string} text - The text to be set to the Clipboard.
|
|
23
|
-
* @return {Promise} - A Promise that resolves when the operation is successful.
|
|
24
|
-
*/
|
|
25
|
-
export function SetText(text) {
|
|
26
|
-
return call(ClipboardSetText, {text});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Get the Clipboard text
|
|
31
|
-
* @returns {Promise<string>} A promise that resolves with the text from the Clipboard.
|
|
32
|
-
*/
|
|
33
|
-
export function Text() {
|
|
34
|
-
return call(ClipboardText);
|
|
35
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* jshint esversion: 9 */
|
|
12
|
+
|
|
13
|
+
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
14
|
+
|
|
15
|
+
const call = newRuntimeCallerWithID(objectNames.Clipboard, '');
|
|
16
|
+
const ClipboardSetText = 0;
|
|
17
|
+
const ClipboardText = 1;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Sets the text to the Clipboard.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} text - The text to be set to the Clipboard.
|
|
23
|
+
* @return {Promise} - A Promise that resolves when the operation is successful.
|
|
24
|
+
*/
|
|
25
|
+
export function SetText(text) {
|
|
26
|
+
return call(ClipboardSetText, {text});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the Clipboard text
|
|
31
|
+
* @returns {Promise<string>} A promise that resolves with the text from the Clipboard.
|
|
32
|
+
*/
|
|
33
|
+
export function Text() {
|
|
34
|
+
return call(ClipboardText);
|
|
35
|
+
}
|
|
@@ -1,96 +1,97 @@
|
|
|
1
|
-
/*
|
|
2
|
-
_ __ _ __
|
|
3
|
-
| | / /___ _(_) /____
|
|
4
|
-
| | /| / / __ `/ / / ___/
|
|
5
|
-
| |/ |/ / /_/ / / (__ )
|
|
6
|
-
|__/|__/\__,_/_/_/____/
|
|
7
|
-
The electron alternative for Go
|
|
8
|
-
(c) Lea Anthony 2019-present
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/* jshint esversion: 9 */
|
|
12
|
-
|
|
13
|
-
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function contextMenuHandler(event) {
|
|
27
|
-
// Check for custom context menu
|
|
28
|
-
let element = event.target;
|
|
29
|
-
let customContextMenu = window.getComputedStyle(element).getPropertyValue("--custom-contextmenu");
|
|
30
|
-
customContextMenu = customContextMenu ? customContextMenu.trim() : "";
|
|
31
|
-
if (customContextMenu) {
|
|
32
|
-
event.preventDefault();
|
|
33
|
-
let customContextMenuData = window.getComputedStyle(element).getPropertyValue("--custom-contextmenu-data");
|
|
34
|
-
openContextMenu(customContextMenu, event.clientX, event.clientY, customContextMenuData);
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
processDefaultContextMenu(event);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/*
|
|
43
|
-
--default-contextmenu: auto; (default) will show the default context menu if contentEditable is true OR text has been selected OR element is input or textarea
|
|
44
|
-
--default-contextmenu: show; will always show the default context menu
|
|
45
|
-
--default-contextmenu: hide; will always hide the default context menu
|
|
46
|
-
|
|
47
|
-
This rule is inherited like normal CSS rules, so nesting works as expected
|
|
48
|
-
*/
|
|
49
|
-
function processDefaultContextMenu(event) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* jshint esversion: 9 */
|
|
12
|
+
|
|
13
|
+
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
14
|
+
import {IsDebug} from "./system";
|
|
15
|
+
|
|
16
|
+
// setup
|
|
17
|
+
window.addEventListener('contextmenu', contextMenuHandler);
|
|
18
|
+
|
|
19
|
+
const call = newRuntimeCallerWithID(objectNames.ContextMenu, '');
|
|
20
|
+
const ContextMenuOpen = 0;
|
|
21
|
+
|
|
22
|
+
function openContextMenu(id, x, y, data) {
|
|
23
|
+
void call(ContextMenuOpen, {id, x, y, data});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function contextMenuHandler(event) {
|
|
27
|
+
// Check for custom context menu
|
|
28
|
+
let element = event.target;
|
|
29
|
+
let customContextMenu = window.getComputedStyle(element).getPropertyValue("--custom-contextmenu");
|
|
30
|
+
customContextMenu = customContextMenu ? customContextMenu.trim() : "";
|
|
31
|
+
if (customContextMenu) {
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
let customContextMenuData = window.getComputedStyle(element).getPropertyValue("--custom-contextmenu-data");
|
|
34
|
+
openContextMenu(customContextMenu, event.clientX, event.clientY, customContextMenuData);
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
processDefaultContextMenu(event);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
--default-contextmenu: auto; (default) will show the default context menu if contentEditable is true OR text has been selected OR element is input or textarea
|
|
44
|
+
--default-contextmenu: show; will always show the default context menu
|
|
45
|
+
--default-contextmenu: hide; will always hide the default context menu
|
|
46
|
+
|
|
47
|
+
This rule is inherited like normal CSS rules, so nesting works as expected
|
|
48
|
+
*/
|
|
49
|
+
function processDefaultContextMenu(event) {
|
|
50
|
+
|
|
51
|
+
// Debug builds always show the menu
|
|
52
|
+
if (IsDebug()) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Process default context menu
|
|
57
|
+
const element = event.target;
|
|
58
|
+
const computedStyle = window.getComputedStyle(element);
|
|
59
|
+
const defaultContextMenuAction = computedStyle.getPropertyValue("--default-contextmenu").trim();
|
|
60
|
+
switch (defaultContextMenuAction) {
|
|
61
|
+
case "show":
|
|
62
|
+
return;
|
|
63
|
+
case "hide":
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
return;
|
|
66
|
+
default:
|
|
67
|
+
// Check if contentEditable is true
|
|
68
|
+
if (element.isContentEditable) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Check if text has been selected
|
|
73
|
+
const selection = window.getSelection();
|
|
74
|
+
const hasSelection = (selection.toString().length > 0)
|
|
75
|
+
if (hasSelection) {
|
|
76
|
+
for (let i = 0; i < selection.rangeCount; i++) {
|
|
77
|
+
const range = selection.getRangeAt(i);
|
|
78
|
+
const rects = range.getClientRects();
|
|
79
|
+
for (let j = 0; j < rects.length; j++) {
|
|
80
|
+
const rect = rects[j];
|
|
81
|
+
if (document.elementFromPoint(rect.left, rect.top) === element) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Check if tagname is input or textarea
|
|
88
|
+
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
|
89
|
+
if (hasSelection || (!element.readOnly && !element.disabled)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// hide default context menu
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
}
|
|
97
|
+
}
|