quasar-ui-danx 0.4.27 → 0.4.29
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/README.md +35 -35
- package/dist/danx.es.js +24686 -24119
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +109 -109
- package/dist/danx.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/ActionTable/ActionTable.vue +29 -7
- package/src/components/ActionTable/Filters/FilterableField.vue +14 -2
- package/src/components/ActionTable/Form/ActionForm.vue +17 -12
- package/src/components/ActionTable/Form/Fields/DateField.vue +24 -20
- package/src/components/ActionTable/Form/Fields/DateRangeField.vue +57 -53
- package/src/components/ActionTable/Form/Fields/EditOnClickTextField.vue +9 -2
- package/src/components/ActionTable/Form/Fields/EditableDiv.vue +51 -21
- package/src/components/ActionTable/Form/Fields/FieldLabel.vue +1 -1
- package/src/components/ActionTable/Form/Fields/SelectField.vue +27 -6
- package/src/components/ActionTable/Form/Fields/SelectOrCreateField.vue +56 -0
- package/src/components/ActionTable/Form/Fields/TextField.vue +2 -0
- package/src/components/ActionTable/Form/Fields/index.ts +1 -0
- package/src/components/ActionTable/Form/RenderedForm.vue +7 -20
- package/src/components/ActionTable/Form/Utilities/MaxLengthCounter.vue +1 -1
- package/src/components/ActionTable/Form/Utilities/SaveStateIndicator.vue +37 -0
- package/src/components/ActionTable/Form/Utilities/index.ts +1 -0
- package/src/components/ActionTable/Layouts/ActionTableLayout.vue +20 -23
- package/src/components/ActionTable/Toolbars/ActionToolbar.vue +44 -36
- package/src/components/ActionTable/{listControls.ts → controls.ts} +13 -9
- package/src/components/ActionTable/index.ts +1 -1
- package/src/components/DragAndDrop/ListItemDraggable.vue +45 -31
- package/src/components/DragAndDrop/dragAndDrop.ts +221 -220
- package/src/components/DragAndDrop/listDragAndDrop.ts +269 -227
- package/src/components/PanelsDrawer/PanelsDrawer.vue +7 -7
- package/src/components/PanelsDrawer/PanelsDrawerTabs.vue +3 -3
- package/src/components/Utility/Buttons/ShowHideButton.vue +86 -0
- package/src/components/Utility/Buttons/index.ts +1 -0
- package/src/components/Utility/Dialogs/ActionFormDialog.vue +30 -0
- package/src/components/Utility/Dialogs/CreateNewWithNameDialog.vue +26 -0
- package/src/components/Utility/Dialogs/RenderedFormDialog.vue +50 -0
- package/src/components/Utility/Dialogs/index.ts +3 -0
- package/src/helpers/FileUpload.ts +4 -4
- package/src/helpers/actions.ts +84 -20
- package/src/helpers/files.ts +56 -43
- package/src/helpers/formats.ts +23 -20
- package/src/helpers/objectStore.ts +24 -12
- package/src/types/actions.d.ts +50 -26
- package/src/types/controls.d.ts +23 -25
- package/src/types/fields.d.ts +1 -0
- package/src/types/files.d.ts +2 -2
- package/src/types/index.d.ts +5 -0
- package/src/types/shared.d.ts +9 -0
- package/src/types/tables.d.ts +3 -3
- package/types/vue-shims.d.ts +3 -2
@@ -7,231 +7,273 @@ import { DragAndDrop } from "./dragAndDrop";
|
|
7
7
|
* @class
|
8
8
|
*/
|
9
9
|
export class ListDragAndDrop extends DragAndDrop {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
10
|
+
listPosition = 0;
|
11
|
+
cursorPosition = 0;
|
12
|
+
initialPosition = 0;
|
13
|
+
initialDropZone: HTMLElement | null = null;
|
14
|
+
onPositionChangeCb = null;
|
15
|
+
onDragPositionChangeCb = null;
|
16
|
+
onDropZoneChangeCb = null;
|
17
|
+
placeholder = null;
|
18
|
+
|
19
|
+
constructor(options = {}) {
|
20
|
+
super({
|
21
|
+
showPlaceholder: true,
|
22
|
+
allowDropZoneChange: true,
|
23
|
+
...options
|
24
|
+
});
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Callback that fires after dragging has ended and the list position has changed from the original
|
29
|
+
*/
|
30
|
+
onPositionChange(cb): ListDragAndDrop {
|
31
|
+
this.onPositionChangeCb = cb;
|
32
|
+
return this;
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Callback that fires when the drop zone has changed
|
37
|
+
*/
|
38
|
+
onDropZoneChange(cb): ListDragAndDrop {
|
39
|
+
this.onDropZoneChangeCb = cb;
|
40
|
+
return this;
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Callback that fires while dragging the element when the cursor's position has changed in the list
|
45
|
+
* @param cb
|
46
|
+
* @returns {ListDragAndDrop}
|
47
|
+
*/
|
48
|
+
onDragPositionChange(cb) {
|
49
|
+
this.onDragPositionChangeCb = cb;
|
50
|
+
return this;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Start listening for drag events and prepare an element for drag/drop
|
55
|
+
* @param e
|
56
|
+
* @param data
|
57
|
+
*/
|
58
|
+
dragStart(e, data) {
|
59
|
+
super.dragStart(e, data);
|
60
|
+
|
61
|
+
if (this.currentDropZone) {
|
62
|
+
this.listPosition = this.getListPosition(e.target);
|
63
|
+
this.initialPosition = this.listPosition;
|
64
|
+
this.initialDropZone = this.currentDropZone;
|
65
|
+
this.updateScrollPosition();
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* When dragging has ended, check for list position changes and fire the onPositionChange callback if it has
|
71
|
+
*/
|
72
|
+
dragEnd(e) {
|
73
|
+
const draggableData = this.draggableData;
|
74
|
+
this.placeholder?.remove();
|
75
|
+
const newDropZone = this.currentDropZone;
|
76
|
+
super.dragEnd(e);
|
77
|
+
|
78
|
+
// If the list drop zone has changed, trigger the callback for drop zone change
|
79
|
+
if (newDropZone && newDropZone !== this.initialDropZone) {
|
80
|
+
this.onDropZoneChangeCb && this.onDropZoneChangeCb(e, newDropZone, this.listPosition, this.initialPosition, draggableData);
|
81
|
+
} else if (this.listPosition !== this.initialPosition) {
|
82
|
+
// If our list position has changed, trigger the position change callback
|
83
|
+
this.onPositionChangeCb &&
|
84
|
+
this.onPositionChangeCb(this.listPosition, this.initialPosition, draggableData);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* The dragging element is moving
|
90
|
+
* @param e
|
91
|
+
*/
|
92
|
+
dragOver(e) {
|
93
|
+
super.dragOver(e);
|
94
|
+
this.updateListPosition(e);
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Notify if the targeted position of the cursor is different from the current position
|
99
|
+
* @param e
|
100
|
+
*/
|
101
|
+
updateListPosition(e: MouseEvent) {
|
102
|
+
const point = {
|
103
|
+
x: e.clientX,
|
104
|
+
y: e.clientY
|
105
|
+
};
|
106
|
+
const newDropZone = this.getDropZoneForTarget(e.target as HTMLElement);
|
107
|
+
if (newDropZone !== this.currentDropZone) {
|
108
|
+
this.currentDropZone = newDropZone;
|
109
|
+
this.cursorPosition = 0;
|
110
|
+
this.listPosition = 0;
|
111
|
+
this.placeholder?.remove();
|
112
|
+
}
|
113
|
+
|
114
|
+
const prevPosition = this.listPosition;
|
115
|
+
const newPosition = this.getListPositionOfPoint(point);
|
116
|
+
|
117
|
+
// If the cursor position has changed, we should update the rendering and see if our actual list position has
|
118
|
+
// changed
|
119
|
+
if (this.cursorPosition !== newPosition) {
|
120
|
+
this.cursorPosition = newPosition;
|
121
|
+
this.listPosition =
|
122
|
+
this.initialPosition < this.cursorPosition
|
123
|
+
? this.cursorPosition - 1
|
124
|
+
: this.cursorPosition;
|
125
|
+
if (this.options.showPlaceholder) {
|
126
|
+
this.renderPlaceholder();
|
127
|
+
}
|
128
|
+
|
129
|
+
// The position has changed, trigger the callback
|
130
|
+
if (this.listPosition !== prevPosition) {
|
131
|
+
this.onDragPositionChangeCb &&
|
132
|
+
this.onDragPositionChangeCb(this.listPosition, this.draggableData);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Find the numeric position of the element in the children of the list
|
139
|
+
* @returns {Number|null}
|
140
|
+
* @param item
|
141
|
+
*/
|
142
|
+
getListPosition(item) {
|
143
|
+
let index = 0;
|
144
|
+
for (const child of this.getChildren()) {
|
145
|
+
if (child === item) {
|
146
|
+
return index;
|
147
|
+
}
|
148
|
+
index++;
|
149
|
+
}
|
150
|
+
|
151
|
+
return null;
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Get all the children of the current drop zone, excluding the placeholder
|
156
|
+
* @returns {*}
|
157
|
+
*/
|
158
|
+
getChildren() {
|
159
|
+
return [...(this.currentDropZone?.children || [])].filter(
|
160
|
+
(c) => c.className.match(/dx-drag-placeholder/) === null
|
161
|
+
);
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Get the list element that is the parent of the target element
|
166
|
+
*/
|
167
|
+
getDropZoneForTarget(target: HTMLElement): HTMLElement | null {
|
168
|
+
return target.closest(`[data-drop-zone]`);
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Check if the current drop zone is the same as the initial drop zone
|
173
|
+
*/
|
174
|
+
isSameDropZone() {
|
175
|
+
return this.currentDropZone === this.initialDropZone;
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Find the element at the current cursor position in the given drop zone
|
180
|
+
* @param point
|
181
|
+
* @returns {null}
|
182
|
+
*/
|
183
|
+
getListPositionOfPoint(point) {
|
184
|
+
let index = 0;
|
185
|
+
const children = this.getChildren();
|
186
|
+
|
187
|
+
while (index < children.length) {
|
188
|
+
const rect = children[index].getBoundingClientRect();
|
189
|
+
if (this.isVertical()) {
|
190
|
+
if (point.y < rect.top + rect.height / 2) {
|
191
|
+
break;
|
192
|
+
}
|
193
|
+
} else {
|
194
|
+
if (point.x < rect.left + rect.width / 2) {
|
195
|
+
break;
|
196
|
+
}
|
197
|
+
}
|
198
|
+
index++;
|
199
|
+
}
|
200
|
+
|
201
|
+
return index;
|
202
|
+
}
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Updates the scroll position while dragging an element so a user can navigate a longer list while dragging
|
206
|
+
*/
|
207
|
+
updateScrollPosition() {
|
208
|
+
if (this.currentDropZone) {
|
209
|
+
const rect = this.currentDropZone.getBoundingClientRect();
|
210
|
+
const threshold = 100;
|
211
|
+
let velocity = 0;
|
212
|
+
const velocityFn = (x) => x * 5;
|
213
|
+
const cursorPos = this.isVertical() ? this.cursorY : this.cursorX;
|
214
|
+
const rectStart = this.isVertical() ? rect.top : rect.left;
|
215
|
+
const rectEnd = this.isVertical() ? rect.bottom : rect.right;
|
216
|
+
const beforeDiff = rectStart + threshold - cursorPos;
|
217
|
+
const afterDiff = cursorPos - (rectEnd - threshold);
|
218
|
+
|
219
|
+
if (beforeDiff > 0) {
|
220
|
+
velocity = -velocityFn(beforeDiff);
|
221
|
+
} else if (afterDiff > 0) {
|
222
|
+
velocity = velocityFn(afterDiff);
|
223
|
+
}
|
224
|
+
|
225
|
+
if (velocity) {
|
226
|
+
if (this.isVertical()) {
|
227
|
+
this.currentDropZone.scrollTo({
|
228
|
+
top: this.currentDropZone.scrollTop + velocity,
|
229
|
+
behavior: "smooth"
|
230
|
+
});
|
231
|
+
} else {
|
232
|
+
this.currentDropZone.scrollTo({
|
233
|
+
left: this.currentDropZone.scrollLeft + velocity,
|
234
|
+
behavior: "smooth"
|
235
|
+
});
|
236
|
+
}
|
237
|
+
}
|
238
|
+
|
239
|
+
setTimeout(() => this.updateScrollPosition(), 500);
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
/**
|
244
|
+
* Render a placeholder element at the given position (in between the elements)
|
245
|
+
*/
|
246
|
+
renderPlaceholder() {
|
247
|
+
// If we're not allowed to change drop zones and we're not in the same drop zone, don't render the placeholder
|
248
|
+
if (!this.options.allowDropZoneChange && !this.isSameDropZone()) {
|
249
|
+
return;
|
250
|
+
}
|
251
|
+
|
252
|
+
if (!this.placeholder) {
|
253
|
+
this.placeholder = document.createElement("div");
|
254
|
+
this.placeholder.classList.add("dx-drag-placeholder");
|
255
|
+
}
|
256
|
+
|
257
|
+
// Make sure the placeholder is oriented correctly
|
258
|
+
if (this.isVertical()) {
|
259
|
+
this.placeholder.classList.add("dx-direction-vertical");
|
260
|
+
this.placeholder.classList.remove("dx-direction-horizontal");
|
261
|
+
this.placeholder.style.height = undefined;
|
262
|
+
} else {
|
263
|
+
this.placeholder.classList.add("dx-direction-horizontal");
|
264
|
+
this.placeholder.classList.remove("dx-direction-vertical");
|
265
|
+
this.placeholder.style.height =
|
266
|
+
this.currentDropZone.getBoundingClientRect().height + "px";
|
267
|
+
}
|
268
|
+
|
269
|
+
const children = this.getChildren();
|
270
|
+
if (this.cursorPosition < children.length) {
|
271
|
+
this.currentDropZone.insertBefore(
|
272
|
+
this.placeholder,
|
273
|
+
children[this.cursorPosition]
|
274
|
+
);
|
275
|
+
} else {
|
276
|
+
this.currentDropZone.appendChild(this.placeholder);
|
277
|
+
}
|
278
|
+
}
|
237
279
|
}
|
@@ -16,7 +16,7 @@
|
|
16
16
|
<h2 v-if="title">
|
17
17
|
{{ title }}
|
18
18
|
</h2>
|
19
|
-
<div v-if="!
|
19
|
+
<div v-if="!target">
|
20
20
|
Loading
|
21
21
|
<QSpinnerHourglass />
|
22
22
|
</div>
|
@@ -39,22 +39,22 @@
|
|
39
39
|
</div>
|
40
40
|
<div class="dx-panels-drawer-body flex-grow overflow-hidden h-full">
|
41
41
|
<div
|
42
|
-
v-if="
|
42
|
+
v-if="target.__timestamp > 0"
|
43
43
|
class="flex items-stretch flex-nowrap h-full"
|
44
44
|
>
|
45
45
|
<PanelsDrawerTabs
|
46
|
-
:key="'pd-tabs:' +
|
46
|
+
:key="'pd-tabs:' + target.id"
|
47
47
|
v-model="activePanel"
|
48
|
-
:
|
48
|
+
:target="target"
|
49
49
|
:class="tabsClass"
|
50
50
|
:panels="panels"
|
51
51
|
@update:model-value="$emit('update:model-value', $event)"
|
52
52
|
/>
|
53
53
|
<PanelsDrawerPanels
|
54
|
-
:key="'pd-panels:' +
|
54
|
+
:key="'pd-panels:' + target.id"
|
55
55
|
:panels="panels"
|
56
56
|
:active-panel="activePanel"
|
57
|
-
:active-item="
|
57
|
+
:active-item="target"
|
58
58
|
:class="activePanelOptions?.class || panelsClass"
|
59
59
|
/>
|
60
60
|
<div
|
@@ -79,7 +79,7 @@ import PanelsDrawerTabs from "./PanelsDrawerTabs";
|
|
79
79
|
export interface Props {
|
80
80
|
title?: string,
|
81
81
|
modelValue?: string | number,
|
82
|
-
|
82
|
+
target: ActionTargetItem;
|
83
83
|
tabsClass?: string | object,
|
84
84
|
panelsClass?: string | object,
|
85
85
|
position?: "standard" | "right" | "left";
|
@@ -13,7 +13,7 @@
|
|
13
13
|
<RenderVnode
|
14
14
|
v-if="panel.tabVnode"
|
15
15
|
:key="panel.name"
|
16
|
-
:vnode="panel.tabVnode(
|
16
|
+
:vnode="panel.tabVnode(target, modelValue)"
|
17
17
|
:is-active="modelValue === panel.name"
|
18
18
|
:name="panel.name"
|
19
19
|
:label="panel.label"
|
@@ -37,7 +37,7 @@ defineEmits(["update:model-value"]);
|
|
37
37
|
|
38
38
|
interface Props {
|
39
39
|
modelValue?: string | number;
|
40
|
-
|
40
|
+
target: ActionTargetItem;
|
41
41
|
panels: ActionPanel[];
|
42
42
|
}
|
43
43
|
|
@@ -51,7 +51,7 @@ function isEnabled(panel) {
|
|
51
51
|
if (!panel.enabled) return false;
|
52
52
|
|
53
53
|
if (typeof panel.enabled === "function") {
|
54
|
-
return panel.enabled(props.
|
54
|
+
return panel.enabled(props.target);
|
55
55
|
}
|
56
56
|
|
57
57
|
return true;
|
@@ -0,0 +1,86 @@
|
|
1
|
+
<template>
|
2
|
+
<QBtn
|
3
|
+
class="py-1 px-2"
|
4
|
+
:disable="disable"
|
5
|
+
@click="onToggle"
|
6
|
+
>
|
7
|
+
<div class="flex items-center flex-nowrap whitespace-nowrap">
|
8
|
+
<slot :is-showing="isShowing">
|
9
|
+
<component
|
10
|
+
:is="isShowing ? (hideIcon || DefaultHideIcon) : (showIcon || DefaultShowIcon)"
|
11
|
+
:class="iconClass"
|
12
|
+
/>
|
13
|
+
<div
|
14
|
+
v-if="label"
|
15
|
+
:class="labelClass"
|
16
|
+
>
|
17
|
+
{{ (isShowing ? hideLabel : showLabel) || label }}
|
18
|
+
</div>
|
19
|
+
</slot>
|
20
|
+
</div>
|
21
|
+
<QTooltip v-if="tooltip">
|
22
|
+
{{ tooltip }}
|
23
|
+
</QTooltip>
|
24
|
+
</QBtn>
|
25
|
+
</template>
|
26
|
+
<script lang="ts" setup>
|
27
|
+
import { FaSolidEye as DefaultShowIcon, FaSolidEyeSlash as DefaultHideIcon } from "danx-icon";
|
28
|
+
import { nextTick } from "vue";
|
29
|
+
import { getItem, setItem } from "../../../helpers";
|
30
|
+
|
31
|
+
export interface Props {
|
32
|
+
name?: string;
|
33
|
+
showLabel?: string;
|
34
|
+
hideLabel?: string;
|
35
|
+
showIcon?: object | string;
|
36
|
+
hideIcon?: object | string;
|
37
|
+
iconClass?: string;
|
38
|
+
labelClass?: string;
|
39
|
+
label?: string;
|
40
|
+
tooltip?: string;
|
41
|
+
disable?: boolean;
|
42
|
+
}
|
43
|
+
|
44
|
+
const emit = defineEmits(["show", "hide"]);
|
45
|
+
const isShowing = defineModel<boolean>();
|
46
|
+
const props = withDefaults(defineProps<Props>(), {
|
47
|
+
name: "",
|
48
|
+
showLabel: "",
|
49
|
+
hideLabel: "",
|
50
|
+
showIcon: null,
|
51
|
+
hideIcon: null,
|
52
|
+
iconClass: "w-4 h-6",
|
53
|
+
labelClass: "ml-2",
|
54
|
+
label: "",
|
55
|
+
tooltip: ""
|
56
|
+
});
|
57
|
+
|
58
|
+
const SETTINGS_KEY = "show-hide-button";
|
59
|
+
const settings = getItem(SETTINGS_KEY, {});
|
60
|
+
|
61
|
+
if (props.name) {
|
62
|
+
if (settings[props.name] !== undefined) {
|
63
|
+
isShowing.value = settings[props.name];
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
function onToggle() {
|
68
|
+
isShowing.value = !isShowing.value;
|
69
|
+
|
70
|
+
|
71
|
+
// NOTE: use nextTick to ensure the value is updated before saving (if the parent does not pass a value for modelValue, this can cause a desync)
|
72
|
+
nextTick(() => {
|
73
|
+
if (isShowing.value) {
|
74
|
+
emit("show");
|
75
|
+
} else {
|
76
|
+
emit("hide");
|
77
|
+
}
|
78
|
+
|
79
|
+
if (props.name) {
|
80
|
+
settings[props.name] = isShowing.value;
|
81
|
+
setItem(SETTINGS_KEY, { ...getItem(SETTINGS_KEY, {}), [props.name]: isShowing.value });
|
82
|
+
}
|
83
|
+
});
|
84
|
+
}
|
85
|
+
|
86
|
+
</script>
|