@sheetxl/utils-react 0.7.4 → 0.7.6

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.4",
4
+ "version": "0.7.6",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -20,14 +20,27 @@
20
20
  "*.css",
21
21
  "**/*.css"
22
22
  ],
23
+ "homepage": "https://sheetxl.com",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/sheetxl/sheetxl.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/sheetxl/sheetxl/issues"
30
+ },
23
31
  "keywords": [
24
32
  "sheetxl",
25
33
  "spreadsheet",
34
+ "javascript",
35
+ "typescript",
36
+ "data grid",
37
+ "excel",
38
+ "xlsx",
26
39
  "utilities",
27
40
  "react"
28
41
  ],
29
42
  "dependencies": {
30
- "@sheetxl/utils": "^0.7.4",
43
+ "@sheetxl/utils": "^0.7.6",
31
44
  "clsx": "^2.1.1",
32
45
  "detect-it": "^4.0.1",
33
46
  "react-merge-refs": "^3.0.2",
package/types/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { CellCoords } from '@sheetxl/utils';
2
2
  import { default as default_2 } from 'react';
3
- import { DelegatingNotifier } from '@sheetxl/utils';
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,8 +292,25 @@ export declare const defaultCreateScrollEndButton: (props: ScrollButtonProps) =>
231
292
  */
232
293
  export declare const defaultCreateScrollStartButton: (props: ScrollButtonProps) => default_2.ReactElement;
233
294
 
234
- export declare class DelegatingReactNotifier extends DelegatingNotifier implements IReactNotifier {
235
- setDelegate(delegate: Partial<IReactNotifier> | null): void;
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
+
310
+ export declare class DefaultReactNotifier extends DefaultNotifier implements IReactNotifier {
311
+ /** @inheritdoc IReactNotifier.setOverrides */
312
+ setOverrides(overrides: Partial<IReactNotifier> | null): void;
313
+ /** @inheritdoc IReactNotifier.getDelegate */
236
314
  getDelegate(): Partial<IReactNotifier> | null;
237
315
  /** @inheritdoc IReactNotifier.showMessage */
238
316
  showMessage(message: string | default_2.ReactNode, options?: EnqueueNotifierOptions): void;
@@ -287,8 +365,34 @@ export declare interface DevicePixelRatioOptions {
287
365
 
288
366
  declare type DynamicContext<CONTEXT> = CONTEXT | (() => CONTEXT);
289
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
+
290
384
  declare type DynamicValue<T, CONTEXT> = T | ((context?: DynamicContext<CONTEXT>) => T);
291
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
+
292
396
  declare const EmptyCssProperties: React.CSSProperties;
293
397
 
294
398
  /**
@@ -404,7 +508,7 @@ export declare interface ICommand<STATE extends any = any, CONTEXT extends any =
404
508
  label(scope?: string, context?: DynamicContext<CONTEXT>): string;
405
509
  tags(context?: DynamicContext<CONTEXT>): string[];
406
510
  description(context?: DynamicContext<CONTEXT>): string;
407
- icon(context?: DynamicContext<CONTEXT>): React.ReactNode;
511
+ icon(context?: DynamicContext<CONTEXT>): React.ReactElement | string;
408
512
  }
409
513
 
410
514
  export declare interface ICommandCallback<STATE extends any = void> {
@@ -633,6 +737,59 @@ export declare interface ICommandsListeners<STATE extends any, CONTEXT extends a
633
737
  onChange?(commands: ICommands.IGroup): void;
634
738
  }
635
739
 
740
+ export declare type IconGlyph = SvgGlyph | UrlGlyph | EmojiGlyph | ReactGlyph;
741
+
742
+ export declare type IconGlyphInput = ({
743
+ svg: SvgSourceInput;
744
+ }) | ({
745
+ url: UrlInput;
746
+ } & BaseGlyph) | ({
747
+ emoji: EmojiInput;
748
+ } & BaseGlyph) | ({
749
+ react: ReactInput;
750
+ } & BaseGlyph);
751
+
752
+ export declare type IconGlyphKey = string;
753
+
754
+ export declare interface IconGlyphPackPair {
755
+ glyph: IconGlyph;
756
+ pack: IconPack;
757
+ packKey: string;
758
+ }
759
+
760
+ export declare interface IconPack {
761
+ icons: Readonly<Record<IconGlyphKey, IconGlyph>>;
762
+ meta: IconPackMeta;
763
+ }
764
+
765
+ export declare interface IconPackInput {
766
+ icons: IconsInputRecord;
767
+ meta?: Partial<IconPackMeta>;
768
+ overrides?: Record<IconPackKey, IconsInputRecord>;
769
+ }
770
+
771
+ export declare type IconPackKey = string;
772
+
773
+ export declare interface IconPackMeta {
774
+ label: string;
775
+ version: string;
776
+ license: string;
777
+ defaultViewBox: string;
778
+ extends: IconPackKey[];
779
+ }
780
+
781
+ export declare type IconPath = {
782
+ d: string;
783
+ className?: string;
784
+ fill?: string;
785
+ stroke?: string;
786
+ opacity?: number;
787
+ fillRule?: "nonzero" | "evenodd";
788
+ clipRule?: "nonzero" | "evenodd";
789
+ };
790
+
791
+ export declare type IconsInputRecord = Readonly<Record<IconGlyphKey, IconGlyphInput>>;
792
+
636
793
  export declare interface IKeyStroke {
637
794
  readonly key: string;
638
795
  readonly modifiers?: KeyModifiers[];
@@ -905,6 +1062,12 @@ export declare interface OptionsNotifierOptions extends default_2.HTMLAttributes
905
1062
  onValidateOption?: (option?: string) => boolean | Promise<boolean>;
906
1063
  }
907
1064
 
1065
+ declare type PackLoader = () => Promise<IconPack | IconPackInput | PackModule>;
1066
+
1067
+ declare type PackModule = {
1068
+ readonly default: IconPack | IconPackInput;
1069
+ } & Record<string, unknown>;
1070
+
908
1071
  /**
909
1072
  * If returns false don't setup the other listeners
910
1073
  */
@@ -952,6 +1115,15 @@ export declare interface PointerModifiers {
952
1115
  metaKey: boolean;
953
1116
  }
954
1117
 
1118
+ export declare type ReactGlyph<P extends ReactIconProps = ReactIconProps> = BaseGlyph & {
1119
+ react: ReactInput<P>;
1120
+ };
1121
+
1122
+ export declare interface ReactIconProps extends React.HTMLAttributes<HTMLElement> {
1123
+ }
1124
+
1125
+ export declare type ReactInput<P extends ReactIconProps = ReactIconProps> = (props: P) => React.ReactNode;
1126
+
955
1127
  export declare namespace ReactUtils {
956
1128
  export {
957
1129
  detectIt,
@@ -968,6 +1140,10 @@ export declare interface RepeatClickOptions {
968
1140
  timerContinuous?: number;
969
1141
  }
970
1142
 
1143
+ export declare interface ResolveOptions {
1144
+ packKey?: IconPackKey;
1145
+ }
1146
+
971
1147
  export declare const RoundedTab: default_2.FC<RoundedTabProps>;
972
1148
 
973
1149
  export declare interface RoundedTabProps extends default_2.HTMLAttributes<HTMLElement> {
@@ -1045,7 +1221,7 @@ export declare interface ScrollPaneProps extends React.HTMLAttributes<HTMLDivEle
1045
1221
  onScrollViewport?: (scrollPoint: Partial<TopLeft>) => void;
1046
1222
  showHorizontalScrollbar?: boolean;
1047
1223
  showVerticalScrollbar?: boolean;
1048
- createScrollCorner?: (dims: Dimensions) => React.ReactNode;
1224
+ createScrollCorner?: (size: Size) => React.ReactNode;
1049
1225
  createHorizontalScrollbar?: (props: ScrollbarRefProps) => React.ReactNode;
1050
1226
  createVerticalScrollbar?: (props: ScrollbarRefProps) => React.ReactNode;
1051
1227
  /**
@@ -1190,6 +1366,21 @@ export declare interface Style {
1190
1366
  strokeStyle?: string;
1191
1367
  }
1192
1368
 
1369
+ export declare type SvgDef = {
1370
+ paths: IconPath[];
1371
+ viewBox?: string;
1372
+ };
1373
+
1374
+ export declare type SvgGlyph = BaseGlyph & {
1375
+ svg: SvgSource;
1376
+ };
1377
+
1378
+ export declare type SvgRender = (props: React.HTMLAttributes<SVGElement>) => React.ReactNode;
1379
+
1380
+ export declare type SvgSource = SvgDef | SvgRender;
1381
+
1382
+ export declare type SvgSourceInput = (SvgDef & BaseGlyph) | SvgRender | IconPath[] | string[] | string;
1383
+
1193
1384
  export declare interface TextSelectionRange {
1194
1385
  start: number;
1195
1386
  end: number;
@@ -1243,6 +1434,16 @@ export declare interface UndoManagerResults {
1243
1434
  redo: (count?: number) => void;
1244
1435
  }
1245
1436
 
1437
+ export declare type UrlGlyph = BaseGlyph & {
1438
+ url: {
1439
+ src: string;
1440
+ };
1441
+ };
1442
+
1443
+ export declare type UrlInput = {
1444
+ src: string;
1445
+ } | string;
1446
+
1246
1447
  /**
1247
1448
  * This is a callback hook that is similar to useCallback except in
1248
1449
  * one important way. When it's dependencies change it does
@@ -1402,4 +1603,26 @@ export declare interface VirtualScrollbarProps extends Omit<ScrollbarProps, "onS
1402
1603
  precisionFactor?: number;
1403
1604
  }
1404
1605
 
1606
+ export declare function WalkingIcon(props: WalkingIconProps): JSX.Element;
1607
+
1608
+ /**
1609
+ * This wraps an icon with a walking stroke animation.
1610
+ *
1611
+ * @remarks
1612
+ * This requires a 'delegating' glyph icons to passed.
1613
+ * This will then use CSS animation to create a walking stroke effect.
1614
+ */
1615
+ export declare interface WalkingIconProps extends DynamicIconProps {
1616
+ /** The key of the icon this must be available in the DynamicIconService. */
1617
+ iconKey: IconGlyphKey;
1618
+ /** Animate the stroke marching effect. */
1619
+ isWalking: boolean;
1620
+ /** Map the accent layer to a semantic token; defaults to "info". */
1621
+ themedType?: "accent" | "success" | "info" | "warn" | "error";
1622
+ /** Animation speed in milliseconds. */
1623
+ speed?: number;
1624
+ dashGap?: number;
1625
+ dashLength?: number;
1626
+ }
1627
+
1405
1628
  export { }