@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.
Files changed (59) hide show
  1. package/{application.js → dist/application.js} +32 -46
  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/dist/create.js +94 -0
  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/dist/nanoid.js +38 -0
  17. package/dist/runtime.js +63 -0
  18. package/{screens.js → dist/screens.js} +38 -45
  19. package/dist/system.js +146 -0
  20. package/dist/utils.js +95 -0
  21. package/dist/window.js +570 -0
  22. package/dist/wml.js +179 -0
  23. package/package.json +62 -18
  24. package/types/application.d.ts +12 -0
  25. package/types/browser.d.ts +6 -0
  26. package/types/callable.d.ts +3 -0
  27. package/types/calls.d.ts +63 -0
  28. package/types/cancellable.d.ts +434 -0
  29. package/types/clipboard.d.ts +13 -0
  30. package/types/contextmenu.d.ts +1 -0
  31. package/types/create.d.ts +31 -0
  32. package/types/dialogs.d.ts +140 -0
  33. package/types/drag.d.ts +1 -0
  34. package/types/event_types.d.ts +221 -0
  35. package/types/events.d.ts +67 -0
  36. package/types/flags.d.ts +7 -0
  37. package/types/index.d.ts +16 -0
  38. package/types/listener.d.ts +9 -0
  39. package/types/nanoid.d.ts +1 -0
  40. package/types/runtime.d.ts +22 -0
  41. package/types/screens.d.ts +60 -0
  42. package/types/system.d.ts +92 -0
  43. package/types/utils.d.ts +21 -0
  44. package/types/window.d.ts +306 -0
  45. package/types/wml.d.ts +8 -0
  46. package/browser.js +0 -24
  47. package/calls.js +0 -123
  48. package/clipboard.js +0 -35
  49. package/contextmenu.js +0 -98
  50. package/dialogs.js +0 -138
  51. package/drag.js +0 -125
  52. package/events.js +0 -134
  53. package/flags.js +0 -63
  54. package/index.js +0 -56
  55. package/runtime.js +0 -122
  56. package/system.js +0 -122
  57. package/types.d.ts +0 -135
  58. package/window.js +0 -122
  59. package/wml.js +0 -151
