socialcalc-ai 1.0.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/README.md +268 -0
- package/components/CellEditModal/CellEditModal.css +584 -0
- package/components/CellEditModal/CellEditModal.tsx +817 -0
- package/components/DemoVideosModal/DemoVideosModal.css +307 -0
- package/components/DemoVideosModal/DemoVideosModal.tsx +289 -0
- package/components/EditableCellsModal/EditableCellsModal.css +346 -0
- package/components/EditableCellsModal/EditableCellsModal.tsx +555 -0
- package/components/HorizontalScrollBar.css +127 -0
- package/components/HorizontalScrollBar.tsx +140 -0
- package/components/RowActionPopover/RowActionPopover.css +95 -0
- package/components/RowActionPopover/RowActionPopover.tsx +82 -0
- package/core/constants.js +1039 -0
- package/core/core.js +7172 -0
- package/core/format-number.js +7034 -0
- package/core/formula.js +1675 -0
- package/core/index.js +28 -0
- package/core/spreadsheet-control.js +7646 -0
- package/core/table-editor.js +8156 -0
- package/index.d.ts +68 -0
- package/index.js +43 -0
- package/modules/device.js +22 -0
- package/modules/editable-cells.js +230 -0
- package/modules/exporters.js +22 -0
- package/modules/formatting.js +258 -0
- package/modules/grid-lines.js +127 -0
- package/modules/history.js +26 -0
- package/modules/horizontal-scroll.js +335 -0
- package/modules/init.js +94 -0
- package/modules/invoice.js +558 -0
- package/modules/listeners.js +531 -0
- package/modules/logos.js +191 -0
- package/modules/plugin-manager.js +208 -0
- package/modules/prompts.js +170 -0
- package/modules/row-col-headers.js +514 -0
- package/modules/sheets.js +151 -0
- package/modules/touch-scroll.js +474 -0
- package/modules/utils.js +317 -0
- package/modules/weight.js +287 -0
- package/package.json +67 -0
- package/utils/imageCompressor.ts +118 -0
- package/utils/scriptLoader.ts +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# SocialCalc AI (`socialcalc-ai`)
|
|
2
|
+
|
|
3
|
+
> **A modernized, modularized, high-performance spreadsheet engine with ES6 module exports, React/Ionic UI components, AI template capabilities, and an extensible plugin system.**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ๐ฆ Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install socialcalc-ai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or with yarn / pnpm:
|
|
14
|
+
```bash
|
|
15
|
+
yarn add socialcalc-ai
|
|
16
|
+
pnpm add socialcalc-ai
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## ๐ Overview
|
|
22
|
+
|
|
23
|
+
This package (`socialcalc-ai`) is a **standalone, framework-agnostic core** with first-class React & Ionic bindings. It takes Dan Bricklin's proven, industrial-strength SocialCalc engine and modernizes it for modern web, mobile, and AI applications:
|
|
24
|
+
- **Clean ES6 module structure** replacing legacy globals.
|
|
25
|
+
- **Pluggable Architecture**: Dynamically toggle features like Grid Lines, 123/ABCD Row-Col Headers, Touch Scroll with momentum, and Editable Cell Locking.
|
|
26
|
+
- **Modern Touch & Mobile Support**: Smooth inertia swipe scrolling without jumping.
|
|
27
|
+
- **Modern Ionic / React Components**: High-fidelity modal editors, responsive horizontal scroll controls, context popovers for row operations, and cell mapping inspectors.
|
|
28
|
+
- **Universal Spreadsheet Commands**: Full support for SocialCalc formulas, cell formatting, font styling, borders, multi-sheet workbooks, and CSV/MSC serialization.
|
|
29
|
+
|
|
30
|
+
> โ ๏ธ **CRITICAL FOR DEVELOPERS & AGENTS**:
|
|
31
|
+
> This package is consumed as a shared standalone dependency across multiple downstream apps. Any breaking changes to public APIs, event signatures, or file paths will impact all applications using it. Always preserve backward compatibility.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ๐ Package Architecture
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
socialcalc/
|
|
39
|
+
โโโ index.js # Main entry point: re-exports core, all modules & React components
|
|
40
|
+
โโโ package.json # Standalone package definition
|
|
41
|
+
โโโ core/ # Core calculation engine & table rendering
|
|
42
|
+
โ โโโ constants.js # SocialCalc constant definitions & default styles
|
|
43
|
+
โ โโโ core.js # Spreadsheet sheet model, cell evaluation, formula AST
|
|
44
|
+
โ โโโ formula.js # Built-in math, logical, string, financial formulas
|
|
45
|
+
โ โโโ format-number.js # Numeric and date formatting routines
|
|
46
|
+
โ โโโ spreadsheet-control.js # Spreadsheet control lifecycle & pane management
|
|
47
|
+
โ โโโ table-editor.js # DOM table editor layout & cursor rendering
|
|
48
|
+
โ โโโ index.js # Assembled core SocialCalc singleton export
|
|
49
|
+
โโโ modules/ # Modularized functional features & plugins
|
|
50
|
+
โ โโโ plugin-manager.js # Central registry for dynamic SocialCalc plugins
|
|
51
|
+
โ โโโ grid-lines.js # Dynamic cell border grid-lines plugin
|
|
52
|
+
โ โโโ row-col-headers.js # 123 Row & ABCD Col headers with resize handles & row selection
|
|
53
|
+
โ โโโ touch-scroll.js # Momentum/inertia mobile touch scroll
|
|
54
|
+
โ โโโ horizontal-scroll.js # Viewport tracking & horizontal scrolling subscriptions
|
|
55
|
+
โ โโโ editable-cells.js # Cell lock & template permission plugin
|
|
56
|
+
โ โโโ listeners.js # Mouse, click, and custom event dispatches
|
|
57
|
+
โ โโโ formatting.js # Cell formatting, font colors, background colors, borders
|
|
58
|
+
โ โโโ sheets.js # Multi-sheet management, switching, renaming
|
|
59
|
+
โ โโโ history.js # Undo / Redo command history stacks
|
|
60
|
+
โ โโโ init.js # Workbook & table editor DOM initialization
|
|
61
|
+
โ โโโ prompts.js # Enhanced input dialogs & modal dispatchers
|
|
62
|
+
โ โโโ exporters.js # HTML, CSV, MSC export helpers
|
|
63
|
+
โ โโโ device.js # Device detection and responsive helpers
|
|
64
|
+
โ โโโ logos.js # Brand/logo helper utilities
|
|
65
|
+
โ โโโ utils.js # Coordinate conversions, DOM utilities
|
|
66
|
+
โ โโโ weight.js # Cell weight/scoring utilities
|
|
67
|
+
โโโ components/ # React & Ionic UI Components
|
|
68
|
+
โ โโโ CellEditModal/ # Rich bottom sheet editor (Text, Formula, Colors, Borders, Images)
|
|
69
|
+
โ โโโ HorizontalScrollBar.tsx # Smooth horizontal navigation bar & track slider
|
|
70
|
+
โ โโโ RowActionPopover/ # Context menu for row insertion & deletion
|
|
71
|
+
โ โโโ EditableCellsModal/ # Template mapping manager & cell lock editor
|
|
72
|
+
โ โโโ DemoVideosModal/ # Formula cheat sheet and interactive tutorials
|
|
73
|
+
โโโ utils/
|
|
74
|
+
โโโ imageCompressor.ts # Client-side image compression for cell image inserts
|
|
75
|
+
โโโ scriptLoader.ts # Dynamic script loader utility
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## ๐ Quick Start in React / Ionic
|
|
81
|
+
|
|
82
|
+
### 1. Installation
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm install socialcalc-ai
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 2. Initialization in React Component
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import React, { useEffect, useState } from "react";
|
|
92
|
+
import * as AppGeneral from "socialcalc-ai";
|
|
93
|
+
import {
|
|
94
|
+
CellEditModal,
|
|
95
|
+
HorizontalScrollBar,
|
|
96
|
+
RowActionPopover,
|
|
97
|
+
} from "socialcalc-ai";
|
|
98
|
+
|
|
99
|
+
const MySpreadsheet: React.FC = () => {
|
|
100
|
+
const [cellEditData, setCellEditData] = useState<any>(null);
|
|
101
|
+
const [showModal, setShowModal] = useState(false);
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
// 1. Initialize DOM workbook container
|
|
105
|
+
const initialMSC = { /* SocialCalc MSC json or save string */ };
|
|
106
|
+
AppGeneral.initializeApp(JSON.stringify(initialMSC));
|
|
107
|
+
|
|
108
|
+
// 2. Enable desired plugins
|
|
109
|
+
AppGeneral.enableRowColHeaders(); // 123 / ABCD headers
|
|
110
|
+
AppGeneral.enableGridLines(); // Cell grid borders
|
|
111
|
+
AppGeneral.enableTouchScroll(); // Smooth touch scrolling
|
|
112
|
+
|
|
113
|
+
// 3. Listen for Cell Edit Modal request events
|
|
114
|
+
const handleCellEdit = (e: any) => {
|
|
115
|
+
setCellEditData(e.detail);
|
|
116
|
+
setShowModal(true);
|
|
117
|
+
};
|
|
118
|
+
window.addEventListener("socialcalc:cell-edit-request", handleCellEdit);
|
|
119
|
+
|
|
120
|
+
return () => {
|
|
121
|
+
window.removeEventListener("socialcalc:cell-edit-request", handleCellEdit);
|
|
122
|
+
};
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div style={{ position: "relative", width: "100%", height: "100vh" }}>
|
|
127
|
+
{/* SocialCalc mounting targets */}
|
|
128
|
+
<div id="container">
|
|
129
|
+
<div id="workbookControl" style={{ display: "none" }}></div>
|
|
130
|
+
<div id="tableeditor"></div>
|
|
131
|
+
<div id="msg"></div>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
{/* Horizontal Scroll Bar */}
|
|
135
|
+
<HorizontalScrollBar />
|
|
136
|
+
|
|
137
|
+
{/* Modern Cell Edit Modal */}
|
|
138
|
+
<CellEditModal
|
|
139
|
+
isOpen={showModal}
|
|
140
|
+
cellData={cellEditData}
|
|
141
|
+
onClose={() => setShowModal(false)}
|
|
142
|
+
/>
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## ๐ Features & Plugins Deep Dive
|
|
151
|
+
|
|
152
|
+
### 1. Row and Column Headers (`modules/row-col-headers.js`)
|
|
153
|
+
Displays standard spreadsheet row numbers (`1, 2, 3...`) and column letters (`A, B, C...`).
|
|
154
|
+
- **Smooth Column Resizing**: Hover or drag right edge of any column header to resize. Live floating tooltip and guideline indicate new column width.
|
|
155
|
+
- **Corner Resize Handle**: Tap/click a column header to display a mobile-friendly corner drag handle (`#sc-col-resize-corner-handle`).
|
|
156
|
+
- **Row Selection**: Clicking a row header selects the full row and fires `socialcalc:row-header-click`.
|
|
157
|
+
- **API**:
|
|
158
|
+
```ts
|
|
159
|
+
AppGeneral.enableRowColHeaders();
|
|
160
|
+
AppGeneral.disableRowColHeaders();
|
|
161
|
+
AppGeneral.toggleRowColHeaders(); // returns boolean
|
|
162
|
+
AppGeneral.isRowColHeadersEnabled(); // returns boolean
|
|
163
|
+
AppGeneral.executeSheetCommand(cmd); // runs SocialCalc sheet command synchronously
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 2. Grid Lines (`modules/grid-lines.js`)
|
|
167
|
+
Provides clean, modern cell grid lines across all table cells.
|
|
168
|
+
- **API**:
|
|
169
|
+
```ts
|
|
170
|
+
AppGeneral.enableGridLines(customCss?: string);
|
|
171
|
+
AppGeneral.disableGridLines();
|
|
172
|
+
AppGeneral.toggleGridLines(); // returns boolean
|
|
173
|
+
AppGeneral.isGridLinesEnabled(); // returns boolean
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 3. Smooth Touch Scroll (`modules/touch-scroll.js`)
|
|
177
|
+
Replaces clunky full-page jumping on mobile swipes with smooth continuous panning and physics-based inertia momentum.
|
|
178
|
+
- **API**:
|
|
179
|
+
```ts
|
|
180
|
+
AppGeneral.enableTouchScroll();
|
|
181
|
+
AppGeneral.disableTouchScroll();
|
|
182
|
+
AppGeneral.toggleTouchScroll(); // returns boolean
|
|
183
|
+
AppGeneral.isTouchScrollEnabled(); // returns boolean
|
|
184
|
+
AppGeneral.configureTouchScroll({ momentumFriction: 0.94 });
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 4. Cell Edit Modal (`components/CellEditModal/`)
|
|
188
|
+
A responsive, high-feature editing sheet replacing legacy browser prompt popups:
|
|
189
|
+
- **Text & Numeric Inputs**: Edit formulas (e.g. `=SUM(B4:C4)`), raw values, or labels.
|
|
190
|
+
- **Formatting Presets**: Currency, Percent, Date, Time, Integer.
|
|
191
|
+
- **Styling**: Bold, Italic, Alignment (Left, Center, Right).
|
|
192
|
+
- **Colors**: 8 curated font colors and 7 cell background colors.
|
|
193
|
+
- **Borders**: All, Top, Bottom, Left, Right with Solid/Dashed/Dotted styles and custom widths.
|
|
194
|
+
- **Image Insertion**: Embed images into cells with automatic client-side compression (`imageCompressor.ts`).
|
|
195
|
+
- **Fallback**: Calling `toggleCellEditModal(false)` automatically falls back to native inline input.
|
|
196
|
+
|
|
197
|
+
### 5. Horizontal Scroll Bar (`components/HorizontalScrollBar.tsx`)
|
|
198
|
+
A dedicated, smooth horizontal control bar for navigating wide sheets:
|
|
199
|
+
- Step buttons for next/prev columns.
|
|
200
|
+
- Draggable slider track with live position indicator.
|
|
201
|
+
- Automatically syncs with spreadsheet viewport when user scrolls or uses keyboard navigation.
|
|
202
|
+
|
|
203
|
+
### 6. Row Action Popover (`components/RowActionPopover/`)
|
|
204
|
+
Context popup that triggers when user taps a row header:
|
|
205
|
+
- **Insert Above**: Calls `executeSheetCommand("insertrow A" + rowNum)`.
|
|
206
|
+
- **Insert Below**: Calls `executeSheetCommand("insertrow A" + (rowNum + 1))`.
|
|
207
|
+
- **Delete Row**: Calls `executeSheetCommand("deleterow A" + rowNum)`.
|
|
208
|
+
|
|
209
|
+
### 7. Editable Cells Mode & Template Mapping (`modules/editable-cells.js`)
|
|
210
|
+
Allows template authors to lock the spreadsheet so end-users can only edit designated cells:
|
|
211
|
+
- **API**:
|
|
212
|
+
```ts
|
|
213
|
+
AppGeneral.enableEditableCellsOnly();
|
|
214
|
+
AppGeneral.disableEditableCellsOnly();
|
|
215
|
+
AppGeneral.toggleEditableCellsOnly();
|
|
216
|
+
AppGeneral.setAppMapping(mappingObj);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 8. Plugin Manager (`modules/plugin-manager.js`)
|
|
220
|
+
Allows developers to register custom plugins with lifecycle hooks:
|
|
221
|
+
- **API**:
|
|
222
|
+
```ts
|
|
223
|
+
AppGeneral.registerPlugin("myPlugin", {
|
|
224
|
+
metadata: { displayName: "My Plugin", description: "Custom feature" },
|
|
225
|
+
enable: () => { ... },
|
|
226
|
+
disable: () => { ... },
|
|
227
|
+
isEnabled: () => true,
|
|
228
|
+
toggle: () => { ... },
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 9. Cell Change & Status Listeners (`modules/listeners.js`)
|
|
233
|
+
Safely intercepts cell updates and spreadsheet status cycles:
|
|
234
|
+
- **API**:
|
|
235
|
+
```ts
|
|
236
|
+
const unsubscribe = AppGeneral.setupCellChangeListener((coord: string) => {
|
|
237
|
+
console.log("Cell modified:", coord);
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
- **Forwarding Safety**: Intercepts `SocialCalc.EditorSheetStatusCallback` while preserving all 4 internal parameters (`recalcdata, status, arg, editor`), avoiding undefined context dereference during render routines.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## ๐ก Events Dispatched by SocialCalc
|
|
245
|
+
|
|
246
|
+
| Event Name | `detail` Payload | Description |
|
|
247
|
+
| :--- | :--- | :--- |
|
|
248
|
+
| `socialcalc:cell-edit-request` | `{ coord, text, okfn, cleanup }` | Dispatched when a cell is clicked/tapped (consumed by `CellEditModal`). |
|
|
249
|
+
| `socialcalc:row-header-click` | `{ rowNum, clientX, clientY }` | Dispatched when a row number is clicked (consumed by `RowActionPopover`). |
|
|
250
|
+
| `socialcalc:cell-change` | `{ coord, value }` | Dispatched when any cell value is successfully modified. |
|
|
251
|
+
| `socialcalc:horizontal-scroll`| `{ currentFirstCol, currentColName, totalCols }` | Dispatched when sheet column scrolls. |
|
|
252
|
+
| `socialcalc:plugin-change` | `{ pluginName, state, allStates }` | Dispatched when any plugin is enabled/disabled. |
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## ๐งช Testing & Verification
|
|
257
|
+
|
|
258
|
+
Run tests anytime you modify the package:
|
|
259
|
+
```bash
|
|
260
|
+
# Run Vitest test suite
|
|
261
|
+
npm test -- --run
|
|
262
|
+
|
|
263
|
+
# Run TypeScript compilation & Vite build
|
|
264
|
+
npm run build
|
|
265
|
+
|
|
266
|
+
# Verify SocialCalc core modularization in Node
|
|
267
|
+
node test-socialcalc.js
|
|
268
|
+
```
|