bm-core-ui 2.7.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/CHANGELOG.md +1624 -0
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/build/@types/index.d.ts +14078 -0
- package/build/BMCodeEditor/BMCodeEditor.js +707 -0
- package/build/BMCollectionView/BMCollectionView.js +5861 -0
- package/build/BMCollectionView/BMCollectionViewCell.js +688 -0
- package/build/BMCollectionView/BMCollectionViewFlowLayout.js +4467 -0
- package/build/BMCollectionView/BMCollectionViewLayout.js +830 -0
- package/build/BMCollectionView/BMCollectionViewLayoutAttributes.js +673 -0
- package/build/BMCollectionView/BMCollectionViewMasonryLayout.js +491 -0
- package/build/BMCollectionView/BMCollectionViewStackLayout.js +634 -0
- package/build/BMCollectionView/BMCollectionViewTileLayout.js +1121 -0
- package/build/BMCoreUI.css +2833 -0
- package/build/BMView/BMAttributedLabelView.js +310 -0
- package/build/BMView/BMLayoutConstraint_v2.5.js +1813 -0
- package/build/BMView/BMLayoutGuide.js +192 -0
- package/build/BMView/BMLayoutSizeClass.js +466 -0
- package/build/BMView/BMMenu.js +574 -0
- package/build/BMView/BMScrollView.js +247 -0
- package/build/BMView/BMTextField.js +512 -0
- package/build/BMView/BMTextFieldDelegate.js +71 -0
- package/build/BMView/BMView_v2.5.js +3572 -0
- package/build/BMView/BMViewport.js +221 -0
- package/build/BMViewLayoutEditor/BMLayoutEditor.js +6117 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorConstraintSettings.js +417 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorDelegate.js +59 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingCells.js +1653 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettings.js +1480 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingsComplexCells.js +431 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingsDelegate.js +46 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorVariablesController.js +460 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorViewGroupSettings.js +293 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorViewSettings.js +382 -0
- package/build/BMViewLayoutEditor/BMLayoutVariableProvider.js +202 -0
- package/build/BMWindow/BMConfirmationPopup.js +477 -0
- package/build/BMWindow/BMKeyboardShortcut.js +151 -0
- package/build/BMWindow/BMPopover/BMPopover.js +492 -0
- package/build/BMWindow/BMToolWindow.js +71 -0
- package/build/BMWindow/BMWindow.js +2000 -0
- package/build/Core/BMAnimationContext.js +1181 -0
- package/build/Core/BMColor.js +991 -0
- package/build/Core/BMCoreUI.js +470 -0
- package/build/Core/BMFunctionCollection.js +110 -0
- package/build/Core/BMIndexPath.js +165 -0
- package/build/Core/BMInset.js +138 -0
- package/build/Core/BMKeyPath.js +100 -0
- package/build/Core/BMPoint.js +291 -0
- package/build/Core/BMRect.js +556 -0
- package/build/Core/BMSize.js +137 -0
- package/build/iScroll/LICENSE +22 -0
- package/build/iScroll/iscroll-probe.js +2154 -0
- 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 +40 -0
- package/lib/@types/BMCoreUI.min.d.ts +14078 -0
- package/lib/BMCoreUI.min.js +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import {YES, NO, BMExtend} from '../Core/BMCoreUI'
|
|
2
|
+
|
|
3
|
+
// @type BMCodeEditorLanguage
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated - This enum will be removed in a future version
|
|
7
|
+
* ---
|
|
8
|
+
* An enum containing the languages that code editors should support.
|
|
9
|
+
*/
|
|
10
|
+
export var BMCodeEditorLanguage = Object.freeze({ // <enum>
|
|
11
|
+
/**
|
|
12
|
+
* Indicates that the code editor should edit javascript.
|
|
13
|
+
*/
|
|
14
|
+
Javascript: 'javascript', // <enum>
|
|
15
|
+
/**
|
|
16
|
+
* Indicates that the code editor should edit CSS.
|
|
17
|
+
*/
|
|
18
|
+
CSS: 'css', // <enum>
|
|
19
|
+
/**
|
|
20
|
+
* Indicates that the code editor should edit JSON.
|
|
21
|
+
*/
|
|
22
|
+
JSON: 'json', // <enum>
|
|
23
|
+
/**
|
|
24
|
+
* Indicates that this code editor should edit typescript.
|
|
25
|
+
*/
|
|
26
|
+
Typescript: 'typescript' // <enum>
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// @endtype
|
|
30
|
+
|
|
31
|
+
// @type BMCodeEditor
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated - This class will be removed in a future version
|
|
35
|
+
* ---
|
|
36
|
+
* The code editor is an abstract type that defines the methods and properties that should be exposed by a code editor.
|
|
37
|
+
* The code editor itself should not be used directly, instead one of the two subtypes - BMCodeMirrorCodeEditor or BMMonacoCodeEditor - shoud be used.
|
|
38
|
+
*/
|
|
39
|
+
export function BMCodeEditor() {}; // <constructor>
|
|
40
|
+
|
|
41
|
+
BMCodeEditor.prototype = {
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The DOM Node managed by this code editor.
|
|
45
|
+
*/
|
|
46
|
+
_container: undefined, // <DOMNode>
|
|
47
|
+
get container() {
|
|
48
|
+
return this._container;
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
delegate: undefined, // <BMCodeEditorDelegate>
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Designated initializer. Must be invoked by all other initializers.
|
|
55
|
+
* Subtypes that override this method must invoke the base implementation at some point during their initialization.
|
|
56
|
+
* @param container <DOMNode> The DOM Node managed by this code editor.
|
|
57
|
+
* {
|
|
58
|
+
* @param code <String, nullable> If specified, the code editor will be initialized with the given code content.
|
|
59
|
+
* @param language <BMCodeEditorLanguage, nullable> Defaults to BMCodeEditorLanguage.Javascript. The language this code editor should use.
|
|
60
|
+
* }
|
|
61
|
+
* @return <BMCodeEditor> This code editor.
|
|
62
|
+
*/
|
|
63
|
+
initWithContainer: function (container) {
|
|
64
|
+
this._container = container;
|
|
65
|
+
|
|
66
|
+
return this;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Controls the code on which the code editor operates.
|
|
71
|
+
*/
|
|
72
|
+
get code() {}, // <String>
|
|
73
|
+
set code(code) {},
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Will be set to `YES` when the current configuration requires the code to be transpiled before it can be executed by the browser environment.
|
|
77
|
+
* When this property returns YES, the `transpiledCode()` method should be invoked to retrieve the transpiled code.
|
|
78
|
+
*/
|
|
79
|
+
get requiresTranspilation() { // <Boolean>
|
|
80
|
+
return NO;
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the transpiled code.
|
|
85
|
+
* This method should not be invoked when `requiresTranspilation` is set to NO.
|
|
86
|
+
* @return <String> The transpiled code.
|
|
87
|
+
*/
|
|
88
|
+
async transpiledCode() { // <String>
|
|
89
|
+
return this.code;
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Controls the cursor position in the code editor.
|
|
94
|
+
* This property is a point where the X coordinate represents the cursor's 0-indexed column and the Y coordinate its 0-indexed line.
|
|
95
|
+
*/
|
|
96
|
+
get cursorPosition() {}, // <BMPoint>
|
|
97
|
+
set cursorPosition(position) {},
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Defaults to `NO`. If the code editor supports extensible autocomplete, it should set this property to `YES` during initialization.
|
|
101
|
+
* If the code editor sets this property to YES, it must override the getter and setter associated with <code>scope</code> property to handle
|
|
102
|
+
* injecting additional autocomplete symbols.
|
|
103
|
+
*/
|
|
104
|
+
supportsExtensibleAutocomplete: NO, // <Boolean>
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Should be overriden by code editors that support extensible autocomplete but do not provide autocomplete
|
|
108
|
+
* for builtin ES6 and jQuery types.
|
|
109
|
+
* Code editors that already provide default autocomplete support for ES6 and jQuery are not required to implement this method.
|
|
110
|
+
* Sets the builtin libraries to the given code.
|
|
111
|
+
* The default implementation does nothing.
|
|
112
|
+
* @param ES6Library <String> The ES6 definition.
|
|
113
|
+
* {
|
|
114
|
+
* @param jQueryLibrary <String> The jQuery definition.
|
|
115
|
+
* @param additionalLibraries <[String], nullable> An optional array containing additional libraries that may
|
|
116
|
+
* be needed for the environment.
|
|
117
|
+
* }
|
|
118
|
+
*/
|
|
119
|
+
setBuiltinES6Library: function (ES6Library, args) {},
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Should be overriden by code editors that support extensible autocomplete.
|
|
123
|
+
* When this method is invoked, the code editor should enable autocomplete definitions for the given imports.
|
|
124
|
+
* If this method has already been previously invoked, the previous imports autocomplete definition should be
|
|
125
|
+
* replaced by this new one.
|
|
126
|
+
* The default implementation does nothing.
|
|
127
|
+
* @param imports <String> The imports definition.
|
|
128
|
+
*/
|
|
129
|
+
setImports(imports) {},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Should be overriden by code editors that support extensible autocomplete.
|
|
133
|
+
* When this method is invoked, the code editor should enable autocomplete definitions for the given external library.
|
|
134
|
+
* If this method has already been previously invoked with the same name, the previous autocomplete definition should be
|
|
135
|
+
* replaced by this new one.
|
|
136
|
+
* The default implementation does nothing.
|
|
137
|
+
* @param name <String> The name of the library.
|
|
138
|
+
* {
|
|
139
|
+
* @param code <String> The contents of the library.
|
|
140
|
+
* }
|
|
141
|
+
*/
|
|
142
|
+
addExternalLibraryNamed(name, args) {},
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Should be overriden by code editors that support extensible autocomplete.
|
|
146
|
+
* When this method is invoked with the name of a library that was previously added, it will be removed from the autocomplete
|
|
147
|
+
* definitions. If that library was not previously imported, this method does nothing.
|
|
148
|
+
* The default implementation does nothing.
|
|
149
|
+
* @param name <String> The name of the library.
|
|
150
|
+
* {
|
|
151
|
+
* @param code <String> The contents of the library.
|
|
152
|
+
* }
|
|
153
|
+
*/
|
|
154
|
+
removeExternalLibraryNamed(name) {},
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Should be overriden by code editors that support extensible autocomplete.
|
|
158
|
+
* When this method is invoked with the name of a library that was previously added, it returns `YES`.
|
|
159
|
+
* If that library was not previously imported, this method returns `NO`.
|
|
160
|
+
* The default implementation returns `NO` in all cases.
|
|
161
|
+
* @param name <String> The name of the library.
|
|
162
|
+
* @return <Boolean> `YES` if the library was imported, `NO` otherwise.
|
|
163
|
+
*/
|
|
164
|
+
hasExternalLibraryNamed(name) {
|
|
165
|
+
return NO;
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Controls the autocomplete scope in which the code runs.
|
|
170
|
+
* Editors that support extensible autocomplete should override this property to handle injecting
|
|
171
|
+
* additional symbols into the autocomplete scope.
|
|
172
|
+
*/
|
|
173
|
+
get scope() {}, // <Object<String, String>, nullable>
|
|
174
|
+
set scope(scope) {},
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Should be invoked to insert the given text at the current cursor position.
|
|
178
|
+
* @param text <String> The text to insert.
|
|
179
|
+
*/
|
|
180
|
+
insertText: function (text) {},
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Should be invoked to cause this code editor to acquire keyboard focus.
|
|
184
|
+
*/
|
|
185
|
+
acquireFocus: function () {},
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Should be invoked to cause this code editor to resign keyboard focus.
|
|
190
|
+
*/
|
|
191
|
+
resignFocus: function () {},
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Should be invoked whenever this code editor is resized for any reason.
|
|
195
|
+
*/
|
|
196
|
+
resized: function () {},
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Should be invoked when this code editor is no longer needed and should be destroyed.
|
|
200
|
+
*/
|
|
201
|
+
release: function () {}
|
|
202
|
+
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// @endtype
|
|
206
|
+
|
|
207
|
+
// @type BMCodeMirrorCodeEditor
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @deprecated - This class will be removed in a future version
|
|
211
|
+
* ---
|
|
212
|
+
* The code mirror code editor is a concrete implementation of BMCodeEditor that uses CodeMirror as its editor.
|
|
213
|
+
*/
|
|
214
|
+
export function BMCodeMirrorCodeEditor() {} // <constructor>
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @deprecated - This constructor will be removed in a future version
|
|
218
|
+
* ---
|
|
219
|
+
* Constructs and returns a code mirror code editor using the specified container.
|
|
220
|
+
* @param container <DOMNode> The DOM Node managed by this code mirror code editor.
|
|
221
|
+
* {
|
|
222
|
+
* @param code <String, nullable> If specified, the code mirror code editor will be initialized with the given code content.
|
|
223
|
+
* @param language <BMCodeEditorLanguage, nullable> Defaults to BMCodeEditorLanguage.Javascript. The language this code editor should use.
|
|
224
|
+
* }
|
|
225
|
+
* @return <BMCodeMirrorCodeEditor> A code editor.
|
|
226
|
+
*/
|
|
227
|
+
export function BMCodeMirrorCodeEditorMakeWithContainer(container, args) {
|
|
228
|
+
return (new BMCodeMirrorCodeEditor()).initWithContainer(container, {code: args && args.code, language: args && args.language});
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
BMExtend(BMCodeMirrorCodeEditor.prototype, BMCodeEditor.prototype, {
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The CodeMirror instance managed by this code editor.
|
|
235
|
+
*/
|
|
236
|
+
_codeMirror: undefined, // <CodeMirror>
|
|
237
|
+
|
|
238
|
+
//@override - BMCodeEditor
|
|
239
|
+
/**
|
|
240
|
+
* Designated initializer. Must be invoked by all other initializers.
|
|
241
|
+
* Initializes this code mirror code editor using the specified container.
|
|
242
|
+
* Optionally, the initial code may be provided as well.
|
|
243
|
+
* @param container <DOMNode> The DOM Node managed by this code mirror code editor.
|
|
244
|
+
* {
|
|
245
|
+
* @param code <String, nullable> If specified, the code mirror code editor will be initialized with the given code content.
|
|
246
|
+
* @param language <BMCodeEditorLanguage, nullable> Defaults to BMCodeEditorLanguage.Javascript. The language this code editor should use.
|
|
247
|
+
* }
|
|
248
|
+
* @return <BMCodeMirrorCodeEditor> This code editor.
|
|
249
|
+
*/
|
|
250
|
+
initWithContainer: function (container, args) {
|
|
251
|
+
BMCodeEditor.prototype.initWithContainer.call(this, container);
|
|
252
|
+
|
|
253
|
+
this._codeMirror = CodeMirror(this.container, {
|
|
254
|
+
mode: (args && args.language) || BMCodeEditorLanguage.Javascript,
|
|
255
|
+
theme: "eclipse",
|
|
256
|
+
lineNumbers: YES,
|
|
257
|
+
firstLineNumber: 0,
|
|
258
|
+
matchBrackets: YES,
|
|
259
|
+
extraKeys: {
|
|
260
|
+
"Ctrl-Q": function (codeMirror) {
|
|
261
|
+
cm.foldCode(cm.getCursor());
|
|
262
|
+
},
|
|
263
|
+
'Ctrl-S': function (codeMirror) {
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
foldGutter: true,
|
|
268
|
+
gutters: ["CodeMirror-lint-markers", "CodeMirror-foldgutter"],
|
|
269
|
+
indentUnit: 4
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
this.container.querySelectorAll(".CodeMirror")[0].style.height = '100%';
|
|
273
|
+
|
|
274
|
+
var self = this;
|
|
275
|
+
this._codeMirror.on('change', function () {
|
|
276
|
+
if (self.delegate && self.delegate.codeEditorContentsDidChange) {
|
|
277
|
+
self.delegate.codeEditorContentsDidChange(self);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
var code = args && args.code;
|
|
282
|
+
if (!code) return this;
|
|
283
|
+
|
|
284
|
+
this.code = code;
|
|
285
|
+
|
|
286
|
+
return this;
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Controls the code on which the code editor operates.
|
|
291
|
+
*/
|
|
292
|
+
get code() { // <String>
|
|
293
|
+
return this._codeMirror.getValue();
|
|
294
|
+
},
|
|
295
|
+
set code(code) {
|
|
296
|
+
this._codeMirror.setValue(code);
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
get cursorPosition() { // <BMPoint>
|
|
300
|
+
var cursor = this._codeMirror.getCursor();
|
|
301
|
+
|
|
302
|
+
return BMPointMake(cursor.ch, cursor.line);
|
|
303
|
+
},
|
|
304
|
+
set cursorPosition(position) {
|
|
305
|
+
this._codeMirror.setCursor({ch: position.x, line: position.y});
|
|
306
|
+
this._codeMirror.scrollIntoView({ch: 0, line: position.y});
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
// @override - BMCodeEditor
|
|
310
|
+
insertText: function (text) {
|
|
311
|
+
var document = this._codeMirror.getDoc();
|
|
312
|
+
var cursor = this._codeMirror.getCursor();
|
|
313
|
+
|
|
314
|
+
document.replaceRange(text, cursor);
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
// @override - BMCodeEditor
|
|
318
|
+
acquireFocus: function () {
|
|
319
|
+
this._codeMirror.focus();
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
// @override - BMCodeEditor
|
|
323
|
+
resignFocus: function () {
|
|
324
|
+
// unsupported
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
// @override - BMCodeEditor
|
|
328
|
+
resized: function () {
|
|
329
|
+
this._codeMirror.refresh();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// @endtype
|
|
335
|
+
|
|
336
|
+
// @type BMMonacoCodeEditor extends BMCodeEditor
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* @deprecated - This class will be removed in a future version
|
|
340
|
+
* ---
|
|
341
|
+
* The monaco code editor is a concrete implementation of BMCodeEditor that uses Monaco as its editor.
|
|
342
|
+
*/
|
|
343
|
+
export function BMMonacoCodeEditor() {} // <constructor>
|
|
344
|
+
|
|
345
|
+
var _BMMonacoCodeEditorThemesCreated = NO;
|
|
346
|
+
var _BMMonacoCodeEditorDefaultsSet = NO;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Invoked when creating a monaco code editor.
|
|
350
|
+
* Creates the default themes if they weren't already created.
|
|
351
|
+
*/
|
|
352
|
+
BMMonacoCodeEditor.createThemes = function () {
|
|
353
|
+
if (_BMMonacoCodeEditorThemesCreated) return;
|
|
354
|
+
|
|
355
|
+
_BMMonacoCodeEditorThemesCreated = YES;
|
|
356
|
+
|
|
357
|
+
monaco.editor.defineTheme('BMMonacoCodeEditorTheme', {
|
|
358
|
+
base: 'vs',
|
|
359
|
+
inherit: YES,
|
|
360
|
+
rules: [
|
|
361
|
+
{token: 'comment', foreground: 'CCCCCC'},
|
|
362
|
+
{token: 'string', foreground: 'BC670F', background: 'FDFBF3'},
|
|
363
|
+
{token: 'keyword', foreground: '6700B9'},
|
|
364
|
+
{token: 'type', foreground: '6700B9'},
|
|
365
|
+
{token: 'identifier', foreground: '434343'},
|
|
366
|
+
{token: 'delimiter', foreground: '434343'},
|
|
367
|
+
{token: 'number', foreground: '7552c1', background: 'E7E6FD'},
|
|
368
|
+
{token: 'tag', foreground: '434343'},
|
|
369
|
+
{token: 'attribute.name', foreground: 'D4430D'},
|
|
370
|
+
{token: 'attribute.value', foreground: '43A202'},
|
|
371
|
+
{token: 'attribute.value.number', foreground: '5AA201', background: 'F6FAEB'},
|
|
372
|
+
{token: 'attribute.value.unit', foreground: '5AA201', background: 'F6FAEB'},
|
|
373
|
+
{token: 'attribute.value.hex', foreground: '43A202'},
|
|
374
|
+
{token: 'tag.css', foreground: '3A77BF'}
|
|
375
|
+
]
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
monaco.editor.defineTheme('BMMonacoCodeEditorThemeDark', {
|
|
379
|
+
base: 'vs-dark',
|
|
380
|
+
inherit: YES,
|
|
381
|
+
rules: [
|
|
382
|
+
{token: 'comment', foreground: '555555'},
|
|
383
|
+
{token: 'string', foreground: 'ee9452', background: 'FDFBF3'},
|
|
384
|
+
{token: 'keyword', foreground: 'a349f5'},
|
|
385
|
+
{token: 'type', foreground: 'a349f5'},
|
|
386
|
+
{token: 'identifier', foreground: 'bcbcbc'},
|
|
387
|
+
{token: 'delimiter', foreground: 'bcbcbc'},
|
|
388
|
+
{token: 'number', foreground: 'a37df1', background: 'E7E6FD'},
|
|
389
|
+
{token: 'tag', foreground: 'bcbcbc'},
|
|
390
|
+
{token: 'attribute.name', foreground: 'ff7b41'},
|
|
391
|
+
{token: 'attribute.value', foreground: '80dc4c'},
|
|
392
|
+
{token: 'attribute.value.number', foreground: '92d94b', background: 'F6FAEB'},
|
|
393
|
+
{token: 'attribute.value.unit', foreground: '92d94b', background: 'F6FAEB'},
|
|
394
|
+
{token: 'attribute.value.hex', foreground: '80dc4c'},
|
|
395
|
+
{token: 'tag.css', foreground: '5fa1ec'}
|
|
396
|
+
]
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* @deprecated - This constructor will be removed in a future version
|
|
402
|
+
* ---
|
|
403
|
+
* Constructs and returns a code mirror code editor using the specified container.
|
|
404
|
+
* @param container <DOMNode> The DOM Node managed by this code mirror code editor.
|
|
405
|
+
* {
|
|
406
|
+
* @param code <String, nullable> If specified, the code mirror code editor will be initialized with the given code content.
|
|
407
|
+
* @param language <BMCodeEditorLanguage, nullable> Defaults to BMCodeEditorLanguage.Javascript. The language this code editor should use.
|
|
408
|
+
* }
|
|
409
|
+
* @return <BMCodeMirrorCodeEditor> A code editor.
|
|
410
|
+
*/
|
|
411
|
+
export function BMMonacoCodeEditorMakeWithContainer(container, args) {
|
|
412
|
+
return (new BMMonacoCodeEditor()).initWithContainer(container, {code: args && args.code, language: args && args.language});
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
BMExtend(BMMonacoCodeEditor.prototype, BMCodeEditor.prototype, {
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* The monaco instance managed by this code editor.
|
|
419
|
+
*/
|
|
420
|
+
_monaco: undefined, // <Monaco>
|
|
421
|
+
|
|
422
|
+
_autocompleteLibraries: undefined, // <Promise>
|
|
423
|
+
|
|
424
|
+
_rootES6Library: undefined, // <Promise>
|
|
425
|
+
|
|
426
|
+
_rootjQueryLibrary: undefined, // <Promise>
|
|
427
|
+
|
|
428
|
+
_importsLibrary: undefined, // <Promise>
|
|
429
|
+
|
|
430
|
+
_externalLibraries: undefined, // <Object<String, Promise>>
|
|
431
|
+
|
|
432
|
+
_language: undefined, // <BMCodeEditorLanguage>
|
|
433
|
+
|
|
434
|
+
_darkModeQuery: undefined, // <MediaQueryList>
|
|
435
|
+
|
|
436
|
+
_darkModeQueryCallback: undefined, // <Function>
|
|
437
|
+
|
|
438
|
+
//@override - BMCodeEditor
|
|
439
|
+
/**
|
|
440
|
+
* Designated initializer. Must be invoked by all other initializers.
|
|
441
|
+
* Initializes this code mirror code editor using the specified container.
|
|
442
|
+
* Optionally, the initial code may be provided as well.
|
|
443
|
+
* @param container <DOMNode> The DOM Node managed by this monaco code editor.
|
|
444
|
+
* {
|
|
445
|
+
* @param code <String, nullable> If specified, the monaco code editor will be initialized with the given code content.
|
|
446
|
+
* @param language <BMCodeEditorLanguage, nullable> Defaults to BMCodeEditorLanguage.Javascript. The language this code editor should use.
|
|
447
|
+
* }
|
|
448
|
+
* @return <BMMonacoCodeEditor> This code editor.
|
|
449
|
+
*/
|
|
450
|
+
initWithContainer: function (container, args) {
|
|
451
|
+
BMCodeEditor.prototype.initWithContainer.call(this, container);
|
|
452
|
+
|
|
453
|
+
BMMonacoCodeEditor.createThemes();
|
|
454
|
+
|
|
455
|
+
var options = {
|
|
456
|
+
folding: YES,
|
|
457
|
+
fontLigatures: NO,
|
|
458
|
+
formatOnPaste: YES,
|
|
459
|
+
mouseWheelZoom: YES,
|
|
460
|
+
scrollBeyondLastLine: YES,
|
|
461
|
+
value: args && args.code,
|
|
462
|
+
language: (args && args.language) || BMCodeEditorLanguage.Javascript,
|
|
463
|
+
fontFamily: 'Menlo, Meslo LG S, Fira Code, Monaco, monospace',
|
|
464
|
+
theme: window.matchMedia("(prefers-color-scheme: dark)").matches ? 'BMMonacoCodeEditorThemeDark' : 'BMMonacoCodeEditorTheme',
|
|
465
|
+
disableLayerHinting: YES
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
this._language = args.language || BMCodeEditorLanguage.Javascript;
|
|
469
|
+
|
|
470
|
+
if (!_BMMonacoCodeEditorDefaultsSet) {
|
|
471
|
+
_BMMonacoCodeEditorDefaultsSet = YES;
|
|
472
|
+
|
|
473
|
+
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
|
|
474
|
+
target: monaco.languages.typescript.ScriptTarget.ESNext,
|
|
475
|
+
allowNonTsExtensions: YES,
|
|
476
|
+
experimentalDecorators: YES,
|
|
477
|
+
strict: YES,
|
|
478
|
+
inlineSourceMap: YES,
|
|
479
|
+
module: monaco.languages.typescript.ModuleKind.CommonJS,
|
|
480
|
+
noImplicitUseStrict: YES
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
|
|
484
|
+
target: monaco.languages.typescript.ScriptTarget.ESNext,
|
|
485
|
+
allowNonTsExtensions: YES,
|
|
486
|
+
experimentalDecorators: YES,
|
|
487
|
+
strict: YES,
|
|
488
|
+
inlineSourceMap: YES,
|
|
489
|
+
inlineSources: YES,
|
|
490
|
+
noImplicitUseStrict: YES,
|
|
491
|
+
alwaysStrict: NO,
|
|
492
|
+
module: monaco.languages.typescript.ModuleKind.None,
|
|
493
|
+
useDefineForClassFields: NO,
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
this._monaco = monaco.editor.create(container, options);
|
|
498
|
+
|
|
499
|
+
var self = this;
|
|
500
|
+
this._monaco.onDidChangeModelContent(function (event) {
|
|
501
|
+
if (self.delegate && self.delegate.codeEditorContentsDidChange) {
|
|
502
|
+
self.delegate.codeEditorContentsDidChange(self);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
this._externalLibraries = {};
|
|
507
|
+
|
|
508
|
+
this._darkModeQueryCallback = (event) => {
|
|
509
|
+
if (event.matches) {
|
|
510
|
+
monaco.editor.setTheme('BMMonacoCodeEditorThemeDark');
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
monaco.editor.setTheme('BMMonacoCodeEditorTheme');
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
this._darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
518
|
+
this._darkModeQuery.addListener(this._darkModeQueryCallback);
|
|
519
|
+
|
|
520
|
+
return this;
|
|
521
|
+
},
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Sets the builtin libraries to the given code. If the builtin libraries are already defined, they will be replaced with the given definitions.
|
|
525
|
+
* @param ES6Library <String> The ES6 definition.
|
|
526
|
+
* {
|
|
527
|
+
* @param jQueryLibrary <String> The jQuery definition.
|
|
528
|
+
* @param additionalLibraries <[String], nullable> An optional array containing additional libraries that may
|
|
529
|
+
* be needed for the environment.
|
|
530
|
+
* }
|
|
531
|
+
*/
|
|
532
|
+
setBuiltinES6Library: function (ES6Library, args) {
|
|
533
|
+
if (this._language === BMCodeEditorLanguage.Javascript) {
|
|
534
|
+
this._rootES6Library = monaco.languages.typescript.javascriptDefaults.addExtraLib(ES6Library, 'ES6.d.ts');
|
|
535
|
+
this._rootjQueryLibrary = monaco.languages.typescript.javascriptDefaults.addExtraLib(args.jQueryLibrary, 'jQuery.d.ts');
|
|
536
|
+
if (args.additionalLibraries) {
|
|
537
|
+
this._autocompleteLibraries = monaco.languages.typescript.javascriptDefaults.addExtraLib(args.additionalLibraries.join('\n'), 'additional.d.ts');
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
if (this._autocompleteLibraries) this._autocompleteLibraries.dispose();
|
|
541
|
+
this._autocompleteLibraries = undefined;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
this._rootES6Library = monaco.languages.typescript.typescriptDefaults.addExtraLib(ES6Library, 'ES6.d.ts');
|
|
546
|
+
this._rootjQueryLibrary = monaco.languages.typescript.typescriptDefaults.addExtraLib(args.jQueryLibrary, 'jQuery.d.ts');
|
|
547
|
+
if (args.additionalLibraries) {
|
|
548
|
+
this._autocompleteLibraries = monaco.languages.typescript.typescriptDefaults.addExtraLib(args.additionalLibraries.join('\n'), 'additional.d.ts');
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
if (this._autocompleteLibraries) this._autocompleteLibraries.dispose();
|
|
552
|
+
this._autocompleteLibraries = undefined;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
|
|
557
|
+
// @override - BMCodeEditor
|
|
558
|
+
setImports(imports) {
|
|
559
|
+
if (this._language === BMCodeEditorLanguage.Javascript) {
|
|
560
|
+
this._importsLibrary = monaco.languages.typescript.javascriptDefaults.addExtraLib(imports, 'node_modules/@types/imports/index.d.ts');
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
this._importsLibrary = monaco.languages.typescript.typescriptDefaults.addExtraLib(imports, 'node_modules/@types/imports/index.d.ts');
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
|
|
567
|
+
// @override - BMCodeEditor
|
|
568
|
+
addExternalLibraryNamed(name, args) {
|
|
569
|
+
if (this._language === BMCodeEditorLanguage.Javascript) {
|
|
570
|
+
this._externalLibraries[name] = monaco.languages.typescript.javascriptDefaults.addExtraLib(args.code, 'node_modules/@types/' + name);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
this._externalLibraries[name] = monaco.languages.typescript.typescriptDefaults.addExtraLib(args.code, 'node_modules/@types/' + name);
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
|
|
577
|
+
// @override - BMCodeEditor
|
|
578
|
+
removeExternalLibraryNamed(name) {
|
|
579
|
+
if (this._externalLibraries[name]) {
|
|
580
|
+
this._externalLibraries[name].dispose();
|
|
581
|
+
delete this._externalLibraries[name];
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
|
|
585
|
+
// @override - BMCodeEditor
|
|
586
|
+
hasExternalLibraryNamed(name) {
|
|
587
|
+
return name in this._externalLibraries;
|
|
588
|
+
},
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Controls the code on which the code editor operates.
|
|
592
|
+
*/
|
|
593
|
+
get code() { // <String>
|
|
594
|
+
return this._monaco.getValue();
|
|
595
|
+
},
|
|
596
|
+
set code(code) {
|
|
597
|
+
this._monaco.setValue(code);
|
|
598
|
+
},
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Will be set to `YES` when the current configuration requires the code to be transpiled before it can be executed by the browser environment.
|
|
602
|
+
* When this property returns YES, the `transpiledCode()` method should be invoked to retrieve the transpiled code.
|
|
603
|
+
*/
|
|
604
|
+
get requiresTranspilation() { // <Boolean>
|
|
605
|
+
return this._language === BMCodeEditorLanguage.Typescript;
|
|
606
|
+
},
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Returns the transpiled code.
|
|
610
|
+
* This method should not be invoked when `requiresTranspilation` is set to NO.
|
|
611
|
+
* @return <String> The transpiled code.
|
|
612
|
+
*/
|
|
613
|
+
transpiledCode() { // <String>
|
|
614
|
+
return new Promise((resolve, reject) => {
|
|
615
|
+
let workerPromise;
|
|
616
|
+
if (monaco.languages.typescript.getLanguageWorker) {
|
|
617
|
+
workerPromise = monaco.languages.typescript.getLanguageWorker("typescript");
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
workerPromise = monaco.languages.typescript.getTypeScriptWorker();
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
workerPromise.then((worker) => {
|
|
624
|
+
// if there is an uri available
|
|
625
|
+
if (this._monaco.getModel()) {
|
|
626
|
+
worker(this._monaco.getModel().uri).then((client) => {
|
|
627
|
+
if (this._monaco.getModel())
|
|
628
|
+
client.getEmitOutput(this._monaco.getModel().uri.toString()).then(function (result) {
|
|
629
|
+
resolve(result.outputFiles[0].text);
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
},
|
|
636
|
+
|
|
637
|
+
get cursorPosition() { // <BMPoint>
|
|
638
|
+
var cursor = this._monaco.getSelection();
|
|
639
|
+
|
|
640
|
+
return BMPointMake(cursor.startColumn, cursor.startLineNumber);
|
|
641
|
+
},
|
|
642
|
+
set cursorPosition(position) {
|
|
643
|
+
var selection = new monaco.Range(position.y, position.x, position.y, position.x);
|
|
644
|
+
this._monaco.setSelection(selection);
|
|
645
|
+
this._monaco.revealPositionInCenter({lineNumber: position.y, column: position.x});
|
|
646
|
+
},
|
|
647
|
+
|
|
648
|
+
// @override - BMCodeEditor
|
|
649
|
+
insertText: function (text) {
|
|
650
|
+
this._monaco.executeEdits('insertSnippet', [{
|
|
651
|
+
range: this._monaco.getSelection(),
|
|
652
|
+
text: text,
|
|
653
|
+
forceMoveMarkers: true
|
|
654
|
+
}]);
|
|
655
|
+
},
|
|
656
|
+
|
|
657
|
+
// @override - BMCodeEditor
|
|
658
|
+
acquireFocus: function () {
|
|
659
|
+
this._monaco.focus();
|
|
660
|
+
},
|
|
661
|
+
|
|
662
|
+
// @override - BMCodeEditor
|
|
663
|
+
resignFocus: function () {
|
|
664
|
+
// unsupported
|
|
665
|
+
},
|
|
666
|
+
|
|
667
|
+
// @override - BMCodeEditor
|
|
668
|
+
resized: function () {
|
|
669
|
+
this._monaco.layout();
|
|
670
|
+
},
|
|
671
|
+
|
|
672
|
+
get supportsExtensibleAutocomplete() {
|
|
673
|
+
return YES;
|
|
674
|
+
},
|
|
675
|
+
|
|
676
|
+
get scope() {
|
|
677
|
+
return this._scope;
|
|
678
|
+
},
|
|
679
|
+
|
|
680
|
+
set scope(scope) {
|
|
681
|
+
//if (this._autocompleteLibrary) this._autocompleteLibrary.dispose();
|
|
682
|
+
|
|
683
|
+
this._scope = scope;
|
|
684
|
+
if (this._language === BMCodeEditorLanguage.Javascript) {
|
|
685
|
+
this._autocompleteLibrary = monaco.languages.typescript.javascriptDefaults.addExtraLib(scope, 'BMMonacoCodeEditor.d.ts');
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
this._autocompleteLibrary = monaco.languages.typescript.typescriptDefaults.addExtraLib(scope, 'BMMonacoCodeEditor.d.ts');
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
|
|
692
|
+
release: function () {
|
|
693
|
+
this._monaco.dispose();
|
|
694
|
+
if (this._autocompleteLibrary) this._autocompleteLibrary.dispose();
|
|
695
|
+
if (this._autocompleteLibraries) this._autocompleteLibraries.dispose();
|
|
696
|
+
if (this._rootES6Library) this._rootES6Library.dispose();
|
|
697
|
+
if (this._rootjQueryLibrary) this._rootjQueryLibrary.dispose();
|
|
698
|
+
if (this._importsLibrary) this._importsLibrary.dispose();
|
|
699
|
+
|
|
700
|
+
this._darkModeQuery.removeListener(this._darkModeQueryCallback);
|
|
701
|
+
|
|
702
|
+
Object.keys(this._externalLibraries).forEach(key => this._externalLibraries[key].dispose());
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
// @endtype
|