@mediafly/js-ui 51.3.2-1 → 51.3.3-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.
Files changed (40) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/constants/constants.js +2 -1
  3. package/lib/constants/constants.js.map +1 -1
  4. package/lib/date-input/date-input.js +33 -12
  5. package/lib/date-input/date-input.js.map +1 -1
  6. package/lib/date-input/validate-date.js +12 -8
  7. package/lib/date-input/validate-date.js.map +1 -1
  8. package/lib/date-time-zone-picker/date-time-zone-factory.js +62 -49
  9. package/lib/date-time-zone-picker/date-time-zone-factory.js.map +1 -1
  10. package/lib/date-time-zone-picker/date-time-zone-picker.html +1 -1
  11. package/lib/date-time-zone-picker/date-time-zone-picker.js +82 -37
  12. package/lib/date-time-zone-picker/date-time-zone-picker.js.map +1 -1
  13. package/lib/date-time-zone-picker/datepicker.html +1 -2
  14. package/lib/date-time-zone-picker/datepicker.js +71 -19
  15. package/lib/date-time-zone-picker/datepicker.js.map +1 -1
  16. package/lib/date-time-zone-picker/time-format-filter.js +6 -6
  17. package/lib/date-time-zone-picker/time-format-filter.js.map +1 -1
  18. package/lib/date-time-zone-picker/timepicker.js +35 -20
  19. package/lib/date-time-zone-picker/timepicker.js.map +1 -1
  20. package/lib/time-input/time-input.js +27 -23
  21. package/lib/time-input/time-input.js.map +1 -1
  22. package/lib/time-input/validate-time.js +6 -2
  23. package/lib/time-input/validate-time.js.map +1 -1
  24. package/lib/tsconfig.deploy.tsbuildinfo +166 -24
  25. package/package.json +4 -4
  26. package/src/components/constants/constants.js +2 -1
  27. package/src/components/date-input/date-input.js +31 -12
  28. package/src/components/date-input/validate-date.js +14 -10
  29. package/src/components/date-time-zone-picker/date-time-zone-factory.ts +62 -49
  30. package/src/components/date-time-zone-picker/date-time-zone-picker.html +1 -1
  31. package/src/components/date-time-zone-picker/date-time-zone-picker.ts +87 -44
  32. package/src/components/date-time-zone-picker/datepicker.html +1 -2
  33. package/src/components/date-time-zone-picker/datepicker.ts +76 -20
  34. package/src/components/date-time-zone-picker/time-format-filter.ts +6 -6
  35. package/src/components/date-time-zone-picker/timepicker.js +46 -28
  36. package/src/components/time-input/time-input.js +27 -24
  37. package/src/components/time-input/validate-time.js +6 -2
  38. package/src/index.spec.js +1 -1
  39. package/webpack.config.js +6 -0
  40. package/tsconfig.tsbuildinfo +0 -7221
@@ -1,8 +1,8 @@
1
1
  import angular from 'angular'
2
2
  import template from './timepicker.html'
3
- import moment from 'moment'
3
+ const { DateTime } = require('luxon')
4
4
 
