@live-change/vue3-components 0.8.64 → 0.8.66

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/index.js CHANGED
@@ -18,8 +18,9 @@ import createReactiveObject from "./utils/createReactiveObject.mjs"
18
18
 
19
19
  export { createReactiveObject }
20
20
 
21
- import { analytics, useAnalytics, installRouterAnalytics, synchronized, synchronizedList } from "./logic"
22
- export { analytics, useAnalytics, installRouterAnalytics, synchronized, synchronizedList }
21
+ export { analytics, useAnalytics, installRouterAnalytics, synchronized, synchronizedList } from "./logic"
22
+
23
+ export { injectComponent, provideComponent } from "./logic/dependencyInjection.js"
23
24
 
24
25
  export {
25
26
  useLocale, Locale
@@ -0,0 +1,42 @@
1
+ import { provide, inject } from 'vue'
2
+
3
+ export function provideComponent(description, component) {
4
+ if(!description) throw new Error("provideComponent: description is required")
5
+ if(!component) throw new Error("provideComponent: component is required")
6
+ if(typeof description === 'string') description = { name: description }
7
+ if(!description.name) throw new Error("provideComponent: description.name is required")
8
+
9
+ for(let key in description) {
10
+ for(let value of (description[key] instanceof Array ? description[key] : [description[key]])) {
11
+ const provideKey = `component:${description.name}:${key}=${value}`
12
+ provide(provideKey, {
13
+ component,
14
+ description
15
+ })
16
+ }
17
+ }
18
+ }
19
+
20
+
21
+ export function injectComponent(request, defaultComponent, factory) {
22
+ if(!request) throw new Error("injectComponent: request is required")
23
+ if(typeof request === 'string') request = { name: request }
24
+
25
+ const filter = request.filter || (() => true)
26
+ delete request.filter
27
+
28
+ for(let key in request) {
29
+ const provideKey = `component:${request.name}:${key}=${request[key]}`
30
+ const component = inject(provideKey, null)
31
+ if(!component) continue
32
+ let isValid = true
33
+ for(let key in component) {
34
+ const value = request[key]
35
+ if(Array.isArray(value)) {
36
+ if(!value.includes(component[key])) isValid = false
37
+ } else if(value !== component[key]) isValid = false
38
+ }
39
+ if(isValid && filter(component)) return component
40
+ }
41
+ return factory ? defaultComponent() : defaultComponent
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/vue3-components",
3
- "version": "0.8.64",
3
+ "version": "0.8.66",
4
4
  "description": "Live Change Framework - vue components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,10 +21,10 @@
21
21
  },
22
22
  "homepage": "https://github.com/live-change/live-change-stack",
23
23
  "dependencies": {
24
- "@live-change/vue3-ssr": "^0.8.64",
24
+ "@live-change/vue3-ssr": "^0.8.66",
25
25
  "debug": "^4.3.4",
26
26
  "mitt": "3.0.1",
27
27
  "vue": "^3.4.29"
28
28
  },
29
- "gitHead": "cf14b283170cd39b80a57865e9b5eb9cf2073f39"
29
+ "gitHead": "33fa71ec087690903b109e2c0a2cf1de886449f7"
30
30
  }