WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/brown-suns-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'slate-react': minor
'slate-dom': minor
---

Split out slate-dom package
2 changes: 2 additions & 0 deletions config/rollup/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { startCase } from 'lodash'
import Core from '../../packages/slate/package.json'
import History from '../../packages/slate-history/package.json'
import Hyperscript from '../../packages/slate-hyperscript/package.json'
import DOM from '../../packages/slate-dom/package.json'
import React from '../../packages/slate-react/package.json'

/**
Expand Down Expand Up @@ -203,5 +204,6 @@ export default [
...factory(Core),
...factory(History),
...factory(Hyperscript),
...factory(DOM),
...factory(React),
]
64 changes: 64 additions & 0 deletions packages/slate-dom/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 packages/slate-dom/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 packages/slate-dom/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
Loading