@milkdown/prose
Advanced tools
Comparing version 7.3.1 to 7.3.2
@@ -36,5 +36,5 @@ import { InputRule } from 'prosemirror-inputrules'; | ||
declare const customInputRulesKey: PluginKey<any>; | ||
declare const customInputRules: ({ rules }: { | ||
declare function customInputRules({ rules }: { | ||
rules: InputRule[]; | ||
}) => Plugin; | ||
}): Plugin; | ||
@@ -44,3 +44,3 @@ declare function markRule(regexp: RegExp, markType: MarkType): InputRule; | ||
type Point = [top: number, left: number]; | ||
declare const calculateNodePosition: (view: EditorView, target: HTMLElement, handler: (selectedRect: DOMRect, targetRect: DOMRect, parentRect: DOMRect) => Point) => void; | ||
declare function calculateNodePosition(view: EditorView, target: HTMLElement, handler: (selectedRect: DOMRect, targetRect: DOMRect, parentRect: DOMRect) => Point): void; | ||
interface Rect { | ||
@@ -52,7 +52,7 @@ left: number; | ||
} | ||
declare const calculateTextPosition: (view: EditorView, target: HTMLElement, handler: (start: Rect, end: Rect, targetRect: DOMRect, parentRect: DOMRect) => Point) => void; | ||
declare function calculateTextPosition(view: EditorView, target: HTMLElement, handler: (start: Rect, end: Rect, targetRect: DOMRect, parentRect: DOMRect) => Point): void; | ||
declare function posToDOMRect(view: EditorView, from: number, to: number): DOMRect; | ||
declare const cloneTr: (tr: Transaction) => Transaction; | ||
declare const equalNodeType: (nodeType: NodeType | NodeType[], node: Node) => boolean; | ||
declare function cloneTr(tr: Transaction): Transaction; | ||
declare function equalNodeType(nodeType: NodeType | NodeType[], node: Node): boolean; | ||
@@ -65,8 +65,8 @@ type Predicate = (node: Node) => boolean; | ||
} | ||
declare const flatten: (node: Node, descend?: boolean) => NodeWithPos[]; | ||
declare const findChildren: (predicate: Predicate) => (node: Node, descend?: boolean) => NodeWithPos[]; | ||
declare const findChildrenByMark: (node: Node, markType: MarkType, descend?: boolean) => NodeWithPos[]; | ||
declare function flatten(node: Node, descend?: boolean): NodeWithPos[]; | ||
declare function findChildren(predicate: Predicate): (node: Node, descend?: boolean) => NodeWithPos[]; | ||
declare function findChildrenByMark(node: Node, markType: MarkType, descend?: boolean): NodeWithPos[]; | ||
declare const getNodeFromSchema: (type: string, schema: Schema) => NodeType; | ||
declare const getMarkFromSchema: (type: string, schema: Schema) => MarkType; | ||
declare function getNodeFromSchema(type: string, schema: Schema): NodeType; | ||
declare function getMarkFromSchema(type: string, schema: Schema): MarkType; | ||
@@ -79,7 +79,7 @@ interface ContentNodeWithPos { | ||
} | ||
declare const findParentNodeClosestToPos: (predicate: Predicate) => ($pos: ResolvedPos) => ContentNodeWithPos | undefined; | ||
declare const findParentNode: (predicate: Predicate) => (selection: Selection) => ContentNodeWithPos | undefined; | ||
declare const findSelectedNodeOfType: (selection: Selection, nodeType: NodeType) => ContentNodeWithPos | undefined; | ||
declare function findParentNodeClosestToPos(predicate: Predicate): ($pos: ResolvedPos) => ContentNodeWithPos | undefined; | ||
declare function findParentNode(predicate: Predicate): (selection: Selection) => ContentNodeWithPos | undefined; | ||
declare function findSelectedNodeOfType(selection: Selection, nodeType: NodeType): ContentNodeWithPos | undefined; | ||
export { type ContentNodeWithPos, type NodeWithPos, browser, calculateNodePosition, calculateTextPosition, cloneTr, customInputRules, customInputRulesKey, equalNodeType, findChildren, findChildrenByMark, findParentNode, findParentNodeClosestToPos, findSelectedNodeOfType, flatten, getMarkFromSchema, getNodeFromSchema, markRule, posToDOMRect }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -60,3 +60,3 @@ import { PluginKey, Plugin, NodeSelection } from 'prosemirror-state'; | ||
const customInputRulesKey = new PluginKey("MILKDOWN_CUSTOM_INPUTRULES"); | ||
const customInputRules = ({ rules }) => { | ||
function customInputRules({ rules }) { | ||
const plugin = new Plugin({ | ||
@@ -101,3 +101,3 @@ key: customInputRulesKey, | ||
return plugin; | ||
}; | ||
} | ||
@@ -167,3 +167,3 @@ function markRule(regexp, markType) { | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
const calculateNodePosition = (view, target, handler) => { | ||
function calculateNodePosition(view, target, handler) { | ||
const state = view.state; | ||
@@ -184,4 +184,4 @@ const { from } = state.selection; | ||
target.style.left = `${left}px`; | ||
}; | ||
const calculateTextPosition = (view, target, handler) => { | ||
} | ||
function calculateTextPosition(view, target, handler) { | ||
const state = view.state; | ||
@@ -199,3 +199,3 @@ const { from, to } = state.selection; | ||
target.style.left = `${left}px`; | ||
}; | ||
} | ||
function minMax(value = 0, min = 0, max = 0) { | ||
@@ -234,10 +234,10 @@ return Math.min(Math.max(value, min), max); | ||
const cloneTr = (tr) => { | ||
function cloneTr(tr) { | ||
return Object.assign(Object.create(tr), tr).setTime(Date.now()); | ||
}; | ||
const equalNodeType = (nodeType, node) => { | ||
} | ||
function equalNodeType(nodeType, node) { | ||
return Array.isArray(nodeType) && nodeType.includes(node.type) || node.type === nodeType; | ||
}; | ||
} | ||
const flatten = (node, descend = true) => { | ||
function flatten(node, descend = true) { | ||
const result = []; | ||
@@ -251,7 +251,11 @@ node.descendants((child, pos) => { | ||
return result; | ||
}; | ||
const findChildren = (predicate) => (node, descend) => flatten(node, descend).filter((child) => predicate(child.node)); | ||
const findChildrenByMark = (node, markType, descend) => findChildren((child) => Boolean(markType.isInSet(child.marks)))(node, descend); | ||
} | ||
function findChildren(predicate) { | ||
return (node, descend) => flatten(node, descend).filter((child) => predicate(child.node)); | ||
} | ||
function findChildrenByMark(node, markType, descend) { | ||
return findChildren((child) => Boolean(markType.isInSet(child.marks)))(node, descend); | ||
} | ||
const getNodeFromSchema = (type, schema) => { | ||
function getNodeFromSchema(type, schema) { | ||
const target = schema.nodes[type]; | ||
@@ -261,4 +265,4 @@ if (!target) | ||
return target; | ||
}; | ||
const getMarkFromSchema = (type, schema) => { | ||
} | ||
function getMarkFromSchema(type, schema) { | ||
const target = schema.marks[type]; | ||
@@ -268,22 +272,26 @@ if (!target) | ||
return target; | ||
}; | ||
} | ||
const findParentNodeClosestToPos = (predicate) => ($pos) => { | ||
for (let i = $pos.depth; i > 0; i--) { | ||
const node = $pos.node(i); | ||
if (predicate(node)) { | ||
return { | ||
pos: i > 0 ? $pos.before(i) : 0, | ||
start: $pos.start(i), | ||
depth: i, | ||
node | ||
}; | ||
function findParentNodeClosestToPos(predicate) { | ||
return ($pos) => { | ||
for (let i = $pos.depth; i > 0; i--) { | ||
const node = $pos.node(i); | ||
if (predicate(node)) { | ||
return { | ||
pos: i > 0 ? $pos.before(i) : 0, | ||
start: $pos.start(i), | ||
depth: i, | ||
node | ||
}; | ||
} | ||
} | ||
} | ||
return void 0; | ||
}; | ||
const findParentNode = (predicate) => (selection) => { | ||
return findParentNodeClosestToPos(predicate)(selection.$from); | ||
}; | ||
const findSelectedNodeOfType = (selection, nodeType) => { | ||
return void 0; | ||
}; | ||
} | ||
function findParentNode(predicate) { | ||
return (selection) => { | ||
return findParentNodeClosestToPos(predicate)(selection.$from); | ||
}; | ||
} | ||
function findSelectedNodeOfType(selection, nodeType) { | ||
if (!(selection instanceof NodeSelection)) | ||
@@ -295,5 +303,5 @@ return; | ||
return void 0; | ||
}; | ||
} | ||
export { browser, calculateNodePosition, calculateTextPosition, cloneTr, customInputRules, customInputRulesKey, equalNodeType, findChildren, findChildrenByMark, findParentNode, findParentNodeClosestToPos, findSelectedNodeOfType, flatten, getMarkFromSchema, getNodeFromSchema, markRule, posToDOMRect }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@milkdown/prose", | ||
"type": "module", | ||
"version": "7.3.1", | ||
"version": "7.3.2", | ||
"license": "MIT", | ||
@@ -133,3 +133,3 @@ "repository": { | ||
"tslib": "^2.5.0", | ||
"@milkdown/exception": "7.3.1" | ||
"@milkdown/exception": "7.3.2" | ||
}, | ||
@@ -136,0 +136,0 @@ "nx": { |
@@ -20,5 +20,5 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
: ie_11up | ||
? +ie_11up![1]! | ||
? +ie_11up[1]! | ||
: ie_edge | ||
? +ie_edge![1]! | ||
? +ie_edge[1]! | ||
: 0 | ||
@@ -25,0 +25,0 @@ export const gecko = !ie && /gecko\/(\d+)/i.test(agent) |
@@ -34,3 +34,3 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
export const customInputRulesKey = new PluginKey('MILKDOWN_CUSTOM_INPUTRULES') | ||
export const customInputRules = ({ rules }: { rules: InputRule[] }): Plugin => { | ||
export function customInputRules({ rules }: { rules: InputRule[] }): Plugin { | ||
const plugin: Plugin = new Plugin({ | ||
@@ -37,0 +37,0 @@ key: customInputRulesKey, |
@@ -15,3 +15,3 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
if (match[matchLength - 1]) { | ||
const first = match[0] as string | ||
const first = match[0] | ||
const last = match[matchLength - 1] as string | ||
@@ -48,3 +48,3 @@ const last1 = match[matchLength - 2] as string | ||
function getMarksBetween(start: number, end: number, state: EditorState) { | ||
let marks: { start: number; end: number; mark: Mark }[] = [] | ||
let marks: { start: number, end: number, mark: Mark }[] = [] | ||
@@ -51,0 +51,0 @@ state.doc.nodesBetween(start, end, (node, pos) => { |
@@ -8,7 +8,3 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
export const calculateNodePosition = ( | ||
view: EditorView, | ||
target: HTMLElement, | ||
handler: (selectedRect: DOMRect, targetRect: DOMRect, parentRect: DOMRect) => Point, | ||
) => { | ||
export function calculateNodePosition(view: EditorView, target: HTMLElement, handler: (selectedRect: DOMRect, targetRect: DOMRect, parentRect: DOMRect) => Point) { | ||
const state = view.state | ||
@@ -43,7 +39,3 @@ const { from } = state.selection | ||
export const calculateTextPosition = ( | ||
view: EditorView, | ||
target: HTMLElement, | ||
handler: (start: Rect, end: Rect, targetRect: DOMRect, parentRect: DOMRect) => Point, | ||
) => { | ||
export function calculateTextPosition(view: EditorView, target: HTMLElement, handler: (start: Rect, end: Rect, targetRect: DOMRect, parentRect: DOMRect) => Point) { | ||
const state = view.state | ||
@@ -50,0 +42,0 @@ const { from, to } = state.selection |
@@ -5,8 +5,8 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
export const cloneTr = (tr: Transaction): Transaction => { | ||
export function cloneTr(tr: Transaction): Transaction { | ||
return Object.assign(Object.create(tr), tr).setTime(Date.now()) | ||
} | ||
export const equalNodeType = (nodeType: NodeType | NodeType[], node: ProseNode) => { | ||
export function equalNodeType(nodeType: NodeType | NodeType[], node: ProseNode) { | ||
return (Array.isArray(nodeType) && nodeType.includes(node.type)) || node.type === nodeType | ||
} |
@@ -5,5 +5,5 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
export interface NodeWithPos { pos: number; node: ProseNode } | ||
export interface NodeWithPos { pos: number, node: ProseNode } | ||
export const flatten = (node: ProseNode, descend = true): NodeWithPos[] => { | ||
export function flatten(node: ProseNode, descend = true): NodeWithPos[] { | ||
const result: NodeWithPos[] = [] | ||
@@ -20,8 +20,9 @@ node.descendants((child, pos) => { | ||
export const findChildren | ||
= (predicate: Predicate) => | ||
(node: ProseNode, descend?: boolean): NodeWithPos[] => | ||
flatten(node, descend).filter(child => predicate(child.node)) | ||
export function findChildren(predicate: Predicate) { | ||
return (node: ProseNode, descend?: boolean): NodeWithPos[] => | ||
flatten(node, descend).filter(child => predicate(child.node)) | ||
} | ||
export const findChildrenByMark = (node: ProseNode, markType: MarkType, descend?: boolean): NodeWithPos[] => | ||
findChildren(child => Boolean(markType.isInSet(child.marks)))(node, descend) | ||
export function findChildrenByMark(node: ProseNode, markType: MarkType, descend?: boolean): NodeWithPos[] { | ||
return findChildren(child => Boolean(markType.isInSet(child.marks)))(node, descend) | ||
} |
@@ -6,3 +6,3 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
export const getNodeFromSchema = (type: string, schema: Schema): NodeType => { | ||
export function getNodeFromSchema(type: string, schema: Schema): NodeType { | ||
const target = schema.nodes[type] | ||
@@ -16,3 +16,3 @@ | ||
export const getMarkFromSchema = (type: string, schema: Schema): MarkType => { | ||
export function getMarkFromSchema(type: string, schema: Schema): MarkType { | ||
const target = schema.marks[type] | ||
@@ -19,0 +19,0 @@ |
@@ -8,29 +8,29 @@ /* Copyright 2021, Milkdown by Mirone. */ | ||
export interface ContentNodeWithPos { pos: number; start: number; depth: number; node: ProseNode } | ||
export interface ContentNodeWithPos { pos: number, start: number, depth: number, node: ProseNode } | ||
export const findParentNodeClosestToPos | ||
= (predicate: Predicate) => | ||
($pos: ResolvedPos): ContentNodeWithPos | undefined => { | ||
for (let i = $pos.depth; i > 0; i--) { | ||
const node = $pos.node(i) | ||
if (predicate(node)) { | ||
return { | ||
pos: i > 0 ? $pos.before(i) : 0, | ||
start: $pos.start(i), | ||
depth: i, | ||
node, | ||
} | ||
} | ||
export function findParentNodeClosestToPos(predicate: Predicate) { | ||
return ($pos: ResolvedPos): ContentNodeWithPos | undefined => { | ||
for (let i = $pos.depth; i > 0; i--) { | ||
const node = $pos.node(i) | ||
if (predicate(node)) { | ||
return { | ||
pos: i > 0 ? $pos.before(i) : 0, | ||
start: $pos.start(i), | ||
depth: i, | ||
node, | ||
} | ||
return undefined | ||
} | ||
} | ||
export const findParentNode | ||
= (predicate: Predicate) => | ||
(selection: Selection): ContentNodeWithPos | undefined => { | ||
return findParentNodeClosestToPos(predicate)(selection.$from) | ||
} | ||
return undefined | ||
} | ||
} | ||
export const findSelectedNodeOfType = (selection: Selection, nodeType: NodeType): ContentNodeWithPos | undefined => { | ||
export function findParentNode(predicate: Predicate) { | ||
return (selection: Selection): ContentNodeWithPos | undefined => { | ||
return findParentNodeClosestToPos(predicate)(selection.$from) | ||
} | ||
} | ||
export function findSelectedNodeOfType(selection: Selection, nodeType: NodeType): ContentNodeWithPos | undefined { | ||
if (!(selection instanceof NodeSelection)) | ||
@@ -37,0 +37,0 @@ return |
Sorry, the diff of this file is not supported yet
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
865
62899
+ Added@milkdown/exception@7.3.2(transitive)
- Removed@milkdown/exception@7.3.1(transitive)
Updated@milkdown/exception@7.3.2