react-virtuoso 0.0.0-development
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/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +967 -0
- package/dist/index.mjs +3803 -0
- package/dist/react-urx/index.d.ts +111 -0
- package/dist/urx/index.d.ts +7 -0
- package/package.json +107 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@virtuoso.dev/react-urx` exports the [[systemToComponent]] function.
|
|
3
|
+
* It wraps urx systems in to UI **logic provider components**,
|
|
4
|
+
* mapping the system input and output streams to the component input / output points.
|
|
5
|
+
*
|
|
6
|
+
* ### Simple System wrapped as React Component
|
|
7
|
+
*
|
|
8
|
+
* ```tsx
|
|
9
|
+
* const sys = system(() => {
|
|
10
|
+
* const foo = statefulStream(42)
|
|
11
|
+
* return { foo }
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* const { Component: MyComponent, useEmitterValue } = systemToComponent(sys, {
|
|
15
|
+
* required: { fooProp: 'foo' },
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* const Child = () => {
|
|
19
|
+
* const foo = useEmitterValue('foo')
|
|
20
|
+
* return <div>{foo}</div>
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* const App = () => {
|
|
24
|
+
* return <Comp fooProp={42}><Child /><Comp>
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
import React from 'react';
|
|
31
|
+
import * as u from '../urx';
|
|
32
|
+
import type { Emitter, Publisher, AnySystemSpec, SR, Stream } from '../urx';
|
|
33
|
+
/** @internal */
|
|
34
|
+
export type Observable<T> = Emitter<T> | Publisher<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Describes the mapping between the system streams and the component properties.
|
|
37
|
+
* Each property uses the keys as the names of the properties and the values as the corresponding stream names.
|
|
38
|
+
* @typeParam SS the type of the system.
|
|
39
|
+
*/
|
|
40
|
+
export interface SystemPropsMap<SS extends AnySystemSpec, K = keyof SR<SS>, D = {
|
|
41
|
+
[key: string]: K;
|
|
42
|
+
}> {
|
|
43
|
+
/**
|
|
44
|
+
* Specifies the required component properties.
|
|
45
|
+
*/
|
|
46
|
+
required?: D;
|
|
47
|
+
/**
|
|
48
|
+
* Specifies the optional component properties.
|
|
49
|
+
*/
|
|
50
|
+
optional?: D;
|
|
51
|
+
/**
|
|
52
|
+
* Specifies the component methods, if any. Streams are converted to methods with a single argument.
|
|
53
|
+
* When invoked, the method publishes the value of the argument to the specified stream.
|
|
54
|
+
*/
|
|
55
|
+
methods?: D;
|
|
56
|
+
/**
|
|
57
|
+
* Specifies the component "event" properties, if any.
|
|
58
|
+
* Event properties accept callback functions which get executed when the stream emits a new value.
|
|
59
|
+
*/
|
|
60
|
+
events?: D;
|
|
61
|
+
}
|
|
62
|
+
/** @internal */
|
|
63
|
+
export type PropsFromPropMap<E extends AnySystemSpec, M extends SystemPropsMap<E>> = {
|
|
64
|
+
[K in Extract<keyof M['required'], string>]: M['required'][K] extends string ? SR<E>[M['required'][K]] extends Observable<infer R> ? R : never : never;
|
|
65
|
+
} & {
|
|
66
|
+
[K in Extract<keyof M['optional'], string>]?: M['optional'][K] extends string ? SR<E>[M['optional'][K]] extends Observable<infer R> ? R : never : never;
|
|
67
|
+
} & {
|
|
68
|
+
[K in Extract<keyof M['events'], string>]?: M['events'][K] extends string ? SR<E>[M['events'][K]] extends Observable<infer R> ? (value: R) => void : never : never;
|
|
69
|
+
};
|
|
70
|
+
/** @internal */
|
|
71
|
+
export type MethodsFromPropMap<E extends AnySystemSpec, M extends SystemPropsMap<E>> = {
|
|
72
|
+
[K in Extract<keyof M['methods'], string>]: M['methods'][K] extends string ? SR<E>[M['methods'][K]] extends Observable<infer R> ? (value: R) => void : never : never;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Used to correctly specify type refs for system components
|
|
76
|
+
*
|
|
77
|
+
* ```tsx
|
|
78
|
+
* const s = system(() => { return { a: statefulStream(0) } })
|
|
79
|
+
* const { Component } = systemToComponent(s)
|
|
80
|
+
*
|
|
81
|
+
* const App = () => {
|
|
82
|
+
* const ref = useRef<RefHandle<typeof Component>>()
|
|
83
|
+
* return <Component ref={ref} />
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @typeParam T the type of the component
|
|
88
|
+
*/
|
|
89
|
+
export type RefHandle<T> = T extends React.ForwardRefExoticComponent<React.RefAttributes<infer Handle>> ? Handle : never;
|
|
90
|
+
/**
|
|
91
|
+
* Converts a system spec to React component by mapping the system streams to component properties, events and methods. Returns hooks for querying and modifying
|
|
92
|
+
* the system streams from the component's child components.
|
|
93
|
+
* @param systemSpec The return value from a [[system]] call.
|
|
94
|
+
* @param map The streams to props / events / methods mapping Check [[SystemPropsMap]] for more details.
|
|
95
|
+
* @param Root The optional React component to render. By default, the resulting component renders nothing, acting as a logical wrapper for its children.
|
|
96
|
+
* @returns an object containing the following:
|
|
97
|
+
* - `Component`: the React component.
|
|
98
|
+
* - `useEmitterValue`: a hook that lets child components use values emitted from the specified output stream.
|
|
99
|
+
* - `useEmitter`: a hook that calls the provided callback whenever the specified stream emits a value.
|
|
100
|
+
* - `usePublisher`: a hook which lets child components publish values to the specified stream.
|
|
101
|
+
* <hr />
|
|
102
|
+
*/
|
|
103
|
+
export declare function systemToComponent<SS extends AnySystemSpec, M extends SystemPropsMap<SS>, S extends SR<SS>, R>(systemSpec: SS, map: M, Root?: R): {
|
|
104
|
+
Component: React.ForwardRefExoticComponent<React.PropsWithoutRef<{ [K in Extract<keyof M["required"], string>]: M["required"][K] extends string ? ReturnType<SS["constructor"]>[M["required"][K]] extends Observable<infer R_1> ? R_1 : never : never; } & { [K_1 in Extract<keyof M["optional"], string>]?: (M["optional"][K_1] extends string ? ReturnType<SS["constructor"]>[M["optional"][K_1]] extends Observable<infer R_2> ? R_2 : never : never) | undefined; } & { [K_2 in Extract<keyof M["events"], string>]?: (M["events"][K_2] extends string ? ReturnType<SS["constructor"]>[M["events"][K_2]] extends Observable<infer R_3> ? (value: R_3) => void : never : never) | undefined; } & (R extends React.ComponentType<infer RP> ? RP : {
|
|
105
|
+
children?: React.ReactNode;
|
|
106
|
+
})> & React.RefAttributes<MethodsFromPropMap<SS, M>>>;
|
|
107
|
+
usePublisher: <K_3 extends keyof S>(key: K_3) => (value: S[K_3] extends u.Stream<infer R_4> ? R_4 : never) => void;
|
|
108
|
+
useEmitterValue: <K_4 extends keyof S, V = S[K_4] extends u.StatefulStream<infer R_5> ? R_5 : never>(key: K_4) => V;
|
|
109
|
+
useEmitter: <K_5 extends keyof S, V_1 = S[K_5] extends u.Stream<infer R_6> ? R_6 : never>(key: K_5, callback: (value: V_1) => void) => void;
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-virtuoso",
|
|
3
|
+
"author": "Petyo Ivanov",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"version": "0.0.0-development",
|
|
7
|
+
"homepage": "https://virtuoso.dev/",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"source": "src/index.tsx",
|
|
10
|
+
"main": "dist/index.cjs",
|
|
11
|
+
"module": "dist/index.mjs",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react",
|
|
15
|
+
"reactjs",
|
|
16
|
+
"virtual",
|
|
17
|
+
"endless",
|
|
18
|
+
"load more",
|
|
19
|
+
"list",
|
|
20
|
+
"scrolling",
|
|
21
|
+
"infinite",
|
|
22
|
+
"virtualized",
|
|
23
|
+
"grid",
|
|
24
|
+
"feed",
|
|
25
|
+
"chat"
|
|
26
|
+
],
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": ">=16 || >=17 || >= 18",
|
|
32
|
+
"react-dom": ">=16 || >=17 || >= 18"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@commitlint/cli": "^12.1.4",
|
|
36
|
+
"@commitlint/config-conventional": "^12.1.4",
|
|
37
|
+
"@emotion/core": "^10.1.0",
|
|
38
|
+
"@emotion/styled": "^10.0.27",
|
|
39
|
+
"@faker-js/faker": "^7.6.0",
|
|
40
|
+
"@testing-library/react": "^13.4.0",
|
|
41
|
+
"@ladle/react": "^2.4.5",
|
|
42
|
+
"@microsoft/api-extractor": "^7.33.7",
|
|
43
|
+
"@playwright/test": "^1.29.1",
|
|
44
|
+
"@types/jsdom": "^16.2.3",
|
|
45
|
+
"@types/lodash": "^4.14.165",
|
|
46
|
+
"@types/react": "^18.0.5",
|
|
47
|
+
"@types/react-beautiful-dnd": "^13.0.0",
|
|
48
|
+
"@types/react-dom": "^18.0.1",
|
|
49
|
+
"@types/react-router-dom": "^5.1.7",
|
|
50
|
+
"@types/react-table": "^7.7.10",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.47.0",
|
|
52
|
+
"@typescript-eslint/parser": "^5.47.0",
|
|
53
|
+
"@vitejs/plugin-react": "^3.0.0",
|
|
54
|
+
"eslint": "^8.30.0",
|
|
55
|
+
"eslint-config-prettier": "^8.5.0",
|
|
56
|
+
"eslint-plugin-html": "^7.1.0",
|
|
57
|
+
"eslint-plugin-import": "^2.26.0",
|
|
58
|
+
"eslint-plugin-json": "^3.1.0",
|
|
59
|
+
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
60
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
61
|
+
"eslint-plugin-react": "^7.31.11",
|
|
62
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
63
|
+
"husky": "^6.0.0",
|
|
64
|
+
"jsdom": "^20.0.3",
|
|
65
|
+
"lodash": "^4.17.21",
|
|
66
|
+
"playwright": "^1.29.1",
|
|
67
|
+
"prettier": "^2.2.1",
|
|
68
|
+
"react": "^18.0.0",
|
|
69
|
+
"react-beautiful-dnd": "^13.0.0",
|
|
70
|
+
"react-dom": "^18.0.0",
|
|
71
|
+
"react-router-dom": "^5.2.0",
|
|
72
|
+
"react-table": "^7.7.0",
|
|
73
|
+
"semantic-release": "^19.0.5",
|
|
74
|
+
"terser": "^5.16.1",
|
|
75
|
+
"tslib": "^2.0.0",
|
|
76
|
+
"typescript": "^4.9.4",
|
|
77
|
+
"vite": "^4.0.0",
|
|
78
|
+
"vitest": "^0.26.2"
|
|
79
|
+
},
|
|
80
|
+
"packageManager": "pnpm@7.21.0",
|
|
81
|
+
"resolutions": {
|
|
82
|
+
"@types/react": "^16.14.2"
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=10"
|
|
86
|
+
},
|
|
87
|
+
"prettier": {
|
|
88
|
+
"printWidth": 140,
|
|
89
|
+
"semi": false,
|
|
90
|
+
"singleQuote": true,
|
|
91
|
+
"trailingComma": "es5"
|
|
92
|
+
},
|
|
93
|
+
"repository": {
|
|
94
|
+
"type": "git",
|
|
95
|
+
"url": "https://github.com/petyosi/react-virtuoso.git"
|
|
96
|
+
},
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "vite build && ./scripts/build-types.sh",
|
|
99
|
+
"test": "vitest run",
|
|
100
|
+
"test:watch": "vitest watch",
|
|
101
|
+
"e2e": "playwright test",
|
|
102
|
+
"lint": "eslint src test e2e --ext .ts,.tsx",
|
|
103
|
+
"typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
|
|
104
|
+
"dev": "ladle serve --viteConfig ladle.vite.config.ts",
|
|
105
|
+
"semantic-release": "semantic-release"
|
|
106
|
+
}
|
|
107
|
+
}
|