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,310 @@
|
|
|
1
|
+
import {YES, NO, BMExtend, BMCopyProperties} from '../Core/BMCoreUI'
|
|
2
|
+
import {BMView} from './BMView_v2.5'
|
|
3
|
+
|
|
4
|
+
const BM_LABEL_VIEW_DEBUG_INTRINSIC_SIZE = NO;
|
|
5
|
+
|
|
6
|
+
// @type BMAttributedLabelView extends BMView
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An attributed label view is a view that displays a text that can have various arguments which may be changed at runtime.
|
|
10
|
+
* The attributed label automatically generates DOM nodes for each argument.
|
|
11
|
+
*
|
|
12
|
+
* Creating a label view with a template can be done using the factory method:
|
|
13
|
+
* ```js
|
|
14
|
+
BMAttributedView.labelViewWithTemplate('Template with ${firstPlaceholder} and ${secondPlaceholder}');
|
|
15
|
+
```
|
|
16
|
+
* which creates an attributed label with two arguments named `firstPlaceholder` and `secondPlaceholder`.
|
|
17
|
+
*
|
|
18
|
+
* The arguments themselves are accessed and updated via the `arguments` property of the attributed label view. Each argument
|
|
19
|
+
* appears as a property of that object. Their value can be read or written through the `value` property of that object .e.g
|
|
20
|
+
* ```js
|
|
21
|
+
// This sets the value of the firstPlaceholder argument
|
|
22
|
+
myLabelView.arguments.firstPlaceholder.value = 3;
|
|
23
|
+
```
|
|
24
|
+
*
|
|
25
|
+
* Additionally, the arguments objects allow specifying CSS styles for each argument. The attributed label view will reapply these styles
|
|
26
|
+
* whenever the underlying DOM structure changes, for example when changing the template string. This is accessible via the `style` property of each argument
|
|
27
|
+
* object. This takes a regular CSS rule object, such as `{color: 'red', borderWidth: '2px'}`.
|
|
28
|
+
*
|
|
29
|
+
* Finally, the underlying DOM nodes themselves are accessible via the `node` property of these arguments objects. Note that there is no guarantee of the lifetime of
|
|
30
|
+
* these DOM nodes. The attribute label can remove and re-create these nodes at any time as needed.
|
|
31
|
+
*/
|
|
32
|
+
export function BMAttributedLabelView() {} // <constructor>
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The regex used by the attributed label view to extract arguments
|
|
36
|
+
*/
|
|
37
|
+
const _BMAttributedLabelViewRegex = /\${([a-zA-Z0-9]+)}/g;
|
|
38
|
+
|
|
39
|
+
BMAttributedLabelView.prototype = BMExtend(Object.create(BMView.prototype), {
|
|
40
|
+
|
|
41
|
+
_supportsAutomaticIntrinsicSize: YES,
|
|
42
|
+
|
|
43
|
+
get intrinsicSize() {
|
|
44
|
+
let result = Object.getOwnPropertyDescriptor(BMView.prototype, 'intrinsicSize').get.call(this);
|
|
45
|
+
|
|
46
|
+
if (BM_LABEL_VIEW_DEBUG_INTRINSIC_SIZE) console.log('[BMAttributedLabelView] Intrinsic size is ' + result);
|
|
47
|
+
|
|
48
|
+
if (BM_LABEL_VIEW_DEBUG_INTRINSIC_SIZE && result && result.width > 1000) debugger;
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
initWithDOMNode() {
|
|
54
|
+
BMView.prototype.initWithDOMNode.apply(this, arguments);
|
|
55
|
+
|
|
56
|
+
this.arguments = {};
|
|
57
|
+
|
|
58
|
+
return this;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* This attributed label view's content node. If this value is not set during initialization, it defaults to the view's node.
|
|
63
|
+
*
|
|
64
|
+
* If set, this controls where the attributed label view will insert its text. The given node should be a descendant of the label view's node.
|
|
65
|
+
*/
|
|
66
|
+
_contentNode: undefined,
|
|
67
|
+
get contentNode() {
|
|
68
|
+
return this._contentNode || this.node;
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* An optional string that will be prefixed to the argument DOM node class names.
|
|
73
|
+
* By default, a DOM node is created for each argument and is assigned a class name that is
|
|
74
|
+
* equal to the argument's name. When this property is set, its value is prefixed to the argument's class name.
|
|
75
|
+
*/
|
|
76
|
+
_classPrefix: undefined, // <String>
|
|
77
|
+
get classPrefix() {
|
|
78
|
+
return this._classPrefix;
|
|
79
|
+
},
|
|
80
|
+
set classPrefix(classPrefix) {
|
|
81
|
+
classPrefix = classPrefix || '';
|
|
82
|
+
|
|
83
|
+
for (let argumentName in this.arguments) {
|
|
84
|
+
let argument = this.arguments[argumentName];
|
|
85
|
+
argument._node.className = classPrefix + argumentName;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The template string.
|
|
91
|
+
*/
|
|
92
|
+
_template: undefined, // <String>
|
|
93
|
+
get template() {
|
|
94
|
+
return this._template;
|
|
95
|
+
},
|
|
96
|
+
set template(template) {
|
|
97
|
+
this._template = template;
|
|
98
|
+
|
|
99
|
+
// Discover the arguments within the template
|
|
100
|
+
_BMAttributedLabelViewRegex.lastIndex = 0;
|
|
101
|
+
|
|
102
|
+
// This object contains the new list of arguments
|
|
103
|
+
let newArguments = {};
|
|
104
|
+
|
|
105
|
+
let match;
|
|
106
|
+
let index = 0;
|
|
107
|
+
while (match = _BMAttributedLabelViewRegex.exec(template)) {
|
|
108
|
+
let argumentName = match[1];
|
|
109
|
+
let argument;
|
|
110
|
+
|
|
111
|
+
if (this.arguments[argumentName]) {
|
|
112
|
+
// If an argument with this name already exists, update its internal index number to the given value
|
|
113
|
+
argument = this.arguments[argumentName];
|
|
114
|
+
argument._index = index;
|
|
115
|
+
newArguments[argumentName] = argument;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Otherwise create a new argument
|
|
119
|
+
argument = Object.create(BMAttributedLabelViewArgument.prototype);
|
|
120
|
+
argument._name = argumentName;
|
|
121
|
+
argument._index = index;
|
|
122
|
+
argument._view = this;
|
|
123
|
+
newArguments[argumentName] = argument;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
index++;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Then replace the arguments within the template with spans
|
|
130
|
+
template = template.replace(_BMAttributedLabelViewRegex, `<span class=${this._classPrefix}$1></span>`);
|
|
131
|
+
|
|
132
|
+
this.contentNode.innerHTML = template;
|
|
133
|
+
|
|
134
|
+
// Set up the node properties of all of the arguments
|
|
135
|
+
this.arguments = newArguments;
|
|
136
|
+
for (let argumentName in newArguments) {
|
|
137
|
+
let argument = newArguments[argumentName];
|
|
138
|
+
argument._setNode(this._node.querySelectorAll(`.${this._classPrefix + argumentName}`)[0]);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Invalidate the intrinsic size upon the template being changed
|
|
142
|
+
this.invalidateIntrinsicSize();
|
|
143
|
+
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* An object that contains the arguments used by this attributed label view.
|
|
148
|
+
* This object's keys and values should not be modified; only the properties label view arguments themselves should be modified.
|
|
149
|
+
*/
|
|
150
|
+
arguments: undefined, // <Readonly<Dictionary<BMAttributedLabelViewArgument>>>
|
|
151
|
+
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Constructs and returns an attributed label view with the given template.
|
|
156
|
+
* @param template <String> The template to use for this label view.
|
|
157
|
+
* @param args <Dictionary<AnyObject>, nullable> An optional list of initial values to use for the placeholders.
|
|
158
|
+
* @return <BMAttributedLabelView> An attributed label view.
|
|
159
|
+
*/
|
|
160
|
+
BMAttributedLabelView.labelViewWithTemplate = function (template, args) {
|
|
161
|
+
let view = BMView.view.call(BMAttributedLabelView);
|
|
162
|
+
|
|
163
|
+
view._classPrefix = '';
|
|
164
|
+
view.template = template;
|
|
165
|
+
for (let argumentName in args) {
|
|
166
|
+
if (view.arguments[argumentName]) {
|
|
167
|
+
view.arguments[argumentName].value = args[argumentName];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return view;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Constructs and returns an attributed label view with the given template. The new view will use the given node.
|
|
176
|
+
* @param node <DOMNode> The node.
|
|
177
|
+
* {
|
|
178
|
+
* @param template <String> The template to use for this label view.
|
|
179
|
+
* @param contentNode <DOMNode, nullable> If set, this should be a descendant of the node property.
|
|
180
|
+
* This parameter represents the DOM node in which the attributed label view will insert its contents.
|
|
181
|
+
* @param arguments <Dictionary<AnyObject>, nullable> An optional list of initial values to use for the placeholders.
|
|
182
|
+
* }
|
|
183
|
+
* @return <BMAttributedLabelView> An attributed label view.
|
|
184
|
+
*/
|
|
185
|
+
BMAttributedLabelView.labelViewForNode = function (node, args) {
|
|
186
|
+
let view = BMView.viewForNode.call(BMAttributedLabelView, node);
|
|
187
|
+
|
|
188
|
+
view._contentNode = args.contentNode;
|
|
189
|
+
view._classPrefix = '';
|
|
190
|
+
view.template = args.template;
|
|
191
|
+
for (let argumentName in args.arguments) {
|
|
192
|
+
if (view.arguments[argumentName]) {
|
|
193
|
+
view.arguments[argumentName].value = args.arguments[argumentName];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return view;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// @endtype
|
|
201
|
+
|
|
202
|
+
// @type BMAttributedLabelViewArgument
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* An attributed label view argument manages the display of an argument of an attributed label view.
|
|
206
|
+
*
|
|
207
|
+
* Label view arguments cannot be created directly. They are always created and managed by an attributed label view.
|
|
208
|
+
*/
|
|
209
|
+
export function BMAttributedLabelViewArgument() {} // <constructor>
|
|
210
|
+
|
|
211
|
+
BMAttributedLabelViewArgument.prototype = {
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The attributed label view managing this argument.
|
|
215
|
+
*/
|
|
216
|
+
_view: undefined, // <BMAttributedLabelView>
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* This argument's name.
|
|
220
|
+
*/
|
|
221
|
+
_name: undefined, // <String>
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Represents this argument's index within the DOM hierarchy.
|
|
225
|
+
*/
|
|
226
|
+
_index: undefined, // <Number>
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The argument's current value. If this is set to a non-string value, its `toString()` method will be used
|
|
230
|
+
* to obtain a string representation.
|
|
231
|
+
* Changing this value will cause the intrinsic size of the associated label to be invalidated.
|
|
232
|
+
*/
|
|
233
|
+
_value: '', // <AnyObject>
|
|
234
|
+
get value() {
|
|
235
|
+
return this._value;
|
|
236
|
+
},
|
|
237
|
+
set value(value) {
|
|
238
|
+
value = (typeof value === 'undefined') ? '' : value;
|
|
239
|
+
if (value != this._value) {
|
|
240
|
+
this._value = value;
|
|
241
|
+
|
|
242
|
+
if (this._node) {
|
|
243
|
+
this._node.innerText = value;
|
|
244
|
+
|
|
245
|
+
// Invalidate the intrinsic size of the label view upon the value being changed
|
|
246
|
+
this._view.invalidateIntrinsicSize();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* An object containing the CSS styles that this argument should use.
|
|
253
|
+
* The object returned by this property should not be modified after being assigned, instead
|
|
254
|
+
* modifications should be performed by creating and setting a new object for this property.
|
|
255
|
+
* Changing this value will cause the intrinsic size of the associated label to be invalidated.
|
|
256
|
+
*/
|
|
257
|
+
_style: undefined, // <Readonly<Dictionary<String>>, nullable>
|
|
258
|
+
get style() {
|
|
259
|
+
return this._style;
|
|
260
|
+
},
|
|
261
|
+
set style(style) {
|
|
262
|
+
if (!this._node) {
|
|
263
|
+
this._style = style || {};
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// If the style is undefined, revert to an empty object
|
|
268
|
+
style = style || {};
|
|
269
|
+
|
|
270
|
+
// Clear the previous styles from the node; this is to prevent older styles from affecting the argument
|
|
271
|
+
// if they don't exist in the new style
|
|
272
|
+
if (this._style) {
|
|
273
|
+
for (let key in this._style) {
|
|
274
|
+
if (!(key in style)) this._node.style.removeProperty(key);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Then add the new styles
|
|
279
|
+
this._style = style;
|
|
280
|
+
for (let key in this._style) {
|
|
281
|
+
this._node.style[key] = this._style[key];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Invalidate the intrinsic size of the label view upon the style being changed as it can affect layout
|
|
285
|
+
this._view.invalidateIntrinsicSize();
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The DOM node managed by this argument.
|
|
290
|
+
*/
|
|
291
|
+
_node: undefined, // <DOMNode>
|
|
292
|
+
get node() {
|
|
293
|
+
return this._node;
|
|
294
|
+
},
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Used internally by CoreUI to assign a node to this argument.
|
|
298
|
+
* @param node <DOMNode> The node.
|
|
299
|
+
*/
|
|
300
|
+
_setNode: function (node) {
|
|
301
|
+
this._node = node;
|
|
302
|
+
|
|
303
|
+
// Set up the value and styles
|
|
304
|
+
node.innerText = this._value;
|
|
305
|
+
BMCopyProperties(node.style, this._style || {});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// @endtype
|