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

Document perseus-types.ts file #1975

Merged
merged 2 commits into from
Dec 11, 2024
Merged

Document perseus-types.ts file #1975

merged 2 commits into from
Dec 11, 2024

Conversation

jeremywiebe
Copy link
Collaborator

Summary:

The perseus-types.ts file is special in the Perseus project. It represents the data that is saved out of editors and consumed by the Perseus rendering system. As a result, we need to be extremely careful when making changes to it. I've added a JSDoc comment to the top of the file that (hopefully) explains the file and some cautions to take into account when making changes.

Issue: LEMS-2561

Test plan:

Read the comments and let me know if they make sense and are clear. I'm happy to make further edits. :)

@jeremywiebe jeremywiebe self-assigned this Dec 10, 2024
Comment on lines -5 to +36
import type {Interval, vec} from "mafs";
// TODO(FEI-4010): Remove `Perseus` prefix for all types here

// Range is replaced within this file with Interval, but it is used elsewhere
// and exported from the package, so we need to keep it around.
export type Coord = [x: number, y: number];
export type Interval = [min: number, max: number];
export type Vector2 = Coord; // Same name as Mafs
export type Range = Interval;
export type Size = [number, number];
export type CollinearTuple = [vec.Vector2, vec.Vector2];
export type Size = [width: number, height: number];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These changes are to "internalize" all types into this file instead of importing them from "outside". This means that if we upgrade Mafs and a type changes, we won't be implicitly breaking the schema. We'd still have type mismatches here in Perseus, but we'd then be able to rationalize the differences between our schema (this file) and the changed types.

Copy link
Contributor

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (928851a) and published it to npm. You
can install it using the tag PR1975.

Example:

yarn add @khanacademy/perseus@PR1975

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1975

Copy link
Contributor

Size Change: +591 B (+0.05%)

Total Size: 1.29 MB

Filename Size Change
packages/perseus/dist/es/index.js 426 kB +591 B (+0.14%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.9 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 697 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 3.7 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

Copy link
Contributor

@nishasy nishasy left a comment

Choose a reason for hiding this comment

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

LGTM, but I'll let other people weigh in too


import type {Coord} from "./interactive2/types";
import type {Interval, vec} from "mafs";
// TODO(FEI-4010): Remove `Perseus` prefix for all types here
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we even still want to remove the Perseus prefix for all the types here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe we still could, yes. Today, some of these type names get quite wordy.

But, I don't think we need to deal with that now.

Comment on lines +4 to +7
* This file, and the types in it, represents the "data schema" that Perseus
* uses. The @khanacademy/perseus-editor package edits and produces objects
* that conform to the types in this file. Similarly, the top-level renderers
* in @khanacademy/perseus, consume objects that conform to these types.
Copy link
Contributor

Choose a reason for hiding this comment

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

My only feedback is that this seems to confident. It does represent all permutations of the data or it should?

But if you feel confident then just 🚢

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's aspirational. :) The new parsing code validates against these types and so I think it's a fair statement.

@jeremywiebe jeremywiebe merged commit 335615b into main Dec 11, 2024
8 checks passed
@jeremywiebe jeremywiebe deleted the jer/perseus-schema-docs branch December 11, 2024 19:40
daniellewhyte added a commit that referenced this pull request Dec 11, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @khanacademy/[email protected]

### Patch Changes

- [#1975](#1975)
[`335615bab`](335615b)
Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Make all types
in `perseus-types.ts` originate from it (no longer import Mafs types)


- [#1953](#1953)
[`acd8bd566`](acd8bd5)
Thanks [@daniellewhyte](https://github.com/daniellewhyte)! - [Dropdown]
Change logic for aria-label

## @khanacademy/[email protected]

### Patch Changes

- Updated dependencies
\[[`335615bab`](335615b),
[`acd8bd566`](acd8bd5)]:
    -   @khanacademy/[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants