Skip to content

Commit 7db3dd5

Browse files
committed
vue-core 3.0.0-rc.11
1 parent eb6b975 commit 7db3dd5

8 files changed

Lines changed: 114 additions & 389 deletions

File tree

packages/preact-core/example/App.jsx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
import { useState, useEffect } from 'preact/hooks';
1+
import { useState, useRef } from 'preact/hooks';
22
import { GridSheet, Policy } from '@gridsheet/preact-core';
33
import { useSpellbook } from '@gridsheet/preact-core/spellbook';
44

55
export function App() {
66
const [enableDecimalLabeler, setEnableDecimalLabeler] = useState(false);
77

8-
const bookProps = {
9-
policies: {},
10-
};
11-
const book = useSpellbook(bookProps);
8+
const bookPropsRef = useRef({ policies: {} });
9+
const book = useSpellbook(bookPropsRef.current);
1210

13-
useEffect(() => {
14-
bookProps.policies.decimal = enableDecimalLabeler
15-
? new Policy({ mixins: [{ renderRowHeaderLabel: (n) => String(n) }] })
11+
const handleToggle = (e) => {
12+
const checked = e.target.checked;
13+
setEnableDecimalLabeler(checked);
14+
bookPropsRef.current.policies.decimal = checked
15+
? new Policy({ mixins: [{ renderColHeaderLabel: (n) => String(n) }] })
1616
: null;
17-
book.registry.transmit(bookProps);
18-
}, [enableDecimalLabeler]);
19-
20-
setTimeout(() => {
21-
console.log('Current policies:', book.registry);
22-
}, 5000);
17+
book.registry.transmit(bookPropsRef.current);
18+
};
2319

2420
return (
2521
<main>
@@ -57,7 +53,7 @@ export function App() {
5753
<input
5854
type="checkbox"
5955
checked={enableDecimalLabeler}
60-
onChange={(e) => setEnableDecimalLabeler(e.target.checked)}
56+
onChange={handleToggle}
6157
/>
6258
Enable Decimal Labeler for Sheet2
6359
</label>

packages/vue-core/example/App.vue

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
<div class="grid-container">
66
<GridSheet
7-
:hub="hub"
7+
:book="book"
88
:initialCells="{
99
A1: { value: 'Hello' },
1010
B1: { value: 'Vue', style: { backgroundColor: '#448888'} },
1111
A2: { value: 123 },
1212
B2: { value: 456 },
1313
A3: { value: 789},
14-
C10: { value: '=SUM(A2:B2)' },
14+
C6: { value: '=SUM(A2:B2)' },
1515
}"
1616
:options="{
1717
mode: 'dark',
@@ -20,10 +20,10 @@
2020
/>
2121

2222
<GridSheet
23-
:hub="hub"
23+
:book="book"
2424
:initialCells="{
2525
C3: { value: '=SUM(Sheet1!A2:B3)' },
26-
default: { labeler: 'decimal' },
26+
defaultCol: { policy: 'decimal' },
2727
}"
2828
:options="{}"
2929
sheetName="Sheet2"
@@ -33,10 +33,10 @@
3333
<!-- Labeler Control -->
3434
<div class="labeler-control">
3535
<label>
36-
<input
37-
type="checkbox"
38-
v-model="enableDecimalLabeler"
39-
@change="updateWireProps"
36+
<input
37+
type="checkbox"
38+
v-model="enableDecimalLabeler"
39+
@change="handleToggle"
4040
/>
4141
Enable Decimal Labeler for Sheet2
4242
</label>
@@ -45,27 +45,21 @@
4545
</template>
4646

4747
<script setup>
48-
import { ref, reactive } from 'vue';
49-
import { GridSheet, useHub } from '@gridsheet/vue-core';
48+
import { ref } from 'vue';
49+
import { GridSheet, Policy } from '@gridsheet/vue-core';
50+
import { useSpellbook } from '@gridsheet/vue-core/spellbook';
5051
5152
const enableDecimalLabeler = ref(false);
5253
53-
const hubProps = reactive({
54-
labelers: enableDecimalLabeler.value ? {
55-
decimal: (n) => String(n)
56-
} : {}
57-
});
54+
const bookProps = { policies: {} };
55+
const book = useSpellbook(bookProps);
5856
59-
const hub = useHub(hubProps);
60-
61-
const updateWireProps = () => {
62-
if (enableDecimalLabeler.value) {
63-
hubProps.labelers = {
64-
decimal: (n) => String(n)
65-
};
66-
} else {
67-
hubProps.labelers = {};
68-
}
57+
const handleToggle = () => {
58+
const { registry } = book.value;
59+
bookProps.policies.decimal = enableDecimalLabeler.value
60+
? new Policy({ mixins: [{ renderColHeaderLabel: (n) => String(n) }] })
61+
: null;
62+
registry.transmit(bookProps);
6963
};
7064
</script>
7165

packages/vue-core/package.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
{
22
"name": "@gridsheet/vue-core",
3-
"version": "2.2.0-0",
3+
"version": "3.0.0-rc.11",
44
"description": "Spreadsheet component for Vue 3",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
77
"types": "dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"types": "./dist/index.d.ts",
11+
"import": "./dist/index.js",
12+
"default": "./dist/index.js"
13+
},
14+
"./spellbook": {
15+
"types": "./dist/spellbook.d.ts",
16+
"import": "./dist/spellbook.js",
17+
"default": "./dist/spellbook.js"
18+
}
19+
},
820
"files": ["dist"],
921
"scripts": {
1022
"dev": "vite example",
11-
"build": "vite build",
12-
"preview": "vite preview"
23+
"build": "rm -rf ./dist || true && vite build"
1324
},
1425
"homepage": "https://gridsheet.walkframe.com/",
1526
"repository": {
@@ -20,13 +31,14 @@
2031
"vue": "^3.3.0"
2132
},
2233
"dependencies": {
23-
"@gridsheet/preact-core": "^2.2.0"
34+
"@gridsheet/preact-core": "workspace:*"
2435
},
2536
"devDependencies": {
2637
"@vitejs/plugin-vue": "^5.2.4",
38+
"@gridsheet/functions": "workspace:*",
2739
"vue": "^3.4.21",
2840
"vite": "^6.3.5",
29-
"vite-plugin-dts": "^3.9.0"
41+
"vite-plugin-dts": "^4.5.3"
3042
},
3143
"author": "righ",
3244
"license": "Apache-2.0"

packages/vue-core/src/GridSheet.vue

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<script lang="ts">
2-
import { defineComponent, onMounted, onBeforeUnmount, ref, h as vueH, isRef, watch } from 'vue';
2+
import { defineComponent, onMounted, onBeforeUnmount, ref, h as vueH, watch } from 'vue';
33
import {
44
GridSheet as PreactGridSheet,
55
h as preactH,
66
render as preactRender,
77
} from '@gridsheet/preact-core';
8-
import type { Ref } from 'vue';
98
10-
import type {
11-
CellsByAddressType,
12-
OptionsType,
13-
HubType,
14-
Connector,
9+
import type {
10+
CellsByAddressType,
11+
OptionsType,
12+
BookType,
13+
SheetHandle,
14+
StoreHandle,
1515
} from '@gridsheet/preact-core';
1616
1717
interface RefObject<T> {
@@ -29,13 +29,17 @@ export default defineComponent({
2929
type: String,
3030
default: '',
3131
},
32-
hub: {
33-
type: Object as () => HubType | Ref<HubType>,
34-
default: null,
32+
book: {
33+
type: Object as () => BookType,
34+
default: undefined,
3535
},
36-
connector: {
37-
type: Object as () => RefObject<Connector | null>,
38-
default: null,
36+
sheetRef: {
37+
type: Object as () => RefObject<SheetHandle | null>,
38+
default: undefined,
39+
},
40+
storeRef: {
41+
type: Object as () => RefObject<StoreHandle | null>,
42+
default: undefined,
3943
},
4044
options: {
4145
type: Object as () => OptionsType,
@@ -55,11 +59,15 @@ export default defineComponent({
5559
let root: HTMLElement | null = null;
5660
5761
function getPreactProps() {
58-
// Remove legacy tableRef, use connector instead
59-
const { tableRef, ...rest } = props as any;
6062
return {
61-
...rest,
62-
hub: isRef(props.hub) ? (props.hub.value as HubType | undefined) : (props.hub as HubType | undefined),
63+
initialCells: props.initialCells,
64+
sheetName: props.sheetName,
65+
book: props.book,
66+
sheetRef: props.sheetRef,
67+
storeRef: props.storeRef,
68+
options: props.options,
69+
className: props.className,
70+
style: props.style,
6371
};
6472
}
6573
@@ -75,24 +83,16 @@ export default defineComponent({
7583
7684
onMounted(() => {
7785
renderPreact();
78-
if (isRef(props.hub)) {
79-
watch(
80-
() => (props.hub as Ref<HubType>).value,
81-
renderPreact,
82-
{ deep: false }
83-
);
84-
} else {
85-
watch(
86-
() => props.hub,
87-
renderPreact,
88-
{ deep: false }
89-
);
90-
}
86+
watch(
87+
() => props.book,
88+
renderPreact,
89+
{ deep: false }
90+
);
9191
});
9292
9393
onBeforeUnmount(() => {
9494
if (root) {
95-
root.innerHTML = '';
95+
preactRender(null, root);
9696
}
9797
});
9898
@@ -101,8 +101,6 @@ export default defineComponent({
101101
};
102102
},
103103
});
104-
105-
106104
</script>
107105

108106
<template>

packages/vue-core/src/book.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
import { shallowRef, watch } from 'vue';
2-
import { createBook, RegistryProps, type TransmitProps } from '@gridsheet/preact-core';
1+
import { shallowRef } from 'vue';
2+
import { createBook, updateSheet, type BookType, type RegistryProps, type TransmitProps } from '@gridsheet/preact-core';
33

4-
export function useBook(registryProps: RegistryProps = {}) {
5-
const book = createBook(registryProps);
6-
const ref = shallowRef(book);
4+
export function useBook(props: RegistryProps = {}) {
5+
const book = createBook(props);
6+
const ref = shallowRef<BookType>(book);
77
const { registry } = ref.value;
88

9-
function transmit(patch?: TransmitProps) {
9+
registry.updateSheet = updateSheet;
10+
registry.transmit = (patch?: TransmitProps) => {
1011
Object.assign(registry, patch);
1112
if (!registry.ready) {
1213
return;
1314
}
14-
requestAnimationFrame(() => (ref.value = { ...ref.value }));
15-
}
16-
registry.transmit = transmit;
15+
requestAnimationFrame(() => (ref.value = { registry }));
16+
};
1717

18-
// Watch for registryProps changes and apply them to book
19-
watch(
20-
() => registryProps,
21-
(newProps) => transmit(newProps),
22-
{ deep: true },
23-
);
2418
return ref;
2519
}

packages/vue-core/src/spellbook.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { allFunctions } from '@gridsheet/functions';
2+
import type { RegistryProps } from '@gridsheet/preact-core';
3+
import { useBook } from './book';
4+
5+
export { createSpellbook } from '@gridsheet/preact-core/spellbook';
6+
7+
/** useBook with all extended functions pre-loaded (Vue version). */
8+
export const useSpellbook = ({ additionalFunctions, ...rest }: RegistryProps = {}) =>
9+
useBook({ ...rest, additionalFunctions: { ...allFunctions, ...additionalFunctions } });

packages/vue-core/vite.config.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,30 @@ export default defineConfig({
1414
vue(),
1515
dts({
1616
tsconfigPath: path.resolve(__dirname, 'tsconfig.json'),
17-
include: ['index.ts', 'src'],
17+
include: ['src'],
1818
outDir: 'dist',
1919
insertTypesEntry: true,
20-
copyDtsFiles: true
21-
})
20+
copyDtsFiles: true,
21+
}),
2222
],
2323
build: {
2424
lib: {
2525
entry: path.resolve(__dirname, './src/index.ts'),
2626
name: 'GridSheetVueCore',
2727
formats: ['es'],
28-
fileName: () => 'index.js'
28+
fileName: (_, name) => `${name}.js`,
2929
},
3030
outDir: 'dist',
3131
emptyOutDir: true,
3232
sourcemap: true,
33-
minify: "esbuild",
33+
minify: 'esbuild',
3434
rollupOptions: {
35-
external: ['vue', '@gridsheet/preact-core'],
36-
}
35+
external: ['vue', /^@gridsheet\/preact-core/, /^@gridsheet\/core/, /^@gridsheet\/functions/, /^dayjs/],
36+
input: {
37+
index: path.resolve(__dirname, './src/index.ts'),
38+
spellbook: path.resolve(__dirname, './src/spellbook.ts'),
39+
},
40+
},
3741
},
3842
resolve: {
3943
alias: {

0 commit comments

Comments
 (0)