quasar-ui-danx 0.4.43 → 0.4.45
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/danx.es.js +5409 -5227
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +80 -80
- package/dist/danx.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/ActionTable/controls.ts +1 -1
- package/src/components/Utility/Buttons/ShowHideButton.vue +1 -1
- package/src/components/Utility/Files/FilePreview.vue +9 -3
- package/src/components/Utility/Widgets/LabelPillWidget.vue +40 -0
- package/src/components/Utility/Widgets/LabelValuePillWidget.vue +26 -0
- package/src/components/Utility/Widgets/index.ts +2 -0
- package/src/components/Utility/index.ts +1 -0
- package/src/helpers/array.ts +15 -15
- package/src/helpers/objectStore.ts +9 -7
- package/src/helpers/utils.ts +3 -0
- package/src/types/controls.d.ts +4 -2
- package/src/types/index.d.ts +1 -0
- package/src/types/widgets.d.ts +5 -0
package/package.json
CHANGED
@@ -115,7 +115,7 @@ export function useControls(name: string, options: ListControlsOptions): ListCon
|
|
115
115
|
* Loads the filter field options for the current filter.
|
116
116
|
*/
|
117
117
|
async function loadFieldOptions() {
|
118
|
-
if (!options.routes.fieldOptions || options.isFieldOptionsEnabled === false) return;
|
118
|
+
if (isLoadingFilters.value || !options.routes.fieldOptions || options.isFieldOptionsEnabled === false) return;
|
119
119
|
|
120
120
|
isLoadingFilters.value = true;
|
121
121
|
try {
|
@@ -138,7 +138,7 @@
|
|
138
138
|
<script setup lang="ts">
|
139
139
|
import { DocumentTextIcon as TextFileIcon, DownloadIcon, PlayIcon } from "@heroicons/vue/outline";
|
140
140
|
import { computed, ComputedRef, onMounted, ref } from "vue";
|
141
|
-
import { download, FileUpload } from "../../../helpers";
|
141
|
+
import { download, FileUpload, uniqueBy } from "../../../helpers";
|
142
142
|
import { ImageIcon, PdfIcon, TrashIcon as RemoveIcon } from "../../../svg";
|
143
143
|
import { UploadedFile } from "../../../types";
|
144
144
|
import { FullScreenCarouselDialog } from "../Dialogs";
|
@@ -202,10 +202,16 @@ const computedImage: ComputedRef<UploadedFile | null> = computed(() => {
|
|
202
202
|
});
|
203
203
|
|
204
204
|
const isUploading = computed(() => !props.file || props.file?.progress !== undefined);
|
205
|
-
const previewableFiles: ComputedRef<
|
206
|
-
return props.relatedFiles?.length > 0 ? props.relatedFiles : [computedImage.value];
|
205
|
+
const previewableFiles: ComputedRef<(UploadedFile | null)[] | null> = computed(() => {
|
206
|
+
return props.relatedFiles?.length > 0 ? uniqueBy([computedImage.value, ...props.relatedFiles], filesHaveSameUrl) : [computedImage.value];
|
207
207
|
});
|
208
208
|
|
209
|
+
function filesHaveSameUrl(a: UploadedFile, b: UploadedFile) {
|
210
|
+
return a.id === b.id ||
|
211
|
+
[b.url, b.optimized?.url, b.thumb?.url].includes(a.url) ||
|
212
|
+
[a.url, a.optimized?.url, a.thumb?.url].includes(b.url);
|
213
|
+
}
|
214
|
+
|
209
215
|
const filename = computed(() => computedImage.value?.name || computedImage.value?.filename || "");
|
210
216
|
const mimeType = computed(
|
211
217
|
() => computedImage.value?.type || computedImage.value?.mime || ""
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<template>
|
2
|
+
<div :class="{[colorClass]: true, [sizeClass]: true, 'rounded-full': true}">
|
3
|
+
<slot>{{ label }}</slot>
|
4
|
+
</div>
|
5
|
+
</template>
|
6
|
+
<script setup lang="ts">
|
7
|
+
import { computed } from "vue";
|
8
|
+
import { LabelPillWidgetProps } from "../../../types";
|
9
|
+
|
10
|
+
const props = withDefaults(defineProps<LabelPillWidgetProps>(), {
|
11
|
+
label: "",
|
12
|
+
color: "none",
|
13
|
+
size: "md"
|
14
|
+
});
|
15
|
+
|
16
|
+
const colorClasses = {
|
17
|
+
sky: "bg-sky-950 text-sky-400",
|
18
|
+
green: "bg-green-950 text-green-400",
|
19
|
+
red: "bg-red-950 text-red-400",
|
20
|
+
amber: "bg-amber-950 text-amber-400",
|
21
|
+
yellow: "bg-yellow-950 text-yellow-400",
|
22
|
+
blue: "bg-blue-950 text-blue-400",
|
23
|
+
slate: "bg-slate-950 text-slate-400",
|
24
|
+
gray: "bg-slate-700 text-gray-300",
|
25
|
+
none: ""
|
26
|
+
};
|
27
|
+
|
28
|
+
const sizeClasses = {
|
29
|
+
xxs: "text-xs px-1 py-.5",
|
30
|
+
xs: "text-xs px-2 py-1",
|
31
|
+
sm: "text-sm px-3 py-1.5",
|
32
|
+
md: "text-base px-3 py-2",
|
33
|
+
lg: "text-lg px-4 py-2"
|
34
|
+
};
|
35
|
+
|
36
|
+
const colorClass = computed(() => {
|
37
|
+
return colorClasses[props.color];
|
38
|
+
});
|
39
|
+
const sizeClass = computed(() => sizeClasses[props.size]);
|
40
|
+
</script>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<template>
|
2
|
+
<div class="flex items-stretch">
|
3
|
+
<div
|
4
|
+
class="rounded-l-lg bg-slate-400 text-slate-900 text-xs px-2 flex items-center justify-center"
|
5
|
+
:class="labelClass"
|
6
|
+
>
|
7
|
+
<slot name="label">
|
8
|
+
{{ label }}
|
9
|
+
</slot>
|
10
|
+
</div>
|
11
|
+
<div class="rounded-r-lg bg-slate-900 text-slate-400 px-2 py-1">
|
12
|
+
<slot name="value">
|
13
|
+
{{ value }}
|
14
|
+
</slot>
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
</template>
|
18
|
+
<script setup lang="ts">
|
19
|
+
withDefaults(defineProps<{
|
20
|
+
label: string;
|
21
|
+
value: string;
|
22
|
+
labelClass?: string;
|
23
|
+
}>(), {
|
24
|
+
labelClass: ""
|
25
|
+
});
|
26
|
+
</script>
|
package/src/helpers/array.ts
CHANGED
@@ -2,31 +2,31 @@
|
|
2
2
|
* Replace an item in an array with a new item
|
3
3
|
*/
|
4
4
|
export function replace(array: any[], item: any, newItem = undefined, appendIfMissing = false) {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
const index: any = typeof item === "function" ? array.findIndex(item) : array.indexOf(item);
|
6
|
+
if (index === false || index === -1) {
|
7
|
+
return appendIfMissing ? [...array, newItem] : array;
|
8
|
+
}
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
const newArray = [...array];
|
11
|
+
newItem !== undefined
|
12
|
+
? newArray.splice(index, 1, newItem)
|
13
|
+
: newArray.splice(index, 1);
|
14
|
+
return newArray;
|
15
15
|
}
|
16
16
|
|
17
17
|
/**
|
18
18
|
* Remove an item from an array
|
19
19
|
*/
|
20
20
|
export function remove(array: any[], item: any) {
|
21
|
-
|
21
|
+
return replace(array, item);
|
22
22
|
}
|
23
23
|
|
24
24
|
/**
|
25
25
|
* Remove duplicate items from an array using a callback to compare 2 elements
|
26
26
|
*/
|
27
|
-
export function uniqueBy(array: any[], cb:
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
export function uniqueBy(array: any[], cb: (a: any, b: any) => boolean) {
|
28
|
+
return array.filter((a, index, self) => {
|
29
|
+
// Check if the current element 'a' is the first occurrence in the array
|
30
|
+
return index === self.findIndex((b) => cb(a, b));
|
31
|
+
});
|
32
32
|
}
|
@@ -92,6 +92,7 @@ function storeObjectChildren<T extends TypedObject>(object: T, recentlyStoredObj
|
|
92
92
|
for (const index in value) {
|
93
93
|
if (value[index] && typeof value[index] === "object") {
|
94
94
|
if (!applyToObject[key]) {
|
95
|
+
// @ts-expect-error this is fine... T is generic, but not sure why the matter to write to an object?
|
95
96
|
applyToObject[key] = [];
|
96
97
|
}
|
97
98
|
applyToObject[key][index] = storeObject(value[index], recentlyStoredObjects);
|
@@ -128,7 +129,10 @@ function removeObjectFromLists<T extends TypedObject>(object: T) {
|
|
128
129
|
*/
|
129
130
|
const registeredAutoRefreshes: AnyObject = {};
|
130
131
|
|
131
|
-
export async function autoRefreshObject<T extends TypedObject>(object: T, condition: (object: T) => boolean, callback: (object: T) => Promise<T>, interval = 3000) {
|
132
|
+
export async function autoRefreshObject<T extends TypedObject>(name: string, object: T, condition: (object: T) => boolean, callback: (object: T) => Promise<T>, interval = 3000) {
|
133
|
+
// Always clear any previously registered auto refreshes before creating a new timeout
|
134
|
+
stopAutoRefreshObject(name);
|
135
|
+
|
132
136
|
if (!object?.id || !object?.__type) {
|
133
137
|
throw new Error("Invalid stored object. Cannot auto-refresh");
|
134
138
|
}
|
@@ -144,13 +148,11 @@ export async function autoRefreshObject<T extends TypedObject>(object: T, condit
|
|
144
148
|
storeObject(refreshedObject);
|
145
149
|
}
|
146
150
|
|
147
|
-
// Save the
|
148
|
-
|
149
|
-
registeredAutoRefreshes[object.__type + ":" + object.id] = timeoutId;
|
151
|
+
// Save the autoRefreshId for the object so it can be cleared when the object refresh is no longer needed
|
152
|
+
registeredAutoRefreshes[name] = setTimeout(() => autoRefreshObject(name, object, condition, callback, interval), interval);
|
150
153
|
}
|
151
154
|
|
152
|
-
export
|
153
|
-
const timeoutId = registeredAutoRefreshes[
|
154
|
-
|
155
|
+
export function stopAutoRefreshObject(name: string) {
|
156
|
+
const timeoutId = registeredAutoRefreshes[name];
|
155
157
|
timeoutId && clearTimeout(timeoutId);
|
156
158
|
}
|
package/src/helpers/utils.ts
CHANGED
@@ -33,6 +33,9 @@ export async function pollUntil(callback: () => any, interval = 1000) {
|
|
33
33
|
*/
|
34
34
|
export function waitForRef(ref: Ref, value: any) {
|
35
35
|
return new Promise<void>((resolve) => {
|
36
|
+
if (ref.value === value) {
|
37
|
+
resolve();
|
38
|
+
}
|
36
39
|
watch(ref, (newValue) => {
|
37
40
|
if (newValue === value) {
|
38
41
|
resolve();
|
package/src/types/controls.d.ts
CHANGED
@@ -31,7 +31,7 @@ export interface ListControlsRoutes<T = ActionTargetItem> {
|
|
31
31
|
|
32
32
|
fieldOptions?(options?: RequestCallOptions): Promise<AnyObject>;
|
33
33
|
|
34
|
-
applyAction?(action: string | ResourceAction | ActionOptions, target: T | null, data?: object, options?: RequestCallOptions): Promise<
|
34
|
+
applyAction?(action: string | ResourceAction | ActionOptions, target: T | null, data?: object, options?: RequestCallOptions): Promise<ApplyActionResponse>;
|
35
35
|
|
36
36
|
batchAction?(action: string | ResourceAction | ActionOptions, targets: T[], data: object, options?: RequestCallOptions): Promise<AnyObject>;
|
37
37
|
|
@@ -123,5 +123,7 @@ export interface ListController<T = ActionTargetItem> {
|
|
123
123
|
export interface ApplyActionResponse<T = ActionTargetItem> {
|
124
124
|
item?: T;
|
125
125
|
result?: T | AnyObject;
|
126
|
-
success
|
126
|
+
success?: boolean;
|
127
|
+
error?: boolean;
|
128
|
+
message?: string;
|
127
129
|
}
|
package/src/types/index.d.ts
CHANGED