@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.
@@ -23,7 +23,7 @@ export function useStonecrop(registry) {
23
23
  const stonecrop = ref(new Stonecrop(registry, store));
24
24
  const isReady = ref(false);
25
25
  onBeforeMount(async () => {
26
- if (!registry)
26
+ if (!registry || !registry.router)
27
27
  return;
28
28
  const route = registry.router.currentRoute.value;
29
29
  const doctypeSlug = route.params.records?.toString().toLowerCase();
@@ -1,5 +1,4 @@
1
1
  import Registry from '../registry';
2
- import router from '../router';
3
2
  import { pinia } from '../stores';
4
3
  /**
5
4
  * Stonecrop Vue plugin
@@ -31,9 +30,13 @@ import { pinia } from '../stores';
31
30
  */
32
31
  const plugin = {
33
32
  install: (app, options) => {
34
- const appRouter = options?.router || router;
33
+ // check if the router is already installed via another plugin
34
+ const existingRouter = app.config.globalProperties.$router;
35
+ const appRouter = existingRouter || options?.router;
35
36
  const registry = new Registry(appRouter, options?.getMeta);
36
- app.use(appRouter);
37
+ if (!existingRouter && appRouter) {
38
+ app.use(appRouter);
39
+ }
37
40
  app.use(pinia);
38
41
  app.provide('$registry', registry);
39
42
  if (options?.components) {
package/dist/registry.js CHANGED
@@ -13,16 +13,16 @@ export default class Registry {
13
13
  * @defaultValue 'Registry'
14
14
  */
15
15
  name;
16
- /**
17
- * The Vue router instance
18
- * @see {@link https://router.vuejs.org/}
19
- */
20
- router;
21
16
  /**
22
17
  * The registry property contains a collection of doctypes
23
18
  * @see {@link DoctypeMeta}
24
19
  */
25
20
  registry;
21
+ /**
22
+ * The Vue router instance
23
+ * @see {@link https://router.vuejs.org/}
24
+ */
25
+ router;
26
26
  /**
27
27
  * The getMeta function fetches doctype metadata from an API
28
28
  * @see {@link DoctypeMeta}
@@ -34,8 +34,8 @@ export default class Registry {
34
34
  }
35
35
  Registry._root = this;
36
36
  this.name = 'Registry';
37
- this.router = router;
38
37
  this.registry = {};
38
+ this.router = router;
39
39
  this.getMeta = getMeta;
40
40
  }
41
41
  /**
@@ -48,7 +48,7 @@ export default class Registry {
48
48
  if (!(doctype.doctype in Object.keys(this.registry))) {
49
49
  this.registry[doctype.slug] = doctype;
50
50
  }
51
- if (!this.router.hasRoute(doctype.doctype) && doctype.component) {
51
+ if (doctype.component && this.router && !this.router.hasRoute(doctype.doctype)) {
52
52
  this.router.addRoute({
53
53
  path: `/${doctype.slug}`,
54
54
  name: doctype.slug,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,KAAK,CAAA;AAOtC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,QAAA,MAAM,MAAM,EAAE,MAeb,CAAA;AAED,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,KAAK,CAAA;AAMtC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,QAAA,MAAM,MAAM,EAAE,MAoBb,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -15,22 +15,22 @@ export default class Registry {
15
15
  * @defaultValue 'Registry'
16
16
  */
17
17
  name: string;
18
- /**
19
- * The Vue router instance
20
- * @see {@link https://router.vuejs.org/}
21
- */
22
- router: Router;
23
18
  /**
24
19
  * The registry property contains a collection of doctypes
25
20
  * @see {@link DoctypeMeta}
26
21
  */
27
22
  registry: Record<string, DoctypeMeta>;
23
+ /**
24
+ * The Vue router instance
25
+ * @see {@link https://router.vuejs.org/}
26
+ */
27
+ router?: Router;
28
28
  /**
29
29
  * The getMeta function fetches doctype metadata from an API
30
30
  * @see {@link DoctypeMeta}
31
31
  */
32
32
  getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>;
33
- constructor(router: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>);
33
+ constructor(router?: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>);
34
34
  /**
35
35
  * Get doctype metadata
36
36
  * @param doctype - The doctype to fetch metadata for
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,OAAO,WAAW,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAA;IAEtB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAErC;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;gBAErD,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAW7F;;;;;OAKG;IACH,UAAU,CAAC,OAAO,EAAE,WAAW;CAY/B"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,OAAO,WAAW,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAA;IAEtB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAErC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;gBAErD,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAW9F;;;;;OAKG;IACH,UAAU,CAAC,OAAO,EAAE,WAAW;CAa/B"}
@@ -211,22 +211,22 @@ export declare class Registry {
211
211
  * @defaultValue 'Registry'
212
212
  */
213
213
  name: string;
214
- /**
215
- * The Vue router instance
216
- * @see {@link https://router.vuejs.org/}
217
- */
218
- router: Router;
219
214
  /**
220
215
  * The registry property contains a collection of doctypes
221
216
  * @see {@link DoctypeMeta}
222
217
  */
223
218
  registry: Record<string, DoctypeMeta>;
219
+ /**
220
+ * The Vue router instance
221
+ * @see {@link https://router.vuejs.org/}
222
+ */
223
+ router?: Router;
224
224
  /**
225
225
  * The getMeta function fetches doctype metadata from an API
226
226
  * @see {@link DoctypeMeta}
227
227
  */
228
228
  getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>;
229
- constructor(router: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>);
229
+ constructor(router?: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>);
230
230
  /**
231
231
  * Get doctype metadata
232
232
  * @param doctype - The doctype to fetch metadata for