datatables.net-searchbuilder 1.7.0 → 1.8.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.
@@ -1,5 +1,5 @@
1
- /*! SearchBuilder 1.7.0
2
- -dev * ©SpryMedia Ltd - datatables.net/license/mit
1
+ /*! SearchBuilder 1.8.0
2
+ * ©SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
 
5
5
  import jQuery from 'jquery';
@@ -12,12 +12,20 @@ let $ = jQuery;
12
12
  'use strict';
13
13
 
14
14
  var $$3;
15
- var dataTable$3;
15
+ var dataTable$2;
16
+ /** Get a moment object. Attempt to get from DataTables for module loading first. */
16
17
  function moment() {
17
- return window.moment;
18
+ var used = DataTable.use('moment');
19
+ return used
20
+ ? used
21
+ : window.moment;
18
22
  }
23
+ /** Get a luxon object. Attempt to get from DataTables for module loading first. */
19
24
  function luxon() {
20
- return window.luxon;
25
+ var used = DataTable.use('luxon');
26
+ return used
27
+ ? used
28
+ : window.luxon;
21
29
  }
22
30
  /**
23
31
  * Sets the value of jQuery for use in the file
@@ -26,7 +34,7 @@ let $ = jQuery;
26
34
  */
27
35
  function setJQuery$2(jq) {
28
36
  $$3 = jq;
29
- dataTable$3 = jq.fn.dataTable;
37
+ dataTable$2 = jq.fn.dataTable;
30
38
  }
