@bpmn-io/form-js-viewer 0.8.0-alpha.1 → 0.9.0
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/index.cjs +35 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +35 -32
- package/dist/index.es.js.map +1 -1
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -1797,7 +1797,7 @@ Select.keyed = true;
|
|
|
1797
1797
|
Select.emptyValue = null;
|
|
1798
1798
|
Select.sanitizeValue = sanitizeSingleSelectValue;
|
|
1799
1799
|
|
|
1800
|
-
function _extends() { _extends = Object.assign
|
|
1800
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
1801
1801
|
var CloseIcon = (({
|
|
1802
1802
|
styles = {},
|
|
1803
1803
|
...props
|
|
@@ -1946,35 +1946,30 @@ function Taglist(props) {
|
|
|
1946
1946
|
formId
|
|
1947
1947
|
} = useContext(FormContext);
|
|
1948
1948
|
const [filter, setFilter] = useState('');
|
|
1949
|
-
const [
|
|
1950
|
-
const [filteredValues, setFilteredValues] = useState([]);
|
|
1949
|
+
const [filteredOptions, setFilteredOptions] = useState([]);
|
|
1951
1950
|
const [isDropdownExpanded, setIsDropdownExpanded] = useState(false);
|
|
1952
|
-
const [
|
|
1951
|
+
const [hasOptionsLeft, setHasOptionsLeft] = useState(true);
|
|
1953
1952
|
const [isEscapeClosed, setIsEscapeClose] = useState(false);
|
|
1954
1953
|
const searchbarRef = useRef();
|
|
1955
1954
|
const {
|
|
1956
1955
|
state: loadState,
|
|
1957
1956
|
values: options
|
|
1958
|
-
} = useValuesAsync(field); //
|
|
1957
|
+
} = useValuesAsync(field); // We cache a map of option values to their index so that we don't need to search the whole options array every time to correlate the label
|
|
1958
|
+
|
|
1959
|
+
const valueToOptionMap = useMemo(() => Object.assign({}, ...options.map((o, x) => ({
|
|
1960
|
+
[o.value]: options[x]
|
|
1961
|
+
}))), [options]); // Usage of stringify is necessary here because we want this effect to only trigger when there is a value change to the array
|
|
1959
1962
|
|
|
1960
1963
|
useEffect(() => {
|
|
1961
1964
|
if (loadState === LOAD_STATES.LOADED) {
|
|
1962
|
-
|
|
1963
|
-
setSelectedValues(selectedValues);
|
|
1964
|
-
} else {
|
|
1965
|
-
setSelectedValues([]);
|
|
1966
|
-
}
|
|
1967
|
-
}, [JSON.stringify(values), options, loadState]);
|
|
1968
|
-
useEffect(() => {
|
|
1969
|
-
if (loadState === LOAD_STATES.LOADED) {
|
|
1970
|
-
setFilteredValues(options.filter(o => o.label && o.value && o.label.toLowerCase().includes(filter.toLowerCase()) && !values.includes(o.value)));
|
|
1965
|
+
setFilteredOptions(options.filter(o => o.label && o.value && o.label.toLowerCase().includes(filter.toLowerCase()) && !values.includes(o.value)));
|
|
1971
1966
|
} else {
|
|
1972
|
-
|
|
1967
|
+
setFilteredOptions([]);
|
|
1973
1968
|
}
|
|
1974
|
-
}, [filter, JSON.stringify(values), options]);
|
|
1969
|
+
}, [filter, JSON.stringify(values), options, loadState]);
|
|
1975
1970
|
useEffect(() => {
|
|
1976
|
-
|
|
1977
|
-
}, [
|
|
1971
|
+
setHasOptionsLeft(options.length > values.length);
|
|
1972
|
+
}, [options.length, values.length]);
|
|
1978
1973
|
|
|
1979
1974
|
const onFilterChange = ({
|
|
1980
1975
|
target
|
|
@@ -1983,17 +1978,25 @@ function Taglist(props) {
|
|
|
1983
1978
|
setFilter(target.value);
|
|
1984
1979
|
};
|
|
1985
1980
|
|
|
1986
|
-
const selectValue =
|
|
1987
|
-
|
|
1981
|
+
const selectValue = value => {
|
|
1982
|
+
if (filter) {
|
|
1983
|
+
setFilter('');
|
|
1984
|
+
} // Ensure values cannot be double selected due to latency
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
if (values.at(-1) === value) {
|
|
1988
|
+
return;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1988
1991
|
props.onChange({
|
|
1989
|
-
value: [...values,
|
|
1992
|
+
value: [...values, value],
|
|
1990
1993
|
field
|
|
1991
1994
|
});
|
|
1992
1995
|
};
|
|
1993
1996
|
|
|
1994
|
-
const deselectValue =
|
|
1997
|
+
const deselectValue = value => {
|
|
1995
1998
|
props.onChange({
|
|
1996
|
-
value: values.filter(v => v !=
|
|
1999
|
+
value: values.filter(v => v != value),
|
|
1997
2000
|
field
|
|
1998
2001
|
});
|
|
1999
2002
|
};
|
|
@@ -2007,8 +2010,8 @@ function Taglist(props) {
|
|
|
2007
2010
|
break;
|
|
2008
2011
|
|
|
2009
2012
|
case 'Backspace':
|
|
2010
|
-
if (!filter &&
|
|
2011
|
-
deselectValue(
|
|
2013
|
+
if (!filter && values.length) {
|
|
2014
|
+
deselectValue(values[values.length - 1]);
|
|
2012
2015
|
}
|
|
2013
2016
|
|
|
2014
2017
|
break;
|
|
@@ -2035,16 +2038,16 @@ function Taglist(props) {
|
|
|
2035
2038
|
class: classNames('fjs-taglist', {
|
|
2036
2039
|
'disabled': disabled
|
|
2037
2040
|
}),
|
|
2038
|
-
children: [!disabled && loadState === LOAD_STATES.LOADED &&
|
|
2041
|
+
children: [!disabled && loadState === LOAD_STATES.LOADED && values.map(v => {
|
|
2039
2042
|
return jsxs("div", {
|
|
2040
2043
|
class: "fjs-taglist-tag",
|
|
2041
2044
|
onMouseDown: e => e.preventDefault(),
|
|
2042
2045
|
children: [jsx("span", {
|
|
2043
2046
|
class: "fjs-taglist-tag-label",
|
|
2044
|
-
children:
|
|
2047
|
+
children: valueToOptionMap[v] ? valueToOptionMap[v].label : `unexpected value{${v}}`
|
|
2045
2048
|
}), jsx("span", {
|
|
2046
2049
|
class: "fjs-taglist-tag-remove",
|
|
2047
|
-
onMouseDown: () => deselectValue(
|
|
2050
|
+
onMouseDown: () => deselectValue(v),
|
|
2048
2051
|
children: jsx(CloseIcon, {})
|
|
2049
2052
|
})]
|
|
2050
2053
|
});
|
|
@@ -2069,10 +2072,10 @@ function Taglist(props) {
|
|
|
2069
2072
|
}), jsx("div", {
|
|
2070
2073
|
class: "fjs-taglist-anchor",
|
|
2071
2074
|
children: !disabled && loadState === LOAD_STATES.LOADED && isDropdownExpanded && !isEscapeClosed && jsx(DropdownList, {
|
|
2072
|
-
values:
|
|
2073
|
-
getLabel:
|
|
2074
|
-
onValueSelected:
|
|
2075
|
-
emptyListMessage:
|
|
2075
|
+
values: filteredOptions,
|
|
2076
|
+
getLabel: o => o.label,
|
|
2077
|
+
onValueSelected: o => selectValue(o.value),
|
|
2078
|
+
emptyListMessage: hasOptionsLeft ? 'No results' : 'All values selected',
|
|
2076
2079
|
listenerElement: searchbarRef.current
|
|
2077
2080
|
})
|
|
2078
2081
|
}), jsx(Description, {
|