uiconfig-blueprint 0.1.0-dev.8 → 0.1.0-dev.9

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.
Files changed (102) hide show
  1. package/dist/ConfigObject.d.ts +2 -1
  2. package/dist/{allPaths-CaVZ3prc.js → allPaths-C4QHVET-.js} +5 -5
  3. package/dist/{allPaths-CaVZ3prc.js.map → allPaths-C4QHVET-.js.map} +1 -1
  4. package/dist/{allPathsLoader-DqAkPjCt.js → allPathsLoader-Dm-MlOxQ.js} +4 -4
  5. package/dist/{allPathsLoader-DqAkPjCt.js.map → allPathsLoader-Dm-MlOxQ.js.map} +1 -1
  6. package/dist/bpComponents/BPContainerComponent.d.ts +1 -1
  7. package/dist/bpComponents/BPNumberInputComponent.d.ts +3 -1
  8. package/dist/bpComponents/BPSliderInputComponent.d.ts +1 -0
  9. package/dist/bpComponents/BPTreeComponent.d.ts +1 -1
  10. package/dist/bpComponents/BPVectorInputComponent.d.ts +1 -0
  11. package/dist/bpComponents/GetNumberTransformFunctions.d.ts +4 -0
  12. package/dist/bpComponents/NumberUnits.d.ts +7 -0
  13. package/dist/components/ExtendedNumericInput.d.ts +13 -3
  14. package/dist/components/NumericInput.d.ts +79 -0
  15. package/dist/components/bpIconWrapper.d.ts +1 -1
  16. package/dist/{index-CdVGBTp6.js → index-2Z2Mq97s.js} +4906 -4699
  17. package/dist/index-2Z2Mq97s.js.map +1 -0
  18. package/dist/{index-CdK1RFUj.js → index-BKXNXgJi.js} +2 -2
  19. package/dist/{index-CdK1RFUj.js.map → index-BKXNXgJi.js.map} +1 -1
  20. package/dist/{index-Ut14H6M3.js → index-BVSBMJ4w.js} +2 -2
  21. package/dist/{index-Ut14H6M3.js.map → index-BVSBMJ4w.js.map} +1 -1
  22. package/dist/index.js +17 -17
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +2 -2
  25. package/dist/lib.d.ts +3 -0
  26. package/dist/{splitPathsBySizeLoader-D0hMznHW.js → splitPathsBySizeLoader-CJaJimKZ.js} +5 -5
  27. package/dist/{splitPathsBySizeLoader-D0hMznHW.js.map → splitPathsBySizeLoader-CJaJimKZ.js.map} +1 -1
  28. package/docs/classes/UI.html +3 -3
  29. package/docs/classes/UiConfigRendererBlueprint.html +3 -3
  30. package/lib/css/renderer.css +76 -1
  31. package/lib/css/renderer.css.map +1 -1
  32. package/lib/esm/ConfigObject.d.ts +2 -1
  33. package/lib/esm/ConfigObject.js +5 -4
  34. package/lib/esm/ConfigObject.js.map +1 -1
  35. package/lib/esm/bpComponents/BPContainerComponent.d.ts +1 -1
  36. package/lib/esm/bpComponents/BPContainerComponent.js +11 -1
  37. package/lib/esm/bpComponents/BPContainerComponent.js.map +1 -1
  38. package/lib/esm/bpComponents/BPFolderComponent.js +2 -2
  39. package/lib/esm/bpComponents/BPFolderComponent.js.map +1 -1
  40. package/lib/esm/bpComponents/BPNumberInputComponent.d.ts +3 -1
  41. package/lib/esm/bpComponents/BPNumberInputComponent.js +6 -1
  42. package/lib/esm/bpComponents/BPNumberInputComponent.js.map +1 -1
  43. package/lib/esm/bpComponents/BPSliderInputComponent.d.ts +1 -0
  44. package/lib/esm/bpComponents/BPSliderInputComponent.js +16 -15
  45. package/lib/esm/bpComponents/BPSliderInputComponent.js.map +1 -1
  46. package/lib/esm/bpComponents/BPTreeComponent.d.ts +1 -1
  47. package/lib/esm/bpComponents/BPTreeComponent.js +11 -7
  48. package/lib/esm/bpComponents/BPTreeComponent.js.map +1 -1
  49. package/lib/esm/bpComponents/BPVectorInputComponent.d.ts +1 -0
  50. package/lib/esm/bpComponents/BPVectorInputComponent.js +14 -8
  51. package/lib/esm/bpComponents/BPVectorInputComponent.js.map +1 -1
  52. package/lib/esm/bpComponents/GetNumberTransformFunctions.d.ts +4 -0
  53. package/lib/esm/bpComponents/GetNumberTransformFunctions.js +14 -0
  54. package/lib/esm/bpComponents/GetNumberTransformFunctions.js.map +1 -0
  55. package/lib/esm/bpComponents/NumberUnits.d.ts +7 -0
  56. package/lib/esm/bpComponents/NumberUnits.js +101 -0
  57. package/lib/esm/bpComponents/NumberUnits.js.map +1 -0
  58. package/lib/esm/components/DialogContext.js +12 -3
  59. package/lib/esm/components/DialogContext.js.map +1 -1
  60. package/lib/esm/components/ExtendedNumericInput.d.ts +13 -3
  61. package/lib/esm/components/ExtendedNumericInput.js +62 -17
  62. package/lib/esm/components/ExtendedNumericInput.js.map +1 -1
  63. package/lib/esm/components/NumericInput.d.ts +79 -0
  64. package/lib/esm/components/NumericInput.js +311 -0
  65. package/lib/esm/components/NumericInput.js.map +1 -0
  66. package/lib/esm/components/Tree2.js +2 -2
  67. package/lib/esm/components/Tree2.js.map +1 -1
  68. package/lib/esm/components/TreeNode2.js +2 -2
  69. package/lib/esm/components/TreeNode2.js.map +1 -1
  70. package/lib/esm/components/VisualStyleContext.js +7 -1
  71. package/lib/esm/components/VisualStyleContext.js.map +1 -1
  72. package/lib/esm/components/bpIconWrapper.d.ts +1 -1
  73. package/lib/esm/components/bpIconWrapper.js +2 -2
  74. package/lib/esm/components/bpIconWrapper.js.map +1 -1
  75. package/lib/esm/components/iconMapping.js +1 -1
  76. package/lib/esm/components/iconMapping.js.map +1 -1
  77. package/lib/esm/lib.d.ts +3 -0
  78. package/lib/esm/lib.js +3 -0
  79. package/lib/esm/lib.js.map +1 -1
  80. package/package.json +1 -1
  81. package/src/ConfigObject.tsx +8 -6
  82. package/src/bpComponents/BPButtonComponent.scss +3 -1
  83. package/src/bpComponents/BPContainerComponent.tsx +11 -0
  84. package/src/bpComponents/BPFolderComponent.tsx +2 -2
  85. package/src/bpComponents/BPNumberInputComponent.tsx +13 -2
  86. package/src/bpComponents/BPSliderInputComponent.tsx +37 -29
  87. package/src/bpComponents/BPTreeComponent.tsx +14 -8
  88. package/src/bpComponents/BPVectorInputComponent.tsx +23 -20
  89. package/src/bpComponents/GetNumberTransformFunctions.tsx +14 -0
  90. package/src/bpComponents/NumberUnits.tsx +123 -0
  91. package/src/components/DialogContext.tsx +16 -2
  92. package/src/components/ExtendedNumericInput.tsx +70 -19
  93. package/src/components/NumericInput.tsx +679 -0
  94. package/src/components/Tree2.tsx +3 -3
  95. package/src/components/TreeNode2.tsx +2 -2
  96. package/src/components/VisualStyleContext.tsx +8 -0
  97. package/src/components/bpIconWrapper.tsx +2 -2
  98. package/src/components/iconMapping.ts +1 -1
  99. package/src/components/tree2.scss +27 -0
  100. package/src/lib.ts +3 -0
  101. package/src/renderer.scss +19 -0
  102. package/dist/index-CdVGBTp6.js.map +0 -1
