inquirer-form 0.1.0 → 0.2.1

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 CHANGED
@@ -1,22 +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
-
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 CHANGED
@@ -1,44 +1,94 @@
1
1
  # inquirer-form
2
2
 
3
- `inquirer-form` 是一套面向 [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) 的可视化表单设计/运行组件,构建在 `agilebuilder-form` 之上,帮助团队快速把「拖拽式 Schema」同步成 Inquirer `QuestionCollection` 并在 Web 端模拟 prompt 交互。
3
+ English | [简体中文](./README.zh-CN.md)
4
4
 
5
- ## 功能亮点
5
+ A Vue 3-based visual form designer and runtime library specifically built for [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/), enabling seamless unification between Web forms and CLI interactions.
6
6
 
7
- - 🧱 Inquirer 专属控件集(input、password、list、checkbox、editor…),可与自定义控件混用
8
- - 🛠️ `<InquirerFormDesigner>` 拖拽式设计器,内置 Schema 引擎与快照
9
- - 🧪 `<InquirerFormRuntime>` Web 运行态,实时渲染与数据回写
10
- - 🔁 `schemaToInquirer` 等工具方法,一键生成 QuestionCollection
11
- - 🧑‍💻 `<InquirerFormPlayground>` Playground 组件,便于演示与交互测试
7
+ ## Features
12
8
 
13
- ## 环境要求
9
+ - **Visual Designer** - Drag-and-drop form design with WYSIWYG experience
10
+ - **Multi-Platform Unity** - One schema drives both Web forms and CLI interactions
11
+ - **Ready to Use** - 9 built-in Inquirer-specific controls
12
+ - **Type Safe** - Complete TypeScript type definitions
13
+ - **i18n Support** - Built-in Chinese and English support
14
+ - **Flexible Extension** - Support for custom controls and themes
15
+ - **Lightweight** - Built on agilebuilder-form
14
16
 
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
- ## 安装
17
+ ## Installation
23
18
 
24
19
  ```bash
25
20
  npm install inquirer-form
21
+ ```
22
+
23
+ ### Required Dependencies
24
+
25
+ This package requires `agilebuilder-form` as a core dependency:
26
26
 
27
- # 如同级有 agilebuilder-form,可直接引用本地版本
28
- npm install agilebuilder-form@file:../ag_form
27
+ ```bash
28
+ npm install agilebuilder-form
29
29
  ```
30
30
 
31
- > 仓库默认把 `agilebuilder-form` 指向 `file:../ag_form`,便于与主库联调;发布到 npm 时无需额外处理。
31
+ ### Peer Dependencies
32
+
33
+ Make sure to install the following peer dependencies:
34
+
35
+ ```bash
36
+ npm install vue@^3.5.0 element-plus@^2.11.7 vuedraggable@^4.1.0
37
+ ```
38
+
39
+ ### Import Styles
40
+
41
+ Don't forget to import the required CSS files in your application:
42
+
43
+ ```typescript
44
+ // Import inquirer-form styles
45
+ import 'inquirer-form/style.css'
46
+
47
+ // Import agilebuilder-form styles
48
+ import 'agilebuilder-form/dist/style.css'
49
+
50
+ // Import Element Plus styles
51
+ import 'element-plus/dist/index.css'
52
+ ```
32
53
 
33
- ## 快速开始
54
+ ## Use Cases
34
55
 
35
- ```ts
56
+ ### CLI Tool Development
57
+ - Configuration wizards for project scaffolding
58
+ - Parameter collection for command-line tools
59
+ - Confirmation flows for batch operations
60
+
61
+ ### Web Application Forms
62
+ - Configuration forms for admin dashboards
63
+ - User registration and settings pages
64
+ - Data entry and editing interfaces
65
+
66
+ ### Multi-Platform Scenarios
67
+ - DevOps tools (CLI operations + Web management)
68
+ - Configuration management systems (CLI config + Web visualization)
69
+ - Automation scripts (CLI execution + Web monitoring)
70
+
71
+ ## Quick Start
72
+
73
+ ### 1. Register Controls
74
+
75
+ ```typescript
36
76
  import { registerInquirerControls } from 'inquirer-form'
37
77
 
78
+ // Register all Inquirer controls
38
79
  registerInquirerControls()
