@stonecrop/stonecrop 0.3.5 → 0.3.6

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,576 @@
1
+ import { Component } from 'vue';
2
+ import { List } from 'immutable';
3
+ import { MachineConfig } from 'xstate';
4
+ import { Map as Map_2 } from 'immutable';
5
+ import { Plugin as Plugin_2 } from 'vue';
6
+ import { Ref } from 'vue';
7
+ import { Router } from 'vue-router';
8
+ import { StateMachine } from 'xstate';
9
+ import { StoreDefinition } from 'pinia';
10
+
11
+ /**
12
+ * Basic field structure for AForm schemas
13
+ * @public
14
+ */
15
+ export declare type BaseSchema = {
16
+ /**
17
+ * The fieldname for the schema field
18
+ * @public
19
+ */
20
+ fieldname: string;
21
+ /**
22
+ * The component to render
23
+ *
24
+ * @remarks
25
+ * This must be a string that represents the component to render. The registration of the component
26
+ * should be done in the main application.
27
+ *
28
+ * @public
29
+ */
30
+ component?: string;
31
+ /**
32
+ * A placeholder value for the field
33
+ * @beta
34
+ */
35
+ value?: any;
36
+ };
37
+
38
+ /**
39
+ * Table cell context definition.
40
+ * @public
41
+ */
42
+ export declare type CellContext = {
43
+ row: TableRow;
44
+ column: TableColumn;
45
+ table: {
46
+ [key: string]: any;
47
+ };
48
+ };
49
+
50
+ /**
51
+ * Doctype Meta class
52
+ * @public
53
+ */
54
+ export declare class DoctypeMeta {
55
+ /**
56
+ * The doctype name
57
+ * @public
58
+ * @readonly
59
+ */
60
+ readonly doctype: string;
61
+ /**
62
+ * The doctype schema
63
+ * @public
64
+ * @readonly
65
+ */
66
+ readonly schema: ImmutableDoctype['schema'];
67
+ /**
68
+ * The doctype workflow
69
+ * @public
70
+ * @readonly
71
+ */
72
+ readonly workflow: ImmutableDoctype['workflow'];
73
+ /**
74
+ * The doctype actions
75
+ * @public
76
+ * @readonly
77
+ */
78
+ readonly actions: ImmutableDoctype['actions'];
79
+ /**
80
+ * The doctype component
81
+ * @public
82
+ * @readonly
83
+ */
84
+ readonly component?: Component;
85
+ constructor(doctype: string, schema: ImmutableDoctype['schema'], workflow: ImmutableDoctype['workflow'], actions: ImmutableDoctype['actions'], component?: Component);
86
+ /**
87
+ * Converts the registered doctype to a slug (kebab-case)
88
+ * @returns The slugified doctype string
89
+ * @public
90
+ */
91
+ get slug(): string;
92
+ }
93
+
94
+ /**
95
+ * Schema structure for defining fieldsets inside AForm
96
+ * @public
97
+ */
98
+ export declare type FieldsetSchema = BaseSchema & {
99
+ /**
100
+ * The label to display in the fieldset
101
+ * @public
102
+ */
103
+ label?: string;
104
+ /**
105
+ * The schemas to be rendered inside the fieldset
106
+ * @public
107
+ */
108
+ schema?: (FormSchema | TableSchema)[];
109
+ /**
110
+ * Indicate whether the fieldset is collapsible
111
+ * @public
112
+ */
113
+ collapsible?: boolean;
114
+ };
115
+
116
+ /**
117
+ * Schema structure for defining forms inside AForm
118
+ * @public
119
+ */
120
+ export declare type FormSchema = BaseSchema & {
121
+ /**
122
+ * Align the field in the form
123
+ * @beta
124
+ */
125
+ align?: string;
126
+ /**
127
+ * Indicate whether the field is editable
128
+ * @beta
129
+ */
130
+ edit?: boolean;
131
+ /**
132
+ * The field type for the schema field
133
+ *
134
+ * @remarks
135
+ * This must be a string that represents the field type. A mask string will be automatically
136
+ * applied for the following field types:
137
+ * - Date ('##/##/####')
138
+ * - Datetime ('####/##/## ##:##')
139
+ * - Time ('##:##')
140
+ * - Fulltime ('##:##:##')
141
+ * - Phone ('(###) ### - ####')
142
+ * - Card ('#### #### #### ####')
143
+ *
144
+ * @public
145
+ */
146
+ fieldtype?: string;
147
+ /**
148
+ * The label to display in the form
149
+ * @public
150
+ */
151
+ label?: string;
152
+ /**
153
+ * The unique identifier for the field
154
+ * @beta
155
+ */
156
+ name?: string;
157
+ /**
158
+ * The width of the field element.
159
+ * @beta
160
+ */
161
+ width?: string;
162
+ /**
163
+ * The mask string for the field
164
+ * @beta
165
+ */
166
+ mask?: string;
167
+ };
168
+
169
+ /**
170
+ * Immutable Doctype type for Stonecrop instances
171
+ * @public
172
+ */
173
+ export declare type ImmutableDoctype = {
174
+ readonly schema?: List<SchemaTypes>;
175
+ readonly workflow: StateMachine<unknown, unknown, any>;
176
+ readonly actions?: Map_2<string, string[]>;
177
+ };
178
+
179
+ /**
180
+ * Install options for Stonecrop Vue plugin
181
+ * @public
182
+ */
183
+ export declare type InstallOptions = {
184
+ router?: Router;
185
+ components?: Record<string, Component>;
186
+ getMeta?: (doctype?: string) => DoctypeMeta | Promise<DoctypeMeta>;
187
+ };
188
+
189
+ /**
190
+ * Mutable Doctype type for Stonecrop instances
191
+ * @public
192
+ */
193
+ export declare type MutableDoctype = {
194
+ schema?: SchemaTypes[];
195
+ workflow: MachineConfig<unknown, unknown, any>;
196
+ actions?: Record<string, string[]>;
197
+ };
198
+
199
+ /**
200
+ * Stonecrop Registry class
201
+ * @public
202
+ */
203
+ export declare class Registry {
204
+ /**
205
+ * The root Registry instance
206
+ */
207
+ static _root: Registry;
208
+ /**
209
+ * The name of the Registry instance
210
+ *
211
+ * @defaultValue 'Registry'
212
+ */
213
+ name: string;
214
+ /**
215
+ * The Vue router instance
216
+ * @see {@link https://router.vuejs.org/}
217
+ */
218
+ router: Router;
219
+ /**
220
+ * The registry property contains a collection of doctypes
221
+ * @see {@link DoctypeMeta}
222
+ */
223
+ registry: Record<string, DoctypeMeta>;
224
+ /**
225
+ * The getMeta function fetches doctype metadata from an API
226
+ * @see {@link DoctypeMeta}
227
+ */
228
+ getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>;
229
+ constructor(router: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>);
230
+ /**
231
+ * Get doctype metadata
232
+ * @param doctype - The doctype to fetch metadata for
233
+ * @returns The doctype metadata
234
+ * @see {@link DoctypeMeta}
235
+ */
236
+ addDoctype(doctype: DoctypeMeta): void;
237
+ }
238
+
239
+ /**
240
+ * Schema type for Stonecrop instances
241
+ * @public
242
+ */
243
+ export declare type Schema = {
244
+ doctype: string;
245
+ schema: List<SchemaTypes>;
246
+ };
247
+
248
+ /**
249
+ * Superset of all schema types for AForm
250
+ * @public
251
+ */
252
+ export declare type SchemaTypes = FormSchema | TableSchema | FieldsetSchema;
253
+
254
+ /**
255
+ * Stonecrop Vue plugin
256
+ * @param app - The Vue app instance
257
+ * @param options - The plugin options
258
+ * @example
259
+ * ```ts
260
+ *
261
+ * import { createApp } from 'vue'
262
+ * import Stonecrop from 'stonecrop'
263
+ *
264
+ * import App from './App.vue'
265
+ *
266
+ * const app = createApp(App)
267
+ * app.use(Stonecrop, {
268
+ * router,
269
+ * components: {
270
+ * // register custom components
271
+ * },
272
+ * getMeta: async (doctype: string) => {
273
+ * // fetch doctype meta from API
274
+ * },
275
+ * })
276
+ *
277
+ * app.mount('#app')
278
+ * ```
279
+ *
280
+ * @public
281
+ */
282
+ export declare const Stonecrop: Plugin_2;
283
+
284
+ /**
285
+ * Stonecrop class
286
+ * @public
287
+ */
288
+ declare class Stonecrop_2 {
289
+ /**
290
+ * The root Stonecrop instance
291
+ */
292
+ static _root: Stonecrop_2;
293
+ /**
294
+ * The name of the Stonecrop instance
295
+ * @readonly
296
+ *
297
+ * @defaultValue 'Stonecrop'
298
+ */
299
+ readonly name = "Stonecrop";
300
+ /**
301
+ * The registry is an immutable collection of doctypes
302
+ * @example
303
+ * ```ts
304
+ * {
305
+ * 'task': {
306
+ * doctype: 'Task',
307
+ * schema: {
308
+ * title: 'string',
309
+ * description: 'string',
310
+ * ...
311
+ * }
312
+ * },
313
+ * ...
314
+ * }
315
+ * ```
316
+ * @see {@link Registry}
317
+ * @see {@link DoctypeMeta}
318
+ */
319
+ readonly registry: Registry;
320
+ /**
321
+ * schema - The Stonecrop schema; the schema is a subset of the registry
322
+ * @example
323
+ * ```ts
324
+ * {
325
+ * doctype: 'Task',
326
+ * schema: {
327
+ * title: 'string',
328
+ * description: 'string',
329
+ * ...
330
+ * }
331
+ * }
332
+ * ```
333
+ * @see {@link Registry}
334
+ * @see {@link DoctypeMeta}
335
+ * @see {@link DoctypeMeta.schema}
336
+ */
337
+ schema: Schema;
338
+ /**
339
+ * The workflow is a subset of the registry
340
+ */
341
+ workflow: ImmutableDoctype['workflow'];
342
+ /**
343
+ * The actions are a subset of the registry
344
+ */
345
+ actions: ImmutableDoctype['actions'];
346
+ /**
347
+ * The Pinia store that manages the mutable records
348
+ */
349
+ store: ReturnType<typeof useDataStore>;
350
+ /**
351
+ * @param registry - The immutable registry
352
+ * @param store - The mutable Pinia store
353
+ * @param schema - The Stonecrop schema
354
+ * @param workflow - The Stonecrop workflow
355
+ * @param actions - The Stonecrop actions
356
+ * @returns The Stonecrop instance with the given registry, store, schema, workflow, and actions. If a Stonecrop instance has already been created, it returns the existing instance instead of creating a new one.
357
+ * @example
358
+ * ```ts
359
+ * const registry = new Registry()
360
+ * const store = useDataStore()
361
+ * const stonecrop = new Stonecrop(registry, store)
362
+ * ```
363
+ */
364
+ constructor(registry: Registry, store: ReturnType<typeof useDataStore>, schema?: Schema, workflow?: ImmutableDoctype['workflow'], actions?: ImmutableDoctype['actions']);
365
+ /**
366
+ * Sets up the Stonecrop instance with the given doctype
367
+ * @param doctype - The doctype to setup
368
+ * @example
369
+ * ```ts
370
+ * const doctype = await registry.getMeta('Task')
371
+ * stonecrop.setup(doctype)
372
+ * ```
373
+ */
374
+ setup(doctype: DoctypeMeta): void;
375
+ /**
376
+ * Gets the meta for the given doctype
377
+ * @param doctype - The doctype to get meta for
378
+ * @returns The meta for the given doctype
379
+ * @throws NotImplementedError
380
+ * @example
381
+ * ```ts
382
+ * const doctype = await registry.getMeta('Task')
383
+ * const meta = stonecrop.getMeta(doctype)
384
+ * ```
385
+ * @see {@link DoctypeMeta}
386
+ */
387
+ getMeta(doctype: DoctypeMeta): DoctypeMeta | Promise<DoctypeMeta> | never;
388
+ /**
389
+ * Gets the workflow for the given doctype
390
+ * @param doctype - The doctype to get workflow for
391
+ * @example
392
+ * ```ts
393
+ * const doctype = await registry.getMeta('Task')
394
+ * stonecrop.getWorkflow(doctype)
395
+ * ```
396
+ */
397
+ getWorkflow(doctype: DoctypeMeta): void;
398
+ /**
399
+ * Gets the actions for the given doctype
400
+ * @param doctype - The doctype to get actions for
401
+ * @example
402
+ * ```ts
403
+ * const doctype = await registry.getMeta('Task')
404
+ * stonecrop.getActions(doctype)
405
+ * ```
406
+ */
407
+ getActions(doctype: DoctypeMeta): void;
408
+ /**
409
+ * Gets the records for the given doctype
410
+ * @param doctype - The doctype to get records for
411
+ * @param filters - The filters to apply to the records
412
+ * @example
413
+ * ```ts
414
+ * const doctype = await registry.getMeta('Task')
415
+ * await stonecrop.getRecords(doctype)
416
+ * ```
417
+ * @example
418
+ * ```ts
419
+ * const doctype = await registry.getMeta('Task')
420
+ * const filters = JSON.stringify({ status: 'Open' })
421
+ * await stonecrop.getRecords(doctype, { body: filters })
422
+ * ```
423
+ */
424
+ getRecords(doctype: DoctypeMeta, filters?: RequestInit): Promise<void>;
425
+ /**
426
+ * Gets the record for the given doctype and id
427
+ * @param doctype - The doctype to get record for
428
+ * @param id - The id of the record to get
429
+ * @example
430
+ * ```ts
431
+ * const doctype = await registry.getMeta('Task')
432
+ * await stonecrop.getRecord(doctype, 'TASK-00001')
433
+ * ```
434
+ */
435
+ getRecord(doctype: DoctypeMeta, id: string): Promise<void>;
436
+ /**
437
+ * Runs the action for the given doctype and id
438
+ * @param doctype - The doctype to run action for
439
+ * @param action - The action to run
440
+ * @param id - The id(s) of the record(s) to run action on
441
+ * @example
442
+ * ```ts
443
+ * const doctype = await registry.getMeta('Task')
444
+ * stonecrop.runAction(doctype, 'CREATE')
445
+ * ```
446
+ * @example
447
+ * ```ts
448
+ * const doctype = await registry.getMeta('Task')
449
+ * stonecrop.runAction(doctype, 'UPDATE', ['TASK-00001'])
450
+ * ```
451
+ * @example
452
+ * ```ts
453
+ * const doctype = await registry.getMeta('Task')
454
+ * stonecrop.runAction(doctype, 'DELETE', ['TASK-00001'])
455
+ * ```
456
+ * @example
457
+ * ```ts
458
+ * const doctype = await registry.getMeta('Task')
459
+ * stonecrop.runAction(doctype, 'TRANSITION', ['TASK-00001', 'TASK-00002'])
460
+ * ```
461
+ */
462
+ runAction(doctype: DoctypeMeta, action: string, id?: string[]): void;
463
+ }
464
+
465
+ /**
466
+ * Stonecrop composable return type
467
+ * @public
468
+ */
469
+ export declare type StonecropReturn = {
470
+ stonecrop: Ref<Stonecrop_2>;
471
+ isReady: Ref<boolean>;
472
+ };
473
+
474
+ /**
475
+ * Table column definition.
476
+ * @public
477
+ */
478
+ export declare type TableColumn = {
479
+ name: string;
480
+ align?: CanvasTextAlign;
481
+ edit?: boolean;
482
+ label?: string;
483
+ type?: string;
484
+ width?: string;
485
+ pinned?: boolean;
486
+ cellComponent?: string;
487
+ cellComponentProps?: Record<string, any>;
488
+ /**
489
+ * The component to use for the modal. If a function is provided, it will be called with the cell context.
490
+ * The following properties are available on the cell context:
491
+ * - `row` - the row object
492
+ * - `column` - the column object
493
+ * - `table` - the table object
494
+ *
495
+ * The function should return the name of the component to use for the modal.
496
+ *
497
+ * Additionally, the following properties will be automatically passed to the modal component:
498
+ * - `colIndex` - the column index of the current cell
499
+ * - `rowIndex` - the row index of the current cell
500
+ * - `store` - the table data store
501
+ */
502
+ modalComponent?: string | ((context: CellContext) => string);
503
+ modalComponentExtraProps?: Record<string, any>;
504
+ format?: string | ((value: any, context: CellContext) => string);
505
+ mask?: (value: any) => any;
506
+ };
507
+
508
+ /**
509
+ * Table configuration definition.
510
+ * @public
511
+ */
512
+ export declare type TableConfig = {
513
+ /**
514
+ * The type of view to display the table in. Possible values:
515
+ * - `uncounted` - row numbers are not displayed in the table
516
+ * - `list` - row numbers are displayed in the table
517
+ * - `list-expansion` - carets are displayed in the number column that expand/collapse the row inline
518
+ * - `tree` - carets are displayed in the number column that expand/collapse grouped rows
519
+ */
520
+ view?: 'uncounted' | 'list' | 'list-expansion' | 'tree';
521
+ fullWidth?: boolean;
522
+ };
523
+
524
+ /**
525
+ * Table row definition.
526
+ * @public
527
+ */
528
+ export declare type TableRow = {
529
+ [key: string]: any;
530
+ indent?: number;
531
+ parent?: number;
532
+ };
533
+
534
+ /**
535
+ * Schema structure for defining tables inside AForm
536
+ * @public
537
+ */
538
+ export declare type TableSchema = BaseSchema & {
539
+ /**
540
+ * The columns to display in the table
541
+ * @public
542
+ */
543
+ columns?: TableColumn[];
544
+ /**
545
+ * The configuration for the table
546
+ * @public
547
+ */
548
+ config?: TableConfig;
549
+ /**
550
+ * The rows to display in the table
551
+ * @public
552
+ */
553
+ rows?: TableRow[];
554
+ };
555
+
556
+ declare const useDataStore: StoreDefinition<"data", Pick<{
557
+ records: Ref<Record<string, any>[], Record<string, any>[]>;
558
+ record: Ref<Record<string, any>, Record<string, any>>;
559
+ }, "records" | "record">, Pick<{
560
+ records: Ref<Record<string, any>[], Record<string, any>[]>;
561
+ record: Ref<Record<string, any>, Record<string, any>>;
562
+ }, never>, Pick<{
563
+ records: Ref<Record<string, any>[], Record<string, any>[]>;
564
+ record: Ref<Record<string, any>, Record<string, any>>;
565
+ }, never>>;
566
+
567
+ /**
568
+ * Stonecrop composable
569
+ * @param registry - An existing Stonecrop Registry instance
570
+ * @returns The Stonecrop instance and a boolean indicating if Stonecrop is setup and ready
571
+ * @throws Error if the Stonecrop plugin is not enabled before using the composable
572
+ * @public
573
+ */
574
+ export declare function useStonecrop(registry?: Registry): StonecropReturn;
575
+
576
+ export { }