kui-vue 6.0.0 → 6.2.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/AI.en-US.md +21 -1
- package/AI.md +37 -1
- package/ai/behaviors.json +82 -0
- package/ai/evals/README.md +59 -0
- package/ai/evals/cases.json +91 -24
- package/ai/evals/config.json +4 -0
- package/ai/evals/evaluate.mjs +267 -0
- package/ai/evals/run.mjs +118 -0
- package/ai/kui-components.json +7894 -955
- package/ai/kui-components.schema.json +67 -0
- package/ai/mcp.mjs +210 -166
- package/ai/skills/kui-vue/SKILL.md +2 -1
- package/ai/skills/kui-vue/references/mcp.md +12 -12
- package/ai/templates/form.vue +49 -0
- package/ai/templates/index.json +23 -0
- package/ai/templates/modal-editor.vue +59 -0
- package/ai/templates/table.vue +63 -0
- package/ai/validate.mjs +225 -0
- package/dist/index.js +2 -2
- package/es/index.js +2180 -2179
- package/es/locale/de.js +1 -1
- package/es/locale/el.js +1 -1
- package/es/locale/en.js +1 -1
- package/es/locale/fr.js +1 -1
- package/es/locale/it.js +1 -1
- package/es/locale/ja.js +1 -1
- package/es/locale/ko.js +1 -1
- package/es/locale/ru.js +1 -1
- package/es/locale/th.js +1 -1
- package/es/locale/uk.js +1 -1
- package/es/locale/vi.js +1 -1
- package/es/locale/zh-CN.js +1 -1
- package/es/locale/zh-TW.js +1 -1
- package/lib/index.cjs +2 -2
- package/lib/locale/de.cjs +1 -1
- package/lib/locale/el.cjs +1 -1
- package/lib/locale/en.cjs +1 -1
- package/lib/locale/fr.cjs +1 -1
- package/lib/locale/it.cjs +1 -1
- package/lib/locale/ja.cjs +1 -1
- package/lib/locale/ko.cjs +1 -1
- package/lib/locale/ru.cjs +1 -1
- package/lib/locale/th.cjs +1 -1
- package/lib/locale/uk.cjs +1 -1
- package/lib/locale/vi.cjs +1 -1
- package/lib/locale/zh-CN.cjs +1 -1
- package/lib/locale/zh-TW.cjs +1 -1
- package/package.json +37 -31
- package/style/base.css +1 -1
- package/style/components.css +2 -2
- package/style/index.css +2 -2
- package/style/motion.css +1 -1
- package/style/theme.css +2 -2
- package/types/affix/index.d.ts +5 -5
- package/types/alert/index.d.ts +9 -7
- package/types/anchor/anchor-link.d.ts +4 -4
- package/types/anchor/anchor.d.ts +6 -6
- package/types/anchor/context.d.ts +1 -1
- package/types/anchor/index.d.ts +4 -4
- package/types/auto-complete/index.d.ts +7 -11
- package/types/avatar/avatar-group.d.ts +5 -5
- package/types/avatar/avatar.d.ts +6 -6
- package/types/avatar/context.d.ts +1 -1
- package/types/avatar/index.d.ts +4 -4
- package/types/back-top/index.d.ts +5 -5
- package/types/badge/index.d.ts +6 -6
- package/types/base/transition.d.ts +1 -1
- package/types/breadcrumb/breadcrumb-item.d.ts +6 -6
- package/types/breadcrumb/breadcrumb.d.ts +4 -4
- package/types/breadcrumb/index.d.ts +4 -4
- package/types/button/button-group.d.ts +5 -5
- package/types/button/button.d.ts +4 -4
- package/types/button/index.d.ts +4 -4
- package/types/calendar/index.d.ts +8 -5
- package/types/card/card-meta.d.ts +4 -4
- package/types/card/index.d.ts +8 -8
- package/types/carousel/carousel-item.d.ts +1 -1
- package/types/carousel/carousel.d.ts +20 -7
- package/types/carousel/index.d.ts +3 -3
- package/types/cascader/index.d.ts +41 -32
- package/types/cascader/types.d.ts +7 -3
- package/types/check-card/check-card-group.d.ts +10 -7
- package/types/check-card/check-card.d.ts +21 -8
- package/types/check-card/context.d.ts +3 -3
- package/types/check-card/index.d.ts +5 -5
- package/types/check-card/types.d.ts +2 -2
- package/types/checkbox/checkbox-group.d.ts +20 -7
- package/types/checkbox/checkbox.d.ts +4 -3
- package/types/checkbox/index.d.ts +5 -5
- package/types/collapse/collapse-panel.d.ts +6 -6
- package/types/collapse/collapse.d.ts +7 -7
- package/types/collapse/context.d.ts +1 -1
- package/types/collapse/index.d.ts +4 -4
- package/types/color-picker/alpha.d.ts +10 -6
- package/types/color-picker/hue.d.ts +7 -4
- package/types/color-picker/index.d.ts +34 -20
- package/types/color-picker/mode.d.ts +9 -9
- package/types/color-picker/paint.d.ts +9 -6
- package/types/color-picker/presets.d.ts +7 -7
- package/types/color-picker/types.d.ts +1 -0
- package/types/components.d.ts +166 -161
- package/types/config/context.d.ts +2 -2
- package/types/config/index.d.ts +7 -7
- package/types/config/popup.d.ts +1 -1
- package/types/const/types.d.ts +2 -2
- package/types/date-picker/index.d.ts +49 -19
- package/types/descriptions/descriptions-item.d.ts +5 -5
- package/types/descriptions/descriptions.d.ts +5 -5
- package/types/descriptions/index.d.ts +4 -2
- package/types/directives/outsiteclick.d.ts +1 -1
- package/types/directives/resize.d.ts +1 -1
- package/types/directives/scroll.d.ts +1 -1
- package/types/divider/index.d.ts +5 -5
- package/types/drawer/index.d.ts +24 -11
- package/types/dropdown/dropdown-button.d.ts +7 -7
- package/types/dropdown/dropdown.d.ts +12 -16
- package/types/dropdown/index.d.ts +4 -2
- package/types/dropdown/trigger.d.ts +6 -6
- package/types/empty/index.d.ts +1 -1
- package/types/feature-card/index.d.ts +7 -7
- package/types/feedback-panel/feedback-panel.d.ts +7 -7
- package/types/feedback-panel/index.d.ts +3 -3
- package/types/flame-wrap/index.d.ts +9 -9
- package/types/flex/index.d.ts +7 -7
- package/types/flex/types.d.ts +1 -1
- package/types/form/context.d.ts +3 -3
- package/types/form/form-item.d.ts +6 -6
- package/types/form/form.d.ts +9 -13
- package/types/form/index.d.ts +6 -6
- package/types/global.d.ts +2 -0
- package/types/grid/grid-item.d.ts +2 -2
- package/types/grid/grid.d.ts +3 -3
- package/types/grid/index.d.ts +5 -5
- package/types/grid/useBreakpoint.d.ts +1 -1
- package/types/icon/index.d.ts +8 -8
- package/types/image/context.d.ts +2 -2
- package/types/image/group.d.ts +4 -4
- package/types/image/image.d.ts +7 -7
- package/types/image/index.d.ts +5 -5
- package/types/image/instance.d.ts +11 -4
- package/types/image/preview.d.ts +6 -6
- package/types/index.d.cts +2 -2
- package/types/index.d.ts +2 -2
- package/types/input/index.d.ts +6 -6
- package/types/input/input-box.d.ts +6 -6
- package/types/input/input-group.d.ts +5 -5
- package/types/input/input.d.ts +27 -10
- package/types/input/textarea.d.ts +17 -8
- package/types/input-number/index.d.ts +10 -7
- package/types/input-otp/index.d.ts +3 -3
- package/types/input-otp/input-otp.d.ts +21 -8
- package/types/input-tag/index.d.ts +6 -6
- package/types/kanban/index.d.ts +5 -5
- package/types/layout/index.d.ts +17 -17
- package/types/list-panel/index.d.ts +7 -7
- package/types/mentions/index.d.ts +7 -7
- package/types/menu/index.d.ts +6 -6
- package/types/menu/menu-context.d.ts +4 -2
- package/types/menu/menu-divider.d.ts +1 -1
- package/types/menu/menu-group.d.ts +4 -4
- package/types/menu/menu-item.d.ts +10 -6
- package/types/menu/menu.d.ts +24 -17
- package/types/menu/recursive-menu.d.ts +5 -5
- package/types/menu/sub-menu.d.ts +6 -6
- package/types/menu/types.d.ts +2 -2
- package/types/message/index.d.ts +3 -3
- package/types/modal/index.d.ts +15 -10
- package/types/modal/modal.d.ts +25 -97
- package/types/modal/toast.d.ts +11 -10
- package/types/notice/container.d.ts +3 -3
- package/types/notice/content.d.ts +10 -77
- package/types/notice/index.d.ts +3 -3
- package/types/notice/instance.d.ts +2 -2
- package/types/page/index.d.ts +6 -6
- package/types/page-header/index.d.ts +4 -4
- package/types/popconfirm/index.d.ts +8 -45
- package/types/poptip/index.d.ts +9 -47
- package/types/popup/index.d.ts +251 -0
- package/types/popup/layers.d.ts +9 -0
- package/types/popup/types.d.ts +15 -0
- package/types/progress/index.d.ts +6 -6
- package/types/qrcode/index.d.ts +7 -7
- package/types/radio/index.d.ts +8 -7
- package/types/radio/radio-button.d.ts +8 -8
- package/types/radio/radio-group.d.ts +4 -3
- package/types/radio/radio.d.ts +7 -7
- package/types/radio/types.d.ts +1 -1
- package/types/rate/index.d.ts +7 -7
- package/types/rate/star.d.ts +7 -7
- package/types/result/index.d.ts +3 -3
- package/types/result/result.d.ts +7 -7
- package/types/ripple/index.d.ts +6 -6
- package/types/row-col/col.d.ts +4 -4
- package/types/row-col/index.d.ts +4 -4
- package/types/row-col/row.d.ts +4 -4
- package/types/segmented/index.d.ts +6 -4
- package/types/select/index.d.ts +5 -5
- package/types/select/option.d.ts +13 -14
- package/types/select/select.d.ts +10 -6
- package/types/select/types.d.ts +1 -1
- package/types/skeleton/index.d.ts +10 -10
- package/types/skeleton/skeleton-avatar.d.ts +13 -13
- package/types/skeleton/skeleton-button.d.ts +15 -15
- package/types/skeleton/skeleton-image.d.ts +11 -11
- package/types/skeleton/skeleton-text.d.ts +11 -11
- package/types/skeleton/skeleton.d.ts +15 -15
- package/types/skeleton/types.d.ts +2 -2
- package/types/skeleton/use-skeleton-loading.d.ts +1 -1
- package/types/slider/index.d.ts +8 -3
- package/types/slider/thumb.d.ts +7 -7
- package/types/space/index.d.ts +4 -4
- package/types/spin/index.d.ts +18 -5
- package/types/splitter/index.d.ts +2 -2
- package/types/splitter/splitter-panel.d.ts +4 -4
- package/types/splitter/splitter.d.ts +6 -6
- package/types/stat-card/countup.d.ts +4 -4
- package/types/stat-card/index.d.ts +5 -5
- package/types/stat-card/rollup.d.ts +6 -4
- package/types/stat-card/stat-card.d.ts +7 -7
- package/types/stat-card/stat-number.d.ts +19 -6
- package/types/stat-card/types.d.ts +1 -1
- package/types/stat-card/utils/countup.d.ts +1 -1
- package/types/stat-card/utils/odometer.d.ts +8 -5
- package/types/steps/index.d.ts +8 -8
- package/types/switch/index.d.ts +3 -2
- package/types/table/column-setting.d.ts +7 -7
- package/types/table/index.d.ts +13 -26
- package/types/table/types.d.ts +2 -2
- package/types/table/utils.d.ts +1 -1
- package/types/tabs/index.d.ts +5 -4
- package/types/tabs/tab-panel.d.ts +6 -6
- package/types/tabs/tabs.d.ts +6 -6
- package/types/tabs/types.d.ts +1 -1
- package/types/tag/index.d.ts +9 -7
- package/types/time-line/index.d.ts +5 -5
- package/types/time-line/timeline-item.d.ts +5 -5
- package/types/time-line/timeline.d.ts +6 -6
- package/types/tooltip/index.d.ts +21 -35
- package/types/tour/index.d.ts +34 -23
- package/types/transfer/index.d.ts +18 -5
- package/types/tree/context.d.ts +1 -1
- package/types/tree/index.d.ts +13 -10
- package/types/tree/types.d.ts +1 -1
- package/types/tree/utils.d.ts +1 -1
- package/types/tree-select/index.d.ts +14 -7
- package/types/typography/index.d.ts +26 -17
- package/types/upload/file-list.d.ts +8 -8
- package/types/upload/index.d.ts +9 -22
- package/types/upload/picture-sort.d.ts +2 -0
- package/types/upload/selector.d.ts +9 -9
- package/types/upload/types.d.ts +1 -1
- package/types/utils/checked.d.ts +1 -1
- package/types/utils/model-value.d.ts +10 -0
- package/types/utils/number.d.ts +1 -1
- package/types/utils/placement.d.ts +1 -1
- package/types/utils/popup.d.ts +11 -0
- package/types/utils/selection-tags.d.ts +18 -0
- package/types/utils/vnode.d.ts +3 -3
- package/types/utils/vue.d.ts +7 -1
- package/types/virtual-list/index.d.ts +6 -6
- package/types/watermark/index.d.ts +8 -8
- package/vetur/attributes.json +1717 -781
- package/vetur/tags.json +359 -159
- package/vetur/web-types.json +7563 -6197
- package/types/directives/transfer.d.ts +0 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { reactive, ref } from "vue";
|
|
3
|
+
import { Button, Form, FormItem, Input, Modal, Space, type FormSubmitEvent } from "kui-vue";
|
|
4
|
+
|
|
5
|
+
const saved = ref({ name: "示例用户" });
|
|
6
|
+
const model = reactive({ name: "" });
|
|
7
|
+
const visible = ref(false);
|
|
8
|
+
const saving = ref(false);
|
|
9
|
+
const error = ref("");
|
|
10
|
+
const session = ref(0);
|
|
11
|
+
const rules = { name: [{ required: true, message: "请输入姓名" }] };
|
|
12
|
+
function open(create: boolean) {
|
|
13
|
+
model.name = create ? "" : saved.value.name;
|
|
14
|
+
error.value = "";
|
|
15
|
+
session.value++;
|
|
16
|
+
visible.value = true;
|
|
17
|
+
}
|
|
18
|
+
async function save({ valid }: FormSubmitEvent) {
|
|
19
|
+
if (!valid || saving.value) return;
|
|
20
|
+
saving.value = true;
|
|
21
|
+
error.value = "";
|
|
22
|
+
try {
|
|
23
|
+
const payload = { ...model };
|
|
24
|
+
// Replace this local mock with a create/update API request.
|
|
25
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
26
|
+
saved.value = payload;
|
|
27
|
+
visible.value = false;
|
|
28
|
+
} catch {
|
|
29
|
+
error.value = "保存失败,请重试";
|
|
30
|
+
} finally {
|
|
31
|
+
saving.value = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<template>
|
|
37
|
+
<Space>
|
|
38
|
+
<Button @click="open(true)">新增</Button>
|
|
39
|
+
<Button @click="open(false)">编辑</Button>
|
|
40
|
+
<span>{{ saved.name }}</span>
|
|
41
|
+
</Space>
|
|
42
|
+
<Modal v-model="visible" title="用户编辑" :footer="false" :loading="saving">
|
|
43
|
+
<Form
|
|
44
|
+
:key="session"
|
|
45
|
+
:model="model"
|
|
46
|
+
:rules="rules"
|
|
47
|
+
:disabled="saving"
|
|
48
|
+
layout="vertical"
|
|
49
|
+
@submit="save"
|
|
50
|
+
>
|
|
51
|
+
<FormItem label="姓名" prop="name"><Input /></FormItem>
|
|
52
|
+
<p v-if="error" role="alert">{{ error }}</p>
|
|
53
|
+
<Space>
|
|
54
|
+
<Button type="primary" html-type="submit" :loading="saving" :disabled="saving">保存</Button>
|
|
55
|
+
<Button :disabled="saving" @click="visible = false">取消</Button>
|
|
56
|
+
</Space>
|
|
57
|
+
</Form>
|
|
58
|
+
</Modal>
|
|
59
|
+
</template>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onBeforeUnmount, ref, watch } from "vue";
|
|
3
|
+
import { Button, Input, Page, Space, Table } from "kui-vue";
|
|
4
|
+
|
|
5
|
+
type Row = { id: number; name: string };
|
|
6
|
+
const allRows: Row[] = Array.from({ length: 47 }, (_, index) => ({
|
|
7
|
+
id: index + 1,
|
|
8
|
+
name: `用户 ${index + 1}`,
|
|
9
|
+
}));
|
|
10
|
+
const columns = [
|
|
11
|
+
{ title: "编号", key: "id" },
|
|
12
|
+
{ title: "姓名", key: "name" },
|
|
13
|
+
];
|
|
14
|
+
const keyword = ref("");
|
|
15
|
+
const query = ref("");
|
|
16
|
+
const page = ref(1);
|
|
17
|
+
const pageSize = ref(10);
|
|
18
|
+
const data = ref<Row[]>([]);
|
|
19
|
+
const total = ref(0);
|
|
20
|
+
const loading = ref(false);
|
|
21
|
+
const error = ref("");
|
|
22
|
+
let requestId = 0;
|
|
23
|
+
|
|
24
|
+
async function load() {
|
|
25
|
+
const id = ++requestId;
|
|
26
|
+
loading.value = true;
|
|
27
|
+
error.value = "";
|
|
28
|
+
const params = { query: query.value, page: page.value, pageSize: pageSize.value };
|
|
29
|
+
try {
|
|
30
|
+
// Replace this local mock with your paginated API returning { data, total }.
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
32
|
+
const rows = allRows.filter((row) => row.name.includes(params.query));
|
|
33
|
+
if (id !== requestId) return;
|
|
34
|
+
total.value = rows.length;
|
|
35
|
+
data.value = rows.slice((params.page - 1) * params.pageSize, params.page * params.pageSize);
|
|
36
|
+
} catch {
|
|
37
|
+
if (id === requestId) error.value = "加载失败,请重试";
|
|
38
|
+
} finally {
|
|
39
|
+
if (id === requestId) loading.value = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function search() {
|
|
43
|
+
query.value = keyword.value.trim();
|
|
44
|
+
page.value = 1;
|
|
45
|
+
}
|
|
46
|
+
watch([query, page, pageSize], load, { immediate: true });
|
|
47
|
+
onBeforeUnmount(() => {
|
|
48
|
+
requestId++;
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<Space vertical block>
|
|
54
|
+
<Space>
|
|
55
|
+
<Input v-model="keyword" placeholder="搜索姓名" />
|
|
56
|
+
<Button type="primary" @click="search">搜索</Button>
|
|
57
|
+
<Button :disabled="loading" @click="load">刷新</Button>
|
|
58
|
+
</Space>
|
|
59
|
+
<p v-if="error" role="alert">{{ error }}</p>
|
|
60
|
+
<Table :columns="columns" :data="data" :loading="loading" />
|
|
61
|
+
<Page v-model:page="page" v-model:pageSize="pageSize" :total="total" show-sizer />
|
|
62
|
+
</Space>
|
|
63
|
+
</template>
|
package/ai/validate.mjs
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { baseParse, ElementTypes, NodeTypes, parserOptions } from "@vue/compiler-dom";
|
|
2
|
+
|
|
3
|
+
const canonical = (name) => name.replace(/-/g, "").toLowerCase();
|
|
4
|
+
const nativeEvents = new Set([
|
|
5
|
+
"click",
|
|
6
|
+
"dblclick",
|
|
7
|
+
"focus",
|
|
8
|
+
"blur",
|
|
9
|
+
"focusin",
|
|
10
|
+
"focusout",
|
|
11
|
+
"keydown",
|
|
12
|
+
"keyup",
|
|
13
|
+
"keypress",
|
|
14
|
+
"mouseenter",
|
|
15
|
+
"mouseleave",
|
|
16
|
+
"mousemove",
|
|
17
|
+
"mousedown",
|
|
18
|
+
"mouseup",
|
|
19
|
+
"pointerdown",
|
|
20
|
+
"pointerup",
|
|
21
|
+
"input",
|
|
22
|
+
"change",
|
|
23
|
+
"submit",
|
|
24
|
+
"reset",
|
|
25
|
+
"scroll",
|
|
26
|
+
"wheel",
|
|
27
|
+
"contextmenu",
|
|
28
|
+
"dragstart",
|
|
29
|
+
"dragend",
|
|
30
|
+
"drop",
|
|
31
|
+
]);
|
|
32
|
+
const attributes = new Set([
|
|
33
|
+
"class",
|
|
34
|
+
"style",
|
|
35
|
+
"id",
|
|
36
|
+
"key",
|
|
37
|
+
"ref",
|
|
38
|
+
"role",
|
|
39
|
+
"title",
|
|
40
|
+
"tabindex",
|
|
41
|
+
"name",
|
|
42
|
+
"type",
|
|
43
|
+
"autofocus",
|
|
44
|
+
"autocomplete",
|
|
45
|
+
"placeholder",
|
|
46
|
+
"maxlength",
|
|
47
|
+
"minlength",
|
|
48
|
+
"min",
|
|
49
|
+
"max",
|
|
50
|
+
"step",
|
|
51
|
+
"pattern",
|
|
52
|
+
"inputmode",
|
|
53
|
+
"accept",
|
|
54
|
+
"rows",
|
|
55
|
+
"cols",
|
|
56
|
+
"readonly",
|
|
57
|
+
"required",
|
|
58
|
+
"for",
|
|
59
|
+
"href",
|
|
60
|
+
"target",
|
|
61
|
+
"rel",
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
// Deliberately never evaluate user expressions. Only unambiguous literals are checked.
|
|
65
|
+
const literal = (expression) => {
|
|
66
|
+
const text = expression?.trim() || "";
|
|
67
|
+
if (/^(true|false|null|-?\d+(?:\.\d+)?)$/.test(text))
|
|
68
|
+
return { known: true, value: JSON.parse(text) };
|
|
69
|
+
if (/^"(?:[^"\\]|\\.)*"$/.test(text)) return { known: true, value: JSON.parse(text) };
|
|
70
|
+
if (/^'[^'\\]*'$/.test(text)) return { known: true, value: text.slice(1, -1) };
|
|
71
|
+
return { known: false };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export function validateUsage(source, metadata) {
|
|
75
|
+
const tags = new Map(
|
|
76
|
+
metadata.components.flatMap((c) => [c.name, ...c.tags].map((t) => [t.toLowerCase(), c])),
|
|
77
|
+
);
|
|
78
|
+
const issues = [];
|
|
79
|
+
const skipped = [];
|
|
80
|
+
const add = (kind, message, node, extra = {}) =>
|
|
81
|
+
issues.push({
|
|
82
|
+
kind,
|
|
83
|
+
message,
|
|
84
|
+
line: node.loc?.start.line,
|
|
85
|
+
column: node.loc?.start.column,
|
|
86
|
+
...extra,
|
|
87
|
+
});
|
|
88
|
+
let ast;
|
|
89
|
+
try {
|
|
90
|
+
ast = baseParse(source, {
|
|
91
|
+
...parserOptions,
|
|
92
|
+
onError: (error) => add("syntax", error.message, error),
|
|
93
|
+
parseMode: "html",
|
|
94
|
+
});
|
|
95
|
+
} catch (error) {
|
|
96
|
+
add("syntax", error.message, error);
|
|
97
|
+
return { valid: false, issues, skipped, scope: "static-template", complete: false };
|
|
98
|
+
}
|
|
99
|
+
const visit = (node, owner) => {
|
|
100
|
+
if (node.type !== NodeTypes.ELEMENT) {
|
|
101
|
+
node.children?.forEach((child) => visit(child, owner));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (["script", "style"].includes(node.tag.toLowerCase())) return;
|
|
105
|
+
const component =
|
|
106
|
+
node.tagType === ElementTypes.COMPONENT ? tags.get(node.tag.toLowerCase()) : undefined;
|
|
107
|
+
if (component) {
|
|
108
|
+
const props = new Map(
|
|
109
|
+
component.props.filter((p) => !p.eventName).map((p) => [canonical(p.name), p]),
|
|
110
|
+
);
|
|
111
|
+
const events = new Set(component.events.map((e) => canonical(e.name)));
|
|
112
|
+
const present = new Set();
|
|
113
|
+
let spread = false;
|
|
114
|
+
for (const attr of node.props) {
|
|
115
|
+
if (attr.type === NodeTypes.DIRECTIVE && attr.name === "on") {
|
|
116
|
+
if (!attr.arg?.isStatic) {
|
|
117
|
+
skipped.push("dynamic events");
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const event = attr.arg.content;
|
|
121
|
+
if (!events.has(canonical(event)) && !nativeEvents.has(event.toLowerCase()))
|
|
122
|
+
add("event", `Unknown event ${event} on ${component.name}`, attr, {
|
|
123
|
+
component: component.name,
|
|
124
|
+
event,
|
|
125
|
+
});
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
let name;
|
|
129
|
+
let value = { known: false };
|
|
130
|
+
if (attr.type === NodeTypes.ATTRIBUTE) {
|
|
131
|
+
name = attr.name;
|
|
132
|
+
value = { known: true, value: attr.value?.content ?? "" };
|
|
133
|
+
} else if (attr.type === NodeTypes.DIRECTIVE && ["bind", "model"].includes(attr.name)) {
|
|
134
|
+
if ((attr.arg && !attr.arg.isStatic) || (attr.name === "bind" && !attr.arg)) {
|
|
135
|
+
spread = true;
|
|
136
|
+
skipped.push("dynamic or spread bindings");
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
name = attr.arg?.content || "modelValue";
|
|
140
|
+
if (attr.name === "model") {
|
|
141
|
+
if (!events.has(canonical(`update:${name}`)))
|
|
142
|
+
add("model", `No update:${name} event on ${component.name}`, attr, {
|
|
143
|
+
component: component.name,
|
|
144
|
+
prop: name,
|
|
145
|
+
});
|
|
146
|
+
} else value = literal(attr.exp?.content);
|
|
147
|
+
if (!value.known) skipped.push("binding expression types");
|
|
148
|
+
}
|
|
149
|
+
if (!name) continue;
|
|
150
|
+
present.add(canonical(name));
|
|
151
|
+
const prop = props.get(canonical(name));
|
|
152
|
+
if (!prop) {
|
|
153
|
+
if (!attributes.has(name.toLowerCase()) && !/^(aria-|data-)/i.test(name))
|
|
154
|
+
add("prop", `Unknown prop ${name} on ${component.name}`, attr, {
|
|
155
|
+
component: component.name,
|
|
156
|
+
prop: name,
|
|
157
|
+
});
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!value.known) continue;
|
|
161
|
+
// Bare boolean attributes are valid; string "false" is not a false boolean.
|
|
162
|
+
const actual =
|
|
163
|
+
prop.boolean && value.value === "" && attr.type === NodeTypes.ATTRIBUTE
|
|
164
|
+
? true
|
|
165
|
+
: value.value;
|
|
166
|
+
if (prop.enumValues && !prop.enumValues.includes(actual))
|
|
167
|
+
add(
|
|
168
|
+
"value",
|
|
169
|
+
`Invalid ${name} on ${component.name}; expected ${prop.enumValues.map((v) => JSON.stringify(v)).join(" | ")}`,
|
|
170
|
+
attr,
|
|
171
|
+
{ component: component.name, prop: name },
|
|
172
|
+
);
|
|
173
|
+
else if (prop.boolean && typeof actual !== "boolean")
|
|
174
|
+
add("value", `${name} requires a boolean binding`, attr, {
|
|
175
|
+
component: component.name,
|
|
176
|
+
prop: name,
|
|
177
|
+
});
|
|
178
|
+
else if (/^number(?: \| undefined)?$/.test(prop.type) && typeof actual !== "number")
|
|
179
|
+
add("value", `${name} requires a numeric binding`, attr, {
|
|
180
|
+
component: component.name,
|
|
181
|
+
prop: name,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (!spread)
|
|
185
|
+
for (const prop of props.values())
|
|
186
|
+
if (prop.required && !present.has(canonical(prop.name)))
|
|
187
|
+
add("required", `Missing required prop ${prop.name} on ${component.name}`, node, {
|
|
188
|
+
component: component.name,
|
|
189
|
+
prop: prop.name,
|
|
190
|
+
});
|
|
191
|
+
} else if (node.tagType === ElementTypes.COMPONENT)
|
|
192
|
+
skipped.push(`unresolved component: ${node.tag}`);
|
|
193
|
+
const slotOwner = node.tag === "template" ? owner : component;
|
|
194
|
+
for (const attr of node.props) {
|
|
195
|
+
if (attr.type !== NodeTypes.DIRECTIVE || attr.name !== "slot") continue;
|
|
196
|
+
if (!slotOwner?.behavior?.slotsComplete) {
|
|
197
|
+
skipped.push("slots without a complete contract");
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (attr.arg && !attr.arg.isStatic) {
|
|
201
|
+
skipped.push("dynamic slots");
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const name = attr.arg?.content || "default";
|
|
205
|
+
if (!slotOwner.behavior.slots.includes(name))
|
|
206
|
+
add("slot", `Unknown slot ${name} on ${slotOwner.name}`, attr, {
|
|
207
|
+
component: slotOwner.name,
|
|
208
|
+
slot: name,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
node.children.forEach((child) =>
|
|
212
|
+
visit(child, component || (node.tag === "template" ? owner : undefined)),
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
visit(ast);
|
|
216
|
+
return {
|
|
217
|
+
valid: issues.length === 0,
|
|
218
|
+
issues,
|
|
219
|
+
skipped: [...new Set(skipped)],
|
|
220
|
+
scope: "static-template",
|
|
221
|
+
complete: false,
|
|
222
|
+
nextStep:
|
|
223
|
+
"Run the application's vue-tsc --noEmit and interaction tests. Static checks do not validate imports, arbitrary expressions or runtime behavior.",
|
|
224
|
+
};
|
|
225
|
+
}
|