@krainovsd/markdown-editor 0.4.9 → 0.5.0-beta.1

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.
@@ -174,7 +174,6 @@ function overlapMark({ marks, shift, state, requireMatched }) {
174
174
  originalText: text.substring(shiftBeforeOuter, text.length - shiftAfterOuter),
175
175
  };
176
176
  }
177
- // eslint-disable-next-line max-params
178
177
  function findMarkIndex(text, marks, requireMatched, direction = "right") {
179
178
  if (text.length === 0)
180
179
  return -1;
@@ -705,16 +704,19 @@ const initKeyMaps = async ({ onEnter, onEscape, multiCursorMode, keyMaps, defaul
705
704
  return view.keymap.of(keyBindings);
706
705
  };
707
706
 
708
- function getChangeEvent({ onChange }) {
709
- return onChange
707
+ function initListeners({ onBlur, onChange, onFocus, onViewChange }) {
708
+ return [getChangeEvent({ onChange, onViewChange }), getFocusEvent({ onBlur, onFocus })];
709
+ }
710
+ function getChangeEvent({ onChange, onViewChange }) {
711
+ return onChange || onViewChange
710
712
  ? view.EditorView.updateListener.of((event) => {
713
+ onViewChange?.(event);
711
714
  if (event.docChanged) {
712
- onChange(event);
715
+ onChange?.(event);
713
716
  }
714
717
  })
715
718
  : [];
716
719
  }
717
-
718
720
  function getFocusEvent({ onBlur, onFocus }) {
719
721
  return onFocus || onBlur
720
722
  ? view.EditorView.focusChangeEffect.of((event, focus) => {
@@ -727,10 +729,6 @@ function getFocusEvent({ onBlur, onFocus }) {
727
729
  : [];
728
730
  }
729
731
 
730
- function initListeners({ onBlur, onChange, onFocus }) {
731
- return [getChangeEvent({ onChange }), getFocusEvent({ onBlur, onFocus })];
732
- }
733
-
734
732
  function styleInject(css, ref) {
735
733
  if ( ref === void 0 ) ref = {};
736
734
  var insertAt = ref.insertAt;
@@ -1214,7 +1212,6 @@ const CODE_OF_END_IMAGE_TEXT = 93; // ]
1214
1212
  const CODE_OF_START_IMAGE_URL = 40; // (
1215
1213
  const CODE_OF_END_IMAGE_URL = 41; // )
1216
1214
 
1217
- /* eslint-disable max-params */
1218
1215
  const IMAGE_NODES = {};
1219
1216
  const INTERVAL_DELAY = 10000;
1220
1217
  const EXISTING_WIDGETS = new Set();
@@ -1610,7 +1607,6 @@ function getLinkLabelSelectionDecoration({ decorations, node, view, forceActive,
1610
1607
  }
1611
1608
  }
1612
1609
 
1613
- /* eslint-disable max-params */
1614
1610
  const LINK_NODES = {};
1615
1611
  class LinkWidget extends view.WidgetType {
1616
1612
  text;
@@ -2227,7 +2223,7 @@ async function initSettings({ readonly, vimMode, }) {
2227
2223
  ];
2228
2224
  }
2229
2225
 
2230
- const initExtensions = async ({ onBlur, onChange, onFocus, onEnter, onEscape, readonly = true, vimMode = false, multiCursorText, provider, theme = "light", dark, light, languages, keyMaps, defaultKeyMaps, imageSrcGetter, autoCompleteTagOptions, autoCompleteConfig, }) => {
2226
+ const initExtensions = async ({ onBlur, onChange, onFocus, onEnter, onEscape, onViewChange, readonly = true, vimMode = false, multiCursorText, provider, theme = "light", dark, light, languages, keyMaps, defaultKeyMaps, imageSrcGetter, autoCompleteTagOptions, autoCompleteConfig, }) => {
2231
2227
  const multiCursorMode = Boolean(multiCursorText && provider);
2232
2228
  const asyncPlugins = await Promise.all([
2233
2229
  initSettings({ readonly, vimMode }),
@@ -2243,7 +2239,7 @@ const initExtensions = async ({ onBlur, onChange, onFocus, onEnter, onEscape, re
2243
2239
  light,
2244
2240
  }),
2245
2241
  new Promise((resolve) => {
2246
- void Promise.resolve().then(() => require('./index--WqbgHNW.js')).then(({ initMarkdown }) => {
2242
+ void Promise.resolve().then(() => require('./index-i33yKEVJ.js')).then(({ initMarkdown }) => {
2247
2243
  resolve(initMarkdown({ languages, imageSrcGetter }));
2248
2244
  });
2249
2245
  }),
@@ -2252,7 +2248,7 @@ const initExtensions = async ({ onBlur, onChange, onFocus, onEnter, onEscape, re
2252
2248
  const extensions = [
2253
2249
  ...asyncPlugins,
2254
2250
  initTheme({ theme, dark, light }),
2255
- initListeners({ onBlur, onChange, onFocus }),
2251
+ initListeners({ onBlur, onChange, onFocus, onViewChange }),
2256
2252
  ];
2257
2253
  if (multiCursorText && provider) {
2258
2254
  const multiCursorModules = await Promise.all([import('yjs'), import('y-codemirror.next')]);
@@ -2331,14 +2327,28 @@ class Editor {
2331
2327
  provider;
2332
2328
  arguments;
2333
2329
  yText;
2334
- constructor(options) {
2335
- void initEditor(options).then((editor) => {
2336
- this.view = editor.view;
2337
- this.provider = editor.provider;
2338
- this.yText = editor.multiCursorText;
2339
- });
2330
+ init = async (options) => {
2331
+ const editor = await initEditor(options);
2332
+ this.view = editor.view;
2333
+ this.provider = editor.provider;
2334
+ this.yText = editor.multiCursorText;
2340
2335
  this.arguments = options;
2341
- }
2336
+ };
2337
+ destroy = () => {
2338
+ return new Promise((resolve) => {
2339
+ saveDispatch(() => {
2340
+ this.view?.destroy?.();
2341
+ this.provider?.destroy?.();
2342
+ resolve(true);
2343
+ });
2344
+ });
2345
+ };
2346
+ reset = async () => {
2347
+ await this.destroy();
2348
+ if (!this.arguments)
2349
+ return;
2350
+ return this.init(this.arguments);
2351
+ };
2342
2352
  focus = () => {
2343
2353
  if (!this.view)
2344
2354
  return;
@@ -2369,10 +2379,6 @@ class Editor {
2369
2379
  });
2370
2380
  };
2371
2381
  replaceContent = (content) => {
2372
- // if (!this.yText) return;
2373
- // this.yText.delete(0, this.yText.length);
2374
- // this.yText.insert(0, content);
2375
- // return;
2376
2382
  if (!this.view)
2377
2383
  return;
2378
2384
  const transaction = this.view.state.update({
@@ -2400,11 +2406,11 @@ class Editor {
2400
2406
  this.view.dispatch({
2401
2407
  effects: ThemeCompartment.reconfigure(theme === "dark"
2402
2408
  ? getDarkTheme({
2403
- dark: this.arguments.dark,
2404
- light: this.arguments.light})
2409
+ dark: this.arguments?.dark,
2410
+ light: this.arguments?.light})
2405
2411
  : getLightTheme({
2406
- dark: this.arguments.dark,
2407
- light: this.arguments.light})),
2412
+ dark: this.arguments?.dark,
2413
+ light: this.arguments?.light})),
2408
2414
  });
2409
2415
  });
2410
2416
  };
@@ -2425,17 +2431,6 @@ class Editor {
2425
2431
  return;
2426
2432
  this.provider.awareness.setLocalStateField("user", { name, color });
2427
2433
  };
2428
- destroy = () => {
2429
- saveDispatch(() => {
2430
- if (!this.view)
2431
- return;
2432
- this.view.destroy();
2433
- });
2434
- saveDispatch(() => {
2435
- if (this.provider)
2436
- this.provider.destroy();
2437
- });
2438
- };
2439
2434
  }
2440
2435
 
2441
2436
  exports.CODE_OF_LINE_BREAK = CODE_OF_LINE_BREAK;
@@ -2445,4 +2440,4 @@ exports.Editor = Editor;
2445
2440
  exports.NAME_OF_MENTION = NAME_OF_MENTION;
2446
2441
  exports.markdownDecorationPlugin = markdownDecorationPlugin;
2447
2442
  exports.markdownState = markdownState;
2448
- //# sourceMappingURL=index-DULzPQ7W.js.map
2443
+ //# sourceMappingURL=index-Da-2bfWr.js.map