@yudaocode/univer-docs-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/cjs/index.js CHANGED
@@ -59,11 +59,13 @@ __export(src_exports, {
59
59
  UniverDocsExtUIPlugin: () => UniverDocsExtUIPlugin,
60
60
  UpdateDocsUIFeaturesOperation: () => UpdateDocsUIFeaturesOperation,
61
61
  YUDAO_DOC_FIELD_DND_MIME: () => YUDAO_DOC_FIELD_DND_MIME,
62
+ confirmStagedDocImport: () => confirmStagedDocImport,
62
63
  enUS: () => en_US_default,
63
64
  isDocSdtKindAllowed: () => isDocSdtKindAllowed,
64
65
  openDocInspectorSidebar: () => openDocInspectorSidebar,
65
66
  resolveDocsUIFeatures: () => resolveDocsUIFeatures,
66
67
  resolveEffectiveSdtDatasetBinding: () => resolveEffectiveSdtDatasetBinding,
68
+ runGuardedStagedImport: () => runGuardedStagedImport,
67
69
  zhCN: () => zh_CN_default
68
70
  });
69
71
  module.exports = __toCommonJS(src_exports);
@@ -286,6 +288,14 @@ function isDocSdtKindAllowed(features, kind) {
286
288
  if (!features?.allowedSdtKinds || features.allowedSdtKinds.length === 0) return true;
287
289
  return features.allowedSdtKinds.includes(kind);
288
290
  }
