@8sheets/data-grid 1.1.0 → 1.1.2
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.
- package/README.md +1 -1
- package/api/serialize.js +1 -1
- package/calc/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/database.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/info.js +1 -1
- package/calc/functions/logical.js +1 -1
- package/calc/functions/lookup.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/functions/stat.js +1 -1
- package/calc/functions/text.js +1 -1
- package/calc/parser.js +3 -3
- package/calc/values.js +1 -1
- package/calcx/async.js +1 -1
- package/calcx/functions/dynamic.js +1 -1
- package/calcx/functions/ets.js +1 -1
- package/calcx/functions/misc.js +1 -1
- package/calcx/lang/convert.js +1 -1
- package/cells/axis-ops.js +1 -1
- package/cells/book-css.js +7 -2
- package/cells/cf-engine.js +1 -1
- package/cells/find-engine.js +2 -2
- package/cells/find.js +1 -1
- package/cells/goto.js +1 -1
- package/cells/link-model.js +1 -0
- package/cells/outline-column.js +1 -1
- package/cells/panes.js +1 -1
- package/cells/rich-runs.js +2 -2
- package/cells/rich-values.js +1 -1
- package/cells/selection-modes.js +1 -1
- package/celltypes/cell-types.js +2 -2
- package/celltypes/dropdowns.js +3 -2
- package/celltypes/file-cell.js +2 -2
- package/celltypes/range-template.js +2 -2
- package/core/cell-type-rules.js +1 -0
- package/core/changes.js +1 -1
- package/core/cond-format.js +1 -1
- package/core/culture.js +1 -1
- package/core/edit-ranges.js +1 -0
- package/core/host-rules.js +1 -0
- package/core/input.js +1 -1
- package/core/numfmt.js +1 -1
- package/core/protection.js +1 -1
- package/core/region-input.js +1 -1
- package/core/sheet.js +1 -1
- package/core/sparse.js +1 -1
- package/core/structure.js +1 -1
- package/core/validation-ranges.js +1 -0
- package/core/workbook.js +1 -1
- package/datasheets/manager.js +1 -1
- package/datasheets/persist.js +1 -1
- package/extras/getdata/persist.js +2 -2
- package/i18n/en/cells.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/ribbon.js +1 -1
- package/i18n/pl/cells.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/ribbon.js +1 -1
- package/io/client.js +1 -1
- package/io/csv.js +7 -7
- package/io/encoding.js +1 -0
- package/io/foreign-sheets.js +2 -2
- package/io/plan.js +1 -1
- package/io/xlsx-read.js +1 -1
- package/io/xlsx-tail.js +1 -1
- package/io/xlsx-write.js +2 -2
- package/io/xml-scan.js +2 -1
- package/io/zip-reader.js +1 -1
- package/package.json +1 -1
- package/pivot/engine.js +1 -1
- package/pivot/xml.js +2 -2
- package/print/note-pages.js +2 -0
- package/print/paginate.js +1 -1
- package/print/pdf-links.js +1 -0
- package/print/pdf.js +11 -11
- package/print/render-page.js +3 -3
- package/slicers/format.js +2 -2
- package/slicers/structured.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/labels-de.js +1 -1
- package/table-view/labels-es.js +1 -1
- package/table-view/labels-fr.js +1 -1
- package/table-view/labels-ja.js +1 -1
- package/table-view/labels.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/version.js +1 -1
- package/ui/dialogs.js +3 -3
- package/ui/icons.js +1 -1
- package/ui/protection-ui.js +1 -1
package/cells/find-engine.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{formulaEntryLimit as
|
|
2
|
-
`);return{...t,text:s}}function z(e,t,n){if(!e.comments)return[];const s=[];for(const[o
|
|
1
|
+
import{cellEditable as J}from"../core/protection.js";import{formulaEntryLimit as W}from"../calc/parser.js";import{CHUNK_BITS as M,CHUNK_MASK as I,EMPTY as D,FORMULA as T,KIND_MASK as G,SPILL as X,STR as Y}from"../core/sheet.js";const H=/[.+^${}()|[\]\\]/g;function P(e){if(!/[*?~]/.test(e))return null;let t="";for(let n=0;n<e.length;n++){const s=e[n];s==="~"&&n+1<e.length&&"*?~".includes(e[n+1])?t+=e[++n].replace(/[*?]/,"\\$&"):s==="*"?t+="[\\s\\S]*":s==="?"?t+="[\\s\\S]":t+=s.replace(H,"\\$&")}return t}const U=(e,t,n,s)=>new RegExp(n?`^(?:${e})$`:e,`${s}${n?"":"m"}u${t?"":"i"}`);function ft(e){try{return U(e,!0,!1,""),null}catch(t){return t.message}}function v(e,{matchCase:t=!1,whole:n=!1,regex:s=!1}={}){if(s){const r=U(e,t,n,"");return c=>r.test(c)}const i=P(e);if(i===null&&!n){if(t)return c=>c.includes(e);const r=e.toLowerCase();return c=>c.toLowerCase().includes(r)}if(i===null){if(t)return c=>c===e;const r=e.toLowerCase();return c=>c.toLowerCase()===r}const o=new RegExp(n?`^(?:${i})$`:i,t?"":"i");return r=>o.test(r)}function q(e,t,{matchCase:n=!1,whole:s=!1,regex:i=!1}={}){if(i){const c=U(e,n,s,"g");return f=>f.replace(c,t)}const o=P(e)??e.replace(H,"\\$&").replace(/[*?]/g,"\\$&"),r=new RegExp(s?`^(?:${o})$`:o,n?"g":"gi");return c=>c.replace(r,()=>t)}const Q=(e,t)=>e===t||e&&t&&typeof e=="object"&&JSON.stringify(e)===JSON.stringify(t);function V(e,t,n){const{styles:s,strings:i}=e,{what:o,look:r,format:c}=t,f=o===""?null:v(o,t),d=new Uint8Array(i.size+1),l=new Map,m=u=>{let h=l.get(u);if(h===void 0){const g=s.get(u);h=Object.keys(c).every(x=>Q(g[x]??null,c[x]??null)),l.set(u,h)}return h};return(u,h,g,x,a)=>{if(r==="values"&&(u.rows.isHidden(h)||u.cols.isHidden(g)||u.filteredRows?.has(h))||c!==null&&!m(u.style(h,g)))return!1;if(f===null)return!0;const y=x&G,S=u.protection&&x&T&&s.get(u.style(h,g)).hiddenFormula;if(r==="formulas"&&x&T&&!S)return f(e.editText(u,h,g));if(y===D)return!1;if(y===Y){if(a>=d.length)return f(i.get(a));let w=d[a];return w===0&&(w=f(i.get(a))?1:2,d[a]=w),w===1}const p=r==="formulas"&&!S?e.editText(u,h,g):n(y,a,s.get(u.style(h,g)));return f(p)}}const F=12,K=()=>new Promise(e=>setTimeout(e,0));class _{constructor(t){this.ctrl=t,this.start=performance.now()}async pause(){return performance.now()-this.start<F?!this.ctrl.cancelled:(this.ctrl.onProgress?.(),await K(),this.start=performance.now(),!this.ctrl.cancelled)}}const A=(e,t,n)=>e?n*1048576+t:t*16384+n;function Z(e){const t=[];for(let n=0;n<=e.maxCol;n++)e.columns[n]!==void 0&&t.push(n);return t}async function j(e,{byCols:t,dir:n,from:s,to:i,withEmpty:o},r,c){const f=Z(e);n<0&&f.reverse();const d=s===null?-n*(1/0):s,l=i===null?n*(1/0):i,m=n>0?a=>a>=d&&a<=l:a=>a<=d&&a>=l,u=o===!0;if(t){for(const a of f){const y=e.columns[a],S=n>0?0:y.length-1,p=n>0?y.length:-1;for(let w=S;w!==p;w+=n){const L=y[w];if(L===void 0)continue;const $=w<<M,{kinds:R,values:E,styles:O}=L;for(let k=n>0?0:I;k>=0&&k<=I;k+=n){const C=R[k];if(C===0&&!(u&&O!==null&&O[k]!==0))continue;const N=$+k;if(m(A(!0,N,a))&&r(N,a,C,E[k]))return!0}if(!await c.pause())return!1}}return!1}const h=e.maxRow>>>M,g=n>0?0:h,x=n>0?h+1:-1;for(let a=g;a!==x;a+=n){const y=[];for(const p of f){const w=e.columns[p][a];w!==void 0&&y.push(p,w)}if(y.length===0)continue;const S=a<<M;for(let p=n>0?0:I;p>=0&&p<=I;p+=n){const w=S+p;for(let L=0;L<y.length;L+=2){const $=y[L+1],R=$.kinds[p];if(R===0&&!(u&&$.styles!==null&&$.styles[p]!==0))continue;const E=y[L];if(m(A(!1,w,E))&&r(w,E,R,$.values[p]))return!0}}if(!await c.pause())return!1}return!1}function b(e,t){if(!t.author?.startsWith("tc="))return t;const n=t.author.slice(3),s=(e.threads??[]).filter(i=>i.id===n||i.parentId===n).map(i=>i.text).join(`
|
|
2
|
+
`);return{...t,text:s}}function z(e,t,n){if(!e.comments)return[];const s=[];for(const[i,o]of e.comments){const r=Math.floor(i/16384);s.push({row:r,col:i-r*16384,note:b(e,o)})}return s.sort((i,o)=>n*(A(t,i.row,i.col)-A(t,o.row,o.col))),s}function tt(e,t,n){const s=e.sheets.filter(r=>!r.hidden);if(t.within!=="workbook")return[e.sheet];const i=s.indexOf(e.sheet),o=[];for(let r=0;r<s.length;r++)o.push(s[(i+n*r+s.length*2)%s.length]);return o}const et=(e,t,n)=>e.some(s=>t>=s.r0&&t<=s.r1&&n>=s.c0&&n<=s.c1);function B(e,t,n){const s=V(e,t,n);if(!t.ranges)return s;const i=t.sheet??e.sheet;return(o,r,c,f,d)=>(o!==i||et(t.ranges,r,c))&&s(o,r,c,f,d)}async function at(e,t,n,s,i,o={}){const r=t.byColumns===!0,c=new _(o),f=tt(e,t,s),d=A(r,n.row,n.col);if(t.look==="notes")return nt(e,t,f,d,r,s);const l=B(e,t,i),m=t.what===""&&t.format!==null;let u=null;const h=async(g,x,a,y)=>(await j(g,{byCols:r,dir:s,from:x,to:a,withEmpty:m},(S,p,w,L)=>y&&A(r,S,p)===d||!l(g,S,p,w,L)?!1:(u={sheet:g,row:S,col:p},!0),c),u!==null||o.cancelled===!0);if(await h(f[0],d,null,!0))return u;for(let g=1;g<f.length;g++)if(await h(f[g],null,null,!1))return u;return await h(f[0],null,d,!1),u}function nt(e,t,n,s,i,o){const r=v(t.what,t),c=l=>r(l.note.text??""),f=z(n[0],i,o),d=o>0?l=>l>s:l=>l<s;for(const l of f)if(d(A(i,l.row,l.col))&&c(l))return{sheet:n[0],row:l.row,col:l.col};for(let l=1;l<n.length;l++)for(const m of z(n[l],i,o))if(c(m))return{sheet:n[l],row:m.row,col:m.col};for(const l of f)if(!d(A(i,l.row,l.col))&&c(l))return{sheet:n[0],row:l.row,col:l.col};return null}class st{constructor(t){this.cap=t,this.count=0,this.overflow=!1,this.size=Math.min(t,1024),this.rows=new Uint32Array(this.size),this.cols=new Uint16Array(this.size),this.sheets=new Uint16Array(this.size),this.sheetList=[]}push(t,n,s){if(this.count===this.cap)return this.overflow=!0,!1;if(this.count===this.size){this.size=Math.min(this.cap,this.size*2);const r=(c,f)=>{const d=new c(this.size);return d.set(f),d};this.rows=r(Uint32Array,this.rows),this.cols=r(Uint16Array,this.cols),this.sheets=r(Uint16Array,this.sheets)}let i=this.sheetList.indexOf(t);i<0&&(i=this.sheetList.length,this.sheetList.push(t));const o=this.count++;return this.rows[o]=n,this.cols[o]=s,this.sheets[o]=i,!0}}async function rt(e,t,n,s={},i=1e5){const o=new st(i),r=t.byColumns===!0,c=new _(s),f=t.sheet?[t.sheet]:t.within==="workbook"?e.sheets.filter(m=>!m.hidden):[e.sheet];if(t.look==="notes"){const m=v(t.what,t);for(const u of f)for(const h of z(u,r,1))m(h.note.text??"")&&o.push(u,h.row,h.col);return o}const d=B(e,t,n),l=t.what===""&&t.format!==null;for(const m of f)if(await j(m,{byCols:r,dir:1,from:null,to:null,withEmpty:l},(h,g,x,a)=>d(m,h,g,x,a)?!o.push(m,h,g):!1,c)||s.cancelled)break;return o}function it(e,t,n,s,i,o,r=null){const{sheet:c}=t;let f=!1;if(i!==null){const d=c.formula(n,s);if(d&&d.t==="array")return!1;const l=c.kind(n,s);if(l&X&&!(l&T))return!1;const m=e.editText(c,n,s),u=i(m);if(u!==m&&u.startsWith("=")&&u.length>1&&!ot(e,u.slice(1)))return r!==null&&r.invalid++,!1;u!==m&&(e.setInput(t,n,s,u),f=!0)}return o&&(f||t.saveCell(n,s),c.setStyle(n,s,e.styles.derive(c.style(n,s),o)),f=!0),f}async function ht(e,t,n,s,i,o={}){const r=await rt(e,{...t,look:"formulas"},i,o,4294967295);if(o.cancelled)return{count:0,sheets:0,cancelled:!0};const c=t.what===""?null:q(t.what,n??"",t);let f=0,d=0;const l={locked:0,invalid:0},m=[];for(let u=0;u<r.sheetList.length;u++){const h=r.sheetList[u],g=[];let x=0,a=0;for(;a<r.count;){const y=performance.now(),S=e.runSlice(h,"replace",p=>{for(let w=0;a<r.count&&!(w%1024===1023&&performance.now()-y>F);a++,w++){if(r.sheets[a]!==u)continue;const L=r.rows[a],$=r.cols[a];if(h.protection&&!J(e,h,L,$)){l.locked++;continue}it(e,p,L,$,c,s,l)&&x++}});if(S!==null&&g.push(S),o.onProgress?.(),a<r.count&&await K(),o.cancelled)return e.rollbackSlices([...m,...g]),{count:0,sheets:0,cancelled:!0}}m.push(...g),x>0&&(f+=x,d++)}return e.pushFolded(m,"replace",e.sheet),{count:f,sheets:d,...l}}function ot(e,t){if(!e.engine)return!W(t);try{return e.engine.validate(t),!0}catch{return!1}}export{st as FoundList,rt as findAll,at as findNext,v as makeMatcher,q as makeReplacer,V as makeTest,ft as regexProblem,ht as replaceAll,it as replaceInCell};
|
package/cells/find.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{overlayRoot as S}from"../api/overlay.js";import{el as l,openFormatCells as T}from"../ui/dialogs.js";import{cellRef as _,MAX_COLS as L,MAX_ROWS as B}from"../core/address.js";import{KIND_MASK as E}from"../core/sheet.js";import{formatCount as g}from"../core/numfmt.js";import{findAll as $,findNext as b,makeReplacer as W,makeTest as O,replaceAll as N,replaceInCell as H}from"./find-engine.js";import{ensureBookCss as D}from"./book-css.js";import{svgNode as P}from"./format-tabs.js";import{t as a,tc as F}from"../i18n/index.js";const m=20,j=["fontName","fontSize","bold","italic","underline","strike","color","fill","pattern","borders","numFmt","hAlign","vAlign","wrap","indent","rotation","shrink","unlocked","hiddenFormula"];let p=null,v=null;const w=[];function R(c){const t=l("span",{class:"bk-fmt-chip",textContent:c?a("Preview*"):a("No Format Set")});return y(t,c),t}function y(c,t){c.textContent=t?a("Preview*"):a("No Format Set"),c.style.background=t?.fill??"",c.style.color=t?.color??"",c.style.fontWeight=t?.bold?"700":"",c.style.fontStyle=t?.italic?"italic":"",c.style.textDecoration=t?.underline?"underline":""}function I(c){const t={};for(const e of j)c[e]!==void 0&&c[e]!==null&&c[e]!==!1&&c[e]!==0&&c[e]!=="General"&&(t[e]=c[e]);return t}class V{constructor(t){this.app=t,this.findFormat=null,this.replaceFormat=null,this.ctrl=null,this.results=null,this.order=null,this.activeRow=-1,this.sort={key:null,dir:1},this._build()}_build(){D();const t=(i,d)=>{const u=l("select",{class:"dlg-input","aria-label":a(i)});for(const[f,k]of d)u.append(l("option",{value:k,textContent:a(f)}));return u},e=(i,d,u=!1)=>l("button",{class:`dlg-btn${u?" primary":""}`,type:"button",textContent:a(i),on:{click:d}}),s=l("button",{type:"button",class:"bk-find-history",title:a("Recent searches"),"aria-label":a("Recent searches"),on:{click:i=>this.app.ribbon.openMenu(i.currentTarget,{items:w.length?w.map(d=>[d,()=>{this.what.value=d,this.what.focus()},{raw:!0}]):[["No recent searches",()=>{}]]})}},P('<svg width="9" height="6" viewBox="0 0 9 6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1 1l3.5 3.5L8 1"/></svg>'));this.what=l("input",{class:"dlg-input","aria-label":a("Find what"),spellcheck:!1}),this.repl=l("input",{class:"dlg-input","aria-label":a("Replace with"),spellcheck:!1}),this.within=t("Within",[["Sheet","sheet"],["Workbook","workbook"]]),this.searchBy=t("Search",[["By Rows","rows"],["By Columns","cols"]]),this.look=t("Look in",[["Formulas","formulas"],["Values","values"],["Notes","notes"]]),this.matchCase=l("input",{type:"checkbox","aria-label":a("Match case")}),this.whole=l("input",{type:"checkbox","aria-label":a("Match entire cell contents")}),this.status=l("div",{class:"dlg-status",role:"status"}),this.progress=l("div",{class:"bk-progress",hidden:!0},l("div")),this.findChip=R(null),this.replaceChip=R(null);const o=i=>e("Format…",d=>this._formatMenu(i,d.currentTarget)),r=(...i)=>l("span",{class:"dlg-row bk-find-fmt",hidden:!0},...i);this.fmtFind=r(this.findChip,o("find")),this.fmtReplace=r(this.replaceChip,o("replace")),this.replaceRow=[l("span",{textContent:a("Replace with:")}),l("div",{class:"dlg-row"},this.repl,this.fmtReplace)],this.modeFind=l("button",{type:"button",role:"tab",class:"dlg-tab",textContent:a("Find"),on:{click:()=>this.setMode(!1)}}),this.modeReplace=l("button",{type:"button",role:"tab",class:"dlg-tab",textContent:a("Replace"),on:{click:()=>this.setMode(!0)}}),this.opts=l("div",{class:"bk-find-opts",hidden:!0},l("span",{textContent:a("Within:")}),this.within,l("label",{class:"dlg-row dlg-check"},this.matchCase,` ${a("Match case")}`),l("span",{textContent:a("Search:")}),this.searchBy,l("label",{class:"dlg-row dlg-check"},this.whole,` ${a("Match entire cell contents")}`),l("span",{textContent:a("Look in:")}),this.look,l("span")),this.btnReplaceAll=e("Replace All",()=>this.doReplaceAll()),this.btnReplace=e("Replace",()=>this.doReplace()),this.resultsHost=l("div",{class:"bk-results",hidden:!0});const n=l("h2",{class:"bk-panel-title",textContent:a("Find & Replace")});this.node=l("div",{class:"bk-panel xl-dlg",role:"dialog","aria-label":a("Find & Replace")},n,l("div",{class:"xl-tabbed"},l("div",{class:"dlg-tabs",role:"tablist"},this.modeFind,this.modeReplace),l("div",{class:"xl-box bk-find-box"},l("div",{class:"bk-find-grid"},l("span",{textContent:a("Find what:")}),l("div",{class:"dlg-row"},l("span",{class:"bk-find-field"},this.what,s),this.fmtFind),...this.replaceRow),this.opts,this.progress,this.resultsHost,l("div",{class:"bk-find-low"},this.status,e("Options",()=>this.toggleOptions())))),l("div",{class:"bk-find-foot"},this.btnReplaceAll,this.btnReplace,e("Find All",()=>this.doFindAll()),e(F("find","Previous"),()=>this.doFind(-1)),e(F("find","Next"),()=>this.doFind(1),!0),e("Close",()=>this.close()))),this.node.addEventListener("keydown",i=>{i.stopPropagation(),i.key==="Escape"?(i.preventDefault(),this.ctrl?this.cancel():this.close()):i.key==="Enter"&&i.target.tagName!=="BUTTON"&&(i.preventDefault(),this.doFind(i.shiftKey?-1:1))}),n.addEventListener("pointerdown",i=>{i.preventDefault(),n.setPointerCapture(i.pointerId);const d=this.node.getBoundingClientRect(),u=i.clientX-d.left,f=i.clientY-d.top,k=x=>{this.node.style.left=`${Math.max(0,Math.min(window.innerWidth-80,x.clientX-u))}px`,this.node.style.top=`${Math.max(0,Math.min(window.innerHeight-40,x.clientY-f))}px`},C=()=>{n.removeEventListener("pointermove",k),n.removeEventListener("pointerup",C)};n.addEventListener("pointermove",k),n.addEventListener("pointerup",C)}),this.node.style.right="24px",this.node.style.top="120px",S().append(this.node);const h=this.node.getBoundingClientRect();this.node.style.left=`${h.left}px`,this.node.style.right="auto"}toggleOptions(){const t=this.opts.hidden||!!(this.findFormat||this.replaceFormat);this.opts.hidden=!t,this.fmtFind.hidden=!t,this.fmtReplace.hidden=!t}setMode(t){this.withReplace=t,this.modeFind.setAttribute("aria-selected",String(!t)),this.modeReplace.setAttribute("aria-selected",String(t));for(const e of this.replaceRow)e.hidden=!t;this.btnReplaceAll.hidden=!t,this.btnReplace.hidden=!t,t&&(this.look.value="formulas"),this.look.querySelector('option[value="values"]').disabled=t,this.look.querySelector('option[value="notes"]').disabled=t}focus(){this.what.focus(),this.what.select()}close(){this.cancel(),(this.what.value!==""||this.findFormat)&&(v=this._options(!1)),this.node.remove(),p=null,this.app.controller.pickCell=null,this.app.controller.focusGrid()}cancel(){this.ctrl&&(this.ctrl.cancelled=!0)}_formatMenu(t,e){const{app:s}=this,o=r=>{t==="find"?(this.findFormat=r,y(this.findChip,r)):(this.replaceFormat=r,y(this.replaceChip,r))};s.ribbon.openMenu(e,{items:[["Format…",()=>T(s,"Number",{onPick:r=>o(Object.keys(r).length?r:null)})],["Choose Format from Cell…",()=>{this.status.textContent=a("Click the cell whose format you want."),s.controller.pickCell=(r,n)=>{const{book:h}=s;o(I(h.styles.get(h.sheet.style(r,n)))),this.status.textContent=""}}],["Clear Format",()=>o(null)]]})}_options(t=!0){const{app:e}=this,s=e.grid.selection,o=s.ranges.length===1&&s.ranges[0].r0===s.ranges[0].r1&&s.ranges[0].c0===s.ranges[0].c1,r=e.book.sheet.mergeAt(s.row,s.col),n=o||r&&s.ranges.length===1;return{what:this.what.value,matchCase:this.matchCase.checked,whole:this.whole.checked,look:this.look.value,format:this.findFormat,byColumns:this.searchBy.value==="cols",within:this.within.value,ranges:t&&!n?s.ranges:null}}_display(){const{grid:t}=this.app;return(e,s,o)=>t.displayText(e,s,o)}_ready(t){if(t.what===""&&t.format===null)return this.status.textContent=a("Enter what to find, or choose a format."),this.what.focus(),!1;if(t.what!==""){const e=w.indexOf(t.what);e>=0&&w.splice(e,1),w.unshift(t.what),w.length=Math.min(w.length,12)}return!0}_begin(){this.cancel();const t={cancelled:!1};this.ctrl=t;const e=this.progress,s=performance.now();return t.onProgress=()=>{if(performance.now()-s>150){e.hidden=!1;const o=e.firstChild;o.style.width=`${((performance.now()-s)/40%100).toFixed(0)}%`,this.status.textContent=a("Searching… Press Esc to stop.")}},t}_end(t){this.ctrl===t&&(this.ctrl=null),this.progress.hidden=!0}_jump(t){const{app:e}=this,{book:s}=e;t.sheet!==s.sheet&&(s.selectedSheets&&!s.selectedSheets.has(t.sheet)&&(s.selectedSheets=null),e.switchSheet(s.sheets.indexOf(t.sheet)));const o=e.grid.selection;o.ranges.some(n=>(n.r0!==n.r1||n.c0!==n.c1)&&t.row>=n.r0&&t.row<=n.r1&&t.col>=n.c0&&t.col<=n.c1)?(e.grid.setSelection({ranges:o.ranges,row:t.row,col:t.col}),e.grid.ensureVisible(t.row,t.col)):e.controller.moveTo(t.row,t.col)}async doFind(t){const e=this._options();if(!this._ready(e))return null;const s=this._begin(),o=performance.now(),r=this.app.grid.selection,n=await b(this.app.book,e,{row:r.row,col:r.col},t,this._display(),s);return this._end(s),s.cancelled?(this.status.textContent=a("Stopped."),null):(this.lastMs=performance.now()-o,n?(this._jump(n),this.status.textContent=`${n.sheet===this.app.book.sheet?"":`${n.sheet.name}!`}${_(n.row,n.col)}`,n):(this.status.textContent=a("We couldn't find what you were looking for."),null))}async doFindAll(){const t=this._options();if(!this._ready(t))return;const e=this._begin(),s=performance.now(),o=await $(this.app.book,t,this._display(),e);if(this._end(e),e.cancelled){this.status.textContent=a("Stopped.");return}this.lastMs=performance.now()-s,this.results=o,this.order=new Uint32Array(o.count);for(let n=0;n<o.count;n++)this.order[n]=n;this.sort={key:null,dir:1},this.activeRow=-1;const r=g(o.count);this.status.textContent=o.overflow?a("The first {shown} cells found. There are more.",{shown:r}):a("{shown} cells found.",{count:o.count,shown:r}),this._renderResults()}_cellValue(t){const{book:e,grid:s}=this.app,{results:o}=this,r=o.sheetList[o.sheets[t]],n=o.rows[t],h=o.cols[t];if(this.look.value==="notes")return r.comments?.get(n*L+h)?.text??"";const i=r.kind(n,h)&E;return s.displayText(i,r.value(n,h),e.styles.get(r.style(n,h))).replace(/\u0001.?\u0001/g," ")}_cellFormula(t){const{book:e}=this.app,{results:s}=this,o=e.editText(s.sheetList[s.sheets[t]],s.rows[t],s.cols[t]);return o[0]==="="||o.startsWith("{=")?o:""}_sortBy(t){const{results:e}=this;if(!e)return;const s=this.sort.key===t?-this.sort.dir:1;this.sort={key:t,dir:s};const o={sheet:i=>e.sheetList[e.sheets[i]].name,cell:i=>e.cols[i]*B+e.rows[i],value:i=>this._cellValue(i),formula:i=>this._cellFormula(i)}[t],r=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"}),n=new Array(e.count);for(let i=0;i<e.count;i++)n[i]=o(i);const h=Array.from(this.order);h.sort((i,d)=>s*(typeof n[i]=="number"?n[i]-n[d]:r.compare(n[i],n[d]))),this.order=Uint32Array.from(h),this._renderResults()}_renderResults(){const{results:t}=this,e=(h,i)=>l("button",{type:"button",textContent:`${a(h)}${this.sort.key===i?this.sort.dir>0?" ▴":" ▾":""}`,on:{click:()=>this._sortBy(i)}}),s=l("div",{class:"bk-results-body",tabIndex:0}),o=l("div",{style:`height:${t.count*m}px`}),r=l("div");s.append(o,r);const n=()=>{const h=Math.floor(s.scrollTop/m),i=Math.min(t.count,h+Math.ceil(s.clientHeight/m)+2),d=[];for(let u=h;u<i;u++){const f=this.order[u],k=l("div",{class:`bk-results-row${u===this.activeRow?" active":""}`,style:`top:${u*m}px`,on:{click:()=>this._pick(u)}},l("span",{textContent:t.sheetList[t.sheets[f]].name}),l("span",{textContent:_(t.rows[f],t.cols[f])}),l("span",{textContent:this._cellValue(f)}),l("span",{textContent:this._cellFormula(f)}));d.push(k)}r.replaceChildren(...d)};this.drawResults=n,s.addEventListener("scroll",n,{passive:!0}),s.addEventListener("keydown",h=>{h.key!=="ArrowDown"&&h.key!=="ArrowUp"||(h.preventDefault(),this._pick(Math.max(0,Math.min(t.count-1,this.activeRow+(h.key==="ArrowDown"?1:-1)))))}),this.resultsHost.replaceChildren(l("div",{class:"bk-results-head"},e("Sheet","sheet"),e("Cell","cell"),e("Value","value"),e("Formula","formula")),s),this.resultsHost.hidden=t.count===0,n(),this.resultsBody=s}_pick(t){const{results:e}=this,s=this.order[t];this.activeRow=t,this._jump({sheet:e.sheetList[e.sheets[s]],row:e.rows[s],col:e.cols[s]});const o=this.resultsBody;t*m<o.scrollTop?o.scrollTop=t*m:(t+1)*m>o.scrollTop+o.clientHeight&&(o.scrollTop=(t+1)*m-o.clientHeight),this.drawResults()}async doReplace(){const t=this._options(!1);if(!this._ready(t))return;const{app:e}=this,{book:s}=e,{sheet:o}=s,{row:r,col:n}=e.grid.selection;if(await b(s,{...t,within:"sheet",look:"formulas"},{row:r,col:n},1,this._display(),{})!==null&&this._matchesHere(t,r,n))if(o.protection&&s.styles.get(o.style(r,n)).unlocked!==!0)this.status.textContent=a("This cell is locked.");else{const d=t.what===""?null:W(t.what,this.repl.value,t),u={invalid:0};if(s.transact("replace",f=>{H(s,f,r,n,d,this.replaceFormat,u)}),e.grid.invalidate(),u.invalid>0){this.status.textContent=a("There's a problem with this formula after the replacement, so the cell was left as it was.");return}}await this.doFind(1)}_matchesHere(t,e,s){const{book:o}=this.app,{sheet:r}=o;return O(o,{...t,look:"formulas"},this._display())(r,e,s,r.kind(e,s),r.value(e,s))}async doReplaceAll(){const t=this._options();if(!this._ready(t))return;const e=this._begin(),s=performance.now(),o=await N(this.app.book,t,this.repl.value,this.replaceFormat,this._display(),e);if(this._end(e),this.lastMs=performance.now()-s,o.cancelled){this.status.textContent=a("Stopped; nothing was replaced.");return}const r={count:o.count,shown:g(o.count),sheets:o.sheets},n=[o.count===0&&o.locked===0&&o.invalid===0?a("We couldn't find anything to replace."):o.sheets>1?a("All done. We made {shown} replacements on {sheets} sheets.",r):a("All done. We made {shown} replacements.",r)];o.locked>0&&n.push(a("{shown} locked cells on protected sheets were left as they were.",{count:o.locked,shown:g(o.locked)})),o.invalid>0&&n.push(a("{shown} cells were left as they were, as the replacement would break their formulas.",{count:o.invalid,shown:g(o.invalid)})),this.status.textContent=n.join(" "),this.app.grid.invalidate(),this.app.afterCommand(),this.what.focus()}}function tt(c,t){if(!p&&v){const e=c.grid.selection;return b(c.book,v,{row:e.row,col:e.col},t,(s,o,r)=>c.grid.displayText(s,o,r),{}).then(s=>s?(s.sheet&&s.sheet!==c.book.sheet&&c.switchSheet(c.book.sheets.indexOf(s.sheet)),c.controller.moveTo(s.row,s.col),s):(c.shell?.setStatus(a("We couldn't find what you were looking for.")),null))}return p?(M(c),p.doFind(t)):(U(c),null)}const A=new WeakSet;function M(c){p.app=c,!A.has(c)&&(A.add(c),c.signal?.addEventListener("abort",()=>{p?.app===c&&(p.cancel(),p.node.remove(),p=null)},{once:!0}))}function U(c,t=!1){p??=new V(c),M(c),p.setMode(t),p.focus();const e=p;return setTimeout(()=>{p===e&&document.activeElement!==e.what&&!e.node.contains(document.activeElement)&&e.focus()},0),p}export{tt as findAgain,U as openFind};
|
|
1
|
+
import{cellEditable as T}from"../core/protection.js";import{overlayRoot as L}from"../api/overlay.js";import{el as l,openFormatCells as B}from"../ui/dialogs.js";import{cellRef as _,MAX_COLS as E,MAX_ROWS as $}from"../core/address.js";import{KIND_MASK as W}from"../core/sheet.js";import{formatCount as k}from"../core/numfmt.js";import{findAll as O,findNext as v,makeReplacer as N,makeTest as H,regexProblem as F,replaceAll as P,replaceInCell as D}from"./find-engine.js";import{ensureBookCss as j}from"./book-css.js";import{svgNode as I}from"./format-tabs.js";import{t as r,tc as R}from"../i18n/index.js";const m=20,V=["fontName","fontSize","bold","italic","underline","strike","color","fill","pattern","borders","numFmt","hAlign","vAlign","wrap","indent","rotation","shrink","unlocked","hiddenFormula"];let p=null,b=null;const w=[];function M(c){const t=l("span",{class:"bk-fmt-chip",textContent:c?r("Preview*"):r("No Format Set")});return y(t,c),t}function y(c,t){c.textContent=t?r("Preview*"):r("No Format Set"),c.style.background=t?.fill??"",c.style.color=t?.color??"",c.style.fontWeight=t?.bold?"700":"",c.style.fontStyle=t?.italic?"italic":"",c.style.textDecoration=t?.underline?"underline":""}function U(c){const t={};for(const e of V)c[e]!==void 0&&c[e]!==null&&c[e]!==!1&&c[e]!==0&&c[e]!=="General"&&(t[e]=c[e]);return t}class X{constructor(t){this.app=t,this.findFormat=null,this.replaceFormat=null,this.ctrl=null,this.results=null,this.order=null,this.activeRow=-1,this.sort={key:null,dir:1},this._build()}_build(){j();const t=(i,d)=>{const u=l("select",{class:"dlg-input","aria-label":r(i)});for(const[f,g]of d)u.append(l("option",{value:g,textContent:r(f)}));return u},e=(i,d,u=!1)=>l("button",{class:`dlg-btn${u?" primary":""}`,type:"button",textContent:r(i),on:{click:d}}),o=l("button",{type:"button",class:"bk-find-history",title:r("Recent searches"),"aria-label":r("Recent searches"),on:{click:i=>this.app.ribbon.openMenu(i.currentTarget,{items:w.length?w.map(d=>[d,()=>{this.what.value=d,this.what.focus()},{raw:!0}]):[["No recent searches",()=>{}]]})}},I('<svg width="9" height="6" viewBox="0 0 9 6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1 1l3.5 3.5L8 1"/></svg>'));this.what=l("input",{class:"dlg-input","aria-label":r("Find what"),spellcheck:!1}),this.repl=l("input",{class:"dlg-input","aria-label":r("Replace with"),spellcheck:!1}),this.within=t("Within",[["Sheet","sheet"],["Workbook","workbook"]]),this.searchBy=t("Search",[["By Rows","rows"],["By Columns","cols"]]),this.look=t("Look in",[["Formulas","formulas"],["Values","values"],["Notes","notes"]]),this.matchCase=l("input",{type:"checkbox","aria-label":r("Match case")}),this.whole=l("input",{type:"checkbox","aria-label":r("Match entire cell contents")}),this.regex=l("input",{type:"checkbox","aria-label":r("Match using regular expressions")}),this.status=l("div",{class:"dlg-status",role:"status"}),this.progress=l("div",{class:"bk-progress",hidden:!0},l("div")),this.findChip=M(null),this.replaceChip=M(null);const s=i=>e("Format…",d=>this._formatMenu(i,d.currentTarget)),a=(...i)=>l("span",{class:"dlg-row bk-find-fmt",hidden:!0},...i);this.fmtFind=a(this.findChip,s("find")),this.fmtReplace=a(this.replaceChip,s("replace")),this.replaceRow=[l("span",{textContent:r("Replace with:")}),l("div",{class:"dlg-row"},this.repl,this.fmtReplace)],this.modeFind=l("button",{type:"button",role:"tab",class:"dlg-tab",textContent:r("Find"),on:{click:()=>this.setMode(!1)}}),this.modeReplace=l("button",{type:"button",role:"tab",class:"dlg-tab",textContent:r("Replace"),on:{click:()=>this.setMode(!0)}}),this.opts=l("div",{class:"bk-find-opts",hidden:!0},l("span",{textContent:r("Within:")}),this.within,l("label",{class:"dlg-row dlg-check"},this.matchCase,` ${r("Match case")}`),l("span",{textContent:r("Search:")}),this.searchBy,l("label",{class:"dlg-row dlg-check"},this.whole,` ${r("Match entire cell contents")}`),l("span",{textContent:r("Look in:")}),this.look,l("label",{class:"dlg-row dlg-check"},this.regex,` ${r("Match using regular expressions")}`)),this.btnReplaceAll=e("Replace All",()=>this.doReplaceAll()),this.btnReplace=e("Replace",()=>this.doReplace()),this.resultsHost=l("div",{class:"bk-results",hidden:!0});const n=l("h2",{class:"bk-panel-title",textContent:r("Find & Replace")});this.node=l("div",{class:"bk-panel xl-dlg",role:"dialog","aria-label":r("Find & Replace")},n,l("div",{class:"xl-tabbed"},l("div",{class:"dlg-tabs",role:"tablist"},this.modeFind,this.modeReplace),l("div",{class:"xl-box bk-find-box"},l("div",{class:"bk-find-grid"},l("span",{textContent:r("Find what:")}),l("div",{class:"dlg-row"},l("span",{class:"bk-find-field"},this.what,o),this.fmtFind),...this.replaceRow),this.opts,this.progress,this.resultsHost,l("div",{class:"bk-find-low"},this.status,e("Options",()=>this.toggleOptions())))),l("div",{class:"bk-find-foot"},this.btnReplaceAll,this.btnReplace,e("Find All",()=>this.doFindAll()),e(R("find","Previous"),()=>this.doFind(-1)),e(R("find","Next"),()=>this.doFind(1),!0),e("Close",()=>this.close()))),this.node.addEventListener("keydown",i=>{i.stopPropagation(),i.key==="Escape"?(i.preventDefault(),this.ctrl?this.cancel():this.close()):i.key==="Enter"&&i.target.tagName!=="BUTTON"&&(i.preventDefault(),this.doFind(i.shiftKey?-1:1))}),n.addEventListener("pointerdown",i=>{i.preventDefault(),n.setPointerCapture(i.pointerId);const d=this.node.getBoundingClientRect(),u=i.clientX-d.left,f=i.clientY-d.top,g=C=>{this.node.style.left=`${Math.max(0,Math.min(window.innerWidth-80,C.clientX-u))}px`,this.node.style.top=`${Math.max(0,Math.min(window.innerHeight-40,C.clientY-f))}px`},x=()=>{n.removeEventListener("pointermove",g),n.removeEventListener("pointerup",x)};n.addEventListener("pointermove",g),n.addEventListener("pointerup",x)}),this.node.style.right="24px",this.node.style.top="120px",L().append(this.node);const h=this.node.getBoundingClientRect();this.node.style.left=`${h.left}px`,this.node.style.right="auto"}toggleOptions(){const t=this.opts.hidden||!!(this.findFormat||this.replaceFormat);this.opts.hidden=!t,this.fmtFind.hidden=!t,this.fmtReplace.hidden=!t}setMode(t){this.withReplace=t,this.modeFind.setAttribute("aria-selected",String(!t)),this.modeReplace.setAttribute("aria-selected",String(t));for(const e of this.replaceRow)e.hidden=!t;this.btnReplaceAll.hidden=!t,this.btnReplace.hidden=!t,t&&(this.look.value="formulas"),this.look.querySelector('option[value="values"]').disabled=t,this.look.querySelector('option[value="notes"]').disabled=t}focus(){this.what.focus(),this.what.select()}close(){this.cancel(),(this.what.value!==""||this.findFormat)&&(b=this._options(!1)),this.node.remove(),p=null,this.app.controller.pickCell=null,this.app.controller.focusGrid()}cancel(){this.ctrl&&(this.ctrl.cancelled=!0)}_formatMenu(t,e){const{app:o}=this,s=a=>{t==="find"?(this.findFormat=a,y(this.findChip,a)):(this.replaceFormat=a,y(this.replaceChip,a))};o.ribbon.openMenu(e,{items:[["Format…",()=>B(o,"Number",{onPick:a=>s(Object.keys(a).length?a:null)})],["Choose Format from Cell…",()=>{this.status.textContent=r("Click the cell whose format you want."),o.controller.pickCell=(a,n)=>{const{book:h}=o;s(U(h.styles.get(h.sheet.style(a,n)))),this.status.textContent=""}}],["Clear Format",()=>s(null)]]})}_options(t=!0){const{app:e}=this,o=e.grid.selection,s=o.ranges.length===1&&o.ranges[0].r0===o.ranges[0].r1&&o.ranges[0].c0===o.ranges[0].c1,a=e.book.sheet.mergeAt(o.row,o.col),n=s||a&&o.ranges.length===1;return{what:this.what.value,matchCase:this.matchCase.checked,whole:this.whole.checked,regex:this.regex.checked,look:this.look.value,format:this.findFormat,byColumns:this.searchBy.value==="cols",within:this.within.value,ranges:t&&!n?o.ranges:null}}_display(){const{grid:t}=this.app;return(e,o,s)=>t.displayText(e,o,s)}_ready(t){if(t.what===""&&t.format===null)return this.status.textContent=r("Enter what to find, or choose a format."),this.what.focus(),!1;const e=t.regex?F(t.what):null;if(e!==null)return this.status.textContent=r("This regular expression isn't valid: {problem}",{problem:e}),this.what.focus(),!1;if(t.what!==""){const o=w.indexOf(t.what);o>=0&&w.splice(o,1),w.unshift(t.what),w.length=Math.min(w.length,12)}return!0}_begin(){this.cancel();const t={cancelled:!1};this.ctrl=t;const e=this.progress,o=performance.now();return t.onProgress=()=>{if(performance.now()-o>150){e.hidden=!1;const s=e.firstChild;s.style.width=`${((performance.now()-o)/40%100).toFixed(0)}%`,this.status.textContent=r("Searching… Press Esc to stop.")}},t}_end(t){this.ctrl===t&&(this.ctrl=null),this.progress.hidden=!0}_jump(t){const{app:e}=this,{book:o}=e;t.sheet!==o.sheet&&(o.selectedSheets&&!o.selectedSheets.has(t.sheet)&&(o.selectedSheets=null),e.switchSheet(o.sheets.indexOf(t.sheet)));const s=e.grid.selection;s.ranges.some(n=>(n.r0!==n.r1||n.c0!==n.c1)&&t.row>=n.r0&&t.row<=n.r1&&t.col>=n.c0&&t.col<=n.c1)?(e.grid.setSelection({ranges:s.ranges,row:t.row,col:t.col}),e.grid.ensureVisible(t.row,t.col)):e.controller.moveTo(t.row,t.col)}async doFind(t){const e=this._options();if(!this._ready(e))return null;const o=this._begin(),s=performance.now(),a=this.app.grid.selection,n=await v(this.app.book,e,{row:a.row,col:a.col},t,this._display(),o);return this._end(o),o.cancelled?(this.status.textContent=r("Stopped."),null):(this.lastMs=performance.now()-s,n?(this._jump(n),this.status.textContent=`${n.sheet===this.app.book.sheet?"":`${n.sheet.name}!`}${_(n.row,n.col)}`,n):(this.status.textContent=r("We couldn't find what you were looking for."),null))}async doFindAll(){const t=this._options();if(!this._ready(t))return;const e=this._begin(),o=performance.now(),s=await O(this.app.book,t,this._display(),e);if(this._end(e),e.cancelled){this.status.textContent=r("Stopped.");return}this.lastMs=performance.now()-o,this.results=s,this.order=new Uint32Array(s.count);for(let n=0;n<s.count;n++)this.order[n]=n;this.sort={key:null,dir:1},this.activeRow=-1;const a=k(s.count);this.status.textContent=s.overflow?r("The first {shown} cells found. There are more.",{shown:a}):r("{shown} cells found.",{count:s.count,shown:a}),this._renderResults()}_cellValue(t){const{book:e,grid:o}=this.app,{results:s}=this,a=s.sheetList[s.sheets[t]],n=s.rows[t],h=s.cols[t];if(this.look.value==="notes")return a.comments?.get(n*E+h)?.text??"";const i=a.kind(n,h)&W;return o.displayText(i,a.value(n,h),e.styles.get(a.style(n,h))).replace(/\u0001.?\u0001/g," ")}_cellFormula(t){const{book:e}=this.app,{results:o}=this,s=e.editText(o.sheetList[o.sheets[t]],o.rows[t],o.cols[t]);return s[0]==="="||s.startsWith("{=")?s:""}_sortBy(t){const{results:e}=this;if(!e)return;const o=this.sort.key===t?-this.sort.dir:1;this.sort={key:t,dir:o};const s={sheet:i=>e.sheetList[e.sheets[i]].name,cell:i=>e.cols[i]*$+e.rows[i],value:i=>this._cellValue(i),formula:i=>this._cellFormula(i)}[t],a=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"}),n=new Array(e.count);for(let i=0;i<e.count;i++)n[i]=s(i);const h=Array.from(this.order);h.sort((i,d)=>o*(typeof n[i]=="number"?n[i]-n[d]:a.compare(n[i],n[d]))),this.order=Uint32Array.from(h),this._renderResults()}_renderResults(){const{results:t}=this,e=(h,i)=>l("button",{type:"button",textContent:`${r(h)}${this.sort.key===i?this.sort.dir>0?" ▴":" ▾":""}`,on:{click:()=>this._sortBy(i)}}),o=l("div",{class:"bk-results-body",tabIndex:0}),s=l("div",{style:`height:${t.count*m}px`}),a=l("div");o.append(s,a);const n=()=>{const h=Math.floor(o.scrollTop/m),i=Math.min(t.count,h+Math.ceil(o.clientHeight/m)+2),d=[];for(let u=h;u<i;u++){const f=this.order[u],g=l("div",{class:`bk-results-row${u===this.activeRow?" active":""}`,style:`top:${u*m}px`,on:{click:()=>this._pick(u)}},l("span",{textContent:t.sheetList[t.sheets[f]].name}),l("span",{textContent:_(t.rows[f],t.cols[f])}),l("span",{textContent:this._cellValue(f)}),l("span",{textContent:this._cellFormula(f)}));d.push(g)}a.replaceChildren(...d)};this.drawResults=n,o.addEventListener("scroll",n,{passive:!0}),o.addEventListener("keydown",h=>{h.key!=="ArrowDown"&&h.key!=="ArrowUp"||(h.preventDefault(),this._pick(Math.max(0,Math.min(t.count-1,this.activeRow+(h.key==="ArrowDown"?1:-1)))))}),this.resultsHost.replaceChildren(l("div",{class:"bk-results-head"},e("Sheet","sheet"),e("Cell","cell"),e("Value","value"),e("Formula","formula")),o),this.resultsHost.hidden=t.count===0,n(),this.resultsBody=o}_pick(t){const{results:e}=this,o=this.order[t];this.activeRow=t,this._jump({sheet:e.sheetList[e.sheets[o]],row:e.rows[o],col:e.cols[o]});const s=this.resultsBody;t*m<s.scrollTop?s.scrollTop=t*m:(t+1)*m>s.scrollTop+s.clientHeight&&(s.scrollTop=(t+1)*m-s.clientHeight),this.drawResults()}async doReplace(){const t=this._options(!1);if(!this._ready(t))return;const{app:e}=this,{book:o}=e,{sheet:s}=o,{row:a,col:n}=e.grid.selection;if(await v(o,{...t,within:"sheet",look:"formulas"},{row:a,col:n},1,this._display(),{})!==null&&this._matchesHere(t,a,n))if(s.protection&&!T(o,s,a,n))this.status.textContent=r("This cell is locked.");else{const d=t.what===""?null:N(t.what,this.repl.value,t),u={invalid:0};if(o.transact("replace",f=>{D(o,f,a,n,d,this.replaceFormat,u)}),e.grid.invalidate(),u.invalid>0){this.status.textContent=r("There's a problem with this formula after the replacement, so the cell was left as it was.");return}}await this.doFind(1)}_matchesHere(t,e,o){const{book:s}=this.app,{sheet:a}=s;return H(s,{...t,look:"formulas"},this._display())(a,e,o,a.kind(e,o),a.value(e,o))}async doReplaceAll(){const t=this._options();if(!this._ready(t))return;const e=this._begin(),o=performance.now(),s=await P(this.app.book,t,this.repl.value,this.replaceFormat,this._display(),e);if(this._end(e),this.lastMs=performance.now()-o,s.cancelled){this.status.textContent=r("Stopped; nothing was replaced.");return}const a={count:s.count,shown:k(s.count),sheets:s.sheets},n=[s.count===0&&s.locked===0&&s.invalid===0?r("We couldn't find anything to replace."):s.sheets>1?r("All done. We made {shown} replacements on {sheets} sheets.",a):r("All done. We made {shown} replacements.",a)];s.locked>0&&n.push(r("{shown} locked cells on protected sheets were left as they were.",{count:s.locked,shown:k(s.locked)})),s.invalid>0&&n.push(r("{shown} cells were left as they were, as the replacement would break their formulas.",{count:s.invalid,shown:k(s.invalid)})),this.status.textContent=n.join(" "),this.app.grid.invalidate(),this.app.afterCommand(),this.what.focus()}}function ot(c,t){if(!p&&b){const e=b.regex?F(b.what):null;if(e!==null)return c.shell?.setStatus(r("This regular expression isn't valid: {problem}",{problem:e})),null;const o=c.grid.selection;return v(c.book,b,{row:o.row,col:o.col},t,(s,a,n)=>c.grid.displayText(s,a,n),{}).then(s=>s?(s.sheet&&s.sheet!==c.book.sheet&&c.switchSheet(c.book.sheets.indexOf(s.sheet)),c.controller.moveTo(s.row,s.col),s):(c.shell?.setStatus(r("We couldn't find what you were looking for.")),null))}return p?(A(c),p.doFind(t)):(K(c),null)}const S=new WeakSet;function A(c){p.app=c,!S.has(c)&&(S.add(c),c.signal?.addEventListener("abort",()=>{p?.app===c&&(p.cancel(),p.node.remove(),p=null)},{once:!0}))}function K(c,t=!1){p??=new X(c),A(c),p.setMode(t),p.focus();const e=p;return setTimeout(()=>{p===e&&document.activeElement!==e.what&&!e.node.contains(document.activeElement)&&e.focus()},0),p}export{ot as findAgain,K as openFind};
|
package/cells/goto.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{el as h,openModal as D}from"../ui/dialogs.js";import{ensureBookCss as L}from"./book-css.js";import{BOOL as U,CHUNK_BITS as v,CHUNK_MASK as $,ERR as q,FORMULA as T,KIND_MASK as N,NUM as H,STR as V}from"../core/sheet.js";import{MAX_COLS as y,MAX_ROWS as j,parseRangeRef as G}from"../core/address.js";import{goToText as X,locationText as z,namedPlaces as P}from"./name-box.js";import{inRanges as S}from"./selection-modes.js";import{t as M,tc as A}from"../i18n/index.js";const O=32768;class C{constructor(){this.ranges=[],this.open=new Map,this.col=-1}add(a,s,e){const n=s*j+e,i=this.open.get(n);if(i&&i.c1===a-1){i.c1=a;return}const t={r0:s,c0:a,r1:e,c1:a};this.open.set(n,t),this.ranges.push(t)}get tooMany(){return this.ranges.length>O}}function Z(r){const{grid:a,book:s}=r,{sheet:e}=s,{ranges:n}=a.selection,i=t=>({r0:t.r0,c0:t.c0,r1:Math.min(t.r1,e.maxRow),c1:Math.min(t.c1,e.maxCol)});if(_(r)){const{r0:t,c0:c}=W(e);return[{r0:t,c0:c,r1:Math.max(t,e.maxRow),c1:Math.max(c,e.maxCol)}]}return n.map(i).filter(t=>t.r0<=t.r1&&t.c0<=t.c1)}function _(r){const{ranges:a}=r.grid.selection;if(a.length!==1)return!1;const s=a[0];if(s.r0===s.r1&&s.c0===s.c1)return!0;const e=r.book.sheet.mergeAt(s.r0,s.c0);return e!=null&&e.r0===s.r0&&e.c0===s.c0&&e.r1===s.r1&&e.c1===s.c1}function W(r){let a=1/0,s=1/0;for(const e of r.rowStyles?.keys()??[])e<a&&(a=e),s=0;for(const e of r.colStyles?.keys()??[])e<s&&(s=e),a=0;for(let e=0;e<=r.maxCol;e++){const n=r.columns[e];if(n!==void 0)for(let i=0;i<n.length&&i<<v<a;i++){const t=n[i];if(t===void 0)continue;const c=i<<v;for(let o=0;o<t.kinds.length&&c+o<a;o++)if(!(t.kinds[o]===0&&(t.styles===null||t.styles[o]===0))){a=c+o,e<s&&(s=e);break}if(s===e)break}}return{r0:a===1/0?0:a,c0:s===1/0?0:s}}function I(r,a,s){const e=new C;for(const n of a)for(let i=n.c0;i<=n.c1;i++){const t=r.columns[i];if(t===void 0)continue;let c=-1;for(let o=n.r0>>>v;o<=n.r1>>>v;o++){const l=t[o],f=o<<v;if(l===void 0){c>=0&&(e.add(i,c,f-1),c=-1);continue}const m=Math.max(n.r0-f,0),u=Math.min(n.r1-f,$);for(let d=m;d<=u;d++){const g=l.kinds[d];g!==0&&s(g,f+d,i,l.values[d])?c<0&&(c=f+d):c>=0&&(e.add(i,c,f+d-1),c=-1)}}c>=0&&e.add(i,c,n.r1)}return e}const K=(r,a)=>{const s=r&N;return s===H&&a.numbers||s===V&&a.text||s===U&&a.logicals||s===q&&a.errors};function J(r,a){const s=new C;for(const e of a)for(let n=e.c0;n<=e.c1&&!s.tooMany;n++){const i=r.columns[n];if(i===void 0){s.add(n,e.r0,e.r1);continue}let t=-1;for(let c=e.r0;c<=e.r1;c++){const o=i[c>>>v];if(o===void 0){t<0&&(t=c);const l=c|$;c=Math.min(l,e.r1);continue}o.kinds[c&$]===0?t<0&&(t=c):t>=0&&(s.add(n,t,c-1),t=-1)}t>=0&&s.add(n,t,e.r1)}return s}const B=(r,a,s)=>{const e=r.rAbs0?r.r0:a+r.r0,n=r.rAbs1?r.r1:a+r.r1,i=r.cAbs0?r.c0:s+r.c0,t=r.cAbs1?r.c1:s+r.c1;return{r0:Math.min(e,n),c0:Math.min(i,t),r1:Math.max(e,n),c1:Math.max(i,t)}};function E(r,a,s,e){return a.formula(s,e)?.tpl??null}function Q(r,a,s,e){const n=new Set,i=[];let t=[];for(const c of s)for(const[o]of a.formulas){const l=Math.floor(o/y),f=o-l*y;l>=c.r0&&l<=c.r1&&f>=c.c0&&f<=c.c1&&t.push([l,f])}for(let c=0;t.length>0&&c<64;c++){const o=[];for(const[l,f]of t){const m=E(r,a,l,f);if(m)for(const u of m.refs){if(u.sheet)continue;const d=B(u,l,f),g=`${d.r0},${d.c0},${d.r1},${d.c1}`;if(!n.has(g)&&(n.add(g),i.push({r0:d.r0,c0:d.c0,r1:Math.min(d.r1,j-1),c1:Math.min(d.c1,y-1)}),!!e))for(const[b]of a.formulas){const p=Math.floor(b/y),k=b-p*y;p>=d.r0&&p<=d.r1&&k>=d.c0&&k<=d.c1&&o.push([p,k])}}}if(!e)break;t=o}return i}function Y(r,a,s,e){const n=new Set;let i=s;for(let o=0;i.length>0&&o<64;o++){const l=[];for(const[f]of a.formulas){if(n.has(f))continue;const m=Math.floor(f/y),u=f-m*y,d=E(r,a,m,u);if(d)for(const g of d.refs){if(g.sheet)continue;const b=B(g,m,u);if(i.some(p=>b.r0<=p.r1&&b.r1>=p.r0&&b.c0<=p.c1&&b.c1>=p.c0)){n.add(f),l.push({r0:m,c0:u,r1:m,c1:u});break}}}if(!e)break;i=l}const t=new Map;for(const o of n){const l=Math.floor(o/y),f=o-l*y;t.has(f)||t.set(f,[]),t.get(f).push(l)}const c=new C;for(const o of[...t.keys()].sort((l,f)=>l-f)){const l=t.get(o).sort((m,u)=>m-u);let f=l[0];for(let m=1;m<=l.length;m++)l[m]!==l[m-1]+1&&(c.add(o,f,l[m-1]),f=l[m])}return c.ranges}function R(r,a,s,e,n,i){const t=a.kind(s,e);return t&T?`f${r.editText(a,s,e).replace(/\$?[A-Z]{1,3}\$?\d+/g,o=>{const l=/^(\$?)([A-Z]+)(\$?)(\d+)$/.exec(o),f=l[2].split("").reduce((m,u)=>m*26+u.charCodeAt(0)-64,0)-1;return`${l[1]?`$${l[2]}`:`C[${f-e+i}]`}${l[3]?`$${l[4]}`:`R[${Number(l[4])-1-s+n}]`}`})}`:`${t&N}:${a.value(s,e)}`}function ee(r,a,s,e){const n=new C;for(const i of s)for(let t=i.c0;t<=i.c1;t++){if(t===e)continue;let c=-1;for(let o=i.r0;o<=i.r1;o++){const l=R(r,a,o,t,o,e)!==R(r,a,o,e,o,e);l&&c<0?c=o:!l&&c>=0&&(n.add(t,c,o-1),c=-1)}c>=0&&n.add(t,c,i.r1)}return n}function te(r,a,s,e){const n=new C;for(const i of s)for(let t=i.c0;t<=i.c1;t++){const c=R(r,a,e,t,e,t);let o=-1;for(let l=i.r0;l<=i.r1;l++){const f=l!==e&&R(r,a,l,t,e,t)!==c;f&&o<0?o=l:!f&&o>=0&&(n.add(t,o,l-1),o=-1)}o>=0&&n.add(t,o,i.r1)}return n}function ne(r,a){const s=(n,i,t)=>{const c=[];let o=-1;for(let l=i;l<=t;l++){const f=n.sizeOf(l)>0;f&&o<0?o=l:!f&&o>=0&&(c.push([o,l-1]),o=-1)}return o>=0&&c.push([o,t]),c},e=[];for(const n of a){const i=s(r.rows,n.r0,Math.min(n.r1,Math.max(r.maxRow,n.r0))),t=s(r.cols,n.c0,Math.min(n.c1,Math.max(r.maxCol,n.c0)));for(const[c,o]of i)for(const[l,f]of t)e.push({r0:c,c0:l,r1:o,c1:f})}return e}const F=r=>(r??"").split(/\s+/).map(G).filter(Boolean);function oe(r,{same:a},s,e){const n=[];for(const i of r.cf??[]){const t=F(i.sqref);(!a||S(t,s,e))&&n.push(...t)}return n}function se(r,{same:a},s,e){const n=[];for(const i of r.validations??[]){const t=F(i.sqref);(!a||S(t,s,e))&&n.push(...t)}return n}function ce(r){const{book:a,grid:s}=r,{sheet:e}=a,{row:n,col:i}=s.selection,t=(o,l)=>{const f=e.formula(o,l);return f&&f.t==="array"&&f.ref?G(f.ref):null};let c=t(n,i);if(!c&&a.engine?.spillMaster){const o=a.engine.spillMaster(e,n,i);o&&(c=t(o.row,o.col)??null)}return c}function re(r,a,s={}){const{book:e,grid:n,controller:i,shell:t}=r,{sheet:c}=e,{row:o,col:l}=n.selection,f=Z(r),m={numbers:s.numbers!==!1,text:s.text!==!1,logicals:s.logicals!==!1,errors:s.errors!==!1};let u=[];switch(a){case"notes":{const b=new C,p=_(r),k=[...c.comments?.keys()??[]].map(x=>[x%y,Math.floor(x/y)]).filter(([x,w])=>p||S(n.selection.ranges,w,x)).sort((x,w)=>x[0]-w[0]||x[1]-w[1]);for(const[x,w]of k)b.add(x,w,w);u=b.ranges;break}case"constants":u=I(c,f,b=>!(b&T)&&K(b,m)).ranges;break;case"formulas":u=I(c,f,b=>b&T&&K(b,m)).ranges;break;case"blanks":u=J(c,f).ranges;break;case"region":{u=[r.commands._currentRegion(o,l)??{r0:o,c0:l,r1:o,c1:l}];break}case"array":{const b=ce(r);u=b?[b]:[];break}case"objects":{const p=(r.objects?._state?.(c)?.objects??[]).filter(k=>!k.hidden&&k.kind!=="foreign");if(p.length>0){r.objects.select(p[0]);for(const k of p.slice(1))r.objects.select(k,{add:!0});t.setStatus(M("{count} objects selected.",{count:p.length}))}else t.setStatus(M("There are no objects on this sheet."));return}case"rowDiff":u=ee(e,c,f,l).ranges;break;case"colDiff":u=te(e,c,f,o).ranges;break;case"precedents":case"precedentsAll":u=Q(e,c,n.selection.ranges,a==="precedentsAll");break;case"dependents":case"dependentsAll":u=Y(e,c,n.selection.ranges,a==="dependentsAll");break;case"lastCell":u=[{r0:Math.max(c.maxRow,0),c0:Math.max(c.maxCol,0),r1:Math.max(c.maxRow,0),c1:Math.max(c.maxCol,0)}];break;case"visible":u=ne(c,n.selection.ranges.length===1&&n.selection.ranges[0].r0===n.selection.ranges[0].r1&&n.selection.ranges[0].c0===n.selection.ranges[0].c1?f:n.selection.ranges);break;case"cf":u=oe(c,s,o,l);break;case"validation":u=se(c,s,o,l);break;default:return}if(u.length===0){t.setStatus(M("No cells were found."));return}if(u.length>O){t.setStatus(M("That selection is too large: more than {count} separate areas.",{count:O.toLocaleString("en-US")}));return}const d=u[0],g=S(u,o,l);n.setSelection({ranges:u,row:g?o:d.r0,col:g?l:d.c0}),i.extent={row:d.r1,col:d.c1},g||n.ensureVisible(d.r0,d.c0)}function le(r){L();const a="bk-special";let s="notes";const e=(p,k,x=!1)=>{const w=h("input",{type:"radio",name:a,value:p,checked:x,on:{change:()=>{s=p,g()}}});return h("label",{class:"dlg-row dlg-check"},w,` ${A("special",k)}`)},n={numbers:h("input",{type:"checkbox",checked:!0}),text:h("input",{type:"checkbox",checked:!0}),logicals:h("input",{type:"checkbox",checked:!0}),errors:h("input",{type:"checkbox",checked:!0})},i=h("input",{type:"radio",name:"bk-depth",checked:!0}),t=h("input",{type:"radio",name:"bk-depth"}),c=h("input",{type:"radio",name:"bk-same",checked:!0}),o=h("input",{type:"radio",name:"bk-same"}),l=(p,k)=>h("label",{class:"dlg-row dlg-check"},p,` ${A("special",k)}`),f=h("div",{class:"bk-special-opts"},l(n.numbers,"Numbers"),l(n.text,"Text"),l(n.logicals,"Logicals"),l(n.errors,"Errors")),m=h("div",{class:"bk-special-opts"},l(i,"Direct only"),l(t,"All levels")),u=h("div",{class:"bk-special-opts"},l(c,"All"),l(o,"Same")),d=h("p",{class:"bk-special-none",textContent:M("There are no options for this selection.")}),g=()=>{f.hidden=s!=="constants"&&s!=="formulas",m.hidden=s!=="precedents"&&s!=="dependents",u.hidden=s!=="cf"&&s!=="validation",d.hidden=!(f.hidden&&m.hidden&&u.hidden)},b=h("div",{class:"bk-special"},h("div",{class:"xl-head dlg-label",textContent:A("special","Select")}),h("div",{class:"bk-grid2"},h("div",{},e("notes","Notes",!0),e("constants","Constants"),e("formulas","Formulas"),e("blanks","Blanks"),e("region","Current region"),e("array","Current array"),e("rowDiff","Row differences"),e("colDiff","Column differences")),h("div",{},e("precedents","Precedents"),e("dependents","Dependents"),e("lastCell","Last cell"),e("visible","Visible cells only"),e("objects","Objects"),e("cf","Conditional formats"),e("validation","Data validation"))),h("hr",{class:"xl-rule"}),h("div",{class:"xl-head dlg-label",textContent:M("Options")}),h("div",{class:"bk-special-low"},f,m,u,d));g(),D(r,A("dlg","Go To Special"),b,[{label:"Cancel"},{label:"OK",primary:!0,action:()=>{let p=s;(p==="precedents"||p==="dependents")&&t.checked&&(p+="All"),re(r,p,{numbers:n.numbers.checked,text:n.text.checked,logicals:n.logicals.checked,errors:n.errors.checked,same:o.checked})}}],{width:334,className:"xl-dlg"})}function pe(r){const{book:a,grid:s}=r,e=a.gotoHistory??=[],n=h("select",{class:"dlg-list bk-goto-list",size:8,"aria-label":M("Go to")});for(const o of P(a))n.append(h("option",{value:o.label,textContent:o.label}));for(const o of e.slice().reverse())n.append(h("option",{value:o,textContent:o}));const i=h("input",{class:"dlg-input","aria-label":M("Reference"),spellcheck:!1,value:e[e.length-1]??""});n.addEventListener("change",()=>{i.value=n.value}),n.addEventListener("dblclick",()=>{t()&&c.close()});const t=()=>{const o=z(a,s.selection);return X(r,i.value)?(e[e.length-1]!==o&&e.push(o),e.length>32&&e.shift(),!0):(i.select(),!1)};L();const c=D(r,A("dlg","Go To"),h("div",{class:"dlg-col"},h("div",{class:"dlg-label",textContent:M("Go to:")}),n,h("label",{class:"bk-above"},h("span",{textContent:M("Reference:")}),i)),[{label:"Special…",left:!0,action:()=>{queueMicrotask(()=>le(r))}},{label:"Cancel"},{label:"OK",primary:!0,action:()=>t()}],{width:326,className:"xl-dlg"});i.focus(),i.select()}export{le as goToSpecial,pe as openGoTo,re as selectSpecial};
|
|
1
|
+
import{el as h,openModal as D}from"../ui/dialogs.js";import{ensureBookCss as L}from"./book-css.js";import{BOOL as U,CHUNK_BITS as v,CHUNK_MASK as $,ERR as q,FORMULA as T,KIND_MASK as N,NUM as V,STR as H}from"../core/sheet.js";import{allValidations as X,hostFormats as z}from"../core/host-rules.js";import{MAX_COLS as y,MAX_ROWS as j,parseRangeRef as G}from"../core/address.js";import{goToText as P,locationText as Z,namedPlaces as W}from"./name-box.js";import{inRanges as S}from"./selection-modes.js";import{t as M,tc as A}from"../i18n/index.js";const O=32768;class C{constructor(){this.ranges=[],this.open=new Map,this.col=-1}add(a,s,e){const n=s*j+e,i=this.open.get(n);if(i&&i.c1===a-1){i.c1=a;return}const t={r0:s,c0:a,r1:e,c1:a};this.open.set(n,t),this.ranges.push(t)}get tooMany(){return this.ranges.length>O}}function J(r){const{grid:a,book:s}=r,{sheet:e}=s,{ranges:n}=a.selection,i=t=>({r0:t.r0,c0:t.c0,r1:Math.min(t.r1,e.maxRow),c1:Math.min(t.c1,e.maxCol)});if(_(r)){const{r0:t,c0:c}=Q(e);return[{r0:t,c0:c,r1:Math.max(t,e.maxRow),c1:Math.max(c,e.maxCol)}]}return n.map(i).filter(t=>t.r0<=t.r1&&t.c0<=t.c1)}function _(r){const{ranges:a}=r.grid.selection;if(a.length!==1)return!1;const s=a[0];if(s.r0===s.r1&&s.c0===s.c1)return!0;const e=r.book.sheet.mergeAt(s.r0,s.c0);return e!=null&&e.r0===s.r0&&e.c0===s.c0&&e.r1===s.r1&&e.c1===s.c1}function Q(r){let a=1/0,s=1/0;for(const e of r.rowStyles?.keys()??[])e<a&&(a=e),s=0;for(const e of r.colStyles?.keys()??[])e<s&&(s=e),a=0;for(let e=0;e<=r.maxCol;e++){const n=r.columns[e];if(n!==void 0)for(let i=0;i<n.length&&i<<v<a;i++){const t=n[i];if(t===void 0)continue;const c=i<<v;for(let o=0;o<t.kinds.length&&c+o<a;o++)if(!(t.kinds[o]===0&&(t.styles===null||t.styles[o]===0))){a=c+o,e<s&&(s=e);break}if(s===e)break}}return{r0:a===1/0?0:a,c0:s===1/0?0:s}}function I(r,a,s){const e=new C;for(const n of a)for(let i=n.c0;i<=n.c1;i++){const t=r.columns[i];if(t===void 0)continue;let c=-1;for(let o=n.r0>>>v;o<=n.r1>>>v;o++){const l=t[o],f=o<<v;if(l===void 0){c>=0&&(e.add(i,c,f-1),c=-1);continue}const m=Math.max(n.r0-f,0),u=Math.min(n.r1-f,$);for(let d=m;d<=u;d++){const g=l.kinds[d];g!==0&&s(g,f+d,i,l.values[d])?c<0&&(c=f+d):c>=0&&(e.add(i,c,f+d-1),c=-1)}}c>=0&&e.add(i,c,n.r1)}return e}const K=(r,a)=>{const s=r&N;return s===V&&a.numbers||s===H&&a.text||s===U&&a.logicals||s===q&&a.errors};function Y(r,a){const s=new C;for(const e of a)for(let n=e.c0;n<=e.c1&&!s.tooMany;n++){const i=r.columns[n];if(i===void 0){s.add(n,e.r0,e.r1);continue}let t=-1;for(let c=e.r0;c<=e.r1;c++){const o=i[c>>>v];if(o===void 0){t<0&&(t=c);const l=c|$;c=Math.min(l,e.r1);continue}o.kinds[c&$]===0?t<0&&(t=c):t>=0&&(s.add(n,t,c-1),t=-1)}t>=0&&s.add(n,t,e.r1)}return s}const B=(r,a,s)=>{const e=r.rAbs0?r.r0:a+r.r0,n=r.rAbs1?r.r1:a+r.r1,i=r.cAbs0?r.c0:s+r.c0,t=r.cAbs1?r.c1:s+r.c1;return{r0:Math.min(e,n),c0:Math.min(i,t),r1:Math.max(e,n),c1:Math.max(i,t)}};function E(r,a,s,e){return a.formula(s,e)?.tpl??null}function ee(r,a,s,e){const n=new Set,i=[];let t=[];for(const c of s)for(const[o]of a.formulas){const l=Math.floor(o/y),f=o-l*y;l>=c.r0&&l<=c.r1&&f>=c.c0&&f<=c.c1&&t.push([l,f])}for(let c=0;t.length>0&&c<64;c++){const o=[];for(const[l,f]of t){const m=E(r,a,l,f);if(m)for(const u of m.refs){if(u.sheet)continue;const d=B(u,l,f),g=`${d.r0},${d.c0},${d.r1},${d.c1}`;if(!n.has(g)&&(n.add(g),i.push({r0:d.r0,c0:d.c0,r1:Math.min(d.r1,j-1),c1:Math.min(d.c1,y-1)}),!!e))for(const[b]of a.formulas){const p=Math.floor(b/y),k=b-p*y;p>=d.r0&&p<=d.r1&&k>=d.c0&&k<=d.c1&&o.push([p,k])}}}if(!e)break;t=o}return i}function te(r,a,s,e){const n=new Set;let i=s;for(let o=0;i.length>0&&o<64;o++){const l=[];for(const[f]of a.formulas){if(n.has(f))continue;const m=Math.floor(f/y),u=f-m*y,d=E(r,a,m,u);if(d)for(const g of d.refs){if(g.sheet)continue;const b=B(g,m,u);if(i.some(p=>b.r0<=p.r1&&b.r1>=p.r0&&b.c0<=p.c1&&b.c1>=p.c0)){n.add(f),l.push({r0:m,c0:u,r1:m,c1:u});break}}}if(!e)break;i=l}const t=new Map;for(const o of n){const l=Math.floor(o/y),f=o-l*y;t.has(f)||t.set(f,[]),t.get(f).push(l)}const c=new C;for(const o of[...t.keys()].sort((l,f)=>l-f)){const l=t.get(o).sort((m,u)=>m-u);let f=l[0];for(let m=1;m<=l.length;m++)l[m]!==l[m-1]+1&&(c.add(o,f,l[m-1]),f=l[m])}return c.ranges}function R(r,a,s,e,n,i){const t=a.kind(s,e);return t&T?`f${r.editText(a,s,e).replace(/\$?[A-Z]{1,3}\$?\d+/g,o=>{const l=/^(\$?)([A-Z]+)(\$?)(\d+)$/.exec(o),f=l[2].split("").reduce((m,u)=>m*26+u.charCodeAt(0)-64,0)-1;return`${l[1]?`$${l[2]}`:`C[${f-e+i}]`}${l[3]?`$${l[4]}`:`R[${Number(l[4])-1-s+n}]`}`})}`:`${t&N}:${a.value(s,e)}`}function ne(r,a,s,e){const n=new C;for(const i of s)for(let t=i.c0;t<=i.c1;t++){if(t===e)continue;let c=-1;for(let o=i.r0;o<=i.r1;o++){const l=R(r,a,o,t,o,e)!==R(r,a,o,e,o,e);l&&c<0?c=o:!l&&c>=0&&(n.add(t,c,o-1),c=-1)}c>=0&&n.add(t,c,i.r1)}return n}function oe(r,a,s,e){const n=new C;for(const i of s)for(let t=i.c0;t<=i.c1;t++){const c=R(r,a,e,t,e,t);let o=-1;for(let l=i.r0;l<=i.r1;l++){const f=l!==e&&R(r,a,l,t,e,t)!==c;f&&o<0?o=l:!f&&o>=0&&(n.add(t,o,l-1),o=-1)}o>=0&&n.add(t,o,i.r1)}return n}function se(r,a){const s=(n,i,t)=>{const c=[];let o=-1;for(let l=i;l<=t;l++){const f=n.sizeOf(l)>0;f&&o<0?o=l:!f&&o>=0&&(c.push([o,l-1]),o=-1)}return o>=0&&c.push([o,t]),c},e=[];for(const n of a){const i=s(r.rows,n.r0,Math.min(n.r1,Math.max(r.maxRow,n.r0))),t=s(r.cols,n.c0,Math.min(n.c1,Math.max(r.maxCol,n.c0)));for(const[c,o]of i)for(const[l,f]of t)e.push({r0:c,c0:l,r1:o,c1:f})}return e}const F=r=>(r??"").split(/\s+/).map(G).filter(Boolean);function ce(r,{same:a},s,e){const n=[];for(const i of[...r.cf??[],...z(r)]){const t=F(i.sqref);(!a||S(t,s,e))&&n.push(...t)}return n}function re(r,{same:a},s,e){const n=[];for(const i of X(r)){const t=F(i.sqref);(!a||S(t,s,e))&&n.push(...t)}return n}function le(r){const{book:a,grid:s}=r,{sheet:e}=a,{row:n,col:i}=s.selection,t=(o,l)=>{const f=e.formula(o,l);return f&&f.t==="array"&&f.ref?G(f.ref):null};let c=t(n,i);if(!c&&a.engine?.spillMaster){const o=a.engine.spillMaster(e,n,i);o&&(c=t(o.row,o.col)??null)}return c}function ae(r,a,s={}){const{book:e,grid:n,controller:i,shell:t}=r,{sheet:c}=e,{row:o,col:l}=n.selection,f=J(r),m={numbers:s.numbers!==!1,text:s.text!==!1,logicals:s.logicals!==!1,errors:s.errors!==!1};let u=[];switch(a){case"notes":{const b=new C,p=_(r),k=[...c.comments?.keys()??[]].map(x=>[x%y,Math.floor(x/y)]).filter(([x,w])=>p||S(n.selection.ranges,w,x)).sort((x,w)=>x[0]-w[0]||x[1]-w[1]);for(const[x,w]of k)b.add(x,w,w);u=b.ranges;break}case"constants":u=I(c,f,b=>!(b&T)&&K(b,m)).ranges;break;case"formulas":u=I(c,f,b=>b&T&&K(b,m)).ranges;break;case"blanks":u=Y(c,f).ranges;break;case"region":{u=[r.commands._currentRegion(o,l)??{r0:o,c0:l,r1:o,c1:l}];break}case"array":{const b=le(r);u=b?[b]:[];break}case"objects":{const p=(r.objects?._state?.(c)?.objects??[]).filter(k=>!k.hidden&&k.kind!=="foreign");if(p.length>0){r.objects.select(p[0]);for(const k of p.slice(1))r.objects.select(k,{add:!0});t.setStatus(M("{count} objects selected.",{count:p.length}))}else t.setStatus(M("There are no objects on this sheet."));return}case"rowDiff":u=ne(e,c,f,l).ranges;break;case"colDiff":u=oe(e,c,f,o).ranges;break;case"precedents":case"precedentsAll":u=ee(e,c,n.selection.ranges,a==="precedentsAll");break;case"dependents":case"dependentsAll":u=te(e,c,n.selection.ranges,a==="dependentsAll");break;case"lastCell":u=[{r0:Math.max(c.maxRow,0),c0:Math.max(c.maxCol,0),r1:Math.max(c.maxRow,0),c1:Math.max(c.maxCol,0)}];break;case"visible":u=se(c,n.selection.ranges.length===1&&n.selection.ranges[0].r0===n.selection.ranges[0].r1&&n.selection.ranges[0].c0===n.selection.ranges[0].c1?f:n.selection.ranges);break;case"cf":u=ce(c,s,o,l);break;case"validation":u=re(c,s,o,l);break;default:return}if(u.length===0){t.setStatus(M("No cells were found."));return}if(u.length>O){t.setStatus(M("That selection is too large: more than {count} separate areas.",{count:O.toLocaleString("en-US")}));return}const d=u[0],g=S(u,o,l);n.setSelection({ranges:u,row:g?o:d.r0,col:g?l:d.c0}),i.extent={row:d.r1,col:d.c1},g||n.ensureVisible(d.r0,d.c0)}function ie(r){L();const a="bk-special";let s="notes";const e=(p,k,x=!1)=>{const w=h("input",{type:"radio",name:a,value:p,checked:x,on:{change:()=>{s=p,g()}}});return h("label",{class:"dlg-row dlg-check"},w,` ${A("special",k)}`)},n={numbers:h("input",{type:"checkbox",checked:!0}),text:h("input",{type:"checkbox",checked:!0}),logicals:h("input",{type:"checkbox",checked:!0}),errors:h("input",{type:"checkbox",checked:!0})},i=h("input",{type:"radio",name:"bk-depth",checked:!0}),t=h("input",{type:"radio",name:"bk-depth"}),c=h("input",{type:"radio",name:"bk-same",checked:!0}),o=h("input",{type:"radio",name:"bk-same"}),l=(p,k)=>h("label",{class:"dlg-row dlg-check"},p,` ${A("special",k)}`),f=h("div",{class:"bk-special-opts"},l(n.numbers,"Numbers"),l(n.text,"Text"),l(n.logicals,"Logicals"),l(n.errors,"Errors")),m=h("div",{class:"bk-special-opts"},l(i,"Direct only"),l(t,"All levels")),u=h("div",{class:"bk-special-opts"},l(c,"All"),l(o,"Same")),d=h("p",{class:"bk-special-none",textContent:M("There are no options for this selection.")}),g=()=>{f.hidden=s!=="constants"&&s!=="formulas",m.hidden=s!=="precedents"&&s!=="dependents",u.hidden=s!=="cf"&&s!=="validation",d.hidden=!(f.hidden&&m.hidden&&u.hidden)},b=h("div",{class:"bk-special"},h("div",{class:"xl-head dlg-label",textContent:A("special","Select")}),h("div",{class:"bk-grid2"},h("div",{},e("notes","Notes",!0),e("constants","Constants"),e("formulas","Formulas"),e("blanks","Blanks"),e("region","Current region"),e("array","Current array"),e("rowDiff","Row differences"),e("colDiff","Column differences")),h("div",{},e("precedents","Precedents"),e("dependents","Dependents"),e("lastCell","Last cell"),e("visible","Visible cells only"),e("objects","Objects"),e("cf","Conditional formats"),e("validation","Data validation"))),h("hr",{class:"xl-rule"}),h("div",{class:"xl-head dlg-label",textContent:M("Options")}),h("div",{class:"bk-special-low"},f,m,u,d));g(),D(r,A("dlg","Go To Special"),b,[{label:"Cancel"},{label:"OK",primary:!0,action:()=>{let p=s;(p==="precedents"||p==="dependents")&&t.checked&&(p+="All"),ae(r,p,{numbers:n.numbers.checked,text:n.text.checked,logicals:n.logicals.checked,errors:n.errors.checked,same:o.checked})}}],{width:334,className:"xl-dlg"})}function ke(r){const{book:a,grid:s}=r,e=a.gotoHistory??=[],n=h("select",{class:"dlg-list bk-goto-list",size:8,"aria-label":M("Go to")});for(const o of W(a))n.append(h("option",{value:o.label,textContent:o.label}));for(const o of e.slice().reverse())n.append(h("option",{value:o,textContent:o}));const i=h("input",{class:"dlg-input","aria-label":M("Reference"),spellcheck:!1,value:e[e.length-1]??""});n.addEventListener("change",()=>{i.value=n.value}),n.addEventListener("dblclick",()=>{t()&&c.close()});const t=()=>{const o=Z(a,s.selection);return P(r,i.value)?(e[e.length-1]!==o&&e.push(o),e.length>32&&e.shift(),!0):(i.select(),!1)};L();const c=D(r,A("dlg","Go To"),h("div",{class:"dlg-col"},h("div",{class:"dlg-label",textContent:M("Go to:")}),n,h("label",{class:"bk-above"},h("span",{textContent:M("Reference:")}),i)),[{label:"Special…",left:!0,action:()=>{queueMicrotask(()=>ie(r))}},{label:"Cancel"},{label:"OK",primary:!0,action:()=>t()}],{width:326,className:"xl-dlg"});i.focus(),i.select()}export{ie as goToSpecial,ke as openGoTo,ae as selectSpecial};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseRangeRef as o,rangeRef as l}from"../core/address.js";import{FORMULA as p}from"../core/sheet.js";const L="#0563C1",k="#954F72",m=(s,t,e)=>(s.ref??"").split(/\s+/).map(o).some(n=>n&&t>=n.r0&&t<=n.r1&&e>=n.c0&&e<=n.c1),A=(s,t,e)=>s.hyperlinks?.find(n=>m(n,t,e))??null;function O(s,t,e){const n=[];for(const i of s??[]){const c=(i.ref??"").split(/\s+/).filter(Boolean).map(o);if(!c.some(r=>r&&t>=r.r0&&t<=r.r1&&e>=r.c0&&e<=r.c1)){n.push(i);continue}const f=c.flatMap(r=>!r||t<r.r0||t>r.r1||e<r.c0||e>r.c1?r?[r]:[]:[{r0:r.r0,c0:r.c0,r1:t-1,c1:r.c1},{r0:t+1,c0:r.c0,r1:r.r1,c1:r.c1},{r0:t,c0:r.c0,r1:t,c1:e-1},{r0:t,c0:e+1,r1:t,c1:r.c1}].filter(a=>a.r0<=a.r1&&a.c0<=a.c1));for(const r of f)n.push({...i,ref:l(r)})}return n}const d=s=>/^[^\s@:]+@[^\s@:/]+\.[^\s@:/]+$/.test(s),u=s=>{const t=s.trim();return/^sjs:\/\//i.test(t)?{location:t.replace(/^sjs:\/\//i,"")}:/^[a-z][a-z0-9+.-]*:/i.test(t)?{target:t}:/^www\./i.test(t)?{target:`http://${t}`}:d(t)?{target:`mailto:${t}`}:/^(?:'[^']+'|[^!\s]+)!/.test(t)||o(t)?{location:t}:{target:t}};function $(s,t,e,n){if(!(t.kind(e,n)&p))return null;const i=s.editText(t,e,n),c=/^=\s*HYPERLINK\(\s*(?:"((?:[^"]|"")*)"|(\$?[A-Za-z]{1,3}\$?\d+))\s*[,)]/i.exec(i);if(!c)return null;if(c[1]!==void 0)return u(c[1].replace(/""/g,'"').replace(/^#/,""));const f=o(c[2]);if(!f)return null;const r=s.editText(t,f.r0,f.c0);return r?u(r.replace(/^#/,"")):null}export{L as LINK_COLOR,k as VISITED_COLOR,$ as formulaLink,d as isEmailAddress,A as linkAt,O as linksWithoutCell,u as normalizeAddress};
|
package/cells/outline-column.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{maxOutlineLevel as ft,outlineLevel as M}from"../core/whatif.js";import{MAX_COLS as X,MAX_ROWS as $}from"../core/address.js";import{registerSection as Q}from"./sections.js";const z=14,j=new WeakMap;function x(t,e){const o=e==="row"?t.rowExtras:t.colExtras;if(o===null)return 0;let l=j.get(t);l===void 0&&(l={},j.set(t,l));let r=l[e];if((r===void 0||r.map!==o||r.version!==(t.outlineVersion??0)||r.size>o.size)&&(r={map:o,version:t.outlineVersion??0,size:0,it:o.values(),max:0},l[e]=r),r.size!==o.size)for(;;){const n=r.it.next();if(n.done)break;r.size++;const i=n.value.indexOf('outlineLevel="');i>=0&&(r.max=Math.max(r.max,Number(n.value.charCodeAt(i+14)-48)))}return r.max}function bt(t,e){const o=t.rows.count,l=t.cols.count;return o===$&&l===X||e.row<o&&e.col<l?e:{...e,row:Math.min(e.row,o-1),col:Math.min(e.col,l-1),ranges:e.ranges.map(r=>({...r,r0:Math.min(r.r0,o-1),c0:Math.min(r.c0,l-1),r1:r.r1===$-1?r.r1:Math.min(r.r1,o-1),c1:r.c1===X-1?r.c1:Math.min(r.c1,l-1)}))}}const tt=t=>{t.outlineVersion=(t.outlineVersion??0)+1};function Mt(t,e){const o=x(t,e);return o===0?0:(o+1)*z+4}const E=(t,e)=>e==="row"?t.summaryAbove===!0:t.summaryLeft===!0;function et(t,e,o,l){const r=e==="row"?t.rows:t.cols,n=[],i=[],c=(w,f)=>{for(;i.length>=w;){const a=i.pop();a.end=f,n.push(a)}};let m=o;const d=Math.max(0,o-2e4);for(;m>d&&M(t,e,m-1)>0;)m--;const u=Math.min(r.count-1,l+2e4);let p=m;for(;p<=u;p++){const w=M(t,e,p);for(w<i.length&&c(w+1,p-1);i.length<w;)i.push({level:i.length+1,start:p,end:-1});if(w===0&&p>l)break}return c(1,p-1),n.filter(w=>w.end>=o-1&&w.start<=l+1)}function yt(t,e){const{sheet:o,dpr:l,theme:r}=e,n=h=>Math.round(h*l),i=e.gutterW,c=e.gutterH,m=e.rowHeaderW,d=e.colHeaderH,u=e.book.outlineStyle,p=u?.ink??r.headerInk,w=u?.bg??r.headerBg,f=u?.button??w,a=u?.line??p;t.fillStyle=w,i>0&&t.fillRect(0,0,n(i),n(e.cssH)),c>0&&t.fillRect(0,0,n(e.cssW),n(c));const s=11,C=(h,v,y)=>{t.fillStyle=f,t.strokeStyle=a,t.lineWidth=Math.max(1,Math.round(l/2)),t.fillRect(n(h),n(v),n(s),n(s)),t.strokeRect(n(h)+.5,n(v)+.5,n(s)-1,n(s)-1),t.fillStyle=p;const g=u&&(y==="+"?u.plusImage:y==="-"?u.minusImage:null),R=g?Z(e,g):null;R?t.drawImage(R,n(h),n(v),n(s),n(s)):y==="+"||y==="-"?(t.fillRect(n(h+2.5),n(v+s/2)-.5,n(s-5),Math.max(1,Math.round(l))),y==="+"&&t.fillRect(n(h+s/2)-.5,n(v+2.5),Math.max(1,Math.round(l)),n(s-5))):(t.font=`${n(9)}px -apple-system, "Helvetica Neue", Arial, sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(y,n(h+s/2),n(v+s/2)+.5))},S=h=>{const v=h==="row",y=x(o,h)+1;for(let k=0;k<y;k++)v?C(2+k*z,Math.max(0,d-14),String(k+1)):C(Math.max(0,m-14),2+k*z,String(k+1));const g=v?o.rows:e.displayCols,R=v?e.cssH-d:e.cssW-m,q=v?e.scrollY:e.scrollX,_=v?o.frozenRows:o.frozenCols,J=_?g.offsetOf(_):0,F=Math.max(g.indexAt(q+J),_),V=g.indexAt(q+J+R/e.zoom);t.save(),t.beginPath(),v?t.rect(0,n(d),n(i),n(R)):t.rect(n(m),0,n(R),n(c)),t.clip();const P=k=>{const b=v?e.cellRect(k,0):e.cellRect(0,k);return v?{at:b.y,size:b.h}:{at:b.x,size:b.w}},L=Math.max(1,Math.round((u?.lineWidth??1)*l));if(V-F<2e3){t.fillStyle=u?.dot??p;const k=Math.max(1,Math.round(l*1.5));for(let b=F;b<=V;b++){const I=M(o,h,b);if(I===0||g.isHidden(b))continue;const H=P(b),W=I*z+2+s/2;v?t.fillRect(n(W)-.5,n(H.at+H.size/2)-.5,k,k):t.fillRect(n(H.at+H.size/2)-.5,n(W)-.5,k,k)}}for(const k of et(o,h,F,V)){const b=(k.level-1)*z+2,I=E(o,h)?k.start-1:k.end+1,H=P(k.start).at,W=P(k.end).at+P(k.end).size,B=g.isHidden(k.start)&&g.isHidden(k.end);if(t.fillStyle=a,!B){const A=E(o,h)?W:H;v?(t.fillRect(n(b+s/2)-.5,n(H),L,n(W-H)),t.fillRect(n(b+s/2)-.5,n(A)-(E(o,h)?L:0),n(s/2),L)):(t.fillRect(n(H),n(b+s/2)-.5,n(W-H),L),t.fillRect(n(A)-(E(o,h)?L:0),n(b+s/2)-.5,L,n(s/2)))}if(I>=0&&I<g.count){const A=P(I);v?C(b,A.at+(A.size-s)/2,B?"+":"-"):C(A.at+(A.size-s)/2,b,B?"+":"-")}}t.restore()};i>0&&S("row"),c>0&&S("col")}function Ct(t,e,o){const{sheet:l}=t,r=t.gutterW,n=t.gutterH,i=t.rowHeaderW,c=t.colHeaderH,m=(u,p)=>{const w=Math.floor((p-2)/z)+1;return w>=1&&w<=x(l,u)+1?{kind:"level",axis:u,level:w}:null};if(r>0&&e<r&&o>=c-16&&o<c)return m("row",e);if(n>0&&o<n&&e>=i-16&&e<i)return m("col",o);const d=(u,p,w)=>{const{row:f,col:a}=u==="row"?t.hitCell(i,p):t.hitCell(p,c),s=u==="row"?f:a;for(const C of et(l,u,s-1,s+1)){const S=E(l,u)?C.start-1:C.end+1,h=(C.level-1)*z+2;if(S===s&&w>=h&&w<h+z)return{kind:"toggle",axis:u,group:C}}return null};return r>0&&e<r&&o>=c?d("row",o,e):n>0&&o<n&&e>=i?d("col",e,o):null}function gt(t,e){const{sheet:o}=t.book;return U(t,"outline",()=>{e.kind==="level"?st(o,e.axis,e.level):mt(o,e.axis,e.group)})}const ot=t=>new Map(t.hiddenSizes??[]);function nt(t){const e={rowExtras:t.rowExtras?new Map(t.rowExtras):null,colExtras:t.colExtras?new Map(t.colExtras):null,rows:ot(t.rows),cols:ot(t.cols),summaryAbove:t.summaryAbove,summaryLeft:t.summaryLeft,autoStyles:t.outlineAutoStyles,outlineColumn:t.outlineColumn};return()=>{const o=nt(t);for(const[l,r]of[[t.rows,e.rows],[t.cols,e.cols]]){if(l.hiddenSizes)for(const n of[...l.hiddenSizes.keys()])r.has(n)||l.setHidden(n,!1);for(const n of r.keys())l.setHidden(n,!0)}return Object.assign(t,{rowExtras:e.rowExtras,colExtras:e.colExtras,summaryAbove:e.summaryAbove,summaryLeft:e.summaryLeft,outlineAutoStyles:e.autoStyles,outlineColumn:e.outlineColumn}),tt(t),t.colsChanged=!0,t.revision++,o}}function U(t,e,o){const{book:l,grid:r}=t,n=l.sheet;return n.protection&&!n.protectionExtras?.outline?(l.guard?.("outline"),!1):(l.transact(n.protection?"outline":e,()=>{const i=nt(n);return o(),tt(n),n.colsChanged=!0,n.revision++,i}),l.dirty=!0,t.objects?.geometryChanged?.(),r.invalidate(),!0)}const D=(t,e)=>e==="row"?t.rowExtras:t.colExtras,O=(t,e)=>e==="row"?t.rows:t.cols,lt=/\s*collapsed="[^"]*"/;function dt(t,e,o){const l=D(t,e)?.get(o);return l!==void 0&&/collapsed="(1|true)"/.test(l)}function K(t,e,o,l){if(o<0)return;e==="row"&&!t.rowExtras&&(t.rowExtras=new Map),e==="col"&&!t.colExtras&&(t.colExtras=new Map);const r=D(t,e),n=(r.get(o)??"").replace(lt,"").trim(),i=l?`${n} collapsed="1"`.trim():n;i?r.set(o,i):r.delete(o)}const Y=(t,e,o)=>E(t,e)?o.start-1:o.end+1,rt=(t,e,o)=>e==="row"&&t.filteredRows?.has(o)===!0;function it(t,e,o,l,r){const n=O(t,e);let i=o;for(;i<=l;){if(M(t,e,i)<=r){rt(t,e,i)||n.setHidden(i,!1),i++;continue}let c=i;for(;c<l&&M(t,e,c+1)>r;)c++;dt(t,e,Y(t,e,{start:i,end:c}))||it(t,e,i,c,r+1),i=c+1}}function ct(t,e,o,l){const r=O(t,e);if(K(t,e,Y(t,e,o),l),l)for(let n=o.start;n<=o.end;n++)r.setHidden(n,!0);else it(t,e,o.start,o.end,o.level);e==="col"&&(t.colsChanged=!0)}function mt(t,e,o){const l=O(t,e);ct(t,e,o,!(l.isHidden(o.start)&&l.isHidden(o.end)))}function st(t,e,o){const l=D(t,e);if(!l)return;const r=O(t,e),n=[...l.keys()].filter(d=>M(t,e,d)>0).sort((d,u)=>d-u);for(const d of n)M(t,e,d)>=o?r.setHidden(d,!0):rt(t,e,d)||r.setHidden(d,!1);for(const d of[...l.keys()])lt.test(l.get(d))&&K(t,e,d,!1);const i=[],c=(d,u)=>{for(;i.length>d;){const p=i.pop();i.length+1>=o&&K(t,e,Y(t,e,{start:p,end:u}),!0)}};let m=-2;for(const d of n){d!==m+1&&c(0,m);const u=M(t,e,d);for(c(u,d-1);i.length<u;)i.push(d);m=d}c(0,m),e==="col"&&(t.colsChanged=!0)}function Ht(t,e,o){const l=[],r=O(t,e);for(let n=M(t,e,o);n>=1;n--){let i=o;for(;i>0&&M(t,e,i-1)>=n;)i--;let c=o;for(;c<r.count-1&&M(t,e,c+1)>=n;)c++;l.push({level:n,start:i,end:c})}return l}function St(t,e,o){const r=E(t,e)?o+1:o-1;if(r<0)return null;const n=M(t,e,o)+1;if(M(t,e,r)<n)return null;let i=r,c=r;const m=O(t,e);for(;i>0&&M(t,e,i-1)>=n;)i--;for(;c<m.count-1&&M(t,e,c+1)>=n;)c++;return{level:n,start:i,end:c}}const N=14,T=(t,e,o,l)=>{const r=t.book.styles.get(e.style(o,l)).indent??0,n=e.outlineColumn?.maxLevel;return n===void 0?r:Math.min(r,n)};function ut(t,e,o,l){return(e.kind(o+1,l)&15)!==0&&T(t,e,o+1,l)>T(t,e,o,l)}const at=new Map,pt=/^data:image\/(png|jpeg|gif|webp);base64,[A-Za-z0-9+/=]+$/,wt=7e5,G=t=>typeof t=="string"&&t.length<=wt&&pt.test(t);function Z(t,e){if(!e)return null;let o=at.get(e);return o===void 0&&(o=new Image,o.onload=()=>t.invalidate(),o.src=e,at.set(e,o)),o.complete&&o.naturalWidth>0?o:null}function zt(t,e,o,l,r,n,i,c){const{sheet:m,theme:d}=e,u=m.outlineColumn,p=T(e,m,o,l),w=Math.round(p*9*c);let f=r+w;const a=Math.round(10*c),s=n+i/2,C=d.cellInk??"#000000",S=u.indicator!==!1&&ut(e,m,o,l),h=S&&m.rows.isHidden(o+1),v=S?Z(e,h?u.indicatorImages?.collapsed:u.indicatorImages?.expanded):null;if(v?t.drawImage(v,f,s-a/2,a,a):S&&(t.fillStyle=C,t.beginPath(),h?(t.moveTo(f+a*.3,s-a*.35),t.lineTo(f+a*.8,s),t.lineTo(f+a*.3,s+a*.35)):(t.moveTo(f+a*.15,s-a*.2),t.lineTo(f+a*.85,s-a*.2),t.lineTo(f+a*.5,s+a*.3)),t.closePath(),t.fill()),f+=Math.round(N*c),u.checkbox){const y=u.checks?.[o]===!0;t.strokeStyle=C,t.lineWidth=Math.max(1,Math.round(c/2)),t.strokeRect(f+.5,s-a/2+.5,a-1,a-1),y&&(t.beginPath(),t.moveTo(f+a*.2,s),t.lineTo(f+a*.42,s+a*.25),t.lineTo(f+a*.82,s-a*.28),t.stroke()),f+=Math.round(N*c)}if(u.images?.length>0){const y=Z(e,u.images[Math.min(p,u.images.length-1)]);y&&t.drawImage(y,f,s-a/2,a,a),f+=Math.round(N*c)}return e._ink=null,f-r-w}function At(t,e,o,l){const{book:r,grid:n}=t,i=r.sheet,c=i.outlineColumn;if(c===null||c.col!==o)return!1;const m=n.cellRect(e,o),d=T(n,i,e,o),u=m.x+2+d*9*n.zoom,p=N*n.zoom,w=f=>f<=i.maxRow&&T(n,i,f,o)>d&&(i.kind(f,o)&15)!==0;return c.indicator!==!1&&l>=u-2&&l<u+p&&ut(n,i,e,o)?U(t,"outline",()=>{const f=!i.rows.isHidden(e+1);for(let a=e+1;w(a);a++)f?i.rows.setHidden(a,!0):T(n,i,a,o)===d+1&&i.rows.setHidden(a,!1)}):c.checkbox&&l>=u+p&&l<u+p*2?U(t,"outline",()=>{const f={...c.checks??{}},a=!f[e];a?f[e]=!0:delete f[e];for(let s=e+1;w(s);s++)a?f[s]=!0:delete f[s];i.outlineColumn={...c,checks:f}}):!1}Q("outlineColumn",{sheet:{save(t){return t.outlineColumn===null?void 0:t.outlineColumn},load(t,e){if(!e||!Number.isInteger(e.col)||e.col<0||e.col>=X)return;const o={};if(e.checks&&typeof e.checks=="object")for(const[r,n]of Object.entries(e.checks))Number(r)>=0&&Number(r)<$&&n===!0&&(o[r]=!0);if(t.outlineColumn={col:e.col,checkbox:e.checkbox===!0,indicator:e.indicator!==!1,checks:o},Number.isInteger(e.maxLevel)&&e.maxLevel>=0&&(t.outlineColumn.maxLevel=e.maxLevel),Array.isArray(e.images)){const r=e.images.filter(G).slice(0,16);r.length>0&&(t.outlineColumn.images=r)}const l=e.indicatorImages;if(l&&typeof l=="object"){const r={};G(l.expanded)&&(r.expanded=l.expanded),G(l.collapsed)&&(r.collapsed=l.collapsed),(r.expanded||r.collapsed)&&(t.outlineColumn.indicatorImages=r)}}}}),Q("outlineStyle",{book:{save(t){return t.outlineStyle??void 0},load(t,e){if(!e||typeof e!="object")return;const o={};for(const l of["bg","ink","button","line","dot"])typeof e[l]=="string"&&/^#[0-9a-fA-F]{6}$/.test(e[l])&&(o[l]=e[l]);Number.isFinite(e.lineWidth)&&e.lineWidth>=1&&e.lineWidth<=6&&(o.lineWidth=e.lineWidth);for(const l of["plusImage","minusImage"])G(e[l])&&(o[l]=e[l]);t.outlineStyle=Object.keys(o).length>0?o:null}}});export{bt as clampToSheet,St as groupOfMark,Ht as groupsAt,ft as maxOutlineLevel,tt as outlineChanged,At as outlineColumnClick,Mt as outlineGutterSize,Ct as outlineHit,U as outlineStep,zt as paintOutlineColumnMark,yt as paintOutlineGutter,gt as runOutlineHit,K as setFlag,ct as setGroupCollapsed,st as showLevel};
|
|
1
|
+
import{maxOutlineLevel as ft,outlineLevel as M}from"../core/whatif.js";import{MAX_COLS as B,MAX_ROWS as X}from"../core/address.js";import{registerSection as Q}from"./sections.js";const z=14,j=new WeakMap;function $(t,e){const n=e==="row"?t.rowExtras:t.colExtras;if(n===null)return 0;let l=j.get(t);l===void 0&&(l={},j.set(t,l));let r=l[e];if((r===void 0||r.map!==n||r.version!==(t.outlineVersion??0)||r.size>n.size)&&(r={map:n,version:t.outlineVersion??0,size:0,it:n.values(),max:0},l[e]=r),r.size!==n.size)for(;;){const o=r.it.next();if(o.done)break;r.size++;const i=o.value.indexOf('outlineLevel="');i>=0&&(r.max=Math.max(r.max,Number(o.value.charCodeAt(i+14)-48)))}return r.max}function Mt(t,e){const n=t.rows.count,l=t.cols.count;return n===X&&l===B||e.row<n&&e.col<l?e:{...e,row:Math.min(e.row,n-1),col:Math.min(e.col,l-1),ranges:e.ranges.map(r=>({...r,r0:Math.min(r.r0,n-1),c0:Math.min(r.c0,l-1),r1:r.r1===X-1?r.r1:Math.min(r.r1,n-1),c1:r.c1===B-1?r.c1:Math.min(r.c1,l-1)}))}}const tt=t=>{t.outlineVersion=(t.outlineVersion??0)+1};function yt(t,e){const n=$(t,e);return n===0?0:(n+1)*z+4}const E=(t,e)=>e==="row"?t.summaryAbove===!0:t.summaryLeft===!0;function et(t,e,n,l){const r=e==="row"?t.rows:t.cols,o=[],i=[],s=(p,k)=>{for(;i.length>=p;){const f=i.pop();f.end=k,o.push(f)}};let d=n;const a=Math.max(0,n-2e4);for(;d>a&&M(t,e,d-1)>0;)d--;const c=Math.min(r.count-1,l+2e4);let m=d;for(;m<=c;m++){const p=M(t,e,m);for(p<i.length&&s(p+1,m-1);i.length<p;)i.push({level:i.length+1,start:m,end:-1});if(p===0&&m>l)break}return s(1,m-1),o.filter(p=>p.end>=n-1&&p.start<=l+1)}function Ct(t,e){const{sheet:n,dpr:l,theme:r}=e,o=w=>Math.round(w*l),i=e.gutterW,s=e.gutterH,d=e.rowHeaderW,a=e.colHeaderH,c=e.book.outlineStyle,m=c?.ink??r.headerInk,p=c?.bg??r.headerBg,k=c?.button??p,f=c?.line??m;t.fillStyle=p,i>0&&t.fillRect(0,0,o(i),o(e.cssH)),s>0&&t.fillRect(0,0,o(e.cssW),o(s));const u=11,C=(w,v,y)=>{t.fillStyle=k,t.strokeStyle=f,t.lineWidth=Math.max(1,Math.round(l/2)),t.fillRect(o(w),o(v),o(u),o(u)),t.strokeRect(o(w)+.5,o(v)+.5,o(u)-1,o(u)-1),t.fillStyle=m;const H=c&&(y==="+"?c.plusImage:y==="-"?c.minusImage:null),L=H?Z(e,H):null;L?t.drawImage(L,o(w),o(v),o(u),o(u)):y==="+"||y==="-"?(t.fillRect(o(w+2.5),o(v+u/2)-.5,o(u-5),Math.max(1,Math.round(l))),y==="+"&&t.fillRect(o(w+u/2)-.5,o(v+2.5),Math.max(1,Math.round(l)),o(u-5))):(t.font=`${o(9)}px -apple-system, "Helvetica Neue", Arial, sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(y,o(w+u/2),o(v+u/2)+.5))},S=w=>{const v=w==="row",y=$(n,w)+1;for(let h=0;h<y;h++)v?C(2+h*z,Math.max(0,a-14),String(h+1)):C(Math.max(0,d-14),2+h*z,String(h+1));const H=v?n.rows:e.displayCols,L=v?e.cssH-a:e.cssW-d,q=v?e.scrollY:e.scrollX,_=v?n.frozenRows:n.frozenCols,J=_?H.offsetOf(_):0,x=Math.max(H.indexAt(q+J),_),F=H.indexAt(q+J+L/e.zoom);t.save(),t.beginPath(),v?t.rect(0,o(a),o(i),o(L)):t.rect(o(d),0,o(L),o(s)),t.clip();const P=h=>{const b=v?e.cellRect(h,0):e.cellRect(0,h);return v?{at:b.y,size:b.h}:{at:b.x,size:b.w}},I=Math.max(1,Math.round((c?.lineWidth??1)*l));if(F-x<2e3){t.fillStyle=c?.dot??m;const h=Math.max(1,Math.round(l*1.5));for(let b=x;b<=F;b++){const W=M(n,w,b);if(W===0||H.isHidden(b))continue;const g=P(b),O=W*z+2+u/2;v?t.fillRect(o(O)-.5,o(g.at+g.size/2)-.5,h,h):t.fillRect(o(g.at+g.size/2)-.5,o(O)-.5,h,h)}}for(const h of et(n,w,x,F)){const b=(h.level-1)*z+2,W=E(n,w)?h.start-1:h.end+1,g=P(h.start).at,O=P(h.end).at+P(h.end).size,V=H.isHidden(h.start)&&H.isHidden(h.end);if(t.fillStyle=f,!V){const A=E(n,w)?O:g;v?(t.fillRect(o(b+u/2)-.5,o(g),I,o(O-g)),t.fillRect(o(b+u/2)-.5,o(A)-(E(n,w)?I:0),o(u/2),I)):(t.fillRect(o(g),o(b+u/2)-.5,o(O-g),I),t.fillRect(o(A)-(E(n,w)?I:0),o(b+u/2)-.5,I,o(u/2)))}if(W>=0&&W<H.count){const A=P(W);v?C(b,A.at+(A.size-u)/2,V?"+":"-"):C(A.at+(A.size-u)/2,b,V?"+":"-")}}t.restore()};i>0&&S("row"),s>0&&S("col")}function Ht(t,e,n){const{sheet:l}=t,r=t.gutterW,o=t.gutterH,i=t.rowHeaderW,s=t.colHeaderH,d=(c,m)=>{const p=Math.floor((m-2)/z)+1;return p>=1&&p<=$(l,c)+1?{kind:"level",axis:c,level:p}:null};if(r>0&&e<r&&n>=s-16&&n<s)return d("row",e);if(o>0&&n<o&&e>=i-16&&e<i)return d("col",n);const a=(c,m,p)=>{const{row:k,col:f}=c==="row"?t.hitCell(i,m):t.hitCell(m,s),u=c==="row"?k:f;for(const C of et(l,c,u-1,u+1)){const S=E(l,c)?C.start-1:C.end+1,w=(C.level-1)*z+2;if(S===u&&p>=w&&p<w+z)return{kind:"toggle",axis:c,group:C}}return null};return r>0&&e<r&&n>=s?a("row",n,e):o>0&&n<o&&e>=i?a("col",e,n):null}function gt(t,e){const{sheet:n}=t.book;return U(t,"outline",()=>{e.kind==="level"?st(n,e.axis,e.level):mt(n,e.axis,e.group)})}const nt=t=>new Map(t.hiddenSizes??[]);function ot(t){const e={rowExtras:t.rowExtras?new Map(t.rowExtras):null,colExtras:t.colExtras?new Map(t.colExtras):null,rows:nt(t.rows),cols:nt(t.cols),summaryAbove:t.summaryAbove,summaryLeft:t.summaryLeft,autoStyles:t.outlineAutoStyles,outlineColumn:t.outlineColumn};return()=>{const n=ot(t);for(const[l,r]of[[t.rows,e.rows],[t.cols,e.cols]]){if(l.hiddenSizes)for(const o of[...l.hiddenSizes.keys()])r.has(o)||l.setHidden(o,!1);for(const o of r.keys())l.setHidden(o,!0)}return Object.assign(t,{rowExtras:e.rowExtras,colExtras:e.colExtras,summaryAbove:e.summaryAbove,summaryLeft:e.summaryLeft,outlineAutoStyles:e.autoStyles,outlineColumn:e.outlineColumn}),tt(t),t.colsChanged=!0,t.revision++,n}}function U(t,e,n){const{book:l,grid:r}=t,o=l.sheet;return o.protection&&!o.protectionExtras?.outline?(l.guard?.("outline"),!1):(l.transact(o.protection?"outline":e,()=>{const i=ot(o);return n(),tt(o),o.colsChanged=!0,o.revision++,i}),l.dirty=!0,t.objects?.geometryChanged?.(),r.invalidate(),!0)}const D=(t,e)=>e==="row"?t.rowExtras:t.colExtras,T=(t,e)=>e==="row"?t.rows:t.cols,lt=/\s*collapsed="[^"]*"/;function dt(t,e,n){const l=D(t,e)?.get(n);return l!==void 0&&/collapsed="(1|true)"/.test(l)}function K(t,e,n,l){if(n<0)return;e==="row"&&!t.rowExtras&&(t.rowExtras=new Map),e==="col"&&!t.colExtras&&(t.colExtras=new Map);const r=D(t,e),o=(r.get(n)??"").replace(lt,"").trim(),i=l?`${o} collapsed="1"`.trim():o;i?r.set(n,i):r.delete(n)}const Y=(t,e,n)=>E(t,e)?n.start-1:n.end+1,rt=(t,e,n)=>e==="row"&&t.filteredRows?.has(n)===!0;function it(t,e,n,l,r){const o=T(t,e);let i=n;for(;i<=l;){if(M(t,e,i)<=r){rt(t,e,i)||o.setHidden(i,!1),i++;continue}let s=i;for(;s<l&&M(t,e,s+1)>r;)s++;dt(t,e,Y(t,e,{start:i,end:s}))||it(t,e,i,s,r+1),i=s+1}}function ct(t,e,n,l){const r=T(t,e);if(K(t,e,Y(t,e,n),l),l)for(let o=n.start;o<=n.end;o++)r.setHidden(o,!0);else it(t,e,n.start,n.end,n.level);e==="col"&&(t.colsChanged=!0)}function mt(t,e,n){const l=T(t,e);ct(t,e,n,!(l.isHidden(n.start)&&l.isHidden(n.end)))}function st(t,e,n){const l=D(t,e);if(!l)return;const r=T(t,e),o=[...l.keys()].filter(a=>M(t,e,a)>0).sort((a,c)=>a-c);for(const a of o)M(t,e,a)>=n?r.setHidden(a,!0):rt(t,e,a)||r.setHidden(a,!1);for(const a of[...l.keys()])lt.test(l.get(a))&&K(t,e,a,!1);const i=[],s=(a,c)=>{for(;i.length>a;){const m=i.pop();i.length+1>=n&&K(t,e,Y(t,e,{start:m,end:c}),!0)}};let d=-2;for(const a of o){a!==d+1&&s(0,d);const c=M(t,e,a);for(s(c,a-1);i.length<c;)i.push(a);d=a}s(0,d),e==="col"&&(t.colsChanged=!0)}function St(t,e,n){const l=[],r=T(t,e);for(let o=M(t,e,n);o>=1;o--){let i=n;for(;i>0&&M(t,e,i-1)>=o;)i--;let s=n;for(;s<r.count-1&&M(t,e,s+1)>=o;)s++;l.push({level:o,start:i,end:s})}return l}function zt(t,e,n){const r=E(t,e)?n+1:n-1;if(r<0)return null;const o=M(t,e,n)+1;if(M(t,e,r)<o)return null;let i=r,s=r;const d=T(t,e);for(;i>0&&M(t,e,i-1)>=o;)i--;for(;s<d.count-1&&M(t,e,s+1)>=o;)s++;return{level:o,start:i,end:s}}const N=14,R=(t,e,n,l)=>{const r=t.book.styles.get(e.style(n,l)).indent??0,o=e.outlineColumn?.maxLevel;return o===void 0?r:Math.min(r,o)};function ut(t,e,n,l){return(e.kind(n+1,l)&15)!==0&&R(t,e,n+1,l)>R(t,e,n,l)}const at=new Map,pt=/^data:image\/(png|jpeg|gif|webp);base64,[A-Za-z0-9+/=]+$/,wt=7e5,G=t=>typeof t=="string"&&t.length<=wt&&pt.test(t);function Z(t,e){if(!e)return null;let n=at.get(e);return n===void 0&&(n=new Image,n.onload=()=>t.invalidate(),n.src=e,at.set(e,n)),n.complete&&n.naturalWidth>0?n:null}function At(t,e,n,l,r,o,i,s){const{sheet:d,theme:a}=e,c=d.outlineColumn,m=R(e,d,n,l),p=Math.round(m*9*s);let k=r+p;const f=Math.round(10*s),u=o+i/2,C=a.cellInk??"#000000",S=c.indicator!==!1&&ut(e,d,n,l),w=S&&d.rows.isHidden(n+1),v=S?Z(e,w?c.indicatorImages?.collapsed:c.indicatorImages?.expanded):null;if(v?t.drawImage(v,k,u-f/2,f,f):S&&(t.fillStyle=C,t.beginPath(),w?(t.moveTo(k+f*.3,u-f*.35),t.lineTo(k+f*.8,u),t.lineTo(k+f*.3,u+f*.35)):(t.moveTo(k+f*.15,u-f*.2),t.lineTo(k+f*.85,u-f*.2),t.lineTo(k+f*.5,u+f*.3)),t.closePath(),t.fill()),k+=Math.round(N*s),c.checkbox){const y=c.checks?.[n]===!0;t.strokeStyle=C,t.lineWidth=Math.max(1,Math.round(s/2)),t.strokeRect(k+.5,u-f/2+.5,f-1,f-1),y&&(t.beginPath(),t.moveTo(k+f*.2,u),t.lineTo(k+f*.42,u+f*.25),t.lineTo(k+f*.82,u-f*.28),t.stroke()),k+=Math.round(N*s)}if(c.images?.length>0){const y=Z(e,c.images[Math.min(m,c.images.length-1)]);y&&t.drawImage(y,k,u-f/2,f,f),k+=Math.round(N*s)}return e._ink=null,k-r-p}function ht(t,e,n,l){const r=t.sheet,o=r.outlineColumn;if(!o||o.col!==n)return null;const i=t.cellRect(e,n),s=R(t,r,e,n),d=i.x+2+s*9*t.zoom,a=N*t.zoom;return o.indicator!==!1&&l>=d-2&&l<d+a&&ut(t,r,e,n)?"toggle":o.checkbox&&l>=d+a&&l<d+a*2?"checkbox":null}function Et(t,e,n,l){const{grid:r}=t,o=r.sheet,i=o.outlineColumn,s=ht(r,e,n,l);if(!s)return!1;const d=R(r,o,e,n),a=c=>c<=o.maxRow&&R(r,o,c,n)>d&&(o.kind(c,n)&15)!==0;return s==="toggle"?U(t,"outline",()=>{const c=!o.rows.isHidden(e+1);for(let m=e+1;a(m);m++)c?o.rows.setHidden(m,!0):R(r,o,m,n)===d+1&&o.rows.setHidden(m,!1)}):s==="checkbox"?U(t,"outline",()=>{const c={...i.checks??{}},m=!c[e];m?c[e]=!0:delete c[e];for(let p=e+1;a(p);p++)m?c[p]=!0:delete c[p];o.outlineColumn={...i,checks:c}}):!1}Q("outlineColumn",{sheet:{save(t){return t.outlineColumn===null?void 0:t.outlineColumn},load(t,e){if(!e||!Number.isInteger(e.col)||e.col<0||e.col>=B)return;const n={};if(e.checks&&typeof e.checks=="object")for(const[r,o]of Object.entries(e.checks))Number(r)>=0&&Number(r)<X&&o===!0&&(n[r]=!0);if(t.outlineColumn={col:e.col,checkbox:e.checkbox===!0,indicator:e.indicator!==!1,checks:n},Number.isInteger(e.maxLevel)&&e.maxLevel>=0&&(t.outlineColumn.maxLevel=e.maxLevel),Array.isArray(e.images)){const r=e.images.filter(G).slice(0,16);r.length>0&&(t.outlineColumn.images=r)}const l=e.indicatorImages;if(l&&typeof l=="object"){const r={};G(l.expanded)&&(r.expanded=l.expanded),G(l.collapsed)&&(r.collapsed=l.collapsed),(r.expanded||r.collapsed)&&(t.outlineColumn.indicatorImages=r)}}}}),Q("outlineStyle",{book:{save(t){return t.outlineStyle??void 0},load(t,e){if(!e||typeof e!="object")return;const n={};for(const l of["bg","ink","button","line","dot"])typeof e[l]=="string"&&/^#[0-9a-fA-F]{6}$/.test(e[l])&&(n[l]=e[l]);Number.isFinite(e.lineWidth)&&e.lineWidth>=1&&e.lineWidth<=6&&(n.lineWidth=e.lineWidth);for(const l of["plusImage","minusImage"])G(e[l])&&(n[l]=e[l]);t.outlineStyle=Object.keys(n).length>0?n:null}}});export{Mt as clampToSheet,zt as groupOfMark,St as groupsAt,ft as maxOutlineLevel,tt as outlineChanged,Et as outlineColumnClick,ht as outlineColumnHit,yt as outlineGutterSize,Ht as outlineHit,U as outlineStep,At as paintOutlineColumnMark,Ct as paintOutlineGutter,gt as runOutlineHit,K as setFlag,ct as setGroupCollapsed,st as showLevel};
|
package/cells/panes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{registerSection as S}from"./sections.js";import{MAX_COLS as M,MAX_ROWS as b}from"../core/address.js";import{optionFor as w}from"./options.js";import{allows as H}from"../core/protection.js";function $(t){const{book:o,grid:e}=t,i=o.sheet;if(i.split){h(t);return}if(i.frozenRows||i.frozenCols||i.frozenTrailingRows||i.frozenTrailingCols){t.shell.setStatus("Panes can't be split while they're frozen. Unfreeze them first.");return}const{row:r,col:n}=e.selection,l=(e.cssW-e.rowHeaderW)/e.zoom,s=(e.cssH-e.colHeaderH)/e.zoom;let c=e.displayCols.offsetOf(n)-e.scrollX,a=i.rows.offsetOf(r)-e.scrollY;c<=0&&a<=0&&(c=l/2,a=s/2),c=c>0&&c<l?Math.round(c):0,a=a>0&&a<s?Math.round(a):0,i.split={x:c,y:a,scrollX:e.scrollX,scrollY:e.scrollY},i.viewChanged=!0,o.dirty=!0,e.invalidate()}function h(t){const{book:o,grid:e}=t,i=o.sheet;i.split&&(e.scrollX=i.split.scrollX,e.scrollY=i.split.scrollY,i.split=null,e.activeBand=null,i.viewChanged=!0,o.dirty=!0,e.invalidate())}function X(t,o,e){const{sheet:i,zoom:r}=t;if(!i.split)return null;const n=t.rowHeaderW,l=t.colHeaderH;return i.split.x>0&&Math.abs(o-n-i.split.x*r)<=4&&e>=l?{axis:"col"}:i.split.y>0&&Math.abs(e-l-i.split.y*r)<=4&&o>=n?{axis:"row"}:null}function k(t){const{sheet:o}=t,{split:e}=o,i=l=>{const s=/^([A-Z]+)(\d+)$/.exec(l??"");if(!s)return null;let c=0;for(const a of s[1])c=c*26+a.charCodeAt(0)-64;return{x:t.displayCols.offsetOf(c-1),y:o.rows.offsetOf(Number(s[2])-1)}},r=i(e.topLeft),n=i(e.firstTopLeft);e.topLeft=null,e.firstTopLeft=null,n&&(e.scrollX=n.x,e.scrollY=n.y),r&&(t.scrollX=Math.max(0,r.x-e.x),t.scrollY=Math.max(0,r.y-e.y),e.mainX=t.scrollX,e.mainY=t.scrollY)}function O(t,o,e,i){const{grid:r,book:n}=t,{sheet:l,zoom:s}=r,c=l.split;c&&(o==="col"?c.x=Math.max(0,Math.round((e-r.rowHeaderW)/s)):c.y=Math.max(0,Math.round((i-r.colHeaderH)/s)),c.x<=0&&c.y<=0&&(l.split=null),l.viewChanged=!0,n.dirty=!0,r.invalidate())}function v(t,o,e,i=!0){const{book:r,grid:n}=t,l=r.sheet;l.split&&h(t),l.frozenTrailingRows=Math.max(0,o),l.frozenTrailingCols=Math.max(0,e),l.trailingStick=i,r.dirty=!0,n.scrollTo(n.scrollX,n.scrollY),n.invalidate()}function Y(t){const o=String(t).trim().toLowerCase();return o==="auto"?"auto":/^\d*\.?\d*\*$/.test(o)?o==="*"?1:Number(o.slice(0,-1)):null}function y(t,o,e,i){t.axisSizing??={rows:new Map,cols:new Map};const r=o==="col"?t.axisSizing.cols:t.axisSizing.rows;i===null?r.delete(e):r.set(e,i),t.axisSizing.rows.size===0&&t.axisSizing.cols.size===0&&(t.axisSizing=null),t.sizingKey=null}function W(t,o,e){t.axisSizing!==
|
|
1
|
+
import{registerSection as S}from"./sections.js";import{MAX_COLS as M,MAX_ROWS as b}from"../core/address.js";import{optionFor as w}from"./options.js";import{allows as H}from"../core/protection.js";function $(t){const{book:o,grid:e}=t,i=o.sheet;if(i.split){h(t);return}if(i.frozenRows||i.frozenCols||i.frozenTrailingRows||i.frozenTrailingCols){t.shell.setStatus("Panes can't be split while they're frozen. Unfreeze them first.");return}const{row:r,col:n}=e.selection,l=(e.cssW-e.rowHeaderW)/e.zoom,s=(e.cssH-e.colHeaderH)/e.zoom;let c=e.displayCols.offsetOf(n)-e.scrollX,a=i.rows.offsetOf(r)-e.scrollY;c<=0&&a<=0&&(c=l/2,a=s/2),c=c>0&&c<l?Math.round(c):0,a=a>0&&a<s?Math.round(a):0,i.split={x:c,y:a,scrollX:e.scrollX,scrollY:e.scrollY},i.viewChanged=!0,o.dirty=!0,e.invalidate()}function h(t){const{book:o,grid:e}=t,i=o.sheet;i.split&&(e.scrollX=i.split.scrollX,e.scrollY=i.split.scrollY,i.split=null,e.activeBand=null,i.viewChanged=!0,o.dirty=!0,e.invalidate())}function X(t,o,e){const{sheet:i,zoom:r}=t;if(!i.split)return null;const n=t.rowHeaderW,l=t.colHeaderH;return i.split.x>0&&Math.abs(o-n-i.split.x*r)<=4&&e>=l?{axis:"col"}:i.split.y>0&&Math.abs(e-l-i.split.y*r)<=4&&o>=n?{axis:"row"}:null}function k(t){const{sheet:o}=t,{split:e}=o,i=l=>{const s=/^([A-Z]+)(\d+)$/.exec(l??"");if(!s)return null;let c=0;for(const a of s[1])c=c*26+a.charCodeAt(0)-64;return{x:t.displayCols.offsetOf(c-1),y:o.rows.offsetOf(Number(s[2])-1)}},r=i(e.topLeft),n=i(e.firstTopLeft);e.topLeft=null,e.firstTopLeft=null,n&&(e.scrollX=n.x,e.scrollY=n.y),r&&(t.scrollX=Math.max(0,r.x-e.x),t.scrollY=Math.max(0,r.y-e.y),e.mainX=t.scrollX,e.mainY=t.scrollY)}function O(t,o,e,i){const{grid:r,book:n}=t,{sheet:l,zoom:s}=r,c=l.split;c&&(o==="col"?c.x=Math.max(0,Math.round((e-r.rowHeaderW)/s)):c.y=Math.max(0,Math.round((i-r.colHeaderH)/s)),c.x<=0&&c.y<=0&&(l.split=null),l.viewChanged=!0,n.dirty=!0,r.invalidate())}function v(t,o,e,i=!0){const{book:r,grid:n}=t,l=r.sheet;l.split&&h(t),l.frozenTrailingRows=Math.max(0,o),l.frozenTrailingCols=Math.max(0,e),l.trailingStick=i,r.dirty=!0,n.scrollTo(n.scrollX,n.scrollY),n.invalidate()}function Y(t){const o=String(t).trim().toLowerCase();return o==="auto"?"auto":/^\d*\.?\d*\*$/.test(o)?o==="*"?1:Number(o.slice(0,-1)):null}function y(t,o,e,i){t.axisSizing??={rows:new Map,cols:new Map};const r=o==="col"?t.axisSizing.cols:t.axisSizing.rows;i===null?r.delete(e):r.set(e,i),t.axisSizing.rows.size===0&&t.axisSizing.cols.size===0&&(t.axisSizing=null),t.sizingKey=null}function W(t,o,e,i=null){const r=t.axisSizing?.[o==="col"?"cols":"rows"].get(e);r!==void 0&&(i&&(i.sizing??=[]).push([e,r]),y(t,o,e,null))}function L(t){const{sheet:o,zoom:e}=t,i=`${t.cssW}|${t.cssH}|${e}|${o.revision}|${o.rows.delta}|${o.cols.delta}`;if(o.sizingKey===i)return;const r=(n,l)=>{const s=n==="col"?o.cols:o.rows,c=(n==="col"?t.cssW-t.rowHeaderW:t.cssH-t.colHeaderH)/e;let a=n==="col"?o.maxCol:o.maxRow,u=0,z=0;for(const[f,p]of l)f>a&&(a=f),p==="auto"?t.onAutoSize?.(n,f):s.isHidden(f)||(u+=p,z+=s.sizeOf(f));if(u===0)return;const g=c-(s.offsetOf(a+1)-z);if(g<1)return;let d=!1;for(const[f,p]of l){if(p==="auto"||s.isHidden(f))continue;const m=Math.floor(g*p/u);s.sizeOf(f)!==m&&(s.setSize(f,m),d=!0)}d&&n==="col"&&(o.colsChanged=!0)};r("col",o.axisSizing.cols),r("row",o.axisSizing.rows),o.sizingKey=`${t.cssW}|${t.cssH}|${e}|${o.revision}|${o.rows.delta}|${o.cols.delta}`}S("layout",{sheet:{save(t){const o={};return t.frozenTrailingRows&&(o.trailRows=t.frozenTrailingRows),t.frozenTrailingCols&&(o.trailCols=t.frozenTrailingCols),t.trailingStick===!1&&(o.stick=!1),t.axisSizing&&(o.cols=[...t.axisSizing.cols],o.rows=[...t.axisSizing.rows]),Object.keys(o).length?o:void 0},load(t,o){if(!o||typeof o!="object")return;const e=(r,n)=>Number.isInteger(r)&&r>0&&r<n?r:0;t.frozenTrailingRows=e(o.trailRows,1e3),t.frozenTrailingCols=e(o.trailCols,1e3),o.stick===!1&&(t.trailingStick=!1);const i=(r,n,l)=>{if(Array.isArray(n))for(const s of n.slice(0,1e4))!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||s[0]>=l||(s[1]==="auto"||typeof s[1]=="number"&&s[1]>0)&&y(t,r,s[0],s[1])};i("col",o.cols,M),i("row",o.rows,b)}}});function I(t,o,e){return e.ctrlKey===!0||e.altKey===!0||(o==="col"?t.columnResizeMode:t.rowResizeMode)==="split"}function K(t,o){for(let e=o+1;e<t.count;e++)if(t.sizeOf(e)>0)return e;return-1}function N(t,o,e,i,r,n){const l=i+r,s=Math.max(0,Math.min(l,i+n));t.setSize(o,s),t.setSize(e,l-s)}const x=7;function B(t,o,e){if(!w(t.book,"dragMerge"))return!1;const{grid:i,sel:r}=t;if(r.ranges.length!==1)return!1;const n=r.ranges[0],l=i.cellRect(n.r0,n.c0),s=i.cellRect(n.r1,n.c1),c=s.x+s.w,a=s.y+s.h,u=(l.x+c)/2,z=(l.y+a)/2;return Math.abs(e-a)<=x&&Math.abs(o-u)<=x||Math.abs(o-c)<=x&&Math.abs(e-z)<=x}function D(t,o,e){const i=o.selection;if(i.ranges.length!==1)return;const r=o._rangeRectInPane(i.ranges[0],e);if(r===null)return;const{dpr:n,theme:l}=o,s=Math.round(5*n);t.fillStyle=l.accent,t.fillRect((r.x0+r.x1)/2-s/2,r.y1-s/2,s,s),t.fillRect(r.x1-s/2,(r.y0+r.y1)/2-s/2,s,s)}function _(t,o,e,i){const r={...o,r1:Math.max(o.r1,e),c1:Math.max(o.c1,i)};for(const n of t.merges){const l=n.r0<=r.r1&&n.r1>=r.r0&&n.c0<=r.c1&&n.c1>=r.c0,s=n.r0>=r.r0&&n.r1<=r.r1&&n.c0>=r.c0&&n.c1<=r.c1;if(l&&!s)return null}return r}const P=(t,o)=>{const e=w(o,"dragHeaders");return e==="both"||e===t};export{H as allows,L as applyAxisSizing,k as applySplitTopLeft,B as dragMergeHit,_ as dragMergeTarget,O as dragSplitBar,W as dropAxisSizing,P as headerDragAllowed,I as isSplitResize,K as nextVisible,D as paintDragMergeGrip,Y as parseSizeSpec,h as removeSplit,y as setAxisSizing,v as setTrailing,X as splitBarHit,N as splitResize,$ as toggleSplit};
|
package/cells/rich-runs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{STR as j}from"../core/sheet.js";import{parseInput as x}from"../core/input.js";const
|
|
2
|
-
`)&&
|
|
1
|
+
import{STR as j}from"../core/sheet.js";import{parseInput as x}from"../core/input.js";const z={bold:"b",italic:"i",underline:"u",strike:"strike",fontSize:"sz",fontName:"name",color:"color",vertAlign:"va"};function q(t){const e={};for(const[i,s]of Object.entries(t)){const l=z[i];if(l===void 0)return null;e[l]=s}return e}function C(t,e){return e?{...t,bold:e.b??t.bold,italic:e.i??t.italic,underline:e.u??t.underline,strike:e.strike??t.strike,fontSize:e.sz??t.fontSize,fontName:e.name??t.fontName,color:e.color??t.color,vertAlign:e.va??t.vertAlign}:t}const v=t=>{const{at:e,...i}=t;return i},E=(t,e)=>JSON.stringify(v(t))===JSON.stringify(v(e));function S(t,e){const i=[],s=t.length>0&&t[0].at===0?t:[{at:0},...t];for(let l=0;l<s.length;l++){const c=s[l];(s[l+1]?.at??e)<=c.at&&!(e===0&&l===0)||i.length>0&&E(i[i.length-1],c)||i.push(c)}return i.length>0?i:[{at:0}]}function R(t,e){let i=t[0];for(const s of t){if(s.at>e)break;i=s}return i}function L(t,e,i,s,l=null){const c=e+i,r=t.filter(n=>n.at<e);s>0&&r.push({...l??v(R(t,e>0?e-1:0)),at:e}),r.push({...R(t,c),at:e+s});for(const n of t)n.at>c&&r.push({...n,at:n.at+s-i});return r}function F(t,e,i,s){const l=r=>{const n={...r,...s};"name"in s&&(delete n.scheme,delete n.family,delete n.charset),"color"in s&&delete n.colorAttrs;for(const o of Object.keys(n))(n[o]===null||n[o]===void 0)&&delete n[o];return n},c=[];for(let r=0;r<t.length;r++){const n=t[r],o=t[r+1]?.at??1/0;if(o<=e||n.at>=i){c.push(n);continue}n.at<e&&c.push(n),c.push({...l(n),at:Math.max(n.at,e)}),o>i&&c.push({...n,at:i})}return c}function T(t,e,i){const s=S(t,e.length),l=n=>{const o=C(i,n);return{b:!!o.bold,i:!!o.italic,u:o.underline??0,strike:!!o.strike,sz:o.fontSize,name:o.fontName,color:o.color??null,va:o.vertAlign??null}},c=l({}),r=n=>JSON.stringify(l(n))!==JSON.stringify(c);return e===""||!s.some(r)?null:S(s.map(n=>{if(!r(n))return{at:n.at};const o=l(n),f={...n,b:o.b,i:o.i,u:o.u,strike:o.strike,sz:o.sz,name:o.name};return o.color!==null?f.color=o.color:delete f.color,o.va?f.va=o.va:delete f.va,f}),e.length)}const J=z;function _(t,e,i,s,l,c,r=!0){if(c&&x(l).kind===j){const n=l[0]==="'"&&l.length>1,o=n&&r,f=n?l.slice(1):l,u=n?S(c.map(m=>({...m,at:Math.max(0,m.at-1)})),f.length):c;t.setRichInput(e,i,s,f,u);const{sheet:h}=e,d=h.cellStyle(i,s);(o||d!==0&&t.styles.get(d).quotePrefix)&&h.setStyle(i,s,t.styles.derive(d,{quotePrefix:o}))}else t.setInput(e,i,s,l,{typedQuote:r});if(l.includes(`
|
|
2
|
+
`)&&l[0]!=="="){const{sheet:n}=e;t.styles.get(n.style(i,s)).wrap||n.setStyle(i,s,t.styles.derive(n.style(i,s),{wrap:!0}))}}function D(t,e,i,s){const l={};let c=!1;for(const[o,f]of Object.entries(s)){const u=J[o];u&&(l[u]=f,c=!0)}if(!c)return;const{sheet:r}=e,n=t.strings.rich;for(const{r0:o,c0:f,r1:u,c1:h}of i){const d=Math.min(u,r.maxRow),m=Math.min(h,r.maxCol);for(let p=f;p<=m;p++){const k=r.columns[p];if(k!==void 0)for(let a=o;a<=d;a++){const g=k[a>>>10];if(g===void 0){a|=1023;continue}if((g.kinds[a&1023]&15)!==2)continue;const O=n.get(g.values[a&1023]);if(!O)continue;const N=O.map(y=>{const{at:b,...I}=y;return Object.keys(I).length===0?y:F([{...y,at:0}],0,1/0,l).map(A=>({...A,at:b}))[0]});e.saveCell(a,p),r.setCell(a,p,2,t.strings.addRich(t.strings.get(g.values[a&1023]),N))}}}}export{F as applyRuns,T as finalizeRuns,S as normalizeRuns,D as overrideRuns,v as propsOf,R as runAt,q as runPatch,L as spliceRuns,_ as storeEntry,C as styleOfRun};
|
package/cells/rich-values.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{unescapeXstring as f}from"../io/xml-scan.js";import{ERRORS as g}from"../core/sheet.js";import{RichValue as x}from"../calc/values.js";const N={rv:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValue",path:"xl/richData/rdrichvalue.xml"},struct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueStructure",path:"xl/richData/rdrichvaluestructure.xml"},types:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueTypes",path:"xl/richData/rdRichValueTypes.xml"},spb:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBag",path:"xl/richData/rdsupportingpropertybag.xml"},spbStruct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBagStructure",path:"xl/richData/rdsupportingpropertybagstructure.xml"},array:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdArray",path:"xl/richData/rdarray.xml"},styles:{type:"http://schemas.microsoft.com/office/2017/06/relationships/richStyles",path:"xl/richData/richStyles.xml"}},S={4:"#NAME?",8:"#SPILL!",9:"#CONNECT!",10:"#BLOCKED!",11:"#UNKNOWN!",12:"#FIELD!",13:"#CALC!",14:"#BUSY!",17:"#BUSY!",19:"#TIMEOUT!"},w={0:"#NULL!",7:"#DIV/0!",15:"#VALUE!",23:"#REF!",29:"#NAME?",36:"#NUM!",42:"#N/A",43:"#GETTING_DATA"},A=/<v\b([^>]*)>([\s\S]*?)<\/v>|<v\b([^>]*)\/>/g,b=i=>/\bt="([^"]+)"/.exec(i??"")?.[1];function h(i){const t=[];for(const s of i.matchAll(A))t.push({t:b(s[1]??s[3]),v:f(s[2]??"")});return t}function y(i){return[...i.matchAll(/<k\b([^>]*)\/?>/g)].map(t=>({n:f(/\bn="([^"]*)"/.exec(t[1])?.[1]??""),t:b(t[1])??"d"}))}function E(i){if(!i)return[];const s=[...i.matchAll(/<metadataType\b[^>]*\bname="([^"]+)"/g)].map(a=>a[1]).indexOf("XLRICHVALUE")+1,e=/<futureMetadata\b[^>]*name="XLRICHVALUE"[^>]*>([\s\S]*?)<\/futureMetadata>/.exec(i),r=e?[...e[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g)].map(a=>Number(/\bi="(\d+)"/.exec(a[1])?.[1]??-1)):[],n=/<valueMetadata\b[^>]*>([\s\S]*?)<\/valueMetadata>/.exec(i),o=[-1];for(const a of n?n[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g):[]){const c=/<rc\b[^>]*\bt="(\d+)"[^>]*\bv="(\d+)"/.exec(a[1]);o.push(c&&Number(c[1])===s?r[Number(c[2])]??-1:-1)}return o}class V{constructor(t){this.byVm=E(t.meta),this.structs=t.struct?[...t.struct.matchAll(/<s\b([^>]*)>([\s\S]*?)<\/s>/g)].map(r=>({t:f(/\bt="([^"]*)"/.exec(r[1])?.[1]??""),keys:y(r[2])})):[],this.values=t.rv?[...t.rv.matchAll(/<rv\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rv>)/g)].map(r=>({s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:h((r[2]??"").replace(/<fb\b[\s\S]*?<\/fb>|<fb\b[^>]*\/>/g,"")).map(n=>n.v)})):[];const s=t.spb??"",e=/<spbArrays\b[^>]*>([\s\S]*?)<\/spbArrays>/.exec(s)?.[1]??"";this.spbArrays=[...e.matchAll(/<a\b[^>]*>([\s\S]*?)<\/a>/g)].map(r=>h(r[1])),this.spbs=[...s.matchAll(/<spb\b([^>]*)>([\s\S]*?)<\/spb>/g)].map(r=>({s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:h(r[2]).map(n=>n.v)})),this.spbStructs=t.spbStruct?[...t.spbStruct.matchAll(/<(s|spbStructure)\b[^>]*>([\s\S]*?)<\/\1>/g)].map(r=>y(r[2])):[],this.arrays=t.array?[...t.array.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/g)].map(r=>({r:Number(/\br="(\d+)"/.exec(r[1])?.[1]??1),c:Number(/\bc="(\d+)"/.exec(r[1])?.[1]??1),v:h(r[2])})):[],this.typeFlags=R(t.types??""),this.added=new Map,this.styles=_(t.styles??"")}indexOfVm(t){return t>0&&t<this.byVm.length?this.byVm[t]:this.added.get(t)??-1}vmOfIndex(t){if(this.vmByIndex===void 0){this.vmByIndex=new Map;for(let s=this.byVm.length-1;s>0;s--)this.byVm[s]>=0&&this.vmByIndex.set(this.byVm[s],s)}return this.vmByIndex.get(t)??-1}sameValue(t,s){const e=this.values[t],r=this.values[s];return!!(e&&r)&&e.s===r.s&&e.v.length===r.v.length&&e.v.every((n,o)=>n===r.v[o])}type(t){return this.structs[this.values[t]?.s]?.t??null}entries(t,s=0){const e=this.values[t],r=e&&this.structs[e.s],n=new Map;if(!r||s>8)return n;r.keys.forEach((a,c)=>n.set(a.n,{n:a.n,t:a.t,v:e.v[c]??""}));const o=n.get("%cvi");if(o&&o.t==="r")for(const[a,c]of this.entries(Number(o.v),s+1))n.has(a)||n.set(a,c);return n}bag(t){const s=this.spbs[t],e=s?this.spbStructs[s.s]??[]:[],r=new Map;return e.forEach((n,o)=>r.set(n.n,{n:n.n,t:n.t,v:s.v[o]??""})),r}view(t,s=!1){const e=this.type(t);if(e===null||e==="_localImage"||e==="_webimage")return null;const r=this.entries(t);if(e==="_error"){const o=Number(r.get("errorType")?.v),a=o===18?s?"#PYTHON!":"#EXTERNAL!":S[o]??null;return a?{kind:"error",text:a,icon:null}:null}if(e==="_array"){const o=this.arrays[Number(r.get("array")?.v)];return{kind:"array",text:o&&o.v.length?this.displayOf(o.v[0]):"",icon:s?"python":"array"}}return e==="_hyperlink"?{kind:"link",text:r.get("Text")?.v||r.get("Address")?.v||"",icon:null}:{kind:"entity",text:r.get("_DisplayString")?.v??r.get("Name")?.v??"",icon:s?"python":k(e,r)}}displayOf(t,s=0){switch(t.t){case"r":{if(s>8)return"";const e=this.view(Number(t.v));return e?e.text:this.entries(Number(t.v)).get("Text")?.v??""}case"a":{const e=this.arrays[Number(t.v)];return e&&e.v.length?this.displayOf(e.v[0],s+1):""}case"b":return t.v==="1"||t.v==="true"?"TRUE":"FALSE";case"e":return v(t.v);case"spb":case"spba":return"";default:return t.v}}flag(t,s,e,r){const o=this.entries(t).get("_Flags");if(o&&o.t==="spb"){const c=this.bag(Number(o.v)).get(s);if(c&&c.t==="spb"){const u=this.bag(Number(c.v)).get(e);if(u)return u.v==="1"||u.v==="true"}}return this.typeFlags.get(this.type(t))?.get(s)?.get(e)??this.typeFlags.get("")?.get(s)?.get(e)??r}fields(t){const s=this.entries(t),e=this.type(t),r=u=>!/^[_%^]/.test(u)&&this.flag(t,u,"ShowInCardView",e!=="_hyperlink");let n=[...s.keys()].filter(r);const o=s.get("_Display");if(o?.t==="spb"){const u=this.bag(Number(o.v)).get("^Order");if(u?.t==="spba"){const p=(this.spbArrays[Number(u.v)]??[]).map(l=>l.v).filter(l=>s.has(l)&&r(l));n=[...p,...n.filter(l=>!p.includes(l))]}}const a=s.get("_SubLabel"),c=a?.t==="spb"?this.bag(Number(a.v)):null;return n.map(u=>{const p=c?.get(u);let l="";return p?.t==="spb"?l=[...this.bag(Number(p.v)).values()].map(d=>d.v).join(" "):p&&(l=p.v),{name:u,value:s.get(u),sub:l}})}keyOf(t,s){const e=this.entries(t);if(e.has(s))return s;const r=s.toLowerCase();for(const o of e.keys())if(o.toLowerCase()===r)return o;const n=e.get("_CanonicalPropertyNames");if(n?.t==="spb"){for(const[o,a]of this.bag(Number(n.v)))if(a.v.toLowerCase()===r&&e.has(o))return o}return null}fieldFormat(t,s,e=null){const r=this.entries(t).get("_Format");if(!r||r.t!=="spb")return null;const n=this.bag(Number(r.v)).get(s),o=n?this.styles.rSty[Number(n.v)]:void 0;if(!o)return null;for(const c of o.rpv){const u=this.styles.rPr[c.i];if(u&&/^(?:NumberFormat|NumFmt|Format)$/i.test(u.n)&&c.v)return c.v}if(o.dxfid===null)return null;if(this.styles.dxfs.length)return this.styles.dxfs[o.dxfid]??null;const a=e?.[o.dxfid];return(typeof a?.numFmt=="string"?a.numFmt:a?.numFmt?.code??a?.numFmt?.formatCode)??null}isEntity(t){const s=this.type(t);return s!==null&&s!=="_error"&&s!=="_array"&&s!=="_localImage"&&s!=="_webimage"&&s!=="_hyperlink"}}function T(i,t,s){let e=t,r=null;for(let n=0;n<s.length;n++){if(!i.isEntity(e))return{error:"#FIELD!"};const o=i.keyOf(e,String(s[n]));if(o===null)return{error:"#FIELD!"};const a=i.entries(e).get(o);if(a.t==="r"&&n<s.length-1){e=Number(a.v);continue}if(n<s.length-1)return{error:"#FIELD!"};r=m(i,a,0)}return r??{error:"#VALUE!"}}function m(i,t,s){switch(t.t){case"i":case"d":{const e=Number(t.v);return Number.isFinite(e)?e:{error:"#NUM!"}}case"b":return t.v==="1"||t.v==="true";case"e":return{error:v(t.v)};case"s":return t.v;case"a":{const e=i.arrays[Number(t.v)];if(!e||s>4)return{error:"#VALUE!"};const r=[];for(let n=0;n<e.r;n++){const o=[];for(let a=0;a<e.c;a++){const c=e.v[n*e.c+a],u=c?m(i,{t:c.t??"d",v:c.v},s+1):"";o.push(u&&typeof u=="object"&&u.rows?u.rows[0]?.[0]??"":u)}r.push(o)}return{rows:r}}case"r":{const e=Number(t.v),r=i.type(e),n=i.entries(e);return r==="_error"?{error:i.view(e)?.text??"#VALUE!"}:r==="_array"?m(i,n.get("array")??{t:"a",v:"-1"},s+1):i.isEntity(e)?{entity:e}:i.view(e)?.text??n.get("Text")?.v??""}case"spb":case"spba":return{error:"#VALUE!"};default:{const e=Number(t.v);return t.v!==""&&Number.isFinite(e)?e:t.v}}}function _(i){const t={dxfs:[],rPr:[],rSty:[]};if(!i)return t;const s=/<(?:\w+:)?dxfs\b[^>]*>([\s\S]*?)<\/(?:\w+:)?dxfs>/.exec(i)?.[1]??"";return t.dxfs=[...s.matchAll(/<((?:\w+:)?)dxf\b[^>]*?(?:\/>|>([\s\S]*?)<\/\1dxf>)/g)].map(e=>{const r=/<(?:\w+:)?numFmt\b[^>]*\bformatCode="([^"]*)"/.exec(e[2]??"")?.[1];return r===void 0?null:f(r)}),t.rPr=[...i.matchAll(/<rPr\b([^>]*)\/?>/g)].map(e=>({n:f(/\bn="([^"]*)"/.exec(e[1])?.[1]??""),t:b(e[1])??"s"})),t.rSty=[...i.matchAll(/<rSty\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rSty>)/g)].map(e=>{const r=/\bdxfid="(\d+)"/.exec(e[1])?.[1],n=[...(e[2]??"").matchAll(/<rpv\b[^>]*\bi="(\d+)"[^>]*>([\s\S]*?)<\/rpv>/g)].map(o=>({i:Number(o[1]),v:f(o[2])}));return{dxfid:r===void 0?null:Number(r),rpv:n}}),t}function R(i){const t=new Map,s=r=>{const n=new Map;for(const o of r.matchAll(/<key\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/key>/g)){const a=new Map;for(const c of o[2].matchAll(/<flag\b[^>]*\bname="([^"]*)"[^>]*\bvalue="([^"]*)"/g))a.set(c[1],c[2]==="1"||c[2]==="true");n.set(f(o[1]),a)}return n},e=/<global\b[^>]*>([\s\S]*?)<\/global>/.exec(i);e&&t.set("",s(e[1]));for(const r of i.matchAll(/<type\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/type>/g))t.set(f(r[1]),s(r[2]));return t}function v(i){return/^#/.test(i)?i.toUpperCase():w[Number(i)]??g[Number(i)]??"#VALUE!"}function k(i,t){const s=[t.get("_Icon")?.v,t.get("%EntityDomainIdString")?.v,t.get("%ProviderInfo")?.v,t.get("%DataProviderString")?.v,i].filter(Boolean).join(" ").toLowerCase();return/stock|financ|bank|exchange|ticker|fund/.test(s)?"stock":/geo|map|country|city|place|globe|location|region/.test(s)?"geography":/currenc|money|coin/.test(s)?"currency":"entity"}async function M(i,t){if(!t.meta||!t.rv||!t.struct||!/<s\b[^>]*\bt="(?!_localImage")/.test(t.struct))return null;const s=i.has("xl/_rels/workbook.xml.rels")?await i.text("xl/_rels/workbook.xml.rels"):"",e=n=>{for(const o of s.matchAll(/<Relationship\b[^>]*\/>/g)){if(!o[0].includes(`Type="${n.type}"`))continue;const a=/\bTarget="([^"]+)"/.exec(o[0])?.[1];if(a)return a.startsWith("/")?a.slice(1):`xl/${a.replace(/^\.\//,"")}`}return n.path},r=async n=>{const o=e(N[n]);return i.has(o)?i.text(o):null};return new V({...t,spb:await r("spb"),spbStruct:await r("spbStruct"),array:await r("array"),styles:await r("styles")})}function D(i,t,s,e){const r=i.richValues,n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const o=r.indexOfVm(n);return o>=0&&r.isEntity(o)?new x(r,o):null}function U(i,t){const s=i.richValues,e=s.vmOfIndex(t);if(e>0)return e;i.richNew??=[];let r=i.richNew.findIndex(o=>o.rv===t);r<0&&(r=i.richNew.push({rv:t})-1);const n=(i.richSource?.vmCount??0)+r+1;return s.added.set(n,t),n}const I={4:4,8:8,9:11,10:12,11:14,12:13,13:9,14:10,17:10};function C(i){const t=i.richValues;if(t){for(const s of i.sheets)if(s.valueMeta!==null)for(const[e,r]of s.valueMeta){const n=t.indexOfVm(r);if(n<0||t.type(n)!=="_error")continue;const o=I[Number(t.entries(n).get("errorType")?.v)],a=Math.floor(e/16384),c=e-a*16384,u=s.kind(a,c);o!==void 0&&(u&7)===4&&s.setCell(a,c,u,o)}}}function P(i,t,s,e){const r=i.richValues;if(!r||t.valueMeta===null)return null;const n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const o=r.indexOfVm(n);if(o<0)return null;const a=t.formula(s,e),c=a?.f??a?.sf??"",u=r.view(o,/(?:^|[^\w.])(?:_xlfn\.)?(?:_xlws\.)?PY\(/i.test(c));return u?{rich:r,index:o,view:u}:null}export{N as RICH_PARTS,V as RichValues,C as adoptRichErrors,P as cellRich,U as entityVm,v as errorText,T as fieldValue,M as readRichValues,D as richValueAt,E as vmIndex};
|
|
1
|
+
import{unescapeXstring as f}from"../io/xml-scan.js";import{ERRORS as g}from"../core/sheet.js";import{RichValue as x}from"../calc/values.js";const N={rv:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValue",path:"xl/richData/rdrichvalue.xml"},struct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueStructure",path:"xl/richData/rdrichvaluestructure.xml"},types:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueTypes",path:"xl/richData/rdRichValueTypes.xml"},spb:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBag",path:"xl/richData/rdsupportingpropertybag.xml"},spbStruct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBagStructure",path:"xl/richData/rdsupportingpropertybagstructure.xml"},array:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdArray",path:"xl/richData/rdarray.xml"},styles:{type:"http://schemas.microsoft.com/office/2017/06/relationships/richStyles",path:"xl/richData/richStyles.xml"}},S={4:"#NAME?",8:"#SPILL!",9:"#CONNECT!",10:"#BLOCKED!",11:"#UNKNOWN!",12:"#FIELD!",13:"#CALC!",14:"#BUSY!",17:"#BUSY!",19:"#TIMEOUT!"},w={0:"#NULL!",7:"#DIV/0!",15:"#VALUE!",23:"#REF!",29:"#NAME?",36:"#NUM!",42:"#N/A",43:"#GETTING_DATA"},A=/<v\b([^>]*)>([\s\S]*?)<\/v>|<v\b([^>]*)\/>/g,h=o=>/\bt="([^"]+)"/.exec(o??"")?.[1];function b(o){const t=[];for(const s of o.matchAll(A))t.push({t:h(s[1]??s[3]),v:f(s[2]??"")});return t}function d(o){return[...o.matchAll(/<k\b([^>]*)\/?>/g)].map(t=>({n:f(/\bn="([^"]*)"/.exec(t[1])?.[1]??""),t:h(t[1])??"d"}))}function k(o){if(!o)return[];const s=[...o.matchAll(/<metadataType\b[^>]*\bname="([^"]+)"/g)].map(a=>a[1]).indexOf("XLRICHVALUE")+1,e=/<futureMetadata\b[^>]*name="XLRICHVALUE"[^>]*>([\s\S]*?)<\/futureMetadata>/.exec(o),r=e?[...e[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g)].map(a=>Number(/\bi="(\d+)"/.exec(a[1])?.[1]??-1)):[],n=/<valueMetadata\b[^>]*>([\s\S]*?)<\/valueMetadata>/.exec(o),i=[-1];for(const a of n?n[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g):[]){const c=/<rc\b[^>]*\bt="(\d+)"[^>]*\bv="(\d+)"/.exec(a[1]);i.push(c&&Number(c[1])===s?r[Number(c[2])]??-1:-1)}return i}class E{constructor(t){this.byVm=k(t.meta),this.structs=t.struct?[...t.struct.matchAll(/<s\b([^>]*)>([\s\S]*?)<\/s>/g)].map(r=>({t:f(/\bt="([^"]*)"/.exec(r[1])?.[1]??""),keys:d(r[2])})):[],this.values=t.rv?[...t.rv.matchAll(/<rv\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rv>)/g)].map(r=>{const n=r[2]??"",i=/<fb\b([^>]*)>([\s\S]*?)<\/fb>/.exec(n);return{s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:b(n).map(a=>a.v),fallback:i&&{t:h(i[1])??"n",v:f(i[2])}}}):[];const s=t.spb??"",e=/<spbArrays\b[^>]*>([\s\S]*?)<\/spbArrays>/.exec(s)?.[1]??"";this.spbArrays=[...e.matchAll(/<a\b[^>]*>([\s\S]*?)<\/a>/g)].map(r=>b(r[1])),this.spbs=[...s.matchAll(/<spb\b([^>]*)>([\s\S]*?)<\/spb>/g)].map(r=>({s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:b(r[2]).map(n=>n.v)})),this.spbStructs=t.spbStruct?[...t.spbStruct.matchAll(/<(s|spbStructure)\b[^>]*>([\s\S]*?)<\/\1>/g)].map(r=>d(r[2])):[],this.arrays=t.array?[...t.array.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/g)].map(r=>({r:Number(/\br="(\d+)"/.exec(r[1])?.[1]??1),c:Number(/\bc="(\d+)"/.exec(r[1])?.[1]??1),v:b(r[2])})):[],this.typeFlags=_(t.types??""),this.added=new Map,this.styles=V(t.styles??"")}indexOfVm(t){return t>0&&t<this.byVm.length?this.byVm[t]:this.added.get(t)??-1}vmOfIndex(t){if(this.vmByIndex===void 0){this.vmByIndex=new Map;for(let s=this.byVm.length-1;s>0;s--)this.byVm[s]>=0&&this.vmByIndex.set(this.byVm[s],s)}return this.vmByIndex.get(t)??-1}sameValue(t,s){const e=this.values[t],r=this.values[s];return!!(e&&r)&&e.s===r.s&&e.v.length===r.v.length&&e.v.every((n,i)=>n===r.v[i])}type(t){return this.structs[this.values[t]?.s]?.t??null}linkedCore(t){const s=e=>{const r=["%EntityServiceId","%EntityId","%EntityCulture"].map(n=>e.get(n)?.v);return r.every(n=>n!==void 0)?JSON.stringify(r):null};if(this.linkedCores===void 0){this.linkedCores=new Map;for(let e=0;e<this.values.length;e++){if(this.type(e)!=="_linkedentity2core")continue;const r=s(this.entries(e));r!==null&&this.linkedCores.set(r,e)}}return this.linkedCores.get(s(t))}entries(t,s=0){const e=this.values[t],r=e&&this.structs[e.s],n=new Map;if(!r||s>8)return n;r.keys.forEach((c,u)=>n.set(c.n,{n:c.n,t:c.t,v:e.v[u]??""}));const i=n.get("%cvi"),a=i?.t==="r"?Number(i.v):r.t==="_linkedentity2"?this.linkedCore(n):void 0;if(a!==void 0)for(const[c,u]of this.entries(a,s+1))n.has(c)||n.set(c,u);return n}bag(t){const s=this.spbs[t],e=s?this.spbStructs[s.s]??[]:[],r=new Map;return e.forEach((n,i)=>r.set(n.n,{n:n.n,t:n.t,v:s.v[i]??""})),r}view(t,s=!1){const e=this.type(t);if(e===null||e==="_localImage"||e==="_webimage"||e==="_formattednumber")return null;const r=this.entries(t);if(e==="_error"){const i=Number(r.get("errorType")?.v),a=i===18?s?"#PYTHON!":"#EXTERNAL!":S[i]??null;return a?{kind:"error",text:a,icon:null}:null}if(e==="_array"){const i=this.arrays[Number(r.get("array")?.v)];return{kind:"array",text:i&&i.v.length?this.displayOf(i.v[0]):"",icon:s?"python":"array"}}return e==="_hyperlink"?{kind:"link",text:r.get("Text")?.v||r.get("Address")?.v||"",icon:null}:{kind:"entity",text:r.get("_DisplayString")?.v??r.get("Name")?.v??"",icon:s?"python":I(e,r)}}displayOf(t,s=0){switch(t.t){case"r":{if(s>8)return"";const e=this.view(Number(t.v));return e?e.text:this.entries(Number(t.v)).get("Text")?.v??""}case"a":{const e=this.arrays[Number(t.v)];return e&&e.v.length?this.displayOf(e.v[0],s+1):""}case"b":return t.v==="1"||t.v==="true"?"TRUE":"FALSE";case"e":return y(t.v);case"spb":case"spba":return"";default:return t.v}}flag(t,s,e,r){const i=this.entries(t).get("_Flags");if(i&&i.t==="spb"){const c=this.bag(Number(i.v)).get(s);if(c&&c.t==="spb"){const u=this.bag(Number(c.v)).get(e);if(u)return u.v==="1"||u.v==="true"}}return this.typeFlags.get(this.type(t))?.get(s)?.get(e)??this.typeFlags.get("")?.get(s)?.get(e)??r}fields(t){const s=this.entries(t),e=this.type(t),r=u=>!/^[_%^]/.test(u)&&this.flag(t,u,"ShowInCardView",e!=="_hyperlink");let n=[...s.keys()].filter(r);const i=s.get("_Display");if(i?.t==="spb"){const u=this.bag(Number(i.v)).get("^Order");if(u?.t==="spba"){const p=(this.spbArrays[Number(u.v)]??[]).map(l=>l.v).filter(l=>s.has(l)&&r(l));n=[...p,...n.filter(l=>!p.includes(l))]}}const a=s.get("_SubLabel"),c=a?.t==="spb"?this.bag(Number(a.v)):null;return n.map(u=>{const p=c?.get(u);let l="";return p?.t==="spb"?l=[...this.bag(Number(p.v)).values()].map(v=>v.v).join(" "):p&&(l=p.v),{name:u,value:s.get(u),sub:l}})}keyOf(t,s){const e=this.entries(t);if(e.has(s))return s;const r=s.toLowerCase();for(const i of e.keys())if(i.toLowerCase()===r)return i;const n=e.get("_CanonicalPropertyNames");if(n?.t==="spb"){for(const[i,a]of this.bag(Number(n.v)))if(a.v.toLowerCase()===r&&e.has(i))return i}return null}fieldFormat(t,s,e=null){const r=this.entries(t).get("_Format");if(!r||r.t!=="spb")return null;const n=this.bag(Number(r.v)).get(s),i=n?this.styles.rSty[Number(n.v)]:void 0;if(!i)return null;for(const c of i.rpv){const u=this.styles.rPr[c.i];if(u&&/^(?:NumberFormat|NumFmt|Format)$/i.test(u.n)&&c.v)return c.v}if(i.dxfid===null)return null;if(this.styles.dxfs.length)return this.styles.dxfs[i.dxfid]??null;const a=e?.[i.dxfid];return(typeof a?.numFmt=="string"?a.numFmt:a?.numFmt?.code??a?.numFmt?.formatCode)??null}isEntity(t){const s=this.type(t);return s!==null&&s!=="_error"&&s!=="_array"&&s!=="_localImage"&&s!=="_webimage"&&s!=="_hyperlink"&&s!=="_formattednumber"}}function C(o,t,s){let e=t,r=null;for(let n=0;n<s.length;n++){if(!o.isEntity(e))return{error:"#FIELD!"};const i=o.keyOf(e,String(s[n]));if(i===null)return{error:"#FIELD!"};const a=o.entries(e).get(i);if(a.t==="r"&&n<s.length-1){e=Number(a.v);continue}if(n<s.length-1)return{error:"#FIELD!"};r=m(o,a,0)}return r??{error:"#VALUE!"}}function m(o,t,s){switch(t.t){case"i":case"d":case"n":{const e=Number(t.v);return Number.isFinite(e)?e:{error:"#NUM!"}}case"b":return t.v==="1"||t.v==="true";case"e":return{error:y(t.v)};case"s":return t.v;case"a":{const e=o.arrays[Number(t.v)];if(!e||s>4)return{error:"#VALUE!"};const r=[];for(let n=0;n<e.r;n++){const i=[];for(let a=0;a<e.c;a++){const c=e.v[n*e.c+a],u=c?m(o,{t:c.t??"d",v:c.v},s+1):"";i.push(u&&typeof u=="object"&&u.rows?u.rows[0]?.[0]??"":u)}r.push(i)}return{rows:r}}case"r":{const e=Number(t.v),r=o.type(e),n=o.entries(e);if(r==="_error")return{error:o.view(e)?.text??"#VALUE!"};if(r==="_formattednumber"){const i=o.values[e].fallback;return i?m(o,i,s+1):{error:"#VALUE!"}}return r==="_array"?m(o,n.get("array")??{t:"a",v:"-1"},s+1):o.isEntity(e)||r==="_webimage"?{entity:e}:o.view(e)?.text??n.get("Text")?.v??""}case"spb":case"spba":return{error:"#VALUE!"};default:{const e=Number(t.v);return t.v!==""&&Number.isFinite(e)?e:t.v}}}function V(o){const t={dxfs:[],rPr:[],rSty:[]};if(!o)return t;const s=/<(?:\w+:)?dxfs\b[^>]*>([\s\S]*?)<\/(?:\w+:)?dxfs>/.exec(o)?.[1]??"";return t.dxfs=[...s.matchAll(/<((?:\w+:)?)dxf\b[^>]*?(?:\/>|>([\s\S]*?)<\/\1dxf>)/g)].map(e=>{const r=/<(?:\w+:)?numFmt\b[^>]*\bformatCode="([^"]*)"/.exec(e[2]??"")?.[1];return r===void 0?null:f(r)}),t.rPr=[...o.matchAll(/<rPr\b([^>]*)\/?>/g)].map(e=>({n:f(/\bn="([^"]*)"/.exec(e[1])?.[1]??""),t:h(e[1])??"s"})),t.rSty=[...o.matchAll(/<rSty\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rSty>)/g)].map(e=>{const r=/\bdxfid="(\d+)"/.exec(e[1])?.[1],n=[...(e[2]??"").matchAll(/<rpv\b[^>]*\bi="(\d+)"[^>]*>([\s\S]*?)<\/rpv>/g)].map(i=>({i:Number(i[1]),v:f(i[2])}));return{dxfid:r===void 0?null:Number(r),rpv:n}}),t}function _(o){const t=new Map,s=r=>{const n=new Map;for(const i of r.matchAll(/<key\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/key>/g)){const a=new Map;for(const c of i[2].matchAll(/<flag\b[^>]*\bname="([^"]*)"[^>]*\bvalue="([^"]*)"/g))a.set(c[1],c[2]==="1"||c[2]==="true");n.set(f(i[1]),a)}return n},e=/<global\b[^>]*>([\s\S]*?)<\/global>/.exec(o);e&&t.set("",s(e[1]));for(const r of o.matchAll(/<type\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/type>/g))t.set(f(r[1]),s(r[2]));return t}function y(o){return/^#/.test(o)?o.toUpperCase():w[Number(o)]??g[Number(o)]??"#VALUE!"}function I(o,t){const s=[t.get("_Icon")?.v,t.get("%EntityDomainIdString")?.v,t.get("%ProviderInfo")?.v,t.get("%DataProviderString")?.v,o].filter(Boolean).join(" ").toLowerCase();return/stock|financ|bank|exchange|ticker|fund/.test(s)?"stock":/geo|map|country|city|place|globe|location|region/.test(s)?"geography":/currenc|money|coin/.test(s)?"currency":"entity"}async function T(o,t){if(!t.meta||!t.rv||!t.struct||!/<s\b[^>]*\bt="(?!_localImage")/.test(t.struct))return null;const s=o.has("xl/_rels/workbook.xml.rels")?await o.text("xl/_rels/workbook.xml.rels"):"",e=n=>{for(const i of s.matchAll(/<Relationship\b[^>]*\/>/g)){if(!i[0].includes(`Type="${n.type}"`))continue;const a=/\bTarget="([^"]+)"/.exec(i[0])?.[1];if(a)return a.startsWith("/")?a.slice(1):`xl/${a.replace(/^\.\//,"")}`}return n.path},r=async n=>{const i=e(N[n]);return o.has(i)?o.text(i):null};return new E({...t,spb:await r("spb"),spbStruct:await r("spbStruct"),array:await r("array"),styles:await r("styles")})}function M(o,t,s,e){const r=o.richValues,n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const i=r.indexOfVm(n);return i>=0&&r.isEntity(i)?new x(r,i):null}function D(o,t){const s=o.richValues,e=s.vmOfIndex(t);if(e>0)return e;o.richNew??=[];let r=o.richNew.findIndex(i=>i.rv===t);r<0&&(r=o.richNew.push({rv:t})-1);const n=(o.richSource?.vmCount??0)+r+1;return s.added.set(n,t),n}const R={4:4,8:8,9:11,10:12,11:14,12:13,13:9,14:10,17:10};function U(o){const t=o.richValues;if(t){for(const s of o.sheets)if(s.valueMeta!==null)for(const[e,r]of s.valueMeta){const n=t.indexOfVm(r);if(n<0||t.type(n)!=="_error")continue;const i=R[Number(t.entries(n).get("errorType")?.v)],a=Math.floor(e/16384),c=e-a*16384,u=s.kind(a,c);i!==void 0&&(u&7)===4&&s.setCell(a,c,u,i)}}}function P(o,t,s,e){const r=o.richValues;if(!r||t.valueMeta===null)return null;const n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const i=r.indexOfVm(n);if(i<0)return null;const a=t.formula(s,e),c=a?.f??a?.sf??"",u=r.view(i,/(?:^|[^\w.])(?:_xlfn\.)?(?:_xlws\.)?PY\(/i.test(c));return u?{rich:r,index:i,view:u}:null}export{N as RICH_PARTS,E as RichValues,U as adoptRichErrors,P as cellRich,D as entityVm,y as errorText,C as fieldValue,T as readRichValues,M as richValueAt,k as vmIndex};
|
package/cells/selection-modes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MAX_COLS as x,MAX_ROWS as
|
|
1
|
+
import{cellEditable as T}from"../core/protection.js";import{MAX_COLS as x,MAX_ROWS as h}from"../core/address.js";import{tableOfSelection as z}from"./table-rows.js";import{viewGet as k}from"./book-view.js";const M=e=>e.statusBar?.refreshFlags();function Y(e,r){e.selMode=e.selMode===r?null:r,e.addBase=e.selMode==="add"?e.sel.ranges.slice():null,M(e.app)}function H(e){!e.selMode&&!e.endMode||(e.selMode=null,e.addBase=null,e.endMode=!1,M(e.app))}function W(e){e.endMode=!e.endMode,M(e.app)}function I(e){e.scrollLock=!e.scrollLock,M(e.app)}const C=e=>e.r0===e.r1&&e.c0===e.c1;function b(e,r,t,o){if(o||e.selMode==="extend"){e.moveTo(r,t,!0);return}if(e.selMode==="add"){const n=Math.max(0,Math.min(r,h-1)),s=Math.max(0,Math.min(t,x-1)),f=e.sel.ranges[e.sel.ranges.length-1];(e.addBase===null||!C(f))&&(e.addBase=e.sel.ranges.slice()),e.grid.setSelection({ranges:[...e.addBase,e._withMerges({r0:n,c0:s,r1:n,c1:s})],row:n,col:s}),e.extent={row:n,col:s},e.grid.ensureVisible(n,s);return}e.moveTo(r,t,!1)}function P(e,r,t,{jump:o=!1,shift:n=!1}={}){const s=r==="col"&&e.grid.rtl?-t:t,{sheet:f}=e;if(o&&!n&&e.book.view?.deselectKeys&&X(e,r,s))return;const c=n||e.selMode==="extend";if(e.scrollLock&&!o){E(e,r,s);return}const a=c?e.extent:{row:e.sel.row,col:e.sel.col},w=e.endMode;w&&(e.endMode=!1,M(e.app));const l=o||w;let{row:i,col:g}=a;const u=e.sel.ranges[e.sel.ranges.length-1],m=c&&(r==="col"?u.r0===0&&u.r1===h-1:u.c0===0&&u.c1===x-1);m&&(r==="col"?i=e.sel.row:g=e.sel.col);const d=!l&&f.mergeAt(i,g);if(d&&(!c&&e.mergeEntry?.selection===e.sel&&({row:i,col:g}=e.mergeEntry),r==="row"?i=s>0?d.r1:d.r0:g=s>0?d.c1:d.c0),r==="row"?i=l?f.jumpRow(i,g,s,!0):e._step(r,i,s):g=l?f.jumpCol(i,g,s,!0):e._step(r,g,s),m){if(!e._selectable(i,g))return;e._extendAxis(r,e.sel[r],r==="col"?g:i),e.grid.ensureVisible(i,g)}else b(e,i,g,n)}function X(e,r,t){const{sel:o}=e;if(o.ranges.reduce((w,l)=>w+(l.r1-l.r0+1)*(l.c1-l.c0+1),0)<2)return!1;const s=_(o.ranges,{r0:o.row,c0:o.col,r1:o.row,c1:o.col}),f=o.row+(r==="row"?t:0),c=o.col+(r==="col"?t:0),a=y(s,f,c)?{row:f,col:c}:{row:s[s.length-1].r0,col:s[s.length-1].c0};return e.grid.setSelection({ranges:s,row:a.row,col:a.col}),e.grid.ensureVisible(a.row,a.col),!0}function E(e,r,t){const{grid:o,sheet:n}=e;if(o.pageLayout){r==="row"?o.scrollTo(o.scrollX,o.scrollY+t*n.rows.defaultSize):o.scrollTo(o.scrollX+t*o.displayCols.defaultSize,o.scrollY);return}const s=o._frozen();if(r==="row"){const f=n.rows.indexAt(o.scrollY+s.h),c=Math.max(n.frozenRows,e._step("row",f,t));o.scrollTo(o.scrollX,n.rows.offsetOf(c)-s.h)}else{const f=o.displayCols.indexAt(o.scrollX+s.w),c=Math.max(n.frozenCols,e._step("col",f,t));o.scrollTo(o.displayCols.offsetOf(c)-s.w,o.scrollY)}}function U(e,r,t,o){const{grid:n,sheet:s}=e,f=o||e.selMode==="extend"?e.extent:{row:e.sel.row,col:e.sel.col},c=r==="col",a=c?n.displayCols:s.rows,w=c?n.scrollX:n.scrollY,l=n.pageLayout?null:n._bands(r).find(m=>m.part==="main"),i=l?l.size:c?n.cssW-n.rowHeaderW:n.cssH-n.colHeaderH;let g=t*i/n.zoom;if(l&&i>0){const m=a.indexAt(l.origin),d=l.origin+g;let p=a.indexAt(Math.max(0,d));t<0&&a.offsetOf(p)<d&&p++,p===m&&(p=e._step(r,m,t)),g=a.offsetOf(p)-l.origin,g===0&&t<0&&(g=-i/n.zoom)}const u=a.indexAt(Math.max(0,a.offsetOf(f[r])+g));c?n.scrollTo(w+g,n.scrollY):n.scrollTo(n.scrollX,w+g),b(e,c?f.row:u,c?u:f.col,o)}function D(e,r,t){const{sheet:o}=e,n=t||e.selMode==="extend"?e.extent:{row:e.sel.row};b(e,r?o.frozenRows:n.row,o.frozenCols,t)}function F(e,r){const{sheet:t}=e;b(e,Math.max(t.maxRow,0),Math.max(t.maxCol,0),r)}function L(e,r){const{sel:t}=e;if(t.ranges.length!==1)return!1;const o=t.ranges[0];if(o.r0===0&&o.r1===h-1)return!1;const n=z(e.app,o);if(!n)return!1;const s=r?o.c0:n.c0,f=r?o.c1:n.c1,c=n.r0+n.headerRows,a=n.r1-n.totalsRows,w=(g,u)=>o.r0===g&&o.r1===u&&o.c0===s&&o.c1===f,l=!C(o)||e.tableSelection===t;if(l&&w(n.r0,n.r1))return r?!1:(e._setSingle({r0:0,c0:0,r1:h-1,c1:x-1},t.row,t.col),!0);const i=t.row>=c&&t.row<=a&&!(l&&w(c,a));return e._setSingle({r0:i?c:n.r0,r1:i?a:n.r1,c0:s,c1:f},t.row,t.col),e.tableSelection=e.sel,!0}function G(e){if(L(e,!0))return;const{sel:r}=e,t=r.ranges.map(o=>({r0:0,c0:o.c0,r1:h-1,c1:o.c1}));e.grid.setSelection({ranges:t,row:r.row,col:r.col}),e.extent={row:h-1,col:t[t.length-1].c1}}function K(e){const{sel:r}=e,t=r.ranges.map(o=>({r0:o.r0,c0:0,r1:o.r1,c1:x-1}));e.grid.setSelection({ranges:t,row:r.row,col:r.col}),e.extent={row:t[t.length-1].r1,col:x-1}}function N(e){const{sel:r}=e,t=r.ranges.find(a=>r.row>=a.r0&&r.row<=a.r1&&r.col>=a.c0&&r.col<=a.c1)??r.ranges[r.ranges.length-1],o=[[t.r0,t.c0],[t.r0,t.c1],[t.r1,t.c1],[t.r1,t.c0]];let n=o.findIndex(([a,w])=>a===r.row&&w===r.col);n=n<0?0:n;let s=(n+1)%4;for(;o[s][0]===r.row&&o[s][1]===r.col&&s!==n;)s=(s+1)%4;const[f,c]=o[s];e.grid.setSelection({ranges:r.ranges,row:f,col:c}),e.extent={row:f===t.r0?t.r1:t.r0,col:c===t.c0?t.c1:t.c0},e.grid.ensureVisible(f,c)}function j(e){const{sel:r}=e,t=e._withMerges({r0:r.row,c0:r.col,r1:r.row,c1:r.col});e.grid.setSelection({ranges:[t],row:r.row,col:r.col}),e.extent={row:r.row,col:r.col},e.grid.ensureVisible(r.row,r.col)}const R={down:[1,0],up:[-1,0],right:[0,1],left:[0,-1],none:[0,0]};function q(e,r){const[t,o]=R[k(e.book,"enterDirection")]??R.down;return r?[-t,-o]:[t,o]}function J(e,r,t){const{sel:o}=e;let n=o.ranges.length-1;for(let d=0;d<o.ranges.length;d++){const p=o.ranges[d];o.row>=p.r0&&o.row<=p.r1&&o.col>=p.c0&&o.col<=p.c1&&(n=d)}const s=o.ranges[n],f=d=>d.r0===0&&d.r1>=h-1?Math.min(d.r1,Math.max(e.sheet.maxRow,d.r0)):d.r1,c=d=>d.c0===0&&d.c1>=x-1?Math.min(d.c1,Math.max(e.sheet.maxCol,d.c0)):d.c1,a=f(s),w=c(s);let{row:l,col:i}=o;const g=e.sheet.mergeAt(l,i),u=d=>{const p=o.ranges.length,S=o.ranges[(n+(d?1:-1)+p)%p],A={row:f(S),col:c(S)};return d?{row:S.r0,col:S.c0}:A};r!==0?(l=r>0?(g?g.r1:l)+1:(g?g.r0:l)-1,l>a?(l=s.r0,i+=1,i>w&&({row:l,col:i}=u(!0))):l<s.r0&&(l=a,i-=1,i<s.c0&&({row:l,col:i}=u(!1)))):t!==0&&(i=t>0?(g?g.c1:i)+1:(g?g.c0:i)-1,i>w?(i=s.c0,l+=1,l>a&&({row:l,col:i}=u(!0))):i<s.c0&&(i=w,l-=1,l<s.r0&&({row:l,col:i}=u(!1))));const m=e.sheet.mergeAt(l,i);m&&(l=m.r0,i=m.c0),e.grid.setSelection({ranges:o.ranges,row:l,col:i}),e.grid.ensureVisible(l,i)}function Q(e,r){const{sheet:t,book:o,sel:n}=e,s=Math.max(t.maxRow,n.row),f=Math.max(t.maxCol,n.col);let{row:c,col:a}=n;const w=(s+1)*(f+1);for(let l=0;l<Math.min(w,5e5);l++)if(a+=r,a>f?(a=0,c=c>=s?0:c+1):a<0&&(a=f,c=c<=0?s:c-1),T(o,t,c,a))return e.moveTo(c,a),!0;return!1}function _(e,r){const t=[];for(const o of e){if(r.r1<o.r0||r.r0>o.r1||r.c1<o.c0||r.c0>o.c1){t.push(o);continue}o.r0<r.r0&&t.push({r0:o.r0,c0:o.c0,r1:r.r0-1,c1:o.c1}),o.r1>r.r1&&t.push({r0:r.r1+1,c0:o.c0,r1:o.r1,c1:o.c1});const n=Math.max(o.r0,r.r0),s=Math.min(o.r1,r.r1);o.c0<r.c0&&t.push({r0:n,c0:o.c0,r1:s,c1:r.c0-1}),o.c1>r.c1&&t.push({r0:n,c0:r.c1+1,r1:s,c1:o.c1})}return t}const y=(e,r,t)=>e.some(o=>r>=o.r0&&r<=o.r1&&t>=o.c0&&t<=o.c1);function Z(e,r){const{grid:t,sel:o}=e,n=_(r.before,r.cut);if(n.length===0){const c={r0:r.cut.r0,c0:r.cut.c0,r1:r.cut.r0,c1:r.cut.c0};t.setSelection({ranges:[c],row:c.r0,col:c.c0});return}const s=y(n,o.row,o.col),f=n[n.length-1];t.setSelection({ranges:n,row:s?o.row:f.r0,col:s?o.col:f.c0})}function $(e,r){let{ranges:t}=e;const o=r.selectionPolicy,n=r.selectionUnit;return o==="single"?t=[{r0:e.row,c0:e.col,r1:e.row,c1:e.col}]:o==="range"&&(t=[t[t.length-1]]),n==="row"?t=t.map(s=>({r0:s.r0,c0:0,r1:s.r1,c1:x-1})):n==="column"&&(t=t.map(s=>({r0:0,c0:s.c0,r1:h-1,c1:s.c1}))),t===e.ranges?e:{...e,ranges:t}}export{P as arrow,H as clearSelMode,j as collapseToActive,$ as constrainSelection,J as cycleInSelection,q as enterStep,Z as finishDeselect,D as home,y as inRanges,F as lastCell,N as nextCorner,Q as nextUnlocked,U as page,G as selectColumn,K as selectRow,L as selectTable,Y as setSelMode,_ as subtractRange,W as toggleEndMode,I as toggleScrollLock};
|