@stonecrop/aform 0.10.11 → 0.10.13

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/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import AForm from './components/AForm.vue';
10
10
  import ANumericInput from './components/form/ANumericInput.vue';
11
11
  import ATextInput from './components/form/ATextInput.vue';
12
12
  import Login from './components/utilities/Login.vue';
13
+ export { isDoctypeMany } from './utils/doctype';
13
14
  /**
14
15
  * Install all AForm components
15
16
  * @param app - Vue app instance
@@ -18,7 +19,7 @@ import Login from './components/utilities/Login.vue';
18
19
  function install(app /* options */) {
19
20
  app.use(installATable); // Install ATable components for use within AForm
20
21
  app.component('ACheckbox', ACheckbox);
21
- app.component('ACombobox', AComboBox);
22
+ app.component('AComboBox', AComboBox);
22
23
  app.component('ADate', ADate);
23
24
  app.component('ADropdown', ADropdown);
24
25
  app.component('ADatePicker', ADatePicker);
@@ -12,6 +12,7 @@ import ANumericInput from './components/form/ANumericInput.vue';
12
12
  import ATextInput from './components/form/ATextInput.vue';
13
13
  import Login from './components/utilities/Login.vue';
14
14
  export type * from './types';
15
+ export { isDoctypeMany } from './utils/doctype';
15
16
  /**
16
17
  * Install all AForm components
17
18
  * @param app - Vue app instance
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,yBAAyB,CAAA;AAE5C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAE9B,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,KAAK,MAAM,6BAA6B,CAAA;AAC/C,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,WAAW,MAAM,mCAAmC,CAAA;AAC3D,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,WAAW,MAAM,mCAAmC,CAAA;AAC3D,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ACb,UAAU,EACV,KAAK,EACL,OAAO,GACP,CAAA"}
@@ -168,12 +168,13 @@ export type FieldsetSchema = BaseSchema & {
168
168
  collapsible?: boolean;
169
169
  };
170
170
  /**
171
- * Schema structure for defining nested doctype fields inside AForm
171
+ * Schema structure for a 1:1 nested doctype field inside AForm
172
172
  *
173
173
  * @remarks
174
- * When a field has `fieldtype: 'Doctype'`, the `options` property contains the slug
175
- * of the referenced doctype. The `schema` property is populated by the framework's
176
- * `registry.resolveSchema()` method with the resolved child schema fields.
174
+ * When a field has `fieldtype: 'Doctype'` without `cardinality: 'many'`, it represents
175
+ * a 1:1 nested form. The `options` property contains the slug of the referenced doctype.
176
+ * The `schema` property is populated by the framework's `registry.resolveSchema()` method
177
+ * with the resolved child schema fields.
177
178
  *
178
179
  * Before resolution: `{ fieldname: 'address', fieldtype: 'Doctype', options: 'address' }`
179
180
  * After resolution: `{ fieldname: 'address', fieldtype: 'Doctype', options: 'address', schema: [...resolved fields...] }`
@@ -182,7 +183,7 @@ export type FieldsetSchema = BaseSchema & {
182
183
  *
183
184
  * @public
184
185
  */
185
- export type DoctypeSchema = BaseSchema & {
186
+ export type DoctypeOneSchema = BaseSchema & {
186
187
  /**
187
188
  * The field type - must be 'Doctype' for nested doctype fields
188
189
  * @public
@@ -198,6 +199,11 @@ export type DoctypeSchema = BaseSchema & {
198
199
  * @public
199
200
  */
200
201
  label?: string;
202
+ /**
203
+ * The cardinality of the relationship — `'one'` or omitted means 1:1 nested form
204
+ * @public
205
+ */
206
+ cardinality?: 'one';
201
207
  /**
202
208
  * The resolved child schema fields, populated by `registry.resolveSchema()`
203
209
  * or provided manually for standalone usage
@@ -206,11 +212,12 @@ export type DoctypeSchema = BaseSchema & {
206
212
  schema?: SchemaTypes[];
207
213
  };
208
214
  /**
209
- * Schema structure for defining 1:many child table fields inside AForm
215
+ * Schema structure for a 1:many child table field inside AForm
210
216
  *
211
217
  * @remarks
212
- * When a field has `fieldtype: 'Table'`, the `options` property contains the slug
213
- * of the child doctype whose records appear as table rows.
218
+ * When a field has `fieldtype: 'Doctype'` with `cardinality: 'many'`, it represents
219
+ * a 1:many child table. The `options` property contains the slug of the child doctype
220
+ * whose records appear as table rows.
214
221
  *
215
222
  * `Registry.resolveSchema()` auto-derives `columns` from the child doctype's schema
216
223
  * fields and sets sensible defaults for `component` (`'ATable'`) and `config` (`{ view: 'list' }`).
@@ -220,12 +227,12 @@ export type DoctypeSchema = BaseSchema & {
220
227
  *
221
228
  * @public
222
229
  */
223
- export type TableDoctypeSchema = BaseSchema & {
230
+ export type DoctypeManySchema = BaseSchema & {
224
231
  /**
225
- * The field type must be 'Table' for 1:many child table fields
232
+ * The field type - must be 'Doctype' for nested doctype fields
226
233
  * @public
227
234
  */
228
- fieldtype: 'Table';
235
+ fieldtype: 'Doctype';
229
236
  /**
230
237
  * The slug of the child doctype in the registry
231
238
  * @public
@@ -236,6 +243,11 @@ export type TableDoctypeSchema = BaseSchema & {
236
243
  * @public
237
244
  */
238
245
  label?: string;
246
+ /**
247
+ * The cardinality of the relationship — `'many'` means 1:many child table
248
+ * @public
249
+ */
250
+ cardinality: 'many';
239
251
  /**
240
252
  * Table columns — auto-derived from child doctype schema if not provided
241
253
  * @public
@@ -251,10 +263,25 @@ export type TableDoctypeSchema = BaseSchema & {
251
263
  * @public
252
264
  */
253
265
  rows?: TableRow[];
266
+ /**
267
+ * The component to render — defaults to `'ATable'` when resolved
268
+ * @public
269
+ */
270
+ component?: string;
254
271
  };
272
+ /**
273
+ * Discriminated union for Doctype fields — either 1:1 nested form or 1:many child table
274
+ *
275
+ * @remarks
276
+ * Use `isDoctypeMany()` type guard to narrow to `DoctypeManySchema`.
277
+ * When `cardinality` is `'many'` or omitted, the field is a 1:1 nested form.
278
+ *
279
+ * @public
280
+ */
281
+ export type DoctypeSchema = DoctypeOneSchema | DoctypeManySchema;
255
282
  /**
256
283
  * Superset of all schema types for AForm
257
284
  * @public
258
285
  */
259
- export type SchemaTypes = FormSchema | TableSchema | FieldsetSchema | DoctypeSchema | TableDoctypeSchema;
286
+ export type SchemaTypes = FormSchema | TableSchema | FieldsetSchema | DoctypeSchema;
260
287
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3E;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;AAElD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IAEpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;IAEf;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,UAAU,CAAC,EAAE;QACZ;;;WAGG;QACH,YAAY,EAAE,MAAM,CAAA;QAEpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAClB,CAAA;CACD,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACxB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG;IACrC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;;OAGG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,UAAU,GAAG;IAC5C;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;IAEvB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAA;IAEjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG,iBAAiB,CAAA;AAEhE;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,cAAc,GAAG,aAAa,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { DoctypeSchema, DoctypeManySchema } from '../types';
2
+ /**
3
+ * Type guard that checks whether a Doctype schema field has `cardinality: 'many'`
4
+ *
5
+ * @param field - A DoctypeSchema field to check
6
+ * @returns `true` if the field has `cardinality: 'many'`
7
+ * @public
8
+ */
9
+ export declare function isDoctypeMany(field: DoctypeSchema): field is DoctypeManySchema;
10
+ //# sourceMappingURL=doctype.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../../src/utils/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEhE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,iBAAiB,CAE9E"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Type guard that checks whether a Doctype schema field has `cardinality: 'many'`
3
+ *
4
+ * @param field - A DoctypeSchema field to check
5
+ * @returns `true` if the field has `cardinality: 'many'`
6
+ * @public
7
+ */
8
+ export function isDoctypeMany(field) {
9
+ return field.cardinality === 'many';
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/aform",
3
- "version": "0.10.11",
3
+ "version": "0.10.13",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {
@@ -35,9 +35,9 @@
35
35
  "dependencies": {
36
36
  "@vueuse/core": "^14.2.1",
37
37
  "@vueuse/components": "^14.2.1",
38
- "@stonecrop/atable": "0.10.11",
39
- "@stonecrop/themes": "0.10.11",
40
- "@stonecrop/utilities": "0.10.11"
38
+ "@stonecrop/atable": "0.10.13",
39
+ "@stonecrop/utilities": "0.10.13",
40
+ "@stonecrop/themes": "0.10.13"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "pinia": "^3.0.4",
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import ANumericInput from './components/form/ANumericInput.vue'
14
14
  import ATextInput from './components/form/ATextInput.vue'
15
15
  import Login from './components/utilities/Login.vue'
16
16
  export type * from './types'
17
+ export { isDoctypeMany } from './utils/doctype'
17
18
 
18
19
  /**
19
20
  * Install all AForm components
@@ -22,8 +23,9 @@ export type * from './types'
22
23
  */
23
24
  function install(app: App /* options */) {
24
25
  app.use(installATable) // Install ATable components for use within AForm
26
+
25
27
  app.component('ACheckbox', ACheckbox)
26
- app.component('ACombobox', AComboBox)
28
+ app.component('AComboBox', AComboBox)
27
29
  app.component('ADate', ADate)
28
30
  app.component('ADropdown', ADropdown)
29
31
  app.component('ADatePicker', ADatePicker)
@@ -194,12 +194,13 @@ export type FieldsetSchema = BaseSchema & {
194
194
  }
195
195
 
196
196
  /**
197
- * Schema structure for defining nested doctype fields inside AForm
197
+ * Schema structure for a 1:1 nested doctype field inside AForm
198
198
  *
199
199
  * @remarks
200
- * When a field has `fieldtype: 'Doctype'`, the `options` property contains the slug
201
- * of the referenced doctype. The `schema` property is populated by the framework's
202
- * `registry.resolveSchema()` method with the resolved child schema fields.
200
+ * When a field has `fieldtype: 'Doctype'` without `cardinality: 'many'`, it represents
201
+ * a 1:1 nested form. The `options` property contains the slug of the referenced doctype.
202
+ * The `schema` property is populated by the framework's `registry.resolveSchema()` method
203
+ * with the resolved child schema fields.
203
204
  *
204
205
  * Before resolution: `{ fieldname: 'address', fieldtype: 'Doctype', options: 'address' }`
205
206
  * After resolution: `{ fieldname: 'address', fieldtype: 'Doctype', options: 'address', schema: [...resolved fields...] }`
@@ -208,7 +209,7 @@ export type FieldsetSchema = BaseSchema & {
208
209
  *
209
210
  * @public
210
211
  */
211
- export type DoctypeSchema = BaseSchema & {
212
+ export type DoctypeOneSchema = BaseSchema & {
212
213
  /**
213
214
  * The field type - must be 'Doctype' for nested doctype fields
214
215
  * @public
@@ -227,6 +228,12 @@ export type DoctypeSchema = BaseSchema & {
227
228
  */
228
229
  label?: string
229
230
 
231
+ /**
232
+ * The cardinality of the relationship — `'one'` or omitted means 1:1 nested form
233
+ * @public
234
+ */
235
+ cardinality?: 'one'
236
+
230
237
  /**
231
238
  * The resolved child schema fields, populated by `registry.resolveSchema()`
232
239
  * or provided manually for standalone usage
@@ -236,11 +243,12 @@ export type DoctypeSchema = BaseSchema & {
236
243
  }
237
244
 
238
245
  /**
239
- * Schema structure for defining 1:many child table fields inside AForm
246
+ * Schema structure for a 1:many child table field inside AForm
240
247
  *
241
248
  * @remarks
242
- * When a field has `fieldtype: 'Table'`, the `options` property contains the slug
243
- * of the child doctype whose records appear as table rows.
249
+ * When a field has `fieldtype: 'Doctype'` with `cardinality: 'many'`, it represents
250
+ * a 1:many child table. The `options` property contains the slug of the child doctype
251
+ * whose records appear as table rows.
244
252
  *
245
253
  * `Registry.resolveSchema()` auto-derives `columns` from the child doctype's schema
246
254
  * fields and sets sensible defaults for `component` (`'ATable'`) and `config` (`{ view: 'list' }`).
@@ -250,12 +258,12 @@ export type DoctypeSchema = BaseSchema & {
250
258
  *
251
259
  * @public
252
260
  */
253
- export type TableDoctypeSchema = BaseSchema & {
261
+ export type DoctypeManySchema = BaseSchema & {
254
262
  /**
255
- * The field type must be 'Table' for 1:many child table fields
263
+ * The field type - must be 'Doctype' for nested doctype fields
256
264
  * @public
257
265
  */
258
- fieldtype: 'Table'
266
+ fieldtype: 'Doctype'
259
267
 
260
268
  /**
261
269
  * The slug of the child doctype in the registry
@@ -269,6 +277,12 @@ export type TableDoctypeSchema = BaseSchema & {
269
277
  */
270
278
  label?: string
271
279
 
280
+ /**
281
+ * The cardinality of the relationship — `'many'` means 1:many child table
282
+ * @public
283
+ */
284
+ cardinality: 'many'
285
+
272
286
  /**
273
287
  * Table columns — auto-derived from child doctype schema if not provided
274
288
  * @public
@@ -286,10 +300,27 @@ export type TableDoctypeSchema = BaseSchema & {
286
300
  * @public
287
301
  */
288
302
  rows?: TableRow[]
303
+
304
+ /**
305
+ * The component to render — defaults to `'ATable'` when resolved
306
+ * @public
307
+ */
308
+ component?: string
289
309
  }
290
310
 
311
+ /**
312
+ * Discriminated union for Doctype fields — either 1:1 nested form or 1:many child table
313
+ *
314
+ * @remarks
315
+ * Use `isDoctypeMany()` type guard to narrow to `DoctypeManySchema`.
316
+ * When `cardinality` is `'many'` or omitted, the field is a 1:1 nested form.
317
+ *
318
+ * @public
319
+ */
320
+ export type DoctypeSchema = DoctypeOneSchema | DoctypeManySchema
321
+
291
322
  /**
292
323
  * Superset of all schema types for AForm
293
324
  * @public
294
325
  */
295
- export type SchemaTypes = FormSchema | TableSchema | FieldsetSchema | DoctypeSchema | TableDoctypeSchema
326
+ export type SchemaTypes = FormSchema | TableSchema | FieldsetSchema | DoctypeSchema
@@ -0,0 +1,12 @@
1
+ import type { DoctypeSchema, DoctypeManySchema } from '../types'
2
+
3
+ /**
4
+ * Type guard that checks whether a Doctype schema field has `cardinality: 'many'`
5
+ *
6
+ * @param field - A DoctypeSchema field to check
7
+ * @returns `true` if the field has `cardinality: 'many'`
8
+ * @public
9
+ */
10
+ export function isDoctypeMany(field: DoctypeSchema): field is DoctypeManySchema {
11
+ return field.cardinality === 'many'
12
+ }