@caipira/tamandua 0.0.32 → 0.0.34

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.
Files changed (51) hide show
  1. package/README.md +12 -4
  2. package/dist/ChartTreemap.js +2 -2
  3. package/dist/{ChartTreemap.vue_vue_type_script_setup_true_lang-CG5aK3KH.js → ChartTreemap.vue_vue_type_script_setup_true_lang-DzIPutlk.js} +3 -1
  4. package/dist/Form.js +2 -2
  5. package/dist/Form.vue_vue_type_script_setup_true_lang-O6nqLPyU.js +205 -0
  6. package/dist/InputPassword.js +2 -2
  7. package/dist/InputPassword.vue_vue_type_script_setup_true_lang-DtP-Tv-2.js +167 -0
  8. package/dist/ModalForm.js +2 -2
  9. package/dist/{ModalForm.vue_vue_type_script_setup_true_lang-BSEORivR.js → ModalForm.vue_vue_type_script_setup_true_lang-BpkPebgZ.js} +34 -32
  10. package/dist/Tag.js +2 -2
  11. package/dist/{Tag.vue_vue_type_script_setup_true_lang-CgX-nT8V.js → Tag.vue_vue_type_script_setup_true_lang-DMigzW22.js} +16 -19
  12. package/dist/components.js +5 -5
  13. package/dist/{crud-lKm5HfM4.js → crud-TcRx_r8S.js} +4 -4
  14. package/dist/form2.js +1 -1
  15. package/dist/{plugin-DOiXH9p9.js → plugin-BN2jubTY.js} +1 -1
  16. package/dist/{plugin-DF8iyfN5.js → plugin-BkoyYU7S.js} +1 -1
  17. package/dist/{plugin-BibUAa04.js → plugin-D4x3uASg.js} +1 -1
  18. package/dist/{plugin-D8CsjFdw.js → plugin-DgCa2m12.js} +1 -1
  19. package/dist/{plugin-C3jERS0X.js → plugin-JFEZqDsu.js} +1 -1
  20. package/dist/{plugins-ChB184ip.js → plugins-Bc8aBhAD.js} +7 -7
  21. package/dist/plugins.js +7 -7
  22. package/dist/tamandua.js +1 -1
  23. package/dist/types/components/Dropdown/types.d.ts +1 -1
  24. package/dist/types/components/Form/Form.vue.d.ts +42 -24
  25. package/dist/types/components/Form/types.d.ts +8 -4
  26. package/dist/types/components/InputPassword/InputPassword.vue.d.ts +1 -1
  27. package/dist/types/components/InputPassword/types.d.ts +10 -2
  28. package/dist/types/components/InputPrice/InputPrice.vue.d.ts +19 -3
  29. package/dist/types/components/InputPrice/types.d.ts +4 -0
  30. package/dist/types/components/InputSelect/InputSelect.story.d.ts +1 -1
  31. package/dist/types/components/InputSelect/InputSelect.vue.d.ts +69 -2
  32. package/dist/types/components/InputSelect/types.d.ts +33 -2
  33. package/dist/types/components/ModalForm/ModalForm.vue.d.ts +6 -1
  34. package/dist/types/components/ModalForm/types.d.ts +6 -4
  35. package/dist/types/composables/useForm.d.ts +20 -0
  36. package/dist/types/enums/form.d.ts +3 -3
  37. package/dist/types/enums/ui.d.ts +10 -10
  38. package/dist/types/form/crud.d.ts +5 -4
  39. package/dist/types/form/form-transformer.d.ts +2 -2
  40. package/dist/types/form/form-transformer.test.d.ts +1 -0
  41. package/dist/types/form/form-value-transformers.d.ts +2 -1
  42. package/dist/types/services/password.d.ts +1 -4
  43. package/dist/types/services/password.test.d.ts +1 -0
  44. package/dist/types/types/address.d.ts +8 -8
  45. package/dist/types/types/common.d.ts +1 -0
  46. package/dist/types/types/form.d.ts +14 -59
  47. package/package.json +6 -4
  48. package/dist/Form.vue_vue_type_script_setup_true_lang-CbuLc6sr.js +0 -186
  49. package/dist/InputPassword.vue_vue_type_script_setup_true_lang-Do7d1Qfe.js +0 -172
  50. /package/dist/types/components/Form/{Form.spec.d.ts → Form.test.d.ts} +0 -0
  51. /package/dist/types/{form/form.test.d.ts → composables/useForm.test.d.ts} +0 -0
