Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9ee80d4
rename to .ts
nabbydude Jan 18, 2026
bf7bc87
add types to slate mocha tests
nabbydude Jan 18, 2026
ef30dc7
rename to .ts
nabbydude Jan 18, 2026
7c4fb97
add types to history and hyperscript packages and hoisted shared type…
nabbydude Jan 19, 2026
e6ad7fc
rename to .ts
nabbydude Jan 19, 2026
1b8f3a9
change imports to treat slate/src as a separate package
nabbydude Jan 19, 2026
f6c2bde
add testing properties to type definitions for elements
nabbydude Jan 19, 2026
2614f70
fix setSelection not accepting non-range selection properties
nabbydude Jan 19, 2026
919c7f1
fix mistakes caused by lack of typechecking
nabbydude Jan 19, 2026
59ebb37
fix errors caused by type widening
nabbydude Jan 19, 2026
2865cd0
prevent returning undefined from match functions
nabbydude Jan 19, 2026
4ecc12b
marking bad tests that were not testing against the current API
nabbydude Jan 19, 2026
0e831f5
fixed defining non-base editors in other packages
nabbydude Jan 19, 2026
63b53cd
changeset
nabbydude Jan 19, 2026
d34f3cd
fix error-causing type I left in CustomTypes tests
nabbydude Jan 19, 2026
4e50cd3
lint + include react tests in linting + disable lib typechecks
nabbydude Jan 19, 2026
1dfdcaf
proper ts projects dependencies
nabbydude Jan 19, 2026
166e1f5
Improve `Node.elements` tests
12joan Jan 19, 2026
eaa933b
Improve `Transforms.mergeNodes` tests
12joan Jan 19, 2026
250a671
Merge pull request #1 from 12joan/fix-tests-pr-suggestions
nabbydude Jan 20, 2026
12d845e
Capitalization
nabbydude Jan 20, 2026
0b72454
fix improper change
nabbydude Jan 30, 2026
a3314a1
automatically include testing tags and make sure every test uses prop…
nabbydude Jan 30, 2026
9f9d348
dont wrap .spec.ts files, let them define their own tests
nabbydude Jan 31, 2026
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
5 changes: 5 additions & 0 deletions .changeset/friendly-kings-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate': patch
---

