@stonecrop/stonecrop 0.3.11 → 0.4.1
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 +17 -19
- package/dist/plugins/index.js +6 -3
- package/dist/registry.js +7 -7
- package/dist/src/composable.d.ts +1 -2
- package/dist/src/composable.d.ts.map +1 -1
- package/dist/src/plugins/index.d.ts.map +1 -1
- package/dist/src/registry.d.ts +6 -6
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/stonecrop.d.ts +7 -8
- package/dist/stonecrop.js +1028 -2827
- package/dist/stonecrop.js.map +1 -1
- package/dist/stonecrop.tsbuildinfo +1 -1
- package/dist/stonecrop.umd.cjs +7 -37
- package/dist/stonecrop.umd.cjs.map +1 -1
- package/package.json +5 -5
- package/src/composable.ts +18 -21
- package/src/plugins/index.ts +7 -3
- package/src/registry.ts +10 -9
- package/dist/router.js +0 -6
- package/dist/src/router.d.ts +0 -3
- package/dist/src/router.d.ts.map +0 -1
- package/src/router.ts +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/stonecrop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "schema helper",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"eslint": "^8.40.0",
|
|
51
51
|
"eslint-config-prettier": "^8.8.0",
|
|
52
52
|
"eslint-plugin-vue": "^9.11.1",
|
|
53
|
-
"typescript": "
|
|
53
|
+
"typescript": "~5.6.3",
|
|
54
54
|
"vite": "^5.4.5",
|
|
55
|
-
"@stonecrop/aform": "0.
|
|
56
|
-
"
|
|
57
|
-
"stonecrop
|
|
55
|
+
"@stonecrop/aform": "0.4.1",
|
|
56
|
+
"stonecrop-rig": "0.2.22",
|
|
57
|
+
"@stonecrop/atable": "0.4.1"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public"
|
package/src/composable.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inject,
|
|
1
|
+
import { inject, onMounted, Ref, ref } from 'vue'
|
|
2
2
|
|
|
3
3
|
import Registry from './registry'
|
|
4
4
|
import { Stonecrop } from './stonecrop'
|
|
@@ -9,8 +9,7 @@ import { useDataStore } from './stores/data'
|
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
11
|
export type StonecropReturn = {
|
|
12
|
-
stonecrop: Ref<Stonecrop>
|
|
13
|
-
isReady: Ref<boolean>
|
|
12
|
+
stonecrop: Ref<Stonecrop | undefined>
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -21,23 +20,24 @@ export type StonecropReturn = {
|
|
|
21
20
|
* @public
|
|
22
21
|
*/
|
|
23
22
|
export function useStonecrop(registry?: Registry): StonecropReturn {
|
|
24
|
-
|
|
25
|
-
registry = inject<Registry>('$registry')
|
|
26
|
-
}
|
|
23
|
+
const stonecrop = ref<Stonecrop>()
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
onMounted(async () => {
|
|
26
|
+
if (!registry) {
|
|
27
|
+
registry = inject<Registry>('$registry')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let store: ReturnType<typeof useDataStore>
|
|
31
|
+
try {
|
|
32
|
+
store = useDataStore()
|
|
33
|
+
} catch (e) {
|
|
34
|
+
throw new Error('Please enable the Stonecrop plugin before using the Stonecrop composable')
|
|
35
|
+
}
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const isReady = ref(false)
|
|
37
|
+
// @ts-expect-error TODO: handle empty registry passed to Stonecrop
|
|
38
|
+
stonecrop.value = new Stonecrop(registry, store)
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
if (!registry) return
|
|
40
|
+
if (!registry || !registry.router) return
|
|
41
41
|
|
|
42
42
|
const route = registry.router.currentRoute.value
|
|
43
43
|
const doctypeSlug = route.params.records?.toString().toLowerCase()
|
|
@@ -64,10 +64,7 @@ export function useStonecrop(registry?: Registry): StonecropReturn {
|
|
|
64
64
|
|
|
65
65
|
stonecrop.value.runAction(doctype, 'LOAD', recordId ? [recordId] : undefined)
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
isReady.value = true
|
|
69
67
|
})
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
return { stonecrop, isReady }
|
|
69
|
+
return { stonecrop }
|
|
73
70
|
}
|
package/src/plugins/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { App, type Plugin } from 'vue'
|
|
2
2
|
|
|
3
3
|
import Registry from '../registry'
|
|
4
|
-
import router from '../router'
|
|
5
4
|
import { pinia } from '../stores'
|
|
6
5
|
import type { InstallOptions } from '../types'
|
|
7
6
|
|
|
@@ -35,10 +34,15 @@ import type { InstallOptions } from '../types'
|
|
|
35
34
|
*/
|
|
36
35
|
const plugin: Plugin = {
|
|
37
36
|
install: (app: App, options?: InstallOptions) => {
|
|
38
|
-
|
|
37
|
+
// check if the router is already installed via another plugin
|
|
38
|
+
const existingRouter = app.config.globalProperties.$router
|
|
39
|
+
const appRouter = existingRouter || options?.router
|
|
39
40
|
const registry = new Registry(appRouter, options?.getMeta)
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
if (!existingRouter && appRouter) {
|
|
43
|
+
app.use(appRouter)
|
|
44
|
+
}
|
|
45
|
+
|
|
42
46
|
app.use(pinia)
|
|
43
47
|
app.provide('$registry', registry)
|
|
44
48
|
|
package/src/registry.ts
CHANGED
|
@@ -19,32 +19,32 @@ export default class Registry {
|
|
|
19
19
|
*/
|
|
20
20
|
name: string
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* The Vue router instance
|
|
24
|
-
* @see {@link https://router.vuejs.org/}
|
|
25
|
-
*/
|
|
26
|
-
router: Router
|
|
27
|
-
|
|
28
22
|
/**
|
|
29
23
|
* The registry property contains a collection of doctypes
|
|
30
24
|
* @see {@link DoctypeMeta}
|
|
31
25
|
*/
|
|
32
26
|
registry: Record<string, DoctypeMeta>
|
|
33
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The Vue router instance
|
|
30
|
+
* @see {@link https://router.vuejs.org/}
|
|
31
|
+
*/
|
|
32
|
+
router?: Router
|
|
33
|
+
|
|
34
34
|
/**
|
|
35
35
|
* The getMeta function fetches doctype metadata from an API
|
|
36
36
|
* @see {@link DoctypeMeta}
|
|
37
37
|
*/
|
|
38
38
|
getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>
|
|
39
39
|
|
|
40
|
-
constructor(router
|
|
40
|
+
constructor(router?: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>) {
|
|
41
41
|
if (Registry._root) {
|
|
42
42
|
return Registry._root
|
|
43
43
|
}
|
|
44
44
|
Registry._root = this
|
|
45
45
|
this.name = 'Registry'
|
|
46
|
-
this.router = router
|
|
47
46
|
this.registry = {}
|
|
47
|
+
this.router = router
|
|
48
48
|
this.getMeta = getMeta
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -58,7 +58,8 @@ export default class Registry {
|
|
|
58
58
|
if (!(doctype.doctype in Object.keys(this.registry))) {
|
|
59
59
|
this.registry[doctype.slug] = doctype
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
|
|
62
|
+
if (doctype.component && this.router && !this.router.hasRoute(doctype.doctype)) {
|
|
62
63
|
this.router.addRoute({
|
|
63
64
|
path: `/${doctype.slug}`,
|
|
64
65
|
name: doctype.slug,
|
package/dist/router.js
DELETED
package/dist/src/router.d.ts
DELETED
package/dist/src/router.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM,6BAGV,CAAA;AAEF,eAAe,MAAM,CAAA"}
|