@8sheets/data-grid 1.0.1 → 1.0.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/calc/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/dbcs.js +1 -0
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/index.js +7 -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 +2 -2
- package/calc/values.js +1 -1
- package/calcx/functions/text.js +1 -1
- package/cells/axis-ops.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/format-tabs.js +3 -3
- package/cells/name-box.js +1 -1
- package/celltypes/dropdowns.js +1 -1
- package/core/address.js +1 -1
- package/core/autofill.js +1 -0
- package/core/cond-format.js +1 -1
- package/core/default-names.js +1 -1
- package/core/input.js +1 -1
- package/core/tables.js +1 -1
- package/core/workbook.js +1 -1
- package/i18n/en/common.js +1 -1
- package/i18n/en/shell.js +2 -1
- package/i18n/pl/common.js +1 -1
- package/i18n/pl/shell.js +2 -1
- package/io/csv.js +8 -8
- package/io/xlsx-write.js +2 -2
- package/package.json +1 -1
- package/table-view/version.js +1 -1
- package/ui/icons.js +1 -1
package/cells/name-box.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{icon as w}from"../ui/icons.js";import{cellRef as C,MAX_COLS as
|
|
1
|
+
import{icon as w}from"../ui/icons.js";import{cellRef as N,isValidName as C,MAX_COLS as S,MAX_ROWS as E,parseRangeRef as L,rangeRef as B,sheetPrefix as p}from"../core/address.js";import{viewGet as M,viewOf as y}from"./book-view.js";import{layoutApp as R}from"./view-options.js";import{t as d}from"../i18n/index.js";import{bindText as x}from"../i18n/dom.js";const T=t=>t.replace(/^'|'$/g,"").replace(/''/g,"'");function b(t,n){const s=/^(?:('(?:[^']|'')+'|[^!'(),=+\-*/ ]+)!)?(\$?[A-Za-z]{0,3}\$?\d*(?::\$?[A-Za-z]{0,3}\$?\d*)?)$/.exec(n.trim());if(!s||!s[2])return null;const e=L(s[2]);if(!e)return null;const o=s[1]?t.sheets.find(r=>r.name.toLowerCase()===T(s[1]).toLowerCase()):t.sheet;return o?{sheet:o,range:e}:null}function f(t,n){return n.cachedFor!==n.text&&(n.cachedFor=n.text,n.cachedTarget=b(t,n.text)),n.cachedTarget}const v=(t,n)=>t.r0===n.r0&&t.c0===n.c0&&t.r1===n.r1&&t.c1===n.c1;function q(t,n,s){const{engine:e}=t;if(!e||s.ranges.length!==1)return null;const o=s.ranges[0];if(e.names.size>0)for(const r of e.names.values()){if(r.hidden)continue;const a=f(t,r);if(a&&a.sheet===n&&v(a.range,o))return r.name}if(e.tables.size>0){for(const r of e.tables.values())if(r.sheet===n&&v(r,o))return r.name}return null}function k(t){const{engine:n}=t,s=[];if(!n)return s;for(const[e,o]of n.names){if(o.hidden)continue;const r=e.indexOf("!"),a=r>=0?Number(e.slice(0,r)):-1;a>=0&&a!==t.activeSheet||f(t,o)&&s.push({label:o.name??e,kind:"name"})}for(const e of n.tables.values())s.push({label:e.name,kind:"table"});return s.sort((e,o)=>e.label.localeCompare(o.label))}function A(t,n){const{engine:s}=t,e=n.trim().toUpperCase();if(!s||!e)return null;const o=s.names.get(`${t.activeSheet}!${e}`)??s.names.get(e);if(o)return f(t,o);for(const r of s.tables.values())if(r.name.toUpperCase()===e)return{sheet:r.sheet,range:{r0:r.r0,c0:r.c0,r1:r.r1,c1:r.c1}};return null}function W(t){const n=/^R(\d+)C(\d+)(?::R(\d+)C(\d+))?$/i.exec(t.trim());if(!n)return null;const s=Number(n[1])-1,e=Number(n[2])-1,o=n[3]?Number(n[3])-1:s,r=n[4]?Number(n[4])-1:e;return s<0||e<0||o>=E||r>=S?null:{r0:Math.min(s,o),c0:Math.min(e,r),r1:Math.max(s,o),c1:Math.max(e,r)}}function z(t,n){const{book:s,grid:e}=t,o=e.selection.ranges[e.selection.ranges.length-1],r=(l,c)=>N(l,c).replace(/^([A-Z]+)(\d+)$/,"$$$1$$$2"),a=`${p(s.sheet.name)}${r(o.r0,o.c0)}${o.r0===o.r1&&o.c0===o.c1?"":`:${r(o.r1,o.c1)}`}`;s.engine.names.set(n.toUpperCase(),{text:a,name:n}),s.engine.nameTemplates.clear(),s.namesChanged=!0,s.dirty=!0,s.engine.rebuild(),t.shell.setStatus(d("Defined {name} as {refers}",{name:n,refers:a})),t.controller.syncNameBox()}function D(t,n,{allowCreate:s=!1}={}){const{book:e,grid:o,controller:r}=t,a=n.split(/[,;]/).map(i=>i.trim()).filter(Boolean);if(a.length===0)return r.syncNameBox(),!1;const l=[];for(const i of a){const h=W(i),g=h?{sheet:e.sheet,range:h}:b(e,i)??A(e,i);if(!g){const $=e.engine?.names.has(`${e.activeSheet}!${i.toUpperCase()}`)||e.engine?.names.has(i.toUpperCase());return s&&!$&&a.length===1&&C(i)?(z(t,i),!0):(t.shell.setStatus(d('"{text}" is not a valid reference or name',{text:i})),r.syncNameBox(),!1)}l.push(g)}const{sheet:c}=l[0];if(c!==e.sheet){const i=e.sheets.indexOf(c);if(c.hidden||i<0)return t.shell.setStatus(d('"{name}" is hidden',{name:c.name})),!1;e.selectedSheets&&!e.selectedSheets.has(c)&&(e.selectedSheets=null),t.switchSheet(i)}const u=l.filter(i=>i.sheet===c).map(i=>i.range),m=u[u.length-1];return o.setSelection({ranges:u,row:m.r0,col:m.c0}),r.extent={row:m.r1,col:m.c1},o.ensureVisible(m.r0,m.c0),r.syncNameBox(),!0}function V(t,n){return`${p(t.sheet.name)}${n.ranges.map(B).join(",")}`}function _(t){const n=t.el("name-box")?.parentElement;if(!n||n.querySelector(".bk-name-drop"))return;const s=document.createElement("button");s.className="bk-name-drop",x(s,{title:"Names and tables","aria-label":"Names and tables"}),s.innerHTML=w("caret",8),s.addEventListener("pointerdown",r=>r.preventDefault()),s.addEventListener("click",()=>{const r=n.getBoundingClientRect(),a=k(t.book).map(l=>[l.label,()=>D(t,l.label),{raw:!0}]);t.ribbon.openMenuAt(r.left,r.bottom+2,{items:a.length?a:[["No names defined",()=>{},{disabled:!0}]]})});const e=document.createElement("div");e.className="bk-name-grip",x(e,{title:"Drag to resize the name box"}),e.addEventListener("pointerdown",r=>{r.preventDefault(),e.setPointerCapture(r.pointerId);const a=r.clientX,l=n.getBoundingClientRect().width,c=m=>{const i=Math.max(60,Math.min(window.innerWidth*.6,l+m.clientX-a));n.style.width=`${i}px`,y(t.book).nameBoxWidth=Math.round(i)},u=()=>{e.removeEventListener("pointermove",c),e.removeEventListener("pointerup",u),R(t)};e.addEventListener("pointermove",c),e.addEventListener("pointerup",u)}),n.style.width=`${M(t.book,"nameBoxWidth")}px`,n.append(s,e);const o=t.el("name-box");o.style.flex="1",o.style.minWidth="0",o.addEventListener("pointerdown",r=>{r.button!==0||document.activeElement===o||(r.preventDefault(),o.focus(),o.select())}),o.addEventListener("blur",()=>{t.controller.isEditing||t.controller.syncNameBox()})}export{D as goToText,_ as installNameBox,V as locationText,q as nameForSelection,k as namedPlaces};
|
package/celltypes/dropdowns.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{overlayRoot as rt}from"../api/overlay.js";import{BOOL as ot,EMPTY as at,ERR as st,ERRORS as lt,FORMULA as it,KIND_MASK as V,NUM as ct,STR as ut}from"../core/sheet.js";import{MAX_COLS as dt,MAX_ROWS as pt,parseRangeRef as ft}from"../core/address.js";import{partsToSerial as I,serialToParts as R}from"../core/numfmt.js";import{validateEntry as mt,validationAt as ht}from"../core/cond-format.js";import{parseInput as xt}from"../core/input.js";import{askAboutInvalid as yt}from"../cells/validation-alert.js";import{t as C}from"../i18n/index.js";const P=(e,t)=>e*16384+t,W=["calendar","time","month","datetime","color","slider","calculator","list"],K=new Map;function Xt(e,t){W.includes(e)||W.push(e),K.set(e,t)}const gt=2e5,j=5e3,B={calendar:"yyyy-mm-dd",time:"h:mm:ss",month:"mmm yyyy",datetime:"yyyy-mm-dd h:mm:ss"};function U(e,t,n,a){const r=t.kind(n,a)&V;if(r===at)return null;const o=t.value(n,a);return r===ct?o:r===ut?e.strings.get(o):r===ot?o!==0:r===st?lt[o]??"#N/A":null}function vt(e){const t=String(e??"");return t[0]==="="||t[0]==="'"?`'${t}`:t}function H(e,t,n,{overFormula:a=!1}={}){const{book:r}=e,{sheet:o}=r;return e.loading?!1:o.protection&&!r.styles.get(o.style(t,n)).unlocked?(e.shell.setStatus("This cell is on a protected sheet. Unprotect the sheet to change it."),!1):!a&&(o.kind(t,n)&it)!==0?(e.shell.setStatus("This cell's value comes from a formula, so this control can't change it."),!1):!0}function bt(e,t,n,a,r){const{book:o}=e,{sheet:u}=o,i=ht(u,t,n);if(!i||!i.showError)return!0;const l=xt(a);if(mt(o,u,i,t,n,l.kind??0,l.value,a))return!0;const s=()=>{};return yt(e,i,{retry:s,cancel:s,accept:i.errorStyle==="warning"||i.errorStyle==="information"?r:s}),!1}function kt(e,t,n,a,{format:r,overFormula:o=!1}={}){return!H(e,t,n,{overFormula:o})||!bt(e,t,n,a,()=>q(e,t,n,a,r))?!1:q(e,t,n,a,r)}function q(e,t,n,a,r){const{book:o,grid:u,controller:i}=e,l=o.sheet;return o.transact("entry",s=>{o.setInput(s,t,n,a),r&&o.styles.get(l.style(t,n)).numFmt==="General"&&l.setStyle(t,n,o.styles.derive(l.style(t,n),{numFmt:r}))}),e.commands?.afterEntry?.(t,n),u.invalidate(),i.syncFormulaBar(),!0}const G=(e,t)=>n=>{const a=G(e,n[e]??null);return n[e]=t,n.cellTypesChanged=!0,a};function wt(e,{r0:t,c0:n,r1:a,c1:r}){const o=t===0&&a===pt-1,u=n===0&&r===dt-1;return{r0:t,c0:n,r1:o?Math.max(e.maxRow,999):a,c1:u?Math.max(e.maxCol,25):r}}function Jt(e,t,n,a){const r=e.sheet,o=t.map(i=>wt(r,i));let u=0;for(const i of o)u+=(i.r1-i.r0+1)*(i.c1-i.c0+1);return u>gt?!1:(e.transact("cell type",()=>{const i=G(n,r[n]??null),l=new Map(r[n]??[]);for(const s of o)for(let x=s.r0;x<=s.r1;x++)for(let y=s.c0;y<=s.c1;y++)a===null?l.delete(P(x,y)):l.set(P(x,y),a);return r[n]=l.size>0?l:null,r.cellTypesChanged=!0,i}),!0)}function Qt(e,t={}){if(!W.includes(e))return null;const n={type:e},a=r=>{Number.isFinite(t[r])&&(n[r]=t[r])};return typeof t.format=="string"&&t.format.length<=64&&(n.format=t.format),e==="slider"&&(a("min"),a("max"),a("step")),e==="list"&&(typeof t.source=="string"&&t.source.length<=300&&(n.source=t.source),Number.isInteger(t.valueColumn)&&t.valueColumn>=0&&(n.valueColumn=t.valueColumn),Array.isArray(t.columns)&&(n.columns=t.columns.slice(0,50).map(r=>String(r).slice(0,200))),Array.isArray(t.rows)&&(n.rows=t.rows.slice(0,j).filter(Array.isArray).map(r=>r.slice(0,50).map(o=>typeof o=="number"?o:String(o).slice(0,1e3))))),K.get(e)?.sanitize?.(t,n),Object.freeze(n)}function X(e,t,n){const a=e.cellDropdowns;if(!a)return null;const r=e.mergeAt(t,n);return a.get(r?P(r.r0,r.c0):P(t,n))??null}function Zt(e){const{sheet:t,sel:n,grid:a}=e;if(!t.cellDropdowns||!X(t,n.row,n.col))return null;const r=a.cellRect(n.row,n.col),o=Math.min(16,r.h);return{x:r.x+r.w+1,y:r.y+r.h-o,size:o}}const J="ct-popup-style",Ct=`
|
|
1
|
+
import{overlayRoot as rt}from"../api/overlay.js";import{BOOL as ot,EMPTY as at,ERR as st,ERRORS as lt,FORMULA as it,KIND_MASK as V,NUM as ct,STR as ut}from"../core/sheet.js";import{MAX_COLS as dt,MAX_ROWS as pt,parseRangeRef as ft}from"../core/address.js";import{partsToSerial as I,serialToParts as R}from"../core/numfmt.js";import{validateEntry as mt,validationAt as ht}from"../core/cond-format.js";import{parseInput as xt}from"../core/input.js";import{askAboutInvalid as yt}from"../cells/validation-alert.js";import{t as C}from"../i18n/index.js";const P=(e,t)=>e*16384+t,W=["calendar","time","month","datetime","color","slider","calculator","list"],K=new Map;function Xt(e,t){W.includes(e)||W.push(e),K.set(e,t)}const gt=2e5,j=5e3,B={calendar:"yyyy-mm-dd",time:"h:mm:ss",month:"mmm yyyy",datetime:"yyyy-mm-dd h:mm:ss"};function U(e,t,n,a){const r=t.kind(n,a)&V;if(r===at)return null;const o=t.value(n,a);return r===ct?o:r===ut?e.strings.get(o):r===ot?o!==0:r===st?lt[o]??"#N/A":null}function vt(e){const t=String(e??"");return t[0]==="="||t[0]==="'"?`'${t}`:t}function H(e,t,n,{overFormula:a=!1}={}){const{book:r}=e,{sheet:o}=r;return e.loading?!1:o.protection&&!r.styles.get(o.style(t,n)).unlocked?(e.shell.setStatus("This cell is on a protected sheet. Unprotect the sheet to change it."),!1):!a&&(o.kind(t,n)&it)!==0?(e.shell.setStatus("This cell's value comes from a formula, so this control can't change it."),!1):!0}function bt(e,t,n,a,r){const{book:o}=e,{sheet:u}=o,i=ht(u,t,n);if(!i||!i.showError)return!0;const l=xt(a);if(mt(o,u,i,t,n,l.kind??0,l.value,l.text??a))return!0;const s=()=>{};return yt(e,i,{retry:s,cancel:s,accept:i.errorStyle==="warning"||i.errorStyle==="information"?r:s}),!1}function kt(e,t,n,a,{format:r,overFormula:o=!1}={}){return!H(e,t,n,{overFormula:o})||!bt(e,t,n,a,()=>q(e,t,n,a,r))?!1:q(e,t,n,a,r)}function q(e,t,n,a,r){const{book:o,grid:u,controller:i}=e,l=o.sheet;return o.transact("entry",s=>{o.setInput(s,t,n,a),r&&o.styles.get(l.style(t,n)).numFmt==="General"&&l.setStyle(t,n,o.styles.derive(l.style(t,n),{numFmt:r}))}),e.commands?.afterEntry?.(t,n),u.invalidate(),i.syncFormulaBar(),!0}const G=(e,t)=>n=>{const a=G(e,n[e]??null);return n[e]=t,n.cellTypesChanged=!0,a};function wt(e,{r0:t,c0:n,r1:a,c1:r}){const o=t===0&&a===pt-1,u=n===0&&r===dt-1;return{r0:t,c0:n,r1:o?Math.max(e.maxRow,999):a,c1:u?Math.max(e.maxCol,25):r}}function Jt(e,t,n,a){const r=e.sheet,o=t.map(i=>wt(r,i));let u=0;for(const i of o)u+=(i.r1-i.r0+1)*(i.c1-i.c0+1);return u>gt?!1:(e.transact("cell type",()=>{const i=G(n,r[n]??null),l=new Map(r[n]??[]);for(const s of o)for(let x=s.r0;x<=s.r1;x++)for(let y=s.c0;y<=s.c1;y++)a===null?l.delete(P(x,y)):l.set(P(x,y),a);return r[n]=l.size>0?l:null,r.cellTypesChanged=!0,i}),!0)}function Qt(e,t={}){if(!W.includes(e))return null;const n={type:e},a=r=>{Number.isFinite(t[r])&&(n[r]=t[r])};return typeof t.format=="string"&&t.format.length<=64&&(n.format=t.format),e==="slider"&&(a("min"),a("max"),a("step")),e==="list"&&(typeof t.source=="string"&&t.source.length<=300&&(n.source=t.source),Number.isInteger(t.valueColumn)&&t.valueColumn>=0&&(n.valueColumn=t.valueColumn),Array.isArray(t.columns)&&(n.columns=t.columns.slice(0,50).map(r=>String(r).slice(0,200))),Array.isArray(t.rows)&&(n.rows=t.rows.slice(0,j).filter(Array.isArray).map(r=>r.slice(0,50).map(o=>typeof o=="number"?o:String(o).slice(0,1e3))))),K.get(e)?.sanitize?.(t,n),Object.freeze(n)}function X(e,t,n){const a=e.cellDropdowns;if(!a)return null;const r=e.mergeAt(t,n);return a.get(r?P(r.r0,r.c0):P(t,n))??null}function Zt(e){const{sheet:t,sel:n,grid:a}=e;if(!t.cellDropdowns||!X(t,n.row,n.col))return null;const r=a.cellRect(n.row,n.col),o=Math.min(16,r.h);return{x:r.x+r.w+1,y:r.y+r.h-o,size:o}}const J="ct-popup-style",Ct=`
|
|
2
2
|
.ct-popup { position: fixed; z-index: 60; padding: 8px; border-radius: 8px; background: var(--menu); color: var(--ink); border: 1px solid var(--panel-line); box-shadow: var(--shadow); font: 12px -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; outline: none; max-width: calc(100vw - 16px); }
|
|
3
3
|
.ct-popup button { font: inherit; color: inherit; background: none; border: 0; border-radius: 4px; padding: 0; cursor: default; }
|
|
4
4
|
.ct-popup button:where(:not(.ct-btn)):hover:not(:disabled) { background: var(--hover); }
|
package/core/address.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const F=1048576,T=16384,$=[];function a(t){let e=$[t];if(e!==void 0)return e;e="";for(let n=t+1;n>0;n=Math.floor((n-1)/26))e=String.fromCharCode(65+(n-1)%26)+e;return $[t]=e,e}function s(t){let e=0;for(let n=0;n<t.length;n++){const r=t.charCodeAt(n)&223;if(r<65||r>90)return-1;e=e*26+(r-64)}return e-1}function S(t,e){return a(e)+(t+1)}const h=/^[\p{L}\p{Nl}\p{No}_\\][\p{L}\p{N}\p{M}_.\\?]*$/u,N=/^([A-Za-z]{1,3})(\d+)$/,L=/^[Rr](\d*)(?:[Cc]\d*)?$|^[Cc](\d*)$/,_=(t,e)=>t===""||Number(t)>=1&&Number(t)<=e;function q(t){if(t.length>255||!h.test(t)||/^(TRUE|FALSE)$/i.test(t)||t.length===2&&t[0]==="\\")return!1;const e=N.exec(t);if(e&&s(e[1])<16384&&_(e[2],1048576))return!1;const n=L.exec(t);return!(n&&_(n[1]??n[2],1048576))}const m=/^\$?([A-Za-z]{1,3})\$?([1-9][0-9]{0,6})$/;function C(t){const e=m.exec(t.trim());if(!e)return null;const n=s(e[1]),r=Number(e[2])-1;return n<0||n>=16384||r>=1048576?null:{row:r,col:n}}function P(t){const e=t.trim().split(":");if(e.length>2||!e[0])return null;const n=(o,c)=>{const l=/^\$?[A-Za-z]{1,3}$/.test(o)?s(o.replace("$","")):-1,f=/^\$?[A-Za-z]{1,3}$/.test(c)?s(c.replace("$","")):-1;if(l>=0&&f>=0&&l<16384&&f<16384)return{r0:0,c0:Math.min(l,f),r1:1048575,c1:Math.max(l,f)};const i=/^\$?[0-9]+$/.test(o)?Number(o.replace("$",""))-1:-1,p=/^\$?[0-9]+$/.test(c)?Number(c.replace("$",""))-1:-1;return i>=0&&p>=0&&i<1048576&&p<1048576?{r0:Math.min(i,p),c0:0,r1:Math.max(i,p),c1:16383}:null},r=C(e[0]);if(e.length===1)return r?{r0:r.row,c0:r.col,r1:r.row,c1:r.col}:null;const u=C(e[1]);return r&&u?{r0:Math.min(r.row,u.row),c0:Math.min(r.col,u.col),r1:Math.max(r.row,u.row),c1:Math.max(r.col,u.col)}:n(e[0],e[1])}function U({r0:t,c0:e,r1:n,c1:r}){if(t===0&&n===1048575)return`${a(e)}:${a(r)}`;if(e===0&&r===16383)return`${t+1}:${n+1}`;const u=S(t,e);return t===n&&e===r?u:`${u}:${S(n,r)}`}const R=/[\x00-\x2d\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\x7f]/,M=/[\s\p{C}]/u,O=/^[\p{Nd}.]/u,g=/^([A-Za-z]{1,3})(\p{Nd}+)$/u,X=/^([A-Za-z]{1,3}\p{Nd}+)\.+([A-Za-z]{1,3}\p{Nd}+)$/u,I=/^R(\p{Nd}+)/iu,E=/^R?C(\p{Nd}+)/iu,w=/^[0-9]+$/,x=(t,e)=>!w.test(t)||Number(t)>=1&&Number(t)<=e;function A(t){const e=g.exec(t);return e!==null&&s(e[1])<16384&&x(e[2],1048576)}function d(t,e=!1){const n=String(t??"");if(n===""||R.test(n)||M.test(n)||O.test(n))return!0;const r=n.toUpperCase();if(r==="TRUE"||r==="FALSE"||r==="R"||r==="C"||r==="RC")return!0;if(!e){if(A(n))return!0;const c=X.exec(n);if(c&&A(c[1])&&A(c[2]))return!0}const u=I.exec(n);if(u&&x(u[1],1048576))return e||n[u[0].length]!==".";const o=E.exec(n);return o&&x(o[1],16384)?e||n[o[0].length]!==".":!1}function W(t,{book:e=null,last:n=null,r1c1:r=!1,always:u=!1}={}){const o=String(t??""),c=`${e!=null?`[${e}]`:""}${o}${n!=null?`:${n}`:""}`;return u||(o!==""||e===null||e===void 0)&&d(o,r)||n!=null&&d(n,r)||e!=null&&(R.test(e)||M.test(e))?`'${c.replace(/'/g,"''")}'`:c}const B=String.raw`[A-Za-z_\u0080-][\w.\u0080-]*`,z=(t,e)=>`${W(t,e)}!`;function Z(t){const e=String(t).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/'/g,"''");return new RegExp(`(?:'${e}'|(?<![\\p{L}\\p{N}_.'\\]\\u0080-\\u{10FFFF}])${e})!`,"giu")}function G(t,e,n){const r=z(n);return String(t).replace(Z(e),()=>r)}function K(t){const e=String(t??"");return e.length>1&&e[0]==="'"&&e[e.length-1]==="'"?e.slice(1,-1).replace(/''/g,"'"):e}export{T as MAX_COLS,F as MAX_ROWS,B as PLAIN_SHEET,S as cellRef,s as colIndex,a as colName,q as isValidName,C as parseCellRef,P as parseRangeRef,W as quoteSheetName,U as rangeRef,G as renameSheetInFormula,d as sheetNeedsQuotes,z as sheetPrefix,Z as sheetReferencePattern,K as unquoteSheetName};
|
package/core/autofill.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EMPTY as k,FORMULA as M,KIND_MASK as w,NUM as y,STR as x}from"./sheet.js";import{partsToSerial as v,serialToParts as C}from"./numfmt.js";const z=[["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],["January","February","March","April","May","June","July","August","September","October","November","December"],["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],["Poniedziałek","Wtorek","Środa","Czwartek","Piątek","Sobota","Niedziela"],["Styczeń","Luty","Marzec","Kwiecień","Maj","Czerwiec","Lipiec","Sierpień","Wrzesień","Październik","Listopad","Grudzień"]];function I(t,e){return t===t.toUpperCase()?e.toUpperCase():t===t.toLowerCase()?e.toLowerCase():e}const b=t=>/[ymd]/i.test(t.replace(/"[^"]*"|\[[^\]]*\]/g,""))&&!/^general$/i.test(t);function L(t,e){const n=t.toLowerCase();for(const f of z){const r=f.findIndex(i=>i.toLowerCase()===n);if(r>=0)return{list:f,i:r}}if(e)for(const f of e){const r=f.findIndex(i=>i.toLowerCase()===n);if(r>=0)return{list:f,i:r}}return null}const S=(t,e)=>(e===12?v(t+1,1,1):v(t,e+1,1))-v(t,e,1);function $(t,e){const n=t.year*12+t.month-1+e,f=Math.floor(n/12),r=n-f*12+1;return v(f,r,Math.min(t.day,S(f,r)))}const O=t=>{const e=t%100;return e>=11&&e<=13?"th":["th","st","nd","rd"][t%10]??"th"},A=/^(?:q|qtr|quarter)\.?\s*$/i;function U(t){const e=/^(.*?)(\d+)(st|nd|rd|th)(.*)$/i.exec(t);if(e&&!/\d/.test(e[4])){const[,s,a,l,c]=e,p=Number(a),g=s===""&&A.test(c.trim())&&p>=1&&p<=4;return{pre:s,num:p,width:a.length,ord:!0,upper:l===l.toUpperCase(),rest:c,wrap:g,key:`${s}\0ord\0${c}`}}const n=/^(\d+)( .*)$/s.exec(t);if(n)return{pre:"",num:Number(n[1]),width:n[1].length,ord:!1,rest:n[2],wrap:!1,key:`\0lead\0${n[2]}`};const f=/^(.*?)(\d+)$/s.exec(t);if(!f)return null;const[,r,i]=f,o=Number(i),u=A.test(r)&&o>=1&&o<=4;return{pre:r,num:o,width:i.length,ord:!1,rest:"",wrap:u,key:`${r}\0`}}function B(t,e){const n=t.wrap?((e-1)%4+4)%4+1:Math.abs(e),f=String(n).padStart(t.width,"0");if(!t.ord)return`${t.pre}${f}${t.rest}`;const r=O(n);return`${t.pre}${f}${t.upper?r.toUpperCase():r}${t.rest}`}function F(t,e={}){const n=t.length;if(n===0||t.some(r=>r.kind&M))return()=>null;const f=t.map(r=>r.kind&w);if(f.every(r=>r===y)){const r=b(t[0].format??"General");if(n===1){if(!r&&e.alone&&!e.force)return()=>null;const d=r&&_(t[0].format)?1/24:1;return h=>({kind:y,value:t[0].value+d*(h+1)})}const i=t[1].value-t[0].value;let o=!0;for(let d=2;d<n;d++)Math.abs(t[d].value-t[d-1].value-i)>1e-9&&(o=!1);if(r){const d=t.map(m=>C(m.value)),h=(d[1].year-d[0].year)*12+d[1].month-d[0].month,N=m=>m.day===d[0].day||m.day<d[0].day&&m.day===S(m.year,m.month);if(d.every(N)&&h!==0)return m=>({kind:y,value:$(d[0],h*(n+m))})}if(o)return d=>({kind:y,value:t[n-1].value+i*(d+1)});const u=t.map((d,h)=>h),s=u.reduce((d,h)=>d+h,0)/n,a=t.reduce((d,h)=>d+h.value,0)/n;let l=0,c=0;for(let d=0;d<n;d++)l+=(u[d]-s)*(t[d].value-a),c+=(u[d]-s)**2;const p=l/c,g=a-p*s;return d=>({kind:y,value:g+p*(n+d)})}if(f.every(r=>r===x)){const r=t.map(o=>L(o.text,e.lists));if(r.every(Boolean)&&r.every(o=>o.list===r[0].list)){const{list:o}=r[0],u=n>=2&&(r[1].i-r[0].i+o.length)%o.length||1;return s=>({text:I(t[0].text,o[(r[n-1].i+u*(s+1))%o.length])})}const i=t.map(o=>U(o.text));if(i.every(Boolean)&&i.every(o=>o.key===i[0].key)){const o=i.map(a=>a.num),u=n>=2?o[1]-o[0]:1;let s=!0;for(let a=2;a<n;a++)o[a]-o[a-1]!==u&&(s=!1);if(s&&u!==0)return a=>({text:B(i[0],o[n-1]+u*(a+1))})}}return()=>null}function _(t){const e=String(t??"").replace(/"[^"]*"|\[[^\]]*\]|\\./g,"");return!/[dy]/i.test(e)&&/[hs]/i.test(e)}function T(t,e){const n=t.kind&w;if(t.kind&M||n===k)return null;if(n===y)return b(t.format??"General")?"date":"number";if(n!==x)return null;const f=L(t.text,e);if(f)return f.list;const r=U(t.text);return r?`text:${r.key}`:null}function E(t,e={}){const n=[],f=new Int32Array(t.length).fill(-1),r=new Int32Array(t.length),i=u=>(u.kind&w)===k&&!(u.kind&M);let o=!1;for(let u=0;u<t.length;){const s=T(t[u],e.lists);if(s===null){u++;continue}const a=[u];for(let c=u+1;c<t.length;c++)if(!i(t[c])){if(T(t[c],e.lists)!==s)break;a.push(c)}const l=F(a.map(c=>t[c]),{...e,alone:t.length===1});l(0)!==null&&(o=!0),a.forEach((c,p)=>{f[c]=n.length,r[c]=p}),n.push({n:a.length,series:l}),u=a[a.length-1]+1}return{active:o,at(u,s){const a=f[u];if(a<0)return null;const l=n[a];return l.series(s*l.n+r[u])}}}function R(t,e){const n=t.length,f=t[n-1].value;if(e==="days"){const u=n>=2?t[1].value-t[0].value:1;return(s,a)=>({kind:y,value:f+u*(a*n+s+1)})}if(e==="weekdays")return n>1?(u,s)=>({kind:y,value:t[u].value+7*(s+1)}):(u,s)=>({kind:y,value:P(f,"weekday",1,s+1)});const r=e==="months"?1:12,i=C(t[0].value),o=v(i.year,i.month,1);return(u,s)=>{const a=t[u].value,l=Math.floor(a)-o+1,c=i.year*12+i.month-1+r*(s+1),p=Math.floor(c/12),g=c-p*12+1,d=v(p,g,1),h=l>=1&&l<=31?d+Math.min(l,S(p,g))-1:d+l-1;return{kind:y,value:h+(a-Math.floor(a))}}}function P(t,e,n,f){if(e==="day")return t+n*f;const r=C(t),i=t-Math.floor(t);if(e==="month")return $(r,n*f)+i;if(e==="year")return $(r,12*n*f)+i;let o=t;const u=n*f<0?-1:1;for(let s=Math.abs(n*f);s>0;){o+=u;const a=Math.floor(o)%7;a!==0&&a!==1&&s--}return o}function W(t){const e=[],n=t[0];n.source.forEach((i,o)=>{i.split(/[\s,;._-]+/).filter(Boolean).forEach((s,a)=>{for(const l of[c=>c,c=>c.toUpperCase(),c=>c.toLowerCase(),c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()])e.push(c=>l((c[o]??"").split(/[\s,;._-]+/).filter(Boolean)[a]??""));e.push(l=>((l[o]??"").split(/[\s,;._-]+/).filter(Boolean)[a]??"").charAt(0)),e.push(l=>((l[o]??"").split(/[\s,;._-]+/).filter(Boolean)[a]??"").charAt(0).toUpperCase())}),e.push(s=>(s[o]??"").toUpperCase()),e.push(s=>(s[o]??"").toLowerCase()),e.push(s=>(s[o]??"").replace(/\S+/g,a=>a.charAt(0).toUpperCase()+a.slice(1).toLowerCase())),e.push(s=>(s[o]??"").replace(/\D/g,"")),e.push(s=>(s[o]??"").replace(/[^\p{L}]/gu,""));for(let s=1;s<=Math.min(i.length,12);s++)e.push(a=>(a[o]??"").slice(0,s)),e.push(a=>(a[o]??"").slice(-s))});const f=e.slice(),r=n.target;for(let i=1;i<r.length;i++){const o=r.slice(0,i);for(const u of f)if(u(n.source)===o)for(const s of[0,1,2,3]){const a=r.slice(i,i+s),l=r.slice(i+s);if(!/[\p{L}\d]/u.test(a))for(const c of f)c(n.source)===l&&e.push(p=>`${u(p)}${a}${c(p)}`)}}return e.find(i=>t.every(o=>i(o.source)===o.target))??null}export{z as BUILTIN_LISTS,k as EMPTY,P as dateStep,W as flashFillRule,b as isDateFormat,R as makeDatePlan,E as makeFillPlan,F as makeSeries};
|
package/core/cond-format.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseRangeRef as
|
|
1
|
+
import{parseRangeRef as T}from"./address.js";import{BOOL as R,ERR as S,ERRORS as A,KIND_MASK as L,NUM as E,STR as h}from"./sheet.js";import{numberToText as O}from"../calc/values.js";import{formatGeneral as q,getFormatter as F}from"./numfmt.js";function N(u){return u.split(/\s+/).map(T).filter(Boolean)}import{CondFormats as j,cfEffectAt as w,evaluatorOf as z,iconAt as H}from"../cells/cf-engine.js";function b(u,n,e){const s=u.validations;if(!s)return null;for(const r of s)if(r._ranges===void 0&&(r._ranges=N(r.sqref)),r._ranges.some(t=>n>=t.r0&&n<=t.r1&&e>=t.c0&&e<=t.c1))return r;return null}function C(u,n,e,s,r){const t=e.formula1.trim();if(t.startsWith('"'))return t.slice(1,-1).split(",").map(o=>o.trim());const f=u.engine;let i=f.template(t,s,r).fn(s,r,n);return i&&i.sheet&&(i=f.toArr(i)),i&&i.data?i.data.filter(o=>o!==null):[]}function G(u,n,e,s,r){return B(u,n,e,s,r).map(t=>t.text)}function B(u,n,e,s,r){const t=e.formula1.trim(),f=()=>C(u,n,e,s,r).map(p=>({text:String(p),value:p}));if(t.startsWith('"'))return f();const l=u.engine.template(t,s,r).fn(s,r,n);if(!l||!l.sheet)return f();const i=[],o=l.sheet;for(let p=l.r0;p<=Math.min(l.r1,o.maxRow);p++)for(let a=l.c0;a<=Math.min(l.c1,o.maxCol);a++){const m=o.kind(p,a)&L;if(m===0)continue;const g=o.value(p,a),c=u.styles.get(o.style(p,a)).numFmt;m===E?i.push({text:c==="General"?q(g):F(c).number(g).replace(/\u0001.?\u0001/g," ").trim(),value:g}):m===h?i.push({text:u.strings.get(g),value:u.strings.get(g)}):m===R?i.push({text:g?"TRUE":"FALSE",value:g!==0}):i.push({text:A[g]??"#N/A",value:null})}return i}function K(u,n,e,s,r,t){if(e?.type!=="list"||typeof t!="string"||/^[='"]/.test(t))return null;const f=t.trim().toLowerCase(),l=C(u,n,e,s,r).find(i=>typeof i=="string"&&i.trim().toLowerCase()===f);return l!==void 0&&l.trim()!==t.trim()?l.trim():null}function W(u,n,e,s,r,t,f,l){if(e.type==="none"||e.type===void 0)return!0;if(t===0)return e.allowBlank;const i=u.engine,o=c=>{if(!c)return null;const x=i.template(c,s,r),y=i.legacy;i.legacy=!0;try{const d=x.fn(s,r,n);return d&&d.sheet?i.refAuto(d,s,r):d}finally{i.legacy=y}},p=t===E?O(f):t===R?f?"TRUE":"FALSE":String(l);if(e.type==="list"){if(t===S)return!1;const c=C(u,n,e,s,r);if(t===E&&c.some(y=>(typeof y=="number"?y:Number(y))===f))return!0;const x=p.trim().toLowerCase();return c.some(y=>String(y).trim().toLowerCase()===x)}if(e.type==="custom"){const c=[n.kind(s,r),n.value(s,r),n.maxRow,n.maxCol],x=t===h?u.strings.add(String(l)):t===R?f?1:0:f;n.setCell(s,r,t,x);try{const y=o(e.formula1);return y===!0||typeof y=="number"&&y!==0}finally{n.setCell(s,r,c[0],c[1]),n.maxRow=c[2],n.maxCol=c[3]}}let a;if(e.type==="textLength"){if(t===S)return!1;a=p.length}else if(t===R)a=1/0;else if(t!==E||(a=f,e.type==="whole"&&!Number.isInteger(a)))return!1;const m=o(e.formula1),g=o(e.formula2);switch(e.operator){case"notBetween":return a<m||a>g;case"equal":return a===m;case"notEqual":return a!==m;case"greaterThan":return a>m;case"lessThan":return a<m;case"greaterThanOrEqual":return a>=m;case"lessThanOrEqual":return a<=m;default:return a>=m&&a<=g}}export{R as BOOL,j as CondFormats,h as STR,w as cfEffectAt,z as evaluatorOf,H as iconAt,B as listEntries,G as listItems,K as listSpelling,C as listValues,N as rangesOf,W as validateEntry,b as validationAt};
|
package/core/default-names.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as o}from"../i18n/index.js";const
|
|
1
|
+
import{t as o}from"../i18n/index.js";import{makeSeries as $}from"./autofill.js";import{STR as p}from"./sheet.js";const x=()=>o("name|Book"),S=()=>`${x()}1`,w=()=>o("name|Sheet"),b=()=>o("name|Table"),s=()=>o("name|Column");function C(e,t=[]){if(t.length>=2){const a=c=>$([{kind:p,value:0,text:String(c)}])(0)?.text,[i,l]=t.slice(-2),m=a(i)===String(l)?a(l):void 0;if(m&&!e.has(m.toLowerCase()))return m}const n=`${s()}1`;if(!e.has(n.toLowerCase()))return n;let r=2;for(;e.has(`${n}${r}`.toLowerCase());)r++;return`${n}${r}`}function k(e){let t=1;for(;e.has(`${s()}${t}`.toLowerCase());)t++;return`${s()}${t}`}const L=()=>o("name|Total"),T=()=>o("name|PivotTable"),N=()=>o("name|Chart");function g(e,t,n=1,r=""){let a=n;for(;t(`${e}${r}${a}`);)a++;return`${e}${r}${a}`}export{x as bookStem,N as chartStem,s as columnStem,k as freeColumnName,S as newBookName,C as newColumnName,g as nextName,T as pivotTableStem,w as sheetStem,b as tableStem,L as totalLabel};
|
package/core/input.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BOOL as g,EMPTY as
|
|
1
|
+
import{BOOL as g,EMPTY as P,ERR as C,ERRORS as D,FORMULA as I,NUM as o,STR as v}from"./sheet.js";import{partsToSerial as l}from"./numfmt.js";const M=["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A"],L=["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],F=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/,S=/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,A=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)[eE][+-]?\d+$/,Y=/^[+-]?(?:\d{1,3}(?:,\d{3})+|\d+)?(?:\.\d*)?%$/,y="(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d*)?|\\.\\d+",j=/^([+-]?)[€£¥]\s?([+-]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d*)?)$/;let $={symbol:"$",symbolFirst:!0};function H(r){$={symbol:r.symbol,symbolFirst:r.symbolFirst}}const Z=r=>`"${r.replace(/"/g,"")}"`;function _(r){const e=r?"#,##0.00":"#,##0",n=Z($.symbol);return $.symbolFirst?`${n}${e}_);[Red]\\(${n}${e}\\)`:`${e} ${n}`}function q(r,e){return e===2?r%4===0&&(r%100!==0||r%400===0||r===1900)?29:28:[4,6,9,11].includes(e)?30:31}const d=r=>r.length<=2?(Number(r)<30?2e3:1900)+Number(r):Number(r),m=(r,e,n)=>r>=1900&&r<=9999&&e>=1&&e<=12&&n>=1&&n<=q(r,e),O=r=>{const e=r.toLowerCase().replace(/\.$/,"");if(e.length<3)return 0;const n=L.indexOf(e.slice(0,3));return n<0?0:new Intl.DateTimeFormat("en-US",{month:"long",timeZone:"UTC"}).format(new Date(Date.UTC(2024,n,15))).toLowerCase().startsWith(e)?n+1:0},b=()=>new Date().getFullYear(),p=(r,e,n)=>r===1900&&e===2&&n===29?60:l(r,e,n);function T(r){let e;if(e=/^(\d{1,2})([/-])(\d{1,2})\2(\d{1,4})$/.exec(r)){const[n,u,t]=[Number(e[1]),Number(e[3]),d(e[4])];return m(t,n,u)?{value:p(t,n,u),format:"m/d/yyyy"}:null}if(e=/^(\d{4})([/-])(\d{1,2})\2(\d{1,2})$/.exec(r)){const[n,u,t]=[Number(e[1]),Number(e[3]),Number(e[4])];return m(n,u,t)?{value:p(n,u,t),format:"m/d/yyyy"}:null}if(e=/^(\d{1,2})[/-](\d{1,2})$/.exec(r)){const[n,u,t]=[Number(e[1]),Number(e[2]),b()];if(m(t,n,u))return{value:p(t,n,u),format:"d-mmm"};const s=d(e[2]);return e[2].length!==1&&m(s,n,1)?{value:l(s,n,1),format:"mmm-yy"}:null}if(e=/^(\d{1,2})[-\s]+([A-Za-z]+\.?)(?:[-\s,]+(\d{2}|\d{4}))?$/.exec(r)){const n=O(e[2]),u=Number(e[1]),t=e[3]?d(e[3]):b();return n&&m(t,n,u)?{value:p(t,n,u),format:e[3]?"d-mmm-yy":"d-mmm"}:null}if(e=/^([A-Za-z]+\.?)[-\s]+(\d{1,4})(?:,?\s*(\d{2}|\d{4}))?$/.exec(r)){const n=O(e[1]);if(!n)return null;const u=Number(e[2]);if(e[3]){const s=d(e[3]);return m(s,n,u)&&e[2].length<=2?{value:l(s,n,u),format:"d-mmm-yy"}:null}if(e[2].length<=2&&m(b(),n,u))return{value:l(b(),n,u),format:"d-mmm"};const t=d(e[2]);return m(t,n,1)&&e[2].length!==3?{value:l(t,n,1),format:"mmm-yy"}:null}return null}function U(r){let e=/^(\d{1,4}):(\d{1,2})(?::(\d{1,2}))?(?:\s+([AaPp][Mm]?))?$/.exec(r),n,u=0,t=0,s;if(e)[n,u,t]=[Number(e[1]),Number(e[2]),Number(e[3]??0)],s=e[4];else if(e=/^(\d{1,2})\s+([AaPp][Mm]?)$/.exec(r))n=Number(e[1]),s=e[2];else return null;if(u>59||t>59)return null;if(s){if(n<1||n>12)return null;const f=s[0].toLowerCase()==="p";n=n%12+(f?12:0)}const i=(n*3600+u*60+t)/86400;return s?{value:i,format:e[3]!==void 0?"h:mm:ss AM/PM":"h:mm AM/PM"}:n>=24?{value:i,format:"[h]:mm:ss"}:{value:i,format:e[3]!==void 0?"h:mm:ss":"h:mm"}}function z(r){const e=/^(.+?)\s+(\d{1,2}(?::\d{1,2}(?::\d{1,2})?)?\s*(?:[AaPp][Mm]?)?)$/.exec(r);if(!e||!/:|[AaPp]/.test(e[2]))return null;const n=T(e[1]),u=U(e[2]);return!n||!u||u.value>=1?null:{value:n.value+u.value,format:"m/d/yyyy h:mm"}}function B(r){const e=/^([+-]?)(\d+) (\d+)\/(\d+)$/.exec(r);if(!e)return null;const n=Number(e[4]);if(n===0)return null;const u=(Number(e[2])+Number(e[3])/n)*(e[1]==="-"?-1:1),t="?".repeat(Math.min(3,e[4].length));return{value:u,format:`# ${t}/${t}`}}function N(r){let e=0,n="";for(const u of r.replace(/,/g,""))u>="0"&&u<="9"?((e>0||u!=="0")&&e++,n+=e>15?"0":u):((u==="e"||u==="E")&&(e=-1/0),n+=u);return Number(n)}const c=N;function W(r){if(r==="")return{kind:P};if(r[0]==="="&&r.length>1)return{kind:I,formula:r.slice(1)};if(r[0]==="'")return{kind:v,text:r.slice(1)};const e=r.trim(),n=r.toUpperCase();if(n==="TRUE")return{kind:g,value:1};if(n==="FALSE")return{kind:g,value:0};const u=M.indexOf(n);if(u>=0)return{kind:C,value:D.indexOf(M[u]),text:r};let t;if((F.test(e)||A.test(e))&&!Number.isFinite(N(e)))return{kind:v,text:r};if(F.test(e))return{kind:o,value:N(e)};if(S.test(e))return{kind:o,value:c(e),format:e.includes(".")?"#,##0.00":"#,##0"};if(A.test(e))return{kind:o,value:N(e),format:"0.00E+00"};if(Y.test(e)&&/\d/.test(e)){const a=e.slice(0,-1);return{kind:o,value:c(a)/100,format:/\.\d/.test(a)?"0.00%":"0%"}}if(t=/^\((\d{1,3}(?:,\d{3})+(?:\.\d*)?|\d+(?:\.\d*)?|\.\d+)\)$/.exec(e))return{kind:o,value:-c(t[1]),...t[1].includes(",")?{format:t[1].includes(".")?"#,##0.00":"#,##0"}:{}};const s=$.symbol.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=(a,k,w)=>{const x=c(k)*(a==="-"||w?-1:1);return{kind:o,value:x,format:_(/\.\d/.test(k))}};if(t=new RegExp(`^([+-]?)${s}\\s?([+-]?)(${y})$`).exec(e))return i(t[1]||t[2],t[3]);if(t=new RegExp(`^([+-]?)(${y})\\s?${s}$`).exec(e))return i(t[1],t[2]);if((t=new RegExp(`^\\(${s}\\s?(${y})\\)$`).exec(e))||(t=new RegExp(`^\\((${y})\\s?${s}\\)$`).exec(e)))return i("",t[1],!0);if(t=j.exec(e))return{kind:o,value:c(t[2])*(t[1]==="-"?-1:1)};const f=B(e);if(f)return{kind:o,...f};const E=T(e);if(E)return{kind:o,...E};const R=U(e);if(R)return{kind:o,...R};const h=z(e);return h?{kind:o,...h}:{kind:v,text:r}}export{W as parseInput,H as setEntryCurrency};
|
package/core/tables.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{patchTableColumns as Y,totalsChildXml as N}from"../slicers/table-file.js";import{colName as q,MAX_COLS as G,rangeRef as F,sheetPrefix as J}from"./address.js";import{columnStem as L,freeColumnName as Q,newColumnName as V,nextName as k,tableStem as ee,totalLabel as te}from"./default-names.js";import{FORMULA as D,KIND_MASK as M,STR as T}from"./sheet.js";import{translateFormula as ne}from"./formula-refs.js";import{autoFilterXml as re,sortStateXml as se}from"../cells/filter-file.js";import{PRESET_DXFS as le,PRESET_STYLES as B}from"./table-presets.js";import{resolveColor as oe}from"../io/xlsx-styles.js";import{elementTableColors as ae}from"../slicers/custom-styles.js";import{undoGroup as ce}from"../cells/undo-group.js";import{escapeMarkup as v,xmlAttr as _}from"../io/xml-escape.js";const ie=["FFFFFF","000000","E8E8E8","0E2841","156082","E97132","196B24","0F9ED5","A02B93","4EA72E"],K=new Set;function Oe(t){K.add(t)}function ue(t,e){const n=B[t];if(!n)return null;const s=e&&e.length>=10?e:ie,r=l=>typeof l=="string"?`#${l}`:oe({a:{theme:String(l[0]),tint:l[1]?String(l[1]):void 0}},s),o={},a={};for(const[l,u,f]of n){const c=le[u],i={};c.bold&&(i.bold=!0),c.italic&&(i.italic=!0),c.c&&(i.color=r(c.c)),c.f&&(i.fill=r(c.f));for(const m of["l","r","t","b","v","h"])c[m]&&(i.borders??={},i.borders[m]={style:c[m][0],color:r(c[m][1])});o[l]=i,f&&(a[l]=f)}return{el:o,sizes:a}}const P=new WeakMap,fe={};function me(t,e){if(t&&B[t]&&t.startsWith("TableStyle")){const n=e&&e.length>=10?e:fe;let s=P.get(n);s||P.set(n,s=new Map);let r=s.get(t);if(!r){const{el:o,sizes:a}=ue(t,e),l=u=>a[u]??1;r=ae(o,[l("firstRowStripe"),l("secondRowStripe")],[l("firstColumnStripe"),l("secondColumnStripe")]),s.set(t,r)}return r}for(const n of K){const s=n(t,e);if(s)return s}return null}function Ue(t,e){const n=t.r0+t.headerRows,s=t.sheet?.rows;if(!s||s.hiddenSizes===null||s.hiddenSizes.size===0)return e-n;let r=t._bandRows;if(!r||r.version!==s.version||r.top!==n||r.r1!==t.r1||r.rows!==s){const l=[];for(const u of s.hiddenSizes.keys())u>=n&&u<=t.r1&&l.push(u);l.sort((u,f)=>u-f),r={version:s.version,top:n,r1:t.r1,rows:s,list:l},t._bandRows=r}let o=0,a=r.list.length;for(;o<a;){const l=o+a>>1;r.list[l]<e?o=l+1:a=l}return e-n-o}function de(t){const e=t.engine;return k(ee(),n=>e.tables.has(n.toUpperCase()))}function ze(t,e,n,s,r="TableStyleMedium2"){const o=t.engine,a=[];let l={...n};return t.transact("table",u=>{if(!s){l.r0>0&&!I(e,l.r0-1,l.c0,l.c1)&&(l={...l,r0:l.r0-1});for(let i=l.c0;i<=l.c1;i++)t.setInput(u,l.r0,i,`${L()}${i-l.c0+1}`)}const f=new Set;for(let i=l.c0;i<=l.c1;i++){let m=t.editText(e,l.r0,i).trim()||`${L()}${i-l.c0+1}`,d=m;for(let p=2;f.has(d.toLowerCase());p++)d=`${m}${p}`;f.add(d.toLowerCase()),a.push(d),(d!==m||(e.kind(l.r0,i)&M)!==T)&&(m=d,u.saveCell(l.r0,i),e.setCell(l.r0,i,T,t.strings.add(d)))}const c={name:de(t),sheet:e,...l,headerRows:1,totalsRows:0,columns:a,styleName:r,showRowStripes:!0,showColumnStripes:!1,showFirstColumn:!1,showLastColumn:!1,filter:{r0:l.r0,c0:l.c0,r1:l.r1,c1:l.c1,columns:new Map},isNew:!0,dirty:!0};return o.tables.set(c.name.toUpperCase(),c),()=>(o.tables.delete(c.name.toUpperCase()),o.rebuild(),()=>(o.tables.set(c.name.toUpperCase(),c),o.rebuild(),()=>null))}),o.tables.get(`${[...o.tables.keys()].pop()}`)}function I(t,e,n,s){for(let r=n;r<=s;r++)if(t.kind(e,r)!==0)return!0;return!1}function g(t,e){const n=[];if(t.engine)for(const s of t.engine.tables.values())s.sheet===e&&n.push(s);return n}function Xe(t,e,n,s){for(const r of g(t,e)){const o=n===r.r1+1-0&&r.totalsRows===0&&s>=r.c0&&s<=r.c1,a=s===r.c1+1&&n>=r.r0&&n<=r.r1;if(o)return r.r1=n,r.filter&&(r.filter.r1=n),r.dirty=!0,n-1>=r.r0+r.headerRows&&t.transact("table-row",l=>{for(let u=r.c0;u<=r.c1;u++)u===s||(e.kind(n-1,u)&D)===0||e.kind(n,u)!==0||t.setInput(l,n,u,`=${ne(t.editText(e,n-1,u).slice(1),1,0)}`)}),t.engine.rebuild(),r;if(a){r.c1=s;const l=t.editText(e,r.r0,s).trim()||V(new Set(r.columns.map(u=>u.toLowerCase())));return r.columns.push(l),r.filter&&(r.filter.c1=s),e.kind(r.r0,s)===0&&e.setCell(r.r0,s,T,t.strings.add(l)),r.dirty=!0,r.columnsChanged=!0,t.engine.rebuild(),r}}return null}function Ne(t,e,n){for(const s of g(t,e)){if(n.r0!==s.r1+1||s.totalsRows!==0||n.c0<s.c0||n.c0>s.c1)continue;const r=n.r1;if(g(t,e).some(a=>a!==s&&a.r0<=r&&a.r1>=n.r0&&a.c0<=s.c1&&a.c1>=s.c0))return null;const o={r1:s.r1,filter:s.filter?{...s.filter}:null};return t.transact("table-expand",()=>{const a=f=>{s.r1=f.r1,s.filter=f.filter?{...f.filter}:null,s.dirty=!0,t.engine.rebuild()},l={r1:r,filter:s.filter?{...s.filter,r1:r}:null};a(l);const u=(f,c)=>()=>(a(f),u(c,f));return u(o,l)}),s}return null}function De(t,e,n,s,r,o){if(!r.startsWith("="))return!1;for(const a of g(t,e)){if(s<a.c0||s>a.c1||n<=a.r0||n>a.r1-a.totalsRows)continue;const l=a.r0+a.headerRows,u=a.r1-a.totalsRows;for(let f=l;f<=u;f++)if(f!==n&&e.kind(f,s)!==0)return!1;return u===l?!1:(t.transact("calculated-column",f=>{for(let c=l;c<=u;c++)c!==n&&t.setInput(f,c,s,`=${o(r.slice(1),c-n,0)}`)}),!0)}return!1}const Z=(t,e)=>{const n=t.totals?.[e];return n?n.label!==void 0?` totalsRowLabel="${_(n.label)}"`:` totalsRowFunction="${n.fn}"`:""},j=t=>`<tableStyleInfo name="${_(t.styleName??"TableStyleMedium2")}" showFirstColumn="${t.showFirstColumn?1:0}" showLastColumn="${t.showLastColumn?1:0}" showRowStripes="${t.showRowStripes===!1?0:1}" showColumnStripes="${t.showColumnStripes?1:0}"/>`,pe=t=>F({r0:t.r0,c0:t.c0,r1:t.r1-t.totalsRows,c1:t.c1}),H=t=>t.filter&&t.headerRows>0?re({...t.filter,r0:t.r0,c0:t.c0,r1:t.r1-t.totalsRows,c1:t.c1},!1)+se(t.filter.sortState):"",W=t=>`${t.headerRows===0?' headerRowCount="0"':""}${t.totalsRows?` totalsRowCount="${t.totalsRows}"`:' totalsRowShown="0"'}`;function Be(t,e){const n=t.columns.map((r,o)=>{const a=N(t,o),l=`<tableColumn id="${t.columnIds?.[o]??o+1}" name="${_(r)}"${Z(t,o)}`;return a?`${l}>${a}</tableColumn>`:`${l}/>`}).join(""),s=H(t);return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1
|
+
import{patchTableColumns as Y,totalsChildXml as N}from"../slicers/table-file.js";import{colName as q,MAX_COLS as G,rangeRef as F,sheetPrefix as J}from"./address.js";import{columnStem as L,freeColumnName as Q,newColumnName as V,nextName as k,tableStem as ee,totalLabel as te}from"./default-names.js";import{FORMULA as D,KIND_MASK as M,STR as T}from"./sheet.js";import{translateFormula as ne}from"./formula-refs.js";import{autoFilterXml as re,sortStateXml as se}from"../cells/filter-file.js";import{PRESET_DXFS as le,PRESET_STYLES as B}from"./table-presets.js";import{resolveColor as oe}from"../io/xlsx-styles.js";import{elementTableColors as ae}from"../slicers/custom-styles.js";import{undoGroup as ce}from"../cells/undo-group.js";import{escapeMarkup as v,xmlAttr as _}from"../io/xml-escape.js";const ie=["FFFFFF","000000","E8E8E8","0E2841","156082","E97132","196B24","0F9ED5","A02B93","4EA72E"],K=new Set;function Oe(t){K.add(t)}function ue(t,e){const n=B[t];if(!n)return null;const s=e&&e.length>=10?e:ie,r=l=>typeof l=="string"?`#${l}`:oe({a:{theme:String(l[0]),tint:l[1]?String(l[1]):void 0}},s),o={},a={};for(const[l,u,f]of n){const c=le[u],i={};c.bold&&(i.bold=!0),c.italic&&(i.italic=!0),c.c&&(i.color=r(c.c)),c.f&&(i.fill=r(c.f));for(const m of["l","r","t","b","v","h"])c[m]&&(i.borders??={},i.borders[m]={style:c[m][0],color:r(c[m][1])});o[l]=i,f&&(a[l]=f)}return{el:o,sizes:a}}const P=new WeakMap,fe={};function me(t,e){if(t&&B[t]&&t.startsWith("TableStyle")){const n=e&&e.length>=10?e:fe;let s=P.get(n);s||P.set(n,s=new Map);let r=s.get(t);if(!r){const{el:o,sizes:a}=ue(t,e),l=u=>a[u]??1;r=ae(o,[l("firstRowStripe"),l("secondRowStripe")],[l("firstColumnStripe"),l("secondColumnStripe")]),s.set(t,r)}return r}for(const n of K){const s=n(t,e);if(s)return s}return null}function Ue(t,e){const n=t.r0+t.headerRows,s=t.sheet?.rows;if(!s||s.hiddenSizes===null||s.hiddenSizes.size===0)return e-n;let r=t._bandRows;if(!r||r.version!==s.version||r.top!==n||r.r1!==t.r1||r.rows!==s){const l=[];for(const u of s.hiddenSizes.keys())u>=n&&u<=t.r1&&l.push(u);l.sort((u,f)=>u-f),r={version:s.version,top:n,r1:t.r1,rows:s,list:l},t._bandRows=r}let o=0,a=r.list.length;for(;o<a;){const l=o+a>>1;r.list[l]<e?o=l+1:a=l}return e-n-o}function de(t){const e=t.engine;return k(ee(),n=>e.tables.has(n.toUpperCase()))}function ze(t,e,n,s,r="TableStyleMedium2"){const o=t.engine,a=[];let l={...n};return t.transact("table",u=>{if(!s){l.r0>0&&!I(e,l.r0-1,l.c0,l.c1)&&(l={...l,r0:l.r0-1});for(let i=l.c0;i<=l.c1;i++)t.setInput(u,l.r0,i,`${L()}${i-l.c0+1}`)}const f=new Set;for(let i=l.c0;i<=l.c1;i++){let m=t.editText(e,l.r0,i).trim()||`${L()}${i-l.c0+1}`,d=m;for(let p=2;f.has(d.toLowerCase());p++)d=`${m}${p}`;f.add(d.toLowerCase()),a.push(d),(d!==m||(e.kind(l.r0,i)&M)!==T)&&(m=d,u.saveCell(l.r0,i),e.setCell(l.r0,i,T,t.strings.add(d)))}const c={name:de(t),sheet:e,...l,headerRows:1,totalsRows:0,columns:a,styleName:r,showRowStripes:!0,showColumnStripes:!1,showFirstColumn:!1,showLastColumn:!1,filter:{r0:l.r0,c0:l.c0,r1:l.r1,c1:l.c1,columns:new Map},isNew:!0,dirty:!0};return o.tables.set(c.name.toUpperCase(),c),()=>(o.tables.delete(c.name.toUpperCase()),o.rebuild(),()=>(o.tables.set(c.name.toUpperCase(),c),o.rebuild(),()=>null))}),o.tables.get(`${[...o.tables.keys()].pop()}`)}function I(t,e,n,s){for(let r=n;r<=s;r++)if(t.kind(e,r)!==0)return!0;return!1}function g(t,e){const n=[];if(t.engine)for(const s of t.engine.tables.values())s.sheet===e&&n.push(s);return n}function Xe(t,e,n,s){for(const r of g(t,e)){const o=n===r.r1+1-0&&r.totalsRows===0&&s>=r.c0&&s<=r.c1,a=s===r.c1+1&&n>=r.r0&&n<=r.r1;if(o)return r.r1=n,r.filter&&(r.filter.r1=n),r.dirty=!0,n-1>=r.r0+r.headerRows&&t.transact("table-row",l=>{for(let u=r.c0;u<=r.c1;u++)u===s||(e.kind(n-1,u)&D)===0||e.kind(n,u)!==0||t.setInput(l,n,u,`=${ne(t.editText(e,n-1,u).slice(1),1,0)}`)}),t.engine.rebuild(),r;if(a){r.c1=s;const l=t.editText(e,r.r0,s).trim()||V(new Set(r.columns.map(u=>u.toLowerCase())),r.columns);return r.columns.push(l),r.filter&&(r.filter.c1=s),e.kind(r.r0,s)===0&&e.setCell(r.r0,s,T,t.strings.add(l)),r.dirty=!0,r.columnsChanged=!0,t.engine.rebuild(),r}}return null}function Ne(t,e,n){for(const s of g(t,e)){if(n.r0!==s.r1+1||s.totalsRows!==0||n.c0<s.c0||n.c0>s.c1)continue;const r=n.r1;if(g(t,e).some(a=>a!==s&&a.r0<=r&&a.r1>=n.r0&&a.c0<=s.c1&&a.c1>=s.c0))return null;const o={r1:s.r1,filter:s.filter?{...s.filter}:null};return t.transact("table-expand",()=>{const a=f=>{s.r1=f.r1,s.filter=f.filter?{...f.filter}:null,s.dirty=!0,t.engine.rebuild()},l={r1:r,filter:s.filter?{...s.filter,r1:r}:null};a(l);const u=(f,c)=>()=>(a(f),u(c,f));return u(o,l)}),s}return null}function De(t,e,n,s,r,o){if(!r.startsWith("="))return!1;for(const a of g(t,e)){if(s<a.c0||s>a.c1||n<=a.r0||n>a.r1-a.totalsRows)continue;const l=a.r0+a.headerRows,u=a.r1-a.totalsRows;for(let f=l;f<=u;f++)if(f!==n&&e.kind(f,s)!==0)return!1;return u===l?!1:(t.transact("calculated-column",f=>{for(let c=l;c<=u;c++)c!==n&&t.setInput(f,c,s,`=${o(r.slice(1),c-n,0)}`)}),!0)}return!1}const Z=(t,e)=>{const n=t.totals?.[e];return n?n.label!==void 0?` totalsRowLabel="${_(n.label)}"`:` totalsRowFunction="${n.fn}"`:""},j=t=>`<tableStyleInfo name="${_(t.styleName??"TableStyleMedium2")}" showFirstColumn="${t.showFirstColumn?1:0}" showLastColumn="${t.showLastColumn?1:0}" showRowStripes="${t.showRowStripes===!1?0:1}" showColumnStripes="${t.showColumnStripes?1:0}"/>`,pe=t=>F({r0:t.r0,c0:t.c0,r1:t.r1-t.totalsRows,c1:t.c1}),H=t=>t.filter&&t.headerRows>0?re({...t.filter,r0:t.r0,c0:t.c0,r1:t.r1-t.totalsRows,c1:t.c1},!1)+se(t.filter.sortState):"",W=t=>`${t.headerRows===0?' headerRowCount="0"':""}${t.totalsRows?` totalsRowCount="${t.totalsRows}"`:' totalsRowShown="0"'}`;function Be(t,e){const n=t.columns.map((r,o)=>{const a=N(t,o),l=`<tableColumn id="${t.columnIds?.[o]??o+1}" name="${_(r)}"${Z(t,o)}`;return a?`${l}>${a}</tableColumn>`:`${l}/>`}).join(""),s=H(t);return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
2
|
<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="${e}" name="${v(t.name)}" displayName="${v(t.name)}" ref="${F(t)}"${W(t)}>${s}<tableColumns count="${t.columns.length}">${n}</tableColumns>${j(t)}</table>`}function Ke(t){return{name:t.name,ref:F(t),filterRef:t.filter&&t.headerRows>0?pe(t):null,filterXml:H(t),counts:W(t),styleInfo:j(t),totals:t.totals?t.columns.map((e,n)=>Z(t,n)):null,totalsChild:t.totals?t.columns.map((e,n)=>N(t,n)):null}}function Pe(t,e){let n=t.replace(/<table\b[^>]*>/,s=>s.replace(/\bname="[^"]*"/,`name="${v(e.name)}"`).replace(/\bdisplayName="[^"]*"/,`displayName="${v(e.name)}"`).replace(/\bref="[^"]*"/,`ref="${e.ref}"`).replace(/\s(?:headerRowCount|totalsRowCount|totalsRowShown)="[^"]*"/g,"").replace(/\s*(\/?)>$/,`${e.counts}$1>`));return n=n.replace(/<autoFilter\b[^>]*\/>|<autoFilter\b[\s\S]*?<\/autoFilter>/,"").replace(/<sortState\b[^>]*\/>|<sortState\b[\s\S]*?<\/sortState>/,""),e.filterXml&&(n=n.replace("<tableColumns",`${e.filterXml}<tableColumns`)),/<tableStyleInfo\b/.test(n)?n=n.replace(/<tableStyleInfo\b[^>]*\/>/,e.styleInfo):n=n.replace("</tableColumns>",`</tableColumns>${e.styleInfo}`),e.totals&&(n=Y(n,e)),n}const he=/[[\]#']/g,E=t=>t.replace(he,"'$&"),we=/^[A-Za-z_\\][A-Za-z0-9_.\\]*$/;function O(t,e){const n=[];for(const s of t.sheets){const r=new Map;for(const[o,a]of s.formulas){const l=a.f??a.sf;if(typeof l!="string")continue;const u=a.f===void 0&&a.base!==void 0;let f=u?r.get(a):void 0;if(f===void 0){const c=e(l,s,Math.floor((u?a.base:o)/G));f=c===l?null:a.f!==void 0?{...a,f:c,tpl:void 0}:{...a,sf:c,tpl:void 0},u&&r.set(a,f)}f!==null&&n.push([s.formulas,o,a,f])}}for(const[s,r]of t.engine.names){const o=e(r.text,null,0);o!==r.text&&n.push([t.engine.names,s,r,{...r,text:o}])}for(const s of t.engine.tables.values())s.totals?.forEach((r,o)=>{if(r?.fn!=="custom"||!r.formula)return;const a=e(r.formula,s.sheet,s.r1);a!==r.formula&&n.push([{set:(l,u)=>{s.totals[l]=u}},o,r,{...r,formula:a}])});return t.formulasEdited=!0,n.some(s=>s[0]===t.engine.names)&&(t.namesChanged=!0),y(n,3),n}const y=(t,e)=>{for(const n of t)n[0].set(n[1],n[e])};function C(t,e,n,s,{rebuild:r=!1}={}){const o=t.engine;t.transact(n,a=>{const l={...e},u=s(a),f={...e};e.dirty=!0,r&&o.rebuild();const c=(i,m,d)=>()=>(Object.assign(e,i),e.dirty=!0,d?.(),r&&o.rebuild(),c(m,i,d));return c(l,f,u)})}function Ze(t,e,n,s){C(t,e,"table-option",()=>{e[n]=s})}function je(t,e,n){n&&e.headerRows===0||C(t,e,"table-filter",()=>{e.filter=n?{r0:e.r0,c0:e.c0,r1:e.r1-e.totalsRows,c1:e.c1,columns:new Map}:null})}function He(t,e,n){const s=t.engine;if(!we.test(n)||/^[A-Za-z]{1,3}[0-9]+$/.test(n)||/^[Rr][Cc]?$|^[Cc]$/.test(n))return"That isn't a valid table name.";const r=n.toUpperCase();if(r===e.name.toUpperCase()&&n===e.name)return null;if(s.tables.has(r)&&s.tables.get(r)!==e)return"Another table already uses that name.";if(s.names.has(r))return"A defined name already uses that name.";const o=e.name;return t.transact("table-name",()=>{const a=new RegExp(`(^|[^A-Za-z0-9_.\\\\])${o.replace(/[.\\]/g,"\\$&")}(?=\\[)`,"gi"),l=O(t,i=>i.replace(a,`$1${n}`)),u=(i,m,d)=>{s.tables.delete(i.toUpperCase()),e.name=m,s.tables.set(m.toUpperCase(),e),e.dirty=!0,y(l,d),s.rebuild()};u(o,n,3);const f=()=>(u(o,n,3),c),c=()=>(u(n,o,2),f);return c}),null}const be={average:101,countNums:102,count:103,max:104,min:105,stdDev:107,sum:109,var:110};function $e(t,e,n){if(!n)return null;if(n.label!==void 0)return n.label;if(n.fn==="custom")return n.formula?`=${n.formula}`:null;const s=be[n.fn];return s?`=SUBTOTAL(${s},${t.name}[${E(t.columns[e])}])`:null}function We(t,e,n){const{sheet:s}=e;if(n===e.totalsRows>0)return null;if(n){const o=e.r1+1;return I(s,o,e.c0,e.c1)?"Clear the row under the table to add a total row.":(C(t,e,"table-totals",a=>{const l=e.c1-e.c0,u=e.totals?.some(Boolean)?e.columns.map((c,i)=>e.totals[i]??null):null;if(u){e.totals=u,u.forEach((c,i)=>{const m=$e(e,i,c);m&&t.setInput(a,o,e.c0+i,m)}),e.totalsRows=1,e.r1=o,e.columnsChanged=e.source!==!0;return}e.totals=e.columns.map(()=>null);const f=te();if(e.totals[0]={label:f},t.setInput(a,o,e.c0,f),l>0){let c=!1;for(let m=e.r0+e.headerRows;m<=e.r1&&!c;m++)c=(s.kind(m,e.c1)&M)===1;const i=c?109:103;e.totals[l]={fn:c?"sum":"count"},t.setInput(a,o,e.c1,`=SUBTOTAL(${i},${e.name}[${E(e.columns[l])}])`)}e.totalsRows=1,e.r1=o,e.columnsChanged=e.source!==!0},{rebuild:!0}),null)}const r=e.r1;return C(t,e,"table-totals",o=>{for(let a=e.c0;a<=e.c1;a++)t.setInput(o,r,a,"");e.totalsRows=0,e.r1=r-1},{rebuild:!0}),null}function Ye(t,e,n){if(n===e.headerRows>0)return null;const{sheet:s}=e;return n?e.r0===0||I(s,e.r0-1,e.c0,e.c1)?"Clear the row above the table to show its headers.":(C(t,e,"table-header",r=>{e.r0-=1,e.headerRows=1,e.columns.forEach((o,a)=>t.setInput(r,e.r0,e.c0+a,o)),e.filter={r0:e.r0,c0:e.c0,r1:e.r1-e.totalsRows,c1:e.c1,columns:new Map}},{rebuild:!0}),null):(C(t,e,"table-header",r=>{for(let o=e.c0;o<=e.c1;o++)t.setInput(r,e.r0,o,"");e.r0+=1,e.headerRows=0,e.filter=null},{rebuild:!0}),null)}function qe(t,e,n){const{sheet:s}=e;if(n.r0!==e.r0)return"The header row must stay in the same row.";if(n.c0!==e.c0)return"The table must keep its first column.";if(n.r1<n.r0+e.headerRows+e.totalsRows)return"The table needs at least one data row.";for(const r of g(t,s))if(r!==e&&r.r0<=n.r1&&r.r1>=n.r0&&r.c0<=n.c1&&r.c1>=n.c0)return"A table can't overlap another table.";return C(t,e,"table-resize",()=>{const r=n.c1-n.c0+1,o=e.columns.slice(0,r);for(let a=o.length;a<r;a++){const l=e.c0+a;let u=e.headerRows?t.editText(s,e.r0,l).trim():"";u||(u=`${L()}${a+1}`),o.push(u)}e.columns=o,e.r1=n.r1,e.c1=n.c1,e.filter&&(e.filter={r0:e.r0,c0:e.c0,r1:e.r1-e.totalsRows,c1:e.c1,columns:new Map}),e.columnsChanged=!0},{rebuild:!0}),null}function Ce(t,e,n){const{sheet:s}=e,r=e.r1-e.r0+1,o=e.c1-e.c0+1,a=new Map,l=(f,c,i,m)=>{const d=(f-e.r0)*o+(c-e.c0);let p=a.get(d);p||a.set(d,p={}),p[i]=m};for(const f of n.areas(e,e.r0,e.r1,e.c0,e.c1)){const c=f.borders;for(let i=Math.max(f.r0,e.r0);i<=Math.min(f.r1,e.r1);i++)for(let m=Math.max(f.c0,e.c0);m<=Math.min(f.c1,e.c1);m++)c.t&&i===f.r0&&l(i,m,"t",c.t),c.b&&i===f.r1&&l(i,m,"b",c.b),c.l&&m===f.c0&&l(i,m,"l",c.l),c.r&&m===f.c1&&l(i,m,"r",c.r),c.h&&i<f.r1&&l(i,m,"b",c.h),c.v&&m<f.c1&&l(i,m,"r",c.v)}const u=new Map;t.transact("format",f=>{for(let c=0;c<r;c++){const i=e.r0+c;for(let m=0;m<o;m++){const d=e.c0+m,p=n.format(e,i,d),h=a.get(c*o+m),w=s.style(i,d),$=t.styles.get(w),b={};if(p.fill&&!$.fill&&(b.fill=p.fill),p.color&&!$.color&&(b.color=p.color),p.bold&&!$.bold&&(b.bold=!0),p.italic&&!$.italic&&(b.italic=!0),h){const R=$.borders??{},z={l:R.l??null,r:R.r??null,t:R.t??null,b:R.b??null};let X=!1;for(const S of["l","r","t","b"])h[S]&&!R[S]&&(z[S]={style:h[S].style,color:h[S].color},X=!0);X&&(b.borders=z)}const A=JSON.stringify(b);if(A==="{}")continue;const U=`${w}|${A}`;let x=u.get(U);x===void 0&&u.set(U,x=t.styles.derive(w,b,A)),x!==w&&(f.saveCell(i,d),s.setStyle(i,d,x))}}})}function Ge(t,e){ce(t,"Convert to Range",()=>ge(t,e))}function ge(t,e){const n=t.engine,{sheet:s}=e,r=me(e.styleName,t.theme),o=t.activeSheet;t.activeSheet=t.sheets.indexOf(s),r?.format&&Ce(t,e,r),t.activeSheet=o;const a=e.name.toUpperCase(),l=new RegExp(`(^|[^A-Za-z0-9_.\\\\])${e.name.replace(/[.\\]/g,"\\$&")}(\\[(?:[^\\[\\]']|'.|\\[(?:[^\\[\\]']|'.)*\\])*\\])`,"gi");t.transact("table-convert",()=>{const u=O(t,(m,d,p)=>m.replace(l,(h,w,$)=>{const b=n.tableSpecToA1(e,$,p);return b===null?h:`${w}${d===s?"":J(s.name)}${b}`})),f=e.source===!0&&e.part?{part:e.part,sheetIndex:t.sheets.indexOf(s)}:null,c=()=>{n.tables.delete(a),f&&(t.removedTables??=[]).push(f),y(u,3),n.rebuild()},i=()=>(n.tables.set(a,e),f&&(t.removedTables=t.removedTables.filter(m=>m!==f)),y(u,2),n.rebuild(),()=>(c(),i));return c(),i})}function Re(t,e,n,s){const r=t.toLowerCase(),o=`${e.toLowerCase()}[`;let a="",l=0;for(let u=r.indexOf(o);u>=0;u=r.indexOf(o,u+1)){const f=u+o.length-1;let c=0,i=f;for(;i<t.length;i++){const p=t[i];if(p==="'")i++;else if(p==="[")c++;else if(p==="]"&&--c===0)break}const m=t.slice(f,i+1),d=m.split(`[${n}]`).join(`[${s}]`);d!==m&&(a+=t.slice(l,f)+d,l=i+1)}return l===0?t:a+t.slice(l)}function Se(t,e,n,s){const r=e.columns[n],o=E(r),a=E(s),l=O(t,i=>i.includes("[")?Re(i,e.name,o,a):i),u=(i,m)=>{e.columns=e.columns.map((d,p)=>p===n?i:d),e.columnsChanged=!0,e.dirty=!0,y(l,m),t.engine?.rebuild()};u(s,3);const f=()=>(u(s,3),c),c=()=>(u(r,2),f);return c}function Je(t,e,n){let s=null;const{sheet:r}=e;for(const o of g(t,r))if(!(o.headerRows===0||o.dataSheet))for(let a=0;a<n.count;a++){if(n.rows[a]!==o.r0||n.cols[a]<o.c0||n.cols[a]>o.c1)continue;const l=n.cols[a],u=l-o.c0,f=r.kind(o.r0,l);let c=f===0?"":String(t.engine.read(r,o.r0,l)??"").trim();const i=new Set(o.columns.filter((h,w)=>w!==u).map(h=>h.toLowerCase()));if(c==="")c=Q(i);else if(i.has(c.toLowerCase())){const h=c;let w=2;for(;i.has(`${h}${w}`.toLowerCase());)w++;c=`${h}${w}`}if(((f&M)!==T||(f&D)!==0||t.strings.get(r.value(o.r0,l))!==c)&&(e.saveCell(o.r0,l),r.setFormula(o.r0,l,null),r.setCell(o.r0,l,T,t.strings.add(c))),o.columns[u]===c)continue;const m=Se(t,o,u,c),d=s,p=(h,w)=>w?()=>p(h(),w()):h;s=p(m,d)}return s}const Qe=[...Array.from({length:21},(t,e)=>`TableStyleLight${e+1}`),...Array.from({length:28},(t,e)=>`TableStyleMedium${e+1}`),...Array.from({length:11},(t,e)=>`TableStyleDark${e+1}`)];export{be as SUBTOTAL_CODE,Qe as TABLE_STYLE_NAMES,Ue as bandRow,q as colName,Ge as convertTableToRange,ze as createTable,De as fillCalculatedColumn,Ne as growTableOver,Xe as maybeExpandTable,de as nextTableName,Pe as patchTableXml,ue as presetElements,He as renameTable,Se as renameTableColumn,qe as resizeTable,Oe as setCustomTableResolver,je as setTableFilterButton,Ye as setTableHeaderRow,Ze as setTableOption,We as setTableTotals,E as structuredColumn,Je as syncTableHeaders,me as tableColors,Ke as tablePatch,Be as tableXml,g as tablesOf,$e as totalInput};
|
package/core/workbook.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{expandBareTables as K}from"../slicers/structured.js";import{syncTableHeaders as j}from"./tables.js";import{BOOL as F,CHUNK_BITS as I,CHUNK_MASK as J,EMPTY as _,ERR as E,ERRORS as W,FORMULA as k,DIRTY as N,EVALUATING as z,KIND_MASK as Z,NUM as P,Sheet as A,SPILL as Y,STR as R}from"./sheet.js";import{cellRef as X,MAX_COLS as w,MAX_ROWS as B,quoteSheetName as Q,rangeRef as ee,renameSheetInFormula as D,sheetReferencePattern as te}from"./address.js";import{translateFormula as se}from"./formula-refs.js";import{sheetStem as q}from"./default-names.js";import{StringTable as ne}from"./strings.js";import{StyleTable as ie}from"./styles.js";import{parseInput as G}from"./input.js";import{noteChanges as H}from"./changes.js";import{overrideRuns as le}from"../cells/rich-runs.js";import{sheetRenameHooks as re}from"./sparse.js";import{expandStructured as oe,toDisplayFormula as V,toFileFormula as ae}from"../calc/parser.js";const he=200,ce=new Set(["entry","clear","format","borders","fill"]);class ue{constructor(){this.ids=new Int32Array(1024),this.list=[]}set(t,e){if(t>=this.ids.length){let l=this.ids.length*2;for(;l<=t;)l*=2;const n=new Int32Array(l);n.set(this.ids),this.ids=n}const s=this.list.length;(s===0||this.list[s-1]!==e)&&this.list.push(e),this.ids[t]=this.list.length}get(t){const e=t<this.ids.length?this.ids[t]:0;return e===0?void 0:this.list[e-1]}}class b{constructor(){this.capacity=1024,this.count=0,this.rows=new Uint32Array(this.capacity),this.cols=new Uint16Array(this.capacity),this.kinds=new Uint8Array(this.capacity),this.styles=new Uint16Array(this.capacity),this.values=new Float64Array(this.capacity),this.formulas=null,this.vms=null}_grow(){const t=this.capacity*2,e=(s,l)=>{const n=new s(t);return n.set(l),n};this.rows=e(Uint32Array,this.rows),this.cols=e(Uint16Array,this.cols),this.kinds=e(Uint8Array,this.kinds),this.styles=e(Uint16Array,this.styles),this.values=e(Float64Array,this.values),this.capacity=t}push(t,e,s){this.count===this.capacity&&this._grow();const l=this.count++,n=t.kind(e,s)&~(N|z);if(this.rows[l]=e,this.cols[l]=s,this.kinds[l]=n,this.styles[l]=t.cellStyle(e,s),this.values[l]=t.value(e,s),n&k&&(this.formulas===null&&(this.formulas=new ue),this.formulas.set(l,t.formula(e,s))),t.valueMeta!==null){const i=t.valueMeta.get(e*w+s);i!==void 0&&(this.vms??=new Map).set(l,i)}}}class Re{constructor(){this.sheets=[new A(`${q()}1`)],this.activeSheet=0,this.strings=new ne,this.styles=new ie,this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.source=null,this.formulasEdited=!1,this.edits=0,this._dirty=!1,this.engine=null,this.selectedSheets=null}get sheet(){return this.sheets[this.activeSheet]}get dirty(){return this._dirty}set dirty(t){t&&this.edits++,this._dirty=!!t}onChange(t){this.listeners.add(t)}_emit(t){this.dirty=!0;for(const e of this.listeners)e(t)}addSheet(t){const e=q();let s=1,l=t??`${e}${s}`;const n=o=>this.sheets.some(r=>r.name.toLowerCase()===o.toLowerCase());for(;n(l);)l=`${e}${++s}`;const i=new A(l);return this.sheets.push(i),this.activeSheet=this.sheets.length-1,this.engine?.sheetsChanged(),this._emit("sheets"),i}deleteSheet(t){if(this.sheets.filter(s=>!s.hidden).length<=1)return!1;this._shrink3D(t);const[e]=this.sheets.splice(t,1);if(this.selectedSheets?.delete(e),this._forgetSheet(e,t),this.engine)for(const[s,l]of this.engine.tables)l.sheet===e&&this.engine.tables.delete(s);for(this._reindexNames(s=>s===t?-1:s>t?s-1:s),this.activeSheet>=this.sheets.length&&(this.activeSheet=this.sheets.length-1);this.sheets[this.activeSheet].hidden;)this.activeSheet=(this.activeSheet+1)%this.sheets.length;return this.structureEdited=!0,this.engine?.sheetsChanged(),this.engine?.rebuild(),this._emit("sheets"),!0}_forgetSheet(t,e){const s=n=>n.sheet===t||n.sheet===void 0&&n.sheetIndex===e||(n.extra?.parts??[]).some(s),l=n=>{n.sheetIndex>e&&n.sheetIndex--;for(const i of n.extra?.parts??[])l(i)};for(const n of[this.undoStack,this.redoStack]){const i=n.filter(o=>!s(o));i.forEach(l),n.splice(0,n.length,...i)}}moveSheet(t,e){if(t===e)return;const s=this.sheet,[l]=this.sheets.splice(t,1);this.sheets.splice(e,0,l),this.activeSheet=this.sheets.indexOf(s);const n=o=>o===t?e:t<e?o>t&&o<=e?o-1:o:o>=e&&o<t?o+1:o,i=o=>{o.sheetIndex=n(o.sheetIndex);for(const r of o.extra?.parts??[])i(r)};for(const o of this.undoStack)i(o);for(const o of this.redoStack)i(o);this.structureEdited=!0,this._reindexNames(n),this.engine?.orderChanged(),this._emit("sheets")}_copyScopedNames(t,e,s){const{engine:l}=this;if(!l||l.names.size===0)return;const n=`${t}!`;let i=!1;for(const[o,r]of[...l.names])o.startsWith(n)&&(l.names.set(`${t+1}!${o.slice(n.length)}`,{...r,text:D(r.text,e.name,s.name)}),i=!0);i&&(this.namesChanged=!0)}_reindexNames(t){const{engine:e}=this;if(!e||e.names.size===0)return;const s=[];let l=!1;for(const[n,i]of e.names){const o=n.indexOf("!"),r=o<0?0:t(Number(n.slice(0,o)));o>=0&&r!==Number(n.slice(0,o))&&(l=!0),o<0?s.push([n,i]):r>=0&&s.push([`${r}!${n.slice(o+1)}`,i])}if(l){e.names.clear();for(const[n,i]of s)e.names.set(n,i);e.nameTemplates.clear(),this.namesChanged=!0,e.rebuild()}}duplicateSheet(t){const e=this.sheets[t];let l=`${e.name} (2)`,n=2;for(;this.sheets.some(a=>a.name.toLowerCase()===l.toLowerCase());)l=`${e.name} (${++n})`;const i=new A(l);e.columns.forEach((a,u)=>{const m=[];a.forEach((h,y)=>{m[y]={kinds:h.kinds.slice(),values:h.values.slice(),styles:h.styles?h.styles.slice():null}}),i.columns[u]=m}),i.maxRow=e.maxRow,i.maxCol=e.maxCol,i.rows=e.rows.shifted(0,0),i.cols=e.cols.shifted(0,0);const o=new Map;e.formulas.forEachCell((a,u,m)=>{let h=o.get(m);h===void 0&&(h={...m,tpl:void 0},o.set(m,h)),i.setFormula(a,u,h)}),i.merges=e.merges.map(a=>({...a})),i.rowStyles=e.rowStyles?new Map(e.rowStyles):null,i.colStyles=e.colStyles?new Map(e.colStyles):null,i.frozenRows=e.frozenRows,i.frozenCols=e.frozenCols,i.showGridlines=e.showGridlines,i.cellTypes=e.cellTypes?new Map(e.cellTypes):null,i.sparkRules=e.sparkRules,i.cellDropdowns=e.cellDropdowns?new Map(e.cellDropdowns):null,i.cellTags=e.cellTags?new Map(e.cellTags):null,i.cellButtons=e.cellButtons?new Map(e.cellButtons):null,i.cellStates=e.cellStates?e.cellStates.slice():null,i.autoMerges=e.autoMerges?e.autoMerges.map(a=>({...a})):null,i.background=e.background,i.outlineColumn=e.outlineColumn?{...e.outlineColumn}:null,i.frozenTrailingRows=e.frozenTrailingRows,i.frozenTrailingCols=e.frozenTrailingCols,i.hideZeros=e.hideZeros,i.hideHeadings=e.hideHeadings,i.isChartSheet=e.isChartSheet,i.hideOutline=e.hideOutline,i.gridColorId=e.gridColorId,i.areaOffset=e.areaOffset,i.selectionPolicy=e.selectionPolicy,i.selectionUnit=e.selectionUnit,i.gridlineAxes=e.gridlineAxes,i.gridColor=e.gridColor,i.tabStyles=e.tabStyles;const r=x;return i.cf=r(e.cf),i.validations=r(e.validations),i.comments=r(e.comments),i.threads=r(e.threads),i.hyperlinks=e.hyperlinks?e.hyperlinks.map(a=>({...r({...a,_ranges:void 0})})):e.hyperlinks,i.autoFilter=r(e.autoFilter),i.filteredRows=e.filteredRows?new Set(e.filteredRows):e.filteredRows,i.pageSetup=r(e.pageSetup),i.tabColor=e.tabColor,i.protection=r(e.protection),i.rtl=e.rtl,i.zoom=e.zoom,i.valueMeta=e.valueMeta?new Map(e.valueMeta):null,i.colsChanged=!0,i.viewChanged=!0,this.sheets.splice(t+1,0,i),this.activeSheet=t+1,this._reindexNames(a=>a>t?a+1:a),this._copyScopedNames(t,e,i),this.structureEdited=!0,this.engine?.sheetsChanged(),this.engine?.rebuild(),this._emit("sheets"),i}sheetNameProblem(t,e){const s=e.trim().slice(0,31);return!s||/[\\/?*[\]:]/.test(s)||/^'|'$/.test(s)?"rules":s.toLowerCase()==="history"?"reserved":this.sheets.some((l,n)=>n!==t&&l.name.toLowerCase()===s.toLowerCase())?"taken":null}renameSheet(t,e){const s=e.trim().slice(0,31);if(this.sheetNameProblem(t,e)!==null)return!1;const l=this.sheets[t].name;this.sheets[t].name=s,this._renameInFormulas(l,s);for(const n of re)n(this,l,s);return this.engine?.sheetsChanged(),this._emit("sheets"),!0}_shrink3D(t){const e=this.sheets[t].name.toLowerCase(),s=r=>this.sheets.findIndex(a=>a.name.toLowerCase()===r.toLowerCase()),l=r=>r[0]==="'"?r.slice(1,-1).replace(/''/g,"'"):r,n=/((?:'(?:[^']|'')+'|[A-Za-z_\u00C0-\uFFFF][\w.\u00C0-\uFFFF]*)):((?:'(?:[^']|'')+'|[A-Za-z_\u00C0-\uFFFF][\w.\u00C0-\uFFFF]*))!/g,i=r=>r.replace(n,(a,u,m,h)=>{if(r[h-1]==="]")return a;const y=l(u),p=l(m);if(y.toLowerCase()!==e&&p.toLowerCase()!==e)return a;let c=s(y),S=s(p);if(c<0||S<0||(c>S&&([c,S]=[S,c]),c===t&&c++,S===t&&S--,c>S))return a;const f=g=>Q(this.sheets[g].name);return c===S?`${f(c)}!`:`${f(c)}:${f(S)}!`}),o=r=>r.includes(":")&&r.includes("!")?r.split(/("(?:[^"]|"")*")/).map((a,u)=>u%2?a:i(a)).join(""):r;for(const r of this.sheets){const a=new Map;r.formulas.forEachCell((u,m,h)=>{let y=a.get(h);if(y===void 0){const p=h.f??h.sf,c=typeof p=="string"?o(p):p;y=c===p?null:h.f!==void 0?{...h,f:c,tpl:void 0}:{...h,sf:c,tpl:void 0},a.set(h,y)}y!==null&&r.setFormula(u,m,y)})}for(const r of this.engine?.names.values()??[])typeof r.text=="string"&&(r.text=o(r.text));this.engine?.templates.clear()}_renameInFormulas(t,e){const s=te(t);let l=!1;for(const n of this.sheets){const i=new Map;n.formulas.forEachCell((o,r,a)=>{let u=i.get(a);if(u===void 0){const m=a.f??a.sf;if(m===void 0||!s.test(m))s.lastIndex=0,u=null;else{s.lastIndex=0;const h=D(m,t,e);u=a.f!==void 0?{...a,f:h,tpl:void 0}:{...a,sf:h,tpl:void 0}}i.set(a,u)}u!==null&&(n.setFormula(o,r,u),l=!0)})}l&&(this.formulasEdited=!0,this.engine?.templates.clear(),this.engine?.rebuild())}editText(t,e,s){const l=t.kind(e,s);if(this.engine?.dataTables.length){const o=this.engine.dataTableAt(t,e,s);if(o){const{info:r}=o,a=r.dt2D==="1",u=r.dtr==="1";return`{=TABLE(${a||u?r.r1:""},${a?r.r2:u?"":r.r1})}`}}if(l&Y&&this.engine){const o=this.engine.spillMaster(t,e,s);if(o)return this.editText(t,o.row,o.col)}if(l&k){const o=t.formula(e,s);if(o&&o.f!==void 0){const r="="+V(o.f);return o.t==="array"&&!o.cm?`{${r}}`:r}if(o&&o.sf!==void 0){const r=Math.floor(o.base/w),a=o.base-r*w;return"="+V(se(o.sf,e-r,s-a))}}const n=l&Z;if(n===_)return"";const i=t.value(e,s);if(n===E&&t.valueMeta!==null&&!(l&k)){const o=this.richImages?.get(t.valueMeta.get(e*w+s));if(o!==void 0)return o.alt??"";const r=this.richValues?.indexOfVm(t.valueMeta.get(e*w+s))??-1,a=r>=0?this.richValues.view(r):null;if(a!==null)return a.text}return n===R?this.styles.get(t.style(e,s)).quotePrefix?`'${this.strings.get(i)}`:this.strings.get(i):n===F?i?"TRUE":"FALSE":n===E?W[i]??"#N/A":String(i)}transact(t,e){if(this.guard&&!this.guard(t))return;const s=this.selectedSheets,l=s!==null&&s.size>1&&ce.has(t)?this._runGroup(t,e,s):this._runOn(this.sheet,t,e);l!==null&&this._pushUndo(l)}transactOn(t,e,s){const l=this._runOn(t,e,s);l!==null&&this._pushUndo(l)}_runOn(t,e,s){const l=new b,n={sheet:t,log:l,saveCell:(u,m)=>l.push(t,u,m)},i=s(n)??null;e!=="entry"&&this.engine?.presentationChanged(),t.changes!==null&&l.count>0&&H(this,t,l),l.vms!==null&&fe(t,l);const o=l.count>0&&this.engine?.tables.size>0?j(this,n,l):null,r=(u,m)=>h=>r(u(h),m(h)),a=i&&o?r(i,o):i??o;return l.count===0&&a===null?null:(t.revision++,this.engine?.cellsChanged(t,l.rows,l.cols,l.count),{sheetIndex:t===this.sheet?this.activeSheet:this.sheets.indexOf(t),sheet:t,log:l,label:e,extra:a})}_runGroup(t,e,s){const l=[];for(const n of this.sheets){if(!s.has(n)||n.protection&&n!==this.sheet)continue;const i=this._runOn(n,t,e);i!==null&&l.push(i)}return l.length===0?null:{sheetIndex:this.activeSheet,sheet:this.sheet,log:new b,label:t,extra:T(this,l)}}runSlice(t,e,s){const l=this._runOn(t,e,s);return l!==null&&this._emit("cells"),l}pushFolded(t,e,s){t.length!==0&&this._pushUndo({sheetIndex:this.sheets.indexOf(s),sheet:s,log:new b,label:e,extra:T(this,t)})}rollbackSlices(t){for(let e=t.length-1;e>=0;e--)this._restore(t[e]);this._emit("cells")}_pushUndo(t){this.allowUndo===!1?this.undoStack.length=0:(this.undoStack.push(t),this.undoStack.length>(this.historyLimit??he)&&this.undoStack.shift()),this.redoStack.length=0,this._emit("cells")}_restore(t){const e=t.sheet??this.sheets[t.sheetIndex],{log:s}=t,l=new b;for(let o=s.count-1;o>=0;o--){const r=s.rows[o],a=s.cols[o];l.push(e,r,a),e.setCell(r,a,s.kinds[o],s.values[o]),e.setStyle(r,a,s.styles[o]),e.setFormula(r,a,s.kinds[o]&k?s.formulas.get(o):null)}if(s.vms!==null){e.valueMeta=new Map(e.valueMeta??[]);for(const[o,r]of s.vms)e.valueMeta.set(s.rows[o]*w+s.cols[o],r)}let n=null;t.extra&&(n=t.extra(e)),this.engine?.presentationChanged(),e.changes!==null&&s.count>0&&H(this,e,l),e.revision++,this.engine?.cellsChanged(e,s.rows,s.cols,s.count);const i=this.sheets.indexOf(e);return i>=0&&(this.activeSheet=i),{sheetIndex:i>=0?i:t.sheetIndex,sheet:e,log:l,label:t.label,extra:n}}undo(){const t=this.undoStack.pop();return t?(this.redoStack.push(this._restore(t)),this._emit("cells"),!0):!1}redo(){const t=this.redoStack.pop();return t?(this.undoStack.push(this._restore(t)),this._emit("cells"),!0):!1}setInput(t,e,s,l){const{sheet:n}=t;this.recorder?.push(`sheet.setValue(${JSON.stringify(X(e,s))}, ${JSON.stringify(l)});`),t.saveCell(e,s),n.setFormula(e,s,null);const i=n.cellStyle(e,s),r=l!==""&&this.styles.get(n.style(e,s)).numFmt==="@"?{kind:R,text:l[0]==="'"?l.slice(1):l}:G(l),a=l[0]==="'"&&l.length>1;switch((a||i!==0&&this.styles.get(i).quotePrefix)&&n.setStyle(e,s,this.styles.derive(i,{quotePrefix:a})),r.kind){case _:n.setCell(e,s,_,0);break;case P:n.setCell(e,s,P,r.value),r.format&&(n.cellStyle(e,s)===0||this.styles.get(n.cellStyle(e,s)).numFmt==="General")&&n.setStyle(e,s,this.styles.derive(n.cellStyle(e,s),{numFmt:r.format}));break;case F:n.setCell(e,s,F,r.value);break;case k:n.setCell(e,s,k|_,0),n.setFormula(e,s,{f:ae(this._expandTableRefs(K(r.formula,this.engine?.tables),n,e,s),this.engine?.names??null),typed:this.dynamicArrays!==!1}),this.formulasEdited=!0;break;default:n.setCell(e,s,R,this.strings.add(r.text))}}setRichInput(t,e,s,l,n){const{sheet:i}=t;t.saveCell(e,s),i.setFormula(e,s,null),i.setCell(e,s,R,this.strings.addRich(l,n))}_expandTableRefs(t,e,s,l){const n=this.engine;return!n||n.tables.size===0?t:oe(t,()=>{for(const i of n.tables.values())if(i.sheet===e&&s>=i.r0&&s<=i.r1&&l>=i.c0&&l<=i.c1)return i;return null})}clearRange(t,e="contents",{visibleOnly:s=!1}={}){this.sheet.dataRanges?.cleared(t)||this.transact("clear",l=>{const{sheet:n}=l,i=[];if(e!=="contents")for(const{r0:r,c0:a,r1:u,c1:m}of t){const h=r===0&&u===B-1,y=a===0&&m===w-1,p=(c,S,f,g)=>{for(const[C,v]of[...S])C<f||C>g||(i.push([c,C,v]),S.delete(C))};h&&n.colStyles!==null&&p("col",n.colStyles,a,m),y&&n.rowStyles!==null&&p("row",n.rowStyles,r,u)}const o=s&&n.filteredRows?.size>0?n.filteredRows:null;for(const{r0:r,c0:a,r1:u,c1:m}of t){const h=Math.min(m,n.maxCol),y=Math.min(u,n.maxRow);for(let p=a;p<=h;p++)if(n.columns[p]!==void 0)for(let c=r;c<=y;c++){if(n._chunk(c,p)===void 0){c|=1023;continue}if(o!==null&&o.has(c))continue;const f=n.kind(c,p)!==0,g=n.cellStyle(c,p)!==0;if(e==="formats"){if(!g)continue;l.saveCell(c,p),n.setStyle(c,p,0);continue}!f&&!(e==="all"&&g)||(l.saveCell(c,p),n.setCell(c,p,_,0),n.setFormula(c,p,null),e==="all"&&n.setStyle(c,p,0))}}return i.length>0?O([],i):void 0})}applyStyle(t,e){const s=JSON.stringify(e);if(this.recorder)for(const l of t)this.recorder.push(`sheet.setFormat(${JSON.stringify(ee(l))}, ${s});`);this.transact("format",l=>{const{sheet:n}=l;this.strings.rich!==null&&le(this,l,t,e);const i=[],o=new Set,r=[];for(const{r0:a,c0:u,r1:m,c1:h}of t){const y=a===0&&m===B-1,p=u===0&&h===w-1;if(y){n.colStyles===null&&(n.colStyles=new Map);for(let f=u;f<=h;f++){const g=n.colStyles.get(f);r.push(["col",f,g]),n.colStyles.set(f,this.styles.derive(g??0,e,s))}if(p&&n.rowStyles!==null)for(const[f,g]of n.rowStyles)r.push(["row",f,g]),n.rowStyles.set(f,this.styles.derive(g,e,s))}else if(p){n.rowStyles===null&&(n.rowStyles=new Map);for(let f=a;f<=m;f++){const g=n.rowStyles.get(f);r.push(["row",f,g]),n.rowStyles.set(f,this.styles.derive(g??0,e,s))}}const c=y?n.maxRow:m,S=p?n.maxCol:h;for(let f=u;f<=S;f++)for(let g=a>>>I;g<=c>>>I;g++){const C=g<<I,v=Math.max(a,C),L=Math.min(c,C+J);if(v>L)continue;const $=n._ensure(v,f),U=f*2048+g;o.has(U)||(o.add(U),i.push(f,g,$.styles===null?null:$.styles.slice()));for(let M=v;M<=L;M++)n.setStyle(M,f,this.styles.derive(n.style(M,f),e,s))}}return O(i,r)})}}function T(d,t){const e=()=>{const s=[];for(let l=t.length-1;l>=0;l--)s.push(d._restore(t[l]));return T(d,s)};return e.parts=t,e}function fe(d,t){let e=null;for(const s of t.vms.keys()){const l=t.rows[s],n=t.cols[s];(d.kind(l,n)&~(N|z))===t.kinds[s]&&d.value(l,n)===t.values[s]||(e??=new Map(d.valueMeta),e.delete(l*w+n))}e!==null&&(d.valueMeta=e.size>0?e:null)}function x(d){if(d===null||typeof d!="object")return d;if(Array.isArray(d))return d.map(x);if(d instanceof Map)return new Map([...d].map(([e,s])=>[e,x(s)]));if(d instanceof Set)return new Set([...d].map(x));if(ArrayBuffer.isView(d))return d.slice();const t={};for(const[e,s]of Object.entries(d))!e.startsWith("_")&&typeof s!="function"&&(t[e]=x(s));return t}function O(d,t){return e=>{const s=[];for(let n=0;n<d.length;n+=3){const i=d[n],o=d[n+1],r=e.columns[i]?.[o];r!==void 0&&(s.push(i,o,r.styles),r.styles=d[n+2])}const l=[];for(const[n,i,o]of t){const r=n==="col"?"colStyles":"rowStyles",a=e[r]??=new Map;l.push([n,i,a.get(i)]),o===void 0?a.delete(i):a.set(i,o)}return O(s,l)}}export{b as CellLog,ce as GROUP_LABELS,Re as Workbook,T as foldEntries,G as parseInput,O as swapStyles};
|
|
1
|
+
import{expandBareTables as j}from"../slicers/structured.js";import{syncTableHeaders as J}from"./tables.js";import{BOOL as I,CHUNK_BITS as A,CHUNK_MASK as W,EMPTY as _,ERR as F,ERRORS as Z,FORMULA as v,DIRTY as N,EVALUATING as z,KIND_MASK as Y,NUM as P,Sheet as T,SPILL as X,STR as R}from"./sheet.js";import{cellRef as Q,MAX_COLS as w,MAX_ROWS as B,quoteSheetName as ee,rangeRef as te,renameSheetInFormula as D,sheetReferencePattern as q}from"./address.js";import{translateFormula as se}from"./formula-refs.js";import{sheetStem as G}from"./default-names.js";import{StringTable as ne}from"./strings.js";import{StyleTable as ie}from"./styles.js";import{parseInput as H}from"./input.js";import{noteChanges as V}from"./changes.js";import{overrideRuns as le}from"../cells/rich-runs.js";import{sheetRenameHooks as re}from"./sparse.js";import{shiftRuleFormulas as oe}from"../cells/cf-file.js";import{expandStructured as ae,toDisplayFormula as K,toFileFormula as he}from"../calc/parser.js";const ce=200,ue=new Set(["entry","clear","format","borders","fill"]);class fe{constructor(){this.ids=new Int32Array(1024),this.list=[]}set(t,e){if(t>=this.ids.length){let l=this.ids.length*2;for(;l<=t;)l*=2;const i=new Int32Array(l);i.set(this.ids),this.ids=i}const n=this.list.length;(n===0||this.list[n-1]!==e)&&this.list.push(e),this.ids[t]=this.list.length}get(t){const e=t<this.ids.length?this.ids[t]:0;return e===0?void 0:this.list[e-1]}}class b{constructor(){this.capacity=1024,this.count=0,this.rows=new Uint32Array(this.capacity),this.cols=new Uint16Array(this.capacity),this.kinds=new Uint8Array(this.capacity),this.styles=new Uint16Array(this.capacity),this.values=new Float64Array(this.capacity),this.formulas=null,this.vms=null}_grow(){const t=this.capacity*2,e=(n,l)=>{const i=new n(t);return i.set(l),i};this.rows=e(Uint32Array,this.rows),this.cols=e(Uint16Array,this.cols),this.kinds=e(Uint8Array,this.kinds),this.styles=e(Uint16Array,this.styles),this.values=e(Float64Array,this.values),this.capacity=t}push(t,e,n){this.count===this.capacity&&this._grow();const l=this.count++,i=t.kind(e,n)&~(N|z);if(this.rows[l]=e,this.cols[l]=n,this.kinds[l]=i,this.styles[l]=t.cellStyle(e,n),this.values[l]=t.value(e,n),i&v&&(this.formulas===null&&(this.formulas=new fe),this.formulas.set(l,t.formula(e,n))),t.valueMeta!==null){const s=t.valueMeta.get(e*w+n);s!==void 0&&(this.vms??=new Map).set(l,s)}}}class be{constructor(){this.sheets=[new T(`${G()}1`)],this.activeSheet=0,this.strings=new ne,this.styles=new ie,this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.source=null,this.formulasEdited=!1,this.edits=0,this._dirty=!1,this.engine=null,this.selectedSheets=null}get sheet(){return this.sheets[this.activeSheet]}get dirty(){return this._dirty}set dirty(t){t&&this.edits++,this._dirty=!!t}onChange(t){this.listeners.add(t)}_emit(t){this.dirty=!0;for(const e of this.listeners)e(t)}addSheet(t){const e=G();let n=1,l=t??`${e}${n}`;const i=o=>this.sheets.some(r=>r.name.toLowerCase()===o.toLowerCase());for(;i(l);)l=`${e}${++n}`;const s=new T(l);return this.sheets.push(s),this.activeSheet=this.sheets.length-1,this.engine?.sheetsChanged(),this._emit("sheets"),s}deleteSheet(t){if(this.sheets.filter(n=>!n.hidden).length<=1)return!1;this._shrink3D(t),this._refErrorsFor(t);const[e]=this.sheets.splice(t,1);if(this.selectedSheets?.delete(e),this._forgetSheet(e,t),this.engine)for(const[n,l]of this.engine.tables)l.sheet===e&&this.engine.tables.delete(n);for(this._reindexNames(n=>n===t?-1:n>t?n-1:n),this.activeSheet>=this.sheets.length&&(this.activeSheet=this.sheets.length-1);this.sheets[this.activeSheet].hidden;)this.activeSheet=(this.activeSheet+1)%this.sheets.length;return this.structureEdited=!0,this.engine?.sheetsChanged(),this.engine?.rebuild(),this._emit("sheets"),!0}_forgetSheet(t,e){const n=i=>i.sheet===t||i.sheet===void 0&&i.sheetIndex===e||(i.extra?.parts??[]).some(n),l=i=>{i.sheetIndex>e&&i.sheetIndex--;for(const s of i.extra?.parts??[])l(s)};for(const i of[this.undoStack,this.redoStack]){const s=i.filter(o=>!n(o));s.forEach(l),i.splice(0,i.length,...s)}}moveSheet(t,e){if(t===e)return;const n=this.sheet,[l]=this.sheets.splice(t,1);this.sheets.splice(e,0,l),this.activeSheet=this.sheets.indexOf(n);const i=o=>o===t?e:t<e?o>t&&o<=e?o-1:o:o>=e&&o<t?o+1:o,s=o=>{o.sheetIndex=i(o.sheetIndex);for(const r of o.extra?.parts??[])s(r)};for(const o of this.undoStack)s(o);for(const o of this.redoStack)s(o);this.structureEdited=!0,this._reindexNames(i),this.engine?.orderChanged(),this._emit("sheets")}_copyScopedNames(t,e,n){const{engine:l}=this;if(!l||l.names.size===0)return;const i=`${t}!`;let s=!1;for(const[o,r]of[...l.names])o.startsWith(i)&&(l.names.set(`${t+1}!${o.slice(i.length)}`,{...r,text:D(r.text,e.name,n.name)}),s=!0);s&&(this.namesChanged=!0)}_reindexNames(t){const{engine:e}=this;if(!e||e.names.size===0)return;const n=[];let l=!1;for(const[i,s]of e.names){const o=i.indexOf("!"),r=o<0?0:t(Number(i.slice(0,o)));o>=0&&r!==Number(i.slice(0,o))&&(l=!0),o<0?n.push([i,s]):r>=0&&n.push([`${r}!${i.slice(o+1)}`,s])}if(l){e.names.clear();for(const[i,s]of n)e.names.set(i,s);e.nameTemplates.clear(),this.namesChanged=!0,e.rebuild()}}duplicateSheet(t){const e=this.sheets[t];let l=`${e.name} (2)`,i=2;for(;this.sheets.some(a=>a.name.toLowerCase()===l.toLowerCase());)l=`${e.name} (${++i})`;const s=new T(l);e.columns.forEach((a,h)=>{const u=[];a.forEach((c,g)=>{u[g]={kinds:c.kinds.slice(),values:c.values.slice(),styles:c.styles?c.styles.slice():null}}),s.columns[h]=u}),s.maxRow=e.maxRow,s.maxCol=e.maxCol,s.rows=e.rows.shifted(0,0),s.cols=e.cols.shifted(0,0);const o=new Map;e.formulas.forEachCell((a,h,u)=>{let c=o.get(u);c===void 0&&(c={...u,tpl:void 0},o.set(u,c)),s.setFormula(a,h,c)}),s.merges=e.merges.map(a=>({...a})),s.rowStyles=e.rowStyles?new Map(e.rowStyles):null,s.colStyles=e.colStyles?new Map(e.colStyles):null,s.frozenRows=e.frozenRows,s.frozenCols=e.frozenCols,s.showGridlines=e.showGridlines,s.cellTypes=e.cellTypes?new Map(e.cellTypes):null,s.sparkRules=e.sparkRules,s.cellDropdowns=e.cellDropdowns?new Map(e.cellDropdowns):null,s.cellTags=e.cellTags?new Map(e.cellTags):null,s.cellButtons=e.cellButtons?new Map(e.cellButtons):null,s.cellStates=e.cellStates?e.cellStates.slice():null,s.autoMerges=e.autoMerges?e.autoMerges.map(a=>({...a})):null,s.background=e.background,s.outlineColumn=e.outlineColumn?{...e.outlineColumn}:null,s.frozenTrailingRows=e.frozenTrailingRows,s.frozenTrailingCols=e.frozenTrailingCols,s.hideZeros=e.hideZeros,s.hideHeadings=e.hideHeadings,s.isChartSheet=e.isChartSheet,s.hideOutline=e.hideOutline,s.gridColorId=e.gridColorId,s.areaOffset=e.areaOffset,s.selectionPolicy=e.selectionPolicy,s.selectionUnit=e.selectionUnit,s.gridlineAxes=e.gridlineAxes,s.gridColor=e.gridColor,s.tabStyles=e.tabStyles;const r=x;return s.cf=r(e.cf),s.validations=r(e.validations),s.comments=r(e.comments),s.threads=r(e.threads),s.hyperlinks=e.hyperlinks?e.hyperlinks.map(a=>({...r({...a,_ranges:void 0})})):e.hyperlinks,s.autoFilter=r(e.autoFilter),s.filteredRows=e.filteredRows?new Set(e.filteredRows):e.filteredRows,s.pageSetup=r(e.pageSetup),s.tabColor=e.tabColor,s.protection=r(e.protection),s.rtl=e.rtl,s.zoom=e.zoom,s.valueMeta=e.valueMeta?new Map(e.valueMeta):null,s.colsChanged=!0,s.viewChanged=!0,this.sheets.splice(t+1,0,s),this.activeSheet=t+1,this._reindexNames(a=>a>t?a+1:a),this._copyScopedNames(t,e,s),this.structureEdited=!0,this.engine?.sheetsChanged(),this.engine?.rebuild(),this._emit("sheets"),s}sheetNameProblem(t,e){const n=e.trim().slice(0,31);return!n||/[\\/?*[\]:]/.test(n)||/^'|'$/.test(n)?"rules":n.toLowerCase()==="history"?"reserved":this.sheets.some((l,i)=>i!==t&&l.name.toLowerCase()===n.toLowerCase())?"taken":null}renameSheet(t,e){const n=e.trim().slice(0,31);if(this.sheetNameProblem(t,e)!==null)return!1;const l=this.sheets[t].name;this.sheets[t].name=n,this._renameInFormulas(l,n);for(const i of re)i(this,l,n);return this.engine?.sheetsChanged(),this._emit("sheets"),!0}_shrink3D(t){const e=this.sheets[t].name.toLowerCase(),n=r=>this.sheets.findIndex(a=>a.name.toLowerCase()===r.toLowerCase()),l=r=>r[0]==="'"?r.slice(1,-1).replace(/''/g,"'"):r,i=/((?:'(?:[^']|'')+'|[A-Za-z_\u00C0-\uFFFF][\w.\u00C0-\uFFFF]*)):((?:'(?:[^']|'')+'|[A-Za-z_\u00C0-\uFFFF][\w.\u00C0-\uFFFF]*))!/g,s=r=>r.replace(i,(a,h,u,c)=>{if(r[c-1]==="]")return a;const g=l(h),p=l(u);if(g.toLowerCase()!==e&&p.toLowerCase()!==e)return a;let f=n(g),S=n(p);if(f<0||S<0||(f>S&&([f,S]=[S,f]),f===t&&f++,S===t&&S--,f>S))return a;const d=y=>ee(this.sheets[y].name);return f===S?`${d(f)}!`:`${d(f)}:${d(S)}!`}),o=r=>r.includes(":")&&r.includes("!")?r.split(/("(?:[^"]|"")*")/).map((a,h)=>h%2?a:s(a)).join(""):r;for(const r of this.sheets){const a=new Map;r.formulas.forEachCell((h,u,c)=>{let g=a.get(c);if(g===void 0){const p=c.f??c.sf,f=typeof p=="string"?o(p):p;g=f===p?null:c.f!==void 0?{...c,f,tpl:void 0}:{...c,sf:f,tpl:void 0},a.set(c,g)}g!==null&&r.setFormula(h,u,g)})}for(const r of this.engine?.names.values()??[])typeof r.text=="string"&&(r.text=o(r.text));this.engine?.templates.clear()}_refErrorsFor(t){const e=q(this.sheets[t].name),n=s=>s.split(/("(?:[^"]|"")*")/).map((o,r)=>r%2?o:o.replace(e,"#REF!")).join(""),l=s=>typeof s=="string"&&s!==""?n(s):s,i=this.sheets[t];for(const s of this.sheets){if(s===i)continue;s.cf?.length>0&&(s.cf=s.cf.map(r=>({...r,rules:r.rules.map(a=>oe(a,l))})),s.cfChanged=!0,s.cfEval?.invalidate()),s.validations?.length>0&&(s.validations=s.validations.map(r=>({...r,formula1:l(r.formula1),formula2:l(r.formula2)})),s.validationsChanged=!0);const o=new Map;s.formulas.forEachCell((r,a,h)=>{let u=o.get(h);if(u===void 0){const c=h.f??h.sf,g=typeof c=="string"?n(c):c;u=g===c?null:h.f!==void 0?{...h,f:g,tpl:void 0}:{...h,sf:g,tpl:void 0},o.set(h,u)}u!==null&&(s.setFormula(r,a,u),this.formulasEdited=!0)})}for(const s of this.engine?.names.values()??[])typeof s.text=="string"&&(s.text=n(s.text));this.engine?.templates.clear()}_renameInFormulas(t,e){const n=q(t);let l=!1;for(const i of this.sheets){const s=new Map;i.formulas.forEachCell((o,r,a)=>{let h=s.get(a);if(h===void 0){const u=a.f??a.sf;if(u===void 0||!n.test(u))n.lastIndex=0,h=null;else{n.lastIndex=0;const c=D(u,t,e);h=a.f!==void 0?{...a,f:c,tpl:void 0}:{...a,sf:c,tpl:void 0}}s.set(a,h)}h!==null&&(i.setFormula(o,r,h),l=!0)})}l&&(this.formulasEdited=!0,this.engine?.templates.clear(),this.engine?.rebuild())}editText(t,e,n){const l=t.kind(e,n);if(this.engine?.dataTables.length){const o=this.engine.dataTableAt(t,e,n);if(o){const{info:r}=o,a=r.dt2D==="1",h=r.dtr==="1";return`{=TABLE(${a||h?r.r1:""},${a?r.r2:h?"":r.r1})}`}}if(l&X&&this.engine){const o=this.engine.spillMaster(t,e,n);if(o)return this.editText(t,o.row,o.col)}if(l&v){const o=t.formula(e,n);if(o&&o.f!==void 0){const r="="+K(o.f);return o.t==="array"&&!o.cm?`{${r}}`:r}if(o&&o.sf!==void 0){const r=Math.floor(o.base/w),a=o.base-r*w;return"="+K(se(o.sf,e-r,n-a))}}const i=l&Y;if(i===_)return"";const s=t.value(e,n);if(i===F&&t.valueMeta!==null&&!(l&v)){const o=this.richImages?.get(t.valueMeta.get(e*w+n));if(o!==void 0)return o.alt??"";const r=this.richValues?.indexOfVm(t.valueMeta.get(e*w+n))??-1,a=r>=0?this.richValues.view(r):null;if(a!==null)return a.text}return i===R?this.styles.get(t.style(e,n)).quotePrefix?`'${this.strings.get(s)}`:this.strings.get(s):i===I?s?"TRUE":"FALSE":i===F?Z[s]??"#N/A":String(s)}transact(t,e){if(this.guard&&!this.guard(t))return;const n=this.selectedSheets,l=n!==null&&n.size>1&&ue.has(t)?this._runGroup(t,e,n):this._runOn(this.sheet,t,e);l!==null&&this._pushUndo(l)}transactOn(t,e,n){const l=this._runOn(t,e,n);l!==null&&this._pushUndo(l)}_runOn(t,e,n){const l=new b,i={sheet:t,log:l,saveCell:(h,u)=>l.push(t,h,u)},s=n(i)??null;e!=="entry"&&this.engine?.presentationChanged(),t.changes!==null&&l.count>0&&V(this,t,l),l.vms!==null&&de(t,l);const o=l.count>0&&this.engine?.tables.size>0?J(this,i,l):null,r=(h,u)=>c=>r(h(c),u(c)),a=s&&o?r(s,o):s??o;return l.count===0&&a===null?null:(t.revision++,this.engine?.cellsChanged(t,l.rows,l.cols,l.count),{sheetIndex:t===this.sheet?this.activeSheet:this.sheets.indexOf(t),sheet:t,log:l,label:e,extra:a})}_runGroup(t,e,n){const l=[];for(const i of this.sheets){if(!n.has(i)||i.protection&&i!==this.sheet)continue;const s=this._runOn(i,t,e);s!==null&&l.push(s)}return l.length===0?null:{sheetIndex:this.activeSheet,sheet:this.sheet,log:new b,label:t,extra:O(this,l)}}runSlice(t,e,n){const l=this._runOn(t,e,n);return l!==null&&this._emit("cells"),l}pushFolded(t,e,n){t.length!==0&&this._pushUndo({sheetIndex:this.sheets.indexOf(n),sheet:n,log:new b,label:e,extra:O(this,t)})}rollbackSlices(t){for(let e=t.length-1;e>=0;e--)this._restore(t[e]);this._emit("cells")}_pushUndo(t){this.allowUndo===!1?this.undoStack.length=0:(this.undoStack.push(t),this.undoStack.length>(this.historyLimit??ce)&&this.undoStack.shift()),this.redoStack.length=0,this._emit("cells")}_restore(t){const e=t.sheet??this.sheets[t.sheetIndex],{log:n}=t,l=new b;for(let o=n.count-1;o>=0;o--){const r=n.rows[o],a=n.cols[o];l.push(e,r,a),e.setCell(r,a,n.kinds[o],n.values[o]),e.setStyle(r,a,n.styles[o]),e.setFormula(r,a,n.kinds[o]&v?n.formulas.get(o):null)}if(n.vms!==null){e.valueMeta=new Map(e.valueMeta??[]);for(const[o,r]of n.vms)e.valueMeta.set(n.rows[o]*w+n.cols[o],r)}let i=null;t.extra&&(i=t.extra(e)),this.engine?.presentationChanged(),e.changes!==null&&n.count>0&&V(this,e,l),e.revision++,this.engine?.cellsChanged(e,n.rows,n.cols,n.count);const s=this.sheets.indexOf(e);return s>=0&&(this.activeSheet=s),{sheetIndex:s>=0?s:t.sheetIndex,sheet:e,log:l,label:t.label,extra:i}}undo(){const t=this.undoStack.pop();return t?(this.redoStack.push(this._restore(t)),this._emit("cells"),!0):!1}redo(){const t=this.redoStack.pop();return t?(this.undoStack.push(this._restore(t)),this._emit("cells"),!0):!1}setInput(t,e,n,l){const{sheet:i}=t;this.recorder?.push(`sheet.setValue(${JSON.stringify(Q(e,n))}, ${JSON.stringify(l)});`),t.saveCell(e,n),i.setFormula(e,n,null);const s=i.cellStyle(e,n),r=l!==""&&this.styles.get(i.style(e,n)).numFmt==="@"?{kind:R,text:l[0]==="'"?l.slice(1):l}:H(l),a=l[0]==="'"&&l.length>1;switch((a||s!==0&&this.styles.get(s).quotePrefix)&&i.setStyle(e,n,this.styles.derive(s,{quotePrefix:a})),r.kind){case _:i.setCell(e,n,_,0);break;case P:i.setCell(e,n,P,r.value),r.format&&(i.cellStyle(e,n)===0||this.styles.get(i.cellStyle(e,n)).numFmt==="General")&&i.setStyle(e,n,this.styles.derive(i.cellStyle(e,n),{numFmt:r.format}));break;case I:i.setCell(e,n,I,r.value);break;case F:i.setCell(e,n,F,r.value);break;case v:i.setCell(e,n,v|_,0),i.setFormula(e,n,{f:he(this._expandTableRefs(j(r.formula,this.engine?.tables),i,e,n),this.engine?.names??null),typed:this.dynamicArrays!==!1}),this.formulasEdited=!0;break;default:i.setCell(e,n,R,this.strings.add(r.text))}}setRichInput(t,e,n,l,i){const{sheet:s}=t;t.saveCell(e,n),s.setFormula(e,n,null),s.setCell(e,n,R,this.strings.addRich(l,i))}_expandTableRefs(t,e,n,l){const i=this.engine;return!i||i.tables.size===0?t:ae(t,()=>{for(const s of i.tables.values())if(s.sheet===e&&n>=s.r0&&n<=s.r1&&l>=s.c0&&l<=s.c1)return s;return null})}clearRange(t,e="contents",{visibleOnly:n=!1}={}){this.sheet.dataRanges?.cleared(t)||this.transact("clear",l=>{const{sheet:i}=l,s=[];if(e!=="contents")for(const{r0:r,c0:a,r1:h,c1:u}of t){const c=r===0&&h===B-1,g=a===0&&u===w-1,p=(f,S,d,y)=>{for(const[C,k]of[...S])C<d||C>y||(s.push([f,C,k]),S.delete(C))};c&&i.colStyles!==null&&p("col",i.colStyles,a,u),g&&i.rowStyles!==null&&p("row",i.rowStyles,r,h)}const o=n&&i.filteredRows?.size>0?i.filteredRows:null;for(const{r0:r,c0:a,r1:h,c1:u}of t){const c=Math.min(u,i.maxCol),g=Math.min(h,i.maxRow);for(let p=a;p<=c;p++)if(i.columns[p]!==void 0)for(let f=r;f<=g;f++){if(i._chunk(f,p)===void 0){f|=1023;continue}if(o!==null&&o.has(f))continue;const d=i.kind(f,p)!==0,y=i.cellStyle(f,p)!==0;if(e==="formats"){if(!y)continue;l.saveCell(f,p),i.setStyle(f,p,0);continue}!d&&!(e==="all"&&y)||(l.saveCell(f,p),i.setCell(f,p,_,0),i.setFormula(f,p,null),e==="all"&&i.setStyle(f,p,0))}}return s.length>0?E([],s):void 0})}applyStyle(t,e){const n=JSON.stringify(e);if(this.recorder)for(const l of t)this.recorder.push(`sheet.setFormat(${JSON.stringify(te(l))}, ${n});`);this.transact("format",l=>{const{sheet:i}=l;this.strings.rich!==null&&le(this,l,t,e);const s=[],o=new Set,r=[];for(const{r0:a,c0:h,r1:u,c1:c}of t){const g=a===0&&u===B-1,p=h===0&&c===w-1;if(g){i.colStyles===null&&(i.colStyles=new Map);for(let d=h;d<=c;d++){const y=i.colStyles.get(d);r.push(["col",d,y]),i.colStyles.set(d,this.styles.derive(y??0,e,n))}if(p&&i.rowStyles!==null)for(const[d,y]of i.rowStyles)r.push(["row",d,y]),i.rowStyles.set(d,this.styles.derive(y,e,n))}else if(p){i.rowStyles===null&&(i.rowStyles=new Map);for(let d=a;d<=u;d++){const y=i.rowStyles.get(d);r.push(["row",d,y]),i.rowStyles.set(d,this.styles.derive(y??0,e,n))}}const f=g?i.maxRow:u,S=p?i.maxCol:c;for(let d=h;d<=S;d++)for(let y=a>>>A;y<=f>>>A;y++){const C=y<<A,k=Math.max(a,C),L=Math.min(f,C+W);if(k>L)continue;const $=i._ensure(k,d),U=d*2048+y;o.has(U)||(o.add(U),s.push(d,y,$.styles===null?null:$.styles.slice()));for(let M=k;M<=L;M++)i.setStyle(M,d,this.styles.derive(i.style(M,d),e,n))}}return E(s,r)})}}function O(m,t){const e=()=>{const n=[];for(let l=t.length-1;l>=0;l--)n.push(m._restore(t[l]));return O(m,n)};return e.parts=t,e}function de(m,t){let e=null;for(const n of t.vms.keys()){const l=t.rows[n],i=t.cols[n];(m.kind(l,i)&~(N|z))===t.kinds[n]&&m.value(l,i)===t.values[n]||(e??=new Map(m.valueMeta),e.delete(l*w+i))}e!==null&&(m.valueMeta=e.size>0?e:null)}function x(m){if(m===null||typeof m!="object")return m;if(Array.isArray(m))return m.map(x);if(m instanceof Map)return new Map([...m].map(([e,n])=>[e,x(n)]));if(m instanceof Set)return new Set([...m].map(x));if(ArrayBuffer.isView(m))return m.slice();const t={};for(const[e,n]of Object.entries(m))!e.startsWith("_")&&typeof n!="function"&&(t[e]=x(n));return t}function E(m,t){return e=>{const n=[];for(let i=0;i<m.length;i+=3){const s=m[i],o=m[i+1],r=e.columns[s]?.[o];r!==void 0&&(n.push(s,o,r.styles),r.styles=m[i+2])}const l=[];for(const[i,s,o]of t){const r=i==="col"?"colStyles":"rowStyles",a=e[r]??=new Map;l.push([i,s,a.get(s)]),o===void 0?a.delete(s):a.set(s,o)}return E(n,l)}}export{b as CellLog,ue as GROUP_LABELS,be as Workbook,O as foldEntries,H as parseInput,E as swapStyles};
|
package/i18n/en/common.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={OK:"OK",Cancel:"Cancel",Close:"Close",Apply:"Apply",Add:"Add","Add…":"Add…",Delete:"Delete","Delete…":"Delete…",Remove:"Remove",Edit:"Edit","Edit…":"Edit…",New:"New","New…":"New…",Yes:"Yes",No:"No",Back:"Back",Next:"Next",Finish:"Finish",Reset:"Reset",Clear:"Clear",Options:"Options","Options…":"Options…",Save:"Save",Open:"Open","Open…":"Open…",Rename:"Rename","Rename…":"Rename…","Move Up":"Move Up","Move Down":"Move Down",Done:"Done",Insert:"Insert","Insert…":"Insert…",Copy:"Copy",Cut:"Cut",Paste:"Paste",Undo:"Undo",Redo:"Redo","Select All":"Select All",Find:"Find",Replace:"Replace",Print:"Print","Print…":"Print…",Preview:"Preview",Refresh:"Refresh",Settings:"Settings",Properties:"Properties","Properties…":"Properties…",Name:"Name","Name:":"Name:",Type:"Type","Type:":"Type:",Value:"Value",Values:"Values",Text:"Text",Number:"Number",Date:"Date",Time:"Time",Color:"Color",Colors:"Colors",Font:"Font",Fonts:"Fonts",Size:"Size",Style:"Style",Styles:"Styles",Width:"Width",Height:"Height",None:"None",Automatic:"Automatic",General:"General",Other:"Other",Default:"Default",All:"All",Sheet:"Sheet",Workbook:"Workbook",Cell:"Cell",Cells:"Cells",Range:"Range",Row:"Row",Rows:"Rows",Column:"Column",Columns:"Columns",Table:"Table",Chart:"Chart",Shape:"Shape",Picture:"Picture",Title:"Title",Description:"Description",Format:"Format","Format Cells":"Format Cells","Format Cells…":"Format Cells…",Hide:"Hide",Unhide:"Unhide",Show:"Show","Show All":"Show All",Ascending:"Ascending",Descending:"Descending",Sort:"Sort",Filter:"Filter",Group:"Group",Ungroup:"Ungroup",Source:"Source",Formula:"Formula",Formulas:"Formulas",Function:"Function",Functions:"Functions",Data:"Data",On:"On",Off:"Off",Error:"Error",Warning:"Warning",Information:"Information",Password:"Password","Password:":"Password:",Comment:"Comment",Comments:"Comments",Note:"Note",Notes:"Notes",Link:"Link",Links:"Links","Not available yet":"Not available yet","{name} options":"{name} options","{count} cells":{one:"{count} cell",other:"{count} cells"},"Theme Colors":"Theme Colors","Standard Colors":"Standard Colors","No Fill":"No Fill","No Color":"No Color","More Colors…":"More Colors…",Preferences:"Preferences","Preferences…":"Preferences…",Region:"Region","Region…":"Region…","Region:":"Region:",Language:"Language","Language:":"Language:","Interface Language":"Interface Language","Interface Language…":"Interface Language…","prefs|Edit…":"Edit…","Formula Language…":"Formula Language…","Menus, dialogs and messages show in this language. Numbers, dates and formula separators follow the region, and function names the formula language.":"Menus, dialogs and messages show in this language. Numbers, dates and formula separators follow the region, and function names the formula language.",File:"File","Open (⌘O)":"Open (⌘O)","Save (⌘S)":"Save (⌘S)","Undo (⌘Z)":"Undo (⌘Z)","Redo (⇧⌘Z)":"Redo (⇧⌘Z)","Switch light or dark":"Switch light or dark","Ribbon tabs":"Ribbon tabs","Show Ribbon Tab":"Show Ribbon Tab",Ribbon:"Ribbon","Name box":"Name box","Cancel (Esc)":"Cancel (Esc)",Enter:"Enter","Formula bar":"Formula bar","Worksheet grid":"Worksheet grid","Worksheet input":"Worksheet input","Cell editor":"Cell editor","Drop an .xlsx file to open it":"Drop an .xlsx file to open it","Task pane":"Task pane","Previous sheet":"Previous sheet","Next sheet":"Next sheet",Sheets:"Sheets","New sheet":"New sheet",Zoom:"Zoom","Zoom…":"Zoom…","{name} (unsaved)":"{name} (unsaved)","[Group]":"[Group]","tab|Home":"Home","tab|Insert":"Insert","tab|Draw":"Draw","tab|Page Layout":"Page Layout","tab|Formulas":"Formulas","tab|Data":"Data","tab|Review":"Review","tab|View":"View","tab|Automate":"Automate","tab|Chart Design":"Chart Design","tab|Format":"Format","tab|Picture Format":"Picture Format","tab|Shape Format":"Shape Format","tab|PivotTable Analyze":"PivotTable Analyze","tab|Design":"Design","tab|Table Design":"Table Design","tab|Sparkline":"Sparkline","tab|Slicer":"Slicer","tab|Timeline":"Timeline","tab|Table Sheet":"Table Sheet","tab|Plan":"Plan","tab|Report":"Report","tab|Bindings":"Bindings","tab|Header & Footer":"Header & Footer","fc.tab|Number":"Number","fc.tab|Alignment":"Alignment","fc.tab|Font":"Font","fc.tab|Border":"Border","fc.tab|Fill":"Fill","fc.tab|Protection":"Protection","Corner radius in points":"Corner radius in points","Corner radius applies to":"Corner radius applies to","Every cell":"Every cell","Outer corners of the selection":"Outer corners of the selection","Rounded corners (points, not in Excel):":"Rounded corners (points, not in Excel):","This number format can't be used. {problem}":"This number format can't be used. {problem}","Enter a number from {min} to {max}":"Enter a number from {min} to {max}",Ready:"Ready","mode|Ready":"Ready","mode|Enter":"Enter","mode|Edit":"Edit","mode|Point":"Point","Cell Mode":"Cell Mode","Caps Lock":"Caps Lock","Num Lock":"Num Lock","Scroll Lock":"Scroll Lock","Fixed Decimal":"Fixed Decimal","Overtype Mode":"Overtype Mode",Overtype:"Overtype","End Mode":"End Mode","Selection Mode":"Selection Mode","Extend Selection":"Extend Selection","Add to Selection":"Add to Selection","Page Number":"Page Number","Page {page} of {count}":"Page {page} of {count}","{count} pages":{one:"{count} page",other:"{count} pages"},Average:"Average",Count:"Count","Numerical Count":"Numerical Count",Minimum:"Minimum",Maximum:"Maximum",Sum:"Sum","status|Average":"Average","status|Count":"Count","status|Numerical Count":"Numerical Count","status|Min":"Min","status|Max":"Max","status|Sum":"Sum","Upload Status":"Upload Status","View Shortcuts":"View Shortcuts","Zoom Slider":"Zoom Slider",Normal:"Normal","Page Layout":"Page Layout","Page Break Preview":"Page Break Preview","name|Book":"Book","name|Sheet":"Sheet","name|Table":"Table","name|Column":"Column","name|Total":"Total","name|PivotTable":"PivotTable","name|Chart":"Chart"};export{e as default};
|
|
1
|
+
var e={OK:"OK",Cancel:"Cancel",Close:"Close",Apply:"Apply",Add:"Add","Add…":"Add…",Delete:"Delete","Delete…":"Delete…",Remove:"Remove",Edit:"Edit","Edit…":"Edit…",New:"New","New…":"New…",Yes:"Yes",No:"No",Back:"Back",Next:"Next",Finish:"Finish",Reset:"Reset",Clear:"Clear",Options:"Options","Options…":"Options…",Save:"Save",Open:"Open","Open…":"Open…",Rename:"Rename","Rename…":"Rename…","Move Up":"Move Up","Move Down":"Move Down",Done:"Done",Insert:"Insert","Insert…":"Insert…",Copy:"Copy",Cut:"Cut",Paste:"Paste",Undo:"Undo",Redo:"Redo","Select All":"Select All",Find:"Find",Replace:"Replace",Print:"Print","Print…":"Print…",Preview:"Preview",Refresh:"Refresh",Settings:"Settings",Properties:"Properties","Properties…":"Properties…",Name:"Name","Name:":"Name:",Type:"Type","Type:":"Type:",Value:"Value",Values:"Values",Text:"Text",Number:"Number",Date:"Date",Time:"Time",Color:"Color",Colors:"Colors",Font:"Font",Fonts:"Fonts",Size:"Size",Style:"Style",Styles:"Styles",Width:"Width",Height:"Height",None:"None",Automatic:"Automatic",General:"General",Other:"Other",Default:"Default",All:"All",Sheet:"Sheet",Workbook:"Workbook",Cell:"Cell",Cells:"Cells",Range:"Range",Row:"Row",Rows:"Rows",Column:"Column",Columns:"Columns",Table:"Table",Chart:"Chart",Shape:"Shape",Picture:"Picture",Title:"Title",Description:"Description",Format:"Format","Format Cells":"Format Cells","Format Cells…":"Format Cells…",Hide:"Hide",Unhide:"Unhide",Show:"Show","Show All":"Show All",Ascending:"Ascending",Descending:"Descending",Sort:"Sort",Filter:"Filter",Group:"Group",Ungroup:"Ungroup",Source:"Source",Formula:"Formula",Formulas:"Formulas",Function:"Function",Functions:"Functions",Data:"Data",On:"On",Off:"Off",Error:"Error",Warning:"Warning",Information:"Information",Password:"Password","Password:":"Password:",Comment:"Comment",Comments:"Comments",Note:"Note",Notes:"Notes",Link:"Link",Links:"Links","Not available yet":"Not available yet","{name} options":"{name} options","{count} cells":{one:"{count} cell",other:"{count} cells"},"Theme Colors":"Theme Colors","Standard Colors":"Standard Colors","No Fill":"No Fill","No Color":"No Color","More Colors…":"More Colors…",Preferences:"Preferences","Preferences…":"Preferences…",Region:"Region","Region…":"Region…","Region:":"Region:",Language:"Language","Language:":"Language:","Interface Language":"Interface Language","Interface Language…":"Interface Language…","prefs|Edit…":"Edit…","Formula Language…":"Formula Language…","Menus, dialogs and messages show in this language. Numbers, dates and formula separators follow the region, and function names the formula language.":"Menus, dialogs and messages show in this language. Numbers, dates and formula separators follow the region, and function names the formula language.",File:"File","Open (⌘O)":"Open (⌘O)","Save (⌘S)":"Save (⌘S)","Undo (⌘Z)":"Undo (⌘Z)","Redo (⇧⌘Z)":"Redo (⇧⌘Z)","Switch light or dark":"Switch light or dark","Ribbon tabs":"Ribbon tabs","Show Ribbon Tab":"Show Ribbon Tab",Ribbon:"Ribbon","Name box":"Name box","Cancel (Esc)":"Cancel (Esc)",Enter:"Enter","Formula bar":"Formula bar","Worksheet grid":"Worksheet grid","Worksheet input":"Worksheet input","Cell editor":"Cell editor","Drop an .xlsx file to open it":"Drop an .xlsx file to open it","Task pane":"Task pane","Previous sheet":"Previous sheet","Next sheet":"Next sheet",Sheets:"Sheets","New sheet":"New sheet",Zoom:"Zoom","Zoom…":"Zoom…","{name} (unsaved)":"{name} (unsaved)","Unsaved changes":"Unsaved changes",Saved:"Saved","Search for commands (⌥Q)":"Search for commands (⌥Q)","Search for commands":"Search for commands","No matching commands":"No matching commands","[Group]":"[Group]","tab|Home":"Home","tab|Insert":"Insert","tab|Draw":"Draw","tab|Page Layout":"Page Layout","tab|Formulas":"Formulas","tab|Data":"Data","tab|Review":"Review","tab|View":"View","tab|Automate":"Automate","tab|Chart Design":"Chart Design","tab|Format":"Format","tab|Picture Format":"Picture Format","tab|Shape Format":"Shape Format","tab|PivotTable Analyze":"PivotTable Analyze","tab|Design":"Design","tab|Table Design":"Table Design","tab|Sparkline":"Sparkline","tab|Slicer":"Slicer","tab|Timeline":"Timeline","tab|Table Sheet":"Table Sheet","tab|Plan":"Plan","tab|Report":"Report","tab|Bindings":"Bindings","tab|Header & Footer":"Header & Footer","fc.tab|Number":"Number","fc.tab|Alignment":"Alignment","fc.tab|Font":"Font","fc.tab|Border":"Border","fc.tab|Fill":"Fill","fc.tab|Protection":"Protection","Corner radius in points":"Corner radius in points","Corner radius applies to":"Corner radius applies to","Every cell":"Every cell","Outer corners of the selection":"Outer corners of the selection","Rounded corners (points, not in Excel):":"Rounded corners (points, not in Excel):","This number format can't be used. {problem}":"This number format can't be used. {problem}","Enter a number from {min} to {max}":"Enter a number from {min} to {max}",Ready:"Ready","mode|Ready":"Ready","mode|Enter":"Enter","mode|Edit":"Edit","mode|Point":"Point","Cell Mode":"Cell Mode","Caps Lock":"Caps Lock","Num Lock":"Num Lock","Scroll Lock":"Scroll Lock","Fixed Decimal":"Fixed Decimal","Overtype Mode":"Overtype Mode",Overtype:"Overtype","End Mode":"End Mode","Selection Mode":"Selection Mode","Extend Selection":"Extend Selection","Add to Selection":"Add to Selection","Page Number":"Page Number","Page {page} of {count}":"Page {page} of {count}","{count} pages":{one:"{count} page",other:"{count} pages"},Average:"Average",Count:"Count","Numerical Count":"Numerical Count",Minimum:"Minimum",Maximum:"Maximum",Sum:"Sum","status|Average":"Average","status|Count":"Count","status|Numerical Count":"Numerical Count","status|Min":"Min","status|Max":"Max","status|Sum":"Sum","Upload Status":"Upload Status","View Shortcuts":"View Shortcuts","Zoom Slider":"Zoom Slider",Normal:"Normal","Page Layout":"Page Layout","Page Break Preview":"Page Break Preview","name|Book":"Book","name|Sheet":"Sheet","name|Table":"Table","name|Column":"Column","name|Total":"Total","name|PivotTable":"PivotTable","name|Chart":"Chart"};export{e as default};
|