31
39
  /**
32
40
  * The Criteria class is used within SearchBuilder to represent a search criteria
@@ -38,10 +46,6 @@ let $ = jQuery;
38
46
  if (serverData === void 0) { serverData = undefined; }
39
47
  if (liveSearch === void 0) { liveSearch = false; }
40
48
  var _this = this;
41
- // Check that the required version of DataTables is included
42
- if (!dataTable$3 || !dataTable$3.versionCheck || !dataTable$3.versionCheck('1.10.0')) {
43
- throw new Error('SearchPane requires DataTables 1.10 or newer');
44
- }
45
49
  this.classes = $$3.extend(true, {}, Criteria.classes);
46
50
  // Get options from user and any extra conditions/column types defined by plug-ins
47
51
  this.c = $$3.extend(true, {}, Criteria.defaults, $$3.fn.dataTable.ext.searchBuilder, opts);
@@ -130,7 +134,7 @@ let $ = jQuery;
130
134
  val.addClass(this.classes.greyscale);
131
135
  }
132
136
  }
133
- $$3(window).on('resize.dtsb', dataTable$3.util.throttle(function () {
137
+ $$3(window).on('resize.dtsb', dataTable$2.util.throttle(function () {
134
138
  _this.s.topGroup.trigger('dtsb-redrawLogic');
135
139
  }));
136
140
  this._buildCriteria();
@@ -145,10 +149,10 @@ let $ = jQuery;
145
149
  Criteria._escapeHTML = function (txt) {
146
150
  return txt
147
151
  .toString()
148
- .replace(/&/g, '&')
149
152
  .replace(/&lt;/g, '<')
150
153
  .replace(/&gt;/g, '>')
151
- .replace(/&quot;/g, '"');
154
+ .replace(/&quot;/g, '"')
155
+ .replace(/&amp;/g, '&');
152
156
  };
153
157
  /**
154
158
  * Redraw the DataTable with the current search parameters
@@ -232,7 +236,8 @@ let $ = jQuery;
232
236
  if (this.s.condition !== undefined && condition !== undefined) {
233
237
  var filter = rowData[this.s.dataIdx];
234
238
  // This check is in place for if a custom decimal character is in place
235
- if (this.s.type.includes('num') &&
239
+ if (this.s.type &&
240
+ this.s.type.includes('num') &&
236
241
  (settings.oLanguage.sDecimal !== '' ||
237
242
  settings.oLanguage.sThousands !== '')) {
238
243
  var splitRD = [rowData[this.s.dataIdx]];
@@ -331,7 +336,7 @@ let $ = jQuery;
331
336
  }
332
337
  }
333
338
  }
334
- if (this.s.type.includes('num') && this.s.dt.page.info().serverSide) {
339
+ if (this.s.type && this.s.type.includes('num') && this.s.dt.page.info().serverSide) {
335
340
  for (i = 0; i < this.s.value.length; i++) {
336
341
  this.s.value[i] = this.s.value[i].replace(/[^0-9.\-]/g, '');
337
342
  }
@@ -656,12 +661,13 @@ let $ = jQuery;
656
661
  Criteria.prototype._populateCondition = function () {
657
662
  var conditionOpts = [];
658
663
  var conditionsLength = Object.keys(this.s.conditions).length;
659
- var colInits = this.s.dt.settings()[0].aoColumns;
664
+ var dt = this.s.dt;
665
+ var colInits = dt.settings()[0].aoColumns;
660
666
  var column = +this.dom.data.children('option:selected').val();
661
667
  var condition, condName;
662
668
  // If there are no conditions stored then we need to get them from the appropriate type
663
669
  if (conditionsLength === 0) {
664
- this.s.type = this.s.dt.column(column).type();
670
+ this.s.type = dt.column(column).type();
665
671
  if (colInits !== undefined) {
666
672
  var colInit = colInits[column];
667
673
  if (colInit.searchBuilderType !== undefined && colInit.searchBuilderType !== null) {
@@ -675,9 +681,9 @@ let $ = jQuery;
675
681
  if (this.s.type === null || this.s.type === undefined) {
676
682
  // This can only happen in DT1 - DT2 will do the invalidation of the type itself
677
683
  if ($$3.fn.dataTable.ext.oApi) {
678
- $$3.fn.dataTable.ext.oApi._fnColumnTypes(this.s.dt.settings()[0]);
684
+ $$3.fn.dataTable.ext.oApi._fnColumnTypes(dt.settings()[0]);
679
685
  }
680
- this.s.type = this.s.dt.column(column).type();
686
+ this.s.type = dt.column(column).type();
681
687
  }
682
688
  // Enable the condition element
683
689
  this.dom.condition
@@ -687,9 +693,9 @@ let $ = jQuery;
687
693
  .addClass(this.classes.italic);
688
694
  this.dom.conditionTitle
689
695
  .prop('selected', true);
690
- var decimal = this.s.dt.settings()[0].oLanguage.sDecimal;
696
+ var decimal = dt.settings()[0].oLanguage.sDecimal;
691
697
  // This check is in place for if a custom decimal character is in place
692
- if (decimal !== '' && this.s.type.indexOf(decimal) === this.s.type.length - decimal.length) {
698
+ if (decimal !== '' && this.s.type && this.s.type.indexOf(decimal) === this.s.type.length - decimal.length) {
693
699
  if (this.s.type.includes('num-fmt')) {
694
700
  this.s.type = this.s.type.replace(decimal, '');
695
701
  }
@@ -698,27 +704,36 @@ let $ = jQuery;
698
704
  }
699
705
  }
700
706
  // Select which conditions are going to be used based on the column type
701
- var conditionObj = this.c.conditions[this.s.type] !== undefined ?
702
- this.c.conditions[this.s.type] :
703
- this.s.type.includes('moment') ?
704
- this.c.conditions.moment :
705
- this.s.type.includes('luxon') ?
706
- this.c.conditions.luxon :
707
- this.c.conditions.string;
708
- // If it is a moment format then extract the date format
709
- if (this.s.type.includes('moment')) {
707
+ var conditionObj = void 0;
708
+ if (this.c.conditions[this.s.type] !== undefined) {
709
+ conditionObj = this.c.conditions[this.s.type];
710
+ }
711
+ else if (this.s.type && this.s.type.includes('datetime-')) {
712
+ // Date / time data types in DataTables are driven by Luxon or
713
+ // Moment.js.
714
+ conditionObj = DataTable.use('moment')
715
+ ? this.c.conditions.moment
716
+ : this.c.conditions.luxon;
717
+ this.s.dateFormat = this.s.type.replace(/datetime-/g, '');
718
+ }
719
+ else if (this.s.type && this.s.type.includes('moment')) {
720
+ conditionObj = this.c.conditions.moment;
710
721
  this.s.dateFormat = this.s.type.replace(/moment-/g, '');
711
722
  }
712
- else if (this.s.type.includes('luxon')) {
723
+ else if (this.s.type && this.s.type.includes('luxon')) {
724
+ conditionObj = this.c.conditions.luxon;
713
725
  this.s.dateFormat = this.s.type.replace(/luxon-/g, '');
714
726
  }
727
+ else {
728
+ conditionObj = this.c.conditions.string;
729
+ }
715
730
  // Add all of the conditions to the select element
716
731
  for (var _i = 0, _a = Object.keys(conditionObj); _i < _a.length; _i++) {
717
732
  condition = _a[_i];
718
733
  if (conditionObj[condition] !== null) {
719
734
  // Serverside processing does not supply the options for the select elements
720
735
  // Instead input elements need to be used for these instead
721
- if (this.s.dt.page.info().serverSide && conditionObj[condition].init === Criteria.initSelect) {
736
+ if (dt.page.info().serverSide && conditionObj[condition].init === Criteria.initSelect) {
722
737
  var col = colInits[column];
723
738
  if (this.s.serverData && this.s.serverData[col.data]) {
724
739
  conditionObj[condition].init = Criteria.initSelectSSP;
@@ -734,7 +749,7 @@ let $ = jQuery;
734
749
  this.s.conditions[condition] = conditionObj[condition];
735
750
  condName = conditionObj[condition].conditionName;
736
751
  if (typeof condName === 'function') {
737
- condName = condName(this.s.dt, this.c.i18n);
752
+ condName = condName(dt, this.c.i18n);
738
753
  }
739
754
  conditionOpts.push($$3('<option>', {
740
755
  text: condName,
@@ -752,7 +767,7 @@ let $ = jQuery;
752
767
  condition = _c[_b];
753
768
  var name_1 = this.s.conditions[condition].conditionName;
754
769
  if (typeof name_1 === 'function') {
755
- name_1 = name_1(this.s.dt, this.c.i18n);
770
+ name_1 = name_1(dt, this.c.i18n);
756
771
  }
757
772
  var newOpt = $$3('<option>', {
758
773
  text: name_1,
@@ -795,7 +810,7 @@ let $ = jQuery;
795
810
  condName = this.s.conditions[cond].conditionName;
796
811
  if (
797
812
  // If the conditionName matches the text of the option
798
- (typeof condName === 'string' ? condName : condName(this.s.dt, this.c.i18n)) ===
813
+ (typeof condName === 'string' ? condName : condName(dt, this.c.i18n)) ===
799
814
  conditionOpts[i].text() &&
800
815
  // and the tokens match
801
816
  cond === defaultCondition) {
@@ -964,7 +979,7 @@ let $ = jQuery;
964
979
  input: 'dtsb-input',
965
980
  inputCont: 'dtsb-inputCont',
966
981
  italic: 'dtsb-italic',
967
- joiner: 'dtsp-joiner',
982
+ joiner: 'dtsb-joiner',
968
983
  left: 'dtsb-left',
969
984
  notItalic: 'dtsb-notItalic',
970
985
  option: 'dtsb-option',
@@ -2379,7 +2394,6 @@ let $ = jQuery;
2379
2394
  }());
2380
2395
 
2381
2396
  var $$2;
2382
- var dataTable$2;
2383
2397
  /**
2384
2398
  * Sets the value of jQuery for use in the file
2385
2399
  *
@@ -2387,7 +2401,7 @@ let $ = jQuery;
2387
2401
  */
