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