prosemirror-view
Advanced tools
Comparing version 1.31.6 to 1.31.7
{ | ||
"name": "prosemirror-view", | ||
"version": "1.31.6", | ||
"version": "1.31.7", | ||
"description": "ProseMirror's view component", | ||
@@ -5,0 +5,0 @@ "type": "module", |
import {Selection, NodeSelection, TextSelection, AllSelection, EditorState} from "prosemirror-state" | ||
import {EditorView} from "./index" | ||
import * as browser from "./browser" | ||
import {domIndex, selectionCollapsed} from "./dom" | ||
import {domIndex, selectionCollapsed, hasBlockDesc} from "./dom" | ||
import {selectionToDOM} from "./selection" | ||
@@ -58,2 +58,3 @@ | ||
function isIgnorable(dom: Node) { | ||
if ((dom as HTMLElement).contentEditable == "false") return true | ||
let desc = dom.pmViewDesc | ||
@@ -160,3 +161,38 @@ return desc && desc.size == 0 && (dom.nextSibling || dom.nodeName != "BR") | ||
function textNodeAfter(node: Node | null, offset: number): Text | undefined { | ||
while (node && offset == node.childNodes.length && !hasBlockDesc(node)) { | ||
offset = domIndex(node) + 1 | ||
node = node.parentNode | ||
} | ||
while (node && offset < node.childNodes.length) { | ||
node = node.childNodes[offset] | ||
if (node.nodeType == 3) return node as Text | ||
offset = 0 | ||
} | ||
} | ||
function textNodeBefore(node: Node | null, offset: number): Text | undefined { | ||
while (node && !offset && !hasBlockDesc(node)) { | ||
offset = domIndex(node) | ||
node = node.parentNode | ||
} | ||
while (node && offset) { | ||
node = node.childNodes[offset - 1] | ||
if (node.nodeType == 3) return node as Text | ||
offset = node.childNodes.length | ||
} | ||
} | ||
function setSelFocus(view: EditorView, node: Node, offset: number) { | ||
if (node.nodeType != 3) { | ||
let before, after | ||
if (after = textNodeAfter(node, offset)) { | ||
node = after | ||
offset = 0 | ||
} else if (before = textNodeBefore(node, offset)) { | ||
node = before | ||
offset = before.nodeValue!.length | ||
} | ||
} | ||
let sel = view.domSelection() | ||
@@ -163,0 +199,0 @@ if (selectionCollapsed(sel)) { |
@@ -77,3 +77,3 @@ export type DOMNode = InstanceType<typeof window.Node> | ||
function hasBlockDesc(dom: Node) { | ||
export function hasBlockDesc(dom: Node) { | ||
let desc | ||
@@ -80,0 +80,0 @@ for (let cur: Node | null = dom; cur; cur = cur.parentNode) if (desc = cur.pmViewDesc) break |
@@ -82,2 +82,5 @@ import {Fragment, DOMParser, ParseRule, Node, Mark, ResolvedPos} from "prosemirror-model" | ||
export function readDOMChange(view: EditorView, from: number, to: number, typeOver: boolean, addedNodes: readonly DOMNode[]) { | ||
let compositionID = view.input.compositionPendingChanges || (view.composing ? view.input.compositionID : 0) | ||
view.input.compositionPendingChanges = 0 | ||
if (from < 0) { | ||
@@ -94,3 +97,3 @@ let origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null | ||
else if (origin == "key") tr.scrollIntoView() | ||
if (view.composing) tr.setMeta("composition", view.input.compositionID) | ||
if (compositionID) tr.setMeta("composition", compositionID) | ||
view.dispatch(tr) | ||
@@ -138,3 +141,3 @@ } | ||
let tr = view.state.tr.setSelection(sel) | ||
if (view.composing) tr.setMeta("composition", view.input.compositionID) | ||
if (compositionID) tr.setMeta("composition", compositionID) | ||
view.dispatch(tr) | ||
@@ -274,3 +277,3 @@ } | ||
if (storedMarks) tr.ensureMarks(storedMarks) | ||
if (view.composing) tr.setMeta("composition", view.input.compositionID) | ||
if (compositionID) tr.setMeta("composition", compositionID) | ||
view.dispatch(tr.scrollIntoView()) | ||
@@ -277,0 +280,0 @@ } |
@@ -40,3 +40,5 @@ import {EditorState} from "prosemirror-state" | ||
else if (rect.bottom > bounding.bottom - getSide(scrollThreshold, "bottom")) | ||
moveY = rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom") | ||
moveY = rect.bottom - rect.top > bounding.bottom - bounding.top | ||
? rect.top + getSide(scrollMargin, "top") - bounding.top | ||
: rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom") | ||
if (rect.left < bounding.left + getSide(scrollThreshold, "left")) | ||
@@ -43,0 +45,0 @@ moveX = -(bounding.left - rect.left + getSide(scrollMargin, "left")) |
@@ -160,10 +160,12 @@ import {Selection} from "prosemirror-state" | ||
pendingRecords() { | ||
if (this.observer) for (let mut of this.observer.takeRecords()) this.queue.push(mut) | ||
return this.queue | ||
} | ||
flush() { | ||
let {view} = this | ||
if (!view.docView || this.flushingSoon > -1) return | ||
let mutations = this.observer ? this.observer.takeRecords() : [] | ||
if (this.queue.length) { | ||
mutations = this.queue.concat(mutations) | ||
this.queue.length = 0 | ||
} | ||
let mutations = this.pendingRecords() | ||
if (mutations.length) this.queue = [] | ||
@@ -170,0 +172,0 @@ let sel = view.domSelectionRange() |
@@ -37,2 +37,4 @@ import {Selection, NodeSelection, TextSelection} from "prosemirror-state" | ||
compositionID = 1 | ||
// Set to a composition ID when there are pending changes at compositionend | ||
compositionPendingChanges = 0 | ||
domChangeCount = 0 | ||
@@ -491,2 +493,4 @@ eventHandlers: {[event: string]: (event: Event) => void} = Object.create(null) | ||
view.input.compositionEndedAt = event.timeStamp | ||
view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0 | ||
if (view.input.compositionPendingChanges) Promise.resolve().then(() => view.domObserver.flush()) | ||
view.input.compositionID++ | ||
@@ -493,0 +497,0 @@ scheduleComposeEnd(view, 20) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
834483
16977