@m3ui-vue/m3ui-vue 1.7.0 → 1.8.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/dist/API.md +578 -3
- package/dist/{MColorPickerModal-BKM1CHxr.js → MColorPickerModal-H8nuX0Wu.js} +3 -4
- package/dist/{MColorPickerModal-BKM1CHxr.js.map → MColorPickerModal-H8nuX0Wu.js.map} +1 -1
- package/dist/MDialog-B42Mhn8W.js +331 -0
- package/dist/MDialog-B42Mhn8W.js.map +1 -0
- package/dist/{MListItem-BU5KDRCB.js → MListItem-DiOAxaN7.js} +102 -102
- package/dist/{MListItem-BU5KDRCB.js.map → MListItem-DiOAxaN7.js.map} +1 -1
- package/dist/{MLoadingIndicator-RykOo5tf.js → MLoadingIndicator-CuTZYFFj.js} +2 -2
- package/dist/{MLoadingIndicator-RykOo5tf.js.map → MLoadingIndicator-CuTZYFFj.js.map} +1 -1
- package/dist/{MSeekBar-B_Y3MpVz.js → MSeekBar-BCDQTx2t.js} +2 -2
- package/dist/{MSeekBar-B_Y3MpVz.js.map → MSeekBar-BCDQTx2t.js.map} +1 -1
- package/dist/{MSegmentedButton-CiOOY1-N.js → MSegmentedButton-BXzRsg1S.js} +2 -2
- package/dist/{MSegmentedButton-CiOOY1-N.js.map → MSegmentedButton-BXzRsg1S.js.map} +1 -1
- package/dist/MSignaturePad-BTqGaPXA.js +313 -0
- package/dist/MSignaturePad-BTqGaPXA.js.map +1 -0
- package/dist/{MSlider-BCeVIxcq.js → MSlider-D_O8J9YH.js} +3 -3
- package/dist/{MSlider-BCeVIxcq.js.map → MSlider-D_O8J9YH.js.map} +1 -1
- package/dist/{MSpinner-Cs03qoqE.js → MSpinner-UCdtSOHP.js} +2 -2
- package/dist/{MSpinner-Cs03qoqE.js.map → MSpinner-UCdtSOHP.js.map} +1 -1
- package/dist/{MTextField-NaFbMkjv.js → MTextField-CYk9yFvi.js} +3 -3
- package/dist/{MTextField-NaFbMkjv.js.map → MTextField-CYk9yFvi.js.map} +1 -1
- package/dist/{_useFieldValidation-Bz34IAQY.js → _useFieldValidation-B0B44M_t.js} +2 -2
- package/dist/{_useFieldValidation-Bz34IAQY.js.map → _useFieldValidation-B0B44M_t.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MFormBuilder.vue.d.ts +22 -0
- package/dist/components/MFormRenderer.vue.d.ts +151 -0
- package/dist/components/MMapRoute.vue.d.ts +13 -5
- package/dist/components/MPdfSigner.vue.d.ts +499 -0
- package/dist/components/MPdfViewer.vue.d.ts +12 -0
- package/dist/components/MPosKeypad.vue.d.ts +1 -1
- package/dist/components/MSpreadsheet.vue.d.ts +137 -0
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/composables/pdfSign.d.ts +52 -0
- package/dist/composables/spreadsheetFormula.d.ts +55 -0
- package/dist/composables/useLocale.d.ts +154 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +2 -2
- package/dist/index.d.ts +7 -0
- package/dist/locales/index.js +539 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +16988 -15064
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +601 -585
- package/dist/map.js.map +1 -1
- package/dist/media.js +4 -4
- package/dist/pdf.d.ts +3 -0
- package/dist/pdf.js +1228 -687
- package/dist/pdf.js.map +1 -1
- package/dist/rich-text-editor.js +12 -13
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-Dh1xZZ8i.js → useLocale-DL96OFgr.js} +78 -1
- package/dist/useLocale-DL96OFgr.js.map +1 -0
- package/package.json +5 -1
- package/src/__tests__/MFormRenderer.test.ts +157 -0
- package/src/__tests__/MMapRoute.test.ts +34 -0
- package/src/__tests__/MPdfSigner.test.ts +175 -0
- package/src/__tests__/MSpreadsheet.test.ts +223 -0
- package/src/__tests__/spreadsheetFormula.test.ts +77 -0
- package/src/__tests__/ssr.test.ts +3 -0
- package/src/components/MFormBuilder.vue +417 -0
- package/src/components/MFormRenderer.vue +324 -0
- package/src/components/MMapRoute.vue +64 -11
- package/src/components/MPdfSigner.vue +433 -0
- package/src/components/MPdfViewer.vue +12 -0
- package/src/components/MSpreadsheet.vue +992 -0
- package/src/composables/pdfSign.ts +141 -0
- package/src/composables/spreadsheetFormula.ts +459 -0
- package/src/composables/useLocale.ts +231 -0
- package/src/index.ts +7 -0
- package/src/locales/de.ts +77 -0
- package/src/locales/es.ts +77 -0
- package/src/locales/fr.ts +77 -0
- package/src/locales/ja.ts +77 -0
- package/src/locales/ko.ts +77 -0
- package/src/locales/pt.ts +77 -0
- package/src/locales/zh.ts +77 -0
- package/src/pdf.ts +3 -0
- package/dist/MButton-CN3wYwIG.js +0 -171
- package/dist/MButton-CN3wYwIG.js.map +0 -1
- package/dist/MDialog-1LAk9WAO.js +0 -167
- package/dist/MDialog-1LAk9WAO.js.map +0 -1
- package/dist/MProgressBar-BWly1UKN.js +0 -179
- package/dist/MProgressBar-BWly1UKN.js.map +0 -1
- package/dist/useLocale-Dh1xZZ8i.js.map +0 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { h, nextTick, ref } from 'vue'
|
|
4
|
+
import MSpreadsheet from '../components/MSpreadsheet.vue'
|
|
5
|
+
import type { SpreadsheetCell } from '../composables/spreadsheetFormula'
|
|
6
|
+
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
document.body.innerHTML = ''
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
function setup(initial: SpreadsheetCell[][], props: Record<string, unknown> = {}) {
|
|
12
|
+
const cells = ref<SpreadsheetCell[][]>(initial)
|
|
13
|
+
const changes: unknown[] = []
|
|
14
|
+
const wrapper = mount(() => h(MSpreadsheet, {
|
|
15
|
+
modelValue: cells.value,
|
|
16
|
+
'onUpdate:modelValue': (v: SpreadsheetCell[][]) => (cells.value = v),
|
|
17
|
+
onChange: (c: unknown) => changes.push(c),
|
|
18
|
+
rows: 20,
|
|
19
|
+
cols: 6,
|
|
20
|
+
...props,
|
|
21
|
+
}), { attachTo: document.body })
|
|
22
|
+
const grid = () => wrapper.find('[role="grid"]')
|
|
23
|
+
const cell = (r: number, c: number) => wrapper.find(`[data-row="${r}"][data-col="${c}"]`)
|
|
24
|
+
const text = (r: number, c: number) => cell(r, c).find('span').text()
|
|
25
|
+
const key = async (k: string, opts: Record<string, unknown> = {}) => { await grid().trigger('keydown', { key: k, ...opts }); await nextTick() }
|
|
26
|
+
const click = async (r: number, c: number, opts: Record<string, unknown> = {}) => {
|
|
27
|
+
cell(r, c).element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, pointerType: 'mouse', ...opts }))
|
|
28
|
+
window.dispatchEvent(new PointerEvent('pointerup'))
|
|
29
|
+
await nextTick()
|
|
30
|
+
}
|
|
31
|
+
const name = () => wrapper.find('[role="status"]').text()
|
|
32
|
+
return { wrapper, cells, changes, grid, cell, text, key, click, name }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function clipboardEvent(type: string, text = '') {
|
|
36
|
+
const data = new Map<string, string>([['text/plain', text]])
|
|
37
|
+
const e = new Event(type, { bubbles: true, cancelable: true }) as ClipboardEvent
|
|
38
|
+
Object.defineProperty(e, 'clipboardData', { value: { getData: (t: string) => data.get(t) ?? '', setData: (t: string, v: string) => data.set(t, v) } })
|
|
39
|
+
return { e, data }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('MSpreadsheet', () => {
|
|
43
|
+
it('shows values and works out formulas; numbers right-aligned, errors in the error color', () => {
|
|
44
|
+
const { text, cell } = setup([[1, 2, '=A1+B1', '=1/0', 'hi']])
|
|
45
|
+
expect(text(0, 2)).toBe('3')
|
|
46
|
+
expect(cell(0, 0).classes()).toContain('text-right')
|
|
47
|
+
expect(text(0, 3)).toBe('#DIV/0!')
|
|
48
|
+
expect(cell(0, 3).classes()).toContain('text-error')
|
|
49
|
+
expect(cell(0, 4).classes()).toContain('text-left')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('typing replaces the cell; Enter stores it (a number as a number) and moves down', async () => {
|
|
53
|
+
const { key, cells, wrapper, name, changes } = setup([[5]])
|
|
54
|
+
;(wrapper.find('[role="grid"]').element as HTMLElement).focus()
|
|
55
|
+
await key('4')
|
|
56
|
+
const input = wrapper.find('input[spellcheck="false"]:not([aria-label])')
|
|
57
|
+
expect((input.element as HTMLInputElement).value).toBe('4')
|
|
58
|
+
await input.setValue('42')
|
|
59
|
+
await input.trigger('keydown', { key: 'Enter' })
|
|
60
|
+
expect(cells.value[0]![0]).toBe(42)
|
|
61
|
+
expect(name()).toBe('A2')
|
|
62
|
+
expect(changes[0]).toEqual([{ row: 0, col: 0, value: 42, oldValue: 5 }])
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('a formula typed in recomputes the cells that read it', async () => {
|
|
66
|
+
const { key, wrapper, text, click } = setup([[1, 2, '=A1*B1']])
|
|
67
|
+
await click(0, 0)
|
|
68
|
+
await key('7')
|
|
69
|
+
const input = wrapper.find('input[spellcheck="false"]:not([aria-label])')
|
|
70
|
+
await input.trigger('keydown', { key: 'Enter' })
|
|
71
|
+
expect(text(0, 2)).toBe('14')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('Escape cancels an edit; F2 edits keeping the contents', async () => {
|
|
75
|
+
const { key, wrapper, cells, click } = setup([['abc']])
|
|
76
|
+
await click(0, 0)
|
|
77
|
+
await key('F2')
|
|
78
|
+
const input = () => wrapper.find('input[spellcheck="false"]:not([aria-label])')
|
|
79
|
+
expect((input().element as HTMLInputElement).value).toBe('abc')
|
|
80
|
+
await input().setValue('zzz')
|
|
81
|
+
await input().trigger('keydown', { key: 'Escape' })
|
|
82
|
+
expect(cells.value[0]![0]).toBe('abc')
|
|
83
|
+
expect(input().exists()).toBe(false)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('arrows move, Shift+arrows extend the range, Delete clears it', async () => {
|
|
87
|
+
const { key, click, name, cells } = setup([[1, 2], [3, 4]])
|
|
88
|
+
await click(0, 0)
|
|
89
|
+
await key('ArrowRight')
|
|
90
|
+
expect(name()).toBe('B1')
|
|
91
|
+
await key('ArrowLeft')
|
|
92
|
+
await key('ArrowDown', { shiftKey: true })
|
|
93
|
+
await key('ArrowRight', { shiftKey: true })
|
|
94
|
+
expect(name()).toBe('A1:B2')
|
|
95
|
+
await key('Delete')
|
|
96
|
+
expect(cells.value.flat().every((v) => v == null)).toBe(true)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('Ctrl+Z undoes and Ctrl+Shift+Z redoes', async () => {
|
|
100
|
+
const { key, click, cells } = setup([[1]])
|
|
101
|
+
await click(0, 0)
|
|
102
|
+
await key('Delete')
|
|
103
|
+
expect(cells.value[0]![0]).toBeNull()
|
|
104
|
+
await key('z', { ctrlKey: true })
|
|
105
|
+
expect(cells.value[0]![0]).toBe(1)
|
|
106
|
+
await key('z', { ctrlKey: true, shiftKey: true })
|
|
107
|
+
expect(cells.value[0]![0]).toBeNull()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('copies the selection as tab-separated values and pastes Excel text, quoted cells included', async () => {
|
|
111
|
+
const { click, grid, cells } = setup([[1, '=A1*2'], ['a', 'b']])
|
|
112
|
+
await click(0, 0)
|
|
113
|
+
await click(1, 1, { shiftKey: true })
|
|
114
|
+
;(grid().element as HTMLElement).focus()
|
|
115
|
+
const copy = clipboardEvent('copy')
|
|
116
|
+
document.dispatchEvent(copy.e)
|
|
117
|
+
expect(copy.data.get('text/plain')).toBe('1\t2\na\tb')
|
|
118
|
+
await click(4, 0)
|
|
119
|
+
;(grid().element as HTMLElement).focus()
|
|
120
|
+
document.dispatchEvent(clipboardEvent('paste', 'x\t"two\nlines"\r\n3\t4.5\r\n').e)
|
|
121
|
+
await nextTick()
|
|
122
|
+
expect(cells.value[4]).toEqual(['x', 'two\nlines'])
|
|
123
|
+
expect(cells.value[5]).toEqual([3, 4.5])
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('pasting its own copy moves the formulas references', async () => {
|
|
127
|
+
const { click, grid, cells } = setup([[1, '=A1*2'], [5]])
|
|
128
|
+
await click(0, 1)
|
|
129
|
+
;(grid().element as HTMLElement).focus()
|
|
130
|
+
const copy = clipboardEvent('copy')
|
|
131
|
+
document.dispatchEvent(copy.e)
|
|
132
|
+
await click(1, 1)
|
|
133
|
+
;(grid().element as HTMLElement).focus()
|
|
134
|
+
document.dispatchEvent(clipboardEvent('paste', copy.data.get('text/plain')).e)
|
|
135
|
+
await nextTick()
|
|
136
|
+
expect(cells.value[1]![1]).toBe('=A2*2')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('the fill handle continues a series, repeats text, counts "Item 1" on and moves formulas', async () => {
|
|
140
|
+
const { wrapper, click, cells } = setup([[1, 'x', 'Item 1', '=A1*10'], [2]])
|
|
141
|
+
const grid = wrapper.find('[role="grid"]').element as HTMLElement
|
|
142
|
+
grid.getBoundingClientRect = () => ({ left: 0, top: 0, right: 600, bottom: 400, width: 600, height: 400, x: 0, y: 0, toJSON() {} })
|
|
143
|
+
// Select A1:A2 and drag the handle down to row 5
|
|
144
|
+
await click(0, 0)
|
|
145
|
+
await click(1, 0, { shiftKey: true })
|
|
146
|
+
const handle = () => wrapper.find('.m3-spreadsheet-fill').element
|
|
147
|
+
const rowHeader = 44
|
|
148
|
+
const at = (row: number, col: number) => ({ clientX: rowHeader + col * 100 + 50, clientY: 32 + row * 32 + 16 })
|
|
149
|
+
handle().dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }))
|
|
150
|
+
window.dispatchEvent(new PointerEvent('pointermove', at(4, 0)))
|
|
151
|
+
window.dispatchEvent(new PointerEvent('pointerup'))
|
|
152
|
+
await nextTick()
|
|
153
|
+
expect(cells.value.slice(0, 5).map((r) => r[0])).toEqual([1, 2, 3, 4, 5])
|
|
154
|
+
// B1:D1 down to row 3
|
|
155
|
+
await click(0, 1)
|
|
156
|
+
await click(0, 3, { shiftKey: true })
|
|
157
|
+
handle().dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }))
|
|
158
|
+
window.dispatchEvent(new PointerEvent('pointermove', at(2, 2)))
|
|
159
|
+
window.dispatchEvent(new PointerEvent('pointerup'))
|
|
160
|
+
await nextTick()
|
|
161
|
+
expect(cells.value.slice(0, 3).map((r) => r[1])).toEqual(['x', 'x', 'x'])
|
|
162
|
+
expect(cells.value.slice(0, 3).map((r) => r[2])).toEqual(['Item 1', 'Item 2', 'Item 3'])
|
|
163
|
+
expect(cells.value.slice(0, 3).map((r) => r[3])).toEqual(['=A1*10', '=A2*10', '=A3*10'])
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('readonly: nothing is written', async () => {
|
|
167
|
+
const { key, click, cells, wrapper } = setup([[1]], { readonly: true })
|
|
168
|
+
await click(0, 0)
|
|
169
|
+
await key('5')
|
|
170
|
+
await key('Delete')
|
|
171
|
+
expect(cells.value[0]![0]).toBe(1)
|
|
172
|
+
expect(wrapper.find('[role="grid"]').attributes('aria-readonly')).toBe('true')
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('renders only the rows in view, plus frozen ones that stick', async () => {
|
|
176
|
+
const { wrapper } = setup([], { rows: 1000, frozenRows: 1, frozenColumns: 1 })
|
|
177
|
+
const rows = wrapper.findAll('[role="row"]')
|
|
178
|
+
expect(rows.length).toBeLessThan(40)
|
|
179
|
+
const frozenCell = wrapper.find('[data-row="5"][data-col="0"]')
|
|
180
|
+
expect((frozenCell.element as HTMLElement).style.position).toBe('sticky')
|
|
181
|
+
expect(wrapper.find('[data-row="0"][data-col="2"]').exists()).toBe(true)
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it('clicking a cell while typing a formula inserts its reference', async () => {
|
|
185
|
+
const { key, click, wrapper, cells } = setup([[3, 4]])
|
|
186
|
+
await click(0, 2)
|
|
187
|
+
await key('=')
|
|
188
|
+
const input = () => wrapper.find('input[spellcheck="false"]:not([aria-label])')
|
|
189
|
+
await input().setValue('=SUM(')
|
|
190
|
+
await click(0, 0)
|
|
191
|
+
expect((input().element as HTMLInputElement).value).toBe('=SUM(A1')
|
|
192
|
+
await input().setValue('=SUM(A1,B1)')
|
|
193
|
+
await input().trigger('keydown', { key: 'Enter' })
|
|
194
|
+
expect(cells.value[0]![2]).toBe('=SUM(A1,B1)')
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('the formula bar shows the raw contents and edits the cell', async () => {
|
|
198
|
+
const { click, wrapper, cells } = setup([['=1+1']])
|
|
199
|
+
await click(0, 0)
|
|
200
|
+
const bar = wrapper.find('input[aria-label="Formula"]')
|
|
201
|
+
expect((bar.element as HTMLInputElement).value).toBe('=1+1')
|
|
202
|
+
await bar.trigger('focus')
|
|
203
|
+
await bar.setValue('=2+2')
|
|
204
|
+
await bar.trigger('keydown', { key: 'Enter' })
|
|
205
|
+
expect(cells.value[0]![0]).toBe('=2+2')
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('column header click selects the column; resizing emits widths', async () => {
|
|
209
|
+
const widths: number[][] = []
|
|
210
|
+
const { wrapper, name } = setup([], { 'onUpdate:columnWidths': (w: number[]) => widths.push(w) })
|
|
211
|
+
const header = wrapper.findAll('[role="columnheader"]')[2]!
|
|
212
|
+
header.element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }))
|
|
213
|
+
await nextTick()
|
|
214
|
+
expect(name()).toBe('B1:B20')
|
|
215
|
+
const grip = header.find('span').element
|
|
216
|
+
grip.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, clientX: 100 }))
|
|
217
|
+
grip.dispatchEvent(new PointerEvent('pointermove', { bubbles: true, clientX: 160 }))
|
|
218
|
+
grip.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }))
|
|
219
|
+
expect(widths.at(-1)![1]).toBe(160)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
vi.restoreAllMocks()
|
|
223
|
+
})
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
FormulaError, cellName, columnIndex, columnName, createSheetEvaluator, formatNumber, parseCellName, shiftFormula,
|
|
4
|
+
type SpreadsheetCell,
|
|
5
|
+
} from '../composables/spreadsheetFormula'
|
|
6
|
+
|
|
7
|
+
const sheet = (cells: SpreadsheetCell[][]) => createSheetEvaluator(cells)
|
|
8
|
+
const code = (v: unknown) => (v instanceof FormulaError ? v.code : v)
|
|
9
|
+
|
|
10
|
+
describe('A1 notation', () => {
|
|
11
|
+
it('columns and cells', () => {
|
|
12
|
+
expect([0, 25, 26, 51, 701, 702].map(columnName)).toEqual(['A', 'Z', 'AA', 'AZ', 'ZZ', 'AAA'])
|
|
13
|
+
expect(columnIndex('AA')).toBe(26)
|
|
14
|
+
expect(cellName(2, 1)).toBe('B3')
|
|
15
|
+
expect(parseCellName('$C$10')).toEqual({ row: 9, col: 2 })
|
|
16
|
+
expect(parseCellName('hello')).toBeNull()
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe('formulas', () => {
|
|
21
|
+
it('arithmetic with precedence, unary minus, percent and power', () => {
|
|
22
|
+
const s = sheet([['=1+2*3', '=(1+2)*3', '=-2^2', '=50%*10', '=2^3^2', '=0.1+0.2']])
|
|
23
|
+
expect([0, 1, 2, 3, 4, 5].map((c) => s.value(0, c))).toEqual([7, 9, 4, 5, 64, 0.30000000000000004])
|
|
24
|
+
expect(formatNumber(0.1 + 0.2)).toBe('0.3')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('references, ranges and functions; text in a range is skipped', () => {
|
|
28
|
+
const s = sheet([
|
|
29
|
+
[1, 2, 'x', '=SUM(A1:C1)', '=AVERAGE(A1:B1)', '=COUNT(A1:C1)', '=COUNTA(A1:C1)'],
|
|
30
|
+
['=A1+B1', '=A2*10', '=MAX(A1:B2)', '=IF(A2>2,"big","small")', '=ROUND(2/3,2)', '=CONCAT(C1,"-",A1)', '=LEN("hello")'],
|
|
31
|
+
])
|
|
32
|
+
expect([3, 4, 5, 6].map((c) => s.value(0, c))).toEqual([3, 1.5, 2, 3])
|
|
33
|
+
expect([0, 1, 2, 3, 4, 5, 6].map((c) => s.value(1, c))).toEqual([3, 30, 30, 'big', 0.67, 'x-1', 5])
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('comparison, text joining, booleans and case-insensitive names', () => {
|
|
37
|
+
const s = sheet([['="a"&"b"', '=1<2', '=sum(1,2)', '="A"="a"', '=AND(TRUE,1>0)', '=NOT(FALSE)']])
|
|
38
|
+
expect([0, 1, 2, 3, 4, 5].map((c) => s.value(0, c))).toEqual(['ab', true, 3, true, true, true])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('errors: #DIV/0!, #NAME?, #VALUE!, a syntax error, and IFERROR', () => {
|
|
42
|
+
const s = sheet([['=1/0', '=NOPE(1)', '="a"*2', '=1+', '=IFERROR(A1,"none")', '=A1+1']])
|
|
43
|
+
expect([0, 1, 2, 3, 4, 5].map((c) => code(s.value(0, c)))).toEqual(['#DIV/0!', '#NAME?', '#VALUE!', '#ERROR!', 'none', '#DIV/0!'])
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('a circular reference is #CIRC!, not a hang', () => {
|
|
47
|
+
const s = sheet([['=B1', '=A1', '=C1+1']])
|
|
48
|
+
expect(code(s.value(0, 0))).toBe('#CIRC!')
|
|
49
|
+
expect(code(s.value(0, 1))).toBe('#CIRC!')
|
|
50
|
+
expect(code(s.value(0, 2))).toBe('#CIRC!')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('SUMIF and COUNTIF with conditions', () => {
|
|
54
|
+
const s = sheet([['a', 'b', 'a'], [1, 2, 3], ['=SUMIF(A1:C1,"a",A2:C2)', '=COUNTIF(A2:C2,">1")', '=SUMIF(A2:C2,"<>2")']])
|
|
55
|
+
expect([0, 1, 2].map((c) => s.value(2, c))).toEqual([4, 2, 4])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('custom functions', () => {
|
|
59
|
+
const s = createSheetEvaluator([['=DOUBLE(21)']], { functions: { DOUBLE: ([a]) => (a as number) * 2 } })
|
|
60
|
+
expect(s.value(0, 0)).toBe(42)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('a reference outside the sheet is #REF!', () => {
|
|
64
|
+
const s = createSheetEvaluator([['=Z99']], { rows: 10, cols: 5 })
|
|
65
|
+
expect(code(s.value(0, 0))).toBe('#REF!')
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('shiftFormula', () => {
|
|
70
|
+
it('moves relative references, keeps $-locked parts and function names', () => {
|
|
71
|
+
expect(shiftFormula('=A1+$B$2+C$3+$D4', 2, 1)).toBe('=B3+$B$2+D$3+$D6')
|
|
72
|
+
expect(shiftFormula('=SUM(A1:A3)*LOG10(B1)', 1, 0)).toBe('=SUM(A2:A4)*LOG10(B2)')
|
|
73
|
+
expect(shiftFormula('="A1"&A1', 1, 0)).toBe('="A1"&A2')
|
|
74
|
+
expect(shiftFormula('=A1', -1, 0)).toBe('=#REF!')
|
|
75
|
+
expect(shiftFormula('plain', 1, 1)).toBe('plain')
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -27,6 +27,9 @@ const props: Record<string, Record<string, unknown>> = {
|
|
|
27
27
|
MTreeTable: { columns: [{ key: 'a', label: 'A' }], rows: [] },
|
|
28
28
|
MTree: { nodes: [{ id: 1, label: 'a' }] },
|
|
29
29
|
MTrackingTimeline: { steps: [{ label: 'Placed' }, { label: 'Delivered' }], current: 0, eta: 0 },
|
|
30
|
+
MSpreadsheet: { modelValue: [[1, '=A1*2']], rows: 5, cols: 3 },
|
|
31
|
+
MFormRenderer: { schema: { fields: [{ type: 'text', name: 'a', label: 'A', required: true }, { type: 'heading', label: 'H' }] }, modelValue: {} },
|
|
32
|
+
MFormBuilder: { modelValue: { fields: [{ type: 'text', name: 'a', label: 'A' }] } },
|
|
30
33
|
MKbd: { keys: 'Ctrl+K' },
|
|
31
34
|
MOrderTicket: { number: 1, createdAt: 0, items: [{ id: 1, name: 'Pizza' }] },
|
|
32
35
|
MSeatMap: { layout: ['ss_ss', 'ss_ss'], modelValue: ['A1'] },
|