@sheetxl/utils-react 0.7.5 → 0.7.7

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.5",
4
+ "version": "0.7.7",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -40,7 +40,7 @@
40
40
  "react"
41
41
  ],
42
42
  "dependencies": {
43
- "@sheetxl/utils": "^0.7.5",
43
+ "@sheetxl/utils": "^0.7.7",
44
44
  "clsx": "^2.1.1",
45
45
  "detect-it": "^4.0.1",
46
46
  "react-merge-refs": "^3.0.2",
package/types/index.d.ts CHANGED
@@ -2,7 +2,6 @@ import { CellCoords } from '@sheetxl/utils';
2
2
  import { default as default_2 } from 'react';
3
3
  import { DefaultNotifier } from '@sheetxl/utils';
4
4
  import { DependencyList } from 'react';
5
- import { Dimensions } from '@sheetxl/utils';
6
5
  import { Direction } from '@sheetxl/utils';
7
6
  import { EditModeHandler } from '@sheetxl/utils';
8
7
  import { INotifier } from '@sheetxl/utils';
@@ -11,9 +10,15 @@ import { NotifierOptions } from '@sheetxl/utils';
11
10
  import { ReactNode } from 'react';
12
11
  import { ReferenceableClipboard } from '@sheetxl/utils';
13
12
  import { RemoveListener } from '@sheetxl/utils';
13
+ import { Size } from '@sheetxl/utils';
14
14
  import { TopLeft } from '@sheetxl/utils';
15
15
  import { UndoManager } from '@sheetxl/utils';
16
16
 
17
+ declare type BaseGlyph = {
18
+ tags?: string[];
19
+ rtlMirror?: boolean;
20
+ };
21
+
17
22
  declare function boundPixel(pixel: number, _increase?: boolean, _absOffset?: number): number;
18
23
 
19
24
  export declare interface BusyNotifierOptions {
@@ -54,7 +59,7 @@ export declare class Command<STATE extends any = void, CONTEXT extends any = voi
54
59
  protected _label: DynamicValue<string, CONTEXT>;
55
60
  protected _scopedLabels?: Record<string, DynamicValue<string, CONTEXT>>;
56
61
  protected _description?: DynamicValue<string, CONTEXT>;
57
- protected _icon: DynamicValue<React.ReactNode, CONTEXT>;
62
+ protected _icon: DynamicValue<React.ReactElement | string, CONTEXT>;
58
63
  protected _tags: DynamicValue<string[], CONTEXT>;
59
64
  protected _shortcut: DynamicValue<IKeyStroke | IKeyStroke[] | null, CONTEXT>;
60
65
  protected _disabled: DynamicValue<boolean, CONTEXT>;
@@ -63,14 +68,14 @@ export declare class Command<STATE extends any = void, CONTEXT extends any = voi
63
68
  protected _callback: ICommandCallback<STATE>;
64
69
  protected _listenersProperties: Set<ICommandPropertyListener<STATE, CONTEXT>>;
65
70
  protected _listenersExecute: Set<ICommandHook<STATE, CONTEXT>>;
66
- constructor(key: string, target: ICommands.ITarget | (() => ICommands.ITarget), props?: ICommandProperties<STATE, CONTEXT>, callback?: ICommandCallback<STATE>);
71
+ constructor(key: string, target: ICommands.ITarget | (() => ICommands.ITarget) | null, props?: ICommandProperties<STATE, CONTEXT>, callback?: ICommandCallback<STATE>);
67
72
  key(): string;
68
73
  protected _resolve<T = any>(value: DynamicValue<T, CONTEXT>, scopedContext?: CONTEXT | (() => CONTEXT)): T;
69
74
  target(): ICommands.ITarget;
70
75
  label(scope?: string, scopedContext?: CONTEXT): string;
71
76
  description(context?: DynamicContext<CONTEXT>): string;
72
77
  tags(context?: DynamicContext<CONTEXT>): string[];
73
- icon(context?: DynamicContext<CONTEXT>): React.ReactNode;
78
+ icon(context?: DynamicContext<CONTEXT>): React.ReactElement | string;
74
79
  shortcut(): IKeyStroke | IKeyStroke[];
75
80
  disabled(): boolean;
76
81
  state(): STATE;
@@ -89,14 +94,55 @@ export declare class Command<STATE extends any = void, CONTEXT extends any = voi
89
94
  protected _applyProps(props: ICommandProperties<STATE, CONTEXT>): ICommandProperties<STATE, CONTEXT>;
90
95
  }
91
96
 
92
- export declare interface CommandButtonCreator {
97
+ export declare interface CommandButtonOptions<STATE = any, CONTEXT = any> extends Omit<React.HTMLAttributes<HTMLElement>, "color" | "label"> {
98
+ /**
99
+ * Allow for listeners against a specific buttons execute rather then the command.
100
+ * Useful when knowing the specific button that executed a command is required.
101
+ * (For example when closing menus or restoring focus)
102
+ */
103
+ commandHook?: ICommandHook<STATE, CONTEXT>;
104
+ /**
105
+ * Optional string to enable the command label to be configured based on the scope of how it is being used.
106
+ */
107
+ scope?: string;
108
+ icon?: React.ReactNode | ((command: ICommand) => React.ReactNode);
109
+ label?: React.ReactNode | ((command: ICommand) => React.ReactNode);
110
+ /**
111
+ * The shortcut to display.
112
+ *
113
+ * @remarks
114
+ * This is display only and doesn't actually track the shortcut.
115
+ * Override the display for the shortcut on the command (if available).
116
+ */
117
+ shortcut?: IKeyStroke | IKeyStroke[];
118
+ selected?: boolean;
119
+ disabled?: boolean;
120
+ disableHover?: boolean;
121
+ /**
122
+ * Tooltip properties. If this is specified then the tooltips are used.
123
+ * Do not provide a child as this component will be the child.
124
+ */
125
+ tooltipProps?: any;
126
+ /**
127
+ * How the button will be styles.
128
+ * @defaultValue CommandButtonType.Toolbar
129
+ */
130
+ variant?: CommandButtonType;
131
+ /**
132
+ * Optional state for this specific command button.
133
+ * @defaultValue to undefined
134
+ */
135
+ commandState?: STATE;
136
+ context?: CONTEXT;
93
137
  }
94
138
 
95
- export declare interface CommandButtonMeta {
139
+ export declare interface CommandButtonProps<STATE = any, CONTEXT = any> extends CommandButtonOptions {
140
+ command: ICommand<STATE, CONTEXT>;
96
141
  }
97
142
 
98
- export declare interface CommandButtonRegistry {
99
- }
143
+ export declare type CommandButtonRefAttribute = {
144
+ ref?: React.Ref<HTMLDivElement>;
145
+ };
100
146
 
101
147
  /**
102
148
  * Follow useCommandsButtons. pattern createCommandButtonSet
@@ -205,6 +251,21 @@ export declare interface CopyPasteResults {
205
251
  clipboard: ReferenceableClipboard;
206
252
  }
207
253
 
254
+ export declare function createDynamicIconService(): {
255
+ register: (key: IconPackKey, packOrLoader: IconPack | IconPackInput | PackLoader) => void;
256
+ prefetch: (keys?: IconPackKey | IconPackKey[]) => Promise<void>;
257
+ setActive: (packKey: IconPackKey) => void;
258
+ getActive: () => IconPackKey;
259
+ resolve: (key: IconGlyphKey, o?: ResolveOptions) => Promise<IconGlyphPackPair | null>;
260
+ registerAlias: (packKey: IconPackKey, fromKey: IconGlyphKey, toKey: IconGlyphKey) => void;
261
+ has: (key: IconGlyphKey, o?: ResolveOptions) => boolean;
262
+ getPack: (packKey?: IconPackKey) => IconPack;
263
+ hasPack: (packKey: IconPackKey) => boolean;
264
+ listPacks: () => IconPackKey[];
265
+ listIcons: (packKey: IconPackKey) => string[];
266
+ addActiveListener: (cb: (key: IconPackKey) => void) => RemoveListener;
267
+ };
268
+
208
269
  declare const createSyntheticEvent: <T extends Element, E extends Event>(event: E) => React.SyntheticEvent<T, E>;
209
270
 
210
271
  export declare const defaultCreateScrollbar: (props: ScrollbarRefProps) => JSX.Element;
@@ -231,6 +292,21 @@ export declare const defaultCreateScrollEndButton: (props: ScrollButtonProps) =>
231
292
  */
232
293
  export declare const defaultCreateScrollStartButton: (props: ScrollButtonProps) => default_2.ReactElement;
233
294
 
295
+ export declare const DefaultDynamicIconService: {
296
+ register: (key: IconPackKey, packOrLoader: IconPack | IconPackInput | PackLoader) => void;
297
+ prefetch: (keys?: IconPackKey | IconPackKey[]) => Promise<void>;
298
+ setActive: (packKey: IconPackKey) => void;
299
+ getActive: () => IconPackKey;
300
+ resolve: (key: IconGlyphKey, o?: ResolveOptions) => Promise<IconGlyphPackPair | null>;
301
+ registerAlias: (packKey: IconPackKey, fromKey: IconGlyphKey, toKey: IconGlyphKey) => void;
302
+ has: (key: IconGlyphKey, o?: ResolveOptions) => boolean;
303
+ getPack: (packKey?: IconPackKey) => IconPack;
304
+ hasPack: (packKey: IconPackKey) => boolean;
305
+ listPacks: () => IconPackKey[];
306
+ listIcons: (packKey: IconPackKey) => string[];
307
+ addActiveListener: (cb: (key: IconPackKey) => void) => RemoveListener;
308
+ };
309
+
234
310
  export declare class DefaultReactNotifier extends DefaultNotifier implements IReactNotifier {
235
311
  /** @inheritdoc IReactNotifier.setOverrides */
236
312
  setOverrides(overrides: Partial<IReactNotifier> | null): void;
@@ -289,8 +365,34 @@ export declare interface DevicePixelRatioOptions {
289
365
 
290
366
  declare type DynamicContext<CONTEXT> = CONTEXT | (() => CONTEXT);
291
367
 
368
+ export declare const DynamicIcon: default_2.MemoExoticComponent<(props: DynamicIconProps) => JSX.Element>;
369
+
370
+ export declare interface DynamicIconProps extends default_2.HTMLAttributes<HTMLElement> {
371
+ iconKey?: IconGlyphKey;
372
+ packKey?: IconPackKey;
373
+ className?: string;
374
+ style?: default_2.CSSProperties;
375
+ /** Sets wrapper font-size; children scale to 1em */
376
+ size?: string | number;
377
+ title?: string;
378
+ role?: 'img' | 'presentation' | string;
379
+ ariaHidden?: boolean;
380
+ /** Extra props forwarded to React glyphs (if the glyph is of type `react`) */
381
+ sourceProps?: unknown;
382
+ }
383
+
292
384
  declare type DynamicValue<T, CONTEXT> = T | ((context?: DynamicContext<CONTEXT>) => T);
293
385
 
386
+ export declare type EmojiGlyph = BaseGlyph & {
387
+ emoji: string | {
388
+ text: string;
389
+ };
390
+ };
391
+
392
+ export declare type EmojiInput = {
393
+ text: string;
394
+ } | string;
395
+
294
396
  declare const EmptyCssProperties: React.CSSProperties;
295
397
 
296
398
  /**
@@ -307,6 +409,11 @@ export declare interface EnqueueNotifierOptions extends NotifierOptions {
307
409
  enqueueProps?: Record<string, any>;
308
410
  }
309
411
 
412
+ /**
413
+ * Simple panel to trigger various error scenarios for testing error boundaries and logging.
414
+ */
415
+ export declare const ErrorTestPanel: () => JSX.Element;
416
+
310
417
  declare const focusableNodeNames: Set<string>;
311
418
 
312
419
  /**
@@ -406,7 +513,7 @@ export declare interface ICommand<STATE extends any = any, CONTEXT extends any =
406
513
  label(scope?: string, context?: DynamicContext<CONTEXT>): string;
407
514
  tags(context?: DynamicContext<CONTEXT>): string[];
408
515
  description(context?: DynamicContext<CONTEXT>): string;
409
- icon(context?: DynamicContext<CONTEXT>): React.ReactNode;
516
+ icon(context?: DynamicContext<CONTEXT>): React.ReactElement | string;
410
517
  }
411
518
 
412
519
  export declare interface ICommandCallback<STATE extends any = void> {
@@ -635,6 +742,59 @@ export declare interface ICommandsListeners<STATE extends any, CONTEXT extends a
635
742
  onChange?(commands: ICommands.IGroup): void;
636
743
  }
637
744
 
745
+ export declare type IconGlyph = SvgGlyph | UrlGlyph | EmojiGlyph | ReactGlyph;
746
+
747
+ export declare type IconGlyphInput = ({
748
+ svg: SvgSourceInput;
749
+ }) | ({
750
+ url: UrlInput;
751
+ } & BaseGlyph) | ({
752
+ emoji: EmojiInput;
753
+ } & BaseGlyph) | ({
754
+ react: ReactInput;
755
+ } & BaseGlyph);
756
+
757
+ export declare type IconGlyphKey = string;
758
+
759
+ export declare interface IconGlyphPackPair {
760
+ glyph: IconGlyph;
761
+ pack: IconPack;
762
+ packKey: string;
763
+ }
764
+
765
+ export declare interface IconPack {
766
+ icons: Readonly<Record<IconGlyphKey, IconGlyph>>;
767
+ meta: IconPackMeta;
768
+ }
769
+
770
+ export declare interface IconPackInput {
771
+ icons: IconsInputRecord;
772
+ meta?: Partial<IconPackMeta>;
773
+ overrides?: Record<IconPackKey, IconsInputRecord>;
774
+ }
775
+
776
+ export declare type IconPackKey = string;
777
+
778
+ export declare interface IconPackMeta {
779
+ label: string;
780
+ version: string;
781
+ license: string;
782
+ defaultViewBox: string;
783
+ extends: IconPackKey[];
784
+ }
785
+
786
+ export declare type IconPath = {
787
+ d: string;
788
+ className?: string;
789
+ fill?: string;
790
+ stroke?: string;
791
+ opacity?: number;
792
+ fillRule?: "nonzero" | "evenodd";
793
+ clipRule?: "nonzero" | "evenodd";
794
+ };
795
+
796
+ export declare type IconsInputRecord = Readonly<Record<IconGlyphKey, IconGlyphInput>>;
797
+
638
798
  export declare interface IKeyStroke {
639
799
  readonly key: string;
640
800
  readonly modifiers?: KeyModifiers[];
@@ -907,6 +1067,12 @@ export declare interface OptionsNotifierOptions extends default_2.HTMLAttributes
907
1067
  onValidateOption?: (option?: string) => boolean | Promise<boolean>;
908
1068
  }
909
1069
 
1070
+ declare type PackLoader = () => Promise<IconPack | IconPackInput | PackModule>;
1071
+
1072
+ declare type PackModule = {
1073
+ readonly default: IconPack | IconPackInput;
1074
+ } & Record<string, unknown>;
1075
+
910
1076
  /**
911
1077
  * If returns false don't setup the other listeners
912
1078
  */
@@ -954,6 +1120,19 @@ export declare interface PointerModifiers {
954
1120
  metaKey: boolean;
955
1121
  }
956
1122
 
1123
+ export declare const ReactErrorBoundary: default_2.FC<{
1124
+ children: ReactNode;
1125
+ }>;
1126
+
1127
+ export declare type ReactGlyph<P extends ReactIconProps = ReactIconProps> = BaseGlyph & {
1128
+ react: ReactInput<P>;
1129
+ };
1130
+
1131
+ export declare interface ReactIconProps extends React.HTMLAttributes<HTMLElement> {
1132
+ }
1133
+
1134
+ export declare type ReactInput<P extends ReactIconProps = ReactIconProps> = (props: P) => React.ReactNode;
1135
+
957
1136
  export declare namespace ReactUtils {
958
1137
  export {
959
1138
  detectIt,
@@ -970,6 +1149,10 @@ export declare interface RepeatClickOptions {
970
1149
  timerContinuous?: number;
971
1150
  }
972
1151
 
1152
+ export declare interface ResolveOptions {
1153
+ packKey?: IconPackKey;
1154
+ }
1155
+
973
1156
  export declare const RoundedTab: default_2.FC<RoundedTabProps>;
974
1157
 
975
1158
  export declare interface RoundedTabProps extends default_2.HTMLAttributes<HTMLElement> {
@@ -1047,7 +1230,7 @@ export declare interface ScrollPaneProps extends React.HTMLAttributes<HTMLDivEle
1047
1230
  onScrollViewport?: (scrollPoint: Partial<TopLeft>) => void;
1048
1231
  showHorizontalScrollbar?: boolean;
1049
1232
  showVerticalScrollbar?: boolean;
1050
- createScrollCorner?: (dims: Dimensions) => React.ReactNode;
1233
+ createScrollCorner?: (size: Size) => React.ReactNode;
1051
1234
  createHorizontalScrollbar?: (props: ScrollbarRefProps) => React.ReactNode;
1052
1235
  createVerticalScrollbar?: (props: ScrollbarRefProps) => React.ReactNode;
1053
1236
  /**
@@ -1192,6 +1375,21 @@ export declare interface Style {
1192
1375
  strokeStyle?: string;
1193
1376
  }
1194
1377
 
1378
+ export declare type SvgDef = {
1379
+ paths: IconPath[];
1380
+ viewBox?: string;
1381
+ };
1382
+
1383
+ export declare type SvgGlyph = BaseGlyph & {
1384
+ svg: SvgSource;
1385
+ };
1386
+
1387
+ export declare type SvgRender = (props: React.HTMLAttributes<SVGElement>) => React.ReactNode;
1388
+
1389
+ export declare type SvgSource = SvgDef | SvgRender;
1390
+
1391
+ export declare type SvgSourceInput = (SvgDef & BaseGlyph) | SvgRender | IconPath[] | string[] | string;
1392
+
1195
1393
  export declare interface TextSelectionRange {
1196
1394
  start: number;
1197
1395
  end: number;
@@ -1219,6 +1417,10 @@ declare const toPrettyKeyCode: (key: string) => string;
1219
1417
 
1220
1418
  export declare const toShortcutString: (keyStroke: IKeyStroke, modifierSymbol?: boolean) => string;
1221
1419
 
1420
+ export declare const UncaughtErrorBoundary: default_2.FC<{
1421
+ children: default_2.ReactNode;
1422
+ }>;
1423
+
1222
1424
  export declare interface UndoContext {
1223
1425
  readonly undoManager: UndoManager;
1224
1426
  }
@@ -1245,6 +1447,16 @@ export declare interface UndoManagerResults {
1245
1447
  redo: (count?: number) => void;
1246
1448
  }
1247
1449
 
1450
+ export declare type UrlGlyph = BaseGlyph & {
1451
+ url: {
1452
+ src: string;
1453
+ };
1454
+ };
1455
+
1456
+ export declare type UrlInput = {
1457
+ src: string;
1458
+ } | string;
1459
+
1248
1460
  /**
1249
1461
  * This is a callback hook that is similar to useCallback except in
1250
1462
  * one important way. When it's dependencies change it does
@@ -1404,4 +1616,26 @@ export declare interface VirtualScrollbarProps extends Omit<ScrollbarProps, "onS
1404
1616
  precisionFactor?: number;
1405
1617
  }
1406
1618
 
1619
+ export declare function WalkingIcon(props: WalkingIconProps): JSX.Element;
1620
+
1621
+ /**
1622
+ * This wraps an icon with a walking stroke animation.
1623
+ *
1624
+ * @remarks
1625
+ * This requires a 'delegating' glyph icons to passed.
1626
+ * This will then use CSS animation to create a walking stroke effect.
1627
+ */
1628
+ export declare interface WalkingIconProps extends DynamicIconProps {
1629
+ /** The key of the icon this must be available in the DynamicIconService. */
1630
+ iconKey: IconGlyphKey;
1631
+ /** Animate the stroke marching effect. */
1632
+ isWalking: boolean;
1633
+ /** Map the accent layer to a semantic token; defaults to "info". */
1634
+ themedType?: "accent" | "success" | "info" | "warn" | "error";
1635
+ /** Animation speed in milliseconds. */
1636
+ speed?: number;
1637
+ dashGap?: number;
1638
+ dashLength?: number;
1639
+ }
1640
+
1407
1641
  export { }