bm-core-ui 2.9.3 → 2.10.0
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/build/@types/index.d.ts +353 -61
- package/build/BMCollectionView/BMCollectionView.js +77 -39
- package/build/BMCollectionView/BMCollectionViewFlowLayout.js +18 -5
- package/build/BMCoreUI.css +45 -18
- package/build/BMView/BMMenu.js +134 -7
- package/build/BMView/BMView_v2.5.js +62 -3
- package/build/BMWindow/BMConfirmationPopup.js +1 -1
- package/build/BMWindow/BMKeyboardShortcut.js +338 -88
- package/build/BMWindow/BMPopover/BMPopover.js +53 -12
- package/build/BMWindow/BMWindow.js +32 -6
- package/build/Core/BMCoreUI.js +20 -8
- package/build/Core/BMRect.js +1 -1
- package/build/images/AlignBottom.png +0 -0
- package/build/images/AlignCenterX.png +0 -0
- package/build/images/AlignCenterY.png +0 -0
- package/build/images/AlignLeading.png +0 -0
- package/build/images/AlignTop.png +0 -0
- package/build/images/AlignTrailing.png +0 -0
- package/build/images/AllConstraints.png +0 -0
- package/build/images/BottomConstraint.png +0 -0
- package/build/images/CenterXConstraint.png +0 -0
- package/build/images/CenterYConstraint.png +0 -0
- package/build/images/CoreUI2.png +0 -0
- package/build/images/CoreUI2@2x.png +0 -0
- package/build/images/Desktop.png +0 -0
- package/build/images/DesktopMini.png +0 -0
- package/build/images/EqualHeight.png +0 -0
- package/build/images/EqualHorizontalSpacing.png +0 -0
- package/build/images/EqualHorizontalSpacingInSuperview.png +0 -0
- package/build/images/EqualVerticalSpacing.png +0 -0
- package/build/images/EqualVerticalSpacingInSuperview.png +0 -0
- package/build/images/EqualWidth.png +0 -0
- package/build/images/HeightConstraint.png +0 -0
- package/build/images/InactiveConstraints.png +0 -0
- package/build/images/Layout.png +0 -0
- package/build/images/LayoutVariables.png +0 -0
- package/build/images/LeftConstraint.png +0 -0
- package/build/images/OwnConstraints.png +0 -0
- package/build/images/Phone.png +0 -0
- package/build/images/PhoneLandscape.png +0 -0
- package/build/images/PhoneLandscapeMini.png +0 -0
- package/build/images/PhoneMini.png +0 -0
- package/build/images/PhonePortrait.png +0 -0
- package/build/images/PhonePortraitMini.png +0 -0
- package/build/images/Properties.png +0 -0
- package/build/images/RightConstraint.png +0 -0
- package/build/images/SubviewConstraints.png +0 -0
- package/build/images/Tablet.png +0 -0
- package/build/images/TabletLandscape.png +0 -0
- package/build/images/TabletLandscapeMini.png +0 -0
- package/build/images/TabletMini.png +0 -0
- package/build/images/TabletPortrait.png +0 -0
- package/build/images/TabletPortraitMini.png +0 -0
- package/build/images/TopConstraint.png +0 -0
- package/build/images/WidthConstraint.png +0 -0
- package/build/index.js +2 -0
- package/lib/@types/BMCoreUI.min.d.ts +353 -61
- package/lib/BMCoreUI.min.js +3 -1
- package/package.json +9 -10
|
@@ -65,7 +65,7 @@ BMViewConstraintAttribute.prototype = {
|
|
|
65
65
|
* }
|
|
66
66
|
* @return <BMLayoutConstraint> A layout constraint.
|
|
67
67
|
*/
|
|
68
|
-
// equalTo(constant, {priority}) {
|
|
68
|
+
// equalTo: function (constant, {priority}) {
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Constructs and returns a layout constraint that links this view constraint attribute to the given attribute.
|
|
@@ -107,7 +107,7 @@ BMViewConstraintAttribute.prototype = {
|
|
|
107
107
|
* }
|
|
108
108
|
* @return <BMLayoutConstraint> A layout constraint.
|
|
109
109
|
*/
|
|
110
|
-
// lessThanOrEqualTo(constant, {priority}) {
|
|
110
|
+
// lessThanOrEqualTo: function (constant, {priority}) {
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* Constructs and returns a layout constraint that links this view constraint attribute to the given attribute.
|
|
@@ -149,7 +149,7 @@ BMViewConstraintAttribute.prototype = {
|
|
|
149
149
|
* }
|
|
150
150
|
* @return <BMLayoutConstraint> A layout constraint.
|
|
151
151
|
*/
|
|
152
|
-
// greaterThanOrEqualTo(constant, {priority}) {
|
|
152
|
+
// greaterThanOrEqualTo: function (constant, {priority}) {
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
155
|
* Constructs and returns a layout constraint that links this view constraint attribute to the given attribute.
|
|
@@ -261,6 +261,32 @@ BMViewLayoutQueue.layoutQueue = function () {
|
|
|
261
261
|
|
|
262
262
|
// @endtype
|
|
263
263
|
|
|
264
|
+
// @type BMViewColorScheme
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Constants that describe the color scheme that a view should use when drawing itself.
|
|
268
|
+
*/
|
|
269
|
+
export var BMViewColorScheme = Object.freeze({ // <enum>
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Indicates that the view's color scheme should be based on the system color scheme.
|
|
273
|
+
*/
|
|
274
|
+
Auto: 'auto', // <enum>
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Indicates that the view should always use a dark color scheme regardless of the system color scheme setting.
|
|
278
|
+
*/
|
|
279
|
+
Dark: 'dark', // <enum>
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Indicates that the view should always use a light color scheme regardless of the system color scheme setting.
|
|
283
|
+
*/
|
|
284
|
+
Light: 'light', // <enum>
|
|
285
|
+
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// @endtype
|
|
289
|
+
|
|
264
290
|
// @type BMView
|
|
265
291
|
|
|
266
292
|
const BMViewDebug = NO;
|
|
@@ -1784,6 +1810,39 @@ BMView.prototype = BMExtend(BMView.prototype, {
|
|
|
1784
1810
|
|
|
1785
1811
|
// #endregion
|
|
1786
1812
|
|
|
1813
|
+
// #region Color Scheme
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
* The color scheme that this view should use.
|
|
1817
|
+
*/
|
|
1818
|
+
_colorScheme: BMViewColorScheme.Auto, // <BMViewColorScheme>
|
|
1819
|
+
|
|
1820
|
+
get colorScheme() {
|
|
1821
|
+
return this._colorScheme;
|
|
1822
|
+
},
|
|
1823
|
+
|
|
1824
|
+
set colorScheme(scheme) {
|
|
1825
|
+
const oldColorScheme = this._colorScheme;
|
|
1826
|
+
this._colorScheme = scheme;
|
|
1827
|
+
|
|
1828
|
+
this.colorSchemeDidChange(oldColorScheme);
|
|
1829
|
+
},
|
|
1830
|
+
|
|
1831
|
+
/**
|
|
1832
|
+
* @protected
|
|
1833
|
+
* Invoked by CoreUI whenever the color scheme that the view should use changes.
|
|
1834
|
+
*
|
|
1835
|
+
* Subclasses may use this method to perform any changes needed to support the requested color scheme.
|
|
1836
|
+
* Subclasses that override this method must invoke the superclass method at some point in their implementation.
|
|
1837
|
+
*
|
|
1838
|
+
* @param scheme <BMViewColorScheme> The previous color scheme.
|
|
1839
|
+
*/
|
|
1840
|
+
colorSchemeDidChange(scheme) {
|
|
1841
|
+
|
|
1842
|
+
},
|
|
1843
|
+
|
|
1844
|
+
// #endregion
|
|
1845
|
+
|
|
1787
1846
|
// #region Intrinsic Size
|
|
1788
1847
|
|
|
1789
1848
|
/**
|
|
@@ -353,7 +353,7 @@ BMAlertPopup.alertPopupWithTitle = function (title, {text, actionText = 'OK'}) {
|
|
|
353
353
|
* You can display your confirmation popup using the usual `bringToFrontAnimated(_)` method, but for convenience you can also
|
|
354
354
|
* use the `confirm()` method that returns a promise which resolves when the user takes a decision.
|
|
355
355
|
*/
|
|
356
|
-
function BMConfirmationPopup() {} // <constructor>
|
|
356
|
+
export function BMConfirmationPopup() {} // <constructor>
|
|
357
357
|
|
|
358
358
|
BMConfirmationPopup.prototype = BMExtend(Object.create(BMAlertPopup.prototype), {
|
|
359
359
|
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import { NO } from "../Core/BMCoreUI";
|
|
3
|
+
import { BMHTMLEntity, NO } from "../Core/BMCoreUI";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A dictionary that contains the mapping between key codes and the character
|
|
7
|
+
* symbols that represent them.
|
|
8
|
+
*/
|
|
9
|
+
const _BMKeyboardShortcutCharacterMap = {
|
|
10
|
+
Backquote: '`',
|
|
11
|
+
Minus: '-',
|
|
12
|
+
Equal: '=',
|
|
13
|
+
BracketLeft: '[',
|
|
14
|
+
BracketRight: ']',
|
|
15
|
+
Backslash: '\\',
|
|
16
|
+
Semicolon: ';',
|
|
17
|
+
Quote: '\'',
|
|
18
|
+
Comma: ',',
|
|
19
|
+
Period: '.',
|
|
20
|
+
Slash: '/',
|
|
21
|
+
Enter: BMHTMLEntity.Return,
|
|
22
|
+
Escape: BMHTMLEntity.Escape,
|
|
23
|
+
Backspace: BMHTMLEntity.Delete,
|
|
24
|
+
};
|
|
4
25
|
|
|
5
26
|
// @type BMKeyboardShortcutModifier
|
|
6
27
|
|
|
@@ -10,44 +31,44 @@ import { NO } from "../Core/BMCoreUI";
|
|
|
10
31
|
*/
|
|
11
32
|
export const BMKeyboardShortcutModifier = Object.freeze({ // <enum>
|
|
12
33
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Represents the command key on macOS and iOS, windows key on Windows and meta key on Linux.
|
|
36
|
+
*/
|
|
37
|
+
Command: {key: 'metaKey', value: 1}, // <enum>
|
|
17
38
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Represents the option key on macOS and alt on other systems.
|
|
41
|
+
*/
|
|
42
|
+
Option: {key: 'altKey', value: 2}, // <enum>
|
|
22
43
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Represents the shit key.
|
|
46
|
+
*/
|
|
47
|
+
Shift: {key: 'shiftKey', value: 4}, // <enum>
|
|
27
48
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Represents the control key.
|
|
51
|
+
*/
|
|
52
|
+
Control: {key: 'ctrlKey', value: 8}, // <enum>
|
|
32
53
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Represents the command key on macOS and iOS and control key on other systems.
|
|
56
|
+
*/
|
|
57
|
+
System: {key: 'systemKey', value: (navigator.platform.startsWith('Mac') || /iPhone|iPad|iPod/.test(navigator.platform)) ? 1 : 8}, // <enum>
|
|
37
58
|
|
|
38
59
|
});
|
|
39
60
|
|
|
40
61
|
// @endtype
|
|
41
62
|
|
|
42
|
-
// @type
|
|
63
|
+
// @type BMKeySequence
|
|
43
64
|
|
|
44
65
|
/**
|
|
45
|
-
* A
|
|
46
|
-
*
|
|
66
|
+
* A class whose instances describe sequences of keys on a keyboard that must be
|
|
67
|
+
* pressed for an action to take place.
|
|
47
68
|
*/
|
|
48
|
-
export function
|
|
69
|
+
export function BMKeySequence() {} // <constructor>
|
|
49
70
|
|
|
50
|
-
|
|
71
|
+
BMKeySequence.prototype = {
|
|
51
72
|
|
|
52
73
|
/**
|
|
53
74
|
* The key that should be pressed for this keyboard shortcut.
|
|
@@ -58,7 +79,7 @@ BMKeyboardShortcut.prototype = {
|
|
|
58
79
|
},
|
|
59
80
|
|
|
60
81
|
/**
|
|
61
|
-
* An
|
|
82
|
+
* An array of keyboard modifiers that must be pressed
|
|
62
83
|
* together with the key in order to trigger the shortcut.
|
|
63
84
|
*/
|
|
64
85
|
_modifiers: undefined, // <[BMKeyboardShortcutModifier]>
|
|
@@ -66,6 +87,196 @@ BMKeyboardShortcut.prototype = {
|
|
|
66
87
|
if (this._modifiers) return this._modifiers.slice();
|
|
67
88
|
},
|
|
68
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Designated initializer. Initializes this key sequence with the specified key and optional modifiers.
|
|
92
|
+
* @param key <String> The key that should be pressed for this key sequence.
|
|
93
|
+
* This maps to the `code` property of keyboard events.
|
|
94
|
+
* {
|
|
95
|
+
* @param modifiers <[BMKeyboardShortcutModifier], nullable> Defaults to an empty array. An optional array of modifiers
|
|
96
|
+
* that must be pressed together with the target key.
|
|
97
|
+
* }
|
|
98
|
+
* @return <BMKeySequence> This key sequence.
|
|
99
|
+
*/
|
|
100
|
+
initWithKeyCode(key, {modifiers} = {modifiers: []}) {
|
|
101
|
+
this._key = key;
|
|
102
|
+
this._modifiers = modifiers?.slice() ?? [];
|
|
103
|
+
|
|
104
|
+
for (const modifier of this._modifiers) {
|
|
105
|
+
this._modifierBitmap = this._modifierBitmap | modifier.value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return this;
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Initializes this key sequence with the specified keyboard event, using the event's key code
|
|
113
|
+
* and any active modifier keys. If the event includes the control or command keys, these may be converted
|
|
114
|
+
* into a system key modifier based on the current platform.
|
|
115
|
+
* @param event <KeyboardEvent> The keyboard event from which this key sequence should be initialized.
|
|
116
|
+
* @return <BMKeySequence> This key sequence.
|
|
117
|
+
*/
|
|
118
|
+
initWithKeyboardEvent(event) {
|
|
119
|
+
const modifiers = [];
|
|
120
|
+
if (event.shiftKey) {
|
|
121
|
+
modifiers.push(BMKeyboardShortcutModifier.Shift);
|
|
122
|
+
}
|
|
123
|
+
if (event.altKey) {
|
|
124
|
+
modifiers.push(BMKeyboardShortcutModifier.Option);
|
|
125
|
+
}
|
|
126
|
+
if (event.metaKey) {
|
|
127
|
+
if (BMKeyboardShortcutModifier.System.value == BMKeyboardShortcutModifier.Command.value) {
|
|
128
|
+
modifiers.push(BMKeyboardShortcutModifier.System);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
modifiers.push(BMKeyboardShortcutModifier.Command);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (event.ctrlKey) {
|
|
135
|
+
if (BMKeyboardShortcutModifier.System.value == BMKeyboardShortcutModifier.Control.value) {
|
|
136
|
+
modifiers.push(BMKeyboardShortcutModifier.System);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
modifiers.push(BMKeyboardShortcutModifier.Control);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return this.initWithKeyCode(event.code, {modifiers});
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A string description of this key sequence, intended to be displayed to end-users.
|
|
148
|
+
* Its format depends on the current platform.
|
|
149
|
+
*/
|
|
150
|
+
get HTMLDescription() { // <String>
|
|
151
|
+
let representation = '';
|
|
152
|
+
const code = this.keyCode || '';
|
|
153
|
+
|
|
154
|
+
if (code.startsWith('Key')) {
|
|
155
|
+
// Alphanumeric keys can be extracted from the key code
|
|
156
|
+
representation = code.substring(3);
|
|
157
|
+
}
|
|
158
|
+
else if (code.startsWith('Digit')) {
|
|
159
|
+
// Digit keys can also be extracted from the key code
|
|
160
|
+
representation = code.substring(5);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Otherwise use the character code map, defaulting to showing the code otherwise
|
|
164
|
+
representation = _BMKeyboardShortcutCharacterMap[code] || code;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const isAppleSystem = (navigator.platform.startsWith('Mac') || /iPhone|iPad|iPod/.test(navigator.platform));
|
|
168
|
+
|
|
169
|
+
// Add the modifier keys
|
|
170
|
+
if (this.modifiers.includes(BMKeyboardShortcutModifier.System)) {
|
|
171
|
+
if (isAppleSystem) {
|
|
172
|
+
representation = BMHTMLEntity.Command + representation;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
representation = 'Ctrl + ' + representation;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (this.modifiers.includes(BMKeyboardShortcutModifier.Command)) {
|
|
180
|
+
if (isAppleSystem) {
|
|
181
|
+
representation = BMHTMLEntity.Command + representation;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
representation = 'Win + ' + representation;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (this.modifiers.includes(BMKeyboardShortcutModifier.Shift)) {
|
|
189
|
+
if (isAppleSystem) {
|
|
190
|
+
representation = BMHTMLEntity.Shift + representation;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
representation = 'Shift + ' + representation;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (this.modifiers.includes(BMKeyboardShortcutModifier.Option)) {
|
|
198
|
+
if (isAppleSystem) {
|
|
199
|
+
representation = BMHTMLEntity.Option + representation;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
representation = 'Alt + ' + representation;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (this.modifiers.includes(BMKeyboardShortcutModifier.Control)) {
|
|
207
|
+
if (isAppleSystem) {
|
|
208
|
+
representation = BMHTMLEntity.Control + representation;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
representation = 'Ctrl + ' + representation;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return representation;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Creates and returns a key sequence initialized with the specified key and optional modifiers.
|
|
221
|
+
* @param key <String> The key that should be pressed for this key sequence.
|
|
222
|
+
* This maps to the `code` property of keyboard events.
|
|
223
|
+
* {
|
|
224
|
+
* @param modifiers <[BMKeyboardShortcutModifier], nullable> Defaults to an empty array. An optional array of modifiers
|
|
225
|
+
* that must be pressed together with the target key.
|
|
226
|
+
* }
|
|
227
|
+
* @return <BMKeySequence> This key sequence.
|
|
228
|
+
*/
|
|
229
|
+
BMKeySequence.keySequenceWithKeyCode = function (key, args) {
|
|
230
|
+
return new this().initWithKeyCode(key, args);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Creates and returns a key sequence initialized with the specified keyboard event, using the event's key code
|
|
235
|
+
* and any active modifier keys. If the event includes the control or command keys, these may be converted
|
|
236
|
+
* into a system key modifier based on the current platform.
|
|
237
|
+
* @param event <KeyboardEvent> The keyboard event from which this key sequence should be initialized.
|
|
238
|
+
* @return <BMKeySequence> This key sequence.
|
|
239
|
+
*/
|
|
240
|
+
BMKeySequence.keySequenceWithKeyboardEvent = function (event) {
|
|
241
|
+
return new this().initWithKeyboardEvent(event);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// @endtype
|
|
245
|
+
|
|
246
|
+
// @type BMKeyboardShortcut
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* A keyboard shortcut object describes the keys that must be pressed for a keyboard shortcut to trigger as
|
|
250
|
+
* well as what should happen when that shortcut is triggered.
|
|
251
|
+
*/
|
|
252
|
+
export function BMKeyboardShortcut() {} // <constructor>
|
|
253
|
+
|
|
254
|
+
BMKeyboardShortcut.prototype = {
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The key sequence that should be pressed to trigger this keyboard shortcut.
|
|
258
|
+
*/
|
|
259
|
+
_keySequence: undefined, // <BMKeySequence>
|
|
260
|
+
get keySequence() {
|
|
261
|
+
return this._keySequence;
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The key that should be pressed for this keyboard shortcut.
|
|
266
|
+
*/
|
|
267
|
+
get keyCode() { // <String>
|
|
268
|
+
return this._keySequence._key;
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* An array of keyboard modifiers that must be pressed
|
|
273
|
+
* together with the key in order to trigger the shortcut.
|
|
274
|
+
*/
|
|
275
|
+
get modifiers() { // <[BMKeyboardShortcutModifier]>
|
|
276
|
+
if (this._keySequence._modifiers) return this._keySequence._modifiers.slice();
|
|
277
|
+
return [];
|
|
278
|
+
},
|
|
279
|
+
|
|
69
280
|
/**
|
|
70
281
|
* A bitmap describing the modifiers that should be active.
|
|
71
282
|
*/
|
|
@@ -101,7 +312,38 @@ BMKeyboardShortcut.prototype = {
|
|
|
101
312
|
preventsDefault: NO, // <Boolean>
|
|
102
313
|
|
|
103
314
|
/**
|
|
104
|
-
* Designated
|
|
315
|
+
* Designated Initializer. Initializes this keyboard shortcut with the specified key sequence and the action that the
|
|
316
|
+
* keyboard shortcut should trigger.
|
|
317
|
+
* @param keySequence <BMKeySequence> The key sequence describing the keyboard buttons that
|
|
318
|
+
* should be pressed to trigger this keyboard shortcut.
|
|
319
|
+
* {
|
|
320
|
+
* @param target <AnyObject> The object that will handle this keyboard shortcut action.
|
|
321
|
+
* @param action <String> The name of a method on the target object that will be invoked when this
|
|
322
|
+
* keyboard shortcut is triggered. That method will receive the following arguments:
|
|
323
|
+
*
|
|
324
|
+
* - `event`: {@link KeyboardEvent} The keyboard event that triggered the keyboard shortcut
|
|
325
|
+
* - `{forKeyboardShortcut}`: {@link BMKeyboardShortcut} The associated keyboard shortcut
|
|
326
|
+
* @param preventsDefault <Boolean, nullable> Defaults to `NO`. When set to `YES`, the default action of the event that triggers
|
|
327
|
+
* normally as a result of the key sequence will be prevented.
|
|
328
|
+
* }
|
|
329
|
+
* @return <BMKeyboardShortcut> This keyboard shortcut.
|
|
330
|
+
*/
|
|
331
|
+
initWithKeySequence(keySequence, {target, action, preventsDefault} = {}) {
|
|
332
|
+
this._keySequence = keySequence;
|
|
333
|
+
|
|
334
|
+
this._target = target;
|
|
335
|
+
this._action = action;
|
|
336
|
+
this.preventsDefault = preventsDefault || NO;
|
|
337
|
+
|
|
338
|
+
for (const modifier of this.modifiers) {
|
|
339
|
+
this._modifierBitmap = this._modifierBitmap | modifier.value;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return this;
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Initializes this keyboard shortcut with the given key and optional modifiers, as well as
|
|
105
347
|
* the target and action that will handle it.
|
|
106
348
|
*
|
|
107
349
|
* In order to be triggered, this keyboard shortcut must be registered with an event handler such as a window
|
|
@@ -110,65 +352,44 @@ BMKeyboardShortcut.prototype = {
|
|
|
110
352
|
* {
|
|
111
353
|
* @param modifiers <[BMKeyboardShortcutModifier], nullable> Defaults to an empty array. An optional array of keyboard modifiers that must be active.
|
|
112
354
|
* for the keyboard shortcut to fire.
|
|
113
|
-
* @param target <AnyObject>
|
|
114
|
-
* @param action <String>
|
|
115
|
-
*
|
|
116
|
-
*
|
|
355
|
+
* @param target <AnyObject> The object that will handle this keyboard shortcut action.
|
|
356
|
+
* @param action <String> The name of a method on the target object that will be invoked when this
|
|
357
|
+
* keyboard shortcut is triggered. That method will receive the following arguments:
|
|
358
|
+
*
|
|
359
|
+
* - `event`: {@link KeyboardEvent} The keyboard event that triggered the keyboard shortcut
|
|
360
|
+
* - `{forKeyboardShortcut}`: {@link BMKeyboardShortcut} The associated keyboard shortcut
|
|
361
|
+
* @param preventsDefault <Boolean, nullable> Defaults to `NO`. When set to `YES`, the default action of the event that triggers
|
|
362
|
+
* normally as a result of the key sequence will be prevented.
|
|
117
363
|
* }
|
|
118
364
|
* @return <BMKeyboardShortcut> This keyboard shortcut.
|
|
119
365
|
*/
|
|
120
366
|
initWithKeyCode(key, {modifiers, target, action, preventsDefault} = {modifiers: []}) {
|
|
121
|
-
|
|
122
|
-
this.
|
|
123
|
-
this._target = target;
|
|
124
|
-
this._action = action;
|
|
125
|
-
this.preventsDefault = preventsDefault || NO;
|
|
367
|
+
const keySequence = new BMKeySequence().initWithKeyCode(key, {modifiers});
|
|
368
|
+
this._keySequence = keySequence;
|
|
126
369
|
|
|
127
|
-
|
|
128
|
-
this._modifierBitmap = this._modifierBitmap | modifier.value;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return this;
|
|
370
|
+
return this.initWithKeySequence(keySequence, {target, action, preventsDefault});
|
|
132
371
|
},
|
|
133
372
|
|
|
134
373
|
/**
|
|
135
374
|
* Initializes this keyboard shortcut with the given keyboard event. If the event includes the control or command keys, these may be converted
|
|
136
375
|
* into a system key modifier based on the current platform.
|
|
137
|
-
* @param event <KeyboardEvent>
|
|
376
|
+
* @param event <KeyboardEvent> The keyboard event from which this keyboard shortcut should be initialized.
|
|
138
377
|
* {
|
|
139
|
-
* @param target <AnyObject>
|
|
140
|
-
* @param action <String>
|
|
141
|
-
*
|
|
142
|
-
* @param preventsDefault <Boolean, nullable> Defaults to `NO`. When set to `YES`, the default action of the event that triggers this keyboard shortcut will be prevented.
|
|
143
|
-
* }
|
|
378
|
+
* @param target <AnyObject> The object that will handle this keyboard shortcut action.
|
|
379
|
+
* @param action <String> The name of a method on the target object that will be invoked when this
|
|
380
|
+
* keyboard shortcut is triggered. That method will receive the following arguments:
|
|
144
381
|
*
|
|
382
|
+
* - `event`: {@link KeyboardEvent} The keyboard event that triggered the keyboard shortcut
|
|
383
|
+
* - `{forKeyboardShortcut}`: {@link BMKeyboardShortcut} The associated keyboard shortcut
|
|
384
|
+
* @param preventsDefault <Boolean, nullable> Defaults to `NO`. When set to `YES`, the default action of the event that triggers
|
|
385
|
+
* normally as a result of the key sequence will be prevented.
|
|
386
|
+
* }
|
|
387
|
+
* @return <BMKeyboardShortcut> This keyboard shortcut.
|
|
145
388
|
*/
|
|
146
389
|
initWithKeyboardEvent(event, {target, action, preventsDefault} = {}) {
|
|
147
|
-
const
|
|
148
|
-
if (event.shiftKey) {
|
|
149
|
-
modifiers.push(BMKeyboardShortcutModifier.Shift);
|
|
150
|
-
}
|
|
151
|
-
if (event.altKey) {
|
|
152
|
-
modifiers.push(BMKeyboardShortcutModifier.Option);
|
|
153
|
-
}
|
|
154
|
-
if (event.metaKey) {
|
|
155
|
-
if (BMKeyboardShortcutModifier.System.value == BMKeyboardShortcutModifier.Command.value) {
|
|
156
|
-
modifiers.push(BMKeyboardShortcutModifier.System);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
modifiers.push(BMKeyboardShortcutModifier.Command);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (event.ctrlKey) {
|
|
163
|
-
if (BMKeyboardShortcutModifier.System.value == BMKeyboardShortcutModifier.Control.value) {
|
|
164
|
-
modifiers.push(BMKeyboardShortcutModifier.System);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
modifiers.push(BMKeyboardShortcutModifier.Control);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
390
|
+
const keySequence = new BMKeySequence().initWithKeyboardEvent(event);
|
|
170
391
|
|
|
171
|
-
return this.
|
|
392
|
+
return this.initWithKeySequence(keySequence, {target, action, preventsDefault});
|
|
172
393
|
},
|
|
173
394
|
|
|
174
395
|
/**
|
|
@@ -179,7 +400,7 @@ BMKeyboardShortcut.prototype = {
|
|
|
179
400
|
* @param targetID <Object ^(String)> A callback that is invoked with the target ID and should return
|
|
180
401
|
* the target object which will handle the keyboard shortcut.
|
|
181
402
|
* }
|
|
182
|
-
* @returns <
|
|
403
|
+
* @returns <BMKeyboardShortcut> This keyboard shortcut.
|
|
183
404
|
*/
|
|
184
405
|
initWithSerializedKeyboardShortcut(shortcut, {targetID: resolver}) {
|
|
185
406
|
if (shortcut._class != 'BMKeyboardShortcut') {
|
|
@@ -188,8 +409,9 @@ BMKeyboardShortcut.prototype = {
|
|
|
188
409
|
|
|
189
410
|
const target = resolver(shortcut._targetID);
|
|
190
411
|
|
|
412
|
+
const modifierValues = Object.values(BMKeyboardShortcutModifier);
|
|
191
413
|
const modifiers = shortcut._modifiers.map(modifier => {
|
|
192
|
-
return
|
|
414
|
+
return modifierValues.find(m => m.key == modifier)
|
|
193
415
|
});
|
|
194
416
|
|
|
195
417
|
return this.initWithKeyCode(shortcut._key, {modifiers, target, action: shortcut._action, preventsDefault: shortcut._preventsDefault});
|
|
@@ -205,8 +427,8 @@ BMKeyboardShortcut.prototype = {
|
|
|
205
427
|
serializedKeyboardShortcutWithTargetID(ID) {
|
|
206
428
|
return {
|
|
207
429
|
_class: `BMKeyboardShortcut`,
|
|
208
|
-
_key: this.
|
|
209
|
-
_modifiers: this.
|
|
430
|
+
_key: this.keyCode,
|
|
431
|
+
_modifiers: this.modifiers.map(m => m.key),
|
|
210
432
|
_targetID: ID,
|
|
211
433
|
_action: this._action,
|
|
212
434
|
_preventsDefault: this.preventsDefault,
|
|
@@ -215,6 +437,27 @@ BMKeyboardShortcut.prototype = {
|
|
|
215
437
|
|
|
216
438
|
};
|
|
217
439
|
|
|
440
|
+
/**
|
|
441
|
+
* Constructs and returns a keyboard shortcut with the specified key sequence and action that will be triggered
|
|
442
|
+
* by the keyboard shortcut.
|
|
443
|
+
* @param keySequence <BMKeySequence> The key sequence describing the keys that should be pressed to
|
|
444
|
+
* trigger this shortcut.s
|
|
445
|
+
* {
|
|
446
|
+
* @param target <AnyObject> The object that will handle this keyboard shortcut action.
|
|
447
|
+
* @param action <String> The name of a method on the target object that will be invoked when this
|
|
448
|
+
* keyboard shortcut is triggered. That method will receive the following arguments:
|
|
449
|
+
*
|
|
450
|
+
* - `event`: {@link KeyboardEvent} The keyboard event that triggered the keyboard shortcut
|
|
451
|
+
* - `{forKeyboardShortcut}`: {@link BMKeyboardShortcut} The associated keyboard shortcut
|
|
452
|
+
* @param preventsDefault <Boolean, nullable> Defaults to `NO`. When set to `YES`, the default action of the event that triggers
|
|
453
|
+
* normally as a result of the key sequence will be prevented.
|
|
454
|
+
* }
|
|
455
|
+
* @return <BMKeyboardShortcut> A keyboard shortcut.
|
|
456
|
+
*/
|
|
457
|
+
BMKeyboardShortcut.keyboardShortcutWithKeySequence = function (event, args) {
|
|
458
|
+
return (new BMKeyboardShortcut).initWithKeySequence(event, args);
|
|
459
|
+
};
|
|
460
|
+
|
|
218
461
|
/**
|
|
219
462
|
* Constructs and returns a keyboard shortcut with the given key and optional modifiers, as well as
|
|
220
463
|
* the target and action that will handle it.
|
|
@@ -225,10 +468,14 @@ BMKeyboardShortcut.prototype = {
|
|
|
225
468
|
* {
|
|
226
469
|
* @param modifiers <[BMKeyboardShortcutModifier], nullable> Defaults to an empty array. An optional array of keyboard modifiers that must be active.
|
|
227
470
|
* for the keyboard shortcut to fire.
|
|
228
|
-
* @param target <AnyObject>
|
|
229
|
-
* @param action <String>
|
|
230
|
-
*
|
|
231
|
-
*
|
|
471
|
+
* @param target <AnyObject> The object that will handle this keyboard shortcut action.
|
|
472
|
+
* @param action <String> The name of a method on the target object that will be invoked when this
|
|
473
|
+
* keyboard shortcut is triggered. That method will receive the following arguments:
|
|
474
|
+
*
|
|
475
|
+
* - `event`: {@link KeyboardEvent} The keyboard event that triggered the keyboard shortcut
|
|
476
|
+
* - `{forKeyboardShortcut}`: {@link BMKeyboardShortcut} The associated keyboard shortcut
|
|
477
|
+
* @param preventsDefault <Boolean, nullable> Defaults to `NO`. When set to `YES`, the default action of the event that triggers
|
|
478
|
+
* normally as a result of the key sequence will be prevented.
|
|
232
479
|
* }
|
|
233
480
|
* @return <BMKeyboardShortcut> A keyboard shortcut.
|
|
234
481
|
*/
|
|
@@ -236,18 +483,21 @@ BMKeyboardShortcut.keyboardShortcutWithKeyCode = function (key, args) {
|
|
|
236
483
|
return (new BMKeyboardShortcut).initWithKeyCode(key, args);
|
|
237
484
|
};
|
|
238
485
|
|
|
239
|
-
|
|
240
486
|
/**
|
|
241
487
|
* Constructs and returns a keyboard shortcut with the given keyboard event. If the event includes the control or command keys, these may be converted
|
|
242
488
|
* into a system key modifier based on the current platform.
|
|
243
|
-
* @param event <KeyboardEvent>
|
|
489
|
+
* @param event <KeyboardEvent> The keyboard event from which this keyboard shortcut should be initialized.
|
|
244
490
|
* {
|
|
245
|
-
* @param target <AnyObject>
|
|
246
|
-
* @param action <String>
|
|
247
|
-
*
|
|
248
|
-
* @param preventsDefault <Boolean, nullable> Defaults to `NO`. When set to `YES`, the default action of the event that triggers this keyboard shortcut will be prevented.
|
|
249
|
-
* }
|
|
491
|
+
* @param target <AnyObject> The object that will handle this keyboard shortcut action.
|
|
492
|
+
* @param action <String> The name of a method on the target object that will be invoked when this
|
|
493
|
+
* keyboard shortcut is triggered. That method will receive the following arguments:
|
|
250
494
|
*
|
|
495
|
+
* - `event`: {@link KeyboardEvent} The keyboard event that triggered the keyboard shortcut
|
|
496
|
+
* - `{forKeyboardShortcut}`: {@link BMKeyboardShortcut} The associated keyboard shortcut
|
|
497
|
+
* @param preventsDefault <Boolean, nullable> Defaults to `NO`. When set to `YES`, the default action of the event that triggers
|
|
498
|
+
* normally as a result of the key sequence will be prevented.
|
|
499
|
+
* }
|
|
500
|
+
* @return <BMKeyboardShortcut> A keyboard shortcut.
|
|
251
501
|
*/
|
|
252
502
|
BMKeyboardShortcut.keyboardShortcutWithKeyboardEvent = function (event, args) {
|
|
253
503
|
return (new BMKeyboardShortcut).initWithKeyboardEvent(event, args);
|
|
@@ -261,7 +511,7 @@ BMKeyboardShortcut.keyboardShortcutWithKeyboardEvent = function (event, args) {
|
|
|
261
511
|
* @param targetID <Object ^(String)> A callback that is invoked with the target ID and should return
|
|
262
512
|
* the target object which will handle the keyboard shortcut.
|
|
263
513
|
* }
|
|
264
|
-
* @returns <
|
|
514
|
+
* @returns <BMKeyboardShortcut, nullable> A keyboard shortcut.
|
|
265
515
|
*/
|
|
266
516
|
BMKeyboardShortcut.keyboardShortcutWithSerializedKeyboardShortcut = function (shortcut, args) {
|
|
267
517
|
return (new BMKeyboardShortcut).initWithSerializedKeyboardShortcut(shortcut, args);
|