toggle-components-library 1.37.0-beta.3 → 1.37.0-beta.5
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 +66 -24
- package/dist/toggle-components-library.common.js.map +1 -1
- package/dist/toggle-components-library.umd.js +66 -24
- 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 +68 -20
package/package.json
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
<div v-for="(crumb, index) in breadcrumb_computed" :key="index">
|
|
4
4
|
<template v-if="index === breadcrumb_computed.length - 1 && editable">
|
|
5
5
|
<span
|
|
6
|
+
ref="editableSpan"
|
|
6
7
|
contenteditable="true"
|
|
7
8
|
class="toggle-breadcrumb-editable-input"
|
|
8
|
-
@input="updateContent($event)
|
|
9
|
+
@input="updateContent($event)"
|
|
9
10
|
@keydown.enter.prevent="handleEnterKey"
|
|
10
11
|
@paste.prevent="handlePaste"
|
|
11
|
-
|
|
12
|
+
v-text="initialContent"
|
|
13
|
+
></span>
|
|
12
14
|
</template>
|
|
13
15
|
<template v-else>
|
|
14
16
|
<router-link :to="{ name: crumb.link}" class="back-product" v-if="crumb.link && !isNuxt">{{ crumb.name }}</router-link>
|
|
@@ -44,41 +46,86 @@ export default {
|
|
|
44
46
|
}
|
|
45
47
|
},
|
|
46
48
|
|
|
47
|
-
data
|
|
49
|
+
data() {
|
|
48
50
|
return {
|
|
49
|
-
content: ''
|
|
51
|
+
content: '',
|
|
52
|
+
initialContent: '',
|
|
53
|
+
lastSelection: null
|
|
50
54
|
};
|
|
51
55
|
},
|
|
52
56
|
|
|
53
57
|
computed: {
|
|
54
58
|
breadcrumb_computed() {
|
|
55
|
-
return this.isNuxt ? this.breadcrumb : this.$route.meta.breadcrumb
|
|
56
|
-
}
|
|
59
|
+
return this.isNuxt ? this.breadcrumb : this.$route.meta.breadcrumb;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
mounted() {
|
|
64
|
+
if (this.breadcrumb_computed && this.breadcrumb_computed.length > 0) {
|
|
65
|
+
const lastCrumb = this.breadcrumb_computed[this.breadcrumb_computed.length - 1];
|
|
66
|
+
this.content = lastCrumb.name;
|
|
67
|
+
this.initialContent = lastCrumb.name;
|
|
68
|
+
}
|
|
57
69
|
},
|
|
58
70
|
|
|
59
71
|
methods: {
|
|
72
|
+
saveSelection() {
|
|
73
|
+
if (window.getSelection) {
|
|
74
|
+
const sel = window.getSelection();
|
|
75
|
+
if (sel.getRangeAt && sel.rangeCount) {
|
|
76
|
+
const range = sel.getRangeAt(0);
|
|
77
|
+
this.lastSelection = {
|
|
78
|
+
start: range.startOffset,
|
|
79
|
+
end: range.endOffset
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
restoreSelection() {
|
|
86
|
+
if (!this.lastSelection || !this.$refs.editableSpan) return;
|
|
87
|
+
|
|
88
|
+
const el = this.$refs.editableSpan;
|
|
89
|
+
if (!el.firstChild && typeof el.textContent === 'string') {
|
|
90
|
+
el.textContent = this.content || '';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const range = document.createRange();
|
|
95
|
+
const sel = window.getSelection();
|
|
96
|
+
const textNode = el.firstChild || el;
|
|
97
|
+
|
|
98
|
+
// Ensure we don't exceed the text length
|
|
99
|
+
const start = Math.min(this.lastSelection.start, textNode.length);
|
|
100
|
+
const end = Math.min(this.lastSelection.end, textNode.length);
|
|
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);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
|
|
60
111
|
handlePaste(event) {
|
|
61
|
-
// Get plain text from clipboard and clean it
|
|
62
112
|
const text = (event.clipboardData || window.clipboardData).getData('text');
|
|
63
113
|
const cleanText = text.replace(/[\r\n\s]+/g, ' ').trim();
|
|
64
114
|
|
|
65
|
-
|
|
115
|
+
this.saveSelection();
|
|
66
116
|
const selection = window.getSelection();
|
|
67
117
|
const selectionLength = selection.toString().length;
|
|
68
118
|
const currentLength = this.content.length;
|
|
69
119
|
|
|
70
|
-
// Check if adding the pasted text would exceed maxChars
|
|
71
120
|
if (currentLength - selectionLength + cleanText.length <= this.maxChars && selection.rangeCount) {
|
|
72
121
|
const range = selection.getRangeAt(0);
|
|
73
122
|
range.deleteContents();
|
|
74
123
|
range.insertNode(document.createTextNode(cleanText));
|
|
75
124
|
|
|
76
|
-
// Move cursor to end of inserted text
|
|
77
125
|
range.collapse(false);
|
|
78
126
|
selection.removeAllRanges();
|
|
79
127
|
selection.addRange(range);
|
|
80
128
|
|
|
81
|
-
// Update content
|
|
82
129
|
this.content = event.target.innerText;
|
|
83
130
|
this.$emit('update:lastCrumb', this.content);
|
|
84
131
|
}
|
|
@@ -89,20 +136,21 @@ export default {
|
|
|
89
136
|
event.target.blur();
|
|
90
137
|
},
|
|
91
138
|
|
|
92
|
-
|
|
93
139
|
updateContent(event) {
|
|
94
|
-
|
|
95
|
-
|
|
140
|
+
this.saveSelection();
|
|
141
|
+
const newText = event.target.innerText;
|
|
142
|
+
|
|
143
|
+
if (newText.length > this.maxChars) {
|
|
96
144
|
event.target.innerText = this.content;
|
|
97
|
-
|
|
98
|
-
// Move the cursor to the end of the input
|
|
99
|
-
document.getSelection().modify("move", "forward", "documentboundary");
|
|
100
|
-
|
|
145
|
+
this.restoreSelection();
|
|
101
146
|
} else {
|
|
102
|
-
this.content =
|
|
147
|
+
this.content = newText;
|
|
103
148
|
this.$emit('update:lastCrumb', this.content);
|
|
149
|
+
this.$nextTick(() => {
|
|
150
|
+
this.restoreSelection();
|
|
151
|
+
});
|
|
104
152
|
}
|
|
105
153
|
}
|
|
106
154
|
}
|
|
107
|
-
}
|
|
155
|
+
};
|
|
108
156
|
</script>
|