@gravity-ui/markdown-editor 15.2.1 → 15.3.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/README.md +6 -6
- package/build/cjs/extensions/additional/YfmHtmlBlock/utils.d.ts +1 -1
- package/build/cjs/extensions/additional/YfmHtmlBlock/utils.js +13 -2
- package/build/cjs/extensions/additional/YfmHtmlBlock/utils.js.map +1 -1
- package/build/cjs/extensions/base/BaseSchema/BaseSchemaSpecs/index.js +2 -12
- package/build/cjs/extensions/base/BaseSchema/BaseSchemaSpecs/index.js.map +1 -1
- package/build/cjs/extensions/behavior/Clipboard/clipboard.js +8 -0
- package/build/cjs/extensions/behavior/Clipboard/clipboard.js.map +1 -1
- package/build/cjs/extensions/behavior/Clipboard/utils.d.ts +3 -0
- package/build/cjs/extensions/behavior/Clipboard/utils.js +45 -0
- package/build/cjs/extensions/behavior/Clipboard/utils.js.map +1 -1
- package/build/cjs/extensions/markdown/Lists/index.js +2 -0
- package/build/cjs/extensions/markdown/Lists/index.js.map +1 -1
- package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.d.ts +4 -0
- package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.js +76 -0
- package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.js.map +1 -0
- package/build/cjs/extensions/yfm/Color/ColorSpecs/index.js +2 -2
- package/build/cjs/extensions/yfm/Color/ColorSpecs/index.js.map +1 -1
- package/build/cjs/markdown-it/color.d.ts +2 -2
- package/build/cjs/markdown-it/color.js +2 -3
- package/build/cjs/markdown-it/color.js.map +1 -1
- package/build/cjs/utils/nodes.d.ts +1 -0
- package/build/cjs/utils/nodes.js +13 -1
- package/build/cjs/utils/nodes.js.map +1 -1
- package/build/cjs/version.js +1 -1
- package/build/cjs/version.js.map +1 -1
- package/build/esm/extensions/additional/YfmHtmlBlock/utils.d.ts +1 -1
- package/build/esm/extensions/additional/YfmHtmlBlock/utils.js +12 -1
- package/build/esm/extensions/additional/YfmHtmlBlock/utils.js.map +1 -1
- package/build/esm/extensions/base/BaseSchema/BaseSchemaSpecs/index.js +1 -11
- package/build/esm/extensions/base/BaseSchema/BaseSchemaSpecs/index.js.map +1 -1
- package/build/esm/extensions/behavior/Clipboard/clipboard.js +9 -1
- package/build/esm/extensions/behavior/Clipboard/clipboard.js.map +1 -1
- package/build/esm/extensions/behavior/Clipboard/utils.d.ts +3 -0
- package/build/esm/extensions/behavior/Clipboard/utils.js +43 -0
- package/build/esm/extensions/behavior/Clipboard/utils.js.map +1 -1
- package/build/esm/extensions/markdown/Lists/index.js +2 -0
- package/build/esm/extensions/markdown/Lists/index.js.map +1 -1
- package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.d.ts +4 -0
- package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.js +71 -0
- package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.js.map +1 -0
- package/build/esm/extensions/yfm/Color/ColorSpecs/index.js +1 -1
- package/build/esm/extensions/yfm/Color/ColorSpecs/index.js.map +1 -1
- package/build/esm/markdown-it/color.d.ts +2 -2
- package/build/esm/markdown-it/color.js +2 -2
- package/build/esm/markdown-it/color.js.map +1 -1
- package/build/esm/utils/nodes.d.ts +1 -0
- package/build/esm/utils/nodes.js +11 -0
- package/build/esm/utils/nodes.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Fragment } from 'prosemirror-model';
|
|
2
|
+
import { Plugin, TextSelection } from 'prosemirror-state';
|
|
3
|
+
// @ts-ignore // TODO: fix cjs build
|
|
4
|
+
import { findChildren, hasParentNode } from 'prosemirror-utils';
|
|
5
|
+
import { getChildrenOfNode } from "../../../../utils/index.js";
|
|
6
|
+
import { isListItemNode, isListNode, liType } from "../utils.js";
|
|
7
|
+
export const collapseListsPlugin = () => new Plugin({
|
|
8
|
+
appendTransaction(trs, oldState, newState) {
|
|
9
|
+
const docChanged = trs.some((tr) => tr.docChanged);
|
|
10
|
+
if (!docChanged)
|
|
11
|
+
return null;
|
|
12
|
+
const hasParentList = hasParentNode(isListNode)(newState.selection) ||
|
|
13
|
+
hasParentNode(isListNode)(oldState.selection);
|
|
14
|
+
if (!hasParentList)
|
|
15
|
+
return null;
|
|
16
|
+
const { tr } = newState;
|
|
17
|
+
let prevStepsCount = -1;
|
|
18
|
+
let currentStepsCount = 0;
|
|
19
|
+
// execute until there are no nested lists.
|
|
20
|
+
while (prevStepsCount !== currentStepsCount) {
|
|
21
|
+
const listNodes = findChildren(tr.doc, isListNode, true);
|
|
22
|
+
prevStepsCount = currentStepsCount;
|
|
23
|
+
currentStepsCount = collapseEmptyListItems(tr, listNodes);
|
|
24
|
+
}
|
|
25
|
+
return tr.docChanged ? tr : null;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
export function collapseEmptyListItems(tr, nodes) {
|
|
29
|
+
const stepsCountBefore = tr.steps.length;
|
|
30
|
+
// TODO: fix cjs build
|
|
31
|
+
nodes.reverse().forEach((list) => {
|
|
32
|
+
const listNode = list.node;
|
|
33
|
+
const listPos = list.pos;
|
|
34
|
+
const childrenOfList = getChildrenOfNode(listNode).reverse();
|
|
35
|
+
childrenOfList.forEach(({ node: itemNode, offset }) => {
|
|
36
|
+
if (isListItemNode(itemNode)) {
|
|
37
|
+
const { firstChild } = itemNode;
|
|
38
|
+
const listItemNodePos = listPos + 1 + offset;
|
|
39
|
+
// if the first child of a list element is a list,
|
|
40
|
+
// then collapse is required
|
|
41
|
+
if (firstChild && isListNode(firstChild)) {
|
|
42
|
+
const nestedList = firstChild.content;
|
|
43
|
+
// nodes at the same level as the list
|
|
44
|
+
const remainingNodes = itemNode.content.content.slice(1);
|
|
45
|
+
const listItems = remainingNodes.length
|
|
46
|
+
? nestedList.append(Fragment.from(liType(tr.doc.type.schema).create(null, remainingNodes)))
|
|
47
|
+
: nestedList;
|
|
48
|
+
const mappedStart = tr.mapping.map(listItemNodePos);
|
|
49
|
+
const mappedEnd = tr.mapping.map(listItemNodePos + itemNode.nodeSize);
|
|
50
|
+
tr.replaceWith(mappedStart, mappedEnd, listItems);
|
|
51
|
+
const closestTextNodePos = findClosestTextNodePos(tr.doc, mappedStart + nestedList.size);
|
|
52
|
+
if (closestTextNodePos) {
|
|
53
|
+
tr.setSelection(TextSelection.create(tr.doc, closestTextNodePos));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
return tr.steps.length - stepsCountBefore;
|
|
60
|
+
}
|
|
61
|
+
function findClosestTextNodePos(doc, pos) {
|
|
62
|
+
while (pos < doc.content.size) {
|
|
63
|
+
const node = doc.nodeAt(pos);
|
|
64
|
+
if (node && node.isText) {
|
|
65
|
+
return pos;
|
|
66
|
+
}
|
|
67
|
+
pos++;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=CollapseListsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollapseListsPlugin.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/Lists/plugins/CollapseListsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAY,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,MAAM,EAAE,aAAa,EAAmB,MAAM,mBAAmB,CAAC;AAC1E,oCAAoC;AACpC,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAC,iBAAiB,EAAC,mCAA0B;AACpD,OAAO,EAAC,cAAc,EAAE,UAAU,EAAE,MAAM,EAAC,oBAAiB;AAE5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,CACpC,IAAI,MAAM,CAAC;IACP,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ;QACrC,MAA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AAG,EAAE,kBAAkB,CAAC,CAAC,CAAC;oBACtE,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,gBAAgB,CAAC;AAC9C,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAS,EAAE,GAAW;IAClD,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACtB,OAAO,GAAG,CAAC;QACf,CAAC;QACD,GAAG,EAAE,CAAC;IACV,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import {Fragment, type Node} from 'prosemirror-model';\nimport {Plugin, TextSelection, type Transaction} from 'prosemirror-state';\n// @ts-ignore // TODO: fix cjs build\nimport {findChildren, hasParentNode} from 'prosemirror-utils';\n\nimport {getChildrenOfNode} from '../../../../utils';\nimport {isListItemNode, isListNode, liType} from '../utils';\n\nexport const collapseListsPlugin = () =>\n new Plugin({\n appendTransaction(trs, oldState, newState) {\n const docChanged = trs.some((tr) => tr.docChanged);\n if (!docChanged) return null;\n\n const hasParentList =\n hasParentNode(isListNode)(newState.selection) ||\n hasParentNode(isListNode)(oldState.selection);\n if (!hasParentList) return null;\n\n const {tr} = newState;\n let prevStepsCount = -1;\n let currentStepsCount = 0;\n\n // execute until there are no nested lists.\n while (prevStepsCount !== currentStepsCount) {\n const listNodes = findChildren(tr.doc, isListNode, true);\n prevStepsCount = currentStepsCount;\n currentStepsCount = collapseEmptyListItems(tr, listNodes);\n }\n\n return tr.docChanged ? tr : null;\n },\n });\n\nexport function collapseEmptyListItems(\n tr: Transaction,\n nodes: ReturnType<typeof findChildren>,\n): number {\n const stepsCountBefore = tr.steps.length;\n // TODO: fix cjs build\n nodes.reverse().forEach((list: {node: Node; pos: number}) => {\n const listNode = list.node;\n const listPos = list.pos;\n const childrenOfList = getChildrenOfNode(listNode).reverse();\n\n childrenOfList.forEach(({node: itemNode, offset}) => {\n if (isListItemNode(itemNode)) {\n const {firstChild} = itemNode;\n const listItemNodePos = listPos + 1 + offset;\n\n // if the first child of a list element is a list,\n // then collapse is required\n if (firstChild && isListNode(firstChild)) {\n const nestedList = firstChild.content;\n\n // nodes at the same level as the list\n const remainingNodes = itemNode.content.content.slice(1);\n\n const listItems = remainingNodes.length\n ? nestedList.append(\n Fragment.from(\n liType(tr.doc.type.schema).create(null, remainingNodes),\n ),\n )\n : nestedList;\n\n const mappedStart = tr.mapping.map(listItemNodePos);\n const mappedEnd = tr.mapping.map(listItemNodePos + itemNode.nodeSize);\n\n tr.replaceWith(mappedStart, mappedEnd, listItems);\n\n const closestTextNodePos = findClosestTextNodePos(\n tr.doc,\n mappedStart + nestedList.size,\n );\n if (closestTextNodePos) {\n tr.setSelection(TextSelection.create(tr.doc, closestTextNodePos));\n }\n }\n }\n });\n });\n\n return tr.steps.length - stepsCountBefore;\n}\n\nfunction findClosestTextNodePos(doc: Node, pos: number): number | null {\n while (pos < doc.content.size) {\n const node = doc.nodeAt(pos);\n if (node && node.isText) {\n return pos;\n }\n pos++;\n }\n return null;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import mdPlugin from
|
|
1
|
+
import mdPlugin from "../../../../markdown-it/color.js";
|
|
2
2
|
import { markTypeFactory } from "../../../../utils/schema.js";
|
|
3
3
|
import { colorClassName, colorMarkName, domColorAttr } from "./const.js";
|
|
4
4
|
export { colorMarkName } from "./const.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/Color/ColorSpecs/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../../src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ACD,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,IAAI;YACb,wBAAwB,EAAE,IAAI;SACjC;KACJ,CAAC,CAAC,CAAC;AACZ,CAAC,CAAC","sourcesContent":["import mdPlugin from 'src/markdown-it/color';\n\nimport type {ExtensionAuto} from '../../../../core';\nimport {markTypeFactory} from '../../../../utils/schema';\n\nimport {colorClassName, colorMarkName, domColorAttr} from './const';\n\nexport {colorMarkName} from './const';\nexport const colorType = markTypeFactory(colorMarkName);\n\nfunction getColorName(className: string) {\n const regexp = /^(yfm|md)-colorify--(\\w+)$/;\n return className.match(regexp)?.[2];\n}\n\nexport type ColorSpecsOptions = {\n validateClassNameColorName?: (colorName: string) => boolean;\n parseStyleColorValue?: (color: string) => string | null;\n};\n\nexport const ColorSpecs: ExtensionAuto<ColorSpecsOptions> = (builder, opts) => {\n const {validateClassNameColorName, parseStyleColorValue} = opts;\n\n builder\n .configureMd((md) => md.use(mdPlugin, {defaultClassName: colorClassName, inline: false}))\n .addMark(colorMarkName, () => ({\n spec: {\n attrs: {[colorMarkName]: {}},\n parseDOM: [\n {\n tag: `span`,\n preserveWhitespace: false,\n getAttrs(node) {\n if (typeof node === 'string') return false;\n\n for (const className of Array.from(node.classList)) {\n const color = getColorName(className);\n if (color && (validateClassNameColorName?.(color) ?? true)) {\n return {\n [colorMarkName]: color,\n };\n }\n }\n\n return false;\n },\n },\n {\n style: 'color',\n preserveWhitespace: false,\n getAttrs(node) {\n if (typeof node !== 'string') return false;\n\n const color = parseStyleColorValue?.(node);\n if (color) {\n return {\n [colorMarkName]: color,\n };\n }\n\n return false;\n },\n },\n ],\n toDOM(node) {\n const colorValue = node.attrs[colorMarkName];\n\n return [\n 'span',\n {\n class: [colorClassName, `${colorClassName}--${colorValue}`].join(' '),\n [domColorAttr]: colorValue,\n },\n 0,\n ];\n },\n },\n fromMd: {\n tokenSpec: {\n name: colorMarkName,\n type: 'mark',\n getAttrs(token) {\n return {\n [colorMarkName]: token.info,\n };\n },\n },\n },\n toMd: {\n open: (_state, mark) => {\n return `{${mark.attrs[colorMarkName]}}(`;\n },\n close: ')',\n mixable: true,\n expelEnclosingWhitespace: true,\n },\n }));\n};\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default
|
|
1
|
+
import { colorPlugin } from 'markdown-it-color';
|
|
2
|
+
export default colorPlugin;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default
|
|
1
|
+
import { colorPlugin } from 'markdown-it-color';
|
|
2
|
+
export default colorPlugin;
|
|
3
3
|
//# sourceMappingURL=color.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.js","sourceRoot":"../../../src","sources":["markdown-it/color.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"../../../src","sources":["markdown-it/color.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAE9C,eAAe,WAAW,CAAC","sourcesContent":["import {colorPlugin} from 'markdown-it-color';\n\nexport default colorPlugin;\n"]}
|
package/build/esm/utils/nodes.js
CHANGED
|
@@ -45,4 +45,15 @@ export function getLastChildOfNode(node) {
|
|
|
45
45
|
const children = getChildrenOfNode(node);
|
|
46
46
|
return children[children.length - 1];
|
|
47
47
|
}
|
|
48
|
+
export const isEmptyString = (node) => {
|
|
49
|
+
if (node.type.name === 'paragraph' && !node.content.size) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (node.childCount === 1 &&
|
|
53
|
+
node.child(0).type.name === 'text' &&
|
|
54
|
+
node.child(0).text?.trim() === '') {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
48
59
|
//# sourceMappingURL=nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.js","sourceRoot":"../../../src","sources":["utils/nodes.ts"],"names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AAC;IAEH,OAAO,aAAa,CAAC,MAAM,KAAK,gBAAgB,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE;IAC3C,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACtD,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACzE,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,IAAU;IAClC,OAAO,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5D,CAAC;AAGD,MAAM,UAAU,iBAAiB,CAAC,IAAqB;IACnD,MAAM,QAAQ,GAAgB,EAAE,CAAC;IACjC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAC,CAAC,CAAC,CAAC;IAC5E,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAqB;IACpD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import {type Fragment, Node} from 'prosemirror-model';\n// @ts-ignore // TODO: fix cjs build\nimport {findChildren} from 'prosemirror-utils';\n\nexport function findFirstTextblockChild(\n parent: Node | Fragment,\n): {node: Node; offset: number} | null {\n if (parent instanceof Node && (!parent.isBlock || parent.isAtom)) return null;\n\n for (const child of getChildrenOfNode(parent)) {\n if (child.node.isTextblock) return child;\n const nestedTextBlockChild = findFirstTextblockChild(child.node);\n if (nestedTextBlockChild) {\n return {\n node: nestedTextBlockChild.node,\n offset: child.offset + nestedTextBlockChild.offset,\n };\n }\n }\n\n return null;\n}\n\nexport const isNodeEmpty = (node: Node) => {\n const emptyChildren = findChildren(\n node,\n (n: Node) =>\n (!n.isText && !n.isAtom && n.content.size === 0 && n.type.name === 'paragraph') ||\n (n.isText && !n.textContent),\n true,\n );\n\n let descendantsCount = 0;\n\n node.descendants(() => {\n descendantsCount++;\n });\n\n return emptyChildren.length === descendantsCount;\n};\n\nexport const isSelectableNode = (node: Node) => {\n if (node.type.spec.selectable === false) return false;\n if (node.type.isText && node.type.spec.selectable !== true) return false;\n return true;\n};\n\nexport function isCodeBlock(node: Node): boolean {\n return node.isTextblock && Boolean(node.type.spec.code);\n}\n\nexport type NodeChild = {node: Node; offset: number; index: number};\nexport function getChildrenOfNode(node: Node | Fragment): NodeChild[] {\n const children: NodeChild[] = [];\n node.forEach((node, offset, index) => children.push({node, offset, index}));\n return children;\n}\n\nexport function getLastChildOfNode(node: Node | Fragment): NodeChild {\n const children = getChildrenOfNode(node);\n return children[children.length - 1];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"../../../src","sources":["utils/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,IAAI,EAAC,MAAM,mBAAmB,CAAC;AACtD,oCAAoC;AACpC,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,MAAM,UAAU,uBAAuB,CACnC,MAAuB;IAEvB,IAAI,MAAM,YAAY,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IAE9E,KAAK,MAAM,KAAK,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW;YAAE,OAAO,KAAK,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AAC,IAAU;IAClC,OAAO,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5D,CAAC;AAGD,MAAM,UAAU,iBAAiB,CAAC,IAAqB;IACnD,MAAM,QAAQ,GAAgB,EAAE,CAAC;IACjC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAC,CAAC,CAAC,CAAC;IAC5E,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAqB;IACpD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAU,EAAE,EAAE;IACxC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IACI,IAAI,CAAC,UAAU,KAAK,CAAC;QACrB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM;QAClC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EACnC,CAAC;QACC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {type Fragment, Node} from 'prosemirror-model';\n// @ts-ignore // TODO: fix cjs build\nimport {findChildren} from 'prosemirror-utils';\n\nexport function findFirstTextblockChild(\n parent: Node | Fragment,\n): {node: Node; offset: number} | null {\n if (parent instanceof Node && (!parent.isBlock || parent.isAtom)) return null;\n\n for (const child of getChildrenOfNode(parent)) {\n if (child.node.isTextblock) return child;\n const nestedTextBlockChild = findFirstTextblockChild(child.node);\n if (nestedTextBlockChild) {\n return {\n node: nestedTextBlockChild.node,\n offset: child.offset + nestedTextBlockChild.offset,\n };\n }\n }\n\n return null;\n}\n\nexport const isNodeEmpty = (node: Node) => {\n const emptyChildren = findChildren(\n node,\n (n: Node) =>\n (!n.isText && !n.isAtom && n.content.size === 0 && n.type.name === 'paragraph') ||\n (n.isText && !n.textContent),\n true,\n );\n\n let descendantsCount = 0;\n\n node.descendants(() => {\n descendantsCount++;\n });\n\n return emptyChildren.length === descendantsCount;\n};\n\nexport const isSelectableNode = (node: Node) => {\n if (node.type.spec.selectable === false) return false;\n if (node.type.isText && node.type.spec.selectable !== true) return false;\n return true;\n};\n\nexport function isCodeBlock(node: Node): boolean {\n return node.isTextblock && Boolean(node.type.spec.code);\n}\n\nexport type NodeChild = {node: Node; offset: number; index: number};\nexport function getChildrenOfNode(node: Node | Fragment): NodeChild[] {\n const children: NodeChild[] = [];\n node.forEach((node, offset, index) => children.push({node, offset, index}));\n return children;\n}\n\nexport function getLastChildOfNode(node: Node | Fragment): NodeChild {\n const children = getChildrenOfNode(node);\n return children[children.length - 1];\n}\n\nexport const isEmptyString = (node: Node) => {\n if (node.type.name === 'paragraph' && !node.content.size) {\n return true;\n }\n\n if (\n node.childCount === 1 &&\n node.child(0).type.name === 'text' &&\n node.child(0).text?.trim() === ''\n ) {\n return true;\n }\n\n return false;\n};\n"]}
|
package/build/esm/version.js
CHANGED
package/build/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"../../src","sources":["version.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC","sourcesContent":["/** During build process, the current version will be injected here */\nexport const VERSION = typeof '15.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"../../src","sources":["version.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC","sourcesContent":["/** During build process, the current version will be injected here */\nexport const VERSION = typeof '15.3.0' !== 'undefined' ? '15.3.0' : 'unknown';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/markdown-editor",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.3.0",
|
|
4
4
|
"description": "Markdown wysiwyg and markup editor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -216,7 +216,7 @@
|
|
|
216
216
|
"@diplodoc/tabs-extension": "^3.5.1",
|
|
217
217
|
"@diplodoc/transform": "^4.43.0",
|
|
218
218
|
"@gravity-ui/eslint-config": "3.3.0",
|
|
219
|
-
"@gravity-ui/gulp-utils": "1.0.
|
|
219
|
+
"@gravity-ui/gulp-utils": "1.0.3",
|
|
220
220
|
"@gravity-ui/prettier-config": "1.1.0",
|
|
221
221
|
"@gravity-ui/stylelint-config": "4.0.1",
|
|
222
222
|
"@gravity-ui/tsconfig": "1.0.0",
|