@chenchaolong/plugin-trade-compliance-workbench 1.0.133 → 1.0.135

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.
Files changed (32) hide show
  1. package/dist/lib/remote-components/trade-compliance-workbench/app.js +7 -7
  2. package/dist/lib/remote-components/trade-compliance-workbench/editor-source.mjs +14 -3
  3. package/dist/lib/remote-components/trade-compliance-workbench/editor.js +19 -19
  4. package/dist/lib/remote-components/trade-compliance-workbench/preview-source.mjs +42 -13
  5. package/dist/lib/remote-components/trade-compliance-workbench/preview.js +168 -168
  6. package/dist/lib/remote-ui/app-source.d.ts.map +1 -1
  7. package/dist/lib/remote-ui/app-source.js +39 -45
  8. package/dist/lib/remote-ui/app-source.js.map +1 -1
  9. package/dist/lib/remote-ui/components/source-file-preview.d.ts +18 -3
  10. package/dist/lib/remote-ui/components/source-file-preview.d.ts.map +1 -1
  11. package/dist/lib/remote-ui/components/source-file-preview.js +34 -17
  12. package/dist/lib/remote-ui/components/source-file-preview.js.map +1 -1
  13. package/dist/lib/remote-ui/customer-contract-contracts.d.ts +8 -0
  14. package/dist/lib/remote-ui/customer-contract-contracts.d.ts.map +1 -1
  15. package/dist/lib/remote-ui/isolated-runtime.d.ts +36 -0
  16. package/dist/lib/remote-ui/isolated-runtime.d.ts.map +1 -0
  17. package/dist/lib/remote-ui/isolated-runtime.js +158 -0
  18. package/dist/lib/remote-ui/isolated-runtime.js.map +1 -0
  19. package/dist/lib/remote-ui/model.d.ts +1 -0
  20. package/dist/lib/remote-ui/model.d.ts.map +1 -1
  21. package/dist/lib/remote-ui/model.js +17 -0
  22. package/dist/lib/remote-ui/model.js.map +1 -1
  23. package/dist/lib/remote-ui/pages/procurement.d.ts.map +1 -1
  24. package/dist/lib/remote-ui/pages/procurement.js +5 -3
  25. package/dist/lib/remote-ui/pages/procurement.js.map +1 -1
  26. package/dist/lib/remote-ui/procurement-contracts.d.ts +8 -0
  27. package/dist/lib/remote-ui/procurement-contracts.d.ts.map +1 -1
  28. package/dist/lib/workbench-view.provider.d.ts +27 -7
  29. package/dist/lib/workbench-view.provider.d.ts.map +1 -1
  30. package/dist/lib/workbench-view.provider.js +20 -1
  31. package/dist/lib/workbench-view.provider.js.map +1 -1
  32. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"app-source.d.ts","sourceRoot":"","sources":["../../../src/lib/remote-ui/app-source.tsx"],"names":[],"mappings":"AAgCA,OAAO,cAAc,CAAA"}
1
+ {"version":3,"file":"app-source.d.ts","sourceRoot":"","sources":["../../../src/lib/remote-ui/app-source.tsx"],"names":[],"mappings":"AAiCA,OAAO,cAAc,CAAA"}
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import React from 'react';
3
3
  import { createRoot } from 'react-dom/client';
4
4
  import { createRemoteBridge } from './bridge.js';
5
+ import { createExcelEditorRuntime, createPreviewRuntime } from './isolated-runtime.js';
5
6
  import { resolvePaginationPageSize } from './contracts.js';
6
7
  import { clampPageAfterSingleDeletion, createBlobUrlOwner, createKeyedLatestRequestGate, createLatestCommittedRequest, createLatestRequestGate, generatedFileHistoryKey, isCurrentSettingsRouteRevision, normalizeWorkbenchData, routeDataRequest, runKeyedLatestRequest, unwrapResponse } from './model.js';
7
8
  import { encodeViewFilters } from '../view-parameters.js';
