@embedpdf/plugin-history 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +199 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +100 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +169 -0
- package/dist/index.js.map +1 -0
- package/dist/preact/index.cjs +38 -0
- package/dist/preact/index.cjs.map +1 -0
- package/dist/preact/index.d.cts +15 -0
- package/dist/preact/index.d.ts +15 -0
- package/dist/preact/index.js +10 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/react/index.cjs +38 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +15 -0
- package/dist/react/index.d.ts +15 -0
- package/dist/react/index.js +10 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 CloudPDF
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
HISTORY_PLUGIN_ID: () => HISTORY_PLUGIN_ID,
|
|
24
|
+
HistoryPlugin: () => HistoryPlugin,
|
|
25
|
+
HistoryPluginPackage: () => HistoryPluginPackage,
|
|
26
|
+
manifest: () => manifest
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/lib/manifest.ts
|
|
31
|
+
var HISTORY_PLUGIN_ID = "history";
|
|
32
|
+
var manifest = {
|
|
33
|
+
id: HISTORY_PLUGIN_ID,
|
|
34
|
+
name: "History Plugin",
|
|
35
|
+
version: "1.0.0",
|
|
36
|
+
provides: ["history"],
|
|
37
|
+
requires: [],
|
|
38
|
+
optional: [],
|
|
39
|
+
defaultConfig: {
|
|
40
|
+
enabled: true
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// src/lib/history-plugin.ts
|
|
45
|
+
var import_core = require("@embedpdf/core");
|
|
46
|
+
|
|
47
|
+
// src/lib/actions.ts
|
|
48
|
+
var SET_HISTORY_STATE = "HISTORY/SET_STATE";
|
|
49
|
+
var setHistoryState = (state) => ({
|
|
50
|
+
type: SET_HISTORY_STATE,
|
|
51
|
+
payload: state
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// src/lib/history-plugin.ts
|
|
55
|
+
var HistoryPlugin = class extends import_core.BasePlugin {
|
|
56
|
+
constructor(id, registry) {
|
|
57
|
+
super(id, registry);
|
|
58
|
+
this.topicHistories = /* @__PURE__ */ new Map();
|
|
59
|
+
this.globalTimeline = [];
|
|
60
|
+
this.globalIndex = -1;
|
|
61
|
+
// This emitter will now broadcast the topic string of the affected history.
|
|
62
|
+
this.historyChange$ = (0, import_core.createEmitter)();
|
|
63
|
+
}
|
|
64
|
+
async initialize(_) {
|
|
65
|
+
}
|
|
66
|
+
getHistoryState() {
|
|
67
|
+
const topics = {};
|
|
68
|
+
Array.from(this.topicHistories.entries()).forEach(([topic, history]) => {
|
|
69
|
+
topics[topic] = {
|
|
70
|
+
canUndo: history.currentIndex > -1,
|
|
71
|
+
canRedo: history.currentIndex < history.commands.length - 1
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
global: {
|
|
76
|
+
canUndo: this.globalIndex > -1,
|
|
77
|
+
canRedo: this.globalIndex < this.globalTimeline.length - 1
|
|
78
|
+
},
|
|
79
|
+
topics
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// The emit function now accepts the topic to broadcast.
|
|
83
|
+
emitHistoryChange(topic) {
|
|
84
|
+
this.dispatch(setHistoryState(this.getHistoryState()));
|
|
85
|
+
this.historyChange$.emit(topic);
|
|
86
|
+
}
|
|
87
|
+
buildCapability() {
|
|
88
|
+
return {
|
|
89
|
+
getHistoryState: () => this.state,
|
|
90
|
+
onHistoryChange: this.historyChange$.on,
|
|
91
|
+
register: (command, topic) => {
|
|
92
|
+
if (!this.topicHistories.has(topic)) {
|
|
93
|
+
this.topicHistories.set(topic, { commands: [], currentIndex: -1 });
|
|
94
|
+
}
|
|
95
|
+
const topicHistory = this.topicHistories.get(topic);
|
|
96
|
+
topicHistory.commands.splice(topicHistory.currentIndex + 1);
|
|
97
|
+
topicHistory.commands.push(command);
|
|
98
|
+
topicHistory.currentIndex++;
|
|
99
|
+
const historyEntry = { command, topic };
|
|
100
|
+
this.globalTimeline.splice(this.globalIndex + 1);
|
|
101
|
+
this.globalTimeline.push(historyEntry);
|
|
102
|
+
this.globalIndex++;
|
|
103
|
+
command.execute();
|
|
104
|
+
this.emitHistoryChange(topic);
|
|
105
|
+
},
|
|
106
|
+
undo: (topic) => {
|
|
107
|
+
let affectedTopic;
|
|
108
|
+
if (topic) {
|
|
109
|
+
const topicHistory = this.topicHistories.get(topic);
|
|
110
|
+
if (topicHistory && topicHistory.currentIndex > -1) {
|
|
111
|
+
topicHistory.commands[topicHistory.currentIndex].undo();
|
|
112
|
+
topicHistory.currentIndex--;
|
|
113
|
+
affectedTopic = topic;
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
if (this.globalIndex > -1) {
|
|
117
|
+
const entry = this.globalTimeline[this.globalIndex];
|
|
118
|
+
entry.command.undo();
|
|
119
|
+
this.topicHistories.get(entry.topic).currentIndex--;
|
|
120
|
+
this.globalIndex--;
|
|
121
|
+
affectedTopic = entry.topic;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (affectedTopic) this.emitHistoryChange(affectedTopic);
|
|
125
|
+
},
|
|
126
|
+
redo: (topic) => {
|
|
127
|
+
let affectedTopic;
|
|
128
|
+
if (topic) {
|
|
129
|
+
const topicHistory = this.topicHistories.get(topic);
|
|
130
|
+
if (topicHistory && topicHistory.currentIndex < topicHistory.commands.length - 1) {
|
|
131
|
+
topicHistory.currentIndex++;
|
|
132
|
+
topicHistory.commands[topicHistory.currentIndex].execute();
|
|
133
|
+
affectedTopic = topic;
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
if (this.globalIndex < this.globalTimeline.length - 1) {
|
|
137
|
+
this.globalIndex++;
|
|
138
|
+
const entry = this.globalTimeline[this.globalIndex];
|
|
139
|
+
entry.command.execute();
|
|
140
|
+
this.topicHistories.get(entry.topic).currentIndex++;
|
|
141
|
+
affectedTopic = entry.topic;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (affectedTopic) this.emitHistoryChange(affectedTopic);
|
|
145
|
+
},
|
|
146
|
+
canUndo: (topic) => {
|
|
147
|
+
if (topic) {
|
|
148
|
+
const history = this.topicHistories.get(topic);
|
|
149
|
+
return !!history && history.currentIndex > -1;
|
|
150
|
+
}
|
|
151
|
+
return this.globalIndex > -1;
|
|
152
|
+
},
|
|
153
|
+
canRedo: (topic) => {
|
|
154
|
+
if (topic) {
|
|
155
|
+
const history = this.topicHistories.get(topic);
|
|
156
|
+
return !!history && history.currentIndex < history.commands.length - 1;
|
|
157
|
+
}
|
|
158
|
+
return this.globalIndex < this.globalTimeline.length - 1;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
HistoryPlugin.id = "history";
|
|
164
|
+
|
|
165
|
+
// src/lib/reducer.ts
|
|
166
|
+
var initialState = {
|
|
167
|
+
global: {
|
|
168
|
+
canUndo: false,
|
|
169
|
+
canRedo: false
|
|
170
|
+
},
|
|
171
|
+
topics: {}
|
|
172
|
+
};
|
|
173
|
+
var reducer = (state = initialState, action) => {
|
|
174
|
+
switch (action.type) {
|
|
175
|
+
case SET_HISTORY_STATE:
|
|
176
|
+
return {
|
|
177
|
+
...state,
|
|
178
|
+
...action.payload
|
|
179
|
+
};
|
|
180
|
+
default:
|
|
181
|
+
return state;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/lib/index.ts
|
|
186
|
+
var HistoryPluginPackage = {
|
|
187
|
+
manifest,
|
|
188
|
+
create: (registry, _engine) => new HistoryPlugin(HISTORY_PLUGIN_ID, registry),
|
|
189
|
+
reducer,
|
|
190
|
+
initialState
|
|
191
|
+
};
|
|
192
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
+
0 && (module.exports = {
|
|
194
|
+
HISTORY_PLUGIN_ID,
|
|
195
|
+
HistoryPlugin,
|
|
196
|
+
HistoryPluginPackage,
|
|
197
|
+
manifest
|
|
198
|
+
});
|
|
199
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/manifest.ts","../src/lib/history-plugin.ts","../src/lib/actions.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["export * from './lib';\n","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 { 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 { 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 { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,oBAAoB;AAE1B,IAAM,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,EACX;AACF;;;ACfA,kBAA0D;;;ACGnD,IAAM,oBAAoB;AAS1B,IAAM,kBAAkB,CAAC,WAAgD;AAAA,EAC9E,MAAM;AAAA,EACN,SAAS;AACX;;;ADLO,IAAM,gBAAN,cAA4B,uBAKjC;AAAA,EAaA,YAAY,IAAY,UAA0B;AAChD,UAAM,IAAI,QAAQ;AAXpB,SAAiB,iBAAiB,oBAAI,IAGpC;AACF,SAAQ,iBAAiC,CAAC;AAC1C,SAAQ,cAAc;AAGtB;AAAA,SAAiB,qBAAiB,2BAAkC;AAAA,EAIpE;AAAA,EAEA,MAAM,WAAW,GAAuC;AAAA,EAAC;AAAA,EAEjD,kBAAgC;AACtC,UAAM,SAAiC,CAAC;AACxC,UAAM,KAA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AAK,cAAc,KAAK,eAAe,SAAS;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;AA7Ia,cAMK,KAAK;;;AEZhB,IAAM,eAA6B;AAAA,EACxC,QAAQ;AAAA,IACN,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AAAA,EACA,QAAQ,CAAC;AACX;AAEO,IAAM,UAAgD,CAAC,QAAQ,cAAc,WAAW;AAC7F,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACH,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG,OAAO;AAAA,MACZ;AAAA,IACF;AACE,aAAO;AAAA,EACX;AACF;;;ACfO,IAAM,uBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,YAAY,IAAI,cAAc,mBAAmB,QAAQ;AAAA,EAC5E;AAAA,EACA;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook, Action, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
|
|
2
|
+
|
|
3
|
+
interface HistoryPluginConfig extends BasePluginConfig {
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The core Command interface that other plugins will implement.
|
|
7
|
+
*/
|
|
8
|
+
interface Command {
|
|
9
|
+
/** A function that applies the change. */
|
|
10
|
+
execute(): void;
|
|
11
|
+
/** A function that reverts the change. */
|
|
12
|
+
undo(): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An entry in the global timeline, associating a command with its topic.
|
|
16
|
+
*/
|
|
17
|
+
interface HistoryEntry {
|
|
18
|
+
command: Command;
|
|
19
|
+
topic: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Information about the history state, to be emitted for UI updates.
|
|
23
|
+
* Includes a global state and a record of each topic's state.
|
|
24
|
+
*/
|
|
25
|
+
interface HistoryState {
|
|
26
|
+
global: {
|
|
27
|
+
canUndo: boolean;
|
|
28
|
+
canRedo: boolean;
|
|
29
|
+
};
|
|
30
|
+
topics: Record<string, {
|
|
31
|
+
canUndo: boolean;
|
|
32
|
+
canRedo: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
interface HistoryCapability {
|
|
36
|
+
/**
|
|
37
|
+
* Registers a command with the history stack.
|
|
38
|
+
* @param command The command to register, with `execute` and `undo` methods.
|
|
39
|
+
* @param topic A string identifier for the history scope (e.g., 'annotations').
|
|
40
|
+
*/
|
|
41
|
+
register: (command: Command, topic: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Undoes the last command.
|
|
44
|
+
* @param topic If provided, undoes the last command for that specific topic.
|
|
45
|
+
* If omitted, performs a global undo of the very last action.
|
|
46
|
+
*/
|
|
47
|
+
undo: (topic?: string) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Redoes the last undone command.
|
|
50
|
+
* @param topic If provided, redoes the last command for that specific topic.
|
|
51
|
+
* If omitted, performs a global redo.
|
|
52
|
+
*/
|
|
53
|
+
redo: (topic?: string) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if an undo operation is possible.
|
|
56
|
+
* @param topic If provided, checks for the specific topic. Otherwise, checks globally.
|
|
57
|
+
*/
|
|
58
|
+
canUndo: (topic?: string) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a redo operation is possible.
|
|
61
|
+
* @param topic If provided, checks for the specific topic. Otherwise, checks globally.
|
|
62
|
+
*/
|
|
63
|
+
canRedo: (topic?: string) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* An event hook that fires whenever a history action occurs.
|
|
66
|
+
* @param topic The topic string that was affected by the action.
|
|
67
|
+
*/
|
|
68
|
+
onHistoryChange: EventHook<string | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the current undo/redo state for all topics and the global timeline.
|
|
71
|
+
*/
|
|
72
|
+
getHistoryState: () => HistoryState;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare const SET_HISTORY_STATE = "HISTORY/SET_STATE";
|
|
76
|
+
interface SetHistoryStateAction extends Action {
|
|
77
|
+
type: typeof SET_HISTORY_STATE;
|
|
78
|
+
payload: HistoryState;
|
|
79
|
+
}
|
|
80
|
+
type HistoryAction = SetHistoryStateAction;
|
|
81
|
+
|
|
82
|
+
declare class HistoryPlugin extends BasePlugin<HistoryPluginConfig, HistoryCapability, HistoryState, HistoryAction> {
|
|
83
|
+
static readonly id: "history";
|
|
84
|
+
private readonly topicHistories;
|
|
85
|
+
private globalTimeline;
|
|
86
|
+
private globalIndex;
|
|
87
|
+
private readonly historyChange$;
|
|
88
|
+
constructor(id: string, registry: PluginRegistry);
|
|
89
|
+
initialize(_: HistoryPluginConfig): Promise<void>;
|
|
90
|
+
private getHistoryState;
|
|
91
|
+
private emitHistoryChange;
|
|
92
|
+
protected buildCapability(): HistoryCapability;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare const HISTORY_PLUGIN_ID = "history";
|
|
96
|
+
declare const manifest: PluginManifest<HistoryPluginConfig>;
|
|
97
|
+
|
|
98
|
+
declare const HistoryPluginPackage: PluginPackage<HistoryPlugin, HistoryPluginConfig, HistoryState, HistoryAction>;
|
|
99
|
+
|
|
100
|
+
export { type Command, HISTORY_PLUGIN_ID, type HistoryCapability, type HistoryEntry, HistoryPlugin, type HistoryPluginConfig, HistoryPluginPackage, type HistoryState, manifest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook, Action, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
|
|
2
|
+
|
|
3
|
+
interface HistoryPluginConfig extends BasePluginConfig {
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The core Command interface that other plugins will implement.
|
|
7
|
+
*/
|
|
8
|
+
interface Command {
|
|
9
|
+
/** A function that applies the change. */
|
|
10
|
+
execute(): void;
|
|
11
|
+
/** A function that reverts the change. */
|
|
12
|
+
undo(): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An entry in the global timeline, associating a command with its topic.
|
|
16
|
+
*/
|
|
17
|
+
interface HistoryEntry {
|
|
18
|
+
command: Command;
|
|
19
|
+
topic: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Information about the history state, to be emitted for UI updates.
|
|
23
|
+
* Includes a global state and a record of each topic's state.
|
|
24
|
+
*/
|
|
25
|
+
interface HistoryState {
|
|
26
|
+
global: {
|
|
27
|
+
canUndo: boolean;
|
|
28
|
+
canRedo: boolean;
|
|
29
|
+
};
|
|
30
|
+
topics: Record<string, {
|
|
31
|
+
canUndo: boolean;
|
|
32
|
+
canRedo: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
interface HistoryCapability {
|
|
36
|
+
/**
|
|
37
|
+
* Registers a command with the history stack.
|
|
38
|
+
* @param command The command to register, with `execute` and `undo` methods.
|
|
39
|
+
* @param topic A string identifier for the history scope (e.g., 'annotations').
|
|
40
|
+
*/
|
|
41
|
+
register: (command: Command, topic: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Undoes the last command.
|
|
44
|
+
* @param topic If provided, undoes the last command for that specific topic.
|
|
45
|
+
* If omitted, performs a global undo of the very last action.
|
|
46
|
+
*/
|
|
47
|
+
undo: (topic?: string) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Redoes the last undone command.
|
|
50
|
+
* @param topic If provided, redoes the last command for that specific topic.
|
|
51
|
+
* If omitted, performs a global redo.
|
|
52
|
+
*/
|
|
53
|
+
redo: (topic?: string) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if an undo operation is possible.
|
|
56
|
+
* @param topic If provided, checks for the specific topic. Otherwise, checks globally.
|
|
57
|
+
*/
|
|
58
|
+
canUndo: (topic?: string) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a redo operation is possible.
|
|
61
|
+
* @param topic If provided, checks for the specific topic. Otherwise, checks globally.
|
|
62
|
+
*/
|
|
63
|
+
canRedo: (topic?: string) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* An event hook that fires whenever a history action occurs.
|
|
66
|
+
* @param topic The topic string that was affected by the action.
|
|
67
|
+
*/
|
|
68
|
+
onHistoryChange: EventHook<string | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the current undo/redo state for all topics and the global timeline.
|
|
71
|
+
*/
|
|
72
|
+
getHistoryState: () => HistoryState;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare const SET_HISTORY_STATE = "HISTORY/SET_STATE";
|
|
76
|
+
interface SetHistoryStateAction extends Action {
|
|
77
|
+
type: typeof SET_HISTORY_STATE;
|
|
78
|
+
payload: HistoryState;
|
|
79
|
+
}
|
|
80
|
+
type HistoryAction = SetHistoryStateAction;
|
|
81
|
+
|
|
82
|
+
declare class HistoryPlugin extends BasePlugin<HistoryPluginConfig, HistoryCapability, HistoryState, HistoryAction> {
|
|
83
|
+
static readonly id: "history";
|
|
84
|
+
private readonly topicHistories;
|
|
85
|
+
private globalTimeline;
|
|
86
|
+
private globalIndex;
|
|
87
|
+
private readonly historyChange$;
|
|
88
|
+
constructor(id: string, registry: PluginRegistry);
|
|
89
|
+
initialize(_: HistoryPluginConfig): Promise<void>;
|
|
90
|
+
private getHistoryState;
|
|
91
|
+
private emitHistoryChange;
|
|
92
|
+
protected buildCapability(): HistoryCapability;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare const HISTORY_PLUGIN_ID = "history";
|
|
96
|
+
declare const manifest: PluginManifest<HistoryPluginConfig>;
|
|
97
|
+
|
|
98
|
+
declare const HistoryPluginPackage: PluginPackage<HistoryPlugin, HistoryPluginConfig, HistoryState, HistoryAction>;
|
|
99
|
+
|
|
100
|
+
export { type Command, HISTORY_PLUGIN_ID, type HistoryCapability, type HistoryEntry, HistoryPlugin, type HistoryPluginConfig, HistoryPluginPackage, type HistoryState, manifest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// src/lib/manifest.ts
|
|
2
|
+
var HISTORY_PLUGIN_ID = "history";
|
|
3
|
+
var manifest = {
|
|
4
|
+
id: HISTORY_PLUGIN_ID,
|
|
5
|
+
name: "History Plugin",
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
provides: ["history"],
|
|
8
|
+
requires: [],
|
|
9
|
+
optional: [],
|
|
10
|
+
defaultConfig: {
|
|
11
|
+
enabled: true
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/lib/history-plugin.ts
|
|
16
|
+
import { BasePlugin, createEmitter } from "@embedpdf/core";
|
|
17
|
+
|
|
18
|
+
// src/lib/actions.ts
|
|
19
|
+
var SET_HISTORY_STATE = "HISTORY/SET_STATE";
|
|
20
|
+
var setHistoryState = (state) => ({
|
|
21
|
+
type: SET_HISTORY_STATE,
|
|
22
|
+
payload: state
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// src/lib/history-plugin.ts
|
|
26
|
+
var HistoryPlugin = class extends BasePlugin {
|
|
27
|
+
constructor(id, registry) {
|
|
28
|
+
super(id, registry);
|
|
29
|
+
this.topicHistories = /* @__PURE__ */ new Map();
|
|
30
|
+
this.globalTimeline = [];
|
|
31
|
+
this.globalIndex = -1;
|
|
32
|
+
// This emitter will now broadcast the topic string of the affected history.
|
|
33
|
+
this.historyChange$ = createEmitter();
|
|
34
|
+
}
|
|
35
|
+
async initialize(_) {
|
|
36
|
+
}
|
|
37
|
+
getHistoryState() {
|
|
38
|
+
const topics = {};
|
|
39
|
+
Array.from(this.topicHistories.entries()).forEach(([topic, history]) => {
|
|
40
|
+
topics[topic] = {
|
|
41
|
+
canUndo: history.currentIndex > -1,
|
|
42
|
+
canRedo: history.currentIndex < history.commands.length - 1
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
global: {
|
|
47
|
+
canUndo: this.globalIndex > -1,
|
|
48
|
+
canRedo: this.globalIndex < this.globalTimeline.length - 1
|
|
49
|
+
},
|
|
50
|
+
topics
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// The emit function now accepts the topic to broadcast.
|
|
54
|
+
emitHistoryChange(topic) {
|
|
55
|
+
this.dispatch(setHistoryState(this.getHistoryState()));
|
|
56
|
+
this.historyChange$.emit(topic);
|
|
57
|
+
}
|
|
58
|
+
buildCapability() {
|
|
59
|
+
return {
|
|
60
|
+
getHistoryState: () => this.state,
|
|
61
|
+
onHistoryChange: this.historyChange$.on,
|
|
62
|
+
register: (command, topic) => {
|
|
63
|
+
if (!this.topicHistories.has(topic)) {
|
|
64
|
+
this.topicHistories.set(topic, { commands: [], currentIndex: -1 });
|
|
65
|
+
}
|
|
66
|
+
const topicHistory = this.topicHistories.get(topic);
|
|
67
|
+
topicHistory.commands.splice(topicHistory.currentIndex + 1);
|
|
68
|
+
topicHistory.commands.push(command);
|
|
69
|
+
topicHistory.currentIndex++;
|
|
70
|
+
const historyEntry = { command, topic };
|
|
71
|
+
this.globalTimeline.splice(this.globalIndex + 1);
|
|
72
|
+
this.globalTimeline.push(historyEntry);
|
|
73
|
+
this.globalIndex++;
|
|
74
|
+
command.execute();
|
|
75
|
+
this.emitHistoryChange(topic);
|
|
76
|
+
},
|
|
77
|
+
undo: (topic) => {
|
|
78
|
+
let affectedTopic;
|
|
79
|
+
if (topic) {
|
|
80
|
+
const topicHistory = this.topicHistories.get(topic);
|
|
81
|
+
if (topicHistory && topicHistory.currentIndex > -1) {
|
|
82
|
+
topicHistory.commands[topicHistory.currentIndex].undo();
|
|
83
|
+
topicHistory.currentIndex--;
|
|
84
|
+
affectedTopic = topic;
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
if (this.globalIndex > -1) {
|
|
88
|
+
const entry = this.globalTimeline[this.globalIndex];
|
|
89
|
+
entry.command.undo();
|
|
90
|
+
this.topicHistories.get(entry.topic).currentIndex--;
|
|
91
|
+
this.globalIndex--;
|
|
92
|
+
affectedTopic = entry.topic;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (affectedTopic) this.emitHistoryChange(affectedTopic);
|
|
96
|
+
},
|
|
97
|
+
redo: (topic) => {
|
|
98
|
+
let affectedTopic;
|
|
99
|
+
if (topic) {
|
|
100
|
+
const topicHistory = this.topicHistories.get(topic);
|
|
101
|
+
if (topicHistory && topicHistory.currentIndex < topicHistory.commands.length - 1) {
|
|
102
|
+
topicHistory.currentIndex++;
|
|
103
|
+
topicHistory.commands[topicHistory.currentIndex].execute();
|
|
104
|
+
affectedTopic = topic;
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
if (this.globalIndex < this.globalTimeline.length - 1) {
|
|
108
|
+
this.globalIndex++;
|
|
109
|
+
const entry = this.globalTimeline[this.globalIndex];
|
|
110
|
+
entry.command.execute();
|
|
111
|
+
this.topicHistories.get(entry.topic).currentIndex++;
|
|
112
|
+
affectedTopic = entry.topic;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (affectedTopic) this.emitHistoryChange(affectedTopic);
|
|
116
|
+
},
|
|
117
|
+
canUndo: (topic) => {
|
|
118
|
+
if (topic) {
|
|
119
|
+
const history = this.topicHistories.get(topic);
|
|
120
|
+
return !!history && history.currentIndex > -1;
|
|
121
|
+
}
|
|
122
|
+
return this.globalIndex > -1;
|
|
123
|
+
},
|
|
124
|
+
canRedo: (topic) => {
|
|
125
|
+
if (topic) {
|
|
126
|
+
const history = this.topicHistories.get(topic);
|
|
127
|
+
return !!history && history.currentIndex < history.commands.length - 1;
|
|
128
|
+
}
|
|
129
|
+
return this.globalIndex < this.globalTimeline.length - 1;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
HistoryPlugin.id = "history";
|
|
135
|
+
|
|
136
|
+
// src/lib/reducer.ts
|
|
137
|
+
var initialState = {
|
|
138
|
+
global: {
|
|
139
|
+
canUndo: false,
|
|
140
|
+
canRedo: false
|
|
141
|
+
},
|
|
142
|
+
topics: {}
|
|
143
|
+
};
|
|
144
|
+
var reducer = (state = initialState, action) => {
|
|
145
|
+
switch (action.type) {
|
|
146
|
+
case SET_HISTORY_STATE:
|
|
147
|
+
return {
|
|
148
|
+
...state,
|
|
149
|
+
...action.payload
|
|
150
|
+
};
|
|
151
|
+
default:
|
|
152
|
+
return state;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/lib/index.ts
|
|
157
|
+
var HistoryPluginPackage = {
|
|
158
|
+
manifest,
|
|
159
|
+
create: (registry, _engine) => new HistoryPlugin(HISTORY_PLUGIN_ID, registry),
|
|
160
|
+
reducer,
|
|
161
|
+
initialState
|
|
162
|
+
};
|
|
163
|
+
export {
|
|
164
|
+
HISTORY_PLUGIN_ID,
|
|
165
|
+
HistoryPlugin,
|
|
166
|
+
HistoryPluginPackage,
|
|
167
|
+
manifest
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/manifest.ts","../src/lib/history-plugin.ts","../src/lib/actions.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 { 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 { 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 { 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"],"mappings":";AAGO,IAAM,oBAAoB;AAE1B,IAAM,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,EACX;AACF;;;ACfA,SAAS,YAAY,qBAAqC;;;ACGnD,IAAM,oBAAoB;AAS1B,IAAM,kBAAkB,CAAC,WAAgD;AAAA,EAC9E,MAAM;AAAA,EACN,SAAS;AACX;;;ADLO,IAAM,gBAAN,cAA4B,WAKjC;AAAA,EAaA,YAAY,IAAY,UAA0B;AAChD,UAAM,IAAI,QAAQ;AAXpB,SAAiB,iBAAiB,oBAAI,IAGpC;AACF,SAAQ,iBAAiC,CAAC;AAC1C,SAAQ,cAAc;AAGtB;AAAA,SAAiB,iBAAiB,cAAkC;AAAA,EAIpE;AAAA,EAEA,MAAM,WAAW,GAAuC;AAAA,EAAC;AAAA,EAEjD,kBAAgC;AACtC,UAAM,SAAiC,CAAC;AACxC,UAAM,KAAK,KAAK,eAAe,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,OAAO,OAAO,MAAM;AACtE,aAAO,KAAK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;;AEZhB,IAAM,eAA6B;AAAA,EACxC,QAAQ;AAAA,IACN,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AAAA,EACA,QAAQ,CAAC;AACX;AAEO,IAAM,UAAgD,CAAC,QAAQ,cAAc,WAAW;AAC7F,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACH,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG,OAAO;AAAA,MACZ;AAAA,IACF;AACE,aAAO;AAAA,EACX;AACF;;;ACfO,IAAM,uBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,YAAY,IAAI,cAAc,mBAAmB,QAAQ;AAAA,EAC5E;AAAA,EACA;AACF;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/preact/index.ts
|
|
21
|
+
var preact_exports = {};
|
|
22
|
+
__export(preact_exports, {
|
|
23
|
+
useHistoryCapability: () => useHistoryCapability,
|
|
24
|
+
useHistoryPlugin: () => useHistoryPlugin
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(preact_exports);
|
|
27
|
+
|
|
28
|
+
// src/preact/hooks/use-history.ts
|
|
29
|
+
var import_preact = require("@embedpdf/core/preact");
|
|
30
|
+
var import_plugin_history = require("@embedpdf/plugin-history");
|
|
31
|
+
var useHistoryPlugin = () => (0, import_preact.usePlugin)(import_plugin_history.HistoryPlugin.id);
|
|
32
|
+
var useHistoryCapability = () => (0, import_preact.useCapability)(import_plugin_history.HistoryPlugin.id);
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
useHistoryCapability,
|
|
36
|
+
useHistoryPlugin
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-history.ts"],"sourcesContent":["export * from './hooks';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { HistoryPlugin } from '@embedpdf/plugin-history';\n\nexport const useHistoryPlugin = () => usePlugin<HistoryPlugin>(HistoryPlugin.id);\nexport const useHistoryCapability = () => useCapability<HistoryPlugin>(HistoryPlugin.id);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyC;AACzC,4BAA8B;AAEvB,IAAM,mBAAmB,UAAM,yBAAyB,oCAAc,EAAE;AACxE,IAAM,uBAAuB,UAAM,6BAA6B,oCAAc,EAAE;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_history from '@embedpdf/plugin-history';
|
|
2
|
+
import { HistoryPlugin } from '@embedpdf/plugin-history';
|
|
3
|
+
|
|
4
|
+
declare const useHistoryPlugin: () => {
|
|
5
|
+
plugin: HistoryPlugin | null;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
ready: Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
declare const useHistoryCapability: () => {
|
|
10
|
+
provides: Readonly<_embedpdf_plugin_history.HistoryCapability> | null;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
ready: Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { useHistoryCapability, useHistoryPlugin };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_history from '@embedpdf/plugin-history';
|
|
2
|
+
import { HistoryPlugin } from '@embedpdf/plugin-history';
|
|
3
|
+
|
|
4
|
+
declare const useHistoryPlugin: () => {
|
|
5
|
+
plugin: HistoryPlugin | null;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
ready: Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
declare const useHistoryCapability: () => {
|
|
10
|
+
provides: Readonly<_embedpdf_plugin_history.HistoryCapability> | null;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
ready: Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { useHistoryCapability, useHistoryPlugin };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/preact/hooks/use-history.ts
|
|
2
|
+
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
3
|
+
import { HistoryPlugin } from "@embedpdf/plugin-history";
|
|
4
|
+
var useHistoryPlugin = () => usePlugin(HistoryPlugin.id);
|
|
5
|
+
var useHistoryCapability = () => useCapability(HistoryPlugin.id);
|
|
6
|
+
export {
|
|
7
|
+
useHistoryCapability,
|
|
8
|
+
useHistoryPlugin
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preact/hooks/use-history.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { HistoryPlugin } from '@embedpdf/plugin-history';\n\nexport const useHistoryPlugin = () => usePlugin<HistoryPlugin>(HistoryPlugin.id);\nexport const useHistoryCapability = () => useCapability<HistoryPlugin>(HistoryPlugin.id);\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,qBAAqB;AAEvB,IAAM,mBAAmB,MAAM,UAAyB,cAAc,EAAE;AACxE,IAAM,uBAAuB,MAAM,cAA6B,cAAc,EAAE;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/react/index.ts
|
|
21
|
+
var react_exports = {};
|
|
22
|
+
__export(react_exports, {
|
|
23
|
+
useHistoryCapability: () => useHistoryCapability,
|
|
24
|
+
useHistoryPlugin: () => useHistoryPlugin
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(react_exports);
|
|
27
|
+
|
|
28
|
+
// src/react/hooks/use-history.ts
|
|
29
|
+
var import_react = require("@embedpdf/core/react");
|
|
30
|
+
var import_plugin_history = require("@embedpdf/plugin-history");
|
|
31
|
+
var useHistoryPlugin = () => (0, import_react.usePlugin)(import_plugin_history.HistoryPlugin.id);
|
|
32
|
+
var useHistoryCapability = () => (0, import_react.useCapability)(import_plugin_history.HistoryPlugin.id);
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
useHistoryCapability,
|
|
36
|
+
useHistoryPlugin
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-history.ts"],"sourcesContent":["export * from './hooks';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { HistoryPlugin } from '@embedpdf/plugin-history';\n\nexport const useHistoryPlugin = () => usePlugin<HistoryPlugin>(HistoryPlugin.id);\nexport const useHistoryCapability = () => useCapability<HistoryPlugin>(HistoryPlugin.id);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyC;AACzC,4BAA8B;AAEvB,IAAM,mBAAmB,UAAM,wBAAyB,oCAAc,EAAE;AACxE,IAAM,uBAAuB,UAAM,4BAA6B,oCAAc,EAAE;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_history from '@embedpdf/plugin-history';
|
|
2
|
+
import { HistoryPlugin } from '@embedpdf/plugin-history';
|
|
3
|
+
|
|
4
|
+
declare const useHistoryPlugin: () => {
|
|
5
|
+
plugin: HistoryPlugin | null;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
ready: Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
declare const useHistoryCapability: () => {
|
|
10
|
+
provides: Readonly<_embedpdf_plugin_history.HistoryCapability> | null;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
ready: Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { useHistoryCapability, useHistoryPlugin };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_history from '@embedpdf/plugin-history';
|
|
2
|
+
import { HistoryPlugin } from '@embedpdf/plugin-history';
|
|
3
|
+
|
|
4
|
+
declare const useHistoryPlugin: () => {
|
|
5
|
+
plugin: HistoryPlugin | null;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
ready: Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
declare const useHistoryCapability: () => {
|
|
10
|
+
provides: Readonly<_embedpdf_plugin_history.HistoryCapability> | null;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
ready: Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { useHistoryCapability, useHistoryPlugin };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/react/hooks/use-history.ts
|
|
2
|
+
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
3
|
+
import { HistoryPlugin } from "@embedpdf/plugin-history";
|
|
4
|
+
var useHistoryPlugin = () => usePlugin(HistoryPlugin.id);
|
|
5
|
+
var useHistoryCapability = () => useCapability(HistoryPlugin.id);
|
|
6
|
+
export {
|
|
7
|
+
useHistoryCapability,
|
|
8
|
+
useHistoryPlugin
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/hooks/use-history.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { HistoryPlugin } from '@embedpdf/plugin-history';\n\nexport const useHistoryPlugin = () => usePlugin<HistoryPlugin>(HistoryPlugin.id);\nexport const useHistoryCapability = () => useCapability<HistoryPlugin>(HistoryPlugin.id);\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,qBAAqB;AAEvB,IAAM,mBAAmB,MAAM,UAAyB,cAAc,EAAE;AACxE,IAAM,uBAAuB,MAAM,cAA6B,cAAc,EAAE;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@embedpdf/plugin-history",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./preact": {
|
|
15
|
+
"types": "./dist/preact/index.d.ts",
|
|
16
|
+
"import": "./dist/preact/index.js",
|
|
17
|
+
"require": "./dist/preact/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./react": {
|
|
20
|
+
"types": "./dist/react/index.d.ts",
|
|
21
|
+
"import": "./dist/react/index.js",
|
|
22
|
+
"require": "./dist/react/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@embedpdf/models": "1.0.7"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "^18.2.0",
|
|
30
|
+
"tsup": "^8.0.0",
|
|
31
|
+
"typescript": "^5.0.0",
|
|
32
|
+
"@embedpdf/core": "1.0.7"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=16.8.0",
|
|
36
|
+
"react-dom": ">=16.8.0",
|
|
37
|
+
"preact": "^10.26.4",
|
|
38
|
+
"@embedpdf/core": "1.0.7"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/embedpdf/embed-pdf-viewer",
|
|
47
|
+
"directory": "packages/plugin-history"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://www.embedpdf.com/docs",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/embedpdf/embed-pdf-viewer/issues"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
|
|
58
|
+
"build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
|
|
59
|
+
"clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
|
|
60
|
+
"lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
|
|
61
|
+
"lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
|
|
62
|
+
"typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
|
|
63
|
+
}
|
|
64
|
+
}
|