@allyhub/sdk 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/node_modules/@allyhub/audio/dist/plan.d.ts +3 -0
- package/dist/node_modules/@allyhub/audio/dist/render.js +1 -1
- package/dist/node_modules/@allyhub/audio/package.json +1 -1
- package/dist/node_modules/@allyhub/chart/dist/chart-file.d.ts +2 -0
- package/dist/node_modules/@allyhub/chart/dist/chart-file.js +1 -1
- package/dist/node_modules/@allyhub/chart/dist/chart-xml.js +3 -2
- package/dist/node_modules/@allyhub/chart/dist/chart.d.ts +5 -12
- package/dist/node_modules/@allyhub/chart/dist/chart.js +2 -1
- package/dist/node_modules/@allyhub/chart/dist/color.d.ts +37 -0
- package/dist/node_modules/@allyhub/chart/dist/color.js +2 -0
- package/dist/node_modules/@allyhub/chart/dist/index.d.ts +1 -0
- package/dist/node_modules/@allyhub/chart/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/chart/dist/svg.js +1 -1
- package/dist/node_modules/@allyhub/chart/package.json +1 -1
- package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/deck-code.d.ts +130 -0
- package/dist/node_modules/@allyhub/formats/dist/data/deck-code.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/gen.d.ts +3 -1
- package/dist/node_modules/@allyhub/formats/dist/data/gen.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/sheet.d.ts +512 -166
- package/dist/node_modules/@allyhub/formats/dist/data/sheet.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +2523 -136
- package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +931 -87
- package/dist/node_modules/@allyhub/formats/dist/schemas.js +1 -1
- package/dist/node_modules/@allyhub/formats/package.json +1 -1
- package/dist/node_modules/@allyhub/image-draw/package.json +1 -1
- package/dist/node_modules/@allyhub/image-measure/package.json +1 -1
- package/dist/node_modules/@allyhub/image-sdk/package.json +1 -1
- package/dist/node_modules/@allyhub/measure/package.json +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/color.d.ts +11 -0
- package/dist/node_modules/@allyhub/ooxml/dist/color.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/ext.d.ts +43 -0
- package/dist/node_modules/@allyhub/ooxml/dist/ext.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/index.d.ts +2 -1
- package/dist/node_modules/@allyhub/ooxml/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/transform.d.ts +13 -0
- package/dist/node_modules/@allyhub/ooxml/dist/transform.js +2 -0
- package/dist/node_modules/@allyhub/ooxml/package.json +5 -1
- package/dist/node_modules/@allyhub/piece/dist/gen.d.ts +4 -4
- package/dist/node_modules/@allyhub/piece/dist/media.d.ts +2 -2
- package/dist/node_modules/@allyhub/piece/package.json +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/account.d.ts +49 -5
- package/dist/node_modules/@allyhub/protocol/dist/account.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/auth.d.ts +56 -0
- package/dist/node_modules/@allyhub/protocol/dist/auth.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/cloud.d.ts +72 -9
- package/dist/node_modules/@allyhub/protocol/dist/cloud.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/editor.d.ts +35 -20
- package/dist/node_modules/@allyhub/protocol/dist/editor.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/errors.d.ts +7 -0
- package/dist/node_modules/@allyhub/protocol/dist/errors.js +2 -0
- package/dist/node_modules/@allyhub/protocol/dist/events.d.ts +328 -0
- package/dist/node_modules/@allyhub/protocol/dist/events.js +2 -0
- package/dist/node_modules/@allyhub/protocol/dist/frame.d.ts +28 -2
- package/dist/node_modules/@allyhub/protocol/dist/frame.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/index.d.ts +2 -0
- package/dist/node_modules/@allyhub/protocol/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/jobs.d.ts +6 -6
- package/dist/node_modules/@allyhub/protocol/dist/mail.d.ts +2 -2
- package/dist/node_modules/@allyhub/protocol/dist/routes.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/snapshots.d.ts +69 -6
- package/dist/node_modules/@allyhub/protocol/dist/snapshots.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/tools.d.ts +9 -9
- package/dist/node_modules/@allyhub/protocol/package.json +1 -1
- package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
- package/dist/node_modules/@allyhub/scenery/package.json +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/annotations.d.ts +14 -0
- package/dist/node_modules/@allyhub/sheet/dist/annotations.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/capabilities.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/index.d.ts +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/index.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/rules.d.ts +24 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/rules.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/styles.d.ts +12 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/workbook.d.ts +3 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/workbook.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/arrange.d.ts +28 -1
- package/dist/node_modules/@allyhub/sheet/dist/arrange.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/data-tools.d.ts +42 -0
- package/dist/node_modules/@allyhub/sheet/dist/data-tools.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/edit.d.ts +43 -2
- package/dist/node_modules/@allyhub/sheet/dist/edit.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/fill.d.ts +10 -0
- package/dist/node_modules/@allyhub/sheet/dist/fill.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/filter.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.d.ts +14 -0
- package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/html.js +10 -10
- package/dist/node_modules/@allyhub/sheet/dist/index.d.ts +6 -1
- package/dist/node_modules/@allyhub/sheet/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/outline.d.ts +30 -0
- package/dist/node_modules/@allyhub/sheet/dist/outline.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/rich.d.ts +29 -0
- package/dist/node_modules/@allyhub/sheet/dist/rich.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/rules.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/table-style.d.ts +6 -0
- package/dist/node_modules/@allyhub/sheet/dist/table-style.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/table-styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/workbook.d.ts +5 -1
- package/dist/node_modules/@allyhub/sheet/dist/workbook.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.d.ts +17 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.js +2 -2
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.d.ts +56 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.d.ts +6 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.js +1 -1
- package/dist/node_modules/@allyhub/sheet/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/animation.d.ts +117 -21
- package/dist/node_modules/@allyhub/slides-core/dist/animation.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/api.d.ts +181 -30
- package/dist/node_modules/@allyhub/slides-core/dist/api.js +3 -3
- package/dist/node_modules/@allyhub/slides-core/dist/capabilities.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/chart-api.d.ts +28 -2
- package/dist/node_modules/@allyhub/slides-core/dist/chart-api.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/check.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/enums.d.ts +222 -4
- package/dist/node_modules/@allyhub/slides-core/dist/enums.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/file.d.ts +6 -0
- package/dist/node_modules/@allyhub/slides-core/dist/file.js +3 -3
- package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.d.ts +3 -0
- package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/index.d.ts +3 -0
- package/dist/node_modules/@allyhub/slides-core/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/merge.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/model.d.ts +98 -10
- package/dist/node_modules/@allyhub/slides-core/dist/numbering.d.ts +6 -0
- package/dist/node_modules/@allyhub/slides-core/dist/numbering.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/office.d.ts +53 -0
- package/dist/node_modules/@allyhub/slides-core/dist/office.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/patterns.d.ts +8 -0
- package/dist/node_modules/@allyhub/slides-core/dist/patterns.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.d.ts +36 -6
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/script.d.ts +11 -0
- package/dist/node_modules/@allyhub/slides-core/dist/script.js +2 -2
- package/dist/node_modules/@allyhub/slides-core/dist/sdk.d.ts +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/sdk.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/table-style.d.ts +48 -0
- package/dist/node_modules/@allyhub/slides-core/dist/table-style.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-core/dist/mix-plan.js +1 -1
- package/dist/node_modules/@allyhub/video-core/dist/timeline.d.ts +4 -0
- package/dist/node_modules/@allyhub/video-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
- package/docs/defaults.md +78 -4
- package/docs/image.md +1 -1
- package/docs/pictures.md +1 -1
- package/docs/project.md +1 -1
- package/docs/sheets.md +19 -9
- package/docs/slides.md +30 -16
- package/docs/speech.md +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { SheetChart, SheetConditional, SheetFilterColumn, SheetSide, SheetValidation } from "@allyhub/formats";
|
|
1
|
+
import type { SheetChart, SheetConditional, SheetFilterColumn, SheetPrint, SheetSide, SheetValidation } from "@allyhub/formats";
|
|
2
2
|
import { type Area, type Place } from "./address.js";
|
|
3
3
|
import { Draft, type BookEdit, type EditBook } from "./edit.js";
|
|
4
|
+
import type { CellNote } from "./annotations.js";
|
|
4
5
|
import type { CellLook, Filter, Worksheet } from "./workbook.js";
|
|
5
6
|
/** Excel's Borders list. */
|
|
6
7
|
export declare const BORDER_PRESETS: readonly ["bottom", "top", "left", "right", "none", "all", "outside", "thickOutside", "bottomDouble", "thickBottom", "topBottom", "topThickBottom", "topDoubleBottom"];
|
|
@@ -42,6 +43,8 @@ export declare function setHidden(book: EditBook, sheetName: string, what: "rows
|
|
|
42
43
|
export declare function setSheetHidden(book: EditBook, sheetName: string, hidden: boolean): BookEdit;
|
|
43
44
|
/** A sheet's tab given a colour, or none. */
|
|
44
45
|
export declare function setTabColor(book: EditBook, sheetName: string, color: string | undefined): BookEdit;
|
|
46
|
+
/** View's and Page Layout's Gridlines: drawn on the sheet, or not. */
|
|
47
|
+
export declare function setGridlines(book: EditBook, sheetName: string, on: boolean): BookEdit;
|
|
45
48
|
/** Cmd+Shift+L: a filter on the selection's region, or off. A table's buttons go and come. */
|
|
46
49
|
export declare function toggleFilter(book: EditBook, sheetName: string, area: Area): BookEdit;
|
|
47
50
|
/** What one column of a filter keeps; nothing clears it. */
|
|
@@ -64,5 +67,29 @@ export declare function setChart(book: EditBook, sheetName: string, index: numbe
|
|
|
64
67
|
}): BookEdit;
|
|
65
68
|
/** A chart taken off its sheet. */
|
|
66
69
|
export declare function removeChart(book: EditBook, sheetName: string, index: number): BookEdit;
|
|
70
|
+
/** Review's New Note and Edit Note, and Delete Note with no text: written on the cell. */
|
|
71
|
+
export declare function setNote(book: EditBook, sheetName: string, at: Place, note: CellNote | undefined): BookEdit;
|
|
72
|
+
/**
|
|
73
|
+
* Insert's Link (Cmd+K) over an area, or Remove Link with none: what linked
|
|
74
|
+
* any of its cells goes first. A new link gives a cell with no colour of
|
|
75
|
+
* its own Excel's Hyperlink look, as Excel does.
|
|
76
|
+
*/
|
|
77
|
+
export declare function setLink(book: EditBook, sheetName: string, area: Area, to: string | undefined): BookEdit;
|
|
78
|
+
/** Excel's Hyperlink cell style: the Office theme's hyperlink colour, underlined. */
|
|
79
|
+
export declare const HYPERLINK_LOOK: CellLook;
|
|
80
|
+
/** Review's Protect Sheet and Unprotect Sheet: what is locked can change while it is off. */
|
|
81
|
+
export declare function setProtect(book: EditBook, sheetName: string, on: boolean): BookEdit;
|
|
82
|
+
/**
|
|
83
|
+
* Whether a protected sheet keeps any cell of an area as it is: a cell is
|
|
84
|
+
* locked unless its look says `locked: false`. Nothing on a sheet that is
|
|
85
|
+
* not protected.
|
|
86
|
+
*/
|
|
87
|
+
export declare function protectedIn(sheet: Worksheet, area: Area): boolean;
|
|
88
|
+
/** The Rules Manager's OK: the sheet's conditional formats as it left them, the strongest first. */
|
|
89
|
+
export declare function setConditionals(book: EditBook, sheetName: string, rules: readonly SheetConditional[]): BookEdit;
|
|
90
|
+
/** Page Layout's settings: what the patch names changes, a field it leaves undefined goes. */
|
|
91
|
+
export declare function setPrint(book: EditBook, sheetName: string, patch: {
|
|
92
|
+
[K in keyof SheetPrint]?: SheetPrint[K] | undefined;
|
|
93
|
+
}): BookEdit;
|
|
67
94
|
export {};
|
|
68
95
|
//# sourceMappingURL=arrange.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{MAX_COLUMNS as S,MAX_ROWS as A,cellName as E,columnIndex as _,columnLetter as O,overlaps as k,rangeName as w,readArea as y,readAreas as v}from"./address.js";import{Draft as g,applyLook as x,blankEdit as M,refused as d,tidied as D,writeOne as B,inputOf as j}from"./edit.js";import{regionAround as R}from"./filter.js";export const BORDER_PRESETS=["bottom","top","left","right","none","all","outside","thickOutside","bottomDouble","thickBottom","topBottom","topThickBottom","topDoubleBottom"];const a=(o,s)=>Object.fromEntries(Object.entries(o).filter(([t])=>t!==s)),p={top:o=>({...o,bottom:o.top}),bottom:o=>({...o,top:o.bottom}),left:o=>({...o,right:o.left}),right:o=>({...o,left:o.right})};function L(o,s,t){const n=e=>({...t,style:e});switch(o){case"bottom":return[{area:p.bottom(s),sides:{bottom:t}}];case"top":return[{area:p.top(s),sides:{top:t}}];case"left":return[{area:p.left(s),sides:{left:t}}];case"right":return[{area:p.right(s),sides:{right:t}}];case"all":return[{area:s,sides:{left:t,right:t,top:t,bottom:t}}];case"outside":case"thickOutside":{const e=o==="outside"?t:n("thick");return[{area:p.top(s),sides:{top:e}},{area:p.bottom(s),sides:{bottom:e}},{area:p.left(s),sides:{left:e}},{area:p.right(s),sides:{right:e}}]}case"bottomDouble":return[{area:p.bottom(s),sides:{bottom:n("double")}}];case"thickBottom":return[{area:p.bottom(s),sides:{bottom:n("thick")}}];case"topBottom":return[{area:p.top(s),sides:{top:t}},{area:p.bottom(s),sides:{bottom:t}}];case"topThickBottom":return[{area:p.top(s),sides:{top:t}},{area:p.bottom(s),sides:{bottom:n("thick")}}];case"topDoubleBottom":return[{area:p.top(s),sides:{top:t}},{area:p.bottom(s),sides:{bottom:n("double")}}];case"none":return[]}}export function drawSides(o,s,t,n){const e=o.spec(s),r=w(t),i=e.format?.find(c=>c.range===r)?.border;x(o,s,t,{border:{...i,...n}})}export function setBorders(o,s,t,n,e={}){const r=o.workbook.sheet(s);if(!r)return d("no-sheet");const i=new g(o);if(n==="none")return x(i,r,t,{border:void 0}),i.finish();const c={style:e.style??"thin",...e.color===void 0?{}:{color:e.color}};for(const f of L(n,t,c))drawSides(i,r,f.area,f.sides);return i.finish()}export function setBorderSides(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new g(o),i=b=>b??{style:"none"},{top:c,bottom:f,left:u,right:l,horizontal:h,vertical:m}=n;return c!==void 0&&drawSides(r,e,p.top(t),{top:i(c)}),f!==void 0&&drawSides(r,e,p.bottom(t),{bottom:i(f)}),u!==void 0&&drawSides(r,e,p.left(t),{left:i(u)}),l!==void 0&&drawSides(r,e,p.right(t),{right:i(l)}),h!==void 0&&t.bottom>t.top&&drawSides(r,e,{...t,bottom:t.bottom-1},{bottom:i(h)}),m!==void 0&&t.right>t.left&&drawSides(r,e,{...t,right:t.right-1},{right:i(m)}),r.finish()}export function mergeLoses(o,s,t){const n=Math.min(s.right,o.columnsUsed-1),e=Math.min(s.bottom,o.lastRow);for(let r=s.top;r<=e;r++){let i=!0;for(let c=s.left;c<=n;c++)if(o.at(r,c)!==void 0)if(i&&(t==="across"||r===s.top))i=!1;else return!0;if(t!=="across"&&!i&&r>=s.top){for(let c=r+1;c<=e;c++)for(let f=s.left;f<=n;f++)if(o.at(c,f)!==void 0)return!0;return!1}}return!1}export function mergeCells(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");if(e.tables.some(l=>k(l.area,t)))return d("merge-table");const r=new g(o),i=r.spec(e),c=(i.merges??[]).filter(l=>{const h=y(l);return!h||!k(h,t)}),f=n==="across"?Array.from({length:t.bottom-t.top+1},(l,h)=>({...t,top:t.top+h,bottom:t.top+h})):[t],u=[];for(const l of f)l.top===l.bottom&&l.left===l.right||(u.push(w(l)),T(r,o,e,l));return u.length===0?M():(i.merges=[...c,...u],n==="center"&&x(r,e,t,{align:"center"}),r.edit.whole=!0,r.finish())}function T(o,s,t,n){let e="";const r=Math.min(n.right,t.columnsUsed-1),i=Math.min(n.bottom,t.lastRow);for(let c=n.top;c<=i;c++)for(let f=n.left;f<=r;f++)t.at(c,f)!==void 0&&(e===""&&(e=j(s,t,c,f)),(c!==n.top||f!==n.left)&&B(o,s,t,c,f,""));e!==j(s,t,n.top,n.left)&&B(o,s,t,n.top,n.left,e)}export function unmergeCells(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n),i=(r.merges??[]).filter(c=>{const f=y(c);return!f||!k(f,t)});return i.length===0?delete r.merges:r.merges=i,e.edit.whole=!0,e.finish()}export function setFreeze(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n);return t&&(t.row>0||t.col>0)?r.freeze=E(t):delete r.freeze,e.edit.whole=!0,e.finish()}export function setHidden(o,s,t,n,e,r){const i=o.workbook.sheet(s);if(!i)return d("no-sheet");const c=new g(o),f=c.spec(i),u=(l,h)=>{const m=a(l[h]??{},"hidden");return r?{...l,[h]:{...m,hidden:!0}}:Object.keys(m).length===0?a(l,h):{...l,[h]:m}};if(t==="columns"){let l={...f.columns};const h=r?Array.from({length:e-n+1},(m,b)=>O(n+b)):Object.keys(l).filter(m=>{const b=_(m);return b!==void 0&&b>=n&&b<=e});for(const m of h)l=u(l,m);f.columns=l}else{let l={...f.rows};const h=r?Array.from({length:e-n+1},(m,b)=>String(n+b+1)):Object.keys(l).filter(m=>{const b=Number(m)-1;return b>=n&&b<=e});for(const m of h)l=u(l,m);f.rows=l}return D(f),c.edit.whole=!0,c.finish()}export function setSheetHidden(o,s,t){const n=o.file.sheets,e=n.filter(u=>u.hidden!==!0),r=n.findIndex(u=>u.name===s),i=n[r];if(!i)return d("no-sheet");if(t&&e.length<=1)return d("last-sheet");const c=a(i,"hidden"),f=t?{...c,hidden:!0}:c;return{...M(),file:{...o.file,sheets:n.map((u,l)=>l===r?f:u)},whole:!0}}export function setTabColor(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n);return t===void 0?delete r.tab:r.tab=t,e.finish()}export function toggleFilter(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r={row:t.top,col:t.left},i=n.tableAt(r.row,r.col);if(i){const h=e.table(n,i);return h.filter===!1?delete h.filter:h.filter=!1,e.edit.whole=!0,e.finish()}const c=e.spec(n);if(c.filter)return delete c.filter,e.edit.whole=!0,e.finish();const u=t.top===t.bottom&&t.left===t.right?R(n,r):t;if(!u)return d("no-data");const l=n.used;return c.filter={range:w({...u,bottom:Math.min(u.bottom,l?.bottom??u.bottom),right:Math.min(u.right,l?.right??u.right)})},e.edit.whole=!0,e.finish()}export function setFilterColumn(o,s,t,n,e){const r=o.workbook.sheet(s);if(!r)return d("no-sheet");const i=new g(o),{table:c}=t;if(c){const f=i.table(r,c),u=c.columns[n-c.at.col]?.name??"",l=a(f.filter===!1||!f.filter?{}:f.filter.columns,u),h=e?{...l,[u]:e}:l;Object.keys(h).length===0?delete f.filter:f.filter={columns:h}}else{const f=i.spec(r);if(!f.filter)return d("no-sheet");const u=O(n),l=a(f.filter.columns??{},u),h=e?{...l,[u]:e}:l;f.filter={range:f.filter.range,...Object.keys(h).length===0?{}:{columns:h}}}return i.edit.whole=!0,i.finish()}export function clearFilters(o,s){const t=o.workbook.sheet(s);if(!t)return d("no-sheet");const n=new g(o),e=n.spec(t);e.filter&&(e.filter={range:e.filter.range});for(const r of t.tables)r.spec.filter&&delete n.table(t,r).filter;return n.edit.whole=!0,n.finish()}export function addConditional(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n);return r.conditional=[t,...r.conditional??[]],e.edit.whole=!0,e.finish()}function z(o,s){if(!k(o,s))return[o];const t=[];s.top>o.top&&t.push({...o,bottom:s.top-1}),s.bottom<o.bottom&&t.push({...o,top:s.bottom+1});const n=Math.max(o.top,s.top),e=Math.min(o.bottom,s.bottom);return s.left>o.left&&t.push({...o,top:n,bottom:e,right:s.left-1}),s.right<o.right&&t.push({...o,top:n,bottom:e,left:s.right+1}),t}function C(o,s){const t=v(o);if(!t)return o;const n=t.flatMap(e=>z(e,s));return n.length===0?void 0:n.map(w).join(" ")}export function clearConditional(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n),i=t?(r.conditional??[]).flatMap(c=>{const f=C(c.range,t);return f===void 0?[]:[{...c,range:f}]}):[];return i.length===0?delete r.conditional:r.conditional=i,e.edit.whole=!0,e.finish()}export function setValidation(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new g(o),i=r.spec(e),c=(i.validations??[]).flatMap(u=>{const l=C(u.range,t);return l===void 0?[]:[{...u,range:l}]}),f=n?[...c,{...n,range:w(t)}]:c;return f.length===0?delete i.validations:i.validations=f,r.edit.whole=!0,r.finish()}export const WHOLE_SHEET={top:0,left:0,bottom:A-1,right:S-1};export function addChart(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n);return r.charts=[...r.charts??[],t],e.finish()}export function setChart(o,s,t,n){const e=o.workbook.sheet(s),r=e?.spec.charts?.[t];if(!e||!r)return d("no-sheet");const i=new g(o),c=i.spec(e),f=Object.fromEntries(Object.entries({...r,...n}).filter(([,u])=>u!==void 0));return c.charts=(c.charts??[]).map((u,l)=>l===t?f:u),i.finish()}export function removeChart(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n),i=(r.charts??[]).filter((c,f)=>f!==t);return i.length>0?r.charts=i:delete r.charts,e.finish()}
|
|
2
|
+
import{MAX_COLUMNS as S,MAX_ROWS as _,cellName as y,columnIndex as L,columnLetter as j,overlaps as a,rangeName as w,readArea as O,readAreas as R}from"./address.js";import{Draft as p,applyLook as x,blankEdit as M,refused as d,tidied as E,writeOne as C,inputOf as A}from"./edit.js";import{regionAround as v}from"./filter.js";export const BORDER_PRESETS=["bottom","top","left","right","none","all","outside","thickOutside","bottomDouble","thickBottom","topBottom","topThickBottom","topDoubleBottom"];const k=(o,s)=>Object.fromEntries(Object.entries(o).filter(([t])=>t!==s)),m={top:o=>({...o,bottom:o.top}),bottom:o=>({...o,top:o.bottom}),left:o=>({...o,right:o.left}),right:o=>({...o,left:o.right})};function D(o,s,t){const n=e=>({...t,style:e});switch(o){case"bottom":return[{area:m.bottom(s),sides:{bottom:t}}];case"top":return[{area:m.top(s),sides:{top:t}}];case"left":return[{area:m.left(s),sides:{left:t}}];case"right":return[{area:m.right(s),sides:{right:t}}];case"all":return[{area:s,sides:{left:t,right:t,top:t,bottom:t}}];case"outside":case"thickOutside":{const e=o==="outside"?t:n("thick");return[{area:m.top(s),sides:{top:e}},{area:m.bottom(s),sides:{bottom:e}},{area:m.left(s),sides:{left:e}},{area:m.right(s),sides:{right:e}}]}case"bottomDouble":return[{area:m.bottom(s),sides:{bottom:n("double")}}];case"thickBottom":return[{area:m.bottom(s),sides:{bottom:n("thick")}}];case"topBottom":return[{area:m.top(s),sides:{top:t}},{area:m.bottom(s),sides:{bottom:t}}];case"topThickBottom":return[{area:m.top(s),sides:{top:t}},{area:m.bottom(s),sides:{bottom:n("thick")}}];case"topDoubleBottom":return[{area:m.top(s),sides:{top:t}},{area:m.bottom(s),sides:{bottom:n("double")}}];case"none":return[]}}export function drawSides(o,s,t,n){const e=o.spec(s),r=w(t),i=e.format?.find(c=>c.range===r)?.border;x(o,s,t,{border:{...i,...n}})}export function setBorders(o,s,t,n,e={}){const r=o.workbook.sheet(s);if(!r)return d("no-sheet");const i=new p(o);if(n==="none")return x(i,r,t,{border:void 0}),i.finish();const c={style:e.style??"thin",...e.color===void 0?{}:{color:e.color}};for(const f of D(n,t,c))drawSides(i,r,f.area,f.sides);return i.finish()}export function setBorderSides(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new p(o),i=b=>b??{style:"none"},{top:c,bottom:f,left:u,right:l,horizontal:h,vertical:g}=n;return c!==void 0&&drawSides(r,e,m.top(t),{top:i(c)}),f!==void 0&&drawSides(r,e,m.bottom(t),{bottom:i(f)}),u!==void 0&&drawSides(r,e,m.left(t),{left:i(u)}),l!==void 0&&drawSides(r,e,m.right(t),{right:i(l)}),h!==void 0&&t.bottom>t.top&&drawSides(r,e,{...t,bottom:t.bottom-1},{bottom:i(h)}),g!==void 0&&t.right>t.left&&drawSides(r,e,{...t,right:t.right-1},{right:i(g)}),r.finish()}export function mergeLoses(o,s,t){const n=Math.min(s.right,o.columnsUsed-1),e=Math.min(s.bottom,o.lastRow);for(let r=s.top;r<=e;r++){let i=!0;for(let c=s.left;c<=n;c++)if(o.at(r,c)!==void 0)if(i&&(t==="across"||r===s.top))i=!1;else return!0;if(t!=="across"&&!i&&r>=s.top){for(let c=r+1;c<=e;c++)for(let f=s.left;f<=n;f++)if(o.at(c,f)!==void 0)return!0;return!1}}return!1}export function mergeCells(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");if(e.tables.some(l=>a(l.area,t)))return d("merge-table");const r=new p(o),i=r.spec(e),c=(i.merges??[]).filter(l=>{const h=O(l);return!h||!a(h,t)}),f=n==="across"?Array.from({length:t.bottom-t.top+1},(l,h)=>({...t,top:t.top+h,bottom:t.top+h})):[t],u=[];for(const l of f)l.top===l.bottom&&l.left===l.right||(u.push(w(l)),N(r,o,e,l));return u.length===0?M():(i.merges=[...c,...u],n==="center"&&x(r,e,t,{align:"center"}),r.edit.whole=!0,r.finish())}function N(o,s,t,n){let e="";const r=Math.min(n.right,t.columnsUsed-1),i=Math.min(n.bottom,t.lastRow);for(let c=n.top;c<=i;c++)for(let f=n.left;f<=r;f++)t.at(c,f)!==void 0&&(e===""&&(e=A(s,t,c,f)),(c!==n.top||f!==n.left)&&C(o,s,t,c,f,""));e!==A(s,t,n.top,n.left)&&C(o,s,t,n.top,n.left,e)}export function unmergeCells(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n),i=(r.merges??[]).filter(c=>{const f=O(c);return!f||!a(f,t)});return i.length===0?delete r.merges:r.merges=i,e.edit.whole=!0,e.finish()}export function setFreeze(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t&&(t.row>0||t.col>0)?r.freeze=y(t):delete r.freeze,e.edit.whole=!0,e.finish()}export function setHidden(o,s,t,n,e,r){const i=o.workbook.sheet(s);if(!i)return d("no-sheet");const c=new p(o),f=c.spec(i),u=(l,h)=>{const g=k(l[h]??{},"hidden");return r?{...l,[h]:{...g,hidden:!0}}:Object.keys(g).length===0?k(l,h):{...l,[h]:g}};if(t==="columns"){let l={...f.columns};const h=r?Array.from({length:e-n+1},(g,b)=>j(n+b)):Object.keys(l).filter(g=>{const b=L(g);return b!==void 0&&b>=n&&b<=e});for(const g of h)l=u(l,g);f.columns=l}else{let l={...f.rows};const h=r?Array.from({length:e-n+1},(g,b)=>String(n+b+1)):Object.keys(l).filter(g=>{const b=Number(g)-1;return b>=n&&b<=e});for(const g of h)l=u(l,g);f.rows=l}return E(f),c.edit.whole=!0,c.finish()}export function setSheetHidden(o,s,t){const n=o.file.sheets,e=n.filter(u=>u.hidden!==!0),r=n.findIndex(u=>u.name===s),i=n[r];if(!i)return d("no-sheet");if(t&&e.length<=1)return d("last-sheet");const c=k(i,"hidden"),f=t?{...c,hidden:!0}:c;return{...M(),file:{...o.file,sheets:n.map((u,l)=>l===r?f:u)},whole:!0}}export function setTabColor(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t===void 0?delete r.tab:r.tab=t,e.finish()}export function setGridlines(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t?delete r.gridlines:r.gridlines=!1,e.finish()}export function toggleFilter(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r={row:t.top,col:t.left},i=n.tableAt(r.row,r.col);if(i){const h=e.table(n,i);return h.filter===!1?delete h.filter:h.filter=!1,e.edit.whole=!0,e.finish()}const c=e.spec(n);if(c.filter)return delete c.filter,e.edit.whole=!0,e.finish();const u=t.top===t.bottom&&t.left===t.right?v(n,r):t;if(!u)return d("no-data");const l=n.used;return c.filter={range:w({...u,bottom:Math.min(u.bottom,l?.bottom??u.bottom),right:Math.min(u.right,l?.right??u.right)})},e.edit.whole=!0,e.finish()}export function setFilterColumn(o,s,t,n,e){const r=o.workbook.sheet(s);if(!r)return d("no-sheet");const i=new p(o),{table:c}=t;if(c){const f=i.table(r,c),u=c.columns[n-c.at.col]?.name??"",l=k(f.filter===!1||!f.filter?{}:f.filter.columns,u),h=e?{...l,[u]:e}:l;Object.keys(h).length===0?delete f.filter:f.filter={columns:h}}else{const f=i.spec(r);if(!f.filter)return d("no-sheet");const u=j(n),l=k(f.filter.columns??{},u),h=e?{...l,[u]:e}:l;f.filter={range:f.filter.range,...Object.keys(h).length===0?{}:{columns:h}}}return i.edit.whole=!0,i.finish()}export function clearFilters(o,s){const t=o.workbook.sheet(s);if(!t)return d("no-sheet");const n=new p(o),e=n.spec(t);e.filter&&(e.filter={range:e.filter.range});for(const r of t.tables)r.spec.filter&&delete n.table(t,r).filter;return n.edit.whole=!0,n.finish()}export function addConditional(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return r.conditional=[t,...r.conditional??[]],e.edit.whole=!0,e.finish()}function H(o,s){if(!a(o,s))return[o];const t=[];s.top>o.top&&t.push({...o,bottom:s.top-1}),s.bottom<o.bottom&&t.push({...o,top:s.bottom+1});const n=Math.max(o.top,s.top),e=Math.min(o.bottom,s.bottom);return s.left>o.left&&t.push({...o,top:n,bottom:e,right:s.left-1}),s.right<o.right&&t.push({...o,top:n,bottom:e,left:s.right+1}),t}function B(o,s){const t=R(o);if(!t)return o;const n=t.flatMap(e=>H(e,s));return n.length===0?void 0:n.map(w).join(" ")}export function clearConditional(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n),i=t?(r.conditional??[]).flatMap(c=>{const f=B(c.range,t);return f===void 0?[]:[{...c,range:f}]}):[];return i.length===0?delete r.conditional:r.conditional=i,e.edit.whole=!0,e.finish()}export function setValidation(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new p(o),i=r.spec(e),c=(i.validations??[]).flatMap(u=>{const l=B(u.range,t);return l===void 0?[]:[{...u,range:l}]}),f=n?[...c,{...n,range:w(t)}]:c;return f.length===0?delete i.validations:i.validations=f,r.edit.whole=!0,r.finish()}export const WHOLE_SHEET={top:0,left:0,bottom:_-1,right:S-1};export function addChart(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return r.charts=[...r.charts??[],t],e.finish()}export function setChart(o,s,t,n){const e=o.workbook.sheet(s),r=e?.spec.charts?.[t];if(!e||!r)return d("no-sheet");const i=new p(o),c=i.spec(e),f=Object.fromEntries(Object.entries({...r,...n}).filter(([,u])=>u!==void 0));return c.charts=(c.charts??[]).map((u,l)=>l===t?f:u),i.finish()}export function removeChart(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n),i=(r.charts??[]).filter((c,f)=>f!==t);return i.length>0?r.charts=i:delete r.charts,e.finish()}export function setNote(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new p(o),i=r.spec(e),c=y(t),f=Object.fromEntries(Object.entries(i.notes??{}).filter(([u])=>u!==c));return n!==void 0&&n.text.trim()!==""&&(f[c]=n.author===void 0||n.author===""?n.text:{text:n.text,author:n.author}),Object.keys(f).length===0?delete i.notes:i.notes=f,r.finish()}export function setLink(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new p(o),i=r.spec(e),c=Object.fromEntries(Object.entries(i.links??{}).filter(([f])=>{const u=O(f);return u===void 0||!a(u,t)}));if(n!==void 0&&n.trim()!==""){c[w(t)]=n.trim();const f=e.lookAt(t.top,t.left);f.color===void 0&&f.underline===void 0&&x(r,e,t,HYPERLINK_LOOK)}return Object.keys(c).length===0?delete i.links:i.links=c,E(i),r.finish()}export const HYPERLINK_LOOK={color:"#0563C1",underline:!0};export function setProtect(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t?r.protect=!0:delete r.protect,e.finish()}export function protectedIn(o,s){if(o.spec.protect!==!0)return!1;const t=Math.min(s.bottom,Math.max(s.top,o.lastRow+1)),n=Math.min(s.right,Math.max(s.left,o.columnsUsed+1));for(let e=s.top;e<=t;e++)for(let r=s.left;r<=n;r++)if(o.lookAt(e,r).locked!==!1)return!0;return!1}export function setConditionals(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t.length===0?delete r.conditional:r.conditional=[...t],e.edit.whole=!0,e.finish()}export function setPrint(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n),i=Object.fromEntries(Object.entries({...r.print,...t}).filter(([,c])=>c!==void 0));return Object.keys(i).length===0?delete r.print:r.print=i,e.finish()}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Area } from "./address.js";
|
|
2
|
+
import { type BookEdit, type EditBook } from "./edit.js";
|
|
3
|
+
import type { Calc } from "./calc/engine.js";
|
|
4
|
+
import { type Scalar } from "./values.js";
|
|
5
|
+
/** Which rows of values to keep: the first of each, by the columns given (all when none). */
|
|
6
|
+
export declare function uniqueRows(rows: readonly (readonly Scalar[])[], columns: readonly number[]): boolean[];
|
|
7
|
+
/**
|
|
8
|
+
* Remove Duplicates over an area: its header row left out when it has one,
|
|
9
|
+
* the rows kept closing up from the top, what is left at the foot cleared.
|
|
10
|
+
* Says how many rows went (`duplicates`) and stayed (`unique`).
|
|
11
|
+
*/
|
|
12
|
+
export declare function removeDuplicates(book: EditBook, calc: Calc, sheetName: string, area: Area, o: {
|
|
13
|
+
header: boolean;
|
|
14
|
+
columns: readonly number[];
|
|
15
|
+
}): BookEdit & {
|
|
16
|
+
duplicates: number;
|
|
17
|
+
unique: number;
|
|
18
|
+
};
|
|
19
|
+
export interface SplitOptions {
|
|
20
|
+
/** Delimited: what splits, Excel's Tab, Semicolon, Comma, Space and Other. */
|
|
21
|
+
delimiters?: readonly string[];
|
|
22
|
+
/** Treat consecutive delimiters as one. */
|
|
23
|
+
consecutive?: boolean;
|
|
24
|
+
/** Text Qualifier: a delimiter inside it does not split. */
|
|
25
|
+
qualifier?: string;
|
|
26
|
+
/** Fixed width: where each break is, in characters from the start. */
|
|
27
|
+
widths?: readonly number[];
|
|
28
|
+
}
|
|
29
|
+
/** A text split as Text to Columns splits it. */
|
|
30
|
+
export declare function splitText(text: string, o: SplitOptions): string[];
|
|
31
|
+
/**
|
|
32
|
+
* Text to Columns over a column's cells: each one's text split into the
|
|
33
|
+
* columns from the destination on (the column itself unless it says),
|
|
34
|
+
* each part read as typed.
|
|
35
|
+
*/
|
|
36
|
+
export declare function textToColumns(book: EditBook, calc: Calc, sheetName: string, area: Area, o: SplitOptions & {
|
|
37
|
+
destination?: {
|
|
38
|
+
row: number;
|
|
39
|
+
col: number;
|
|
40
|
+
};
|
|
41
|
+
}): BookEdit;
|
|
42
|
+
//# sourceMappingURL=data-tools.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
+
import{inputOf as y,refused as g,writeCells as q}from"./edit.js";import{moveFormula as x}from"./formula/move.js";import{parseFormula as A}from"./formula/parse.js";import{printFormula as C}from"./formula/print.js";import{CellError as E}from"./values.js";const $=t=>t===null?"":typeof t=="string"?`s${t.toLowerCase()}`:t instanceof E?`e${t.code}`:`${typeof t}${String(t)}`;export function uniqueRows(t,o){const i=new Set;return t.map(e=>{const s=(o.length===0?e.map((l,n)=>n):o).map(l=>$(e[l]??null)).join("\0");return i.has(s)?!1:(i.add(s),!0)})}function F(t,o){if(o===0||!t.startsWith("="))return t;const i=A(t);return i.ok?C(x(i.node,o,0)):t}export function removeDuplicates(t,o,i,e,u){const s=t.workbook.sheet(i);if(!s)return{...g("no-sheet"),duplicates:0,unique:0};const l=u.header?e.top+1:e.top,n=e.right-e.left+1,r=[],p=[];for(let f=l;f<=e.bottom;f++)r.push(Array.from({length:n},(m,w)=>o.value(s,f,e.left+w))),p.push(Array.from({length:n},(m,w)=>y(t,s,f,e.left+w)));const c=uniqueRows(r,u.columns.map(f=>f-e.left)),d=[];let h=l;c.forEach((f,m)=>{const w=l+m;f&&(w!==h&&p[m]?.forEach((k,b)=>{d.push({row:h,col:e.left+b,text:F(k,h-w)})}),h+=1)});for(let f=h;f<=e.bottom;f++)for(let m=0;m<n;m++)d.push({row:f,col:e.left+m,text:""});const a=h-l;return{...q(t,i,d),duplicates:c.length-a,unique:a}}export function splitText(t,o){if(o.widths&&o.widths.length>0){const n=[...new Set(o.widths)].filter(c=>c>0).sort((c,d)=>c-d),r=[];let p=0;for(const c of n)r.push(t.slice(p,c).trim()),p=c;return r.push(t.slice(p).trim()),r}const i=o.delimiters??[];if(i.length===0)return[t];const e=[];let u="",s=!1,l=!1;for(let n=0;n<t.length;n++){const r=t.charAt(n);if(o.qualifier&&r===o.qualifier){s&&t.charAt(n+1)===o.qualifier?(u+=r,n+=1):s=!s,l=!1;continue}if(!s&&i.includes(r)){o.consecutive===!0&&l||e.push(u),u="",l=!0;continue}u+=r,l=!1}return e.push(u),e}export function textToColumns(t,o,i,e,u){const s=t.workbook.sheet(i);if(!s)return g("no-sheet");const l=u.destination??{row:e.top,col:e.left},n=[];for(let r=e.top;r<=e.bottom;r++){const p=o.value(s,r,e.left);if(p===null)continue;const c=typeof p=="string"?p:y(t,s,r,e.left);splitText(c,u).forEach((d,h)=>{n.push({row:l.row+r-e.top,col:l.col+h,text:d})})}return n.length===0?g("no-data"):q(t,i,n)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SheetFile, SheetTable, SheetWorksheet } from "@allyhub/formats";
|
|
1
|
+
import type { SheetFile, SheetRun, SheetTable, SheetWorksheet } from "@allyhub/formats";
|
|
2
2
|
import { type Area } from "./address.js";
|
|
3
3
|
import { restructure, type RefusedEdit } from "./structure.js";
|
|
4
4
|
import { type CellLook, type CsvRows, type SharedFormula, type Table, type Workbook, type Worksheet } from "./workbook.js";
|
|
@@ -48,7 +48,7 @@ export interface BookEdit {
|
|
|
48
48
|
/** CSV files no sheet names any more. */
|
|
49
49
|
removed?: string[];
|
|
50
50
|
}
|
|
51
|
-
export type EditRefused = RefusedEdit | "column-name" | "sheet-name" | "sheet-taken" | "name-invalid" | "merge-table" | "no-data" | "table-move";
|
|
51
|
+
export type EditRefused = RefusedEdit | "column-name" | "sheet-name" | "sheet-taken" | "name-invalid" | "merge-table" | "no-data" | "table-move" | "table-shift" | "merge-shift" | "table-overlap" | "table-room" | "rich-loose";
|
|
52
52
|
/** The most typed cells written as keys of `cells`: more go in a CSV file of their own, as a script's do. */
|
|
53
53
|
export declare const BLOCK_CELLS = 100;
|
|
54
54
|
export declare const blankEdit: () => BookEdit;
|
|
@@ -82,6 +82,12 @@ export declare class Draft {
|
|
|
82
82
|
}
|
|
83
83
|
export declare const movedTo: (text: string, rows: number, columns: number) => string;
|
|
84
84
|
export declare function writeOne(d: Draft, book: EditBook, sheet: Worksheet, row: number, col: number, text: string): BookEdit | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* A cell's text as rich text: its runs, alike ones joined. Runs that say
|
|
87
|
+
* nothing of their font are its plain text, written as typed; a table's or
|
|
88
|
+
* a block's cells are CSV's plain text and hold none.
|
|
89
|
+
*/
|
|
90
|
+
export declare function setRuns(book: EditBook, sheetName: string, row: number, col: number, runs: readonly SheetRun[]): BookEdit;
|
|
85
91
|
/** One cell written as typed, or several: `text` is what a person types there. */
|
|
86
92
|
export interface CellWrite {
|
|
87
93
|
row: number;
|
|
@@ -151,4 +157,39 @@ export declare function exceptionsOf(table: Table): {
|
|
|
151
157
|
column: string;
|
|
152
158
|
text: string;
|
|
153
159
|
}[];
|
|
160
|
+
/**
|
|
161
|
+
* Insert's Table and Home's Format as Table over cells: Excel's Create
|
|
162
|
+
* Table. The area's top row is its header (with no header, Excel's
|
|
163
|
+
* Column1, Column2), what the cells hold, as typed, goes to a CSV file of
|
|
164
|
+
* its own, and their looks stay where they are. Refused over a table.
|
|
165
|
+
*/
|
|
166
|
+
export declare function makeTable(book: EditBook, sheetName: string, area: Area, o: {
|
|
167
|
+
header: boolean;
|
|
168
|
+
style?: string | undefined;
|
|
169
|
+
}): BookEdit;
|
|
170
|
+
/** Format as Table over a table: its style; TableStyleMedium2 is a new table's, `none` none. */
|
|
171
|
+
export declare function setTableStyle(book: EditBook, sheetName: string, tableName: string, style: string): BookEdit;
|
|
172
|
+
/** Table Design's Table Style Options: each said only where it is not a new table's. */
|
|
173
|
+
export declare function setTableOptions(book: EditBook, sheetName: string, tableName: string, options: {
|
|
174
|
+
banded_rows?: boolean;
|
|
175
|
+
banded_columns?: boolean;
|
|
176
|
+
first_column?: boolean;
|
|
177
|
+
last_column?: boolean;
|
|
178
|
+
}): BookEdit;
|
|
179
|
+
/**
|
|
180
|
+
* Name Manager's New and Edit: a name, what it refers to as typed (a
|
|
181
|
+
* formula after =, or a value) and its scope, the workbook or a sheet. A
|
|
182
|
+
* name renamed is renamed in every formula that read it, as Excel does.
|
|
183
|
+
*/
|
|
184
|
+
export declare function setName(book: EditBook, o: {
|
|
185
|
+
name: string;
|
|
186
|
+
value: string;
|
|
187
|
+
scope?: string | undefined;
|
|
188
|
+
was?: {
|
|
189
|
+
name: string;
|
|
190
|
+
scope?: string | undefined;
|
|
191
|
+
} | undefined;
|
|
192
|
+
}): BookEdit;
|
|
193
|
+
/** Name Manager's Delete: a formula that read it then reads #NAME?, as Excel's does. */
|
|
194
|
+
export declare function deleteName(book: EditBook, name: string, scope?: string): BookEdit;
|
|
154
195
|
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{MAX_COLUMNS as K,MAX_ROWS as R,cellName as N,columnLetter as C,contains as q,overlaps as O,rangeName as M,readAddress as X,readArea as j}from"./address.js";import{moveFormula as z}from"./formula/move.js";import{parseFormula as D}from"./formula/parse.js";import{printFormula as G}from"./formula/print.js";import{freeColumn as B,duplicated as H,restructure as F,uniqueColumn as I,withColumnsUpTo as A}from"./structure.js";import{readTyped as T}from"./values.js";import{FormulaCell as P,placeKey as V,validName as J}from"./workbook.js";export const BLOCK_CELLS=100;const _=(n,o)=>n.top<=o.top&&n.left<=o.left&&n.bottom>=o.bottom&&n.right>=o.right,S=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>e!==o)),Q=n=>S(n,"formula"),b=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>e!==o));export const blankEdit=()=>({rows:new Map,cells:[],whole:!1}),refused=n=>({...blankEdit(),refused:n});const v=n=>T(n).formula!==void 0;function Y(n){const o=T(n);return o.formula!==void 0?n:o.value===null?null:o.format!==void 0?n:typeof o.value=="number"||typeof o.value=="boolean"?o.value:n}const Z=n=>n!==null&&typeof n=="object"?Object.fromEntries(Object.entries(n).filter(([o])=>o!=="value"&&o!=="formula")):{};export class Draft{book;specs=new Map;file;fileChanged=!1;grown=new Map;added=new Map;edit=blankEdit();constructor(o){this.book=o,this.file=o.file}spec(o){let e=this.specs.get(o.index);if(!e){const t=this.file.sheets.findIndex(s=>s.name===o.name);e={...this.file.sheets[t]??{name:o.name}},this.specs.set(o.index,e),this.fileChanged||(this.file={...this.file,sheets:[...this.file.sheets]},this.fileChanged=!0),this.file.sheets[t]=e}return e}table(o,e){const t=this.spec(o),s=[...t.tables??[]],r=s.findIndex(l=>l.name===e.name),i={...s[r]??e.spec};return s[r]=i,t.tables=s,i}rows(o){const e=this.edit.rows.get(o);if(e)return e;const t=[...this.book.rows.get(o)??[]];return this.edit.rows.set(o,t),t}setField(o,e,t,s){const r=this.rows(o),i=[...r[e]??[]];for(;i.length<=t;)i.push("");return i[t]=s,r[e]=i,i}rowsOf(o){return this.grown.get(o)??o.rows}grow(o,e,t){this.grown.set(o,this.rowsOf(o)+1);const s=this.added.get(o)??new Map;s.set(e,t),this.added.set(o,s)}addedAt(o,e,t){for(const[s,r]of this.added){const i=r.get(e);if(i!==void 0&&s.sheet===o&&t>=s.at.col&&t<s.at.col+s.columns.length)return{table:s,record:i}}}finish(){return this.fileChanged&&(this.edit.file=this.file),this.edit}}function ee(n,o,e,t){return o.tables.find(s=>{const r=s.at.row+n.rowsOf(s)+1;if(e!==r)return!1;const i=s.at.col+s.columns.length-1;if(t<s.at.col||t>i)return!1;for(let l=s.at.col;l<=i;l++)if(o.at(e,l)!==void 0)return!1;return!0})}function te(n,o,e){return n.tables.find(t=>{const{top:s,bottom:r,right:i}=t.area;if(e!==i+1||o<s||o>r)return!1;for(let l=s;l<=r;l++)if(n.at(l,e)!==void 0)return!1;return!0})}export const movedTo=(n,o,e)=>{const t=D(n);return t.ok?G(z(t.node,o,e)):n};function E(n,o,e,t,s,r){const i=e.at.row+1,l=n.table(o,e),f=movedTo(r,i-s,0);if(l.columns={...l.columns,[t.name]:{...l.columns?.[t.name],formula:f}},t.csv!==void 0){const c=e.places[s-i];c!==void 0&&n.setField(e.file,c,t.csv,"")}n.edit.whole=!0}function ne(n,o,e,t){const{csv:s}=e;if(s===void 0)return!1;const r=n.rows(o.file);return o.places.some((i,l)=>l!==t&&(r[i]?.[s]??"")!=="")}function oe(n,o,e,t,s){const r=s.trim();if(r==="")return refused("column-name");if(r===t.name)return n.finish();const i=e.columns.filter(c=>c!==t).map(c=>c.name),l=I(i,r),f=F(o,{op:"rename-column",table:e.name,from:t.name,to:l});return{...blankEdit(),file:f.file,rows:new Map(f.rows),whole:!0}}function se(n,o,e,t,s,r){const i=e.columns[s-e.at.col];if(!i)return;const l=t-e.at.row-1;if(v(r)){if(i.formula){E(n,o,e,i,t,r);return}if(!ne(n,e,i,l)){E(n,o,e,i,t,r);return}n.edit.offer={sheet:o.name,row:t,col:s,text:r}}const c=e.places[l];if(c===void 0)return;let d=i.csv;if(d===void 0){if(r==="")return;const w=e.columns.map(p=>p.name);n.edit.rows.set(e.file,A(n.rows(e.file),w,i.index)),n.edit.whole=!0,d=i.index}const a=n.setField(e.file,c,d,r);n.edit.cells.push({sheet:o,row:t,col:s,...r===""&&i.formula?{column:i.formula}:{input:r},record:{table:e,index:l,fields:a}})}function re(n,o,e,t,s){const r=n.rows(o.file),i=Math.max(r[0]?.length??1,1),l=new Array(i).fill(""),f=o.columns[t-o.at.col];f?.csv!==void 0&&(l[f.csv]=s),r.push(l),n.grow(o,e,r.length-1),n.edit.whole=!0}function ie(n,o,e,t,s){const r=n.table(o,e),i=e.columns.map(w=>w.name),l=t===e.at.row,f=l?I(i,s.trim()===""?B(i):s.trim()):B(i);if(n.edit.whole=!0,!l&&v(s)){r.columns={...r.columns,[f]:{formula:movedTo(s,e.at.row+1-t,0)}};return}const c=i.length,d=A(n.rows(e.file),i,c-1),a=d[0];if(a&&a.push(f),d.forEach((w,p)=>{p>0&&w.length>0&&w.push("")}),!l){const w=e.places[t-e.at.row-1],p=w===void 0?void 0:d[w];p&&(p[c]=s)}n.edit.rows.set(e.file,d)}function le(n,o,e,t,s,r,i){n.setField(e,s-t.top,r-t.left,i),n.edit.cells.push({sheet:o,row:s,col:r,input:i})}function fe(n,o,e){return Object.keys(n.spec.cells??{}).some(t=>{if(!t.includes(":"))return!1;const s=j(t);return s!==void 0&&q(s,o,e)})}function ce(n,o,e,t,s){const r=n.spec(o),i=N({row:e,col:t});let l={...r.cells};const f=l[i],c=f===void 0?{}:Z(f),d=Y(s),a=Object.keys(c).length===0;let w;if(d===null){const p=fe(o,e,t);w=!a||p,a&&!p?l=b(l,i):l[i]=a?null:c}else w=!0,l[i]=a?d:{...c,...v(s)?{formula:s}:{value:d}};r.cells=l,Object.keys(l).length===0&&delete r.cells,n.edit.cells.push({sheet:o,row:e,col:t,input:s,key:w?i:null})}export function writeOne(n,o,e,t,s,r){const i=n.addedAt(e,t,s);if(i){const{csv:c}=i.table.columns[s-i.table.at.col]??{};c!==void 0&&n.setField(i.table.file,i.record,c,r);return}const l=e.tableAt(t,s);if(l){const c=l.columns[s-l.at.col];if(t===l.at.row)return c?oe(n,o,l,c,r):void 0;se(n,e,l,t,s,r);return}if(r!==""){const c=ee(n,e,t,s);if(c){re(n,c,t,s,r);return}const d=te(e,t,s);if(d){ie(n,e,d,t,r);return}}const f=e.blockAt(t,s);f?le(n,e,f.file,f.area,t,s,r):ce(n,e,t,s,r)}export function writeCells(n,o,e){const t=n.workbook.sheet(o);if(!t)return refused("no-sheet");const s=new Draft(n);for(const{row:r,col:i,text:l}of[...e].sort((f,c)=>f.row-c.row||f.col-c.col)){const f=writeOne(s,n,t,r,i,l);if(f)return f}return s.finish()}export function overwriteColumn(n,o,e,t,s){const r=n.workbook.sheet(o),i=r?.tableAt(e,t);if(!r||!i)return refused("no-sheet");const l=i.columns[t-i.at.col];if(!l)return refused("no-sheet");const f=new Draft(n);E(f,r,i,l,e,s);const{csv:c}=l;if(c!==void 0)for(const d of i.places)f.setField(i.file,d,c,"");return f.finish()}function*ue(n,o){const e=Math.min(o.right,n.columnsUsed-1);for(let t=o.left;t<=e;t++){const[s,r]=n.span(t,o.top,o.bottom);for(let i=s;i<=r;i++)n.at(i,t)!==void 0&&(yield[i,t])}}export function clearCells(n,o,e){const t=n.workbook.sheet(o);if(!t)return refused("no-sheet");const s=new Draft(n);for(const r of t.tables){const{top:i,bottom:l}=r.data;if(!(l<i||e.top>i||e.bottom<l))for(const f of r.columns){const c=r.at.col+f.index;if(c<e.left||c>e.right||!f.formula)continue;const d=s.table(t,r),a=r.columns.map(L=>L.name);f.csv===void 0&&s.edit.rows.set(r.file,A(s.rows(r.file),a,f.index));const w=Q(d.columns?.[f.name]??{}),p=b(d.columns??{},f.name);d.columns=Object.keys(w).length>0?{...p,[f.name]:w}:p,Object.keys(d.columns).length===0&&delete d.columns,s.edit.whole=!0}}for(const[r,i]of ue(t,e)){if(t.tableAt(r,i)?.at.row===r)continue;const l=writeOne(s,n,t,r,i,"");if(l)return l}return s.finish()}export function dropKeys(n,o){n.cells&&(n.cells=Object.fromEntries(Object.entries(n.cells).filter(([e])=>{const t=j(e);return!t||!_(o,t)})))}export function fillCells(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");if(!r.tables.some(f=>O(f.area,t))&&!r.blocks.some(f=>O(f.area,t))&&v(s)){const f=new Draft(n),c=f.spec(r);dropKeys(c,t);const d=movedTo(s,t.top-e.row,t.left-e.col),a=M(t);return c.cells={...c.cells,[a]:d},f.edit.whole=!0,f.finish()}const l=[];for(let f=t.top;f<=t.bottom;f++)for(let c=t.left;c<=t.right;c++)f===e.row&&c===e.col||l.push({row:f,col:c,text:v(s)?movedTo(s,f-e.row,c-e.col):s});return writeCells(n,o,l)}export function writeBlockOf(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");const i=new Draft(n),l=i.spec(r);return l.blocks=[...l.blocks??[],{at:N(e),rows:s}],i.edit.rows.set(s,t),i.edit.whole=!0,i.finish()}const $=(n,o)=>Object.keys(o).some(e=>e in n),x=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>!(e in o)));function de(n){if(n===null||typeof n!="object")return n;const o=Object.keys(n);return o.length===1&&o[0]==="value"?n.value??null:o.length===1&&o[0]==="formula"?n.formula??null:n}const me={bold:!1,italic:!1,underline:!1,strike:!1,wrap:!1,align:"general",format:"General",color:"#000000",fill:"#FFFFFF",font:"Calibri",size:11,border:{left:{style:"none"},right:{style:"none"},top:{style:"none"},bottom:{style:"none"}}};function ae(n,o,e,t){for(const[s,r]of Object.entries(n.columns??{})){const i=X(`${s}1`)?.col;if(i!==void 0&&i>=e.left&&i<=e.right&&t in r)return!0}for(const[s,r]of Object.entries(n.rows??{})){const i=Number(s)-1;if(i>=e.top&&i<=e.bottom&&t in r)return!0}return o.tables.some(s=>O(s.area,e)&&s.columns.some(r=>r.spec!==void 0&&t in r.spec&&s.at.col+r.index>=e.left&&s.at.col+r.index<=e.right))}export function setLook(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n);return applyLook(r,s,e,t),r.finish()}export function applyLook(n,o,e,t){const s=n.spec(o);he(n,o,s,e,t),tidied(s)}function he(n,o,e,t,s){if(e.cells){const u={...e.cells},m=[];for(const[g,h]of Object.entries(u)){if(h===null||typeof h!="object"||!$(h,s))continue;const y=j(g);!y||!O(y,t)||(g.includes(":")&&!_(t,y)&&m.push({range:g,...Object.fromEntries(Object.entries(h).filter(([W])=>W in s))}),u[g]=de(x(h,s)))}e.cells=u,m.length>0&&(e.format=[...e.format??[],...m])}const r=e.format??[],i=u=>{const m=j(u.range);return m!==void 0&&O(m,t)},l=r.some(u=>i(u)&&$(u,s)),f=Object.fromEntries(Object.entries(s).filter(([,u])=>u!==void 0)),c=t.top===0&&t.bottom===R-1,d=t.left===0&&t.right===K-1;if(c&&!d&&!l){let u={...e.columns};for(let m=t.left;m<=t.right;m++){const g=C(m),h={...x(u[g]??{},s),...f};u=Object.keys(h).length===0?b(u,g):{...u,[g]:h}}e.columns=u;return}if(d&&!c&&!l){let u={...e.rows};for(let m=t.top;m<=t.bottom;m++){const g=String(m+1),h={...x(u[g]??{},s),...f};u=Object.keys(h).length===0?b(u,g):{...u,[g]:h}}e.rows=u;return}const a=o.tables.find(u=>u.rows>0&&t.top===u.data.top&&t.bottom===u.data.bottom&&t.left>=u.area.left&&t.right<=u.area.right);if(a&&!l){const u=n.table(o,a);let m={...u.columns};for(let g=t.left;g<=t.right;g++){const h=a.columns[g-a.at.col]?.name;if(h===void 0)continue;const y={...x(m[h]??{},s),...f};m=Object.keys(y).length===0?b(m,h):{...m,[h]:y}}u.columns=m,Object.keys(m).length===0&&delete u.columns,n.edit.whole=!0;return}const w=M(t),p=r.find(u=>{const m=j(u.range);return m!==void 0&&M(m)===w}),U=(p?r.slice(r.indexOf(p)+1):[]).some(u=>i(u)&&$(u,s)),k={};for(const[u,m]of Object.entries(s)){const g=r.some(h=>h!==p&&i(h)&&u in h)||ae(e,o,t,u);m!==void 0?k[u]=m:g&&(k[u]=me[u])}if(p&&!U){const u={...x(p,s),...k};e.format=r.flatMap(m=>m!==p?[m]:Object.keys(u).length>1?[u]:[])}else Object.keys(k).length>0&&(e.format=[...r,{range:w,...k}])}export function tidied(n){n.format?.length===0&&delete n.format,n.columns&&Object.keys(n.columns).length===0&&delete n.columns,n.rows&&Object.keys(n.rows).length===0&&delete n.rows,n.cells&&Object.keys(n.cells).length===0&&delete n.cells}export function setColumnWidth(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n),i=r.spec(s),l=C(e),f=S(i.columns?.[l]??{},"width"),c=t===void 0?f:{...f,width:t},d=b(i.columns??{},l);return i.columns=Object.keys(c).length===0?d:{...d,[l]:c},tidied(i),r.finish()}export function setRowHeight(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n),i=r.spec(s),l=String(e+1),f=S(i.rows?.[l]??{},"height"),c=t===void 0?f:{...f,height:t},d=b(i.rows??{},l);return i.rows=Object.keys(c).length===0?d:{...d,[l]:c},tidied(i),r.finish()}export function sheetNameProblem(n,o,e){if(o.trim()===""||o.length>31||/[\\/?*[\]:]/u.test(o)||o.startsWith("'")||o.endsWith("'"))return"sheet-name";const t=n.workbook.sheet(o);if(t&&t.name!==e)return"sheet-taken"}export function renameSheet(n,o,e){const t=sheetNameProblem(n,e,o);if(t)return refused(t);const s=F(n,{op:"rename-sheet",from:o,to:e});return{...blankEdit(),file:s.file,rows:new Map(s.rows),whole:!0}}export function addSheet(n,o,e){const t=sheetNameProblem(n,o);if(t)return refused(t);const s=[...n.file.sheets],r=s.findIndex(i=>i.name===e);return s.splice(r<0?s.length:r+1,0,{name:o}),{...blankEdit(),file:{...n.file,sheets:s},whole:!0}}export function copyName(n,o){for(let e=2;;e++){const t=` (${String(e)})`,s=o.slice(0,31-t.length).trimEnd()+t;if(!n.workbook.sheet(s))return s}}export function duplicateSheet(n,o){const e=H(n,o,copyName(n,o));return e.refused?refused(e.refused):{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0}}export function deleteSheet(n,o){const e=F(n,{op:"delete-sheet",name:o});if(e.refused)return refused(e.refused);const t=we(n.file,e.file);for(const s of t)e.rows.delete(s);return{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0,...t.length===0?{}:{removed:t}}}function we(n,o){const e=s=>s.sheets.flatMap(r=>[...(r.tables??[]).map(i=>i.rows),...(r.blocks??[]).map(i=>i.rows)]),t=new Set(e(o));return[...new Set(e(n))].filter(s=>!t.has(s))}export function moveSheet(n,o,e){const t=[...n.file.sheets],s=t.findIndex(i=>i.name===o),[r]=t.splice(s,1);return r?(t.splice(e,0,r),{...blankEdit(),file:{...n.file,sheets:t},whole:!0}):refused("no-sheet")}export function bandEdit(n,o){const e=F(n,o);return e.refused?refused(e.refused):{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0}}export function defineName(n,o,e,t){if(!J(o)||n.workbook.name(o)||n.workbook.table(o))return refused("name-invalid");const s=(l,f)=>`$${C(f)}$${String(l+1)}`,r=t.top===t.bottom&&t.left===t.right?s(t.top,t.left):`${s(t.top,t.left)}:${s(t.bottom,t.right)}`,i=/^[\p{L}_][\p{L}\p{N}_.]*$/u.test(e)?e:`'${e.replaceAll("'","''")}'`;return{...blankEdit(),file:{...n.file,names:{...n.file.names,[o]:`=${i}!${r}`}},whole:!0}}export function inputOf(n,o,e,t){const s=o.at(e,t);if(s===void 0)return"";if(s instanceof P)return s.text;const r=o.tableAt(e,t);if(r){const d=r.columns[t-r.at.col];if(e===r.at.row)return d?.name??"";const a=d?.csv===void 0?void 0:r.records[e-r.at.row-1]?.[d.csv];if(a!==void 0)return a}const i=o.blockAt(e,t);if(i){const d=n.rows.get(i.file)?.[e-i.area.top]?.[t-i.area.left];if(d!==void 0)return d}const l=o.keys.get(V(e,t)),f=l===void 0?void 0:o.spec.cells?.[l],c=f!==null&&typeof f=="object"?f.value:f;return c!=null?String(c):typeof s=="object"?s.code:String(s)}export function exceptionsOf(n){const o=[];for(const e of n.columns){const{csv:t}=e;!e.formula||t===void 0||n.records.forEach((s,r)=>{const i=s[t]??"";i!==""&&o.push({row:n.at.row+1+r,col:n.at.col+e.index,column:e.name,text:i})})}return o}
|
|
2
|
+
import{MAX_COLUMNS as P,MAX_ROWS as V,cellName as S,columnLetter as $,contains as J,overlaps as k,rangeName as E,readAddress as Q,readArea as v}from"./address.js";import{moveFormula as Y}from"./formula/move.js";import{parseFormula as Z}from"./formula/parse.js";import{printFormula as ee}from"./formula/print.js";import{freeColumn as K,duplicated as te,restructure as _,uniqueColumn as q,withColumnsUpTo as T}from"./structure.js";import{RUN_FIELDS as ne,joinedRuns as oe,plainRuns as D,runsWithout as se}from"./rich.js";import{CellError as re,readTyped as C}from"./values.js";import{FormulaCell as ie,placeKey as le,runsText as N,validName as X}from"./workbook.js";export const BLOCK_CELLS=100;const z=(n,o)=>n.top<=o.top&&n.left<=o.left&&n.bottom>=o.bottom&&n.right>=o.right,R=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>e!==o)),fe=n=>R(n,"formula"),O=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>e!==o));export const blankEdit=()=>({rows:new Map,cells:[],whole:!1}),refused=n=>({...blankEdit(),refused:n});const x=n=>C(n).formula!==void 0;function ce(n){const o=C(n);return o.formula!==void 0?n:o.value===null?null:o.format!==void 0?n:typeof o.value=="number"||typeof o.value=="boolean"?o.value:n}const I=n=>n!==null&&typeof n=="object"?Object.fromEntries(Object.entries(n).filter(([o])=>o!=="value"&&o!=="formula"&&o!=="runs")):{};export class Draft{book;specs=new Map;file;fileChanged=!1;grown=new Map;added=new Map;edit=blankEdit();constructor(o){this.book=o,this.file=o.file}spec(o){let e=this.specs.get(o.index);if(!e){const t=this.file.sheets.findIndex(s=>s.name===o.name);e={...this.file.sheets[t]??{name:o.name}},this.specs.set(o.index,e),this.fileChanged||(this.file={...this.file,sheets:[...this.file.sheets]},this.fileChanged=!0),this.file.sheets[t]=e}return e}table(o,e){const t=this.spec(o),s=[...t.tables??[]],r=s.findIndex(l=>l.name===e.name),i={...s[r]??e.spec};return s[r]=i,t.tables=s,i}rows(o){const e=this.edit.rows.get(o);if(e)return e;const t=[...this.book.rows.get(o)??[]];return this.edit.rows.set(o,t),t}setField(o,e,t,s){const r=this.rows(o),i=[...r[e]??[]];for(;i.length<=t;)i.push("");return i[t]=s,r[e]=i,i}rowsOf(o){return this.grown.get(o)??o.rows}grow(o,e,t){this.grown.set(o,this.rowsOf(o)+1);const s=this.added.get(o)??new Map;s.set(e,t),this.added.set(o,s)}addedAt(o,e,t){for(const[s,r]of this.added){const i=r.get(e);if(i!==void 0&&s.sheet===o&&t>=s.at.col&&t<s.at.col+s.columns.length)return{table:s,record:i}}}finish(){return this.fileChanged&&(this.edit.file=this.file),this.edit}}function ue(n,o,e,t){return o.tables.find(s=>{const r=s.at.row+n.rowsOf(s)+1;if(e!==r)return!1;const i=s.at.col+s.columns.length-1;if(t<s.at.col||t>i)return!1;for(let l=s.at.col;l<=i;l++)if(o.at(e,l)!==void 0)return!1;return!0})}function de(n,o,e){return n.tables.find(t=>{const{top:s,bottom:r,right:i}=t.area;if(e!==i+1||o<s||o>r)return!1;for(let l=s;l<=r;l++)if(n.at(l,e)!==void 0)return!1;return!0})}export const movedTo=(n,o,e)=>{const t=Z(n);return t.ok?ee(Y(t.node,o,e)):n};function U(n,o,e,t,s,r){const i=e.at.row+1,l=n.table(o,e),f=movedTo(r,i-s,0);if(l.columns={...l.columns,[t.name]:{...l.columns?.[t.name],formula:f}},t.csv!==void 0){const c=e.places[s-i];c!==void 0&&n.setField(e.file,c,t.csv,"")}n.edit.whole=!0}function ae(n,o,e,t){const{csv:s}=e;if(s===void 0)return!1;const r=n.rows(o.file);return o.places.some((i,l)=>l!==t&&(r[i]?.[s]??"")!=="")}function me(n,o,e,t,s){const r=s.trim();if(r==="")return refused("column-name");if(r===t.name)return n.finish();const i=e.columns.filter(c=>c!==t).map(c=>c.name),l=q(i,r),f=_(o,{op:"rename-column",table:e.name,from:t.name,to:l});return{...blankEdit(),file:f.file,rows:new Map(f.rows),whole:!0}}function he(n,o,e,t,s,r){const i=e.columns[s-e.at.col];if(!i)return;const l=t-e.at.row-1;if(x(r)){if(i.formula){U(n,o,e,i,t,r);return}if(!ae(n,e,i,l)){U(n,o,e,i,t,r);return}n.edit.offer={sheet:o.name,row:t,col:s,text:r}}const c=e.places[l];if(c===void 0)return;let d=i.csv;if(d===void 0){if(r==="")return;const h=e.columns.map(g=>g.name);n.edit.rows.set(e.file,T(n.rows(e.file),h,i.index)),n.edit.whole=!0,d=i.index}const m=n.setField(e.file,c,d,r);n.edit.cells.push({sheet:o,row:t,col:s,...r===""&&i.formula?{column:i.formula}:{input:r},record:{table:e,index:l,fields:m}})}function we(n,o,e,t,s){const r=n.rows(o.file),i=Math.max(r[0]?.length??1,1),l=new Array(i).fill(""),f=o.columns[t-o.at.col];f?.csv!==void 0&&(l[f.csv]=s),r.push(l),n.grow(o,e,r.length-1),n.edit.whole=!0}function pe(n,o,e,t,s){const r=n.table(o,e),i=e.columns.map(h=>h.name),l=t===e.at.row,f=l?q(i,s.trim()===""?K(i):s.trim()):K(i);if(n.edit.whole=!0,!l&&x(s)){r.columns={...r.columns,[f]:{formula:movedTo(s,e.at.row+1-t,0)}};return}const c=i.length,d=T(n.rows(e.file),i,c-1),m=d[0];if(m&&m.push(f),d.forEach((h,g)=>{g>0&&h.length>0&&h.push("")}),!l){const h=e.places[t-e.at.row-1],g=h===void 0?void 0:d[h];g&&(g[c]=s)}n.edit.rows.set(e.file,d)}function be(n,o,e,t,s,r,i){n.setField(e,s-t.top,r-t.left,i),n.edit.cells.push({sheet:o,row:s,col:r,input:i})}function ge(n,o,e){return Object.keys(n.spec.cells??{}).some(t=>{if(!t.includes(":"))return!1;const s=v(t);return s!==void 0&&J(s,o,e)})}function ye(n,o,e,t,s){const r=n.spec(o),i=S({row:e,col:t});let l={...r.cells};const f=l[i];if(f!==null&&typeof f=="object"&&f.runs!==void 0&&N(f.runs)===s){n.edit.cells.push({sheet:o,row:e,col:t,input:s,key:i});return}const c=f===void 0?{}:I(f),d=ce(s),m=Object.keys(c).length===0;let h;if(d===null){const g=ge(o,e,t);h=!m||g,m&&!g?l=O(l,i):l[i]=m?null:c}else h=!0,l[i]=m?d:{...c,...x(s)?{formula:s}:{value:d}};r.cells=l,Object.keys(l).length===0&&delete r.cells,n.edit.cells.push({sheet:o,row:e,col:t,input:s,key:h?i:null})}export function writeOne(n,o,e,t,s,r){const i=n.addedAt(e,t,s);if(i){const{csv:c}=i.table.columns[s-i.table.at.col]??{};c!==void 0&&n.setField(i.table.file,i.record,c,r);return}const l=e.tableAt(t,s);if(l){const c=l.columns[s-l.at.col];if(t===l.at.row)return c?me(n,o,l,c,r):void 0;he(n,e,l,t,s,r);return}if(r!==""){const c=ue(n,e,t,s);if(c){we(n,c,t,s,r);return}const d=de(e,t,s);if(d){pe(n,e,d,t,r);return}}const f=e.blockAt(t,s);f?be(n,e,f.file,f.area,t,s,r):ye(n,e,t,s,r)}export function setRuns(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");const i=oe(s),l=N(i);if(i.length===0||D(i))return writeCells(n,o,[{row:e,col:t,text:l}]);if(r.tableAt(e,t)||r.blockAt(e,t))return refused("rich-loose");const f=new Draft(n),c=f.spec(r),d=S({row:e,col:t}),m=c.cells?.[d],h=m===void 0?{}:I(m);return c.cells={...c.cells,[d]:{...h,runs:i}},f.edit.cells.push({sheet:r,row:e,col:t,input:l,key:d}),f.finish()}function ke(n,o){if(n===null||typeof n!="object"||!n.runs)return n;const e=se(n.runs,o);if(!D(e))return{...n,runs:e};const t=N(e),s=I(n);return C(t).value===t&&C(t).format===void 0?Object.keys(s).length===0?t:{...s,value:t}:{...s,runs:[{text:t}]}}export function writeCells(n,o,e){const t=n.workbook.sheet(o);if(!t)return refused("no-sheet");const s=new Draft(n);for(const{row:r,col:i,text:l}of[...e].sort((f,c)=>f.row-c.row||f.col-c.col)){const f=writeOne(s,n,t,r,i,l);if(f)return f}return s.finish()}export function overwriteColumn(n,o,e,t,s){const r=n.workbook.sheet(o),i=r?.tableAt(e,t);if(!r||!i)return refused("no-sheet");const l=i.columns[t-i.at.col];if(!l)return refused("no-sheet");const f=new Draft(n);U(f,r,i,l,e,s);const{csv:c}=l;if(c!==void 0)for(const d of i.places)f.setField(i.file,d,c,"");return f.finish()}function*G(n,o){const e=Math.min(o.right,n.columnsUsed-1);for(let t=o.left;t<=e;t++){const[s,r]=n.span(t,o.top,o.bottom);for(let i=s;i<=r;i++)n.at(i,t)!==void 0&&(yield[i,t])}}export function clearCells(n,o,e){const t=n.workbook.sheet(o);if(!t)return refused("no-sheet");const s=new Draft(n);for(const r of t.tables){const{top:i,bottom:l}=r.data;if(!(l<i||e.top>i||e.bottom<l))for(const f of r.columns){const c=r.at.col+f.index;if(c<e.left||c>e.right||!f.formula)continue;const d=s.table(t,r),m=r.columns.map(y=>y.name);f.csv===void 0&&s.edit.rows.set(r.file,T(s.rows(r.file),m,f.index));const h=fe(d.columns?.[f.name]??{}),g=O(d.columns??{},f.name);d.columns=Object.keys(h).length>0?{...g,[f.name]:h}:g,Object.keys(d.columns).length===0&&delete d.columns,s.edit.whole=!0}}for(const[r,i]of G(t,e)){if(t.tableAt(r,i)?.at.row===r)continue;const l=writeOne(s,n,t,r,i,"");if(l)return l}return s.finish()}export function dropKeys(n,o){n.cells&&(n.cells=Object.fromEntries(Object.entries(n.cells).filter(([e])=>{const t=v(e);return!t||!z(o,t)})))}export function fillCells(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");if(!r.tables.some(f=>k(f.area,t))&&!r.blocks.some(f=>k(f.area,t))&&x(s)){const f=new Draft(n),c=f.spec(r);dropKeys(c,t);const d=movedTo(s,t.top-e.row,t.left-e.col),m=E(t);return c.cells={...c.cells,[m]:d},f.edit.whole=!0,f.finish()}const l=[];for(let f=t.top;f<=t.bottom;f++)for(let c=t.left;c<=t.right;c++)f===e.row&&c===e.col||l.push({row:f,col:c,text:x(s)?movedTo(s,f-e.row,c-e.col):s});return writeCells(n,o,l)}export function writeBlockOf(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");const i=new Draft(n),l=i.spec(r);return l.blocks=[...l.blocks??[],{at:S(e),rows:s}],i.edit.rows.set(s,t),i.edit.whole=!0,i.finish()}const W=(n,o)=>Object.keys(o).some(e=>e in n),L=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>!(e in o)));function Oe(n){if(n===null||typeof n!="object")return n;const o=Object.keys(n);return o.length===1&&o[0]==="value"?n.value??null:o.length===1&&o[0]==="formula"?n.formula??null:n}const je={bold:!1,italic:!1,underline:!1,strike:!1,wrap:!1,locked:!0,hide_formula:!1,align:"general",format:"General",color:"#000000",fill:"#FFFFFF",font:"Calibri",size:11,border:{left:{style:"none"},right:{style:"none"},top:{style:"none"},bottom:{style:"none"}}};function ve(n,o,e,t){for(const[s,r]of Object.entries(n.columns??{})){const i=Q(`${s}1`)?.col;if(i!==void 0&&i>=e.left&&i<=e.right&&t in r)return!0}for(const[s,r]of Object.entries(n.rows??{})){const i=Number(s)-1;if(i>=e.top&&i<=e.bottom&&t in r)return!0}return o.tables.some(s=>k(s.area,e)&&s.columns.some(r=>r.spec!==void 0&&t in r.spec&&s.at.col+r.index>=e.left&&s.at.col+r.index<=e.right))}export function setLook(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n);return applyLook(r,s,e,t),r.finish()}export function applyLook(n,o,e,t){const s=n.spec(o);Ce(n,o,s,e,t),tidied(s)}function Ce(n,o,e,t,s){const r=ne.filter(u=>u in s);if(e.cells&&r.length>0)for(const[u,a]of Object.entries(e.cells)){if(a===null||typeof a!="object"||!a.runs)continue;const w=v(u);w&&k(w,t)&&(e.cells={...e.cells,[u]:ke(a,r)})}if(e.cells){const u={...e.cells},a=[];for(const[w,b]of Object.entries(u)){if(b===null||typeof b!="object"||!W(b,s))continue;const j=v(w);!j||!k(j,t)||(w.includes(":")&&!z(t,j)&&a.push({range:w,...Object.fromEntries(Object.entries(b).filter(([H])=>H in s))}),u[w]=Oe(L(b,s)))}e.cells=u,a.length>0&&(e.format=[...e.format??[],...a])}const i=e.format??[],l=u=>{const a=v(u.range);return a!==void 0&&k(a,t)},f=i.some(u=>l(u)&&W(u,s)),c=Object.fromEntries(Object.entries(s).filter(([,u])=>u!==void 0)),d=t.top===0&&t.bottom===V-1,m=t.left===0&&t.right===P-1;if(d&&!m&&!f){let u={...e.columns};for(let a=t.left;a<=t.right;a++){const w=$(a),b={...L(u[w]??{},s),...c};u=Object.keys(b).length===0?O(u,w):{...u,[w]:b}}e.columns=u;return}if(m&&!d&&!f){let u={...e.rows};for(let a=t.top;a<=t.bottom;a++){const w=String(a+1),b={...L(u[w]??{},s),...c};u=Object.keys(b).length===0?O(u,w):{...u,[w]:b}}e.rows=u;return}const h=o.tables.find(u=>u.rows>0&&t.top===u.data.top&&t.bottom===u.data.bottom&&t.left>=u.area.left&&t.right<=u.area.right);if(h&&!f){const u=n.table(o,h);let a={...u.columns};for(let w=t.left;w<=t.right;w++){const b=h.columns[w-h.at.col]?.name;if(b===void 0)continue;const j={...L(a[b]??{},s),...c};a=Object.keys(j).length===0?O(a,b):{...a,[b]:j}}u.columns=a,Object.keys(a).length===0&&delete u.columns,n.edit.whole=!0;return}const g=E(t),y=i.find(u=>{const a=v(u.range);return a!==void 0&&E(a)===g}),A=(y?i.slice(i.indexOf(y)+1):[]).some(u=>l(u)&&W(u,s)),p={};for(const[u,a]of Object.entries(s)){const w=i.some(b=>b!==y&&l(b)&&u in b)||ve(e,o,t,u);a!==void 0?p[u]=a:w&&(p[u]=je[u])}if(y&&!A){const u={...L(y,s),...p};e.format=i.flatMap(a=>a!==y?[a]:Object.keys(u).length>1?[u]:[])}else Object.keys(p).length>0&&(e.format=[...i,{range:g,...p}])}export function tidied(n){n.format?.length===0&&delete n.format,n.columns&&Object.keys(n.columns).length===0&&delete n.columns,n.rows&&Object.keys(n.rows).length===0&&delete n.rows,n.cells&&Object.keys(n.cells).length===0&&delete n.cells}export function setColumnWidth(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n),i=r.spec(s),l=$(e),f=R(i.columns?.[l]??{},"width"),c=t===void 0?f:{...f,width:t},d=O(i.columns??{},l);return i.columns=Object.keys(c).length===0?d:{...d,[l]:c},tidied(i),r.finish()}export function setRowHeight(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n),i=r.spec(s),l=String(e+1),f=R(i.rows?.[l]??{},"height"),c=t===void 0?f:{...f,height:t},d=O(i.rows??{},l);return i.rows=Object.keys(c).length===0?d:{...d,[l]:c},tidied(i),r.finish()}export function sheetNameProblem(n,o,e){if(o.trim()===""||o.length>31||/[\\/?*[\]:]/u.test(o)||o.startsWith("'")||o.endsWith("'"))return"sheet-name";const t=n.workbook.sheet(o);if(t&&t.name!==e)return"sheet-taken"}export function renameSheet(n,o,e){const t=sheetNameProblem(n,e,o);if(t)return refused(t);const s=_(n,{op:"rename-sheet",from:o,to:e});return{...blankEdit(),file:s.file,rows:new Map(s.rows),whole:!0}}export function addSheet(n,o,e){const t=sheetNameProblem(n,o);if(t)return refused(t);const s=[...n.file.sheets],r=s.findIndex(i=>i.name===e);return s.splice(r<0?s.length:r+1,0,{name:o}),{...blankEdit(),file:{...n.file,sheets:s},whole:!0}}export function copyName(n,o){for(let e=2;;e++){const t=` (${String(e)})`,s=o.slice(0,31-t.length).trimEnd()+t;if(!n.workbook.sheet(s))return s}}export function duplicateSheet(n,o){const e=te(n,o,copyName(n,o));return e.refused?refused(e.refused):{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0}}export function deleteSheet(n,o){const e=_(n,{op:"delete-sheet",name:o});if(e.refused)return refused(e.refused);const t=xe(n.file,e.file);for(const s of t)e.rows.delete(s);return{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0,...t.length===0?{}:{removed:t}}}function xe(n,o){const e=s=>s.sheets.flatMap(r=>[...(r.tables??[]).map(i=>i.rows),...(r.blocks??[]).map(i=>i.rows)]),t=new Set(e(o));return[...new Set(e(n))].filter(s=>!t.has(s))}export function moveSheet(n,o,e){const t=[...n.file.sheets],s=t.findIndex(i=>i.name===o),[r]=t.splice(s,1);return r?(t.splice(e,0,r),{...blankEdit(),file:{...n.file,sheets:t},whole:!0}):refused("no-sheet")}export function bandEdit(n,o){const e=_(n,o);return e.refused?refused(e.refused):{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0}}export function defineName(n,o,e,t){if(!X(o)||n.workbook.name(o)||n.workbook.table(o))return refused("name-invalid");const s=(l,f)=>`$${$(f)}$${String(l+1)}`,r=t.top===t.bottom&&t.left===t.right?s(t.top,t.left):`${s(t.top,t.left)}:${s(t.bottom,t.right)}`,i=/^[\p{L}_][\p{L}\p{N}_.]*$/u.test(e)?e:`'${e.replaceAll("'","''")}'`;return{...blankEdit(),file:{...n.file,names:{...n.file.names,[o]:`=${i}!${r}`}},whole:!0}}export function inputOf(n,o,e,t){const s=o.at(e,t);if(s===void 0)return"";if(s instanceof ie)return s.text;const r=o.tableAt(e,t);if(r){const d=r.columns[t-r.at.col];if(e===r.at.row)return d?.name??"";const m=d?.csv===void 0?void 0:r.records[e-r.at.row-1]?.[d.csv];if(m!==void 0)return m}const i=o.blockAt(e,t);if(i){const d=n.rows.get(i.file)?.[e-i.area.top]?.[t-i.area.left];if(d!==void 0)return d}const l=o.keys.get(le(e,t)),f=l===void 0?void 0:o.spec.cells?.[l],c=f!==null&&typeof f=="object"?f.value:f;return c!=null?String(c):typeof s=="object"?s.code:String(s)}export function exceptionsOf(n){const o=[];for(const e of n.columns){const{csv:t}=e;!e.formula||t===void 0||n.records.forEach((s,r)=>{const i=s[t]??"";i!==""&&o.push({row:n.at.row+1+r,col:n.at.col+e.index,column:e.name,text:i})})}return o}function Le(n){const o=new Set([...n.file.sheets.flatMap(e=>(e.tables??[]).map(t=>t.name)),...Object.keys(n.file.names??{})].map(e=>e.toLowerCase()));for(let e=1;;e++){const t=`Table${String(e)}`;if(!o.has(t.toLowerCase()))return t}}export function makeTable(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");if(s.tables.some(p=>k(p.area,e)))return refused("table-overlap");const r=e.right-e.left+1,i=(p,u)=>inputOf(n,s,p,u);if(!t.header){if(e.top===0)return refused("table-room");for(let p=0;p<r;p++)if(i(e.top-1,e.left+p)!=="")return refused("table-room")}const l=new Draft(n),f=new Set,c=Array.from({length:r},(p,u)=>{const a=t.header?i(e.top,e.left+u).trim():"";let w=a===""?`Column${String(u+1)}`:a;for(let b=2;f.has(w.toLowerCase());b++)w=`${a===""?`Column${String(u+1)}`:a}${String(b)}`;return f.add(w.toLowerCase()),w}),d=t.header?e.top+1:e.top,m=[];for(let p=d;p<=e.bottom;p++)m.push(Array.from({length:r},(u,a)=>i(p,e.left+a)));for(const[p,u]of G(s,e)){const a=writeOne(l,n,s,p,u,"");if(a)return a}const h=Le(n),g=new Set([...n.rows.keys(),...l.edit.rows.keys()].map(p=>p.toLowerCase()));let y=`data/${h.toLowerCase()}.csv`;for(let p=2;g.has(y);p++)y=`data/${h.toLowerCase()}-${String(p)}.csv`;l.edit.rows.set(y,[c,...m]);const M=l.spec(s),A=t.header?e.top:e.top-1;return M.tables=[...M.tables??[],{name:h,at:S({row:A,col:e.left}),rows:y,...t.style!==void 0&&t.style!=="TableStyleMedium2"?{style:t.style}:{}}],l.edit.whole=!0,l.finish()}export function setTableStyle(n,o,e,t){const s=n.workbook.sheet(o),r=s?.tables.find(f=>f.name===e);if(!s||!r)return refused("no-sheet");const i=new Draft(n),l=i.table(s,r);return t==="TableStyleMedium2"?delete l.style:l.style=t,i.edit.whole=!0,i.finish()}export function setTableOptions(n,o,e,t){const s=n.workbook.sheet(o),r=s?.tables.find(f=>f.name===e);if(!s||!r)return refused("no-sheet");const i=new Draft(n),l=i.table(s,r);return t.banded_rows!==void 0&&(t.banded_rows?delete l.banded_rows:l.banded_rows=!1),t.banded_columns!==void 0&&(t.banded_columns?l.banded_columns=!0:delete l.banded_columns),t.first_column!==void 0&&(t.first_column?l.first_column=!0:delete l.first_column),t.last_column!==void 0&&(t.last_column?l.last_column=!0:delete l.last_column),i.edit.whole=!0,i.finish()}function F(n,o){return o===void 0?n.names:n.sheets.find(e=>e.name===o)?.names}function B(n,o,e){const t=Object.keys(e).length===0?void 0:e;if(o===void 0){const s={...n};return t?s.names=t:delete s.names,s}return{...n,sheets:n.sheets.map(s=>{if(s.name!==o)return s;const r={...s};return t?r.names=t:delete r.names,r})}}export function setName(n,o){const e=o.name.trim(),t=o.was!==void 0&&o.was.name.toLowerCase()!==e.toLowerCase(),s=Object.keys(F(n.file,o.scope)??{}).some(d=>d.toLowerCase()===e.toLowerCase()&&!(d.toLowerCase()===o.was?.name.toLowerCase()&&o.was.scope===o.scope));if(!X(e)||s||n.workbook.table(e))return refused("name-invalid");const r=o.value.trim(),i=C(r).value,l=r.startsWith("=")||i instanceof re?r:i,f=t&&o.was?bandEdit(n,{op:"rename-name",from:o.was.name,to:e}):void 0;if(f?.refused)return f;let c=f?.file??n.file;if(o.was){const d={...F(c,o.was.scope)};for(const m of Object.keys(d))m.toLowerCase()===o.was.name.toLowerCase()&&(d[m]=null);c=B(c,o.was.scope,Object.fromEntries(Object.entries(d).filter(([,m])=>m!==null)))}return c=B(c,o.scope,{...F(c,o.scope),[e]:l}),{...blankEdit(),file:c,rows:f?.rows??new Map,whole:!0}}export function deleteName(n,o,e){const t=F(n.file,e)??{},s=Object.fromEntries(Object.entries(t).filter(([r])=>r.toLowerCase()!==o.toLowerCase()));return{...blankEdit(),file:B(n.file,e,s),whole:!0}}
|
|
@@ -27,4 +27,14 @@ export declare function fillDownTo(sheet: Worksheet, area: Area): number | undef
|
|
|
27
27
|
* of one moves as its cells' values.
|
|
28
28
|
*/
|
|
29
29
|
export declare function moveCells(book: EditBook, sheetName: string, from: Area, toSheet: string, to: Place): BookEdit;
|
|
30
|
+
export type CellShift = "right" | "down" | "left" | "up";
|
|
31
|
+
/**
|
|
32
|
+
* Excel's Insert Cells (shift right or down) and Delete Cells (shift left or
|
|
33
|
+
* up) over an area: the cells from it to the sheet's edge, across it alone,
|
|
34
|
+
* move by its size, looks with them, and every formula that named them
|
|
35
|
+
* follows, as Excel's references do (one to a deleted cell is #REF!).
|
|
36
|
+
* Refused when a table or a merged range is among what would move, as
|
|
37
|
+
* Excel refuses.
|
|
38
|
+
*/
|
|
39
|
+
export declare function shiftCells(book: EditBook, sheetName: string, area: Area, shift: CellShift): BookEdit;
|
|
30
40
|
//# sourceMappingURL=fill.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{cellName as
|
|
2
|
+
import{MAX_COLUMNS as et,MAX_ROWS as nt,cellName as W,contains as U,overlaps as T,rangeName as st}from"./address.js";import{rectangles as X}from"./api/rectangles.js";import{Draft as z,applyLook as $,blankEdit as D,clearCells as G,dropKeys as rt,inputOf as B,movedTo as H,refused as M,writeCells as P,writeOne as it}from"./edit.js";import{relativeKey as ct}from"./formula/move.js";import{parseFormula as Q}from"./formula/parse.js";import{printFormula as lt}from"./formula/print.js";import{mapNode as ft}from"./formula/walk.js";import{restructure as V}from"./structure.js";import{seriesAfter as ut}from"./series.js";import{readTyped as pt}from"./values.js";import{workbookOf as dt}from"./workbook.js";const J=s=>pt(s).formula!==void 0;function wt(s,e,t){const o=Q(s);return o.ok?ct(o.node,e,t):void 0}const ht=(s,e)=>!s.tables.some(t=>T(t.area,e))&&!s.blocks.some(t=>T(t.area,e));function at(s,e,t,o){if(s.some(r=>J(r.text))){const r=s.length;return e.map((f,i)=>{const p=t?s[((r-1-i)%r+r)%r]:s[i%r],h=p?.text??"";return{...f,text:p?H(h,f.row-p.row,f.col-p.col):h}})}const n=ut(s.map(r=>r.text),e.length,{mode:o,back:t});return e.map((r,f)=>({...r,text:n[f]??""}))}const Y=["bold","italic","underline","strike","font","size","color","fill","align","valign","wrap","shrink","indent","rotation","border","locked","hide_formula","format"];export const NO_LOOK=Object.fromEntries(Y.map(s=>[s,void 0]));export function copyLooks(s,e,t,o){const c=new Map;for(const n of o){const r=e.lookAt(n.from.row,n.from.col),f=t.lookAt(n.to.row,n.to.col);if(JSON.stringify(r)===JSON.stringify(f))continue;const i=JSON.stringify(r),p=c.get(i);p?p.places.push(n.to):c.set(i,{look:r,places:[n.to]})}for(const{look:n,places:r}of c.values()){const f={};for(const i of Y)f[i]=n[i];for(const i of X(r))$(s,t,i,f)}}export function autoFill(s,e,t,o,c="auto"){const n=s.workbook.sheet(e);if(!n)return M("no-sheet");const r=o.bottom>t.bottom||o.top<t.top,f=o.top<t.top||o.left<t.left,i=new z(s),p=r?{first:t.left,last:t.right}:{first:t.top,last:t.bottom},h=new Map,y=(u,d)=>{const x=`${String(u)}:${String(d)}`;let v=h.get(x);return v===void 0&&(v=B(s,n,u,d),h.set(x,v)),v},L=(t.bottom-t.top+1)*(t.right-t.left+1),m=new Set;for(let u=t.top;u<=t.bottom;u++)for(let d=t.left;d<=t.right;d++){const x=y(u,d);J(x)&&m.add(wt(x,u,d)??"")}if(m.size===1&&L>0&&ht(n,o)&&bt(y,t)){const u=i.spec(n);return rt(u,o),u.cells={...u.cells,[st(o)]:H(y(t.top,t.left),o.top-t.top,o.left-t.left)},i.edit.whole=!0,Z(i,n,t,o,r),i.finish()}for(let u=p.first;u<=p.last;u++){const d=[];if(r)for(let w=t.top;w<=t.bottom;w++)d.push({row:w,col:u,text:y(w,u)});else for(let w=t.left;w<=t.right;w++)d.push({row:u,col:w,text:y(u,w)});const x=[],v=f?r?t.top-1:t.left-1:r?t.bottom+1:t.right+1,A=r?f?o.top:o.bottom:f?o.left:o.right,E=f?-1:1;for(let w=v;f?w>=A:w<=A;w+=E)x.push(r?{row:w,col:u}:{row:u,col:w});for(const w of at(d,x,f,c))it(i,s,n,w.row,w.col,w.text)}return Z(i,n,t,o,r),i.finish()}function bt(s,e){for(let t=e.top;t<=e.bottom;t++)for(let o=e.left;o<=e.right;o++)if(!J(s(t,o)))return!1;return!0}function Z(s,e,t,o,c){const n=[],r=t.bottom-t.top+1,f=t.right-t.left+1;for(let i=o.top;i<=o.bottom;i++)for(let p=o.left;p<=o.right;p++){if(U(t,i,p))continue;const h=c?t.top+((i-t.top)%r+r)%r:i,y=c?p:t.left+((p-t.left)%f+f)%f;n.push({from:{row:h,col:y},to:{row:i,col:p}})}copyLooks(s,e,e,n)}export function pasteLooks(s,e,t,o){const c=s.workbook.sheet(e),n=s.workbook.sheet(t);if(!c||!n)return M("no-sheet");const r=new z(s);return copyLooks(r,c,n,o),r.finish()}export function fillDownTo(s,e){const t=(o,c)=>c>=0&&s.at(o,c)!==void 0;for(const o of[e.left-1,e.right+1]){if(!t(e.bottom,o)&&!t(e.bottom+1,o))continue;let c=e.bottom;for(;t(c+1,o);)c+=1;if(c>e.bottom)return c}}function gt(s,e,t){if(!J(s))return s;const o=Q(s);if(!o.ok)return s;const c=ft(o.node,n=>n.kind!=="ref"?n:n.sheet===void 0?{...n,sheet:e}:n.sheet.toLowerCase()!==t.toLowerCase()||n.lastSheet!==void 0?n:Object.fromEntries(Object.entries(n).filter(([r])=>r!=="sheet")));return lt(c)}function N(s){const e=D();e.whole=!0;for(const t of s){t.file&&(e.file=t.file);for(const[o,c]of t.rows)e.rows.set(o,c)}return e}function _(s,e){const t=e.file??s.file,o=new Map(s.rows);for(const[c,n]of e.rows)o.set(c,n);return{file:t,rows:o,workbook:dt({file:t,rows:c=>o.get(c)})}}export function moveCells(s,e,t,o,c){const n=s.workbook.sheet(e),r=s.workbook.sheet(o);if(!n||!r)return M("no-sheet");const f=c.row-t.top,i=c.col-t.left;if(f===0&&i===0&&n===r)return D();const p={top:c.row,left:c.col,bottom:t.bottom+f,right:t.right+i},h=n.tables.filter(l=>U(t,l.area.top,l.area.left)&&U(t,l.area.bottom,l.area.right));for(const l of n.tables)if(!h.includes(l)&&T(l.area,t)&&t.top<=l.at.row)return M("table-move");if(h.length>0&&n!==r)return M("table-move");for(const l of r.tables)if(!h.includes(l)&&T(l.area,p)&&p.top<=l.at.row)return M("table-move");const y={op:"move-cells",sheet:e,area:t,rows:f,columns:i,...n===r?{}:{to:o}},L=V(s,y),m={...D(),file:L.file,rows:new Map(L.rows)},u=_(s,m),d=u.workbook.sheet(e),x=u.workbook.sheet(o);if(!d||!x)return M("no-sheet");const v=[],A=[],E=Math.min(t.right,d.columnsUsed-1),w=Math.min(t.bottom,d.lastRow),K=(l,b)=>h.some(g=>U(g.area,l,b));for(let l=t.top;l<=w;l++)for(let b=t.left;b<=E;b++)if(!K(l,b)){if(d.at(l,b)!==void 0){const g=B(u,d,l,b);v.push({row:l+f,col:b+i,text:n===r?g:gt(g,e,o)})}A.push({from:{row:l,col:b},to:{row:l+f,col:b+i}})}const S=G(u,e,t);if(S.refused!==void 0)return S;const C=_(u,S),j=[m,S];let R=C;if(h.length>0){const l=new z(C),b=C.workbook.sheet(e);if(!b)return M("no-sheet");for(const I of h){const q=b.tables.find(ot=>ot.name===I.name);if(!q)continue;const tt=l.table(b,q);tt.at=W({row:I.at.row+f,col:I.at.col+i})}const g=l.finish();j.push(g),R=_(C,g)}const F=P(R,o,v);if(F.refused!==void 0)return F;j.push(F);const a=_(R,F),O=a.workbook.sheet(e),k=a.workbook.sheet(o);if(O&&k){const l=new z(a);copyLooks(l,d,k,A);const b=A.map(g=>g.from).filter(g=>!(n===r&&U(p,g.row,g.col))&&Object.keys(d.lookAt(g.row,g.col)).length>0);for(const g of X(b))$(l,O,g,NO_LOOK);j.push(l.finish())}return N(j)}export function shiftCells(s,e,t,o){const c=s.workbook.sheet(e);if(!c)return M("no-sheet");const n=o==="down"||o==="up",r=o==="down"||o==="right",f=n?t.bottom-t.top+1:t.right-t.left+1,i=n?{...t,bottom:Math.max(t.bottom,c.lastRow)}:{...t,right:Math.max(t.right,c.columnsUsed-1)},p=n?{...t,bottom:nt-1}:{...t,right:et-1};if(c.tables.some(a=>T(a.area,p)))return M("table-shift");if(c.merges.some(a=>T(a,p)))return M("merge-shift");const h=V(s,{op:"shift-cells",sheet:e,rows:n,insert:r,at:n?t.top:t.left,count:f,first:n?t.left:t.top,last:n?t.right:t.bottom});if(h.refused!==void 0)return M(h.refused);const y={...D(),file:h.file,rows:new Map(h.rows)},L=_(s,y),m=L.workbook.sheet(e);if(!m)return M("no-sheet");const u=r?f:-f,d=r?i:n?{...i,top:t.bottom+1}:{...i,left:t.right+1},x=Math.min(i.bottom,m.lastRow),v=Math.min(i.right,m.columnsUsed-1),A=[],E=[],w=new Set;for(let a=d.top;a<=Math.min(d.bottom,x);a++)for(let O=d.left;O<=Math.min(d.right,v);O++){const k=n?{row:a+u,col:O}:{row:a,col:O+u};m.at(a,O)!==void 0&&A.push({...k,text:B(L,m,a,O)}),E.push({from:{row:a,col:O},to:k}),w.add(W(k))}const K=G(L,e,i);if(K.refused!==void 0)return K;const S=_(L,K),C=P(S,e,A);if(C.refused!==void 0)return C;const j=_(S,C),R=[y,K,C],F=j.workbook.sheet(e);if(F){const a=new z(j);copyLooks(a,m,F,E);const O=[];for(let k=i.top;k<=x;k++)for(let l=i.left;l<=v;l++)!w.has(W({row:k,col:l}))&&Object.keys(m.lookAt(k,l)).length>0&&O.push({row:k,col:l});for(const k of X(O))$(a,F,k,NO_LOOK);R.push(a.finish())}return N(R)}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import"./address.js";import{compareForSort as
|
|
2
|
+
import"./address.js";import{hasWildcard as q,wildcard as M}from"./calc/functions/criteria.js";import{compareForSort as T}from"./sort.js";import{shownValue as L}from"./format.js";import{choicesIn as E}from"./validate.js";const g=(e,n,o,t)=>L(n.value(e,o,t),e.lookAt(o,t).format),v=(e,n)=>{if(n==="")return e.blanks===!0;const o=n.toLowerCase();return e.values?.some(t=>t.toLowerCase()===o)===!0},h=e=>e.values!==void 0||e.blanks!==void 0,O=(e,n)=>!h(e)||v(e,n);function C(e,n,o,t){const r=e.validations.length===0?void 0:e.validationAt(n,o);return r?.spec.multiple===!0?E(t,r.spec):[t]}function A(e,n,o){const{operator:t}=e,r=e.value;if(typeof r=="number"&&typeof n=="number")switch(t){case"equal":return n===r;case"notEqual":return n!==r;case"greaterThan":return n>r;case"greaterThanOrEqual":return n>=r;case"lessThan":return n<r;case"lessThanOrEqual":return n<=r}const a=String(r);if(t==="equal"||t==="notEqual"){const m=q(a)?M(a)(o):o.toLowerCase()===a.toLowerCase();return t==="equal"?m:!m}if(o==="")return!1;const i=o.toLowerCase().localeCompare(a.toLowerCase());switch(t){case"greaterThan":return i>0;case"greaterThanOrEqual":return i>=0;case"lessThan":return i<0;case"lessThanOrEqual":return i<=0}}function R(e,n,o,t,r){const{top:a}=o.area,i=Math.min(o.area.bottom,e.lastRow),m=()=>{const s=[];for(let u=a+1;u<=i;u++){const d=n.value(e,u,t);typeof d=="number"&&s.push(d)}return s};if(r.values!==void 0||r.blanks!==void 0)return s=>{const u=g(e,n,s,t);return u===""?r.blanks===!0:C(e,s,t,u).some(d=>v(r,d))};const p=r.conditions;if(p)return s=>{const u=n.value(e,s,t),d=g(e,n,s,t),c=p.map(f=>A(f,u,d));return r.or===!0?c.some(Boolean):c.every(Boolean)};const l=r.top;if(l){const s=m().sort((c,f)=>l.bottom===!0?c-f:f-c),u=l.percent===!0?Math.max(1,Math.floor(s.length*l.count/100)):Math.round(l.count),d=s[Math.min(u,s.length)-1];return c=>{const f=n.value(e,c,t);return typeof f!="number"||d===void 0?!1:l.bottom===!0?f<=d:f>=d}}if(r.average){const s=m(),u=s.reduce((c,f)=>c+f,0)/Math.max(1,s.length),d=r.average==="above";return c=>{const f=n.value(e,c,t);return typeof f=="number"&&(d?f>u:f<u)}}const b=r.color;return b?s=>{const u=e.lookAt(s,t);return b.fill!==void 0?typeof u.fill=="string"&&u.fill.toUpperCase()===b.fill.toUpperCase():b.font!==void 0?(u.color??"#000000").toUpperCase()===b.font.toUpperCase():!0}:()=>!0}function k(e,n,o,t){return[...o.columns].filter(([r])=>r!==t).map(([r,a])=>R(e,n,o,r,a))}const y=(e,n)=>e.every(o=>o(n));export function filteredRows(e,n){const o=new Set;for(const t of e.filters){if(t.columns.size===0)continue;const{top:r,bottom:a}=t.area,i=Math.min(a,e.lastRow),m=k(e,n,t);for(let p=r+1;p<=i;p++)y(m,p)||o.add(p)}return o}export function filterChoices(e,n,o,t){const r=o.columns.get(t),a=new Map;let i=0;const{top:m,bottom:p}=o.area,l=Math.min(p,e.lastRow),b=k(e,n,o,t);for(let s=m+1;s<=l;s++){if(!y(b,s))continue;const u=g(e,n,s,t);if(u===""){i+=1;continue}const d=C(e,s,t,u);for(const c of d){const f=c.toLowerCase(),w=a.get(f);w?w.count+=1:a.set(f,{text:c,count:1,on:r===void 0||O(r,c),value:d.length>1?c:n.value(e,s,t)})}}return{values:[...a.values()].sort((s,u)=>T(s.value,u.value)),blanks:i===0?void 0:{count:i,on:r===void 0||r.blanks===!0||!h(r)}}}export function regionAround(e,n){const o=(a,i)=>a>=0&&i>=0&&(e.at(a,i)!==void 0||e.spillAt(a,i)!==void 0),t={top:n.row,left:n.col,bottom:n.row,right:n.col};for(let a=!0;a;){a=!1;const i=p=>{for(let l=t.left-1;l<=t.right+1;l++)if(o(p,l))return!0;return!1},m=p=>{for(let l=t.top-1;l<=t.bottom+1;l++)if(o(l,p))return!0;return!1};i(t.top-1)&&(t.top-=1,a=!0),i(t.bottom+1)&&(t.bottom+=1,a=!0),m(t.left-1)&&(t.left-=1,a=!0),m(t.right+1)&&(t.right+=1,a=!0)}return t.top===t.bottom&&t.left===t.right&&!o(t.top,t.left)?void 0:t}
|
|
@@ -47,6 +47,20 @@ export type StructureEdit = {
|
|
|
47
47
|
op: "delete-column";
|
|
48
48
|
table: string;
|
|
49
49
|
name: string;
|
|
50
|
+
} | {
|
|
51
|
+
/**
|
|
52
|
+
* Excel's Insert Cells and Delete Cells: rows (or columns) put in or
|
|
53
|
+
* taken out at `at` across `first`…`last` alone, the cells past them
|
|
54
|
+
* shifted down or up (right or left).
|
|
55
|
+
*/
|
|
56
|
+
op: "shift-cells";
|
|
57
|
+
sheet: string;
|
|
58
|
+
rows: boolean;
|
|
59
|
+
insert: boolean;
|
|
60
|
+
at: number;
|
|
61
|
+
count: number;
|
|
62
|
+
first: number;
|
|
63
|
+
last: number;
|
|
50
64
|
} | {
|
|
51
65
|
op: "move-cells";
|
|
52
66
|
sheet: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{MAX_COLUMNS as
|
|
2
|
+
import{MAX_COLUMNS as M,MAX_ROWS as S}from"../address.js";import{mapNode as O}from"./walk.js";const c=(n,r)=>n?.toLowerCase()===r?.toLowerCase(),k=(n,r,t)=>n.index>=r?{...n,index:n.index+t}:n;function R(n,r,t){if(n.index<r)return n;if(n.index>=r+t)return{...n,index:n.index-t}}function C(n,r,t,s){const o=n.index<=r.index?n:r,e=o===n?r:n,u=k(o,t,s),i=e.index>=t?{...e,index:e.index+s}:e;return o===n?[u,i]:[i,u]}function E(n,r,t,s){const o=n.index<=r.index?n:r,e=o===n?r:n,u=t+s-1;if(o.index>=t&&e.index<=u)return;const i=o.index<t?o:o.index>u?{...o,index:o.index-s}:{...o,index:t},a=e.index<t?e:e.index>u?{...e,index:e.index-s}:{...e,index:t-1};return o===n?[i,a]:[a,i]}function x(n){return{kind:"error",code:"#REF!",...n.sheet===void 0?{}:{sheet:n.sheet}}}const h={kind:"error",code:"#REF!"};function g(n,r,t){if(!c(n.sheet??t,r.sheet)||n.lastSheet!==void 0)return n;const{col:s,row:o}=n;if(s===void 0||o===void 0)return n;const e=n.col2??s,u=n.row2??o,{area:i,rows:a,columns:d,to:f}=r;if(!(Math.min(s.index,e.index)>=i.left&&Math.max(s.index,e.index)<=i.right&&Math.min(o.index,u.index)>=i.top&&Math.max(o.index,u.index)<=i.bottom))return n;const l=(m,b)=>({...m,index:m.index+b}),w={...n,col:l(s,d),row:l(o,a),...n.col2?{col2:l(n.col2,d)}:{},...n.row2?{row2:l(n.row2,a)}:{}};return f===void 0?w:c(f,t)?Object.fromEntries(Object.entries(w).filter(([m])=>m!=="sheet")):{...w,sheet:f}}function p(n,r,t){if(!c(n.sheet??t,r.sheet)||n.lastSheet!==void 0)return n;const s=r.op==="insert-rows"||r.op==="delete-rows",o=s?n.row:n.col,e=s?n.row2:n.col2;if(o===void 0)return n;const u=s?["row","row2"]:["col","col2"],i=r.op==="insert-rows"||r.op==="insert-columns",a=s?S:M;if(e===void 0){const f=i?k(o,r.at,r.count):R(o,r.at,r.count);return!f||f.index>=a?x(n):f===o?n:{...n,[u[0]]:f}}const d=i?C(o,e,r.at,r.count):E(o,e,r.at,r.count);return!d||d[0].index>=a||d[1].index>=a?x(n):d[0]===o&&d[1]===e?n:{...n,[u[0]]:d[0],[u[1]]:d[1]}}function F(n,r,t){const s=r.rows?n.col:n.row,o=(r.rows?n.col2:n.row2)??s;if(s===void 0||o===void 0||Math.min(s.index,o.index)<r.first||Math.max(s.index,o.index)>r.last)return n;const e=r.rows?r.insert?"insert-rows":"delete-rows":r.insert?"insert-columns":"delete-columns";return p(n,{op:e,sheet:r.sheet,at:r.at,count:r.count},t)}export function rewriteFormula(n,r,t,s){const o=(e,u)=>e===void 0?s===void 0||c(s,u):c(e,u);return O(n,e=>{switch(r.op){case"rename-sheet":return(e.kind==="ref"||e.kind==="name"||e.kind==="error")&&c(e.sheet,r.from)?{...e,sheet:r.to}:e.kind==="ref"&&c(e.lastSheet,r.from)?{...e,lastSheet:r.to}:e;case"rename-table":return e.kind==="structured"&&c(e.table,r.from)?{...e,table:r.to}:e;case"delete-sheet":return e.kind==="ref"&&c(e.sheet,r.name)||e.kind==="ref"&&c(e.lastSheet,r.name)?x(e):e.kind==="name"&&c(e.sheet,r.name)?h:e;case"delete-table":return e.kind==="structured"&&c(e.table,r.name)||e.kind==="name"&&c(e.name,r.name)?h:e;case"delete-column":return e.kind==="structured"&&o(e.table,r.table)&&e.columns.some(u=>c(u,r.name))?h:e;case"rename-column":return e.kind==="structured"&&o(e.table,r.table)&&e.columns.some(u=>c(u,r.from))?{...e,columns:e.columns.map(u=>c(u,r.from)?r.to:u)}:e;case"rename-name":return e.kind==="name"&&c(e.name,r.from)?{...e,name:r.to}:e.kind==="call"&&c(e.name,r.from)?{...e,name:r.to.toUpperCase(),written:r.to}:e;case"move-cells":return e.kind==="ref"?g(e,r,t):e;case"shift-cells":return e.kind==="ref"?F(e,r,t):e;default:return e.kind==="ref"?p(e,r,t):e}})}
|