@@ -0,0 +1,679 @@
1
+ /*
2
+ * Copyright 2017 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import classNames from "classnames";
18
+ import * as React from "react";
19
+
20
+ import {ChevronDown, ChevronUp} from "@blueprintjs/icons";
21
+
22
+ import {
23
+ AbstractPureComponent,
24
+ Button,
25
+ ButtonGroup,
26
+ Classes,
27
+ ControlGroup,
28
+ DISPLAYNAME_PREFIX,
29
+ type HTMLInputProps,
30
+ InputGroup,
31
+ Intent,
32
+ Position,
33
+ refHandler,
34
+ removeNonHTMLProps,
35
+ setRef,
36
+ Utils,
37
+ } from "@blueprintjs/core";
38
+ import * as Errors from "@blueprintjs/core/src/common/errors";
39
+ import type {InputSharedProps} from "@blueprintjs/core/src/components/forms/inputSharedProps";
40
+ import {
41
+ clampValue,
42
+ getValueOrEmptyValue,
43
+ isValidNumericKeyboardEvent,
44
+ isValueNumeric,
45
+ parseStringToStringNumber,
46
+ sanitizeNumericInput,
47
+ toLocaleString,
48
+ toMaxPrecision,
49
+ } from "@blueprintjs/core/src/components/forms/numericInputUtils";
50
+
51
+ export interface NumericInputProps extends InputSharedProps {
52
+ /**
53
+ * Whether to allow only floating-point number characters in the field,
54
+ * mimicking the native `input[type="number"]`.
55
+ *
56
+ * @default true
57
+ */
58
+ allowNumericCharactersOnly?: boolean;
59
+
60
+ /**
61
+ * Set this to `true` if you will be controlling the `value` of this input with asynchronous updates.
62
+ * These may occur if you do not immediately call setState in a parent component with the value from
63
+ * the `onChange` handler.
64
+ */
65
+ asyncControl?: boolean;
66
+
67
+ /**
68
+ * The position of the buttons with respect to the input field.
69
+ *
70
+ * @default Position.RIGHT
71
+ */
72
+ buttonPosition?: typeof Position.LEFT | typeof Position.RIGHT | "none";
73
+
74
+ /**
75
+ * Whether the value should be clamped to `[min, max]` on blur.
76
+ * The value will be clamped to each bound only if the bound is defined.
77
+ * Note that native `input[type="number"]` controls do *NOT* clamp on blur.
78
+ *
79
+ * @default false
80
+ */
81
+ clampValueOnBlur?: boolean;
82
+
83
+ /**
84
+ * In uncontrolled mode, this sets the default value of the input.
85
+ * Note that this value is only used upon component instantiation and changes to this prop
86
+ * during the component lifecycle will be ignored.
87
+ *
88
+ * @default ""
89
+ */
90
+ defaultValue?: number | string;
91
+ /**
92
+ * If set to `true`, the input will display with larger styling.
93
+ * This is equivalent to setting `Classes.LARGE` via className on the
94
+ * parent control group and on the child input group.
95
+ *
96
+ * @default false
97
+ */
98
+ large?: boolean;
99
+
100
+ /**
101
+ * The locale name, which is passed to the component to format the number and allowing to type the number in the specific locale.
102
+ * [See MDN documentation for more info about browser locale identification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
103
+ *
104
+ * @default ""
105
+ */
106
+ locale?: string;
107
+
108
+ /**
109
+ * The increment between successive values when <kbd>shift</kbd> is held.
110
+ * Pass explicit `null` value to disable this interaction.
111
+ *
112
+ * @default 10
113
+ */
114
+ majorStepSize?: number | null;
115
+
116
+ /** The maximum value of the input. */
117
+ max?: number;
118
+
119
+ /** The minimum value of the input. */
120
+ min?: number;
121
+
122
+ /**
123
+ * The increment between successive values when <kbd>alt</kbd> is held.
124
+ * Pass explicit `null` value to disable this interaction.
125
+ *
126
+ * @default 0.1
127
+ */
128
+ minorStepSize?: number | null;
129
+
130
+ /**
131
+ * Whether the entire text field should be selected on focus.
132
+ *
133
+ * @default false
134
+ */
135
+ selectAllOnFocus?: boolean;
136
+
137
+ /**
138
+ * Whether the entire text field should be selected on increment.
139
+ *
140
+ * @default false
141
+ */
142
+ selectAllOnIncrement?: boolean;
143
+
144
+ /**
145
+ * If set to `true`, the input will display with smaller styling.
146
+ * This is equivalent to setting `Classes.SMALL` via className on the
147
+ * parent control group and on the child input group.
148
+ *
149
+ * @default false
150
+ */
151
+ small?: boolean;
152
+
153
+ /**
154
+ * The increment between successive values when no modifier keys are held.
155
+ *
156
+ * @default 1
157
+ */
158
+ stepSize?: number;
159
+
160
+ /**
161
+ * The value to display in the input field.
162
+ */
163
+ value?: number | string;
164
+
165
+ /** The callback invoked when the value changes due to a button click. */
166
+ onButtonClick?(valueAsNumber: number, valueAsString: string): void;
167
+
168
+ /** The callback invoked when the value changes due to typing, arrow keys, or button clicks. */
169
+ onValueChange?(valueAsNumber: number, valueAsString: string, inputElement: HTMLInputElement | null): void;
170
+ }
171
+
172
+ export interface NumericInputState {
173
+ currentImeInputInvalid: boolean;
174
+ prevMinProp?: number;
175
+ prevMaxProp?: number;
176
+ shouldSelectAfterUpdate: boolean;
177
+ stepMaxPrecision: number;
178
+ value: string;
179
+ }
180
+
181
+ enum IncrementDirection {
182
+ DOWN = -1,
183
+ UP = +1,
184
+ }
185
+
186
+ const NON_HTML_PROPS: Array<keyof NumericInputProps> = [
187
+ "allowNumericCharactersOnly",
188
+ "buttonPosition",
189
+ "clampValueOnBlur",
190
+ "className",
191
+ "defaultValue",
192
+ "majorStepSize",
193
+ "minorStepSize",
194
+ "onButtonClick",
195
+ "onValueChange",
196
+ "selectAllOnFocus",
197
+ "selectAllOnIncrement",
198
+ "stepSize",
199
+ ];
200
+
201
+ type ButtonEventHandlers = Required<Pick<React.HTMLAttributes<HTMLElement>, "onKeyDown" | "onMouseDown">>;
202
+
203
+ /**
204
+ * Numeric input component.
205
+ *
206
+ * @see https://blueprintjs.com/docs/#core/components/numeric-input
207
+ */
208
+ export class NumericInput extends AbstractPureComponent<HTMLInputProps & NumericInputProps, NumericInputState> {
209
+ public static displayName = `${DISPLAYNAME_PREFIX}.NumericInput`;
210
+
211
+ public static VALUE_EMPTY = "";
212
+
213
+ public static VALUE_ZERO = "0";
214
+
215
+ private numericInputId = Utils.uniqueId("numericInput");
216
+
217
+ public static defaultProps: NumericInputProps = {
218
+ allowNumericCharactersOnly: true,
219
+ buttonPosition: Position.RIGHT,
220
+ clampValueOnBlur: false,
221
+ defaultValue: NumericInput.VALUE_EMPTY,
222
+ large: false,
223
+ majorStepSize: 10,
224
+ minorStepSize: 0.1,
225
+ selectAllOnFocus: false,
226
+ selectAllOnIncrement: false,
227
+ small: false,
228
+ stepSize: 1,
229
+ };
230
+
231
+ public static getDerivedStateFromProps(props: NumericInputProps, state: NumericInputState) {
232
+ const nextState = {
233
+ prevMaxProp: props.max,
234
+ prevMinProp: props.min,
235
+ };
236
+
237
+ const didMinChange = props.min !== state.prevMinProp;
238
+ const didMaxChange = props.max !== state.prevMaxProp;
239
+ const didBoundsChange = didMinChange || didMaxChange;
240
+
241
+ // in controlled mode, use props.value
242
+ // in uncontrolled mode, if state.value has not been assigned yet (upon initial mount), use props.defaultValue
243
+ const value = props.value?.toString() ?? state.value;
244
+ const stepMaxPrecision = NumericInput.getStepMaxPrecision(props);
245
+
246
+ const sanitizedValue =
247
+ value !== NumericInput.VALUE_EMPTY
248
+ ? NumericInput.roundAndClampValue(value, stepMaxPrecision, props.min, props.max, 0, props.locale)
249
+ : NumericInput.VALUE_EMPTY;
250
+
251
+ // if a new min and max were provided that cause the existing value to fall
252
+ // outside of the new bounds, then clamp the value to the new valid range.
253
+ if (didBoundsChange && sanitizedValue !== state.value) {
254
+ return { ...nextState, stepMaxPrecision, value: sanitizedValue };
255
+ }
256
+ return { ...nextState, stepMaxPrecision, value };
257
+ }
258
+
259
+ private static CONTINUOUS_CHANGE_DELAY = 300;
260
+
261
+ private static CONTINUOUS_CHANGE_INTERVAL = 100;
262
+
263
+ // Value Helpers
264
+ // =============
265
+ private static getStepMaxPrecision(props: HTMLInputProps & NumericInputProps) {
266
+ if (props.minorStepSize != null) {
267
+ return Utils.countDecimalPlaces(props.minorStepSize);
268
+ } else {
269
+ return Utils.countDecimalPlaces(props.stepSize!);
270
+ }
271
+ }
272
+
273
+ private static roundAndClampValue(
274
+ value: string,
275
+ stepMaxPrecision: number,
276
+ min: number | undefined,
277
+ max: number | undefined,
278
+ delta = 0,
279
+ locale: string | undefined,
280
+ ) {
281
+ if (!isValueNumeric(value, locale)) {
282
+ return NumericInput.VALUE_EMPTY;
283
+ }
284
+ const currentValue = parseStringToStringNumber(value, locale);
285
+ const nextValue = toMaxPrecision(Number(currentValue) + delta, stepMaxPrecision);
286
+ const clampedValue = clampValue(nextValue, min, max);
287
+ return toLocaleString(clampedValue, locale);
288
+ }
289
+
290
+ public state: NumericInputState = {
291
+ currentImeInputInvalid: false,
292
+ shouldSelectAfterUpdate: false,
293
+ stepMaxPrecision: NumericInput.getStepMaxPrecision(this.props),
294
+ value: getValueOrEmptyValue(this.props.value ?? this.props.defaultValue),
295
+ };
296
+
297
+ // updating these flags need not trigger re-renders, so don't include them in this.state.
298
+ private didPasteEventJustOccur = false;
299
+
300
+ private delta = 0;
301
+
302
+ public inputElement: HTMLInputElement | null = null;
303
+
304
+ private inputRef: React.Ref<HTMLInputElement> = refHandler(this, "inputElement", this.props.inputRef);
305
+
306
+ private intervalId?: number;
307
+
308
+ private incrementButtonHandlers = this.getButtonEventHandlers(IncrementDirection.UP);
309
+
310
+ private decrementButtonHandlers = this.getButtonEventHandlers(IncrementDirection.DOWN);
311
+
312
+ private getCurrentValueAsNumber = () => Number(parseStringToStringNumber(this.state.value, this.props.locale));
313
+
314
+ public render() {
315
+ const { buttonPosition, className, fill, large, small } = this.props;
316
+ const containerClasses = classNames(
317
+ Classes.NUMERIC_INPUT,
318
+ { [Classes.LARGE]: large, [Classes.SMALL]: small },
319
+ className,
320
+ );
321
+ const buttons = this.renderButtons();
322
+ return (
323
+ <ControlGroup className={containerClasses} fill={fill}>
324
+ {buttonPosition === Position.LEFT && buttons}
325
+ {this.renderInput()}
326
+ {buttonPosition === Position.RIGHT && buttons}
327
+ </ControlGroup>
328
+ );
329
+ }
330
+
331
+ public componentDidUpdate(prevProps: NumericInputProps, prevState: NumericInputState) {
332
+ super.componentDidUpdate(prevProps, prevState);
333
+
334
+ if (prevProps.inputRef !== this.props.inputRef) {
335
+ setRef(prevProps.inputRef, null);
336
+ this.inputRef = refHandler(this, "inputElement", this.props.inputRef);
337
+ setRef(this.props.inputRef, this.inputElement);
338
+ }
339
+
340
+ if (this.state.shouldSelectAfterUpdate) {
341
+ this.inputElement?.setSelectionRange(0, this.state.value.length);
342
+ }
343
+
344
+ const didMinChange = this.props.min !== prevProps.min;
345
+ const didMaxChange = this.props.max !== prevProps.max;
346
+ const didBoundsChange = didMinChange || didMaxChange;
347
+ const didLocaleChange = this.props.locale !== prevProps.locale;
348
+ const didValueChange = this.state.value !== prevState.value;
349
+
350
+ if ((didBoundsChange && didValueChange) || (didLocaleChange && prevState.value !== NumericInput.VALUE_EMPTY)) {
351
+ // we clamped the value due to a bounds change, so we should fire the change callback
352
+ const valueToParse = didLocaleChange ? prevState.value : this.state.value;
353
+ const valueAsString = parseStringToStringNumber(valueToParse, prevProps.locale);
354
+ const localizedValue = toLocaleString(+valueAsString, this.props.locale);
355
+
356
+ this.props.onValueChange?.(+valueAsString, localizedValue, this.inputElement);
357
+ }
358
+ }
359
+
360
+ protected validateProps(nextProps: HTMLInputProps & NumericInputProps) {
361
+ const { majorStepSize, max, min, minorStepSize, stepSize/*, value*/ } = nextProps;
362
+ if (min != null && max != null && min > max) {
363
+ console.error(Errors.NUMERIC_INPUT_MIN_MAX);
364
+ }
365
+ if (stepSize! <= 0) {
366
+ console.error(Errors.NUMERIC_INPUT_STEP_SIZE_NON_POSITIVE);
367
+ }
368
+ if (minorStepSize && minorStepSize <= 0) {
369
+ console.error(Errors.NUMERIC_INPUT_MINOR_STEP_SIZE_NON_POSITIVE);
370
+ }
371
+ if (majorStepSize && majorStepSize <= 0) {
372
+ console.error(Errors.NUMERIC_INPUT_MAJOR_STEP_SIZE_NON_POSITIVE);
373
+ }
374
+ if (minorStepSize && minorStepSize > stepSize!) {
375
+ console.error(Errors.NUMERIC_INPUT_MINOR_STEP_SIZE_BOUND);
376
+ }
377
+ if (majorStepSize && majorStepSize < stepSize!) {
378
+ console.error(Errors.NUMERIC_INPUT_MAJOR_STEP_SIZE_BOUND);
379
+ }
380
+
381
+ // controlled mode
382
+ // if (value != null) {
383
+ // const stepMaxPrecision = NumericInput.getStepMaxPrecision(nextProps);
384
+ // const sanitizedValue = NumericInput.roundAndClampValue(
385
+ // value.toString(),
386
+ // stepMaxPrecision,
387
+ // min,
388
+ // max,
389
+ // 0,
390
+ // this.props.locale,
391
+ // );
392
+ // const valueDoesNotMatch = sanitizedValue !== value.toString();
393
+ // const localizedValue = toLocaleString(
394
+ // Number(parseStringToStringNumber(value, this.props.locale)),
395
+ // this.props.locale,
396
+ // );
397
+ // const isNotLocalized = sanitizedValue !== localizedValue;
398
+ //
399
+ // if (valueDoesNotMatch && isNotLocalized) {
400
+ // console.warn(Errors.NUMERIC_INPUT_CONTROLLED_VALUE_INVALID);
401
+ // }
402
+ // }
403
+ }
404
+
405
+ // Render Helpers
406
+ // ==============
407
+
408
+ private renderButtons() {
409
+ const { intent, max, min, locale } = this.props;
410
+ const value = parseStringToStringNumber(this.state.value, locale);
411
+ const disabled = this.props.disabled || this.props.readOnly;
412
+ const isIncrementDisabled = max !== undefined && value !== "" && +value >= max;
413
+ const isDecrementDisabled = min !== undefined && value !== "" && +value <= min;
414
+
415
+ return (
416
+ <ButtonGroup className={Classes.FIXED} key="button-group" vertical={true}>
417
+ <Button
418
+ aria-label="increment"
419
+ aria-controls={this.numericInputId}
420
+ disabled={disabled || isIncrementDisabled}
421
+ icon={<ChevronUp />}
422
+ intent={intent}
423
+ {...this.incrementButtonHandlers}
424
+ />
425
+ <Button
426
+ aria-label="decrement"
427
+ aria-controls={this.numericInputId}
428
+ disabled={disabled || isDecrementDisabled}
429
+ icon={<ChevronDown />}
430
+ intent={intent}
431
+ {...this.decrementButtonHandlers}
432
+ />
433
+ </ButtonGroup>
434
+ );
435
+ }
436
+
437
+ private renderInput() {
438
+ const inputGroupHtmlProps = removeNonHTMLProps(this.props, NON_HTML_PROPS, true);
439
+ const valueAsNumber = this.getCurrentValueAsNumber();
440
+
441
+ return (
442
+ <InputGroup
443
+ asyncControl={this.props.asyncControl}
444
+ autoComplete="off"
445
+ id={this.numericInputId}
446
+ role={this.props.allowNumericCharactersOnly ? "spinbutton" : undefined}
447
+ {...inputGroupHtmlProps}
448
+ aria-valuemax={this.props.max}
449
+ aria-valuemin={this.props.min}
450
+ aria-valuenow={valueAsNumber}
451
+ intent={this.state.currentImeInputInvalid ? Intent.DANGER : this.props.intent}
452
+ inputClassName={this.props.inputClassName}
453
+ inputRef={this.inputRef}
454
+ large={this.props.large}
455
+ leftElement={this.props.leftElement}
456
+ leftIcon={this.props.leftIcon}
457
+ onFocus={this.handleInputFocus}
458
+ onBlur={this.handleInputBlur}
459
+ onCompositionEnd={this.handleCompositionEnd}
460
+ onCompositionUpdate={this.handleCompositionUpdate}
461
+ onKeyDown={this.handleInputKeyDown}
462
+ onKeyPress={this.handleInputKeyPress}
463
+ onPaste={this.handleInputPaste}
464
+ onValueChange={this.handleInputChange}
465
+ rightElement={this.props.rightElement}
466
+ small={this.props.small}
467
+ value={this.state.value}
468
+ />
469
+ );
470
+ }
471
+
472
+ // Callbacks - Buttons
473
+ // ===================
474
+
475
+ private getButtonEventHandlers(direction: IncrementDirection): ButtonEventHandlers {
476
+ return {
477
+ // keydown is fired repeatedly when held so it's implicitly continuous
478
+ onKeyDown: evt => {
479
+ if (!this.props.disabled && Utils.isKeyboardClick(evt)) {
480
+ this.handleButtonClick(evt, direction);
481
+ }
482
+ },
483
+ onMouseDown: evt => {
484
+ if (!this.props.disabled) {
485
+ this.handleButtonClick(evt, direction);
486
+ this.startContinuousChange();
487
+ }
488
+ },
489
+ };
490
+ }
491
+
492
+ private handleButtonClick = (e: React.MouseEvent | React.KeyboardEvent, direction: IncrementDirection) => {
493
+ const delta = this.updateDelta(direction, e);
494
+ const nextValue = this.incrementValue(delta);
495
+ this.props.onButtonClick?.(Number(parseStringToStringNumber(nextValue, this.props.locale)), nextValue);
496
+ };
497
+
498
+ private startContinuousChange() {
499
+ // The button's onMouseUp event handler doesn't fire if the user
500
+ // releases outside of the button, so we need to watch all the way
501
+ // from the top.
502
+ document.addEventListener("mouseup", this.stopContinuousChange);
503
+
504
+ // Initial delay is slightly longer to prevent the user from
505
+ // accidentally triggering the continuous increment/decrement.
506
+ this.setTimeout(() => {
507
+ this.intervalId = window.setInterval(this.handleContinuousChange, NumericInput.CONTINUOUS_CHANGE_INTERVAL);
508
+ }, NumericInput.CONTINUOUS_CHANGE_DELAY);
509
+ }
510
+
511
+ private stopContinuousChange = () => {
512
+ this.delta = 0;
513
+ this.clearTimeouts();
514
+ clearInterval(this.intervalId);
515
+ document.removeEventListener("mouseup", this.stopContinuousChange);
516
+ };
517
+
518
+ private handleContinuousChange = () => {
519
+ // If either min or max prop is set, when reaching the limit
520
+ // the button will be disabled and stopContinuousChange will be never fired,
521
+ // hence the need to check on each iteration to properly clear the timeout
522
+ if (this.props.min !== undefined || this.props.max !== undefined) {
523
+ const min = this.props.min ?? -Infinity;
524
+ const max = this.props.max ?? Infinity;
525
+ const valueAsNumber = this.getCurrentValueAsNumber();
526
+ if (valueAsNumber <= min || valueAsNumber >= max) {
527
+ this.stopContinuousChange();
528
+ return;
529
+ }
530
+ }
531
+ const nextValue = this.incrementValue(this.delta);
532
+ this.props.onButtonClick?.(Number(parseStringToStringNumber(nextValue, this.props.locale)), nextValue);
533
+ };
534
+
535
+ // Callbacks - Input
536
+ // =================
537
+
538
+ private handleInputFocus = (e: React.FocusEvent<HTMLInputElement>) => {
539
+ // update this state flag to trigger update for input selection (see componentDidUpdate)
540
+ this.setState({ shouldSelectAfterUpdate: this.props.selectAllOnFocus! });
541
+ this.props.onFocus?.(e);
542
+ };
543
+
544
+ private handleInputBlur = (e: React.FocusEvent<HTMLInputElement>) => {
545
+ // always disable this flag on blur so it's ready for next time.
546
+ this.setState({ shouldSelectAfterUpdate: false });
547
+
548
+ if (this.props.clampValueOnBlur) {
549
+ const { value } = e.target as HTMLInputElement;
550
+ this.handleNextValue(this.roundAndClampValue(value));
551
+ }
552
+
553
+ this.props.onBlur?.(e);
554
+ };
555
+
556
+ private handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
557
+ if (this.props.disabled || this.props.readOnly) {
558
+ return;
559
+ }
560
+
561
+ const direction = Utils.getArrowKeyDirection(e, ["ArrowDown"], ["ArrowUp"]);
562
+ if (direction !== undefined) {
563
+ // when the input field has focus, some key combinations will modify
564
+ // the field's selection range. we'll actually want to select all
565
+ // text in the field after we modify the value on the following
566
+ // lines. preventing the default selection behavior lets us do that
567
+ // without interference.
568
+ e.preventDefault();
569
+
570
+ const delta = this.updateDelta(direction, e);
571
+ this.incrementValue(delta);
572
+ }
573
+
574
+ this.props.onKeyDown?.(e);
575
+ };
576
+
577
+ private handleCompositionEnd = (e: React.CompositionEvent<HTMLInputElement>) => {
578
+ if (this.props.allowNumericCharactersOnly) {
579
+ this.handleNextValue(sanitizeNumericInput(e.data, this.props.locale));
580
+ this.setState({ currentImeInputInvalid: false });
581
+ }
582
+ };
583
+
584
+ private handleCompositionUpdate = (e: React.CompositionEvent<HTMLInputElement>) => {
585
+ if (this.props.allowNumericCharactersOnly) {
586
+ const { data } = e;
587
+ const sanitizedValue = sanitizeNumericInput(data, this.props.locale);
588
+ if (sanitizedValue.length === 0 && data.length > 0) {
589
+ this.setState({ currentImeInputInvalid: true });
590
+ } else {
591
+ this.setState({ currentImeInputInvalid: false });
592
+ }
593
+ }
594
+ };
595
+
596
+ private handleInputKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {
597
+ // we prohibit keystrokes in onKeyPress instead of onKeyDown, because
598
+ // e.key is not trustworthy in onKeyDown in all browsers.
599
+ if (this.props.allowNumericCharactersOnly && !isValidNumericKeyboardEvent(e, this.props.locale)) {
600
+ e.preventDefault();
601
+ }
602
+
603
+ // eslint-disable-next-line deprecation/deprecation
604
+ this.props.onKeyPress?.(e);
605
+ };
606
+
607
+ private handleInputPaste = (e: React.ClipboardEvent<HTMLInputElement>) => {
608
+ this.didPasteEventJustOccur = true;
609
+ this.props.onPaste?.(e);
610
+ };
611
+
612
+ private handleInputChange = (value: string) => {
613
+ let nextValue = value;
614
+ if (this.props.allowNumericCharactersOnly && this.didPasteEventJustOccur) {
615
+ this.didPasteEventJustOccur = false;
616
+ nextValue = sanitizeNumericInput(value, this.props.locale);
617
+ }
618
+
619
+ this.handleNextValue(nextValue);
620
+ this.setState({ shouldSelectAfterUpdate: false });
621
+ };
622
+
623
+ // Data logic
624
+ // ==========
625
+
626
+ private handleNextValue(valueAsString: string) {
627
+ if (this.props.value == null) {
628
+ this.setState({ value: valueAsString });
629
+ }
630
+
631
+ this.props.onValueChange?.(
632
+ Number(parseStringToStringNumber(valueAsString, this.props.locale)),
633
+ valueAsString,
634
+ this.inputElement,
635
+ );
636
+ }
637
+
638
+ private incrementValue(delta: number) {
639
+ // pretend we're incrementing from 0 if currValue is empty
640
+ const currValue = this.state.value === NumericInput.VALUE_EMPTY ? NumericInput.VALUE_ZERO : this.state.value;
641
+ const nextValue = this.roundAndClampValue(currValue, delta);
642
+
643
+ if (nextValue !== this.state.value) {
644
+ this.handleNextValue(nextValue);
645
+ this.setState({ shouldSelectAfterUpdate: this.props.selectAllOnIncrement! });
646
+ }
647
+
648
+ // return value used in continuous change updates
649
+ return nextValue;
650
+ }
651
+
652
+ private getIncrementDelta(direction: IncrementDirection, isShiftKeyPressed: boolean, isAltKeyPressed: boolean) {
653
+ const { majorStepSize, minorStepSize, stepSize } = this.props;
654
+
655
+ if (isShiftKeyPressed && majorStepSize != null) {
656
+ return direction * majorStepSize;
657
+ } else if (isAltKeyPressed && minorStepSize != null) {
658
+ return direction * minorStepSize;
659
+ } else {
660
+ return direction * stepSize!;
661
+ }
662
+ }
663
+
664
+ private roundAndClampValue(value: string, delta = 0) {
665
+ return NumericInput.roundAndClampValue(
666
+ value,
667
+ this.state.stepMaxPrecision,
668
+ this.props.min,
669
+ this.props.max,
670
+ delta,
671
+ this.props.locale,
672
+ );
673
+ }
674
+
675
+ private updateDelta(direction: IncrementDirection, e: React.MouseEvent | React.KeyboardEvent) {
676
+ this.delta = this.getIncrementDelta(direction, e.shiftKey, e.altKey);
677
+ return this.delta;
678
+ }
679
+ }
@@ -192,11 +192,11 @@ export class Tree2<T = {}> extends React.Component<TreeProps<T>> {
192
192
  const draggable = !!node.draggable;
193
193
  const droppable = !!node.droppable;
194
194
  const parentDroppable = !!(parentNode && parentNode.droppable);
195
- return (<>
195
+ return (<React.Fragment key={'wr-'+node.id}>
196
196
  {parentDroppable && i === 0 && this.renderNodeSpacer(parentNode, elementPath, i)}
197
197
  <TreeNode2<T>
198
198
  {...node}
199
- key={node.id}
199
+ key={'node-'+node.id}
200
200
  contentRef={this.handleContentRef}
201
201
  depth={elementPath.length - 1}
202
202
  onClick={this.handleNodeClick}
@@ -218,7 +218,7 @@ export class Tree2<T = {}> extends React.Component<TreeProps<T>> {
218
218
  {this.renderNodes(node.childNodes, elementPath, undefined, node)}
219
219
  </TreeNode2>
220
220
  {parentDroppable && i >= 0 && this.renderNodeSpacer(parentNode, elementPath, i + 1)}
221
- </>)
221
+ </React.Fragment>)
222
222
  });
223
223
 
224
224
  return <ul className={classNames(Classes.TREE_NODE_LIST, className)}>{nodeItems}</ul>;