@linzjs/lui 24.2.0 → 24.3.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/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/components/Drawer/Drawer.d.ts +3 -2
- package/dist/components/LuiModal/LuiModalV2.d.ts +2 -0
- package/dist/contexts/LuiFilterCharactersProvider.d.ts +11 -0
- package/dist/functions/LinzFreeTextFilter.d.ts +14 -0
- package/dist/functions/LinzFreeTextValidator.d.ts +2 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +149 -3
- package/dist/index.js.map +1 -1
- package/dist/lui.esm.js +146 -5
- package/dist/lui.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/lui.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default, { forwardRef as forwardRef$1, useState, useRef, useCallback, useEffect, useContext, Fragment, useLayoutEffect,
|
|
2
|
+
import React__default, { forwardRef as forwardRef$1, useState, useRef, useCallback, useEffect, useContext, createContext, Fragment, useLayoutEffect, useMemo, Component, cloneElement, useId as useId$1, useInsertionEffect as useInsertionEffect$1, Children, isValidElement, createElement, useImperativeHandle, useReducer } from 'react';
|
|
3
3
|
import { Menu as Menu$2, ControlledMenu, applyStatics, MenuItem, SubMenu, MenuDivider, MenuHeader, useMenuState, FocusableItem } from '@szhsin/react-menu';
|
|
4
4
|
import lottie from 'lottie-web/build/player/lottie_light';
|
|
5
5
|
import crypto$1 from 'crypto';
|
|
@@ -6989,6 +6989,113 @@ var DateInput = forwardRef$1(function (props, ref) {
|
|
|
6989
6989
|
} })));
|
|
6990
6990
|
});
|
|
6991
6991
|
|
|
6992
|
+
// eslint-disable-next-line no-control-regex
|
|
6993
|
+
var LinzInvalidCharMatcher = /([^\u0000-\u017f])/gu;
|
|
6994
|
+
var LinzFreeTextValidator = function (value, invalidCharMatcher, maxReportedChars) {
|
|
6995
|
+
if (invalidCharMatcher === void 0) { invalidCharMatcher = LinzInvalidCharMatcher; }
|
|
6996
|
+
if (maxReportedChars === void 0) { maxReportedChars = 10; }
|
|
6997
|
+
if (!value) {
|
|
6998
|
+
return undefined;
|
|
6999
|
+
}
|
|
7000
|
+
var matchedItems = value.match(invalidCharMatcher);
|
|
7001
|
+
if (matchedItems === null) {
|
|
7002
|
+
return undefined;
|
|
7003
|
+
}
|
|
7004
|
+
var invalidCharacters = Array.from(new Set(matchedItems)).slice(0, maxReportedChars);
|
|
7005
|
+
return "Invalid character".concat(invalidCharacters.length === 1 ? '' : 's', " ").concat(invalidCharacters.join(', '));
|
|
7006
|
+
};
|
|
7007
|
+
|
|
7008
|
+
function CreateLinzFreeTextFilter(removeInvalidChars) {
|
|
7009
|
+
if (removeInvalidChars === void 0) { removeInvalidChars = true; }
|
|
7010
|
+
return function (value) {
|
|
7011
|
+
if (!value) {
|
|
7012
|
+
return '';
|
|
7013
|
+
}
|
|
7014
|
+
var strLength = value.length;
|
|
7015
|
+
if (!strLength) {
|
|
7016
|
+
return '';
|
|
7017
|
+
}
|
|
7018
|
+
return Array.prototype.flatMap
|
|
7019
|
+
.call(value, function (char) {
|
|
7020
|
+
// Supported character range
|
|
7021
|
+
if (char.match(LinzInvalidCharMatcher) === null) {
|
|
7022
|
+
return char;
|
|
7023
|
+
}
|
|
7024
|
+
var charCode = char.charCodeAt(0);
|
|
7025
|
+
// Silent conversion characters
|
|
7026
|
+
// why: https://toitutewhenua.atlassian.net/wiki/spaces/STEP/pages/124322198/Minimum+Text+Validation#Silent-conversion-characters
|
|
7027
|
+
switch (charCode) {
|
|
7028
|
+
case 0x2018:
|
|
7029
|
+
case 0x2019:
|
|
7030
|
+
return "'";
|
|
7031
|
+
case 0x201c:
|
|
7032
|
+
case 0x201d:
|
|
7033
|
+
return '"';
|
|
7034
|
+
case 0x2022:
|
|
7035
|
+
return '*';
|
|
7036
|
+
case 0x2013:
|
|
7037
|
+
case 0x2014:
|
|
7038
|
+
return '-';
|
|
7039
|
+
}
|
|
7040
|
+
return removeInvalidChars ? '' : char;
|
|
7041
|
+
})
|
|
7042
|
+
.join('');
|
|
7043
|
+
};
|
|
7044
|
+
}
|
|
7045
|
+
/**
|
|
7046
|
+
* Default LINZ free text filter function.
|
|
7047
|
+
* Silently converts some invalid characters with supported alternatives.
|
|
7048
|
+
* Removes all other invalid characters.
|
|
7049
|
+
*/
|
|
7050
|
+
var LinzFreeTextFilter = CreateLinzFreeTextFilter(true);
|
|
7051
|
+
/**
|
|
7052
|
+
* LINZ free text filter function that leaves invalid characters intact.
|
|
7053
|
+
* Silently converts some invalid characters with supported alternatives.
|
|
7054
|
+
* Leaves all other invalid characters as is.
|
|
7055
|
+
* Should be paired with LinzFreeTextValidator to warn users about invalid characters.
|
|
7056
|
+
*/
|
|
7057
|
+
var LinzFreeTextFilterConvertOnly = CreateLinzFreeTextFilter(false);
|
|
7058
|
+
|
|
7059
|
+
var LuiFilterCharactersContext = createContext({
|
|
7060
|
+
filterCharacters: function (input) {
|
|
7061
|
+
// Default implementation: return input as is.
|
|
7062
|
+
return input;
|
|
7063
|
+
},
|
|
7064
|
+
filterInputEvent: function () {
|
|
7065
|
+
// Default implementation: do nothing.
|
|
7066
|
+
return;
|
|
7067
|
+
}
|
|
7068
|
+
});
|
|
7069
|
+
function useFilterCharacters() {
|
|
7070
|
+
return useContext(LuiFilterCharactersContext);
|
|
7071
|
+
}
|
|
7072
|
+
var LuiFilterCharactersProvider = function (_a) {
|
|
7073
|
+
var children = _a.children, filterFunction = _a.filterFunction;
|
|
7074
|
+
var filterCharacters = useCallback(function (input) {
|
|
7075
|
+
if (input === undefined) {
|
|
7076
|
+
return input;
|
|
7077
|
+
}
|
|
7078
|
+
var filter = typeof filterFunction === 'function'
|
|
7079
|
+
? filterFunction
|
|
7080
|
+
: LinzFreeTextFilter;
|
|
7081
|
+
return filter(input);
|
|
7082
|
+
}, [filterFunction]);
|
|
7083
|
+
var filterInputEvent = useCallback(function (event) {
|
|
7084
|
+
var value = event.target.value;
|
|
7085
|
+
var filteredValue = filterCharacters(value);
|
|
7086
|
+
if (filteredValue !== value) {
|
|
7087
|
+
var caretPosition = event.target.selectionStart;
|
|
7088
|
+
event.target.value = filteredValue;
|
|
7089
|
+
if (caretPosition !== null) {
|
|
7090
|
+
var positionOffset = value.length - filteredValue.length;
|
|
7091
|
+
var newCaretPosition = Math.max(caretPosition - positionOffset, 0);
|
|
7092
|
+
event.target.setSelectionRange(newCaretPosition, newCaretPosition);
|
|
7093
|
+
}
|
|
7094
|
+
}
|
|
7095
|
+
}, [filterFunction]);
|
|
7096
|
+
return (React__default.createElement(LuiFilterCharactersContext.Provider, { value: { filterCharacters: filterCharacters, filterInputEvent: filterInputEvent } }, children));
|
|
7097
|
+
};
|
|
7098
|
+
|
|
6992
7099
|
function useGenerateOrDefaultId(idFromProps) {
|
|
6993
7100
|
var id = useState(idFromProps ? idFromProps : v4())[0];
|
|
6994
7101
|
return id;
|
|
@@ -6997,6 +7104,7 @@ var BareInput = forwardRef$1(function (props, ref) { return React__default.creat
|
|
|
6997
7104
|
var LuiTextInput = forwardRef$1(function (props, ref) {
|
|
6998
7105
|
var _a, _b, _c;
|
|
6999
7106
|
var id = useGenerateOrDefaultId((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.id);
|
|
7107
|
+
var filterInputEvent = useFilterCharacters().filterInputEvent;
|
|
7000
7108
|
var LuiInput = ((_b = props.inputProps) === null || _b === void 0 ? void 0 : _b.type) === 'date' ? DateInput : BareInput;
|
|
7001
7109
|
return (React__default.createElement("div", { className: clsx$1('LuiTextInput', props.error && 'hasError', props.warning && 'hasWarning', props.className) },
|
|
7002
7110
|
React__default.createElement("label", { className: 'LuiTextInput-label', htmlFor: id },
|
|
@@ -7004,7 +7112,15 @@ var LuiTextInput = forwardRef$1(function (props, ref) {
|
|
|
7004
7112
|
React__default.createElement("span", { className: 'LuiTextInput-label-text ' +
|
|
7005
7113
|
clsx$1(props.hideLabel ? 'LuiScreenReadersOnly' : '') }, props.label),
|
|
7006
7114
|
React__default.createElement("span", { className: "LuiTextInput-inputWrapper" },
|
|
7007
|
-
React__default.createElement(LuiInput, __assign({ ref: ref, className: clsx$1('LuiTextInput-input', props.showPadlockIcon ? 'LuiTextInput-padlock-icon ' : '', props.size ? "LuiTextInput-".concat(props.size) : ''), min: ((_c = props.inputProps) === null || _c === void 0 ? void 0 : _c.type) === 'date' ? undefined : '0', value: props.value, onChange:
|
|
7115
|
+
React__default.createElement(LuiInput, __assign({ ref: ref, className: clsx$1('LuiTextInput-input', props.showPadlockIcon ? 'LuiTextInput-padlock-icon ' : '', props.size ? "LuiTextInput-".concat(props.size) : ''), min: ((_c = props.inputProps) === null || _c === void 0 ? void 0 : _c.type) === 'date' ? undefined : '0', value: props.value, onChange: function (event) {
|
|
7116
|
+
var _a;
|
|
7117
|
+
if (((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.type) !== 'date') {
|
|
7118
|
+
filterInputEvent(event);
|
|
7119
|
+
}
|
|
7120
|
+
if (props.onChange) {
|
|
7121
|
+
props.onChange(event);
|
|
7122
|
+
}
|
|
7123
|
+
} }, props.inputProps, { id: id })),
|
|
7008
7124
|
props.icon),
|
|
7009
7125
|
props.error && (React__default.createElement("span", { className: "LuiTextInput-error" },
|
|
7010
7126
|
React__default.createElement(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }),
|
|
@@ -7149,13 +7265,22 @@ var LuiSelectInput = function (props) {
|
|
|
7149
7265
|
var LuiTextAreaInput = React__default.forwardRef(function (props, ref) {
|
|
7150
7266
|
var _a, _b;
|
|
7151
7267
|
var id = useGenerateOrDefaultId((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.id);
|
|
7268
|
+
var filterInputEvent = useFilterCharacters().filterInputEvent;
|
|
7152
7269
|
var rows = props.rows !== undefined ? props.rows : 5;
|
|
7153
7270
|
return (React__default.createElement("div", { className: clsx$1('LuiTextAreaInput', ((_b = props.inputProps) === null || _b === void 0 ? void 0 : _b.disabled) ? 'isDisabled' : '', props.error ? 'hasError' : '', props.warning ? 'hasWarning' : '') },
|
|
7154
7271
|
React__default.createElement("label", { htmlFor: id },
|
|
7155
7272
|
props.mandatory && (React__default.createElement("span", { className: "LuiTextAreaInput-mandatory" }, "*")),
|
|
7156
7273
|
React__default.createElement("span", { className: "LuiTextAreaInput-label" }, props.label),
|
|
7157
7274
|
React__default.createElement("div", { className: "LuiTextAreaInput-wrapper" },
|
|
7158
|
-
React__default.createElement("textarea", __assign({ id: id, value: props.value, onChange:
|
|
7275
|
+
React__default.createElement("textarea", __assign({ id: id, value: props.value, onChange: function (event) {
|
|
7276
|
+
var _a;
|
|
7277
|
+
if (((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.type) !== 'date') {
|
|
7278
|
+
filterInputEvent(event);
|
|
7279
|
+
}
|
|
7280
|
+
if (props.onChange) {
|
|
7281
|
+
props.onChange(event);
|
|
7282
|
+
}
|
|
7283
|
+
}, ref: ref, rows: rows }, props.inputProps)))),
|
|
7159
7284
|
props.error && (React__default.createElement("span", { className: "LuiTextAreaInput-error" },
|
|
7160
7285
|
React__default.createElement(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextAreaInput-error-icon", size: "sm", status: "error" }),
|
|
7161
7286
|
props.error)),
|
|
@@ -18237,7 +18362,23 @@ var LuiModalV2 = function (props) {
|
|
|
18237
18362
|
showButtons && (React__default.createElement("div", { className: "lui-modal-v2-header-buttons" },
|
|
18238
18363
|
showHelpButton && React__default.createElement(HelpButton, { helpLink: props.helpLink }),
|
|
18239
18364
|
showCloseButton && React__default.createElement(CloseButton, { onClose: props.onClose })))),
|
|
18240
|
-
React__default.createElement(
|
|
18365
|
+
React__default.createElement(ModalContents, { children: props.children, tabIndex: props.tabIndex }))));
|
|
18366
|
+
};
|
|
18367
|
+
var ModalContents = function (props) {
|
|
18368
|
+
useEffect(function () {
|
|
18369
|
+
var modalContent = document.querySelector('.ReactModal__Content');
|
|
18370
|
+
if (props.tabIndex === undefined || !modalContent)
|
|
18371
|
+
return;
|
|
18372
|
+
switch (props.tabIndex) {
|
|
18373
|
+
case null:
|
|
18374
|
+
modalContent === null || modalContent === void 0 ? void 0 : modalContent.removeAttribute('tabindex');
|
|
18375
|
+
break;
|
|
18376
|
+
default:
|
|
18377
|
+
modalContent === null || modalContent === void 0 ? void 0 : modalContent.setAttribute('tabindex', props.tabIndex.toString());
|
|
18378
|
+
break;
|
|
18379
|
+
}
|
|
18380
|
+
}, []);
|
|
18381
|
+
return React__default.createElement("div", { className: "lui-modal-v2-contents" }, props.children);
|
|
18241
18382
|
};
|
|
18242
18383
|
var ButtonRow = function (props) { return (React__default.createElement("div", { className: clsx$1('lui-modal-v2-btn-row', props.className) }, props.children)); };
|
|
18243
18384
|
LuiModalV2.Buttons = ButtonRow;
|
|
@@ -41306,5 +41447,5 @@ var DrawerGlobal = forwardRef$1(function (props, ref) {
|
|
|
41306
41447
|
return (React__default.createElement(Drawer, __assign({}, props, { ref: ref, isOpen: isOpen, onRequestClose: onRequestClose })));
|
|
41307
41448
|
});
|
|
41308
41449
|
|
|
41309
|
-
export { CheckboxItemRenderer, ColorBucket, ColorInput, ColorInputGroup, ColorPalette, Drawer, DrawerGlobal, DrawerGlobalContext, DrawerGlobalProvider, LuiAccordicard, LuiAccordicardStatic, LuiAccordion, LuiAlertModal, LuiAlertModalButtons, LuiAlertModalV2, LuiAppFooterSml, LuiAutoExpandTextAreaInput, LuiBadge, LuiBanner, LuiBannerContent, LuiBannerV2, LuiBearingInput, LuiButton, LuiButtonGroup, LuiCheckboxInput, LuiCloseableHeaderMenuContext, LuiCloseableHeaderMenuContextV2, LuiCloseableHeaderMenuItem, LuiCloseableHeaderMenuItemV2, LuiComboSelect, LuiControlledMenu, LuiCounter, LuiDateInput, LuiDrawerMenu, LuiDrawerMenuDivider, LuiDrawerMenuDividerV2, LuiDrawerMenuOption, LuiDrawerMenuOptionV2, LuiDrawerMenuOptions, LuiDrawerMenuOptionsV2, LuiDrawerMenuSection, LuiDrawerMenuSectionV2, LuiDrawerMenuV2, LuiDropdownMenu, LuiDropdownMenuV2, LuiDropdownMenuV2DropContent, LuiErrorIllustration, LuiErrorPage, LuiErrorPanel, LuiExpandableBanner, LuiFileInputBox, LuiFilterContainer, LuiFilterMenu, LuiFooter, LuiFormSectionHeader, LuiHeader, LuiHeaderMenuItem, LuiHeaderMenuItemV2, LuiHeaderV2, LuiIcon, LuiListBox, LuiLoadingSpinner, LuiMenu, LuiMenuCloseButton, LuiMenuCloseButtonV2, LuiMessagingContextProvider, LuiMiniSpinner, LuiModal, LuiModalV2, LuiMoneyInput, LuiMultiSwitch, LuiMultiSwitchYesNo, LuiPagination, LuiPassiveSearchInput, LuiProgressBar, LuiRadioInput, LuiResizableLayout, LuiSearchBox, LuiSearchInput, LuiSelectDataMenu, LuiSelectInput, LuiSelectMenu, LuiSelectMenuDivider, LuiSelectMenuHeader, LuiSelectMenuItem, LuiSelectMenuItemSwitch, LuiSelectSubMenuItem, LuiShadow, LuiSideMenu, LuiSideMenuItem, LuiSidePanel, LuiSidePanelProvider, LuiSideToolbar, LuiSplitButton, LuiSplitButtonMenuItem, LuiSplitButtonPosition, LuiStaticMessage, LuiStatusSpinner, LuiSwitchButton, LuiTab, LuiTabs, LuiTabsContext, LuiTabsGroup, LuiTabsPanel, LuiTabsPanelSwitch, LuiTextAreaInput, LuiTextInput, LuiToastMessage, LuiTooltip, LuiUpdatesSplashModal, RadioItemRenderer, SplitPanelState, Splitter, ToolbarButton, ToolbarDirection, ToolbarItem, ToolbarItemSeparator, breakpointQuery, breakpoints, defaultColours, isChromatic, useClickedOutsideElement, useDrawerGlobalContext, useEscapeFunction, useLuiCloseableHeaderMenuContextV2, useMediaQuery, usePageClickFunction, useShowLUIMessage, useSplitterRef, useToast };
|
|
41450
|
+
export { CheckboxItemRenderer, ColorBucket, ColorInput, ColorInputGroup, ColorPalette, Drawer, DrawerGlobal, DrawerGlobalContext, DrawerGlobalProvider, LinzFreeTextFilter, LinzFreeTextFilterConvertOnly, LinzFreeTextValidator, LuiAccordicard, LuiAccordicardStatic, LuiAccordion, LuiAlertModal, LuiAlertModalButtons, LuiAlertModalV2, LuiAppFooterSml, LuiAutoExpandTextAreaInput, LuiBadge, LuiBanner, LuiBannerContent, LuiBannerV2, LuiBearingInput, LuiButton, LuiButtonGroup, LuiCheckboxInput, LuiCloseableHeaderMenuContext, LuiCloseableHeaderMenuContextV2, LuiCloseableHeaderMenuItem, LuiCloseableHeaderMenuItemV2, LuiComboSelect, LuiControlledMenu, LuiCounter, LuiDateInput, LuiDrawerMenu, LuiDrawerMenuDivider, LuiDrawerMenuDividerV2, LuiDrawerMenuOption, LuiDrawerMenuOptionV2, LuiDrawerMenuOptions, LuiDrawerMenuOptionsV2, LuiDrawerMenuSection, LuiDrawerMenuSectionV2, LuiDrawerMenuV2, LuiDropdownMenu, LuiDropdownMenuV2, LuiDropdownMenuV2DropContent, LuiErrorIllustration, LuiErrorPage, LuiErrorPanel, LuiExpandableBanner, LuiFileInputBox, LuiFilterCharactersProvider, LuiFilterContainer, LuiFilterMenu, LuiFooter, LuiFormSectionHeader, LuiHeader, LuiHeaderMenuItem, LuiHeaderMenuItemV2, LuiHeaderV2, LuiIcon, LuiListBox, LuiLoadingSpinner, LuiMenu, LuiMenuCloseButton, LuiMenuCloseButtonV2, LuiMessagingContextProvider, LuiMiniSpinner, LuiModal, LuiModalV2, LuiMoneyInput, LuiMultiSwitch, LuiMultiSwitchYesNo, LuiPagination, LuiPassiveSearchInput, LuiProgressBar, LuiRadioInput, LuiResizableLayout, LuiSearchBox, LuiSearchInput, LuiSelectDataMenu, LuiSelectInput, LuiSelectMenu, LuiSelectMenuDivider, LuiSelectMenuHeader, LuiSelectMenuItem, LuiSelectMenuItemSwitch, LuiSelectSubMenuItem, LuiShadow, LuiSideMenu, LuiSideMenuItem, LuiSidePanel, LuiSidePanelProvider, LuiSideToolbar, LuiSplitButton, LuiSplitButtonMenuItem, LuiSplitButtonPosition, LuiStaticMessage, LuiStatusSpinner, LuiSwitchButton, LuiTab, LuiTabs, LuiTabsContext, LuiTabsGroup, LuiTabsPanel, LuiTabsPanelSwitch, LuiTextAreaInput, LuiTextInput, LuiToastMessage, LuiTooltip, LuiUpdatesSplashModal, RadioItemRenderer, SplitPanelState, Splitter, ToolbarButton, ToolbarDirection, ToolbarItem, ToolbarItemSeparator, breakpointQuery, breakpoints, defaultColours, isChromatic, useClickedOutsideElement, useDrawerGlobalContext, useEscapeFunction, useFilterCharacters, useLuiCloseableHeaderMenuContextV2, useMediaQuery, usePageClickFunction, useShowLUIMessage, useSplitterRef, useToast };
|
|
41310
41451
|
//# sourceMappingURL=lui.esm.js.map
|