rask-ui 0.22.0 → 0.23.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.
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EACL,SAAS,EACT,KAAK,EACL,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAsB,QAAQ,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIrE,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,IAC3D,CAAC,MAAM,KAAK,CAAC,GACb,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC;AAE1B,qBAAa,sBAAuB,SAAQ,SAAS;IAC3C,QAAQ,EAAE,8BAA8B,CAAC,GAAG,CAAC,CAAC;IACtD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAS;IAC9B,QAAQ,WAML;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAC1C,OAAO,CAAC,aAAa,CAAc;IAEnC,qBAAqB,IAAI,OAAO;IAMhC,kBAAkB,IAAI,IAAI;IAG1B,yBAAyB,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI;IAe/C,MAAM;CAoBP;AAID,wBAAgB,mBAAmB,2CAElC;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,IAAI,QAM5C;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,QAMxC;AAED,MAAM,MAAM,6BAA6B,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,IAC1D,CAAC,MAAM,MAAM,KAAK,CAAC,GACnB,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC;AAEhC,qBAAa,qBAAqB,CAAC,CAAC,SAAS,K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AAI,CAAA;KAAE,CAAC,CAAM;IAC3D,QAAQ,gBAAa;IACrB,eAAe;IAcf,QAAQ,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAM;IACjC,UAAU,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAM;IAEnC,iBAAiB,IAAI,IAAI;IAGzB,oBAAoB,IAAI,IAAI;IAI5B,yBAAyB,CACvB,SAAS,EAAE,QAAQ,CAAC;QAAE,QAAQ,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,CAAC,CAAC,GAClD,IAAI;IAcP,qBAAqB,IAAI,OAAO;IAMhC,MAAM;CA2CP;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,SAO9D"}
package/dist/component.js CHANGED
@@ -44,7 +44,7 @@ export class RaskStatelessComponent extends Component {
44
44
  result = this.renderFn(this.reactiveProps);
45
45
  }
