MCPcopy Index your code
hub / github.com/editablejs/editable / ContentEditable

Function ContentEditable

packages/editor/src/components/content.tsx:79–670  ·  view source on GitHub ↗
(props: EditableProps)

Source from the content-addressed store, hash-verified

77 * ContentEditable.
78 */
79export const ContentEditable = (props: EditableProps) => {
80 const {
81 autoFocus = true,
82 placeholder,
83 readOnly: readOnlyProp = false,
84 lang,
85 style = {},
86 as: Component = 'div',
87 selectionDrawingStyle: selectionDrawingStyleProp,
88 ...attributes
89 } = props
90 const editor = useEditableStatic()
91
92 const ref = React.useRef<HTMLDivElement>(null)
93 const [readOnly, setReadOnly] = useReadOnly()
94 // 标记是否是刚拖拽完毕
95 const isDragEnded = React.useRef(false)
96 const dragTo = useDragTo()
97 const dragging = useDragging()
98 const { getDrag, setDrag } = useDragMethods()
99
100 const [rendered, setRendered] = React.useState(false)
101
102 // Touch hold timer
103 const touchHoldTimer = React.useRef<number | null>(null)
104
105 React.useEffect(() => {
106 if (placeholder && !readOnly) {
107 const unsubscribe = Placeholder.subscribe(
108 editor,
109 ([node]) => {
110 if (Editable.isEditor(node) && !node.children.some(n => Editor.isList(editor, n)))
111 return () => placeholder
112 },
113 true,
114 )
115
116 return () => {
117 unsubscribe()
118 }
119 }
120 }, [editor, placeholder, readOnly])
121
122 useIsomorphicLayoutEffect(() => {
123 setReadOnly(readOnlyProp)
124 }, [readOnlyProp])
125
126 useIsomorphicLayoutEffect(() => {
127 Locale.setLang(editor, props.lang || 'en-US')
128 }, [editor, lang])
129
130 useIsomorphicLayoutEffect(() => {
131 if (selectionDrawingStyleProp) SelectionDrawing.setStyle(editor, selectionDrawingStyleProp)
132 }, [editor, selectionDrawingStyleProp])
133
134 const [focused, setFocused] = useFocused()
135
136 const startPointRef = React.useRef<Point | null>(null)

Callers

nothing calls this directly

Calls 12

useEditableStaticFunction · 0.90
useReadOnlyFunction · 0.90
useDragToFunction · 0.90
useDraggingFunction · 0.90
useDragMethodsFunction · 0.90
useFocusedFunction · 0.90
useMultipleClickFunction · 0.90
isDOMNodeFunction · 0.90
getDefaultViewFunction · 0.90
usePlaceholderFunction · 0.90
onMethod · 0.80
offMethod · 0.80

Tested by

no test coverage detected