rask-ui 0.21.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.
Files changed (112) hide show
  1. package/dist/asyncState.d.ts +16 -0
  2. package/dist/asyncState.d.ts.map +1 -0
  3. package/dist/asyncState.js +24 -0
  4. package/dist/component.d.ts.map +1 -1
  5. package/dist/component.js +6 -4
  6. package/dist/context.d.ts +5 -0
  7. package/dist/context.d.ts.map +1 -0
  8. package/dist/context.js +29 -0
  9. package/dist/createAsync.test.d.ts +2 -0
  10. package/dist/createAsync.test.d.ts.map +1 -0
  11. package/dist/createAsync.test.js +110 -0
  12. package/dist/createContext.d.ts +36 -20
  13. package/dist/createContext.d.ts.map +1 -1
  14. package/dist/createContext.js +58 -37
  15. package/dist/createMutation.test.d.ts +2 -0
  16. package/dist/createMutation.test.d.ts.map +1 -0
  17. package/dist/createMutation.test.js +168 -0
  18. package/dist/createQuery.test.d.ts +2 -0
  19. package/dist/createQuery.test.d.ts.map +1 -0
  20. package/dist/createQuery.test.js +156 -0
  21. package/dist/createRef.d.ts +6 -0
  22. package/dist/createRef.d.ts.map +1 -0
  23. package/dist/createRef.js +8 -0
  24. package/dist/createState.d.ts +0 -2
  25. package/dist/createState.d.ts.map +1 -1
  26. package/dist/createState.js +5 -40
  27. package/dist/createState.test.d.ts.map +1 -0
  28. package/dist/createState.test.js +111 -0
  29. package/dist/createView.d.ts +44 -18
  30. package/dist/createView.d.ts.map +1 -1
  31. package/dist/createView.js +48 -57
  32. package/dist/createView.test.d.ts.map +1 -0
  33. package/dist/{tests/createView.test.js → createView.test.js} +40 -40
  34. package/dist/error.d.ts +14 -3
  35. package/dist/error.d.ts.map +1 -1
  36. package/dist/error.js +15 -14
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -1
  40. package/dist/jsx.d.ts +256 -10
  41. package/dist/observation.test.d.ts.map +1 -0
  42. package/dist/observation.test.js +150 -0
  43. package/dist/suspense.d.ts +25 -0
  44. package/dist/suspense.d.ts.map +1 -0
  45. package/dist/suspense.js +97 -0
  46. package/dist/test-setup.d.ts +16 -0
  47. package/dist/test-setup.d.ts.map +1 -0
  48. package/dist/test-setup.js +40 -0
  49. package/dist/test.d.ts +2 -0
  50. package/dist/test.d.ts.map +1 -0
  51. package/dist/test.js +24 -0
  52. package/dist/useCatchError.d.ts +6 -1
  53. package/dist/useCatchError.d.ts.map +1 -1
  54. package/dist/useCatchError.js +5 -4
  55. package/package.json +2 -2
  56. package/swc-plugin/target/wasm32-wasip1/release/swc_plugin_rask_component.wasm +0 -0
  57. package/dist/createComputed.d.ts +0 -4
  58. package/dist/createComputed.d.ts.map +0 -1
  59. package/dist/createComputed.js +0 -69
  60. package/dist/createEffect.d.ts +0 -2
  61. package/dist/createEffect.d.ts.map +0 -1
  62. package/dist/createEffect.js +0 -29
  63. package/dist/createRouter.d.ts +0 -8
  64. package/dist/createRouter.d.ts.map +0 -1
  65. package/dist/createRouter.js +0 -27
  66. package/dist/createTask.d.ts +0 -31
  67. package/dist/createTask.d.ts.map +0 -1
  68. package/dist/createTask.js +0 -79
  69. package/dist/patchInferno.d.ts +0 -6
  70. package/dist/patchInferno.d.ts.map +0 -1
  71. package/dist/patchInferno.js +0 -53
  72. package/dist/scheduler.d.ts +0 -4
  73. package/dist/scheduler.d.ts.map +0 -1
  74. package/dist/scheduler.js +0 -107
  75. package/dist/tests/batch.test.d.ts +0 -2
  76. package/dist/tests/batch.test.d.ts.map +0 -1
  77. package/dist/tests/batch.test.js +0 -244
  78. package/dist/tests/createComputed.test.d.ts +0 -2
  79. package/dist/tests/createComputed.test.d.ts.map +0 -1
  80. package/dist/tests/createComputed.test.js +0 -257
  81. package/dist/tests/createContext.test.d.ts +0 -2
  82. package/dist/tests/createContext.test.d.ts.map +0 -1
  83. package/dist/tests/createContext.test.js +0 -136
  84. package/dist/tests/createEffect.test.d.ts +0 -2
  85. package/dist/tests/createEffect.test.d.ts.map +0 -1
  86. package/dist/tests/createEffect.test.js +0 -467
  87. package/dist/tests/createState.test.d.ts.map +0 -1
  88. package/dist/tests/createState.test.js +0 -144
  89. package/dist/tests/createTask.test.d.ts +0 -2
  90. package/dist/tests/createTask.test.d.ts.map +0 -1
  91. package/dist/tests/createTask.test.js +0 -322
  92. package/dist/tests/createView.test.d.ts.map +0 -1
  93. package/dist/tests/error.test.d.ts +0 -2
  94. package/dist/tests/error.test.d.ts.map +0 -1
  95. package/dist/tests/error.test.js +0 -168
  96. package/dist/tests/observation.test.d.ts.map +0 -1
  97. package/dist/tests/observation.test.js +0 -341
  98. package/dist/useComputed.d.ts +0 -5
  99. package/dist/useComputed.d.ts.map +0 -1
  100. package/dist/useComputed.js +0 -69
  101. package/dist/useQuery.d.ts +0 -25
  102. package/dist/useQuery.d.ts.map +0 -1
  103. package/dist/useQuery.js +0 -25
  104. package/dist/useSuspendAsync.d.ts +0 -18
  105. package/dist/useSuspendAsync.d.ts.map +0 -1
  106. package/dist/useSuspendAsync.js +0 -37
  107. package/dist/useTask.d.ts +0 -25
  108. package/dist/useTask.d.ts.map +0 -1
  109. package/dist/useTask.js +0 -70
  110. /package/dist/{tests/createState.test.d.ts → createState.test.d.ts} +0 -0
  111. /package/dist/{tests/createView.test.d.ts → createView.test.d.ts} +0 -0
  112. /package/dist/{tests/observation.test.d.ts → observation.test.d.ts} +0 -0
