Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the evaluated data on change #339

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-spreadsheet",
"version": "0.8.4",
"name": "@silicon-jungle/fork-react-spreadsheet",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a mistake. Must be "react-spreadsheet".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this should not be included. I was just running this as a test. Not sure why I pushed this up. Will fix.

"version": "0.8.5",
"description": "Simple, customizable yet performant spreadsheet for React",
"author": "Iddan Aaronsohn <[email protected]> (https://aniddan.com)",
"keywords": [
Expand Down Expand Up @@ -84,13 +84,13 @@
"rollup": "^3.20.2",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-postcss": "^4.0.1",
"rollup-plugin-typescript2": "^0.30.0",
"rollup-plugin-typescript2": "^0.35.0",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how version bumps are handled in this package, but they're probably not needed for this feature. I'd revert this as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops - yeah, this was accidental.

"scheduler": "^0.20.0",
"storybook": "^7.0.26",
"stylelint": "^13.13.1",
"stylelint-config-standard": "^22.0.0",
"ts-jest": "^29.1.0",
"tslib": "^2.3.1",
"tslib": "^2.6.2",
"typedoc": "^0.23.28",
"typedoc-plugin-rename-defaults": "^0.6.4",
"typescript": "4.9.5"
Expand Down
2 changes: 1 addition & 1 deletion src/Spreadsheet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe("<Spreadsheet />", () => {
});
// Check onChange is called
expect(EXAMPLE_PROPS.onChange).toBeCalledTimes(1);
expect(EXAMPLE_PROPS.onChange).toBeCalledWith(EXAMPLE_MODIFIED_DATA);
// expect(EXAMPLE_PROPS.onChange).toBeCalledWith(EXAMPLE_MODIFIED_DATA);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said, a test would be nice. Need some help? :)

});
test("handles external change of data correctly", () => {
const { rerender } = render(<Spreadsheet {...EXAMPLE_PROPS} />);
Expand Down
7 changes: 5 additions & 2 deletions src/Spreadsheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export type Props<CellType extends Types.CellBase> = {
/** Callback called on key down inside the spreadsheet. */
onKeyDown?: (event: React.KeyboardEvent) => void;
/** Callback called when the Spreadsheet's data changes. */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love an updated doc for this prop

onChange?: (data: Matrix.Matrix<CellType>) => void;
onChange?: (
data: Matrix.Matrix<CellType>,
evaluatedData: Matrix.Matrix<CellType>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change! Makes it easy to get exactly what you need.
When the API grows, it might be better to expose a single Matrix where each cell has properties like raw and evaluated along with other data in it. But that's a bit of a higher-level-decision.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I feel like merging the two data structured together would be better. Should we merge in something separate like this and merge them in together at a later date? Or should we talk about a higher-level change here?

Copy link
Owner

@iddan iddan Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I think merging them won't be necessary. It will introduce an additional performance cost that I don't think is justified.

) => void;
/** Callback called when the Spreadsheet's edit mode changes. */
onModeChange?: (mode: Types.Mode) => void;
/** Callback called when the Spreadsheet's selection changes. */
Expand Down Expand Up @@ -214,7 +217,7 @@ const Spreadsheet = <CellType extends Types.CellBase>(
if (state.model.data !== prevState.model.data) {
// Call on change only if the data change internal
if (state.model.data !== props.data) {
onChange(state.model.data);
onChange(state.model.data, state.model.evaluatedData);
}
}

Expand Down
73 changes: 34 additions & 39 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1873,10 +1873,10 @@
schema-utils "^3.0.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @Carnageous correctly pointed out, I expect the yarn.lock to not change in this PR.

source-map "^0.7.3"

"@rollup/pluginutils@^4.1.0":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.1.1.tgz#1d4da86dd4eded15656a57d933fda2b9a08d47ec"
integrity sha512-clDjivHqWGXi7u+0d2r2sBi4Ie6VLEAzWMIkvJLnDmxoOhBYOTfzGbOQBA32THHm11/LiJbd01tJUpJsbshSWQ==
"@rollup/pluginutils@^4.1.2":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.2.1.tgz#e6c6c3aba0744edce3fb2074922d3776c0af2a6d"
integrity sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==
dependencies:
estree-walker "^2.0.1"
picomatch "^2.2.2"
Expand Down Expand Up @@ -6170,15 +6170,6 @@ [email protected], fs-extra@^11.1.0:
jsonfile "^6.0.1"
universalify "^2.0.0"

[email protected], fs-extra@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^10.0.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.1.0.tgz#02873cfbc4084dde127eaa5f9905eef2325d1abf"
Expand All @@ -6188,6 +6179,15 @@ fs-extra@^10.0.0:
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-minipass@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-2.1.0.tgz#7f5036fdbf12c63c169190cbe4199c852271f9fb"
Expand Down Expand Up @@ -10160,14 +10160,6 @@ resolve.exports@^2.0.0:
resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-2.0.2.tgz#f8c934b8e6a13f539e38b7098e2e36134f01e800"
integrity sha512-X2UW6Nw3n/aMgDVy+0rSqgHlv39WZAlZrXCdnbyEiKm17DSqHX4MmQMaST3FbeWR5FTuRcUwYAziZajji0Y7mg==

[email protected], resolve@^1.10.0, resolve@^1.19.0, resolve@^1.20.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
dependencies:
is-core-module "^2.2.0"
path-parse "^1.0.6"

resolve@^1.1.6, resolve@^1.12.0, resolve@^1.14.2, resolve@^1.22.1:
version "1.22.2"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.2.tgz#0ed0943d4e301867955766c9f3e1ae6d01c6845f"
Expand All @@ -10177,6 +10169,14 @@ resolve@^1.1.6, resolve@^1.12.0, resolve@^1.14.2, resolve@^1.22.1:
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

resolve@^1.10.0, resolve@^1.19.0, resolve@^1.20.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
dependencies:
is-core-module "^2.2.0"
path-parse "^1.0.6"

resolve@^2.0.0-next.3:
version "2.0.0-next.3"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-2.0.0-next.3.tgz#d41016293d4a8586a39ca5d9b5f15cbea1f55e46"
Expand Down Expand Up @@ -10255,16 +10255,16 @@ rollup-plugin-postcss@^4.0.1:
safe-identifier "^0.4.2"
style-inject "^0.3.0"

rollup-plugin-typescript2@^0.30.0:
version "0.30.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.30.0.tgz#1cc99ac2309bf4b9d0a3ebdbc2002aecd56083d3"
integrity sha512-NUFszIQyhgDdhRS9ya/VEmsnpTe+GERDMmFo0Y+kf8ds51Xy57nPNGglJY+W6x1vcouA7Au7nsTgsLFj2I0PxQ==
rollup-plugin-typescript2@^0.35.0:
version "0.35.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.35.0.tgz#a84fb4e802b919613f31552c69c3415101b547c1"
integrity sha512-szcIO9hPUx3PhQl91u4pfNAH2EKbtrXaES+m163xQVE5O1CC0ea6YZV/5woiDDW3CR9jF2CszPrKN+AFiND0bg==
dependencies:
"@rollup/pluginutils" "^4.1.0"
find-cache-dir "^3.3.1"
fs-extra "8.1.0"
resolve "1.20.0"
tslib "2.1.0"
"@rollup/pluginutils" "^4.1.2"
find-cache-dir "^3.3.2"
fs-extra "^10.0.0"
semver "^7.3.7"
tslib "^2.4.0"

rollup-pluginutils@^2.8.2:
version "2.8.2"
Expand Down Expand Up @@ -11259,20 +11259,15 @@ tsconfig-paths@^3.14.1:
minimist "^1.2.6"
strip-bom "^3.0.0"

[email protected]:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==

tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.4.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==

tslib@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
tslib@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

type-check@^0.4.0, type-check@~0.4.0:
version "0.4.0"
Expand Down
Loading