@startlibs/form 1.1.3 → 1.2.0-rc.2
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/lib/AutoComplete.mjs +7 -7
- package/lib/AutoComplete.mjs.map +1 -1
- package/lib/Checkbox.mjs +4 -2
- package/lib/Checkbox.mjs.map +1 -1
- package/lib/Combobox.mjs +1 -1
- package/lib/Combobox.mjs.map +1 -1
- package/lib/DatePicker.mjs +25 -9
- package/lib/DatePicker.mjs.map +1 -1
- package/lib/Errors.mjs +20 -10
- package/lib/Errors.mjs.map +1 -1
- package/lib/ExpandableBox.mjs +1 -1
- package/lib/ExpandableBox.mjs.map +1 -1
- package/lib/Field.mjs +10 -5
- package/lib/Field.mjs.map +1 -1
- package/lib/FieldBox.mjs +3 -3
- package/lib/FieldBox.mjs.map +1 -1
- package/lib/InputboxGroup.mjs +1 -1
- package/lib/InputboxGroup.mjs.map +1 -1
- package/lib/RichText.mjs +11 -6
- package/lib/RichText.mjs.map +1 -1
- package/lib/TextInput.mjs +4 -4
- package/lib/TextInput.mjs.map +1 -1
- package/lib/alt/checkbox/SimpleCheckbox.mjs +1 -1
- package/lib/alt/checkbox/SimpleCheckbox.mjs.map +1 -1
- package/lib/alt/checkbox/ToggleCheckbox.mjs +4 -3
- package/lib/alt/checkbox/ToggleCheckbox.mjs.map +1 -1
- package/lib/alt/radiobox/CleanTabRadiobox.mjs +1 -1
- package/lib/alt/radiobox/CleanTabRadiobox.mjs.map +1 -1
- package/lib/alt/radiobox/SimpleRadiobox.mjs +2 -2
- package/lib/alt/radiobox/SimpleRadiobox.mjs.map +1 -1
- package/lib/alt/radiobox/TabRadiobox.mjs +1 -1
- package/lib/alt/radiobox/TabRadiobox.mjs.map +1 -1
- package/lib/index.cjs +94 -51
- package/lib/index.cjs.map +1 -1
- package/lib/index.mjs +2 -2
- package/lib/withFormImageInput.mjs +1 -1
- package/lib/withFormImageInput.mjs.map +1 -1
- package/lib-yak/AutoComplete.mjs +705 -0
- package/lib-yak/AutoComplete.mjs.map +1 -0
- package/lib-yak/Checkbox.mjs +80 -0
- package/lib-yak/Checkbox.mjs.map +1 -0
- package/lib-yak/Combobox.mjs +652 -0
- package/lib-yak/Combobox.mjs.map +1 -0
- package/lib-yak/ComboboxWithCustom.mjs +77 -0
- package/lib-yak/ComboboxWithCustom.mjs.map +1 -0
- package/lib-yak/DatePicker.mjs +774 -0
- package/lib-yak/DatePicker.mjs.map +1 -0
- package/lib-yak/EditableBox.mjs +495 -0
- package/lib-yak/EditableBox.mjs.map +1 -0
- package/lib-yak/Errors.mjs +226 -0
- package/lib-yak/Errors.mjs.map +1 -0
- package/lib-yak/ExpandableBox.mjs +247 -0
- package/lib-yak/ExpandableBox.mjs.map +1 -0
- package/lib-yak/Field.mjs +93 -0
- package/lib-yak/Field.mjs.map +1 -0
- package/lib-yak/FieldBox.mjs +173 -0
- package/lib-yak/FieldBox.mjs.map +1 -0
- package/lib-yak/Form.mjs +322 -0
- package/lib-yak/Form.mjs.map +1 -0
- package/lib-yak/FormValue.mjs +111 -0
- package/lib-yak/FormValue.mjs.map +1 -0
- package/lib-yak/InputboxGroup.mjs +146 -0
- package/lib-yak/InputboxGroup.mjs.map +1 -0
- package/lib-yak/Radiobox.mjs +69 -0
- package/lib-yak/Radiobox.mjs.map +1 -0
- package/lib-yak/RichText.mjs +776 -0
- package/lib-yak/RichText.mjs.map +1 -0
- package/lib-yak/TextInput.mjs +589 -0
- package/lib-yak/TextInput.mjs.map +1 -0
- package/lib-yak/alt/checkbox/SimpleCheckbox.mjs +225 -0
- package/lib-yak/alt/checkbox/SimpleCheckbox.mjs.map +1 -0
- package/lib-yak/alt/checkbox/ToggleCheckbox.mjs +173 -0
- package/lib-yak/alt/checkbox/ToggleCheckbox.mjs.map +1 -0
- package/lib-yak/alt/radiobox/CleanTabRadiobox.mjs +87 -0
- package/lib-yak/alt/radiobox/CleanTabRadiobox.mjs.map +1 -0
- package/lib-yak/alt/radiobox/IconRadioBox.mjs +138 -0
- package/lib-yak/alt/radiobox/IconRadioBox.mjs.map +1 -0
- package/lib-yak/alt/radiobox/SimpleRadiobox.mjs +203 -0
- package/lib-yak/alt/radiobox/SimpleRadiobox.mjs.map +1 -0
- package/lib-yak/alt/radiobox/TabRadiobox.mjs +117 -0
- package/lib-yak/alt/radiobox/TabRadiobox.mjs.map +1 -0
- package/lib-yak/enhanceInput.mjs +131 -0
- package/lib-yak/enhanceInput.mjs.map +1 -0
- package/lib-yak/index.mjs +28 -0
- package/lib-yak/index.mjs.map +1 -0
- package/lib-yak/useConfirmDialog.mjs +117 -0
- package/lib-yak/useConfirmDialog.mjs.map +1 -0
- package/lib-yak/useDraftConfirmation.mjs +56 -0
- package/lib-yak/useDraftConfirmation.mjs.map +1 -0
- package/lib-yak/validation.mjs +91 -0
- package/lib-yak/validation.mjs.map +1 -0
- package/lib-yak/withFormImageInput.mjs +298 -0
- package/lib-yak/withFormImageInput.mjs.map +1 -0
- package/package.json +13 -3
- package/src/AutoComplete.jsx +12 -12
- package/src/Checkbox.jsx +2 -2
- package/src/Combobox.jsx +1 -1
- package/src/DatePicker.jsx +25 -22
- package/src/Errors.jsx +18 -8
- package/src/ExpandableBox.jsx +3 -3
- package/src/Field.jsx +9 -4
- package/src/FieldBox.jsx +6 -6
- package/src/IconRadioBoxOldHubt.jsx +1 -1
- package/src/InputboxGroup.jsx +1 -1
- package/src/RichText.jsx +17 -13
- package/src/TextInput.jsx +37 -26
- package/src/alt/checkbox/SimpleCheckbox.jsx +5 -5
- package/src/alt/checkbox/ToggleCheckbox.jsx +9 -8
- package/src/alt/radiobox/CleanTabRadiobox.jsx +2 -2
- package/src/alt/radiobox/SimpleRadiobox.jsx +7 -7
- package/src/alt/radiobox/TabRadiobox.jsx +4 -4
- package/src/withFormImageInput.jsx +2 -2
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
|
+
import _isString from 'lodash/fp/isString';
|
|
5
|
+
import _isFinite from 'lodash/fp/isFinite';
|
|
6
|
+
import _sortBy from 'lodash/fp/sortBy';
|
|
7
|
+
import _filter from 'lodash/fp/filter';
|
|
8
|
+
import _flow from 'lodash/fp/flow';
|
|
9
|
+
import _identity from 'lodash/fp/identity';
|
|
10
|
+
import { yakDomTag } from '@startlibs/utils/yakDomTag';
|
|
11
|
+
import React, { useRef, useEffect, useMemo } from 'react';
|
|
12
|
+
import { styled, css } from '@yak/react';
|
|
13
|
+
import { FixedSizeList } from 'react-window';
|
|
14
|
+
import { ContextListMenu, ListItem, Icon, Loading, willUseIsSticky, usePositioning, getDialogLayersSize, ListSeparator } from '@startlibs/components';
|
|
15
|
+
import { useRefState, useEnsureRef, useToggle, useLazyConstant, useUpdateEffect, Fill } from '@startlibs/core';
|
|
16
|
+
import { getColor, getUID, normalizeText, callIfFunction, ifUndefined } from '@startlibs/utils';
|
|
17
|
+
import { Field } from './Field.mjs';
|
|
18
|
+
import { TextInput } from './TextInput.mjs';
|
|
19
|
+
import { useInput } from './enhanceInput.mjs';
|
|
20
|
+
|
|
21
|
+
const _excluded = ["getLabel", "getLabelAs", "getBoxLabelAs", "getIcon", "scrollContainer", "className", "options", "autoFocus", "autoOpenMenu", "mandatory", "placeholder", "disabled", "fieldValue", "label", "path", "withWindowing", "tabIndex", "fieldClassName", "descText", "helpText", "raw", "digitable", "digitableConstraint", "digitableAsOption", "suggestive", "onDigitableChange", "footerOptions", "isLoading", "isOptionDisabled", "menuRef", "overrideSetValue", "transformOnSelect", "check"],
|
|
22
|
+
_excluded2 = ["setValue", "icon", "option", "onHover", "checked", "label", "setRef"];
|
|
23
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
24
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
25
|
+
const ComboboxMenu = styled(ContextListMenu).attrs({
|
|
26
|
+
className: "styled-combobox-menu"
|
|
27
|
+
})`
|
|
28
|
+
z-index: 100;
|
|
29
|
+
background-color: white;
|
|
30
|
+
border-radius: 4px 4px 6px 6px;
|
|
31
|
+
margin-top: -1px;
|
|
32
|
+
margin-bottom: 0.5rem;
|
|
33
|
+
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 10px -2px rgba(0,0,0,0.15), 0 1px 2px 0px rgba(0,0,0,0.2);
|
|
34
|
+
border: 1px solid #b4b4b4;
|
|
35
|
+
max-height: 25rem;
|
|
36
|
+
width: auto;
|
|
37
|
+
${ListItem} > * {
|
|
38
|
+
font-size: 13px;
|
|
39
|
+
}
|
|
40
|
+
@media (max-width: 600px) {
|
|
41
|
+
${ListItem} > * {
|
|
42
|
+
font-size: 14px;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
${props => props.withoutIcons && css`
|
|
46
|
+
${ListItem} > * {
|
|
47
|
+
padding-left: 1.25rem;
|
|
48
|
+
padding-right: 1.25rem;
|
|
49
|
+
}
|
|
50
|
+
`}
|
|
51
|
+
${props => props.withWindowing && css`
|
|
52
|
+
overflow: hidden;
|
|
53
|
+
padding: 0;
|
|
54
|
+
`}
|
|
55
|
+
`;
|
|
56
|
+
const ComboboxInput = styled(yakDomTag("div")).attrs({
|
|
57
|
+
className: "styled-combobox-input"
|
|
58
|
+
})`
|
|
59
|
+
width: 100%;
|
|
60
|
+
font-size: 14px;
|
|
61
|
+
border: 1px solid ${__yakProps => {
|
|
62
|
+
const v = getColor('gray210');
|
|
63
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
64
|
+
}};
|
|
65
|
+
border-radius: 8px;
|
|
66
|
+
color: ${__yakProps => {
|
|
67
|
+
const v = getColor('gray60');
|
|
68
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
69
|
+
}};
|
|
70
|
+
background: white;
|
|
71
|
+
position: relative;
|
|
72
|
+
display: block;
|
|
73
|
+
min-height: 3rem;
|
|
74
|
+
padding: 0.5rem 2.5rem 0.5rem 0.7rem;
|
|
75
|
+
overflow: auto;
|
|
76
|
+
outline: 0;
|
|
77
|
+
outline: none;
|
|
78
|
+
cursor: pointer;
|
|
79
|
+
user-select: none;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
word-break: break-word;
|
|
84
|
+
${props => props.suggestive && css`
|
|
85
|
+
padding-right: 0.7rem;
|
|
86
|
+
`}
|
|
87
|
+
@media (max-width: 600px) {
|
|
88
|
+
min-height: 42px;
|
|
89
|
+
padding-left: 1rem;
|
|
90
|
+
${props => props.suggestive && css`
|
|
91
|
+
padding-right: 1rem;
|
|
92
|
+
`}
|
|
93
|
+
}
|
|
94
|
+
${props => props.isFocused && css`
|
|
95
|
+
border-color: ${__yakProps => {
|
|
96
|
+
const v = getColor('gray180');
|
|
97
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
98
|
+
}};
|
|
99
|
+
box-shadow: 0px 0px 0px 2px rgba(0,0,0,0.1);
|
|
100
|
+
`}
|
|
101
|
+
&:focus {
|
|
102
|
+
border-color: ${__yakProps => {
|
|
103
|
+
const v = getColor('gray180');
|
|
104
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
105
|
+
}};
|
|
106
|
+
box-shadow: 0px 0px 0px 2px rgba(0,0,0,0.1);
|
|
107
|
+
}
|
|
108
|
+
${props => props.hasErrors && css`
|
|
109
|
+
border-color: ${__yakProps => {
|
|
110
|
+
const v = getColor('alert');
|
|
111
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
112
|
+
}} !important;
|
|
113
|
+
`}
|
|
114
|
+
input {
|
|
115
|
+
position: absolute;
|
|
116
|
+
top: -1px;
|
|
117
|
+
left: 0;
|
|
118
|
+
border: none;
|
|
119
|
+
${props => !props.suggestive && css`
|
|
120
|
+
padding-right: 2.5rem;
|
|
121
|
+
`}
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
const ComboboxDropdownIcon = styled(Icon)`
|
|
125
|
+
position: absolute;
|
|
126
|
+
top: 51%;
|
|
127
|
+
transform: translateY(-50%);
|
|
128
|
+
right: 1rem;
|
|
129
|
+
color: ${__yakProps => {
|
|
130
|
+
const v = getColor('gray60');
|
|
131
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
132
|
+
}};
|
|
133
|
+
`;
|
|
134
|
+
const FooterOptionsContainer = styled(yakDomTag("div"))`
|
|
135
|
+
background: white;
|
|
136
|
+
border-top: 1px solid rgba(0,0,0,0.1);
|
|
137
|
+
padding: 0;
|
|
138
|
+
${props => !props.hasWindoning && css`
|
|
139
|
+
padding: 0.5rem 0;
|
|
140
|
+
margin: 0.5rem 0 -0.5rem;
|
|
141
|
+
bottom: -0.5rem;
|
|
142
|
+
position: sticky;
|
|
143
|
+
`}
|
|
144
|
+
`;
|
|
145
|
+
const ComboboxPlaceholder = styled(yakDomTag("div"))`
|
|
146
|
+
color: rgba(0,0,0,0.3);
|
|
147
|
+
`;
|
|
148
|
+
const ComboboxLoading = styled(Loading)`
|
|
149
|
+
bottom: 6px;
|
|
150
|
+
right: 0.6rem;
|
|
151
|
+
left: auto;
|
|
152
|
+
top: auto;
|
|
153
|
+
@media (max-width: 600px) {
|
|
154
|
+
bottom: 9px;
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
const SEPARATOR = {};
|
|
158
|
+
const NO_DIGITABLE_FOUND = "Nenhum resultado encontrado";
|
|
159
|
+
//shouldRecenter?
|
|
160
|
+
const Combobox = styled(/*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
161
|
+
let {
|
|
162
|
+
getLabel = _identity,
|
|
163
|
+
getLabelAs,
|
|
164
|
+
getBoxLabelAs,
|
|
165
|
+
getIcon,
|
|
166
|
+
scrollContainer = el => el.closest('.dialog-container') || document.body,
|
|
167
|
+
className,
|
|
168
|
+
options,
|
|
169
|
+
autoFocus,
|
|
170
|
+
autoOpenMenu,
|
|
171
|
+
mandatory,
|
|
172
|
+
placeholder,
|
|
173
|
+
disabled,
|
|
174
|
+
fieldValue,
|
|
175
|
+
label,
|
|
176
|
+
path,
|
|
177
|
+
withWindowing,
|
|
178
|
+
tabIndex = 1,
|
|
179
|
+
fieldClassName,
|
|
180
|
+
descText,
|
|
181
|
+
helpText,
|
|
182
|
+
raw,
|
|
183
|
+
digitable,
|
|
184
|
+
digitableConstraint,
|
|
185
|
+
digitableAsOption,
|
|
186
|
+
suggestive,
|
|
187
|
+
onDigitableChange,
|
|
188
|
+
footerOptions,
|
|
189
|
+
isLoading,
|
|
190
|
+
isOptionDisabled,
|
|
191
|
+
menuRef,
|
|
192
|
+
overrideSetValue,
|
|
193
|
+
transformOnSelect = _identity,
|
|
194
|
+
check = (a, b) => a === b
|
|
195
|
+
} = _ref,
|
|
196
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
197
|
+
const selectedElement = useRef();
|
|
198
|
+
const selectedElementIndex = useRef();
|
|
199
|
+
const fieldRef = useRef();
|
|
200
|
+
const windowingRef = useRef();
|
|
201
|
+
const skipFocus = useRefState(autoFocus);
|
|
202
|
+
const skipHover = useRefState();
|
|
203
|
+
const skipDigitableSetValue = useRefState();
|
|
204
|
+
const listElement = useEnsureRef(menuRef);
|
|
205
|
+
const container = useEnsureRef(ref);
|
|
206
|
+
const keyState = useRefState();
|
|
207
|
+
const contextMenu = useToggle(false);
|
|
208
|
+
const hover = useToggle();
|
|
209
|
+
const strongHover = useRefState();
|
|
210
|
+
const scrollToVisibility = useToggle();
|
|
211
|
+
const autoCompleteUID = useLazyConstant(() => getUID());
|
|
212
|
+
const [formValue, confirmValue, {
|
|
213
|
+
hasErrors
|
|
214
|
+
}] = useInput(_objectSpread({
|
|
215
|
+
fieldValue,
|
|
216
|
+
path
|
|
217
|
+
}, rest), raw);
|
|
218
|
+
const value = useToggle(formValue);
|
|
219
|
+
const setValue = v => {
|
|
220
|
+
value.openWith(v);
|
|
221
|
+
};
|
|
222
|
+
const digitableValue = useToggle(getLabel(value.isOpen));
|
|
223
|
+
const digitableRef = useRef();
|
|
224
|
+
const ignoringFilter = useToggle();
|
|
225
|
+
const setHover = v => {
|
|
226
|
+
hover.openWith(v);
|
|
227
|
+
if (digitable) {
|
|
228
|
+
strongHover.set(hover.get());
|
|
229
|
+
} else {
|
|
230
|
+
setValue(v);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
React.useLayoutEffect(() => {
|
|
234
|
+
if (digitable && !skipDigitableSetValue.get()) {
|
|
235
|
+
if (contextMenu.isOpen) {
|
|
236
|
+
digitableRef.current.select();
|
|
237
|
+
if (value.get() && !suggestive) {
|
|
238
|
+
setHover(transformOnSelect(value.get()));
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
digitableValue.openWith(getLabel(value.get()));
|
|
242
|
+
strongHover.set(hover.get());
|
|
243
|
+
hover.close();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
skipDigitableSetValue.set(false);
|
|
247
|
+
}, [contextMenu.isOpen]);
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
contextMenu.isOpen && recenterScroll();
|
|
250
|
+
}, [contextMenu.isOpen]);
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
selectedElement.current && scrollToVisibility.isOpen && makeOptionVisible();
|
|
253
|
+
}, [hover]);
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
var _container$current;
|
|
256
|
+
autoFocus && ((_container$current = container.current) === null || _container$current === void 0 ? void 0 : _container$current.focus());
|
|
257
|
+
}, []);
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
autoOpenMenu && toggleCombobox();
|
|
260
|
+
}, []);
|
|
261
|
+
useUpdateEffect(() => {
|
|
262
|
+
if (value.isOpen !== formValue && !contextMenu.isOpen) {
|
|
263
|
+
confirmValue(value.isOpen);
|
|
264
|
+
}
|
|
265
|
+
}, [!!contextMenu.isOpen]);
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
if (formValue !== value.isOpen) {
|
|
268
|
+
setValue(formValue);
|
|
269
|
+
}
|
|
270
|
+
if (digitable) {
|
|
271
|
+
digitableValue.openWith(prev => prev !== getLabel(formValue) ? getLabel(formValue) : prev);
|
|
272
|
+
}
|
|
273
|
+
}, [formValue]);
|
|
274
|
+
const filteredOptions = useMemo(() => _flow(_filter(v => {
|
|
275
|
+
if (!digitable || !digitableValue.isOpen || ignoringFilter.isOpen) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
return normalizeText(getLabel(v)).includes(normalizeText(digitableValue.isOpen));
|
|
279
|
+
}), _sortBy(v => normalizeText(getLabel(v)).indexOf(normalizeText(digitableValue.isOpen)) > 0))(options), [options, digitable, digitableValue.isOpen, ignoringFilter.isOpen]);
|
|
280
|
+
const digitableOption = useMemo(() => {
|
|
281
|
+
const option = filteredOptions.length < 8 && digitableAsOption && !!digitableValue.isOpen && callIfFunction(digitableAsOption, digitableValue.isOpen);
|
|
282
|
+
return option || !filteredOptions.length && digitable && !suggestive && NO_DIGITABLE_FOUND;
|
|
283
|
+
}, [digitableValue.isOpen, filteredOptions.length]);
|
|
284
|
+
const availableOptions = filteredOptions.concat(digitableOption || []);
|
|
285
|
+
const allOptions = availableOptions.concat(footerOptions || []).filter(v => v !== SEPARATOR);
|
|
286
|
+
const withPlaceholder = !value.isOpen && value.isOpen !== 0 && placeholder;
|
|
287
|
+
useUpdateEffect(() => {
|
|
288
|
+
if (suggestive || !digitable) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (hover.isOpen) {
|
|
292
|
+
setHover(allOptions[0] === NO_DIGITABLE_FOUND ? allOptions[1] : allOptions[0]);
|
|
293
|
+
} else if (digitableValue.isOpen) {
|
|
294
|
+
setHover(ifUndefined(value.isOpen, allOptions[0]));
|
|
295
|
+
}
|
|
296
|
+
}, [digitableValue.isOpen]);
|
|
297
|
+
const toggleCombobox = () => {
|
|
298
|
+
if (contextMenu.isOpen) {
|
|
299
|
+
contextMenu.close();
|
|
300
|
+
} else {
|
|
301
|
+
contextMenu.open();
|
|
302
|
+
}
|
|
303
|
+
hover.close();
|
|
304
|
+
};
|
|
305
|
+
const getCurrentHeight = () => {
|
|
306
|
+
var _listElement$current$;
|
|
307
|
+
return listElement.current.offsetHeight - (((_listElement$current$ = listElement.current.querySelector(".JS-list-footer")) === null || _listElement$current$ === void 0 ? void 0 : _listElement$current$.offsetHeight) || 0);
|
|
308
|
+
};
|
|
309
|
+
const recenterScroll = () => {
|
|
310
|
+
if (withWindowing) {
|
|
311
|
+
const index = hover.get() ? availableOptions.indexOf(hover.get()) : selectedElementIndex.current;
|
|
312
|
+
if (windowingRef.current) {
|
|
313
|
+
windowingRef.current.scrollToItem(_isFinite(index) ? index : availableOptions.map(getLabel).indexOf(getLabel(value.get())) || 0, "center");
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
if (!listElement.current) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (listElement.current.getBoundingClientRect().bottom > window.innerHeight) {
|
|
320
|
+
const currentScrollContainer = scrollContainer(container.current);
|
|
321
|
+
currentScrollContainer.scrollTop = listElement.current.getBoundingClientRect().bottom + currentScrollContainer.scrollTop - window.innerHeight;
|
|
322
|
+
}
|
|
323
|
+
if (selectedElement.current) {
|
|
324
|
+
listElement.current.scrollTop = selectedElement.current.offsetTop + selectedElement.current.offsetHeight / 2 - getCurrentHeight() / 2;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const makeOptionVisible = () => {
|
|
329
|
+
if (withWindowing) {
|
|
330
|
+
if (windowingRef.current) {
|
|
331
|
+
windowingRef.current.scrollToItem(selectedElementIndex.current || 0);
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
if (footerOptions && (footerOptions === null || footerOptions === void 0 ? void 0 : footerOptions.indexOf(hover.isOpen)) >= 0 || !listElement.current) {
|
|
335
|
+
return;
|
|
336
|
+
} else if (selectedElement.current.offsetTop < listElement.current.scrollTop) {
|
|
337
|
+
skipHover.set(true);
|
|
338
|
+
listElement.current.scrollTop = selectedElement.current.offsetTop;
|
|
339
|
+
} else if (selectedElement.current.offsetTop + selectedElement.current.offsetHeight > listElement.current.scrollTop + getCurrentHeight()) {
|
|
340
|
+
skipHover.set(true);
|
|
341
|
+
listElement.current.scrollTop = selectedElement.current.offsetTop + selectedElement.current.offsetHeight - getCurrentHeight();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
const handleHover = (value, e) => {
|
|
346
|
+
if (skipHover.get()) {
|
|
347
|
+
skipHover.set(false);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
scrollToVisibility.close();
|
|
351
|
+
hover.openWith(value);
|
|
352
|
+
};
|
|
353
|
+
const digitableKeyDown = e => {
|
|
354
|
+
if (e.key.length == 1 || e.key == "Spacebar") {
|
|
355
|
+
e.stopPropagation();
|
|
356
|
+
} else if (e.key === 'Tab' || e.key === 'Enter') {
|
|
357
|
+
if (suggestive && allOptions.indexOf(strongHover.get()) < 0) {
|
|
358
|
+
if (allOptions.indexOf(value.isOpen) >= 0) {
|
|
359
|
+
setValue(transformOnSelect(value.isOpen));
|
|
360
|
+
} else {
|
|
361
|
+
setValue(transformOnSelect(callIfFunction(digitableAsOption, digitableValue.get()) || digitableValue.get()));
|
|
362
|
+
}
|
|
363
|
+
} else if (strongHover.get() === hover.get()) {
|
|
364
|
+
setValue(transformOnSelect(strongHover.get()));
|
|
365
|
+
}
|
|
366
|
+
if (e.key === "Enter") {
|
|
367
|
+
skipFocus.set(true);
|
|
368
|
+
container.current.focus();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
const keyDown = e => {
|
|
373
|
+
if (e.getModifierState('Shift') && e.key === 'Tab') {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if ((e.key === 'Escape' || e.key === 'Tab') && contextMenu.isOpen) {
|
|
377
|
+
e.stopPropagation();
|
|
378
|
+
toggleCombobox();
|
|
379
|
+
}
|
|
380
|
+
if (e.key.length === 1) {
|
|
381
|
+
e.stopPropagation();
|
|
382
|
+
if (!contextMenu.isOpen) {
|
|
383
|
+
contextMenu.open();
|
|
384
|
+
if (digitable) {
|
|
385
|
+
skipDigitableSetValue.set(true);
|
|
386
|
+
digitableValue.openWith(e.key);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const prevKeyState = keyState.get();
|
|
391
|
+
const repeated = !prevKeyState || e.key === prevKeyState.word[0] && prevKeyState.repeated;
|
|
392
|
+
const word = ((prevKeyState === null || prevKeyState === void 0 ? void 0 : prevKeyState.word) || '') + e.key;
|
|
393
|
+
clearTimeout((prevKeyState === null || prevKeyState === void 0 ? void 0 : prevKeyState.timeout) || -1);
|
|
394
|
+
const timeout = setTimeout(() => keyState.set(null), 1000);
|
|
395
|
+
keyState.set({
|
|
396
|
+
repeated,
|
|
397
|
+
word,
|
|
398
|
+
timeout
|
|
399
|
+
});
|
|
400
|
+
const labels = allOptions.map(o => {
|
|
401
|
+
const label = getLabel(o);
|
|
402
|
+
return _isString(label) ? label.slice(0, repeated ? 1 : word.length).toLowerCase() : "";
|
|
403
|
+
});
|
|
404
|
+
const goTo = index => {
|
|
405
|
+
scrollToVisibility.open();
|
|
406
|
+
setHover(allOptions[index]);
|
|
407
|
+
};
|
|
408
|
+
const currentIndex = allOptions.indexOf(hover.isOpen !== false ? hover.isOpen : value.isOpen);
|
|
409
|
+
const direction = repeated ? e.shiftKey ? -1 : 1 : 0;
|
|
410
|
+
const fnName = direction < 0 ? 'lastIndexOf' : 'indexOf';
|
|
411
|
+
const item = repeated ? word.slice(0, 1) : word;
|
|
412
|
+
const fromIndex = (currentIndex || (direction < 0 ? labels.length - 1 : 0)) + direction;
|
|
413
|
+
const next = labels[fnName](item, fromIndex);
|
|
414
|
+
if (next >= 0) {
|
|
415
|
+
goTo(next);
|
|
416
|
+
} else {
|
|
417
|
+
const next = labels[fnName](item);
|
|
418
|
+
if (next >= 0) {
|
|
419
|
+
goTo(next);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (['ArrowUp', 'ArrowDown', ' ', 'Enter'].indexOf(e.key) < 0) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
e.stopPropagation();
|
|
427
|
+
e.preventDefault();
|
|
428
|
+
if (contextMenu.isOpen) {
|
|
429
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
430
|
+
const oldValue = hover.isOpen !== false ? hover.isOpen : value.isOpen;
|
|
431
|
+
const previousIndex = allOptions.indexOf(oldValue);
|
|
432
|
+
const newIndex = Math.min(Math.max((previousIndex + allOptions.length + (e.key === 'ArrowUp' ? previousIndex < 0 ? 0 : -1 : 1)) % allOptions.length, 0), allOptions.length - 1);
|
|
433
|
+
scrollToVisibility.open();
|
|
434
|
+
setHover(allOptions[newIndex]);
|
|
435
|
+
} else {
|
|
436
|
+
if (hover.isOpen !== false) {
|
|
437
|
+
setValue(transformOnSelect(hover.isOpen));
|
|
438
|
+
}
|
|
439
|
+
toggleCombobox();
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
toggleCombobox();
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const createOption = (option, i, props, opts) => {
|
|
446
|
+
if (option === SEPARATOR) {
|
|
447
|
+
return /*#__PURE__*/React.createElement(ListSeparator, {
|
|
448
|
+
key: "separator" + i
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
if (option === NO_DIGITABLE_FOUND) {
|
|
452
|
+
return /*#__PURE__*/React.createElement(Option, {
|
|
453
|
+
key: NO_DIGITABLE_FOUND + i,
|
|
454
|
+
disabled: true,
|
|
455
|
+
label: NO_DIGITABLE_FOUND
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
const label = getLabel(option, {
|
|
459
|
+
option: true
|
|
460
|
+
});
|
|
461
|
+
const checked = hover.isOpen !== false ? check(option, hover.isOpen) : check(option, value.isOpen);
|
|
462
|
+
if (checked) {
|
|
463
|
+
selectedElementIndex.current = i;
|
|
464
|
+
}
|
|
465
|
+
return /*#__PURE__*/React.createElement(Option, _extends({
|
|
466
|
+
key: label + i,
|
|
467
|
+
option: option,
|
|
468
|
+
disabled: callIfFunction(isOptionDisabled, option, label),
|
|
469
|
+
icon: callIfFunction(getIcon, option),
|
|
470
|
+
checked: checked,
|
|
471
|
+
label: getLabelAs ? getLabelAs(option) : label,
|
|
472
|
+
setValue: v => {
|
|
473
|
+
if (!callIfFunction(overrideSetValue, v, {
|
|
474
|
+
setValue,
|
|
475
|
+
close: contextMenu.close
|
|
476
|
+
})) {
|
|
477
|
+
setValue(transformOnSelect(v));
|
|
478
|
+
digitableValue.openWith(getLabel(v));
|
|
479
|
+
contextMenu.close();
|
|
480
|
+
}
|
|
481
|
+
skipFocus.set(true);
|
|
482
|
+
container.current.focus();
|
|
483
|
+
},
|
|
484
|
+
setRef: selectedElement,
|
|
485
|
+
onHover: handleHover
|
|
486
|
+
}, props));
|
|
487
|
+
};
|
|
488
|
+
const onClickInput = () => {
|
|
489
|
+
if (digitableRef.current && !contextMenu.get()) {
|
|
490
|
+
digitableRef.current.select();
|
|
491
|
+
}
|
|
492
|
+
if (!suggestive) {
|
|
493
|
+
ignoringFilter.open();
|
|
494
|
+
}
|
|
495
|
+
contextMenu.open();
|
|
496
|
+
};
|
|
497
|
+
const onFocus = e => {
|
|
498
|
+
var _listElement$current;
|
|
499
|
+
if ((_listElement$current = listElement.current) !== null && _listElement$current !== void 0 && _listElement$current.contains(e.target) || skipFocus.get()) {
|
|
500
|
+
skipFocus.set(false);
|
|
501
|
+
} else {
|
|
502
|
+
if (!suggestive) {
|
|
503
|
+
ignoringFilter.open();
|
|
504
|
+
}
|
|
505
|
+
contextMenu.open();
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
const onBlur = e => {
|
|
509
|
+
var _listElement$current2;
|
|
510
|
+
if (!((_listElement$current2 = listElement.current) !== null && _listElement$current2 !== void 0 && _listElement$current2.contains(e.relatedTarget))) {
|
|
511
|
+
if (!availableOptions.length && digitableAsOption && digitableValue.get()) {
|
|
512
|
+
setValue(transformOnSelect(callIfFunction(digitableAsOption, digitableValue.get())));
|
|
513
|
+
} else if (suggestive) {
|
|
514
|
+
setValue(transformOnSelect(callIfFunction(digitableAsOption, digitableValue.get()) || digitableValue.get()));
|
|
515
|
+
} else if (formValue !== value.isOpen) {
|
|
516
|
+
confirmValue(value.isOpen);
|
|
517
|
+
}
|
|
518
|
+
contextMenu.close();
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
return /*#__PURE__*/React.createElement(Field, {
|
|
522
|
+
className: fieldClassName,
|
|
523
|
+
mandatory: mandatory,
|
|
524
|
+
descText: descText,
|
|
525
|
+
helpText: helpText,
|
|
526
|
+
label: label,
|
|
527
|
+
labelClick: toggleCombobox,
|
|
528
|
+
ref: fieldRef
|
|
529
|
+
}, /*#__PURE__*/React.createElement(ComboboxInput, {
|
|
530
|
+
onBlur: onBlur,
|
|
531
|
+
onFocus: onFocus,
|
|
532
|
+
onClick: onClickInput,
|
|
533
|
+
ref: container,
|
|
534
|
+
tabIndex: contextMenu.isOpen && digitable ? '-1' : tabIndex,
|
|
535
|
+
onKeyDown: keyDown,
|
|
536
|
+
disabled: disabled,
|
|
537
|
+
withPlaceholder: withPlaceholder,
|
|
538
|
+
hasErrors: hasErrors,
|
|
539
|
+
comboboxIsOpen: contextMenu.isOpen,
|
|
540
|
+
isFocused: digitable && !!contextMenu.isOpen,
|
|
541
|
+
suggestive: suggestive
|
|
542
|
+
}, digitable && !!contextMenu.isOpen ? /*#__PURE__*/React.createElement(TextInput, {
|
|
543
|
+
raw: true,
|
|
544
|
+
tabIndex: tabIndex,
|
|
545
|
+
autoFocus: true,
|
|
546
|
+
autoComplete: autoCompleteUID,
|
|
547
|
+
ref: digitableRef,
|
|
548
|
+
constraint: digitableConstraint,
|
|
549
|
+
onKeyDown: digitableKeyDown,
|
|
550
|
+
setValue: v => {
|
|
551
|
+
ignoringFilter.close();
|
|
552
|
+
digitableValue.openWith(v);
|
|
553
|
+
},
|
|
554
|
+
value: digitableValue.isOpen || "",
|
|
555
|
+
placeholder: placeholder,
|
|
556
|
+
onChange: onDigitableChange
|
|
557
|
+
}) : withPlaceholder ? /*#__PURE__*/React.createElement(ComboboxPlaceholder, null, placeholder) : /*#__PURE__*/React.createElement("div", null, getBoxLabelAs ? getBoxLabelAs(value.isOpen) : getLabel(value.isOpen)), isLoading ? /*#__PURE__*/React.createElement(ComboboxLoading, {
|
|
558
|
+
absolute: true,
|
|
559
|
+
size: 20
|
|
560
|
+
}) : !suggestive && /*#__PURE__*/React.createElement(ComboboxDropdownIcon, {
|
|
561
|
+
icon: "arrow-down"
|
|
562
|
+
}), !!contextMenu.isOpen && (!suggestive || !digitable || allOptions.length && digitableValue.isOpen) && /*#__PURE__*/React.createElement(ComboboxMenuContainer, {
|
|
563
|
+
withWindowing: withWindowing,
|
|
564
|
+
ref: listElement,
|
|
565
|
+
windowingRef: windowingRef,
|
|
566
|
+
options: availableOptions,
|
|
567
|
+
digitableValue: digitableValue.get(),
|
|
568
|
+
digitableAsOption: digitableAsOption,
|
|
569
|
+
footerOptions: footerOptions,
|
|
570
|
+
getIcon: getIcon,
|
|
571
|
+
createOption: createOption
|
|
572
|
+
})));
|
|
573
|
+
})).attrs({
|
|
574
|
+
className: "styled-combobox"
|
|
575
|
+
})`
|
|
576
|
+
user-select: none;
|
|
577
|
+
`;
|
|
578
|
+
const [WithIsSticky] = willUseIsSticky();
|
|
579
|
+
const Option = _ref2 => {
|
|
580
|
+
let {
|
|
581
|
+
setValue,
|
|
582
|
+
icon,
|
|
583
|
+
option,
|
|
584
|
+
onHover,
|
|
585
|
+
checked,
|
|
586
|
+
label,
|
|
587
|
+
setRef
|
|
588
|
+
} = _ref2,
|
|
589
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
590
|
+
return /*#__PURE__*/React.createElement(ListItem, _extends({
|
|
591
|
+
hover: checked,
|
|
592
|
+
tabIndex: -1,
|
|
593
|
+
onMouseOver: e => onHover(option, e),
|
|
594
|
+
ref: checked ? setRef : undefined,
|
|
595
|
+
onClick: e => {
|
|
596
|
+
e.stopPropagation();
|
|
597
|
+
setValue(option);
|
|
598
|
+
}
|
|
599
|
+
}, props), /*#__PURE__*/React.createElement("a", null, icon && /*#__PURE__*/React.createElement(Icon, {
|
|
600
|
+
icon: icon
|
|
601
|
+
}), label));
|
|
602
|
+
};
|
|
603
|
+
const ITEM_HEIGHT = 37;
|
|
604
|
+
const ComboboxMenuContainer = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
605
|
+
let {
|
|
606
|
+
options,
|
|
607
|
+
digitableAsOption,
|
|
608
|
+
footerOptions,
|
|
609
|
+
getIcon,
|
|
610
|
+
createOption,
|
|
611
|
+
withWindowing,
|
|
612
|
+
digitableValue,
|
|
613
|
+
windowingRef
|
|
614
|
+
} = _ref3;
|
|
615
|
+
const [positionInfo, positionPlaceholder] = usePositioning(ref, {
|
|
616
|
+
fill: true,
|
|
617
|
+
on: options.length
|
|
618
|
+
});
|
|
619
|
+
const getMenuHeight = options => Math.min(options.length * ITEM_HEIGHT + 9, 300 - ((footerOptions === null || footerOptions === void 0 ? void 0 : footerOptions.length) || 0) * ITEM_HEIGHT - (footerOptions !== null && footerOptions !== void 0 && footerOptions.length ? 7 : 0));
|
|
620
|
+
const slot = 'Popup';
|
|
621
|
+
const slotName = useMemo(() => getDialogLayersSize() === 0 ? slot : slot + '-' + (getDialogLayersSize() - 1), []);
|
|
622
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, positionPlaceholder, /*#__PURE__*/React.createElement(Fill, {
|
|
623
|
+
name: slotName
|
|
624
|
+
}, /*#__PURE__*/React.createElement(ComboboxMenu, _extends({}, positionInfo, {
|
|
625
|
+
ref: ref,
|
|
626
|
+
withWindowing: withWindowing,
|
|
627
|
+
withoutIcons: !getIcon
|
|
628
|
+
}), withWindowing ? /*#__PURE__*/React.createElement(FixedSizeList, {
|
|
629
|
+
ref: windowingRef,
|
|
630
|
+
height: getMenuHeight(options),
|
|
631
|
+
itemCount: options.length,
|
|
632
|
+
itemSize: ITEM_HEIGHT,
|
|
633
|
+
width: "100%"
|
|
634
|
+
}, _ref4 => {
|
|
635
|
+
let {
|
|
636
|
+
index,
|
|
637
|
+
style
|
|
638
|
+
} = _ref4;
|
|
639
|
+
return createOption(options[index], index, {
|
|
640
|
+
style
|
|
641
|
+
});
|
|
642
|
+
}) : options.map(createOption).filter(Boolean), footerOptions && /*#__PURE__*/React.createElement(WithIsSticky, {
|
|
643
|
+
intersection: true
|
|
644
|
+
}, (sentinel, isSticky) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FooterOptionsContainer, {
|
|
645
|
+
isSticky: isSticky,
|
|
646
|
+
className: "JS-list-footer",
|
|
647
|
+
hasWindoning: withWindowing
|
|
648
|
+
}, footerOptions.map(createOption)), sentinel("margin-top:-3px;"))))));
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
export { Combobox, ComboboxInput, ComboboxMenu, NO_DIGITABLE_FOUND, Option, SEPARATOR };
|
|
652
|
+
//# sourceMappingURL=Combobox.mjs.map
|