react-science 20.4.0 → 20.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/components/accordion/accordion_context_provider.d.ts.map +1 -1
  2. package/lib/components/accordion/accordion_context_provider.js +1 -1
  3. package/lib/components/accordion/accordion_context_provider.js.map +1 -1
  4. package/lib/components/button/Button.d.ts.map +1 -1
  5. package/lib/components/color-picker/gradient_select/gradient_select.utils.d.ts.map +1 -1
  6. package/lib/components/color-picker/gradient_select/gradient_select.utils.js.map +1 -1
  7. package/lib/components/color-picker/index.d.ts +2 -0
  8. package/lib/components/color-picker/index.d.ts.map +1 -1
  9. package/lib/components/color-picker/index.js +1 -0
  10. package/lib/components/color-picker/index.js.map +1 -1
  11. package/lib/components/color-picker/preview/ColorPreview.d.ts +1 -8
  12. package/lib/components/color-picker/preview/ColorPreview.d.ts.map +1 -1
  13. package/lib/components/color-picker/preview/ColorPreview.js +1 -1
  14. package/lib/components/color-picker/preview/ColorPreview.js.map +1 -1
  15. package/lib/components/color-picker/preview/color_config.d.ts +14 -0
  16. package/lib/components/color-picker/preview/color_config.d.ts.map +1 -0
  17. package/lib/components/color-picker/preview/color_config.js +11 -0
  18. package/lib/components/color-picker/preview/color_config.js.map +1 -0
  19. package/lib/components/draggable/draggable.d.ts +18 -0
  20. package/lib/components/draggable/draggable.d.ts.map +1 -0
  21. package/lib/components/draggable/draggable.js +70 -0
  22. package/lib/components/draggable/draggable.js.map +1 -0
  23. package/lib/components/form/components/field_groups/svg_line_style.d.ts +2 -0
  24. package/lib/components/form/components/field_groups/svg_line_style.d.ts.map +1 -1
  25. package/lib/components/form/components/field_groups/svg_text_style.d.ts +2 -0
  26. package/lib/components/form/components/field_groups/svg_text_style.d.ts.map +1 -1
  27. package/lib/components/form/components/input/draggable_numeric_input.d.ts +10 -0
  28. package/lib/components/form/components/input/draggable_numeric_input.d.ts.map +1 -0
  29. package/lib/components/form/components/input/draggable_numeric_input.js +29 -0
  30. package/lib/components/form/components/input/draggable_numeric_input.js.map +1 -0
  31. package/lib/components/form/components/input/index.d.ts +1 -0
  32. package/lib/components/form/components/input/index.d.ts.map +1 -1
  33. package/lib/components/form/components/input/numeric_input.d.ts +1 -2
  34. package/lib/components/form/components/input/numeric_input.d.ts.map +1 -1
  35. package/lib/components/form/components/input/numeric_input.js.map +1 -1
  36. package/lib/components/form/components/input_groups/form_group.d.ts +1 -0
  37. package/lib/components/form/components/input_groups/form_group.d.ts.map +1 -1
  38. package/lib/components/form/components/input_groups/form_group.js +4 -4
  39. package/lib/components/form/components/input_groups/form_group.js.map +1 -1
  40. package/lib/components/form/components/layout/form.d.ts +11 -0
  41. package/lib/components/form/components/layout/form.d.ts.map +1 -1
  42. package/lib/components/form/components/layout/form.js +3 -1
  43. package/lib/components/form/components/layout/form.js.map +1 -1
  44. package/lib/components/form/context/use_ts_form.d.ts +7 -0
  45. package/lib/components/form/context/use_ts_form.d.ts.map +1 -1
  46. package/lib/components/form/context/use_ts_form.js +2 -0
  47. package/lib/components/form/context/use_ts_form.js.map +1 -1
  48. package/lib/components/hooks/useSelect.d.ts.map +1 -1
  49. package/lib/components/hooks/useSelect.js.map +1 -1
  50. package/lib/components/table/reorder_rows/draggable_row_tr.js +1 -1
  51. package/lib/components/table/reorder_rows/draggable_row_tr.js.map +1 -1
  52. package/lib/components/table/reorder_rows/use_drop_monitor.d.ts.map +1 -1
  53. package/lib/components/table/reorder_rows/use_drop_monitor.js +1 -1
  54. package/lib/components/table/reorder_rows/use_drop_monitor.js.map +1 -1
  55. package/lib/components/table/table_root.d.ts.map +1 -1
  56. package/lib/components/table/table_root.js.map +1 -1
  57. package/lib/components/toolbar/Toolbar.d.ts.map +1 -1
  58. package/lib/components/toolbar/Toolbar.js.map +1 -1
  59. package/lib/components/utils/assert.d.ts +13 -0
  60. package/lib/components/utils/assert.d.ts.map +1 -1
  61. package/lib/components/utils/assert.js +13 -0
  62. package/lib/components/utils/assert.js.map +1 -1
  63. package/lib/components/utils/svg.js +1 -1
  64. package/lib/components/utils/svg.js.map +1 -1
  65. package/package.json +26 -25
  66. package/src/components/accordion/accordion_context_provider.tsx +1 -2
  67. package/src/components/button/Button.tsx +3 -3
  68. package/src/components/color-picker/gradient_select/gradient_select.utils.ts +1 -5
  69. package/src/components/color-picker/index.ts +5 -0
  70. package/src/components/color-picker/preview/ColorPreview.tsx +2 -6
  71. package/src/components/color-picker/preview/color_config.ts +29 -0
  72. package/src/components/draggable/draggable.tsx +127 -0
  73. package/src/components/form/components/input/draggable_numeric_input.tsx +107 -0
  74. package/src/components/form/components/input/index.ts +1 -0
  75. package/src/components/form/components/input/numeric_input.tsx +2 -1
  76. package/src/components/form/components/input_groups/form_group.tsx +10 -3
  77. package/src/components/form/components/layout/form.tsx +20 -2
  78. package/src/components/form/context/use_ts_form.ts +2 -0
  79. package/src/components/hooks/useSelect.tsx +1 -2
  80. package/src/components/table/reorder_rows/draggable_row_tr.tsx +1 -1
  81. package/src/components/table/reorder_rows/use_drop_monitor.ts +1 -1
  82. package/src/components/table/table_root.tsx +1 -2
  83. package/src/components/toolbar/Toolbar.tsx +1 -4
  84. package/src/components/utils/assert.ts +13 -0
  85. package/src/components/utils/svg.ts +1 -1
