@embedpdf/plugin-history 1.5.0 → 2.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +239 -80
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +33 -8
- package/dist/lib/history-plugin.d.ts +12 -4
- package/dist/lib/types.d.ts +67 -7
- package/dist/preact/index.cjs +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-history.d.ts +11 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +2 -0
- package/dist/svelte/index.js +10 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vue/index.cjs +1 -1
- package/package.json +14 -6
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@embedpdf/core"),e="history",
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@embedpdf/core"),e="history",o={id:e,name:"History Plugin",version:"1.0.0",provides:["history"],requires:[],optional:[],defaultConfig:{enabled:!0}},n="HISTORY/INIT_STATE",i="HISTORY/CLEANUP_STATE",s="HISTORY/SET_DOCUMENT_STATE",c=class extends t.BasePlugin{constructor(e,o){super(e,o),this.documentHistories=new Map,this.historyChange$=t.createEmitter()}async initialize(t){this.logger.info("HistoryPlugin","Initialize","History plugin initialized")}onDocumentLoadingStarted(t){this.dispatch((t=>({type:n,payload:{documentId:t}}))(t)),this.documentHistories.set(t,{topicHistories:new Map,globalTimeline:[],globalIndex:-1}),this.logger.debug("HistoryPlugin","DocumentOpened",`Initialized history state for document: ${t}`)}onDocumentClosed(t){this.dispatch((t=>({type:i,payload:{documentId:t}}))(t)),this.documentHistories.delete(t),this.logger.debug("HistoryPlugin","DocumentClosed",`Cleaned up history state for document: ${t}`)}getDocumentHistoryData(t){const e=t??this.getActiveDocumentId(),o=this.documentHistories.get(e);if(!o)throw new Error(`History data not found for document: ${e}`);return o}getDocumentHistoryState(t){const e=this.documentHistories.get(t);if(!e)throw new Error(`History data not found for document: ${t}`);const o={};return Array.from(e.topicHistories.entries()).forEach(([t,e])=>{o[t]={canUndo:e.currentIndex>-1,canRedo:e.currentIndex<e.commands.length-1}}),{global:{canUndo:e.globalIndex>-1,canRedo:e.globalIndex<e.globalTimeline.length-1},topics:o}}emitHistoryChange(t,e){const o=this.getDocumentHistoryState(t);this.dispatch(((t,e)=>({type:s,payload:{documentId:t,state:e}}))(t,o)),this.historyChange$.emit({documentId:t,topic:e,state:o})}register(t,e,o){const n=this.getDocumentHistoryData(o);n.topicHistories.has(e)||n.topicHistories.set(e,{commands:[],currentIndex:-1});const i=n.topicHistories.get(e);i.commands.splice(i.currentIndex+1),i.commands.push(t),i.currentIndex++;const s={command:t,topic:e};n.globalTimeline.splice(n.globalIndex+1),n.globalTimeline.push(s),n.globalIndex++,t.execute(),this.emitHistoryChange(o,e)}undo(t,e){const o=this.getDocumentHistoryData(e);let n;if(t){const e=o.topicHistories.get(t);e&&e.currentIndex>-1&&(e.commands[e.currentIndex].undo(),e.currentIndex--,n=t)}else if(o.globalIndex>-1){const t=o.globalTimeline[o.globalIndex];t.command.undo(),o.topicHistories.get(t.topic).currentIndex--,o.globalIndex--,n=t.topic}n&&this.emitHistoryChange(e,n)}redo(t,e){const o=this.getDocumentHistoryData(e);let n;if(t){const e=o.topicHistories.get(t);e&&e.currentIndex<e.commands.length-1&&(e.currentIndex++,e.commands[e.currentIndex].execute(),n=t)}else if(o.globalIndex<o.globalTimeline.length-1){o.globalIndex++;const t=o.globalTimeline[o.globalIndex];t.command.execute(),o.topicHistories.get(t.topic).currentIndex++,n=t.topic}n&&this.emitHistoryChange(e,n)}canUndo(t,e){const o=this.getDocumentHistoryData(e);if(t){const e=o.topicHistories.get(t);return!!e&&e.currentIndex>-1}return o.globalIndex>-1}canRedo(t,e){const o=this.getDocumentHistoryData(e);if(t){const e=o.topicHistories.get(t);return!!e&&e.currentIndex<e.commands.length-1}return o.globalIndex<o.globalTimeline.length-1}createHistoryScope(t){return{register:(e,o)=>this.register(e,o,t),undo:e=>this.undo(e,t),redo:e=>this.redo(e,t),canUndo:e=>this.canUndo(e,t),canRedo:e=>this.canRedo(e,t),getHistoryState:()=>this.getDocumentHistoryState(t),onHistoryChange:e=>this.historyChange$.on(o=>{o.documentId===t&&e(o.topic)})}}buildCapability(){return{register:(t,e)=>{const o=this.getActiveDocumentId();this.register(t,e,o)},undo:t=>{const e=this.getActiveDocumentId();this.undo(t,e)},redo:t=>{const e=this.getActiveDocumentId();this.redo(t,e)},canUndo:t=>{const e=this.getActiveDocumentId();return this.canUndo(t,e)},canRedo:t=>{const e=this.getActiveDocumentId();return this.canRedo(t,e)},getHistoryState:()=>{const t=this.getActiveDocumentId();return this.getDocumentHistoryState(t)},forDocument:t=>this.createHistoryScope(t),onHistoryChange:this.historyChange$.on}}async destroy(){this.historyChange$.clear(),this.documentHistories.clear(),super.destroy()}};c.id="history";let r=c;const d={global:{canUndo:!1,canRedo:!1},topics:{}},a={documents:{},activeDocumentId:null},u={manifest:o,create:t=>new r(e,t),reducer:(t=a,e)=>{switch(e.type){case n:{const{documentId:o}=e.payload;return{...t,documents:{...t.documents,[o]:{...d}}}}case i:{const{documentId:o}=e.payload,{[o]:n,...i}=t.documents;return{...t,documents:i,activeDocumentId:t.activeDocumentId===o?null:t.activeDocumentId}}case s:{const{documentId:o,state:n}=e.payload;return t.documents[o]?{...t,documents:{...t.documents,[o]:n}}:t}case"HISTORY/SET_ACTIVE_DOCUMENT":return{...t,activeDocumentId:e.payload};default:return t}},initialState:a};exports.HISTORY_PLUGIN_ID=e,exports.HistoryPlugin=r,exports.HistoryPluginPackage=u,exports.manifest=o;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/history-plugin.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { HistoryPluginConfig } from './types';\n\nexport const HISTORY_PLUGIN_ID = 'history';\n\nexport const manifest: PluginManifest<HistoryPluginConfig> = {\n id: HISTORY_PLUGIN_ID,\n name: 'History Plugin',\n version: '1.0.0',\n provides: ['history'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Action } from '@embedpdf/core';\nimport { HistoryState } from './types';\n\nexport const SET_HISTORY_STATE = 'HISTORY/SET_STATE';\n\nexport interface SetHistoryStateAction extends Action {\n type: typeof SET_HISTORY_STATE;\n payload: HistoryState;\n}\n\nexport type HistoryAction = SetHistoryStateAction;\n\nexport const setHistoryState = (state: HistoryState): SetHistoryStateAction => ({\n type: SET_HISTORY_STATE,\n payload: state,\n});\n","import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\nimport {\n Command,\n HistoryCapability,\n HistoryEntry,\n HistoryPluginConfig,\n HistoryState,\n} from './types';\nimport { HistoryAction, setHistoryState } from './actions';\n\nexport class HistoryPlugin extends BasePlugin<\n HistoryPluginConfig,\n HistoryCapability,\n HistoryState,\n HistoryAction\n> {\n static readonly id = 'history' as const;\n\n private readonly topicHistories = new Map<\n string,\n { commands: Command[]; currentIndex: number }\n >();\n private globalTimeline: HistoryEntry[] = [];\n private globalIndex = -1;\n\n // This emitter will now broadcast the topic string of the affected history.\n private readonly historyChange$ = createEmitter<string | undefined>();\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n }\n\n async initialize(_: HistoryPluginConfig): Promise<void> {}\n\n private getHistoryState(): HistoryState {\n const topics: HistoryState['topics'] = {};\n Array.from(this.topicHistories.entries()).forEach(([topic, history]) => {\n topics[topic] = {\n canUndo: history.currentIndex > -1,\n canRedo: history.currentIndex < history.commands.length - 1,\n };\n });\n return {\n global: {\n canUndo: this.globalIndex > -1,\n canRedo: this.globalIndex < this.globalTimeline.length - 1,\n },\n topics,\n };\n }\n\n // The emit function now accepts the topic to broadcast.\n private emitHistoryChange(topic: string) {\n // update the state\n this.dispatch(setHistoryState(this.getHistoryState()));\n\n // emit the event\n this.historyChange$.emit(topic);\n }\n\n protected buildCapability(): HistoryCapability {\n return {\n getHistoryState: () => this.state,\n onHistoryChange: this.historyChange$.on,\n\n register: (command: Command, topic: string) => {\n // 1. Manage Topic History\n if (!this.topicHistories.has(topic)) {\n this.topicHistories.set(topic, { commands: [], currentIndex: -1 });\n }\n const topicHistory = this.topicHistories.get(topic)!;\n topicHistory.commands.splice(topicHistory.currentIndex + 1);\n topicHistory.commands.push(command);\n topicHistory.currentIndex++;\n\n // 2. Manage Global History\n const historyEntry: HistoryEntry = { command, topic };\n this.globalTimeline.splice(this.globalIndex + 1);\n this.globalTimeline.push(historyEntry);\n this.globalIndex++;\n\n // 3. Execute and notify with the specific topic\n command.execute();\n this.emitHistoryChange(topic);\n },\n\n undo: (topic?: string) => {\n let affectedTopic: string | undefined;\n\n if (topic) {\n // Scoped Undo\n const topicHistory = this.topicHistories.get(topic);\n if (topicHistory && topicHistory.currentIndex > -1) {\n topicHistory.commands[topicHistory.currentIndex].undo();\n topicHistory.currentIndex--;\n affectedTopic = topic;\n }\n } else {\n // Global Undo\n if (this.globalIndex > -1) {\n const entry = this.globalTimeline[this.globalIndex];\n entry.command.undo();\n this.topicHistories.get(entry.topic)!.currentIndex--;\n this.globalIndex--;\n affectedTopic = entry.topic;\n }\n }\n if (affectedTopic) this.emitHistoryChange(affectedTopic);\n },\n\n redo: (topic?: string) => {\n let affectedTopic: string | undefined;\n\n if (topic) {\n // Scoped Redo\n const topicHistory = this.topicHistories.get(topic);\n if (topicHistory && topicHistory.currentIndex < topicHistory.commands.length - 1) {\n topicHistory.currentIndex++;\n topicHistory.commands[topicHistory.currentIndex].execute();\n affectedTopic = topic;\n }\n } else {\n // Global Redo\n if (this.globalIndex < this.globalTimeline.length - 1) {\n this.globalIndex++;\n const entry = this.globalTimeline[this.globalIndex];\n entry.command.execute();\n this.topicHistories.get(entry.topic)!.currentIndex++;\n affectedTopic = entry.topic;\n }\n }\n if (affectedTopic) this.emitHistoryChange(affectedTopic);\n },\n\n canUndo: (topic?: string) => {\n if (topic) {\n const history = this.topicHistories.get(topic);\n return !!history && history.currentIndex > -1;\n }\n return this.globalIndex > -1;\n },\n\n canRedo: (topic?: string) => {\n if (topic) {\n const history = this.topicHistories.get(topic);\n return !!history && history.currentIndex < history.commands.length - 1;\n }\n return this.globalIndex < this.globalTimeline.length - 1;\n },\n };\n }\n}\n","import { Reducer } from '@embedpdf/core';\nimport { HistoryAction, SET_HISTORY_STATE } from './actions';\nimport { HistoryState } from './types';\n\nexport const initialState: HistoryState = {\n global: {\n canUndo: false,\n canRedo: false,\n },\n topics: {},\n};\n\nexport const reducer: Reducer<HistoryState, HistoryAction> = (state = initialState, action) => {\n switch (action.type) {\n case SET_HISTORY_STATE:\n return {\n ...state,\n ...action.payload,\n };\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, HISTORY_PLUGIN_ID } from './manifest';\nimport { HistoryPluginConfig, HistoryState } from './types';\nimport { HistoryPlugin } from './history-plugin';\nimport { initialState, reducer } from './reducer';\nimport { HistoryAction } from './actions';\n\nexport const HistoryPluginPackage: PluginPackage<\n HistoryPlugin,\n HistoryPluginConfig,\n HistoryState,\n HistoryAction\n> = {\n manifest,\n create: (registry) => new HistoryPlugin(HISTORY_PLUGIN_ID, registry),\n reducer,\n initialState,\n};\n\nexport * from './history-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["HISTORY_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","SET_HISTORY_STATE","_HistoryPlugin","BasePlugin","constructor","registry","super","this","topicHistories","Map","globalTimeline","globalIndex","historyChange$","createEmitter","initialize","_","getHistoryState","topics","Array","from","entries","forEach","topic","history","canUndo","currentIndex","canRedo","commands","length","global","emitHistoryChange","state","dispatch","type","payload","emit","buildCapability","onHistoryChange","on","register","command","has","set","topicHistory","get","splice","push","historyEntry","execute","undo","affectedTopic","entry","redo","HistoryPlugin","initialState","HistoryPluginPackage","create","reducer","action"],"mappings":"kHAGaA,EAAoB,UAEpBC,EAAgD,CAC3DC,GAAIF,EACJG,KAAM,iBACNC,QAAS,QACTC,SAAU,CAAC,WACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,ICVAC,EAAoB,oBCOpBC,EAAN,cAA4BC,EAAAA,WAkBjC,WAAAC,CAAYX,EAAYY,GACtBC,MAAMb,EAAIY,GAXKE,KAAAC,mBAAqBC,IAItCF,KAAQG,eAAiC,GACzCH,KAAQI,aAAc,EAGLJ,KAAAK,eAAiBC,iBAAkC,CAMpE,gBAAMC,CAAWC,GAAuC,CAEhD,eAAAC,GACN,MAAMC,EAAiC,CAAC,EAOjC,OANDC,MAAAC,KAAKZ,KAAKC,eAAeY,WAAWC,SAAQ,EAAEC,EAAOC,MACzDN,EAAOK,GAAS,CACdE,QAASD,EAAQE,cAAe,EAChCC,QAASH,EAAQE,aAAeF,EAAQI,SAASC,OAAS,EAC5D,IAEK,CACLC,OAAQ,CACNL,QAASjB,KAAKI,aAAc,EAC5Be,QAASnB,KAAKI,YAAcJ,KAAKG,eAAekB,OAAS,GAE3DX,SACF,CAIM,iBAAAa,CAAkBR,GDxCG,IAACS,EC0C5BxB,KAAKyB,UD1CuBD,EC0CExB,KAAKS,kBD1CyC,CAC9EiB,KAAMhC,EACNiC,QAASH,KC2CFxB,KAAAK,eAAeuB,KAAKb,EAAK,CAGtB,eAAAc,GACD,MAAA,CACLpB,gBAAiB,IAAMT,KAAKwB,MAC5BM,gBAAiB9B,KAAKK,eAAe0B,GAErCC,SAAU,CAACC,EAAkBlB,KAEtBf,K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M7B,OAAQG,eACtCyB,EAAgBC,EAAM7B,KAAA,CAGtB4B,GAAoB3C,KAAAuB,kBAAkBoB,EAAa,EAGzD1B,QAAUF,IACR,GAAIA,EAAO,CACT,MAAMC,EAAUhB,KAAKC,eAAeoC,IAAItB,GACxC,QAASC,GAAWA,EAAQE,cAAe,CAAA,CAE7C,OAAOlB,KAAKI,aAAc,CAAA,EAG5Be,QAAUJ,IACR,GAAIA,EAAO,CACT,MAAMC,EAAUhB,KAAKC,eAAeoC,IAAItB,GACxC,QAASC,GAAWA,EAAQE,aAAeF,EAAQI,SAASC,OAAS,CAAA,CAEvE,OAAOrB,KAAKI,YAAcJ,KAAKG,eAAekB,OAAS,CAAA,EAE3D,GArIF1B,EAAgBT,GAAK,UANhB,IAAM4D,EAANnD,ECNA,MAAMoD,EAA6B,CACxCzB,OAAQ,CACNL,SAAS,EACTE,SAAS,GAEXT,OAAQ,CAAA,GCFGsC,EAKT,CACF/D,WACAgE,OAASnD,GAAa,IAAIgD,EAAc9D,EAAmBc,GAC3DoD,QDH2D,CAAC1B,EAAQuB,EAAcI,IAC1EA,EAAOzB,OACRhC,EACI,IACF8B,KACA2B,EAAOxB,SAGLH,ECJXuB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/history-plugin.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { HistoryPluginConfig } from './types';\n\nexport const HISTORY_PLUGIN_ID = 'history';\n\nexport const manifest: PluginManifest<HistoryPluginConfig> = {\n id: HISTORY_PLUGIN_ID,\n name: 'History Plugin',\n version: '1.0.0',\n provides: ['history'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Action } from '@embedpdf/core';\nimport { HistoryDocumentState } from './types';\n\n// Document lifecycle actions\nexport const INIT_HISTORY_STATE = 'HISTORY/INIT_STATE';\nexport const CLEANUP_HISTORY_STATE = 'HISTORY/CLEANUP_STATE';\n\n// History state updates\nexport const SET_HISTORY_DOCUMENT_STATE = 'HISTORY/SET_DOCUMENT_STATE';\nexport const SET_ACTIVE_HISTORY_DOCUMENT = 'HISTORY/SET_ACTIVE_DOCUMENT';\n\n// Document lifecycle action interfaces\nexport interface InitHistoryStateAction extends Action {\n type: typeof INIT_HISTORY_STATE;\n payload: {\n documentId: string;\n };\n}\n\nexport interface CleanupHistoryStateAction extends Action {\n type: typeof CLEANUP_HISTORY_STATE;\n payload: {\n documentId: string;\n };\n}\n\n// State update action interfaces\nexport interface SetHistoryDocumentStateAction extends Action {\n type: typeof SET_HISTORY_DOCUMENT_STATE;\n payload: {\n documentId: string;\n state: HistoryDocumentState;\n };\n}\n\nexport interface SetActiveHistoryDocumentAction extends Action {\n type: typeof SET_ACTIVE_HISTORY_DOCUMENT;\n payload: string | null; // documentId\n}\n\nexport type HistoryAction =\n | InitHistoryStateAction\n | CleanupHistoryStateAction\n | SetHistoryDocumentStateAction\n | SetActiveHistoryDocumentAction;\n\n// Action creators\nexport const initHistoryState = (documentId: string): InitHistoryStateAction => ({\n type: INIT_HISTORY_STATE,\n payload: { documentId },\n});\n\nexport const cleanupHistoryState = (documentId: string): CleanupHistoryStateAction => ({\n type: CLEANUP_HISTORY_STATE,\n payload: { documentId },\n});\n\nexport const setHistoryDocumentState = (\n documentId: string,\n state: HistoryDocumentState,\n): SetHistoryDocumentStateAction => ({\n type: SET_HISTORY_DOCUMENT_STATE,\n payload: { documentId, state },\n});\n\nexport const setActiveHistoryDocument = (\n documentId: string | null,\n): SetActiveHistoryDocumentAction => ({\n type: SET_ACTIVE_HISTORY_DOCUMENT,\n payload: documentId,\n});\n","import { BasePlugin, createEmitter, Listener, PluginRegistry } from '@embedpdf/core';\nimport {\n Command,\n HistoryCapability,\n HistoryChangeEvent,\n HistoryDocumentState,\n HistoryEntry,\n HistoryPluginConfig,\n HistoryScope,\n HistoryState,\n} from './types';\nimport {\n HistoryAction,\n initHistoryState,\n cleanupHistoryState,\n setHistoryDocumentState,\n} from './actions';\n\ninterface DocumentHistoryData {\n topicHistories: Map<string, { commands: Command[]; currentIndex: number }>;\n globalTimeline: HistoryEntry[];\n globalIndex: number;\n}\n\nexport class HistoryPlugin extends BasePlugin<\n HistoryPluginConfig,\n HistoryCapability,\n HistoryState,\n HistoryAction\n> {\n static readonly id = 'history' as const;\n\n // Per-document history data (persisted with state)\n private readonly documentHistories = new Map<string, DocumentHistoryData>();\n\n // Event emitter for history changes\n private readonly historyChange$ = createEmitter<HistoryChangeEvent>();\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n }\n\n async initialize(_: HistoryPluginConfig): Promise<void> {\n this.logger.info('HistoryPlugin', 'Initialize', 'History plugin initialized');\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Lifecycle (from BasePlugin)\n // ─────────────────────────────────────────────────────────\n\n protected override onDocumentLoadingStarted(documentId: string): void {\n // Initialize history state for this document\n this.dispatch(initHistoryState(documentId));\n\n // Create document history data\n this.documentHistories.set(documentId, {\n topicHistories: new Map(),\n globalTimeline: [],\n globalIndex: -1,\n });\n\n this.logger.debug(\n 'HistoryPlugin',\n 'DocumentOpened',\n `Initialized history state for document: ${documentId}`,\n );\n }\n\n protected override onDocumentClosed(documentId: string): void {\n // Cleanup history state\n this.dispatch(cleanupHistoryState(documentId));\n\n // Cleanup document history data\n this.documentHistories.delete(documentId);\n\n this.logger.debug(\n 'HistoryPlugin',\n 'DocumentClosed',\n `Cleaned up history state for document: ${documentId}`,\n );\n }\n\n // ─────────────────────────────────────────────────────────\n // Helper Methods\n // ─────────────────────────────────────────────────────────\n\n private getDocumentHistoryData(documentId?: string): DocumentHistoryData {\n const id = documentId ?? this.getActiveDocumentId();\n const data = this.documentHistories.get(id);\n if (!data) {\n throw new Error(`History data not found for document: ${id}`);\n }\n return data;\n }\n\n private getDocumentHistoryState(documentId: string): HistoryDocumentState {\n const data = this.documentHistories.get(documentId);\n if (!data) {\n throw new Error(`History data not found for document: ${documentId}`);\n }\n\n const topics: HistoryDocumentState['topics'] = {};\n Array.from(data.topicHistories.entries()).forEach(([topic, history]) => {\n topics[topic] = {\n canUndo: history.currentIndex > -1,\n canRedo: history.currentIndex < history.commands.length - 1,\n };\n });\n\n return {\n global: {\n canUndo: data.globalIndex > -1,\n canRedo: data.globalIndex < data.globalTimeline.length - 1,\n },\n topics,\n };\n }\n\n private emitHistoryChange(documentId: string, topic: string | undefined) {\n // Update the state\n const state = this.getDocumentHistoryState(documentId);\n this.dispatch(setHistoryDocumentState(documentId, state));\n\n // Emit the event\n this.historyChange$.emit({\n documentId,\n topic,\n state,\n });\n }\n\n // ─────────────────────────────────────────────────────────\n // History Operations (per document)\n // ─────────────────────────────────────────────────────────\n\n private register(command: Command, topic: string, documentId: string): void {\n const data = this.getDocumentHistoryData(documentId);\n\n // 1. Manage Topic History\n if (!data.topicHistories.has(topic)) {\n data.topicHistories.set(topic, { commands: [], currentIndex: -1 });\n }\n const topicHistory = data.topicHistories.get(topic)!;\n topicHistory.commands.splice(topicHistory.currentIndex + 1);\n topicHistory.commands.push(command);\n topicHistory.currentIndex++;\n\n // 2. Manage Global History\n const historyEntry: HistoryEntry = { command, topic };\n data.globalTimeline.splice(data.globalIndex + 1);\n data.globalTimeline.push(historyEntry);\n data.globalIndex++;\n\n // 3. Execute and notify with the specific topic\n command.execute();\n this.emitHistoryChange(documentId, topic);\n }\n\n private undo(topic: string | undefined, documentId: string): void {\n const data = this.getDocumentHistoryData(documentId);\n let affectedTopic: string | undefined;\n\n if (topic) {\n // Scoped Undo\n const topicHistory = data.topicHistories.get(topic);\n if (topicHistory && topicHistory.currentIndex > -1) {\n topicHistory.commands[topicHistory.currentIndex].undo();\n topicHistory.currentIndex--;\n affectedTopic = topic;\n }\n } else {\n // Global Undo\n if (data.globalIndex > -1) {\n const entry = data.globalTimeline[data.globalIndex];\n entry.command.undo();\n data.topicHistories.get(entry.topic)!.currentIndex--;\n data.globalIndex--;\n affectedTopic = entry.topic;\n }\n }\n\n if (affectedTopic) {\n this.emitHistoryChange(documentId, affectedTopic);\n }\n }\n\n private redo(topic: string | undefined, documentId: string): void {\n const data = this.getDocumentHistoryData(documentId);\n let affectedTopic: string | undefined;\n\n if (topic) {\n // Scoped Redo\n const topicHistory = data.topicHistories.get(topic);\n if (topicHistory && topicHistory.currentIndex < topicHistory.commands.length - 1) {\n topicHistory.currentIndex++;\n topicHistory.commands[topicHistory.currentIndex].execute();\n affectedTopic = topic;\n }\n } else {\n // Global Redo\n if (data.globalIndex < data.globalTimeline.length - 1) {\n data.globalIndex++;\n const entry = data.globalTimeline[data.globalIndex];\n entry.command.execute();\n data.topicHistories.get(entry.topic)!.currentIndex++;\n affectedTopic = entry.topic;\n }\n }\n\n if (affectedTopic) {\n this.emitHistoryChange(documentId, affectedTopic);\n }\n }\n\n private canUndo(topic: string | undefined, documentId: string): boolean {\n const data = this.getDocumentHistoryData(documentId);\n\n if (topic) {\n const history = data.topicHistories.get(topic);\n return !!history && history.currentIndex > -1;\n }\n return data.globalIndex > -1;\n }\n\n private canRedo(topic: string | undefined, documentId: string): boolean {\n const data = this.getDocumentHistoryData(documentId);\n\n if (topic) {\n const history = data.topicHistories.get(topic);\n return !!history && history.currentIndex < history.commands.length - 1;\n }\n return data.globalIndex < data.globalTimeline.length - 1;\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createHistoryScope(documentId: string): HistoryScope {\n return {\n register: (command: Command, topic: string) => this.register(command, topic, documentId),\n undo: (topic?: string) => this.undo(topic, documentId),\n redo: (topic?: string) => this.redo(topic, documentId),\n canUndo: (topic?: string) => this.canUndo(topic, documentId),\n canRedo: (topic?: string) => this.canRedo(topic, documentId),\n getHistoryState: () => this.getDocumentHistoryState(documentId),\n onHistoryChange: (listener: Listener<string | undefined>) =>\n this.historyChange$.on((event) => {\n if (event.documentId === documentId) {\n listener(event.topic);\n }\n }),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): HistoryCapability {\n return {\n // Active document operations\n register: (command: Command, topic: string) => {\n const documentId = this.getActiveDocumentId();\n this.register(command, topic, documentId);\n },\n\n undo: (topic?: string) => {\n const documentId = this.getActiveDocumentId();\n this.undo(topic, documentId);\n },\n\n redo: (topic?: string) => {\n const documentId = this.getActiveDocumentId();\n this.redo(topic, documentId);\n },\n\n canUndo: (topic?: string) => {\n const documentId = this.getActiveDocumentId();\n return this.canUndo(topic, documentId);\n },\n\n canRedo: (topic?: string) => {\n const documentId = this.getActiveDocumentId();\n return this.canRedo(topic, documentId);\n },\n\n getHistoryState: () => {\n const documentId = this.getActiveDocumentId();\n return this.getDocumentHistoryState(documentId);\n },\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createHistoryScope(documentId),\n\n // Events\n onHistoryChange: this.historyChange$.on,\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async destroy(): Promise<void> {\n // Clear all emitters\n this.historyChange$.clear();\n\n // Clear document histories\n this.documentHistories.clear();\n\n super.destroy();\n }\n}\n","import { Reducer } from '@embedpdf/core';\nimport {\n HistoryAction,\n INIT_HISTORY_STATE,\n CLEANUP_HISTORY_STATE,\n SET_HISTORY_DOCUMENT_STATE,\n SET_ACTIVE_HISTORY_DOCUMENT,\n} from './actions';\nimport { HistoryState, HistoryDocumentState } from './types';\n\nconst initialDocumentState: HistoryDocumentState = {\n global: {\n canUndo: false,\n canRedo: false,\n },\n topics: {},\n};\n\nexport const initialState: HistoryState = {\n documents: {},\n activeDocumentId: null,\n};\n\nexport const reducer: Reducer<HistoryState, HistoryAction> = (state = initialState, action) => {\n switch (action.type) {\n case INIT_HISTORY_STATE: {\n const { documentId } = action.payload;\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: { ...initialDocumentState },\n },\n };\n }\n\n case CLEANUP_HISTORY_STATE: {\n const { documentId } = action.payload;\n const { [documentId]: removed, ...remainingDocs } = state.documents;\n\n return {\n ...state,\n documents: remainingDocs,\n activeDocumentId: state.activeDocumentId === documentId ? null : state.activeDocumentId,\n };\n }\n\n case SET_HISTORY_DOCUMENT_STATE: {\n const { documentId, state: docState } = action.payload;\n if (!state.documents[documentId]) {\n return state;\n }\n\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: docState,\n },\n };\n }\n\n case SET_ACTIVE_HISTORY_DOCUMENT: {\n return {\n ...state,\n activeDocumentId: action.payload,\n };\n }\n\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, HISTORY_PLUGIN_ID } from './manifest';\nimport { HistoryPluginConfig, HistoryState } from './types';\nimport { HistoryPlugin } from './history-plugin';\nimport { initialState, reducer } from './reducer';\nimport { HistoryAction } from './actions';\n\nexport const HistoryPluginPackage: PluginPackage<\n HistoryPlugin,\n HistoryPluginConfig,\n HistoryState,\n HistoryAction\n> = {\n manifest,\n create: (registry) => new HistoryPlugin(HISTORY_PLUGIN_ID, registry),\n reducer,\n initialState,\n};\n\nexport * from './history-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["HISTORY_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","INIT_HISTORY_STATE","CLEANUP_HISTORY_STATE","SET_HISTORY_DOCUMENT_STATE","_HistoryPlugin","BasePlugin","constructor","registry","super","this","documentHistories","Map","historyChange$","createEmitter","initialize","_","logger","info","onDocumentLoadingStarted","documentId","dispatch","type","payload","initHistoryState","set","topicHistories","globalTimeline","globalIndex","debug","onDocumentClosed","cleanupHistoryState","delete","getDocumentHistoryData","getActiveDocumentId","data","get","Error","getDocumentHistoryState","topics","Array","from","entries","forEach","topic","history","canUndo","currentIndex","canRedo","commands","length","global","emitHistoryChange","state","setHistoryDocumentState","emit","register","command","has","topicHistory","splice","push","historyEntry","execute","undo","affectedTopic","entry","redo","createHistoryScope","getHistoryState","onHistoryChange","listener","on","event","buildCapability","forDocument","destroy","clear","HistoryPlugin","initialDocumentState","initialState","documents","activeDocumentId","HistoryPluginPackage","create","reducer","action","removed","remainingDocs","docState"],"mappings":"kHAGaA,EAAoB,UAEpBC,EAAgD,CAC3DC,GAAIF,EACJG,KAAM,iBACNC,QAAS,QACTC,SAAU,CAAC,WACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,ICTAC,EAAqB,qBACrBC,EAAwB,wBAGxBC,EAA6B,6BCgB7BC,EAAN,cAA4BC,EAAAA,WAcjC,WAAAC,CAAYb,EAAYc,GACtBC,MAAMf,EAAIc,GANZE,KAAiBC,sBAAwBC,IAGzCF,KAAiBG,eAAiBC,iBAIlC,CAEA,gBAAMC,CAAWC,GACfN,KAAKO,OAAOC,KAAK,gBAAiB,aAAc,6BAClD,CAMmB,wBAAAC,CAAyBC,GAE1CV,KAAKW,SDLuB,CAACD,IAAA,CAC/BE,KAAMpB,EACNqB,QAAS,CAAEH,gBCGKI,CAAiBJ,IAG/BV,KAAKC,kBAAkBc,IAAIL,EAAY,CACrCM,mBAAoBd,IACpBe,eAAgB,GAChBC,aAAa,IAGflB,KAAKO,OAAOY,MACV,gBACA,iBACA,2CAA2CT,IAE/C,CAEmB,gBAAAU,CAAiBV,GAElCV,KAAKW,SDlB0B,CAACD,IAAA,CAClCE,KAAMnB,EACNoB,QAAS,CAAEH,gBCgBKW,CAAoBX,IAGlCV,KAAKC,kBAAkBqB,OAAOZ,GAE9BV,KAAKO,OAAOY,MACV,gBACA,iBACA,0CAA0CT,IAE9C,CAMQ,sBAAAa,CAAuBb,GAC7B,MAAM1B,EAAK0B,GAAcV,KAAKwB,sBACxBC,EAAOzB,KAAKC,kBAAkByB,IAAI1C,GACxC,IAAKyC,EACH,MAAM,IAAIE,MAAM,wCAAwC3C,KAE1D,OAAOyC,CACT,CAEQ,uBAAAG,CAAwBlB,GAC9B,MAAMe,EAAOzB,KAAKC,kBAAkByB,IAAIhB,GACxC,IAAKe,EACH,MAAM,IAAIE,MAAM,wCAA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AKC,kBAAkBkE,QAEvBpE,MAAMmE,SACR,GA1RAvE,EAAgBX,GAAK,UANhB,IAAMoF,EAANzE,ECdP,MAAM0E,EAA6C,CACjD5B,OAAQ,CACNL,SAAS,EACTE,SAAS,GAEXT,OAAQ,CAAA,GAGGyC,EAA6B,CACxCC,UAAW,CAAA,EACXC,iBAAkB,MCbPC,EAKT,CACF1F,WACA2F,OAAS5E,GAAa,IAAIsE,EAActF,EAAmBgB,GAC3D6E,QDQ2D,CAAChC,EAAQ2B,EAAcM,KAClF,OAAQA,EAAOhE,MACb,KAAKpB,EAAoB,CACvB,MAAMkB,WAAEA,GAAekE,EAAO/D,QAC9B,MAAO,IACF8B,EACH4B,UAAW,IACN5B,EAAM4B,UACT7D,CAACA,GAAa,IAAK2D,IAGzB,CAEA,KAAK5E,EAAuB,CAC1B,MAAMiB,WAAEA,GAAekE,EAAO/D,SACtBH,CAACA,GAAamE,KAAYC,GAAkBnC,EAAM4B,UAE1D,MAAO,IACF5B,EACH4B,UAAWO,EACXN,iBAAkB7B,EAAM6B,mBAAqB9D,EAAa,KAAOiC,EAAM6B,iBAE3E,CAEA,KAAK9E,EAA4B,CAC/B,MAAMgB,WAAEA,EAAYiC,MAAOoC,GAAaH,EAAO/D,QAC/C,OAAK8B,EAAM4B,UAAU7D,GAId,IACFiC,EACH4B,UAAW,IACN5B,EAAM4B,UACT7D,CAACA,GAAaqE,IAPTpC,CAUX,CAEA,IFrDuC,8BEsDrC,MAAO,IACFA,EACH6B,iBAAkBI,EAAO/D,SAI7B,QACE,OAAO8B,ICtDX2B"}
|
package/dist/index.js
CHANGED
|
@@ -11,24 +11,74 @@ const manifest = {
|
|
|
11
11
|
enabled: true
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const INIT_HISTORY_STATE = "HISTORY/INIT_STATE";
|
|
15
|
+
const CLEANUP_HISTORY_STATE = "HISTORY/CLEANUP_STATE";
|
|
16
|
+
const SET_HISTORY_DOCUMENT_STATE = "HISTORY/SET_DOCUMENT_STATE";
|
|
17
|
+
const SET_ACTIVE_HISTORY_DOCUMENT = "HISTORY/SET_ACTIVE_DOCUMENT";
|
|
18
|
+
const initHistoryState = (documentId) => ({
|
|
19
|
+
type: INIT_HISTORY_STATE,
|
|
20
|
+
payload: { documentId }
|
|
21
|
+
});
|
|
22
|
+
const cleanupHistoryState = (documentId) => ({
|
|
23
|
+
type: CLEANUP_HISTORY_STATE,
|
|
24
|
+
payload: { documentId }
|
|
25
|
+
});
|
|
26
|
+
const setHistoryDocumentState = (documentId, state) => ({
|
|
27
|
+
type: SET_HISTORY_DOCUMENT_STATE,
|
|
28
|
+
payload: { documentId, state }
|
|
18
29
|
});
|
|
19
30
|
const _HistoryPlugin = class _HistoryPlugin extends BasePlugin {
|
|
20
31
|
constructor(id, registry) {
|
|
21
32
|
super(id, registry);
|
|
22
|
-
this.
|
|
23
|
-
this.globalTimeline = [];
|
|
24
|
-
this.globalIndex = -1;
|
|
33
|
+
this.documentHistories = /* @__PURE__ */ new Map();
|
|
25
34
|
this.historyChange$ = createEmitter();
|
|
26
35
|
}
|
|
27
36
|
async initialize(_) {
|
|
37
|
+
this.logger.info("HistoryPlugin", "Initialize", "History plugin initialized");
|
|
38
|
+
}
|
|
39
|
+
// ─────────────────────────────────────────────────────────
|
|
40
|
+
// Document Lifecycle (from BasePlugin)
|
|
41
|
+
// ─────────────────────────────────────────────────────────
|
|
42
|
+
onDocumentLoadingStarted(documentId) {
|
|
43
|
+
this.dispatch(initHistoryState(documentId));
|
|
44
|
+
this.documentHistories.set(documentId, {
|
|
45
|
+
topicHistories: /* @__PURE__ */ new Map(),
|
|
46
|
+
globalTimeline: [],
|
|
47
|
+
globalIndex: -1
|
|
48
|
+
});
|
|
49
|
+
this.logger.debug(
|
|
50
|
+
"HistoryPlugin",
|
|
51
|
+
"DocumentOpened",
|
|
52
|
+
`Initialized history state for document: ${documentId}`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
onDocumentClosed(documentId) {
|
|
56
|
+
this.dispatch(cleanupHistoryState(documentId));
|
|
57
|
+
this.documentHistories.delete(documentId);
|
|
58
|
+
this.logger.debug(
|
|
59
|
+
"HistoryPlugin",
|
|
60
|
+
"DocumentClosed",
|
|
61
|
+
`Cleaned up history state for document: ${documentId}`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
// ─────────────────────────────────────────────────────────
|
|
65
|
+
// Helper Methods
|
|
66
|
+
// ─────────────────────────────────────────────────────────
|
|
67
|
+
getDocumentHistoryData(documentId) {
|
|
68
|
+
const id = documentId ?? this.getActiveDocumentId();
|
|
69
|
+
const data = this.documentHistories.get(id);
|
|
70
|
+
if (!data) {
|
|
71
|
+
throw new Error(`History data not found for document: ${id}`);
|
|
72
|
+
}
|
|
73
|
+
return data;
|
|
28
74
|
}
|
|
29
|
-
|
|
75
|
+
getDocumentHistoryState(documentId) {
|
|
76
|
+
const data = this.documentHistories.get(documentId);
|
|
77
|
+
if (!data) {
|
|
78
|
+
throw new Error(`History data not found for document: ${documentId}`);
|
|
79
|
+
}
|
|
30
80
|
const topics = {};
|
|
31
|
-
Array.from(
|
|
81
|
+
Array.from(data.topicHistories.entries()).forEach(([topic, history]) => {
|
|
32
82
|
topics[topic] = {
|
|
33
83
|
canUndo: history.currentIndex > -1,
|
|
34
84
|
canRedo: history.currentIndex < history.commands.length - 1
|
|
@@ -36,109 +86,218 @@ const _HistoryPlugin = class _HistoryPlugin extends BasePlugin {
|
|
|
36
86
|
});
|
|
37
87
|
return {
|
|
38
88
|
global: {
|
|
39
|
-
canUndo:
|
|
40
|
-
canRedo:
|
|
89
|
+
canUndo: data.globalIndex > -1,
|
|
90
|
+
canRedo: data.globalIndex < data.globalTimeline.length - 1
|
|
41
91
|
},
|
|
42
92
|
topics
|
|
43
93
|
};
|
|
44
94
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.dispatch(
|
|
48
|
-
this.historyChange$.emit(
|
|
95
|
+
emitHistoryChange(documentId, topic) {
|
|
96
|
+
const state = this.getDocumentHistoryState(documentId);
|
|
97
|
+
this.dispatch(setHistoryDocumentState(documentId, state));
|
|
98
|
+
this.historyChange$.emit({
|
|
99
|
+
documentId,
|
|
100
|
+
topic,
|
|
101
|
+
state
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// ─────────────────────────────────────────────────────────
|
|
105
|
+
// History Operations (per document)
|
|
106
|
+
// ─────────────────────────────────────────────────────────
|
|
107
|
+
register(command, topic, documentId) {
|
|
108
|
+
const data = this.getDocumentHistoryData(documentId);
|
|
109
|
+
if (!data.topicHistories.has(topic)) {
|
|
110
|
+
data.topicHistories.set(topic, { commands: [], currentIndex: -1 });
|
|
111
|
+
}
|
|
112
|
+
const topicHistory = data.topicHistories.get(topic);
|
|
113
|
+
topicHistory.commands.splice(topicHistory.currentIndex + 1);
|
|
114
|
+
topicHistory.commands.push(command);
|
|
115
|
+
topicHistory.currentIndex++;
|
|
116
|
+
const historyEntry = { command, topic };
|
|
117
|
+
data.globalTimeline.splice(data.globalIndex + 1);
|
|
118
|
+
data.globalTimeline.push(historyEntry);
|
|
119
|
+
data.globalIndex++;
|
|
120
|
+
command.execute();
|
|
121
|
+
this.emitHistoryChange(documentId, topic);
|
|
122
|
+
}
|
|
123
|
+
undo(topic, documentId) {
|
|
124
|
+
const data = this.getDocumentHistoryData(documentId);
|
|
125
|
+
let affectedTopic;
|
|
126
|
+
if (topic) {
|
|
127
|
+
const topicHistory = data.topicHistories.get(topic);
|
|
128
|
+
if (topicHistory && topicHistory.currentIndex > -1) {
|
|
129
|
+
topicHistory.commands[topicHistory.currentIndex].undo();
|
|
130
|
+
topicHistory.currentIndex--;
|
|
131
|
+
affectedTopic = topic;
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
if (data.globalIndex > -1) {
|
|
135
|
+
const entry = data.globalTimeline[data.globalIndex];
|
|
136
|
+
entry.command.undo();
|
|
137
|
+
data.topicHistories.get(entry.topic).currentIndex--;
|
|
138
|
+
data.globalIndex--;
|
|
139
|
+
affectedTopic = entry.topic;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (affectedTopic) {
|
|
143
|
+
this.emitHistoryChange(documentId, affectedTopic);
|
|
144
|
+
}
|
|
49
145
|
}
|
|
146
|
+
redo(topic, documentId) {
|
|
147
|
+
const data = this.getDocumentHistoryData(documentId);
|
|
148
|
+
let affectedTopic;
|
|
149
|
+
if (topic) {
|
|
150
|
+
const topicHistory = data.topicHistories.get(topic);
|
|
151
|
+
if (topicHistory && topicHistory.currentIndex < topicHistory.commands.length - 1) {
|
|
152
|
+
topicHistory.currentIndex++;
|
|
153
|
+
topicHistory.commands[topicHistory.currentIndex].execute();
|
|
154
|
+
affectedTopic = topic;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
if (data.globalIndex < data.globalTimeline.length - 1) {
|
|
158
|
+
data.globalIndex++;
|
|
159
|
+
const entry = data.globalTimeline[data.globalIndex];
|
|
160
|
+
entry.command.execute();
|
|
161
|
+
data.topicHistories.get(entry.topic).currentIndex++;
|
|
162
|
+
affectedTopic = entry.topic;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (affectedTopic) {
|
|
166
|
+
this.emitHistoryChange(documentId, affectedTopic);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
canUndo(topic, documentId) {
|
|
170
|
+
const data = this.getDocumentHistoryData(documentId);
|
|
171
|
+
if (topic) {
|
|
172
|
+
const history = data.topicHistories.get(topic);
|
|
173
|
+
return !!history && history.currentIndex > -1;
|
|
174
|
+
}
|
|
175
|
+
return data.globalIndex > -1;
|
|
176
|
+
}
|
|
177
|
+
canRedo(topic, documentId) {
|
|
178
|
+
const data = this.getDocumentHistoryData(documentId);
|
|
179
|
+
if (topic) {
|
|
180
|
+
const history = data.topicHistories.get(topic);
|
|
181
|
+
return !!history && history.currentIndex < history.commands.length - 1;
|
|
182
|
+
}
|
|
183
|
+
return data.globalIndex < data.globalTimeline.length - 1;
|
|
184
|
+
}
|
|
185
|
+
// ─────────────────────────────────────────────────────────
|
|
186
|
+
// Document Scoping
|
|
187
|
+
// ─────────────────────────────────────────────────────────
|
|
188
|
+
createHistoryScope(documentId) {
|
|
189
|
+
return {
|
|
190
|
+
register: (command, topic) => this.register(command, topic, documentId),
|
|
191
|
+
undo: (topic) => this.undo(topic, documentId),
|
|
192
|
+
redo: (topic) => this.redo(topic, documentId),
|
|
193
|
+
canUndo: (topic) => this.canUndo(topic, documentId),
|
|
194
|
+
canRedo: (topic) => this.canRedo(topic, documentId),
|
|
195
|
+
getHistoryState: () => this.getDocumentHistoryState(documentId),
|
|
196
|
+
onHistoryChange: (listener) => this.historyChange$.on((event) => {
|
|
197
|
+
if (event.documentId === documentId) {
|
|
198
|
+
listener(event.topic);
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
// ─────────────────────────────────────────────────────────
|
|
204
|
+
// Capability
|
|
205
|
+
// ─────────────────────────────────────────────────────────
|
|
50
206
|
buildCapability() {
|
|
51
207
|
return {
|
|
52
|
-
|
|
53
|
-
onHistoryChange: this.historyChange$.on,
|
|
208
|
+
// Active document operations
|
|
54
209
|
register: (command, topic) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
const topicHistory = this.topicHistories.get(topic);
|
|
59
|
-
topicHistory.commands.splice(topicHistory.currentIndex + 1);
|
|
60
|
-
topicHistory.commands.push(command);
|
|
61
|
-
topicHistory.currentIndex++;
|
|
62
|
-
const historyEntry = { command, topic };
|
|
63
|
-
this.globalTimeline.splice(this.globalIndex + 1);
|
|
64
|
-
this.globalTimeline.push(historyEntry);
|
|
65
|
-
this.globalIndex++;
|
|
66
|
-
command.execute();
|
|
67
|
-
this.emitHistoryChange(topic);
|
|
210
|
+
const documentId = this.getActiveDocumentId();
|
|
211
|
+
this.register(command, topic, documentId);
|
|
68
212
|
},
|
|
69
213
|
undo: (topic) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const topicHistory = this.topicHistories.get(topic);
|
|
73
|
-
if (topicHistory && topicHistory.currentIndex > -1) {
|
|
74
|
-
topicHistory.commands[topicHistory.currentIndex].undo();
|
|
75
|
-
topicHistory.currentIndex--;
|
|
76
|
-
affectedTopic = topic;
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
if (this.globalIndex > -1) {
|
|
80
|
-
const entry = this.globalTimeline[this.globalIndex];
|
|
81
|
-
entry.command.undo();
|
|
82
|
-
this.topicHistories.get(entry.topic).currentIndex--;
|
|
83
|
-
this.globalIndex--;
|
|
84
|
-
affectedTopic = entry.topic;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (affectedTopic) this.emitHistoryChange(affectedTopic);
|
|
214
|
+
const documentId = this.getActiveDocumentId();
|
|
215
|
+
this.undo(topic, documentId);
|
|
88
216
|
},
|
|
89
217
|
redo: (topic) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const topicHistory = this.topicHistories.get(topic);
|
|
93
|
-
if (topicHistory && topicHistory.currentIndex < topicHistory.commands.length - 1) {
|
|
94
|
-
topicHistory.currentIndex++;
|
|
95
|
-
topicHistory.commands[topicHistory.currentIndex].execute();
|
|
96
|
-
affectedTopic = topic;
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
if (this.globalIndex < this.globalTimeline.length - 1) {
|
|
100
|
-
this.globalIndex++;
|
|
101
|
-
const entry = this.globalTimeline[this.globalIndex];
|
|
102
|
-
entry.command.execute();
|
|
103
|
-
this.topicHistories.get(entry.topic).currentIndex++;
|
|
104
|
-
affectedTopic = entry.topic;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (affectedTopic) this.emitHistoryChange(affectedTopic);
|
|
218
|
+
const documentId = this.getActiveDocumentId();
|
|
219
|
+
this.redo(topic, documentId);
|
|
108
220
|
},
|
|
109
221
|
canUndo: (topic) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return !!history && history.currentIndex > -1;
|
|
113
|
-
}
|
|
114
|
-
return this.globalIndex > -1;
|
|
222
|
+
const documentId = this.getActiveDocumentId();
|
|
223
|
+
return this.canUndo(topic, documentId);
|
|
115
224
|
},
|
|
116
225
|
canRedo: (topic) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
226
|
+
const documentId = this.getActiveDocumentId();
|
|
227
|
+
return this.canRedo(topic, documentId);
|
|
228
|
+
},
|
|
229
|
+
getHistoryState: () => {
|
|
230
|
+
const documentId = this.getActiveDocumentId();
|
|
231
|
+
return this.getDocumentHistoryState(documentId);
|
|
232
|
+
},
|
|
233
|
+
// Document-scoped operations
|
|
234
|
+
forDocument: (documentId) => this.createHistoryScope(documentId),
|
|
235
|
+
// Events
|
|
236
|
+
onHistoryChange: this.historyChange$.on
|
|
123
237
|
};
|
|
124
238
|
}
|
|
239
|
+
// ─────────────────────────────────────────────────────────
|
|
240
|
+
// Lifecycle
|
|
241
|
+
// ─────────────────────────────────────────────────────────
|
|
242
|
+
async destroy() {
|
|
243
|
+
this.historyChange$.clear();
|
|
244
|
+
this.documentHistories.clear();
|
|
245
|
+
super.destroy();
|
|
246
|
+
}
|
|
125
247
|
};
|
|
126
248
|
_HistoryPlugin.id = "history";
|
|
127
249
|
let HistoryPlugin = _HistoryPlugin;
|
|
128
|
-
const
|
|
250
|
+
const initialDocumentState = {
|
|
129
251
|
global: {
|
|
130
252
|
canUndo: false,
|
|
131
253
|
canRedo: false
|
|
132
254
|
},
|
|
133
255
|
topics: {}
|
|
134
256
|
};
|
|
257
|
+
const initialState = {
|
|
258
|
+
documents: {},
|
|
259
|
+
activeDocumentId: null
|
|
260
|
+
};
|
|
135
261
|
const reducer = (state = initialState, action) => {
|
|
136
262
|
switch (action.type) {
|
|
137
|
-
case
|
|
263
|
+
case INIT_HISTORY_STATE: {
|
|
264
|
+
const { documentId } = action.payload;
|
|
265
|
+
return {
|
|
266
|
+
...state,
|
|
267
|
+
documents: {
|
|
268
|
+
...state.documents,
|
|
269
|
+
[documentId]: { ...initialDocumentState }
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
case CLEANUP_HISTORY_STATE: {
|
|
274
|
+
const { documentId } = action.payload;
|
|
275
|
+
const { [documentId]: removed, ...remainingDocs } = state.documents;
|
|
276
|
+
return {
|
|
277
|
+
...state,
|
|
278
|
+
documents: remainingDocs,
|
|
279
|
+
activeDocumentId: state.activeDocumentId === documentId ? null : state.activeDocumentId
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
case SET_HISTORY_DOCUMENT_STATE: {
|
|
283
|
+
const { documentId, state: docState } = action.payload;
|
|
284
|
+
if (!state.documents[documentId]) {
|
|
285
|
+
return state;
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
...state,
|
|
289
|
+
documents: {
|
|
290
|
+
...state.documents,
|
|
291
|
+
[documentId]: docState
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
case SET_ACTIVE_HISTORY_DOCUMENT: {
|
|
138
296
|
return {
|
|
139
297
|
...state,
|
|
140
|
-
|
|
298
|
+
activeDocumentId: action.payload
|
|
141
299
|
};
|
|
300
|
+
}
|
|
142
301
|
default:
|
|
143
302
|
return state;
|
|
144
303
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/history-plugin.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { HistoryPluginConfig } from './types';\n\nexport const HISTORY_PLUGIN_ID = 'history';\n\nexport const manifest: PluginManifest<HistoryPluginConfig> = {\n id: HISTORY_PLUGIN_ID,\n name: 'History Plugin',\n version: '1.0.0',\n provides: ['history'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Action } from '@embedpdf/core';\nimport { HistoryState } from './types';\n\nexport const SET_HISTORY_STATE = 'HISTORY/SET_STATE';\n\nexport interface SetHistoryStateAction extends Action {\n type: typeof SET_HISTORY_STATE;\n payload: HistoryState;\n}\n\nexport type HistoryAction = SetHistoryStateAction;\n\nexport const setHistoryState = (state: HistoryState): SetHistoryStateAction => ({\n type: SET_HISTORY_STATE,\n payload: state,\n});\n","import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\nimport {\n Command,\n HistoryCapability,\n HistoryEntry,\n HistoryPluginConfig,\n HistoryState,\n} from './types';\nimport { HistoryAction, setHistoryState } from './actions';\n\nexport class HistoryPlugin extends BasePlugin<\n HistoryPluginConfig,\n HistoryCapability,\n HistoryState,\n HistoryAction\n> {\n static readonly id = 'history' as const;\n\n private readonly topicHistories = new Map<\n string,\n { commands: Command[]; currentIndex: number }\n >();\n private globalTimeline: HistoryEntry[] = [];\n private globalIndex = -1;\n\n // This emitter will now broadcast the topic string of the affected history.\n private readonly historyChange$ = createEmitter<string | undefined>();\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n }\n\n async initialize(_: HistoryPluginConfig): Promise<void> {}\n\n private getHistoryState(): HistoryState {\n const topics: HistoryState['topics'] = {};\n Array.from(this.topicHistories.entries()).forEach(([topic, history]) => {\n topics[topic] = {\n canUndo: history.currentIndex > -1,\n canRedo: history.currentIndex < history.commands.length - 1,\n };\n });\n return {\n global: {\n canUndo: this.globalIndex > -1,\n canRedo: this.globalIndex < this.globalTimeline.length - 1,\n },\n topics,\n };\n }\n\n // The emit function now accepts the topic to broadcast.\n private emitHistoryChange(topic: string) {\n // update the state\n this.dispatch(setHistoryState(this.getHistoryState()));\n\n // emit the event\n this.historyChange$.emit(topic);\n }\n\n protected buildCapability(): HistoryCapability {\n return {\n getHistoryState: () => this.state,\n onHistoryChange: this.historyChange$.on,\n\n register: (command: Command, topic: string) => {\n // 1. Manage Topic History\n if (!this.topicHistories.has(topic)) {\n this.topicHistories.set(topic, { commands: [], currentIndex: -1 });\n }\n const topicHistory = this.topicHistories.get(topic)!;\n topicHistory.commands.splice(topicHistory.currentIndex + 1);\n topicHistory.commands.push(command);\n topicHistory.currentIndex++;\n\n // 2. Manage Global History\n const historyEntry: HistoryEntry = { command, topic };\n this.globalTimeline.splice(this.globalIndex + 1);\n this.globalTimeline.push(historyEntry);\n this.globalIndex++;\n\n // 3. Execute and notify with the specific topic\n command.execute();\n this.emitHistoryChange(topic);\n },\n\n undo: (topic?: string) => {\n let affectedTopic: string | undefined;\n\n if (topic) {\n // Scoped Undo\n const topicHistory = this.topicHistories.get(topic);\n if (topicHistory && topicHistory.currentIndex > -1) {\n topicHistory.commands[topicHistory.currentIndex].undo();\n topicHistory.currentIndex--;\n affectedTopic = topic;\n }\n } else {\n // Global Undo\n if (this.globalIndex > -1) {\n const entry = this.globalTimeline[this.globalIndex];\n entry.command.undo();\n this.topicHistories.get(entry.topic)!.currentIndex--;\n this.globalIndex--;\n affectedTopic = entry.topic;\n }\n }\n if (affectedTopic) this.emitHistoryChange(affectedTopic);\n },\n\n redo: (topic?: string) => {\n let affectedTopic: string | undefined;\n\n if (topic) {\n // Scoped Redo\n const topicHistory = this.topicHistories.get(topic);\n if (topicHistory && topicHistory.currentIndex < topicHistory.commands.length - 1) {\n topicHistory.currentIndex++;\n topicHistory.commands[topicHistory.currentIndex].execute();\n affectedTopic = topic;\n }\n } else {\n // Global Redo\n if (this.globalIndex < this.globalTimeline.length - 1) {\n this.globalIndex++;\n const entry = this.globalTimeline[this.globalIndex];\n entry.command.execute();\n this.topicHistories.get(entry.topic)!.currentIndex++;\n affectedTopic = entry.topic;\n }\n }\n if (affectedTopic) this.emitHistoryChange(affectedTopic);\n },\n\n canUndo: (topic?: string) => {\n if (topic) {\n const history = this.topicHistories.get(topic);\n return !!history && history.currentIndex > -1;\n }\n return this.globalIndex > -1;\n },\n\n canRedo: (topic?: string) => {\n if (topic) {\n const history = this.topicHistories.get(topic);\n return !!history && history.currentIndex < history.commands.length - 1;\n }\n return this.globalIndex < this.globalTimeline.length - 1;\n },\n };\n }\n}\n","import { Reducer } from '@embedpdf/core';\nimport { HistoryAction, SET_HISTORY_STATE } from './actions';\nimport { HistoryState } from './types';\n\nexport const initialState: HistoryState = {\n global: {\n canUndo: false,\n canRedo: false,\n },\n topics: {},\n};\n\nexport const reducer: Reducer<HistoryState, HistoryAction> = (state = initialState, action) => {\n switch (action.type) {\n case SET_HISTORY_STATE:\n return {\n ...state,\n ...action.payload,\n };\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, HISTORY_PLUGIN_ID } from './manifest';\nimport { HistoryPluginConfig, HistoryState } from './types';\nimport { HistoryPlugin } from './history-plugin';\nimport { initialState, reducer } from './reducer';\nimport { HistoryAction } from './actions';\n\nexport const HistoryPluginPackage: PluginPackage<\n HistoryPlugin,\n HistoryPluginConfig,\n HistoryState,\n HistoryAction\n> = {\n manifest,\n create: (registry) => new HistoryPlugin(HISTORY_PLUGIN_ID, registry),\n reducer,\n initialState,\n};\n\nexport * from './history-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";AAGO,MAAM,oBAAoB;AAE1B,MAAM,WAAgD;AAAA,EAC3D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,SAAS;AAAA,EACpB,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,EAAA;AAEb;ACZO,MAAM,oBAAoB;AASpB,MAAA,kBAAkB,CAAC,WAAgD;AAAA,EAC9E,MAAM;AAAA,EACN,SAAS;AACX;ACLO,MAAM,iBAAN,MAAM,uBAAsB,WAKjC;AAAA,EAaA,YAAY,IAAY,UAA0B;AAChD,UAAM,IAAI,QAAQ;AAXH,SAAA,qCAAqB,IAGpC;AACF,SAAQ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,MAC5B;AAAA,MAEA,SAAS,CAAC,UAAmB;AAC3B,YAAI,OAAO;AACT,gBAAM,UAAU,KAAK,eAAe,IAAI,KAAK;AAC7C,iBAAO,CAAC,CAAC,WAAW,QAAQ,eAAe,QAAQ,SAAS,SAAS;AAAA,QAAA;AAEvE,eAAO,KAAK,cAAc,KAAK,eAAe,SAAS;AAAA,MAAA;AAAA,IAE3D;AAAA,EAAA;AAEJ;AAvIE,eAAgB,KAAK;AANhB,IAAM,gBAAN;ACNA,MAAM,eAA6B;AAAA,EACxC,QAAQ;AAAA,IACN,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AAAA,EACA,QAAQ,CAAA;AACV;AAEO,MAAM,UAAgD,CAAC,QAAQ,cAAc,WAAW;AAC7F,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,GAAG,OAAO;AAAA,MACZ;AAAA,IACF;AACS,aAAA;AAAA,EAAA;AAEb;ACfO,MAAM,uBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,aAAa,IAAI,cAAc,mBAAmB,QAAQ;AAAA,EACnE;AAAA,EACA;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/history-plugin.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { HistoryPluginConfig } from './types';\n\nexport const HISTORY_PLUGIN_ID = 'history';\n\nexport const manifest: PluginManifest<HistoryPluginConfig> = {\n id: HISTORY_PLUGIN_ID,\n name: 'History Plugin',\n version: '1.0.0',\n provides: ['history'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Action } from '@embedpdf/core';\nimport { HistoryDocumentState } from './types';\n\n// Document lifecycle actions\nexport const INIT_HISTORY_STATE = 'HISTORY/INIT_STATE';\nexport const CLEANUP_HISTORY_STATE = 'HISTORY/CLEANUP_STATE';\n\n// History state updates\nexport const SET_HISTORY_DOCUMENT_STATE = 'HISTORY/SET_DOCUMENT_STATE';\nexport const SET_ACTIVE_HISTORY_DOCUMENT = 'HISTORY/SET_ACTIVE_DOCUMENT';\n\n// Document lifecycle action interfaces\nexport interface InitHistoryStateAction extends Action {\n type: typeof INIT_HISTORY_STATE;\n payload: {\n documentId: string;\n };\n}\n\nexport interface CleanupHistoryStateAction extends Action {\n type: typeof CLEANUP_HISTORY_STATE;\n payload: {\n documentId: string;\n };\n}\n\n// State update action interfaces\nexport interface SetHistoryDocumentStateAction extends Action {\n type: typeof SET_HISTORY_DOCUMENT_STATE;\n payload: {\n documentId: string;\n state: HistoryDocumentState;\n };\n}\n\nexport interface SetActiveHistoryDocumentAction extends Action {\n type: typeof SET_ACTIVE_HISTORY_DOCUMENT;\n payload: string | null; // documentId\n}\n\nexport type HistoryAction =\n | InitHistoryStateAction\n | CleanupHistoryStateAction\n | SetHistoryDocumentStateAction\n | SetActiveHistoryDocumentAction;\n\n// Action creators\nexport const initHistoryState = (documentId: string): InitHistoryStateAction => ({\n type: INIT_HISTORY_STATE,\n payload: { documentId },\n});\n\nexport const cleanupHistoryState = (documentId: string): CleanupHistoryStateAction => ({\n type: CLEANUP_HISTORY_STATE,\n payload: { documentId },\n});\n\nexport const setHistoryDocumentState = (\n documentId: string,\n state: HistoryDocumentState,\n): SetHistoryDocumentStateAction => ({\n type: SET_HISTORY_DOCUMENT_STATE,\n payload: { documentId, state },\n});\n\nexport const setActiveHistoryDocument = (\n documentId: string | null,\n): SetActiveHistoryDocumentAction => ({\n type: SET_ACTIVE_HISTORY_DOCUMENT,\n payload: documentId,\n});\n","import { BasePlugin, createEmitter, Listener, PluginRegistry } from '@embedpdf/core';\nimport {\n Command,\n HistoryCapability,\n HistoryChangeEvent,\n HistoryDocumentState,\n HistoryEntry,\n HistoryPluginConfig,\n HistoryScope,\n HistoryState,\n} from './types';\nimport {\n HistoryAction,\n initHistoryState,\n cleanupHistoryState,\n setHistoryDocumentState,\n} from './actions';\n\ninterface DocumentHistoryData {\n topicHistories: Map<string, { commands: Command[]; currentIndex: number }>;\n globalTimeline: HistoryEntry[];\n globalIndex: number;\n}\n\nexport class HistoryPlugin extends BasePlugin<\n HistoryPluginConfig,\n HistoryCapability,\n HistoryState,\n HistoryAction\n> {\n static readonly id = 'history' as const;\n\n // Per-document history data (persisted with state)\n private readonly documentHistories = new Map<string, DocumentHistoryData>();\n\n // Event emitter for history changes\n private readonly historyChange$ = createEmitter<HistoryChangeEvent>();\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n }\n\n async initialize(_: HistoryPluginConfig): Promise<void> {\n this.logger.info('HistoryPlugin', 'Initialize', 'History plugin initialized');\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Lifecycle (from BasePlugin)\n // ─────────────────────────────────────────────────────────\n\n protected override onDocumentLoadingStarted(documentId: string): void {\n // Initialize history state for this document\n this.dispatch(initHistoryState(documentId));\n\n // Create document history data\n this.documentHistories.set(documentId, {\n topicHistories: new Map(),\n globalTimeline: [],\n globalIndex: -1,\n });\n\n this.logger.debug(\n 'HistoryPlugin',\n 'DocumentOpened',\n `Initialized history state for document: ${documentId}`,\n );\n }\n\n protected override onDocumentClosed(documentId: string): void {\n // Cleanup history state\n this.dispatch(cleanupHistoryState(documentId));\n\n // Cleanup document history data\n this.documentHistories.delete(documentId);\n\n this.logger.debug(\n 'HistoryPlugin',\n 'DocumentClosed',\n `Cleaned up history state for document: ${documentId}`,\n );\n }\n\n // ─────────────────────────────────────────────────────────\n // Helper Methods\n // ─────────────────────────────────────────────────────────\n\n private getDocumentHistoryData(documentId?: string): DocumentHistoryData {\n const id = documentId ?? this.getActiveDocumentId();\n const data = this.documentHistories.get(id);\n if (!data) {\n throw new Error(`History data not found for document: ${id}`);\n }\n return data;\n }\n\n private getDocumentHistoryState(documentId: string): HistoryDocumentState {\n const data = this.documentHistories.get(documentId);\n if (!data) {\n throw new Error(`History data not found for document: ${documentId}`);\n }\n\n const topics: HistoryDocumentState['topics'] = {};\n Array.from(data.topicHistories.entries()).forEach(([topic, history]) => {\n topics[topic] = {\n canUndo: history.currentIndex > -1,\n canRedo: history.currentIndex < history.commands.length - 1,\n };\n });\n\n return {\n global: {\n canUndo: data.globalIndex > -1,\n canRedo: data.globalIndex < data.globalTimeline.length - 1,\n },\n topics,\n };\n }\n\n private emitHistoryChange(documentId: string, topic: string | undefined) {\n // Update the state\n const state = this.getDocumentHistoryState(documentId);\n this.dispatch(setHistoryDocumentState(documentId, state));\n\n // Emit the event\n this.historyChange$.emit({\n documentId,\n topic,\n state,\n });\n }\n\n // ─────────────────────────────────────────────────────────\n // History Operations (per document)\n // ─────────────────────────────────────────────────────────\n\n private register(command: Command, topic: string, documentId: string): void {\n const data = this.getDocumentHistoryData(documentId);\n\n // 1. Manage Topic History\n if (!data.topicHistories.has(topic)) {\n data.topicHistories.set(topic, { commands: [], currentIndex: -1 });\n }\n const topicHistory = data.topicHistories.get(topic)!;\n topicHistory.commands.splice(topicHistory.currentIndex + 1);\n topicHistory.commands.push(command);\n topicHistory.currentIndex++;\n\n // 2. Manage Global History\n const historyEntry: HistoryEntry = { command, topic };\n data.globalTimeline.splice(data.globalIndex + 1);\n data.globalTimeline.push(historyEntry);\n data.globalIndex++;\n\n // 3. Execute and notify with the specific topic\n command.execute();\n this.emitHistoryChange(documentId, topic);\n }\n\n private undo(topic: string | undefined, documentId: string): void {\n const data = this.getDocumentHistoryData(documentId);\n let affectedTopic: string | undefined;\n\n if (topic) {\n // Scoped Undo\n const topicHistory = data.topicHistories.get(topic);\n if (topicHistory && topicHistory.currentIndex > -1) {\n topicHistory.commands[topicHistory.currentIndex].undo();\n topicHistory.currentIndex--;\n affectedTopic = topic;\n }\n } else {\n // Global Undo\n if (data.globalIndex > -1) {\n const entry = data.globalTimeline[data.globalIndex];\n entry.command.undo();\n data.topicHistories.get(entry.topic)!.currentIndex--;\n data.globalIndex--;\n affectedTopic = entry.topic;\n }\n }\n\n if (affectedTopic) {\n this.emitHistoryChange(documentId, affectedTopic);\n }\n }\n\n private redo(topic: string | undefined, documentId: string): void {\n const data = this.getDocumentHistoryData(documentId);\n let affectedTopic: string | undefined;\n\n if (topic) {\n // Scoped Redo\n const topicHistory = data.topicHistories.get(topic);\n if (topicHistory && topicHistory.currentIndex < topicHistory.commands.length - 1) {\n topicHistory.currentIndex++;\n topicHistory.commands[topicHistory.currentIndex].execute();\n affectedTopic = topic;\n }\n } else {\n // Global Redo\n if (data.globalIndex < data.globalTimeline.length - 1) {\n data.globalIndex++;\n const entry = data.globalTimeline[data.globalIndex];\n entry.command.execute();\n data.topicHistories.get(entry.topic)!.currentIndex++;\n affectedTopic = entry.topic;\n }\n }\n\n if (affectedTopic) {\n this.emitHistoryChange(documentId, affectedTopic);\n }\n }\n\n private canUndo(topic: string | undefined, documentId: string): boolean {\n const data = this.getDocumentHistoryData(documentId);\n\n if (topic) {\n const history = data.topicHistories.get(topic);\n return !!history && history.currentIndex > -1;\n }\n return data.globalIndex > -1;\n }\n\n private canRedo(topic: string | undefined, documentId: string): boolean {\n const data = this.getDocumentHistoryData(documentId);\n\n if (topic) {\n const history = data.topicHistories.get(topic);\n return !!history && history.currentIndex < history.commands.length - 1;\n }\n return data.globalIndex < data.globalTimeline.length - 1;\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createHistoryScope(documentId: string): HistoryScope {\n return {\n register: (command: Command, topic: string) => this.register(command, topic, documentId),\n undo: (topic?: string) => this.undo(topic, documentId),\n redo: (topic?: string) => this.redo(topic, documentId),\n canUndo: (topic?: string) => this.canUndo(topic, documentId),\n canRedo: (topic?: string) => this.canRedo(topic, documentId),\n getHistoryState: () => this.getDocumentHistoryState(documentId),\n onHistoryChange: (listener: Listener<string | undefined>) =>\n this.historyChange$.on((event) => {\n if (event.documentId === documentId) {\n listener(event.topic);\n }\n }),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): HistoryCapability {\n return {\n // Active document operations\n register: (command: Command, topic: string) => {\n const documentId = this.getActiveDocumentId();\n this.register(command, topic, documentId);\n },\n\n undo: (topic?: string) => {\n const documentId = this.getActiveDocumentId();\n this.undo(topic, documentId);\n },\n\n redo: (topic?: string) => {\n const documentId = this.getActiveDocumentId();\n this.redo(topic, documentId);\n },\n\n canUndo: (topic?: string) => {\n const documentId = this.getActiveDocumentId();\n return this.canUndo(topic, documentId);\n },\n\n canRedo: (topic?: string) => {\n const documentId = this.getActiveDocumentId();\n return this.canRedo(topic, documentId);\n },\n\n getHistoryState: () => {\n const documentId = this.getActiveDocumentId();\n return this.getDocumentHistoryState(documentId);\n },\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createHistoryScope(documentId),\n\n // Events\n onHistoryChange: this.historyChange$.on,\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async destroy(): Promise<void> {\n // Clear all emitters\n this.historyChange$.clear();\n\n // Clear document histories\n this.documentHistories.clear();\n\n super.destroy();\n }\n}\n","import { Reducer } from '@embedpdf/core';\nimport {\n HistoryAction,\n INIT_HISTORY_STATE,\n CLEANUP_HISTORY_STATE,\n SET_HISTORY_DOCUMENT_STATE,\n SET_ACTIVE_HISTORY_DOCUMENT,\n} from './actions';\nimport { HistoryState, HistoryDocumentState } from './types';\n\nconst initialDocumentState: HistoryDocumentState = {\n global: {\n canUndo: false,\n canRedo: false,\n },\n topics: {},\n};\n\nexport const initialState: HistoryState = {\n documents: {},\n activeDocumentId: null,\n};\n\nexport const reducer: Reducer<HistoryState, HistoryAction> = (state = initialState, action) => {\n switch (action.type) {\n case INIT_HISTORY_STATE: {\n const { documentId } = action.payload;\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: { ...initialDocumentState },\n },\n };\n }\n\n case CLEANUP_HISTORY_STATE: {\n const { documentId } = action.payload;\n const { [documentId]: removed, ...remainingDocs } = state.documents;\n\n return {\n ...state,\n documents: remainingDocs,\n activeDocumentId: state.activeDocumentId === documentId ? null : state.activeDocumentId,\n };\n }\n\n case SET_HISTORY_DOCUMENT_STATE: {\n const { documentId, state: docState } = action.payload;\n if (!state.documents[documentId]) {\n return state;\n }\n\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: docState,\n },\n };\n }\n\n case SET_ACTIVE_HISTORY_DOCUMENT: {\n return {\n ...state,\n activeDocumentId: action.payload,\n };\n }\n\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, HISTORY_PLUGIN_ID } from './manifest';\nimport { HistoryPluginConfig, HistoryState } from './types';\nimport { HistoryPlugin } from './history-plugin';\nimport { initialState, reducer } from './reducer';\nimport { HistoryAction } from './actions';\n\nexport const HistoryPluginPackage: PluginPackage<\n HistoryPlugin,\n HistoryPluginConfig,\n HistoryState,\n HistoryAction\n> = {\n manifest,\n create: (registry) => new HistoryPlugin(HISTORY_PLUGIN_ID, registry),\n reducer,\n initialState,\n};\n\nexport * from './history-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";AAGO,MAAM,oBAAoB;AAE1B,MAAM,WAAgD;AAAA,EAC3D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,SAAS;AAAA,EACpB,UAAU,CAAA;AAAA,EACV,UAAU,CAAA;AAAA,EACV,eAAe;AAAA,IACb,SAAS;AAAA,EAAA;AAEb;ACXO,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAG9B,MAAM,6BAA6B;AACnC,MAAM,8BAA8B;AAsCpC,MAAM,mBAAmB,CAAC,gBAAgD;AAAA,EAC/E,MAAM;AAAA,EACN,SAAS,EAAE,WAAA;AACb;AAEO,MAAM,sBAAsB,CAAC,gBAAmD;AAAA,EACrF,MAAM;AAAA,EACN,SAAS,EAAE,WAAA;AACb;AAEO,MAAM,0BAA0B,CACrC,YACA,WACmC;AAAA,EACnC,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L,GAAG;AAAA,QACH,WAAW;AAAA,QACX,kBAAkB,MAAM,qBAAqB,aAAa,OAAO,MAAM;AAAA,MAAA;AAAA,IAE3E;AAAA,IAEA,KAAK,4BAA4B;AAC/B,YAAM,EAAE,YAAY,OAAO,SAAA,IAAa,OAAO;AAC/C,UAAI,CAAC,MAAM,UAAU,UAAU,GAAG;AAChC,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL,GAAG;AAAA,QACH,WAAW;AAAA,UACT,GAAG,MAAM;AAAA,UACT,CAAC,UAAU,GAAG;AAAA,QAAA;AAAA,MAChB;AAAA,IAEJ;AAAA,IAEA,KAAK,6BAA6B;AAChC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,kBAAkB,OAAO;AAAA,MAAA;AAAA,IAE7B;AAAA,IAEA;AACE,aAAO;AAAA,EAAA;AAEb;ACjEO,MAAM,uBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,aAAa,IAAI,cAAc,mBAAmB,QAAQ;AAAA,EACnE;AAAA,EACA;AACF;"}
|
package/dist/lib/actions.d.ts
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
import { Action } from '@embedpdf/core';
|
|
2
|
-
import {
|
|
3
|
-
export declare const
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { HistoryDocumentState } from './types';
|
|
3
|
+
export declare const INIT_HISTORY_STATE = "HISTORY/INIT_STATE";
|
|
4
|
+
export declare const CLEANUP_HISTORY_STATE = "HISTORY/CLEANUP_STATE";
|
|
5
|
+
export declare const SET_HISTORY_DOCUMENT_STATE = "HISTORY/SET_DOCUMENT_STATE";
|
|
6
|
+
export declare const SET_ACTIVE_HISTORY_DOCUMENT = "HISTORY/SET_ACTIVE_DOCUMENT";
|
|
7
|
+
export interface InitHistoryStateAction extends Action {
|
|
8
|
+
type: typeof INIT_HISTORY_STATE;
|
|
9
|
+
payload: {
|
|
10
|
+
documentId: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface CleanupHistoryStateAction extends Action {
|
|
14
|
+
type: typeof CLEANUP_HISTORY_STATE;
|
|
15
|
+
payload: {
|
|
16
|
+
documentId: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface SetHistoryDocumentStateAction extends Action {
|
|
20
|
+
type: typeof SET_HISTORY_DOCUMENT_STATE;
|
|
21
|
+
payload: {
|
|
22
|
+
documentId: string;
|
|
23
|
+
state: HistoryDocumentState;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface SetActiveHistoryDocumentAction extends Action {
|
|
27
|
+
type: typeof SET_ACTIVE_HISTORY_DOCUMENT;
|
|
28
|
+
payload: string | null;
|
|
29
|
+
}
|
|
30
|
+
export type HistoryAction = InitHistoryStateAction | CleanupHistoryStateAction | SetHistoryDocumentStateAction | SetActiveHistoryDocumentAction;
|
|
31
|
+
export declare const initHistoryState: (documentId: string) => InitHistoryStateAction;
|
|
32
|
+
export declare const cleanupHistoryState: (documentId: string) => CleanupHistoryStateAction;
|
|
33
|
+
export declare const setHistoryDocumentState: (documentId: string, state: HistoryDocumentState) => SetHistoryDocumentStateAction;
|
|
34
|
+
export declare const setActiveHistoryDocument: (documentId: string | null) => SetActiveHistoryDocumentAction;
|
|
@@ -3,13 +3,21 @@ import { HistoryCapability, HistoryPluginConfig, HistoryState } from './types';
|
|
|
3
3
|
import { HistoryAction } from './actions';
|
|
4
4
|
export declare class HistoryPlugin extends BasePlugin<HistoryPluginConfig, HistoryCapability, HistoryState, HistoryAction> {
|
|
5
5
|
static readonly id: "history";
|
|
6
|
-
private readonly
|
|
7
|
-
private globalTimeline;
|
|
8
|
-
private globalIndex;
|
|
6
|
+
private readonly documentHistories;
|
|
9
7
|
private readonly historyChange$;
|
|
10
8
|
constructor(id: string, registry: PluginRegistry);
|
|
11
9
|
initialize(_: HistoryPluginConfig): Promise<void>;
|
|
12
|
-
|
|
10
|
+
protected onDocumentLoadingStarted(documentId: string): void;
|
|
11
|
+
protected onDocumentClosed(documentId: string): void;
|
|
12
|
+
private getDocumentHistoryData;
|
|
13
|
+
private getDocumentHistoryState;
|
|
13
14
|
private emitHistoryChange;
|
|
15
|
+
private register;
|
|
16
|
+
private undo;
|
|
17
|
+
private redo;
|
|
18
|
+
private canUndo;
|
|
19
|
+
private canRedo;
|
|
20
|
+
private createHistoryScope;
|
|
14
21
|
protected buildCapability(): HistoryCapability;
|
|
22
|
+
destroy(): Promise<void>;
|
|
15
23
|
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -18,10 +18,9 @@ export interface HistoryEntry {
|
|
|
18
18
|
topic: string;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* Includes a global state and a record of each topic's state.
|
|
21
|
+
* Per-document history state
|
|
23
22
|
*/
|
|
24
|
-
export interface
|
|
23
|
+
export interface HistoryDocumentState {
|
|
25
24
|
global: {
|
|
26
25
|
canUndo: boolean;
|
|
27
26
|
canRedo: boolean;
|
|
@@ -31,7 +30,26 @@ export interface HistoryState {
|
|
|
31
30
|
canRedo: boolean;
|
|
32
31
|
}>;
|
|
33
32
|
}
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Information about the history state, to be emitted for UI updates.
|
|
35
|
+
* Includes per-document history states.
|
|
36
|
+
*/
|
|
37
|
+
export interface HistoryState {
|
|
38
|
+
documents: Record<string, HistoryDocumentState>;
|
|
39
|
+
activeDocumentId: string | null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Event payload for history changes
|
|
43
|
+
*/
|
|
44
|
+
export interface HistoryChangeEvent {
|
|
45
|
+
documentId: string;
|
|
46
|
+
topic: string | undefined;
|
|
47
|
+
state: HistoryDocumentState;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Scoped history capability for a specific document
|
|
51
|
+
*/
|
|
52
|
+
export interface HistoryScope {
|
|
35
53
|
/**
|
|
36
54
|
* Registers a command with the history stack.
|
|
37
55
|
* @param command The command to register, with `execute` and `undo` methods.
|
|
@@ -61,12 +79,54 @@ export interface HistoryCapability {
|
|
|
61
79
|
*/
|
|
62
80
|
canRedo: (topic?: string) => boolean;
|
|
63
81
|
/**
|
|
64
|
-
*
|
|
82
|
+
* Returns the current undo/redo state for all topics and the global timeline.
|
|
83
|
+
*/
|
|
84
|
+
getHistoryState: () => HistoryDocumentState;
|
|
85
|
+
/**
|
|
86
|
+
* An event hook that fires whenever a history action occurs for this document.
|
|
65
87
|
* @param topic The topic string that was affected by the action.
|
|
66
88
|
*/
|
|
67
89
|
onHistoryChange: EventHook<string | undefined>;
|
|
90
|
+
}
|
|
91
|
+
export interface HistoryCapability {
|
|
68
92
|
/**
|
|
69
|
-
*
|
|
93
|
+
* Registers a command with the history stack for the active document.
|
|
94
|
+
* @param command The command to register, with `execute` and `undo` methods.
|
|
95
|
+
* @param topic A string identifier for the history scope (e.g., 'annotations').
|
|
96
|
+
*/
|
|
97
|
+
register: (command: Command, topic: string) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Undoes the last command for the active document.
|
|
100
|
+
* @param topic If provided, undoes the last command for that specific topic.
|
|
101
|
+
* If omitted, performs a global undo of the very last action.
|
|
102
|
+
*/
|
|
103
|
+
undo: (topic?: string) => void;
|
|
104
|
+
/**
|
|
105
|
+
* Redoes the last undone command for the active document.
|
|
106
|
+
* @param topic If provided, redoes the last command for that specific topic.
|
|
107
|
+
* If omitted, performs a global redo.
|
|
108
|
+
*/
|
|
109
|
+
redo: (topic?: string) => void;
|
|
110
|
+
/**
|
|
111
|
+
* Checks if an undo operation is possible for the active document.
|
|
112
|
+
* @param topic If provided, checks for the specific topic. Otherwise, checks globally.
|
|
113
|
+
*/
|
|
114
|
+
canUndo: (topic?: string) => boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a redo operation is possible for the active document.
|
|
117
|
+
* @param topic If provided, checks for the specific topic. Otherwise, checks globally.
|
|
118
|
+
*/
|
|
119
|
+
canRedo: (topic?: string) => boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Returns the current undo/redo state for the active document.
|
|
122
|
+
*/
|
|
123
|
+
getHistoryState: () => HistoryDocumentState;
|
|
124
|
+
/**
|
|
125
|
+
* Get document-scoped history operations
|
|
126
|
+
*/
|
|
127
|
+
forDocument: (documentId: string) => HistoryScope;
|
|
128
|
+
/**
|
|
129
|
+
* An event hook that fires whenever a history action occurs.
|
|
70
130
|
*/
|
|
71
|
-
|
|
131
|
+
onHistoryChange: EventHook<HistoryChangeEvent>;
|
|
72
132
|
}
|
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/preact"),t=require("@embedpdf/plugin-history");exports.useHistoryCapability=()=>e.useCapability(t.HistoryPlugin.id),exports.useHistoryPlugin=()=>e.usePlugin(t.HistoryPlugin.id),Object.keys(t).forEach(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-history");exports.useHistoryCapability=()=>e.useCapability(t.HistoryPlugin.id),exports.useHistoryPlugin=()=>e.usePlugin(t.HistoryPlugin.id),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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-history");exports.useHistoryCapability=()=>e.useCapability(t.HistoryPlugin.id),exports.useHistoryPlugin=()=>e.usePlugin(t.HistoryPlugin.id),Object.keys(t).forEach(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-history");exports.useHistoryCapability=()=>e.useCapability(t.HistoryPlugin.id),exports.useHistoryPlugin=()=>e.usePlugin(t.HistoryPlugin.id),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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-history';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HistoryPlugin } from '../../lib/index.ts';
|
|
2
|
+
export declare const useHistoryPlugin: () => {
|
|
3
|
+
plugin: HistoryPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useHistoryCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../lib/index.ts').HistoryCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/svelte"),t=require("@embedpdf/plugin-history");exports.useHistoryCapability=()=>e.useCapability(t.HistoryPlugin.id),exports.useHistoryPlugin=()=>e.usePlugin(t.HistoryPlugin.id),Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-history.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { HistoryPlugin } from '@embedpdf/plugin-history';\n\nexport const useHistoryPlugin = () => usePlugin<HistoryPlugin>(HistoryPlugin.id);\nexport const useHistoryCapability = () => useCapability<HistoryPlugin>(HistoryPlugin.id);\n"],"names":["useCapability","HistoryPlugin","id","usePlugin"],"mappings":"4LAIoC,IAAMA,gBAA6BC,EAAAA,cAAcC,6BADrD,IAAMC,YAAyBF,EAAAA,cAAcC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { usePlugin, useCapability } from "@embedpdf/core/svelte";
|
|
2
|
+
import { HistoryPlugin } from "@embedpdf/plugin-history";
|
|
3
|
+
export * from "@embedpdf/plugin-history";
|
|
4
|
+
const useHistoryPlugin = () => usePlugin(HistoryPlugin.id);
|
|
5
|
+
const useHistoryCapability = () => useCapability(HistoryPlugin.id);
|
|
6
|
+
export {
|
|
7
|
+
useHistoryCapability,
|
|
8
|
+
useHistoryPlugin
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-history.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { HistoryPlugin } from '@embedpdf/plugin-history';\n\nexport const useHistoryPlugin = () => usePlugin<HistoryPlugin>(HistoryPlugin.id);\nexport const useHistoryCapability = () => useCapability<HistoryPlugin>(HistoryPlugin.id);\n"],"names":[],"mappings":";;;AAGO,MAAM,mBAAmB,MAAM,UAAyB,cAAc,EAAE;AACxE,MAAM,uBAAuB,MAAM,cAA6B,cAAc,EAAE;"}
|
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/vue"),t=require("@embedpdf/plugin-history");exports.useHistoryCapability=()=>e.useCapability(t.HistoryPlugin.id),exports.useHistoryPlugin=()=>e.usePlugin(t.HistoryPlugin.id),Object.keys(t).forEach(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/vue"),t=require("@embedpdf/plugin-history");exports.useHistoryCapability=()=>e.useCapability(t.HistoryPlugin.id),exports.useHistoryPlugin=()=>e.usePlugin(t.HistoryPlugin.id),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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-history",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -26,23 +26,30 @@
|
|
|
26
26
|
"types": "./dist/vue/index.d.ts",
|
|
27
27
|
"import": "./dist/vue/index.js",
|
|
28
28
|
"require": "./dist/vue/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./svelte": {
|
|
31
|
+
"types": "./dist/svelte/index.d.ts",
|
|
32
|
+
"svelte": "./dist/svelte/index.js",
|
|
33
|
+
"import": "./dist/svelte/index.js",
|
|
34
|
+
"require": "./dist/svelte/index.cjs"
|
|
29
35
|
}
|
|
30
36
|
},
|
|
31
37
|
"dependencies": {
|
|
32
|
-
"@embedpdf/models": "
|
|
38
|
+
"@embedpdf/models": "2.0.0-next.0"
|
|
33
39
|
},
|
|
34
40
|
"devDependencies": {
|
|
35
41
|
"@types/react": "^18.2.0",
|
|
36
42
|
"typescript": "^5.0.0",
|
|
37
|
-
"@embedpdf/
|
|
38
|
-
"@embedpdf/
|
|
43
|
+
"@embedpdf/build": "1.1.0",
|
|
44
|
+
"@embedpdf/core": "2.0.0-next.0"
|
|
39
45
|
},
|
|
40
46
|
"peerDependencies": {
|
|
41
47
|
"react": ">=16.8.0",
|
|
42
48
|
"react-dom": ">=16.8.0",
|
|
43
49
|
"preact": "^10.26.4",
|
|
44
50
|
"vue": ">=3.2.0",
|
|
45
|
-
"
|
|
51
|
+
"svelte": ">=5 <6",
|
|
52
|
+
"@embedpdf/core": "2.0.0-next.0"
|
|
46
53
|
},
|
|
47
54
|
"files": [
|
|
48
55
|
"dist",
|
|
@@ -65,7 +72,8 @@
|
|
|
65
72
|
"build:react": "vite build --mode react",
|
|
66
73
|
"build:preact": "vite build --mode preact",
|
|
67
74
|
"build:vue": "vite build --mode vue",
|
|
68
|
-
"build": "
|
|
75
|
+
"build:svelte": "vite build --mode svelte",
|
|
76
|
+
"build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue,svelte \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\" \"vite build --mode svelte\"",
|
|
69
77
|
"clean": "rimraf dist",
|
|
70
78
|
"lint": "eslint src --color",
|
|
71
79
|
"lint:fix": "eslint src --color --fix"
|