@@ -1,8 +1,8 @@
1
- export declare const enum FormStates {
1
+ export declare enum FormStates {
2
2
  ADD = 0,
3
3
  EDIT = 1
4
4
  }
5
- export declare const enum FormDataTypes {
5
+ export declare enum FormDataTypes {
6
6
  Address = 0,
7
7
  Boolean = 1,
8
8
  Country = 2,
@@ -17,7 +17,7 @@ export declare const enum FormDataTypes {
17
17
  StringArray = 11,
18
18
  Website = 12
19
19
  }
20
- export declare const enum FormSubmissionFormat {
20
+ export declare enum FormSubmissionFormat {
21
21
  FormData = 0,
22
22
  JSON = 1
23
23
  }
@@ -1,4 +1,4 @@
1
- export declare const enum ElementSize {
1
+ export declare enum ElementSize {
2
2
  Unset = "",
3
3
  ExtraSmall = "xs",
4
4
  Small = "sm",
@@ -6,13 +6,13 @@ export declare const enum ElementSize {
6
6
  Large = "lg",
7
7
  ExtraLarge = "xl"
8
8
  }
9
- export declare const enum ElementShape {
9
+ export declare enum ElementShape {
10
10
  Unset = "",
11
11
  Square = "square",
12
12
  Rounded = "rounded",
13
13
  Circle = "circle"
14
14
  }
15
- export declare const enum ButtonVariant {
15
+ export declare enum ButtonVariant {
16
16
  DEFAULT = "default",
17
17
  PRIMARY = "primary",
18
18
  SUCCESS = "success",
@@ -21,18 +21,18 @@ export declare const enum ButtonVariant {
21
21
  LINK = "link",
22
22
  TRANSPARENT = "transparent"
23
23
  }
24
- export declare const enum ToastVariant {
24
+ export declare enum ToastVariant {
25
25
  DEFAULT = "default",
26
26
  PRIMARY = "primary",
27
27
  SUCCESS = "success",
28
28
  DANGER = "danger",
29
29
  WARNING = "warning"
30
30
  }
31
- export declare const enum ElementTrigger {
31
+ export declare enum ElementTrigger {
32
32
  CLICK = "click",
33
33
  HOVER = "hover"
34
34
  }
35
- export declare const enum ElementPosition {
35
+ export declare enum ElementPosition {
36
36
  TOP_START = "top-start",
37
37
  TOP = "top",
38
38
  TOP_END = "top-end",
@@ -46,22 +46,22 @@ export declare const enum ElementPosition {
46
46
  LEFT = "left",
47
47
  LEFT_START = "left-start"
48
48
  }
49
- export declare const enum ButtonType {
49
+ export declare enum ButtonType {
50
50
  BUTTON = "button",
51
51
  SUBMIT = "submit",
52
52
  FILE = "file"
53
53
  }
54
- export declare const enum LinkType {
54
+ export declare enum LinkType {
55
55
  Default = "default",
56
56
  Router = "router"
57
57
  }
58
- export declare const enum GraphyPriceVariant {
58
+ export declare enum GraphyPriceVariant {
59
59
  DEFAULT = "default",
60
60
  INCREASE = "increase",
61
61
  DECREASE = "decrease",
62
62
  AUTO = "auto"
63
63
  }
64
- export declare const enum Icon {
64
+ export declare enum Icon {
65
65
  Account = "account",
66
66
  AlertOctagon = "alert-octagon",
67
67
  AlertOctagonOutline = "alert-octagon-outline",
@@ -1,5 +1,6 @@
1
1
  import { FormStates } from '../enums/form.js';
2
- import { default as Form } from '../components/Form/Form.vue';
2
+ import { ComponentExposed } from 'vue-component-type-helpers';
3
+ import { default as ModalForm } from '../components/ModalForm/ModalForm.vue';
3
4
 
4
5
  export default class CrudService {
5
6
  id: string;
@@ -11,8 +12,8 @@ export default class CrudService {
11
12
  EDIT: string;
12
13
  };
13
14
  isLoading: boolean;
14
- formReference: InstanceType<typeof Form> | null;
15
- constructor(entity: string, formReference: any);
15
+ formReference: ComponentExposed<typeof ModalForm> | undefined;
16
+ constructor(entity: string, formReference: ComponentExposed<typeof ModalForm>);
16
17
  get isEditing(): boolean;
17
18
  get isCreating(): boolean;
18
19
  show(state?: FormStates): void;
@@ -20,7 +21,7 @@ export default class CrudService {
20
21
  edit(id: string): void;
21
22
  close(): void;
22
23
  reset(): void;
23
- save(): void;
24
+ save(): Promise<void>;
24
25
  onSave(close?: boolean): void;
25
26
  delete(): void;
26
27
  onDelete(close?: boolean): void;
@@ -1,7 +1,7 @@
1
- import { FormSchema, FormInstance, FormSubmissionFormatMap } from '../types/form.js';
1
+ import { JSONForm, FormSchema, FormInstance, FormDataForm } from '../types/form.js';
2
2
  import { FormSubmissionFormat } from '../enums/form.js';
3
3
 
4
4
  /**
5
5
  * Transforms the form values to a format that conforms to the submission format
6
6
  */
7
- export declare const transformForm: <F extends FormSubmissionFormat, S extends FormSchema>(form: FormInstance<S>, schema: FormSchema, submissionFormat: F) => Promise<FormSubmissionFormatMap[F]>;
7
+ export declare const transformForm: <F extends FormSubmissionFormat, S extends FormSchema>(form: FormInstance<S>, schema: S, format: F) => Promise<F extends FormSubmissionFormat.FormData ? FormDataForm : JSONForm>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
- import { InputPriceModel, InputPasswordModel } from '../types/form.js';
1
+ import { InputPasswordModel } from '../components/InputPassword/types.js';
2
+ import { InputPriceModel } from '../components/InputPrice/types.js';
2
3
  import { Country } from '../types/address.js';
3
4
 
4
5
  declare const formValueDateTransformer: (date: Date) => string;
@@ -1,8 +1,5 @@
1
1
  declare const _default: {
2
2
  generatePassword: (passwordLength?: number) => string;
3
- getPasswordStrength: (pwd: string) => {
4
- score: number;
5
- complexity: string;
6
- };
3
+ getPasswordStrength: (pwd: string) => number;
7
4
  };
8
5
  export default _default;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,15 +1,15 @@
1
- export interface Country {
1
+ export type Country = {
2
2
  name: string;
3
3
  dialCode: string;
4
4
  flag: string;
5
5
  iso2: string;
6
6
  order: string;
7
- }
8
- export interface CountryStateOption {
7
+ };
8
+ export type CountryStateOption = {
9
9
  uuid: string;
10
10
  name: string;
11
- }
12
- export interface AddressResource {
11
+ };
12
+ export type AddressResource = {
13
13
  city?: string;
14
14
  complement?: string;
15
15
  country?: string;
@@ -22,8 +22,8 @@ export interface AddressResource {
22
22
  street?: string;
23
23
  town?: string;
24
24
  zipCode?: string;
25
- }
26
- export interface AddressModel {
25
+ };
26
+ export type AddressModel = {
27
27
  city?: string;
28
28
  complement?: string;
29
29
  country?: Country;
@@ -36,4 +36,4 @@ export interface AddressModel {
36
36
  street?: string;
37
37
  town?: string;
38
38
  zipCode?: string;
39
- }
39
+ };
@@ -2,3 +2,4 @@ export type KeysMatching<T, V> = {
2
2
  [K in keyof T]-?: T[K] extends V ? K : never;
3
3
  }[keyof T];
4
4
  export type Maybe<T> = NonNullable<T> | undefined;
5
+ export type Default<T, D> = T extends undefined ? D : T;
@@ -1,59 +1,13 @@
1
1
  import { FormDataTypes, FormSubmissionFormat } from '../enums/form.js';
2
- import { Icon } from '../enums/ui.js';
3
2
  import { AddressModel, Country } from './address.js';
4
- import { APISearchFilters } from './api.js';
5
- import { Pagination } from './ui.js';
3
+ import { InputPasswordModel } from '../components/InputPassword/types.js';
4
+ import { InputPriceModel } from '../components/InputPrice/types.js';
6
5
  import { Website } from './website.js';
6
+ import { Maybe } from './common.js';
7
7
 
8
- export type SelectValuePrimitives = string | number;
9
- export type SelectValue = SelectValuePrimitives | Array<SelectValuePrimitives>;
10
- export type SelectOption = {
11
- /** Optional icon, to be appended to the label */
12
- icon?: `${Icon}`;
13
- /** Option label, either a string or an object containing the props necessary to render the option */
14
- label: string | object;
15
- /** Optional type, used to diferentiate options from one another */
16
- type?: string;
17
- /** Optional renderer, containing the fully resolved path to the component that will be used
18
- * to render the option
19
- */
20
- renderer?: string;
21
- } & ({
22
- /** If true, the option is a group label and can't be selected */
23
- isGroupLabel: boolean;
24
- value?: never;
25
- action?: never;
26
- } | {
27
- /** Option value */
28
- value: SelectValue;
29
- action?: never;
30
- isGroupLabel?: never;
31
- } | {
32
- /** Action to be executed once the option is selected */
33
- action: (filters?: APISearchFilters) => Promise<{
34
- items: unknown[];
35
- pagination: Pagination;
36
- }> | Promise<void> | void;
37
- value?: never;
38
- isGroupLabel?: never;
39
- });
40
- export interface InputPriceModel {
41
- iso: string;
42
- value?: number;
43
- }
44
- export interface InputPasswordModel {
45
- /** Unencrypted password */
46
- raw: string;
47
- /** If an encryptor was passed, this prop will hold the encrypted value */
48
- hash?: string;
49
- /** Strength of the password */
50
- strength?: number;
51
- /** Date of creation or last update */
52
- updatedAt?: Date;
53
- }
54
- export type FormStyle = {
55
- [key in "label" | "input"]?: string;
56
- };
8
+ /**
9
+ * Map of the form data types and their corresponding value types
10
+ */
57
11
  export type FormSchemaValueMap = {
58
12
  [FormDataTypes.Address]: AddressModel;
59
13
  [FormDataTypes.Boolean]: boolean;
@@ -69,6 +23,10 @@ export type FormSchemaValueMap = {
69
23
  [FormDataTypes.StringArray]: string[];
70
24
  [FormDataTypes.Website]: Website;
71
25
  };
26
+ /**
27
+ * Form in the FormData format
28
+ */
29
+ export type FormDataForm = InstanceType<typeof FormData>;
72
30
  /**
73
31
  * Form in the JSON format
74
32
  */
@@ -76,9 +34,8 @@ export type JSONForm = {
76
34
  [prop: string]: string | number | boolean | string[];
77
35
  };
78
36
  /**
79
- * Form in the FormData format
37
+ * Form submission format map
80
38
  */
81
- export type FormDataForm = InstanceType<typeof FormData>;
82
39
  export type FormSubmissionFormatMap = {
83
40
  [FormSubmissionFormat.FormData]: FormDataForm;
84
41
  [FormSubmissionFormat.JSON]: JSONForm;
@@ -98,17 +55,15 @@ export type ValidationResult<T = FormSubmissionFormat.FormData> = {
98
55
  /**
99
56
  * Form schema, defining the form fields and their corresponding FormDataTypes
100
57
  */
101
- export type FormSchema = {
102
- [key: string]: FormDataTypes;
103
- };
58
+ export type FormSchema = Record<string, FormDataTypes>;
104
59
  /**
105
60
  * Object containing the form values, each value being of one of the types from
106
61
  * FormDataTypes, defined by each corresponding input component
107
62
  */
108
63
  export type FormInstance<T extends Record<string, FormDataTypes>> = {
109
- [K in keyof T]: FormSchemaValueMap[T[K]];
64
+ [K in keyof T]: T[K] extends FormDataTypes ? Maybe<FormSchemaValueMap[T[K]]> : never;
110
65
  };
111
66
  /**
112
- * Type union of the accepted values by the FormData
67
+ * Union type of the accepted values by FormData
113
68
  */
114
69
  export type AcceptedFormDataValues = string | Blob;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caipira/tamandua",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "private": false,
5
5
  "description": "UI library for the Caipira ecosystem",
6
6
  "license": "GPL-3.0-only",
@@ -62,7 +62,7 @@
62
62
  "build:dev": "vite build --mode development",
63
63
  "build:prod": "vite build --mode production",
64
64
  "preview": "vite preview",
65
- "start:test": "vitest",
65
+ "test:start": "vitest",
66
66
  "test": "vitest --run",
67
67
  "typecheck": "vue-tsc --noEmit -p tsconfig.json --composite false",
68
68
  "start:sb": "storybook dev",
@@ -78,9 +78,11 @@
78
78
  "peerDependencies": {
79
79
  "tailwindcss": "^3.4.3",
80
80
  "vue": "^3.0.0",
81
- "vue-i18n": "9"
81
+ "vue-i18n": "9",
82
+ "vue-router": "4.3.0"
82
83
  },
83
84
  "devDependencies": {
85
+ "vue-component-type-helpers": "^2.0.19",
84
86
  "@faker-js/faker": "^8.4.1",
85
87
  "@storybook/addon-actions": "^8.0.8",
86
88
  "@storybook/addon-essentials": "^8.0.8",
@@ -112,4 +114,4 @@
112
114
  "vue": "^3.4.21",
113
115
  "vue-tsc": "^2.0.13"
114
116
  }
115
- }
117
+ }
@@ -1,186 +0,0 @@
1
- import { defineComponent as A, reactive as P, ref as _, watch as T, provide as N, resolveComponent as O, openBlock as B, createElementBlock as j, renderSlot as E, createElementVNode as J, normalizeClass as R, withDirectives as W, createVNode as M, mergeProps as z, vShow as K } from "vue";
2
- import { B as L } from "./ui-BC6H9E93.js";
3
- import { F as a, a as p } from "./form-BkXpIJ0e.js";
4
- import { f as I } from "./index-CjvqeRf7.js";
5
- const V = (t) => t ? I(t, "yyyy-MM-dd") : "", h = (t) => [`${t?.iso}`, `${t?.value}`], b = (t) => t?.iso2 ?? "", w = async (t) => t?.hash ? t.hash : t?.raw ?? "", i = {
6
- default: (t, r, e) => (r[e] = t, r),
7
- price: (t, r, e, n = ["Currency", "Value"]) => {
8
- const [c, s] = h(t);
9
- return r[`${e}${n[0]}`] = c, r[`${e}${n[1]}`] = s, r;
10
- },
11
- password: async (t, r, e) => (r[e] = await w(t), r),
12
- stringArray: (t, r, e) => (r[e] = t, r)
13
- }, Y = async (t, r, e, n) => {
14
- switch (t) {
15
- case a.Country:
16
- return i.default(
17
- b(e),
18
- r,
19
- n
20
- );
21
- case a.Documents:
22
- return i.default(e, r, n);
23
- case a.Date:
24
- return i.default(
25
- V(e),
26
- r,
27
- n
28
- );
29
- case a.Address:
30
- return i.default(e, r, n);
31
- case a.Price:
32
- return i.price(e, r, n);
33
- case a.Password:
34
- return await i.password(e, r, n);
35
- case a.StringArray:
36
- return i.stringArray(e, r, n);
37
- default:
38
- return i.default(e, r, n);
39
- }
40
- }, m = (t) => (t == null ? t = "" : typeof t == "object" ? t = JSON.stringify(t) : typeof t == "number" ? t = t.toString() : typeof t == "boolean" && (t = t ? "1" : "0"), t), u = {
41
- default: (t, r, e) => (t = m(t), t && r.append(e, t), r),
42
- price: (t, r, e, n = ["Currency", "Value"]) => {
43
- const [c, s] = h(t);
44
- return r.append(`${e}${n[0]}`, m(c)), r.append(`${e}${n[1]}`, m(s)), r;
45
- },
46
- address: (t, r, e) => (r.append(
47
- e,
48
- JSON.stringify({
49
- ...t,
50
- country: b(t?.country)
51
- })
52
- ), r),
53
- documents: (t, r, e) => (e.endsWith("[]") || (e = `${e}[]`), Array.from(t).forEach((n) => r.append(e, n)), r),
54
- document: (t, r, e) => (r.append(e, t), r),
55
- stringArray: (t, r, e) => (e.endsWith("[]") || (e = `${e}[]`), t.forEach((n) => r.append(e, m(n))), r)
56
- }, q = async (t, r, e, n) => {
57
- switch (t) {
58
- case a.Country:
59
- return u.default(
60
- b(e),
61
- r,
62
- n
63
- );
64
- case a.Document:
65
- return u.document(e, r, n);
66
- case a.Documents:
67
- return u.documents(e, r, n);
68
- case a.Date:
69
- return u.default(
70
- V(e),
71
- r,
72
- n
73
- );
74
- case a.Address:
75
- return u.address(e, r, n);
76
- case a.Price:
77
- return u.price(e, r, n);
78
- case a.Password:
79
- return u.default(
80
- await w(e),
81
- r,
82
- n
83
- );
84
- case a.StringArray:
85
- return u.stringArray(e, r, n);
86
- default:
87
- return u.default(e, r, n);
88
- }
89
- }, x = async (t, r, e) => {
90
- switch (e) {
91
- case p.JSON:
92
- let n = {};
93
- for (const s in t)
94
- n = await Y(
95
- r[s],
96
- n,
97
- t[s],
98
- s
99
- );
100
- return n;
101
- case p.FormData:
102
- default:
103
- let c = new FormData();
104
- for (const s in t)
105
- c = await q(
106
- r[s],
107
- c,
108
- t[s],
109
- s
110
- );
111
- return c;
112
- }
113
- }, X = /* @__PURE__ */ A({
114
- name: "TForm",
115
- __name: "Form",
116
- props: {
117
- id: { default: "" },
118
- idKey: { default: "id" },
119
- schema: { default: () => ({}) },
120
- formStyle: { default: () => ({}) },
121
- showSubmit: { type: Boolean, default: !1 },
122
- submitLabel: { default: "Submit" },
123
- buttonProps: {},
124
- buttonVariant: { default: L.PRIMARY },
125
- submissionFormat: { default: p.FormData },
126
- buttonWrapperClasses: { default: "" }
127
- },
128
- emits: ["submit", "change"],
129
- setup(t, { expose: r, emit: e }) {
130
- const n = t, c = e, s = P({}), y = _(null), l = async () => {
131
- c("submit", await F());
132
- }, F = async () => {
133
- const o = { ...s };
134
- return n.id && (o[n.idKey] = n.id), {
135
- isValid: !0,
136
- form: await x(
137
- o,
138
- n.schema,
139
- n.submissionFormat
140
- )
141
- };
142
- }, S = () => {
143
- Object.assign(s, {});
144
- }, g = (o) => {
145
- for (const [d, f] of Object.entries(o))
146
- s[d] = f;
147
- }, $ = () => s, D = (o, d) => {
148
- s[o] = d;
149
- }, C = (o) => s[o];
150
- return T(s, (o) => {
151
- c("change", o);
152
- }), N("formStyle", n.formStyle), r({
153
- submit: l,
154
- reset: S,
155
- setValues: g,
156
- getValues: $,
157
- setValue: D,
158
- getValue: C
159
- }), (o, d) => {
160
- const f = O("t-button");
161
- return B(), j("form", {
162
- onSubmit: l,
163
- ref_key: "formReference",
164
- ref: y
165
- }, [
166
- E(o.$slots, "default", { form: s }),
167
- J("div", {
168
- class: R([n.buttonWrapperClasses])
169
- }, [
170
- W(M(f, z(n.buttonProps, {
171
- type: "submit",
172
- class: "mt-4",
173
- variant: n.buttonVariant,
174
- label: n.submitLabel,
175
- onClick: l
176
- }), null, 16, ["variant", "label"]), [
177
- [K, n.showSubmit]
178
- ])
179
- ], 2)
180
- ], 544);
181
- };
182
- }
183
- });
184
- export {
185
- X as _
186
- };