291
+ function cloneIoModalConfig(cfg) {
292
+ if (!cfg) return void 0;
293
+ return {
294
+ ...cfg.tabs ? { tabs: [...cfg.tabs] } : {},
295
+ ...cfg.defaultTab !== void 0 ? { defaultTab: cfg.defaultTab } : {},
296
+ ...cfg.showPipelineBadge !== void 0 ? { showPipelineBadge: cfg.showPipelineBadge } : {}
297
+ };
298
+ }
289
299
  function resolveDocsUIFeatures(raw) {
290
300
  return {
291
301
  sdtControls: Boolean(raw?.sdtControls),
@@ -319,40 +329,91 @@ function resolveDocsUIFeatures(raw) {
319
329
  paragraphAdvancedLayout: raw?.paragraphAdvancedLayout ?? true,
320
330
  legacyFormatIo: raw?.legacyFormatIo ?? true,
321
331
  bookmarks: raw?.bookmarks ?? true,
322
- ...raw?.allowedSdtKinds ? { allowedSdtKinds: [...raw.allowedSdtKinds] } : {}
332
+ ...raw?.allowedSdtKinds ? { allowedSdtKinds: [...raw.allowedSdtKinds] } : {},
333
+ ...raw?.ioModal ? { ioModal: cloneIoModalConfig(raw.ioModal) } : {}
323
334
  };
324
335
  }
325
336
  var IDocsUIFeatureService = (0, import_core.createIdentifier)(
326
337
  "yudao.univer-docs-ui.feature.service"
327
338
  );
328
339
  var DocsUIFeatureService = class extends import_core.Disposable {
329
- constructor(initial) {
340
+ constructor(initial, initialIoModal) {
330
341
  super();
331
342
  this._modalOpen$ = new import_rxjs.BehaviorSubject(false);
332
- this._modalTab$ = new import_rxjs.BehaviorSubject("preview");
333
343
  this.modalOpen$ = this._modalOpen$.asObservable();
334
- this.modalTab$ = this._modalTab$.asObservable();
335
- this._features$ = new import_rxjs.BehaviorSubject(resolveDocsUIFeatures(initial));
344
+ const resolvedFeatures = resolveDocsUIFeatures(initial);
345
+ this._baseIoModal = cloneIoModalConfig(initialIoModal ?? resolvedFeatures.ioModal);
346
+ const initTab = this._resolveValidTab(void 0, this._baseIoModal);
347
+ this._features$ = new import_rxjs.BehaviorSubject(resolvedFeatures);
348
+ this._modalTab$ = new import_rxjs.BehaviorSubject(initTab);
349
+ this._ioModal$ = new import_rxjs.BehaviorSubject(
350
+ cloneIoModalConfig(this._baseIoModal)
351
+ );
336
352
  this.features$ = this._features$.asObservable();
353
+ this.modalTab$ = this._modalTab$.asObservable();
354
+ this.ioModal$ = this._ioModal$.asObservable();
337
355
  this.disposeWithMe({
338
356
  dispose: () => {
339
357
  this._features$.complete();
340
358
  this._modalOpen$.complete();
341
359
  this._modalTab$.complete();
360
+ this._ioModal$.complete();
342
361
  }
343
362
  });
344
363
  }
364
+ _mergeIoModal(override) {
365
+ const featIoModal = this._features$.getValue().ioModal;
366
+ const base = this._baseIoModal ?? featIoModal;
367
+ if (!base && !override) return void 0;
368
+ return cloneIoModalConfig({
369
+ ...base ?? {},
370
+ ...override ?? {}
371
+ });
372
+ }
373
+ _resolveValidTab(requestedTab, cfg) {
374
+ const raw = requestedTab || cfg?.defaultTab || "preview";
375
+ const allowed = cfg?.tabs;
376
+ if (allowed && allowed.length > 0) {
377
+ if (allowed.includes(raw)) {
378
+ return raw;
379
+ }
380
+ if (raw === "preview") {
381
+ if (allowed.includes("export")) return "export";
382
+ if (allowed.includes("print")) return "print";
383
+ }
384
+ return allowed[0];
385
+ }
386
+ return raw;
387
+ }
345
388
  getFeatures() {
346
389
  return this._features$.getValue();
347
390
  }
348
391
  setFeatures(features) {
349
- this._features$.next(resolveDocsUIFeatures(features));
392
+ const next = resolveDocsUIFeatures(features);
393
+ this._features$.next(next);
394
+ if (features.ioModal !== void 0) {
395
+ this._ioModal$.next(this._mergeIoModal());
396
+ }
350
397
  }
351
398
  patchFeatures(patch) {
352
399
  this._features$.next({
353
400
  ...this._features$.getValue(),
354
401
  ...patch
355
402
  });
403
+ if (patch.ioModal !== void 0) {
404
+ this._ioModal$.next(this._mergeIoModal());
405
+ }
406
+ }
407
+ getIoModalConfig() {
408
+ return this._ioModal$.getValue();
409
+ }
410
+ setIoModalConfig(config) {
411
+ this._baseIoModal = cloneIoModalConfig(config);
412
+ const merged = this._mergeIoModal();
413
+ this._ioModal$.next(merged);
414
+ if (!this._modalOpen$.getValue()) {
415
+ this._modalTab$.next(this._resolveValidTab(void 0, merged));
416
+ }
356
417
  }
357
418
  isModalOpen() {
358
419
  return this._modalOpen$.getValue();
@@ -360,15 +421,17 @@ var DocsUIFeatureService = class extends import_core.Disposable {
360
421
  getModalTab() {
361
422
  return this._modalTab$.getValue();
362
423
  }
363
- openModal(tab = "preview") {
364
- this._modalTab$.next(tab);
424
+ openModal(tab, ioModal) {
425
+ const merged = this._mergeIoModal(ioModal);
426
+ this._ioModal$.next(merged);
427
+ this._modalTab$.next(this._resolveValidTab(tab, merged));
365
428
  this._modalOpen$.next(true);
366
429
  }
367
430
  closeModal() {
368
431
  this._modalOpen$.next(false);
369
432
  }
370
433
  setModalTab(tab) {
371
- this._modalTab$.next(tab);
434
+ this._modalTab$.next(this._resolveValidTab(tab, this._ioModal$.getValue()));
372
435
  }
373
436
  };
374
437
 
@@ -404,7 +467,7 @@ var OpenDocModalOperation = {
404
467
  if (featureService.getFeatures().builtinPreviewModal === false) {
405
468
  return false;
406
469
  }
407
- featureService.openModal(params?.tab ?? "preview");
470
+ featureService.openModal(params?.tab, params?.ioModal);
408
471
  return true;
409
472
  }
410
473
  };
@@ -504,15 +567,19 @@ var ImportDocFileOperation = {
504
567
  import_core2.UniverInstanceType.UNIVER_DOC
505
568
  );
506
569
  if (!docModel) return false;
507
- void ioService.importDoc(params.file, docModel.getUnitId(), {
508
- target: params.target
509
- }).then((parsed) => {
570
+ void ioService.importDoc(
571
+ params.file,
572
+ docModel.getUnitId(),
573
+ params.signal ? { target: params.target, signal: params.signal } : { target: params.target }
574
+ ).then((parsed) => {
575
+ if (params.signal?.aborted) return;
510
576
  if (parsed.body) {
511
577
  commandService.syncExecuteCommand(import_univer_docs.ReplaceDocUnitSnapshotCommand.id, {
512
578
  unitId: docModel.getUnitId(),
513
579
  snapshot: parsed
514
580
  });
515
581
  }
582
+ }).catch(() => {
516
583
  });
517
584
  return true;
518
585
  }
@@ -520,14 +587,17 @@ var ImportDocFileOperation = {
520
587
  if (accessor.has(IDocsUIFeatureService)) {
521
588
  const featureService = accessor.get(IDocsUIFeatureService);
522
589
  if (featureService.getFeatures().builtinPreviewModal !== false) {
523
- featureService.openModal("import");
590
+ featureService.openModal("import", params?.ioModal);
524
591
  return true;
525
592
  }
526
593
  return false;
527
594
  }
528
595
  } catch {
529
596
  }
530
- return commandService.syncExecuteCommand(OpenDocModalOperation.id, { tab: "import" });
597
+ return commandService.syncExecuteCommand(OpenDocModalOperation.id, {
598
+ tab: "import",
599
+ ...params?.ioModal ? { ioModal: params.ioModal } : {}
600
+ });
531
601
  }
532
602
  };
533
603
  var QuickInsertDocSdtOperation = {
@@ -746,6 +816,9 @@ var UpdateDocsUIFeaturesOperation = {
746
816
  } else if (params?.patch) {
747
817
  featureService.patchFeatures(params.patch);
748
818
  }
819
+ if (params?.ioModal !== void 0) {
820
+ featureService.setIoModalConfig(params.ioModal);
821
+ }
749
822
  return true;
750
823
  }
751
824
  };
@@ -5002,6 +5075,84 @@ var MODAL_PEN_COLORS = [
5002
5075
  { hex: "#2C53F1", label: "\u7B7E\u5B57\u84DD" },
5003
5076
  { hex: "#DC2626", label: "\u6731\u7802\u7EA2" }
5004
5077
  ];
5078
+ async function runGuardedStagedImport(params) {
5079
+ const {
5080
+ file,
5081
+ unitId,
5082
+ activeTarget,
5083
+ ioService,
5084
+ importReqSeqRef,
5085
+ importAbortRef,
5086
+ onStaged,
5087
+ onError
5088
+ } = params;
5089
+ importAbortRef.current?.abort();
5090
+ const abortController = new AbortController();
5091
+ importAbortRef.current = abortController;
5092
+ const reqSeq = ++importReqSeqRef.current;
5093
+ try {
5094
+ const outcome = await ioService.importDocWithReport(file, {
5095
+ unitId,
5096
+ target: activeTarget,
5097
+ signal: abortController.signal
5098
+ });
5099
+ if (reqSeq !== importReqSeqRef.current || abortController.signal.aborted) {
5100
+ return;
5101
+ }
5102
+ const stagedSnap = outcome.snapshot ?? outcome.documentData;
5103
+ onStaged({
5104
+ snapshot: stagedSnap,
5105
+ warnings: outcome.warnings,
5106
+ executedBy: outcome.executedBy,
5107
+ fileName: outcome.fileName || file.name
5108
+ });
5109
+ } catch (err) {
5110
+ if (reqSeq !== importReqSeqRef.current || abortController.signal.aborted || err?.name === "AbortError") {
5111
+ return;
5112
+ }
5113
+ const message = err?.message || String(err);
5114
+ onError({
5115
+ operation: "import",
5116
+ failedTarget: activeTarget,
5117
+ message
5118
+ });
5119
+ }
5120
+ }
5121
+ function confirmStagedDocImport(params) {
5122
+ const { commandService, unitId, pendingImport } = params;
5123
+ if (!pendingImport.snapshot?.body) {
5124
+ const missingBodyMsg = "\u5BFC\u5165\u5FEB\u7167\u7F3A\u5C11\u6709\u6548\u6B63\u6587\u7ED3\u6784\uFF08body\uFF09\uFF0C\u65E0\u6CD5\u8986\u76D6\u5F53\u524D\u8BBE\u8BA1\u5668\u6587\u6863";
5125
+ return {
5126
+ ok: false,
5127
+ ioError: {
5128
+ operation: "import",
5129
+ failedTarget: pendingImport.executedBy,
5130
+ message: missingBodyMsg
5131
+ },
5132
+ statusTip: `\u5BFC\u5165\u5E94\u7528\u5931\u8D25: ${missingBodyMsg}`
5133
+ };
5134
+ }
5135
+ const applied = commandService.syncExecuteCommand(import_univer_docs4.ReplaceDocUnitSnapshotCommand.id, {
5136
+ unitId,
5137
+ snapshot: pendingImport.snapshot
5138
+ });
5139
+ if (!applied) {
5140
+ const applyErrMsg = "\u5E94\u7528\u5BFC\u5165\u5FEB\u7167\u5230\u5F53\u524D\u8BBE\u8BA1\u5668\u5931\u8D25\uFF08\u6587\u6863\u5904\u4E8E\u53EA\u8BFB\u6A21\u5F0F\u6216\u5FEB\u7167\u7ED3\u6784\u4E0D\u5408\u6CD5\uFF09";
5141
+ return {
5142
+ ok: false,
5143
+ ioError: {
5144
+ operation: "import",
5145
+ failedTarget: pendingImport.executedBy,
5146
+ message: applyErrMsg
5147
+ },
5148
+ statusTip: `\u5BFC\u5165\u5E94\u7528\u5931\u8D25: ${applyErrMsg}`
5149
+ };
5150
+ }
5151
+ return {
5152
+ ok: true,
5153
+ statusTip: "\u5DF2\u5E94\u7528\u5230\u5F53\u524D\u8BBE\u8BA1\u5668\uFF0C\u8BF7\u7531\u5BBF\u4E3B\u4FDD\u5B58"
5154
+ };
5155
+ }
5005
5156
  function inferExtFromFileName(fileName) {
5006
5157
  const m = fileName.trim().toLowerCase().match(/\.([^.]+)$/);
5007
5158
  if (!m) return "docx";
@@ -5039,6 +5190,10 @@ var DocPreviewAndIoModal = () => {
5039
5190
  const open = (0, import_ui4.useObservable)(featureService.modalOpen$, featureService.isModalOpen());
5040
5191
  const tab = (0, import_ui4.useObservable)(featureService.modalTab$, featureService.getModalTab());
5041
5192
  const features = (0, import_ui4.useObservable)(featureService.features$, featureService.getFeatures());
5193
+ const ioModalConfig = (0, import_ui4.useObservable)(
5194
+ featureService.ioModal$,
5195
+ featureService.getIoModalConfig()
5196
+ );
5042
5197
  const ioAdapter = (0, import_ui4.useObservable)(ioService.adapter$, ioService.getAdapter());
5043
5198
  const unit = (0, import_ui4.useObservable)(
5044
5199
  () => instanceService.getCurrentTypeOfUnit$(import_core5.UniverInstanceType.UNIVER_DOC),
@@ -5068,8 +5223,16 @@ var DocPreviewAndIoModal = () => {
5068
5223
  const fileInputRef = (0, import_react3.useRef)(null);
5069
5224
  const sigCanvasRef = (0, import_react3.useRef)(null);
5070
5225
  const iframeRef = (0, import_react3.useRef)(null);
5226
+ const importReqSeqRef = (0, import_react3.useRef)(0);
5227
+ const importAbortRef = (0, import_react3.useRef)(null);
5071
5228
  (0, import_react3.useEffect)(() => {
5072
- if (!open || !unit) return;
5229
+ if (!open) {
5230
+ importReqSeqRef.current += 1;
5231
+ importAbortRef.current?.abort();
5232
+ importAbortRef.current = null;
5233
+ return;
5234
+ }
5235
+ if (!unit) return;
5073
5236
  const snap = unit.getSnapshot();
5074
5237
  const meta = sdtService.getTemplateMetadata(unit.getUnitId());
5075
5238
  const initialData = meta.sampleData ?? {};
@@ -5099,7 +5262,16 @@ var DocPreviewAndIoModal = () => {
5099
5262
  const isCustomBackendAdapter = Boolean(
5100
5263
  ioAdapter.exportDoc || ioAdapter.importDoc || ioAdapter.onSave
5101
5264
  );
5102
- const activeCapabilityOp = tab === "import" ? "import" : "export";
5265
+ const hasCompactTabs = Boolean(ioModalConfig?.tabs && ioModalConfig.tabs.length > 0);
5266
+ const visibleTabs = hasCompactTabs ? ioModalConfig.tabs : [
5267
+ "import",
5268
+ "preview",
5269
+ ...features.sdtControls ? ["form"] : [],
5270
+ "json"
5271
+ ];
5272
+ const effectiveTab = visibleTabs.includes(tab) ? tab : tab === "preview" && visibleTabs.includes("export") ? "export" : tab === "preview" && visibleTabs.includes("print") ? "print" : visibleTabs[0] ?? "preview";
5273
+ const showPipelineBadge = ioModalConfig?.showPipelineBadge !== false;
5274
+ const activeCapabilityOp = effectiveTab === "import" ? "import" : "export";
5103
5275
  const activeFormatMatrix = ioCaps.formats[activeCapabilityOp];
5104
5276
  const browserSupportedFormats = import_univer_docs4.DOC_IO_CAPABILITY_FORMATS.filter(
5105
5277
  (fmt) => activeFormatMatrix[fmt]?.browser
@@ -5232,35 +5404,29 @@ var DocPreviewAndIoModal = () => {
5232
5404
  setSelectedImportFile(file);
5233
5405
  setIoError(null);
5234
5406
  setPendingImport(null);
5235
- try {
5236
- const outcome = await ioService.importDocWithReport(file, {
5237
- unitId: unit.getUnitId(),
5238
- target: activeTarget
5239
- });
5240
- const stagedSnap = outcome.snapshot ?? outcome.documentData;
5241
- setPendingImport({
5242
- snapshot: stagedSnap,
5243
- warnings: outcome.warnings,
5244
- executedBy: outcome.executedBy,
5245
- fileName: outcome.fileName || file.name
5246
- });
5247
- if (stagedSnap.body) {
5248
- setPreviewHtml(
5249
- (0, import_univer_docs4.exportDocHtmlString)(stagedSnap, void 0, { printFieldsOnly })
5407
+ await runGuardedStagedImport({
5408
+ file,
5409
+ unitId: unit.getUnitId(),
5410
+ activeTarget,
5411
+ ioService,
5412
+ importReqSeqRef,
5413
+ importAbortRef,
5414
+ onStaged: (staged) => {
5415
+ setPendingImport(staged);
5416
+ if (staged.snapshot.body) {
5417
+ setPreviewHtml(
5418
+ (0, import_univer_docs4.exportDocHtmlString)(staged.snapshot, void 0, { printFieldsOnly })
5419
+ );
5420
+ }
5421
+ setStatusTip(
5422
+ `\u5DF2\u5B8C\u6210\u300C${staged.fileName}\u300D\u9884\u89E3\u6790\uFF08\u5C1A\u672A\u8986\u76D6\u5F53\u524D\u8BBE\u8BA1\u5668\u6587\u6863\uFF0C\u8BF7\u786E\u8BA4\u540E\u5E94\u7528\uFF09`
5250
5423
  );
5424
+ },
5425
+ onError: (errState) => {
5426
+ setIoError(errState);
5427
+ setStatusTip(`\u5BFC\u5165\u5931\u8D25: ${errState.message}`);
5251
5428
  }
5252
- setStatusTip(
5253
- `\u5DF2\u5B8C\u6210\u300C${outcome.fileName || file.name}\u300D\u9884\u89E3\u6790\uFF08\u5C1A\u672A\u8986\u76D6\u5F53\u524D\u8BBE\u8BA1\u5668\u6587\u6863\uFF0C\u8BF7\u786E\u8BA4\u540E\u5E94\u7528\uFF09`
5254
- );
5255
- } catch (err) {
5256
- const message = err?.message || String(err);
5257
- setIoError({
5258
- operation: "import",
5259
- failedTarget: activeTarget,
5260
- message
5261
- });
5262
- setStatusTip(`\u5BFC\u5165\u5931\u8D25: ${message}`);
5263
- }
5429
+ });
5264
5430
  };
5265
5431
  const handleFileInputChange = (e) => {
5266
5432
  const file = e.target.files?.[0];
@@ -5278,18 +5444,26 @@ var DocPreviewAndIoModal = () => {
5278
5444
  };
5279
5445
  const handleConfirmStagedImport = () => {
5280
5446
  if (!pendingImport) return;
5281
- if (pendingImport.snapshot.body) {
5282
- commandService.syncExecuteCommand(import_univer_docs4.ReplaceDocUnitSnapshotCommand.id, {
5283
- unitId: unit.getUnitId(),
5284
- snapshot: pendingImport.snapshot
5285
- });
5447
+ const result = confirmStagedDocImport({
5448
+ commandService,
5449
+ unitId: unit.getUnitId(),
5450
+ pendingImport
5451
+ });
5452
+ if (!result.ok) {
5453
+ setIoError(result.ioError);
5454
+ setStatusTip(result.statusTip);
5455
+ return;
5286
5456
  }
5287
5457
  setPendingImport(null);
5458
+ setIoError(null);
5288
5459
  setJsonEditorText(JSON.stringify(unit.getSnapshot(), null, 2));
5289
5460
  setPreviewHtml((0, import_univer_docs4.exportDocHtmlString)(unit.getSnapshot(), void 0, { printFieldsOnly }));
5290
- setStatusTip("\u5DF2\u5E94\u7528\u5230\u5F53\u524D\u8BBE\u8BA1\u5668\uFF0C\u8BF7\u7531\u5BBF\u4E3B\u4FDD\u5B58");
5461
+ setStatusTip(result.statusTip);
5291
5462
  };
5292
5463
  const handleCancelStagedImport = () => {
5464
+ importReqSeqRef.current += 1;
5465
+ importAbortRef.current?.abort();
5466
+ importAbortRef.current = null;
5293
5467
  setPendingImport(null);
5294
5468
  setPreviewHtml((0, import_univer_docs4.exportDocHtmlString)(unit.getSnapshot(), void 0, { printFieldsOnly }));
5295
5469
  setStatusTip("\u5DF2\u53D6\u6D88\u672C\u6B21\u5BFC\u5165\uFF0C\u5F53\u524D\u8BBE\u8BA1\u5668\u6587\u6863\u672A\u505A\u4FEE\u6539");
@@ -5319,7 +5493,7 @@ var DocPreviewAndIoModal = () => {
5319
5493
  }
5320
5494
  };
5321
5495
  const stagedStats = pendingImport?.snapshot?.body ? (0, import_univer_docs4.getDocumentStats)(pendingImport.snapshot) : null;
5322
- const renderIoControlCard = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5496
+ const renderIoControlCard = (opts) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5323
5497
  "div",
5324
5498
  {
5325
5499
  style: {
@@ -5394,49 +5568,51 @@ var DocPreviewAndIoModal = () => {
5394
5568
  }
5395
5569
  )
5396
5570
  ] }),
5397
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5398
- "input",
5399
- {
5400
- ref: fileInputRef,
5401
- type: "file",
5402
- "data-testid": "yudao-io-file-input",
5403
- accept: DOC_IMPORT_ACCEPT_EXTENSIONS,
5404
- style: { display: "none" },
5405
- onChange: handleFileInputChange
5406
- }
5407
- ),
5408
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", gap: 6, alignItems: "center" }, children: [
5571
+ !opts?.hideFilePicker && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
5409
5572
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5410
- "button",
5573
+ "input",
5411
5574
  {
5412
- type: "button",
5413
- "data-testid": "yudao-io-pick-file",
5414
- className: "yudao-doc-mini-btn",
5415
- style: { flex: 1 },
5416
- onClick: () => {
5417
- if (fileInputRef.current) {
5418
- fileInputRef.current.value = "";
5419
- fileInputRef.current.click();
5420
- }
5421
- },
5422
- children: "\u9009\u62E9\u6587\u4EF6\u9884\u5BFC\u5165"
5575
+ ref: fileInputRef,
5576
+ type: "file",
5577
+ "data-testid": "yudao-io-file-input",
5578
+ accept: DOC_IMPORT_ACCEPT_EXTENSIONS,
5579
+ style: { display: "none" },
5580
+ onChange: handleFileInputChange
5423
5581
  }
5424
5582
  ),
5425
- selectedImportFile && !pendingImport && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5426
- "span",
5427
- {
5428
- style: {
5429
- fontSize: 10.5,
5430
- color: "#4e5565",
5431
- maxWidth: 130,
5432
- overflow: "hidden",
5433
- textOverflow: "ellipsis",
5434
- whiteSpace: "nowrap"
5435
- },
5436
- title: selectedImportFile.name,
5437
- children: selectedImportFile.name
5438
- }
5439
- )
5583
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", gap: 6, alignItems: "center" }, children: [
5584
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5585
+ "button",
5586
+ {
5587
+ type: "button",
5588
+ "data-testid": "yudao-io-pick-file",
5589
+ className: "yudao-doc-mini-btn",
5590
+ style: { flex: 1 },
5591
+ onClick: () => {
5592
+ if (fileInputRef.current) {
5593
+ fileInputRef.current.value = "";
5594
+ fileInputRef.current.click();
5595
+ }
5596
+ },
5597
+ children: "\u9009\u62E9\u6587\u4EF6\u9884\u5BFC\u5165"
5598
+ }
5599
+ ),
5600
+ selectedImportFile && !pendingImport && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5601
+ "span",
5602
+ {
5603
+ style: {
5604
+ fontSize: 10.5,
5605
+ color: "#4e5565",
5606
+ maxWidth: 130,
5607
+ overflow: "hidden",
5608
+ textOverflow: "ellipsis",
5609
+ whiteSpace: "nowrap"
5610
+ },
5611
+ title: selectedImportFile.name,
5612
+ children: selectedImportFile.name
5613
+ }
5614
+ )
5615
+ ] })
5440
5616
  ] }),
5441
5617
  pendingImport && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5442
5618
  "div",
@@ -5565,6 +5741,17 @@ var DocPreviewAndIoModal = () => {
5565
5741
  ]
5566
5742
  }
