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

Custom and Extended Types #3785

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
38a0ecc
added custom types
mdmjg Jul 13, 2020
0312ee5
files
mdmjg Jul 13, 2020
82c254d
more extensions
mdmjg Jul 13, 2020
62a8aaa
files
mdmjg Jul 13, 2020
f1b329f
changed fixtures
mdmjg Jul 13, 2020
c6c86e7
changes eslint file
mdmjg Jul 13, 2020
14400a5
changed element.children to descendant
mdmjg Jul 17, 2020
821b814
updated types
mdmjg Jul 20, 2020
1e929c6
more type changes
mdmjg Jul 20, 2020
4cf3745
changed a lot of typing, still getting building errors
mdmjg Jul 20, 2020
e0a9be6
extended text type in slate-react
mdmjg Jul 20, 2020
df9c098
removed type assertions
mdmjg Jul 21, 2020
0fe3788
Clean up of custom types and a couple uneeded comments.
BrentFarese Jul 24, 2020
304c9cd
Rename headingElement-true.tsx.tsx to headingElement-true.tsx
mdmjg Jul 24, 2020
052ef78
moved basetext and baselement
mdmjg Jul 24, 2020
d086d98
Update packages/slate/src/interfaces/text.ts
mdmjg Jul 24, 2020
395d91e
Fix some type issues with core functions.
BrentFarese Jul 24, 2020
cc7fd88
Merge branch 'custom-types' of github.com:arity-contracts/slate into …
BrentFarese Jul 24, 2020
a60e065
Clean up text and element files.
BrentFarese Jul 24, 2020
18b47f2
Convert other types to extended types.
BrentFarese Jul 24, 2020
d5d816a
Change the type of editor.marks to the appropriate type.
BrentFarese Jul 29, 2020
329e44e
Add version 100.0.0 to package.json
timbuckley Jul 30, 2020
ccfbead
Merge branch 'master' of github.com:arity-contracts/slate
timbuckley Jul 30, 2020
3b70b09
Revert "Add version 100.0.0 to package.json"
timbuckley Jul 30, 2020
4f652d9
added custom types
mdmjg Jul 13, 2020
e55260b
files
mdmjg Jul 13, 2020
6dc5c3e
more extensions
mdmjg Jul 13, 2020
8d7e318
files
mdmjg Jul 13, 2020
7368fd9
changed fixtures
mdmjg Jul 13, 2020
82c8f97
changes eslint file
mdmjg Jul 13, 2020
d3daf18
changed element.children to descendant
mdmjg Jul 17, 2020
de6ba2b
updated types
mdmjg Jul 20, 2020
8ee9d1e
more type changes
mdmjg Jul 20, 2020
f4be265
changed a lot of typing, still getting building errors
mdmjg Jul 20, 2020
f250ca6
extended text type in slate-react
mdmjg Jul 20, 2020
01204fb
removed type assertions
mdmjg Jul 21, 2020
8daeef0
Clean up of custom types and a couple uneeded comments.
BrentFarese Jul 24, 2020
c52308b
Rename headingElement-true.tsx.tsx to headingElement-true.tsx
mdmjg Jul 24, 2020
e0e7463
moved basetext and baselement
mdmjg Jul 24, 2020
d42a3e2
Update packages/slate/src/interfaces/text.ts
mdmjg Jul 24, 2020
88c15bd
Fix some type issues with core functions.
BrentFarese Jul 24, 2020
e102403
Clean up text and element files.
BrentFarese Jul 24, 2020
fcd2bdf
Convert other types to extended types.
BrentFarese Jul 24, 2020
81383bf
Change the type of editor.marks to the appropriate type.
BrentFarese Jul 29, 2020
bfac456
Run prettier clean up.
BrentFarese Jul 30, 2020
f8b7568
Run linter.
BrentFarese Jul 30, 2020
faa5274
Remove key:string uknown from the base types.
BrentFarese Jul 31, 2020
8264419
Clean up types after removing key:string unknown.
BrentFarese Jul 31, 2020
aa3a235
Lint and prettier fixes.
BrentFarese Jul 31, 2020
51ad8ef
Merge branch 'master' of https://github.com/ianstormtaylor/slate
timbuckley Aug 11, 2020
dbb2072
Merge branch 'master' of https://github.com/ianstormtaylor/slate
timbuckley Aug 19, 2020
d20085f
Implement custom-types
timbuckley Aug 11, 2020
9c311ae
merge changes
mdmjg Aug 19, 2020
2a94b1f
added custom types to examples
mdmjg Aug 19, 2020
95d4d5d
Merge branch 'custom-types' of https://github.com/arity-contracts/sla…
mdmjg Aug 19, 2020
dd2aa6f
reset yarn lock
mdmjg Aug 20, 2020
37ed24d
added ts to fixtures
mdmjg Aug 20, 2020
ec1e876
examples custom types
mdmjg Aug 20, 2020
43046f4
Set yarn.lock back to match master
timbuckley Aug 20, 2020
d91a75a
Fixup Transforms mergine in index
timbuckley Aug 20, 2020
3f4bcda
(m) Bring back editor.children Node[] coerc
timbuckley Aug 20, 2020
c576beb
(m) Fully bring yarn.lock back to before
timbuckley Aug 20, 2020
7dd9ff2
Fix type coersion on editor.children
timbuckley Aug 20, 2020
ff2b19f
custom-types.ts -> custom-types.d.ts
timbuckley Aug 20, 2020
e328ca7
Use thesunny's version of transforms/index
timbuckley Aug 20, 2020
84448f6
Excluded .ts files from test.
BrentFarese Aug 20, 2020
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
74 changes: 61 additions & 13 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"prettier/@typescript-eslint",
"prettier/react"
],
"plugins": ["@typescript-eslint", "import", "react", "prettier"],
"plugins": [
"@typescript-eslint",
"import",
"react",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
Expand All @@ -16,7 +21,12 @@
},
"ignorePatterns": ["**/next-env.d.ts"],
"settings": {
"import/extensions": [".js", ".ts", ".jsx", ".tsx"],
"import/extensions": [
".js",
".ts",
".jsx",
".tsx"
],
"react": {
"version": "detect"
}
Expand All @@ -29,8 +39,16 @@
},
"rules": {
"constructor-super": "error",
"dot-notation": ["error", { "allowKeywords": true }],
"eqeqeq": ["error", "smart"],
"dot-notation": [
"error",
{
"allowKeywords": true
}
],
"eqeqeq": [
"error",
"smart"
],
"import/default": "error",
"import/export": "error",
"import/first": "error",
Expand All @@ -40,7 +58,9 @@
"import/no-deprecated": "error",
"import/no-extraneous-dependencies": [
"error",
{ "peerDependencies": true }
{
"peerDependencies": true
}
],
"import/no-mutable-exports": "error",
"import/no-named-as-default": "error",
Expand Down Expand Up @@ -86,18 +106,27 @@
"no-var": "error",
"no-void": "error",
"no-with": "error",
"object-shorthand": ["error", "always"],
"object-shorthand": [
"error",
"always"
],
"prefer-arrow-callback": "error",
"prefer-const": [
"error",
{ "destructuring": "all", "ignoreReadBeforeAssign": true }
{
"destructuring": "all",
"ignoreReadBeforeAssign": true
}
],
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"prettier/prettier": "error",
"radix": "error",
"react/jsx-boolean-value": ["error", "never"],
"react/jsx-boolean-value": [
"error",
"never"
],
"react/jsx-no-duplicate-props": "error",
"react/jsx-no-target-blank": "error",
"react/jsx-no-undef": "error",
Expand All @@ -112,15 +141,34 @@
"react/react-in-jsx-scope": "error",
"react/self-closing-comp": "error",
"react/sort-prop-types": "error",
"spaced-comment": ["error", "always", { "exceptions": ["-"] }],
"spaced-comment": [
"error",
"always",
{
"exceptions": [
"-"
]
}
],
"use-isnan": "error",
"valid-jsdoc": [
"error",
{ "prefer": { "return": "returns" }, "requireReturn": false }
{
"prefer": {
"return": "returns"
},
"requireReturn": false
}
],
"valid-typeof": "error",
"yield-star-spacing": ["error", "after"],
"yoda": ["error", "never"]
"yield-star-spacing": [
"error",
"after"
],
"yoda": [
"error",
"never"
]
},
"overrides": [
{
Expand All @@ -131,4 +179,4 @@
}
}
]
}
}
19 changes: 9 additions & 10 deletions docs/api/locations.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Location

