@ni/nimble-components 20.3.0 → 20.3.2

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.
@@ -16288,7 +16288,7 @@
16288
16288
 
16289
16289
  /**
16290
16290
  * Do not edit directly
16291
- * Generated on Fri, 15 Sep 2023 14:20:06 GMT
16291
+ * Generated on Fri, 15 Sep 2023 20:59:38 GMT
16292
16292
  */
16293
16293
 
16294
16294
  const Information100DarkUi = "#a46eff";
@@ -44882,6 +44882,66 @@ img.ProseMirror-separator {
44882
44882
  group: 'inline',
44883
44883
  });
44884
44884
 
44885
+ const HardBreak = Node$1.create({
44886
+ name: 'hardBreak',
44887
+ addOptions() {
44888
+ return {
44889
+ keepMarks: true,
44890
+ HTMLAttributes: {},
44891
+ };
44892
+ },
44893
+ inline: true,
44894
+ group: 'inline',
44895
+ selectable: false,
44896
+ parseHTML() {
44897
+ return [
44898
+ { tag: 'br' },
44899
+ ];
44900
+ },
44901
+ renderHTML({ HTMLAttributes }) {
44902
+ return ['br', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];
44903
+ },
44904
+ renderText() {
44905
+ return '\n';
44906
+ },
44907
+ addCommands() {
44908
+ return {
44909
+ setHardBreak: () => ({ commands, chain, state, editor, }) => {
44910
+ return commands.first([
44911
+ () => commands.exitCode(),
44912
+ () => commands.command(() => {
44913
+ const { selection, storedMarks } = state;
44914
+ if (selection.$from.parent.type.spec.isolating) {
44915
+ return false;
44916
+ }
44917
+ const { keepMarks } = this.options;
44918
+ const { splittableMarks } = editor.extensionManager;
44919
+ const marks = storedMarks
44920
+ || (selection.$to.parentOffset && selection.$from.marks());
44921
+ return chain()
44922
+ .insertContent({ type: this.name })
44923
+ .command(({ tr, dispatch }) => {
44924
+ if (dispatch && marks && keepMarks) {
44925
+ const filteredMarks = marks
44926
+ .filter(mark => splittableMarks.includes(mark.type.name));
44927
+ tr.ensureMarks(filteredMarks);
44928
+ }
44929
+ return true;
44930
+ })
44931
+ .run();
44932
+ }),
44933
+ ]);
44934
+ },
44935
+ };
44936
+ },
44937
+ addKeyboardShortcuts() {
44938
+ return {
44939
+ 'Mod-Enter': () => this.editor.commands.setHardBreak(),
44940
+ 'Shift-Enter': () => this.editor.commands.setHardBreak(),
44941
+ };
44942
+ },
44943
+ });
44944
+
44885
44945
  const styles$q = css `
44886
44946
  .positioning-region {
44887
44947
  display: flex;
@@ -58508,8 +58568,9 @@ img.ProseMirror-separator {
58508
58568
  const supportedTokenizerRules = zeroTokenizerConfiguration.enable([
58509
58569
  'emphasis',
58510
58570
  'list',
58571
+ 'escape',
58511
58572
  'autolink',
58512
- 'escape'
58573
+ 'newline'
58513
58574
  ]);
58514
58575
  supportedTokenizerRules.validateLink = href => /^https?:\/\//i.test(href);
58515
58576
  /**
@@ -58595,7 +58656,8 @@ img.ProseMirror-separator {
58595
58656
  orderedList: orderedListNode,
58596
58657
  doc: defaultMarkdownSerializer.nodes.doc,
58597
58658
  paragraph: defaultMarkdownSerializer.nodes.paragraph,
58598
- text: defaultMarkdownSerializer.nodes.text
58659
+ text: defaultMarkdownSerializer.nodes.text,
58660
+ hardBreak: defaultMarkdownSerializer.nodes.hard_break
58599
58661
  };
58600
58662
  const marks = {
58601
58663
  italic: defaultMarkdownSerializer.marks.em,
@@ -58862,6 +58924,7 @@ img.ProseMirror-separator {
58862
58924
  placeholder: '',
58863
58925
  showOnlyWhenEditable: false
58864
58926
  }),
58927
+ HardBreak,
58865
58928
  customLink.configure({
58866
58929
  // HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap
58867
58930
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -68038,6 +68101,298 @@ img.ProseMirror-separator {
68038
68101
  .register(nimbleTableColumnEnumText());
68039
68102
  DesignSystem.tagFor(TableColumnEnumText);
68040
68103
 
68104
+ /**
68105
+ * The group header view for displaying number fields as text.
68106
+ */
68107
+ class TableColumnNumberTextGroupHeaderView extends TableColumnTextGroupHeaderViewBase {
68108
+ columnConfigChanged() {
68109
+ this.updateText();
68110
+ }
68111
+ groupHeaderValueChanged() {
68112
+ this.updateText();
68113
+ }
68114
+ updateText() {
68115
+ this.text = this.columnConfig?.formatter?.formatValue(this.groupHeaderValue)
68116
+ ?? '';
68117
+ }
68118
+ }
68119
+ const tableColumnNumberTextGroupHeaderView = TableColumnNumberTextGroupHeaderView.compose({
68120
+ baseName: 'table-column-number-text-group-header-view',
68121
+ template: template$9,
68122
+ styles: styles$b
68123
+ });
68124
+ DesignSystem.getOrCreate()
68125
+ .withPrefix('nimble')
68126
+ .register(tableColumnNumberTextGroupHeaderView());
68127
+ const tableColumnNumberTextGroupHeaderTag = DesignSystem.tagFor(TableColumnNumberTextGroupHeaderView);
68128
+
68129
+ /**
68130
+ * A cell view for displaying number fields as text
68131
+ */
68132
+ class TableColumnNumberTextCellView extends TableColumnTextCellViewBase {
68133
+ columnConfigChanged() {
68134
+ this.updateText();
68135
+ this.alignment = this.columnConfig?.alignment ?? TextCellViewBaseAlignment.left;
68136
+ }
68137
+ cellRecordChanged() {
68138
+ this.updateText();
68139
+ }
68140
+ updateText() {
68141
+ this.text = this.columnConfig?.formatter?.formatValue(this.cellRecord?.value)
68142
+ ?? '';
68143
+ }
68144
+ }
68145
+ const numberTextCellView = TableColumnNumberTextCellView.compose({
68146
+ baseName: 'table-column-number-text-cell-view',
68147
+ template: template$8,
68148
+ styles: styles$a
68149
+ });
68150
+ DesignSystem.getOrCreate().withPrefix('nimble').register(numberTextCellView());
68151
+ const tableColumnNumberTextCellViewTag = DesignSystem.tagFor(TableColumnNumberTextCellView);
68152
+
68153
+ /**
68154
+ * Formatting scheme for the number-text table column
68155
+ */
68156
+ const NumberTextFormat = {
68157
+ default: undefined,
68158
+ decimal: 'decimal'
68159
+ };
68160
+ /**
68161
+ * The aligment of the value in the number-text table column.
68162
+ * The `default` alignment is determined by the column's `NumberTextFormat`.
68163
+ */
68164
+ const NumberTextAlignment = {
68165
+ default: undefined,
68166
+ left: 'left',
68167
+ right: 'right'
68168
+ };
68169
+
68170
+ /**
68171
+ * The base class for number formatters used by the number-text column.
68172
+ */
68173
+ class NumberFormatter {
68174
+ /**
68175
+ * Tries to format the passed value using the `format()` function implemented by a concrete implementation of the class.
68176
+ * Returns an empty string if the value is not a number or if `format()` throws an error.
68177
+ */
68178
+ formatValue(value) {
68179
+ if (typeof value !== 'number') {
68180
+ return '';
68181
+ }
68182
+ try {
68183
+ return this.format(value);
68184
+ }
68185
+ catch {
68186
+ return '';
68187
+ }
68188
+ }
68189
+ }
68190
+
68191
+ /**
68192
+ * The formatter for a number-text column whose format is configured to be 'default'.
68193
+ */
68194
+ class DefaultFormatter extends NumberFormatter {
68195
+ constructor(locale) {
68196
+ super();
68197
+ this.defaultFormatter = new Intl.NumberFormat(locale, {
68198
+ maximumSignificantDigits: DefaultFormatter.maximumDigits,
68199
+ useGrouping: true
68200
+ });
68201
+ this.leadingZeroFormatter = new Intl.NumberFormat(locale, {
68202
+ maximumFractionDigits: DefaultFormatter.maximumDigits - 1,
68203
+ useGrouping: true
68204
+ });
68205
+ this.exponentialFormatter = new Intl.NumberFormat(locale, {
68206
+ maximumSignificantDigits: DefaultFormatter.maximumDigits,
68207
+ notation: 'scientific'
68208
+ });
68209
+ }
68210
+ format(number) {
68211
+ // The NumberFormat option of `signDisplay: "negative"` is not supported in all browsers nimble supports.
68212
+ // Because that option cannot be used to avoid rendering "-0", coerce the value -0 to 0 prior to formatting.
68213
+ const valueToFormat = number === 0 ? 0 : number;
68214
+ const formatter = this.getFormatterForNumber(valueToFormat);
68215
+ return formatter.format(valueToFormat);
68216
+ }
68217
+ getFormatterForNumber(number) {
68218
+ if (number === 0) {
68219
+ return this.defaultFormatter;
68220
+ }
68221
+ const absoluteValue = Math.abs(number);
68222
+ if (absoluteValue >= DefaultFormatter.exponentialUpperBound
68223
+ || absoluteValue < DefaultFormatter.exponentialLowerBound) {
68224
+ return this.exponentialFormatter;
68225
+ }
68226
+ // Ideally, we could set 'roundingPriority: "lessPrecision"' with a formatter that has both 'maximumSignificantDigits' and
68227
+ // 'maximumFractionDigits' configured instead of having two different formatters that we conditionally choose between. However,
68228
+ // 'roundingPrioirty' is not supported yet in all browsers nimble supports.
68229
+ if (absoluteValue < 1) {
68230
+ return this.leadingZeroFormatter;
68231
+ }
68232
+ return this.defaultFormatter;
68233
+ }
68234
+ }
68235
+ // The maximum number of digits that should be rendered for any given value.
68236
+ DefaultFormatter.maximumDigits = 6;
68237
+ // Use exponential notation for numbers that will be rendered with 3 leading 0s or more.
68238
+ // Because a maximum of 6 digits are rendered, showing more than 3 leading 0s is not ideal
68239
+ // because then at least half of the displayed digits will be leading 0s.
68240
+ DefaultFormatter.exponentialLowerBound = 0.000995;
68241
+ // Use exponential formatting for numbers whose magnitude cannot otherwise be displayed
68242
+ // with 6 digits or less.
68243
+ DefaultFormatter.exponentialUpperBound = 999999.5;
68244
+
68245
+ /**
68246
+ * The formatter for a number-text column whose format is configured to be 'decimal'.
68247
+ */
68248
+ class DecimalFormatter extends NumberFormatter {
68249
+ constructor(locale, decimalsToDisplay) {
68250
+ super();
68251
+ this.formatter = new Intl.NumberFormat(locale, {
68252
+ maximumFractionDigits: decimalsToDisplay,
68253
+ minimumFractionDigits: decimalsToDisplay,
68254
+ useGrouping: true
68255
+ });
68256
+ this.tenPowDecimalDigits = 10 ** decimalsToDisplay;
68257
+ }
68258
+ format(number) {
68259
+ // The NumberFormat option of `signDisplay: "negative"` is not supported in all browsers nimble supports.
68260
+ // Because that option cannot be used to avoid rendering "-0", coerce the value -0 to 0 prior to formatting.
68261
+ const valueToFormat = this.willRoundToZero(number) ? 0 : number;
68262
+ return this.formatter.format(valueToFormat);
68263
+ }
68264
+ willRoundToZero(number) {
68265
+ // Multiply the value by 10 raised to decimal-digits so that Math.round can be used to emulate rounding to
68266
+ // decimal-digits decimal places. If that rounded value is 0, then the value will be rendered with only 0s.
68267
+ return Math.round(number * this.tenPowDecimalDigits) === 0;
68268
+ }
68269
+ }
68270
+
68271
+ const numberTextValidityFlagNames = ['invalidDecimalDigits'];
68272
+ // The maximum and minimum allowed configuration for 'maximumFractionDigits'
68273
+ // and 'minimumFractionDigits' on the NumberFormat.
68274
+ const minimumValidDecimalDigits = 0;
68275
+ const maximumValidDecimalDigits = 20;
68276
+ /**
68277
+ * Validator for TableColumnNumberText.
68278
+ */
68279
+ class TableColumnNumberTextValidator extends ColumnValidator {
68280
+ constructor(columnInternals) {
68281
+ super(columnInternals, numberTextValidityFlagNames);
68282
+ }
68283
+ validateDecimalDigits(format, decimalDigits) {
68284
+ const shouldValidateDecimalDigitsValue = format === NumberTextFormat.decimal
68285
+ && typeof decimalDigits === 'number';
68286
+ const invalid = shouldValidateDecimalDigitsValue
68287
+ ? this.isInvalidDecimalDigitsValue(decimalDigits)
68288
+ : false;
68289
+ this.setConditionValue('invalidDecimalDigits', invalid);
68290
+ }
68291
+ isInvalidDecimalDigitsValue(decimalDigits) {
68292
+ return (decimalDigits < minimumValidDecimalDigits
68293
+ || decimalDigits > maximumValidDecimalDigits);
68294
+ }
68295
+ }
68296
+
68297
+ const defaultDecimalDigits = 2;
68298
+ /**
68299
+ * The table column for displaying numbers as text.
68300
+ */
68301
+ class TableColumnNumberText extends TableColumnTextBase {
68302
+ constructor() {
68303
+ super(...arguments);
68304
+ /** @internal */
68305
+ this.validator = new TableColumnNumberTextValidator(this.columnInternals);
68306
+ this.langSubscriber = {
68307
+ handleChange: () => {
68308
+ this.updateColumnConfig();
68309
+ }
68310
+ };
68311
+ }
68312
+ connectedCallback() {
68313
+ super.connectedCallback();
68314
+ lang$1.subscribe(this.langSubscriber, this);
68315
+ this.updateColumnConfig();
68316
+ }
68317
+ disconnectedCallback() {
68318
+ super.disconnectedCallback();
68319
+ lang$1.unsubscribe(this.langSubscriber, this);
68320
+ }
68321
+ get validity() {
68322
+ return this.validator.getValidity();
68323
+ }
68324
+ getColumnInternalsOptions() {
68325
+ return {
68326
+ cellRecordFieldNames: ['value'],
68327
+ cellViewTag: tableColumnNumberTextCellViewTag,
68328
+ groupHeaderViewTag: tableColumnNumberTextGroupHeaderTag,
68329
+ delegatedEvents: [],
68330
+ sortOperation: TableColumnSortOperation.basic
68331
+ };
68332
+ }
68333
+ formatChanged() {
68334
+ this.updateColumnConfig();
68335
+ }
68336
+ alignmentChanged() {
68337
+ this.updateColumnConfig();
68338
+ }
68339
+ decimalDigitsChanged() {
68340
+ this.updateColumnConfig();
68341
+ }
68342
+ updateColumnConfig() {
68343
+ this.validator.validateDecimalDigits(this.format, this.decimalDigits);
68344
+ if (this.validator.isValid()) {
68345
+ const columnConfig = {
68346
+ formatter: this.createFormatter(),
68347
+ alignment: this.determineCellContentAlignment()
68348
+ };
68349
+ this.columnInternals.columnConfig = columnConfig;
68350
+ }
68351
+ else {
68352
+ this.columnInternals.columnConfig = undefined;
68353
+ }
68354
+ }
68355
+ createFormatter() {
68356
+ switch (this.format) {
68357
+ case NumberTextFormat.decimal:
68358
+ return new DecimalFormatter(lang$1.getValueFor(this), this.decimalDigits ?? defaultDecimalDigits);
68359
+ default:
68360
+ return new DefaultFormatter(lang$1.getValueFor(this));
68361
+ }
68362
+ }
68363
+ determineCellContentAlignment() {
68364
+ if (this.alignment === NumberTextAlignment.left) {
68365
+ return TextCellViewBaseAlignment.left;
68366
+ }
68367
+ if (this.alignment === NumberTextAlignment.right) {
68368
+ return TextCellViewBaseAlignment.right;
68369
+ }
68370
+ // Look at format to determine the default alignment
68371
+ if (this.format === NumberTextFormat.decimal) {
68372
+ return TextCellViewBaseAlignment.right;
68373
+ }
68374
+ return TextCellViewBaseAlignment.left;
68375
+ }
68376
+ }
68377
+ __decorate$1([
68378
+ attr
68379
+ ], TableColumnNumberText.prototype, "format", void 0);
68380
+ __decorate$1([
68381
+ attr
68382
+ ], TableColumnNumberText.prototype, "alignment", void 0);
68383
+ __decorate$1([
68384
+ attr({ attribute: 'decimal-digits', converter: nullableNumberConverter })
68385
+ ], TableColumnNumberText.prototype, "decimalDigits", void 0);
68386
+ const nimbleTableColumnNumberText = TableColumnNumberText.compose({
68387
+ baseName: 'table-column-number-text',
68388
+ template: template$b,
68389
+ styles: styles$d
68390
+ });
68391
+ DesignSystem.getOrCreate()
68392
+ .withPrefix('nimble')
68393
+ .register(nimbleTableColumnNumberText());
68394
+ DesignSystem.tagFor(TableColumnNumberText);
68395
+
68041
68396
  const iconValidityFlagNames = [
68042
68397
  ...enumBaseValidityFlagNames,
68043
68398
  'invalidIconName'