nice-elements 1.13.6 → 1.13.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nice-elements",
3
- "version": "1.13.6",
3
+ "version": "1.13.8",
4
4
  "description": "Nice elements used in olaii angular 1.x webapps.",
5
5
  "main": "dist/nice.js",
6
6
  "license": "MIT",
@@ -332,7 +332,10 @@ angular.module('niceElements')
332
332
 
333
333
 
334
334
  // ------------------ Watch for model change ------------------
335
- $scope.$watchGroup(["model", 'minDate', 'maxDate', 'nextDate'], function () {
335
+ // Watch timestamp so in-place moment mutations (e.g. model.add(1, "day")) are detected too
336
+ $scope.$watchGroup([function () {
337
+ return $scope.model ? moment($scope.model).valueOf() : $scope.model;
338
+ }, 'minDate', 'maxDate', 'nextDate'], function () {
336
339
  $scope.bootstrap();
337
340
  });
338
341
 
@@ -1,4 +1,11 @@
1
- <ng-form class="nice-component nice-input" ng-class="{ 'margin-bottom-0' : noMargin, 'nice-component-inline': isInline }" name="forma">
1
+ <ng-form
2
+ class="nice-component nice-input"
3
+ ng-class="[
4
+ 'nice-input-type-' + type,
5
+ { 'margin-bottom-0' : noMargin, 'nice-component-inline': isInline }
6
+ ]"
7
+ name="forma"
8
+ >
2
9
  <div class="row">
3
10
  <!------------------------- Title ------------------------->
4
11
  <nice-title text="title || niceTitle" help="help" required="required" description="description" label-width="labelWidth"></nice-title>
@@ -45,7 +45,7 @@ angular.module('niceElements')
45
45
  autocomplete: "@?",
46
46
  disableTrim: "@?"
47
47
  },
