@sheetpane/review 0.0.0-stage → 0.4.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/LICENSE +21 -0
- package/README.md +125 -2
- package/dist/fills.d.ts +64 -0
- package/dist/fills.d.ts.map +1 -0
- package/dist/fills.js +233 -0
- package/dist/fills.js.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/rows.d.ts +49 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +79 -0
- package/dist/rows.js.map +1 -0
- package/dist/sheet.d.ts +74 -0
- package/dist/sheet.d.ts.map +1 -0
- package/dist/sheet.js +181 -0
- package/dist/sheet.js.map +1 -0
- package/dist/write.d.ts +53 -0
- package/dist/write.d.ts.map +1 -0
- package/dist/write.js +99 -0
- package/dist/write.js.map +1 -0
- package/dist/xml.d.ts +23 -0
- package/dist/xml.d.ts.map +1 -0
- package/dist/xml.js +41 -0
- package/dist/xml.js.map +1 -0
- package/package.json +45 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,gFAAgF;AAChF,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAA8B,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAkC5D,MAAM,OAAO,GAAG,CAAC,CAAU,EAAwB,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CA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AAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,kBAAkB,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;QAC3J,CAAC;KACF,CAAC;AACJ,CAAC;AAED,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/rows.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ProblemSeverity, type Severity, type SheetpaneError } from '@sheetpane/grid';
|
|
2
|
+
/** The severities that are problems — what the review lists and colours unless `severities` names others. */
|
|
3
|
+
export declare const PROBLEM_SEVERITIES: readonly ProblemSeverity[];
|
|
4
|
+
/** The Review sheet's columns, left to right. */
|
|
5
|
+
export declare const COLUMNS: readonly ['ID', 'Sheet', 'Cell', 'Severity', 'Type', 'Found', 'Expected', 'Message', 'Author', 'Status', 'Accepted', 'Accepted by', 'Accepted at'];
|
|
6
|
+
/** Column widths in Excel's character units, one per {@link COLUMNS} entry. */
|
|
7
|
+
export declare const WIDTHS: readonly number[];
|
|
8
|
+
/** One row of the Review sheet: the cells' text, and where the Cell column links to. */
|
|
9
|
+
export interface ReviewRow {
|
|
10
|
+
/** The error. */
|
|
11
|
+
error: SheetpaneError;
|
|
12
|
+
/** One string per {@link COLUMNS} entry; `''` leaves the cell empty. */
|
|
13
|
+
cells: string[];
|
|
14
|
+
/** The internal hyperlink of the Cell column (`'Holdings'!I6`), or undefined for none. */
|
|
15
|
+
link: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** What the export lists. */
|
|
18
|
+
export interface Selection {
|
|
19
|
+
/** The severities listed; default {@link PROBLEM_SEVERITIES}. */
|
|
20
|
+
severities?: readonly Severity[] | undefined;
|
|
21
|
+
/** The layers listed (an error with no `layer` is `review`); default every layer but `compare` (W-63), which is listed only when named. */
|
|
22
|
+
layers?: readonly string[] | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** A sheet name quoted for a reference: `'Q3 ''final'''!`. */
|
|
25
|
+
export declare const quoteSheet: (name: string) => string;
|
|
26
|
+
/** `2026-10-19T09:12:00.000Z` → `2026-10-19 09:12 UTC`; anything unreadable as it is. */
|
|
27
|
+
export declare function when(iso: string | undefined): string;
|
|
28
|
+
/** `@sheetpane/compare`'s layer (W-63): a comparison is not the review, so it is listed only when `layers` names it — as `@sheetpane/comments` writes it. */
|
|
29
|
+
export declare const COMPARE_LAYER = "compare";
|
|
30
|
+
/**
|
|
31
|
+
* The errors one export lists: not the file's own comments (`author: 'file'`), only the severities and layers
|
|
32
|
+
* asked for (by default every layer but `compare`); the workbook's errors first, then each sheet in the file's order — its whole-sheet errors, then its
|
|
33
|
+
* cells top to bottom, left to right.
|
|
34
|
+
*
|
|
35
|
+
* @param errors - The store's errors.
|
|
36
|
+
* @param sel - The severities and layers to list.
|
|
37
|
+
* @param sheetOrder - The file's sheet names, in order.
|
|
38
|
+
* @returns The errors to list, in order.
|
|
39
|
+
*/
|
|
40
|
+
export declare function selectErrors(errors: readonly SheetpaneError[], sel: Selection, sheetOrder: readonly string[]): SheetpaneError[];
|
|
41
|
+
/**
|
|
42
|
+
* The Review sheet's row for one error. An accepted error (W-69) reads *Accepted: <reason>*, with who and when.
|
|
43
|
+
*
|
|
44
|
+
* @param e - The error.
|
|
45
|
+
* @param hasSheet - Whether the file has a sheet by this name (no link otherwise).
|
|
46
|
+
* @returns The row's cells and its link.
|
|
47
|
+
*/
|
|
48
|
+
export declare function rowOf(e: SheetpaneError, hasSheet: (name: string) => boolean): ReviewRow;
|
|
49
|
+
//# sourceMappingURL=r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AS,cAAc,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,cAAc,EAAE,CAc/H;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,CAiBvF"}
|
package/dist/rows.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Which errors the review lists, in which order, and the text of each row
|
|
2
|
+
// (W-59 DoD 1, 5). Pure functions over the store's errors: no XML here.
|
|
3
|
+
import { BUILTIN_TYPE_NAMES, DEFAULT_ERROR_TYPES, SEVERITY, errorScope, layerOf } from '@sheetpane/grid';
|
|
4
|
+
import { parseRange } from '@sheetpane/export';
|
|
5
|
+
/** The severities that are problems — what the review lists and colours unless `severities` names others. */
|
|
6
|
+
export const PROBLEM_SEVERITIES = ['error', 'warning', 'note'];
|
|
7
|
+
/** The Review sheet's columns, left to right. */
|
|
8
|
+
export const COLUMNS = ['ID', 'Sheet', 'Cell', 'Severity', 'Type', 'Found', 'Expected', 'Message', 'Author', 'Status', 'Accepted', 'Accepted by', 'Accepted at'];
|
|
9
|
+
/** Column widths in Excel's character units, one per {@link COLUMNS} entry. */
|
|
10
|
+
export const WIDTHS = [11, 16, 12, 10, 18, 18, 18, 60, 14, 10, 40, 14, 18];
|
|
11
|
+
/** A sheet name quoted for a reference: `'Q3 ''final'''!`. */
|
|
12
|
+
export const quoteSheet = (name) => `'${name.replace(/'/g, "''")}'`;
|
|
13
|
+
const typeName = (id) => DEFAULT_ERROR_TYPES.find((t) => t.id === id)?.name ?? BUILTIN_TYPE_NAMES[id] ?? id;
|
|
14
|
+
const cap = (s) => (s ? s[0].toUpperCase() + s.slice(1) : s);
|
|
15
|
+
/** A severity's name as the panel shows it — `Passed` and `Not checked` for W-50's results; one from an old saved review that is no severity, capitalised. */
|
|
16
|
+
const severityName = (s) => SEVERITY[s]?.name ?? cap(s);
|
|
17
|
+
/** `2026-10-19T09:12:00.000Z` → `2026-10-19 09:12 UTC`; anything unreadable as it is. */
|
|
18
|
+
export function when(iso) {
|
|
19
|
+
if (!iso)
|
|
20
|
+
return '';
|
|
21
|
+
const d = new Date(iso);
|
|
22
|
+
return Number.isNaN(d.getTime()) ? iso : `${d.toISOString().slice(0, 16).replace('T', ' ')} UTC`;
|
|
23
|
+
}
|
|
24
|
+
/** `@sheetpane/compare`'s layer (W-63): a comparison is not the review, so it is listed only when `layers` names it — as `@sheetpane/comments` writes it. */
|
|
25
|
+
export const COMPARE_LAYER = 'compare';
|
|
26
|
+
/**
|
|
27
|
+
* The errors one export lists: not the file's own comments (`author: 'file'`), only the severities and layers
|
|
28
|
+
* asked for (by default every layer but `compare`); the workbook's errors first, then each sheet in the file's order — its whole-sheet errors, then its
|
|
29
|
+
* cells top to bottom, left to right.
|
|
30
|
+
*
|
|
31
|
+
* @param errors - The store's errors.
|
|
32
|
+
* @param sel - The severities and layers to list.
|
|
33
|
+
* @param sheetOrder - The file's sheet names, in order.
|
|
34
|
+
* @returns The errors to list, in order.
|
|
35
|
+
*/
|
|
36
|
+
export function selectErrors(errors, sel, sheetOrder) {
|
|
37
|
+
const sev = new Set(sel.severities ?? PROBLEM_SEVERITIES);
|
|
38
|
+
const layers = sel.layers ? new Set(sel.layers) : undefined;
|
|
39
|
+
const picked = errors.filter((e) => e.author !== 'file' && sev.has(e.severity) && (layers ? layers.has(layerOf(e)) : layerOf(e) !== COMPARE_LAYER));
|
|
40
|
+
const sheetIx = (s) => { const i = sheetOrder.indexOf(s); return i < 0 ? sheetOrder.length : i; };
|
|
41
|
+
const key = (e) => {
|
|
42
|
+
const scope = errorScope(e);
|
|
43
|
+
if (scope === 'workbook')
|
|
44
|
+
return [0, 0, 0, 0];
|
|
45
|
+
const r = scope === 'cell' ? parseRange(e.range) : undefined;
|
|
46
|
+
return [1, sheetIx(e.sheet), scope === 'sheet' ? -1 : (r?.top ?? Number.MAX_SAFE_INTEGER), r?.left ?? 0];
|
|
47
|
+
};
|
|
48
|
+
const keyed = picked.map((e, i) => ({ e, i, k: key(e) }));
|
|
49
|
+
keyed.sort((a, b) => a.k[0] - b.k[0] || a.k[1] - b.k[1] || (a.k[1] === sheetOrder.length ? a.e.sheet.localeCompare(b.e.sheet) : 0) || a.k[2] - b.k[2] || a.k[3] - b.k[3] || a.i - b.i);
|
|
50
|
+
return keyed.map((x) => x.e);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The Review sheet's row for one error. An accepted error (W-69) reads *Accepted: <reason>*, with who and when.
|
|
54
|
+
*
|
|
55
|
+
* @param e - The error.
|
|
56
|
+
* @param hasSheet - Whether the file has a sheet by this name (no link otherwise).
|
|
57
|
+
* @returns The row's cells and its link.
|
|
58
|
+
*/
|
|
59
|
+
export function rowOf(e, hasSheet) {
|
|
60
|
+
const scope = errorScope(e);
|
|
61
|
+
const range = e.range.trim().toUpperCase().replace(/\$/g, '');
|
|
62
|
+
const cell = scope === 'workbook' ? 'Whole workbook' : scope === 'sheet' ? 'Whole sheet' : range;
|
|
63
|
+
const accepted = e.status === 'accepted';
|
|
64
|
+
const cells = [
|
|
65
|
+
e.id, e.sheet, cell, severityName(e.severity), typeName(e.type), e.found, e.expected, e.message, e.author, cap(e.status),
|
|
66
|
+
accepted ? `Accepted: ${e.reason ?? ''}` : '',
|
|
67
|
+
accepted ? (e.acceptedBy?.trim() || e.author) : '',
|
|
68
|
+
accepted ? when(e.acceptedAt) : '',
|
|
69
|
+
];
|
|
70
|
+
let link;
|
|
71
|
+
if (scope !== 'workbook' && hasSheet(e.sheet)) {
|
|
72
|
+
if (scope === 'sheet')
|
|
73
|
+
link = `${quoteSheet(e.sheet)}!A1`;
|
|
74
|
+
else if (parseRange(range))
|
|
75
|
+
link = `${quoteSheet(e.sheet)}!${range}`;
|
|
76
|
+
}
|
|
77
|
+
return { error: e, cells, link };
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL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UAAU,CAAC;IACzC,MAAM,KAAK,GAAG;QACZ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;QACxH,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE;QAC7C,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;QAClD,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE;KACnC,CAAC;IACF,IAAI,IAAwB,CAAC;IAC7B,IAAI,KAAK,KAAK,UAAU,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C,IAAI,KAAK,KAAK,OAAO;YAAE,IAAI,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;aACrD,IAAI,UAAU,CAAC,KAAK,CAAC;YAAE,IAAI,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;IACvE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACnC,CAAC"}
|
package/dist/sheet.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type ReviewRow } from './rows.js';
|
|
2
|
+
import { type PatchContext } from './xml.js';
|
|
3
|
+
/** The defined name that marks the Review sheet: workbook-scoped, hidden, over the table (`'Review'!$A$1:$M$4`). */
|
|
4
|
+
export declare const REVIEW_NAME = "_sheetpane_review";
|
|
5
|
+
/**
|
|
6
|
+
* A usable sheet name from what the host asked for: forbidden characters dropped, apostrophes trimmed from the ends,
|
|
7
|
+
* at most 31 characters; `Review` when nothing is left.
|
|
8
|
+
*
|
|
9
|
+
* @param name - The name asked for.
|
|
10
|
+
* @returns A name Excel accepts.
|
|
11
|
+
*/
|
|
12
|
+
export declare function cleanSheetName(name: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* A name no sheet has, compared as Excel compares them (ignoring case): `Review`, else `Review (2)`, `Review (3)`…
|
|
15
|
+
* trimmed so the whole stays within 31 characters. A user's sheet is never overwritten.
|
|
16
|
+
*
|
|
17
|
+
* @param base - The clean name.
|
|
18
|
+
* @param taken - The workbook's sheet names.
|
|
19
|
+
* @returns A free name.
|
|
20
|
+
*/
|
|
21
|
+
export declare function uniqueSheetName(base: string, taken: readonly string[]): string;
|
|
22
|
+
/** The sheet a formula like `'Q3 ''x'''!$A$1:$M$9` (or `Review!A1`) points at. */
|
|
23
|
+
export declare function sheetOfFormula(formula: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Which sheet of a workbook is a Review sheet sheetpane wrote, by its defined name — so a host can leave it out
|
|
26
|
+
* when the annotated file is uploaded again.
|
|
27
|
+
*
|
|
28
|
+
* @param book - A workbook as `@sheetpane/import` reads it (its `definedNames` and `sheets`).
|
|
29
|
+
* @returns The Review sheet's name, or undefined when the file has none.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { read } from '@sheetpane/import';
|
|
33
|
+
* import { reviewSheetOf } from '@sheetpane/review';
|
|
34
|
+
*
|
|
35
|
+
* const book = await read(bytes, { name: 'holdings.xlsx' });
|
|
36
|
+
* const skip = reviewSheetOf(book); // 'Review', or undefined
|
|
37
|
+
* const data = book.sheets.filter((s) => s.name !== skip);
|
|
38
|
+
* ```
|
|
39
|
+
* @see https://github.com/arpitarya/sheetpane/blob/main/records/0123_REVIEW.md
|
|
40
|
+
*/
|
|
41
|
+
export declare function reviewSheetOf(book: {
|
|
42
|
+
definedNames: readonly {
|
|
43
|
+
name: string;
|
|
44
|
+
formula: string;
|
|
45
|
+
}[];
|
|
46
|
+
sheets: readonly {
|
|
47
|
+
name: string;
|
|
48
|
+
}[];
|
|
49
|
+
}): string | undefined;
|
|
50
|
+
/** The worksheet XML: a frozen header row, column widths, one row per error, the Cell column's links. */
|
|
51
|
+
export declare function sheetXml(rows: readonly ReviewRow[], headerStyle: number | undefined): string;
|
|
52
|
+
/** Puts the marker name in the workbook part, replacing an earlier one; `<definedNames>` is created in schema position when missing. */
|
|
53
|
+
export declare function setMarker(wb: string, formula: string): string;
|
|
54
|
+
/** Adds `<sheet name sheetId r:id>` at the end of `<sheets>`, binding the relationships namespace on the root when missing. */
|
|
55
|
+
export declare function addSheet(wb: string, name: string, rId: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Writes the Review sheet. An earlier Review sheet this plugin wrote (the marker names it, and it has no parts of
|
|
58
|
+
* its own) is rewritten in place; otherwise a new sheet is added last, under a name no sheet has.
|
|
59
|
+
*
|
|
60
|
+
* @param patch - The export's package.
|
|
61
|
+
* @param rows - The rows, in order.
|
|
62
|
+
* @param o - The name asked for and the header's style index (none: unstyled).
|
|
63
|
+
* @returns The name and part of the sheet written.
|
|
64
|
+
*/
|
|
65
|
+
export declare function writeReviewSheet(patch: PatchContext, rows: readonly ReviewRow[], o: {
|
|
66
|
+
name: string;
|
|
67
|
+
headerStyle?: number | undefined;
|
|
68
|
+
}): Promise<{
|
|
69
|
+
name: string;
|
|
70
|
+
path: string;
|
|
71
|
+
}>;
|
|
72
|
+
/** The workbook's styles part, through its relationship. */
|
|
73
|
+
export declare function stylesPath(patch: PatchContext): Promise<string | undefined>;
|
|
74
|
+
//# sourceMappingURL=sheet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"she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AE,EAAE,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CA0BtL;AAQD,4DAA4D;AAC5D,wBAAsB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAKjF"}
|
package/dist/sheet.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// The Review sheet (W-59 DoD 2): a new worksheet part, its relationship and
|
|
2
|
+
// content type, a <sheet> in the workbook, and a defined name that marks it so a
|
|
3
|
+
// host can skip it when the file comes back. Every cell is an inline string, so
|
|
4
|
+
// sharedStrings is never touched. Links are internal hyperlinks (`location`),
|
|
5
|
+
// which need no relationship.
|
|
6
|
+
import { cellRef, escapeAttr, escapeText, getAttr, parseRels, relsPathOf, resolveTarget, setAttr, spError, unescapeXml } from '@sheetpane/export';
|
|
7
|
+
import { COLUMNS, WIDTHS, quoteSheet } from './rows.js';
|
|
8
|
+
import { CT_WORKSHEET, NS_MAIN, NS_R, REL_WORKSHEET, XML_DECL, freeName, inlineText, prefixOf, relativeTarget, } from './xml.js';
|
|
9
|
+
/** The defined name that marks the Review sheet: workbook-scoped, hidden, over the table (`'Review'!$A$1:$M$4`). */
|
|
10
|
+
export const REVIEW_NAME = '_sheetpane_review';
|
|
11
|
+
/** Characters a sheet name may not hold. */
|
|
12
|
+
const BAD = /[[\]:*?/\\]/g;
|
|
13
|
+
/**
|
|
14
|
+
* A usable sheet name from what the host asked for: forbidden characters dropped, apostrophes trimmed from the ends,
|
|
15
|
+
* at most 31 characters; `Review` when nothing is left.
|
|
16
|
+
*
|
|
17
|
+
* @param name - The name asked for.
|
|
18
|
+
* @returns A name Excel accepts.
|
|
19
|
+
*/
|
|
20
|
+
export function cleanSheetName(name) {
|
|
21
|
+
const s = name.replace(BAD, '').replace(/^'+|'+$/g, '').trim().slice(0, 31).replace(/'+$/, '');
|
|
22
|
+
return s || 'Review';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A name no sheet has, compared as Excel compares them (ignoring case): `Review`, else `Review (2)`, `Review (3)`…
|
|
26
|
+
* trimmed so the whole stays within 31 characters. A user's sheet is never overwritten.
|
|
27
|
+
*
|
|
28
|
+
* @param base - The clean name.
|
|
29
|
+
* @param taken - The workbook's sheet names.
|
|
30
|
+
* @returns A free name.
|
|
31
|
+
*/
|
|
32
|
+
export function uniqueSheetName(base, taken) {
|
|
33
|
+
const have = new Set(taken.map((t) => t.toLowerCase()));
|
|
34
|
+
if (!have.has(base.toLowerCase()))
|
|
35
|
+
return base;
|
|
36
|
+
for (let n = 2;; n++) {
|
|
37
|
+
const tail = ` (${n})`;
|
|
38
|
+
const name = base.slice(0, 31 - tail.length).replace(/'+$/, '') + tail;
|
|
39
|
+
if (!have.has(name.toLowerCase()))
|
|
40
|
+
return name;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The sheet a formula like `'Q3 ''x'''!$A$1:$M$9` (or `Review!A1`) points at. */
|
|
44
|
+
export function sheetOfFormula(formula) {
|
|
45
|
+
const f = formula.trim().replace(/^=/, '');
|
|
46
|
+
const q = /^'((?:[^']|'')+)'!/.exec(f);
|
|
47
|
+
if (q)
|
|
48
|
+
return q[1].replace(/''/g, "'");
|
|
49
|
+
const p = /^([^'!]+)!/.exec(f);
|
|
50
|
+
return p ? p[1] : undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Which sheet of a workbook is a Review sheet sheetpane wrote, by its defined name — so a host can leave it out
|
|
54
|
+
* when the annotated file is uploaded again.
|
|
55
|
+
*
|
|
56
|
+
* @param book - A workbook as `@sheetpane/import` reads it (its `definedNames` and `sheets`).
|
|
57
|
+
* @returns The Review sheet's name, or undefined when the file has none.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { read } from '@sheetpane/import';
|
|
61
|
+
* import { reviewSheetOf } from '@sheetpane/review';
|
|
62
|
+
*
|
|
63
|
+
* const book = await read(bytes, { name: 'holdings.xlsx' });
|
|
64
|
+
* const skip = reviewSheetOf(book); // 'Review', or undefined
|
|
65
|
+
* const data = book.sheets.filter((s) => s.name !== skip);
|
|
66
|
+
* ```
|
|
67
|
+
* @see https://github.com/arpitarya/sheetpane/blob/main/records/0123_REVIEW.md
|
|
68
|
+
*/
|
|
69
|
+
export function reviewSheetOf(book) {
|
|
70
|
+
const d = book.definedNames.find((n) => n.name.toLowerCase() === REVIEW_NAME);
|
|
71
|
+
const name = d && sheetOfFormula(d.formula);
|
|
72
|
+
return name !== undefined && book.sheets.some((s) => s.name === name) ? name : undefined;
|
|
73
|
+
}
|
|
74
|
+
/** The worksheet XML: a frozen header row, column widths, one row per error, the Cell column's links. */
|
|
75
|
+
export function sheetXml(rows, headerStyle) {
|
|
76
|
+
const last = cellRef(rows.length, COLUMNS.length - 1);
|
|
77
|
+
const cell = (r, c, text, s) => (text === '' ? '' : `<c r="${cellRef(r, c)}"${s ? ` s="${s}"` : ''} t="inlineStr">${inlineText(text)}</c>`);
|
|
78
|
+
const head = `<row r="1">${COLUMNS.map((h, c) => cell(0, c, h, headerStyle)).join('')}</row>`;
|
|
79
|
+
const body = rows.map((row, i) => `<row r="${i + 2}">${row.cells.map((t, c) => cell(i + 1, c, t)).join('')}</row>`).join('');
|
|
80
|
+
const links = rows.map((row, i) => (row.link ? `<hyperlink ref="${cellRef(i + 1, 2)}" location="${escapeAttr(row.link)}" display="${escapeAttr(row.cells[2])}"/>` : '')).join('');
|
|
81
|
+
const cols = WIDTHS.map((w, i) => `<col min="${i + 1}" max="${i + 1}" width="${w}" customWidth="1"/>`).join('');
|
|
82
|
+
return `${XML_DECL}<worksheet xmlns="${NS_MAIN}" xmlns:r="${NS_R}"><dimension ref="A1:${last}"/>`
|
|
83
|
+
+ '<sheetViews><sheetView workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/><selection pane="bottomLeft" activeCell="A2" sqref="A2"/></sheetView></sheetViews>'
|
|
84
|
+
+ `<sheetFormatPr defaultRowHeight="15"/><cols>${cols}</cols><sheetData>${head}${body}</sheetData>`
|
|
85
|
+
+ (links ? `<hyperlinks>${links}</hyperlinks>` : '')
|
|
86
|
+
+ '<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>';
|
|
87
|
+
}
|
|
88
|
+
/** Puts the marker name in the workbook part, replacing an earlier one; `<definedNames>` is created in schema position when missing. */
|
|
89
|
+
export function setMarker(wb, formula) {
|
|
90
|
+
const P = prefixOf(wb, 'workbook');
|
|
91
|
+
const el = `<${P}definedName name="${REVIEW_NAME}" hidden="1">${escapeText(formula)}</${P}definedName>`;
|
|
92
|
+
let out = wb.replace(new RegExp(`<(?:\\w+:)?definedName\\b[^>]*\\bname\\s*=\\s*"${REVIEW_NAME}"[^>]*?(?:/>|>[\\s\\S]*?</(?:\\w+:)?definedName>)`, 'gi'), '');
|
|
93
|
+
const self = /<(?:\w+:)?definedNames\b[^>]*\/>/.exec(out);
|
|
94
|
+
if (self)
|
|
95
|
+
return out.replace(self[0], `<${P}definedNames>${el}</${P}definedNames>`);
|
|
96
|
+
const close = new RegExp(`</(?:\\w+:)?definedNames>`).exec(out);
|
|
97
|
+
if (close)
|
|
98
|
+
return out.slice(0, close.index) + el + out.slice(close.index);
|
|
99
|
+
// CT_Workbook: … sheets, functionGroups, externalReferences, definedNames …
|
|
100
|
+
for (const name of ['externalReferences', 'functionGroups', 'sheets']) {
|
|
101
|
+
const m = new RegExp(`</(?:\\w+:)?${name}>|<(?:\\w+:)?${name}\\b[^>]*/>`).exec(out);
|
|
102
|
+
if (m) {
|
|
103
|
+
const at = m.index + m[0].length;
|
|
104
|
+
return `${out.slice(0, at)}<${P}definedNames>${el}</${P}definedNames>${out.slice(at)}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
throw spError('SP-5001', 'sheetpane review: the workbook part has no <sheets>');
|
|
108
|
+
}
|
|
109
|
+
/** Adds `<sheet name sheetId r:id>` at the end of `<sheets>`, binding the relationships namespace on the root when missing. */
|
|
110
|
+
export function addSheet(wb, name, rId) {
|
|
111
|
+
const root = /<(\w+:)?workbook\b[^>]*>/.exec(wb);
|
|
112
|
+
if (!root)
|
|
113
|
+
throw spError('SP-5001', 'sheetpane review: not a workbook part');
|
|
114
|
+
const P = root[1] ?? '';
|
|
115
|
+
let out = wb, rp = 'r';
|
|
116
|
+
const bound = [...root[0].matchAll(/\sxmlns:([\w.-]+)\s*=\s*"([^"]*)"/g)].find((m) => m[2] === NS_R);
|
|
117
|
+
if (bound)
|
|
118
|
+
rp = bound[1];
|
|
119
|
+
else {
|
|
120
|
+
if (/\sxmlns:r\s*=/.test(root[0]))
|
|
121
|
+
rp = 'spr';
|
|
122
|
+
out = out.replace(root[0], setAttr(root[0], `xmlns:${rp}`, NS_R));
|
|
123
|
+
}
|
|
124
|
+
const ids = [...out.matchAll(/<(?:\w+:)?sheet\b[^>]*>/g)].map((m) => Number(getAttr(m[0], 'sheetId') ?? 0)).filter(Number.isFinite);
|
|
125
|
+
const el = `<${P}sheet name="${escapeAttr(name)}" sheetId="${Math.max(0, ...ids) + 1}" ${rp}:id="${rId}"/>`;
|
|
126
|
+
const close = /<\/(?:\w+:)?sheets>/.exec(out);
|
|
127
|
+
if (close)
|
|
128
|
+
return out.slice(0, close.index) + el + out.slice(close.index);
|
|
129
|
+
const self = /<(?:\w+:)?sheets\b[^>]*\/>/.exec(out);
|
|
130
|
+
if (self)
|
|
131
|
+
return out.replace(self[0], `<${P}sheets>${el}</${P}sheets>`);
|
|
132
|
+
throw spError('SP-5001', 'sheetpane review: the workbook part has no <sheets>');
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Writes the Review sheet. An earlier Review sheet this plugin wrote (the marker names it, and it has no parts of
|
|
136
|
+
* its own) is rewritten in place; otherwise a new sheet is added last, under a name no sheet has.
|
|
137
|
+
*
|
|
138
|
+
* @param patch - The export's package.
|
|
139
|
+
* @param rows - The rows, in order.
|
|
140
|
+
* @param o - The name asked for and the header's style index (none: unstyled).
|
|
141
|
+
* @returns The name and part of the sheet written.
|
|
142
|
+
*/
|
|
143
|
+
export async function writeReviewSheet(patch, rows, o) {
|
|
144
|
+
const wbPath = patch.workbookPath();
|
|
145
|
+
const wb = await patch.readText(wbPath);
|
|
146
|
+
if (wb === undefined)
|
|
147
|
+
throw spError('SP-5001', 'sheetpane review: no workbook part');
|
|
148
|
+
const xml = sheetXml(rows, o.headerStyle);
|
|
149
|
+
const range = `$A$1:$${cellRef(rows.length, COLUMNS.length - 1).replace(/(\d+)$/, '$$$1')}`;
|
|
150
|
+
// an earlier export's Review sheet, found by its marker: replaced, not repeated
|
|
151
|
+
const marker = [...wb.matchAll(/<(?:\w+:)?definedName\b[^>]*>([\s\S]*?)<\/(?:\w+:)?definedName>/g)].find((m) => (getAttr(m[0], 'name') ?? '').toLowerCase() === REVIEW_NAME);
|
|
152
|
+
const earlier = marker && sheetOfFormula(unescapeXml(marker[1]));
|
|
153
|
+
const earlierPath = earlier !== undefined ? patch.sheetPath(earlier) : undefined;
|
|
154
|
+
if (earlier !== undefined && earlierPath && !(await hasRelationships(patch, earlierPath))) {
|
|
155
|
+
const next = setMarker(wb, `${quoteSheet(earlier)}!${range}`);
|
|
156
|
+
patch.write(earlierPath, xml);
|
|
157
|
+
patch.write(wbPath, next);
|
|
158
|
+
return { name: earlier, path: earlierPath };
|
|
159
|
+
}
|
|
160
|
+
const name = uniqueSheetName(cleanSheetName(o.name), patch.sheetNames());
|
|
161
|
+
setMarker(addSheet(wb, name, 'rId0'), ''); // the workbook part is checked before anything is written
|
|
162
|
+
const path = freeName((p) => patch.has(p), 'xl/worksheets/sheet', '.xml');
|
|
163
|
+
patch.write(path, xml);
|
|
164
|
+
const rId = await patch.addRelationship(wbPath, REL_WORKSHEET, relativeTarget(wbPath, path));
|
|
165
|
+
await patch.setContentType(path, CT_WORKSHEET);
|
|
166
|
+
patch.write(wbPath, setMarker(addSheet(wb, name, rId), `${quoteSheet(name)}!${range}`));
|
|
167
|
+
return { name, path };
|
|
168
|
+
}
|
|
169
|
+
/** Whether a part has any relationship of its own (a Review sheet someone gave comments or a drawing in Excel). */
|
|
170
|
+
async function hasRelationships(patch, part) {
|
|
171
|
+
const rels = await patch.readText(relsPathOf(part));
|
|
172
|
+
return !!rels && parseRels(rels).length > 0;
|
|
173
|
+
}
|
|
174
|
+
/** The workbook's styles part, through its relationship. */
|
|
175
|
+
export async function stylesPath(patch) {
|
|
176
|
+
const wb = patch.workbookPath();
|
|
177
|
+
const rels = await patch.readText(relsPathOf(wb));
|
|
178
|
+
const r = rels && parseRels(rels).find((x) => x.type.endsWith('/styles') && x.mode !== 'External');
|
|
179
|
+
return r ? resolveTarget(wb, r.target) : undefined;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=sheet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sheet.js","sourceRoot":"","sources":["../src/sheet.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iFAAiF;AACjF,gFAAgF;AAChF,8EAA8E;AAC9E,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClJ,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAkB,MAAM,WAAW,CAAC;AACxE,OAAO,EACL,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,GACrG,MAAM,UAAU,CAAC;AAElB,oHAAoH;AACpH,MAAM,CA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C;AAED,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAmB;IAClD,MAAM,EAAE,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IAClD,MAAM,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;IACnG,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC"}
|
package/dist/write.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Severity, type SheetpaneError, type SpCode } from '@sheetpane/grid';
|
|
2
|
+
import type { PatchContext } from './xml.js';
|
|
3
|
+
/** Why an error's cells were not (or not all) coloured. */
|
|
4
|
+
export type SkipReason = 'no-cell' | 'no-sheet' | 'bad-range' | 'range-capped' | 'no-styles' | 'unreadable-part';
|
|
5
|
+
/** What one export wrote. */
|
|
6
|
+
export interface ReviewReport {
|
|
7
|
+
/** The Review sheet's name as written (`Review`, or `Review (2)` beside a user's own *Review*); undefined when none was written. */
|
|
8
|
+
sheet: string | undefined;
|
|
9
|
+
/** The ids listed on the Review sheet, in its order. */
|
|
10
|
+
listed: string[];
|
|
11
|
+
/** The listed errors by status: an accepted error (W-69) is never counted with the open ones. */
|
|
12
|
+
counts: {
|
|
13
|
+
open: number;
|
|
14
|
+
accepted: number;
|
|
15
|
+
resolved: number;
|
|
16
|
+
};
|
|
17
|
+
/** The ids whose cells were coloured. */
|
|
18
|
+
filled: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Errors whose cells were not coloured, and why: `no-cell` — about a whole sheet or the workbook (W-55), listed,
|
|
21
|
+
* never coloured; `no-sheet` / `bad-range` — nowhere to colour; `range-capped` — over 10,000 cells, so only the
|
|
22
|
+
* cells the file has were coloured (SP-5003); `no-styles` — the file has no readable styles part (SP-5004);
|
|
23
|
+
* `unreadable-part` — the sheet could not be read, so it was left as it was (SP-5002).
|
|
24
|
+
*/
|
|
25
|
+
skipped: {
|
|
26
|
+
id: string;
|
|
27
|
+
reason: SkipReason;
|
|
28
|
+
code?: SpCode;
|
|
29
|
+
}[];
|
|
30
|
+
}
|
|
31
|
+
/** How one export writes. */
|
|
32
|
+
export interface WriteOptions {
|
|
33
|
+
/** Write the Review sheet. */
|
|
34
|
+
sheet: boolean;
|
|
35
|
+
/** Colour flagged cells. */
|
|
36
|
+
fill: boolean;
|
|
37
|
+
/** The Review sheet's name, as asked for. */
|
|
38
|
+
sheetName: string;
|
|
39
|
+
/** Severity → ARGB fill; a severity not named is not coloured. */
|
|
40
|
+
fills: Readonly<Record<string, string>>;
|
|
41
|
+
/** Severities, worst first: on a cell flagged twice, the worse one's fill wins. */
|
|
42
|
+
order: readonly Severity[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Writes the review into the package.
|
|
46
|
+
*
|
|
47
|
+
* @param patch - The export's package.
|
|
48
|
+
* @param errors - The errors to list, in order (already selected).
|
|
49
|
+
* @param o - What to write.
|
|
50
|
+
* @returns What was written and skipped.
|
|
51
|
+
*/
|
|
52
|
+
export declare function writeReview(patch: PatchContext, errors: readonly SheetpaneError[], o: WriteOptions): Promise<ReviewReport>;
|
|
53
|
+
//# sourceMappingURL=write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAIA,OAAO,EAAyB,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKzG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fills first (each sheet's flagged
|
|
2
|
+
// cells), then the Review sheet, then the styles part once with every fill and
|
|
3
|
+
// cloned format appended. A part that cannot be read is left as it was, and
|
|
4
|
+
// what was not written is reported (W-59 DoD 2, 3, 5).
|
|
5
|
+
import { errorScope, spMessage } from '@sheetpane/grid';
|
|
6
|
+
import { parseRange, spError } from '@sheetpane/export';
|
|
7
|
+
import { HEADER_FILL, StyleBook, fillSheet, planRange } from './fills.js';
|
|
8
|
+
import { rowOf } from './rows.js';
|
|
9
|
+
import { stylesPath, writeReviewSheet } from './sheet.js';
|
|
10
|
+
/**
|
|
11
|
+
* Writes the review into the package.
|
|
12
|
+
*
|
|
13
|
+
* @param patch - The export's package.
|
|
14
|
+
* @param errors - The errors to list, in order (already selected).
|
|
15
|
+
* @param o - What to write.
|
|
16
|
+
* @returns What was written and skipped.
|
|
17
|
+
*/
|
|
18
|
+
export async function writeReview(patch, errors, o) {
|
|
19
|
+
const report = { sheet: undefined, listed: [], filled: [], skipped: [], counts: { open: 0, accepted: 0, resolved: 0 } };
|
|
20
|
+
const rank = (s) => { const i = o.order.findIndex((x) => x === s); return i < 0 ? o.order.length : i; };
|
|
21
|
+
const sp = await stylesPath(patch);
|
|
22
|
+
let book;
|
|
23
|
+
try {
|
|
24
|
+
const x = sp ? await patch.readText(sp) : undefined;
|
|
25
|
+
book = x === undefined ? undefined : new StyleBook(x);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
book = undefined;
|
|
29
|
+
}
|
|
30
|
+
// 1 · the flagged cells: open errors at a cell, with a fill for their severity
|
|
31
|
+
if (o.fill) {
|
|
32
|
+
const bySheet = new Map();
|
|
33
|
+
for (const e of errors) {
|
|
34
|
+
if (e.status !== 'open' || !o.fills[e.severity])
|
|
35
|
+
continue; // an accepted or resolved error is not a problem
|
|
36
|
+
if (errorScope(e) !== 'cell') {
|
|
37
|
+
report.skipped.push({ id: e.id, reason: 'no-cell' });
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!patch.sheetPath(e.sheet)) {
|
|
41
|
+
report.skipped.push({ id: e.id, reason: 'no-sheet' });
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const r = parseRange(e.range.replace(/\$/g, ''));
|
|
45
|
+
if (!r) {
|
|
46
|
+
report.skipped.push({ id: e.id, reason: 'bad-range' });
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!book) {
|
|
50
|
+
report.skipped.push({ id: e.id, reason: 'no-styles', code: 'SP-5004' });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
(bySheet.get(e.sheet) ?? bySheet.set(e.sheet, []).get(e.sheet)).push({ e, r });
|
|
54
|
+
}
|
|
55
|
+
for (const [sheet, items] of bySheet) {
|
|
56
|
+
const path = patch.sheetPath(sheet);
|
|
57
|
+
const plan = { cells: new Map(), wide: [] };
|
|
58
|
+
const capped = [];
|
|
59
|
+
for (const { e, r } of items)
|
|
60
|
+
if (!planRange(plan, r, e.severity, rank))
|
|
61
|
+
capped.push(e.id);
|
|
62
|
+
try {
|
|
63
|
+
const xml = await patch.readText(path);
|
|
64
|
+
if (xml === undefined)
|
|
65
|
+
throw spError('SP-5002', `sheetpane review: no part ${path}`);
|
|
66
|
+
patch.write(path, fillSheet(xml, plan, rank, (s, sev) => book.clone(s, o.fills[sev])));
|
|
67
|
+
report.filled.push(...items.map(({ e }) => e.id));
|
|
68
|
+
for (const id of capped)
|
|
69
|
+
report.skipped.push({ id, reason: 'range-capped', code: 'SP-5003' });
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
console.error(spMessage('SP-5002', `sheetpane review: cells on sheet "${sheet}" not coloured`), err);
|
|
73
|
+
for (const { e } of items)
|
|
74
|
+
report.skipped.push({ id: e.id, reason: 'unreadable-part', code: 'SP-5002' });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// 2 · the Review sheet
|
|
79
|
+
if (o.sheet) {
|
|
80
|
+
const names = new Set(patch.sheetNames());
|
|
81
|
+
const rows = errors.map((e) => rowOf(e, (n) => names.has(n)));
|
|
82
|
+
try {
|
|
83
|
+
const written = await writeReviewSheet(patch, rows, { name: o.sheetName, headerStyle: book?.clone(0, HEADER_FILL) });
|
|
84
|
+
report.sheet = written.name;
|
|
85
|
+
report.listed = errors.map((e) => e.id);
|
|
86
|
+
for (const e of errors)
|
|
87
|
+
if (e.status === 'open' || e.status === 'accepted' || e.status === 'resolved')
|
|
88
|
+
report.counts[e.status]++;
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
console.error(spMessage('SP-5001', 'sheetpane review: the Review sheet was not written'), err);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// 3 · the styles part, once
|
|
95
|
+
if (sp && book?.changed)
|
|
96
|
+
patch.write(sp, book.toXml());
|
|
97
|
+
return report;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+EAA+E;AAC/E,4EAA4E;AAC5E,uDAAuD;AACvD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAmD,MAAM,iBAAiB,CAAC;AACzG,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAiB,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAuC1D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAmB,EAAE,MAAiC,EAAE,CAAe;IACvG,MAAM,MAAM,GAAiB,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE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SAAS,CAAC,SAAS,EAAE,oDAAoD,CAAC,EAAE,GAAG,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;IAED,4BAA4B;IAC5B,IAAI,EAAE,IAAI,IAAI,EAAE,OAAO;QAAE,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/xml.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Plugin } from '@sheetpane/grid';
|
|
2
|
+
/** What `exportPatch` is handed: the package, through `@sheetpane/export`'s context. */
|
|
3
|
+
export type PatchContext = Parameters<NonNullable<Plugin['exportPatch']>>[0];
|
|
4
|
+
export declare const XML_DECL = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
|
5
|
+
export declare const NS_MAIN = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
6
|
+
export declare const NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
7
|
+
export declare const REL_WORKSHEET = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet";
|
|
8
|
+
export declare const CT_WORKSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
|
|
9
|
+
/** The most text a cell holds. */
|
|
10
|
+
export declare const MAX_TEXT = 32767;
|
|
11
|
+
/** An element, self-closed or not, by local name (any prefix): `<x:xf …/>` or `<xf …>…</xf>`. */
|
|
12
|
+
export declare const elementRe: (name: string, flags?: string) => RegExp;
|
|
13
|
+
/** The opening tag of an element's text. */
|
|
14
|
+
export declare const openTag: (xml: string) => string;
|
|
15
|
+
/** A cell's text as an inline-string body: cleaned of what XML forbids, at most 32,767 characters, SpreadsheetML-escaped. */
|
|
16
|
+
export declare function inlineText(s: string, P?: string): string;
|
|
17
|
+
/** The relative target from one part to another: `xl/workbook.xml` → `xl/worksheets/sheet3.xml` is `worksheets/sheet3.xml`. */
|
|
18
|
+
export declare function relativeTarget(fromPart: string, toPart: string): string;
|
|
19
|
+
/** A part name that does not exist yet: `prefix` + n + `suffix`, smallest n from 1. */
|
|
20
|
+
export declare function freeName(has: (p: string) => boolean, prefix: string, suffix: string): string;
|
|
21
|
+
/** The namespace prefix (with its colon, or `''`) the root element of a part uses. */
|
|
22
|
+
export declare const prefixOf: (xml: string, root: string) => string;
|
|
23
|
+
//# sourceMappingURL=xml.d.ts.map
|