@@ -14,38 +14,12 @@ function finitePositiveAttribute(element: Element | null, name: string): number
1414 return Number . isFinite ( value ) && value > 0 ? value : undefined
1515}
1616
17- function contentEditableSelection ( element : HTMLElement ) : {
18- currentText : string
19- selectionStart : number
20- selectionEnd : number
21- } {
22- const currentText = element . textContent ?? ''
23- const selection = document . getSelection ( )
24- if ( ! selection || selection . rangeCount === 0 ) {
25- return { currentText, selectionStart : currentText . length , selectionEnd : currentText . length }
26- }
27-
28- const range = selection . getRangeAt ( 0 )
29- if ( ! element . contains ( range . startContainer ) || ! element . contains ( range . endContainer ) ) {
30- return { currentText, selectionStart : currentText . length , selectionEnd : currentText . length }
31- }
32-
33- const before = document . createRange ( )
34- before . selectNodeContents ( element )
35- before . setEnd ( range . startContainer , range . startOffset )
36- const selectionStart = before . toString ( ) . length
37- return {
38- currentText,
39- selectionStart,
40- selectionEnd : selectionStart + range . toString ( ) . length ,
41- }
42- }
43-
4417/**
45- * Last-resort admission for every editable workspace surface. Specialized editors publish a larger
46- * or smaller payload ceiling on an ancestor with `data-paste-max-bytes`; controls without one inherit
47- * the Socket.IO-sized default. The capture listener runs before React, ProseMirror, Monaco, and xterm
48- * can parse or render the clipboard value.
18+ * Last-resort admission for every editable workspace surface. Specialized editors publish their
19+ * downstream ceiling on an ancestor with `data-paste-max-bytes`; controls without one inherit a
20+ * crash-only fallback. This layer bounds only the clipboard payload, so a small paste into an already
21+ * large field keeps native behavior. Editors with a real result-size contract enforce it themselves.
22+ * The capture listener runs before React, ProseMirror, Monaco, and xterm parse the clipboard value.
4923 */
5024export function PasteAdmissionGuard ( ) {
5125 const { toast : notify } = useToast ( )
@@ -68,31 +42,10 @@ export function PasteAdmissionGuard() {
6842 policyElement ,
6943 'data-paste-max-characters'
7044 )
71- const nativeControl =
72- event . target instanceof HTMLInputElement || event . target instanceof HTMLTextAreaElement
73- const editableElement = event . target . closest < HTMLElement > (
74- '[contenteditable]:not([contenteditable="false"])'
75- )
76- const projectedValue = nativeControl
77- ? {
78- currentText : event . target . value ,
79- selectionStart : event . target . selectionStart ?? event . target . value . length ,
80- selectionEnd : event . target . selectionEnd ?? event . target . value . length ,
81- }
82- : editableElement
83- ? contentEditableSelection ( editableElement )
84- : null
8545 const admission = assessTextPaste ( {
8646 pastedText : text ,
8747 maxPastedBytes,
8848 maxPastedCharacters,
89- ...( projectedValue
90- ? {
91- ...projectedValue ,
92- maxResultBytes : maxPastedBytes ,
93- maxResultCharacters : maxPastedCharacters ,
94- }
95- : { } ) ,
9649 } )
9750 if ( admission . accepted ) return
9851
0 commit comments