@streamline-pulse/formkrafter-core 0.20.0 → 0.22.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.
@@ -0,0 +1,10 @@
1
+ /** What a reviewer said about one field, keyed by the brick `key`. */
2
+ export interface FieldAnnotation {
3
+ /** The value must be corrected. */
4
+ incorrect?: boolean;
5
+ /** Free text shown to whoever corrects the field. */
6
+ comment?: string;
7
+ }
8
+ export type FieldAnnotations = Record<string, FieldAnnotation>;
9
+ /** Keys flagged as incorrect: the fields a correction step lets the applicant edit. */
10
+ export declare const flaggedKeys: (annotations: FieldAnnotations | undefined) => string[];
@@ -0,0 +1,34 @@
1
+ import type { SelectOption } from "./options";
2
+ import type { BrickSpec } from "./brick-spec";
3
+ import type { JSONSchemaType } from "../validators/json-schema-type";
4
+ /** One data-bearing brick of a spec, described independently of any renderer. */
5
+ export interface FieldDescriptor {
6
+ /** Data key (`configs.key`). */
7
+ key: string;
8
+ /** Spec path, as `iterateBricks` yields it (`"0.2.1"`). */
9
+ path: string;
10
+ /** Label resolved for the locale, falling back to the key. */
11
+ label: string;
12
+ /** Brick id (`text`, `select`, `data-grid`, ...). */
13
+ brick: string;
14
+ type: "input" | "collection";
15
+ dataType?: JSONSchemaType;
16
+ /** Several values among `options` (multi select, select boxes, tags). */
17
+ multiple: boolean;
18
+ required: boolean;
19
+ /** Static options only; remote, catalog and computed sources are not resolved here. */
20
+ options?: SelectOption[];
21
+ /** For a collection, the fields of one row. */
22
+ columns?: FieldDescriptor[];
23
+ }
24
+ export interface CollectFieldsOptions {
25
+ /** Keep keys starting with `_` (never part of the submitted data). Default false. */
26
+ includePrivate?: boolean;
27
+ }
28
+ /**
29
+ * Lists the fields a form collects: every input and collection with a key,
30
+ * in document order, with the label, static options and requiredness a
31
+ * backend or an assistant needs to read or fill the data. Panels are
32
+ * flattened; a collection is one field whose `columns` describe a row.
33
+ */
34
+ export declare const collectFields: (spec: BrickSpec | undefined, locale?: string, options?: CollectFieldsOptions) => FieldDescriptor[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamline-pulse/formkrafter-core",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Framework-agnostic core for FormKrafter: form specs, RFC 6902 ops with undo/redo, Ajv validation, sandboxed rules engine and injectable services",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,6 +16,7 @@
16
16
  ],
17
17
  "files": [
18
18
  "dist",
19
+ "schema",
19
20
  "LICENSE"
20
21
  ],
21
22
  "scripts": {
@@ -39,7 +40,8 @@
39
40
  ".": {
40
41
  "types": "./dist/index.d.ts",
41
42
  "import": "./dist/index.js"
42
- }
43
+ },
44
+ "./schema/form-spec.schema.json": "./schema/form-spec.schema.json"
43
45
  },
