@embedpdf/plugin-document-manager 2.0.0-next.0 → 2.0.0-next.2

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/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),o=class extends e.BasePlugin{constructor(t,o,n){super(t,o),this.id=t,this.documentOpened$=e.createBehaviorEmitter(),this.documentClosed$=e.createBehaviorEmitter(),this.activeDocumentChanged$=e.createBehaviorEmitter(),this.documentError$=e.createBehaviorEmitter(),this.documentOrderChanged$=e.createBehaviorEmitter(),this.openFileRequest$=e.createEmitter(),this.loadOptions=new Map,this.maxDocuments=null==n?void 0:n.maxDocuments}buildCapability(){return{openFileDialog:e=>this.openFileDialog(e),openDocumentUrl:e=>this.openDocumentUrl(e),openDocumentBuffer:e=>this.openDocumentBuffer(e),retryDocument:(e,t)=>this.retryDocument(e,t),closeDocument:e=>this.closeDocument(e),closeAllDocuments:()=>this.closeAllDocuments(),setActiveDocument:t=>{if(!this.isDocumentOpen(t))throw new Error(`Cannot set active document: ${t} is not open`);this.dispatchCoreAction(e.setActiveDocument(t))},getActiveDocumentId:()=>this.coreState.core.activeDocumentId,getActiveDocument:()=>{var e;const t=this.coreState.core.activeDocumentId;return t?(null==(e=this.coreState.core.documents[t])?void 0:e.document)??null:null},getDocumentOrder:()=>this.coreState.core.documentOrder,moveDocument:(t,o)=>{this.dispatchCoreAction(e.moveDocument(t,o))},swapDocuments:(t,o)=>{const n=this.coreState.core.documentOrder,r=n.indexOf(t),s=n.indexOf(o);if(-1===r||-1===s)throw new Error("One or both documents not found in order");const c=[...n];[c[r],c[s]]=[c[s],c[r]],this.dispatchCoreAction(e.reorderDocuments(c))},getDocument:e=>{var t;return(null==(t=this.coreState.core.documents[e])?void 0:t.document)??null},getDocumentState:e=>this.coreState.core.documents[e]??null,getOpenDocuments:()=>this.coreState.core.documentOrder.map(e=>this.coreState.core.documents[e]).filter(e=>null!==e),isDocumentOpen:e=>this.isDocumentOpen(e),getDocumentCount:()=>Object.keys(this.coreState.core.documents).length,getDocumentIndex:e=>this.coreState.core.documentOrder.indexOf(e),onDocumentOpened:this.documentOpened$.on,onDocumentClosed:this.documentClosed$.on,onDocumentError:this.documentError$.on,onActiveDocumentChanged:this.activeDocumentChanged$.on,onDocumentOrderChanged:this.documentOrderChanged$.on}}isDocumentOpen(e){return!!this.coreState.core.documents[e]}onDocumentLoaded(e){const t=this.coreState.core.documents[e];t&&"loaded"===t.status&&(this.loadOptions.delete(e),this.documentOpened$.emit(t),this.logger.info("DocumentManagerPlugin","DocumentOpened",`Document ${e} opened successfully`,{name:t.name}))}onDocumentClosed(e){this.loadOptions.delete(e),this.documentClosed$.emit(e),this.logger.info("DocumentManagerPlugin","DocumentClosed",`Document ${e} closed`)}onActiveDocumentChanged(e,t){this.activeDocumentChanged$.emit({previousDocumentId:e,currentDocumentId:t}),this.logger.info("DocumentManagerPlugin","ActiveDocumentChanged",`Active document changed from ${e} to ${t}`)}onCoreStoreUpdated(e,t){e.core.documentOrder!==t.core.documentOrder&&this.documentOrderChanged$.emit({order:t.core.documentOrder})}onOpenFileRequest(e){return this.openFileRequest$.on(e)}openDocumentUrl(o){const n=new t.Task,r=o.documentId||this.generateDocumentId(),s=this.checkDocumentLimit();if(s)return n.reject(s),n;const c=this.extractNameFromUrl(o.url);this.loadOptions.set(r,o),this.dispatchCoreAction(e.startLoadingDocument(r,c,o.scale,o.rotation,!!o.password,o.autoActivate)),this.logger.info("DocumentManagerPlugin","OpenDocumentUrl",`Starting to load document from URL: ${o.url}`,{documentId:r,passwordProvided:!!o.password});const i={id:r,url:o.url},a=this.engine.openDocumentUrl(i,{password:o.password,mode:o.mode,requestOptions:o.requestOptions});return n.resolve({documentId:r,task:a}),this.handleLoadTask(r,a,"OpenDocumentUrl"),n}openDocumentBuffer(o){const n=new t.Task,r=this.checkDocumentLimit();if(r)return n.reject(r),n;const s=o.documentId||this.generateDocumentId();this.loadOptions.set(s,o),this.dispatchCoreAction(e.startLoadingDocument(s,o.name,o.scale,o.rotation,!!o.password,o.autoActivate)),this.logger.info("DocumentManagerPlugin","OpenDocumentBuffer",`Starting to load document from buffer: ${o.name}`,{documentId:s,passwordProvided:!!o.password});const c={id:s,content:o.buffer},i=this.engine.openDocumentBuffer(c,{password:o.password});return n.resolve({documentId:s,task:i}),this.handleLoadTask(s,i,"OpenDocumentBuffer"),n}retryDocument(o,n){const r=new t.Task,s=this.validateRetry(o);if(!s.valid)return r.reject(s.error),r;const c={...this.loadOptions.get(o),...(null==n?void 0:n.password)&&{password:n.password}};this.loadOptions.set(o,c),this.dispatchCoreAction(e.retryLoadingDocument(o,!!(null==n?void 0:n.password))),this.logger.info("DocumentManagerPlugin","RetryDocument",`Retrying to load document ${o}`,{passwordProvided:!!(null==n?void 0:n.password)});const i="url"in c?this.retryUrlDocument(o,c):this.retryBufferDocument(o,c);return r.resolve({documentId:o,task:i}),this.handleLoadTask(o,i,"RetryDocument"),r}openFileDialog(e){const o=new t.Task;return this.openFileRequest$.emit({task:o,options:e}),o}closeDocument(o){const n=new t.Task,r=this.coreState.core.documents[o];return r?("loaded"===r.status&&r.document?this.engine.closeDocument(r.document).wait(()=>{this.dispatchCoreAction(e.closeDocument(o)),n.resolve()},e=>{this.logger.error("DocumentManagerPlugin","CloseDocument",`Failed to close document ${o}`,e),n.fail(e)}):(this.logger.info("DocumentManagerPlugin","CloseDocument",`Closing document ${o} in ${r.status} state (skipping engine close)`),this.dispatchCoreAction(e.closeDocument(o)),n.resolve()),n):(this.logger.warn("DocumentManagerPlugin","CloseDocument",`Cannot close document ${o}: not found in state`),n.resolve(),n)}closeAllDocuments(){const e=Object.keys(this.coreState.core.documents),o=e.map(e=>this.closeDocument(e));return this.logger.info("DocumentManagerPlugin","CloseAllDocuments",`Closing ${e.length} documents`),t.Task.all(o)}checkDocumentLimit(){return this.maxDocuments&&Object.keys(this.coreState.core.documents).length>=this.maxDocuments?{code:t.PdfErrorCode.Unknown,message:`Maximum number of documents (${this.maxDocuments}) reached`}:null}validateRetry(e){const o=this.coreState.core.documents[e];return o?"loaded"===o.status?{valid:!1,error:{code:t.PdfErrorCode.Unknown,message:`Document ${e} is already loaded successfully`}}:"error"!==o.status?{valid:!1,error:{code:t.PdfErrorCode.Unknown,message:`Document ${e} is not in error state (current state: ${o.status})`}}:this.loadOptions.has(e)?{valid:!0}:{valid:!1,error:{code:t.PdfErrorCode.Unknown,message:`No retry information available for document ${e}`}}:{valid:!1,error:{code:t.PdfErrorCode.NotFound,message:`Document ${e} not found`}}}retryUrlDocument(e,t){const o={id:e,url:t.url};return this.engine.openDocumentUrl(o,{password:t.password,mode:t.mode,requestOptions:t.requestOptions})}retryBufferDocument(e,t){const o={id:e,content:t.buffer};return this.engine.openDocumentBuffer(o,{password:t.password})}handleLoadTask(t,o,n){o.wait(o=>{this.dispatchCoreAction(e.setDocumentLoaded(t,o))},e=>{this.handleLoadError(t,e,n)})}handleLoadError(t,o,n){var r,s,c;const i=(null==(r=o.reason)?void 0:r.message)||"Failed to load document";this.logger.error("DocumentManagerPlugin",n,"Failed to load document",o),this.dispatchCoreAction(e.setDocumentError(t,i,null==(s=o.reason)?void 0:s.code,o.reason)),this.documentError$.emit({documentId:t,message:i,code:null==(c=o.reason)?void 0:c.code,reason:o.reason})}generateDocumentId(){return`doc-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}extractNameFromUrl(e){try{const t=new URL(e),o=t.pathname.split("/").pop()||"document.pdf";return decodeURIComponent(o)}catch{return"document.pdf"}}async initialize(e){var t;if(this.logger.info("DocumentManagerPlugin","Initialize","Document Manager Plugin initialized",{maxDocuments:this.maxDocuments,initialDocumentsCount:(null==(t=e.initialDocuments)?void 0:t.length)??0}),e.initialDocuments&&e.initialDocuments.length>0)for(const n of e.initialDocuments)try{"buffer"in n?this.openDocumentBuffer(n):"url"in n&&this.openDocumentUrl(n)}catch(o){this.logger.error("DocumentManagerPlugin","Initialize","Failed to initiate initial document load",o)}}async destroy(){await this.closeAllDocuments().toPromise(),this.loadOptions.clear(),this.documentOpened$.clear(),this.documentClosed$.clear(),this.activeDocumentChanged$.clear(),this.documentOrderChanged$.clear(),this.documentError$.clear(),super.destroy()}};o.id="document-manager";let n=o;const r="document-manager",s={id:r,name:"Document Manager Plugin",version:"1.0.0",provides:["document-manager"],requires:[],optional:[],defaultConfig:{enabled:!0,maxDocuments:10}},c={manifest:s,create:(e,t)=>new n(r,e,t),reducer:e=>e,initialState:{}};exports.DOCUMENT_MANAGER_PLUGIN_ID=r,exports.DocumentManagerPlugin=n,exports.DocumentManagerPluginPackage=c,exports.manifest=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),o=class extends e.BasePlugin{constructor(t,o,n){super(t,o),this.id=t,this.documentOpened$=e.createBehaviorEmitter(),this.documentClosed$=e.createBehaviorEmitter(),this.activeDocumentChanged$=e.createBehaviorEmitter(),this.documentError$=e.createBehaviorEmitter(),this.documentOrderChanged$=e.createBehaviorEmitter(),this.openFileRequest$=e.createEmitter(),this.loadOptions=new Map,this.maxDocuments=null==n?void 0:n.maxDocuments}buildCapability(){return{openFileDialog:e=>this.openFileDialog(e),openDocumentUrl:e=>this.openDocumentUrl(e),openDocumentBuffer:e=>this.openDocumentBuffer(e),retryDocument:(e,t)=>this.retryDocument(e,t),closeDocument:e=>this.closeDocument(e),closeAllDocuments:()=>this.closeAllDocuments(),setActiveDocument:t=>{if(!this.isDocumentOpen(t))throw new Error(`Cannot set active document: ${t} is not open`);this.dispatchCoreAction(e.setActiveDocument(t))},getActiveDocumentId:()=>this.coreState.core.activeDocumentId,getActiveDocument:()=>{var e;const t=this.coreState.core.activeDocumentId;return t?(null==(e=this.coreState.core.documents[t])?void 0:e.document)??null:null},getDocumentOrder:()=>this.coreState.core.documentOrder,moveDocument:(t,o)=>{this.dispatchCoreAction(e.moveDocument(t,o))},swapDocuments:(t,o)=>{const n=this.coreState.core.documentOrder,r=n.indexOf(t),s=n.indexOf(o);if(-1===r||-1===s)throw new Error("One or both documents not found in order");const c=[...n];[c[r],c[s]]=[c[s],c[r]],this.dispatchCoreAction(e.reorderDocuments(c))},getDocument:e=>{var t;return(null==(t=this.coreState.core.documents[e])?void 0:t.document)??null},getDocumentState:e=>this.coreState.core.documents[e]??null,getOpenDocuments:()=>this.coreState.core.documentOrder.map(e=>this.coreState.core.documents[e]).filter(e=>null!==e),isDocumentOpen:e=>this.isDocumentOpen(e),getDocumentCount:()=>Object.keys(this.coreState.core.documents).length,getDocumentIndex:e=>this.coreState.core.documentOrder.indexOf(e),onDocumentOpened:this.documentOpened$.on,onDocumentClosed:this.documentClosed$.on,onDocumentError:this.documentError$.on,onActiveDocumentChanged:this.activeDocumentChanged$.on,onDocumentOrderChanged:this.documentOrderChanged$.on}}isDocumentOpen(e){return!!this.coreState.core.documents[e]}onDocumentLoaded(e){const t=this.coreState.core.documents[e];t&&"loaded"===t.status&&(this.loadOptions.delete(e),this.documentOpened$.emit(t),this.logger.info("DocumentManagerPlugin","DocumentOpened",`Document ${e} opened successfully`,{name:t.name}))}onDocumentClosed(e){this.loadOptions.delete(e),this.documentClosed$.emit(e),this.logger.info("DocumentManagerPlugin","DocumentClosed",`Document ${e} closed`)}onActiveDocumentChanged(e,t){this.activeDocumentChanged$.emit({previousDocumentId:e,currentDocumentId:t}),this.logger.info("DocumentManagerPlugin","ActiveDocumentChanged",`Active document changed from ${e} to ${t}`)}onCoreStoreUpdated(e,t){e.core.documentOrder!==t.core.documentOrder&&this.documentOrderChanged$.emit({order:t.core.documentOrder})}onOpenFileRequest(e){return this.openFileRequest$.on(e)}openDocumentUrl(o){const n=new t.Task,r=o.documentId||this.generateDocumentId(),s=this.checkDocumentLimit();if(s)return n.reject(s),n;const c=this.extractNameFromUrl(o.url);this.loadOptions.set(r,o),this.dispatchCoreAction(e.startLoadingDocument(r,c,o.scale,o.rotation,!!o.password,o.autoActivate)),this.logger.info("DocumentManagerPlugin","OpenDocumentUrl",`Starting to load document from URL: ${o.url}`,{documentId:r,passwordProvided:!!o.password});const i={id:r,url:o.url},u=this.engine.openDocumentUrl(i,{password:o.password,mode:o.mode,requestOptions:o.requestOptions});return n.resolve({documentId:r,task:u}),this.handleLoadTask(r,u,"OpenDocumentUrl"),n}openDocumentBuffer(o){const n=new t.Task,r=this.checkDocumentLimit();if(r)return n.reject(r),n;const s=o.documentId||this.generateDocumentId();this.loadOptions.set(s,o),this.dispatchCoreAction(e.startLoadingDocument(s,o.name,o.scale,o.rotation,!!o.password,o.autoActivate)),this.logger.info("DocumentManagerPlugin","OpenDocumentBuffer",`Starting to load document from buffer: ${o.name}`,{documentId:s,passwordProvided:!!o.password});const c={id:s,content:o.buffer},i=this.engine.openDocumentBuffer(c,{password:o.password});return n.resolve({documentId:s,task:i}),this.handleLoadTask(s,i,"OpenDocumentBuffer"),n}retryDocument(o,n){const r=new t.Task,s=this.validateRetry(o);if(!s.valid)return r.reject(s.error),r;const c={...this.loadOptions.get(o),...(null==n?void 0:n.password)&&{password:n.password}};this.loadOptions.set(o,c),this.dispatchCoreAction(e.retryLoadingDocument(o,!!(null==n?void 0:n.password))),this.logger.info("DocumentManagerPlugin","RetryDocument",`Retrying to load document ${o}`,{passwordProvided:!!(null==n?void 0:n.password)});const i="url"in c?this.retryUrlDocument(o,c):this.retryBufferDocument(o,c);return r.resolve({documentId:o,task:i}),this.handleLoadTask(o,i,"RetryDocument"),r}openFileDialog(e){const o=new t.Task;return this.openFileRequest$.emit({task:o,options:e}),o}closeDocument(o){const n=new t.Task,r=this.coreState.core.documents[o];return r?("loaded"===r.status&&r.document?this.engine.closeDocument(r.document).wait(()=>{this.dispatchCoreAction(e.closeDocument(o)),n.resolve()},e=>{this.logger.error("DocumentManagerPlugin","CloseDocument",`Failed to close document ${o}`,e),n.fail(e)}):(this.logger.info("DocumentManagerPlugin","CloseDocument",`Closing document ${o} in ${r.status} state (skipping engine close)`),this.dispatchCoreAction(e.closeDocument(o)),n.resolve()),n):(this.logger.warn("DocumentManagerPlugin","CloseDocument",`Cannot close document ${o}: not found in state`),n.resolve(),n)}closeAllDocuments(){const e=Object.keys(this.coreState.core.documents),o=e.map(e=>this.closeDocument(e));return this.logger.info("DocumentManagerPlugin","CloseAllDocuments",`Closing ${e.length} documents`),t.Task.all(o)}checkDocumentLimit(){return this.maxDocuments&&Object.keys(this.coreState.core.documents).length>=this.maxDocuments?{code:t.PdfErrorCode.Unknown,message:`Maximum number of documents (${this.maxDocuments}) reached`}:null}validateRetry(e){const o=this.coreState.core.documents[e];return o?"loaded"===o.status?{valid:!1,error:{code:t.PdfErrorCode.Unknown,message:`Document ${e} is already loaded successfully`}}:"error"!==o.status?{valid:!1,error:{code:t.PdfErrorCode.Unknown,message:`Document ${e} is not in error state (current state: ${o.status})`}}:this.loadOptions.has(e)?{valid:!0}:{valid:!1,error:{code:t.PdfErrorCode.Unknown,message:`No retry information available for document ${e}`}}:{valid:!1,error:{code:t.PdfErrorCode.NotFound,message:`Document ${e} not found`}}}retryUrlDocument(e,t){const o={id:e,url:t.url};return this.engine.openDocumentUrl(o,{password:t.password,mode:t.mode,requestOptions:t.requestOptions})}retryBufferDocument(e,t){const o={id:e,content:t.buffer};return this.engine.openDocumentBuffer(o,{password:t.password})}handleLoadTask(t,o,n){o.wait(o=>{this.dispatchCoreAction(e.setDocumentLoaded(t,o))},e=>{this.handleLoadError(t,e,n)})}handleLoadError(t,o,n){var r,s,c;const i=(null==(r=o.reason)?void 0:r.message)||"Failed to load document";this.logger.error("DocumentManagerPlugin",n,"Failed to load document",o),this.dispatchCoreAction(e.setDocumentError(t,i,null==(s=o.reason)?void 0:s.code,o.reason)),this.documentError$.emit({documentId:t,message:i,code:null==(c=o.reason)?void 0:c.code,reason:o.reason})}generateDocumentId(){return`doc-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}extractNameFromUrl(e){try{const t=new URL(e),o=t.pathname.split("/").pop()||"document.pdf";return decodeURIComponent(o)}catch{return"document.pdf"}}async initialize(e){var t;if(this.logger.info("DocumentManagerPlugin","Initialize","Document Manager Plugin initialized",{maxDocuments:this.maxDocuments,initialDocumentsCount:(null==(t=e.initialDocuments)?void 0:t.length)??0}),e.initialDocuments&&e.initialDocuments.length>0)for(const n of e.initialDocuments)try{"buffer"in n?this.openDocumentBuffer(n):"url"in n&&this.openDocumentUrl(n)}catch(o){this.logger.error("DocumentManagerPlugin","Initialize","Failed to initiate initial document load",o)}}async destroy(){await this.closeAllDocuments().toPromise(),this.loadOptions.clear(),this.documentOpened$.clear(),this.documentClosed$.clear(),this.activeDocumentChanged$.clear(),this.documentOrderChanged$.clear(),this.documentError$.clear(),super.destroy()}};o.id="document-manager";let n=o;const r="document-manager",s={id:r,name:"Document Manager Plugin",version:"1.0.0",provides:["document-manager"],requires:[],optional:[],defaultConfig:{maxDocuments:10}},c={manifest:s,create:(e,t)=>new n(r,e,t),reducer:e=>e,initialState:{}};exports.DOCUMENT_MANAGER_PLUGIN_ID=r,exports.DocumentManagerPlugin=n,exports.DocumentManagerPluginPackage=c,exports.manifest=s;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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":["_DocumentManagerPlugin","BasePlugin","constructor","id","registry","config","super","this","documentOpened$","createBehaviorEmitter","documentClosed$","activeDocumentChanged$","documentError$","documentOrderChanged$","openFileRequest$","createEmitter","loadOptions","Map","maxDocuments","buildCapability","openFileDialog","options","openDocumentUrl","openDocumentBuffer","retryDocument","documentId","closeDocument","closeAllDocuments","setActiveDocument","isDocumentOpen","Error","dispatchCoreAction","setActiveDocumentAction","getActiveDocumentId","coreState","core","activeDocumentId","getActiveDocument","activeId","_a","documents","document","getDocumentOrder","documentOrder","moveDocument","toIndex","moveDocumentAction","swapDocuments","id1","id2","order","index1","indexOf","index2","newOrder","reorderDocumentsAction","getDocument","getDocumentState","getOpenDocuments","map","filter","state","getDocumentCount","Object","keys","length","getDocumentIndex","onDocumentOpened","on","onDocumentClosed","onDocumentError","onActiveDocumentChanged","onDocumentOrderChanged","onDocumentLoaded","docState","status","delete","emit","logger","info","name","previousId","currentId","previousDocumentId","currentDocumentId","onCoreStoreUpdated","oldState","newState","onOpenFileRequest","handler","task","Task","generateDocumentId","limitError","checkDocumentLimit","reject","documentName","extractNameFromUrl","url","set","startLoadingDocument","scale","rotation","password","autoActivate","passwordProvided","file","engineTask","engine","mode","requestOptions","resolve","handleLoadTask","content","buffer","retryOptions","validation","validateRetry","valid","error","mergedOptions","get","retryLoadingDocument","retryUrlDocument","retryBufferDocument","wait","closeDocumentAction","fail","warn","documentIds","tasks","all","code","PdfErrorCode","Unknown","message","has","NotFound","context","pdfDocument","setDocumentLoaded","handleLoadError","errorMessage","reason","setDocumentError","_b","_c","Date","now","Math","random","toString","substr","urlObj","URL","filename","pathname","split","pop","decodeURIComponent","initialize","initialDocumentsCount","initialDocuments","docConfig","destroy","toPromise","clear","DocumentManagerPlugin","DOCUMENT_MANAGER_PLUGIN_ID","manifest","version","provides","requires","optional","defaultConfig","enabled","DocumentManagerPluginPackage","create","reducer","initialState"],"mappings":"gJAuCaA,EAAN,cAAoCC,EAAAA,WAsBzC,WAAAC,CACkBC,EAChBC,EACAC,GAEAC,MAAMH,EAAIC,GAJMG,KAAAJ,GAAAA,EAjBlBI,KAAiBC,gBAAkBC,0BACnCF,KAAiBG,gBAAkBD,0BACnCF,KAAiBI,uBAAyBF,0BAC1CF,KAAiBK,eAAiBH,0BAElCF,KAAiBM,sBAAwBJ,0BAEzCF,KAAiBO,iBAAmBC,kBAOpCR,KAAQS,gBAAkBC,IAQxBV,KAAKW,aAAe,MAAAb,OAAA,EAAAA,EAAQa,YAC9B,CAEU,eAAAC,GACR,MAAO,CAELC,eAAiBC,GAAYd,KAAKa,eAAeC,GACjDC,gBAAkBD,GAAYd,KAAKe,gBAAgBD,GACnDE,mBAAqBF,GAAYd,KAAKgB,mBAAmBF,GACzDG,cAAe,CAACC,EAAYJ,IAAYd,KAAKiB,cAAcC,EAAYJ,GACvEK,cAAgBD,GAAelB,KAAKmB,cAAcD,GAClDE,kBAAmB,IAAMpB,KAAKoB,oBAE9BC,kBAAoB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B+I,uBAAuB,OAAA1H,EAAAlC,EAAO6J,uBAAP,EAAA3H,EAAyB0B,SAAU,IAIxD5D,EAAO6J,kBAAoB7J,EAAO6J,iBAAiBjG,OAAS,EAE9D,IAAA,MAAWkG,KAAa9J,EAAO6J,iBAC7B,IAEM,WAAYC,EACd5J,KAAKgB,mBAAmB4I,GACf,QAASA,GAClB5J,KAAKe,gBAAgB6I,EAEzB,OAAS5C,GACPhH,KAAKuE,OAAOyC,MACV,wBACA,aACA,2CACAA,EAEJ,CAGN,CAEA,aAAM6C,SAEE7J,KAAKoB,oBAAoB0I,YAG/B9J,KAAKS,YAAYsJ,QAGjB/J,KAAKC,gBAAgB8J,QACrB/J,KAAKG,gBAAgB4J,QACrB/J,KAAKI,uBAAuB2J,QAC5B/J,KAAKM,sBAAsByJ,QAC3B/J,KAAKK,eAAe0J,QAEpBhK,MAAM8J,SACR,GA3lBApK,EAAgBG,GAAK,mBAJhB,IAAMoK,EAANvK,ECpCA,MAAMwK,EAA6B,mBAE7BC,EAAwD,CACnEtK,GAAIqK,EACJxF,KAAM,0BACN0F,QAAS,QACTC,SAAU,CAAC,oBACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,EACT7J,aAAc,KCTL8J,EAGT,CACFP,WACAQ,OAAQ,CAAC7K,EAAUC,IACjB,IAAIkK,EAAsBC,EAA4BpK,EAAUC,GAClE6K,QAAUrH,GAAUA,EACpBsH,aAAc,CAAA"}
1
+ {"version":3,"file":"index.cjs","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 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":["_DocumentManagerPlugin","BasePlugin","constructor","id","registry","config","super","this","documentOpened$","createBehaviorEmitter","documentClosed$","activeDocumentChanged$","documentError$","documentOrderChanged$","openFileRequest$","createEmitter","loadOptions","Map","maxDocuments","buildCapability","openFileDialog","options","openDocumentUrl","openDocumentBuffer","retryDocument","documentId","closeDocument","closeAllDocuments","setActiveDocument","isDocumentOpen","Error","dispatchCoreAction","setActiveDocumentAction","getActiveDocumentId","coreState","core","activeDocumentId","getActiveDocument","activeId","_a","documents","document","getDocumentOrder","documentOrder","moveDocument","toIndex","moveDocumentAction","swapDocuments","id1","id2","order","index1","indexOf","index2","newOrder","reorderDocumentsAction","getDocument","getDocumentState","getOpenDocuments","map","filter","state","getDocumentCount","Object","keys","length","getDocumentIndex","onDocumentOpened","on","onDocumentClosed","onDocumentError","onActiveDocumentChanged","onDocumentOrderChanged","onDocumentLoaded","docState","status","delete","emit","logger","info","name","previousId","currentId","previousDocumentId","currentDocumentId","onCoreStoreUpdated","oldState","newState","onOpenFileRequest","handler","task","Task","generateDocumentId","limitError","checkDocumentLimit","reject","documentName","extractNameFromUrl","url","set","startLoadingDocument","scale","rotation","password","autoActivate","passwordProvided","file","engineTask","engine","mode","requestOptions","resolve","handleLoadTask","content","buffer","retryOptions","validation","validateRetry","valid","error","mergedOptions","get","retryLoadingDocument","retryUrlDocument","retryBufferDocument","wait","closeDocumentAction","fail","warn","documentIds","tasks","all","code","PdfErrorCode","Unknown","message","has","NotFound","context","pdfDocument","setDocumentLoaded","handleLoadError","errorMessage","reason","setDocumentError","_b","_c","Date","now","Math","random","toString","substr","urlObj","URL","filename","pathname","split","pop","decodeURIComponent","initialize","initialDocumentsCount","initialDocuments","docConfig","destroy","toPromise","clear","DocumentManagerPlugin","DOCUMENT_MANAGER_PLUGIN_ID","manifest","version","provides","requires","optional","defaultConfig","DocumentManagerPluginPackage","create","reducer","initialState"],"mappings":"gJAuCaA,EAAN,cAAoCC,EAAAA,WAsBzC,WAAAC,CACkBC,EAChBC,EACAC,GAEAC,MAAMH,EAAIC,GAJMG,KAAAJ,GAAAA,EAjBlBI,KAAiBC,gBAAkBC,0BACnCF,KAAiBG,gBAAkBD,0BACnCF,KAAiBI,uBAAyBF,0BAC1CF,KAAiBK,eAAiBH,0BAElCF,KAAiBM,sBAAwBJ,0BAEzCF,KAAiBO,iBAAmBC,kBAOpCR,KAAQS,gBAAkBC,IAQxBV,KAAKW,aAAe,MAAAb,OAAA,EAAAA,EAAQa,YAC9B,CAEU,eAAAC,GACR,MAAO,CAELC,eAAiBC,GAAYd,KAAKa,eAAeC,GACjDC,gBAAkBD,GAAYd,KAAKe,gBAAgBD,GACnDE,mBAAqBF,GAAYd,KAAKgB,mBAAmBF,GACzDG,cAAe,CAACC,EAAYJ,IA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cACT,CACF,CAMA,gBAAMK,CAAW3J,SAOf,GANAE,KAAKuE,OAAOC,KAAK,wBAAyB,aAAc,sCAAuC,CAC7F7D,aAAcX,KAAKW,aACnB+I,uBAAuB,OAAA1H,EAAAlC,EAAO6J,uBAAP,EAAA3H,EAAyB0B,SAAU,IAIxD5D,EAAO6J,kBAAoB7J,EAAO6J,iBAAiBjG,OAAS,EAE9D,IAAA,MAAWkG,KAAa9J,EAAO6J,iBAC7B,IAEM,WAAYC,EACd5J,KAAKgB,mBAAmB4I,GACf,QAASA,GAClB5J,KAAKe,gBAAgB6I,EAEzB,OAAS5C,GACPhH,KAAKuE,OAAOyC,MACV,wBACA,aACA,2CACAA,EAEJ,CAGN,CAEA,aAAM6C,SAEE7J,KAAKoB,oBAAoB0I,YAG/B9J,KAAKS,YAAYsJ,QAGjB/J,KAAKC,gBAAgB8J,QACrB/J,KAAKG,gBAAgB4J,QACrB/J,KAAKI,uBAAuB2J,QAC5B/J,KAAKM,sBAAsByJ,QAC3B/J,KAAKK,eAAe0J,QAEpBhK,MAAM8J,SACR,GA3lBApK,EAAgBG,GAAK,mBAJhB,IAAMoK,EAANvK,ECpCA,MAAMwK,EAA6B,mBAE7BC,EAAwD,CACnEtK,GAAIqK,EACJxF,KAAM,0BACN0F,QAAS,QACTC,SAAU,CAAC,oBACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACb5J,aAAc,KCRL6J,EAGT,CACFN,WACAO,OAAQ,CAAC5K,EAAUC,IACjB,IAAIkK,EAAsBC,EAA4BpK,EAAUC,GAClE4K,QAAUpH,GAAUA,EACpBqH,aAAc,CAAA"}
package/dist/index.js CHANGED
@@ -447,7 +447,6 @@ const manifest = {
447
447
  requires: [],
448
448
  optional: [],
449
449
  defaultConfig: {
450
- enabled: true,
451
450
  maxDocuments: 10
452
451
  }
453
452
  };
