@v1nt1248/3nclient-lib 0.3.14 → 0.3.16

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.
@@ -1,3 +1,4 @@
1
+ import { VNode } from 'vue';
1
2
  export interface Ui3nInputFileProps {
2
3
  /**
3
4
  * Selected files
@@ -40,3 +41,9 @@ export interface Ui3nInputFileEmits {
40
41
  */
41
42
  (event: 'error', value: string): void;
42
43
  }
44
+ export interface Ui3nInputFileSlots {
45
+ /**
46
+ * Default slot
47
+ */
48
+ default: () => VNode;
49
+ }
@@ -1,5 +1,14 @@
1
- import { Ui3nInputFileProps } from './types';
2
- declare const _default: import('vue').DefineComponent<Ui3nInputFileProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
1
+ import { Ui3nInputFileProps, Ui3nInputFileSlots } from './types';
2
+ declare function __VLS_template(): {
3
+ attrs: Partial<{}>;
4
+ slots: Readonly<Ui3nInputFileSlots> & Ui3nInputFileSlots;
5
+ refs: {
6
+ fileInput: HTMLInputElement;
7
+ };
8
+ rootEl: HTMLDivElement;
9
+ };
10
+ type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
11
+ declare const __VLS_component: import('vue').DefineComponent<Ui3nInputFileProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
3
12
  error: (value: string) => any;
4
13
  "update:modelValue": (value: FileList | File[]) => any;
5
14
  }, string, import('vue').PublicProps, Readonly<Ui3nInputFileProps> & Readonly<{
@@ -12,4 +21,10 @@ declare const _default: import('vue').DefineComponent<Ui3nInputFileProps, {}, {}
12
21
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
13
22
  fileInput: HTMLInputElement;
14
23
  }, HTMLDivElement>;
24
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
15
25
  export default _default;
