prosemirror-flat-list
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -732,2 +732,7 @@ // src/commands/dedent-list.ts | ||
// src/utils/is-collapsed-list-node.ts | ||
function isCollapsedListNode(node) { | ||
return !!(isListNode(node) && node.attrs.collapsed); | ||
} | ||
// src/commands/protect-collapsed.ts | ||
@@ -742,3 +747,3 @@ var protectCollapsed = (state, dispatch) => { | ||
} | ||
if (parent && isListNode(parent) && parent.attrs.collapsed && index >= 1) { | ||
if (parent && isCollapsedListNode(parent) && index >= 1) { | ||
found = true; | ||
@@ -951,2 +956,23 @@ if (!dispatch) { | ||
// src/commands/set-safe-selection.ts | ||
import { TextSelection } from "prosemirror-state"; | ||
function moveOutOfCollapsed($pos, minDepth) { | ||
for (let depth = minDepth; depth <= $pos.depth; depth++) { | ||
if (isCollapsedListNode($pos.node(depth)) && $pos.index(depth) >= 1) { | ||
const before = $pos.posAtIndex(depth, 1); | ||
const $before = $pos.doc.resolve(before); | ||
return TextSelection.near($before, -1); | ||
} | ||
} | ||
return null; | ||
} | ||
function setSafeSelection(tr) { | ||
const { $from, $to, to } = tr.selection; | ||
const selection = moveOutOfCollapsed($from, 0) || moveOutOfCollapsed($to, $from.sharedDepth(to)); | ||
if (selection) { | ||
tr.setSelection(selection); | ||
} | ||
return tr; | ||
} | ||
// src/commands/toggle-collapsed.ts | ||
@@ -962,11 +988,9 @@ function createToggleCollapsedCommand({ | ||
if (isListNode(node) && isToggleable(node)) { | ||
const pos = $from.before(depth); | ||
const attrs = node.attrs; | ||
dispatch == null ? void 0 : dispatch( | ||
state.tr.setNodeAttribute( | ||
pos, | ||
"collapsed", | ||
collapsed != null ? collapsed : !attrs.collapsed | ||
) | ||
); | ||
if (dispatch) { | ||
const pos = $from.before(depth); | ||
const attrs = node.attrs; | ||
const tr = state.tr; | ||
tr.setNodeAttribute(pos, "collapsed", collapsed != null ? collapsed : !attrs.collapsed); | ||
dispatch(setSafeSelection(tr)); | ||
} | ||
return true; | ||
@@ -1070,3 +1094,3 @@ } | ||
if (setNodeAttributes(tr, listPos, list.attrs, attrs)) { | ||
view.dispatch(tr); | ||
view.dispatch(setSafeSelection(tr)); | ||
} | ||
@@ -1373,2 +1397,3 @@ return true; | ||
handleListMarkerMouseDown, | ||
isCollapsedListNode, | ||
isListNode, | ||
@@ -1385,3 +1410,4 @@ isListType, | ||
rangeToString, | ||
setSafeSelection, | ||
wrappingListInputRule | ||
}; |
@@ -262,2 +262,7 @@ import { Command } from 'prosemirror-state'; | ||
/** | ||
* @internal | ||
*/ | ||
export declare function isCollapsedListNode(node: ProsemirrorNode): boolean; | ||
/** @public */ | ||
@@ -433,2 +438,9 @@ export declare function isListNode(node: Node_2 | null | undefined): boolean; | ||
/** | ||
* If one of the selection's end points is inside a collapsed node, move the selection outside of it | ||
* | ||
* @internal | ||
*/ | ||
export declare function setSafeSelection(tr: Transaction): Transaction; | ||
/** | ||
* @public | ||
@@ -435,0 +447,0 @@ */ |
@@ -732,2 +732,7 @@ // src/commands/dedent-list.ts | ||
// src/utils/is-collapsed-list-node.ts | ||
function isCollapsedListNode(node) { | ||
return !!(isListNode(node) && node.attrs.collapsed); | ||
} | ||
// src/commands/protect-collapsed.ts | ||
@@ -742,3 +747,3 @@ var protectCollapsed = (state, dispatch) => { | ||
} | ||
if (parent && isListNode(parent) && parent.attrs.collapsed && index >= 1) { | ||
if (parent && isCollapsedListNode(parent) && index >= 1) { | ||
found = true; | ||
@@ -951,2 +956,23 @@ if (!dispatch) { | ||
// src/commands/set-safe-selection.ts | ||
import { TextSelection } from "prosemirror-state"; | ||
function moveOutOfCollapsed($pos, minDepth) { | ||
for (let depth = minDepth; depth <= $pos.depth; depth++) { | ||
if (isCollapsedListNode($pos.node(depth)) && $pos.index(depth) >= 1) { | ||
const before = $pos.posAtIndex(depth, 1); | ||
const $before = $pos.doc.resolve(before); | ||
return TextSelection.near($before, -1); | ||
} | ||
} | ||
return null; | ||
} | ||
function setSafeSelection(tr) { | ||
const { $from, $to, to } = tr.selection; | ||
const selection = moveOutOfCollapsed($from, 0) || moveOutOfCollapsed($to, $from.sharedDepth(to)); | ||
if (selection) { | ||
tr.setSelection(selection); | ||
} | ||
return tr; | ||
} | ||
// src/commands/toggle-collapsed.ts | ||
@@ -962,11 +988,9 @@ function createToggleCollapsedCommand({ | ||
if (isListNode(node) && isToggleable(node)) { | ||
const pos = $from.before(depth); | ||
const attrs = node.attrs; | ||
dispatch == null ? void 0 : dispatch( | ||
state.tr.setNodeAttribute( | ||
pos, | ||
"collapsed", | ||
collapsed != null ? collapsed : !attrs.collapsed | ||
) | ||
); | ||
if (dispatch) { | ||
const pos = $from.before(depth); | ||
const attrs = node.attrs; | ||
const tr = state.tr; | ||
tr.setNodeAttribute(pos, "collapsed", collapsed != null ? collapsed : !attrs.collapsed); | ||
dispatch(setSafeSelection(tr)); | ||
} | ||
return true; | ||
@@ -1070,3 +1094,3 @@ } | ||
if (setNodeAttributes(tr, listPos, list.attrs, attrs)) { | ||
view.dispatch(tr); | ||
view.dispatch(setSafeSelection(tr)); | ||
} | ||
@@ -1373,2 +1397,3 @@ return true; | ||
handleListMarkerMouseDown, | ||
isCollapsedListNode, | ||
isListNode, | ||
@@ -1385,3 +1410,4 @@ isListType, | ||
rangeToString, | ||
setSafeSelection, | ||
wrappingListInputRule | ||
}; |
{ | ||
"name": "prosemirror-flat-list", | ||
"type": "module", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Powerful list support for ProseMirror", | ||
@@ -6,0 +6,0 @@ "author": "ocavue <ocavue@gmail.com>", |
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
145225
4631