44
46
  "publishConfig": {
45
47
  "access": "public"
@@ -0,0 +1,208 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://formkrafter.com/schema/form-spec.schema.json",
4
+ "title": "FormKrafter form spec",
5
+ "description": "A form is a tree of bricks. The same document drives the builder, every renderer and server-side validation, and is portable JSON with no FormKrafter-specific encoding.",
6
+ "$ref": "#/$defs/brick",
7
+
8
+ "$defs": {
9
+ "brick": {
10
+ "type": "object",
11
+ "required": ["type", "id", "name"],
12
+ "properties": {
13
+ "type": {
14
+ "$ref": "#/$defs/brickType",
15
+ "description": "What role the node plays in the tree."
16
+ },
17
+ "id": {
18
+ "type": "string",
19
+ "minLength": 1,
20
+ "description": "Which registered brick renders this node, for example \"text\", \"select\", \"data-grid\"."
21
+ },
22
+ "name": {
23
+ "type": "string",
24
+ "description": "Human label for the node, shown in the builder."
25
+ },
26
+ "dataType": {
27
+ "$ref": "#/$defs/jsonSchemaType",
28
+ "description": "The JSON type the brick's value takes. Validation rules are only enforced when it is present."
29
+ },
30
+ "category": {
31
+ "type": "string",
32
+ "description": "Palette grouping in the builder."
33
+ },
34
+ "editable": {
35
+ "type": "boolean",
36
+ "description": "Whether the builder lets this node be edited. Defaults to true."
37
+ },
38
+ "unWrapData": {
39
+ "type": "boolean",
40
+ "description": "Whether the brick's value is spread into the parent record rather than nested under its key."
41
+ },
42
+ "isPrivate": {
43
+ "type": "boolean",
44
+ "description": "Hides the brick from the builder palette."
45
+ },
46
+ "validators": {
47
+ "type": "array",
48
+ "items": { "$ref": "#/$defs/validator" },
49
+ "description": "Validators the brick offers in the builder. The rules actually enforced live in \"validations\"."
50
+ },
51
+ "validations": {
52
+ "type": "array",
53
+ "items": { "$ref": "#/$defs/validation" }
54
+ },
55
+ "rules": {
56
+ "type": "array",
57
+ "items": { "$ref": "#/$defs/rule" }
58
+ },
59
+ "configs": {
60
+ "$ref": "#/$defs/configs"
61
+ },
62
+ "configsForm": {
63
+ "$ref": "#/$defs/brick",
64
+ "description": "A spec describing the brick's own configuration form, used by the builder."
65
+ },
66
+ "styles": {
67
+ "type": "object",
68
+ "description": "Style tokens applied to the brick, as CSS-like key/value pairs.",
69
+ "additionalProperties": true
70
+ },
71
+ "children": {
72
+ "type": "array",
73
+ "items": { "$ref": "#/$defs/brick" },
74
+ "description": "Child bricks. A collection's children describe one repeating row."
75
+ }
76
+ },
77
+ "additionalProperties": false
78
+ },
79
+
80
+ "brickType": {
81
+ "enum": ["panel", "input", "collection", "output", "action"]
82
+ },
83
+
84
+ "jsonSchemaPrimitiveType": {
85
+ "enum": ["string", "number", "integer", "boolean", "object", "array", "null", "void"]
86
+ },
87
+
88
+ "jsonSchemaType": {
89
+ "oneOf": [
90
+ { "$ref": "#/$defs/jsonSchemaPrimitiveType" },
91
+ { "type": "array", "items": { "$ref": "#/$defs/jsonSchemaPrimitiveType" } }
92
+ ]
93
+ },
94
+
95
+ "validator": {
96
+ "enum": [
97
+ "required",
98
+ "minLength",
99
+ "maxLength",
100
+ "min",
101
+ "max",
102
+ "pattern",
103
+ "minItems",
104
+ "maxItems",
105
+ "email",
106
+ "url",
107
+ "custom"
108
+ ]
109
+ },
110
+
111
+ "validation": {
112
+ "type": "object",
113
+ "required": ["validator"],
114
+ "properties": {
115
+ "validator": { "$ref": "#/$defs/validator" },
116
+ "message": {
117
+ "$ref": "#/$defs/localizedText",
118
+ "description": "Overrides the built-in message for this rule."
119
+ },
120
+ "value": {
121
+ "description": "The rule's argument: a number for min/max and lengths, a regular expression source for pattern. Absent for required, email and url."
122
+ },
123
+ "customValidator": {
124
+ "type": "string",
125
+ "description": "Sandboxed expression evaluated when validator is \"custom\"."
126
+ }
127
+ },
128
+ "additionalProperties": false
129
+ },
130
+
131
+ "rule": {
132
+ "type": "object",
133
+ "required": ["name", "type"],
134
+ "properties": {
135
+ "name": { "type": "string" },
136
+ "type": { "enum": ["jsonLogic", "javaScript"] },
137
+ "logic": {
138
+ "description": "A JsonLogic expression, evaluated against the form data merged with the host's runtime context."
139
+ },
140
+ "code": {
141
+ "type": "string",
142
+ "description": "Source evaluated in the AST sandbox when type is \"javaScript\"."
143
+ },
144
+ "effects": {
145
+ "type": "array",
146
+ "items": { "$ref": "#/$defs/effect" }
147
+ }
148
+ },
149
+ "additionalProperties": false
150
+ },
151
+
152
+ "effect": {
153
+ "type": "object",
154
+ "properties": {
155
+ "name": { "type": "string" },
156
+ "property": {
157
+ "type": "object",
158
+ "required": ["target", "type"],
159
+ "properties": {
160
+ "target": {
161
+ "type": "string",
162
+ "description": "The property the rule drives, for example \"hidden\", \"disabled\", \"value\"."
163
+ },
164
+ "type": { "enum": ["logic", "code", "boolean", "string"] }
165
+ },
166
+ "additionalProperties": false
167
+ },
168
+ "logic": {},
169
+ "code": { "type": "string" },
170
+ "boolean": { "type": "boolean" },
171
+ "string": { "type": "string" }
172
+ },
173
+ "additionalProperties": false
174
+ },
175
+
176
+ "configs": {
177
+ "type": "object",
178
+ "description": "Brick configuration. Only key and uid are defined for every brick; each brick id adds its own, so unknown properties are allowed on purpose.",
179
+ "properties": {
180
+ "key": {
181
+ "type": "string",
182
+ "description": "The field's name in the form data. A brick without a key holds no value."
183
+ },
184
+ "uid": {
185
+ "type": "string",
186
+ "description": "Identity of the node while the builder is editing it. Stored specs do not need it: the builder hydrates missing ones and strips them from everything it emits."
187
+ },
188
+ "label": { "$ref": "#/$defs/localizedText" },
189
+ "placeholder": { "$ref": "#/$defs/localizedText" },
190
+ "defaultValue": {
191
+ "description": "Seeded into the form data on load for keys the host did not supply."
192
+ }
193
+ },
194
+ "additionalProperties": true
195
+ },
196
+
197
+ "localizedText": {
198
+ "description": "Either a plain string, or an object keyed by locale.",
199
+ "oneOf": [
200
+ { "type": "string" },
201
+ {
202
+ "type": "object",
203
+ "additionalProperties": { "type": "string" }
204
+ }
205
+ ]
206
+ }
207
+ }
208
+ }