5567
5743
  );
5744
+ const tabLabels = {
5745
+ import: "\u6587\u6863\u5BFC\u5165",
5746
+ export: "\u6587\u6863\u5BFC\u51FA",
5747
+ print: "\u6253\u5370\u9884\u89C8",
5748
+ preview: "\u5957\u6253\u9884\u89C8\u4E0E\u5BFC\u51FA",
5749
+ form: "\u7ED3\u6784\u5316\u8868\u5355\u6821\u9A8C\u4E0E\u53D6\u503C",
5750
+ json: "{ } Univer IDocumentData \u5951\u7EA6"
5751
+ };
5752
+ const isSplitPaneTab = effectiveTab === "import" || effectiveTab === "export" || effectiveTab === "print" || effectiveTab === "preview";
5753
+ const showPrintSettingsSection = !hasCompactTabs || effectiveTab === "print" || effectiveTab === "preview";
5754
+ const showExportActionsSection = !hasCompactTabs || effectiveTab === "export" || effectiveTab === "print" || effectiveTab === "preview";
5568
5755
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "yudao-doc-modal-backdrop", onClick: () => featureService.closeModal(), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5569
5756
  "div",
5570
5757
  {
@@ -5573,48 +5760,22 @@ var DocPreviewAndIoModal = () => {
5573
5760
  onClick: (e) => e.stopPropagation(),
5574
5761
  children: [
5575
5762
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "yudao-doc-modal-header", children: [
5576
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "yudao-doc-modal-tabs", children: [
5577
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5578
- "button",
5579
- {
5580
- type: "button",
5581
- className: `yudao-doc-modal-tab ${tab === "import" ? "is-active" : ""}`,
5582
- onClick: () => featureService.setModalTab("import"),
5583
- children: "\u6587\u6863\u5BFC\u5165"
5584
- }
5585
- ),
5586
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5587
- "button",
5588
- {
5589
- type: "button",
5590
- className: `yudao-doc-modal-tab ${tab === "preview" ? "is-active" : ""}`,
5591
- onClick: () => featureService.setModalTab("preview"),
5592
- children: "\u5957\u6253\u9884\u89C8\u4E0E\u5BFC\u51FA"
5593
- }
5594
- ),
5595
- features.sdtControls && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5596
- "button",
5597
- {
5598
- type: "button",
5599
- className: `yudao-doc-modal-tab ${tab === "form" ? "is-active" : ""}`,
5600
- onClick: () => featureService.setModalTab("form"),
5601
- children: "\u7ED3\u6784\u5316\u8868\u5355\u6821\u9A8C\u4E0E\u53D6\u503C"
5602
- }
5603
- ),
5604
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5605
- "button",
5606
- {
5607
- type: "button",
5608
- className: `yudao-doc-modal-tab ${tab === "json" ? "is-active" : ""}`,
5609
- onClick: () => featureService.setModalTab("json"),
5610
- children: `{ } Univer IDocumentData \u5951\u7EA6`
5611
- }
5612
- )
5613
- ] }),
5763
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "yudao-doc-modal-tabs", children: visibleTabs.map((tabKey) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5764
+ "button",
5765
+ {
5766
+ type: "button",
5767
+ "data-testid": `yudao-io-tab-${tabKey}`,
5768
+ className: `yudao-doc-modal-tab ${effectiveTab === tabKey ? "is-active" : ""}`,
5769
+ onClick: () => featureService.setModalTab(tabKey),
5770
+ children: tabLabels[tabKey]
5771
+ },
5772
+ tabKey
5773
+ )) }),
5614
5774
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 10 }, children: [
5615
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5775
+ showPipelineBadge && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5616
5776
  "span",
5617
5777
  {
5778
+ "data-testid": "yudao-io-pipeline-badge",
5618
5779
  style: {
5619
5780
  fontSize: 11,
5620
5781
  padding: "3px 8px",
@@ -5641,7 +5802,7 @@ var DocPreviewAndIoModal = () => {
5641
5802
  )
5642
5803
  ] })
