Skip to content

Commit

Permalink
Implement custom-types
Browse files Browse the repository at this point in the history
Co-authored-by: mdmjg <mdj308@nyu.edu>
  • Loading branch information
timbuckley and mdmjg committed Aug 19, 2020
1 parent dbb2072 commit d20085f
Show file tree
Hide file tree
Showing 43 changed files with 2,297 additions and 3,354 deletions.
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

0 comments on commit d20085f

Please sign in to comment.