@yudaocode/univer-pdfs-ui 1.6.215 → 1.6.216

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/lib/es/index.js CHANGED
@@ -466,6 +466,63 @@ import {
466
466
  // src/services/pdfs-ui-feature.service.ts
467
467
  import { createIdentifier, Disposable } from "@univerjs/core";
468
468
  import { BehaviorSubject } from "rxjs";
469
+ var ALL_PDF_IO_MODAL_TABS = [
470
+ "preview",
471
+ "import",
472
+ "export",
473
+ "json"
474
+ ];
475
+ function isValidPdfModalTab(val) {
476
+ return val === "preview" || val === "import" || val === "export" || val === "json";
477
+ }
478
+ function resolvePdfIoModalConfig(raw, base) {
479
+ let tabs;
480
+ let hasExplicitTabs;
481
+ if (Array.isArray(raw?.tabs)) {
482
+ const deduped = [];
483
+ for (const item of raw.tabs) {
484
+ if (isValidPdfModalTab(item) && !deduped.includes(item)) {
485
+ deduped.push(item);
486
+ }
487
+ }
488
+ if (deduped.length > 0) {
489
+ tabs = deduped;
490
+ hasExplicitTabs = true;
491
+ } else {
492
+ tabs = base?.tabs ? [...base.tabs] : [...ALL_PDF_IO_MODAL_TABS];
493
+ hasExplicitTabs = Boolean(base?.hasExplicitTabs);
494
+ }
495
+ } else {
496
+ tabs = base?.tabs ? [...base.tabs] : [...ALL_PDF_IO_MODAL_TABS];
497
+ hasExplicitTabs = Boolean(base?.hasExplicitTabs);
498
+ }
499
+ const candidateDefault = raw?.defaultTab ?? base?.defaultTab ?? "preview";
500
+ let defaultTab;
501
+ if (isValidPdfModalTab(candidateDefault) && tabs.includes(candidateDefault)) {
502
+ defaultTab = candidateDefault;
503
+ } else if ((candidateDefault === "import" || candidateDefault === "export") && tabs.includes("preview")) {
504
+ defaultTab = "preview";
505
+ } else {
506
+ defaultTab = tabs[0] ?? "preview";
507
+ }
508
+ return {
509
+ tabs,
510
+ defaultTab,
511
+ showPipelineBadge: raw?.showPipelineBadge ?? base?.showPipelineBadge ?? true,
512
+ hasExplicitTabs
513
+ };
514
+ }
515
+ function clampPdfModalTab(requested, config) {
516
+ if (isValidPdfModalTab(requested)) {
517
+ if (config.tabs.includes(requested)) {
518
+ return requested;
519
+ }
520
+ if ((requested === "import" || requested === "export") && config.tabs.includes("preview")) {
521
+ return "preview";
522
+ }
523
+ }
524
+ return config.defaultTab;
525
+ }
469
526
  function resolvePdfsUIFeatures(raw) {
470
527
  const rw = raw?.reportWidgets;
471
528
  const qrcode = typeof rw === "boolean" ? rw : Boolean(rw?.qrcode);
@@ -511,20 +568,24 @@ var IPdfsUIFeatureService = createIdentifier(
511
568
  "yudao.univer-pdfs-ui.feature.service"
512
569
  );
513
570
  var PdfsUIFeatureService = class extends Disposable {
514
- constructor(initial, editorEnabled = true) {
571
+ constructor(initial, editorEnabled = true, ioModal) {
515
572
  super();
516
- this._modalTab$ = new BehaviorSubject("preview");
517
- this.modalTab$ = this._modalTab$.asObservable();
573
+ this._baseIoModal = resolvePdfIoModalConfig(ioModal);
518
574
  this._features$ = new BehaviorSubject(resolvePdfsUIFeatures(initial));
575
+ this._modalTab$ = new BehaviorSubject(this._baseIoModal.defaultTab);
519
576
  this._editorEnabled$ = new BehaviorSubject(editorEnabled);
577
+ this._ioModal$ = new BehaviorSubject(this._baseIoModal);
520
578
  this.features$ = this._features$.asObservable();
579
+ this.modalTab$ = this._modalTab$.asObservable();
521
580
  this.editorEnabled$ = this._editorEnabled$.asObservable();
581
+ this.ioModal$ = this._ioModal$.asObservable();
522
582
  }
523
583
  dispose() {
524
584
  super.dispose();
525
585
  this._features$.complete();
526
586
  this._modalTab$.complete();
527
587
  this._editorEnabled$.complete();
588
+ this._ioModal$.complete();
528
589
  }
529
590
  getFeatures() {
530
591
  return this._features$.getValue();
@@ -542,7 +603,27 @@ var PdfsUIFeatureService = class extends Disposable {
542
603
  return this._modalTab$.getValue();
543
604
  }
544
605
  setModalTab(tab) {
545
- this._modalTab$.next(tab);
606
+ this._modalTab$.next(clampPdfModalTab(tab, this._ioModal$.getValue()));
607
+ }
608
+ getIoModalConfig() {
609
+ const cur = this._ioModal$.getValue();
610
+ return {
611
+ ...cur,
612
+ tabs: [...cur.tabs]
613
+ };
614
+ }
615
+ setIoModalConfig(config) {
616
+ this._baseIoModal = resolvePdfIoModalConfig(config);
617
+ this._ioModal$.next(this._baseIoModal);
618
+ this._modalTab$.next(clampPdfModalTab(this._modalTab$.getValue(), this._baseIoModal));
619
+ }
620
+ applyModalOpenConfig(override) {
621
+ const resolved = override ? resolvePdfIoModalConfig(override, this._baseIoModal) : {
622
+ ...this._baseIoModal,
623
+ tabs: [...this._baseIoModal.tabs]
624
+ };
625
+ this._ioModal$.next(resolved);
626
+ return resolved;
546
627
  }
547
628
  isEditorEnabled() {
548
629
  return this._editorEnabled$.getValue();
@@ -585,7 +666,9 @@ var OpenPdfPreviewOperation = {
585
666
  const selectionService = accessor.get(IPdfSelectionService);
586
667
  selectionService.commitActiveEditing();
587
668
  selectionService.setEditingElement(null);
588
- accessor.get(IPdfsUIFeatureService).setModalTab(params?.tab ?? "preview");
669
+ const featureService = accessor.get(IPdfsUIFeatureService);
670
+ const effectiveIoModal = featureService.applyModalOpenConfig(params?.ioModal);
671
+ featureService.setModalTab(clampPdfModalTab(params?.tab, effectiveIoModal));
589
672
  selectionService.setPreviewOpen(true);
590
673
  return true;
591
674
  }
@@ -593,7 +676,8 @@ var OpenPdfPreviewOperation = {
593
676
  async function readBrowserFileAsOverlayOutcome(file, options) {
594
677
  const validated = await importPdfSource(file, {
595
678
  fileName: file.name,
596
- password: options?.password
679
+ password: options?.password,
680
+ signal: options?.signal
597
681
  });
598
682
  return {
599
683
  mode: "overlay",
@@ -612,7 +696,8 @@ var UploadBasePdfOperation = {
612
696
  selectionService.commitActiveEditing();
613
697
  selectionService.setEditingElement(null);
614
698
  if (!params?.file) {
615
- featureService.setModalTab("import");
699
+ const effectiveIoModal = featureService.applyModalOpenConfig(params?.ioModal);
700
+ featureService.setModalTab(clampPdfModalTab("import", effectiveIoModal));
616
701
  selectionService.setPreviewOpen(true);
617
702
  return true;
618
703
  }
@@ -625,8 +710,12 @@ var UploadBasePdfOperation = {
625
710
  unitId: unit.getUnitId(),
626
711
  snapshot: unit.save(),
627
712
  target: params.target,
628
- password: params.password
713
+ password: params.password,
714
+ signal: params.signal
629
715
  }).then((outcome) => {
716
+ if (params.signal?.aborted) {
717
+ return false;
718
+ }
630
719
  if (outcome.mode === "snapshot") {
631
720
  return commandService.syncExecuteCommand(ReplacePdfSnapshotCommand.id, {
632
721
  unitId: unit.getUnitId(),
@@ -916,6 +1005,9 @@ var UpdatePdfUIFeaturesOperation = {
916
1005
  if (typeof params?.editorEnabled === "boolean") {
917
1006
  featureService.setEditorEnabled(params.editorEnabled);
918
1007
  }
1008
+ if (params?.ioModal !== void 0) {
1009
+ featureService.setIoModalConfig(params.ioModal);
1010
+ }
919
1011
  return true;
920
1012
  }
921
1013
  };
@@ -8309,6 +8401,69 @@ function resolveFallbackTarget(err, attemptedTarget) {
8309
8401
  }
8310
8402
  return attemptedTarget === "server" ? "browser" : "server";
8311
8403
  }
8404
+ async function executeGuardedStagedImport(params) {
8405
+ params.importAbortRef?.current?.abort();
8406
+ const reqSeq = ++params.importReqSeqRef.current;
8407
+ const controller = typeof AbortController === "function" ? new AbortController() : null;
8408
+ if (params.importAbortRef) {
8409
+ params.importAbortRef.current = controller;
8410
+ }
8411
+ params.onStart?.();
8412
+ try {
8413
+ const report = await params.ioService.importPdfWithReport(params.file, {
8414
+ unitId: params.unitId,
8415
+ target: params.target,
8416
+ ...controller ? { signal: controller.signal } : {}
8417
+ });
8418
+ if (reqSeq !== params.importReqSeqRef.current || controller?.signal.aborted) {
8419
+ return null;
8420
+ }
8421
+ params.onSuccess(report);
8422
+ return report;
8423
+ } catch (err) {
8424
+ if (reqSeq !== params.importReqSeqRef.current || controller?.signal.aborted || err?.name === "AbortError") {
8425
+ return null;
8426
+ }
8427
+ const fallbackTarget = resolveFallbackTarget(err, params.target);
8428
+ const msg = err?.message || String(err);
8429
+ params.onError({
8430
+ operation: "import",
8431
+ message: `PDF \u5BFC\u5165\u89E3\u6790\u5931\u8D25: ${msg}`,
8432
+ failedTarget: params.target,
8433
+ fallbackTarget
8434
+ });
8435
+ return null;
8436
+ } finally {
8437
+ if (reqSeq === params.importReqSeqRef.current) {
8438
+ if (params.importAbortRef && params.importAbortRef.current === controller) {
8439
+ params.importAbortRef.current = null;
8440
+ }
8441
+ params.onSettled?.();
8442
+ }
8443
+ }
8444
+ }
8445
+ function applyStagedPdfImportToUnit(commandService, unitId, staged) {
8446
+ const applied = staged.outcome.mode === "overlay" ? commandService.syncExecuteCommand(ImportPdfSourceCommand2.id, {
8447
+ unitId,
8448
+ sourceDocumentRef: staged.outcome.sourceDocumentRef,
8449
+ pageSizes: staged.outcome.pageSizes
8450
+ }) : commandService.syncExecuteCommand(ReplacePdfSnapshotCommand4.id, {
8451
+ unitId,
8452
+ snapshot: staged.snapshot
8453
+ });
8454
+ if (!applied) {
8455
+ return {
8456
+ applied: false,
8457
+ error: {
8458
+ operation: "import",
8459
+ message: "\u5E94\u7528\u5BFC\u5165\u5FEB\u7167\u5230\u8BBE\u8BA1\u5668\u5931\u8D25\uFF1A\u547D\u4EE4\u6267\u884C\u8FD4\u56DE false\uFF0C\u5F53\u524D\u6587\u6863\u672A\u88AB\u4FEE\u6539\u3002",
8460
+ failedTarget: staged.executedBy,
8461
+ fallbackTarget: staged.executedBy === "server" ? "browser" : "server"
8462
+ }
8463
+ };
8464
+ }
8465
+ return { applied: true };
8466
+ }
8312
8467
  function uint8ToDataUri(bytes) {
8313
8468
  let binary = "";
8314
8469
  const chunkSize = 32768;
@@ -8403,6 +8558,7 @@ var PdfUnifiedIoSection = ({
8403
8558
  serverAvailable,
8404
8559
  snapSizeKb,
8405
8560
  editorEnabled,
8561
+ showImportSection = true,
8406
8562
  importing,
8407
8563
  rendering,
8408
8564
  selectedFileName,
@@ -8474,7 +8630,7 @@ var PdfUnifiedIoSection = ({
8474
8630
  ]
8475
8631
  }
8476
8632
  ),
8477
- editorEnabled && /* @__PURE__ */ jsxs6("div", { className: "univer-pdf-io-import-box", children: [
8633
+ editorEnabled && showImportSection && /* @__PURE__ */ jsxs6("div", { className: "univer-pdf-io-import-box", children: [
8478
8634
  /* @__PURE__ */ jsxs6("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 6 }, children: [
8479
8635
  /* @__PURE__ */ jsx6("span", { style: { fontSize: 11.5, fontWeight: 600, color: "#1B1C1F" }, children: "PDF / \u6A21\u677F\u5206\u9636\u6BB5\u5BFC\u5165" }),
8480
8636
  selectedFileName && !pendingImport && /* @__PURE__ */ jsx6(
@@ -8604,6 +8760,7 @@ var PdfPreviewModal = () => {
8604
8760
  const featureService = useDependency5(IPdfsUIFeatureService);
8605
8761
  const features = useObservable5(featureService.features$, featureService.getFeatures());
8606
8762
  const editorEnabled = useObservable5(featureService.editorEnabled$, featureService.isEditorEnabled());
8763
+ const ioModal = useObservable5(featureService.ioModal$, featureService.getIoModalConfig());
8607
8764
  const ioAdapter = useObservable5(ioService.adapter$, ioService.getAdapter());
8608
8765
  const open = useObservable5(selectionService.previewOpen$, false);
8609
8766
  const modalTab = useObservable5(featureService.modalTab$, featureService.getModalTab());
@@ -8614,6 +8771,8 @@ var PdfPreviewModal = () => {
8614
8771
  [instanceService]
8615
8772
  );
8616
8773
  const fileInputRef = useRef3(null);
8774
+ const importReqSeqRef = useRef3(0);
8775
+ const importAbortRef = useRef3(null);
8617
8776
  const [sampleJsonText, setSampleJsonText] = useState5("{}");
8618
8777
  const [pdfBytesState, setPdfBytesState] = useState5(null);
8619
8778
  const [rendering, setRendering] = useState5(false);
@@ -8771,29 +8930,30 @@ var PdfPreviewModal = () => {
8771
8930
  const runStagedImport = async (file, overrideTarget) => {
8772
8931
  if (!unit) return;
8773
8932
  const effectiveTarget = overrideTarget ?? ioTarget;
8774
- setImporting(true);
8775
- setIoError(null);
8776
- setPendingImport(null);
8777
- setStatusTip("");
8778
- try {
8779
- const report = await ioService.importPdfWithReport(file, {
8780
- unitId: unit.getUnitId(),
8781
- target: effectiveTarget
8782
- });
8783
- setPendingImport(report);
8784
- } catch (err) {
8785
- setPendingImport(null);
8786
- const fallbackTarget = resolveFallbackTarget(err, effectiveTarget);
8787
- const msg = err?.message || String(err);
8788
- setIoError({
8789
- operation: "import",
8790
- message: `PDF \u5BFC\u5165\u89E3\u6790\u5931\u8D25: ${msg}`,
8791
- failedTarget: effectiveTarget,
8792
- fallbackTarget
8793
- });
8794
- } finally {
8795
- setImporting(false);
8796
- }
8933
+ await executeGuardedStagedImport({
8934
+ file,
8935
+ unitId: unit.getUnitId(),
8936
+ target: effectiveTarget,
8937
+ ioService,
8938
+ importReqSeqRef,
8939
+ importAbortRef,
8940
+ onStart: () => {
8941
+ setImporting(true);
8942
+ setIoError(null);
8943
+ setPendingImport(null);
8944
+ setStatusTip("");
8945
+ },
8946
+ onSuccess: (report) => {
8947
+ setPendingImport(report);
8948
+ },
8949
+ onError: (errState) => {
8950
+ setPendingImport(null);
8951
+ setIoError(errState);
8952
+ },
8953
+ onSettled: () => {
8954
+ setImporting(false);
8955
+ }
8956
+ });
8797
8957
  };
8798
8958
  const handleImportFileChange = (e) => {
8799
8959
  const file = e.target.files?.[0];
@@ -8805,17 +8965,11 @@ var PdfPreviewModal = () => {
8805
8965
  const handleConfirmStagedImport = () => {
8806
8966
  if (!unit || !pendingImport) return;
8807
8967
  const staged = pendingImport;
8808
- if (staged.outcome.mode === "overlay") {
8809
- commandService.syncExecuteCommand(ImportPdfSourceCommand2.id, {
8810
- unitId: unit.getUnitId(),
8811
- sourceDocumentRef: staged.outcome.sourceDocumentRef,
8812
- pageSizes: staged.outcome.pageSizes
8813
- });
8814
- } else {
8815
- commandService.syncExecuteCommand(ReplacePdfSnapshotCommand4.id, {
8816
- unitId: unit.getUnitId(),
8817
- snapshot: staged.snapshot
8818
- });
8968
+ const outcomeResult = applyStagedPdfImportToUnit(commandService, unit.getUnitId(), staged);
8969
+ if (!outcomeResult.applied) {
8970
+ setIoError(outcomeResult.error ?? null);
8971
+ setStatusTip("");
8972
+ return;
8819
8973
  }
8820
8974
  setPendingImport(null);
8821
8975
  setIoError(null);
@@ -8840,6 +8994,10 @@ var PdfPreviewModal = () => {
8840
8994
  );
8841
8995
  };
8842
8996
  const handleCancelStagedImport = () => {
8997
+ importReqSeqRef.current += 1;
8998
+ importAbortRef.current?.abort();
8999
+ importAbortRef.current = null;
9000
+ setImporting(false);
8843
9001
  setPendingImport(null);
8844
9002
  setIoError(null);
8845
9003
  setStatusTip("\u5DF2\u53D6\u6D88\u672C\u6B21\u5BFC\u5165\uFF0C\u5F53\u524D\u8BBE\u8BA1\u5668\u5185\u5BB9\u672A\u53D8\u66F4");
@@ -8848,7 +9006,7 @@ var PdfPreviewModal = () => {
8848
9006
  setIoTarget(nextTarget);
8849
9007
  setIoError(null);
8850
9008
  setPdfBytesState(null);
8851
- if (modalTab === "preview") {
9009
+ if (modalTab === "preview" || modalTab === "export") {
8852
9010
  void generatePreview(sampleJsonText, watermarkText, excludeBasePdf, nextTarget);
8853
9011
  } else if (modalTab === "import") {
8854
9012
  const caps = ioService.getIoCapabilities();
@@ -8871,8 +9029,19 @@ var PdfPreviewModal = () => {
8871
9029
  await generatePreview(sampleJsonText, watermarkText, excludeBasePdf, nextTarget);
8872
9030
  }
8873
9031
  };
9032
+ useEffect4(() => {
9033
+ return () => {
9034
+ importReqSeqRef.current += 1;
9035
+ importAbortRef.current?.abort();
9036
+ importAbortRef.current = null;
9037
+ };
9038
+ }, []);
8874
9039
  useEffect4(() => {
8875
9040
  if (!open) {
9041
+ importReqSeqRef.current += 1;
9042
+ importAbortRef.current?.abort();
9043
+ importAbortRef.current = null;
9044
+ setImporting(false);
8876
9045
  setPendingImport(null);
8877
9046
  setSelectedImportFile(null);
8878
9047
  setIoError(null);
@@ -8886,7 +9055,8 @@ var PdfPreviewModal = () => {
8886
9055
  const initialPdfA = Boolean(snap.pdfACompliant ?? snap.metadata?.pdfACompliant);
8887
9056
  const initialPdfUa = Boolean(snap.accessibilityTagged ?? snap.metadata?.accessibilityTagged);
8888
9057
  const caps = ioService.getIoCapabilities();
8889
- const initialTarget = resolveInitialModalIoTarget(caps, featureService.getModalTab());
9058
+ const activeTab = clampPdfModalTab(featureService.getModalTab(), ioModal);
9059
+ const initialTarget = resolveInitialModalIoTarget(caps, activeTab);
8890
9060
  setSampleJsonText(initialSampleText);
8891
9061
  setWatermarkText(initialWm);
8892
9062
  setExcludeBasePdf(initialStripBg);
@@ -8895,8 +9065,7 @@ var PdfPreviewModal = () => {
8895
9065
  setIoTarget(initialTarget);
8896
9066
  setIoError(null);
8897
9067
  setStatusTip("");
8898
- const activeTab = featureService.getModalTab();
8899
- if (activeTab === "preview") {
9068
+ if (activeTab === "preview" || activeTab === "export") {
8900
9069
  void generatePreview(initialSampleText, initialWm, initialStripBg, initialTarget, {
8901
9070
  pdfACompliant: initialPdfA,
8902
9071
  accessibilityTagged: initialPdfUa
@@ -9118,7 +9287,14 @@ var PdfPreviewModal = () => {
9118
9287
  setStatusTip("\u672A\u8BC6\u522B\u7684 JSON \u683C\u5F0F\uFF1A\u8BF7\u63D0\u4F9B Univer IPdfUnitData \u6216 pdfme Template JSON");
9119
9288
  return;
9120
9289
  }
9121
- commandService.syncExecuteCommand(ReplacePdfSnapshotCommand4.id, { snapshot: nextSnapshot });
9290
+ const applied = commandService.syncExecuteCommand(ReplacePdfSnapshotCommand4.id, {
9291
+ unitId: unit.getUnitId(),
9292
+ snapshot: nextSnapshot
9293
+ });
9294
+ if (!applied) {
9295
+ setStatusTip("\u5E94\u7528\u6A21\u677F JSON \u5931\u8D25\uFF1AReplacePdfSnapshotCommand \u6267\u884C\u8FD4\u56DE false");
9296
+ return;
9297
+ }
9122
9298
  setStatusTip("\u5DF2\u6210\u529F\u5E94\u7528\u6A21\u677F JSON\uFF08\u652F\u6301 Ctrl+Z \u64A4\u9500\uFF09\uFF01");
9123
9299
  } catch (err) {
9124
9300
  setStatusTip(`JSON \u89E3\u6790\u9519\u8BEF: ${err?.message || String(err)}`);
@@ -9128,9 +9304,24 @@ var PdfPreviewModal = () => {
9128
9304
  const ioCaps = ioService.getIoCapabilities();
9129
9305
  const pdfCapReport = inspectPdfExportCapabilities(unit.save());
9130
9306
  const snapSizeKb = (pdfCapReport.snapshotByteSize / 1024).toFixed(1);
9131
- const isUnifiedIoTab = modalTab === "preview" || modalTab === "import";
9132
- const browserAvailable = modalTab === "import" ? Boolean(ioCaps.formats.import.pdf?.browser) : Boolean(ioCaps.formats.export.pdf?.browser);
9133
- const serverAvailable = modalTab === "import" ? Boolean(ioCaps.formats.import.pdf?.server) : Boolean(ioCaps.formats.export.pdf?.server);
9307
+ const effectiveModalTab = clampPdfModalTab(modalTab, ioModal);
9308
+ const isUnifiedIoTab = !(effectiveModalTab === "json" && ioModal.tabs.includes("json"));
9309
+ const showImportControls = !ioModal.hasExplicitTabs ? ioModal.tabs.includes("import") : effectiveModalTab === "import";
9310
+ const showExportControls = !ioModal.hasExplicitTabs ? ioModal.tabs.includes("export") : effectiveModalTab === "export";
9311
+ const browserAvailable = effectiveModalTab === "import" ? Boolean(ioCaps.formats.import.pdf?.browser) : Boolean(ioCaps.formats.export.pdf?.browser);
9312
+ const serverAvailable = effectiveModalTab === "import" ? Boolean(ioCaps.formats.import.pdf?.server) : Boolean(ioCaps.formats.export.pdf?.server);
9313
+ const tabLabelFor = (tabKey) => {
9314
+ switch (tabKey) {
9315
+ case "preview":
9316
+ return "PDF \u9884\u89C8";
9317
+ case "import":
9318
+ return "PDF \u5BFC\u5165";
9319
+ case "export":
9320
+ return "PDF \u5BFC\u51FA";
9321
+ case "json":
9322
+ return "{ } JSON \u5951\u7EA6 (IPdfUnitData / pdfme \u4E92\u8F6C)";
9323
+ }
9324
+ };
9134
9325
  const unifiedIoSection = /* @__PURE__ */ jsx6(
9135
9326
  PdfUnifiedIoSection,
9136
9327
  {
@@ -9139,6 +9330,7 @@ var PdfPreviewModal = () => {
9139
9330
  serverAvailable,
9140
9331
  snapSizeKb,
9141
9332
  editorEnabled,
9333
+ showImportSection: showImportControls,
9142
9334
  importing,
9143
9335
  rendering,
9144
9336
  selectedFileName: selectedImportFile?.name,
@@ -9163,11 +9355,12 @@ var PdfPreviewModal = () => {
9163
9355
  onClick: (e) => e.stopPropagation(),
9164
9356
  children: [
9165
9357
  /* @__PURE__ */ jsxs6("div", { className: "univer-pdf-modal-header", children: [
9166
- /* @__PURE__ */ jsxs6("div", { className: "univer-pdf-modal-tabs", children: [
9358
+ /* @__PURE__ */ jsx6("div", { className: "univer-pdf-modal-tabs", children: !ioModal.hasExplicitTabs ? /* @__PURE__ */ jsxs6(Fragment4, { children: [
9167
9359
  /* @__PURE__ */ jsxs6(
9168
9360
  "button",
9169
9361
  {
9170
9362
  type: "button",
9363
+ "data-testid": "yudao-io-tab-preview",
9171
9364
  className: `univer-pdf-modal-tab ${isUnifiedIoTab ? "is-active" : ""}`,
9172
9365
  style: { display: "inline-flex", alignItems: "center", gap: 5 },
9173
9366
  onClick: () => featureService.setModalTab("preview"),
@@ -9177,20 +9370,36 @@ var PdfPreviewModal = () => {
9177
9370
  ]
9178
9371
  }
9179
9372
  ),
9180
- /* @__PURE__ */ jsx6(
9373
+ ioModal.tabs.includes("json") && /* @__PURE__ */ jsx6(
9181
9374
  "button",
9182
9375
  {
9183
9376
  type: "button",
9184
- className: `univer-pdf-modal-tab ${modalTab === "json" ? "is-active" : ""}`,
9377
+ "data-testid": "yudao-io-tab-json",
9378
+ className: `univer-pdf-modal-tab ${effectiveModalTab === "json" ? "is-active" : ""}`,
9185
9379
  onClick: () => featureService.setModalTab("json"),
9186
9380
  children: `{ } JSON \u5951\u7EA6 (IPdfUnitData / pdfme \u4E92\u8F6C)`
9187
9381
  }
9188
9382
  )
9189
- ] }),
9383
+ ] }) : ioModal.tabs.map((tabKey) => /* @__PURE__ */ jsxs6(
9384
+ "button",
9385
+ {
9386
+ type: "button",
9387
+ "data-testid": `yudao-io-tab-${tabKey}`,
9388
+ className: `univer-pdf-modal-tab ${effectiveModalTab === tabKey ? "is-active" : ""}`,
9389
+ style: { display: "inline-flex", alignItems: "center", gap: 5 },
9390
+ onClick: () => featureService.setModalTab(tabKey),
9391
+ children: [
9392
+ tabKey !== "json" && /* @__PURE__ */ jsx6(UiFilePdfIcon, {}),
9393
+ /* @__PURE__ */ jsx6("span", { children: tabLabelFor(tabKey) })
9394
+ ]
9395
+ },
9396
+ tabKey
9397
+ )) }),
9190
9398
  /* @__PURE__ */ jsxs6("div", { style: { display: "flex", alignItems: "center", gap: 10 }, children: [
9191
- /* @__PURE__ */ jsxs6(
9399
+ ioModal.showPipelineBadge && /* @__PURE__ */ jsxs6(
9192
9400
  "span",
9193
9401
  {
9402
+ "data-testid": "yudao-io-pipeline-badge",
9194
9403
  style: {
9195
9404
  fontSize: 11,
9196
9405
  padding: "3px 8px",
@@ -9554,7 +9763,7 @@ var PdfPreviewModal = () => {
9554
9763
  }
9555
9764
  )
9556
9765
  ] }),
9557
- splitMergeQuickBox,
9766
+ showExportControls && splitMergeQuickBox,
9558
9767
  /* @__PURE__ */ jsxs6("div", { className: "univer-pdf-btn-row", children: [
9559
9768
  /* @__PURE__ */ jsx6(
9560
9769
  "button",
@@ -9566,41 +9775,43 @@ var PdfPreviewModal = () => {
9566
9775
  children: rendering ? "\u6E32\u67D3\u4E2D..." : "\u91CD\u65B0\u751F\u6210 PDF"
9567
9776
  }
9568
9777
  ),
9569
- /* @__PURE__ */ jsx6(
9570
- "button",
9571
- {
9572
- type: "button",
9573
- className: "univer-pdf-mini-btn",
9574
- disabled: rendering,
9575
- onClick: () => {
9576
- const baseObj = unit.save().metadata?.sampleData ?? { orderNo: "SO-2026-001" };
9577
- const batchArr = [1, 2, 3].map((n) => ({
9578
- ...baseObj,
9579
- orderNo: `BATCH-2026-00${n}`,
9580
- batchSeq: n
9581
- }));
9582
- const txt = JSON.stringify(batchArr, null, 2);
9583
- setSampleJsonText(txt);
9584
- void generatePreview(txt);
9585
- },
9586
- children: "\u6279\u91CF\u5957\u6253 (3\u5355\u5408\u5E76)"
9587
- }
9588
- ),
9589
- /* @__PURE__ */ jsxs6(
9590
- "button",
9591
- {
9592
- type: "button",
9593
- "data-testid": "yudao-io-export-download",
9594
- className: "univer-pdf-mini-btn",
9595
- style: { display: "inline-flex", alignItems: "center", gap: 4 },
9596
- disabled: rendering,
9597
- onClick: () => void handleExportAndDownload(),
9598
- children: [
9599
- /* @__PURE__ */ jsx6(UiDownloadIcon, {}),
9600
- /* @__PURE__ */ jsx6("span", { children: "\u4E0B\u8F7D PDF \u6587\u4EF6" })
9601
- ]
9602
- }
9603
- ),
9778
+ showExportControls && /* @__PURE__ */ jsxs6(Fragment4, { children: [
9779
+ /* @__PURE__ */ jsx6(
9780
+ "button",
9781
+ {
9782
+ type: "button",
9783
+ className: "univer-pdf-mini-btn",
9784
+ disabled: rendering,
9785
+ onClick: () => {
9786
+ const baseObj = unit.save().metadata?.sampleData ?? { orderNo: "SO-2026-001" };
9787
+ const batchArr = [1, 2, 3].map((n) => ({
9788
+ ...baseObj,
9789
+ orderNo: `BATCH-2026-00${n}`,
9790
+ batchSeq: n
9791
+ }));
9792
+ const txt = JSON.stringify(batchArr, null, 2);
9793
+ setSampleJsonText(txt);
9794
+ void generatePreview(txt);
9795
+ },
9796
+ children: "\u6279\u91CF\u5957\u6253 (3\u5355\u5408\u5E76)"
9797
+ }
9798
+ ),
9799
+ /* @__PURE__ */ jsxs6(
9800
+ "button",
9801
+ {
9802
+ type: "button",
9803
+ "data-testid": "yudao-io-export-download",
9804
+ className: "univer-pdf-mini-btn",
9805
+ style: { display: "inline-flex", alignItems: "center", gap: 4 },
9806
+ disabled: rendering,
9807
+ onClick: () => void handleExportAndDownload(),
9808
+ children: [
9809
+ /* @__PURE__ */ jsx6(UiDownloadIcon, {}),
9810
+ /* @__PURE__ */ jsx6("span", { children: "\u4E0B\u8F7D PDF \u6587\u4EF6" })
9811
+ ]
9812
+ }
9813
+ )
9814
+ ] }),
9604
9815
  features.print && /* @__PURE__ */ jsxs6(
9605
9816
  "button",
9606
9817
  {
@@ -9648,109 +9859,118 @@ var PdfPreviewModal = () => {
9648
9859
  /* @__PURE__ */ jsx6("div", { className: "univer-pdf-modal-label", children: "\u901A\u7528 PDF \u5BFC\u5165\u4E0E\u5BFC\u51FA\u5DE5\u4F5C\u53F0" }),
9649
9860
  /* @__PURE__ */ jsx6("div", { style: { fontSize: 12, color: "#4E5565", lineHeight: 1.55 }, children: "\u5F53\u524D\u5904\u4E8E\u901A\u7528 PDF \u6587\u6863/\u6279\u6CE8\u6A21\u5F0F\uFF08\u672A\u5F00\u542F\u6570\u636E\u96C6\u7ED1\u5B9A\uFF09\u3002\u53EF\u9009\u62E9\u6D4F\u89C8\u5668\u6216\u670D\u52A1\u7AEF\u901A\u9053\u5B8C\u6210 PDF \u5BFC\u5165\u5BA1\u6838\u4E0E\u5BFC\u51FA\u4E0B\u8F7D\u3002" }),
9650
9861
  unifiedIoSection,
9651
- /* @__PURE__ */ jsxs6(
9652
- "button",
9653
- {
9654
- type: "button",
9655
- "data-testid": "yudao-io-export-download",
9656
- className: "univer-pdf-mini-btn is-primary",
9657
- style: { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 4 },
9658
- disabled: rendering,
9659
- onClick: () => void handleExportAndDownload(),
9660
- children: [
9661
- /* @__PURE__ */ jsx6(UiDownloadIcon, {}),
9662
- /* @__PURE__ */ jsx6("span", { children: "\u4E0B\u8F7D\u6807\u51C6 PDF \u6587\u4EF6" })
9663
- ]
9664
- }
9665
- ),
9666
- /* @__PURE__ */ jsxs6(
9667
- "button",
9668
- {
9669
- type: "button",
9670
- className: "univer-pdf-mini-btn",
9671
- style: { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 4 },
9672
- disabled: rendering,
9673
- onClick: handleDownloadCalibrationGrid,
9674
- children: [
9675
- /* @__PURE__ */ jsx6(UiRulerGridIcon, {}),
9676
- /* @__PURE__ */ jsx6("span", { children: "\u4E0B\u8F7D\u6BEB\u7C73\u6821\u51C6\u6D4B\u8BD5\u5C3A PDF" })
9677
- ]
9678
- }
9679
- ),
9680
- /* @__PURE__ */ jsxs6("label", { className: "univer-pdf-checkbox-row", style: { fontSize: 11.5 }, children: [
9681
- /* @__PURE__ */ jsx6(
9682
- "input",
9862
+ showExportControls && /* @__PURE__ */ jsxs6(Fragment4, { children: [
9863
+ /* @__PURE__ */ jsxs6(
9864
+ "button",
9683
9865
  {
9684
- type: "checkbox",
9685
- checked: enableAuditSeal,
9686
- onChange: (e) => {
9687
- const checked = e.target.checked;
9688
- setEnableAuditSeal(checked);
9689
- void generatePreview(sampleJsonText, watermarkText, excludeBasePdf, ioTarget, void 0, checked);
9690
- }
9866
+ type: "button",
9867
+ "data-testid": "yudao-io-export-download",
9868
+ className: "univer-pdf-mini-btn is-primary",
9869
+ style: { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 4 },
9870
+ disabled: rendering,
9871
+ onClick: () => void handleExportAndDownload(),
9872
+ children: [
9873
+ /* @__PURE__ */ jsx6(UiDownloadIcon, {}),
9874
+ /* @__PURE__ */ jsx6("span", { children: "\u4E0B\u8F7D\u6807\u51C6 PDF \u6587\u4EF6" })
9875
+ ]
9691
9876
  }
9692
9877
  ),
9693
- /* @__PURE__ */ jsx6(UiShieldSealIcon, { style: { color: "#4E5565" } }),
9694
- /* @__PURE__ */ jsx6("span", { children: "\u9644\u52A0 SHA-256 \u9632\u7BE1\u6539\u7B7E\u7AE0\u6458\u8981" })
9695
- ] }),
9696
- /* @__PURE__ */ jsxs6("div", { style: { display: "flex", flexDirection: "column", gap: 4 }, children: [
9697
- /* @__PURE__ */ jsx6("div", { style: { fontSize: 11, fontWeight: 600, color: "#1B1C1F" }, children: "\u9488\u5F0F\u786C\u4EF6\u504F\u79FB\u8865\u507F X/Y (mm)" }),
9698
- /* @__PURE__ */ jsxs6("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 4 }, children: [
9878
+ /* @__PURE__ */ jsxs6(
9879
+ "button",
9880
+ {
9881
+ type: "button",
9882
+ className: "univer-pdf-mini-btn",
9883
+ style: { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 4 },
9884
+ disabled: rendering,
9885
+ onClick: handleDownloadCalibrationGrid,
9886
+ children: [
9887
+ /* @__PURE__ */ jsx6(UiRulerGridIcon, {}),
9888
+ /* @__PURE__ */ jsx6("span", { children: "\u4E0B\u8F7D\u6BEB\u7C73\u6821\u51C6\u6D4B\u8BD5\u5C3A PDF" })
9889
+ ]
9890
+ }
9891
+ ),
9892
+ /* @__PURE__ */ jsxs6("label", { className: "univer-pdf-checkbox-row", style: { fontSize: 11.5 }, children: [
9699
9893
  /* @__PURE__ */ jsx6(
9700
9894
  "input",
9701
9895
  {
9702
- type: "number",
9703
- step: "0.5",
9704
- title: "\u6C34\u5E73\u504F\u79FB X (mm)",
9705
- value: printerOffsetXMm,
9896
+ type: "checkbox",
9897
+ checked: enableAuditSeal,
9706
9898
  onChange: (e) => {
9707
- const nextX = Number(e.target.value) || 0;
9708
- setPrinterOffsetXMm(nextX);
9709
- void generatePreview(sampleJsonText, watermarkText, excludeBasePdf, ioTarget, {
9710
- printerOffsetXMm: nextX
9711
- });
9712
- },
9713
- style: {
9714
- width: "100%",
9715
- boxSizing: "border-box",
9716
- border: "1px solid #D5D8DF",
9717
- borderRadius: 4,
9718
- padding: "2px 4px",
9719
- fontSize: 11,
9720
- color: "#1B1C1F",
9721
- background: "#FFFFFF"
9899
+ const checked = e.target.checked;
9900
+ setEnableAuditSeal(checked);
9901
+ void generatePreview(
9902
+ sampleJsonText,
9903
+ watermarkText,
9904
+ excludeBasePdf,
9905
+ ioTarget,
9906
+ void 0,
9907
+ checked
9908
+ );
9722
9909
  }
9723
9910
  }
9724
9911
  ),
9725
- /* @__PURE__ */ jsx6(
9726
- "input",
9727
- {
9728
- type: "number",
9729
- step: "0.5",
9730
- title: "\u5782\u76F4\u504F\u79FB Y (mm)",
9731
- value: printerOffsetYMm,
9732
- onChange: (e) => {
9733
- const nextY = Number(e.target.value) || 0;
9734
- setPrinterOffsetYMm(nextY);
9735
- void generatePreview(sampleJsonText, watermarkText, excludeBasePdf, ioTarget, {
9736
- printerOffsetYMm: nextY
9737
- });
9738
- },
9739
- style: {
9740
- width: "100%",
9741
- boxSizing: "border-box",
9742
- border: "1px solid #D5D8DF",
9743
- borderRadius: 4,
9744
- padding: "2px 4px",
9745
- fontSize: 11,
9746
- color: "#1B1C1F",
9747
- background: "#FFFFFF"
9912
+ /* @__PURE__ */ jsx6(UiShieldSealIcon, { style: { color: "#4E5565" } }),
9913
+ /* @__PURE__ */ jsx6("span", { children: "\u9644\u52A0 SHA-256 \u9632\u7BE1\u6539\u7B7E\u7AE0\u6458\u8981" })
9914
+ ] }),
9915
+ /* @__PURE__ */ jsxs6("div", { style: { display: "flex", flexDirection: "column", gap: 4 }, children: [
9916
+ /* @__PURE__ */ jsx6("div", { style: { fontSize: 11, fontWeight: 600, color: "#1B1C1F" }, children: "\u9488\u5F0F\u786C\u4EF6\u504F\u79FB\u8865\u507F X/Y (mm)" }),
9917
+ /* @__PURE__ */ jsxs6("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 4 }, children: [
9918
+ /* @__PURE__ */ jsx6(
9919
+ "input",
9920
+ {
9921
+ type: "number",
9922
+ step: "0.5",
9923
+ title: "\u6C34\u5E73\u504F\u79FB X (mm)",
9924
+ value: printerOffsetXMm,
9925
+ onChange: (e) => {
9926
+ const nextX = Number(e.target.value) || 0;
9927
+ setPrinterOffsetXMm(nextX);
9928
+ void generatePreview(sampleJsonText, watermarkText, excludeBasePdf, ioTarget, {
9929
+ printerOffsetXMm: nextX
9930
+ });
9931
+ },
9932
+ style: {
9933
+ width: "100%",
9934
+ boxSizing: "border-box",
9935
+ border: "1px solid #D5D8DF",
9936
+ borderRadius: 4,
9937
+ padding: "2px 4px",
9938
+ fontSize: 11,
9939
+ color: "#1B1C1F",
9940
+ background: "#FFFFFF"
9941
+ }
9748
9942
  }
9749
- }
9750
- )
9751
- ] })
9943
+ ),
9944
+ /* @__PURE__ */ jsx6(
9945
+ "input",
9946
+ {
9947
+ type: "number",
9948
+ step: "0.5",
9949
+ title: "\u5782\u76F4\u504F\u79FB Y (mm)",
9950
+ value: printerOffsetYMm,
9951
+ onChange: (e) => {
9952
+ const nextY = Number(e.target.value) || 0;
9953
+ setPrinterOffsetYMm(nextY);
9954
+ void generatePreview(sampleJsonText, watermarkText, excludeBasePdf, ioTarget, {
9955
+ printerOffsetYMm: nextY
9956
+ });
9957
+ },
9958
+ style: {
9959
+ width: "100%",
9960
+ boxSizing: "border-box",
9961
+ border: "1px solid #D5D8DF",
9962
+ borderRadius: 4,
9963
+ padding: "2px 4px",
9964
+ fontSize: 11,
9965
+ color: "#1B1C1F",
9966
+ background: "#FFFFFF"
9967
+ }
9968
+ }
9969
+ )
9970
+ ] })
9971
+ ] }),
9972
+ splitMergeQuickBox
9752
9973
  ] }),
9753
- splitMergeQuickBox,
9754
9974
  features.print && /* @__PURE__ */ jsxs6(
9755
9975
  "button",
9756
9976
  {
@@ -9916,13 +10136,17 @@ function createBtn(config) {
9916
10136
  tooltip: config.tooltip ?? config.title,
9917
10137
  icon: config.icon,
9918
10138
  params: config.params,
9919
- hidden$: needsHiddenObs ? combineLatest([featService.features$, featService.editorEnabled$]).pipe(
9920
- map(([f, editorEnabled]) => {
10139
+ hidden$: needsHiddenObs ? combineLatest([
10140
+ featService.features$,
10141
+ featService.editorEnabled$,
10142
+ featService.ioModal$
10143
+ ]).pipe(
10144
+ map(([f, editorEnabled, ioModal]) => {
9921
10145
  if (requiresEditor && !editorEnabled) return true;
9922
10146
  if (config.elementTypeGate && !isPdfElementTypeAllowed(config.elementTypeGate, f)) {
9923
10147
  return true;
9924
10148
  }
9925
- return config.hiddenWhen ? config.hiddenWhen(f, editorEnabled) : false;
10149
+ return config.hiddenWhen ? config.hiddenWhen(f, editorEnabled, ioModal) : false;
9926
10150
  })
9927
10151
  ) : void 0
9928
10152
  };
@@ -10198,7 +10422,7 @@ var UploadBasePdfMenuFactory = createBtn({
10198
10422
  label: "pdfs.ribbon.importPdf",
10199
10423
  icon: "PdfUploadIcon",
10200
10424
  requiresEditor: true,
10201
- hiddenWhen: (f) => !f.basePdfOverlay
10425
+ hiddenWhen: (f, _editor, ioModal) => !f.basePdfOverlay || !ioModal.tabs.includes("import")
10202
10426
  });
10203
10427
  var OpenJsonExchangeMenuFactory = createBtn({
10204
10428
  id: "pdfs-ui.menu.open-json",
@@ -10207,7 +10431,8 @@ var OpenJsonExchangeMenuFactory = createBtn({
10207
10431
  label: "pdfs.ribbon.jsonExchange",
10208
10432
  icon: "PdfJsonIcon",
10209
10433
  params: { tab: "json" },
10210
- requiresEditor: true
10434
+ requiresEditor: true,
10435
+ hiddenWhen: (_f, _editor, ioModal) => !ioModal.tabs.includes("json")
10211
10436
  });
10212
10437
  var ToggleInspectorMenuFactory = createBtn({
10213
10438
  id: TogglePdfInspectorOperation.id,
@@ -10220,8 +10445,7 @@ var OpenPdfPreviewMenuFactory = createBtn({
10220
10445
  id: OpenPdfPreviewOperation.id,
10221
10446
  title: "pdfs.ribbon.previewPdf",
10222
10447
  label: "pdfs.ribbon.previewPdf",
10223
- icon: "PdfPreviewIcon",
10224
- params: { tab: "preview" }
10448
+ icon: "PdfPreviewIcon"
10225
10449
  });
10226
10450
  var PrintPdfMenuFactory = createBtn({
10227
10451
  id: PrintPdfOperation.id,
@@ -10540,7 +10764,7 @@ var UniverPdfsUIPlugin = class extends Plugin {
10540
10764
  this._injector.add([
10541
10765
  IPdfsUIFeatureService,
10542
10766
  {
10543
- useFactory: () => new PdfsUIFeatureService(this._config.features, editorEnabled)
10767
+ useFactory: () => new PdfsUIFeatureService(this._config.features, editorEnabled, this._config.ioModal)
10544
10768
  }
10545
10769
  ]);
10546
10770
  this._injector.add([
@@ -10560,6 +10784,7 @@ UniverPdfsUIPlugin = __decorateClass([
10560
10784
  __decorateParam(1, Inject2(Injector))
10561
10785
  ], UniverPdfsUIPlugin);
10562
10786
  export {
10787
+ ALL_PDF_IO_MODAL_TABS,
10563
10788
  AdjustPdfZoomOperation,
10564
10789
  IPdfsUIFeatureService,
10565
10790
  InsertPdfPresetElementOperation,
@@ -10593,9 +10818,12 @@ export {
10593
10818
  UniverPdfsUIPlugin,
10594
10819
  UpdatePdfUIFeaturesOperation,
10595
10820
  UploadBasePdfOperation,
10821
+ applyStagedPdfImportToUnit,
10822
+ clampPdfModalTab,
10596
10823
  clearPdfDocumentCache,
10597
10824
  computePdfDocumentCacheKey,
10598
10825
  configurePdfjsAssets,
10826
+ executeGuardedStagedImport,
10599
10827
  getPdfjsAssetsConfig,
10600
10828
  inspectSourcePdfPages,
10601
10829
  isPdfElementTypeAllowed,
@@ -10604,6 +10832,7 @@ export {
10604
10832
  readBrowserFileAsOverlayOutcome,
10605
10833
  renderSourcePdfPageToCanvas,
10606
10834
  resolveInitialModalIoTarget,
10835
+ resolvePdfIoModalConfig,
10607
10836
  resolvePdfsUIFeatures
10608
10837
  };
10609
10838
  //# sourceMappingURL=index.js.map