5643
5804
  ] }),
5644
- tab === "import" || tab === "preview" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { flex: 1, minHeight: 0, display: "flex" }, children: [
5805
+ isSplitPaneTab ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { flex: 1, minHeight: 0, display: "flex" }, children: [
5645
5806
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5646
5807
  "div",
5647
5808
  {
@@ -5656,7 +5817,8 @@ var DocPreviewAndIoModal = () => {
5656
5817
  overflowY: "auto"
5657
5818
  },
5658
5819
  children: [
5659
- tab === "import" && renderIoControlCard(),
5820
+ effectiveTab === "import" && renderIoControlCard(),
5821
+ hasCompactTabs && effectiveTab === "export" && renderIoControlCard({ hideFilePicker: true }),
5660
5822
  features.datasetBinding ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
5661
5823
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontSize: 12, fontWeight: 600, color: "#1b1c1f" }, children: "\u4E1A\u52A1\u6570\u636E\u96C6 JSON\uFF08\u652F\u6301\u5355\u6761\u5BF9\u8C61\u6216\u6279\u91CF\u6570\u7EC4 [...]\uFF09" }),
5662
5824
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
@@ -5690,7 +5852,7 @@ var DocPreviewAndIoModal = () => {
5690
5852
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { children: ".md" }),
5691
5853
  " \u7B49\u6587\u6863\u683C\u5F0F\u3002"
5692
5854
  ] }),
