@thinkpixellab-public/px-vue 4.1.8 → 4.1.9
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/composables/useProvide.js +29 -0
- package/package.json +1 -1
- package/utils/utilsSsr.js +5 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { computed, provide } from 'vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Provides a reactive value that can be injected by child components.
|
|
5
|
+
*
|
|
6
|
+
* @param {symbol | string} key - a unique key used for provide/inject.
|
|
7
|
+
* @param {any | import('vue').Ref<any> | (() => any)} valueOrFn
|
|
8
|
+
* - a **static value** (string, number, object, etc.).
|
|
9
|
+
* - a **vue `ref()`** (reactive state that can change).
|
|
10
|
+
* - a **function** (computed dynamically based on external state).
|
|
11
|
+
*
|
|
12
|
+
* @returns {void}
|
|
13
|
+
* - provides `{ value }` if `valueOrFn` is static or computed.
|
|
14
|
+
* - provides `{ value, setValue }` if `valueOrFn` is a `ref()`.
|
|
15
|
+
*/
|
|
16
|
+
export function useProvide(key, valueOrFn) {
|
|
17
|
+
// create a computed value that updates when valueOrFn is a function or ref
|
|
18
|
+
const computedValue = computed(() => {
|
|
19
|
+
if (typeof valueOrFn === 'function') {
|
|
20
|
+
return valueOrFn();
|
|
21
|
+
} else if (valueOrFn.value !== undefined) {
|
|
22
|
+
return valueOrFn.value;
|
|
23
|
+
} else {
|
|
24
|
+
return valueOrFn;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
provide(key, computedValue);
|
|
29
|
+
}
|
package/package.json
CHANGED
package/utils/utilsSsr.js
CHANGED
|
@@ -34,3 +34,8 @@ export function getQueryParam(name, fallback = null) {
|
|
|
34
34
|
|
|
35
35
|
return params[name] || fallback;
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
export function getQueryBool(name) {
|
|
39
|
+
let val = getQueryParam(name, 'false').toLowerCase();
|
|
40
|
+
return !(val === '0' || val === 'false' || val === 'null' || val === 'undefined');
|
|
41
|
+
}
|