prosemirror-flat-list
Advanced tools
Comparing version 0.0.25 to 0.0.26
@@ -869,2 +869,33 @@ // src/commands/dedent-list.ts | ||
// src/commands/toggle-collapsed.ts | ||
function createToggleCollapsedCommand({ | ||
collapsed = void 0, | ||
isToggleable = defaultIsToggleable | ||
} = {}) { | ||
const toggleCollapsed = (state, dispatch) => { | ||
const { $from } = state.selection; | ||
for (let depth = $from.depth; depth >= 0; depth--) { | ||
const node = $from.node(depth); | ||
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 | ||
) | ||
); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
return toggleCollapsed; | ||
} | ||
function defaultIsToggleable(node) { | ||
const attrs = node.attrs; | ||
return attrs.kind === "toggle" && node.childCount >= 2 && !isListNode(node.firstChild); | ||
} | ||
// src/commands/wrap-in-list.ts | ||
@@ -1194,2 +1225,3 @@ import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
createSplitListCommand, | ||
createToggleCollapsedCommand, | ||
createWrapInListCommand, | ||
@@ -1196,0 +1228,0 @@ defaultAttributesGetter, |
@@ -16,2 +16,3 @@ import { Attrs } from 'prosemirror-model'; | ||
import { Plugin as Plugin_2 } from 'prosemirror-state'; | ||
import { ProsemirrorNode } from '@remirror/core'; | ||
import { ResolvedPos } from 'prosemirror-model'; | ||
@@ -84,2 +85,9 @@ import { Schema } from 'prosemirror-model'; | ||
/** | ||
* @public | ||
* | ||
* Return a command function that toggle the `collapsed` attribute of the list node. | ||
*/ | ||
export declare function createToggleCollapsedCommand({ collapsed, isToggleable, }?: ToggleCollapsedProps): Command; | ||
/** | ||
* Returns a command function that wraps the selection in a list with the given | ||
@@ -325,4 +333,18 @@ * type an attributes. | ||
/** @public */ | ||
export declare interface ToggleCollapsedProps { | ||
/** | ||
* If this value exists, the command will set the `collapsed` attribute to | ||
* this value instead of toggle it. | ||
*/ | ||
collapsed?: boolean; | ||
/** | ||
* An optional function to accept a list node and return whether or not this | ||
* node can toggle its `collapsed` attribute. | ||
*/ | ||
isToggleable?: (node: ProsemirrorNode) => boolean; | ||
} | ||
/** @public */ | ||
export declare function wrappingListInputRule<T extends Attrs = ListAttributes>(re: RegExp, getAttrs: T | ((matches: RegExpMatchArray) => T)): InputRule; | ||
export { } |
@@ -869,2 +869,33 @@ // src/commands/dedent-list.ts | ||
// src/commands/toggle-collapsed.ts | ||
function createToggleCollapsedCommand({ | ||
collapsed = void 0, | ||
isToggleable = defaultIsToggleable | ||
} = {}) { | ||
const toggleCollapsed = (state, dispatch) => { | ||
const { $from } = state.selection; | ||
for (let depth = $from.depth; depth >= 0; depth--) { | ||
const node = $from.node(depth); | ||
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 | ||
) | ||
); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
return toggleCollapsed; | ||
} | ||
function defaultIsToggleable(node) { | ||
const attrs = node.attrs; | ||
return attrs.kind === "toggle" && node.childCount >= 2 && !isListNode(node.firstChild); | ||
} | ||
// src/commands/wrap-in-list.ts | ||
@@ -1194,2 +1225,3 @@ import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
createSplitListCommand, | ||
createToggleCollapsedCommand, | ||
createWrapInListCommand, | ||
@@ -1196,0 +1228,0 @@ defaultAttributesGetter, |
{ | ||
"name": "prosemirror-flat-list", | ||
"type": "module", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"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
127369
4050