5693
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 6, paddingTop: 4, borderTop: "1px solid #e3e5ea" }, children: [
5855
+ showPrintSettingsSection && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 6, paddingTop: 4, borderTop: "1px solid #e3e5ea" }, children: [
5694
5856
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5695
5857
  "input",
5696
5858
  {
@@ -5900,8 +6062,9 @@ var DocPreviewAndIoModal = () => {
5900
6062
  )
5901
6063
  ] })
5902
6064
  ] }),
5903
- tab !== "import" && renderIoControlCard(),
5904
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 6, marginTop: 2 }, children: [
6065
+ !hasCompactTabs && effectiveTab !== "import" && renderIoControlCard(),
6066
+ hasCompactTabs && effectiveTab === "preview" && renderIoControlCard(),
6067
+ showExportActionsSection && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 6, marginTop: 2 }, children: [
5905
6068
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", gap: 6 }, children: [
5906
6069
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5907
6070
  "select",
@@ -5984,6 +6147,7 @@ var DocPreviewAndIoModal = () => {
5984
6147
  "button",
5985
6148
  {
5986
6149
  type: "button",
6150
+ "data-testid": "yudao-io-print-btn",
5987
6151
  className: "yudao-doc-mini-btn yudao-doc-export-btn",
5988
6152
  style: { gridColumn: "1 / -1" },
5989
6153
  onClick: () => {
@@ -6038,7 +6202,7 @@ var DocPreviewAndIoModal = () => {
6038
6202
  }
6039
6203
  }
6040
6204
  ) })