@@ -0,0 +1,107 @@
1
+ import type { Intent } from '@blueprintjs/core';
2
+ import { NumericInput as BPNumericInput } from '@blueprintjs/core';
3
+ import styled from '@emotion/styled';
4
+
5
+ import { Draggable as InputDraggable } from '../../../draggable/draggable.tsx';
6
+ import { useFieldContext } from '../../context/use_ts_form.ts';
7
+ import { getIntent } from '../../utils/use_intent.ts';
8
+ import { FormGroup } from '../input_groups/index.ts';
9
+
10
+ import type { NumericInputProps } from './numeric_input.tsx';
11
+
12
+ interface DraggableNumericInputProps extends NumericInputProps {
13
+ draggableLabel: string;
14
+ draggableIntent?: Intent;
15
+ hideInput?: boolean;
16
+ }
17
+
18
+ const DraggableNumericInputContainer = styled.div`
19
+ display: flex;
20
+ flex-direction: row;
21
+ gap: 5px;
22
+ `;
23
+
24
+ const Draggable = styled(InputDraggable)`
25
+ flex: 1;
26
+ `;
27
+
28
+ export function DraggableNumericInput(props: DraggableNumericInputProps) {
29
+ const {
30
+ label,
31
+ required,
32
+ helpText,
33
+ placeholder,
34
+ step,
35
+ min,
36
+ max,
37
+ layout,
38
+ fullWidth,
39
+ draggableLabel,
40
+ draggableIntent = 'success',
41
+ hideInput = false,
42
+ majorStepSize,
43
+ minorStepSize,
44
+ ...otherProps
45
+ } = props;
46
+
47
+ const field = useFieldContext<string>();
48
+ const error = field
49
+ .getMeta()
50
+ .errors.map((e) => e.message)
51
+ .at(0);
52
+
53
+ const intent = getIntent(error);
54
+
55
+ function onChange(_: number, valueAsString: string) {
56
+ return field.handleChange(valueAsString);
57
+ }
58
+
59
+ return (
60
+ <FormGroup
61
+ name={field.name}
62
+ label={label}
63
+ intent={intent}
64
+ required={required}
65
+ helpText={helpText}
66
+ layout={layout}
67
+ error={undefined}
68
+ fullWidth={fullWidth}
69
+ contentFullWidth
70
+ >
71
+ <DraggableNumericInputContainer>
72
+ {!hideInput && (
73
+ <BPNumericInput
74
+ {...otherProps}
75
+ id={field.name}
76
+ name={field.name}
77
+ stepSize={step}
78
+ min={min}
79
+ max={max}
80
+ majorStepSize={majorStepSize}
81
+ minorStepSize={minorStepSize}
82
+ value={field.state.value ?? ''}
83
+ onValueChange={onChange}
84
+ onBlur={field.handleBlur}
85
+ intent={intent}
86
+ placeholder={placeholder}
87
+ required={required}
88
+ />
89
+ )}
90
+
91
+ <Draggable
92
+ value={Number(field.state.value)}
93
+ onBlur={field.handleBlur}
94
+ onChange={onChange}
95
+ step={step}
96
+ min={min}
97
+ max={max}
98
+ majorStepSize={majorStepSize}
99
+ minorStepSize={minorStepSize}
100
+ intent={draggableIntent}
101
+ >
102
+ {draggableLabel}
103
+ </Draggable>
104
+ </DraggableNumericInputContainer>
105
+ </FormGroup>
106
+ );
107
+ }
@@ -11,3 +11,4 @@ export type {
11
11
  } from './select.js';
