rme 0.0.58 → 0.0.59

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.d.ts CHANGED
@@ -9,6 +9,7 @@ export { useCommands, useHelpers, useKeymap, useRemirrorContext } from '@remirro
9
9
  import * as _drl990114_codemirror_themes from '@drl990114/codemirror-themes';
10
10
  import { CreateThemeOptions } from '@drl990114/codemirror-themes';
11
11
  export { CreateThemeOptions, createTheme } from '@drl990114/codemirror-themes';
12
+ import { EditorViewConfig } from '@codemirror/view';
12
13
  import { LanguageDescription, LanguageSupport } from '@codemirror/language';
13
14
  import * as styled_components from 'styled-components';
14
15
  import * as styled_components_dist_types from 'styled-components/dist/types';
@@ -214,6 +215,13 @@ declare const wysiwygTransformer: {
214
215
  declare const _default: react.NamedExoticComponent<EditorProps>;
215
216
 
216
217
  declare const changeTheme: (theme: CreateThemeOptions) => void;
218
+ type CreateCodemirrorOptions = {
219
+ /**
220
+ * when it is true, undo and redo will use prosemirror view.
221
+ */
222
+ useProsemirrorHistoryKey?: boolean;
223
+ codemirrorEditorViewConfig?: EditorViewConfig;
224
+ };
217
225
  declare const getLanguageMap: () => Record<string, LanguageDescription>;
218
226
  declare const loadLanguage: (languageName: string) => Promise<LanguageSupport> | LanguageSupport | undefined;
219
227
  declare function computeChange(oldVal: string, newVal: string): {
@@ -433,4 +441,4 @@ declare const lightTheme: {
433
441
  };
434
442
  };
435
443
 
436
- export { type CreateWysiwygDelegateOptions, type DocToString, Editor, type EditorChangeEventParams, type EditorChangeHandler, type EditorContext, type EditorDelegate, extensions as EditorExtensions, type EditorProps, type EditorRef, type EditorState, type EditorViewType, type Note, Preview, SourceCodeThemeWrapper, _default$1 as SourceEditor, type StringToDoc, ThemeProvider, _default as WysiwygEditor, WysiwygThemeWrapper, buildMarkdownParser, buildMarkdownSerializer, changeTheme, common, computeChange, createSourceCodeDelegate, createSourceCodeManager, createWysiwygDelegate, darkTheme, getLanguageMap, lightTheme, loadLanguage, tableSelectorSize, wysiwygTransformer };
444
+ export { type CreateCodemirrorOptions, type CreateWysiwygDelegateOptions, type DocToString, Editor, type EditorChangeEventParams, type EditorChangeHandler, type EditorContext, type EditorDelegate, extensions as EditorExtensions, type EditorProps, type EditorRef, type EditorState, type EditorViewType, type Note, Preview, SourceCodeThemeWrapper, _default$1 as SourceEditor, type StringToDoc, ThemeProvider, _default as WysiwygEditor, WysiwygThemeWrapper, buildMarkdownParser, buildMarkdownSerializer, changeTheme, common, computeChange, createSourceCodeDelegate, createSourceCodeManager, createWysiwygDelegate, darkTheme, getLanguageMap, lightTheme, loadLanguage, tableSelectorSize, wysiwygTransformer };
package/dist/index.mjs CHANGED
@@ -8301,6 +8301,7 @@ import { nanoid as nanoid2 } from "nanoid";
8301
8301
  import { createTheme } from "@drl990114/codemirror-themes";
8302
8302
 
8303
8303
  // src/editor/codemirror/codemirror.ts
8304
+ import { redo, undo } from "@remirror/pm/history";
8304
8305
  var cmInstanceMap = /* @__PURE__ */ new Map();
8305
8306
  var themeRef = { current: createTheme(lightTheme.codemirrorTheme) };
8306
8307
  var changeTheme = (theme) => {
@@ -8318,7 +8319,7 @@ var MfCodemirrorView = class {
8318
8319
  node,
8319
8320
  extensions: extensions2 = [],
8320
8321
  languageName,
8321
- createParams = {}
8322
+ options = {}
8322
8323
  }) {
8323
8324
  this.toggleName = "paragraph";
8324
8325
  this.id = nanoid2();
@@ -8332,6 +8333,7 @@ var MfCodemirrorView = class {
8332
8333
  this.schema = node.type.schema;
8333
8334
  this.languageName = languageName;
8334
8335
  this.loadLanguage = loadLanguage;
8336
+ this.options = options;
8335
8337
  this.content = this.node.textContent;
8336
8338
  const changeFilter = CodeMirrorEditorState.changeFilter.of((tr) => {
8337
8339
  if (!tr.docChanged) {
@@ -8352,7 +8354,7 @@ var MfCodemirrorView = class {
8352
8354
  this.cm = new CodeMirrorEditorView({
8353
8355
  state: startState,
8354
8356
  dispatch: this.valueChanged.bind(this),
8355
- ...createParams
8357
+ ...this.options.codemirrorEditorViewConfig || {}
8356
8358
  });
8357
8359
  cmInstanceMap.set(this.id, this);
8358
8360
  this.updateLanguage();
@@ -8442,7 +8444,7 @@ var MfCodemirrorView = class {
8442
8444
  return TextSelection3.between(doc.resolve(anchor + start), doc.resolve(head + start));
8443
8445
  }
8444
8446
  codeMirrorKeymap() {
8445
- return [
8447
+ const keymaps = [
8446
8448
  {
8447
8449
  key: "ArrowUp",
8448
8450
  run: this.maybeEscape("line", -1)
@@ -8498,6 +8500,38 @@ var MfCodemirrorView = class {
8498
8500
  }
8499
8501
  }
8500
8502
  ];
8503
+ if (this.options?.useProsemirrorHistoryKey) {
8504
+ keymaps.push(
8505
+ {
8506
+ key: "Mod-z",
8507
+ run: () => {
8508
+ undo(this.view.state, this.view.dispatch);
8509
+ this.view.focus();
8510
+ return false;
8511
+ }
8512
+ },
8513
+ {
8514
+ key: "Mod-y",
8515
+ mac: "Mod-Shift-z",
8516
+ run: () => {
8517
+ redo(this.view.state, this.view.dispatch);
8518
+ this.view.focus();
8519
+ return false;
8520
+ },
8521
+ preventDefault: true
8522
+ },
8523
+ {
8524
+ linux: "Ctrl-Shift-z",
8525
+ run: () => {
8526
+ redo(this.view.state, this.view.dispatch);
8527
+ this.view.focus();
8528
+ return false;
8529
+ },
8530
+ preventDefault: true
8531
+ }
8532
+ );
8533
+ }
8534
+ return keymaps;
8501
8535
  }
8502
8536
  maybeEscape(unit, dir) {
8503
8537
  return (view) => {
@@ -8626,8 +8660,6 @@ var minimalSetup = (() => [
8626
8660
  dropCursor(),
8627
8661
  lineNumbers(),
8628
8662
  highlightSpecialChars(),
8629
- history(),
8630
- indentOnInput(),
8631
8663
  syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
8632
8664
  bracketMatching(),
8633
8665
  closeBrackets(),
@@ -8635,13 +8667,7 @@ var minimalSetup = (() => [
8635
8667
  crosshairCursor(),
8636
8668
  highlightSelectionMatches(),
8637
8669
  keymap2.of([
8638
- ...closeBracketsKeymap,
8639
- ...defaultKeymap,
8640
- ...searchKeymap,
8641
- ...historyKeymap,
8642
- ...foldKeymap,
8643
- ...completionKeymap,
8644
- ...lintKeymap
8670
+ ...defaultKeymap
8645
8671
  ])
8646
8672
  ])();
8647
8673
 
@@ -15042,6 +15068,7 @@ function removeNewlines(str) {
15042
15068
  var HtmlNodeView = class {
15043
15069
  constructor(node, view, getPos) {
15044
15070
  this._htmlSrcElt = null;
15071
+ this.destroying = false;
15045
15072
  this.ignoreMutation = () => true;
15046
15073
  this.handleMouseEnter = () => {
15047
15074
  this.dom.classList.add("node-enter");
@@ -15147,13 +15174,13 @@ var HtmlNodeView = class {
15147
15174
  node: this._node,
15148
15175
  getPos: this._getPos,
15149
15176
  languageName: "html",
15150
- createParams: {
15151
- parent: this._htmlSrcElt
15152
- },
15153
- extensions: [
15154
- minimalSetup,
15155
- htmlLang
15156
- ]
15177
+ extensions: [minimalSetup, htmlLang],
15178
+ options: {
15179
+ useProsemirrorHistoryKey: true,
15180
+ codemirrorEditorViewConfig: {
15181
+ parent: this._htmlSrcElt
15182
+ }
15183
+ }
15157
15184
  });
15158
15185
  this._htmlSrcElt.classList.remove("node-hide");
15159
15186
  this._innerView = this.mfCodemirrorView.cm;
@@ -15162,11 +15189,14 @@ var HtmlNodeView = class {
15162
15189
  this.setSelection(prevCursorPos, prevCursorPos);
15163
15190
  this._innerView.focus();
15164
15191
  this._innerView.contentDOM.addEventListener("blur", () => {
15192
+ if (this.destroying)
15193
+ return;
15165
15194
  this.closeEditor(true);
15166
15195
  });
15167
15196
  this.mfCodemirrorView.forwardSelection();
15168
15197
  }
15169
15198
  destroy() {
15199
+ this.destroying = true;
15170
15200
  this.closeEditor(false);
15171
15201
  if (this._htmlRenderElt) {
15172
15202
  this._htmlRenderElt.remove();
@@ -17614,7 +17644,8 @@ function extensions({ handleViewImgSrcUrl }) {
17614
17644
  new LineHeadingExtension({}),
17615
17645
  new LineListExtension(),
17616
17646
  new LineCodeMirrorExtension({
17617
- extensions: [minimalSetup]
17647
+ extensions: [minimalSetup],
17648
+ useProsemirrorHistoryKey: true
17618
17649
  }),
17619
17650
  new LineTableExtension({ resizable: false }),
17620
17651
  new LineTableRowExtension(),
@@ -18633,7 +18664,8 @@ var CodeMirror6NodeView = class {
18633
18664
  node,
18634
18665
  view,
18635
18666
  getPos,
18636
- extensions: extensions2
18667
+ extensions: extensions2,
18668
+ options
18637
18669
  }) {
18638
18670
  this.node = node;
18639
18671
  this.view = view;
@@ -18644,7 +18676,8 @@ var CodeMirror6NodeView = class {
18644
18676
  getPos: this.getPos,
18645
18677
  node: this.node,
18646
18678
  extensions: extensions2,
18647
- languageName: this.languageName
18679
+ languageName: this.languageName,
18680
+ options
18648
18681
  });
18649
18682
  this.cm = this.mfCodemirrorView.cm;
18650
18683
  this.dom = this.cm.dom;
@@ -18714,7 +18747,10 @@ var LineCodeMirrorExtension = class extends NodeExtension4 {
18714
18747
  view,
18715
18748
  getPos,
18716
18749
  extensions: this.options.extensions,
18717
- toggleName: this.options.toggleName
18750
+ toggleName: this.options.toggleName,
18751
+ options: {
18752
+ useProsemirrorHistoryKey: this.options.useProsemirrorHistoryKey
18753
+ }
18718
18754
  });
18719
18755
  return this.nodeview;
18720
18756
  };
@@ -18870,8 +18906,12 @@ LineCodeMirrorExtension = __decorateClass([
18870
18906
  defaultOptions: {
18871
18907
  hideDecoration: false,
18872
18908
  extensions: null,
18873
- toggleName: "paragraph"
18874
- }
18909
+ toggleName: "paragraph",
18910
+ useProsemirrorHistoryKey: false
18911
+ },
18912
+ staticKeys: [],
18913
+ handlerKeys: [],
18914
+ customHandlerKeys: []
18875
18915
  })
18876
18916
  ], LineCodeMirrorExtension);
18877
18917