@ni/ok-components 1.9.3 → 1.9.4

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.
@@ -81808,27 +81808,13 @@ focus outline in that case.
81808
81808
  return mixinGroupableColumnAPI(mixinFractionalWidthColumnAPI(mixinColumnWithPlaceholderAPI(mixinSortableColumnAPI(base))));
81809
81809
  }
81810
81810
 
81811
- function formatNumericDate(formatter, date) {
81812
- if (typeof date === 'number') {
81813
- try {
81814
- return formatter.format(date);
81815
- }
81816
- catch (_e) {
81817
- return '';
81818
- }
81819
- }
81820
- else {
81821
- return '';
81822
- }
81823
- }
81824
-
81825
81811
  /**
81826
81812
  * The group header view for displaying date/time fields as text.
81827
81813
  */
81828
81814
  class TableColumnDateTextGroupHeaderView extends TableColumnTextGroupHeaderViewBase {
81829
81815
  updateText() {
81830
81816
  if (this.columnConfig) {
81831
- this.text = formatNumericDate(this.columnConfig.formatter, this.groupHeaderValue);
81817
+ this.text = this.columnConfig.formatter.format(this.groupHeaderValue);
81832
81818
  }
81833
81819
  else {
81834
81820
  this.text = '';
@@ -81954,7 +81940,7 @@ focus outline in that case.
81954
81940
  class TableColumnDateTextCellView extends TableColumnTextCellViewBase {
81955
81941
  updateText() {
81956
81942
  if (this.columnConfig) {
81957
- this.text = formatNumericDate(this.columnConfig.formatter, this.cellRecord?.value);
81943
+ this.text = this.columnConfig.formatter.format(this.cellRecord?.value);
81958
81944
  }
81959
81945
  else {
81960
81946
  this.text = '';
@@ -81974,6 +81960,30 @@ focus outline in that case.
81974
81960
  */
81975
81961
  const DateTextFormat = {
81976
81962
  default: undefined};
81963
+ /**
81964
+ * The `Intl.DateTimeFormatOptions` properties supported by the date-text column and `DateTextFormatter`.
81965
+ */
81966
+ const supportedIntlDateTimeFormatOptionNames = [
81967
+ 'localeMatcher',
81968
+ 'weekday',
81969
+ 'era',
81970
+ 'year',
81971
+ 'month',
81972
+ 'day',
81973
+ 'hour',
81974
+ 'minute',
81975
+ 'second',
81976
+ 'dayPeriod',
81977
+ 'timeZoneName',
81978
+ 'formatMatcher',
81979
+ 'hour12',
81980
+ 'timeZone',
81981
+ 'calendar',
81982
+ 'numberingSystem',
81983
+ 'dateStyle',
81984
+ 'timeStyle',
81985
+ 'hourCycle'
81986
+ ];
81977
81987
 
81978
81988
  const dateTextValidityFlagNames = ['invalidCustomOptionsCombination'];
81979
81989
  /**
@@ -82005,6 +82015,65 @@ focus outline in that case.
82005
82015
  }
82006
82016
  };
82007
82017
 
82018
+ /**
82019
+ * A class for formatting date values using the provided locale and options.
82020
+ */
82021
+ class DateTextFormatter {
82022
+ constructor(lang, options) {
82023
+ this.options = this.resolveOptions(options);
82024
+ this.formatter = new Intl.DateTimeFormat(lang, this.options);
82025
+ }
82026
+ format(value) {
82027
+ const milliseconds = this.parseValue(value);
82028
+ if (milliseconds === undefined || !Number.isFinite(milliseconds)) {
82029
+ return '';
82030
+ }
82031
+ try {
82032
+ return this.formatter.format(milliseconds);
82033
+ }
82034
+ catch (_e) {
82035
+ return '';
82036
+ }
82037
+ }
82038
+ optionsMatch(targetOptions) {
82039
+ const resolvedTargetOptions = targetOptions ?? DateTextFormatter.defaultOptions;
82040
+ for (const name of supportedIntlDateTimeFormatOptionNames) {
82041
+ if (this.options[name] !== resolvedTargetOptions[name]) {
82042
+ return false;
82043
+ }
82044
+ }
82045
+ return true;
82046
+ }
82047
+ parseValue(value) {
82048
+ if (value instanceof Date) {
82049
+ return value.getTime();
82050
+ }
82051
+ if (typeof value === 'number') {
82052
+ return value;
82053
+ }
82054
+ return undefined;
82055
+ }
82056
+ resolveOptions(options) {
82057
+ if (options === undefined) {
82058
+ return DateTextFormatter.defaultOptions;
82059
+ }
82060
+ const supportedOptions = {};
82061
+ for (const name of supportedIntlDateTimeFormatOptionNames) {
82062
+ this.resolveOption(supportedOptions, options, name);
82063
+ }
82064
+ return supportedOptions;
82065
+ }
82066
+ resolveOption(target, source, name) {
82067
+ if (source[name] !== undefined) {
82068
+ target[name] = source[name];
82069
+ }
82070
+ }
82071
+ }
82072
+ DateTextFormatter.defaultOptions = {
82073
+ dateStyle: 'medium',
82074
+ timeStyle: 'medium'
82075
+ };
82076
+
82008
82077
  /**
82009
82078
  * The table column for displaying dates/times as text.
82010
82079
  */
@@ -82115,18 +82184,11 @@ focus outline in that case.
82115
82184
  }
82116
82185
  }
82117
82186
  createFormatter() {
82118
- let options;
82119
- if (this.format === DateTextFormat.default) {
82120
- options = {
82121
- dateStyle: 'medium',
82122
- timeStyle: 'medium'
82123
- };
82124
- }
82125
- else {
82126
- options = this.getCustomFormattingOptions();
82127
- }
82187
+ const options = this.format === DateTextFormat.default
82188
+ ? undefined
82189
+ : this.getCustomFormattingOptions();
82128
82190
  try {
82129
- return new Intl.DateTimeFormat(lang.getValueFor(this), options);
82191
+ return new DateTextFormatter(lang.getValueFor(this), options);
82130
82192
  }
82131
82193
  catch (_e) {
82132
82194
  return undefined;