39
80
  ```
40
81
 
41
- ### 设计器
82
+ ### 2. Import Styles
83
+
84
+ ```typescript
85
+ // main.ts or App.vue
86
+ import 'inquirer-form/style.css'
87
+ import 'agilebuilder-form/dist/style.css'
88
+ import 'element-plus/dist/index.css'
89
+ ```
90
+
91
+ ### 3. Use the Designer
42
92
 
43
93
  ```vue
44
94
  <script setup lang="ts">
@@ -46,7 +96,9 @@ import { InquirerFormDesigner, createInquirerSampleControls } from 'inquirer-for
46
96
  import { SchemaEngine } from 'agilebuilder-form'
47
97
 
48
98
  const engine = new SchemaEngine()
49
- engine.getSchema().controls = createInquirerSampleControls()
99
+
100
+ // Optional: Load sample form
101
+ engine.getSchema().controls = createInquirerSampleControls((key) => key)
50
102
  </script>
51
103
 
52
104
  <template>
@@ -54,7 +106,7 @@ engine.getSchema().controls = createInquirerSampleControls()
54
106
  </template>
55
107
  ```
56
108
 
57
- ### 运行态
109
+ ### 4. Web Runtime
58
110
 
59
111
  ```vue
60
112
  <script setup lang="ts">
@@ -63,7 +115,11 @@ import { InquirerFormRuntime } from 'inquirer-form'
63
115
  import type { FormData, FormSchema } from 'agilebuilder-form'
64
116
 
65
117
  const formData = ref<FormData>({})
66
- const schema: FormSchema = {/* 从设计器或接口获取 */}
118
+ const schema: FormSchema = {
119
+ controls: [
120
+ // Get from designer or define manually
121
+ ]
122
+ }
67
123
  </script>
68
124
 
69
125
  <template>
@@ -71,70 +127,333 @@ const schema: FormSchema = {/* 从设计器或接口获取 */}
71
127
  </template>
72
128
  ```
73
129
 
74
- ### Schema Inquirer
130
+ ### 5. Convert to Inquirer
75
131
 
76
- ```ts
132
+ ```typescript
77
133
  import inquirer from 'inquirer'
78
134
  import { schemaToInquirer } from 'inquirer-form'
135
+ import type { FormSchema } from 'agilebuilder-form'
79
136
 
137
+ const schema: FormSchema = {
138
+ // Get from designer or API
139
+ }
140
+
141
+ // Convert to Inquirer questions
80
142
  const questions = schemaToInquirer(schema)
143
+
144
+ // Use in CLI
81
145
  const answers = await inquirer.prompt(questions)
146
+ console.log(answers)
82
147
  ```
83
148
 
84
- ### Playground
149
+ ### 6. Try the Playground
85
150
 
86
151
  ```bash
152
+ git clone <repository-url>
153
+ cd inquirer-form
87
154
  npm install
88
155
  npm run dev
89
156
  ```
