@rme-sdk/extension-diff 1.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 drl990114
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.
@@ -0,0 +1,231 @@
1
+ import { CommandFunction } from '@rme-sdk/core';
2
+ import { CreateExtensionPlugin } from '@rme-sdk/core';
3
+ import { DecorationSet } from '@rme-sdk/pm/view';
4
+ import { FromToProps } from '@rme-sdk/core';
5
+ import { Handler } from '@rme-sdk/core';
6
+ import { Helper } from '@rme-sdk/core';
7
+ import { PlainExtension } from '@rme-sdk/core';
8
+ import { Static } from '@rme-sdk/core';
9
+ import type { Step } from '@rme-sdk/pm/transform';
10
+ import type { StepMap } from '@rme-sdk/pm/transform';
11
+ import type { Transform } from '@rme-sdk/pm/transform';
12
+
13
+ export declare class Commit {
14
+ message: string;
15
+ time: number;
16
+ steps: Step[];
17
+ maps: StepMap[];
18
+ hidden?: boolean;
19
+ constructor(props: CommitConstructorProps);
20
+ }
21
+
22
+ declare interface CommitConstructorProps {
23
+ message: string;
24
+ time: number;
25
+ steps: Step[];
26
+ maps: StepMap[];
27
+ hidden?: boolean;
28
+ }
29
+
30
+ declare type CommitId = number | 'first' | 'last';
31
+
32
+ /**
33
+ * An extension for the remirror editor. CHANGE ME.
34
+ */
35
+ declare class DiffExtension extends PlainExtension<DiffOptions> {
36
+ get name(): "diff";
37
+ private hovered?;
38
+ private selections?;
39
+ /**
40
+ * Create the custom change tracking plugin.
41
+ *
42
+ * This has been adapted from the prosemirror website demo.
43
+ * https://github.com/ProseMirror/website/blob/master/example/track/index.js
44
+ */
45
+ createPlugin(): CreateExtensionPlugin;
46
+ /**
47
+ * Highlight the provided commit.
48
+ */
49
+ highlightCommit(commit: Commit | CommitId): CommandFunction;
50
+ /**
51
+ * Remove the highlight from the commit.
52
+ */
53
+ removeHighlightedCommit(commit: Commit | CommitId): CommandFunction;
54
+ /**
55
+ * Add a commit to the transaction history.
56
+ */
57
+ commitChange(message: string): CommandFunction;
58
+ /**
59
+ * Revert a commit which was added to the transaction history.
60
+ */
61
+ revertCommit(commit?: Commit): CommandFunction;
62
+ /**
63
+ * Get the full list of tracked commit changes
64
+ */
65
+ getCommits(): Helper<Commit[]>;
66
+ private getIndexByName;
67
+ /**
68
+ * Get the commit by it's index
69
+ */
70
+ getCommit(id: CommitId): Helper<Commit>;
71
+ private getCommitId;
72
+ /**
73
+ * Get the meta data for this custom plugin.
74
+ */
75
+ private getMeta;
76
+ /**
77
+ * Set the meta data for the plugin.
78
+ */
79
+ private setMeta;
80
+ /**
81
+ * Calls the selection handlers when the selection changes the number of
82
+ * commit spans covered.
83
+ */
84
+ private handleSelection;
85
+ /**
86
+ * Transform the view and event into a commit and span.
87
+ */
88
+ private getHandlerPropsFromEvent;
89
+ /**
90
+ * Capture the mouseover event and trigger the `onMouseOverCommit` handler
91
+ * when it is captured.
92
+ */
93
+ private handlerMouseOver;
94
+ /**
95
+ * Capture the mouseleave event and trigger the `onMouseLeaveCommit` handler.
96
+ */
97
+ private handleMouseLeave;
98
+ /**
99
+ * Create the initial plugin state for the custom plugin.
100
+ */
101
+ private createInitialState;
102
+ /**
103
+ * Apply state updates in response to document changes.
104
+ */
105
+ private applyStateUpdates;
106
+ private createDecorationSet;
107
+ /**
108
+ * Apply updates to the highlight decorations.
109
+ */
110
+ private updateHighlights;
111
+ /**
112
+ * Apply updates for the commit tracker.
113
+ *
114
+ * Please note this isn't able to track marks and diffs. It can only
115
+ * track changes to content.
116
+ */
117
+ private updateTracked;
118
+ }
119
+ export { DiffExtension }
120
+ export { DiffExtension as DiffExtension_alias_1 }
121
+
122
+ declare interface DiffOptions {
123
+ /**
124
+ * @defaultValue 'blame-marker';
125
+ */
126
+ blameMarkerClass?: Static<string>;
127
+ /**
128
+ * @defaultValue `(message: string) => "Revert: '" + message + "'"`
129
+ */
130
+ revertMessage?: (message: string) => string;
131
+ /**
132
+ * A handler that is called whenever a tracked change is hovered over in the
133
+ * editor.
134
+ */
135
+ onMouseOverCommit?: Handler<(props: HandlerProps) => void>;
136
+ /**
137
+ * A handler that is called whenever a tracked change was being hovered is no
138
+ * longer hovered.
139
+ */
140
+ onMouseLeaveCommit?: Handler<(props: HandlerProps) => void>;
141
+ /**
142
+ * Called when the commit is part of the current text selection. Called with
143
+ * an array of possible selection.
144
+ */
145
+ onSelectCommits?: Handler<(selections: HandlerProps[], previousSelections?: HandlerProps[]) => void>;
146
+ /**
147
+ * Called when commits are deselected.
148
+ */
149
+ onDeselectCommits?: Handler<(selections: HandlerProps[]) => void>;
150
+ }
151
+ export { DiffOptions }
152
+ export { DiffOptions as DiffOptions_alias_1 }
153
+
154
+ declare interface DiffPluginState extends TrackedStateProps, HighlightStateProps {
155
+ }
156
+ export { DiffPluginState }
157
+ export { DiffPluginState as DiffPluginState_alias_1 }
158
+
159
+ declare interface HandlerProps extends FromToProps {
160
+ /**
161
+ * The commit.
162
+ */
163
+ commit: Commit;
164
+ }
165
+ export { HandlerProps }
166
+ export { HandlerProps as HandlerProps_alias_1 }
167
+
168
+ declare interface HighlightStateProps {
169
+ /**
170
+ * The decorations for highlighted commits.
171
+ */
172
+ decorations: DecorationSet;
173
+ /**
174
+ * The id's of the commits to be highlighted.
175
+ */
176
+ commits?: number[];
177
+ }
178
+
179
+ export declare class Span {
180
+ from: number;
181
+ to: number;
182
+ commit: number | undefined;
183
+ constructor(props: SpanConstructorProps);
184
+ }
185
+
186
+ declare interface SpanConstructorProps {
187
+ from: number;
188
+ to: number;
189
+ commit: number | undefined;
190
+ }
191
+
192
+ declare interface TrackedStateProps {
193
+ /**
194
+ * The tracked state.
195
+ */
196
+ tracked: TrackState;
197
+ }
198
+
199
+ export declare class TrackState {
200
+ blameMap: Span[];
201
+ commits: Commit[];
202
+ uncommittedSteps: Step[];
203
+ uncommittedMaps: StepMap[];
204
+ constructor(props: TrackStateConstructorProps);
205
+ /**
206
+ * Apply a transform to this state.
207
+ */
208
+ applyTransform(transform: Transform): TrackState;
209
+ /**
210
+ * When a transaction is marked as a commit, this is used to put any
211
+ * uncommitted steps into a new commit.
212
+ */
213
+ applyCommit(message: string, time: number): TrackState;
214
+ }
215
+
216
+ declare interface TrackStateConstructorProps {
217
+ blameMap: Span[];
218
+ commits: Commit[];
219
+ uncommittedSteps: Step[];
220
+ uncommittedMaps: StepMap[];
221
+ }
222
+
223
+ export { }
224
+
225
+ declare global {
226
+ namespace Remirror {
227
+ interface AllExtensions {
228
+ diff: DiffExtension;
229
+ }
230
+ }
231
+ }
@@ -0,0 +1,231 @@
1
+ import { CommandFunction } from '@rme-sdk/core';
2
+ import { CreateExtensionPlugin } from '@rme-sdk/core';
3
+ import { DecorationSet } from '@rme-sdk/pm/view';
4
+ import { FromToProps } from '@rme-sdk/core';
5
+ import { Handler } from '@rme-sdk/core';
6
+ import { Helper } from '@rme-sdk/core';
7
+ import { PlainExtension } from '@rme-sdk/core';
8
+ import { Static } from '@rme-sdk/core';
9
+ import type { Step } from '@rme-sdk/pm/transform';
10
+ import type { StepMap } from '@rme-sdk/pm/transform';
11
+ import type { Transform } from '@rme-sdk/pm/transform';
12
+
13
+ export declare class Commit {
14
+ message: string;
15
+ time: number;
16
+ steps: Step[];
17
+ maps: StepMap[];
18
+ hidden?: boolean;
19
+ constructor(props: CommitConstructorProps);
20
+ }
21
+
22
+ declare interface CommitConstructorProps {
23
+ message: string;
24
+ time: number;
25
+ steps: Step[];
26
+ maps: StepMap[];
27
+ hidden?: boolean;
28
+ }
29
+
30
+ declare type CommitId = number | 'first' | 'last';
31
+
32
+ /**
33
+ * An extension for the remirror editor. CHANGE ME.
34
+ */
35
+ declare class DiffExtension extends PlainExtension<DiffOptions> {
36
+ get name(): "diff";
37
+ private hovered?;
38
+ private selections?;
39
+ /**
40
+ * Create the custom change tracking plugin.
41
+ *
42
+ * This has been adapted from the prosemirror website demo.
43
+ * https://github.com/ProseMirror/website/blob/master/example/track/index.js
44
+ */
45
+ createPlugin(): CreateExtensionPlugin;
46
+ /**
47
+ * Highlight the provided commit.
48
+ */
49
+ highlightCommit(commit: Commit | CommitId): CommandFunction;
50
+ /**
51
+ * Remove the highlight from the commit.
52
+ */
53
+ removeHighlightedCommit(commit: Commit | CommitId): CommandFunction;
54
+ /**
55
+ * Add a commit to the transaction history.
56
+ */
57
+ commitChange(message: string): CommandFunction;
58
+ /**
59
+ * Revert a commit which was added to the transaction history.
60
+ */
61
+ revertCommit(commit?: Commit): CommandFunction;
62
+ /**
63
+ * Get the full list of tracked commit changes
64
+ */
65
+ getCommits(): Helper<Commit[]>;
66
+ private getIndexByName;
67
+ /**
68
+ * Get the commit by it's index
69
+ */
70
+ getCommit(id: CommitId): Helper<Commit>;
71
+ private getCommitId;
72
+ /**
73
+ * Get the meta data for this custom plugin.
74
+ */
75
+ private getMeta;
76
+ /**
77
+ * Set the meta data for the plugin.
78
+ */
79
+ private setMeta;
80
+ /**
81
+ * Calls the selection handlers when the selection changes the number of
82
+ * commit spans covered.
83
+ */
84
+ private handleSelection;
85
+ /**
86
+ * Transform the view and event into a commit and span.
87
+ */
88
+ private getHandlerPropsFromEvent;
89
+ /**
90
+ * Capture the mouseover event and trigger the `onMouseOverCommit` handler
91
+ * when it is captured.
92
+ */
93
+ private handlerMouseOver;
94
+ /**
95
+ * Capture the mouseleave event and trigger the `onMouseLeaveCommit` handler.
96
+ */
97
+ private handleMouseLeave;
98
+ /**
99
+ * Create the initial plugin state for the custom plugin.
100
+ */
101
+ private createInitialState;
102
+ /**
103
+ * Apply state updates in response to document changes.
104
+ */
105
+ private applyStateUpdates;
106
+ private createDecorationSet;
107
+ /**
108
+ * Apply updates to the highlight decorations.
109
+ */
110
+ private updateHighlights;
111
+ /**
112
+ * Apply updates for the commit tracker.
113
+ *
114
+ * Please note this isn't able to track marks and diffs. It can only
115
+ * track changes to content.
116
+ */
117
+ private updateTracked;
118
+ }
119
+ export { DiffExtension }
120
+ export { DiffExtension as DiffExtension_alias_1 }
121
+
122
+ declare interface DiffOptions {
123
+ /**
124
+ * @defaultValue 'blame-marker';
125
+ */
126
+ blameMarkerClass?: Static<string>;
127
+ /**
128
+ * @defaultValue `(message: string) => "Revert: '" + message + "'"`
129
+ */
130
+ revertMessage?: (message: string) => string;
131
+ /**
132
+ * A handler that is called whenever a tracked change is hovered over in the
133
+ * editor.
134
+ */
135
+ onMouseOverCommit?: Handler<(props: HandlerProps) => void>;
136
+ /**
137
+ * A handler that is called whenever a tracked change was being hovered is no
138
+ * longer hovered.
139
+ */
140
+ onMouseLeaveCommit?: Handler<(props: HandlerProps) => void>;
141
+ /**
142
+ * Called when the commit is part of the current text selection. Called with
143
+ * an array of possible selection.
144
+ */
145
+ onSelectCommits?: Handler<(selections: HandlerProps[], previousSelections?: HandlerProps[]) => void>;
146
+ /**
147
+ * Called when commits are deselected.
148
+ */
149
+ onDeselectCommits?: Handler<(selections: HandlerProps[]) => void>;
150
+ }
151
+ export { DiffOptions }
152
+ export { DiffOptions as DiffOptions_alias_1 }
153
+
154
+ declare interface DiffPluginState extends TrackedStateProps, HighlightStateProps {
155
+ }
156
+ export { DiffPluginState }
157
+ export { DiffPluginState as DiffPluginState_alias_1 }
158
+
159
+ declare interface HandlerProps extends FromToProps {
160
+ /**
161
+ * The commit.
162
+ */
163
+ commit: Commit;
164
+ }
165
+ export { HandlerProps }
166
+ export { HandlerProps as HandlerProps_alias_1 }
167
+
168
+ declare interface HighlightStateProps {
169
+ /**
170
+ * The decorations for highlighted commits.
171
+ */
172
+ decorations: DecorationSet;
173
+ /**
174
+ * The id's of the commits to be highlighted.
175
+ */
176
+ commits?: number[];
177
+ }
178
+
179
+ export declare class Span {
180
+ from: number;
181
+ to: number;
182
+ commit: number | undefined;
183
+ constructor(props: SpanConstructorProps);
184
+ }
185
+
186
+ declare interface SpanConstructorProps {
187
+ from: number;
188
+ to: number;
189
+ commit: number | undefined;
190
+ }
191
+
192
+ declare interface TrackedStateProps {
193
+ /**
194
+ * The tracked state.
195
+ */
196
+ tracked: TrackState;
197
+ }
198
+
199
+ export declare class TrackState {
200
+ blameMap: Span[];
201
+ commits: Commit[];
202
+ uncommittedSteps: Step[];
203
+ uncommittedMaps: StepMap[];
204
+ constructor(props: TrackStateConstructorProps);
205
+ /**
206
+ * Apply a transform to this state.
207
+ */
208
+ applyTransform(transform: Transform): TrackState;
209
+ /**
210
+ * When a transaction is marked as a commit, this is used to put any
211
+ * uncommitted steps into a new commit.
212
+ */
213
+ applyCommit(message: string, time: number): TrackState;
214
+ }
215
+
216
+ declare interface TrackStateConstructorProps {
217
+ blameMap: Span[];
218
+ commits: Commit[];
219
+ uncommittedSteps: Step[];
220
+ uncommittedMaps: StepMap[];
221
+ }
222
+
223
+ export { }
224
+
225
+ declare global {
226
+ namespace Remirror {
227
+ interface AllExtensions {
228
+ diff: DiffExtension;
229
+ }
230
+ }
231
+ }