@superrb/react-addons 3.0.0 → 4.0.0-1
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/components/button.d.ts +1 -1
- package/components/form.d.ts.map +1 -1
- package/components/form.js +6 -4
- package/components/modal.d.ts.map +1 -1
- package/components/modal.js +6 -4
- package/components/slideshow-buttons.d.ts +1 -1
- package/components/slideshow-buttons.d.ts.map +1 -1
- package/hooks/use-draggable-scroll.d.ts +2 -2
- package/hooks/use-draggable-scroll.d.ts.map +1 -1
- package/hooks/use-draggable-scroll.js +6 -3
- package/hooks/use-escape.d.ts +2 -1
- package/hooks/use-escape.d.ts.map +1 -1
- package/hooks/use-event-listener.d.ts +1 -1
- package/hooks/use-event-listener.d.ts.map +1 -1
- package/hooks/use-event-listener.js +6 -6
- package/hooks/use-is-in-viewport.d.ts.map +1 -1
- package/hooks/use-is-in-viewport.js +3 -3
- package/package.json +15 -10
- package/tsconfig.tsbuildinfo +1 -1
- package/.pnp.cjs +0 -11252
- package/.pnp.loader.mjs +0 -2126
- package/.yarn/install-state.gz +0 -0
package/components/button.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type Props = (PropsWithChildren<HTMLAttributes<HTMLButtonElement | HTMLAnchorEle
|
|
|
6
6
|
className?: string;
|
|
7
7
|
href?: string;
|
|
8
8
|
};
|
|
9
|
-
declare const _default: import("react").
|
|
9
|
+
declare const _default: import("react").NamedExoticComponent<Props & import("react").RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
|
|
10
10
|
export default _default;
|
|
11
11
|
export type { Props as ButtonProps };
|
|
12
12
|
//# sourceMappingURL=button.d.ts.map
|
package/components/form.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/components/form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,SAAS,
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/components/form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,SAAS,EAST,oBAAoB,EAErB,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAExD,OAAO,EAAiB,UAAU,EAAiB,MAAM,iBAAiB,CAAA;AAE1E,OAAiB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAY5C,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvD,MAAM,WAAW,SAAS,CACxB,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,EAC3B,aAAa,SAAS,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAEjD,MAAM,EAAE,CAAC,CAAA;IACT,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE;SAAG,CAAC,IAAI,CAAC,IAAI,MAAM,GAAG,GAAG;KAAE,CAAA;IACzC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IACvC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IACvC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,oBAAoB,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,GAAG,KAAK,CAAA;IAClE,kBAAkB,CAAC,EAAE,CACnB,KAAK,CAAC,EAAE,UAAU,EAClB,WAAW,CAAC,EAAE,SAAS,KACpB,SAAS,CAAA;IACd,YAAY,CAAC,EAAE,CACb,KAAK,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,KAChE,SAAS,CAAA;IACd,SAAS,CAAC,EAAE;SAAG,CAAC,IAAI,aAAa,GAAG,aAAa;KAAE,CAAA;IACnD,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,OAAO,CACtB,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,EAC3B,aAAa,SAAS,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAEjD,IAAI,EAAE,eAAe,CAAA;IACrB,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;IACpC,MAAM,EAAE;SACL,CAAC,IAAI,aAAa,IAAI,MAAM,CAAC,CAAC,EAAE,WAAW;KAC7C,CAAA;CACF;;AAsVD,wBAA+B"}
|
package/components/form.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useEffect, Fragment, forwardRef, useRef, useCallback, useImperativeHandle, } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { kebabCase, sentenceCase } from 'change-case';
|
|
5
5
|
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
7
7
|
import useAsync from '../hooks/use-async';
|
|
@@ -13,7 +13,7 @@ import messages from './form/messages.json';
|
|
|
13
13
|
import { GoogleReCaptchaProvider, useGoogleReCaptcha, } from 'react-google-recaptcha-v3';
|
|
14
14
|
const FormInner = forwardRef(function FormInner({ schema, name, action, disabled = false, className = '', initialData = {}, onSubmit, onChange = () => { }, method, onStatusChange = () => { }, renderSuccessMessage = (data) => (_jsx(SuccessMessage, { data: data })), renderErrorMessage = (error, fieldSchema) => (_jsx(ErrorMessage, { error: error, fieldSchema: fieldSchema })), renderSubmit = (props) => _jsx(SubmitButton, { ...props }), renderers = {}, useRecaptcha = true, ...props }, ref) {
|
|
15
15
|
const [response, setResponse] = useState();
|
|
16
|
-
const formRef = useRef();
|
|
16
|
+
const formRef = useRef(null);
|
|
17
17
|
const fieldRefs = useRef(new Map());
|
|
18
18
|
const { executeRecaptcha } = useGoogleReCaptcha();
|
|
19
19
|
for (const name of Object.keys(schema.fields)) {
|
|
@@ -118,11 +118,13 @@ const FormInner = forwardRef(function FormInner({ schema, name, action, disabled
|
|
|
118
118
|
setValue(fieldName, field?.value);
|
|
119
119
|
handleInput(event);
|
|
120
120
|
};
|
|
121
|
-
return (_jsx(Fragment, { children: field?.spec?.meta?.hidden === true ? (_jsx(FormField, { register: register(fieldName), schema: field, onInput: onInput, disabled: disabled, ref: (ref) =>
|
|
121
|
+
return (_jsx(Fragment, { children: field?.spec?.meta?.hidden === true ? (_jsx(FormField, { register: register(fieldName), schema: field, onInput: onInput, disabled: disabled, ref: (ref) => {
|
|
122
|
+
fieldRefs.current.set(fieldName, ref);
|
|
123
|
+
} })) : (_jsx("div", { className: `form__group form__group--${kebabCase(fieldName)} ${fieldName in errors ? 'form__group--error' : ''} ${field?.type === 'boolean' ? 'form__group--checkbox' : ''} ${field?.type === 'date' ? 'form__group--date' : ''}`, children: _jsxs("label", { className: "form__label", htmlFor: `${name}__${kebabCase(fieldName)}`, children: [_jsx("span", { className: "form__label-text", "data-label": `${field?.spec?.meta?.buttonLabel ? field?.spec?.meta?.buttonLabel : field?.spec?.label}`, dangerouslySetInnerHTML: {
|
|
122
124
|
__html: `${field?.spec?.label} ${!field?.spec?.optional
|
|
123
125
|
? '<span class="form__required-indicator">*</span>'
|
|
124
126
|
: ''}`,
|
|
125
|
-
} }), fieldName in renderers ? (renderers[fieldName](register(fieldName), errors[fieldName], field)) : (_jsxs(_Fragment, { children: [_jsx(FormField, { register: register(fieldName), id: `${name}__${
|
|
127
|
+
} }), fieldName in renderers ? (renderers[fieldName](register(fieldName), errors[fieldName], field)) : (_jsxs(_Fragment, { children: [_jsx(FormField, { register: register(fieldName), id: `${name}__${kebabCase(fieldName)}`, schema: field, onInput: onInput, onChange: onInput, disabled: disabled, ref: (ref) => {
|
|
126
128
|
fieldRefs.current.set(fieldName, ref);
|
|
127
129
|
} }), fieldName in errors &&
|
|
128
130
|
renderErrorMessage(errors[fieldName], field), field.spec?.meta?.help && (_jsx("p", { className: "form__help", children: field.spec.meta.help }))] }))] }) })) }, key));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/components/modal.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/components/modal.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EAIlB,MAAM,OAAO,CAAA;AASd,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAC5B,IAAI,EACJ,SAAS,EACT,SAAS,EACT,WAAmB,EACnB,aAAoB,EACpB,QAAQ,GACT,EAAE,iBAAiB,CAAC,KAAK,CAAC,2CAqE1B"}
|
package/components/modal.js
CHANGED
|
@@ -5,9 +5,9 @@ import { local } from '../storage';
|
|
|
5
5
|
import { useEscape, useEventListener, useLockBodyScroll, useModal, } from '../hooks';
|
|
6
6
|
export default function Modal({ name, className, openAfter, dismissable = false, preventScroll = true, children, }) {
|
|
7
7
|
const [dismissed, setDismissed] = useState(false);
|
|
8
|
-
const openTimer = useRef();
|
|
9
|
-
const ref = useRef();
|
|
10
|
-
const innerRef = useRef();
|
|
8
|
+
const openTimer = useRef(null);
|
|
9
|
+
const ref = useRef(null);
|
|
10
|
+
const innerRef = useRef(null);
|
|
11
11
|
const { isOpen, openModal, closeModal } = useModal(name);
|
|
12
12
|
useLockBodyScroll(isOpen && preventScroll);
|
|
13
13
|
useEffect(() => {
|
|
@@ -16,7 +16,9 @@ export default function Modal({ name, className, openAfter, dismissable = false,
|
|
|
16
16
|
}
|
|
17
17
|
}, [dismissable, name]);
|
|
18
18
|
useEffect(() => {
|
|
19
|
-
|
|
19
|
+
if (openTimer.current) {
|
|
20
|
+
clearTimeout(openTimer.current);
|
|
21
|
+
}
|
|
20
22
|
if (!dismissed && openAfter) {
|
|
21
23
|
openTimer.current = setTimeout(() => {
|
|
22
24
|
openModal();
|
|
@@ -4,5 +4,5 @@ import { Slideshow } from '@/hooks/use-slideshow';
|
|
|
4
4
|
export default function SlideshowButtons({ slideshow: { currentSlide, goTo, slideshowRef, atStart, atEnd }, ButtonComponent, }: {
|
|
5
5
|
slideshow: Slideshow;
|
|
6
6
|
ButtonComponent?: FC<ButtonProps>;
|
|
7
|
-
}): JSX.Element;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
//# sourceMappingURL=slideshow-buttons.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slideshow-buttons.d.ts","sourceRoot":"","sources":["../src/components/slideshow-buttons.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,SAAS,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,EAC/D,eAAwB,GACzB,EAAE;IACD,SAAS,EAAE,SAAS,CAAA;IACpB,eAAe,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAA;CAClC,
|
|
1
|
+
{"version":3,"file":"slideshow-buttons.d.ts","sourceRoot":"","sources":["../src/components/slideshow-buttons.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,SAAS,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,EAC/D,eAAwB,GACzB,EAAE;IACD,SAAS,EAAE,SAAS,CAAA;IACpB,eAAe,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAA;CAClC,2CAqBA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MouseEventHandler,
|
|
1
|
+
import { MouseEventHandler, RefObject } from 'react';
|
|
2
2
|
interface Events {
|
|
3
3
|
onMouseDown: MouseEventHandler<HTMLElement>;
|
|
4
4
|
}
|
|
5
|
-
export default function useDraggableScroll(ref:
|
|
5
|
+
export default function useDraggableScroll(ref: RefObject<HTMLElement | null>, { className, ...opts }: {
|
|
6
6
|
className: string;
|
|
7
7
|
}): {
|
|
8
8
|
events: Events;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-draggable-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-draggable-scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"use-draggable-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-draggable-scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,SAAS,EAIV,MAAM,OAAO,CAAA;AAId,UAAU,MAAM;IACd,WAAW,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAA;CAC5C;AAED,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE;;EAkF9C"}
|
|
@@ -8,17 +8,20 @@ export default function useDraggableScroll(ref, { className, ...opts }) {
|
|
|
8
8
|
isMounted: ref.current !== undefined,
|
|
9
9
|
});
|
|
10
10
|
const [modifiedEvents, setModifiedEvents] = useState(events);
|
|
11
|
-
const timer = useRef();
|
|
11
|
+
const timer = useRef(null);
|
|
12
12
|
const [dragging, setDragging] = useState(false);
|
|
13
13
|
const [shouldScroll, setShouldScroll] = useState(false);
|
|
14
14
|
setRef(ref.current);
|
|
15
15
|
useEffect(() => {
|
|
16
|
+
if (!ref.current) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
16
19
|
const shouldScroll = ref.current?.scrollWidth > ref.current?.clientWidth ||
|
|
17
20
|
ref.current?.scrollHeight > ref.current?.clientHeight;
|
|
18
21
|
setShouldScroll(shouldScroll);
|
|
19
22
|
const fn = shouldScroll ? 'add' : 'remove';
|
|
20
23
|
ref.current?.classList[fn](`${className}--draggable`);
|
|
21
|
-
}, [ref
|
|
24
|
+
}, [ref, className]);
|
|
22
25
|
const onDragStart = () => {
|
|
23
26
|
setDragging(true);
|
|
24
27
|
ref.current?.classList.add(`${className}--dragging`);
|
|
@@ -50,6 +53,6 @@ export default function useDraggableScroll(ref, { className, ...opts }) {
|
|
|
50
53
|
originalOnMouseDown(event);
|
|
51
54
|
},
|
|
52
55
|
});
|
|
53
|
-
}, [ref, ref.current, setModifiedEvents, shouldScroll]);
|
|
56
|
+
}, [ref, ref.current, setModifiedEvents, shouldScroll]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
54
57
|
return { events: modifiedEvents };
|
|
55
58
|
}
|
package/hooks/use-escape.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
declare const useEscape: (ref: RefObject<HTMLElement | null>, callback: () => void) => void;
|
|
2
3
|
export default useEscape;
|
|
3
4
|
//# sourceMappingURL=use-escape.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-escape.d.ts","sourceRoot":"","sources":["../src/hooks/use-escape.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-escape.d.ts","sourceRoot":"","sources":["../src/hooks/use-escape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGjC,QAAA,MAAM,SAAS,GACb,KAAK,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,UAAU,MAAM,IAAI,SAiBrB,CAAA;AAED,eAAe,SAAS,CAAA"}
|
|
@@ -2,6 +2,6 @@ type Target = Document | Window | Element;
|
|
|
2
2
|
type EventMap<T extends Target> = T extends Window ? WindowEventHandlersEventMap & GlobalEventHandlersEventMap : T extends Document ? DocumentEventMap : GlobalEventHandlersEventMap;
|
|
3
3
|
type EventName<T extends Target> = keyof EventMap<T>;
|
|
4
4
|
type EventListener<T extends Target, E extends EventName<T>> = (event: EventMap<T>[E]) => void | boolean;
|
|
5
|
-
export default function useEventListener<T extends Target, E extends EventName<T>>(eventName: E, handler: EventListener<T, E>, options?: boolean | AddEventListenerOptions, element?: T, flag?: boolean): void;
|
|
5
|
+
export default function useEventListener<T extends Target, E extends EventName<T>>(eventName: E, handler: EventListener<T, E>, options?: boolean | AddEventListenerOptions, element?: T | null, flag?: boolean): void;
|
|
6
6
|
export {};
|
|
7
7
|
//# sourceMappingURL=use-event-listener.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-event-listener.d.ts","sourceRoot":"","sources":["../src/hooks/use-event-listener.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAEzC,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,GAC9C,2BAA2B,GAAG,2BAA2B,GACzD,CAAC,SAAS,QAAQ,GAChB,gBAAgB,GAChB,2BAA2B,CAAA;AAEjC,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAA;AAEpD,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,IAAI,CAC7D,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAClB,IAAI,GAAG,OAAO,CAAA;AAGnB,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAEtB,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,OAAO,GAAE,OAAO,GAAG,uBAA4B,EAC/C,OAAO,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"use-event-listener.d.ts","sourceRoot":"","sources":["../src/hooks/use-event-listener.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAEzC,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,GAC9C,2BAA2B,GAAG,2BAA2B,GACzD,CAAC,SAAS,QAAQ,GAChB,gBAAgB,GAChB,2BAA2B,CAAA;AAEjC,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAA;AAEpD,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,IAAI,CAC7D,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAClB,IAAI,GAAG,OAAO,CAAA;AAGnB,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAEtB,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,OAAO,GAAE,OAAO,GAAG,uBAA4B,EAC/C,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,EAClB,IAAI,GAAE,OAAc,QAmDrB"}
|
|
@@ -2,8 +2,8 @@ import { useEffect, useRef } from 'react';
|
|
|
2
2
|
// Hook
|
|
3
3
|
export default function useEventListener(eventName, handler, options = {}, element, flag = true) {
|
|
4
4
|
// Create a ref that stores handler
|
|
5
|
-
const savedHandler = useRef();
|
|
6
|
-
const elementRef = useRef();
|
|
5
|
+
const savedHandler = useRef(null);
|
|
6
|
+
const elementRef = useRef(null);
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
elementRef.current = element || window;
|
|
9
9
|
}, [element]);
|
|
@@ -21,17 +21,17 @@ export default function useEventListener(eventName, handler, options = {}, eleme
|
|
|
21
21
|
if (!isSupported)
|
|
22
22
|
return;
|
|
23
23
|
// Create event listener that calls handler function stored in ref
|
|
24
|
-
const eventListener = (event) => savedHandler.current(event);
|
|
24
|
+
const eventListener = (event) => savedHandler.current?.(event);
|
|
25
25
|
if (flag) {
|
|
26
26
|
// Add event listener
|
|
27
|
-
elementRef.current
|
|
27
|
+
elementRef.current?.addEventListener(eventName, eventListener, options);
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
elementRef.current
|
|
30
|
+
elementRef.current?.removeEventListener(eventName, eventListener);
|
|
31
31
|
}
|
|
32
32
|
// Remove event listener on cleanup
|
|
33
33
|
return () => {
|
|
34
|
-
elementRef.current
|
|
34
|
+
elementRef.current?.removeEventListener(eventName, eventListener);
|
|
35
35
|
};
|
|
36
36
|
}, [eventName, handler, options, element, flag]);
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-is-in-viewport.d.ts","sourceRoot":"","sources":["../src/hooks/use-is-in-viewport.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,OAAO,UAAQ,EACf,UAAU,SAAY,EACtB,SAAS,WAA0B;;
|
|
1
|
+
{"version":3,"file":"use-is-in-viewport.d.ts","sourceRoot":"","sources":["../src/hooks/use-is-in-viewport.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,OAAO,UAAQ,EACf,UAAU,SAAY,EACtB,SAAS,WAA0B;;kBA2Dd,WAAW,GAAG,IAAI;EAiBxC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
export default function useIsInViewport(initial = false, rootMargin = '0px 0px', threshold = [0, 0.25, 0.5, 0.75, 1]) {
|
|
3
3
|
const [isInViewport, setIsInViewport] = useState(initial);
|
|
4
|
-
const element = useRef();
|
|
5
|
-
const observer = useRef();
|
|
4
|
+
const element = useRef(null);
|
|
5
|
+
const observer = useRef(null);
|
|
6
6
|
useEffect(() => {
|
|
7
7
|
if (!observer.current) {
|
|
8
8
|
observer.current = new IntersectionObserver((entries) => {
|
|
@@ -20,7 +20,7 @@ export default function useIsInViewport(initial = false, rootMargin = '0px 0px',
|
|
|
20
20
|
observer.current = null;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
}, []);
|
|
23
|
+
}, [rootMargin, threshold]);
|
|
24
24
|
const waitForObserver = () => {
|
|
25
25
|
return new Promise((resolve, reject) => {
|
|
26
26
|
if (observer.current) {
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superrb/react-addons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-1",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"module": "index.js",
|
|
6
7
|
"repository": "https://github.com/superrbstudio/react-addons",
|
|
7
8
|
"author": "@molovo",
|
|
8
9
|
"license": "MIT",
|
|
9
|
-
"private": false,
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@hookform/resolvers": "^3.3.1",
|
|
12
|
-
"change-case": "^
|
|
12
|
+
"change-case": "^5.0.0",
|
|
13
13
|
"install-peers-cli": "^2.2.0",
|
|
14
14
|
"js-cookie": "^3.0.5",
|
|
15
15
|
"react-google-recaptcha-v3": "^1.10.1",
|
|
@@ -18,21 +18,21 @@
|
|
|
18
18
|
"simple-zustand-devtools": "^1.1.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"react": "^
|
|
21
|
+
"react": "^19.1.0",
|
|
22
22
|
"typescript": "^5.2.2",
|
|
23
|
-
"yup": "^1.
|
|
23
|
+
"yup": "^1.4.0",
|
|
24
24
|
"zustand": "^4.4.7"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "tsc",
|
|
28
28
|
"prepublishOnly": "yarn build",
|
|
29
|
-
"
|
|
29
|
+
"install-peers": "install-peers",
|
|
30
30
|
"dev": "watch 'yarn build' ./src"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/js-cookie": "^3.0.3",
|
|
34
34
|
"@types/node": "^20.5.7",
|
|
35
|
-
"@types/react": "^
|
|
35
|
+
"@types/react": "^19.1.0",
|
|
36
36
|
"eslint": "^8.50.0",
|
|
37
37
|
"eslint-config-next": "^13.5.3",
|
|
38
38
|
"eslint-config-prettier": "^9.0.0",
|
|
@@ -40,8 +40,13 @@
|
|
|
40
40
|
"eslint-plugin-react": "^7.33.2",
|
|
41
41
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
42
42
|
"prettier": "^3.2.2",
|
|
43
|
+
"react": "^19.1.0",
|
|
44
|
+
"typescript": "^5.2.2",
|
|
43
45
|
"typescript-eslint": "^0.0.1-alpha.0",
|
|
44
|
-
"watch": "^1.0.2"
|
|
46
|
+
"watch": "^1.0.2",
|
|
47
|
+
"yup": "^1.4.0",
|
|
48
|
+
"zustand": "^4.4.7"
|
|
45
49
|
},
|
|
46
|
-
"packageManager": "yarn@
|
|
47
|
-
|
|
50
|
+
"packageManager": "yarn@4.9.1",
|
|
51
|
+
"stableVersion": "3.0.0"
|
|
52
|
+
}
|