solid-tiny-utils 0.14.0 → 0.15.0
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.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/solidjs/create-easy-context.d.mts +13 -0
- package/dist/solidjs/create-easy-context.mjs +30 -0
- package/dist/solidjs/create-persisted-store.d.mts +1 -1
- package/dist/solidjs/index.d.mts +1 -1
- package/dist/solidjs/utils.d.mts +2 -2
- package/package.json +1 -1
- package/dist/solidjs/create-context-provider.d.mts +0 -6
- package/dist/solidjs/create-context-provider.mjs +0 -20
package/dist/index.d.mts
CHANGED
|
@@ -9,9 +9,9 @@ import { AnyFn, Fn } from "./types/fn.mjs";
|
|
|
9
9
|
import { MaybeAccessor, MaybeArray, MaybeNullableAccessor, MaybePromise } from "./types/maybe.mjs";
|
|
10
10
|
import { SetterParam } from "./types/solidjs.mjs";
|
|
11
11
|
import { createClickOutside } from "./solidjs/create-click-outside.mjs";
|
|
12
|
-
import { createContextProvider } from "./solidjs/create-context-provider.mjs";
|
|
13
12
|
import { createDebounce } from "./solidjs/create-debounce.mjs";
|
|
14
13
|
import { createDebouncedWatch } from "./solidjs/create-debounce-watch.mjs";
|
|
14
|
+
import { EasyContext, createEasyContext } from "./solidjs/create-easy-context.mjs";
|
|
15
15
|
import { DocumentEventName, GeneralEventListener, WindowEventName, makeEventListener } from "./solidjs/make-event-listener.mjs";
|
|
16
16
|
import { createEventListener } from "./solidjs/create-event-listener.mjs";
|
|
17
17
|
import { createIntersectionObserver } from "./solidjs/create-intersection-observer.mjs";
|
|
@@ -31,4 +31,4 @@ import { isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, is
|
|
|
31
31
|
import { clamp, inRange, max, min, toHex } from "./utils/number.mjs";
|
|
32
32
|
import { draw, random, shuffle, uid } from "./utils/random.mjs";
|
|
33
33
|
import { camel, capitalize, dash, pascal, snake, template, title, trim } from "./utils/str.mjs";
|
|
34
|
-
export { AnyFn, CreateVisibilityObserverOption, DocumentEventName, EntryCallback, Fn, GeneralEventListener, MakePresenceOptions, MaybeAccessor, MaybeArray, MaybeCallableChild, MaybeNullableAccessor, MaybePromise, OKLCH, PersistedStorage, PersistedStoreOption, PresencePhase, RGB, SetterParam, StaticStoreSetter, UseVisibilityObserverFn, WindowEventName, access, accessWith, assignAccessors, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside,
|
|
34
|
+
export { AnyFn, CreateVisibilityObserverOption, DocumentEventName, EasyContext, EntryCallback, Fn, GeneralEventListener, MakePresenceOptions, MaybeAccessor, MaybeArray, MaybeCallableChild, MaybeNullableAccessor, MaybePromise, OKLCH, PersistedStorage, PersistedStoreOption, PresencePhase, RGB, SetterParam, StaticStoreSetter, UseVisibilityObserverFn, WindowEventName, access, accessWith, assignAccessors, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside, createDebounce, createDebouncedWatch, createEasyContext, createEventListener, createIntersectionObserver, createList, createLoopExec, createPersistedStore, createPresence, createStaticStore, createThrottle, createVisibilityObserver, createWatch, dash, dataIf, draw, hasAnimation, hexToRgb, inRange, isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, isUndefined, isValidHex, isValidOKLCH, isValidRGB, iterate, list, makeEventListener, max, min, mountStyle, noop, oklchToRgb, pascal, random, range, rgbToHex, rgbToOklch, runAtNextAnimationFrame, runSolidEventHandler, shuffle, sleep, snake, stringStyleToObject, template, title, toHex, trim, uid };
|
package/dist/index.mjs
CHANGED
|
@@ -14,10 +14,10 @@ import { assignAccessors } from "./solidjs/assign-accessors.mjs";
|
|
|
14
14
|
import { makeEventListener } from "./solidjs/make-event-listener.mjs";
|
|
15
15
|
import { access, accessWith, callMaybeCallableChild, runSolidEventHandler } from "./solidjs/utils.mjs";
|
|
16
16
|
import { createClickOutside } from "./solidjs/create-click-outside.mjs";
|
|
17
|
-
import { createContextProvider } from "./solidjs/create-context-provider.mjs";
|
|
18
17
|
import { createDebounce } from "./solidjs/create-debounce.mjs";
|
|
19
18
|
import { createWatch } from "./solidjs/create-watch.mjs";
|
|
20
19
|
import { createDebouncedWatch } from "./solidjs/create-debounce-watch.mjs";
|
|
20
|
+
import { createEasyContext } from "./solidjs/create-easy-context.mjs";
|
|
21
21
|
import { createEventListener } from "./solidjs/create-event-listener.mjs";
|
|
22
22
|
import { createIntersectionObserver } from "./solidjs/create-intersection-observer.mjs";
|
|
23
23
|
import { createList } from "./solidjs/create-list.mjs";
|
|
@@ -28,4 +28,4 @@ import { createPresence } from "./solidjs/create-presence.mjs";
|
|
|
28
28
|
import { createThrottle } from "./solidjs/create-throttle.mjs";
|
|
29
29
|
import { createVisibilityObserver } from "./solidjs/create-visibility-observer.mjs";
|
|
30
30
|
import { combineClass, combineStyle, mountStyle, stringStyleToObject } from "./dom/css.mjs";
|
|
31
|
-
export { access, accessWith, assignAccessors, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside,
|
|
31
|
+
export { access, accessWith, assignAccessors, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside, createDebounce, createDebouncedWatch, createEasyContext, createEventListener, createIntersectionObserver, createList, createLoopExec, createPersistedStore, createPresence, createStaticStore, createThrottle, createVisibilityObserver, createWatch, dash, dataIf, draw, hasAnimation, hexToRgb, inRange, isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, isUndefined, isValidHex, isValidOKLCH, isValidRGB, iterate, list, makeEventListener, max, min, mountStyle, noop, oklchToRgb, pascal, random, range, rgbToHex, rgbToOklch, runAtNextAnimationFrame, runSolidEventHandler, shuffle, sleep, snake, stringStyleToObject, template, title, toHex, trim, uid };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ParentComponent } from "solid-js";
|
|
2
|
+
|
|
3
|
+
//#region src/solidjs/create-easy-context.d.ts
|
|
4
|
+
interface EasyContext<V, P extends object> {
|
|
5
|
+
initial: (params: P) => {
|
|
6
|
+
value: V;
|
|
7
|
+
Provider: ParentComponent;
|
|
8
|
+
};
|
|
9
|
+
useContext: () => V;
|
|
10
|
+
}
|
|
11
|
+
declare function createEasyContext<V, P extends object>(factory: (params: P) => V): EasyContext<V, P>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { EasyContext, createEasyContext };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isUndefined } from "../utils/is.mjs";
|
|
2
|
+
import { createComponent, createContext, useContext } from "solid-js";
|
|
3
|
+
//#region src/solidjs/create-easy-context.ts
|
|
4
|
+
function createEasyContext(factory) {
|
|
5
|
+
const ctx = createContext();
|
|
6
|
+
const initial = (params) => {
|
|
7
|
+
const value = factory(params);
|
|
8
|
+
const Provider = (props) => createComponent(ctx.Provider, {
|
|
9
|
+
value,
|
|
10
|
+
get children() {
|
|
11
|
+
return props.children;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
value,
|
|
16
|
+
Provider
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const useThisContext = () => {
|
|
20
|
+
const value = useContext(ctx);
|
|
21
|
+
if (isUndefined(value)) throw new Error("createEasyContext: missing context provider");
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
initial,
|
|
26
|
+
useContext: useThisContext
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createEasyContext };
|
|
@@ -37,6 +37,6 @@ interface PersistedStoreOption {
|
|
|
37
37
|
* setSettings({ sidebarOpen: false });
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
declare function createPersistedStore<T extends
|
|
40
|
+
declare function createPersistedStore<T extends object>(init: T, opts?: PersistedStoreOption): readonly [T, StaticStoreSetter<T>];
|
|
41
41
|
//#endregion
|
|
42
42
|
export { PersistedStorage, PersistedStoreOption, createPersistedStore };
|
package/dist/solidjs/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assignAccessors } from "./assign-accessors.mjs";
|
|
2
2
|
import { createClickOutside } from "./create-click-outside.mjs";
|
|
3
|
-
import { createContextProvider } from "./create-context-provider.mjs";
|
|
4
3
|
import { createDebounce } from "./create-debounce.mjs";
|
|
5
4
|
import { createDebouncedWatch } from "./create-debounce-watch.mjs";
|
|
5
|
+
import { EasyContext, createEasyContext } from "./create-easy-context.mjs";
|
|
6
6
|
import { DocumentEventName, GeneralEventListener, WindowEventName, makeEventListener } from "./make-event-listener.mjs";
|
|
7
7
|
import { createEventListener } from "./create-event-listener.mjs";
|
|
8
8
|
import { createIntersectionObserver } from "./create-intersection-observer.mjs";
|
package/dist/solidjs/utils.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ declare function access<T>(value: MaybeAccessor<T>): T;
|
|
|
7
7
|
/** If value is a function – call it with a given arguments – otherwise get the value as is */
|
|
8
8
|
declare function accessWith<T>(valueOrFn: T, ...args: T extends AnyFn ? Parameters<T> : never): T extends AnyFn ? ReturnType<T> : T;
|
|
9
9
|
declare function runSolidEventHandler<T, E extends Event, EHandler extends JSX.EventHandler<T, any> = JSX.EventHandler<T, E>>(event: E, handler?: EHandler | JSX.BoundEventHandler<T, E, EHandler>): void;
|
|
10
|
-
type MaybeCallableChild<T extends unknown[] = []> = JSX.Element | ((...args: T) => JSX.Element);
|
|
11
|
-
declare function callMaybeCallableChild<T extends unknown[] = []>(children: MaybeCallableChild<T>, ...args: T): JSX.Element;
|
|
10
|
+
type MaybeCallableChild<T extends readonly unknown[] = []> = JSX.Element | ((...args: T) => JSX.Element);
|
|
11
|
+
declare function callMaybeCallableChild<T extends readonly unknown[] = []>(children: MaybeCallableChild<T>, ...args: T): JSX.Element;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { MaybeCallableChild, access, accessWith, callMaybeCallableChild, runSolidEventHandler };
|
package/package.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ParentProps } from "solid-js";
|
|
2
|
-
|
|
3
|
-
//#region src/solidjs/create-context-provider.d.ts
|
|
4
|
-
declare function createContextProvider<P extends Record<string, unknown>, V>(factory: (props: P) => V): readonly [(props: ParentProps<P>) => import("solid-js").JSX.Element, () => V | undefined];
|
|
5
|
-
//#endregion
|
|
6
|
-
export { createContextProvider };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { createComponent, createContext, splitProps, useContext } from "solid-js";
|
|
2
|
-
//#region src/solidjs/create-context-provider.ts
|
|
3
|
-
function createContextProvider(factory) {
|
|
4
|
-
const Ctx = createContext();
|
|
5
|
-
const Provider = (props) => {
|
|
6
|
-
const [local, rest] = splitProps(props, ["children"]);
|
|
7
|
-
return createComponent(Ctx.Provider, {
|
|
8
|
-
value: factory(rest),
|
|
9
|
-
get children() {
|
|
10
|
-
return local.children;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
function useStateContext() {
|
|
15
|
-
return useContext(Ctx);
|
|
16
|
-
}
|
|
17
|
-
return [Provider, useStateContext];
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { createContextProvider };
|