@stonecrop/stonecrop 0.3.10 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/stonecrop",
3
- "version": "0.3.10",
3
+ "version": "0.4.0",
4
4
  "description": "schema helper",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -50,10 +50,10 @@
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.10",
56
- "@stonecrop/atable": "0.3.10",
55
+ "@stonecrop/aform": "0.4.0",
56
+ "@stonecrop/atable": "0.4.0",
57
57
  "stonecrop-rig": "0.2.22"
58
58
  },
59
59
  "publishConfig": {
package/src/composable.ts CHANGED
@@ -37,7 +37,7 @@ export function useStonecrop(registry?: Registry): StonecropReturn {
37
37
  const isReady = ref(false)
38
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()
@@ -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