@jupyterlab/codemirror 4.3.4 → 4.3.5

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.
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { Annotation, EditorSelection, Facet } from '@codemirror/state';
11
11
  import { ViewPlugin } from '@codemirror/view';
12
+ import { yUndoManager, YUndoManagerConfig, yUndoManagerFacet } from './yundomanager';
12
13
  import { createAbsolutePositionFromRelativePosition, createRelativePositionFromJSON, createRelativePositionFromTypeIndex, relativePositionToJSON } from 'yjs';
13
14
  /**
14
15
  * Defines a range on text using relative positions that can be transformed back to
@@ -207,23 +208,13 @@ export const ySync = ViewPlugin.fromClass(class {
207
208
  */
208
209
  export function ybinding({ ytext, undoManager }) {
209
210
  const ySyncConfig = new YSyncConfig(ytext);
210
- // We don't need the undo manager extension as in y-codemirror.next
211
- // because we deal with undo/redo with our own keyboard shortcut mechanism.
212
- return [
213
- ySyncFacet.of(ySyncConfig),
214
- ySync,
211
+ const plugins = [ySyncFacet.of(ySyncConfig), ySync];
212
+ if (undoManager) {
213
+ plugins.push(
215
214
  // We need to add a new origin to the undo manager to ensure text updates
216
- // are tracked.
217
- undoManager
218
- ? ViewPlugin.define(() => {
219
- undoManager.addTrackedOrigin(ySyncConfig);
220
- return {
221
- destroy: () => {
222
- undoManager.removeTrackedOrigin(ySyncConfig);
223
- }
224
- };
225
- })
226
- : []
227
- ];
215
+ // are tracked; we also need to restore selection after undo/redo.
216
+ yUndoManagerFacet.of(new YUndoManagerConfig(undoManager)), yUndoManager);
217
+ }
218
+ return plugins;
228
219
  }
229
220
  //# sourceMappingURL=ybinding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ybinding.js","sourceRoot":"","sources":["../../src/extensions/ybinding.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,UAAU,EACV,eAAe,EAEf,KAAK,EAEN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAc,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CAAC,EAAE,KAAK,CAAC,CAAC;IACpD,IAAI,WAAW,EAAE;QACf,OAAO,CAAC,IAAI;QACV,yEAAyE;QACzE,kEAAkE;QAClE,iBAAiB,CAAC,EAAE,CAAC,IAAI,kBAAkB,CAAC,WAAW,CAAC,CAAC,EACzD,YAAY,CACb,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { EditorView, PluginValue, ViewPlugin, ViewUpdate } from '@codemirror/view';
