@slimr/react 2.1.46 → 2.1.47

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/README.md CHANGED
@@ -4,17 +4,7 @@ A collection of useful 1st and third party react components, hooks, and util. In
4
4
 
5
5
  ## Context
6
6
 
7
- `@slimr` is a set of slim React (hence '@slimr') libs:
8
-
9
- - [@slimr/css](https://www.npmjs.com/package/@slimr/css) - Framework agnostic css-in-js features inspired by the popular Emotion lib
10
- - [@slimr/forms](https://www.npmjs.com/package/@slimr/forms) - A minimalistic form hook
11
- - [@slimr/hooks](https://www.npmjs.com/package/@slimr/hooks) - A collection of useful 1st and third party react hooks
12
- - [@slimr/markdown](https://www.npmjs.com/package/@slimr/markdown) - A simple component and slim markdown-to-html parser
13
- - [@slimr/mdi-paths](https://www.npmjs.com/package/@slimr/mdi-paths) - A basic Icon component and Material Design icon svg paths, code-split by path.
14
- - [@slimr/router](https://www.npmjs.com/package/@slimr/router) - A novel React-web router that supports stack routing
15
- - [@slimr/styled](https://www.npmjs.com/package/@slimr/styled) - css-in-js features inspired by the popular styled-components and Chakra-UI libs
16
- - [@slimr/swr](https://www.npmjs.com/package/@slimr/swr) - A React hook for fetching data that supports stale-while-refresh eager rendering
17
- - [@slimr/util](https://www.npmjs.com/package/@slimr/util) - Framework agnostic Javascript polyfills
7
+ `@slimr` is a set of slim React (hence '@slimr') libs. Check them all out on [github](https://github.com/bdombro/slimr)!
18
8
 
19
9
  ## Setup
20
10
 
@@ -40,50 +30,25 @@ export default defineConfig({
40
30
  - [@slimr/router](https://www.npmjs.com/package/@slimr/router) - A novel React-web router that supports stack routing
41
31
  - [@slimr/styled](https://www.npmjs.com/package/@slimr/styled) - css-in-js features inspired by the popular styled-components and Chakra-UI libs
42
32
  - [@slimr/swr](https://www.npmjs.com/package/@slimr/swr) - A React hook for fetching data that supports stale-while-refresh eager rendering
43
- - [@slimr/util](https://www.npmjs.com/package/@slimr/util) - Framework agnostic Javascript polyfills
44
33
  - [react-use](https://www.npmjs.com/package/react-use) - an excellent collection of hooks
45
34
 
46
- ### useDeepCompareMemo and useShallowCompareMemo
35
+ ### mergeRefs
47
36
 
48
- like react-use's useDeepEffects, but for memos
37
+ Merge React refs so that multiple refs can be used on a single element. Is
38
+ used to merge refs from a forwardRef and a local ref from useRef.
49
39
 
50
- ### useForm, FormError
40
+ Credits: react-merge-refs
51
41
 
52
- A hook and custom Error from [@slimr/forms](https://www.npmjs.com/package/@slimr/forms), which returns a Form component and reactive form state.
42
+ ```typescript
43
+ const MyComponent = forwardRef((props, ref1) => {
44
+ const ref2 = useRef(null)
45
+ return (<div ref={mergeRefs([ref1, ref2])} />)
46
+ })
47
+ ```
53
48
 
54
- ```tsx
55
- import {FormError, useForm} from '@slimr/forms'
56
- import {formToValues} from '@slimr/util'
57
-
58
- function MyForm() {
59
- const { Form, submitting, submitted, accepted, errors} = useForm()
60
-
61
- const onSubmit = async (e: React.FormEventHandler<HTMLFormElement> => {
62
- const vals = formToJson(e.target as HTMLFormElement)
63
- const errors: Record<string, string> = {}
64
- if (!vals.name) {
65
- errors.name = 'Name is required'
66
- }
67
- if (!vals.terms) {
68
- errors.checkbox = 'You must agree to the terms'
69
- }
70
- if (Object.keys(errors).length) {
71
- throw new FormError(errors)
72
- }
73
- }
49
+ ### useDeepCompareMemo and useShallowCompareMemo
74
50
 
75
- return (
76
- <Form onSubmit={onSubmit}>
77
- <input disabled={submitting || accepted} name="name" />
78
- <div>{errors.name}<div>
79
- <input disabled={submitting || accepted} name="terms" type="checkbox" />
80
- <div>{errors.terms}<div>
81
- <button type="submit">Submit</button>
82
- <button type="reset">Reset</button>
83
- </Form>
84
- )
85
- }
86
- ```
51
+ like react-use's useDeepEffects, but for memos
87
52
 
88
53
  ### useSet2
89
54
 
package/cjs/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export * from '@slimr/markdown';
3
3
  export * from '@slimr/router';
4
4
  export * from '@slimr/styled';
5
5
  export * from '@slimr/swr';
6
- export * from '@slimr/util';
7
6
  export * from 'react-use';
7
+ export * from './merge-refs.js';
8
8
  export * from './useMemos.js';
9
9
  export * from './useSet2.js';
package/cjs/index.js CHANGED
@@ -19,8 +19,8 @@ __exportStar(require("@slimr/markdown"), exports);
19
19
  __exportStar(require("@slimr/router"), exports);
20
20
  __exportStar(require("@slimr/styled"), exports);
21
21
  __exportStar(require("@slimr/swr"), exports);
22
- __exportStar(require("@slimr/util"), exports);
23
22
  __exportStar(require("react-use"), exports);
23
+ __exportStar(require("./merge-refs.js"), exports);
24
24
  __exportStar(require("./useMemos.js"), exports);
25
25
  __exportStar(require("./useSet2.js"), exports);
26
26
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,kDAA+B;AAC/B,gDAA6B;AAC7B,gDAA6B;AAC7B,6CAA0B;AAC1B,8CAA2B;AAC3B,4CAAyB;AAEzB,gDAA6B;AAC7B,+CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,kDAA+B;AAC/B,gDAA6B;AAC7B,gDAA6B;AAC7B,6CAA0B;AAC1B,4CAAyB;AAEzB,kDAA+B;AAC/B,gDAA6B;AAC7B,+CAA4B"}
package/cjs/index.ts CHANGED
@@ -3,8 +3,8 @@ export * from '@slimr/markdown'
3
3
  export * from '@slimr/router'
4
4
  export * from '@slimr/styled'
5
5
  export * from '@slimr/swr'
6
- export * from '@slimr/util'
7
6
  export * from 'react-use'
8
7
 
8
+ export * from './merge-refs.js'
9
9
  export * from './useMemos.js'
10
10
  export * from './useSet2.js'
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * Merge React refs so that multiple refs can be used on a single element. Is
4
+ * used to merge refs from a forwardRef and a local ref from useRef.
5
+ *
6
+ * Credits: react-merge-refs
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const MyComponent = forwardRef((props, ref1) => {
11
+ * const ref2 = useRef(null)
12
+ * return (<div ref={mergeRefs([ref1, ref2])} />)
13
+ * })
14
+ * ```
15
+ **/
16
+ export declare function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>): React.RefCallback<T>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeRefs = void 0;
4
+ /**
5
+ * Merge React refs so that multiple refs can be used on a single element. Is
6
+ * used to merge refs from a forwardRef and a local ref from useRef.
7
+ *
8
+ * Credits: react-merge-refs
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const MyComponent = forwardRef((props, ref1) => {
13
+ * const ref2 = useRef(null)
14
+ * return (<div ref={mergeRefs([ref1, ref2])} />)
15
+ * })
16
+ * ```
17
+ **/
18
+ function mergeRefs(refs) {
19
+ return value => {
20
+ refs.forEach(ref => {
21
+ if (typeof ref === 'function') {
22
+ ref(value);
23
+ }
24
+ else if (ref != null) {
25
+ ;
26
+ ref.current = value;
27
+ }
28
+ });
29
+ };
30
+ }
31
+ exports.mergeRefs = mergeRefs;
32
+ //# sourceMappingURL=merge-refs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-refs.js","sourceRoot":"","sources":["../src/merge-refs.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;IAaI;AACJ,SAAgB,SAAS,CACvB,IAA2D;IAE3D,OAAO,KAAK,CAAC,EAAE;QACb,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACjB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;gBAC7B,GAAG,CAAC,KAAK,CAAC,CAAA;aACX;iBAAM,IAAI,GAAG,IAAI,IAAI,EAAE;gBACtB,CAAC;gBAAC,GAAwC,CAAC,OAAO,GAAG,KAAK,CAAA;aAC3D;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC;AAZD,8BAYC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Merge React refs so that multiple refs can be used on a single element. Is
3
+ * used to merge refs from a forwardRef and a local ref from useRef.
4
+ *
5
+ * Credits: react-merge-refs
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const MyComponent = forwardRef((props, ref1) => {
10
+ * const ref2 = useRef(null)
11
+ * return (<div ref={mergeRefs([ref1, ref2])} />)
12
+ * })
13
+ * ```
14
+ **/
15
+ export function mergeRefs<T = any>(
16
+ refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>
17
+ ): React.RefCallback<T> {
18
+ return value => {
19
+ refs.forEach(ref => {
20
+ if (typeof ref === 'function') {
21
+ ref(value)
22
+ } else if (ref != null) {
23
+ ;(ref as React.MutableRefObject<T | null>).current = value
24
+ }
25
+ })
26
+ }
27
+ }
package/esm/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export * from '@slimr/markdown';
3
3
  export * from '@slimr/router';
4
4
  export * from '@slimr/styled';
5
5
  export * from '@slimr/swr';
6
- export * from '@slimr/util';
7
6
  export * from 'react-use';
7
+ export * from './merge-refs.js';
8
8
  export * from './useMemos.js';
9
9
  export * from './useSet2.js';
package/esm/index.js CHANGED
@@ -3,8 +3,8 @@ export * from '@slimr/markdown';
3
3
  export * from '@slimr/router';
4
4
  export * from '@slimr/styled';
5
5
  export * from '@slimr/swr';
6
- export * from '@slimr/util';
7
6
  export * from 'react-use';
7
+ export * from './merge-refs.js';
8
8
  export * from './useMemos.js';
9
9
  export * from './useSet2.js';
10
10
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AAEzB,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AAEzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA"}
package/esm/index.ts CHANGED
@@ -3,8 +3,8 @@ export * from '@slimr/markdown'
3
3
  export * from '@slimr/router'
4
4
  export * from '@slimr/styled'
5
5
  export * from '@slimr/swr'
6
- export * from '@slimr/util'
7
6
  export * from 'react-use'
8
7
 
8
+ export * from './merge-refs.js'
9
9
  export * from './useMemos.js'
10
10
  export * from './useSet2.js'
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ /**
3
+ * Merge React refs so that multiple refs can be used on a single element. Is
4
+ * used to merge refs from a forwardRef and a local ref from useRef.
5
+ *
6
+ * Credits: react-merge-refs
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const MyComponent = forwardRef((props, ref1) => {
11
+ * const ref2 = useRef(null)
12
+ * return (<div ref={mergeRefs([ref1, ref2])} />)
13
+ * })
14
+ * ```
15
+ **/
16
+ export declare function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>): React.RefCallback<T>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Merge React refs so that multiple refs can be used on a single element. Is
3
+ * used to merge refs from a forwardRef and a local ref from useRef.
4
+ *
5
+ * Credits: react-merge-refs
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const MyComponent = forwardRef((props, ref1) => {
10
+ * const ref2 = useRef(null)
11
+ * return (<div ref={mergeRefs([ref1, ref2])} />)
12
+ * })
13
+ * ```
14
+ **/
15
+ export function mergeRefs(refs) {
16
+ return value => {
17
+ refs.forEach(ref => {
18
+ if (typeof ref === 'function') {
19
+ ref(value);
20
+ }
21
+ else if (ref != null) {
22
+ ;
23
+ ref.current = value;
24
+ }
25
+ });
26
+ };
27
+ }
28
+ //# sourceMappingURL=merge-refs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-refs.js","sourceRoot":"","sources":["../src/merge-refs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;IAaI;AACJ,MAAM,UAAU,SAAS,CACvB,IAA2D;IAE3D,OAAO,KAAK,CAAC,EAAE;QACb,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACjB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;gBAC7B,GAAG,CAAC,KAAK,CAAC,CAAA;aACX;iBAAM,IAAI,GAAG,IAAI,IAAI,EAAE;gBACtB,CAAC;gBAAC,GAAwC,CAAC,OAAO,GAAG,KAAK,CAAA;aAC3D;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Merge React refs so that multiple refs can be used on a single element. Is
3
+ * used to merge refs from a forwardRef and a local ref from useRef.
4
+ *
5
+ * Credits: react-merge-refs
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const MyComponent = forwardRef((props, ref1) => {
10
+ * const ref2 = useRef(null)
11
+ * return (<div ref={mergeRefs([ref1, ref2])} />)
12
+ * })
13
+ * ```
14
+ **/
15
+ export function mergeRefs<T = any>(
16
+ refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>
17
+ ): React.RefCallback<T> {
18
+ return value => {
19
+ refs.forEach(ref => {
20
+ if (typeof ref === 'function') {
21
+ ref(value)
22
+ } else if (ref != null) {
23
+ ;(ref as React.MutableRefObject<T | null>).current = value
24
+ }
25
+ })
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slimr/react",
3
- "version": "2.1.46",
3
+ "version": "2.1.47",
4
4
  "author": "Brian Dombrowski",
5
5
  "license": "ISC",
6
6
  "private": false,
@@ -32,12 +32,12 @@
32
32
  "start": "nodemon -w src -e '*' -x 'npm run build && cd ../demo && npm start'"
33
33
  },
34
34
  "dependencies": {
35
- "@slimr/forms": "^4.1.42",
36
- "@slimr/markdown": "^2.1.34",
37
- "@slimr/router": "^2.1.50",
38
- "@slimr/styled": "^2.1.41",
39
- "@slimr/swr": "^2.1.33",
40
- "@slimr/util": "^3.2.36",
35
+ "@slimr/forms": "^4.1.46",
36
+ "@slimr/markdown": "^2.1.35",
37
+ "@slimr/router": "^2.1.51",
38
+ "@slimr/styled": "^2.1.42",
39
+ "@slimr/swr": "^2.1.34",
40
+ "@slimr/util": "^3.2.38",
41
41
  "react-use": "17"
42
42
  },
43
43
  "peerDependencies": {
package/src/index.ts CHANGED
@@ -3,8 +3,8 @@ export * from '@slimr/markdown'
3
3
  export * from '@slimr/router'
4
4
  export * from '@slimr/styled'
5
5
  export * from '@slimr/swr'
6
- export * from '@slimr/util'
7
6
  export * from 'react-use'
8
7
 
8
+ export * from './merge-refs.js'
9
9
  export * from './useMemos.js'
10
10
  export * from './useSet2.js'
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Merge React refs so that multiple refs can be used on a single element. Is
3
+ * used to merge refs from a forwardRef and a local ref from useRef.
4
+ *
5
+ * Credits: react-merge-refs
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const MyComponent = forwardRef((props, ref1) => {
10
+ * const ref2 = useRef(null)
11
+ * return (<div ref={mergeRefs([ref1, ref2])} />)
12
+ * })
13
+ * ```
14
+ **/
15
+ export function mergeRefs<T = any>(
16
+ refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>
17
+ ): React.RefCallback<T> {
18
+ return value => {
19
+ refs.forEach(ref => {
20
+ if (typeof ref === 'function') {
21
+ ref(value)
22
+ } else if (ref != null) {
23
+ ;(ref as React.MutableRefObject<T | null>).current = value
24
+ }
25
+ })
26
+ }
27
+ }