@@ -47,9 +48,6 @@ const procurementPageMeta = {
47
48
  const bridge = createRemoteBridge();
48
49
  let sourcePreviewRuntimePromise = null;
49
50
  async function ensureSourcePreviewRuntime() {
50
- const runtimeWindow = window;
51
- if (runtimeWindow.TradeComplianceSourcePreview)
52
- return runtimeWindow.TradeComplianceSourcePreview;
53
51
  if (sourcePreviewRuntimePromise)
54
52
  return sourcePreviewRuntimePromise;
55
53
  sourcePreviewRuntimePromise = (async () => {
@@ -59,14 +57,7 @@ async function ensureSourcePreviewRuntime() {
59
57
  const script = asRecord(result.data).script;
60
58
  if (typeof script !== 'string' || !script.trim())
61
59
  throw new Error('文件预览运行时响应不完整');
62
- const element = document.createElement('script');
63
- element.dataset.tradeCompliancePreviewRuntime = 'true';
64
- element.textContent = script;
65
- document.body.appendChild(element);
66
- const runtime = runtimeWindow.TradeComplianceSourcePreview;
67
- if (!runtime)
68
- throw new Error('文件预览运行时初始化失败');
69
- return runtime;
60
+ return createPreviewRuntime(script);
70
61
  })().catch(error => { sourcePreviewRuntimePromise = null; throw error; });
71
62
  return sourcePreviewRuntimePromise;
72
63
  }
@@ -489,6 +480,12 @@ function App() {
489
480
  salesFilesPrototypeListenerCleanupRef.current?.();
490
481
  salesFilesPrototypeListenerCleanupRef.current = null;
491
482
  blobUrlOwnerRef.current.dispose();
483
+ const previewRuntime = sourcePreviewRuntimePromise;
484
+ sourcePreviewRuntimePromise = null;
485
+ void previewRuntime?.then(runtime => runtime.dispose?.(), () => undefined);
486
+ const editorRuntime = excelEditorRuntimePromise;
487
+ excelEditorRuntimePromise = null;
488
+ void editorRuntime?.then(runtime => runtime.dispose?.(), () => undefined);
492
489
  bridge.destroy();
493
490
  };
494
491
  }, [configureSalesFilesPrototypeCapability, load]);
