@wailsio/runtime 3.0.0-alpha.65 → 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.
Files changed (142) hide show
  1. package/{src → dist}/application.js +2 -16
  2. package/dist/browser.js +20 -0
  3. package/dist/callable.js +144 -0
  4. package/dist/calls.js +194 -0
  5. package/dist/cancellable.js +792 -0
  6. package/dist/clipboard.js +30 -0
  7. package/dist/contextmenu.js +80 -0
  8. package/{src → dist}/create.js +2 -33
  9. package/dist/dialogs.js +134 -0
  10. package/dist/drag.js +222 -0
  11. package/dist/event_types.js +232 -0
  12. package/dist/events.js +114 -0
  13. package/dist/flags.js +23 -0
  14. package/dist/index.js +38 -0
  15. package/dist/listener.js +44 -0
  16. package/{src → dist}/nanoid.js +7 -11
  17. package/dist/runtime.js +63 -0
  18. package/dist/screens.js +38 -0
  19. package/dist/system.js +146 -0
  20. package/{src → dist}/utils.js +29 -20
  21. package/dist/window.js +570 -0
  22. package/{src → dist}/wml.js +52 -123
  23. package/package.json +43 -19
  24. package/types/application.d.ts +3 -10
  25. package/types/browser.d.ts +4 -4
  26. package/types/callable.d.ts +3 -0
  27. package/types/calls.d.ts +43 -49
  28. package/types/cancellable.d.ts +434 -0
  29. package/types/clipboard.d.ts +6 -5
  30. package/types/contextmenu.d.ts +1 -0
  31. package/types/create.d.ts +6 -27
  32. package/types/dialogs.d.ts +99 -143
  33. package/types/drag.d.ts +1 -0
  34. package/types/event_types.d.ts +221 -219
  35. package/types/events.d.ts +46 -250
  36. package/types/flags.d.ts +3 -3
  37. package/types/index.d.ts +16 -14
  38. package/types/listener.d.ts +9 -0
  39. package/types/nanoid.d.ts +1 -1
  40. package/types/runtime.d.ts +18 -26
  41. package/types/screens.d.ts +42 -76
  42. package/types/system.d.ts +59 -79
  43. package/types/utils.d.ts +15 -8
  44. package/types/window.d.ts +123 -224
  45. package/types/wml.d.ts +2 -6
  46. package/docs/.nojekyll +0 -1
  47. package/docs/assets/highlight.css +0 -22
  48. package/docs/assets/icons.js +0 -15
  49. package/docs/assets/icons.svg +0 -1
  50. package/docs/assets/main.js +0 -59
  51. package/docs/assets/navigation.js +0 -1
  52. package/docs/assets/search.js +0 -1
  53. package/docs/assets/style.css +0 -1415
  54. package/docs/classes/Call.RuntimeError.html +0 -11
  55. package/docs/classes/Events.WailsEvent.html +0 -4
  56. package/docs/functions/Application.Hide.html +0 -2
  57. package/docs/functions/Application.Quit.html +0 -2
  58. package/docs/functions/Application.Show.html +0 -2
  59. package/docs/functions/Browser.OpenURL.html +0 -3
  60. package/docs/functions/Call.ByID.html +0 -8
  61. package/docs/functions/Call.ByName.html +0 -6
  62. package/docs/functions/Call.Call.html +0 -11
  63. package/docs/functions/Clipboard.SetText.html +0 -6
  64. package/docs/functions/Clipboard.Text.html +0 -3
  65. package/docs/functions/Create.Any.html +0 -2
  66. package/docs/functions/Create.Array.html +0 -4
  67. package/docs/functions/Create.ByteSlice.html +0 -3
  68. package/docs/functions/Create.Map.html +0 -4
  69. package/docs/functions/Create.Nullable.html +0 -3
  70. package/docs/functions/Create.Struct.html +0 -3
  71. package/docs/functions/Dialogs.Error.html +0 -5
  72. package/docs/functions/Dialogs.Info.html +0 -5
  73. package/docs/functions/Dialogs.OpenFile.html +0 -3
  74. package/docs/functions/Dialogs.Question.html +0 -5
  75. package/docs/functions/Dialogs.SaveFile.html +0 -3
  76. package/docs/functions/Dialogs.Warning.html +0 -5
  77. package/docs/functions/Events.Emit.html +0 -6
  78. package/docs/functions/Events.Off.html +0 -4
  79. package/docs/functions/Events.OffAll.html +0 -3
  80. package/docs/functions/Events.On.html +0 -7
  81. package/docs/functions/Events.OnMultiple.html +0 -8
  82. package/docs/functions/Events.Once.html +0 -7
  83. package/docs/functions/Events.setup.html +0 -1
  84. package/docs/functions/Flags.GetFlag.html +0 -6
  85. package/docs/functions/Screens.GetAll.html +0 -3
  86. package/docs/functions/Screens.GetCurrent.html +0 -3
  87. package/docs/functions/Screens.GetPrimary.html +0 -3
  88. package/docs/functions/System.Capabilities.html +0 -4
  89. package/docs/functions/System.Environment.html +0 -5
  90. package/docs/functions/System.IsAMD64.html +0 -3
  91. package/docs/functions/System.IsARM.html +0 -3
  92. package/docs/functions/System.IsARM64.html +0 -5
  93. package/docs/functions/System.IsDarkMode.html +0 -5
  94. package/docs/functions/System.IsDebug.html +0 -1
  95. package/docs/functions/System.IsLinux.html +0 -3
  96. package/docs/functions/System.IsMac.html +0 -3
  97. package/docs/functions/System.IsWindows.html +0 -3
  98. package/docs/functions/System.invoke.html +0 -1
  99. package/docs/functions/WML.Enable.html +0 -2
  100. package/docs/functions/WML.Reload.html +0 -2
  101. package/docs/functions/init.html +0 -1
  102. package/docs/index.html +0 -5
  103. package/docs/interfaces/Call.CallOptions.html +0 -7
  104. package/docs/interfaces/Dialogs.Button.html +0 -7
  105. package/docs/interfaces/Dialogs.FileFilter.html +0 -5
  106. package/docs/interfaces/Dialogs.MessageDialogOptions.html +0 -9
  107. package/docs/interfaces/Dialogs.OpenFileDialogOptions.html +0 -33
  108. package/docs/interfaces/Dialogs.SaveFileDialogOptions.html +0 -35
  109. package/docs/interfaces/Screens.Rect.html +0 -9
  110. package/docs/interfaces/Screens.Screen.html +0 -25
  111. package/docs/interfaces/Screens.Size.html +0 -5
  112. package/docs/interfaces/System.EnvironmentInfo.html +0 -11
  113. package/docs/interfaces/System.OSInfo.html +0 -9
  114. package/docs/modules/Application.html +0 -4
  115. package/docs/modules/Browser.html +0 -2
  116. package/docs/modules/Call.html +0 -6
  117. package/docs/modules/Clipboard.html +0 -3
  118. package/docs/modules/Create.html +0 -7
  119. package/docs/modules/Dialogs.html +0 -12
  120. package/docs/modules/Events.html +0 -10
  121. package/docs/modules/Flags.html +0 -2
  122. package/docs/modules/Screens.html +0 -7
  123. package/docs/modules/System.html +0 -14
  124. package/docs/modules/WML.html +0 -3
  125. package/docs/modules.html +0 -14
  126. package/docs/variables/Events.Types.html +0 -1
  127. package/docs/variables/Window.html +0 -2
  128. package/src/browser.js +0 -24
  129. package/src/calls.js +0 -221
  130. package/src/clipboard.js +0 -35
  131. package/src/contextmenu.js +0 -97
  132. package/src/dialogs.js +0 -200
  133. package/src/drag.js +0 -119
  134. package/src/event_types.js +0 -219
  135. package/src/events.js +0 -140
  136. package/src/flags.js +0 -25
  137. package/src/index.js +0 -60
  138. package/src/runtime.js +0 -92
  139. package/src/screens.js +0 -71
  140. package/src/system.js +0 -143
  141. package/src/window.js +0 -638
  142. package/tsconfig.json +0 -20
