@rufous/ui 0.1.95 → 0.1.97

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.
Files changed (3) hide show
  1. package/dist/main.cjs +22 -21
  2. package/dist/main.js +22 -21
  3. package/package.json +1 -1
package/dist/main.cjs CHANGED
@@ -49677,14 +49677,15 @@ function findMisspelled(doc3) {
49677
49677
  function createSpellCheckPlugin() {
49678
49678
  let debounceTimer = null;
49679
49679
  let viewRef = null;
49680
+ let currentDecos = DecorationSet.empty;
49681
+ let currentDoc = null;
49680
49682
  const runCheck = (view) => {
49681
49683
  try {
49682
49684
  if (!typo || !view?.dom?.isConnected || !view.state) return;
49683
49685
  const { doc: doc3 } = view.state;
49684
49686
  if (!doc3 || doc3.content.size <= 4) {
49685
- const tr2 = view.state.tr.setMeta(spellCheckPluginKey, { decorations: DecorationSet.empty });
49686
- tr2.setMeta("addToHistory", false);
49687
- view.dispatch(tr2);
49687
+ currentDecos = DecorationSet.empty;
49688
+ currentDoc = doc3;
49688
49689
  return;
49689
49690
  }
49690
49691
  const misspelled = findMisspelled(doc3);
@@ -49695,33 +49696,30 @@ function createSpellCheckPlugin() {
49695
49696
  "data-spell-word": word
49696
49697
  })
49697
49698
  );
49698
- const decorationSet = DecorationSet.create(doc3, decos);
49699
- const tr = view.state.tr.setMeta(spellCheckPluginKey, { decorations: decorationSet });
49700
- tr.setMeta("addToHistory", false);
49701
- view.dispatch(tr);
49699
+ currentDecos = DecorationSet.create(doc3, decos);
49700
+ currentDoc = doc3;
49701
+ if (view.dom?.isConnected && !view.isDestroyed) {
49702
+ const tr = view.state.tr.setMeta("spellCheckDone", true);
49703
+ tr.setMeta("addToHistory", false);
49704
+ view.dispatch(tr);
49705
+ }
49702
49706
  } catch {
49707
+ currentDecos = DecorationSet.empty;
49708
+ currentDoc = null;
49703
49709
  }
49704
49710
  };
49705
49711
  const scheduleCheck = (view) => {
49706
49712
  if (debounceTimer) clearTimeout(debounceTimer);
49707
- debounceTimer = setTimeout(() => runCheck(view), 500);
49713
+ debounceTimer = setTimeout(() => {
49714
+ if (viewRef?.dom?.isConnected) runCheck(viewRef);
49715
+ }, 500);
49708
49716
  };