Changed type signature of `Editor#setSelection` to allow non-Range properties of Selections (functionality unchanged)
3 changes: 2 additions & 1 deletion config/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"target": "esnext"
"target": "esnext",
"skipLibCheck": true
}
}
9 changes: 9 additions & 0 deletions config/typescript/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noImplicitAny": false,
"rootDir": "../..",
"jsxFactory": "jsx",
"noEmit": true
}
}
2 changes: 2 additions & 0 deletions packages/slate-history/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
],
"devDependencies": {
"@babel/runtime": "^7.23.2",
"@types/mocha": "^10.0.10",
"@types/node": "^25.0.9",
"lodash": "^4.17.21",
"slate": "^0.123.0",
"slate-hyperscript": "^0.115.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,71 @@
import assert from 'assert'
import { fixtures } from '../../../support/fixtures'
import { createHyperscript } from 'slate-hyperscript'
import { History, withHistory } from '..'
import {
createHyperscript,
createEditor as createEditorCreator,
} from 'slate-hyperscript'
import { History, HistoryEditor, withHistory } from '..'
import { BaseEditor, Editor, createEditor as createBaseEditor } from 'slate'

describe('slate-history', () => {
fixtures(__dirname, 'undo', ({ module }) => {
const { input, run, output } = module
const editor = withTest(withHistory(input))
run(editor)
editor.undo()
assert.deepEqual(editor.children, output.children)
assert.deepEqual(editor.selection, output.selection)
})

fixtures(__dirname, 'isHistory', ({ module }) => {
const { input, run, output } = module
const editor = withTest(withHistory(input))
run(editor)
const result = History.isHistory(editor.history)
assert.strictEqual(result, output)
})
})

export const jsx = createHyperscript({
elements: {
block: {},
inline: { inline: true },
},
})
declare module 'slate' {
interface CustomTypes {
// Editor is already defined in /support/types, but it will include this type
PackageSpecificEditorForTests: HistoryEditor
}
}

const withTest = editor => {
const withTest = (editor: Editor) => {
const { isInline, isVoid, isElementReadOnly, isSelectable } = editor

editor.isInline = element => {
return element.inline === true ? true : isInline(element)
}

editor.isVoid = element => {
return element.void === true ? true : isVoid(element)
}

editor.isElementReadOnly = element => {
return element.readOnly === true ? true : isElementReadOnly(element)
}

editor.isSelectable = element => {
return element.nonSelectable === true ? false : isSelectable(element)
}

return editor
}

export const jsx = createHyperscript({
elements: {
block: {},
inline: { inline: true },
},
creators: {
editor: createEditorCreator(() =>
withTest(withHistory(createBaseEditor()))
),
},
})

describe('slate-history', () => {
fixtures<{
input: BaseEditor
run: (input: Editor) => void
output: Pick<Editor, 'children' | 'selection'>
}>(__dirname, 'undo', ({ module }) => {
const { input, run, output } = module
const editor = input as Editor
run(editor)
editor.undo()
assert.deepEqual(editor.children, output.children)
assert.deepEqual(editor.selection, output.selection)
})

fixtures<{
input: BaseEditor
run: (input: Editor) => void
output: boolean
}>(__dirname, 'isHistory', ({ module }) => {
const { input, run, output } = module
const editor = input as Editor
run(editor)
const result = History.isHistory(editor.history)
assert.strictEqual(result, output)
})
})
6 changes: 0 additions & 6 deletions packages/slate-history/test/jsx.d.ts

This file was deleted.

5 changes: 5 additions & 0 deletions packages/slate-history/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../../config/typescript/tsconfig.test.json",
"include": ["./**/*", "../../../support/*"],
"references": [{ "path": "../" }]
}
2 changes: 2 additions & 0 deletions packages/slate-hyperscript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
],
"devDependencies": {
"@babel/runtime": "^7.23.2",
"@types/mocha": "^10.0.10",
"@types/node": "^25.0.9",
"slate": "^0.123.0",
"source-map-loader": "^4.0.1"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/slate-hyperscript/test/fixtures/element-custom.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/** @jsx jsx */
import { createHyperscript } from 'slate-hyperscript'

declare namespace jsx.JSX {
interface IntrinsicElements {
paragraph: {}
}
}

const jsx = createHyperscript({
elements: {
paragraph: { type: 'paragraph' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ import { resolve } from 'path'
import { fixtures } from '../../../support/fixtures'

describe('slate-hyperscript', () => {
fixtures(resolve(__dirname, 'fixtures'), ({ module }) => {
fixtures<
| {
input: unknown[]
output: unknown[]
}
| {
input: Record<string, unknown>
output: Record<string, unknown>
}
>(resolve(__dirname, 'fixtures'), ({ module }) => {
const { input, output } = module
let actual = {}
let actual: unknown[] | Record<string, unknown> = {}

if (Array.isArray(output)) {
if (Array.isArray(input)) {
actual = input
} else {
for (const key in output) {
Expand Down
6 changes: 0 additions & 6 deletions packages/slate-hyperscript/test/jsx.d.ts

This file was deleted.

5 changes: 5 additions & 0 deletions packages/slate-hyperscript/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../../config/typescript/tsconfig.test.json",
"include": ["./**/*", "../../../support/*"],
"references": [{ "path": "../" }]
}
2 changes: 1 addition & 1 deletion packages/slate-hyperscript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"outDir": "./lib",
"composite": true
},
"references": []
"references": [{ "path": "../slate" }]
}
5 changes: 3 additions & 2 deletions packages/slate-react/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../../config/typescript/tsconfig.json",
"extends": "../../../config/typescript/tsconfig.test.json",
"compilerOptions": {
"types": ["@testing-library/jest-dom"]
"jsxFactory": "React.createElement",
"jsxFragmentFactory": "React.Fragment"
},
"references": [{ "path": "../" }]
}
3 changes: 3 additions & 0 deletions packages/slate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
],
"devDependencies": {
"@babel/runtime": "^7.23.2",
"@types/lodash": "^4.17.23",
"@types/mocha": "^10.0.10",
"@types/node": "^25.0.9",
"lodash": "^4.17.21",
"slate-hyperscript": "^0.115.0",
"source-map-loader": "^4.0.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/slate/src/interfaces/transforms/selection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Editor, Location, Point, Range } from '../../index'
import { Editor, Location, Point, Selection } from '../../index'
import { MoveUnit, SelectionEdge } from '../../types/types'

export interface SelectionCollapseOptions {
Expand Down Expand Up @@ -49,7 +49,7 @@ export interface SelectionTransforms {
/**
* Set new properties on the selection.
*/
setSelection: (editor: Editor, props: Partial<Range>) => void
setSelection: (editor: Editor, props: Partial<Selection>) => void
}

// eslint-disable-next-line no-redeclare
Expand Down
12 changes: 6 additions & 6 deletions packages/slate/src/transforms-selection/set-selection.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SelectionTransforms } from '../interfaces/transforms/selection'
import { Range } from '../interfaces/range'
import { Point } from '../interfaces/point'
import { Selection } from '../interfaces'

export const setSelection: SelectionTransforms['setSelection'] = (
editor,
props
) => {
const { selection } = editor
const oldProps: Partial<Range> | null = {}
const newProps: Partial<Range> = {}
const oldProps: Partial<Selection> = {}
const newProps: Partial<Selection> = {}

if (!selection) {
return
Expand All @@ -24,10 +24,10 @@ export const setSelection: SelectionTransforms['setSelection'] = (
!Point.equals(props.focus, selection.focus)) ||
(k !== 'anchor' &&
k !== 'focus' &&
props[<keyof Range>k] !== selection[<keyof Range>k])
props[k as keyof Selection] !== selection[k as keyof Selection])
) {
oldProps[<keyof Range>k] = selection[<keyof Range>k]
newProps[<keyof Range>k] = props[<keyof Range>k]
oldProps[k as keyof Selection] = selection[k as keyof Selection]
newProps[k as keyof Selection] = props[k as keyof Selection]
}
}

Expand Down
110 changes: 0 additions & 110 deletions packages/slate/test/index.js

This file was deleted.

Loading
Loading