2
+ import { Facet } from '@codemirror/state';
3
+ import type { UndoManager } from 'yjs';
4
+ interface IStackItem {
5
+ meta: Map<any, any>;
6
+ }
7
+ export declare class YUndoManagerConfig {
8
+ constructor(undoManager: UndoManager);
9
+ undoManager: UndoManager;
10
+ }
11
+ export declare const yUndoManagerFacet: Facet<YUndoManagerConfig, YUndoManagerConfig>;
12
+ declare class YUndoManagerPluginValue implements PluginValue {
13
+ constructor(view: EditorView);
14
+ _onStackItemAdded: ({ stackItem, changedParentTypes }: {
15
+ stackItem: IStackItem;
16
+ changedParentTypes: Map<any, any>;
17
+ }) => void;
18
+ _onStackItemPopped: ({ stackItem }: {
19
+ stackItem: IStackItem;
20
+ }) => void;
21
+ _storeSelection: () => void;
22
+ update(update: ViewUpdate): void;
23
+ destroy(): void;
24
+ private _undoManager;
25
+ private _view;
26
+ private _beforeChangeSelection;
27
+ private _conf;
28
+ private _syncConf;
29
+ }
30
+ export declare const yUndoManager: ViewPlugin<YUndoManagerPluginValue>;
31
+ export {};
@@ -0,0 +1,80 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ *
5
+ * Vendored from https://github.com/yjs/y-codemirror.next
6
+ * licensed under MIT License by Kevin Jahns.
7
+ *
8
+ * Ideally we would depend on the y-codemirror.next, but it is impractical
9
+ * until https://github.com/yjs/y-codemirror.next/issues/27 is resolved.
10
+ *
11
+ * Modifications compared to upstream:
12
+ * - removed spurious mutex (https://github.com/yjs/y-codemirror.next/issues/15)
13
+ * - added TypeScript types
14
+ * - simplified `YUndoManagerConfig` by removing public methods
15
+ * - moved `_onStackItemAdded`, `_onStackItemPopped` and `_storeSelection` definitions out of constructor
16
+ */
17
+ import { EditorView, ViewPlugin } from '@codemirror/view';
18
+ import { Facet } from '@codemirror/state';
19
+ import { ySyncAnnotation, ySyncFacet } from './ybinding';
20
+ export class YUndoManagerConfig {
21
+ constructor(undoManager) {
22
+ this.undoManager = undoManager;
23
+ }
24
+ }
25
+ export const yUndoManagerFacet = Facet.define({
26
+ combine(inputs) {
27
+ return inputs[inputs.length - 1];
28
+ }
29
+ });
30
+ class YUndoManagerPluginValue {
31
+ constructor(view) {
32
+ this._onStackItemAdded = ({ stackItem, changedParentTypes }) => {
33
+ // only store metadata if this type was affected
34
+ if (changedParentTypes.has(this._syncConf.ytext) &&
35
+ this._beforeChangeSelection &&
36
+ !stackItem.meta.has(this)) {
37
+ // do not overwrite previous stored selection
38
+ stackItem.meta.set(this, this._beforeChangeSelection);
39
+ }
40
+ };
41
+ this._onStackItemPopped = ({ stackItem }) => {
42
+ const sel = stackItem.meta.get(this);
43
+ if (sel) {
44
+ const selection = this._syncConf.fromYRange(sel);
45
+ this._view.dispatch(this._view.state.update({
46
+ selection,
47
+ effects: [EditorView.scrollIntoView(selection)]
48
+ }));
49
+ this._storeSelection();
50
+ }
51
+ };
52
+ this._storeSelection = () => {
53
+ // store the selection before the change is applied so we can restore it with the undo manager.
54
+ this._beforeChangeSelection = this._syncConf.toYRange(this._view.state.selection.main);
55
+ };
56
+ this._view = view;
57
+ this._conf = view.state.facet(yUndoManagerFacet);
58
+ this._undoManager = this._conf.undoManager;
59
+ this._syncConf = view.state.facet(ySyncFacet);
60
+ this._beforeChangeSelection = null;
61
+ this._undoManager.on('stack-item-added', this._onStackItemAdded);
62
+ this._undoManager.on('stack-item-popped', this._onStackItemPopped);
63
+ this._undoManager.addTrackedOrigin(this._syncConf);
64
+ }
65
+ update(update) {
66
+ if (update.selectionSet &&
67
+ (update.transactions.length === 0 ||
68
+ update.transactions[0].annotation(ySyncAnnotation) !== this._syncConf)) {
69
+ // This only works when YUndoManagerPlugin is included before the sync plugin
70
+ this._storeSelection();
71
+ }
72
+ }
73
+ destroy() {
74
+ this._undoManager.off('stack-item-added', this._onStackItemAdded);
75
+ this._undoManager.off('stack-item-popped', this._onStackItemPopped);
76
+ this._undoManager.removeTrackedOrigin(this._syncConf);
77
+ }
78
+ }
79
+ export const yUndoManager = ViewPlugin.fromClass(YUndoManagerPluginValue);
80
+ //# sourceMappingURL=yundomanager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yundomanager.js","sourceRoot":"","sources":["../../src/extensions/yundomanager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,UAAU,EAEV,UAAU,EAEX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAU,eAAe,EAAe,UAAU,EAAE,MAAM,YAAY,CAAC;AAO9E,MAAM,OAAO,kBAAkB;IAC7B,YAAY,WAAwB;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CAEF;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAG3C;IACA,OAAO,CAAC,MAAM;QACZ,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnC,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,uBAAuB;IAC3B,YAAY,IAAgB;QAU5B,sBAAiB,GAAG,CAAC,EACnB,SAAS,EACT,kBAAkB,EAInB,EAAE,EAAE;YACH,gDAAgD;YAChD,IACE,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;gBAC5C,IAAI,CAAC,sBAAsB;gBAC3B,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,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iBAAiB,CAAC,CAAC;QACjE,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,mBAAmB,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACnE,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAqCD,MAAM,CAAC,MAAkB;QACvB,IACE,MAAM,CAAC,YAAY;YACnB,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC;gBAC/B,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,EACxE;YACA,6EAA6E;YAC7E,IAAI,CAAC,eAAe,EAAE,CAAC;SACxB;IACH,CAAC;IACD,OAAO;QACL,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAClE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACpE,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CAMF;AACD,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlab/codemirror",
3
- "version": "4.3.4",
3
+ "version": "4.3.5",
4
4
  "description": "JupyterLab - CodeMirror Editor Provider",
5
5
  "homepage": "https://github.com/jupyterlab/jupyterlab",
6
6
  "bugs": {
@@ -58,11 +58,11 @@
58
58
  "@codemirror/state": "^6.4.1",
59
59
  "@codemirror/view": "^6.26.3",
60
60
  "@jupyter/ydoc": "^3.0.0",
61
- "@jupyterlab/codeeditor": "^4.3.4",
62
- "@jupyterlab/coreutils": "^6.3.4",
63
- "@jupyterlab/documentsearch": "^4.3.4",
64
- "@jupyterlab/nbformat": "^4.3.4",
65
- "@jupyterlab/translation": "^4.3.4",
61
+ "@jupyterlab/codeeditor": "^4.3.5",
62
+ "@jupyterlab/coreutils": "^6.3.5",
63
+ "@jupyterlab/documentsearch": "^4.3.5",
64
+ "@jupyterlab/nbformat": "^4.3.5",
65
+ "@jupyterlab/translation": "^4.3.5",
66
66
  "@lezer/common": "^1.2.1",
67
67
  "@lezer/generator": "^1.7.0",
68
68
  "@lezer/highlight": "^1.2.0",
@@ -73,7 +73,7 @@
73
73
  "yjs": "^13.5.40"
74
74
  },
75
75
  "devDependencies": {
76
- "@jupyterlab/testing": "^4.3.4",
76
+ "@jupyterlab/testing": "^4.3.5",
77
77
  "@lezer/generator": "^1.7.0",
78
78
  "@lezer/lr": "^1.4.0",
79
79
  "@types/jest": "^29.2.0",
@@ -15,6 +15,11 @@ import {
15
15
  SelectionRange
16
16
  } from '@codemirror/state';
17
17
  import { EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view';
18
+ import {
19
+ yUndoManager,
20
+ YUndoManagerConfig,
21
+ yUndoManagerFacet
22
+ } from './yundomanager';
18
23
  import type {
19
24
  RelativePosition,
20
25
  Text,
@@ -274,22 +279,14 @@ export function ybinding({
274
279
  undoManager?: UndoManager;
275
280
  }): Extension {
276
281
  const ySyncConfig = new YSyncConfig(ytext);
277
- // We don't need the undo manager extension as in y-codemirror.next
278
- // because we deal with undo/redo with our own keyboard shortcut mechanism.
279
- return [
280
- ySyncFacet.of(ySyncConfig),
281
- ySync,
282
- // We need to add a new origin to the undo manager to ensure text updates
283
- // are tracked.
284
- undoManager
285
- ? ViewPlugin.define(() => {
286
- undoManager.addTrackedOrigin(ySyncConfig);
287
- return {
288
- destroy: () => {
289
- undoManager.removeTrackedOrigin(ySyncConfig);
290
- }
291
- };
292
- })
293
- : []
294
- ];
282
+ const plugins = [ySyncFacet.of(ySyncConfig), ySync];
283
+ if (undoManager) {
284
+ plugins.push(
285
+ // We need to add a new origin to the undo manager to ensure text updates
286
+ // are tracked; we also need to restore selection after undo/redo.
287
+ yUndoManagerFacet.of(new YUndoManagerConfig(undoManager)),
288
+ yUndoManager
289
+ );
290
+ }
291
+ return plugins;
295
292
  }
@@ -0,0 +1,115 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ *
5
+ * Vendored from https://github.com/yjs/y-codemirror.next
6
+ * licensed under MIT License by Kevin Jahns.
7
+ *
8
+ * Ideally we would depend on the y-codemirror.next, but it is impractical
9
+ * until https://github.com/yjs/y-codemirror.next/issues/27 is resolved.
10
+ *
11
+ * Modifications compared to upstream:
12
+ * - removed spurious mutex (https://github.com/yjs/y-codemirror.next/issues/15)
13
+ * - added TypeScript types
14
+ * - simplified `YUndoManagerConfig` by removing public methods
15
+ * - moved `_onStackItemAdded`, `_onStackItemPopped` and `_storeSelection` definitions out of constructor
16
+ */
17
+ import {
18
+ EditorView,
19
+ PluginValue,
20
+ ViewPlugin,
21
+ ViewUpdate
22
+ } from '@codemirror/view';
23
+ import { Facet } from '@codemirror/state';
24
+ import { YRange, ySyncAnnotation, YSyncConfig, ySyncFacet } from './ybinding';
25
+ import type { UndoManager } from 'yjs';
26
+
27
+ interface IStackItem {
28
+ meta: Map<any, any>;
29
+ }
30
+
31
+ export class YUndoManagerConfig {
32
+ constructor(undoManager: UndoManager) {
33
+ this.undoManager = undoManager;
34
+ }
35
+ public undoManager: UndoManager;
36
+ }
37
+
38
+ export const yUndoManagerFacet = Facet.define<
39
+ YUndoManagerConfig,
40
+ YUndoManagerConfig
41
+ >({
42
+ combine(inputs) {
43
+ return inputs[inputs.length - 1];
44
+ }
45
+ });
46
+
47
+ class YUndoManagerPluginValue implements PluginValue {
48
+ constructor(view: EditorView) {
49
+ this._view = view;
50
+ this._conf = view.state.facet(yUndoManagerFacet);
51
+ this._undoManager = this._conf.undoManager;
52
+ this._syncConf = view.state.facet(ySyncFacet);
53
+ this._beforeChangeSelection = null;
54
+ this._undoManager.on('stack-item-added', this._onStackItemAdded);
55
+ this._undoManager.on('stack-item-popped', this._onStackItemPopped);
56
+ this._undoManager.addTrackedOrigin(this._syncConf);
57
+ }
58
+ _onStackItemAdded = ({
59
+ stackItem,
60
+ changedParentTypes
61
+ }: {
62
+ stackItem: IStackItem;
63
+ changedParentTypes: Map<any, any>;
64
+ }) => {
65
+ // only store metadata if this type was affected
66
+ if (
67
+ changedParentTypes.has(this._syncConf.ytext) &&
68
+ this._beforeChangeSelection &&
69
+ !stackItem.meta.has(this)
70
+ ) {
71
+ // do not overwrite previous stored selection
72
+ stackItem.meta.set(this, this._beforeChangeSelection);
73
+ }
74
+ };
75
+ _onStackItemPopped = ({ stackItem }: { stackItem: IStackItem }) => {
76
+ const sel = stackItem.meta.get(this);
77
+ if (sel) {
78
+ const selection = this._syncConf.fromYRange(sel);
79
+ this._view.dispatch(
80
+ this._view.state.update({
81
+ selection,
82
+ effects: [EditorView.scrollIntoView(selection)]
83
+ })
84
+ );
85
+ this._storeSelection();
86
+ }
87
+ };
88
+ _storeSelection = () => {
89
+ // store the selection before the change is applied so we can restore it with the undo manager.
90
+ this._beforeChangeSelection = this._syncConf.toYRange(
91
+ this._view.state.selection.main
92
+ );
93
+ };
94
+ update(update: ViewUpdate) {
95
+ if (
96
+ update.selectionSet &&
97
+ (update.transactions.length === 0 ||
98
+ update.transactions[0].annotation(ySyncAnnotation) !== this._syncConf)
99
+ ) {
100
+ // This only works when YUndoManagerPlugin is included before the sync plugin
101
+ this._storeSelection();
102
+ }
103
+ }
104
+ destroy() {
105
+ this._undoManager.off('stack-item-added', this._onStackItemAdded);
106
+ this._undoManager.off('stack-item-popped', this._onStackItemPopped);
107
+ this._undoManager.removeTrackedOrigin(this._syncConf);
108
+ }
109
+ private _undoManager: UndoManager;
110
+ private _view: EditorView;
111
+ private _beforeChangeSelection: null | YRange;
112
+ private _conf: YUndoManagerConfig;
113
+ private _syncConf: YSyncConfig;
114
+ }
115
+ export const yUndoManager = ViewPlugin.fromClass(YUndoManagerPluginValue);