Skip to content

Commit 3817485

Browse files
add useRoot
1 parent 9ad871d commit 3817485

File tree

5 files changed

+63
-157
lines changed

5 files changed

+63
-157
lines changed

src/reactivity/events/index.js

+12-63
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,12 @@
1-
import { useClickEvent } from "./click.js";
2-
import {usePointerEvent} from "./pointer.js";
3-
import {useMouseEvent} from "./mouse.js";
4-
import {useWheelEvent} from "./wheel.js";
5-
import {useKeyEvent} from "./key.js";
6-
import {useDragEvent,useDropEvent} from "./drag.js";
7-
import {useClipboardEvent} from "./clipboard.js";
8-
import {useFocusEvent} from "./focus.js";
9-
import {useInputEvent} from "./Input.js";
10-
import {useHashEvent} from "./hash.js";
11-
import {useCustomEvent} from "./custom-event.js";
12-
import {useSwipeEvent} from "./swipe.js"
13-
const Events={
14-
usePointerEvent,
15-
useMouseEvent,
16-
useWheelEvent,
17-
useKeyEvent,
18-
useDragEvent,
19-
useDropEvent,
20-
useClickEvent,
21-
useClipboardEvent,
22-
useFocusEvent,
23-
useInputEvent,
24-
useHashEvent,
25-
useCustomEvent,
26-
useSwipeEvent,
27-
ExtractAll: function () {
28-
const keys = Object.keys(this);
29-
for (let i = 0; i < keys.length; i++) {
30-
const key = keys[i];
31-
if (key !== 'ExtractAll' && key !== 'RemoveAll') {
32-
globalThis[key] = this[key];
33-
}
34-
}
35-
return this;
36-
},
37-
RemoveAll: function () {
38-
const keys = Object.keys(this);
39-
for (let i = 0; i < keys.length; i++) {
40-
const key = keys[i];
41-
if (key !== 'RemoveAll') {
42-
delete globalThis[key];
43-
}
44-
}
45-
return this;
46-
}
47-
}
48-
export {
49-
usePointerEvent,
50-
useMouseEvent,
51-
useWheelEvent,
52-
useKeyEvent,
53-
useDragEvent,
54-
useDropEvent,
55-
useClickEvent,
56-
useClipboardEvent,
57-
useFocusEvent,
58-
useInputEvent,
59-
useHashEvent,
60-
useCustomEvent,
61-
useSwipeEvent
62-
}
63-
export default Events
1+
export * from "./click.js";
2+
export * from "./pointer.js";
3+
export * from "./mouse.js";
4+
export * from "./wheel.js";
5+
export * from "./key.js";
6+
export * from "./drag.js";
7+
export * from "./clipboard.js";
8+
export * from "./focus.js";
9+
export * from "./Input.js";
10+
export * from "./hash.js";
11+
export * from "./custom-event.js";
12+
export * from "./swipe.js"

src/reactivity/hooks/UI/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from "./useStyle";
22
export * from "./useTheme";
33
// export * from "../Head/useTitle";
44
// export * from "../Head/useFavIcon";
5-
export * from "./useMediaQuery"
5+
export * from "./useMediaQuery"
6+
export * from "./useRoot.js"

