@stonecrop/schema 0.14.0 → 0.16.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/package.json +14 -9
- package/dist/cli.cjs +0 -41
- package/dist/cli.cjs.map +0 -1
- package/dist/converter/heuristics.js +0 -258
- package/dist/converter/index.js +0 -181
- package/dist/converter/scalars.js +0 -86
- package/dist/converter/types.js +0 -5
- package/dist/converter-CYNFRwPg.js +0 -512
- package/dist/converter-CYNFRwPg.js.map +0 -1
- package/dist/converter-DNwpowpq.js +0 -459
- package/dist/converter-DNwpowpq.js.map +0 -1
- package/dist/doctype.js +0 -152
- package/dist/field.js +0 -110
- package/dist/fieldtype.js +0 -97
- package/dist/index--rNo7Kel.js +0 -494
- package/dist/index--rNo7Kel.js.map +0 -1
- package/dist/index-0qWNlDQ5.js +0 -450
- package/dist/index-0qWNlDQ5.js.map +0 -1
- package/dist/index-2UVTfbcY.js +0 -448
- package/dist/index-2UVTfbcY.js.map +0 -1
- package/dist/index-9QjWZ_PC.js +0 -449
- package/dist/index-9QjWZ_PC.js.map +0 -1
- package/dist/index-BCADNO5M.js +0 -449
- package/dist/index-BCADNO5M.js.map +0 -1
- package/dist/index-BJjSlCSo.js +0 -496
- package/dist/index-BJjSlCSo.js.map +0 -1
- package/dist/index-BRQJGVFR.js +0 -453
- package/dist/index-BRQJGVFR.js.map +0 -1
- package/dist/index-BatnoC-J.js +0 -429
- package/dist/index-BatnoC-J.js.map +0 -1
- package/dist/index-BbG7Mzvg.js +0 -495
- package/dist/index-BbG7Mzvg.js.map +0 -1
- package/dist/index-BdCmYHg0.js +0 -493
- package/dist/index-BdCmYHg0.js.map +0 -1
- package/dist/index-BhMd2_xl.js +0 -454
- package/dist/index-BhMd2_xl.js.map +0 -1
- package/dist/index-BzhZpuzA.js +0 -556
- package/dist/index-BzhZpuzA.js.map +0 -1
- package/dist/index-C1oC7Xwz.js +0 -552
- package/dist/index-C1oC7Xwz.js.map +0 -1
- package/dist/index-C5ANE_rn.js +0 -501
- package/dist/index-C5ANE_rn.js.map +0 -1
- package/dist/index-C8F23K8c.js +0 -555
- package/dist/index-C8F23K8c.js.map +0 -1
- package/dist/index-CD5wQNH-.js +0 -516
- package/dist/index-CD5wQNH-.js.map +0 -1
- package/dist/index-CLc5mUMQ.js +0 -478
- package/dist/index-CLc5mUMQ.js.map +0 -1
- package/dist/index-CMeexvC6.js +0 -459
- package/dist/index-CMeexvC6.js.map +0 -1
- package/dist/index-COrltkHl.js +0 -401
- package/dist/index-COrltkHl.js.map +0 -1
- package/dist/index-CX662Zb2.js +0 -551
- package/dist/index-CX662Zb2.js.map +0 -1
- package/dist/index-Cq_yfoqI.js +0 -553
- package/dist/index-Cq_yfoqI.js.map +0 -1
- package/dist/index-Cu-6609R.js +0 -493
- package/dist/index-Cu-6609R.js.map +0 -1
- package/dist/index-CvN9xK1B.js +0 -453
- package/dist/index-CvN9xK1B.js.map +0 -1
- package/dist/index-CzoRIy1-.js +0 -408
- package/dist/index-CzoRIy1-.js.map +0 -1
- package/dist/index-D66L9JNw.js +0 -506
- package/dist/index-D66L9JNw.js.map +0 -1
- package/dist/index-D68mWfHm.js +0 -510
- package/dist/index-D68mWfHm.js.map +0 -1
- package/dist/index-D6Up-BP5.js +0 -435
- package/dist/index-D6Up-BP5.js.map +0 -1
- package/dist/index-D8R5ppAg.js +0 -529
- package/dist/index-D8R5ppAg.js.map +0 -1
- package/dist/index-D9qPYlSk.js +0 -491
- package/dist/index-D9qPYlSk.js.map +0 -1
- package/dist/index-DCjAX4l-.js +0 -516
- package/dist/index-DCjAX4l-.js.map +0 -1
- package/dist/index-DE0b6fs6.js +0 -515
- package/dist/index-DE0b6fs6.js.map +0 -1
- package/dist/index-DEkR-1RC.js +0 -496
- package/dist/index-DEkR-1RC.js.map +0 -1
- package/dist/index-DIY_FLR2.js +0 -516
- package/dist/index-DIY_FLR2.js.map +0 -1
- package/dist/index-DIb_Z0wI.js +0 -476
- package/dist/index-DIb_Z0wI.js.map +0 -1
- package/dist/index-DNROIEMe.js +0 -449
- package/dist/index-DNROIEMe.js.map +0 -1
- package/dist/index-DT-NJBvW.js +0 -510
- package/dist/index-DT-NJBvW.js.map +0 -1
- package/dist/index-DUFcQC-H.js +0 -449
- package/dist/index-DUFcQC-H.js.map +0 -1
- package/dist/index-DVVTsJNb.js +0 -495
- package/dist/index-DVVTsJNb.js.map +0 -1
- package/dist/index-DYy5E1cU.js +0 -508
- package/dist/index-DYy5E1cU.js.map +0 -1
- package/dist/index-DdC5tpt-.js +0 -488
- package/dist/index-DdC5tpt-.js.map +0 -1
- package/dist/index-Dk593rMz.js +0 -512
- package/dist/index-Dk593rMz.js.map +0 -1
- package/dist/index-DmD8vmuB.js +0 -449
- package/dist/index-DmD8vmuB.js.map +0 -1
- package/dist/index-DpCFgELB.js +0 -514
- package/dist/index-DpCFgELB.js.map +0 -1
- package/dist/index-DqxTn6jG.js +0 -488
- package/dist/index-DqxTn6jG.js.map +0 -1
- package/dist/index-DyK5-0kh.js +0 -514
- package/dist/index-DyK5-0kh.js.map +0 -1
- package/dist/index-Vd0_gZjr.js +0 -451
- package/dist/index-Vd0_gZjr.js.map +0 -1
- package/dist/index-XSSAHj8g.js +0 -495
- package/dist/index-XSSAHj8g.js.map +0 -1
- package/dist/index-XZZbfFxT.js +0 -434
- package/dist/index-XZZbfFxT.js.map +0 -1
- package/dist/index-YP0m26Y5.js +0 -555
- package/dist/index-YP0m26Y5.js.map +0 -1
- package/dist/index-_3q9Bzka.js +0 -512
- package/dist/index-_3q9Bzka.js.map +0 -1
- package/dist/index-aeXXzPET.cjs +0 -2
- package/dist/index-aeXXzPET.cjs.map +0 -1
- package/dist/index-glU_Uw7z.js +0 -543
- package/dist/index-glU_Uw7z.js.map +0 -1
- package/dist/index-i0Uz8G2K.js +0 -554
- package/dist/index-i0Uz8G2K.js.map +0 -1
- package/dist/index-neVkjlgB.js +0 -446
- package/dist/index-neVkjlgB.js.map +0 -1
- package/dist/index-xdlVWldg.js +0 -408
- package/dist/index-xdlVWldg.js.map +0 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/jsonschema.js +0 -225
- package/dist/naming.js +0 -106
- package/dist/src/fieldtype.d.ts +0 -63
- package/dist/src/fieldtype.d.ts.map +0 -1
- package/dist/src/fieldtype.js +0 -106
- package/dist/src/jsonschema.d.ts +0 -95
- package/dist/src/jsonschema.d.ts.map +0 -1
- package/dist/src/schema-field.d.ts +0 -66
- package/dist/src/schema-field.d.ts.map +0 -1
- package/dist/src/schema-field.js +0 -0
- package/dist/src/tsdoc-metadata.json +0 -11
- package/dist/validation.js +0 -60
package/dist/doctype.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { FieldMeta } from './field';
|
|
3
|
-
/**
|
|
4
|
-
* Cardinality for relationship links.
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export const Cardinality = z.enum(['atMostOne', 'one', 'noneOrMany', 'atLeastOne']).meta({
|
|
8
|
-
title: 'Cardinality',
|
|
9
|
-
description: 'Cardinality for relationship links between doctypes',
|
|
10
|
-
});
|
|
11
|
-
/**
|
|
12
|
-
* Sync fetch strategy - data is fetched in the initial query.
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export const SyncFetch = z
|
|
16
|
-
.object({
|
|
17
|
-
/** Fetch method type */
|
|
18
|
-
method: z.literal('sync'),
|
|
19
|
-
/** Optional limit on number of records to fetch */
|
|
20
|
-
limit: z.number().int().positive().optional(),
|
|
21
|
-
})
|
|
22
|
-
.meta({
|
|
23
|
-
title: 'SyncFetch',
|
|
24
|
-
description: 'Sync fetch strategy - data is fetched in the initial query',
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
* Lazy fetch strategy - data is fetched on demand in a separate query.
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export const LazyFetch = z
|
|
31
|
-
.object({
|
|
32
|
-
/** Fetch method type */
|
|
33
|
-
method: z.literal('lazy'),
|
|
34
|
-
})
|
|
35
|
-
.meta({
|
|
36
|
-
title: 'LazyFetch',
|
|
37
|
-
description: 'Lazy fetch strategy - data is fetched on demand in a separate query',
|
|
38
|
-
});
|
|
39
|
-
/**
|
|
40
|
-
* Custom fetch strategy - uses a custom handler function.
|
|
41
|
-
* @public
|
|
42
|
-
*/
|
|
43
|
-
export const CustomFetch = z
|
|
44
|
-
.object({
|
|
45
|
-
/** Fetch method type */
|
|
46
|
-
method: z.literal('custom'),
|
|
47
|
-
/** Serialized handler function to invoke */
|
|
48
|
-
handler: z.string(),
|
|
49
|
-
})
|
|
50
|
-
.meta({
|
|
51
|
-
title: 'CustomFetch',
|
|
52
|
-
description: 'Custom fetch strategy - uses a custom handler function',
|
|
53
|
-
});
|
|
54
|
-
/**
|
|
55
|
-
* Fetch strategy for link data loading.
|
|
56
|
-
* - sync: fetched in the initial query
|
|
57
|
-
* - lazy: fetched on demand in a separate query
|
|
58
|
-
* - custom: uses a custom handler function
|
|
59
|
-
* @public
|
|
60
|
-
*/
|
|
61
|
-
export const FetchStrategy = z.discriminatedUnion('method', [SyncFetch, LazyFetch, CustomFetch]).meta({
|
|
62
|
-
title: 'FetchStrategy',
|
|
63
|
-
description: 'Fetch strategy for link data loading',
|
|
64
|
-
});
|
|
65
|
-
/**
|
|
66
|
-
* Link declaration - describes a relationship from one doctype to another.
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
export const LinkDeclaration = z
|
|
70
|
-
.object({
|
|
71
|
-
/** Target doctype slug */
|
|
72
|
-
target: z.string().min(1),
|
|
73
|
-
/** Cardinality of the relationship */
|
|
74
|
-
cardinality: Cardinality,
|
|
75
|
-
/** Backlink fieldname on the target doctype that points back to this link */
|
|
76
|
-
backlink: z.string().optional(),
|
|
77
|
-
/** Override default rendering component (AForm for 1:1, ATable for 1:many) */
|
|
78
|
-
component: z.string().optional(),
|
|
79
|
-
/** Fieldname of the corresponding Link field in the fields array */
|
|
80
|
-
fieldname: z.string().min(1).optional(),
|
|
81
|
-
/** Fetch strategy for loading nested data */
|
|
82
|
-
fetch: FetchStrategy.optional(),
|
|
83
|
-
/** Whether to block workflow actions until nested data is loaded (default: true) */
|
|
84
|
-
blockWorkflows: z.boolean().optional(),
|
|
85
|
-
})
|
|
86
|
-
.meta({
|
|
87
|
-
title: 'LinkDeclaration',
|
|
88
|
-
description: 'Declares a relationship from one doctype to another',
|
|
89
|
-
});
|
|
90
|
-
/**
|
|
91
|
-
* Action definition within a workflow
|
|
92
|
-
* @public
|
|
93
|
-
*/
|
|
94
|
-
export const ActionDefinition = z
|
|
95
|
-
.object({
|
|
96
|
-
/** Display label for the action */
|
|
97
|
-
label: z.string().min(1),
|
|
98
|
-
/** Handler function name or path */
|
|
99
|
-
handler: z.string().min(1),
|
|
100
|
-
/** Fields that must have values before action can execute */
|
|
101
|
-
requiredFields: z.array(z.string()).optional(),
|
|
102
|
-
/** Workflow states where this action is available */
|
|
103
|
-
allowedStates: z.array(z.string()).optional(),
|
|
104
|
-
/** Whether to show a confirmation dialog */
|
|
105
|
-
confirm: z.boolean().optional(),
|
|
106
|
-
/** Additional arguments for the action */
|
|
107
|
-
args: z.record(z.string(), z.unknown()).optional(),
|
|
108
|
-
})
|
|
109
|
-
.meta({
|
|
110
|
-
title: 'ActionDefinition',
|
|
111
|
-
description: 'Action definition within a workflow',
|
|
112
|
-
});
|
|
113
|
-
/**
|
|
114
|
-
* Workflow metadata - states and actions for a doctype
|
|
115
|
-
* @public
|
|
116
|
-
*/
|
|
117
|
-
export const WorkflowMeta = z
|
|
118
|
-
.object({
|
|
119
|
-
/** List of workflow states */
|
|
120
|
-
states: z.array(z.string()).optional(),
|
|
121
|
-
/** Actions available in this workflow */
|
|
122
|
-
actions: z.record(z.string(), ActionDefinition).optional(),
|
|
123
|
-
})
|
|
124
|
-
.meta({
|
|
125
|
-
title: 'WorkflowMeta',
|
|
126
|
-
description: 'Workflow metadata - states and actions for a doctype',
|
|
127
|
-
});
|
|
128
|
-
/**
|
|
129
|
-
* Doctype metadata - complete definition of a doctype
|
|
130
|
-
* @public
|
|
131
|
-
*/
|
|
132
|
-
export const DoctypeMeta = z
|
|
133
|
-
.object({
|
|
134
|
-
/** Display name of the doctype */
|
|
135
|
-
name: z.string().min(1),
|
|
136
|
-
/** URL-friendly slug (kebab-case) */
|
|
137
|
-
slug: z.string().min(1).optional(),
|
|
138
|
-
/** Database table name */
|
|
139
|
-
tableName: z.string().optional(),
|
|
140
|
-
/** Field definitions (including link fields with fieldtype: 'Link') */
|
|
141
|
-
fields: z.array(FieldMeta),
|
|
142
|
-
/** Relationship links to other doctypes */
|
|
143
|
-
links: z.record(z.string(), LinkDeclaration).optional(),
|
|
144
|
-
/** Workflow configuration */
|
|
145
|
-
workflow: WorkflowMeta.optional(),
|
|
146
|
-
/** Parent doctype for inheritance */
|
|
147
|
-
inherits: z.string().optional(),
|
|
148
|
-
})
|
|
149
|
-
.meta({
|
|
150
|
-
title: 'DoctypeMeta',
|
|
151
|
-
description: 'Doctype metadata - complete definition of a doctype',
|
|
152
|
-
});
|
package/dist/field.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { StonecropFieldType } from './fieldtype';
|
|
3
|
-
/**
|
|
4
|
-
* Field options - flexible bag for type-specific configuration.
|
|
5
|
-
*
|
|
6
|
-
* Usage by fieldtype:
|
|
7
|
-
* - Link/Doctype: target doctype slug as string ("customer", "sales-order-item")
|
|
8
|
-
* - Select: array of choices (["Draft", "Submitted", "Cancelled"])
|
|
9
|
-
* - Decimal: config object (\{ precision: 10, scale: 2 \})
|
|
10
|
-
* - Code: config object (\{ language: "python" \})
|
|
11
|
-
*
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
export const FieldOptions = z
|
|
15
|
-
.union([
|
|
16
|
-
z.string(), // Link/Doctype target: "customer"
|
|
17
|
-
z.array(z.string()), // Select choices: ["A", "B", "C"]
|
|
18
|
-
z.record(z.string(), z.unknown()), // Config: \{ precision: 10, scale: 2 \}
|
|
19
|
-
])
|
|
20
|
-
.meta({
|
|
21
|
-
title: 'FieldOptions',
|
|
22
|
-
description: 'Field options - flexible bag for type-specific configuration',
|
|
23
|
-
});
|
|
24
|
-
/**
|
|
25
|
-
* Validation configuration for form fields
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export const FieldValidation = z
|
|
29
|
-
.looseObject({
|
|
30
|
-
/** Error message to display when validation fails */
|
|
31
|
-
errorMessage: z.string(),
|
|
32
|
-
})
|
|
33
|
-
.meta({
|
|
34
|
-
title: 'FieldValidation',
|
|
35
|
-
description: 'Validation configuration for form fields',
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* Unified field metadata - the single source of truth for field definitions.
|
|
39
|
-
* Works for both forms (AForm) and tables (ATable).
|
|
40
|
-
*
|
|
41
|
-
* Core principle: "Text" is "Text" regardless of rendering context.
|
|
42
|
-
*
|
|
43
|
-
* @public
|
|
44
|
-
*/
|
|
45
|
-
export const FieldMeta = z
|
|
46
|
-
.object({
|
|
47
|
-
// === CORE (required) ===
|
|
48
|
-
/** Unique identifier for the field within its doctype */
|
|
49
|
-
fieldname: z.string().min(1),
|
|
50
|
-
/** Semantic field type - determines behavior and default component */
|
|
51
|
-
fieldtype: StonecropFieldType,
|
|
52
|
-
// === COMPONENT (optional - derived from fieldtype when not specified) ===
|
|
53
|
-
/** Vue component to render this field. If not specified, derived from TYPE_MAP */
|
|
54
|
-
component: z.string().optional(),
|
|
55
|
-
// === DISPLAY ===
|
|
56
|
-
/** Human-readable label for the field */
|
|
57
|
-
label: z.string().optional(),
|
|
58
|
-
/** Width of the field (CSS value, e.g., "40ch", "200px") */
|
|
59
|
-
width: z.string().optional(),
|
|
60
|
-
/** Text alignment within the field */
|
|
61
|
-
align: z.enum(['left', 'center', 'right', 'start', 'end']).optional(),
|
|
62
|
-
// === BEHAVIOR ===
|
|
63
|
-
/** Whether the field is required */
|
|
64
|
-
required: z.boolean().optional(),
|
|
65
|
-
/** Whether the field is read-only */
|
|
66
|
-
readOnly: z.boolean().optional(),
|
|
67
|
-
/** Whether the field is editable (for table cells) */
|
|
68
|
-
edit: z.boolean().optional(),
|
|
69
|
-
/** Whether the field is hidden from the UI */
|
|
70
|
-
hidden: z.boolean().optional(),
|
|
71
|
-
// === VALUE ===
|
|
72
|
-
/** Current value of the field */
|
|
73
|
-
value: z.unknown().optional(),
|
|
74
|
-
/** Default value for new records */
|
|
75
|
-
default: z.unknown().optional(),
|
|
76
|
-
// === TYPE-SPECIFIC ===
|
|
77
|
-
/**
|
|
78
|
-
* Type-specific options:
|
|
79
|
-
* - Link: target doctype slug ("customer")
|
|
80
|
-
* - Doctype: child doctype slug ("sales-order-item")
|
|
81
|
-
* - Select: choices array (["Draft", "Submitted"])
|
|
82
|
-
* - Decimal: \{ precision, scale \}
|
|
83
|
-
* - Code: \{ language \}
|
|
84
|
-
*/
|
|
85
|
-
options: FieldOptions.optional(),
|
|
86
|
-
/**
|
|
87
|
-
* Cardinality for Doctype fields:
|
|
88
|
-
* - 'one': exactly 1 (default)
|
|
89
|
-
* - 'atMostOne': 0 or 1
|
|
90
|
-
* - 'noneOrMany': 0 or more
|
|
91
|
-
* - 'atLeastOne': 1 or more
|
|
92
|
-
*/
|
|
93
|
-
cardinality: z.enum(['one', 'atMostOne', 'noneOrMany', 'atLeastOne']).optional(),
|
|
94
|
-
/**
|
|
95
|
-
* Input mask pattern. Accepts either a plain mask string or a stringified
|
|
96
|
-
* arrow function that receives `locale` and returns a mask string.
|
|
97
|
-
*
|
|
98
|
-
* Plain pattern: `"##/##/####"`
|
|
99
|
-
*
|
|
100
|
-
* Function pattern: `"(locale) => locale === 'en-US' ? '(###) ###-####' : '####-######'"`
|
|
101
|
-
*/
|
|
102
|
-
mask: z.string().optional(),
|
|
103
|
-
// === VALIDATION ===
|
|
104
|
-
/** Validation configuration */
|
|
105
|
-
validation: FieldValidation.optional(),
|
|
106
|
-
})
|
|
107
|
-
.meta({
|
|
108
|
-
title: 'FieldMeta',
|
|
109
|
-
description: 'Unified field metadata - the single source of truth for field definitions, works for both forms (AForm) and tables (ATable)',
|
|
110
|
-
});
|
package/dist/fieldtype.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* The complete list of field types built into Stonecrop.
|
|
4
|
-
* User apps can use any string as a fieldtype; this const is the exhaustive set of types
|
|
5
|
-
* that Stonecrop provides default components for.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export const BUILTIN_FIELD_TYPES = [
|
|
9
|
-
'Data', // Short text, varchar
|
|
10
|
-
'Text', // Long text
|
|
11
|
-
'Int', // Integer
|
|
12
|
-
'Float', // Floating point (IEEE 754)
|
|
13
|
-
'Decimal', // Arbitrary precision decimal
|
|
14
|
-
'Check', // Boolean/checkbox
|
|
15
|
-
'Date', // Date only
|
|
16
|
-
'Time', // Time only
|
|
17
|
-
'Datetime', // Date and time
|
|
18
|
-
'Duration', // Time interval
|
|
19
|
-
'DateRange', // Date range
|
|
20
|
-
'JSON', // JSON data
|
|
21
|
-
'Code', // Code/source (with syntax highlighting)
|
|
22
|
-
'Link', // Reference to another doctype
|
|
23
|
-
'Attach', // File attachment
|
|
24
|
-
'Currency', // Currency value
|
|
25
|
-
'Quantity', // Quantity with unit
|
|
26
|
-
'Select', // Dropdown selection
|
|
27
|
-
];
|
|
28
|
-
/**
|
|
29
|
-
* Stonecrop field type — any non-empty string is valid; Stonecrop provides default components
|
|
30
|
-
* for the builtin types listed in {@link BUILTIN_FIELD_TYPES}. Custom fieldtypes are supported
|
|
31
|
-
* by supplying an explicit `component` on the field definition.
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
export const StonecropFieldType = z.string().min(1).meta({
|
|
35
|
-
title: 'StonecropFieldType',
|
|
36
|
-
description: 'Semantic field types for Stonecrop doctypes, consistent across forms and tables',
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Returns `true` when `fieldtype` is one of the builtin types Stonecrop ships with.
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
export function isBuiltinFieldType(fieldtype) {
|
|
43
|
-
return BUILTIN_FIELD_TYPES.includes(fieldtype);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Mapping from builtin fieldtypes to their default Vue component.
|
|
47
|
-
* Components can be overridden in the field definition.
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
export const TYPE_MAP = {
|
|
51
|
-
// Text
|
|
52
|
-
Data: { component: 'ATextInput', fieldtype: 'Data' },
|
|
53
|
-
Text: { component: 'ATextInput', fieldtype: 'Text' },
|
|
54
|
-
// Numeric
|
|
55
|
-
Int: { component: 'ANumericInput', fieldtype: 'Int' },
|
|
56
|
-
Float: { component: 'ANumericInput', fieldtype: 'Float' },
|
|
57
|
-
Decimal: { component: 'ADecimalInput', fieldtype: 'Decimal' },
|
|
58
|
-
// Boolean
|
|
59
|
-
Check: { component: 'ACheckbox', fieldtype: 'Check' },
|
|
60
|
-
// Date/Time
|
|
61
|
-
Date: { component: 'ADate', fieldtype: 'Date' },
|
|
62
|
-
Time: { component: 'ATimeInput', fieldtype: 'Time' },
|
|
63
|
-
Datetime: { component: 'ADatetimePicker', fieldtype: 'Datetime' },
|
|
64
|
-
Duration: { component: 'ADurationInput', fieldtype: 'Duration' },
|
|
65
|
-
DateRange: { component: 'ADateRangePicker', fieldtype: 'DateRange' },
|
|
66
|
-
// Structured
|
|
67
|
-
JSON: { component: 'ACodeEditor', fieldtype: 'JSON' },
|
|
68
|
-
Code: { component: 'ACodeEditor', fieldtype: 'Code' },
|
|
69
|
-
// Relational
|
|
70
|
-
Link: { component: 'ALink', fieldtype: 'Link' },
|
|
71
|
-
// Files
|
|
72
|
-
Attach: { component: 'AFileAttach', fieldtype: 'Attach' },
|
|
73
|
-
// Specialized
|
|
74
|
-
Currency: { component: 'ACurrencyInput', fieldtype: 'Currency' },
|
|
75
|
-
Quantity: { component: 'AQuantityInput', fieldtype: 'Quantity' },
|
|
76
|
-
Select: { component: 'ADropdown', fieldtype: 'Select' },
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Get the default component for a builtin field type.
|
|
80
|
-
* For an open-string fieldtype that may be custom, use {@link resolveComponent} instead.
|
|
81
|
-
* @param fieldtype - A builtin field type
|
|
82
|
-
* @returns The default component name
|
|
83
|
-
* @public
|
|
84
|
-
*/
|
|
85
|
-
export function getDefaultComponent(fieldtype) {
|
|
86
|
-
return TYPE_MAP[fieldtype]?.component ?? 'ATextInput';
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Resolve the component name for any fieldtype string, falling back to `'ATextInput'`
|
|
90
|
-
* for unknown custom types.
|
|
91
|
-
* @param fieldtype - Any fieldtype string (builtin or custom)
|
|
92
|
-
* @returns The component name to use for rendering
|
|
93
|
-
* @public
|
|
94
|
-
*/
|
|
95
|
-
export function resolveComponent(fieldtype) {
|
|
96
|
-
return isBuiltinFieldType(fieldtype) ? getDefaultComponent(fieldtype) : 'ATextInput';
|
|
97
|
-
}
|