@sheetxl/utils-react 0.7.2 → 0.7.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sheetxl/utils-react",
3
3
  "description": "Utils React - Utilities for React capabilities needed for all SheetXL components.",
4
- "version": "0.7.2",
4
+ "version": "0.7.4",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -27,7 +27,7 @@
27
27
  "react"
28
28
  ],
29
29
  "dependencies": {
30
- "@sheetxl/utils": "^0.7.2",
30
+ "@sheetxl/utils": "^0.7.4",
31
31
  "clsx": "^2.1.1",
32
32
  "detect-it": "^4.0.1",
33
33
  "react-merge-refs": "^3.0.2",
package/types/index.d.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import { CellCoords } from '@sheetxl/utils';
2
2
  import { default as default_2 } from 'react';
3
+ import { DelegatingNotifier } from '@sheetxl/utils';
3
4
  import { DependencyList } from 'react';
4
5
  import { Dimensions } from '@sheetxl/utils';
5
6
  import { Direction } from '@sheetxl/utils';
6
7
  import { EditModeHandler } from '@sheetxl/utils';
8
+ import { INotifier } from '@sheetxl/utils';
7
9
  import { JSX } from 'react/jsx-runtime';
10
+ import { NotifierOptions } from '@sheetxl/utils';
11
+ import { ReactNode } from 'react';
8
12
  import { ReferenceableClipboard } from '@sheetxl/utils';
9
13
  import { RemoveListener } from '@sheetxl/utils';
10
14
  import { TopLeft } from '@sheetxl/utils';
@@ -12,8 +16,8 @@ import { UndoManager } from '@sheetxl/utils';
12
16
 
13
17
  declare function boundPixel(pixel: number, _increase?: boolean, _absOffset?: number): number;
14
18
 
15
- export declare interface BusyNotificationOptions {
16
- icon?: React.ReactNode;
19
+ export declare interface BusyNotifierOptions {
20
+ icon?: default_2.ReactNode;
17
21
  }
18
22
 
19
23
  export declare type CellFinder = (activeCoords: CellCoords, isContentfulCell: IsContentfulCell | undefined, hiddenAt: HiddenHeadersAt | undefined, direction: Direction, first: boolean, limit: number) => number;
@@ -190,10 +194,6 @@ export declare interface CopyPasteProps {
190
194
  * Called after paste has been called.
191
195
  */
192
196
  onPaste?: (reference: ReferenceableClipboard.ReferenceItem, args: ReferenceableClipboard.PasteOptions) => void;
193
- /**
194
- * A notifier to provide for warnings and errors.
195
- */
196
- notifier?: Notifier;
197
197
  }
198
198
 
199
199
  export declare interface CopyPasteResults {
@@ -231,7 +231,24 @@ export declare const defaultCreateScrollEndButton: (props: ScrollButtonProps) =>
231
231
  */
232
232
  export declare const defaultCreateScrollStartButton: (props: ScrollButtonProps) => default_2.ReactElement;
233
233
 
234
- export declare const DefaultNotifier: Notifier;
234
+ export declare class DelegatingReactNotifier extends DelegatingNotifier implements IReactNotifier {
235
+ setDelegate(delegate: Partial<IReactNotifier> | null): void;
236
+ getDelegate(): Partial<IReactNotifier> | null;
237
+ /** @inheritdoc IReactNotifier.showMessage */
238
+ showMessage(message: string | default_2.ReactNode, options?: EnqueueNotifierOptions): void;
239
+ /** @inheritdoc IReactNotifier.showBusy */
240
+ showBusy(message: string | default_2.ReactNode, options?: BusyNotifierOptions): (Promise<() => void>) | (() => void);
241
+ /** @inheritdoc IReactNotifier.showWindow */
242
+ showWindow(type: string, props?: any, options?: {
243
+ disableAutoDestroy?: boolean;
244
+ }): Promise<HTMLElement>;
245
+ /** @inheritdoc IReactNotifier.showError */
246
+ showError(error: any): void;
247
+ /** @inheritdoc IReactNotifier.showOptions */
248
+ showOptions(options: OptionsNotifierOptions): Promise<string>;
249
+ /** @inheritdoc IReactNotifier.showInputOptions */
250
+ showInputOptions(options: InputOptionsNotifierOptions): Promise<InputResults>;
251
+ }
235
252
 
236
253
  /**
237
254
  * Re-export detectIt.
@@ -274,6 +291,20 @@ declare type DynamicValue<T, CONTEXT> = T | ((context?: DynamicContext<CONTEXT>)
274
291
 
275
292
  declare const EmptyCssProperties: React.CSSProperties;
276
293
 
294
+ /**
295
+ * Configuration for non-blocking notifications.
296
+ */
297
+ export declare interface EnqueueNotifierOptions extends NotifierOptions {
298
+ /**
299
+ * A hint for decorations of the message.
300
+ */
301
+ type?: NotifierType;
302
+ /**
303
+ * Passed directly to the Snackbar component.
304
+ */
305
+ enqueueProps?: Record<string, any>;
306
+ }
307
+
277
308
  declare const focusableNodeNames: Set<string>;
278
309
 
279
310
  /**
@@ -607,19 +638,19 @@ export declare interface IKeyStroke {
607
638
  readonly modifiers?: KeyModifiers[];
608
639
  }
609
640
 
610
- export declare interface InputOptionsNotificationOptions extends OptionsNotificationOptions {
641
+ export declare interface InputOptionsNotifierOptions extends OptionsNotifierOptions {
611
642
  initialValue?: string;
612
643
  /**
613
644
  * Css style for input
614
645
  */
615
- inputProps?: React.HTMLAttributes<HTMLInputElement | HTMLTextAreaElement>;
646
+ inputProps?: default_2.HTMLAttributes<HTMLInputElement | HTMLTextAreaElement>;
616
647
  inputLabel?: string;
617
648
  inputType?: 'text' | 'password' | 'email' | 'number' | 'search' | 'tel' | 'url';
618
649
  inputPlaceHolder?: string;
619
650
  onInputOption?: (input?: string, option?: string) => void;
620
651
  /**
621
652
  * Call when an option is selected. If false is returned, the the
622
- * dialog will not close. Notification is not provided but can
653
+ * dialog will not close. INotifier is not provided but can
623
654
  * be supplied via the textFieldProps helperText property.
624
655
  * @remarks
625
656
  * Optional the textProps can be updated via the textFieldProps argument
@@ -637,6 +668,50 @@ export declare interface InputValidationResults {
637
668
  message?: string;
638
669
  }
639
670
 
671
+ /**
672
+ * Interface that provides popups for the user.
673
+ */
674
+ export declare interface IReactNotifier extends INotifier {
675
+ /**
676
+ * Useful when informing the user of something but are not expecting a response.
677
+ */
678
+ showMessage: (message: string | default_2.ReactNode, options?: EnqueueNotifierOptions) => void;
679
+ /**
680
+ * Useful when performing a long running operation and you want to inform the user.
681
+ *
682
+ * A return type of a handler will be returned to allow for hideBusy.
683
+ * If multiple calls are made the consumer should continue to indicated blocked
684
+ * until all calls have been hideBusy.
685
+ */
686
+ showBusy: (message: string | default_2.ReactNode, options?: BusyNotifierOptions) => (Promise<() => void>) | (() => void);
687
+ /**
688
+ * Show a dialog for a given type.
689
+ *
690
+ * @param type
691
+ * @param props
692
+ * @param options
693
+ */
694
+ showWindow: (type: string, props?: any, options?: {
695
+ disableAutoDestroy?: boolean;
696
+ }) => Promise<HTMLElement>;
697
+ /**
698
+ * Should return error object exception.
699
+ *
700
+ * @param error
701
+ */
702
+ showError: (error: Error | string) => void;
703
+ /**
704
+ * Provide a user with a list of options to choose from.
705
+ * @param options
706
+ */
707
+ showOptions: (options: OptionsNotifierOptions) => Promise<string>;
708
+ /**
709
+ * Provider a user with a way to enter a text input.
710
+ * @param options
711
+ */
712
+ showInputOptions: (options: InputOptionsNotifierOptions) => Promise<InputResults>;
713
+ }
714
+
640
715
  export declare interface IsContentfulCell {
641
716
  (coords: CellCoords): boolean;
642
717
  }
@@ -736,42 +811,34 @@ export declare const MouseButtonCodes: {
736
811
 
737
812
  export declare type MouseButtonCodes = typeof MouseButtonCodes[keyof typeof MouseButtonCodes];
738
813
 
814
+ export declare const NotifierProvider: default_2.FC<NotifierProviderProps>;
815
+
739
816
  /**
740
- * Configuration for non-blocking notifications.
817
+ * Context provider for notifications. Allows custom notification implementations
818
+ * to be provided to components within the provider tree.
819
+ *
820
+ * @example
821
+ * ```tsx
822
+ * const customNotifier = {
823
+ * showMessage: (message) => toast(message),
824
+ * showError: (error) => toast.error(error),
825
+ * // ... other methods
826
+ * };
827
+ *
828
+ * <NotifierProvider notifier={customNotifier}>
829
+ * <App />
830
+ * </NotifierProvider>
831
+ * ```
741
832
  */
742
- declare interface NotificationOptions_2 {
743
- /**
744
- * A hint for decorations of the message.
745
- */
746
- type?: NotificationType;
747
- /**
748
- * Setting this to true will leave the notification on the screen unless it is dismissed (programmatically or through user interaction).
749
- * If `false` will be removed after a period of time.
750
- *
751
- * @defaultValue false
752
- */
753
- persist?: boolean;
754
- /**
755
- * Ignores displaying multiple snackBars with the same `message`.
756
- *
757
- * @defaultValue false
758
- */
759
- preventDuplicate?: boolean;
760
- /**
761
- * If provided then then notification provider should not notify if the same id is used again.
762
- */
763
- onceKey?: string;
764
- /**
765
- * Passed directly to the Snackbar component.
766
- */
767
- enqueueProps?: Record<string, any>;
833
+ export declare interface NotifierProviderProps {
834
+ children: ReactNode;
835
+ notifier: IReactNotifier;
768
836
  }
769
- export { NotificationOptions_2 as NotificationOptions }
770
837
 
771
838
  /**
772
839
  * Indicates the type of notification.
773
840
  */
774
- export declare const NotificationType: {
841
+ export declare const NotifierType: {
775
842
  readonly Default: "default";
776
843
  readonly Error: "error";
777
844
  readonly Success: "success";
@@ -779,57 +846,14 @@ export declare const NotificationType: {
779
846
  readonly Info: "info";
780
847
  };
781
848
 
782
- export declare type NotificationType = typeof NotificationType[keyof typeof NotificationType];
783
-
784
- /**
785
- * Interface that provides popups for the user.
786
- */
787
- export declare interface Notifier {
788
- /**
789
- * Useful when informing the user of something but are not expecting a response.
790
- */
791
- showMessage?: (message: string | React.ReactNode, options?: NotificationOptions_2) => void;
792
- /**
793
- * Useful when performing a long running operation and you want to inform the user.
794
- *
795
- * A return type of a handler will be returned to allow for hideBusy.
796
- * If multiple calls are made the consumer should continue to indicated blocked
797
- * until all calls have been hideBusy.
798
- */
799
- showBusy?: (message: string | React.ReactNode, options?: BusyNotificationOptions) => (Promise<() => void>) | (() => void);
800
- /**
801
- * Show a dialog for a given type.
802
- * @param type
803
- * @param props
804
- * @param options
805
- */
806
- showWindow?: (type: string, props?: any, options?: {
807
- disableAutoDestroy?: boolean;
808
- }) => Promise<HTMLElement>;
809
- /**
810
- * Should return error object exception.
811
- *
812
- * @param error
813
- */
814
- showError?: (error: Error | string) => void;
815
- /**
816
- * Provide a user with a list of options to choose from.
817
- * @param options
818
- */
819
- showOptions?: (options: OptionsNotificationOptions) => Promise<string>;
820
- /**
821
- * Provider a user with a way to enter a text input.
822
- * @param options
823
- */
824
- showInputOptions?: (options: InputOptionsNotificationOptions) => Promise<InputResults>;
825
- }
849
+ export declare type NotifierType = typeof NotifierType[keyof typeof NotifierType];
826
850
 
827
851
  export declare type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
828
852
 
829
853
  /**
830
854
  * Configuration for an options dialog.
831
855
  */
832
- export declare interface OptionsNotificationOptions extends React.HTMLAttributes<HTMLDivElement> {
856
+ export declare interface OptionsNotifierOptions extends default_2.HTMLAttributes<HTMLDivElement> {
833
857
  /**
834
858
  * The options as a list of strings
835
859
  */
@@ -848,7 +872,7 @@ export declare interface OptionsNotificationOptions extends React.HTMLAttributes
848
872
  * @remarks
849
873
  * Not yet implemented
850
874
  */
851
- icon?: React.ReactNode;
875
+ icon?: default_2.ReactNode;
852
876
  /**
853
877
  * Allows for the option will be the default selected option and the enter key trigger.
854
878
  * @defaultValue The first option
@@ -872,10 +896,10 @@ export declare interface OptionsNotificationOptions extends React.HTMLAttributes
872
896
  * @remarks
873
897
  * The option is passed as the `children` prop and as the second argument
874
898
  */
875
- createOptionsButton?: (option: string, props: React.HTMLAttributes<HTMLButtonElement> & React.Attributes, isDefaultOption: boolean) => React.ReactNode;
899
+ createOptionsButton?: (option: string, props: default_2.HTMLAttributes<HTMLButtonElement> & default_2.Attributes, isDefaultOption: boolean) => default_2.ReactNode;
876
900
  /**
877
901
  * Call when an option is selected. If false is returned, the the
878
- * dialog will not close. Notification is not provided but can
902
+ * dialog will not close. INotifier is not provided but can
879
903
  * be supplied via the textFieldProps helperText property.
880
904
  */
881
905
  onValidateOption?: (option?: string) => boolean | Promise<boolean>;
@@ -1205,7 +1229,6 @@ export declare interface UndoManagerProps {
1205
1229
  * way to disable/protect a sheet. Excel clears the undo stack!
1206
1230
  */
1207
1231
  disabled?: boolean;
1208
- notifier?: Notifier;
1209
1232
  commands?: ICommands.IGroup;
1210
1233
  }
1211
1234
 
@@ -1292,6 +1315,28 @@ export declare function useImperativeElement<R extends T, A = any, T = HTMLEleme
1292
1315
  */
1293
1316
  export declare function useMouseDownAndHoldListener(onPointerDown: (event: default_2.PointerEvent<Element>) => boolean | void, options?: RepeatClickOptions): (event: default_2.PointerEvent<Element>) => void;
1294
1317
 
1318
+ /**
1319
+ * Hook to access the notification system. Uses the notifier from the nearest
1320
+ * NotifierProvider, or falls back to the default ReactNotifier singleton if
1321
+ * no provider is found.
1322
+ *
1323
+ * @returns The notification interface
1324
+ *
1325
+ * @example
1326
+ * ```tsx
1327
+ * function MyComponent() {
1328
+ * const notifier = useNotifier();
1329
+ *
1330
+ * const handleClick = () => {
1331
+ * notifier.showMessage('Hello World!', { type: NotifierType.Success });
1332
+ * };
1333
+ *
1334
+ * return <button onClick={handleClick}>Show INotifier</button>;
1335
+ * }
1336
+ * ```
1337
+ */
1338
+ export declare const useNotifier: () => IReactNotifier;
1339
+
1295
1340
  export declare function useOnClickOrFocusAway(ref: default_2.RefObject<any>, listenerArg: ClickOrFocusAwayListener, options?: ClickOrFocusAwayOptions): void;
1296
1341
 
1297
1342
  /**
@@ -1308,7 +1353,7 @@ export declare function useTraceUpdate(props: any, enabled?: boolean): void;
1308
1353
  /**
1309
1354
  * Undo manager hook
1310
1355
  */
1311
- export declare const useUndoManager: ({ manager, commands: commandsParent, disabled: propDisabled, notifier }: UndoManagerProps) => UndoManagerResults;
1356
+ export declare const useUndoManager: ({ manager, commands: commandsParent, disabled: propDisabled, }: UndoManagerProps) => UndoManagerResults;
1312
1357
 
1313
1358
  /**
1314
1359
  * The virtual scrollbar is for very large scroll area.