@hitachivantara/uikit-react-core 5.36.11 → 5.37.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/dist/cjs/components/Dropdown/Dropdown.cjs +4 -1
- package/dist/cjs/components/Dropdown/Dropdown.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Context.cjs +5 -0
- package/dist/cjs/components/QueryBuilder/Context.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/QueryBuilder.cjs +6 -2
- package/dist/cjs/components/QueryBuilder/QueryBuilder.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Rule/Attribute/Attribute.cjs +2 -3
- package/dist/cjs/components/QueryBuilder/Rule/Attribute/Attribute.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Rule/Operator/Operator.cjs +1 -2
- package/dist/cjs/components/QueryBuilder/Rule/Operator/Operator.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Rule/Rule.cjs +16 -14
- package/dist/cjs/components/QueryBuilder/Rule/Rule.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Rule/Value/BooleanValue/BooleanValue.cjs +1 -2
- package/dist/cjs/components/QueryBuilder/Rule/Value/BooleanValue/BooleanValue.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Rule/Value/DateTimeValue/DateTimeValue.cjs +1 -2
- package/dist/cjs/components/QueryBuilder/Rule/Value/DateTimeValue/DateTimeValue.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Rule/Value/NumericValue/NumericValue.cjs +1 -2
- package/dist/cjs/components/QueryBuilder/Rule/Value/NumericValue/NumericValue.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Rule/Value/TextValue/TextValue.cjs +1 -2
- package/dist/cjs/components/QueryBuilder/Rule/Value/TextValue/TextValue.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Rule/Value/Value.cjs +8 -3
- package/dist/cjs/components/QueryBuilder/Rule/Value/Value.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/RuleGroup/RuleGroup.cjs +13 -12
- package/dist/cjs/components/QueryBuilder/RuleGroup/RuleGroup.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/utils/reducer.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/providers/Provider.cjs +11 -3
- package/dist/cjs/providers/Provider.cjs.map +1 -1
- package/dist/esm/components/Dropdown/Dropdown.js +5 -2
- package/dist/esm/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Context.js +7 -2
- package/dist/esm/components/QueryBuilder/Context.js.map +1 -1
- package/dist/esm/components/QueryBuilder/QueryBuilder.js +6 -2
- package/dist/esm/components/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Rule/Attribute/Attribute.js +3 -4
- package/dist/esm/components/QueryBuilder/Rule/Attribute/Attribute.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Rule/Operator/Operator.js +3 -4
- package/dist/esm/components/QueryBuilder/Rule/Operator/Operator.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Rule/Rule.js +18 -16
- package/dist/esm/components/QueryBuilder/Rule/Rule.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Rule/Value/BooleanValue/BooleanValue.js +3 -4
- package/dist/esm/components/QueryBuilder/Rule/Value/BooleanValue/BooleanValue.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Rule/Value/DateTimeValue/DateTimeValue.js +3 -4
- package/dist/esm/components/QueryBuilder/Rule/Value/DateTimeValue/DateTimeValue.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Rule/Value/NumericValue/NumericValue.js +3 -4
- package/dist/esm/components/QueryBuilder/Rule/Value/NumericValue/NumericValue.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Rule/Value/TextValue/TextValue.js +3 -4
- package/dist/esm/components/QueryBuilder/Rule/Value/TextValue/TextValue.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Rule/Value/Value.js +10 -5
- package/dist/esm/components/QueryBuilder/Rule/Value/Value.js.map +1 -1
- package/dist/esm/components/QueryBuilder/RuleGroup/RuleGroup.js +15 -14
- package/dist/esm/components/QueryBuilder/RuleGroup/RuleGroup.js.map +1 -1
- package/dist/esm/components/QueryBuilder/utils/reducer.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/providers/Provider.js +11 -3
- package/dist/esm/providers/Provider.js.map +1 -1
- package/dist/types/index.d.ts +65 -0
- package/package.json +3 -3
|
@@ -81,8 +81,10 @@ const HvDropdown = React.forwardRef((props, ref) => {
|
|
|
81
81
|
const [isOpen, setIsOpen] = useControlled.useControlled(expanded, Boolean(defaultExpanded));
|
|
82
82
|
const [selectionLabel, setSelectionLabel] = React.useState(utils.getSelectionLabel(labels, placeholder, multiSelect, values));
|
|
83
83
|
const [internalValues, setInternalValues] = React.useState(values);
|
|
84
|
+
const internalValuesRef = React.useRef(values);
|
|
84
85
|
React.useEffect(() => {
|
|
85
86
|
setInternalValues(values);
|
|
87
|
+
internalValuesRef.current = values;
|
|
86
88
|
}, [values]);
|
|
87
89
|
React.useEffect(() => {
|
|
88
90
|
setSelectionLabel(utils.getSelectionLabel(labels, placeholder, multiSelect, values));
|
|
@@ -101,7 +103,7 @@ const HvDropdown = React.forwardRef((props, ref) => {
|
|
|
101
103
|
if (!open) {
|
|
102
104
|
setValidationState(() => {
|
|
103
105
|
if (required) {
|
|
104
|
-
const hasSelection = utils.getSelected(
|
|
106
|
+
const hasSelection = utils.getSelected(internalValuesRef.current).length > 0;
|
|
105
107
|
if (!hasSelection) {
|
|
106
108
|
return "invalid";
|
|
107
109
|
}
|
|
@@ -114,6 +116,7 @@ const HvDropdown = React.forwardRef((props, ref) => {
|
|
|
114
116
|
const selected = utils.getSelected(listValues);
|
|
115
117
|
if (commitChanges) {
|
|
116
118
|
setInternalValues(listValues);
|
|
119
|
+
internalValuesRef.current = listValues;
|
|
117
120
|
setSelectionLabel(utils.getSelectionLabel(labels, placeholder, multiSelect, listValues));
|
|
118
121
|
setValidationState(() => {
|
|
119
122
|
if (required && selected.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown.cjs","sources":["../../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import { forwardRef, useEffect, useRef, useState } from \"react\";\n\nimport { PopperProps, useForkRef } from \"@mui/material\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { setId } from \"@core/utils/setId\";\nimport { useLabels, useUniqueId, useControlled } from \"@core/hooks\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport {\n HvBaseDropdown,\n HvBaseDropdownProps,\n} from \"@core/components/BaseDropdown\";\nimport { HvListValue } from \"@core/components/List\";\nimport {\n isInvalid,\n HvInfoMessage,\n HvWarningText,\n HvFormElement,\n HvLabel,\n} from \"@core/components/Forms\";\nimport { ExtractNames } from \"@core/utils/classes\";\nimport { HvTypography } from \"@core/components/Typography\";\n\nimport { getSelected, getSelectionLabel } from \"./utils\";\nimport { HvDropdownList, HvDropdownListProps } from \"./List\";\nimport { staticClasses, useClasses } from \"./Dropdown.styles\";\nimport { HvDropdownLabelsProps, HvDropdownStatus } from \"./types\";\n\nexport { staticClasses as dropdownClasses };\n\nexport type HvDropdownClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDropdownProps\n extends HvBaseProps<HTMLDivElement, \"onChange\"> {\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvDropdownClasses;\n /**\n * The form element name.\n */\n name?: string;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: any;\n /**\n * Provide additional descriptive text for the form element.\n */\n description?: any;\n /**\n * The placeholder value when nothing is selected.\n */\n placeholder?: string;\n /**\n * Indicates that the form element is disabled.\n */\n disabled?: boolean;\n /**\n * Indicates that the form element is in read only mode.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n */\n required?: boolean;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvDropdownStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: any;\n /**\n * Identifies the element that provides an error message for the dropdown.\n *\n * Will only be used when the validation status is invalid.\n */\n \"aria-errormessage\"?: string;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (selected: HvListValue | HvListValue[] | undefined) => void;\n /**\n * The list to be rendered by the dropdown.\n */\n values?: HvListValue[];\n /**\n * If `true` the dropdown is multiSelect, if `false` the dropdown is single select.\n */\n multiSelect?: boolean;\n /**\n * If `true` the dropdown is rendered with a search bar, if `false` there won't be a search bar.\n */\n showSearch?: boolean;\n /**\n * If `true` the dropdown starts opened if `false` it starts closed.\n */\n expanded?: boolean;\n /**\n * When uncontrolled, defines the initial expanded state.\n */\n defaultExpanded?: boolean;\n /**\n * If 'true' the dropdown will notify on the first render.\n */\n notifyChangesOnFirstRender?: boolean;\n /**\n * An object containing all the labels for the dropdown.\n */\n labels?: HvDropdownLabelsProps;\n /**\n * If `true` the dropdown will show tooltips when user mouseenter text in list\n */\n hasTooltips?: boolean;\n /**\n * Disable the portal behavior.\n * The children stay within it's parent DOM hierarchy.\n */\n disablePortal?: boolean;\n /**\n * If `true` the dropdown width depends size of content if `false` the width depends on the header size.\n * Defaults to `false`.\n */\n variableWidth?: boolean;\n /**\n * If `true`, selection can be toggled when single selection.\n */\n singleSelectionToggle?: boolean;\n /**\n * Placement of the dropdown.\n */\n placement?: \"left\" | \"right\";\n /**\n * An object containing props to be wired to the popper component.\n */\n popperProps?: Partial<PopperProps>;\n /**\n * Callback called when the user cancels the changes.\n *\n * Called when the cancel button is used and when the user clicks outside the open container.\n *\n * @param {object} event The event source of the callback.\n */\n onCancel?: (event: Event) => void;\n /**\n * Callback called when dropdown changes the expanded state.\n *\n * @param {object} event The event source of the callback.\n * @param {boolean} open If the dropdown new state is open (`true`) or closed (`false`).\n */\n onToggle?: (event: Event, open: boolean) => void;\n /**\n * Callback called when the user clicks outside the open container.\n *\n * @param {object} event The event source of the callback.\n */\n onClickOutside?: (event: Event) => void;\n /**\n * @ignore\n */\n onFocus?: React.FocusEventHandler<any>;\n /**\n * @ignore\n */\n onBlur?: React.FocusEventHandler<any>;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n height?: number;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n maxHeight?: number;\n /**\n * Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options.\n */\n virtualized?: boolean;\n /**\n * Extra props passed to the dropdown.\n */\n baseDropdownProps?: Partial<HvBaseDropdownProps>;\n /**\n * Extra props passed to the list.\n */\n listProps?: HvDropdownListProps;\n}\n\nconst DEFAULT_LABELS: HvDropdownLabelsProps = {\n select: undefined,\n selectAll: \"All\",\n cancelLabel: \"Cancel\",\n applyLabel: \"Apply\",\n searchPlaceholder: \"Search\",\n multiSelectionConjunction: \"/\",\n};\n\n/**\n * A dropdown list is a graphical control element, similar to a list box, that allows the user to choose one value from a list.\n */\nexport const HvDropdown = forwardRef<HTMLDivElement, HvDropdownProps>(\n (props, ref) => {\n const {\n classes: classesProp,\n className,\n\n id,\n name,\n\n required = false,\n disabled = false,\n readOnly = false,\n\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n\n placeholder = \"Select...\",\n\n onChange,\n\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n\n onCancel,\n onToggle,\n onClickOutside,\n\n onFocus,\n onBlur,\n\n values,\n multiSelect = false,\n showSearch = false,\n expanded,\n defaultExpanded = false,\n notifyChangesOnFirstRender = false,\n labels: labelsProp,\n hasTooltips = false,\n disablePortal = false,\n singleSelectionToggle = true,\n placement,\n variableWidth = false,\n popperProps = {},\n height,\n maxHeight,\n virtualized = false,\n baseDropdownProps = {},\n listProps = {},\n ...others\n } = useDefaultProps(\"HvDropdown\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const elementId = useUniqueId(id, \"hvdropdown\");\n\n const [validationState, setValidationState] = useControlled(\n status,\n \"standBy\"\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const [isOpen, setIsOpen] = useControlled(\n expanded,\n Boolean(defaultExpanded)\n );\n const [selectionLabel, setSelectionLabel] = useState(\n getSelectionLabel(labels, placeholder, multiSelect, values)\n );\n const [internalValues, setInternalValues] = useState(values);\n\n useEffect(() => {\n setInternalValues(values);\n }, [values]);\n\n useEffect(() => {\n setSelectionLabel(\n getSelectionLabel(labels, placeholder, multiSelect, values)\n );\n }, [labels, multiSelect, placeholder, values]);\n\n if (import.meta.env.DEV && virtualized && !height) {\n // eslint-disable-next-line no-console\n console.error(\n \"Dropdown/List in virtualized mode requires a height. Please define it.\"\n );\n }\n\n const dropdownHeaderRef = useRef<HTMLDivElement>();\n\n const {\n ref: refProp,\n dropdownHeaderRef: dropdownHeaderRefProp,\n ...otherBaseDropdownProps\n } = baseDropdownProps;\n const headerForkedRef = useForkRef(\n dropdownHeaderRefProp,\n dropdownHeaderRef\n );\n\n const dropdownForkedRef = useForkRef(ref, refProp);\n\n const handleToggle: HvBaseDropdownProps[\"onToggle\"] = (event, open) => {\n onToggle?.(event, open);\n\n setIsOpen(open);\n\n if (!open) {\n // also run built-in validation when closing without changes\n // as the user \"touched\" the input\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required) {\n const hasSelection = getSelected(internalValues).length > 0;\n\n if (!hasSelection) {\n return \"invalid\";\n }\n }\n\n return \"valid\";\n });\n }\n };\n\n /** Applies the selected values to the state */\n const handleSelection: HvDropdownListProps[\"onChange\"] = (\n listValues,\n commitChanges,\n toggle,\n notifyChanges = true\n ) => {\n const selected = getSelected(listValues);\n\n if (commitChanges) {\n setInternalValues(listValues);\n setSelectionLabel(\n getSelectionLabel(labels, placeholder, multiSelect, listValues)\n );\n\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required && selected.length === 0) {\n return \"invalid\";\n }\n\n return \"valid\";\n });\n }\n if (notifyChanges) onChange?.(multiSelect ? selected : selected[0]);\n if (toggle) {\n handleToggle(undefined as any, false);\n\n // focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n dropdownHeaderRef.current?.focus({ preventScroll: true });\n }\n };\n\n /**\n * Handles the `Cancel` action. Both single and ranged modes are handled here.\n */\n const handleCancel: HvDropdownListProps[\"onCancel\"] = (evt) => {\n onCancel?.(evt as any);\n\n handleToggle(evt as any, false);\n\n // focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n dropdownHeaderRef.current?.focus({ preventScroll: true });\n };\n\n const handleClickOutside: HvBaseDropdownProps[\"onClickOutside\"] = (evt) => {\n onClickOutside?.(evt);\n onCancel?.(evt);\n };\n\n const setFocusToContent: HvBaseDropdownProps[\"onContainerCreation\"] = (\n containerRef\n ) => {\n const inputs = containerRef?.getElementsByTagName(\"input\");\n if (inputs && inputs.length > 0) {\n inputs[0].focus();\n return;\n }\n const listItems =\n containerRef != null\n ? [...containerRef.getElementsByTagName(\"li\")]\n : [];\n listItems.every((listItem) => {\n if (listItem.tabIndex >= 0) {\n listItem.focus();\n return false;\n }\n return true;\n });\n };\n\n const buildHeaderLabel = () => {\n const hasSelection = getSelected(internalValues).length > 0;\n return labels?.select || !multiSelect ? (\n <HvTypography\n component=\"div\"\n variant=\"body\"\n className={cx(classes.placeholder, {\n [classes.selectionDisabled]: disabled,\n [classes.placeholderClosed]: !(isOpen || hasSelection),\n })}\n >\n {selectionLabel.selected}\n </HvTypography>\n ) : (\n <HvTypography\n component=\"div\"\n className={cx(classes.placeholder, {\n [classes.selectionDisabled]: disabled,\n })}\n variant=\"body\"\n >\n <b>{selectionLabel.selected}</b>\n {` ${labels?.multiSelectionConjunction} ${selectionLabel.total}`}\n </HvTypography>\n );\n };\n\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n // the error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and required is true\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined && required));\n\n const isStateInvalid = isInvalid(validationState);\n\n let errorMessageId;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n className={cx(\n classes.root,\n {\n [classes.disabled]: disabled,\n },\n className\n )}\n {...others}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n ref={dropdownForkedRef}\n id={setId(id, \"dropdown\")}\n classes={{\n root: cx(classes.dropdown, {\n [classes.readOnly]: readOnly,\n }),\n arrow: classes.arrow,\n header: cx(classes.dropdownHeader, {\n [classes.dropdownHeaderInvalid]: isStateInvalid,\n }),\n headerOpen: classes.dropdownHeaderOpen,\n }}\n expanded={isOpen}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n disablePortal={disablePortal}\n placement={placement}\n popperProps={popperProps}\n placeholder={buildHeaderLabel()}\n onToggle={handleToggle}\n onClickOutside={handleClickOutside}\n onContainerCreation={setFocusToContent}\n role=\"combobox\"\n variableWidth={variableWidth}\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-invalid={isStateInvalid ? true : undefined}\n aria-errormessage={errorMessageId}\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n onFocus={onFocus}\n onBlur={onBlur}\n dropdownHeaderRef={headerForkedRef}\n {...otherBaseDropdownProps}\n >\n <HvDropdownList\n id={setId(elementId, \"values\")}\n classes={{\n rootList: classes.rootList,\n dropdownListContainer: classes.dropdownListContainer,\n }}\n values={internalValues}\n multiSelect={multiSelect}\n showSearch={showSearch}\n onChange={handleSelection}\n onCancel={handleCancel}\n labels={labels}\n notifyChangesOnFirstRender={notifyChangesOnFirstRender}\n hasTooltips={hasTooltips}\n singleSelectionToggle={singleSelectionToggle}\n aria-label={ariaLabel}\n aria-labelledby={hasLabel ? setId(elementId, \"label\") : undefined}\n height={height}\n maxHeight={maxHeight}\n virtualized={virtualized}\n {...listProps}\n />\n </HvBaseDropdown>\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n }\n);\n"],"names":["DEFAULT_LABELS","select","undefined","selectAll","cancelLabel","applyLabel","searchPlaceholder","multiSelectionConjunction","HvDropdown","forwardRef","props","ref","classes","classesProp","className","id","name","required","disabled","readOnly","label","ariaLabel","ariaLabelledBy","description","ariaDescribedBy","placeholder","onChange","status","statusMessage","ariaErrorMessage","onCancel","onToggle","onClickOutside","onFocus","onBlur","values","multiSelect","showSearch","expanded","defaultExpanded","notifyChangesOnFirstRender","labels","labelsProp","hasTooltips","disablePortal","singleSelectionToggle","placement","variableWidth","popperProps","height","maxHeight","virtualized","baseDropdownProps","listProps","others","useDefaultProps","cx","useClasses","useLabels","elementId","useUniqueId","validationState","setValidationState","useControlled","validationMessage","isOpen","setIsOpen","Boolean","selectionLabel","setSelectionLabel","useState","getSelectionLabel","internalValues","setInternalValues","useEffect","dropdownHeaderRef","useRef","refProp","dropdownHeaderRefProp","otherBaseDropdownProps","headerForkedRef","useForkRef","dropdownForkedRef","handleToggle","event","open","hasSelection","getSelected","length","handleSelection","listValues","commitChanges","toggle","notifyChanges","selected","current","focus","preventScroll","handleCancel","evt","handleClickOutside","setFocusToContent","containerRef","inputs","getElementsByTagName","listItems","every","listItem","tabIndex","buildHeaderLabel","jsx","HvTypography","selectionDisabled","placeholderClosed","jsxs","total","hasLabel","hasDescription","canShowError","isStateInvalid","isInvalid","errorMessageId","setId","HvFormElement","root","labelContainer","HvLabel","HvInfoMessage","HvBaseDropdown","dropdown","arrow","header","dropdownHeader","dropdownHeaderInvalid","headerOpen","dropdownHeaderOpen","join","trim","HvDropdownList","rootList","dropdownListContainer","HvWarningText","error"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuMA,MAAMA,iBAAwC;AAAA,EAC5CC,QAAQC;AAAAA,EACRC,WAAW;AAAA,EACXC,aAAa;AAAA,EACbC,YAAY;AAAA,EACZC,mBAAmB;AAAA,EACnBC,2BAA2B;AAC7B;AAKO,MAAMC,aAAaC,MAAAA,WACxB,CAACC,OAAOC,QAAQ;AACR,QAAA;AAAA,IACJC,SAASC;AAAAA,IACTC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IAEAC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IAEXC;AAAAA,IACA,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnBC;AAAAA,IACA,oBAAoBC;AAAAA,IAEpBC,cAAc;AAAA,IAEdC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IACA,qBAAqBC;AAAAA,IAErBC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IAEAC;AAAA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De,YAAY1H,QAAQ2H;AAAAA,IAAAA,GAEtB,UAAUtE,QACV,UACA,UACA,UACA,eACA,WACA,aACA,aAAa4C,iBAAiB,GAC9B,UAAU1B,cACV,gBAAgBiB,oBAChB,qBAAqBC,mBACrB,MAAK,YACL,eACA,cAAYhF,WACZ,mBACE,CAACD,SAASsG,MAAAA,MAAM/D,WAAW,OAAO,GAAGrC,cAAc,EAChDkH,KAAK,GAAG,EACRC,UAAUvI,QAEf,gBAAcqH,iBAAiB,OAAOrH,QACtC,qBAAmBuH,gBACnB,oBACE,CAAClG,eAAemG,MAAAA,MAAM/D,WAAW,aAAa,GAAGnC,eAAe,EAC7DgH,KAAK,GAAG,EACRC,KAAAA,KAAUvI,QAEf,SACA,QACA,mBAAmB8E,iBACnB,GAAID,wBAEJ,UAAA+B,2BAAAA,IAAC4B,KAAAA,kBACC,IAAIhB,MAAAA,MAAM/D,WAAW,QAAQ,GAC7B,SAAS;AAAA,MACPgF,UAAU/H,QAAQ+H;AAAAA,MAClBC,uBAAuBhI,QAAQgI;AAAAA,IACjC,GACA,QAAQpE,gBACR,aACA,YACA,UAAUiB,iBACV,UAAUS,cACV,QACA,4BACA,aACA,uBACA,cAAY7E,WACZ,mBAAiB+F,WAAWM,MAAAA,MAAM/D,WAAW,OAAO,IAAIzD,QACxD,QACA,WACA,aACImD,GAAAA,UAAAA,CAAU,EAElB,CAAA;AAAA,IACCiE,gBACCR,2BAAA,IAAC+B,YACC,eAAA,EAAA,IAAInB,MAAAA,MAAM/D,WAAW,OAAO,GAC5B,eAAa,MACb,WAAW/C,QAAQkI,OAElB9E,UACH,mBAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,CACF;;;"}
|
|
1
|
+
{"version":3,"file":"Dropdown.cjs","sources":["../../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import { forwardRef, useEffect, useRef, useState } from \"react\";\n\nimport { PopperProps, useForkRef } from \"@mui/material\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { setId } from \"@core/utils/setId\";\nimport { useLabels, useUniqueId, useControlled } from \"@core/hooks\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport {\n HvBaseDropdown,\n HvBaseDropdownProps,\n} from \"@core/components/BaseDropdown\";\nimport { HvListValue } from \"@core/components/List\";\nimport {\n isInvalid,\n HvInfoMessage,\n HvWarningText,\n HvFormElement,\n HvLabel,\n} from \"@core/components/Forms\";\nimport { ExtractNames } from \"@core/utils/classes\";\nimport { HvTypography } from \"@core/components/Typography\";\n\nimport { getSelected, getSelectionLabel } from \"./utils\";\nimport { HvDropdownList, HvDropdownListProps } from \"./List\";\nimport { staticClasses, useClasses } from \"./Dropdown.styles\";\nimport { HvDropdownLabelsProps, HvDropdownStatus } from \"./types\";\n\nexport { staticClasses as dropdownClasses };\n\nexport type HvDropdownClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDropdownProps\n extends HvBaseProps<HTMLDivElement, \"onChange\"> {\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvDropdownClasses;\n /**\n * The form element name.\n */\n name?: string;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: any;\n /**\n * Provide additional descriptive text for the form element.\n */\n description?: any;\n /**\n * The placeholder value when nothing is selected.\n */\n placeholder?: string;\n /**\n * Indicates that the form element is disabled.\n */\n disabled?: boolean;\n /**\n * Indicates that the form element is in read only mode.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n */\n required?: boolean;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvDropdownStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: any;\n /**\n * Identifies the element that provides an error message for the dropdown.\n *\n * Will only be used when the validation status is invalid.\n */\n \"aria-errormessage\"?: string;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (selected: HvListValue | HvListValue[] | undefined) => void;\n /**\n * The list to be rendered by the dropdown.\n */\n values?: HvListValue[];\n /**\n * If `true` the dropdown is multiSelect, if `false` the dropdown is single select.\n */\n multiSelect?: boolean;\n /**\n * If `true` the dropdown is rendered with a search bar, if `false` there won't be a search bar.\n */\n showSearch?: boolean;\n /**\n * If `true` the dropdown starts opened if `false` it starts closed.\n */\n expanded?: boolean;\n /**\n * When uncontrolled, defines the initial expanded state.\n */\n defaultExpanded?: boolean;\n /**\n * If 'true' the dropdown will notify on the first render.\n */\n notifyChangesOnFirstRender?: boolean;\n /**\n * An object containing all the labels for the dropdown.\n */\n labels?: HvDropdownLabelsProps;\n /**\n * If `true` the dropdown will show tooltips when user mouseenter text in list\n */\n hasTooltips?: boolean;\n /**\n * Disable the portal behavior.\n * The children stay within it's parent DOM hierarchy.\n */\n disablePortal?: boolean;\n /**\n * If `true` the dropdown width depends size of content if `false` the width depends on the header size.\n * Defaults to `false`.\n */\n variableWidth?: boolean;\n /**\n * If `true`, selection can be toggled when single selection.\n */\n singleSelectionToggle?: boolean;\n /**\n * Placement of the dropdown.\n */\n placement?: \"left\" | \"right\";\n /**\n * An object containing props to be wired to the popper component.\n */\n popperProps?: Partial<PopperProps>;\n /**\n * Callback called when the user cancels the changes.\n *\n * Called when the cancel button is used and when the user clicks outside the open container.\n *\n * @param {object} event The event source of the callback.\n */\n onCancel?: (event: Event) => void;\n /**\n * Callback called when dropdown changes the expanded state.\n *\n * @param {object} event The event source of the callback.\n * @param {boolean} open If the dropdown new state is open (`true`) or closed (`false`).\n */\n onToggle?: (event: Event, open: boolean) => void;\n /**\n * Callback called when the user clicks outside the open container.\n *\n * @param {object} event The event source of the callback.\n */\n onClickOutside?: (event: Event) => void;\n /**\n * @ignore\n */\n onFocus?: React.FocusEventHandler<any>;\n /**\n * @ignore\n */\n onBlur?: React.FocusEventHandler<any>;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n height?: number;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n maxHeight?: number;\n /**\n * Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options.\n */\n virtualized?: boolean;\n /**\n * Extra props passed to the dropdown.\n */\n baseDropdownProps?: Partial<HvBaseDropdownProps>;\n /**\n * Extra props passed to the list.\n */\n listProps?: HvDropdownListProps;\n}\n\nconst DEFAULT_LABELS: HvDropdownLabelsProps = {\n select: undefined,\n selectAll: \"All\",\n cancelLabel: \"Cancel\",\n applyLabel: \"Apply\",\n searchPlaceholder: \"Search\",\n multiSelectionConjunction: \"/\",\n};\n\n/**\n * A dropdown list is a graphical control element, similar to a list box, that allows the user to choose one value from a list.\n */\nexport const HvDropdown = forwardRef<HTMLDivElement, HvDropdownProps>(\n (props, ref) => {\n const {\n classes: classesProp,\n className,\n\n id,\n name,\n\n required = false,\n disabled = false,\n readOnly = false,\n\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n\n placeholder = \"Select...\",\n\n onChange,\n\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n\n onCancel,\n onToggle,\n onClickOutside,\n\n onFocus,\n onBlur,\n\n values,\n multiSelect = false,\n showSearch = false,\n expanded,\n defaultExpanded = false,\n notifyChangesOnFirstRender = false,\n labels: labelsProp,\n hasTooltips = false,\n disablePortal = false,\n singleSelectionToggle = true,\n placement,\n variableWidth = false,\n popperProps = {},\n height,\n maxHeight,\n virtualized = false,\n baseDropdownProps = {},\n listProps = {},\n ...others\n } = useDefaultProps(\"HvDropdown\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const elementId = useUniqueId(id, \"hvdropdown\");\n\n const [validationState, setValidationState] = useControlled(\n status,\n \"standBy\"\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const [isOpen, setIsOpen] = useControlled(\n expanded,\n Boolean(defaultExpanded)\n );\n const [selectionLabel, setSelectionLabel] = useState(\n getSelectionLabel(labels, placeholder, multiSelect, values)\n );\n\n const [internalValues, setInternalValues] = useState(values);\n\n // Hack - Keeping track of internal values for validation purposes since useState is async\n const internalValuesRef = useRef(values);\n\n useEffect(() => {\n setInternalValues(values);\n internalValuesRef.current = values;\n }, [values]);\n\n useEffect(() => {\n setSelectionLabel(\n getSelectionLabel(labels, placeholder, multiSelect, values)\n );\n }, [labels, multiSelect, placeholder, values]);\n\n if (import.meta.env.DEV && virtualized && !height) {\n // eslint-disable-next-line no-console\n console.error(\n \"Dropdown/List in virtualized mode requires a height. Please define it.\"\n );\n }\n\n const dropdownHeaderRef = useRef<HTMLDivElement>();\n\n const {\n ref: refProp,\n dropdownHeaderRef: dropdownHeaderRefProp,\n ...otherBaseDropdownProps\n } = baseDropdownProps;\n const headerForkedRef = useForkRef(\n dropdownHeaderRefProp,\n dropdownHeaderRef\n );\n\n const dropdownForkedRef = useForkRef(ref, refProp);\n\n const handleToggle: HvBaseDropdownProps[\"onToggle\"] = (event, open) => {\n onToggle?.(event, open);\n\n setIsOpen(open);\n\n if (!open) {\n // also run built-in validation when closing without changes\n // as the user \"touched\" the input\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required) {\n const hasSelection =\n getSelected(internalValuesRef.current).length > 0;\n\n if (!hasSelection) {\n return \"invalid\";\n }\n }\n\n return \"valid\";\n });\n }\n };\n\n /** Applies the selected values to the state */\n const handleSelection: HvDropdownListProps[\"onChange\"] = (\n listValues,\n commitChanges,\n toggle,\n notifyChanges = true\n ) => {\n const selected = getSelected(listValues);\n\n if (commitChanges) {\n setInternalValues(listValues);\n internalValuesRef.current = listValues;\n\n setSelectionLabel(\n getSelectionLabel(labels, placeholder, multiSelect, listValues)\n );\n\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required && selected.length === 0) {\n return \"invalid\";\n }\n\n return \"valid\";\n });\n }\n if (notifyChanges) onChange?.(multiSelect ? selected : selected[0]);\n if (toggle) {\n handleToggle(undefined as any, false);\n\n // focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n dropdownHeaderRef.current?.focus({ preventScroll: true });\n }\n };\n\n /**\n * Handles the `Cancel` action. Both single and ranged modes are handled here.\n */\n const handleCancel: HvDropdownListProps[\"onCancel\"] = (evt) => {\n onCancel?.(evt as any);\n\n handleToggle(evt as any, false);\n\n // focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n dropdownHeaderRef.current?.focus({ preventScroll: true });\n };\n\n const handleClickOutside: HvBaseDropdownProps[\"onClickOutside\"] = (evt) => {\n onClickOutside?.(evt);\n onCancel?.(evt);\n };\n\n const setFocusToContent: HvBaseDropdownProps[\"onContainerCreation\"] = (\n containerRef\n ) => {\n const inputs = containerRef?.getElementsByTagName(\"input\");\n if (inputs && inputs.length > 0) {\n inputs[0].focus();\n return;\n }\n const listItems =\n containerRef != null\n ? [...containerRef.getElementsByTagName(\"li\")]\n : [];\n listItems.every((listItem) => {\n if (listItem.tabIndex >= 0) {\n listItem.focus();\n return false;\n }\n return true;\n });\n };\n\n const buildHeaderLabel = () => {\n const hasSelection = getSelected(internalValues).length > 0;\n return labels?.select || !multiSelect ? (\n <HvTypography\n component=\"div\"\n variant=\"body\"\n className={cx(classes.placeholder, {\n [classes.selectionDisabled]: disabled,\n [classes.placeholderClosed]: !(isOpen || hasSelection),\n })}\n >\n {selectionLabel.selected}\n </HvTypography>\n ) : (\n <HvTypography\n component=\"div\"\n className={cx(classes.placeholder, {\n [classes.selectionDisabled]: disabled,\n })}\n variant=\"body\"\n >\n <b>{selectionLabel.selected}</b>\n {` ${labels?.multiSelectionConjunction} ${selectionLabel.total}`}\n </HvTypography>\n );\n };\n\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n // the error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and required is true\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined && required));\n\n const isStateInvalid = isInvalid(validationState);\n\n let errorMessageId;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n className={cx(\n classes.root,\n {\n [classes.disabled]: disabled,\n },\n className\n )}\n {...others}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n ref={dropdownForkedRef}\n id={setId(id, \"dropdown\")}\n classes={{\n root: cx(classes.dropdown, {\n [classes.readOnly]: readOnly,\n }),\n arrow: classes.arrow,\n header: cx(classes.dropdownHeader, {\n [classes.dropdownHeaderInvalid]: isStateInvalid,\n }),\n headerOpen: classes.dropdownHeaderOpen,\n }}\n expanded={isOpen}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n disablePortal={disablePortal}\n placement={placement}\n popperProps={popperProps}\n placeholder={buildHeaderLabel()}\n onToggle={handleToggle}\n onClickOutside={handleClickOutside}\n onContainerCreation={setFocusToContent}\n role=\"combobox\"\n variableWidth={variableWidth}\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-invalid={isStateInvalid ? true : undefined}\n aria-errormessage={errorMessageId}\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n onFocus={onFocus}\n onBlur={onBlur}\n dropdownHeaderRef={headerForkedRef}\n {...otherBaseDropdownProps}\n >\n <HvDropdownList\n id={setId(elementId, \"values\")}\n classes={{\n rootList: classes.rootList,\n dropdownListContainer: classes.dropdownListContainer,\n }}\n values={internalValues}\n multiSelect={multiSelect}\n showSearch={showSearch}\n onChange={handleSelection}\n onCancel={handleCancel}\n labels={labels}\n notifyChangesOnFirstRender={notifyChangesOnFirstRender}\n hasTooltips={hasTooltips}\n singleSelectionToggle={singleSelectionToggle}\n aria-label={ariaLabel}\n aria-labelledby={hasLabel ? setId(elementId, \"label\") : undefined}\n height={height}\n maxHeight={maxHeight}\n virtualized={virtualized}\n {...listProps}\n />\n </HvBaseDropdown>\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n }\n);\n"],"names":["DEFAULT_LABELS","select","undefined","selectAll","cancelLabel","applyLabel","searchPlaceholder","multiSelectionConjunction","HvDropdown","forwardRef","props","ref","classes","classesProp","className","id","name","required","disabled","readOnly","label","ariaLabel","ariaLabelledBy","description","ariaDescribedBy","placeholder","onChange","status","statusMessage","ariaErrorMessage","onCancel","onToggle","onClickOutside","onFocus","onBlur","values","multiSelect","showSearch","expanded","defaultExpanded","notifyChangesOnFirstRender","labels","labelsProp","hasTooltips","disablePortal","singleSelectionToggle","placement","variableWidth","popperProps","height","maxHeight","virtualized","baseDropdownProps","listProps","others","useDefaultProps","cx","useClasses","useLabels","elementId","useUniqueId","validationState","setValidationState","useControlled","validationMessage","isOpen","setIsOpen","Boolean","selectionLabel","setSelectionLabel","useState","getSelectionLabel","internalValues","setInternalValues","internalValuesRef","useRef","useEffect","current","dropdownHeaderRef","refProp","dropdownHeaderRefProp","otherBaseDropdownProps","headerForkedRef","useForkRef","dropdownForkedRef","handleToggle","event","open","hasSelection","getSelected","length","handleSelection","listValues","commitChanges","toggle","notifyChanges","selected","focus","preventScroll","handleCancel","evt","handleClickOutside","setFocusToContent","containerRef","inputs","getElementsByTagName","listItems","every","listItem","tabIndex","buildHeaderLabel","jsx","HvTypography","selectionDisabled","placeholderClosed","jsxs","total","hasLabel","hasDescription","canShowError","isStateInvalid","isInvalid","errorMessageId","setId","HvFormElement","root","labelContainer","HvLabel","HvInfoMessage","HvBaseDropdown","dropdown","arrow","header","dropdownHeader","dropdownHeaderInvalid","headerOpen","dropdownHeaderOpen","join","trim","HvDropdownList","rootList","dropdownListContainer","HvWarningText","error"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuMA,MAAMA,iBAAwC;AAAA,EAC5CC,QAAQC;AAAAA,EACRC,WAAW;AAAA,EACXC,aAAa;AAAA,EACbC,YAAY;AAAA,EACZC,mBAAmB;AAAA,EACnBC,2BAA2B;AAC7B;AAKO,MAAMC,aAAaC,MAAAA,WACxB,CAACC,OAAOC,QAAQ;AACR,QAAA;AAAA,IACJC,SAASC;AAAAA,IACTC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IAEAC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IAEXC;AAAAA,IACA,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnBC;AAAAA,IACA,oBAAoBC;AAAAA,IAEpBC,cAAc;AAAA,IAEdC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IACA,qBAAqBC;AAAAA,IAErBC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IAEAC;AAAAA,IACAC,cAAc;AAAA,IACdC,aAAa;AAAA,IACbC;AAAAA,IACAC,kBAAkB;AAAA,IAClBC,6BAA6B;AAAA,IAC7BC,QAAQC;AAAAA,IACRC,cAAc;AAAA,IACdC,gBAAgB;AAAA,IAChBC,wBAAwB;AAAA,IACxBC;AAAAA,IACAC,gBAAgB;AA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B,UAAUzB,cACV,gBAAgBgB,oBAChB,qBAAqBC,mBACrB,MAAK,YACL,eACA,cAAYjF,WACZ,mBACE,CAACD,SAASuG,MAAAA,MAAMhE,WAAW,OAAO,GAAGrC,cAAc,EAChDmH,KAAK,GAAG,EACRC,UAAUxI,QAEf,gBAAcsH,iBAAiB,OAAOtH,QACtC,qBAAmBwH,gBACnB,oBACE,CAACnG,eAAeoG,MAAAA,MAAMhE,WAAW,aAAa,GAAGnC,eAAe,EAC7DiH,KAAK,GAAG,EACRC,KAAAA,KAAUxI,QAEf,SACA,QACA,mBAAmBgF,iBACnB,GAAID,wBAEJ,UAAA8B,2BAAAA,IAAC4B,KAAAA,kBACC,IAAIhB,MAAAA,MAAMhE,WAAW,QAAQ,GAC7B,SAAS;AAAA,MACPiF,UAAUhI,QAAQgI;AAAAA,MAClBC,uBAAuBjI,QAAQiI;AAAAA,IACjC,GACA,QAAQrE,gBACR,aACA,YACA,UAAUmB,iBACV,UAAUQ,cACV,QACA,4BACA,aACA,uBACA,cAAY9E,WACZ,mBAAiBgG,WAAWM,MAAAA,MAAMhE,WAAW,OAAO,IAAIzD,QACxD,QACA,WACA,aACImD,GAAAA,UAAAA,CAAU,EAElB,CAAA;AAAA,IACCkE,gBACCR,2BAAA,IAAC+B,YACC,eAAA,EAAA,IAAInB,MAAAA,MAAMhE,WAAW,OAAO,GAC5B,eAAa,MACb,WAAW/C,QAAQmI,OAElB/E,UACH,mBAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,CACF;;;"}
|
|
@@ -273,6 +273,7 @@ const HvQueryBuilderContext = React.createContext({
|
|
|
273
273
|
maxDepth: 1,
|
|
274
274
|
labels: defaultLabels,
|
|
275
275
|
initialTouched: false,
|
|
276
|
+
disableConfirmation: false,
|
|
276
277
|
readOnly: false
|
|
277
278
|
});
|
|
278
279
|
const HvQueryBuilderProvider = ({
|
|
@@ -281,9 +282,13 @@ const HvQueryBuilderProvider = ({
|
|
|
281
282
|
}) => {
|
|
282
283
|
return /* @__PURE__ */ jsxRuntime.jsx(HvQueryBuilderContext.Provider, { value, children });
|
|
283
284
|
};
|
|
285
|
+
const useQueryBuilderContext = () => {
|
|
286
|
+
return React.useContext(HvQueryBuilderContext);
|
|
287
|
+
};
|
|
284
288
|
exports.HvQueryBuilderContext = HvQueryBuilderContext;
|
|
285
289
|
exports.HvQueryBuilderProvider = HvQueryBuilderProvider;
|
|
286
290
|
exports.defaultCombinators = defaultCombinators;
|
|
287
291
|
exports.defaultLabels = defaultLabels;
|
|
288
292
|
exports.defaultOperators = defaultOperators;
|
|
293
|
+
exports.useQueryBuilderContext = useQueryBuilderContext;
|
|
289
294
|
//# sourceMappingURL=Context.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.cjs","sources":["../../../../src/components/QueryBuilder/Context.tsx"],"sourcesContent":["import { createContext } from \"react\";\n\nimport {\n AskAction,\n HvQueryBuilderAttribute,\n QueryAction,\n HvQueryBuilderLabels,\n HvQueryBuilderQueryCombinator,\n HvQueryBuilderQueryOperator,\n} from \"./types\";\n\nexport const defaultOperators = {\n numeric: [\n {\n operator: \"greaterThan\",\n label: \"Greater than (>)\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThan\",\n label: \"Less than (<)\",\n combinators: [\"and\"],\n },\n {\n operator: \"equalsTo\",\n label: \"Equal to (=)\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"greaterThanEq\",\n label: \"Greater than or equal to (>=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThanEq\",\n label: \"Less than or equal to (<=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"notEqual\",\n label: \"Not equal to (!=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"range\",\n label: \"Range\",\n combinators: [\"and\"],\n },\n ],\n text: [\n {\n operator: \"equals\",\n label: \"Equals\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"equalsIgnoreCase\",\n label: \"Equals Ignore Case\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"Contains\",\n label: \"Contains\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"StartsWith\",\n label: \"A string begins with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"EndsWith\",\n label: \"A string ends with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"IsNotEmpty\",\n label: \"Is Not empty\",\n combinators: [\"and\"],\n },\n {\n operator: \"IsNot\",\n label: \"Is Not\",\n combinators: [\"and\"],\n },\n {\n operator: \"Empty\",\n label: \"Empty\",\n combinators: [\"and\"],\n },\n ],\n textarea: [\n {\n operator: \"equals\",\n label: \"Equals\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"equalsIgnoreCase\",\n label: \"Equals Ignore Case\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"Contains\",\n label: \"Contains\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"StartsWith\",\n label: \"A string begins with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"EndsWith\",\n label: \"A string ends with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"IsNotEmpty\",\n label: \"Is Not empty\",\n combinators: [\"and\"],\n },\n {\n operator: \"IsNot\",\n label: \"Is Not\",\n combinators: [\"and\"],\n },\n {\n operator: \"Empty\",\n label: \"Empty\",\n combinators: [\"and\"],\n },\n ],\n boolean: [\n {\n operator: \"equalsTo\",\n label: \"=\",\n combinators: [\"and\", \"or\"],\n },\n ],\n dateandtime: [\n {\n operator: \"greaterThan\",\n label: \"Greater than\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThan\",\n label: \"Less than\",\n combinators: [\"and\"],\n },\n {\n operator: \"equalsTo\",\n label: \"Equal to\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"greaterThanEq\",\n label: \"Greater than or equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThanEq\",\n label: \"Less than or equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"notEqual\",\n label: \"Not equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"range\",\n label: \"Range\",\n combinators: [\"and\"],\n },\n ],\n};\n\nexport const defaultCombinators = [\n { operand: \"and\", label: \"AND\" },\n { operand: \"or\", label: \"OR\" },\n];\n\nexport const defaultLabels = {\n query: {\n delete: {\n ariaLabel: \"Reset query\",\n tooltip: \"Reset query\",\n dialogTitle: \"Remove all conditions?\",\n dialogMessage:\n \"Are you sure you want to remove all the conditions? They will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n },\n rule: {\n attribute: {\n label: \"Attribute\",\n placeholder: \"Select attribute...\",\n exists: \"Attribute already exists.\",\n },\n operator: {\n label: \"Operator\",\n placeholder: \"Select operator...\",\n },\n value: {\n distance: {\n label: \"Value\",\n connectorText: \"radius miles from\",\n button: \"Select location\",\n validation: {\n required: \"The value is required.\",\n invalid: \"Value must be a positive number.\",\n },\n },\n text: {\n label: \"Value\",\n placeholder: \"Enter value...\",\n validation: {\n required: \"The value is required.\",\n },\n },\n boolean: {\n label: \"Value\",\n placeholder: \"Enter value\",\n options: {\n true: \"True\",\n false: \"False\",\n },\n },\n numeric: {\n label: \"Value\",\n placeholder: \"Enter value\",\n validation: {\n required: \"The value is required.\",\n invalid: \"Value must be a number.\",\n equal: \"Cannot be equal.\",\n greaterThan: \"Needs to be greater.\",\n },\n range: {\n leftLabel: \"From\",\n rightLabel: \"To\",\n },\n },\n datetime: {\n dateLabel: \"Date\",\n datePlaceholder: \"Select Date\",\n timeLabel: \"Time\",\n timePlaceholder: \"Select Time\",\n startDateLabel: \"Start Date\",\n startDatePlaceholder: \"Select Start Date\",\n startTimeLabel: \"Start Time\",\n startTimePlaceholder: \"Select Start Time\",\n endDateLabel: \"End Date\",\n endDatePlaceholder: \"Select End Date\",\n endTimeLabel: \"End Time\",\n endTimePlaceholder: \"Select End Time\",\n validation: {\n required: \"The value is required.\",\n invalidInterval:\n \"End date and time must be after start date and time.\",\n },\n },\n },\n delete: {\n ariaLabel: \"Remove condition\",\n tooltip: \"Remove condition\",\n dialogTitle: \"Remove condition?\",\n dialogMessage:\n \"Are you sure you want to remove the condition? It will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n },\n group: {\n delete: {\n ariaLabel: \"Remove group\",\n tooltip: \"Remove group\",\n dialogTitle: \"Remove group?\",\n dialogMessage:\n \"Are you sure you want to remove the group? It will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n reset: {\n ariaLabel: \"Change operator\",\n tooltip: \"Change operator query\",\n dialogTitle: \"Change conditional operator?\",\n dialogMessage:\n \"Do you want to change conditional operator? You won't be able to undo this operation. Conditions and/or groups will be removed.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n addRule: {\n label: \"Add condition\",\n },\n addGroup: {\n label: \"Add group\",\n },\n },\n empty: {\n title: \"No conditions created yet\",\n createCondition: \"Create a condition\",\n createGroup: \"condition group\",\n spacer: \" or a \",\n },\n};\n\nexport interface HvQueryBuilderContextValue {\n dispatchAction: React.Dispatch<QueryAction>;\n askAction: React.Dispatch<React.SetStateAction<AskAction | undefined>>;\n selectLocation?: React.Dispatch<unknown>;\n attributes?: Record<string, HvQueryBuilderAttribute>;\n operators: Record<string, HvQueryBuilderQueryOperator[]>;\n combinators: HvQueryBuilderQueryCombinator[];\n maxDepth: number;\n labels: HvQueryBuilderLabels;\n initialTouched: boolean;\n readOnly: boolean;\n}\n\nexport const HvQueryBuilderContext = createContext<HvQueryBuilderContextValue>({\n dispatchAction: () => ({}),\n askAction: () => ({}),\n selectLocation: () => ({}),\n attributes: {},\n operators: defaultOperators,\n combinators: defaultCombinators,\n maxDepth: 1,\n labels: defaultLabels,\n initialTouched: false,\n readOnly: false,\n});\n\nexport interface HvQueryBuilderProviderProps {\n value: HvQueryBuilderContextValue;\n children: React.ReactNode;\n}\n\nexport const HvQueryBuilderProvider = ({\n children,\n value,\n}: HvQueryBuilderProviderProps) => {\n return (\n <HvQueryBuilderContext.Provider value={value}>\n {children}\n </HvQueryBuilderContext.Provider>\n );\n};\n"],"names":["defaultOperators","numeric","operator","label","combinators","text","textarea","boolean","dateandtime","defaultCombinators","operand","defaultLabels","query","delete","ariaLabel","tooltip","dialogTitle","dialogMessage","dialogConfirm","dialogCancel","dialogCloseTooltip","rule","attribute","placeholder","exists","value","distance","connectorText","button","validation","required","invalid","options","true","false","equal","greaterThan","range","leftLabel","rightLabel","datetime","dateLabel","datePlaceholder","timeLabel","timePlaceholder","startDateLabel","startDatePlaceholder","startTimeLabel","startTimePlaceholder","endDateLabel","endDatePlaceholder","endTimeLabel","endTimePlaceholder","invalidInterval","group","reset","addRule","addGroup","empty","title","createCondition","createGroup","spacer","HvQueryBuilderContext","createContext","dispatchAction","askAction","selectLocation","attributes","operators","maxDepth","labels","initialTouched","readOnly","HvQueryBuilderProvider","children","jsx"],"mappings":";;;;AAWO,MAAMA,mBAAmB;AAAA,EAC9BC,SAAS,CACP;AAAA,IACEC,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,OAAO,IAAI;AAAA,EAAA,GAE3B;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,U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AA,IAAA,sBAAsB,UAAtB,EAA+B,OAC7BD,SACH,CAAA;AAEJ;;;;;;"}
|
|
1
|
+
{"version":3,"file":"Context.cjs","sources":["../../../../src/components/QueryBuilder/Context.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\n\nimport {\n AskAction,\n HvQueryBuilderAttribute,\n QueryAction,\n HvQueryBuilderLabels,\n HvQueryBuilderQueryCombinator,\n HvQueryBuilderQueryOperator,\n HvQueryBuilderRenderers,\n} from \"./types\";\n\nexport const defaultOperators = {\n numeric: [\n {\n operator: \"greaterThan\",\n label: \"Greater than (>)\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThan\",\n label: \"Less than (<)\",\n combinators: [\"and\"],\n },\n {\n operator: \"equalsTo\",\n label: \"Equal to (=)\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"greaterThanEq\",\n label: \"Greater than or equal to (>=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThanEq\",\n label: \"Less than or equal to (<=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"notEqual\",\n label: \"Not equal to (!=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"range\",\n label: \"Range\",\n combinators: [\"and\"],\n },\n ],\n text: [\n {\n operator: \"equals\",\n label: \"Equals\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"equalsIgnoreCase\",\n label: \"Equals Ignore Case\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"Contains\",\n label: \"Contains\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"StartsWith\",\n label: \"A string begins with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"EndsWith\",\n label: \"A string ends with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"IsNotEmpty\",\n label: \"Is Not empty\",\n combinators: [\"and\"],\n },\n {\n operator: \"IsNot\",\n label: \"Is Not\",\n combinators: [\"and\"],\n },\n {\n operator: \"Empty\",\n label: \"Empty\",\n combinators: [\"and\"],\n },\n ],\n textarea: [\n {\n operator: \"equals\",\n label: \"Equals\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"equalsIgnoreCase\",\n label: \"Equals Ignore Case\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"Contains\",\n label: \"Contains\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"StartsWith\",\n label: \"A string begins with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"EndsWith\",\n label: \"A string ends with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"IsNotEmpty\",\n label: \"Is Not empty\",\n combinators: [\"and\"],\n },\n {\n operator: \"IsNot\",\n label: \"Is Not\",\n combinators: [\"and\"],\n },\n {\n operator: \"Empty\",\n label: \"Empty\",\n combinators: [\"and\"],\n },\n ],\n boolean: [\n {\n operator: \"equalsTo\",\n label: \"=\",\n combinators: [\"and\", \"or\"],\n },\n ],\n dateandtime: [\n {\n operator: \"greaterThan\",\n label: \"Greater than\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThan\",\n label: \"Less than\",\n combinators: [\"and\"],\n },\n {\n operator: \"equalsTo\",\n label: \"Equal to\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"greaterThanEq\",\n label: \"Greater than or equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThanEq\",\n label: \"Less than or equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"notEqual\",\n label: \"Not equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"range\",\n label: \"Range\",\n combinators: [\"and\"],\n },\n ],\n};\n\nexport const defaultCombinators = [\n { operand: \"and\", label: \"AND\" },\n { operand: \"or\", label: \"OR\" },\n];\n\nexport const defaultLabels = {\n query: {\n delete: {\n ariaLabel: \"Reset query\",\n tooltip: \"Reset query\",\n dialogTitle: \"Remove all conditions?\",\n dialogMessage:\n \"Are you sure you want to remove all the conditions? They will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n },\n rule: {\n attribute: {\n label: \"Attribute\",\n placeholder: \"Select attribute...\",\n exists: \"Attribute already exists.\",\n },\n operator: {\n label: \"Operator\",\n placeholder: \"Select operator...\",\n },\n value: {\n distance: {\n label: \"Value\",\n connectorText: \"radius miles from\",\n button: \"Select location\",\n validation: {\n required: \"The value is required.\",\n invalid: \"Value must be a positive number.\",\n },\n },\n text: {\n label: \"Value\",\n placeholder: \"Enter value...\",\n validation: {\n required: \"The value is required.\",\n },\n },\n boolean: {\n label: \"Value\",\n placeholder: \"Enter value\",\n options: {\n true: \"True\",\n false: \"False\",\n },\n },\n numeric: {\n label: \"Value\",\n placeholder: \"Enter value\",\n validation: {\n required: \"The value is required.\",\n invalid: \"Value must be a number.\",\n equal: \"Cannot be equal.\",\n greaterThan: \"Needs to be greater.\",\n },\n range: {\n leftLabel: \"From\",\n rightLabel: \"To\",\n },\n },\n datetime: {\n dateLabel: \"Date\",\n datePlaceholder: \"Select Date\",\n timeLabel: \"Time\",\n timePlaceholder: \"Select Time\",\n startDateLabel: \"Start Date\",\n startDatePlaceholder: \"Select Start Date\",\n startTimeLabel: \"Start Time\",\n startTimePlaceholder: \"Select Start Time\",\n endDateLabel: \"End Date\",\n endDatePlaceholder: \"Select End Date\",\n endTimeLabel: \"End Time\",\n endTimePlaceholder: \"Select End Time\",\n validation: {\n required: \"The value is required.\",\n invalidInterval:\n \"End date and time must be after start date and time.\",\n },\n },\n },\n delete: {\n ariaLabel: \"Remove condition\",\n tooltip: \"Remove condition\",\n dialogTitle: \"Remove condition?\",\n dialogMessage:\n \"Are you sure you want to remove the condition? It will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n },\n group: {\n delete: {\n ariaLabel: \"Remove group\",\n tooltip: \"Remove group\",\n dialogTitle: \"Remove group?\",\n dialogMessage:\n \"Are you sure you want to remove the group? It will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n reset: {\n ariaLabel: \"Change operator\",\n tooltip: \"Change operator query\",\n dialogTitle: \"Change conditional operator?\",\n dialogMessage:\n \"Do you want to change conditional operator? You won't be able to undo this operation. Conditions and/or groups will be removed.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n addRule: {\n label: \"Add condition\",\n },\n addGroup: {\n label: \"Add group\",\n },\n },\n empty: {\n title: \"No conditions created yet\",\n createCondition: \"Create a condition\",\n createGroup: \"condition group\",\n spacer: \" or a \",\n },\n};\n\nexport interface HvQueryBuilderContextValue {\n dispatchAction: React.Dispatch<QueryAction>;\n askAction: React.Dispatch<React.SetStateAction<AskAction | undefined>>;\n selectLocation?: React.Dispatch<unknown>;\n attributes?: Record<string, HvQueryBuilderAttribute>;\n operators: Record<string, HvQueryBuilderQueryOperator[]>;\n combinators: HvQueryBuilderQueryCombinator[];\n maxDepth: number;\n labels: HvQueryBuilderLabels;\n initialTouched: boolean;\n readOnly: boolean;\n disableConfirmation: boolean;\n renderers?: HvQueryBuilderRenderers;\n}\n\nexport const HvQueryBuilderContext = createContext<HvQueryBuilderContextValue>({\n dispatchAction: () => ({}),\n askAction: () => ({}),\n selectLocation: () => ({}),\n attributes: {},\n operators: defaultOperators,\n combinators: defaultCombinators,\n maxDepth: 1,\n labels: defaultLabels,\n initialTouched: false,\n disableConfirmation: false,\n readOnly: false,\n});\n\nexport interface HvQueryBuilderProviderProps {\n value: HvQueryBuilderContextValue;\n children: React.ReactNode;\n}\n\nexport const HvQueryBuilderProvider = ({\n children,\n value,\n}: HvQueryBuilderProviderProps) => {\n return (\n <HvQueryBuilderContext.Provider value={value}>\n {children}\n </HvQueryBuilderContext.Provider>\n );\n};\n\nexport const useQueryBuilderContext = () => {\n return useContext(HvQueryBuilderContext);\n};\n"],"names":["defaultOperators","numeric","operator","label","combinators","text","textarea","boolean","dateandtime","defaultCombinators","operand","defaultLabels","query","delete","ariaLabel","tooltip","dialogTitle","dialogMessage","dialogConfirm","dialogCancel","dialogCloseTooltip","rule","attribute","placeholder","exists","value","distance","connectorText","button","validation","required","invalid","options","true","false","equal","greaterThan","range","leftLabel","rightLabel","datetime","dateLabel","datePlaceholder","timeLabel","timePlaceholder","startDateLabel","startDatePlaceholder","startTimeLabel","startTimePlaceholder","endDateLabel","endDatePlaceholder","endTimeLabel","endTimePlaceholder","invalidInterval","group","reset","addRule","addGroup","empty","title","createCondition","createGroup","spacer","HvQueryBuilderContext","createContext","dispatchAction","askAction","selectLocation","attributes","operators","maxDepth","labels","initialTouched","disableConfirmation","readOnly","HvQueryBuilderProvider","children","jsx","useQueryBuilderContext","useContext"],"mappings":";;;;AAYO,MAAMA,mBAAmB;AAAA,EAC9BC,SAAS,CACP;AAAA,IACEC,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,OAAO,IAAI;AAAA,EAAA,GAE3B;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,CACpB;AAAA,EAEHC,MAAM,CACJ;AAAA,IACEH,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,OAAO,IAAI;AAAA,EAAA,GAE3B;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;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ual);
|
|
|
17
17
|
const HvQueryBuilder = (props) => {
|
|
18
18
|
const {
|
|
19
19
|
attributes,
|
|
20
|
+
renderers,
|
|
20
21
|
query,
|
|
21
22
|
onChange,
|
|
23
|
+
disableConfirmation = false,
|
|
22
24
|
operators = Context.defaultOperators,
|
|
23
25
|
combinators = Context.defaultCombinators,
|
|
24
26
|
maxDepth = 1,
|
|
@@ -48,8 +50,10 @@ const HvQueryBuilder = (props) => {
|
|
|
48
50
|
maxDepth,
|
|
49
51
|
labels,
|
|
50
52
|
initialTouched: initialState,
|
|
51
|
-
readOnly
|
|
52
|
-
|
|
53
|
+
readOnly,
|
|
54
|
+
renderers,
|
|
55
|
+
disableConfirmation
|
|
56
|
+
}), [attributes, operators, combinators, maxDepth, labels, readOnly, initialState, renderers, disableConfirmation]);
|
|
53
57
|
React.useEffect(() => {
|
|
54
58
|
if (currentAttributes.current == null) {
|
|
55
59
|
currentAttributes.current = attributes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.cjs","sources":["../../../../src/components/QueryBuilder/QueryBuilder.tsx"],"sourcesContent":["import { useEffect, useMemo, useReducer, useRef, useState } from \"react\";\nimport cloneDeep from \"lodash/cloneDeep\";\nimport isEqual from \"lodash/isEqual\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { ConfirmationDialog } from \"./ConfirmationDialog\";\nimport {\n HvQueryBuilderProvider,\n defaultCombinators,\n defaultLabels,\n defaultOperators,\n} from \"./Context\";\nimport { RuleGroup } from \"./RuleGroup\";\nimport {\n AskAction,\n HvQueryBuilderAttribute,\n HvQueryBuilderQuery,\n HvQueryBuilderLabels,\n HvQueryBuilderQueryCombinator,\n HvQueryBuilderQueryOperator,\n HvQueryBuilderChangedQuery,\n} from \"./types\";\nimport { clearNodeIds, emptyGroup } from \"./utils\";\nimport reducer from \"./utils/reducer\";\nimport { useClasses, staticClasses } from \"./QueryBuilder.styles\";\n\nexport { staticClasses as queryBuilderClasses };\n\nexport type HvQueryBuilderClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvQueryBuilderProps {\n /** The query attribute types. */\n attributes?: Record<string, HvQueryBuilderAttribute>;\n /** The query rules operators by attribute type and combinator. */\n operators?: Record<string, HvQueryBuilderQueryOperator[]>;\n /** The query combinators operands. */\n combinators?: HvQueryBuilderQueryCombinator[];\n /** The initial query representation. */\n query?: HvQueryBuilderQuery;\n /** Callback fired when query changes. */\n onChange?: (value: HvQueryBuilderChangedQuery) => void;\n /** Max depth of nested query groups. */\n maxDepth?: number;\n /** Object containing all the labels. */\n labels?: HvQueryBuilderLabels;\n /** Whether the query builder is in read-only mode. */\n readOnly?: boolean;\n /** A Jss Object used to override or extend the styles applied. */\n classes?: HvQueryBuilderClasses;\n}\n\n// TODO - v6\n// - uncontrolled vs controlled: users should be able to control the state\n// - \"query\" renamed to \"initialQuery\" and \"query\" used to control the state\n// - \"query\" provided with ids by the user but removed through \"onChange\"\n\n/**\n * This component allows you to create conditions and group them using logical operators.\n * It outputs a structured set of rules which can be easily parsed to create SQL/NoSQL/whatever queries.\n */\nexport const HvQueryBuilder = (props: HvQueryBuilderProps) => {\n const {\n attributes,\n query,\n onChange,\n operators = defaultOperators,\n combinators = defaultCombinators,\n maxDepth = 1,\n labels = defaultLabels,\n readOnly = false,\n classes: classesProp,\n } = useDefaultProps(\"HvQueryBuilder\", props);\n\n const { classes } = useClasses(classesProp);\n\n const currentAttributes = useRef<HvQueryBuilderProps[\"attributes\"] | null>(\n null\n );\n\n const initialQuery = useRef(query ?? emptyGroup());\n\n const [pendingAction, setPendingAction] = useState<AskAction>();\n const [prevState, setPrevState] = useState(initialQuery.current);\n const [initialState, setInitialState] = useState(true);\n\n const [state, dispatchAction] = useReducer(\n reducer,\n // Deep clone is needed to make sure that the \"query\" prop and \"initialQuery\" are not mutated\n cloneDeep(initialQuery.current)\n );\n\n const value = useMemo(\n () => ({\n dispatchAction,\n askAction: setPendingAction,\n attributes,\n operators,\n combinators,\n maxDepth,\n labels,\n initialTouched: initialState,\n readOnly,\n }),\n [\n attributes,\n operators,\n combinators,\n maxDepth,\n labels,\n readOnly,\n initialState,\n ]\n );\n\n // Keep track of attributes\n useEffect(() => {\n if (currentAttributes.current == null) {\n // First run, nothing to do\n currentAttributes.current = attributes;\n } else if (currentAttributes.current !== attributes) {\n // Attributes changed. The existing query is almost certainly invalid, so reset it\n currentAttributes.current = attributes;\n dispatchAction({ type: \"reset-query\" });\n }\n }, [attributes]);\n\n // Propagate the change if the query is modified\n useEffect(() => {\n if (!isEqual(state, prevState)) {\n if (initialState) {\n setInitialState(false);\n }\n\n onChange?.(clearNodeIds(state) as HvQueryBuilderChangedQuery);\n setPrevState(cloneDeep(state));\n }\n }, [initialState, onChange, prevState, state]);\n\n const handleConfirm = () => {\n if (pendingAction) {\n setPendingAction(undefined);\n pendingAction.actions.forEach((action) => dispatchAction(action));\n }\n };\n\n const handleCancel = () => {\n setPendingAction(undefined);\n };\n\n return (\n <HvQueryBuilderProvider value={value}>\n <RuleGroup\n level={0}\n id={state.id}\n combinator={state.combinator}\n rules={state.rules}\n classes={classes}\n />\n <ConfirmationDialog\n isOpen={pendingAction != null}\n onConfirm={handleConfirm}\n onCancel={handleCancel}\n title={pendingAction?.dialog.dialogTitle || \"\"}\n message={pendingAction?.dialog.dialogMessage || \"\"}\n confirmButtonLabel={pendingAction?.dialog.dialogConfirm || \"\"}\n cancelButtonLabel={pendingAction?.dialog.dialogCancel || \"\"}\n closeButtonTooltip={pendingAction?.dialog.dialogCloseTooltip || \"\"}\n />\n </HvQueryBuilderProvider>\n );\n};\n"],"names":["HvQueryBuilder","props","attributes","query","onChange","operators","defaultOperators","combinators","defaultCombinators","maxDepth","labels","defaultLabels","readOnly","classes","classesProp","useDefaultProps","useClasses","currentAttributes","useRef","initialQuery","emptyGroup","pendingAction","setPendingAction","useState","prevState","setPrevState","current","initialState","setInitialState","state","dispatchAction","useReducer","reducer","cloneDeep","value","useMemo","askAction","initialTouched","useEffect","type","isEqual","clearNodeIds","handleConfirm","undefined","actions","forEach","action","handleCancel","jsxs","HvQueryBuilderProvider","jsx","RuleGroup","id","combinator","rules","ConfirmationDialog","dialog","dialogTitle","dialogMessage","dialogConfirm","dialogCancel","dialogCloseTooltip"],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"QueryBuilder.cjs","sources":["../../../../src/components/QueryBuilder/QueryBuilder.tsx"],"sourcesContent":["import { useEffect, useMemo, useReducer, useRef, useState } from \"react\";\nimport cloneDeep from \"lodash/cloneDeep\";\nimport isEqual from \"lodash/isEqual\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { ConfirmationDialog } from \"./ConfirmationDialog\";\nimport {\n HvQueryBuilderProvider,\n defaultCombinators,\n defaultLabels,\n defaultOperators,\n} from \"./Context\";\nimport { RuleGroup } from \"./RuleGroup\";\nimport {\n AskAction,\n HvQueryBuilderAttribute,\n HvQueryBuilderQuery,\n HvQueryBuilderLabels,\n HvQueryBuilderQueryCombinator,\n HvQueryBuilderQueryOperator,\n HvQueryBuilderChangedQuery,\n HvQueryBuilderRenderers,\n} from \"./types\";\nimport { clearNodeIds, emptyGroup } from \"./utils\";\nimport reducer from \"./utils/reducer\";\nimport { useClasses, staticClasses } from \"./QueryBuilder.styles\";\n\nexport { staticClasses as queryBuilderClasses };\n\nexport type HvQueryBuilderClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvQueryBuilderProps {\n /** The query attribute types. */\n attributes?: Record<string, HvQueryBuilderAttribute>;\n /** The query rules operators by attribute type and combinator. */\n operators?: Record<string, HvQueryBuilderQueryOperator[]>;\n /** The query combinators operands. */\n combinators?: HvQueryBuilderQueryCombinator[];\n /** The initial query representation. */\n query?: HvQueryBuilderQuery;\n /** Callback fired when query changes. */\n onChange?: (value: HvQueryBuilderChangedQuery) => void;\n /** Max depth of nested query groups. */\n maxDepth?: number;\n /** Object containing all the labels. */\n labels?: HvQueryBuilderLabels;\n /** Whether the query builder is in read-only mode. */\n readOnly?: boolean;\n /** Renderers for custom attribute types. */\n renderers?: HvQueryBuilderRenderers;\n /** Whether to opt-out of the confirmation dialogs shown before removing rules and rule groups. Default to `false`. */\n disableConfirmation?: boolean;\n /** A Jss Object used to override or extend the styles applied. */\n classes?: HvQueryBuilderClasses;\n}\n\n// TODO - v6\n// - uncontrolled vs controlled: users should be able to control the state\n// - \"query\" renamed to \"initialQuery\" and \"query\" used to control the state\n// - \"query\" provided with ids by the user but removed through \"onChange\"\n\n/**\n * This component allows you to create conditions and group them using logical operators.\n * It outputs a structured set of rules which can be easily parsed to create SQL/NoSQL/whatever queries.\n */\nexport const HvQueryBuilder = (props: HvQueryBuilderProps) => {\n const {\n attributes,\n renderers,\n query,\n onChange,\n disableConfirmation = false,\n operators = defaultOperators,\n combinators = defaultCombinators,\n maxDepth = 1,\n labels = defaultLabels,\n readOnly = false,\n classes: classesProp,\n } = useDefaultProps(\"HvQueryBuilder\", props);\n\n const { classes } = useClasses(classesProp);\n\n const currentAttributes = useRef<HvQueryBuilderProps[\"attributes\"] | null>(\n null\n );\n\n const initialQuery = useRef(query ?? emptyGroup());\n\n const [pendingAction, setPendingAction] = useState<AskAction>();\n const [prevState, setPrevState] = useState(initialQuery.current);\n const [initialState, setInitialState] = useState(true);\n\n const [state, dispatchAction] = useReducer(\n reducer,\n // Deep clone is needed to make sure that the \"query\" prop and \"initialQuery\" are not mutated\n cloneDeep(initialQuery.current)\n );\n\n const value = useMemo(\n () => ({\n dispatchAction,\n askAction: setPendingAction,\n attributes,\n operators,\n combinators,\n maxDepth,\n labels,\n initialTouched: initialState,\n readOnly,\n renderers,\n disableConfirmation,\n }),\n [\n attributes,\n operators,\n combinators,\n maxDepth,\n labels,\n readOnly,\n initialState,\n renderers,\n disableConfirmation,\n ]\n );\n\n // Keep track of attributes\n useEffect(() => {\n if (currentAttributes.current == null) {\n // First run, nothing to do\n currentAttributes.current = attributes;\n } else if (currentAttributes.current !== attributes) {\n // Attributes changed. The existing query is almost certainly invalid, so reset it\n currentAttributes.current = attributes;\n dispatchAction({ type: \"reset-query\" });\n }\n }, [attributes]);\n\n // Propagate the change if the query is modified\n useEffect(() => {\n if (!isEqual(state, prevState)) {\n if (initialState) {\n setInitialState(false);\n }\n\n onChange?.(clearNodeIds(state) as HvQueryBuilderChangedQuery);\n setPrevState(cloneDeep(state));\n }\n }, [initialState, onChange, prevState, state]);\n\n const handleConfirm = () => {\n if (pendingAction) {\n setPendingAction(undefined);\n pendingAction.actions.forEach((action) => dispatchAction(action));\n }\n };\n\n const handleCancel = () => {\n setPendingAction(undefined);\n };\n\n return (\n <HvQueryBuilderProvider value={value}>\n <RuleGroup\n level={0}\n id={state.id}\n combinator={state.combinator}\n rules={state.rules}\n classes={classes}\n />\n <ConfirmationDialog\n isOpen={pendingAction != null}\n onConfirm={handleConfirm}\n onCancel={handleCancel}\n title={pendingAction?.dialog.dialogTitle || \"\"}\n message={pendingAction?.dialog.dialogMessage || \"\"}\n confirmButtonLabel={pendingAction?.dialog.dialogConfirm || \"\"}\n cancelButtonLabel={pendingAction?.dialog.dialogCancel || \"\"}\n closeButtonTooltip={pendingAction?.dialog.dialogCloseTooltip || \"\"}\n />\n </HvQueryBuilderProvider>\n );\n};\n"],"names":["HvQueryBuilder","props","attributes","renderers","query","onChange","disableConfirmation","operators","defaultOperators","combinators","defaultCombinators","maxDepth","labels","defaultLabels","readOnly","classes","classesProp","useDefaultProps","useClasses","currentAttributes","useRef","initialQuery","emptyGroup","pendingAction","setPendingAction","useState","prevState","setPrevState","current","initialState","setInitialState","state","dispatchAction","useReducer","reducer","cloneDeep","value","useMemo","askAction","initialTouched","useEffect","type","isEqual","clearNodeIds","handleConfirm","undefined","actions","forEach","action","handleCancel","jsxs","HvQueryBuilderProvider","jsx","RuleGroup","id","combinator","rules","ConfirmationDialog","dialog","dialogTitle","dialogMessage","dialogConfirm","dialogCancel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Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
|
-
const Context = require("../../Context.cjs");
|
|
6
5
|
const index = require("../../utils/index.cjs");
|
|
6
|
+
const Context = require("../../Context.cjs");
|
|
7
7
|
const Dropdown = require("../../../Dropdown/Dropdown.cjs");
|
|
8
8
|
const Attribute = ({
|
|
9
9
|
id,
|
|
@@ -11,14 +11,13 @@ const Attribute = ({
|
|
|
11
11
|
disabled,
|
|
12
12
|
isInvalid
|
|
13
13
|
}) => {
|
|
14
|
-
const context = React.useContext(Context.HvQueryBuilderContext);
|
|
15
14
|
const {
|
|
16
15
|
dispatchAction,
|
|
17
16
|
attributes,
|
|
18
17
|
operators,
|
|
19
18
|
labels,
|
|
20
19
|
readOnly
|
|
21
|
-
} =
|
|
20
|
+
} = Context.useQueryBuilderContext();
|
|
22
21
|
const values = React.useMemo(() => {
|
|
23
22
|
if (!attributes)
|
|
24
23
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Attribute.cjs","sources":["../../../../../../src/components/QueryBuilder/Rule/Attribute/Attribute.tsx"],"sourcesContent":["import { useMemo,
|
|
1
|
+
{"version":3,"file":"Attribute.cjs","sources":["../../../../../../src/components/QueryBuilder/Rule/Attribute/Attribute.tsx"],"sourcesContent":["import { useMemo, memo } from \"react\";\n\nimport { HvDropdown } from \"@core/components/Dropdown\";\n\nimport { isBigList } from \"../../utils\";\nimport { useQueryBuilderContext } from \"../../Context\";\n\nexport interface AttributeProps {\n id: React.Key;\n attribute?: string;\n disabled?: boolean;\n isInvalid?: boolean;\n}\n\nexport const Attribute = ({\n id,\n attribute,\n disabled,\n isInvalid,\n}: AttributeProps) => {\n const { dispatchAction, attributes, operators, labels, readOnly } =\n useQueryBuilderContext();\n\n const values = useMemo(() => {\n if (!attributes) return [];\n\n return Object.keys(attributes).map((key) => ({\n id: key,\n label: attributes[key].label,\n selected: key === attribute,\n }));\n }, [attributes, attribute]);\n\n const currentType =\n attribute != null && attributes ? attributes[attribute]?.type : null;\n\n return (\n <HvDropdown\n singleSelectionToggle={false}\n label={labels.rule.attribute.label}\n placeholder={labels.rule.attribute.placeholder}\n values={values}\n disabled={disabled}\n readOnly={readOnly}\n status={isInvalid ? \"invalid\" : \"valid\"}\n statusMessage={labels.rule.attribute.exists}\n onChange={(selected) => {\n if (selected && !Array.isArray(selected)) {\n const attributeId = selected.id;\n\n const type =\n attributes && attributeId && attributes[attributeId]?.type;\n const typeOperators = type ? operators[type] : undefined;\n\n let operator;\n if (currentType === type) {\n operator = undefined;\n } else if (typeOperators?.length === 1) {\n operator = typeOperators[0].operator;\n } else {\n operator = null;\n }\n\n // default boolean attributes to true\n const value = type === \"boolean\" ? true : undefined;\n\n dispatchAction({\n type: \"set-attribute\",\n id,\n attribute: attributeId?.toString(),\n operator,\n value,\n });\n } else {\n dispatchAction({ type: \"set-attribute\", id, attribute: null });\n }\n }}\n showSearch={isBigList(values)}\n {...(isBigList(values) && { virtualized: true, height: 300 })}\n />\n );\n};\n\nexport default memo(Attribute);\n"],"names":["Attribute","id","attribute","disabled","isInvalid","dispatchAction","attributes","operators","labels","readOnly","useQueryBuilderContext","values","useMemo","Object","keys","map","key","label","selected","currentType","type","jsx","HvDropdown","rule","placeholder","exists","Array","isArray","attributeId","typeOperators","undefined","operator","length","value","toString","isBigList","virtualized","height","memo"],"mappings":";;;;;;;AAcO,MAAMA,YAAYA,CAAC;AAAA,EACxBC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AACc,MAAM;AACd,QAAA;AAAA,IAAEC;AAAAA,IAAgBC;AAAAA,IAAYC;AAAAA,IAAWC;AAAAA,IAAQC;AAAAA,MACrDC,QAAuB,uBAAA;AAEnBC,QAAAA,SAASC,MAAAA,QAAQ,MAAM;AAC3B,QAAI,CAACN;AAAY,aAAO;AAExB,WAAOO,OAAOC,KAAKR,UAAU,EAAES,IAAKC,CAAS,SAAA;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MC,QAAQ;AAAA,EACvD,EAAA,CAAA;AAEN;AAEeC,WAAKtC,SAAS;;"}
|
|
@@ -11,14 +11,13 @@ const Operator = ({
|
|
|
11
11
|
attribute,
|
|
12
12
|
operator
|
|
13
13
|
}) => {
|
|
14
|
-
const context = React.useContext(Context.HvQueryBuilderContext);
|
|
15
14
|
const {
|
|
16
15
|
dispatchAction,
|
|
17
16
|
attributes,
|
|
18
17
|
operators,
|
|
19
18
|
labels,
|
|
20
19
|
readOnly
|
|
21
|
-
} =
|
|
20
|
+
} = Context.useQueryBuilderContext();
|
|
22
21
|
const value = operator ?? null;
|
|
23
22
|
const values = React.useMemo(() => {
|
|
24
23
|
const attributeSpec = attribute && attributes ? attributes[attribute] : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Operator.cjs","sources":["../../../../../../src/components/QueryBuilder/Rule/Operator/Operator.tsx"],"sourcesContent":["import { memo,
|
|
1
|
+
{"version":3,"file":"Operator.cjs","sources":["../../../../../../src/components/QueryBuilder/Rule/Operator/Operator.tsx"],"sourcesContent":["import { memo, useMemo } from \"react\";\n\nimport { HvDropdown } from \"@core/components/Dropdown\";\n\nimport { useQueryBuilderContext } from \"../../Context\";\nimport { isBigList } from \"../../utils\";\n\nexport interface OperatorProps {\n id: React.Key;\n combinator: string;\n attribute: string;\n operator?: string;\n}\n\nexport const Operator = ({\n id,\n combinator,\n attribute,\n operator,\n}: OperatorProps) => {\n const { dispatchAction, attributes, operators, labels, readOnly } =\n useQueryBuilderContext();\n\n const value = operator ?? null;\n\n const values = useMemo(() => {\n const attributeSpec =\n attribute && attributes ? attributes[attribute] : null;\n const options = attributeSpec\n ? operators[attributeSpec.type].filter((o) =>\n o.combinators.includes(combinator)\n ) ?? []\n : [];\n return options.map((key) => ({\n id: key.operator,\n label: key.label,\n selected: key.operator === value,\n }));\n }, [attribute, attributes, operators, combinator, value]);\n\n return (\n <HvDropdown\n required\n status=\"valid\"\n singleSelectionToggle={false}\n label={labels.rule.operator.label}\n placeholder={labels.rule.operator.placeholder}\n values={values}\n disabled={values.length === 0}\n readOnly={readOnly}\n onChange={(selected) => {\n if (selected && !Array.isArray(selected) && selected.id) {\n dispatchAction({\n type: \"set-operator\",\n id,\n operator: selected.id.toString(),\n value:\n value === \"range\" ||\n selected.id === \"range\" ||\n selected.id === \"IsNotEmpty\" ||\n selected.id === \"Empty\"\n ? null\n : undefined,\n });\n } else {\n dispatchAction({\n type: \"set-operator\",\n id,\n operator: null,\n value: null,\n });\n }\n }}\n showSearch={isBigList(values)}\n {...(isBigList(values) && { virtualized: true, height: 300 })}\n />\n );\n};\n\nexport default memo(Operator);\n"],"names":["Operator","id","combinator","attribute","operator","dispatchAction","attributes","operators","labels","readOnly","useQueryBuilderContext","value","values","useMemo","attributeSpec","options","type","filter","o","combinators","includes","map","key","label","selected","jsx","HvDropdown","rule","placeholder","length","Array","isArray","toString","undefined","isBigList","virtualized","height","memo"],"mappings":";;;;;;;AAcO,MAAMA,WAAWA,CAAC;AAAA,EACvBC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AACa,MAAM;AACb,QAAA;AAAA,IAAEC;AAAAA,IAAgBC;AAAAA,IAAYC;AAAAA,IAAWC;AAAAA,IAAQC;AAAAA,MACrDC,QAAuB,uBAAA;AAEzB,QAAMC,QAAQP,YAAY;AAEpBQ,QAAAA,SAASC,MAAAA,QAAQ,MAAM;AAC3B,UAAMC,gBACJX,aAAaG,aAAaA,WAAWH,SAAS,IAAI;AACpD,UAAMY,UAAUD,gBACZP,UAAUO,cAAcE,IAAI,EAAEC,OAAQC,CAAAA,MACpCA,EAAEC,YAAYC,SAASlB,UAAU,CACnC,KAAK,KACL;AACGa,WAAAA,QAAQM,IAAKC,CAAS,SAAA;AAAA,MAC3BrB,IAAIqB,IAAIlB;AAAAA,MACRmB,OAAOD,IAAIC;AAAAA,MACXC,UAAUF,IAAIlB,aAAaO;AAAAA,IAC3B,EAAA;AAAA,EAAA,GACD,CAACR,WAAWG,YAAYC,WAAWL,YAAYS,KAAK,CAAC;AAGtD,SAAAc,2BAAA,IAACC,SACC,YAAA,EAAA,UAAQ,MACR,QAAO,SACP,uBAAuB,OACvB,OAAOlB,OAAOmB,KAAKvB,SAASmB,OAC5B,aAAaf,OAAOmB,KAAKvB,SAASwB,aAClC,QACA,UAAUhB,OAAOiB,WAAW,GAC5B,UACA,UAAWL,CAAa,aAAA;AACtB,QAAIA,YAAY,CAACM,MAAMC,QAAQP,QAAQ,KAAKA,SAASvB,IAAI;AACxC,qBAAA;AAAA,QACbe,MAAM;AAAA,QACNf;AAAAA,QACAG,UAAUoB,SAASvB,GAAG+B,SAAS;AAAA,QAC/BrB,OACEA,UAAU,WACVa,SAASvB,OAAO,WAChBuB,SAASvB,OAAO,gBAChBuB,SAASvB,OAAO,UACZ,OACAgC;AAAAA,MAAAA,CACP;AAAA,IAAA,OACI;AACU,qBAAA;AAAA,QACbjB,MAAM;AAAA,QACNf;AAAAA,QACAG,UAAU;AAAA,QACVO,OAAO;AAAA,MAAA,CACR;AAAA,IACH;AAAA,EAAA,GAEF,YAAYuB,MAAAA,UAAUtB,MAAM,GACvBsB,GAAAA,MAAAA,UAAUtB,MAAM,KAAK;AAAA,IAAEuB,aAAa;AAAA,IAAMC,QAAQ;AAAA,EACvD,EAAA,CAAA;AAEN;AAEeC,WAAKrC,QAAQ;;"}
|
|
@@ -28,16 +28,17 @@ const Rule = (props) => {
|
|
|
28
28
|
classes,
|
|
29
29
|
cx
|
|
30
30
|
} = Rule_styles.useClasses(classesProp);
|
|
31
|
-
const context = React.useContext(Context.HvQueryBuilderContext);
|
|
32
|
-
const theme = material.useTheme();
|
|
33
|
-
const isMdDown = material.useMediaQuery(theme.breakpoints.down("md"));
|
|
34
31
|
const {
|
|
35
32
|
askAction,
|
|
33
|
+
dispatchAction,
|
|
36
34
|
attributes,
|
|
37
35
|
operators,
|
|
38
36
|
labels,
|
|
39
|
-
readOnly
|
|
40
|
-
|
|
37
|
+
readOnly,
|
|
38
|
+
disableConfirmation
|
|
39
|
+
} = Context.useQueryBuilderContext();
|
|
40
|
+
const theme = material.useTheme();
|
|
41
|
+
const isMdDown = material.useMediaQuery(theme.breakpoints.down("md"));
|
|
41
42
|
const availableOperators = React.useMemo(() => {
|
|
42
43
|
const attributeSpec = attribute != null && attributes ? attributes[attribute] : null;
|
|
43
44
|
if (attributeSpec != null) {
|
|
@@ -56,15 +57,16 @@ const Rule = (props) => {
|
|
|
56
57
|
/* @__PURE__ */ jsxRuntime.jsx(Grid.HvGrid, { item: true, xs: 2, lg: 3, children: /* @__PURE__ */ jsxRuntime.jsx(Attribute.Attribute, { attribute, id, disabled, isInvalid }) }),
|
|
57
58
|
attribute != null && availableOperators > 0 && /* @__PURE__ */ jsxRuntime.jsx(Grid.HvGrid, { item: true, xs: 2, lg: 3, children: /* @__PURE__ */ jsxRuntime.jsx(Operator.Operator, { id, combinator, attribute, operator }) }),
|
|
58
59
|
attribute != null && (operator != null || availableOperators === 0) && /* @__PURE__ */ jsxRuntime.jsx(Grid.HvGrid, { item: true, xs: true, children: shouldShowValueInput && /* @__PURE__ */ jsxRuntime.jsx(Value.Value, { attribute, id, operator, value }) }),
|
|
59
|
-
/* @__PURE__ */ jsxRuntime.jsx(Grid.HvGrid, { item: true, className: classes.actionsContainer, children: /* @__PURE__ */ jsxRuntime.jsx(Button.HvButton, { icon: true, "aria-label": labels.rule.delete.ariaLabel, onClick: () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx(Grid.HvGrid, { item: true, className: classes.actionsContainer, children: /* @__PURE__ */ jsxRuntime.jsx(Button.HvButton, { icon: true, "aria-label": labels.rule.delete.ariaLabel, onClick: () => disableConfirmation ? dispatchAction({
|
|
61
|
+
type: "remove-node",
|
|
62
|
+
id
|
|
63
|
+
}) : askAction({
|
|
64
|
+
actions: [{
|
|
65
|
+
type: "remove-node",
|
|
66
|
+
id
|
|
67
|
+
}],
|
|
68
|
+
dialog: labels.rule.delete
|
|
69
|
+
}), disabled: readOnly, children: /* @__PURE__ */ jsxRuntime.jsx(DeleteIcon, {}) }) })
|
|
68
70
|
] });
|
|
69
71
|
};
|
|
70
72
|
exports.queryBuilderRuleClasses = Rule_styles.staticClasses;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rule.cjs","sources":["../../../../../src/components/QueryBuilder/Rule/Rule.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Rule.cjs","sources":["../../../../../src/components/QueryBuilder/Rule/Rule.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport { Delete } from \"@hitachivantara/uikit-react-icons\";\nimport { useMediaQuery, useTheme } from \"@mui/material\";\n\nimport { HvGrid } from \"@core/components/Grid\";\nimport { HvButton } from \"@core/components/Button\";\nimport { withTooltip } from \"@core/hocs/withTooltip\";\nimport { useDefaultProps } from \"@core/hooks\";\nimport { ExtractNames } from \"@core/utils\";\n\nimport { useQueryBuilderContext } from \"../Context\";\nimport { Attribute } from \"./Attribute\";\nimport { Operator } from \"./Operator\";\nimport { Value } from \"./Value\";\nimport { staticClasses, useClasses } from \"./Rule.styles\";\n\nexport { staticClasses as queryBuilderRuleClasses };\n\nexport type HvQueryBuilderRuleClasses = ExtractNames<typeof useClasses>;\n\nexport interface RuleProps {\n id: React.Key;\n combinator: string;\n attribute?: string;\n operator?: string;\n value?: any;\n disabled?: boolean;\n isInvalid: boolean;\n classes?: HvQueryBuilderRuleClasses;\n}\n\nexport const Rule = (props: RuleProps) => {\n const {\n id,\n combinator,\n attribute,\n operator,\n value,\n disabled,\n isInvalid,\n classes: classesProp,\n } = useDefaultProps(\"HvQueryBuilderRule\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const {\n askAction,\n dispatchAction,\n attributes,\n operators,\n labels,\n readOnly,\n disableConfirmation,\n } = useQueryBuilderContext();\n\n const theme = useTheme();\n\n const isMdDown = useMediaQuery(theme.breakpoints.down(\"md\"));\n\n const availableOperators = useMemo(() => {\n const attributeSpec =\n attribute != null && attributes ? attributes[attribute] : null;\n if (attributeSpec != null) {\n const typeOperators = operators[attributeSpec.type];\n if (typeOperators != null) {\n return typeOperators.reduce(\n (count, item) =>\n count + (item.combinators.includes(combinator) ? 1 : 0),\n 0\n );\n }\n }\n\n return -1;\n }, [attribute, attributes, combinator, operators]);\n\n const shouldShowValueInput =\n operator !== \"Empty\" && operator !== \"IsNotEmpty\";\n\n const DeleteIcon = withTooltip(\n () => <Delete />,\n labels.rule.delete.tooltip,\n \"bottom\"\n );\n\n return (\n <HvGrid\n container\n className={cx(classes.root, { [classes.isMdDown]: isMdDown })}\n spacing={0}\n wrap=\"nowrap\"\n >\n <HvGrid item xs={2} lg={3}>\n <Attribute\n attribute={attribute}\n id={id}\n disabled={disabled}\n isInvalid={isInvalid}\n />\n </HvGrid>\n {attribute != null && availableOperators > 0 && (\n <HvGrid item xs={2} lg={3}>\n <Operator\n id={id}\n combinator={combinator}\n attribute={attribute}\n operator={operator}\n />\n </HvGrid>\n )}\n {attribute != null && (operator != null || availableOperators === 0) && (\n <HvGrid item xs>\n {shouldShowValueInput && (\n <Value\n attribute={attribute}\n id={id}\n operator={operator}\n value={value}\n />\n )}\n </HvGrid>\n )}\n <HvGrid item className={classes.actionsContainer}>\n <HvButton\n icon\n aria-label={labels.rule.delete.ariaLabel}\n onClick={() =>\n disableConfirmation\n ? dispatchAction({ type: \"remove-node\", id })\n : askAction({\n actions: [{ type: \"remove-node\", id }],\n dialog: labels.rule.delete,\n })\n }\n disabled={readOnly}\n >\n <DeleteIcon />\n </HvButton>\n </HvGrid>\n </HvGrid>\n );\n};\n"],"names":["Rule","props","id","combinator","attribute","operator","value","disabled","isInvalid","classes","classesProp","useDefaultProps","cx","useClasses","askAction","dispatchAction","attributes","operators","labels","readOnly","disableConfirmation","useQueryBuilderContext","theme","useTheme","isMdDown","useMediaQuery","breakpoints","down","availableOperators","useMemo","attributeSpec","typeOperators","type","reduce","count","item","combinators","includes","shouldShowValueInput","DeleteIcon","withTooltip","jsx","Delete","rule","delete","tooltip","HvGrid","root","Attribute","Operator","Value","actionsContainer","HvButton","ariaLabel","actions","dialog"],"mappings":";;;;;;;;;;;;;;;AA+BaA,MAAAA,OAAOA,CAACC,UAAqB;AAClC,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,SAASC;AAAAA,EAAAA,IACPC,gBAAgB,gBAAA,sBAAsBV,KAAK;AAEzC,QAAA;AAAA,IAAEQ;AAAAA,IAASG;AAAAA,EAAAA,IAAOC,YAAAA,WAAWH,WAAW;AAExC,QAAA;AAAA,IACJI;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,MACEC,QAAuB,uBAAA;AAE3B,QAAMC,QAAQC,SAAAA;AAEd,QAAMC,WAAWC,SAAAA,cAAcH,MAAMI,YAAYC,KAAK,IAAI,CAAC;AAErDC,QAAAA,qBAAqBC,MAAAA,QAAQ,MAAM;AACvC,UAAMC,gBACJ1B,aAAa,QAAQY,aAAaA,WAAWZ,SAAS,IAAI;AAC5D,QAAI0B,iBAAiB,MAAM;AACnBC,YAAAA,gBAAgBd,UAAUa,cAAcE,IAAI;AAClD,UAAID,iBAAiB,MAAM;AACzB,eAAOA,cAAcE,OACnB,CAACC,OAAOC,SACND,SAASC,KAAKC,YAAYC,SAASlC,UAAU,IAAI,IAAI,IACvD,CACF;AAAA,MACF;AAAA,IACF;AAEO,WAAA;AAAA,KACN,CAACC,WAAWY,YAAYb,YAAYc,SAAS,CAAC;AAE3CqB,QAAAA,uBACJjC,aAAa,WAAWA,aAAa;AAEjCkC,QAAAA,aAAaC,YAAAA,YACjB,MAAOC,2BAAAA,IAAAC,gBAAAA,QAA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;;;"}
|
|
@@ -9,12 +9,11 @@ const BooleanValue = ({
|
|
|
9
9
|
id,
|
|
10
10
|
value = true
|
|
11
11
|
}) => {
|
|
12
|
-
const context = React.useContext(Context.HvQueryBuilderContext);
|
|
13
12
|
const {
|
|
14
13
|
labels,
|
|
15
14
|
dispatchAction,
|
|
16
15
|
readOnly
|
|
17
|
-
} =
|
|
16
|
+
} = Context.useQueryBuilderContext();
|
|
18
17
|
const values = ["true", "false"].map((v) => ({
|
|
19
18
|
id: v,
|
|
20
19
|
label: labels.rule.value.boolean.options[v],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BooleanValue.cjs","sources":["../../../../../../../src/components/QueryBuilder/Rule/Value/BooleanValue/BooleanValue.tsx"],"sourcesContent":["import { memo
|
|
1
|
+
{"version":3,"file":"BooleanValue.cjs","sources":["../../../../../../../src/components/QueryBuilder/Rule/Value/BooleanValue/BooleanValue.tsx"],"sourcesContent":["import { memo } from \"react\";\n\nimport { HvDropdown } from \"@core/components/Dropdown\";\n\nimport { useQueryBuilderContext } from \"../../../Context\";\nimport { isBigList } from \"../../../utils\";\n\nexport interface BooleanValueProps {\n id: React.Key;\n value?: boolean;\n}\n\nexport const BooleanValue = ({ id, value = true }: BooleanValueProps) => {\n const { labels, dispatchAction, readOnly } = useQueryBuilderContext();\n\n const values = [\"true\", \"false\"].map((v) => ({\n id: v,\n label: labels.rule.value.boolean.options[v],\n selected: value === (v === \"true\"),\n }));\n\n return (\n <HvDropdown\n required\n status=\"valid\"\n singleSelectionToggle={false}\n label={labels.rule.value.boolean.label}\n placeholder={labels.rule.value.boolean.placeholder}\n values={values}\n readOnly={readOnly}\n onChange={(selected) => {\n if (selected && !Array.isArray(selected) && selected.id) {\n dispatchAction({\n type: \"set-value\",\n id,\n value: selected.id === \"true\",\n });\n } else {\n dispatchAction({ type: \"set-value\", id, value: null });\n }\n }}\n showSearch={isBigList(values)}\n {...(isBigList(values) && { virtualized: true, height: 300 })}\n />\n );\n};\n\nexport default memo(BooleanValue);\n"],"names":["BooleanValue","id","value","labels","dispatchAction","readOnly","useQueryBuilderContext","values","map","v","label","rule","boolean","options","selected","jsx","HvDropdown","placeholder","Array","isArray","type","isBigList","virtualized","height","memo"],"mappings":";;;;;;;AAYO,MAAMA,eAAeA,CAAC;AAAA,EAAEC;AAAAA,EAAIC,QAAQ;AAAwB,MAAM;AACjE,QAAA;AAAA,IAAEC;AAAAA,IAAQC;AAAAA,IAAgBC;AAAAA,MAAaC,QAAuB,uBAAA;AAEpE,QAAMC,SAAS,CAAC,QAAQ,OAAO,EAAEC,IAAKC,CAAO,OAAA;AAAA,IAC3CR,IAAIQ;AAAAA,IACJC,OAAOP,OAAOQ,KAAKT,MAAMU,QAAQC,QAAQJ,CAAC;AAAA,IAC1CK,UAAUZ,WAAWO,MAAM;AAAA,EAC3B,EAAA;AAGA,SAAAM,+BAACC,SAAAA,cACC,UAAQ,MACR,QAAO,SACP,uBAAuB,OACvB,OAAOb,OAAOQ,KAAKT,MAAMU,QAAQF,OACjC,aAAaP,OAAOQ,KAAKT,MAAMU,QAAQK,aACvC,QACA,UACA,UAAWH,CAAa,aAAA;AACtB,QAAIA,YAAY,CAACI,MAAMC,QAAQL,QAAQ,KAAKA,SAASb,IAAI;AACxC,qBAAA;AAAA,QACbmB,MAAM;AAAA,QACNnB;AAAAA,QACAC,OAAOY,SAASb,OAAO;AAAA,MAAA,CACxB;AAAA,IAAA,OACI;AACU,qBAAA;AAAA,QAAEmB,MAAM;AAAA,QAAanB;AAAAA,QAAIC,OAAO;AAAA,MAAA,CAAM;AAAA,IACvD;AAAA,EAAA,GAEF,YAAYmB,MAAAA,UAAUd,MAAM,GACvBc,GAAAA,MAAAA,UAAUd,MAAM,KAAK;AAAA,IAAEe,aAAa;AAAA,IAAMC,QAAQ;AAAA,EACvD,EAAA,CAAA;AAEN;AAEeC,WAAKxB,YAAY;;"}
|
|
@@ -30,12 +30,11 @@ const DateTimeValue = ({
|
|
|
30
30
|
const theme = material.useTheme();
|
|
31
31
|
const isMdDown = material.useMediaQuery(theme.breakpoints.down("md"));
|
|
32
32
|
const isRange = valueIsRange(operator);
|
|
33
|
-
const context = React.useContext(Context.HvQueryBuilderContext);
|
|
34
33
|
const {
|
|
35
34
|
labels,
|
|
36
35
|
dispatchAction,
|
|
37
36
|
readOnly
|
|
38
|
-
} =
|
|
37
|
+
} = Context.useQueryBuilderContext();
|
|
39
38
|
const elementId = uniqueId__default.default(`datetime${id}`);
|
|
40
39
|
const [touchedDate, setTouchedDate] = React.useState(initialTouched);
|
|
41
40
|
const [touchedTime, setTouchedTime] = React.useState(initialTouched);
|