solid-tiny-utils 0.13.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 +3 -1
- package/dist/index.mjs +3 -1
- package/dist/solidjs/assign-accessors.d.mts +13 -0
- package/dist/solidjs/assign-accessors.mjs +15 -0
- 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 +2 -0
- package/dist/solidjs/utils.d.mts +2 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,12 +4,14 @@ import { isValidHex, isValidOKLCH, isValidRGB } from "./color/validation.mjs";
|
|
|
4
4
|
import { hasAnimation } from "./dom/animation.mjs";
|
|
5
5
|
import { dataIf } from "./dom/attrs.mjs";
|
|
6
6
|
import { combineClass, combineStyle, mountStyle, stringStyleToObject } from "./dom/css.mjs";
|
|
7
|
+
import { assignAccessors } from "./solidjs/assign-accessors.mjs";
|
|
7
8
|
import { AnyFn, Fn } from "./types/fn.mjs";
|
|
8
9
|
import { MaybeAccessor, MaybeArray, MaybeNullableAccessor, MaybePromise } from "./types/maybe.mjs";
|
|
9
10
|
import { SetterParam } from "./types/solidjs.mjs";
|
|
10
11
|
import { createClickOutside } from "./solidjs/create-click-outside.mjs";
|
|
11
12
|
import { createDebounce } from "./solidjs/create-debounce.mjs";
|
|
12
13
|
import { createDebouncedWatch } from "./solidjs/create-debounce-watch.mjs";
|
|
14
|
+
import { EasyContext, createEasyContext } from "./solidjs/create-easy-context.mjs";
|
|
13
15
|
import { DocumentEventName, GeneralEventListener, WindowEventName, makeEventListener } from "./solidjs/make-event-listener.mjs";
|
|
14
16
|
import { createEventListener } from "./solidjs/create-event-listener.mjs";
|
|
15
17
|
import { createIntersectionObserver } from "./solidjs/create-intersection-observer.mjs";
|
|
@@ -29,4 +31,4 @@ import { isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, is
|
|
|
29
31
|
import { clamp, inRange, max, min, toHex } from "./utils/number.mjs";
|
|
30
32
|
import { draw, random, shuffle, uid } from "./utils/random.mjs";
|
|
31
33
|
import { camel, capitalize, dash, pascal, snake, template, title, trim } from "./utils/str.mjs";
|
|
32
|
-
export { AnyFn, CreateVisibilityObserverOption, DocumentEventName, EntryCallback, Fn, GeneralEventListener, MakePresenceOptions, MaybeAccessor, MaybeArray, MaybeCallableChild, MaybeNullableAccessor, MaybePromise, OKLCH, PersistedStorage, PersistedStoreOption, PresencePhase, RGB, SetterParam, StaticStoreSetter, UseVisibilityObserverFn, WindowEventName, access, accessWith, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside, createDebounce, createDebouncedWatch, 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 };
|
|
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
|
@@ -10,12 +10,14 @@ import { oklchToRgb, rgbToOklch } from "./color/oklch-rgb.mjs";
|
|
|
10
10
|
import { isValidHex, isValidOKLCH, isValidRGB } from "./color/validation.mjs";
|
|
11
11
|
import { hasAnimation } from "./dom/animation.mjs";
|
|
12
12
|
import { dataIf } from "./dom/attrs.mjs";
|
|
13
|
+
import { assignAccessors } from "./solidjs/assign-accessors.mjs";
|
|
13
14
|
import { makeEventListener } from "./solidjs/make-event-listener.mjs";
|
|
14
15
|
import { access, accessWith, callMaybeCallableChild, runSolidEventHandler } from "./solidjs/utils.mjs";
|
|
15
16
|
import { createClickOutside } from "./solidjs/create-click-outside.mjs";
|
|
16
17
|
import { createDebounce } from "./solidjs/create-debounce.mjs";
|
|
17
18
|
import { createWatch } from "./solidjs/create-watch.mjs";
|
|
18
19
|
import { createDebouncedWatch } from "./solidjs/create-debounce-watch.mjs";
|
|
20
|
+
import { createEasyContext } from "./solidjs/create-easy-context.mjs";
|
|
19
21
|
import { createEventListener } from "./solidjs/create-event-listener.mjs";
|
|
20
22
|
import { createIntersectionObserver } from "./solidjs/create-intersection-observer.mjs";
|
|
21
23
|
import { createList } from "./solidjs/create-list.mjs";
|
|
@@ -26,4 +28,4 @@ import { createPresence } from "./solidjs/create-presence.mjs";
|
|
|
26
28
|
import { createThrottle } from "./solidjs/create-throttle.mjs";
|
|
27
29
|
import { createVisibilityObserver } from "./solidjs/create-visibility-observer.mjs";
|
|
28
30
|
import { combineClass, combineStyle, mountStyle, stringStyleToObject } from "./dom/css.mjs";
|
|
29
|
-
export { access, accessWith, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside, createDebounce, createDebouncedWatch, 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 };
|
|
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 { Accessor } from "solid-js";
|
|
2
|
+
|
|
3
|
+
//#region src/solidjs/assign-accessors.d.ts
|
|
4
|
+
type AccessorRecord = Record<PropertyKey, Accessor<unknown>>;
|
|
5
|
+
type AccessorValues<T extends AccessorRecord> = { readonly [K in keyof T]: ReturnType<T[K]> };
|
|
6
|
+
/**
|
|
7
|
+
* Assigns accessor-backed getters to an object.
|
|
8
|
+
*
|
|
9
|
+
* `append` keys must not already exist on `base`.
|
|
10
|
+
*/
|
|
11
|
+
declare function assignAccessors<Base extends object, Append extends AccessorRecord>(base: Base, append: Append & { [K in keyof Base]?: never }): Readonly<Base & AccessorValues<Append>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { assignAccessors };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/solidjs/assign-accessors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Assigns accessor-backed getters to an object.
|
|
4
|
+
*
|
|
5
|
+
* `append` keys must not already exist on `base`.
|
|
6
|
+
*/
|
|
7
|
+
function assignAccessors(base, append) {
|
|
8
|
+
for (const key in append) if (Object.hasOwn(append, key) && !Object.hasOwn(base, key)) Object.defineProperty(base, key, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: append[key]
|
|
11
|
+
});
|
|
12
|
+
return base;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { assignAccessors };
|
|
@@ -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,6 +1,8 @@
|
|
|
1
|
+
import { assignAccessors } from "./assign-accessors.mjs";
|
|
1
2
|
import { createClickOutside } from "./create-click-outside.mjs";
|
|
2
3
|
import { createDebounce } from "./create-debounce.mjs";
|
|
3
4
|
import { createDebouncedWatch } from "./create-debounce-watch.mjs";
|
|
5
|
+
import { EasyContext, createEasyContext } from "./create-easy-context.mjs";
|
|
4
6
|
import { DocumentEventName, GeneralEventListener, WindowEventName, makeEventListener } from "./make-event-listener.mjs";
|
|
5
7
|
import { createEventListener } from "./create-event-listener.mjs";
|
|
6
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 };
|