46
46
  catch (error) {
47
- const notifyError = this.context.getContext?.(CatchErrorContext);
47
+ const notifyError = CatchErrorContext.use();
48
48
  if (typeof notifyError !== "function") {
49
49
  throw error;
50
50
  }
@@ -176,8 +176,7 @@ export class RaskStatefulComponent extends Component {
176
176
  this.isRendering = false;
177
177
  }
178
178
  catch (error) {
179
- const notifyError = this.contexts.get(CatchErrorContext) ||
180
- this.context.getContext?.(CatchErrorContext);
179
+ const notifyError = CatchErrorContext.use();
181
180
  if (typeof notifyError !== "function") {
182
181
  throw error;
183
182
  }
@@ -1,32 +1,49 @@
1
1
  /**
2
- * Creates a context by wrapping a hook function that will be used as a context identifier.
2
+ * Creates a context that provides two methods: `use()` to consume context values and
3
+ * `inject()` to provide context values to child components.
3
4
  *
4
5
  * @warning **Do not destructure context values!** The returned value may be a reactive
5
6
  * object, and destructuring breaks reactivity.
6
7
  *
7
8
  * @example
8
- * // Create a context hook
9
- * const useTheme = createContext(() => {
9
+ * // Create a context
10
+ * const ThemeContext = createContext(() => {
10
11
  * return useState({ color: "blue" });
11
12
  * });
12
13
  *
13
14
  * // Provider component
14
15
  * function App() {
15
- * const theme = useInjectContext(useTheme);
16
+ * const theme = ThemeContext.inject();
16
17
  * // theme is now available to all children
17
18
  * return () => <Child />;
18
19
  * }
19
20
  *
20
21
  * // Consumer component
21
22
  * function Child() {
22
- * const theme = useContext(useTheme);
23
+ * const theme = ThemeContext.use();
23
24
  * return () => <div style={{ color: theme.color }}>Text</div>;
24
25
  * }
25
26
  *
26
27
  * @param hook - A function that will be used as the context identifier
27
- * @returns The same hook function, to be used with useContext() and useInjectContext()
28
+ * @returns An object with `use()` and `inject()` methods
28
29
  */
29
- export declare function createContext<T, P extends any[]>(hook: (...params: P) => T): (...params: P) => T;
30
- export declare function useContext<T, P extends any[]>(hook: (...params: P) => T): T;
31
- export declare function useInjectContext<T, P extends any[]>(hook: (...params: P) => T, ...params: P): T;
30
+ export declare function createContext<T, P extends any[]>(hook: (...params: P) => T): {
31
+ /**
32
+ * Consumes the context value from the nearest parent component that called `inject()`.
33
+ * Must be called during component setup.
34
+ *
35
+ * @returns The context value provided by the nearest parent
36
+ * @throws Error if called outside component setup, if no parent context exists, or if the specific context was not provided
37
+ */
38
+ use(): any;
39
+ /**
40
+ * Injects a context value by calling the hook function and making it available to all child components.
41
+ * Must be called during component setup.
42
+ *
43
+ * @param params - Parameters to pass to the hook function
44
+ * @returns The context value created by the hook
45
+ * @throws Error if called outside component setup
46
+ */
47
+ inject(...params: P): T;
48
+ };
32
49
  //# sourceMappingURL=createContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createContext.d.ts","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,eAAP,CAAC,KAAK,CAAC,CAE1E;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAkB3E;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EACjD,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,EACzB,GAAG,MAAM,EAAE,CAAC,KAab"}
1
+ {"version":3,"file":"createContext.d.ts","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC;IAEvE;;;;;;OAMG;;IAsBH;;;;;;;OAOG;sBACe,CAAC;EActB"}
@@ -1,55 +1,72 @@
1
1
  /**
2
- * Creates a context by wrapping a hook function that will be used as a context identifier.
2
+ * Creates a context that provides two methods: `use()` to consume context values and
3
+ * `inject()` to provide context values to child components.
3
4
  *
4
5
  * @warning **Do not destructure context values!** The returned value may be a reactive
5
6
  * object, and destructuring breaks reactivity.
6
7
  *
7
8
  * @example
8
- * // Create a context hook
9
- * const useTheme = createContext(() => {
9
+ * // Create a context
10
+ * const ThemeContext = createContext(() => {
10
11
  * return useState({ color: "blue" });
11
12
  * });
12
13
  *
13
14
  * // Provider component
14
15
  * function App() {
15
- * const theme = useInjectContext(useTheme);
16
+ * const theme = ThemeContext.inject();
16
17
  * // theme is now available to all children
17
18
  * return () => <Child />;
18
19
  * }
19
20
  *
20
21
  * // Consumer component
21
22
  * function Child() {
22
- * const theme = useContext(useTheme);
23
+ * const theme = ThemeContext.use();
23
24
  * return () => <div style={{ color: theme.color }}>Text</div>;
24
25
  * }
25
26
  *
26
27
  * @param hook - A function that will be used as the context identifier
27
- * @returns The same hook function, to be used with useContext() and useInjectContext()
28
+ * @returns An object with `use()` and `inject()` methods
28
29
  */
29
30
  import { getCurrentComponent } from "./component";
30
31
  export function createContext(hook) {
31
- return hook;
32
- }
33
- export function useContext(hook) {
34
- let currentComponent = getCurrentComponent();
35
- if (!currentComponent) {
36
- throw new Error("Only use useContext in component setup");
37
- }
38
- if (typeof currentComponent.context.getContext !== "function") {
39
- throw new Error("There is no parent context");
40
- }
41
- const contextValue = currentComponent.context.getContext(hook);
42
- if (!contextValue) {
43
- throw new Error("There is a parent context, but not the one you are using");
44
- }
45
- return contextValue;
46
- }
47
- export function useInjectContext(hook, ...params) {
48
- const currentComponent = getCurrentComponent();
49
- if (!currentComponent) {
50
- throw new Error("Only use useInjectContext in component setup");
51
- }
52
- const value = hook(...params);
53
- currentComponent.contexts.set(hook, value);
54
- return value;
32
+ return {
33
+ /**
34
+ * Consumes the context value from the nearest parent component that called `inject()`.
35
+ * Must be called during component setup.
36
+ *
37
+ * @returns The context value provided by the nearest parent
38
+ * @throws Error if called outside component setup, if no parent context exists, or if the specific context was not provided
39
+ */
40
+ use() {
41
+ let currentComponent = getCurrentComponent();
42
+ if (!currentComponent) {
43
+ throw new Error("Only use useContext in component setup");
44
+ }
45
+ if (typeof currentComponent.context.getContext !== "function") {
46
+ throw new Error("There is no parent context");
47
+ }
48
+ const contextValue = currentComponent.context.getContext(hook);
49
+ if (!contextValue) {
50
+ throw new Error("There is a parent context, but not the one you are using");
51
+ }
52
+ return contextValue;
53
+ },
54
+ /**
55
+ * Injects a context value by calling the hook function and making it available to all child components.
56
+ * Must be called during component setup.
57
+ *
58
+ * @param params - Parameters to pass to the hook function
59
+ * @returns The context value created by the hook
60
+ * @throws Error if called outside component setup
61
+ */
62
+ inject(...params) {
63
+ const currentComponent = getCurrentComponent();
64
+ if (!currentComponent) {
65
+ throw new Error("Only use useInjectContext in component setup");
66
+ }
67
+ const value = hook(...params);
68
+ currentComponent.contexts.set(hook, value);
69
+ return value;
70
+ },
71
+ };
55
72
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./types";
2
2
  export { render } from "./render";
3
3
  export { useCleanup, useMountEffect, RaskStatefulComponent, RaskStatelessComponent, } from "./component";
4
- export { createContext, useContext, useInjectContext } from "./createContext";
4
+ export { createContext } from "./createContext";
5
5
  export { useState, assignState } from "./useState";
6
6
  export { useAsync, Async } from "./useAsync";
7
7
  export { useAction, Action } from "./useAction";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC;AAEjB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC;AAEjB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import "./types";
3
3
  export { render } from "./render";
4
4
  export { useCleanup, useMountEffect, RaskStatefulComponent, RaskStatelessComponent, } from "./component";
5
- export { createContext, useContext, useInjectContext } from "./createContext";
5
+ export { createContext } from "./createContext";
6
6
  export { useState, assignState } from "./useState";
7
7
  export { useAsync } from "./useAsync";
8
8
  export { useAction } from "./useAction";
@@ -1,6 +1,9 @@
1
- export declare const CatchErrorContext: (state: {
2
- error: unknown;
3
- }) => (error: unknown) => unknown;
1
+ export declare const CatchErrorContext: {
2
+ use(): any;
3
+ inject(state: {
4
+ error: unknown;
5
+ }): (error: unknown) => unknown;
6
+ };
4
7
  export declare function useCatchError(): {
5
8
  error: unknown;
6
9
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useCatchError.d.ts","sourceRoot":"","sources":["../src/useCatchError.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB;WAAkC,OAAO;cACtD,OAAO,YACtB,CAAC;AAEH,wBAAgB,aAAa;WAMK,OAAO;EAOxC"}
1
+ {"version":3,"file":"useCatchError.d.ts","sourceRoot":"","sources":["../src/useCatchError.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB;;;eAAkC,OAAO;gBACtD,OAAO;CACtB,CAAC;AAEH,wBAAgB,aAAa;WAMK,OAAO;EAOxC"}
@@ -1,5 +1,5 @@
1
1
  import { useState } from "./useState";
2
- import { createContext, useInjectContext } from "./createContext";
2
+ import { createContext } from "./createContext";
3
3
  import { getCurrentComponent } from "./component";
4
4
  export const CatchErrorContext = createContext((state) => {
5
5
  return (error) => (state.error = error);
@@ -12,6 +12,6 @@ export function useCatchError() {
12
12
  const state = useState({
13
13
  error: null,
14
14
  });
15
- useInjectContext(CatchErrorContext, state);
15
+ CatchErrorContext.inject(state);
16
16
  return state;
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rask-ui",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",