@@ -1742,6 +1739,8 @@ async function attachPurchaseSource(draft, task, owner) {
1742
1739
  if (draft.sourcePreview || !task.sourceFileId)
1743
1740
  return draft;
1744
1741
  const preview = await loadSourcePreview(task.sourceFileId, 'purchase', owner);
1742
+ if (preview.previewKind === 'PDF_PAGES')
1743
+ return { ...draft, sourcePreview: { kind: 'PDF_PAGES', pages: preview.pages, pageCount: preview.pageCount, fileName: preview.fileName } };
1745
1744
  if (preview.previewKind === 'BINARY')
1746
1745
  return { ...draft, sourcePreview: { kind: 'BINARY', url: preview.url, fileName: preview.fileName, mimeType: preview.mimeType }, sourceFileUrl: preview.url };
1747
1746
  if (preview.previewKind === 'URL')
@@ -1754,6 +1753,8 @@ async function attachCustomerSource(review, owner) {
1754
1753
  if (review.sourcePreview.kind === 'URL' || !review.sourceFileId)
1755
1754
  return review;
1756
1755
  const preview = await loadSourcePreview(review.sourceFileId, 'customer', owner);
1756
+ if (preview.previewKind === 'PDF_PAGES')
1757
+ return { ...review, sourcePreview: { kind: 'PDF_PAGES', pages: preview.pages, pageCount: preview.pageCount, fileName: preview.fileName } };
1757
1758
  if (preview.previewKind === 'URL')
1758
1759
  return { ...review, sourcePreview: { kind: 'URL', url: preview.url } };
1759
1760
  if (preview.previewKind === 'BINARY')
@@ -1763,18 +1764,33 @@ async function attachCustomerSource(review, owner) {
1763
1764
  return { ...review, sourcePreview: { kind: 'UNAVAILABLE', message: preview.message } };
1764
1765
  }
1765
1766
  async function loadSourcePreview(sourceFileId, slot, owner) {
1766
- const result = asActionResult(unwrapResponse(await bridge.executeAction('preview_source_file', { sourceFileId })));
1767
- if (result.success === false)
1768
- throw new Error(resolveActionMessage(result) || '源文件加载失败');
1769
- const file = asRecord(result.data);
1770
- if (file.previewKind === 'TEXT' && typeof file.content === 'string')
1771
- return { previewKind: 'TEXT', content: file.content };
1772
- if (file.previewKind === 'BINARY' && typeof file.base64 === 'string' && typeof file.mimeType === 'string') {
1773
- return { previewKind: 'BINARY', url: owner.replace(slot, blobUrlFromBase64(file.base64, file.mimeType)), fileName: typeof file.fileName === 'string' ? file.fileName : '源文件', mimeType: file.mimeType };
1767
+ try {
1768
+ const result = asActionResult(unwrapResponse(await bridge.executeAction('preview_source_file', { sourceFileId })));
1769
+ if (result.success === false)
1770
+ return { previewKind: 'UNAVAILABLE', message: resolveActionMessage(result) || '源文件加载失败,请下载原文件查看' };
1771
+ const file = asRecord(result.data);
1772
+ if (file.previewKind === 'TEXT' && typeof file.content === 'string')
1773
+ return { previewKind: 'TEXT', content: file.content };
1774
+ if (file.previewKind === 'BINARY' && typeof file.base64 === 'string' && typeof file.mimeType === 'string') {
1775
+ return { previewKind: 'BINARY', url: owner.replace(slot, blobUrlFromBase64(file.base64, file.mimeType)), fileName: typeof file.fileName === 'string' ? file.fileName : '源文件', mimeType: file.mimeType };
1776
+ }
1777
+ if (file.previewKind === 'PDF_PAGES' && Array.isArray(file.pages) && typeof file.pageCount === 'number' && typeof file.fileName === 'string') {
1778
+ const pages = file.pages.flatMap(page => {
1779
+ const item = asRecord(page);
1780
+ if (!Number.isInteger(item.pageNumber) || typeof item.base64 !== 'string' || typeof item.mimeType !== 'string')
1781
+ return [];
1782
+ return [{ pageNumber: Number(item.pageNumber), url: blobUrlFromBase64(item.base64, item.mimeType) }];
1783
+ });
1784
+ if (pages.length)
1785
+ return { previewKind: 'PDF_PAGES', pages: owner.replaceMany(slot, pages.map(page => page.url)).map((url, index) => ({ pageNumber: pages[index].pageNumber, url })), pageCount: file.pageCount, fileName: file.fileName };
1786
+ }
1787
+ if (file.previewKind === 'UNAVAILABLE')
1788
+ return { previewKind: 'UNAVAILABLE', message: typeof file.message === 'string' ? file.message : '源文件暂无法在线预览' };
1789
+ return { previewKind: 'UNAVAILABLE', message: '源文件预览响应无效,请下载原文件查看' };
1790
+ }
1791
+ catch (error) {
1792
+ return { previewKind: 'UNAVAILABLE', message: error instanceof Error ? `源文件预览失败:${error.message}` : '源文件预览失败,请下载原文件查看' };
1774
1793
  }
1775
- if (file.previewKind === 'UNAVAILABLE')
1776
- return { previewKind: 'UNAVAILABLE', message: typeof file.message === 'string' ? file.message : '源文件暂无法在线预览' };
1777
- throw new Error('源文件预览响应类型无效');
1778
1794
  }
1779
1795
  function blobUrlFromBase64(base64, mimeType) {
1780
1796
  const binary = atob(base64);
@@ -1799,9 +1815,6 @@ function asCustomerContractReanalysisResult(value) {
1799
1815
  return payload;
1800
1816
  }
1801
1817
  async function ensureExcelEditorRuntime() {
1802
- const runtimeWindow = window;
1803
- if (runtimeWindow.TradeComplianceExcelEditor?.open)
1804
- return runtimeWindow.TradeComplianceExcelEditor;
1805
1818
  if (excelEditorRuntimePromise)
1806
1819
  return excelEditorRuntimePromise;
1807
1820
  excelEditorRuntimePromise = (async () => {
@@ -1812,27 +1825,8 @@ async function ensureExcelEditorRuntime() {
1812
1825
  const css = result.data?.css;
1813
1826
  if (typeof script !== 'string' || !script.trim() || typeof css !== 'string')
1814
1827
  throw new Error('Excel 编辑器运行时响应不完整');
1815
- let styleElement = document.head.querySelector('style[data-trade-compliance-editor-styles]');
1816
- if (!styleElement) {
1817
- styleElement = document.createElement('style');
1818
- styleElement.dataset.tradeComplianceEditorStyles = 'true';
1819
- styleElement.textContent = css;
1820
- document.head.appendChild(styleElement);
1821
- }
1822
- let scriptElement = document.body.querySelector('script[data-trade-compliance-editor-runtime]');
1823
- if (!scriptElement) {
1824
- scriptElement = document.createElement('script');
1825
- scriptElement.dataset.tradeComplianceEditorRuntime = 'true';
1826
- scriptElement.textContent = script;
1827
- document.body.appendChild(scriptElement);
1828
- }
1829
- const runtime = runtimeWindow.TradeComplianceExcelEditor;
1830
- if (!runtime?.open)
1831
- throw new Error('Excel 编辑器运行时初始化失败');
1832
- return runtime;
1828
+ return createExcelEditorRuntime(script, css);
1833
1829
  })().catch((error) => {
1834
- document.querySelector('script[data-trade-compliance-editor-runtime]')?.remove();
1835
- document.querySelector('style[data-trade-compliance-editor-styles]')?.remove();
1836
1830
  excelEditorRuntimePromise = null;
1837
1831
  throw error;
1838
1832
  });