package/src/calls.js DELETED
@@ -1,221 +0,0 @@
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
- if (!data) {
52
- promiseHandler.resolve();
53
- } else if (!isJSON) {
54
- promiseHandler.resolve(data);
55
- } else {
56
- try {
57
- promiseHandler.resolve(JSON.parse(data));
58
- } catch (err) {
59
- promiseHandler.reject(new TypeError("could not parse result: " + err.message, { cause: err }));
60
- }
61
- }
62
- }
63
- }
64
-
65
- /**
66
- * Handles the error from a call request.
67
- *
68
- * @param {string} id - The id of the promise handler.
69
- * @param {string} data - The error data to reject the promise handler with.
70
- * @param {boolean} isJSON - Indicates whether the data is JSON or not.
71
- *
72
- * @return {void}
73
- */
74
- function errorHandler(id, data, isJSON) {
75
- const promiseHandler = getAndDeleteResponse(id);
76
- if (promiseHandler) {
77
- if (!isJSON) {
78
- promiseHandler.reject(new Error(data));
79
- } else {
80
- let error;
81
- try {
82
- error = JSON.parse(data);
83
- } catch (err) {
84
- promiseHandler.reject(new TypeError("could not parse error: " + err.message, { cause: err }));
85
- return;
86
- }
87
-
88
- let options = {};
89
- if (error.cause) {
90
- options.cause = error.cause;
91
- }
92
-
93
- let exception;
94
- switch (error.kind) {
95
- case "ReferenceError":
96
- exception = new ReferenceError(error.message, options);
97
- break;
98
- case "TypeError":
99
- exception = new TypeError(error.message, options);
100
- break;
101
- case "RuntimeError":
102
- exception = new RuntimeError(error.message, options);
103
- break;
104
- default:
105
- exception = new Error(error.message, options);
106
- break;
107
- }
108
-
109
- promiseHandler.reject(exception);
110
- }
111
- }
112
- }
113
-
114
- /**
115
- * Retrieves and removes the response associated with the given ID from the callResponses map.
116
- *
117
- * @param {any} id - The ID of the response to be retrieved and removed.
118
- *
119
- * @returns {any} The response object associated with the given ID.
120
- */
121
- function getAndDeleteResponse(id) {
122
- const response = callResponses.get(id);
123
- callResponses.delete(id);
124
- return response;
125
- }
126
-
127
- /**
128
- * Collects all required information for a binding call.
129
- *
130
- * @typedef {Object} CallOptions
131
- * @property {number} [methodID] - The numeric ID of the bound method to call.
132
- * @property {string} [methodName] - The fully qualified name of the bound method to call.
133
- * @property {any[]} args - Arguments to be passed into the bound method.
134
- */
135
-
136
- /**
137
- * Exception class that will be thrown in case the bound method returns an error.
138
- * The value of the {@link RuntimeError#name} property is "RuntimeError".
139
- */
140
- export class RuntimeError extends Error {
141
- /**
142
- * Constructs a new RuntimeError instance.
143
- *
144
- * @param {string} message - The error message.
145
- * @param {any[]} args - Optional arguments for the Error constructor.
146
- */
147
- constructor(message, ...args) {
148
- super(message, ...args);
149
- this.name = "RuntimeError";
150
- }
151
- }
152
-
153
- /**
154
- * Call a bound method according to the given call options.
155
- *
156
- * In case of failure, the returned promise will reject with an exception
157
- * among ReferenceError (unknown method), TypeError (wrong argument count or type),
158
- * {@link RuntimeError} (method returned an error), or other (network or internal errors).
159
- * The exception might have a "cause" field with the value returned
160
- * by the application- or service-level error marshaling functions.
161
- *
162
- * @param {CallOptions} options - A method call descriptor.
163
- * @returns {Promise<any>} - The result of the call.
164
- */
165
- export function Call(options) {
166
- const id = generateID();
167
- const doCancel = () => { return cancelCall(type, {"call-id": id}) };
168
- let queuedCancel = false, callRunning = false;
169
- let p = new Promise((resolve, reject) => {
170
- options["call-id"] = id;
171
- callResponses.set(id, { resolve, reject });
172
- call(CallBinding, options).then((_) => {
173
- callRunning = true;
174
- if (queuedCancel) {
175
- return doCancel();
176
- }
177
- }).catch((error) => {
178
- reject(error);
179
- callResponses.delete(id);
180
- });
181
- });
182
- p.cancel = () => {
183
- if (callRunning) {
184
- return doCancel();
185
- } else {
186
- queuedCancel = true;
187
- }
188
- };
189
-
190
- return p;
191
- }
192
-
193
- /**
194
- * Calls a bound method by name with the specified arguments.
195
- * See {@link Call} for details.
196
- *
197
- * @param {string} methodName - The name of the method in the format 'package.struct.method'.
198
- * @param {any[]} args - The arguments to pass to the method.
199
- * @returns {Promise<any>} The result of the method call.
200
- */
201
- export function ByName(methodName, ...args) {
202
- return Call({
203
- methodName,
204
- args
205
- });
206
- }
207
-
208
- /**
209
- * Calls a method by its numeric ID with the specified arguments.
210
- * See {@link Call} for details.
211
- *
212
- * @param {number} methodID - The ID of the method to call.
213
- * @param {any[]} args - The arguments to pass to the method.
214
- * @return {Promise<any>} - The result of the method call.
215
- */
216
- export function ByID(methodID, ...args) {
217
- return Call({
218
- methodID,
219
- args
220
- });
221
- }
package/src/clipboard.js DELETED
@@ -1,35 +0,0 @@
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,97 +0,0 @@
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
- }
package/src/dialogs.js DELETED
@@ -1,200 +0,0 @@
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
- dialogResponses.delete(id);
139
- if (isJSON) {
140
- p.resolve(JSON.parse(data));
141
- } else {
142
- p.resolve(data);
143
- }
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
- dialogResponses.delete(id);
159
- p.reject(new Error(message));
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/src/drag.js DELETED
@@ -1,119 +0,0 @@
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
- }