@canvas-components/react-list-table 0.3.53 → 0.3.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/index.cjs +69 -957
- package/dist/index.d.cts +7 -61
- package/dist/index.d.ts +7 -61
- package/dist/index.js +71 -961
- package/dist/print-integration.cjs +30 -0
- package/dist/print-integration.d.cts +76 -0
- package/dist/print-integration.d.ts +76 -0
- package/dist/print-integration.js +26 -0
- package/dist/print-settings.cjs +2 -0
- package/dist/print-settings.d.cts +69 -0
- package/dist/print-settings.d.ts +69 -0
- package/dist/print-settings.js +1 -0
- package/package.json +31 -5
package/dist/index.cjs
CHANGED
|
@@ -3,20 +3,11 @@
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var reactDom = require('react-dom');
|
|
5
5
|
var reactComponents = require('@canvas-components/react-components');
|
|
6
|
-
var reactPrintDesign = require('@canvas-components/react-print-design');
|
|
7
6
|
var listTable = require('@canvas-components/list-table');
|
|
8
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
8
|
var chart = require('@canvas-components/chart');
|
|
10
9
|
var date = require('@canvas-components/utils/date');
|
|
11
10
|
var number = require('@canvas-components/utils/number');
|
|
12
|
-
var utils = require('@canvas-components/utils');
|
|
13
|
-
var printDesign = require('@canvas-components/print-design');
|
|
14
|
-
var print = require('@canvas-components/print');
|
|
15
|
-
var client = require('react-dom/client');
|
|
16
|
-
|
|
17
|
-
var __defProp = Object.defineProperty;
|
|
18
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
19
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
20
11
|
|
|
21
12
|
// #style-inject:#style-inject
|
|
22
13
|
function styleInject(css, { insertAt } = {}) {
|
|
@@ -1076,40 +1067,19 @@ function ReactTableContextMenuView(props) {
|
|
|
1076
1067
|
request.onPrint?.();
|
|
1077
1068
|
}
|
|
1078
1069
|
}
|
|
1079
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1070
|
+
) : props.hostMenu ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1080
1071
|
MenuSubmenu,
|
|
1081
1072
|
{
|
|
1082
|
-
label:
|
|
1083
|
-
items:
|
|
1084
|
-
...
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
props.onPrintTemplate?.(template.key);
|
|
1091
|
-
}
|
|
1092
|
-
})) : [
|
|
1093
|
-
{
|
|
1094
|
-
key: "print-direct",
|
|
1095
|
-
label: "\u76F4\u63A5\u6253\u5370",
|
|
1096
|
-
onClick: request.onGetPrintData ? () => {
|
|
1097
|
-
setMenuOpen(false);
|
|
1098
|
-
props.onDirectPrint?.();
|
|
1099
|
-
} : void 0
|
|
1100
|
-
}
|
|
1101
|
-
],
|
|
1102
|
-
{
|
|
1103
|
-
key: "print-configure",
|
|
1104
|
-
label: "\u6253\u5370\u8BBE\u8BA1",
|
|
1105
|
-
onClick: request.onGetPrintData ? () => {
|
|
1106
|
-
setMenuOpen(false);
|
|
1107
|
-
props.onPrint?.();
|
|
1108
|
-
} : void 0
|
|
1109
|
-
}
|
|
1110
|
-
]
|
|
1073
|
+
label: props.hostMenu.label,
|
|
1074
|
+
items: props.hostMenu.items.map((item) => ({
|
|
1075
|
+
...item,
|
|
1076
|
+
onClick: item.onClick ? () => {
|
|
1077
|
+
setMenuOpen(false);
|
|
1078
|
+
item.onClick?.();
|
|
1079
|
+
} : void 0
|
|
1080
|
+
}))
|
|
1111
1081
|
}
|
|
1112
|
-
),
|
|
1082
|
+
) : null,
|
|
1113
1083
|
request.customItems?.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1114
1084
|
CustomContextMenuItem,
|
|
1115
1085
|
{
|
|
@@ -4151,792 +4121,25 @@ function fitExportDialogColumns(columns, availableWidth) {
|
|
|
4151
4121
|
});
|
|
4152
4122
|
return fit(columns);
|
|
4153
4123
|
}
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
align: column.align ?? "left",
|
|
4163
|
-
overflow: column.overflow ?? "wrap",
|
|
4164
|
-
summaryType: choice?.summary.type ?? "none",
|
|
4165
|
-
showTypePrefix: choice?.summary.showTypePrefix ? "yes" : "no",
|
|
4166
|
-
precision: choice?.summary.precision,
|
|
4167
|
-
roundingMode: choice?.summary.roundingMode ?? "round",
|
|
4168
|
-
preserveTrailingZeros: choice?.summary.preserveTrailingZeros ? "yes" : "no",
|
|
4169
|
-
summaryTitle: choice?.summaryTitle
|
|
4170
|
-
};
|
|
4171
|
-
});
|
|
4172
|
-
}
|
|
4173
|
-
function restorePrintColumns(columns, settings) {
|
|
4174
|
-
const current = new Map(columns.map((column) => [column.key, column]));
|
|
4175
|
-
const restored = [];
|
|
4176
|
-
settings?.columns?.forEach((saved) => {
|
|
4177
|
-
const column = current.get(saved.key);
|
|
4178
|
-
if (!column) return;
|
|
4179
|
-
restored.push({ ...column, ...saved, title: column.title });
|
|
4180
|
-
current.delete(saved.key);
|
|
4181
|
-
});
|
|
4182
|
-
return [...restored, ...current.values()];
|
|
4183
|
-
}
|
|
4184
|
-
function resolvePrintSelectedKeys(sourceColumns, presetConfig, cached) {
|
|
4185
|
-
new Set(cached?.columns.map((column) => column.key));
|
|
4186
|
-
const presetKeys = presetConfig?.selectedKeys ? new Set(presetConfig.selectedKeys) : null;
|
|
4187
|
-
return sourceColumns.filter((column) => {
|
|
4188
|
-
if (presetKeys) return presetKeys.has(column.key);
|
|
4189
|
-
return true;
|
|
4190
|
-
}).map((column) => column.key);
|
|
4191
|
-
}
|
|
4192
|
-
function createTableDocument(source, preset) {
|
|
4193
|
-
const config = preset?.config;
|
|
4194
|
-
const page = printDesign.createPrintDesignPage("\u8868\u683C\u6253\u5370");
|
|
4195
|
-
const [paperWidth, paperHeight] = print.BROWSER_PRINT_PAPER_SIZES[config?.paperSize ?? "a4"];
|
|
4196
|
-
page.width = config?.orientation === "landscape" ? paperHeight : paperWidth;
|
|
4197
|
-
page.height = config?.orientation === "landscape" ? paperWidth : paperHeight;
|
|
4198
|
-
page.orientation = config?.orientation ?? "portrait";
|
|
4199
|
-
page.margins = config?.pageMargins ?? page.margins;
|
|
4200
|
-
const selectedKeys = resolvePrintSelectedKeys(source.columns, config);
|
|
4201
|
-
const columns = restorePrintColumns(
|
|
4202
|
-
createPrintColumns(source.columns, source.summaryColumns),
|
|
4203
|
-
config?.columns ? { columns: config.columns } : null
|
|
4204
|
-
).filter((column) => selectedKeys.includes(column.key));
|
|
4205
|
-
const left = page.margins?.left ?? 10;
|
|
4206
|
-
const right = page.margins?.right ?? 10;
|
|
4207
|
-
const bottom = page.margins?.bottom ?? 10;
|
|
4208
|
-
const contentWidth = page.width - left - right;
|
|
4209
|
-
const widthSum = columns.reduce((sum, column) => sum + column.width, 0);
|
|
4210
|
-
const rowHeight = config?.rowHeight ?? 8;
|
|
4211
|
-
const footerY = page.height - bottom - 6;
|
|
4212
|
-
const tableY = 28;
|
|
4213
|
-
const tableHeight = footerY - tableY - 8;
|
|
4214
|
-
const rowsPerPage = Math.max(1, Math.floor((tableHeight - 9) / rowHeight));
|
|
4215
|
-
const pageCount = Math.max(1, Math.ceil(source.rows.length / rowsPerPage));
|
|
4216
|
-
const printedAt = (/* @__PURE__ */ new Date()).toLocaleString("zh-CN");
|
|
4217
|
-
const pages = Array.from(
|
|
4218
|
-
{ length: pageCount },
|
|
4219
|
-
(_, index) => ({
|
|
4220
|
-
...page,
|
|
4221
|
-
id: index === 0 ? page.id : printDesign.createPrintDesignPage().id,
|
|
4222
|
-
name: `\u8868\u683C\u6253\u5370 ${index + 1}`,
|
|
4223
|
-
elements: [
|
|
4224
|
-
{
|
|
4225
|
-
id: `list-table-title-${index}`,
|
|
4226
|
-
type: "text",
|
|
4227
|
-
name: "\u6807\u9898",
|
|
4228
|
-
x: left,
|
|
4229
|
-
y: 12,
|
|
4230
|
-
width: contentWidth,
|
|
4231
|
-
height: 10,
|
|
4232
|
-
text: config?.title ?? "\u8868\u683C\u6253\u5370",
|
|
4233
|
-
fontSize: config?.titleFontSize ?? 18,
|
|
4234
|
-
fontWeight: "700",
|
|
4235
|
-
textAlign: "center"
|
|
4236
|
-
},
|
|
4237
|
-
{
|
|
4238
|
-
id: `list-table-data-${index}`,
|
|
4239
|
-
type: "table",
|
|
4240
|
-
name: "\u8868\u683C\u6570\u636E",
|
|
4241
|
-
x: left,
|
|
4242
|
-
y: tableY,
|
|
4243
|
-
width: contentWidth,
|
|
4244
|
-
height: tableHeight,
|
|
4245
|
-
manualHeight: true,
|
|
4246
|
-
dataMode: "binding",
|
|
4247
|
-
dataPath: `listTable.pages.${index}.rows`,
|
|
4248
|
-
dataSource: [],
|
|
4249
|
-
columns: columns.map((column) => ({
|
|
4250
|
-
key: column.key,
|
|
4251
|
-
title: column.title,
|
|
4252
|
-
dataIndex: column.key,
|
|
4253
|
-
width: widthSum > 0 ? Math.max(24, column.width / widthSum * 720) : 120,
|
|
4254
|
-
align: column.align
|
|
4255
|
-
})),
|
|
4256
|
-
rowHeight,
|
|
4257
|
-
headerRowHeight: 9,
|
|
4258
|
-
showHeader: true
|
|
4259
|
-
},
|
|
4260
|
-
{
|
|
4261
|
-
id: `list-table-print-time-${index}`,
|
|
4262
|
-
type: "text",
|
|
4263
|
-
name: "\u6253\u5370\u65F6\u95F4",
|
|
4264
|
-
x: left,
|
|
4265
|
-
y: footerY,
|
|
4266
|
-
width: contentWidth / 2,
|
|
4267
|
-
height: 6,
|
|
4268
|
-
text: `\u6253\u5370\u65F6\u95F4\uFF1A${printedAt}`,
|
|
4269
|
-
fontSize: 9,
|
|
4270
|
-
color: "#000000"
|
|
4271
|
-
},
|
|
4272
|
-
{
|
|
4273
|
-
id: `list-table-page-number-${index}`,
|
|
4274
|
-
type: "text",
|
|
4275
|
-
name: "\u5206\u9875\u4FE1\u606F",
|
|
4276
|
-
x: left + contentWidth / 2,
|
|
4277
|
-
y: footerY,
|
|
4278
|
-
width: contentWidth / 2,
|
|
4279
|
-
height: 6,
|
|
4280
|
-
text: `\u7B2C ${index + 1} \u9875 / \u5171 ${pageCount} \u9875`,
|
|
4281
|
-
textAlign: "right",
|
|
4282
|
-
fontSize: 9,
|
|
4283
|
-
color: "#000000"
|
|
4284
|
-
}
|
|
4285
|
-
]
|
|
4286
|
-
})
|
|
4287
|
-
);
|
|
4288
|
-
return printDesign.createPrintDesignDocument({
|
|
4289
|
-
name: preset?.name ?? "\u8868\u683C\u6253\u5370\u6A21\u677F",
|
|
4290
|
-
pages
|
|
4291
|
-
});
|
|
4292
|
-
}
|
|
4293
|
-
function mapPrintSourceRows(source) {
|
|
4294
|
-
return source.rows.map(
|
|
4295
|
-
(row) => Object.fromEntries(
|
|
4296
|
-
source.columns.map((column, index) => [column.key, row[index] ?? ""])
|
|
4297
|
-
)
|
|
4298
|
-
);
|
|
4299
|
-
}
|
|
4300
|
-
function mapPrintSourceRowsAsync(source, options) {
|
|
4301
|
-
return utils.mapInBatches(
|
|
4302
|
-
source.rows.length,
|
|
4303
|
-
(index) => Object.fromEntries(
|
|
4304
|
-
source.columns.map((column, columnIndex) => [
|
|
4305
|
-
column.key,
|
|
4306
|
-
source.rows[index][columnIndex] ?? ""
|
|
4307
|
-
])
|
|
4308
|
-
),
|
|
4309
|
-
options
|
|
4310
|
-
);
|
|
4311
|
-
}
|
|
4312
|
-
function getRowsPerPage(document2, rowCount) {
|
|
4313
|
-
const firstTable = document2.pages[0]?.elements.find(
|
|
4314
|
-
(item) => item.type === "table"
|
|
4315
|
-
);
|
|
4316
|
-
return firstTable?.type === "table" ? Math.max(
|
|
4317
|
-
1,
|
|
4318
|
-
Math.floor(
|
|
4319
|
-
(firstTable.height - (firstTable.showHeader === false ? 0 : firstTable.headerRowHeight ?? 9)) / (firstTable.rowHeight ?? 8)
|
|
4320
|
-
)
|
|
4321
|
-
) : Math.max(1, Math.ceil(rowCount / Math.max(1, document2.pages.length)));
|
|
4322
|
-
}
|
|
4323
|
-
function getPrintDesignSampleSize() {
|
|
4324
|
-
return getRowsPerPage(createTableDocument({ columns: [], rows: [] }), 0);
|
|
4325
|
-
}
|
|
4326
|
-
function createTableData(source, document2, rows = mapPrintSourceRows(source)) {
|
|
4327
|
-
const rowsPerPage = getRowsPerPage(document2, rows.length);
|
|
4328
|
-
return {
|
|
4329
|
-
listTable: {
|
|
4330
|
-
rows,
|
|
4331
|
-
columns: source.columns.map((column) => ({ key: column.key })),
|
|
4332
|
-
pages: document2.pages.map((_, index) => ({
|
|
4333
|
-
rows: rows.slice(index * rowsPerPage, (index + 1) * rowsPerPage)
|
|
4334
|
-
}))
|
|
4335
|
-
}
|
|
4336
|
-
};
|
|
4337
|
-
}
|
|
4338
|
-
async function createTableDataAsync(source, document2, rows, options) {
|
|
4339
|
-
const rowsPerPage = getRowsPerPage(document2, rows.length);
|
|
4340
|
-
const pages = await utils.mapInBatches(
|
|
4341
|
-
document2.pages.length,
|
|
4342
|
-
(index) => ({
|
|
4343
|
-
rows: rows.slice(index * rowsPerPage, (index + 1) * rowsPerPage)
|
|
4344
|
-
}),
|
|
4345
|
-
options
|
|
4346
|
-
);
|
|
4347
|
-
return {
|
|
4348
|
-
listTable: {
|
|
4349
|
-
rows,
|
|
4350
|
-
columns: source.columns.map((column) => ({ key: column.key })),
|
|
4351
|
-
pages
|
|
4352
|
-
}
|
|
4353
|
-
};
|
|
4354
|
-
}
|
|
4355
|
-
async function createTablePreviewSource(source, template, options, preparedRows) {
|
|
4356
|
-
const rows = preparedRows ?? await mapPrintSourceRowsAsync(source, options);
|
|
4357
|
-
const pageCount = Math.max(
|
|
4358
|
-
template.pages.length,
|
|
4359
|
-
Math.ceil(rows.length / getRowsPerPage(template, rows.length))
|
|
4360
|
-
);
|
|
4361
|
-
const pages = await utils.mapInBatches(
|
|
4362
|
-
pageCount,
|
|
4363
|
-
(index) => {
|
|
4364
|
-
const page = template.pages[index % template.pages.length];
|
|
4365
|
-
return {
|
|
4366
|
-
...page,
|
|
4367
|
-
id: `${page.id}:print:${index}`,
|
|
4368
|
-
name: `\u8868\u683C\u6253\u5370 ${index + 1}`,
|
|
4369
|
-
elements: page.elements.map((element) => {
|
|
4370
|
-
const id = `${element.id}:print:${index}`;
|
|
4371
|
-
if (element.type === "table" && (element.dataPath === "listTable.rows" || /^listTable\.pages\.\d+\.rows$/.test(element.dataPath ?? ""))) {
|
|
4372
|
-
return {
|
|
4373
|
-
...element,
|
|
4374
|
-
id,
|
|
4375
|
-
dataPath: `listTable.pages.${index}.rows`
|
|
4376
|
-
};
|
|
4377
|
-
}
|
|
4378
|
-
if (element.type === "text" && element.id.startsWith("list-table-page-number-")) {
|
|
4379
|
-
return {
|
|
4380
|
-
...element,
|
|
4381
|
-
id,
|
|
4382
|
-
text: `\u7B2C ${index + 1} \u9875 / \u5171 ${pageCount} \u9875`
|
|
4383
|
-
};
|
|
4384
|
-
}
|
|
4385
|
-
return { ...element, id };
|
|
4386
|
-
})
|
|
4387
|
-
};
|
|
4388
|
-
},
|
|
4389
|
-
options
|
|
4390
|
-
);
|
|
4391
|
-
const document2 = { ...template, pages };
|
|
4392
|
-
return {
|
|
4393
|
-
document: document2,
|
|
4394
|
-
data: await createTableDataAsync(source, document2, rows, options)
|
|
4395
|
-
};
|
|
4396
|
-
}
|
|
4397
|
-
function getPrintSourceFormat(source) {
|
|
4398
|
-
return JSON.stringify(
|
|
4399
|
-
source.columns.map((column) => String(column.key)).sort()
|
|
4400
|
-
);
|
|
4401
|
-
}
|
|
4402
|
-
function ReactListTablePrintDesignDialog(props) {
|
|
4403
|
-
const [fullscreen, setFullscreen] = react.useState(true);
|
|
4404
|
-
const [source, setSource] = react.useState(null);
|
|
4405
|
-
const [error, setError] = react.useState("");
|
|
4406
|
-
const [attempt, setAttempt] = react.useState(0);
|
|
4407
|
-
const [emptyDocument] = react.useState(
|
|
4408
|
-
() => printDesign.createPrintDesignDocument({ name: "\u8868\u683C\u6253\u5370\u6A21\u677F" })
|
|
4409
|
-
);
|
|
4410
|
-
react.useEffect(() => {
|
|
4411
|
-
const controller = new AbortController();
|
|
4412
|
-
setSource(null);
|
|
4413
|
-
setError("");
|
|
4414
|
-
const timer = setTimeout(() => {
|
|
4415
|
-
void Promise.resolve().then(
|
|
4416
|
-
() => props.loadSource({
|
|
4417
|
-
rowLimit: getPrintDesignSampleSize(),
|
|
4418
|
-
includeSummary: false,
|
|
4419
|
-
signal: controller.signal
|
|
4420
|
-
})
|
|
4421
|
-
).then((value) => {
|
|
4422
|
-
if (!controller.signal.aborted) setSource(value);
|
|
4423
|
-
}).catch((cause) => {
|
|
4424
|
-
if (!controller.signal.aborted)
|
|
4425
|
-
setError(
|
|
4426
|
-
cause instanceof Error ? cause.message : "\u8BFB\u53D6\u6253\u5370\u6570\u636E\u5931\u8D25"
|
|
4427
|
-
);
|
|
4428
|
-
});
|
|
4429
|
-
}, 0);
|
|
4430
|
-
return () => {
|
|
4431
|
-
clearTimeout(timer);
|
|
4432
|
-
controller.abort();
|
|
4433
|
-
};
|
|
4434
|
-
}, [props.loadSource, attempt]);
|
|
4435
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4436
|
-
reactComponents.ReactModal,
|
|
4437
|
-
{
|
|
4438
|
-
open: true,
|
|
4439
|
-
fullscreen,
|
|
4440
|
-
closable: false,
|
|
4441
|
-
fullscreenable: false,
|
|
4442
|
-
footer: false,
|
|
4443
|
-
width: "min(96vw, 1440px)",
|
|
4444
|
-
style: { height: fullscreen ? "100%" : "min(88vh, 900px)" },
|
|
4445
|
-
bodyStyle: {
|
|
4446
|
-
padding: 0,
|
|
4447
|
-
overflow: "hidden",
|
|
4448
|
-
display: "flex",
|
|
4449
|
-
position: "relative"
|
|
4450
|
-
},
|
|
4451
|
-
onCancel: props.onClose,
|
|
4452
|
-
children: source ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4453
|
-
LoadedPrintDesigner,
|
|
4454
|
-
{
|
|
4455
|
-
...props,
|
|
4456
|
-
source,
|
|
4457
|
-
fullscreen,
|
|
4458
|
-
onFullscreenChange: setFullscreen
|
|
4459
|
-
}
|
|
4460
|
-
) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4461
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4462
|
-
reactPrintDesign.ReactPrintDesign,
|
|
4463
|
-
{
|
|
4464
|
-
document: emptyDocument,
|
|
4465
|
-
fullscreen,
|
|
4466
|
-
onClose: props.onClose,
|
|
4467
|
-
style: { flex: 1 }
|
|
4468
|
-
}
|
|
4469
|
-
),
|
|
4470
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4471
|
-
"div",
|
|
4472
|
-
{
|
|
4473
|
-
role: "status",
|
|
4474
|
-
style: {
|
|
4475
|
-
position: "absolute",
|
|
4476
|
-
inset: 0,
|
|
4477
|
-
background: "rgba(255,255,255,0.85)",
|
|
4478
|
-
display: "flex",
|
|
4479
|
-
alignItems: "center",
|
|
4480
|
-
justifyContent: "center",
|
|
4481
|
-
gap: 12
|
|
4482
|
-
},
|
|
4483
|
-
children: [
|
|
4484
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { children: error || "\u6B63\u5728\u8BFB\u53D6\u7B2C\u4E00\u9875\u6570\u636E\u2026" }),
|
|
4485
|
-
error ? /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { onClick: () => setAttempt((value) => value + 1), children: "\u91CD\u8BD5" }) : null,
|
|
4486
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { onClick: props.onClose, children: "\u5173\u95ED" })
|
|
4487
|
-
]
|
|
4488
|
-
}
|
|
4489
|
-
)
|
|
4490
|
-
] })
|
|
4491
|
-
}
|
|
4492
|
-
);
|
|
4493
|
-
}
|
|
4494
|
-
function LoadedPrintDesigner(props) {
|
|
4495
|
-
const document2 = react.useMemo(
|
|
4496
|
-
() => createTableDocument({ ...props.source, rows: [] }),
|
|
4497
|
-
[props.source]
|
|
4498
|
-
);
|
|
4499
|
-
const [boundDocument, setBoundDocument] = react.useState(document2);
|
|
4500
|
-
const rows = react.useMemo(() => mapPrintSourceRows(props.source), [props.source]);
|
|
4501
|
-
const defaultTemplates = react.useMemo(
|
|
4502
|
-
() => [
|
|
4503
|
-
document2,
|
|
4504
|
-
...props.printPresets?.map(
|
|
4505
|
-
(preset) => createTableDocument({ ...props.source, rows: [] }, preset)
|
|
4506
|
-
) ?? [],
|
|
4507
|
-
...props.printTemplates ?? []
|
|
4508
|
-
],
|
|
4509
|
-
[document2, props.printPresets, props.printTemplates, props.source]
|
|
4510
|
-
);
|
|
4511
|
-
const data = react.useMemo(
|
|
4512
|
-
() => createTableData(props.source, boundDocument, rows),
|
|
4513
|
-
[props.source, boundDocument, rows]
|
|
4514
|
-
);
|
|
4515
|
-
const loadPreviewData = react.useCallback(
|
|
4516
|
-
async (template, options) => {
|
|
4517
|
-
const source = await props.loadSource(options);
|
|
4518
|
-
options.signal?.throwIfAborted();
|
|
4519
|
-
return createTablePreviewSource(source, template, options);
|
|
4520
|
-
},
|
|
4521
|
-
[props.loadSource]
|
|
4522
|
-
);
|
|
4523
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4524
|
-
reactPrintDesign.ReactPrintDesign,
|
|
4525
|
-
{
|
|
4526
|
-
document: document2,
|
|
4527
|
-
defaultTemplates,
|
|
4528
|
-
data,
|
|
4529
|
-
dataFormatKey: getPrintSourceFormat(props.source),
|
|
4530
|
-
onChange: setBoundDocument,
|
|
4531
|
-
storeKey: props.storeKey,
|
|
4532
|
-
loadPreviewData,
|
|
4533
|
-
fullscreen: props.fullscreen,
|
|
4534
|
-
onFullscreenChange: props.onFullscreenChange,
|
|
4535
|
-
onClose: props.onClose,
|
|
4536
|
-
style: { flex: 1 }
|
|
4537
|
-
}
|
|
4538
|
-
);
|
|
4539
|
-
}
|
|
4540
|
-
var PRINT_PROGRESS_MIN_DURATION = 500;
|
|
4541
|
-
function createPrintProgress(container, onCancel) {
|
|
4542
|
-
const host = container.ownerDocument.createElement("div");
|
|
4543
|
-
host.dataset.listTablePrintProgress = "";
|
|
4544
|
-
container.append(host);
|
|
4545
|
-
const root = client.createRoot(host);
|
|
4546
|
-
const startedAt = performance.now();
|
|
4547
|
-
let disposed = false;
|
|
4548
|
-
let open = true;
|
|
4549
|
-
let message = "\u6B63\u5728\u8BFB\u53D6\u6253\u5370\u6570\u636E";
|
|
4550
|
-
let percent = 0;
|
|
4551
|
-
let failed = false;
|
|
4552
|
-
let errorTitle = "\u6253\u5370\u5931\u8D25";
|
|
4553
|
-
let closeTimer;
|
|
4554
|
-
let resolveClose;
|
|
4555
|
-
let configuring = false;
|
|
4556
|
-
let batchSize = 50;
|
|
4557
|
-
let action;
|
|
4558
|
-
const confirm = () => {
|
|
4559
|
-
const pending = action;
|
|
4560
|
-
action = void 0;
|
|
4561
|
-
configuring = false;
|
|
4562
|
-
render();
|
|
4563
|
-
pending?.resolve();
|
|
4564
|
-
};
|
|
4565
|
-
const dispose = () => {
|
|
4566
|
-
if (disposed) return;
|
|
4567
|
-
disposed = true;
|
|
4568
|
-
clearTimeout(closeTimer);
|
|
4569
|
-
root.unmount();
|
|
4570
|
-
host.remove();
|
|
4571
|
-
resolveClose?.();
|
|
4572
|
-
action?.resolve();
|
|
4573
|
-
action = void 0;
|
|
4574
|
-
};
|
|
4575
|
-
const render = () => {
|
|
4576
|
-
if (disposed) return;
|
|
4577
|
-
reactDom.flushSync(
|
|
4578
|
-
() => root.render(
|
|
4579
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4580
|
-
reactComponents.ReactModal,
|
|
4581
|
-
{
|
|
4582
|
-
open,
|
|
4583
|
-
title: configuring ? "\u76F4\u63A5\u6253\u5370\u8BBE\u7F6E" : failed ? errorTitle : "\u6B63\u5728\u51C6\u5907\u6253\u5370",
|
|
4584
|
-
width: 440,
|
|
4585
|
-
centered: true,
|
|
4586
|
-
maskClosable: false,
|
|
4587
|
-
fullscreenable: false,
|
|
4588
|
-
getContainer: container,
|
|
4589
|
-
onCancel,
|
|
4590
|
-
afterClose: () => queueMicrotask(dispose),
|
|
4591
|
-
footer: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4592
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { onClick: onCancel, children: failed ? "\u5173\u95ED" : "\u53D6\u6D88\u6253\u5370" }),
|
|
4593
|
-
action && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4594
|
-
reactComponents.ReactButton,
|
|
4595
|
-
{
|
|
4596
|
-
disabled: configuring && (!batchSize || !Number.isInteger(batchSize) || batchSize < 1),
|
|
4597
|
-
onClick: confirm,
|
|
4598
|
-
children: action.label
|
|
4599
|
-
}
|
|
4600
|
-
)
|
|
4601
|
-
] }),
|
|
4602
|
-
children: [
|
|
4603
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4604
|
-
"p",
|
|
4605
|
-
{
|
|
4606
|
-
role: "status",
|
|
4607
|
-
"aria-live": "polite",
|
|
4608
|
-
style: { whiteSpace: "pre-line" },
|
|
4609
|
-
children: message
|
|
4610
|
-
}
|
|
4611
|
-
),
|
|
4612
|
-
configuring ? /* @__PURE__ */ jsxRuntime.jsxs("label", { style: { display: "flex", alignItems: "center", gap: 12 }, children: [
|
|
4613
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { whiteSpace: "nowrap", flexShrink: 0 }, children: "\u6BCF\u6B21\u6253\u5370\u9875\u6570" }),
|
|
4614
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4615
|
-
reactComponents.ReactInputNumber,
|
|
4616
|
-
{
|
|
4617
|
-
"aria-label": "\u6BCF\u6B21\u6253\u5370\u9875\u6570",
|
|
4618
|
-
style: { flex: 1, minWidth: 0 },
|
|
4619
|
-
min: 1,
|
|
4620
|
-
precision: 0,
|
|
4621
|
-
value: batchSize,
|
|
4622
|
-
onChange: (value) => {
|
|
4623
|
-
batchSize = value;
|
|
4624
|
-
render();
|
|
4625
|
-
}
|
|
4626
|
-
}
|
|
4627
|
-
)
|
|
4628
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
4629
|
-
reactComponents.ReactProgress,
|
|
4630
|
-
{
|
|
4631
|
-
percent,
|
|
4632
|
-
label: "\u6253\u5370\u51C6\u5907\u8FDB\u5EA6",
|
|
4633
|
-
status: failed ? "exception" : "normal"
|
|
4634
|
-
}
|
|
4635
|
-
)
|
|
4636
|
-
]
|
|
4637
|
-
}
|
|
4638
|
-
)
|
|
4639
|
-
)
|
|
4640
|
-
);
|
|
4641
|
-
};
|
|
4642
|
-
render();
|
|
4643
|
-
return {
|
|
4644
|
-
host,
|
|
4645
|
-
async configure(defaultPages) {
|
|
4646
|
-
configuring = true;
|
|
4647
|
-
batchSize = Number.isFinite(defaultPages) ? Math.max(1, Math.floor(defaultPages)) : 50;
|
|
4648
|
-
message = "\u6309\u6279\u6B21\u751F\u6210\u6253\u5370\u9875\u9762\uFF0C\u907F\u514D\u4E00\u6B21\u52A0\u8F7D\u8FC7\u591A\u5185\u5BB9\u3002";
|
|
4649
|
-
await new Promise((resolve) => {
|
|
4650
|
-
action = { label: "\u5F00\u59CB\u6253\u5370", resolve };
|
|
4651
|
-
render();
|
|
4652
|
-
});
|
|
4653
|
-
return batchSize ?? 50;
|
|
4654
|
-
},
|
|
4655
|
-
async continueBatch(firstPage, lastPage) {
|
|
4656
|
-
message = `\u7B2C ${firstPage}\u2013${lastPage} \u9875\u7684\u6253\u5370\u7A97\u53E3\u5DF2\u5173\u95ED\uFF0C\u662F\u5426\u7EE7\u7EED\u4E0B\u4E00\u6279\uFF1F`;
|
|
4657
|
-
await new Promise((resolve) => {
|
|
4658
|
-
action = { label: "\u7EE7\u7EED\u4E0B\u4E00\u6279", resolve };
|
|
4659
|
-
render();
|
|
4660
|
-
});
|
|
4661
|
-
},
|
|
4662
|
-
update(text, value) {
|
|
4663
|
-
if (percent === value && message === text) return;
|
|
4664
|
-
message = text;
|
|
4665
|
-
percent = value;
|
|
4666
|
-
render();
|
|
4667
|
-
},
|
|
4668
|
-
error(text, title) {
|
|
4669
|
-
message = text;
|
|
4670
|
-
errorTitle = title ?? "\u6253\u5370\u5931\u8D25";
|
|
4671
|
-
failed = true;
|
|
4672
|
-
render();
|
|
4673
|
-
},
|
|
4674
|
-
close(immediate = false) {
|
|
4675
|
-
if (disposed) return Promise.resolve();
|
|
4676
|
-
if (immediate) {
|
|
4677
|
-
dispose();
|
|
4678
|
-
return Promise.resolve();
|
|
4679
|
-
}
|
|
4680
|
-
return new Promise((resolve) => {
|
|
4681
|
-
resolveClose = resolve;
|
|
4682
|
-
closeTimer = setTimeout(
|
|
4683
|
-
() => {
|
|
4684
|
-
open = false;
|
|
4685
|
-
render();
|
|
4686
|
-
},
|
|
4687
|
-
Math.max(
|
|
4688
|
-
0,
|
|
4689
|
-
PRINT_PROGRESS_MIN_DURATION - (performance.now() - startedAt)
|
|
4690
|
-
)
|
|
4691
|
-
);
|
|
4692
|
-
});
|
|
4693
|
-
}
|
|
4694
|
-
};
|
|
4695
|
-
}
|
|
4696
|
-
var PRINT_ROWS_WORKER_SOURCE = `
|
|
4697
|
-
self.onmessage = function(event) {
|
|
4698
|
-
try {
|
|
4699
|
-
const { keys, rows } = event.data;
|
|
4700
|
-
self.postMessage({ rows: rows.map(row => Object.fromEntries(keys.map((key, index) => [key, row[index] ?? ""]))) });
|
|
4701
|
-
} catch (error) {
|
|
4702
|
-
self.postMessage({ error: String(error) });
|
|
4703
|
-
}
|
|
4704
|
-
};`;
|
|
4705
|
-
async function preparePrintRows(source, options = {}) {
|
|
4706
|
-
const keys = source.columns.map((column) => column.key);
|
|
4707
|
-
let worker;
|
|
4708
|
-
let url;
|
|
4709
|
-
try {
|
|
4710
|
-
options.signal?.throwIfAborted();
|
|
4711
|
-
url = URL.createObjectURL(
|
|
4712
|
-
new Blob([PRINT_ROWS_WORKER_SOURCE], { type: "text/javascript" })
|
|
4713
|
-
);
|
|
4714
|
-
worker = new Worker(url);
|
|
4715
|
-
const result = new Array(source.rows.length);
|
|
4716
|
-
for (let offset = 0; offset < source.rows.length; offset += 2e3) {
|
|
4717
|
-
options.signal?.throwIfAborted();
|
|
4718
|
-
const rows = await new Promise(
|
|
4719
|
-
(resolve, reject) => {
|
|
4720
|
-
const cleanup = () => {
|
|
4721
|
-
clearTimeout(timeout);
|
|
4722
|
-
options.signal?.removeEventListener("abort", abort);
|
|
4723
|
-
};
|
|
4724
|
-
const fail = (error) => {
|
|
4725
|
-
cleanup();
|
|
4726
|
-
reject(error);
|
|
4727
|
-
};
|
|
4728
|
-
const abort = () => fail(options.signal?.reason);
|
|
4729
|
-
const timeout = setTimeout(
|
|
4730
|
-
() => fail(new Error("\u6253\u5370 Worker \u54CD\u5E94\u8D85\u65F6")),
|
|
4731
|
-
15e3
|
|
4732
|
-
);
|
|
4733
|
-
options.signal?.addEventListener("abort", abort, { once: true });
|
|
4734
|
-
worker.onerror = () => fail(new Error("\u6253\u5370 Worker \u6267\u884C\u5931\u8D25"));
|
|
4735
|
-
worker.onmessageerror = () => fail(new Error("\u6253\u5370 Worker \u6570\u636E\u4F20\u8F93\u5931\u8D25"));
|
|
4736
|
-
worker.onmessage = (event) => {
|
|
4737
|
-
cleanup();
|
|
4738
|
-
if (event.data.error) reject(new Error(event.data.error));
|
|
4739
|
-
else resolve(event.data.rows);
|
|
4740
|
-
};
|
|
4741
|
-
try {
|
|
4742
|
-
worker.postMessage({
|
|
4743
|
-
keys,
|
|
4744
|
-
rows: source.rows.slice(offset, offset + 2e3)
|
|
4745
|
-
});
|
|
4746
|
-
} catch (error) {
|
|
4747
|
-
fail(error);
|
|
4748
|
-
}
|
|
4749
|
-
}
|
|
4750
|
-
);
|
|
4751
|
-
for (let index = 0; index < rows.length; index++)
|
|
4752
|
-
result[offset + index] = rows[index];
|
|
4753
|
-
options.onProgress?.(
|
|
4754
|
-
Math.min(offset + rows.length, source.rows.length),
|
|
4755
|
-
source.rows.length
|
|
4756
|
-
);
|
|
4757
|
-
}
|
|
4758
|
-
return result;
|
|
4759
|
-
} catch {
|
|
4760
|
-
worker?.terminate();
|
|
4761
|
-
worker = void 0;
|
|
4762
|
-
options.signal?.throwIfAborted();
|
|
4763
|
-
return await utils.mapInBatches(
|
|
4764
|
-
source.rows.length,
|
|
4765
|
-
(index) => Object.fromEntries(
|
|
4766
|
-
keys.map((key, column) => [key, source.rows[index][column] ?? ""])
|
|
4767
|
-
),
|
|
4768
|
-
options
|
|
4769
|
-
);
|
|
4770
|
-
} finally {
|
|
4771
|
-
worker?.terminate();
|
|
4772
|
-
if (url) URL.revokeObjectURL(url);
|
|
4124
|
+
function defineReactListTablePrintIntegration(integration) {
|
|
4125
|
+
if (!integration.Host || typeof integration.createMenu !== "function" || typeof integration.readTemplates !== "function" || typeof integration.createTemplateChoices !== "function")
|
|
4126
|
+
throw new Error("\u8868\u683C\u6253\u5370\u96C6\u6210\u7F3A\u5C11\u5BBF\u4E3B\u83DC\u5355\u3001\u6A21\u677F\u6216\u754C\u9762\u80FD\u529B\u3002");
|
|
4127
|
+
if (!integration.componentRegistry.get("table"))
|
|
4128
|
+
throw new Error("\u8868\u683C\u6253\u5370\u96C6\u6210\u7F3A\u5C11 table \u539F\u751F\u7EC4\u4EF6\u3002");
|
|
4129
|
+
for (const factory of integration.editor.componentFactories.list()) {
|
|
4130
|
+
if (!integration.componentRegistry.get(factory.type))
|
|
4131
|
+
throw new Error(`\u6253\u5370\u8BBE\u8BA1\u7EC4\u4EF6\u7F3A\u5C11\u539F\u751F\u7ED8\u5236\u80FD\u529B\uFF1A${factory.type}`);
|
|
4773
4132
|
}
|
|
4133
|
+
return Object.freeze(integration);
|
|
4774
4134
|
}
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
async function runDirectPrint(container, loadSource, resolveTemplate = (source) => createTableDocument({ ...source, rows: [] }), validate, defaultPagesPerBatch = 50) {
|
|
4784
|
-
const controller = new AbortController();
|
|
4785
|
-
const { signal } = controller;
|
|
4786
|
-
const ownerDocument = container.ownerDocument;
|
|
4787
|
-
const previousFocus = ownerDocument.activeElement;
|
|
4788
|
-
let frame;
|
|
4789
|
-
const progress = createPrintProgress(container, () => {
|
|
4790
|
-
controller.abort();
|
|
4791
|
-
void cleanup(true);
|
|
4792
|
-
});
|
|
4793
|
-
const cleanup = async (immediate = false) => {
|
|
4794
|
-
frame?.remove();
|
|
4795
|
-
await progress.close(immediate);
|
|
4796
|
-
if (previousFocus?.isConnected)
|
|
4797
|
-
previousFocus.focus({ preventScroll: true });
|
|
4798
|
-
};
|
|
4799
|
-
const timer = setInterval(() => {
|
|
4800
|
-
if (!progress.host.isConnected) controller.abort();
|
|
4801
|
-
}, 250);
|
|
4802
|
-
let maximum = 0;
|
|
4803
|
-
const report = (text, value) => {
|
|
4804
|
-
signal.throwIfAborted();
|
|
4805
|
-
maximum = Math.max(maximum, Math.floor(value));
|
|
4806
|
-
progress.update(text, maximum);
|
|
4807
|
-
};
|
|
4808
|
-
try {
|
|
4809
|
-
const pagesPerBatch = await progress.configure(defaultPagesPerBatch);
|
|
4810
|
-
signal.throwIfAborted();
|
|
4811
|
-
report("\u6B63\u5728\u8BFB\u53D6\u6253\u5370\u6570\u636E", 0);
|
|
4812
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
4813
|
-
const source = await loadSource({
|
|
4814
|
-
signal,
|
|
4815
|
-
onProgress: (done, total) => report(
|
|
4816
|
-
`\u6B63\u5728\u8BFB\u53D6\u6253\u5370\u6570\u636E ${done}/${total}`,
|
|
4817
|
-
total ? done / total * 30 : 30
|
|
4818
|
-
)
|
|
4819
|
-
});
|
|
4820
|
-
report("\u6B63\u5728\u8F6C\u6362\u6253\u5370\u6570\u636E", 30);
|
|
4821
|
-
const rows = await preparePrintRows(source, {
|
|
4822
|
-
signal,
|
|
4823
|
-
onProgress: (done, total) => report(
|
|
4824
|
-
`\u6B63\u5728\u8F6C\u6362\u6253\u5370\u6570\u636E ${done}/${total}`,
|
|
4825
|
-
30 + (total ? done / total : 1) * 25
|
|
4826
|
-
)
|
|
4827
|
-
});
|
|
4828
|
-
const template = resolveTemplate(source);
|
|
4829
|
-
validate?.(source, template, createTableData(source, template, rows));
|
|
4830
|
-
report("\u6B63\u5728\u751F\u6210\u5206\u9875", 55);
|
|
4831
|
-
const prepared = await createTablePreviewSource(
|
|
4832
|
-
source,
|
|
4833
|
-
template,
|
|
4834
|
-
{
|
|
4835
|
-
signal,
|
|
4836
|
-
onProgress: (done, total) => report(
|
|
4837
|
-
`\u6B63\u5728\u751F\u6210\u5206\u9875 ${done}/${total}`,
|
|
4838
|
-
55 + (total ? done / total : 1) * 15
|
|
4839
|
-
)
|
|
4840
|
-
},
|
|
4841
|
-
rows
|
|
4842
|
-
);
|
|
4843
|
-
report("\u6B63\u5728\u751F\u6210\u6253\u5370\u9875\u9762", 70);
|
|
4844
|
-
for await (const batch of printDesign.transformPrintDesignToHtmlBatches(
|
|
4845
|
-
prepared.document,
|
|
4846
|
-
{
|
|
4847
|
-
pagesPerBatch,
|
|
4848
|
-
data: prepared.data,
|
|
4849
|
-
signal,
|
|
4850
|
-
onProgress: (value) => report("\u6B63\u5728\u751F\u6210\u6253\u5370\u9875\u9762", 70 + value * 29)
|
|
4851
|
-
}
|
|
4852
|
-
)) {
|
|
4853
|
-
report(`\u6B63\u5728\u6253\u5370\u7B2C ${batch.firstPage}\u2013${batch.lastPage} \u9875`, maximum);
|
|
4854
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
4855
|
-
signal.throwIfAborted();
|
|
4856
|
-
frame = ownerDocument.createElement("iframe");
|
|
4857
|
-
frame.title = "\u8868\u683C\u6253\u5370";
|
|
4858
|
-
frame.setAttribute("aria-hidden", "true");
|
|
4859
|
-
frame.style.cssText = "position:fixed;left:-10000px;top:0;width:1px;height:1px;border:0";
|
|
4860
|
-
container.append(frame);
|
|
4861
|
-
const printWindow = frame.contentWindow;
|
|
4862
|
-
if (!printWindow) throw new Error("\u65E0\u6CD5\u521B\u5EFA\u6253\u5370\u9875\u9762");
|
|
4863
|
-
await new Promise((resolve, reject) => {
|
|
4864
|
-
const abort = () => {
|
|
4865
|
-
dispose();
|
|
4866
|
-
reject(signal.reason);
|
|
4867
|
-
};
|
|
4868
|
-
const dispose = () => {
|
|
4869
|
-
frame?.removeEventListener("load", loaded);
|
|
4870
|
-
signal.removeEventListener("abort", abort);
|
|
4871
|
-
};
|
|
4872
|
-
const loaded = () => {
|
|
4873
|
-
dispose();
|
|
4874
|
-
resolve();
|
|
4875
|
-
};
|
|
4876
|
-
frame.addEventListener("load", loaded, { once: true });
|
|
4877
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
4878
|
-
printWindow.document.open();
|
|
4879
|
-
printWindow.document.write(batch.html);
|
|
4880
|
-
printWindow.document.close();
|
|
4881
|
-
});
|
|
4882
|
-
await Promise.all([
|
|
4883
|
-
...Array.from(
|
|
4884
|
-
printWindow.document.images,
|
|
4885
|
-
(image) => image.decode?.().catch(() => void 0)
|
|
4886
|
-
),
|
|
4887
|
-
printWindow.document.fonts?.ready
|
|
4888
|
-
]);
|
|
4889
|
-
signal.throwIfAborted();
|
|
4890
|
-
await new Promise((resolve, reject) => {
|
|
4891
|
-
const dispose = () => {
|
|
4892
|
-
printWindow.removeEventListener("afterprint", finished);
|
|
4893
|
-
signal.removeEventListener("abort", aborted);
|
|
4894
|
-
};
|
|
4895
|
-
const finished = () => {
|
|
4896
|
-
dispose();
|
|
4897
|
-
resolve();
|
|
4898
|
-
};
|
|
4899
|
-
const aborted = () => {
|
|
4900
|
-
dispose();
|
|
4901
|
-
reject(signal.reason);
|
|
4902
|
-
};
|
|
4903
|
-
printWindow.addEventListener("afterprint", finished, { once: true });
|
|
4904
|
-
signal.addEventListener("abort", aborted, { once: true });
|
|
4905
|
-
try {
|
|
4906
|
-
printWindow.focus();
|
|
4907
|
-
printWindow.print();
|
|
4908
|
-
} catch (error) {
|
|
4909
|
-
dispose();
|
|
4910
|
-
reject(error);
|
|
4911
|
-
}
|
|
4912
|
-
});
|
|
4913
|
-
frame.remove();
|
|
4914
|
-
frame = void 0;
|
|
4915
|
-
if (batch.hasMore) {
|
|
4916
|
-
await progress.continueBatch(batch.firstPage, batch.lastPage);
|
|
4917
|
-
signal.throwIfAborted();
|
|
4918
|
-
report("\u6B63\u5728\u751F\u6210\u4E0B\u4E00\u6279\u6253\u5370\u9875\u9762", maximum);
|
|
4919
|
-
}
|
|
4920
|
-
}
|
|
4921
|
-
report("\u6253\u5370\u7A97\u53E3\u5DF2\u5173\u95ED", 100);
|
|
4922
|
-
await cleanup();
|
|
4923
|
-
} catch (error) {
|
|
4924
|
-
frame?.remove();
|
|
4925
|
-
if (!signal.aborted) {
|
|
4926
|
-
if (error instanceof InvalidPrintTemplateError)
|
|
4927
|
-
progress.error(
|
|
4928
|
-
`${error.locations.join("\n")}
|
|
4929
|
-
\u4FEE\u6539\u6A21\u677F\u540E\u53EF\u7EE7\u7EED\u4F7F\u7528\u3002`,
|
|
4930
|
-
"\u6253\u5370\u6A21\u677F\u5DF2\u5931\u6548"
|
|
4931
|
-
);
|
|
4932
|
-
else
|
|
4933
|
-
progress.error(
|
|
4934
|
-
`\u6253\u5370\u5931\u8D25\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
4935
|
-
);
|
|
4936
|
-
} else await cleanup(true);
|
|
4937
|
-
} finally {
|
|
4938
|
-
clearInterval(timer);
|
|
4939
|
-
}
|
|
4135
|
+
var PrintIntegrationContext = react.createContext(null);
|
|
4136
|
+
function ReactListTablePrintProvider(props) {
|
|
4137
|
+
if (props.integration)
|
|
4138
|
+
defineReactListTablePrintIntegration(props.integration);
|
|
4139
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PrintIntegrationContext.Provider, { value: props.integration, children: props.children });
|
|
4140
|
+
}
|
|
4141
|
+
function useReactListTablePrintIntegration() {
|
|
4142
|
+
return react.useContext(PrintIntegrationContext);
|
|
4940
4143
|
}
|
|
4941
4144
|
|
|
4942
4145
|
// src/features/editor/utils.ts
|
|
@@ -6783,6 +5986,7 @@ function retainEqualQueryOption(previous, next) {
|
|
|
6783
5986
|
}
|
|
6784
5987
|
function ReactListTableInner(props, ref) {
|
|
6785
5988
|
props = useStableTableProps(props);
|
|
5989
|
+
const printIntegration = useReactListTablePrintIntegration();
|
|
6786
5990
|
const {
|
|
6787
5991
|
className,
|
|
6788
5992
|
style,
|
|
@@ -7048,51 +6252,37 @@ function ReactListTableInner(props, ref) {
|
|
|
7048
6252
|
closeDangerConfirmRequest
|
|
7049
6253
|
} = useReactListTableState(options);
|
|
7050
6254
|
const hasPagination = paginationConfig != null;
|
|
7051
|
-
const [printRequest, setPrintRequest] = react.useState(null);
|
|
7052
|
-
const [savedPrintTemplates, setSavedPrintTemplates] = react.useState([]);
|
|
7053
|
-
const printStoreKey = storageKey ? `list:${storageKey}` : void 0;
|
|
7054
|
-
const printMenuOpen = Boolean(headerContextMenuRequest);
|
|
7055
|
-
react.useEffect(() => {
|
|
7056
|
-
if (!printMenuOpen || !printStoreKey) {
|
|
7057
|
-
setSavedPrintTemplates([]);
|
|
7058
|
-
return;
|
|
7059
|
-
}
|
|
7060
|
-
let disposed = false;
|
|
7061
|
-
void reactPrintDesign.readPrintDesignTemplates(printStoreKey).then((versions) => {
|
|
7062
|
-
if (!disposed) setSavedPrintTemplates(versions);
|
|
7063
|
-
}).catch(() => {
|
|
7064
|
-
if (!disposed) setSavedPrintTemplates([]);
|
|
7065
|
-
});
|
|
7066
|
-
return () => {
|
|
7067
|
-
disposed = true;
|
|
7068
|
-
};
|
|
7069
|
-
}, [printMenuOpen, printStoreKey]);
|
|
7070
|
-
const latestSavedTemplates = [
|
|
7071
|
-
...new Set(savedPrintTemplates.map((item) => item.templateId))
|
|
7072
|
-
].map((templateId) => {
|
|
7073
|
-
const versions = savedPrintTemplates.filter(
|
|
7074
|
-
(item) => item.templateId === templateId
|
|
7075
|
-
);
|
|
7076
|
-
return versions[versions.length - 1];
|
|
7077
|
-
});
|
|
7078
|
-
const printTemplateChoices = [
|
|
7079
|
-
{ key: "base", label: "\u8868\u683C\u6253\u5370\u6A21\u677F" },
|
|
7080
|
-
...props.printPresets?.map((item, index) => ({
|
|
7081
|
-
key: `preset:${index}`,
|
|
7082
|
-
label: item.name
|
|
7083
|
-
})) ?? [],
|
|
7084
|
-
...props.printTemplates?.map((item, index) => ({
|
|
7085
|
-
key: `document:${index}`,
|
|
7086
|
-
label: item.name
|
|
7087
|
-
})) ?? [],
|
|
7088
|
-
...latestSavedTemplates.map((item) => ({
|
|
7089
|
-
key: `saved:${item.id}`,
|
|
7090
|
-
label: `${item.document.name} (v${item.version})`
|
|
7091
|
-
}))
|
|
7092
|
-
];
|
|
7093
6255
|
const [cacheConfigOpen, setCacheConfigOpen] = react.useState(false);
|
|
7094
6256
|
const paginationLayout = resolveReactListTablePaginationLayout(resolvedRowHeight);
|
|
7095
6257
|
const portalContainer = resolveFullscreenPortalContainer(shellRef.current);
|
|
6258
|
+
const PrintHost = printIntegration?.Host;
|
|
6259
|
+
const contextMenuRequest = headerContextMenuRequest ? {
|
|
6260
|
+
...headerContextMenuRequest,
|
|
6261
|
+
scrollbar: effectiveScrollbar,
|
|
6262
|
+
onChangeScrollbar: (value) => {
|
|
6263
|
+
headerContextMenuRequest.onChangeScrollbar?.(value);
|
|
6264
|
+
setScrollbarOverride(value);
|
|
6265
|
+
if (reactComponents.getSharedScrollbarSettings().shared)
|
|
6266
|
+
reactComponents.setSharedScrollbarSettings({ shared: true, value });
|
|
6267
|
+
},
|
|
6268
|
+
onResetScrollbar: () => {
|
|
6269
|
+
headerContextMenuRequest.onResetScrollbar?.();
|
|
6270
|
+
setScrollbarOverride(null);
|
|
6271
|
+
if (reactComponents.getSharedScrollbarSettings().shared)
|
|
6272
|
+
reactComponents.setSharedScrollbarSettings({ shared: true, value: {} });
|
|
6273
|
+
}
|
|
6274
|
+
} : null;
|
|
6275
|
+
const renderContextMenu = (hostMenu) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
6276
|
+
ReactTableContextMenuView,
|
|
6277
|
+
{
|
|
6278
|
+
hostMenu,
|
|
6279
|
+
onViewCacheConfig: () => {
|
|
6280
|
+
headerContextMenuRequest?.onClose();
|
|
6281
|
+
setCacheConfigOpen(true);
|
|
6282
|
+
},
|
|
6283
|
+
request: contextMenuRequest
|
|
6284
|
+
}
|
|
6285
|
+
);
|
|
7096
6286
|
react.useImperativeHandle(
|
|
7097
6287
|
ref,
|
|
7098
6288
|
() => ({
|
|
@@ -7281,101 +6471,21 @@ function ReactListTableInner(props, ref) {
|
|
|
7281
6471
|
portalContainer
|
|
7282
6472
|
) : null,
|
|
7283
6473
|
reactDom.createPortal(
|
|
7284
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7285
|
-
|
|
7286
|
-
{
|
|
7287
|
-
printTemplates: printTemplateChoices,
|
|
7288
|
-
onPrintTemplate: (key) => {
|
|
7289
|
-
const request = headerContextMenuRequest;
|
|
7290
|
-
if (!request?.onGetPrintData) return;
|
|
7291
|
-
request.onClose();
|
|
7292
|
-
void runDirectPrint(
|
|
7293
|
-
portalContainer,
|
|
7294
|
-
request.onGetPrintData,
|
|
7295
|
-
(source) => {
|
|
7296
|
-
const document2 = key.startsWith("saved:") ? savedPrintTemplates.find((item) => item.id === key.slice(6))?.document : key.startsWith("preset:") ? createTableDocument(
|
|
7297
|
-
{ ...source, rows: [] },
|
|
7298
|
-
props.printPresets?.[Number(key.slice(7))]
|
|
7299
|
-
) : key.startsWith("document:") ? props.printTemplates?.[Number(key.slice(9))] : createTableDocument({ ...source, rows: [] });
|
|
7300
|
-
if (!document2) throw new Error("\u627E\u4E0D\u5230\u6253\u5370\u6A21\u677F");
|
|
7301
|
-
return document2;
|
|
7302
|
-
},
|
|
7303
|
-
(source, document2, data) => {
|
|
7304
|
-
const saved = key.startsWith("saved:") ? savedPrintTemplates.find((item) => item.id === key.slice(6)) : void 0;
|
|
7305
|
-
if (!reactPrintDesign.isPrintDesignDocumentCompatible(document2, data) || saved && reactPrintDesign.isPrintDesignTemplateInvalid(
|
|
7306
|
-
saved,
|
|
7307
|
-
getPrintSourceFormat(source),
|
|
7308
|
-
data
|
|
7309
|
-
)) {
|
|
7310
|
-
const locations = reactPrintDesign.getPrintDesignTemplateInvalidLocations(
|
|
7311
|
-
document2,
|
|
7312
|
-
data,
|
|
7313
|
-
saved?.dataFormat,
|
|
7314
|
-
getPrintSourceFormat(source)
|
|
7315
|
-
);
|
|
7316
|
-
throw new InvalidPrintTemplateError(
|
|
7317
|
-
locations.length ? locations : ["\u6A21\u677F\u4E0E\u5F53\u524D\u6570\u636E\u4E0D\u517C\u5BB9"]
|
|
7318
|
-
);
|
|
7319
|
-
}
|
|
7320
|
-
},
|
|
7321
|
-
props.directPrintPagesPerBatch
|
|
7322
|
-
);
|
|
7323
|
-
},
|
|
7324
|
-
onViewCacheConfig: () => {
|
|
7325
|
-
headerContextMenuRequest?.onClose();
|
|
7326
|
-
setCacheConfigOpen(true);
|
|
7327
|
-
},
|
|
7328
|
-
onPrint: () => {
|
|
7329
|
-
const getPrintData = headerContextMenuRequest?.onGetPrintData;
|
|
7330
|
-
if (!getPrintData) return;
|
|
7331
|
-
setPrintRequest({ loadSource: getPrintData });
|
|
7332
|
-
headerContextMenuRequest?.onClose();
|
|
7333
|
-
},
|
|
7334
|
-
onDirectPrint: () => {
|
|
7335
|
-
const request = headerContextMenuRequest;
|
|
7336
|
-
if (!request?.onGetPrintData) return;
|
|
7337
|
-
request.onClose();
|
|
7338
|
-
void runDirectPrint(
|
|
7339
|
-
portalContainer,
|
|
7340
|
-
request.onGetPrintData,
|
|
7341
|
-
void 0,
|
|
7342
|
-
void 0,
|
|
7343
|
-
props.directPrintPagesPerBatch
|
|
7344
|
-
);
|
|
7345
|
-
},
|
|
7346
|
-
request: headerContextMenuRequest ? {
|
|
7347
|
-
...headerContextMenuRequest,
|
|
7348
|
-
scrollbar: effectiveScrollbar,
|
|
7349
|
-
onChangeScrollbar: (value) => {
|
|
7350
|
-
headerContextMenuRequest.onChangeScrollbar?.(value);
|
|
7351
|
-
setScrollbarOverride(value);
|
|
7352
|
-
if (reactComponents.getSharedScrollbarSettings().shared)
|
|
7353
|
-
reactComponents.setSharedScrollbarSettings({ shared: true, value });
|
|
7354
|
-
},
|
|
7355
|
-
onResetScrollbar: () => {
|
|
7356
|
-
headerContextMenuRequest.onResetScrollbar?.();
|
|
7357
|
-
setScrollbarOverride(null);
|
|
7358
|
-
if (reactComponents.getSharedScrollbarSettings().shared)
|
|
7359
|
-
reactComponents.setSharedScrollbarSettings({ shared: true, value: {} });
|
|
7360
|
-
}
|
|
7361
|
-
} : null
|
|
7362
|
-
}
|
|
7363
|
-
),
|
|
7364
|
-
portalContainer
|
|
7365
|
-
),
|
|
7366
|
-
printRequest ? reactDom.createPortal(
|
|
7367
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7368
|
-
ReactListTablePrintDesignDialog,
|
|
6474
|
+
PrintHost && printIntegration ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
6475
|
+
PrintHost,
|
|
7369
6476
|
{
|
|
7370
|
-
|
|
6477
|
+
integration: printIntegration,
|
|
6478
|
+
request: headerContextMenuRequest,
|
|
6479
|
+
portalContainer,
|
|
7371
6480
|
storeKey: storageKey ? `list:${storageKey}` : void 0,
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
6481
|
+
presets: props.printPresets,
|
|
6482
|
+
templates: props.printTemplates,
|
|
6483
|
+
pagesPerBatch: props.directPrintPagesPerBatch,
|
|
6484
|
+
children: renderContextMenu
|
|
7375
6485
|
}
|
|
7376
|
-
),
|
|
6486
|
+
) : renderContextMenu(null),
|
|
7377
6487
|
portalContainer
|
|
7378
|
-
)
|
|
6488
|
+
),
|
|
7379
6489
|
cacheConfigOpen && storageKey ? reactDom.createPortal(
|
|
7380
6490
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7381
6491
|
ReactListTableCacheConfigDialog,
|
|
@@ -7457,3 +6567,5 @@ Object.defineProperty(exports, "getListTableStoredPageSize", {
|
|
|
7457
6567
|
exports.ReactListTable = ReactListTable;
|
|
7458
6568
|
exports.ReactListTableDebugProvider = ReactListTableDebugProvider;
|
|
7459
6569
|
exports.ReactListTableExportNameDialog = ReactListTableExportNameDialog;
|
|
6570
|
+
exports.ReactListTablePrintProvider = ReactListTablePrintProvider;
|
|
6571
|
+
exports.defineReactListTablePrintIntegration = defineReactListTablePrintIntegration;
|