@stonecrop/stonecrop 0.7.9 → 0.8.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/dist/src/composable.d.ts +8 -0
- package/dist/src/composable.d.ts.map +1 -1
- package/dist/src/composable.js +129 -0
- package/dist/src/registry.d.ts +59 -0
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +166 -0
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stonecrop.js +6 -3
- package/dist/src/stores/hst.d.ts +5 -0
- package/dist/src/stores/hst.d.ts.map +1 -1
- package/dist/src/stores/hst.js +10 -3
- package/dist/stonecrop.d.ts +163 -1
- package/dist/stonecrop.js +917 -729
- package/dist/stonecrop.js.map +1 -1
- package/dist/stonecrop.umd.cjs +3 -3
- package/dist/stonecrop.umd.cjs.map +1 -1
- package/package.json +3 -3
- package/src/composable.ts +166 -0
- package/src/registry.ts +189 -0
- package/src/stonecrop.ts +6 -3
- package/src/stores/hst.ts +13 -3
package/dist/stonecrop.d.ts
CHANGED
|
@@ -1280,6 +1280,50 @@ export declare class DoctypeMeta {
|
|
|
1280
1280
|
get slug(): string;
|
|
1281
1281
|
}
|
|
1282
1282
|
|
|
1283
|
+
/**
|
|
1284
|
+
* Schema structure for defining nested doctype fields inside AForm
|
|
1285
|
+
*
|
|
1286
|
+
* @remarks
|
|
1287
|
+
* When a field has `fieldtype: 'Doctype'`, the `options` property contains the slug
|
|
1288
|
+
* of the referenced doctype. The `schema` property is populated by the framework's
|
|
1289
|
+
* `registry.resolveSchema()` method with the resolved child schema fields.
|
|
1290
|
+
*
|
|
1291
|
+
* Before resolution: `{ fieldname: 'address', fieldtype: 'Doctype', options: 'address' }`
|
|
1292
|
+
* After resolution: `{ fieldname: 'address', fieldtype: 'Doctype', options: 'address', schema: [...resolved fields...] }`
|
|
1293
|
+
*
|
|
1294
|
+
* Users can also manually provide the `schema` property without using the framework registry.
|
|
1295
|
+
*
|
|
1296
|
+
* @public
|
|
1297
|
+
*/
|
|
1298
|
+
export declare type DoctypeSchema = BaseSchema & {
|
|
1299
|
+
/**
|
|
1300
|
+
* The field type - must be 'Doctype' for nested doctype fields
|
|
1301
|
+
* @public
|
|
1302
|
+
*/
|
|
1303
|
+
fieldtype: 'Doctype';
|
|
1304
|
+
/**
|
|
1305
|
+
* The slug of the referenced doctype in the registry
|
|
1306
|
+
* @public
|
|
1307
|
+
*/
|
|
1308
|
+
options: string;
|
|
1309
|
+
/**
|
|
1310
|
+
* The label to display above the nested form section
|
|
1311
|
+
* @public
|
|
1312
|
+
*/
|
|
1313
|
+
label?: string;
|
|
1314
|
+
/**
|
|
1315
|
+
* The resolved child schema fields, populated by `registry.resolveSchema()`
|
|
1316
|
+
* or provided manually for standalone usage
|
|
1317
|
+
* @public
|
|
1318
|
+
*/
|
|
1319
|
+
schema?: SchemaTypes[];
|
|
1320
|
+
/**
|
|
1321
|
+
* Indicate whether the nested form is read-only
|
|
1322
|
+
* @public
|
|
1323
|
+
*/
|
|
1324
|
+
readOnly?: boolean;
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1283
1327
|
/**
|
|
1284
1328
|
* Supported action types for field triggers
|
|
1285
1329
|
* @public
|
|
@@ -1918,6 +1962,13 @@ export declare type HSTStonecropReturn = BaseStonecropReturn & {
|
|
|
1918
1962
|
handleHSTChange: (changeData: HSTChangeData) => void;
|
|
1919
1963
|
hstStore: Ref<HSTNode | undefined>;
|
|
1920
1964
|
formData: Ref<Record<string, any>>;
|
|
1965
|
+
resolvedSchema: Ref<SchemaTypes[]>;
|
|
1966
|
+
loadNestedData: (parentPath: string, childDoctype: DoctypeMeta, recordId?: string) => Record<string, any>;
|
|
1967
|
+
saveRecursive: (doctype: DoctypeMeta, recordId: string) => Promise<Record<string, any>>;
|
|
1968
|
+
createNestedContext: (basePath: string, childDoctype: DoctypeMeta) => {
|
|
1969
|
+
provideHSTPath: (fieldname: string) => string;
|
|
1970
|
+
handleHSTChange: (changeData: HSTChangeData) => void;
|
|
1971
|
+
};
|
|
1921
1972
|
};
|
|
1922
1973
|
|
|
1923
1974
|
/**
|
|
@@ -2142,6 +2193,64 @@ export declare class Registry {
|
|
|
2142
2193
|
* @see {@link DoctypeMeta}
|
|
2143
2194
|
*/
|
|
2144
2195
|
addDoctype(doctype: DoctypeMeta): void;
|
|
2196
|
+
/**
|
|
2197
|
+
* Resolve nested Doctype and Table fields in a schema by embedding child schemas inline.
|
|
2198
|
+
*
|
|
2199
|
+
* @remarks
|
|
2200
|
+
* Walks the schema array and for each field with `fieldtype: 'Doctype'` and a string
|
|
2201
|
+
* `options` value, looks up the referenced doctype in the registry and embeds its schema
|
|
2202
|
+
* as the field's `schema` property. Recurses for deeply nested doctypes.
|
|
2203
|
+
*
|
|
2204
|
+
* For fields with `fieldtype: 'Table'`, looks up the referenced child doctype and
|
|
2205
|
+
* auto-derives `columns` from its schema fields (unless columns are already provided).
|
|
2206
|
+
* Also sets sensible defaults for `component` (`'ATable'`) and `config` (`{ view: 'list' }`).
|
|
2207
|
+
* Row data is expected to come from the parent form's data model at `data[fieldname]`.
|
|
2208
|
+
*
|
|
2209
|
+
* Returns a new array — does not mutate the original schema.
|
|
2210
|
+
*
|
|
2211
|
+
* @param schema - The schema array to resolve
|
|
2212
|
+
* @returns A new schema array with nested Doctype fields resolved
|
|
2213
|
+
*
|
|
2214
|
+
* @example
|
|
2215
|
+
* ```ts
|
|
2216
|
+
* registry.addDoctype(addressDoctype)
|
|
2217
|
+
* registry.addDoctype(customerDoctype)
|
|
2218
|
+
*
|
|
2219
|
+
* // Before: customer schema has { fieldname: 'address', fieldtype: 'Doctype', options: 'address' }
|
|
2220
|
+
* const resolved = registry.resolveSchema(customerSchema)
|
|
2221
|
+
* // After: address field now has schema: [...address fields...]
|
|
2222
|
+
* ```
|
|
2223
|
+
*
|
|
2224
|
+
* @public
|
|
2225
|
+
*/
|
|
2226
|
+
resolveSchema(schema: SchemaTypes[], visited?: Set<string>): SchemaTypes[];
|
|
2227
|
+
/**
|
|
2228
|
+
* Initialize a new record with default values based on a schema.
|
|
2229
|
+
*
|
|
2230
|
+
* @remarks
|
|
2231
|
+
* Creates a plain object with keys from the schema's fieldnames and default values
|
|
2232
|
+
* derived from each field's `fieldtype`:
|
|
2233
|
+
* - Data, Text → `''`
|
|
2234
|
+
* - Check → `false`
|
|
2235
|
+
* - Int, Float, Decimal, Currency, Quantity → `0`
|
|
2236
|
+
* - Table → `[]`
|
|
2237
|
+
* - JSON, Doctype → `{}`
|
|
2238
|
+
* - All others → `null`
|
|
2239
|
+
*
|
|
2240
|
+
* For Doctype fields with a resolved `schema` array, recursively initializes the nested record.
|
|
2241
|
+
*
|
|
2242
|
+
* @param schema - The schema array to derive defaults from
|
|
2243
|
+
* @returns A plain object with default values for each field
|
|
2244
|
+
*
|
|
2245
|
+
* @example
|
|
2246
|
+
* ```ts
|
|
2247
|
+
* const defaults = registry.initializeRecord(addressSchema)
|
|
2248
|
+
* // { street: '', city: '', state: '', zip_code: '' }
|
|
2249
|
+
* ```
|
|
2250
|
+
*
|
|
2251
|
+
* @public
|
|
2252
|
+
*/
|
|
2253
|
+
initializeRecord(schema: SchemaTypes[]): Record<string, any>;
|
|
2145
2254
|
}
|
|
2146
2255
|
|
|
2147
2256
|
/**
|
|
@@ -2168,7 +2277,7 @@ export declare type Schema = {
|
|
|
2168
2277
|
* Superset of all schema types for AForm
|
|
2169
2278
|
* @public
|
|
2170
2279
|
*/
|
|
2171
|
-
export declare type SchemaTypes = FormSchema | TableSchema | FieldsetSchema;
|
|
2280
|
+
export declare type SchemaTypes = FormSchema | TableSchema | FieldsetSchema | DoctypeSchema | TableDoctypeSchema;
|
|
2172
2281
|
|
|
2173
2282
|
/**
|
|
2174
2283
|
* Schema validator class
|
|
@@ -2821,6 +2930,59 @@ export declare interface TableDisplay {
|
|
|
2821
2930
|
rowModified?: boolean;
|
|
2822
2931
|
}
|
|
2823
2932
|
|
|
2933
|
+
/**
|
|
2934
|
+
* Schema structure for defining 1:many child table fields inside AForm
|
|
2935
|
+
*
|
|
2936
|
+
* @remarks
|
|
2937
|
+
* When a field has `fieldtype: 'Table'`, the `options` property contains the slug
|
|
2938
|
+
* of the child doctype whose records appear as table rows.
|
|
2939
|
+
*
|
|
2940
|
+
* `Registry.resolveSchema()` auto-derives `columns` from the child doctype's schema
|
|
2941
|
+
* fields and sets sensible defaults for `component` (`'ATable'`) and `config` (`{ view: 'list' }`).
|
|
2942
|
+
*
|
|
2943
|
+
* Users can override any auto-derived property by specifying it explicitly on the schema field.
|
|
2944
|
+
* Row data comes from the parent form's data model at `data[fieldname]` (an array).
|
|
2945
|
+
*
|
|
2946
|
+
* @public
|
|
2947
|
+
*/
|
|
2948
|
+
export declare type TableDoctypeSchema = BaseSchema & {
|
|
2949
|
+
/**
|
|
2950
|
+
* The field type — must be 'Table' for 1:many child table fields
|
|
2951
|
+
* @public
|
|
2952
|
+
*/
|
|
2953
|
+
fieldtype: 'Table';
|
|
2954
|
+
/**
|
|
2955
|
+
* The slug of the child doctype in the registry
|
|
2956
|
+
* @public
|
|
2957
|
+
*/
|
|
2958
|
+
options: string;
|
|
2959
|
+
/**
|
|
2960
|
+
* The label to display above the table section
|
|
2961
|
+
* @public
|
|
2962
|
+
*/
|
|
2963
|
+
label?: string;
|
|
2964
|
+
/**
|
|
2965
|
+
* Table columns — auto-derived from child doctype schema if not provided
|
|
2966
|
+
* @public
|
|
2967
|
+
*/
|
|
2968
|
+
columns?: TableColumn[];
|
|
2969
|
+
/**
|
|
2970
|
+
* Table configuration — defaults to `{ view: 'list' }` if not provided
|
|
2971
|
+
* @public
|
|
2972
|
+
*/
|
|
2973
|
+
config?: TableConfig;
|
|
2974
|
+
/**
|
|
2975
|
+
* Table rows — populated from the parent form's data model at `data[fieldname]`
|
|
2976
|
+
* @public
|
|
2977
|
+
*/
|
|
2978
|
+
rows?: TableRow[];
|
|
2979
|
+
/**
|
|
2980
|
+
* Indicate whether the table is read-only
|
|
2981
|
+
* @public
|
|
2982
|
+
*/
|
|
2983
|
+
readOnly?: boolean;
|
|
2984
|
+
};
|
|
2985
|
+
|
|
2824
2986
|
/**
|
|
2825
2987
|
* Table modal definition.
|
|
2826
2988
|
* @public
|