@data-fair/frame 0.15.0 → 0.16.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.
@@ -4,5 +4,6 @@ import type { Router } from 'vue-router';
4
4
  export declare const useDFrameParentUrls: (dFrameContent: DFrameContent, router?: Router) => {
5
5
  get: (childHref: string) => Ref<string | undefined>;
6
6
  clear: () => void;
7
+ parentUrls: Record<string, string | null>;
7
8
  };
8
9
  export default useDFrameParentUrls;
@@ -1,27 +1,27 @@
1
- import { onScopeDispose, ref } from 'vue';
1
+ import { onScopeDispose, toRef, reactive } from 'vue';
2
2
  export const useDFrameParentUrls = (dFrameContent, router) => {
3
- let computedParentUrls = {};
3
+ let parentUrls = reactive({});
4
4
  let listeners = {};
5
5
  const get = (childHref) => {
6
- if (computedParentUrls[childHref])
7
- return computedParentUrls[childHref];
8
- const resolvedChildHref = router ? router.resolve(childHref).href : childHref;
9
- const parentUrl = computedParentUrls[childHref] = ref();
10
- const listener = (result) => {
11
- parentUrl.value = result;
12
- };
13
- listeners[resolvedChildHref] = listener;
14
- dFrameContent.addParentUrlListener(resolvedChildHref, listener);
15
- return parentUrl;
6
+ if (parentUrls[childHref] === undefined) {
7
+ const resolvedChildHref = router ? router.resolve(childHref).href : childHref;
8
+ parentUrls[childHref] = null;
9
+ const listener = (result) => {
10
+ parentUrls[childHref] = result;
11
+ };
12
+ listeners[resolvedChildHref] = listener;
13
+ dFrameContent.addParentUrlListener(resolvedChildHref, listener);
14
+ }
15
+ return toRef(() => parentUrls[childHref] ?? undefined);
16
16
  };
17
17
  const clear = () => {
18
18
  for (const [resolvedChildHref, listener] of Object.entries(listeners)) {
19
19
  dFrameContent.removeParentUrlListener(resolvedChildHref, listener);
20
20
  }
21
- computedParentUrls = {};
21
+ parentUrls = {};
22
22
  listeners = {};
23
23
  };
24
24
  onScopeDispose(clear);
25
- return { get, clear };
25
+ return { get, clear, parentUrls };
26
26
  };
27
27
  export default useDFrameParentUrls;
@@ -1,5 +1,12 @@
1
+ import { type App } from 'vue';
1
2
  import DFrameContent, { type DFrameContentOptions } from '../DFrameContent.js';
2
3
  import type { Router } from 'vue-router';
3
4
  type VueRouterDFrameContentOptions = Omit<DFrameContentOptions, 'updateSrc'>;
4
5
  export declare function vueRouterDFrameContent(router: Router, options?: VueRouterDFrameContentOptions): DFrameContent;
6
+ export declare const vueRouterDFrameContentKey: unique symbol;
7
+ export declare function createVueRouterDFrameContent(router: Router, options?: VueRouterDFrameContentOptions): {
8
+ dFrameContent: DFrameContent;
9
+ install(app: App): void;
10
+ };
11
+ export declare function useVueRouterDFrameContent(): DFrameContent;
5
12
  export default vueRouterDFrameContent;
@@ -1,3 +1,4 @@
1
+ import { inject } from 'vue';
1
2
  import DFrameContent from '../DFrameContent.js';
2
3
  let dFrameContent = null;
3
4
  export function vueRouterDFrameContent(router, options) {
@@ -31,4 +32,18 @@ export function vueRouterDFrameContent(router, options) {
31
32
  });
32
33
  return dFrameContent;
33
34
  }
35
+ export const vueRouterDFrameContentKey = Symbol('vue-router-d-frame-content');
36
+ export function createVueRouterDFrameContent(router, options) {
37
+ const dFrameContent = vueRouterDFrameContent(router, options);
38
+ return {
39
+ dFrameContent,
40
+ install(app) { app.provide(vueRouterDFrameContentKey, dFrameContent); },
41
+ };
42
+ }
43
+ export function useVueRouterDFrameContent() {
44
+ const dFrameContent = inject(vueRouterDFrameContentKey);
45
+ if (!dFrameContent)
46
+ throw new Error('useVueRouterDFrameContent requires using the plugin createVueRouterDFrameContent');
47
+ return dFrameContent;
48
+ }
34
49
  export default vueRouterDFrameContent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/frame",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "An iframe wrapper for powerful web app integrations.",
5
5
  "main": "dist/frame.min.js",
6
6
  "directories": {