ponkotsu-md-editor 0.2.28 → 0.2.30

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: 0cc45ca65c7659579a474af291d5085d7d6c71e54bca0d39c2f2715da9127cae
4
- data.tar.gz: '02597c3e57b09366d114524e719bf021f412f457a2aeabbcc1fb291c8272e478'
3
+ metadata.gz: 91415e80a85a2d898fcedacaecdab8f0c7bc0318f70116639e8f876be4923703
4
+ data.tar.gz: 3869fdf6b809a201dc03453c19255504a6ae77dcabc1675587ea07739a182e94
5
5
  SHA512:
6
- metadata.gz: 136b83c73133c4fc00eec970fca2526a3d5caa9956694aade0b4fecb863e0dbb40e55a74a9fe1350e384b01710fb5748e7748f49141418753ffe6e1fb36479f7
7
- data.tar.gz: 3f83b1ecc4172c0217325ed2161cc61b55f5b4afe65a95f8a09ada47898e3c2a5279caca2999b5d25a197bc2f2db4b18b1c1dd8a43776a91c879201c17c71859
6
+ metadata.gz: e7395d5c820e5ef6a5aac7c42813453a638adae579980c921cd7c95681d5158a04efd97ec760b3c32ae8595271214a882768a8915b385eafdf8f32a3acc4e21e
7
+ data.tar.gz: 451c5dd0f0b3b3dfa97cc927c2b43b769deae7a98b2dedc38b9f833519ff67502f9f4f4ec09882c13dfd366eb080d4b2313538a3f03a4e1c207e5dee04863d8d
@@ -39,6 +39,44 @@
39
39
  if (textarea && hiddenField) {
40
40
  // プレースホルダーのマウスホイールイベント処理
41
41
  if (placeholder) {
42
+ // クリック時にエディタにフォーカス
43
+ placeholder.addEventListener('click', function(e) {
44
+ e.preventDefault();
45
+ textarea.focus();
46
+
47
+ // クリック位置にカーソルを設定(オプション)
48
+ const rect = textarea.getBoundingClientRect();
49
+ const x = e.clientX - rect.left;
50
+ const y = e.clientY - rect.top;
51
+
52
+ // contenteditable要素内の適切な位置にカーソルを設定
53
+ if (document.caretRangeFromPoint) {
54
+ const range = document.caretRangeFromPoint(e.clientX, e.clientY);
55
+ if (range && textarea.contains(range.startContainer)) {
56
+ const selection = window.getSelection();
57
+ selection.removeAllRanges();
58
+ selection.addRange(range);
59
+ } else {
60
+ // フォールバック: エディタの開始位置にカーソルを設定
61
+ const range = document.createRange();
62
+ range.selectNodeContents(textarea);
63
+ range.collapse(true);
64
+ const selection = window.getSelection();
65
+ selection.removeAllRanges();
66
+ selection.addRange(range);
67
+ }
68
+ } else {
69
+ // caretRangeFromPointが利用できない場合のフォールバック
70
+ const range = document.createRange();
71
+ range.selectNodeContents(textarea);
72
+ range.collapse(true);
73
+ const selection = window.getSelection();
74
+ selection.removeAllRanges();
75
+ selection.addRange(range);
76
+ }
77
+ });
78
+
79
+ // マウスホイールイベント処理(プレースホルダー内スクロール用)
42
80
  placeholder.addEventListener('wheel', function(e) {
43
81
  // プレースホルダーがスクロール可能かチェック
44
82
  const canScrollVertically = placeholder.scrollHeight > placeholder.clientHeight;
@@ -83,8 +121,6 @@
83
121
  hiddenField.value = (textarea.innerText || '').replaceAll('\u00A0', ' ');
84
122
  };
85
123
 
86
- textarea.addEventListener('blur', syncToHidden);
87
-
88
124
  // 初期化時に同期
89
125
  syncToHidden();
90
126
 
@@ -100,7 +136,9 @@
100
136
  // 初期状態でプレースホルダを表示するための空要素チェック
101
137
  function updatePlaceholderVisibility() {
102
138
  // <br>のみの場合も空とみなす
103
- if (textarea.innerHTML.trim() === '&nbsp;' || textarea.innerHTML.trim() === '' || textarea.innerHTML.trim() === '\<br\>') {
139
+ if (textarea.innerHTML.trim() === '&nbsp;' || textarea.innerHTML.trim() === ''
140
+ || textarea.innerHTML.trim() === '\<br\>'
141
+ || textarea.innerHTML.trim() === '<div> </div>') {
104
142
  textarea.classList.add('empty');
105
143
  } else {
106
144
  textarea.classList.remove('empty');
@@ -66,23 +66,13 @@
66
66
  width: 100%;
67
67
  height: calc(24 * 20px);
68
68
  color: var(--text-placeholder);
69
- pointer-events: none;
70
69
  z-index: 10;
71
70
  white-space: pre-line;
72
71
  display: block;
73
72
  overflow: auto;
74
73
  padding: 0.5em 0.75em;
75
74
  box-sizing: border-box;
76
- }
77
-
78
- /* マウスホバー時のみpointer-eventsを有効化 */
79
- #editor_content_placeholder:hover {
80
- pointer-events: auto;
81
- }
82
-
83
- /* エディタがフォーカスされている時はプレースホルダーのpointer-eventsを無効化 */
84
- #editor_content:focus ~ #editor_content_placeholder {
85
- pointer-events: none !important;
75
+ cursor: text;
86
76
  }
87
77
 
88
78
  /* emptyクラスがない時(コンテンツがある時)にプレースホルダーを隠す */
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PonkotsuMdEditor
4
- VERSION = "0.2.28"
4
+ VERSION = "0.2.30"
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.28
4
+ version: 0.2.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhq_boiler