@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,68 @@
|
|
|
1
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { nanoid } from 'nanoid';
|
|
4
|
+
import { createStore, withStore } from 'justorm/react';
|
|
5
|
+
import _i18n from 'roddeh-i18n';
|
|
6
|
+
import LS from '../tools/localStorage.js';
|
|
7
|
+
import { queryParams } from '../tools/queryParams.js';
|
|
8
|
+
|
|
9
|
+
const DEFAULT_LANG = 'en';
|
|
10
|
+
const modules = {};
|
|
11
|
+
const queryLang = queryParams.lang;
|
|
12
|
+
if (queryLang)
|
|
13
|
+
LS.set('lang', queryLang);
|
|
14
|
+
const store = createStore('i18n', {
|
|
15
|
+
lang: LS.get('lang') ?? DEFAULT_LANG,
|
|
16
|
+
async changeLang(lang) {
|
|
17
|
+
// TODO: use WebWorker for requests?
|
|
18
|
+
const requests = modules[lang].map(loader => loader());
|
|
19
|
+
await Promise.all(requests);
|
|
20
|
+
modules[lang] = [];
|
|
21
|
+
this.lang = lang;
|
|
22
|
+
LS.set('lang', lang);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
function init(config) {
|
|
26
|
+
const langs = Object.keys(config);
|
|
27
|
+
const texts = langs.reduce((acc, lang) => ({ ...acc, [lang]: _i18n.create({ values: {} }) }), {});
|
|
28
|
+
const _getText = (lang, key, props) => {
|
|
29
|
+
if (texts[lang]?.translator.data.values[key]) {
|
|
30
|
+
return texts[lang](key, ...props);
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
function getTrans(key, props = []) {
|
|
35
|
+
return _getText(store.lang, key, props) || key;
|
|
36
|
+
}
|
|
37
|
+
const storeName = `i18n-${nanoid()}`;
|
|
38
|
+
const componentStore = createStore(storeName, { _updated: '' });
|
|
39
|
+
const callLoader = async (loader, lang) => {
|
|
40
|
+
const values = typeof loader === 'function' ? (await loader()).default : loader;
|
|
41
|
+
texts[lang].translator.add({ values });
|
|
42
|
+
componentStore._updated = nanoid();
|
|
43
|
+
};
|
|
44
|
+
Object.entries(config).forEach(([lang, loader]) => {
|
|
45
|
+
if (!modules[lang])
|
|
46
|
+
modules[lang] = [];
|
|
47
|
+
if (lang === store.lang)
|
|
48
|
+
return callLoader(loader, lang);
|
|
49
|
+
modules[lang].push(() => callLoader(loader, lang));
|
|
50
|
+
});
|
|
51
|
+
// TODO: revert ability to register modules
|
|
52
|
+
return {
|
|
53
|
+
storeName,
|
|
54
|
+
componentStore,
|
|
55
|
+
// hook (update when componentStore._updated changed)
|
|
56
|
+
withI18N: Component => withStore(storeName)(Component),
|
|
57
|
+
i18n: (key, props) => getTrans(key, props),
|
|
58
|
+
I18N: memo(withStore({
|
|
59
|
+
i18n: ['lang'],
|
|
60
|
+
[storeName]: true,
|
|
61
|
+
})(function I18N({ id, children, props }) {
|
|
62
|
+
const key = id ?? children;
|
|
63
|
+
return jsx(Fragment, { children: getTrans(key, props) });
|
|
64
|
+
})),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { init, store };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function indexWhere(arr, val, fieldName) {
|
|
2
|
+
if (!fieldName) {
|
|
3
|
+
return arr.indexOf(val);
|
|
4
|
+
}
|
|
5
|
+
const isValObj = typeof val === 'object';
|
|
6
|
+
let index = -1;
|
|
7
|
+
arr.some((d, i) => {
|
|
8
|
+
const dVal = isValObj ? val?.[fieldName] : val;
|
|
9
|
+
if (d?.[fieldName] === dVal) {
|
|
10
|
+
index = i;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
});
|
|
15
|
+
return index;
|
|
16
|
+
}
|
|
17
|
+
function sliceWhere([...arr], val, fieldName) {
|
|
18
|
+
spliceWhere(arr, val, fieldName);
|
|
19
|
+
return arr;
|
|
20
|
+
}
|
|
21
|
+
function spliceWhere(arr, val, fieldName) {
|
|
22
|
+
const index = indexWhere(arr, val, fieldName);
|
|
23
|
+
if (index > -1)
|
|
24
|
+
arr.splice(index, 1);
|
|
25
|
+
}
|
|
26
|
+
function _addUniq({ arr, val, fieldName }, action) {
|
|
27
|
+
if (Array.isArray(val)) {
|
|
28
|
+
val.forEach(v => addUniq(arr, v, fieldName));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const index = indexWhere(arr, val, fieldName);
|
|
32
|
+
if (index === -1)
|
|
33
|
+
action(val);
|
|
34
|
+
}
|
|
35
|
+
function addUniq(arr, val, fieldName) {
|
|
36
|
+
_addUniq({ arr, val, fieldName }, value => arr.push(value));
|
|
37
|
+
}
|
|
38
|
+
function unshiftUniq(arr, val, fieldName) {
|
|
39
|
+
_addUniq({ arr, val, fieldName }, value => arr.unshift(value));
|
|
40
|
+
}
|
|
41
|
+
function insert(baseArr, targetArr, startIndex) {
|
|
42
|
+
return [
|
|
43
|
+
...baseArr.slice(0, startIndex),
|
|
44
|
+
...targetArr,
|
|
45
|
+
...baseArr.slice(startIndex + targetArr.length),
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
function getIndexCircular(arr, index) {
|
|
49
|
+
const l = arr.length;
|
|
50
|
+
return arr[((index % l) + l) % l];
|
|
51
|
+
}
|
|
52
|
+
function circularSlice(arr, startIndex, count) {
|
|
53
|
+
const newArr = [];
|
|
54
|
+
for (let i = 0; i < count; i++) {
|
|
55
|
+
newArr.push(getIndexCircular(arr, startIndex + i));
|
|
56
|
+
}
|
|
57
|
+
return newArr;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { addUniq, circularSlice, getIndexCircular, indexWhere, insert, sliceWhere, spliceWhere, unshiftUniq };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isBrowser } from './env.js';
|
|
2
|
+
import 'nanoid';
|
|
3
|
+
import 'timen';
|
|
4
|
+
import 'compareq';
|
|
5
|
+
import 'lodash.pick';
|
|
6
|
+
import './queryParams.js';
|
|
7
|
+
|
|
8
|
+
function getCoords(elem) {
|
|
9
|
+
const box = elem.getBoundingClientRect();
|
|
10
|
+
return {
|
|
11
|
+
top: box.top + window.pageYOffset,
|
|
12
|
+
left: box.left + window.pageXOffset,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function hasParent(elem, parentElem) {
|
|
16
|
+
const isEqual = elem === parentElem;
|
|
17
|
+
if (isEqual || elem.nodeName === 'HTML') {
|
|
18
|
+
return isEqual;
|
|
19
|
+
}
|
|
20
|
+
return hasParent(elem.parentNode, parentElem);
|
|
21
|
+
}
|
|
22
|
+
var INTERACTION_MODE;
|
|
23
|
+
(function (INTERACTION_MODE) {
|
|
24
|
+
INTERACTION_MODE["POINTER"] = "pointer";
|
|
25
|
+
INTERACTION_MODE["KEYBOARD"] = "keyboard";
|
|
26
|
+
})(INTERACTION_MODE || (INTERACTION_MODE = {}));
|
|
27
|
+
let interactionMode = INTERACTION_MODE.POINTER;
|
|
28
|
+
const getInteractionMode = () => interactionMode;
|
|
29
|
+
function watchControllerFlag() {
|
|
30
|
+
const classes = document.body.classList;
|
|
31
|
+
const onPointerMove = () => {
|
|
32
|
+
classes.remove(INTERACTION_MODE.KEYBOARD);
|
|
33
|
+
classes.add(INTERACTION_MODE.POINTER);
|
|
34
|
+
};
|
|
35
|
+
['pointerdown', 'pointermove'].forEach(event => {
|
|
36
|
+
document.addEventListener(event, onPointerMove, true);
|
|
37
|
+
});
|
|
38
|
+
document.addEventListener('keydown', () => {
|
|
39
|
+
classes.remove(INTERACTION_MODE.POINTER);
|
|
40
|
+
classes.add(INTERACTION_MODE.KEYBOARD);
|
|
41
|
+
});
|
|
42
|
+
classes.add(interactionMode);
|
|
43
|
+
}
|
|
44
|
+
const isTouch = () => isBrowser && 'ontouchstart' in window;
|
|
45
|
+
|
|
46
|
+
export { INTERACTION_MODE, getCoords, getInteractionMode, hasParent, isTouch, watchControllerFlag };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function toBase64(file) {
|
|
2
|
+
return new Promise(resolve => {
|
|
3
|
+
const reader = new FileReader();
|
|
4
|
+
reader.readAsDataURL(file);
|
|
5
|
+
reader.onload = () => resolve(reader.result);
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
reader.onerror = error => resolve({ error });
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { toBase64 };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isBrowser } from './env.js';
|
|
2
|
+
|
|
3
|
+
const ls = isBrowser && window.localStorage;
|
|
4
|
+
var LS = isBrowser
|
|
5
|
+
? {
|
|
6
|
+
get(key) {
|
|
7
|
+
let result = ls.getItem(key);
|
|
8
|
+
try {
|
|
9
|
+
result = JSON.parse(result);
|
|
10
|
+
}
|
|
11
|
+
catch (e) { }
|
|
12
|
+
return result;
|
|
13
|
+
},
|
|
14
|
+
set(key, val) {
|
|
15
|
+
if (!val) {
|
|
16
|
+
this.remove(key);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const item = typeof val === 'object' ? JSON.stringify(val) : val;
|
|
20
|
+
ls.setItem(key, item);
|
|
21
|
+
},
|
|
22
|
+
remove(key) {
|
|
23
|
+
ls.removeItem(key);
|
|
24
|
+
},
|
|
25
|
+
clear() {
|
|
26
|
+
ls.clear();
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
: { get() { }, set() { }, remove() { }, clear() { } };
|
|
30
|
+
|
|
31
|
+
export { LS as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const LABEL = ['', 'k', 'M', 'B'];
|
|
2
|
+
function stringify(number) {
|
|
3
|
+
if (typeof number === 'string')
|
|
4
|
+
return number.match(/\d/g).join('');
|
|
5
|
+
return String(number);
|
|
6
|
+
}
|
|
7
|
+
const format = {
|
|
8
|
+
short(number, lv = 0) {
|
|
9
|
+
const numStr = stringify(number);
|
|
10
|
+
const level = Math.floor((numStr.length - 1) / 3);
|
|
11
|
+
if (level === 0)
|
|
12
|
+
return numStr;
|
|
13
|
+
const label = LABEL[level];
|
|
14
|
+
const num = numStr.slice(0, -level * 3);
|
|
15
|
+
return `${num}${label}`;
|
|
16
|
+
},
|
|
17
|
+
sections(number, splitter = ' ') {
|
|
18
|
+
const [whole, fractional] = stringify(number).split('.');
|
|
19
|
+
let result = whole.replace(/\B(?=(\d{3})+(?!\d))/g, splitter);
|
|
20
|
+
if (fractional !== undefined)
|
|
21
|
+
result = `${result}.${fractional}`;
|
|
22
|
+
return result;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const zero = num => num || 0;
|
|
26
|
+
|
|
27
|
+
export { format, zero };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isBrowser } from './env.js';
|
|
2
|
+
|
|
3
|
+
const SSRQueryParams = {};
|
|
4
|
+
function parseQueryParams(qs) {
|
|
5
|
+
const queryString = qs || isBrowser ? location?.search : '';
|
|
6
|
+
if (!queryString)
|
|
7
|
+
return {};
|
|
8
|
+
return [...new URLSearchParams(queryString).entries()].reduce((acc, [key, value]) => {
|
|
9
|
+
acc[key] = value;
|
|
10
|
+
return acc;
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
const setSSRQueryParams = (params) => {
|
|
14
|
+
Object.assign(SSRQueryParams, params);
|
|
15
|
+
};
|
|
16
|
+
const queryParams = isBrowser
|
|
17
|
+
? parseQueryParams()
|
|
18
|
+
: SSRQueryParams;
|
|
19
|
+
|
|
20
|
+
export { parseQueryParams, queryParams, setSSRQueryParams };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Time from 'timen';
|
|
2
|
+
import compare from 'compareq';
|
|
3
|
+
import pick from 'lodash.pick';
|
|
4
|
+
import { addUniq, spliceWhere } from './array.js';
|
|
5
|
+
import { isBrowser } from './env.js';
|
|
6
|
+
|
|
7
|
+
const ITEMS = new Map();
|
|
8
|
+
const NATIVE_OBSERVERS = new Map();
|
|
9
|
+
const IS_NATIVE = isBrowser && 'ResizeObserver' in window;
|
|
10
|
+
const TIMEOUT = 500;
|
|
11
|
+
const SIZE_FIELDS = ['offsetWidth', 'offsetHeight'];
|
|
12
|
+
function check() {
|
|
13
|
+
ITEMS.forEach((item, elem) => {
|
|
14
|
+
const { sizes, listeners } = item;
|
|
15
|
+
const newSizes = pick(elem, SIZE_FIELDS);
|
|
16
|
+
if (!compare(newSizes, sizes)) {
|
|
17
|
+
item.sizes = newSizes;
|
|
18
|
+
listeners.forEach(cb => cb(newSizes, elem));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
run();
|
|
22
|
+
}
|
|
23
|
+
function run() {
|
|
24
|
+
if (ITEMS.size > 0)
|
|
25
|
+
Time.after(TIMEOUT, check);
|
|
26
|
+
}
|
|
27
|
+
function observe(elem, cb) {
|
|
28
|
+
if (IS_NATIVE) {
|
|
29
|
+
const observer = new ResizeObserver(cb);
|
|
30
|
+
observer.observe(elem);
|
|
31
|
+
NATIVE_OBSERVERS.set(elem, observer);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const data = ITEMS.get(elem);
|
|
35
|
+
if (data) {
|
|
36
|
+
addUniq(data.listeners, cb);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
ITEMS.set(elem, {
|
|
40
|
+
sizes: pick(elem, SIZE_FIELDS),
|
|
41
|
+
listeners: [cb],
|
|
42
|
+
});
|
|
43
|
+
if (ITEMS.size === 1)
|
|
44
|
+
run();
|
|
45
|
+
}
|
|
46
|
+
function unobserve(elem, cb) {
|
|
47
|
+
if (IS_NATIVE) {
|
|
48
|
+
const observer = NATIVE_OBSERVERS.get(elem);
|
|
49
|
+
if (!observer)
|
|
50
|
+
return;
|
|
51
|
+
observer.unobserve(elem);
|
|
52
|
+
NATIVE_OBSERVERS.delete(elem);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const data = ITEMS.get(elem);
|
|
56
|
+
if (!cb || data?.listeners.indexOf(cb) === -1)
|
|
57
|
+
return;
|
|
58
|
+
if (data.listeners.length === 1)
|
|
59
|
+
ITEMS.delete(elem);
|
|
60
|
+
else
|
|
61
|
+
spliceWhere(data.listeners, cb);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { observe, unobserve };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const METRICS_BY_AXIS = {
|
|
2
|
+
horizontal: {
|
|
3
|
+
size: 'offsetWidth',
|
|
4
|
+
scroll: 'scrollWidth',
|
|
5
|
+
},
|
|
6
|
+
vertical: {
|
|
7
|
+
size: 'offsetHeight',
|
|
8
|
+
scroll: 'scrollHeight',
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
function isScrollable(node, axis, threshold = 5) {
|
|
12
|
+
const m = METRICS_BY_AXIS[axis];
|
|
13
|
+
return node[m.scroll] - node[m.size] > threshold;
|
|
14
|
+
}
|
|
15
|
+
function getScrollParent(node, axis = 'vertical') {
|
|
16
|
+
if (node == null)
|
|
17
|
+
return null;
|
|
18
|
+
if (node.tagName === 'BODY' || isScrollable(node, axis))
|
|
19
|
+
return node;
|
|
20
|
+
return getScrollParent(node.parentNode, axis);
|
|
21
|
+
}
|
|
22
|
+
function scrollTo(elem, left, top) {
|
|
23
|
+
if ('scrollBehavior' in document.documentElement.style) {
|
|
24
|
+
elem.scrollTo({ left, top, behavior: 'smooth' });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
elem.scrollTo(left, top);
|
|
28
|
+
}
|
|
29
|
+
function scrollIntoView(elem, { horizontal } = { horizontal: false }) {
|
|
30
|
+
if (!elem)
|
|
31
|
+
return;
|
|
32
|
+
const scrollParent = getScrollParent(elem);
|
|
33
|
+
if (!scrollParent)
|
|
34
|
+
return;
|
|
35
|
+
const to = horizontal
|
|
36
|
+
? elem.offsetLeft + elem.offsetWidth / 2 - scrollParent.clientWidth / 2
|
|
37
|
+
: elem.offsetTop + elem.offsetHeight / 2 - scrollParent.clientHeight / 2;
|
|
38
|
+
scrollTo(scrollParent, 0, Math.max(0, to));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { getScrollParent, scrollIntoView, scrollTo };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Time from 'timen';
|
|
2
|
+
|
|
3
|
+
function throttle(fn, ms, { trailing, skipFirst } = {}) {
|
|
4
|
+
let isCooldown = skipFirst;
|
|
5
|
+
let isCalledAtCooldown = false;
|
|
6
|
+
function runNext(...args) {
|
|
7
|
+
Time.after(ms, () => {
|
|
8
|
+
isCooldown = false;
|
|
9
|
+
if (trailing && isCalledAtCooldown) {
|
|
10
|
+
fn.apply(this, args);
|
|
11
|
+
isCalledAtCooldown = false;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return function throttled(...args) {
|
|
16
|
+
if (isCooldown) {
|
|
17
|
+
if (!isCalledAtCooldown && skipFirst && trailing)
|
|
18
|
+
runNext.apply(this, args);
|
|
19
|
+
isCalledAtCooldown = true;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
isCooldown = true;
|
|
23
|
+
isCalledAtCooldown = false;
|
|
24
|
+
fn.apply(this, args);
|
|
25
|
+
runNext.apply(this, args);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { throttle as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function focusOnClick(buttonElem: HTMLButtonElement | null): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import { Size } from 'uilib/types';
|
|
3
|
+
export type Props = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
4
|
+
className?: string;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
variant?: 'clear' | 'default' | 'outlined' | 'primary';
|
|
7
|
+
size?: Size;
|
|
8
|
+
loading?: boolean;
|
|
9
|
+
checked?: boolean;
|
|
10
|
+
square?: boolean;
|
|
11
|
+
prefixElem?: ReactNode;
|
|
12
|
+
postfixElem?: ReactNode;
|
|
13
|
+
onRef?: (ref: HTMLButtonElement) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import * as T from './Checkbox.types';
|
|
3
|
+
export declare class Checkbox extends Component<T.Props> {
|
|
4
|
+
id: any;
|
|
5
|
+
store: any;
|
|
6
|
+
static defaultProps: {
|
|
7
|
+
size: string;
|
|
8
|
+
variant: string;
|
|
9
|
+
label: string;
|
|
10
|
+
checked: boolean;
|
|
11
|
+
};
|
|
12
|
+
constructor(props: any);
|
|
13
|
+
onMouseDown: () => void;
|
|
14
|
+
onMouseUp: () => void;
|
|
15
|
+
onFocus: (e: any) => void;
|
|
16
|
+
onBlur: (e: any) => void;
|
|
17
|
+
render(): JSX.Element;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode, HTMLAttributes } from 'react';
|
|
2
|
+
import { Size, ComponentType } from '../../types';
|
|
3
|
+
export type Props = HTMLAttributes<HTMLInputElement> & ComponentType & {
|
|
4
|
+
label?: ReactNode;
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
error?: string | boolean;
|
|
8
|
+
size?: Size;
|
|
9
|
+
variant?: 'default' | 'outlined';
|
|
10
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Props = {
|
|
2
|
+
className?: string;
|
|
3
|
+
size?: 's' | 'm' | 'l' | 'xl';
|
|
4
|
+
children: any;
|
|
5
|
+
alignItemsCenter?: boolean;
|
|
6
|
+
justifyContentCenter?: boolean;
|
|
7
|
+
vertical?: boolean;
|
|
8
|
+
fullHeight?: boolean | string;
|
|
9
|
+
fullWidth?: boolean | string;
|
|
10
|
+
scrolledX?: boolean;
|
|
11
|
+
scrolledY?: boolean;
|
|
12
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import * as T from './DateTime.types';
|
|
3
|
+
export declare function formatDate({ value, format, locale }: {
|
|
4
|
+
value: any;
|
|
5
|
+
format: any;
|
|
6
|
+
locale?: string;
|
|
7
|
+
}): any;
|
|
8
|
+
export declare function DateTime({ value, format, locale }: T.Props): JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import * as T from './Draggable.types';
|
|
3
|
+
export declare class Draggable extends Component<T.Props> {
|
|
4
|
+
store: any;
|
|
5
|
+
startPos: any;
|
|
6
|
+
draggingElem: any;
|
|
7
|
+
draggingElemBounds: any;
|
|
8
|
+
dragStartFired: boolean;
|
|
9
|
+
timers: any;
|
|
10
|
+
constructor(props: any);
|
|
11
|
+
componentDidUpdate(prevProps: any): void;
|
|
12
|
+
componentWillUnmount(): void;
|
|
13
|
+
onPointerDown: (e: any) => void;
|
|
14
|
+
onPointerMove: (e: any) => void;
|
|
15
|
+
checkUnderElem: any;
|
|
16
|
+
onPointerOut: ({ target }: {
|
|
17
|
+
target: any;
|
|
18
|
+
}) => void;
|
|
19
|
+
onPointerUp: (e: any) => void;
|
|
20
|
+
selectInner: (elem: any) => any;
|
|
21
|
+
transformInner(elem: any, str?: any): void;
|
|
22
|
+
dropUnder(): void;
|
|
23
|
+
render(): JSX.Element;
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export type Props = {
|
|
3
|
+
items: string[];
|
|
4
|
+
className?: string;
|
|
5
|
+
itemClassName?: string;
|
|
6
|
+
renderItem: (id: string, isActive: boolean) => ReactNode;
|
|
7
|
+
onDragStart?: (id: string) => void;
|
|
8
|
+
onDragEnd?: (id: string) => void;
|
|
9
|
+
onChange: (items: string[]) => void;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import { Size } from 'uilib/types';
|
|
3
|
+
type ContentProps = HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
className?: string;
|
|
5
|
+
};
|
|
6
|
+
export type Props = {
|
|
7
|
+
className?: string;
|
|
8
|
+
size?: Size;
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
header: ReactNode;
|
|
11
|
+
headerClassName?: string;
|
|
12
|
+
content: (props: ContentProps) => ReactNode | ReactNode;
|
|
13
|
+
contentProps?: ContentProps;
|
|
14
|
+
onChange?: (isOpen: boolean) => void;
|
|
15
|
+
};
|
|
16
|
+
export {};
|