ponkotsu-md-editor 0.2.32 → 0.2.33
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 +4 -4
- data/app/assets/javascripts/markdown_editor.js +65 -33
- data/lib/ponkotsu/md/editor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7340ba8c2ac893d51238f60395be14004050920c09de9ffe172e47af8736fa8
|
|
4
|
+
data.tar.gz: 383aa9b69c43ab1319cd17b675402dfc7fcf94f44c5ad140c0fe3efa64190c5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bac62356700052a2be43f8a9a7710f9bebda2c7109afbc62bc48c7fd7f617c150becd6959d0ab7ba830b76670673b03a3cbd4636ad4461e5533bffc756d581ce
|
|
7
|
+
data.tar.gz: 4a0f6612cc409a4e255fdb8868624bbf618d39979513e946cb14db8e888d4cb7f484077c9bff7bd045ffc9a6e04395b3a13097b64b7122052c9c4f3eadb3db9d
|
|
@@ -117,19 +117,45 @@
|
|
|
117
117
|
}, { passive: false });
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
const syncToHidden = () => {
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
const syncToHidden = (() => {
|
|
121
|
+
let lastValue = '';
|
|
122
|
+
let pendingUpdate = false;
|
|
123
|
+
|
|
124
|
+
return () => {
|
|
125
|
+
if (pendingUpdate) return;
|
|
126
|
+
|
|
127
|
+
// テキスト取得(innerTextよりtextContentの方が高速)
|
|
128
|
+
const currentText = (textarea.textContent || '').replaceAll('\u00A0', ' ');
|
|
129
|
+
|
|
130
|
+
// 変更がない場合はスキップ
|
|
131
|
+
if (currentText === lastValue) return;
|
|
132
|
+
|
|
133
|
+
pendingUpdate = true;
|
|
134
|
+
requestAnimationFrame(() => {
|
|
135
|
+
hiddenField.value = currentText;
|
|
136
|
+
lastValue = currentText;
|
|
137
|
+
pendingUpdate = false;
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
})();
|
|
123
141
|
|
|
124
142
|
// 初期化時に同期
|
|
125
143
|
syncToHidden();
|
|
126
144
|
|
|
127
|
-
//
|
|
145
|
+
// フォーム送信時の処理を非同期化
|
|
128
146
|
const form = textarea.closest('form');
|
|
129
147
|
if (form) {
|
|
130
148
|
form.addEventListener('submit', function(e) {
|
|
131
|
-
|
|
132
|
-
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
|
|
151
|
+
// 同期的に値を設定(確実性のため)
|
|
152
|
+
hiddenField.value = (textarea.textContent || '').replaceAll('\u00A0', ' ');
|
|
153
|
+
|
|
154
|
+
// 次のティックで送信
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
// console.log('Form submitting with content length:', hiddenField.value.length);
|
|
157
|
+
form.submit();
|
|
158
|
+
}, 0);
|
|
133
159
|
});
|
|
134
160
|
}
|
|
135
161
|
|
|
@@ -240,7 +266,7 @@
|
|
|
240
266
|
}
|
|
241
267
|
|
|
242
268
|
onReady(function() {
|
|
243
|
-
console.log('Enhanced Markdown editor initializing...');
|
|
269
|
+
// console.log('Enhanced Markdown editor initializing...');
|
|
244
270
|
|
|
245
271
|
// Get DOM elements
|
|
246
272
|
const textarea = document.getElementById('editor_content');
|
|
@@ -306,7 +332,7 @@
|
|
|
306
332
|
'Expected:' + expected + '\n' +
|
|
307
333
|
'Actual:', actual);
|
|
308
334
|
} else {
|
|
309
|
-
console.log('Assertion passed:', message);
|
|
335
|
+
// console.log('Assertion passed:', message);
|
|
310
336
|
}
|
|
311
337
|
}
|
|
312
338
|
|
|
@@ -417,16 +443,16 @@
|
|
|
417
443
|
}
|
|
418
444
|
|
|
419
445
|
// === デバッグ出力 ===
|
|
420
|
-
console.log('[DEBUG] getContentEditableSelection');
|
|
421
|
-
console.log('fullText:', JSON.stringify(fullText));
|
|
422
|
-
console.log('startPos:', startPos, 'endPos:', endPos);
|
|
423
|
-
console.log('selectedText:', JSON.stringify(selectedText));
|
|
424
|
-
console.log('rangeText:', JSON.stringify(rangeText));
|
|
425
|
-
console.log('textNodes:', textNodes.map(n => n.textContent));
|
|
426
|
-
console.log('range.startContainer:', range.startContainer);
|
|
427
|
-
console.log('range.startOffset:', range.startOffset);
|
|
428
|
-
console.log('range.endContainer:', range.endContainer);
|
|
429
|
-
console.log('range.endOffset:', range.endOffset);
|
|
446
|
+
// console.log('[DEBUG] getContentEditableSelection');
|
|
447
|
+
// console.log('fullText:', JSON.stringify(fullText));
|
|
448
|
+
// console.log('startPos:', startPos, 'endPos:', endPos);
|
|
449
|
+
// console.log('selectedText:', JSON.stringify(selectedText));
|
|
450
|
+
// console.log('rangeText:', JSON.stringify(rangeText));
|
|
451
|
+
// console.log('textNodes:', textNodes.map(n => n.textContent));
|
|
452
|
+
// console.log('range.startContainer:', range.startContainer);
|
|
453
|
+
// console.log('range.startOffset:', range.startOffset);
|
|
454
|
+
// console.log('range.endContainer:', range.endContainer);
|
|
455
|
+
// console.log('range.endOffset:', range.endOffset);
|
|
430
456
|
// ===================
|
|
431
457
|
|
|
432
458
|
return {
|
|
@@ -864,6 +890,8 @@
|
|
|
864
890
|
}
|
|
865
891
|
}
|
|
866
892
|
|
|
893
|
+
const MAX_CACHE_SIZE = 500;
|
|
894
|
+
|
|
867
895
|
function analyzeHtml(target, isCountEmptyDiv = false) {
|
|
868
896
|
|
|
869
897
|
const cacheKey = `${target}_${isCountEmptyDiv}`;
|
|
@@ -937,9 +965,13 @@
|
|
|
937
965
|
}
|
|
938
966
|
}
|
|
939
967
|
|
|
940
|
-
if (analyzeHtmlCache.size >
|
|
941
|
-
|
|
942
|
-
|
|
968
|
+
if (analyzeHtmlCache.size > MAX_CACHE_SIZE) {
|
|
969
|
+
// 古いエントリを複数削除(より効率的)
|
|
970
|
+
const deleteCount = Math.floor(MAX_CACHE_SIZE * 0.2); // 20%削除
|
|
971
|
+
const keys = Array.from(analyzeHtmlCache.keys());
|
|
972
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
973
|
+
analyzeHtmlCache.delete(keys[i]);
|
|
974
|
+
}
|
|
943
975
|
}
|
|
944
976
|
|
|
945
977
|
analyzeHtmlCache.set(cacheKey, lines);
|
|
@@ -1030,10 +1062,10 @@
|
|
|
1030
1062
|
const endOffset = getOffsetInContainer(textarea, range.endContainer, range.endOffset);
|
|
1031
1063
|
|
|
1032
1064
|
// === デバッグ出力(削除可能)===
|
|
1033
|
-
console.log('DOM-based text:', JSON.stringify(domBasedText));
|
|
1034
|
-
console.log('beginEndLenStrings:', beginEndLenStrings);
|
|
1035
|
-
console.log('Selection offsets:', startOffset, endOffset);
|
|
1036
|
-
console.log('Selected text should be:', JSON.stringify(domBasedText.substring(startOffset, endOffset)));
|
|
1065
|
+
// console.log('DOM-based text:', JSON.stringify(domBasedText));
|
|
1066
|
+
// console.log('beginEndLenStrings:', beginEndLenStrings);
|
|
1067
|
+
// console.log('Selection offsets:', startOffset, endOffset);
|
|
1068
|
+
// console.log('Selected text should be:', JSON.stringify(domBasedText.substring(startOffset, endOffset)));
|
|
1037
1069
|
// =============================
|
|
1038
1070
|
|
|
1039
1071
|
const startPos = getLineAndCharIndex(textarea, startOffset);
|
|
@@ -1228,10 +1260,10 @@
|
|
|
1228
1260
|
const range = selection.getRangeAt(0);
|
|
1229
1261
|
const selectedText = range.toString();
|
|
1230
1262
|
|
|
1231
|
-
console.log('Markdown apply debug:');
|
|
1232
|
-
console.log('Selected text:', JSON.stringify(selectedText));
|
|
1233
|
-
console.log('Before markup:', JSON.stringify(before));
|
|
1234
|
-
console.log('After markup:', JSON.stringify(after));
|
|
1263
|
+
// console.log('Markdown apply debug:');
|
|
1264
|
+
// console.log('Selected text:', JSON.stringify(selectedText));
|
|
1265
|
+
// console.log('Before markup:', JSON.stringify(before));
|
|
1266
|
+
// console.log('After markup:', JSON.stringify(after));
|
|
1235
1267
|
|
|
1236
1268
|
if (selectedText.length === 0) {
|
|
1237
1269
|
// No selection - insert markers at cursor position
|
|
@@ -1261,7 +1293,7 @@
|
|
|
1261
1293
|
newSelection.removeAllRanges();
|
|
1262
1294
|
newSelection.addRange(newRange);
|
|
1263
1295
|
|
|
1264
|
-
console.log('DOM replacement completed successfully');
|
|
1296
|
+
// console.log('DOM replacement completed successfully');
|
|
1265
1297
|
|
|
1266
1298
|
// Fire input event for change detection
|
|
1267
1299
|
element.dispatchEvent(new Event('input', { bubbles: true }));
|
|
@@ -1645,7 +1677,7 @@
|
|
|
1645
1677
|
script.onload = () => {
|
|
1646
1678
|
this.loaded = true;
|
|
1647
1679
|
this.loading = false;
|
|
1648
|
-
console.log('Twitter widgets.js loaded successfully');
|
|
1680
|
+
// console.log('Twitter widgets.js loaded successfully');
|
|
1649
1681
|
resolve();
|
|
1650
1682
|
};
|
|
1651
1683
|
|
|
@@ -1676,7 +1708,7 @@
|
|
|
1676
1708
|
|
|
1677
1709
|
if (window.twttr && window.twttr.widgets) {
|
|
1678
1710
|
await window.twttr.widgets.load(container);
|
|
1679
|
-
console.log('Twitter widgets initialized');
|
|
1711
|
+
// console.log('Twitter widgets initialized');
|
|
1680
1712
|
}
|
|
1681
1713
|
} catch (error) {
|
|
1682
1714
|
console.error('Failed to initialize Twitter widgets:', error);
|
|
@@ -2199,7 +2231,7 @@
|
|
|
2199
2231
|
});
|
|
2200
2232
|
}
|
|
2201
2233
|
|
|
2202
|
-
console.log('ponkotsu Markdown editor initialized successfully');
|
|
2234
|
+
// console.log('ponkotsu Markdown editor initialized successfully');
|
|
2203
2235
|
});
|
|
2204
2236
|
|
|
2205
2237
|
// Enhanced error handling
|