@economic/taco 2.26.20 → 2.27.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Report/Report.d.ts +1 -1
- package/dist/components/Report/types.d.ts +1 -1
- package/dist/components/Report/useReport.d.ts +2 -2
- package/dist/components/Select2/Select2.d.ts +6 -4
- package/dist/components/Select2/components/Trigger.d.ts +0 -1
- package/dist/components/Select2/utilities.d.ts +1 -0
- package/dist/esm/packages/taco/src/components/Datepicker/useDatepicker.js +1 -1
- package/dist/esm/packages/taco/src/components/Datepicker/useDatepicker.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/useReport.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/Select2.js +18 -7
- package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/components/Option.js +6 -11
- package/dist/esm/packages/taco/src/components/Select2/components/Option.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js +19 -22
- package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/utilities.js +13 -1
- package/dist/esm/packages/taco/src/components/Select2/utilities.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +2 -2
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +4 -2
- package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js +15 -6
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js +15 -6
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js +6 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/date.js +2 -2
- package/dist/esm/packages/taco/src/utils/date.js.map +1 -1
- package/dist/primitives/Table/Core/components/Footer/Footer.d.ts +11 -2
- package/dist/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterColumn.d.ts +1 -1
- package/dist/taco.cjs.development.js +92 -54
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/dist/utils/date.d.ts +1 -1
- package/package.json +2 -2
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Trigger.js","sources":["../../../../../../../../src/components/Select2/components/Trigger.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { Tag } from '../../Tag/Tag';\nimport { Tooltip } from '../../Tooltip/Tooltip';\nimport { Icon } from '../../Icon/Icon';\nimport { Badge } from '../../Badge/Badge';\nimport { getInputClasses } from '../../Input/util';\nimport { Select2OptionValue } from '../types';\nimport { useSelect2Context } from './Context';\nimport { Select2OptionProps } from './Option';\nimport { getIndexOfFirstChildOverflowingParent } from '../../../utils/dom';\nimport { ScrollArea } from '../../ScrollArea/ScrollArea';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { FontSize, FontSizes } from '../../../types';\n\ntype Select2TriggerProps = Omit<React.HTMLAttributes<HTMLButtonElement>, 'children' | 'defaultValue' | 'onChange' | 'value'> & {\n emptyValue?: Select2OptionValue;\n placeholder?: string;\n children: React.ReactElement<Select2OptionProps>[];\n fontSize?: FontSize;\n};\n\nexport const Trigger = React.forwardRef<HTMLButtonElement, Select2TriggerProps>(function Select2Trigger(props, ref) {\n const { multiple, value } = useSelect2Context();\n\n if (Array.isArray(value) || multiple) {\n const values = Array.isArray(value) ? value : value !== undefined ? [value] : undefined;\n return <Multiple {...props} ref={ref} values={values} />;\n }\n\n return <Single {...props} ref={ref} value={value} />;\n});\n\ntype ButtonProps = React.HTMLAttributes<HTMLButtonElement> &\n Omit<Select2TriggerProps, 'children' | 'open' | 'setValue' | 'value'>;\n\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Select2TriggerButton(props, ref) {\n const { children, onClick, tabIndex = 0, fontSize, ...otherProps } = props;\n const { disabled, highlighted, invalid, open, readOnly } = useSelect2Context();\n\n const className = cn(\n 'cursor-pointer px-1.5 h-fit',\n getInputClasses({ ...props, disabled, highlighted, invalid, readOnly })\n .replace('w-full', '')\n .replace('px-2', ''),\n {\n 'w-full': !props.className?.includes('w-'),\n 'text-xs': fontSize === FontSizes.small,\n 'text-sm': fontSize === FontSizes.medium,\n 'text-base': fontSize === FontSizes.large,\n },\n props.className\n );\n\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n if (disabled || readOnly) {\n event.preventDefault();\n return;\n }\n\n if (typeof onClick === 'function') {\n onClick(event);\n }\n };\n\n return (\n <button\n {...otherProps}\n aria-invalid={invalid ? true : undefined}\n aria-readonly={readOnly ? true : undefined}\n className={className}\n disabled={disabled}\n onClick={handleClick}\n ref={ref}\n role=\"combobox\"\n tabIndex={disabled || readOnly ? -1 : tabIndex}\n type=\"button\">\n {children}\n <Icon name={open ? 'chevron-up' : 'chevron-down'} className=\"pointer-events-none -mr-1 ml-auto\" />\n </button>\n );\n});\n\ntype SingleProps = Omit<Select2TriggerProps, 'value'> & { value?: Select2OptionValue; placeholder?: string };\n\nconst Single = React.forwardRef<HTMLButtonElement, SingleProps>(function Select2TriggerSingle(props, ref) {\n const { children, emptyValue, value, placeholder, ...buttonProps } = props;\n const { disabled, readOnly, tags } = useSelect2Context();\n const contentClassName = cn('truncate items-center gap-1');\n\n const currentValue = children.find(matchesValue(value));\n\n let output;\n\n if (placeholder && currentValue === undefined) {\n output = <div className={cn({ 'text-grey-700': disabled, 'text-grey-500': !disabled })}>{placeholder}</div>;\n } else if (currentValue) {\n if (tags && emptyValue !== value) {\n output = (\n <Tag\n className=\"truncate\"\n color={currentValue.props.color}\n disabled={disabled}\n icon={currentValue.props.prefix}\n readOnly={readOnly}>\n {currentValue.props.children}\n </Tag>\n );\n } else {\n output = (\n <>\n {currentValue.props.prefix ? (\n typeof currentValue.props.prefix === 'string' ? (\n <Icon name={currentValue.props.prefix} className=\"mr-1 !h-5 !w-5\" />\n ) : (\n currentValue.props.prefix\n )\n ) : null}\n {currentValue.props.children}\n </>\n );\n }\n }\n\n return (\n <Button {...buttonProps} ref={ref}>\n <div className={contentClassName}>{output}</div>\n </Button>\n );\n});\n\ntype MultipleProps = Omit<Select2TriggerProps, 'value'> & {\n values?: Select2OptionValue[];\n};\n\nconst Multiple = React.forwardRef<HTMLButtonElement, MultipleProps>(function Select2TriggerMultiple(props, ref) {\n const { children, emptyValue: _, values = [], placeholder, ...buttonProps } = props;\n const { disabled, open, readOnly, setValue, tags } = useSelect2Context();\n const buttonRef = useMergedRef<HTMLButtonElement>(ref);\n\n const valuesAsChildren = values\n .map(value => children.find(c => c.props.value === value))\n .filter(c => !!c) as React.ReactElement<Select2OptionProps>[];\n\n let content;\n let { className } = buttonProps;\n\n if (open) {\n className = cn('!absolute z-20 !h-fit', buttonProps.className);\n content = (\n <ScrollArea className=\"my-1 flex max-h-[5.5rem] flex-col\">\n <div className=\"flex flex-wrap gap-1\">\n {valuesAsChildren.length === 0 ? (\n <div className={cn({ 'text-grey-700': disabled, 'text-grey-500': !disabled })}>{placeholder}</div>\n ) : (\n valuesAsChildren.map(child => (\n <Tag\n key={String(child.props.value)}\n className=\"truncate\"\n color={tags ? child.props.color : undefined}\n disabled={disabled}\n icon={child.props.prefix}\n onDelete={event => {\n event?.stopPropagation();\n event?.preventDefault();\n\n if (!disabled && !readOnly) {\n setValue(child.props.value);\n }\n }}\n readOnly={readOnly}>\n {child.props.children}\n </Tag>\n ))\n )}\n </div>\n </ScrollArea>\n );\n } else {\n content = <MultipleValue key={String(open)} valuesAsChildren={valuesAsChildren} placeholder={placeholder} />;\n }\n\n return (\n <div\n className=\"relative inline-flex h-fit flex-grow\"\n data-taco=\"select2-container\"\n style={{ width: open ? buttonRef.current?.offsetWidth : undefined }}>\n <Button {...buttonProps} className={className} ref={buttonRef}>\n {content}\n </Button>\n </div>\n );\n});\n\ntype MultipleValueProps = Omit<Select2TriggerProps, 'value' | 'children'> & {\n valuesAsChildren: React.ReactElement<Select2OptionProps>[];\n placeholder?: string;\n};\n\nconst MultipleValue = ({ valuesAsChildren, placeholder }: MultipleValueProps) => {\n const { disabled, open, readOnly, setValue, tags } = useSelect2Context();\n const [contentRef, setContentRef] = React.useState<HTMLDivElement | null>(null);\n const boundaryIndex = contentRef ? getIndexOfFirstChildOverflowingParent(contentRef, 30) : undefined;\n\n const createClickHandler = tagValue => event => {\n event?.stopPropagation();\n event?.preventDefault();\n\n if (!disabled && !readOnly) {\n setValue(tagValue);\n }\n };\n\n return (\n <div className=\"relative flex items-center gap-1 overflow-hidden\">\n <div className=\"flex gap-1 truncate\" ref={el => setContentRef(el)}>\n {valuesAsChildren.length === 0 ? (\n <div className={cn({ 'text-grey-700': disabled, 'text-grey-500': !disabled })}>{placeholder}</div>\n ) : (\n valuesAsChildren.map((child, index) => {\n const tag = (\n <Tag\n key={String(child.props.value)}\n className={cn('cursor-pointer', {\n truncate: index === boundaryIndex,\n hidden: boundaryIndex !== undefined && boundaryIndex !== null ? index > boundaryIndex : false,\n })}\n color={tags ? child.props.color : undefined}\n disabled={disabled}\n icon={child.props.prefix}\n onDelete={open ? createClickHandler(child.props.value) : undefined}\n readOnly={readOnly}>\n {child.props.children}\n </Tag>\n );\n\n if (index === boundaryIndex) {\n return (\n <Tooltip key={String(child.props.value)} title={String(child.props.children)}>\n {tag}\n </Tooltip>\n );\n }\n\n return tag;\n })\n )}\n </div>\n {boundaryIndex !== undefined && boundaryIndex !== null && boundaryIndex < valuesAsChildren.length - 1 ? (\n <Tooltip\n title={valuesAsChildren\n .slice(boundaryIndex + 1)\n .map(child => (child ? String(child.props.children) : ''))\n .join(', ')}>\n <Badge className=\"flex-shrink-0\">+{valuesAsChildren.length - (boundaryIndex + 1)}</Badge>\n </Tooltip>\n ) : null}\n </div>\n );\n};\n\nconst matchesValue = (value: undefined | any | any[]) => (child: React.ReactElement<any>) => {\n if (Array.isArray(value)) {\n return value.includes(child.props.value);\n }\n\n return child.props.value === value;\n};\n"],"names":["Trigger","React","forwardRef","Select2Trigger","props","ref","multiple","value","useSelect2Context","Array","isArray","values","undefined","Multiple","Single","Button","Select2TriggerButton","children","onClick","tabIndex","fontSize","otherProps","disabled","highlighted","invalid","open","readOnly","className","cn","getInputClasses","replace","_props$className","includes","FontSizes","small","medium","large","handleClick","event","preventDefault","role","type","Icon","name","Select2TriggerSingle","emptyValue","placeholder","buttonProps","tags","contentClassName","currentValue","find","matchesValue","output","Tag","color","icon","prefix","Select2TriggerMultiple","_","setValue","buttonRef","useMergedRef","valuesAsChildren","map","c","filter","content","ScrollArea","length","child","key","String","onDelete","stopPropagation","MultipleValue","style","width","_buttonRef$current","current","offsetWidth","contentRef","setContentRef","useState","boundaryIndex","getIndexOfFirstChildOverflowingParent","createClickHandler","tagValue","el","index","tag","truncate","hidden","Tooltip","title","slice","join","Badge"],"mappings":";;;;;;;;;;;;;MAsBaA,OAAO,gBAAGC,cAAK,CAACC,UAAU,CAAyC,SAASC,cAAcA,CAACC,KAAK,EAAEC,GAAG;EAC9G,MAAM;IAAEC,QAAQ;IAAEC;GAAO,GAAGC,iBAAiB,EAAE;EAE/C,IAAIC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,IAAID,QAAQ,EAAE;IAClC,MAAMK,MAAM,GAAGF,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,GAAGA,KAAK,GAAGA,KAAK,KAAKK,SAAS,GAAG,CAACL,KAAK,CAAC,GAAGK,SAAS;IACvF,oBAAOX,6BAACY,QAAQ,oBAAKT,KAAK;MAAEC,GAAG,EAAEA,GAAG;MAAEM,MAAM,EAAEA;OAAU;;EAG5D,oBAAOV,6BAACa,MAAM,oBAAKV,KAAK;IAAEC,GAAG,EAAEA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G,CAAC,CAAC,CACxBpB,GAAG,CAACM,KAAK,IAAKA,KAAK,GAAGE,MAAM,CAACF,KAAK,CAAClE,KAAK,CAACa,QAAQ,CAAC,GAAG,EAAG,CAAC,CACzD+E,IAAI,CAAC,IAAI;kBACd/F,6BAACgG,KAAK;IAACtE,SAAS,EAAC;UAAkBoC,gBAAgB,CAACM,MAAM,IAAIe,aAAa,GAAG,CAAC,CAAC,CAAS,CACnF,IACV,IAAI,CACN;AAEd,CAAC;AAED,MAAMhC,YAAY,GAAI7C,KAA8B,IAAM+D,KAA8B;EACpF,IAAI7D,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,EAAE;IACtB,OAAOA,KAAK,CAACyB,QAAQ,CAACsC,KAAK,CAAClE,KAAK,CAACG,KAAK,CAAC;;EAG5C,OAAO+D,KAAK,CAAClE,KAAK,CAACG,KAAK,KAAKA,KAAK;AACtC,CAAC;;;;"}
|
1
|
+
{"version":3,"file":"Trigger.js","sources":["../../../../../../../../src/components/Select2/components/Trigger.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { Tag } from '../../Tag/Tag';\nimport { Tooltip } from '../../Tooltip/Tooltip';\nimport { Icon } from '../../Icon/Icon';\nimport { Badge } from '../../Badge/Badge';\nimport { getInputClasses } from '../../Input/util';\nimport { Select2OptionValue } from '../types';\nimport { useSelect2Context } from './Context';\nimport { Select2OptionProps } from './Option';\nimport { getIndexOfFirstChildOverflowingParent } from '../../../utils/dom';\nimport { ScrollArea } from '../../ScrollArea/ScrollArea';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { getFontSize } from '../utilities';\n\ntype Select2TriggerProps = Omit<React.HTMLAttributes<HTMLButtonElement>, 'children' | 'defaultValue' | 'onChange' | 'value'> & {\n emptyValue?: Select2OptionValue;\n placeholder?: string;\n children: React.ReactElement<Select2OptionProps>[];\n};\n\nconst Placeholder = ({ disabled, ...props }) => (\n <div {...props} className={cn({ 'text-grey-700': disabled, 'text-grey-500': !disabled })} />\n);\n\nexport const Trigger = React.forwardRef<HTMLButtonElement, Select2TriggerProps>(function Select2Trigger(props, ref) {\n const { multiple, value } = useSelect2Context();\n\n if (Array.isArray(value) || multiple) {\n const values = Array.isArray(value) ? value : value !== undefined ? [value] : undefined;\n return <Multiple {...props} ref={ref} values={values} />;\n }\n\n return <Single {...props} ref={ref} value={value} />;\n});\n\ntype ButtonProps = React.HTMLAttributes<HTMLButtonElement> &\n Omit<Select2TriggerProps, 'children' | 'open' | 'setValue' | 'value'>;\n\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Select2TriggerButton(props, ref) {\n const { children, onClick, tabIndex = 0, ...otherProps } = props;\n const { disabled, fontSize, highlighted, invalid, open, readOnly } = useSelect2Context();\n\n const className = cn(\n 'cursor-pointer px-1.5 h-fit',\n getInputClasses({ ...props, disabled, highlighted, invalid, readOnly })\n .replace('w-full', '')\n .replace('px-2', ''),\n getFontSize(fontSize),\n {\n 'w-full': !props.className?.includes('w-'),\n },\n props.className\n );\n\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n if (disabled || readOnly) {\n event.preventDefault();\n return;\n }\n\n if (typeof onClick === 'function') {\n onClick(event);\n }\n };\n\n return (\n <button\n {...otherProps}\n aria-invalid={invalid ? true : undefined}\n aria-readonly={readOnly ? true : undefined}\n className={className}\n disabled={disabled}\n onClick={handleClick}\n ref={ref}\n role=\"combobox\"\n tabIndex={disabled || readOnly ? -1 : tabIndex}\n type=\"button\">\n {children}\n <Icon name={open ? 'chevron-up' : 'chevron-down'} className=\"pointer-events-none -mr-1 ml-auto\" />\n </button>\n );\n});\n\ntype SingleProps = Omit<Select2TriggerProps, 'value'> & { value?: Select2OptionValue; placeholder?: string };\n\nconst Single = React.forwardRef<HTMLButtonElement, SingleProps>(function Select2TriggerSingle(props, ref) {\n const { children, emptyValue, value, placeholder, ...buttonProps } = props;\n const { disabled, readOnly, tags } = useSelect2Context();\n const contentClassName = cn('truncate items-center gap-1');\n\n const currentValue = children.find(matchesValue(value));\n\n let output;\n\n if (placeholder && currentValue === undefined) {\n output = <Placeholder disabled={disabled}>{placeholder}</Placeholder>;\n } else if (currentValue) {\n if (tags && emptyValue !== value) {\n output = (\n <Tag\n className=\"truncate\"\n color={currentValue.props.color}\n disabled={disabled}\n icon={currentValue.props.prefix}\n readOnly={readOnly}>\n {currentValue.props.children}\n </Tag>\n );\n } else {\n output = (\n <>\n {currentValue.props.prefix ? (\n typeof currentValue.props.prefix === 'string' ? (\n <Icon name={currentValue.props.prefix} className=\"mr-1 !h-5 !w-5\" />\n ) : (\n currentValue.props.prefix\n )\n ) : null}\n {currentValue.props.children}\n </>\n );\n }\n }\n\n return (\n <Button {...buttonProps} ref={ref}>\n <div className={contentClassName}>{output}</div>\n </Button>\n );\n});\n\ntype MultipleProps = Omit<Select2TriggerProps, 'value'> & {\n values?: Select2OptionValue[];\n};\n\nconst Multiple = React.forwardRef<HTMLButtonElement, MultipleProps>(function Select2TriggerMultiple(props, ref) {\n const { children, emptyValue: _, values = [], placeholder, ...buttonProps } = props;\n const { disabled, open, readOnly, setValue, tags } = useSelect2Context();\n const buttonRef = useMergedRef<HTMLButtonElement>(ref);\n\n const valuesAsChildren = values\n .map(value => children.find(c => c.props.value === value))\n .filter(c => !!c) as React.ReactElement<Select2OptionProps>[];\n\n let content;\n let { className } = buttonProps;\n\n if (open) {\n className = cn('!absolute z-20 !h-fit', buttonProps.className);\n content = (\n <ScrollArea className=\"my-1 flex max-h-[5.5rem] flex-col\">\n <div className=\"flex flex-wrap gap-1\">\n {valuesAsChildren.length === 0 ? (\n <Placeholder disabled={disabled}>{placeholder}</Placeholder>\n ) : (\n valuesAsChildren.map(child => (\n <Tag\n key={String(child.props.value)}\n className=\"truncate\"\n color={tags ? child.props.color : undefined}\n disabled={disabled}\n icon={child.props.prefix}\n onDelete={event => {\n event?.stopPropagation();\n event?.preventDefault();\n\n if (!disabled && !readOnly) {\n setValue(child.props.value);\n }\n }}\n readOnly={readOnly}>\n {child.props.children}\n </Tag>\n ))\n )}\n </div>\n </ScrollArea>\n );\n } else {\n content = <MultipleValue key={String(open)} valuesAsChildren={valuesAsChildren} placeholder={placeholder} />;\n }\n\n return (\n <div\n className=\"relative inline-flex h-fit flex-grow\"\n data-taco=\"select2-container\"\n style={{ width: open ? buttonRef.current?.offsetWidth : undefined }}>\n <Button {...buttonProps} className={className} ref={buttonRef}>\n {content}\n </Button>\n </div>\n );\n});\n\ntype MultipleValueProps = Omit<Select2TriggerProps, 'value' | 'children'> & {\n valuesAsChildren: React.ReactElement<Select2OptionProps>[];\n placeholder?: string;\n};\n\nconst MultipleValue = ({ valuesAsChildren, placeholder }: MultipleValueProps) => {\n const { disabled, open, readOnly, setValue, tags } = useSelect2Context();\n const [contentRef, setContentRef] = React.useState<HTMLDivElement | null>(null);\n const boundaryIndex = contentRef ? getIndexOfFirstChildOverflowingParent(contentRef, 30) : undefined;\n\n const createClickHandler = tagValue => event => {\n event?.stopPropagation();\n event?.preventDefault();\n\n if (!disabled && !readOnly) {\n setValue(tagValue);\n }\n };\n\n return (\n <div className=\"relative flex items-center gap-1 overflow-hidden\">\n <div className=\"flex gap-1 truncate\" ref={el => setContentRef(el)}>\n {valuesAsChildren.length === 0 ? (\n <Placeholder disabled={disabled}>{placeholder}</Placeholder>\n ) : (\n valuesAsChildren.map((child, index) => {\n const tag = (\n <Tag\n key={String(child.props.value)}\n className={cn('cursor-pointer', {\n truncate: index === boundaryIndex,\n hidden: boundaryIndex !== undefined && boundaryIndex !== null ? index > boundaryIndex : false,\n })}\n color={tags ? child.props.color : undefined}\n disabled={disabled}\n icon={child.props.prefix}\n onDelete={open ? createClickHandler(child.props.value) : undefined}\n readOnly={readOnly}>\n {child.props.children}\n </Tag>\n );\n\n if (index === boundaryIndex) {\n return (\n <Tooltip key={String(child.props.value)} title={String(child.props.children)}>\n {tag}\n </Tooltip>\n );\n }\n\n return tag;\n })\n )}\n </div>\n {boundaryIndex !== undefined && boundaryIndex !== null && boundaryIndex < valuesAsChildren.length - 1 ? (\n <Tooltip\n title={valuesAsChildren\n .slice(boundaryIndex + 1)\n .map(child => (child ? String(child.props.children) : ''))\n .join(', ')}>\n <Badge className=\"flex-shrink-0\">+{valuesAsChildren.length - (boundaryIndex + 1)}</Badge>\n </Tooltip>\n ) : null}\n </div>\n );\n};\n\nconst matchesValue = (value: undefined | any | any[]) => (child: React.ReactElement<any>) => {\n if (Array.isArray(value)) {\n return value.includes(child.props.value);\n }\n\n return child.props.value === value;\n};\n"],"names":["Placeholder","disabled","props","React","className","cn","Trigger","forwardRef","Select2Trigger","ref","multiple","value","useSelect2Context","Array","isArray","values","undefined","Multiple","Single","Button","Select2TriggerButton","children","onClick","tabIndex","otherProps","fontSize","highlighted","invalid","open","readOnly","getInputClasses","replace","getFontSize","_props$className","includes","handleClick","event","preventDefault","role","type","Icon","name","Select2TriggerSingle","emptyValue","placeholder","buttonProps","tags","contentClassName","currentValue","find","matchesValue","output","Tag","color","icon","prefix","Select2TriggerMultiple","_","setValue","buttonRef","useMergedRef","valuesAsChildren","map","c","filter","content","ScrollArea","length","child","key","String","onDelete","stopPropagation","MultipleValue","style","width","_buttonRef$current","current","offsetWidth","contentRef","setContentRef","useState","boundaryIndex","getIndexOfFirstChildOverflowingParent","createClickHandler","tagValue","el","index","tag","truncate","hidden","Tooltip","title","slice","join","Badge"],"mappings":";;;;;;;;;;;;;AAqBA,MAAMA,WAAW,GAAGA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;CAAO,oBACvCC,sDAASD,KAAK;EAAEE,SAAS,EAAEC,EAAE,CAAC;IAAE,eAAe,EAAEJ,QAAQ;IAAE,eAAe,EAAE,CAACA;GAAU;GAAK,CAC/F;MAEYK,OAAO,gBAAGH,cAAK,CAACI,UAAU,CAAyC,SAASC,cAAcA,CAACN,KAAK,EAAEO,GAAG;EAC9G,MAAM;IAAEC,QAAQ;IAAEC;GAAO,GAAGC,iBAAiB,EAAE;EAE/C,IAAIC,KAAK,CAACC,OAAO,CAACH,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K,EAAE/B,gBAAgB,CAClBgC,KAAK,CAACX,aAAa,GAAG,CAAC,CAAC,CACxBpB,GAAG,CAACM,KAAK,IAAKA,KAAK,GAAGE,MAAM,CAACF,KAAK,CAAClE,KAAK,CAACmB,QAAQ,CAAC,GAAG,EAAG,CAAC,CACzDyE,IAAI,CAAC,IAAI;kBACd3F,6BAAC4F,KAAK;IAAC3F,SAAS,EAAC;UAAkByD,gBAAgB,CAACM,MAAM,IAAIe,aAAa,GAAG,CAAC,CAAC,CAAS,CACnF,IACV,IAAI,CACN;AAEd,CAAC;AAED,MAAMhC,YAAY,GAAIvC,KAA8B,IAAMyD,KAA8B;EACpF,IAAIvD,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,EAAE;IACtB,OAAOA,KAAK,CAACuB,QAAQ,CAACkC,KAAK,CAAClE,KAAK,CAACS,KAAK,CAAC;;EAG5C,OAAOyD,KAAK,CAAClE,KAAK,CAACS,KAAK,KAAKA,KAAK;AACtC,CAAC;;;;"}
|
@@ -1,9 +1,21 @@
|
|
1
1
|
import cn from 'clsx';
|
2
|
+
import { FontSizes } from '../../types.js';
|
2
3
|
|
3
4
|
const createOptionClassName = (shouldPauseHoverState = false) => cn('group mb-px flex w-full text-sm flex-shrink-0 font-normal cursor-pointer items-center rounded bg-white px-2 leading-8 text-black aria-hidden:hidden gap-1.5 bg-white aria-current:wcag-grey-200 aria-disabled:text-black/25 aria-disabled:pointer-events-none', {
|
4
5
|
'hover:wcag-grey-200': !shouldPauseHoverState
|
5
6
|
});
|
6
7
|
const createCollectionClassName = () => 'flex flex-col gap-px';
|
8
|
+
const getFontSize = fontSize => {
|
9
|
+
switch (fontSize) {
|
10
|
+
case FontSizes.small:
|
11
|
+
return 'text-xs';
|
12
|
+
case FontSizes.large:
|
13
|
+
return 'text-base';
|
14
|
+
case FontSizes.medium:
|
15
|
+
default:
|
16
|
+
return 'text-sm';
|
17
|
+
}
|
18
|
+
};
|
7
19
|
|
8
|
-
export { createCollectionClassName, createOptionClassName };
|
20
|
+
export { createCollectionClassName, createOptionClassName, getFontSize };
|
9
21
|
//# sourceMappingURL=utilities.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utilities.js","sources":["../../../../../../../src/components/Select2/utilities.ts"],"sourcesContent":["import cn from 'clsx';\n\nexport const createOptionClassName = (shouldPauseHoverState = false) =>\n cn(\n 'group mb-px flex w-full text-sm flex-shrink-0 font-normal cursor-pointer items-center rounded bg-white px-2 leading-8 text-black aria-hidden:hidden gap-1.5 bg-white aria-current:wcag-grey-200 aria-disabled:text-black/25 aria-disabled:pointer-events-none',\n\n {\n 'hover:wcag-grey-200': !shouldPauseHoverState,\n }\n );\n\nexport const createCollectionClassName = () => 'flex flex-col gap-px';\n"],"names":["createOptionClassName","shouldPauseHoverState","cn","createCollectionClassName"],"mappings":"
|
1
|
+
{"version":3,"file":"utilities.js","sources":["../../../../../../../src/components/Select2/utilities.ts"],"sourcesContent":["import cn from 'clsx';\nimport { FontSize, FontSizes } from '../../types';\n\nexport const createOptionClassName = (shouldPauseHoverState = false) =>\n cn(\n 'group mb-px flex w-full text-sm flex-shrink-0 font-normal cursor-pointer items-center rounded bg-white px-2 leading-8 text-black aria-hidden:hidden gap-1.5 bg-white aria-current:wcag-grey-200 aria-disabled:text-black/25 aria-disabled:pointer-events-none',\n\n {\n 'hover:wcag-grey-200': !shouldPauseHoverState,\n }\n );\n\nexport const createCollectionClassName = () => 'flex flex-col gap-px';\n\nexport const getFontSize = (fontSize?: FontSize) => {\n switch (fontSize) {\n case FontSizes.small:\n return 'text-xs';\n\n case FontSizes.large:\n return 'text-base';\n\n case FontSizes.medium:\n default:\n return 'text-sm';\n }\n};\n"],"names":["createOptionClassName","shouldPauseHoverState","cn","createCollectionClassName","getFontSize","fontSize","FontSizes","small","large","medium"],"mappings":";;;MAGaA,qBAAqB,GAAGA,CAACC,qBAAqB,GAAG,KAAK,KAC/DC,EAAE,CACE,+PAA+P,EAE/P;EACI,qBAAqB,EAAE,CAACD;CAC3B;MAGIE,yBAAyB,GAAGA,MAAM;MAElCC,WAAW,GAAIC,QAAmB;EAC3C,QAAQA,QAAQ;IACZ,KAAKC,SAAS,CAACC,KAAK;MAChB,OAAO,SAAS;IAEpB,KAAKD,SAAS,CAACE,KAAK;MAChB,OAAO,WAAW;IAEtB,KAAKF,SAAS,CAACG,MAAM;IACrB;MACI,OAAO,SAAS;;AAE5B;;;;"}
|
@@ -50,8 +50,8 @@ function Alert(props) {
|
|
50
50
|
if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {
|
51
51
|
links.push(validationTexts.alert.messageAnd);
|
52
52
|
}
|
53
|
+
const rowIndex = table.getRowModel().rows.findIndex(row => row.id === error.rowId);
|
53
54
|
const handleClick = () => {
|
54
|
-
const rowIndex = table.getRowModel().rows.findIndex(row => row.id === error.rowId);
|
55
55
|
if (rowIndex > -1) {
|
56
56
|
scrollToRow(rowIndex);
|
57
57
|
} else {
|
@@ -74,7 +74,7 @@ function Alert(props) {
|
|
74
74
|
className: "text-blue",
|
75
75
|
onClick: handleClick,
|
76
76
|
role: "button"
|
77
|
-
}, rowIdentityColumn ? error.pendingChange._meta.original[rowIdentityColumn.id] :
|
77
|
+
}, rowIdentityColumn ? error.pendingChange._meta.original[rowIdentityColumn.id] : rowIndex + 1)));
|
78
78
|
// if appropriate, concatenate the item with the text ","
|
79
79
|
if (pendingChangesWithErrors.length > 2 && index < pendingChangesWithErrors.length - 2) {
|
80
80
|
links.push(', ');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Alert.js","sources":["../../../../../../../../../src/components/Table3/components/Editing/Alert.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { ScrollToOptions as ReactVirtualScrollToOptions } from '@tanstack/react-virtual';\nimport { Alert as BaseAlert, AlertProps as BaseAlertProps } from '../../../Alert/Alert';\nimport { TableRef } from '../../../../primitives/Table/types';\nimport { Tooltip } from '../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../Provider/Localization';\nimport { Dialog, DialogProps } from '../../../Dialog/Dialog';\nimport { Group } from '../../../Group/Group';\nimport { Button } from '../../../Button/Button';\n\ntype AlertProps<TType = unknown> = Omit<BaseAlertProps, 'children'> & {\n scrollToIndex: (index: number, options: ReactVirtualScrollToOptions) => void;\n table: ReactTable<TType>;\n tableRef: React.RefObject<TableRef>;\n};\n\nexport function Alert<TType = unknown>(props: AlertProps<TType>) {\n const { scrollToIndex, table, tableRef, ...attributes } = props;\n const { texts } = useLocalization();\n const validationTexts = texts.table3.editing.validation;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const [showFilterResetDialog, setShowFilterResetDialog] = React.useState<string | false>(false);\n\n const pendingChangesWithErrors = tableMeta.editing.getErrors<TType>();\n\n // mark errors being rendered as seen\n React.useEffect(() => {\n pendingChangesWithErrors.forEach(error => {\n tableMeta.editing.setRowErrorsSeen(error.rowId);\n });\n }, [pendingChangesWithErrors]);\n\n function scrollToRow(rowIndex: number) {\n tableMeta.rowActive.setRowActiveIndex(rowIndex);\n scrollToIndex(rowIndex, { align: 'center' });\n\n requestAnimationFrame(() => {\n const cell = tableRef.current?.querySelector(\n 'tbody > tr[data-row-active=\"true\"] > td[data-cell-editing-invalid=\"true\"]'\n );\n\n if (cell) {\n (cell as HTMLElement).focus?.();\n }\n });\n }\n\n // generate the \"N unsaved entries\" title\n const title = (\n pendingChangesWithErrors.length === 1 ? validationTexts.alert.titleOne : validationTexts.alert.titlePlural\n ).replace('[COUNT]', String(pendingChangesWithErrors.length));\n\n // generate links to each invalid row, to go into the error message\n const links: React.ReactNode[] = [];\n const rowIdentityColumn = tableMeta.rowIdentityColumnId ? table.getColumn(tableMeta.rowIdentityColumnId) : undefined;\n\n pendingChangesWithErrors.forEach((error, index) => {\n // if appropriate, concatenate the item with the text \"and\"\n if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {\n links.push(validationTexts.alert.messageAnd);\n }\n\n const handleClick = () => {\n const rowIndex = table.getRowModel().rows.findIndex(row => row.id === error.rowId);\n\n if (rowIndex > -1) {\n scrollToRow(rowIndex);\n } else {\n setShowFilterResetDialog(error.rowId);\n }\n };\n\n let tooltip;\n\n if (error.pendingChange._meta.errors.row) {\n tooltip = error.pendingChange._meta.errors.row;\n } else {\n const firstCellErrorColumnId = Object.keys(error.pendingChange._meta.errors.cells)[0];\n const columnName = table.getAllColumns().find(column => column.id === firstCellErrorColumnId)?.columnDef.meta?.header;\n tooltip = `${columnName}: ${error.pendingChange._meta.errors.cells[firstCellErrorColumnId]}`;\n }\n\n links.push(\n <Tooltip key={error.rowId} title={tooltip}>\n <span className=\"text-blue\" onClick={handleClick} role=\"button\">\n {rowIdentityColumn ? error.pendingChange._meta.original[rowIdentityColumn.id] : error.rowId}\n </span>\n </Tooltip>\n );\n\n // if appropriate, concatenate the item with the text \",\"\n if (pendingChangesWithErrors.length > 2 && index < pendingChangesWithErrors.length - 2) {\n links.push(', ');\n }\n });\n\n // generate the \"Row N is incomplete and hasn't been saved\" error message\n const message = (links.length === 1 ? validationTexts.alert.messageOne : validationTexts.alert.messagePlural)\n .split(/(\\[\\w+\\])/)\n .map(part => {\n if (part === '[COLUMN]') {\n return rowIdentityColumn?.columnDef.meta?.header ?? validationTexts.alert.messageRow;\n }\n\n if (part === '[ROW]') {\n return links;\n }\n\n return part;\n });\n\n const handleResetFilters = () => {\n table.resetGlobalFilter();\n table.resetColumnFilters();\n\n requestAnimationFrame(() => {\n const rowIndex = table.getRowModel().rows.findIndex(row => row.id === showFilterResetDialog);\n\n if (rowIndex > -1) {\n scrollToRow(rowIndex);\n }\n\n setShowFilterResetDialog(false);\n });\n };\n\n return (\n <>\n <BaseAlert {...attributes} state=\"error\">\n <span className=\"font-bold\">{title}</span>\n {message}\n </BaseAlert>\n <FilterResetDialog\n open={showFilterResetDialog !== false}\n onChange={() => setShowFilterResetDialog(false)}\n onSubmit={handleResetFilters}\n />\n </>\n );\n}\n\ntype FilterResetDialogProps = Omit<DialogProps, 'children'> & {\n onSubmit: () => void;\n};\n\nfunction FilterResetDialog(props: FilterResetDialogProps) {\n const { onSubmit: handleSubmit, ...dialogProps } = props;\n const { texts } = useLocalization();\n\n return (\n <Dialog {...dialogProps} size=\"xs\">\n <Dialog.Content aria-label=\"Create a new account\">\n <Dialog.Title>{texts.table3.editing.validation.resetFiltersDialog.title}</Dialog.Title>\n\n <p>{texts.table3.editing.validation.resetFiltersDialog.description}</p>\n\n <Dialog.Footer>\n <Group>\n <Dialog.Close>\n <Button>{texts.table3.editing.validation.resetFiltersDialog.cancel}</Button>\n </Dialog.Close>\n <Button appearance=\"primary\" onClick={handleSubmit}>\n {texts.table3.editing.validation.resetFiltersDialog.confirm}\n </Button>\n </Group>\n </Dialog.Footer>\n </Dialog.Content>\n </Dialog>\n );\n}\n"],"names":["Alert","props","scrollToIndex","table","tableRef","attributes","texts","useLocalization","validationTexts","table3","editing","validation","tableMeta","options","meta","showFilterResetDialog","setShowFilterResetDialog","React","useState","pendingChangesWithErrors","getErrors","useEffect","forEach","error","setRowErrorsSeen","rowId","scrollToRow","rowIndex","rowActive","setRowActiveIndex","align","requestAnimationFrame","cell","_tableRef$current","current","querySelector","_cell$focus","focus","call","title","length","alert","titleOne","titlePlural","replace","String","links","rowIdentityColumn","rowIdentityColumnId","getColumn","undefined","index","push","messageAnd","handleClick","getRowModel","rows","findIndex","row","id","tooltip","pendingChange","_meta","errors","_table$getAllColumns$","_table$getAllColumns$2","firstCellErrorColumnId","Object","keys","cells","columnName","getAllColumns","find","column","columnDef","header","Tooltip","key","className","onClick","role","original","message","messageOne","messagePlural","split","map","part","_rowIdentityColumn$co","_rowIdentityColumn$co2","messageRow","handleResetFilters","resetGlobalFilter","resetColumnFilters","BaseAlert","state","FilterResetDialog","open","onChange","onSubmit","handleSubmit","dialogProps","Dialog","size","Content","Title","resetFiltersDialog","description","Footer","Group","Close","Button","cancel","appearance","confirm"],"mappings":";;;;;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,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC+F,kBAAkB,CAACnE,KAAK,CAAgB,eAEvFtB,wCAAIX,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC+F,kBAAkB,CAACC,WAAW,CAAK,eAEvE1F,6BAACqF,MAAM,CAACM,MAAM,qBACV3F,6BAAC4F,KAAK,qBACF5F,6BAACqF,MAAM,CAACQ,KAAK,qBACT7F,6BAAC8F,MAAM,QAAEzG,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC+F,kBAAkB,CAACM,MAAM,CAAU,CACjE,eACf/F,6BAAC8F,MAAM;IAACE,UAAU,EAAC,SAAS;IAAClC,OAAO,EAAEqB;KACjC9F,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC+F,kBAAkB,CAACQ,OAAO,CACtD,CACL,CACI,CACH,CACZ;AAEjB;;;;"}
|
1
|
+
{"version":3,"file":"Alert.js","sources":["../../../../../../../../../src/components/Table3/components/Editing/Alert.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { ScrollToOptions as ReactVirtualScrollToOptions } from '@tanstack/react-virtual';\nimport { Alert as BaseAlert, AlertProps as BaseAlertProps } from '../../../Alert/Alert';\nimport { TableRef } from '../../../../primitives/Table/types';\nimport { Tooltip } from '../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../Provider/Localization';\nimport { Dialog, DialogProps } from '../../../Dialog/Dialog';\nimport { Group } from '../../../Group/Group';\nimport { Button } from '../../../Button/Button';\n\ntype AlertProps<TType = unknown> = Omit<BaseAlertProps, 'children'> & {\n scrollToIndex: (index: number, options: ReactVirtualScrollToOptions) => void;\n table: ReactTable<TType>;\n tableRef: React.RefObject<TableRef>;\n};\n\nexport function Alert<TType = unknown>(props: AlertProps<TType>) {\n const { scrollToIndex, table, tableRef, ...attributes } = props;\n const { texts } = useLocalization();\n const validationTexts = texts.table3.editing.validation;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const [showFilterResetDialog, setShowFilterResetDialog] = React.useState<string | false>(false);\n\n const pendingChangesWithErrors = tableMeta.editing.getErrors<TType>();\n\n // mark errors being rendered as seen\n React.useEffect(() => {\n pendingChangesWithErrors.forEach(error => {\n tableMeta.editing.setRowErrorsSeen(error.rowId);\n });\n }, [pendingChangesWithErrors]);\n\n function scrollToRow(rowIndex: number) {\n tableMeta.rowActive.setRowActiveIndex(rowIndex);\n scrollToIndex(rowIndex, { align: 'center' });\n\n requestAnimationFrame(() => {\n const cell = tableRef.current?.querySelector(\n 'tbody > tr[data-row-active=\"true\"] > td[data-cell-editing-invalid=\"true\"]'\n );\n\n if (cell) {\n (cell as HTMLElement).focus?.();\n }\n });\n }\n\n // generate the \"N unsaved entries\" title\n const title = (\n pendingChangesWithErrors.length === 1 ? validationTexts.alert.titleOne : validationTexts.alert.titlePlural\n ).replace('[COUNT]', String(pendingChangesWithErrors.length));\n\n // generate links to each invalid row, to go into the error message\n const links: React.ReactNode[] = [];\n const rowIdentityColumn = tableMeta.rowIdentityColumnId ? table.getColumn(tableMeta.rowIdentityColumnId) : undefined;\n\n pendingChangesWithErrors.forEach((error, index) => {\n // if appropriate, concatenate the item with the text \"and\"\n if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {\n links.push(validationTexts.alert.messageAnd);\n }\n const rowIndex = table.getRowModel().rows.findIndex(row => row.id === error.rowId);\n\n const handleClick = () => {\n if (rowIndex > -1) {\n scrollToRow(rowIndex);\n } else {\n setShowFilterResetDialog(error.rowId);\n }\n };\n\n let tooltip;\n\n if (error.pendingChange._meta.errors.row) {\n tooltip = error.pendingChange._meta.errors.row;\n } else {\n const firstCellErrorColumnId = Object.keys(error.pendingChange._meta.errors.cells)[0];\n const columnName = table.getAllColumns().find(column => column.id === firstCellErrorColumnId)?.columnDef.meta?.header;\n tooltip = `${columnName}: ${error.pendingChange._meta.errors.cells[firstCellErrorColumnId]}`;\n }\n\n links.push(\n <Tooltip key={error.rowId} title={tooltip}>\n <span className=\"text-blue\" onClick={handleClick} role=\"button\">\n {rowIdentityColumn ? error.pendingChange._meta.original[rowIdentityColumn.id] : rowIndex + 1}\n </span>\n </Tooltip>\n );\n\n // if appropriate, concatenate the item with the text \",\"\n if (pendingChangesWithErrors.length > 2 && index < pendingChangesWithErrors.length - 2) {\n links.push(', ');\n }\n });\n\n // generate the \"Row N is incomplete and hasn't been saved\" error message\n const message = (links.length === 1 ? validationTexts.alert.messageOne : validationTexts.alert.messagePlural)\n .split(/(\\[\\w+\\])/)\n .map(part => {\n if (part === '[COLUMN]') {\n return rowIdentityColumn?.columnDef.meta?.header ?? validationTexts.alert.messageRow;\n }\n\n if (part === '[ROW]') {\n return links;\n }\n\n return part;\n });\n\n const handleResetFilters = () => {\n table.resetGlobalFilter();\n table.resetColumnFilters();\n\n requestAnimationFrame(() => {\n const rowIndex = table.getRowModel().rows.findIndex(row => row.id === showFilterResetDialog);\n\n if (rowIndex > -1) {\n scrollToRow(rowIndex);\n }\n\n setShowFilterResetDialog(false);\n });\n };\n\n return (\n <>\n <BaseAlert {...attributes} state=\"error\">\n <span className=\"font-bold\">{title}</span>\n {message}\n </BaseAlert>\n <FilterResetDialog\n open={showFilterResetDialog !== false}\n onChange={() => setShowFilterResetDialog(false)}\n onSubmit={handleResetFilters}\n />\n </>\n );\n}\n\ntype FilterResetDialogProps = Omit<DialogProps, 'children'> & {\n onSubmit: () => void;\n};\n\nfunction FilterResetDialog(props: FilterResetDialogProps) {\n const { onSubmit: handleSubmit, ...dialogProps } = props;\n const { texts } = useLocalization();\n\n return (\n <Dialog {...dialogProps} size=\"xs\">\n <Dialog.Content aria-label=\"Create a new account\">\n <Dialog.Title>{texts.table3.editing.validation.resetFiltersDialog.title}</Dialog.Title>\n\n <p>{texts.table3.editing.validation.resetFiltersDialog.description}</p>\n\n <Dialog.Footer>\n <Group>\n <Dialog.Close>\n <Button>{texts.table3.editing.validation.resetFiltersDialog.cancel}</Button>\n </Dialog.Close>\n <Button appearance=\"primary\" onClick={handleSubmit}>\n {texts.table3.editing.validation.resetFiltersDialog.confirm}\n </Button>\n </Group>\n </Dialog.Footer>\n </Dialog.Content>\n </Dialog>\n );\n}\n"],"names":["Alert","props","scrollToIndex","table","tableRef","attributes","texts","useLocalization","validationTexts","table3","editing","validation","tableMeta","options","meta","showFilterResetDialog","setShowFilterResetDialog","React","useState","pendingChangesWithErrors","getErrors","useEffect","forEach","error","setRowErrorsSeen","rowId","scrollToRow","rowIndex","rowActive","setRowActiveIndex","align","requestAnimationFrame","cell","_tableRef$current","current","querySelector","_cell$focus","focus","call","title","length","alert","titleOne","titlePlural","replace","String","links","rowIdentityColumn","rowIdentityColumnId","getColumn","undefined","index","push","messageAnd","getRowModel","rows","findIndex","row","id","handleClick","tooltip","pendingChange","_meta","errors","_table$getAllColumns$","_table$getAllColumns$2","firstCellErrorColumnId","Object","keys","cells","columnName","getAllColumns","find","column","columnDef","header","Tooltip","key","className","onClick","role","original","message","messageOne","messagePlural","split","map","part","_rowIdentityColumn$co","_rowIdentityColumn$co2","messageRow","handleResetFilters","resetGlobalFilter","resetColumnFilters","BaseAlert","state","FilterResetDialog","open","onChange","onSubmit","handleSubmit","dialogProps","Dialog","size","Content","Title","resetFiltersDialog","description","Footer","Group","Close","Button","cancel","appearance","confirm"],"mappings":";;;;;;;;SAiBgBA,KAAKA,CAAkBC,KAAwB;EAC3D,MAAM;IAAEC,aAAa;IAAEC,KAAK;IAAEC,QAAQ;IAAE,GAAGC;GAAY,GAAGJ,KAAK;EAC/D,MAAM;IAAEK;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,eAAe,GAAGF,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU;EACvD,MAAMC,SAAS,GAAGT,KAAK,CAACU,OAAO,CAACC,IAA6B;EAC7D,MAAM,CAACC,qBAAqB,EAAEC,wBAAwB,CAAC,GAAGC,cAAK,CAACC,QAAQ,C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,CAAU,CACjE,eACf/F,6BAAC8F,MAAM;IAACE,UAAU,EAAC,SAAS;IAAClC,OAAO,EAAEqB;KACjC9F,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC+F,kBAAkB,CAACQ,OAAO,CACtD,CACL,CACI,CACH,CACZ;AAEjB;;;;"}
|
@@ -2,7 +2,7 @@ import React__default from 'react';
|
|
2
2
|
import { FocusScope } from '@react-aria/focus';
|
3
3
|
import { Header } from './components/Header/Header.js';
|
4
4
|
import { Body } from './components/Body/Body.js';
|
5
|
-
import {
|
5
|
+
import { Foot } from './components/Footer/Footer.js';
|
6
6
|
import { EmptyStateBody } from './components/Body/EmptyStateBody.js';
|
7
7
|
import { TableToolbar } from './components/Toolbar/Toolbar.js';
|
8
8
|
|
@@ -45,7 +45,9 @@ function TableGrid(props) {
|
|
45
45
|
enableHorizontalArrowKeyNavigation: enableHorizontalArrowKeyNavigation,
|
46
46
|
table: table.instance,
|
47
47
|
style: table.renderer.style
|
48
|
-
}, table.renderer.rows), table.meta.footer.isEnabled ?
|
48
|
+
}, table.renderer.rows), table.meta.footer.isEnabled ? /*#__PURE__*/React__default.createElement(Foot, {
|
49
|
+
table: table.instance
|
50
|
+
}) : null)) : ( /*#__PURE__*/React__default.createElement(EmptyStateBody, {
|
49
51
|
emptyState: table.props.emptyState
|
50
52
|
})))));
|
51
53
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Table.js","sources":["../../../../../../../../src/primitives/Table/Core/Table.tsx"],"sourcesContent":["import React from 'react';\nimport { FocusScope } from '@react-aria/focus';\nimport { Header } from './components/Header/Header';\nimport { Body } from './components/Body/Body';\nimport {
|
1
|
+
{"version":3,"file":"Table.js","sources":["../../../../../../../../src/primitives/Table/Core/Table.tsx"],"sourcesContent":["import React from 'react';\nimport { FocusScope } from '@react-aria/focus';\nimport { Header } from './components/Header/Header';\nimport { Body } from './components/Body/Body';\nimport { Foot } from './components/Footer/Footer';\nimport { EmptyStateBody } from './components/Body/EmptyStateBody';\nimport { useTableReturnValue } from './useTable';\nimport { TableToolbar } from './components/Toolbar/Toolbar';\nimport './style.css';\n\ntype TableProps = {\n children: JSX.Element | Array<JSX.Element | null>;\n};\n\nexport function Table(props: TableProps) {\n return <>{props.children}</>;\n}\nTable.Toolbar = TableToolbar;\nTable.Grid = TableGrid;\n\nexport type TableGridProps<TType = unknown> = React.TableHTMLAttributes<HTMLTableElement> & {\n 'data-taco': string;\n enableHorizontalArrowKeyNavigation?: boolean;\n table: useTableReturnValue<TType>;\n};\n\nexport function TableGrid<TType = unknown>(props: TableGridProps<TType>) {\n const { enableHorizontalArrowKeyNavigation, table, ...attributes } = props;\n const handleFocus =\n table.meta.rowActive.rowActiveIndex === undefined\n ? (event: React.FocusEvent) => {\n table.meta.rowActive.handleFocus(event, table.meta.length, table.renderer.scrollToIndex);\n }\n : undefined;\n\n return (\n <>\n <style>{table.stylesheet}</style>\n <FocusScope>\n <table\n {...attributes}\n id={table.id}\n data-table-font-size={table.meta.fontSize.size}\n data-table-grouped={!!table.state.grouping?.length}\n data-table-horizontally-scrolled={table.meta.columnFreezing.isHorizontallyScrolled ? true : undefined}\n data-table-status={table.meta.server.isEnabled ? (table.meta.server.isReady ? 'ready' : undefined) : 'ready'}\n data-table-pause-hover={table.meta.rowActive.isHoverStatePaused ? true : undefined}\n data-table-resizing={table.state.columnSizingInfo.isResizingColumn ? true : undefined}\n data-table-row-height={table.meta.rowHeight.height}\n onFocus={handleFocus}\n onScroll={table.meta.columnFreezing.handleScroll}\n ref={table.ref}\n style={table.style}\n tabIndex={-1}>\n <thead>\n {table.instance.getHeaderGroups().map(headerGroup => (\n <tr key={headerGroup.id}>\n {headerGroup.headers.map(props => (\n <Header key={props.id} header={props} scrollToIndex={table.renderer.scrollToIndex} />\n ))}\n </tr>\n ))}\n </thead>\n {table.instance.getRowModel().rows.length ? (\n <>\n <Body\n enableHorizontalArrowKeyNavigation={enableHorizontalArrowKeyNavigation}\n table={table.instance}\n style={table.renderer.style}>\n {table.renderer.rows}\n </Body>\n {table.meta.footer.isEnabled ? <Foot table={table.instance} /> : null}\n </>\n ) : (\n <EmptyStateBody emptyState={table.props.emptyState} />\n )}\n </table>\n </FocusScope>\n </>\n );\n}\n"],"names":["Table","props","React","children","Toolbar","TableToolbar","Grid","TableGrid","enableHorizontalArrowKeyNavigation","table","attributes","handleFocus","meta","rowActive","rowActiveIndex","undefined","event","length","renderer","scrollToIndex","stylesheet","FocusScope","id","fontSize","size","_table$state$grouping","state","grouping","columnFreezing","isHorizontallyScrolled","server","isEnabled","isReady","isHoverStatePaused","columnSizingInfo","isResizingColumn","rowHeight","height","onFocus","onScroll","handleScroll","ref","style","tabIndex","instance","getHeaderGroups","map","headerGroup","key","headers","Header","header","getRowModel","rows","Body","footer","Foot","EmptyStateBody","emptyState"],"mappings":";;;;;;;;SAcgBA,KAAKA,CAACC,KAAiB;EACnC,oBAAOC,4DAAGD,KAAK,CAACE,QAAQ,CAAI;AAChC;AACAH,KAAK,CAACI,OAAO,GAAGC,YAAY;AAC5BL,KAAK,CAACM,IAAI,GAAGC,SAAS;SAQNA,SAASA,CAAkBN,KAA4B;;EACnE,MAAM;IAAEO,kCAAkC;IAAEC,KAAK;IAAE,GAAGC;GAAY,GAAGT,KAAK;EAC1E,MAAMU,WAAW,GACbF,KAAK,CAACG,IAAI,CAACC,SAAS,CAACC,cAAc,KAAKC,SAAS,GAC1CC,KAAuB;IACpBP,KAAK,CAACG,IAAI,CAACC,SAAS,CAACF,WAAW,CAACK,KAAK,EAAEP,KAAK,CAACG,IAAI,CAACK,MAAM,EAAER,KAAK,CAACS,QAAQ,CAACC,aAAa,CAAC;GAC3F,GACDJ,SAAS;EAEnB,oBACIb,yEACIA,4CAAQO,KAAK,CAACW,UAAU,CAAS,eACjClB,6BAACmB,UAAU,qBACPnB,wDACQQ,UAAU;IACdY,EAAE,EAAEb,KAAK,CAACa,EAAE;4BACUb,KAAK,CAACG,IAAI,CAACW,QAAQ,CAACC,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EA,kCAAkC;IACtEC,KAAK,EAAEA,KAAK,CAACmC,QAAQ;IACrBF,KAAK,EAAEjC,KAAK,CAACS,QAAQ,CAACwB;KACrBjC,KAAK,CAACS,QAAQ,CAACmC,IAAI,CACjB,EACN5C,KAAK,CAACG,IAAI,CAAC2C,MAAM,CAACxB,SAAS,gBAAG7B,6BAACsD,IAAI;IAAC/C,KAAK,EAAEA,KAAK,CAACmC;IAAY,GAAG,IAAI,CACtE,mBAEH1C,6BAACuD,cAAc;IAACC,UAAU,EAAEjD,KAAK,CAACR,KAAK,CAACyD;IAAc,CACzD,CACG,CACC,CACd;AAEX;;;;"}
|
@@ -2,16 +2,25 @@ import React__default from 'react';
|
|
2
2
|
import { flexRender } from '@tanstack/react-table';
|
3
3
|
import { Summary } from './Summary.js';
|
4
4
|
|
5
|
-
function
|
6
|
-
|
5
|
+
function Foot(props) {
|
6
|
+
const nonGroupedHeaders = props.table.getFooterGroups()[0].headers.filter(header => !header.column.getIsGrouped());
|
7
|
+
return /*#__PURE__*/React__default.createElement("tfoot", null, /*#__PURE__*/React__default.createElement("tr", null, nonGroupedHeaders.map((header, index) => ( /*#__PURE__*/React__default.createElement(Footer, {
|
7
8
|
key: header.id,
|
8
|
-
|
9
|
+
header: header,
|
10
|
+
index: index
|
11
|
+
})))));
|
12
|
+
}
|
13
|
+
function Footer(props) {
|
14
|
+
return /*#__PURE__*/React__default.createElement(MemoedFooter, {
|
15
|
+
footer: props.header,
|
16
|
+
index: props.index
|
9
17
|
});
|
10
18
|
}
|
11
19
|
const MemoedFooter = /*#__PURE__*/React__default.memo(function MemoedFooter(props) {
|
12
20
|
var _footer$subHeaders, _footer$subHeaders$fi;
|
13
21
|
const {
|
14
|
-
footer
|
22
|
+
footer,
|
23
|
+
index
|
15
24
|
} = props;
|
16
25
|
const columnMeta = footer.column.columnDef.meta;
|
17
26
|
// getIsPinned returns true for split header groups, even if the split group has no pinned sub headers
|
@@ -24,7 +33,7 @@ const MemoedFooter = /*#__PURE__*/React__default.memo(function MemoedFooter(prop
|
|
24
33
|
}
|
25
34
|
let content;
|
26
35
|
let align;
|
27
|
-
if (
|
36
|
+
if (index === 0) {
|
28
37
|
align = 'left';
|
29
38
|
content = /*#__PURE__*/React__default.createElement(Summary, {
|
30
39
|
table: footer.getContext().table
|
@@ -42,5 +51,5 @@ const MemoedFooter = /*#__PURE__*/React__default.memo(function MemoedFooter(prop
|
|
42
51
|
}, content);
|
43
52
|
});
|
44
53
|
|
45
|
-
export { Footer };
|
54
|
+
export { Foot, Footer };
|
46
55
|
//# sourceMappingURL=Footer.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Footer.js","sources":["../../../../../../../../../../src/primitives/Table/Core/components/Footer/Footer.tsx"],"sourcesContent":["import React from 'react';\nimport {
|
1
|
+
{"version":3,"file":"Footer.js","sources":["../../../../../../../../../../src/primitives/Table/Core/components/Footer/Footer.tsx"],"sourcesContent":["import React from 'react';\nimport {\n Header as ReactTableHeader,\n ColumnMeta as ReactTableColumnMeta,\n flexRender,\n Table as ReactTable,\n} from '@tanstack/react-table';\nimport { Summary } from './Summary';\n\nexport type FootProps<TType = unknown> = {\n table: ReactTable<TType>;\n};\nexport function Foot<TType = unknown>(props: FootProps<TType>) {\n const nonGroupedHeaders = props.table.getFooterGroups()[0].headers.filter(header => !header.column.getIsGrouped());\n return (\n <tfoot>\n <tr>\n {nonGroupedHeaders.map((header, index) => (\n <Footer key={header.id} header={header} index={index} />\n ))}\n </tr>\n </tfoot>\n );\n}\n\nexport type FooterProps<TType = unknown> = {\n header: ReactTableHeader<TType, unknown>;\n index: number;\n};\nexport function Footer<TType = unknown>(props: FooterProps<TType>) {\n return <MemoedFooter footer={props.header} index={props.index} />;\n}\n\nexport type MemoedFooterProps<TType = unknown> = {\n footer: ReactTableHeader<TType, unknown>;\n index: number;\n};\nconst MemoedFooter = React.memo(function MemoedFooter<TType = unknown>(props: MemoedFooterProps<TType>) {\n const { footer, index } = props;\n const columnMeta = footer.column.columnDef.meta as ReactTableColumnMeta<TType, unknown>;\n\n // getIsPinned returns true for split header groups, even if the split group has no pinned sub headers\n const isHeaderGroup = !!footer.subHeaders?.length;\n const isPinned = isHeaderGroup\n ? footer.subHeaders.find(x => x.column.getIsPinned())?.column.getIsPinned()\n : footer.column.getIsPinned();\n\n const style: React.CSSProperties = {};\n\n if (isPinned) {\n // pinned columns should be offset from either the left or right\n style[isPinned] = `${footer.column.getStart(isPinned) - 1}px`;\n }\n\n let content;\n let align;\n\n if (index === 0) {\n align = 'left';\n content = <Summary table={footer.getContext().table} />;\n } else {\n align = columnMeta.align;\n content = footer.isPlaceholder ? null : flexRender(footer.column.columnDef.footer, footer.getContext());\n }\n\n return (\n <td\n key={footer.id}\n data-cell-align={align}\n data-cell-id={footer.id}\n data-cell-pinned={isPinned ? isPinned : undefined}\n style={style}>\n {content}\n </td>\n );\n}) as <TType = unknown>(props: MemoedFooterProps<TType>) => JSX.Element;\n"],"names":["Foot","props","nonGroupedHeaders","table","getFooterGroups","headers","filter","header","column","getIsGrouped","React","map","index","Footer","key","id","MemoedFooter","footer","memo","columnMeta","columnDef","meta","isHeaderGroup","_footer$subHeaders","subHeaders","length","isPinned","_footer$subHeaders$fi","find","x","getIsPinned","style","getStart","content","align","Summary","getContext","isPlaceholder","flexRender","undefined"],"mappings":";;;;SAYgBA,IAAIA,CAAkBC,KAAuB;EACzD,MAAMC,iBAAiB,GAAGD,KAAK,CAACE,KAAK,CAACC,eAAe,EAAE,CAAC,CAAC,CAAC,CAACC,OAAO,CAACC,MAAM,CAACC,MAAM,IAAI,CAACA,MAAM,CAACC,MAAM,CAACC,YAAY,EAAE,CAAC;EAClH,oBACIC,yDACIA,yCACKR,iBAAiB,CAACS,GAAG,CAAC,CAACJ,MAAM,EAAEK,KAAK,oBACjCF,6BAACG,MAAM;IAACC,GAAG,EAAEP,MAAM,CAACQ,EAAE;IAAER,MAAM,EAAEA,MAAM;IAAEK,KAAK,EAAEA;IAAS,CAC3D,CAAC,CAC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AAM,CAACT,MAAM,CAACY,SAAS,CAACH,MAAM,EAAEA,MAAM,CAACmB,UAAU,EAAE,CAAC;;EAG3G,oBACI1B;IACII,GAAG,EAAEG,MAAM,CAACF,EAAE;uBACGmB,KAAK;oBACRjB,MAAM,CAACF,EAAE;wBACLW,QAAQ,GAAGA,QAAQ,GAAGa,SAAS;IACjDR,KAAK,EAAEA;KACNE,OAAO,CACP;AAEb,CAAC,CAAsE;;;;"}
|
@@ -55,12 +55,21 @@ function Print(props) {
|
|
55
55
|
// do this here because Safari doesn't support the beforeprint event
|
56
56
|
togglePrinting(true);
|
57
57
|
requestAnimationFrame(() => {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
requestAnimationFrame(() => {
|
59
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
60
|
+
if (isSafari) {
|
61
|
+
try {
|
62
|
+
// Try using document.execCommand for printing in Safari
|
63
|
+
document.execCommand('print', false, undefined);
|
64
|
+
} catch (error) {
|
65
|
+
// If document.execCommand fails or throws an error, fallback to window.print()
|
66
|
+
window.print();
|
67
|
+
}
|
68
|
+
} else {
|
69
|
+
// Execute window.print() for all other browsers
|
70
|
+
window.print();
|
71
|
+
}
|
72
|
+
});
|
64
73
|
});
|
65
74
|
}, 150);
|
66
75
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Print.js","sources":["../../../../../../../../../../../../src/primitives/Table/Core/components/Toolbar/components/Print/Print.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { IconButton } from '../../../../../../../components/IconButton/IconButton';\nimport { useLocalization } from '../../../../../../../components/Provider/Localization';\nimport { useToast } from '../../../../../../../components/Toast/Toaster';\nimport { TableRef } from '../../../../../types';\nimport { PrintDialog } from './PrintDialog';\nimport { Shortcut } from '../../../../../../../components/Shortcut/Shortcut';\n\nexport type PrintProps<TType = unknown> = {\n table: ReactTable<TType>;\n tableId: string;\n tableRef: React.RefObject<TableRef>;\n};\n\nexport function Print<TType = unknown>(props: PrintProps<TType>) {\n const { table, tableId, tableRef } = props;\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLButtonElement>(null);\n const lastScrollTopRef = React.useRef<number>();\n const toast = useToast();\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const { allRows, orientation, size, splitGroups } = tableMeta.printing.settings;\n\n const togglePrinting = React.useCallback(\n enabled => {\n tableMeta.printing.setIsPrinting(enabled);\n\n if (tableRef.current) {\n if (enabled) {\n lastScrollTopRef.current = tableRef.current.scrollTop;\n } else if (lastScrollTopRef.current !== undefined) {\n tableRef.current.scrollTop = lastScrollTopRef.current;\n lastScrollTopRef.current = undefined;\n }\n }\n },\n [tableRef.current]\n );\n\n React.useEffect(() => {\n const afterPrint = () => {\n togglePrinting(false);\n };\n\n window.addEventListener('afterprint', afterPrint);\n\n return () => {\n window.removeEventListener('afterprint', afterPrint);\n };\n }, []);\n\n const print = async () => {\n const toastRef = toast.loading(texts.table.print.loading);\n\n if (tableMeta.server.isEnabled && tableMeta.server.loadAllIfNeeded) {\n try {\n await tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, undefined);\n } catch (error) {\n const errorMessage = `${texts.table.print.error}: ${error}`;\n console.error(errorMessage);\n toastRef.error(errorMessage);\n }\n }\n\n // this might close immediately if the dataset is small - this is okay\n toastRef.close();\n\n // use a timeout to let the toast close, otherwise it freezes mid animation when the print dialog opens\n setTimeout(() => {\n // do this here because Safari doesn't support the beforeprint event\n togglePrinting(true);\n\n requestAnimationFrame(() => {\n try {\n // window.print doesn't always work in Safari :man_shrugging:\n document.execCommand('print', false, undefined);\n } catch {\n window.print();\n }\n });\n }, 150);\n };\n\n const printStyle = [`@page { size: ${size} ${orientation}; }`];\n\n if (!allRows) {\n printStyle.push(`table[data-taco^='table']#${tableId} tr:not([data-row-selected=\"true\"]) { display: none; }`);\n }\n\n if (splitGroups) {\n printStyle.push(`table[data-taco^='table']#${tableId} tr[data-row-group]:not(:first-child) { break-before: page; }`);\n }\n\n const shortcut = { key: 'p', meta: true, shift: false };\n const tooltip = (\n <>\n {texts.table.print.tooltip}\n <Shortcut className=\"ml-2\" keys={shortcut} />\n </>\n );\n\n return (\n <>\n <style media=\"print\">{printStyle.join('\\n')}</style>\n <IconButton\n icon=\"print\"\n aria-label={texts.table.print.tooltip}\n dialog={dialogProps => (\n <PrintDialog\n {...dialogProps}\n table={table}\n onAccept={print}\n orientation={orientation}\n setOrientation={value => tableMeta.printing.setSetting('orientation', value)}\n size={size}\n setSize={value => tableMeta.printing.setSetting('size', value)}\n allRows={allRows}\n setAllRows={value => tableMeta.printing.setSetting('allRows', value)}\n splitGroups={splitGroups}\n setSplitGroups={value => tableMeta.printing.setSetting('splitGroups', value)}\n />\n )}\n ref={ref}\n shortcut={shortcut}\n tooltip={tooltip}\n />\n </>\n );\n}\n"],"names":["Print","props","table","tableId","tableRef","texts","useLocalization","ref","React","useRef","lastScrollTopRef","toast","useToast","tableMeta","options","meta","allRows","orientation","size","splitGroups","printing","settings","togglePrinting","useCallback","enabled","setIsPrinting","current","scrollTop","undefined","useEffect","afterPrint","window","addEventListener","removeEventListener","print","toastRef","close","setTimeout","requestAnimationFrame","document","execCommand","loading","_temp2","server","isEnabled","loadAllIfNeeded","_temp","_catch","Promise","resolve","getState","sorting","columnFilters","then","error","errorMessage","console","_temp3","e","reject","printStyle","push","shortcut","key","shift","tooltip","Shortcut","className","keys","media","join","IconButton","icon","dialog","dialogProps","PrintDialog","onAccept","setOrientation","value","setSetting","setSize","setAllRows","setSplitGroups"],"mappings":";;;;;;;;SAegBA,KAAKA,CAAkBC,KAAwB;EAC3D,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC;GAAU,GAAGH,KAAK;EAC1C,MAAM;IAAEI;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAoB,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js","sources":["../../../../../../../../../../../../src/primitives/Table/Core/components/Toolbar/components/Print/Print.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { IconButton } from '../../../../../../../components/IconButton/IconButton';\nimport { useLocalization } from '../../../../../../../components/Provider/Localization';\nimport { useToast } from '../../../../../../../components/Toast/Toaster';\nimport { TableRef } from '../../../../../types';\nimport { PrintDialog } from './PrintDialog';\nimport { Shortcut } from '../../../../../../../components/Shortcut/Shortcut';\n\nexport type PrintProps<TType = unknown> = {\n table: ReactTable<TType>;\n tableId: string;\n tableRef: React.RefObject<TableRef>;\n};\n\nexport function Print<TType = unknown>(props: PrintProps<TType>) {\n const { table, tableId, tableRef } = props;\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLButtonElement>(null);\n const lastScrollTopRef = React.useRef<number>();\n const toast = useToast();\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const { allRows, orientation, size, splitGroups } = tableMeta.printing.settings;\n\n const togglePrinting = React.useCallback(\n enabled => {\n tableMeta.printing.setIsPrinting(enabled);\n\n if (tableRef.current) {\n if (enabled) {\n lastScrollTopRef.current = tableRef.current.scrollTop;\n } else if (lastScrollTopRef.current !== undefined) {\n tableRef.current.scrollTop = lastScrollTopRef.current;\n lastScrollTopRef.current = undefined;\n }\n }\n },\n [tableRef.current]\n );\n\n React.useEffect(() => {\n const afterPrint = () => {\n togglePrinting(false);\n };\n\n window.addEventListener('afterprint', afterPrint);\n\n return () => {\n window.removeEventListener('afterprint', afterPrint);\n };\n }, []);\n\n const print = async () => {\n const toastRef = toast.loading(texts.table.print.loading);\n\n if (tableMeta.server.isEnabled && tableMeta.server.loadAllIfNeeded) {\n try {\n await tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, undefined);\n } catch (error) {\n const errorMessage = `${texts.table.print.error}: ${error}`;\n console.error(errorMessage);\n toastRef.error(errorMessage);\n }\n }\n\n // this might close immediately if the dataset is small - this is okay\n toastRef.close();\n\n // use a timeout to let the toast close, otherwise it freezes mid animation when the print dialog opens\n setTimeout(() => {\n // do this here because Safari doesn't support the beforeprint event\n togglePrinting(true);\n\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n\n if (isSafari) {\n try {\n // Try using document.execCommand for printing in Safari\n document.execCommand('print', false, undefined);\n } catch (error) {\n // If document.execCommand fails or throws an error, fallback to window.print()\n window.print();\n }\n } else {\n // Execute window.print() for all other browsers\n window.print();\n }\n });\n });\n }, 150);\n };\n\n const printStyle = [`@page { size: ${size} ${orientation}; }`];\n\n if (!allRows) {\n printStyle.push(`table[data-taco^='table']#${tableId} tr:not([data-row-selected=\"true\"]) { display: none; }`);\n }\n\n if (splitGroups) {\n printStyle.push(`table[data-taco^='table']#${tableId} tr[data-row-group]:not(:first-child) { break-before: page; }`);\n }\n\n const shortcut = { key: 'p', meta: true, shift: false };\n const tooltip = (\n <>\n {texts.table.print.tooltip}\n <Shortcut className=\"ml-2\" keys={shortcut} />\n </>\n );\n\n return (\n <>\n <style media=\"print\">{printStyle.join('\\n')}</style>\n <IconButton\n icon=\"print\"\n aria-label={texts.table.print.tooltip}\n dialog={dialogProps => (\n <PrintDialog\n {...dialogProps}\n table={table}\n onAccept={print}\n orientation={orientation}\n setOrientation={value => tableMeta.printing.setSetting('orientation', value)}\n size={size}\n setSize={value => tableMeta.printing.setSetting('size', value)}\n allRows={allRows}\n setAllRows={value => tableMeta.printing.setSetting('allRows', value)}\n splitGroups={splitGroups}\n setSplitGroups={value => tableMeta.printing.setSetting('splitGroups', value)}\n />\n )}\n ref={ref}\n shortcut={shortcut}\n tooltip={tooltip}\n />\n </>\n );\n}\n"],"names":["Print","props","table","tableId","tableRef","texts","useLocalization","ref","React","useRef","lastScrollTopRef","toast","useToast","tableMeta","options","meta","allRows","orientation","size","splitGroups","printing","settings","togglePrinting","useCallback","enabled","setIsPrinting","current","scrollTop","undefined","useEffect","afterPrint","window","addEventListener","removeEventListener","print","toastRef","close","setTimeout","requestAnimationFrame","isSafari","test","navigator","userAgent","document","execCommand","error","loading","_temp2","server","isEnabled","loadAllIfNeeded","_temp","_catch","Promise","resolve","getState","sorting","columnFilters","then","errorMessage","console","_temp3","e","reject","printStyle","push","shortcut","key","shift","tooltip","Shortcut","className","keys","media","join","IconButton","icon","dialog","dialogProps","PrintDialog","onAccept","setOrientation","value","setSetting","setSize","setAllRows","setSplitGroups"],"mappings":";;;;;;;;SAegBA,KAAKA,CAAkBC,KAAwB;EAC3D,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC;GAAU,GAAGH,KAAK;EAC1C,MAAM;IAAEI;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAoB,IAAI,CAAC;EACjD,MAAMC,gBAAgB,GAAGF,cAAK,CAACC,MAAM,EAAU;EAC/C,MAAME,KAAK,GAAGC,QAAQ,EAAE;EACxB,MAAMC,SAAS,GAAGX,KAAK,CAACY,OAAO,CAACC,IAA6B;EAC7D,MAAM;IAAEC,OAAO;IAAEC,WAAW;IAAEC,IAAI;IAAEC;GAAa,GAAGN,SAAS,CAACO,QAAQ,CAACC,QAAQ;EAE/E,MAAMC,cAAc,GAAGd,cAAK,CAACe,WAAW,CACpCC,OAAO;IACHX,SAAS,CAACO,QAAQ,CAACK,aAAa,CAACD,OAAO,CAAC;IAEzC,IAAIpB,QAAQ,CAACsB,OAAO,EAAE;MAClB,IAAIF,OAAO,EAAE;QACTd,gBAAgB,CAACgB,OAAO,GAAGtB,QAAQ,CAACsB,OAAO,CAACC,SAAS;OACxD,MAAM,IAAIjB,gBAAgB,CAACgB,OAAO,KAAKE,SAAS,EAAE;QAC/CxB,QAAQ,CAACsB,OAAO,CAACC,SAAS,GAAGjB,gBAAgB,CAACgB,OAAO;QACrDhB,gBAAgB,CAACgB,OAAO,GAAGE,SAAS;;;GAG/C,EACD,CAACxB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ACJD,WAAW;MACf5E,KAAK,EAAEA,KAAK;MACZ8E,QAAQ,EAAE9C,KAAK;MACfjB,WAAW,EAAEA,WAAW;MACxBgE,cAAc,EAAEC,KAAK,IAAIrE,SAAS,CAACO,QAAQ,CAAC+D,UAAU,CAAC,aAAa,EAAED,KAAK,CAAC;MAC5EhE,IAAI,EAAEA,IAAI;MACVkE,OAAO,EAAEF,KAAK,IAAIrE,SAAS,CAACO,QAAQ,CAAC+D,UAAU,CAAC,MAAM,EAAED,KAAK,CAAC;MAC9DlE,OAAO,EAAEA,OAAO;MAChBqE,UAAU,EAAEH,KAAK,IAAIrE,SAAS,CAACO,QAAQ,CAAC+D,UAAU,CAAC,SAAS,EAAED,KAAK,CAAC;MACpE/D,WAAW,EAAEA,WAAW;MACxBmE,cAAc,EAAEJ,KAAK,IAAIrE,SAAS,CAACO,QAAQ,CAAC+D,UAAU,CAAC,aAAa,EAAED,KAAK;OAC7E,CACL;IACD3E,GAAG,EAAEA,GAAG;IACR2D,QAAQ,EAAEA,QAAQ;IAClBG,OAAO,EAAEA;IACX,CACH;AAEX;;;;"}
|
@@ -79,13 +79,18 @@ function ensureOrdering(columns, settingsOrder, internalColumnsPinnedToTheRight
|
|
79
79
|
});
|
80
80
|
});
|
81
81
|
if (settingsOrder && settingsOrder.length > 0) {
|
82
|
+
const columnsAbsentInSettingsOrder = [];
|
82
83
|
orderingEnabled = orderingEnabled.reduce((acc, column) => {
|
83
84
|
const index = settingsOrder.indexOf(column);
|
84
85
|
if (index > -1) {
|
85
86
|
acc[index] = column;
|
87
|
+
} else {
|
88
|
+
columnsAbsentInSettingsOrder.push(column);
|
86
89
|
}
|
87
90
|
return acc;
|
88
|
-
}, []).filter(column => !!column)
|
91
|
+
}, []).filter(column => !!column)
|
92
|
+
// Append absent columns at the end
|
93
|
+
.concat(columnsAbsentInSettingsOrder);
|
89
94
|
}
|
90
95
|
const order = [...internalColumns, ...orderingDisabled, ...orderingEnabled];
|
91
96
|
// actions should always be last, enforce that
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"columns.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/util/columns.ts"],"sourcesContent":["import { ColumnDef as ReactTableColumnDef, GroupColumnDef as ReactTableGroupColumnDef } from '@tanstack/react-table';\nimport { isDate } from 'date-fns';\nimport { FontSize, FontSizes } from '../../../../types';\nimport { format, parseFromISOString } from '../../../../utils/date';\nimport { TableColumnDataType } from '../../types';\n\nexport function isInternalColumn(id: string | undefined) {\n return id?.startsWith('__');\n}\n\n// column widths\nexport const getCellMinWidth = (fontSize: FontSize = 'medium') => {\n switch (fontSize) {\n case FontSizes.small:\n return 57;\n\n case FontSizes.large:\n return 83;\n\n default:\n case FontSizes.medium:\n return 72;\n }\n};\n\n// highlighting\nexport function isCellHighlighted(query: string, value: unknown, dataType?: TableColumnDataType) {\n if (value === undefined || value === null) {\n return false;\n }\n\n return String(getCellValueAsString(value, dataType)).toLocaleLowerCase().includes(query.toLocaleLowerCase());\n}\n\nexport function getCellValueAsString(value: unknown, dataType?: TableColumnDataType): string {\n if (value === undefined || value === null) {\n return '';\n } else if (isDate(value)) {\n return format(value as Date) ?? '';\n } else if (dataType === 'datetime' && typeof value === 'string') {\n return format(parseFromISOString(value as string)) ?? '';\n }\n\n return String(value);\n}\n\nfunction orderColumn<TType = unknown>(\n column: ReactTableColumnDef<TType>,\n { orderingDisabled, orderingEnabled }: { orderingDisabled: string[]; orderingEnabled: string[] }\n) {\n const groupedColumn = column as ReactTableGroupColumnDef<TType>;\n\n if (Array.isArray(groupedColumn.columns) && groupedColumn.columns.length > 0) {\n groupedColumn.columns.forEach((subcolumn: ReactTableColumnDef<TType>) =>\n orderColumn(subcolumn, { orderingDisabled, orderingEnabled })\n );\n } else {\n if (column.meta?.enableOrdering) {\n orderingEnabled.push(column.id as string);\n } else {\n orderingDisabled.push(column.id as string);\n }\n }\n}\n\n// ordering\nexport function ensureOrdering<TType = unknown>(\n columns: ReactTableColumnDef<TType>[],\n settingsOrder: string[] | undefined,\n internalColumnsPinnedToTheRight: string[] = ['__actions']\n): string[] {\n // internal columns come with a defined order\n const internalColumns = columns\n .filter(column => isInternalColumn(column.id) && !internalColumnsPinnedToTheRight.includes(String(column.id)))\n .map(column => column.id) as string[];\n\n // columns with ordering disabled should be moved to the front\n const orderingDisabled: string[] = [];\n let orderingEnabled: string[] = [];\n\n let orderedColumns = columns;\n\n // if settings is defined, make sure the columns that are actual children are sorted by it\n if (Array.isArray(settingsOrder)) {\n orderedColumns = columns.slice().sort(\n // the magic >>> 0 here ensures that columns that aren't found in settings, but are children, are pushed to the end\n (a, b) => (settingsOrder.indexOf(a.id as string) >>> 0) - (settingsOrder.indexOf(b.id as string) >>> 0)\n );\n }\n\n orderedColumns.forEach(column => {\n if (isInternalColumn(column.id)) {\n return;\n }\n\n orderColumn(column, { orderingDisabled, orderingEnabled });\n });\n\n if (settingsOrder && settingsOrder.length > 0) {\n orderingEnabled = orderingEnabled\n .reduce((acc, column) => {\n const index = settingsOrder.indexOf(column);\n if (index > -1) {\n acc[index] = column;\n }\n\n return acc;\n }, [] as string[])\n .filter(column => !!column);\n }\n\n const order = [...internalColumns, ...orderingDisabled, ...orderingEnabled];\n\n // actions should always be last, enforce that\n internalColumnsPinnedToTheRight.forEach(id => {\n if (columns.findIndex(column => column.id === id) > -1) {\n order.push(id);\n }\n });\n\n return order;\n}\n\n// freezing - we use the react-table pinning state, but that requires some mapping between them\nexport function unfreezeAllExternalColumns(leftPinnedState?: string[]): string[] {\n return leftPinnedState?.filter(id => isInternalColumn(id) && id !== '__actions') ?? [];\n}\n\nexport function freezeUptoExternalColumn(index: number, columns: string[]): string[] {\n return columns.slice(0, index + 1);\n}\n"],"names":["isInternalColumn","id","startsWith","getCellMinWidth","fontSize","FontSizes","small","large","medium","isCellHighlighted","query","value","dataType","undefined","String","getCellValueAsString","toLocaleLowerCase","includes","isDate","_format","format","_format2","parseFromISOString","orderColumn","column","orderingDisabled","orderingEnabled","groupedColumn","Array","isArray","columns","length","forEach","subcolumn","_column$meta","meta","enableOrdering","push","ensureOrdering","settingsOrder","internalColumnsPinnedToTheRight","internalColumns","filter","map","orderedColumns","slice","sort","a","b","indexOf","reduce","acc","index","order","findIndex","unfreezeAllExternalColumns","leftPinnedState","_leftPinnedState$filt","freezeUptoExternalColumn"],"mappings":";;;;SAMgBA,gBAAgBA,CAACC,EAAsB;EACnD,OAAOA,EAAE,aAAFA,EAAE,uBAAFA,EAAE,CAAEC,UAAU,CAAC,IAAI,CAAC;AAC/B;AAEA;MACaC,eAAe,GAAGA,CAACC,WAAqB,QAAQ;EACzD,QAAQA,QAAQ;IACZ,KAAKC,SAAS,CAACC,KAAK;MAChB,OAAO,EAAE;IAEb,KAAKD,SAAS,CAACE,KAAK;MAChB,OAAO,EAAE;IAEb;IACA,KAAKF,SAAS,CAACG,MAAM;MACjB,OAAO,EAAE;;AAErB;AAEA;SACgBC,iBAAiBA,CAACC,KAAa,EAAEC,KAAc,EAAEC,QAA8B;EAC3F,IAAID,KAAK,KAAKE,SAAS,IAAIF,KAAK,KAAK,IAAI,EAAE;IACvC,OAAO,KAAK;;EAGhB,OAAOG,MAAM,CAACC,oBAAoB,CAACJ,KAAK,EAAEC,QAAQ,CAAC,CAAC,CAACI,iBAAiB,EAAE,CAACC,QAAQ,CAACP,KAAK,CAACM,iBAAiB,EAAE,CAAC;AAChH;SAEgBD,oBAAoBA,CAACJ,KAAc,EAAEC,QAA8B;EAC/E,IAAID,KAAK,KAAKE,SAAS,IAAIF,KAAK,KAAK,IAAI,EAAE;IACvC,OAAO,EAAE;GACZ,MAAM,IAAIO,MAAM,CAACP,KAAK,CAAC,EAAE;IAAA,IAAAQ,OAAA;IACtB,QAAAA,OAAA,GAAOC,MAAM,CAACT,KAAa,CAAC,cAAAQ,OAAA,cAAAA,OAAA,GAAI,EAAE;GACrC,MAAM,IAAIP,QAAQ,KAAK,UAAU,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAE;IAAA,IAAAU,QAAA;IAC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AK,CAACC,OAAO,CAACU,aAAa,CAAC,EAAE;IAC9BK,cAAc,GAAGd,OAAO,CAACe,KAAK,EAAE,CAACC,IAAI;;IAEjC,CAACC,CAAC,EAAEC,CAAC,KAAK,CAACT,aAAa,CAACU,OAAO,CAACF,CAAC,CAAC9C,EAAY,CAAC,KAAK,CAAC,KAAKsC,aAAa,CAACU,OAAO,CAACD,CAAC,CAAC/C,EAAY,CAAC,KAAK,CAAC,CAAC,CAC1G;;EAGL2C,cAAc,CAACZ,OAAO,CAACR,MAAM;IACzB,IAAIxB,gBAAgB,CAACwB,MAAM,CAACvB,EAAE,CAAC,EAAE;MAC7B;;IAGJsB,WAAW,CAACC,MAAM,EAAE;MAAEC,gBAAgB;MAAEC;KAAiB,CAAC;GAC7D,CAAC;EAEF,IAAIa,aAAa,IAAIA,aAAa,CAACR,MAAM,GAAG,CAAC,EAAE;
|
1
|
+
{"version":3,"file":"columns.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/util/columns.ts"],"sourcesContent":["import { ColumnDef as ReactTableColumnDef, GroupColumnDef as ReactTableGroupColumnDef } from '@tanstack/react-table';\nimport { isDate } from 'date-fns';\nimport { FontSize, FontSizes } from '../../../../types';\nimport { format, parseFromISOString } from '../../../../utils/date';\nimport { TableColumnDataType } from '../../types';\n\nexport function isInternalColumn(id: string | undefined) {\n return id?.startsWith('__');\n}\n\n// column widths\nexport const getCellMinWidth = (fontSize: FontSize = 'medium') => {\n switch (fontSize) {\n case FontSizes.small:\n return 57;\n\n case FontSizes.large:\n return 83;\n\n default:\n case FontSizes.medium:\n return 72;\n }\n};\n\n// highlighting\nexport function isCellHighlighted(query: string, value: unknown, dataType?: TableColumnDataType) {\n if (value === undefined || value === null) {\n return false;\n }\n\n return String(getCellValueAsString(value, dataType)).toLocaleLowerCase().includes(query.toLocaleLowerCase());\n}\n\nexport function getCellValueAsString(value: unknown, dataType?: TableColumnDataType): string {\n if (value === undefined || value === null) {\n return '';\n } else if (isDate(value)) {\n return format(value as Date) ?? '';\n } else if (dataType === 'datetime' && typeof value === 'string') {\n return format(parseFromISOString(value as string)) ?? '';\n }\n\n return String(value);\n}\n\nfunction orderColumn<TType = unknown>(\n column: ReactTableColumnDef<TType>,\n { orderingDisabled, orderingEnabled }: { orderingDisabled: string[]; orderingEnabled: string[] }\n) {\n const groupedColumn = column as ReactTableGroupColumnDef<TType>;\n\n if (Array.isArray(groupedColumn.columns) && groupedColumn.columns.length > 0) {\n groupedColumn.columns.forEach((subcolumn: ReactTableColumnDef<TType>) =>\n orderColumn(subcolumn, { orderingDisabled, orderingEnabled })\n );\n } else {\n if (column.meta?.enableOrdering) {\n orderingEnabled.push(column.id as string);\n } else {\n orderingDisabled.push(column.id as string);\n }\n }\n}\n\n// ordering\nexport function ensureOrdering<TType = unknown>(\n columns: ReactTableColumnDef<TType>[],\n settingsOrder: string[] | undefined,\n internalColumnsPinnedToTheRight: string[] = ['__actions']\n): string[] {\n // internal columns come with a defined order\n const internalColumns = columns\n .filter(column => isInternalColumn(column.id) && !internalColumnsPinnedToTheRight.includes(String(column.id)))\n .map(column => column.id) as string[];\n\n // columns with ordering disabled should be moved to the front\n const orderingDisabled: string[] = [];\n let orderingEnabled: string[] = [];\n\n let orderedColumns = columns;\n\n // if settings is defined, make sure the columns that are actual children are sorted by it\n if (Array.isArray(settingsOrder)) {\n orderedColumns = columns.slice().sort(\n // the magic >>> 0 here ensures that columns that aren't found in settings, but are children, are pushed to the end\n (a, b) => (settingsOrder.indexOf(a.id as string) >>> 0) - (settingsOrder.indexOf(b.id as string) >>> 0)\n );\n }\n\n orderedColumns.forEach(column => {\n if (isInternalColumn(column.id)) {\n return;\n }\n\n orderColumn(column, { orderingDisabled, orderingEnabled });\n });\n\n if (settingsOrder && settingsOrder.length > 0) {\n const columnsAbsentInSettingsOrder: string[] = [];\n\n orderingEnabled = orderingEnabled\n .reduce((acc, column) => {\n const index = settingsOrder.indexOf(column);\n if (index > -1) {\n acc[index] = column;\n } else {\n columnsAbsentInSettingsOrder.push(column);\n }\n\n return acc;\n }, [] as string[])\n .filter(column => !!column)\n // Append absent columns at the end\n .concat(columnsAbsentInSettingsOrder);\n }\n\n const order = [...internalColumns, ...orderingDisabled, ...orderingEnabled];\n\n // actions should always be last, enforce that\n internalColumnsPinnedToTheRight.forEach(id => {\n if (columns.findIndex(column => column.id === id) > -1) {\n order.push(id);\n }\n });\n\n return order;\n}\n\n// freezing - we use the react-table pinning state, but that requires some mapping between them\nexport function unfreezeAllExternalColumns(leftPinnedState?: string[]): string[] {\n return leftPinnedState?.filter(id => isInternalColumn(id) && id !== '__actions') ?? [];\n}\n\nexport function freezeUptoExternalColumn(index: number, columns: string[]): string[] {\n return columns.slice(0, index + 1);\n}\n"],"names":["isInternalColumn","id","startsWith","getCellMinWidth","fontSize","FontSizes","small","large","medium","isCellHighlighted","query","value","dataType","undefined","String","getCellValueAsString","toLocaleLowerCase","includes","isDate","_format","format","_format2","parseFromISOString","orderColumn","column","orderingDisabled","orderingEnabled","groupedColumn","Array","isArray","columns","length","forEach","subcolumn","_column$meta","meta","enableOrdering","push","ensureOrdering","settingsOrder","internalColumnsPinnedToTheRight","internalColumns","filter","map","orderedColumns","slice","sort","a","b","indexOf","columnsAbsentInSettingsOrder","reduce","acc","index","concat","order","findIndex","unfreezeAllExternalColumns","leftPinnedState","_leftPinnedState$filt","freezeUptoExternalColumn"],"mappings":";;;;SAMgBA,gBAAgBA,CAACC,EAAsB;EACnD,OAAOA,EAAE,aAAFA,EAAE,uBAAFA,EAAE,CAAEC,UAAU,CAAC,IAAI,CAAC;AAC/B;AAEA;MACaC,eAAe,GAAGA,CAACC,WAAqB,QAAQ;EACzD,QAAQA,QAAQ;IACZ,KAAKC,SAAS,CAACC,KAAK;MAChB,OAAO,EAAE;IAEb,KAAKD,SAAS,CAACE,KAAK;MAChB,OAAO,EAAE;IAEb;IACA,KAAKF,SAAS,CAACG,MAAM;MACjB,OAAO,EAAE;;AAErB;AAEA;SACgBC,iBAAiBA,CAACC,KA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${v}` : v.toString();
|
15
15
|
return mask.replace('dd', pad(value.getDate())).replace('mm', pad(value.getMonth() + 1)).replace('yy', String(value.getFullYear()).slice(2));
|
16
16
|
};
|
17
|
-
const parseFromCustomString = (date = '', mask = 'dd.mm.yy') => {
|
17
|
+
const parseFromCustomString = (date = '', mask = 'dd.mm.yy', defaultYear = undefined) => {
|
18
18
|
if (!date || !date.length) {
|
19
19
|
return undefined;
|
20
20
|
}
|
@@ -48,7 +48,7 @@ const parseFromCustomString = (date = '', mask = 'dd.mm.yy') => {
|
|
48
48
|
month = Number.parseInt(month, 10);
|
49
49
|
year = Number.parseInt(year, 10);
|
50
50
|
const currentDate = new Date();
|
51
|
-
return new Date( /* year */Object.is(year, NaN) ? currentDate.getFullYear() : year, /* month */Object.is(month, NaN) ? currentDate.getMonth() : month - 1,
|
51
|
+
return new Date( /* year */Object.is(year, NaN) ? defaultYear !== null && defaultYear !== void 0 ? defaultYear : currentDate.getFullYear() : year, /* month */Object.is(month, NaN) ? currentDate.getMonth() : month - 1,
|
52
52
|
// months are zero based in javascript, so subtract a day
|
53
53
|
/* day */
|
54
54
|
Object.is(day, NaN) ? currentDate.getDate() : day, /* hours */12, /* minutes */0 // set to midday to avoid UTC offset causing dates to be mismatched server side
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"date.js","sources":["../../../../../../src/utils/date.ts"],"sourcesContent":["import { isDate, toDate, isValid } from 'date-fns';\n\nexport const isWeakEqual = (leftDate: Date, rightDate: Date) => {\n return (\n leftDate.getFullYear() === rightDate.getFullYear() &&\n leftDate.getMonth() === rightDate.getMonth() &&\n leftDate.getDay() === rightDate.getDay()\n );\n};\n\nexport const format = (date: Date | undefined, mask = 'dd.mm.yy'): string | undefined => {\n if (!date) {\n return undefined;\n }\n\n const value = isDate(date) ? date : toDate(date);\n\n if (!isValid(value)) {\n return undefined;\n }\n\n const pad = (v: number): string => (String(v).length === 1 ? `0${v}` : v.toString());\n\n return mask\n .replace('dd', pad(value.getDate()))\n .replace('mm', pad(value.getMonth() + 1))\n .replace('yy', String(value.getFullYear()).slice(2));\n};\n\nexport const parseFromCustomString = (date = ''
|
1
|
+
{"version":3,"file":"date.js","sources":["../../../../../../src/utils/date.ts"],"sourcesContent":["import { isDate, toDate, isValid } from 'date-fns';\n\nexport const isWeakEqual = (leftDate: Date, rightDate: Date) => {\n return (\n leftDate.getFullYear() === rightDate.getFullYear() &&\n leftDate.getMonth() === rightDate.getMonth() &&\n leftDate.getDay() === rightDate.getDay()\n );\n};\n\nexport const format = (date: Date | undefined, mask = 'dd.mm.yy'): string | undefined => {\n if (!date) {\n return undefined;\n }\n\n const value = isDate(date) ? date : toDate(date);\n\n if (!isValid(value)) {\n return undefined;\n }\n\n const pad = (v: number): string => (String(v).length === 1 ? `0${v}` : v.toString());\n\n return mask\n .replace('dd', pad(value.getDate()))\n .replace('mm', pad(value.getMonth() + 1))\n .replace('yy', String(value.getFullYear()).slice(2));\n};\n\nexport const parseFromCustomString = (\n date = '',\n mask = 'dd.mm.yy',\n defaultYear: number | undefined = undefined\n): Date | undefined => {\n if (!date || !date.length) {\n return undefined;\n }\n\n const sanitizedMask = mask.split(/[^dmy]/);\n const dd = sanitizedMask.findIndex(x => x === 'dd');\n const mm = sanitizedMask.findIndex(x => x === 'mm');\n const yy = sanitizedMask.findIndex(x => x === 'yy' || x === 'yyyy');\n\n let day;\n let month;\n let year;\n\n const getFullYear = (y: string): string => {\n if (y && y.length === 2) {\n const z = Number.parseInt(y, 10);\n\n return z > 50 ? `19${y}` : `20${y}`;\n }\n\n return y;\n };\n\n const inputParts = date.split(/\\D/);\n\n if (inputParts.length === 1) {\n const fullDate = inputParts[0];\n const unseparatedMask = mask.replace(/[^dmy]/g, '');\n\n day = fullDate.slice(unseparatedMask.indexOf('d'), unseparatedMask.lastIndexOf('d') + 1);\n month = fullDate.slice(unseparatedMask.indexOf('m'), unseparatedMask.lastIndexOf('m') + 1);\n year = getFullYear(fullDate.slice(unseparatedMask.indexOf('y'), unseparatedMask.lastIndexOf('y') + 3)); // account for full years\n } else {\n day = inputParts[dd];\n month = inputParts[mm];\n year = getFullYear(inputParts[yy]);\n }\n\n day = Number.parseInt(day, 10);\n month = Number.parseInt(month, 10);\n year = Number.parseInt(year, 10);\n\n const currentDate = new Date();\n\n return new Date(\n /* year */ Object.is(year, NaN) ? defaultYear ?? currentDate.getFullYear() : year,\n /* month */ Object.is(month, NaN) ? currentDate.getMonth() : month - 1, // months are zero based in javascript, so subtract a day\n /* day */ Object.is(day, NaN) ? currentDate.getDate() : day,\n /* hours */ 12,\n /* minutes */ 0 // set to midday to avoid UTC offset causing dates to be mismatched server side\n );\n};\n\nexport const parseFromISOString = (date: string): Date | undefined => {\n const tempDate = new Date(date);\n return isValid(tempDate) ? parseFromCustomString(format(new Date(date))) : undefined;\n};\n"],"names":["isWeakEqual","leftDate","rightDate","getFullYear","getMonth","getDay","format","date","mask","undefined","value","isDate","toDate","isValid","pad","v","String","length","toString","replace","getDate","slice","parseFromCustomString","defaultYear","sanitizedMask","split","dd","findIndex","x","mm","yy","day","month","year","y","z","Number","parseInt","inputParts","fullDate","unseparatedMask","indexOf","lastIndexOf","currentDate","Date","Object","is","NaN","parseFromISOString","tempDate"],"mappings":";;MAEaA,WAAW,GAAGA,CAACC,QAAc,EAAEC,SAAe;EACvD,OACID,QAAQ,CAACE,WAAW,EAAE,KAAKD,SAAS,CAACC,WAAW,EAAE,IAClDF,QAAQ,CAACG,QAAQ,EAAE,KAAKF,SAAS,CAACE,QAAQ,EAAE,IAC5CH,QAAQ,CAACI,MAAM,EAAE,KAAKH,SAAS,CAACG,MAAM,EAAE;AAEhD;MAEaC,MAAM,GAAGA,CAACC,IAAsB,EAAEC,IAAI,GAAG,UAAU;EAC5D,IAAI,CAACD,IAAI,EAAE;IACP,OAAOE,SAAS;;EAGpB,MAAMC,KAAK,GAAGC,MAAM,CAACJ,IAAI,CAAC,GAAGA,IAAI,GAAGK,MAAM,CAACL,IAAI,CAAC;EAEhD,IAAI,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