melondtable 1.15.4 → 1.16.1

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.
@@ -1902,6 +1902,16 @@ function numberSortAsc(a, b) {
1902
1902
  function stripHTML(html) {
1903
1903
  return html.replace(/<[^>]*>/g, '');
1904
1904
  }
1905
+ function format(str, args) {
1906
+ if (!str) return str;
1907
+
1908
+ Object.keys(args).forEach(arg => {
1909
+ let regex = new RegExp(`{(${arg})}`, 'g');
1910
+ str = str.replace(regex, args[arg]);
1911
+ });
1912
+
1913
+ return str;
1914
+ }
1905
1915
 
1906
1916
  class DataManager {
1907
1917
  constructor(options) {
@@ -2655,7 +2665,10 @@ class CellManager {
2655
2665
  bindCopyCellContents() {
2656
2666
  this.keyboard.on('ctrl+c', () => {
2657
2667
  const noOfCellsCopied = this.copyCellContents(this.$focusedCell, this.$selectionCursor);
2658
- const message = `${noOfCellsCopied} cell${noOfCellsCopied > 1 ? 's' : ''} copied`;
2668
+ const message = this.instance.translate('{count} cells copied', {
2669
+ count: noOfCellsCopied
2670
+ });
2671
+
2659
2672
  if (noOfCellsCopied) {
2660
2673
  this.instance.showToastMessage(message, 2);
2661
2674
  }
@@ -3572,7 +3585,11 @@ class ColumnManager {
3572
3585
 
3573
3586
  const onMouseMove = (e) => {
3574
3587
  if (!isDragging) return;
3575
- const finalWidth = startWidth + (e.pageX - startX);
3588
+ let delta = e.pageX - startX;
3589
+ if (this.options.direction === 'rtl') {
3590
+ delta = -1 * delta;
3591
+ }
3592
+ const finalWidth = startWidth + delta;
3576
3593
  const {
3577
3594
  colIndex
3578
3595
  } = $.data($resizingCell);
@@ -3973,7 +3990,10 @@ class RowManager {
3973
3990
  const checkedRows = this.getCheckedRows();
3974
3991
  const count = checkedRows.length;
3975
3992
  if (count > 0) {
3976
- this.bodyRenderer.showToastMessage(`${count} row${count > 1 ? 's' : ''} selected`);
3993
+ let message = this.instance.translate('{count} rows selected', {
3994
+ count: count
3995
+ });
3996
+ this.bodyRenderer.showToastMessage(message);
3977
3997
  } else {
3978
3998
  this.bodyRenderer.clearToastMessage();
3979
3999
  }
@@ -5205,6 +5225,83 @@ class Keyboard {
5205
5225
  }
5206
5226
  }
5207
5227
 
5228
+ var en = {
5229
+ "Sort Ascending": "Sort Ascending",
5230
+ "Sort Descending": "Sort Descending",
5231
+ "Reset sorting": "Reset sorting",
5232
+ "Remove column": "Remove column",
5233
+ "No Data": "No Data",
5234
+ "{count} cells copied": {"1":"{count} cell copied","default":"{count} cells copied"},
5235
+ "{count} rows selected": {"1":"{count} row selected","default":"{count} rows selected"}
5236
+ };
5237
+
5238
+ var de = {
5239
+ "Sort Ascending": "Aufsteigend sortieren",
5240
+ "Sort Descending": "Absteigend sortieren",
5241
+ "Reset sorting": "Sortierung zurücksetzen",
5242
+ "Remove column": "Spalte entfernen",
5243
+ "No Data": "Keine Daten",
5244
+ "{count} cells copied": {"1":"{count} Zelle kopiert","default":"{count} Zellen kopiert"},
5245
+ "{count} rows selected": {"1":"{count} Zeile ausgewählt","default":"{count} Zeilen ausgewählt"}
5246
+ };
5247
+
5248
+ var fr = {
5249
+ "Sort Ascending": "Trier par ordre croissant",
5250
+ "Sort Descending": "Trier par ordre décroissant",
5251
+ "Reset sorting": "Réinitialiser le tri",
5252
+ "Remove column": "Supprimer colonne",
5253
+ "No Data": "Pas de données",
5254
+ "{count} cells copied": {"1":"{count} cellule copiée","default":"{count} cellules copiées"},
5255
+ "{count} rows selected": {"1":"{count} ligne sélectionnée","default":"{count} lignes sélectionnées"}
5256
+ };
5257
+
5258
+ var it = {
5259
+ "Sort Ascending": "Ordinamento ascendente",
5260
+ "Sort Descending": "Ordinamento decrescente",
5261
+ "Reset sorting": "Azzeramento ordinamento",
5262
+ "Remove column": "Rimuovi colonna",
5263
+ "No Data": "Nessun dato",
5264
+ "{count} cells copied": {"1":"Copiato {count} cella","default":"{count} celle copiate"},
5265
+ "{count} rows selected": {"1":"{count} linea selezionata","default":"{count} linee selezionate"}
5266
+ };
5267
+
5268
+ function getTranslations() {
5269
+ return {
5270
+ en,
5271
+ de,
5272
+ fr,
5273
+ it,
5274
+ };
5275
+ }
5276
+
5277
+ class TranslationManager {
5278
+ constructor(language) {
5279
+ this.language = language;
5280
+ this.translations = getTranslations();
5281
+ }
5282
+
5283
+ addTranslations(translations) {
5284
+ this.translations = Object.assign(this.translations, translations);
5285
+ }
5286
+
5287
+ translate(sourceText, args) {
5288
+ let translation = (this.translations[this.language] &&
5289
+ this.translations[this.language][sourceText]) || sourceText;
5290
+
5291
+ if (typeof translation === 'object') {
5292
+ translation = args && args.count ?
5293
+ this.getPluralizedTranslation(translation, args.count) :
5294
+ sourceText;
5295
+ }
5296
+
5297
+ return format(translation, args || {});
5298
+ }
5299
+
5300
+ getPluralizedTranslation(translations, count) {
5301
+ return translations[count] || translations['default'];
5302
+ }
5303
+ }
5304
+
5208
5305
  function filterRows(rows, filters) {
5209
5306
  let filteredRowIndices = [];
5210
5307
 
@@ -5397,74 +5494,76 @@ function guessFilter(keyword = '') {
5397
5494
  };
5398
5495
  }
5399
5496
 
5400
- var DEFAULT_OPTIONS = {
5401
- columns: [],
5402
- data: [],
5403
- dropdownButton: icons.chevronDown,
5404
- headerDropdown: [
5405
- {
5406
- label: 'Sort Ascending',
5407
- action: function (column) {
5408
- this.sortColumn(column.colIndex, 'asc');
5497
+ function getDefaultOptions(instance) {
5498
+ return {
5499
+ columns: [],
5500
+ data: [],
5501
+ dropdownButton: icons.chevronDown,
5502
+ headerDropdown: [
5503
+ {
5504
+ label: instance.translate('Sort Ascending'),
5505
+ action: function (column) {
5506
+ this.sortColumn(column.colIndex, 'asc');
5507
+ }
5508
+ },
5509
+ {
5510
+ label: instance.translate('Sort Descending'),
5511
+ action: function (column) {
5512
+ this.sortColumn(column.colIndex, 'desc');
5513
+ }
5514
+ },
5515
+ {
5516
+ label: instance.translate('Reset sorting'),
5517
+ action: function (column) {
5518
+ this.sortColumn(column.colIndex, 'none');
5519
+ }
5520
+ },
5521
+ {
5522
+ label: instance.translate('Remove column'),
5523
+ action: function (column) {
5524
+ this.removeColumn(column.colIndex);
5525
+ }
5409
5526
  }
5527
+ ],
5528
+ events: {
5529
+ onRemoveColumn(column) {},
5530
+ onSwitchColumn(column1, column2) {},
5531
+ onSortColumn(column) {},
5532
+ onCheckRow(row) {},
5533
+ onDestroy() {}
5410
5534
  },
5411
- {
5412
- label: 'Sort Descending',
5413
- action: function (column) {
5414
- this.sortColumn(column.colIndex, 'desc');
5415
- }
5535
+ hooks: {
5536
+ columnTotal: null
5416
5537
  },
5417
- {
5418
- label: 'Reset sorting',
5419
- action: function (column) {
5420
- this.sortColumn(column.colIndex, 'none');
5421
- }
5538
+ sortIndicator: {
5539
+ asc: '↑',
5540
+ desc: '↓',
5541
+ none: ''
5422
5542
  },
5423
- {
5424
- label: 'Remove column',
5425
- action: function (column) {
5426
- this.removeColumn(column.colIndex);
5427
- }
5428
- }
5429
- ],
5430
- events: {
5431
- onRemoveColumn(column) {},
5432
- onSwitchColumn(column1, column2) {},
5433
- onSortColumn(column) {},
5434
- onCheckRow(row) {},
5435
- onDestroy() {}
5436
- },
5437
- hooks: {
5438
- columnTotal: null
5439
- },
5440
- sortIndicator: {
5441
- asc: '↑',
5442
- desc: '↓',
5443
- none: ''
5444
- },
5445
- overrideComponents: {
5446
- // ColumnManager: CustomColumnManager
5447
- },
5448
- filterRows: filterRows,
5449
- freezeMessage: '',
5450
- getEditor: null,
5451
- serialNoColumn: true,
5452
- checkboxColumn: false,
5453
- clusterize: true,
5454
- logs: false,
5455
- layout: 'fixed', // fixed, fluid, ratio
5456
- noDataMessage: 'No Data',
5457
- cellHeight: 40,
5458
- minimumColumnWidth: 30,
5459
- inlineFilters: false,
5460
- treeView: false,
5461
- checkedRowStatus: true,
5462
- dynamicRowHeight: false,
5463
- pasteFromClipboard: false,
5464
- showTotalRow: false,
5465
- direction: 'ltr',
5466
- disableReorderColumn: false
5467
- };
5543
+ overrideComponents: {
5544
+ // ColumnManager: CustomColumnManager
5545
+ },
5546
+ filterRows: filterRows,
5547
+ freezeMessage: '',
5548
+ getEditor: null,
5549
+ serialNoColumn: true,
5550
+ checkboxColumn: false,
5551
+ clusterize: true,
5552
+ logs: false,
5553
+ layout: 'fixed', // fixed, fluid, ratio
5554
+ noDataMessage: instance.translate('No Data'),
5555
+ cellHeight: 40,
5556
+ minimumColumnWidth: 30,
5557
+ inlineFilters: false,
5558
+ treeView: false,
5559
+ checkedRowStatus: true,
5560
+ dynamicRowHeight: false,
5561
+ pasteFromClipboard: false,
5562
+ showTotalRow: false,
5563
+ direction: 'ltr',
5564
+ disableReorderColumn: false
5565
+ };
5566
+ }
5468
5567
 
5469
5568
  let defaultComponents = {
5470
5569
  DataManager,
@@ -5489,6 +5588,8 @@ class DataTable {
5489
5588
  throw new Error('Invalid argument given for `wrapper`');
5490
5589
  }
5491
5590
 
5591
+ this.initializeTranslations(options);
5592
+ this.setDefaultOptions();
5492
5593
  this.buildOptions(options);
5493
5594
  this.prepare();
5494
5595
  this.initializeComponents();
@@ -5499,23 +5600,36 @@ class DataTable {
5499
5600
  }
5500
5601
  }
5501
5602
 
5603
+ initializeTranslations(options) {
5604
+ this.language = options.language || 'en';
5605
+ this.translationManager = new TranslationManager(this.language);
5606
+
5607
+ if (options.translations) {
5608
+ this.translationManager.addTranslations(options.translations);
5609
+ }
5610
+ }
5611
+
5612
+ setDefaultOptions() {
5613
+ this.DEFAULT_OPTIONS = getDefaultOptions(this);
5614
+ }
5615
+
5502
5616
  buildOptions(options) {
5503
5617
  this.options = this.options || {};
5504
5618
 
5505
5619
  this.options = Object.assign(
5506
- {}, DEFAULT_OPTIONS,
5620
+ {}, this.DEFAULT_OPTIONS,
5507
5621
  this.options || {}, options
5508
5622
  );
5509
5623
 
5510
5624
  options.headerDropdown = options.headerDropdown || [];
5511
5625
  this.options.headerDropdown = [
5512
- ...DEFAULT_OPTIONS.headerDropdown,
5626
+ ...this.DEFAULT_OPTIONS.headerDropdown,
5513
5627
  ...options.headerDropdown
5514
5628
  ];
5515
5629
 
5516
5630
  // custom user events
5517
5631
  this.events = Object.assign(
5518
- {}, DEFAULT_OPTIONS.events,
5632
+ {}, this.DEFAULT_OPTIONS.events,
5519
5633
  this.options.events || {},
5520
5634
  options.events || {}
5521
5635
  );
@@ -5701,6 +5815,10 @@ class DataTable {
5701
5815
  console.log.apply(console, arguments);
5702
5816
  }
5703
5817
  }
5818
+
5819
+ translate(str, args) {
5820
+ return this.translationManager.translate(str, args);
5821
+ }
5704
5822
  }
5705
5823
 
5706
5824
  DataTable.instances = 0;
@@ -5711,9 +5829,9 @@ var description = "A modern datatable library for the web";
5711
5829
  var main = "dist/melondtable.cjs.js";
5712
5830
  var unpkg = "dist/melondtable.min.js";
5713
5831
  var jsdelivr = "dist/melondtable.min.js";
5714
- var scripts = {"start":"yarn run dev","build":"rollup -c && NODE_ENV=production rollup -c","dev":"rollup -c -w","cy:server":"http-server -p 8989","cy:open":"cypress open","cy:run":"cypress run","test":"start-server-and-test cy:server http://localhost:8989 cy:run","test-local":"start-server-and-test cy:server http://localhost:8989 cy:open","travis-deploy-once":"travis-deploy-once","semantic-release":"semantic-release","lint":"eslint src","commit":"npx git-cz"};
5832
+ var scripts = {"start":"yarn run dev","build":"rollup -c && NODE_ENV=production rollup -c","dev":"rollup -c -w","cy:server":"http-server -p 8989","cy:open":"cypress open","cy:run":"cypress run","test":"start-server-and-test cy:server http://localhost:8989 cy:run","test-local":"start-server-and-test cy:server http://localhost:8989 cy:open","travis-deploy-once":"travis-deploy-once","semantic-release":"semantic-release","lint":"eslint src","lint-and-build":"yarn lint && yarn build","commit":"npx git-cz"};
5715
5833
  var files = ["dist","src"];
5716
- var devDependencies = {"autoprefixer":"^9.0.0","chai":"3.5.0","cypress":"3.0.1","cz-conventional-changelog":"^2.1.0","deepmerge":"^2.0.1","eslint":"^5.0.1","eslint-config-airbnb":"^16.1.0","eslint-config-airbnb-base":"^12.1.0","eslint-plugin-import":"^2.11.0","http-server":"^0.11.1","mocha":"3.3.0","postcss-custom-properties":"^7.0.0","postcss-nested":"^3.0.0","rollup":"^0.59.4","rollup-plugin-commonjs":"^8.3.0","rollup-plugin-eslint":"^4.0.0","rollup-plugin-json":"^2.3.0","rollup-plugin-node-resolve":"^3.0.3","rollup-plugin-postcss":"^1.2.8","rollup-plugin-uglify-es":"^0.0.1","semantic-release":"^17.1.1","start-server-and-test":"^1.4.1","travis-deploy-once":"^5.0.1"};
5834
+ var devDependencies = {"autoprefixer":"^9.0.0","chai":"3.5.0","cypress":"^9.2.0","cz-conventional-changelog":"^2.1.0","deepmerge":"^2.0.1","eslint":"^5.0.1","eslint-config-airbnb":"^16.1.0","eslint-config-airbnb-base":"^12.1.0","eslint-plugin-import":"^2.11.0","http-server":"^0.11.1","mocha":"3.3.0","postcss-custom-properties":"^7.0.0","postcss-nested":"^3.0.0","rollup":"^0.59.4","rollup-plugin-commonjs":"^8.3.0","rollup-plugin-eslint":"^4.0.0","rollup-plugin-json":"^2.3.0","rollup-plugin-node-resolve":"^3.0.3","rollup-plugin-postcss":"^1.2.8","rollup-plugin-uglify-es":"^0.0.1","semantic-release":"^17.1.1","start-server-and-test":"^1.4.1","travis-deploy-once":"^5.0.1"};
5717
5835
  var repository = {"type":"git","url":"https://github.com/amonak/melondtable.git"};
5718
5836
  var keywords = ["datatable","data","grid","table"];
5719
5837
  var author = "Faris Ansari";
@@ -188,6 +188,11 @@
188
188
  border-right: 1px solid var(--dt-border-color);
189
189
  }
190
190
 
191
+ .datatable[dir=rtl] .dt-cell__resize-handle {
192
+ right: unset;
193
+ left: -3px;
194
+ }
195
+
191
196
  .icon-open, .icon-close {
192
197
  width: 16px;
193
198
  height: 16px;