@stonecrop/stonecrop 0.3.7 → 0.3.8
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/composable.js +15 -10
- package/dist/registry.js +1 -1
- package/dist/src/composable.d.ts.map +1 -1
- package/dist/src/stonecrop.d.ts +7 -7
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stores/xstate.d.ts +22 -1
- package/dist/src/stores/xstate.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +6 -6
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/stonecrop.d.ts +11 -11
- package/dist/stonecrop.js +129 -124
- package/dist/stonecrop.js.map +1 -1
- package/dist/stonecrop.umd.cjs +2 -2
- package/dist/stonecrop.umd.cjs.map +1 -1
- package/dist/stores/xstate.js +1 -1
- package/package.json +4 -4
- package/src/composable.ts +15 -9
- package/src/registry.ts +1 -1
- package/src/stonecrop.ts +22 -19
- package/src/stores/xstate.ts +1 -1
- package/src/types/index.ts +6 -6
package/dist/stores/xstate.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/stonecrop",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "schema helper",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"pinia": "^2.3.0",
|
|
36
36
|
"pinia-shared-state": "^0.3.0",
|
|
37
37
|
"pinia-undo": "^0.1.9",
|
|
38
|
-
"pinia-xstate": "^
|
|
38
|
+
"pinia-xstate": "^2.2.1",
|
|
39
39
|
"vue": "^3.5.11",
|
|
40
40
|
"vue-router": "^4.4.0",
|
|
41
41
|
"xstate": "^4.38.3"
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"eslint-plugin-vue": "^9.11.1",
|
|
53
53
|
"typescript": "^5.6.3",
|
|
54
54
|
"vite": "^5.4.5",
|
|
55
|
-
"@stonecrop/atable": "0.3.7",
|
|
56
55
|
"stonecrop-rig": "0.2.22",
|
|
57
|
-
"@stonecrop/aform": "0.3.
|
|
56
|
+
"@stonecrop/aform": "0.3.8",
|
|
57
|
+
"@stonecrop/atable": "0.3.8"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public"
|
package/src/composable.ts
CHANGED
|
@@ -32,10 +32,13 @@ export function useStonecrop(registry?: Registry): StonecropReturn {
|
|
|
32
32
|
throw new Error('Please enable the Stonecrop plugin before using the Stonecrop composable')
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// @ts-expect-error TODO: handle empty registry passed to Stonecrop
|
|
35
36
|
const stonecrop = ref(new Stonecrop(registry, store))
|
|
36
37
|
const isReady = ref(false)
|
|
37
38
|
|
|
38
39
|
onBeforeMount(async () => {
|
|
40
|
+
if (!registry) return
|
|
41
|
+
|
|
39
42
|
const route = registry.router.currentRoute.value
|
|
40
43
|
const doctypeSlug = route.params.records?.toString().toLowerCase()
|
|
41
44
|
const recordId = route.params.record?.toString().toLowerCase()
|
|
@@ -46,19 +49,22 @@ export function useStonecrop(registry?: Registry): StonecropReturn {
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
// setup doctype via registry
|
|
49
|
-
const doctype = await registry.getMeta(doctypeSlug)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
const doctype = await registry.getMeta?.(doctypeSlug)
|
|
53
|
+
if (doctype) {
|
|
54
|
+
registry.addDoctype(doctype)
|
|
55
|
+
stonecrop.value.setup(doctype)
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
if (doctypeSlug) {
|
|
58
|
+
if (recordId) {
|
|
59
|
+
await stonecrop.value.getRecord(doctype, recordId)
|
|
60
|
+
} else {
|
|
61
|
+
await stonecrop.value.getRecords(doctype)
|
|
62
|
+
}
|
|
58
63
|
}
|
|
64
|
+
|
|
65
|
+
stonecrop.value.runAction(doctype, 'LOAD', recordId ? [recordId] : undefined)
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
stonecrop.value.runAction(doctype, 'LOAD', recordId ? [recordId] : undefined)
|
|
62
68
|
isReady.value = true
|
|
63
69
|
})
|
|
64
70
|
|
package/src/registry.ts
CHANGED
|
@@ -58,7 +58,7 @@ export default class Registry {
|
|
|
58
58
|
if (!(doctype.doctype in Object.keys(this.registry))) {
|
|
59
59
|
this.registry[doctype.slug] = doctype
|
|
60
60
|
}
|
|
61
|
-
if (!this.router.hasRoute(doctype.doctype)) {
|
|
61
|
+
if (!this.router.hasRoute(doctype.doctype) && doctype.component) {
|
|
62
62
|
this.router.addRoute({
|
|
63
63
|
path: `/${doctype.slug}`,
|
|
64
64
|
name: doctype.slug,
|
package/src/stonecrop.ts
CHANGED
|
@@ -43,6 +43,11 @@ export class Stonecrop {
|
|
|
43
43
|
*/
|
|
44
44
|
readonly registry: Registry
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The Pinia store that manages the mutable records
|
|
48
|
+
*/
|
|
49
|
+
store: ReturnType<typeof useDataStore>
|
|
50
|
+
|
|
46
51
|
/**
|
|
47
52
|
* schema - The Stonecrop schema; the schema is a subset of the registry
|
|
48
53
|
* @example
|
|
@@ -60,22 +65,17 @@ export class Stonecrop {
|
|
|
60
65
|
* @see {@link DoctypeMeta}
|
|
61
66
|
* @see {@link DoctypeMeta.schema}
|
|
62
67
|
*/
|
|
63
|
-
schema
|
|
68
|
+
schema?: Schema
|
|
64
69
|
|
|
65
70
|
/**
|
|
66
71
|
* The workflow is a subset of the registry
|
|
67
72
|
*/
|
|
68
|
-
workflow
|
|
73
|
+
workflow?: ImmutableDoctype['workflow']
|
|
69
74
|
|
|
70
75
|
/**
|
|
71
76
|
* The actions are a subset of the registry
|
|
72
77
|
*/
|
|
73
|
-
actions
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The Pinia store that manages the mutable records
|
|
77
|
-
*/
|
|
78
|
-
store: ReturnType<typeof useDataStore>
|
|
78
|
+
actions?: ImmutableDoctype['actions']
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* @param registry - The immutable registry
|
|
@@ -236,19 +236,22 @@ export class Stonecrop {
|
|
|
236
236
|
*/
|
|
237
237
|
runAction(doctype: DoctypeMeta, action: string, id?: string[]): void {
|
|
238
238
|
const doctypeRegistry = this.registry.registry[doctype.slug]
|
|
239
|
-
const actions = doctypeRegistry.actions
|
|
239
|
+
const actions = doctypeRegistry.actions?.get(action)
|
|
240
240
|
|
|
241
241
|
// trigger the action on the state machine
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
242
|
+
if (this.workflow) {
|
|
243
|
+
const { initialState } = this.workflow
|
|
244
|
+
this.workflow.transition(initialState, { type: action })
|
|
245
|
+
|
|
246
|
+
// run actions after state machine transition
|
|
247
|
+
// TODO: should this happen with or without the workflow?
|
|
248
|
+
if (actions && actions.length > 0) {
|
|
249
|
+
actions.forEach(action => {
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
251
|
+
const actionFn = new Function(action)
|
|
252
|
+
actionFn(id)
|
|
253
|
+
})
|
|
254
|
+
}
|
|
252
255
|
}
|
|
253
256
|
}
|
|
254
257
|
}
|
package/src/stores/xstate.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SchemaTypes } from '@stonecrop/aform'
|
|
1
|
+
import type { SchemaTypes } from '@stonecrop/aform'
|
|
2
2
|
import { List, Map } from 'immutable'
|
|
3
|
-
import { Component } from 'vue'
|
|
4
|
-
import { Router } from 'vue-router'
|
|
5
|
-
import { MachineConfig, StateMachine } from 'xstate'
|
|
3
|
+
import type { Component } from 'vue'
|
|
4
|
+
import type { Router } from 'vue-router'
|
|
5
|
+
import type { MachineConfig, StateMachine } from 'xstate'
|
|
6
6
|
|
|
7
7
|
import DoctypeMeta from '../doctype'
|
|
8
8
|
|
|
@@ -13,7 +13,7 @@ import DoctypeMeta from '../doctype'
|
|
|
13
13
|
export type ImmutableDoctype = {
|
|
14
14
|
// TODO: allow schema to be a function
|
|
15
15
|
readonly schema?: List<SchemaTypes>
|
|
16
|
-
readonly workflow: StateMachine<unknown,
|
|
16
|
+
readonly workflow: StateMachine<unknown, any, any>
|
|
17
17
|
readonly actions?: Map<string, string[]>
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -24,7 +24,7 @@ export type ImmutableDoctype = {
|
|
|
24
24
|
export type MutableDoctype = {
|
|
25
25
|
// TODO: allow schema to be a function
|
|
26
26
|
schema?: SchemaTypes[]
|
|
27
|
-
workflow: MachineConfig<unknown,
|
|
27
|
+
workflow: MachineConfig<unknown, any, any>
|
|
28
28
|
actions?: Record<string, string[]>
|
|
29
29
|
}
|
|
30
30
|
|