@griddle/react 0.1.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.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/GriddleGrid.d.ts +45 -0
- package/dist/GriddleGrid.d.ts.map +1 -0
- package/dist/GriddleGrid.js +646 -0
- package/dist/GriddleGrid.js.map +1 -0
- package/dist/LoopGrid.d.ts +3 -0
- package/dist/LoopGrid.d.ts.map +1 -0
- package/dist/LoopGrid.js +569 -0
- package/dist/LoopGrid.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/useGriddle.d.ts +30 -0
- package/dist/useGriddle.d.ts.map +1 -0
- package/dist/useGriddle.js +39 -0
- package/dist/useGriddle.js.map +1 -0
- package/package.json +60 -0
- package/src/GriddleGrid.tsx +825 -0
- package/src/LoopGrid.tsx +709 -0
- package/src/index.ts +5 -0
- package/src/useGriddle.ts +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Trustybits
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @griddle/react
|
|
2
|
+
|
|
3
|
+
React bindings for [Griddle](https://github.com/Trustybits/griddle) — a headless,
|
|
4
|
+
zero-dependency grid/canvas engine. Provides a `<GriddleGrid />` component and a
|
|
5
|
+
`useGriddle()` hook that wrap [`@griddle/core`](https://www.npmjs.com/package/@griddle/core)
|
|
6
|
+
with virtualized rendering, drag/resize handles, and animations.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @griddle/react @griddle/core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`@griddle/core` and `react` are **peer dependencies**. On npm 7+ the peers are
|
|
15
|
+
installed automatically; with Yarn or pnpm, add `@griddle/core` yourself (as
|
|
16
|
+
shown above). `react` is expected to already be in your app (>=17).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { GriddleGrid, useGriddle } from '@griddle/react';
|
|
22
|
+
|
|
23
|
+
export default function App() {
|
|
24
|
+
const api = useGriddle({
|
|
25
|
+
config: { cols: 12, rows: 12, unitWidth: 75, unitHeight: 75 },
|
|
26
|
+
tiles: [
|
|
27
|
+
{ id: '1', col: 0, row: 0, w: 2, h: 2 },
|
|
28
|
+
{ id: '2', col: 2, row: 0, w: 1, h: 1 },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<GriddleGrid
|
|
34
|
+
api={api}
|
|
35
|
+
renderTile={(tile, selected) => (
|
|
36
|
+
<div data-selected={selected}>#{tile.id}</div>
|
|
37
|
+
)}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Loop mode (infinite gallery)
|
|
44
|
+
|
|
45
|
+
Enable `loop` in the config and the content repeats endlessly with drag-to-pan
|
|
46
|
+
physics — no scrollbars:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
const api = useGriddle({
|
|
50
|
+
config: {
|
|
51
|
+
cols: 12, rows: 12, unitWidth: 120, unitHeight: 120,
|
|
52
|
+
loop: { enabled: true, interaction: 'pan' }, // 'pan' = viewer, 'edit' = ghost edit
|
|
53
|
+
},
|
|
54
|
+
tiles,
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`<GriddleGrid>` automatically switches to the loop renderer when
|
|
59
|
+
`config.loop.enabled` is `true`, so most apps never touch the loop component
|
|
60
|
+
directly. For advanced cases where you want to render the loop plane explicitly,
|
|
61
|
+
`GriddleLoopGrid` is also exported and takes the same props as `GriddleGrid`:
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { GriddleLoopGrid } from '@griddle/react';
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
See the [main repository](https://github.com/Trustybits/griddle) for full docs.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT © Trustybits
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import type { GriddleApi } from './useGriddle.js';
|
|
3
|
+
import type { CameraState, Tile } from '@griddle/core';
|
|
4
|
+
export interface GriddleGridProps {
|
|
5
|
+
api: GriddleApi;
|
|
6
|
+
renderTile: (tile: Tile, selected: boolean) => ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
/** Optional container height; default '100%'. */
|
|
10
|
+
height?: number | string;
|
|
11
|
+
/** Whether to render the background grid lines. Default true. */
|
|
12
|
+
showGrid?: boolean;
|
|
13
|
+
/** Controlled selection state. If omitted, selection is managed internally. */
|
|
14
|
+
selection?: Set<string>;
|
|
15
|
+
/** Called whenever the selection changes. */
|
|
16
|
+
onSelectionChange?: (selection: Set<string>) => void;
|
|
17
|
+
/** Called when the user draw-creates a new tile rect on empty space. */
|
|
18
|
+
onDrawCreate?: (rect: {
|
|
19
|
+
col: number;
|
|
20
|
+
row: number;
|
|
21
|
+
w: number;
|
|
22
|
+
h: number;
|
|
23
|
+
}) => void;
|
|
24
|
+
/** Called when a drag gesture begins (pointer down on a tile). */
|
|
25
|
+
onDragStart?: (tileId: string) => void;
|
|
26
|
+
/** Called when a drag gesture ends. `committed` is true if the tile moved. */
|
|
27
|
+
onDragEnd?: (tileId: string, committed: boolean) => void;
|
|
28
|
+
/** Called when a resize gesture begins (pointer down on a handle). */
|
|
29
|
+
onResizeStart?: (tileId: string) => void;
|
|
30
|
+
/** Called when a resize gesture ends. `committed` is true if the tile resized. */
|
|
31
|
+
onResizeEnd?: (tileId: string, committed: boolean) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Loop mode only: fires whenever the camera moves (offset, velocity,
|
|
34
|
+
* isMoving, isDragging). Use it to drive velocity-based visual effects.
|
|
35
|
+
* Called from the render loop — keep the handler cheap.
|
|
36
|
+
*/
|
|
37
|
+
onCameraChange?: (camera: CameraState) => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Renders the grid. When `config.loop.enabled` is set, delegates to the
|
|
41
|
+
* loop-mode renderer (infinitely repeating plane); otherwise renders the
|
|
42
|
+
* standard scrollable grid. Toggling loop at runtime remounts the surface.
|
|
43
|
+
*/
|
|
44
|
+
export declare function GriddleGrid(props: GriddleGridProps): import("react/jsx-runtime").JSX.Element;
|
|
45
|
+
//# sourceMappingURL=Gri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