UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

1 lines 17.8 kB
module.exports=function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}({0:function(e,t,n){e.exports=n(972)},3:function(e,t){e.exports=function(){throw Error("define cannot be used indirect")}},964:function(e,t){e.exports=require("./formatblock")},972:function(e,t,n){var o,i,l;!function(a,define){i=[n(964),n(973)],o=a,l="function"==typeof o?o.apply(t,i):o,!(void 0!==l&&(e.exports=l))}(function(){!function(e,t){var n=window.kendo,o=e.extend,i=e.proxy,l=n.ui.editor,a=l.Dom,s=l.EditorUtils,r=l.RangeUtils,p=l.Command,d="kendoEditor",c="k-state-active",h="k-state-selected",u="scope",m="row",f="col",g="rowgroup",b="colgroup",w="colspan",_="rowspan",C="table",x="thead",v="tbody",T="tr",y="td",S="th",R=l.Tool,A=l.ToolTemplate,I=l.InsertHtmlCommand,k=l.BlockFormatFinder,N=l.EditorUtils.registerTool,z=n.getTouches,H=n.template,M="<td style='width:#=width#%;'>#=content#</td>",E=new k([{tags:[C]}]),P=I.extend({init:function(t){var n=e.extend({postProcess:this.postProcess,skipCleaners:!0},t||{});I.fn.init.call(this,n)},_tableHtml:function(e,t){var n,o;return e=e||1,t=t||1,n=H(M)({width:100/t,content:l.emptyTableCellContent}),o=100/e,"<table class='k-table' data-last>"+Array(e+1).join("<tr style='height:"+o+"%;'>"+Array(t+1).join(n)+"</tr>")+"</table>"},postProcess:function(t,n){var o=e("table[data-last]",t.document).removeAttr("data-last");n.setStart(o.find(y)[0],0),n.collapse(!0),t.selectRange(n)},exec:function(){var e=this.options;e.html=this._tableHtml(e.rows,e.columns),I.fn.exec.call(this)}}),B=R.extend({initialize:function(t,n){var o,a,r,p;R.fn.initialize.call(this,t,n),o=e(this.options.popupTemplate).appendTo("body").kendoPopup({anchor:t,copyAnchorStyles:!1,open:i(this._open,this),activate:i(this._activate,this),close:i(this._close,this)}).data("kendoPopup"),t.click(i(this._toggle,this)).keydown(i(this._keydown,this)),a=this._editor=n.editor,this._popup=o,r=new l.TableWizardTool({template:new A({template:s.tableWizardButtonTemplate,title:a.options.messages.tableWizard}),command:l.TableWizardCommand,insertNewTable:!0}),N("tableWizardInsert",r),p=e("<div>"+r.options.template.getHtml()+"</div>"),p.appendTo(o.element),a.toolbar&&a.toolbar.attachToolsEvents(p)},popup:function(){return this._popup},_activate:e.noop,_open:function(){this._popup.options.anchor.addClass(c)},_close:function(){this._popup.options.anchor.removeClass(c)},_keydown:function(e){var t=n.keys,o=e.keyCode;o==t.DOWN&&e.altKey?this._popup.open():o==t.ESC&&this._popup.close()},_toggle:function(t){var n=e(t.target).closest(".k-tool");n.hasClass("k-state-disabled")||this.popup().toggle()},update:function(e){var t=this.popup();t.wrapper&&"block"==t.wrapper.css("display")&&t.close(),e.removeClass("k-state-hover")},destroy:function(){this._popup.destroy()}}),W=B.extend({init:function(t){this.cols=8,this.rows=6,B.fn.init.call(this,e.extend(t,{command:P,popupTemplate:"<div class='k-ct-popup'>"+Array(this.cols*this.rows+1).join("<span class='k-ct-cell k-state-disabled'></span>")+"<div class='k-status'></div></div>"}))},_activate:function(){function t(t){var n=e(window);return{row:Math.floor((t.clientY+n.scrollTop()-c.top)/i)+1,col:Math.floor((t.clientX+n.scrollLeft()-c.left)/o)+1}}var o,i,l=this,a=l._popup.element,s=a.find(".k-ct-cell"),r=s.eq(0),p=s.eq(s.length-1),c=n.getOffset(r),h=n.getOffset(p),u=l.cols,m=l.rows;a.find("*").addBack().attr("unselectable","on"),h.left+=p[0].offsetWidth,h.top+=p[0].offsetHeight,o=(h.left-c.left)/u,i=(h.top-c.top)/m,a.autoApplyNS(d).on("mousemove",".k-ct-cell",function(e){l._setTableSize(t(e))}).on("mouseleave",".k-ct-cell",function(){l._setTableSize()}).on("down",".k-ct-cell",function(e){e.preventDefault();var n=z(e)[0];l._exec(t(n.location))})},_valid:function(e){return e&&e.row>0&&e.col>0&&e.row<=this.rows&&e.col<=this.cols},_exec:function(e){this._valid(e)&&(this._editor.exec("createTable",{rows:e.row,columns:e.col}),this._popup.close())},_setTableSize:function(t){var o=this._popup.element,i=o.find(".k-status"),l=o.find(".k-ct-cell"),a=this.cols,s=this._editor.options.messages;this._valid(t)?(i.text(n.format(s.createTableHint,t.row,t.col)),l.each(function(n){e(this).toggleClass(h,n%a<t.col&&n/a<t.row)})):(i.text(s.createTable),l.removeClass(h))},_keydown:function(e){var t,o,i,l,a,s,r,p;B.fn._keydown.call(this,e),this._popup.visible()&&(t=n.keys,o=e.keyCode,i=this._popup.element.find(".k-ct-cell"),l=Math.max(i.filter(".k-state-selected").last().index(),0),a=Math.floor(l/this.cols),s=l%this.cols,r=!1,o!=t.DOWN||e.altKey?o==t.UP?(r=!0,a--):o==t.RIGHT?(r=!0,s++):o==t.LEFT&&(r=!0,s--):(r=!0,a++),p={row:Math.max(1,Math.min(this.rows,a+1)),col:Math.max(1,Math.min(this.cols,s+1))},o==t.ENTER?this._exec(p):this._setTableSize(p),r&&(e.preventDefault(),e.stopImmediatePropagation()))},_open:function(){var e=this._editor.options.messages;B.fn._open.call(this),this.popup().element.find(".k-status").text(e.createTable).end().find(".k-ct-cell").removeClass(h)},_close:function(){B.fn._close.call(this),this.popup().element.off("."+d)}}),j=p.extend({_clearColIndexAttr:function(e){a.clearTableMappings(e,"col-index")},_mapColIndices:function(e){a.reMapTableColumns(e,"col-index")},_findRowSpanCell:function(t,n,o){var i,l,a;for(a=n;a>=0;a--)if(i=t.rows[a],l=e(i).find("[col-index="+o+"]"),l.length)return l},_resetTableResizing:function(e){e._destroyResizings(),e._initializeColumnResizing(),e._initializeRowResizing(),e._initializeTableResizing()},_findNextTdInRow:function(e,t){var n,o,i=e.find("td:last-child"),l=parseInt(i.attr("col-index"),10)+i.prop("colSpan")-1;for(o=t;o<=l;o++)if(n=e.find("[col-index="+o+"]"),n.length)return n},_adjustColgroups:function(e,t){for(var n,o,i,l=t.getElementsByTagName(f),s=t.getElementsByTagName(b),r=e.cells,p=r.length;l.length>0;)l[0].remove();for(;s.length>0;)s[0].remove();for(n=p-1;n>=0;n--)i=r[n],i.getAttribute(u)===b?(o=a.createEmptyNode(this.editor.document,b),o.setAttribute("span",i.getAttribute(w)),t.prepend(o)):t.prepend(a.createEmptyNode(this.editor.document,f))},_associateHeaderIds:function(t){a.clearTableMappings(t,"col-index"),a.reMapTableColumns(t,"col-index"),e(t).find("th, td").removeAttr("id headers"),a.associateWithIds(t)},_getNumberOfColumns:function(e){return a._getNumberOfColumns(e,"td, th")}}),D=j.extend({exec:function(){var n,o,i,s,r,p,d,c,h=this.lockRange(!0),f=a.closest(h.endContainer,[y,S]),b=a.closest(f,C),w=this.options.position||"after";if(!b||this.immutables()&&l.Immutables.immutableParent(f))return this.releaseRange(h),t;for(this._mapColIndices(b),o=f.parentNode,r=a.findNodeIndex(o,!0),f.rowSpan>1&&"after"===w&&(o=b.rows[r+f.rowSpan-1]),n=this._getNumberOfColumns(b),s=o.cloneNode(!0),e(s).empty(),c=0;c<n;c+=i.prop("colSpan"))i=e(o).find("[col-index="+c+"]"),i.length?i.prop("rowSpan")>1&&"after"===w&&i?i.attr(_,i.prop("rowSpan")+1):this._appendCell(s,i):(r=a.findNodeIndex(o,!0),i=this._findRowSpanCell(o.parentElement,r,c),p=i.closest(T).index(),p+i.prop("rowSpan")-1===r&&"after"===w?this._appendCell(s,i):i.attr(_,i.prop("rowSpan")+1)),d=e(s).find("[col-index="+c+"]"),d.attr(u)!==g||d.attr(_)||d.attr(u,m);"before"==w?a.insertBefore(s,o):a.insertAfter(s,o),e(b).find("[headers]").length>0&&this._associateHeaderIds(b),this._clearColIndexAttr(b),this.releaseRange(h),this._resetTableResizing(this.editor)},_appendCell:function(e,t){var n;n=t.clone(),n.html(l.emptyTableCellContent),n.removeAttr(_),n.appendTo(e)}}),L=j.extend({exec:function(){var n,o,i,s,r=this.lockRange(!0),p=a.closest(r.endContainer,[y,S]),d=a.closest(p,C),c=d.getElementsByTagName(f),h=d.getElementsByTagName(b),m=d&&d.rows,g=this.options.position||"after";if(!p||this.immutables()&&l.Immutables.immutableParent(p))return this.releaseRange(r),t;for(this._mapColIndices(d),n=parseInt(p.getAttribute("col-index"),10),p.colSpan>1&&"after"===g&&(p.setAttribute("col-index",n+p.colSpan-1),n=n+p.colSpan-1),o=0;o<m.length;o++)i=this._processForColSpan(m[o],n,g,p),i&&(s=i.cloneNode(),s.innerHTML=l.emptyTableCellContent,s.removeAttribute(w),s.getAttribute(u)&&s.getAttribute(u)===b&&s.setAttribute(u,f),"before"==g?a.insertBefore(s,i):a.insertAfter(s,i),this._resizeCells(s,i));(c.length>0||h.length>0)&&this._adjustColgroups(m[0],d),e(d).find("[headers]").length>0&&this._associateHeaderIds(d),this._clearColIndexAttr(d),this.releaseRange(r),this._resetTableResizing(this.editor)},_processForColSpan:function(n,o,i,l){var a,s,r=o-1;if(a=e(n).find("[col-index="+o+"]")[0],a&&a.colSpan>1&&"after"===i&&a!==l)return a.colSpan+=1,t;if(a)return a;for(r;r>=0&&(a=e(n).find("[col-index="+r+"]")[0],!(a&&a.colSpan>1));r--);return a?(s=parseInt(a.getAttribute("col-index"),10)+a.colSpan-1,s===o&&"after"===i?a:(o<=s&&a.setAttribute(w,a.colSpan+1),t)):t},_resizeCells:function(e,t){var n,o,i,l=e.style.width;l&&(n=parseFloat(l),o=l.slice((""+n).length),i=n/2+o,e.style.width=i,t.style.width=i)}}),O=j.extend({exec:function(){var n,o,i,s=this.lockRange(),p=r.mapAll(s,function(t){return e(t).closest(T)[0]}),d=a.closest(s.endContainer,[y,S]),c=p[0],h=d?d.rowSpan:1,u=e(p[0]).index(),m=a.closest(c,C),f=c.parentElement;if(!m||this.immutables()&&l.Immutables.immutableParent(c))return this.releaseRange(s),t;for(o=0;o<h;o++)p.indexOf(f.rows[u+o])<0&&p.push(f.rows[u+o]);if(m.rows.length<=p.length)n=a.next(m),n&&!a.insignificant(n)||(n=a.prev(m)),a.remove(m),this._resetTableResizing(this.editor);else if(f.rows.length<=p.length)n=f.nextSibling,n||(n=f.previousSibling),a.remove(f);else{for(this._mapColIndices(m),i=0;i<p.length;i++)c=p[i],a.removeTextSiblings(c),n=a.next(c)||a.prev(c),n=n.cells[0],this._handleRowSpanCells(m,c),a.remove(c);this._clearColIndexAttr(m)}e(m).find("[headers]").length>0?this._associateHeaderIds(m):a.is(f,x)&&e(m).find("[scope]").length>0&&this._adjustColgroups(f.rows[0],m),n&&(s.setStart(n,0),s.collapse(!0),this.editor.selectRange(s)),this._resetTableResizing(this.editor)},_handleRowSpanCells:function(t,n){var o,i,l,s,r=a.findNodeIndex(n,!0),p=t.rows[0],d=p.cells[p.cells.length-1],c=parseInt(d.getAttribute("col-index"),10)+d.colSpan-1;for(o=0;o<=c;o+=i.prop("colSpan"))i=e(n).find("[col-index="+o+"]"),i.length&&i.prop("rowSpan")>1&&(s=t.rows[r+1],l=e(s).find("[col-index="+(o+1)+"]"),l.length?l.before(i):e(s).append(i),this._reduceRowSpan(i)),i.length||(i=this._findRowSpanCell(n.parentElement,r,o),this._reduceRowSpan(i))},_reduceRowSpan:function(e){var t=e.prop("rowSpan")-1;t<=1?(e.removeAttr(_),e.attr(u)===g&&e.attr(u,m)):e.attr(_,t)}}),F=j.extend({exec:function(){var n,o,i,s,r=this.lockRange(),p=a.closest(r.endContainer,[y,S]),d=a.closest(p,C),c=d&&d.rows,h=a.findNodeIndex(p,!0),u=c&&c[0].cells.length,m=d.getElementsByTagName(f),g=d.getElementsByTagName(b);if(!p||this.immutables()&&l.Immutables.immutableParent(p))return this.releaseRange(r),t;if(1==u||p.colSpan==u)n=a.next(d),n&&!a.insignificant(n)||(n=a.prev(d)),a.remove(d),this._resetTableResizing(this.editor);else{for(a.removeTextSiblings(p),n=a.next(p)||a.prev(p),this._mapColIndices(d),h=parseInt(p.getAttribute("col-index"),10),s=0;s<p.colSpan;s++)for(o=0;o<c.length;o+=i.prop("rowSpan")||1)i=e(c[o]).find("[col-index="+(h+s)+"]"),i.length&&i.prop("colSpan")<=1?i.remove():this._handleColSpanCells(c[o],h+s);this._clearColIndexAttr(d)}(m.length>0||g.length>0)&&this._adjustColgroups(c[0],d),e(d).find("[headers]").length>0&&this._associateHeaderIds(d),n&&(r.setStart(n,0),r.collapse(!0),this.editor.selectRange(r)),this._resetTableResizing(this.editor)},_handleColSpanCells:function(n,o){var i,l,a=e(n).find("[col-index="+o+"]");if(a.length&&a.prop("colSpan")>1)return i=a.clone(!0),a.after(i),this._reduceColSpan(i),i.attr("col-index",parseInt(a.attr("col-index"),10)+1),a.remove(),t;for(l=o;l>=0;l--)if(a=e(n).find("[col-index="+l+"]"),a.length)return this._reduceColSpan(a),a.attr("col-index",parseInt(a.attr("col-index"),10)+1),t},_reduceColSpan:function(e){var t=e.prop("colSpan")-1;t<=1?(e.removeAttr(w),e.attr(u)===b&&e.attr(u,f)):e.attr(w,t)}}),V=j.extend({exec:function(){var n,o,i,s,r,p=this.lockRange(),d=a.closest(p.endContainer,[y,S]);return d?(n=a.closest(d,C),o=d.parentNode,i=a.findNodeIndex(d,!0),s=o.children[i+1],this.immutables()&&l.Immutables.immutableParent(d)?(this.releaseRange(p),t):(this._mapColIndices(n),i=parseInt(e(d).attr("col-index"),10),s=e(o).find("[col-index="+(i+1+this._getColspan(d)-1)+"]").get(0),s&&s.rowSpan===d.rowSpan&&d.tagName===s.tagName?(r=this._getColspan(d)+this._getColspan(s),e(d).prop(w,r).append(a.emptyNode(s)?"":"<br/>"+s.innerHTML),e(d).width(d.offsetWidth),e(s).remove(),d.getAttribute(u)===f&&d.setAttribute(u,b),d.getAttribute(u)===b&&this._adjustColgroups(o,n),e(n).find("[headers]").length>0&&this._associateHeaderIds(n),this._clearColIndexAttr(n),this.releaseRange(p),this._resetTableResizing(this.editor),t):(this._clearColIndexAttr(n),this.releaseRange(p),t))):(this.releaseRange(p),t)},_getColspan:function(e){return parseInt(e.getAttribute(w),10)||1}}),q=j.extend({exec:function(){var n,o,i,s,r,p,d,c=this.lockRange(),h=a.closest(c.endContainer,[y,S]);return h?(n=a.closest(h,T),o=a.closest(h,[x,v]),i=a.closest(h,C),s=a.findNodeIndex(h,!0),r=a.findNodeIndex(n,!0),r+1===o.rows.length?(this.releaseRange(c),t):(p=o.rows[r+this._getRowspan(h)],d=p&&p.children[s],this.immutables()&&l.Immutables.immutableParent(h)?(this.releaseRange(c),t):(this._mapColIndices(i),s=e(h).attr("col-index"),d=e(p).find("[col-index="+s+"]").get(0),d&&d.colSpan===h.colSpan&&h.tagName===d.tagName?(e(h).prop(_,this._getRowspan(h)+this._getRowspan(d)).append(a.emptyNode(d)?"":"<br/>"+d.innerHTML),h.getAttribute(u)===m&&h.setAttribute(u,g),e(d).remove(),e(i).find("[headers]").length>0&&this._associateHeaderIds(i),this._clearColIndexAttr(i),this.releaseRange(c),t):(this._clearColIndexAttr(i),this.releaseRange(c),t)))):(this.releaseRange(c),t)},_getRowspan:function(e){return parseInt(e.getAttribute(_),10)||1}}),U=j.extend({exec:function(){var n=this.lockRange(),o=this.options.type,i="row"===o?w:_,s=a.closest(n.endContainer,[y,S]),r=a.closest(s,[x,v]),p=a.closest(s,C),d=a.createEmptyNode(this.editor.document,s.nodeName.toLowerCase());return!s||this.immutables()&&l.Immutables.immutableParent(s)?(this.releaseRange(n),t):(this._mapColIndices(p),"row"===o&&e(s).is("["+i+"]")?this._splitCellHorizontally(s,r,i,d):"column"===o&&e(s).is("["+i+"]")&&this._splitCellVertically(s,r,i,d),e(s).prop(i.toLowerCase())<=1&&e(s).removeAttr(i),e(p).find("[headers]").length>0&&this._associateHeaderIds(p),this._clearColIndexAttr(p),this.releaseRange(n),t)},_getRowspanValue:function(e){return parseInt(e.getAttribute(_),10)},_getColspanValue:function(e){return parseInt(e.getAttribute(w),10)},_splitCellHorizontally:function(t,n,o,i){var l=t.rowSpan,a=t.colSpan,s=e(i),r=Math.floor(a/2);r>1&&s.attr(w,r),l>1&&s.attr(_,l),e(t).prop(o,a-r).after(s),e(t).width(t.offsetWidth),s.width(s[0].offsetWidth),t.hasAttribute(u)&&(t.getAttribute(u)===b?(s.attr(u,f),t.getAttribute(w)&&"1"!==t.getAttribute(w)||t.setAttribute(u,f),this._adjustColgroups(t.parentNode,n.parentNode)):s.attr(u,t.getAttribute(u)))},_splitCellVertically:function(t,n,o,i){var l=a.closest(t,T),s=parseInt(e(t).attr("col-index"),10),r=a.findNodeIndex(l,!0),p=t.rowSpan,d=t.colSpan,c=Math.floor(p/2),h=e(n).find(T).eq(r+p-c),f=this._findNextTdInRow(h,s+d),b=e(i);c>1&&b.attr(_,c),d>1&&b.attr(w,d),f&&f.length?f.before(b):h.append(b),e(t).prop(o,p-c),t.hasAttribute(u)&&(t.getAttribute(u)===g?(b.attr(u,m),t.getAttribute(_)&&"1"!==t.getAttribute(_)||t.setAttribute(u,m)):b.attr(u,t.getAttribute(u)))}}),K=R.extend({command:function(e){var t={row:{insert:D,"delete":O,merge:V,split:U},column:{insert:L,"delete":F,merge:q,split:U}};return e=o(e,this.options),e.action=e.action||"insert",new t[e.type][e.action](e)},initialize:function(e,t){R.fn.initialize.call(this,e,t),e.addClass("k-state-disabled"),e.attr("disabled","disabled")},update:function(e,t){var n=!E.isFormatted(t);n===!0?(e.parent().addClass("k-hidden k-state-disabled"),e.attr("disabled","disabled"),e.addClass("k-state-disabled")):(e.parent().removeClass("k-hidden k-state-disabled"),e.removeAttr("disabled"),e.removeClass("k-state-disabled"))}});o(n.ui.editor,{PopupTool:B,TableCommand:P,InsertTableTool:W,TableModificationTool:K,InsertRowCommand:D,InsertColumnCommand:L,DeleteRowCommand:O,DeleteColumnCommand:F,MergeCellsHorizontallyCommand:V,MergeCellsVerticallyCommand:q,SplitCellCommand:U}),N("createTable",new W({template:new A({template:s.buttonTemplate,popup:!0,title:"Create table"})})),N("addColumnLeft",new K({type:"column",position:"before",template:new A({template:s.buttonTemplate,title:"Add column on the left"})})),N("addColumnRight",new K({type:"column",template:new A({template:s.buttonTemplate,title:"Add column on the right"})})),N("addRowAbove",new K({type:"row",position:"before",template:new A({template:s.buttonTemplate,title:"Add row above"})})),N("addRowBelow",new K({type:"row",template:new A({template:s.buttonTemplate,title:"Add row below"})})),N("deleteRow",new K({type:"row",action:"delete",template:new A({template:s.buttonTemplate,title:"Delete row"})})),N("deleteColumn",new K({type:"column",action:"delete",template:new A({template:s.buttonTemplate,title:"Delete column"})})),N("mergeCellsHorizontally",new K({type:"row",action:"merge",template:new A({template:s.buttonTemplate,title:"Merge Cell Right"})})),N("mergeCellsVertically",new K({type:"column",action:"merge",template:new A({template:s.buttonTemplate,title:"Merge Cell Down"})})),N("splitCellHorizontally",new K({type:"row",action:"split",template:new A({template:s.buttonTemplate,title:"Split Cell"})})),N("splitCellVertically",new K({type:"column",action:"split",template:new A({template:s.buttonTemplate,title:"Split Cell"})}))}(window.kendo.jQuery)},n(3))},973:function(e,t){e.exports=require("./insert")}});