@mixd-id/web-scaffold 0.2.250801014 → 0.2.260801002
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 +25 -1
- package/docs/components/AIDashboard.md +117 -32
- package/docs/components/Alert.md +3 -1
- package/docs/components/Card.md +5 -0
- package/docs/components/PivotList.md +207 -0
- package/docs/components/Textbox.md +20 -1
- package/docs/components/Tooltip.md +148 -0
- package/package.json +17 -61
- package/src/components/AIChat.vue +14 -5
- package/src/components/AIChatItem.vue +34 -3
- package/src/components/AIDashboard.vue +144 -98
- package/src/components/Alert.vue +58 -35
- package/src/components/Card.vue +55 -6
- package/src/components/Carousel.vue +1 -1
- package/src/{widgets → components}/CartSetting.vue +1 -0
- package/src/components/Chart.vue +2 -2
- package/src/components/Checkbox.vue +22 -24
- package/src/components/CodeEditor.vue +2 -0
- package/src/{widgets → components}/CollapsiblePanelSetting.vue +1 -0
- package/src/components/ColorPicker.vue +2 -2
- package/src/{widgets → components}/ComponentSetting2.vue +1 -1
- package/src/components/Confirm.vue +2 -0
- package/src/{widgets → components}/ContactForm.vue +1 -1
- package/src/components/CopyToClipboard.vue +0 -1
- package/src/components/Datepicker.vue +2 -0
- package/src/components/Datetimepicker.vue +1 -1
- package/src/components/Dropdown.vue +1 -1
- package/src/{widgets → components}/FeatureList.vue +1 -1
- package/src/components/Gmaps.vue +1 -1
- package/src/{widgets → components}/IconList.vue +1 -1
- package/src/components/Image.vue +1 -1
- package/src/components/ImagePreview.vue +32 -51
- package/src/components/List.vue +45 -8
- package/src/components/MarkdownEdit.vue +1 -1
- package/src/components/MarkdownPreview.vue +4 -1
- package/src/{widgets → components}/MenuItem1Setting.vue +1 -0
- package/src/components/Metric.vue +30 -7
- package/src/components/MultiDropdown.vue +3 -1
- package/src/{widgets → components}/MultiValueSetting.vue +2 -2
- package/src/{widgets → components}/MultiValueSetting2.vue +2 -2
- package/src/components/OTPField.vue +3 -1
- package/src/components/PivotList.vue +1239 -0
- package/src/{widgets → components}/PresetBar.vue +1 -1
- package/src/components/PresetSelectorFilterItem.vue +1 -1
- package/src/components/Radio.vue +1 -1
- package/src/{widgets → components}/Share.vue +1 -1
- package/src/components/SvgEditor.vue +1 -1
- package/src/components/Switch.vue +1 -1
- package/src/components/TextWithTag.vue +2 -2
- package/src/components/Textbox.vue +63 -5
- package/src/components/Toast.vue +2 -1
- package/src/components/Tooltip.vue +626 -0
- package/src/components/VirtualGrid.vue +2 -2
- package/src/components/VirtualTable.vue +4 -3
- package/src/{widgets → components}/WebDatasourceSelector.vue +2 -0
- package/src/{widgets → components}/WebLayoutSelector.vue +1 -1
- package/src/directives/tooltip.js +131 -0
- package/src/index.js +11 -235
- package/src/themes/default/index.js +16 -0
- package/src/utils/ai-dashboard.js +163 -38
- package/src/utils/helpers.mjs +52 -5
- package/src/utils/list.mjs +4 -1
- package/src/utils/pivot-formula.mjs +358 -0
- package/src/utils/pivot-list.mjs +557 -0
- package/src/utils/tooltip.mjs +243 -0
- package/src/utils/wss.js +26 -6
- package/src/utils/wss.mjs +29 -2
- /package/src/{widgets → components}/AhrefSetting.vue +0 -0
- /package/src/{widgets → components}/ArticleSetting.vue +0 -0
- /package/src/{widgets → components}/BackgroundColorSetting.vue +0 -0
- /package/src/{widgets → components}/BlockSetting.vue +0 -0
- /package/src/{widgets → components}/BorderColorSetting.vue +0 -0
- /package/src/{widgets → components}/ButtonSetting.vue +0 -0
- /package/src/{widgets → components}/CarouselSetting.vue +0 -0
- /package/src/{widgets → components}/ColumnSelector.vue +0 -0
- /package/src/{widgets → components}/ComponentSetting.vue +0 -0
- /package/src/{widgets → components}/ContactFormSetting.vue +0 -0
- /package/src/{widgets → components}/CountdownSetting.vue +0 -0
- /package/src/{widgets → components}/DataListSetting.vue +0 -0
- /package/src/{widgets → components}/EmbeddedVideo.vue +0 -0
- /package/src/{widgets → components}/EmbeddedVideoSetting.vue +0 -0
- /package/src/{widgets → components}/FAQ.vue +0 -0
- /package/src/{widgets → components}/FAQSetting.vue +0 -0
- /package/src/{widgets → components}/FeatureListSetting.vue +0 -0
- /package/src/{widgets → components}/FlexSetting.vue +0 -0
- /package/src/{widgets → components}/GridSetting.vue +0 -0
- /package/src/{widgets → components}/Header2.vue +0 -0
- /package/src/{widgets → components}/Header2Setting.vue +0 -0
- /package/src/{widgets → components}/IconListSetting.vue +0 -0
- /package/src/{widgets → components}/ImageSetting.vue +0 -0
- /package/src/{widgets → components}/LLMChat.vue +0 -0
- /package/src/{widgets → components}/LinkSetting.vue +0 -0
- /package/src/{widgets → components}/LinkSettingModal.vue +0 -0
- /package/src/{widgets → components}/ModalSetting.vue +0 -0
- /package/src/{widgets → components}/OGSettingModal.vue +0 -0
- /package/src/{widgets → components}/ParagraphSetting.vue +0 -0
- /package/src/{widgets → components}/PositionSetting.vue +0 -0
- /package/src/{widgets → components}/PresetBarPivot.vue +0 -0
- /package/src/{widgets → components}/PresetBarPivotColumnEdit.vue +0 -0
- /package/src/{widgets → components}/PresetBarPivotValueEdit.vue +0 -0
- /package/src/{widgets → components}/PresetSelector.vue +0 -0
- /package/src/{widgets → components}/Review.vue +0 -0
- /package/src/{widgets → components}/ReviewSetting.vue +0 -0
- /package/src/{widgets → components}/SearchModalSetting.vue +0 -0
- /package/src/{widgets → components}/ShareSetting.vue +0 -0
- /package/src/{widgets → components}/SvgSetting.vue +0 -0
- /package/src/{widgets → components}/TableSetting.vue +0 -0
- /package/src/{widgets → components}/TestimonialSetting.vue +0 -0
- /package/src/{widgets → components}/TextBlockSetting.vue +0 -0
- /package/src/{widgets → components}/ThumbnailSetting.vue +0 -0
- /package/src/{widgets → components}/WebComponentSelector.vue +0 -0
- /package/src/{widgets → components}/WebPageBuilder.vue +0 -0
- /package/src/{widgets → components}/YoutubeVideoSetting.vue +0 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// Excel-like formula engine for PivotList virtual columns. Formulas are
|
|
2
|
+
// evaluated entirely client-side against one pivot row at a time — no eval(),
|
|
3
|
+
// no server round-trip.
|
|
4
|
+
//
|
|
5
|
+
// Syntax (the leading '=' is optional):
|
|
6
|
+
// =([_amount-sum] - [_cost-sum]) / [_amount-sum] * 100
|
|
7
|
+
// =IF([_qty-count] > 10, "High", "Low")
|
|
8
|
+
// =ROUND([_amount-sum] / [_qty-sum], 2)
|
|
9
|
+
//
|
|
10
|
+
// Column references go in [brackets] (pivot aliases contain '-', so bare
|
|
11
|
+
// identifiers can't express them). Operators: + - * / % ^, & (concat),
|
|
12
|
+
// comparisons = <> > >= < <=. Blank cells count as 0 in arithmetic, like
|
|
13
|
+
// a spreadsheet. Failures surface as Excel-style error codes per cell.
|
|
14
|
+
|
|
15
|
+
class FormulaError extends Error{
|
|
16
|
+
constructor(code, message){
|
|
17
|
+
super(message ?? code)
|
|
18
|
+
this.code = code
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const FUNCTIONS = {
|
|
23
|
+
IF: (args) => truthy(args[0]) ? args[1] : (args.length > 2 ? args[2] : null),
|
|
24
|
+
AND: (args) => args.every(truthy),
|
|
25
|
+
OR: (args) => args.some(truthy),
|
|
26
|
+
NOT: (args) => !truthy(args[0]),
|
|
27
|
+
ABS: (args) => Math.abs(toNumber(args[0])),
|
|
28
|
+
ROUND: (args) => {
|
|
29
|
+
const f = Math.pow(10, Math.trunc(toNumber(args[1] ?? 0)))
|
|
30
|
+
return Math.round(toNumber(args[0]) * f) / f
|
|
31
|
+
},
|
|
32
|
+
FLOOR: (args) => Math.floor(toNumber(args[0])),
|
|
33
|
+
CEIL: (args) => Math.ceil(toNumber(args[0])),
|
|
34
|
+
MIN: (args) => Math.min(...numbers(args)),
|
|
35
|
+
MAX: (args) => Math.max(...numbers(args)),
|
|
36
|
+
SUM: (args) => numbers(args).reduce((a, b) => a + b, 0),
|
|
37
|
+
AVG: (args) => {
|
|
38
|
+
const nums = numbers(args)
|
|
39
|
+
if(nums.length < 1) throw new FormulaError('#DIV/0!')
|
|
40
|
+
return nums.reduce((a, b) => a + b, 0) / nums.length
|
|
41
|
+
},
|
|
42
|
+
COUNT: (args) => args.filter(_ => _ !== null && _ !== undefined && _ !== '').length,
|
|
43
|
+
CONCAT: (args) => args.map(toText).join(''),
|
|
44
|
+
LEN: (args) => toText(args[0]).length,
|
|
45
|
+
UPPER: (args) => toText(args[0]).toUpperCase(),
|
|
46
|
+
LOWER: (args) => toText(args[0]).toLowerCase(),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const truthy = (v) => {
|
|
50
|
+
if(typeof v === 'string') return v.length > 0 && v !== '0' && v.toLowerCase() !== 'false'
|
|
51
|
+
return Boolean(v)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Spreadsheet coercion: blank is 0, numeric strings (MySQL returns aggregates
|
|
55
|
+
// as strings) parse, anything else is a #VALUE! error.
|
|
56
|
+
const toNumber = (v) => {
|
|
57
|
+
if(v === null || v === undefined || v === '') return 0
|
|
58
|
+
if(typeof v === 'number') return v
|
|
59
|
+
if(typeof v === 'boolean') return v ? 1 : 0
|
|
60
|
+
const n = parseFloat(v)
|
|
61
|
+
if(Number.isNaN(n) || `${v}`.trim() === '' || !/^-?[\d.]+([eE][+-]?\d+)?$/.test(`${v}`.trim()))
|
|
62
|
+
throw new FormulaError('#VALUE!')
|
|
63
|
+
return n
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const toText = (v) => v === null || v === undefined ? '' : `${v}`
|
|
67
|
+
|
|
68
|
+
const numbers = (args) => args
|
|
69
|
+
.filter(_ => _ !== null && _ !== undefined && _ !== '')
|
|
70
|
+
.map(toNumber)
|
|
71
|
+
|
|
72
|
+
const isNumericLike = (v) => {
|
|
73
|
+
if(typeof v === 'number') return true
|
|
74
|
+
return typeof v === 'string' && /^-?[\d.]+([eE][+-]?\d+)?$/.test(v.trim())
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ---------------------------------------------------------------- tokenizer
|
|
78
|
+
|
|
79
|
+
const tokenize = (src) => {
|
|
80
|
+
const tokens = []
|
|
81
|
+
let i = 0
|
|
82
|
+
|
|
83
|
+
while(i < src.length){
|
|
84
|
+
const ch = src[i]
|
|
85
|
+
|
|
86
|
+
if(/\s/.test(ch)){ i++; continue }
|
|
87
|
+
|
|
88
|
+
if(ch === '['){
|
|
89
|
+
const end = src.indexOf(']', i)
|
|
90
|
+
if(end < 0) throw new FormulaError('#NAME?', 'Unclosed column reference')
|
|
91
|
+
tokens.push({ type: 'ref', value: src.slice(i + 1, end).trim() })
|
|
92
|
+
i = end + 1
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if(ch === '"' || ch === "'"){
|
|
97
|
+
let j = i + 1, out = ''
|
|
98
|
+
while(j < src.length && src[j] !== ch){
|
|
99
|
+
out += src[j]
|
|
100
|
+
j++
|
|
101
|
+
}
|
|
102
|
+
if(j >= src.length) throw new FormulaError('#NAME?', 'Unclosed string')
|
|
103
|
+
tokens.push({ type: 'str', value: out })
|
|
104
|
+
i = j + 1
|
|
105
|
+
continue
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if(/[\d.]/.test(ch)){
|
|
109
|
+
const match = src.slice(i).match(/^\d*\.?\d+([eE][+-]?\d+)?/)
|
|
110
|
+
if(!match) throw new FormulaError('#NAME?', `Bad number at "${src.slice(i, i + 8)}"`)
|
|
111
|
+
tokens.push({ type: 'num', value: parseFloat(match[0]) })
|
|
112
|
+
i += match[0].length
|
|
113
|
+
continue
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if(/[A-Za-z_]/.test(ch)){
|
|
117
|
+
const match = src.slice(i).match(/^[A-Za-z_][A-Za-z0-9_]*/)
|
|
118
|
+
tokens.push({ type: 'ident', value: match[0].toUpperCase() })
|
|
119
|
+
i += match[0].length
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const two = src.slice(i, i + 2)
|
|
124
|
+
if([ '<>', '>=', '<=' ].includes(two)){
|
|
125
|
+
tokens.push({ type: 'op', value: two })
|
|
126
|
+
i += 2
|
|
127
|
+
continue
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if('+-*/%^&=<>(),'.includes(ch)){
|
|
131
|
+
tokens.push({ type: 'op', value: ch })
|
|
132
|
+
i++
|
|
133
|
+
continue
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
throw new FormulaError('#NAME?', `Unexpected character "${ch}"`)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return tokens
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ------------------------------------------------------------------ parser
|
|
143
|
+
// Recursive descent, spreadsheet precedence (lowest to highest):
|
|
144
|
+
// comparisons = <> > >= < <=
|
|
145
|
+
// concat &
|
|
146
|
+
// additive + -
|
|
147
|
+
// multiplicative * / %
|
|
148
|
+
// power ^ (right-associative)
|
|
149
|
+
// unary -
|
|
150
|
+
// primary number, string, [ref], FUNC(...), (...)
|
|
151
|
+
|
|
152
|
+
const parse = (tokens) => {
|
|
153
|
+
let pos = 0
|
|
154
|
+
|
|
155
|
+
const peek = () => tokens[pos]
|
|
156
|
+
const takeOp = (...values) => {
|
|
157
|
+
const t = tokens[pos]
|
|
158
|
+
if(t && t.type === 'op' && values.includes(t.value)){
|
|
159
|
+
pos++
|
|
160
|
+
return t.value
|
|
161
|
+
}
|
|
162
|
+
return null
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const primary = () => {
|
|
166
|
+
const t = tokens[pos]
|
|
167
|
+
if(!t) throw new FormulaError('#NAME?', 'Unexpected end of formula')
|
|
168
|
+
|
|
169
|
+
if(t.type === 'num' || t.type === 'str'){
|
|
170
|
+
pos++
|
|
171
|
+
return { type: 'value', value: t.value }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if(t.type === 'ref'){
|
|
175
|
+
pos++
|
|
176
|
+
return { type: 'ref', key: t.value }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if(t.type === 'ident'){
|
|
180
|
+
pos++
|
|
181
|
+
if(!takeOp('(')) throw new FormulaError('#NAME?', `Unknown name "${t.value}" — column references use [brackets]`)
|
|
182
|
+
if(!FUNCTIONS[t.value]) throw new FormulaError('#NAME?', `Unknown function ${t.value}`)
|
|
183
|
+
const args = []
|
|
184
|
+
if(!takeOp(')')){
|
|
185
|
+
do{
|
|
186
|
+
args.push(comparison())
|
|
187
|
+
} while(takeOp(','))
|
|
188
|
+
if(!takeOp(')')) throw new FormulaError('#NAME?', `Missing ) after ${t.value}(`)
|
|
189
|
+
}
|
|
190
|
+
return { type: 'call', name: t.value, args }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if(takeOp('(')){
|
|
194
|
+
const node = comparison()
|
|
195
|
+
if(!takeOp(')')) throw new FormulaError('#NAME?', 'Missing )')
|
|
196
|
+
return node
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
throw new FormulaError('#NAME?', `Unexpected "${t.value}"`)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const unary = () => {
|
|
203
|
+
if(takeOp('-')) return { type: 'neg', node: unary() }
|
|
204
|
+
if(takeOp('+')) return unary()
|
|
205
|
+
return primary()
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const power = () => {
|
|
209
|
+
const left = unary()
|
|
210
|
+
if(takeOp('^')) return { type: 'binary', op: '^', left, right: power() }
|
|
211
|
+
return left
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const multiplicative = () => {
|
|
215
|
+
let left = power()
|
|
216
|
+
let op
|
|
217
|
+
while((op = takeOp('*', '/', '%'))){
|
|
218
|
+
left = { type: 'binary', op, left, right: power() }
|
|
219
|
+
}
|
|
220
|
+
return left
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const additive = () => {
|
|
224
|
+
let left = multiplicative()
|
|
225
|
+
let op
|
|
226
|
+
while((op = takeOp('+', '-'))){
|
|
227
|
+
left = { type: 'binary', op, left, right: multiplicative() }
|
|
228
|
+
}
|
|
229
|
+
return left
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const concat = () => {
|
|
233
|
+
let left = additive()
|
|
234
|
+
while(takeOp('&')){
|
|
235
|
+
left = { type: 'binary', op: '&', left, right: additive() }
|
|
236
|
+
}
|
|
237
|
+
return left
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const comparison = () => {
|
|
241
|
+
let left = concat()
|
|
242
|
+
let op
|
|
243
|
+
while((op = takeOp('=', '<>', '>', '>=', '<', '<='))){
|
|
244
|
+
left = { type: 'binary', op, left, right: concat() }
|
|
245
|
+
}
|
|
246
|
+
return left
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const root = comparison()
|
|
250
|
+
if(pos < tokens.length) throw new FormulaError('#NAME?', `Unexpected "${tokens[pos].value}" after formula`)
|
|
251
|
+
return root
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// --------------------------------------------------------------- evaluator
|
|
255
|
+
|
|
256
|
+
const compare = (op, a, b) => {
|
|
257
|
+
// numbers compare numerically when both sides look numeric, else as text
|
|
258
|
+
if(isNumericLike(a) && isNumericLike(b)){
|
|
259
|
+
a = toNumber(a)
|
|
260
|
+
b = toNumber(b)
|
|
261
|
+
}
|
|
262
|
+
else{
|
|
263
|
+
a = toText(a)
|
|
264
|
+
b = toText(b)
|
|
265
|
+
}
|
|
266
|
+
switch(op){
|
|
267
|
+
case '=': return a === b
|
|
268
|
+
case '<>': return a !== b
|
|
269
|
+
case '>': return a > b
|
|
270
|
+
case '>=': return a >= b
|
|
271
|
+
case '<': return a < b
|
|
272
|
+
case '<=': return a <= b
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const evalNode = (node, getValue) => {
|
|
277
|
+
switch(node.type){
|
|
278
|
+
|
|
279
|
+
case 'value':
|
|
280
|
+
return node.value
|
|
281
|
+
|
|
282
|
+
case 'ref':
|
|
283
|
+
return getValue(node.key)
|
|
284
|
+
|
|
285
|
+
case 'neg':
|
|
286
|
+
return -toNumber(evalNode(node.node, getValue))
|
|
287
|
+
|
|
288
|
+
case 'call':
|
|
289
|
+
return FUNCTIONS[node.name](node.args.map(arg => evalNode(arg, getValue)))
|
|
290
|
+
|
|
291
|
+
case 'binary': {
|
|
292
|
+
const { op } = node
|
|
293
|
+
const a = evalNode(node.left, getValue)
|
|
294
|
+
|
|
295
|
+
if([ '=', '<>', '>', '>=', '<', '<=' ].includes(op)){
|
|
296
|
+
return compare(op, a, evalNode(node.right, getValue))
|
|
297
|
+
}
|
|
298
|
+
if(op === '&'){
|
|
299
|
+
return toText(a) + toText(evalNode(node.right, getValue))
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const x = toNumber(a)
|
|
303
|
+
const y = toNumber(evalNode(node.right, getValue))
|
|
304
|
+
switch(op){
|
|
305
|
+
case '+': return x + y
|
|
306
|
+
case '-': return x - y
|
|
307
|
+
case '*': return x * y
|
|
308
|
+
case '/':
|
|
309
|
+
if(y === 0) throw new FormulaError('#DIV/0!')
|
|
310
|
+
return x / y
|
|
311
|
+
case '%':
|
|
312
|
+
if(y === 0) throw new FormulaError('#DIV/0!')
|
|
313
|
+
return x % y
|
|
314
|
+
case '^': return Math.pow(x, y)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const collectRefs = (node, refs) => {
|
|
321
|
+
if(!node) return refs
|
|
322
|
+
if(node.type === 'ref') refs.push(node.key)
|
|
323
|
+
if(node.node) collectRefs(node.node, refs)
|
|
324
|
+
if(node.left) collectRefs(node.left, refs)
|
|
325
|
+
if(node.right) collectRefs(node.right, refs)
|
|
326
|
+
;(node.args ?? []).forEach(arg => collectRefs(arg, refs))
|
|
327
|
+
return refs
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Parse once, evaluate many. Throws FormulaError on syntax errors; the
|
|
331
|
+
// returned evaluate() returns an Excel-style error CODE string ('#DIV/0!',
|
|
332
|
+
// '#VALUE!', …) instead of throwing, so one bad cell doesn't break a column.
|
|
333
|
+
const compileFormula = (formula) => {
|
|
334
|
+
const src = `${formula ?? ''}`.replace(/^\s*=/, '')
|
|
335
|
+
if(!src.trim()) throw new FormulaError('#NAME?', 'Empty formula')
|
|
336
|
+
|
|
337
|
+
const ast = parse(tokenize(src))
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
refs: [ ...new Set(collectRefs(ast, [])) ],
|
|
341
|
+
evaluate(row){
|
|
342
|
+
try{
|
|
343
|
+
return evalNode(ast, (key) => row ? row[key] : null)
|
|
344
|
+
}
|
|
345
|
+
catch(err){
|
|
346
|
+
return err instanceof FormulaError ? err.code : '#ERROR!'
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const evaluateFormula = (formula, row) => compileFormula(formula).evaluate(row)
|
|
353
|
+
|
|
354
|
+
export {
|
|
355
|
+
FormulaError,
|
|
356
|
+
compileFormula,
|
|
357
|
+
evaluateFormula
|
|
358
|
+
}
|