12
12
  export type { SubmitButton as _SubmitButton } from './submit_button.js';
13
13
  export type { Switch as _Switch } from './switch.js';
14
+ export type { DraggableNumericInput as _DraggableNumericInput } from './draggable_numeric_input.js';
@@ -6,7 +6,8 @@ import { getIntent } from '../../utils/use_intent.js';
6
6
  import type { FormGroupInputProps } from '../input_groups/form_group.js';
7
7
  import { FormGroup } from '../input_groups/form_group.js';
8
8
 
9
- interface NumericInputProps extends FormGroupInputProps, BPNumericInputProps {
9
+ export interface NumericInputProps
10
+ extends FormGroupInputProps, BPNumericInputProps {
10
11
  step?: number;
11
12
  min?: number;
12
13
  max?: number;
@@ -16,7 +16,7 @@ const FormContainer = styled.div<{
16
16
  display: grid;
17
17
  margin: 0;
18
18
  grid-template-columns: ${(props) =>
19
- props.layout === 'inline' ? '[label] 30% [input] 70%' : '1fr'};
19
+ props.layout === 'inline' ? '[label] 3fr [input] 7fr' : '1fr'};
20
20
  gap: 5px 20px;
21
21
  grid-template-rows: ${(props) =>
22
22
  props.layout === 'inline' ? 'auto auto' : 'auto'};
@@ -29,6 +29,7 @@ const RequiredSpan = styled.span`
29
29
  const ContainerElement = styled.div<{
30
30
  height?: number | 'auto';
31
31
  fullWidth?: boolean;
32
+ contentFullWidth?: boolean;
32
33
  layout?: Layout;
33
34
  }>`
34
35
  display: inline-block;
@@ -40,7 +41,7 @@ const ContainerElement = styled.div<{
40
41
  : '1 / -1'};
41
42
  height: ${(props) =>
42
43
  props.height === 'auto' ? props.height : `${props.height}px`};
43
- width: fit-content;
44
+ width: ${(props) => (props.contentFullWidth ? '100%' : 'fit-content')};
44
45
  min-width: 180px;
45
46
  `;
46
47
 
@@ -85,6 +86,7 @@ interface FormGroupProps {
85
86
  error?: string;
86
87
  layout?: Layout;
87
88
  fullWidth?: boolean;
89
+ contentFullWidth?: boolean;
88
90
  }
89
91
 
90
92
  export function FormGroup(props: FormGroupProps) {
@@ -98,6 +100,7 @@ export function FormGroup(props: FormGroupProps) {
98
100
  error,
99
101
  layout,
100
102
  fullWidth = false,
103
+ contentFullWidth = false,
101
104
  } = props;
102
105
 
103
106
  const { layout: formLayout } = useFormContext();
@@ -122,7 +125,11 @@ export function FormGroup(props: FormGroupProps) {
122
125
  )}
123
126
  </Label>
124
127
  )}
125
- <ContainerElement fullWidth={fullWidth} layout={layout || formLayout}>
128
+ <ContainerElement
129
+ fullWidth={fullWidth}
130
+ layout={layout || formLayout}
131
+ contentFullWidth={contentFullWidth}
132
+ >
126
133
  {children}
127
134
 
128
135
  <ErrorAndHelpText>
@@ -8,10 +8,21 @@ export interface AppFormProps extends Omit<DomFormProps, 'noValidate'> {
8
8
  domValidate?: boolean;
9
9
  /**
10
10
  * should return meta to pass to `form.handleSubmit`
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * onSubmitMeta={(event) => event.nativeEvent.submitter?.dataset.action}
15
+ * ```
11
16
  */
12
17
  // Generic meta-result is not possible with higher order component pattern
13
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
19
  onSubmitMeta?: (event: SyntheticEvent<HTMLFormElement, SubmitEvent>) => any;
20
+
21
+ /**
22
+ * onSubmit form will call `event.stopPropagation()`.
23
+ * It can be useful for nested form.
24
+ */
25
+ onSubmitStopPropagation?: boolean;
15
26
  }
16
27
 
17
28
  const props: AppFormProps = { children: null };
@@ -32,7 +43,14 @@ export const AppForm = minimalForm(
32
43
  defaultValues,
33
44
  props,
34
45
  render: function FormRender(props) {
35
- const { form, children, domValidate, onSubmitMeta, ...domProps } = props;
46
+ const {
47
+ form,
48
+ children,
49
+ domValidate,
50
+ onSubmitMeta,
51
+ onSubmitStopPropagation,
52
+ ...domProps
53
+ } = props;
36
54
  const { AppForm } = form;
37
55
 
38
56
  return (
@@ -41,13 +59,13 @@ export const AppForm = minimalForm(
41
59
  <DomForm
42
60
  onSubmit={(event) => {
43
61
  event.preventDefault();
62
+ if (onSubmitStopPropagation) event.stopPropagation();
44
63
 
45
64
  const meta = onSubmitMeta?.(
46
65
  // onSubmit event is not typed properly.
47
66
  // It uses Event instead of SubmitEvent.
48
67
  event as SyntheticEvent<HTMLFormElement, SubmitEvent>,
49
68
  );
50
-
51
69
  void form.handleSubmit(meta);
52
70
  }}
53
71
  {...domProps}
@@ -2,6 +2,7 @@ import { createFormHook, createFormHookContexts } from '@tanstack/react-form';
2
2
 
3
3
  import { Checkbox } from '../components/input/checkbox.js';
4
4
  import { ColorPicker } from '../components/input/color_picker.tsx';
5
+ import { DraggableNumericInput } from '../components/input/draggable_numeric_input.js';
5
6
  import { Input } from '../components/input/input.js';
6
7
  import { NumericInput } from '../components/input/numeric_input.js';
7
8
  import { RadioGroup } from '../components/input/radio_group.js';
@@ -37,6 +38,7 @@ const { useAppForm, withForm, withFieldGroup } = createFormHook({
37
38
  Switch,
38
39
  ColorPicker,
39
40
  RadioGroup,
41
+ DraggableNumericInput,
40
42
  },
41
43
  });
42
44
 
@@ -24,8 +24,7 @@ interface UseSelectRenderOptions<T> extends UseSelectCommonOptions<T> {
24
24
  }
25
25
 
26
26
  export type UseSelectOptions<T> =
27
- | UseSelectBaseOptions<T>
28
- | UseSelectRenderOptions<T>;
27
+ UseSelectBaseOptions<T> | UseSelectRenderOptions<T>;
29
28
 
30
29
  function isAccessLabelByKey<T>(
31
30
  options: UseSelectOptions<T>,
@@ -9,10 +9,10 @@ import {
9
9
  pointerOutsideOfPreview,
10
10
  setCustomNativeDragPreview,
11
11
  } from '@zakodium/pdnd-esm';
12
+ import { assert } from '@zakodium/utils';
12
13
  import { useEffect, useMemo, useRef, useState } from 'react';
13
14
  import { createPortal } from 'react-dom';
14
15
 
15
- import { assert } from '../../utils/index.js';
16
16
  import { useFlashRowEffect } from '../flash_row/use_flash_row_effect.js';
17
17
  import { PreviewTable } from '../preview_table.js';
18
18
  import { useIsPreviewTable } from '../preview_table_context.js';
@@ -5,10 +5,10 @@ import {
5
5
  extractClosestEdge,
6
6
  monitorForElements,
7
7
  } from '@zakodium/pdnd-esm';
8
+ import { assert } from '@zakodium/utils';
8
9
  import type { RefObject } from 'react';
9
10
  import { useEffect } from 'react';
10
11
 
11
- import { assert } from '../../utils/index.js';
12
12
  import { useFlashedRowContext } from '../flash_row/flashed_row_context.js';
13
13
 
14
14
  import { isItemData } from './item_data.js';
@@ -232,8 +232,7 @@ interface VirtualizedTableProps<
232
232
  }
233
233
 
234
234
  export type TableProps<TData extends RowData> =
235
- | RegularTableProps<TData>
236
- | VirtualizedTableProps<TData>;
235
+ RegularTableProps<TData> | VirtualizedTableProps<TData>;
237
236
 
238
237
  export function Table<TData extends RowData>(props: TableProps<TData>) {
239
238
  const {
@@ -29,10 +29,7 @@ import { useCheckOverflow } from './useCheckOverflow.tsx';
29
29
  export type Overflow = 'wrap' | 'collapse';
30
30
 
31
31
  export type PopoverInteractionType =
32
- | 'click'
33
- | 'hover'
34
- | 'click-target'
35
- | 'hover-target';
32
+ 'click' | 'hover' | 'click-target' | 'hover-target';
36
33
 
37
34
  interface ToolbarBaseProps {
38
35
  intent?: Intent;
@@ -1,7 +1,15 @@
1
+ /**
2
+ * @param x
3
+ * @deprecated Use `assertUnreachable` from `@zakodium/utils`
4
+ */
1
5
  export function assertUnreachable(x: never): never {
2
6
  throw new Error(`unreachable: ${String(x)}`);
3
7
  }
4
8
 
9
+ /**
10
+ * @param x
11
+ * @deprecated Use `assertNotNullish` from `@zakodium/utils`
12
+ */
5
13
  export function assertNotNull<T>(
6
14
  value: T | null | undefined,
7
15
  ): asserts value is Exclude<T, null | undefined> {
@@ -13,6 +21,11 @@ export function assertNotNull<T>(
13
21
  }
14
22
  }
15
23
 
24
+ /**
25
+ * @param value
26
+ * @param message
27
+ * @deprecated Use `assert` from `@zakodium/utils`
28
+ */
16
29
  export function assert(value: unknown, message?: string): asserts value {
17
30
  if (!value) {
18
31
  throw new Error(`unreachable${message ? `: ${message}` : ''}`);
@@ -1,4 +1,4 @@
1
- import { assert } from './assert.ts';
1
+ import { assert } from '@zakodium/utils';
2
2
 
3
3
  export interface ExportSVGOptions {
4
4
  /**