@open-document/core 0.12.0 → 0.13.1
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/dist/{build-DfUfpeTR.js → build-CvsOak5B.js} +1 -1
- package/dist/{check-CHxiOkQG.js → check-CbUBwYmf.js} +3 -3
- package/dist/cli/bin.js +47 -10
- package/dist/config-BWtOZ1jc.d.ts +45 -0
- package/dist/{config-9IdbhVuT.js → config-CltJJVsw.js} +398 -493
- package/dist/{context-BLI1-64_.js → context-CWgfsHoE.js} +2 -1
- package/dist/deploy-gcp-BUiSuqz7.js +758 -0
- package/dist/{dev-yNYKv5mm.js → dev-B8H2qT6G.js} +1 -1
- package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
- package/dist/{diff-Bs205mOx.js → diff-BvIjjgnc.js} +2 -2
- package/dist/{export-tkquS5O5.js → export-DX30_s2q.js} +3 -3
- package/dist/{sdk-CHEGeINh.d.ts → flow-CS5apebG.d.ts} +72 -3
- package/dist/{import-D1hIKIr3.js → import-DgsdJT5e.js} +2 -2
- package/dist/index.d.ts +155 -59
- package/dist/index.js +896 -90
- package/dist/open-doc-plugin-DnX5usgI.js +320 -0
- package/dist/ops/index.d.ts +98 -13
- package/dist/ops/index.js +3 -3
- package/dist/{ops-Dgqujq5a.js → ops-CSR5RlrE.js} +2 -1
- package/dist/{preview-BImdTH6K.js → preview-DYMUNjXL.js} +1 -1
- package/dist/{templates-DT5zzqHq.js → templates-B5Tz0AKb.js} +3 -3
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2 -1
- package/package.json +1 -1
- package/skills/doc-authoring/SKILL.md +15 -16
- package/skills/doc-authoring/references/long-form.md +43 -2
- package/skills/doc-authoring/references/pagination.md +14 -2
- package/skills/doc-authoring/references/tables-and-charts.md +21 -17
- package/src/app/components/callout.tsx +101 -0
- package/src/app/components/chart.tsx +191 -33
- package/src/app/components/code-block.tsx +249 -0
- package/src/app/components/data-table.tsx +146 -18
- package/src/app/components/flow-page.tsx +57 -8
- package/src/app/components/numbering.tsx +226 -12
- package/src/app/components/page-frame.tsx +42 -0
- package/src/app/lib/chart.test.ts +15 -0
- package/src/app/lib/chart.ts +134 -9
- package/src/app/lib/diagnostics.ts +45 -1
- package/src/app/lib/export-dom.ts +15 -2
- package/src/app/lib/export-pdf.ts +9 -1
- package/src/app/lib/flow-measure.ts +33 -4
- package/src/app/lib/flow.test.ts +20 -1
- package/src/app/lib/flow.ts +120 -20
- package/src/app/lib/labels.ts +29 -10
- package/src/app/lib/sdk.ts +6 -0
- package/src/app/lib/use-doc-pages.ts +23 -8
- package/src/app/routes/doc.tsx +1 -0
- package/dist/config-P61niZMf.d.ts +0 -24
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import { LOC_PROP, sourceAttrs } from '../lib/source-loc';
|
|
3
|
+
|
|
4
|
+
export type CodeBlockProps = {
|
|
5
|
+
code?: string;
|
|
6
|
+
children?: string;
|
|
7
|
+
lang?: string;
|
|
8
|
+
title?: ReactNode;
|
|
9
|
+
lineNumbers?: boolean;
|
|
10
|
+
/** 1-based line numbers to highlight. */
|
|
11
|
+
highlightLines?: number[];
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
className?: string;
|
|
14
|
+
[LOC_PROP]?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type TokenKind = 'plain' | 'keyword' | 'string' | 'comment' | 'number' | 'type';
|
|
18
|
+
|
|
19
|
+
type Token = { kind: TokenKind; text: string };
|
|
20
|
+
|
|
21
|
+
const KEYWORDS = new Set([
|
|
22
|
+
'import',
|
|
23
|
+
'from',
|
|
24
|
+
'export',
|
|
25
|
+
'default',
|
|
26
|
+
'const',
|
|
27
|
+
'let',
|
|
28
|
+
'var',
|
|
29
|
+
'function',
|
|
30
|
+
'return',
|
|
31
|
+
'if',
|
|
32
|
+
'else',
|
|
33
|
+
'for',
|
|
34
|
+
'while',
|
|
35
|
+
'switch',
|
|
36
|
+
'case',
|
|
37
|
+
'break',
|
|
38
|
+
'continue',
|
|
39
|
+
'async',
|
|
40
|
+
'await',
|
|
41
|
+
'try',
|
|
42
|
+
'catch',
|
|
43
|
+
'finally',
|
|
44
|
+
'throw',
|
|
45
|
+
'new',
|
|
46
|
+
'class',
|
|
47
|
+
'extends',
|
|
48
|
+
'implements',
|
|
49
|
+
'interface',
|
|
50
|
+
'type',
|
|
51
|
+
'satisfies',
|
|
52
|
+
'as',
|
|
53
|
+
'true',
|
|
54
|
+
'false',
|
|
55
|
+
'null',
|
|
56
|
+
'undefined',
|
|
57
|
+
'def',
|
|
58
|
+
'elif',
|
|
59
|
+
'in',
|
|
60
|
+
'and',
|
|
61
|
+
'or',
|
|
62
|
+
'not',
|
|
63
|
+
'SELECT',
|
|
64
|
+
'FROM',
|
|
65
|
+
'WHERE',
|
|
66
|
+
'GROUP',
|
|
67
|
+
'BY',
|
|
68
|
+
'ORDER',
|
|
69
|
+
'LIMIT',
|
|
70
|
+
'JOIN',
|
|
71
|
+
'ON',
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
const TOKEN_RE =
|
|
75
|
+
/(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)|\b(\d+(?:\.\d+)?)\b|\b([A-Za-z_][A-Za-z0-9_]*)\b/g;
|
|
76
|
+
|
|
77
|
+
function tokenizeLine(line: string): Token[] {
|
|
78
|
+
const out: Token[] = [];
|
|
79
|
+
let cursor = 0;
|
|
80
|
+
for (const match of line.matchAll(TOKEN_RE)) {
|
|
81
|
+
const idx = match.index ?? 0;
|
|
82
|
+
if (idx > cursor) {
|
|
83
|
+
out.push({ kind: 'plain', text: line.slice(cursor, idx) });
|
|
84
|
+
}
|
|
85
|
+
const [full, comment, str, num, ident] = match;
|
|
86
|
+
if (comment !== undefined) {
|
|
87
|
+
out.push({ kind: 'comment', text: full });
|
|
88
|
+
} else if (str !== undefined) {
|
|
89
|
+
out.push({ kind: 'string', text: full });
|
|
90
|
+
} else if (num !== undefined) {
|
|
91
|
+
out.push({ kind: 'number', text: full });
|
|
92
|
+
} else if (ident !== undefined) {
|
|
93
|
+
if (KEYWORDS.has(ident)) {
|
|
94
|
+
out.push({ kind: 'keyword', text: full });
|
|
95
|
+
} else if (/^[A-Z]/.test(ident)) {
|
|
96
|
+
out.push({ kind: 'type', text: full });
|
|
97
|
+
} else {
|
|
98
|
+
out.push({ kind: 'plain', text: full });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
cursor = idx + full.length;
|
|
102
|
+
}
|
|
103
|
+
if (cursor < line.length) {
|
|
104
|
+
out.push({ kind: 'plain', text: line.slice(cursor) });
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function tokenStyle(kind: TokenKind): CSSProperties | undefined {
|
|
110
|
+
switch (kind) {
|
|
111
|
+
case 'keyword':
|
|
112
|
+
return { color: 'var(--od-accent, #2563eb)', fontWeight: 600 };
|
|
113
|
+
case 'string':
|
|
114
|
+
return { color: '#0f766e' };
|
|
115
|
+
case 'comment':
|
|
116
|
+
return { color: 'var(--od-muted, #6b7280)', fontStyle: 'italic' };
|
|
117
|
+
case 'number':
|
|
118
|
+
return { color: '#b45309' };
|
|
119
|
+
case 'type':
|
|
120
|
+
return {
|
|
121
|
+
color: 'color-mix(in srgb, var(--od-accent, #2563eb) 75%, var(--od-text, #16181d))',
|
|
122
|
+
fontWeight: 500,
|
|
123
|
+
};
|
|
124
|
+
default:
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Print-ready syntax-highlighted code block with optional header bar, line
|
|
131
|
+
* numbers, and highlighted lines. Uses `--od-*` variables so it harmonizes with
|
|
132
|
+
* the document's design system and exports cleanly to PDF, HTML, and Word.
|
|
133
|
+
*/
|
|
134
|
+
export function CodeBlock({
|
|
135
|
+
code,
|
|
136
|
+
children,
|
|
137
|
+
lang,
|
|
138
|
+
title,
|
|
139
|
+
lineNumbers = false,
|
|
140
|
+
highlightLines,
|
|
141
|
+
style,
|
|
142
|
+
className,
|
|
143
|
+
[LOC_PROP]: loc,
|
|
144
|
+
}: CodeBlockProps) {
|
|
145
|
+
const raw = (code ?? children ?? '').replace(/^\n+|\s+$/g, '');
|
|
146
|
+
const lines = raw.split('\n');
|
|
147
|
+
const highlighted = new Set(highlightLines ?? []);
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div
|
|
151
|
+
{...sourceAttrs(loc)}
|
|
152
|
+
className={className}
|
|
153
|
+
style={{
|
|
154
|
+
border: '1px solid var(--od-rule, #e5e7eb)',
|
|
155
|
+
borderRadius: 'var(--od-radius, 6px)',
|
|
156
|
+
background: 'color-mix(in srgb, var(--od-text, #16181d) 3%, var(--od-bg, #ffffff))',
|
|
157
|
+
overflow: 'hidden',
|
|
158
|
+
margin: '0 0 12px',
|
|
159
|
+
...style,
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
{(title || lang) && (
|
|
163
|
+
<div
|
|
164
|
+
style={{
|
|
165
|
+
display: 'flex',
|
|
166
|
+
alignItems: 'center',
|
|
167
|
+
justifyContent: 'space-between',
|
|
168
|
+
padding: '5px 12px',
|
|
169
|
+
borderBottom: '1px solid var(--od-rule, #e5e7eb)',
|
|
170
|
+
background: 'color-mix(in srgb, var(--od-text, #16181d) 5%, var(--od-bg, #ffffff))',
|
|
171
|
+
fontFamily: 'var(--od-font-mono, monospace)',
|
|
172
|
+
fontSize: 10.5,
|
|
173
|
+
color: 'var(--od-muted, #6b7280)',
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
<span style={{ fontWeight: 600, color: 'var(--od-text, #16181d)' }}>{title ?? ''}</span>
|
|
177
|
+
{lang && (
|
|
178
|
+
<span style={{ textTransform: 'uppercase', letterSpacing: '0.05em', fontSize: 9.5 }}>
|
|
179
|
+
{lang}
|
|
180
|
+
</span>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
)}
|
|
184
|
+
<pre
|
|
185
|
+
style={{
|
|
186
|
+
margin: 0,
|
|
187
|
+
padding: '10px 12px',
|
|
188
|
+
fontFamily: 'var(--od-font-mono, monospace)',
|
|
189
|
+
fontSize: 11,
|
|
190
|
+
lineHeight: 1.55,
|
|
191
|
+
color: 'var(--od-text, #16181d)',
|
|
192
|
+
whiteSpace: 'pre-wrap',
|
|
193
|
+
overflowWrap: 'anywhere',
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
{lines.map((line, index) => {
|
|
197
|
+
const lineNo = index + 1;
|
|
198
|
+
const isHighlighted = highlighted.has(lineNo);
|
|
199
|
+
const tokens = tokenizeLine(line);
|
|
200
|
+
return (
|
|
201
|
+
<div
|
|
202
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: source line order
|
|
203
|
+
key={index}
|
|
204
|
+
style={{
|
|
205
|
+
display: 'flex',
|
|
206
|
+
...(isHighlighted
|
|
207
|
+
? {
|
|
208
|
+
background: 'color-mix(in srgb, var(--od-accent, #2563eb) 10%, transparent)',
|
|
209
|
+
margin: '0 -12px',
|
|
210
|
+
padding: '0 12px',
|
|
211
|
+
borderLeft: '2.5px solid var(--od-accent, #2563eb)',
|
|
212
|
+
}
|
|
213
|
+
: {}),
|
|
214
|
+
}}
|
|
215
|
+
>
|
|
216
|
+
{lineNumbers && (
|
|
217
|
+
<span
|
|
218
|
+
aria-hidden="true"
|
|
219
|
+
style={{
|
|
220
|
+
flex: 'none',
|
|
221
|
+
width: 24,
|
|
222
|
+
paddingRight: 8,
|
|
223
|
+
textAlign: 'right',
|
|
224
|
+
color: 'var(--od-muted, #6b7280)',
|
|
225
|
+
userSelect: 'none',
|
|
226
|
+
fontVariantNumeric: 'tabular-nums',
|
|
227
|
+
opacity: 0.65,
|
|
228
|
+
}}
|
|
229
|
+
>
|
|
230
|
+
{lineNo}
|
|
231
|
+
</span>
|
|
232
|
+
)}
|
|
233
|
+
<span style={{ flex: 1 }}>
|
|
234
|
+
{tokens.length === 0
|
|
235
|
+
? '\u00a0'
|
|
236
|
+
: tokens.map((tok, ti) => (
|
|
237
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: token sequence
|
|
238
|
+
<span key={ti} style={tokenStyle(tok.kind)}>
|
|
239
|
+
{tok.text}
|
|
240
|
+
</span>
|
|
241
|
+
))}
|
|
242
|
+
</span>
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
})}
|
|
246
|
+
</pre>
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
import { LOC_PROP, sourceAttrs } from '../lib/source-loc';
|
|
3
|
+
import { useTableSlice } from './flow-page';
|
|
3
4
|
import { Figure } from './numbering';
|
|
4
5
|
|
|
5
6
|
export type DataAlign = 'left' | 'center' | 'right';
|
|
@@ -9,8 +10,18 @@ export type DataFormat =
|
|
|
9
10
|
| 'number'
|
|
10
11
|
| 'integer'
|
|
11
12
|
| 'percent'
|
|
13
|
+
| 'currency'
|
|
14
|
+
| 'delta'
|
|
12
15
|
| ((value: unknown, row: Record<string, unknown>) => ReactNode);
|
|
13
16
|
|
|
17
|
+
export type DataSummaryOp =
|
|
18
|
+
| 'sum'
|
|
19
|
+
| 'avg'
|
|
20
|
+
| 'min'
|
|
21
|
+
| 'max'
|
|
22
|
+
| 'count'
|
|
23
|
+
| ((values: number[]) => ReactNode);
|
|
24
|
+
|
|
14
25
|
export type DataColumn = {
|
|
15
26
|
key: string;
|
|
16
27
|
label?: ReactNode;
|
|
@@ -18,6 +29,10 @@ export type DataColumn = {
|
|
|
18
29
|
format?: DataFormat;
|
|
19
30
|
/** Column width. A number is px; `tableLayout: fixed` means these are honoured. */
|
|
20
31
|
width?: number | string;
|
|
32
|
+
/** Draws a proportional horizontal bar behind numeric cells in this column. */
|
|
33
|
+
dataBar?: boolean;
|
|
34
|
+
/** Aggregation for this column when `summaryRow` is enabled on the table. */
|
|
35
|
+
summary?: DataSummaryOp | ReactNode;
|
|
21
36
|
};
|
|
22
37
|
|
|
23
38
|
export type DataTableProps = {
|
|
@@ -33,6 +48,12 @@ export type DataTableProps = {
|
|
|
33
48
|
limit?: number;
|
|
34
49
|
/** Tighter rows, for a dense appendix table. */
|
|
35
50
|
compact?: boolean;
|
|
51
|
+
/** Allows `flow()` to split this table across pages and repeat the `<thead>` on each sheet. */
|
|
52
|
+
splittable?: boolean;
|
|
53
|
+
/** Appends a summary footer row. Pass `true` to use column `summary` ops, or a record of values/ops. */
|
|
54
|
+
summaryRow?: boolean | Record<string, DataSummaryOp | ReactNode>;
|
|
55
|
+
/** Label printed in the first column of the summary row when not overridden. Defaults to 'Total'. */
|
|
56
|
+
summaryLabel?: ReactNode;
|
|
36
57
|
/** What an empty cell prints as. Defaults to an em dash. */
|
|
37
58
|
emptyValue?: ReactNode;
|
|
38
59
|
style?: CSSProperties;
|
|
@@ -74,6 +95,14 @@ function formatValue(
|
|
|
74
95
|
if (format === 'integer') return Math.round(value).toLocaleString();
|
|
75
96
|
if (format === 'percent')
|
|
76
97
|
return `${(value * 100).toLocaleString(undefined, { maximumFractionDigits: 1 })}%`;
|
|
98
|
+
if (format === 'currency')
|
|
99
|
+
return `$${value.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}`;
|
|
100
|
+
if (format === 'delta') {
|
|
101
|
+
const sign = value > 0 ? '+' : '';
|
|
102
|
+
const text = `${sign}${value.toLocaleString(undefined, { maximumFractionDigits: 2 })}`;
|
|
103
|
+
const color = value > 0 ? '#15803d' : value < 0 ? '#b91c1c' : 'var(--od-muted)';
|
|
104
|
+
return <span style={{ color, fontWeight: 500 }}>{text}</span>;
|
|
105
|
+
}
|
|
77
106
|
if (format === 'text') return String(value);
|
|
78
107
|
// Grouping separators are what make a column of figures readable; the
|
|
79
108
|
// fraction digits follow the data rather than padding every integer.
|
|
@@ -83,6 +112,26 @@ function formatValue(
|
|
|
83
112
|
return String(value);
|
|
84
113
|
}
|
|
85
114
|
|
|
115
|
+
function computeSummary(
|
|
116
|
+
op: DataSummaryOp | ReactNode,
|
|
117
|
+
values: number[],
|
|
118
|
+
format: DataFormat | undefined,
|
|
119
|
+
emptyValue: ReactNode,
|
|
120
|
+
): ReactNode {
|
|
121
|
+
if (typeof op === 'function') return op(values);
|
|
122
|
+
if (op === 'sum' || op === 'avg' || op === 'min' || op === 'max' || op === 'count') {
|
|
123
|
+
if (values.length === 0) return emptyValue;
|
|
124
|
+
let num = 0;
|
|
125
|
+
if (op === 'count') num = values.length;
|
|
126
|
+
else if (op === 'sum') num = values.reduce((a, b) => a + b, 0);
|
|
127
|
+
else if (op === 'avg') num = values.reduce((a, b) => a + b, 0) / values.length;
|
|
128
|
+
else if (op === 'min') num = Math.min(...values);
|
|
129
|
+
else if (op === 'max') num = Math.max(...values);
|
|
130
|
+
return formatValue(num, op === 'count' ? 'integer' : format, {}, emptyValue);
|
|
131
|
+
}
|
|
132
|
+
return op;
|
|
133
|
+
}
|
|
134
|
+
|
|
86
135
|
/**
|
|
87
136
|
* A print-shaped table from data, so the numbers in a report come from a file
|
|
88
137
|
* instead of being retyped into JSX. Alignment and grouping follow the column's
|
|
@@ -95,21 +144,42 @@ export function DataTable({
|
|
|
95
144
|
id,
|
|
96
145
|
limit,
|
|
97
146
|
compact = false,
|
|
147
|
+
splittable = false,
|
|
148
|
+
summaryRow,
|
|
149
|
+
summaryLabel = 'Total',
|
|
98
150
|
emptyValue = '—',
|
|
99
151
|
style,
|
|
100
152
|
className,
|
|
101
153
|
[LOC_PROP]: loc,
|
|
102
154
|
}: DataTableProps) {
|
|
155
|
+
const slice = useTableSlice();
|
|
103
156
|
const resolved: DataColumn[] = (columns ?? Object.keys(rows[0] ?? {})).map(normalizeColumn);
|
|
104
157
|
|
|
105
|
-
const
|
|
106
|
-
const hidden = rows.length -
|
|
158
|
+
const limited = limit !== undefined ? rows.slice(0, limit) : rows;
|
|
159
|
+
const hidden = rows.length - limited.length;
|
|
160
|
+
|
|
161
|
+
const isContinued = splittable && slice !== null && slice.rowStart > 0;
|
|
162
|
+
const isLastSlice = !splittable || slice === null || slice.rowEnd >= limited.length;
|
|
163
|
+
const shown =
|
|
164
|
+
splittable && slice !== null ? limited.slice(slice.rowStart, slice.rowEnd) : limited;
|
|
165
|
+
|
|
166
|
+
const maxByCol = new Map<string, number>();
|
|
167
|
+
for (const col of resolved) {
|
|
168
|
+
if (!col.dataBar) continue;
|
|
169
|
+
let max = 0;
|
|
170
|
+
for (const row of limited) {
|
|
171
|
+
const v = row[col.key];
|
|
172
|
+
if (isNumber(v) && Math.abs(v) > max) max = Math.abs(v);
|
|
173
|
+
}
|
|
174
|
+
if (max > 0) maxByCol.set(col.key, max);
|
|
175
|
+
}
|
|
107
176
|
|
|
108
177
|
const cellPadding = compact ? '4px 8px' : '7px 8px';
|
|
109
178
|
|
|
110
179
|
const table = (
|
|
111
180
|
<table
|
|
112
181
|
{...(caption ? {} : sourceAttrs(loc))}
|
|
182
|
+
{...(splittable ? { 'data-od-splittable': '' } : {})}
|
|
113
183
|
className={className}
|
|
114
184
|
style={{
|
|
115
185
|
width: '100%',
|
|
@@ -158,6 +228,11 @@ export function DataTable({
|
|
|
158
228
|
<tr key={rowIndex}>
|
|
159
229
|
{resolved.map((column) => {
|
|
160
230
|
const align = column.align ?? inferAlign(rows, column.key);
|
|
231
|
+
const val = row[column.key];
|
|
232
|
+
const maxBar = maxByCol.get(column.key);
|
|
233
|
+
const barRatio =
|
|
234
|
+
maxBar && isNumber(val) ? Math.min(1, Math.max(0, Math.abs(val) / maxBar)) : 0;
|
|
235
|
+
|
|
161
236
|
return (
|
|
162
237
|
<td
|
|
163
238
|
key={column.key}
|
|
@@ -168,29 +243,78 @@ export function DataTable({
|
|
|
168
243
|
borderBottom: '1px solid var(--od-rule)',
|
|
169
244
|
fontVariantNumeric: align === 'right' ? 'tabular-nums' : undefined,
|
|
170
245
|
overflowWrap: 'anywhere',
|
|
246
|
+
...(barRatio > 0
|
|
247
|
+
? {
|
|
248
|
+
backgroundImage: `linear-gradient(to right, color-mix(in srgb, var(--od-accent, #2563eb) 14%, transparent) ${(barRatio * 100).toFixed(1)}%, transparent ${(barRatio * 100).toFixed(1)}%)`,
|
|
249
|
+
}
|
|
250
|
+
: {}),
|
|
171
251
|
}}
|
|
172
252
|
>
|
|
173
|
-
{formatValue(
|
|
253
|
+
{formatValue(val, column.format, row, emptyValue)}
|
|
174
254
|
</td>
|
|
175
255
|
);
|
|
176
256
|
})}
|
|
177
257
|
</tr>
|
|
178
258
|
))}
|
|
179
259
|
</tbody>
|
|
180
|
-
{hidden > 0 && (
|
|
260
|
+
{isLastSlice && (summaryRow || hidden > 0) && (
|
|
181
261
|
<tfoot>
|
|
182
|
-
|
|
183
|
-
<
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
262
|
+
{summaryRow && (
|
|
263
|
+
<tr>
|
|
264
|
+
{resolved.map((column, colIndex) => {
|
|
265
|
+
const align = column.align ?? inferAlign(rows, column.key);
|
|
266
|
+
const explicit =
|
|
267
|
+
typeof summaryRow === 'object' ? summaryRow[column.key] : column.summary;
|
|
268
|
+
let content: ReactNode = null;
|
|
269
|
+
if (explicit !== undefined) {
|
|
270
|
+
if (explicit === 'count') {
|
|
271
|
+
const nonNull = limited.filter(
|
|
272
|
+
(r) =>
|
|
273
|
+
r[column.key] !== null &&
|
|
274
|
+
r[column.key] !== undefined &&
|
|
275
|
+
r[column.key] !== '',
|
|
276
|
+
).length;
|
|
277
|
+
content = formatValue(nonNull, 'integer', {}, emptyValue);
|
|
278
|
+
} else {
|
|
279
|
+
const nums = limited.map((r) => r[column.key]).filter(isNumber);
|
|
280
|
+
content = computeSummary(explicit, nums, column.format, emptyValue);
|
|
281
|
+
}
|
|
282
|
+
} else if (colIndex === 0) {
|
|
283
|
+
content = summaryLabel;
|
|
284
|
+
}
|
|
285
|
+
return (
|
|
286
|
+
<td
|
|
287
|
+
key={column.key}
|
|
288
|
+
style={{
|
|
289
|
+
textAlign: align,
|
|
290
|
+
fontSize: compact ? 11 : 12,
|
|
291
|
+
fontWeight: 600,
|
|
292
|
+
padding: cellPadding,
|
|
293
|
+
borderTop: '1.5px solid var(--od-text)',
|
|
294
|
+
borderBottom: '1px solid var(--od-rule)',
|
|
295
|
+
fontVariantNumeric: align === 'right' ? 'tabular-nums' : undefined,
|
|
296
|
+
}}
|
|
297
|
+
>
|
|
298
|
+
{content}
|
|
299
|
+
</td>
|
|
300
|
+
);
|
|
301
|
+
})}
|
|
302
|
+
</tr>
|
|
303
|
+
)}
|
|
304
|
+
{hidden > 0 && (
|
|
305
|
+
<tr>
|
|
306
|
+
<td
|
|
307
|
+
colSpan={resolved.length}
|
|
308
|
+
style={{
|
|
309
|
+
fontSize: 'var(--od-size-caption)',
|
|
310
|
+
color: 'var(--od-muted)',
|
|
311
|
+
padding: '6px 8px 0',
|
|
312
|
+
}}
|
|
313
|
+
>
|
|
314
|
+
{hidden} more row{hidden === 1 ? '' : 's'} not shown
|
|
315
|
+
</td>
|
|
316
|
+
</tr>
|
|
317
|
+
)}
|
|
194
318
|
</tfoot>
|
|
195
319
|
)}
|
|
196
320
|
</table>
|
|
@@ -198,11 +322,15 @@ export function DataTable({
|
|
|
198
322
|
|
|
199
323
|
if (!caption) return table;
|
|
200
324
|
|
|
325
|
+
const effectiveCaption =
|
|
326
|
+
isContinued && typeof caption === 'string' ? `${caption} (cont.)` : caption;
|
|
327
|
+
|
|
201
328
|
return (
|
|
202
329
|
<Figure
|
|
203
330
|
kind="table"
|
|
204
|
-
caption={
|
|
205
|
-
{...(id !== undefined ? { id } : {})}
|
|
331
|
+
caption={effectiveCaption}
|
|
332
|
+
{...(id !== undefined && !isContinued ? { id } : {})}
|
|
333
|
+
{...(isContinued ? { numbered: false } : {})}
|
|
206
334
|
{...sourceAttrs(loc)}
|
|
207
335
|
>
|
|
208
336
|
{table}
|
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CSSProperties, createContext, type ReactNode, useContext } from 'react';
|
|
2
2
|
import type { DesignSystem } from '../lib/design';
|
|
3
|
-
import type { FlowSection } from '../lib/flow';
|
|
3
|
+
import type { BlockSlice, FlowSection } from '../lib/flow';
|
|
4
4
|
import type { ExtractedNote } from '../lib/footnotes';
|
|
5
5
|
import { Footnotes } from './footnote';
|
|
6
6
|
|
|
7
7
|
export const FLOW_BLOCK_ATTR = 'data-od-flow-block';
|
|
8
8
|
|
|
9
|
+
export type TableSliceRange = { rowStart: number; rowEnd: number };
|
|
10
|
+
|
|
11
|
+
const SLICE_CONTEXT_KEY = '__open_doc_table_slice_context__';
|
|
12
|
+
type GlobalWithSlice = typeof globalThis & {
|
|
13
|
+
[SLICE_CONTEXT_KEY]?: ReturnType<typeof createContext<TableSliceRange | null>>;
|
|
14
|
+
};
|
|
15
|
+
const g = globalThis as GlobalWithSlice;
|
|
16
|
+
if (!g[SLICE_CONTEXT_KEY]) {
|
|
17
|
+
g[SLICE_CONTEXT_KEY] = createContext<TableSliceRange | null>(null);
|
|
18
|
+
}
|
|
19
|
+
const TableSliceContext = g[SLICE_CONTEXT_KEY];
|
|
20
|
+
|
|
21
|
+
export function useTableSlice(): TableSliceRange | null {
|
|
22
|
+
return useContext(TableSliceContext);
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
/**
|
|
10
26
|
* The page shell a flow section renders into. The framework owns the margin and
|
|
11
27
|
* base typography here — that is the trade for not hand-splitting pages — while
|
|
@@ -33,20 +49,30 @@ export function flowShellStyle(design: DesignSystem | undefined, padding?: numbe
|
|
|
33
49
|
};
|
|
34
50
|
}
|
|
35
51
|
|
|
36
|
-
export function FlowBlock({
|
|
37
|
-
|
|
52
|
+
export function FlowBlock({
|
|
53
|
+
slice,
|
|
54
|
+
children,
|
|
55
|
+
}: {
|
|
56
|
+
slice?: TableSliceRange | null;
|
|
57
|
+
children?: ReactNode;
|
|
58
|
+
}) {
|
|
59
|
+
const inner = <div {...{ [FLOW_BLOCK_ATTR]: '' }}>{children}</div>;
|
|
60
|
+
if (!slice) return inner;
|
|
61
|
+
return <TableSliceContext.Provider value={slice}>{inner}</TableSliceContext.Provider>;
|
|
38
62
|
}
|
|
39
63
|
|
|
40
64
|
export function FlowPage({
|
|
41
65
|
section,
|
|
42
66
|
design,
|
|
43
67
|
blockIndices,
|
|
68
|
+
blockSlices,
|
|
44
69
|
blocks,
|
|
45
70
|
notes,
|
|
46
71
|
}: {
|
|
47
72
|
section: FlowSection;
|
|
48
73
|
design: DesignSystem | undefined;
|
|
49
74
|
blockIndices: number[];
|
|
75
|
+
blockSlices?: BlockSlice[];
|
|
50
76
|
/** Blocks with footnotes already lifted out; falls back to the authored ones. */
|
|
51
77
|
blocks?: ReactNode[];
|
|
52
78
|
notes?: ExtractedNote[];
|
|
@@ -54,13 +80,36 @@ export function FlowPage({
|
|
|
54
80
|
const Header = section.header;
|
|
55
81
|
const Footer = section.footer;
|
|
56
82
|
const source = blocks ?? section.blocks;
|
|
83
|
+
const items: BlockSlice[] = blockSlices ?? blockIndices.map((index) => ({ index }));
|
|
84
|
+
const cols = section.columns && section.columns > 1 ? section.columns : 1;
|
|
85
|
+
|
|
57
86
|
return (
|
|
58
87
|
<div style={flowShellStyle(design, section.padding)}>
|
|
59
88
|
{Header && <Header />}
|
|
60
|
-
<div
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
89
|
+
<div
|
|
90
|
+
style={{
|
|
91
|
+
flex: cols > 1 ? 'none' : 1,
|
|
92
|
+
minHeight: 0,
|
|
93
|
+
...(cols > 1
|
|
94
|
+
? {
|
|
95
|
+
columnCount: cols,
|
|
96
|
+
columnGap: section.columnGap ?? 24,
|
|
97
|
+
columnFill: 'balance',
|
|
98
|
+
}
|
|
99
|
+
: {}),
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
{items.map((item) => {
|
|
103
|
+
const slice =
|
|
104
|
+
item.rowStart !== undefined && item.rowEnd !== undefined
|
|
105
|
+
? { rowStart: item.rowStart, rowEnd: item.rowEnd }
|
|
106
|
+
: null;
|
|
107
|
+
return (
|
|
108
|
+
<FlowBlock key={`${item.index}-${item.rowStart ?? 0}`} slice={slice}>
|
|
109
|
+
{source[item.index]}
|
|
110
|
+
</FlowBlock>
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
64
113
|
</div>
|
|
65
114
|
{notes && notes.length > 0 && <Footnotes notes={notes} />}
|
|
66
115
|
{Footer && <Footer />}
|