|
| 1 | +# @gridsheet/svelte-core |
| 2 | + |
| 3 | +Spreadsheet component for Svelte 5 |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @gridsheet/svelte-core @gridsheet/functions |
| 9 | +``` |
| 10 | + |
| 11 | +### Peer Dependencies |
| 12 | + |
| 13 | +This package requires the following peer dependency: |
| 14 | + |
| 15 | +- `svelte` ^5.0.0 |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +```svelte |
| 20 | +<script> |
| 21 | + import { GridSheet } from '@gridsheet/svelte-core'; |
| 22 | + import { useSpellbook } from '@gridsheet/svelte-core/spellbook'; // requires @gridsheet/functions |
| 23 | + const book = useSpellbook(); |
| 24 | +</script> |
| 25 | +
|
| 26 | +<GridSheet |
| 27 | + {book} |
| 28 | + initialCells={{ |
| 29 | + A1: { value: 'Hello' }, |
| 30 | + B1: { value: 'Svelte', style: { backgroundColor: '#448888' } }, |
| 31 | + A2: { value: 123 }, |
| 32 | + B2: { value: 456 }, |
| 33 | + A3: { value: 789 }, |
| 34 | + C6: { value: '=SUM(A2:B2)' }, |
| 35 | + }} |
| 36 | + options={{ |
| 37 | + mode: 'dark', |
| 38 | + }} |
| 39 | + sheetName="Sheet1" |
| 40 | +/> |
| 41 | +
|
| 42 | +<GridSheet |
| 43 | + {book} |
| 44 | + initialCells={{ |
| 45 | + C3: { value: '=SUM(Sheet1!A2:B3)' }, |
| 46 | + }} |
| 47 | + options={{}} |
| 48 | + sheetName="Sheet2" |
| 49 | +/> |
| 50 | +``` |
| 51 | + |
| 52 | +## Components |
| 53 | + |
| 54 | +### GridSheet |
| 55 | + |
| 56 | +The main spreadsheet component for Svelte 5 applications. |
| 57 | + |
| 58 | +**Props:** |
| 59 | +- `book` - Writable store for cross-sheet data binding and state management |
| 60 | +- `initialCells` - Initial cell data with values, styles, and formulas |
| 61 | +- `options` - GridSheet options (e.g., mode: 'dark') |
| 62 | +- `sheetName` - Name of the sheet |
| 63 | +- `sheetRef` - Ref object to access sheet handle |
| 64 | +- `storeRef` - Ref object to access store handle |
| 65 | +- `className` - CSS class name |
| 66 | +- `style` - Inline styles |
| 67 | + |
| 68 | +### useSpellbook |
| 69 | + |
| 70 | +Creates a reactive book with all extended functions (`@gridsheet/functions`) pre-loaded. Returns a `Writable<BookType>`. |
| 71 | + |
| 72 | +```js |
| 73 | +import { useSpellbook } from '@gridsheet/svelte-core/spellbook'; // requires @gridsheet/functions |
| 74 | +const book = useSpellbook({ /* RegistryProps */ }); |
| 75 | +``` |
| 76 | + |
| 77 | +### useBook |
| 78 | + |
| 79 | +Same as `useSpellbook` but without extended functions. |
| 80 | + |
| 81 | +```js |
| 82 | +import { useBook } from '@gridsheet/svelte-core'; |
| 83 | +const book = useBook({ /* RegistryProps */ }); |
| 84 | +``` |
| 85 | + |
| 86 | +## Exports |
| 87 | + |
| 88 | +This package exports: |
| 89 | + |
| 90 | +- All core GridSheet functionality from `@gridsheet/preact-core` |
| 91 | +- `GridSheet` - Svelte 5 component |
| 92 | +- `useBook` - Svelte-specific reactive book using writable store |
| 93 | +- `@gridsheet/svelte-core/spellbook` - `useSpellbook`, `createSpellbook` |
| 94 | + |
| 95 | +## Docs |
| 96 | + |
| 97 | +- [GridSheet document](https://gridsheet.walkframe.com/) |
| 98 | +- [Examples](https://gridsheet.walkframe.com/examples/case1) |
| 99 | + |
| 100 | +## Development |
| 101 | + |
| 102 | +```bash |
| 103 | +# Start development server |
| 104 | +pnpm dev |
| 105 | + |
| 106 | +# Build the package |
| 107 | +pnpm build |
| 108 | +``` |
| 109 | + |
| 110 | +## License |
| 111 | + |
| 112 | +Apache-2.0 |
0 commit comments