@udecode/plate-indent-list
Advanced tools
Comparing version 31.0.0 to 31.1.0
@@ -57,9 +57,16 @@ import * as _udecode_plate_core from '@udecode/plate-core'; | ||
declare const KEY_LIST_RESTART = "listRestart"; | ||
declare const KEY_LIST_CHECKED = "checked"; | ||
declare const KEY_TODO_STYLE_TYPE = "todo"; | ||
interface IndentListPlugin { | ||
getSiblingIndentListOptions?: GetSiblingIndentListOptions<TElement>; | ||
/** | ||
/**x | ||
* Map html element to list style type. | ||
*/ | ||
getListStyleType?: (element: HTMLElement) => ListStyleType; | ||
markerComponent?: React.FC<IMarkerComponentProps>; | ||
} | ||
interface IMarkerComponentProps { | ||
onChange: (checked: boolean) => void; | ||
checked: boolean; | ||
} | ||
declare const createIndentListPlugin: <OP = IndentListPlugin, OV extends _udecode_slate.Value = _udecode_slate.Value, OE extends _udecode_plate_core.PlateEditor<OV> = _udecode_plate_core.PlateEditor<OV>>(override?: Partial<_udecode_plate_core.PlatePlugin<_udecode_plate_core.NoInfer<OP>, OV, OE>> | undefined, overrideByKey?: _udecode_plate_core.OverrideByKey<OV, OE> | undefined) => _udecode_plate_core.PlatePlugin<_udecode_plate_core.NoInfer<OP>, OV, OE>; | ||
@@ -91,2 +98,16 @@ | ||
declare const useIndentTodoToolBarButtonState: ({ nodeType, }?: { | ||
nodeType?: string | undefined; | ||
}) => { | ||
pressed: boolean; | ||
nodeType: string; | ||
}; | ||
declare const useIndentTodoToolBarButton: ({ nodeType, pressed, }: ReturnType<typeof useIndentTodoToolBarButtonState>) => { | ||
props: { | ||
pressed: boolean; | ||
onMouseDown: (e: React.MouseEvent<HTMLButtonElement>) => void; | ||
onClick: () => void; | ||
}; | ||
}; | ||
/** | ||
@@ -142,2 +163,3 @@ * If there is no previous list item and node list start is defined, unset list start (1). | ||
declare const indentList: <V extends Value>(editor: PlateEditor<V>, { listStyleType, ...options }?: IndentListOptions<V>) => void; | ||
declare const indentTodo: <V extends Value>(editor: PlateEditor<V>, { listStyleType, ...options }?: IndentListOptions<V>) => void; | ||
@@ -154,2 +176,7 @@ /** | ||
}) => void; | ||
declare const setIndentTodoNode: <V extends Value>(editor: TEditor<V>, { listStyleType, indent, at, }: { | ||
listStyleType?: string | undefined; | ||
indent?: number | undefined; | ||
at: Path; | ||
}) => void; | ||
@@ -180,3 +207,3 @@ /** | ||
*/ | ||
declare const toggleIndentListSet: <V extends Value>(editor: TEditor<V>, [node]: TNodeEntry, { listStyleType, ...options }: IndentListOptions<V>) => true | undefined; | ||
declare const toggleIndentListSet: <V extends Value>(editor: TEditor<V>, [node, path]: TNodeEntry, { listStyleType, ...options }: IndentListOptions<V>) => true | undefined; | ||
@@ -190,2 +217,2 @@ /** | ||
export { type GetIndentListSiblingsOptions, type GetSiblingIndentListOptions, type IndentListOptions, type IndentListPlugin, KEY_LIST_RESTART, KEY_LIST_START, KEY_LIST_STYLE_TYPE, ListStyleType, areEqListStyleType, createIndentListPlugin, getIndentListSiblings, getNextIndentList, getPreviousIndentList, getSiblingIndentList, getSiblingListStyleType, indentList, injectIndentListComponent, normalizeFirstIndentListStart, normalizeIndentList, normalizeIndentListNotIndented, normalizeIndentListStart, normalizeNextIndentListStart, onKeyDownIndentList, outdentList, setIndentListNode, setIndentListNodes, setIndentListSiblingNodes, someIndentList, toggleIndentList, toggleIndentListSet, toggleIndentListUnset, useIndentListToolbarButton, useIndentListToolbarButtonState, withIndentList }; | ||
export { type GetIndentListSiblingsOptions, type GetSiblingIndentListOptions, type IMarkerComponentProps, type IndentListOptions, type IndentListPlugin, KEY_LIST_CHECKED, KEY_LIST_RESTART, KEY_LIST_START, KEY_LIST_STYLE_TYPE, KEY_TODO_STYLE_TYPE, ListStyleType, areEqListStyleType, createIndentListPlugin, getIndentListSiblings, getNextIndentList, getPreviousIndentList, getSiblingIndentList, getSiblingListStyleType, indentList, indentTodo, injectIndentListComponent, normalizeFirstIndentListStart, normalizeIndentList, normalizeIndentListNotIndented, normalizeIndentListStart, normalizeNextIndentListStart, onKeyDownIndentList, outdentList, setIndentListNode, setIndentListNodes, setIndentListSiblingNodes, setIndentTodoNode, someIndentList, toggleIndentList, toggleIndentListSet, toggleIndentListUnset, useIndentListToolbarButton, useIndentListToolbarButtonState, useIndentTodoToolBarButton, useIndentTodoToolBarButtonState, withIndentList }; |
@@ -62,5 +62,7 @@ "use strict"; | ||
__export(src_exports, { | ||
KEY_LIST_CHECKED: () => KEY_LIST_CHECKED, | ||
KEY_LIST_RESTART: () => KEY_LIST_RESTART, | ||
KEY_LIST_START: () => KEY_LIST_START, | ||
KEY_LIST_STYLE_TYPE: () => KEY_LIST_STYLE_TYPE, | ||
KEY_TODO_STYLE_TYPE: () => KEY_TODO_STYLE_TYPE, | ||
ListStyleType: () => ListStyleType, | ||
@@ -75,2 +77,3 @@ areEqListStyleType: () => areEqListStyleType, | ||
indentList: () => indentList, | ||
indentTodo: () => indentTodo, | ||
injectIndentListComponent: () => injectIndentListComponent, | ||
@@ -87,2 +90,3 @@ normalizeFirstIndentListStart: () => normalizeFirstIndentListStart, | ||
setIndentListSiblingNodes: () => setIndentListSiblingNodes, | ||
setIndentTodoNode: () => setIndentTodoNode, | ||
someIndentList: () => someIndentList, | ||
@@ -94,2 +98,4 @@ toggleIndentList: () => toggleIndentList, | ||
useIndentListToolbarButtonState: () => useIndentListToolbarButtonState, | ||
useIndentTodoToolBarButton: () => useIndentTodoToolBarButton, | ||
useIndentTodoToolBarButtonState: () => useIndentTodoToolBarButtonState, | ||
withIndentList: () => withIndentList | ||
@@ -100,6 +106,7 @@ }); | ||
// src/createIndentListPlugin.ts | ||
var import_plate_common15 = require("@udecode/plate-common"); | ||
var import_plate_common17 = require("@udecode/plate-common"); | ||
// src/injectIndentListComponent.tsx | ||
var import_react = __toESM(require("react")); | ||
var import_plate_common = require("@udecode/plate-common"); | ||
var import_clsx = require("clsx"); | ||
@@ -140,3 +147,4 @@ | ||
const listStart = element[KEY_LIST_START]; | ||
if (listStyleType) { | ||
const isTodo = element.hasOwnProperty(KEY_LIST_CHECKED) && listStyleType === KEY_TODO_STYLE_TYPE; | ||
if (listStyleType && !isTodo) { | ||
let className = (0, import_clsx.clsx)(`slate-${KEY_LIST_STYLE_TYPE}-${listStyleType}`); | ||
@@ -161,6 +169,45 @@ const style = { | ||
} | ||
if (isTodo) { | ||
const className = (0, import_clsx.clsx)("slate-list-todo"); | ||
const checked = element[KEY_LIST_CHECKED]; | ||
const style = { | ||
position: "relative", | ||
padding: 0, | ||
margin: 0 | ||
}; | ||
return function Ol({ children, editor }) { | ||
const { markerComponent } = (0, import_plate_common.getPluginOptions)( | ||
editor, | ||
KEY_LIST_STYLE_TYPE | ||
); | ||
return /* @__PURE__ */ import_react.default.createElement("div", { className: `${className}`, style }, markerComponent ? markerComponent({ | ||
checked, | ||
onChange: (v) => { | ||
const path = (0, import_plate_common.findNodePath)(editor, element); | ||
(0, import_plate_common.setNodes)(editor, { checked: v }, { at: path }); | ||
} | ||
}) : /* @__PURE__ */ import_react.default.createElement( | ||
"input", | ||
{ | ||
contentEditable: false, | ||
"data-slate-void": true, | ||
type: "checkbox", | ||
style: { | ||
marginRight: 5, | ||
marginLeft: -17, | ||
paddingTop: -10 | ||
}, | ||
checked, | ||
onChange: (v) => { | ||
const path = (0, import_plate_common.findNodePath)(editor, element); | ||
(0, import_plate_common.setNodes)(editor, { checked: v.target.checked }, { at: path }); | ||
} | ||
} | ||
), /* @__PURE__ */ import_react.default.createElement("span", null, children)); | ||
}; | ||
} | ||
}; | ||
// src/onKeyDownIndentList.ts | ||
var import_plate_common9 = require("@udecode/plate-common"); | ||
var import_plate_common10 = require("@udecode/plate-common"); | ||
@@ -178,2 +225,12 @@ // src/transforms/indentList.ts | ||
}; | ||
var indentTodo = (editor, _a = {}) => { | ||
var _b = _a, { listStyleType = "disc" /* Disc */ } = _b, options = __objRest(_b, ["listStyleType"]); | ||
(0, import_plate_indent.setIndent)(editor, __spreadValues({ | ||
offset: 1, | ||
setNodesProps: () => ({ | ||
[KEY_LIST_CHECKED]: false, | ||
[KEY_LIST_STYLE_TYPE]: listStyleType | ||
}) | ||
}, options)); | ||
}; | ||
@@ -185,3 +242,3 @@ // src/transforms/outdentList.ts | ||
offset: -1, | ||
unsetNodesProps: [KEY_LIST_STYLE_TYPE] | ||
unsetNodesProps: [KEY_LIST_STYLE_TYPE, KEY_LIST_CHECKED] | ||
}, options)); | ||
@@ -191,3 +248,3 @@ }; | ||
// src/transforms/setIndentListNode.ts | ||
var import_plate_common = require("@udecode/plate-common"); | ||
var import_plate_common2 = require("@udecode/plate-common"); | ||
var import_plate_indent3 = require("@udecode/plate-indent"); | ||
@@ -200,3 +257,3 @@ var setIndentListNode = (editor, { | ||
const newIndent = indent || indent + 1; | ||
(0, import_plate_common.setElements)( | ||
(0, import_plate_common2.setElements)( | ||
editor, | ||
@@ -207,5 +264,21 @@ { [KEY_LIST_STYLE_TYPE]: listStyleType, [import_plate_indent3.KEY_INDENT]: newIndent }, | ||
}; | ||
var setIndentTodoNode = (editor, { | ||
listStyleType = KEY_TODO_STYLE_TYPE, | ||
indent = 0, | ||
at | ||
}) => { | ||
const newIndent = indent || indent + 1; | ||
(0, import_plate_common2.setElements)( | ||
editor, | ||
{ | ||
[KEY_LIST_STYLE_TYPE]: listStyleType, | ||
[KEY_LIST_CHECKED]: false, | ||
[import_plate_indent3.KEY_INDENT]: newIndent | ||
}, | ||
{ at } | ||
); | ||
}; | ||
// src/transforms/setIndentListNodes.ts | ||
var import_plate_common2 = require("@udecode/plate-common"); | ||
var import_plate_common3 = require("@udecode/plate-common"); | ||
var import_plate_indent4 = require("@udecode/plate-indent"); | ||
@@ -215,3 +288,3 @@ var setIndentListNodes = (editor, entries, { | ||
}) => { | ||
(0, import_plate_common2.withoutNormalizing)(editor, () => { | ||
(0, import_plate_common3.withoutNormalizing)(editor, () => { | ||
entries.forEach((entry) => { | ||
@@ -221,3 +294,13 @@ var _a; | ||
let indent = (_a = node[import_plate_indent4.KEY_INDENT]) != null ? _a : 0; | ||
indent = node[KEY_LIST_STYLE_TYPE] ? indent : indent + 1; | ||
indent = node[KEY_LIST_STYLE_TYPE] || node.hasOwnProperty(KEY_LIST_CHECKED) ? indent : indent + 1; | ||
if (listStyleType === "todo") { | ||
(0, import_plate_common3.unsetNodes)(editor, KEY_LIST_STYLE_TYPE, { at: path }); | ||
setIndentTodoNode(editor, { | ||
listStyleType, | ||
indent, | ||
at: path | ||
}); | ||
return; | ||
} | ||
(0, import_plate_common3.unsetNodes)(editor, KEY_LIST_CHECKED, { at: path }); | ||
setIndentListNode(editor, { | ||
@@ -233,11 +316,11 @@ listStyleType, | ||
// src/transforms/setIndentListSiblingNodes.ts | ||
var import_plate_common6 = require("@udecode/plate-common"); | ||
var import_plate_common7 = require("@udecode/plate-common"); | ||
var import_plate_indent6 = require("@udecode/plate-indent"); | ||
// src/queries/getNextIndentList.ts | ||
var import_plate_common4 = require("@udecode/plate-common"); | ||
var import_plate_common5 = require("@udecode/plate-common"); | ||
var import_slate = require("slate"); | ||
// src/queries/getSiblingIndentList.ts | ||
var import_plate_common3 = require("@udecode/plate-common"); | ||
var import_plate_common4 = require("@udecode/plate-common"); | ||
var import_plate_indent5 = require("@udecode/plate-indent"); | ||
@@ -263,3 +346,3 @@ var getSiblingIndentList = (editor, [node, path], { | ||
const nextIndent = nextNode[import_plate_indent5.KEY_INDENT]; | ||
if (!(0, import_plate_common3.isDefined)(nextIndent)) | ||
if (!(0, import_plate_common4.isDefined)(nextIndent)) | ||
return; | ||
@@ -287,3 +370,3 @@ if (breakQuery && breakQuery(nextNode)) | ||
const nextPath = import_slate.Path.next(currPath); | ||
const nextNode = (0, import_plate_common4.getNode)(editor, nextPath); | ||
const nextNode = (0, import_plate_common5.getNode)(editor, nextPath); | ||
if (!nextNode) | ||
@@ -299,10 +382,10 @@ return; | ||
// src/queries/getPreviousIndentList.ts | ||
var import_plate_common5 = require("@udecode/plate-common"); | ||
var import_plate_common6 = require("@udecode/plate-common"); | ||
var getPreviousIndentList = (editor, entry, options) => { | ||
return getSiblingIndentList(editor, entry, __spreadProps(__spreadValues({ | ||
getPreviousEntry: ([, currPath]) => { | ||
const prevPath = (0, import_plate_common5.getPreviousPath)(currPath); | ||
const prevPath = (0, import_plate_common6.getPreviousPath)(currPath); | ||
if (!prevPath) | ||
return; | ||
const prevNode = (0, import_plate_common5.getNode)(editor, prevPath); | ||
const prevNode = (0, import_plate_common6.getNode)(editor, prevPath); | ||
if (!prevNode) | ||
@@ -330,3 +413,4 @@ return; | ||
const [node] = entry; | ||
if (!node[KEY_LIST_STYLE_TYPE]) | ||
if (!node[KEY_LIST_STYLE_TYPE] && // @ts-ignore | ||
!node.hasOwnProperty(KEY_LIST_CHECKED)) | ||
return siblings; | ||
@@ -364,3 +448,3 @@ let iterEntry = entry; | ||
}) => { | ||
(0, import_plate_common6.withoutNormalizing)(editor, () => { | ||
(0, import_plate_common7.withoutNormalizing)(editor, () => { | ||
const siblings = getIndentListSiblings( | ||
@@ -372,7 +456,17 @@ editor, | ||
siblings.forEach(([node, path]) => { | ||
setIndentListNode(editor, { | ||
listStyleType, | ||
indent: node[import_plate_indent6.KEY_INDENT], | ||
at: path | ||
}); | ||
if (listStyleType === KEY_TODO_STYLE_TYPE) { | ||
(0, import_plate_common7.unsetNodes)(editor, KEY_LIST_STYLE_TYPE, { at: path }); | ||
setIndentTodoNode(editor, { | ||
listStyleType, | ||
indent: node[import_plate_indent6.KEY_INDENT], | ||
at: path | ||
}); | ||
} else { | ||
(0, import_plate_common7.unsetNodes)(editor, KEY_LIST_CHECKED, { at: path }); | ||
setIndentListNode(editor, { | ||
listStyleType, | ||
indent: node[import_plate_indent6.KEY_INDENT], | ||
at: path | ||
}); | ||
} | ||
}); | ||
@@ -383,3 +477,3 @@ }); | ||
// src/transforms/toggleIndentList.ts | ||
var import_plate_common8 = require("@udecode/plate-common"); | ||
var import_plate_common9 = require("@udecode/plate-common"); | ||
var import_plate_indent7 = require("@udecode/plate-indent"); | ||
@@ -394,2 +488,9 @@ | ||
const [block] = entry; | ||
if (listStyleType === KEY_TODO_STYLE_TYPE) { | ||
if (!block.hasOwnProperty(KEY_LIST_CHECKED)) { | ||
eqListStyleType = false; | ||
break; | ||
} | ||
continue; | ||
} | ||
if (!block[KEY_LIST_STYLE_TYPE] || block[KEY_LIST_STYLE_TYPE] !== listStyleType) { | ||
@@ -404,19 +505,32 @@ eqListStyleType = false; | ||
// src/transforms/toggleIndentListSet.ts | ||
var toggleIndentListSet = (editor, [node], _a) => { | ||
var toggleIndentListSet = (editor, [node, path], _a) => { | ||
var _b = _a, { listStyleType = "disc" /* Disc */ } = _b, options = __objRest(_b, ["listStyleType"]); | ||
if (!node[KEY_LIST_STYLE_TYPE]) { | ||
if (node.hasOwnProperty(KEY_LIST_CHECKED) || node[KEY_LIST_STYLE_TYPE]) | ||
return; | ||
if (listStyleType === "todo") { | ||
indentTodo(editor, __spreadValues({ | ||
listStyleType | ||
}, options)); | ||
} else { | ||
indentList(editor, __spreadValues({ | ||
listStyleType | ||
}, options)); | ||
return true; | ||
} | ||
return true; | ||
}; | ||
// src/transforms/toggleIndentListUnset.ts | ||
var import_plate_common7 = require("@udecode/plate-common"); | ||
var import_plate_common8 = require("@udecode/plate-common"); | ||
var toggleIndentListUnset = (editor, [node, path], { | ||
listStyleType = "disc" /* Disc */ | ||
}) => { | ||
if (listStyleType === KEY_TODO_STYLE_TYPE && node.hasOwnProperty(KEY_LIST_CHECKED)) { | ||
(0, import_plate_common8.unsetNodes)(editor, KEY_LIST_CHECKED, { at: path }); | ||
outdentList(editor, { listStyleType }); | ||
return true; | ||
} | ||
if (listStyleType === node[KEY_LIST_STYLE_TYPE]) { | ||
(0, import_plate_common7.unsetNodes)(editor, KEY_LIST_STYLE_TYPE, { at: path }); | ||
(0, import_plate_common8.unsetNodes)(editor, [KEY_LIST_STYLE_TYPE], { | ||
at: path | ||
}); | ||
outdentList(editor, { listStyleType }); | ||
@@ -430,8 +544,8 @@ return true; | ||
const { listStyleType } = options; | ||
const { getSiblingIndentListOptions } = (0, import_plate_common8.getPluginOptions)( | ||
const { getSiblingIndentListOptions } = (0, import_plate_common9.getPluginOptions)( | ||
editor, | ||
KEY_LIST_STYLE_TYPE | ||
); | ||
if ((0, import_plate_common8.isCollapsed)(editor.selection)) { | ||
const entry = (0, import_plate_common8.getBlockAbove)(editor); | ||
if ((0, import_plate_common9.isCollapsed)(editor.selection)) { | ||
const entry = (0, import_plate_common9.getBlockAbove)(editor); | ||
if (!entry) | ||
@@ -451,4 +565,4 @@ return; | ||
} | ||
if ((0, import_plate_common8.isExpanded)(editor.selection)) { | ||
const _entries = (0, import_plate_common8.getNodeEntries)(editor, { block: true }); | ||
if ((0, import_plate_common9.isExpanded)(editor.selection)) { | ||
const _entries = (0, import_plate_common9.getNodeEntries)(editor, { block: true }); | ||
const entries = [..._entries]; | ||
@@ -459,11 +573,11 @@ const eqListStyleType = areEqListStyleType(editor, entries, { | ||
if (eqListStyleType) { | ||
(0, import_plate_common8.withoutNormalizing)(editor, () => { | ||
(0, import_plate_common9.withoutNormalizing)(editor, () => { | ||
entries.forEach((entry) => { | ||
const [node, path] = entry; | ||
const indent = node[import_plate_indent7.KEY_INDENT]; | ||
(0, import_plate_common8.unsetNodes)(editor, KEY_LIST_STYLE_TYPE, { at: path }); | ||
(0, import_plate_common9.unsetNodes)(editor, KEY_LIST_STYLE_TYPE, { at: path }); | ||
if (indent > 1) { | ||
(0, import_plate_common8.setElements)(editor, { [import_plate_indent7.KEY_INDENT]: indent - 1 }, { at: path }); | ||
(0, import_plate_common9.setElements)(editor, { [import_plate_indent7.KEY_INDENT]: indent - 1 }, { at: path }); | ||
} else { | ||
(0, import_plate_common8.unsetNodes)(editor, import_plate_indent7.KEY_INDENT, { at: path }); | ||
(0, import_plate_common9.unsetNodes)(editor, [import_plate_indent7.KEY_INDENT, KEY_LIST_CHECKED], { at: path }); | ||
} | ||
@@ -484,3 +598,3 @@ }); | ||
return; | ||
const entry = (0, import_plate_common9.getBlockAbove)(editor); | ||
const entry = (0, import_plate_common10.getBlockAbove)(editor); | ||
if (!entry) | ||
@@ -492,3 +606,3 @@ return; | ||
return; | ||
if ((0, import_plate_common9.isHotkey)("Enter", e) && (0, import_plate_common9.isBlockAboveEmpty)(editor) && node.indent) { | ||
if ((0, import_plate_common10.isHotkey)("Enter", e) && (0, import_plate_common10.isBlockAboveEmpty)(editor) && node.indent) { | ||
outdentList(editor); | ||
@@ -501,14 +615,38 @@ e.stopPropagation(); | ||
// src/withIndentList.ts | ||
var import_plate_common14 = require("@udecode/plate-common"); | ||
var import_plate_common16 = require("@udecode/plate-common"); | ||
var import_plate_indent9 = require("@udecode/plate-indent"); | ||
// src/delete-backward/deleteBackwardIndentList.ts | ||
var import_plate_common11 = require("@udecode/plate-common"); | ||
var deleteBackwardIndentList = (editor) => { | ||
const { deleteBackward } = editor; | ||
return function(unit) { | ||
deleteBackwardHelper(editor); | ||
deleteBackward(unit); | ||
}; | ||
}; | ||
function deleteBackwardHelper(editor) { | ||
if ((0, import_plate_common11.isCollapsed)(editor.selection)) { | ||
const str = (0, import_plate_common11.getNodeString)(editor); | ||
if (str) | ||
return; | ||
const entry = (0, import_plate_common11.getAboveNode)(editor); | ||
if (!entry) | ||
return; | ||
const node = entry[0]; | ||
if ((0, import_plate_common11.isDefined)(node[KEY_LIST_STYLE_TYPE])) { | ||
outdentList(editor); | ||
} | ||
} | ||
} | ||
// src/normalizeIndentList.ts | ||
var import_plate_common13 = require("@udecode/plate-common"); | ||
var import_plate_common15 = require("@udecode/plate-common"); | ||
// src/normalizers/normalizeIndentListNotIndented.ts | ||
var import_plate_common10 = require("@udecode/plate-common"); | ||
var import_plate_common12 = require("@udecode/plate-common"); | ||
var import_plate_indent8 = require("@udecode/plate-indent"); | ||
var normalizeIndentListNotIndented = (editor, [node, path]) => { | ||
if (!(0, import_plate_common10.isDefined)(node[import_plate_indent8.KEY_INDENT]) && (node[KEY_LIST_STYLE_TYPE] || node[KEY_LIST_START])) { | ||
(0, import_plate_common10.unsetNodes)(editor, [KEY_LIST_STYLE_TYPE, KEY_LIST_START], { at: path }); | ||
if (!(0, import_plate_common12.isDefined)(node[import_plate_indent8.KEY_INDENT]) && (node[KEY_LIST_STYLE_TYPE] || node[KEY_LIST_START])) { | ||
(0, import_plate_common12.unsetNodes)(editor, [KEY_LIST_STYLE_TYPE, KEY_LIST_START], { at: path }); | ||
return true; | ||
@@ -519,9 +657,9 @@ } | ||
// src/normalizers/normalizeIndentListStart.ts | ||
var import_plate_common12 = require("@udecode/plate-common"); | ||
var import_plate_common14 = require("@udecode/plate-common"); | ||
// src/normalizers/normalizeFirstIndentListStart.ts | ||
var import_plate_common11 = require("@udecode/plate-common"); | ||
var import_plate_common13 = require("@udecode/plate-common"); | ||
var normalizeFirstIndentListStart = (editor, [node, path]) => { | ||
if ((0, import_plate_common11.isDefined)(node[KEY_LIST_START])) { | ||
(0, import_plate_common11.unsetNodes)(editor, KEY_LIST_START, { at: path }); | ||
if ((0, import_plate_common13.isDefined)(node[KEY_LIST_START])) { | ||
(0, import_plate_common13.unsetNodes)(editor, KEY_LIST_START, { at: path }); | ||
return true; | ||
@@ -541,3 +679,3 @@ } | ||
if (currListStart !== listStart) { | ||
(0, import_plate_common12.setElements)(editor, { [KEY_LIST_START]: listStart }, { at: path }); | ||
(0, import_plate_common14.setElements)(editor, { [KEY_LIST_START]: listStart }, { at: path }); | ||
return true; | ||
@@ -548,3 +686,3 @@ } | ||
var normalizeIndentListStart = (editor, entry, options) => { | ||
return (0, import_plate_common12.withoutNormalizing)(editor, () => { | ||
return (0, import_plate_common14.withoutNormalizing)(editor, () => { | ||
const [node] = entry; | ||
@@ -567,3 +705,3 @@ const listStyleType = node[KEY_LIST_STYLE_TYPE]; | ||
normalized = true; | ||
prevEntry = [(0, import_plate_common12.getNode)(editor, currEntry[1]), currEntry[1]]; | ||
prevEntry = [(0, import_plate_common14.getNode)(editor, currEntry[1]), currEntry[1]]; | ||
currEntry = getNextIndentList(editor, currEntry, options); | ||
@@ -581,3 +719,3 @@ if (!currEntry) | ||
return ([node, path]) => { | ||
const normalized = (0, import_plate_common13.withoutNormalizing)(editor, () => { | ||
const normalized = (0, import_plate_common15.withoutNormalizing)(editor, () => { | ||
if (normalizeIndentListNotIndented(editor, [node, path])) | ||
@@ -603,2 +741,3 @@ return true; | ||
editor.normalizeNode = normalizeIndentList(editor, options); | ||
editor.deleteBackward = deleteBackwardIndentList(editor); | ||
editor.apply = (operation) => { | ||
@@ -608,3 +747,3 @@ const { path } = operation; | ||
if (operation.type === "set_node") { | ||
nodeBefore = (0, import_plate_common14.getNode)(editor, path); | ||
nodeBefore = (0, import_plate_common16.getNode)(editor, path); | ||
} | ||
@@ -634,3 +773,3 @@ if (operation.type === "insert_node") { | ||
if (operation.type === "merge_node" && operation.properties[KEY_LIST_STYLE_TYPE]) { | ||
const node = (0, import_plate_common14.getNode)(editor, path); | ||
const node = (0, import_plate_common16.getNode)(editor, path); | ||
if (node) { | ||
@@ -643,3 +782,3 @@ const nextNodeEntryBefore = getNextIndentList( | ||
if (nextNodeEntryBefore) { | ||
nextIndentListPathRef = (0, import_plate_common14.createPathRef)(editor, nextNodeEntryBefore[1]); | ||
nextIndentListPathRef = (0, import_plate_common16.createPathRef)(editor, nextNodeEntryBefore[1]); | ||
} | ||
@@ -652,3 +791,3 @@ } | ||
if (properties[KEY_LIST_STYLE_TYPE]) { | ||
const node = (0, import_plate_common14.getNode)(editor, path); | ||
const node = (0, import_plate_common16.getNode)(editor, path); | ||
if (!node) | ||
@@ -664,3 +803,3 @@ return; | ||
if (nextPath) { | ||
const nextNode = (0, import_plate_common14.getNode)(editor, nextPath); | ||
const nextNode = (0, import_plate_common16.getNode)(editor, nextPath); | ||
if (nextNode) { | ||
@@ -681,3 +820,3 @@ normalizeIndentListStart( | ||
if (prevListStyleType && !listStyleType) { | ||
const node = (0, import_plate_common14.getNode)(editor, path); | ||
const node = (0, import_plate_common16.getNode)(editor, path); | ||
if (!node) | ||
@@ -699,3 +838,3 @@ return; | ||
if ((prevListStyleType || listStyleType) && prevListStyleType !== listStyleType) { | ||
const node = (0, import_plate_common14.getNode)(editor, path); | ||
const node = (0, import_plate_common16.getNode)(editor, path); | ||
if (!node) | ||
@@ -731,3 +870,3 @@ return; | ||
if (prevIndent !== indent) { | ||
const node = (0, import_plate_common14.getNode)(editor, path); | ||
const node = (0, import_plate_common16.getNode)(editor, path); | ||
if (!node) | ||
@@ -801,3 +940,5 @@ return; | ||
var KEY_LIST_RESTART = "listRestart"; | ||
var createIndentListPlugin = (0, import_plate_common15.createPluginFactory)({ | ||
var KEY_LIST_CHECKED = "checked"; | ||
var KEY_TODO_STYLE_TYPE = "todo"; | ||
var createIndentListPlugin = (0, import_plate_common17.createPluginFactory)({ | ||
key: KEY_LIST_STYLE_TYPE, | ||
@@ -817,3 +958,3 @@ inject: { | ||
pluginsByKey: { | ||
[import_plate_common15.KEY_DESERIALIZE_HTML]: { | ||
[import_plate_common17.KEY_DESERIALIZE_HTML]: { | ||
editor: { | ||
@@ -827,3 +968,3 @@ insertData: { | ||
const { body } = document; | ||
(0, import_plate_common15.traverseHtmlElements)(body, (element) => { | ||
(0, import_plate_common17.traverseHtmlElements)(body, (element) => { | ||
if (element.tagName === "LI") { | ||
@@ -833,3 +974,3 @@ const { childNodes } = element; | ||
childNodes.forEach((child) => { | ||
if ((0, import_plate_common15.isHtmlBlockElement)(child)) { | ||
if ((0, import_plate_common17.isHtmlBlockElement)(child)) { | ||
liChildren.push(...child.childNodes); | ||
@@ -845,3 +986,3 @@ } else { | ||
}); | ||
return (0, import_plate_common15.postCleanHtml)(body.innerHTML); | ||
return (0, import_plate_common17.postCleanHtml)(body.innerHTML); | ||
} | ||
@@ -858,3 +999,3 @@ } | ||
return { | ||
type: (0, import_plate_common15.getPluginType)(editor, import_plate_common15.ELEMENT_DEFAULT), | ||
type: (0, import_plate_common17.getPluginType)(editor, import_plate_common17.ELEMENT_DEFAULT), | ||
listStyleType: (_a = options.getListStyleType) == null ? void 0 : _a.call(options, element), | ||
@@ -875,5 +1016,5 @@ // gdoc uses aria-level attribute | ||
// src/hooks/someIndentList.ts | ||
var import_plate_common16 = require("@udecode/plate-common"); | ||
var import_plate_common18 = require("@udecode/plate-common"); | ||
var someIndentList = (editor, type) => { | ||
return !!editor.selection && (0, import_plate_common16.someNode)(editor, { | ||
return !!editor.selection && (0, import_plate_common18.someNode)(editor, { | ||
match: (n) => { | ||
@@ -883,3 +1024,4 @@ const list = n[KEY_LIST_STYLE_TYPE]; | ||
return list === "disc" /* Disc */; | ||
return !!list && list !== "disc" /* Disc */; | ||
const isHasProperty = n.hasOwnProperty(KEY_LIST_CHECKED); | ||
return !!list && list !== "disc" /* Disc */ && !isHasProperty; | ||
} | ||
@@ -890,7 +1032,7 @@ }); | ||
// src/hooks/useIndentListToolbarButton.ts | ||
var import_plate_common17 = require("@udecode/plate-common"); | ||
var import_plate_common19 = require("@udecode/plate-common"); | ||
var useIndentListToolbarButtonState = ({ | ||
nodeType = "disc" /* Disc */ | ||
} = {}) => { | ||
const pressed = (0, import_plate_common17.useEditorSelector)( | ||
const pressed = (0, import_plate_common19.useEditorSelector)( | ||
(editor) => someIndentList(editor, nodeType), | ||
@@ -908,3 +1050,3 @@ [nodeType] | ||
}) => { | ||
const editor = (0, import_plate_common17.useEditorRef)(); | ||
const editor = (0, import_plate_common19.useEditorRef)(); | ||
return { | ||
@@ -925,2 +1067,51 @@ props: { | ||
// src/hooks/useIndentTodoToolbarButton.ts | ||
var import_plate_common21 = require("@udecode/plate-common"); | ||
// src/hooks/someIndentTodo.ts | ||
var import_plate_common20 = require("@udecode/plate-common"); | ||
var someIndentTodo = (editor, type) => { | ||
return (0, import_plate_common20.someNode)(editor, { | ||
at: editor.selection, | ||
match: (n) => { | ||
const list = n[KEY_LIST_STYLE_TYPE]; | ||
const isHasProperty = n.hasOwnProperty(KEY_LIST_CHECKED); | ||
return n.type === "p" && isHasProperty && list === KEY_TODO_STYLE_TYPE; | ||
} | ||
}); | ||
}; | ||
// src/hooks/useIndentTodoToolbarButton.ts | ||
var useIndentTodoToolBarButtonState = ({ | ||
nodeType = "disc" /* Disc */ | ||
} = {}) => { | ||
const pressed = (0, import_plate_common21.useEditorSelector)( | ||
(editor) => someIndentTodo(editor, nodeType), | ||
[nodeType] | ||
); | ||
return { | ||
pressed, | ||
nodeType | ||
}; | ||
}; | ||
var useIndentTodoToolBarButton = ({ | ||
nodeType, | ||
pressed | ||
}) => { | ||
const editor = (0, import_plate_common21.useEditorRef)(); | ||
return { | ||
props: { | ||
pressed, | ||
onMouseDown: (e) => { | ||
e.preventDefault(); | ||
}, | ||
onClick: () => { | ||
toggleIndentList(editor, { | ||
listStyleType: nodeType | ||
}); | ||
} | ||
} | ||
}; | ||
}; | ||
// src/queries/getSiblingListStyleType.ts | ||
@@ -948,5 +1139,7 @@ var getSiblingListStyleType = (editor, _a) => { | ||
0 && (module.exports = { | ||
KEY_LIST_CHECKED, | ||
KEY_LIST_RESTART, | ||
KEY_LIST_START, | ||
KEY_LIST_STYLE_TYPE, | ||
KEY_TODO_STYLE_TYPE, | ||
ListStyleType, | ||
@@ -961,2 +1154,3 @@ areEqListStyleType, | ||
indentList, | ||
indentTodo, | ||
injectIndentListComponent, | ||
@@ -973,2 +1167,3 @@ normalizeFirstIndentListStart, | ||
setIndentListSiblingNodes, | ||
setIndentTodoNode, | ||
someIndentList, | ||
@@ -980,4 +1175,6 @@ toggleIndentList, | ||
useIndentListToolbarButtonState, | ||
useIndentTodoToolBarButton, | ||
useIndentTodoToolBarButtonState, | ||
withIndentList | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@udecode/plate-indent-list", | ||
"version": "31.0.0", | ||
"version": "31.1.0", | ||
"description": "Indent list plugin for Plate", | ||
@@ -42,3 +42,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@udecode/plate-indent": "31.0.0", | ||
"@udecode/plate-indent": "31.1.0", | ||
"@udecode/plate-list": "31.0.0", | ||
@@ -45,0 +45,0 @@ "clsx": "^1.2.1" |
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
225203
2342
+ Added@udecode/plate-indent@31.1.0(transitive)
- Removed@udecode/plate-indent@31.0.0(transitive)
Updated@udecode/plate-indent@31.1.0