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/modules/utils.js
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
// Utility functions for storage, formatting UI, etc.
|
|
2
|
+
import {
|
|
3
|
+
getCellFormatting,
|
|
4
|
+
applySelectedFormatting,
|
|
5
|
+
resetCellFormatting,
|
|
6
|
+
} from "./formatting.js";
|
|
7
|
+
|
|
8
|
+
let SocialCalc;
|
|
9
|
+
|
|
10
|
+
// Ensure SocialCalc is loaded from the global scope
|
|
11
|
+
if (typeof window !== "undefined" && window.SocialCalc) {
|
|
12
|
+
SocialCalc = window.SocialCalc;
|
|
13
|
+
} else if (typeof global !== "undefined" && global.SocialCalc) {
|
|
14
|
+
SocialCalc = global.SocialCalc;
|
|
15
|
+
} else {
|
|
16
|
+
console.error("SocialCalc not found in global scope");
|
|
17
|
+
SocialCalc = {}; // Fallback to prevent errors
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function saveAs() {
|
|
21
|
+
return new Promise(function (resolve, reject) {
|
|
22
|
+
navigator.notification.prompt(
|
|
23
|
+
"Please enter the filename", // message
|
|
24
|
+
function (results) {
|
|
25
|
+
if (results.buttonIndex === 2) {
|
|
26
|
+
resolve(results.input1);
|
|
27
|
+
}
|
|
28
|
+
}, // callback to invoke
|
|
29
|
+
"Save as", // title
|
|
30
|
+
["Cancel", "Save"], // buttonLabels
|
|
31
|
+
"" // defaultText
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getAllOldFiles() {
|
|
37
|
+
return new Promise(function (resolve, reject) {
|
|
38
|
+
var files = {};
|
|
39
|
+
|
|
40
|
+
for (var i = 0; i < window.localStorage.length; i++) {
|
|
41
|
+
if (window.localStorage.key(i).length >= 30) continue;
|
|
42
|
+
var filename = window.localStorage.key(i);
|
|
43
|
+
|
|
44
|
+
if (filename === "logoArray") continue;
|
|
45
|
+
if (filename === "inapp") continue;
|
|
46
|
+
if (filename === "sound") continue;
|
|
47
|
+
if (filename === "cloudInapp") continue;
|
|
48
|
+
if (filename === "inapplocal") continue;
|
|
49
|
+
if (filename === "inappPurchase") continue;
|
|
50
|
+
if (filename === "flag") continue;
|
|
51
|
+
if (filename === "share") continue;
|
|
52
|
+
if (filename === "cellArray") continue;
|
|
53
|
+
if (filename === "sk_receiptForProduct") continue;
|
|
54
|
+
if (filename === "sk_receiptForTransaction") continue;
|
|
55
|
+
if (
|
|
56
|
+
filename === "didTutorial" ||
|
|
57
|
+
filename === "customise" ||
|
|
58
|
+
filename === "rename" ||
|
|
59
|
+
filename === "choice"
|
|
60
|
+
)
|
|
61
|
+
continue;
|
|
62
|
+
/// console.log(filename);
|
|
63
|
+
var filedata = decodeURIComponent(window.localStorage.getItem(filename));
|
|
64
|
+
|
|
65
|
+
files[filename] = filedata;
|
|
66
|
+
}
|
|
67
|
+
// console.log(files);
|
|
68
|
+
resolve(files);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function deleteAllOldFiles(files) {
|
|
73
|
+
return new Promise(function (resolve, reject) {
|
|
74
|
+
for (var i in files) {
|
|
75
|
+
console.log("Removing.." + i);
|
|
76
|
+
window.localStorage.removeItem(i);
|
|
77
|
+
}
|
|
78
|
+
resolve(true);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function showFormattingButtons(coord, callback) {
|
|
83
|
+
console.log("Showing formatting buttons for cell:", coord);
|
|
84
|
+
|
|
85
|
+
if (window.cellFormattingInstance) {
|
|
86
|
+
window.cellFormattingInstance.hideButtons();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
window.cellFormattingInstance = {
|
|
90
|
+
coord: coord,
|
|
91
|
+
callback: callback,
|
|
92
|
+
hideButtons: function () {
|
|
93
|
+
const existingButtons = document.getElementById(
|
|
94
|
+
"cell-formatting-buttons"
|
|
95
|
+
);
|
|
96
|
+
if (existingButtons) {
|
|
97
|
+
existingButtons.remove();
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const control = SocialCalc.GetCurrentWorkBookControl();
|
|
103
|
+
const editor = control.workbook.spreadsheet.editor;
|
|
104
|
+
|
|
105
|
+
// Get current cell formatting
|
|
106
|
+
const currentFormatting = getCellFormatting(coord);
|
|
107
|
+
console.log("Current cell formatting:", currentFormatting);
|
|
108
|
+
|
|
109
|
+
// Create floating formatting buttons
|
|
110
|
+
const buttonsContainer = document.createElement("div");
|
|
111
|
+
buttonsContainer.id = "cell-formatting-buttons";
|
|
112
|
+
|
|
113
|
+
// Check if dark theme is active
|
|
114
|
+
const isDarkTheme =
|
|
115
|
+
document.body.classList.contains("dark-theme") ||
|
|
116
|
+
document.querySelector(".dark-theme") !== null;
|
|
117
|
+
|
|
118
|
+
const baseStyles = `
|
|
119
|
+
position: fixed;
|
|
120
|
+
top: 20px;
|
|
121
|
+
right: 20px;
|
|
122
|
+
z-index: 10000;
|
|
123
|
+
border-radius: 8px;
|
|
124
|
+
padding: 12px;
|
|
125
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
|
126
|
+
display: flex;
|
|
127
|
+
flex-direction: column;
|
|
128
|
+
gap: 8px;
|
|
129
|
+
min-width: 220px;
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
const themeStyles = isDarkTheme
|
|
133
|
+
? "background: #1a1a1a; border: 1px solid #444; color: #fff;"
|
|
134
|
+
: "background: white; border: 1px solid #ccc; color: #000;";
|
|
135
|
+
|
|
136
|
+
buttonsContainer.style.cssText = baseStyles + themeStyles;
|
|
137
|
+
|
|
138
|
+
// Font Size Section
|
|
139
|
+
const fontSizeSection = document.createElement("div");
|
|
140
|
+
const fontSizeButtonStyle = isDarkTheme
|
|
141
|
+
? "padding: 4px 8px; border: 1px solid #555; border-radius: 4px; background: #2a2a2a; color: #fff; cursor: pointer; font-size: 10px;"
|
|
142
|
+
: "padding: 4px 8px; border: 1px solid #ccc; border-radius: 4px; background: #f8f9fa; color: #000; cursor: pointer; font-size: 10px;";
|
|
143
|
+
|
|
144
|
+
fontSizeSection.innerHTML = `
|
|
145
|
+
<div style="font-weight: bold; margin-bottom: 8px; font-size: 14px;">Font Size</div>
|
|
146
|
+
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
|
|
147
|
+
<button class="format-btn" data-action="font-size" data-value="8pt" style="${fontSizeButtonStyle}">8pt</button>
|
|
148
|
+
<button class="format-btn" data-action="font-size" data-value="10pt" style="${fontSizeButtonStyle}">10pt</button>
|
|
149
|
+
<button class="format-btn" data-action="font-size" data-value="12pt" style="${fontSizeButtonStyle}">12pt</button>
|
|
150
|
+
<button class="format-btn" data-action="font-size" data-value="14pt" style="${fontSizeButtonStyle}">14pt</button>
|
|
151
|
+
<button class="format-btn" data-action="font-size" data-value="16pt" style="${fontSizeButtonStyle}">16pt</button>
|
|
152
|
+
<button class="format-btn" data-action="font-size" data-value="18pt" style="${fontSizeButtonStyle}">18pt</button>
|
|
153
|
+
</div>
|
|
154
|
+
`;
|
|
155
|
+
|
|
156
|
+
// Font Color Section
|
|
157
|
+
const fontColorSection = document.createElement("div");
|
|
158
|
+
fontColorSection.innerHTML = `
|
|
159
|
+
<div style="font-weight: bold; margin-bottom: 8px; font-size: 14px;">Font Color</div>
|
|
160
|
+
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
|
|
161
|
+
<button class="format-btn" data-action="font-color" data-value="black" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: black; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
162
|
+
<button class="format-btn" data-action="font-color" data-value="red" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: red; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
163
|
+
<button class="format-btn" data-action="font-color" data-value="blue" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: blue; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
164
|
+
<button class="format-btn" data-action="font-color" data-value="green" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: green; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
165
|
+
<button class="format-btn" data-action="font-color" data-value="yellow" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: yellow; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
166
|
+
<button class="format-btn" data-action="font-color" data-value="purple" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: purple; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
167
|
+
</div>
|
|
168
|
+
`;
|
|
169
|
+
|
|
170
|
+
// Background Color Section
|
|
171
|
+
const bgColorSection = document.createElement("div");
|
|
172
|
+
bgColorSection.innerHTML = `
|
|
173
|
+
<div style="font-weight: bold; margin-bottom: 8px; font-size: 14px;">Background Color</div>
|
|
174
|
+
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
|
|
175
|
+
<button class="format-btn" data-action="bg-color" data-value="white" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: white; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
176
|
+
<button class="format-btn" data-action="bg-color" data-value="lightgray" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: lightgray; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
177
|
+
<button class="format-btn" data-action="bg-color" data-value="lightblue" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: lightblue; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
178
|
+
<button class="format-btn" data-action="bg-color" data-value="lightgreen" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: lightgreen; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
179
|
+
<button class="format-btn" data-action="bg-color" data-value="lightyellow" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: lightyellow; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
180
|
+
<button class="format-btn" data-action="bg-color" data-value="lightpink" style="padding: 8px; border: 1px solid #ccc; border-radius: 4px; background: lightpink; cursor: pointer; min-width: 30px; min-height: 30px;"></button>
|
|
181
|
+
</div>
|
|
182
|
+
`;
|
|
183
|
+
|
|
184
|
+
// Current cell info section
|
|
185
|
+
const cellInfoSection = document.createElement("div");
|
|
186
|
+
cellInfoSection.innerHTML = `
|
|
187
|
+
<div style="font-weight: bold; margin-bottom: 8px; font-size: 14px; border-bottom: 1px solid ${
|
|
188
|
+
isDarkTheme ? "#555" : "#eee"
|
|
189
|
+
}; padding-bottom: 8px;">
|
|
190
|
+
Cell ${coord} Formatting
|
|
191
|
+
</div>
|
|
192
|
+
`;
|
|
193
|
+
|
|
194
|
+
// Action Buttons
|
|
195
|
+
const actionButtons = document.createElement("div");
|
|
196
|
+
actionButtons.innerHTML = `
|
|
197
|
+
<div style="display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid ${
|
|
198
|
+
isDarkTheme ? "#555" : "#eee"
|
|
199
|
+
};">
|
|
200
|
+
<button id="apply-formatting" style="padding: 8px 16px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; flex: 1;">Apply</button>
|
|
201
|
+
<button id="reset-formatting" style="padding: 8px 16px; background: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer; flex: 1;">Reset</button>
|
|
202
|
+
<button id="cancel-formatting" style="padding: 8px 16px; background: #6c757d; color: white; border: none; border-radius: 4px; cursor: pointer; flex: 1;">Cancel</button>
|
|
203
|
+
</div>
|
|
204
|
+
`;
|
|
205
|
+
|
|
206
|
+
buttonsContainer.appendChild(cellInfoSection);
|
|
207
|
+
buttonsContainer.appendChild(fontSizeSection);
|
|
208
|
+
buttonsContainer.appendChild(fontColorSection);
|
|
209
|
+
buttonsContainer.appendChild(bgColorSection);
|
|
210
|
+
buttonsContainer.appendChild(actionButtons);
|
|
211
|
+
|
|
212
|
+
document.body.appendChild(buttonsContainer);
|
|
213
|
+
|
|
214
|
+
let selectedFormatting = {
|
|
215
|
+
fontSize: null,
|
|
216
|
+
fontColor: null,
|
|
217
|
+
bgColor: null,
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// Handle button clicks
|
|
221
|
+
buttonsContainer.addEventListener("click", function (e) {
|
|
222
|
+
if (e.target.classList.contains("format-btn")) {
|
|
223
|
+
const action = e.target.getAttribute("data-action");
|
|
224
|
+
const value = e.target.getAttribute("data-value");
|
|
225
|
+
|
|
226
|
+
// Remove previous selection in this category
|
|
227
|
+
const categoryButtons = buttonsContainer.querySelectorAll(
|
|
228
|
+
`[data-action="${action}"]`
|
|
229
|
+
);
|
|
230
|
+
categoryButtons.forEach((btn) => {
|
|
231
|
+
if (action === "font-size") {
|
|
232
|
+
btn.style.border = isDarkTheme ? "1px solid #555" : "1px solid #ccc";
|
|
233
|
+
} else {
|
|
234
|
+
btn.style.border = "1px solid #ccc";
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// Highlight selected button
|
|
239
|
+
e.target.style.border = "3px solid #007bff";
|
|
240
|
+
|
|
241
|
+
// Store selection
|
|
242
|
+
if (action === "font-size") {
|
|
243
|
+
selectedFormatting.fontSize = value;
|
|
244
|
+
} else if (action === "font-color") {
|
|
245
|
+
selectedFormatting.fontColor = value;
|
|
246
|
+
} else if (action === "bg-color") {
|
|
247
|
+
selectedFormatting.bgColor = value;
|
|
248
|
+
}
|
|
249
|
+
} else if (e.target.id === "apply-formatting") {
|
|
250
|
+
applySelectedFormatting(coord, selectedFormatting);
|
|
251
|
+
window.cellFormattingInstance.hideButtons();
|
|
252
|
+
if (callback) callback();
|
|
253
|
+
} else if (e.target.id === "reset-formatting") {
|
|
254
|
+
resetCellFormatting(coord);
|
|
255
|
+
window.cellFormattingInstance.hideButtons();
|
|
256
|
+
if (callback) callback();
|
|
257
|
+
} else if (e.target.id === "cancel-formatting") {
|
|
258
|
+
window.cellFormattingInstance.hideButtons();
|
|
259
|
+
if (callback) callback();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Add close on click outside
|
|
264
|
+
setTimeout(() => {
|
|
265
|
+
document.addEventListener("click", function closeOnClickOutside(e) {
|
|
266
|
+
if (!buttonsContainer.contains(e.target)) {
|
|
267
|
+
window.cellFormattingInstance.hideButtons();
|
|
268
|
+
document.removeEventListener("click", closeOnClickOutside);
|
|
269
|
+
if (callback) callback();
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}, 100);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Additional helper functions for cell formatting
|
|
276
|
+
export function formatCurrentCell(options = {}) {
|
|
277
|
+
const control = SocialCalc.GetCurrentWorkBookControl();
|
|
278
|
+
if (!control || !control.workbook || !control.workbook.spreadsheet) {
|
|
279
|
+
console.warn("Spreadsheet not initialized");
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const editor = control.workbook.spreadsheet.editor;
|
|
284
|
+
const coord = editor.ecell.coord;
|
|
285
|
+
|
|
286
|
+
if (!coord) {
|
|
287
|
+
console.warn("No active cell");
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
showFormattingButtons(coord, options.callback);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function toggleCellFormatting() {
|
|
295
|
+
const control = SocialCalc.GetCurrentWorkBookControl();
|
|
296
|
+
if (!control || !control.workbook || !control.workbook.spreadsheet) {
|
|
297
|
+
console.warn("Spreadsheet not initialized");
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const editor = control.workbook.spreadsheet.editor;
|
|
302
|
+
const coord = editor.ecell.coord;
|
|
303
|
+
|
|
304
|
+
if (!coord) {
|
|
305
|
+
console.warn("No active cell");
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Check if formatting buttons are already shown
|
|
310
|
+
const existingButtons = document.getElementById("cell-formatting-buttons");
|
|
311
|
+
if (existingButtons) {
|
|
312
|
+
existingButtons.remove();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
showFormattingButtons(coord);
|
|
317
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// Weight tracking functions
|
|
2
|
+
let SocialCalc;
|
|
3
|
+
|
|
4
|
+
// Ensure SocialCalc is loaded from the global scope
|
|
5
|
+
if (typeof window !== "undefined" && window.SocialCalc) {
|
|
6
|
+
SocialCalc = window.SocialCalc;
|
|
7
|
+
} else if (typeof global !== "undefined" && global.SocialCalc) {
|
|
8
|
+
SocialCalc = global.SocialCalc;
|
|
9
|
+
} else {
|
|
10
|
+
console.error("SocialCalc not found in global scope");
|
|
11
|
+
SocialCalc = {}; // Fallback to prevent errors
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getDayCoordinates() {
|
|
15
|
+
console.log("=== GET DAY COORDINATES ===");
|
|
16
|
+
|
|
17
|
+
// Weight tracker coordinates mapping day numbers (1-7) to rows (5-11)
|
|
18
|
+
// Columns: B=Date, C=Weight, D=Goal, E=From Goal
|
|
19
|
+
const coordinates = {
|
|
20
|
+
1: {
|
|
21
|
+
// Day 1 -> Row 5
|
|
22
|
+
date: "B5",
|
|
23
|
+
weight: "C5",
|
|
24
|
+
goal: "D5",
|
|
25
|
+
fromGoal: "E5",
|
|
26
|
+
},
|
|
27
|
+
2: {
|
|
28
|
+
// Day 2 -> Row 6
|
|
29
|
+
date: "B6",
|
|
30
|
+
weight: "C6",
|
|
31
|
+
goal: "D6",
|
|
32
|
+
fromGoal: "E6",
|
|
33
|
+
},
|
|
34
|
+
3: {
|
|
35
|
+
// Day 3 -> Row 7
|
|
36
|
+
date: "B7",
|
|
37
|
+
weight: "C7",
|
|
38
|
+
goal: "D7",
|
|
39
|
+
fromGoal: "E7",
|
|
40
|
+
},
|
|
41
|
+
4: {
|
|
42
|
+
// Day 4 -> Row 8
|
|
43
|
+
date: "B8",
|
|
44
|
+
weight: "C8",
|
|
45
|
+
goal: "D8",
|
|
46
|
+
fromGoal: "E8",
|
|
47
|
+
},
|
|
48
|
+
5: {
|
|
49
|
+
// Day 5 -> Row 9
|
|
50
|
+
date: "B9",
|
|
51
|
+
weight: "C9",
|
|
52
|
+
goal: "D9",
|
|
53
|
+
fromGoal: "E9",
|
|
54
|
+
},
|
|
55
|
+
6: {
|
|
56
|
+
// Day 6 -> Row 10
|
|
57
|
+
date: "B10",
|
|
58
|
+
weight: "C10",
|
|
59
|
+
goal: "D10",
|
|
60
|
+
fromGoal: "E10",
|
|
61
|
+
},
|
|
62
|
+
7: {
|
|
63
|
+
// Day 7 -> Row 11
|
|
64
|
+
date: "B11",
|
|
65
|
+
weight: "C11",
|
|
66
|
+
goal: "D11",
|
|
67
|
+
fromGoal: "E11",
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
console.log("Day coordinates mapping:", coordinates);
|
|
72
|
+
console.log("=== END GET DAY COORDINATES ===");
|
|
73
|
+
|
|
74
|
+
return coordinates;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function addWeight(dayNumber, date, weight, goal) {
|
|
78
|
+
return new Promise(function (resolve, reject) {
|
|
79
|
+
console.log("=== ADD WEIGHT START ===");
|
|
80
|
+
console.log("Day number:", dayNumber);
|
|
81
|
+
console.log("Date:", date);
|
|
82
|
+
console.log("Weight:", weight);
|
|
83
|
+
console.log("Goal:", goal);
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
var control = SocialCalc.GetCurrentWorkBookControl();
|
|
87
|
+
console.log("Workbook control:", control ? "Found" : "Not found");
|
|
88
|
+
|
|
89
|
+
if (!control) {
|
|
90
|
+
throw new Error("No workbook control available");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!control.currentSheetButton) {
|
|
94
|
+
throw new Error("No current sheet button available");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var currsheet = control.currentSheetButton.id;
|
|
98
|
+
console.log("Current active sheet:", currsheet);
|
|
99
|
+
|
|
100
|
+
// Get day coordinates
|
|
101
|
+
const coordinates = getDayCoordinates();
|
|
102
|
+
|
|
103
|
+
if (!coordinates[dayNumber]) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Invalid day number: ${dayNumber}. Must be between 1-7.`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const dayCoords = coordinates[dayNumber];
|
|
110
|
+
console.log("Using coordinates for day", dayNumber, ":", dayCoords);
|
|
111
|
+
|
|
112
|
+
// Calculate "From Goal" (weight - goal)
|
|
113
|
+
const fromGoal = parseFloat(weight) - parseFloat(goal);
|
|
114
|
+
console.log("Calculated From Goal (weight - goal):", fromGoal);
|
|
115
|
+
|
|
116
|
+
// Build commands to set all four values
|
|
117
|
+
var commands = [];
|
|
118
|
+
|
|
119
|
+
// Set date
|
|
120
|
+
commands.push(`set ${dayCoords.date} text t ${date}`);
|
|
121
|
+
|
|
122
|
+
// Set weight
|
|
123
|
+
commands.push(`set ${dayCoords.weight} value n ${weight}`);
|
|
124
|
+
|
|
125
|
+
// Set goal
|
|
126
|
+
commands.push(`set ${dayCoords.goal} value n ${goal}`);
|
|
127
|
+
|
|
128
|
+
// Set from goal (calculated)
|
|
129
|
+
commands.push(`set ${dayCoords.fromGoal} value n ${fromGoal}`);
|
|
130
|
+
|
|
131
|
+
var cmd = commands.join("\n") + "\n";
|
|
132
|
+
console.log("Generated SocialCalc commands:", cmd);
|
|
133
|
+
|
|
134
|
+
var commandObj = {
|
|
135
|
+
cmdtype: "scmd",
|
|
136
|
+
id: currsheet,
|
|
137
|
+
cmdstr: cmd,
|
|
138
|
+
saveundo: false,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
console.log("Command object:", commandObj);
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
control.ExecuteWorkBookControlCommand(commandObj, false);
|
|
145
|
+
console.log("✓ Weight data added successfully");
|
|
146
|
+
console.log("=== ADD WEIGHT SUCCESS ===");
|
|
147
|
+
resolve(true);
|
|
148
|
+
} catch (execError) {
|
|
149
|
+
console.error("Error executing command:", execError);
|
|
150
|
+
throw execError;
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error("=== ADD WEIGHT ERROR ===");
|
|
154
|
+
console.error("Error details:", error);
|
|
155
|
+
console.error("Stack trace:", error.stack);
|
|
156
|
+
reject(error);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function clearWeight(dayNumber) {
|
|
162
|
+
return new Promise(function (resolve, reject) {
|
|
163
|
+
console.log("=== CLEAR WEIGHT START ===");
|
|
164
|
+
console.log("Day number:", dayNumber);
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
var control = SocialCalc.GetCurrentWorkBookControl();
|
|
168
|
+
console.log("Workbook control:", control ? "Found" : "Not found");
|
|
169
|
+
|
|
170
|
+
if (!control) {
|
|
171
|
+
throw new Error("No workbook control available");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!control.currentSheetButton) {
|
|
175
|
+
throw new Error("No current sheet button available");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
var currsheet = control.currentSheetButton.id;
|
|
179
|
+
console.log("Current active sheet:", currsheet);
|
|
180
|
+
|
|
181
|
+
// Get day coordinates
|
|
182
|
+
const coordinates = getDayCoordinates();
|
|
183
|
+
|
|
184
|
+
if (!coordinates[dayNumber]) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`Invalid day number: ${dayNumber}. Must be between 1-7.`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const dayCoords = coordinates[dayNumber];
|
|
191
|
+
console.log("Using coordinates for day", dayNumber, ":", dayCoords);
|
|
192
|
+
|
|
193
|
+
// Build commands to clear all four values
|
|
194
|
+
var commands = [];
|
|
195
|
+
|
|
196
|
+
// Clear all cells for this day
|
|
197
|
+
commands.push(`erase ${dayCoords.date} formulas`);
|
|
198
|
+
commands.push(`erase ${dayCoords.weight} formulas`);
|
|
199
|
+
commands.push(`erase ${dayCoords.goal} formulas`);
|
|
200
|
+
commands.push(`erase ${dayCoords.fromGoal} formulas`);
|
|
201
|
+
|
|
202
|
+
var cmd = commands.join("\n") + "\n";
|
|
203
|
+
console.log("Generated SocialCalc clear commands:", cmd);
|
|
204
|
+
|
|
205
|
+
var commandObj = {
|
|
206
|
+
cmdtype: "scmd",
|
|
207
|
+
id: currsheet,
|
|
208
|
+
cmdstr: cmd,
|
|
209
|
+
saveundo: false,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
console.log("Command object:", commandObj);
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
control.ExecuteWorkBookControlCommand(commandObj, false);
|
|
216
|
+
console.log("✓ Weight data cleared successfully");
|
|
217
|
+
console.log("=== CLEAR WEIGHT SUCCESS ===");
|
|
218
|
+
resolve(true);
|
|
219
|
+
} catch (execError) {
|
|
220
|
+
console.error("Error executing command:", execError);
|
|
221
|
+
throw execError;
|
|
222
|
+
}
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error("=== CLEAR WEIGHT ERROR ===");
|
|
225
|
+
console.error("Error details:", error);
|
|
226
|
+
console.error("Stack trace:", error.stack);
|
|
227
|
+
reject(error);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function getWeightData(dayNumber) {
|
|
233
|
+
console.log("=== GET WEIGHT DATA START ===");
|
|
234
|
+
console.log("Day number:", dayNumber);
|
|
235
|
+
|
|
236
|
+
try {
|
|
237
|
+
// Get day coordinates
|
|
238
|
+
const coordinates = getDayCoordinates();
|
|
239
|
+
|
|
240
|
+
if (!coordinates[dayNumber]) {
|
|
241
|
+
throw new Error(`Invalid day number: ${dayNumber}. Must be between 1-7.`);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const dayCoords = coordinates[dayNumber];
|
|
245
|
+
console.log("Using coordinates for day", dayNumber, ":", dayCoords);
|
|
246
|
+
|
|
247
|
+
// Get current sheet
|
|
248
|
+
var control = SocialCalc.GetCurrentWorkBookControl();
|
|
249
|
+
if (!control || !control.currentSheetButton) {
|
|
250
|
+
throw new Error("No current sheet available");
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
var currsheet = control.currentSheetButton.id;
|
|
254
|
+
console.log("Current active sheet:", currsheet);
|
|
255
|
+
|
|
256
|
+
// Read values from cells
|
|
257
|
+
var dateCell = SocialCalc.GetCellDataValue(
|
|
258
|
+
currsheet + "!" + dayCoords.date
|
|
259
|
+
);
|
|
260
|
+
var weightCell = SocialCalc.GetCellDataValue(
|
|
261
|
+
currsheet + "!" + dayCoords.weight
|
|
262
|
+
);
|
|
263
|
+
var goalCell = SocialCalc.GetCellDataValue(
|
|
264
|
+
currsheet + "!" + dayCoords.goal
|
|
265
|
+
);
|
|
266
|
+
var fromGoalCell = SocialCalc.GetCellDataValue(
|
|
267
|
+
currsheet + "!" + dayCoords.fromGoal
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
const data = {
|
|
271
|
+
date: dateCell || "",
|
|
272
|
+
weight: weightCell || "",
|
|
273
|
+
goal: goalCell || "",
|
|
274
|
+
fromGoal: fromGoalCell || "",
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
console.log("Retrieved weight data:", data);
|
|
278
|
+
console.log("=== GET WEIGHT DATA SUCCESS ===");
|
|
279
|
+
|
|
280
|
+
return data;
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error("=== GET WEIGHT DATA ERROR ===");
|
|
283
|
+
console.error("Error details:", error);
|
|
284
|
+
console.error("Stack trace:", error.stack);
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "socialcalc-ai",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Modernized, modular spreadsheet calculation engine and React/Ionic UI suite with AI formula and template capabilities.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"import": "./index.js",
|
|
13
|
+
"default": "./index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"core",
|
|
19
|
+
"modules",
|
|
20
|
+
"components",
|
|
21
|
+
"utils",
|
|
22
|
+
"index.js",
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"README.md",
|
|
25
|
+
"!**/*.test.ts",
|
|
26
|
+
"!**/*.test.js",
|
|
27
|
+
"!**/*.spec.ts",
|
|
28
|
+
"!**/*.spec.js"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "vitest run"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"socialcalc",
|
|
35
|
+
"socialcalc-ai",
|
|
36
|
+
"spreadsheet",
|
|
37
|
+
"react-spreadsheet",
|
|
38
|
+
"ionic-spreadsheet",
|
|
39
|
+
"excel",
|
|
40
|
+
"sheets",
|
|
41
|
+
"calc",
|
|
42
|
+
"formula",
|
|
43
|
+
"msc"
|
|
44
|
+
],
|
|
45
|
+
"author": "Anirudh Sharma",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@ionic/react": ">=7.0.0",
|
|
49
|
+
"ionicons": ">=7.0.0",
|
|
50
|
+
"react": ">=18.0.0",
|
|
51
|
+
"react-dom": ">=18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@ionic/react": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"ionicons": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"react-dom": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|