26
+ type __VLS_WithTemplateSlots<T, S> = T & {
27
+ new (): {
28
+ $slots: S;
29
+ };
30
+ };
@@ -18089,23 +18089,23 @@ var Wo = {
18089
18089
  function o(e) {
18090
18090
  n.disabled || (e.stopImmediatePropagation(), a.value?.click());
18091
18091
  }
18092
- function l(e) {
18092
+ function u(e) {
18093
18093
  if (!e) return !1;
18094
18094
  if (!n.maxFileSize) return !0;
18095
18095
  let { name: t, size: i } = e;
18096
18096
  return i > n.maxFileSize ? (r("error", `The [${t}] file is too big. Maximum file size ${co(n.maxFileSize)}`), !1) : !0;
18097
18097
  }
18098
- function u(e) {
18098
+ function d(e) {
18099
18099
  if (!e) return !1;
18100
18100
  let { name: t } = e, i = `.${(0, Ts.default)(t.split("."))}`.toLowerCase(), a = n.allowedFileTypes.split(",").map((e) => (0, Es.default)(e).toLowerCase()), o = a.includes("*") || a.includes(i);
18101
18101
  return o || r("error", `The [${t}] file type is not valid.`), o;
18102
18102
  }
18103
- function d(e) {
18103
+ function f(e) {
18104
18104
  if (!e) return !1;
18105
18105
  let { name: t } = e, i = [...n.modelValue].find((e) => e.name === t);
18106
18106
  return i && r("error", `The [${t}] file has already been downloaded.`), !i;
18107
18107
  }
18108
- function f(e = []) {
18108
+ function p(e = []) {
18109
18109
  if (!n.maxNumberOfFiles) return !0;
18110
18110
  let t = e.reduce((e, t) => {
18111
18111
  let { size: n } = t;
@@ -18113,21 +18113,21 @@ var Wo = {
18113
18113
  }, 0) <= Number(n.maxNumberOfFiles);
18114
18114
  return t || r("error", `You cannot select more than ${n.maxNumberOfFiles} files.`), t;
18115
18115
  }
18116
- function p(e) {
18116
+ function m(e) {
18117
18117
  if ((0, ws.default)(e)) {
18118
- if (!f(e)) return;
18119
- let t = e.filter((e) => d(e)).filter((e) => l(e)).filter((e) => u(e));
18118
+ if (!p(e)) return;
18119
+ let t = e.filter((e) => f(e)).filter((e) => u(e)).filter((e) => d(e));
18120
18120
  (0, ws.default)(t) > 0 && r("update:modelValue", [...n.modelValue, ...t]);
18121
18121
  }
18122
18122
  }
18123
- function m() {
18124
- a.value && a.value.files && p([...a.value.files]), a.value && (a.value.value = "");
18123
+ function h() {
18124
+ a.value && a.value.files && m([...a.value.files]), a.value && (a.value.value = "");
18125
18125
  }
18126
18126
  return (t, n) => (x(), s("div", { class: g(t.$style.ui3nInputFile) }, [c("label", {
18127
18127
  for: A(i),
18128
18128
  class: g([t.$style.label, e.disabled && t.$style.disabled]),
18129
18129
  onClick: B(o, ["stop", "prevent"])
18130
- }, D(e.buttonText), 11, Ds), c("input", {
18130
+ }, [T(t.$slots, "default", {}, () => [l(D(e.buttonText), 1)])], 10, Ds), c("input", {
18131
18131
  id: A(i),
18132
18132
  ref_key: "fileInput",
18133
18133
  ref: a,
@@ -18137,7 +18137,7 @@ var Wo = {
18137
18137
  multiple: e.multiple,
18138
18138
  accept: e.allowedFileTypes,
18139
18139
  disabled: e.disabled,
18140
- onChange: m
18140
+ onChange: h
18141
18141
  }, null, 40, Os)], 2));
18142
18142
  }
18143
18143
  }), [["__cssModules", { $style: {
@@ -4199,30 +4199,29 @@ var Me = class extends Error {
4199
4199
  }
4200
4200
  };
4201
4201
  async function J(e) {
4202
- let { fn: t, fnArgs: n, defaultValue: r, doesErrorPropagateStop: i = !1, timeoutValue: a = 5e3, retryCount: o = 0, retryDelay: s = 1e3, errorText: c = "An error occurred while executing the function.", actionIfError: l, actionIfSuccess: u, actionInFinally: d } = e, f, p = o + 1;
4203
- for (let e = 1; e <= p; e++) {
4204
- let r = new AbortController(), { signal: i } = r, o = null;
4202
+ let { fn: t, fnArgs: n, passSignal: r = !1, defaultValue: i, doesErrorPropagateStop: a = !1, timeoutValue: o = 5e3, retryCount: s = 0, retryDelay: c = 1e3, errorText: l = "An error occurred while executing the function.", actionIfError: u, actionIfSuccess: d, actionInFinally: f } = e, p = n, m = s + 1, h;
4203
+ for (let e = 1; e <= m; e++) {
4204
+ let n = new AbortController(), i = null;
4205
4205
  try {
4206
- let s = new Promise((t, i) => {
4207
- a <= 0 || (o = setTimeout(() => {
4208
- r.abort(), i(new Me(`Attempt ${e}/${p} timed out.`, {
4206
+ let a = (async () => r ? t(n.signal, ...p) : t(...p))(), s = new Promise((t, r) => {
4207
+ o > 0 && (i = setTimeout(() => {
4208
+ n.abort(), r(new Me(`Attempt ${e}/${m} timed out.`, {
4209
4209
  cause: "timeout",
4210
- fnArgs: n
4210
+ fnArgs: p
4211
4211
  }));
4212
- }, a));
4213
- }), c = n, l = t.length > c.length ? t(i, ...c) : t(...c), d = await Promise.race([Promise.resolve(l), s]);
4214
- return u?.(), o && clearTimeout(o), d;
4212
+ }, o));
4213
+ }), c = await Promise.race([a, s]);
4214
+ return i && clearTimeout(i), d?.(), f?.(), c;
4215
4215
  } catch (t) {
4216
- if (o && clearTimeout(o), f = t, e === p) break;
4217
- console.warn(`Attempt ${e} failed. Retrying in ${s}ms...`, t), s > 0 && await b(s);
4216
+ i && clearTimeout(i), h = t, e < m && (console.warn(`[executeFunc] Attempt ${e} failed. Retrying in ${c}ms...`, t), c > 0 && await b(c));
4218
4217
  }
4219
4218
  }
4220
- let m = f instanceof Me && f.cause === "timeout", h = f.name === "AbortError" || f.name === "CanceledError", g = m ? f : new Me(h ? "Operation aborted" : c, {
4221
- cause: f,
4222
- fnArgs: n
4219
+ let g = h instanceof Me && h.cause === "timeout", _ = h?.name === "AbortError" || h?.name === "CanceledError", v = g ? h : new Me(_ ? "Operation aborted" : l, {
4220
+ cause: h,
4221
+ fnArgs: p
4223
4222
  });
4224
- if (console.error(`All ${p} attempts failed.`, g), l?.(g), !i) throw g;
4225
- return d?.(), r;
4223
+ if (console.error(`[executeFunc] All ${m} attempts failed.`, v), u?.(v), f?.(), !a) throw v;
4224
+ return i;
4226
4225
  }
4227
4226
  //#endregion
4228
4227
  //#region src/utils/remove-whitespace-in-string.ts
@@ -7248,4 +7247,4 @@ function jt(e) {
7248
7247
  return e.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`);
7249
7248
  }
7250
7249
  //#endregion
7251
- export { g as DIALOGS_KEY, Me as ExecuteFunctionError, _ as NOTIFICATIONS_KEY, T as NamedProcs, Et as SQLiteOn3NStorage, w as SingleCyclicProc, x as SingleProc, O as TaskRunner, v as VUEBUS_KEY, lt as b64ToBlob, ut as blobFromDataURL, ct as blobToB64, qe as capitalize, je as copyToClipboard, pt as createVideoThumbnail, y as defer, h as emoticons, J as executeFunc, ft as fileToUint8Array, Ye as formatFileSize, Be as generateColor, ke as getDeliveryErrors, G as getFileExtension, A as getRandomId, ze as hasSlotContent, He as html2text, Ve as invertColor, st as isFileArchive, it as isFileAudio, Qe as isFileImage, tt as isFileVideo, m as mailReg, C as makeSyncedFunc, Re as markSearch, K as mimeTypes, ne as patchTextareaMaxRowsSupport, Ke as prepareDateAsSting, Ne as removeWhitespaceInString, dt as resizeImage, k as round, D as schedulerYield, Fe as selectAll, Le as selectEnd, Ie as selectStart, b as sleep, q as transformFileToWeb3NFile, Ae as transformWeb3nFileToFile, ht as tryOnScopeDispose, X as uint8ToDataURL, mt as unrefElement };
7250
+ export { g as DIALOGS_KEY, _ as NOTIFICATIONS_KEY, T as NamedProcs, Et as SQLiteOn3NStorage, w as SingleCyclicProc, x as SingleProc, O as TaskRunner, v as VUEBUS_KEY, lt as b64ToBlob, ut as blobFromDataURL, ct as blobToB64, qe as capitalize, je as copyToClipboard, pt as createVideoThumbnail, y as defer, h as emoticons, J as executeFunc, ft as fileToUint8Array, Ye as formatFileSize, Be as generateColor, ke as getDeliveryErrors, G as getFileExtension, A as getRandomId, ze as hasSlotContent, He as html2text, Ve as invertColor, st as isFileArchive, it as isFileAudio, Qe as isFileImage, tt as isFileVideo, m as mailReg, C as makeSyncedFunc, Re as markSearch, K as mimeTypes, ne as patchTextareaMaxRowsSupport, Ke as prepareDateAsSting, Ne as removeWhitespaceInString, dt as resizeImage, k as round, D as schedulerYield, Fe as selectAll, Le as selectEnd, Ie as selectStart, b as sleep, q as transformFileToWeb3NFile, Ae as transformWeb3nFileToFile, ht as tryOnScopeDispose, X as uint8ToDataURL, mt as unrefElement };
@@ -1,7 +1,8 @@
1
- export type ExtractArgs<F> = F extends (signal: AbortSignal, ...args: infer P) => any ? P : F extends (...args: infer P) => any ? P : never;
2
- export interface ExecuteFnBaseProps<F extends (...args: any[]) => any, V> {
1
+ type ExtractArgs<F> = F extends (signal: AbortSignal, ...args: infer P) => any ? P : F extends (...args: infer P) => any ? P : never;
2
+ interface BaseProps<F extends (...args: any[]) => any, V> {
3
3
  fn: F;
4
4
  fnArgs: ExtractArgs<F>;
5
+ passSignal?: boolean;
5
6
  timeoutValue?: number;
6
7
  retryCount?: number;
7
8
  retryDelay?: number;
@@ -10,20 +11,14 @@ export interface ExecuteFnBaseProps<F extends (...args: any[]) => any, V> {
10
11
  actionIfSuccess?: () => void;
11
12
  actionInFinally?: () => void;
12
13
  }
13
- export interface ExecuteFunctionPropsNoCatchError<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> extends ExecuteFnBaseProps<F, V> {
14
+ interface ExecuteFunctionPropsNoCatchError<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> extends BaseProps<F, V> {
14
15
  doesErrorPropagateStop: true;
15
16
  defaultValue: V;
16
17
  }
17
- export interface ExecuteFunctionPropsCatchError<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> extends ExecuteFnBaseProps<F, V> {
18
+ interface ExecuteFunctionPropsCatchError<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> extends BaseProps<F, V> {
18
19
  doesErrorPropagateStop?: false;
19
20
  defaultValue?: undefined;
20
21
  }
21
- export type ExecuteFunctionProps<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> = ExecuteFunctionPropsCatchError<F, V> | ExecuteFunctionPropsNoCatchError<F, V>;
22
- export declare class ExecuteFunctionError extends Error {
23
- cause: unknown;
24
- constructor(message: string, data?: {
25
- cause?: unknown;
26
- fnArgs?: unknown[];
27
- });
28
- }
22
+ type ExecuteFunctionProps<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> = ExecuteFunctionPropsCatchError<F, V> | ExecuteFunctionPropsNoCatchError<F, V>;
29
23
  export declare function executeFunc<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>>(props: ExecuteFunctionProps<F, V>): Promise<V>;
24
+ export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@v1nt1248/3nclient-lib",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "author": "v1nt1248",
5
- "version": "0.3.14",
5
+ "version": "0.3.16",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "type": "module",
8
8
  "files": [
@@ -1,3 +1,5 @@
1
+ import { VNode } from 'vue';
2
+
1
3
  export interface Ui3nInputFileProps {
2
4
  /**
3
5
  * Selected files
@@ -41,3 +43,10 @@ export interface Ui3nInputFileEmits {
41
43
  */
42
44
  (event: 'error', value: string): void;
43
45
  }
46
+
47
+ export interface Ui3nInputFileSlots {
48
+ /**
49
+ * Default slot
50
+ */
51
+ default: () => VNode;
52
+ }
@@ -1,34 +1,10 @@
1
- <template>
2
- <div :class="$style.ui3nInputFile">
3
- <label
4
- :for="id"
5
- :class="[$style.label, disabled && $style.disabled]"
6
- @click.stop.prevent="selectFiles"
7
- >
8
- {{ buttonText }}
9
- </label>
10
-
11
- <input
12
- :id="id"
13
- ref="fileInput"
14
- type="file"
15
- name="file"
16
- hidden
17
- :multiple="multiple"
18
- :accept="allowedFileTypes"
19
- :disabled="disabled"
20
- @change="onChange"
21
- >
22
- </div>
23
- </template>
24
-
25
1
  <script lang="ts" setup>
26
2
  import { ref } from 'vue';
27
3
  import size from 'lodash/size';
28
4
  import last from 'lodash/last';
29
5
  import trim from 'lodash/trim';
30
6
  import { getRandomId, formatFileSize } from '@/utils';
31
- import type { Ui3nInputFileProps, Ui3nInputFileEmits } from './types';
7
+ import type { Ui3nInputFileProps, Ui3nInputFileEmits, Ui3nInputFileSlots } from './types';
32
8
  import type { Nullable } from '@/types';
33
9
 
34
10
  const props = withDefaults(defineProps<Ui3nInputFileProps>(), {
@@ -37,6 +13,7 @@
37
13
  allowedFileTypes: '*',
38
14
  });
39
15
  const emits = defineEmits<Ui3nInputFileEmits>();
16
+ defineSlots<Ui3nInputFileSlots>();
40
17
 
41
18
  const id = getRandomId(4);
42
19
  const fileInput = ref<Nullable<HTMLInputElement>>(null);
@@ -141,6 +118,30 @@
141
118
  }
142
119
  </script>
143
120
 
121
+ <template>
122
+ <div :class="$style.ui3nInputFile">
123
+ <label
124
+ :for="id"
125
+ :class="[$style.label, disabled && $style.disabled]"
126
+ @click.stop.prevent="selectFiles"
127
+ >
128
+ <slot>{{ buttonText }}</slot>
129
+ </label>
130
+
131
+ <input
132
+ :id="id"
133
+ ref="fileInput"
134
+ type="file"
135
+ name="file"
136
+ hidden
137
+ :multiple="multiple"
138
+ :accept="allowedFileTypes"
139
+ :disabled="disabled"
140
+ @change="onChange"
141
+ />
142
+ </div>
143
+ </template>
144
+
144
145
  <style lang="scss" module>
145
146
  .ui3nInputFile {
146
147
  position: relative;