angular-ui-grid
Version:
A data grid for Angular
2 lines • 13.1 kB
JavaScript
/*! For license information please see ui-grid.cellnav.min.js.LICENSE.txt */
(()=>{var e={590:()=>{!function(){"use strict";var e=angular.module("ui.grid.cellNav",["ui.grid"]);e.constant("uiGridCellNavConstants",{FEATURE_NAME:"gridCellNav",CELL_NAV_EVENT:"cellNav",direction:{LEFT:0,RIGHT:1,UP:2,DOWN:3,PG_UP:4,PG_DOWN:5},EVENT_TYPE:{KEYDOWN:0,CLICK:1,CLEAR:2}}),e.factory("uiGridCellNavFactory",["gridUtil","uiGridConstants","uiGridCellNavConstants","GridRowColumn","$q",function(e,l,i,o,n){var t=function(e,l,i,o){this.rows=e.visibleRowCache,this.columns=l.visibleColumnCache,this.leftColumns=i?i.visibleColumnCache:[],this.rightColumns=o?o.visibleColumnCache:[],this.bodyContainer=e};return t.prototype.getFocusableCols=function(){return this.leftColumns.concat(this.columns,this.rightColumns).filter((function(e){return e.colDef.allowCellFocus}))},t.prototype.getFocusableRows=function(){return this.rows.filter((function(e){return!1!==e.allowCellFocus}))},t.prototype.getNextRowCol=function(e,l,o){switch(e){case i.direction.LEFT:return this.getRowColLeft(l,o);case i.direction.RIGHT:return this.getRowColRight(l,o);case i.direction.UP:return this.getRowColUp(l,o);case i.direction.DOWN:return this.getRowColDown(l,o);case i.direction.PG_UP:return this.getRowColPageUp(l,o);case i.direction.PG_DOWN:return this.getRowColPageDown(l,o)}},t.prototype.initializeSelection=function(){var e=this.getFocusableCols(),l=this.getFocusableRows();return 0===e.length||0===l.length?null:new o(l[0],e[0])},t.prototype.getRowColLeft=function(e,l){var i=this.getFocusableCols(),n=this.getFocusableRows(),t=i.indexOf(l),r=n.indexOf(e);-1===t&&(t=1);var a=0===t?i.length-1:t-1;return new o(a>=t?0===r?e:n[r-1]:e,i[a])},t.prototype.getRowColRight=function(e,l){var i=this.getFocusableCols(),n=this.getFocusableRows(),t=i.indexOf(l),r=n.indexOf(e);-1===t&&(t=0);var a=t===i.length-1?0:t+1;return a<=t?r===n.length-1?new o(e,i[a]):new o(n[r+1],i[a]):new o(e,i[a])},t.prototype.getRowColDown=function(e,l){var i=this.getFocusableCols(),n=this.getFocusableRows(),t=i.indexOf(l),r=n.indexOf(e);return-1===t&&(t=0),r===n.length-1?new o(e,i[t]):new o(n[r+1],i[t])},t.prototype.getRowColPageDown=function(e,l){var i=this.getFocusableCols(),n=this.getFocusableRows(),t=i.indexOf(l),r=n.indexOf(e);-1===t&&(t=0);var a=this.bodyContainer.minRowsToRender();return r>=n.length-a?new o(n[n.length-1],i[t]):new o(n[r+a],i[t])},t.prototype.getRowColUp=function(e,l){var i=this.getFocusableCols(),n=this.getFocusableRows(),t=i.indexOf(l),r=n.indexOf(e);return-1===t&&(t=0),new o(0===r?e:n[r-1],i[t])},t.prototype.getRowColPageUp=function(e,l){var i=this.getFocusableCols(),n=this.getFocusableRows(),t=i.indexOf(l),r=n.indexOf(e);-1===t&&(t=0);var a=this.bodyContainer.minRowsToRender();return new o(r-a<0?n[0]:n[r-a],i[t])},t}]),e.service("uiGridCellNavService",["gridUtil","uiGridConstants","uiGridCellNavConstants","$q","uiGridCellNavFactory","GridRowColumn","ScrollEvent",function(e,l,i,o,n,t,r){var a={initializeGrid:function(e){e.registerColumnBuilder(a.cellNavColumnBuilder),e.cellNav={},e.cellNav.lastRowCol=null,e.cellNav.focusedCells=[],a.defaultGridOptions(e.options);var l={events:{cellNav:{navigate:function(e,l){},viewPortKeyDown:function(e,l){},viewPortKeyPress:function(e,l){}}},methods:{cellNav:{scrollToFocus:function(l,i){return a.scrollToFocus(e,l,i)},getFocusedCell:function(){return e.cellNav.lastRowCol},getCurrentSelection:function(){return e.cellNav.focusedCells},rowColSelectIndex:function(l){for(var i=-1,o=0;o<e.cellNav.focusedCells.length;o++)if(e.cellNav.focusedCells[o].col.uid===l.col.uid&&e.cellNav.focusedCells[o].row.uid===l.row.uid){i=o;break}return i}}}};e.api.registerEventsFromObject(l.events),e.api.registerMethodsFromObject(l.methods)},defaultGridOptions:function(e){e.modifierKeysToMultiSelectCells=!0===e.modifierKeysToMultiSelectCells,e.keyDownOverrides=e.keyDownOverrides||[]},decorateRenderContainers:function(e){var l=e.hasRightContainer()?e.renderContainers.right:null,i=e.hasLeftContainer()?e.renderContainers.left:null;null!==i&&(e.renderContainers.left.cellNav=new n(e.renderContainers.body,i,l,e.renderContainers.body)),null!==l&&(e.renderContainers.right.cellNav=new n(e.renderContainers.body,l,e.renderContainers.body,i)),e.renderContainers.body.cellNav=new n(e.renderContainers.body,e.renderContainers.body,i,l)},getDirection:function(e){return e.keyCode===l.keymap.LEFT||e.keyCode===l.keymap.TAB&&e.shiftKey?i.direction.LEFT:e.keyCode===l.keymap.RIGHT||e.keyCode===l.keymap.TAB?i.direction.RIGHT:e.keyCode===l.keymap.UP||e.keyCode===l.keymap.ENTER&&e.shiftKey?i.direction.UP:e.keyCode===l.keymap.PG_UP?i.direction.PG_UP:e.keyCode===l.keymap.DOWN||e.keyCode===l.keymap.ENTER&&!e.ctrlKey&&!e.altKey?i.direction.DOWN:e.keyCode===l.keymap.PG_DOWN?i.direction.PG_DOWN:null},cellNavColumnBuilder:function(e,l,i){return e.allowCellFocus=void 0===e.allowCellFocus||e.allowCellFocus,o.all([])},scrollToFocus:function(e,l,i){var o=null,n=null;return null!=l&&(o=e.getRow(l)),null!=i&&(n=e.getColumn(i.name?i.name:i.field)),e.api.core.scrollToIfNecessary(o,n).then((function(){var l={row:o,col:n};null!==o&&null!==n&&e.cellNav.broadcastCellNav(l,null,null)}))},getLeftWidth:function(e,l){var i=0;if(!l)return i;var o=e.renderContainers.body.visibleColumnCache.indexOf(l);e.renderContainers.body.visibleColumnCache.forEach((function(e,l){l<o&&(i+=e.drawnWidth)}));var n=0===o?0:(o+1)/e.renderContainers.body.visibleColumnCache.length;return i+=l.drawnWidth*n}};return a}]),e.directive("uiGridCellnav",["gridUtil","uiGridCellNavService","uiGridCellNavConstants","uiGridConstants","GridRowColumn","$timeout","$compile","i18nService",function(e,l,i,o,n,t,r,a){return{replace:!0,priority:-150,require:"^uiGrid",scope:!1,controller:function(){},compile:function(){return{pre:function(e,t,r,a){var c=e,s=a.grid;l.initializeGrid(s),a.cellNav={},a.cellNav.makeRowCol=function(e){return e instanceof n||(e=new n(e.row,e.col)),e},a.cellNav.getActiveCell=function(){var e=t[0].getElementsByClassName("ui-grid-cell-focus");if(e.length>0)return e[0]},a.cellNav.broadcastCellNav=s.cellNav.broadcastCellNav=function(e,l,o){l=!(void 0===l||!l),e=a.cellNav.makeRowCol(e),a.cellNav.broadcastFocus(e,l,o),c.$broadcast(i.CELL_NAV_EVENT,e,l,o)},a.cellNav.clearFocus=s.cellNav.clearFocus=function(){s.cellNav.focusedCells=[],c.$broadcast(i.CELL_NAV_EVENT)},a.cellNav.broadcastFocus=function(e,l,i){l=!(void 0===l||!l);var o=(e=a.cellNav.makeRowCol(e)).row,t=e.col,r=a.grid.api.cellNav.rowColSelectIndex(e);if(null===s.cellNav.lastRowCol||-1===r||s.cellNav.lastRowCol.col===t&&s.cellNav.lastRowCol.row===o){var c=new n(o,t);(null===s.cellNav.lastRowCol||s.cellNav.lastRowCol.row!==c.row||s.cellNav.lastRowCol.col!==c.col||s.options.enableCellEditOnFocus)&&(s.api.cellNav.raise.navigate(c,s.cellNav.lastRowCol,i),s.cellNav.lastRowCol=c),a.grid.options.modifierKeysToMultiSelectCells&&l?s.cellNav.focusedCells.push(e):s.cellNav.focusedCells=[e]}else s.options.modifierKeysToMultiSelectCells&&l&&r>=0&&s.cellNav.focusedCells.splice(r,1)},a.cellNav.handleKeyDown=function(e){var n=l.getDirection(e);if(null===n)return null;var t="body";e.uiGridTargetRenderContainerId&&(t=e.uiGridTargetRenderContainerId);var r=a.grid.api.cellNav.getFocusedCell();if(r){var c=a.grid.renderContainers[t].cellNav.getNextRowCol(n,r.row,r.col),d=a.grid.renderContainers[t].cellNav.getFocusableCols(),u=a.grid.api.cellNav.rowColSelectIndex(c);return n===i.direction.LEFT&&c.col===d[d.length-1]&&c.row===r.row&&e.keyCode===o.keymap.TAB&&e.shiftKey?(s.cellNav.focusedCells.splice(u,1),a.cellNav.clearFocus(),!0):n!==i.direction.RIGHT||c.col!==d[0]||c.row!==r.row||e.keyCode!==o.keymap.TAB||e.shiftKey?(s.scrollToIfNecessary(c.row,c.col).then((function(){a.cellNav.broadcastCellNav(c,null,e)})),e.stopPropagation(),e.preventDefault(),!1):(s.cellNav.focusedCells.splice(u,1),a.cellNav.clearFocus(),!0)}}},post:function(e,l,o,n){var t,c,s=n.grid,d=!0;try{angular.module("ngAria")}catch(e){d=!1}d&&(t='<div id="'+s.id+'-aria-speakable" class="ui-grid-a11y-ariascreenreader-speakable ui-grid-offscreen" aria-live="assertive" role="alert" aria-atomic="true" aria-hidden="false" aria-relevant="additions" > </div>',c=r(t)(e),l.prepend(c),e.$on(i.CELL_NAV_EVENT,(function(e,l,i,o){if(!o||"focus"!==o.type){for(var n,t,r,d,u=[],v=s.api.cellNav.getCurrentSelection(),C=0;C<v.length;C++){var f=(r=void 0,r="","selectionRowHeaderCol"===(t=v[C]).col.field&&(r=(t.row.isSelected?a.getSafeText("search.aria.selected"):a.getSafeText("search.aria.notSelected"))+", "),r+s.getCellDisplayValue(t.row,t.col)+(n=v[C].col,", "+a.getSafeText("headerCell.aria.column")+" "+n.displayName));u.push(f)}(d=u.toString())!==c.text().trim()&&(c[0].style.clip="rect(0px,0px,0px,0px)",c[0].innerHTML="",c[0].style.visibility="hidden",c[0].style.visibility="visible",""!==d&&(c[0].style.clip="auto",c[0].appendChild(document.createTextNode(d+" ")),c[0].style.visibility="hidden",c[0].style.visibility="visible"))}})))}}}}}]),e.directive("uiGridRenderContainer",["$timeout","$document","gridUtil","uiGridConstants","uiGridCellNavService","$compile","uiGridCellNavConstants",function(e,l,i,o,n,t,r){return{replace:!0,priority:-99999,require:["^uiGrid","uiGridRenderContainer","?^uiGridCellnav"],scope:!1,compile:function(){return{post:function(l,o,a,c){var s=c[0],d=c[1],u=c[2];if(s.grid.api.cellNav){var v=d.containerId,C=s.grid;if(n.decorateRenderContainers(C),"body"===v){s.grid.options.modifierKeysToMultiSelectCells?o.attr("aria-multiselectable",!0):o.attr("aria-multiselectable",!1);var f=t('<div class="ui-grid-focuser" role="region" aria-live="assertive" aria-atomic="false" tabindex="0" aria-controls="'+C.id+"-aria-speakable "+C.id+'-grid-container" aria-owns="'+C.id+'-grid-container"></div>')(l);o.append(f),f.on("focus",(function(e){e.uiGridTargetRenderContainerId=v;var l=s.grid.api.cellNav.getFocusedCell();null===l&&(l=s.grid.renderContainers[v].cellNav.getNextRowCol(r.direction.DOWN,null,null)).row&&l.col&&s.cellNav.broadcastCellNav(l)})),u.setAriaActivedescendant=function(e){o.attr("aria-activedescendant",e)},u.removeAriaActivedescendant=function(e){o.attr("aria-activedescendant")===e&&o.attr("aria-activedescendant","")},s.focus=function(){i.focus.byElement(f[0])};var g=null;f.on("keydown",(function(e){e.uiGridTargetRenderContainerId=v;var l=s.grid.api.cellNav.getFocusedCell();null===(s.grid.options.keyDownOverrides.some((function(l){return Object.keys(l).every((function(i){return l[i]===e[i]}))}))?null:s.cellNav.handleKeyDown(e))&&(s.grid.api.cellNav.raise.viewPortKeyDown(e,l,s.cellNav.handleKeyDown),g=l)})),f.on("keypress",(function(l){g&&(e((function(){s.grid.api.cellNav.raise.viewPortKeyPress(l,g)}),4),g=null)})),l.$on("$destroy",(function(){f.off()}))}}}}}}}]),e.directive("uiGridViewport",(function(){return{replace:!0,priority:-99999,require:["^uiGrid","^uiGridRenderContainer","?^uiGridCellnav"],scope:!1,compile:function(){return{pre:function(e,l,i,o){},post:function(e,l,i,o){var n=o[0],t=o[1];if(n.grid.api.cellNav&&"body"===t.containerId){var r=n.grid;r.api.core.on.scrollBegin(e,(function(){var e=n.grid.api.cellNav.getFocusedCell();null!==e&&t.colContainer.containsColumn(e.col)&&n.cellNav.clearFocus()})),r.api.core.on.scrollEnd(e,(function(e){var l=n.grid.api.cellNav.getFocusedCell();null!==l&&t.colContainer.containsColumn(l.col)&&n.cellNav.broadcastCellNav(l)})),r.api.cellNav.on.navigate(e,(function(){n.focus()}))}}}}}})),e.directive("uiGridCell",["$timeout","$document","uiGridCellNavService","gridUtil","uiGridCellNavConstants","uiGridConstants","GridRowColumn",function(e,l,i,o,n,t,r){return{priority:-150,restrict:"A",require:["^uiGrid","?^uiGridCellnav"],scope:!1,link:function(e,l,i,o){var a=o[0],c=o[1];if(a.grid.api.cellNav&&e.col.colDef.allowCellFocus){var s=a.grid;e.focused=!1,l.attr("tabindex",-1),l.find("div").on("click",(function(l){a.cellNav.broadcastCellNav(new r(e.row,e.col),l.ctrlKey||l.metaKey,l),l.stopPropagation(),e.$apply()})),l.on("mousedown",u),a.grid.api.edit&&(a.grid.api.edit.on.beginCellEdit(e,(function(){l.off("mousedown",u)})),a.grid.api.edit.on.afterCellEdit(e,(function(){l.on("mousedown",u)})),a.grid.api.edit.on.cancelCellEdit(e,(function(){l.on("mousedown",u)}))),v(),l.on("focus",(function(l){a.cellNav.broadcastCellNav(new r(e.row,e.col),!1,l),l.stopPropagation(),e.$apply()})),e.$on(n.CELL_NAV_EVENT,v);var d=a.grid.registerDataChangeCallback((function(l){C(),e.$applyAsync(v)}),[t.dataChange.ROW]);e.$on("$destroy",(function(){d(),l.find("div").off(),l.off()}))}function u(e){e.preventDefault()}function v(){s.cellNav.focusedCells.some((function(l,i){return l.row===e.row&&l.col===e.col}))?function(){if(!e.focused){l.find("div").addClass("ui-grid-cell-focus"),l.attr("aria-selected",!0),c.setAriaActivedescendant(l.attr("id")),e.focused=!0}}():C()}function C(){e.focused&&(l.find("div").removeClass("ui-grid-cell-focus"),l.attr("aria-selected",!1),c.removeAriaActivedescendant(l.attr("id")),e.focused=!1)}}}}])}()}},l={};function i(o){var n=l[o];if(void 0!==n)return n.exports;var t=l[o]={exports:{}};return e[o](t,t.exports,i),t.exports}i(590)})();