@lexical/list 0.44.1-nightly.20260519.0 → 0.45.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LexicalList.dev.js → dist/LexicalList.dev.js} +286 -31
- package/{LexicalList.dev.mjs → dist/LexicalList.dev.mjs} +285 -33
- package/{LexicalList.mjs → dist/LexicalList.mjs} +3 -0
- package/{LexicalList.node.mjs → dist/LexicalList.node.mjs} +3 -0
- package/dist/LexicalList.prod.js +9 -0
- package/dist/LexicalList.prod.mjs +9 -0
- package/dist/LexicalListExtension.d.ts +29 -0
- package/dist/ListImportExtension.d.ts +34 -0
- package/{index.d.ts → dist/index.d.ts} +4 -37
- package/dist/registerList.d.ts +20 -0
- package/package.json +33 -17
- package/src/LexicalListExtension.ts +76 -0
- package/src/LexicalListItemNode.ts +724 -0
- package/src/LexicalListNode.ts +393 -0
- package/src/ListImportExtension.ts +319 -0
- package/src/checkList.ts +469 -0
- package/src/formatList.ts +582 -0
- package/src/index.ts +98 -0
- package/src/registerList.ts +231 -0
- package/src/utils.ts +196 -0
- package/LexicalList.prod.js +0 -9
- package/LexicalList.prod.mjs +0 -9
- /package/{LexicalList.js → dist/LexicalList.js} +0 -0
- /package/{LexicalList.js.flow → dist/LexicalList.js.flow} +0 -0
- /package/{LexicalListItemNode.d.ts → dist/LexicalListItemNode.d.ts} +0 -0
- /package/{LexicalListNode.d.ts → dist/LexicalListNode.d.ts} +0 -0
- /package/{checkList.d.ts → dist/checkList.d.ts} +0 -0
- /package/{formatList.d.ts → dist/formatList.d.ts} +0 -0
- /package/{utils.d.ts → dist/utils.d.ts} +0 -0
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { effect, namedSignals } from '@lexical/extension';
|
|
10
9
|
import { $getNearestNodeOfType, $insertNodeToNearestRootAtCaret, removeClassNamesFromElement, addClassNamesToElement, isHTMLElement as isHTMLElement$1, mergeRegister, $findMatchingParent, calculateZoomLevel } from '@lexical/utils';
|
|
11
|
-
import { $
|
|
10
|
+
import { $getSelection, $isRangeSelection, $isTextNode, $isRootOrShadowRoot, $createParagraphNode, $copyNode, $isElementNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, $applyNodeReplacement, ElementNode, buildImportMap, $getSiblingCaret, $rewindSiblingCaret, setDOMStyleFromCSS, isHTMLElement, $isParagraphNode, $setFormatFromDOM, $setDirectionFromDOM, normalizeClassNames, getStyleObjectFromCSS, $createTextNode, createCommand, COMMAND_PRIORITY_LOW, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_SPACE_COMMAND, $getNearestNodeFromDOMNode, KEY_ARROW_LEFT_COMMAND, getNearestEditorFromDOMNode, $addUpdateTag, SKIP_SELECTION_FOCUS_TAG, SKIP_DOM_SELECTION_TAG, $getNodeByKey, INSERT_PARAGRAPH_COMMAND, TextNode, defineExtension, safeCast, configExtension, $createLineBreakNode } from 'lexical';
|
|
11
|
+
import { namedSignals, effect } from '@lexical/extension';
|
|
12
|
+
import { DOMImportExtension, defineImportRule, sel, isElementOfTag, $propagateTextAlignToBlockChildren, $isBlockLevel } from '@lexical/html';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -1293,7 +1294,7 @@ function $normalizeChildren(nodes, listNode) {
|
|
|
1293
1294
|
}
|
|
1294
1295
|
return normalizedListItems;
|
|
1295
1296
|
}
|
|
1296
|
-
function isDomChecklist(domNode) {
|
|
1297
|
+
function isDomChecklist$1(domNode) {
|
|
1297
1298
|
if (domNode.getAttribute('__lexicallisttype') === 'check' ||
|
|
1298
1299
|
// is github checklist
|
|
1299
1300
|
domNode.classList.contains('contains-task-list') ||
|
|
@@ -1317,7 +1318,7 @@ function $convertListNode(domNode) {
|
|
|
1317
1318
|
if (isHTMLOListElement(domNode)) {
|
|
1318
1319
|
const start = domNode.start;
|
|
1319
1320
|
node = $createListNode('number', start);
|
|
1320
|
-
} else if (isDomChecklist(domNode)) {
|
|
1321
|
+
} else if (isDomChecklist$1(domNode)) {
|
|
1321
1322
|
node = $createListNode('check');
|
|
1322
1323
|
} else {
|
|
1323
1324
|
node = $createListNode('bullet');
|
|
@@ -1785,33 +1786,13 @@ function $findChildrenEndListItemNode(listItemNode) {
|
|
|
1785
1786
|
}
|
|
1786
1787
|
|
|
1787
1788
|
/**
|
|
1788
|
-
*
|
|
1789
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1789
1790
|
*
|
|
1790
|
-
*
|
|
1791
|
-
*
|
|
1792
|
-
* Otherwise it will replace its parent with a new ListNode and re-insert the ListItemNode and any previous children.
|
|
1793
|
-
* If the selection's anchor node is not an empty ListItemNode, it will add a new ListNode or merge an existing ListNode,
|
|
1794
|
-
* unless the the node is a leaf node, in which case it will attempt to find a ListNode up the branch and replace it with
|
|
1795
|
-
* a new ListNode, or create a new ListNode at the nearest root/shadow root.
|
|
1796
|
-
* @param editor - The lexical editor.
|
|
1797
|
-
* @param listType - The type of list, "number" | "bullet" | "check".
|
|
1798
|
-
*/
|
|
1799
|
-
function insertList(editor, listType) {
|
|
1800
|
-
editor.update(() => $insertList(listType));
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
/**
|
|
1804
|
-
* @deprecated use {@link $removeList} from an update or command listener.
|
|
1791
|
+
* This source code is licensed under the MIT license found in the
|
|
1792
|
+
* LICENSE file in the root directory of this source tree.
|
|
1805
1793
|
*
|
|
1806
|
-
* Searches for the nearest ancestral ListNode and removes it. If selection is an empty ListItemNode
|
|
1807
|
-
* it will remove the whole list, including the ListItemNode. For each ListItemNode in the ListNode,
|
|
1808
|
-
* removeList will also generate new ParagraphNodes in the removed ListNode's place. Any child node
|
|
1809
|
-
* inside a ListItemNode will be appended to the new ParagraphNodes.
|
|
1810
|
-
* @param editor - The lexical editor.
|
|
1811
1794
|
*/
|
|
1812
|
-
|
|
1813
|
-
editor.update(() => $removeList());
|
|
1814
|
-
}
|
|
1795
|
+
|
|
1815
1796
|
/**
|
|
1816
1797
|
* Configures {@link ListNode}, {@link ListItemNode} and registers
|
|
1817
1798
|
* the strict indent transform if `hasStrictIndent` is true (default false).
|
|
@@ -1837,10 +1818,8 @@ const ListExtension = defineExtension({
|
|
|
1837
1818
|
});
|
|
1838
1819
|
/**
|
|
1839
1820
|
* Registers checklist functionality for {@link ListNode} and
|
|
1840
|
-
* {@link ListItemNode} with a
|
|
1841
|
-
*
|
|
1842
|
-
* the expected keyboard and mouse interactions for
|
|
1843
|
-
* checkboxes.
|
|
1821
|
+
* {@link ListItemNode} with a `INSERT_CHECK_LIST_COMMAND` listener and
|
|
1822
|
+
* the expected keyboard and mouse interactions for checkboxes.
|
|
1844
1823
|
*/
|
|
1845
1824
|
const CheckListExtension = defineExtension({
|
|
1846
1825
|
build: (editor, config) => namedSignals(config),
|
|
@@ -1852,4 +1831,277 @@ const CheckListExtension = defineExtension({
|
|
|
1852
1831
|
register: (editor, config, state) => registerCheckList(editor, state.getOutput())
|
|
1853
1832
|
});
|
|
1854
1833
|
|
|
1855
|
-
|
|
1834
|
+
/**
|
|
1835
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1836
|
+
*
|
|
1837
|
+
* This source code is licensed under the MIT license found in the
|
|
1838
|
+
* LICENSE file in the root directory of this source tree.
|
|
1839
|
+
*
|
|
1840
|
+
*/
|
|
1841
|
+
|
|
1842
|
+
|
|
1843
|
+
/**
|
|
1844
|
+
* Mirrors the legacy `isDomChecklist` heuristic from
|
|
1845
|
+
* `@lexical/list`.
|
|
1846
|
+
*/
|
|
1847
|
+
function isDomChecklist(domNode) {
|
|
1848
|
+
return domNode.matches('[__lexicallisttype="check"], .contains-task-list, [data-is-checklist="1"]') || domNode.querySelector(':scope > [aria-checked]') !== null;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
/**
|
|
1852
|
+
* Lift nested `ListNode`s out of `ListItemNode`s into sibling
|
|
1853
|
+
* `ListItemNode`s (the legacy `$normalizeChildren` shape). Also wraps any
|
|
1854
|
+
* non-`ListItemNode` children in a new `ListItemNode`.
|
|
1855
|
+
*/
|
|
1856
|
+
function $normalizeListChildren(children) {
|
|
1857
|
+
const out = [];
|
|
1858
|
+
for (const child of children) {
|
|
1859
|
+
if ($isListItemNode(child)) {
|
|
1860
|
+
out.push(child);
|
|
1861
|
+
const innerChildren = child.getChildren();
|
|
1862
|
+
if (innerChildren.length > 1) {
|
|
1863
|
+
for (const inner of innerChildren) {
|
|
1864
|
+
if ($isListNode(inner)) {
|
|
1865
|
+
out.push($createListItemNode().append(inner));
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
} else {
|
|
1870
|
+
out.push($createListItemNode().append(child));
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
return out;
|
|
1874
|
+
}
|
|
1875
|
+
const ListRule = defineImportRule({
|
|
1876
|
+
$import: (ctx, el) => {
|
|
1877
|
+
let node;
|
|
1878
|
+
if (isElementOfTag(el, 'ol')) {
|
|
1879
|
+
node = $createListNode('number', el.start);
|
|
1880
|
+
} else if (isDomChecklist(el)) {
|
|
1881
|
+
node = $createListNode('check');
|
|
1882
|
+
} else {
|
|
1883
|
+
node = $createListNode('bullet');
|
|
1884
|
+
}
|
|
1885
|
+
$setDirectionFromDOM(node, el);
|
|
1886
|
+
// Propagate the list's `text-align` onto each `ListItemNode` child
|
|
1887
|
+
// (legacy `wrapContinuousInlines` did the same), so pasting
|
|
1888
|
+
// `<ul style="text-align: left"><li>…</li></ul>` ends up with the
|
|
1889
|
+
// alignment on the list items where the reconciler renders it as
|
|
1890
|
+
// `style="text-align: left"`.
|
|
1891
|
+
return [node.splice(0, 0, $propagateTextAlignToBlockChildren($normalizeListChildren(ctx.$importChildren(el)), el))];
|
|
1892
|
+
},
|
|
1893
|
+
match: sel.tag('ol', 'ul'),
|
|
1894
|
+
name: '@lexical/list/list'
|
|
1895
|
+
});
|
|
1896
|
+
|
|
1897
|
+
/**
|
|
1898
|
+
* Apply formatting from the first child paragraph of `<li>` to the list
|
|
1899
|
+
* item itself, then unwrap that paragraph (Google Docs sets the alignment
|
|
1900
|
+
* of the `<p>` inside the `<li>`). Mirrors the legacy
|
|
1901
|
+
* `setFormatFromChildren`.
|
|
1902
|
+
*/
|
|
1903
|
+
function $liftFormatFromSingleParagraph(listItemNode, children) {
|
|
1904
|
+
if (children.length !== 1) {
|
|
1905
|
+
return children;
|
|
1906
|
+
}
|
|
1907
|
+
const firstChild = children[0];
|
|
1908
|
+
if ($isParagraphNode(firstChild) && !listItemNode.getFormatType() && firstChild.getFormatType()) {
|
|
1909
|
+
listItemNode.setFormat(firstChild.getFormatType());
|
|
1910
|
+
return firstChild.getChildren();
|
|
1911
|
+
}
|
|
1912
|
+
return children;
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
/**
|
|
1916
|
+
* Collapse block children of a `<li>` into inline-with-line-break form: a
|
|
1917
|
+
* `ListItemNode` is an inline-level container, so any block child marks a
|
|
1918
|
+
* boundary. Contiguous inline siblings are kept together as a single run and
|
|
1919
|
+
* one {@link $createLineBreakNode} is inserted between runs — reproducing the
|
|
1920
|
+
* legacy `wrapContinuousInlines` + `$unwrapArtificialNodes` shape
|
|
1921
|
+
* (`<li>1<div>2</div>3</li>` → `1<br>2<br>3`) without the
|
|
1922
|
+
* `ArtificialNode__DO_NOT_USE` marker.
|
|
1923
|
+
*
|
|
1924
|
+
* Boundaries are detected with {@link $isBlockLevel}, NOT `$isParagraphNode`:
|
|
1925
|
+
* the `<div>`/`<section>`/… `TransparentBlockRule` happens to emit
|
|
1926
|
+
* `ParagraphNode`s, but a `<blockquote>` (`QuoteNode`), heading
|
|
1927
|
+
* (`HeadingNode`), or block decorator (`HorizontalRuleNode`, …) is just as
|
|
1928
|
+
* much a block boundary and must not be silently spliced into the list item
|
|
1929
|
+
* as-is. A nested `ListNode` is the one deliberate exception — it is a valid
|
|
1930
|
+
* list-item child that {@link $normalizeListChildren} lifts into a sibling,
|
|
1931
|
+
* so it is preserved here rather than unwrapped.
|
|
1932
|
+
*/
|
|
1933
|
+
function $flattenListItemBlocks(children) {
|
|
1934
|
+
const $isBoundary = node => $isBlockLevel(node) && !$isListNode(node);
|
|
1935
|
+
if (!children.some($isBoundary)) {
|
|
1936
|
+
return children;
|
|
1937
|
+
}
|
|
1938
|
+
// Partition into segments — each maximal run of inline siblings, and each
|
|
1939
|
+
// boundary's own content — then join the segments with a single line break.
|
|
1940
|
+
const segments = [];
|
|
1941
|
+
let inlineRun = [];
|
|
1942
|
+
const flushInlineRun = () => {
|
|
1943
|
+
if (inlineRun.length > 0) {
|
|
1944
|
+
segments.push(inlineRun);
|
|
1945
|
+
inlineRun = [];
|
|
1946
|
+
}
|
|
1947
|
+
};
|
|
1948
|
+
for (const child of children) {
|
|
1949
|
+
if ($isBoundary(child)) {
|
|
1950
|
+
flushInlineRun();
|
|
1951
|
+
// Unwrap a block ElementNode to its inline content; a childless block
|
|
1952
|
+
// DecoratorNode stands on its own line.
|
|
1953
|
+
segments.push($isElementNode(child) ? child.getChildren() : [child]);
|
|
1954
|
+
} else {
|
|
1955
|
+
inlineRun.push(child);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
flushInlineRun();
|
|
1959
|
+
const out = [];
|
|
1960
|
+
for (const segment of segments) {
|
|
1961
|
+
if (out.length > 0) {
|
|
1962
|
+
out.push($createLineBreakNode());
|
|
1963
|
+
}
|
|
1964
|
+
out.push(...segment);
|
|
1965
|
+
}
|
|
1966
|
+
return out;
|
|
1967
|
+
}
|
|
1968
|
+
const ListItemRule = defineImportRule({
|
|
1969
|
+
$import: (ctx, el) => {
|
|
1970
|
+
const ariaChecked = el.getAttribute('aria-checked');
|
|
1971
|
+
const checked = ariaChecked === 'true' ? true : ariaChecked === 'false' ? false : undefined;
|
|
1972
|
+
const node = $createListItemNode(checked);
|
|
1973
|
+
$setFormatFromDOM(node, el);
|
|
1974
|
+
$setDirectionFromDOM(node, el);
|
|
1975
|
+
return [node.splice(0, 0,
|
|
1976
|
+
// Lift a sole wrapping paragraph's format onto the item *before*
|
|
1977
|
+
// flattening, otherwise the paragraph would already be unwrapped and
|
|
1978
|
+
// its alignment lost.
|
|
1979
|
+
$flattenListItemBlocks($liftFormatFromSingleParagraph(node, ctx.$importChildren(el))))];
|
|
1980
|
+
},
|
|
1981
|
+
match: sel.tag('li'),
|
|
1982
|
+
name: '@lexical/list/li'
|
|
1983
|
+
});
|
|
1984
|
+
function $buildChecklistItem(ctx, el, checkboxOwner) {
|
|
1985
|
+
const checkboxInput = isElementOfTag(checkboxOwner, 'input') ? checkboxOwner : checkboxOwner.querySelector('input[type="checkbox"]');
|
|
1986
|
+
if (!checkboxInput || checkboxInput.getAttribute('type') !== 'checkbox') {
|
|
1987
|
+
return [];
|
|
1988
|
+
}
|
|
1989
|
+
const checked = checkboxInput.hasAttribute('checked');
|
|
1990
|
+
const node = $createListItemNode(checked);
|
|
1991
|
+
$setFormatFromDOM(node, el);
|
|
1992
|
+
$setDirectionFromDOM(node, el);
|
|
1993
|
+
return [node.splice(0, 0, $flattenListItemBlocks($liftFormatFromSingleParagraph(node, ctx.$importChildren(el))))];
|
|
1994
|
+
}
|
|
1995
|
+
const TaskListItemRule = defineImportRule({
|
|
1996
|
+
$import: (ctx, el, $next) => {
|
|
1997
|
+
const input = el.querySelector(':scope > input[type="checkbox"]');
|
|
1998
|
+
if (!input) {
|
|
1999
|
+
return $next();
|
|
2000
|
+
}
|
|
2001
|
+
return $buildChecklistItem(ctx, el, input);
|
|
2002
|
+
},
|
|
2003
|
+
match: sel.tag('li').classAll('task-list-item'),
|
|
2004
|
+
name: '@lexical/list/li-task-list-item'
|
|
2005
|
+
});
|
|
2006
|
+
const JoplinChecklistItemRule = defineImportRule({
|
|
2007
|
+
$import: (ctx, el, $next) => {
|
|
2008
|
+
const wrapper = el.querySelector(':scope > .checkbox-wrapper');
|
|
2009
|
+
if (!wrapper) {
|
|
2010
|
+
return $next();
|
|
2011
|
+
}
|
|
2012
|
+
const input = wrapper.querySelector(':scope > input[type="checkbox"]');
|
|
2013
|
+
if (!input) {
|
|
2014
|
+
return $next();
|
|
2015
|
+
}
|
|
2016
|
+
return $buildChecklistItem(ctx, el, input);
|
|
2017
|
+
},
|
|
2018
|
+
match: sel.tag('li').classAll('joplin-checkbox'),
|
|
2019
|
+
name: '@lexical/list/li-joplin-checkbox'
|
|
2020
|
+
});
|
|
2021
|
+
|
|
2022
|
+
/**
|
|
2023
|
+
* A {@link ChildSchema} that enforces ListNode invariants: only
|
|
2024
|
+
* `ListItemNode` and (immediately-nested) `ListNode` children are
|
|
2025
|
+
* accepted; runs of other children get wrapped in a fresh
|
|
2026
|
+
* `ListItemNode`.
|
|
2027
|
+
*
|
|
2028
|
+
* @experimental
|
|
2029
|
+
*/
|
|
2030
|
+
const ListSchema = {
|
|
2031
|
+
$accepts: child => $isListItemNode(child) || $isListNode(child),
|
|
2032
|
+
// Inline runs inside a `<ul>`/`<ol>` (e.g. text between two `<li>`s)
|
|
2033
|
+
// become the children of a synthetic `ListItemNode`. `ListItemNode`
|
|
2034
|
+
// is itself a block-level container of inlines, so no intermediate
|
|
2035
|
+
// `ParagraphNode` is needed (and the demoted-paragraph normalization
|
|
2036
|
+
// would strip one anyway).
|
|
2037
|
+
$packageRun: run => [$createListItemNode().splice(0, 0, run)],
|
|
2038
|
+
name: 'ListSchema'
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
/**
|
|
2042
|
+
* Import rules for {@link ListNode} and {@link ListItemNode}, including
|
|
2043
|
+
* GitHub task-list and Joplin checkbox heuristics.
|
|
2044
|
+
*
|
|
2045
|
+
* @experimental
|
|
2046
|
+
*/
|
|
2047
|
+
const ListImportRules = [
|
|
2048
|
+
// More specific rules (class-restricted) must precede the generic `li`
|
|
2049
|
+
// rule so they win the dispatch race (lower array index = higher
|
|
2050
|
+
// priority).
|
|
2051
|
+
TaskListItemRule, JoplinChecklistItemRule, ListRule, ListItemRule];
|
|
2052
|
+
|
|
2053
|
+
/**
|
|
2054
|
+
* Bundles {@link ListImportRules} together with the runtime
|
|
2055
|
+
* {@link ListExtension}. The application is expected to already have
|
|
2056
|
+
* `CoreImportExtension` (or some equivalent) in its dependency graph —
|
|
2057
|
+
* the core/text/paragraph/inline-format rules are a shared baseline,
|
|
2058
|
+
* not something this leaf importer should re-declare.
|
|
2059
|
+
*
|
|
2060
|
+
* @experimental
|
|
2061
|
+
*/
|
|
2062
|
+
const ListImportExtension = defineExtension({
|
|
2063
|
+
dependencies: [ListExtension, configExtension(DOMImportExtension, {
|
|
2064
|
+
rules: ListImportRules
|
|
2065
|
+
})],
|
|
2066
|
+
name: '@lexical/list/Import'
|
|
2067
|
+
});
|
|
2068
|
+
|
|
2069
|
+
/**
|
|
2070
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2071
|
+
*
|
|
2072
|
+
* This source code is licensed under the MIT license found in the
|
|
2073
|
+
* LICENSE file in the root directory of this source tree.
|
|
2074
|
+
*
|
|
2075
|
+
*/
|
|
2076
|
+
|
|
2077
|
+
|
|
2078
|
+
/**
|
|
2079
|
+
* @deprecated use {@link $insertList} from an update or command listener.
|
|
2080
|
+
*
|
|
2081
|
+
* Inserts a new ListNode. If the selection's anchor node is an empty ListItemNode and is a child of
|
|
2082
|
+
* the root/shadow root, it will replace the ListItemNode with a ListNode and the old ListItemNode.
|
|
2083
|
+
* Otherwise it will replace its parent with a new ListNode and re-insert the ListItemNode and any previous children.
|
|
2084
|
+
* If the selection's anchor node is not an empty ListItemNode, it will add a new ListNode or merge an existing ListNode,
|
|
2085
|
+
* unless the the node is a leaf node, in which case it will attempt to find a ListNode up the branch and replace it with
|
|
2086
|
+
* a new ListNode, or create a new ListNode at the nearest root/shadow root.
|
|
2087
|
+
* @param editor - The lexical editor.
|
|
2088
|
+
* @param listType - The type of list, "number" | "bullet" | "check".
|
|
2089
|
+
*/
|
|
2090
|
+
function insertList(editor, listType) {
|
|
2091
|
+
editor.update(() => $insertList(listType));
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
/**
|
|
2095
|
+
* @deprecated use {@link $removeList} from an update or command listener.
|
|
2096
|
+
*
|
|
2097
|
+
* Searches for the nearest ancestral ListNode and removes it. If selection is an empty ListItemNode
|
|
2098
|
+
* it will remove the whole list, including the ListItemNode. For each ListItemNode in the ListNode,
|
|
2099
|
+
* removeList will also generate new ParagraphNodes in the removed ListNode's place. Any child node
|
|
2100
|
+
* inside a ListItemNode will be appended to the new ParagraphNodes.
|
|
2101
|
+
* @param editor - The lexical editor.
|
|
2102
|
+
*/
|
|
2103
|
+
function removeList(editor) {
|
|
2104
|
+
editor.update(() => $removeList());
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
export { $createListItemNode, $createListNode, $getListDepth, $handleListInsertParagraph, $insertList, $isListItemNode, $isListNode, $removeList, CheckListExtension, INSERT_CHECK_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, ListExtension, ListImportExtension, ListImportRules, ListItemNode, ListNode, ListSchema, REMOVE_LIST_COMMAND, UPDATE_LIST_START_COMMAND, insertList, registerCheckList, registerList, registerListStrictIndentTransform, removeList };
|
|
@@ -22,8 +22,11 @@ export const INSERT_CHECK_LIST_COMMAND = mod.INSERT_CHECK_LIST_COMMAND;
|
|
|
22
22
|
export const INSERT_ORDERED_LIST_COMMAND = mod.INSERT_ORDERED_LIST_COMMAND;
|
|
23
23
|
export const INSERT_UNORDERED_LIST_COMMAND = mod.INSERT_UNORDERED_LIST_COMMAND;
|
|
24
24
|
export const ListExtension = mod.ListExtension;
|
|
25
|
+
export const ListImportExtension = mod.ListImportExtension;
|
|
26
|
+
export const ListImportRules = mod.ListImportRules;
|
|
25
27
|
export const ListItemNode = mod.ListItemNode;
|
|
26
28
|
export const ListNode = mod.ListNode;
|
|
29
|
+
export const ListSchema = mod.ListSchema;
|
|
27
30
|
export const REMOVE_LIST_COMMAND = mod.REMOVE_LIST_COMMAND;
|
|
28
31
|
export const UPDATE_LIST_START_COMMAND = mod.UPDATE_LIST_START_COMMAND;
|
|
29
32
|
export const insertList = mod.insertList;
|
|
@@ -20,8 +20,11 @@ export const INSERT_CHECK_LIST_COMMAND = mod.INSERT_CHECK_LIST_COMMAND;
|
|
|
20
20
|
export const INSERT_ORDERED_LIST_COMMAND = mod.INSERT_ORDERED_LIST_COMMAND;
|
|
21
21
|
export const INSERT_UNORDERED_LIST_COMMAND = mod.INSERT_UNORDERED_LIST_COMMAND;
|
|
22
22
|
export const ListExtension = mod.ListExtension;
|
|
23
|
+
export const ListImportExtension = mod.ListImportExtension;
|
|
24
|
+
export const ListImportRules = mod.ListImportRules;
|
|
23
25
|
export const ListItemNode = mod.ListItemNode;
|
|
24
26
|
export const ListNode = mod.ListNode;
|
|
27
|
+
export const ListSchema = mod.ListSchema;
|
|
25
28
|
export const REMOVE_LIST_COMMAND = mod.REMOVE_LIST_COMMAND;
|
|
26
29
|
export const UPDATE_LIST_START_COMMAND = mod.UPDATE_LIST_START_COMMAND;
|
|
27
30
|
export const insertList = mod.insertList;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/extension"),r=require("@lexical/html");function i(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function s(e){let t=1,n=e.getParent();for(;null!=n;){if(x(n)){const e=n.getParent();if(M(e)){t++,n=e.getParent();continue}i(40)}return t}return t}function o(e){let t=e.getParent();M(t)||i(40);let n=t;for(;null!==n;)n=n.getParent(),M(n)&&(t=n);return t}function l(e){let t=[];const n=e.getChildren().filter(x);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();M(i)?t=t.concat(l(i)):t.push(r)}return t}function c(e){return x(e)&&M(e.getFirstChild())}function a(e,t){return x(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function d(e){const n=t.$getSelection();if(null!==n){let r=n.getNodes();if(t.$isRangeSelection(n)){const[i]=n.getStartEndPoints(),s=i.getNode(),o=s.getParent();if(t.$isRootOrShadowRoot(s)){const e=s.getFirstChild();if(e)r=e.selectStart().getNodes();else{const e=t.$createParagraphNode();s.append(e),r=e.select().getNodes()}}else if(a(s,r)){const n=k(e);if(t.$isRootOrShadowRoot(o)){s.replace(n);const e=L();t.$isElementNode(s)&&(e.setFormat(s.getFormatType()),e.setIndent(s.getIndent())),n.append(e)}else if(x(s)){const e=s.getParentOrThrow();u(n,e.getChildren()),e.replace(n)}return}}const i=new Set;for(let n=0;n<r.length;n++){const s=r[n];if(t.$isElementNode(s)&&s.isEmpty()&&!x(s)&&!i.has(s.getKey())){g(s,e);continue}let o=t.$isLeafNode(s)?s.getParent():x(s)&&s.isEmpty()?s:null;for(;null!=o;){const n=o.getKey();if(M(o)){if(!i.has(n)){const t=k(e);u(t,o.getChildren()),o.replace(t),i.add(n)}break}{const r=o.getParent();if(t.$isRootOrShadowRoot(r)&&!i.has(n)){i.add(n),g(o,e);break}o=r}}}}}function u(e,t){e.splice(e.getChildrenSize(),0,t)}function g(e,n){if(M(e))return e;const r=e.getPreviousSibling(),i=e.getNextSibling(),s=L();let o;if(u(s,e.getChildren()),M(r)&&n===r.getListType())r.append(s),M(i)&&n===i.getListType()&&(u(r,i.getChildren()),i.remove()),o=r;else if(M(i)&&n===i.getListType())i.getFirstChildOrThrow().insertBefore(s),o=i;else{const t=k(n);t.append(s),e.replace(t),o=t}s.setFormat(e.getFormatType()),s.setIndent(e.getIndent());const l=t.$getSelection();return t.$isRangeSelection(l)&&(o.getKey()===l.anchor.key&&l.anchor.set(s.getKey(),l.anchor.offset,"element"),o.getKey()===l.focus.key&&l.focus.set(s.getKey(),l.focus.offset,"element")),e.remove(),o}function h(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&c(n)&&c(r)&&(h(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function p(){const n=t.$getSelection();if(t.$isRangeSelection(n)){const r=new Set,i=n.getNodes(),s=n.anchor.getNode();if(a(s,i))r.add(o(s));else for(let n=0;n<i.length;n++){const s=i[n];if(t.$isLeafNode(s)){const t=e.$getNearestNodeOfType(s,N);null!=t&&r.add(o(t))}}for(const e of r){let r=e;const i=l(e);for(const e of i){const i=t.$createParagraphNode().setTextStyle(n.style).setTextFormat(n.format);u(i,e.getChildren()),r.insertAfter(i),r=i,e.__key===n.anchor.key&&t.$setPointFromCaret(n.anchor,t.$normalizeCaret(t.$getChildCaret(i,"next"))),e.__key===n.focus.key&&t.$setPointFromCaret(n.focus,t.$normalizeCaret(t.$getChildCaret(i,"next"))),e.remove()}e.remove()}}}function f(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())x(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),M(r.getFirstChild())||n++)}function m(e){const n=new Set;if(c(e)||n.has(e.getKey()))return;const r=e.getParent(),i=e.getNextSibling(),s=e.getPreviousSibling();if(c(i)&&c(s)){const t=s.getFirstChild();if(M(t)){t.append(e);const r=i.getFirstChild();if(M(r)){u(t,r.getChildren()),i.remove(),n.add(i.getKey())}}}else if(c(i)){const t=i.getFirstChild();if(M(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(c(s)){const t=s.getFirstChild();M(t)&&t.append(e)}else if(M(r)){const n=t.$copyNode(e),o=t.$copyNode(r);n.append(o),o.append(e),s?s.insertAfter(n):i?i.insertBefore(n):r.append(n)}}function _(e){if(c(e))return;const n=e.getParent(),r=n?n.getParent():void 0;if(M(r?r.getParent():void 0)&&x(r)&&M(n)){const i=n?n.getFirstChild():void 0,s=n?n.getLastChild():void 0;if(e.is(i))r.insertBefore(e),n.isEmpty()&&r.remove();else if(e.is(s))r.insertAfter(e),n.isEmpty()&&r.remove();else{const i=t.$copyNode(e),s=t.$copyNode(n);i.append(s),e.getPreviousSiblings().forEach(e=>s.append(e));const o=t.$copyNode(e),l=t.$copyNode(n);o.append(l),u(l,e.getNextSiblings()),r.insertBefore(i),r.insertAfter(o),r.replace(e)}}}function C(e=!1){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!n.isCollapsed())return!1;const r=n.anchor.getNode();let s=null;if(x(r)&&0===r.getChildrenSize())s=r;else if(t.$isTextNode(r)){const e=r.getParent();x(e)&&e.getChildren().every(e=>t.$isTextNode(e)&&""===e.getTextContent().trim())&&(s=e)}if(null===s)return!1;const l=o(s),c=s.getParent();M(c)||i(40);const a=c.getParent();let d;if(t.$isRootOrShadowRoot(a))d=t.$createParagraphNode(),l.insertAfter(d);else{if(!x(a))return!1;d=t.$copyNode(a),a.insertAfter(d)}d.setTextStyle(n.style).setTextFormat(n.format).select();const u=s.getNextSiblings();if(u.length>0){const n=e?function(e,t){return e.getStart()+t.getIndexWithinParent()}(c,s):1,r=t.$copyNode(c).setStart(n);if(x(d)){const e=t.$copyNode(d);e.append(r),d.insertAfter(e)}else d.insertAfter(r);r.append(...u)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!x(e)&&!M(e))break;t=e}t.remove()}(s),!0}class N extends t.ElementNode{__value;__checked;$config(){return this.config("listitem",{$transform:n=>{const r=n.getParent();if(M(r))"check"!==r.getListType()&&null!=n.getChecked()&&n.setChecked(void 0);else if(r){const s=n.createParentElementNode();M(s)||i(340);const o=[n];for(const e of["previous","next"]){o.reverse();for(const{origin:r}of t.$getSiblingCaret(n,e)){if(!x(r))break;o.push(r)}}n.insertBefore(s),s.splice(0,0,o),t.$isRootOrShadowRoot(r)||(e.$insertNodeToNearestRootAtCaret(s,t.$rewindSiblingCaret(t.$getSiblingCaret(s,"next")),{$shouldSplit:()=>!1,removeEmptyDestination:!0}),r.isEmpty()&&r.isAttached()&&r.remove())}},extends:t.ElementNode,importDOM:t.buildImportMap({li:()=>({conversion:T,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(n,r,i){!function(e,t){const n=t.getParent();!M(n)||"check"!==n.getListType()||M(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}(r,this),r.value=this.__value,function(n,r,i){const s=r.list;if(!s)return;const o=s.listitem,l=s.nested&&s.nested.listitem,c=i.getParent(),a=M(c)&&"check"===c.getListType(),d=i.getChecked(),u=i.getChildren().some(e=>M(e)),g=[];void 0!==s.listitemChecked&&g.push(s.listitemChecked);void 0!==s.listitemUnchecked&&g.push(s.listitemUnchecked);void 0!==l&&g.push(...t.normalizeClassNames(l));g.length>0&&e.removeClassNamesFromElement(n,...g);const h=[];void 0!==o&&h.push(...t.normalizeClassNames(o));if(a){const e=d?s.listitemChecked:s.listitemUnchecked;void 0!==e&&h.push(e)}void 0!==l&&u&&h.push(...t.normalizeClassNames(l));h.length>0&&e.addClassNamesToElement(n,...h)}(r,i.theme,this);const s=n?n.__style:"",o=this.__style;s!==o&&t.setDOMStyleFromCSS(r.style,o,s),function(e,n,r){const i=n.__textStyle,s=r?r.__textStyle:"";if(null!==r&&s===i)return;const o=t.getStyleObjectFromCSS(i);for(const t in o)e.style.setProperty(`--listitem-marker-${t}`,o[t]);if(""!==s)for(const n in t.getStyleObjectFromCSS(s))n in o||e.style.removeProperty(`--listitem-marker-${n}`)}(r,this,n)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const n=this.createDOM(e._config),r=this.getFormatType();r&&(n.style.textAlign=r);const i=this.getDirection();return i&&(n.dir=i),c(this)?{after(e){if(t.isHTMLElement(e)){const n=e.previousElementSibling;if(t.isHTMLElement(n)&&"LI"===n.nodeName){for(;e.firstChild;)n.append(e.firstChild);e.remove()}}return e},element:n}:{element:n}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let n=0;n<e.length;n++){const r=e[n];if(t.$isElementNode(r)&&this.canMergeWith(r)){const e=r.getChildren();this.append(...e),r.remove()}else super.append(r)}return this}replace(e,n){if(x(e))return super.replace(e);this.setIndent(0);const r=this.getParentOrThrow();if(!M(r))return e;if(r.__first===this.getKey())r.insertBefore(e);else if(r.__last===this.getKey())r.insertAfter(e);else{const n=t.$copyNode(r);let i=this.getNextSibling();for(;i;){const e=i;i=i.getNextSibling(),n.append(e)}r.insertAfter(e),e.insertAfter(n)}const s=this.__key;let o=0;if(n&&(t.$isElementNode(e)||i(139),o=e.getChildrenSize(),e.splice(o,0,this.getChildren())),n&&t.$isElementNode(e)){const n=t.$getSelection();if(t.$isRangeSelection(n))for(const t of n.getStartEndPoints())t.key===s&&"element"===t.type&&t.set(e.getKey(),o+t.offset,"element")}return this.remove(),0===r.getChildrenSize()&&r.remove(),e}insertAfter(e,n=!0){const r=this.getParentOrThrow();if(M(r)||i(39),x(e))return super.insertAfter(e,n);const s=this.getNextSiblings();if(r.insertAfter(e,n),0!==s.length){const i=t.$copyNode(r);s.forEach(e=>i.append(e)),e.insertAfter(i,n)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&c(t)&&c(n)&&(h(t.getFirstChild(),n.getFirstChild()),n.remove())}resetOnCopyNodeFrom(e){super.resetOnCopyNodeFrom(e),e.getChecked()&&this.setChecked(!1)}insertNewAfter(e,n=!0){const r=t.$copyNode(this);return this.insertAfter(r,n),r}collapseAtStart(e){const n=t.$createParagraphNode();this.getChildren().forEach(e=>n.append(e));const r=this.getParentOrThrow(),i=r.getParentOrThrow(),s=x(i);if(1===r.getChildrenSize())if(s)r.remove(),i.select();else{r.insertBefore(n),r.remove();const t=e.anchor,i=e.focus,s=n.getKey();"element"===t.type&&t.getNode().is(this)&&t.set(s,t.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else r.insertBefore(n),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return M(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;x(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&i(117),(e=Math.floor(e))>=0||i(199);let t=this.getIndent();for(;t!==e;)t<e?(m(this),t++):(_(this),t--);return this}canInsertAfter(e){return x(e)}canReplaceWith(e){return x(e)}canMergeWith(e){return x(e)||t.$isParagraphNode(e)}extractWithChild(e,n){if(!t.$isRangeSelection(n))return!1;const r=n.anchor.getNode(),i=n.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===n.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return k("bullet")}canMergeWhenEmpty(){return!0}}function T(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return y(t);if(e.classList.contains("joplin-checkbox"))for(const t of e.children)if(t.classList.contains("checkbox-wrapper")&&t.children.length>0&&"INPUT"===t.children[0].tagName)return y(t.children[0]);const n=e.getAttribute("aria-checked"),r=L("true"===n||"false"!==n&&void 0);return t.$setFormatFromDOM(r,e),{after:S.bind(null,r),node:t.$setDirectionFromDOM(r,e)}}function y(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};const t=L(e.hasAttribute("checked"));return{after:S.bind(null,t),node:t}}function S(e,n){const r=n[0];return 1===n.length&&t.$isParagraphNode(r)&&!e.getFormatType()&&r.getFormatType()?(e.setFormat(r.getFormatType()),r.getChildren()):n}function L(e){return t.$applyNodeReplacement(new N(void 0,e))}function x(e){return e instanceof N}class O extends t.ElementNode{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();M(t)&&e.getListType()===t.getListType()&&h(e,t)}(e),f(e)},extends:t.ElementNode,importDOM:t.buildImportMap({ol:()=>({conversion:E,priority:0}),ul:()=>({conversion:E,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=$[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,v(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(v(t,n.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(t){const n=this.createDOM(t._config,t);return e.isHTMLElement(n)&&(1!==this.__start&&n.setAttribute("start",String(this.__start)),"check"===this.__listType&&n.setAttribute("__lexicalListType","check")),{element:n}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,n,r){let i=r;for(let e=0;e<r.length;e++){const n=r[e];x(n)||(i===r&&(i=[...r]),i[e]=this.createListItemNode().append(!t.$isElementNode(n)||M(n)||n.isInline()?n:t.$createTextNode(n.getTextContent())))}return super.splice(e,n,i)}extractWithChild(e){return x(e)}createListItemNode(){return L()}}function v(n,r,i){const o=[],l=[],c=r.list;if(void 0!==c){const e=c[`${i.__tag}Depth`]||[],n=s(i)-1,r=n%e.length,a=e[r],d=c[i.__tag];let u;const g=c.nested,h=c.checklist;if(void 0!==g&&g.list&&(u=g.list),void 0!==d&&o.push(d),void 0!==h&&"check"===i.__listType&&o.push(h),void 0!==a){o.push(...t.normalizeClassNames(a));for(let t=0;t<e.length;t++)t!==r&&l.push(i.__tag+t)}if(void 0!==u){const e=t.normalizeClassNames(u);n>1?o.push(...e):l.push(...e)}}l.length>0&&e.removeClassNamesFromElement(n,...l),o.length>0&&e.addClassNamesToElement(n,...o)}function E(n){let r;if(function(t){return e.isHTMLElement(t)&&"ol"===t.nodeName.toLowerCase()}(n)){const e=n.start;r=k("number",e)}else r=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list")||"1"===t.getAttribute("data-is-checklist"))return!0;for(const n of t.childNodes)if(e.isHTMLElement(n)&&n.hasAttribute("aria-checked"))return!0;return!1}(n)?k("check"):k("bullet");return t.$setDirectionFromDOM(r,n),{after:e=>function(e,t){const n=t.createListItemNode.bind(t),r=[];for(let t=0;t<e.length;t++){const i=e[t];if(x(i)){r.push(i);const e=i.getChildren();e.length>1&&e.forEach(e=>{M(e)&&r.push(n().append(e))})}else r.push(n().append(i))}return r}(e,r),node:r}}const $={ol:"number",ul:"bullet"};function k(e="number",n=1){return t.$applyNodeReplacement(new O(e,n))}function M(e){return e instanceof O}const b=t.createCommand("INSERT_CHECK_LIST_COMMAND");function P(n,r){const i=r&&r.disableTakeFocusOnClick||!1,s="boolean"==typeof i?()=>i:i.peek.bind(i),o=t=>{const n=t.target;if(!e.isHTMLElement(n))return!1;const r=n.__lexicalCheckListLastHandled;return void 0!==r&&t.timeStamp-r<500},l=t=>{const n=t.target;e.isHTMLElement(n)&&(n.__lexicalCheckListLastHandled=t.timeStamp)},c=e=>{o(e)||(l(e),A(e,s()))},a=e=>{"touch"===e.pointerType&&(o(e)||(l(e),A(e,s())))},u=e=>{!function(e,t){I(e,()=>{e.preventDefault(),t&&e.stopPropagation()})}(e,s())};return e.mergeRegister(n.registerCommand(b,()=>(d("check"),!0),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>R(e,n,!1),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>R(e,n,!0),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.KEY_ESCAPE_COMMAND,()=>{if(null!=F()){const e=n.getRootElement();return null!=e&&e.focus(),!0}return!1},t.COMMAND_PRIORITY_LOW),n.registerCommand(t.KEY_SPACE_COMMAND,e=>{const r=F();return!(null==r||!n.isEditable())&&(n.update(()=>{const n=t.$getNearestNodeFromDOMNode(r);x(n)&&(e.preventDefault(),n.toggleChecked())}),!0)},t.COMMAND_PRIORITY_LOW),n.registerCommand(t.KEY_ARROW_LEFT_COMMAND,r=>n.getEditorState().read(()=>{const i=t.$getSelection();if(t.$isRangeSelection(i)&&i.isCollapsed()){const{anchor:s}=i,o="element"===s.type;if(o||0===s.offset){const i=s.getNode(),l=e.$findMatchingParent(i,e=>t.$isElementNode(e)&&!e.isInline());if(x(l)){const e=l.getParent();if(M(e)&&"check"===e.getListType()&&(o||l.getFirstDescendant()===i)){const e=n.getElementByKey(l.__key);if(null!=e&&document.activeElement!==e)return e.focus(),r.preventDefault(),!0}}}}return!1}),t.COMMAND_PRIORITY_LOW),n.registerRootListener(e=>{if(null!==e)return e.addEventListener("click",c),e.addEventListener("pointerup",a),e.addEventListener("pointerdown",u,{capture:!0}),e.addEventListener("mousedown",u,{capture:!0}),e.addEventListener("touchstart",u,{capture:!0,passive:!1}),()=>{e.removeEventListener("click",c),e.removeEventListener("pointerup",a),e.removeEventListener("pointerdown",u,{capture:!0}),e.removeEventListener("mousedown",u,{capture:!0}),e.removeEventListener("touchstart",u,{capture:!0})}}))}function I(t,n){const r=t.target;if(!e.isHTMLElement(r))return;const i=r.firstChild;if(e.isHTMLElement(i)&&("UL"===i.tagName||"OL"===i.tagName))return;const s=r.parentNode;if(!s||"check"!==s.__lexicalListType)return;let o=null,l=null;if("clientX"in t)o=t.clientX;else if("touches"in t){const e=t.touches;e.length>0&&(o=e[0].clientX,l="touch")}if(null==o)return;const c=r.getBoundingClientRect(),a=o/e.calculateZoomLevel(r),d=window.getComputedStyle?window.getComputedStyle(r,"::before"):{width:"0px"},u=parseFloat(d.width),g="touch"===l||"pointerType"in t&&"touch"===t.pointerType?32:0;("rtl"===r.dir?a<c.right+g&&a>c.right-u-g:a>c.left-g&&a<c.left+u+g)&&n()}function A(n,r){I(n,()=>{if(e.isHTMLElement(n.target)){const e=n.target,i=t.getNearestEditorFromDOMNode(e);null!=i&&i.isEditable()&&i.update(()=>{const n=t.$getNearestNodeFromDOMNode(e);x(n)&&(r?(t.$addUpdateTag(t.SKIP_SELECTION_FOCUS_TAG),t.$addUpdateTag(t.SKIP_DOM_SELECTION_TAG)):e.focus(),n.toggleChecked())})}})}function F(){const t=document.activeElement;return e.isHTMLElement(t)&&"LI"===t.tagName&&null!=t.parentNode&&"check"===t.parentNode.__lexicalListType?t:null}function R(e,n,r){const i=F();return null!=i&&n.update(()=>{const s=t.$getNearestNodeFromDOMNode(i);if(!x(s))return;const o=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&x(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;x(n);){const e=t?n.getLastChild():n.getFirstChild();if(!M(e))return n;n=t?e.getLastChild():e.getFirstChild()}return null}(s,r);if(null!=o){o.selectStart();const t=n.getElementByKey(o.__key);null!=t&&(e.preventDefault(),setTimeout(()=>{t.focus()},0))}}),!1}const D=t.createCommand("UPDATE_LIST_START_COMMAND"),w=t.createCommand("INSERT_UNORDERED_LIST_COMMAND"),W=t.createCommand("INSERT_ORDERED_LIST_COMMAND"),K=t.createCommand("REMOVE_LIST_COMMAND");function B(n,r){return e.mergeRegister(n.registerCommand(W,()=>(d("number"),!0),t.COMMAND_PRIORITY_LOW),n.registerCommand(D,e=>{const{listNodeKey:n,newStart:r}=e,i=t.$getNodeByKey(n);return!!M(i)&&("number"===i.getListType()&&(i.setStart(r),f(i)),!0)},t.COMMAND_PRIORITY_LOW),n.registerCommand(w,()=>(d("bullet"),!0),t.COMMAND_PRIORITY_LOW),n.registerCommand(K,()=>(p(),!0),t.COMMAND_PRIORITY_LOW),n.registerCommand(t.INSERT_PARAGRAPH_COMMAND,()=>C(!!(r&&r.restoreNumbering)),t.COMMAND_PRIORITY_LOW),n.registerNodeTransform(N,e=>{const n=e.getFirstChild();if(n){if(t.$isTextNode(n)){const t=n.getStyle(),r=n.getFormat();e.getTextStyle()!==t&&e.setTextStyle(t),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const n=t.$getSelection();t.$isRangeSelection(n)&&(n.style!==e.getTextStyle()||n.format!==e.getTextFormat())&&n.isCollapsed()&&e.is(n.anchor.getNode())&&e.setTextStyle(n.style).setTextFormat(n.format)}}),n.registerNodeTransform(t.TextNode,e=>{const t=e.getParent();if(x(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}))}function H(t){const n=t=>{const n=t.getParent();if(M(t.getFirstChild())||!M(n))return;const r=e.$findMatchingParent(t,e=>x(e)&&M(e.getParent())&&x(e.getPreviousSibling()));if(null===r&&t.getIndent()>0)t.setIndent(0);else if(x(r)){const e=r.getPreviousSibling();if(x(e)){const r=function(e){let t=e,n=t.getFirstChild();for(;M(n);){const e=n.getLastChild();if(!x(e))break;t=e,n=t.getFirstChild()}return t}(e),i=r.getParent();if(M(i)){const e=s(i);e+1<s(n)&&t.setIndent(e)}}}};return t.registerNodeTransform(O,e=>{const t=[e];for(;t.length>0;){const e=t.shift();if(M(e))for(const r of e.getChildren())if(x(r)){n(r);const e=r.getFirstChild();M(e)&&t.push(e)}}})}const U=t.defineExtension({build:(e,t,r)=>n.namedSignals(t),config:t.safeCast({hasStrictIndent:!1,shouldPreserveNumbering:!1}),name:"@lexical/list/List",nodes:()=>[O,N],register(t,r,i){const s=i.getOutput();return e.mergeRegister(n.effect(()=>B(t,{restoreNumbering:s.shouldPreserveNumbering.value})),n.effect(()=>s.hasStrictIndent.value?H(t):void 0))}}),Y=t.defineExtension({build:(e,t)=>n.namedSignals(t),config:t.safeCast({disableTakeFocusOnClick:!1}),dependencies:[U],name:"@lexical/list/CheckList",register:(e,t,n)=>P(e,n.getOutput())});function z(e){const t=[];for(const n of e)if(x(n)){t.push(n);const e=n.getChildren();if(e.length>1)for(const n of e)M(n)&&t.push(L().append(n))}else t.push(L().append(n));return t}const q=r.defineImportRule({$import:(e,n)=>{let i;var s;return r.isElementOfTag(n,"ol")?i=k("number",n.start):i=(s=n).matches('[__lexicallisttype="check"], .contains-task-list, [data-is-checklist="1"]')||null!==s.querySelector(":scope > [aria-checked]")?k("check"):k("bullet"),t.$setDirectionFromDOM(i,n),[i.splice(0,0,r.$propagateTextAlignToBlockChildren(z(e.$importChildren(n)),n))]},match:r.sel.tag("ol","ul"),name:"@lexical/list/list"});function J(e,n){if(1!==n.length)return n;const r=n[0];return t.$isParagraphNode(r)&&!e.getFormatType()&&r.getFormatType()?(e.setFormat(r.getFormatType()),r.getChildren()):n}function V(e){const n=e=>r.$isBlockLevel(e)&&!M(e);if(!e.some(n))return e;const i=[];let s=[];const o=()=>{s.length>0&&(i.push(s),s=[])};for(const r of e)n(r)?(o(),i.push(t.$isElementNode(r)?r.getChildren():[r])):s.push(r);o();const l=[];for(const e of i)l.length>0&&l.push(t.$createLineBreakNode()),l.push(...e);return l}const j=r.defineImportRule({$import:(e,n)=>{const r=n.getAttribute("aria-checked"),i=L("true"===r||"false"!==r&&void 0);return t.$setFormatFromDOM(i,n),t.$setDirectionFromDOM(i,n),[i.splice(0,0,V(J(i,e.$importChildren(n))))]},match:r.sel.tag("li"),name:"@lexical/list/li"});function G(e,n,i){const s=r.isElementOfTag(i,"input")?i:i.querySelector('input[type="checkbox"]');if(!s||"checkbox"!==s.getAttribute("type"))return[];const o=L(s.hasAttribute("checked"));return t.$setFormatFromDOM(o,n),t.$setDirectionFromDOM(o,n),[o.splice(0,0,V(J(o,e.$importChildren(n))))]}const X={$accepts:e=>x(e)||M(e),$packageRun:e=>[L().splice(0,0,e)],name:"ListSchema"},Z=[r.defineImportRule({$import:(e,t,n)=>{const r=t.querySelector(':scope > input[type="checkbox"]');return r?G(e,t,r):n()},match:r.sel.tag("li").classAll("task-list-item"),name:"@lexical/list/li-task-list-item"}),r.defineImportRule({$import:(e,t,n)=>{const r=t.querySelector(":scope > .checkbox-wrapper");if(!r)return n();const i=r.querySelector(':scope > input[type="checkbox"]');return i?G(e,t,i):n()},match:r.sel.tag("li").classAll("joplin-checkbox"),name:"@lexical/list/li-joplin-checkbox"}),q,j],Q=t.defineExtension({dependencies:[U,t.configExtension(r.DOMImportExtension,{rules:Z})],name:"@lexical/list/Import"});exports.$createListItemNode=L,exports.$createListNode=k,exports.$getListDepth=s,exports.$handleListInsertParagraph=C,exports.$insertList=d,exports.$isListItemNode=x,exports.$isListNode=M,exports.$removeList=p,exports.CheckListExtension=Y,exports.INSERT_CHECK_LIST_COMMAND=b,exports.INSERT_ORDERED_LIST_COMMAND=W,exports.INSERT_UNORDERED_LIST_COMMAND=w,exports.ListExtension=U,exports.ListImportExtension=Q,exports.ListImportRules=Z,exports.ListItemNode=N,exports.ListNode=O,exports.ListSchema=X,exports.REMOVE_LIST_COMMAND=K,exports.UPDATE_LIST_START_COMMAND=D,exports.insertList=function(e,t){e.update(()=>d(t))},exports.registerCheckList=P,exports.registerList=B,exports.registerListStrictIndentTransform=H,exports.removeList=function(e){e.update(()=>p())};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import{$getNearestNodeOfType as e,$insertNodeToNearestRootAtCaret as t,removeClassNamesFromElement as n,addClassNamesToElement as r,isHTMLElement as i,mergeRegister as s,$findMatchingParent as o,calculateZoomLevel as l}from"@lexical/utils";import{$getSelection as c,$isRangeSelection as a,$isTextNode as u,$isRootOrShadowRoot as h,$createParagraphNode as g,$copyNode as d,$isElementNode as f,$isLeafNode as p,$setPointFromCaret as m,$normalizeCaret as _,$getChildCaret as y,$applyNodeReplacement as C,ElementNode as v,buildImportMap as k,$getSiblingCaret as T,$rewindSiblingCaret as b,setDOMStyleFromCSS as S,isHTMLElement as x,$isParagraphNode as L,$setFormatFromDOM as N,$setDirectionFromDOM as F,normalizeClassNames as P,getStyleObjectFromCSS as A,$createTextNode as E,createCommand as O,COMMAND_PRIORITY_LOW as I,KEY_ARROW_DOWN_COMMAND as w,KEY_ARROW_UP_COMMAND as D,KEY_ESCAPE_COMMAND as M,KEY_SPACE_COMMAND as $,$getNearestNodeFromDOMNode as R,KEY_ARROW_LEFT_COMMAND as K,getNearestEditorFromDOMNode as B,$addUpdateTag as W,SKIP_SELECTION_FOCUS_TAG as U,SKIP_DOM_SELECTION_TAG as J,$getNodeByKey as V,INSERT_PARAGRAPH_COMMAND as q,TextNode as z,defineExtension as H,safeCast as j,configExtension as X,$createLineBreakNode as G}from"lexical";import{namedSignals as Q,effect as Y}from"@lexical/extension";import{DOMImportExtension as Z,defineImportRule as ee,sel as te,isElementOfTag as ne,$propagateTextAlignToBlockChildren as re,$isBlockLevel as ie}from"@lexical/html";function se(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function oe(e){let t=1,n=e.getParent();for(;null!=n;){if(xe(n)){const e=n.getParent();if(Ee(e)){t++,n=e.getParent();continue}se(40)}return t}return t}function le(e){let t=e.getParent();Ee(t)||se(40);let n=t;for(;null!==n;)n=n.getParent(),Ee(n)&&(t=n);return t}function ce(e){let t=[];const n=e.getChildren().filter(xe);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();Ee(i)?t=t.concat(ce(i)):t.push(r)}return t}function ae(e){return xe(e)&&Ee(e.getFirstChild())}function ue(e,t){return xe(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function he(e){const t=c();if(null!==t){let n=t.getNodes();if(a(t)){const[r]=t.getStartEndPoints(),i=r.getNode(),s=i.getParent();if(h(i)){const e=i.getFirstChild();if(e)n=e.selectStart().getNodes();else{const e=g();i.append(e),n=e.select().getNodes()}}else if(ue(i,n)){const t=Ae(e);if(h(s)){i.replace(t);const e=Se();f(i)&&(e.setFormat(i.getFormatType()),e.setIndent(i.getIndent())),t.append(e)}else if(xe(i)){const e=i.getParentOrThrow();ge(t,e.getChildren()),e.replace(t)}return}}const r=new Set;for(let t=0;t<n.length;t++){const i=n[t];if(f(i)&&i.isEmpty()&&!xe(i)&&!r.has(i.getKey())){de(i,e);continue}let s=p(i)?i.getParent():xe(i)&&i.isEmpty()?i:null;for(;null!=s;){const t=s.getKey();if(Ee(s)){if(!r.has(t)){const n=Ae(e);ge(n,s.getChildren()),s.replace(n),r.add(t)}break}{const n=s.getParent();if(h(n)&&!r.has(t)){r.add(t),de(s,e);break}s=n}}}}}function ge(e,t){e.splice(e.getChildrenSize(),0,t)}function de(e,t){if(Ee(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=Se();let s;if(ge(i,e.getChildren()),Ee(n)&&t===n.getListType())n.append(i),Ee(r)&&t===r.getListType()&&(ge(n,r.getChildren()),r.remove()),s=n;else if(Ee(r)&&t===r.getListType())r.getFirstChildOrThrow().insertBefore(i),s=r;else{const n=Ae(t);n.append(i),e.replace(n),s=n}i.setFormat(e.getFormatType()),i.setIndent(e.getIndent());const o=c();return a(o)&&(s.getKey()===o.anchor.key&&o.anchor.set(i.getKey(),o.anchor.offset,"element"),s.getKey()===o.focus.key&&o.focus.set(i.getKey(),o.focus.offset,"element")),e.remove(),s}function fe(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&ae(n)&&ae(r)&&(fe(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function pe(){const t=c();if(a(t)){const n=new Set,r=t.getNodes(),i=t.anchor.getNode();if(ue(i,r))n.add(le(i));else for(let t=0;t<r.length;t++){const i=r[t];if(p(i)){const t=e(i,ve);null!=t&&n.add(le(t))}}for(const e of n){let n=e;const r=ce(e);for(const e of r){const r=g().setTextStyle(t.style).setTextFormat(t.format);ge(r,e.getChildren()),n.insertAfter(r),n=r,e.__key===t.anchor.key&&m(t.anchor,_(y(r,"next"))),e.__key===t.focus.key&&m(t.focus,_(y(r,"next"))),e.remove()}e.remove()}}}function me(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())xe(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),Ee(r.getFirstChild())||n++)}function _e(e){const t=new Set;if(ae(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(ae(r)&&ae(i)){const n=i.getFirstChild();if(Ee(n)){n.append(e);const i=r.getFirstChild();if(Ee(i)){ge(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(ae(r)){const t=r.getFirstChild();if(Ee(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(ae(i)){const t=i.getFirstChild();Ee(t)&&t.append(e)}else if(Ee(n)){const t=d(e),s=d(n);t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function ye(e){if(ae(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(Ee(n?n.getParent():void 0)&&xe(n)&&Ee(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=d(e),i=d(t);r.append(i),e.getPreviousSiblings().forEach(e=>i.append(e));const s=d(e),o=d(t);s.append(o),ge(o,e.getNextSiblings()),n.insertBefore(r),n.insertAfter(s),n.replace(e)}}}function Ce(e=!1){const t=c();if(!a(t)||!t.isCollapsed())return!1;const n=t.anchor.getNode();let r=null;if(xe(n)&&0===n.getChildrenSize())r=n;else if(u(n)){const e=n.getParent();xe(e)&&e.getChildren().every(e=>u(e)&&""===e.getTextContent().trim())&&(r=e)}if(null===r)return!1;const i=le(r),s=r.getParent();Ee(s)||se(40);const o=s.getParent();let l;if(h(o))l=g(),i.insertAfter(l);else{if(!xe(o))return!1;l=d(o),o.insertAfter(l)}l.setTextStyle(t.style).setTextFormat(t.format).select();const f=r.getNextSiblings();if(f.length>0){const t=e?function(e,t){return e.getStart()+t.getIndexWithinParent()}(s,r):1,n=d(s).setStart(t);if(xe(l)){const e=d(l);e.append(n),l.insertAfter(e)}else l.insertAfter(n);n.append(...f)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!xe(e)&&!Ee(e))break;t=e}t.remove()}(r),!0}class ve extends v{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{const n=e.getParent();if(Ee(n))"check"!==n.getListType()&&null!=e.getChecked()&&e.setChecked(void 0);else if(n){const r=e.createParentElementNode();Ee(r)||se(340);const i=[e];for(const t of["previous","next"]){i.reverse();for(const{origin:n}of T(e,t)){if(!xe(n))break;i.push(n)}}e.insertBefore(r),r.splice(0,0,i),h(n)||(t(r,b(T(r,"next")),{$shouldSplit:()=>!1,removeEmptyDestination:!0}),n.isEmpty()&&n.isAttached()&&n.remove())}},extends:v,importDOM:k({li:()=>({conversion:ke,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,t,i){!function(e,t){const n=t.getParent();!Ee(n)||"check"!==n.getListType()||Ee(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}(t,this),t.value=this.__value,function(e,t,i){const s=t.list;if(!s)return;const o=s.listitem,l=s.nested&&s.nested.listitem,c=i.getParent(),a=Ee(c)&&"check"===c.getListType(),u=i.getChecked(),h=i.getChildren().some(e=>Ee(e)),g=[];void 0!==s.listitemChecked&&g.push(s.listitemChecked);void 0!==s.listitemUnchecked&&g.push(s.listitemUnchecked);void 0!==l&&g.push(...P(l));g.length>0&&n(e,...g);const d=[];void 0!==o&&d.push(...P(o));if(a){const e=u?s.listitemChecked:s.listitemUnchecked;void 0!==e&&d.push(e)}void 0!==l&&h&&d.push(...P(l));d.length>0&&r(e,...d)}(t,i.theme,this);const s=e?e.__style:"",o=this.__style;s!==o&&S(t.style,o,s),function(e,t,n){const r=t.__textStyle,i=n?n.__textStyle:"";if(null!==n&&i===r)return;const s=A(r);for(const t in s)e.style.setProperty(`--listitem-marker-${t}`,s[t]);if(""!==i)for(const t in A(i))t in s||e.style.removeProperty(`--listitem-marker-${t}`)}(t,this,e)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),n=this.getFormatType();n&&(t.style.textAlign=n);const r=this.getDirection();return r&&(t.dir=r),ae(this)?{after(e){if(x(e)){const t=e.previousElementSibling;if(x(t)&&"LI"===t.nodeName){for(;e.firstChild;)t.append(e.firstChild);e.remove()}}return e},element:t}:{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(f(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,t){if(xe(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!Ee(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else{const t=d(n);let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}n.insertAfter(e),e.insertAfter(t)}const r=this.__key;let i=0;if(t&&(f(e)||se(139),i=e.getChildrenSize(),e.splice(i,0,this.getChildren())),t&&f(e)){const t=c();if(a(t))for(const n of t.getStartEndPoints())n.key===r&&"element"===n.type&&n.set(e.getKey(),i+n.offset,"element")}return this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if(Ee(n)||se(39),xe(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const i=d(n);r.forEach(e=>i.append(e)),e.insertAfter(i,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&ae(t)&&ae(n)&&(fe(t.getFirstChild(),n.getFirstChild()),n.remove())}resetOnCopyNodeFrom(e){super.resetOnCopyNodeFrom(e),e.getChecked()&&this.setChecked(!1)}insertNewAfter(e,t=!0){const n=d(this);return this.insertAfter(n,t),n}collapseAtStart(e){const t=g();this.getChildren().forEach(e=>t.append(e));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=xe(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else n.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return Ee(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;xe(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&se(117),(e=Math.floor(e))>=0||se(199);let t=this.getIndent();for(;t!==e;)t<e?(_e(this),t++):(ye(this),t--);return this}canInsertAfter(e){return xe(e)}canReplaceWith(e){return xe(e)}canMergeWith(e){return xe(e)||L(e)}extractWithChild(e,t){if(!a(t))return!1;const n=t.anchor.getNode(),r=t.focus.getNode();return this.isParentOf(n)&&this.isParentOf(r)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return Ae("bullet")}canMergeWhenEmpty(){return!0}}function ke(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return Te(t);if(e.classList.contains("joplin-checkbox"))for(const t of e.children)if(t.classList.contains("checkbox-wrapper")&&t.children.length>0&&"INPUT"===t.children[0].tagName)return Te(t.children[0]);const t=e.getAttribute("aria-checked"),n=Se("true"===t||"false"!==t&&void 0);return N(n,e),{after:be.bind(null,n),node:F(n,e)}}function Te(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};const t=Se(e.hasAttribute("checked"));return{after:be.bind(null,t),node:t}}function be(e,t){const n=t[0];return 1===t.length&&L(n)&&!e.getFormatType()&&n.getFormatType()?(e.setFormat(n.getFormatType()),n.getChildren()):t}function Se(e){return C(new ve(void 0,e))}function xe(e){return e instanceof ve}class Le extends v{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();Ee(t)&&e.getListType()===t.getListType()&&fe(e,t)}(e),me(e)},extends:v,importDOM:k({ol:()=>({conversion:Fe,priority:0}),ul:()=>({conversion:Fe,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=Pe[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,Ne(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(Ne(t,n.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(e){const t=this.createDOM(e._config,e);return i(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,t,n){let r=n;for(let e=0;e<n.length;e++){const t=n[e];xe(t)||(r===n&&(r=[...n]),r[e]=this.createListItemNode().append(!f(t)||Ee(t)||t.isInline()?t:E(t.getTextContent())))}return super.splice(e,t,r)}extractWithChild(e){return xe(e)}createListItemNode(){return Se()}}function Ne(e,t,i){const s=[],o=[],l=t.list;if(void 0!==l){const e=l[`${i.__tag}Depth`]||[],t=oe(i)-1,n=t%e.length,r=e[n],c=l[i.__tag];let a;const u=l.nested,h=l.checklist;if(void 0!==u&&u.list&&(a=u.list),void 0!==c&&s.push(c),void 0!==h&&"check"===i.__listType&&s.push(h),void 0!==r){s.push(...P(r));for(let t=0;t<e.length;t++)t!==n&&o.push(i.__tag+t)}if(void 0!==a){const e=P(a);t>1?s.push(...e):o.push(...e)}}o.length>0&&n(e,...o),s.length>0&&r(e,...s)}function Fe(e){let t;if(function(e){return i(e)&&"ol"===e.nodeName.toLowerCase()}(e)){const n=e.start;t=Ae("number",n)}else t=function(e){if("check"===e.getAttribute("__lexicallisttype")||e.classList.contains("contains-task-list")||"1"===e.getAttribute("data-is-checklist"))return!0;for(const t of e.childNodes)if(i(t)&&t.hasAttribute("aria-checked"))return!0;return!1}(e)?Ae("check"):Ae("bullet");return F(t,e),{after:e=>function(e,t){const n=t.createListItemNode.bind(t),r=[];for(let t=0;t<e.length;t++){const i=e[t];if(xe(i)){r.push(i);const e=i.getChildren();e.length>1&&e.forEach(e=>{Ee(e)&&r.push(n().append(e))})}else r.push(n().append(i))}return r}(e,t),node:t}}const Pe={ol:"number",ul:"bullet"};function Ae(e="number",t=1){return C(new Le(e,t))}function Ee(e){return e instanceof Le}const Oe=O("INSERT_CHECK_LIST_COMMAND");function Ie(e,t){const n=t&&t.disableTakeFocusOnClick||!1,r="boolean"==typeof n?()=>n:n.peek.bind(n),l=e=>{const t=e.target;if(!i(t))return!1;const n=t.__lexicalCheckListLastHandled;return void 0!==n&&e.timeStamp-n<500},u=e=>{const t=e.target;i(t)&&(t.__lexicalCheckListLastHandled=e.timeStamp)},h=e=>{l(e)||(u(e),De(e,r()))},g=e=>{"touch"===e.pointerType&&(l(e)||(u(e),De(e,r())))},d=e=>{!function(e,t){we(e,()=>{e.preventDefault(),t&&e.stopPropagation()})}(e,r())};return s(e.registerCommand(Oe,()=>(he("check"),!0),I),e.registerCommand(w,t=>$e(t,e,!1),I),e.registerCommand(D,t=>$e(t,e,!0),I),e.registerCommand(M,()=>{if(null!=Me()){const t=e.getRootElement();return null!=t&&t.focus(),!0}return!1},I),e.registerCommand($,t=>{const n=Me();return!(null==n||!e.isEditable())&&(e.update(()=>{const e=R(n);xe(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},I),e.registerCommand(K,t=>e.getEditorState().read(()=>{const n=c();if(a(n)&&n.isCollapsed()){const{anchor:r}=n,i="element"===r.type;if(i||0===r.offset){const n=r.getNode(),s=o(n,e=>f(e)&&!e.isInline());if(xe(s)){const r=s.getParent();if(Ee(r)&&"check"===r.getListType()&&(i||s.getFirstDescendant()===n)){const n=e.getElementByKey(s.__key);if(null!=n&&document.activeElement!==n)return n.focus(),t.preventDefault(),!0}}}}return!1}),I),e.registerRootListener(e=>{if(null!==e)return e.addEventListener("click",h),e.addEventListener("pointerup",g),e.addEventListener("pointerdown",d,{capture:!0}),e.addEventListener("mousedown",d,{capture:!0}),e.addEventListener("touchstart",d,{capture:!0,passive:!1}),()=>{e.removeEventListener("click",h),e.removeEventListener("pointerup",g),e.removeEventListener("pointerdown",d,{capture:!0}),e.removeEventListener("mousedown",d,{capture:!0}),e.removeEventListener("touchstart",d,{capture:!0})}}))}function we(e,t){const n=e.target;if(!i(n))return;const r=n.firstChild;if(i(r)&&("UL"===r.tagName||"OL"===r.tagName))return;const s=n.parentNode;if(!s||"check"!==s.__lexicalListType)return;let o=null,c=null;if("clientX"in e)o=e.clientX;else if("touches"in e){const t=e.touches;t.length>0&&(o=t[0].clientX,c="touch")}if(null==o)return;const a=n.getBoundingClientRect(),u=o/l(n),h=window.getComputedStyle?window.getComputedStyle(n,"::before"):{width:"0px"},g=parseFloat(h.width),d="touch"===c||"pointerType"in e&&"touch"===e.pointerType?32:0;("rtl"===n.dir?u<a.right+d&&u>a.right-g-d:u>a.left-d&&u<a.left+g+d)&&t()}function De(e,t){we(e,()=>{if(i(e.target)){const n=e.target,r=B(n);null!=r&&r.isEditable()&&r.update(()=>{const e=R(n);xe(e)&&(t?(W(U),W(J)):n.focus(),e.toggleChecked())})}})}function Me(){const e=document.activeElement;return i(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function $e(e,t,n){const r=Me();return null!=r&&t.update(()=>{const i=R(r);if(!xe(i))return;const s=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&xe(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;xe(n);){const e=t?n.getLastChild():n.getFirstChild();if(!Ee(e))return n;n=t?e.getLastChild():e.getFirstChild()}return null}(i,n);if(null!=s){s.selectStart();const n=t.getElementByKey(s.__key);null!=n&&(e.preventDefault(),setTimeout(()=>{n.focus()},0))}}),!1}const Re=O("UPDATE_LIST_START_COMMAND"),Ke=O("INSERT_UNORDERED_LIST_COMMAND"),Be=O("INSERT_ORDERED_LIST_COMMAND"),We=O("REMOVE_LIST_COMMAND");function Ue(e,t){return s(e.registerCommand(Be,()=>(he("number"),!0),I),e.registerCommand(Re,e=>{const{listNodeKey:t,newStart:n}=e,r=V(t);return!!Ee(r)&&("number"===r.getListType()&&(r.setStart(n),me(r)),!0)},I),e.registerCommand(Ke,()=>(he("bullet"),!0),I),e.registerCommand(We,()=>(pe(),!0),I),e.registerCommand(q,()=>Ce(!!(t&&t.restoreNumbering)),I),e.registerNodeTransform(ve,e=>{const t=e.getFirstChild();if(t){if(u(t)){const n=t.getStyle(),r=t.getFormat();e.getTextStyle()!==n&&e.setTextStyle(n),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const t=c();a(t)&&(t.style!==e.getTextStyle()||t.format!==e.getTextFormat())&&t.isCollapsed()&&e.is(t.anchor.getNode())&&e.setTextStyle(t.style).setTextFormat(t.format)}}),e.registerNodeTransform(z,e=>{const t=e.getParent();if(xe(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}))}function Je(e){const t=e=>{const t=e.getParent();if(Ee(e.getFirstChild())||!Ee(t))return;const n=o(e,e=>xe(e)&&Ee(e.getParent())&&xe(e.getPreviousSibling()));if(null===n&&e.getIndent()>0)e.setIndent(0);else if(xe(n)){const r=n.getPreviousSibling();if(xe(r)){const n=function(e){let t=e,n=t.getFirstChild();for(;Ee(n);){const e=n.getLastChild();if(!xe(e))break;t=e,n=t.getFirstChild()}return t}(r),i=n.getParent();if(Ee(i)){const n=oe(i);n+1<oe(t)&&e.setIndent(n)}}}};return e.registerNodeTransform(Le,e=>{const n=[e];for(;n.length>0;){const e=n.shift();if(Ee(e))for(const r of e.getChildren())if(xe(r)){t(r);const e=r.getFirstChild();Ee(e)&&n.push(e)}}})}const Ve=H({build:(e,t,n)=>Q(t),config:j({hasStrictIndent:!1,shouldPreserveNumbering:!1}),name:"@lexical/list/List",nodes:()=>[Le,ve],register(e,t,n){const r=n.getOutput();return s(Y(()=>Ue(e,{restoreNumbering:r.shouldPreserveNumbering.value})),Y(()=>r.hasStrictIndent.value?Je(e):void 0))}}),qe=H({build:(e,t)=>Q(t),config:j({disableTakeFocusOnClick:!1}),dependencies:[Ve],name:"@lexical/list/CheckList",register:(e,t,n)=>Ie(e,n.getOutput())});function ze(e){const t=[];for(const n of e)if(xe(n)){t.push(n);const e=n.getChildren();if(e.length>1)for(const n of e)Ee(n)&&t.push(Se().append(n))}else t.push(Se().append(n));return t}const He=ee({$import:(e,t)=>{let n;var r;return ne(t,"ol")?n=Ae("number",t.start):n=(r=t).matches('[__lexicallisttype="check"], .contains-task-list, [data-is-checklist="1"]')||null!==r.querySelector(":scope > [aria-checked]")?Ae("check"):Ae("bullet"),F(n,t),[n.splice(0,0,re(ze(e.$importChildren(t)),t))]},match:te.tag("ol","ul"),name:"@lexical/list/list"});function je(e,t){if(1!==t.length)return t;const n=t[0];return L(n)&&!e.getFormatType()&&n.getFormatType()?(e.setFormat(n.getFormatType()),n.getChildren()):t}function Xe(e){const t=e=>ie(e)&&!Ee(e);if(!e.some(t))return e;const n=[];let r=[];const i=()=>{r.length>0&&(n.push(r),r=[])};for(const s of e)t(s)?(i(),n.push(f(s)?s.getChildren():[s])):r.push(s);i();const s=[];for(const e of n)s.length>0&&s.push(G()),s.push(...e);return s}const Ge=ee({$import:(e,t)=>{const n=t.getAttribute("aria-checked"),r=Se("true"===n||"false"!==n&&void 0);return N(r,t),F(r,t),[r.splice(0,0,Xe(je(r,e.$importChildren(t))))]},match:te.tag("li"),name:"@lexical/list/li"});function Qe(e,t,n){const r=ne(n,"input")?n:n.querySelector('input[type="checkbox"]');if(!r||"checkbox"!==r.getAttribute("type"))return[];const i=Se(r.hasAttribute("checked"));return N(i,t),F(i,t),[i.splice(0,0,Xe(je(i,e.$importChildren(t))))]}const Ye={$accepts:e=>xe(e)||Ee(e),$packageRun:e=>[Se().splice(0,0,e)],name:"ListSchema"},Ze=[ee({$import:(e,t,n)=>{const r=t.querySelector(':scope > input[type="checkbox"]');return r?Qe(e,t,r):n()},match:te.tag("li").classAll("task-list-item"),name:"@lexical/list/li-task-list-item"}),ee({$import:(e,t,n)=>{const r=t.querySelector(":scope > .checkbox-wrapper");if(!r)return n();const i=r.querySelector(':scope > input[type="checkbox"]');return i?Qe(e,t,i):n()},match:te.tag("li").classAll("joplin-checkbox"),name:"@lexical/list/li-joplin-checkbox"}),He,Ge],et=H({dependencies:[Ve,X(Z,{rules:Ze})],name:"@lexical/list/Import"});function tt(e,t){e.update(()=>he(t))}function nt(e){e.update(()=>pe())}export{Se as $createListItemNode,Ae as $createListNode,oe as $getListDepth,Ce as $handleListInsertParagraph,he as $insertList,xe as $isListItemNode,Ee as $isListNode,pe as $removeList,qe as CheckListExtension,Oe as INSERT_CHECK_LIST_COMMAND,Be as INSERT_ORDERED_LIST_COMMAND,Ke as INSERT_UNORDERED_LIST_COMMAND,Ve as ListExtension,et as ListImportExtension,Ze as ListImportRules,ve as ListItemNode,Le as ListNode,Ye as ListSchema,We as REMOVE_LIST_COMMAND,Re as UPDATE_LIST_START_COMMAND,tt as insertList,Ie as registerCheckList,Ue as registerList,Je as registerListStrictIndentTransform,nt as removeList};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export interface ListConfig {
|
|
9
|
+
/**
|
|
10
|
+
* When `true`, enforces strict indentation rules for list items, ensuring consistent structure.
|
|
11
|
+
* When `false` (default), indentation is more flexible.
|
|
12
|
+
*/
|
|
13
|
+
hasStrictIndent: boolean;
|
|
14
|
+
shouldPreserveNumbering: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configures {@link ListNode}, {@link ListItemNode} and registers
|
|
18
|
+
* the strict indent transform if `hasStrictIndent` is true (default false).
|
|
19
|
+
*/
|
|
20
|
+
export declare const ListExtension: import("lexical").LexicalExtension<ListConfig, "@lexical/list/List", import("@lexical/extension").NamedSignalsOutput<ListConfig>, unknown>;
|
|
21
|
+
export interface CheckListConfig {
|
|
22
|
+
disableTakeFocusOnClick: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Registers checklist functionality for {@link ListNode} and
|
|
26
|
+
* {@link ListItemNode} with a `INSERT_CHECK_LIST_COMMAND` listener and
|
|
27
|
+
* the expected keyboard and mouse interactions for checkboxes.
|
|
28
|
+
*/
|
|
29
|
+
export declare const CheckListExtension: import("lexical").LexicalExtension<CheckListConfig, "@lexical/list/CheckList", import("@lexical/extension").NamedSignalsOutput<CheckListConfig>, unknown>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { ChildSchema } from '@lexical/html';
|
|
9
|
+
/**
|
|
10
|
+
* A {@link ChildSchema} that enforces ListNode invariants: only
|
|
11
|
+
* `ListItemNode` and (immediately-nested) `ListNode` children are
|
|
12
|
+
* accepted; runs of other children get wrapped in a fresh
|
|
13
|
+
* `ListItemNode`.
|
|
14
|
+
*
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
export declare const ListSchema: ChildSchema;
|
|
18
|
+
/**
|
|
19
|
+
* Import rules for {@link ListNode} and {@link ListItemNode}, including
|
|
20
|
+
* GitHub task-list and Joplin checkbox heuristics.
|
|
21
|
+
*
|
|
22
|
+
* @experimental
|
|
23
|
+
*/
|
|
24
|
+
export declare const ListImportRules: (import("@lexical/html").DOMImportRule<import("@lexical/html").ElementSelectorBuilder<HTMLOListElement | HTMLUListElement, Record<string, never>>> | import("@lexical/html").DOMImportRule<import("@lexical/html").ElementSelectorBuilder<HTMLLIElement, Record<string, never>>>)[];
|
|
25
|
+
/**
|
|
26
|
+
* Bundles {@link ListImportRules} together with the runtime
|
|
27
|
+
* {@link ListExtension}. The application is expected to already have
|
|
28
|
+
* `CoreImportExtension` (or some equivalent) in its dependency graph —
|
|
29
|
+
* the core/text/paragraph/inline-format rules are a shared baseline,
|
|
30
|
+
* not something this leaf importer should re-declare.
|
|
31
|
+
*
|
|
32
|
+
* @experimental
|
|
33
|
+
*/
|
|
34
|
+
export declare const ListImportExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/list/Import", unknown, unknown>;
|