90
157
 
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"
158
+ Visit the browser to see the complete demo with designer, Web preview, and Inquirer export.
159
+
160
+ ## API Documentation
161
+
162
+ ### Components
163
+
164
+ #### InquirerFormDesigner
165
+
166
+ Visual form designer component.
167
+
168
+ **Props:**
169
+ - `engine?: SchemaEngine` - Schema engine instance (optional, creates new instance by default)
170
+ - `seedSample?: boolean` - Whether to load sample form (default `false`)
171
+ - `autoRegisterControls?: boolean` - Whether to auto-register controls (default `true`)
172
+
173
+ **Example:**
174
+ ```vue
175
+ <InquirerFormDesigner
176
+ :engine="engine"
177
+ :seedSample="true"
178
+ :autoRegisterControls="true"
179
+ />
180
+ ```
181
+
182
+ #### InquirerFormRuntime
183
+
184
+ Web form runtime component.
185
+
186
+ **Props:**
187
+ - `schema: FormSchema` - Form schema (required)
188
+ - `modelValue: FormData` - Form data (v-model)
189
+
190
+ **Events:**
191
+ - `update:modelValue` - Form data update event
192
+
193
+ **Example:**
194
+ ```vue
195
+ <InquirerFormRuntime v-model="formData" :schema="schema" />
196
+ ```
197
+
198
+ #### InquirerFormPlayground
199
+
200
+ Complete playground component with designer, runtime, and export features.
201
+
202
+ **Example:**
203
+ ```vue
204
+ <InquirerFormPlayground />
205
+ ```
206
+
207
+ ### Functions
208
+
209
+ #### registerInquirerControls()
210
+
211
+ Register all built-in Inquirer controls to the global registry.
212
+
213
+ ```typescript
214
+ import { registerInquirerControls } from 'inquirer-form'
215
+
216
+ registerInquirerControls()
217
+ ```
218
+
219
+ #### schemaToInquirer(schema, options?)
220
+
221
+ Convert form schema to Inquirer questions.
222
+
223
+ **Parameters:**
224
+ - `schema: FormSchema` - Form schema
225
+ - `options?: TransformOptions` - Transform options
226
+ - `includeDisabled?: boolean` - Whether to include disabled fields (default `false`)
227
+
228
+ **Returns:**
229
+ - `InquirerQuestion[]` - Array of Inquirer questions
230
+
231
+ **Example:**
232
+ ```typescript
233
+ import { schemaToInquirer } from 'inquirer-form'
234
+
235
+ const questions = schemaToInquirer(schema, {
236
+ includeDisabled: false
237
+ })
238
+ ```
239
+
240
+ #### createInquirerSampleControls(t)
241
+
242
+ Create sample form controls.
243
+
244
+ **Parameters:**
245
+ - `t: (key: string) => string` - i18n translation function
246
+
247
+ **Returns:**
248
+ - `SchemaNode[]` - Array of schema nodes
249
+
250
+ **Example:**
251
+ ```typescript
252
+ import { createInquirerSampleControls } from 'inquirer-form'
253
+
254
+ const controls = createInquirerSampleControls((key) => key)
255
+ engine.getSchema().controls = controls
256
+ ```
257
+
258
+ ### Types
259
+
260
+ #### InquirerPromptType
261
+
262
+ Supported Inquirer prompt types.
263
+
264
+ ```typescript
265
+ type InquirerPromptType =
266
+ | 'input' // Text input
267
+ | 'number' // Number input
268
+ | 'confirm' // Confirmation (yes/no)
269
+ | 'list' // Single choice list
270
+ | 'rawlist' // Raw list
271
+ | 'expand' // Expand choice
272
+ | 'checkbox' // Multiple choice
273
+ | 'password' // Password input
274
+ | 'editor' // Multi-line editor
275
+ ```
276
+
277
+ #### InquirerQuestion
278
+
279
+ Inquirer question object interface.
280
+
281
+ ```typescript
282
+ interface InquirerQuestion {
283
+ type: InquirerPromptType
284
+ name: string
285
+ message: string
286
+ default?: any
287
+ prefix?: string
288
+ suffix?: string
289
+ pageSize?: number
290
+ loop?: boolean
291
+ mask?: string | boolean
292
+ choices?: InquirerChoice[]
293
+ whenExpression?: string
294
+ validateExpression?: string
295
+ filterExpression?: string
296
+ transformerExpression?: string
297
+ metadata?: Record<string, any>
298
+ }
299
+ ```
300
+
301
+ #### InquirerChoice
302
+
303
+ Choice interface (for list, checkbox, etc.).
304
+
305
+ ```typescript
306
+ interface InquirerChoice {
307
+ name: string // Display text
308
+ value: string // Actual value
309
+ short?: string // Short description
135
310
  }
136
311
  ```
137
312
 
