@sprawlify/solid 0.0.13 → 0.0.14
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-C_ThrXdH.d.ts +14 -0
- package/dist/index.d.ts +52 -7
- package/dist/index.js +102 -5
- package/dist/index.jsx +88 -5
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.jsx +3 -0
- package/dist/utils-DSKoW7eB.jsx +29 -0
- package/dist/utils-GEMuT7an.js +29 -0
- package/package.json +2 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context } from "solid-js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/create-context.d.ts
|
|
4
|
+
interface CreateContextOptions<T> {
|
|
5
|
+
strict?: boolean;
|
|
6
|
+
hookName?: string;
|
|
7
|
+
providerName?: string;
|
|
8
|
+
errorMessage?: string;
|
|
9
|
+
defaultValue?: T;
|
|
10
|
+
}
|
|
11
|
+
type CreateContextReturn<T> = [Context<T>['Provider'], () => T, Context<T>];
|
|
12
|
+
declare function createContext$1<T>(options?: CreateContextOptions<T>): CreateContextReturn<T>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { createContext$1 as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { t as createContext } from "./index-C_ThrXdH.js";
|
|
1
2
|
import { Key } from "@solid-primitives/keyed";
|
|
2
3
|
import { Machine, MachineSchema, Service } from "@sprawlify/primitives/core";
|
|
3
|
-
import
|
|
4
|
+
import * as solid_js0 from "solid-js";
|
|
5
|
+
import { Accessor, JSX, ParentProps } from "solid-js";
|
|
4
6
|
import * as _sprawlify_primitives_types0 from "@sprawlify/primitives/types";
|
|
7
|
+
import { FilterOptions, FilterReturn, Locale } from "@sprawlify/primitives/i18n-utils";
|
|
5
8
|
|
|
6
9
|
//#region src/core/machine.d.ts
|
|
7
10
|
declare function useMachine<T extends MachineSchema>(machine: Machine<T>, userProps?: Partial<T["props"]> | Accessor<Partial<T["props"]>>): Service<T>;
|
|
8
11
|
//#endregion
|
|
9
12
|
//#region src/core/merge-props.d.ts
|
|
10
|
-
type MaybeAccessor<T> = T | (() => T);
|
|
11
|
-
declare function mergeProps<T>(source: MaybeAccessor<T>): T;
|
|
12
|
-
declare function mergeProps<T, U>(source: MaybeAccessor<T>, source1: MaybeAccessor<U>): T & U;
|
|
13
|
-
declare function mergeProps<T, U, V>(source: MaybeAccessor<T>, source1: MaybeAccessor<U>, source2: MaybeAccessor<V>): T & U & V;
|
|
14
|
-
declare function mergeProps<T, U, V, W>(source: MaybeAccessor<T>, source1: MaybeAccessor<U>, source2: MaybeAccessor<V>, source3: MaybeAccessor<W>): T & U & V & W;
|
|
13
|
+
type MaybeAccessor$1<T> = T | (() => T);
|
|
14
|
+
declare function mergeProps<T>(source: MaybeAccessor$1<T>): T;
|
|
15
|
+
declare function mergeProps<T, U>(source: MaybeAccessor$1<T>, source1: MaybeAccessor$1<U>): T & U;
|
|
16
|
+
declare function mergeProps<T, U, V>(source: MaybeAccessor$1<T>, source1: MaybeAccessor$1<U>, source2: MaybeAccessor$1<V>): T & U & V;
|
|
17
|
+
declare function mergeProps<T, U, V, W>(source: MaybeAccessor$1<T>, source1: MaybeAccessor$1<U>, source2: MaybeAccessor$1<V>, source3: MaybeAccessor$1<W>): T & U & V & W;
|
|
15
18
|
//#endregion
|
|
16
19
|
//#region src/core/normalize-props.d.ts
|
|
17
20
|
type PropTypes = JSX.IntrinsicElements & {
|
|
@@ -20,4 +23,46 @@ type PropTypes = JSX.IntrinsicElements & {
|
|
|
20
23
|
};
|
|
21
24
|
declare const normalizeProps: _sprawlify_primitives_types0.NormalizeProps<PropTypes>;
|
|
22
25
|
//#endregion
|
|
23
|
-
|
|
26
|
+
//#region src/providers/environment/use-environment-context.d.ts
|
|
27
|
+
type RootNode = ShadowRoot | Document | Node;
|
|
28
|
+
interface UseEnvironmentContext {
|
|
29
|
+
getRootNode(): RootNode;
|
|
30
|
+
getDocument(): Document;
|
|
31
|
+
getWindow(): Window & typeof globalThis;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/providers/environment/environment-provider.d.ts
|
|
35
|
+
interface EnvironmentProviderProps {
|
|
36
|
+
children?: JSX.Element;
|
|
37
|
+
value?: RootNode | (() => RootNode);
|
|
38
|
+
}
|
|
39
|
+
declare const EnvironmentProvider: (props: EnvironmentProviderProps) => JSX.Element;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/providers/locale/locale-provider.d.ts
|
|
42
|
+
interface LocaleProviderProps extends ParentProps {
|
|
43
|
+
locale: string;
|
|
44
|
+
}
|
|
45
|
+
declare const LocaleProvider: (props: LocaleProviderProps) => solid_js0.JSX.Element;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/providers/locale/use-collator.d.ts
|
|
48
|
+
interface UseCollatorProps extends Intl.CollatorOptions {
|
|
49
|
+
locale?: string;
|
|
50
|
+
}
|
|
51
|
+
interface UseCollatorReturn extends Accessor<Intl.Collator> {}
|
|
52
|
+
declare function useCollator(props?: UseCollatorProps): UseCollatorReturn;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/providers/locale/use-filter.d.ts
|
|
55
|
+
interface UseFilterProps extends FilterOptions {}
|
|
56
|
+
declare function useFilter(props: UseFilterProps): UseFilterReturn;
|
|
57
|
+
interface UseFilterReturn extends Accessor<FilterReturn> {}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/providers/locale/use-locale-context.d.ts
|
|
60
|
+
interface UseLocaleContext extends Accessor<Locale> {}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/types.d.ts
|
|
63
|
+
type Assign<T, U> = Omit<T, keyof U> & U;
|
|
64
|
+
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
65
|
+
type MaybeAccessor<T> = Accessor<T> | T;
|
|
66
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { Assign, EnvironmentProvider, type EnvironmentProviderProps, Key, LocaleProvider, type LocaleProviderProps, MaybeAccessor, MaybePromise, Optional, PropTypes, type RootNode, type UseCollatorProps, type UseEnvironmentContext, type UseFilterProps, type UseFilterReturn, type UseLocaleContext, createContext, mergeProps, normalizeProps, useCollator, useEnvironmentContext, useFilter, useLocaleContext, useMachine };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { t as createContext } from "./utils-GEMuT7an.js";
|
|
1
2
|
import { Key } from "@solid-primitives/keyed";
|
|
2
3
|
import { INIT_STATE, MachineStatus, createScope, mergeProps as mergeProps$1 } from "@sprawlify/primitives/core";
|
|
3
4
|
import { compact, ensure, isEqual, isFunction, isNumber, isObject, isString, toArray, warn } from "@sprawlify/primitives/utils";
|
|
4
|
-
import { createEffect, createMemo, createSignal, mergeProps as mergeProps$2, onCleanup, onMount, untrack } from "solid-js";
|
|
5
|
+
import { Show, createEffect, createMemo, createSignal, mergeProps as mergeProps$2, onCleanup, onMount, untrack } from "solid-js";
|
|
5
6
|
import { createNormalizer } from "@sprawlify/primitives/types";
|
|
7
|
+
import { createComponent, memo, template, use } from "solid-js/web";
|
|
8
|
+
import { getDocument, getWindow } from "@sprawlify/primitives/dom-query";
|
|
9
|
+
import { createCollator, createFilter, isRTL } from "@sprawlify/primitives/i18n-utils";
|
|
6
10
|
|
|
7
11
|
//#region src/core/bindable.ts
|
|
8
12
|
function createBindable(props) {
|
|
@@ -199,7 +203,7 @@ function useMachine(machine, userProps = {}) {
|
|
|
199
203
|
if (!strs) return;
|
|
200
204
|
const fns = strs.map((s) => {
|
|
201
205
|
const fn = machine.implementations?.actions?.[s];
|
|
202
|
-
if (!fn) warn(`[
|
|
206
|
+
if (!fn) warn(`[sprawlify-js] No implementation found for action "${JSON.stringify(s)}"`);
|
|
203
207
|
return fn;
|
|
204
208
|
});
|
|
205
209
|
for (const fn of fns) fn?.(getParams());
|
|
@@ -213,7 +217,7 @@ function useMachine(machine, userProps = {}) {
|
|
|
213
217
|
if (!strs) return;
|
|
214
218
|
const fns = strs.map((s) => {
|
|
215
219
|
const fn = machine.implementations?.effects?.[s];
|
|
216
|
-
if (!fn) warn(`[
|
|
220
|
+
if (!fn) warn(`[sprawlify-js] No implementation found for effect "${JSON.stringify(s)}"`);
|
|
217
221
|
return fn;
|
|
218
222
|
});
|
|
219
223
|
const cleanups = [];
|
|
@@ -232,7 +236,7 @@ function useMachine(machine, userProps = {}) {
|
|
|
232
236
|
});
|
|
233
237
|
};
|
|
234
238
|
const computed = (key) => {
|
|
235
|
-
ensure(machine.computed, () => `[
|
|
239
|
+
ensure(machine.computed, () => `[sprawlify-js] No computed object found on machine`);
|
|
236
240
|
const fn = machine.computed[key];
|
|
237
241
|
return fn({
|
|
238
242
|
context: ctx,
|
|
@@ -413,4 +417,97 @@ function hyphenateStyleName(name) {
|
|
|
413
417
|
}
|
|
414
418
|
|
|
415
419
|
//#endregion
|
|
416
|
-
|
|
420
|
+
//#region src/utils/run-if-fn.ts
|
|
421
|
+
const isFunction$1 = (value) => typeof value === "function";
|
|
422
|
+
const runIfFn = (valueOrFn, ...args) => isFunction$1(valueOrFn) ? valueOrFn(...args) : valueOrFn;
|
|
423
|
+
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/providers/environment/use-environment-context.ts
|
|
426
|
+
const [EnvironmentContextProvider, useEnvironmentContext] = createContext({
|
|
427
|
+
hookName: "useEnvironmentContext",
|
|
428
|
+
providerName: "<EnvironmentProvider />",
|
|
429
|
+
strict: false,
|
|
430
|
+
defaultValue: () => ({
|
|
431
|
+
getRootNode: () => document,
|
|
432
|
+
getDocument: () => document,
|
|
433
|
+
getWindow: () => window
|
|
434
|
+
})
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/providers/environment/environment-provider.tsx
|
|
439
|
+
var _tmpl$ = /* @__PURE__ */ template(`<span hidden>`);
|
|
440
|
+
const EnvironmentProvider = (props) => {
|
|
441
|
+
const [spanRef, setSpanRef] = createSignal();
|
|
442
|
+
const getRootNode = () => runIfFn(props.value) ?? spanRef()?.getRootNode() ?? document;
|
|
443
|
+
return createComponent(EnvironmentContextProvider, {
|
|
444
|
+
value: createMemo(() => ({
|
|
445
|
+
getRootNode,
|
|
446
|
+
getDocument: () => getDocument(getRootNode()),
|
|
447
|
+
getWindow: () => getWindow(getRootNode())
|
|
448
|
+
})),
|
|
449
|
+
get children() {
|
|
450
|
+
return [memo(() => props.children), createComponent(Show, {
|
|
451
|
+
get when() {
|
|
452
|
+
return !props.value;
|
|
453
|
+
},
|
|
454
|
+
get children() {
|
|
455
|
+
var _el$ = _tmpl$();
|
|
456
|
+
use(setSpanRef, _el$);
|
|
457
|
+
return _el$;
|
|
458
|
+
}
|
|
459
|
+
})];
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/providers/locale/use-locale-context.ts
|
|
466
|
+
const [LocaleContextProvider, useLocaleContext] = createContext({
|
|
467
|
+
hookName: "useEnvironmentContext",
|
|
468
|
+
providerName: "<EnvironmentProvider />",
|
|
469
|
+
strict: false,
|
|
470
|
+
defaultValue: () => ({
|
|
471
|
+
dir: "ltr",
|
|
472
|
+
locale: "en-US"
|
|
473
|
+
})
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/providers/locale/locale-provider.tsx
|
|
478
|
+
const LocaleProvider = (props) => {
|
|
479
|
+
return createComponent(LocaleContextProvider, {
|
|
480
|
+
value: createMemo(() => ({
|
|
481
|
+
locale: props.locale,
|
|
482
|
+
dir: isRTL(props.locale) ? "rtl" : "ltr"
|
|
483
|
+
})),
|
|
484
|
+
get children() {
|
|
485
|
+
return props.children;
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/providers/locale/use-collator.ts
|
|
492
|
+
function useCollator(props = {}) {
|
|
493
|
+
const env = useLocaleContext();
|
|
494
|
+
const locale = () => props.locale ?? env().locale;
|
|
495
|
+
return createMemo(() => {
|
|
496
|
+
const { locale: _, ...options } = props;
|
|
497
|
+
return createCollator(locale(), options);
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/providers/locale/use-filter.ts
|
|
503
|
+
function useFilter(props) {
|
|
504
|
+
const env = useLocaleContext();
|
|
505
|
+
const locale = createMemo(() => props.locale ?? env().locale);
|
|
506
|
+
return createMemo(() => createFilter({
|
|
507
|
+
...props,
|
|
508
|
+
locale: locale()
|
|
509
|
+
}));
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
//#endregion
|
|
513
|
+
export { EnvironmentProvider, Key, LocaleProvider, createContext, mergeProps, normalizeProps, useCollator, useEnvironmentContext, useFilter, useLocaleContext, useMachine };
|
package/dist/index.jsx
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { t as createContext } from "./utils-DSKoW7eB.jsx";
|
|
1
2
|
import { Key } from "@solid-primitives/keyed";
|
|
2
3
|
import { INIT_STATE, MachineStatus, createScope, mergeProps as mergeProps$1 } from "@sprawlify/primitives/core";
|
|
3
4
|
import { compact, ensure, isEqual, isFunction, isNumber, isObject, isString, toArray, warn } from "@sprawlify/primitives/utils";
|
|
4
|
-
import { createEffect, createMemo, createSignal, mergeProps as mergeProps$2, onCleanup, onMount, untrack } from "solid-js";
|
|
5
|
+
import { Show, createEffect, createMemo, createSignal, mergeProps as mergeProps$2, onCleanup, onMount, untrack } from "solid-js";
|
|
5
6
|
import { createNormalizer } from "@sprawlify/primitives/types";
|
|
7
|
+
import { getDocument, getWindow } from "@sprawlify/primitives/dom-query";
|
|
8
|
+
import { createCollator, createFilter, isRTL } from "@sprawlify/primitives/i18n-utils";
|
|
6
9
|
|
|
7
10
|
//#region src/core/bindable.ts
|
|
8
11
|
function createBindable(props) {
|
|
@@ -199,7 +202,7 @@ function useMachine(machine, userProps = {}) {
|
|
|
199
202
|
if (!strs) return;
|
|
200
203
|
const fns = strs.map((s) => {
|
|
201
204
|
const fn = machine.implementations?.actions?.[s];
|
|
202
|
-
if (!fn) warn(`[
|
|
205
|
+
if (!fn) warn(`[sprawlify-js] No implementation found for action "${JSON.stringify(s)}"`);
|
|
203
206
|
return fn;
|
|
204
207
|
});
|
|
205
208
|
for (const fn of fns) fn?.(getParams());
|
|
@@ -213,7 +216,7 @@ function useMachine(machine, userProps = {}) {
|
|
|
213
216
|
if (!strs) return;
|
|
214
217
|
const fns = strs.map((s) => {
|
|
215
218
|
const fn = machine.implementations?.effects?.[s];
|
|
216
|
-
if (!fn) warn(`[
|
|
219
|
+
if (!fn) warn(`[sprawlify-js] No implementation found for effect "${JSON.stringify(s)}"`);
|
|
217
220
|
return fn;
|
|
218
221
|
});
|
|
219
222
|
const cleanups = [];
|
|
@@ -232,7 +235,7 @@ function useMachine(machine, userProps = {}) {
|
|
|
232
235
|
});
|
|
233
236
|
};
|
|
234
237
|
const computed = (key) => {
|
|
235
|
-
ensure(machine.computed, () => `[
|
|
238
|
+
ensure(machine.computed, () => `[sprawlify-js] No computed object found on machine`);
|
|
236
239
|
const fn = machine.computed[key];
|
|
237
240
|
return fn({
|
|
238
241
|
context: ctx,
|
|
@@ -413,4 +416,84 @@ function hyphenateStyleName(name) {
|
|
|
413
416
|
}
|
|
414
417
|
|
|
415
418
|
//#endregion
|
|
416
|
-
|
|
419
|
+
//#region src/utils/run-if-fn.ts
|
|
420
|
+
const isFunction$1 = (value) => typeof value === "function";
|
|
421
|
+
const runIfFn = (valueOrFn, ...args) => isFunction$1(valueOrFn) ? valueOrFn(...args) : valueOrFn;
|
|
422
|
+
|
|
423
|
+
//#endregion
|
|
424
|
+
//#region src/providers/environment/use-environment-context.ts
|
|
425
|
+
const [EnvironmentContextProvider, useEnvironmentContext] = createContext({
|
|
426
|
+
hookName: "useEnvironmentContext",
|
|
427
|
+
providerName: "<EnvironmentProvider />",
|
|
428
|
+
strict: false,
|
|
429
|
+
defaultValue: () => ({
|
|
430
|
+
getRootNode: () => document,
|
|
431
|
+
getDocument: () => document,
|
|
432
|
+
getWindow: () => window
|
|
433
|
+
})
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/providers/environment/environment-provider.tsx
|
|
438
|
+
const EnvironmentProvider = (props) => {
|
|
439
|
+
const [spanRef, setSpanRef] = createSignal();
|
|
440
|
+
const getRootNode = () => runIfFn(props.value) ?? spanRef()?.getRootNode() ?? document;
|
|
441
|
+
const environment = createMemo(() => ({
|
|
442
|
+
getRootNode,
|
|
443
|
+
getDocument: () => getDocument(getRootNode()),
|
|
444
|
+
getWindow: () => getWindow(getRootNode())
|
|
445
|
+
}));
|
|
446
|
+
return <EnvironmentContextProvider value={environment}>
|
|
447
|
+
{props.children}
|
|
448
|
+
<Show when={!props.value}>
|
|
449
|
+
<span hidden ref={setSpanRef} />
|
|
450
|
+
</Show>
|
|
451
|
+
</EnvironmentContextProvider>;
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region src/providers/locale/use-locale-context.ts
|
|
456
|
+
const [LocaleContextProvider, useLocaleContext] = createContext({
|
|
457
|
+
hookName: "useEnvironmentContext",
|
|
458
|
+
providerName: "<EnvironmentProvider />",
|
|
459
|
+
strict: false,
|
|
460
|
+
defaultValue: () => ({
|
|
461
|
+
dir: "ltr",
|
|
462
|
+
locale: "en-US"
|
|
463
|
+
})
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/providers/locale/locale-provider.tsx
|
|
468
|
+
const LocaleProvider = (props) => {
|
|
469
|
+
const context = createMemo(() => ({
|
|
470
|
+
locale: props.locale,
|
|
471
|
+
dir: isRTL(props.locale) ? "rtl" : "ltr"
|
|
472
|
+
}));
|
|
473
|
+
return <LocaleContextProvider value={context}>{props.children}</LocaleContextProvider>;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/providers/locale/use-collator.ts
|
|
478
|
+
function useCollator(props = {}) {
|
|
479
|
+
const env = useLocaleContext();
|
|
480
|
+
const locale = () => props.locale ?? env().locale;
|
|
481
|
+
return createMemo(() => {
|
|
482
|
+
const { locale: _, ...options } = props;
|
|
483
|
+
return createCollator(locale(), options);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/providers/locale/use-filter.ts
|
|
489
|
+
function useFilter(props) {
|
|
490
|
+
const env = useLocaleContext();
|
|
491
|
+
const locale = createMemo(() => props.locale ?? env().locale);
|
|
492
|
+
return createMemo(() => createFilter({
|
|
493
|
+
...props,
|
|
494
|
+
locale: locale()
|
|
495
|
+
}));
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
//#endregion
|
|
499
|
+
export { EnvironmentProvider, Key, LocaleProvider, createContext, mergeProps, normalizeProps, useCollator, useEnvironmentContext, useFilter, useLocaleContext, useMachine };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { hasProp, isFunction } from "@sprawlify/primitives/utils";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/create-context.ts
|
|
5
|
+
function getErrorMessage(hook, provider) {
|
|
6
|
+
return `${hook} returned \`undefined\`. Seems you forgot to wrap component within ${provider}`;
|
|
7
|
+
}
|
|
8
|
+
function createContext$1(options = {}) {
|
|
9
|
+
const { strict = true, hookName = "useContext", providerName = "Provider", errorMessage, defaultValue } = options;
|
|
10
|
+
const Context$1 = createContext(defaultValue);
|
|
11
|
+
function useContext$1() {
|
|
12
|
+
const context = useContext(Context$1);
|
|
13
|
+
if (!context && strict) {
|
|
14
|
+
const error = new Error(errorMessage ?? getErrorMessage(hookName, providerName));
|
|
15
|
+
error.name = "ContextError";
|
|
16
|
+
if (hasProp(Error, "captureStackTrace") && isFunction(Error.captureStackTrace)) Error.captureStackTrace(error, useContext$1);
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
return [
|
|
22
|
+
Context$1.Provider,
|
|
23
|
+
useContext$1,
|
|
24
|
+
Context$1
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createContext$1 as t };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { hasProp, isFunction } from "@sprawlify/primitives/utils";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/create-context.ts
|
|
5
|
+
function getErrorMessage(hook, provider) {
|
|
6
|
+
return `${hook} returned \`undefined\`. Seems you forgot to wrap component within ${provider}`;
|
|
7
|
+
}
|
|
8
|
+
function createContext$1(options = {}) {
|
|
9
|
+
const { strict = true, hookName = "useContext", providerName = "Provider", errorMessage, defaultValue } = options;
|
|
10
|
+
const Context$1 = createContext(defaultValue);
|
|
11
|
+
function useContext$1() {
|
|
12
|
+
const context = useContext(Context$1);
|
|
13
|
+
if (!context && strict) {
|
|
14
|
+
const error = new Error(errorMessage ?? getErrorMessage(hookName, providerName));
|
|
15
|
+
error.name = "ContextError";
|
|
16
|
+
if (hasProp(Error, "captureStackTrace") && isFunction(Error.captureStackTrace)) Error.captureStackTrace(error, useContext$1);
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
return [
|
|
22
|
+
Context$1.Provider,
|
|
23
|
+
useContext$1,
|
|
24
|
+
Context$1
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createContext$1 as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprawlify/solid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Solid wrapper for primitives.",
|
|
6
6
|
"author": "sprawlify <npm@sprawlify.com>",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@solid-primitives/keyed": "^1.5.2",
|
|
25
|
-
"@sprawlify/primitives": "0.0.
|
|
25
|
+
"@sprawlify/primitives": "0.0.14"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"solid-js": ">=1.1.3"
|