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