The `Location` interface is a union of the ways to refer to a specific location in a Slate document: paths, points or ranges. Methods will often accept a `Location` instead of requiring only a `Path`, `Point` or `Range`.
The `Location` interface is a union of the ways to refer to a specific location in a Slate document: paths, points or ranges. Methods will often accept a `Location` instead of requiring only a `Path`, `Point` or `Range`.

```typescript
type Location = Path | Point | Range
Expand All @@ -26,9 +26,9 @@ type Path = number[]

```typescript
interface Point {
path: Path
offset: number
[key: string]: unknown
path: Path
offset: number
[key: string]: unknown
}
```

Expand Down Expand Up @@ -66,9 +66,9 @@ Options: `{affinity?: 'forward' | 'backward' | null}`

```typescript
interface Range {
anchor: Point
focus: Point
[key: string]: unknown
anchor: Point
focus: Point
[key: string]: unknown
}
```

Expand Down Expand Up @@ -96,7 +96,7 @@ Get the intersection of one `range` with `another`.

###### `Range.isBackward(range: Range): boolean`

Check if a `range` is backward, meaning that its anchor point appears *after* its focus point in the document.
Check if a `range` is backward, meaning that its anchor point appears _after_ its focus point in the document.

###### `Range.isCollapsed(range: Range): boolean`

Expand Down Expand Up @@ -126,5 +126,4 @@ Get the start point of a `range`

Transform a `range` by an `op`.

Options: `{affinity: 'forward' | 'backward' |
'outward' | 'inward' | null}`
Options: `{affinity: 'forward' | 'backward' | 'outward' | 'inward' | null}`
10 changes: 5 additions & 5 deletions docs/api/nodes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Node

The `Node` union type represents all of the different types of nodes that occur in a Slate document tree.
The `Node` union type represents all of the different types of nodes that occur in a Slate document tree.

```typescript
type Node = Editor | Element | Text
Expand Down Expand Up @@ -57,7 +57,7 @@ Get the first node entry in a root node from a `path`.