package/dist/index.js.map CHANGED
@@ -1 +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,SAAi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AAO,oBAAoB,OAAO,iBAAiB,SAAS,GAAG;AAEjE,iBAAW,aAAa,OAAO,kBAAkB;AAC/C,YAAI;AAEF,cAAI,YAAY,WAAW;AACzB,iBAAK,mBAAmB,SAAS;AAAA,UACnC,WAAW,SAAS,WAAW;AAC7B,iBAAK,gBAAgB,SAAS;AAAA,UAChC;AAAA,QACF,SAAS,OAAO;AACd,eAAK,OAAO;AAAA,YACV;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,QAEJ;AAAA,MACF;AAAA,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;"}
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 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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iBAAK,mBAAmB,SAAS;AAAA,UACnC,WAAW,SAAS,WAAW;AAC7B,iBAAK,gBAAgB,SAAS;AAAA,UAChC;AAAA,QACF,SAAS,OAAO;AACd,eAAK,OAAO;AAAA,YACV;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,QAEJ;AAAA,MACF;AAAA,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,cAAc;AAAA,EAAA;AAElB;ACVO,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;"}
@@ -1,2 +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]})});
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.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
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +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":"sR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,"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) {\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","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,EACKA,EACJC,IAAKC,GAAUT,EAAUK,UAAUI,IACnCC,OAAQC,GAA8BA,SAIpCX,EAAUY,cACdJ,IAAKC,GAAUT,EAAUK,UAAUI,IACnCC,OAAQC,GAA8BA,SAZlB,GAatB,CAACX,EAAWO,KCnDV,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,EAAmC,UAAzBJ,EAAcG,OACxBE,EAAoC,WAAzBL,EAAcG,OAE/B,OAAOtC,MAAAyC,EAAAA,SAAA,CAAGP,WAAS,CAAEC,gBAAeE,YAAWE,UAASC,cAC1D,0BCMO,UAAyBN,SAAEA,IAChC,MAAMQ,EAAiB/D,KACjBH,iBAAEA,GAAqBJ,KACvBgB,SAAEA,GAAalB,IAuBfyE,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,iBAAgBlE,mBAAkBmE,aACzD"}
@@ -36,7 +36,7 @@ const useOpenDocuments = (documentIds) => {
36
36
  const coreState = useCoreState();
37
37
  return useMemo(() => {
38
38
  if (!coreState) return [];
39
- if (documentIds && documentIds.length > 0) {
39
+ if (documentIds) {
40
40
  return documentIds.map((docId) => coreState.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
41
41
  }
42
42
  return coreState.documentOrder.map((docId) => coreState.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
@@ -1 +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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A,MAC9B,eAAc,gBAAW,YAAX,mBAAoB;AAAA,IAAA,CACnC;AACD,aAAS;AAAA,MACP,CAAC,WAAW;;AACV,SAAAA,MAAA,QAAQ,YAAR,gBAAAA,IAAiB,QAAQ;AAAA,MAC3B;AAAA,MACA,CAAC,UAAU;;AACT,SAAAA,MAAA,QAAQ,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;"}
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) {\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;AACpD,MAAM,+BAA+B,MAC1C,cAAqC,sBAAsB,EAAE;AAKxD,MAAM,oBAAoB,MAAM;AACrC,QAAM,YAAY,aAAA;AAElB,SAAO,QAAQ,MAAM;AACnB,QAAI,CAAC,WAAW;AACd,aAAO;AAAA,QACL,kBAAkB;AAAA,QAClB,gBA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AA;AAAA,EAAA;AAGN;AC5CO,MAAM,+BAA+B,oBAAoBC,8BAA0B,EACvF,WAAW,UAAU,EACrB,MAAA;"}
@@ -1,2 +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]})});
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.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
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +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,oBA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AuBf0E,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"}
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) {\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","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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EAAA0B,EAAoBD,eAE3BE,KACNC,UACC,OAAA3B,EAAAP,EAAQM,UAARC,EAAiB4B,QAAQD,IAE1BE,UACC,OAAA7B,EAAAP,EAAQM,UAARC,EAAiB8B,KAAKD,OAc9B,CC5CO,MAAME,EAA+BC,EAAAA,oBAAoBC,EAAAA,8BAC7DC,WAAW9C,GACX+C,gCCkBI,UAAyBjB,WAAEA,EAAAkB,SAAYA,IAC5C,MAAMC,EAAgBC,EAAAA,iBAAiBpB,GAEvC,IAAKmB,EAAe,OAAO,KAE3B,MAAME,EAAqC,YAAzBF,EAAcG,OAC1BC,EAAmC,UAAzBJ,EAAcG,OACxBE,EAAoC,WAAzBL,EAAcG,OAE/B,OAAOtC,MAAAyC,EAAAA,SAAA,CAAGP,WAAS,CAAEC,gBAAeE,YAAWE,UAASC,cAC1D,0BCMO,UAAyBN,SAAEA,IAChC,MAAMQ,EAAiB/D,KACjBH,iBAAEA,GAAqBJ,KACvBgB,SAAEA,GAAalB,IAuBfyE,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,iBAAgBlE,mBAAkBmE,aACzD"}
@@ -35,7 +35,7 @@ const useOpenDocuments = (documentIds) => {
35
35
  const coreState = useCoreState();
36
36
  return useMemo(() => {
37
37
  if (!coreState) return [];
38
- if (documentIds && documentIds.length > 0) {
38
+ if (documentIds) {
39
39
  return documentIds.map((docId) => coreState.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
40
40
  }
41
41
  return coreState.documentOrder.map((docId) => coreState.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
@@ -1 +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;AACpD,MAAM,+BAA+B,MAC1C,cAAqC,sBAAsB,EAAE;AAKxD,MAAM,oBAAoB,MAAM;AACrC,QAAM,YAAY,aAAA;AAElB,SAAO,QAAQ,MAAM;AACnB,QAAI,CAAC,WAAW;AACd,aAAO;AAAA,QACL,kBAAkB;AAAA,QAClB,gBAAgB;AAAA,MAAA;AAAA,IAEpB;AAEA,UAAM,mBAAmB,UAAU;AACnC,UAAM,iBAAiB,mBAClB,UAAU,UAAU,gBAAgB,KAAK,OAC1C;AAEJ,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ,GAAG,CAAC,SAAS,CAAC;AAChB;AAKO,MAAM,mBAAmB,CAAC,gBAA2B;AAC1D,QAAM,YAAY,aAAA;AAElB,SAAO,QAAQ,MAAM;AACnB,QAAI,CAAC,UAAW,QAAO,CAAA;AAGvB,QAAI,eAAe,YAAY,SAAS,GAAG;AACzC,aAAO,YACJ,IAAI,CAAC,UAAU,UAAU,UAAU,KAAK,CAAC,EACzC,OAAO,CAAC,QAA8B,QAAQ,QAAQ,Q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AAG,CAAC,MAAM,CAAC;AAEX,QAAM,WAAW,OAAO,MAAqC;;AAC3D,UAAM,QAAQ,OAAE,cAAmC,UAArC,mBAA6C;AAC3D,QAAI,CAAC,QAAQ,CAAC,SAAU;AACxB,UAAM,SAAS,MAAM,KAAK,YAAA;AAC1B,UAAM,WAAW,SAAS,mBAAmB;AAAA,MAC3C,MAAM,KAAK;AAAA,MACX;AAAA,MACA,aAAY,gBAAW,YAAX,mBAAoB;AAAA,MAChC,QAAO,gBAAW,YAAX,mBAAoB;AAAA,MAC3B,WAAU,gBAAW,YAAX,mBAAoB;AAAA,MAC9B,eAAc,gBAAW,YAAX,mBAAoB;AAAA,IAAA,CACnC;AACD,aAAS;AAAA,MACP,CAAC,WAAW;;AACV,SAAAA,MAAA,QAAQ,YAAR,gBAAAA,IAAiB,QAAQ;AAAA,MAC3B;AAAA,MACA,CAAC,UAAU;;AACT,SAAAA,MAAA,QAAQ,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;"}
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) {\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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IAAA,CACnC;AACD,aAAS;AAAA,MACP,CAAC,WAAW;;AACV,SAAAA,MAAA,QAAQ,YAAR,gBAAAA,IAAiB,QAAQ;AAAA,MAC3B;AAAA,MACA,CAAC,UAAU;;AACT,SAAAA,MAAA,QAAQ,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;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-document-manager");require("svelte/internal/disclose-version");const n=require("svelte/internal/client"),r=require("@embedpdf/core/svelte");function o(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const u=o(n),i=()=>r.usePlugin(t.DocumentManagerPlugin.id),c=()=>r.useCapability(t.DocumentManagerPlugin.id);function l(){const e=r.useCoreState(),t=u.derived(()=>{var t;return(null==(t=e.current)?void 0:t.activeDocumentId)??null}),n=u.derived(()=>{const t=e.current;if(!t)return null;const n=t.activeDocumentId;return n?t.documents[n]??null:null});return{get activeDocumentId(){return u.get(t)},get activeDocument(){return u.get(n)}}}function a(e){const t=r.useCoreState(),n=u.derived(()=>e?e():void 0),o=u.derived(()=>{const e=t.current;return e?u.get(n)&&u.get(n).length>0?u.get(n).map(t=>e.documents[t]).filter(e=>null!=e):e.documentOrder.map(t=>e.documents[t]).filter(e=>null!=e):[]});return{get current(){return u.get(o)}}}var s=u.from_html('<input type="file" accept="application/pdf"/>');function d(e,t){u.push(t,!0);const n=i(),r=c();let o=u.state(null),l=u.state(null),a=u.state(void 0);u.user_effect(()=>{var e;if(!(null==(e=n.plugin)?void 0:e.onOpenFileRequest))return;return n.plugin.onOpenFileRequest(({task:e,options:t})=>{var n;u.set(l,e,!0),u.set(a,t,!0),null==(n=u.get(o))||n.click()})});var d=s();d.__change=async e=>{var t,n,o,i,c;const s=null==(t=e.target.files)?void 0:t[0];if(!s||!r.provides)return;const d=await s.arrayBuffer();r.provides.openDocumentBuffer({name:s.name,buffer:d,documentId:null==(n=u.get(a))?void 0:n.documentId,scale:null==(o=u.get(a))?void 0:o.scale,rotation:null==(i=u.get(a))?void 0:i.rotation,autoActivate:null==(c=u.get(a))?void 0:c.autoActivate}).wait(e=>{var t;null==(t=u.get(l))||t.resolve(e)},e=>{var t;null==(t=u.get(l))||t.fail(e)})},u.set_style(d,"",{},{display:"none"}),u.bind_this(d,e=>u.set(o,e),()=>u.get(o)),u.append(e,d),u.pop()}u.delegate(["change"]);const p=e.createPluginPackage(t.DocumentManagerPluginPackage).addUtility(d).build();exports.DocumentContent=function(e,t){u.push(t,!0);const n=r.useDocumentState(()=>t.documentId),o=u.derived(()=>{var e;return"loading"===(null==(e=n.current)?void 0:e.status)}),i=u.derived(()=>{var e;return"error"===(null==(e=n.current)?void 0:e.status)}),c=u.derived(()=>{var e;return"loaded"===(null==(e=n.current)?void 0:e.status)});var l=u.comment(),a=u.first_child(l),s=e=>{var r=u.comment(),l=u.first_child(r);u.snippet(l,()=>t.children,()=>({documentState:n.current,isLoading:u.get(o),isError:u.get(i),isLoaded:u.get(c)})),u.append(e,r)};u.if(a,e=>{n.current&&e(s)}),u.append(e,l),u.pop()},exports.DocumentContext=function(e,t){u.push(t,!0);const n=a(),r=l(),o=c(),i={select:e=>{var t;null==(t=o.provides)||t.setActiveDocument(e)},close:e=>{var t;null==(t=o.provides)||t.closeDocument(e)},move:(e,t)=>{var n;null==(n=o.provides)||n.moveDocument(e,t)}};var s=u.comment(),d=u.first_child(s);u.snippet(d,()=>t.children,()=>({documentStates:n.current,activeDocumentId:r.activeDocumentId,actions:i})),u.append(e,s),u.pop()},exports.DocumentManagerPluginPackage=p,exports.FilePicker=d,exports.useActiveDocument=l,exports.useDocumentManagerCapability=c,exports.useDocumentManagerPlugin=i,exports.useOpenDocuments=a,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-document-manager");require("svelte/internal/disclose-version");const n=require("svelte/internal/client"),r=require("@embedpdf/core/svelte");function o(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const u=o(n),i=()=>r.usePlugin(t.DocumentManagerPlugin.id),c=()=>r.useCapability(t.DocumentManagerPlugin.id);function a(){const e=r.useCoreState(),t=u.derived(()=>{var t;return(null==(t=e.current)?void 0:t.activeDocumentId)??null}),n=u.derived(()=>{const t=e.current;if(!t)return null;const n=t.activeDocumentId;return n?t.documents[n]??null:null});return{get activeDocumentId(){return u.get(t)},get activeDocument(){return u.get(n)}}}function l(e){const t=r.useCoreState(),n=u.derived(()=>e?e():void 0),o=u.derived(()=>{const e=t.current;return e?u.get(n)?u.get(n).map(t=>e.documents[t]).filter(e=>null!=e):e.documentOrder.map(t=>e.documents[t]).filter(e=>null!=e):[]});return{get current(){return u.get(o)}}}var s=u.from_html('<input type="file" accept="application/pdf"/>');function d(e,t){u.push(t,!0);const n=i(),r=c();let o=u.state(null),a=u.state(null),l=u.state(void 0);u.user_effect(()=>{var e;if(!(null==(e=n.plugin)?void 0:e.onOpenFileRequest))return;return n.plugin.onOpenFileRequest(({task:e,options:t})=>{var n;u.set(a,e,!0),u.set(l,t,!0),null==(n=u.get(o))||n.click()})});var d=s();d.__change=async e=>{var t,n,o,i,c;const s=null==(t=e.target.files)?void 0:t[0];if(!s||!r.provides)return;const d=await s.arrayBuffer();r.provides.openDocumentBuffer({name:s.name,buffer:d,documentId:null==(n=u.get(l))?void 0:n.documentId,scale:null==(o=u.get(l))?void 0:o.scale,rotation:null==(i=u.get(l))?void 0:i.rotation,autoActivate:null==(c=u.get(l))?void 0:c.autoActivate}).wait(e=>{var t;null==(t=u.get(a))||t.resolve(e)},e=>{var t;null==(t=u.get(a))||t.fail(e)})},u.set_style(d,"",{},{display:"none"}),u.bind_this(d,e=>u.set(o,e),()=>u.get(o)),u.append(e,d),u.pop()}u.delegate(["change"]);const p=e.createPluginPackage(t.DocumentManagerPluginPackage).addUtility(d).build();exports.DocumentContent=function(e,t){u.push(t,!0);const n=r.useDocumentState(()=>t.documentId),o=u.derived(()=>{var e;return"loading"===(null==(e=n.current)?void 0:e.status)}),i=u.derived(()=>{var e;return"error"===(null==(e=n.current)?void 0:e.status)}),c=u.derived(()=>{var e;return"loaded"===(null==(e=n.current)?void 0:e.status)});var a=u.comment(),l=u.first_child(a),s=e=>{var r=u.comment(),a=u.first_child(r);u.snippet(a,()=>t.children,()=>({documentState:n.current,isLoading:u.get(o),isError:u.get(i),isLoaded:u.get(c)})),u.append(e,r)};u.if(l,e=>{n.current&&e(s)}),u.append(e,a),u.pop()},exports.DocumentContext=function(e,t){u.push(t,!0);const n=l(),r=a(),o=c(),i={select:e=>{var t;null==(t=o.provides)||t.setActiveDocument(e)},close:e=>{var t;null==(t=o.provides)||t.closeDocument(e)},move:(e,t)=>{var n;null==(n=o.provides)||n.moveDocument(e,t)}};var s=u.comment(),d=u.first_child(s);u.snippet(d,()=>t.children,()=>({documentStates:n.current,activeDocumentId:r.activeDocumentId,actions:i})),u.append(e,s),u.pop()},exports.DocumentManagerPluginPackage=p,exports.FilePicker=d,exports.useActiveDocument=a,exports.useDocumentManagerCapability=c,exports.useDocumentManagerPlugin=i,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
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-document-manager.svelte.ts","../../src/svelte/components/FilePicker.svelte","../../src/svelte/index.ts","../../src/svelte/components/DocumentContent.svelte","../../src/svelte/components/DocumentContext.svelte"],"sourcesContent":["import { useCapability, usePlugin, useCoreState } from '@embedpdf/core/svelte';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport type { 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 function useActiveDocument() {\n // Keep reference to avoid destructuring - maintains reactivity\n const coreStateRef = useCoreState();\n\n // Use $derived.by for computed values that depend on the reactive coreState\n const activeDocumentId = $derived.by(() => {\n return coreStateRef.current?.activeDocumentId ?? null;\n });\n\n const activeDocument = $derived.by(() => {\n const core = coreStateRef.current;\n if (!core) return null;\n\n const docId = core.activeDocumentId;\n return docId ? (core.documents[docId] ?? null) : null;\n });\n\n return {\n get activeDocumentId() {\n return activeDocumentId;\n },\n get activeDocument() {\n return activeDocument;\n },\n };\n}\n\n/**\n * Hook for all open documents (in order)\n * @param getDocumentIds Optional getter function for specific document IDs to filter/order by\n */\nexport function useOpenDocuments(getDocumentIds?: () => string[] | undefined) {\n // Keep reference to avoid destructuring - maintains reactivity\n const coreStateRef = useCoreState();\n\n // Derive documentIds reactively if getter is provided\n const documentIds = $derived(getDocumentIds ? getDocumentIds() : undefined);\n\n // Use $derived.by for computed array of documents\n const documents = $derived.by(() => {\n const core = coreStateRef.current;\n if (!core) return [];\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds && documentIds.length > 0) {\n return documentIds\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return core.documentOrder\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n });\n\n return {\n get current() {\n return documents;\n },\n };\n}\n","<script lang=\"ts\">\n import { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\n import type { Task } from '@embedpdf/models';\n import type { PdfErrorReason } from '@embedpdf/models';\n import type {\n OpenDocumentResponse,\n OpenFileDialogOptions,\n } from '@embedpdf/plugin-document-manager';\n\n const documentManagerPlugin = useDocumentManagerPlugin();\n const documentManagerCapability = useDocumentManagerCapability();\n\n let inputRef = $state<HTMLInputElement | null>(null);\n let taskRef = $state<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\n let optionsRef = $state<OpenFileDialogOptions | undefined>(undefined);\n\n $effect(() => {\n if (!documentManagerPlugin.plugin?.onOpenFileRequest) return;\n\n const unsubscribe = documentManagerPlugin.plugin.onOpenFileRequest(({ task, options }) => {\n taskRef = task;\n optionsRef = options;\n inputRef?.click();\n });\n\n return unsubscribe;\n });\n\n const onChange = async (event: Event) => {\n const target = event.target as HTMLInputElement;\n const file = target.files?.[0];\n if (!file || !documentManagerCapability.provides) return;\n\n const buffer = await file.arrayBuffer();\n const openTask = documentManagerCapability.provides.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef?.documentId,\n scale: optionsRef?.scale,\n rotation: optionsRef?.rotation,\n autoActivate: optionsRef?.autoActivate,\n });\n\n openTask.wait(\n (result) => {\n taskRef?.resolve(result);\n },\n (error) => {\n taskRef?.fail(error);\n },\n );\n };\n</script>\n\n<input\n bind:this={inputRef}\n type=\"file\"\n accept=\"application/pdf\"\n style:display=\"none\"\n onchange={onChange}\n/>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { DocumentManagerPluginPackage as BaseDocumentManagerPackage } from '@embedpdf/plugin-document-manager';\n\nimport { FilePicker, DocumentContext, DocumentContent } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-document-manager';\n\nexport const DocumentManagerPluginPackage = createPluginPackage(BaseDocumentManagerPackage)\n .addUtility(FilePicker)\n .build();\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import type { DocumentState } from '@embedpdf/core';\n\n export interface DocumentContentRenderProps {\n documentState: DocumentState;\n isLoading: boolean;\n isError: boolean;\n isLoaded: boolean;\n }\n\n interface DocumentContentProps {\n documentId: string | null;\n children: Snippet<[DocumentContentRenderProps]>;\n }\n\n let { documentId, children }: DocumentContentProps = $props();\n\n const docState = useDocumentState(() => documentId);\n\n const isLoading = $derived(docState.current?.status === 'loading');\n const isError = $derived(docState.current?.status === 'error');\n const isLoaded = $derived(docState.current?.status === 'loaded');\n</script>\n\n<!--\n Headless component for rendering document content with loading/error states\n \n @example\n <DocumentContent {documentId}>\n {#snippet children({ documentState, isLoading, isError, isLoaded })}\n {#if isLoading}\n <LoadingSpinner />\n {:else if isError}\n <ErrorMessage />\n {:else if isLoaded}\n <PDFViewer {documentState} />\n {/if}\n {/snippet}\n </DocumentContent>\n-->\n{#if docState.current}\n {@render children({\n documentState: docState.current,\n isLoading,\n isError,\n isLoaded,\n })}\n{/if}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\n import type { DocumentState } from '@embedpdf/core';\n\n export interface TabActions {\n select: (documentId: string) => void;\n close: (documentId: string) => void;\n move: (documentId: string, toIndex: number) => void;\n }\n\n export interface DocumentContextRenderProps {\n documentStates: DocumentState[];\n activeDocumentId: string | null;\n actions: TabActions;\n }\n\n interface DocumentContextProps {\n children: Snippet<[DocumentContextRenderProps]>;\n }\n\n let { children }: DocumentContextProps = $props();\n\n const openDocuments = useOpenDocuments();\n const activeDoc = useActiveDocument();\n const capability = useDocumentManagerCapability();\n\n const actions: TabActions = {\n select: (documentId: string) => {\n capability.provides?.setActiveDocument(documentId);\n },\n close: (documentId: string) => {\n capability.provides?.closeDocument(documentId);\n },\n move: (documentId: string, toIndex: number) => {\n capability.provides?.moveDocument(documentId, toIndex);\n },\n };\n</script>\n\n<!--\n Headless component for managing document tabs\n Provides all state and actions, completely UI-agnostic\n \n @example\n <DocumentContext>\n {#snippet children({ documentStates, activeDocumentId, actions })}\n <div class=\"tabs\">\n {#each documentStates as doc (doc.id)}\n <button\n onclick={() => actions.select(doc.id)}\n class:active={doc.id === activeDocumentId}\n >\n {doc.name}\n <button onclick={(e) => { e.stopPropagation(); actions.close(doc.id); }}>×</button>\n </button>\n {/each}\n </div>\n {/snippet}\n </DocumentContext>\n-->\n{@render children({\n documentStates: openDocuments.current,\n activeDocumentId: activeDoc.activeDocumentId,\n actions,\n})}\n"],"names":["useDocumentManagerPlugin","usePlugin","DocumentManagerPlugin","id","useDocumentManagerCapability","useCapability","useActiveDocument","coreStateRef","useCoreState","activeDocumentId","_a","current","activeDocument","core","docId","documents","useOpenDocuments","getDocumentIds","documentIds","$","derived","get","length","map","filter","doc","documentOrder","documentManagerPlugin","documentManagerCapability","inputRef","taskRef","optionsRef","user_effect","plugin","onOpenFileRequest","task","options","set","click","async","event","file","target","files","provides","buffer","arrayBuffer","openDocumentBuffer","name","documentId","scale","rotation","autoActivate","wait","result","resolve","error","fail","bind_this","input","$$value","DocumentManagerPluginPackage","createPluginPackage","BaseDocumentManagerPackage","addUtility","FilePicker","build","docState","useDocumentState","$$props","isLoading","status","isError","isLoaded","documentState","$$render","consequent","openDocuments","activeDoc","capability","actions","select","setActiveDocument","close","closeDocument","move","toIndex","moveDocument","documentStates"],"mappings":"kjBAIaA,EAAA,IACXC,YAAiCC,EAAAA,sBAAsBC,IAC5CC,EAAA,IACX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../src/svelte/hooks/use-document-manager.svelte.ts","../../src/svelte/components/FilePicker.svelte","../../src/svelte/index.ts","../../src/svelte/components/DocumentContent.svelte","../../src/svelte/components/DocumentContext.svelte"],"sourcesContent":["import { useCapability, usePlugin, useCoreState } from '@embedpdf/core/svelte';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport type { 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 function useActiveDocument() {\n // Keep reference to avoid destructuring - maintains reactivity\n const coreStateRef = useCoreState();\n\n // Use $derived.by for computed values that depend on the reactive coreState\n const activeDocumentId = $derived.by(() => {\n return coreStateRef.current?.activeDocumentId ?? null;\n });\n\n const activeDocument = $derived.by(() => {\n const core = coreStateRef.current;\n if (!core) return null;\n\n const docId = core.activeDocumentId;\n return docId ? (core.documents[docId] ?? null) : null;\n });\n\n return {\n get activeDocumentId() {\n return activeDocumentId;\n },\n get activeDocument() {\n return activeDocument;\n },\n };\n}\n\n/**\n * Hook for all open documents (in order)\n * @param getDocumentIds Optional getter function for specific document IDs to filter/order by\n */\nexport function useOpenDocuments(getDocumentIds?: () => string[] | undefined) {\n // Keep reference to avoid destructuring - maintains reactivity\n const coreStateRef = useCoreState();\n\n // Derive documentIds reactively if getter is provided\n const documentIds = $derived(getDocumentIds ? getDocumentIds() : undefined);\n\n // Use $derived.by for computed array of documents\n const documents = $derived.by(() => {\n const core = coreStateRef.current;\n if (!core) return [];\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds) {\n return documentIds\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return core.documentOrder\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n });\n\n return {\n get current() {\n return documents;\n },\n };\n}\n","<script lang=\"ts\">\n import { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\n import type { Task } from '@embedpdf/models';\n import type { PdfErrorReason } from '@embedpdf/models';\n import type {\n OpenDocumentResponse,\n OpenFileDialogOptions,\n } from '@embedpdf/plugin-document-manager';\n\n const documentManagerPlugin = useDocumentManagerPlugin();\n const documentManagerCapability = useDocumentManagerCapability();\n\n let inputRef = $state<HTMLInputElement | null>(null);\n let taskRef = $state<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\n let optionsRef = $state<OpenFileDialogOptions | undefined>(undefined);\n\n $effect(() => {\n if (!documentManagerPlugin.plugin?.onOpenFileRequest) return;\n\n const unsubscribe = documentManagerPlugin.plugin.onOpenFileRequest(({ task, options }) => {\n taskRef = task;\n optionsRef = options;\n inputRef?.click();\n });\n\n return unsubscribe;\n });\n\n const onChange = async (event: Event) => {\n const target = event.target as HTMLInputElement;\n const file = target.files?.[0];\n if (!file || !documentManagerCapability.provides) return;\n\n const buffer = await file.arrayBuffer();\n const openTask = documentManagerCapability.provides.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef?.documentId,\n scale: optionsRef?.scale,\n rotation: optionsRef?.rotation,\n autoActivate: optionsRef?.autoActivate,\n });\n\n openTask.wait(\n (result) => {\n taskRef?.resolve(result);\n },\n (error) => {\n taskRef?.fail(error);\n },\n );\n };\n</script>\n\n<input\n bind:this={inputRef}\n type=\"file\"\n accept=\"application/pdf\"\n style:display=\"none\"\n onchange={onChange}\n/>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { DocumentManagerPluginPackage as BaseDocumentManagerPackage } from '@embedpdf/plugin-document-manager';\n\nimport { FilePicker, DocumentContext, DocumentContent } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-document-manager';\n\nexport const DocumentManagerPluginPackage = createPluginPackage(BaseDocumentManagerPackage)\n .addUtility(FilePicker)\n .build();\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import type { DocumentState } from '@embedpdf/core';\n\n export interface DocumentContentRenderProps {\n documentState: DocumentState;\n isLoading: boolean;\n isError: boolean;\n isLoaded: boolean;\n }\n\n interface DocumentContentProps {\n documentId: string | null;\n children: Snippet<[DocumentContentRenderProps]>;\n }\n\n let { documentId, children }: DocumentContentProps = $props();\n\n const docState = useDocumentState(() => documentId);\n\n const isLoading = $derived(docState.current?.status === 'loading');\n const isError = $derived(docState.current?.status === 'error');\n const isLoaded = $derived(docState.current?.status === 'loaded');\n</script>\n\n<!--\n Headless component for rendering document content with loading/error states\n \n @example\n <DocumentContent {documentId}>\n {#snippet children({ documentState, isLoading, isError, isLoaded })}\n {#if isLoading}\n <LoadingSpinner />\n {:else if isError}\n <ErrorMessage />\n {:else if isLoaded}\n <PDFViewer {documentState} />\n {/if}\n {/snippet}\n </DocumentContent>\n-->\n{#if docState.current}\n {@render children({\n documentState: docState.current,\n isLoading,\n isError,\n isLoaded,\n })}\n{/if}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\n import type { DocumentState } from '@embedpdf/core';\n\n export interface TabActions {\n select: (documentId: string) => void;\n close: (documentId: string) => void;\n move: (documentId: string, toIndex: number) => void;\n }\n\n export interface DocumentContextRenderProps {\n documentStates: DocumentState[];\n activeDocumentId: string | null;\n actions: TabActions;\n }\n\n interface DocumentContextProps {\n children: Snippet<[DocumentContextRenderProps]>;\n }\n\n let { children }: DocumentContextProps = $props();\n\n const openDocuments = useOpenDocuments();\n const activeDoc = useActiveDocument();\n const capability = useDocumentManagerCapability();\n\n const actions: TabActions = {\n select: (documentId: string) => {\n capability.provides?.setActiveDocument(documentId);\n },\n close: (documentId: string) => {\n capability.provides?.closeDocument(documentId);\n },\n move: (documentId: string, toIndex: number) => {\n capability.provides?.moveDocument(documentId, toIndex);\n },\n };\n</script>\n\n<!--\n Headless component for managing document tabs\n Provides all state and actions, completely UI-agnostic\n \n @example\n <DocumentContext>\n {#snippet children({ documentStates, activeDocumentId, actions })}\n <div class=\"tabs\">\n {#each documentStates as doc (doc.id)}\n <button\n onclick={() => actions.select(doc.id)}\n class:active={doc.id === activeDocumentId}\n >\n {doc.name}\n <button onclick={(e) => { e.stopPropagation(); actions.close(doc.id); }}>×</button>\n </button>\n {/each}\n </div>\n {/snippet}\n </DocumentContext>\n-->\n{@render children({\n documentStates: openDocuments.current,\n activeDocumentId: activeDoc.activeDocumentId,\n actions,\n})}\n"],"names":["useDocumentManagerPlugin","usePlugin","DocumentManagerPlugin","id","useDocumentManagerCapability","useCapability","useActiveDocument","coreStateRef","useCoreState","activeDocumentId","_a","current","activeDocument","core","docId","documents","useOpenDocuments","getDocumentIds","documentIds","$","derived","get","map","filter","doc","documentOrder","documentManagerPlugin","documentManagerCapability","inputRef","taskRef","optionsRef","user_effect","plugin","onOpenFileRequest","task","options","set","click","async","event","file","target","files","provides","buffer","arrayBuffer","openDocumentBuffer","name","documentId","scale","rotation","autoActivate","wait","result","resolve","error","fail","bind_this","input","$$value","DocumentManagerPluginPackage","createPluginPackage","BaseDocumentManagerPackage","addUtility","FilePicker","build","docState","useDocumentState","$$props","isLoading","status","isError","isLoaded","documentState","$$render","consequent","openDocuments","activeDoc","capability","actions","select","setActiveDocument","close","closeDocument","move","toIndex","moveDocument","documentStates"],"mappings":"kjBAIaA,EAAA,IACXC,YAAiCC,EAAAA,sBAAsBC,IAC5CC,EAAA,IACXC,gBAAqCH,EAAAA,sBAAsBC,IAK7C,SAAAG,IAER,MAAAC,EAAeC,EAAAA,eAGfC,uBACG,OAAA,OAAAC,EAAAH,EAAaI,cAAb,EAAAD,EAAsBD,mBAAoB,OAG7CG,uBACEC,EAAON,EAAaI,QACrB,IAAAE,SAAa,WAEZC,EAAQD,EAAKJ,wBACZK,EAASD,EAAKE,UAAUD,IAAU,KAAQ,cAI7C,oBAAAL,gBACKA,E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OAAS2B,KAAKD,4CAOTpC,EAAAsC,UAAAC,EAAAC,GAAAxC,EAAAiB,IAAAR,eAAAA,yBAHb,wBC1CO,MAAMgC,EAA+BC,EAAAA,oBAAoBC,EAAAA,8BAC7DC,WAAWC,GACXC,2DCOK,MAAAC,EAAWC,EAAAA,iBAAgB,IAAAC,EAAApB,YAE3BqB,uBAAqB,MAA6B,aAA7B,OAAA3D,EAAAwD,EAASvD,kBAAS2D,UACvCC,uBAAmB,MAA6B,WAA7B,OAAA7D,EAAAwD,EAASvD,kBAAS2D,UACrCE,uBAAoB,MAA6B,YAA7B,OAAA9D,EAAAwD,EAASvD,kBAAS2D,2HAqB1CG,cAAeP,EAASvD,QACxB0D,gBAAAA,GACAE,cAAAA,GACAC,eAAAA,gCALCN,EAASvD,SAAO+D,EAAAC,0BAlBrB,qDCDQ,MAAAC,EAAgB5D,IAChB6D,EAAYvE,IACZwE,EAAa1E,IAEb2E,EAAmB,CACvBC,OAAShC,UACP,OAAAtC,EAAAoE,EAAWnC,aAAUsC,kBAAkBjC,IAEzCkC,MAAQlC,UACN,OAAAtC,EAAAoE,EAAWnC,aAAUwC,cAAcnC,IAErCoC,KAAI,CAAGpC,EAAoBqC,WACzB,OAAA3E,EAAAoE,EAAWnC,WAAXjC,EAAqB4E,aAAatC,EAAYqC,2EA2BlDE,eAAgBX,EAAcjE,QAC9BF,iBAAkBoE,EAAUpE,iBAC5BsE,kCA1BF"}
@@ -33,7 +33,7 @@ function useOpenDocuments(getDocumentIds) {
33
33
  const documents = $.derived(() => {
34
34
  const core = coreStateRef.current;
35
35
  if (!core) return [];
36
- if ($.get(documentIds) && $.get(documentIds).length > 0) {
36
+ if ($.get(documentIds)) {
37
37
  return $.get(documentIds).map((docId) => core.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
38
38
  }
39
39
  return core.documentOrder.map((docId) => core.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-document-manager.svelte.ts","../../src/svelte/components/FilePicker.svelte","../../src/svelte/components/DocumentContext.svelte","../../src/svelte/components/DocumentContent.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin, useCoreState } from '@embedpdf/core/svelte';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport type { 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 function useActiveDocument() {\n // Keep reference to avoid destructuring - maintains reactivity\n const coreStateRef = useCoreState();\n\n // Use $derived.by for computed values that depend on the reactive coreState\n const activeDocumentId = $derived.by(() => {\n return coreStateRef.current?.activeDocumentId ?? null;\n });\n\n const activeDocument = $derived.by(() => {\n const core = coreStateRef.current;\n if (!core) return null;\n\n const docId = core.activeDocumentId;\n return docId ? (core.documents[docId] ?? null) : null;\n });\n\n return {\n get activeDocumentId() {\n return activeDocumentId;\n },\n get activeDocument() {\n return activeDocument;\n },\n };\n}\n\n/**\n * Hook for all open documents (in order)\n * @param getDocumentIds Optional getter function for specific document IDs to filter/order by\n */\nexport function useOpenDocuments(getDocumentIds?: () => string[] | undefined) {\n // Keep reference to avoid destructuring - maintains reactivity\n const coreStateRef = useCoreState();\n\n // Derive documentIds reactively if getter is provided\n const documentIds = $derived(getDocumentIds ? getDocumentIds() : undefined);\n\n // Use $derived.by for computed array of documents\n const documents = $derived.by(() => {\n const core = coreStateRef.current;\n if (!core) return [];\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds && documentIds.length > 0) {\n return documentIds\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return core.documentOrder\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n });\n\n return {\n get current() {\n return documents;\n },\n };\n}\n","<script lang=\"ts\">\n import { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\n import type { Task } from '@embedpdf/models';\n import type { PdfErrorReason } from '@embedpdf/models';\n import type {\n OpenDocumentResponse,\n OpenFileDialogOptions,\n } from '@embedpdf/plugin-document-manager';\n\n const documentManagerPlugin = useDocumentManagerPlugin();\n const documentManagerCapability = useDocumentManagerCapability();\n\n let inputRef = $state<HTMLInputElement | null>(null);\n let taskRef = $state<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\n let optionsRef = $state<OpenFileDialogOptions | undefined>(undefined);\n\n $effect(() => {\n if (!documentManagerPlugin.plugin?.onOpenFileRequest) return;\n\n const unsubscribe = documentManagerPlugin.plugin.onOpenFileRequest(({ task, options }) => {\n taskRef = task;\n optionsRef = options;\n inputRef?.click();\n });\n\n return unsubscribe;\n });\n\n const onChange = async (event: Event) => {\n const target = event.target as HTMLInputElement;\n const file = target.files?.[0];\n if (!file || !documentManagerCapability.provides) return;\n\n const buffer = await file.arrayBuffer();\n const openTask = documentManagerCapability.provides.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef?.documentId,\n scale: optionsRef?.scale,\n rotation: optionsRef?.rotation,\n autoActivate: optionsRef?.autoActivate,\n });\n\n openTask.wait(\n (result) => {\n taskRef?.resolve(result);\n },\n (error) => {\n taskRef?.fail(error);\n },\n );\n };\n</script>\n\n<input\n bind:this={inputRef}\n type=\"file\"\n accept=\"application/pdf\"\n style:display=\"none\"\n onchange={onChange}\n/>\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\n import type { DocumentState } from '@embedpdf/core';\n\n export interface TabActions {\n select: (documentId: string) => void;\n close: (documentId: string) => void;\n move: (documentId: string, toIndex: number) => void;\n }\n\n export interface DocumentContextRenderProps {\n documentStates: DocumentState[];\n activeDocumentId: string | null;\n actions: TabActions;\n }\n\n interface DocumentContextProps {\n children: Snippet<[DocumentContextRenderProps]>;\n }\n\n let { children }: DocumentContextProps = $props();\n\n const openDocuments = useOpenDocuments();\n const activeDoc = useActiveDocument();\n const capability = useDocumentManagerCapability();\n\n const actions: TabActions = {\n select: (documentId: string) => {\n capability.provides?.setActiveDocument(documentId);\n },\n close: (documentId: string) => {\n capability.provides?.closeDocument(documentId);\n },\n move: (documentId: string, toIndex: number) => {\n capability.provides?.moveDocument(documentId, toIndex);\n },\n };\n</script>\n\n<!--\n Headless component for managing document tabs\n Provides all state and actions, completely UI-agnostic\n \n @example\n <DocumentContext>\n {#snippet children({ documentStates, activeDocumentId, actions })}\n <div class=\"tabs\">\n {#each documentStates as doc (doc.id)}\n <button\n onclick={() => actions.select(doc.id)}\n class:active={doc.id === activeDocumentId}\n >\n {doc.name}\n <button onclick={(e) => { e.stopPropagation(); actions.close(doc.id); }}>×</button>\n </button>\n {/each}\n </div>\n {/snippet}\n </DocumentContext>\n-->\n{@render children({\n documentStates: openDocuments.current,\n activeDocumentId: activeDoc.activeDocumentId,\n actions,\n})}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import type { DocumentState } from '@embedpdf/core';\n\n export interface DocumentContentRenderProps {\n documentState: DocumentState;\n isLoading: boolean;\n isError: boolean;\n isLoaded: boolean;\n }\n\n interface DocumentContentProps {\n documentId: string | null;\n children: Snippet<[DocumentContentRenderProps]>;\n }\n\n let { documentId, children }: DocumentContentProps = $props();\n\n const docState = useDocumentState(() => documentId);\n\n const isLoading = $derived(docState.current?.status === 'loading');\n const isError = $derived(docState.current?.status === 'error');\n const isLoaded = $derived(docState.current?.status === 'loaded');\n</script>\n\n<!--\n Headless component for rendering document content with loading/error states\n \n @example\n <DocumentContent {documentId}>\n {#snippet children({ documentState, isLoading, isError, isLoaded })}\n {#if isLoading}\n <LoadingSpinner />\n {:else if isError}\n <ErrorMessage />\n {:else if isLoaded}\n <PDFViewer {documentState} />\n {/if}\n {/snippet}\n </DocumentContent>\n-->\n{#if docState.current}\n {@render children({\n documentState: docState.current,\n isLoading,\n isError,\n isLoaded,\n })}\n{/if}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { DocumentManagerPluginPackage as BaseDocumentManagerPackage } from '@embedpdf/plugin-document-manager';\n\nimport { FilePicker, DocumentContext, DocumentContent } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-document-manager';\n\nexport const DocumentManagerPluginPackage = createPluginPackage(BaseDocumentManagerPackage)\n .addUtility(FilePicker)\n .build();\n"],"names":["_a","BaseDocumentManagerPackage"],"mappings":";;;;;;AAIa,MAAA,2BAAA,MACX,UAAiC,sBAAsB,EAAE;AAC9C,MAAA,+BAAA,MACX,cAAqC,sBAAsB,EAAE;AAK/C,SAAA,oBAAoB;AAE5B,QAAA,eAAe,aAAA;AAGf,QAAA,mCAAqC;;AAClC,aAAA,kBAAa,YAAb,mBAAsB,qBAAoB;AAAA,EACnD,CAAC;AAEK,QAAA,iCAAmC;UACjC,OAAO,aAAa;AACrB,QAAA,CAAA,aAAa;UAEZ,QAAQ,KAAK;WACZ,QAAS,KAAK,UAAU,KAAK,KAAK,OAAQ;AAAA,EACnD,CAAC;;IAGK,IAAA,mBAAmB;mBACd,gBAAA;AAAA,IACT;AAAA,IACI,IAAA,iBAAiB;mBACZ,cAAA;AAAA,IACT;AAAA;AAEJ;SAMgB,iBAAiB,gBAA6C;AAEtE,QAAA,eAAe,aAAA;AAGf,QAAA,cAAA,EAAA,QAAA,MAAuB,iBAAiB,eAAA,UAA4B;AAGpE,QAAA,4BAA8B;UAC5B,OAAO,aAAa;SACrB,KAAA,QAAA,CAAA;AAGD,QAAA,EAAA,IAAA,WAAA,WAAe,WAAA,EAAY,SAAS,GAAG;mBAClC,WAAA,EACJ,IAAA,CAAK,UAAU,KAAK,UAAU,KAAK,GACnC,QAAQ,QAA8B,QAAQ,QAAQ,cAAiB;AAAA,IAC5E;WAGO,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YAAA,EAAA,IAAA,gCAAA,QAAQ,CAAA;;;AAHrB;;4CCpDA;;AAuBQ,QAAA,gBAAgB,iBAAgB;AAChC,QAAA,YAAY,kBAAiB;AAC7B,QAAA,aAAa,6BAA4B;QAEzC,UAAmB;AAAA,IACvB,QAAM,CAAG,eAAuB;;AAC9B,uBAAW,aAAX,mBAAqB,kBAAkB;AAAA,IACzC;AAAA,IACA,OAAK,CAAG,eAAuB;;AAC7B,uBAAW,aAAX,mBAAqB,cAAc;AAAA,IACrC;AAAA,IACA,MAAI,CAAG,YAAoB,YAAoB;;AAC7C,uBAAW,aAAX,mBAAqB,aAAa,YAAY;AAAA,IAChD;AAAA;;;;IA0BF,gBAAgB,cAAc;AAAA,IAC9B,kBAAkB,UAAU;AAAA,IAC5B;AAAA;;;AA1BF;4CCtCA;;AAmBQ,QAAA,WAAW,iBAAgB,MAAA,QAAA,UAAA;AAE3B,QAAA;;AAAqB,2BAAS,YAAT,mBAAkB,YAAW;AAAA,GAAS;AAC3D,QAAA;;AAAmB,2BAAS,YAAT,mBAAkB,YAAW;AAAA,GAAO;AACvD,QAAA;;AAAoB,2BAAS,YAAT,mBAAkB,YAAW;AAAA,GAAQ;;;;;;;;QAqB7D,eAAe,SAAS;AAAA,QACxB,iBAAA,SAAS;AAAA,QACT,eAAA,OAAO;AAAA,QACP,gBAAA,QAAQ;AAAA;;;;AALP,UAAA,SAAS,QAAO,UAAA,UAAA;AAAA;;;;AAlBrB;ACdO,MAAM,+BAA+B,oBAAoBC,8BAA0B,EACvF,WAAW,UAAU,EACrB,MAAA;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-document-manager.svelte.ts","../../src/svelte/components/FilePicker.svelte","../../src/svelte/components/DocumentContext.svelte","../../src/svelte/components/DocumentContent.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin, useCoreState } from '@embedpdf/core/svelte';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport type { 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 function useActiveDocument() {\n // Keep reference to avoid destructuring - maintains reactivity\n const coreStateRef = useCoreState();\n\n // Use $derived.by for computed values that depend on the reactive coreState\n const activeDocumentId = $derived.by(() => {\n return coreStateRef.current?.activeDocumentId ?? null;\n });\n\n const activeDocument = $derived.by(() => {\n const core = coreStateRef.current;\n if (!core) return null;\n\n const docId = core.activeDocumentId;\n return docId ? (core.documents[docId] ?? null) : null;\n });\n\n return {\n get activeDocumentId() {\n return activeDocumentId;\n },\n get activeDocument() {\n return activeDocument;\n },\n };\n}\n\n/**\n * Hook for all open documents (in order)\n * @param getDocumentIds Optional getter function for specific document IDs to filter/order by\n */\nexport function useOpenDocuments(getDocumentIds?: () => string[] | undefined) {\n // Keep reference to avoid destructuring - maintains reactivity\n const coreStateRef = useCoreState();\n\n // Derive documentIds reactively if getter is provided\n const documentIds = $derived(getDocumentIds ? getDocumentIds() : undefined);\n\n // Use $derived.by for computed array of documents\n const documents = $derived.by(() => {\n const core = coreStateRef.current;\n if (!core) return [];\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds) {\n return documentIds\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return core.documentOrder\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n });\n\n return {\n get current() {\n return documents;\n },\n };\n}\n","<script lang=\"ts\">\n import { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\n import type { Task } from '@embedpdf/models';\n import type { PdfErrorReason } from '@embedpdf/models';\n import type {\n OpenDocumentResponse,\n OpenFileDialogOptions,\n } from '@embedpdf/plugin-document-manager';\n\n const documentManagerPlugin = useDocumentManagerPlugin();\n const documentManagerCapability = useDocumentManagerCapability();\n\n let inputRef = $state<HTMLInputElement | null>(null);\n let taskRef = $state<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\n let optionsRef = $state<OpenFileDialogOptions | undefined>(undefined);\n\n $effect(() => {\n if (!documentManagerPlugin.plugin?.onOpenFileRequest) return;\n\n const unsubscribe = documentManagerPlugin.plugin.onOpenFileRequest(({ task, options }) => {\n taskRef = task;\n optionsRef = options;\n inputRef?.click();\n });\n\n return unsubscribe;\n });\n\n const onChange = async (event: Event) => {\n const target = event.target as HTMLInputElement;\n const file = target.files?.[0];\n if (!file || !documentManagerCapability.provides) return;\n\n const buffer = await file.arrayBuffer();\n const openTask = documentManagerCapability.provides.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef?.documentId,\n scale: optionsRef?.scale,\n rotation: optionsRef?.rotation,\n autoActivate: optionsRef?.autoActivate,\n });\n\n openTask.wait(\n (result) => {\n taskRef?.resolve(result);\n },\n (error) => {\n taskRef?.fail(error);\n },\n );\n };\n</script>\n\n<input\n bind:this={inputRef}\n type=\"file\"\n accept=\"application/pdf\"\n style:display=\"none\"\n onchange={onChange}\n/>\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\n import type { DocumentState } from '@embedpdf/core';\n\n export interface TabActions {\n select: (documentId: string) => void;\n close: (documentId: string) => void;\n move: (documentId: string, toIndex: number) => void;\n }\n\n export interface DocumentContextRenderProps {\n documentStates: DocumentState[];\n activeDocumentId: string | null;\n actions: TabActions;\n }\n\n interface DocumentContextProps {\n children: Snippet<[DocumentContextRenderProps]>;\n }\n\n let { children }: DocumentContextProps = $props();\n\n const openDocuments = useOpenDocuments();\n const activeDoc = useActiveDocument();\n const capability = useDocumentManagerCapability();\n\n const actions: TabActions = {\n select: (documentId: string) => {\n capability.provides?.setActiveDocument(documentId);\n },\n close: (documentId: string) => {\n capability.provides?.closeDocument(documentId);\n },\n move: (documentId: string, toIndex: number) => {\n capability.provides?.moveDocument(documentId, toIndex);\n },\n };\n</script>\n\n<!--\n Headless component for managing document tabs\n Provides all state and actions, completely UI-agnostic\n \n @example\n <DocumentContext>\n {#snippet children({ documentStates, activeDocumentId, actions })}\n <div class=\"tabs\">\n {#each documentStates as doc (doc.id)}\n <button\n onclick={() => actions.select(doc.id)}\n class:active={doc.id === activeDocumentId}\n >\n {doc.name}\n <button onclick={(e) => { e.stopPropagation(); actions.close(doc.id); }}>×</button>\n </button>\n {/each}\n </div>\n {/snippet}\n </DocumentContext>\n-->\n{@render children({\n documentStates: openDocuments.current,\n activeDocumentId: activeDoc.activeDocumentId,\n actions,\n})}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import type { DocumentState } from '@embedpdf/core';\n\n export interface DocumentContentRenderProps {\n documentState: DocumentState;\n isLoading: boolean;\n isError: boolean;\n isLoaded: boolean;\n }\n\n interface DocumentContentProps {\n documentId: string | null;\n children: Snippet<[DocumentContentRenderProps]>;\n }\n\n let { documentId, children }: DocumentContentProps = $props();\n\n const docState = useDocumentState(() => documentId);\n\n const isLoading = $derived(docState.current?.status === 'loading');\n const isError = $derived(docState.current?.status === 'error');\n const isLoaded = $derived(docState.current?.status === 'loaded');\n</script>\n\n<!--\n Headless component for rendering document content with loading/error states\n \n @example\n <DocumentContent {documentId}>\n {#snippet children({ documentState, isLoading, isError, isLoaded })}\n {#if isLoading}\n <LoadingSpinner />\n {:else if isError}\n <ErrorMessage />\n {:else if isLoaded}\n <PDFViewer {documentState} />\n {/if}\n {/snippet}\n </DocumentContent>\n-->\n{#if docState.current}\n {@render children({\n documentState: docState.current,\n isLoading,\n isError,\n isLoaded,\n })}\n{/if}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { DocumentManagerPluginPackage as BaseDocumentManagerPackage } from '@embedpdf/plugin-document-manager';\n\nimport { FilePicker, DocumentContext, DocumentContent } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-document-manager';\n\nexport const DocumentManagerPluginPackage = createPluginPackage(BaseDocumentManagerPackage)\n .addUtility(FilePicker)\n .build();\n"],"names":["_a","BaseDocumentManagerPackage"],"mappings":";;;;;;AAIa,MAAA,2BAAA,MACX,UAAiC,sBAAsB,EAAE;AAC9C,MAAA,+BAAA,MACX,cAAqC,sBAAsB,EAAE;AAK/C,SAAA,oBAAoB;AAE5B,QAAA,eAAe,aAAA;AAGf,QAAA,mCAAqC;;AAClC,aAAA,kBAAa,YAAb,mBAAsB,qBAAoB;AAAA,EACnD,CAAC;AAEK,QAAA,iCAAmC;UACjC,OAAO,aAAa;AACrB,QAAA,CAAA,aAAa;UAEZ,QAAQ,KAAK;WACZ,QAAS,KAAK,UAAU,KAAK,KAAK,OAAQ;AAAA,EACnD,CAAC;;IAGK,IAAA,mBAAmB;mBACd,gBAAA;AAAA,IACT;AAAA,IACI,IAAA,iBAAiB;mBACZ,cAAA;AAAA,IACT;AAAA;AAEJ;SAMgB,iBAAiB,gBAA6C;AAEtE,QAAA,eAAe,aAAA;AAGf,QAAA,cAAA,EAAA,QAAA,MAAuB,iBAAiB,eAAA,UAA4B;AAGpE,QAAA,4BAA8B;UAC5B,OAAO,aAAa;SACrB,KAAA,QAAA,CAAA;AAGD,QAAA,EAAA,IAAA,WAAA,GAAa;mBACR,WAAA,EACJ,IAAA,CAAK,UAAU,KAAK,UAAU,KAAK,GACnC,QAAQ,QAA8B,QAAQ,QAAQ,cAAiB;AAAA,IAC5E;WAGO,KAAK,cACT,KAAK,UAAU,KAAK,UAAU,KAAK,CAAA,EACnC,QAAQ,QAA8B,QAAQ,QAAQ,cAAiB;AAAA,EAC5E,CAAC;;IAGK,IAAA,UAAU;mBACL,SAAA;AAAA,IACT;AAAA;AAEJ;;uCCzEA;;AASQ,QAAA,wBAAwB,yBAAwB;AAChD,QAAA,4BAA4B,6BAA4B;AAE1D,MAAA,mBAA2C,IAAI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AAG,eAAuB;;AAC7B,uBAAW,aAAX,mBAAqB,cAAc;AAAA,IACrC;AAAA,IACA,MAAI,CAAG,YAAoB,YAAoB;;AAC7C,uBAAW,aAAX,mBAAqB,aAAa,YAAY;AAAA,IAChD;AAAA;;;;IA0BF,gBAAgB,cAAc;AAAA,IAC9B,kBAAkB,UAAU;AAAA,IAC5B;AAAA;;;AA1BF;4CCtCA;;AAmBQ,QAAA,WAAW,iBAAgB,MAAA,QAAA,UAAA;AAE3B,QAAA;;AAAqB,2BAAS,YAAT,mBAAkB,YAAW;AAAA,GAAS;AAC3D,QAAA;;AAAmB,2BAAS,YAAT,mBAAkB,YAAW;AAAA,GAAO;AACvD,QAAA;;AAAoB,2BAAS,YAAT,mBAAkB,YAAW;AAAA,GAAQ;;;;;;;;QAqB7D,eAAe,SAAS;AAAA,QACxB,iBAAA,SAAS;AAAA,QACT,eAAA,OAAO;AAAA,QACP,gBAAA,QAAQ;AAAA;;;;AALP,UAAA,SAAS,QAAO,UAAA,UAAA;AAAA;;;;AAlBrB;ACdO,MAAM,+BAA+B,oBAAoBC,8BAA0B,EACvF,WAAW,UAAU,EACrB,MAAA;"}
@@ -1,2 +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("vue"),u=require("@embedpdf/core/vue"),o=n.defineComponent({__name:"document-content",props:{documentId:{}},setup(e){const t=e,o=u.useDocumentState(()=>n.toValue(t.documentId)),l=n.computed(()=>{var e;return"loading"===(null==(e=o.value)?void 0:e.status)}),a=n.computed(()=>{var e;return"error"===(null==(e=o.value)?void 0:e.status)}),r=n.computed(()=>{var e;return"loaded"===(null==(e=o.value)?void 0:e.status)});return(e,t)=>n.unref(o)?n.renderSlot(e.$slots,"default",{key:0,documentState:n.unref(o),isLoading:l.value,isError:a.value,isLoaded:r.value}):n.createCommentVNode("",!0)}}),l=()=>u.usePlugin(t.DocumentManagerPlugin.id),a=()=>u.useCapability(t.DocumentManagerPlugin.id);function r(){const e=u.useCoreState();return{activeDocumentId:n.computed(()=>{var t;return(null==(t=e.value)?void 0:t.activeDocumentId)??null}),activeDocument:n.computed(()=>{const t=e.value;if(!t)return null;const n=t.activeDocumentId;return n?t.documents[n]??null:null})}}function c(e){const t=u.useCoreState();return n.computed(()=>{const u=t.value;if(!u)return[];const o=e?n.toValue(e):void 0;return o&&o.length>0?o.map(e=>u.documents[e]).filter(e=>null!=e):u.documentOrder.map(e=>u.documents[e]).filter(e=>null!=e)})}const i=n.defineComponent({__name:"document-context",setup(e){const t=c(),{activeDocumentId:u}=r(),{provides:o}=a(),l={select:e=>{var t;null==(t=o.value)||t.setActiveDocument(e)},close:e=>{var t;null==(t=o.value)||t.closeDocument(e)},move:(e,t)=>{var n;null==(n=o.value)||n.moveDocument(e,t)}};return(e,o)=>n.renderSlot(e.$slots,"default",{documentStates:n.unref(t),activeDocumentId:n.unref(u),actions:l})}}),s=n.defineComponent({__name:"file-picker",setup(e){const{plugin:t}=l(),{provides:u}=a(),o=n.ref(null),r=n.ref(null),c=n.ref(void 0);n.watch(t,(e,t,n)=>{if(!(null==e?void 0:e.onOpenFileRequest))return;n(e.onOpenFileRequest(({task:e,options:t})=>{var n;r.value=e,c.value=t,null==(n=o.value)||n.click()}))},{immediate:!0});const i=async e=>{var t,n,o,l,a;const i=null==(t=e.target.files)?void 0:t[0],s=u.value;if(!i||!s)return;const d=await i.arrayBuffer();s.openDocumentBuffer({name:i.name,buffer:d,documentId:null==(n=c.value)?void 0:n.documentId,scale:null==(o=c.value)?void 0:o.scale,rotation:null==(l=c.value)?void 0:l.rotation,autoActivate:null==(a=c.value)?void 0:a.autoActivate}).wait(e=>{var t;null==(t=r.value)||t.resolve(e)},e=>{var t;null==(t=r.value)||t.fail(e)})};return(e,t)=>(n.openBlock(),n.createElementBlock("input",{ref_key:"inputRef",ref:o,type:"file",accept:"application/pdf",style:{display:"none"},onChange:i},null,544))}}),d=e.createPluginPackage(t.DocumentManagerPluginPackage).addUtility(s).build();exports.DocumentContent=o,exports.DocumentContext=i,exports.DocumentManagerPluginPackage=d,exports.FilePicker=s,exports.useActiveDocument=r,exports.useDocumentManagerCapability=a,exports.useDocumentManagerPlugin=l,exports.useOpenDocuments=c,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-document-manager"),n=require("vue"),u=require("@embedpdf/core/vue"),o=n.defineComponent({__name:"document-content",props:{documentId:{}},setup(e){const t=e,o=u.useDocumentState(()=>n.toValue(t.documentId)),l=n.computed(()=>{var e;return"loading"===(null==(e=o.value)?void 0:e.status)}),a=n.computed(()=>{var e;return"error"===(null==(e=o.value)?void 0:e.status)}),r=n.computed(()=>{var e;return"loaded"===(null==(e=o.value)?void 0:e.status)});return(e,t)=>n.unref(o)?n.renderSlot(e.$slots,"default",{key:0,documentState:n.unref(o),isLoading:l.value,isError:a.value,isLoaded:r.value}):n.createCommentVNode("",!0)}}),l=()=>u.usePlugin(t.DocumentManagerPlugin.id),a=()=>u.useCapability(t.DocumentManagerPlugin.id);function r(){const e=u.useCoreState();return{activeDocumentId:n.computed(()=>{var t;return(null==(t=e.value)?void 0:t.activeDocumentId)??null}),activeDocument:n.computed(()=>{const t=e.value;if(!t)return null;const n=t.activeDocumentId;return n?t.documents[n]??null:null})}}function c(e){const t=u.useCoreState();return n.computed(()=>{const u=t.value;if(!u)return[];const o=e?n.toValue(e):void 0;return o?o.map(e=>u.documents[e]).filter(e=>null!=e):u.documentOrder.map(e=>u.documents[e]).filter(e=>null!=e)})}const i=n.defineComponent({__name:"document-context",setup(e){const t=c(),{activeDocumentId:u}=r(),{provides:o}=a(),l={select:e=>{var t;null==(t=o.value)||t.setActiveDocument(e)},close:e=>{var t;null==(t=o.value)||t.closeDocument(e)},move:(e,t)=>{var n;null==(n=o.value)||n.moveDocument(e,t)}};return(e,o)=>n.renderSlot(e.$slots,"default",{documentStates:n.unref(t),activeDocumentId:n.unref(u),actions:l})}}),s=n.defineComponent({__name:"file-picker",setup(e){const{plugin:t}=l(),{provides:u}=a(),o=n.ref(null),r=n.ref(null),c=n.ref(void 0);n.watch(t,(e,t,n)=>{if(!(null==e?void 0:e.onOpenFileRequest))return;n(e.onOpenFileRequest(({task:e,options:t})=>{var n;r.value=e,c.value=t,null==(n=o.value)||n.click()}))},{immediate:!0});const i=async e=>{var t,n,o,l,a;const i=null==(t=e.target.files)?void 0:t[0],s=u.value;if(!i||!s)return;const d=await i.arrayBuffer();s.openDocumentBuffer({name:i.name,buffer:d,documentId:null==(n=c.value)?void 0:n.documentId,scale:null==(o=c.value)?void 0:o.scale,rotation:null==(l=c.value)?void 0:l.rotation,autoActivate:null==(a=c.value)?void 0:a.autoActivate}).wait(e=>{var t;null==(t=r.value)||t.resolve(e)},e=>{var t;null==(t=r.value)||t.fail(e)})};return(e,t)=>(n.openBlock(),n.createElementBlock("input",{ref_key:"inputRef",ref:o,type:"file",accept:"application/pdf",style:{display:"none"},onChange:i},null,544))}}),d=e.createPluginPackage(t.DocumentManagerPluginPackage).addUtility(s).build();exports.DocumentContent=o,exports.DocumentContext=i,exports.DocumentManagerPluginPackage=d,exports.FilePicker=s,exports.useActiveDocument=r,exports.useDocumentManagerCapability=a,exports.useDocumentManagerPlugin=l,exports.useOpenDocuments=c,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/vue/components/document-content.vue","../../src/vue/hooks/use-document-manager.ts","../../src/vue/components/document-context.vue","../../src/vue/components/file-picker.vue","../../src/vue/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport type { 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: MaybeRefOrGetter<string | null>;\n}\n\nconst props = defineProps<DocumentContentProps>();\nconst documentState = useDocumentState(() => toValue(props.documentId));\n\nconst isLoading = computed(() => documentState.value?.status === 'loading');\nconst isError = computed(() => documentState.value?.status === 'error');\nconst isLoaded = computed(() => documentState.value?.status === 'loaded');\n</script>\n\n<template>\n <!--\n Headless component for rendering document content with loading/error states\n \n @example\n <DocumentContent :documentId=\"activeDocumentId\">\n <template #default=\"{ documentState, isLoading, isError, isLoaded }\">\n <LoadingSpinner v-if=\"isLoading\" />\n <ErrorMessage v-else-if=\"isError\" />\n <PDFViewer v-else-if=\"isLoaded\" :document=\"documentState\" />\n </template>\n </DocumentContent>\n -->\n <slot\n v-if=\"documentState\"\n :documentState=\"documentState\"\n :isLoading=\"isLoading\"\n :isError=\"isError\"\n :isLoaded=\"isLoaded\"\n />\n</template>\n","import { DocumentState } from '@embedpdf/core';\nimport { useCapability, usePlugin, useCoreState } from '@embedpdf/core/vue';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\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 function useActiveDocument() {\n const coreState = useCoreState();\n\n const activeDocumentId = computed(() => {\n return coreState.value?.activeDocumentId ?? null;\n });\n\n const activeDocument = computed(() => {\n const core = coreState.value;\n if (!core) return null;\n\n const docId = core.activeDocumentId;\n return docId ? (core.documents[docId] ?? null) : null;\n });\n\n return {\n activeDocumentId,\n activeDocument,\n };\n}\n\n/**\n * Hook for all open documents (in order)\n * @param getDocumentIds Optional getter function, ref, or array of specific document IDs to filter/order by\n */\nexport function useOpenDocuments(getDocumentIds?: MaybeRefOrGetter<string[] | undefined>) {\n const coreState = useCoreState();\n\n const documents = computed(() => {\n const core = coreState.value;\n if (!core) return [];\n\n // Get documentIds reactively if provided\n const documentIds = getDocumentIds ? toValue(getDocumentIds) : undefined;\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds && documentIds.length > 0) {\n return documentIds\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return core.documentOrder\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n });\n\n return documents;\n}\n","<script setup lang=\"ts\">\nimport { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\nimport type { 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\nconst documentStates = useOpenDocuments();\nconst { activeDocumentId } = useActiveDocument();\nconst { provides } = useDocumentManagerCapability();\n\nconst actions: TabActions = {\n select: (documentId: string) => {\n provides.value?.setActiveDocument(documentId);\n },\n close: (documentId: string) => {\n provides.value?.closeDocument(documentId);\n },\n move: (documentId: string, toIndex: number) => {\n provides.value?.moveDocument(documentId, toIndex);\n },\n};\n</script>\n\n<template>\n <!--\n Headless component for managing document tabs\n Provides all state and actions, completely UI-agnostic\n \n @example\n <DocumentContext>\n <template #default=\"{ documentStates, activeDocumentId, actions }\">\n <div class=\"tabs\">\n <button\n v-for=\"doc in documentStates\"\n :key=\"doc.id\"\n @click=\"actions.select(doc.id)\"\n :class=\"{ active: doc.id === activeDocumentId }\"\n >\n {{ doc.name }}\n <button @click.stop=\"actions.close(doc.id)\">×</button>\n </button>\n </div>\n </template>\n </DocumentContext>\n -->\n <slot :documentStates=\"documentStates\" :activeDocumentId=\"activeDocumentId\" :actions=\"actions\" />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watch } from 'vue';\nimport { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\nimport type { Task } from '@embedpdf/models';\nimport type { PdfErrorReason } from '@embedpdf/models';\nimport type {\n OpenDocumentResponse,\n OpenFileDialogOptions,\n} from '@embedpdf/plugin-document-manager';\n\nconst { plugin } = useDocumentManagerPlugin();\nconst { provides } = useDocumentManagerCapability();\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst taskRef = ref<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\nconst optionsRef = ref<OpenFileDialogOptions | undefined>(undefined);\n\nwatch(\n plugin,\n (pluginValue, _, onCleanup) => {\n if (!pluginValue?.onOpenFileRequest) return;\n\n const unsubscribe = pluginValue.onOpenFileRequest(({ task, options }) => {\n taskRef.value = task;\n optionsRef.value = options;\n inputRef.value?.click();\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n);\n\nconst onChange = async (event: Event) => {\n const target = event.target as HTMLInputElement;\n const file = target.files?.[0];\n const cap = provides.value;\n if (!file || !cap) return;\n\n const buffer = await file.arrayBuffer();\n const openTask = cap.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef.value?.documentId,\n scale: optionsRef.value?.scale,\n rotation: optionsRef.value?.rotation,\n autoActivate: optionsRef.value?.autoActivate,\n });\n\n openTask.wait(\n (result) => {\n taskRef.value?.resolve(result);\n },\n (error) => {\n taskRef.value?.fail(error);\n },\n );\n};\n</script>\n\n<template>\n <input\n ref=\"inputRef\"\n type=\"file\"\n accept=\"application/pdf\"\n style=\"display: none\"\n @change=\"onChange\"\n />\n</template>\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":["props","__props","documentState","useDocumentState","toValue","documentId","isLoading","computed","_a","value","status","isError","isLoaded","_unref","_renderSlot","_ctx","$slots","useDocumentManagerPlugin","usePlugin","DocumentManagerPlugin","id","useDocumentManagerCapability","useCapability","useActiveDocument","coreState","useCoreState","activeDocumentId","activeDocument","core","docId","documents","useOpenDocuments","getDocumentIds","documentIds","length","map","filter","doc","documentOrder","documentStates","provides","actions","select","setActiveDocument","close","closeDocument","move","toIndex","moveDocument","plugin","inputRef","ref","taskRef","optionsRef","watch","pluginValue","_","onCleanup","onOpenFileRequest","task","options","click","immediate","onChange","async","event","file","target","files","cap","buffer","arrayBuffer","openDocumentBuffer","name","_b","scale","_c","rotation","_d","autoActivate","_e","wait","result","resolve","error","fail","_createElementBlock","type","accept","style","display","DocumentManagerPluginPackage","createPluginPackage","BaseDocumentManagerPackage","addUtility","FilePicker","build"],"mappings":"gSAgBA,MAAMA,EAAQC,EACRC,EAAgBC,EAAAA,iBAAiB,IAAMC,EAAAA,QAAQJ,EAAMK,aAErDC,EAAYC,EAAAA,SAAS,WAAM,MAAgC,aAAhC,OAAAC,EAAAN,EAAcO,gBAAOC,UAChDC,EAAUJ,EAAAA,SAAS,WAAM,MAAgC,WAAhC,OAAAC,EAAAN,EAAcO,gBAAOC,UAC9CE,EAAWL,EAAAA,SAAS,WAAM,MAAgC,YAAhC,OAAAC,EAAAN,EAAcO,gBAAOC,uBAiB3CG,EAAAA,MAAAX,GADRY,EAAAA,WAMEC,EAAAC,OAAA,UAAA,OAJCd,cAAeW,EAAAA,MAAAX,GACfI,UAAWA,EAAAG,MACXE,QAASA,EAAAF,MACTG,SAAUA,EAAAH,uCCrCFQ,EAA2B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KACbuB,SAAEA,GAAanB,IACf6B,EAAWC,EAAAA,IAA6B,MACxCC,EAAUD,EAAAA,IAAuD,MACjEE,EAAaF,EAAAA,SAAuC,GAE1DG,EAAAA,MACEL,EACA,CAACM,EAAaC,EAAGC,KACf,WAAKF,WAAaG,mBAAmB,OAQrCD,EANoBF,EAAYG,kBAAkB,EAAGC,OAAMC,oBACzDR,EAAQ3C,MAAQkD,EAChBN,EAAW5C,MAAQmD,EACnB,OAAApD,EAAA0C,EAASzC,QAATD,EAAgBqD,YAKpB,CAAEC,WAAW,IAGf,MAAMC,EAAWC,MAAOC,kBACtB,MACMC,EAAO,OAAA1D,EADEyD,EAAME,OACDC,YAAP,EAAA5D,EAAe,GACtB6D,EAAM7B,EAAS/B,MACrB,IAAKyD,IAASG,EAAK,OAEnB,MAAMC,QAAeJ,EAAKK,cACTF,EAAIG,mBAAmB,CACtCC,KAAMP,EAAKO,KACXH,SACAjE,WAAY,OAAAqE,EAAArB,EAAW5C,YAAX,EAAAiE,EAAkBrE,WAC9BsE,MAAO,OAAAC,EAAAvB,EAAW5C,YAAX,EAAAmE,EAAkBD,MACzBE,SAAU,OAAAC,EAAAzB,EAAW5C,YAAX,EAAAqE,EAAkBD,SAC5BE,aAAc,OAAAC,EAAA3B,EAAW5C,YAAX,EAAAuE,EAAkBD,eAGzBE,KACNC,UACC,OAAA1E,EAAA4C,EAAQ3C,QAARD,EAAe2E,QAAQD,IAExBE,UACC,OAAA5E,EAAA4C,EAAQ3C,QAARD,EAAe6E,KAAKD,kCAOxBE,EAAAA,mBAME,QAAA,SALI,WAAJnC,IAAID,EACJqC,KAAK,OACLC,OAAO,kBACPC,MAAA,CAAAC,QAAA,QACC3B,0BCxDQ4B,EAA+BC,EAAAA,oBAAoBC,EAAAA,8BAC7DC,WAAWC,GACXC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/components/document-content.vue","../../src/vue/hooks/use-document-manager.ts","../../src/vue/components/document-context.vue","../../src/vue/components/file-picker.vue","../../src/vue/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport type { 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: MaybeRefOrGetter<string | null>;\n}\n\nconst props = defineProps<DocumentContentProps>();\nconst documentState = useDocumentState(() => toValue(props.documentId));\n\nconst isLoading = computed(() => documentState.value?.status === 'loading');\nconst isError = computed(() => documentState.value?.status === 'error');\nconst isLoaded = computed(() => documentState.value?.status === 'loaded');\n</script>\n\n<template>\n <!--\n Headless component for rendering document content with loading/error states\n \n @example\n <DocumentContent :documentId=\"activeDocumentId\">\n <template #default=\"{ documentState, isLoading, isError, isLoaded }\">\n <LoadingSpinner v-if=\"isLoading\" />\n <ErrorMessage v-else-if=\"isError\" />\n <PDFViewer v-else-if=\"isLoaded\" :document=\"documentState\" />\n </template>\n </DocumentContent>\n -->\n <slot\n v-if=\"documentState\"\n :documentState=\"documentState\"\n :isLoading=\"isLoading\"\n :isError=\"isError\"\n :isLoaded=\"isLoaded\"\n />\n</template>\n","import { DocumentState } from '@embedpdf/core';\nimport { useCapability, usePlugin, useCoreState } from '@embedpdf/core/vue';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\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 function useActiveDocument() {\n const coreState = useCoreState();\n\n const activeDocumentId = computed(() => {\n return coreState.value?.activeDocumentId ?? null;\n });\n\n const activeDocument = computed(() => {\n const core = coreState.value;\n if (!core) return null;\n\n const docId = core.activeDocumentId;\n return docId ? (core.documents[docId] ?? null) : null;\n });\n\n return {\n activeDocumentId,\n activeDocument,\n };\n}\n\n/**\n * Hook for all open documents (in order)\n * @param getDocumentIds Optional getter function, ref, or array of specific document IDs to filter/order by\n */\nexport function useOpenDocuments(getDocumentIds?: MaybeRefOrGetter<string[] | undefined>) {\n const coreState = useCoreState();\n\n const documents = computed(() => {\n const core = coreState.value;\n if (!core) return [];\n\n // Get documentIds reactively if provided\n const documentIds = getDocumentIds ? toValue(getDocumentIds) : undefined;\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds) {\n return documentIds\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return core.documentOrder\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n });\n\n return documents;\n}\n","<script setup lang=\"ts\">\nimport { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\nimport type { 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\nconst documentStates = useOpenDocuments();\nconst { activeDocumentId } = useActiveDocument();\nconst { provides } = useDocumentManagerCapability();\n\nconst actions: TabActions = {\n select: (documentId: string) => {\n provides.value?.setActiveDocument(documentId);\n },\n close: (documentId: string) => {\n provides.value?.closeDocument(documentId);\n },\n move: (documentId: string, toIndex: number) => {\n provides.value?.moveDocument(documentId, toIndex);\n },\n};\n</script>\n\n<template>\n <!--\n Headless component for managing document tabs\n Provides all state and actions, completely UI-agnostic\n \n @example\n <DocumentContext>\n <template #default=\"{ documentStates, activeDocumentId, actions }\">\n <div class=\"tabs\">\n <button\n v-for=\"doc in documentStates\"\n :key=\"doc.id\"\n @click=\"actions.select(doc.id)\"\n :class=\"{ active: doc.id === activeDocumentId }\"\n >\n {{ doc.name }}\n <button @click.stop=\"actions.close(doc.id)\">×</button>\n </button>\n </div>\n </template>\n </DocumentContext>\n -->\n <slot :documentStates=\"documentStates\" :activeDocumentId=\"activeDocumentId\" :actions=\"actions\" />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watch } from 'vue';\nimport { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\nimport type { Task } from '@embedpdf/models';\nimport type { PdfErrorReason } from '@embedpdf/models';\nimport type {\n OpenDocumentResponse,\n OpenFileDialogOptions,\n} from '@embedpdf/plugin-document-manager';\n\nconst { plugin } = useDocumentManagerPlugin();\nconst { provides } = useDocumentManagerCapability();\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst taskRef = ref<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\nconst optionsRef = ref<OpenFileDialogOptions | undefined>(undefined);\n\nwatch(\n plugin,\n (pluginValue, _, onCleanup) => {\n if (!pluginValue?.onOpenFileRequest) return;\n\n const unsubscribe = pluginValue.onOpenFileRequest(({ task, options }) => {\n taskRef.value = task;\n optionsRef.value = options;\n inputRef.value?.click();\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n);\n\nconst onChange = async (event: Event) => {\n const target = event.target as HTMLInputElement;\n const file = target.files?.[0];\n const cap = provides.value;\n if (!file || !cap) return;\n\n const buffer = await file.arrayBuffer();\n const openTask = cap.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef.value?.documentId,\n scale: optionsRef.value?.scale,\n rotation: optionsRef.value?.rotation,\n autoActivate: optionsRef.value?.autoActivate,\n });\n\n openTask.wait(\n (result) => {\n taskRef.value?.resolve(result);\n },\n (error) => {\n taskRef.value?.fail(error);\n },\n );\n};\n</script>\n\n<template>\n <input\n ref=\"inputRef\"\n type=\"file\"\n accept=\"application/pdf\"\n style=\"display: none\"\n @change=\"onChange\"\n />\n</template>\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":["props","__props","documentState","useDocumentState","toValue","documentId","isLoading","computed","_a","value","status","isError","isLoaded","_unref","_renderSlot","_ctx","$slots","useDocumentManagerPlugin","usePlugin","DocumentManagerPlugin","id","useDocumentManagerCapability","useCapability","useActiveDocument","coreState","useCoreState","activeDocumentId","activeDocument","core","docId","documents","useOpenDocuments","getDocumentIds","documentIds","map","filter","doc","documentOrder","documentStates","provides","actions","select","setActiveDocument","close","closeDocument","move","toIndex","moveDocument","plugin","inputRef","ref","taskRef","optionsRef","watch","pluginValue","_","onCleanup","onOpenFileRequest","task","options","click","immediate","onChange","async","event","file","target","files","cap","buffer","arrayBuffer","openDocumentBuffer","name","_b","scale","_c","rotation","_d","autoActivate","_e","wait","result","resolve","error","fail","_createElementBlock","type","accept","style","display","DocumentManagerPluginPackage","createPluginPackage","BaseDocumentManagerPackage","addUtility","FilePicker","build"],"mappings":"gSAgBA,MAAMA,EAAQC,EACRC,EAAgBC,EAAAA,iBAAiB,IAAMC,EAAAA,QAAQJ,EAAMK,aAErDC,EAAYC,EAAAA,SAAS,WAAM,MAAgC,aAAhC,OAAAC,EAAAN,EAAcO,gBAAOC,UAChDC,EAAUJ,EAAAA,SAAS,WAAM,MAAgC,WAAhC,OAAAC,EAAAN,EAAcO,gBAAOC,UAC9CE,EAAWL,EAAAA,SAAS,WAAM,MAAgC,YAAhC,OAAAC,EAAAN,EAAcO,gBAAOC,uBAiB3CG,EAAAA,MAAAX,GADRY,EAAAA,WAMEC,EAAAC,OAAA,UAAA,OAJCd,cAAeW,EAAAA,MAAAX,GACfI,UAAWA,EAAAG,MACXE,QAASA,EAAAF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OAAEA,GAAW/B,KACbsB,SAAEA,GAAalB,IACf4B,EAAWC,EAAAA,IAA6B,MACxCC,EAAUD,EAAAA,IAAuD,MACjEE,EAAaF,EAAAA,SAAuC,GAE1DG,EAAAA,MACEL,EACA,CAACM,EAAaC,EAAGC,KACf,WAAKF,WAAaG,mBAAmB,OAQrCD,EANoBF,EAAYG,kBAAkB,EAAGC,OAAMC,oBACzDR,EAAQ1C,MAAQiD,EAChBN,EAAW3C,MAAQkD,EACnB,OAAAnD,EAAAyC,EAASxC,QAATD,EAAgBoD,YAKpB,CAAEC,WAAW,IAGf,MAAMC,EAAWC,MAAOC,kBACtB,MACMC,EAAO,OAAAzD,EADEwD,EAAME,OACDC,YAAP,EAAA3D,EAAe,GACtB4D,EAAM7B,EAAS9B,MACrB,IAAKwD,IAASG,EAAK,OAEnB,MAAMC,QAAeJ,EAAKK,cACTF,EAAIG,mBAAmB,CACtCC,KAAMP,EAAKO,KACXH,SACAhE,WAAY,OAAAoE,EAAArB,EAAW3C,YAAX,EAAAgE,EAAkBpE,WAC9BqE,MAAO,OAAAC,EAAAvB,EAAW3C,YAAX,EAAAkE,EAAkBD,MACzBE,SAAU,OAAAC,EAAAzB,EAAW3C,YAAX,EAAAoE,EAAkBD,SAC5BE,aAAc,OAAAC,EAAA3B,EAAW3C,YAAX,EAAAsE,EAAkBD,eAGzBE,KACNC,UACC,OAAAzE,EAAA2C,EAAQ1C,QAARD,EAAe0E,QAAQD,IAExBE,UACC,OAAA3E,EAAA2C,EAAQ1C,QAARD,EAAe4E,KAAKD,kCAOxBE,EAAAA,mBAME,QAAA,SALI,WAAJnC,IAAID,EACJqC,KAAK,OACLC,OAAO,kBACPC,MAAA,CAAAC,QAAA,QACC3B,0BCxDQ4B,EAA+BC,EAAAA,oBAAoBC,EAAAA,8BAC7DC,WAAWC,GACXC"}
package/dist/vue/index.js CHANGED
@@ -59,7 +59,7 @@ function useOpenDocuments(getDocumentIds) {
59
59
  const core = coreState.value;
60
60
  if (!core) return [];
61
61
  const documentIds = getDocumentIds ? toValue(getDocumentIds) : void 0;
62
- if (documentIds && documentIds.length > 0) {
62
+ if (documentIds) {
63
63
  return documentIds.map((docId) => core.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
64
64
  }
65
65
  return core.documentOrder.map((docId) => core.documents[docId]).filter((doc) => doc !== null && doc !== void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/vue/components/document-content.vue","../../src/vue/hooks/use-document-manager.ts","../../src/vue/components/document-context.vue","../../src/vue/components/file-picker.vue","../../src/vue/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport type { 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: MaybeRefOrGetter<string | null>;\n}\n\nconst props = defineProps<DocumentContentProps>();\nconst documentState = useDocumentState(() => toValue(props.documentId));\n\nconst isLoading = computed(() => documentState.value?.status === 'loading');\nconst isError = computed(() => documentState.value?.status === 'error');\nconst isLoaded = computed(() => documentState.value?.status === 'loaded');\n</script>\n\n<template>\n <!--\n Headless component for rendering document content with loading/error states\n \n @example\n <DocumentContent :documentId=\"activeDocumentId\">\n <template #default=\"{ documentState, isLoading, isError, isLoaded }\">\n <LoadingSpinner v-if=\"isLoading\" />\n <ErrorMessage v-else-if=\"isError\" />\n <PDFViewer v-else-if=\"isLoaded\" :document=\"documentState\" />\n </template>\n </DocumentContent>\n -->\n <slot\n v-if=\"documentState\"\n :documentState=\"documentState\"\n :isLoading=\"isLoading\"\n :isError=\"isError\"\n :isLoaded=\"isLoaded\"\n />\n</template>\n","import { DocumentState } from '@embedpdf/core';\nimport { useCapability, usePlugin, useCoreState } from '@embedpdf/core/vue';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\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 function useActiveDocument() {\n const coreState = useCoreState();\n\n const activeDocumentId = computed(() => {\n return coreState.value?.activeDocumentId ?? null;\n });\n\n const activeDocument = computed(() => {\n const core = coreState.value;\n if (!core) return null;\n\n const docId = core.activeDocumentId;\n return docId ? (core.documents[docId] ?? null) : null;\n });\n\n return {\n activeDocumentId,\n activeDocument,\n };\n}\n\n/**\n * Hook for all open documents (in order)\n * @param getDocumentIds Optional getter function, ref, or array of specific document IDs to filter/order by\n */\nexport function useOpenDocuments(getDocumentIds?: MaybeRefOrGetter<string[] | undefined>) {\n const coreState = useCoreState();\n\n const documents = computed(() => {\n const core = coreState.value;\n if (!core) return [];\n\n // Get documentIds reactively if provided\n const documentIds = getDocumentIds ? toValue(getDocumentIds) : undefined;\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds && documentIds.length > 0) {\n return documentIds\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return core.documentOrder\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n });\n\n return documents;\n}\n","<script setup lang=\"ts\">\nimport { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\nimport type { 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\nconst documentStates = useOpenDocuments();\nconst { activeDocumentId } = useActiveDocument();\nconst { provides } = useDocumentManagerCapability();\n\nconst actions: TabActions = {\n select: (documentId: string) => {\n provides.value?.setActiveDocument(documentId);\n },\n close: (documentId: string) => {\n provides.value?.closeDocument(documentId);\n },\n move: (documentId: string, toIndex: number) => {\n provides.value?.moveDocument(documentId, toIndex);\n },\n};\n</script>\n\n<template>\n <!--\n Headless component for managing document tabs\n Provides all state and actions, completely UI-agnostic\n \n @example\n <DocumentContext>\n <template #default=\"{ documentStates, activeDocumentId, actions }\">\n <div class=\"tabs\">\n <button\n v-for=\"doc in documentStates\"\n :key=\"doc.id\"\n @click=\"actions.select(doc.id)\"\n :class=\"{ active: doc.id === activeDocumentId }\"\n >\n {{ doc.name }}\n <button @click.stop=\"actions.close(doc.id)\">×</button>\n </button>\n </div>\n </template>\n </DocumentContext>\n -->\n <slot :documentStates=\"documentStates\" :activeDocumentId=\"activeDocumentId\" :actions=\"actions\" />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watch } from 'vue';\nimport { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\nimport type { Task } from '@embedpdf/models';\nimport type { PdfErrorReason } from '@embedpdf/models';\nimport type {\n OpenDocumentResponse,\n OpenFileDialogOptions,\n} from '@embedpdf/plugin-document-manager';\n\nconst { plugin } = useDocumentManagerPlugin();\nconst { provides } = useDocumentManagerCapability();\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst taskRef = ref<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\nconst optionsRef = ref<OpenFileDialogOptions | undefined>(undefined);\n\nwatch(\n plugin,\n (pluginValue, _, onCleanup) => {\n if (!pluginValue?.onOpenFileRequest) return;\n\n const unsubscribe = pluginValue.onOpenFileRequest(({ task, options }) => {\n taskRef.value = task;\n optionsRef.value = options;\n inputRef.value?.click();\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n);\n\nconst onChange = async (event: Event) => {\n const target = event.target as HTMLInputElement;\n const file = target.files?.[0];\n const cap = provides.value;\n if (!file || !cap) return;\n\n const buffer = await file.arrayBuffer();\n const openTask = cap.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef.value?.documentId,\n scale: optionsRef.value?.scale,\n rotation: optionsRef.value?.rotation,\n autoActivate: optionsRef.value?.autoActivate,\n });\n\n openTask.wait(\n (result) => {\n taskRef.value?.resolve(result);\n },\n (error) => {\n taskRef.value?.fail(error);\n },\n );\n};\n</script>\n\n<template>\n <input\n ref=\"inputRef\"\n type=\"file\"\n accept=\"application/pdf\"\n style=\"display: none\"\n @change=\"onChange\"\n />\n</template>\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":["_unref","_renderSlot","_a","_createElementBlock","BaseDocumentManagerPackage","FilePicker"],"mappings":";;;;;;;;;;;AAgBA,UAAM,QAAQ;AACd,UAAM,gBAAgB,iBAAiB,MAAM,QAAQ,MAAM,UAAU,CAAC;AAEtE,UAAM,YAAY,SAAS,MAAA;;AAAM,kCAAc,UAAd,mBAAqB,YAAW;AAAA,KAAS;AAC1E,UAAM,UAAU,SAAS,MAAA;;AAAM,kCAAc,UAAd,mBAAqB,YAAW;AAAA,KAAO;AACtE,UAAM,WAAW,SAAS,MAAA;;AAAM,kCAAc,UAAd,mBAAqB,YAAW;AAAA,KAAQ;;aAiB9DA,MAAA,aAAA,IADRC,WAME,KAAA,QAAA,WAAA;AAAA;QAJC,eAAeD,MAAA,aAAA;AAAA,QACf,WAAW,UAAA;AAAA,QACX,SAAS,QAAA;AAAA,QACT,UAAU,SAAA;AAAA,MAAA;;;;ACrCR,MAAM,2BAA2B,MACtC,UAAiC,sBAAsB,EAAE;AACpD,MAAM,+BAA+B,MAC1C,cAAqC,sB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;;AACT,WAAAA,MAAA,QAAQ,UAAR,gBAAAA,IAAe,KAAK;AAAA,QACtB;AAAA,MAAA;AAAA,IAEJ;;0BAIEC,mBAME,SAAA;AAAA,iBALI;AAAA,QAAJ,KAAI;AAAA,QACJ,MAAK;AAAA,QACL,QAAO;AAAA,QACP,OAAA,EAAA,WAAA,OAAA;AAAA,QACC;AAAA,MAAA;;;;ACxDE,MAAM,+BAA+B,oBAAoBC,8BAA0B,EACvF,WAAWC,SAAU,EACrB,MAAA;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/vue/components/document-content.vue","../../src/vue/hooks/use-document-manager.ts","../../src/vue/components/document-context.vue","../../src/vue/components/file-picker.vue","../../src/vue/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport type { 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: MaybeRefOrGetter<string | null>;\n}\n\nconst props = defineProps<DocumentContentProps>();\nconst documentState = useDocumentState(() => toValue(props.documentId));\n\nconst isLoading = computed(() => documentState.value?.status === 'loading');\nconst isError = computed(() => documentState.value?.status === 'error');\nconst isLoaded = computed(() => documentState.value?.status === 'loaded');\n</script>\n\n<template>\n <!--\n Headless component for rendering document content with loading/error states\n \n @example\n <DocumentContent :documentId=\"activeDocumentId\">\n <template #default=\"{ documentState, isLoading, isError, isLoaded }\">\n <LoadingSpinner v-if=\"isLoading\" />\n <ErrorMessage v-else-if=\"isError\" />\n <PDFViewer v-else-if=\"isLoaded\" :document=\"documentState\" />\n </template>\n </DocumentContent>\n -->\n <slot\n v-if=\"documentState\"\n :documentState=\"documentState\"\n :isLoading=\"isLoading\"\n :isError=\"isError\"\n :isLoaded=\"isLoaded\"\n />\n</template>\n","import { DocumentState } from '@embedpdf/core';\nimport { useCapability, usePlugin, useCoreState } from '@embedpdf/core/vue';\nimport { DocumentManagerPlugin } from '@embedpdf/plugin-document-manager';\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\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 function useActiveDocument() {\n const coreState = useCoreState();\n\n const activeDocumentId = computed(() => {\n return coreState.value?.activeDocumentId ?? null;\n });\n\n const activeDocument = computed(() => {\n const core = coreState.value;\n if (!core) return null;\n\n const docId = core.activeDocumentId;\n return docId ? (core.documents[docId] ?? null) : null;\n });\n\n return {\n activeDocumentId,\n activeDocument,\n };\n}\n\n/**\n * Hook for all open documents (in order)\n * @param getDocumentIds Optional getter function, ref, or array of specific document IDs to filter/order by\n */\nexport function useOpenDocuments(getDocumentIds?: MaybeRefOrGetter<string[] | undefined>) {\n const coreState = useCoreState();\n\n const documents = computed(() => {\n const core = coreState.value;\n if (!core) return [];\n\n // Get documentIds reactively if provided\n const documentIds = getDocumentIds ? toValue(getDocumentIds) : undefined;\n\n // If specific documentIds are provided, use THEIR order\n if (documentIds) {\n return documentIds\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n }\n\n // Otherwise use the global document order\n return core.documentOrder\n .map((docId) => core.documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n });\n\n return documents;\n}\n","<script setup lang=\"ts\">\nimport { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '../hooks';\nimport type { 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\nconst documentStates = useOpenDocuments();\nconst { activeDocumentId } = useActiveDocument();\nconst { provides } = useDocumentManagerCapability();\n\nconst actions: TabActions = {\n select: (documentId: string) => {\n provides.value?.setActiveDocument(documentId);\n },\n close: (documentId: string) => {\n provides.value?.closeDocument(documentId);\n },\n move: (documentId: string, toIndex: number) => {\n provides.value?.moveDocument(documentId, toIndex);\n },\n};\n</script>\n\n<template>\n <!--\n Headless component for managing document tabs\n Provides all state and actions, completely UI-agnostic\n \n @example\n <DocumentContext>\n <template #default=\"{ documentStates, activeDocumentId, actions }\">\n <div class=\"tabs\">\n <button\n v-for=\"doc in documentStates\"\n :key=\"doc.id\"\n @click=\"actions.select(doc.id)\"\n :class=\"{ active: doc.id === activeDocumentId }\"\n >\n {{ doc.name }}\n <button @click.stop=\"actions.close(doc.id)\">×</button>\n </button>\n </div>\n </template>\n </DocumentContext>\n -->\n <slot :documentStates=\"documentStates\" :activeDocumentId=\"activeDocumentId\" :actions=\"actions\" />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watch } from 'vue';\nimport { useDocumentManagerCapability, useDocumentManagerPlugin } from '../hooks';\nimport type { Task } from '@embedpdf/models';\nimport type { PdfErrorReason } from '@embedpdf/models';\nimport type {\n OpenDocumentResponse,\n OpenFileDialogOptions,\n} from '@embedpdf/plugin-document-manager';\n\nconst { plugin } = useDocumentManagerPlugin();\nconst { provides } = useDocumentManagerCapability();\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst taskRef = ref<Task<OpenDocumentResponse, PdfErrorReason> | null>(null);\nconst optionsRef = ref<OpenFileDialogOptions | undefined>(undefined);\n\nwatch(\n plugin,\n (pluginValue, _, onCleanup) => {\n if (!pluginValue?.onOpenFileRequest) return;\n\n const unsubscribe = pluginValue.onOpenFileRequest(({ task, options }) => {\n taskRef.value = task;\n optionsRef.value = options;\n inputRef.value?.click();\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n);\n\nconst onChange = async (event: Event) => {\n const target = event.target as HTMLInputElement;\n const file = target.files?.[0];\n const cap = provides.value;\n if (!file || !cap) return;\n\n const buffer = await file.arrayBuffer();\n const openTask = cap.openDocumentBuffer({\n name: file.name,\n buffer,\n documentId: optionsRef.value?.documentId,\n scale: optionsRef.value?.scale,\n rotation: optionsRef.value?.rotation,\n autoActivate: optionsRef.value?.autoActivate,\n });\n\n openTask.wait(\n (result) => {\n taskRef.value?.resolve(result);\n },\n (error) => {\n taskRef.value?.fail(error);\n },\n );\n};\n</script>\n\n<template>\n <input\n ref=\"inputRef\"\n type=\"file\"\n accept=\"application/pdf\"\n style=\"display: none\"\n @change=\"onChange\"\n />\n</template>\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":["_unref","_renderSlot","_a","_createElementBlock","BaseDocumentManagerPackage","FilePicker"],"mappings":";;;;;;;;;;;AAgBA,UAAM,QAAQ;AACd,UAAM,gBAAgB,iBAAiB,MAAM,QAAQ,MAAM,UAAU,CAAC;AAEtE,UAAM,YAAY,SAAS,MAAA;;AAAM,kCAAc,UAAd,mBAAqB,YAAW;AAAA,KAAS;AAC1E,UAAM,UAAU,SAAS,MAAA;;AAAM,kCAAc,UAAd,mBAAqB,YAAW;AAAA,KAAO;AACtE,UAAM,WAAW,SAAS,MAAA;;AAAM,kCAAc,UAAd,mBAAqB,YAAW;AAAA,KAAQ;;aAiB9DA,MAAA,aAAA,IADRC,WAME,KAAA,QAAA,WAAA;AAAA;QAJC,eAAeD,MAAA,aAAA;AAAA,QACf,WAAW,UAAA;AAAA,QACX,SAAS,QAAA;AAAA,QACT,UAAU,SAAA;AAAA,MAAA;;;;ACrCR,MAAM,2B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AAA,IAAe,QAAQ;AAAA,QACzB;AAAA,QACA,CAAC,UAAU;;AACT,WAAAA,MAAA,QAAQ,UAAR,gBAAAA,IAAe,KAAK;AAAA,QACtB;AAAA,MAAA;AAAA,IAEJ;;0BAIEC,mBAME,SAAA;AAAA,iBALI;AAAA,QAAJ,KAAI;AAAA,QACJ,MAAK;AAAA,QACL,QAAO;AAAA,QACP,OAAA,EAAA,WAAA,OAAA;AAAA,QACC;AAAA,MAAA;;;;ACxDE,MAAM,+BAA+B,oBAAoBC,8BAA0B,EACvF,WAAWC,SAAU,EACrB,MAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-document-manager",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0-next.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -34,13 +34,13 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@embedpdf/models": "2.0.0-next.0"
37
+ "@embedpdf/models": "2.0.0-next.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.2.0",
41
41
  "typescript": "^5.0.0",
42
- "@embedpdf/build": "1.1.0",
43
- "@embedpdf/core": "2.0.0-next.0"
42
+ "@embedpdf/core": "2.0.0-next.2",
43
+ "@embedpdf/build": "1.1.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "react": ">=16.8.0",
@@ -48,7 +48,7 @@
48
48
  "preact": "^10.26.4",
49
49
  "vue": ">=3.2.0",
50
50
  "svelte": ">=5 <6",
51
- "@embedpdf/core": "2.0.0-next.0"
51
+ "@embedpdf/core": "2.0.0-next.2"
52
52
  },
53
53
  "files": [
54
54
  "dist",