toggle-components-library 1.37.0-beta.2 → 1.37.0-beta.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toggle-components-library",
3
- "version": "1.37.0-beta.2",
3
+ "version": "1.37.0-beta.4",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -6,6 +6,8 @@
6
6
  contenteditable="true"
7
7
  class="toggle-breadcrumb-editable-input"
8
8
  @input="updateContent($event);"
9
+ @keydown.enter.prevent="handleEnterKey"
10
+ @paste.prevent="handlePaste"
9
11
  >{{ crumb.name }}</span>
10
12
  </template>
11
13
  <template v-else>
@@ -55,17 +57,60 @@ export default {
55
57
  },
56
58
 
57
59
  methods: {
60
+ handlePaste(event) {
61
+ // Get plain text from clipboard and clean it
62
+ const text = (event.clipboardData || window.clipboardData).getData('text');
63
+ const cleanText = text.replace(/[\r\n\s]+/g, ' ').trim();
64
+
65
+ // Get current selection information
66
+ const selection = window.getSelection();
67
+ const selectionLength = selection.toString().length;
68
+ const currentLength = this.content.length;
69
+
70
+ // Check if adding the pasted text would exceed maxChars
71
+ if (currentLength - selectionLength + cleanText.length <= this.maxChars && selection.rangeCount) {
72
+ const range = selection.getRangeAt(0);
73
+ range.deleteContents();
74
+ range.insertNode(document.createTextNode(cleanText));
75
+
76
+ // Move cursor to end of inserted text
77
+ range.collapse(false);
78
+ selection.removeAllRanges();
79
+ selection.addRange(range);
80
+
81
+ // Update content
82
+ this.content = event.target.innerText;
83
+ this.$emit('update:lastCrumb', this.content);
84
+ }
85
+ },
86
+
87
+ handleEnterKey(event) {
88
+ event.preventDefault();
89
+ event.target.blur();
90
+ },
58
91
 
92
+
59
93
  updateContent(event) {
60
- // Limit the input to 50 characters
61
- if (event.target.innerText.length >= this.maxChars) {
94
+ const newText = event.target.innerText;
95
+
96
+ // If text exceeds maxChars, prevent the change
97
+ if (newText.length > this.maxChars) {
98
+ // Save current selection
99
+ const selection = window.getSelection();
100
+ const range = selection.getRangeAt(0);
101
+ const cursorOffset = range.startOffset;
102
+
103
+ // Restore previous content
62
104
  event.target.innerText = this.content;
63
-
64
- // Move the cursor to the end of the input
65
- document.getSelection().modify("move", "forward", "documentboundary");
66
-
105
+
106
+ // Restore cursor position
107
+ const newRange = document.createRange();
108
+ newRange.setStart(event.target.firstChild || event.target, Math.min(cursorOffset, this.content.length));
109
+ newRange.collapse(true);
110
+ selection.removeAllRanges();
111
+ selection.addRange(newRange);
67
112
  } else {
68
- this.content = event.target.innerText;
113
+ this.content = newText;
69
114
  this.$emit('update:lastCrumb', this.content);
70
115
  }
71
116
  }
@@ -27,6 +27,7 @@
27
27
  line-height: 1;
28
28
  border: 1px solid transparent;
29
29
  margin: -1px 0 0 -10px;
30
+ white-space: nowrap
30
31
  }
31
32
 
32
33
  .toggle-breadcrumb-editable-input:hover {