6041
- ] }) : tab === "form" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { flex: 1, minHeight: 0, padding: 18, display: "flex", gap: 16 }, children: [
6205
+ ] }) : effectiveTab === "form" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { flex: 1, minHeight: 0, padding: 18, display: "flex", gap: 16 }, children: [
6042
6206
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { width: 320, display: "flex", flexDirection: "column", gap: 10 }, children: [
6043
6207
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
6044
6208
  "div",
@@ -6123,10 +6287,19 @@ var DocPreviewAndIoModal = () => {
6123
6287
  onClick: () => {
6124
6288
  try {
6125
6289
  const parsed = JSON.parse(jsonEditorText);
6126
- commandService.syncExecuteCommand(import_univer_docs4.ReplaceDocUnitSnapshotCommand.id, {
6127
- unitId: unit.getUnitId(),
6128
- snapshot: parsed
6129
- });
6290
+ const ok = commandService.syncExecuteCommand(
6291
+ import_univer_docs4.ReplaceDocUnitSnapshotCommand.id,
6292
+ {
6293
+ unitId: unit.getUnitId(),
6294
+ snapshot: parsed
6295
+ }
6296
+ );
6297
+ if (!ok) {
6298
+ setStatusTip(
6299
+ "\u5E94\u7528 JSON \u5FEB\u7167\u5931\u8D25\uFF1A\u5FEB\u7167\u7ED3\u6784\u4E0D\u5408\u6CD5\u6216\u5F53\u524D\u6587\u6863\u5904\u4E8E\u53EA\u8BFB\u6A21\u5F0F"
6300
+ );
6301
+ return;
6302
+ }
6130
6303
  setStatusTip("\u5DF2\u5E94\u7528 JSON \u5FEB\u7167\uFF08\u652F\u6301 Ctrl+Z \u64A4\u9500\uFF09\uFF01");
6131
6304
  } catch (err) {
6132
6305
  setStatusTip(`JSON \u683C\u5F0F\u6709\u8BEF: ${err?.message || String(err)}`);
@@ -8248,7 +8421,7 @@ var UniverDocsExtUIPlugin = class extends import_core8.Plugin {
8248
8421
  this._injector.add([
8249
8422
  IDocsUIFeatureService,
8250
8423
  {
8251
- useFactory: () => new DocsUIFeatureService(this._config.features)
8424
+ useFactory: () => new DocsUIFeatureService(this._config.features, this._config.ioModal)
8252
8425
  }
8253
8426
  ]);
8254
8427
  this._injector.add([
@@ -8292,11 +8465,13 @@ UniverDocsExtUIPlugin = __decorateClass([
8292
8465
  UniverDocsExtUIPlugin,
8293
8466
  UpdateDocsUIFeaturesOperation,
8294
8467
  YUDAO_DOC_FIELD_DND_MIME,
8468
+ confirmStagedDocImport,
8295
8469
  enUS,
8296
8470
  isDocSdtKindAllowed,
8297
8471
  openDocInspectorSidebar,
8298
8472
  resolveDocsUIFeatures,
8299
8473
  resolveEffectiveSdtDatasetBinding,
8474
+ runGuardedStagedImport,
8300
8475
  zhCN
8301
8476
  });
8302
8477
  //# sourceMappingURL=index.js.map