1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-21 13:51:59 +02:00

Revert "Revert "TypeScript Improvement: Use [key: string]: unknown, not [key: string]: any ()""

This reverts commit 81d2f9bb8f6a78590d7868deb289ec36fb208629.
This commit is contained in:
CameronAckermanSEL 2020-05-04 17:38:14 -07:00
parent 036ee664af
commit d82ffe49a5
17 changed files with 42 additions and 38 deletions

@ -28,7 +28,7 @@ type Path = number[]
interface Point {
path: Path
offset: number
[key: string]: any
[key: string]: unknown
}
```
@ -68,7 +68,7 @@ Options: `{affinity?: 'forward' | 'backward' | null}`
interface Range {
anchor: Point
focus: Point
[key: string]: any
[key: string]: unknown
}
```

@ -123,7 +123,7 @@ interface Editor {
selection: Range | null
operations: Operation[]
marks: Record<string, any> | null
[key: string]: any
[key: string]: unknown
// Schema-specific node behaviors.
isInline: (element: Element) => boolean
@ -212,7 +212,7 @@ Apply an operation in the editor.
```typescript
interface Element {
children: Node[]
[key: string]: any
[key: string]: unknown
}
```
@ -237,7 +237,7 @@ Check if an element matches a set of `props`. Note: This checks custom propertie
```typescript
interface Text {
text: string,
[key: string]: any
[key: string]: unknown
}
```

@ -5,7 +5,7 @@ Slate works with pure JSON objects. All it requires is that those JSON objects c
```ts
interface Text {
text: string
[key: string]: any
[key: string]: unknown
}
```
@ -22,7 +22,7 @@ To take another example, the `Element` node interface in Slate is:
```ts
interface Element {
children: Node[]
[key: string]: any
[key: string]: unknown
}
```

@ -55,7 +55,7 @@ Elements make up the middle layers of a richtext document. They are the nodes th
```ts
interface Element {
children: Node[]
[key: string]: any
[key: string]: unknown
}
```
@ -126,7 +126,7 @@ Text nodes are the lowest-level nodes in the tree, containing the text content o
```ts
interface Text {
text: string
[key: string]: any
[key: string]: unknown
}
```

@ -37,7 +37,7 @@ Points are slightly more specific than paths, and contain an `offset` into a spe
interface Point {
path: Path
offset: number
[key: string]: any
[key: string]: unknown
}
```
@ -71,7 +71,7 @@ Ranges are a way to refer not just to a single point in the document, but to a w
interface Range {
anchor: Point
focus: Point
[key: string]: any
[key: string]: unknown
}
```

@ -8,7 +8,7 @@ interface Editor {
selection: Range | null
operations: Operation[]
marks: Record<string, any> | null
[key: string]: any
[key: string]: unknown
// Schema-specific node behaviors.
isInline: (element: Element) => boolean

@ -708,7 +708,7 @@ export const Editable = (props: EditableProps) => {
if (Hotkeys.isRedo(nativeEvent)) {
event.preventDefault()
if (editor.redo) {
if (typeof editor.redo === 'function') {
editor.redo()
}
@ -718,7 +718,7 @@ export const Editable = (props: EditableProps) => {
if (Hotkeys.isUndo(nativeEvent)) {
event.preventDefault()
if (editor.undo) {
if (typeof editor.undo === 'function') {
editor.undo()
}

@ -43,7 +43,7 @@ const Leaf = (props: {
opacity: '0.333',
}}
>
{leaf.placeholder}
{leaf.placeholder as React.ReactNode}
</span>
{children}
</React.Fragment>

@ -17,7 +17,7 @@ export const Slate = (props: {
value: Node[]
children: React.ReactNode
onChange: (value: Node[]) => void
[key: string]: any
[key: string]: unknown
}) => {
const { editor, children, onChange, value, ...rest } = props
const [key, setKey] = useState(0)

@ -38,7 +38,7 @@ export interface Editor {
selection: Range | null
operations: Operation[]
marks: Record<string, any> | null
[key: string]: any
[key: string]: unknown
// Schema-specific node behaviors.
isInline: (element: Element) => boolean
@ -1332,7 +1332,7 @@ export const Editor = {
// the operation was applied.
parent.children.splice(index, 1)
const truePath = Path.transform(path, op)!
const newParent = Node.get(editor, Path.parent(truePath))
const newParent = Node.get(editor, Path.parent(truePath)) as Ancestor
const newIndex = truePath[truePath.length - 1]
newParent.children.splice(newIndex, 0, node)

@ -9,7 +9,7 @@ import { Editor, Node, Path } from '..'
export interface Element {
children: Node[]
[key: string]: any
[key: string]: unknown
}
export const Element = {

@ -5,7 +5,7 @@ export type InsertNodeOperation = {
type: 'insert_node'
path: Path
node: Node
[key: string]: any
[key: string]: unknown
}
export type InsertTextOperation = {
@ -13,7 +13,7 @@ export type InsertTextOperation = {
path: Path
offset: number
text: string
[key: string]: any
[key: string]: unknown
}
export type MergeNodeOperation = {
@ -22,21 +22,21 @@ export type MergeNodeOperation = {
position: number
target: number | null
properties: Partial<Node>
[key: string]: any
[key: string]: unknown
}
export type MoveNodeOperation = {
type: 'move_node'
path: Path
newPath: Path
[key: string]: any
[key: string]: unknown
}
export type RemoveNodeOperation = {
type: 'remove_node'
path: Path
node: Node
[key: string]: any
[key: string]: unknown
}
export type RemoveTextOperation = {
@ -44,7 +44,7 @@ export type RemoveTextOperation = {
path: Path
offset: number
text: string
[key: string]: any
[key: string]: unknown
}
export type SetNodeOperation = {
@ -52,25 +52,25 @@ export type SetNodeOperation = {
path: Path
properties: Partial<Node>
newProperties: Partial<Node>
[key: string]: any
[key: string]: unknown
}
export type SetSelectionOperation =
| {
type: 'set_selection'
[key: string]: any
[key: string]: unknown
properties: null
newProperties: Range
}
| {
type: 'set_selection'
[key: string]: any
[key: string]: unknown
properties: Partial<Range>
newProperties: Partial<Range>
}
| {
type: 'set_selection'
[key: string]: any
[key: string]: unknown
properties: Range
newProperties: null
}
@ -81,7 +81,7 @@ export type SplitNodeOperation = {
position: number
target: number | null
properties: Partial<Node>
[key: string]: any
[key: string]: unknown
}
export type NodeOperation =

@ -12,7 +12,7 @@ import { Operation, Path } from '..'
export interface Point {
path: Path
offset: number
[key: string]: any
[key: string]: unknown
}
export const Point = {

@ -11,7 +11,7 @@ import { Operation, Path, Point, PointEntry } from '..'
export interface Range {
anchor: Point
focus: Point
[key: string]: any
[key: string]: unknown
}
export const Range = {

@ -9,7 +9,7 @@ import { Range } from '..'
export interface Text {
text: string
[key: string]: any
[key: string]: unknown
}
export const Text = {

@ -10,7 +10,7 @@ import {
Descendant,
NodeEntry,
Path,
Transforms,
Ancestor,
} from '..'
export const GeneralTransforms = {
@ -104,7 +104,7 @@ export const GeneralTransforms = {
// the operation was applied.
parent.children.splice(index, 1)
const truePath = Path.transform(path, op)!
const newParent = Node.get(editor, Path.parent(truePath))
const newParent = Node.get(editor, Path.parent(truePath)) as Ancestor
const newIndex = truePath[truePath.length - 1]
newParent.children.splice(newIndex, 0, node)

@ -8,6 +8,8 @@ import {
Range,
Text,
Transforms,
NodeEntry,
Ancestor,
} from '..'
export const NodeTransforms = {
@ -168,7 +170,8 @@ export const NodeTransforms = {
)
}
const [parent, parentPath] = Editor.node(editor, Path.parent(path))
const parentNodeEntry = Editor.node(editor, Path.parent(path))
const [parent, parentPath] = parentNodeEntry as NodeEntry<Ancestor>
const index = path[path.length - 1]
const { length } = parent.children
@ -721,7 +724,7 @@ export const NodeTransforms = {
for (const pathRef of pathRefs) {
const path = pathRef.unref()!
const [node] = Editor.node(editor, path)
const [node] = Editor.node(editor, path) as NodeEntry<Ancestor>
let range = Editor.range(editor, path)
if (split && rangeRef) {
@ -823,7 +826,8 @@ export const NodeTransforms = {
: Path.common(firstPath, lastPath)
const range = Editor.range(editor, firstPath, lastPath)
const [commonNode] = Editor.node(editor, commonPath)
const commonNodeEntry = Editor.node(editor, commonPath)
const [commonNode] = commonNodeEntry as NodeEntry<Ancestor>
const depth = commonPath.length + 1
const wrapperPath = Path.next(lastPath.slice(0, depth))
const wrapper = { ...element, children: [] }