toggle-components-library 1.37.0-beta.1 → 1.37.0-beta.3

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.1",
3
+ "version": "1.37.0-beta.3",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#abb7c5"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>
@@ -2,12 +2,13 @@
2
2
  <div class="toggle-breadcrumb" v-if="breadcrumb_computed">
3
3
  <div v-for="(crumb, index) in breadcrumb_computed" :key="index">
4
4
  <template v-if="index === breadcrumb_computed.length - 1 && editable">
5
- <input
5
+ <span
6
+ contenteditable="true"
6
7
  class="toggle-breadcrumb-editable-input"
7
- v-model="crumb.name"
8
- maxlength="50"
9
- @input="autoResizeInput($event.target); updateContent($event);"
10
- />
8
+ @input="updateContent($event);"
9
+ @keydown.enter.prevent="handleEnterKey"
10
+ @paste.prevent="handlePaste"
11
+ >{{ crumb.name }}</span>
11
12
  </template>
12
13
  <template v-else>
13
14
  <router-link :to="{ name: crumb.link}" class="back-product" v-if="crumb.link && !isNuxt">{{ crumb.name }}</router-link>
@@ -33,12 +34,20 @@ export default {
33
34
  },
34
35
  editable: {
35
36
  type: Boolean,
36
- default: false
37
+ default: false,
38
+ required: false
39
+ },
40
+ maxChars: {
41
+ type: Number,
42
+ default: 50,
43
+ required: false
37
44
  }
38
45
  },
39
46
 
40
47
  data: function () {
41
- return {};
48
+ return {
49
+ content: ''
50
+ };
42
51
  },
43
52
 
44
53
  computed: {
@@ -48,12 +57,51 @@ export default {
48
57
  },
49
58
 
50
59
  methods: {
51
- autoResizeInput(input) {
52
- input.style.width = input.value.length * 11 + "px";
53
- },
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
+ },
91
+
92
+
54
93
  updateContent(event) {
55
- const newContent = event.target.value;
56
- this.$emit('update:lastCrumb', newContent);
94
+ // Limit the input to 50 characters
95
+ if (event.target.innerText.length >= this.maxChars) {
96
+ event.target.innerText = this.content;
97
+
98
+ // Move the cursor to the end of the input
99
+ document.getSelection().modify("move", "forward", "documentboundary");
100
+
101
+ } else {
102
+ this.content = event.target.innerText;
103
+ this.$emit('update:lastCrumb', this.content);
104
+ }
57
105
  }
58
106
  }
59
107
  }
@@ -17,19 +17,19 @@
17
17
  background-color: transparent;
18
18
  display: inline-flex;
19
19
  align-items: center;
20
- min-width: 10rem !important;
21
- max-width: 31rem !important;
20
+ min-width: 5rem !important;
22
21
  height: 2rem;
23
- width: 15rem;
24
22
  padding-right: 0.5rem;
23
+ padding-left: 10px;
25
24
  border: none;
26
25
  border-radius: 4px;
27
26
  white-space: nowrap;
28
- overflow: hidden;
29
27
  line-height: 1;
30
28
  border: 1px solid transparent;
31
- margin: -1px 0 0 0;
29
+ margin: -1px 0 0 -10px;
30
+ white-space: nowrap
32
31
  }
32
+
33
33
  .toggle-breadcrumb-editable-input:hover {
34
34
  border: 1px solid #ccc;
35
35
  background-color: $toggle-off-white;
@@ -37,9 +37,20 @@
37
37
 
38
38
  .toggle-breadcrumb-editable-input:focus {
39
39
  border: 1px solid #ccc;
40
+ background-color: $toggle-off-white;
40
41
  outline: none;
41
42
  }
42
43
 
44
+ .toggle-breadcrumb-editable-input::after {
45
+ content: '';
46
+ background-image: url('../assets/icons/edit-icon.svg');
47
+ background-repeat:no-repeat;
48
+ background-size:contain;
49
+ height: 22px;
50
+ width: 22px;
51
+ margin: 0 0 0 10px;
52
+ cursor: text;
53
+ }
43
54
 
44
55
  a {
45
56