@embedpdf/plugin-document-manager 2.0.0-next.0 → 2.0.0-next.1
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/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +1 -1
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +1 -1
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +1 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +4 -4
package/dist/preact/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/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
|
|
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":"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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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,EAAiBhE,KACjBH,iBAAEA,GAAqBJ,KACvBiB,SAAEA,GAAanB,IAuBf0E,EAAsB,CAC1BC,OAtBaC,EAAAA,YACZ7B,IACC,MAAA5B,GAAAA,EAAU0D,kBAAkB9B,IAE9B,CAAC5B,IAmBD2D,MAhBYF,EAAAA,YACX7B,IACC,MAAA5B,GAAAA,EAAU4D,cAAchC,IAE1B,CAAC5B,IAaD6D,KAVWJ,EAAAA,YACX,CAAC7B,EAAoBkC,KACnB,MAAA9D,GAAAA,EAAU+D,aAAanC,EAAYkC,IAErC,CAAC9D,KASH,yBAAU8C,SAAAA,EAAS,CAAEQ,iBAAgBnE,mBAAkBoE,aACzD"}
|
|
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":"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,SAASM,IACd,MAAMC,OAAEA,GAAWrB,KACbsB,SAAEA,GAAalB,IACfmB,EAAWC,EAAAA,OAAyB,MACpCC,EAAUD,EAAAA,OAA0D,MACpEE,EAAaF,EAAAA,YAA0C,GAE7DG,EAAAA,UAAU,KACR,WAAKN,WAAQO,mBAAmB,OAMhC,OALcP,EAAOO,kBAAkB,EAAGC,OAAMC,oBAC9CL,EAAQM,QAAUF,EAClBH,EAAWK,QAAUD,EACrB,OAAAE,EAAAT,EAASQ,UAATC,EAAkBC,WAGnB,CAACZ,IAwBJ,OACEa,EA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hBYF,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"}
|
package/dist/preact/index.js
CHANGED
|
@@ -36,7 +36,7 @@ const useOpenDocuments = (documentIds) => {
|
|
|
36
36
|
const coreState = useCoreState();
|
|
37
37
|
return useMemo(() => {
|
|
38
38
|
if (!coreState) return [];
|
|
39
|
-
if (documentIds
|
|
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);
|
package/dist/preact/index.js.map
CHANGED
|
@@ -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;A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AAA,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,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,gBAA2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,MAAM;AACd,QAAI,EAAC,iCAAQ,mBAAmB;AAChC,UAAM,QAAQ,OAAO,kBAAkB,CAAC,EAAE,MAAM,cAAc;;AAC5D,cAAQ,UAAU;AAClB,iBAAW,UAAU;AACrB,qBAAS,YAAT,mBAAkB;AAAA,IACpB,CAAC;AACD,WAAO;AAAA,EACT,GAAG,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;"}
|
package/dist/react/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/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
|
|
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
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -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,oBAC9CL,EAAQM,QAAUF,EAClBH,EAAWK,QAAUD,EACrB,OAAAE,EAAAT,EAASQ,UAATC,EAAkBC,WAGnB,CAACZ,IAwBJ,OACEa,EAAAA,IAAC,QAAA,CACCC,IAAKZ,EACLa,KAAK,OACLC,OAAO,kBACPC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B,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,MAIpB,MAAMD,EAAmBH,EAAUG,iBAKnC,MAAO,CACLA,mBACAC,eANqBD,EAClBH,EAAUK,UAAUF,IAAqB,KAC1C,OAMH,CAACH,KAMOM,EAAoBC,IAC/B,MAAMP,EAAYC,EAAAA,eAElB,OAAO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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"}
|
package/dist/react/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const useOpenDocuments = (documentIds) => {
|
|
|
35
35
|
const coreState = useCoreState();
|
|
36
36
|
return useMemo(() => {
|
|
37
37
|
if (!coreState) return [];
|
|
38
|
-
if (documentIds
|
|
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);
|
package/dist/react/index.js.map
CHANGED
|
@@ -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,QAAQ,MAAS;AAAA,IAC5E;AAGA,WAAO,UAAU,cACd,IAAI,CAAC,UAAU,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M,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;AACzC,QAAM,WAAW,cAAc,WAAW;AAE1C,SAAO,oBAAA,UAAA,E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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;"}
|
package/dist/svelte/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/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
|
|
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,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,EACT,EACI,kBAAAG,gBACKA,EACT,EAEJ,UAMgBI,EAAiBC,GAEzB,MAAAV,EAAeC,EAAAA,eAGfU,EAAAC,EAAAC,QAAA,IAAuBH,EAAiBA,YAGxCF,uBACEF,EAAON,EAAaI,eACrBE,EAGDM,EAAAE,IAAAH,UAAeA,GAAYI,OAAS,QAC/BJ,GACJK,IAAKT,GAAUD,EAAKE,UAAUD,IAC9BU,OAAQC,GAA8BA,SAIpCZ,EAAKa,cACTH,IAAKT,GAAUD,EAAKE,UAAUD,IAC9BU,OAAQC,GAA8BA,SAZpC,YAgBD,WAAAd,gBACKI,EACT,EAEJ,iGChEQ,MAAAY,EAAwB3B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D,EAAAyD,EAASxD,kBAAS4D,2HAqB1CG,cAAeP,EAASxD,QACxB2D,gBAAAA,GACAE,cAAAA,GACAC,eAAAA,gCALCN,EAASxD,SAAOgE,EAAAC,0BAlBrB,qDCDQ,MAAAC,EAAgB7D,IAChB8D,EAAYxE,IACZyE,EAAa3E,IAEb4E,EAAmB,CACvBC,OAAShC,UACP,OAAAvC,EAAAqE,EAAWnC,aAAUsC,kBAAkBjC,IAEzCkC,MAAQlC,UACN,OAAAvC,EAAAqE,EAAWnC,aAAUwC,cAAcnC,IAErCoC,KAAI,CAAGpC,EAAoBqC,WACzB,OAAA5E,EAAAqE,EAAWnC,WAAXlC,EAAqB6E,aAAatC,EAAYqC,2EA2BlDE,eAAgBX,EAAclE,QAC9BF,iBAAkBqE,EAAUrE,iBAC5BuE,kCA1BF"}
|
|
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) {\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,EACT,EACI,kBAAAG,gBACKA,EACT,EAEJ,UAMgBI,EAAiBC,GAEzB,MAAAV,EAAeC,EAAAA,eAGfU,EAAAC,EAAAC,QAAA,IAAuBH,EAAiBA,YAGxCF,uBACEF,EAAON,EAAaI,eACrBE,EAGDM,EAAAE,IAAAH,SACKA,GACJI,IAAKR,GAAUD,EAAKE,UAAUD,IAC9BS,OAAQC,GAA8BA,SAIpCX,EAAKY,cACTH,IAAKR,GAAUD,EAAKE,UAAUD,IAC9BS,OAAQC,GAA8BA,SAZpC,YAgBD,WAAAb,gBACKI,EACT,EAEJ,iGChEQ,MAAAW,EAAwB1B,IACxB2B,EAA4BvB,IAE9B,IAAAwB,UAA2C,MAC3CC,UAAoE,MACpEC,eAAuD,GAE3DX,EAAAY,YAAO,gBACA,OAAArB,EAAAgB,EAAsBM,aAAtB,EAAAtB,EAA8BuB,mBAAiB,cAEhCP,EAAsBM,OAAOC,kBAAiB,EAAIC,OAAMC,oBAC1EhB,EAAAiB,IAAAP,EAAUK,GAAI,GACdf,EAAAiB,IAAAN,EAAaK,GAAO,GACpBhB,OAAAA,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AAoE,EAAWnC,aAAUwC,cAAcnC,IAErCoC,KAAI,CAAGpC,EAAoBqC,WACzB,OAAA3E,EAAAoE,EAAWnC,WAAXjC,EAAqB4E,aAAatC,EAAYqC,2EA2BlDE,eAAgBX,EAAcjE,QAC9BF,iBAAkBoE,EAAUpE,iBAC5BsE,kCA1BF"}
|
package/dist/svelte/index.js
CHANGED
|
@@ -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)
|
|
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);
|
package/dist/svelte/index.js.map
CHANGED
|
@@ -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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AS,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,gBAA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A,QAAQ;AAAA;;;;AALP,UAAA,SAAS,QAAO,UAAA,UAAA;AAAA;;;;AAlBrB;ACdO,MAAM,+BAA+B,oBAAoBC,8BAA0B,EACvF,WAAW,UAAU,EACrB,MAAA;"}
|
package/dist/vue/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/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
|
|
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
|
package/dist/vue/index.cjs.map
CHANGED
|
@@ -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,IACtCC,YAAiCC,EAAAA,sBAAsBC,IAC5CC,EAA+B,IAC1CC,gBAAqCH,EAAAA,sBAAsBC,IAKtD,SAASG,IACd,MAAMC,EAAYC,EAAAA,eAclB,MAAO,CACLC,iBAbuBnB,EAAAA,SAAS,WAChC,OAAO,OAAAC,EAAAgB,EAAUf,YAAV,EAAAD,EAAiBkB,mBAAoB,OAa5CC,eAVqBpB,EAAAA,SAAS,KAC9B,MAAMqB,EAAOJ,EAAUf,MACvB,IAAKmB,EAAM,OAAO,KAElB,MAAMC,EAAQD,EAAKF,iBACnB,OAAOG,EAASD,EAAKE,UAAUD,IAAU,KAAQ,OAOrD,CAMO,SAASE,EAAiBC,GAC/B,MAAMR,EAAYC,EAAAA,eAsBlB,OApBkBlB,EAAAA,SAAS,KACzB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,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,MACTG,SAAUA,EAAAH,uCCrCFQ,EAA2B,IACtCC,YAAiCC,EAAAA,sBAAsBC,IAC5CC,EAA+B,IAC1CC,gBAAqCH,EAAAA,sBAAsBC,IAKtD,SAASG,IACd,MAAMC,EAAYC,EAAAA,eAclB,MAAO,CACLC,iBAbuBnB,EAAAA,SAAS,WAChC,OAAO,OAAAC,EAAAgB,EAAUf,YAAV,EAAAD,EAAiBkB,mBAAoB,OAa5CC,eAVqBpB,EAAAA,SAAS,KAC9B,MAAMqB,EAAOJ,EAAUf,MACvB,IAAKmB,EAAM,OAAO,KAElB,MAAMC,EAAQD,EAAKF,iBACnB,OAAOG,EAASD,EAAKE,UAAUD,IAAU,KAAQ,OAOrD,CAMO,SAASE,EAAiBC,GAC/B,MAAMR,EAAY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ACrB,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
|
|
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);
|
package/dist/vue/index.js.map
CHANGED
|
@@ -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,sBAAsB,EAAE;AAKxD,SAAS,oBAAoB;AAClC,QAAM,YAAY,aAAA;AAElB,QAAM,mBAAmB,SAAS,MAAM;;AACtC,aAAO,eAAU,UAAV,mBAAiB,qBAAoB;AAAA,EAC9C,CAAC;AAED,QAAM,iBAAiB,SAAS,MAAM;AACpC,UAAM,OAAO,UAAU;AACvB,QAAI,CAAC,KAAM,QAAO;AAElB,UAAM,QAAQ,KAAK;AACnB,WAAO,QAAS,KAAK,UAAU,KAAK,KAAK,OAAQ;AAAA,EACnD,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EAAA;AAEJ;AAMO,SAAS,iBA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C,aAAa,GAAG,cAAc;AAC7B,YAAI,EAAC,2CAAa,mBAAmB;AAErC,cAAM,cAAc,YAAY,kBAAkB,CAAC,EAAE,MAAM,cAAc;;AACvE,kBAAQ,QAAQ;AAChB,qBAAW,QAAQ;AACnB,yBAAS,UAAT,mBAAgB;AAAA,QAClB,CAAC;AAED,kBAAU,WAAW;AAAA,MACvB;AAAA,MACA,EAAE,WAAW,KAAA;AAAA,IAAK;AAGpB,UAAM,WAAW,OAAO,UAAiB;;AACvC,YAAM,SAAS,MAAM;AACrB,YAAM,QAAO,YAAO,UAAP,mBAAe;AAC5B,YAAM,MAAM,SAAS;AACrB,UAAI,CAAC,QAAQ,CAAC,IAAK;AAEnB,YAAM,SAAS,MAAM,KAAK,YAAA;AAC1B,YAAM,WAAW,IAAI,mBAAmB;AAAA,QACtC,MAAM,KAAK;AAAA,QACX;AAAA,QACA,aAAY,gBAAW,UAAX,mBAAkB;AAAA,QAC9B,QAAO,gBAAW,UAAX,mBAAkB;AAAA,QACzB,WAAU,gBAAW,UAAX,mBAAkB;AAAA,QAC5B,eAAc,gBAAW,UAAX,mBAAkB;AAAA,MAAA,CACjC;AAED,eAAS;AAAA,QACP,CAAC,WAAW;;AACV,WAAAE,MAAA,QAAQ,UAAR,gBAAAA,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;"}
|
|
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,2BAA2B,MACtC,UAAiC,sBAAsB,EAAE;AACpD,MAAM,+BAA+B,MAC1C,cAAqC,sBAAsB,EAAE;AAKxD,SAAS,oBAAoB;AAClC,QAAM,YAAY,aAAA;AAElB,QAAM,mBAAmB,SAAS,MAAM;;AACtC,aAAO,eAAU,UAAV,mBAAiB,qBAAoB;AAAA,EAC9C,CAAC;AAED,QAAM,iBAAiB,SAAS,MAAM;AACpC,UAAM,OAAO,UAAU;AACvB,QAAI,CAAC,KAAM,QAAO;AAElB,UAAM,QAAQ,KAAK;AACnB,WAAO,QAAS,KAAK,UAAU,KAAK,KAAK,OAAQ;AAAA,E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-1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-document-manager",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.1",
|
|
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.
|
|
37
|
+
"@embedpdf/models": "2.0.0-next.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/react": "^18.2.0",
|
|
41
41
|
"typescript": "^5.0.0",
|
|
42
42
|
"@embedpdf/build": "1.1.0",
|
|
43
|
-
"@embedpdf/core": "2.0.0-next.
|
|
43
|
+
"@embedpdf/core": "2.0.0-next.1"
|
|
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.
|
|
51
|
+
"@embedpdf/core": "2.0.0-next.1"
|
|
52
52
|
},
|
|
53
53
|
"files": [
|
|
54
54
|
"dist",
|