138
- ## 许可证
313
+ ## Built-in Controls
314
+
315
+ | Control Type | Description | Inquirer Type |
316
+ |-------------|-------------|---------------|
317
+ | Input | Text input field | `input` |
318
+ | Password | Password input field | `password` |
319
+ | Number | Number input field | `number` |
320
+ | Confirm | Confirmation box | `confirm` |
321
+ | List | Single choice list | `list` |
322
+ | RawList | Raw list | `rawlist` |
323
+ | Expand | Expand choice | `expand` |
324
+ | Checkbox | Multiple choice | `checkbox` |
325
+ | Editor | Multi-line editor | `editor` |
326
+
327
+ ## Advanced Usage
328
+
329
+ ### Custom Controls
330
+
331
+ ```typescript
332
+ import { registry } from 'agilebuilder-form'
333
+ import type { ControlMeta } from 'agilebuilder-form'
334
+
335
+ const customControl: ControlMeta = {
336
+ type: 'custom-input',
337
+ label: 'Custom Input',
338
+ component: CustomInputComponent,
339
+ initialSchema: () => ({
340
+ id: generateId(),
341
+ type: 'custom-input',
342
+ field: '',
343
+ props: {}
344
+ })
345
+ }
346
+
347
+ // Register custom control
348
+ registry.register(customControl)
349
+ ```
350
+
351
+ ### Expression Support
352
+
353
+ Schema supports various expression fields for dynamic control:
354
+
355
+ ```typescript
356
+ {
357
+ type: 'input',
358
+ field: 'email',
359
+ props: {
360
+ message: 'Enter your email',
361
+ // Conditional display
362
+ whenExpression: "return answers.needEmail === true",
363
+ // Validation
364
+ validateExpression: "return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(input) || 'Please enter a valid email'",
365
+ // Filter
366
+ filterExpression: "return input.trim().toLowerCase()",
367
+ // Transform display
368
+ transformerExpression: "return input.replace(/@.*/, '@***')"
369
+ }
370
+ }
371
+ ```
372
+
373
+ ### Integration with Inquirer.js
374
+
375
+ Complete CLI integration example:
376
+
377
+ ```typescript
378
+ import inquirer from 'inquirer'
379
+ import { schemaToInquirer } from 'inquirer-form'
380
+ import type { FormSchema } from 'agilebuilder-form'
381
+
382
+ // Load schema from file or API
383
+ const schema: FormSchema = require('./form-schema.json')
384
+
385
+ // Convert to Inquirer questions
386
+ const questions = schemaToInquirer(schema)
387
+
388
+ // Process expressions (convert strings to functions)
389
+ const processedQuestions = questions.map(q => ({
390
+ ...q,
391
+ when: q.whenExpression
392
+ ? new Function('answers', q.whenExpression)
393
+ : undefined,
394
+ validate: q.validateExpression
395
+ ? new Function('input', 'answers', q.validateExpression)
396
+ : undefined,
397
+ filter: q.filterExpression
398
+ ? new Function('input', 'answers', q.filterExpression)
399
+ : undefined,
400
+ transformer: q.transformerExpression
401
+ ? new Function('input', 'answers', 'flags', q.transformerExpression)
402
+ : undefined
403
+ }))
404
+
405
+ // Execute prompts
406
+ const answers = await inquirer.prompt(processedQuestions)
407
+ console.log('User input:', answers)
408
+ ```
409
+
410
+ ## Development
411
+
412
+ ### Scripts
413
+
414
+ | Command | Description |
415
+ |---------|-------------|
416
+ | `npm run dev` | Start development server (Playground) |
417
+ | `npm run build` | Build for production |
418
+ | `npm run type-check` | TypeScript type checking |
419
+ | `npm run test:unit` | Run unit tests |
420
+ | `npm run docs:dev` | Start documentation dev server |
421
+ | `npm run docs:build` | Build documentation |
422
+
423
+ ### Build Output
424
+
425
+ After running `npm run build`, the following files will be generated:
426
+
427
+ ```
428
+ dist/
429
+ inquirer-form.es.js # ES Module
430
+ inquirer-form.umd.js # UMD Module
431
+ inquirer-form.css # Stylesheet
432
+ index.d.ts # TypeScript declarations
433
+ ```
434
+
435
+ ### Publishing to npm
436
+
437
+ 1. Make sure you're logged in to npm
438
+ 2. Update version: `npm version patch|minor|major`
439
+ 3. Build: `npm run build`
440
+ 4. Publish: `npm publish --access public`
441
+
442
+ ## Related Projects
443
+
444
+ - [agilebuilder-form](https://github.com/yjkjdev/agilebuilder-form) - Underlying form engine
445
+ - [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) - CLI interaction library
446
+ - [Element Plus](https://element-plus.org/) - UI component library
447
+ - [Vue 3](https://vuejs.org/) - Progressive JavaScript framework
448
+
449
+ ## License
139
450
 
140
451
  [MIT](./LICENSE)
452
+
453
+ ## Contributing
454
+
455
+ Issues and Pull Requests are welcome!
456
+
457
+ ## Contact
458
+
459
+ For questions or suggestions, please contact us through GitHub Issues.