@embedpdf/plugin-history 1.0.18 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@embedpdf/core"),e="history",i={id:e,name:"History Plugin",version:"1.0.0",provides:["history"],requires:[],optional:[],defaultConfig:{enabled:!0}},s="HISTORY/SET_STATE",n=class extends t.BasePlugin{constructor(e,i){super(e,i),this.topicHistories=new Map,this.globalTimeline=[],this.globalIndex=-1,this.historyChange$=t.createEmitter()}async initialize(t){}getHistoryState(){const t={};return Array.from(this.topicHistories.entries()).forEach((([e,i])=>{t[e]={canUndo:i.currentIndex>-1,canRedo:i.currentIndex<i.commands.length-1}})),{global:{canUndo:this.globalIndex>-1,canRedo:this.globalIndex<this.globalTimeline.length-1},topics:t}}emitHistoryChange(t){var e;this.dispatch((e=this.getHistoryState(),{type:s,payload:e})),this.historyChange$.emit(t)}buildCapability(){return{getHistoryState:()=>this.state,onHistoryChange:this.historyChange$.on,register:(t,e)=>{this.topicHistories.has(e)||this.topicHistories.set(e,{commands:[],currentIndex:-1});const i=this.topicHistories.get(e);i.commands.splice(i.currentIndex+1),i.commands.push(t),i.currentIndex++;const s={command:t,topic:e};this.globalTimeline.splice(this.globalIndex+1),this.globalTimeline.push(s),this.globalIndex++,t.execute(),this.emitHistoryChange(e)},undo:t=>{let e;if(t){const i=this.topicHistories.get(t);i&&i.currentIndex>-1&&(i.commands[i.currentIndex].undo(),i.currentIndex--,e=t)}else if(this.globalIndex>-1){const t=this.globalTimeline[this.globalIndex];t.command.undo(),this.topicHistories.get(t.topic).currentIndex--,this.globalIndex--,e=t.topic}e&&this.emitHistoryChange(e)},redo:t=>{let e;if(t){const i=this.topicHistories.get(t);i&&i.currentIndex<i.commands.length-1&&(i.currentIndex++,i.commands[i.currentIndex].execute(),e=t)}else if(this.globalIndex<this.globalTimeline.length-1){this.globalIndex++;const t=this.globalTimeline[this.globalIndex];t.command.execute(),this.topicHistories.get(t.topic).currentIndex++,e=t.topic}e&&this.emitHistoryChange(e)},canUndo:t=>{if(t){const e=this.topicHistories.get(t);return!!e&&e.currentIndex>-1}return this.globalIndex>-1},canRedo:t=>{if(t){const e=this.topicHistories.get(t);return!!e&&e.currentIndex<e.commands.length-1}return this.globalIndex<this.globalTimeline.length-1}}}};n.id="history";let o=n;const r={global:{canUndo:!1,canRedo:!1},topics:{}},a={manifest:i,create:(t,i)=>new o(e,t),reducer:(t=r,e)=>e.type===s?{...t,...e.payload}:t,initialState:r};exports.HISTORY_PLUGIN_ID=e,exports.HistoryPlugin=o,exports.HistoryPluginPackage=a,exports.manifest=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@embedpdf/core"),e="history",i={id:e,name:"History Plugin",version:"1.0.0",provides:["history"],requires:[],optional:[],defaultConfig:{enabled:!0}},s="HISTORY/SET_STATE",n=class extends t.BasePlugin{constructor(e,i){super(e,i),this.topicHistories=new Map,this.globalTimeline=[],this.globalIndex=-1,this.historyChange$=t.createEmitter()}async initialize(t){}getHistoryState(){const t={};return Array.from(this.topicHistories.entries()).forEach((([e,i])=>{t[e]={canUndo:i.currentIndex>-1,canRedo:i.currentIndex<i.commands.length-1}})),{global:{canUndo:this.globalIndex>-1,canRedo:this.globalIndex<this.globalTimeline.length-1},topics:t}}emitHistoryChange(t){var e;this.dispatch((e=this.getHistoryState(),{type:s,payload:e})),this.historyChange$.emit(t)}buildCapability(){return{getHistoryState:()=>this.state,onHistoryChange:this.historyChange$.on,register:(t,e)=>{this.topicHistories.has(e)||this.topicHistories.set(e,{commands:[],currentIndex:-1});const i=this.topicHistories.get(e);i.commands.splice(i.currentIndex+1),i.commands.push(t),i.currentIndex++;const s={command:t,topic:e};this.globalTimeline.splice(this.globalIndex+1),this.globalTimeline.push(s),this.globalIndex++,t.execute(),this.emitHistoryChange(e)},undo:t=>{let e;if(t){const i=this.topicHistories.get(t);i&&i.currentIndex>-1&&(i.commands[i.currentIndex].undo(),i.currentIndex--,e=t)}else if(this.globalIndex>-1){const t=this.globalTimeline[this.globalIndex];t.command.undo(),this.topicHistories.get(t.topic).currentIndex--,this.globalIndex--,e=t.topic}e&&this.emitHistoryChange(e)},redo:t=>{let e;if(t){const i=this.topicHistories.get(t);i&&i.currentIndex<i.commands.length-1&&(i.currentIndex++,i.commands[i.currentIndex].execute(),e=t)}else if(this.globalIndex<this.globalTimeline.length-1){this.globalIndex++;const t=this.globalTimeline[this.globalIndex];t.command.execute(),this.topicHistories.get(t.topic).currentIndex++,e=t.topic}e&&this.emitHistoryChange(e)},canUndo:t=>{if(t){const e=this.topicHistories.get(t);return!!e&&e.currentIndex>-1}return this.globalIndex>-1},canRedo:t=>{if(t){const e=this.topicHistories.get(t);return!!e&&e.currentIndex<e.commands.length-1}return this.globalIndex<this.globalTimeline.length-1}}}};n.id="history";let o=n;const r={global:{canUndo:!1,canRedo:!1},topics:{}},a={manifest:i,create:t=>new o(e,t),reducer:(t=r,e)=>e.type===s?{...t,...e.payload}:t,initialState:r};exports.HISTORY_PLUGIN_ID=e,exports.HistoryPlugin=o,exports.HistoryPluginPackage=a,exports.manifest=i;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -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, _engine) => 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","_engine","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,C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T,GAAK,UANhB,IAAM4D,EAANnD,ECNA,MAAMoD,EAA6B,CACxCzB,OAAQ,CACNL,SAAS,EACTE,SAAS,GAEXT,OAAQ,CAAA,GCFGsC,EAKT,CACF/D,WACAgE,OAAQ,CAACnD,EAAUoD,IAAY,IAAIJ,EAAc9D,EAAmBc,GACpEqD,QDH2D,CAAC3B,EAAQuB,EAAcK,IAC1EA,EAAO1B,OACRhC,EACI,IACF8B,KACA4B,EAAOzB,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 { 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,KA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EAAAlB,eACbkB,EAAahB,SAASgB,EAAalB,cAAcuB,UACjCE,EAAA5B,EAClB,MAGA,GAAIf,KAAKI,YAAcJ,KAAKG,eAAekB,OAAS,EAAG,CAChDrB,KAAAI,cACL,MAAMwC,EAAQ5C,KAAKG,eAAeH,KAAKI,aACvCwC,EAAMX,QAAQQ,UACdzC,KAAKC,eAAeoC,IAAIO,EAAM7B,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"}
package/dist/index.js CHANGED
@@ -145,7 +145,7 @@ const reducer = (state = initialState, action) => {
145
145
  };
146
146
  const HistoryPluginPackage = {
147
147
  manifest,
148
- create: (registry, _engine) => new HistoryPlugin(HISTORY_PLUGIN_ID, registry),
148
+ create: (registry) => new HistoryPlugin(HISTORY_PLUGIN_ID, registry),
149
149
  reducer,
150
150
  initialState
151
151
  };
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, _engine) => 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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AAK,eAAe,IAAI,MAAM,KAAK,EAAG;AACtC,4BAAgB,MAAM;AAAA,UAAA;AAAA,QACxB;AAEE,YAAA,cAAoB,MAAA,kBAAkB,aAAa;AAAA,MACzD;AAAA,MAEA,SAAS,CAAC,UAAmB;AAC3B,YAAI,OAAO;AACT,gBAAM,UAAU,KAAK,eAAe,IAAI,KAAK;AAC7C,iBAAO,CAAC,CAAC,WAAW,QAAQ,eAAe;AAAA,QAAA;AAE7C,eAAO,KAAK,cAAc;AAAA,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,UAAU,YAAY,IAAI,cAAc,mBAAmB,QAAQ;AAAA,EAC5E;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 { 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,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,IAAI,KAAK;AAC7C,iBAAO,CAAC,CAAC,WAAW,QAAQ,eAAe;AAAA,QAAA;AAE7C,eAAO,KAAK,cAAc;AAAA,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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-history",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -23,19 +23,19 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@embedpdf/models": "1.0.18"
26
+ "@embedpdf/models": "1.0.20"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/react": "^18.2.0",
30
30
  "typescript": "^5.0.0",
31
- "@embedpdf/core": "1.0.18",
31
+ "@embedpdf/core": "1.0.20",
32
32
  "@embedpdf/build": "1.0.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": ">=16.8.0",
36
36
  "react-dom": ">=16.8.0",
37
37
  "preact": "^10.26.4",
38
- "@embedpdf/core": "1.0.18"
38
+ "@embedpdf/core": "1.0.20"
39
39
  },
40
40
  "files": [
41
41
  "dist",