@embedpdf/plugin-document-manager 2.0.0-next.0
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/LICENSE +21 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +466 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/document-manager-plugin.d.ts +45 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/types.d.ts +80 -0
- package/dist/preact/adapter.d.ts +5 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -0
- package/dist/preact/index.cjs.map +1 -0
- package/dist/preact/index.d.ts +1 -0
- package/dist/preact/index.js +136 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +135 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared/components/document-content.d.ts +27 -0
- package/dist/shared/components/document-context.d.ts +42 -0
- package/dist/shared/components/file-picker.d.ts +1 -0
- package/dist/shared/components/index.d.ts +3 -0
- package/dist/shared/hooks/index.d.ts +1 -0
- package/dist/shared/hooks/use-document-manager.d.ts +23 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared-preact/components/document-content.d.ts +27 -0
- package/dist/shared-preact/components/document-context.d.ts +42 -0
- package/dist/shared-preact/components/file-picker.d.ts +1 -0
- package/dist/shared-preact/components/index.d.ts +3 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-document-manager.d.ts +23 -0
- package/dist/shared-preact/index.d.ts +4 -0
- package/dist/shared-react/components/document-content.d.ts +27 -0
- package/dist/shared-react/components/document-context.d.ts +42 -0
- package/dist/shared-react/components/file-picker.d.ts +1 -0
- package/dist/shared-react/components/index.d.ts +3 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-document-manager.d.ts +23 -0
- package/dist/shared-react/index.d.ts +4 -0
- package/dist/svelte/components/DocumentContent.svelte.d.ts +15 -0
- package/dist/svelte/components/DocumentContext.svelte.d.ts +18 -0
- package/dist/svelte/components/FilePicker.svelte.d.ts +3 -0
- package/dist/svelte/components/index.d.ts +3 -0
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-document-manager.svelte.d.ts +26 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +4 -0
- package/dist/svelte/index.js +175 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vue/components/document-content.vue.d.ts +29 -0
- package/dist/vue/components/document-context.vue.d.ts +28 -0
- package/dist/vue/components/file-picker.vue.d.ts +3 -0
- package/dist/vue/components/index.d.ts +3 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-document-manager.d.ts +17 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +4 -0
- package/dist/vue/index.js +169 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/lib/document-manager-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import {\n BasePlugin,\n PluginRegistry,\n createBehaviorEmitter,\n startLoadingDocument,\n setDocumentLoaded,\n setDocumentError,\n retryLoadingDocument,\n closeDocument as closeDocumentAction,\n setActiveDocument as setActiveDocumentAction,\n moveDocument as moveDocumentAction,\n reorderDocuments as reorderDocumentsAction,\n DocumentState,\n Unsubscribe,\n Listener,\n createEmitter,\n} from '@embedpdf/core';\nimport {\n PdfDocumentObject,\n Task,\n PdfFile,\n PdfFileUrl,\n PdfErrorReason,\n PdfErrorCode,\n} from '@embedpdf/models';\n\nimport {\n DocumentManagerPluginConfig,\n DocumentManagerCapability,\n DocumentChangeEvent,\n DocumentOrderChangeEvent,\n LoadDocumentUrlOptions,\n LoadDocumentBufferOptions,\n RetryOptions,\n DocumentErrorEvent,\n OpenDocumentResponse,\n OpenFileDialogOptions,\n} from './types';\n\nexport class DocumentManagerPlugin extends BasePlugin<\n DocumentManagerPluginConfig,\n DocumentManagerCapability\n> {\n static readonly id = 'document-manager' as const;\n\n private readonly documentOpened$ = createBehaviorEmitter<DocumentState>();\n private readonly documentClosed$ = createBehaviorEmitter<string>();\n private readonly activeDocumentChanged$ = createBehaviorEmitter<DocumentChangeEvent>();\n private readonly documentError$ = createBehaviorEmitter<DocumentErrorEvent>();\n\n private readonly documentOrderChanged$ = createBehaviorEmitter<DocumentOrderChangeEvent>();\n\n private readonly openFileRequest$ = createEmitter<{\n task: Task<OpenDocumentResponse, PdfErrorReason>;\n options?: OpenFileDialogOptions;\n }>();\n\n private maxDocuments?: number;\n\n private loadOptions = new Map<string, LoadDocumentUrlOptions | LoadDocumentBufferOptions>();\n\n constructor(\n public readonly id: string,\n registry: PluginRegistry,\n config?: DocumentManagerPluginConfig,\n ) {\n super(id, registry);\n this.maxDocuments = config?.maxDocuments;\n }\n\n protected buildCapability(): DocumentManagerCapability {\n return {\n // Document lifecycle - orchestration only\n openFileDialog: (options) => this.openFileDialog(options),\n openDocumentUrl: (options) => this.openDocumentUrl(options),\n openDocumentBuffer: (options) => this.openDocumentBuffer(options),\n retryDocument: (documentId, options) => this.retryDocument(documentId, options),\n closeDocument: (documentId) => this.closeDocument(documentId),\n closeAllDocuments: () => this.closeAllDocuments(),\n\n setActiveDocument: (documentId) => {\n if (!this.isDocumentOpen(documentId)) {\n throw new Error(`Cannot set active document: ${documentId} is not open`);\n }\n this.dispatchCoreAction(setActiveDocumentAction(documentId));\n },\n\n getActiveDocumentId: () => this.coreState.core.activeDocumentId,\n getActiveDocument: () => {\n const activeId = this.coreState.core.activeDocumentId;\n if (!activeId) return null;\n return this.coreState.core.documents[activeId]?.document ?? null;\n },\n\n getDocumentOrder: () => this.coreState.core.documentOrder,\n\n moveDocument: (documentId, toIndex) => {\n this.dispatchCoreAction(moveDocumentAction(documentId, toIndex));\n },\n\n swapDocuments: (id1, id2) => {\n const order = this.coreState.core.documentOrder;\n const index1 = order.indexOf(id1);\n const index2 = order.indexOf(id2);\n\n if (index1 === -1 || index2 === -1) {\n throw new Error('One or both documents not found in order');\n }\n\n const newOrder = [...order];\n [newOrder[index1], newOrder[index2]] = [newOrder[index2], newOrder[index1]];\n\n this.dispatchCoreAction(reorderDocumentsAction(newOrder));\n },\n\n getDocument: (documentId) => {\n return this.coreState.core.documents[documentId]?.document ?? null;\n },\n\n getDocumentState: (documentId) => {\n return this.coreState.core.documents[documentId] ?? null;\n },\n\n getOpenDocuments: () => {\n return this.coreState.core.documentOrder\n .map((documentId) => this.coreState.core.documents[documentId])\n .filter((state): state is DocumentState => state !== null);\n },\n\n isDocumentOpen: (documentId) => this.isDocumentOpen(documentId),\n\n getDocumentCount: () => {\n return Object.keys(this.coreState.core.documents).length;\n },\n\n getDocumentIndex: (documentId) => {\n return this.coreState.core.documentOrder.indexOf(documentId);\n },\n\n // Events\n onDocumentOpened: this.documentOpened$.on,\n onDocumentClosed: this.documentClosed$.on,\n onDocumentError: this.documentError$.on,\n onActiveDocumentChanged: this.activeDocumentChanged$.on,\n onDocumentOrderChanged: this.documentOrderChanged$.on,\n };\n }\n\n /**\n * Check if a document is currently open\n */\n private isDocumentOpen(documentId: string): boolean {\n return !!this.coreState.core.documents[documentId];\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Lifecycle Hooks (from BasePlugin)\n // ─────────────────────────────────────────────────────────\n\n protected override onDocumentLoaded(documentId: string): void {\n const docState = this.coreState.core.documents[documentId];\n if (!docState || docState.status !== 'loaded') return;\n\n // Clean up load options to free memory\n this.loadOptions.delete(documentId);\n\n // Emit opened event\n this.documentOpened$.emit(docState);\n\n this.logger.info(\n 'DocumentManagerPlugin',\n 'DocumentOpened',\n `Document ${documentId} opened successfully`,\n { name: docState.name },\n );\n }\n\n protected override onDocumentClosed(documentId: string): void {\n // Clean up load options\n this.loadOptions.delete(documentId);\n\n // Emit closed event\n this.documentClosed$.emit(documentId);\n\n this.logger.info('DocumentManagerPlugin', 'DocumentClosed', `Document ${documentId} closed`);\n }\n\n protected override onActiveDocumentChanged(\n previousId: string | null,\n currentId: string | null,\n ): void {\n this.activeDocumentChanged$.emit({\n previousDocumentId: previousId,\n currentDocumentId: currentId,\n });\n\n this.logger.info(\n 'DocumentManagerPlugin',\n 'ActiveDocumentChanged',\n `Active document changed from ${previousId} to ${currentId}`,\n );\n }\n\n protected override onCoreStoreUpdated(oldState: any, newState: any): void {\n // Emit order change event if order changed\n if (oldState.core.documentOrder !== newState.core.documentOrder) {\n this.documentOrderChanged$.emit({\n order: newState.core.documentOrder,\n });\n }\n }\n\n public onOpenFileRequest(\n handler: Listener<{\n task: Task<OpenDocumentResponse, PdfErrorReason>;\n options?: OpenFileDialogOptions;\n }>,\n ): Unsubscribe {\n return this.openFileRequest$.on(handler);\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Loading (orchestration only - no state management)\n // ─────────────────────────────────────────────────────────\n\n private openDocumentUrl(\n options: LoadDocumentUrlOptions,\n ): Task<OpenDocumentResponse, PdfErrorReason> {\n const task = new Task<OpenDocumentResponse, PdfErrorReason>();\n\n const documentId = options.documentId || this.generateDocumentId();\n\n // Check limit\n const limitError = this.checkDocumentLimit();\n if (limitError) {\n task.reject(limitError);\n return task;\n }\n\n const documentName = this.extractNameFromUrl(options.url);\n\n // Store options for potential retry\n this.loadOptions.set(documentId, options);\n\n this.dispatchCoreAction(\n startLoadingDocument(\n documentId,\n documentName,\n options.scale,\n options.rotation,\n !!options.password,\n options.autoActivate,\n ),\n );\n\n this.logger.info(\n 'DocumentManagerPlugin',\n 'OpenDocumentUrl',\n `Starting to load document from URL: ${options.url}`,\n { documentId, passwordProvided: !!options.password },\n );\n\n // Create file object and call engine\n const file: PdfFileUrl = {\n id: documentId,\n url: options.url,\n };\n const engineTask = this.engine.openDocumentUrl(file, {\n password: options.password,\n mode: options.mode,\n requestOptions: options.requestOptions,\n });\n\n task.resolve({\n documentId,\n task: engineTask,\n });\n\n // Handle result\n this.handleLoadTask(documentId, engineTask, 'OpenDocumentUrl');\n\n return task;\n }\n\n private openDocumentBuffer(\n options: LoadDocumentBufferOptions,\n ): Task<OpenDocumentResponse, PdfErrorReason> {\n const task = new Task<OpenDocumentResponse, PdfErrorReason>();\n\n const limitError = this.checkDocumentLimit();\n if (limitError) {\n task.reject(limitError);\n return task;\n }\n\n const documentId = options.documentId || this.generateDocumentId();\n\n // Store options for potential retry\n this.loadOptions.set(documentId, options);\n\n this.dispatchCoreAction(\n startLoadingDocument(\n documentId,\n options.name,\n options.scale,\n options.rotation,\n !!options.password,\n options.autoActivate,\n ),\n );\n\n this.logger.info(\n 'DocumentManagerPlugin',\n 'OpenDocumentBuffer',\n `Starting to load document from buffer: ${options.name}`,\n { documentId, passwordProvided: !!options.password },\n );\n\n // Create file object and call engine\n const file: PdfFile = {\n id: documentId,\n content: options.buffer,\n };\n const engineTask = this.engine.openDocumentBuffer(file, {\n password: options.password,\n });\n\n task.resolve({\n documentId,\n task: engineTask,\n });\n\n // Handle result\n this.handleLoadTask(documentId, engineTask, 'OpenDocumentBuffer');\n\n return task;\n }\n\n private retryDocument(\n documentId: string,\n retryOptions?: RetryOptions,\n ): Task<OpenDocumentResponse, PdfErrorReason> {\n const task = new Task<OpenDocumentResponse, PdfErrorReason>();\n\n // Validate retry\n const validation = this.validateRetry(documentId);\n if (!validation.valid) {\n task.reject(validation.error!);\n return task;\n }\n\n const originalOptions = this.loadOptions.get(documentId)!;\n\n // Merge retry options (e.g., new password)\n const mergedOptions = {\n ...originalOptions,\n ...(retryOptions?.password && { password: retryOptions.password }),\n };\n\n // Update stored options\n this.loadOptions.set(documentId, mergedOptions);\n\n // Set back to loading state\n this.dispatchCoreAction(retryLoadingDocument(documentId, !!retryOptions?.password));\n\n this.logger.info(\n 'DocumentManagerPlugin',\n 'RetryDocument',\n `Retrying to load document ${documentId}`,\n { passwordProvided: !!retryOptions?.password },\n );\n\n // Execute retry based on type\n const engineTask =\n 'url' in mergedOptions\n ? this.retryUrlDocument(documentId, mergedOptions)\n : this.retryBufferDocument(documentId, mergedOptions);\n\n task.resolve({\n documentId,\n task: engineTask,\n });\n\n // Handle result\n this.handleLoadTask(documentId, engineTask, 'RetryDocument');\n\n return task;\n }\n\n private openFileDialog(\n options?: OpenFileDialogOptions,\n ): Task<OpenDocumentResponse, PdfErrorReason> {\n const task = new Task<OpenDocumentResponse, PdfErrorReason>();\n this.openFileRequest$.emit({ task, options });\n return task;\n }\n\n private closeDocument(documentId: string): Task<void, PdfErrorReason> {\n const task = new Task<void, PdfErrorReason>();\n\n const docState = this.coreState.core.documents[documentId];\n if (!docState) {\n this.logger.warn(\n 'DocumentManagerPlugin',\n 'CloseDocument',\n `Cannot close document ${documentId}: not found in state`,\n );\n task.resolve();\n return task;\n }\n\n // ✅ SIMPLIFIED: Just dispatch - reducer calculates next active!\n if (docState.status === 'loaded' && docState.document) {\n this.engine.closeDocument(docState.document).wait(\n () => {\n this.dispatchCoreAction(closeDocumentAction(documentId));\n task.resolve();\n },\n (error) => {\n this.logger.error(\n 'DocumentManagerPlugin',\n 'CloseDocument',\n `Failed to close document ${documentId}`,\n error,\n );\n task.fail(error);\n },\n );\n } else {\n // Document is not loaded (error, loading, etc.), just clean up state\n this.logger.info(\n 'DocumentManagerPlugin',\n 'CloseDocument',\n `Closing document ${documentId} in ${docState.status} state (skipping engine close)`,\n );\n this.dispatchCoreAction(closeDocumentAction(documentId));\n task.resolve();\n }\n\n return task;\n }\n\n private closeAllDocuments(): Task<void[], PdfErrorReason> {\n const documentIds = Object.keys(this.coreState.core.documents);\n const tasks = documentIds.map((documentId) => this.closeDocument(documentId));\n\n this.logger.info(\n 'DocumentManagerPlugin',\n 'CloseAllDocuments',\n `Closing ${documentIds.length} documents`,\n );\n\n return Task.all(tasks);\n }\n\n // ─────────────────────────────────────────────────────────\n // Helper Methods\n // ─────────────────────────────────────────────────────────\n\n private checkDocumentLimit(): PdfErrorReason | null {\n if (\n this.maxDocuments &&\n Object.keys(this.coreState.core.documents).length >= this.maxDocuments\n ) {\n return {\n code: PdfErrorCode.Unknown,\n message: `Maximum number of documents (${this.maxDocuments}) reached`,\n };\n }\n return null;\n }\n\n private validateRetry(documentId: string): {\n valid: boolean;\n error?: PdfErrorReason;\n } {\n const docState = this.coreState.core.documents[documentId];\n\n if (!docState) {\n return {\n valid: false,\n error: {\n code: PdfErrorCode.NotFound,\n message: `Document ${documentId} not found`,\n },\n };\n }\n\n if (docState.status === 'loaded') {\n return {\n valid: false,\n error: {\n code: PdfErrorCode.Unknown,\n message: `Document ${documentId} is already loaded successfully`,\n },\n };\n }\n\n if (docState.status !== 'error') {\n return {\n valid: false,\n error: {\n code: PdfErrorCode.Unknown,\n message: `Document ${documentId} is not in error state (current state: ${docState.status})`,\n },\n };\n }\n\n if (!this.loadOptions.has(documentId)) {\n return {\n valid: false,\n error: {\n code: PdfErrorCode.Unknown,\n message: `No retry information available for document ${documentId}`,\n },\n };\n }\n\n return { valid: true };\n }\n\n private retryUrlDocument(\n documentId: string,\n options: LoadDocumentUrlOptions,\n ): Task<PdfDocumentObject, PdfErrorReason> {\n const file: PdfFileUrl = {\n id: documentId,\n url: options.url,\n };\n\n return this.engine.openDocumentUrl(file, {\n password: options.password,\n mode: options.mode,\n requestOptions: options.requestOptions,\n });\n }\n\n private retryBufferDocument(\n documentId: string,\n options: LoadDocumentBufferOptions,\n ): Task<PdfDocumentObject, PdfErrorReason> {\n const file: PdfFile = {\n id: documentId,\n content: options.buffer,\n };\n\n return this.engine.openDocumentBuffer(file, {\n password: options.password,\n });\n }\n\n private handleLoadTask(\n documentId: string,\n engineTask: Task<PdfDocumentObject, PdfErrorReason>,\n context: string,\n ): void {\n engineTask.wait(\n (pdfDocument) => {\n this.dispatchCoreAction(setDocumentLoaded(documentId, pdfDocument));\n },\n (error) => {\n this.handleLoadError(documentId, error, context);\n },\n );\n }\n\n private handleLoadError(documentId: string, error: any, context: string): void {\n const errorMessage = error.reason?.message || 'Failed to load document';\n\n this.logger.error('DocumentManagerPlugin', context, 'Failed to load document', error);\n\n this.dispatchCoreAction(\n setDocumentError(documentId, errorMessage, error.reason?.code, error.reason),\n );\n\n this.documentError$.emit({\n documentId,\n message: errorMessage,\n code: error.reason?.code,\n reason: error.reason,\n });\n }\n\n private generateDocumentId(): string {\n return `doc-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n }\n\n private extractNameFromUrl(url: string): string {\n try {\n const urlObj = new URL(url);\n const pathname = urlObj.pathname;\n const filename = pathname.split('/').pop() || 'document.pdf';\n return decodeURIComponent(filename);\n } catch {\n return 'document.pdf';\n }\n }\n\n // ─────────────────────────────────────────────────────────\n // Plugin Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(config: DocumentManagerPluginConfig): Promise<void> {\n this.logger.info('DocumentManagerPlugin', 'Initialize', 'Document Manager Plugin initialized', {\n maxDocuments: this.maxDocuments,\n initialDocumentsCount: config.initialDocuments?.length ?? 0,\n });\n\n // Handle initial documents from config\n if (config.initialDocuments && config.initialDocuments.length > 0) {\n // Process strictly in order\n for (const docConfig of config.initialDocuments) {\n try {\n // Type guard to distinguish between URL and Buffer options\n if ('buffer' in docConfig) {\n this.openDocumentBuffer(docConfig);\n } else if ('url' in docConfig) {\n this.openDocumentUrl(docConfig);\n }\n } catch (error) {\n this.logger.error(\n 'DocumentManagerPlugin',\n 'Initialize',\n 'Failed to initiate initial document load',\n error,\n );\n }\n }\n }\n }\n\n async destroy(): Promise<void> {\n // Close all documents\n await this.closeAllDocuments().toPromise();\n\n // Clear load options\n this.loadOptions.clear();\n\n // Clear emitters\n this.documentOpened$.clear();\n this.documentClosed$.clear();\n this.activeDocumentChanged$.clear();\n this.documentOrderChanged$.clear();\n this.documentError$.clear();\n\n super.destroy();\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { DocumentManagerPluginConfig } from './types';\n\nexport const DOCUMENT_MANAGER_PLUGIN_ID = 'document-manager';\n\nexport const manifest: PluginManifest<DocumentManagerPluginConfig> = {\n id: DOCUMENT_MANAGER_PLUGIN_ID,\n name: 'Document Manager Plugin',\n version: '1.0.0',\n provides: ['document-manager'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n maxDocuments: 10,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { DocumentManagerPlugin } from './document-manager-plugin';\nimport { manifest, DOCUMENT_MANAGER_PLUGIN_ID } from './manifest';\nimport { DocumentManagerPluginConfig } from './types';\n\nexport const DocumentManagerPluginPackage: PluginPackage<\n DocumentManagerPlugin,\n DocumentManagerPluginConfig\n> = {\n manifest,\n create: (registry, config) =>\n new DocumentManagerPlugin(DOCUMENT_MANAGER_PLUGIN_ID, registry, config),\n reducer: (state) => state,\n initialState: {},\n};\n\nexport * from './document-manager-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["setActiveDocumentAction","moveDocumentAction","reorderDocumentsAction","closeDocumentAction"],"mappings":";;AAuCO,MAAM,yBAAN,MAAM,+BAA8B,WAGzC;AAAA,EAmBA,YACkB,IAChB,UACA,QACA;AACA,UAAM,IAAI,QAAQ;AAJF,SAAA,KAAA;AAjBlB,SAAiB,kBAAkB,sBAAA;AACnC,SAAiB,kBAAkB,sBAAA;AACnC,SAAiB,yBAAyB,sBAAA;AAC1C,SAAiB,iBAAiB,sBAAA;AAElC,SAAiB,wBAAwB,sBAAA;AAEzC,SAAiB,mBAAmB,cAAA;AAOpC,SAAQ,kCAAkB,IAAA;AAQxB,SAAK,eAAe,iCAAQ;AAAA,EAC9B;AAAA,EAEU,kBAA6C;AACrD,WAAO;AAAA;AAAA,MAEL,gBAAgB,CAAC,YAAY,KAAK,eAAe,OAAO;AAAA,MACx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AA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,UAAyB;AAE7B,UAAM,KAAK,kBAAA,EAAoB,UAAA;AAG/B,SAAK,YAAY,MAAA;AAGjB,SAAK,gBAAgB,MAAA;AACrB,SAAK,gBAAgB,MAAA;AACrB,SAAK,uBAAuB,MAAA;AAC5B,SAAK,sBAAsB,MAAA;AAC3B,SAAK,eAAe,MAAA;AAEpB,UAAM,QAAA;AAAA,EACR;AACF;AA5lBE,uBAAgB,KAAK;AAJhB,IAAM,wBAAN;ACpCA,MAAM,6BAA6B;AAEnC,MAAM,WAAwD;AAAA,EACnE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,kBAAkB;AAAA,EAC7B,UAAU,CAAA;AAAA,EACV,UAAU,CAAA;AAAA,EACV,eAAe;AAAA,IACb,SAAS;AAAA,IACT,cAAc;AAAA,EAAA;AAElB;ACXO,MAAM,+BAGT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,WACjB,IAAI,sBAAsB,4BAA4B,UAAU,MAAM;AAAA,EACxE,SAAS,CAAC,UAAU;AAAA,EACpB,cAAc,CAAA;AAChB;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BasePlugin, PluginRegistry, Unsubscribe, Listener } from '@embedpdf/core';
|
|
2
|
+
import { Task, PdfErrorReason } from '@embedpdf/models';
|
|
3
|
+
import { DocumentManagerPluginConfig, DocumentManagerCapability, OpenDocumentResponse, OpenFileDialogOptions } from './types';
|
|
4
|
+
export declare class DocumentManagerPlugin extends BasePlugin<DocumentManagerPluginConfig, DocumentManagerCapability> {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
static readonly id: "document-manager";
|
|
7
|
+
private readonly documentOpened$;
|
|
8
|
+
private readonly documentClosed$;
|
|
9
|
+
private readonly activeDocumentChanged$;
|
|
10
|
+
private readonly documentError$;
|
|
11
|
+
private readonly documentOrderChanged$;
|
|
12
|
+
private readonly openFileRequest$;
|
|
13
|
+
private maxDocuments?;
|
|
14
|
+
private loadOptions;
|
|
15
|
+
constructor(id: string, registry: PluginRegistry, config?: DocumentManagerPluginConfig);
|
|
16
|
+
protected buildCapability(): DocumentManagerCapability;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a document is currently open
|
|
19
|
+
*/
|
|
20
|
+
private isDocumentOpen;
|
|
21
|
+
protected onDocumentLoaded(documentId: string): void;
|
|
22
|
+
protected onDocumentClosed(documentId: string): void;
|
|
23
|
+
protected onActiveDocumentChanged(previousId: string | null, currentId: string | null): void;
|
|
24
|
+
protected onCoreStoreUpdated(oldState: any, newState: any): void;
|
|
25
|
+
onOpenFileRequest(handler: Listener<{
|
|
26
|
+
task: Task<OpenDocumentResponse, PdfErrorReason>;
|
|
27
|
+
options?: OpenFileDialogOptions;
|
|
28
|
+
}>): Unsubscribe;
|
|
29
|
+
private openDocumentUrl;
|
|
30
|
+
private openDocumentBuffer;
|
|
31
|
+
private retryDocument;
|
|
32
|
+
private openFileDialog;
|
|
33
|
+
private closeDocument;
|
|
34
|
+
private closeAllDocuments;
|
|
35
|
+
private checkDocumentLimit;
|
|
36
|
+
private validateRetry;
|
|
37
|
+
private retryUrlDocument;
|
|
38
|
+
private retryBufferDocument;
|
|
39
|
+
private handleLoadTask;
|
|
40
|
+
private handleLoadError;
|
|
41
|
+
private generateDocumentId;
|
|
42
|
+
private extractNameFromUrl;
|
|
43
|
+
initialize(config: DocumentManagerPluginConfig): Promise<void>;
|
|
44
|
+
destroy(): Promise<void>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PluginPackage } from '@embedpdf/core';
|
|
2
|
+
import { DocumentManagerPlugin } from './document-manager-plugin';
|
|
3
|
+
import { DocumentManagerPluginConfig } from './types';
|
|
4
|
+
export declare const DocumentManagerPluginPackage: PluginPackage<DocumentManagerPlugin, DocumentManagerPluginConfig>;
|
|
5
|
+
export * from './document-manager-plugin';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './manifest';
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook, DocumentState } from '@embedpdf/core';
|
|
2
|
+
import { PdfDocumentObject, Rotation, Task, PdfErrorReason, PdfRequestOptions } from '@embedpdf/models';
|
|
3
|
+
export type InitialDocumentOptions = LoadDocumentUrlOptions | LoadDocumentBufferOptions;
|
|
4
|
+
export interface DocumentManagerPluginConfig extends BasePluginConfig {
|
|
5
|
+
maxDocuments?: number;
|
|
6
|
+
initialDocuments?: InitialDocumentOptions[];
|
|
7
|
+
}
|
|
8
|
+
export interface DocumentChangeEvent {
|
|
9
|
+
previousDocumentId: string | null;
|
|
10
|
+
currentDocumentId: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface DocumentOrderChangeEvent {
|
|
13
|
+
order: string[];
|
|
14
|
+
movedDocumentId?: string;
|
|
15
|
+
fromIndex?: number;
|
|
16
|
+
toIndex?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface DocumentErrorEvent {
|
|
19
|
+
documentId: string;
|
|
20
|
+
message: string;
|
|
21
|
+
code?: number;
|
|
22
|
+
reason?: PdfErrorReason;
|
|
23
|
+
}
|
|
24
|
+
export interface LoadDocumentUrlOptions {
|
|
25
|
+
url: string;
|
|
26
|
+
documentId?: string;
|
|
27
|
+
password?: string;
|
|
28
|
+
mode?: 'auto' | 'range-request' | 'full-fetch';
|
|
29
|
+
requestOptions?: PdfRequestOptions;
|
|
30
|
+
scale?: number;
|
|
31
|
+
rotation?: Rotation;
|
|
32
|
+
autoActivate?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface LoadDocumentBufferOptions {
|
|
35
|
+
buffer: ArrayBuffer;
|
|
36
|
+
name: string;
|
|
37
|
+
documentId?: string;
|
|
38
|
+
password?: string;
|
|
39
|
+
scale?: number;
|
|
40
|
+
rotation?: Rotation;
|
|
41
|
+
autoActivate?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface RetryOptions {
|
|
44
|
+
password?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface OpenFileDialogOptions {
|
|
47
|
+
documentId?: string;
|
|
48
|
+
scale?: number;
|
|
49
|
+
rotation?: Rotation;
|
|
50
|
+
autoActivate?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface OpenDocumentResponse {
|
|
53
|
+
documentId: string;
|
|
54
|
+
task: Task<PdfDocumentObject, PdfErrorReason>;
|
|
55
|
+
}
|
|
56
|
+
export interface DocumentManagerCapability {
|
|
57
|
+
openFileDialog: (options?: OpenFileDialogOptions) => Task<OpenDocumentResponse, PdfErrorReason>;
|
|
58
|
+
openDocumentUrl(options: LoadDocumentUrlOptions): Task<OpenDocumentResponse, PdfErrorReason>;
|
|
59
|
+
openDocumentBuffer(options: LoadDocumentBufferOptions): Task<OpenDocumentResponse, PdfErrorReason>;
|
|
60
|
+
retryDocument(documentId: string, options?: RetryOptions): Task<OpenDocumentResponse, PdfErrorReason>;
|
|
61
|
+
closeDocument(documentId: string): Task<void, PdfErrorReason>;
|
|
62
|
+
closeAllDocuments(): Task<void[], PdfErrorReason>;
|
|
63
|
+
setActiveDocument(documentId: string): void;
|
|
64
|
+
getActiveDocumentId(): string | null;
|
|
65
|
+
getActiveDocument(): PdfDocumentObject | null;
|
|
66
|
+
getDocumentOrder(): string[];
|
|
67
|
+
moveDocument(documentId: string, toIndex: number): void;
|
|
68
|
+
swapDocuments(documentId1: string, documentId2: string): void;
|
|
69
|
+
getDocument(documentId: string): PdfDocumentObject | null;
|
|
70
|
+
getDocumentState(documentId: string): DocumentState | null;
|
|
71
|
+
getOpenDocuments(): DocumentState[];
|
|
72
|
+
isDocumentOpen(documentId: string): boolean;
|
|
73
|
+
getDocumentCount(): number;
|
|
74
|
+
getDocumentIndex(documentId: string): number;
|
|
75
|
+
onDocumentOpened: EventHook<DocumentState>;
|
|
76
|
+
onDocumentClosed: EventHook<string>;
|
|
77
|
+
onDocumentError: EventHook<DocumentErrorEvent>;
|
|
78
|
+
onActiveDocumentChanged: EventHook<DocumentChangeEvent>;
|
|
79
|
+
onDocumentOrderChanged: EventHook<DocumentOrderChangeEvent>;
|
|
80
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Fragment } from 'preact';
|
|
2
|
+
export { useEffect, useRef, useState, useCallback, useMemo } from 'preact/hooks';
|
|
3
|
+
export type { ComponentChildren as ReactNode } from 'preact';
|
|
4
|
+
export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
|
|
5
|
+
export type ChangeEvent<T = Element> = import('preact').JSX.TargetedEvent<T extends EventTarget ? T : never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/preact';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-document-manager"),n=require("preact/jsx-runtime"),u=require("@embedpdf/core/preact");require("preact");const r=require("preact/hooks");const o=()=>u.usePlugin(t.DocumentManagerPlugin.id),c=()=>u.useCapability(t.DocumentManagerPlugin.id),a=()=>{const e=u.useCoreState();return r.useMemo(()=>{if(!e)return{activeDocumentId:null,activeDocument:null};const t=e.activeDocumentId;return{activeDocumentId:t,activeDocument:t?e.documents[t]??null:null}},[e])},l=e=>{const t=u.useCoreState();return r.useMemo(()=>t?e&&e.length>0?e.map(e=>t.documents[e]).filter(e=>null!=e):t.documentOrder.map(e=>t.documents[e]).filter(e=>null!=e):[],[t,e])};function i(){const{plugin:e}=o(),{provides:t}=c(),u=r.useRef(null),a=r.useRef(null),l=r.useRef(void 0);r.useEffect(()=>{if(!(null==e?void 0:e.onOpenFileRequest))return;return e.onOpenFileRequest(({task:e,options:t})=>{var n;a.current=e,l.current=t,null==(n=u.current)||n.click()})},[e]);return n.jsx("input",{ref:u,type:"file",accept:"application/pdf",style:{display:"none"},onChange:async e=>{var n,u,r,o,c;const i=null==(n=e.currentTarget.files)?void 0:n[0];if(!i||!t)return;const s=await i.arrayBuffer();t.openDocumentBuffer({name:i.name,buffer:s,documentId:null==(u=l.current)?void 0:u.documentId,scale:null==(r=l.current)?void 0:r.scale,rotation:null==(o=l.current)?void 0:o.rotation,autoActivate:null==(c=l.current)?void 0:c.autoActivate}).wait(e=>{var t;null==(t=a.current)||t.resolve(e)},e=>{var t;null==(t=a.current)||t.fail(e)})}})}const s=e.createPluginPackage(t.DocumentManagerPluginPackage).addUtility(i).build();exports.DocumentContent=function({documentId:e,children:t}){const r=u.useDocumentState(e);if(!r)return null;const o="loading"===r.status,c="error"===r.status,a="loaded"===r.status;return n.jsx(n.Fragment,{children:t({documentState:r,isLoading:o,isError:c,isLoaded:a})})},exports.DocumentContext=function({children:e}){const t=l(),{activeDocumentId:u}=a(),{provides:o}=c(),i={select:r.useCallback(e=>{null==o||o.setActiveDocument(e)},[o]),close:r.useCallback(e=>{null==o||o.closeDocument(e)},[o]),move:r.useCallback((e,t)=>{null==o||o.moveDocument(e,t)},[o])};return n.jsx(n.Fragment,{children:e({documentStates:t,activeDocumentId:u,actions:i})})},exports.DocumentManagerPluginPackage=s,exports.FilePicker=i,exports.useActiveDocument=a,exports.useDocumentManagerCapability=c,exports.useDocumentManagerPlugin=o,exports.useOpenDocuments=l,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-document-manager.ts","../../src/shared/components/file-picker.tsx","../../src/shared/index.ts","../../src/shared/components/document-content.tsx","../../src/shared/components/document-context.tsx"],"sourcesContent":["import { useMemo } from '@framework';\nimport { useCapability, useCoreState, usePlugin } from '@embedpdf/core/@framework';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport { DocumentState } from '@embedpdf/core';\n\nexport const useDocumentManagerPlugin = () =>\n usePlugin<DocumentManagerPlugin>(DocumentManagerPlugin.id);\nexport const useDocumentManagerCapability = () =>\n useCapability<DocumentManagerPlugin>(DocumentManagerPlugin.id);\n\n/**\n * Hook for active document state\n */\nexport const useActiveDocument = () => {\n const coreState = useCoreState();\n\n return useMemo(() => {\n if (!coreState) {\n return {\n activeDocumentId: null,\n activeDocument: null,\n };\n }\n\n const activeDocumentId = coreState.activeDocumentId;\n const activeDocument = activeDocumentId\n ? (coreState.documents[activeDocumentId] ?? null)\n : null;\n\n return {\n activeDocumentId,\n activeDocument,\n };\n }, [coreState]);\n};\n\n/**\n * Hook for all open documents (in order)\n */\nexport const useOpenDocuments = (documentIds?: string[]) => {\n const coreState = useCoreState();\n\n return useMemo(() => {\n if (!coreState) return [];\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds && documentIds.length > 0) {\n return documentIds\n .map((docId) => coreState.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return coreState.documentOrder\n .map((docId) => coreState.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }, [coreState, documentIds]);\n};\n","import { ChangeEvent, useEffect, useRef } from '@framework';\nimport { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\nimport { PdfErrorReason, Task } from '@embedpdf/models';\nimport { OpenDocumentResponse, OpenFileDialogOptions } from '@embedpdf/plugin-document-manager';\n\nexport function FilePicker() {\n const { plugin } = useDocumentManagerPlugin();\n const { provides } = useDocumentManagerCapability();\n const inputRef = useRef<HTMLInputElement>(null);\n const taskRef = useRef<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\n const optionsRef = useRef<OpenFileDialogOptions | undefined>(undefined);\n\n useEffect(() => {\n if (!plugin?.onOpenFileRequest) return;\n const unsub = plugin.onOpenFileRequest(({ task, options }) => {\n taskRef.current = task;\n optionsRef.current = options;\n inputRef.current?.click();\n });\n return unsub;\n }, [plugin]);\n\n const onChange = async (e: ChangeEvent<HTMLInputElement>) => {\n const file = (e.currentTarget as HTMLInputElement).files?.[0];\n if (!file || !provides) return;\n const buffer = await file.arrayBuffer();\n const openTask = provides.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef.current?.documentId,\n scale: optionsRef.current?.scale,\n rotation: optionsRef.current?.rotation,\n autoActivate: optionsRef.current?.autoActivate,\n });\n openTask.wait(\n (result) => {\n taskRef.current?.resolve(result);\n },\n (error) => {\n taskRef.current?.fail(error);\n },\n );\n };\n\n return (\n <input\n ref={inputRef}\n type=\"file\"\n accept=\"application/pdf\"\n style={{ display: 'none' }}\n onChange={onChange}\n />\n );\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { DocumentManagerPluginPackage as BaseDocumentManagerPackage } from '@embedpdf/plugin-document-manager';\nimport { FilePicker } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-document-manager';\n\n// A convenience package that auto-registers our utilities\nexport const DocumentManagerPluginPackage = createPluginPackage(BaseDocumentManagerPackage)\n .addUtility(FilePicker) // headless utility consumers can mount once and call cap.openFileDialog()\n .build();\n","import { ReactNode } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { DocumentState } from '@embedpdf/core';\n\nexport interface DocumentContentRenderProps {\n documentState: DocumentState;\n isLoading: boolean;\n isError: boolean;\n isLoaded: boolean;\n}\n\ninterface DocumentContentProps {\n documentId: string | null;\n children: (props: DocumentContentRenderProps) => ReactNode;\n}\n\n/**\n * Headless component for rendering document content with loading/error states\n *\n * @example\n * <DocumentContent documentId={activeDocumentId}>\n * {({ document, isLoading, isError, isLoaded }) => {\n * if (isLoading) return <LoadingSpinner />;\n * if (isError) return <ErrorMessage />;\n * if (isLoaded) return <PDFViewer document={document} />;\n * return null;\n * }}\n * </DocumentContent>\n */\nexport function DocumentContent({ documentId, children }: DocumentContentProps) {\n const documentState = useDocumentState(documentId);\n\n if (!documentState) return null;\n\n const isLoading = documentState.status === 'loading';\n const isError = documentState.status === 'error';\n const isLoaded = documentState.status === 'loaded';\n\n return <>{children({ documentState, isLoading, isError, isLoaded })}</>;\n}\n","import { ReactNode, useCallback } from '@framework';\nimport { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\nimport { DocumentState } from '@embedpdf/core';\n\nexport interface TabActions {\n select: (documentId: string) => void;\n close: (documentId: string) => void;\n move: (documentId: string, toIndex: number) => void;\n}\n\nexport interface DocumentContextRenderProps {\n documentStates: DocumentState[];\n activeDocumentId: string | null;\n actions: TabActions;\n}\n\ninterface DocumentContextProps {\n children: (props: DocumentContextRenderProps) => ReactNode;\n}\n\n/**\n * Headless component for managing document tabs\n * Provides all state and actions, completely UI-agnostic\n *\n * @example\n * <DocumentContext>\n * {({ documents, activeDocumentId, actions }) => (\n * <div className=\"tabs\">\n * {documents.map((doc) => (\n * <button\n * key={doc.id}\n * onClick={() => actions.select(doc.id)}\n * className={doc.id === activeDocumentId ? 'active' : ''}\n * >\n * {doc.name}\n * <button onClick={(e) => {\n * e.stopPropagation();\n * actions.close(doc.id);\n * }}>×</button>\n * </button>\n * ))}\n * </div>\n * )}\n * </DocumentContext>\n */\nexport function DocumentContext({ children }: DocumentContextProps) {\n const documentStates = useOpenDocuments();\n const { activeDocumentId } = useActiveDocument();\n const { provides } = useDocumentManagerCapability();\n\n const select = useCallback(\n (documentId: string) => {\n provides?.setActiveDocument(documentId);\n },\n [provides],\n );\n\n const close = useCallback(\n (documentId: string) => {\n provides?.closeDocument(documentId);\n },\n [provides],\n );\n\n const move = useCallback(\n (documentId: string, toIndex: number) => {\n provides?.moveDocument(documentId, toIndex);\n },\n [provides],\n );\n\n const actions: TabActions = {\n select,\n close,\n move,\n };\n\n return <>{children({ documentStates, activeDocumentId, actions })}</>;\n}\n"],"names":["useDocumentManagerPlugin","usePlugin","DocumentManagerPlugin","id","useDocumentManagerCapability","useCapability","useActiveDocument","coreState","useCoreState","useMemo","activeDocumentId","activeDocument","documents","useOpenDocuments","documentIds","length","map","docId","filter","doc","documentOrder","FilePicker","plugin","provides","inputRef","useRef","taskRef","optionsRef","useEffect","onOpenFileRequest","task","options","current","_a","click","jsx","ref","type","accept","style","display","onChange","async","e","file","currentTarget","files","buffer","arrayBuffer","openDocumentBuffer","name","documentId","_b","scale","_c","rotation","_d","autoActivate","_e","wait","result","resolve","error","fail","DocumentManagerPluginPackage","createPluginPackage","BaseDocumentManagerPackage","addUtility","build","children","documentState","useDocumentState","isLoading","status","isError","isLoaded","Fragment","documentStates","actions","select","useCallback","setActiveDocument","close","closeDocument","move","toIndex","moveDocument"],"mappings":"sRAKO,MAAMA,EAA2B,IACtCC,YAAiCC,EAAAA,sBAAsBC,IAC5CC,EAA+B,IAC1CC,gBAAqCH,EAAAA,sBAAsBC,IAKhDG,EAAoB,KAC/B,MAAMC,EAAYC,EAAAA,eAElB,OAAOC,EAAAA,QAAQ,KACb,IAAKF,EACH,MAAO,CACLG,iBAAkB,KAClBC,eAAgB,MAIpB,MAAMD,EAAmBH,EAAUG,iBAKnC,MAAO,CACLA,mBACAC,eANqBD,EAClBH,EAAUK,UAAUF,IAAqB,KAC1C,OAMH,CAACH,KAMOM,EAAoBC,IAC/B,MAAMP,EAAYC,EAAAA,eAElB,OAAOC,EAAAA,QAAQ,IACRF,EAGDO,GAAeA,EAAYC,OAAS,EAC/BD,EACJE,IAAKC,GAAUV,EAAUK,UAAUK,IACnCC,OAAQC,GAA8BA,SAIpCZ,EAAUa,cACdJ,IAAKC,GAAUV,EAAUK,UAAUK,IACnCC,OAAQC,GAA8BA,SAZlB,GAatB,CAACZ,EAAWO,KCnDV,SAASO,IACd,MAAMC,OAAEA,GAAWtB,KACbuB,SAAEA,GAAanB,IACfoB,EAAWC,EAAAA,OAAyB,MACpCC,EAAUD,EAAAA,OAA0D,MACpEE,EAAaF,EAAAA,YAA0C,GAE7DG,EAAAA,UAAU,KACR,WAAKN,WAAQO,mBAAmB,OAMhC,OALcP,EAAOO,kBAAkB,EAAGC,OAAMC,o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,IAuBf0E,EAAsB,CAC1BC,OAtBaC,EAAAA,YACZ7B,IACC,MAAA5B,GAAAA,EAAU0D,kBAAkB9B,IAE9B,CAAC5B,IAmBD2D,MAhBYF,EAAAA,YACX7B,IACC,MAAA5B,GAAAA,EAAU4D,cAAchC,IAE1B,CAAC5B,IAaD6D,KAVWJ,EAAAA,YACX,CAAC7B,EAAoBkC,KACnB,MAAA9D,GAAAA,EAAU+D,aAAanC,EAAYkC,IAErC,CAAC9D,KASH,yBAAU8C,SAAAA,EAAS,CAAEQ,iBAAgBnE,mBAAkBoE,aACzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../shared-preact';
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createPluginPackage } from "@embedpdf/core";
|
|
2
|
+
import { DocumentManagerPlugin, DocumentManagerPluginPackage as DocumentManagerPluginPackage$1 } from "@embedpdf/plugin-document-manager";
|
|
3
|
+
export * from "@embedpdf/plugin-document-manager";
|
|
4
|
+
import { jsx, Fragment } from "preact/jsx-runtime";
|
|
5
|
+
import { useDocumentState, usePlugin, useCapability, useCoreState } from "@embedpdf/core/preact";
|
|
6
|
+
import "preact";
|
|
7
|
+
import { useMemo, useCallback, useRef, useEffect } from "preact/hooks";
|
|
8
|
+
function DocumentContent({ documentId, children }) {
|
|
9
|
+
const documentState = useDocumentState(documentId);
|
|
10
|
+
if (!documentState) return null;
|
|
11
|
+
const isLoading = documentState.status === "loading";
|
|
12
|
+
const isError = documentState.status === "error";
|
|
13
|
+
const isLoaded = documentState.status === "loaded";
|
|
14
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children({ documentState, isLoading, isError, isLoaded }) });
|
|
15
|
+
}
|
|
16
|
+
const useDocumentManagerPlugin = () => usePlugin(DocumentManagerPlugin.id);
|
|
17
|
+
const useDocumentManagerCapability = () => useCapability(DocumentManagerPlugin.id);
|
|
18
|
+
const useActiveDocument = () => {
|
|
19
|
+
const coreState = useCoreState();
|
|
20
|
+
return useMemo(() => {
|
|
21
|
+
if (!coreState) {
|
|
22
|
+
return {
|
|
23
|
+
activeDocumentId: null,
|
|
24
|
+
activeDocument: null
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const activeDocumentId = coreState.activeDocumentId;
|
|
28
|
+
const activeDocument = activeDocumentId ? coreState.documents[activeDocumentId] ?? null : null;
|
|
29
|
+
return {
|
|
30
|
+
activeDocumentId,
|
|
31
|
+
activeDocument
|
|
32
|
+
};
|
|
33
|
+
}, [coreState]);
|
|
34
|
+
};
|
|
35
|
+
const useOpenDocuments = (documentIds) => {
|
|
36
|
+
const coreState = useCoreState();
|
|
37
|
+
return useMemo(() => {
|
|
38
|
+
if (!coreState) return [];
|
|
39
|
+
if (documentIds && documentIds.length > 0) {
|
|
40
|
+
return documentIds.map((docId) => coreState.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
|
|
41
|
+
}
|
|
42
|
+
return coreState.documentOrder.map((docId) => coreState.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
|
|
43
|
+
}, [coreState, documentIds]);
|
|
44
|
+
};
|
|
45
|
+
function DocumentContext({ children }) {
|
|
46
|
+
const documentStates = useOpenDocuments();
|
|
47
|
+
const { activeDocumentId } = useActiveDocument();
|
|
48
|
+
const { provides } = useDocumentManagerCapability();
|
|
49
|
+
const select = useCallback(
|
|
50
|
+
(documentId) => {
|
|
51
|
+
provides == null ? void 0 : provides.setActiveDocument(documentId);
|
|
52
|
+
},
|
|
53
|
+
[provides]
|
|
54
|
+
);
|
|
55
|
+
const close = useCallback(
|
|
56
|
+
(documentId) => {
|
|
57
|
+
provides == null ? void 0 : provides.closeDocument(documentId);
|
|
58
|
+
},
|
|
59
|
+
[provides]
|
|
60
|
+
);
|
|
61
|
+
const move = useCallback(
|
|
62
|
+
(documentId, toIndex) => {
|
|
63
|
+
provides == null ? void 0 : provides.moveDocument(documentId, toIndex);
|
|
64
|
+
},
|
|
65
|
+
[provides]
|
|
66
|
+
);
|
|
67
|
+
const actions = {
|
|
68
|
+
select,
|
|
69
|
+
close,
|
|
70
|
+
move
|
|
71
|
+
};
|
|
72
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children({ documentStates, activeDocumentId, actions }) });
|
|
73
|
+
}
|
|
74
|
+
function FilePicker() {
|
|
75
|
+
const { plugin } = useDocumentManagerPlugin();
|
|
76
|
+
const { provides } = useDocumentManagerCapability();
|
|
77
|
+
const inputRef = useRef(null);
|
|
78
|
+
const taskRef = useRef(null);
|
|
79
|
+
const optionsRef = useRef(void 0);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!(plugin == null ? void 0 : plugin.onOpenFileRequest)) return;
|
|
82
|
+
const unsub = plugin.onOpenFileRequest(({ task, options }) => {
|
|
83
|
+
var _a;
|
|
84
|
+
taskRef.current = task;
|
|
85
|
+
optionsRef.current = options;
|
|
86
|
+
(_a = inputRef.current) == null ? void 0 : _a.click();
|
|
87
|
+
});
|
|
88
|
+
return unsub;
|
|
89
|
+
}, [plugin]);
|
|
90
|
+
const onChange = async (e) => {
|
|
91
|
+
var _a, _b, _c, _d, _e;
|
|
92
|
+
const file = (_a = e.currentTarget.files) == null ? void 0 : _a[0];
|
|
93
|
+
if (!file || !provides) return;
|
|
94
|
+
const buffer = await file.arrayBuffer();
|
|
95
|
+
const openTask = provides.openDocumentBuffer({
|
|
96
|
+
name: file.name,
|
|
97
|
+
buffer,
|
|
98
|
+
documentId: (_b = optionsRef.current) == null ? void 0 : _b.documentId,
|
|
99
|
+
scale: (_c = optionsRef.current) == null ? void 0 : _c.scale,
|
|
100
|
+
rotation: (_d = optionsRef.current) == null ? void 0 : _d.rotation,
|
|
101
|
+
autoActivate: (_e = optionsRef.current) == null ? void 0 : _e.autoActivate
|
|
102
|
+
});
|
|
103
|
+
openTask.wait(
|
|
104
|
+
(result) => {
|
|
105
|
+
var _a2;
|
|
106
|
+
(_a2 = taskRef.current) == null ? void 0 : _a2.resolve(result);
|
|
107
|
+
},
|
|
108
|
+
(error) => {
|
|
109
|
+
var _a2;
|
|
110
|
+
(_a2 = taskRef.current) == null ? void 0 : _a2.fail(error);
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
return /* @__PURE__ */ jsx(
|
|
115
|
+
"input",
|
|
116
|
+
{
|
|
117
|
+
ref: inputRef,
|
|
118
|
+
type: "file",
|
|
119
|
+
accept: "application/pdf",
|
|
120
|
+
style: { display: "none" },
|
|
121
|
+
onChange
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
const DocumentManagerPluginPackage = createPluginPackage(DocumentManagerPluginPackage$1).addUtility(FilePicker).build();
|
|
126
|
+
export {
|
|
127
|
+
DocumentContent,
|
|
128
|
+
DocumentContext,
|
|
129
|
+
DocumentManagerPluginPackage,
|
|
130
|
+
FilePicker,
|
|
131
|
+
useActiveDocument,
|
|
132
|
+
useDocumentManagerCapability,
|
|
133
|
+
useDocumentManagerPlugin,
|
|
134
|
+
useOpenDocuments
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/components/document-content.tsx","../../src/shared/hooks/use-document-manager.ts","../../src/shared/components/document-context.tsx","../../src/shared/components/file-picker.tsx","../../src/shared/index.ts"],"sourcesContent":["import { ReactNode } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { DocumentState } from '@embedpdf/core';\n\nexport interface DocumentContentRenderProps {\n documentState: DocumentState;\n isLoading: boolean;\n isError: boolean;\n isLoaded: boolean;\n}\n\ninterface DocumentContentProps {\n documentId: string | null;\n children: (props: DocumentContentRenderProps) => ReactNode;\n}\n\n/**\n * Headless component for rendering document content with loading/error states\n *\n * @example\n * <DocumentContent documentId={activeDocumentId}>\n * {({ document, isLoading, isError, isLoaded }) => {\n * if (isLoading) return <LoadingSpinner />;\n * if (isError) return <ErrorMessage />;\n * if (isLoaded) return <PDFViewer document={document} />;\n * return null;\n * }}\n * </DocumentContent>\n */\nexport function DocumentContent({ documentId, children }: DocumentContentProps) {\n const documentState = useDocumentState(documentId);\n\n if (!documentState) return null;\n\n const isLoading = documentState.status === 'loading';\n const isError = documentState.status === 'error';\n const isLoaded = documentState.status === 'loaded';\n\n return <>{children({ documentState, isLoading, isError, isLoaded })}</>;\n}\n","import { useMemo } from '@framework';\nimport { useCapability, useCoreState, usePlugin } from '@embedpdf/core/@framework';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport { DocumentState } from '@embedpdf/core';\n\nexport const useDocumentManagerPlugin = () =>\n usePlugin<DocumentManagerPlugin>(DocumentManagerPlugin.id);\nexport const useDocumentManagerCapability = () =>\n useCapability<DocumentManagerPlugin>(DocumentManagerPlugin.id);\n\n/**\n * Hook for active document state\n */\nexport const useActiveDocument = () => {\n const coreState = useCoreState();\n\n return useMemo(() => {\n if (!coreState) {\n return {\n activeDocumentId: null,\n activeDocument: null,\n };\n }\n\n const activeDocumentId = coreState.activeDocumentId;\n const activeDocument = activeDocumentId\n ? (coreState.documents[activeDocumentId] ?? null)\n : null;\n\n return {\n activeDocumentId,\n activeDocument,\n };\n }, [coreState]);\n};\n\n/**\n * Hook for all open documents (in order)\n */\nexport const useOpenDocuments = (documentIds?: string[]) => {\n const coreState = useCoreState();\n\n return useMemo(() => {\n if (!coreState) return [];\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds && documentIds.length > 0) {\n return documentIds\n .map((docId) => coreState.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return coreState.documentOrder\n .map((docId) => coreState.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }, [coreState, documentIds]);\n};\n","import { ReactNode, useCallback } from '@framework';\nimport { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\nimport { DocumentState } from '@embedpdf/core';\n\nexport interface TabActions {\n select: (documentId: string) => void;\n close: (documentId: string) => void;\n move: (documentId: string, toIndex: number) => void;\n}\n\nexport interface DocumentContextRenderProps {\n documentStates: DocumentState[];\n activeDocumentId: string | null;\n actions: TabActions;\n}\n\ninterface DocumentContextProps {\n children: (props: DocumentContextRenderProps) => ReactNode;\n}\n\n/**\n * Headless component for managing document tabs\n * Provides all state and actions, completely UI-agnostic\n *\n * @example\n * <DocumentContext>\n * {({ documents, activeDocumentId, actions }) => (\n * <div className=\"tabs\">\n * {documents.map((doc) => (\n * <button\n * key={doc.id}\n * onClick={() => actions.select(doc.id)}\n * className={doc.id === activeDocumentId ? 'active' : ''}\n * >\n * {doc.name}\n * <button onClick={(e) => {\n * e.stopPropagation();\n * actions.close(doc.id);\n * }}>×</button>\n * </button>\n * ))}\n * </div>\n * )}\n * </DocumentContext>\n */\nexport function DocumentContext({ children }: DocumentContextProps) {\n const documentStates = useOpenDocuments();\n const { activeDocumentId } = useActiveDocument();\n const { provides } = useDocumentManagerCapability();\n\n const select = useCallback(\n (documentId: string) => {\n provides?.setActiveDocument(documentId);\n },\n [provides],\n );\n\n const close = useCallback(\n (documentId: string) => {\n provides?.closeDocument(documentId);\n },\n [provides],\n );\n\n const move = useCallback(\n (documentId: string, toIndex: number) => {\n provides?.moveDocument(documentId, toIndex);\n },\n [provides],\n );\n\n const actions: TabActions = {\n select,\n close,\n move,\n };\n\n return <>{children({ documentStates, activeDocumentId, actions })}</>;\n}\n","import { ChangeEvent, useEffect, useRef } from '@framework';\nimport { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\nimport { PdfErrorReason, Task } from '@embedpdf/models';\nimport { OpenDocumentResponse, OpenFileDialogOptions } from '@embedpdf/plugin-document-manager';\n\nexport function FilePicker() {\n const { plugin } = useDocumentManagerPlugin();\n const { provides } = useDocumentManagerCapability();\n const inputRef = useRef<HTMLInputElement>(null);\n const taskRef = useRef<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\n const optionsRef = useRef<OpenFileDialogOptions | undefined>(undefined);\n\n useEffect(() => {\n if (!plugin?.onOpenFileRequest) return;\n const unsub = plugin.onOpenFileRequest(({ task, options }) => {\n taskRef.current = task;\n optionsRef.current = options;\n inputRef.current?.click();\n });\n return unsub;\n }, [plugin]);\n\n const onChange = async (e: ChangeEvent<HTMLInputElement>) => {\n const file = (e.currentTarget as HTMLInputElement).files?.[0];\n if (!file || !provides) return;\n const buffer = await file.arrayBuffer();\n const openTask = provides.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef.current?.documentId,\n scale: optionsRef.current?.scale,\n rotation: optionsRef.current?.rotation,\n autoActivate: optionsRef.current?.autoActivate,\n });\n openTask.wait(\n (result) => {\n taskRef.current?.resolve(result);\n },\n (error) => {\n taskRef.current?.fail(error);\n },\n );\n };\n\n return (\n <input\n ref={inputRef}\n type=\"file\"\n accept=\"application/pdf\"\n style={{ display: 'none' }}\n onChange={onChange}\n />\n );\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { DocumentManagerPluginPackage as BaseDocumentManagerPackage } from '@embedpdf/plugin-document-manager';\nimport { FilePicker } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-document-manager';\n\n// A convenience package that auto-registers our utilities\nexport const DocumentManagerPluginPackage = createPluginPackage(BaseDocumentManagerPackage)\n .addUtility(FilePicker) // headless utility consumers can mount once and call cap.openFileDialog()\n .build();\n"],"names":["_a","BaseDocumentManagerPackage"],"mappings":";;;;;;;AA6BO,SAAS,gBAAgB,EAAE,YAAY,YAAkC;AAC9E,QAAM,gBAAgB,iBAAiB,UAAU;AAEjD,MAAI,CAAC,cAAe,QAAO;AAE3B,QAAM,YAAY,cAAc,WAAW;AAC3C,QAAM,UAAU,cAAc,WAAW;AACzC,QAAM,WAAW,cAAc,WAAW;AAE1C,SAAO,oBAAA,UAAA,EAAG,mBAAS,EAAE,eAAe,WAAW,SAAS,SAAA,CAAU,EAAA,CAAE;AACtE;AClCO,MAAM,2BAA2B,MACtC,UAAiC,sBAAsB,EAAE;AACp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AAQ,YAAR,gBAAAA,IAAiB,KAAK;AAAA,MACxB;AAAA,IAAA;AAAA,EAEJ;AAEA,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,MAAK;AAAA,MACL,QAAO;AAAA,MACP,OAAO,EAAE,SAAS,OAAA;AAAA,MAClB;AAAA,IAAA;AAAA,EAAA;AAGN;AC5CO,MAAM,+BAA+B,oBAAoBC,8BAA0B,EACvF,WAAW,UAAU,EACrB,MAAA;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/react';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-document-manager"),n=require("react/jsx-runtime"),u=require("@embedpdf/core/react"),r=require("react");const o=()=>u.usePlugin(t.DocumentManagerPlugin.id),c=()=>u.useCapability(t.DocumentManagerPlugin.id),a=()=>{const e=u.useCoreState();return r.useMemo(()=>{if(!e)return{activeDocumentId:null,activeDocument:null};const t=e.activeDocumentId;return{activeDocumentId:t,activeDocument:t?e.documents[t]??null:null}},[e])},l=e=>{const t=u.useCoreState();return r.useMemo(()=>t?e&&e.length>0?e.map(e=>t.documents[e]).filter(e=>null!=e):t.documentOrder.map(e=>t.documents[e]).filter(e=>null!=e):[],[t,e])};function i(){const{plugin:e}=o(),{provides:t}=c(),u=r.useRef(null),a=r.useRef(null),l=r.useRef(void 0);r.useEffect(()=>{if(!(null==e?void 0:e.onOpenFileRequest))return;return e.onOpenFileRequest(({task:e,options:t})=>{var n;a.current=e,l.current=t,null==(n=u.current)||n.click()})},[e]);return n.jsx("input",{ref:u,type:"file",accept:"application/pdf",style:{display:"none"},onChange:async e=>{var n,u,r,o,c;const i=null==(n=e.currentTarget.files)?void 0:n[0];if(!i||!t)return;const s=await i.arrayBuffer();t.openDocumentBuffer({name:i.name,buffer:s,documentId:null==(u=l.current)?void 0:u.documentId,scale:null==(r=l.current)?void 0:r.scale,rotation:null==(o=l.current)?void 0:o.rotation,autoActivate:null==(c=l.current)?void 0:c.autoActivate}).wait(e=>{var t;null==(t=a.current)||t.resolve(e)},e=>{var t;null==(t=a.current)||t.fail(e)})}})}const s=e.createPluginPackage(t.DocumentManagerPluginPackage).addUtility(i).build();exports.DocumentContent=function({documentId:e,children:t}){const r=u.useDocumentState(e);if(!r)return null;const o="loading"===r.status,c="error"===r.status,a="loaded"===r.status;return n.jsx(n.Fragment,{children:t({documentState:r,isLoading:o,isError:c,isLoaded:a})})},exports.DocumentContext=function({children:e}){const t=l(),{activeDocumentId:u}=a(),{provides:o}=c(),i={select:r.useCallback(e=>{null==o||o.setActiveDocument(e)},[o]),close:r.useCallback(e=>{null==o||o.closeDocument(e)},[o]),move:r.useCallback((e,t)=>{null==o||o.moveDocument(e,t)},[o])};return n.jsx(n.Fragment,{children:e({documentStates:t,activeDocumentId:u,actions:i})})},exports.DocumentManagerPluginPackage=s,exports.FilePicker=i,exports.useActiveDocument=a,exports.useDocumentManagerCapability=c,exports.useDocumentManagerPlugin=o,exports.useOpenDocuments=l,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-document-manager.ts","../../src/shared/components/file-picker.tsx","../../src/shared/index.ts","../../src/shared/components/document-content.tsx","../../src/shared/components/document-context.tsx"],"sourcesContent":["import { useMemo } from '@framework';\nimport { useCapability, useCoreState, usePlugin } from '@embedpdf/core/@framework';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport { DocumentState } from '@embedpdf/core';\n\nexport const useDocumentManagerPlugin = () =>\n usePlugin<DocumentManagerPlugin>(DocumentManagerPlugin.id);\nexport const useDocumentManagerCapability = () =>\n useCapability<DocumentManagerPlugin>(DocumentManagerPlugin.id);\n\n/**\n * Hook for active document state\n */\nexport const useActiveDocument = () => {\n const coreState = useCoreState();\n\n return useMemo(() => {\n if (!coreState) {\n return {\n activeDocumentId: null,\n activeDocument: null,\n };\n }\n\n const activeDocumentId = coreState.activeDocumentId;\n const activeDocument = activeDocumentId\n ? (coreState.documents[activeDocumentId] ?? null)\n : null;\n\n return {\n activeDocumentId,\n activeDocument,\n };\n }, [coreState]);\n};\n\n/**\n * Hook for all open documents (in order)\n */\nexport const useOpenDocuments = (documentIds?: string[]) => {\n const coreState = useCoreState();\n\n return useMemo(() => {\n if (!coreState) return [];\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds && documentIds.length > 0) {\n return documentIds\n .map((docId) => coreState.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return coreState.documentOrder\n .map((docId) => coreState.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }, [coreState, documentIds]);\n};\n","import { ChangeEvent, useEffect, useRef } from '@framework';\nimport { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\nimport { PdfErrorReason, Task } from '@embedpdf/models';\nimport { OpenDocumentResponse, OpenFileDialogOptions } from '@embedpdf/plugin-document-manager';\n\nexport function FilePicker() {\n const { plugin } = useDocumentManagerPlugin();\n const { provides } = useDocumentManagerCapability();\n const inputRef = useRef<HTMLInputElement>(null);\n const taskRef = useRef<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\n const optionsRef = useRef<OpenFileDialogOptions | undefined>(undefined);\n\n useEffect(() => {\n if (!plugin?.onOpenFileRequest) return;\n const unsub = plugin.onOpenFileRequest(({ task, options }) => {\n taskRef.current = task;\n optionsRef.current = options;\n inputRef.current?.click();\n });\n return unsub;\n }, [plugin]);\n\n const onChange = async (e: ChangeEvent<HTMLInputElement>) => {\n const file = (e.currentTarget as HTMLInputElement).files?.[0];\n if (!file || !provides) return;\n const buffer = await file.arrayBuffer();\n const openTask = provides.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef.current?.documentId,\n scale: optionsRef.current?.scale,\n rotation: optionsRef.current?.rotation,\n autoActivate: optionsRef.current?.autoActivate,\n });\n openTask.wait(\n (result) => {\n taskRef.current?.resolve(result);\n },\n (error) => {\n taskRef.current?.fail(error);\n },\n );\n };\n\n return (\n <input\n ref={inputRef}\n type=\"file\"\n accept=\"application/pdf\"\n style={{ display: 'none' }}\n onChange={onChange}\n />\n );\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { DocumentManagerPluginPackage as BaseDocumentManagerPackage } from '@embedpdf/plugin-document-manager';\nimport { FilePicker } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-document-manager';\n\n// A convenience package that auto-registers our utilities\nexport const DocumentManagerPluginPackage = createPluginPackage(BaseDocumentManagerPackage)\n .addUtility(FilePicker) // headless utility consumers can mount once and call cap.openFileDialog()\n .build();\n","import { ReactNode } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { DocumentState } from '@embedpdf/core';\n\nexport interface DocumentContentRenderProps {\n documentState: DocumentState;\n isLoading: boolean;\n isError: boolean;\n isLoaded: boolean;\n}\n\ninterface DocumentContentProps {\n documentId: string | null;\n children: (props: DocumentContentRenderProps) => ReactNode;\n}\n\n/**\n * Headless component for rendering document content with loading/error states\n *\n * @example\n * <DocumentContent documentId={activeDocumentId}>\n * {({ document, isLoading, isError, isLoaded }) => {\n * if (isLoading) return <LoadingSpinner />;\n * if (isError) return <ErrorMessage />;\n * if (isLoaded) return <PDFViewer document={document} />;\n * return null;\n * }}\n * </DocumentContent>\n */\nexport function DocumentContent({ documentId, children }: DocumentContentProps) {\n const documentState = useDocumentState(documentId);\n\n if (!documentState) return null;\n\n const isLoading = documentState.status === 'loading';\n const isError = documentState.status === 'error';\n const isLoaded = documentState.status === 'loaded';\n\n return <>{children({ documentState, isLoading, isError, isLoaded })}</>;\n}\n","import { ReactNode, useCallback } from '@framework';\nimport { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\nimport { DocumentState } from '@embedpdf/core';\n\nexport interface TabActions {\n select: (documentId: string) => void;\n close: (documentId: string) => void;\n move: (documentId: string, toIndex: number) => void;\n}\n\nexport interface DocumentContextRenderProps {\n documentStates: DocumentState[];\n activeDocumentId: string | null;\n actions: TabActions;\n}\n\ninterface DocumentContextProps {\n children: (props: DocumentContextRenderProps) => ReactNode;\n}\n\n/**\n * Headless component for managing document tabs\n * Provides all state and actions, completely UI-agnostic\n *\n * @example\n * <DocumentContext>\n * {({ documents, activeDocumentId, actions }) => (\n * <div className=\"tabs\">\n * {documents.map((doc) => (\n * <button\n * key={doc.id}\n * onClick={() => actions.select(doc.id)}\n * className={doc.id === activeDocumentId ? 'active' : ''}\n * >\n * {doc.name}\n * <button onClick={(e) => {\n * e.stopPropagation();\n * actions.close(doc.id);\n * }}>×</button>\n * </button>\n * ))}\n * </div>\n * )}\n * </DocumentContext>\n */\nexport function DocumentContext({ children }: DocumentContextProps) {\n const documentStates = useOpenDocuments();\n const { activeDocumentId } = useActiveDocument();\n const { provides } = useDocumentManagerCapability();\n\n const select = useCallback(\n (documentId: string) => {\n provides?.setActiveDocument(documentId);\n },\n [provides],\n );\n\n const close = useCallback(\n (documentId: string) => {\n provides?.closeDocument(documentId);\n },\n [provides],\n );\n\n const move = useCallback(\n (documentId: string, toIndex: number) => {\n provides?.moveDocument(documentId, toIndex);\n },\n [provides],\n );\n\n const actions: TabActions = {\n select,\n close,\n move,\n };\n\n return <>{children({ documentStates, activeDocumentId, actions })}</>;\n}\n"],"names":["useDocumentManagerPlugin","usePlugin","DocumentManagerPlugin","id","useDocumentManagerCapability","useCapability","useActiveDocument","coreState","useCoreState","useMemo","activeDocumentId","activeDocument","documents","useOpenDocuments","documentIds","length","map","docId","filter","doc","documentOrder","FilePicker","plugin","provides","inputRef","useRef","taskRef","optionsRef","useEffect","onOpenFileRequest","task","options","current","_a","click","jsx","ref","type","accept","style","display","onChange","async","e","file","currentTarget","files","buffer","arrayBuffer","openDocumentBuffer","name","documentId","_b","scale","_c","rotation","_d","autoActivate","_e","wait","result","resolve","error","fail","DocumentManagerPluginPackage","createPluginPackage","BaseDocumentManagerPackage","addUtility","build","children","documentState","useDocumentState","isLoading","status","isError","isLoaded","Fragment","documentStates","actions","select","useCallback","setActiveDocument","close","closeDocument","move","toIndex","moveDocument"],"mappings":"qPAKO,MAAMA,EAA2B,IACtCC,YAAiCC,EAAAA,sBAAsBC,IAC5CC,EAA+B,IAC1CC,gBAAqCH,EAAAA,sBAAsBC,IAKhDG,EAAoB,KAC/B,MAAMC,EAAYC,EAAAA,eAElB,OAAOC,EAAAA,QAAQ,KACb,IAAKF,EACH,MAAO,CACLG,iBAAkB,KAClBC,eAAgB,MAIpB,MAAMD,EAAmBH,EAAUG,iBAKnC,MAAO,CACLA,mBACAC,eANqBD,EAClBH,EAAUK,UAAUF,IAAqB,KAC1C,OAMH,CAACH,KAMOM,EAAoBC,IAC/B,MAAMP,EAAYC,EAAAA,eAElB,OAAOC,EAAAA,QAAQ,IACRF,EAGDO,GAAeA,EAAYC,OAAS,EAC/BD,EACJE,IAAKC,GAAUV,EAAUK,UAAUK,IACnCC,OAAQC,GAA8BA,SAIpCZ,EAAUa,cACdJ,IAAKC,GAAUV,EAAUK,UAAUK,IACnCC,OAAQC,GAA8BA,SAZlB,GAatB,CAACZ,EAAWO,KCnDV,SAASO,IACd,MAAMC,OAAEA,GAAWtB,KACbuB,SAAEA,GAAanB,IACfoB,EAAWC,EAAAA,OAAyB,MACpCC,EAAUD,EAAAA,OAA0D,MACpEE,EAAaF,EAAAA,YAA0C,GAE7DG,EAAAA,UAAU,KACR,WAAKN,WAAQO,mBAAmB,OAMhC,OALcP,EAAOO,kBAAkB,EAAGC,OAAMC,oBAC9CL,EAAQM,QAAUF,EAClBH,EAAWK,QAAUD,EACrB,OAAAE,EAAAT,EAASQ,UAATC,EAAkBC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B9B,IAE9B,CAAC5B,IAmBD2D,MAhBYF,EAAAA,YACX7B,IACC,MAAA5B,GAAAA,EAAU4D,cAAchC,IAE1B,CAAC5B,IAaD6D,KAVWJ,EAAAA,YACX,CAAC7B,EAAoBkC,KACnB,MAAA9D,GAAAA,EAAU+D,aAAanC,EAAYkC,IAErC,CAAC9D,KASH,yBAAU8C,SAAAA,EAAS,CAAEQ,iBAAgBnE,mBAAkBoE,aACzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../shared-react';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { createPluginPackage } from "@embedpdf/core";
|
|
2
|
+
import { DocumentManagerPlugin, DocumentManagerPluginPackage as DocumentManagerPluginPackage$1 } from "@embedpdf/plugin-document-manager";
|
|
3
|
+
export * from "@embedpdf/plugin-document-manager";
|
|
4
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
5
|
+
import { useDocumentState, usePlugin, useCapability, useCoreState } from "@embedpdf/core/react";
|
|
6
|
+
import { useMemo, useCallback, useRef, useEffect } from "react";
|
|
7
|
+
function DocumentContent({ documentId, children }) {
|
|
8
|
+
const documentState = useDocumentState(documentId);
|
|
9
|
+
if (!documentState) return null;
|
|
10
|
+
const isLoading = documentState.status === "loading";
|
|
11
|
+
const isError = documentState.status === "error";
|
|
12
|
+
const isLoaded = documentState.status === "loaded";
|
|
13
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children({ documentState, isLoading, isError, isLoaded }) });
|
|
14
|
+
}
|
|
15
|
+
const useDocumentManagerPlugin = () => usePlugin(DocumentManagerPlugin.id);
|
|
16
|
+
const useDocumentManagerCapability = () => useCapability(DocumentManagerPlugin.id);
|
|
17
|
+
const useActiveDocument = () => {
|
|
18
|
+
const coreState = useCoreState();
|
|
19
|
+
return useMemo(() => {
|
|
20
|
+
if (!coreState) {
|
|
21
|
+
return {
|
|
22
|
+
activeDocumentId: null,
|
|
23
|
+
activeDocument: null
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const activeDocumentId = coreState.activeDocumentId;
|
|
27
|
+
const activeDocument = activeDocumentId ? coreState.documents[activeDocumentId] ?? null : null;
|
|
28
|
+
return {
|
|
29
|
+
activeDocumentId,
|
|
30
|
+
activeDocument
|
|
31
|
+
};
|
|
32
|
+
}, [coreState]);
|
|
33
|
+
};
|
|
34
|
+
const useOpenDocuments = (documentIds) => {
|
|
35
|
+
const coreState = useCoreState();
|
|
36
|
+
return useMemo(() => {
|
|
37
|
+
if (!coreState) return [];
|
|
38
|
+
if (documentIds && documentIds.length > 0) {
|
|
39
|
+
return documentIds.map((docId) => coreState.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
|
|
40
|
+
}
|
|
41
|
+
return coreState.documentOrder.map((docId) => coreState.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
|
|
42
|
+
}, [coreState, documentIds]);
|
|
43
|
+
};
|
|
44
|
+
function DocumentContext({ children }) {
|
|
45
|
+
const documentStates = useOpenDocuments();
|
|
46
|
+
const { activeDocumentId } = useActiveDocument();
|
|
47
|
+
const { provides } = useDocumentManagerCapability();
|
|
48
|
+
const select = useCallback(
|
|
49
|
+
(documentId) => {
|
|
50
|
+
provides == null ? void 0 : provides.setActiveDocument(documentId);
|
|
51
|
+
},
|
|
52
|
+
[provides]
|
|
53
|
+
);
|
|
54
|
+
const close = useCallback(
|
|
55
|
+
(documentId) => {
|
|
56
|
+
provides == null ? void 0 : provides.closeDocument(documentId);
|
|
57
|
+
},
|
|
58
|
+
[provides]
|
|
59
|
+
);
|
|
60
|
+
const move = useCallback(
|
|
61
|
+
(documentId, toIndex) => {
|
|
62
|
+
provides == null ? void 0 : provides.moveDocument(documentId, toIndex);
|
|
63
|
+
},
|
|
64
|
+
[provides]
|
|
65
|
+
);
|
|
66
|
+
const actions = {
|
|
67
|
+
select,
|
|
68
|
+
close,
|
|
69
|
+
move
|
|
70
|
+
};
|
|
71
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children({ documentStates, activeDocumentId, actions }) });
|
|
72
|
+
}
|
|
73
|
+
function FilePicker() {
|
|
74
|
+
const { plugin } = useDocumentManagerPlugin();
|
|
75
|
+
const { provides } = useDocumentManagerCapability();
|
|
76
|
+
const inputRef = useRef(null);
|
|
77
|
+
const taskRef = useRef(null);
|
|
78
|
+
const optionsRef = useRef(void 0);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!(plugin == null ? void 0 : plugin.onOpenFileRequest)) return;
|
|
81
|
+
const unsub = plugin.onOpenFileRequest(({ task, options }) => {
|
|
82
|
+
var _a;
|
|
83
|
+
taskRef.current = task;
|
|
84
|
+
optionsRef.current = options;
|
|
85
|
+
(_a = inputRef.current) == null ? void 0 : _a.click();
|
|
86
|
+
});
|
|
87
|
+
return unsub;
|
|
88
|
+
}, [plugin]);
|
|
89
|
+
const onChange = async (e) => {
|
|
90
|
+
var _a, _b, _c, _d, _e;
|
|
91
|
+
const file = (_a = e.currentTarget.files) == null ? void 0 : _a[0];
|
|
92
|
+
if (!file || !provides) return;
|
|
93
|
+
const buffer = await file.arrayBuffer();
|
|
94
|
+
const openTask = provides.openDocumentBuffer({
|
|
95
|
+
name: file.name,
|
|
96
|
+
buffer,
|
|
97
|
+
documentId: (_b = optionsRef.current) == null ? void 0 : _b.documentId,
|
|
98
|
+
scale: (_c = optionsRef.current) == null ? void 0 : _c.scale,
|
|
99
|
+
rotation: (_d = optionsRef.current) == null ? void 0 : _d.rotation,
|
|
100
|
+
autoActivate: (_e = optionsRef.current) == null ? void 0 : _e.autoActivate
|
|
101
|
+
});
|
|
102
|
+
openTask.wait(
|
|
103
|
+
(result) => {
|
|
104
|
+
var _a2;
|
|
105
|
+
(_a2 = taskRef.current) == null ? void 0 : _a2.resolve(result);
|
|
106
|
+
},
|
|
107
|
+
(error) => {
|
|
108
|
+
var _a2;
|
|
109
|
+
(_a2 = taskRef.current) == null ? void 0 : _a2.fail(error);
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ jsx(
|
|
114
|
+
"input",
|
|
115
|
+
{
|
|
116
|
+
ref: inputRef,
|
|
117
|
+
type: "file",
|
|
118
|
+
accept: "application/pdf",
|
|
119
|
+
style: { display: "none" },
|
|
120
|
+
onChange
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
const DocumentManagerPluginPackage = createPluginPackage(DocumentManagerPluginPackage$1).addUtility(FilePicker).build();
|
|
125
|
+
export {
|
|
126
|
+
DocumentContent,
|
|
127
|
+
DocumentContext,
|
|
128
|
+
DocumentManagerPluginPackage,
|
|
129
|
+
FilePicker,
|
|
130
|
+
useActiveDocument,
|
|
131
|
+
useDocumentManagerCapability,
|
|
132
|
+
useDocumentManagerPlugin,
|
|
133
|
+
useOpenDocuments
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=index.js.map
|