49709
49717
  return new Plugin2({
49710
49718
  key: spellCheckPluginKey,
49711
- state: {
49712
- init() {
49713
- return DecorationSet.empty;
49714
- },
49715
- apply(tr, _oldDecos) {
49716
- const meta = tr.getMeta(spellCheckPluginKey);
49717
- if (meta?.decorations) return meta.decorations;
49718
- if (tr.docChanged) return DecorationSet.empty;
49719
- return _oldDecos;
49720
- }
49721
- },
49722
49719
  props: {
49723
49720
  decorations(state) {
49724
- return spellCheckPluginKey.getState(state) || DecorationSet.empty;
49721
+ if (state.doc !== currentDoc) return DecorationSet.empty;
49722
+ return currentDecos;
49725
49723
  }
49726
49724
  },
49727
49725
  view(editorView) {
@@ -49730,17 +49728,20 @@ function createSpellCheckPlugin() {
49730
49728
  if (viewRef) scheduleCheck(viewRef);
49731
49729
  };
49732
49730
  initSpellChecker().then(() => {
49733
- if (viewRef) runCheck(viewRef);
49731
+ if (viewRef?.dom?.isConnected) runCheck(viewRef);
49734
49732
  });
49735
49733
  return {
49736
49734
  update(view, prevState) {
49737
49735
  viewRef = view;
49738
49736
  if (view.state.doc !== prevState.doc) {
49737
+ currentDecos = DecorationSet.empty;
49739
49738
  scheduleCheck(view);
49740
49739
  }
49741
49740
  },
49742
49741
  destroy() {
49743
49742
  if (debounceTimer) clearTimeout(debounceTimer);
49743
+ currentDecos = DecorationSet.empty;
49744
+ currentDoc = null;
49744
49745
  viewRef = null;
49745
49746
  scheduleRecheckFn = null;
49746
49747
  }
package/dist/main.js CHANGED
@@ -21007,14 +21007,15 @@ function findMisspelled(doc3) {
21007
21007
  function createSpellCheckPlugin() {
21008
21008
  let debounceTimer = null;
21009
21009
  let viewRef = null;
21010
+ let currentDecos = DecorationSet.empty;
21011
+ let currentDoc = null;
21010
21012
  const runCheck = (view) => {
21011
21013
  try {
21012
21014
  if (!typo || !view?.dom?.isConnected || !view.state) return;
21013
21015
  const { doc: doc3 } = view.state;
21014
21016
  if (!doc3 || doc3.content.size <= 4) {
21015
- const tr2 = view.state.tr.setMeta(spellCheckPluginKey, { decorations: DecorationSet.empty });
21016
- tr2.setMeta("addToHistory", false);
21017
- view.dispatch(tr2);
21017
+ currentDecos = DecorationSet.empty;
21018
+ currentDoc = doc3;
21018
21019
  return;
21019
21020
  }
21020
21021
  const misspelled = findMisspelled(doc3);
@@ -21025,33 +21026,30 @@ function createSpellCheckPlugin() {
21025
21026
  "data-spell-word": word
21026
21027
  })
21027
21028
  );
21028
- const decorationSet = DecorationSet.create(doc3, decos);
21029
- const tr = view.state.tr.setMeta(spellCheckPluginKey, { decorations: decorationSet });
21030
- tr.setMeta("addToHistory", false);
21031
- view.dispatch(tr);
21029
+ currentDecos = DecorationSet.create(doc3, decos);
21030
+ currentDoc = doc3;
21031
+ if (view.dom?.isConnected && !view.isDestroyed) {
21032
+ const tr = view.state.tr.setMeta("spellCheckDone", true);
21033
+ tr.setMeta("addToHistory", false);
21034
+ view.dispatch(tr);
21035
+ }
21032
21036
  } catch {
21037
+ currentDecos = DecorationSet.empty;
21038
+ currentDoc = null;
21033
21039
  }
21034
21040
  };
21035
21041
  const scheduleCheck = (view) => {
21036
21042
  if (debounceTimer) clearTimeout(debounceTimer);
21037
- debounceTimer = setTimeout(() => runCheck(view), 500);
21043
+ debounceTimer = setTimeout(() => {
21044
+ if (viewRef?.dom?.isConnected) runCheck(viewRef);
21045
+ }, 500);
21038
21046
  };
21039
21047
  return new Plugin({
21040
21048
  key: spellCheckPluginKey,
21041
- state: {
21042
- init() {
21043
- return DecorationSet.empty;
21044
- },
21045
- apply(tr, _oldDecos) {
21046
- const meta = tr.getMeta(spellCheckPluginKey);
21047
- if (meta?.decorations) return meta.decorations;
21048
- if (tr.docChanged) return DecorationSet.empty;
21049
- return _oldDecos;
21050
- }
21051
- },
21052
21049
  props: {
21053
21050
  decorations(state) {
21054
- return spellCheckPluginKey.getState(state) || DecorationSet.empty;
21051
+ if (state.doc !== currentDoc) return DecorationSet.empty;
21052
+ return currentDecos;
21055
21053
  }
21056
21054
  },
21057
21055
  view(editorView) {
@@ -21060,17 +21058,20 @@ function createSpellCheckPlugin() {
21060
21058
  if (viewRef) scheduleCheck(viewRef);
21061
21059
  };
21062
21060
  initSpellChecker().then(() => {
21063
- if (viewRef) runCheck(viewRef);
21061
+ if (viewRef?.dom?.isConnected) runCheck(viewRef);
21064
21062
  });
21065
21063
  return {
21066
21064
  update(view, prevState) {
21067
21065
  viewRef = view;
21068
21066
  if (view.state.doc !== prevState.doc) {
21067
+ currentDecos = DecorationSet.empty;
21069
21068
  scheduleCheck(view);
21070
21069
  }
21071
21070
  },
21072
21071
  destroy() {
21073
21072
  if (debounceTimer) clearTimeout(debounceTimer);
21073
+ currentDecos = DecorationSet.empty;
21074
+ currentDoc = null;
21074
21075
  viewRef = null;
21075
21076
  scheduleRecheckFn = null;
21076
21077
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rufous/ui",
3
3
  "private": false,
4
- "version": "0.1.95",
4
+ "version": "0.1.97",
5
5
  "type": "module",
6
6
  "description": "Experimental: A lightweight React UI component library (Beta)",
7
7
  "style": "./dist/main.css",