@visactor/vtable-search 1.25.1-alpha.1 → 1.26.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
3
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VTable = global.VTable || {}, global.VTable.export = {})));
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VTable = global.VTable || {}, global.VTable.search = {})));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
7
  const isValid = value => null != value;
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).VTable=e.VTable||{},e.VTable.export={}))}(this,(function(e){"use strict";var t=e=>null!=e;const r="__search_component_highlight",l="__search_component_focus",s={bgColor:"rgba(255, 255, 0, 0.2)"},i={bgColor:"rgba(255, 155, 0, 0.2)"};function n(e,r){return t(e)&&t(r)&&r.toString().includes(e)}function o(e,r,l){if(!t(e))return!1;return(Array.isArray(l)&&l.length>0?l:Object.keys(r)).some((l=>t(r?.[l])&&r[l].toString().includes(e)))}function h(e,t){if("undefined"==typeof document||"undefined"==typeof window)return;const r=e.getElement?.()||e.container;if(!r)return;const l=e.getCellRect(t.col,t.row);if(!l)return;let s=r.parentElement;for(;s;){const e=getComputedStyle(s),t=/(auto|scroll|overlay)/.test(e.overflowY),r=s.scrollHeight>s.clientHeight;if(t&&r)break;s=s.parentElement||s.getRootNode?.()?.host||null}s||(s=document.scrollingElement||document.documentElement);const i=s,n=r.getBoundingClientRect(),o=i.getBoundingClientRect(),h=n.top-o.top+i.scrollTop+l.top,u=h+l.height,a=i.clientHeight,c=i.scrollTop;if(!(h>=c&&u<=c+a)){let e;e=h<c?h:u-a,i.scrollTop=Math.max(0,e)}}e.SearchComponent=class{table;skipHeader;autoJump;highlightCellStyle;focuseHighlightCellStyle;focusHighlightCellStyle;queryMethod;treeQueryMethod;fieldsToSearch;enableViewportScroll;callback;queryStr;queryResult;currentIndex;isTree;treeIndex;scrollOption;constructor(e){this.table=e.table,this.autoJump=e.autoJump||!1,this.skipHeader=e.skipHeader||!1,this.highlightCellStyle=e.highlightCellStyle||s,this.focusHighlightCellStyle=e.focusHighlightCellStyle||e.focuseHighlightCellStyle||i,this.queryMethod=e.queryMethod||n,this.treeQueryMethod=e.treeQueryMethod||o,this.fieldsToSearch=e.fieldsToSearch||[],this.isTree=!1,this.treeIndex=0,this.callback=e.callback,this.scrollOption=e.scrollOption||{duration:900,easing:"quartIn"},this.enableViewportScroll=e.enableViewportScroll||!1,this.table.registerCustomCellStyle(r,this.highlightCellStyle),this.table.registerCustomCellStyle(l,this.focusHighlightCellStyle)}search(e){if(this.clear(),this.queryStr=e,!e)return{index:0,results:this.queryResult};if(this.isTree=this.table.options.columns.some((e=>e.tree)),this.treeIndex=this.isTree?this.table.options.columns.findIndex((e=>e.tree)):0,this.isTree){const e=this.table.colCount,t=(r,l)=>{r.forEach(((r,s)=>{const i=[...l,s];this.treeQueryMethod(this.queryStr,r,this.fieldsToSearch,{table:this.table})&&this.queryResult.push({indexNumber:i,range:{start:{row:null,col:0},end:{row:null,col:e}}}),r.children&&Array.isArray(r.children)&&r.children.length>0&&t(r.children,i)}))};return t(this.table.records,[]),this.queryResult.length>0&&this.jumpToCell({IndexNumber:this.queryResult[0].indexNumber}),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.updateCellStyle(),this.currentIndex=0,{index:0,results:this.queryResult}}for(let e=0;e<this.table.rowCount;e++)for(let t=0;t<this.table.colCount;t++){if(this.skipHeader&&this.table.isHeader(t,e))continue;const r=this.table.getCellValue(t,e);if(this.queryMethod(this.queryStr,r,{col:t,row:e,table:this.table})){const l=this.table.getCellRange(t,e);if(l.start.col!==l.end.col||l.start.row!==l.end.row){let e=!1;for(let t=this.queryResult.length-1;t>=0;t--)if(this.queryResult[t].col===l.start.col&&this.queryResult[t].row===l.start.row){e=!0;break}e||this.queryResult.push({col:l.start.col,row:l.start.row,range:l,value:r})}else this.queryResult.push({col:t,row:e,value:r})}}return this.updateCellStyle(),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.autoJump?this.next():{index:0,results:this.queryResult}}arrangeCustomCellStyle(e,t=!0,l=r){const{col:s,row:i,range:n}=e;this.table.arrangeCustomCellStyle(n?{range:n}:{row:i,col:s},t?l:null)}updateCellStyle(e=!0){if(!e)return this.table.customCellStylePlugin.clearCustomCellStyleArrangement(),(this.queryResult||[]).forEach((e=>{this.table.scenegraph.updateCellContent(e.col,e.row)})),void this.table.scenegraph.updateNextFrame();if(this.queryResult)if(this.table.hasCustomCellStyle(r)||this.table.registerCustomCellStyle(r,this.highlightCellStyle),this.table.hasCustomCellStyle(l)||this.table.registerCustomCellStyle(l,this.focusHighlightCellStyle),this.isTree){const{range:t,indexNumber:r}=this.queryResult[0];let s=0;for(;this.table.isHeader(0,s);)s++;const i=this.getBodyRowIndexByRecordIndex(r)+s;t.start.row=i,t.end.row=i,this.arrangeCustomCellStyle({range:t},e,l)}else{for(let e=0;e<this.queryResult.length;e++)this.table.customCellStylePlugin.addCustomCellStyleArrangement({col:this.queryResult[e].col,row:this.queryResult[e].row},r),this.table.scenegraph.updateCellContent(this.queryResult[e].col,this.queryResult[e].row,!0);this.table.scenegraph.updateNextFrame()}}next(){if(!this.queryResult.length)return{index:0,results:this.queryResult};if(this.isTree){if(-1!==this.currentIndex){const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(e){let r=0;for(;this.table.isHeader(0,r);)r++;const l=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=l,e.end.row=l,this.arrangeCustomCellStyle({range:e})}}this.currentIndex++,this.currentIndex>=this.queryResult.length&&(this.currentIndex=0);const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(this.jumpToCell({IndexNumber:t}),e){let r=0;for(;this.table.isHeader(0,r);)r++;const s=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=s,e.end.row=s,this.arrangeCustomCellStyle({range:e},!0,l)}}else{-1!==this.currentIndex&&this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),this.currentIndex++,this.currentIndex>=this.queryResult.length&&(this.currentIndex=0);const{col:e,row:t}=this.queryResult[this.currentIndex];this.arrangeCustomCellStyle(this.queryResult[this.currentIndex],!0,l),this.jumpToCell({col:e,row:t})}return{index:this.currentIndex,results:this.queryResult}}prev(){if(!this.queryResult.length)return{index:0,results:this.queryResult};if(this.isTree){if(-1!==this.currentIndex){const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(e){let r=0;for(;this.table.isHeader(0,r);)r++;const l=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=l,e.end.row=l,this.arrangeCustomCellStyle({range:e})}}this.currentIndex--,this.currentIndex<0&&(this.currentIndex=this.queryResult.length-1);const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(this.jumpToCell({IndexNumber:t}),e){let r=0;for(;this.table.isHeader(0,r);)r++;const s=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=s,e.end.row=s,this.arrangeCustomCellStyle({range:e},!0,l)}}else{-1!==this.currentIndex&&this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),this.currentIndex--,this.currentIndex<0&&(this.currentIndex=this.queryResult.length-1);const{col:e,row:t}=this.queryResult[this.currentIndex];this.arrangeCustomCellStyle(this.queryResult[this.currentIndex],!0,l),this.jumpToCell({col:e,row:t})}return{index:this.currentIndex,results:this.queryResult}}jumpToCell(e){if(this.isTree){const{IndexNumber:t}=e,r=[...t],l=[...r];let s=0,i=0;for(;s<l.length-1;){s++;const e=r.slice(0,s);for(;this.table.isHeader(0,i);)i++;const t=this.getBodyRowIndexByRecordIndex(e)+i;"expand"!==this.table.getHierarchyState(this.treeIndex,t)&&this.table.toggleHierarchyState(this.treeIndex,t)}const n=this.getBodyRowIndexByRecordIndex(r)+i;this.table.scrollToRow(n,this.scrollOption),this.enableViewportScroll&&h(this.table,{row:n,col:this.treeIndex})}else{const{col:t,row:r}=e,{rowStart:l,rowEnd:s}=this.table.getBodyVisibleRowRange(),{colStart:i,colEnd:n}=this.table.getBodyVisibleColRange();!(r<=l||r>=s||t<=i||t>=n)||this.table.scrollToCell({col:t,row:r}),this.enableViewportScroll&&h(this.table,{row:r,col:t})}}getBodyRowIndexByRecordIndex(e){return Array.isArray(e)&&1===e.length&&(e=e[0]),this.table.dataSource.getTableIndex(e)}clear(){this.updateCellStyle(!1),this.queryStr="",this.queryResult=[],this.currentIndex=-1}}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).VTable=e.VTable||{},e.VTable.search={}))}(this,(function(e){"use strict";var t=e=>null!=e;const r="__search_component_highlight",l="__search_component_focus",s={bgColor:"rgba(255, 255, 0, 0.2)"},i={bgColor:"rgba(255, 155, 0, 0.2)"};function n(e,r){return t(e)&&t(r)&&r.toString().includes(e)}function o(e,r,l){if(!t(e))return!1;return(Array.isArray(l)&&l.length>0?l:Object.keys(r)).some((l=>t(r?.[l])&&r[l].toString().includes(e)))}function h(e,t){if("undefined"==typeof document||"undefined"==typeof window)return;const r=e.getElement?.()||e.container;if(!r)return;const l=e.getCellRect(t.col,t.row);if(!l)return;let s=r.parentElement;for(;s;){const e=getComputedStyle(s),t=/(auto|scroll|overlay)/.test(e.overflowY),r=s.scrollHeight>s.clientHeight;if(t&&r)break;s=s.parentElement||s.getRootNode?.()?.host||null}s||(s=document.scrollingElement||document.documentElement);const i=s,n=r.getBoundingClientRect(),o=i.getBoundingClientRect(),h=n.top-o.top+i.scrollTop+l.top,u=h+l.height,a=i.clientHeight,c=i.scrollTop;if(!(h>=c&&u<=c+a)){let e;e=h<c?h:u-a,i.scrollTop=Math.max(0,e)}}e.SearchComponent=class{table;skipHeader;autoJump;highlightCellStyle;focuseHighlightCellStyle;focusHighlightCellStyle;queryMethod;treeQueryMethod;fieldsToSearch;enableViewportScroll;callback;queryStr;queryResult;currentIndex;isTree;treeIndex;scrollOption;constructor(e){this.table=e.table,this.autoJump=e.autoJump||!1,this.skipHeader=e.skipHeader||!1,this.highlightCellStyle=e.highlightCellStyle||s,this.focusHighlightCellStyle=e.focusHighlightCellStyle||e.focuseHighlightCellStyle||i,this.queryMethod=e.queryMethod||n,this.treeQueryMethod=e.treeQueryMethod||o,this.fieldsToSearch=e.fieldsToSearch||[],this.isTree=!1,this.treeIndex=0,this.callback=e.callback,this.scrollOption=e.scrollOption||{duration:900,easing:"quartIn"},this.enableViewportScroll=e.enableViewportScroll||!1,this.table.registerCustomCellStyle(r,this.highlightCellStyle),this.table.registerCustomCellStyle(l,this.focusHighlightCellStyle)}search(e){if(this.clear(),this.queryStr=e,!e)return{index:0,results:this.queryResult};if(this.isTree=this.table.options.columns.some((e=>e.tree)),this.treeIndex=this.isTree?this.table.options.columns.findIndex((e=>e.tree)):0,this.isTree){const e=this.table.colCount,t=(r,l)=>{r.forEach(((r,s)=>{const i=[...l,s];this.treeQueryMethod(this.queryStr,r,this.fieldsToSearch,{table:this.table})&&this.queryResult.push({indexNumber:i,range:{start:{row:null,col:0},end:{row:null,col:e}}}),r.children&&Array.isArray(r.children)&&r.children.length>0&&t(r.children,i)}))};return t(this.table.records,[]),this.queryResult.length>0&&this.jumpToCell({IndexNumber:this.queryResult[0].indexNumber}),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.updateCellStyle(),this.currentIndex=0,{index:0,results:this.queryResult}}for(let e=0;e<this.table.rowCount;e++)for(let t=0;t<this.table.colCount;t++){if(this.skipHeader&&this.table.isHeader(t,e))continue;const r=this.table.getCellValue(t,e);if(this.queryMethod(this.queryStr,r,{col:t,row:e,table:this.table})){const l=this.table.getCellRange(t,e);if(l.start.col!==l.end.col||l.start.row!==l.end.row){let e=!1;for(let t=this.queryResult.length-1;t>=0;t--)if(this.queryResult[t].col===l.start.col&&this.queryResult[t].row===l.start.row){e=!0;break}e||this.queryResult.push({col:l.start.col,row:l.start.row,range:l,value:r})}else this.queryResult.push({col:t,row:e,value:r})}}return this.updateCellStyle(),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.autoJump?this.next():{index:0,results:this.queryResult}}arrangeCustomCellStyle(e,t=!0,l=r){const{col:s,row:i,range:n}=e;this.table.arrangeCustomCellStyle(n?{range:n}:{row:i,col:s},t?l:null)}updateCellStyle(e=!0){if(!e)return this.table.customCellStylePlugin.clearCustomCellStyleArrangement(),(this.queryResult||[]).forEach((e=>{this.table.scenegraph.updateCellContent(e.col,e.row)})),void this.table.scenegraph.updateNextFrame();if(this.queryResult)if(this.table.hasCustomCellStyle(r)||this.table.registerCustomCellStyle(r,this.highlightCellStyle),this.table.hasCustomCellStyle(l)||this.table.registerCustomCellStyle(l,this.focusHighlightCellStyle),this.isTree){const{range:t,indexNumber:r}=this.queryResult[0];let s=0;for(;this.table.isHeader(0,s);)s++;const i=this.getBodyRowIndexByRecordIndex(r)+s;t.start.row=i,t.end.row=i,this.arrangeCustomCellStyle({range:t},e,l)}else{for(let e=0;e<this.queryResult.length;e++)this.table.customCellStylePlugin.addCustomCellStyleArrangement({col:this.queryResult[e].col,row:this.queryResult[e].row},r),this.table.scenegraph.updateCellContent(this.queryResult[e].col,this.queryResult[e].row,!0);this.table.scenegraph.updateNextFrame()}}next(){if(!this.queryResult.length)return{index:0,results:this.queryResult};if(this.isTree){if(-1!==this.currentIndex){const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(e){let r=0;for(;this.table.isHeader(0,r);)r++;const l=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=l,e.end.row=l,this.arrangeCustomCellStyle({range:e})}}this.currentIndex++,this.currentIndex>=this.queryResult.length&&(this.currentIndex=0);const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(this.jumpToCell({IndexNumber:t}),e){let r=0;for(;this.table.isHeader(0,r);)r++;const s=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=s,e.end.row=s,this.arrangeCustomCellStyle({range:e},!0,l)}}else{-1!==this.currentIndex&&this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),this.currentIndex++,this.currentIndex>=this.queryResult.length&&(this.currentIndex=0);const{col:e,row:t}=this.queryResult[this.currentIndex];this.arrangeCustomCellStyle(this.queryResult[this.currentIndex],!0,l),this.jumpToCell({col:e,row:t})}return{index:this.currentIndex,results:this.queryResult}}prev(){if(!this.queryResult.length)return{index:0,results:this.queryResult};if(this.isTree){if(-1!==this.currentIndex){const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(e){let r=0;for(;this.table.isHeader(0,r);)r++;const l=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=l,e.end.row=l,this.arrangeCustomCellStyle({range:e})}}this.currentIndex--,this.currentIndex<0&&(this.currentIndex=this.queryResult.length-1);const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(this.jumpToCell({IndexNumber:t}),e){let r=0;for(;this.table.isHeader(0,r);)r++;const s=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=s,e.end.row=s,this.arrangeCustomCellStyle({range:e},!0,l)}}else{-1!==this.currentIndex&&this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),this.currentIndex--,this.currentIndex<0&&(this.currentIndex=this.queryResult.length-1);const{col:e,row:t}=this.queryResult[this.currentIndex];this.arrangeCustomCellStyle(this.queryResult[this.currentIndex],!0,l),this.jumpToCell({col:e,row:t})}return{index:this.currentIndex,results:this.queryResult}}jumpToCell(e){if(this.isTree){const{IndexNumber:t}=e,r=[...t],l=[...r];let s=0,i=0;for(;s<l.length-1;){s++;const e=r.slice(0,s);for(;this.table.isHeader(0,i);)i++;const t=this.getBodyRowIndexByRecordIndex(e)+i;"expand"!==this.table.getHierarchyState(this.treeIndex,t)&&this.table.toggleHierarchyState(this.treeIndex,t)}const n=this.getBodyRowIndexByRecordIndex(r)+i;this.table.scrollToRow(n,this.scrollOption),this.enableViewportScroll&&h(this.table,{row:n,col:this.treeIndex})}else{const{col:t,row:r}=e,{rowStart:l,rowEnd:s}=this.table.getBodyVisibleRowRange(),{colStart:i,colEnd:n}=this.table.getBodyVisibleColRange();!(r<=l||r>=s||t<=i||t>=n)||this.table.scrollToCell({col:t,row:r}),this.enableViewportScroll&&h(this.table,{row:r,col:t})}}getBodyRowIndexByRecordIndex(e){return Array.isArray(e)&&1===e.length&&(e=e[0]),this.table.dataSource.getTableIndex(e)}clear(){this.updateCellStyle(!1),this.queryStr="",this.queryResult=[],this.currentIndex=-1}}}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vtable-search",
3
- "version": "1.25.1-alpha.1",
3
+ "version": "1.26.1-alpha.0",
4
4
  "description": "The search util of VTable",
5
5
  "author": {
6
6
  "name": "VisActor",
@@ -24,13 +24,14 @@
24
24
  },
25
25
  "unpkg": "latest",
26
26
  "unpkgFiles": [
27
- "dist/vtable-exporter.js"
27
+ "dist/vtable-search.js",
28
+ "dist/vtable-search.min.js"
28
29
  ],
29
30
  "publishConfig": {
30
31
  "access": "public"
31
32
  },
32
33
  "dependencies": {
33
- "@visactor/vtable": "1.25.1-alpha.1",
34
+ "@visactor/vtable": "1.26.1-alpha.0",
34
35
  "@visactor/vutils": "~1.0.17"
35
36
  },
36
37
  "devDependencies": {
@@ -78,8 +79,8 @@
78
79
  "@types/react-is": "^17.0.3",
79
80
  "rollup-plugin-node-resolve": "5.2.0",
80
81
  "@internal/bundler": "0.0.1",
81
- "@internal/eslint-config": "0.0.1",
82
- "@internal/ts-config": "0.0.1"
82
+ "@internal/ts-config": "0.0.1",
83
+ "@internal/eslint-config": "0.0.1"
83
84
  },
84
85
  "scripts": {
85
86
  "start": "vite ./demo",