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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quasar-ui-danx",
3
- "version": "0.4.43",
3
+ "version": "0.4.45",
4
4
  "author": "Dan <dan@flytedesk.com>",
5
5
  "description": "DanX Vue / Quasar component library",
6
6
  "license": "MIT",
@@ -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 {
@@ -41,7 +41,7 @@ export interface Props {
41
41
  hideIcon?: object | string;
42
42
  iconClass?: string;
43
43
  labelClass?: string;
44
- label?: string;
44
+ label?: string | number;
45
45
  tooltip?: string;
46
46
  disable?: boolean;
47
47
  }
@@ -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<[UploadedFile | null]> = computed(() => {
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>
@@ -0,0 +1,2 @@
1
+ export { default as LabelPillWidget } from "./LabelPillWidget.vue";
2
+ export { default as LabelValuePillWidget } from "./LabelValuePillWidget.vue";
@@ -8,3 +8,4 @@ export * from "./Popovers";
8
8
  export * from "./Tabs";
9
9
  export * from "./Tools";
10
10
  export * from "./Transitions";
11
+ export * from "./Widgets";
@@ -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
- 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
- }
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
- const newArray = [...array];
11
- newItem !== undefined
12
- ? newArray.splice(index, 1, newItem)
13
- : newArray.splice(index, 1);
14
- return newArray;
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
- return replace(array, item);
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: Function) {
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
- });
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 timeoutId to the object so it can be cleared when the object refresh is no longer needed
148
- const timeoutId = setTimeout(() => autoRefreshObject(object, condition, callback, interval), interval);
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 async function stopAutoRefreshObject<T extends TypedObject>(object: T) {
153
- const timeoutId = registeredAutoRefreshes[object.__type + ":" + object.id];
154
-
155
+ export function stopAutoRefreshObject(name: string) {
156
+ const timeoutId = registeredAutoRefreshes[name];
155
157
  timeoutId && clearTimeout(timeoutId);
156
158
  }
@@ -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();
@@ -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<AnyObject>;
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: boolean;
126
+ success?: boolean;
127
+ error?: boolean;
128
+ message?: string;
127
129
  }
@@ -12,5 +12,6 @@ export * from "./forms";
12
12
  export * from "./requests";
13
13
  export * from "./shared";
14
14
  export * from "./tables";
15
+ export * from "./widgets";
15
16
 
16
17
  export type DanxController<T = ActionTargetItem> = ActionController<T> & ListController<T>;
@@ -0,0 +1,5 @@
1
+ export interface LabelPillWidgetProps {
2
+ label?: string;
3
+ size?: "xs" | "sm" | "md" | "lg";
4
+ color?: "sky" | "green" | "red" | "amber" | "yellow" | "blue" | "slate" | "gray" | "none";
5
+ }