@aheart-ui/ai 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +21 -2
- package/es/actions.vue.d.ts +34 -0
- package/es/actions.vue.js +27 -0
- package/es/actions.vue2.js +4 -0
- package/es/agent-execution.vue.d.ts +106 -0
- package/es/agent-execution.vue.js +441 -0
- package/es/agent-execution.vue2.js +4 -0
- package/es/agent-workbench.vue.d.ts +186 -0
- package/es/agent-workbench.vue.js +537 -0
- package/es/agent-workbench.vue2.js +4 -0
- package/es/attachments.vue.d.ts +39 -0
- package/es/attachments.vue.js +39 -0
- package/es/attachments.vue2.js +4 -0
- package/es/bubble.vue.d.ts +27 -0
- package/es/bubble.vue.js +82 -0
- package/es/bubble.vue2.js +4 -0
- package/es/chat-panel.vue.d.ts +108 -0
- package/es/chat-panel.vue.js +330 -0
- package/es/chat-panel.vue2.js +4 -0
- package/es/conversations.vue.d.ts +39 -0
- package/es/conversations.vue.js +29 -0
- package/es/conversations.vue2.js +4 -0
- package/es/form-field.vue.d.ts +28 -0
- package/es/form-field.vue.js +176 -0
- package/es/form-field.vue2.js +4 -0
- package/es/form-schema.d.ts +73 -0
- package/es/form-schema.js +105 -0
- package/es/form.vue.d.ts +81 -0
- package/es/form.vue.js +376 -0
- package/es/form.vue2.js +4 -0
- package/es/index.d.ts +20 -0
- package/es/index.js +42 -0
- package/es/package.json +3 -0
- package/es/process.vue.d.ts +30 -0
- package/es/process.vue.js +29 -0
- package/es/process.vue2.js +4 -0
- package/es/prompts.vue.d.ts +39 -0
- package/es/prompts.vue.js +33 -0
- package/es/prompts.vue2.js +4 -0
- package/es/safe-markdown.d.ts +3 -0
- package/es/safe-markdown.js +23 -0
- package/es/sender.vue.d.ts +52 -0
- package/es/sender.vue.js +46 -0
- package/es/sender.vue2.js +4 -0
- package/es/sources.vue.d.ts +30 -0
- package/es/sources.vue.js +34 -0
- package/es/sources.vue2.js +4 -0
- package/es/stream-reducer.d.ts +35 -0
- package/es/stream-reducer.js +85 -0
- package/es/style.css +1586 -0
- package/es/thought-chain.vue.d.ts +30 -0
- package/es/thought-chain.vue.js +15 -0
- package/es/thought-chain.vue2.js +4 -0
- package/es/types.d.ts +203 -0
- package/es/welcome.vue.d.ts +41 -0
- package/es/welcome.vue.js +27 -0
- package/es/welcome.vue2.js +4 -0
- package/lib/actions.vue.d.ts +34 -0
- package/lib/actions.vue.js +1 -0
- package/lib/actions.vue2.js +1 -0
- package/lib/agent-execution.vue.d.ts +106 -0
- package/lib/agent-execution.vue.js +1 -0
- package/lib/agent-execution.vue2.js +1 -0
- package/lib/agent-workbench.vue.d.ts +186 -0
- package/lib/agent-workbench.vue.js +1 -0
- package/lib/agent-workbench.vue2.js +1 -0
- package/lib/attachments.vue.d.ts +39 -0
- package/lib/attachments.vue.js +1 -0
- package/lib/attachments.vue2.js +1 -0
- package/lib/bubble.vue.d.ts +27 -0
- package/lib/bubble.vue.js +1 -0
- package/lib/bubble.vue2.js +1 -0
- package/lib/chat-panel.vue.d.ts +108 -0
- package/lib/chat-panel.vue.js +1 -0
- package/lib/chat-panel.vue2.js +1 -0
- package/lib/conversations.vue.d.ts +39 -0
- package/lib/conversations.vue.js +1 -0
- package/lib/conversations.vue2.js +1 -0
- package/lib/form-field.vue.d.ts +28 -0
- package/lib/form-field.vue.js +1 -0
- package/lib/form-field.vue2.js +1 -0
- package/lib/form-schema.d.ts +73 -0
- package/lib/form-schema.js +1 -0
- package/lib/form.vue.d.ts +81 -0
- package/lib/form.vue.js +1 -0
- package/lib/form.vue2.js +1 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +1 -0
- package/lib/package.json +3 -0
- package/lib/process.vue.d.ts +30 -0
- package/lib/process.vue.js +1 -0
- package/lib/process.vue2.js +1 -0
- package/lib/prompts.vue.d.ts +39 -0
- package/lib/prompts.vue.js +1 -0
- package/lib/prompts.vue2.js +1 -0
- package/lib/safe-markdown.d.ts +3 -0
- package/lib/safe-markdown.js +2 -0
- package/lib/sender.vue.d.ts +52 -0
- package/lib/sender.vue.js +1 -0
- package/lib/sender.vue2.js +1 -0
- package/lib/sources.vue.d.ts +30 -0
- package/lib/sources.vue.js +1 -0
- package/lib/sources.vue2.js +1 -0
- package/lib/stream-reducer.d.ts +35 -0
- package/lib/stream-reducer.js +1 -0
- package/lib/style.css +1586 -0
- package/lib/thought-chain.vue.d.ts +30 -0
- package/lib/thought-chain.vue.js +1 -0
- package/lib/thought-chain.vue2.js +1 -0
- package/lib/types.d.ts +203 -0
- package/lib/welcome.vue.d.ts +41 -0
- package/lib/welcome.vue.js +1 -0
- package/lib/welcome.vue2.js +1 -0
- package/package.json +70 -3
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { defineComponent as x, ref as k, computed as f, openBlock as a, createElementBlock as y, normalizeClass as g, createElementVNode as B, createTextVNode as C, toDisplayString as m, createCommentVNode as v, createBlock as t, unref as u } from "vue";
|
|
2
|
+
import { Textarea as S, TreeSelect as T, Upload as h, RadioGroup as D, CheckboxGroup as E, Select as N, Switch as P, InputNumber as q, DatePicker as I, DateRangePicker as R, TimePicker as w, TimeRangePicker as A, Input as G } from "aheart-ui";
|
|
3
|
+
const j = ["data-field-key", "aria-invalid", "aria-describedby"], z = ["id", "for"], L = {
|
|
4
|
+
key: 0,
|
|
5
|
+
class: "aheart-ai-form__required",
|
|
6
|
+
"aria-hidden": "true"
|
|
7
|
+
}, F = ["id"], H = ["id"], M = /* @__PURE__ */ x({
|
|
8
|
+
__name: "form-field",
|
|
9
|
+
props: {
|
|
10
|
+
field: {},
|
|
11
|
+
value: {},
|
|
12
|
+
disabled: { type: Boolean },
|
|
13
|
+
error: {}
|
|
14
|
+
},
|
|
15
|
+
emits: ["update"],
|
|
16
|
+
setup(e, { expose: c, emit: V }) {
|
|
17
|
+
const b = e, i = V, s = k(), n = k(), U = f(
|
|
18
|
+
() => (b.field.options ?? []).map((r) => ({
|
|
19
|
+
key: r.value,
|
|
20
|
+
title: r.label,
|
|
21
|
+
disabled: r.disabled
|
|
22
|
+
}))
|
|
23
|
+
), o = f(
|
|
24
|
+
() => [b.field.description && `${b.field.key}-description`, b.error && `${b.field.key}-error`].filter(Boolean).join(" ") || void 0
|
|
25
|
+
), $ = f(
|
|
26
|
+
() => b.field.type === "date-range" || b.field.type === "time-range" ? `${b.field.key}-start` : b.field.key
|
|
27
|
+
);
|
|
28
|
+
return c({
|
|
29
|
+
focus: () => {
|
|
30
|
+
var r, l;
|
|
31
|
+
if (n.value) {
|
|
32
|
+
n.value.focus("start");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
(l = (r = s.value) == null ? void 0 : r.querySelector('input, button, [role="combobox"], [tabindex="0"]')) == null || l.focus({ preventScroll: !0 });
|
|
36
|
+
}
|
|
37
|
+
}), (r, l) => (a(), y("div", {
|
|
38
|
+
ref_key: "fieldElement",
|
|
39
|
+
ref: s,
|
|
40
|
+
class: g(["aheart-ai-form__field", { "is-error": !!e.error, "is-disabled": e.disabled }]),
|
|
41
|
+
"data-field-key": e.field.key,
|
|
42
|
+
"aria-invalid": e.error ? "true" : void 0,
|
|
43
|
+
"aria-describedby": o.value,
|
|
44
|
+
tabindex: "-1"
|
|
45
|
+
}, [
|
|
46
|
+
B("label", {
|
|
47
|
+
id: `${e.field.key}-label`,
|
|
48
|
+
for: $.value
|
|
49
|
+
}, [
|
|
50
|
+
C(m(e.field.label) + " ", 1),
|
|
51
|
+
e.field.required ? (a(), y("span", L, "*")) : v("", !0)
|
|
52
|
+
], 8, z),
|
|
53
|
+
e.field.description ? (a(), y("p", {
|
|
54
|
+
key: 0,
|
|
55
|
+
id: `${e.field.key}-description`,
|
|
56
|
+
class: "aheart-ai-form__field-description"
|
|
57
|
+
}, m(e.field.description), 9, F)) : v("", !0),
|
|
58
|
+
e.field.type === "textarea" ? (a(), t(u(S), {
|
|
59
|
+
key: 1,
|
|
60
|
+
id: e.field.key,
|
|
61
|
+
"aria-labelledby": `${e.field.key}-label`,
|
|
62
|
+
"aria-describedby": o.value,
|
|
63
|
+
"model-value": e.value,
|
|
64
|
+
placeholder: e.field.placeholder,
|
|
65
|
+
disabled: e.disabled,
|
|
66
|
+
"onUpdate:modelValue": l[0] || (l[0] = (d) => i("update", d))
|
|
67
|
+
}, null, 8, ["id", "aria-labelledby", "aria-describedby", "model-value", "placeholder", "disabled"])) : e.field.type === "tree-select" ? (a(), t(u(T), {
|
|
68
|
+
key: 2,
|
|
69
|
+
id: e.field.key,
|
|
70
|
+
"labelled-by": `${e.field.key}-label`,
|
|
71
|
+
"model-value": e.value,
|
|
72
|
+
"tree-data": U.value,
|
|
73
|
+
multiple: Array.isArray(e.value),
|
|
74
|
+
disabled: e.disabled,
|
|
75
|
+
"onUpdate:modelValue": l[1] || (l[1] = (d) => i("update", d))
|
|
76
|
+
}, null, 8, ["id", "labelled-by", "model-value", "tree-data", "multiple", "disabled"])) : e.field.type === "upload" ? (a(), t(u(h), {
|
|
77
|
+
key: 3,
|
|
78
|
+
"file-list": e.value,
|
|
79
|
+
disabled: e.disabled,
|
|
80
|
+
"onUpdate:fileList": l[2] || (l[2] = (d) => i("update", d))
|
|
81
|
+
}, null, 8, ["file-list", "disabled"])) : e.field.type === "radio" ? (a(), t(u(D), {
|
|
82
|
+
key: 4,
|
|
83
|
+
"model-value": e.value,
|
|
84
|
+
options: e.field.options,
|
|
85
|
+
disabled: e.disabled,
|
|
86
|
+
"onUpdate:modelValue": l[3] || (l[3] = (d) => i("update", d))
|
|
87
|
+
}, null, 8, ["model-value", "options", "disabled"])) : e.field.type === "checkbox" ? (a(), t(u(E), {
|
|
88
|
+
key: 5,
|
|
89
|
+
"model-value": e.value,
|
|
90
|
+
options: e.field.options,
|
|
91
|
+
disabled: e.disabled,
|
|
92
|
+
"onUpdate:modelValue": l[4] || (l[4] = (d) => i("update", d))
|
|
93
|
+
}, null, 8, ["model-value", "options", "disabled"])) : e.field.type === "select" ? (a(), t(u(N), {
|
|
94
|
+
key: 6,
|
|
95
|
+
id: e.field.key,
|
|
96
|
+
"labelled-by": `${e.field.key}-label`,
|
|
97
|
+
"model-value": e.value,
|
|
98
|
+
disabled: e.disabled,
|
|
99
|
+
options: e.field.options,
|
|
100
|
+
"onUpdate:modelValue": l[5] || (l[5] = (d) => i("update", d))
|
|
101
|
+
}, null, 8, ["id", "labelled-by", "model-value", "disabled", "options"])) : e.field.type === "switch" ? (a(), t(u(P), {
|
|
102
|
+
key: 7,
|
|
103
|
+
id: e.field.key,
|
|
104
|
+
"model-value": !!e.value,
|
|
105
|
+
disabled: e.disabled,
|
|
106
|
+
"onUpdate:modelValue": l[6] || (l[6] = (d) => i("update", d))
|
|
107
|
+
}, null, 8, ["id", "model-value", "disabled"])) : e.field.type === "number" ? (a(), t(u(q), {
|
|
108
|
+
key: 8,
|
|
109
|
+
id: e.field.key,
|
|
110
|
+
"model-value": e.value,
|
|
111
|
+
placeholder: e.field.placeholder,
|
|
112
|
+
disabled: e.disabled,
|
|
113
|
+
"onUpdate:modelValue": l[7] || (l[7] = (d) => i("update", d))
|
|
114
|
+
}, null, 8, ["id", "model-value", "placeholder", "disabled"])) : e.field.type === "date" ? (a(), t(u(I), {
|
|
115
|
+
key: 9,
|
|
116
|
+
id: e.field.key,
|
|
117
|
+
"labelled-by": `${e.field.key}-label`,
|
|
118
|
+
"described-by": o.value,
|
|
119
|
+
status: e.error ? "error" : void 0,
|
|
120
|
+
"model-value": e.value,
|
|
121
|
+
placeholder: e.field.placeholder,
|
|
122
|
+
disabled: e.disabled,
|
|
123
|
+
"onUpdate:modelValue": l[8] || (l[8] = (d) => i("update", d))
|
|
124
|
+
}, null, 8, ["id", "labelled-by", "described-by", "status", "model-value", "placeholder", "disabled"])) : e.field.type === "date-range" ? (a(), t(u(R), {
|
|
125
|
+
key: 10,
|
|
126
|
+
ref_key: "rangeControl",
|
|
127
|
+
ref: n,
|
|
128
|
+
id: e.field.key,
|
|
129
|
+
"labelled-by": `${e.field.key}-label`,
|
|
130
|
+
"described-by": o.value,
|
|
131
|
+
status: e.error ? "error" : void 0,
|
|
132
|
+
"model-value": e.value,
|
|
133
|
+
disabled: e.disabled,
|
|
134
|
+
"onUpdate:modelValue": l[9] || (l[9] = (d) => i("update", d))
|
|
135
|
+
}, null, 8, ["id", "labelled-by", "described-by", "status", "model-value", "disabled"])) : e.field.type === "time" ? (a(), t(u(w), {
|
|
136
|
+
key: 11,
|
|
137
|
+
id: e.field.key,
|
|
138
|
+
"labelled-by": `${e.field.key}-label`,
|
|
139
|
+
"described-by": o.value,
|
|
140
|
+
status: e.error ? "error" : void 0,
|
|
141
|
+
"model-value": e.value,
|
|
142
|
+
placeholder: e.field.placeholder,
|
|
143
|
+
disabled: e.disabled,
|
|
144
|
+
"onUpdate:modelValue": l[10] || (l[10] = (d) => i("update", d))
|
|
145
|
+
}, null, 8, ["id", "labelled-by", "described-by", "status", "model-value", "placeholder", "disabled"])) : e.field.type === "time-range" ? (a(), t(u(A), {
|
|
146
|
+
key: 12,
|
|
147
|
+
ref_key: "rangeControl",
|
|
148
|
+
ref: n,
|
|
149
|
+
id: e.field.key,
|
|
150
|
+
"labelled-by": `${e.field.key}-label`,
|
|
151
|
+
"described-by": o.value,
|
|
152
|
+
status: e.error ? "error" : void 0,
|
|
153
|
+
"model-value": e.value,
|
|
154
|
+
disabled: e.disabled,
|
|
155
|
+
"onUpdate:modelValue": l[11] || (l[11] = (d) => i("update", d))
|
|
156
|
+
}, null, 8, ["id", "labelled-by", "described-by", "status", "model-value", "disabled"])) : (a(), t(u(G), {
|
|
157
|
+
key: 13,
|
|
158
|
+
id: e.field.key,
|
|
159
|
+
"model-value": e.value,
|
|
160
|
+
placeholder: e.field.placeholder,
|
|
161
|
+
disabled: e.disabled,
|
|
162
|
+
"aria-describedby": o.value,
|
|
163
|
+
"onUpdate:modelValue": l[12] || (l[12] = (d) => i("update", d))
|
|
164
|
+
}, null, 8, ["id", "model-value", "placeholder", "disabled", "aria-describedby"])),
|
|
165
|
+
e.error ? (a(), y("p", {
|
|
166
|
+
key: 14,
|
|
167
|
+
id: `${e.field.key}-error`,
|
|
168
|
+
class: "aheart-ai-form__field-error",
|
|
169
|
+
role: "alert"
|
|
170
|
+
}, m(e.error), 9, H)) : v("", !0)
|
|
171
|
+
], 10, j));
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
export {
|
|
175
|
+
M as default
|
|
176
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const AI_FORM_FIELD_TYPES: readonly ["input", "textarea", "number", "select", "checkbox", "radio", "switch", "date", "date-range", "time", "time-range", "upload", "tree-select"];
|
|
2
|
+
export declare const AI_FORM_CONDITION_OPERATORS: readonly ["equals", "not-equals", "includes", "not-includes", "is-empty", "is-not-empty"];
|
|
3
|
+
export type AIFormFieldType = (typeof AI_FORM_FIELD_TYPES)[number];
|
|
4
|
+
export type AIFormConditionOperator = (typeof AI_FORM_CONDITION_OPERATORS)[number];
|
|
5
|
+
export interface AIFormCondition {
|
|
6
|
+
field: string;
|
|
7
|
+
operator: AIFormConditionOperator;
|
|
8
|
+
value?: string | number | boolean | string[];
|
|
9
|
+
}
|
|
10
|
+
export interface AIFormOption {
|
|
11
|
+
label: string;
|
|
12
|
+
value: string | number;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface AIFormGroupV1 {
|
|
16
|
+
key: string;
|
|
17
|
+
title: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AIFormFieldV1 {
|
|
21
|
+
key: string;
|
|
22
|
+
label: string;
|
|
23
|
+
type: AIFormFieldType;
|
|
24
|
+
defaultValue?: unknown;
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
group?: string;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
options?: AIFormOption[];
|
|
30
|
+
visibleWhen?: AIFormCondition;
|
|
31
|
+
disabledWhen?: AIFormCondition;
|
|
32
|
+
rules?: AIFormRuleV1[];
|
|
33
|
+
dependencies?: string[];
|
|
34
|
+
preserve?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export type AIFormRuleV1 = {
|
|
37
|
+
kind: 'range';
|
|
38
|
+
valueType: 'number' | 'length';
|
|
39
|
+
min?: number;
|
|
40
|
+
max?: number;
|
|
41
|
+
message?: string;
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'format';
|
|
44
|
+
format: 'email' | 'url' | 'date' | 'time';
|
|
45
|
+
message?: string;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'compare';
|
|
48
|
+
field: string;
|
|
49
|
+
operator: 'equals' | 'not-equals' | 'greater-than' | 'greater-than-or-equal' | 'less-than' | 'less-than-or-equal';
|
|
50
|
+
message?: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'async';
|
|
53
|
+
validator: string;
|
|
54
|
+
message?: string;
|
|
55
|
+
};
|
|
56
|
+
export type AIFormAsyncValidator = (value: unknown, context: {
|
|
57
|
+
values: Readonly<Record<string, unknown>>;
|
|
58
|
+
field: AIFormFieldV1;
|
|
59
|
+
signal: AbortSignal;
|
|
60
|
+
}) => void | boolean | string | Promise<void | boolean | string>;
|
|
61
|
+
export interface AIFormSchemaV1 {
|
|
62
|
+
version: '1';
|
|
63
|
+
title?: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
groups?: AIFormGroupV1[];
|
|
66
|
+
fields: AIFormFieldV1[];
|
|
67
|
+
}
|
|
68
|
+
export interface AIFormSchemaValidation {
|
|
69
|
+
valid: boolean;
|
|
70
|
+
errors: string[];
|
|
71
|
+
schema?: AIFormSchemaV1;
|
|
72
|
+
}
|
|
73
|
+
export declare const validateAIFormSchema: (schema: unknown) => AIFormSchemaValidation;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const $ = [
|
|
2
|
+
"input",
|
|
3
|
+
"textarea",
|
|
4
|
+
"number",
|
|
5
|
+
"select",
|
|
6
|
+
"checkbox",
|
|
7
|
+
"radio",
|
|
8
|
+
"switch",
|
|
9
|
+
"date",
|
|
10
|
+
"date-range",
|
|
11
|
+
"time",
|
|
12
|
+
"time-range",
|
|
13
|
+
"upload",
|
|
14
|
+
"tree-select"
|
|
15
|
+
], b = ["equals", "not-equals", "includes", "not-includes", "is-empty", "is-not-empty"], a = (e) => typeof e == "object" && e !== null && !Array.isArray(e), u = (e) => typeof e == "string" || typeof e == "number", c = (e) => Array.isArray(e) && e.every(u), k = (e) => a(e) && typeof e.uid == "string" && typeof e.name == "string", l = (e) => {
|
|
16
|
+
if (typeof e != "string" || !/^\d{4}-\d{2}-\d{2}$/.test(e)) return !1;
|
|
17
|
+
const [t, i, o] = e.split("-").map(Number), r = new Date(Date.UTC(t, i - 1, o));
|
|
18
|
+
return r.getUTCFullYear() === t && r.getUTCMonth() === i - 1 && r.getUTCDate() === o;
|
|
19
|
+
}, h = (e) => {
|
|
20
|
+
if (typeof e != "string" || !/^\d{2}:\d{2}:\d{2}$/.test(e)) return !1;
|
|
21
|
+
const [t, i, o] = e.split(":").map(Number);
|
|
22
|
+
return t <= 23 && i <= 59 && o <= 59;
|
|
23
|
+
}, m = (e, t) => Array.isArray(e) && e.length === 2 && e.every(t), A = /* @__PURE__ */ new Set(["version", "title", "description", "groups", "fields"]), S = /* @__PURE__ */ new Set(["key", "title", "description"]), O = /* @__PURE__ */ new Set([
|
|
24
|
+
"key",
|
|
25
|
+
"label",
|
|
26
|
+
"type",
|
|
27
|
+
"defaultValue",
|
|
28
|
+
"placeholder",
|
|
29
|
+
"description",
|
|
30
|
+
"group",
|
|
31
|
+
"required",
|
|
32
|
+
"options",
|
|
33
|
+
"visibleWhen",
|
|
34
|
+
"disabledWhen",
|
|
35
|
+
"rules",
|
|
36
|
+
"dependencies",
|
|
37
|
+
"preserve"
|
|
38
|
+
]), w = /* @__PURE__ */ new Set(["label", "value", "disabled"]), T = /* @__PURE__ */ new Set(["field", "operator", "value"]), E = /* @__PURE__ */ new Set(["select", "checkbox", "radio", "tree-select"]), d = (e, t, i, o) => {
|
|
39
|
+
const r = Object.keys(e).filter((p) => !t.has(p));
|
|
40
|
+
r.length && o.push(`${i} 包含不支持的属性:${r.join("、")}`);
|
|
41
|
+
}, _ = (e, t) => t === void 0 ? !0 : e === "switch" ? typeof t == "boolean" : e === "number" ? typeof t == "number" : e === "checkbox" ? c(t) : e === "upload" ? Array.isArray(t) && t.every(k) : e === "date" ? l(t) : e === "time" ? h(t) : e === "date-range" ? m(t, l) : e === "time-range" ? m(t, h) : e === "tree-select" ? u(t) || c(t) : e === "select" || e === "radio" ? u(t) : typeof t == "string", g = (e, t, i) => !a(e) || typeof e.field != "string" || !e.field.trim() ? (i.push(`${t} 必须包含字段名`), !1) : (d(e, T, t, i), typeof e.operator != "string" || !b.includes(e.operator) ? (i.push(`${t} 包含不支持的条件操作符`), !1) : e.value !== void 0 && !u(e.value) && typeof e.value != "boolean" && !Array.isArray(e.value) ? (i.push(`${t}.value 类型不安全`), !1) : Array.isArray(e.value) && !e.value.every((o) => typeof o == "string") ? (i.push(`${t}.value 数组只能包含字符串`), !1) : !0), D = (e) => {
|
|
42
|
+
const t = [];
|
|
43
|
+
if (!a(e) || e.version !== "1" || !Array.isArray(e.fields))
|
|
44
|
+
return { valid: !1, errors: ["AIForm schema 必须是 version 为 1 的 fields 数组"] };
|
|
45
|
+
d(e, A, "schema", t), e.title !== void 0 && typeof e.title != "string" && t.push("schema.title 必须是字符串"), e.description !== void 0 && typeof e.description != "string" && t.push("schema.description 必须是字符串");
|
|
46
|
+
const i = /* @__PURE__ */ new Set();
|
|
47
|
+
e.groups !== void 0 && (Array.isArray(e.groups) ? e.groups.forEach((r, p) => {
|
|
48
|
+
const s = `groups[${p}]`;
|
|
49
|
+
if (!a(r)) {
|
|
50
|
+
t.push(`${s} 必须是对象`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
d(r, S, s, t), typeof r.key != "string" || !r.key.trim() ? t.push(`${s}.key 必须是非空字符串`) : i.has(r.key) ? t.push(`${s}.key 不能重复`) : i.add(r.key), (typeof r.title != "string" || !r.title.trim()) && t.push(`${s}.title 必须是非空字符串`), r.description !== void 0 && typeof r.description != "string" && t.push(`${s}.description 必须是字符串`);
|
|
54
|
+
}) : t.push("schema.groups 必须是数组"));
|
|
55
|
+
const o = /* @__PURE__ */ new Set();
|
|
56
|
+
return e.fields.forEach((r, p) => {
|
|
57
|
+
const s = `fields[${p}]`;
|
|
58
|
+
if (!a(r) || typeof r.key != "string" || !r.key.trim()) {
|
|
59
|
+
t.push(`${s}.key 必须是非空字符串`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
d(r, O, s, t), o.has(r.key) && t.push(`${s}.key 不能重复`), o.add(r.key), typeof r.label != "string" && t.push(`${s}.label 必须是字符串`), (typeof r.type != "string" || !$.includes(r.type)) && t.push(`${s}.type 不受支持`), r.required !== void 0 && typeof r.required != "boolean" && t.push(`${s}.required 必须是布尔值`), r.placeholder !== void 0 && typeof r.placeholder != "string" && t.push(`${s}.placeholder 必须是字符串`), r.description !== void 0 && typeof r.description != "string" && t.push(`${s}.description 必须是字符串`), r.group !== void 0 && (typeof r.group != "string" || !i.has(r.group)) && t.push(`${s}.group 必须引用已声明的分组`), _(r.type, r.defaultValue) || t.push(`${s}.defaultValue 与字段类型不兼容`), r.visibleWhen !== void 0 && g(r.visibleWhen, `${s}.visibleWhen`, t), r.disabledWhen !== void 0 && g(r.disabledWhen, `${s}.disabledWhen`, t), r.dependencies !== void 0 && (!Array.isArray(r.dependencies) || !r.dependencies.every((n) => typeof n == "string" && n.trim())) && t.push(`${s}.dependencies 必须是非空字段名数组`), r.preserve !== void 0 && typeof r.preserve != "boolean" && t.push(`${s}.preserve 必须是布尔值`), r.rules !== void 0 && (Array.isArray(r.rules) ? r.rules.forEach((n, f) => q(n, `${s}.rules[${f}]`, t)) : t.push(`${s}.rules 必须是数组`)), r.options !== void 0 && (Array.isArray(r.options) ? r.options.forEach((n, f) => {
|
|
63
|
+
!a(n) || typeof n.label != "string" || !u(n.value) || n.disabled !== void 0 && typeof n.disabled != "boolean" ? t.push(`${s}.options[${f}] 不合法`) : d(n, w, `${s}.options[${f}]`, t);
|
|
64
|
+
}) : t.push(`${s}.options 必须是数组`)), r.required === !0 && E.has(r.type) && (!Array.isArray(r.options) || !r.options.some((n) => a(n) && n.disabled !== !0)) && t.push(`${s}.options 必须为必填字段提供至少一个可用选项`);
|
|
65
|
+
}), e.fields.forEach((r, p) => {
|
|
66
|
+
if (a(r)) {
|
|
67
|
+
for (const s of ["visibleWhen", "disabledWhen"]) {
|
|
68
|
+
const n = r[s];
|
|
69
|
+
a(n) && typeof n.field == "string" && !o.has(n.field) && t.push(`fields[${p}].${s}.field 必须引用已声明的字段`);
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(r.dependencies))
|
|
72
|
+
for (const s of r.dependencies) typeof s == "string" && !o.has(s) && t.push(`fields[${p}].dependencies 必须引用已声明的字段`);
|
|
73
|
+
if (Array.isArray(r.rules))
|
|
74
|
+
for (const s of r.rules) a(s) && s.kind === "compare" && typeof s.field == "string" && !o.has(s.field) && t.push(`fields[${p}].rules.compare.field 必须引用已声明的字段`);
|
|
75
|
+
if (Array.isArray(r.rules)) {
|
|
76
|
+
for (const s of r.rules) if (a(s) && (s.kind === "range" && (s.valueType === "number" && r.type !== "number" || s.valueType === "length" && !["input", "textarea", "checkbox"].includes(String(r.type))) && t.push(`fields[${p}].rules.range 与字段类型组合不合法`), s.kind === "format" && ((s.format === "email" || s.format === "url" ? ["input", "textarea"] : s.format === "date" ? ["date"] : ["time"]).includes(String(r.type)) || t.push(`fields[${p}].rules.format 与字段类型组合不合法`)), s.kind === "compare" && typeof s.field == "string")) {
|
|
77
|
+
const n = e.fields.find((f) => a(f) && f.key === s.field);
|
|
78
|
+
n && ["greater-than", "greater-than-or-equal", "less-than", "less-than-or-equal"].includes(String(s.operator)) && (r.type === "number" && n.type === "number" || ["date", "time"].includes(String(r.type)) && r.type === n.type || t.push(`fields[${p}].rules.compare 有序比较类型不兼容`));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}), t.length ? { valid: !1, errors: t } : { valid: !0, errors: [], schema: e };
|
|
83
|
+
}, y = /* @__PURE__ */ Object.create(null);
|
|
84
|
+
Object.assign(y, {
|
|
85
|
+
range: /* @__PURE__ */ new Set(["kind", "valueType", "min", "max", "message"]),
|
|
86
|
+
format: /* @__PURE__ */ new Set(["kind", "format", "message"]),
|
|
87
|
+
compare: /* @__PURE__ */ new Set(["kind", "field", "operator", "message"]),
|
|
88
|
+
async: /* @__PURE__ */ new Set(["kind", "validator", "message"])
|
|
89
|
+
});
|
|
90
|
+
const q = (e, t, i) => {
|
|
91
|
+
if (!a(e) || typeof e.kind != "string" || !Object.prototype.hasOwnProperty.call(y, e.kind)) {
|
|
92
|
+
i.push(`${t} kind 不受支持`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (d(e, y[e.kind], t, i), e.message !== void 0 && typeof e.message != "string" && i.push(`${t}.message 必须是字符串`), e.kind === "range") {
|
|
96
|
+
e.valueType !== "number" && e.valueType !== "length" && i.push(`${t}.valueType 不受支持`), e.min === void 0 && e.max === void 0 && i.push(`${t} 至少需要一个范围边界`);
|
|
97
|
+
for (const o of ["min", "max"]) e[o] !== void 0 && (typeof e[o] != "number" || !Number.isFinite(e[o])) && i.push(`${t}.${o} 必须是有限数字`);
|
|
98
|
+
typeof e.min == "number" && typeof e.max == "number" && e.min > e.max && i.push(`${t} min 不能大于 max`);
|
|
99
|
+
} else e.kind === "format" ? ["email", "url", "date", "time"].includes(String(e.format)) || i.push(`${t}.format 不受支持`) : e.kind === "compare" ? ((typeof e.field != "string" || !e.field.trim()) && i.push(`${t}.field 必须是字段名`), ["equals", "not-equals", "greater-than", "greater-than-or-equal", "less-than", "less-than-or-equal"].includes(String(e.operator)) || i.push(`${t}.operator 不受支持`)) : (typeof e.validator != "string" || !/^[A-Za-z][A-Za-z0-9_-]*$/.test(e.validator)) && i.push(`${t}.validator 必须是安全名称`);
|
|
100
|
+
};
|
|
101
|
+
export {
|
|
102
|
+
b as AI_FORM_CONDITION_OPERATORS,
|
|
103
|
+
$ as AI_FORM_FIELD_TYPES,
|
|
104
|
+
D as validateAIFormSchema
|
|
105
|
+
};
|
package/es/form.vue.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type AIFormAsyncValidator } from './form-schema';
|
|
2
|
+
declare const _default: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
+
modelValue?: Record<string, unknown> | undefined;
|
|
4
|
+
schema: unknown;
|
|
5
|
+
disabled?: boolean | undefined;
|
|
6
|
+
submitting?: boolean | undefined;
|
|
7
|
+
submitText?: string | undefined;
|
|
8
|
+
submitError?: string | undefined;
|
|
9
|
+
validators?: Record<string, AIFormAsyncValidator> | undefined;
|
|
10
|
+
}>, {
|
|
11
|
+
modelValue: () => {};
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
submitting: boolean;
|
|
14
|
+
submitText: string;
|
|
15
|
+
submitError: undefined;
|
|
16
|
+
validators: () => {};
|
|
17
|
+
}>>, {
|
|
18
|
+
validate: () => Promise<any>;
|
|
19
|
+
resetFields: () => void;
|
|
20
|
+
clearValidate: (names?: string[] | undefined) => void;
|
|
21
|
+
setFieldsErrors: (fields: {
|
|
22
|
+
name: string;
|
|
23
|
+
errors: string[];
|
|
24
|
+
}[]) => void;
|
|
25
|
+
}, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {
|
|
26
|
+
submit: (value: Record<string, unknown>) => void;
|
|
27
|
+
"update:modelValue": (value: Record<string, unknown>) => void;
|
|
28
|
+
"schema-error": (errors: string[]) => void;
|
|
29
|
+
"validation-error": (errors: {
|
|
30
|
+
key: string;
|
|
31
|
+
message: string;
|
|
32
|
+
}[]) => void;
|
|
33
|
+
}, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
34
|
+
modelValue?: Record<string, unknown> | undefined;
|
|
35
|
+
schema: unknown;
|
|
36
|
+
disabled?: boolean | undefined;
|
|
37
|
+
submitting?: boolean | undefined;
|
|
38
|
+
submitText?: string | undefined;
|
|
39
|
+
submitError?: string | undefined;
|
|
40
|
+
validators?: Record<string, AIFormAsyncValidator> | undefined;
|
|
41
|
+
}>, {
|
|
42
|
+
modelValue: () => {};
|
|
43
|
+
disabled: boolean;
|
|
44
|
+
submitting: boolean;
|
|
45
|
+
submitText: string;
|
|
46
|
+
submitError: undefined;
|
|
47
|
+
validators: () => {};
|
|
48
|
+
}>>> & Readonly<{
|
|
49
|
+
onSubmit?: ((value: Record<string, unknown>) => any) | undefined;
|
|
50
|
+
"onUpdate:modelValue"?: ((value: Record<string, unknown>) => any) | undefined;
|
|
51
|
+
"onSchema-error"?: ((errors: string[]) => any) | undefined;
|
|
52
|
+
"onValidation-error"?: ((errors: {
|
|
53
|
+
key: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}[]) => any) | undefined;
|
|
56
|
+
}>, {
|
|
57
|
+
disabled: boolean;
|
|
58
|
+
modelValue: Record<string, unknown>;
|
|
59
|
+
submitting: boolean;
|
|
60
|
+
submitText: string;
|
|
61
|
+
submitError: string;
|
|
62
|
+
validators: Record<string, AIFormAsyncValidator>;
|
|
63
|
+
}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
|
|
64
|
+
export default _default;
|
|
65
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
66
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
67
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
68
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
69
|
+
} : {
|
|
70
|
+
type: import('vue').PropType<T[K]>;
|
|
71
|
+
required: true;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
type __VLS_WithDefaults<P, D> = {
|
|
75
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
76
|
+
default: D[K];
|
|
77
|
+
}> : P[K];
|
|
78
|
+
};
|
|
79
|
+
type __VLS_Prettify<T> = {
|
|
80
|
+
[K in keyof T]: T[K];
|
|
81
|
+
} & {};
|