@prezly/slate-lists
Advanced tools
Comparing version
@@ -18,4 +18,8 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var slate_1 = require("slate"); | ||
var isListItem_1 = __importDefault(require("./isListItem")); | ||
/** | ||
@@ -32,3 +36,3 @@ * Returns all "list-items" in a given Range. | ||
at: at, | ||
match: function (node) { return slate_1.Element.isElement(node) && node.type === options.listItemType; }, | ||
match: function (node) { return (0, isListItem_1.default)(options, node); }, | ||
}); | ||
@@ -35,0 +39,0 @@ return Array.from(listItemsInSelection).filter(function (_a) { |
@@ -1,2 +0,3 @@ | ||
import { Editor, Element, NodeEntry, Path } from 'slate'; | ||
import { ElementNode } from '@prezly/slate-types'; | ||
import { Editor, NodeEntry, Path } from 'slate'; | ||
import { ListsOptions } from '../types'; | ||
@@ -7,3 +8,3 @@ /** | ||
*/ | ||
declare const getParentList: (options: ListsOptions, editor: Editor, listItemPath: Path) => NodeEntry<Element> | null; | ||
declare const getParentList: (options: ListsOptions, editor: Editor, listItemPath: Path) => NodeEntry<ElementNode> | null; | ||
export default getParentList; |
@@ -15,3 +15,3 @@ "use strict"; | ||
at: listItemPath, | ||
match: function (node) { return slate_1.Element.isElement(node) && options.listTypes.includes(node.type); }, | ||
match: function (node) { return (0, isList_1.default)(options, node); }, | ||
}); | ||
@@ -18,0 +18,0 @@ if (parentList && (0, isList_1.default)(options, parentList[0])) { |
@@ -1,2 +0,3 @@ | ||
import { Editor, Element, NodeEntry, Path } from 'slate'; | ||
import { ElementNode } from '@prezly/slate-types'; | ||
import { Editor, NodeEntry, Path } from 'slate'; | ||
import { ListsOptions } from '../types'; | ||
@@ -7,3 +8,3 @@ /** | ||
*/ | ||
declare const getParentListItem: (options: ListsOptions, editor: Editor, listItemPath: Path) => NodeEntry<Element> | null; | ||
declare const getParentListItem: (options: ListsOptions, editor: Editor, listItemPath: Path) => NodeEntry<ElementNode> | null; | ||
export default getParentListItem; |
@@ -15,3 +15,3 @@ "use strict"; | ||
at: listItemPath, | ||
match: function (node) { return slate_1.Element.isElement(node) && node.type === options.listItemType; }, | ||
match: function (node) { return (0, isListItem_1.default)(options, node); }, | ||
}); | ||
@@ -18,0 +18,0 @@ if (parentListItem && (0, isListItem_1.default)(options, parentListItem[0])) { |
@@ -0,1 +1,2 @@ | ||
import { ElementNode } from '@prezly/slate-types'; | ||
import { ListsOptions } from '../types'; | ||
@@ -5,3 +6,3 @@ /** | ||
*/ | ||
declare const isList: (options: ListsOptions, node: unknown) => node is import("slate").DefaultNode; | ||
declare function isList(options: ListsOptions, node: unknown): node is ElementNode; | ||
export default isList; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var slate_1 = require("slate"); | ||
var slate_types_1 = require("@prezly/slate-types"); | ||
/** | ||
* Checks whether node.type is an Element matching any of options.listTypes. | ||
*/ | ||
var isList = function (options, node) { | ||
return slate_1.Element.isElement(node) && options.listTypes.includes(node.type); | ||
}; | ||
function isList(options, node) { | ||
return (0, slate_types_1.isElementNode)(node, options.listTypes); | ||
} | ||
exports.default = isList; | ||
//# sourceMappingURL=isList.js.map |
@@ -0,1 +1,2 @@ | ||
import { ElementNode } from '@prezly/slate-types'; | ||
import { ListsOptions } from '../types'; | ||
@@ -5,3 +6,3 @@ /** | ||
*/ | ||
declare const isListItem: (options: ListsOptions, node: unknown) => node is import("slate").DefaultNode; | ||
declare function isListItem(options: ListsOptions, node: unknown): node is ElementNode; | ||
export default isListItem; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var slate_1 = require("slate"); | ||
var slate_types_1 = require("@prezly/slate-types"); | ||
/** | ||
* Checks whether node.type is an Element matching options.listItemType. | ||
*/ | ||
var isListItem = function (options, node) { | ||
return slate_1.Element.isElement(node) && node.type === options.listItemType; | ||
}; | ||
function isListItem(options, node) { | ||
return (0, slate_types_1.isElementNode)(node, options.listItemType); | ||
} | ||
exports.default = isListItem; | ||
//# sourceMappingURL=isListItem.js.map |
@@ -0,1 +1,2 @@ | ||
import { ElementNode } from '@prezly/slate-types'; | ||
import { ListsOptions } from '../types'; | ||
@@ -5,3 +6,3 @@ /** | ||
*/ | ||
declare const isListItemText: (options: ListsOptions, node: unknown) => node is import("slate").DefaultNode; | ||
declare function isListItemText(options: ListsOptions, node: unknown): node is ElementNode; | ||
export default isListItemText; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var slate_1 = require("slate"); | ||
var slate_types_1 = require("@prezly/slate-types"); | ||
/** | ||
* Checks whether node.type is an Element matching options.listItemTextType. | ||
*/ | ||
var isListItemText = function (options, node) { | ||
return slate_1.Element.isElement(node) && node.type === options.listItemTextType; | ||
}; | ||
function isListItemText(options, node) { | ||
return (0, slate_types_1.isElementNode)(node, options.listItemTextType); | ||
} | ||
exports.default = isListItemText; | ||
//# sourceMappingURL=isListItemText.js.map |
@@ -32,2 +32,3 @@ "use strict"; | ||
var slate_commons_1 = require("@prezly/slate-commons"); | ||
var slate_types_1 = require("@prezly/slate-types"); | ||
var slate_1 = require("slate"); | ||
@@ -50,6 +51,9 @@ var isList_1 = __importDefault(require("./isList")); | ||
var _c = __read(ancestor, 2), ancestorNode = _c[0], ancestorPath = _c[1]; | ||
if (!slate_1.Element.isElement(ancestorNode) || | ||
__spreadArray([options.listItemType], __read(options.listTypes), false).includes(ancestorNode.type)) { | ||
if (!slate_1.Element.isElement(ancestorNode)) { | ||
return false; | ||
} | ||
if ((0, slate_types_1.isElementNode)(ancestorNode) && | ||
__spreadArray(__spreadArray([], __read(options.listTypes), false), [options.listItemType], false).includes(ancestorNode.type)) { | ||
return false; | ||
} | ||
if (ancestorNode.children.length === 1) { | ||
@@ -56,0 +60,0 @@ slate_1.Transforms.unwrapNodes(editor, { at: ancestorPath, voids: true }); |
@@ -22,3 +22,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var slate_types_1 = require("@prezly/slate-types"); | ||
var slate_1 = require("slate"); | ||
@@ -42,3 +41,3 @@ var createListItem_1 = __importDefault(require("./createListItem")); | ||
var _c = __read(children[childIndex], 2), childNode = _c[0], childPath = _c[1]; | ||
if (slate_1.Text.isText(childNode) || (0, slate_types_1.isInlineNode)(childNode)) { | ||
if (slate_1.Text.isText(childNode) || editor.isInline(childNode)) { | ||
var listItemText = (0, createListItemText_1.default)(options, [childNode]); | ||
@@ -45,0 +44,0 @@ slate_1.Transforms.wrapNodes(editor, listItemText, { at: childPath }); |
@@ -6,32 +6,32 @@ import { ListsOptions } from './types'; | ||
declare const Lists: (options: ListsOptions) => { | ||
canDeleteBackward: (editor: import("slate").DefaultEditor) => boolean; | ||
decreaseDepth: (editor: import("slate").DefaultEditor) => void; | ||
decreaseListItemDepth: (editor: import("slate").DefaultEditor, listItemPath: import("slate").Path) => void; | ||
getListItemsInRange: (editor: import("slate").DefaultEditor, at: import("slate").BaseRange | null | undefined) => import("slate").NodeEntry<import("slate").DefaultNode>[]; | ||
getListsInRange: (editor: import("slate").DefaultEditor, at: import("slate").BaseRange | null | undefined) => import("slate").NodeEntry<import("slate").DefaultNode>[]; | ||
canDeleteBackward: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor) => boolean; | ||
decreaseDepth: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor) => void; | ||
decreaseListItemDepth: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, listItemPath: import("slate").Path) => void; | ||
getListItemsInRange: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, at: import("slate").BaseRange | null | undefined) => import("slate").NodeEntry<import("@prezly/slate-types").ElementNode>[]; | ||
getListsInRange: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, at: import("slate").BaseRange | null | undefined) => import("slate").NodeEntry<import("@prezly/slate-types").ElementNode>[]; | ||
getListType: (node: unknown) => string; | ||
getNestedList: (editor: import("slate").DefaultEditor, listItemPath: import("slate").Path) => import("slate").NodeEntry<import("slate").DefaultNode> | null; | ||
getParentList: (editor: import("slate").DefaultEditor, listItemPath: import("slate").Path) => import("slate").NodeEntry<import("slate").DefaultNode> | null; | ||
getParentListItem: (editor: import("slate").DefaultEditor, listItemPath: import("slate").Path) => import("slate").NodeEntry<import("slate").DefaultNode> | null; | ||
increaseDepth: (editor: import("slate").DefaultEditor) => void; | ||
increaseListItemDepth: (editor: import("slate").DefaultEditor, listItemPath: import("slate").Path) => void; | ||
isCursorAtStartOfListItem: (editor: import("slate").DefaultEditor) => boolean; | ||
isCursorInEmptyListItem: (editor: import("slate").DefaultEditor) => boolean; | ||
getNestedList: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, listItemPath: import("slate").Path) => import("slate").NodeEntry<import("@prezly/slate-types").ElementNode> | null; | ||
getParentList: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, listItemPath: import("slate").Path) => import("slate").NodeEntry<import("@prezly/slate-types").ElementNode> | null; | ||
getParentListItem: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, listItemPath: import("slate").Path) => import("slate").NodeEntry<import("@prezly/slate-types").ElementNode> | null; | ||
increaseDepth: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor) => void; | ||
increaseListItemDepth: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, listItemPath: import("slate").Path) => void; | ||
isCursorAtStartOfListItem: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor) => boolean; | ||
isCursorInEmptyListItem: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor) => boolean; | ||
isList: (node: unknown) => boolean; | ||
isListItem: (node: unknown) => boolean; | ||
isListItemText: (node: unknown) => boolean; | ||
listItemContainsText: (editor: import("slate").DefaultEditor, node: unknown) => boolean; | ||
moveListItemsToAnotherList: (editor: import("slate").DefaultEditor, parameters: { | ||
listItemContainsText: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, node: unknown) => boolean; | ||
moveListItemsToAnotherList: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, parameters: { | ||
at: import("slate").NodeEntry<import("slate").Node>; | ||
to: import("slate").NodeEntry<import("slate").Node>; | ||
}) => void; | ||
moveListToListItem: (editor: import("slate").DefaultEditor, parameters: { | ||
moveListToListItem: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, parameters: { | ||
at: import("slate").NodeEntry<import("slate").Node>; | ||
to: import("slate").NodeEntry<import("slate").Node>; | ||
}) => void; | ||
setListType: (editor: import("slate").DefaultEditor, listType: string) => void; | ||
splitListItem: (editor: import("slate").DefaultEditor) => void; | ||
unwrapList: (editor: import("slate").DefaultEditor) => void; | ||
wrapInList: (editor: import("slate").DefaultEditor, listType: string) => void; | ||
setListType: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, listType: string) => void; | ||
splitListItem: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor) => void; | ||
unwrapList: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor) => void; | ||
wrapInList: (editor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor, listType: string) => void; | ||
}; | ||
export default Lists; |
@@ -0,1 +1,2 @@ | ||
import { ElementNode } from '@prezly/slate-types'; | ||
export interface ListsOptions { | ||
@@ -5,19 +6,19 @@ /** | ||
*/ | ||
defaultBlockType: string; | ||
defaultBlockType: ElementNode['type']; | ||
/** | ||
* Type of the node representing list item text. | ||
*/ | ||
listItemTextType: string; | ||
listItemTextType: ElementNode['type']; | ||
/** | ||
* Type of the node representing list item. | ||
*/ | ||
listItemType: string; | ||
listItemType: ElementNode['type']; | ||
/** | ||
* Types of nodes representing lists. The first type will be the default type (e.g. when wrapping with lists). | ||
*/ | ||
listTypes: string[]; | ||
listTypes: ElementNode['type'][]; | ||
/** | ||
* Types of nodes that can be converted into a node representing list item text. | ||
*/ | ||
wrappableTypes: string[]; | ||
wrappableTypes: ElementNode['type'][]; | ||
} |
@@ -5,3 +5,3 @@ import { ListsOptions } from './types'; | ||
*/ | ||
declare const withLists: (options: ListsOptions) => <T extends import("slate").DefaultEditor>(editor: T) => T; | ||
declare const withLists: (options: ListsOptions) => <T extends import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor>(editor: T) => T; | ||
export default withLists; |
{ | ||
"name": "@prezly/slate-lists", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "The best Slate lists extension out there", | ||
@@ -31,11 +31,11 @@ "license": "MIT", | ||
"dependencies": { | ||
"@prezly/slate-commons": "^0.2.2", | ||
"@prezly/slate-types": "^0.2.2", | ||
"@prezly/slate-commons": "^0.3.0", | ||
"@prezly/slate-types": "^0.3.0", | ||
"uuid": "^8.3.2" | ||
}, | ||
"devDependencies": { | ||
"@prezly/slate-hyperscript": "^0.2.2", | ||
"@prezly/slate-hyperscript": "^0.3.0", | ||
"@types/uuid": "^8.3.0" | ||
}, | ||
"gitHead": "fc9d07e662e6d23a7a23ee293d19f65cde11486c" | ||
"gitHead": "d82fb3271763b0c2b97abd75516b7a8e092e0aa7" | ||
} |
@@ -5,2 +5,4 @@ import { Editor, Element, NodeEntry, Path, Range } from 'slate'; | ||
import isListItem from './isListItem'; | ||
/** | ||
@@ -22,3 +24,3 @@ * Returns all "list-items" in a given Range. | ||
at, | ||
match: (node) => Element.isElement(node) && node.type === options.listItemType, | ||
match: (node) => isListItem(options, node), | ||
}); | ||
@@ -25,0 +27,0 @@ |
@@ -1,5 +0,5 @@ | ||
import { Editor, Element, NodeEntry, Path } from 'slate'; | ||
import { ElementNode } from '@prezly/slate-types'; | ||
import { Editor, NodeEntry, Path } from 'slate'; | ||
import { ListsOptions } from '../types'; | ||
import isList from './isList'; | ||
@@ -15,10 +15,10 @@ | ||
listItemPath: Path, | ||
): NodeEntry<Element> | null => { | ||
const parentList = Editor.above(editor, { | ||
): NodeEntry<ElementNode> | null => { | ||
const parentList = Editor.above<ElementNode>(editor, { | ||
at: listItemPath, | ||
match: (node) => Element.isElement(node) && options.listTypes.includes(node.type as string), | ||
match: (node) => isList(options, node), | ||
}); | ||
if (parentList && isList(options, parentList[0])) { | ||
return parentList as NodeEntry<Element>; | ||
return parentList; | ||
} | ||
@@ -25,0 +25,0 @@ |
@@ -1,2 +0,3 @@ | ||
import { Editor, Element, NodeEntry, Path } from 'slate'; | ||
import { ElementNode } from '@prezly/slate-types'; | ||
import { Editor, NodeEntry, Path } from 'slate'; | ||
@@ -15,10 +16,10 @@ import { ListsOptions } from '../types'; | ||
listItemPath: Path, | ||
): NodeEntry<Element> | null => { | ||
const parentListItem = Editor.above(editor, { | ||
): NodeEntry<ElementNode> | null => { | ||
const parentListItem = Editor.above<ElementNode>(editor, { | ||
at: listItemPath, | ||
match: (node) => Element.isElement(node) && node.type === options.listItemType, | ||
match: (node) => isListItem(options, node), | ||
}); | ||
if (parentListItem && isListItem(options, parentListItem[0])) { | ||
return parentListItem as NodeEntry<Element>; | ||
return parentListItem; | ||
} | ||
@@ -25,0 +26,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Element } from 'slate'; | ||
import { ElementNode, isElementNode } from '@prezly/slate-types'; | ||
@@ -8,6 +8,6 @@ import { ListsOptions } from '../types'; | ||
*/ | ||
const isList = (options: ListsOptions, node: unknown): node is Element => { | ||
return Element.isElement(node) && options.listTypes.includes(node.type as string); | ||
}; | ||
function isList(options: ListsOptions, node: unknown): node is ElementNode { | ||
return isElementNode(node, options.listTypes); | ||
} | ||
export default isList; |
@@ -1,2 +0,2 @@ | ||
import { Element } from 'slate'; | ||
import { ElementNode, isElementNode } from '@prezly/slate-types'; | ||
@@ -8,6 +8,6 @@ import { ListsOptions } from '../types'; | ||
*/ | ||
const isListItem = (options: ListsOptions, node: unknown): node is Element => { | ||
return Element.isElement(node) && node.type === options.listItemType; | ||
}; | ||
function isListItem(options: ListsOptions, node: unknown): node is ElementNode { | ||
return isElementNode(node, options.listItemType); | ||
} | ||
export default isListItem; |
@@ -1,2 +0,2 @@ | ||
import { Element } from 'slate'; | ||
import { ElementNode, isElementNode } from '@prezly/slate-types'; | ||
@@ -8,6 +8,6 @@ import { ListsOptions } from '../types'; | ||
*/ | ||
const isListItemText = (options: ListsOptions, node: unknown): node is Element => { | ||
return Element.isElement(node) && node.type === options.listItemTextType; | ||
}; | ||
function isListItemText(options: ListsOptions, node: unknown): node is ElementNode { | ||
return isElementNode(node, options.listItemTextType); | ||
} | ||
export default isListItemText; |
import { EditorCommands } from '@prezly/slate-commons'; | ||
import { isElementNode } from '@prezly/slate-types'; | ||
import { Editor, Element, Node, NodeEntry, Transforms } from 'slate'; | ||
@@ -30,5 +31,9 @@ | ||
if (!Element.isElement(ancestorNode)) { | ||
return false; | ||
} | ||
if ( | ||
!Element.isElement(ancestorNode) || | ||
[options.listItemType, ...options.listTypes].includes(ancestorNode.type as string) | ||
isElementNode(ancestorNode) && | ||
[...options.listTypes, options.listItemType].includes(ancestorNode.type) | ||
) { | ||
@@ -35,0 +40,0 @@ return false; |
@@ -1,2 +0,1 @@ | ||
import { isInlineNode } from '@prezly/slate-types'; | ||
import { Editor, Element, Node, NodeEntry, Text, Transforms } from 'slate'; | ||
@@ -30,3 +29,3 @@ | ||
if (Text.isText(childNode) || isInlineNode(childNode)) { | ||
if (Text.isText(childNode) || editor.isInline(childNode)) { | ||
const listItemText = createListItemText(options, [childNode]); | ||
@@ -33,0 +32,0 @@ Transforms.wrapNodes(editor, listItemText, { at: childPath }); |
/* eslint-disable no-param-reassign */ | ||
import { EditorCommands } from '@prezly/slate-commons'; | ||
import { | ||
@@ -12,2 +11,3 @@ BULLETED_LIST_NODE_TYPE, | ||
PARAGRAPH_NODE_TYPE, | ||
isElementNode, | ||
} from '@prezly/slate-types'; | ||
@@ -37,6 +37,8 @@ import { Editor } from 'slate'; | ||
editor.isInline = (element) => | ||
EditorCommands.isElementWithType(element) && element.type === INLINE_ELEMENT | ||
? true | ||
: isInline(element); | ||
editor.isInline = (element) => { | ||
if (isElementNode(element, INLINE_ELEMENT)) { | ||
return true; | ||
} | ||
return isInline(element); | ||
}; | ||
@@ -43,0 +45,0 @@ return editor; |
@@ -0,1 +1,3 @@ | ||
import { ElementNode } from '@prezly/slate-types'; | ||
export interface ListsOptions { | ||
@@ -5,3 +7,3 @@ /** | ||
*/ | ||
defaultBlockType: string; | ||
defaultBlockType: ElementNode['type']; | ||
@@ -11,3 +13,3 @@ /** | ||
*/ | ||
listItemTextType: string; | ||
listItemTextType: ElementNode['type']; | ||
@@ -17,3 +19,3 @@ /** | ||
*/ | ||
listItemType: string; | ||
listItemType: ElementNode['type']; | ||
@@ -23,3 +25,3 @@ /** | ||
*/ | ||
listTypes: string[]; | ||
listTypes: ElementNode['type'][]; | ||
@@ -29,3 +31,3 @@ /** | ||
*/ | ||
wrappableTypes: string[]; | ||
wrappableTypes: ElementNode['type'][]; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
335632
0.54%6703
0.22%189
-0.53%+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated