@wailsio/runtime 3.0.0-alpha.5 → 3.0.0-alpha.55
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/Create.Any.html +2 -0
- package/docs/functions/Create.Array.html +4 -0
- package/docs/functions/Create.ByteSlice.html +3 -0
- package/docs/functions/Create.Map.html +4 -0
- package/docs/functions/Create.Nullable.html +3 -0
- package/docs/functions/Create.Struct.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/functions/init.html +1 -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.Rect.html +9 -0
- package/docs/interfaces/Screens.Screen.html +25 -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/Create.html +7 -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 +7 -0
- package/docs/modules/System.html +14 -0
- package/docs/modules/WML.html +3 -0
- package/docs/modules.html +14 -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 -98
- 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 +219 -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 -122
- 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 +52 -0
- package/types/dialogs.d.ts +184 -0
- package/types/event_types.d.ts +219 -0
- package/types/events.d.ts +271 -0
- package/types/flags.d.ts +7 -0
- package/types/index.d.ts +14 -0
- package/types/nanoid.d.ts +1 -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
package/src/create.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Any is a dummy creation function for simple or unknown types.
|
|
15
|
+
* @template T
|
|
16
|
+
* @param {any} source
|
|
17
|
+
* @returns {T}
|
|
18
|
+
*/
|
|
19
|
+
export function Any(source) {
|
|
20
|
+
return /** @type {T} */(source);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ByteSlice is a creation function that replaces
|
|
25
|
+
* null strings with empty strings.
|
|
26
|
+
* @param {any} source
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
export function ByteSlice(source) {
|
|
30
|
+
return /** @type {any} */((source == null) ? "" : source);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Array takes a creation function for an arbitrary type
|
|
35
|
+
* and returns an in-place creation function for an array
|
|
36
|
+
* whose elements are of that type.
|
|
37
|
+
* @template T
|
|
38
|
+
* @param {(source: any) => T} element
|
|
39
|
+
* @returns {(source: any) => T[]}
|
|
40
|
+
*/
|
|
41
|
+
export function Array(element) {
|
|
42
|
+
if (element === Any) {
|
|
43
|
+
return (source) => (source === null ? [] : source);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (source) => {
|
|
47
|
+
if (source === null) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < source.length; i++) {
|
|
51
|
+
source[i] = element(source[i]);
|
|
52
|
+
}
|
|
53
|
+
return source;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Map takes creation functions for two arbitrary types
|
|
59
|
+
* and returns an in-place creation function for an object
|
|
60
|
+
* whose keys and values are of those types.
|
|
61
|
+
* @template K, V
|
|
62
|
+
* @param {(source: any) => K} key
|
|
63
|
+
* @param {(source: any) => V} value
|
|
64
|
+
* @returns {(source: any) => { [_: K]: V }}
|
|
65
|
+
*/
|
|
66
|
+
export function Map(key, value) {
|
|
67
|
+
if (value === Any) {
|
|
68
|
+
return (source) => (source === null ? {} : source);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (source) => {
|
|
72
|
+
if (source === null) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
for (const key in source) {
|
|
76
|
+
source[key] = value(source[key]);
|
|
77
|
+
}
|
|
78
|
+
return source;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Nullable takes a creation function for an arbitrary type
|
|
84
|
+
* and returns a creation function for a nullable value of that type.
|
|
85
|
+
* @template T
|
|
86
|
+
* @param {(source: any) => T} element
|
|
87
|
+
* @returns {(source: any) => (T | null)}
|
|
88
|
+
*/
|
|
89
|
+
export function Nullable(element) {
|
|
90
|
+
if (element === Any) {
|
|
91
|
+
return Any;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (source) => (source === null ? null : element(source));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Struct takes an object mapping field names to creation functions
|
|
99
|
+
* and returns an in-place creation function for a struct.
|
|
100
|
+
* @template {{ [_: string]: ((source: any) => any) }} T
|
|
101
|
+
* @template {{ [Key in keyof T]?: ReturnType<T[Key]> }} U
|
|
102
|
+
* @param {T} createField
|
|
103
|
+
* @returns {(source: any) => U}
|
|
104
|
+
*/
|
|
105
|
+
export function Struct(createField) {
|
|
106
|
+
let allAny = true;
|
|
107
|
+
for (const name in createField) {
|
|
108
|
+
if (createField[name] !== Any) {
|
|
109
|
+
allAny = false;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (allAny) {
|
|
114
|
+
return Any;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return (source) => {
|
|
118
|
+
for (const name in createField) {
|
|
119
|
+
if (name in source) {
|
|
120
|
+
source[name] = createField[name](source[name]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return source;
|
|
124
|
+
};
|
|
125
|
+
}
|
package/src/dialogs.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* @typedef {Object} OpenFileDialogOptions
|
|
15
|
+
* @property {boolean} [CanChooseDirectories] - Indicates if directories can be chosen.
|
|
16
|
+
* @property {boolean} [CanChooseFiles] - Indicates if files can be chosen.
|
|
17
|
+
* @property {boolean} [CanCreateDirectories] - Indicates if directories can be created.
|
|
18
|
+
* @property {boolean} [ShowHiddenFiles] - Indicates if hidden files should be shown.
|
|
19
|
+
* @property {boolean} [ResolvesAliases] - Indicates if aliases should be resolved.
|
|
20
|
+
* @property {boolean} [AllowsMultipleSelection] - Indicates if multiple selection is allowed.
|
|
21
|
+
* @property {boolean} [HideExtension] - Indicates if the extension should be hidden.
|
|
22
|
+
* @property {boolean} [CanSelectHiddenExtension] - Indicates if hidden extensions can be selected.
|
|
23
|
+
* @property {boolean} [TreatsFilePackagesAsDirectories] - Indicates if file packages should be treated as directories.
|
|
24
|
+
* @property {boolean} [AllowsOtherFiletypes] - Indicates if other file types are allowed.
|
|
25
|
+
* @property {FileFilter[]} [Filters] - Array of file filters.
|
|
26
|
+
* @property {string} [Title] - Title of the dialog.
|
|
27
|
+
* @property {string} [Message] - Message to show in the dialog.
|
|
28
|
+
* @property {string} [ButtonText] - Text to display on the button.
|
|
29
|
+
* @property {string} [Directory] - Directory to open in the dialog.
|
|
30
|
+
* @property {boolean} [Detached] - Indicates if the dialog should appear detached from the main window.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {Object} SaveFileDialogOptions
|
|
36
|
+
* @property {string} [Filename] - Default filename to use in the dialog.
|
|
37
|
+
* @property {boolean} [CanChooseDirectories] - Indicates if directories can be chosen.
|
|
38
|
+
* @property {boolean} [CanChooseFiles] - Indicates if files can be chosen.
|
|
39
|
+
* @property {boolean} [CanCreateDirectories] - Indicates if directories can be created.
|
|
40
|
+
* @property {boolean} [ShowHiddenFiles] - Indicates if hidden files should be shown.
|
|
41
|
+
* @property {boolean} [ResolvesAliases] - Indicates if aliases should be resolved.
|
|
42
|
+
* @property {boolean} [AllowsMultipleSelection] - Indicates if multiple selection is allowed.
|
|
43
|
+
* @property {boolean} [HideExtension] - Indicates if the extension should be hidden.
|
|
44
|
+
* @property {boolean} [CanSelectHiddenExtension] - Indicates if hidden extensions can be selected.
|
|
45
|
+
* @property {boolean} [TreatsFilePackagesAsDirectories] - Indicates if file packages should be treated as directories.
|
|
46
|
+
* @property {boolean} [AllowsOtherFiletypes] - Indicates if other file types are allowed.
|
|
47
|
+
* @property {FileFilter[]} [Filters] - Array of file filters.
|
|
48
|
+
* @property {string} [Title] - Title of the dialog.
|
|
49
|
+
* @property {string} [Message] - Message to show in the dialog.
|
|
50
|
+
* @property {string} [ButtonText] - Text to display on the button.
|
|
51
|
+
* @property {string} [Directory] - Directory to open in the dialog.
|
|
52
|
+
* @property {boolean} [Detached] - Indicates if the dialog should appear detached from the main window.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {Object} MessageDialogOptions
|
|
57
|
+
* @property {string} [Title] - The title of the dialog window.
|
|
58
|
+
* @property {string} [Message] - The main message to show in the dialog.
|
|
59
|
+
* @property {Button[]} [Buttons] - Array of button options to show in the dialog.
|
|
60
|
+
* @property {boolean} [Detached] - True if the dialog should appear detached from the main window (if applicable).
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {Object} Button
|
|
65
|
+
* @property {string} [Label] - Text that appears within the button.
|
|
66
|
+
* @property {boolean} [IsCancel] - True if the button should cancel an operation when clicked.
|
|
67
|
+
* @property {boolean} [IsDefault] - True if the button should be the default action when the user presses enter.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @typedef {Object} FileFilter
|
|
72
|
+
* @property {string} [DisplayName] - Display name for the filter, it could be "Text Files", "Images" etc.
|
|
73
|
+
* @property {string} [Pattern] - Pattern to match for the filter, e.g. "*.txt;*.md" for text markdown files.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
// setup
|
|
77
|
+
window._wails = window._wails || {};
|
|
78
|
+
window._wails.dialogErrorCallback = dialogErrorCallback;
|
|
79
|
+
window._wails.dialogResultCallback = dialogResultCallback;
|
|
80
|
+
|
|
81
|
+
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
82
|
+
|
|
83
|
+
import { nanoid } from './nanoid.js';
|
|
84
|
+
|
|
85
|
+
// Define constants from the `methods` object in Title Case
|
|
86
|
+
const DialogInfo = 0;
|
|
87
|
+
const DialogWarning = 1;
|
|
88
|
+
const DialogError = 2;
|
|
89
|
+
const DialogQuestion = 3;
|
|
90
|
+
const DialogOpenFile = 4;
|
|
91
|
+
const DialogSaveFile = 5;
|
|
92
|
+
|
|
93
|
+
const call = newRuntimeCallerWithID(objectNames.Dialog, '');
|
|
94
|
+
const dialogResponses = new Map();
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Generates a unique id that is not present in dialogResponses.
|
|
98
|
+
* @returns {string} unique id
|
|
99
|
+
*/
|
|
100
|
+
function generateID() {
|
|
101
|
+
let result;
|
|
102
|
+
do {
|
|
103
|
+
result = nanoid();
|
|
104
|
+
} while (dialogResponses.has(result));
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Shows a dialog of specified type with the given options.
|
|
110
|
+
* @param {number} type - type of dialog
|
|
111
|
+
* @param {MessageDialogOptions|OpenFileDialogOptions|SaveFileDialogOptions} options - options for the dialog
|
|
112
|
+
* @returns {Promise} promise that resolves with result of dialog
|
|
113
|
+
*/
|
|
114
|
+
function dialog(type, options = {}) {
|
|
115
|
+
const id = generateID();
|
|
116
|
+
options["dialog-id"] = id;
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
dialogResponses.set(id, {resolve, reject});
|
|
119
|
+
call(type, options).catch((error) => {
|
|
120
|
+
reject(error);
|
|
121
|
+
dialogResponses.delete(id);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Handles the callback from a dialog.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} id - The ID of the dialog response.
|
|
130
|
+
* @param {string} data - The data received from the dialog.
|
|
131
|
+
* @param {boolean} isJSON - Flag indicating whether the data is in JSON format.
|
|
132
|
+
*
|
|
133
|
+
* @return {undefined}
|
|
134
|
+
*/
|
|
135
|
+
function dialogResultCallback(id, data, isJSON) {
|
|
136
|
+
let p = dialogResponses.get(id);
|
|
137
|
+
if (p) {
|
|
138
|
+
if (isJSON) {
|
|
139
|
+
p.resolve(JSON.parse(data));
|
|
140
|
+
} else {
|
|
141
|
+
p.resolve(data);
|
|
142
|
+
}
|
|
143
|
+
dialogResponses.delete(id);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Callback function for handling errors in dialog.
|
|
149
|
+
*
|
|
150
|
+
* @param {string} id - The id of the dialog response.
|
|
151
|
+
* @param {string} message - The error message.
|
|
152
|
+
*
|
|
153
|
+
* @return {void}
|
|
154
|
+
*/
|
|
155
|
+
function dialogErrorCallback(id, message) {
|
|
156
|
+
let p = dialogResponses.get(id);
|
|
157
|
+
if (p) {
|
|
158
|
+
p.reject(message);
|
|
159
|
+
dialogResponses.delete(id);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
// Replace `methods` with constants in Title Case
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @param {MessageDialogOptions} options - Dialog options
|
|
168
|
+
* @returns {Promise<string>} - The label of the button pressed
|
|
169
|
+
*/
|
|
170
|
+
export const Info = (options) => dialog(DialogInfo, options);
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param {MessageDialogOptions} options - Dialog options
|
|
174
|
+
* @returns {Promise<string>} - The label of the button pressed
|
|
175
|
+
*/
|
|
176
|
+
export const Warning = (options) => dialog(DialogWarning, options);
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {MessageDialogOptions} options - Dialog options
|
|
180
|
+
* @returns {Promise<string>} - The label of the button pressed
|
|
181
|
+
*/
|
|
182
|
+
export const Error = (options) => dialog(DialogError, options);
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @param {MessageDialogOptions} options - Dialog options
|
|
186
|
+
* @returns {Promise<string>} - The label of the button pressed
|
|
187
|
+
*/
|
|
188
|
+
export const Question = (options) => dialog(DialogQuestion, options);
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @param {OpenFileDialogOptions} options - Dialog options
|
|
192
|
+
* @returns {Promise<string[]|string>} Returns selected file or list of files. Returns blank string if no file is selected.
|
|
193
|
+
*/
|
|
194
|
+
export const OpenFile = (options) => dialog(DialogOpenFile, options);
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {SaveFileDialogOptions} options - Dialog options
|
|
198
|
+
* @returns {Promise<string>} Returns the selected file. Returns blank string if no file is selected.
|
|
199
|
+
*/
|
|
200
|
+
export const SaveFile = (options) => dialog(DialogSaveFile, options);
|
package/{drag.js → src/drag.js}
RENAMED
|
@@ -1,125 +1,119 @@
|
|
|
1
|
-
/*
|
|
2
|
-
_ __ _ __
|
|
3
|
-
| | / /___ _(_) /____
|
|
4
|
-
| | /| / / __ `/ / / ___/
|
|
5
|
-
| |/ |/ / /_/ / / (__ )
|
|
6
|
-
|__/|__/\__,_/_/_/____/
|
|
7
|
-
The electron alternative for Go
|
|
8
|
-
(c) Lea Anthony 2019-present
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let
|
|
17
|
-
let resizeEdge = null;
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
window._wails = window._wails || {};
|
|
21
|
-
|
|
22
|
-
window._wails.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if(
|
|
49
|
-
invoke(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let
|
|
96
|
-
let
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
let
|
|
102
|
-
let
|
|
103
|
-
let
|
|
104
|
-
let
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
else if (
|
|
118
|
-
else if (
|
|
119
|
-
|
|
120
|
-
else if (topCorner && rightCorner) setResize("ne-resize");
|
|
121
|
-
else if (leftBorder) setResize("w-resize");
|
|
122
|
-
else if (topBorder) setResize("n-resize");
|
|
123
|
-
else if (bottomBorder) setResize("s-resize");
|
|
124
|
-
else if (rightBorder) setResize("e-resize");
|
|
125
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
/* jshint esversion: 9 */
|
|
11
|
+
import {invoke, IsWindows} from "./system";
|
|
12
|
+
import {GetFlag} from "./flags";
|
|
13
|
+
|
|
14
|
+
// Setup
|
|
15
|
+
let shouldDrag = false;
|
|
16
|
+
let resizable = false;
|
|
17
|
+
let resizeEdge = null;
|
|
18
|
+
let defaultCursor = "auto";
|
|
19
|
+
|
|
20
|
+
window._wails = window._wails || {};
|
|
21
|
+
|
|
22
|
+
window._wails.setResizable = function(value) {
|
|
23
|
+
resizable = value;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
window._wails.endDrag = function() {
|
|
27
|
+
document.body.style.cursor = 'default';
|
|
28
|
+
shouldDrag = false;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
window.addEventListener('mousedown', onMouseDown);
|
|
32
|
+
window.addEventListener('mousemove', onMouseMove);
|
|
33
|
+
window.addEventListener('mouseup', onMouseUp);
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function dragTest(e) {
|
|
37
|
+
let val = window.getComputedStyle(e.target).getPropertyValue("--wails-draggable");
|
|
38
|
+
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
|
39
|
+
if (!val || val === "" || val.trim() !== "drag" || mousePressed === 0) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return e.detail === 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function onMouseDown(e) {
|
|
46
|
+
|
|
47
|
+
// Check for resizing
|
|
48
|
+
if (resizeEdge) {
|
|
49
|
+
invoke("wails:resize:" + resizeEdge);
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (dragTest(e)) {
|
|
55
|
+
// This checks for clicks on the scroll bar
|
|
56
|
+
if (e.offsetX > e.target.clientWidth || e.offsetY > e.target.clientHeight) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
shouldDrag = true;
|
|
60
|
+
} else {
|
|
61
|
+
shouldDrag = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function onMouseUp() {
|
|
66
|
+
shouldDrag = false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function setResize(cursor) {
|
|
70
|
+
document.documentElement.style.cursor = cursor || defaultCursor;
|
|
71
|
+
resizeEdge = cursor;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function onMouseMove(e) {
|
|
75
|
+
if (shouldDrag) {
|
|
76
|
+
shouldDrag = false;
|
|
77
|
+
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
|
78
|
+
if (mousePressed > 0) {
|
|
79
|
+
invoke("wails:drag");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!resizable || !IsWindows()) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (defaultCursor == null) {
|
|
87
|
+
defaultCursor = document.documentElement.style.cursor;
|
|
88
|
+
}
|
|
89
|
+
let resizeHandleHeight = GetFlag("system.resizeHandleHeight") || 5;
|
|
90
|
+
let resizeHandleWidth = GetFlag("system.resizeHandleWidth") || 5;
|
|
91
|
+
|
|
92
|
+
// Extra pixels for the corner areas
|
|
93
|
+
let cornerExtra = GetFlag("resizeCornerExtra") || 10;
|
|
94
|
+
|
|
95
|
+
let rightBorder = window.outerWidth - e.clientX < resizeHandleWidth;
|
|
96
|
+
let leftBorder = e.clientX < resizeHandleWidth;
|
|
97
|
+
let topBorder = e.clientY < resizeHandleHeight;
|
|
98
|
+
let bottomBorder = window.outerHeight - e.clientY < resizeHandleHeight;
|
|
99
|
+
|
|
100
|
+
// Adjust for corners
|
|
101
|
+
let rightCorner = window.outerWidth - e.clientX < (resizeHandleWidth + cornerExtra);
|
|
102
|
+
let leftCorner = e.clientX < (resizeHandleWidth + cornerExtra);
|
|
103
|
+
let topCorner = e.clientY < (resizeHandleHeight + cornerExtra);
|
|
104
|
+
let bottomCorner = window.outerHeight - e.clientY < (resizeHandleHeight + cornerExtra);
|
|
105
|
+
|
|
106
|
+
// If we aren't on an edge, but were, reset the cursor to default
|
|
107
|
+
if (!leftBorder && !rightBorder && !topBorder && !bottomBorder && resizeEdge !== undefined) {
|
|
108
|
+
setResize();
|
|
109
|
+
}
|
|
110
|
+
// Adjusted for corner areas
|
|
111
|
+
else if (rightCorner && bottomCorner) setResize("se-resize");
|
|
112
|
+
else if (leftCorner && bottomCorner) setResize("sw-resize");
|
|
113
|
+
else if (leftCorner && topCorner) setResize("nw-resize");
|
|
114
|
+
else if (topCorner && rightCorner) setResize("ne-resize");
|
|
115
|
+
else if (leftBorder) setResize("w-resize");
|
|
116
|
+
else if (topBorder) setResize("n-resize");
|
|
117
|
+
else if (bottomBorder) setResize("s-resize");
|
|
118
|
+
else if (rightBorder) setResize("e-resize");
|
|
119
|
+
}
|