@@ -0,0 +1,150 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { Signal, Observer, getCurrentObserver } from './observation';
3
+ describe('Signal', () => {
4
+ it('should allow subscribing to notifications', () => {
5
+ const signal = new Signal();
6
+ const callback = vi.fn();
7
+ signal.subscribe(callback);
8
+ signal.notify();
9
+ expect(callback).toHaveBeenCalledTimes(1);
10
+ });
11
+ it('should return a disposer function', () => {
12
+ const signal = new Signal();
13
+ const callback = vi.fn();
14
+ const dispose = signal.subscribe(callback);
15
+ dispose();
16
+ signal.notify();
17
+ expect(callback).not.toHaveBeenCalled();
18
+ });
19
+ it('should handle multiple subscribers', () => {
20
+ const signal = new Signal();
21
+ const callback1 = vi.fn();
22
+ const callback2 = vi.fn();
23
+ signal.subscribe(callback1);
24
+ signal.subscribe(callback2);
25
+ signal.notify();
26
+ expect(callback1).toHaveBeenCalledTimes(1);
27
+ expect(callback2).toHaveBeenCalledTimes(1);
28
+ });
29
+ it('should allow unsubscribing individual callbacks', () => {
30
+ const signal = new Signal();
31
+ const callback1 = vi.fn();
32
+ const callback2 = vi.fn();
33
+ const dispose1 = signal.subscribe(callback1);
34
+ signal.subscribe(callback2);
35
+ dispose1();
36
+ signal.notify();
37
+ expect(callback1).not.toHaveBeenCalled();
38
+ expect(callback2).toHaveBeenCalledTimes(1);
39
+ });
40
+ });
41
+ describe('Observer', () => {
42
+ it('should queue notifications in microtasks', async () => {
43
+ let callCount = 0;
44
+ const observer = new Observer(() => {
45
+ callCount++;
46
+ });
47
+ const signal = new Signal();
48
+ const dispose = observer.observe();
49
+ observer.subscribeSignal(signal);
50
+ dispose();
51
+ // Trigger multiple notifications
52
+ signal.notify();
53
+ signal.notify();
54
+ signal.notify();
55
+ // Should not be called synchronously
56
+ expect(callCount).toBe(0);
57
+ // Wait for microtask
58
+ await new Promise((resolve) => queueMicrotask(() => resolve()));
59
+ // Should be called only once due to queuing
60
+ expect(callCount).toBe(1);
61
+ });
62
+ it('should track signals during observation', () => {
63
+ const callback = vi.fn();
64
+ const observer = new Observer(callback);
65
+ const signal = new Signal();
66
+ const dispose = observer.observe();
67
+ observer.subscribeSignal(signal);
68
+ dispose();
69
+ signal.notify();
70
+ return new Promise((resolve) => {
71
+ queueMicrotask(() => {
72
+ expect(callback).toHaveBeenCalledTimes(1);
73
+ resolve(undefined);
74
+ });
75
+ });
76
+ });
77
+ it('should clear signals when observing again', async () => {
78
+ let callCount = 0;
79
+ const observer = new Observer(() => {
80
+ callCount++;
81
+ });
82
+ const signal1 = new Signal();
83
+ const signal2 = new Signal();
84
+ // First observation
85
+ let dispose = observer.observe();
86
+ observer.subscribeSignal(signal1);
87
+ dispose();
88
+ // Second observation - should clear previous signals
89
+ dispose = observer.observe();
90
+ observer.subscribeSignal(signal2);
91
+ dispose();
92
+ // Notify first signal - should not trigger observer
93
+ signal1.notify();
94
+ await new Promise((resolve) => queueMicrotask(() => resolve()));
95
+ expect(callCount).toBe(0);
96
+ // Notify second signal - should trigger observer
97
+ signal2.notify();
98
+ await new Promise((resolve) => queueMicrotask(() => resolve()));
99
+ expect(callCount).toBe(1);
100
+ });
101
+ it('should dispose of all signal subscriptions', async () => {
102
+ const callback = vi.fn();
103
+ const observer = new Observer(callback);
104
+ const signal = new Signal();
105
+ const dispose = observer.observe();
106
+ observer.subscribeSignal(signal);
107
+ dispose();
108
+ observer.dispose();
109
+ signal.notify();
110
+ await new Promise((resolve) => queueMicrotask(() => resolve()));
111
+ expect(callback).not.toHaveBeenCalled();
112
+ });
113
+ it('should set current observer during observation', () => {
114
+ const observer = new Observer(() => { });
115
+ expect(getCurrentObserver()).toBeUndefined();
116
+ const dispose = observer.observe();
117
+ expect(getCurrentObserver()).toBe(observer);
118
+ dispose();
119
+ expect(getCurrentObserver()).toBeUndefined();
120
+ });
121
+ it('should handle nested observations with stack', () => {
122
+ const observer1 = new Observer(() => { });
123
+ const observer2 = new Observer(() => { });
124
+ const dispose1 = observer1.observe();
125
+ expect(getCurrentObserver()).toBe(observer1);
126
+ const dispose2 = observer2.observe();
127
+ expect(getCurrentObserver()).toBe(observer2);
128
+ dispose2();
129
+ expect(getCurrentObserver()).toBe(observer1);
130
+ dispose1();
131
+ expect(getCurrentObserver()).toBeUndefined();
132
+ });
133
+ it('should prevent duplicate notifications while queued', async () => {
134
+ let callCount = 0;
135
+ const observer = new Observer(() => {
136
+ callCount++;
137
+ });
138
+ const signal = new Signal();
139
+ const dispose = observer.observe();
140
+ observer.subscribeSignal(signal);
141
+ dispose();
142
+ // Rapid-fire notifications
143
+ for (let i = 0; i < 100; i++) {
144
+ signal.notify();
145
+ }
146
+ await new Promise((resolve) => queueMicrotask(() => resolve()));
147
+ // Should only be called once
148
+ expect(callCount).toBe(1);
149
+ });
150
+ });
@@ -0,0 +1,25 @@
1
+ import { VNode } from "snabbdom";
2
+ export declare function createSuspense<T extends Record<string, Promise<any>>>(promises: T): {
3
+ [K in keyof T]: Awaited<T[K]>;
4
+ };
5
+ export declare function Suspense(props: {
6
+ fallback: VNode;
7
+ children: VNode | VNode[];
8
+ }): () => VNode | VNode[];
9
+ type SuspensePromiseState<T> = {
10
+ status: "pending";
11
+ value: null;
12
+ error: null;
13
+ } | {
14
+ status: "resolved";
15
+ value: T;
16
+ error: null;
17
+ } | {
18
+ status: "rejected";
19
+ value: null;
20
+ error: string;
21
+ };
22
+ export type SuspensePromise<T> = Promise<T> & SuspensePromiseState<T>;
23
+ export declare function createSuspensePromise<T>(promise: Promise<T>): SuspensePromise<T>;
24
+ export {};
25
+ //# sourceMappingURL=suspense.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../src/suspense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAKjC,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EACnE,QAAQ,EAAE,CAAC,GACV;KACA,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9B,CAuBA;AAQD,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,QAAQ,EAAE,KAAK,CAAC;IAChB,QAAQ,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;CAC3B,yBAmBA;AAED,KAAK,oBAAoB,CAAC,CAAC,IACvB;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,CAAC,CAAC;IACT,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AAEtE,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAClB,eAAe,CAAC,CAAC,CAAC,CAgEpB"}
@@ -0,0 +1,97 @@
1
+ import { getCurrentComponent } from "./component";
2
+ import { createState } from "./createState";
3
+ import { getCurrentObserver, Signal } from "./observation";
4
+ export function createSuspense(promises) {
5
+ let currentComponent = getCurrentComponent();
6
+ if (!currentComponent) {
7
+ throw new Error("createSuspense must be used in the setup of a component");
8
+ }
9
+ const proxy = {};
10
+ for (const key in promises) {
11
+ const promise = promises[key];
12
+ const suspensePromise = isSuspensePromise(promise)
13
+ ? promise
14
+ : createSuspensePromise(promise);
15
+ currentComponent.notifyAsync(suspensePromise);
16
+ Object.defineProperty(proxy, key, {
17
+ get() {
18
+ return suspensePromise.value;
19
+ },
20
+ });
21
+ }
22
+ return proxy;
23
+ }
24
+ function isSuspensePromise(promise) {
25
+ return "status" in promise;
26
+ }
27
+ export function Suspense(props) {
28
+ const currentComponent = getCurrentComponent();
29
+ const state = createState({
30
+ suspendingPromises: [],
31
+ });
32
+ currentComponent.onAsync((promise) => {
33
+ state.suspendingPromises = state.suspendingPromises.concat(promise);
34
+ });
35
+ return () => {
36
+ const isAllResolved = state.suspendingPromises.every((promise) => promise.status === "resolved");
37
+ console.log(isAllResolved);
38
+ return isAllResolved ? props.children : props.fallback;
39
+ };
40
+ }
41
+ export function createSuspensePromise(promise) {
42
+ const signal = new Signal();
43
+ const state = {
44
+ error: null,
45
+ status: "pending",
46
+ value: null,
47
+ };
48
+ Object.defineProperty(promise, "value", {
49
+ get() {
50
+ const observer = getCurrentObserver();
51
+ if (observer) {
52
+ observer.subscribeSignal(signal);
53
+ }
54
+ return state.value;
55
+ },
56
+ set(newValue) {
57
+ state.value = newValue;
58
+ signal.notify();
59
+ },
60
+ });
61
+ Object.defineProperty(promise, "error", {
62
+ get() {
63
+ const observer = getCurrentObserver();
64
+ if (observer) {
65
+ observer.subscribeSignal(signal);
66
+ }
67
+ return state.error;
68
+ },
69
+ });
70
+ Object.defineProperty(promise, "status", {
71
+ get() {
72
+ const observer = getCurrentObserver();
73
+ if (observer) {
74
+ observer.subscribeSignal(signal);
75
+ }
76
+ return state.status;
77
+ },
78
+ });
79
+ promise
80
+ .then((value) => {
81
+ Object.assign(state, {
82
+ value,
83
+ error: null,
84
+ status: "resolved",
85
+ });
86
+ signal.notify();
87
+ })
88
+ .catch((error) => {
89
+ Object.assign(state, {
90
+ value: null,
91
+ error: String(error),
92
+ status: "rejected",
93
+ });
94
+ signal.notify();
95
+ });
96
+ return promise;
97
+ }
@@ -0,0 +1,16 @@
1
+ import type { VNode } from 'snabbdom';
2
+ /**
3
+ * Test helper to render a component and provide easy cleanup
4
+ *
5
+ * @example
6
+ * const { container, unmount } = renderComponent(<MyComponent />);
7
+ * expect(container.textContent).toBe('hello');
8
+ * unmount();
9
+ */
10
+ export declare function renderComponent(vnode: VNode): {
11
+ container: HTMLElement;
12
+ vnode: VNode;
13
+ unmount: () => void;
14
+ rerender: (newVnode: VNode) => VNode;
15
+ };
16
+ //# sourceMappingURL=test-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../src/test-setup.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAUtC;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK;;;;yBAmBnB,KAAK;EAK7B"}
@@ -0,0 +1,40 @@
1
+ // Test setup file for vitest
2
+ import { afterEach } from 'vitest';
3
+ import { render, patch } from './render';
4
+ // Clean up after each test
5
+ afterEach(() => {
6
+ document.body.innerHTML = '';
7
+ // Remove any style tags added by render function
8
+ document.querySelectorAll('style').forEach(style => style.remove());
9
+ });
10
+ /**
11
+ * Test helper to render a component and provide easy cleanup
12
+ *
13
+ * @example
14
+ * const { container, unmount } = renderComponent(<MyComponent />);
15
+ * expect(container.textContent).toBe('hello');
16
+ * unmount();
17
+ */
18
+ export function renderComponent(vnode) {
19
+ const container = document.createElement('div');
20
+ document.body.appendChild(container);
21
+ let currentVnode = render(vnode, container);
22
+ const actualElement = currentVnode.elm;
23
+ return {
24
+ // The actual rendered DOM element (after patch replaces container)
25
+ container: actualElement,
26
+ // The vnode returned by render
27
+ vnode: currentVnode,
28
+ // Cleanup function
29
+ unmount: () => {
30
+ if (actualElement && actualElement.parentNode) {
31
+ actualElement.parentNode.removeChild(actualElement);
32
+ }
33
+ },
34
+ // Re-render with new vnode
35
+ rerender: (newVnode) => {
36
+ currentVnode = patch(currentVnode, newVnode);
37
+ return currentVnode;
38
+ }
39
+ };
40
+ }
package/dist/test.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function test(container: any): void;
2
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAiBA,wBAAgB,IAAI,CAAC,SAAS,EAAE,GAAG,QA4BlC"}
package/dist/test.js ADDED
@@ -0,0 +1,24 @@
1
+ import { init, classModule, propsModule, styleModule, eventListenersModule, h, } from "snabbdom";
2
+ const patch = init([
3
+ // Init patch function with chosen modules
4
+ classModule, // makes it easy to toggle classes
5
+ propsModule, // for setting properties on DOM elements
6
+ styleModule, // handles styling on elements with support for animations
7
+ eventListenersModule, // attaches event listeners
8
+ ]);
9
+ export function test(container) {
10
+ const vnode = h("div#container.two.classes", { on: { click: () => console.log("div clicked") } }, [
11
+ h("span", { style: { fontWeight: "bold" } }, "This is bold"),
12
+ " and this is just normal text",
13
+ h("a", { props: { href: "/foo" } }, "I'll take you places!"),
14
+ ]);
15
+ // Patch into empty DOM element – this modifies the DOM as a side effect
16
+ patch(container, vnode);
17
+ const newVnode = h("div#container.two.classes", { on: { click: () => console.log("updated div clicked") } }, [
18
+ h("span", { style: { fontWeight: "normal", fontStyle: "italic" } }, "This is now italic type"),
19
+ " and this is still just normal text",
20
+ h("a", { props: { href: "/bar" } }, "I'll take you places!"),
21
+ ]);
22
+ // Second `patch` invocation
23
+ patch(vnode, newVnode); // Snabbdom efficiently updates the old view to the new state
24
+ }
@@ -1,4 +1,9 @@
1
- export declare const CatchErrorContext: import("./createContext").Context<(error: unknown) => void>;
1
+ export declare const CatchErrorContext: {
2
+ use(): any;
3
+ inject(state: {
4
+ error: unknown;
5
+ }): (error: unknown) => unknown;
6
+ };
2
7
  export declare function useCatchError(): {
3
8
  error: unknown;
4
9
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useCatchError.d.ts","sourceRoot":"","sources":["../src/useCatchError.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,4CAAyB,OAAO,KAAK,IAAI,CAAG,CAAC;AAE3E,wBAAgB,aAAa;WAQK,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,16 +1,17 @@
1
1
  import { useState } from "./useState";
2
- import { createContext, useInjectContext } from "./createContext";
2
+ import { createContext } from "./createContext";
3
3
  import { getCurrentComponent } from "./component";
4
- export const CatchErrorContext = createContext();
4
+ export const CatchErrorContext = createContext((state) => {
5
+ return (error) => (state.error = error);
6
+ });
5
7
  export function useCatchError() {
6
8
  const currentComponent = getCurrentComponent();
7
9
  if (!currentComponent || currentComponent.isRendering) {
8
10
  throw new Error("Only use the useCatchError hook in setup");
9
11
  }
10
- const inject = useInjectContext(CatchErrorContext);
11
12
  const state = useState({
12
13
  error: null,
13
14
  });
14
- inject((error) => (state.error = error));
15
+ CatchErrorContext.inject(state);
15
16
  return state;
16
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rask-ui",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "README.md"
34
34
  ],
35
35
  "scripts": {
36
- "build": "npm run build:plugin && tsc --project tsconfig.build.json && cp ../../README.md . && cp ../../logo.png .",
36
+ "build": "npm run build:plugin && tsc --project tsconfig.build.json && cpx ../../README.md . && cpx ../../logo.png .",
37
37
  "build:plugin": "cd swc-plugin && cargo build --release --target wasm32-wasip1",
38
38
  "dev": "tsc --watch",
39
39
  "test": "vitest",
@@ -1,4 +0,0 @@
1
- export declare function createComputed<T extends Record<string, () => any>>(computed: T): {
2
- [K in keyof T]: ReturnType<T[K]>;
3
- };
4
- //# sourceMappingURL=createComputed.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createComputed.d.ts","sourceRoot":"","sources":["../src/createComputed.ts"],"names":[],"mappings":"AAIA,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAChE,QAAQ,EAAE,CAAC,GACV;KACA,CAAC,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjC,CA0EA"}
@@ -1,69 +0,0 @@
1
- import { getCurrentComponent, createCleanup } from "./component";
2
- import { INSPECT_MARKER, INSPECTOR_ENABLED } from "./inspect";
3
- import { getCurrentObserver, Observer, Signal } from "./observation";
4
- export function createComputed(computed) {
5
- const currentComponent = getCurrentComponent();
6
- const proxy = {};
7
- let notifyInspectorRef = {};
8
- for (const prop in computed) {
9
- let isDirty = true;
10
- let value;
11
- const signal = new Signal();
12
- const computedObserver = new Observer(() => {
13
- isDirty = true;
14
- signal.notify();
15
- if (INSPECTOR_ENABLED) {
16
- notifyInspectorRef.current?.notify({
17
- type: "computed",
18
- path: notifyInspectorRef.current.path.concat(prop),
19
- isDirty: true,
20
- value,
21
- });
22
- }
23
- });
24
- createCleanup(() => computedObserver.dispose());
25
- Object.defineProperty(proxy, prop, {
26
- enumerable: true,
27
- configurable: true,
28
- get() {
29
- const currentObserver = getCurrentObserver();
30
- if (currentObserver) {
31
- currentObserver.subscribeSignal(signal);
32
- }
33
- if (isDirty) {
34
- const stopObserving = computedObserver.observe();
35
- value = computed[prop]();
36
- stopObserving();
37
- isDirty = false;
38
- if (INSPECTOR_ENABLED) {
39
- notifyInspectorRef.current?.notify({
40
- type: "computed",
41
- path: notifyInspectorRef.current.path.concat(prop),
42
- isDirty: false,
43
- value,
44
- });
45
- }
46
- return value;
47
- }
48
- return value;
49
- },
50
- });
51
- }
52
- if (INSPECTOR_ENABLED) {
53
- Object.defineProperty(proxy, INSPECT_MARKER, {
54
- enumerable: false,
55
- configurable: false,
56
- get() {
57
- return !notifyInspectorRef.current;
58
- },
59
- set: (value) => {
60
- Object.defineProperty(notifyInspectorRef, "current", {
61
- get() {
62
- return value.current;
63
- },
64
- });
65
- },
66
- });
67
- }
68
- return proxy;
69
- }
@@ -1,2 +0,0 @@
1
- export declare function createEffect(cb: () => void | (() => void)): void;
2
- //# sourceMappingURL=createEffect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createEffect.d.ts","sourceRoot":"","sources":["../src/createEffect.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,QA2BzD"}
@@ -1,29 +0,0 @@
1
- import { syncBatch } from "./batch";
2
- import { createCleanup, getCurrentComponent } from "./component";
3
- import { Observer } from "./observation";
4
- export function createEffect(cb) {
5
- const component = getCurrentComponent();
6
- if (!component || component.isRendering) {
7
- throw new Error("Only use createEffect in component setup");
8
- }
9
- let disposer;
10
- const observer = new Observer(() => {
11
- syncBatch(runEffect);
12
- });
13
- const runEffect = () => {
14
- try {
15
- disposer?.();
16
- }
17
- catch (error) {
18
- console.error("Error in effect dispose function:", error);
19
- }
20
- const stopObserving = observer.observe();
21
- disposer = cb();
22
- stopObserving();
23
- };
24
- createCleanup(() => {
25
- observer.dispose();
26
- disposer?.();
27
- });
28
- runEffect();
29
- }
@@ -1,8 +0,0 @@
1
- import { RoutesConfig, TRouter, TRoutes } from "typed-client-router";
2
- export type Router<T extends RoutesConfig> = Omit<TRouter<T>, "current" | "listen" | "pathname"> & {
3
- route?: TRoutes<T>;
4
- };
5
- export declare function createRouter<const T extends RoutesConfig>(config: T, options?: {
6
- base?: string;
7
- }): Router<T>;
8
- //# sourceMappingURL=createRouter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRouter.d.ts","sourceRoot":"","sources":["../src/createRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,OAAO,EACP,OAAO,EACR,MAAM,qBAAqB,CAAC;AAI7B,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,YAAY,IAAI,IAAI,CAC/C,OAAO,CAAC,CAAC,CAAC,EACV,SAAS,GAAG,QAAQ,GAAG,UAAU,CAClC,GAAG;IACF,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACpB,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,YAAY,EACvD,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE;IACR,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GACA,MAAM,CAAC,CAAC,CAAC,CA4BX"}
@@ -1,27 +0,0 @@
1
- import { createRouter as internalCreateRouter, } from "typed-client-router";
2
- import { getCurrentObserver, Signal } from "./observation";
3
- import { createCleanup, getCurrentComponent } from "./component";
4
- export function createRouter(config, options) {
5
- if (!getCurrentComponent()) {
6
- throw new Error("Only use createRouter in component setup");
7
- }
8
- const router = internalCreateRouter(config, options);
9
- const signal = new Signal();
10
- createCleanup(router.listen(() => signal.notify()));
11
- return {
12
- get route() {
13
- const observer = getCurrentObserver();
14
- if (observer) {
15
- observer.subscribeSignal(signal);
16
- }
17
- return router.current;
18
- },
19
- get queries() {
20
- return router.queries;
21
- },
22
- setQuery: router.setQuery,
23
- push: router.push,
24
- replace: router.replace,
25
- url: router.url,
26
- };
27
- }
@@ -1,31 +0,0 @@
1
- export type TaskState<P, T> = {
2
- isRunning: false;
3
- params: null;
4
- result: null;
5
- error: null;
6
- } | {
7
- isRunning: true;
8
- result: T | null;
9
- params: P;
10
- error: null;
11
- } | {
12
- isRunning: false;
13
- params: null;
14
- result: T;
15
- error: null;
16
- } | {
17
- isRunning: false;
18
- params: null;
19
- result: null;
20
- error: string;
21
- };
22
- export type Task<A, B = never> = [B] extends [never] ? TaskState<null, A> & {
23
- run(): Promise<A>;
24
- rerun(): Promise<A>;
25
- } : TaskState<A, B> & {
26
- run(params: A): Promise<B>;
27
- rerun(params: A): Promise<B>;
28
- };
29
- export declare function createTask<T>(task: (params: undefined, signal: AbortSignal) => Promise<T>): Task<T>;
30
- export declare function createTask<P, T>(task: (params: P, signal: AbortSignal) => Promise<T>): Task<P, T>;
31
- //# sourceMappingURL=createTask.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createTask.d.ts","sourceRoot":"","sources":["../src/createTask.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,IACtB;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IACjB,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAChD,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG;IACnB,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAClB,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;CACrB,GACD,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;IAChB,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9B,CAAC;AAEN,wBAAgB,UAAU,CAAC,CAAC,EAC1B,IAAI,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3D,IAAI,CAAC,CAAC,CAAC,CAAC;AACX,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC7B,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GACnD,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}