prosemirror-flat-list
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -49,3 +49,3 @@ // src/commands/dedent-list.ts | ||
kind: "task", | ||
checked: element.hasAttribute("data-checked") | ||
checked: element.hasAttribute("data-list-checked") | ||
}; | ||
@@ -838,2 +838,12 @@ } | ||
// src/utils/create-and-fill.ts | ||
function createAndFill(type, attrs, content, marks) { | ||
const node = type.createAndFill(attrs, content, marks); | ||
if (!node) { | ||
throw new RangeError(`Failed to create '${type.name}' node`); | ||
} | ||
node.check(); | ||
return node; | ||
} | ||
// src/utils/is-block-node-selection.ts | ||
@@ -896,17 +906,24 @@ function isBlockNodeSelection(selection) { | ||
const tr = state.tr; | ||
const listType = listNode.type; | ||
const attrs = listNode.attrs; | ||
const newAttrs = { kind: attrs.kind }; | ||
tr.delete(tr.selection.from, tr.selection.to); | ||
const { $from, $to } = tr.selection; | ||
const atEnd = $to.parentOffset == $to.parent.content.size; | ||
const { parentOffset } = $to; | ||
const atStart = parentOffset == 0; | ||
const atEnd = parentOffset == $to.parent.content.size; | ||
if (atStart) { | ||
if (dispatch) { | ||
const pos = $from.before(-1); | ||
tr.insert(pos, createAndFill(listType, newAttrs)); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
return true; | ||
} | ||
if (atEnd && attrs.collapsed) { | ||
if (dispatch) { | ||
const pos = $from.after(-1); | ||
tr.insert( | ||
pos, | ||
listNode.type.createAndFill({ | ||
kind: attrs.kind | ||
}) | ||
); | ||
tr.insert(pos, createAndFill(listType, newAttrs)); | ||
tr.setSelection(Selection.near(tr.doc.resolve(pos))); | ||
dispatch(tr); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
@@ -917,10 +934,3 @@ return true; | ||
const typesAfter = [ | ||
{ | ||
type: getListType(state.schema), | ||
attrs: { | ||
// We don't want to inherit all list attributes (e.g. checked) except | ||
// for the list kind | ||
kind: attrs.kind | ||
} | ||
}, | ||
{ type: listType, attrs: newAttrs }, | ||
nextType ? { type: nextType } : null | ||
@@ -927,0 +937,0 @@ ]; |
@@ -49,3 +49,3 @@ // src/commands/dedent-list.ts | ||
kind: "task", | ||
checked: element.hasAttribute("data-checked") | ||
checked: element.hasAttribute("data-list-checked") | ||
}; | ||
@@ -838,2 +838,12 @@ } | ||
// src/utils/create-and-fill.ts | ||
function createAndFill(type, attrs, content, marks) { | ||
const node = type.createAndFill(attrs, content, marks); | ||
if (!node) { | ||
throw new RangeError(`Failed to create '${type.name}' node`); | ||
} | ||
node.check(); | ||
return node; | ||
} | ||
// src/utils/is-block-node-selection.ts | ||
@@ -896,17 +906,24 @@ function isBlockNodeSelection(selection) { | ||
const tr = state.tr; | ||
const listType = listNode.type; | ||
const attrs = listNode.attrs; | ||
const newAttrs = { kind: attrs.kind }; | ||
tr.delete(tr.selection.from, tr.selection.to); | ||
const { $from, $to } = tr.selection; | ||
const atEnd = $to.parentOffset == $to.parent.content.size; | ||
const { parentOffset } = $to; | ||
const atStart = parentOffset == 0; | ||
const atEnd = parentOffset == $to.parent.content.size; | ||
if (atStart) { | ||
if (dispatch) { | ||
const pos = $from.before(-1); | ||
tr.insert(pos, createAndFill(listType, newAttrs)); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
return true; | ||
} | ||
if (atEnd && attrs.collapsed) { | ||
if (dispatch) { | ||
const pos = $from.after(-1); | ||
tr.insert( | ||
pos, | ||
listNode.type.createAndFill({ | ||
kind: attrs.kind | ||
}) | ||
); | ||
tr.insert(pos, createAndFill(listType, newAttrs)); | ||
tr.setSelection(Selection.near(tr.doc.resolve(pos))); | ||
dispatch(tr); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
@@ -917,10 +934,3 @@ return true; | ||
const typesAfter = [ | ||
{ | ||
type: getListType(state.schema), | ||
attrs: { | ||
// We don't want to inherit all list attributes (e.g. checked) except | ||
// for the list kind | ||
kind: attrs.kind | ||
} | ||
}, | ||
{ type: listType, attrs: newAttrs }, | ||
nextType ? { type: nextType } : null | ||
@@ -927,0 +937,0 @@ ]; |
{ | ||
"name": "prosemirror-flat-list", | ||
"type": "module", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"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
156436
4940