@@ -0,0 +1,30 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { newRuntimeCaller, objectNames } from "./runtime.js";
11
+ const call = newRuntimeCaller(objectNames.Clipboard);
12
+ const ClipboardSetText = 0;
13
+ const ClipboardText = 1;
14
+ /**
15
+ * Sets the text to the Clipboard.
16
+ *
17
+ * @param text - The text to be set to the Clipboard.
18
+ * @return A Promise that resolves when the operation is successful.
19
+ */
20
+ export function SetText(text) {
21
+ return call(ClipboardSetText, { text });
22
+ }
23
+ /**
24
+ * Get the Clipboard text
25
+ *
26
+ * @returns A promise that resolves with the text from the Clipboard.
27
+ */
28
+ export function Text() {
29
+ return call(ClipboardText);
30
+ }
@@ -0,0 +1,80 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { newRuntimeCaller, objectNames } from "./runtime.js";
11
+ import { IsDebug } from "./system.js";
12
+ import { eventTarget } from "./utils.js";
13
+ // setup
14
+ window.addEventListener('contextmenu', contextMenuHandler);
15
+ const call = newRuntimeCaller(objectNames.ContextMenu);
16
+ const ContextMenuOpen = 0;
17
+ function openContextMenu(id, x, y, data) {
18
+ void call(ContextMenuOpen, { id, x, y, data });
19
+ }
20
+ function contextMenuHandler(event) {
21
+ const target = eventTarget(event);
22
+ // Check for custom context menu
23
+ const customContextMenu = window.getComputedStyle(target).getPropertyValue("--custom-contextmenu").trim();
24
+ if (customContextMenu) {
25
+ event.preventDefault();
26
+ const data = window.getComputedStyle(target).getPropertyValue("--custom-contextmenu-data");
27
+ openContextMenu(customContextMenu, event.clientX, event.clientY, data);
28
+ }
29
+ else {
30
+ processDefaultContextMenu(event, target);
31
+ }
32
+ }
33
+ /*
34
+ --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
35
+ --default-contextmenu: show; will always show the default context menu
36
+ --default-contextmenu: hide; will always hide the default context menu
37
+
38
+ This rule is inherited like normal CSS rules, so nesting works as expected
39
+ */
40
+ function processDefaultContextMenu(event, target) {
41
+ // Debug builds always show the menu
42
+ if (IsDebug()) {
43
+ return;
44
+ }
45
+ // Process default context menu
46
+ switch (window.getComputedStyle(target).getPropertyValue("--default-contextmenu").trim()) {
47
+ case 'show':
48
+ return;
49
+ case 'hide':
50
+ event.preventDefault();
51
+ return;
52
+ }
53
+ // Check if contentEditable is true
54
+ if (target.isContentEditable) {
55
+ return;
56
+ }
57
+ // Check if text has been selected
58
+ const selection = window.getSelection();
59
+ const hasSelection = selection && selection.toString().length > 0;
60
+ if (hasSelection) {
61
+ for (let i = 0; i < selection.rangeCount; i++) {
62
+ const range = selection.getRangeAt(i);
63
+ const rects = range.getClientRects();
64
+ for (let j = 0; j < rects.length; j++) {
65
+ const rect = rects[j];
66
+ if (document.elementFromPoint(rect.left, rect.top) === target) {
67
+ return;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ // Check if tag is input or textarea.
73
+ if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
74
+ if (hasSelection || (!target.readOnly && !target.disabled)) {
75
+ return;
76
+ }
77
+ }
78
+ // hide default context menu
79
+ event.preventDefault();
80
+ }
package/dist/create.js ADDED
@@ -0,0 +1,94 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ /**
11
+ * Any is a dummy creation function for simple or unknown types.
12
+ */
13
+ export function Any(source) {
14
+ return source;
15
+ }
16
+ /**
17
+ * ByteSlice is a creation function that replaces
18
+ * null strings with empty strings.
19
+ */
20
+ export function ByteSlice(source) {
21
+ return ((source == null) ? "" : source);
22
+ }
23
+ /**
24
+ * Array takes a creation function for an arbitrary type
25
+ * and returns an in-place creation function for an array
26
+ * whose elements are of that type.
27
+ */
28
+ export function Array(element) {
29
+ if (element === Any) {
30
+ return (source) => (source === null ? [] : source);
31
+ }
32
+ return (source) => {
33
+ if (source === null) {
34
+ return [];
35
+ }
36
+ for (let i = 0; i < source.length; i++) {
37
+ source[i] = element(source[i]);
38
+ }
39
+ return source;
40
+ };
41
+ }
42
+ /**
43
+ * Map takes creation functions for two arbitrary types
44
+ * and returns an in-place creation function for an object
45
+ * whose keys and values are of those types.
46
+ */
47
+ export function Map(key, value) {
48
+ if (value === Any) {
49
+ return (source) => (source === null ? {} : source);
50
+ }
51
+ return (source) => {
52
+ if (source === null) {
53
+ return {};
54
+ }
55
+ for (const key in source) {
56
+ source[key] = value(source[key]);
57
+ }
58
+ return source;
59
+ };
60
+ }
61
+ /**
62
+ * Nullable takes a creation function for an arbitrary type
63
+ * and returns a creation function for a nullable value of that type.
64
+ */
65
+ export function Nullable(element) {
66
+ if (element === Any) {
67
+ return Any;
68
+ }
69
+ return (source) => (source === null ? null : element(source));
70
+ }
71
+ /**
72
+ * Struct takes an object mapping field names to creation functions
73
+ * and returns an in-place creation function for a struct.
74
+ */
75
+ export function Struct(createField) {
76
+ let allAny = true;
77
+ for (const name in createField) {
78
+ if (createField[name] !== Any) {
79
+ allAny = false;
80
+ break;
81
+ }
82
+ }
83
+ if (allAny) {
84
+ return Any;
85
+ }
86
+ return (source) => {
87
+ for (const name in createField) {
88
+ if (name in source) {
89
+ source[name] = createField[name](source[name]);
90
+ }
91
+ }
92
+ return source;
93
+ };
94
+ }
@@ -0,0 +1,134 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { newRuntimeCaller, objectNames } from "./runtime.js";
11
+ import { nanoid } from './nanoid.js';
12
+ // setup
13
+ window._wails = window._wails || {};
14
+ window._wails.dialogErrorCallback = dialogErrorCallback;
15
+ window._wails.dialogResultCallback = dialogResultCallback;
16
+ const call = newRuntimeCaller(objectNames.Dialog);
17
+ const dialogResponses = new Map();
18
+ // Define constants from the `methods` object in Title Case
19
+ const DialogInfo = 0;
20
+ const DialogWarning = 1;
21
+ const DialogError = 2;
22
+ const DialogQuestion = 3;
23
+ const DialogOpenFile = 4;
24
+ const DialogSaveFile = 5;
25
+ /**
26
+ * Handles the result of a dialog request.
27
+ *
28
+ * @param id - The id of the request to handle the result for.
29
+ * @param data - The result data of the request.
30
+ * @param isJSON - Indicates whether the data is JSON or not.
31
+ */
32
+ function dialogResultCallback(id, data, isJSON) {
33
+ let resolvers = getAndDeleteResponse(id);
34
+ if (!resolvers) {
35
+ return;
36
+ }
37
+ if (isJSON) {
38
+ try {
39
+ resolvers.resolve(JSON.parse(data));
40
+ }
41
+ catch (err) {
42
+ resolvers.reject(new TypeError("could not parse result: " + err.message, { cause: err }));
43
+ }
44
+ }
45
+ else {
46
+ resolvers.resolve(data);
47
+ }
48
+ }
49
+ /**
50
+ * Handles the error from a dialog request.
51
+ *
52
+ * @param id - The id of the promise handler.
53
+ * @param message - An error message.
54
+ */
55
+ function dialogErrorCallback(id, message) {
56
+ var _a;
57
+ (_a = getAndDeleteResponse(id)) === null || _a === void 0 ? void 0 : _a.reject(new window.Error(message));
58
+ }
59
+ /**
60
+ * Retrieves and removes the response associated with the given ID from the dialogResponses map.
61
+ *
62
+ * @param id - The ID of the response to be retrieved and removed.
63
+ * @returns The response object associated with the given ID, if any.
64
+ */
65
+ function getAndDeleteResponse(id) {
66
+ const response = dialogResponses.get(id);
67
+ dialogResponses.delete(id);
68
+ return response;
69
+ }
70
+ /**
71
+ * Generates a unique ID using the nanoid library.
72
+ *
73
+ * @returns A unique ID that does not exist in the dialogResponses set.
74
+ */
75
+ function generateID() {
76
+ let result;
77
+ do {
78
+ result = nanoid();
79
+ } while (dialogResponses.has(result));
80
+ return result;
81
+ }
82
+ /**
83
+ * Presents a dialog of specified type with the given options.
84
+ *
85
+ * @param type - Dialog type.
86
+ * @param options - Options for the dialog.
87
+ * @returns A promise that resolves with result of dialog.
88
+ */
89
+ function dialog(type, options = {}) {
90
+ const id = generateID();
91
+ return new Promise((resolve, reject) => {
92
+ dialogResponses.set(id, { resolve, reject });
93
+ call(type, Object.assign({ "dialog-id": id }, options)).catch((err) => {
94
+ dialogResponses.delete(id);
95
+ reject(err);
96
+ });
97
+ });
98
+ }
99
+ /**
100
+ * Presents an info dialog.
101
+ *
102
+ * @param options - Dialog options
103
+ * @returns A promise that resolves with the label of the chosen button.
104
+ */
105
+ export function Info(options) { return dialog(DialogInfo, options); }
106
+ /**
107
+ * Presents a warning dialog.
108
+ *
109
+ * @param options - Dialog options.
110
+ * @returns A promise that resolves with the label of the chosen button.
111
+ */
112
+ export function Warning(options) { return dialog(DialogWarning, options); }
113
+ /**
114
+ * Presents an error dialog.
115
+ *
116
+ * @param options - Dialog options.
117
+ * @returns A promise that resolves with the label of the chosen button.
118
+ */
119
+ export function Error(options) { return dialog(DialogError, options); }
120
+ /**
121
+ * Presents a question dialog.
122
+ *
123
+ * @param options - Dialog options.
124
+ * @returns A promise that resolves with the label of the chosen button.
125
+ */
126
+ export function Question(options) { return dialog(DialogQuestion, options); }
127
+ export function OpenFile(options) { var _a; return (_a = dialog(DialogOpenFile, options)) !== null && _a !== void 0 ? _a : []; }
128
+ /**
129
+ * Presents a file selection dialog to pick a file to save.
130
+ *
131
+ * @param options - Dialog options.
132
+ * @returns Selected file, or a blank string if no file has been selected.
133
+ */
134
+ export function SaveFile(options) { return dialog(DialogSaveFile, options); }
package/dist/drag.js ADDED
@@ -0,0 +1,222 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { invoke, IsWindows } from "./system.js";
11
+ import { GetFlag } from "./flags.js";
12
+ import { canTrackButtons, eventTarget } from "./utils.js";
13
+ // Setup
14
+ let canDrag = false;
15
+ let dragging = false;
16
+ let resizable = false;
17
+ let canResize = false;
18
+ let resizing = false;
19
+ let resizeEdge = "";
20
+ let defaultCursor = "auto";
21
+ let buttons = 0;
22
+ const buttonsTracked = canTrackButtons();
23
+ window._wails = window._wails || {};
24
+ window._wails.setResizable = (value) => {
25
+ resizable = value;
26
+ if (!resizable) {
27
+ // Stop resizing if in progress.
28
+ canResize = resizing = false;
29
+ setResize();
30
+ }
31
+ };
32
+ window.addEventListener('mousedown', update, { capture: true });
33
+ window.addEventListener('mousemove', update, { capture: true });
34
+ window.addEventListener('mouseup', update, { capture: true });
35
+ for (const ev of ['click', 'contextmenu', 'dblclick']) {
36
+ window.addEventListener(ev, suppressEvent, { capture: true });
37
+ }
38
+ function suppressEvent(event) {
39
+ // Suppress click events while resizing or dragging.
40
+ if (dragging || resizing) {
41
+ event.stopImmediatePropagation();
42
+ event.stopPropagation();
43
+ event.preventDefault();
44
+ }
45
+ }
46
+ // Use constants to avoid comparing strings multiple times.
47
+ const MouseDown = 0;
48
+ const MouseUp = 1;
49
+ const MouseMove = 2;
50
+ function update(event) {
51
+ // Windows suppresses mouse events at the end of dragging or resizing,
52
+ // so we need to be smart and synthesize button events.
53
+ let eventType, eventButtons = event.buttons;
54
+ switch (event.type) {
55
+ case 'mousedown':
56
+ eventType = MouseDown;
57
+ if (!buttonsTracked) {
58
+ eventButtons = buttons | (1 << event.button);
59
+ }
60
+ break;
61
+ case 'mouseup':
62
+ eventType = MouseUp;
63
+ if (!buttonsTracked) {
64
+ eventButtons = buttons & ~(1 << event.button);
65
+ }
66
+ break;
67
+ default:
68
+ eventType = MouseMove;
69
+ if (!buttonsTracked) {
70
+ eventButtons = buttons;
71
+ }
72
+ break;
73
+ }
74
+ let released = buttons & ~eventButtons;
75
+ let pressed = eventButtons & ~buttons;
76
+ buttons = eventButtons;
77
+ // Synthesize a release-press sequence if we detect a press of an already pressed button.
78
+ if (eventType === MouseDown && !(pressed & event.button)) {
79
+ released |= (1 << event.button);
80
+ pressed |= (1 << event.button);
81
+ }
82
+ // Suppress all button events during dragging and resizing,
83
+ // unless this is a mouseup event that is ending a drag action.
84
+ if (eventType !== MouseMove // Fast path for mousemove
85
+ && resizing
86
+ || (dragging
87
+ && (eventType === MouseDown
88
+ || event.button !== 0))) {
89
+ event.stopImmediatePropagation();
90
+ event.stopPropagation();
91
+ event.preventDefault();
92
+ }
93
+ // Handle releases
94
+ if (released & 1) {
95
+ primaryUp(event);
96
+ }
97
+ // Handle presses
98
+ if (pressed & 1) {
99
+ primaryDown(event);
100
+ }
101
+ // Handle mousemove
102
+ if (eventType === MouseMove) {
103
+ onMouseMove(event);
104
+ }
105
+ ;
106
+ }
107
+ function primaryDown(event) {
108
+ // Reset readiness state.
109
+ canDrag = false;
110
+ canResize = false;
111
+ // Ignore repeated clicks on macOS and Linux.
112
+ if (!IsWindows()) {
113
+ if (event.type === 'mousedown' && event.button === 0 && event.detail !== 1) {
114
+ return;
115
+ }
116
+ }
117
+ if (resizeEdge) {
118
+ // Ready to resize if the primary button was pressed for the first time.
119
+ canResize = true;
120
+ // Do not start drag operations when on resize edges.
121
+ return;
122
+ }
123
+ // Retrieve target element
124
+ const target = eventTarget(event);
125
+ // Ready to drag if the primary button was pressed for the first time on a draggable element.
126
+ // Ignore clicks on the scrollbar.
127
+ const style = window.getComputedStyle(target);
128
+ canDrag = (style.getPropertyValue("--wails-draggable").trim() === "drag"
129
+ && (event.offsetX - parseFloat(style.paddingLeft) < target.clientWidth
130
+ && event.offsetY - parseFloat(style.paddingTop) < target.clientHeight));
131
+ }
132
+ function primaryUp(event) {
133
+ // Stop dragging and resizing.
134
+ canDrag = false;
135
+ dragging = false;
136
+ canResize = false;
137
+ resizing = false;
138
+ }
139
+ const cursorForEdge = Object.freeze({
140
+ "se-resize": "nwse-resize",
141
+ "sw-resize": "nesw-resize",
142
+ "nw-resize": "nwse-resize",
143
+ "ne-resize": "nesw-resize",
144
+ "w-resize": "ew-resize",
145
+ "n-resize": "ns-resize",
146
+ "s-resize": "ns-resize",
147
+ "e-resize": "ew-resize",
148
+ });
149
+ function setResize(edge) {
150
+ if (edge) {
151
+ if (!resizeEdge) {
152
+ defaultCursor = document.body.style.cursor;
153
+ }
154
+ document.body.style.cursor = cursorForEdge[edge];
155
+ }
156
+ else if (!edge && resizeEdge) {
157
+ document.body.style.cursor = defaultCursor;
158
+ }
159
+ resizeEdge = edge || "";
160
+ }
161
+ function onMouseMove(event) {
162
+ if (canResize && resizeEdge) {
163
+ // Start resizing.
164
+ resizing = true;
165
+ invoke("wails:resize:" + resizeEdge);
166
+ }
167
+ else if (canDrag) {
168
+ // Start dragging.
169
+ dragging = true;
170
+ invoke("wails:drag");
171
+ }
172
+ if (dragging || resizing) {
173
+ // Either drag or resize is ongoing,
174
+ // reset readiness and stop processing.
175
+ canDrag = canResize = false;
176
+ return;
177
+ }
178
+ if (!resizable || !IsWindows()) {
179
+ if (resizeEdge) {
180
+ setResize();
181
+ }
182
+ return;
183
+ }
184
+ const resizeHandleHeight = GetFlag("system.resizeHandleHeight") || 5;
185
+ const resizeHandleWidth = GetFlag("system.resizeHandleWidth") || 5;
186
+ // Extra pixels for the corner areas.
187
+ const cornerExtra = GetFlag("resizeCornerExtra") || 10;
188
+ const rightBorder = (window.outerWidth - event.clientX) < resizeHandleWidth;
189
+ const leftBorder = event.clientX < resizeHandleWidth;
190
+ const topBorder = event.clientY < resizeHandleHeight;
191
+ const bottomBorder = (window.outerHeight - event.clientY) < resizeHandleHeight;
192
+ // Adjust for corner areas.
193
+ const rightCorner = (window.outerWidth - event.clientX) < (resizeHandleWidth + cornerExtra);
194
+ const leftCorner = event.clientX < (resizeHandleWidth + cornerExtra);
195
+ const topCorner = event.clientY < (resizeHandleHeight + cornerExtra);
196
+ const bottomCorner = (window.outerHeight - event.clientY) < (resizeHandleHeight + cornerExtra);
197
+ if (!leftCorner && !topCorner && !bottomCorner && !rightCorner) {
198
+ // Optimisation: out of all corner areas implies out of borders.
199
+ setResize();
200
+ }
201
+ // Detect corners.
202
+ else if (rightCorner && bottomCorner)
203
+ setResize("se-resize");
204
+ else if (leftCorner && bottomCorner)
205
+ setResize("sw-resize");
206
+ else if (leftCorner && topCorner)
207
+ setResize("nw-resize");
208
+ else if (topCorner && rightCorner)
209
+ setResize("ne-resize");
210
+ // Detect borders.
211
+ else if (leftBorder)
212
+ setResize("w-resize");
213
+ else if (topBorder)
214
+ setResize("n-resize");
215
+ else if (bottomBorder)
216
+ setResize("s-resize");
217
+ else if (rightBorder)
218
+ setResize("e-resize");
219
+ // Out of border area.
220
+ else
221
+ setResize();
222
+ }