Skip to content

Commit

Permalink
refactor: Split out slate dom package (ianstormtaylor#5734)
Browse files Browse the repository at this point in the history
* Copied some things from slate-react into new react-dom package

* Refactor slate-react to use slate-dom

* Fixed failing tests

* Created changeset

* Ran fix:prettier

* Fixed name

* Removed duplicate code

* Fixed import

* Restored linting rule

* Bumped slate-dom version

* Bumped slate dependency version

* Added export of IS_NODE_MAP_DIRTY after rebase
  • Loading branch information
bmingles authored Oct 31, 2024
0 parents commit f50a915
Show file tree
Hide file tree
Showing 16 changed files with 2,904 additions and 0 deletions.
64 changes: 64 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "slate-dom",
"description": "Tools for building completely customizable richtext editors with React.",
"version": "0.110.2",
"license": "MIT",
"repository": "git://github.com/ianstormtaylor/slate.git",
"main": "dist/index.js",
"module": "dist/index.es.js",
"types": "dist/index.d.ts",
"umd": "dist/slate-dom.js",
"umdMin": "dist/slate-dom.min.js",
"sideEffects": false,
"files": [
"dist/"
],
"dependencies": {
"@juggle/resize-observer": "^3.4.0",
"direction": "^1.0.4",
"is-hotkey": "^0.2.0",
"is-plain-object": "^5.0.0",
"lodash": "^4.17.21",
"scroll-into-view-if-needed": "^3.1.0",
"tiny-invariant": "1.3.1"
},
"devDependencies": {
"@babel/runtime": "^7.23.2",
"@types/is-hotkey": "^0.1.8",
"@types/jest": "29.5.6",
"@types/jsdom": "^21.1.4",
"@types/lodash": "^4.14.200",
"@types/resize-observer-browser": "^0.1.8",
"slate": "^0.110.2",
"slate-hyperscript": "^0.100.0",
"source-map-loader": "^4.0.1"
},
"peerDependencies": {
"slate": ">=0.99.0"
},
"umdGlobals": {
"slate": "Slate"
},
"keywords": [
"canvas",
"contenteditable",
"docs",
"document",
"edit",
"editor",
"editable",
"html",
"immutable",
"markdown",
"medium",
"paper",
"react",
"rich",
"richtext",
"richtext",
"slate",
"text",
"wysiwyg",
"wysiwym"
]
}
45 changes: 45 additions & 0 deletions src/custom-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BaseRange, BaseText } from 'slate'
import { DOMEditor } from './plugin/dom-editor'

declare module 'slate' {
interface CustomTypes {
Editor: DOMEditor
Text: BaseText & {
placeholder?: string
onPlaceholderResize?: (node: HTMLElement | null) => void
// FIXME: is unknown correct here?
[key: string]: unknown
}
Range: BaseRange & {
placeholder?: string
onPlaceholderResize?: (node: HTMLElement | null) => void
// FIXME: is unknown correct here?
[key: string]: unknown
}
}
}

declare global {
interface Window {
MSStream: boolean
}
interface DocumentOrShadowRoot {
getSelection(): Selection | null
}

interface CaretPosition {
readonly offsetNode: Node
readonly offset: number
getClientRect(): DOMRect | null
}

interface Document {
caretPositionFromPoint(x: number, y: number): CaretPosition | null
}

interface Node {
getRootNode(options?: GetRootNodeOptions): Document | ShadowRoot
}
}

export {}
89 changes: 89 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Plugin
export { DOMEditor, type DOMEditorInterface } from './plugin/dom-editor'
export { withDOM } from './plugin/with-dom'

// Utils
export { TRIPLE_CLICK } from './utils/constants'

export {
applyStringDiff,
mergeStringDiffs,
normalizePoint,
normalizeRange,
normalizeStringDiff,
StringDiff,
targetRange,
TextDiff,
verifyDiffState,
} from './utils/diff-text'

export {
DOMElement,
DOMNode,
DOMPoint,
DOMRange,
DOMSelection,
DOMStaticRange,
DOMText,
getActiveElement,
getDefaultView,
getSelection,
hasShadowRoot,
isAfter,
isBefore,
isDOMElement,
isDOMNode,
isDOMSelection,
isPlainTextOnlyPaste,
isTrackedMutation,
normalizeDOMPoint,
} from './utils/dom'

export {
CAN_USE_DOM,
HAS_BEFORE_INPUT_SUPPORT,
IS_ANDROID,
IS_CHROME,
IS_FIREFOX,
IS_FIREFOX_LEGACY,
IS_IOS,
IS_WEBKIT,
IS_UC_MOBILE,
IS_WECHATBROWSER,
} from './utils/environment'

export { default as Hotkeys } from './utils/hotkeys'

export { Key } from './utils/key'

export {
isElementDecorationsEqual,
isTextDecorationsEqual,
} from './utils/range-list'

export {
EDITOR_TO_ELEMENT,
EDITOR_TO_FORCE_RENDER,
EDITOR_TO_KEY_TO_ELEMENT,
EDITOR_TO_ON_CHANGE,
EDITOR_TO_PENDING_ACTION,
EDITOR_TO_PENDING_DIFFS,
EDITOR_TO_PENDING_INSERTION_MARKS,
EDITOR_TO_PENDING_SELECTION,
EDITOR_TO_PLACEHOLDER_ELEMENT,
EDITOR_TO_SCHEDULE_FLUSH,
EDITOR_TO_USER_MARKS,
EDITOR_TO_USER_SELECTION,
EDITOR_TO_WINDOW,
ELEMENT_TO_NODE,
IS_COMPOSING,
IS_FOCUSED,
IS_NODE_MAP_DIRTY,
IS_READ_ONLY,
MARK_PLACEHOLDER_SYMBOL,
NODE_TO_ELEMENT,
NODE_TO_INDEX,
NODE_TO_KEY,
NODE_TO_PARENT,
PLACEHOLDER_SYMBOL,
} from './utils/weak-maps'
Loading

0 comments on commit f50a915

Please sign in to comment.