toggle-components-library 1.37.0-beta.5 → 1.37.0-beta.6
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/dist/toggle-components-library.common.js +65 -72
- package/dist/toggle-components-library.common.js.map +1 -1
- package/dist/toggle-components-library.umd.js +65 -72
- package/dist/toggle-components-library.umd.js.map +1 -1
- package/dist/toggle-components-library.umd.min.js +1 -1
- package/dist/toggle-components-library.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/breadcrumb/ToggleBreadCrumb.vue +63 -69
package/package.json
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
ref="editableSpan"
|
|
7
7
|
contenteditable="true"
|
|
8
8
|
class="toggle-breadcrumb-editable-input"
|
|
9
|
-
@input="
|
|
9
|
+
@input="handleInput"
|
|
10
|
+
@keypress="handleKeypress"
|
|
10
11
|
@keydown.enter.prevent="handleEnterKey"
|
|
11
12
|
@paste.prevent="handlePaste"
|
|
12
|
-
|
|
13
|
-
></span>
|
|
13
|
+
>{{ crumb.name }}</span>
|
|
14
14
|
</template>
|
|
15
15
|
<template v-else>
|
|
16
16
|
<router-link :to="{ name: crumb.link}" class="back-product" v-if="crumb.link && !isNuxt">{{ crumb.name }}</router-link>
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
|
|
25
25
|
<script>
|
|
26
26
|
export default {
|
|
27
|
-
mixins: [],
|
|
28
27
|
props: {
|
|
29
28
|
isNuxt: {
|
|
30
29
|
type: Boolean,
|
|
@@ -48,10 +47,8 @@ export default {
|
|
|
48
47
|
|
|
49
48
|
data() {
|
|
50
49
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
lastSelection: null
|
|
54
|
-
};
|
|
50
|
+
lastValidContent: ''
|
|
51
|
+
}
|
|
55
52
|
},
|
|
56
53
|
|
|
57
54
|
computed: {
|
|
@@ -61,96 +58,93 @@ export default {
|
|
|
61
58
|
},
|
|
62
59
|
|
|
63
60
|
mounted() {
|
|
64
|
-
|
|
65
|
-
const lastCrumb = this.breadcrumb_computed[this.breadcrumb_computed.length - 1];
|
|
66
|
-
this.content = lastCrumb.name;
|
|
67
|
-
this.initialContent = lastCrumb.name;
|
|
68
|
-
}
|
|
61
|
+
this.updateContent();
|
|
69
62
|
},
|
|
70
63
|
|
|
71
64
|
methods: {
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
start: range.startOffset,
|
|
79
|
-
end: range.endOffset
|
|
80
|
-
};
|
|
65
|
+
updateContent() {
|
|
66
|
+
if (this.$refs.editableSpan && this.breadcrumb_computed?.length) {
|
|
67
|
+
const lastCrumb = this.breadcrumb_computed[this.breadcrumb_computed.length - 1];
|
|
68
|
+
if (this.$refs.editableSpan.textContent !== lastCrumb.name) {
|
|
69
|
+
this.$refs.editableSpan.textContent = lastCrumb.name;
|
|
70
|
+
this.lastValidContent = lastCrumb.name;
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
73
|
},
|
|
84
74
|
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
75
|
+
handleKeypress(event) {
|
|
76
|
+
if (event.key.length !== 1) return;
|
|
77
|
+
|
|
78
|
+
const currentLength = this.$refs.editableSpan.textContent.length;
|
|
79
|
+
const selection = window.getSelection();
|
|
80
|
+
const selectedLength = selection.toString().length;
|
|
81
|
+
|
|
82
|
+
if (currentLength - selectedLength >= this.maxChars) {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
return false;
|
|
91
85
|
}
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
handleInput(event) {
|
|
89
|
+
const newText = event.target.textContent;
|
|
92
90
|
|
|
93
|
-
|
|
91
|
+
if (newText.length <= this.maxChars) {
|
|
92
|
+
this.lastValidContent = newText;
|
|
93
|
+
this.$emit('update:lastCrumb', newText);
|
|
94
|
+
} else {
|
|
95
|
+
// Get cursor position before restoring text
|
|
96
|
+
const selection = window.getSelection();
|
|
97
|
+
const cursorPosition = selection.getRangeAt(0).startOffset;
|
|
98
|
+
|
|
99
|
+
// Restore previous content
|
|
100
|
+
event.target.textContent = this.lastValidContent;
|
|
101
|
+
|
|
102
|
+
// Restore cursor position
|
|
94
103
|
const range = document.createRange();
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
range.setStart(textNode, start);
|
|
103
|
-
range.setEnd(textNode, end);
|
|
104
|
-
sel.removeAllRanges();
|
|
105
|
-
sel.addRange(range);
|
|
106
|
-
} catch (e) {
|
|
107
|
-
console.warn('Failed to restore selection:', e);
|
|
104
|
+
const textNode = event.target.firstChild;
|
|
105
|
+
if (textNode) {
|
|
106
|
+
range.setStart(textNode, Math.min(cursorPosition, this.lastValidContent.length));
|
|
107
|
+
range.collapse(true);
|
|
108
|
+
selection.removeAllRanges();
|
|
109
|
+
selection.addRange(range);
|
|
110
|
+
}
|
|
108
111
|
}
|
|
109
112
|
},
|
|
110
113
|
|
|
111
114
|
handlePaste(event) {
|
|
115
|
+
event.preventDefault();
|
|
112
116
|
const text = (event.clipboardData || window.clipboardData).getData('text');
|
|
113
117
|
const cleanText = text.replace(/[\r\n\s]+/g, ' ').trim();
|
|
114
118
|
|
|
115
|
-
this.saveSelection();
|
|
116
119
|
const selection = window.getSelection();
|
|
120
|
+
const range = selection.getRangeAt(0);
|
|
121
|
+
const currentLength = this.$refs.editableSpan.textContent.length;
|
|
117
122
|
const selectionLength = selection.toString().length;
|
|
118
|
-
const currentLength = this.content.length;
|
|
119
123
|
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
const availableSpace = this.maxChars - (currentLength - selectionLength);
|
|
125
|
+
if (availableSpace > 0) {
|
|
126
|
+
const truncatedText = cleanText.slice(0, availableSpace);
|
|
122
127
|
range.deleteContents();
|
|
123
|
-
range.insertNode(document.createTextNode(
|
|
124
|
-
|
|
128
|
+
range.insertNode(document.createTextNode(truncatedText));
|
|
125
129
|
range.collapse(false);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.content = event.target.innerText;
|
|
130
|
-
this.$emit('update:lastCrumb', this.content);
|
|
130
|
+
this.lastValidContent = this.$refs.editableSpan.textContent;
|
|
131
|
+
this.$emit('update:lastCrumb', this.lastValidContent);
|
|
131
132
|
}
|
|
132
133
|
},
|
|
133
134
|
|
|
134
135
|
handleEnterKey(event) {
|
|
135
136
|
event.preventDefault();
|
|
136
137
|
event.target.blur();
|
|
137
|
-
}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
138
140
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.restoreSelection();
|
|
146
|
-
} else {
|
|
147
|
-
this.content = newText;
|
|
148
|
-
this.$emit('update:lastCrumb', this.content);
|
|
149
|
-
this.$nextTick(() => {
|
|
150
|
-
this.restoreSelection();
|
|
151
|
-
});
|
|
152
|
-
}
|
|
141
|
+
watch: {
|
|
142
|
+
'breadcrumb_computed': {
|
|
143
|
+
handler() {
|
|
144
|
+
this.$nextTick(this.updateContent);
|
|
145
|
+
},
|
|
146
|
+
deep: true
|
|
153
147
|
}
|
|
154
148
|
}
|
|
155
|
-
}
|
|
149
|
+
}
|
|
156
150
|
</script>
|