@servicetitan/form 32.2.0 → 32.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/date-range-picker/date-range-picker.tsx"],"sourcesContent":["import { ComponentType, Component, SyntheticEvent } from 'react';\nimport {\n DateRangePicker as DateRangePickerKendo,\n DateRangePickerChangeEvent,\n CalendarHeaderTitleProps,\n MultiViewCalendarProps,\n CalendarCellProps,\n ActiveView,\n} from '@progress/kendo-react-dateinputs';\nimport { Icon, InputDateMask, Stack } from '@servicetitan/design-system';\nimport { DateRange } from '@servicetitan/form-state';\nimport { observable, action, makeObservable } from 'mobx';\nimport { observer } from 'mobx-react';\nimport classnames from 'classnames';\nimport moment from 'moment';\nimport * as Styles from './date-range-picker.module.css';\nimport { FieldState } from 'formstate';\n\nexport interface DateRangePickerProps {\n field: FieldState<DateRange | undefined>;\n ['qa-testing']: string;\n placeHolder?: string;\n minDate?: Date;\n maxDate?: Date;\n calendarMinDate?: Date;\n calendarMaxDate?: Date;\n topView?: ActiveView;\n bottomView?: ActiveView;\n className?: string;\n calendarComponent?: ComponentType<MultiViewCalendarProps>;\n headerTitleComponent?: ComponentType<CalendarHeaderTitleProps>;\n cellComponent?: ComponentType<CalendarCellProps>;\n inputFormat?: string;\n horizontalAlign?: 'left' | 'center' | 'right';\n disabled?: boolean;\n small?: boolean;\n disableRangeValidation?: boolean;\n maskChar?: string;\n}\n\n@observer\nexport class DateRangePicker extends Component<DateRangePickerProps> {\n // `HTMLDivElement` leads to issues with Node/SSR\n @observable wrapElem?: any /* HTMLDivElement */;\n isFocused = false;\n @observable showDatePicker = false;\n isIconClicked = false;\n isDateRangePickerClicked = false;\n\n constructor(props: DateRangePickerProps) {\n super(props);\n makeObservable(this);\n }\n\n @action\n handleRef = (wrapElem: HTMLDivElement) => {\n this.wrapElem = wrapElem;\n };\n\n @action\n toggleShow(show?: boolean) {\n this.showDatePicker = show !== undefined ? show : !this.showDatePicker;\n }\n\n handleClickGlobal = (evt: Event) => {\n if (!(evt.target instanceof Node)) {\n return;\n }\n\n const isPrevFocused = this.isFocused;\n\n this.isFocused = this.isDateRangePickerClicked;\n\n if (!this.isFocused && isPrevFocused) {\n // click outside\n this.props.field.enableAutoValidationAndValidate();\n\n this.toggleShow(false);\n } else if (this.isFocused && !isPrevFocused && !this.isIconClicked) {\n // click inside but outside icons\n this.props.field.disableAutoValidation();\n }\n\n this.isIconClicked = false;\n this.isDateRangePickerClicked = false;\n };\n\n handleClickDateRangePicker = () => {\n this.isDateRangePickerClicked = true;\n };\n\n handleClickIcon = () => {\n this.isIconClicked = true;\n\n if (this.showDatePicker) {\n this.props.field.enableAutoValidationAndValidate();\n } else {\n this.props.field.disableAutoValidation();\n }\n\n this.toggleShow();\n };\n\n componentDidMount() {\n window.addEventListener('click', this.handleClickGlobal);\n }\n\n componentWillUnmount() {\n window.removeEventListener('click', this.handleClickGlobal);\n }\n\n handleChange = (event: DateRangePickerChangeEvent) => {\n const value = event.target.value;\n\n if (value.start && value.end && value.start > value.end) {\n [value.start, value.end] = [value.end, value.start];\n }\n\n this.props.field.onChange({ from: value.start ?? undefined, to: value.end ?? undefined });\n };\n\n handleFromChange = (from?: Date) => {\n const to = this.props.field.value ? this.props.field.value.to : undefined;\n\n if (from || to) {\n this.props.field.onChange({ from, to });\n } else {\n this.props.field.onChange(undefined);\n }\n };\n\n handleToChange = (to?: Date) => {\n const from = this.props.field.value ? this.props.field.value.from : undefined;\n\n if (from || to) {\n this.props.field.onChange({ from, to });\n } else {\n this.props.field.onChange(undefined);\n }\n };\n\n render() {\n const { hasError } = this.props.field;\n const {\n 'qa-testing': qaTestingLocator,\n placeHolder,\n inputFormat,\n className,\n calendarComponent,\n headerTitleComponent,\n cellComponent,\n minDate,\n maxDate,\n calendarMinDate,\n calendarMaxDate,\n topView,\n bottomView,\n horizontalAlign,\n disabled = false,\n small,\n maskChar,\n } = this.props;\n\n const value = this.props.field.value ? this.props.field.value : {};\n\n const horizontalAlignClass = classnames({\n [Styles.popupCenter]: horizontalAlign === 'center',\n [Styles.popupRight]: horizontalAlign === 'right',\n });\n\n return (\n <div\n className={classnames(Styles.dateRangePicker, className)}\n ref={this.handleRef}\n onClick={this.handleClickDateRangePicker}\n >\n <DateRangePickerKendo\n className={Styles.dateRangePickerKendo}\n calendarSettings={{\n min: minDate ?? calendarMinDate,\n max: maxDate ?? calendarMaxDate,\n topView,\n bottomView,\n disabled,\n mode: 'range',\n headerTitle: headerTitleComponent,\n cell: cellComponent,\n }}\n popupSettings={{\n appendTo: this.wrapElem,\n className: horizontalAlignClass,\n }}\n startDateInputSettings={{\n tabIndex: -1,\n }}\n endDateInputSettings={{\n tabIndex: -1,\n }}\n show={this.showDatePicker}\n value={{ start: value.from ?? null, end: value.to ?? null }}\n onChange={this.handleChange}\n min={minDate}\n max={maxDate}\n calendar={calendarComponent}\n />\n <Stack alignItems=\"center\" className=\"flex-grow-1\">\n <Stack.Item fill>\n <InputDateMask\n shortLabel={\n <Icon\n name=\"today\"\n className={classnames(\n Styles.icon,\n `${qaTestingLocator}-icon-from`\n )}\n onClick={this.handleClickIcon}\n />\n }\n placeholder={placeHolder}\n value={value.from}\n onChange={this.handleFromChange}\n onBlur={this.handleFromChange}\n error={hasError}\n disabled={disabled}\n qa-testing={`${qaTestingLocator}-from`}\n dateFormat={inputFormat}\n minDate={minDate}\n maxDate={this.maxFromDate}\n small={small}\n maskChar={maskChar}\n />\n </Stack.Item>\n <Icon name=\"arrow_forward\" className={Styles.endLabel} />\n <Stack.Item fill>\n <InputDateMask\n shortLabel={\n <Icon\n name=\"today\"\n className={classnames(\n Styles.icon,\n `${qaTestingLocator}-icon-to`\n )}\n onClick={this.handleClickIcon}\n />\n }\n placeholder={placeHolder}\n value={value.to}\n onChange={this.handleToChange}\n onBlur={this.handleToChange}\n error={hasError}\n disabled={disabled}\n qa-testing={`${qaTestingLocator}-to`}\n dateFormat={inputFormat}\n minDate={this.minToDate}\n maxDate={maxDate}\n small={small}\n maskChar={maskChar}\n />\n </Stack.Item>\n </Stack>\n <input\n hidden\n // eslint-disable-next-line react/no-unknown-property\n qa-testing={qaTestingLocator}\n onChange={this.handleHiddenInputChange}\n />\n </div>\n );\n }\n\n formatDate(date?: Date, inputFormat = 'L') {\n return date ? moment(date).format(inputFormat) : '';\n }\n\n handleHiddenInputChange = (ev: SyntheticEvent<HTMLInputElement>) => {\n const values = ev.currentTarget.value.split('-').map(v => new Date(v));\n this.props.field.onChange({ from: values[0] || undefined, to: values[1] || undefined });\n };\n\n get maxFromDate() {\n const { disableRangeValidation, maxDate, field } = this.props;\n if (disableRangeValidation) {\n return maxDate;\n }\n\n const to = field.value ? field.value.to : undefined;\n\n if (maxDate && to) {\n return maxDate > to ? to : maxDate;\n }\n\n return maxDate ?? to;\n }\n\n get minToDate() {\n const { disableRangeValidation, minDate, field } = this.props;\n if (disableRangeValidation) {\n return minDate;\n }\n\n const from = field.value ? field.value.from : undefined;\n if (minDate && from) {\n return minDate < from ? from : minDate;\n }\n\n return minDate ?? from;\n }\n}\n"],"names":["Component","DateRangePicker","DateRangePickerKendo","Icon","InputDateMask","Stack","observable","action","makeObservable","observer","classnames","moment","Styles","toggleShow","show","showDatePicker","undefined","componentDidMount","window","addEventListener","handleClickGlobal","componentWillUnmount","removeEventListener","render","hasError","props","field","qaTestingLocator","placeHolder","inputFormat","className","calendarComponent","headerTitleComponent","cellComponent","minDate","maxDate","calendarMinDate","calendarMaxDate","topView","bottomView","horizontalAlign","disabled","small","maskChar","value","horizontalAlignClass","popupCenter","popupRight","div","dateRangePicker","ref","handleRef","onClick","handleClickDateRangePicker","dateRangePickerKendo","calendarSettings","min","max","mode","headerTitle","cell","popupSettings","appendTo","wrapElem","startDateInputSettings","tabIndex","endDateInputSettings","start","from","end","to","onChange","handleChange","calendar","alignItems","Item","fill","shortLabel","name","icon","handleClickIcon","placeholder","handleFromChange","onBlur","error","qa-testing","dateFormat","maxFromDate","endLabel","handleToChange","minToDate","input","hidden","handleHiddenInputChange","formatDate","date","format","disableRangeValidation","constructor","isFocused","isIconClicked","isDateRangePickerClicked","evt","target","Node","isPrevFocused","enableAutoValidationAndValidate","disableAutoValidation","event","ev","values","currentTarget","split","map","v","Date"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAwBA,SAAS,QAAwB,QAAQ;AACjE,SACIC,mBAAmBC,oBAAoB,QAMpC,mCAAmC;AAC1C,SAASC,IAAI,EAAEC,aAAa,EAAEC,KAAK,QAAQ,8BAA8B;AAEzE,SAASC,UAAU,EAAEC,MAAM,EAAEC,cAAc,QAAQ,OAAO;AAC1D,SAASC,QAAQ,QAAQ,aAAa;AACtC,OAAOC,gBAAgB,aAAa;AACpC,OAAOC,YAAY,SAAS;AAC5B,YAAYC,YAAY,iCAAiC;AA0BzD,OAAO,MAAMX,wBAAwBD;IAmBjCa,WAAWC,IAAc,EAAE;QACvB,IAAI,CAACC,cAAc,GAAGD,SAASE,YAAYF,OAAO,CAAC,IAAI,CAACC,cAAc;IAC1E;IAyCAE,oBAAoB;QAChBC,OAAOC,gBAAgB,CAAC,SAAS,IAAI,CAACC,iBAAiB;IAC3D;IAEAC,uBAAuB;QACnBH,OAAOI,mBAAmB,CAAC,SAAS,IAAI,CAACF,iBAAiB;IAC9D;IAgCAG,SAAS;QACL,MAAM,EAAEC,QAAQ,EAAE,GAAG,IAAI,CAACC,KAAK,CAACC,KAAK;QACrC,MAAM,EACF,cAAcC,gBAAgB,EAC9BC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,iBAAiB,EACjBC,oBAAoB,EACpBC,aAAa,EACbC,OAAO,EACPC,OAAO,EACPC,eAAe,EACfC,eAAe,EACfC,OAAO,EACPC,UAAU,EACVC,eAAe,EACfC,WAAW,KAAK,EAChBC,KAAK,EACLC,QAAQ,EACX,GAAG,IAAI,CAAClB,KAAK;QAEd,MAAMmB,QAAQ,IAAI,CAACnB,KAAK,CAACC,KAAK,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EhE,IAAIoD,QAAQE,IAAI;gBACZ,IAAI,CAAC7C,KAAK,CAACC,KAAK,CAAC6C,QAAQ,CAAC;oBAAEH;oBAAME;gBAAG;YACzC,OAAO;gBACH,IAAI,CAAC7C,KAAK,CAACC,KAAK,CAAC6C,QAAQ,CAACvD;YAC9B;QACJ,IAEAyE,uBAAAA,kBAAiB,CAACnB;YACd,MAAMF,OAAO,IAAI,CAAC3C,KAAK,CAACC,KAAK,CAACkB,KAAK,GAAG,IAAI,CAACnB,KAAK,CAACC,KAAK,CAACkB,KAAK,CAACwB,IAAI,GAAGpD;YAEpE,IAAIoD,QAAQE,IAAI;gBACZ,IAAI,CAAC7C,KAAK,CAACC,KAAK,CAAC6C,QAAQ,CAAC;oBAAEH;oBAAME;gBAAG;YACzC,OAAO;gBACH,IAAI,CAAC7C,KAAK,CAACC,KAAK,CAAC6C,QAAQ,CAACvD;YAC9B;QACJ,IAuIA6E,uBAAAA,2BAA0B,CAACgB;YACvB,MAAMC,SAASD,GAAGE,aAAa,CAACnE,KAAK,CAACoE,KAAK,CAAC,KAAKC,GAAG,CAACC,CAAAA,IAAK,IAAIC,KAAKD;YACnE,IAAI,CAACzF,KAAK,CAACC,KAAK,CAAC6C,QAAQ,CAAC;gBAAEH,MAAM0C,MAAM,CAAC,EAAE,IAAI9F;gBAAWsD,IAAIwC,MAAM,CAAC,EAAE,IAAI9F;YAAU;QACzF;QAlOIR,eAAe,IAAI;IACvB;AA+PJ"}
|
1
|
+
{"version":3,"sources":["../../src/date-range-picker/date-range-picker.tsx"],"sourcesContent":["import { ComponentType, Component, SyntheticEvent } from 'react';\nimport {\n DateRangePicker as DateRangePickerKendo,\n DateRangePickerChangeEvent,\n CalendarHeaderTitleProps,\n MultiViewCalendarProps,\n CalendarCellProps,\n ActiveView,\n} from '@progress/kendo-react-dateinputs';\nimport { Icon, InputDateMask, Stack } from '@servicetitan/design-system';\nimport { DateRange } from '@servicetitan/form-state';\nimport { observable, action, makeObservable } from 'mobx';\nimport { observer } from 'mobx-react';\nimport classnames from 'classnames';\nimport moment from 'moment';\nimport * as Styles from './date-range-picker.module.css';\nimport { FieldState } from 'formstate';\n\nexport interface DateRangePickerProps {\n field: FieldState<DateRange | undefined>;\n ['qa-testing']: string;\n placeHolder?: string;\n minDate?: Date;\n maxDate?: Date;\n calendarMinDate?: Date;\n calendarMaxDate?: Date;\n topView?: ActiveView;\n bottomView?: ActiveView;\n className?: string;\n calendarComponent?: ComponentType<MultiViewCalendarProps>;\n headerTitleComponent?: ComponentType<CalendarHeaderTitleProps>;\n cellComponent?: ComponentType<CalendarCellProps>;\n inputFormat?: string;\n horizontalAlign?: 'left' | 'center' | 'right';\n disabled?: boolean;\n small?: boolean;\n disableRangeValidation?: boolean;\n maskChar?: string;\n}\n\n@observer\nexport class DateRangePicker extends Component<DateRangePickerProps> {\n // `HTMLDivElement` leads to issues with Node/SSR\n @observable wrapElem?: any /* HTMLDivElement */;\n isFocused = false;\n @observable showDatePicker = false;\n isIconClicked = false;\n isDateRangePickerClicked = false;\n\n constructor(props: DateRangePickerProps) {\n super(props);\n makeObservable(this);\n }\n\n @action\n handleRef = (wrapElem: HTMLDivElement) => {\n this.wrapElem = wrapElem;\n };\n\n @action\n toggleShow(show?: boolean) {\n this.showDatePicker = show !== undefined ? show : !this.showDatePicker;\n }\n\n handleClickGlobal = (evt: Event) => {\n if (!(evt.target instanceof Node)) {\n return;\n }\n\n const isPrevFocused = this.isFocused;\n\n this.isFocused = this.isDateRangePickerClicked;\n\n if (!this.isFocused && isPrevFocused) {\n // click outside\n this.props.field.enableAutoValidationAndValidate();\n\n this.toggleShow(false);\n } else if (this.isFocused && !isPrevFocused && !this.isIconClicked) {\n // click inside but outside icons\n this.props.field.disableAutoValidation();\n }\n\n this.isIconClicked = false;\n this.isDateRangePickerClicked = false;\n };\n\n handleClickDateRangePicker = () => {\n this.isDateRangePickerClicked = true;\n };\n\n handleClickIcon = () => {\n this.isIconClicked = true;\n\n if (this.showDatePicker) {\n this.props.field.enableAutoValidationAndValidate();\n } else {\n this.props.field.disableAutoValidation();\n }\n\n this.toggleShow();\n };\n\n componentDidMount() {\n window.addEventListener('click', this.handleClickGlobal);\n }\n\n componentWillUnmount() {\n window.removeEventListener('click', this.handleClickGlobal);\n }\n\n handleChange = (event: DateRangePickerChangeEvent) => {\n const value = event.target.value;\n\n if (value.start && value.end && value.start > value.end) {\n [value.start, value.end] = [value.end, value.start];\n }\n\n this.props.field.onChange({ from: value.start ?? undefined, to: value.end ?? undefined });\n };\n\n handleFromChange = (from?: Date) => {\n const to = this.props.field.value ? this.props.field.value.to : undefined;\n\n if (from || to) {\n this.props.field.onChange({ from, to });\n } else {\n this.props.field.onChange(undefined);\n }\n };\n\n handleToChange = (to?: Date) => {\n const from = this.props.field.value ? this.props.field.value.from : undefined;\n\n if (from || to) {\n this.props.field.onChange({ from, to });\n } else {\n this.props.field.onChange(undefined);\n }\n };\n\n render() {\n const { hasError } = this.props.field;\n const {\n 'qa-testing': qaTestingLocator,\n placeHolder,\n inputFormat,\n className,\n calendarComponent,\n headerTitleComponent,\n cellComponent,\n minDate,\n maxDate,\n calendarMinDate,\n calendarMaxDate,\n topView,\n bottomView,\n horizontalAlign,\n disabled = false,\n small,\n maskChar,\n } = this.props;\n\n const value = this.props.field.value ? this.props.field.value : {};\n\n const horizontalAlignClass = classnames({\n [Styles.popupCenter]: horizontalAlign === 'center',\n [Styles.popupRight]: horizontalAlign === 'right',\n });\n\n return (\n <div\n className={classnames(Styles.dateRangePicker, className)}\n ref={this.handleRef}\n onClick={this.handleClickDateRangePicker}\n >\n <DateRangePickerKendo\n className={Styles.dateRangePickerKendo}\n calendarSettings={{\n min: minDate ?? calendarMinDate,\n max: maxDate ?? calendarMaxDate,\n topView,\n bottomView,\n disabled,\n mode: 'range',\n headerTitle: headerTitleComponent,\n cell: cellComponent,\n }}\n popupSettings={{\n appendTo: this.wrapElem,\n className: horizontalAlignClass,\n }}\n startDateInputSettings={{\n tabIndex: -1,\n }}\n endDateInputSettings={{\n tabIndex: -1,\n }}\n show={this.showDatePicker}\n value={{ start: value.from ?? null, end: value.to ?? null }}\n onChange={this.handleChange}\n min={minDate}\n max={maxDate}\n calendar={calendarComponent}\n />\n <Stack alignItems=\"center\" className=\"flex-grow-1\">\n <Stack.Item fill>\n <InputDateMask\n shortLabel={\n <Icon\n name=\"today\"\n className={classnames(\n Styles.icon,\n `${qaTestingLocator}-icon-from`\n )}\n onClick={this.handleClickIcon}\n />\n }\n placeholder={placeHolder}\n value={value.from}\n onChange={this.handleFromChange}\n onBlur={this.handleFromChange}\n error={hasError}\n disabled={disabled}\n qa-testing={`${qaTestingLocator}-from`}\n dateFormat={inputFormat}\n minDate={minDate}\n maxDate={this.maxFromDate}\n small={small}\n maskChar={maskChar}\n />\n </Stack.Item>\n <Icon name=\"arrow_forward\" className={Styles.endLabel} />\n <Stack.Item fill>\n <InputDateMask\n shortLabel={\n <Icon\n name=\"today\"\n className={classnames(\n Styles.icon,\n `${qaTestingLocator}-icon-to`\n )}\n onClick={this.handleClickIcon}\n />\n }\n placeholder={placeHolder}\n value={value.to}\n onChange={this.handleToChange}\n onBlur={this.handleToChange}\n error={hasError}\n disabled={disabled}\n qa-testing={`${qaTestingLocator}-to`}\n dateFormat={inputFormat}\n minDate={this.minToDate}\n maxDate={maxDate}\n small={small}\n maskChar={maskChar}\n />\n </Stack.Item>\n </Stack>\n <input\n hidden\n // eslint-disable-next-line react/no-unknown-property\n qa-testing={qaTestingLocator}\n onChange={this.handleHiddenInputChange}\n />\n </div>\n );\n }\n\n formatDate(date?: Date, inputFormat = 'L') {\n return date ? moment(date).format(inputFormat) : '';\n }\n\n handleHiddenInputChange = (ev: SyntheticEvent<HTMLInputElement>) => {\n const values = ev.currentTarget.value.split('-').map(v => new Date(v));\n this.props.field.onChange({ from: values[0] || undefined, to: values[1] || undefined });\n };\n\n get maxFromDate() {\n const { disableRangeValidation, maxDate, field } = this.props;\n if (disableRangeValidation) {\n return maxDate;\n }\n\n const to = field.value ? field.value.to : undefined;\n\n if (maxDate && to) {\n return maxDate > to ? to : maxDate;\n }\n\n return maxDate ?? to;\n }\n\n get minToDate() {\n const { disableRangeValidation, minDate, field } = this.props;\n if (disableRangeValidation) {\n return minDate;\n }\n\n const from = field.value ? field.value.from : undefined;\n if (minDate && from) {\n return minDate < from ? from : minDate;\n }\n\n return minDate ?? from;\n }\n}\n"],"names":["Component","DateRangePicker","DateRangePickerKendo","Icon","InputDateMask","Stack","observable","action","makeObservable","observer","classnames","moment","Styles","toggleShow","show","showDatePicker","undefined","componentDidMount","window","addEventListener","handleClickGlobal","componentWillUnmount","removeEventListener","render","hasError","props","field","qaTestingLocator","placeHolder","inputFormat","className","calendarComponent","headerTitleComponent","cellComponent","minDate","maxDate","calendarMinDate","calendarMaxDate","topView","bottomView","horizontalAlign","disabled","small","maskChar","value","horizontalAlignClass","popupCenter","popupRight","div","dateRangePicker","ref","handleRef","onClick","handleClickDateRangePicker","dateRangePickerKendo","calendarSettings","min","max","mode","headerTitle","cell","popupSettings","appendTo","wrapElem","startDateInputSettings","tabIndex","endDateInputSettings","start","from","end","to","onChange","handleChange","calendar","alignItems","Item","fill","shortLabel","name","icon","handleClickIcon","placeholder","handleFromChange","onBlur","error","qa-testing","dateFormat","maxFromDate","endLabel","handleToChange","minToDate","input","hidden","handleHiddenInputChange","formatDate","date","format","disableRangeValidation","isFocused","isIconClicked","isDateRangePickerClicked","evt","target","Node","isPrevFocused","enableAutoValidationAndValidate","disableAutoValidation","event","ev","values","currentTarget","split","map","v","Date"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAwBA,SAAS,QAAwB,QAAQ;AACjE,SACIC,mBAAmBC,oBAAoB,QAMpC,mCAAmC;AAC1C,SAASC,IAAI,EAAEC,aAAa,EAAEC,KAAK,QAAQ,8BAA8B;AAEzE,SAASC,UAAU,EAAEC,MAAM,EAAEC,cAAc,QAAQ,OAAO;AAC1D,SAASC,QAAQ,QAAQ,aAAa;AACtC,OAAOC,g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C;oBAAEH;oBAAME;gBAAG;YACzC,OAAO;gBACH,IAAI,CAAC7C,KAAK,CAACC,KAAK,CAAC6C,QAAQ,CAACvD;YAC9B;QACJ,IAuIA6E,uBAAAA,2BAA0B,CAACe;YACvB,MAAMC,SAASD,GAAGE,aAAa,CAAClE,KAAK,CAACmE,KAAK,CAAC,KAAKC,GAAG,CAACC,CAAAA,IAAK,IAAIC,KAAKD;YACnE,IAAI,CAACxF,KAAK,CAACC,KAAK,CAAC6C,QAAQ,CAAC;gBAAEH,MAAMyC,MAAM,CAAC,EAAE,IAAI7F;gBAAWsD,IAAIuC,MAAM,CAAC,EAAE,IAAI7F;YAAU;QACzF;QAlOIR,eAAe,IAAI;IACvB;AA+PJ"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/file-uploader/file-uploader.tsx"],"sourcesContent":["import { Component, Fragment, FC } from 'react';\n\nimport { injectDependency, optional } from '@servicetitan/react-ioc';\n\nimport { observer } from 'mobx-react';\nimport { observable, action, makeObservable } from 'mobx';\n\nimport { FilePicker, FileDescriptor, Banner, FilePickerProps } from '@servicetitan/design-system';\nimport { Confirm } from '@servicetitan/confirm';\n\nimport { FileUploaderConfig, FILE_UPLOADER_CONFIGURATION_TOKEN } from './config';\nimport { Uploader } from './uploader';\n\nimport { v4 as uuid } from 'uuid';\n\nfunction immutableSplice<T>(arr: T[], start: number, deleteCount: number, ...items: T[]) {\n return [...arr.slice(0, start), ...items, ...arr.slice(start + deleteCount)];\n}\n\ninterface UploadError {\n id: string;\n file: File;\n message?: string;\n}\n\ninterface UploadErrorsProps {\n errors: UploadError[];\n multiple?: boolean;\n className?: string;\n onClose(): void;\n}\n\nconst UploadErrors: FC<UploadErrorsProps> = ({ errors, className, onClose, multiple }) => {\n const title = multiple\n ? 'One or more files could not be uploaded:'\n : 'Your file could not be uploaded';\n\n return (\n <Banner icon status=\"critical\" title={title} className={className} onClose={onClose}>\n <ul className=\"p-x-0-i\">\n {errors.map(({ id, file, message }) => (\n <li key={id} style={!multiple ? { listStyle: 'none' } : {}}>\n {multiple && file.name}\n {message && (multiple ? ` (${message})` : message)}\n </li>\n ))}\n </ul>\n </Banner>\n );\n};\n\ntype ExcludedFilePickerProps = 'onDelete' | 'onDownload' | 'onReplace' | 'onSelected' | 'value';\n\ninterface FileUploaderProps extends Omit<FilePickerProps, ExcludedFilePickerProps> {\n config?: FileUploaderConfig;\n value: FileDescriptor[];\n folderName?: string;\n hideReplace?: boolean;\n hideDownload?: boolean;\n onChange?(value: FileDescriptor[]): void;\n}\n\n@observer\nexport class FileUploader extends Component<FileUploaderProps> {\n static defaultProps = {\n folderName: 'temp',\n };\n\n @injectDependency(FILE_UPLOADER_CONFIGURATION_TOKEN)\n @optional()\n declare config?: FileUploaderConfig;\n\n @observable errors: UploadError[] = [];\n\n uploader!: Uploader;\n\n constructor(props: FileUploaderProps) {\n super(props);\n makeObservable(this);\n }\n\n @action\n addError(file: File, message?: string) {\n this.errors.push({\n file,\n message,\n id: uuid(),\n });\n }\n\n @action\n clearErrors() {\n this.errors = [];\n }\n\n @action\n handleUploadProgress = (file: File, progress: number) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n ...this.props.value[index],\n uploadProgress: progress,\n })\n );\n } else {\n this.uploader.cancel(file);\n }\n };\n\n @action\n handleUploadSuccess = (file: File, message?: string) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n ...this.props.value[index],\n ...(message\n ? { file: message, displayName: file.name, downloadLink: message }\n : { file: file.name }),\n uploadProgress: undefined,\n })\n );\n }\n };\n\n @action\n handleUploadError = (file: File, message?: string) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.addError(file, message);\n\n this.props.onChange(\n this.props.value.filter(fileDescriptor => fileDescriptor.file !== file)\n );\n };\n\n componentDidMount() {\n this.uploader = new Uploader(\n {\n ...this.config,\n ...this.props.config,\n },\n {\n progress: this.handleUploadProgress,\n success: this.handleUploadSuccess,\n error: this.handleUploadError,\n },\n this.props.folderName\n );\n }\n\n componentWillUnmount() {\n this.uploader.cancel();\n }\n\n handleDownload = (file: FileDescriptor) => {\n if (!file.downloadLink) {\n return;\n }\n\n const path =\n this.props.config?.downloadPath ??\n this.config?.downloadPath ??\n `/app/api/fileuploader/folders/${this.props.folderName}/files/`;\n\n window.open(path + file.downloadLink);\n };\n\n handleSelected = (files: FileList) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.props.onChange([\n ...this.props.value,\n ...Array.from(files).map(file => ({\n file,\n uploadProgress: 0,\n })),\n ]);\n this.uploader.upload(files);\n };\n\n handleReplace = ({ file: { file }, newFile }: { file: FileDescriptor; newFile: File }) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.uploader.upload(newFile);\n\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n file: newFile,\n uploadProgress: 0,\n })\n );\n }\n };\n\n handleDelete = ({ file }: FileDescriptor) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.props.onChange(\n this.props.value.filter(fileDescriptor => fileDescriptor.file !== file)\n );\n };\n\n handleErrorsClose = () => {\n this.clearErrors();\n };\n\n render() {\n const {\n value,\n onChange,\n hideReplace,\n hideDownload,\n limitReached,\n multiple,\n config,\n folderName,\n ...rest\n } = this.props;\n\n if (!onChange && !value.length) {\n return null;\n }\n\n const readonlyProps = onChange\n ? {}\n : {\n onReplace: undefined,\n onDelete: undefined,\n limitReached: true,\n };\n\n return (\n <Fragment>\n {!!this.errors.length && (\n <UploadErrors\n errors={this.errors}\n onClose={this.handleErrorsClose}\n className=\"m-b-2\"\n multiple={multiple}\n />\n )}\n <Confirm\n onConfirm={this.handleDelete}\n title=\"Are you sure you want to delete this file?\"\n >\n {onDelete => (\n <FilePicker\n value={value.length ? value : undefined}\n onReplace={!hideReplace ? this.handleReplace : undefined}\n onSelected={this.handleSelected}\n onDelete={onDelete}\n onDownload={!hideDownload ? this.handleDownload : undefined}\n limitReached={limitReached}\n multiple={multiple}\n {...rest}\n {...readonlyProps}\n />\n )}\n </Confirm>\n </Fragment>\n );\n }\n}\n"],"names":["Component","Fragment","injectDependency","optional","observer","observable","action","makeObservable","FilePicker","Banner","Confirm","FileUploaderConfig","FILE_UPLOADER_CONFIGURATION_TOKEN","Uploader","v4","uuid","immutableSplice","arr","start","deleteCount","items","slice","UploadErrors","errors","className","onClose","multiple","title","icon","status","ul","map","id","file","message","li","style","listStyle","name","FileUploader","addError","push","clearErrors","componentDidMount","uploader","config","props","progress","handleUploadProgress","success","handleUploadSuccess","error","handleUploadError","folderName","componentWillUnmount","cancel","render","value","onChange","hideReplace","hideDownload","limitReached","rest","length","readonlyProps","onReplace","undefined","onDelete","handleErrorsClose","onConfirm","handleDelete","handleReplace","onSelected","handleSelected","onDownload","handleDownload","constructor","index","findIndex","fileDescriptor","uploadProgress","displayName","downloadLink","filter","path","downloadPath","window","open","files","Array","from","upload","newFile","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAY,QAAQ;AAEhD,SAASC,gBAAgB,EAAEC,QAAQ,QAAQ,0BAA0B;AAErE,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,UAAU,EAAEC,MAAM,EAAEC,cAAc,QAAQ,OAAO;AAE1D,SAASC,UAAU,EAAkBC,MAAM,QAAyB,8BAA8B;AAClG,SAASC,OAAO,QAAQ,wBAAwB;AAEhD,SAASC,kBAAkB,EAAEC,iCAAiC,QAAQ,WAAW;AACjF,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,MAAMC,IAAI,QAAQ,OAAO;AAElC,SAASC,gBAAmBC,GAAQ,EAAEC,KAA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,gBAAe,CAAC,EAAErC,IAAI,EAAkB;YACpC,IAAI,CAAC,IAAI,CAACa,KAAK,CAACY,QAAQ,EAAE;gBACtB;YACJ;YAEA,IAAI,CAACZ,KAAK,CAACY,QAAQ,CACf,IAAI,CAACZ,KAAK,CAACW,KAAK,CAAC0B,MAAM,CAACJ,CAAAA,iBAAkBA,eAAe9C,IAAI,KAAKA;QAE1E,IAEAmC,uBAAAA,qBAAoB;YAChB,IAAI,CAAC1B,WAAW;QACpB;QAlJInC,eAAe,IAAI;IACvB;AA2MJ;AA1NI,iBADSgC,cACFsD,gBAAe;IAClBxC,YAAY;AAChB"}
|
1
|
+
{"version":3,"sources":["../../src/file-uploader/file-uploader.tsx"],"sourcesContent":["import { Component, Fragment, FC } from 'react';\n\nimport { injectDependency, optional } from '@servicetitan/react-ioc';\n\nimport { observer } from 'mobx-react';\nimport { observable, action, makeObservable } from 'mobx';\n\nimport { FilePicker, FileDescriptor, Banner, FilePickerProps } from '@servicetitan/design-system';\nimport { Confirm } from '@servicetitan/confirm';\n\nimport { FileUploaderConfig, FILE_UPLOADER_CONFIGURATION_TOKEN } from './config';\nimport { Uploader } from './uploader';\n\nimport { v4 as uuid } from 'uuid';\n\nfunction immutableSplice<T>(arr: T[], start: number, deleteCount: number, ...items: T[]) {\n return [...arr.slice(0, start), ...items, ...arr.slice(start + deleteCount)];\n}\n\ninterface UploadError {\n id: string;\n file: File;\n message?: string;\n}\n\ninterface UploadErrorsProps {\n errors: UploadError[];\n multiple?: boolean;\n className?: string;\n onClose(): void;\n}\n\nconst UploadErrors: FC<UploadErrorsProps> = ({ errors, className, onClose, multiple }) => {\n const title = multiple\n ? 'One or more files could not be uploaded:'\n : 'Your file could not be uploaded';\n\n return (\n <Banner icon status=\"critical\" title={title} className={className} onClose={onClose}>\n <ul className=\"p-x-0-i\">\n {errors.map(({ id, file, message }) => (\n <li key={id} style={!multiple ? { listStyle: 'none' } : {}}>\n {multiple && file.name}\n {message && (multiple ? ` (${message})` : message)}\n </li>\n ))}\n </ul>\n </Banner>\n );\n};\n\ntype ExcludedFilePickerProps = 'onDelete' | 'onDownload' | 'onReplace' | 'onSelected' | 'value';\n\ninterface FileUploaderProps extends Omit<FilePickerProps, ExcludedFilePickerProps> {\n config?: FileUploaderConfig;\n value: FileDescriptor[];\n folderName?: string;\n hideReplace?: boolean;\n hideDownload?: boolean;\n onChange?(value: FileDescriptor[]): void;\n}\n\n@observer\nexport class FileUploader extends Component<FileUploaderProps> {\n static defaultProps = {\n folderName: 'temp',\n };\n\n @injectDependency(FILE_UPLOADER_CONFIGURATION_TOKEN)\n @optional()\n declare config?: FileUploaderConfig;\n\n @observable errors: UploadError[] = [];\n\n uploader!: Uploader;\n\n constructor(props: FileUploaderProps) {\n super(props);\n makeObservable(this);\n }\n\n @action\n addError(file: File, message?: string) {\n this.errors.push({\n file,\n message,\n id: uuid(),\n });\n }\n\n @action\n clearErrors() {\n this.errors = [];\n }\n\n @action\n handleUploadProgress = (file: File, progress: number) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n ...this.props.value[index],\n uploadProgress: progress,\n })\n );\n } else {\n this.uploader.cancel(file);\n }\n };\n\n @action\n handleUploadSuccess = (file: File, message?: string) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n ...this.props.value[index],\n ...(message\n ? { file: message, displayName: file.name, downloadLink: message }\n : { file: file.name }),\n uploadProgress: undefined,\n })\n );\n }\n };\n\n @action\n handleUploadError = (file: File, message?: string) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.addError(file, message);\n\n this.props.onChange(\n this.props.value.filter(fileDescriptor => fileDescriptor.file !== file)\n );\n };\n\n componentDidMount() {\n this.uploader = new Uploader(\n {\n ...this.config,\n ...this.props.config,\n },\n {\n progress: this.handleUploadProgress,\n success: this.handleUploadSuccess,\n error: this.handleUploadError,\n },\n this.props.folderName\n );\n }\n\n componentWillUnmount() {\n this.uploader.cancel();\n }\n\n handleDownload = (file: FileDescriptor) => {\n if (!file.downloadLink) {\n return;\n }\n\n const path =\n this.props.config?.downloadPath ??\n this.config?.downloadPath ??\n `/app/api/fileuploader/folders/${this.props.folderName}/files/`;\n\n window.open(path + file.downloadLink);\n };\n\n handleSelected = (files: FileList) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.props.onChange([\n ...this.props.value,\n ...Array.from(files).map(file => ({\n file,\n uploadProgress: 0,\n })),\n ]);\n this.uploader.upload(files);\n };\n\n handleReplace = ({ file: { file }, newFile }: { file: FileDescriptor; newFile: File }) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.uploader.upload(newFile);\n\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n file: newFile,\n uploadProgress: 0,\n })\n );\n }\n };\n\n handleDelete = ({ file }: FileDescriptor) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.props.onChange(\n this.props.value.filter(fileDescriptor => fileDescriptor.file !== file)\n );\n };\n\n handleErrorsClose = () => {\n this.clearErrors();\n };\n\n render() {\n const {\n value,\n onChange,\n hideReplace,\n hideDownload,\n limitReached,\n multiple,\n config,\n folderName,\n ...rest\n } = this.props;\n\n if (!onChange && !value.length) {\n return null;\n }\n\n const readonlyProps = onChange\n ? {}\n : {\n onReplace: undefined,\n onDelete: undefined,\n limitReached: true,\n };\n\n return (\n <Fragment>\n {!!this.errors.length && (\n <UploadErrors\n errors={this.errors}\n onClose={this.handleErrorsClose}\n className=\"m-b-2\"\n multiple={multiple}\n />\n )}\n <Confirm\n onConfirm={this.handleDelete}\n title=\"Are you sure you want to delete this file?\"\n >\n {onDelete => (\n <FilePicker\n value={value.length ? value : undefined}\n onReplace={!hideReplace ? this.handleReplace : undefined}\n onSelected={this.handleSelected}\n onDelete={onDelete}\n onDownload={!hideDownload ? this.handleDownload : undefined}\n limitReached={limitReached}\n multiple={multiple}\n {...rest}\n {...readonlyProps}\n />\n )}\n </Confirm>\n </Fragment>\n );\n }\n}\n"],"names":["Component","Fragment","injectDependency","optional","observer","observable","action","makeObservable","FilePicker","Banner","Confirm","FileUploaderConfig","FILE_UPLOADER_CONFIGURATION_TOKEN","Uploader","v4","uuid","immutableSplice","arr","start","deleteCount","items","slice","UploadErrors","errors","className","onClose","multiple","title","icon","status","ul","map","id","file","message","li","style","listStyle","name","FileUploader","addError","push","clearErrors","componentDidMount","uploader","config","props","progress","handleUploadProgress","success","handleUploadSuccess","error","handleUploadError","folderName","componentWillUnmount","cancel","render","value","onChange","hideReplace","hideDownload","limitReached","rest","length","readonlyProps","onReplace","undefined","onDelete","handleErrorsClose","onConfirm","handleDelete","handleReplace","onSelected","handleSelected","onDownload","handleDownload","index","findIndex","fileDescriptor","uploadProgress","displayName","downloadLink","filter","path","downloadPath","window","open","files","Array","from","upload","newFile","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAY,QAAQ;AAEhD,SAASC,gBAAgB,EAAEC,QAAQ,QAAQ,0BAA0B;AAErE,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,UAAU,EAAEC,MAAM,EAAEC,cAAc,QAAQ,OAAO;AAE1D,SAASC,UAAU,EAAkBC,MAAM,QAAyB,8BAA8B;AAClG,SAASC,OAAO,QAAQ,wBAAwB;AAEhD,SAASC,kBAAkB,EAAEC,iCAAiC,QAAQ,WAAW;AACjF,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,MAAMC,IAAI,QAAQ,OAAO;AAElC,SAASC,gBAAmBC,GAAQ,EAAEC,KAAa,EAAEC,WAAmB,EAAE,GAAGC,KAAU;IACnF,OAAO;WAAIH,IAAII,KAAK,CAAC,GAAGH;WAAW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E;gBACtB;YACJ;YAEA,IAAI,CAACZ,KAAK,CAACY,QAAQ,CACf,IAAI,CAACZ,KAAK,CAACW,KAAK,CAACyB,MAAM,CAACJ,CAAAA,iBAAkBA,eAAe7C,IAAI,KAAKA;QAE1E,IAEAmC,uBAAAA,qBAAoB;YAChB,IAAI,CAAC1B,WAAW;QACpB;QAlJInC,eAAe,IAAI;IACvB;AA2MJ;AA1NI,iBADSgC,cACFqD,gBAAe;IAClBvC,YAAY;AAChB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/file-uploader/uploader.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid';\n\nimport { FileUploaderConfig } from './config';\n\nconst Resumable = require('resumablejs');\n\ninterface Resumable {\n files: ResumableFile[];\n on(event: 'fileAdded', callback: (file: ResumableFile, event: Event) => void): void;\n on(event: 'fileProgress', callback: (file: ResumableFile, message?: string) => void): void;\n on(event: 'fileSuccess', callback: (file: ResumableFile, message?: string) => void): void;\n on(event: 'fileError', callback: (file: ResumableFile, message?: string) => void): void;\n addFile(file: File): void;\n upload(): void;\n cancel(): void;\n}\n\ninterface ResumableFile {\n file: File;\n progress(relative?: boolean): number;\n isComplete(): boolean;\n cancel(): void;\n}\n\nexport class Uploader {\n private readonly resumable: Resumable;\n\n constructor(\n config: FileUploaderConfig = {},\n handlers: {\n progress?(file: File, progress: number): void;\n success?(file: File, message?: string): void;\n error?(file: File, message?: string): void;\n } = {},\n folderName = 'default'\n ) {\n const { errorParser, ...configuration } = config;\n\n const resumable: Resumable = new Resumable({\n target: `/app/api/fileuploader/folders/${folderName}/files`,\n testChunks: false,\n simultaneousUploads: 1,\n headers: { 'X-Requested-With': 'XMLHttpRequest' },\n permanentErrors: [302, 400, 404, 415, 500, 501],\n generateUniqueIdentifier: () => uuid(),\n fileTypeErrorCallback: (file: File) => {\n handlers.error?.(\n file,\n `File type not allowed. Please provide file of type ${configuration.fileType\n ?.map(ext => `.${ext}`)\n ?.join(', ')}.`\n );\n },\n ...configuration,\n });\n\n resumable.on('fileAdded', () => {\n resumable.upload();\n });\n\n resumable.on('fileProgress', resumableFile => {\n if (resumableFile.isComplete()) {\n return;\n }\n\n let progress = Math.floor(resumableFile.progress(false) * 100);\n if (progress > 99) {\n progress = 99;\n }\n\n if (handlers.progress) {\n handlers.progress(resumableFile.file, progress);\n }\n });\n\n resumable.on('fileSuccess', (resumableFile, message) => {\n if (handlers.success) {\n handlers.success(resumableFile.file, message);\n }\n\n resumableFile.cancel();\n });\n\n resumable.on('fileError', (resumableFile, message) => {\n if (handlers.error) {\n handlers.error(resumableFile.file, errorParser ? errorParser(message) : message);\n }\n\n resumableFile.cancel();\n });\n\n this.resumable = resumable;\n }\n\n upload(source: File | FileList) {\n if (source instanceof File) {\n this.resumable.addFile(source);\n } else {\n for (const file of Array.from(source)) {\n this.resumable.addFile(file);\n }\n }\n }\n\n cancel(file?: File) {\n if (file) {\n for (const resumableFile of this.resumable.files) {\n if (resumableFile.file === file) {\n resumableFile.cancel();\n break;\n }\n }\n } else {\n this.resumable.cancel();\n }\n }\n}\n"],"names":["v4","uuid","Resumable","require","Uploader","upload","source","File","resumable","addFile","file","Array","from","cancel","resumableFile","files","
|
1
|
+
{"version":3,"sources":["../../src/file-uploader/uploader.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid';\n\nimport { FileUploaderConfig } from './config';\n\nconst Resumable = require('resumablejs');\n\ninterface Resumable {\n files: ResumableFile[];\n on(event: 'fileAdded', callback: (file: ResumableFile, event: Event) => void): void;\n on(event: 'fileProgress', callback: (file: ResumableFile, message?: string) => void): void;\n on(event: 'fileSuccess', callback: (file: ResumableFile, message?: string) => void): void;\n on(event: 'fileError', callback: (file: ResumableFile, message?: string) => void): void;\n addFile(file: File): void;\n upload(): void;\n cancel(): void;\n}\n\ninterface ResumableFile {\n file: File;\n progress(relative?: boolean): number;\n isComplete(): boolean;\n cancel(): void;\n}\n\nexport class Uploader {\n private readonly resumable: Resumable;\n\n constructor(\n config: FileUploaderConfig = {},\n handlers: {\n progress?(file: File, progress: number): void;\n success?(file: File, message?: string): void;\n error?(file: File, message?: string): void;\n } = {},\n folderName = 'default'\n ) {\n const { errorParser, ...configuration } = config;\n\n const resumable: Resumable = new Resumable({\n target: `/app/api/fileuploader/folders/${folderName}/files`,\n testChunks: false,\n simultaneousUploads: 1,\n headers: { 'X-Requested-With': 'XMLHttpRequest' },\n permanentErrors: [302, 400, 404, 415, 500, 501],\n generateUniqueIdentifier: () => uuid(),\n fileTypeErrorCallback: (file: File) => {\n handlers.error?.(\n file,\n `File type not allowed. Please provide file of type ${configuration.fileType\n ?.map(ext => `.${ext}`)\n ?.join(', ')}.`\n );\n },\n ...configuration,\n });\n\n resumable.on('fileAdded', () => {\n resumable.upload();\n });\n\n resumable.on('fileProgress', resumableFile => {\n if (resumableFile.isComplete()) {\n return;\n }\n\n let progress = Math.floor(resumableFile.progress(false) * 100);\n if (progress > 99) {\n progress = 99;\n }\n\n if (handlers.progress) {\n handlers.progress(resumableFile.file, progress);\n }\n });\n\n resumable.on('fileSuccess', (resumableFile, message) => {\n if (handlers.success) {\n handlers.success(resumableFile.file, message);\n }\n\n resumableFile.cancel();\n });\n\n resumable.on('fileError', (resumableFile, message) => {\n if (handlers.error) {\n handlers.error(resumableFile.file, errorParser ? errorParser(message) : message);\n }\n\n resumableFile.cancel();\n });\n\n this.resumable = resumable;\n }\n\n upload(source: File | FileList) {\n if (source instanceof File) {\n this.resumable.addFile(source);\n } else {\n for (const file of Array.from(source)) {\n this.resumable.addFile(file);\n }\n }\n }\n\n cancel(file?: File) {\n if (file) {\n for (const resumableFile of this.resumable.files) {\n if (resumableFile.file === file) {\n resumableFile.cancel();\n break;\n }\n }\n } else {\n this.resumable.cancel();\n }\n }\n}\n"],"names":["v4","uuid","Resumable","require","Uploader","upload","source","File","resumable","addFile","file","Array","from","cancel","resumableFile","files","config","handlers","folderName","errorParser","configuration","target","testChunks","simultaneousUploads","headers","permanentErrors","generateUniqueIdentifier","fileTypeErrorCallback","error","fileType","map","ext","join","on","isComplete","progress","Math","floor","message","success"],"mappings":";;;;;;;;;;;;;AAAA,SAASA,MAAMC,IAAI,QAAQ,OAAO;AAIlC,MAAMC,YAAYC,QAAQ;AAoB1B,OAAO,MAAMC;IAsETC,OAAOC,MAAuB,EAAE;QAC5B,IAAIA,kBAAkBC,MAAM;YACxB,IAAI,CAACC,SAAS,CAACC,OAAO,CAACH;QAC3B,OAAO;YACH,KAAK,MAAMI,QAAQC,MAAMC,IAAI,CAACN,QAAS;gBACnC,IAAI,CAACE,SAAS,CAACC,OAAO,CAACC;YAC3B;QACJ;IACJ;IAEAG,OAAOH,IAAW,EAAE;QAChB,IAAIA,MAAM;YACN,KAAK,MAAMI,iBAAiB,IAAI,CAACN,SAAS,CAACO,KAAK,CAAE;gBAC9C,IAAID,cAAcJ,IAAI,KAAKA,MAAM;oBAC7BI,cAAcD,MAAM;oBACpB;gBACJ;YACJ;QACJ,OAAO;YACH,IAAI,CAACL,SAAS,CAACK,MAAM;QACzB;IACJ;IAxFA,YACIG,SAA6B,CAAC,CAAC,EAC/BC,WAII,CAAC,CAAC,EACNC,aAAa,SAAS,CACxB;QAVF,uBAAiBV,aAAjB,KAAA;QAWI,MAAM,EAAEW,WAAW,EAAE,GAAGC,eAAe,GAAGJ;QAE1C,MAAMR,YAAuB,IAAIN,UAAU;YACvCmB,QAAQ,CAAC,8BAA8B,EAAEH,WAAW,MAAM,CAAC;YAC3DI,YAAY;YACZC,qBAAqB;YACrBC,SAAS;gBAAE,oBAAoB;YAAiB;YAChDC,iBAAiB;gBAAC;gBAAK;gBAAK;gBAAK;gBAAK;gBAAK;aAAI;YAC/CC,0BAA0B,IAAMzB;YAChC0B,uBAAuB,CAACjB;oBAGsCU,6BAAAA,yBAF1DH;iBAAAA,kBAAAA,SAASW,KAAK,cAAdX,sCAAAA,qBAAAA,UACIP,MACA,CAAC,mDAAmD,GAAEU,0BAAAA,cAAcS,QAAQ,cAAtBT,+CAAAA,8BAAAA,wBAChDU,GAAG,CAACC,CAAAA,MAAO,CAAC,CAAC,EAAEA,KAAK,eAD4BX,kDAAAA,4BAEhDY,IAAI,CAAC,MAAM,CAAC,CAAC;YAE3B;YACA,GAAGZ,aAAa;QACpB;QAEAZ,UAAUyB,EAAE,CAAC,aAAa;YACtBzB,UAAUH,MAAM;QACpB;QAEAG,UAAUyB,EAAE,CAAC,gBAAgBnB,CAAAA;YACzB,IAAIA,cAAcoB,UAAU,IAAI;gBAC5B;YACJ;YAEA,IAAIC,WAAWC,KAAKC,KAAK,CAACvB,cAAcqB,QAAQ,CAAC,SAAS;YAC1D,IAAIA,WAAW,IAAI;gBACfA,WAAW;YACf;YAEA,IAAIlB,SAASkB,QAAQ,EAAE;gBACnBlB,SAASkB,QAAQ,CAACrB,cAAcJ,IAAI,EAAEyB;YAC1C;QACJ;QAEA3B,UAAUyB,EAAE,CAAC,eAAe,CAACnB,eAAewB;YACxC,IAAIrB,SAASsB,OAAO,EAAE;gBAClBtB,SAASsB,OAAO,CAACzB,cAAcJ,IAAI,EAAE4B;YACzC;YAEAxB,cAAcD,MAAM;QACxB;QAEAL,UAAUyB,EAAE,CAAC,aAAa,CAACnB,eAAewB;YACtC,IAAIrB,SAASW,KAAK,EAAE;gBAChBX,SAASW,KAAK,CAACd,cAAcJ,IAAI,EAAES,cAAcA,YAAYmB,WAAWA;YAC5E;YAEAxB,cAAcD,MAAM;QACxB;QAEA,IAAI,CAACL,SAAS,GAAGA;IACrB;AAwBJ"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/original-number-input/ordinal-number-input.tsx"],"sourcesContent":["import { Input, InputProps } from '@servicetitan/design-system';\nimport { action, observable, makeObservable } from 'mobx';\nimport { observer } from 'mobx-react';\nimport { Component, ChangeEvent } from 'react';\n\nexport interface OrdinalNumberInputProps extends Omit<InputProps, 'onChange'> {\n min: number;\n max: number;\n value?: number;\n onChange?(value?: number): void;\n}\n\n@observer\nexport class OrdinalNumberInput extends Component<OrdinalNumberInputProps> {\n @observable hasFocus = false;\n\n constructor(props: OrdinalNumberInputProps) {\n super(props);\n makeObservable(this);\n }\n\n render() {\n const { min, max, value, onChange, ...props } = this.props;\n\n return (\n <Input\n placeholder={this.getPlaceholder()}\n {...props}\n value={this.getDisplayValue()}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n onChange={this.handleChange}\n />\n );\n }\n\n @action private handleFocus = () => (this.hasFocus = true);\n @action private handleBlur = () => (this.hasFocus = false);\n\n private handleChange = (e: ChangeEvent<HTMLInputElement>): void => {\n const parsed = parseIntIntoRange(e.currentTarget.value, this.props.min, this.props.max);\n if (this.props.onChange) {\n this.props.onChange(parsed);\n }\n };\n\n private getPlaceholder() {\n return `${this.props.min}‒${this.props.max}`;\n }\n\n private getDisplayValue() {\n const value = this.props.value;\n if (typeof value !== 'number') {\n return '';\n }\n return this.hasFocus ? value.toString() : ordinalString(value);\n }\n}\n\nexport function parseIntIntoRange(input: string, min: number, max: number) {\n let parsed = parseInt(input, 10);\n if (Number.isNaN(parsed)) {\n return undefined;\n }\n if (parsed < min) {\n parsed = min;\n } else if (parsed > max) {\n parsed = max;\n }\n return parsed;\n}\n\nexport function ordinalString(num: number): string {\n switch (num % 100) {\n case 11:\n case 12:\n case 13:\n return num.toString() + 'th';\n default:\n switch (num % 10) {\n case 1:\n return num.toString() + 'st';\n case 2:\n return num.toString() + 'nd';\n case 3:\n return num.toString() + 'rd';\n default:\n return num.toString() + 'th';\n }\n }\n}\n\nexport function ordinalSuffix(num: number): string {\n switch (num % 100) {\n case 11:\n case 12:\n case 13:\n return 'th';\n default:\n switch (num % 10) {\n case 1:\n return 'st';\n case 2:\n return 'nd';\n case 3:\n return 'rd';\n default:\n return 'th';\n }\n }\n}\n"],"names":["Input","action","observable","makeObservable","observer","Component","OrdinalNumberInput","render","min","max","value","onChange","props","placeholder","getPlaceholder","getDisplayValue","onFocus","handleFocus","onBlur","handleBlur","handleChange","hasFocus","toString","ordinalString","
|
1
|
+
{"version":3,"sources":["../../src/original-number-input/ordinal-number-input.tsx"],"sourcesContent":["import { Input, InputProps } from '@servicetitan/design-system';\nimport { action, observable, makeObservable } from 'mobx';\nimport { observer } from 'mobx-react';\nimport { Component, ChangeEvent } from 'react';\n\nexport interface OrdinalNumberInputProps extends Omit<InputProps, 'onChange'> {\n min: number;\n max: number;\n value?: number;\n onChange?(value?: number): void;\n}\n\n@observer\nexport class OrdinalNumberInput extends Component<OrdinalNumberInputProps> {\n @observable hasFocus = false;\n\n constructor(props: OrdinalNumberInputProps) {\n super(props);\n makeObservable(this);\n }\n\n render() {\n const { min, max, value, onChange, ...props } = this.props;\n\n return (\n <Input\n placeholder={this.getPlaceholder()}\n {...props}\n value={this.getDisplayValue()}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n onChange={this.handleChange}\n />\n );\n }\n\n @action private handleFocus = () => (this.hasFocus = true);\n @action private handleBlur = () => (this.hasFocus = false);\n\n private handleChange = (e: ChangeEvent<HTMLInputElement>): void => {\n const parsed = parseIntIntoRange(e.currentTarget.value, this.props.min, this.props.max);\n if (this.props.onChange) {\n this.props.onChange(parsed);\n }\n };\n\n private getPlaceholder() {\n return `${this.props.min}‒${this.props.max}`;\n }\n\n private getDisplayValue() {\n const value = this.props.value;\n if (typeof value !== 'number') {\n return '';\n }\n return this.hasFocus ? value.toString() : ordinalString(value);\n }\n}\n\nexport function parseIntIntoRange(input: string, min: number, max: number) {\n let parsed = parseInt(input, 10);\n if (Number.isNaN(parsed)) {\n return undefined;\n }\n if (parsed < min) {\n parsed = min;\n } else if (parsed > max) {\n parsed = max;\n }\n return parsed;\n}\n\nexport function ordinalString(num: number): string {\n switch (num % 100) {\n case 11:\n case 12:\n case 13:\n return num.toString() + 'th';\n default:\n switch (num % 10) {\n case 1:\n return num.toString() + 'st';\n case 2:\n return num.toString() + 'nd';\n case 3:\n return num.toString() + 'rd';\n default:\n return num.toString() + 'th';\n }\n }\n}\n\nexport function ordinalSuffix(num: number): string {\n switch (num % 100) {\n case 11:\n case 12:\n case 13:\n return 'th';\n default:\n switch (num % 10) {\n case 1:\n return 'st';\n case 2:\n return 'nd';\n case 3:\n return 'rd';\n default:\n return 'th';\n }\n }\n}\n"],"names":["Input","action","observable","makeObservable","observer","Component","OrdinalNumberInput","render","min","max","value","onChange","props","placeholder","getPlaceholder","getDisplayValue","onFocus","handleFocus","onBlur","handleBlur","handleChange","hasFocus","toString","ordinalString","e","parsed","parseIntIntoRange","currentTarget","input","parseInt","Number","isNaN","undefined","num","ordinalSuffix"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,KAAK,QAAoB,8BAA8B;AAChE,SAASC,MAAM,EAAEC,UAAU,EAAEC,cAAc,QAAQ,OAAO;AAC1D,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,SAAS,QAAqB,QAAQ;AAU/C,OAAO,MAAMC,2BAA2BD;IAQpCE,SAAS;QACL,MAAM,EAAEC,GAAG,EAAEC,GAAG,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGC,OAAO,GAAG,IAAI,CAACA,KAAK;QAE1D,qBACI,KAACZ;YACGa,aAAa,IAAI,CAACC,cAAc;YAC/B,GAAGF,KAAK;YACTF,OAAO,IAAI,CAACK,eAAe;YAC3BC,SAAS,IAAI,CAACC,WAAW;YACzBC,QAAQ,IAAI,CAACC,UAAU;YACvBR,UAAU,IAAI,CAACS,YAAY;;IAGvC;IAYQN,iBAAiB;QACrB,OAAO,GAAG,IAAI,CAACF,KAAK,CAACJ,GAAG,CAAC,CAAC,EAAE,IAAI,CAACI,KAAK,CAACH,GAAG,EAAE;IAChD;IAEQM,kBAAkB;QACtB,MAAML,QAAQ,IAAI,CAACE,KAAK,CAACF,KAAK;QAC9B,IAAI,OAAOA,UAAU,UAAU;YAC3B,OAAO;QACX;QACA,OAAO,IAAI,CAACW,QAAQ,GAAGX,MAAMY,QAAQ,KAAKC,cAAcb;IAC5D;IAxCA,YAAYE,KAA8B,CAAE;QACxC,KAAK,C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K;oBACD,OAAO;gBACX;oBACI,OAAO;YACf;IACR;AACJ"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@servicetitan/form",
|
3
|
-
"version": "32.
|
3
|
+
"version": "32.4.0",
|
4
4
|
"description": "",
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/form",
|
6
6
|
"repository": {
|
@@ -17,14 +17,14 @@
|
|
17
17
|
],
|
18
18
|
"devDependencies": {
|
19
19
|
"@progress/kendo-react-dateinputs": "~5.5.0",
|
20
|
-
"@servicetitan/confirm": "^32.
|
21
|
-
"@servicetitan/culture": "^32.
|
20
|
+
"@servicetitan/confirm": "^32.4.0",
|
21
|
+
"@servicetitan/culture": "^32.4.0",
|
22
22
|
"@servicetitan/design-system": "~14.5.1",
|
23
|
-
"@servicetitan/form-state": "^32.
|
24
|
-
"@servicetitan/hash-browser-router": "^31.
|
25
|
-
"@servicetitan/react-ioc": "^31.
|
23
|
+
"@servicetitan/form-state": "^32.4.0",
|
24
|
+
"@servicetitan/hash-browser-router": "^31.6.0",
|
25
|
+
"@servicetitan/react-ioc": "^31.6.0",
|
26
26
|
"@servicetitan/tokens": ">=12.2.1",
|
27
|
-
"@servicetitan/web-components": "^31.
|
27
|
+
"@servicetitan/web-components": "^31.6.0",
|
28
28
|
"@types/react": "~18.2.55",
|
29
29
|
"@types/react-input-mask": "~2.0.5",
|
30
30
|
"@types/uuid": "~8.3.4",
|
@@ -38,10 +38,10 @@
|
|
38
38
|
},
|
39
39
|
"peerDependencies": {
|
40
40
|
"@progress/kendo-react-dateinputs": "~5.5.0",
|
41
|
-
"@servicetitan/confirm": "^32.
|
42
|
-
"@servicetitan/culture": "^32.
|
41
|
+
"@servicetitan/confirm": "^32.4.0",
|
42
|
+
"@servicetitan/culture": "^32.4.0",
|
43
43
|
"@servicetitan/design-system": ">=13.2.1",
|
44
|
-
"@servicetitan/form-state": "^32.
|
44
|
+
"@servicetitan/form-state": "^32.4.0",
|
45
45
|
"@servicetitan/react-ioc": ">21.0.0",
|
46
46
|
"@servicetitan/tokens": ">=12.2.1",
|
47
47
|
"accounting": "~0.4.1",
|
@@ -65,5 +65,5 @@
|
|
65
65
|
"less": true,
|
66
66
|
"webpack": false
|
67
67
|
},
|
68
|
-
"gitHead": "
|
68
|
+
"gitHead": "3dab3310534a39aaacb0069e1d377579fe0a7fab"
|
69
69
|
}
|