@itwin/components-react 4.5.1 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/lib/cjs/components-react/datepicker/DateField.js +1 -1
- package/lib/cjs/components-react/datepicker/DateField.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeHooks.d.ts.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeHooks.js +7 -4
- package/lib/cjs/components-react/tree/controlled/TreeHooks.js.map +1 -1
- package/lib/esm/components-react/datepicker/DateField.js +1 -1
- package/lib/esm/components-react/datepicker/DateField.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeHooks.d.ts.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeHooks.js +8 -5
- package/lib/esm/components-react/tree/controlled/TreeHooks.js.map +1 -1
- package/package.json +4 -4
- package/lib/cjs/components-react/common/UseRerender.d.ts +0 -22
- package/lib/cjs/components-react/common/UseRerender.d.ts.map +0 -1
- package/lib/cjs/components-react/common/UseRerender.js +0 -36
- package/lib/cjs/components-react/common/UseRerender.js.map +0 -1
- package/lib/esm/components-react/common/UseRerender.d.ts +0 -22
- package/lib/esm/components-react/common/UseRerender.d.ts.map +0 -1
- package/lib/esm/components-react/common/UseRerender.js +0 -32
- package/lib/esm/components-react/common/UseRerender.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Change Log - @itwin/components-react
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 12 Oct 2023 16:59:20 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.6.1
|
|
6
|
+
Thu, 12 Oct 2023 16:59:20 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.6.0
|
|
11
|
+
Wed, 04 Oct 2023 18:05:34 GMT
|
|
12
|
+
|
|
13
|
+
### Updates
|
|
14
|
+
|
|
15
|
+
- Fix `useTreeModel` missing tree model changes that happen after render until `useTreeModel` subscribes to `TreeModelSource.onModelChanged` event.
|
|
4
16
|
|
|
5
17
|
## 4.5.1
|
|
6
18
|
Fri, 08 Sep 2023 16:10:53 GMT
|
|
@@ -138,7 +138,7 @@ function DateField({ initialDate, onDateChange, readOnly, dateFormatter, timeDis
|
|
|
138
138
|
if (dateFormatter && dateFormatter.parseDate)
|
|
139
139
|
return dateFormatter.parseDate(dateString);
|
|
140
140
|
const newDateValue = Date.parse(dateString);
|
|
141
|
-
// istanbul ignore
|
|
141
|
+
// istanbul ignore next
|
|
142
142
|
if (newDateValue)
|
|
143
143
|
return new Date(newDateValue);
|
|
144
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/DateField.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4BAA0B;AAC1B,6CAA+B;AAC/B,4DAAoC;AAEpC,0DAA0E;AAE1E,wDAA6C;AAC7C,sDAA6C;AAmB7C;;;GAGG;AACH,SAAgB,eAAe,CAC7B,SAAe,EACf,WAAyB,EACzB,eAA+B,EAC/B,mBAA0C;IAE1C,IAAI,eAAe,EAAE;QACnB,OAAO,eAAe,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;KAC/C;IAED,IAAI,mBAAmB,EAAE;QACvB,QAAQ,mBAAmB,EAAE;YAC3B,KAAK,qCAAoB,CAAC,WAAW;gBACnC,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC;YACjC,KAAK,qCAAoB,CAAC,QAAQ;gBAChC,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9C,KAAK,qCAAoB,CAAC,WAAW;gBACnC,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC,KAAK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C,EACD,CAAC,YAAY,EAAE,SAAS,CAAC,CAC1B,CAAC;IAEF,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CACpC,CAAC,KAAyC,EAAE,EAAE;QAC5C,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC,EACD,CAAC,eAAe,CAAC,CAClB,CAAC;IAEF,SAAS,cAAc,CAAC,KAA4C;QAClE,uBAAuB;QACvB,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE;YACzB,eAAe,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAC3C,KAAK,CAAC,cAAc,EAAE,CAAC;SACxB;IACH,CAAC;IACD,MAAM,UAAU,GAAG,IAAA,oBAAU,EAC3B,SAAS,EACT,uBAAuB,EACvB,WAAW,IAAI,2BAA2B,CAC3C,CAAC;IACF,OAAO,CACL,oBAAC,qBAAK,mBACQ,uBAAuB,EACnC,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,cAAc,EACzB,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,QAAQ,IAAI,CAAC,aAAa,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EACjE,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC;AAxGD,8BAwGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport \"./DateField.scss\";\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport type { DateFormatter } from \"@itwin/appui-abstract\";\nimport { AlternateDateFormats, TimeDisplay } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { Logger } from \"@itwin/core-bentley\";\n\n/** Props for [[DateField]] Component.\n * @internal\n */\nexport interface DateFieldProps extends CommonProps {\n /** Defines initial date and time for component. */\n initialDate: Date;\n /** Function to call when the date or time is changed. */\n onDateChange?: (day: Date) => void;\n /** Optional value to define if edit field allows editing. If a DateFormatter is provided\n * it must provide a parseData function or the field will be read only no matter the setting of this value. */\n readOnly?: boolean;\n /** Optional date formatter that produces an explicit date display */\n dateFormatter?: DateFormatter;\n /** This property has two purposes, the first is specify that the display of time is desired and the second is to define the format of the time display. */\n timeDisplay?: TimeDisplay;\n}\n\n/** Function to format a Date object that is used in control, type editor, and type converter\n * to produce a consistent formatted Date string.\n * @internal\n */\nexport function formatInputDate(\n inputDate: Date,\n timeDisplay?: TimeDisplay,\n customFormatter?: DateFormatter,\n alternateDateFormat?: AlternateDateFormats\n): string | undefined {\n if (customFormatter) {\n return customFormatter.formateDate(inputDate);\n }\n\n if (alternateDateFormat) {\n switch (alternateDateFormat) {\n case AlternateDateFormats.IsoDateTime:\n return inputDate.toISOString();\n case AlternateDateFormats.IsoShort:\n return inputDate.toISOString().slice(0, 10);\n case AlternateDateFormats.UtcDateTime:\n return inputDate.toUTCString().slice(5);\n case AlternateDateFormats.UtcShort:\n return inputDate.toUTCString().slice(5, 16);\n case AlternateDateFormats.UtcDateTimeWithDay:\n return inputDate.toUTCString();\n case AlternateDateFormats.UtcShortWithDay:\n return inputDate.toUTCString().slice(0, 16);\n }\n } else {\n const dateString = inputDate.toLocaleDateString(undefined, {\n day: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n });\n let timeString: string = \"\";\n\n if (timeDisplay) {\n switch (timeDisplay) {\n case TimeDisplay.H12MC:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: true,\n hour: \"2-digit\",\n minute: \"2-digit\",\n });\n break;\n case TimeDisplay.H12MSC:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: true,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n break;\n case TimeDisplay.H24M:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n });\n // istanbul ignore next\n if (timeString === \"24:00\") timeString = \"00:00\";\n break;\n case TimeDisplay.H24MS:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n // istanbul ignore next\n if (timeString === \"24:00:00\") timeString = \"00:00:00\";\n break;\n }\n }\n return timeString.length ? `${dateString}, ${timeString}` : dateString;\n }\n}\n\n/** Date input component. This component is typically used by the [[DatePickerPopupButton]] to display and edit date and time.\n * @internal\n */\nexport function DateField({\n initialDate,\n onDateChange,\n readOnly,\n dateFormatter,\n timeDisplay,\n style,\n className,\n}: DateFieldProps) {\n const initialDateRef = React.useRef(initialDate);\n const [hasBadInput, setHasBadInput] = React.useState(false);\n const [inputValue, setInputValue] = React.useState(\n formatInputDate(initialDate, timeDisplay, dateFormatter)\n );\n\n // See if new initialDate props have changed since component mounted\n React.useEffect(() => {\n // istanbul ignore else\n if (initialDate.getTime() !== initialDateRef.current.getTime()) {\n initialDateRef.current = initialDate;\n }\n setInputValue(formatInputDate(initialDate, timeDisplay, dateFormatter));\n }, [initialDate, dateFormatter, timeDisplay]);\n\n const handleInputChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setInputValue(event.currentTarget.value);\n },\n []\n );\n\n const parseDate = React.useCallback(\n (dateString: string) => {\n try {\n if (dateFormatter && dateFormatter.parseDate)\n return dateFormatter.parseDate(dateString);\n\n const newDateValue = Date.parse(dateString);\n // istanbul ignore else\n if (newDateValue) return new Date(newDateValue);\n } catch (_error) /* istanbul ignore next */ {\n Logger.logInfo(\n \"DateField\",\n `Encountered error parsing input value '${dateString}' as a date.`\n );\n return undefined;\n }\n // istanbul ignore next\n return undefined;\n },\n [dateFormatter]\n );\n\n const updateInputDate = React.useCallback(\n (dateString: string) => {\n try {\n const newDateValue = parseDate(dateString);\n if (newDateValue) {\n const newDate = new Date(newDateValue);\n onDateChange && onDateChange(newDate);\n setHasBadInput(false);\n } else {\n setHasBadInput(true);\n }\n } catch (_error) {\n // istanbul ignore next\n setHasBadInput(true);\n }\n },\n [onDateChange, parseDate]\n );\n\n const handleOnBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n updateInputDate(event.target.value);\n },\n [updateInputDate]\n );\n\n function onInputKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {\n // istanbul ignore else\n if (event.key === \"Enter\") {\n updateInputDate(event.currentTarget.value);\n event.preventDefault();\n }\n }\n const classNames = classnames(\n className,\n \"components-date-input\",\n hasBadInput && \"components-date-has-error\"\n );\n return (\n <Input\n data-testid=\"components-date-input\"\n style={style}\n className={classNames}\n onKeyDown={onInputKeyDown}\n onBlur={handleOnBlur}\n onChange={handleInputChange}\n value={inputValue}\n disabled={readOnly || (dateFormatter && !dateFormatter.parseDate)}\n size=\"small\"\n />\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/DateField.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4BAA0B;AAC1B,6CAA+B;AAC/B,4DAAoC;AAEpC,0DAA0E;AAE1E,wDAA6C;AAC7C,sDAA6C;AAmB7C;;;GAGG;AACH,SAAgB,eAAe,CAC7B,SAAe,EACf,WAAyB,EACzB,eAA+B,EAC/B,mBAA0C;IAE1C,IAAI,eAAe,EAAE;QACnB,OAAO,eAAe,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;KAC/C;IAED,IAAI,mBAAmB,EAAE;QACvB,QAAQ,mBAAmB,EAAE;YAC3B,KAAK,qCAAoB,CAAC,WAAW;gBACnC,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC;YACjC,KAAK,qCAAoB,CAAC,QAA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AAC,KAAK,CAAC,CAAC;aACvB;iBAAM;gBACL,cAAc,CAAC,IAAI,CAAC,CAAC;aACtB;SACF;QAAC,OAAO,MAAM,EAAE;YACf,uBAAuB;YACvB,cAAc,CAAC,IAAI,CAAC,CAAC;SACtB;IACH,CAAC,EACD,CAAC,YAAY,EAAE,SAAS,CAAC,CAC1B,CAAC;IAEF,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CACpC,CAAC,KAAyC,EAAE,EAAE;QAC5C,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC,EACD,CAAC,eAAe,CAAC,CAClB,CAAC;IAEF,SAAS,cAAc,CAAC,KAA4C;QAClE,uBAAuB;QACvB,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE;YACzB,eAAe,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAC3C,KAAK,CAAC,cAAc,EAAE,CAAC;SACxB;IACH,CAAC;IACD,MAAM,UAAU,GAAG,IAAA,oBAAU,EAC3B,SAAS,EACT,uBAAuB,EACvB,WAAW,IAAI,2BAA2B,CAC3C,CAAC;IACF,OAAO,CACL,oBAAC,qBAAK,mBACQ,uBAAuB,EACnC,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,cAAc,EACzB,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,QAAQ,IAAI,CAAC,aAAa,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EACjE,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC;AAxGD,8BAwGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport \"./DateField.scss\";\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport type { DateFormatter } from \"@itwin/appui-abstract\";\nimport { AlternateDateFormats, TimeDisplay } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { Logger } from \"@itwin/core-bentley\";\n\n/** Props for [[DateField]] Component.\n * @internal\n */\nexport interface DateFieldProps extends CommonProps {\n /** Defines initial date and time for component. */\n initialDate: Date;\n /** Function to call when the date or time is changed. */\n onDateChange?: (day: Date) => void;\n /** Optional value to define if edit field allows editing. If a DateFormatter is provided\n * it must provide a parseData function or the field will be read only no matter the setting of this value. */\n readOnly?: boolean;\n /** Optional date formatter that produces an explicit date display */\n dateFormatter?: DateFormatter;\n /** This property has two purposes, the first is specify that the display of time is desired and the second is to define the format of the time display. */\n timeDisplay?: TimeDisplay;\n}\n\n/** Function to format a Date object that is used in control, type editor, and type converter\n * to produce a consistent formatted Date string.\n * @internal\n */\nexport function formatInputDate(\n inputDate: Date,\n timeDisplay?: TimeDisplay,\n customFormatter?: DateFormatter,\n alternateDateFormat?: AlternateDateFormats\n): string | undefined {\n if (customFormatter) {\n return customFormatter.formateDate(inputDate);\n }\n\n if (alternateDateFormat) {\n switch (alternateDateFormat) {\n case AlternateDateFormats.IsoDateTime:\n return inputDate.toISOString();\n case AlternateDateFormats.IsoShort:\n return inputDate.toISOString().slice(0, 10);\n case AlternateDateFormats.UtcDateTime:\n return inputDate.toUTCString().slice(5);\n case AlternateDateFormats.UtcShort:\n return inputDate.toUTCString().slice(5, 16);\n case AlternateDateFormats.UtcDateTimeWithDay:\n return inputDate.toUTCString();\n case AlternateDateFormats.UtcShortWithDay:\n return inputDate.toUTCString().slice(0, 16);\n }\n } else {\n const dateString = inputDate.toLocaleDateString(undefined, {\n day: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n });\n let timeString: string = \"\";\n\n if (timeDisplay) {\n switch (timeDisplay) {\n case TimeDisplay.H12MC:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: true,\n hour: \"2-digit\",\n minute: \"2-digit\",\n });\n break;\n case TimeDisplay.H12MSC:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: true,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n break;\n case TimeDisplay.H24M:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n });\n // istanbul ignore next\n if (timeString === \"24:00\") timeString = \"00:00\";\n break;\n case TimeDisplay.H24MS:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n // istanbul ignore next\n if (timeString === \"24:00:00\") timeString = \"00:00:00\";\n break;\n }\n }\n return timeString.length ? `${dateString}, ${timeString}` : dateString;\n }\n}\n\n/** Date input component. This component is typically used by the [[DatePickerPopupButton]] to display and edit date and time.\n * @internal\n */\nexport function DateField({\n initialDate,\n onDateChange,\n readOnly,\n dateFormatter,\n timeDisplay,\n style,\n className,\n}: DateFieldProps) {\n const initialDateRef = React.useRef(initialDate);\n const [hasBadInput, setHasBadInput] = React.useState(false);\n const [inputValue, setInputValue] = React.useState(\n formatInputDate(initialDate, timeDisplay, dateFormatter)\n );\n\n // See if new initialDate props have changed since component mounted\n React.useEffect(() => {\n // istanbul ignore else\n if (initialDate.getTime() !== initialDateRef.current.getTime()) {\n initialDateRef.current = initialDate;\n }\n setInputValue(formatInputDate(initialDate, timeDisplay, dateFormatter));\n }, [initialDate, dateFormatter, timeDisplay]);\n\n const handleInputChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setInputValue(event.currentTarget.value);\n },\n []\n );\n\n const parseDate = React.useCallback(\n (dateString: string) => {\n try {\n if (dateFormatter && dateFormatter.parseDate)\n return dateFormatter.parseDate(dateString);\n\n const newDateValue = Date.parse(dateString);\n // istanbul ignore next\n if (newDateValue) return new Date(newDateValue);\n } catch (_error) /* istanbul ignore next */ {\n Logger.logInfo(\n \"DateField\",\n `Encountered error parsing input value '${dateString}' as a date.`\n );\n return undefined;\n }\n // istanbul ignore next\n return undefined;\n },\n [dateFormatter]\n );\n\n const updateInputDate = React.useCallback(\n (dateString: string) => {\n try {\n const newDateValue = parseDate(dateString);\n if (newDateValue) {\n const newDate = new Date(newDateValue);\n onDateChange && onDateChange(newDate);\n setHasBadInput(false);\n } else {\n setHasBadInput(true);\n }\n } catch (_error) {\n // istanbul ignore next\n setHasBadInput(true);\n }\n },\n [onDateChange, parseDate]\n );\n\n const handleOnBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n updateInputDate(event.target.value);\n },\n [updateInputDate]\n );\n\n function onInputKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {\n // istanbul ignore else\n if (event.key === \"Enter\") {\n updateInputDate(event.currentTarget.value);\n event.preventDefault();\n }\n }\n const classNames = classnames(\n className,\n \"components-date-input\",\n hasBadInput && \"components-date-has-error\"\n );\n return (\n <Input\n data-testid=\"components-date-input\"\n style={style}\n className={classNames}\n onKeyDown={onInputKeyDown}\n onBlur={handleOnBlur}\n onChange={handleInputChange}\n value={inputValue}\n disabled={readOnly || (dateFormatter && !dateFormatter.parseDate)}\n size=\"small\"\n />\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeHooks.d.ts","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeHooks.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"TreeHooks.d.ts","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeHooks.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,eAAe,GAAG,SAAS,CAUpE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,SAAS,gBAAgB,EACtE,YAAY,EAAE,aAAa,EAC3B,WAAW,EAAE,eAAe,iCAM7B;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,SAAS,gBAAgB,EAC3E,YAAY,EAAE,aAAa,EAC3B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,eAAe,sCAM7B;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,mBAGhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,cAAc,SAAS,gBAAgB,EAC1E,eAAe,EAAE,CAAC,MAAM,cAAc,CAAC,GAAG,sBAAsB,oBAOjE"}
|
|
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.useTreeEventsHandler = exports.useTreeModelSource = exports.usePagedTreeNodeLoader = exports.useTreeNodeLoader = exports.useTreeModel = void 0;
|
|
11
11
|
const react_1 = require("react");
|
|
12
12
|
const core_react_1 = require("@itwin/core-react");
|
|
13
|
-
const UseRerender_1 = require("../../common/UseRerender");
|
|
14
13
|
const TreeEventHandler_1 = require("./TreeEventHandler");
|
|
15
14
|
const TreeModelSource_1 = require("./TreeModelSource");
|
|
16
15
|
const TreeNodeLoader_1 = require("./TreeNodeLoader");
|
|
@@ -21,10 +20,14 @@ const TreeNodeLoader_1 = require("./TreeNodeLoader");
|
|
|
21
20
|
* @public
|
|
22
21
|
*/
|
|
23
22
|
function useTreeModel(modelSource) {
|
|
24
|
-
const
|
|
23
|
+
const [_, setState] = (0, react_1.useState)({});
|
|
25
24
|
(0, react_1.useEffect)(() => {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const forceRender = () => setState({});
|
|
26
|
+
// force one more render when `modelSource` changes in case there were some tree model modifications
|
|
27
|
+
// before listener is added on `onModelChanged` event.
|
|
28
|
+
forceRender();
|
|
29
|
+
return modelSource.onModelChanged.addListener(forceRender);
|
|
30
|
+
}, [modelSource]);
|
|
28
31
|
return modelSource.getModel();
|
|
29
32
|
}
|
|
30
33
|
exports.useTreeModel = useTreeModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeHooks.js","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeHooks.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"TreeHooks.js","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeHooks.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,iCAAkE;AAClE,kDAAkD;AAGlD,yDAAsD;AAEtD,uDAAoD;AACpD,qDAAuE;AAEvE;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,WAA4B;IACvD,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IACnC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACvC,oGAAoG;QACpG,sDAAsD;QACtD,WAAW,EAAE,CAAC;QACd,OAAO,WAAW,CAAC,cAAc,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAC7D,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAClB,OAAO,WAAW,CAAC,QAAQ,EAAE,CAAC;AAChC,CAAC;AAVD,oCAUC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,YAA2B,EAC3B,WAA4B;IAE5B,OAAO,IAAA,eAAO,EACZ,GAAG,EAAE,CAAC,IAAI,+BAAc,CAAC,YAAY,EAAE,WAAW,CAAC,EACnD,CAAC,YAAY,EAAE,WAAW,CAAC,CAC5B,CAAC;AACJ,CAAC;AARD,8CAQC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CACpC,YAA2B,EAC3B,QAAgB,EAChB,WAA4B;IAE5B,OAAO,IAAA,eAAO,EACZ,GAAG,EAAE,CAAC,IAAI,oCAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,QAAQ,CAAC,EAClE,CAAC,YAAY,EAAE,WAAW,EAAE,QAAQ,CAAC,CACtC,CAAC;AACJ,CAAC;AATD,wDASC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,YAA8B;IAC/D,0HAA0H;IAC1H,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,IAAI,iCAAe,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,kDAAkD;AACjH,CAAC;AAHD,gDAGC;AAED;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAClC,eAAgE;IAEhE,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,GAAqB,EAAE;QACjD,IAAI,OAAO,eAAe,KAAK,UAAU;YAAE,OAAO,eAAe,EAAE,CAAC;QACpE,OAAO,IAAI,mCAAgB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IACtB,OAAO,IAAA,0BAAa,EAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AARD,oDAQC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport type { TreeDataProvider } from \"../TreeDataProvider\";\nimport type { TreeEventHandlerParams } from \"./TreeEventHandler\";\nimport { TreeEventHandler } from \"./TreeEventHandler\";\nimport type { TreeModel } from \"./TreeModel\";\nimport { TreeModelSource } from \"./TreeModelSource\";\nimport { PagedTreeNodeLoader, TreeNodeLoader } from \"./TreeNodeLoader\";\n\n/**\n * React hook that returns an immutable `TreeModel` whenever it changes in the given\n * `TreeModelSource`.\n *\n * @public\n */\nexport function useTreeModel(modelSource: TreeModelSource): TreeModel {\n const [_, setState] = useState({});\n useEffect(() => {\n const forceRender = () => setState({});\n // force one more render when `modelSource` changes in case there were some tree model modifications\n // before listener is added on `onModelChanged` event.\n forceRender();\n return modelSource.onModelChanged.addListener(forceRender);\n }, [modelSource]);\n return modelSource.getModel();\n}\n\n/**\n * Custom hook which creates a nodes' loader using the supplied data provider and model source. The\n * loader pulls nodes from the data provider and puts them into the model source.\n *\n * @public\n */\nexport function useTreeNodeLoader<TDataProvider extends TreeDataProvider>(\n dataProvider: TDataProvider,\n modelSource: TreeModelSource\n) {\n return useMemo(\n () => new TreeNodeLoader(dataProvider, modelSource),\n [dataProvider, modelSource]\n );\n}\n\n/**\n * Custom hook which creates a paging nodes' loader using the supplied data provider and model source. The loader pulls\n * nodes from the data provider and puts them into the model source.\n * @public\n */\nexport function usePagedTreeNodeLoader<TDataProvider extends TreeDataProvider>(\n dataProvider: TDataProvider,\n pageSize: number,\n modelSource: TreeModelSource\n) {\n return useMemo(\n () => new PagedTreeNodeLoader(dataProvider, modelSource, pageSize),\n [dataProvider, modelSource, pageSize]\n );\n}\n\n/**\n * Custom hook which creates a `TreeModelSource`.\n *\n * @note The model source has no direct dependency on the data provider, but we want a fresh model\n * source whenever the data provider changes - that's the reason the hook takes a data provider.\n *\n * @public\n */\nexport function useTreeModelSource(dataProvider: TreeDataProvider) {\n // need to create new model source every time data provider changes although it does not need data provider to be created.\n return useMemo(() => new TreeModelSource(), [dataProvider]); // eslint-disable-line react-hooks/exhaustive-deps\n}\n\n/**\n * Custom hook which creates and takes care of disposing a TreeEventsHandler. The input is either a factory method\n * for a custom `TreeEventHandler` implementation or parameters for the default implementation.\n *\n * @note Caller must ensure `factoryOrParams` changes only when a new handler needs to be created. `useCallback` or `useMemo` can\n * be used for that purpose based on whether the input is a factory function or params object.\n *\n * @public\n */\nexport function useTreeEventsHandler<TEventsHandler extends TreeEventHandler>(\n factoryOrParams: (() => TEventsHandler) | TreeEventHandlerParams\n) {\n const factory = useCallback((): TreeEventHandler => {\n if (typeof factoryOrParams === \"function\") return factoryOrParams();\n return new TreeEventHandler(factoryOrParams);\n }, [factoryOrParams]);\n return useDisposable(factory);\n}\n"]}
|
|
@@ -108,7 +108,7 @@ export function DateField({ initialDate, onDateChange, readOnly, dateFormatter,
|
|
|
108
108
|
if (dateFormatter && dateFormatter.parseDate)
|
|
109
109
|
return dateFormatter.parseDate(dateString);
|
|
110
110
|
const newDateValue = Date.parse(dateString);
|
|
111
|
-
// istanbul ignore
|
|
111
|
+
// istanbul ignore next
|
|
112
112
|
if (newDateValue)
|
|
113
113
|
return new Date(newDateValue);
|
|
114
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/DateField.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAmB7C;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAe,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a,CAAC,SAAS,CAAC,EACjE,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport \"./DateField.scss\";\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport type { DateFormatter } from \"@itwin/appui-abstract\";\nimport { AlternateDateFormats, TimeDisplay } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { Logger } from \"@itwin/core-bentley\";\n\n/** Props for [[DateField]] Component.\n * @internal\n */\nexport interface DateFieldProps extends CommonProps {\n /** Defines initial date and time for component. */\n initialDate: Date;\n /** Function to call when the date or time is changed. */\n onDateChange?: (day: Date) => void;\n /** Optional value to define if edit field allows editing. If a DateFormatter is provided\n * it must provide a parseData function or the field will be read only no matter the setting of this value. */\n readOnly?: boolean;\n /** Optional date formatter that produces an explicit date display */\n dateFormatter?: DateFormatter;\n /** This property has two purposes, the first is specify that the display of time is desired and the second is to define the format of the time display. */\n timeDisplay?: TimeDisplay;\n}\n\n/** Function to format a Date object that is used in control, type editor, and type converter\n * to produce a consistent formatted Date string.\n * @internal\n */\nexport function formatInputDate(\n inputDate: Date,\n timeDisplay?: TimeDisplay,\n customFormatter?: DateFormatter,\n alternateDateFormat?: AlternateDateFormats\n): string | undefined {\n if (customFormatter) {\n return customFormatter.formateDate(inputDate);\n }\n\n if (alternateDateFormat) {\n switch (alternateDateFormat) {\n case AlternateDateFormats.IsoDateTime:\n return inputDate.toISOString();\n case AlternateDateFormats.IsoShort:\n return inputDate.toISOString().slice(0, 10);\n case AlternateDateFormats.UtcDateTime:\n return inputDate.toUTCString().slice(5);\n case AlternateDateFormats.UtcShort:\n return inputDate.toUTCString().slice(5, 16);\n case AlternateDateFormats.UtcDateTimeWithDay:\n return inputDate.toUTCString();\n case AlternateDateFormats.UtcShortWithDay:\n return inputDate.toUTCString().slice(0, 16);\n }\n } else {\n const dateString = inputDate.toLocaleDateString(undefined, {\n day: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n });\n let timeString: string = \"\";\n\n if (timeDisplay) {\n switch (timeDisplay) {\n case TimeDisplay.H12MC:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: true,\n hour: \"2-digit\",\n minute: \"2-digit\",\n });\n break;\n case TimeDisplay.H12MSC:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: true,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n break;\n case TimeDisplay.H24M:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n });\n // istanbul ignore next\n if (timeString === \"24:00\") timeString = \"00:00\";\n break;\n case TimeDisplay.H24MS:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n // istanbul ignore next\n if (timeString === \"24:00:00\") timeString = \"00:00:00\";\n break;\n }\n }\n return timeString.length ? `${dateString}, ${timeString}` : dateString;\n }\n}\n\n/** Date input component. This component is typically used by the [[DatePickerPopupButton]] to display and edit date and time.\n * @internal\n */\nexport function DateField({\n initialDate,\n onDateChange,\n readOnly,\n dateFormatter,\n timeDisplay,\n style,\n className,\n}: DateFieldProps) {\n const initialDateRef = React.useRef(initialDate);\n const [hasBadInput, setHasBadInput] = React.useState(false);\n const [inputValue, setInputValue] = React.useState(\n formatInputDate(initialDate, timeDisplay, dateFormatter)\n );\n\n // See if new initialDate props have changed since component mounted\n React.useEffect(() => {\n // istanbul ignore else\n if (initialDate.getTime() !== initialDateRef.current.getTime()) {\n initialDateRef.current = initialDate;\n }\n setInputValue(formatInputDate(initialDate, timeDisplay, dateFormatter));\n }, [initialDate, dateFormatter, timeDisplay]);\n\n const handleInputChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setInputValue(event.currentTarget.value);\n },\n []\n );\n\n const parseDate = React.useCallback(\n (dateString: string) => {\n try {\n if (dateFormatter && dateFormatter.parseDate)\n return dateFormatter.parseDate(dateString);\n\n const newDateValue = Date.parse(dateString);\n // istanbul ignore else\n if (newDateValue) return new Date(newDateValue);\n } catch (_error) /* istanbul ignore next */ {\n Logger.logInfo(\n \"DateField\",\n `Encountered error parsing input value '${dateString}' as a date.`\n );\n return undefined;\n }\n // istanbul ignore next\n return undefined;\n },\n [dateFormatter]\n );\n\n const updateInputDate = React.useCallback(\n (dateString: string) => {\n try {\n const newDateValue = parseDate(dateString);\n if (newDateValue) {\n const newDate = new Date(newDateValue);\n onDateChange && onDateChange(newDate);\n setHasBadInput(false);\n } else {\n setHasBadInput(true);\n }\n } catch (_error) {\n // istanbul ignore next\n setHasBadInput(true);\n }\n },\n [onDateChange, parseDate]\n );\n\n const handleOnBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n updateInputDate(event.target.value);\n },\n [updateInputDate]\n );\n\n function onInputKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {\n // istanbul ignore else\n if (event.key === \"Enter\") {\n updateInputDate(event.currentTarget.value);\n event.preventDefault();\n }\n }\n const classNames = classnames(\n className,\n \"components-date-input\",\n hasBadInput && \"components-date-has-error\"\n );\n return (\n <Input\n data-testid=\"components-date-input\"\n style={style}\n className={classNames}\n onKeyDown={onInputKeyDown}\n onBlur={handleOnBlur}\n onChange={handleInputChange}\n value={inputValue}\n disabled={readOnly || (dateFormatter && !dateFormatter.parseDate)}\n size=\"small\"\n />\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/DateField.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAA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AAW,IAAI,2BAA2B,CAC3C,CAAC;IACF,OAAO,CACL,oBAAC,KAAK,mBACQ,uBAAuB,EACnC,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,cAAc,EACzB,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,QAAQ,IAAI,CAAC,aAAa,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EACjE,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport \"./DateField.scss\";\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport type { DateFormatter } from \"@itwin/appui-abstract\";\nimport { AlternateDateFormats, TimeDisplay } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { Logger } from \"@itwin/core-bentley\";\n\n/** Props for [[DateField]] Component.\n * @internal\n */\nexport interface DateFieldProps extends CommonProps {\n /** Defines initial date and time for component. */\n initialDate: Date;\n /** Function to call when the date or time is changed. */\n onDateChange?: (day: Date) => void;\n /** Optional value to define if edit field allows editing. If a DateFormatter is provided\n * it must provide a parseData function or the field will be read only no matter the setting of this value. */\n readOnly?: boolean;\n /** Optional date formatter that produces an explicit date display */\n dateFormatter?: DateFormatter;\n /** This property has two purposes, the first is specify that the display of time is desired and the second is to define the format of the time display. */\n timeDisplay?: TimeDisplay;\n}\n\n/** Function to format a Date object that is used in control, type editor, and type converter\n * to produce a consistent formatted Date string.\n * @internal\n */\nexport function formatInputDate(\n inputDate: Date,\n timeDisplay?: TimeDisplay,\n customFormatter?: DateFormatter,\n alternateDateFormat?: AlternateDateFormats\n): string | undefined {\n if (customFormatter) {\n return customFormatter.formateDate(inputDate);\n }\n\n if (alternateDateFormat) {\n switch (alternateDateFormat) {\n case AlternateDateFormats.IsoDateTime:\n return inputDate.toISOString();\n case AlternateDateFormats.IsoShort:\n return inputDate.toISOString().slice(0, 10);\n case AlternateDateFormats.UtcDateTime:\n return inputDate.toUTCString().slice(5);\n case AlternateDateFormats.UtcShort:\n return inputDate.toUTCString().slice(5, 16);\n case AlternateDateFormats.UtcDateTimeWithDay:\n return inputDate.toUTCString();\n case AlternateDateFormats.UtcShortWithDay:\n return inputDate.toUTCString().slice(0, 16);\n }\n } else {\n const dateString = inputDate.toLocaleDateString(undefined, {\n day: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n });\n let timeString: string = \"\";\n\n if (timeDisplay) {\n switch (timeDisplay) {\n case TimeDisplay.H12MC:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: true,\n hour: \"2-digit\",\n minute: \"2-digit\",\n });\n break;\n case TimeDisplay.H12MSC:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: true,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n break;\n case TimeDisplay.H24M:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n });\n // istanbul ignore next\n if (timeString === \"24:00\") timeString = \"00:00\";\n break;\n case TimeDisplay.H24MS:\n timeString = inputDate.toLocaleTimeString(undefined, {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n // istanbul ignore next\n if (timeString === \"24:00:00\") timeString = \"00:00:00\";\n break;\n }\n }\n return timeString.length ? `${dateString}, ${timeString}` : dateString;\n }\n}\n\n/** Date input component. This component is typically used by the [[DatePickerPopupButton]] to display and edit date and time.\n * @internal\n */\nexport function DateField({\n initialDate,\n onDateChange,\n readOnly,\n dateFormatter,\n timeDisplay,\n style,\n className,\n}: DateFieldProps) {\n const initialDateRef = React.useRef(initialDate);\n const [hasBadInput, setHasBadInput] = React.useState(false);\n const [inputValue, setInputValue] = React.useState(\n formatInputDate(initialDate, timeDisplay, dateFormatter)\n );\n\n // See if new initialDate props have changed since component mounted\n React.useEffect(() => {\n // istanbul ignore else\n if (initialDate.getTime() !== initialDateRef.current.getTime()) {\n initialDateRef.current = initialDate;\n }\n setInputValue(formatInputDate(initialDate, timeDisplay, dateFormatter));\n }, [initialDate, dateFormatter, timeDisplay]);\n\n const handleInputChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setInputValue(event.currentTarget.value);\n },\n []\n );\n\n const parseDate = React.useCallback(\n (dateString: string) => {\n try {\n if (dateFormatter && dateFormatter.parseDate)\n return dateFormatter.parseDate(dateString);\n\n const newDateValue = Date.parse(dateString);\n // istanbul ignore next\n if (newDateValue) return new Date(newDateValue);\n } catch (_error) /* istanbul ignore next */ {\n Logger.logInfo(\n \"DateField\",\n `Encountered error parsing input value '${dateString}' as a date.`\n );\n return undefined;\n }\n // istanbul ignore next\n return undefined;\n },\n [dateFormatter]\n );\n\n const updateInputDate = React.useCallback(\n (dateString: string) => {\n try {\n const newDateValue = parseDate(dateString);\n if (newDateValue) {\n const newDate = new Date(newDateValue);\n onDateChange && onDateChange(newDate);\n setHasBadInput(false);\n } else {\n setHasBadInput(true);\n }\n } catch (_error) {\n // istanbul ignore next\n setHasBadInput(true);\n }\n },\n [onDateChange, parseDate]\n );\n\n const handleOnBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n updateInputDate(event.target.value);\n },\n [updateInputDate]\n );\n\n function onInputKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {\n // istanbul ignore else\n if (event.key === \"Enter\") {\n updateInputDate(event.currentTarget.value);\n event.preventDefault();\n }\n }\n const classNames = classnames(\n className,\n \"components-date-input\",\n hasBadInput && \"components-date-has-error\"\n );\n return (\n <Input\n data-testid=\"components-date-input\"\n style={style}\n className={classNames}\n onKeyDown={onInputKeyDown}\n onBlur={handleOnBlur}\n onChange={handleInputChange}\n value={inputValue}\n disabled={readOnly || (dateFormatter && !dateFormatter.parseDate)}\n size=\"small\"\n />\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeHooks.d.ts","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeHooks.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"TreeHooks.d.ts","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeHooks.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,eAAe,GAAG,SAAS,CAUpE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,SAAS,gBAAgB,EACtE,YAAY,EAAE,aAAa,EAC3B,WAAW,EAAE,eAAe,iCAM7B;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,SAAS,gBAAgB,EAC3E,YAAY,EAAE,aAAa,EAC3B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,eAAe,sCAM7B;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,mBAGhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,cAAc,SAAS,gBAAgB,EAC1E,eAAe,EAAE,CAAC,MAAM,cAAc,CAAC,GAAG,sBAAsB,oBAOjE"}
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module Tree
|
|
7
7
|
*/
|
|
8
|
-
import { useCallback, useEffect, useMemo } from "react";
|
|
8
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
9
9
|
import { useDisposable } from "@itwin/core-react";
|
|
10
|
-
import { useRerender } from "../../common/UseRerender";
|
|
11
10
|
import { TreeEventHandler } from "./TreeEventHandler";
|
|
12
11
|
import { TreeModelSource } from "./TreeModelSource";
|
|
13
12
|
import { PagedTreeNodeLoader, TreeNodeLoader } from "./TreeNodeLoader";
|
|
@@ -18,10 +17,14 @@ import { PagedTreeNodeLoader, TreeNodeLoader } from "./TreeNodeLoader";
|
|
|
18
17
|
* @public
|
|
19
18
|
*/
|
|
20
19
|
export function useTreeModel(modelSource) {
|
|
21
|
-
const
|
|
20
|
+
const [_, setState] = useState({});
|
|
22
21
|
useEffect(() => {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const forceRender = () => setState({});
|
|
23
|
+
// force one more render when `modelSource` changes in case there were some tree model modifications
|
|
24
|
+
// before listener is added on `onModelChanged` event.
|
|
25
|
+
forceRender();
|
|
26
|
+
return modelSource.onModelChanged.addListener(forceRender);
|
|
27
|
+
}, [modelSource]);
|
|
25
28
|
return modelSource.getModel();
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeHooks.js","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeHooks.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"TreeHooks.js","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeHooks.ts"],"names":[],"mappings":"AAAA;;;gGAG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ACtC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAA8B;IAC/D,0HAA0H;IAC1H,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,eAAe,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,kDAAkD;AACjH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,eAAgE;IAEhE,MAAM,OAAO,GAAG,WAAW,CAAC,GAAqB,EAAE;QACjD,IAAI,OAAO,eAAe,KAAK,UAAU;YAAE,OAAO,eAAe,EAAE,CAAC;QACpE,OAAO,IAAI,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IACtB,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport type { TreeDataProvider } from \"../TreeDataProvider\";\nimport type { TreeEventHandlerParams } from \"./TreeEventHandler\";\nimport { TreeEventHandler } from \"./TreeEventHandler\";\nimport type { TreeModel } from \"./TreeModel\";\nimport { TreeModelSource } from \"./TreeModelSource\";\nimport { PagedTreeNodeLoader, TreeNodeLoader } from \"./TreeNodeLoader\";\n\n/**\n * React hook that returns an immutable `TreeModel` whenever it changes in the given\n * `TreeModelSource`.\n *\n * @public\n */\nexport function useTreeModel(modelSource: TreeModelSource): TreeModel {\n const [_, setState] = useState({});\n useEffect(() => {\n const forceRender = () => setState({});\n // force one more render when `modelSource` changes in case there were some tree model modifications\n // before listener is added on `onModelChanged` event.\n forceRender();\n return modelSource.onModelChanged.addListener(forceRender);\n }, [modelSource]);\n return modelSource.getModel();\n}\n\n/**\n * Custom hook which creates a nodes' loader using the supplied data provider and model source. The\n * loader pulls nodes from the data provider and puts them into the model source.\n *\n * @public\n */\nexport function useTreeNodeLoader<TDataProvider extends TreeDataProvider>(\n dataProvider: TDataProvider,\n modelSource: TreeModelSource\n) {\n return useMemo(\n () => new TreeNodeLoader(dataProvider, modelSource),\n [dataProvider, modelSource]\n );\n}\n\n/**\n * Custom hook which creates a paging nodes' loader using the supplied data provider and model source. The loader pulls\n * nodes from the data provider and puts them into the model source.\n * @public\n */\nexport function usePagedTreeNodeLoader<TDataProvider extends TreeDataProvider>(\n dataProvider: TDataProvider,\n pageSize: number,\n modelSource: TreeModelSource\n) {\n return useMemo(\n () => new PagedTreeNodeLoader(dataProvider, modelSource, pageSize),\n [dataProvider, modelSource, pageSize]\n );\n}\n\n/**\n * Custom hook which creates a `TreeModelSource`.\n *\n * @note The model source has no direct dependency on the data provider, but we want a fresh model\n * source whenever the data provider changes - that's the reason the hook takes a data provider.\n *\n * @public\n */\nexport function useTreeModelSource(dataProvider: TreeDataProvider) {\n // need to create new model source every time data provider changes although it does not need data provider to be created.\n return useMemo(() => new TreeModelSource(), [dataProvider]); // eslint-disable-line react-hooks/exhaustive-deps\n}\n\n/**\n * Custom hook which creates and takes care of disposing a TreeEventsHandler. The input is either a factory method\n * for a custom `TreeEventHandler` implementation or parameters for the default implementation.\n *\n * @note Caller must ensure `factoryOrParams` changes only when a new handler needs to be created. `useCallback` or `useMemo` can\n * be used for that purpose based on whether the input is a factory function or params object.\n *\n * @public\n */\nexport function useTreeEventsHandler<TEventsHandler extends TreeEventHandler>(\n factoryOrParams: (() => TEventsHandler) | TreeEventHandlerParams\n) {\n const factory = useCallback((): TreeEventHandler => {\n if (typeof factoryOrParams === \"function\") return factoryOrParams();\n return new TreeEventHandler(factoryOrParams);\n }, [factoryOrParams]);\n return useDisposable(factory);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/components-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.1",
|
|
4
4
|
"description": "iTwin.js UI complex components",
|
|
5
5
|
"main": "lib/cjs/components-react.js",
|
|
6
6
|
"module": "lib/esm/components-react.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@itwin/appui-abstract": "^3.7.0 || ^4.0.0",
|
|
26
26
|
"@itwin/core-bentley": "^3.7.0 || ^4.0.0",
|
|
27
|
-
"@itwin/core-react": "^4.
|
|
27
|
+
"@itwin/core-react": "^4.6.1",
|
|
28
28
|
"react": "^17.0.0 || ^18.0.0",
|
|
29
29
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
30
30
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@itwin/core-common": "^3.7.0",
|
|
40
40
|
"@itwin/core-geometry": "^3.7.0",
|
|
41
41
|
"@itwin/core-i18n": "^3.7.0",
|
|
42
|
-
"@itwin/core-react": "4.
|
|
42
|
+
"@itwin/core-react": "4.6.1",
|
|
43
43
|
"@itwin/eslint-plugin": "^4.0.0-dev.45",
|
|
44
44
|
"@testing-library/dom": "^8.11.2",
|
|
45
45
|
"@testing-library/react": "^12.0.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@types/react-window": "^1.8.2",
|
|
61
61
|
"@types/sinon": "^10.0.15",
|
|
62
62
|
"@types/sinon-chai": "^3.2.0",
|
|
63
|
-
"chai": "^4.
|
|
63
|
+
"chai": "^4.3.10",
|
|
64
64
|
"chai-as-promised": "^7",
|
|
65
65
|
"chai-string": "^1.5.0",
|
|
66
66
|
"chai-subset": "1.6.0",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/** @internal */
|
|
2
|
-
interface RerenderData<T extends (arg: any) => void> {
|
|
3
|
-
/** Data specific to the current rerender cycle. */
|
|
4
|
-
rerenderContext: Parameters<T>[0];
|
|
5
|
-
/** Identifies the current rerender cycle. Starts at 0. */
|
|
6
|
-
numRerenders: number;
|
|
7
|
-
/** Rerenders component with new `rerenderContext`, if one is provided. */
|
|
8
|
-
rerender: T;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
* Makes component able to rerender itself.
|
|
13
|
-
*/
|
|
14
|
-
export declare function useRerender(): RerenderData<() => void>;
|
|
15
|
-
/**
|
|
16
|
-
* @internal
|
|
17
|
-
* Makes component able to rerender itself while preserving some data between rerenders.
|
|
18
|
-
* @param initialContext Data that component receives on first render cycle.
|
|
19
|
-
*/
|
|
20
|
-
export declare function useRerender<T>(initialContext: T): RerenderData<(newContext: T) => void>;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=UseRerender.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UseRerender.d.ts","sourceRoot":"","sources":["../../../../src/components-react/common/UseRerender.ts"],"names":[],"mappings":"AAOA,gBAAgB;AAChB,UAAU,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI;IACjD,mDAAmD;IACnD,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,QAAQ,EAAE,CAAC,CAAC;CACb;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,CAAC;AACxD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,cAAc,EAAE,CAAC,GAChB,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.useRerender = void 0;
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
/** @internal */
|
|
10
|
-
function useRerender(initialContext) {
|
|
11
|
-
const data = (0, react_1.useRef)({
|
|
12
|
-
numRerenders: 0,
|
|
13
|
-
rerenderRequested: false,
|
|
14
|
-
context: initialContext,
|
|
15
|
-
}).current;
|
|
16
|
-
if (data.rerenderRequested) {
|
|
17
|
-
data.numRerenders += 1;
|
|
18
|
-
data.rerenderRequested = false;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
data.context = initialContext;
|
|
22
|
-
data.numRerenders = 0;
|
|
23
|
-
}
|
|
24
|
-
const [_, setState] = (0, react_1.useState)({});
|
|
25
|
-
return {
|
|
26
|
-
rerenderContext: data.context,
|
|
27
|
-
numRerenders: data.numRerenders,
|
|
28
|
-
rerender: (newContext) => {
|
|
29
|
-
data.rerenderRequested = true;
|
|
30
|
-
data.context = newContext;
|
|
31
|
-
setState({});
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
exports.useRerender = useRerender;
|
|
36
|
-
//# sourceMappingURL=UseRerender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UseRerender.js","sourceRoot":"","sources":["../../../../src/components-react/common/UseRerender.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iCAAyC;AAyBzC,gBAAgB;AAChB,SAAgB,WAAW,CACzB,cAAkB;IAElB,MAAM,IAAI,GAAG,IAAA,cAAM,EAAC;QAClB,YAAY,EAAE,CAAC;QACf,iBAAiB,EAAE,KAAK;QACxB,OAAO,EAAE,cAAc;KACxB,CAAC,CAAC,OAAO,CAAC;IACX,IAAI,IAAI,CAAC,iBAAiB,EAAE;QAC1B,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;KAChC;SAAM;QACL,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;KACvB;IAED,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IACnC,OAAO;QACL,eAAe,EAAE,IAAI,CAAC,OAAO;QAC7B,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,QAAQ,EAAE,CAAC,UAAU,EAAE,EAAE;YACvB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;YAC9B,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC;YAC1B,QAAQ,CAAC,EAAE,CAAC,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC;AA1BD,kCA0BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useRef, useState } from \"react\";\n\n/** @internal */\ninterface RerenderData<T extends (arg: any) => void> {\n /** Data specific to the current rerender cycle. */\n rerenderContext: Parameters<T>[0];\n /** Identifies the current rerender cycle. Starts at 0. */\n numRerenders: number;\n /** Rerenders component with new `rerenderContext`, if one is provided. */\n rerender: T;\n}\n\n/**\n * @internal\n * Makes component able to rerender itself.\n */\nexport function useRerender(): RerenderData<() => void>;\n/**\n * @internal\n * Makes component able to rerender itself while preserving some data between rerenders.\n * @param initialContext Data that component receives on first render cycle.\n */\nexport function useRerender<T>(\n initialContext: T\n): RerenderData<(newContext: T) => void>;\n/** @internal */\nexport function useRerender<T>(\n initialContext?: T\n): RerenderData<(newContext?: T) => void> {\n const data = useRef({\n numRerenders: 0,\n rerenderRequested: false,\n context: initialContext,\n }).current;\n if (data.rerenderRequested) {\n data.numRerenders += 1;\n data.rerenderRequested = false;\n } else {\n data.context = initialContext;\n data.numRerenders = 0;\n }\n\n const [_, setState] = useState({});\n return {\n rerenderContext: data.context,\n numRerenders: data.numRerenders,\n rerender: (newContext) => {\n data.rerenderRequested = true;\n data.context = newContext;\n setState({});\n },\n };\n}\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/** @internal */
|
|
2
|
-
interface RerenderData<T extends (arg: any) => void> {
|
|
3
|
-
/** Data specific to the current rerender cycle. */
|
|
4
|
-
rerenderContext: Parameters<T>[0];
|
|
5
|
-
/** Identifies the current rerender cycle. Starts at 0. */
|
|
6
|
-
numRerenders: number;
|
|
7
|
-
/** Rerenders component with new `rerenderContext`, if one is provided. */
|
|
8
|
-
rerender: T;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
* Makes component able to rerender itself.
|
|
13
|
-
*/
|
|
14
|
-
export declare function useRerender(): RerenderData<() => void>;
|
|
15
|
-
/**
|
|
16
|
-
* @internal
|
|
17
|
-
* Makes component able to rerender itself while preserving some data between rerenders.
|
|
18
|
-
* @param initialContext Data that component receives on first render cycle.
|
|
19
|
-
*/
|
|
20
|
-
export declare function useRerender<T>(initialContext: T): RerenderData<(newContext: T) => void>;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=UseRerender.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UseRerender.d.ts","sourceRoot":"","sources":["../../../../src/components-react/common/UseRerender.ts"],"names":[],"mappings":"AAOA,gBAAgB;AAChB,UAAU,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI;IACjD,mDAAmD;IACnD,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,QAAQ,EAAE,CAAC,CAAC;CACb;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,CAAC;AACxD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,cAAc,EAAE,CAAC,GAChB,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import { useRef, useState } from "react";
|
|
6
|
-
/** @internal */
|
|
7
|
-
export function useRerender(initialContext) {
|
|
8
|
-
const data = useRef({
|
|
9
|
-
numRerenders: 0,
|
|
10
|
-
rerenderRequested: false,
|
|
11
|
-
context: initialContext,
|
|
12
|
-
}).current;
|
|
13
|
-
if (data.rerenderRequested) {
|
|
14
|
-
data.numRerenders += 1;
|
|
15
|
-
data.rerenderRequested = false;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
data.context = initialContext;
|
|
19
|
-
data.numRerenders = 0;
|
|
20
|
-
}
|
|
21
|
-
const [_, setState] = useState({});
|
|
22
|
-
return {
|
|
23
|
-
rerenderContext: data.context,
|
|
24
|
-
numRerenders: data.numRerenders,
|
|
25
|
-
rerender: (newContext) => {
|
|
26
|
-
data.rerenderRequested = true;
|
|
27
|
-
data.context = newContext;
|
|
28
|
-
setState({});
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=UseRerender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UseRerender.js","sourceRoot":"","sources":["../../../../src/components-react/common/UseRerender.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAyBzC,gBAAgB;AAChB,MAAM,UAAU,WAAW,CACzB,cAAkB;IAElB,MAAM,IAAI,GAAG,MAAM,CAAC;QAClB,YAAY,EAAE,CAAC;QACf,iBAAiB,EAAE,KAAK;QACxB,OAAO,EAAE,cAAc;KACxB,CAAC,CAAC,OAAO,CAAC;IACX,IAAI,IAAI,CAAC,iBAAiB,EAAE;QAC1B,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;KAChC;SAAM;QACL,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;KACvB;IAED,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnC,OAAO;QACL,eAAe,EAAE,IAAI,CAAC,OAAO;QAC7B,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,QAAQ,EAAE,CAAC,UAAU,EAAE,EAAE;YACvB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;YAC9B,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC;YAC1B,QAAQ,CAAC,EAAE,CAAC,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useRef, useState } from \"react\";\n\n/** @internal */\ninterface RerenderData<T extends (arg: any) => void> {\n /** Data specific to the current rerender cycle. */\n rerenderContext: Parameters<T>[0];\n /** Identifies the current rerender cycle. Starts at 0. */\n numRerenders: number;\n /** Rerenders component with new `rerenderContext`, if one is provided. */\n rerender: T;\n}\n\n/**\n * @internal\n * Makes component able to rerender itself.\n */\nexport function useRerender(): RerenderData<() => void>;\n/**\n * @internal\n * Makes component able to rerender itself while preserving some data between rerenders.\n * @param initialContext Data that component receives on first render cycle.\n */\nexport function useRerender<T>(\n initialContext: T\n): RerenderData<(newContext: T) => void>;\n/** @internal */\nexport function useRerender<T>(\n initialContext?: T\n): RerenderData<(newContext?: T) => void> {\n const data = useRef({\n numRerenders: 0,\n rerenderRequested: false,\n context: initialContext,\n }).current;\n if (data.rerenderRequested) {\n data.numRerenders += 1;\n data.rerenderRequested = false;\n } else {\n data.context = initialContext;\n data.numRerenders = 0;\n }\n\n const [_, setState] = useState({});\n return {\n rerenderContext: data.context,\n numRerenders: data.numRerenders,\n rerender: (newContext) => {\n data.rerenderRequested = true;\n data.context = newContext;\n setState({});\n },\n };\n}\n"]}
|