###### `Node.fragment(root: Node, range: Range): Descendant[]`

Get the sliced fragment represented by the `range`.
Get the sliced fragment represented by the `range`.

###### `Node.get(root: Node, path: Path): Node`

Expand Down Expand Up @@ -85,7 +85,7 @@ Get the node at a specific `path`, ensuring it's a leaf text node. If the node i

###### `Node.levels(root: Node, path: Path, options?): Generator<NodeEntry>`

Return a generator of the nodes in a branch of the tree, from a specific `path`. By default, the order is top-down, from the lowest to the highest node in the tree, but you can pass the `reverse: true` option to go bottom-up.
Return a generator of the nodes in a branch of the tree, from a specific `path`. By default, the order is top-down, from the lowest to the highest node in the tree, but you can pass the `reverse: true` option to go bottom-up.

Options: `{reverse?: boolean}`

Expand Down Expand Up @@ -236,8 +236,8 @@ Check if an element matches a set of `props`. Note: This checks custom propertie

```typescript
interface Text {
text: string,
[key: string]: unknown
text: string
[key: string]: unknown
}
```

Expand Down
12 changes: 6 additions & 6 deletions docs/api/refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

```typescript
interface PointRef {
current: Point | null
affinity: 'forward' | 'backward' | null
unref(): Point | null
current: Point | null
affinity: 'forward' | 'backward' | null
unref(): Point | null
}
```

Expand All @@ -26,9 +26,9 @@ Transform the point refs current value by an `op`.

```typescript
interface RangeRef {
current: Range | null
affinity: 'forward' | 'backward' | 'outward' | 'inward' | null
unref(): Range | null
current: Range | null
affinity: 'forward' | 'backward' | 'outward' | 'inward' | null
unref(): Range | null
}
```

Expand Down
24 changes: 12 additions & 12 deletions docs/api/transforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?)`

Expand All @@ -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?)`

Expand Down Expand Up @@ -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.

Expand All @@ -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)`

Expand Down
2 changes: 1 addition & 1 deletion docs/libraries/slate-hyperscript.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Slate Hyperscript

This package contains a hyperscript helper for creating Slate documents with JSX!
This package contains a hyperscript helper for creating Slate documents with JSX!
5 changes: 2 additions & 3 deletions docs/libraries/slate-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ React components for rendering Slate editors

The main Slate editor.

###### `DefaultElement(props: RenderElementProps)`
###### `DefaultElement(props: RenderElementProps)`

The default element renderer.

###### `DefaultLeaf(props: RenderLeafProps)`
###### `DefaultLeaf(props: RenderLeafProps)`

The default custom leaf renderer.

Expand Down Expand Up @@ -137,4 +137,3 @@ Adds React and DOM specific behaviors to the editor.
## Utils

Private convenience modules

21 changes: 16 additions & 5 deletions docs/walkthroughs/01-installing-slate.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ _Note, if you'd rather use a pre-bundled version of Slate, you can `yarn add sla

Once you've installed Slate, you'll need to import it.


```jsx
// Import React dependencies.
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useMemo, useState } from 'react'
// Import the Slate editor factory.
import { createEditor } from 'slate'

Expand Down Expand Up @@ -70,7 +69,11 @@ const App = () => {
const [value, setValue] = useState([])
// Render the Slate context.
return (
<Slate editor={editor} value={value} onChange={newValue => setValue(newValue)} />
<Slate
editor={editor}
value={value}
onChange={newValue => setValue(newValue)}
/>
)
}
```
Expand All @@ -89,7 +92,11 @@ const App = () => {
const [value, setValue] = useState([])
return (
// Add the editable component inside the context.
<Slate editor={editor} value={value} onChange={newValue => setValue(newValue)}>
<Slate
editor={editor}
value={value}
onChange={newValue => setValue(newValue)}
>
<Editable />
</Slate>
)
Expand All @@ -114,7 +121,11 @@ const App = () => {
])

return (
<Slate editor={editor} value={value} onChange={newValue => setValue(newValue)}>
<Slate
editor={editor}
value={value}
onChange={newValue => setValue(newValue)}
>
<Editable />
</Slate>
)
Expand Down
2 changes: 1 addition & 1 deletion docs/walkthroughs/02-adding-event-handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const App = () => {
// Prevent the ampersand character from being inserted.
event.preventDefault()
// Execute the `insertText` method when the event occurs.
editor.insertText("and")
editor.insertText('and')
}
}}
/>
Expand Down
Loading