@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/stonecrop",
3
- "version": "0.3.11",
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": "^5.6.3",
53
+ "typescript": "~5.6.3",
54
54
  "vite": "^5.4.5",
55
- "@stonecrop/aform": "0.3.11",
56
- "@stonecrop/atable": "0.3.11",
57
- "stonecrop-rig": "0.2.22"
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, onBeforeMount, Ref, ref } from 'vue'
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
- if (!registry) {
25
- registry = inject<Registry>('$registry')
26
- }
23
+ const stonecrop = ref<Stonecrop>()
27
24
 
28
- let store: ReturnType<typeof useDataStore>
29
- try {
30
- store = useDataStore()
31
- } catch (e) {
32
- throw new Error('Please enable the Stonecrop plugin before using the Stonecrop composable')
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
- // @ts-expect-error TODO: handle empty registry passed to Stonecrop
36
- const stonecrop = ref(new Stonecrop(registry, store))
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
- onBeforeMount(async () => {
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
- // @ts-expect-error TODO: fix the type mismatch
72
- return { stonecrop, isReady }
69
+ return { stonecrop }
73
70
  }
@@ -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
- const appRouter = options?.router || router
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
- app.use(appRouter)
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: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>) {
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
- if (!this.router.hasRoute(doctype.doctype) && doctype.component) {
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
@@ -1,6 +0,0 @@
1
- import { createRouter, createWebHistory } from 'vue-router';
2
- const router = createRouter({
3
- history: createWebHistory(),
4
- routes: [],
5
- });
6
- export default router;
@@ -1,3 +0,0 @@
1
- declare const router: import("vue-router").Router;
2
- export default router;
3
- //# sourceMappingURL=router.d.ts.map
@@ -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"}
package/src/router.ts DELETED
@@ -1,8 +0,0 @@
1
- import { createRouter, createWebHistory } from 'vue-router'
2
-
3
- const router = createRouter({
4
- history: createWebHistory(),
5
- routes: [],
6
- })
7
-
8
- export default router