5
- angular.module('app').directive('mflyTimePicker', ['translateFactory', function mflyTimePicker (translateFactory) {
5
+ angular.module('app').directive('mflyTimePicker', ['translateFactory', function mflyTimePicker(translateFactory) {
6
6
 
7
7
  return {
8
8
  restrict: 'E',
@@ -13,13 +13,15 @@ angular.module('app').directive('mflyTimePicker', ['translateFactory', function
13
13
  onTimeChange: '&'
14
14
  },
15
15
  template,
16
- link: function($scope) {
16
+ link: function ($scope) {
17
17
  var validTimeFormats = [
18
18
  'h:mm',
19
19
  'h:mm A',
20
20
  'h:mmA'
21
21
  ];
22
22
 
23
+ const luxonFormats = ['H:mm', 'h:mm a', 'h:mma'];
24
+
23
25
  $scope.timeValue = {
24
26
  time: '',
25
27
  initialized: false
@@ -34,13 +36,23 @@ angular.module('app').directive('mflyTimePicker', ['translateFactory', function
34
36
  // programmatically, we need to update the time picker accordingly.
35
37
  $scope.$watch('timeMoment', function (newValue) {
36
38
  if (newValue) {
37
- $scope.timeValue.time = $scope.timeMoment.format('h:mm A');
39
+ $scope.timeValue.time = $scope.timeMoment.toFormat('h:mm a');
38
40
  }
39
41
  });
40
42
 
41
- $scope.validateTime = function() {
43
+ $scope.validateTime = function () {
42
44
  if ($scope.timeValue.time) {
43
- var isValid = moment($scope.timeValue.time, validTimeFormats, true).isValid();
45
+ var isValid = false;
46
+
47
+ // Try each format until one works
48
+ for (const format of luxonFormats) {
49
+ const parsed = DateTime.fromFormat($scope.timeValue.time, format);
50
+ if (parsed.isValid) {
51
+ isValid = true;
52
+ break;
53
+ }
54
+ }
55
+
44
56
  $scope.form.validation.mflyTimepicker.$setValidity('invalidTime', isValid);
45
57
  if (isValid) {
46
58
  processTime();
@@ -51,13 +63,13 @@ angular.module('app').directive('mflyTimePicker', ['translateFactory', function
51
63
  }
52
64
  };
53
65
 
54
- //watch necessary to style preceeding add-on element (CSS has no prev sibling selector)
55
- $scope.$watch('form.validation.mflyTimepicker', function(newValue){
66
+ //watch necessary to style preceding add-on element (CSS has no prev sibling selector)
67
+ $scope.$watch('form.validation.mflyTimepicker', function (newValue) {
56
68
  if (newValue) {
57
- $scope.$watch('form.validation.mflyTimepicker.$valid', function(newValue){
69
+ $scope.$watch('form.validation.mflyTimepicker.$valid', function (newValue) {
58
70
  $scope.invalidAddOn = !newValue;
59
71
  });
60
- $scope.$watch('form.validation.mflyTimepicker.$dirty', function(newValue){
72
+ $scope.$watch('form.validation.mflyTimepicker.$dirty', function (newValue) {
61
73
  $scope.dirtyAddOn = newValue;
62
74
  });
63
75
  }
@@ -65,11 +77,18 @@ angular.module('app').directive('mflyTimePicker', ['translateFactory', function
65
77
 
66
78
  function processTime() {
67
79
  if ($scope.timeValue.time && $scope.form.validation.mflyTimepicker.$valid) {
68
- //update our time moment with the time change in the textbox
69
- var tempMomemnt = moment($scope.timeValue.time, validTimeFormats, true);
80
+ let tempDateTime;
81
+ for (const format of luxonFormats) {
82
+ tempDateTime = DateTime.fromFormat($scope.timeValue.time, format);
83
+ if (tempDateTime.isValid) break;
84
+ }
70
85
 
71
- $scope.timeMoment.hour(tempMomemnt.hour());
72
- $scope.timeMoment.minute(tempMomemnt.minute());
86
+ $scope.timeMoment = $scope.timeMoment.set({
87
+ hour: tempDateTime.hour,
88
+ minute: tempDateTime.minute,
89
+ second: 0,
90
+ millisecond: 0,
91
+ });
73
92
 
74
93
  //callback to the parent component
75
94
  $scope.onTimeChange();
@@ -81,29 +100,28 @@ angular.module('app').directive('mflyTimePicker', ['translateFactory', function
81
100
  }
82
101
 
83
102
 
84
- function populateDropdown(){
103
+ function populateDropdown() {
85
104
  if ($scope.timeMoment) {
86
- $scope.timeValue.time = $scope.timeMoment.format('hh:mm A');
105
+ $scope.timeValue.time = $scope.timeMoment.toFormat('hh:mm a');
87
106
  }
88
107
 
89
- //init a moment with todays date
90
- var tempMoment = moment();
91
- //store that date in a seperate value
92
- var todaysDate = tempMoment.date();
108
+ // Populate the drop down with available times
109
+ var tempDateTime = DateTime.now().startOf('day');
110
+
111
+ var todaysDate = tempDateTime.day;
93
112
 
94
- //backup our moment to 12:00am
95
- tempMoment.hour(0);
96
- tempMoment.minute(0);
113
+ // Starting from 12:00 am
114
+ tempDateTime = tempDateTime.set({ hour: 0, minute: 0, second: 0, millisecond: 0 });
97
115
 
98
- //push 30 min intervals into our dropdown array until the date changes
116
+ // Add a time entry on every 30 minutes
99
117
  do {
100
- $scope.dropdownItems.push(tempMoment.format('hh:mm A'));
101
- tempMoment.add(30, 'm');
102
- } while (todaysDate === tempMoment.date());
118
+ $scope.dropdownItems.push(tempDateTime.toFormat('hh:mm a'));
119
+ tempDateTime = tempDateTime.plus({ minutes: 30 });
120
+ } while (todaysDate === tempDateTime.day);
103
121
  }
104
122
 
105
123
 
106
- $scope.itemClicked = function(itemValue){
124
+ $scope.itemClicked = function (itemValue) {
107
125
  $scope.form.validation.mflyTimepicker.$setDirty();
108
126
  $scope.timeValue.time = itemValue;
109
127
  $scope.validateTime();
@@ -1,6 +1,6 @@
1
1
  import angular from 'angular'
2
2
  import template from './time-input.html'
3
- import moment from 'moment'
3
+ const { DateTime } = require('luxon')
4
4
 
5
5
 
6
6
  angular.module('app').directive('mflyTimeInput', [
@@ -28,13 +28,6 @@ angular.module('app').directive('mflyTimeInput', [
28
28
  // ----------------------------------------
29
29
  $scope.vm = {};
30
30
 
31
- // See: https://momentjs.com/docs/#/parsing/string-format/
32
- var validTimeFormats = [
33
- 'H:mm',
34
- 'h:mm A',
35
- 'h:mmA'
36
- ];
37
-
38
31
  // Format the ng-model value as a time string.
39
32
  // The result of this function is assigned to `ngModelCtrl.$viewValue`.
40
33
  ngModelCtrl.$formatters.push(function (nativeDate) {
@@ -43,7 +36,7 @@ angular.module('app').directive('mflyTimeInput', [
43
36
  return '';
44
37
  }
45
38
 
46
- return moment(nativeDate).format('h:mm A');
39
+ return DateTime.fromJSDate(nativeDate).toFormat('h:mm a');
47
40
  });
48
41
 
49
42
  // Display the time string in the UI.
@@ -67,15 +60,25 @@ angular.module('app').directive('mflyTimeInput', [
67
60
  // component of "today". If a model value exists, we need to set the
68
61
  // outgoing date object's date part back to the original model value
69
62
  // since the user did not intend to change that part.
70
- var targetMoment = moment(viewValue, validTimeFormats, true);
63
+ let targetDateTime;
64
+ const luxonFormats = ['H:mm', 'h:mm a', 'h:mma'];
65
+
66
+ // Try each format until one works
67
+ for (const format of luxonFormats) {
68
+ targetDateTime = DateTime.fromFormat(viewValue, format);
69
+ if (targetDateTime.isValid) break;
70
+ }
71
71
 
72
72
  if (ngModelCtrl.$modelValue) {
73
- var modelMoment = moment(ngModelCtrl.$modelValue);
74
- targetMoment.year(modelMoment.year());
75
- targetMoment.dayOfYear(modelMoment.dayOfYear());
73
+ const modelDateTime = DateTime.fromJSDate(ngModelCtrl.$modelValue);
74
+ targetDateTime = targetDateTime.set({
75
+ year: modelDateTime.year,
76
+ month: modelDateTime.month,
77
+ day: modelDateTime.day
78
+ });
76
79
  }
77
80
 
78
- return targetMoment.toDate();
81
+ return targetDateTime.toJSDate();
79
82
  });
80
83
 
81
84
  // When the user input changes the scope model, push it through the
@@ -91,15 +94,15 @@ angular.module('app').directive('mflyTimeInput', [
91
94
 
92
95
  // Time dropdown
93
96
  // ----------------------------------------
94
- var beginningOfToday = moment().hour(0).minute(0).second(0);
95
- var timeCursor = moment(beginningOfToday);
97
+ const beginningOfToday = DateTime.now().startOf('day');
98
+ let timeCursor = beginningOfToday;
96
99
  $scope.dropdownEntries = [];
97
100
 
98
101
  // Populate time entries for all 30-min intervals on today's date
99
102
  do {
100
- $scope.dropdownEntries.push(timeCursor.format('h:mm A'));
101
- timeCursor.add(30, 'minutes');
102
- } while (timeCursor.date() === beginningOfToday.date());
103
+ $scope.dropdownEntries.push(timeCursor.toFormat('h:mm a'));
104
+ timeCursor = timeCursor.plus({ minutes: 30 });
105
+ } while (timeCursor.day === beginningOfToday.day);
103
106
 
104
107
  // When a time is clicked, update the view model
105
108
  $scope.setTime = function (timeString) {
@@ -123,15 +126,15 @@ angular.module('app').directive('mflyTimeInput', [
123
126
  function entriesForTime (time) {
124
127
 
125
128
  // Find the number of minutes until our target time.
126
- var target = moment(time);
127
- var midnight = moment(target).hour(0).minute(0).second(0);
128
- var minutesFromMidnight = target.diff(midnight, 'minutes');
129
+ const target = DateTime.fromJSDate(time);
130
+ const midnight = target.startOf('day');
131
+ const minutesFromMidnight = target.diff(midnight, 'minutes').minutes;
129
132
 
130
133
  // Round up to the next 30 minute interval.
131
- minutesFromMidnight = Math.ceil((minutesFromMidnight + 1) / 30) * 30;
134
+ const roundedMinutes = Math.ceil((minutesFromMidnight + 1) / 30) * 30;
132
135
 
133
136
  // Divide by 30 to get number of places we should scroll down.
134
- return minutesFromMidnight / 30;
137
+ return roundedMinutes / 30;
135
138
  }
136
139
 
137
140
  // If `dropdownDefault` is specified by the consumer, we should
@@ -1,5 +1,5 @@
1
1
  import angular from 'angular'
2
- import moment from 'moment'
2
+ const { DateTime } = require('luxon')
3
3
 
4
4
  angular.module('app').directive('mflyValidateTime', function mflyValidateTime () {
5
5
 
@@ -19,7 +19,11 @@ angular.module('app').directive('mflyValidateTime', function mflyValidateTime ()
19
19
  return true;
20
20
  }
21
21
 
22
- return moment(viewValue, validTimeFormats, true).isValid();
22
+ // Check if the time is valid according to the given formats
23
+ return validTimeFormats.some(format => {
24
+ const parsed = DateTime.fromFormat(viewValue, format === 'H:mm' ? 'H:mm' : 'h:mm a')
25
+ return parsed.isValid
26
+ })
23
27
  };
24
28
  }
25
29
 
package/src/index.spec.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import './index'
2
2
 
3
- import './app/canary.spec'
3
+ import './app/canary.spec.ts'
4
4
  import './components/auto-complete/tests/auto-complete-match-renderer.spec'
5
5
  import './components/auto-complete/tests/auto-complete.spec'
6
6
  import './components/auto-focus/tests/auto-focus.spec'
package/webpack.config.js CHANGED
@@ -219,6 +219,12 @@ module.exports = function (env) {
219
219
  ],
220
220
  resolve: {
221
221
  extensions: ['.js', '.ts', '*'],
222
+ alias: {
223
+ // Ignore moment import in pikaday since we've migrated to luxon
224
+ moment: false,
225
+ // Force luxon to use ES6 build for proper import support
226
+ 'luxon': path.resolve(__dirname, 'node_modules/luxon/build/es6/luxon.js'),
227
+ },
222
228
  plugins: [
223
229
  new TsConfigPathsPlugin(),
224
230
  ],