48
- controller: function ($scope, $attrs, $rootScope, $element, ngDialog) {
48
+ controller: function ($scope, $attrs, $rootScope, $element, ngDialog, NiceService) {
49
49
  if (!$attrs.type) { $attrs.type = 'text'; }
50
50
  if (!$attrs.title) { $attrs.title = ''; }
51
51
  if (!$attrs.regex) { $attrs.regex = null; }
@@ -83,6 +83,9 @@ angular.module('niceElements')
83
83
  $scope.inputMode = "numeric";
84
84
  }
85
85
 
86
+ // Decimal.js model is kept as Decimal (same constructor), input works with string
87
+ $scope.decimalConstructor = NiceService.isDecimal($scope.model) ? $scope.model.constructor : null;
88
+
86
89
  // Set internal type
87
90
  $scope.internalType = $scope.type;
88
91
  if ($scope.type == "percent") {
@@ -92,7 +95,9 @@ angular.module('niceElements')
92
95
  } else if ($scope.type == "number") {
93
96
  $scope.internalType = "text";
94
97
  $scope.inputMode = "decimal";
95
- if ($scope.model != null) {
98
+ if ($scope.decimalConstructor) {
99
+ // Keep Decimal
100
+ } else if ($scope.model != null) {
96
101
  $scope.model = Number($scope.model);
97
102
  } else {
98
103
  $scope.model = null;
@@ -103,8 +108,7 @@ angular.module('niceElements')
103
108
  $scope.model = Number($scope.model);
104
109
  } else if ($scope.type == "email") {
105
110
  $scope.inputMode = "email";
106
- // TODO: get rid of the errors
107
- $scope.regexexp = new RegExp('^[_a-zA-Z0-9]+(.[_a-zA-Z0-9]+)*@[a-zA-Z0-9]+(.[a-zA-Z0-9]+)+(.[a-zA-Z]{2,4})');
111
+ $scope.regexexp = new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$");
108
112
  } else {
109
113
  $scope.internalType = "text";
110
114
  }
@@ -113,7 +117,7 @@ angular.module('niceElements')
113
117
  $scope.valid = $scope.forma;
114
118
  }
115
119
 
116
- if ($scope.model && angular.isDefined($scope.minDecimalsCutZeros) && $scope.type == 'number') {
120
+ if ($scope.model && !$scope.decimalConstructor && angular.isDefined($scope.minDecimalsCutZeros) && $scope.type == 'number') {
117
121
  $scope.model = Number($scope.model);
118
122
  if ($scope.model.toString().split('.').length < 2 || $scope.model.toString().split('.')[1].length < parseInt($scope.minDecimalsCutZeros)) {
119
123
  $scope.model = Number((Number($scope.model)).toFixed(parseInt($scope.minDecimalsCutZeros)));
@@ -129,9 +133,18 @@ angular.module('niceElements')
129
133
  }
130
134
 
131
135
  $scope.$watch('model', function (value_new, value_old) {
132
- if ($scope.type == "number" && value_old && value_old[value_old.length - 1] == ".") {
136
+ if ($scope.type == "number" && NiceService.isDecimal($scope.model)) {
137
+ $scope.decimalConstructor = $scope.model.constructor;
138
+ // Don't overwrite what user is typing (e.g. "1." or "1.50") if it has the same value
139
+ const internal = NiceService.parseDecimal($scope.internalModel, $scope.decimalConstructor);
140
+ if (!internal || !internal.equals($scope.model)) {
141
+ $scope.internalModel = $scope.model.toFixed();
142
+ }
143
+ } else if ($scope.type == "number" && value_old && value_old[value_old.length - 1] == ".") {
133
144
  // IGNORE
134
145
  } else {
146
+ // Parent switched to plain value (null keeps Decimal, e.g. cleared input)
147
+ if ($scope.model != null) $scope.decimalConstructor = null;
135
148
  $scope.internalModel = angular.copy($scope.model);
136
149
  }
137
150
 
@@ -142,7 +155,19 @@ angular.module('niceElements')
142
155
  });
143
156
 
144
157
  $scope.$watch('internalModel', function (value_new, value_old) {
145
- if ($scope.type == "number" && value_new) {
158
+ if ($scope.type == "number" && $scope.decimalConstructor) {
159
+ if (angular.isString(value_new) && value_new.indexOf(',') >= 0) {
160
+ $scope.internalModel = value_new.replace(',', '.');
161
+ return;
162
+ }
163
+ const value = NiceService.parseDecimal(value_new, $scope.decimalConstructor);
164
+ if (value === undefined) return; // Incomplete number, e.g. "-"
165
+ const isSame = value === null ? $scope.model == null : NiceService.isDecimal($scope.model) && value.equals($scope.model);
166
+ if (!isSame) {
167
+ $scope.model = value;
168
+ $scope.handleChange();
169
+ }
170
+ } else if ($scope.type == "number" && value_new) {
146
171
  if (typeof value_new != "number") {
147
172
  $scope.internalModel = value_new.replace(',', '.');
148
173
  $scope.model = angular.copy($scope.internalModel);
@@ -220,16 +245,18 @@ angular.module('niceElements')
220
245
 
221
246
  if ($scope.type == "decimal" || $scope.type == "number" || $scope.type == "integer") {
222
247
  // Handle decimal numbers
223
- if ($scope.type == "number" || $scope.type == "decimal") {
248
+ if (($scope.type == "number" || $scope.type == "decimal") && !$scope.decimalConstructor) {
224
249
  $scope.model = String($scope.model).replace(",", "."); // Replace , with .
225
250
  if (isNaN($scope.model)) { // If parsed float is NaN
226
251
  $scope.model = String(parseFloat($scope.model) || "");
227
252
  }
228
253
  }
254
+ // Decimal model isn't a string, check the typed value instead
255
+ const current = $scope.decimalConstructor ? String($scope.internalModel != null ? $scope.internalModel : "") : String($scope.model);
229
256
 
230
257
  if (event.charCode == 46 || event.charCode == 44) { // Handle "." and "," key (only one allowed)
231
258
  if ($scope.type == "number" || $scope.type == "decimal") {
232
- if (String($scope.model).indexOf(".") >= 0) {
259
+ if (current.indexOf(".") >= 0) {
233
260
  event.preventDefault();
234
261
  return false;
235
262
  }
@@ -238,7 +265,7 @@ angular.module('niceElements')
238
265
  return false;
239
266
  }
240
267
  } else if (event.charCode == 45) {
241
- if (String($scope.model).indexOf("-") >= 0) {
268
+ if (current.indexOf("-") >= 0) {
242
269
  event.preventDefault();
243
270
  return false;
244
271
  }
@@ -46,6 +46,17 @@
46
46
  border-right: 1px solid var(--nice-border-color) !important;
47
47
  }
48
48
 
49
+ &.nice-input-type-number {
50
+ input {
51
+ padding-right: 0;
52
+ }
53
+
54
+ .input-group-addon {
55
+ line-height: 31px;
56
+ padding-left: 4px;
57
+ }
58
+ }
59
+
49
60
 
50
61
  .input-group {
51
62
  margin-bottom: 0px;
@@ -1,4 +1,11 @@
1
- <div class="nice-component nice-number" ng-form="niceNumberForm" ng-class="{ 'margin-bottom-0' : noMargin, 'nice-component-inline': isInline }">
1
+ <div
2
+ class="nice-component nice-number"
3
+ ng-form="niceNumberForm"
4
+ ng-class="[{
5
+ 'margin-bottom-0' : noMargin,
6
+ 'nice-component-inline': isInline
7
+ }]"
8
+ >
2
9
  <div ng-class="{'row' : !disableRow}">
3
10
  <!------------------------- Title ------------------------->
4
11
  <nice-title text="title || niceTitle" help="help" required="required" description="description" label-width="labelWidth"></nice-title>
@@ -7,15 +14,39 @@
7
14
  <div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
8
15
  <div class="input-group" ng-class="{'has-warning': !isDisabled && niceNumberForm.$invalid && niceNumberForm.$dirty}">
9
16
  <span class="input-group-btn">
10
- <button type="button" class="btn btn-default btn-left" ng-disabled="!canSubtract || isDisabled" ng-click="subtract()" tabindex="-1">
17
+ <!-- Subtract -->
18
+ <button
19
+ type="button"
20
+ class="btn btn-default btn-left"
21
+ ng-disabled="!canSubtract || isDisabled"
22
+ ng-click="subtract()"
23
+ tabindex="-1
24
+ ">
11
25
  <nice-icon icon="icon-minus"></nice-icon>
12
26
  </button>
13
27
  </span>
14
28
 
15
- <input type="number" step="{{ step }}" ng-change="inputChanged()" class="form-control" max="{{ max }}" min="{{ min }}" ng-disabled="isDisabled" ng-model="model" />
29
+ <!-- Value -->
30
+ <input
31
+ type="number"
32
+ step="{{ step }}"
33
+ ng-change="inputChanged()"
34
+ class="form-control"
35
+ max="{{ max }}"
36
+ min="{{ min }}"
37
+ ng-disabled="isDisabled"
38
+ ng-model="internal.value"
39
+ />
16
40
 
17
41
  <span class="input-group-btn">
18
- <button type="button" class="btn btn-default btn-right" ng-disabled="!canAdd || isDisabled" ng-click="add()" tabindex="-1">
42
+ <!-- Add -->
43
+ <button
44
+ type="button"
45
+ class="btn btn-default btn-right"
46
+ ng-disabled="!canAdd || isDisabled"
47
+ ng-click="add()"
48
+ tabindex="-1"
49
+ >
19
50
  <nice-icon icon="icon-plus"></nice-icon>
20
51
  </button>
21
52
  </span>
@@ -36,7 +36,7 @@ angular.module('niceElements')
36
36
  onChange: '&?'
37
37
  },
38
38
 
39
- controller: function ($scope, $timeout) {
39
+ controller: function ($scope, $timeout, NiceService) {
40
40
  $scope.canAdd = true;
41
41
  $scope.canSubtract = true;
42
42
  $scope.preventZero = $scope.preventZero == "true";
@@ -75,8 +75,13 @@ angular.module('niceElements')
75
75
  if ($scope.innerStep == "any") $scope.innerStep = 1; // Fix step any
76
76
  if (Number.isNaN($scope.innerStep)) $scope.innerStep = 1; // Fix step any
77
77
 
78
+ // Decimal.js model is kept as Decimal (same constructor), input works with number
79
+ $scope.decimalConstructor = NiceService.isDecimal($scope.model) ? $scope.model.constructor : null;
80
+
78
81
  // Check if number is defined
79
- if (!$scope.model) {
82
+ if ($scope.decimalConstructor) {
83
+ // Keep Decimal
84
+ } else if (!$scope.model) {
80
85
  $scope.model = $scope.defaultValue;
81
86
  } else {
82
87
  if (parseFloat($scope.model)) {
@@ -126,14 +131,42 @@ angular.module('niceElements')
126
131
  });
127
132
 
128
133
 
134
+ // Input model. <input type="number"> needs a number, so Decimal model is converted.
135
+ const toInternal = function (value) {
136
+ return NiceService.isDecimal(value) ? value.toNumber() : value;
137
+ };
138
+
139
+ const setModel = function (value) {
140
+ if ($scope.decimalConstructor && value != null && !NiceService.isDecimal(value)) {
141
+ value = new $scope.decimalConstructor(value);
142
+ }
143
+ $scope.model = value;
144
+ };
145
+
146
+ $scope.internal = {
147
+ value: toInternal($scope.model)
148
+ };
149
+
150
+
129
151
  // On input change
130
152
  $scope.inputChanged = function () {
153
+ setModel($scope.internal.value);
131
154
  $scope.check();
132
155
  };
133
156
 
134
157
 
135
- // Watch for model change
136
- $scope.$watch("model", function (oldModel, newModel) {
158
+ // Watch for model change. Decimal is watched by value, because parent can replace it with new equal object.
159
+ $scope.$watch(function () {
160
+ return NiceService.isDecimal($scope.model) ? $scope.model.toString() : $scope.model;
161
+ }, function (oldModel, newModel) {
162
+ if (NiceService.isDecimal($scope.model)) {
163
+ $scope.decimalConstructor = $scope.model.constructor;
164
+ } else if ($scope.model != null) {
165
+ $scope.decimalConstructor = null; // Parent switched to plain value
166
+ }
167
+ if (toInternal($scope.model) !== $scope.internal.value) {
168
+ $scope.internal.value = toInternal($scope.model);
169
+ }
137
170
  $scope.check();
138
171
  if ($scope.onChange && oldModel != newModel) {
139
172
  $timeout(function () {
@@ -148,11 +181,11 @@ angular.module('niceElements')
148
181
  const result = new Decimal($scope.model != undefined ? $scope.model : $scope.defaultValue).plus($scope.innerStep).toNumber(); //.toFixed($scope.decimals);
149
182
  if ($scope.max) {
150
183
  if (result <= parseFloat($scope.max)) {
151
- $scope.model = result;
184
+ setModel(result);
152
185
  $scope.niceNumberForm.$setDirty();
153
186
  }
154
187
  } else {
155
- $scope.model = result;
188
+ setModel(result);
156
189
  $scope.niceNumberForm.$setDirty();
157
190
  }
158
191
  $scope.check();
@@ -163,7 +196,7 @@ angular.module('niceElements')
163
196
  $scope.subtract = function () {
164
197
  const result = new Decimal($scope.model != undefined ? $scope.model : $scope.defaultValue).minus($scope.innerStep).toNumber();
165
198
  if (result >= Number($scope.min)) {
166
- $scope.model = result;
199
+ setModel(result);
167
200
  $scope.niceNumberForm.$setDirty();
168
201
  }
169
202
  $scope.check();
@@ -1,4 +1,17 @@
1
- <div class="nice-component nice-toggle" ng-class="{ 'margin-bottom-0': noMargin, 'title-right': titleRight, 'nice-component-inline': isInline, 'nice-component-block': isBlock, 'active': inverted ? !model : model }" ng-form="formToggle">
1
+ <div
2
+ class="nice-component nice-toggle"
3
+ ng-class="[
4
+ 'nice-toggle-' + type,
5
+ {
6
+ 'margin-bottom-0': noMargin,
7
+ 'title-right': titleRight,
8
+ 'nice-component-inline': isInline,
9
+ 'nice-component-block': isBlock,
10
+ 'active': inverted ? !model : model
11
+ }
12
+ ]"
13
+ ng-form="formToggle"
14
+ >
2
15
  <div class="row">
3
16
  <!------------------------- Title ------------------------->
4
17
  <nice-title text="title || niceTitle" help="help" required="required" description="description" description="description" label-width="labelWidth"></nice-title>
@@ -6,7 +19,10 @@
6
19
  <!------------------------- Field ------------------------->
7
20
  <div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
8
21
  <button type="button" class="nice-toggle-field" ng-click="toggle()" ng-disabled="isDisabled">
9
- <div class="nice-toggle-field-handle">{{ state }}</div>
22
+ <div class="nice-toggle-field-handle">
23
+ <nice-icon ng-if="showIcons && model" icon="icon-check"></nice-icon>
24
+ <nice-icon ng-if="showIcons && !model" icon="icon-x"></nice-icon>
25
+ </div>
10
26
  </button>
11
27
  </div>
12
28
  </div>
@@ -26,12 +26,15 @@ angular.module('niceElements')
26
26
  titleRight: '=',
27
27
  help: '@',
28
28
  required: '=',
29
- inverted: '='
29
+ inverted: '=',
30
+ showIcons: '=',
31
+ type: '@?'
30
32
  },
31
33
  controller: function ($scope, $timeout) {
32
34
  if (!$scope.title) { $scope.title = ''; }
33
35
  if (!$scope.fieldWidth) { $scope.fieldWidth = 'col-sm-8'; }
34
36
  if (!$scope.labelWidth) { $scope.labelWidth = 'col-sm-4'; }
37
+ if (!$scope.type) { $scope.type = 'default'; }
35
38
  if (!angular.isDefined($scope.model)) $scope.model = false;
36
39
 
37
40
  // ------------------------- Switch -------------------------
@@ -96,6 +96,17 @@
96
96
  background: var(--nice-border-color);
97
97
  border-radius: 50%;
98
98
  transition: all 0.3s ease-in-out;
99
+
100
+ display: flex;
101
+ flex-direction: column;
102
+ justify-content: center;
103
+ align-items: center;
104
+
105
+ .nice-icon {
106
+ color: var(--nice-input-bg);
107
+ height: 14px;
108
+ width: 14px;
109
+ }
99
110
  }
100
111
  }
101
112
 
@@ -106,7 +117,27 @@
106
117
  .nice-toggle-field-handle {
107
118
  background: var(--nice-input-bg);
108
119
  left: calc(100% - 22px);
120
+
121
+ .nice-icon {
122
+ color: var(--nice-primary-color);
123
+ }
109
124
  }
125
+
126
+ }
127
+
128
+ &.nice-toggle-success {
129
+ .nice-toggle-field { background: var(--nice-success-color); }
130
+ .nice-toggle-field-handle { .nice-icon { color: var(--nice-success-color); }}
131
+ }
132
+
133
+ &.nice-toggle-danger {
134
+ .nice-toggle-field { background: var(--nice-danger-color); }
135
+ .nice-toggle-field-handle { .nice-icon { color: var(--nice-danger-color); }}
136
+ }
137
+
138
+ &.nice-toggle-warning {
139
+ .nice-toggle-field { background: var(--nice-warning-color); }
140
+ .nice-toggle-field-handle { .nice-icon { color: var(--nice-warning-color); }}
110
141
  }
111
142
  }
112
143
 
@@ -16,8 +16,15 @@
16
16
  }
17
17
  }
18
18
 
19
+ // Header / footer borders are driven by the body scroll position
20
+ timeline-scope: --nice-view-scroll;
21
+
19
22
  .nice-view-header {
20
23
  flex-shrink: 0;
24
+ border-bottom: 1px solid transparent;
25
+ animation: nice-view-header-border linear both;
26
+ animation-timeline: --nice-view-scroll;
27
+ animation-range: 0 1rem;
21
28
  padding: var(--nice-view-padding);
22
29
  padding-bottom: calc(var(--nice-view-padding) / 2);
23
30
 
@@ -48,11 +55,16 @@
48
55
  .nice-view-body {
49
56
  flex-grow: 1;
50
57
  overflow: auto;
58
+ scroll-timeline: --nice-view-scroll block;
51
59
  padding: var(--nice-view-padding);
52
60
  }
53
61
 
54
62
  .nice-view-footer {
55
63
  flex-shrink: 0;
64
+ border-top: 1px solid transparent;
65
+ animation: nice-view-footer-border linear both;
66
+ animation-timeline: --nice-view-scroll;
67
+ animation-range: calc(100% - 1rem) 100%;
56
68
  padding: var(--nice-view-padding);
57
69
  padding-top: calc(var(--nice-view-padding) / 2);
58
70
  }
@@ -61,3 +73,13 @@
61
73
  --nice-view-padding: 1rem;
62
74
  }
63
75
  }
76
+
77
+ @keyframes nice-view-header-border {
78
+ from { border-bottom-color: transparent; }
79
+ to { border-bottom-color: var(--nice-border-color); }
80
+ }
81
+
82
+ @keyframes nice-view-footer-border {
83
+ from { border-top-color: var(--nice-border-color); }
84
+ to { border-top-color: transparent; }
85
+ }
@@ -10,12 +10,25 @@ angular.module('niceElements')
10
10
  .service('NiceService', function ($rootScope) {
11
11
  const service = {
12
12
  name: "Nice elements",
13
- version: "1.13.6",
13
+ version: "1.13.8",
14
14
  getHeader: function () {
15
15
  return {};
16
16
  },
17
17
  toast: function (message, type) {
18
18
  $rootScope.$broadcast('toast', message, type);
19
+ },
20
+ // Check if value is a Decimal.js object (also Decimal.clone() instances)
21
+ isDecimal: function (value) {
22
+ return typeof Decimal !== 'undefined' && Decimal.isDecimal(value);
23
+ },
24
+ // Parse input value with Decimal constructor. Returns null for empty and undefined for invalid input (e.g. "-")
25
+ parseDecimal: function (value, DecimalConstructor) {
26
+ if (value === null || value === undefined || value === '') return null;
27
+ try {
28
+ return new DecimalConstructor(String(value).replace(',', '.'));
29
+ } catch (e) {
30
+ return undefined;
31
+ }
19
32
  }
20
33
  };
21
34