|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <title>GridSheet Preact Demo</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + margin: 0; |
| 10 | + padding: 24px; |
| 11 | + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; |
| 12 | + background: #1a1a2e; |
| 13 | + color: #eee; |
| 14 | + } |
| 15 | + h1 { margin: 0 0 16px; font-size: 1.4rem; } |
| 16 | + .sheet-section { margin-bottom: 24px; } |
| 17 | + .sheet-section h2 { font-size: 1rem; margin: 0 0 8px; color: #aaa; } |
| 18 | + </style> |
| 19 | +</head> |
| 20 | +<body> |
| 21 | + <div id="app"></div> |
| 22 | + |
| 23 | + <script type="module"> |
| 24 | + import { h, render } from "https://cdn.jsdelivr.net/npm/preact@10.29.0/+esm"; |
| 25 | + import htm from "https://cdn.jsdelivr.net/npm/htm@3/+esm"; |
| 26 | + import { GridSheet, useBook } from "https://cdn.jsdelivr.net/npm/@gridsheet/preact-core@3.0.1/+esm"; |
| 27 | + import { allFunctions } from "https://cdn.jsdelivr.net/npm/@gridsheet/functions@3.0.1/+esm"; |
| 28 | + |
| 29 | + const html = htm.bind(h); |
| 30 | + |
| 31 | + function App() { |
| 32 | + const book = useBook({ additionalFunctions: allFunctions }); |
| 33 | + |
| 34 | + return html` |
| 35 | + <div> |
| 36 | + <h1>GridSheet Demo</h1> |
| 37 | + <p style="margin: 0 0 16px; color: #888; font-size: 0.85rem;"> |
| 38 | + A fully functional spreadsheet in a single HTML file — no build tools required. |
| 39 | + Just load <code>@gridsheet/preact-core</code> and <code>@gridsheet/functions</code> from CDN via ESM imports. |
| 40 | + </p> |
| 41 | +
|
| 42 | + <div class="sheet-section"> |
| 43 | + <h2>Sheet1 — Basic Operations & Formulas</h2> |
| 44 | + <${GridSheet} |
| 45 | + book=${book} |
| 46 | + sheetName="Sheet1" |
| 47 | + initialCells=${{ |
| 48 | + A0: { label: "Name" }, |
| 49 | + B0: { label: "Score" }, |
| 50 | + C0: { label: "Grade" }, |
| 51 | + A1: { value: "Alice" }, |
| 52 | + B1: { value: 92 }, |
| 53 | + C1: { value: '=IF(B1>=90,"A",IF(B1>=80,"B","C"))' }, |
| 54 | + A2: { value: "Bob" }, |
| 55 | + B2: { value: 75 }, |
| 56 | + C2: { value: '=IF(B2>=90,"A",IF(B2>=80,"B","C"))' }, |
| 57 | + A3: { value: "Carol" }, |
| 58 | + B3: { value: 88 }, |
| 59 | + C3: { value: '=IF(B3>=90,"A",IF(B3>=80,"B","C"))' }, |
| 60 | + "06": { sortFixed: true }, |
| 61 | + "07": { sortFixed: true }, |
| 62 | + "08": { sortFixed: true }, |
| 63 | + "09": { sortFixed: true }, |
| 64 | + A6: { value: "AVG", style: { fontWeight: "bold", backgroundColor: "#2a2a4a" } }, |
| 65 | + B6: { value: "=AVERAGE(B1:B3)", style: { backgroundColor: "#2a2a4a" } }, |
| 66 | + C6: { value: "", style: { backgroundColor: "#2a2a4a" } }, |
| 67 | + A7: { value: "SUM", style: { fontWeight: "bold", backgroundColor: "#2a2a4a" } }, |
| 68 | + B7: { value: "=SUM(B1:B3)", style: { backgroundColor: "#2a2a4a" } }, |
| 69 | + C7: { value: "", style: { backgroundColor: "#2a2a4a" } }, |
| 70 | + A8: { value: "MAX", style: { fontWeight: "bold", backgroundColor: "#2a2a4a" } }, |
| 71 | + B8: { value: "=MAX(B1:B3)", style: { backgroundColor: "#2a2a4a" } }, |
| 72 | + C8: { value: "", style: { backgroundColor: "#2a2a4a" } }, |
| 73 | + A9: { value: "MIN", style: { fontWeight: "bold", backgroundColor: "#2a2a4a" } }, |
| 74 | + B9: { value: "=MIN(B1:B3)", style: { backgroundColor: "#2a2a4a" } }, |
| 75 | + C9: { value: "", style: { backgroundColor: "#2a2a4a" } }, |
| 76 | + }} |
| 77 | + options=${{ |
| 78 | + mode: "dark", |
| 79 | + sheetHeight: 300, |
| 80 | + }} |
| 81 | + /> |
| 82 | + </div> |
| 83 | +
|
| 84 | + <div class="sheet-section"> |
| 85 | + <h2>Sheet2 — Cross-sheet References</h2> |
| 86 | + <${GridSheet} |
| 87 | + book=${book} |
| 88 | + sheetName="Sheet2" |
| 89 | + initialCells=${{ |
| 90 | + A1: { value: "SUM from Sheet1", style: { fontWeight: "bold" } }, |
| 91 | + A2: { value: "=Sheet1!B7" }, |
| 92 | + B1: { value: "TODAY()", style: { fontWeight: "bold" } }, |
| 93 | + B2: { value: "=TODAY()" }, |
| 94 | + }} |
| 95 | + options=${{ |
| 96 | + mode: "dark", |
| 97 | + sheetHeight: 200, |
| 98 | + }} |
| 99 | + /> |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + `; |
| 103 | + } |
| 104 | + |
| 105 | + render(html`<${App} />`, document.getElementById("app")); |
| 106 | + </script> |
| 107 | +</body> |
| 108 | +</html> |
0 commit comments