@sl-material/sl-table-sheet 1.0.0-beta0

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.
@@ -0,0 +1,491 @@
1
+ "use strict";var B=Object.defineProperty;var V=(c,e,t)=>e in c?B(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var u=(c,e,t)=>V(c,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("xlsx"),_=require("@visactor/vtable-sheet"),H=require("@visactor/vtable-editors");function I(c){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>c[t]})}}return e.default=c,Object.freeze(e)}const b=I(j),y=I(_),k=I(H);class T{static detectHeaderRows(e,t){let n=1;t!==void 0?n=t:n=this.autoDetectHeaderRows(e);const o=e.slice(0,n),s=this.filterTitleRows(o);return{headerRows:n,dataStartRow:n,effectiveHeaderRows:s}}static autoDetectHeaderRows(e){const t=Math.min(5,e.length);let n=1;const o=e[0]||[],s=e[1]||[],l=this.getNonEmptyCells(o),i=this.getNonEmptyCells(s),a=this.isTitleRow(l),d=this.isHeaderRow(i);if(a&&d)return 2;if(d&&!a)return 1;for(let r=0;r<t-1;r++){const h=e[r]||[],p=this.getNonEmptyCells(h),f=this.isTitleRow(p),m=this.isHeaderRow(p),g=this.isDataRow(p);if(f&&m)n=Math.max(n,r+2);else if(m&&!g&&r<t-2){const w=e[r+2]||[],S=this.getNonEmptyCells(w);this.isDataRow(S)||(n=Math.max(n,r+2))}}return n}static filterTitleRows(e){for(let t=0;t<e.length;t++){const n=e[t],o=this.getNonEmptyCells(n);if(o.length===1&&o[0].length>20)return e.slice(t+1)}return e}static getNonEmptyCells(e){return e.filter(t=>String(t||"").trim()!=="")}static isTitleRow(e){return e.length===1&&e[0].length>20}static isHeaderRow(e){return e.length>3}static isDataRow(e){return e.length>0&&e.some(t=>{const n=String(t||"").trim();return/^\d+$/.test(n)||/^\d{4}-\d{1,2}-\d{1,2}/.test(n)||n.length<=10})}static mergeHeaders(e,t){const n=[];for(let o=0;o<t;o++){const s=[];let l=!1;for(let i=e.length-1;i>=0;i--){const a=e[i][o],d=String(a||"").trim();d!==""?l||s.unshift(d):l=!0}n.push(s.length>0?s.join(" - "):`列${o+1}`)}return n}}function R(c){if(c){if(c.length===8)return"#"+c.substring(2);if(c.length===6)return"#"+c}}function P(c,e){return{0:"#FFFFFF",1:"#000000",2:"#E7E6E6",3:"#44546A",4:"#4472C4",5:"#ED7D31",6:"#A5A5A5",7:"#FFC000",8:"#5B9BD5",9:"#70AD47"}[c]}function C(c){if(c){if(c.rgb)return R(c.rgb);if(c.argb)return R(c.argb);if(c.theme!==void 0)return P(c.theme,c.tint);if(c.indexed!==void 0)return{64:"#000000",65:"#FFFFFF",8:"#000000",9:"#FFFFFF",10:"#FF0000",11:"#00FF00",12:"#0000FF",13:"#FFFF00",14:"#FF00FF",15:"#00FFFF"}[c.indexed]}}class q{static extractStyles(e,t,n){const o=new Map,s=t.Styles;if(!s)return;const l=s.Fonts||[],i=s.Fills||[],a=s.CellXf||[],d=b.utils.decode_range(e["!ref"]||"A1");for(let r=n;r<=d.e.r;r++)for(let h=d.s.c;h<=d.e.c;h++){const p=b.utils.encode_cell({r,c:h}),f=e[p];if((f==null?void 0:f.s)!==void 0){const m=this.extractCellStyle(f,l,i,a);if(m&&this.hasNonDefaultStyle(m)){const g=r-n;o.set(`${g}-${h}`,m)}}}return o.size>0?o:void 0}static extractCellStyle(e,t,n,o){var d;const s={};let l=null,i,a;if(typeof e.s=="number")l=o[e.s],i=(l==null?void 0:l.fontId)??(l==null?void 0:l.fontid),a=(l==null?void 0:l.fillId)??(l==null?void 0:l.fillid);else if(typeof e.s=="object"&&(l=e.s,i=l.fontId??l.fontid,a=l.fillId??l.fillid,l.patternType==="solid")){if(l.fgColor&&Object.keys(l.fgColor).length>0){const r=C(l.fgColor);r&&(s.bgColor=r)}if(!s.bgColor&&((d=l.bgColor)==null?void 0:d.indexed)!==void 0){const r=C(l.bgColor);r&&(s.bgColor=r)}}return l&&(this.extractFontStyle(s,i,t),this.extractFillStyle(s,a,n)),s}static extractFontStyle(e,t,n){if(t!==void 0&&n[t]){const o=n[t];if(o.color){const s=C(o.color);s&&s!=="#000000"&&(e.fontColor=s)}o.bold&&(e.bold=!0),o.italic&&(e.italic=!0)}}static extractFillStyle(e,t,n){if(t!==void 0&&n[t]){const o=n[t];if(o.patternType==="solid"&&o.fgColor){const s=C(o.fgColor);s&&(e.bgColor=s)}}}static hasNonDefaultStyle(e){return!!(e.fontColor||e.bgColor||e.bold||e.italic)}}class U{static extractComments(e,t){const n=new Map;return this.collectComments(e).forEach(s=>{const l=b.utils.decode_cell(s.r),i=l.r-t,a=l.c;if(i>=0){const d=`${i}-${a}`,r=this.cleanCommentText(s.t,s.a);n.set(d,{text:r,author:s.a})}}),n.size>0?n:void 0}static collectComments(e){let t=[];return e["!comments"]&&(t=e["!comments"]),t.length===0&&(t=this.extractCommentsFromCells(e)),t}static extractCommentsFromCells(e){const t=[];return Object.keys(e).forEach(n=>{if(!n.startsWith("!")){const o=e[n];o!=null&&o.c&&Array.isArray(o.c)&&o.c.forEach(s=>{const l=s.t||(s.r&&typeof s.r=="string"?s.r:"");l&&t.push({r:n,t:l,a:s.a})})}}),t}static cleanCommentText(e,t){let n=e;return t&&n.startsWith(t+":")&&(n=n.substring(t.length+1).trim(),n.startsWith(`
2
+ `)&&(n=n.substring(1))),n}}class K{static parseBuffer(e,t={}){const{sheetIndex:n=0,headerRow:o=0,headerRows:s,mergeHeaders:l=!0,extractStyles:i=!0,extractComments:a=!0}=t,d=b.read(e,{type:"array",cellStyles:!0,cellNF:!0}),r=d.SheetNames;if(n>=r.length)throw new Error(`Sheet index ${n} out of range. Available sheets: ${r.length}`);const h=d.Sheets[r[n]],p=b.utils.sheet_to_json(h,{header:1,defval:""});if(p.length===0)return{columns:[],records:[]};const{headerRows:f,dataStartRow:m,effectiveHeaderRows:g}=T.detectHeaderRows(p.slice(o),s),w=this.buildColumns(p,o,f,g,l),S=p.slice(o+m),E=i?q.extractStyles(h,d,o+m):void 0,A=a?U.extractComments(h,o+m):void 0;return{columns:w,records:S,cellStyles:E,cellComments:A}}static buildColumns(e,t,n,o,s){if(s&&n>1){const i=e.slice(t,t+n),a=Math.max(...i.map(r=>r.length));return T.mergeHeaders(o,a).map((r,h)=>({key:`col_${h}`,field:`col_${h}`,title:r,width:120,sort:!1,filter:!1}))}return(e[t]||[]).map((i,a)=>({key:`col_${a}`,field:`col_${a}`,title:String(i||`Column ${a+1}`),width:120,sort:!1,filter:!1}))}}class O{static exportToStream(e,t,n){const{filterEmptyColumns:o=!0}=n||{},s=o?this.filterEmptyColumns(e):e,l=s.map(h=>h.title||h.field||""),i=this.buildDataRows(t,e,s),a=[l,...i],d=b.utils.aoa_to_sheet(a),r=b.utils.book_new();return b.utils.book_append_sheet(r,d,"Sheet1"),b.write(r,{bookType:"xlsx",type:"array"})}static download(e,t="export"){const n=new Blob([e],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),o=URL.createObjectURL(n),s=document.createElement("a");s.href=o,s.download=`${t}.xlsx`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o)}static filterEmptyColumns(e){return e.filter(t=>{const n=t.title||t.field||"";return n&&typeof n=="string"&&n.trim()!==""})}static buildDataRows(e,t,n){return e.map(o=>Array.isArray(o)?n.map(s=>{const l=t.indexOf(s);if(l>=0&&l<o.length){const i=o[l];return this.extractCellValue(i)}return""}):n.map(s=>{const l=s.field||s.key,i=l?o[l]:void 0;return this.extractCellValue(i)}))}static extractCellValue(e){return e&&typeof e=="object"&&"value"in e?e.value:e}}async function N(c){const e=await fetch(c);if(!e.ok)throw new Error(`Failed to fetch Excel file: ${e.statusText}`);return e.arrayBuffer()}function v(c,e={}){return K.parseBuffer(c,e)}async function L(c,e={}){const t=await N(c);return v(t,e)}async function $(c,e={}){const t=await Y(c);return v(t,e)}function X(c,e,t){return O.exportToStream(c,e,t)}function W(c,e="export"){O.download(c,e)}function Y(c){return new Promise((e,t)=>{const n=new FileReader;n.onload=o=>{var l;const s=(l=o.target)==null?void 0:l.result;e(s)},n.onerror=()=>t(new Error("Failed to read file")),n.readAsArrayBuffer(c)})}class G{constructor(e,t){u(this,"customComponentContainers",new Map);u(this,"activeComponentKey",null);u(this,"justCreatedComponent",!1);u(this,"tableInstance",null);u(this,"container",null);u(this,"handleOutsideClick",e=>{if(this.justCreatedComponent||!this.activeComponentKey)return;const t=this.customComponentContainers.get(this.activeComponentKey);t&&!t.contains(e.target)&&this.closeActiveComponent()});this.tableInstance=e,this.container=t,this.bindOutsideClickHandler()}showComponent(e,t,n){var m;const{col:o,row:s}=n,l=this.tableInstance.getCellRect(o,s),i=this.tableInstance.getCellValue(o,s),a=(m=this.container)==null?void 0:m.getBoundingClientRect(),d=((a==null?void 0:a.left)||0)+l.left,r=((a==null?void 0:a.top)||0)+l.bottom,h=this.createComponentContainer(d,r,t),p={table:this.tableInstance,row:s,col:o,value:i,dataValue:n.dataValue,rect:l,setValue:g=>{this.tableInstance.changeCellValue(o,s,g),this.closeActiveComponent()},close:()=>{this.closeActiveComponent()}};try{const g=t.render(p);h.appendChild(g),document.body.appendChild(h)}catch(g){console.error("❌ 渲染组件时出错:",g);return}const f=`${e}-${o}-${s}`;this.customComponentContainers.set(f,h),this.activeComponentKey=f,t.onMount&&t.onMount(h,p),h.addEventListener("click",g=>{g.stopPropagation()}),this.justCreatedComponent=!0,setTimeout(()=>{this.justCreatedComponent=!1},100)}createComponentContainer(e,t,n){const o=document.createElement("div");return o.className="vtable-custom-component",o.style.position="fixed",o.style.zIndex="9999",o.style.left=`${e}px`,o.style.top=`${t}px`,o.style.backgroundColor="white",o.style.borderRadius="4px",o.style.boxShadow="0 2px 12px rgba(0, 0, 0, 0.15)",n.containerStyle&&Object.assign(o.style,n.containerStyle),o}closeActiveComponent(){if(!this.activeComponentKey)return;const e=this.customComponentContainers.get(this.activeComponentKey);e&&(e.remove(),this.customComponentContainers.delete(this.activeComponentKey)),this.activeComponentKey=null}bindOutsideClickHandler(){document.addEventListener("click",this.handleOutsideClick)}destroy(){this.closeActiveComponent(),this.customComponentContainers.clear(),document.removeEventListener("click",this.handleOutsideClick)}}class M{constructor(e,t){u(this,"markedMap",null);u(this,"tableInstance",null);this.tableInstance=e,this.markedMap=t||null}handleCellMouseEnter(e){const{col:t,row:n}=e,o=this.tableInstance.columnHeaderLevelCount||1,s=n-o,l=`${s}-${t}`;this.markedMap&&this.markedMap.has(l)&&s>=0&&this.showTooltip(t,n,l)}showTooltip(e,t,n){const o=this.tableInstance.getVisibleCellRangeRelativeRect({col:e,row:t}),s=this.markedMap.get(n),l=this.tableInstance.getCellValue(e,t);let i=`${l}`;if(s&&typeof s=="object"&&"comment"in s){const a=s.comment;a&&(i=`${l}: ${a}`)}this.tableInstance.showTooltip(e,t,{content:i,referencePosition:{rect:o,placement:"right"},className:"defineTooltip",disappearDelay:100,style:{bgColor:"black",color:"white",font:"normal bold normal 14px/1 STKaiti",arrowMark:!0,padding:[12]}})}getMarkedMap(){return this.markedMap}setMarkedMap(e){this.markedMap=e}}class J{static registerEditors(e){if(e){if(e.dateEditor!==!1){const t=new k.DateInputEditor(e.dateEditor||{});y.VTable.register.editor("dateEditor",t)}if(e.listEditor){const t=new k.ListEditor(e.listEditor||{values:["技术中心","财务部"]});y.VTable.register.editor("listEditor",t)}e.customEditors&&Object.entries(e.customEditors).forEach(([t,n])=>{y.VTable.register.editor(t,n)})}}}class Q{constructor(e,t,n){u(this,"tableInstance");u(this,"config");u(this,"customComponentManager",null);u(this,"cellMarkManager",null);this.config=e,this.tableInstance=e.tableInstance,this.customComponentManager=t,this.cellMarkManager=n}bindEvents(){this.tableInstance&&(this.tableInstance.on("click_cell",e=>{var t,n;this.handleCellClick(e),(n=(t=this.config).onCellClick)==null||n.call(t,e)}),this.config.onCellChange&&this.tableInstance.on("change_cell_value",this.config.onCellChange),this.tableInstance.on("mouseenter_cell",e=>{var t;(t=this.cellMarkManager)==null||t.handleCellMouseEnter(e)}))}handleCellClick(e){var i,a,d;const{col:t}=e,o=(this.config.columns||[])[t];if(!(o!=null&&o.customComponent))return;const s=o.customComponent,l=(i=this.config.customComponents)==null?void 0:i[s];l!=null&&l.showOnClick&&((a=this.customComponentManager)==null||a.closeActiveComponent(),(d=this.customComponentManager)==null||d.showComponent(s,l,e))}on(e,t){var n;(n=this.tableInstance)==null||n.on(e,t)}off(e,t){var n;(n=this.tableInstance)==null||n.off(e,t)}}class F{constructor(e,t){u(this,"sheetInstance",null);u(this,"tableInstance",null);u(this,"container",null);u(this,"config");u(this,"customComponentManager",null);u(this,"cellMarkManager",null);u(this,"eventManager",null);this.config=e,this.cellMarkManager=new M(null,t||void 0),this.init()}init(){if(this.container=this.getContainer(this.config.container),!this.container)throw new Error("Container not found");J.registerEditors(this.config.editors),this.createSheet()}getContainer(e){return typeof e=="string"?document.getElementById(e)||document.querySelector(e):e}createSheet(){var i,a;const{columns:e=[],records:t=[],showFormulaBar:n=!0,showSheetTab:o=!0,sheets:s,options:l}=this.config;this.sheetInstance=new y.VTableSheet(this.container,{showFormulaBar:n,showSheetTab:o,sheets:s||[{sheetKey:"sheet1",sheetTitle:"Sheet1",dragOrder:{dragHeaderMode:"all"},columns:e,data:t}],tooltip:{isShowOverflowTextTooltip:!0},...l}),this.tableInstance=(i=this.sheetInstance.getActiveSheet())==null?void 0:i.tableInstance,this.customComponentManager=new G(this.tableInstance,this.container),this.cellMarkManager=new M(this.tableInstance,((a=this.cellMarkManager)==null?void 0:a.getMarkedMap())||void 0),this.eventManager=new Q({tableInstance:this.tableInstance,columns:this.config.columns,customComponents:this.config.customComponents,onCellClick:this.config.onCellClick,onCellChange:this.config.onCellChange},this.customComponentManager,this.cellMarkManager),this.eventManager.bindEvents()}changeCellValue(e,t,n){this.tableInstance&&this.tableInstance.changeCellValue(e,t,n)}getCellValue(e,t){var n;return(n=this.tableInstance)==null?void 0:n.getCellValue(e,t)}getSelectedCells(){var e;return(e=this.tableInstance)==null?void 0:e.getSelectedCellInfos()}updateData(e){var n;console.log("updateData 调用:",e.length,"条记录");const t=(n=this.sheetInstance)==null?void 0:n.getActiveSheet();if(t)if(typeof t.updateRecords=="function")console.log("使用 updateRecords 方法"),t.updateRecords(e);else if(typeof t.setData=="function")console.log("使用 setData 方法"),t.setData(e);else if(this.tableInstance)if(typeof this.tableInstance.updateOption=="function"){console.log("使用 tableInstance.updateOption 方法");const o=this.tableInstance.option||{};this.tableInstance.updateOption({...o,records:e})}else console.warn("无法更新数据:找不到合适的方法");else console.warn("无法更新数据:找不到合适的方法");else console.warn("无法获取活动工作表")}updateColumns(e){var n;console.log("updateColumns 调用:",e.length,"列");const t=(n=this.sheetInstance)==null?void 0:n.getActiveSheet();if(t)if(typeof t.updateColumns=="function")console.log("使用 activeSheet.updateColumns 方法"),t.updateColumns(e);else if(typeof t.setColumns=="function")console.log("使用 setColumns 方法"),t.setColumns(e);else if(this.tableInstance)if(typeof this.tableInstance.updateOption=="function"){console.log("使用 tableInstance.updateOption 方法更新列");const o=this.tableInstance.option||{};this.tableInstance.updateOption({...o,columns:e})}else console.warn("无法更新列配置:找不到合适的方法");else console.warn("无法更新列配置:找不到合适的方法");else console.warn("无法获取活动工作表")}addRow(e,t){var o;const n=(o=this.sheetInstance)==null?void 0:o.getActiveSheet();n&&n.addRecord(e,t)}deleteRow(e){var n;const t=(n=this.sheetInstance)==null?void 0:n.getActiveSheet();t&&t.deleteRecord(e)}exportData(e="csv"){var t,n;return(n=(t=this.sheetInstance)==null?void 0:t.exportData)==null?void 0:n.call(t,e)}switchSheet(e){var t,n;(t=this.sheetInstance)==null||t.switchSheet(e),this.tableInstance=(n=this.sheetInstance.getActiveSheet())==null?void 0:n.tableInstance}getActiveSheet(){var e;return(e=this.sheetInstance)==null?void 0:e.getActiveSheet()}getAllSheets(){var e;return(e=this.sheetInstance)==null?void 0:e.getAllSheets()}refresh(){if(this.tableInstance&&this.tableInstance.option)try{this.tableInstance.updateOption(this.tableInstance.option)}catch(e){console.warn("刷新表格失败:",e);const t=this.tableInstance.container;t&&(t.style.display="none",setTimeout(()=>{t.style.display=""},0))}}getSheetInstance(){return this.sheetInstance}getTableInstance(){return this.tableInstance}setColumnCustomRender(e,t){var o;const n=(o=this.sheetInstance)==null?void 0:o.getActiveSheet();if(n){const s=n.columns||[],l=s.find(i=>i.field===e);l&&(l.customRender=t,n.updateColumns(s))}}getMarkedMap(){var e;return((e=this.cellMarkManager)==null?void 0:e.getMarkedMap())||null}on(e,t){var n;(n=this.eventManager)==null||n.on(e,t)}off(e,t){var n;(n=this.eventManager)==null||n.off(e,t)}destroy(){var e,t,n;(e=this.customComponentManager)==null||e.destroy(),this.customComponentManager=null,this.cellMarkManager=null,this.eventManager=null,this.sheetInstance&&((n=(t=this.sheetInstance).destroy)==null||n.call(t),this.sheetInstance=null,this.tableInstance=null)}}class Z{constructor(e={}){u(this,"dialog",null);u(this,"tableInstance",null);u(this,"elements",{});u(this,"state",{findText:"",replaceText:"",matches:[],currentIndex:0});u(this,"options");this.options=e,this.tableInstance=e.tableInstance,this.init()}init(){this.createDialog(),this.bindEvents(),this.injectStyles()}createDialog(){this.dialog=document.createElement("div"),this.dialog.className="find-replace-dialog",this.dialog.style.display="none",this.dialog.innerHTML=`
3
+ <div class="find-replace-container">
4
+ <div class="find-replace-body">
5
+ <div class="find-replace-group">
6
+ <label class="find-replace-label">查找内容</label>
7
+ <div class="find-replace-input-wrapper">
8
+ <input
9
+ type="text"
10
+ class="find-replace-input find-input"
11
+ placeholder="请输入查找内容"
12
+ />
13
+ </div>
14
+ </div>
15
+
16
+ <div class="find-replace-group">
17
+ <label class="find-replace-label">替换为</label>
18
+ <input
19
+ type="text"
20
+ class="find-replace-input replace-input"
21
+ placeholder="请输入替换内容"
22
+ />
23
+ </div>
24
+
25
+ <div class="find-replace-result" style="display: none">
26
+ 已找到 <span class="total-matches">0</span> 个结果
27
+ <span class="current-position"></span>
28
+ </div>
29
+ </div>
30
+
31
+ <div class="find-replace-footer">
32
+ <button class="find-replace-btn cancel-btn">关闭</button>
33
+ <button class="find-replace-btn find-prev-btn">查找上一个</button>
34
+ <button class="find-replace-btn find-next-btn">查找下一个</button>
35
+ <button class="find-replace-btn replace-one-btn">替换</button>
36
+ <button class="find-replace-btn find-replace-btn-primary replace-all-btn">全部替换</button>
37
+ </div>
38
+ </div>
39
+ `,(this.resolveContainer(this.options.container)||document.body).appendChild(this.dialog),this.elements={findInput:this.dialog.querySelector(".find-input"),replaceInput:this.dialog.querySelector(".replace-input"),resultInfo:this.dialog.querySelector(".find-replace-result"),totalMatches:this.dialog.querySelector(".total-matches"),selectedColumnsOnly:this.dialog.querySelector(".selected-columns-only")}}bindEvents(){var t,n,o,s,l;if(!this.dialog)return;const e=this.dialog.querySelector(".cancel-btn");e==null||e.addEventListener("click",()=>this.close()),this.bindDragEvents(),(t=this.elements.findInput)==null||t.addEventListener("input",i=>{this.state.findText=i.target.value,this.state.findText||this.clearResults()}),(n=this.dialog.querySelector(".find-next-btn"))==null||n.addEventListener("click",()=>this.findNext()),(o=this.dialog.querySelector(".find-prev-btn"))==null||o.addEventListener("click",()=>this.findPrevious()),(s=this.dialog.querySelector(".replace-one-btn"))==null||s.addEventListener("click",()=>this.replaceOne()),(l=this.dialog.querySelector(".replace-all-btn"))==null||l.addEventListener("click",()=>this.replaceAll())}bindDragEvents(){var r;const e=(r=this.dialog)==null?void 0:r.querySelector(".find-replace-header");if(!e||!this.dialog)return;let t=!1,n=0,o=0,s=0,l=0;const i=h=>{t=!0,n=h.clientX,o=h.clientY;const p=this.dialog.getBoundingClientRect();s=p.left,l=p.top,this.dialog.style.left=`${s}px`,this.dialog.style.transform="none",document.addEventListener("mousemove",a),document.addEventListener("mouseup",d)},a=h=>{if(!t||!this.dialog)return;const p=h.clientX-n,f=h.clientY-o,m=Math.max(0,s+p),g=Math.max(0,l+f);this.dialog.style.left=`${m}px`,this.dialog.style.top=`${g}px`},d=()=>{t=!1,document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",d)};e.addEventListener("mousedown",i)}injectStyles(){if(document.getElementById("find-replace-styles"))return;const e=document.createElement("style");e.id="find-replace-styles",e.textContent=`
40
+ .find-replace-dialog {
41
+ position: fixed;
42
+ top: 80px;
43
+ left: 50%;
44
+ transform: translateX(-50%);
45
+ z-index: 9999;
46
+ font-size: 14px;
47
+ color: #1D2129;
48
+ pointer-events: auto;
49
+ }
50
+
51
+ .find-replace-container {
52
+ background: white;
53
+ border-radius: 8px;
54
+ width: 500px;
55
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
56
+ animation: slideIn 0.2s ease-out;
57
+ }
58
+
59
+ @keyframes slideIn {
60
+ from { opacity: 0; transform: translateX(20px); }
61
+ to { opacity: 1; transform: translateX(0); }
62
+ }
63
+
64
+
65
+
66
+ .find-replace-title {
67
+ font-size: 16px;
68
+ font-weight: 500;
69
+ color: #303133;
70
+ }
71
+
72
+
73
+
74
+ .find-replace-body {
75
+ padding: 16px;
76
+ }
77
+
78
+ .find-replace-group {
79
+ margin-bottom: 16px;
80
+ display: flex;
81
+ align-items: center;
82
+
83
+ }
84
+
85
+ .find-replace-label {
86
+ display: block;
87
+ min-width: 56px;
88
+ margin-right: 8px;
89
+ }
90
+
91
+ .find-replace-checkbox {
92
+
93
+ display: none;
94
+ align-items: center;
95
+ font-weight: normal;
96
+ min-width: auto;
97
+ margin-right: 0;
98
+ }
99
+
100
+ .find-replace-checkbox input {
101
+ margin-right: 6px;
102
+ }
103
+
104
+ .find-replace-input-wrapper {
105
+ position: relative;
106
+ display: flex;
107
+ align-items: center;
108
+ flex: 1;
109
+ height: 32px;
110
+ }
111
+
112
+ .find-replace-input {
113
+ width: 100%;
114
+ padding: 0px 12px;
115
+ border: 1px solid #dcdfe6;
116
+ border-radius: 4px;
117
+ height:32px;
118
+ }
119
+
120
+ .find-replace-input:focus {
121
+ outline: none;
122
+ border-color: #409eff;
123
+ }
124
+
125
+ .current-position {
126
+ margin-left: 10px;
127
+ color: #409eff;
128
+ font-weight: 500;
129
+ }
130
+
131
+ .find-replace-footer {
132
+ padding: 0px 16px 16px 16px;
133
+ display: flex;
134
+ justify-content: flex-end;
135
+ gap: 8px;
136
+ flex-wrap: wrap;
137
+ }
138
+
139
+ .find-replace-btn {
140
+ padding: 6px 16px;
141
+ border-radius: 4px;
142
+ height: 32px;
143
+ cursor: pointer;
144
+ background: var(--sl-color-white);
145
+ border: 1px solid var(--sl-border-color);
146
+ }
147
+
148
+ .find-replace-btn-primary {
149
+ background-color: var(--sl-color-primary);
150
+ color: white;
151
+ }
152
+
153
+ .find-replace-btn-primary:hover {
154
+ border-color: var(--sl-button-hover-border-color);
155
+ background-color: var(--sl-button-hover-bg-color);
156
+ }
157
+
158
+ .message-toast {
159
+ height:40px;
160
+ position: fixed;
161
+ top: 20px;
162
+ left: 50%;
163
+ transform: translateX(-50%) translateY(-100px);
164
+ padding: 11px 15px;
165
+ color: white;
166
+ border-radius: 4px;
167
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
168
+ z-index: 9999;
169
+ opacity: 0;
170
+ transition: all 0.3s ease-out;
171
+ display: flex;
172
+ align-items: center;
173
+ }
174
+ .message-toast--info {
175
+ background-color: var(--sl-color-info-light-9);
176
+ border: 1px solid var(--sl-color-info-light-8);
177
+ color: var(--sl-color-info);
178
+ }
179
+ .message-toast--success {
180
+ background-color: var(--sl-color-success-light-9);
181
+ border: 1px solid var(--sl-color-success-light-8);
182
+ color: var(--sl-color-success);
183
+ }
184
+ .message-toast--warning {
185
+ background-color: var(--sl-color-warning-light-9);
186
+ border: 1px solid var(--sl-color-warning-light-8);
187
+ color: var(--sl-color-warning);
188
+ }
189
+ .message-toast--error {
190
+ background-color: var(--sl-color-error-light-9);
191
+ border: 1px solid var(--sl-color-error-light-8);
192
+ color: var(--sl-color-error);
193
+ }
194
+
195
+ .message-toast.show {
196
+ transform: translateX(-50%) translateY(0);
197
+ opacity: 1;
198
+ }
199
+ `,document.head.appendChild(e)}resolveContainer(e){return e?typeof e=="string"?document.getElementById(e)||document.querySelector(e):e:null}open(){var e;this.dialog&&(this.dialog.style.display="block",(e=this.elements.findInput)==null||e.focus())}close(){this.dialog&&(this.dialog.style.display="none",this.resetState())}resetState(){this.state={findText:"",replaceText:"",matches:[],currentIndex:0},this.elements.findInput&&(this.elements.findInput.value=""),this.elements.replaceInput&&(this.elements.replaceInput.value=""),this.clearResults()}clearResults(){this.elements.resultInfo&&(this.elements.resultInfo.style.display="none")}performSearch(){var l,i,a,d,r;if(!this.state.findText)return this.showMessage("请输入查找内容","warning"),!1;if(!this.tableInstance)return this.showMessage("未连接表格实例","error"),!1;this.state.matches=[];const e=this.tableInstance.colCount||0,t=this.tableInstance.rowCount||0,n=this.tableInstance.columnHeaderLevelCount||1,o=((l=this.elements.selectedColumnsOnly)==null?void 0:l.checked)||!1;let s=[];if(o){const h=((a=(i=this.tableInstance).getSelectedCellInfos)==null?void 0:a.call(i))||[];if(h.length===0)return this.showMessage("请先选中要搜索的列","warning"),!1;const p=new Set;h.forEach(f=>{f.col!==void 0&&p.add(f.col)}),s=Array.from(p)}else s=Array.from({length:e},(h,p)=>p);for(let h=n;h<t;h++)for(const p of s){const f=this.tableInstance.getCellValue(p,h);f&&String(f).toLowerCase().includes(this.state.findText.toLowerCase())&&this.state.matches.push({row:h,col:p,value:String(f)})}return this.state.matches.length>0?(this.elements.totalMatches&&(this.elements.totalMatches.textContent=String(this.state.matches.length)),this.elements.resultInfo&&(this.elements.resultInfo.style.display="block"),this.state.currentIndex=0,this.highlightMatch(0),(r=(d=this.options).onSearch)==null||r.call(d,this.state.matches),!0):(this.showMessage("未找到匹配内容","warning"),this.clearResults(),!1)}highlightMatch(e){var n,o,s;if(this.state.matches.length===0)return;const t=this.state.matches[e];if((n=this.tableInstance)!=null&&n.selectCell&&this.tableInstance.selectCell(t.col,t.row),(o=this.tableInstance)!=null&&o.getVisibleCellRange&&((s=this.tableInstance)!=null&&s.scrollToCell)){const l=this.tableInstance.getVisibleCellRange();if(l){const{startRow:i,endRow:a,startCol:d,endCol:r}=l;t.row>=i&&t.row<=a&&t.col>=d&&t.col<=r||this.tableInstance.scrollToCell({col:t.col,row:t.row})}}}findNext(){this.state.matches.length===0&&!this.performSearch()||(this.state.currentIndex=(this.state.currentIndex+1)%this.state.matches.length,this.highlightMatch(this.state.currentIndex))}findPrevious(){this.state.matches.length===0&&!this.performSearch()||(this.state.currentIndex=this.state.currentIndex===0?this.state.matches.length-1:this.state.currentIndex-1,this.highlightMatch(this.state.currentIndex))}replaceOne(){var o,s,l,i;if(this.state.matches.length===0&&!this.performSearch())return;this.state.replaceText=((o=this.elements.replaceInput)==null?void 0:o.value)||"";const e=this.state.matches[this.state.currentIndex],n=e.value.replace(this.state.findText,this.state.replaceText);(s=this.tableInstance)!=null&&s.changeCellValue&&(this.tableInstance.changeCellValue(e.col,e.row,n),(i=(l=this.options).onReplace)==null||i.call(l,e,n)),this.showMessage(`已替换第 ${this.state.currentIndex+1} 个匹配项`,"success"),setTimeout(()=>{const a=this.state.currentIndex;this.performSearch(),this.state.matches.length>0&&(this.state.currentIndex=Math.min(a,this.state.matches.length-1),this.highlightMatch(this.state.currentIndex))},100)}replaceAll(){var t;if(this.state.matches.length===0&&!this.performSearch())return;this.state.replaceText=((t=this.elements.replaceInput)==null?void 0:t.value)||"";const e=this.state.matches.length;this.state.matches.forEach(n=>{var l,i,a;const s=n.value.replace(new RegExp(this.state.findText,"g"),this.state.replaceText);(l=this.tableInstance)!=null&&l.changeCellValue&&(this.tableInstance.changeCellValue(n.col,n.row,s),(a=(i=this.options).onReplace)==null||a.call(i,n,s))}),this.showMessage(`已替换全部 ${e} 个匹配项`,"success")}showMessage(e,t="info"){const n=document.createElement("div");n.className=`message-toast message-toast--${t}`;const o=document.createElement("span");o.textContent=e,n.appendChild(o);const s=document.createElement("span");s.className="message-close",s.innerHTML="&times;",s.style.cssText=`
200
+ margin-left: 12px;
201
+ cursor: pointer;
202
+ font-size: 22px;
203
+ font-weight: 300;
204
+ opacity: 0.8;
205
+ transition: opacity 0.2s;
206
+ `,s.onmouseenter=()=>s.style.opacity="1",s.onmouseleave=()=>s.style.opacity="0.8",n.appendChild(s),document.body.appendChild(n);let l;const i=()=>{clearTimeout(l),n.classList.remove("show"),setTimeout(()=>{n.parentNode&&document.body.removeChild(n)},300)};s.onclick=i,setTimeout(()=>n.classList.add("show"),10),l=setTimeout(i,3e3)}setTableInstance(e){this.tableInstance=e,this.state.matches=[],this.state.currentIndex=0,this.clearResults()}setSelectedColumnsOnly(e){this.elements.selectedColumnsOnly&&(this.elements.selectedColumnsOnly.checked=e)}getSelectedColumnsOnly(){var e;return((e=this.elements.selectedColumnsOnly)==null?void 0:e.checked)||!1}setFindText(e){this.state.findText=e,this.elements.findInput&&(this.elements.findInput.value=e)}setReplaceText(e){this.state.replaceText=e,this.elements.replaceInput&&(this.elements.replaceInput.value=e)}destroy(){this.dialog&&(this.dialog.remove(),this.dialog=null)}}const ee={toolbar:{title:"制表错误",unit:"条",total:"共 {total} 个错误项",hint:"请在错误项里查询对应的数据或在数据里进行搜索",buttons:{search:"查找/替换",freeze:{label:"冻结前",suffix:"列"},list:"仅显示错误列"}},dialog:{find:{label:"查找内容",placeholder:"请输入查找内容"},replace:{label:"替换为",placeholder:"请输入替换内容"},checkbox:{selectedOnly:"只替换选中列"},buttons:{close:"关闭",findPrev:"查找上一个",findNext:"查找下一个",replaceOne:"替换",replaceAll:"全部替换"},messages:{pleaseInputFind:"请输入查找内容",notConnected:"未连接表格实例",pleaseSelectColumns:"请先选中要搜索的列",noMatchFound:"未找到匹配内容",nothingToReplace:"没有可替换的内容",replacedOne:"已替换第 {index} 个匹配项",replacedAll:"已替换全部 {count} 个匹配项"},result:{found:"已找到 {count} 个结果"}},sheet:{defaultTitle:"Sheet1"}},te={toolbar:{title:"製表錯誤",unit:"筆",total:"共 {total} 個錯誤項",hint:"請在錯誤項裡查詢對應的資料或在資料裡進行搜尋",buttons:{search:"尋找/取代",freeze:{label:"凍結前",suffix:"欄"},list:"僅顯示錯誤欄"}},dialog:{find:{label:"尋找內容",placeholder:"請輸入尋找內容"},replace:{label:"取代為",placeholder:"請輸入取代內容"},checkbox:{selectedOnly:"只取代選中欄"},buttons:{close:"關閉",findPrev:"尋找上一個",findNext:"尋找下一個",replaceOne:"取代",replaceAll:"全部取代"},messages:{pleaseInputFind:"請輸入尋找內容",notConnected:"未連接表格實例",pleaseSelectColumns:"請先選中要搜尋的欄",noMatchFound:"未找到符合內容",nothingToReplace:"沒有可取代的內容",replacedOne:"已取代第 {index} 個符合項",replacedAll:"已取代全部 {count} 個符合項"},result:{found:"已找到 {count} 個結果"}},sheet:{defaultTitle:"Sheet1"}},ne={toolbar:{title:"Table Errors",unit:"items",total:"Total {total} errors",hint:"Please search for the corresponding data in the error items or in the data",buttons:{search:"Find/Replace",freeze:{label:"Freeze first",suffix:"columns"},list:"Show error columns only"}},dialog:{find:{label:"Find content",placeholder:"Please enter content to find"},replace:{label:"Replace with",placeholder:"Please enter replacement content"},checkbox:{selectedOnly:"Replace selected columns only"},buttons:{close:"Close",findPrev:"Find Previous",findNext:"Find Next",replaceOne:"Replace",replaceAll:"Replace All"},messages:{pleaseInputFind:"Please enter content to find",notConnected:"Table instance not connected",pleaseSelectColumns:"Please select columns to search first",noMatchFound:"No matching content found",nothingToReplace:"Nothing to replace",replacedOne:"Replaced match #{index}",replacedAll:"Replaced all {count} matches"},result:{found:"Found {count} result(s)"}},sheet:{defaultTitle:"Sheet1"}},oe={"zh-CN":ee,"en-US":ne,"zh-TW":te};let se="zh-CN";function le(){return oe[se]}function ie(c,e={}){return c.replace(/\{(\w+)\}/g,(t,n)=>e[n]!==void 0?String(e[n]):`{${n}}`)}function x(c,e){const t=le(),n=c.split(".");let o=t;for(const s of n)if(o&&typeof o=="object"&&s in o)o=o[s];else return console.warn(`I18n message not found: ${c}`),c;return typeof o=="string"?ie(o,e||{}):(console.warn(`I18n message is not a string: ${c}`),c)}class re{constructor(e){u(this,"container",null);u(this,"toolbarElement",null);u(this,"config");u(this,"elements",{});this.config={title:x("toolbar.title"),count:0,total:0,hint:x("toolbar.hint"),freezeCount:0,showErrorList:!1,buttons:{search:!0,freeze:!0,export:!0,refresh:!0,list:!0},...e},this.init()}init(){this.config.container&&(this.container=this.getContainer(this.config.container)),this.createToolbar(),this.injectStyles()}getContainer(e){return typeof e=="string"?document.getElementById(e)||document.querySelector(e):e}createToolbar(){this.toolbarElement=document.createElement("div"),this.toolbarElement.className="sl-toolbar";const e=this.createLeftSection(),t=this.createRightSection();this.toolbarElement.appendChild(e),this.toolbarElement.appendChild(t),this.container&&this.container.appendChild(this.toolbarElement)}createLeftSection(){const e=document.createElement("div");if(e.className="sl-toolbar-left",this.config.leftSlot){const t=typeof this.config.leftSlot=="function"?this.config.leftSlot():this.config.leftSlot;t&&e.appendChild(t)}return e}createRightSection(){const e=document.createElement("div");e.className="sl-toolbar-right";const{buttons:t}=this.config;if((t==null?void 0:t.search)!==!1){const n=this.createButton({text:x("toolbar.buttons.search"),onClick:()=>{var o,s;return(s=(o=this.config).onSearchClick)==null?void 0:s.call(o)}});e.appendChild(n)}if((t==null?void 0:t.freeze)!==!1){const n=this.createFreezeButton();e.appendChild(n)}return e}createButton(e){const t=document.createElement("button");return t.className=e.icon?"sl-toolbar-btn sl-toolbar-btn-icon":"sl-toolbar-btn",t.textContent=e.text,e.title&&(t.title=e.title),e.onClick&&(t.onclick=e.onClick),t}createFreezeButton(){const e=document.createElement("div");e.className="sl-freeze-selector";const t=document.createElement("span");t.className="sl-freeze-label",t.textContent=x("toolbar.buttons.freeze.label");const n=document.createElement("div");n.className="sl-freeze-input-wrapper";const o=document.createElement("input");o.type="number",o.className="sl-freeze-input",o.min="0",o.max="100",o.value=String(this.config.freezeCount||0),this.elements.freezeSelect=o;const s=document.createElement("div");s.className="sl-freeze-arrows";const l=document.createElement("button");l.className="sl-freeze-arrow sl-freeze-arrow-up",l.innerHTML="▲",l.type="button";const i=document.createElement("button");i.className="sl-freeze-arrow sl-freeze-arrow-down",i.innerHTML="▼",i.type="button",s.appendChild(l),s.appendChild(i);const a=document.createElement("span");a.className="sl-freeze-suffix",a.textContent=x("toolbar.buttons.freeze.suffix");const d=r=>{var h,p;r<0&&(r=0),r>100&&(r=100),o.value=String(r),this.config.freezeCount=r,(p=(h=this.config).onFreezeChange)==null||p.call(h,r)};return l.onclick=r=>{r.preventDefault();const h=parseInt(o.value,10)||0;d(h+1)},i.onclick=r=>{r.preventDefault();const h=parseInt(o.value,10)||0;d(h-1)},o.oninput=()=>{let r=parseInt(o.value,10);(isNaN(r)||r<0)&&(r=0,o.value="0"),r>100&&(r=100,o.value="100"),this.config.freezeCount=r},o.onblur=()=>{var h,p;const r=parseInt(o.value,10)||0;(p=(h=this.config).onFreezeChange)==null||p.call(h,r)},o.onkeydown=r=>{r.key==="Enter"&&o.blur()},n.appendChild(o),n.appendChild(s),e.appendChild(t),e.appendChild(n),e.appendChild(a),e}formatNumber(e){return e.toLocaleString()}injectStyles(){if(document.getElementById("sl-toolbar-styles"))return;const e=document.createElement("style");e.id="sl-toolbar-styles",e.textContent=`
207
+ .sl-toolbar {
208
+ display: flex;
209
+ justify-content: space-between;
210
+ align-items: center;
211
+ padding: 8px 16px;
212
+ background: var(--sl-vtable-card-bg-color);
213
+ font-size: 14px;
214
+ color: var(--sl-vtable-content-color);
215
+ flex-shrink: 0;
216
+ heihgt:60px;
217
+ border-radius: 4px;
218
+ }
219
+ .sl-toolbar-title {
220
+ display: flex;
221
+ align-items: baseline;
222
+ gap: 4px;
223
+ }
224
+
225
+ .sl-title-text {
226
+ font-size: 14px;
227
+ font-weight: 500;
228
+ color: var(--sl-vtable-content-color);
229
+ }
230
+
231
+ .sl-title-count {
232
+ font-size: 16px;
233
+ font-weight: 600;
234
+ color: #F53F3F;
235
+ }
236
+
237
+ .sl-title-unit {
238
+ font-size: 14px;
239
+ color: #1D2129;
240
+ }
241
+
242
+ .sl-title-total {
243
+ font-size: 12px;
244
+ color: #86909C;
245
+ margin-left: 4px;
246
+ }
247
+
248
+ .sl-toolbar-hint {
249
+ font-size: 12px;
250
+ color: #86909C;
251
+ }
252
+
253
+ .sl-toolbar-right {
254
+ display: flex;
255
+ align-items: center;
256
+ gap: 24px;
257
+ }
258
+
259
+ .sl-toolbar-btn {
260
+ padding: 6px 14px;
261
+ height: 32px;
262
+ background: var(--sl-vtable-bg-color1);
263
+ border: 1px solid var(--sl-vtable-bg-color1);
264
+ border-radius: 8px;
265
+ font-size: 14px;
266
+ color: var(--sl-vtable-content-color);
267
+ cursor: pointer;
268
+ transition: all 0.2s;
269
+ white-space: nowrap;
270
+ }
271
+
272
+ .sl-toolbar-btn:hover {
273
+ background: #E8E9EB;
274
+ }
275
+
276
+ .sl-toolbar-btn-icon {
277
+ padding: 6px 10px;
278
+ font-size: 16px;
279
+ min-width: 32px;
280
+ }
281
+
282
+ .sl-toolbar-btn-complex {
283
+ display: flex;
284
+ align-items: center;
285
+ gap: 4px;
286
+ }
287
+
288
+ .sl-btn-icon {
289
+ font-size: 14px;
290
+ }
291
+
292
+ .sl-btn-text {
293
+ font-size: 14px;
294
+ }
295
+
296
+ .sl-btn-count {
297
+ font-size: 14px;
298
+ font-weight: 600;
299
+ color: var(--sl-vtable-primary-color);
300
+ }
301
+
302
+ .sl-btn-suffix {
303
+ font-size: 14px;
304
+ }
305
+
306
+ .sl-freeze-selector {
307
+ display: flex;
308
+ align-items: center;
309
+ gap: 4px;
310
+ }
311
+
312
+ .sl-freeze-label {
313
+ font-size: 14px;
314
+ color: var(--sl-vtable-content-color);
315
+ white-space: nowrap;
316
+ }
317
+
318
+ .sl-freeze-input-wrapper {
319
+ position: relative;
320
+ display: inline-flex;
321
+ align-items: center;
322
+ background: var(--sl-vtable-bg-color1);
323
+ border: 1px solid var(--sl-vtable-bg-color1);
324
+ border-radius: 8px;
325
+ transition: all 0.2s;
326
+ height: 32px;
327
+ box-sizing: border-box;
328
+ }
329
+
330
+ .sl-freeze-input-wrapper:hover {
331
+ background: #E8E9EB;
332
+ border-color: var(--sl-vtable-primary-color);
333
+ }
334
+
335
+ .sl-freeze-input-wrapper:focus-within {
336
+ border-color: var(--sl-vtable-primary-color);
337
+ box-shadow: 0 0 0 2px rgba(40, 120, 255, 0.1);
338
+ }
339
+
340
+ .sl-freeze-input {
341
+ width: 30px;
342
+ height: 30px;
343
+ padding: 0px 2px;
344
+ border-radius: 8px 0px 0px 8px;
345
+ background: #fff;
346
+ border: none;
347
+ font-size: 14px;
348
+ color: var(--sl-vtable-content-color);
349
+ text-align: center;
350
+ outline: none;
351
+ -moz-appearance: textfield;
352
+ }
353
+
354
+ .sl-freeze-input::-webkit-outer-spin-button,
355
+ .sl-freeze-input::-webkit-inner-spin-button {
356
+ -webkit-appearance: none;
357
+ margin: 0;
358
+ }
359
+
360
+ .sl-freeze-arrows {
361
+ display: flex;
362
+ flex-direction: column;
363
+ border-left: 1px solid #E5E6EB;
364
+ }
365
+
366
+ .sl-freeze-arrow {
367
+ width: 20px;
368
+ height: 16px;
369
+ padding: 0;
370
+ background: transparent;
371
+ border: none;
372
+ font-size: 8px;
373
+ color: var(--sl-vtable-content-color);
374
+ cursor: pointer;
375
+ display: flex;
376
+ align-items: center;
377
+ justify-content: center;
378
+ transition: all 0.2s;
379
+ opacity: 0.6;
380
+ }
381
+
382
+ .sl-freeze-arrow:hover {
383
+ background: rgba(40, 120, 255, 0.1);
384
+ opacity: 1;
385
+ color: var(--sl-vtable-primary-color);
386
+ }
387
+
388
+ .sl-freeze-arrow:active {
389
+ background: rgba(40, 120, 255, 0.2);
390
+ }
391
+
392
+ .sl-freeze-arrow-up {
393
+ border-radius: 0 8px 0 0;
394
+ }
395
+
396
+ .sl-freeze-arrow-down {
397
+ border-radius: 0 0 8px 0;
398
+ border-top: 1px solid #E5E6EB;
399
+ }
400
+
401
+ .sl-freeze-suffix {
402
+ font-size: 14px;
403
+ color: var(--sl-vtable-content-color);
404
+ }
405
+
406
+ .sl-error-list-checkbox {
407
+ display: inline-flex;
408
+ align-items: center;
409
+ gap: 8px;
410
+ cursor: pointer;
411
+ user-select: none;
412
+ }
413
+
414
+ .sl-checkbox-input {
415
+ position: absolute;
416
+ opacity: 0;
417
+ width: 0;
418
+ height: 0;
419
+ }
420
+
421
+ .sl-checkbox-custom {
422
+ position: relative;
423
+ width: 16px;
424
+ height: 16px;
425
+ border: 2px solid #C9CDD4;
426
+ border-radius: 4px;
427
+ background: #fff;
428
+ transition: all 0.2s;
429
+ flex-shrink: 0;
430
+ }
431
+
432
+ .sl-checkbox-input:checked + .sl-checkbox-custom {
433
+ background: var(--sl-vtable-primary-color);
434
+ border-color: var(--sl-vtable-primary-color);
435
+ }
436
+
437
+ .sl-checkbox-input:checked + .sl-checkbox-custom::after {
438
+ content: "";
439
+ position: absolute;
440
+ left: 4px;
441
+ top: 1px;
442
+ width: 4px;
443
+ height: 8px;
444
+ border: solid white;
445
+ border-width: 0 2px 2px 0;
446
+ transform: rotate(45deg);
447
+ }
448
+
449
+ .sl-error-list-checkbox:hover .sl-checkbox-custom {
450
+ border-color: var(--sl-vtable-primary-color);
451
+ }
452
+
453
+ .sl-checkbox-label {
454
+ font-size: 14px;
455
+ color: var(--sl-vtable-content-color);
456
+ }
457
+
458
+ /* 响应式设计 */
459
+ @media (max-width: 768px) {
460
+ .sl-toolbar {
461
+ flex-direction: column;
462
+ align-items: flex-start;
463
+ gap: 12px;
464
+ }
465
+
466
+ .sl-toolbar-left {
467
+ flex-direction: column;
468
+ align-items: flex-start;
469
+ gap: 8px;
470
+ }
471
+
472
+ .sl-toolbar-right {
473
+ width: 100%;
474
+ justify-content: flex-start;
475
+ flex-wrap: wrap;
476
+ }
477
+ }
478
+ `,document.head.appendChild(e)}updateTitle(e){this.elements.titleText&&(this.elements.titleText.textContent=e)}updateStats(e,t){this.elements.titleCount&&(this.elements.titleCount.textContent=this.formatNumber(e)),this.elements.titleTotal&&(this.elements.titleTotal.textContent=`(共 ${this.formatNumber(t)} 个错误项)`)}updateHint(e){this.elements.hint&&(this.elements.hint.textContent=e)}updateFreezeCount(e){this.config.freezeCount=e,this.elements.freezeSelect&&(this.elements.freezeSelect.value=String(e))}updateShowErrorList(e){this.config.showErrorList=e,this.elements.errorListCheckbox&&(this.elements.errorListCheckbox.checked=e)}show(){this.toolbarElement&&(this.toolbarElement.style.display="flex")}hide(){this.toolbarElement&&(this.toolbarElement.style.display="none")}getElement(){return this.toolbarElement}setLeftSlot(e){var n;const t=(n=this.toolbarElement)==null?void 0:n.querySelector(".sl-toolbar-left");if(t&&(t.innerHTML="",e)){const o=typeof e=="function"?e():e;o&&t.appendChild(o)}}getLeftSection(){var e;return((e=this.toolbarElement)==null?void 0:e.querySelector(".sl-toolbar-left"))||null}destroy(){this.toolbarElement&&(this.toolbarElement.remove(),this.toolbarElement=null),this.elements={}}}class z{static processRecords(e,t){const n=new Map;return{displayRecords:e.map((s,l)=>Array.isArray(s)?this.processArrayRow(s,l,n):this.processObjectRow(s,l,t,n)),markedMap:n}}static processArrayRow(e,t,n){return e.map((o,s)=>o&&typeof o=="object"&&"value"in o?(o.isMarked&&n.set(`${t}-${s}`,{isMarked:!0,comment:o.comment||""}),o.value):o)}static processObjectRow(e,t,n,o){return n.map((s,l)=>{const i=s.field||s.key,a=e[i];return a&&typeof a=="object"&&"value"in a?(a.isMarked&&o.set(`${t}-${l}`,{isMarked:!0,comment:a.comment||""}),a.value):a})}}const ae=(c,e)=>({bgColor:"#FFEBEB",color:"#FF4D50",marked:{shape:"triangle",bgColor:"#FF4D50",size:8}});class D{static initColumns(e,t,n){return e.map((o,s)=>{const l=o.style,i={...o};return i.style=a=>{const d=a.row;let r=l?l(a):void 0;if(r=this.applyExcelStyle(r,d,s,n),t.has(`${d}-${s}`)){const h=ae();return{...r,...h,bgColor:h.bgColor,color:h.color}}return r},i})}static applyExcelStyle(e,t,n,o){if(!o)return e;const s=o.get(`${t}-${n}`);if(!s)return e;const l=e||{};return s.fontColor&&(l.color=s.fontColor),s.bgColor&&(l.bgColor=s.bgColor),s.bold&&(l.fontWeight="bold"),s.italic&&(l.fontStyle="italic"),l}}class ce{constructor(e){u(this,"tableSheet",null);u(this,"findReplaceDialog",null);u(this,"toolbar",null);u(this,"container",null);u(this,"tableContainer",null);u(this,"toolbarContainer",null);u(this,"config");u(this,"excelCellStyles",null);this.config={showToolbar:!0,...e},this.init()}init(){if(this.container=this.getContainer(this.config.container),!this.container)throw new Error("Container not found");this.createLayout(),this.config.showToolbar&&this.createToolbar(),this.createTable(),this.createFindReplaceDialog(),this.injectStyles()}getContainer(e){return typeof e=="string"?document.getElementById(e)||document.querySelector(e):e}createLayout(){this.container&&(this.container.innerHTML="",this.container.className="sl-table-sheet-wrapper",this.config.showToolbar&&(this.toolbarContainer=document.createElement("div"),this.container.appendChild(this.toolbarContainer)),this.tableContainer=document.createElement("div"),this.tableContainer.className="sl-table-container",this.container.appendChild(this.tableContainer))}createToolbar(){this.toolbarContainer&&(this.toolbar=new re({container:this.toolbarContainer,title:"制表错误7",count:2993,total:12393,hint:"请在错误项里查询对应的数据或在数据里进行搜索",buttons:{search:!0,freeze:!0,export:!0,refresh:!0,list:!0},onSearchClick:()=>this.openFindReplace(),onFreezeChange:e=>this.freezeColumns(e),onListChange:()=>console.log("列表"),...this.config.toolbar}))}createTable(){if(!this.tableContainer)return;const e=this.config.columns||[],{displayRecords:t,markedMap:n}=z.processRecords(this.config.records||[],e),o=D.initColumns(e,n);this.tableSheet=new F({container:this.tableContainer,columns:o,records:t,showFormulaBar:this.config.showFormulaBar,showSheetTab:this.config.showSheetTab,sheets:this.config.sheets,editors:this.config.editors,customComponents:this.config.customComponents,options:this.config.options,onCellChange:this.config.onCellChange},n)}createFindReplaceDialog(){var t;const e=(t=this.tableSheet)==null?void 0:t.getTableInstance();e&&(this.findReplaceDialog=new Z({tableInstance:e,selectedColumnsOnly:!1,onSearch:n=>{console.log(`找到 ${n.length} 个匹配项`)},onReplace:(n,o)=>{console.log("替换成功:",n,"->",o)}}))}openFindReplace(){var e;(e=this.findReplaceDialog)==null||e.open()}freezeColumns(e){console.log("冻结前列",e)}injectStyles(){if(document.getElementById("sl-table-sheet-styles"))return;const e=document.createElement("style");e.id="sl-table-sheet-styles",e.textContent=`
479
+ .sl-table-sheet-wrapper {
480
+ display: flex;
481
+ flex-direction: column;
482
+ height: 100%;
483
+ background: #fff;
484
+ }
485
+ .sl-table-container {
486
+ flex: 1;
487
+ overflow: hidden;
488
+ position: relative;
489
+ margin-top:12px;
490
+ }
491
+ `,document.head.appendChild(e)}updateTitleStats(e,t){var n;(n=this.toolbar)==null||n.updateStats(e,t)}getTableSheet(){return this.tableSheet}getTableInstance(){var e;return(e=this.tableSheet)==null?void 0:e.getTableInstance()}getFindReplaceDialog(){return this.findReplaceDialog}setFindReplaceSelectedColumnsOnly(e){this.findReplaceDialog&&this.findReplaceDialog.setSelectedColumnsOnly(e)}updateData(e){var t;(t=this.tableSheet)==null||t.updateData(e)}updateColumns(e){var t;(t=this.tableSheet)==null||t.updateColumns(e)}exportData(e="csv"){var t;return(t=this.tableSheet)==null?void 0:t.exportData(e)}exportToExcelStream(e){const t=this.config.columns||[],n=this.config.records||[];return X(t,n,e)}downloadExcel(e="export"){const t=this.exportToExcelStream();W(t,e)}async loadExcelFromUrl(e,t={}){const{autoDisplay:n=!0,...o}=t,s=await L(e,o);return this.handleExcelImportResult(s,n),s}parseExcelBuffer(e,t={}){const{autoDisplay:n=!0,...o}=t,s=v(e,o);return this.handleExcelImportResult(s,n),s}async parseExcelFile(e,t={}){const{autoDisplay:n=!0,...o}=t,s=await $(e,o);return this.handleExcelImportResult(s,n),s}handleExcelImportResult(e,t){var s;console.log("handleExcelImportResult 调用:",{columns:e.columns.length,records:e.records.length,autoDisplay:t,hasTableSheet:!!this.tableSheet}),this.excelCellStyles=e.cellStyles||null;const n=D.initColumns(e.columns,new Map,this.excelCellStyles);this.config.columns=n;let o=e.records;if(e.cellComments&&e.cellComments.size>0?(console.log("处理 Excel 标注数据:",e.cellComments.size,"个标注"),console.log("所有标注数据:"),e.cellComments.forEach((l,i)=>{console.log(` ${i}:`,l)}),o=e.records.map((l,i)=>l.map((a,d)=>{const r=`${i}-${d}`,h=e.cellComments.get(r);return h?(console.log(`单元格 [${i},${d}] 有标注:`,h),{value:a,isMarked:!0,comment:h.text||""}):a})),console.log("标注处理完成,第一条记录:",o[0])):console.log("没有找到标注数据"),this.config.records=o,t&&this.tableSheet)try{console.log("尝试更新现有表格..."),console.log("更新前表格状态:",{hasTableInstance:!!this.tableSheet,container:this.tableContainer,containerVisible:((s=this.tableContainer)==null?void 0:s.offsetParent)!==null}),this.tableSheet.updateColumns(n),this.tableSheet.updateData(this.config.records),console.log("表格更新成功,更新后状态:",{recordsCount:this.config.records.length,columnsCount:n.length,firstRecord:this.config.records[0]}),console.log("强制重新创建表格以确保数据正确显示"),setTimeout(()=>{this.recreateTable(n,this.config.records||[])},100)}catch(l){console.warn("动态更新失败,尝试重新创建表格:",l),this.recreateTable(n,this.config.records||[])}else console.log("跳过自动显示:",{autoDisplay:t,hasTableSheet:!!this.tableSheet});this.config.onExcelImport&&this.config.onExcelImport(e)}recreateTable(e,t){console.log("重新创建表格:",{columnCount:e.length,recordCount:t.length}),this.tableSheet&&(this.tableSheet.destroy(),this.tableSheet=null);const{displayRecords:n,markedMap:o}=z.processRecords(t,e);this.tableSheet=new F({container:this.tableContainer,columns:e,records:n,showFormulaBar:this.config.showFormulaBar,showSheetTab:this.config.showSheetTab,sheets:this.config.sheets,editors:this.config.editors,customComponents:this.config.customComponents,options:this.config.options,onCellChange:this.config.onCellChange},o),this.updateFindReplaceTableInstance(),console.log("表格重新创建完成,标记单元格数:",o.size)}updateFindReplaceTableInstance(){var t;const e=(t=this.tableSheet)==null?void 0:t.getTableInstance();e&&this.findReplaceDialog&&this.findReplaceDialog.setTableInstance(e)}refresh(){var e;(e=this.tableSheet)==null||e.refresh()}on(e,t){var n;(n=this.tableSheet)==null||n.on(e,t)}off(e,t){var n;(n=this.tableSheet)==null||n.off(e,t)}getToolbar(){return this.toolbar}destroy(){var e,t,n;(e=this.toolbar)==null||e.destroy(),(t=this.findReplaceDialog)==null||t.destroy(),(n=this.tableSheet)==null||n.destroy(),this.container&&(this.container.innerHTML=""),this.toolbar=null,this.tableSheet=null,this.findReplaceDialog=null,this.container=null,this.tableContainer=null,this.toolbarContainer=null}}exports.default=ce;exports.fetchExcelFromUrl=N;exports.loadExcelFromUrl=L;exports.parseExcelBuffer=v;exports.parseExcelFile=$;