@unhead/vue 1.10.1 → 1.10.2
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 +37 -29
- package/dist/index.mjs +37 -29
- package/package.json +4 -4
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,9 +129,13 @@ 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
|
|
107
|
-
|
|
108
|
-
|
|
132
|
+
const id = unhead.resolveScriptKey(input);
|
|
133
|
+
const prevScript = head._scripts?.[id];
|
|
134
|
+
if (prevScript) {
|
|
135
|
+
prevScript.updateTrigger(options.trigger);
|
|
136
|
+
registerVueScopeHandlers(prevScript, scope);
|
|
137
|
+
return prevScript;
|
|
138
|
+
}
|
|
109
139
|
let script;
|
|
110
140
|
const status = vue.ref("awaitingLoad");
|
|
111
141
|
const _ = head.hooks.hook("script:updated", ({ script: s }) => {
|
|
@@ -117,34 +147,12 @@ function useScript(_input, _options) {
|
|
|
117
147
|
}
|
|
118
148
|
});
|
|
119
149
|
script = unhead.useScript(input, options);
|
|
120
|
-
|
|
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
|
-
}
|
|
150
|
+
registerVueScopeHandlers(script, scope);
|
|
143
151
|
return new Proxy(script, {
|
|
144
|
-
get(_2,
|
|
145
|
-
if (
|
|
152
|
+
get(_2, key, a) {
|
|
153
|
+
if (key === "status")
|
|
146
154
|
return status;
|
|
147
|
-
return Reflect.get(_2,
|
|
155
|
+
return Reflect.get(_2, key, a);
|
|
148
156
|
}
|
|
149
157
|
});
|
|
150
158
|
}
|
package/dist/index.mjs
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
|
+
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,9 +129,13 @@ function useScript(_input, _options) {
|
|
|
103
129
|
options.eventContext = scope;
|
|
104
130
|
if (scope && typeof options.trigger === "undefined")
|
|
105
131
|
options.trigger = onMounted;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
132
|
+
const id = resolveScriptKey(input);
|
|
133
|
+
const prevScript = head._scripts?.[id];
|
|
134
|
+
if (prevScript) {
|
|
135
|
+
prevScript.updateTrigger(options.trigger);
|
|
136
|
+
registerVueScopeHandlers(prevScript, scope);
|
|
137
|
+
return prevScript;
|
|
138
|
+
}
|
|
109
139
|
let script;
|
|
110
140
|
const status = ref("awaitingLoad");
|
|
111
141
|
const _ = head.hooks.hook("script:updated", ({ script: s }) => {
|
|
@@ -117,34 +147,12 @@ function useScript(_input, _options) {
|
|
|
117
147
|
}
|
|
118
148
|
});
|
|
119
149
|
script = useScript$1(input, options);
|
|
120
|
-
|
|
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
|
-
}
|
|
150
|
+
registerVueScopeHandlers(script, scope);
|
|
143
151
|
return new Proxy(script, {
|
|
144
|
-
get(_2,
|
|
145
|
-
if (
|
|
152
|
+
get(_2, key, a) {
|
|
153
|
+
if (key === "status")
|
|
146
154
|
return status;
|
|
147
|
-
return Reflect.get(_2,
|
|
155
|
+
return Reflect.get(_2, key, a);
|
|
148
156
|
}
|
|
149
157
|
});
|
|
150
158
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.10.
|
|
4
|
+
"version": "1.10.2",
|
|
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.
|
|
70
|
-
"@unhead/shared": "1.10.
|
|
71
|
-
"unhead": "1.10.
|
|
69
|
+
"@unhead/schema": "1.10.2",
|
|
70
|
+
"@unhead/shared": "1.10.2",
|
|
71
|
+
"unhead": "1.10.2"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "unbuild .",
|