inquirer-form 0.1.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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ag-form Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # inquirer-form
2
+
3
+ `inquirer-form` 是一套面向 [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) 的可视化表单设计/运行组件,构建在 `agilebuilder-form` 之上,帮助团队快速把「拖拽式 Schema」同步成 Inquirer `QuestionCollection` 并在 Web 端模拟 prompt 交互。
4
+
5
+ ## 功能亮点
6
+
7
+ - 🧱 Inquirer 专属控件集(input、password、list、checkbox、editor…),可与自定义控件混用
8
+ - 🛠️ `<InquirerFormDesigner>` 拖拽式设计器,内置 Schema 引擎与快照
9
+ - 🧪 `<InquirerFormRuntime>` Web 运行态,实时渲染与数据回写
10
+ - 🔁 `schemaToInquirer` 等工具方法,一键生成 QuestionCollection
11
+ - 🧑‍💻 `<InquirerFormPlayground>` Playground 组件,便于演示与交互测试
12
+
13
+ ## 环境要求
14
+
15
+ - Node.js ≥ `20.19.0`(或 ≥ `22.12.0`)
16
+ - 包管理器:`npm`(亦可兼容 `pnpm`、`yarn`,命令需自适应)
17
+ - 需要在宿主应用中安装的 peerDependencies:
18
+ - `vue@^3.5`
19
+ - `element-plus@^2.11`
20
+ - `vuedraggable@^4.1`
21
+
22
+ ## 安装
23
+
24
+ ```bash
25
+ npm install inquirer-form
26
+
27
+ # 如同级有 agilebuilder-form,可直接引用本地版本
28
+ npm install agilebuilder-form@file:../ag_form
29
+ ```
30
+
31
+ > 仓库默认把 `agilebuilder-form` 指向 `file:../ag_form`,便于与主库联调;发布到 npm 时无需额外处理。
32
+
33
+ ## 快速开始
34
+
35
+ ```ts
36
+ import { registerInquirerControls } from 'inquirer-form'
37
+
38
+ registerInquirerControls()
39
+ ```
40
+
41
+ ### 设计器
42
+
43
+ ```vue
44
+ <script setup lang="ts">
45
+ import { InquirerFormDesigner, createInquirerSampleControls } from 'inquirer-form'
46
+ import { SchemaEngine } from 'agilebuilder-form'
47
+
48
+ const engine = new SchemaEngine()
49
+ engine.getSchema().controls = createInquirerSampleControls()
50
+ </script>
51
+
52
+ <template>
53
+ <InquirerFormDesigner :engine="engine" />
54
+ </template>
55
+ ```
56
+
57
+ ### 运行态
58
+
59
+ ```vue
60
+ <script setup lang="ts">
61
+ import { ref } from 'vue'
62
+ import { InquirerFormRuntime } from 'inquirer-form'
63
+ import type { FormData, FormSchema } from 'agilebuilder-form'
64
+
65
+ const formData = ref<FormData>({})
66
+ const schema: FormSchema = {/* 从设计器或接口获取 */}
67
+ </script>
68
+
69
+ <template>
70
+ <InquirerFormRuntime v-model="formData" :schema="schema" />
71
+ </template>
72
+ ```
73
+
74
+ ### Schema → Inquirer
75
+
76
+ ```ts
77
+ import inquirer from 'inquirer'
78
+ import { schemaToInquirer } from 'inquirer-form'
79
+
80
+ const questions = schemaToInquirer(schema)
81
+ const answers = await inquirer.prompt(questions)
82
+ ```
83
+
84
+ ### Playground
85
+
86
+ ```bash
87
+ npm install
88
+ npm run dev
89
+ ```
90
+
91
+ 在浏览器中即可体验集成了 Designer / Runtime / JSON 导出的 `<InquirerFormPlayground>`。
92
+
93
+ ## 脚本
94
+
95
+ | 命令 | 说明 |
96
+ | ------------------- | ----------------------------------------- |
97
+ | `npm run dev` | Vite + Playground 热更新 |
98
+ | `npm run build` | 生成 `dist` 产物(ESM + CSS + d.ts) |
99
+ | `npm run test:unit` | Vitest 单元测试 |
100
+ | `npm run docs:*` | VitePress 文档站(可选) |
101
+
102
+ ## 发布 npm 模块
103
+
104
+ 1. **准备环境**
105
+ 确保已登录正确的 npm 账号,并使用 Node.js 满足 `engines` 要求。使用 `npm ci` 或 `npm install` 保证依赖一致。
106
+ 2. **构建产物**
107
+ ```bash
108
+ npm run build
109
+ ```
110
+ 该命令会输出 `dist/` 目录(包含 `inquirer-form.es.js`、`inquirer-form.umd.js`、`inquirer-form.css`、`index.d.ts`),并通过 `vite-plugin-dts` 生成类型声明。
111
+ 3. **核对发布内容**
112
+ `package.json` 的 `"files": ["dist", "README.md", "LICENSE"]` 会确保只发布:
113
+ - `dist/`:打包后的 JS/CSS/类型文件
114
+ - `README.md`:使用文档
115
+ - `LICENSE`
116
+ 如需附带额外文件(例如示例或类型增强),可在 `files` 数组中补充路径。
117
+ 4. **版本与发布**
118
+ ```bash
119
+ npm version patch # 或 minor / major
120
+ npm publish --access public
121
+ ```
122
+ 若你在 Monorepo/CI 中发布,可使用 `npm publish --provenance` 等附加参数。
123
+ 5. **验证**
124
+ 在空目录下执行 `npm pack` 或 `npm install inquirer-form@<version>`,确认产物与类型均正常。
125
+
126
+ > ⚠️ 不要把 `docs/`、`src/`、Playground 配置等开发文件放入 npm 包中;`files` 字段已默认排除它们。
127
+
128
+ ## 与 agilebuilder-form 联调
129
+
130
+ 当 `agilebuilder-form` 与本项目位于同级目录时,可继续保持 `file:../ag_form` 依赖。若要从 npm 使用正式版本,只需把依赖切换为对应版本号即可。
131
+
132
+ ```json
133
+ "dependencies": {
134
+ "agilebuilder-form": "^x.y.z"
135
+ }
136
+ ```
137
+
138
+ ## 许可证
139
+
140
+ [MIT](./LICENSE)
Binary file
@@ -0,0 +1,84 @@
1
+ import { App } from 'vue';
2
+ import { ComponentOptionsMixin } from 'vue';
3
+ import { ComponentProvideOptions } from 'vue';
4
+ import { ControlMeta } from 'agilebuilder-form';
5
+ import { DefineComponent } from 'vue';
6
+ import { FormData as FormData_2 } from 'agilebuilder-form';
7
+ import { FormSchema } from 'agilebuilder-form';
8
+ import { PublicProps } from 'vue';
9
+ import { SchemaEngine } from 'agilebuilder-form';
10
+ import { SchemaNode } from 'agilebuilder-form';
11
+
12
+ declare type __VLS_Props = {
13
+ engine?: SchemaEngine;
14
+ seedSample?: boolean;
15
+ autoRegisterControls?: boolean;
16
+ };
17
+
18
+ declare type __VLS_Props_2 = {
19
+ schema: FormSchema;
20
+ modelValue?: FormData_2;
21
+ };
22
+
23
+ export declare function createInquirerSampleControls(): SchemaNode[];
24
+
25
+ declare const _default: {
26
+ install(app: App): void;
27
+ };
28
+ export default _default;
29
+
30
+ export declare interface InquirerChoice {
31
+ /** 显示给用户的文本 */
32
+ name: string;
33
+ /** 传递给业务的值 */
34
+ value: string;
35
+ /** Inquirer 用于 summarize 的字段,可选 */
36
+ short?: string;
37
+ }
38
+
39
+ export declare const inquirerControls: ControlMeta[];
40
+
41
+ export declare const InquirerFormDesigner: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
42
+ seedSample: boolean;
43
+ autoRegisterControls: boolean;
44
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
45
+
46
+ export declare const InquirerFormPlayground: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, HTMLDivElement>;
47
+
48
+ export declare const InquirerFormRuntime: DefineComponent<__VLS_Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
49
+ "update:modelValue": (value: FormData_2) => any;
50
+ }, string, PublicProps, Readonly<__VLS_Props_2> & Readonly<{
51
+ "onUpdate:modelValue"?: ((value: FormData_2) => any) | undefined;
52
+ }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
53
+
54
+ export declare type InquirerPromptType = 'input' | 'number' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor';
55
+
56
+ export declare interface InquirerQuestion {
57
+ type: InquirerPromptType;
58
+ name: string;
59
+ message: string;
60
+ default?: any;
61
+ prefix?: string;
62
+ suffix?: string;
63
+ pageSize?: number;
64
+ loop?: boolean;
65
+ mask?: string | boolean;
66
+ choices?: InquirerChoice[];
67
+ /** 字符串形式存储的 when 表达式,后续由调用方转换为函数 */
68
+ whenExpression?: string;
69
+ validateExpression?: string;
70
+ filterExpression?: string;
71
+ transformerExpression?: string;
72
+ /** 分类、提示等额外信息 */
73
+ metadata?: Record<string, any>;
74
+ }
75
+
76
+ export declare function registerInquirerControls(): void;
77
+
78
+ export declare function schemaToInquirer(schema: FormSchema, options?: TransformOptions): InquirerQuestion[];
79
+
80
+ declare interface TransformOptions {
81
+ includeDisabled?: boolean;
82
+ }
83
+
84
+ export { }
@@ -0,0 +1 @@
1
+ @charset "UTF-8";.inquirer-designer-card[data-v-5aa173c3]{display:flex;flex-direction:column;gap:8px}.card-header[data-v-5aa173c3]{display:flex;align-items:center;gap:8px}.type-badge[data-v-5aa173c3]{padding:2px 6px;border-radius:2px;font-size:12px;font-weight:600;text-transform:uppercase;background-color:#0f6cbd1f;background-color:color-mix(in srgb,var(--ag-primary-color, #0f6cbd) 12%,transparent);color:#0f6cbd;color:var(--ag-primary-color, #0f6cbd)}.message[data-v-5aa173c3]{font-size:14px;font-weight:600;color:#0f1d32;color:var(--ag-text-primary, #0f1d32)}.description[data-v-5aa173c3]{margin:0;font-size:12px;line-height:1.4;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.options-preview[data-v-5aa173c3]{margin:0;padding-left:16px;font-size:12px;color:#2e3a4e}.options-preview li[data-v-5aa173c3]{list-style:disc}.options-preview .more[data-v-5aa173c3]{list-style:none;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.inquirer-input[data-v-b9ac497e]{display:flex;flex-direction:column;gap:4px}.transformer-preview[data-v-b9ac497e]{margin:0;font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.base-input-config[data-v-bd4a89f6]{display:flex;flex-direction:column}.textarea-setting[data-v-2c386165]{margin-bottom:12px}.textarea-setting label[data-v-2c386165]{display:block;margin-bottom:4px;font-size:12px;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.textarea-setting .hint[data-v-2c386165]{margin:4px 0 0;font-size:12px;line-height:1.4;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.expression-editor[data-v-91ba45bb]{margin-bottom:16px;display:flex;flex-direction:column;gap:8px}.expression-editor__label[data-v-91ba45bb]{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.info-icon[data-v-91ba45bb]{width:14px;height:14px;cursor:pointer;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.code-input[data-v-91ba45bb] textarea{font-family:JetBrains Mono,Fira Code,Menlo,Consolas,monospace;font-size:12px}.example-toggle[data-v-91ba45bb]{border:none;background:transparent;font-size:12px;cursor:pointer;color:var(--ag-primary-color, #0f6cbd);padding:0}.expression-editor__examples[data-v-91ba45bb]{border-radius:4px;border:1px dashed #dcdfe6;padding:8px 12px;background-color:#fff;display:flex;flex-direction:column;gap:4px}.examples-title[data-v-91ba45bb]{margin:0;font-size:12px;font-weight:600;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.examples-list[data-v-91ba45bb]{margin:0;padding-left:16px;display:flex;flex-direction:column;gap:4px}.examples-list code[data-v-91ba45bb]{font-family:JetBrains Mono,Fira Code,Menlo,Consolas,monospace;background-color:#f3f4f6;padding:1px 4px;border-radius:2px;font-size:12px}.fade-enter-active[data-v-91ba45bb],.fade-leave-active[data-v-91ba45bb]{transition:opacity .2s ease}.fade-enter-from[data-v-91ba45bb],.fade-leave-to[data-v-91ba45bb]{opacity:0}.inline-settings[data-v-c4882c52]{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.inquirer-password[data-v-0cb418f2]{display:flex;flex-direction:column;gap:4px}.mask-hint[data-v-0cb418f2]{margin:0;font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.number-runtime[data-v-ade0684b]{display:flex;align-items:center;gap:8px}.number-runtime__input[data-v-ade0684b]{flex:1}.affix[data-v-ade0684b]{font-size:13px;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.number-setting[data-v-4fb22ad3]{margin-bottom:12px}.number-setting label[data-v-4fb22ad3]{display:block;margin-bottom:4px;font-size:12px;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.confirm-runtime[data-v-f41e6b08]{display:flex;align-items:center;gap:12px}.state[data-v-f41e6b08]{font-size:13px;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.affix[data-v-f41e6b08]{font-size:13px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.inquirer-list[data-v-ad8b9ebc]{display:flex;flex-direction:column;gap:4px}.select-runtime[data-v-ad8b9ebc]{width:100%}.affix[data-v-ad8b9ebc]{font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.list-hint[data-v-ad8b9ebc]{margin:0;font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.checkbox-wrapper[data-v-86b287ae]{display:flex;flex-direction:column;gap:4px}.checkbox-runtime[data-v-86b287ae]{display:flex;flex-direction:column;gap:6px}.affix[data-v-86b287ae]{font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.multi-default[data-v-c571b549]{margin-bottom:12px}.multi-default label[data-v-c571b549]{display:block;margin-bottom:4px;font-size:12px;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.editor-runtime[data-v-bd13db5a]{display:flex;flex-direction:column;gap:4px}.affix[data-v-bd13db5a]{font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.transformer-preview[data-v-bd13db5a]{margin:0;font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.node-description[data-v-762f3565]{margin:8px 0 0;font-size:12px;line-height:1.4;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.node-error[data-v-762f3565]{margin:4px 0 0;font-size:12px;color:#ff6b6b}.inquirer-web-runtime[data-v-2ef727bc]{padding:24px}.form-header[data-v-2ef727bc]{margin-bottom:32px;padding-bottom:16px;border-bottom:1px solid transparent;border-bottom-color:#d8e0ef;border-bottom-color:var(--ag-border-light, #d8e0ef)}.form-title[data-v-2ef727bc]{margin:0 0 8px;font-size:24px;font-weight:600;color:#0f1d32;color:var(--ag-text-primary, #0f1d32)}.form-description[data-v-2ef727bc]{margin:0;font-size:14px;line-height:1.5;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.form-content[data-v-2ef727bc]{padding:16px 24px 0 0}.runtime-empty[data-v-2ef727bc]{padding:40px;text-align:center;color:#5a6578;color:var(--ag-text-tertiary, #5a6578);font-size:14px}.inquirer-demo[data-v-cdc491b8]{width:100%;max-width:100%;box-sizing:border-box;display:flex;flex-direction:column;gap:16px;min-height:calc(100vh - var(--vp-nav-height, 64px));background:#f5f7fb;padding:16px}.inquirer-demo[data-v-cdc491b8]>*{margin:0 auto;width:100%}.callout-panel[data-v-cdc491b8],.demo-workspace[data-v-cdc491b8]{border-radius:8px;background:#fff;border:1px solid rgba(15,23,42,.08);box-shadow:0 8px 24px #0f172a14}.callout-panel[data-v-cdc491b8]{padding:16px;display:flex;flex-direction:column;gap:16px}.callout-header[data-v-cdc491b8]{display:flex;justify-content:space-between;gap:24px;flex-wrap:wrap}.callout-header h1[data-v-cdc491b8]{margin:0 0 8px}.callout-header p[data-v-cdc491b8]{margin:0;font-size:14px;line-height:1.6;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.callout-actions[data-v-cdc491b8]{display:flex;flex-wrap:wrap;gap:8px}.callout-actions button[data-v-cdc491b8]{padding:10px 16px;border-radius:8px;border:1px solid rgba(15,23,42,.08);background:#fff;cursor:pointer;font-weight:600;transition:transform .2s,box-shadow .2s}.callout-actions button[data-v-cdc491b8]:hover{transform:translateY(-1px);box-shadow:0 10px 20px #0f172a14}.callout-controls header[data-v-cdc491b8]{font-size:13px;text-transform:uppercase;letter-spacing:.08em;margin-bottom:8px;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.callout-controls ul[data-v-cdc491b8]{list-style:none;display:flex;flex-direction:column;gap:8px;padding:0;margin:0}.callout-controls li[data-v-cdc491b8]{display:flex;justify-content:space-between;padding:10px 14px;border-radius:8px;background:#f5f7fb;border:1px solid rgba(15,23,42,.05)}.callout-controls .type[data-v-cdc491b8]{font-weight:600}.callout-controls .meta[data-v-cdc491b8]{font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.demo-workspace[data-v-cdc491b8]{padding:16px;display:flex;flex-direction:column;gap:16px;flex:1;min-height:0}.workspace-tabs[data-v-cdc491b8]{display:flex;flex-wrap:wrap;gap:8px;background:#fff;border-radius:8px;border:1px solid rgba(15,23,42,.08)}.tab-item[data-v-cdc491b8]{flex:1 1 200px;border:none;border-radius:8px;background:transparent;cursor:pointer;display:flex;flex-direction:column;align-items:flex-start;padding:12px;text-align:left;transition:background .2s,box-shadow .2s}.tab-item span[data-v-cdc491b8]{font-weight:600;font-size:15px}.tab-item small[data-v-cdc491b8]{font-size:12px;color:#2e3a4e;color:var(--ag-text-secondary, #2e3a4e)}.tab-item.active[data-v-cdc491b8]{background:#edf2ff;box-shadow:inset 0 0 0 1px #4f46e559}.workspace-panel[data-v-cdc491b8]{border-radius:8px;background:#fff;box-shadow:inset 0 0 0 1px #0f172a0d;min-height:0}.designer-panel[data-v-cdc491b8]{flex:1;display:flex;min-height:0}.designer-panel[data-v-cdc491b8] .designer-shell{flex:1;min-height:0;height:100%}.panel-header[data-v-cdc491b8]{display:flex;align-items:flex-start;gap:12px;margin-bottom:16px;flex-wrap:wrap}.panel-header h2[data-v-cdc491b8]{margin:0}.panel-header small[data-v-cdc491b8]{font-size:12px;color:#5a6578;color:var(--ag-text-tertiary, #5a6578)}.panel-header .btn-copy[data-v-cdc491b8]{margin-left:auto;padding:6px 14px;border-radius:8px;border:none;cursor:pointer;color:#fff;font-weight:600;background-color:#0f6cbd;background-color:var(--ag-primary-color, #0f6cbd)}.runtime-json[data-v-cdc491b8]{margin-top:16px}.runtime-json header[data-v-cdc491b8]{font-size:13px;font-weight:600;margin-bottom:8px}.runtime-json pre[data-v-cdc491b8]{margin:0;padding:12px;border-radius:4px;background:#f5f7fb;color:#0f1d32;max-height:240px;overflow:auto}.json-viewer[data-v-cdc491b8]{margin:0;padding:12px;border-radius:4px;background:#f5f7fb;color:#0f1d32;max-height:360px;overflow:auto;border:1px solid rgba(15,23,42,.06)}.code-snippet[data-v-cdc491b8]{margin-top:16px}.code-snippet header[data-v-cdc491b8]{font-size:13px;font-weight:600;margin-bottom:8px}.code-snippet pre[data-v-cdc491b8]{margin:0;padding:12px;border-radius:4px;background:#111827;color:#caf0f8;font-size:13px;overflow:auto}@media(max-width:960px){.inquirer-demo[data-v-cdc491b8]{padding:16px}.workspace-tabs[data-v-cdc491b8]{flex-direction:column}.tab-item[data-v-cdc491b8]{width:100%}}