src/reactivity/hooks/UI/useRoot.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Str } from "../../../data"
2+
class ZikoUseRoot{
3+
constructor(props){
4+
this.props={};
5+
props && this.set(props)
6+
}
7+
get(prop){
8+
return this.props[prop]
9+
}
10+
// getStaticValue(){
11+
// return document.documentElement.style.getPropertyValue("--primary-col")
12+
// }
13+
set(props){
14+
Object.entries(props).forEach(([key,value])=>this.#setOneProp(key, value));
15+
return this;
16+
}
17+
#setOneProp(prop, value){
18+
const CssProp = `--${Str.camel2hyphencase(prop)}`
19+
document.documentElement.style.setProperty(CssProp,value);
20+
Object.assign(this.props, {[prop]: `var(${CssProp})`})
21+
Object.assign(this, {[prop] : `var(${CssProp})`})
22+
}
23+
}
24+
25+
const useRootValue=CssVar=>{
26+
if(!CssVar.startsWith("--")) CssVar = `--${Str.camel2hyphencase(CssVar)}`
27+
return `var(${CssVar})`
28+
}
29+
// const useRootStaticValue=CssVar=>{
30+
// if(!CssVar.startsWith("--")) CssVar = `--${Str.camel2hyphencase(CssVar)}`
31+
// return globalThis.document.documentElement.style.getPropertyValue(CssVar)
32+
// }
33+
const useRoot=(props)=>new ZikoUseRoot(props)
34+
export{
35+
ZikoUseRoot,
36+
useRoot,
37+
useRootValue,
38+
// useRootStaticValue
39+
}

src/reactivity/hooks/index.js

+8-91
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,8 @@
1-
import {
2-
useTitle,
3-
useFavIcon,
4-
useMeta,
5-
useHead
6-
} from "./Head"
7-
import {
8-
useStyle,
9-
useTheme,
10-
useMediaQuery
11-
} from "./UI";
12-
import {
13-
useEventEmitter,
14-
useChannel,
15-
useThread,
16-
useBluetooth
17-
} from "./Interactions";
18-
import {
19-
useBattery,
20-
useGeolocation
21-
} from "./Sensors";
22-
import {
23-
useThrottle,
24-
useDebounce
25-
} from "./Decorators";
26-
import {
27-
useLocaleStorage,
28-
useSessionStorage
29-
} from "./Storage"
30-
import {
31-
useSuccesifKeys
32-
} from "./Contexte";
33-
const Hooks={
34-
useStyle,
35-
useTheme,
36-
useMediaQuery,
37-
useBattery,
38-
useGeolocation,
39-
useEventEmitter,
40-
useChannel,
41-
useThread,
42-
useBluetooth,
43-
useTitle,
44-
useFavIcon,
45-
useMeta,
46-
useHead,
47-
useThrottle,
48-
useDebounce,
49-
useLocaleStorage,
50-
useSessionStorage,
51-
useSuccesifKeys,
52-
ExtractAll: function () {
53-
const keys = Object.keys(this);
54-
for (let i = 0; i < keys.length; i++) {
55-
const key = keys[i];
56-
if (key !== 'ExtractAll' && key !== 'RemoveAll') {
57-
globalThis[key] = this[key];
58-
}
59-
}
60-
return this;
61-
},
62-
RemoveAll: function () {
63-
const keys = Object.keys(this);
64-
for (let i = 0; i < keys.length; i++) {
65-
const key = keys[i];
66-
if (key !== 'RemoveAll') {
67-
delete globalThis[key];
68-
}
69-
}
70-
return this;
71-
}
72-
}
73-
export default Hooks;
74-
export{
75-
useStyle,
76-
useTheme,
77-
useMediaQuery,
78-
useTitle,
79-
useFavIcon,
80-
useBattery,
81-
useGeolocation,
82-
useEventEmitter,
83-
useChannel,
84-
useThread,
85-
useBluetooth,
86-
useThrottle,
87-
useDebounce,
88-
useLocaleStorage,
89-
useSessionStorage,
90-
useSuccesifKeys
91-
}
1+
export * from "./contexte"
2+
export * from "./decorators"
3+
export * from "./head"
4+
export * from "./interactions"
5+
export * from "./sensors"
6+
export * from "./storage"
7+
export * from "./ui"
8+
// export * from "./window"

src/reactivity/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Events from "./events";
1+
import * as Events from "./events";
22
import * as Observer from "./observer"
3-
import Hooks from "./hooks"
3+
import * as Hooks from "./hooks"
44
const Reactivity={
55
...Events,
66
...Observer,

0 commit comments

Comments
 (0)