@mediafly/js-ui 51.4.0-0 → 51.4.1-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 (44) hide show
  1. package/CHANGELOG.md +5 -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 +6 -6
  11. package/lib/date-time-zone-picker/date-time-zone-picker.js +119 -59
  12. package/lib/date-time-zone-picker/date-time-zone-picker.js.map +1 -1
  13. package/lib/date-time-zone-picker/datepicker.html +2 -3
  14. package/lib/date-time-zone-picker/datepicker.js +79 -26
  15. package/lib/date-time-zone-picker/datepicker.js.map +1 -1
  16. package/lib/date-time-zone-picker/time-format-filter.js +8 -8
  17. package/lib/date-time-zone-picker/time-format-filter.js.map +1 -1
  18. package/lib/date-time-zone-picker/time-zone-picker.js +1 -1
  19. package/lib/date-time-zone-picker/timepicker.html +1 -2
  20. package/lib/date-time-zone-picker/timepicker.js +35 -40
  21. package/lib/date-time-zone-picker/timepicker.js.map +1 -1
  22. package/lib/time-input/time-input.js +27 -23
  23. package/lib/time-input/time-input.js.map +1 -1
  24. package/lib/time-input/validate-time.js +6 -3
  25. package/lib/time-input/validate-time.js.map +1 -1
  26. package/lib/tsconfig.deploy.tsbuildinfo +163 -25
  27. package/package.json +4 -4
  28. package/src/components/constants/constants.js +2 -1
  29. package/src/components/date-input/date-input.js +31 -12
  30. package/src/components/date-input/validate-date.js +14 -10
  31. package/src/components/date-time-zone-picker/date-time-zone-factory.ts +62 -49
  32. package/src/components/date-time-zone-picker/date-time-zone-picker.html +6 -6
  33. package/src/components/date-time-zone-picker/date-time-zone-picker.ts +131 -70
  34. package/src/components/date-time-zone-picker/datepicker.html +2 -3
  35. package/src/components/date-time-zone-picker/datepicker.ts +83 -26
  36. package/src/components/date-time-zone-picker/time-format-filter.ts +8 -8
  37. package/src/components/date-time-zone-picker/time-zone-picker.js +1 -1
  38. package/src/components/date-time-zone-picker/timepicker.html +1 -2
  39. package/src/components/date-time-zone-picker/timepicker.js +46 -47
  40. package/src/components/time-input/time-input.js +27 -24
  41. package/src/components/time-input/validate-time.js +6 -3
  42. package/src/index.spec.js +1 -1
  43. package/webpack.config.js +6 -0
  44. package/tsconfig.tsbuildinfo +0 -7221
@@ -1,6 +1,6 @@
1
1
  import angular from 'angular'
2
2
  import _ from 'lodash'
3
- import moment from 'moment'
3
+ import { DateTime } from 'luxon'
4
4
 
5
5
  // This filter takes a datetime string with UTC offset, like `2015-09-30T00:00:00-08:00`
6
6
  // and converts it to a short format with time zone code displayed, like `12:00 AM AKST`.
@@ -13,7 +13,7 @@ angular.module('app').filter('formatDate', function formatDate() {
13
13
  return ''
14
14
  }
15
15
 
16
- const formattedDateTime = moment.parseZone(date).format('M/DD/YY')
16
+ const formattedDateTime = DateTime.fromISO(date, { setZone: true }).toFormat('M/dd/yy')
17
17
 
18
18
  return formattedDateTime
19
19
  }
