ponkotsu-md-editor 0.2.16 → 0.2.17

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44c0d57085b26248050128b50dd4e4651198ed4d6805cc40eb4a6db417e20a91
4
- data.tar.gz: 7ebe6787dc0b1591c08995be8640f68ad6aaec0e25d1cce0212631db5dc54064
3
+ metadata.gz: 4a1a95ceac09dc027f3d4ef1d20b55e081f6a823ebae67f3960751ec37ecf008
4
+ data.tar.gz: ced47c4fb6b5c055c72e61ebd71e1af27716055112c423894cec2d8618c570e2
5
5
  SHA512:
6
- metadata.gz: fc5a9675a51a6b64f976a7af0b3b8ef1b273906f48f4ce086353bbe65ee2a7400acd9cf970c66979762511653a36520375ec74693dbe1567a7639c7a4aa94016
7
- data.tar.gz: a0c6d1de3b9dd58f7b4e0d3f6e06d8aa2834ff3da5cbdc24a0ad3a1a4e27010e4b12f70a33f881c1e438cc32cd0b5002f09cd5a24bd8abe0d0fe7303c102afe5
6
+ metadata.gz: b38378161c6b1831682572c0b33c46da6e409687ba02ed9680109cced3a7fff3570ddeb7b2bd56da30498a1ec16a7be4616947c0103aa4f4b7638727c5c64003
7
+ data.tar.gz: 9a6f8c0bff90b72782600eae59b026c9c08a948f8eb80ca0e981b07ad6728da471f3a002436c9a173b0672d48e2880cef8349e9bb9f48f97c6da08bffc01cb75
@@ -1,6 +1,19 @@
1
1
  (function() {
2
2
  'use strict';
3
3
 
4
+ // Debounce function for delayed execution
5
+ function debounce(func, wait) {
6
+ let timeout;
7
+ return function executedFunction(...args) {
8
+ const later = () => {
9
+ clearTimeout(timeout);
10
+ func(...args);
11
+ };
12
+ clearTimeout(timeout);
13
+ timeout = setTimeout(later, wait);
14
+ };
15
+ }
16
+
4
17
  // Safe DOM element retrieval
5
18
  function getElement(selector) {
6
19
  try {
@@ -23,7 +36,7 @@
23
36
  const syncToHidden = () => {
24
37
  hiddenField.value = (textarea.innerText || '').replaceAll('\u00A0', ' ');
25
38
  };
26
- textarea.addEventListener('input', syncToHidden);
39
+ textarea.addEventListener('input', debounce(syncToHidden, 150));
27
40
  textarea.addEventListener('blur', syncToHidden);
28
41
  // 初期化時にも同期
29
42
  syncToHidden();
@@ -42,7 +55,7 @@
42
55
  updatePlaceholderVisibility();
43
56
 
44
57
  // 入力時にプレースホルダの表示/非表示を制御
45
- textarea.addEventListener('input', updatePlaceholderVisibility);
58
+ textarea.addEventListener('input', debounce(updatePlaceholderVisibility, 150));
46
59
  textarea.addEventListener('blur', updatePlaceholderVisibility);
47
60
  }
48
61
  } else {
@@ -117,7 +130,7 @@
117
130
  caretPosition.end = textarea.selectionEnd;
118
131
  }
119
132
  };
120
- textarea.addEventListener('input', saveCaretPosition);
133
+ textarea.addEventListener('input', debounce(saveCaretPosition, 100));
121
134
  textarea.addEventListener('keyup', saveCaretPosition);
122
135
  textarea.addEventListener('click', saveCaretPosition);
123
136
  }
@@ -692,7 +705,16 @@
692
705
  }
693
706
  }
694
707
 
708
+ const analyzeHtmlCache = new Map();
709
+
695
710
  function analyzeHtml(target, isCountEmptyDiv = false) {
711
+
712
+ const cacheKey = `${target}_${isCountEmptyDiv}`;
713
+
714
+ if (analyzeHtmlCache.has(cacheKey)) {
715
+ return analyzeHtmlCache.get(cacheKey);
716
+ }
717
+
696
718
  let lines = [];
697
719
  let remain = target;
698
720
 
@@ -758,6 +780,12 @@
758
780
  }
759
781
  }
760
782
 
783
+ if (analyzeHtmlCache.size > 100) {
784
+ const firstKey = analyzeHtmlCache.keys().next().value;
785
+ analyzeHtmlCache.delete(firstKey);
786
+ }
787
+
788
+ analyzeHtmlCache.set(cacheKey, lines);
761
789
  return lines;
762
790
  }
763
791
 
@@ -1975,19 +2003,6 @@
1975
2003
  }
1976
2004
  }
1977
2005
 
1978
- // Debounce function for delayed execution
1979
- function debounce(func, wait) {
1980
- let timeout;
1981
- return function executedFunction(...args) {
1982
- const later = () => {
1983
- clearTimeout(timeout);
1984
- func(...args);
1985
- };
1986
- clearTimeout(timeout);
1987
- timeout = setTimeout(later, wait);
1988
- };
1989
- }
1990
-
1991
2006
  // Keyboard shortcuts
1992
2007
  if (textarea) {
1993
2008
  textarea.addEventListener('keydown', function(e) {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PonkotsuMdEditor
4
- VERSION = "0.2.16"
4
+ VERSION = "0.2.17"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ponkotsu-md-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhq_boiler