realgrid-vue
Version:
RealGrid2 wrapping Component for Vue3
2 lines (1 loc) • 15.6 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("realgrid"),i=require("vue");function C(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const h=C(w),F=t=>t.replace(/-./g,e=>e[1].toUpperCase()),r=(t,e="")=>{const n={};for(let o in t)n[F(e?`${e}-${o}`:o)]=i.toRaw(t[o]);return n},m=(t,e={},n={})=>{t=t||{};const o=["children"];for(const[a,s]of Object.entries(e))if(!o.includes(a))if(!n.hasOwnProperty(a))t[a]=null;else if(Array.isArray(s))(!n[a]||JSON.stringify(s)!=JSON.stringify(n[a]))&&(t[a]=n[a]);else if(s instanceof Object&&!(s instanceof Date||Array.isArray(s)||typeof s=="function"))if(!(n[a]instanceof Object))t[a]=n[a];else{const d=m({},s,n[a]);d&&Object.keys(d).length>0&&(t[a]=d)}else s!==n[a]&&(t[a]=n[a]);for(const[a,s]of Object.entries(n))o.includes(a)||e.hasOwnProperty(a)||(t[a]=s);return t},R=(t,e,n)=>{for(const[o,a]of Object.entries(n))o&&typeof a=="function"&&o.startsWith("on")&&(o==="onRowInserting"?t.onRowInserting=a:o==="onDataRowInserting"?e.onRowInserting=a:(t.hasOwnProperty(o)&&(t[o]=a),e.hasOwnProperty(o)&&(e[o]=a)))},p=()=>i.defineComponent({name:"RealGridBase",props:{disabled:Boolean,gridProps:Object,dataProps:Object,locale:Object,autoGenerateField:Boolean,rows:Array,rowStyleCallback:Function,cellStyleCallback:Function,layout:Array,onInitialized:Function,onDestroy:Function,onCurrentChanging:Function,onCurrentChanged:Function,onCurrentRowChanged:Function,onValidateColumn:Function,onValidateRow:Function,onValidationFail:Function,onColumnCheckedChanged:Function,onMenuItemClicked:Function,onContextMenuPopup:Function,onContextMenuItemClicked:Function,onCellButtonClicked:Function,onScrollToBottom:Function,onTopIndexChanged:Function,onTopIndexChanging:Function,onLeftPosChanged:Function,onRowsDeleting:Function,onRowInserting:Function,onSelectionCleared:Function,onSelectionChanged:Function,onSelectionAdded:Function,onSelectionEnded:Function,onShowEditor:Function,onShowEditCommand:Function,onHideEditor:Function,onEditChange:Function,onGetEditValue:Function,onEditCommit:Function,onEditCanceled:Function,onItemEditCanceled:Function,onItemEditCancel:Function,onEditSearch:Function,onSearchCellButtonClick:Function,onCellEdited:Function,onEditRowChanged:Function,onEditRowPasted:Function,onRowsPasted:Function,onCellPasting:Function,onItemChecked:Function,onItemAllChecked:Function,onErrorClicked:Function,onSorting:Function,onSortingChanged:Function,onFiltering:Function,onFilteringChanged:Function,onWheel:Function,onKeyDown:Function,onKeyPress:Function,onKeyUp:Function,onShowTooltip:Function,onShowHeaderTooltip:Function,onColumnPropertyChanged:Function,onLayoutPropertyChanged:Function,onGridActivated:Function,onCopy:Function,onPaste:Function,onPasted:Function,onItemsChecked:Function,onCellClicked:Function,onCellDblClicked:Function,onCellItemClicked:Function,onCommandStackChanged:Function,onDataLoadComplated:Function,onLayoutExpanding:Function,onLayoutExpanded:Function,onLayoutCollapsing:Function,onLayoutCollapsed:Function,onGridFocusChanged:Function},data(){return{$dataProvider:null,$gridView:null,_mountTimer:null,_mountCBs:[]}},mounted(){const t=this.$el,e=r(i.toRaw(this.$props)),{grid:n,dataProvider:o}=this._createGrid(t,e);this.dataProvider=o,this.gridView=n,this.executeCB(),R(n,o,e),this._applyOptions(e),e.layout&&n.setColumnLayout(e.layout),this._doInitProc(n,e),this._setData(e)},computed:{dataProvider:{get(){return i.toRaw(this.$data.$dataProvider)},set(t){this.$dataProvider=t}},gridView:{get(){return i.toRaw(this.$data.$gridView)},set(t){this.$gridView=t}}},unmounted(){const t=r(this.$props),e=r(this.$attrs,"on"),n=t.onDestroy||e.onDestroy;n&&n(this.gridView),this.gridView=this.gridView&&this.gridView.destroy(),this.dataProvider=this.dataProvider&&this.dataProvider.destroy()},destroyed(){const t=r(this.$props),e=r(this.$attrs,"on"),n=t.onDestroy||e.onDestroy;n&&n(this.gridView),this.gridView=this.gridView&&this.gridView.destroy(),this.dataProvider=this.dataProvider&&this.dataProvider.destroy()},watch:{gridProps:{handler(t,e){const n=m({},e,t);this.gridView&&n&&Object.keys(n).length>0&&this.gridView.setOptions(n)},deep:!0},disabled(t,e){this.gridView&&(this.gridView.disabled=t)},dataProps:{handler(t,e){const n=m({},e,t);this.dataProvider&&n&&Object.keys(n).length>0&&this.dataProvider.setOptions(n)},deep:!0},locale:{handler(t,e){t&&h.default.setLocale(t)}},layout:{handler(t,e){this.gridView&&this.gridView.setColumnLayout(t)},deep:!0}},methods:{addCallback(t){this.$data._mountCBs.push(t),clearTimeout(this.$data._mountTimer);const e=this;this.$data._mountTimer=window.setTimeout(function(){e.executeCB()},20)},removeCallback(t){if(this.$data._mountCBs.indexOf(t)>=0){const e=this.$data._mountCBs.indexOf(t);this.$data._mountCBs.splice(e,1)}},executeCB(){const t=this.gridView,e=this.dataProvider;if(t&&(clearTimeout(this._mountTimer),t&&t._view)){t.beginUpdate();try{e==null||e.beginUpdate();try{const n=this.$data._mountCBs.sort((o,a)=>(o.$mountSeq==null?-1:o.$mountSeq)-(a.$mountSeq==null?-1:a.$mountSeq));for(;n&&n.length;){const o=n.shift();o==null||o.call(this,t)}}finally{e==null||e.endUpdate()}}finally{t.endUpdate(!0),this.$data._mountTimer=null,this.$data._mountCBs=[]}}},_applyOptions(t){const e=this.gridView,n=this.dataProvider;if(e)for(let[o,a]of Object.entries(t))switch(o){case"gridProps":a&&e.setOptions(a);break;case"disabled":e&&(e.disabled=!!a);break;case"dataProps":a&&(n==null||n.setOptions(a));break;case"layout":a&&e&&e.setColumnLayout(a);break;case"rowStyleCallback":e.setRowStyleCallback(a);break;case"cellStyleCallback":e.setCellStyleCallback(a);break;case"locale":a&&h.default.setLocale(a);break}this._doApplyOptions(t)},_createGrid(t,e){return{grid:null,dataProvider:null}},_doInitProc(t,e){const n=e.onInitialized;if(n){const o=n.constructor.name;o==="Function"?n(t):o==="AsyncFunction"&&Promise.resolve(n(t))}},_doApplyOptions(t){},_setData(t){}},render(){var s;const t=d=>{const l=[];if(Array.isArray(d))for(let u of d)Array.isArray(u.children)?l.push(...t(u.children)):l.push(u);return l},e=[];for(let d of Object.keys(this.$slots)){let l=this.$slots[d];typeof l=="function"&&(l=l()),e.push(...t(l))}let n=0;for(let d=0;d<e.length;d++){const l=e[d];if(l.type instanceof Object&&l.type.hasOwnProperty("name")){const u=l.type.name;u&&/^RG.+Column$/.exec(u)&&(l.props=l.props||{},l.props&&((s=l.props).displayIndex??(s.displayIndex=n++)))}l.$mountSeq=d}const o=this.$attrs.style?this.$attrs.style:{width:"100%",height:"100%"};return i.h("div",{style:o},e)}}),f=i.defineComponent({name:"RealGridVue",extends:p(),props:{accessibility:Boolean,waiOptions:Object,onPageChanging:Function,onPageChanged:Function,onPageCountChanged:Function,onGrouping:Function,onGrouped:Function,onExpanding:Function,onExpanded:Function,onCollapsing:Function,onCollapsed:Function,onRowCountChanged:Function,onRowUpdating:Function,onRowUpdated:Function,onRowsUpdated:Function,onRowListUpdated:Function,onDataRowInserting:Function,onRowInserted:Function,onRowsInserted:Function,onRowDeleting:Function,onRowDeleted:Function,onRowsDeleted:Function,onRowMoving:Function,onRowMoved:Function,onRowsMoving:Function,onRowsMoved:Function,onRowListMoving:Function,onRowListMoved:Function,onValueChanged:Function,onDataChanged:Function,onRowStateChanged:Function,onRowStatesChanged:Function,onRowStatesCleared:Function,onRestoreRows:Function},data(){return{$dataProvider:null,$gridView:null}},watch:{rows:{handler(t,e){var n;if(this.$data._mountTimer!=null){const o=()=>{i.nextTick(()=>{var a;(a=this.dataProvider)==null||a.setRows(i.toRaw(t))})};o.$mountSeq=1/0,this.addCallback(o)}else(n=this.dataProvider)==null||n.setRows(i.toRaw(t))}}},methods:{_createGrid(t,e){var a;const n=new h.default.GridView(t,e==null?void 0:e.accessibility,e==null?void 0:e.waiOptions),o=new h.default.LocalDataProvider((a=e.dataProps)==null?void 0:a.undoable);return n.setDataSource(o),{grid:n,dataProvider:o}},_doApplyOptions(t){},_setData(t){var e;t.rows&&((e=this.dataProvider)==null||e.setRows(i.toRaw(t.rows)))}}}),$=i.defineComponent({name:"RealTreeVue",extends:p(),props:{treeOptions:Object,treeField:String,needSorting:Boolean,childrenField:String,iconField:String,json:Object,rowsProp:String,childrenProp:String,iconProp:String,onTreeItemExpanding:Function,onTreeItemExpanded:Function,onTreeItemCollapsing:Function,onTreeItemCollapsed:Function,onTreeItemChanged:Function,onRowCountChanged:Function,onRowAdding:Function,onRowAdded:Function,onRowsAdded:Function,onRowDeleting:Function,onRowDeleted:Function,onRowsDeleted:Function,onRowUpdating:Function,onRowUpdated:Function,onRowsUpdating:Function,onRowsUpdated:Function,onValueChanged:Function,onDataChanged:Function,onRowStateChanged:Function,onRowStatesChanged:Function,onRowSiblingMoving:Function,onRowSiblingMoved:Function,onRowsSiblingMoving:Function,onRowsSiblingMoved:Function,onRowParentChanging:Function,onRowParentChanged:Function},data(){return{$gridView:null,$dataProvider:null}},computed:{gridView:{get(){return i.toRaw(this.$data.$gridView)},set(t){this.$gridView=t}},dataProvider:{get(){return i.toRaw(this.$data.$dataProvider)},set(t){this.$dataProvider=t}}},methods:{_createGrid(t,e){var a;const n=new h.TreeView(t),o=new h.LocalTreeDataProvider((a=e.dataProps)==null?void 0:a.undoable);return n.setDataSource(o),{grid:n,dataProvider:o}},_doApplyOptions(t){var e;for(const[n,o]of Object.entries(t))switch(n){case"treeOptions":o&&((e=this.gridView)==null||e.setTreeOptions(i.toRaw(o)));break}},_setData(t){var e,n;t.rows?(e=this.dataProvider)==null||e.setRows(i.toRaw(t.rows),this.treeField,this.needSorting,this.childrenField,this.iconField):t.json&&((n=this.dataProvider)==null||n.setObjectRows(i.toRaw(t.json),this.rowsProp,this.childrenProp,this.iconProp))}},watch:{rows:{handler(t,e){var n;if(this.$data._mountTimer!=null){const o=()=>{i.nextTick(()=>{var a;(a=this.dataProvider)==null||a.setRows(i.toRaw(t),this.treeField,this.needSorting,this.childrenField,this.iconField)})};o.$mountSeq=1/0,this.addCallback(o)}else(n=this.dataProvider)==null||n.setRows(i.toRaw(t),this.treeField,this.needSorting,this.childrenField,this.iconField)}},json:{handler(t,e){var n;if(this.$data._mountTimer!=null){const o=()=>{i.nextTick(()=>{var a;(a=this.dataProvider)==null||a.setObjectRows(i.toRaw(t),this.rowsProp,this.childrenProp,this.iconProp)})};o.$mountSeq=1/0,this.addCallback(o)}else(n=this.dataProvider)==null||n.setObjectRows(i.toRaw(t),this.rowsProp,this.childrenProp,this.iconProp)}}}}),c=i.defineComponent({name:"ComponentBase",props:{},data(){return{$model:null,$oldValue:null}},mounted(){const t=i.toRaw(this.$parent);t&&(this.$oldValue=r(i.toRaw(this.$attrs)),this.mountCB.$mountSeq=this.$.vnode.$mountSeq,t.addCallback(this.mountCB))},unmounted(){const t=this.$parent;t&&(t.removeCallback(this.mountCB),t.addCallback(this.unmountCB))},destroyed(){const t=this.$parent;t&&(t.removeCallback(this.mountCB),t.addCallback(this.unmountCB))},watch:{$attrs:{handler(t,e){var a;const n=r(i.toRaw(t)),o=m({},r(i.toRaw(this.$data.$oldValue)),r(i.toRaw(t)));if(o&&Object.keys(o).length>0){const s=i.toRaw((a=this.$data)==null?void 0:a.$model);s&&s.assignFrom&&s.assignFrom(n),this._doWatchAttrs(o),this.$oldValue=n}},deep:!0}},methods:{mountCB(){},unmountCB(){},_doWatchAttrs(t){}},render(){}}),y=i.defineComponent({name:"RGSeriesColumn",extends:c,data(){return{}},props:{},methods:{mountCB(t){var n;if(r(i.toRaw((n=this.$parent)==null?void 0:n.$attrs))){const o=r(i.toRaw(this.$attrs));t&&(this.$model=t.addColumn({...o,type:"series"},o.displayIndex??-1))}},unmountCB(t){this.$data.$model&&t.removeColumn(this.$data.$model.name)},_doWatchAttrs(t){if(t.hasOwnProperty("width")&&!isNaN(t.width)){const n=i.toRaw(this.$data.$model).layout;n&&(n.cellWidth=t.width)}}}}),g=i.defineComponent({name:"RGStateBar",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setStateBar(r(i.toRaw(this.$attrs))),this.$model=t.stateBar}}}),P=i.defineComponent({name:"RGRowIndicator",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setRowIndicator(r(i.toRaw(this.$attrs))),this.$model=t.rowIndicator}}}),S=i.defineComponent({name:"RGHeaderSummaries",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setHeaderSummaries(r(i.toRaw(this.$attrs))),this.$model=t.headerSummaries}}}),b=i.defineComponent({name:"RGHeaderSummary",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setHeaderSummary(r(i.toRaw(this.$attrs))),this.$model=t.headerSummary}}}),G=i.defineComponent({name:"RGHeader",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setHeader(r(i.toRaw(this.$attrs))),this.$model=t.header}}}),k=i.defineComponent({name:"RGGroupPanel",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setGroupPanel(r(i.toRaw(this.$attrs))),this.$model=t.groupPanel}}}),B=i.defineComponent({name:"RGFooter",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setFooter(r(i.toRaw(this.$attrs))),this.$model=t.footer}}}),v=i.defineComponent({name:"RGFooters",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setFooters(r(i.toRaw(this.$attrs))),this.$model=t.footer}}}),O=i.defineComponent({name:"RGFilterPanel",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setFilterPanel(r(i.toRaw(this.$attrs))),this.$model=t.filterPanel}}}),V=i.defineComponent({name:"RGDataField",extends:c,props:{},data(){return{}},methods:{mountCB(t){const e=r(i.toRaw(this.$attrs));if(e.fieldName){const n=t.getDataSource();n.fieldByName(e.fieldName)||(this.$model=n.addField(e,!0))}},unmountDB(t){this.$model&&t.getDataSource().removeField(this.$model)}}}),x=i.defineComponent({name:"RGDataColumn",extends:c,data(){return{}},props:{},methods:{mountCB(t){var n;const e=r(i.toRaw((n=this.$parent)==null?void 0:n.$props));if(e){const o=e.autoGenerateField,a=t==null?void 0:t.getDataSource(),s=r(i.toRaw(this.$attrs));let d=s.fieldName;o&&(!d&&s.field&&(d=s.field.fieldName),a&&!a.fieldByName(d)&&a.addField(s.field||d)),t&&(this.$model=t.addColumn({...s,fieldName:d},s.displayIndex??-1))}},unmountCB(t){var n;this.$data.$model&&t.removeColumn(this.$data.$model.name);const e=r(i.toRaw((n=this.$parent)==null?void 0:n.$props));if(e){const o=e.autoGenerateField,a=t==null?void 0:t.getDataSource(),s=r(i.toRaw(this.$attrs));let d=s.fieldName;o&&(!d&&s.field&&(d=s.field.fieldName),t.columnByField(d)||a.removeField(d))}},_doWatchAttrs(t){if(t.hasOwnProperty("width")&&!isNaN(t.width)){const n=i.toRaw(this.$data.$model).layout;n&&(n.cellWidth=t.width)}}}}),D=i.defineComponent({name:"RGLiteralColumn",extends:c,data(){return{}},props:{},methods:{mountCB(t){var n;if(r(i.toRaw((n=this.$parent)==null?void 0:n.$attrs))){const o=r(i.toRaw(this.$attrs));t&&(this.$model=t.addColumn({...o,type:"literal"},o.displayIndex??-1))}},unmountCB(t){this.$data.$model&&t.removeColumn(this.$data.$model.name)},_doWatchAttrs(t){if(t.hasOwnProperty("width")&&!isNaN(t.width)){const n=i.toRaw(this.$data.$model).layout;n&&(n.cellWidth=t.width)}}}}),_=i.defineComponent({name:"RGCheckBar",extends:c,props:{},data(){return{}},methods:{mountCB(t){t.setCheckBar(r(i.toRaw(this.$attrs))),this.$model=t.checkBar}}});exports.RGCheckBar=_;exports.RGDataColumn=x;exports.RGDataField=V;exports.RGFilterPanel=O;exports.RGFooter=B;exports.RGFooters=v;exports.RGGroupPanel=k;exports.RGHeader=G;exports.RGHeaderSummaries=S;exports.RGHeaderSummary=b;exports.RGLiteralColumn=D;exports.RGRowIndicator=P;exports.RGSeriesColumn=y;exports.RGStateBar=g;exports.RealGridVue=f;exports.RealTreeVue=$;