datatables.net-autofill 3.0.0-beta.1 → 3.0.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.
@@ -1,4 +1,4 @@
1
- /*! AutoFill 3.0.0-beta.1 for DataTables
1
+ /*! AutoFill 3.0.1 for DataTables
2
2
  * Copyright (c) SpryMedia Ltd - datatables.net/license
3
3
  */
4
4
 
@@ -59,6 +59,7 @@ class AutoFill {
59
59
  }
60
60
  enable(flag = true) {
61
61
  let that = this;
62
+ let namespace = this.s.namespace;
62
63
  if (flag === false) {
63
64
  return this.disable();
64
65
  }
@@ -81,13 +82,13 @@ class AutoFill {
81
82
  that._attach(that.dom.attachedTo);
82
83
  }
83
84
  };
84
- window.addEventListener('resize', function () {
85
+ Dom.w.on('resize' + namespace, function () {
85
86
  let handle = Dom.s('div.dtaf-handle');
86
87
  if (handle.count() > 0 && that.dom.attachedTo) {
87
88
  that._attach(that.dom.attachedTo);
88
89
  }
89
90
  });
90
- window.addEventListener('orientationchange', function () {
91
+ Dom.w.on('orientationchange' + namespace, function () {
91
92
  setTimeout(function () {
92
93
  orientationReset();
93
94
  setTimeout(orientationReset, 150);
@@ -128,14 +129,12 @@ class AutoFill {
128
129
  this.dom = {
129
130
  attachedTo: null,
130
131
  container: Dom.c('div').classAdd('dtaf-container'),
131
- closeButton: Dom
132
- .c('button')
132
+ closeButton: Dom.c('button')
133
133
  .classAdd(AutoFill.classes.close)
134
134
  .html('×'),
135
135
  dtScroll: null,
136
136
  handle: Dom.c('div').classAdd('dtaf-handle'),
137
- list: Dom
138
- .c('div')
137
+ list: Dom.c('div')
139
138
  .classAdd('dtaf-list')
140
139
  .html(this.s.dt.i18n('autoFill.info', ''))
141
140
  .attr('aria-modal', true)
@@ -161,12 +160,9 @@ class AutoFill {
161
160
  * Initialise the RowReorder instance
162
161
  */
163
162
  _init() {
164
- let that = this;
165
163
  let dt = this.s.dt;
166
164
  // Need to account for scrolling as it has a different DOM structure
167
- let dtScroll = Dom
168
- .s(this.s.dt.table().container())
169
- .find('div.dt-scroll-body');
165
+ let dtScroll = Dom.s(this.s.dt.table().container()).find('div.dt-scroll-body');
170
166
  // Make the instance accessible to the API
171
167
  dt.settings()[0].autoFill = this;
172
168
  if (dtScroll.count()) {
@@ -179,8 +175,9 @@ class AutoFill {
179
175
  if (this.c.enable !== false) {
180
176
  this.enable();
181
177
  }
182
- dt.on('destroy.autoFill', function () {
183
- that._focusListenerRemove();
178
+ dt.on('destroy.autoFill', () => {
179
+ this._focusListenerRemove();
180
+ this.dom.handle.off();
184
181
  });
185
182
  }
186
183
  /**
@@ -252,12 +249,10 @@ class AutoFill {
252
249
  available.push('cancel');
253
250
  for (let i = 0; i < available.length; i++) {
254
251
  let name = available[i];
255
- list.append(Dom
256
- .c('button')
252
+ list.append(Dom.c('button')
257
253
  .classAdd(AutoFill.classes.btn)
258
254
  .html(actions[name].option(dt, cells))
259
- .append(Dom
260
- .c('span')
255
+ .append(Dom.c('span')
261
256
  .classAdd('dtaf-button')
262
257
  .html(dt.i18n('autoFill.button', '')))
263
258
  .on('click', function (e) {
@@ -480,11 +475,16 @@ class AutoFill {
480
475
  });
481
476
  }
482
477
  }
478
+ /**
479
+ * Clean up the event listeners
480
+ */
483
481
  _focusListenerRemove() {
484
- var dt = this.s.dt;
482
+ let namespace = this.s.namespace;
483
+ let dt = this.s.dt;
485
484
  dt.off('.autoFill');
486
- Dom.s(dt.table().body()).off(this.s.namespace);
487
- Dom.s(document.body).off(this.s.namespace);
485
+ Dom.s(dt.table().body()).off(namespace);
486
+ Dom.s(document.body).off(namespace);
487
+ Dom.w.off(namespace);
488
488
  }
489
489
  /**
490
490
  * Get the position of a node, relative to another, including any scrolling
@@ -939,7 +939,7 @@ AutoFill.defaults = {
939
939
  horizontal: true
940
940
  };
941
941
  /** AutoFill version */
942
- AutoFill.version = '3.0.0-beta.1';
942
+ AutoFill.version = '3.0.1';
943
943
 
944
944
  // Doesn't do anything - Not documented
945
945
  Api.register('autoFill()', function () {
@@ -1,4 +1,4 @@
1
- /*! AutoFill 3.0.0-beta.1 for DataTables
1
+ /*! AutoFill 3.0.1 for DataTables
2
2
  * Copyright (c) SpryMedia Ltd - datatables.net/license
3
3
  */
4
- (e=>{var o;"function"==typeof define&&define.amd?define(["datatables.net"],function(t){return e(window,document,t)}):"object"==typeof exports?(o=function(t){t.DataTable||require("datatables.net")(t)},"undefined"==typeof window?module.exports=function(t){return t=t||window,o(t),e(t,t.document,t.DataTable)}:(o(window),module.exports=e(window,window.document,window.DataTable))):e(window,document,window.DataTable)})(function(c,n,u){var h=u.Dom,t=u.Api,d=u.util;if(!u||!u.versionCheck||!u.versionCheck("3"))throw"Warning: AutoFill requires DataTables 3 or greater";var o=0;class r{enabled(){return this.s.enabled}enable(t=!0){let e=this;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1});function o(){e.s.handle={height:0,width:0},e.dom.handle.css({height:"",width:""}),e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return c.addEventListener("resize",function(){0<h.s("div.dtaf-handle").count()&&e.dom.attachedTo&&e._attach(e.dom.attachedTo)}),c.addEventListener("orientationchange",function(){setTimeout(function(){o(),setTimeout(o,150)},50)}),this}disable(){return this.s.enabled=!1,this._focusListenerRemove(),this}constructor(t,e){this.c=d.object.assignDeep({},r.defaults,e),this.s={dt:new u.Api(t),enabled:!1,end:{column:0,row:0},handle:{height:0,width:0},namespace:".autoFill"+o++,scroll:{windowHeight:0,windowWidth:0,dtTop:0,dtLeft:0,dtHeight:0,dtWidth:0},scrollInterval:null,start:{column:0,row:0}},this.dom={attachedTo:null,container:h.c("div").classAdd("dtaf-container"),closeButton:h.c("button").classAdd(r.classes.close).html("&times;"),dtScroll:null,handle:h.c("div").classAdd("dtaf-handle"),list:h.c("div").classAdd("dtaf-list").html(this.s.dt.i18n("autoFill.info","")).attr("aria-modal",!0).attr("role","dialog").append(h.c("div").classAdd("dtaf-list-items")),offsetParent:null,start:null,select:{top:h.c("div").classAdd("dtaf-select top"),right:h.c("div").classAdd("dtaf-select right"),bottom:h.c("div").classAdd("dtaf-select bottom"),left:h.c("div").classAdd("dtaf-select left")}},this.dom.list.appendTo(this.dom.container),this._init()}_init(){let t=this;var e=this.s.dt,o=h.s(this.s.dt.table().container()).find("div.dt-scroll-body");e.settings()[0].autoFill=this,o.count()&&"static"===(this.dom.dtScroll=o).css("position")&&o.css("position","relative"),!1!==this.c.enable&&this.enable(),e.on("destroy.autoFill",function(){t._focusListenerRemove()})}_attach(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=e.table().node().offsetParent),l.height&&l.width||(i.appendTo("body"),l.height=i.height("outer"),l.width=i.width("outer")),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height+"px",left:o.left+t.offsetWidth-l.width+"px"}).appendTo(this.dom.offsetParent)):this._detach()}_actionSelector(o){let i=this,l=this.s.dt,n=r.actions,s=[];if(d.object.each(n,function(t,e){e.available(l,o)&&s.push(t)}),1===s.length&&!1===this.c.alwaysAsk){var t=n[s[0]].execute(l,o,null);this._update(t,o)}else if(1<s.length||this.c.alwaysAsk){var a=this.dom.list.children("div.dtaf-list-items").empty();s.push("cancel");for(let t=0;t<s.length;t++){let e=s[t];a.append(h.c("button").classAdd(r.classes.btn).html(n[e].option(l,o)).append(h.c("span").classAdd("dtaf-button").html(l.i18n("autoFill.button",""))).on("click",function(t){"button"===t.target.nodeName.toLowerCase()&&(t=n[e].execute(l,o,h.s(this).closest("button")),i._update(t,o),i.dom.container.remove())}))}this.dom.container.appendTo("body"),this.dom.container.on("click",function(t){t.target===i.dom.container.get(0)&&i.dom.container.remove()}),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).classAdd(r.classes.closeable),this.dom.closeButton.on("click",function(){return i.dom.container.trigger("click")}))}}_detach(){this.dom.attachedTo=null,this.dom.handle.detach()}_drawSelection(t,e){var o,i=this.s.dt,l=this.s.start,n=h.s(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?h.s(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=h.s(i.cell(a.index(),s).node());i.cell(a.get(0)).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.height("outer")-i,a=this._getPosition(l.get(0)).left+l.width("outer")-o,(n=this.dom.select).top.css({top:i+"px",left:o+"px",width:a+"px"}),n.left.css({top:i+"px",left:o+"px",height:t+"px"}),n.bottom.css({top:i+t+"px",left:o+"px",width:a+"px"}),n.right.css({top:i+"px",left:o+a+"px",height:t+"px"}))}_editor(l){var n=this.s.dt;let s=this.c.editor;if(s){var a={},d=[],c=s.fields();for(let i=0,t=l.length;i<t;i++)for(let t=0,e=l[i].length;t<e;t++){var r=l[i][t],u=n.settings()[0].columns[r.index.column];let o=u.editField;if(void 0===o){var h=u.data;for(let t=0,e=c.length;t<e;t++){var f=s.field(c[t]);if(f.dataSrc()===h){o=f.name();break}}}if(!o)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";if("string"!=typeof o)throw"AutoFill with multiple edit fields is not supported";a[o]||(a[o]={});u=n.row(r.index.row).id();a[o][u]=r.set,d.push(r.index)}s.bubble(d,!1).multiSet(a).submit(null,function(){s.close()})}}_emitEvent(t,e){this.s.dt.trigger(t,e)}_focusListener(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?(h.s(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),h.s(n.body).on("click"+t,function(t){h.s(t.target).closest(e.table().body()).count()||i._detach()})):h.s(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){h.s(t.relatedTarget).classHas("dtaf-handle")||i._detach()})}_focusListenerRemove(){var t=this.s.dt;t.off(".autoFill"),h.s(t.table().body()).off(this.s.namespace),h.s(n.body).off(this.s.namespace)}_getPosition(t,e){let o=h.s(this.s.dt.table().node().offsetParent),i=t,l,n=0,s=0;e&&(o=h.s(e));do{var a=i.offsetTop,d=i.offsetLeft;if(l=h.s(i.offsetParent),n+=a+ +parseInt(l.css("border-top-width")||"0"),s+=d+ +parseInt(l.css("border-left-width")||"0"),"body"===i.nodeName.toLowerCase())break}while(i=l.get(0),l.get(0)!==o.get(0));return{top:n,left:s}}_mousedown(t){let e=this;var o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf(h.s(this.dom.start).parent().get(0)),column:h.s(this.dom.start).index()},h.s(n.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&h.s(n.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=o.table().node().offsetParent,i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:c.innerHeight,windowWidth:c.innerWidth,dtTop:i?i.offset().top:0,dtLeft:i?i.offset().left:0,dtHeight:i?i.height("outer"):0,dtWidth:i?i.width("outer"):0}}_mousemove(t){var e=t.touches&&t.touches.length?n.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))}_mouseup(e){h.s(n.body).off(".autoFill");let o=this,d=this.s.dt;var t=this.dom.select,t=(t.top.remove(),t.left.remove(),t.right.remove(),t.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(t.row!==i.row||t.column!==i.column){var l=d.cell(":eq("+t.row+")",t.column+":visible",{page:"current"});if(h.s(l.node()).find("div.DTE").count()){let t=d.editor();t.on("submitSuccess.dtaf close.dtaf",function(){t.off(".dtaf"),setTimeout(function(){o._mouseup(e)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){t.off(".dtaf")}),void t.submit()}else{let n=this._range(t.row,i.row);var c=this._range(t.column,i.column),r=[];let s=d.settings()[0].columns,a=d.columns(this.c.columns).indexes();for(let l=0;l<n.length;l++)r.push(c.map(function(t){var e=d.row(":eq("+n[l]+")",{page:"current"}),e=d.cell(e.index(),t+":visible");let o=e.data();var t=e.index(),i=s[t.column].editField;if(void 0!==i&&(o=u.util.get(i)(d.row(t.row).data())),-1!==a.indexOf(t.column))return{cell:e,data:o,label:e.data(),index:t}}).filter(t=>!!t));this._actionSelector(r),this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null)}}}_range(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i}_shiftScroll(t){var e,o,i,l,n=this,s=this.s.scroll,a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-c.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-c.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;c.scrollTo(c.scrollX+(s.windowHoriz||0),c.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&((t=null==(t=n.dom.dtScroll)?void 0:t.get(0))&&s.dtVert&&(t.scrollTop+=s.dtVert),t)&&s.dtHoriz&&(t.scrollLeft+=s.dtHoriz)},20))}_update(t,i){if(!1!==t){var l,t=this.s.dt,n=t.columns(this.c.columns).indexes(),e=(this._emitEvent("preAutoFill",[t,i]),this._editor(i),null!==this.c.update?this.c.update:!this.c.editor);if(e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)l=i[o][t],-1!==n.indexOf(l.index.column)&&l.cell.data(l.set);t.draw(!1)}this._emitEvent("autoFill",[t,i])}}}return r.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,i,e){let l=+i[0][0].data;var n=e?parseFloat(e.find("input").val()):1;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l,l+=n}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,i,e){var l=i[0][0].data;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[o][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[0][t].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},r.classes={btn:"btn",close:"dtaf-list-close",closeable:"dtaf-list-closeable"},r.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:!0,editor:null,vertical:!0,horizontal:!0},r.version="3.0.0-beta.1",t.register("autoFill()",function(){return this.inst(this.context)}),t.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),t.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),t.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),h.s(n).on("preInit.dt.autofill",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.autoFill,o=u.defaults.autoFill,t||o)&&(i={},d.is.plainObject(o)&&d.object.assign(i,o),d.is.plainObject(t)&&d.object.assign(i,t),!1!==t)&&new r(e,i)}),u.AutoFill=r,u});
4
+ (e=>{var o;"function"==typeof define&&define.amd?define(["datatables.net"],function(t){return e(window,document,t)}):"object"==typeof exports?(o=function(t){t.DataTable||require("datatables.net")(t)},"undefined"==typeof window?module.exports=function(t){return t=t||window,o(t),e(t,t.document,t.DataTable)}:(o(window),module.exports=e(window,window.document,window.DataTable))):e(window,document,window.DataTable)})(function(c,n,u){var h=u.Dom,t=u.Api,d=u.util;if(!u||!u.versionCheck||!u.versionCheck("3"))throw"Warning: AutoFill requires DataTables 3 or greater";var o=0;class r{enabled(){return this.s.enabled}enable(t=!0){let e=this;var o=this.s.namespace;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1});function i(){e.s.handle={height:0,width:0},e.dom.handle.css({height:"",width:""}),e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return h.w.on("resize"+o,function(){0<h.s("div.dtaf-handle").count()&&e.dom.attachedTo&&e._attach(e.dom.attachedTo)}),h.w.on("orientationchange"+o,function(){setTimeout(function(){i(),setTimeout(i,150)},50)}),this}disable(){return this.s.enabled=!1,this._focusListenerRemove(),this}constructor(t,e){this.c=d.object.assignDeep({},r.defaults,e),this.s={dt:new u.Api(t),enabled:!1,end:{column:0,row:0},handle:{height:0,width:0},namespace:".autoFill"+o++,scroll:{windowHeight:0,windowWidth:0,dtTop:0,dtLeft:0,dtHeight:0,dtWidth:0},scrollInterval:null,start:{column:0,row:0}},this.dom={attachedTo:null,container:h.c("div").classAdd("dtaf-container"),closeButton:h.c("button").classAdd(r.classes.close).html("&times;"),dtScroll:null,handle:h.c("div").classAdd("dtaf-handle"),list:h.c("div").classAdd("dtaf-list").html(this.s.dt.i18n("autoFill.info","")).attr("aria-modal",!0).attr("role","dialog").append(h.c("div").classAdd("dtaf-list-items")),offsetParent:null,start:null,select:{top:h.c("div").classAdd("dtaf-select top"),right:h.c("div").classAdd("dtaf-select right"),bottom:h.c("div").classAdd("dtaf-select bottom"),left:h.c("div").classAdd("dtaf-select left")}},this.dom.list.appendTo(this.dom.container),this._init()}_init(){var t=this.s.dt,e=h.s(this.s.dt.table().container()).find("div.dt-scroll-body");t.settings()[0].autoFill=this,e.count()&&"static"===(this.dom.dtScroll=e).css("position")&&e.css("position","relative"),!1!==this.c.enable&&this.enable(),t.on("destroy.autoFill",()=>{this._focusListenerRemove(),this.dom.handle.off()})}_attach(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=e.table().node().offsetParent),l.height&&l.width||(i.appendTo("body"),l.height=i.height("outer"),l.width=i.width("outer")),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height+"px",left:o.left+t.offsetWidth-l.width+"px"}).appendTo(this.dom.offsetParent)):this._detach()}_actionSelector(o){let i=this,l=this.s.dt,n=r.actions,s=[];if(d.object.each(n,function(t,e){e.available(l,o)&&s.push(t)}),1===s.length&&!1===this.c.alwaysAsk){var t=n[s[0]].execute(l,o,null);this._update(t,o)}else if(1<s.length||this.c.alwaysAsk){var a=this.dom.list.children("div.dtaf-list-items").empty();s.push("cancel");for(let t=0;t<s.length;t++){let e=s[t];a.append(h.c("button").classAdd(r.classes.btn).html(n[e].option(l,o)).append(h.c("span").classAdd("dtaf-button").html(l.i18n("autoFill.button",""))).on("click",function(t){"button"===t.target.nodeName.toLowerCase()&&(t=n[e].execute(l,o,h.s(this).closest("button")),i._update(t,o),i.dom.container.remove())}))}this.dom.container.appendTo("body"),this.dom.container.on("click",function(t){t.target===i.dom.container.get(0)&&i.dom.container.remove()}),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).classAdd(r.classes.closeable),this.dom.closeButton.on("click",function(){return i.dom.container.trigger("click")}))}}_detach(){this.dom.attachedTo=null,this.dom.handle.detach()}_drawSelection(t,e){var o,i=this.s.dt,l=this.s.start,n=h.s(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?h.s(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=h.s(i.cell(a.index(),s).node());i.cell(a.get(0)).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.height("outer")-i,a=this._getPosition(l.get(0)).left+l.width("outer")-o,(n=this.dom.select).top.css({top:i+"px",left:o+"px",width:a+"px"}),n.left.css({top:i+"px",left:o+"px",height:t+"px"}),n.bottom.css({top:i+t+"px",left:o+"px",width:a+"px"}),n.right.css({top:i+"px",left:o+a+"px",height:t+"px"}))}_editor(l){var n=this.s.dt;let s=this.c.editor;if(s){var a={},d=[],c=s.fields();for(let i=0,t=l.length;i<t;i++)for(let t=0,e=l[i].length;t<e;t++){var r=l[i][t],u=n.settings()[0].columns[r.index.column];let o=u.editField;if(void 0===o){var h=u.data;for(let t=0,e=c.length;t<e;t++){var f=s.field(c[t]);if(f.dataSrc()===h){o=f.name();break}}}if(!o)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";if("string"!=typeof o)throw"AutoFill with multiple edit fields is not supported";a[o]||(a[o]={});u=n.row(r.index.row).id();a[o][u]=r.set,d.push(r.index)}s.bubble(d,!1).multiSet(a).submit(null,function(){s.close()})}}_emitEvent(t,e){this.s.dt.trigger(t,e)}_focusListener(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?(h.s(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),h.s(n.body).on("click"+t,function(t){h.s(t.target).closest(e.table().body()).count()||i._detach()})):h.s(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){h.s(t.relatedTarget).classHas("dtaf-handle")||i._detach()})}_focusListenerRemove(){var t=this.s.namespace,e=this.s.dt;e.off(".autoFill"),h.s(e.table().body()).off(t),h.s(n.body).off(t),h.w.off(t)}_getPosition(t,e){let o=h.s(this.s.dt.table().node().offsetParent),i=t,l,n=0,s=0;e&&(o=h.s(e));do{var a=i.offsetTop,d=i.offsetLeft;if(l=h.s(i.offsetParent),n+=a+ +parseInt(l.css("border-top-width")||"0"),s+=d+ +parseInt(l.css("border-left-width")||"0"),"body"===i.nodeName.toLowerCase())break}while(i=l.get(0),l.get(0)!==o.get(0));return{top:n,left:s}}_mousedown(t){let e=this;var o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf(h.s(this.dom.start).parent().get(0)),column:h.s(this.dom.start).index()},h.s(n.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&h.s(n.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=o.table().node().offsetParent,i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:c.innerHeight,windowWidth:c.innerWidth,dtTop:i?i.offset().top:0,dtLeft:i?i.offset().left:0,dtHeight:i?i.height("outer"):0,dtWidth:i?i.width("outer"):0}}_mousemove(t){var e=t.touches&&t.touches.length?n.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))}_mouseup(e){h.s(n.body).off(".autoFill");let o=this,d=this.s.dt;var t=this.dom.select,t=(t.top.remove(),t.left.remove(),t.right.remove(),t.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(t.row!==i.row||t.column!==i.column){var l=d.cell(":eq("+t.row+")",t.column+":visible",{page:"current"});if(h.s(l.node()).find("div.DTE").count()){let t=d.editor();t.on("submitSuccess.dtaf close.dtaf",function(){t.off(".dtaf"),setTimeout(function(){o._mouseup(e)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){t.off(".dtaf")}),void t.submit()}else{let n=this._range(t.row,i.row);var c=this._range(t.column,i.column),r=[];let s=d.settings()[0].columns,a=d.columns(this.c.columns).indexes();for(let l=0;l<n.length;l++)r.push(c.map(function(t){var e=d.row(":eq("+n[l]+")",{page:"current"}),e=d.cell(e.index(),t+":visible");let o=e.data();var t=e.index(),i=s[t.column].editField;if(void 0!==i&&(o=u.util.get(i)(d.row(t.row).data())),-1!==a.indexOf(t.column))return{cell:e,data:o,label:e.data(),index:t}}).filter(t=>!!t));this._actionSelector(r),this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null)}}}_range(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i}_shiftScroll(t){var e,o,i,l,n=this,s=this.s.scroll,a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-c.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-c.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;c.scrollTo(c.scrollX+(s.windowHoriz||0),c.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&((t=null==(t=n.dom.dtScroll)?void 0:t.get(0))&&s.dtVert&&(t.scrollTop+=s.dtVert),t)&&s.dtHoriz&&(t.scrollLeft+=s.dtHoriz)},20))}_update(t,i){if(!1!==t){var l,t=this.s.dt,n=t.columns(this.c.columns).indexes(),e=(this._emitEvent("preAutoFill",[t,i]),this._editor(i),null!==this.c.update?this.c.update:!this.c.editor);if(e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)l=i[o][t],-1!==n.indexOf(l.index.column)&&l.cell.data(l.set);t.draw(!1)}this._emitEvent("autoFill",[t,i])}}}return r.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,i,e){let l=+i[0][0].data;var n=e?parseFloat(e.find("input").val()):1;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l,l+=n}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,i,e){var l=i[0][0].data;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[o][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[0][t].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},r.classes={btn:"btn",close:"dtaf-list-close",closeable:"dtaf-list-closeable"},r.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:!0,editor:null,vertical:!0,horizontal:!0},r.version="3.0.1",t.register("autoFill()",function(){return this.inst(this.context)}),t.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),t.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),t.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),h.s(n).on("preInit.dt.autofill",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.autoFill,o=u.defaults.autoFill,t||o)&&(i={},d.is.plainObject(o)&&d.object.assign(i,o),d.is.plainObject(t)&&d.object.assign(i,t),!1!==t)&&new r(e,i)}),u.AutoFill=r,u});
@@ -1,4 +1,4 @@
1
- /*! AutoFill 3.0.0-beta.1 for DataTables
1
+ /*! AutoFill 3.0.1 for DataTables
2
2
  * Copyright (c) SpryMedia Ltd - datatables.net/license
3
3
  */
4
- import DataTable,{Dom,util,Api}from"datatables.net";if(!DataTable||!DataTable.versionCheck||!DataTable.versionCheck("3"))throw"Warning: AutoFill requires DataTables 3 or greater";var _instance=0;class AutoFill{enabled(){return this.s.enabled}enable(t=!0){let e=this;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1});function o(){e.s.handle={height:0,width:0},e.dom.handle.css({height:"",width:""}),e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return window.addEventListener("resize",function(){0<Dom.s("div.dtaf-handle").count()&&e.dom.attachedTo&&e._attach(e.dom.attachedTo)}),window.addEventListener("orientationchange",function(){setTimeout(function(){o(),setTimeout(o,150)},50)}),this}disable(){return this.s.enabled=!1,this._focusListenerRemove(),this}constructor(t,e){this.c=util.object.assignDeep({},AutoFill.defaults,e),this.s={dt:new DataTable.Api(t),enabled:!1,end:{column:0,row:0},handle:{height:0,width:0},namespace:".autoFill"+_instance++,scroll:{windowHeight:0,windowWidth:0,dtTop:0,dtLeft:0,dtHeight:0,dtWidth:0},scrollInterval:null,start:{column:0,row:0}},this.dom={attachedTo:null,container:Dom.c("div").classAdd("dtaf-container"),closeButton:Dom.c("button").classAdd(AutoFill.classes.close).html("&times;"),dtScroll:null,handle:Dom.c("div").classAdd("dtaf-handle"),list:Dom.c("div").classAdd("dtaf-list").html(this.s.dt.i18n("autoFill.info","")).attr("aria-modal",!0).attr("role","dialog").append(Dom.c("div").classAdd("dtaf-list-items")),offsetParent:null,start:null,select:{top:Dom.c("div").classAdd("dtaf-select top"),right:Dom.c("div").classAdd("dtaf-select right"),bottom:Dom.c("div").classAdd("dtaf-select bottom"),left:Dom.c("div").classAdd("dtaf-select left")}},this.dom.list.appendTo(this.dom.container),this._init()}_init(){let t=this;var e=this.s.dt,o=Dom.s(this.s.dt.table().container()).find("div.dt-scroll-body");e.settings()[0].autoFill=this,o.count()&&"static"===(this.dom.dtScroll=o).css("position")&&o.css("position","relative"),!1!==this.c.enable&&this.enable(),e.on("destroy.autoFill",function(){t._focusListenerRemove()})}_attach(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=e.table().node().offsetParent),l.height&&l.width||(i.appendTo("body"),l.height=i.height("outer"),l.width=i.width("outer")),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height+"px",left:o.left+t.offsetWidth-l.width+"px"}).appendTo(this.dom.offsetParent)):this._detach()}_actionSelector(o){let i=this,l=this.s.dt,n=AutoFill.actions,s=[];if(util.object.each(n,function(t,e){e.available(l,o)&&s.push(t)}),1===s.length&&!1===this.c.alwaysAsk){var t=n[s[0]].execute(l,o,null);this._update(t,o)}else if(1<s.length||this.c.alwaysAsk){var a=this.dom.list.children("div.dtaf-list-items").empty();s.push("cancel");for(let t=0;t<s.length;t++){let e=s[t];a.append(Dom.c("button").classAdd(AutoFill.classes.btn).html(n[e].option(l,o)).append(Dom.c("span").classAdd("dtaf-button").html(l.i18n("autoFill.button",""))).on("click",function(t){"button"===t.target.nodeName.toLowerCase()&&(t=n[e].execute(l,o,Dom.s(this).closest("button")),i._update(t,o),i.dom.container.remove())}))}this.dom.container.appendTo("body"),this.dom.container.on("click",function(t){t.target===i.dom.container.get(0)&&i.dom.container.remove()}),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).classAdd(AutoFill.classes.closeable),this.dom.closeButton.on("click",function(){return i.dom.container.trigger("click")}))}}_detach(){this.dom.attachedTo=null,this.dom.handle.detach()}_drawSelection(t,e){var o,i=this.s.dt,l=this.s.start,n=Dom.s(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?Dom.s(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=Dom.s(i.cell(a.index(),s).node());i.cell(a.get(0)).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.height("outer")-i,a=this._getPosition(l.get(0)).left+l.width("outer")-o,(n=this.dom.select).top.css({top:i+"px",left:o+"px",width:a+"px"}),n.left.css({top:i+"px",left:o+"px",height:t+"px"}),n.bottom.css({top:i+t+"px",left:o+"px",width:a+"px"}),n.right.css({top:i+"px",left:o+a+"px",height:t+"px"}))}_editor(l){var n=this.s.dt;let s=this.c.editor;if(s){var a={},d=[],c=s.fields();for(let i=0,t=l.length;i<t;i++)for(let t=0,e=l[i].length;t<e;t++){var r=l[i][t],u=n.settings()[0].columns[r.index.column];let o=u.editField;if(void 0===o){var h=u.data;for(let t=0,e=c.length;t<e;t++){var f=s.field(c[t]);if(f.dataSrc()===h){o=f.name();break}}}if(!o)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";if("string"!=typeof o)throw"AutoFill with multiple edit fields is not supported";a[o]||(a[o]={});u=n.row(r.index.row).id();a[o][u]=r.set,d.push(r.index)}s.bubble(d,!1).multiSet(a).submit(null,function(){s.close()})}}_emitEvent(t,e){this.s.dt.trigger(t,e)}_focusListener(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?(Dom.s(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),Dom.s(document.body).on("click"+t,function(t){Dom.s(t.target).closest(e.table().body()).count()||i._detach()})):Dom.s(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){Dom.s(t.relatedTarget).classHas("dtaf-handle")||i._detach()})}_focusListenerRemove(){var t=this.s.dt;t.off(".autoFill"),Dom.s(t.table().body()).off(this.s.namespace),Dom.s(document.body).off(this.s.namespace)}_getPosition(t,e){let o=Dom.s(this.s.dt.table().node().offsetParent),i=t,l,n=0,s=0;e&&(o=Dom.s(e));do{var a=i.offsetTop,d=i.offsetLeft;if(l=Dom.s(i.offsetParent),n+=a+ +parseInt(l.css("border-top-width")||"0"),s+=d+ +parseInt(l.css("border-left-width")||"0"),"body"===i.nodeName.toLowerCase())break}while(i=l.get(0),l.get(0)!==o.get(0));return{top:n,left:s}}_mousedown(t){let e=this;var o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf(Dom.s(this.dom.start).parent().get(0)),column:Dom.s(this.dom.start).index()},Dom.s(document.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&Dom.s(document.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=o.table().node().offsetParent,i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:window.innerHeight,windowWidth:window.innerWidth,dtTop:i?i.offset().top:0,dtLeft:i?i.offset().left:0,dtHeight:i?i.height("outer"):0,dtWidth:i?i.width("outer"):0}}_mousemove(t){var e=t.touches&&t.touches.length?document.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))}_mouseup(e){Dom.s(document.body).off(".autoFill");let o=this,d=this.s.dt;var t=this.dom.select,t=(t.top.remove(),t.left.remove(),t.right.remove(),t.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(t.row!==i.row||t.column!==i.column){var l=d.cell(":eq("+t.row+")",t.column+":visible",{page:"current"});if(Dom.s(l.node()).find("div.DTE").count()){let t=d.editor();t.on("submitSuccess.dtaf close.dtaf",function(){t.off(".dtaf"),setTimeout(function(){o._mouseup(e)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){t.off(".dtaf")}),void t.submit()}else{let n=this._range(t.row,i.row);var c=this._range(t.column,i.column),r=[];let s=d.settings()[0].columns,a=d.columns(this.c.columns).indexes();for(let l=0;l<n.length;l++)r.push(c.map(function(t){var e=d.row(":eq("+n[l]+")",{page:"current"}),e=d.cell(e.index(),t+":visible");let o=e.data();var t=e.index(),i=s[t.column].editField;if(void 0!==i&&(o=DataTable.util.get(i)(d.row(t.row).data())),-1!==a.indexOf(t.column))return{cell:e,data:o,label:e.data(),index:t}}).filter(t=>!!t));this._actionSelector(r),this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null)}}}_range(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i}_shiftScroll(t){var e,o,i,l,n=this,s=this.s.scroll,a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-window.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-window.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;window.scrollTo(window.scrollX+(s.windowHoriz||0),window.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&((t=null==(t=n.dom.dtScroll)?void 0:t.get(0))&&s.dtVert&&(t.scrollTop+=s.dtVert),t)&&s.dtHoriz&&(t.scrollLeft+=s.dtHoriz)},20))}_update(t,i){if(!1!==t){var l,t=this.s.dt,n=t.columns(this.c.columns).indexes(),e=(this._emitEvent("preAutoFill",[t,i]),this._editor(i),null!==this.c.update?this.c.update:!this.c.editor);if(e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)l=i[o][t],-1!==n.indexOf(l.index.column)&&l.cell.data(l.set);t.draw(!1)}this._emitEvent("autoFill",[t,i])}}}AutoFill.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,i,e){let l=+i[0][0].data;var n=e?parseFloat(e.find("input").val()):1;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l,l+=n}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,i,e){var l=i[0][0].data;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[o][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[0][t].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},AutoFill.classes={btn:"btn",close:"dtaf-list-close",closeable:"dtaf-list-closeable"},AutoFill.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:!0,editor:null,vertical:!0,horizontal:!0},AutoFill.version="3.0.0-beta.1",Api.register("autoFill()",function(){return this.inst(this.context)}),Api.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),Api.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),Api.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),Dom.s(document).on("preInit.dt.autofill",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.autoFill,o=DataTable.defaults.autoFill,t||o)&&(i={},util.is.plainObject(o)&&util.object.assign(i,o),util.is.plainObject(t)&&util.object.assign(i,t),!1!==t)&&new AutoFill(e,i)}),DataTable.AutoFill=AutoFill;export default DataTable;
4
+ import DataTable,{Dom,util,Api}from"datatables.net";if(!DataTable||!DataTable.versionCheck||!DataTable.versionCheck("3"))throw"Warning: AutoFill requires DataTables 3 or greater";var _instance=0;class AutoFill{enabled(){return this.s.enabled}enable(t=!0){let e=this;var o=this.s.namespace;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1});function i(){e.s.handle={height:0,width:0},e.dom.handle.css({height:"",width:""}),e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return Dom.w.on("resize"+o,function(){0<Dom.s("div.dtaf-handle").count()&&e.dom.attachedTo&&e._attach(e.dom.attachedTo)}),Dom.w.on("orientationchange"+o,function(){setTimeout(function(){i(),setTimeout(i,150)},50)}),this}disable(){return this.s.enabled=!1,this._focusListenerRemove(),this}constructor(t,e){this.c=util.object.assignDeep({},AutoFill.defaults,e),this.s={dt:new DataTable.Api(t),enabled:!1,end:{column:0,row:0},handle:{height:0,width:0},namespace:".autoFill"+_instance++,scroll:{windowHeight:0,windowWidth:0,dtTop:0,dtLeft:0,dtHeight:0,dtWidth:0},scrollInterval:null,start:{column:0,row:0}},this.dom={attachedTo:null,container:Dom.c("div").classAdd("dtaf-container"),closeButton:Dom.c("button").classAdd(AutoFill.classes.close).html("&times;"),dtScroll:null,handle:Dom.c("div").classAdd("dtaf-handle"),list:Dom.c("div").classAdd("dtaf-list").html(this.s.dt.i18n("autoFill.info","")).attr("aria-modal",!0).attr("role","dialog").append(Dom.c("div").classAdd("dtaf-list-items")),offsetParent:null,start:null,select:{top:Dom.c("div").classAdd("dtaf-select top"),right:Dom.c("div").classAdd("dtaf-select right"),bottom:Dom.c("div").classAdd("dtaf-select bottom"),left:Dom.c("div").classAdd("dtaf-select left")}},this.dom.list.appendTo(this.dom.container),this._init()}_init(){var t=this.s.dt,e=Dom.s(this.s.dt.table().container()).find("div.dt-scroll-body");t.settings()[0].autoFill=this,e.count()&&"static"===(this.dom.dtScroll=e).css("position")&&e.css("position","relative"),!1!==this.c.enable&&this.enable(),t.on("destroy.autoFill",()=>{this._focusListenerRemove(),this.dom.handle.off()})}_attach(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=e.table().node().offsetParent),l.height&&l.width||(i.appendTo("body"),l.height=i.height("outer"),l.width=i.width("outer")),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height+"px",left:o.left+t.offsetWidth-l.width+"px"}).appendTo(this.dom.offsetParent)):this._detach()}_actionSelector(o){let i=this,l=this.s.dt,n=AutoFill.actions,s=[];if(util.object.each(n,function(t,e){e.available(l,o)&&s.push(t)}),1===s.length&&!1===this.c.alwaysAsk){var t=n[s[0]].execute(l,o,null);this._update(t,o)}else if(1<s.length||this.c.alwaysAsk){var a=this.dom.list.children("div.dtaf-list-items").empty();s.push("cancel");for(let t=0;t<s.length;t++){let e=s[t];a.append(Dom.c("button").classAdd(AutoFill.classes.btn).html(n[e].option(l,o)).append(Dom.c("span").classAdd("dtaf-button").html(l.i18n("autoFill.button",""))).on("click",function(t){"button"===t.target.nodeName.toLowerCase()&&(t=n[e].execute(l,o,Dom.s(this).closest("button")),i._update(t,o),i.dom.container.remove())}))}this.dom.container.appendTo("body"),this.dom.container.on("click",function(t){t.target===i.dom.container.get(0)&&i.dom.container.remove()}),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).classAdd(AutoFill.classes.closeable),this.dom.closeButton.on("click",function(){return i.dom.container.trigger("click")}))}}_detach(){this.dom.attachedTo=null,this.dom.handle.detach()}_drawSelection(t,e){var o,i=this.s.dt,l=this.s.start,n=Dom.s(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?Dom.s(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=Dom.s(i.cell(a.index(),s).node());i.cell(a.get(0)).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.height("outer")-i,a=this._getPosition(l.get(0)).left+l.width("outer")-o,(n=this.dom.select).top.css({top:i+"px",left:o+"px",width:a+"px"}),n.left.css({top:i+"px",left:o+"px",height:t+"px"}),n.bottom.css({top:i+t+"px",left:o+"px",width:a+"px"}),n.right.css({top:i+"px",left:o+a+"px",height:t+"px"}))}_editor(l){var n=this.s.dt;let s=this.c.editor;if(s){var a={},d=[],c=s.fields();for(let i=0,t=l.length;i<t;i++)for(let t=0,e=l[i].length;t<e;t++){var r=l[i][t],u=n.settings()[0].columns[r.index.column];let o=u.editField;if(void 0===o){var h=u.data;for(let t=0,e=c.length;t<e;t++){var f=s.field(c[t]);if(f.dataSrc()===h){o=f.name();break}}}if(!o)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";if("string"!=typeof o)throw"AutoFill with multiple edit fields is not supported";a[o]||(a[o]={});u=n.row(r.index.row).id();a[o][u]=r.set,d.push(r.index)}s.bubble(d,!1).multiSet(a).submit(null,function(){s.close()})}}_emitEvent(t,e){this.s.dt.trigger(t,e)}_focusListener(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?(Dom.s(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),Dom.s(document.body).on("click"+t,function(t){Dom.s(t.target).closest(e.table().body()).count()||i._detach()})):Dom.s(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){Dom.s(t.relatedTarget).classHas("dtaf-handle")||i._detach()})}_focusListenerRemove(){var t=this.s.namespace,e=this.s.dt;e.off(".autoFill"),Dom.s(e.table().body()).off(t),Dom.s(document.body).off(t),Dom.w.off(t)}_getPosition(t,e){let o=Dom.s(this.s.dt.table().node().offsetParent),i=t,l,n=0,s=0;e&&(o=Dom.s(e));do{var a=i.offsetTop,d=i.offsetLeft;if(l=Dom.s(i.offsetParent),n+=a+ +parseInt(l.css("border-top-width")||"0"),s+=d+ +parseInt(l.css("border-left-width")||"0"),"body"===i.nodeName.toLowerCase())break}while(i=l.get(0),l.get(0)!==o.get(0));return{top:n,left:s}}_mousedown(t){let e=this;var o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf(Dom.s(this.dom.start).parent().get(0)),column:Dom.s(this.dom.start).index()},Dom.s(document.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&Dom.s(document.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=o.table().node().offsetParent,i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:window.innerHeight,windowWidth:window.innerWidth,dtTop:i?i.offset().top:0,dtLeft:i?i.offset().left:0,dtHeight:i?i.height("outer"):0,dtWidth:i?i.width("outer"):0}}_mousemove(t){var e=t.touches&&t.touches.length?document.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))}_mouseup(e){Dom.s(document.body).off(".autoFill");let o=this,d=this.s.dt;var t=this.dom.select,t=(t.top.remove(),t.left.remove(),t.right.remove(),t.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(t.row!==i.row||t.column!==i.column){var l=d.cell(":eq("+t.row+")",t.column+":visible",{page:"current"});if(Dom.s(l.node()).find("div.DTE").count()){let t=d.editor();t.on("submitSuccess.dtaf close.dtaf",function(){t.off(".dtaf"),setTimeout(function(){o._mouseup(e)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){t.off(".dtaf")}),void t.submit()}else{let n=this._range(t.row,i.row);var c=this._range(t.column,i.column),r=[];let s=d.settings()[0].columns,a=d.columns(this.c.columns).indexes();for(let l=0;l<n.length;l++)r.push(c.map(function(t){var e=d.row(":eq("+n[l]+")",{page:"current"}),e=d.cell(e.index(),t+":visible");let o=e.data();var t=e.index(),i=s[t.column].editField;if(void 0!==i&&(o=DataTable.util.get(i)(d.row(t.row).data())),-1!==a.indexOf(t.column))return{cell:e,data:o,label:e.data(),index:t}}).filter(t=>!!t));this._actionSelector(r),this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null)}}}_range(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i}_shiftScroll(t){var e,o,i,l,n=this,s=this.s.scroll,a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-window.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-window.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;window.scrollTo(window.scrollX+(s.windowHoriz||0),window.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&((t=null==(t=n.dom.dtScroll)?void 0:t.get(0))&&s.dtVert&&(t.scrollTop+=s.dtVert),t)&&s.dtHoriz&&(t.scrollLeft+=s.dtHoriz)},20))}_update(t,i){if(!1!==t){var l,t=this.s.dt,n=t.columns(this.c.columns).indexes(),e=(this._emitEvent("preAutoFill",[t,i]),this._editor(i),null!==this.c.update?this.c.update:!this.c.editor);if(e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)l=i[o][t],-1!==n.indexOf(l.index.column)&&l.cell.data(l.set);t.draw(!1)}this._emitEvent("autoFill",[t,i])}}}AutoFill.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,i,e){let l=+i[0][0].data;var n=e?parseFloat(e.find("input").val()):1;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l,l+=n}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,i,e){var l=i[0][0].data;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[o][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[0][t].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},AutoFill.classes={btn:"btn",close:"dtaf-list-close",closeable:"dtaf-list-closeable"},AutoFill.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:!0,editor:null,vertical:!0,horizontal:!0},AutoFill.version="3.0.1",Api.register("autoFill()",function(){return this.inst(this.context)}),Api.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),Api.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),Api.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),Dom.s(document).on("preInit.dt.autofill",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.autoFill,o=DataTable.defaults.autoFill,t||o)&&(i={},util.is.plainObject(o)&&util.object.assign(i,o),util.is.plainObject(t)&&util.object.assign(i,t),!1!==t)&&new AutoFill(e,i)}),DataTable.AutoFill=AutoFill;export default DataTable;
@@ -1,4 +1,4 @@
1
- /*! AutoFill 3.0.0-beta.1 for DataTables
1
+ /*! AutoFill 3.0.1 for DataTables
2
2
  * Copyright (c) SpryMedia Ltd - datatables.net/license
3
3
  */
4
4
 
@@ -18,6 +18,7 @@ class AutoFill {
18
18
  }
19
19
  enable(flag = true) {
20
20
  let that = this;
21
+ let namespace = this.s.namespace;
21
22
  if (flag === false) {
22
23
  return this.disable();
23
24
  }
@@ -40,13 +41,13 @@ class AutoFill {
40
41
  that._attach(that.dom.attachedTo);
41
42
  }
42
43
  };
43
- window.addEventListener('resize', function () {
44
+ Dom.w.on('resize' + namespace, function () {
44
45
  let handle = Dom.s('div.dtaf-handle');
45
46
  if (handle.count() > 0 && that.dom.attachedTo) {
46
47
  that._attach(that.dom.attachedTo);
47
48
  }
48
49
  });
49
- window.addEventListener('orientationchange', function () {
50
+ Dom.w.on('orientationchange' + namespace, function () {
50
51
  setTimeout(function () {
51
52
  orientationReset();
52
53
  setTimeout(orientationReset, 150);
@@ -87,14 +88,12 @@ class AutoFill {
87
88
  this.dom = {
88
89
  attachedTo: null,
89
90
  container: Dom.c('div').classAdd('dtaf-container'),
90
- closeButton: Dom
91
- .c('button')
91
+ closeButton: Dom.c('button')
92
92
  .classAdd(AutoFill.classes.close)
93
93
  .html('&times;'),
94
94
  dtScroll: null,
95
95
  handle: Dom.c('div').classAdd('dtaf-handle'),
96
- list: Dom
97
- .c('div')
96
+ list: Dom.c('div')
98
97
  .classAdd('dtaf-list')
99
98
  .html(this.s.dt.i18n('autoFill.info', ''))
100
99
  .attr('aria-modal', true)
@@ -120,12 +119,9 @@ class AutoFill {
120
119
  * Initialise the RowReorder instance
121
120
  */
122
121
  _init() {
123
- let that = this;
124
122
  let dt = this.s.dt;
125
123
  // Need to account for scrolling as it has a different DOM structure
126
- let dtScroll = Dom
127
- .s(this.s.dt.table().container())
128
- .find('div.dt-scroll-body');
124
+ let dtScroll = Dom.s(this.s.dt.table().container()).find('div.dt-scroll-body');
129
125
  // Make the instance accessible to the API
130
126
  dt.settings()[0].autoFill = this;
131
127
  if (dtScroll.count()) {
@@ -138,8 +134,9 @@ class AutoFill {
138
134
  if (this.c.enable !== false) {
139
135
  this.enable();
140
136
  }
141
- dt.on('destroy.autoFill', function () {
142
- that._focusListenerRemove();
137
+ dt.on('destroy.autoFill', () => {
138
+ this._focusListenerRemove();
139
+ this.dom.handle.off();
143
140
  });
144
141
  }
145
142
  /**
@@ -211,12 +208,10 @@ class AutoFill {
211
208
  available.push('cancel');
212
209
  for (let i = 0; i < available.length; i++) {
213
210
  let name = available[i];
214
- list.append(Dom
215
- .c('button')
211
+ list.append(Dom.c('button')
216
212
  .classAdd(AutoFill.classes.btn)
217
213
  .html(actions[name].option(dt, cells))
218
- .append(Dom
219
- .c('span')
214
+ .append(Dom.c('span')
220
215
  .classAdd('dtaf-button')
221
216
  .html(dt.i18n('autoFill.button', '')))
222
217
  .on('click', function (e) {
@@ -439,11 +434,16 @@ class AutoFill {
439
434
  });
440
435
  }
441
436
  }
437
+ /**
438
+ * Clean up the event listeners
439
+ */
442
440
  _focusListenerRemove() {
443
- var dt = this.s.dt;
441
+ let namespace = this.s.namespace;
442
+ let dt = this.s.dt;
444
443
  dt.off('.autoFill');
445
- Dom.s(dt.table().body()).off(this.s.namespace);
446
- Dom.s(document.body).off(this.s.namespace);
444
+ Dom.s(dt.table().body()).off(namespace);
445
+ Dom.s(document.body).off(namespace);
446
+ Dom.w.off(namespace);
447
447
  }
448
448
  /**
449
449
  * Get the position of a node, relative to another, including any scrolling
@@ -898,7 +898,7 @@ AutoFill.defaults = {
898
898
  horizontal: true
899
899
  };
900
900
  /** AutoFill version */
901
- AutoFill.version = '3.0.0-beta.1';
901
+ AutoFill.version = '3.0.1';
902
902
 
903
903
  // Doesn't do anything - Not documented
904
904
  Api.register('autoFill()', function () {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "js/dataTables.autoFill.js",
5
5
  "module": "js/dataTables.autoFill.mjs",
6
6
  "types": "./types/types.d.ts",
7
- "version": "3.0.0-beta.1",
7
+ "version": "3.0.1",
8
8
  "files": [
9
9
  "js/**/*.js",
10
10
  "js/**/*.mjs",
@@ -19,7 +19,7 @@
19
19
  "sort"
20
20
  ],
21
21
  "dependencies": {
22
- "datatables.net": "3.0.0-beta.1"
22
+ "datatables.net": "^3"
23
23
  },
24
24
  "author": {
25
25
  "name": "SpryMedia Ltd",
@@ -30,6 +30,6 @@
30
30
  "license": "MIT",
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "https://github.com/DataTables/DataTablesAutoFill"
33
+ "url": "git+https://github.com/DataTables/AutoFill.git"
34
34
  }
35
35
  }
package/types/types.d.ts CHANGED
@@ -1,13 +1,100 @@
1
- import DataTables__default, { ColumnSelector, Api, ApiCellMethods, CellIdxWithVisible, Dom, Context } from 'datatables.net';
2
- export * from 'datatables.net';
1
+ import DataTables, { ColumnSelector, Api, ApiCellMethods, CellIdxWithVisible, Dom } from 'datatables.net';
3
2
  export { default } from 'datatables.net';
4
3
 
4
+ declare module 'datatables.net' {
5
+ interface Options {
6
+ /**
7
+ * autoFill extension options
8
+ */
9
+ autoFill?: boolean | Partial<AutoFillDefaults>;
10
+ }
11
+ interface Defaults {
12
+ /**
13
+ * autoFill extension options
14
+ */
15
+ autoFill?: AutoFillDefaults;
16
+ }
17
+ interface Language {
18
+ /**
19
+ * AutoFill language options
20
+ */
21
+ autoFill?: ConfigAutoFillLanguage;
22
+ }
23
+ interface Api<T> {
24
+ /**
25
+ * AutoFill methods container
26
+ *
27
+ * @returns Api for chaining with the additional autoFill methods
28
+ */
29
+ autoFill: ApiAutoFill<T>;
30
+ }
31
+ interface DataTablesStatic {
32
+ /**
33
+ * AutoFill class
34
+ */
35
+ AutoFill: AutoFill;
36
+ }
37
+ }
38
+ interface ConfigAutoFillLanguage {
39
+ /**
40
+ * Multi-fill selector button text
41
+ */
42
+ button?: string;
43
+ /**
44
+ * Multi-fill selector cancel option message
45
+ */
46
+ cancel?: string;
47
+ /**
48
+ * Multi-fill selector message for the _full fill_ fill type
49
+ */
50
+ fill?: string;
51
+ /**
52
+ * Multi-fill selector message for the _horizontal fill_ fill type
53
+ */
54
+ fillHorizontal?: string;
55
+ /**
56
+ * Multi-fill selector message for the _vertical fill_ fill type
57
+ */
58
+ fillVertical?: string;
59
+ /**
60
+ * Multi-fill selector message for the _increment_ fill type
61
+ */
62
+ increment?: string;
63
+ /**
64
+ * Information message shown at the top of the fill type selector
65
+ */
66
+ info?: string;
67
+ }
68
+ interface ApiAutoFill<T> {
69
+ (): ApiAutoFillMethods<T>;
70
+ }
71
+ interface ApiAutoFillMethods<T> extends Api<T> {
72
+ /**
73
+ * Disable AutoFill. Please note that this disallows future interactions with the table (until re-enabled).
74
+ *
75
+ * @returns DataTables Api instance
76
+ */
77
+ disable(): Api<T>;
78
+ /**
79
+ * Enable end user and API modification of the focused cells in the DataTable. Differing levels of enablement are available via the optional parameter.
80
+ *
81
+ * @param flag can be true or false to signify whether to enable or disable
82
+ * @returns DataTables Api instance
83
+ */
84
+ enable(flag?: string | boolean): Api<T>;
85
+ /**
86
+ * This method will return a boolean value indicating if AutoFill is enabled or not on the selected table.
87
+ *
88
+ * @returns boolean signifying if autofill is enables
89
+ */
90
+ enabled(): boolean;
91
+ }
5
92
  interface Classes {
6
93
  btn: string;
7
94
  close: string;
8
95
  closeable: string;
9
96
  }
10
- interface Defaults {
97
+ interface AutoFillDefaults {
11
98
  /** Ask user what they want to do, even for a single option */
12
99
  alwaysAsk: boolean;
13
100
  /** Show a "Close" button in the list of options */
@@ -27,6 +114,34 @@ interface Defaults {
27
114
  /** Enable horizontal fill */
28
115
  horizontal: boolean;
29
116
  }
117
+ /** Common and useful DOM elements for the class instance */
118
+ interface InternalDom {
119
+ attachedTo: HTMLElement | null;
120
+ /** Fill type chooser background */
121
+ container: Dom;
122
+ /** Popover close button */
123
+ closeButton: Dom;
124
+ /** DataTables scrolling container */
125
+ dtScroll: Dom | null;
126
+ /** AutoFill handle */
127
+ handle: Dom;
128
+ /** Fill type chooser */
129
+ list: Dom;
130
+ /** Offset parent element */
131
+ offsetParent: HTMLElement | null;
132
+ /**
133
+ * Selected cells outline - Need to use 4 elements, otherwise the mouse over
134
+ * if you back into the selected rectangle will be over that element, rather
135
+ * than the cells!
136
+ */
137
+ select: {
138
+ top: Dom;
139
+ right: Dom;
140
+ bottom: Dom;
141
+ left: Dom;
142
+ };
143
+ start: HTMLElement | null;
144
+ }
30
145
  interface Action {
31
146
  available(dt: Api, cells: SelectedCells[][]): boolean;
32
147
  option(dt: Api, cells: SelectedCells[][]): string;
@@ -39,253 +154,41 @@ interface SelectedCells {
39
154
  label: string;
40
155
  set?: any;
41
156
  }
42
-
43
- /*! AutoFill for DataTables
44
- * Copyright (c) SpryMedia Ltd - datatables.net/license
45
- */
46
-
47
- declare class AutoFill {
48
- /**
49
- * AutoFill actions. The options here determine how AutoFill will fill the
50
- * data in the table when the user has selected a range of cells. Please see
51
- * the documentation on the DataTables site for full details on how to
52
- * create plug- ins.
53
- */
54
- static actions: Record<string, Action>;
55
- /** Class names used by AutoFill for customisation */
56
- static classes: Classes;
57
- /** Defaults */
58
- static defaults: Defaults;
59
- /** AutoFill version */
60
- static version: string;
61
- enabled(): boolean;
62
- enable(flag?: boolean): this;
63
- disable(): this;
64
- private c;
65
- private dom;
66
- private s;
67
- constructor(dt: Api | Context, opts?: Partial<Defaults>);
68
- /**
69
- * Initialise the RowReorder instance
70
- */
71
- private _init;
72
- /**
73
- * Display the AutoFill drag handle by appending it to a table cell. This is
74
- * the opposite of the _detach method.
75
- *
76
- * @param node Cell to insert the handle into
77
- */
78
- private _attach;
79
- /**
80
- * Determine can the fill type should be. This can be automatic, or ask the
81
- * end user.
82
- *
83
- * @param cells Information about the selected cells from the key up
84
- * function
85
- */
86
- private _actionSelector;
87
- /**
88
- * Remove the AutoFill handle from the document
89
- */
90
- private _detach;
91
- /**
92
- * Draw the selection outline by calculating the range between the start
93
- * and end cells, then placing the highlighting elements to draw a rectangle
94
- *
95
- * @param target End cell
96
- * @param e Originating event
97
- * @private
98
- */
99
- private _drawSelection;
100
- /**
101
- * Use the Editor API to perform an update based on the new data for the
102
- * cells
103
- *
104
- * @param cells Information about the selected cells from the key up
105
- * function
106
- */
107
- private _editor;
108
- /**
109
- * Emit an event on the DataTable for listeners
110
- *
111
- * @param name Event name
112
- * @param args Event arguments
113
- */
114
- private _emitEvent;
115
- /**
116
- * Attach suitable listeners (based on the configuration) that will attach
117
- * and detach the AutoFill handle in the document.
118
- */
119
- private _focusListener;
120
- private _focusListenerRemove;
121
- /**
122
- * Get the position of a node, relative to another, including any scrolling
123
- * offsets.
124
- *
125
- * @param node Node to get the position of
126
- * @param targetHost Node to use as the parent
127
- * @return Offset calculation
128
- */
129
- private _getPosition;
130
- /**
131
- * Start mouse drag - selects the start cell
132
- *
133
- * @param e Mouse down event
134
- */
135
- private _mousedown;
136
- /**
137
- * Mouse drag - selects the end cell and update the selection display for
138
- * the end user
139
- *
140
- * @param e Mouse move event
141
- */
142
- private _mousemove;
143
- /**
144
- * End mouse drag - perform the update actions
145
- *
146
- * @param e Mouse up event
147
- * @private
148
- */
149
- private _mouseup;
150
- /**
151
- * Create an array with a range of numbers defined by the start and end
152
- * parameters passed in (inclusive!).
153
- *
154
- * @param start Start
155
- * @param end End
156
- */
157
- private _range;
158
- /**
159
- * Move the window and DataTables scrolling during a drag to scroll new
160
- * content into view. This is done by proximity to the edge of the scrolling
161
- * container of the mouse - for example near the top edge of the window
162
- * should scroll up. This is a little complicated as there are two elements
163
- * that can be scrolled - the window and the DataTables scrolling view port
164
- * (if scrollX and / or scrollY is enabled).
165
- *
166
- * @param e Mouse move event object
167
- */
168
- private _shiftScroll;
169
- /**
170
- * Update the DataTable after the user has selected what they want to do
171
- *
172
- * @param result Return from the `execute` method - can be false internally
173
- * to do nothing. This is not documented for plug-ins and is used only by
174
- * the cancel option.
175
- * @param cells Information about the selected cells from the key up
176
- * function, augmented with the set values
177
- */
178
- private _update;
157
+ interface Settings {
158
+ /** Host DataTable instance */
159
+ dt: Api;
160
+ /** Enabled setting */
161
+ enabled: boolean;
162
+ end: {
163
+ column: number;
164
+ row: number;
165
+ };
166
+ /** Cached handle size */
167
+ handle: {
168
+ height: number;
169
+ width: number;
170
+ };
171
+ /** Unique namespace for events attached to the document */
172
+ namespace: string;
173
+ start: {
174
+ column: number;
175
+ row: number;
176
+ };
177
+ /** Cached dimension information for use in the mouse move event handler */
178
+ scroll: {
179
+ windowHeight: number;
180
+ windowWidth: number;
181
+ dtTop: number;
182
+ dtLeft: number;
183
+ dtHeight: number;
184
+ dtWidth: number;
185
+ windowVert?: number;
186
+ windowHoriz?: number;
187
+ dtVert?: number;
188
+ dtHoriz?: number;
189
+ };
190
+ /** Interval object used for smooth scrolling */
191
+ scrollInterval: any;
179
192
  }
180
193
 
181
- // Type definitions for DataTables AutoFill
182
-
183
-
184
-
185
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
186
- * DataTables' types integration
187
- */
188
- declare module 'datatables.net' {
189
- interface Config {
190
- /**
191
- * autoFill extension options
192
- */
193
- autoFill?: boolean | Partial<Defaults>;
194
- }
195
-
196
- interface ConfigLanguage {
197
- /**
198
- * AutoFill language options
199
- */
200
- autoFill?: ConfigAutoFillLanguage;
201
- }
202
-
203
- interface Api<T> {
204
- /**
205
- * AutoFill methods container
206
- *
207
- * @returns Api for chaining with the additional autoFill methods
208
- */
209
- autoFill: ApiAutoFill<T>;
210
- }
211
-
212
- interface DataTablesStatic {
213
- /**
214
- * AutoFill class
215
- */
216
- AutoFill: AutoFill;
217
- }
218
- }
219
-
220
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
221
- * Options
222
- */
223
-
224
- interface ConfigAutoFillLanguage {
225
- /**
226
- * Multi-fill selector button text
227
- */
228
- button?: string;
229
-
230
- /**
231
- * Multi-fill selector cancel option message
232
- */
233
- cancel?: string;
234
-
235
- /**
236
- * Multi-fill selector message for the _full fill_ fill type
237
- */
238
- fill?: string;
239
-
240
- /**
241
- * Multi-fill selector message for the _horizontal fill_ fill type
242
- */
243
- fillHorizontal?: string;
244
-
245
- /**
246
- * Multi-fill selector message for the _vertical fill_ fill type
247
- */
248
- fillVertical?: string;
249
-
250
- /**
251
- * Multi-fill selector message for the _increment_ fill type
252
- */
253
- increment?: string;
254
-
255
- /**
256
- * Information message shown at the top of the fill type selector
257
- */
258
- info?: string;
259
- }
260
-
261
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
262
- * API
263
- */
264
-
265
- interface ApiAutoFill<T> {
266
- (): ApiAutoFillMethods<T>;
267
- }
268
-
269
- interface ApiAutoFillMethods<T> extends Api<T> {
270
- /**
271
- * Disable AutoFill. Please note that this disallows future interactions with the table (until re-enabled).
272
- *
273
- * @returns DataTables Api instance
274
- */
275
- disable(): Api<T>;
276
-
277
- /**
278
- * Enable end user and API modification of the focused cells in the DataTable. Differing levels of enablement are available via the optional parameter.
279
- *
280
- * @param flag can be true or false to signify whether to enable or disable
281
- * @returns DataTables Api instance
282
- */
283
- enable(flag?: string | boolean): Api<T>;
284
-
285
- /**
286
- * This method will return a boolean value indicating if AutoFill is enabled or not on the selected table.
287
- *
288
- * @returns boolean signifying if autofill is enables
289
- */
290
- enabled(): boolean;
291
- }
194
+ export type { Action, AutoFillDefaults, Classes, InternalDom, SelectedCells, Settings };