prosemirror-flat-list
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -90,3 +90,4 @@ // src/commands/dedent-list.ts | ||
nativeList = false, | ||
markerToDOM = defaultMarkerToDOM | ||
getMarker = defaultMarkerGetter, | ||
getAttributes = defaultAttributesGetter | ||
}) { | ||
@@ -96,13 +97,4 @@ var _a; | ||
const markerHidden = ((_a = node.firstChild) == null ? void 0 : _a.type) === node.type; | ||
const marker = markerHidden ? null : markerToDOM(attrs); | ||
const markerType = markerHidden ? void 0 : attrs.type || "bullet"; | ||
const domAttrs = { | ||
class: "prosemirror-flat-list", | ||
"data-list-type": markerType, | ||
"data-list-order": attrs.order != null ? String(attrs.order) : void 0, | ||
"data-list-checked": attrs.checked ? "" : void 0, | ||
"data-list-collapsed": attrs.collapsed ? "" : void 0, | ||
"data-list-collapsable": node.childCount >= 2 ? "" : void 0, | ||
style: attrs.order != null ? `counter-set: prosemirror-flat-list-counter ${attrs.order};` : void 0 | ||
}; | ||
const marker = markerHidden || nativeList ? null : getMarker(node); | ||
const domAttrs = getAttributes(node); | ||
const contentContainer = ["div", { class: "list-content" }, 0]; | ||
@@ -120,14 +112,11 @@ if (marker) { | ||
]; | ||
return nativeList ? [ | ||
attrs.type === "ordered" ? "ol" : "ul", | ||
["li", domAttrs, markerContainer, contentContainer] | ||
] : ["div", domAttrs, markerContainer, contentContainer]; | ||
return ["div", domAttrs, markerContainer, contentContainer]; | ||
} else if (!nativeList) { | ||
return ["div", domAttrs, contentContainer]; | ||
} else { | ||
return nativeList ? [ | ||
attrs.type === "ordered" ? "ol" : "ul", | ||
["li", domAttrs, contentContainer] | ||
] : ["div", domAttrs, contentContainer]; | ||
return [attrs.type === "ordered" ? "ol" : "ul", ["li", domAttrs, 0]]; | ||
} | ||
} | ||
var defaultMarkerToDOM = (attrs) => { | ||
function defaultMarkerGetter(node) { | ||
const attrs = node.attrs; | ||
switch (attrs.type) { | ||
@@ -149,3 +138,19 @@ case "task": | ||
} | ||
}; | ||
} | ||
function defaultAttributesGetter(node) { | ||
var _a; | ||
const attrs = node.attrs; | ||
const markerHidden = ((_a = node.firstChild) == null ? void 0 : _a.type) === node.type; | ||
const markerType = markerHidden ? void 0 : attrs.type || "bullet"; | ||
const domAttrs = { | ||
class: "prosemirror-flat-list", | ||
"data-list-type": markerType, | ||
"data-list-order": attrs.order != null ? String(attrs.order) : void 0, | ||
"data-list-checked": attrs.checked ? "" : void 0, | ||
"data-list-collapsed": attrs.collapsed ? "" : void 0, | ||
"data-list-collapsable": node.childCount >= 2 ? "" : void 0, | ||
style: attrs.order != null ? `counter-set: prosemirror-flat-list-counter ${attrs.order};` : void 0 | ||
}; | ||
return domAttrs; | ||
} | ||
@@ -1107,2 +1112,8 @@ // src/schema/spec.ts | ||
} | ||
static fromSchema(schema) { | ||
return schema.cached.listDomSerializer || (schema.cached.listDomSerializer = new ListDOMSerializer( | ||
this.nodesFromSchema(schema), | ||
this.marksFromSchema(schema) | ||
)); | ||
} | ||
serializeFragment(fragment, options, target) { | ||
@@ -1139,6 +1150,3 @@ const dom = super.serializeFragment(fragment, options, target); | ||
}, | ||
clipboardSerializer: new ListDOMSerializer( | ||
ListDOMSerializer.nodesFromSchema(schema), | ||
ListDOMSerializer.marksFromSchema(schema) | ||
) | ||
clipboardSerializer: ListDOMSerializer.fromSchema(schema) | ||
} | ||
@@ -1168,4 +1176,5 @@ }); | ||
createWrapInListCommand, | ||
defaultAttributesGetter, | ||
defaultListClickHandler, | ||
defaultMarkerToDOM, | ||
defaultMarkerGetter, | ||
doSplitList, | ||
@@ -1179,2 +1188,3 @@ enterWithoutLift, | ||
isListType, | ||
joinListElements, | ||
listKeymap, | ||
@@ -1181,0 +1191,0 @@ listToDOM, |
@@ -87,6 +87,17 @@ import { Attrs } from 'prosemirror-model'; | ||
/** @internal */ | ||
export declare function defaultAttributesGetter(node: Node_2): { | ||
class: string; | ||
'data-list-type': ListType | undefined; | ||
'data-list-order': string | undefined; | ||
'data-list-checked': string | undefined; | ||
'data-list-collapsed': string | undefined; | ||
'data-list-collapsable': string | undefined; | ||
style: string | undefined; | ||
}; | ||
/** @internal */ | ||
export declare const defaultListClickHandler: ListClickHandler; | ||
/** @internal */ | ||
export declare const defaultMarkerToDOM: MarkerToDOM; | ||
export declare function defaultMarkerGetter(node: Node_2): DOMOutputSpec[] | null; | ||
@@ -129,2 +140,9 @@ /** | ||
/** | ||
* Merge adjacent <ul> elements or adjacent <ol> elements into a single list element. | ||
* | ||
* @public | ||
*/ | ||
export declare function joinListElements<T extends Element | DocumentFragment>(parent: T): T; | ||
/** @public */ | ||
@@ -146,2 +164,3 @@ export declare interface ListAttributes { | ||
}; | ||
static fromSchema(schema: Schema): ListDOMSerializer; | ||
serializeFragment(fragment: Fragment, options?: { | ||
@@ -174,9 +193,27 @@ document?: Document; | ||
/** @public */ | ||
export declare function listToDOM({ node, nativeList, markerToDOM, }: ListToDOMProps): DOMOutputSpec; | ||
export declare function listToDOM({ node, nativeList, getMarker, getAttributes, }: ListToDOMProps): DOMOutputSpec; | ||
/** @public */ | ||
export declare interface ListToDOMProps { | ||
/** | ||
* The list node to be rendered. | ||
*/ | ||
node: Node_2; | ||
/** | ||
* If `true`, the list will be rendered as a native `<ul>` or `<ol>` element. | ||
* You might want to use {@link joinListElements} to join the list elements | ||
* later. | ||
* | ||
* @defaultValue false | ||
*/ | ||
nativeList?: boolean; | ||
markerToDOM?: MarkerToDOM; | ||
/** | ||
* An optional function to get the content inside `<div class="list-marker">`. | ||
* If this function returns `null`, the marker will be hidden. | ||
*/ | ||
getMarker?: (node: Node_2) => DOMOutputSpec[] | null; | ||
/** | ||
* An optional function to get the attributes added to HTML element. | ||
*/ | ||
getAttributes?: (node: Node_2) => Record<string, string | undefined>; | ||
} | ||
@@ -194,5 +231,2 @@ | ||
/** @public */ | ||
export declare type MarkerToDOM = (attrs: ListAttributes) => DOMOutputSpec[] | null; | ||
/** | ||
@@ -199,0 +233,0 @@ * Migrate a ProseMirror document JSON object from the old list structure to the |
@@ -90,3 +90,4 @@ // src/commands/dedent-list.ts | ||
nativeList = false, | ||
markerToDOM = defaultMarkerToDOM | ||
getMarker = defaultMarkerGetter, | ||
getAttributes = defaultAttributesGetter | ||
}) { | ||
@@ -96,13 +97,4 @@ var _a; | ||
const markerHidden = ((_a = node.firstChild) == null ? void 0 : _a.type) === node.type; | ||
const marker = markerHidden ? null : markerToDOM(attrs); | ||
const markerType = markerHidden ? void 0 : attrs.type || "bullet"; | ||
const domAttrs = { | ||
class: "prosemirror-flat-list", | ||
"data-list-type": markerType, | ||
"data-list-order": attrs.order != null ? String(attrs.order) : void 0, | ||
"data-list-checked": attrs.checked ? "" : void 0, | ||
"data-list-collapsed": attrs.collapsed ? "" : void 0, | ||
"data-list-collapsable": node.childCount >= 2 ? "" : void 0, | ||
style: attrs.order != null ? `counter-set: prosemirror-flat-list-counter ${attrs.order};` : void 0 | ||
}; | ||
const marker = markerHidden || nativeList ? null : getMarker(node); | ||
const domAttrs = getAttributes(node); | ||
const contentContainer = ["div", { class: "list-content" }, 0]; | ||
@@ -120,14 +112,11 @@ if (marker) { | ||
]; | ||
return nativeList ? [ | ||
attrs.type === "ordered" ? "ol" : "ul", | ||
["li", domAttrs, markerContainer, contentContainer] | ||
] : ["div", domAttrs, markerContainer, contentContainer]; | ||
return ["div", domAttrs, markerContainer, contentContainer]; | ||
} else if (!nativeList) { | ||
return ["div", domAttrs, contentContainer]; | ||
} else { | ||
return nativeList ? [ | ||
attrs.type === "ordered" ? "ol" : "ul", | ||
["li", domAttrs, contentContainer] | ||
] : ["div", domAttrs, contentContainer]; | ||
return [attrs.type === "ordered" ? "ol" : "ul", ["li", domAttrs, 0]]; | ||
} | ||
} | ||
var defaultMarkerToDOM = (attrs) => { | ||
function defaultMarkerGetter(node) { | ||
const attrs = node.attrs; | ||
switch (attrs.type) { | ||
@@ -149,3 +138,19 @@ case "task": | ||
} | ||
}; | ||
} | ||
function defaultAttributesGetter(node) { | ||
var _a; | ||
const attrs = node.attrs; | ||
const markerHidden = ((_a = node.firstChild) == null ? void 0 : _a.type) === node.type; | ||
const markerType = markerHidden ? void 0 : attrs.type || "bullet"; | ||
const domAttrs = { | ||
class: "prosemirror-flat-list", | ||
"data-list-type": markerType, | ||
"data-list-order": attrs.order != null ? String(attrs.order) : void 0, | ||
"data-list-checked": attrs.checked ? "" : void 0, | ||
"data-list-collapsed": attrs.collapsed ? "" : void 0, | ||
"data-list-collapsable": node.childCount >= 2 ? "" : void 0, | ||
style: attrs.order != null ? `counter-set: prosemirror-flat-list-counter ${attrs.order};` : void 0 | ||
}; | ||
return domAttrs; | ||
} | ||
@@ -1107,2 +1112,8 @@ // src/schema/spec.ts | ||
} | ||
static fromSchema(schema) { | ||
return schema.cached.listDomSerializer || (schema.cached.listDomSerializer = new ListDOMSerializer( | ||
this.nodesFromSchema(schema), | ||
this.marksFromSchema(schema) | ||
)); | ||
} | ||
serializeFragment(fragment, options, target) { | ||
@@ -1139,6 +1150,3 @@ const dom = super.serializeFragment(fragment, options, target); | ||
}, | ||
clipboardSerializer: new ListDOMSerializer( | ||
ListDOMSerializer.nodesFromSchema(schema), | ||
ListDOMSerializer.marksFromSchema(schema) | ||
) | ||
clipboardSerializer: ListDOMSerializer.fromSchema(schema) | ||
} | ||
@@ -1168,4 +1176,5 @@ }); | ||
createWrapInListCommand, | ||
defaultAttributesGetter, | ||
defaultListClickHandler, | ||
defaultMarkerToDOM, | ||
defaultMarkerGetter, | ||
doSplitList, | ||
@@ -1179,2 +1188,3 @@ enterWithoutLift, | ||
isListType, | ||
joinListElements, | ||
listKeymap, | ||
@@ -1181,0 +1191,0 @@ listToDOM, |
{ | ||
"name": "prosemirror-flat-list", | ||
"type": "module", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "", | ||
@@ -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
119873
3808