2388
2402
  function setJQuery$1(jq) {
2389
2403
  $$2 = jq;
2390
- dataTable$2 = jq.fn.dataTable;
2404
+ jq.fn.dataTable;
2391
2405
  }
2392
2406
  /**
2393
2407
  * The Group class is used within SearchBuilder to represent a group of criteria
@@ -2398,10 +2412,6 @@ let $ = jQuery;
2398
2412
  if (isChild === void 0) { isChild = false; }
2399
2413
  if (depth === void 0) { depth = 1; }
2400
2414
  if (serverData === void 0) { serverData = undefined; }
2401
- // Check that the required version of DataTables is included
2402
- if (!dataTable$2 || !dataTable$2.versionCheck || !dataTable$2.versionCheck('1.10.0')) {
2403
- throw new Error('SearchBuilder requires DataTables 1.10 or newer');
2404
- }
2405
2415
  this.classes = $$2.extend(true, {}, Group.classes);
2406
2416
  // Get options from user
2407
2417
  this.c = $$2.extend(true, {}, Group.defaults, opts);
@@ -3162,8 +3172,8 @@ let $ = jQuery;
3162
3172
  function SearchBuilder(builderSettings, opts) {
3163
3173
  var _this = this;
3164
3174
  // Check that the required version of DataTables is included
3165
- if (!dataTable$1 || !dataTable$1.versionCheck || !dataTable$1.versionCheck('1.10.0')) {
3166
- throw new Error('SearchBuilder requires DataTables 1.10 or newer');
3175
+ if (!dataTable$1 || !dataTable$1.versionCheck || !dataTable$1.versionCheck('2')) {
3176
+ throw new Error('SearchBuilder requires DataTables 2 or newer');
3167
3177
  }
3168
3178
  var table = new dataTable$1.Api(builderSettings);
3169
3179
  this.classes = $$1.extend(true, {}, SearchBuilder.classes);
@@ -3358,9 +3368,7 @@ let $ = jQuery;
3358
3368
  data.searchBuilder = _this._collapseArray(_this.getDetails(true));
3359
3369
  }
3360
3370
  });
3361
- this.s.dt.on(dataTable$1.versionCheck('2')
3362
- ? 'columns-reordered'
3363
- : 'column-reorder', function () {
3371
+ this.s.dt.on('columns-reordered', function () {
3364
3372
  _this.rebuild(_this.getDetails());
3365
3373
  });
3366
3374
  if (loadState) {
@@ -3575,7 +3583,7 @@ let $ = jQuery;
3575
3583
  _this.dom.clearAll.remove();
3576
3584
  });
3577
3585
  };
3578
- SearchBuilder.version = '1.7.0';
3586
+ SearchBuilder.version = '1.8.0';
3579
3587
  SearchBuilder.classes = {
3580
3588
  button: 'dtsb-button',
3581
3589
  clearAll: 'dtsb-clearAll',
@@ -3683,8 +3691,8 @@ let $ = jQuery;
3683
3691
  return SearchBuilder;
3684
3692
  }());
3685
3693
 
3686
- /*! SearchBuilder 1.7.0
3687
- -dev * ©SpryMedia Ltd - datatables.net/license/mit
3694
+ /*! SearchBuilder 1.8.0
3695
+ * ©SpryMedia Ltd - datatables.net/license/mit
3688
3696
  */
3689
3697
  setJQuery($);
3690
3698
  setJQuery$1($);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "js/dataTables.searchBuilder.js",
5
5
  "module": "js/dataTables.searchBuilder.mjs",
6
6
  "types": "./types/types.d.ts",
7
- "version": "1.7.0",
7
+ "version": "1.8.0",
8
8
  "files": [
9
9
  "js/**/*.js",
10
10
  "js/**/*.mjs",
@@ -21,7 +21,7 @@
21
21
  "sort"
22
22
  ],
23
23
  "dependencies": {
24
- "datatables.net": ">=1.11.0",
24
+ "datatables.net": "^2.1",
25
25
  "jquery": ">=1.7"
26
26
  },
27
27
  "moduleType": [
package/types/types.d.ts CHANGED
@@ -48,6 +48,10 @@ declare module 'datatables.net' {
48
48
  searchBuilderType?: string;
49
49
  }
50
50
 
51
+ interface Feature {
52
+ searchBuilder?: string[] | ConfigSearchBuilder | ConfigSearchBuilder[];
53
+ }
54
+
51
55
  interface Api<T> {
52
56
  /**
53
57
  * SearchBuilder methods container