@caipira/tamandua 0.0.33 → 0.0.35
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/Form.js +2 -2
- package/dist/Form.vue_vue_type_script_setup_true_lang-O6nqLPyU.js +205 -0
- package/dist/InputSelect.js +2 -2
- package/dist/{InputSelect.vue_vue_type_script_setup_true_lang-BlA3DIYZ.js → InputSelect.vue_vue_type_script_setup_true_lang-vCtwK795.js} +4 -1
- package/dist/ModalForm.js +2 -2
- package/dist/{ModalForm.vue_vue_type_script_setup_true_lang-BSEORivR.js → ModalForm.vue_vue_type_script_setup_true_lang-Da80UtoI.js} +34 -32
- package/dist/components.js +3 -3
- package/dist/{crud-lKm5HfM4.js → crud-TcRx_r8S.js} +4 -4
- package/dist/form2.js +1 -1
- package/dist/{plugin-DF8iyfN5.js → plugin-BkoyYU7S.js} +1 -1
- package/dist/{plugin-C3jERS0X.js → plugin-BqzDqLcd.js} +1 -1
- package/dist/{plugin-Daf_swsz.js → plugin-cVdTR_s6.js} +1 -1
- package/dist/{plugins-BA8tojIo.js → plugins-MQbI25Au.js} +5 -5
- package/dist/plugins.js +5 -5
- package/dist/tamandua.js +1 -1
- package/dist/types/components/Dropdown/types.d.ts +3 -3
- package/dist/types/components/Form/Form.vue.d.ts +42 -24
- package/dist/types/components/Form/types.d.ts +8 -4
- package/dist/types/components/InputPassword/InputPassword.vue.d.ts +1 -1
- package/dist/types/components/InputPassword/index.d.ts +1 -1
- package/dist/types/components/InputPassword/types.d.ts +10 -2
- package/dist/types/components/InputPrice/InputPrice.vue.d.ts +19 -3
- package/dist/types/components/InputPrice/index.d.ts +1 -1
- package/dist/types/components/InputPrice/types.d.ts +4 -0
- package/dist/types/components/InputSelect/InputSelect.story.d.ts +3 -3
- package/dist/types/components/InputSelect/InputSelect.vue.d.ts +69 -2
- package/dist/types/components/InputSelect/index.d.ts +1 -1
- package/dist/types/components/InputSelect/types.d.ts +38 -7
- package/dist/types/components/ModalForm/ModalForm.vue.d.ts +6 -1
- package/dist/types/components/ModalForm/types.d.ts +7 -5
- package/dist/types/components/index.d.ts +4 -4
- package/dist/types/composables/useForm.d.ts +20 -0
- package/dist/types/form/crud.d.ts +4 -3
- package/dist/types/form/form-transformer.d.ts +2 -2
- package/dist/types/form/form-transformer.test.d.ts +1 -0
- package/dist/types/form/form-value-transformers.d.ts +2 -1
- package/dist/types/types/address.d.ts +8 -8
- package/dist/types/types/common.d.ts +1 -0
- package/dist/types/types/form.d.ts +14 -59
- package/package.json +8 -5
- package/dist/Form.vue_vue_type_script_setup_true_lang-CbuLc6sr.js +0 -186
- /package/dist/types/{form/form.test.d.ts → composables/useForm.test.d.ts} +0 -0
|
@@ -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 {
|
|
5
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
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
|
-
*
|
|
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.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UI library for the Caipira ecosystem",
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
@@ -62,11 +62,12 @@
|
|
|
62
62
|
"build:dev": "vite build --mode development",
|
|
63
63
|
"build:prod": "vite build --mode production",
|
|
64
64
|
"preview": "vite preview",
|
|
65
|
-
"start
|
|
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",
|
|
69
|
-
"build:sb": "storybook build"
|
|
69
|
+
"build:sb": "storybook build",
|
|
70
|
+
"prepublishOnly": "npm run build:prod"
|
|
70
71
|
},
|
|
71
72
|
"dependencies": {
|
|
72
73
|
"@floating-ui/vue": "^1.0.6",
|
|
@@ -77,9 +78,11 @@
|
|
|
77
78
|
"peerDependencies": {
|
|
78
79
|
"tailwindcss": "^3.4.3",
|
|
79
80
|
"vue": "^3.0.0",
|
|
80
|
-
"vue-i18n": "9"
|
|
81
|
+
"vue-i18n": "9",
|
|
82
|
+
"vue-router": "4.3.0"
|
|
81
83
|
},
|
|
82
84
|
"devDependencies": {
|
|
85
|
+
"vue-component-type-helpers": "^2.0.19",
|
|
83
86
|
"@faker-js/faker": "^8.4.1",
|
|
84
87
|
"@storybook/addon-actions": "^8.0.8",
|
|
85
88
|
"@storybook/addon-essentials": "^8.0.8",
|
|
@@ -111,4 +114,4 @@
|
|
|
111
114
|
"vue": "^3.4.21",
|
|
112
115
|
"vue-tsc": "^2.0.13"
|
|
113
116
|
}
|
|
114
|
-
}
|
|
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
|
-
};
|
|
File without changes
|