@homecode/ui 4.19.3 → 4.19.5
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/dist/esm/index.js +1 -3
- package/dist/esm/src/components/Autocomplete/Autocomplete.js +4 -4
- package/dist/esm/src/components/Draggable/Draggable.js +79 -16
- package/dist/esm/src/components/Draggable/Draggable.styl.js +1 -1
- package/dist/esm/src/components/Input/Input.js +1 -1
- package/dist/esm/src/components/Shimmer/Shimmer.js +2 -2
- package/dist/esm/types/src/components/Draggable/Draggable.d.ts +4 -1
- package/dist/esm/types/src/components/Draggable/Draggable.types.d.ts +4 -2
- package/dist/esm/types/src/components/Shimmer/Shimmer.d.ts +2 -3
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -29,9 +29,7 @@ export { Router, RouterContext, RouterStore } from './src/components/Router/Rout
|
|
|
29
29
|
export { RequiredStar } from './src/components/RequiredStar/RequiredStar.js';
|
|
30
30
|
export { Select, SelectHelpers } from './src/components/Select/Select.js';
|
|
31
31
|
export { Scroll } from './src/components/Scroll/Scroll.js';
|
|
32
|
-
|
|
33
|
-
import 'classnames';
|
|
34
|
-
import './src/components/Shimmer/Shimmer.styl.js';
|
|
32
|
+
export { Shimmer } from './src/components/Shimmer/Shimmer.js';
|
|
35
33
|
export { Spinner } from './src/components/Spinner/Spinner.js';
|
|
36
34
|
export { Table } from './src/components/Table/Table.js';
|
|
37
35
|
export { Tabs } from './src/components/Tabs/Tabs.js';
|
|
@@ -2,10 +2,10 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import '../AssistiveText/AssistiveText.styl.js';
|
|
4
4
|
import { useState, useRef, useEffect, useMemo } from 'react';
|
|
5
|
+
import S from './Autocomplete.styl.js';
|
|
6
|
+
import { Shimmer } from '../Shimmer/Shimmer.js';
|
|
5
7
|
import debounce from '../../tools/debounce.js';
|
|
6
8
|
import { useIsMounted } from '../../hooks/useIsMounted.js';
|
|
7
|
-
import S from './Autocomplete.styl.js';
|
|
8
|
-
import Shimmer from '../Shimmer/Shimmer.js';
|
|
9
9
|
import { useListKeyboardControl } from '../../hooks/useListKeyboardControl.js';
|
|
10
10
|
import '../Spinner/Spinner.styl.js';
|
|
11
11
|
import '../Button/Button.styl.js';
|
|
@@ -30,8 +30,8 @@ import '../Container/Container.styl.js';
|
|
|
30
30
|
import '../DatePicker/DatePicker.styl.js';
|
|
31
31
|
import 'moment';
|
|
32
32
|
import '../DatePickerInput/DatePickerInput.styl.js';
|
|
33
|
-
import '../Draggable/Draggable.styl.js';
|
|
34
33
|
import '../../tools/queryParams.js';
|
|
34
|
+
import '../Draggable/Draggable.styl.js';
|
|
35
35
|
import '../Expand/Expand.styl.js';
|
|
36
36
|
import '../Form/Form.styl.js';
|
|
37
37
|
import '../Form/Validator.js';
|
|
@@ -64,7 +64,7 @@ function Autocomplete(props) {
|
|
|
64
64
|
const [isFocused, setIsFocused] = useState(false);
|
|
65
65
|
const currentRequest = useRef('');
|
|
66
66
|
const inputRef = useRef(null);
|
|
67
|
-
const isOpen =
|
|
67
|
+
const isOpen = options.length > 0;
|
|
68
68
|
const classes = cn(S.root, className);
|
|
69
69
|
const handleInputChange = (e, value) => {
|
|
70
70
|
const val = (value || e?.target.value) ?? '';
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { Component } from 'react';
|
|
3
|
-
import S from './Draggable.styl.js';
|
|
4
|
-
import Time from 'timen';
|
|
5
|
-
import cn from 'classnames';
|
|
6
|
-
import { createStore } from 'justorm/react';
|
|
7
2
|
import 'nanoid';
|
|
8
3
|
import '../../tools/dom.js';
|
|
9
|
-
import
|
|
4
|
+
import throttle from '../../tools/throttle.js';
|
|
5
|
+
import Time from 'timen';
|
|
10
6
|
import 'compareq';
|
|
11
7
|
import 'lodash.pick';
|
|
12
8
|
import '../../tools/queryParams.js';
|
|
9
|
+
import { Component } from 'react';
|
|
10
|
+
import S from './Draggable.styl.js';
|
|
11
|
+
import cn from 'classnames';
|
|
12
|
+
import { createStore } from 'justorm/react';
|
|
13
13
|
|
|
14
14
|
class Draggable extends Component {
|
|
15
15
|
store;
|
|
@@ -44,10 +44,9 @@ class Draggable extends Component {
|
|
|
44
44
|
document.addEventListener('pointermove', this.onPointerMove);
|
|
45
45
|
document.addEventListener('pointerup', this.onPointerUp);
|
|
46
46
|
};
|
|
47
|
-
onPointerMove =
|
|
47
|
+
onPointerMove = ({ clientX, clientY }) => {
|
|
48
48
|
if (!this.draggingElem)
|
|
49
49
|
return;
|
|
50
|
-
const { clientX: x, clientY: y } = e;
|
|
51
50
|
if (!this.store.draggingId) {
|
|
52
51
|
this.store.draggingId = this.draggingElem.dataset.id;
|
|
53
52
|
}
|
|
@@ -55,12 +54,12 @@ class Draggable extends Component {
|
|
|
55
54
|
this.dragStartFired = true;
|
|
56
55
|
this.props.onDragStart?.(this.store.draggingId);
|
|
57
56
|
}
|
|
58
|
-
const dx =
|
|
59
|
-
const dy =
|
|
57
|
+
const dx = clientX - this.startPos.x;
|
|
58
|
+
const dy = clientY - this.startPos.y;
|
|
60
59
|
this.transformInner(this.draggingElem, `translate(${dx}px, ${dy}px)`);
|
|
61
|
-
this.checkUnderElem(
|
|
60
|
+
this.checkUnderElem(clientX, clientY);
|
|
62
61
|
};
|
|
63
|
-
checkUnderElem =
|
|
62
|
+
checkUnderElem = throttle((x, y) => {
|
|
64
63
|
const underItem = document.elementFromPoint(x, y)?.closest(`.${S.item}`);
|
|
65
64
|
if (!underItem) {
|
|
66
65
|
this.store.underOffset = '';
|
|
@@ -70,12 +69,57 @@ class Draggable extends Component {
|
|
|
70
69
|
// @ts-ignore
|
|
71
70
|
const { id } = underItem.dataset;
|
|
72
71
|
const { draggingId, underId } = this.store;
|
|
72
|
+
const { isShifting, onChange } = this.props;
|
|
73
73
|
if (!this.startPos || id === draggingId || id === underId)
|
|
74
74
|
return;
|
|
75
75
|
const { x: x1, y: y1 } = this.draggingElemBounds;
|
|
76
76
|
const { x: x2, y: y2 } = this.selectInner(underItem).getBoundingClientRect();
|
|
77
77
|
const dx = x1 - x2;
|
|
78
78
|
const dy = y1 - y2;
|
|
79
|
+
if (isShifting) {
|
|
80
|
+
const items = [...this.props.items];
|
|
81
|
+
const dragIndex = items.indexOf(draggingId);
|
|
82
|
+
const underIndex = items.indexOf(id);
|
|
83
|
+
if (id !== underId) {
|
|
84
|
+
let newItems;
|
|
85
|
+
if (dragIndex < underIndex) {
|
|
86
|
+
// Moving forward: take items before dragIndex, then between dragIndex+1 and underIndex, then dragged item, then rest
|
|
87
|
+
newItems = [
|
|
88
|
+
...items.slice(0, dragIndex),
|
|
89
|
+
...items.slice(dragIndex + 1, underIndex + 1),
|
|
90
|
+
draggingId,
|
|
91
|
+
...items.slice(underIndex + 1),
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Moving backward: take items before underIndex, then dragged item, then between underIndex and dragIndex-1, then rest
|
|
96
|
+
newItems = [
|
|
97
|
+
...items.slice(0, underIndex),
|
|
98
|
+
draggingId,
|
|
99
|
+
...items.slice(underIndex, dragIndex),
|
|
100
|
+
...items.slice(dragIndex + 1),
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
onChange?.(newItems);
|
|
104
|
+
}
|
|
105
|
+
const direction = Math.sign(underIndex - dragIndex);
|
|
106
|
+
items.forEach((itemId, index) => {
|
|
107
|
+
if (itemId === draggingId)
|
|
108
|
+
return;
|
|
109
|
+
const elem = document.querySelector(`[data-id="${itemId}"]`);
|
|
110
|
+
if (!elem)
|
|
111
|
+
return;
|
|
112
|
+
if (direction > 0 && index > dragIndex && index <= underIndex) {
|
|
113
|
+
this.transformInner(elem, `translate(${-dx}px, ${-dy}px)`);
|
|
114
|
+
}
|
|
115
|
+
else if (direction < 0 && index < dragIndex && index >= underIndex) {
|
|
116
|
+
this.transformInner(elem, `translate(${dx}px, ${dy}px)`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this.transformInner(elem, null);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
79
123
|
this.store.underOffset = `translate(${dx}px, ${dy}px)`;
|
|
80
124
|
this.store.underId = id;
|
|
81
125
|
}, 100);
|
|
@@ -88,7 +132,7 @@ class Draggable extends Component {
|
|
|
88
132
|
};
|
|
89
133
|
onPointerUp = e => {
|
|
90
134
|
const { underId, draggingId } = this.store;
|
|
91
|
-
const {
|
|
135
|
+
const { onDragEnd, isShifting } = this.props;
|
|
92
136
|
const { id } = this.draggingElem.dataset;
|
|
93
137
|
if (draggingId) {
|
|
94
138
|
e.stopPropagation();
|
|
@@ -99,15 +143,25 @@ class Draggable extends Component {
|
|
|
99
143
|
this.dragStartFired = false;
|
|
100
144
|
this.startPos = null;
|
|
101
145
|
this.store.draggingId = null;
|
|
102
|
-
|
|
146
|
+
// Only call onChange if not in shifting mode
|
|
147
|
+
if (underId && !isShifting && this.props.onChange) {
|
|
103
148
|
const newItems = [...this.props.items];
|
|
104
149
|
const draggingIndex = newItems.indexOf(id);
|
|
105
150
|
const underIndex = newItems.indexOf(underId);
|
|
106
151
|
newItems[underIndex] = id;
|
|
107
152
|
newItems[draggingIndex] = underId;
|
|
108
|
-
onChange(newItems);
|
|
153
|
+
this.props.onChange(newItems);
|
|
109
154
|
}
|
|
110
155
|
this.dropUnder();
|
|
156
|
+
// Reset all item transforms
|
|
157
|
+
// if (this.props.isShifting) {
|
|
158
|
+
// this.props.items.forEach(itemId => {
|
|
159
|
+
// const elem = document.querySelector(`[data-id="${itemId}"]`);
|
|
160
|
+
// if (elem) {
|
|
161
|
+
// this.transformInner(elem, null);
|
|
162
|
+
// }
|
|
163
|
+
// });
|
|
164
|
+
// }
|
|
111
165
|
this.timers.after(100, () => {
|
|
112
166
|
if (this.draggingElem) {
|
|
113
167
|
this.selectInner(this.draggingElem).style.transform = null;
|
|
@@ -129,7 +183,16 @@ class Draggable extends Component {
|
|
|
129
183
|
render() {
|
|
130
184
|
const { items, className, itemClassName, renderItem, children } = this.props;
|
|
131
185
|
const { draggingId, underId, underOffset } = this.store;
|
|
132
|
-
return (jsxs("div", { className: cn(S.root, draggingId && S.dragging, className), children: [items.map((id, index) =>
|
|
186
|
+
return (jsxs("div", { className: cn(S.root, draggingId && S.dragging, className), children: [items.map((id, index) => {
|
|
187
|
+
const isDragging = id === draggingId;
|
|
188
|
+
const isUnder = id === underId;
|
|
189
|
+
return (jsx("div", { className: cn(S.item, itemClassName, isDragging && S.active), onPointerDown: this.onPointerDown, "data-id": id, children: jsx("div", { className: S.inner, style: isDragging || (!this.props.isShifting && isUnder)
|
|
190
|
+
? {
|
|
191
|
+
transform: isUnder ? underOffset : null,
|
|
192
|
+
transition: 'none',
|
|
193
|
+
}
|
|
194
|
+
: null, children: renderItem(id, index, isDragging) }) }, id));
|
|
195
|
+
}), children] }));
|
|
133
196
|
}
|
|
134
197
|
}
|
|
135
198
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import styleInject from '../../../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".Draggable_root__S1BgI{display:flex;flex-wrap:wrap;position:relative;touch-action:none}.Draggable_item__Z1pXk{display:flex}.Draggable_inner__c4syM{height:100%;transition:transform .2s ease-out;width:100%}.Draggable_dragging__M8qhF .
|
|
3
|
+
var css_248z = ".Draggable_root__S1BgI{display:flex;flex-wrap:wrap;position:relative;touch-action:none}.Draggable_item__Z1pXk{display:inline-flex;max-width:100px;width:100%}.Draggable_inner__c4syM{height:100%;transition:transform .2s ease-out;width:100%}.Draggable_dragging__M8qhF .Draggable_inner__c4syM{pointer-events:none}.Draggable_dragging__M8qhF .Draggable_active__XcFM3{pointer-events:none;z-index:1}.Draggable_dragging__M8qhF .Draggable_active__XcFM3 .Draggable_inner__c4syM{transition-duration:0s}";
|
|
4
4
|
var S = {"root":"Draggable_root__S1BgI","item":"Draggable_item__Z1pXk","inner":"Draggable_inner__c4syM","dragging":"Draggable_dragging__M8qhF","active":"Draggable_active__XcFM3"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
@@ -12,9 +12,9 @@ import { Scroll } from '../Scroll/Scroll.js';
|
|
|
12
12
|
import { capitalize } from '../../tools/string.js';
|
|
13
13
|
import { generateUID } from '../../tools/uid.js';
|
|
14
14
|
import S from './Input.styl.js';
|
|
15
|
-
import debounce from '../../tools/debounce.js';
|
|
16
15
|
import '../Autocomplete/Autocomplete.styl.js';
|
|
17
16
|
import '../Shimmer/Shimmer.styl.js';
|
|
17
|
+
import debounce from '../../tools/debounce.js';
|
|
18
18
|
import '../ButtonGroup/ButtonGroup.styl.js';
|
|
19
19
|
import '../Calendar/Calendar.styl.js';
|
|
20
20
|
import '../../tools/dom.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import cn from 'classnames';
|
|
3
2
|
import S from './Shimmer.styl.js';
|
|
3
|
+
import cn from 'classnames';
|
|
4
4
|
|
|
5
5
|
const Shimmer = ({ className, size = 'm' }) => (jsx("div", { className: cn(S.root, className, S[`size-${size}`]), children: jsx("div", { className: S.inner }) }));
|
|
6
6
|
|
|
7
|
-
export { Shimmer
|
|
7
|
+
export { Shimmer };
|
|
@@ -11,7 +11,10 @@ export declare class Draggable extends Component<T.Props> {
|
|
|
11
11
|
componentDidUpdate(prevProps: any): void;
|
|
12
12
|
componentWillUnmount(): void;
|
|
13
13
|
onPointerDown: (e: any) => void;
|
|
14
|
-
onPointerMove: (
|
|
14
|
+
onPointerMove: ({ clientX, clientY }: {
|
|
15
|
+
clientX: any;
|
|
16
|
+
clientY: any;
|
|
17
|
+
}) => void;
|
|
15
18
|
checkUnderElem: any;
|
|
16
19
|
onPointerOut: ({ target }: {
|
|
17
20
|
target: any;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
export
|
|
2
|
+
export interface Props {
|
|
3
3
|
items: string[];
|
|
4
4
|
className?: string;
|
|
5
5
|
itemClassName?: string;
|
|
6
|
+
isShifting?: boolean;
|
|
7
|
+
mode: 'swap' | 'push';
|
|
6
8
|
renderItem: (id: string, index: number, isActive: boolean) => ReactNode;
|
|
7
9
|
onDragStart?: (id: string) => void;
|
|
8
10
|
onDragEnd?: (id: string) => void;
|
|
9
11
|
onChange: (items: string[]) => void;
|
|
10
12
|
children?: ReactNode;
|
|
11
|
-
}
|
|
13
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Size } from 'uilib/types';
|
|
2
|
-
type ShimmerProps = {
|
|
2
|
+
export type ShimmerProps = {
|
|
3
3
|
className?: string;
|
|
4
4
|
size?: Size;
|
|
5
5
|
};
|
|
6
|
-
declare const Shimmer: ({ className, size }: ShimmerProps) => JSX.Element;
|
|
7
|
-
export default Shimmer;
|
|
6
|
+
export declare const Shimmer: ({ className, size }: ShimmerProps) => JSX.Element;
|