@unhead/vue 1.10.1 → 1.10.3

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/dist/index.cjs CHANGED
@@ -94,6 +94,32 @@ function useServerSeoMeta(input, options) {
94
94
  return useSeoMeta(input, { ...options, mode: "server" });
95
95
  }
96
96
 
97
+ function registerVueScopeHandlers(script, scope) {
98
+ if (!scope) {
99
+ return;
100
+ }
101
+ const _registerCb = (key, cb) => {
102
+ if (!script._cbs[key]) {
103
+ cb(script.instance);
104
+ return () => {
105
+ };
106
+ }
107
+ let i = script._cbs[key].push(cb);
108
+ const destroy = () => {
109
+ if (i) {
110
+ script._cbs[key]?.splice(i - 1, 1);
111
+ i = null;
112
+ }
113
+ };
114
+ vue.onScopeDispose(destroy);
115
+ return destroy;
116
+ };
117
+ vue.onScopeDispose(() => {
118
+ script._triggerAbortController?.abort();
119
+ });
120
+ script.onLoaded = (cb) => _registerCb("loaded", cb);
121
+ script.onError = (cb) => _registerCb("error", cb);
122
+ }
97
123
  function useScript(_input, _options) {
98
124
  const input = typeof _input === "string" ? { src: _input } : _input;
99
125
  const head = injectHead.injectHead();
@@ -103,48 +129,15 @@ function useScript(_input, _options) {
103
129
  options.eventContext = scope;
104
130
  if (scope && typeof options.trigger === "undefined")
105
131
  options.trigger = vue.onMounted;
106
- const key = unhead.resolveScriptKey(input);
107
- if (head._scripts?.[key])
108
- return head._scripts[key];
109
- let script;
110
- const status = vue.ref("awaitingLoad");
111
- const _ = head.hooks.hook("script:updated", ({ script: s }) => {
112
- if (script && s.id === script.id) {
113
- status.value = s.status;
114
- if (s.status === "removed") {
115
- _();
116
- }
117
- }
132
+ head._scriptStatusWatcher = head._scriptStatusWatcher || head.hooks.hook("script:updated", ({ script: s }) => {
133
+ s._statusRef.value = s.status;
118
134
  });
119
- script = unhead.useScript(input, options);
120
- if (scope) {
121
- const _registerCb = (key2, cb) => {
122
- if (!script._cbs[key2]) {
123
- cb(script.instance);
124
- return () => {
125
- };
126
- }
127
- let i = script._cbs[key2].push(cb);
128
- const destroy = () => {
129
- if (i) {
130
- script._cbs[key2]?.splice(i - 1, 1);
131
- i = null;
132
- }
133
- };
134
- vue.onScopeDispose(destroy);
135
- return destroy;
136
- };
137
- vue.onScopeDispose(() => {
138
- script._triggerAbortController?.abort();
139
- });
140
- script.onLoaded = (cb) => _registerCb("loaded", cb);
141
- script.onError = (cb) => _registerCb("error", cb);
142
- }
135
+ const script = unhead.useScript(input, options);
136
+ script._statusRef = script._statusRef || vue.ref(script.status);
137
+ registerVueScopeHandlers(script, scope);
143
138
  return new Proxy(script, {
144
- get(_2, key2, a) {
145
- if (key2 === "status")
146
- return status;
147
- return Reflect.get(_2, key2, a);
139
+ get(_, key, a) {
140
+ return Reflect.get(_, key === "status" ? "_statusRef" : key, a);
148
141
  }
149
142
  });
150
143
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { resolveScriptKey, useScript as useScript$1 } from 'unhead';
1
+ import { useScript as useScript$1 } from 'unhead';
2
2
  export { CapoPlugin, HashHydrationPlugin, createHeadCore } from 'unhead';
3
3
  import { V as Vue3, h as headSymbol, i as injectHead } from './shared/vue.40986ab9.mjs';
4
4
  export { c as createHead, a as createServerHead, r as resolveUnrefHeadInput, s as setHeadInjectionHandler } from './shared/vue.40986ab9.mjs';
@@ -94,6 +94,32 @@ function useServerSeoMeta(input, options) {
94
94
  return useSeoMeta(input, { ...options, mode: "server" });
95
95
  }
96
96
 
97
+ function registerVueScopeHandlers(script, scope) {
98
+ if (!scope) {
99
+ return;
100
+ }
101
+ const _registerCb = (key, cb) => {
102
+ if (!script._cbs[key]) {
103
+ cb(script.instance);
104
+ return () => {
105
+ };
106
+ }
107
+ let i = script._cbs[key].push(cb);
108
+ const destroy = () => {
109
+ if (i) {
110
+ script._cbs[key]?.splice(i - 1, 1);
111
+ i = null;
112
+ }
113
+ };
114
+ onScopeDispose(destroy);
115
+ return destroy;
116
+ };
117
+ onScopeDispose(() => {
118
+ script._triggerAbortController?.abort();
119
+ });
120
+ script.onLoaded = (cb) => _registerCb("loaded", cb);
121
+ script.onError = (cb) => _registerCb("error", cb);
122
+ }
97
123
  function useScript(_input, _options) {
98
124
  const input = typeof _input === "string" ? { src: _input } : _input;
99
125
  const head = injectHead();
@@ -103,48 +129,15 @@ function useScript(_input, _options) {
103
129
  options.eventContext = scope;
104
130
  if (scope && typeof options.trigger === "undefined")
105
131
  options.trigger = onMounted;
106
- const key = resolveScriptKey(input);
107
- if (head._scripts?.[key])
108
- return head._scripts[key];
109
- let script;
110
- const status = ref("awaitingLoad");
111
- const _ = head.hooks.hook("script:updated", ({ script: s }) => {
112
- if (script && s.id === script.id) {
113
- status.value = s.status;
114
- if (s.status === "removed") {
115
- _();
116
- }
117
- }
132
+ head._scriptStatusWatcher = head._scriptStatusWatcher || head.hooks.hook("script:updated", ({ script: s }) => {
133
+ s._statusRef.value = s.status;
118
134
  });
119
- script = useScript$1(input, options);
120
- if (scope) {
121
- const _registerCb = (key2, cb) => {
122
- if (!script._cbs[key2]) {
123
- cb(script.instance);
124
- return () => {
125
- };
126
- }
127
- let i = script._cbs[key2].push(cb);
128
- const destroy = () => {
129
- if (i) {
130
- script._cbs[key2]?.splice(i - 1, 1);
131
- i = null;
132
- }
133
- };
134
- onScopeDispose(destroy);
135
- return destroy;
136
- };
137
- onScopeDispose(() => {
138
- script._triggerAbortController?.abort();
139
- });
140
- script.onLoaded = (cb) => _registerCb("loaded", cb);
141
- script.onError = (cb) => _registerCb("error", cb);
142
- }
135
+ const script = useScript$1(input, options);
136
+ script._statusRef = script._statusRef || ref(script.status);
137
+ registerVueScopeHandlers(script, scope);
143
138
  return new Proxy(script, {
144
- get(_2, key2, a) {
145
- if (key2 === "status")
146
- return status;
147
- return Reflect.get(_2, key2, a);
139
+ get(_, key, a) {
140
+ return Reflect.get(_, key === "status" ? "_statusRef" : key, a);
148
141
  }
149
142
  });
150
143
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/vue",
3
3
  "type": "module",
4
- "version": "1.10.1",
4
+ "version": "1.10.3",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -66,9 +66,9 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "hookable": "^5.5.3",
69
- "@unhead/schema": "1.10.1",
70
- "@unhead/shared": "1.10.1",
71
- "unhead": "1.10.1"
69
+ "@unhead/schema": "1.10.3",
70
+ "@unhead/shared": "1.10.3",
71
+ "unhead": "1.10.3"
72
72
  },
73
73
  "scripts": {
74
74
  "build": "unbuild .",