sheet-happens 0.0.22 → 0.0.24
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/dist/clipboard.d.ts +4 -0
- package/dist/constants.d.ts +45 -0
- package/dist/coordinate.d.ts +18 -0
- package/dist/index.d.ts +21 -71
- package/dist/index.js +2271 -1801
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +2272 -1802
- package/dist/index.modern.js.map +1 -1
- package/dist/layout.d.ts +3 -0
- package/dist/mouse.d.ts +13 -0
- package/dist/props.d.ts +5 -0
- package/dist/render.d.ts +3 -0
- package/dist/scroll.d.ts +4 -0
- package/dist/style.d.ts +4 -0
- package/dist/types.d.ts +112 -0
- package/dist/util.d.ts +7 -0
- package/package.json +1 -1
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { XY, CellLayout, LayoutCache } from './types';
|
|
2
|
+
export declare const makeCellLayout: (freeze: XY, indent: XY, offset: XY, columns: LayoutCache, rows: LayoutCache) => CellLayout;
|
|
3
|
+
export declare const makeLayoutCache: (sizer: (index: number) => number) => LayoutCache;
|
package/dist/mouse.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CellLayout, CellPropertyFunction, Change, Clickable, Rectangle, RowOrColumnPropertyFunction, SheetMouseEvent, SheetStyle, VisibleLayout, XY } from './types';
|
|
2
|
+
import { MouseEvent, PointerEvent, RefObject } from 'react';
|
|
3
|
+
export declare const useMouse: (hitmapRef: RefObject<Clickable[]>, selection: Rectangle, knobArea: Rectangle | null, editMode: boolean, editData: CellPropertyFunction<string>, sourceData: CellPropertyFunction<string | number | null>, canSizeColumn: RowOrColumnPropertyFunction<boolean | null>, canSizeRow: RowOrColumnPropertyFunction<boolean | null>, canOrderColumn: RowOrColumnPropertyFunction<boolean | null>, canOrderRow: RowOrColumnPropertyFunction<boolean | null>, cellLayout: CellLayout, visibleCells: VisibleLayout, sheetStyle: SheetStyle, onEdit?: ((cell: XY) => void) | undefined, onCommit?: (() => void) | undefined, onKnobAreaChange?: ((knobArea: Rectangle | null) => void) | undefined, onDragOffsetChange?: ((dragOffset: XY | null) => void) | undefined, onDropTargetChange?: ((selection: Rectangle | null) => void) | undefined, onSelectionChange?: ((selection: Rectangle, scrollToHead?: boolean | undefined) => void) | undefined, onInvalidateColumn?: ((column: number) => void) | undefined, onInvalidateRow?: ((row: number) => void) | undefined, onChange?: ((changes: Change[]) => void) | undefined, onColumnOrderChange?: ((indices: number[], order: number) => void) | undefined, onRowOrderChange?: ((indices: number[], order: number) => void) | undefined, onCellWidthChange?: ((indices: number[], value: number) => void) | undefined, onCellHeightChange?: ((indices: number[], value: number) => void) | undefined, onRightClick?: ((e: SheetMouseEvent) => void) | undefined, dontCommitEditOnSelectionChange?: boolean | undefined) => {
|
|
4
|
+
knobPosition: XY | null;
|
|
5
|
+
mouseHandlers: {
|
|
6
|
+
onPointerLeave: () => void;
|
|
7
|
+
onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;
|
|
8
|
+
onPointerMove: (e: PointerEvent<HTMLDivElement>) => void;
|
|
9
|
+
onPointerUp: (e: PointerEvent<HTMLDivElement>) => void;
|
|
10
|
+
onDoubleClick: (e: MouseEvent) => void;
|
|
11
|
+
onContextMenu: (e: MouseEvent) => void;
|
|
12
|
+
};
|
|
13
|
+
};
|
package/dist/props.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Direction, XY, CellContentType, CellProperty, CellPropertyFunction, PropTypes, RowOrColumnProperty, RowOrColumnPropertyFunction } from './types';
|
|
2
|
+
export declare const createRowOrColumnProp: <T extends PropTypes>(rowColProp: T | T[] | RowOrColumnPropertyFunction<T> | undefined, defaultValue: T) => RowOrColumnPropertyFunction<T>;
|
|
3
|
+
export declare const createCellProp: <T extends PropTypes>(cellProp: T | T[][] | CellPropertyFunction<T> | undefined, defaultValue: T) => CellPropertyFunction<T>;
|
|
4
|
+
export declare const findApproxMaxEditDataIndex: (editData: CellPropertyFunction<string>) => XY;
|
|
5
|
+
export declare const findInDisplayData: (displayData: CellPropertyFunction<CellContentType>, start: XY, direction: Direction) => XY;
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CellLayout, CellPropertyFunction, RowOrColumnPropertyFunction, InternalSheetStyle, Rectangle, Selection, Clickable, Style, CellContentType, VisibleLayout, XY } from './types';
|
|
2
|
+
export declare const renderSheet: (context: CanvasRenderingContext2D, cellLayout: CellLayout, visibleCells: VisibleLayout, sheetStyle: InternalSheetStyle, cellStyle: CellPropertyFunction<Style>, selection: Rectangle, secondarySelections: Selection[], knobPosition: XY | null, knobArea: Rectangle | null, dragOffset: XY | null, dropTarget: Rectangle | null, columnHeaders: RowOrColumnPropertyFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, displayData: CellPropertyFunction<CellContentType>, dataOffset: XY) => Clickable[];
|
|
3
|
+
export declare const renderCell: (context: CanvasRenderingContext2D, cellContent: CellContentType, style: Style, defaultCellStyle: Required<Style>, xCoord: number, yCoord: number, cellWidth: number, cellHeight: number) => Clickable[];
|
package/dist/scroll.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UIEvent } from 'react';
|
|
2
|
+
import { XY, CellLayout } from './types';
|
|
3
|
+
export declare const useScroll: (offset: XY, maxScroll: XY, cellLayout: CellLayout, onOffsetChange?: ((offset: XY) => void) | undefined, onMaxScrollChange?: ((maxScroll: XY) => void) | undefined) => (e: UIEvent) => void;
|
|
4
|
+
export declare const scrollToCell: (element: HTMLDivElement, cell: XY, view: XY, freeze: XY, offset: XY, maxScroll: XY, cellLayout: CellLayout, callback: (offset: XY, maxScroll: XY) => void) => void;
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InternalSheetStyle, SheetStyle, Style } from './types';
|
|
2
|
+
export declare const resolveSheetStyle: (sheetStyle?: SheetStyle | undefined) => InternalSheetStyle;
|
|
3
|
+
export declare const resolveCellStyle: (optionalStyle: Style, defaultStyle: Required<Style>) => Required<Style>;
|
|
4
|
+
export declare const applyAlignment: (start: number, cellSize: number, style: Required<Style>, imageWidth: number, alignment?: 'left' | 'center' | 'right') => number;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { MouseEvent, PointerEvent, CSSProperties } from 'react';
|
|
2
|
+
export declare type PropTypes = string | number | boolean | Style | CellContentType;
|
|
3
|
+
export declare type CellPropertyFunction<T extends PropTypes> = (x: number, y: number) => T;
|
|
4
|
+
export declare type RowOrColumnPropertyFunction<T extends PropTypes> = (rowOrColIndex: number) => T;
|
|
5
|
+
export declare type CellProperty<T extends PropTypes> = T | T[][] | CellPropertyFunction<T>;
|
|
6
|
+
export declare type RowOrColumnProperty<T extends PropTypes> = T | T[] | RowOrColumnPropertyFunction<T>;
|
|
7
|
+
export declare type CellContentType = null | number | string | CellContent;
|
|
8
|
+
export declare type CellContent = {
|
|
9
|
+
items: CellContentItem[];
|
|
10
|
+
};
|
|
11
|
+
export declare type CellContentItem = {
|
|
12
|
+
content: HTMLImageElement | string | number;
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
width?: number;
|
|
16
|
+
height?: number;
|
|
17
|
+
horizontalAlign?: 'left' | 'right' | 'center';
|
|
18
|
+
onClick?: (e: MouseEvent) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare type XY = [number, number];
|
|
21
|
+
export declare type Rectangle = [XY, XY];
|
|
22
|
+
export declare type Direction = 'up' | 'down' | 'left' | 'right';
|
|
23
|
+
export declare type LayoutCache = {
|
|
24
|
+
getSize: (i: number) => number;
|
|
25
|
+
getStart: (i: number) => number;
|
|
26
|
+
getEnd: (i: number) => number;
|
|
27
|
+
lookupIndex: (i: number, anchor?: number) => number;
|
|
28
|
+
getVersion: () => number;
|
|
29
|
+
clearAfter: (i: number) => void;
|
|
30
|
+
setSizer: (s: (i: number) => number) => void;
|
|
31
|
+
};
|
|
32
|
+
export declare type CellLayout = {
|
|
33
|
+
cellToPixel: (cell: XY, anchor?: XY) => XY;
|
|
34
|
+
pixelToCell: (pixel: XY, anchor?: XY) => XY;
|
|
35
|
+
cellToAbsolute: (cell: XY, anchor?: XY) => XY;
|
|
36
|
+
absoluteToCell: (pixel: XY, anchor?: XY) => XY;
|
|
37
|
+
columnToPixel: (column: number, anchor?: number) => number;
|
|
38
|
+
rowToPixel: (column: number, anchor?: number) => number;
|
|
39
|
+
pixelToColumn: (pixel: number, anchor?: number) => number;
|
|
40
|
+
pixelToRow: (pixel: number, anchor?: number) => number;
|
|
41
|
+
columnToAbsolute: (column: number, anchor?: number) => number;
|
|
42
|
+
rowToAbsolute: (column: number, anchor?: number) => number;
|
|
43
|
+
absoluteToColumn: (pixel: number, anchor?: number) => number;
|
|
44
|
+
absoluteToRow: (pixel: number, anchor?: number) => number;
|
|
45
|
+
getVisibleCells: (view: XY) => VisibleLayout;
|
|
46
|
+
getIndentX: () => number;
|
|
47
|
+
getIndentY: () => number;
|
|
48
|
+
getVersion: () => number;
|
|
49
|
+
};
|
|
50
|
+
export declare type VisibleLayout = {
|
|
51
|
+
columns: number[];
|
|
52
|
+
rows: number[];
|
|
53
|
+
};
|
|
54
|
+
export declare type Selection = {
|
|
55
|
+
span: Rectangle;
|
|
56
|
+
color: string;
|
|
57
|
+
};
|
|
58
|
+
export declare type Clickable = {
|
|
59
|
+
rect: Rectangle;
|
|
60
|
+
obj: CellContentItem;
|
|
61
|
+
};
|
|
62
|
+
export declare type Resizable = {
|
|
63
|
+
rect: Rectangle;
|
|
64
|
+
anchor: number;
|
|
65
|
+
size: number;
|
|
66
|
+
indices: number[];
|
|
67
|
+
};
|
|
68
|
+
export declare type Change = {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
value: string | number | null;
|
|
72
|
+
source?: {
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export declare type ParsedChange = {
|
|
78
|
+
selection: Rectangle;
|
|
79
|
+
changes: Change[];
|
|
80
|
+
};
|
|
81
|
+
export declare type SheetMouseEvent = MouseEvent & {
|
|
82
|
+
cellX: number;
|
|
83
|
+
cellY: number;
|
|
84
|
+
};
|
|
85
|
+
export declare type SheetPointerEvent = PointerEvent & {
|
|
86
|
+
cellX: number;
|
|
87
|
+
cellY: number;
|
|
88
|
+
};
|
|
89
|
+
export declare type InputStyle = Pick<CSSProperties, 'position' | 'top' | 'left' | 'width' | 'height' | 'outline' | 'border' | 'textAlign' | 'color' | 'fontSize' | 'fontFamily'>;
|
|
90
|
+
export declare type Style = {
|
|
91
|
+
color?: string;
|
|
92
|
+
fontSize?: number;
|
|
93
|
+
fontFamily?: string;
|
|
94
|
+
textAlign?: 'right' | 'left' | 'center';
|
|
95
|
+
marginRight?: number;
|
|
96
|
+
marginLeft?: number;
|
|
97
|
+
weight?: string;
|
|
98
|
+
fillColor?: string;
|
|
99
|
+
backgroundColor?: string;
|
|
100
|
+
};
|
|
101
|
+
export declare type SheetStyle = {
|
|
102
|
+
hideGridlines?: boolean;
|
|
103
|
+
hideColumnHeaders?: boolean;
|
|
104
|
+
hideRowHeaders?: boolean;
|
|
105
|
+
hideScrollBars?: boolean;
|
|
106
|
+
freezeColumns?: number;
|
|
107
|
+
freezeRows?: number;
|
|
108
|
+
};
|
|
109
|
+
export declare type InternalSheetStyle = Required<SheetStyle> & {
|
|
110
|
+
columnHeaderHeight: number;
|
|
111
|
+
rowHeaderWidth: number;
|
|
112
|
+
};
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const tail: <T>(list: T[]) => T;
|
|
2
|
+
export declare const clamp: (x: number, min: number, max: number) => number;
|
|
3
|
+
export declare const seq: (n: number, s?: number, d?: number) => number[];
|
|
4
|
+
export declare const isInRange: (x: number, min: number, max: number) => boolean;
|
|
5
|
+
export declare const isInRangeLeft: (x: number, min: number, max: number) => boolean;
|
|
6
|
+
export declare const isInRangeRight: (x: number, min: number, max: number) => boolean;
|
|
7
|
+
export declare const isInRangeCenter: (x: number, min: number, max: number) => boolean;
|