mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-24 16:02:55 +02:00
Custom TypeScript Types (#3835)
This PR adds better TypeScript types into Slate and is based on the proposal here: https://github.com/ianstormtaylor/slate/issues/3725
* Extend Slate's types like Element and Text
* Supports type discrimination (ie. if an element has type === "table" then we get a reduced set of properties)
* added custom types
* files
* more extensions
* files
* changed fixtures
* changes eslint file
* changed element.children to descendant
* updated types
* more type changes
* changed a lot of typing, still getting building errors
* extended text type in slate-react
* removed type assertions
* Clean up of custom types and a couple uneeded comments.
* Rename headingElement-true.tsx.tsx to headingElement-true.tsx
* moved basetext and baselement
* Update packages/slate/src/interfaces/text.ts
Co-authored-by: Brent Farese <25846953+BrentFarese@users.noreply.github.com>
* Fix some type issues with core functions.
* Clean up text and element files.
* Convert other types to extended types.
* Change the type of editor.marks to the appropriate type.
* Add version 100.0.0 to package.json
* Revert "Add version 100.0.0 to package.json"
This reverts commit 329e44e43d
.
* added custom types
* files
* more extensions
* files
* changed fixtures
* changes eslint file
* changed element.children to descendant
* updated types
* more type changes
* changed a lot of typing, still getting building errors
* extended text type in slate-react
* removed type assertions
* Clean up of custom types and a couple uneeded comments.
* Rename headingElement-true.tsx.tsx to headingElement-true.tsx
* moved basetext and baselement
* Update packages/slate/src/interfaces/text.ts
Co-authored-by: Brent Farese <25846953+BrentFarese@users.noreply.github.com>
* Fix some type issues with core functions.
* Clean up text and element files.
* Convert other types to extended types.
* Change the type of editor.marks to the appropriate type.
* Run linter.
* Remove key:string uknown from the base types.
* Clean up types after removing key:string unknown.
* Lint and prettier fixes.
* Implement custom-types
Co-authored-by: mdmjg <mdj308@nyu.edu>
* added custom types to examples
* reset yarn lock
* added ts to fixtures
* examples custom types
* Working fix
* ts-thesunny-try
* Extract interface types.
* Fix minor return type in create-editor.
* Fix the typing issue with Location having compile time CustomTypes
* Extract types for Transforms.
* Update README.
* Fix dependency on slate-history in slate-react
Co-authored-by: mdmjg <mdj308@nyu.edu>
Co-authored-by: Brent Farese <brentfarese@gmail.com>
Co-authored-by: Brent Farese <25846953+BrentFarese@users.noreply.github.com>
Co-authored-by: Tim Buckley <timothypbuckley@gmail.com>
This commit is contained in:
@@ -8,28 +8,28 @@ Transforms that operate on nodes.
|
||||
|
||||
###### NodeOptions
|
||||
|
||||
All transforms listed below support a parameter `options`. This includes options specific to the transform, and general `NodeOptions` to specify the place in the document that the transform is applied to.
|
||||
All transforms listed below support a parameter `options`. This includes options specific to the transform, and general `NodeOptions` to specify the place in the document that the transform is applied to.
|
||||
|
||||
```typescript
|
||||
interface NodeOptions {
|
||||
at?: Location
|
||||
match?: (node: Node) => boolean
|
||||
mode?: 'highest' | 'lowest'
|
||||
voids?: boolean
|
||||
at?: Location
|
||||
match?: (node: Node) => boolean
|
||||
mode?: 'highest' | 'lowest'
|
||||
voids?: boolean
|
||||
}
|
||||
```
|
||||
|
||||
###### `Transforms.insertNodes(editor: Editor, nodes: Node | Node[], options?)`
|
||||
|
||||
Insert `nodes` at the specified location in the document. If no location is specified, insert at the current selection. If there is no selection, insert at the end of the document.
|
||||
Insert `nodes` at the specified location in the document. If no location is specified, insert at the current selection. If there is no selection, insert at the end of the document.
|
||||
|
||||
Options supported: `NodeOptions & {hanging?: boolean, select?: boolean}`.
|
||||
Options supported: `NodeOptions & {hanging?: boolean, select?: boolean}`.
|
||||
|
||||
###### `Transforms.removeNodes(editor: Editor, options?)`
|
||||
|
||||
Remove nodes at the specified location in the document. If no location is specified, remove the nodes in the selection.
|
||||
Remove nodes at the specified location in the document. If no location is specified, remove the nodes in the selection.
|
||||
|
||||
Options supported: `NodeOptions & {hanging?: boolean}`
|
||||
Options supported: `NodeOptions & {hanging?: boolean}`
|
||||
|
||||
###### `Transforms.mergeNodes(editor: Editor, options?)`
|
||||
|
||||
@@ -41,7 +41,7 @@ Options supported: `NodeOptions & {hanging?: boolean}`
|
||||
|
||||
Split nodes at the specified location. If no location is specified, split the selection.
|
||||
|
||||
Options supported: `NodeOptions & {height?: number, always?: boolean}`
|
||||
Options supported: `NodeOptions & {height?: number, always?: boolean}`
|
||||
|
||||
###### `Transforms.wrapNodes(editor: Editor, element: Element, options?)`
|
||||
|
||||
@@ -75,7 +75,7 @@ Options supported: `NodeOptions`. For `options.mode`, `'all'` is also supported.
|
||||
|
||||
###### `Transforms.moveNodes(editor: Editor, options)`
|
||||
|
||||
Move the nodes from an origin to a destination. A destination must be specified in the `options`. If no origin is specified, move the selection.
|
||||
Move the nodes from an origin to a destination. A destination must be specified in the `options`. If no origin is specified, move the selection.
|
||||
|
||||
Options supported: `NodeOptions & {to: Path}`. For `options.mode`, `'all'` is also supported.
|
||||
|
||||
@@ -87,7 +87,7 @@ Transforms that operate on the document's selection.
|
||||
|
||||
Collapse the selection to a single point.
|
||||
|
||||
Options: `{edge?: 'anchor' | 'focus' | 'start' | 'end'}`
|
||||
Options: `{edge?: 'anchor' | 'focus' | 'start' | 'end'}`
|
||||
|
||||
###### `Transforms.select(editor: Editor, target: Location)`
|
||||
|
||||
|
Reference in New Issue
Block a user