@homecode/ui 4.11.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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/esm/index.js +78 -0
- package/dist/esm/node_modules/style-inject/dist/style-inject.es.js +28 -0
- package/dist/esm/src/components/AssistiveText/AssistiveText.js +10 -0
- package/dist/esm/src/components/AssistiveText/AssistiveText.styl.js +7 -0
- package/dist/esm/src/components/Button/Button.helpers.js +12 -0
- package/dist/esm/src/components/Button/Button.js +38 -0
- package/dist/esm/src/components/Button/Button.styl.js +7 -0
- package/dist/esm/src/components/ButtonGroup/ButtonGroup.js +10 -0
- package/dist/esm/src/components/ButtonGroup/ButtonGroup.styl.js +7 -0
- package/dist/esm/src/components/Checkbox/Checkbox.js +48 -0
- package/dist/esm/src/components/Checkbox/Checkbox.styl.js +7 -0
- package/dist/esm/src/components/Container/Container.js +12 -0
- package/dist/esm/src/components/Container/Container.styl.js +7 -0
- package/dist/esm/src/components/DateTime/DateTime.js +17 -0
- package/dist/esm/src/components/Draggable/Draggable.js +136 -0
- package/dist/esm/src/components/Draggable/Draggable.styl.js +7 -0
- package/dist/esm/src/components/Expand/Expand.js +24 -0
- package/dist/esm/src/components/Expand/Expand.styl.js +7 -0
- package/dist/esm/src/components/Form/Form.helpers.js +42 -0
- package/dist/esm/src/components/Form/Form.js +286 -0
- package/dist/esm/src/components/Form/Form.styl.js +7 -0
- package/dist/esm/src/components/Form/Form.types.js +1 -0
- package/dist/esm/src/components/Form/SubmitButtons/SubmitButtons.js +8 -0
- package/dist/esm/src/components/Form/SubmitButtons/SubmitButtons.styl.js +7 -0
- package/dist/esm/src/components/Form/Validator.js +36 -0
- package/dist/esm/src/components/Gallery/Dots/Dots.js +9 -0
- package/dist/esm/src/components/Gallery/Dots/Dots.styl.js +7 -0
- package/dist/esm/src/components/Gallery/Gallery.js +180 -0
- package/dist/esm/src/components/Gallery/Gallery.styl.js +7 -0
- package/dist/esm/src/components/Heading/Heading.js +37 -0
- package/dist/esm/src/components/Heading/Heading.styl.js +7 -0
- package/dist/esm/src/components/Icon/Icon.js +27 -0
- package/dist/esm/src/components/Icon/Icon.styl.js +7 -0
- package/dist/esm/src/components/Icon/icons/avatar.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/brokenImage.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/check.svg.js +19 -0
- package/dist/esm/src/components/Icon/icons/chevronDown.svg.js +20 -0
- package/dist/esm/src/components/Icon/icons/chevronLeft.svg.js +20 -0
- package/dist/esm/src/components/Icon/icons/chevronRight.svg.js +20 -0
- package/dist/esm/src/components/Icon/icons/chevronUp.svg.js +20 -0
- package/dist/esm/src/components/Icon/icons/close.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/colors.svg.js +60 -0
- package/dist/esm/src/components/Icon/icons/copy.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/delete.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/draft.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/edit.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/externalLink.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/fullscreen.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/fullscreenExit.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/gear.svg.js +20 -0
- package/dist/esm/src/components/Icon/icons/history.svg.js +17 -0
- package/dist/esm/src/components/Icon/icons/home.svg.js +19 -0
- package/dist/esm/src/components/Icon/icons/index.js +41 -0
- package/dist/esm/src/components/Icon/icons/loader.svg.js +45 -0
- package/dist/esm/src/components/Icon/icons/menu.svg.js +18 -0
- package/dist/esm/src/components/Icon/icons/mic.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/minus.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/moreHorizontal.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/moreVertical.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/plus.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/redo.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/requiredStar.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/save.svg.js +17 -0
- package/dist/esm/src/components/Icon/icons/send.svg.js +16 -0
- package/dist/esm/src/components/Icon/icons/settings.svg.js +52 -0
- package/dist/esm/src/components/Icon/icons/shoppingBag.svg.js +17 -0
- package/dist/esm/src/components/Icon/icons/social_email.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/social_instagram.svg.js +15 -0
- package/dist/esm/src/components/Icon/icons/social_telegram.svg.js +19 -0
- package/dist/esm/src/components/Icon/icons/undo.svg.js +15 -0
- package/dist/esm/src/components/Input/Input.js +331 -0
- package/dist/esm/src/components/Input/Input.styl.js +7 -0
- package/dist/esm/src/components/InputFile/InputFile.js +292 -0
- package/dist/esm/src/components/InputFile/InputFile.styl.js +7 -0
- package/dist/esm/src/components/InputFile/InputFile.types.js +1 -0
- package/dist/esm/src/components/InputFile/Item/Item.js +18 -0
- package/dist/esm/src/components/InputFile/Item/Item.styl.js +7 -0
- package/dist/esm/src/components/Label/Label.constants.json.js +8 -0
- package/dist/esm/src/components/Label/Label.helpers.js +35 -0
- package/dist/esm/src/components/Label/Label.js +58 -0
- package/dist/esm/src/components/Label/Label.styl.js +7 -0
- package/dist/esm/src/components/Lazy/Lazy.js +65 -0
- package/dist/esm/src/components/LightBox/LightBox.js +28 -0
- package/dist/esm/src/components/LightBox/LightBox.styl.js +7 -0
- package/dist/esm/src/components/Notifications/Notifications.constants.json.js +6 -0
- package/dist/esm/src/components/Notifications/Notifications.js +67 -0
- package/dist/esm/src/components/Notifications/Notifications.styl.js +7 -0
- package/dist/esm/src/components/Notifications/store.js +62 -0
- package/dist/esm/src/components/Paranja/Paranja.js +14 -0
- package/dist/esm/src/components/Paranja/Paranja.styl.js +7 -0
- package/dist/esm/src/components/Popup/Popup.helpers.js +31 -0
- package/dist/esm/src/components/Popup/Popup.js +396 -0
- package/dist/esm/src/components/Popup/Popup.styl.js +7 -0
- package/dist/esm/src/components/PopupMenu/PopupMenu.js +15 -0
- package/dist/esm/src/components/PopupMenu/PopupMenu.styl.js +7 -0
- package/dist/esm/src/components/Portal/Portal.js +19 -0
- package/dist/esm/src/components/RequiredStar/RequiredStar.js +12 -0
- package/dist/esm/src/components/RequiredStar/RequiredStar.styl.js +7 -0
- package/dist/esm/src/components/Router/Link/Link.js +61 -0
- package/dist/esm/src/components/Router/Link/Link.styl.js +7 -0
- package/dist/esm/src/components/Router/Redirect.js +12 -0
- package/dist/esm/src/components/Router/Route.js +4 -0
- package/dist/esm/src/components/Router/Router.helpers.js +33 -0
- package/dist/esm/src/components/Router/Router.js +68 -0
- package/dist/esm/src/components/Router/context.js +5 -0
- package/dist/esm/src/components/Router/store.js +55 -0
- package/dist/esm/src/components/Scroll/Scroll.js +274 -0
- package/dist/esm/src/components/Scroll/Scroll.styl.js +7 -0
- package/dist/esm/src/components/Select/Select.helpers.js +37 -0
- package/dist/esm/src/components/Select/Select.js +583 -0
- package/dist/esm/src/components/Select/Select.styl.js +7 -0
- package/dist/esm/src/components/Spinner/Spinner.js +11 -0
- package/dist/esm/src/components/Spinner/Spinner.styl.js +7 -0
- package/dist/esm/src/components/Spinner/spinner.svg.js +24 -0
- package/dist/esm/src/components/Table/Table.js +24 -0
- package/dist/esm/src/components/Table/Table.styl.js +7 -0
- package/dist/esm/src/components/Tabs/Tabs.js +43 -0
- package/dist/esm/src/components/Tabs/Tabs.styl.js +7 -0
- package/dist/esm/src/components/Text/Text.js +44 -0
- package/dist/esm/src/components/Text/Text.styl.js +7 -0
- package/dist/esm/src/components/Theme/Theme.defaults.js +50 -0
- package/dist/esm/src/components/Theme/Theme.helpers.js +67 -0
- package/dist/esm/src/components/Theme/Theme.js +13 -0
- package/dist/esm/src/components/VH/VH.js +33 -0
- package/dist/esm/src/components/Virtualized/List/List.js +124 -0
- package/dist/esm/src/components/Virtualized/List/List.styl.js +7 -0
- package/dist/esm/src/components/Virtualized/List/ListScroll.js +21 -0
- package/dist/esm/src/components/Virtualized/List/ListScroll.styl.js +7 -0
- package/dist/esm/src/components/Virtualized/Virtualized.helpers.js +14 -0
- package/dist/esm/src/components/Virtualized/Virtualized.js +200 -0
- package/dist/esm/src/components/Virtualized/Virtualized.styl.js +7 -0
- package/dist/esm/src/components/Virtualized/Virtualized.types.js +1 -0
- package/dist/esm/src/services/i18n.js +68 -0
- package/dist/esm/src/tools/array.js +60 -0
- package/dist/esm/src/tools/config.js +9 -0
- package/dist/esm/src/tools/debounce.js +11 -0
- package/dist/esm/src/tools/dom.js +46 -0
- package/dist/esm/src/tools/env.js +3 -0
- package/dist/esm/src/tools/file.js +11 -0
- package/dist/esm/src/tools/localStorage.js +31 -0
- package/dist/esm/src/tools/number.js +27 -0
- package/dist/esm/src/tools/object.js +5 -0
- package/dist/esm/src/tools/queryParams.js +20 -0
- package/dist/esm/src/tools/rangeMap.js +3 -0
- package/dist/esm/src/tools/resizeObserver.js +64 -0
- package/dist/esm/src/tools/scroll.js +41 -0
- package/dist/esm/src/tools/string.js +7 -0
- package/dist/esm/src/tools/throttle.js +30 -0
- package/dist/esm/src/tools/uid.js +7 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/src/components/AssistiveText/AssistiveText.d.ts +3 -0
- package/dist/esm/types/src/components/AssistiveText/AssistiveText.types.d.ts +7 -0
- package/dist/esm/types/src/components/Button/Button.d.ts +4 -0
- package/dist/esm/types/src/components/Button/Button.helpers.d.ts +1 -0
- package/dist/esm/types/src/components/Button/Button.types.d.ts +14 -0
- package/dist/esm/types/src/components/ButtonGroup/ButtonGroup.d.ts +3 -0
- package/dist/esm/types/src/components/ButtonGroup/ButtonGroup.types.d.ts +5 -0
- package/dist/esm/types/src/components/Checkbox/Checkbox.d.ts +18 -0
- package/dist/esm/types/src/components/Checkbox/Checkbox.types.d.ts +10 -0
- package/dist/esm/types/src/components/Container/Container.d.ts +3 -0
- package/dist/esm/types/src/components/Container/Container.types.d.ts +13 -0
- package/dist/esm/types/src/components/DateTime/DateTime.d.ts +8 -0
- package/dist/esm/types/src/components/DateTime/DateTime.types.d.ts +6 -0
- package/dist/esm/types/src/components/Draggable/Draggable.d.ts +24 -0
- package/dist/esm/types/src/components/Draggable/Draggable.types.d.ts +11 -0
- package/dist/esm/types/src/components/Expand/Expand.d.ts +3 -0
- package/dist/esm/types/src/components/Expand/Expand.types.d.ts +16 -0
- package/dist/esm/types/src/components/Form/Form.d.ts +32 -0
- package/dist/esm/types/src/components/Form/Form.helpers.d.ts +6 -0
- package/dist/esm/types/src/components/Form/Form.types.d.ts +71 -0
- package/dist/esm/types/src/components/Form/SubmitButtons/SubmitButtons.d.ts +13 -0
- package/dist/esm/types/src/components/Form/Validator.d.ts +2 -0
- package/dist/esm/types/src/components/Form/index.d.ts +2 -0
- package/dist/esm/types/src/components/Gallery/Dots/Dots.d.ts +5 -0
- package/dist/esm/types/src/components/Gallery/Gallery.d.ts +36 -0
- package/dist/esm/types/src/components/Gallery/Gallery.types.d.ts +12 -0
- package/dist/esm/types/src/components/Heading/Heading.d.ts +3 -0
- package/dist/esm/types/src/components/Heading/Heading.types.d.ts +5 -0
- package/dist/esm/types/src/components/Icon/Icon.d.ts +45 -0
- package/dist/esm/types/src/components/Icon/Icon.example.d.ts +3 -0
- package/dist/esm/types/src/components/Icon/Icon.helpers.d.ts +1 -0
- package/dist/esm/types/src/components/Icon/Icon.types.d.ts +8 -0
- package/dist/esm/types/src/components/Icon/icons/index.d.ts +39 -0
- package/dist/esm/types/src/components/Input/Input.d.ts +42 -0
- package/dist/esm/types/src/components/Input/Input.types.d.ts +21 -0
- package/dist/esm/types/src/components/InputFile/InputFile.d.ts +48 -0
- package/dist/esm/types/src/components/InputFile/InputFile.types.d.ts +22 -0
- package/dist/esm/types/src/components/InputFile/Item/Item.d.ts +16 -0
- package/dist/esm/types/src/components/Label/Label.d.ts +19 -0
- package/dist/esm/types/src/components/Label/Label.helpers.d.ts +1 -0
- package/dist/esm/types/src/components/Label/Label.types.d.ts +8 -0
- package/dist/esm/types/src/components/Lazy/Lazy.d.ts +18 -0
- package/dist/esm/types/src/components/Lazy/Lazy.types.d.ts +15 -0
- package/dist/esm/types/src/components/LightBox/LightBox.d.ts +3 -0
- package/dist/esm/types/src/components/LightBox/LightBox.types.d.ts +7 -0
- package/dist/esm/types/src/components/Notifications/Notifications.d.ts +2 -0
- package/dist/esm/types/src/components/Notifications/Notifications.types.d.ts +19 -0
- package/dist/esm/types/src/components/Notifications/store.d.ts +2 -0
- package/dist/esm/types/src/components/Paranja/Paranja.d.ts +3 -0
- package/dist/esm/types/src/components/Paranja/Paranja.types.d.ts +8 -0
- package/dist/esm/types/src/components/Popup/Popup.d.ts +73 -0
- package/dist/esm/types/src/components/Popup/Popup.helpers.d.ts +8 -0
- package/dist/esm/types/src/components/Popup/Popup.types.d.ts +34 -0
- package/dist/esm/types/src/components/PopupMenu/PopupMenu.d.ts +3 -0
- package/dist/esm/types/src/components/PopupMenu/PopupMenu.types.d.ts +13 -0
- package/dist/esm/types/src/components/Portal/Portal.d.ts +7 -0
- package/dist/esm/types/src/components/RequiredStar/RequiredStar.d.ts +3 -0
- package/dist/esm/types/src/components/RequiredStar/RequiredStar.types.d.ts +6 -0
- package/dist/esm/types/src/components/Router/Link/Link.d.ts +1 -0
- package/dist/esm/types/src/components/Router/Link/Link.types.d.ts +12 -0
- package/dist/esm/types/src/components/Router/Redirect.d.ts +5 -0
- package/dist/esm/types/src/components/Router/Route.d.ts +5 -0
- package/dist/esm/types/src/components/Router/Router.d.ts +7 -0
- package/dist/esm/types/src/components/Router/Router.helpers.d.ts +2 -0
- package/dist/esm/types/src/components/Router/Router.types.d.ts +18 -0
- package/dist/esm/types/src/components/Router/context.d.ts +6 -0
- package/dist/esm/types/src/components/Router/store.d.ts +2 -0
- package/dist/esm/types/src/components/Scroll/Scroll.d.ts +67 -0
- package/dist/esm/types/src/components/Scroll/Scroll.types.d.ts +27 -0
- package/dist/esm/types/src/components/Select/Select.d.ts +94 -0
- package/dist/esm/types/src/components/Select/Select.helpers.d.ts +14 -0
- package/dist/esm/types/src/components/Select/Select.types.d.ts +74 -0
- package/dist/esm/types/src/components/Spinner/Spinner.d.ts +3 -0
- package/dist/esm/types/src/components/Spinner/Spinner.types.d.ts +4 -0
- package/dist/esm/types/src/components/Table/Table.d.ts +8 -0
- package/dist/esm/types/src/components/Table/Table.types.d.ts +19 -0
- package/dist/esm/types/src/components/Tabs/Tabs.d.ts +3 -0
- package/dist/esm/types/src/components/Tabs/Tabs.types.d.ts +27 -0
- package/dist/esm/types/src/components/Text/Text.d.ts +7 -0
- package/dist/esm/types/src/components/Theme/Theme.d.ts +5 -0
- package/dist/esm/types/src/components/Theme/Theme.defaults.d.ts +32 -0
- package/dist/esm/types/src/components/Theme/Theme.helpers.d.ts +15 -0
- package/dist/esm/types/src/components/Theme/Theme.types.d.ts +6 -0
- package/dist/esm/types/src/components/VH/VH.d.ts +12 -0
- package/dist/esm/types/src/components/Virtualized/Cards/Cards.d.ts +26 -0
- package/dist/esm/types/src/components/Virtualized/List/List.d.ts +44 -0
- package/dist/esm/types/src/components/Virtualized/List/ListScroll.d.ts +8 -0
- package/dist/esm/types/src/components/Virtualized/Table/Table.d.ts +26 -0
- package/dist/esm/types/src/components/Virtualized/Virtualized.d.ts +34 -0
- package/dist/esm/types/src/components/Virtualized/Virtualized.helpers.d.ts +18 -0
- package/dist/esm/types/src/components/Virtualized/Virtualized.types.d.ts +53 -0
- package/dist/esm/types/src/components/Virtualized/index.d.ts +4 -0
- package/dist/esm/types/src/components/index.d.ts +33 -0
- package/dist/esm/types/src/index.d.ts +3 -0
- package/dist/esm/types/src/services/i18n.d.ts +16 -0
- package/dist/esm/types/src/services/index.d.ts +1 -0
- package/dist/esm/types/src/tools/array.d.ts +8 -0
- package/dist/esm/types/src/tools/config.d.ts +10 -0
- package/dist/esm/types/src/tools/debounce.d.ts +1 -0
- package/dist/esm/types/src/tools/dom.d.ts +12 -0
- package/dist/esm/types/src/tools/env.d.ts +1 -0
- package/dist/esm/types/src/tools/file.d.ts +1 -0
- package/dist/esm/types/src/tools/index.d.ts +16 -0
- package/dist/esm/types/src/tools/localStorage.d.ts +12 -0
- package/dist/esm/types/src/tools/number.d.ts +5 -0
- package/dist/esm/types/src/tools/object.d.ts +1 -0
- package/dist/esm/types/src/tools/queryParams.d.ts +3 -0
- package/dist/esm/types/src/tools/rangeMap.d.ts +2 -0
- package/dist/esm/types/src/tools/resizeObserver.d.ts +2 -0
- package/dist/esm/types/src/tools/scroll.d.ts +5 -0
- package/dist/esm/types/src/tools/string.d.ts +1 -0
- package/dist/esm/types/src/tools/throttle.d.ts +6 -0
- package/dist/esm/types/src/tools/uid.d.ts +1 -0
- package/dist/esm/types/src/types.d.ts +15 -0
- package/package.json +117 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState, useRef, useCallback, createElement } from 'react';
|
|
2
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import { Button } from '../Button/Button.js';
|
|
5
|
+
import { ButtonGroup } from '../ButtonGroup/ButtonGroup.js';
|
|
6
|
+
import S from './Tabs.styl.js';
|
|
7
|
+
|
|
8
|
+
function isId(id) {
|
|
9
|
+
return ['string', 'number'].includes(typeof id);
|
|
10
|
+
}
|
|
11
|
+
function Tabs(props) {
|
|
12
|
+
const { size = 'm', contentClassName, items, onChange, renderAll, activeId: initialId, children, ...rest } = props;
|
|
13
|
+
const [activeId, setActiveId] = useState(isId(initialId) ? initialId : items[0].id);
|
|
14
|
+
const tabsContent = useRef([]);
|
|
15
|
+
const onTabClick = useCallback((e, { id, onClick } = {}) => {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
if (onClick && !onClick(e)) {
|
|
18
|
+
e.peventDefault();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
setActiveId(id);
|
|
22
|
+
onChange?.(id);
|
|
23
|
+
}, []);
|
|
24
|
+
tabsContent.current = [];
|
|
25
|
+
const tabs = items.map((params) => {
|
|
26
|
+
const { id, label, forceRender, content, contentClassName: currContentClassName, ...rest } = params;
|
|
27
|
+
const isActive = activeId === id;
|
|
28
|
+
const tabContent = typeof content === 'function' ? content() : content;
|
|
29
|
+
if (renderAll || forceRender || isActive) {
|
|
30
|
+
tabsContent.current.push(jsx("div", { className: cn(contentClassName, currContentClassName, !isActive && S.inactive), children: tabContent }, id));
|
|
31
|
+
}
|
|
32
|
+
return (createElement(Button, { ...rest, size: size, key: id, onClick: e => onTabClick(e, params), checked: isActive }, label));
|
|
33
|
+
});
|
|
34
|
+
if (typeof children === 'function') {
|
|
35
|
+
return children({
|
|
36
|
+
tabs: jsx(ButtonGroup, { ...rest, children: tabs }),
|
|
37
|
+
content: tabsContent.current,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return jsx(Fragment, { children: tabsContent.current });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { Tabs };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { Link } from '../Router/Link/Link.js';
|
|
5
|
+
import { isBrowser } from '../../tools/env.js';
|
|
6
|
+
import 'nanoid';
|
|
7
|
+
import '../../tools/dom.js';
|
|
8
|
+
import 'timen';
|
|
9
|
+
import 'compareq';
|
|
10
|
+
import 'lodash.pick';
|
|
11
|
+
import '../../tools/queryParams.js';
|
|
12
|
+
import S from './Text.styl.js';
|
|
13
|
+
|
|
14
|
+
const textToAnchorId = text => text.toLowerCase().split(' ').join('_');
|
|
15
|
+
const getPath = () => (isBrowser && location.pathname) ?? '/';
|
|
16
|
+
const scrollIntoHeader = id => document.getElementById(id)?.scrollIntoView();
|
|
17
|
+
function useAnchor(text) {
|
|
18
|
+
if (typeof text !== 'string')
|
|
19
|
+
return [];
|
|
20
|
+
const id = textToAnchorId(text);
|
|
21
|
+
const href = `${getPath()}#${id}`;
|
|
22
|
+
const scrollUp = useCallback(() => scrollIntoHeader(id), [id]);
|
|
23
|
+
return [
|
|
24
|
+
id,
|
|
25
|
+
jsxs(Fragment, { children: ["\u00A0", jsx(Link, { href: href, className: S.anchor, onClick: scrollUp, children: "#" })] }),
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
function H({ As, className, children, anchor, ...rest }) {
|
|
29
|
+
const [id, anchorEl] = useAnchor(anchor ?? children);
|
|
30
|
+
return (jsxs(As, { ...rest, className: cn(S.heading, className), id: id, children: [children, anchorEl] }));
|
|
31
|
+
}
|
|
32
|
+
const H1 = props => jsx(H, { ...props, As: "h1", anchor: false });
|
|
33
|
+
const H2 = props => jsx(H, { ...props, As: "h2" });
|
|
34
|
+
const H3 = props => jsx(H, { ...props, As: "h3" });
|
|
35
|
+
const H4 = props => jsx(H, { ...props, As: "h4" });
|
|
36
|
+
const H5 = props => jsx(H, { ...props, As: "h5" });
|
|
37
|
+
const H6 = props => jsx(H, { ...props, As: "h6" });
|
|
38
|
+
if (isBrowser) {
|
|
39
|
+
window.addEventListener('load', () => {
|
|
40
|
+
scrollIntoHeader(location.hash.slice(1));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { H1, H2, H3, H4, H5, H6 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from '../../../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".Text_heading__DR-MG{position:relative}.Text_anchor__hq6W6{align-items:flex-start;border-radius:50%;height:100%;opacity:0;padding:0 .5em;transform:translateX(-1em);transition:.2s ease-out;transition-property:transform,opacity;-webkit-user-select:none;-moz-user-select:none;user-select:none}.Text_anchor__hq6W6:before{background:none!important;height:100%;position:absolute;width:2em}.Text_heading__DR-MG:hover .Text_anchor__hq6W6{opacity:1;transform:translateX(0)}.Text_heading__DR-MG .Text_anchor__hq6W6:hover{color:var(--active-color)}";
|
|
4
|
+
var S = {"heading":"Text_heading__DR-MG","anchor":"Text_anchor__hq6W6"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { colorsConfigToVars } from './Theme.helpers.js';
|
|
2
|
+
|
|
3
|
+
const baseConfig = {
|
|
4
|
+
'indent-s': '10px',
|
|
5
|
+
'indent-m': '20px',
|
|
6
|
+
'indent-l': '30px',
|
|
7
|
+
'border-radius-s': '2px',
|
|
8
|
+
'border-radius-m': '4px',
|
|
9
|
+
'border-radius-l': '6px',
|
|
10
|
+
};
|
|
11
|
+
const colorsAlphaModes = [0, 50, 100, 200, 300, 500, 800, 900];
|
|
12
|
+
const colors = {
|
|
13
|
+
light: '#e6e6e6',
|
|
14
|
+
dark: '#1a1a1a',
|
|
15
|
+
};
|
|
16
|
+
function getColors({ accent = colors.light, decent = colors.dark, active = '#54b62b', warning = '#ffa31a', danger = '#da3749', disabled = '#f1f1f2', link = '#3089fe', } = {}) {
|
|
17
|
+
return {
|
|
18
|
+
active: {
|
|
19
|
+
color: active,
|
|
20
|
+
mods: { alpha: [100, 300, 500, 800] /* mix: [['accent', 300]] */ },
|
|
21
|
+
},
|
|
22
|
+
warning: {
|
|
23
|
+
color: warning,
|
|
24
|
+
mods: { alpha: [100, 300, 500] },
|
|
25
|
+
},
|
|
26
|
+
danger: {
|
|
27
|
+
color: danger,
|
|
28
|
+
mods: { alpha: [100, 300, 500] },
|
|
29
|
+
},
|
|
30
|
+
disabled,
|
|
31
|
+
link,
|
|
32
|
+
accent: {
|
|
33
|
+
color: accent,
|
|
34
|
+
mods: { alpha: colorsAlphaModes },
|
|
35
|
+
},
|
|
36
|
+
decent: {
|
|
37
|
+
color: decent,
|
|
38
|
+
mods: { alpha: colorsAlphaModes },
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const getConfig = (cfg = {}) => ({
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
...colorsConfigToVars(getColors(cfg.colors)),
|
|
45
|
+
...baseConfig,
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
...cfg.rest,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export { baseConfig, colors, getColors, getConfig };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function hexToRGB(str) {
|
|
2
|
+
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
|
3
|
+
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
4
|
+
const hex = str.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);
|
|
5
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
6
|
+
if (!result)
|
|
7
|
+
return null;
|
|
8
|
+
return [
|
|
9
|
+
parseInt(result[1], 16),
|
|
10
|
+
parseInt(result[2], 16),
|
|
11
|
+
parseInt(result[3], 16),
|
|
12
|
+
].join(',');
|
|
13
|
+
}
|
|
14
|
+
const mix = (c1, c2, val) => Math.floor(c1 * (1 - val) + c2 * val);
|
|
15
|
+
function mixColor(color1, color2, val = 1) {
|
|
16
|
+
const c1 = (/^#/.test(color1) ? hexToRGB(color1) : color1)
|
|
17
|
+
.split(',')
|
|
18
|
+
.map(n => parseInt(n, 10));
|
|
19
|
+
const c2 = (/^#/.test(color2) ? hexToRGB(color2) : color2)
|
|
20
|
+
.split(',')
|
|
21
|
+
.map(n => parseInt(n, 10));
|
|
22
|
+
const rgb = [
|
|
23
|
+
mix(c1[0], c2[0], val),
|
|
24
|
+
mix(c1[1], c2[1], val),
|
|
25
|
+
mix(c1[2], c2[2], val),
|
|
26
|
+
].join(',');
|
|
27
|
+
return `rgb(${rgb})`;
|
|
28
|
+
}
|
|
29
|
+
function rgba(color, transparency) {
|
|
30
|
+
return `rgba(${getRGB(color)},${transparency})`;
|
|
31
|
+
}
|
|
32
|
+
function getRGB(color) {
|
|
33
|
+
if (/^rgb/.test(color))
|
|
34
|
+
return color.replace(/^rgb?\(|\)$/g, '');
|
|
35
|
+
return hexToRGB(color);
|
|
36
|
+
}
|
|
37
|
+
const getConfigColor = val => val?.color || val;
|
|
38
|
+
const colorMods = {
|
|
39
|
+
alpha: (color, val) => [rgba(color, val / 1000), `alpha-${val}`],
|
|
40
|
+
mix: (color1, [color2, val], config) => [
|
|
41
|
+
mixColor(color1, getConfigColor(config[color2]), val / 1000),
|
|
42
|
+
`mix-${color2}-${val}`,
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
function colorsConfigToVars(config) {
|
|
46
|
+
return Object.entries(config).reduce((acc, [name, val]) => {
|
|
47
|
+
const colorName = `${name}-color`;
|
|
48
|
+
if (typeof val === 'string') {
|
|
49
|
+
acc[colorName] = val;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const { color, mods } = val;
|
|
53
|
+
acc[colorName] = color;
|
|
54
|
+
if (typeof mods === 'object' && mods !== null) {
|
|
55
|
+
Object.entries(mods || {}).forEach(([mod, vals]) => {
|
|
56
|
+
vals.forEach(val => {
|
|
57
|
+
const [res, prefix] = colorMods[mod](color, val, config);
|
|
58
|
+
acc[`${colorName}-${prefix}`] = res;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return acc;
|
|
64
|
+
}, {});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { colorsConfigToVars, getRGB, mixColor, rgba };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
function buildVar(name, val) {
|
|
4
|
+
return `--${name}: ${val};`;
|
|
5
|
+
}
|
|
6
|
+
function Theme({ config = {} }) {
|
|
7
|
+
const vars = Object.entries(config)
|
|
8
|
+
.map(([name, val]) => buildVar(name, val))
|
|
9
|
+
.join('\n');
|
|
10
|
+
return jsx("style", { children: `:root {${vars}}` });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { Theme };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
import { isBrowser } from '../../tools/env.js';
|
|
4
|
+
import 'nanoid';
|
|
5
|
+
import '../../tools/dom.js';
|
|
6
|
+
import 'timen';
|
|
7
|
+
import 'compareq';
|
|
8
|
+
import 'lodash.pick';
|
|
9
|
+
import '../../tools/queryParams.js';
|
|
10
|
+
|
|
11
|
+
const getVH = () => (isBrowser ? window.innerHeight / 100 : 0);
|
|
12
|
+
class VH extends Component {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
this.state = { vh: 0 };
|
|
16
|
+
}
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
this.updateVH();
|
|
19
|
+
window.addEventListener('resize', this.updateVH);
|
|
20
|
+
}
|
|
21
|
+
componentWillUnmount() {
|
|
22
|
+
window.removeEventListener('resize', this.updateVH);
|
|
23
|
+
}
|
|
24
|
+
updateVH = () => {
|
|
25
|
+
this.setState({ vh: getVH() });
|
|
26
|
+
};
|
|
27
|
+
render() {
|
|
28
|
+
const { vh } = this.state;
|
|
29
|
+
return jsx("style", { children: `:root{--vh: ${vh}px;}` });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { VH };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Component, createRef } from 'react';
|
|
3
|
+
import omit from 'lodash.omit';
|
|
4
|
+
import { createStore } from 'justorm/react';
|
|
5
|
+
import Time from 'timen';
|
|
6
|
+
import * as number from '../../../tools/number.js';
|
|
7
|
+
import 'nanoid';
|
|
8
|
+
import '../../../tools/dom.js';
|
|
9
|
+
import 'compareq';
|
|
10
|
+
import 'lodash.pick';
|
|
11
|
+
import '../../../tools/queryParams.js';
|
|
12
|
+
import Virtualized from '../Virtualized.js';
|
|
13
|
+
import S from './List.styl.js';
|
|
14
|
+
|
|
15
|
+
const { zero } = number;
|
|
16
|
+
const CONTENT_BEFORE_SIZE_CHECK_TIMEOUT = 300;
|
|
17
|
+
class List extends Component {
|
|
18
|
+
store;
|
|
19
|
+
wrapElem;
|
|
20
|
+
contentBeforeElem;
|
|
21
|
+
contentAfterElem;
|
|
22
|
+
timers = Time.create();
|
|
23
|
+
unsubscribeContentBeforeResize;
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props);
|
|
26
|
+
this.store = createStore(this, {
|
|
27
|
+
mounted: false,
|
|
28
|
+
contentBeforeHeight: 0,
|
|
29
|
+
hasWrap: false,
|
|
30
|
+
});
|
|
31
|
+
// this.wrapElem = createRef<HTMLDivElement>();
|
|
32
|
+
this.contentBeforeElem = createRef();
|
|
33
|
+
this.contentAfterElem = createRef();
|
|
34
|
+
}
|
|
35
|
+
componentDidMount() {
|
|
36
|
+
// update, to pass actual wrapElem to Virtualized props
|
|
37
|
+
// this.store.mounted = true;
|
|
38
|
+
if (this.props.contentBefore) {
|
|
39
|
+
this.subscribeContentBeforeResize();
|
|
40
|
+
this.checkContentBeforeHeight();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
componentDidUpdate(prevProps) {
|
|
44
|
+
const { contentBefore } = this.props;
|
|
45
|
+
if (!prevProps.contentBefore && contentBefore)
|
|
46
|
+
this.subscribeContentBeforeResize();
|
|
47
|
+
if (prevProps.contentBefore && !contentBefore)
|
|
48
|
+
this.unsubscribeContentBeforeResize?.();
|
|
49
|
+
}
|
|
50
|
+
subscribeContentBeforeResize() {
|
|
51
|
+
this.unsubscribeContentBeforeResize = Time.every(CONTENT_BEFORE_SIZE_CHECK_TIMEOUT, this.checkContentBeforeHeight);
|
|
52
|
+
}
|
|
53
|
+
checkContentBeforeHeight = () => {
|
|
54
|
+
const elem = this.contentBeforeElem.current;
|
|
55
|
+
if (!elem)
|
|
56
|
+
return;
|
|
57
|
+
const { offsetHeight } = elem;
|
|
58
|
+
if (offsetHeight !== this.store.contentBeforeHeight)
|
|
59
|
+
this.store.contentBeforeHeight = offsetHeight;
|
|
60
|
+
};
|
|
61
|
+
getProps() {
|
|
62
|
+
const props = omit(this.props, [
|
|
63
|
+
'contentBefore',
|
|
64
|
+
'contentAfter',
|
|
65
|
+
'customWrapElem',
|
|
66
|
+
]);
|
|
67
|
+
const { contentBeforeHeight } = this.store;
|
|
68
|
+
const offsetBefore = zero(contentBeforeHeight) + zero(this.props.offsetBefore);
|
|
69
|
+
const offsetAfter = zero(this.contentAfterElem.current?.offsetHeight) +
|
|
70
|
+
zero(this.props.offsetAfter);
|
|
71
|
+
if (offsetBefore)
|
|
72
|
+
props.offsetBefore = offsetBefore;
|
|
73
|
+
if (offsetAfter)
|
|
74
|
+
props.offsetAfter = offsetAfter;
|
|
75
|
+
return props;
|
|
76
|
+
}
|
|
77
|
+
getItemProps = ({ index, offsetBefore, offsetAfter }) => {
|
|
78
|
+
const { itemHeight } = this.props;
|
|
79
|
+
return {
|
|
80
|
+
className: S.item,
|
|
81
|
+
style: { top: zero(offsetBefore) + index * itemHeight },
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
onWrapRef = (ref) => {
|
|
85
|
+
if (!ref)
|
|
86
|
+
return;
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
this.wrapElem = this.props.customWrapElem?.getRef?.(ref) || ref;
|
|
89
|
+
if (!this.store.hasWrap)
|
|
90
|
+
this.store.hasWrap = true;
|
|
91
|
+
};
|
|
92
|
+
renderLayout = ({ state, items, ...rest }) => {
|
|
93
|
+
const { contentBefore, contentAfter, customWrapElem } = this.props;
|
|
94
|
+
const { height, offsetAfter } = state;
|
|
95
|
+
const { contentBeforeHeight } = this.store;
|
|
96
|
+
const props = omit(rest, [
|
|
97
|
+
'contentBefore',
|
|
98
|
+
'contentAfter',
|
|
99
|
+
'scrollTop',
|
|
100
|
+
'itemHeight',
|
|
101
|
+
'itemsCount',
|
|
102
|
+
'totalCount',
|
|
103
|
+
'overlapCount',
|
|
104
|
+
'onScrollEnd',
|
|
105
|
+
'renderItem',
|
|
106
|
+
'wrapElem',
|
|
107
|
+
'getItemProps',
|
|
108
|
+
'offsetAfter',
|
|
109
|
+
'offsetBefore',
|
|
110
|
+
]);
|
|
111
|
+
const content = (jsxs(Fragment, { children: [contentBefore && (jsx("div", { ref: this.contentBeforeElem, children: contentBefore }, "contentBefore")), jsx("div", { className: S.gap, style: { height: height - contentBeforeHeight } }, "gap"), items, contentAfter && (jsx("div", { className: S.contentAfter, ref: this.contentAfterElem, style: { top: height - zero(offsetAfter) }, children: contentAfter }, "contentAfter"))] }));
|
|
112
|
+
let Elem = 'div';
|
|
113
|
+
if (customWrapElem) {
|
|
114
|
+
Elem = customWrapElem.component;
|
|
115
|
+
Object.assign(props, customWrapElem?.props);
|
|
116
|
+
}
|
|
117
|
+
return (jsx(Elem, { ...props, ref: this.onWrapRef, children: content }));
|
|
118
|
+
};
|
|
119
|
+
render() {
|
|
120
|
+
return (jsx(Virtualized, { ...this.getProps(), wrapElem: this.wrapElem, getItemProps: this.getItemProps, children: this.renderLayout }));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { List as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from '../../../../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".List_gap__-52oM{pointer-events:none;width:100%}.List_gap__-52oM,.List_item__-true{position:absolute}.List_contentAfter__H0Ujd{left:0;position:absolute;width:100%}";
|
|
4
|
+
var S = {"gap":"List_gap__-52oM","item":"List_item__-true","contentAfter":"List_contentAfter__H0Ujd"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { Scroll } from '../../Scroll/Scroll.js';
|
|
4
|
+
import List from './List.js';
|
|
5
|
+
import S from './ListScroll.styl.js';
|
|
6
|
+
|
|
7
|
+
function ListScroll({ scrollProps, ...rest }) {
|
|
8
|
+
const innerClassName = cn(scrollProps.x && S.x, scrollProps.y && S.y);
|
|
9
|
+
const props = {
|
|
10
|
+
...scrollProps,
|
|
11
|
+
innerClassName,
|
|
12
|
+
};
|
|
13
|
+
return (jsx(List, { ...rest, customWrapElem: {
|
|
14
|
+
component: Scroll,
|
|
15
|
+
props,
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
getRef: ref => ref.innerElem,
|
|
18
|
+
} }));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { ListScroll as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from '../../../../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".ListScroll_x__tSPeG{width:100%}.ListScroll_y__mvFCU{height:100%}";
|
|
4
|
+
var S = {"x":"ListScroll_x__tSPeG","y":"ListScroll_y__mvFCU"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function getLastIndex(scrollTop, clientHeight, itemHeight, overlapCount, totalCount) {
|
|
2
|
+
return Math.min(totalCount - 1, Math.floor((scrollTop + clientHeight) / itemHeight + overlapCount));
|
|
3
|
+
}
|
|
4
|
+
// Returns indexes of first and last items to be rendered
|
|
5
|
+
function getIndexes({ scrollTop, clientHeight, itemHeight, itemsCount, totalCount, overlapCount, }) {
|
|
6
|
+
const first = Math.max(0, Math.floor(scrollTop / itemHeight - overlapCount));
|
|
7
|
+
const last = Math.min(Math.max(first, itemsCount + overlapCount - 1), getLastIndex(scrollTop, clientHeight, itemHeight, overlapCount, totalCount));
|
|
8
|
+
return { first, last };
|
|
9
|
+
}
|
|
10
|
+
function getHeight({ itemsCount, itemHeight, offsetBefore = 0, offsetAfter = 0, }) {
|
|
11
|
+
return itemsCount * itemHeight + offsetBefore + offsetAfter;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { getHeight, getIndexes, getLastIndex };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import pick from 'lodash.pick';
|
|
4
|
+
import compare from 'compareq';
|
|
5
|
+
import Time from 'timen';
|
|
6
|
+
import debounce from '../../tools/debounce.js';
|
|
7
|
+
import { getHeight, getIndexes } from './Virtualized.helpers.js';
|
|
8
|
+
import S from './Virtualized.styl.js';
|
|
9
|
+
|
|
10
|
+
class Virtualized extends Component {
|
|
11
|
+
clearUnfreezeTimer;
|
|
12
|
+
scrollTopInited = false;
|
|
13
|
+
scrollElem;
|
|
14
|
+
lastScrollEndIndex = 0;
|
|
15
|
+
static defaultProps = {
|
|
16
|
+
overlapCount: 10,
|
|
17
|
+
pageSize: 20,
|
|
18
|
+
};
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.state = {
|
|
22
|
+
id: null,
|
|
23
|
+
height: getHeight(props),
|
|
24
|
+
first: 0,
|
|
25
|
+
last: 0,
|
|
26
|
+
isFreezed: false,
|
|
27
|
+
};
|
|
28
|
+
this.onScroll = debounce(this.onScroll, 150);
|
|
29
|
+
this.checkIfEnd = debounce(this.checkIfEnd, 200);
|
|
30
|
+
}
|
|
31
|
+
static getDerivedStateFromProps(props, { height }) {
|
|
32
|
+
const newHeight = getHeight(props);
|
|
33
|
+
if (newHeight !== height)
|
|
34
|
+
return { height: newHeight };
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
componentDidMount() {
|
|
38
|
+
// Time.after(100, () => {
|
|
39
|
+
const indexes = this.getIndexes();
|
|
40
|
+
this.setState(indexes); // eslint-disable-line
|
|
41
|
+
// });
|
|
42
|
+
// document.addEventListener('scroll', this.onScroll, true);
|
|
43
|
+
}
|
|
44
|
+
getSnapshotBeforeUpdate(prevProps) {
|
|
45
|
+
const { itemHeight, itemsCount } = this.props;
|
|
46
|
+
if (itemsCount === 0 && itemsCount !== prevProps.itemsCount)
|
|
47
|
+
return 0;
|
|
48
|
+
if (this.scrollElem) {
|
|
49
|
+
if (itemHeight !== prevProps.itemHeight)
|
|
50
|
+
return (itemHeight / prevProps.itemHeight) * this.scrollElem.scrollTop;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
shouldComponentUpdate(nextProps, nextState) {
|
|
55
|
+
if (nextProps.id !== this.props.id)
|
|
56
|
+
return true;
|
|
57
|
+
if (nextProps.itemsCount !== this.props.itemsCount)
|
|
58
|
+
return true;
|
|
59
|
+
if (nextProps.wrapElem !== this.props.wrapElem)
|
|
60
|
+
return true;
|
|
61
|
+
if (!compare(nextState, this.state))
|
|
62
|
+
return true;
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
66
|
+
const state = {};
|
|
67
|
+
const scrollElemUpdated = this.scrollElem !== this.props.wrapElem;
|
|
68
|
+
if (scrollElemUpdated)
|
|
69
|
+
this.scrollElem = this.props.wrapElem;
|
|
70
|
+
if (this.scrollElem) {
|
|
71
|
+
const newScrollTop = this.getNewScrollTop(prevProps, snapshot);
|
|
72
|
+
if (typeof newScrollTop === 'number')
|
|
73
|
+
this.scrollElem.scrollTop = newScrollTop;
|
|
74
|
+
}
|
|
75
|
+
if (prevProps.id !== this.props.id)
|
|
76
|
+
state.id = this.props.id;
|
|
77
|
+
if (scrollElemUpdated || this.needUpdateIndexes(prevProps))
|
|
78
|
+
Object.assign(state, this.getIndexes());
|
|
79
|
+
if (this.needUpdateHeight(prevProps))
|
|
80
|
+
state.height = getHeight(this.props);
|
|
81
|
+
if (Object.keys(state).length)
|
|
82
|
+
this.setState(state);
|
|
83
|
+
}
|
|
84
|
+
componentWillUnmount() {
|
|
85
|
+
this.clearUnfreezeTimer?.();
|
|
86
|
+
}
|
|
87
|
+
needUpdateIndexes(prevProps) {
|
|
88
|
+
// const { wrapElem } = this.props;
|
|
89
|
+
// if (!prevProps.wrapElem && wrapElem) return true;
|
|
90
|
+
return ['id', 'itemsCount', 'totalCount', 'overlapCount'].some(key => prevProps[key] !== this.props[key]);
|
|
91
|
+
}
|
|
92
|
+
needUpdateHeight(prevProps) {
|
|
93
|
+
return ['totalCount', 'offsetAfter'].some(key => prevProps[key] !== this.props[key]);
|
|
94
|
+
}
|
|
95
|
+
getNewScrollTop(prevProps, snapshot) {
|
|
96
|
+
const { initialScrollTop, scrollTop, itemsCount } = this.props;
|
|
97
|
+
if (!this.scrollTopInited) {
|
|
98
|
+
const scrollValue = initialScrollTop ?? scrollTop;
|
|
99
|
+
if (scrollValue && prevProps.itemsCount && itemsCount) {
|
|
100
|
+
this.scrollTopInited = true;
|
|
101
|
+
return scrollValue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (prevProps.initialScrollTop > 0 && initialScrollTop === 0)
|
|
105
|
+
return 0;
|
|
106
|
+
if (typeof scrollTop === 'number' && scrollTop !== prevProps.scrollTop)
|
|
107
|
+
return scrollTop;
|
|
108
|
+
if (typeof snapshot === 'number')
|
|
109
|
+
return snapshot;
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
getIndexes() {
|
|
113
|
+
// const { wrapElem } = this.props;
|
|
114
|
+
if (!this.scrollElem)
|
|
115
|
+
return null;
|
|
116
|
+
const { scrollTop, clientHeight } = this.scrollElem;
|
|
117
|
+
return getIndexes({
|
|
118
|
+
scrollTop,
|
|
119
|
+
clientHeight,
|
|
120
|
+
...pick(this.props, [
|
|
121
|
+
'itemsCount',
|
|
122
|
+
'totalCount',
|
|
123
|
+
'itemHeight',
|
|
124
|
+
'overlapCount',
|
|
125
|
+
]),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
onScroll = e => {
|
|
129
|
+
this.scrollElem = e.target;
|
|
130
|
+
const { onScroll } = this.props;
|
|
131
|
+
const indexes = this.getIndexes();
|
|
132
|
+
const { scrollTop } = this.scrollElem;
|
|
133
|
+
if (onScroll)
|
|
134
|
+
onScroll({ scrollTop, ...indexes });
|
|
135
|
+
this.checkIfEnd();
|
|
136
|
+
if (!compare(indexes, pick(this.state, ['first', 'last'])))
|
|
137
|
+
this.setState({ ...indexes });
|
|
138
|
+
this.unfreeze();
|
|
139
|
+
};
|
|
140
|
+
checkIfEnd = () => {
|
|
141
|
+
const { itemsCount, totalCount, pageSize, onScrollEnd } = this.props;
|
|
142
|
+
if (itemsCount === totalCount)
|
|
143
|
+
return;
|
|
144
|
+
if (itemsCount < this.lastScrollEndIndex)
|
|
145
|
+
return;
|
|
146
|
+
this.lastScrollEndIndex = Math.min(itemsCount + pageSize, totalCount);
|
|
147
|
+
onScrollEnd?.();
|
|
148
|
+
};
|
|
149
|
+
unfreeze = () => {
|
|
150
|
+
this.clearUnfreezeTimer?.();
|
|
151
|
+
this.clearUnfreezeTimer = Time.after(200, () => {
|
|
152
|
+
this.setState({ isFreezed: false });
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
getItemProps = (index) => {
|
|
156
|
+
const { getItemProps, offsetBefore, offsetAfter } = this.props;
|
|
157
|
+
const props = {
|
|
158
|
+
className: S.item,
|
|
159
|
+
key: index,
|
|
160
|
+
};
|
|
161
|
+
if (getItemProps) {
|
|
162
|
+
const { className, ...rest } = getItemProps({
|
|
163
|
+
index,
|
|
164
|
+
offsetBefore,
|
|
165
|
+
offsetAfter,
|
|
166
|
+
});
|
|
167
|
+
props.className = cn(props.className, className);
|
|
168
|
+
Object.assign(props, rest);
|
|
169
|
+
}
|
|
170
|
+
return props;
|
|
171
|
+
};
|
|
172
|
+
renderItems() {
|
|
173
|
+
const { itemsCount, renderItem } = this.props;
|
|
174
|
+
const { first, last } = this.state;
|
|
175
|
+
const items = [];
|
|
176
|
+
if (itemsCount > 0) {
|
|
177
|
+
for (let i = first; i <= last; i++) {
|
|
178
|
+
items.push(renderItem(this.getItemProps(i)));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return items;
|
|
182
|
+
}
|
|
183
|
+
render() {
|
|
184
|
+
const { children, className, pageSize, ...rest } = this.props;
|
|
185
|
+
const { isFreezed } = this.state;
|
|
186
|
+
const state = {
|
|
187
|
+
...pick(this.state, ['first', 'last', 'height']),
|
|
188
|
+
...pick(this.props, ['offsetBefore', 'offsetAfter']),
|
|
189
|
+
};
|
|
190
|
+
return children({
|
|
191
|
+
...rest,
|
|
192
|
+
state,
|
|
193
|
+
className: cn(S.root, isFreezed && S.freezeClicks, className),
|
|
194
|
+
onScroll: this.onScroll,
|
|
195
|
+
items: this.renderItems(),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { Virtualized as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from '../../../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".Virtualized_root__SX71a{display:block;height:100%;max-height:100%;overflow-y:auto;position:relative}.Virtualized_item__1vSN0{animation:Virtualized_show__2WhkK .1s ease-out;-webkit-backface-visibility:hidden;backface-visibility:hidden;transform:translateZ(0)}.Virtualized_freezeClicks__SCBdy .Virtualized_item__1vSN0{pointer-events:none}@keyframes Virtualized_show__2WhkK{0%{opacity:0}to{opacity:1}}";
|
|
4
|
+
var S = {"root":"Virtualized_root__SX71a","item":"Virtualized_item__1vSN0","show":"Virtualized_show__2WhkK","freezeClicks":"Virtualized_freezeClicks__SCBdy"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|