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

Commit 4540b10

Browse files
bminglesRavenColEvol
authored andcommitted
refactor: Split out slate dom package (ianstormtaylor#5734)
* 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
1 parent 71ee0c3 commit 4540b10

37 files changed

+1847
-1559
lines changed

.changeset/brown-suns-smile.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'slate-react': minor
3+
'slate-dom': minor
4+
---
5+
6+
Split out slate-dom package

config/rollup/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { startCase } from 'lodash'
1212
import Core from '../../packages/slate/package.json'
1313
import History from '../../packages/slate-history/package.json'
1414
import Hyperscript from '../../packages/slate-hyperscript/package.json'
15+
import DOM from '../../packages/slate-dom/package.json'
1516
import React from '../../packages/slate-react/package.json'
1617

1718
/**
@@ -203,5 +204,6 @@ export default [
203204
...factory(Core),
204205
...factory(History),
205206
...factory(Hyperscript),
207+
...factory(DOM),
206208
...factory(React),
207209
]

packages/slate-dom/package.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "slate-dom",
3+
"description": "Tools for building completely customizable richtext editors with React.",
4+
"version": "0.110.2",
5+
"license": "MIT",
6+
"repository": "git://github.com/ianstormtaylor/slate.git",
7+
"main": "dist/index.js",
8+
"module": "dist/index.es.js",
9+
"types": "dist/index.d.ts",
10+
"umd": "dist/slate-dom.js",
11+
"umdMin": "dist/slate-dom.min.js",
12+
"sideEffects": false,
13+
"files": [
14+
"dist/"
15+
],
16+
"dependencies": {
17+
"@juggle/resize-observer": "^3.4.0",
18+
"direction": "^1.0.4",
19+
"is-hotkey": "^0.2.0",
20+
"is-plain-object": "^5.0.0",
21+
"lodash": "^4.17.21",
22+
"scroll-into-view-if-needed": "^3.1.0",
23+
"tiny-invariant": "1.3.1"
24+
},
25+
"devDependencies": {
26+
"@babel/runtime": "^7.23.2",
27+
"@types/is-hotkey": "^0.1.8",
28+
"@types/jest": "29.5.6",
29+
"@types/jsdom": "^21.1.4",
30+
"@types/lodash": "^4.14.200",
31+
"@types/resize-observer-browser": "^0.1.8",
32+
"slate": "^0.110.2",
33+
"slate-hyperscript": "^0.100.0",
34+
"source-map-loader": "^4.0.1"
35+
},
36+
"peerDependencies": {
37+
"slate": ">=0.99.0"
38+
},
39+
"umdGlobals": {
40+
"slate": "Slate"
41+
},
42+
"keywords": [
43+
"canvas",
44+
"contenteditable",
45+
"docs",
46+
"document",
47+
"edit",
48+
"editor",
49+
"editable",
50+
"html",
51+
"immutable",
52+
"markdown",
53+
"medium",
54+
"paper",
55+
"react",
56+
"rich",
57+
"richtext",
58+
"richtext",
59+
"slate",
60+
"text",
61+
"wysiwyg",
62+
"wysiwym"
63+
]
64+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { BaseRange, BaseText } from 'slate'
2+
import { DOMEditor } from './plugin/dom-editor'
3+
4+
declare module 'slate' {
5+
interface CustomTypes {
6+
Editor: DOMEditor
7+
Text: BaseText & {
8+
placeholder?: string
9+
onPlaceholderResize?: (node: HTMLElement | null) => void
10+
// FIXME: is unknown correct here?
11+
[key: string]: unknown
12+
}
13+
Range: BaseRange & {
14+
placeholder?: string
15+
onPlaceholderResize?: (node: HTMLElement | null) => void
16+
// FIXME: is unknown correct here?
17+
[key: string]: unknown
18+
}
19+
}
20+
}
21+
22+
declare global {
23+
interface Window {
24+
MSStream: boolean
25+
}
26+
interface DocumentOrShadowRoot {
27+
getSelection(): Selection | null
28+
}
29+
30+
interface CaretPosition {
31+
readonly offsetNode: Node
32+
readonly offset: number
33+
getClientRect(): DOMRect | null
34+
}
35+
36+
interface Document {
37+
caretPositionFromPoint(x: number, y: number): CaretPosition | null
38+
}
39+
40+
interface Node {
41+
getRootNode(options?: GetRootNodeOptions): Document | ShadowRoot
42+
}
43+
}
44+
45+
export {}

packages/slate-dom/src/index.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Plugin
2+
export { DOMEditor, type DOMEditorInterface } from './plugin/dom-editor'
3+
export { withDOM } from './plugin/with-dom'
4+
5+
// Utils
6+
export { TRIPLE_CLICK } from './utils/constants'
7+
8+
export {
9+
applyStringDiff,
10+
mergeStringDiffs,
11+
normalizePoint,
12+
normalizeRange,
13+
normalizeStringDiff,
14+
StringDiff,
15+
targetRange,
16+
TextDiff,
17+
verifyDiffState,
18+
} from './utils/diff-text'
19+
20+
export {
21+
DOMElement,
22+
DOMNode,
23+
DOMPoint,
24+
DOMRange,
25+
DOMSelection,
26+
DOMStaticRange,
27+
DOMText,
28+
getActiveElement,
29+
getDefaultView,
30+
getSelection,
31+
hasShadowRoot,
32+
isAfter,
33+
isBefore,
34+
isDOMElement,
35+
isDOMNode,
36+
isDOMSelection,
37+
isPlainTextOnlyPaste,
38+
isTrackedMutation,
39+
normalizeDOMPoint,
40+
} from './utils/dom'
41+
42+
export {
43+
CAN_USE_DOM,
44+
HAS_BEFORE_INPUT_SUPPORT,
45+
IS_ANDROID,
46+
IS_CHROME,
47+
IS_FIREFOX,
48+
IS_FIREFOX_LEGACY,
49+
IS_IOS,
50+
IS_WEBKIT,
51+
IS_UC_MOBILE,
52+
IS_WECHATBROWSER,
53+
} from './utils/environment'
54+
55+
export { default as Hotkeys } from './utils/hotkeys'
56+
57+
export { Key } from './utils/key'
58+
59+
export {
60+
isElementDecorationsEqual,
61+
isTextDecorationsEqual,
62+
} from './utils/range-list'
63+
64+
export {
65+
EDITOR_TO_ELEMENT,
66+
EDITOR_TO_FORCE_RENDER,
67+
EDITOR_TO_KEY_TO_ELEMENT,
68+
EDITOR_TO_ON_CHANGE,
69+
EDITOR_TO_PENDING_ACTION,
70+
EDITOR_TO_PENDING_DIFFS,
71+
EDITOR_TO_PENDING_INSERTION_MARKS,
72+
EDITOR_TO_PENDING_SELECTION,
73+
EDITOR_TO_PLACEHOLDER_ELEMENT,
74+
EDITOR_TO_SCHEDULE_FLUSH,
75+
EDITOR_TO_USER_MARKS,
76+
EDITOR_TO_USER_SELECTION,
77+
EDITOR_TO_WINDOW,
78+
ELEMENT_TO_NODE,
79+
IS_COMPOSING,
80+
IS_FOCUSED,
81+
IS_NODE_MAP_DIRTY,
82+
IS_READ_ONLY,
83+
MARK_PLACEHOLDER_SYMBOL,
84+
NODE_TO_ELEMENT,
85+
NODE_TO_INDEX,
86+
NODE_TO_KEY,
87+
NODE_TO_PARENT,
88+
PLACEHOLDER_SYMBOL,
89+
} from './utils/weak-maps'

0 commit comments

Comments
 (0)