@@ -28,11 +28,11 @@ angular.module('app').filter('formatTimeWithTimeZone', ['dateTimeZoneFactory', f
28
28
  }
29
29
 
30
30
  // Parse zone preserves the string date's offset --ignoring offset in locale)
31
- const dateTimeZone = moment.parseZone(date)
31
+ const dateTimeZone = DateTime.fromISO(date, { setZone: true })
32
32
 
33
- const formattedTime = dateTimeZone.format('h:mm A')
33
+ const formattedTime = dateTimeZone.toFormat('h:mm a')
34
34
 
35
- // NOTE: getTimeZone expects a momentDate
35
+ // NOTE: getTimeZone expects a luxonDate
36
36
  const formattedZone = dateTimeZoneFactory.getTimeZone(dateTimeZone).display
37
37
 
38
38
  return `${formattedTime} ${formattedZone}`
@@ -48,11 +48,11 @@ angular.module('app').filter('formatDateTimeWithTimeZone', ['dateTimeZoneFactory
48
48
  }
49
49
 
50
50
  // Parse zone preserves the string date's offset --ignoring offset in locale)
51
- const dateTimeZone = moment.parseZone(date)
51
+ const dateTimeZone = DateTime.fromISO(date, { setZone: true })
52
52
 
53
- const formattedDateTime = moment.parseZone(date).format('M/DD/YY h:mm A')
53
+ const formattedDateTime = DateTime.fromISO(date, { setZone: true }).toFormat('M/dd/yy h:mm a')
54
54
 
55
- // NOTE: getTimeZone expects a momentDate
55
+ // NOTE: getTimeZone expects a luxonDate
56
56
  const formattedZone = dateTimeZoneFactory.getTimeZone(dateTimeZone).display
57
57
 
58
58
  return `${formattedDateTime} ${formattedZone}`
@@ -36,7 +36,7 @@ angular.module('app').directive('mflyTimeZonePicker', ['dateTimeZoneFactory', fu
36
36
  //update the bound timeZone object
37
37
  $scope.timeZone = $scope.timeZones[index];
38
38
  //update the parent component
39
- //must pass the zone value as the parent funciton does not get the update first
39
+ //must pass the zone value as the parent function does not get the update first
40
40
  $scope.onTimeZoneChange({zoneOffset:$scope.timeZone.value});
41
41
  }
42
42
  };
@@ -12,9 +12,8 @@
12
12
  type="text"
13
13
  class="o-form-control c-time-input__box"
14
14
  ng-model="timeValue.time"
15
- ng-change="validateTime()"
16
15
  ng-focus="focusAddOn = true"
17
- ng-blur="focusAddOn = false"
16
+ ng-blur="focusAddOn = false; validateTime()"
18
17
  />
19
18
 
20
19
  <span
@@ -1,25 +1,27 @@
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',
9
9
  replace: true,
10
10
  scope: {
11
11
  inputId: '@',
12
- timeMoment: '=',
12
+ timeLuxon: '=',
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
@@ -32,78 +34,75 @@ angular.module('app').directive('mflyTimePicker', ['translateFactory', function
32
34
 
33
35
  // If the DTZ picker is initialized, or has its value changed
34
36
  // programmatically, we need to update the time picker accordingly.
35
- $scope.$watch('timeMoment', function (newValue) {
37
+ $scope.$watch('timeLuxon', function (newValue) {
36
38
  if (newValue) {
37
- $scope.timeValue.time = $scope.timeMoment.format('h:mm A');
39
+ $scope.timeValue.time = $scope.timeLuxon.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();
44
- $scope.form.validation.mflyTimepicker.$setValidity('invalidTime', isValid);
45
- if (isValid) {
46
- processTime();
45
+ // Try each format until one works
46
+ for (const format of luxonFormats) {
47
+ const parsed = DateTime.fromFormat($scope.timeValue.time, format);
48
+ if (parsed.isValid) {
49
+ processTime(parsed);
50
+ $scope.form.validation.mflyTimepicker.$setValidity('invalidTime', true);
51
+ return;
52
+ }
47
53
  }
48
- } else {
49
- //if the time is removed it is invalid
50
- $scope.form.validation.mflyTimepicker.$setValidity('invalidTime', false);
51
54
  }
55
+
56
+ $scope.form.validation.mflyTimepicker.$setValidity('invalidTime', false);
52
57
  };
53
58
 
54
- //watch necessary to style preceeding add-on element (CSS has no prev sibling selector)
55
- $scope.$watch('form.validation.mflyTimepicker', function(newValue){
59
+ //watch necessary to style preceding add-on element (CSS has no prev sibling selector)
60
+ $scope.$watch('form.validation.mflyTimepicker', function (newValue) {
56
61
  if (newValue) {
57
- $scope.$watch('form.validation.mflyTimepicker.$valid', function(newValue){
62
+ $scope.$watch('form.validation.mflyTimepicker.$valid', function (newValue) {
58
63
  $scope.invalidAddOn = !newValue;
59
64
  });
60
- $scope.$watch('form.validation.mflyTimepicker.$dirty', function(newValue){
65
+ $scope.$watch('form.validation.mflyTimepicker.$dirty', function (newValue) {
61
66
  $scope.dirtyAddOn = newValue;
62
67
  });
63
68
  }
64
69
  });
65
70
 
66
- function processTime() {
67
- 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);
70
-
71
- $scope.timeMoment.hour(tempMomemnt.hour());
72
- $scope.timeMoment.minute(tempMomemnt.minute());
71
+ function processTime(newTime) {
72
+ $scope.timeLuxon = $scope.timeLuxon.set({
73
+ hour: newTime.hour,
74
+ minute: newTime.minute,
75
+ second: 0,
76
+ millisecond: 0,
77
+ });
73
78
 
74
- //callback to the parent component
75
- $scope.onTimeChange();
76
- } else {
77
- //reset time value
78
- $scope.timeValue.time = '12:00 AM';
79
- $scope.validateTime();
80
- }
79
+ //callback to the parent component
80
+ $scope.onTimeChange({ newTime });
81
81
  }
82
82
 
83
83
 
84
- function populateDropdown(){
85
- if ($scope.timeMoment) {
86
- $scope.timeValue.time = $scope.timeMoment.format('hh:mm A');
84
+ function populateDropdown() {
85
+ if ($scope.timeLuxon) {
86
+ $scope.timeValue.time = $scope.timeLuxon.toFormat('hh:mm a');
87
87
  }
88
88
 
89
- //init a moment with todays date
90
- var tempMoment = moment();
91
- //store that date in a seperate value
92
- var todaysDate = tempMoment.date();
89
+ // Populate the drop down with available times
90
+ var tempDateTime = DateTime.now().startOf('day');
91
+
92
+ var todaysDate = tempDateTime.day;
93
93
 
94
- //backup our moment to 12:00am
95
- tempMoment.hour(0);
96
- tempMoment.minute(0);
94
+ // Starting from 12:00 am
95
+ tempDateTime = tempDateTime.set({ hour: 0, minute: 0, second: 0, millisecond: 0 });
97
96
 
98
- //push 30 min intervals into our dropdown array until the date changes
97
+ // Add a time entry on every 30 minutes
99
98
  do {
100
- $scope.dropdownItems.push(tempMoment.format('hh:mm A'));
101
- tempMoment.add(30, 'm');
102
- } while (todaysDate === tempMoment.date());
99
+ $scope.dropdownItems.push(tempDateTime.toFormat('hh:mm a'));
100
+ tempDateTime = tempDateTime.plus({ minutes: 30 });
101
+ } while (todaysDate === tempDateTime.day);
103
102
  }
104
103
 
105
104
 
106
- $scope.itemClicked = function(itemValue){
105
+ $scope.itemClicked = function (itemValue) {
107
106
  $scope.form.validation.mflyTimepicker.$setDirty();
108
107
  $scope.timeValue.time = itemValue;
109
108
  $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
 
@@ -7,7 +7,6 @@ angular.module('app').directive('mflyValidateTime', function mflyValidateTime ()
7
7
 
8
8
  $ctrl.$validators.timeFormat = function (modelValue, viewValue) {
9
9
 
10
- // https://momentjs.com/docs/#/parsing/string-format/
11
10
  var validTimeFormats = [
12
11
  'H:mm',
13
12
  'h:mm A',
@@ -19,7 +18,11 @@ angular.module('app').directive('mflyValidateTime', function mflyValidateTime ()
19
18
  return true;
20
19
  }
21
20
 
22
- return moment(viewValue, validTimeFormats, true).isValid();
21
+ // Check if the time is valid according to the given formats
22
+ return validTimeFormats.some(format => {
23
+ const parsed = DateTime.fromFormat(viewValue, format === 'H:mm' ? 'H:mm' : 'h:mm a')
24
+ return parsed.isValid
25
+ })
23
26
  };
24
27
  }
25
28
 
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
  ],