Skip to content

Commit

Permalink
incremental updates for TS 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dylans committed Oct 16, 2023
1 parent fea5e3b commit e67a036
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
1 change: 0 additions & 1 deletion config/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"suppressImplicitAnyIndexErrors": true,
"target": "esnext"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"slate-react": "workspace:*",
"source-map-loader": "^4.0.0",
"ts-jest": "^27.1.3",
"typescript": "4.9.5"
"typescript": "5.0.4"
},
"simple-git-hooks": {
"pre-commit": "yarn lint-staged"
Expand Down
3 changes: 2 additions & 1 deletion packages/slate-react/src/components/leaf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {
useState,
useEffect,
} from 'react'
import type { JSX } from 'react'
import { Element, Text } from 'slate'
import { ResizeObserver as ResizeObserverPolyfill } from '@juggle/resize-observer'
import String from './string'
Expand Down Expand Up @@ -99,7 +100,7 @@ const Leaf = (props: {
useEffect(() => {
if (leafIsPlaceholder) {
if (!showPlaceholderTimeoutRef.current) {
// Delay the placeholder so it will not render in a selection
// Delay the placeholder, so it will not render in a selection
showPlaceholderTimeoutRef.current = setTimeout(() => {
setShowPlaceholder(true)
showPlaceholderTimeoutRef.current = null
Expand Down
4 changes: 2 additions & 2 deletions packages/slate/src/interfaces/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const Element: ElementInterface = {
elementVal: string,
elementKey: string = 'type'
): value is T => {
return isElement(value) && value[elementKey] === elementVal
return isElement(value) && value[<keyof Descendant>elementKey] === elementVal
},

matches(element: Element, props: Partial<Element>): boolean {
Expand All @@ -94,7 +94,7 @@ export const Element: ElementInterface = {
continue
}

if (element[key] !== props[key]) {
if (element[<keyof Descendant>key] !== props[<keyof Descendant>key]) {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/slate/src/interfaces/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const Text: TextInterface = {
continue
}

if (!text.hasOwnProperty(key) || text[key] !== props[key]) {
if (!text.hasOwnProperty(key) || text[<keyof Text>key] !== props[<keyof Text>key]) {
return false
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/slate/src/interfaces/transforms/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const applyToDraft = (editor: Editor, selection: Selection, op: Operation) => {
const parent = Node.parent(editor, path)
parent.children.splice(index, 1)

// Transform all of the points in the value, but if the point was in the
// Transform all the points in the value, but if the point was in the
// node that was removed we need to update the range or remove it.
if (selection) {
for (const [point, key] of Range.points(selection)) {
Expand Down Expand Up @@ -214,19 +214,19 @@ const applyToDraft = (editor: Editor, selection: Selection, op: Operation) => {
throw new Error(`Cannot set the "${key}" property of nodes!`)
}

const value = newProperties[key]
const value = newProperties[<keyof Node>key]

if (value == null) {
delete node[key]
delete node[<keyof Node>key]
} else {
node[key] = value
node[<keyof Node>key] = value
}
}

// properties that were previously defined, but are now missing, must be deleted
for (const key in properties) {
if (!newProperties.hasOwnProperty(key)) {
delete node[key]
delete node[<keyof Node>key]
}
}

Expand All @@ -252,16 +252,16 @@ const applyToDraft = (editor: Editor, selection: Selection, op: Operation) => {
}

for (const key in newProperties) {
const value = newProperties[key]
const value = newProperties[<keyof Range>key]

if (value == null) {
if (key === 'anchor' || key === 'focus') {
throw new Error(`Cannot remove the "${key}" selection property`)
}

delete selection[key]
delete selection[<keyof Range>key]
} else {
selection[key] = value
selection[<keyof Range>key] = value
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/slate/src/transforms-node/set-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ export const setNodes: NodeTransforms['setNodes'] = (
continue
}

if (compare(props[k], node[k])) {
if (compare(props[<keyof Node>k], node[<keyof Node>k])) {
hasChanges = true
// Omit new properties from the old properties list
if (node.hasOwnProperty(k)) properties[k] = node[k]
if (node.hasOwnProperty(k)) properties[<keyof Node>k] = node[<keyof Node>k]
// Omit properties that have been removed from the new properties list
if (merge) {
if (props[k] != null) newProperties[k] = merge(node[k], props[k])
if (props[<keyof Node>k] != null) newProperties[<keyof Node>k] = merge(node[<keyof Node>k], props[<keyof Node>k])
} else {
if (props[k] != null) newProperties[k] = props[k]
if (props[<keyof Node>k] != null) newProperties[<keyof Node>k] = props[<keyof Node>k]
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/slate/src/transforms-selection/set-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const setSelection: SelectionTransforms['setSelection'] = (
(k === 'focus' &&
props.focus != null &&
!Point.equals(props.focus, selection.focus)) ||
(k !== 'anchor' && k !== 'focus' && props[k] !== selection[k])
(k !== 'anchor' && k !== 'focus' && props[<keyof Range>k] !== selection[<keyof Range>k])
) {
oldProps[k] = selection[k]
newProps[k] = props[k]
oldProps[<keyof Range>k] = selection[<keyof Range>k]
newProps[<keyof Range>k] = props[<keyof Range>k]
}
}

Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13885,7 +13885,7 @@ resolve@^2.0.0-next.3:
slate-react: "workspace:*"
source-map-loader: ^4.0.0
ts-jest: ^27.1.3
typescript: 4.9.5
typescript: 5.0.4
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -15262,23 +15262,23 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard

"typescript@npm:4.9.5":
version: 4.9.5
resolution: "typescript@npm:4.9.5"
"typescript@npm:5.0.4":
version: 5.0.4
resolution: "typescript@npm:5.0.4"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: ee000bc26848147ad423b581bd250075662a354d84f0e06eb76d3b892328d8d4440b7487b5a83e851b12b255f55d71835b008a66cbf8f255a11e4400159237db
checksum: 82b94da3f4604a8946da585f7d6c3025fff8410779e5bde2855ab130d05e4fd08938b9e593b6ebed165bda6ad9292b230984f10952cf82f0a0ca07bbeaa08172
languageName: node
linkType: hard

"typescript@patch:typescript@4.9.5#~builtin<compat/typescript>":
version: 4.9.5
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=289587"
"typescript@patch:typescript@5.0.4#~builtin<compat/typescript>":
version: 5.0.4
resolution: "typescript@patch:typescript@npm%3A5.0.4#~builtin<compat/typescript>::version=5.0.4&hash=b5f058"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 1f8f3b6aaea19f0f67cba79057674ba580438a7db55057eb89cc06950483c5d632115c14077f6663ea76fd09fce3c190e6414bb98582ec80aa5a4eaf345d5b68
checksum: d26b6ba97b6d163c55dbdffd9bbb4c211667ebebc743accfeb2c8c0154aace7afd097b51165a72a5bad2cf65a4612259344ff60f8e642362aa1695c760d303ac
languageName: node
linkType: hard

Expand Down

0 comments on commit e67a036

Please sign in to comment.