@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.
@@ -1,4 +1,4 @@
1
- import { inject, onBeforeMount, ref } from 'vue';
1
+ import { inject, onMounted, ref } from 'vue';
2
2
  import { Stonecrop } from './stonecrop';
3
3
  import { useDataStore } from './stores/data';
4
4
  /**
@@ -9,21 +9,21 @@ import { useDataStore } from './stores/data';
9
9
  * @public
10
10
  */
11
11
  export function useStonecrop(registry) {
12
- if (!registry) {
13
- registry = inject('$registry');
14
- }
15
- let store;
16
- try {
17
- store = useDataStore();
18
- }
19
- catch (e) {
20
- throw new Error('Please enable the Stonecrop plugin before using the Stonecrop composable');
21
- }
22
- // @ts-expect-error TODO: handle empty registry passed to Stonecrop
23
- const stonecrop = ref(new Stonecrop(registry, store));
24
- const isReady = ref(false);
25
- onBeforeMount(async () => {
26
- if (!registry)
12
+ const stonecrop = ref();
13
+ onMounted(async () => {
14
+ if (!registry) {
15
+ registry = inject('$registry');
16
+ }
17
+ let store;
18
+ try {
19
+ store = useDataStore();
20
+ }
21
+ catch (e) {
22
+ throw new Error('Please enable the Stonecrop plugin before using the Stonecrop composable');
23
+ }
24
+ // @ts-expect-error TODO: handle empty registry passed to Stonecrop
25
+ stonecrop.value = new Stonecrop(registry, store);
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();
@@ -47,8 +47,6 @@ export function useStonecrop(registry) {
47
47
  }
48
48
  stonecrop.value.runAction(doctype, 'LOAD', recordId ? [recordId] : undefined);
49
49
  }
50
- isReady.value = true;
51
50
  });
52
- // @ts-expect-error TODO: fix the type mismatch
53
- return { stonecrop, isReady };
51
+ return { stonecrop };
54
52
  }
@@ -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,
@@ -6,8 +6,7 @@ import { Stonecrop } from './stonecrop';
6
6
  * @public
7
7
  */
8
8
  export type StonecropReturn = {
9
- stonecrop: Ref<Stonecrop>;
10
- isReady: Ref<boolean>;
9
+ stonecrop: Ref<Stonecrop | undefined>;
11
10
  };
12
11
  /**
13
12
  * Stonecrop composable
@@ -1 +1 @@
1
- {"version":3,"file":"composable.d.ts","sourceRoot":"","sources":["../../src/composable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,GAAG,EAAO,MAAM,KAAK,CAAA;AAErD,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IACzB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACrB,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,eAAe,CAkDjE"}
1
+ {"version":3,"file":"composable.d.ts","sourceRoot":"","sources":["../../src/composable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,GAAG,EAAO,MAAM,KAAK,CAAA;AAEjD,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC,CAAA;CACrC,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,eAAe,CAgDjE"}
@@ -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
@@ -467,8 +467,7 @@ declare class Stonecrop_2 {
467
467
  * @public
468
468
  */
469
469
  export declare type StonecropReturn = {
470
- stonecrop: Ref<Stonecrop_2>;
471
- isReady: Ref<boolean>;
470
+ stonecrop: Ref<Stonecrop_2 | undefined>;
472
471
  };
473
472
 
474
473
  /**