@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/Color/ColorSpecs/index.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/Color/ColorSpecs/index.ts"],"names":[],"mappings":";;;;AAAA,qFAA6C;AAG7C,wDAAyD;AAEzD,sCAAoE;AAEpE,oCAAsC;AAA9B,sGAAA,aAAa,OAAA;AACR,QAAA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,KAAK;oBACzB,QAAQ,CAAC,IAAI;wBACT,IAAI,OAAO,IAAI,KAAK,QAAQ;4BAAE,OAAO,KAAK,CAAC;wBAE3C,MAAM,KAAK,GAAG,oBAAoB,EAAE,CAAC,IAAI,CAAC,CAAC;wBAC3C,IAAI,KAAK,EAAE,CAAC;4BACR,OAAO;gCACH,CAAC,qBAAa,CAAC,EAAE,KAAK;6BACzB,CAAC;wBACN,CAAC;wBAED,OAAO,KAAK,CAAC;oBACjB,CAAC;iBACJ;aACJ;YACD,KAAK,CAAC,IAAI;gBACN,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAa,CAAC,CAAC;gBAE7C,OAAO;oBACH,MAAM;oBACN;wBACI,KAAK,EAAE,CAAC,sBAAc,EAAE,GAAG,sBAAc,KAAK,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;wBACrE,CAAC,oBAAY,CAAC,EAAE,UAAU;qBAC7B;oBACD,CAAC;iBACJ,CAAC;YACN,CAAC;SACJ;QACD,MAAM,EAAE;YACJ,SAAS,EAAE;gBACP,IAAI,EAAE,qBAAa;gBACnB,IAAI,EAAE,MAAM;gBACZ,QAAQ,CAAC,KAAK;oBACV,OAAO;wBACH,CAAC,qBAAa,CAAC,EAAE,KAAK,CAAC,IAAI;qBAC9B,CAAC;gBACN,CAAC;aACJ;SACJ;QACD,IAAI,EAAE;YACF,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;gBACnB,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,qBAAa,CAAC,IAAI,CAAC;YAC7C,CAAC;YACD,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,IAAI;YACb,wBAAwB,EAAE,IAAI;SACjC;KACJ,CAAC,CAAC,CAAC;AACZ,CAAC,CAAC;AA7EW,QAAA,UAAU,cA6ErB","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,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
exports.default = markdown_it_color_1.default;
|
|
3
|
+
const markdown_it_color_1 = require("markdown-it-color");
|
|
4
|
+
exports.default = markdown_it_color_1.colorPlugin;
|
|
6
5
|
//# sourceMappingURL=color.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.js","sourceRoot":"../../../src","sources":["markdown-it/color.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"../../../src","sources":["markdown-it/color.ts"],"names":[],"mappings":";;AAAA,yDAA8C;AAE9C,kBAAe,+BAAW,CAAC","sourcesContent":["import {colorPlugin} from 'markdown-it-color';\n\nexport default colorPlugin;\n"]}
|
package/build/cjs/utils/nodes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSelectableNode = exports.isNodeEmpty = void 0;
|
|
3
|
+
exports.isEmptyString = exports.isSelectableNode = exports.isNodeEmpty = void 0;
|
|
4
4
|
exports.findFirstTextblockChild = findFirstTextblockChild;
|
|
5
5
|
exports.isCodeBlock = isCodeBlock;
|
|
6
6
|
exports.getChildrenOfNode = getChildrenOfNode;
|
|
@@ -54,4 +54,16 @@ function getLastChildOfNode(node) {
|
|
|
54
54
|
const children = getChildrenOfNode(node);
|
|
55
55
|
return children[children.length - 1];
|
|
56
56
|
}
|
|
57
|
+
const isEmptyString = (node) => {
|
|
58
|
+
if (node.type.name === 'paragraph' && !node.content.size) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (node.childCount === 1 &&
|
|
62
|
+
node.child(0).type.name === 'text' &&
|
|
63
|
+
node.child(0).text?.trim() === '') {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
exports.isEmptyString = isEmptyString;
|
|
57
69
|
//# sourceMappingURL=nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.js","sourceRoot":"../../../src","sources":["utils/nodes.ts"],"names":[],"mappings":";;;AAIA,0DAiBC;AA0BD,kCAEC;AAGD,8CAIC;AAED,gDAGC;AA7DD,yDAAsD;AACtD,oCAAoC;AACpC,yDAA+C;AAE/C,SAAgB,uBAAuB,CACnC,MAAuB;IAEvB,IAAI,MAAM,YAAY,wBAAI,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,CAAC;QACzC,MAAM,oBAAoB,GAAG,uBAAuB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjE,IAAI,oBAAoB,EAAE,CAAC;YACvB,OAAO;gBACH,IAAI,EAAE,oBAAoB,CAAC,IAAI;gBAC/B,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,oBAAoB,CAAC,MAAM;aACrD,CAAC;QACN,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAEM,MAAM,WAAW,GAAG,CAAC,IAAU,EAAE,EAAE;IACtC,MAAM,aAAa,GAAG,IAAA,gCAAY,EAC9B,IAAI,EACJ,CAAC,CAAO,EAAE,EAAE,CACR,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC;QAC/E,CAAC,CAAC,CAAC,MAAM,IAAI,C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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":";;;AAIA,0DAiBC;AA0BD,kCAEC;AAGD,8CAIC;AAED,gDAGC;AA7DD,yDAAsD;AACtD,oCAAoC;AACpC,yDAA+C;AAE/C,SAAgB,uBAAuB,CACnC,MAAuB;IAEvB,IAAI,MAAM,YAAY,wBAAI,IAAI,CAAC,CAAC,MAAM,CAAC,O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AC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAdW,QAAA,aAAa,iBAcxB","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/cjs/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
/** During build process, the current version will be injected here */
|
|
5
|
-
exports.VERSION = typeof '15.
|
|
5
|
+
exports.VERSION = typeof '15.3.0' !== 'undefined' ? '15.3.0' : 'unknown';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
package/build/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"../../src","sources":["version.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACzD,QAAA,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;AACzD,QAAA,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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SanitizeOptions } from '@diplodoc/transform/lib/sanitize.js';
|
|
2
2
|
export declare const getYfmHtmlBlockOptions: (defaultOptions: SanitizeOptions) => SanitizeOptions;
|
|
3
3
|
export interface GetSanitizeYfmHtmlBlockArgs {
|
|
4
4
|
options: SanitizeOptions;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as sanitizeModule from '@diplodoc/transform/lib/sanitize.js';
|
|
2
|
+
const sanitizeAll = () => {
|
|
3
|
+
console.warn('[YfmHtmlBlock]: sanitize function not found');
|
|
4
|
+
return '';
|
|
5
|
+
};
|
|
6
|
+
const getSanitizeFunction = () => {
|
|
7
|
+
const module = sanitizeModule;
|
|
8
|
+
const sanitize = 'sanitize' in module && module.sanitize ? module.sanitize : module.default;
|
|
9
|
+
return sanitize instanceof Function ? sanitize : sanitizeAll;
|
|
10
|
+
};
|
|
11
|
+
// MAJOR: use `import {sanitize} from '@diplodoc/transform/lib/sanitize.js'`
|
|
12
|
+
const diplodocSanitize = getSanitizeFunction();
|
|
2
13
|
// yfmHtmlBlock additional css properties white list
|
|
3
14
|
const getYfmHtmlBlockWhiteList = () => {
|
|
4
15
|
const whiteList = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"../../../../../src","sources":["extensions/additional/YfmHtmlBlock/utils.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,EAAE,EAAsB,MAAM,qCAAqC,CAAC;AAE3F,oDAAoD;AACpD,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAClC,MAAM,SAAS,GAA4B,EAAE,CAAC;IAE9C,qBAAqB;IACrB,SAAS,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,CAAC,gBAAgB;IACnD,SAAS,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC,gBAAgB;IACjD,SAAS,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC,gBAAgB;IAChD,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,8CAA8C;IACxE,SAAS,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC,gBAAgB;IAClD,SAAS,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC,mBAAmB;IACpD,SAAS,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC,kBAAkB;IAClD,SAAS,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC,8CAA8C;IAC/E,SAAS,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,CAAC,yBAAyB;IAChE,SAAS,CAAC,mBAA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c,CAAC,iBAA0C,CAAC;IAE3F,OAAO;QACH,GAAG,cAAc;QACjB,iBAAiB,EAAE;YACf,GAAG,wBAAwB;YAC3B,GAAG,6BAA6B;SACnC;QACD,WAAW,EACP,OAAO,cAAc,CAAC,WAAW,KAAK,SAAS;YAC3C,CAAC,CAAC,cAAc,CAAC,WAAW;YAC5B,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,GAAG,uBAAuB,CAAC;QAC7E,YAAY,EAAE;YACV,GAAG,cAAc,CAAC,YAAY;YAC9B,GAAG,wBAAwB,EAAE;SAChC;KACJ,CAAC;AACN,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,uBAAuB,GAChC,CAAC,EAAC,OAAO,EAAE,QAAQ,GAAG,gBAAgB,EAA8B,EAAE,EAAE,CACxE,CAAC,OAAe,EAAE,EAAE,CAChB,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC","sourcesContent":["import diplodocSanitize, {type SanitizeOptions} from '@diplodoc/transform/lib/sanitize.js';\n\n// yfmHtmlBlock additional css properties white list\nconst getYfmHtmlBlockWhiteList = () => {\n const whiteList: Record<string, boolean> = {};\n\n // flex, grid, column\n whiteList['align-content'] = true; // default: auto\n whiteList['align-items'] = true; // default: auto\n whiteList['align-self'] = true; // default: auto\n whiteList.columns = true; // default: depending on individual properties\n whiteList['column-count'] = true; // default: auto\n whiteList['column-fill'] = true; // default: balance\n whiteList['column-gap'] = true; // default: normal\n whiteList['column-rule'] = true; // default: depending on individual properties\n whiteList['column-rule-color'] = true; // default: current color\n whiteList['column-rule-style'] = true; // default: medium\n whiteList['column-rule-width'] = true; // default: medium\n whiteList['column-span'] = true; // default: none\n whiteList['column-width'] = true; // default: auto\n whiteList.flex = true; // default: depending on individual properties\n whiteList['flex-basis'] = true; // default: auto\n whiteList['flex-direction'] = true; // default: row\n whiteList['flex-flow'] = true; // default: depending on individual properties\n whiteList['flex-grow'] = true; // default: 0\n whiteList['flex-shrink'] = true; // default: 1\n whiteList['flex-wrap'] = true; // default: nowrap\n whiteList.gap = true; // default: normal normal\n whiteList.grid = true; // default: depending on individual properties\n whiteList['grid-area'] = true; // default: depending on individual properties\n whiteList['grid-auto-columns'] = true; // default: auto\n whiteList['grid-auto-flow'] = true; // default: none\n whiteList['grid-auto-rows'] = true; // default: auto\n whiteList['grid-column'] = true; // default: depending on individual properties\n whiteList['grid-column-end'] = true; // default: auto\n whiteList['grid-column-start'] = true; // default: auto\n whiteList['grid-row'] = true; // default: depending on individual properties\n whiteList['grid-row-end'] = true; // default: auto\n whiteList['grid-row-start'] = true; // default: auto\n whiteList['grid-template'] = true; // default: depending on individual properties\n whiteList['grid-template-areas'] = true; // default: none\n whiteList['grid-template-columns'] = true; // default: none\n whiteList['grid-template-rows'] = true; // default: none\n whiteList['justify-content'] = true; // default: auto\n whiteList['justify-items'] = true; // default: auto\n whiteList['justify-self'] = true; // default: auto\n whiteList['line-height'] = true; // default: normal\n whiteList['object-fit'] = true; // default: fill\n whiteList['object-position'] = true; // default: 50% 50%\n whiteList.order = true; // default: 0\n whiteList.orphans = true; // default: 2\n whiteList['row-gap'] = true;\n\n // position, opacity, overflow\n whiteList['all'] = true; // default: depending on individual properties\n whiteList['bottom'] = true; // default: auto\n whiteList['content'] = true; // default: normal\n whiteList['cursor'] = true; // default: auto\n whiteList['direction'] = true; // default: ltr\n whiteList['left'] = true; // default: auto\n whiteList['line-break'] = true; // default: auto\n whiteList['opacity'] = true; // default: 1\n whiteList['overflow'] = true; // default: depending on individual properties\n whiteList['overflow-wrap'] = true; // default: normal\n whiteList['overflow-x'] = true; // default: visible\n whiteList['overflow-y'] = true; // default: visible\n whiteList['position'] = true; // default: static\n whiteList['right'] = true; // default: auto\n whiteList['top'] = true; // default: auto\n whiteList['white-space'] = true; // default: normal\n whiteList['z-index'] = true; // default: auto\n\n return whiteList;\n};\n\n// yfmHtmlBlock additional allowedTags\nconst yfmHtmlBlockAllowedTags = ['link', 'base', 'style'];\n\n// yfmHtmlBlock additional allowedTags\nconst yfmHtmlBlockAllowedAttributes = {\n link: ['rel', 'href'],\n base: ['target'],\n style: [],\n};\n\nexport const getYfmHtmlBlockOptions = (defaultOptions: SanitizeOptions): SanitizeOptions => {\n type AllowedAttributesType = Record<\n string,\n (string | {name: string; multiple?: boolean | undefined; values: string[]})[]\n >;\n const defaultAllowedAttributes = defaultOptions.allowedAttributes as AllowedAttributesType;\n\n return {\n ...defaultOptions,\n allowedAttributes: {\n ...defaultAllowedAttributes,\n ...yfmHtmlBlockAllowedAttributes,\n },\n allowedTags:\n typeof defaultOptions.allowedTags === 'boolean'\n ? defaultOptions.allowedTags\n : [...(defaultOptions.allowedTags ?? []), ...yfmHtmlBlockAllowedTags],\n cssWhiteList: {\n ...defaultOptions.cssWhiteList,\n ...getYfmHtmlBlockWhiteList(),\n },\n };\n};\n\nexport interface GetSanitizeYfmHtmlBlockArgs {\n options: SanitizeOptions;\n sanitize?: (html: string, options?: SanitizeOptions) => string;\n}\nexport const getSanitizeYfmHtmlBlock =\n ({options, sanitize = diplodocSanitize}: GetSanitizeYfmHtmlBlockArgs) =>\n (content: string) =>\n sanitize(content, getYfmHtmlBlockOptions(options));\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"../../../../../src","sources":["extensions/additional/YfmHtmlBlock/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc,MAAM,qCAAqC,CAAC;AAatE,MAAM,WAAW,GAAG,GAAG,EAAE;IACrB,OAAO,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;IAC5D,OAAO,EAAE,CAAC;AACd,CAAC,CAAC;AACF,MAAM,mBAAmB,GAAG,GAAe,EAAE;IACzC,MAAM,MAAM,GAAG,cAAgC,CAAC;IAChD,MAAM,QAAQ,GAAG,UAAU,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAA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GAAG,cAAc,CAAC,YAAY;YAC9B,GAAG,wBAAwB,EAAE;SAChC;KACJ,CAAC;AACN,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,uBAAuB,GAChC,CAAC,EAAC,OAAO,EAAE,QAAQ,GAAG,gBAAgB,EAA8B,EAAE,EAAE,CACxE,CAAC,OAAe,EAAE,EAAE,CAChB,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC","sourcesContent":["import type {SanitizeOptions} from '@diplodoc/transform/lib/sanitize.js';\nimport * as sanitizeModule from '@diplodoc/transform/lib/sanitize.js';\n\ntype SanitizeFn = (\n html: string,\n options?: SanitizeOptions,\n additionalOptions?: SanitizeOptions,\n) => string;\n\ninterface SanitizeModule {\n sanitize?: SanitizeFn;\n default?: SanitizeFn;\n}\n\nconst sanitizeAll = () => {\n console.warn('[YfmHtmlBlock]: sanitize function not found');\n return '';\n};\nconst getSanitizeFunction = (): SanitizeFn => {\n const module = sanitizeModule as SanitizeModule;\n const sanitize = 'sanitize' in module && module.sanitize ? module.sanitize : module.default;\n return sanitize instanceof Function ? sanitize : sanitizeAll;\n};\n\n// MAJOR: use `import {sanitize} from '@diplodoc/transform/lib/sanitize.js'`\nconst diplodocSanitize = getSanitizeFunction();\n\n// yfmHtmlBlock additional css properties white list\nconst getYfmHtmlBlockWhiteList = () => {\n const whiteList: Record<string, boolean> = {};\n\n // flex, grid, column\n whiteList['align-content'] = true; // default: auto\n whiteList['align-items'] = true; // default: auto\n whiteList['align-self'] = true; // default: auto\n whiteList.columns = true; // default: depending on individual properties\n whiteList['column-count'] = true; // default: auto\n whiteList['column-fill'] = true; // default: balance\n whiteList['column-gap'] = true; // default: normal\n whiteList['column-rule'] = true; // default: depending on individual properties\n whiteList['column-rule-color'] = true; // default: current color\n whiteList['column-rule-style'] = true; // default: medium\n whiteList['column-rule-width'] = true; // default: medium\n whiteList['column-span'] = true; // default: none\n whiteList['column-width'] = true; // default: auto\n whiteList.flex = true; // default: depending on individual properties\n whiteList['flex-basis'] = true; // default: auto\n whiteList['flex-direction'] = true; // default: row\n whiteList['flex-flow'] = true; // default: depending on individual properties\n whiteList['flex-grow'] = true; // default: 0\n whiteList['flex-shrink'] = true; // default: 1\n whiteList['flex-wrap'] = true; // default: nowrap\n whiteList.gap = true; // default: normal normal\n whiteList.grid = true; // default: depending on individual properties\n whiteList['grid-area'] = true; // default: depending on individual properties\n whiteList['grid-auto-columns'] = true; // default: auto\n whiteList['grid-auto-flow'] = true; // default: none\n whiteList['grid-auto-rows'] = true; // default: auto\n whiteList['grid-column'] = true; // default: depending on individual properties\n whiteList['grid-column-end'] = true; // default: auto\n whiteList['grid-column-start'] = true; // default: auto\n whiteList['grid-row'] = true; // default: depending on individual properties\n whiteList['grid-row-end'] = true; // default: auto\n whiteList['grid-row-start'] = true; // default: auto\n whiteList['grid-template'] = true; // default: depending on individual properties\n whiteList['grid-template-areas'] = true; // default: none\n whiteList['grid-template-columns'] = true; // default: none\n whiteList['grid-template-rows'] = true; // default: none\n whiteList['justify-content'] = true; // default: auto\n whiteList['justify-items'] = true; // default: auto\n whiteList['justify-self'] = true; // default: auto\n whiteList['line-height'] = true; // default: normal\n whiteList['object-fit'] = true; // default: fill\n whiteList['object-position'] = true; // default: 50% 50%\n whiteList.order = true; // default: 0\n whiteList.orphans = true; // default: 2\n whiteList['row-gap'] = true;\n\n // position, opacity, overflow\n whiteList['all'] = true; // default: depending on individual properties\n whiteList['bottom'] = true; // default: auto\n whiteList['content'] = true; // default: normal\n whiteList['cursor'] = true; // default: auto\n whiteList['direction'] = true; // default: ltr\n whiteList['left'] = true; // default: auto\n whiteList['line-break'] = true; // default: auto\n whiteList['opacity'] = true; // default: 1\n whiteList['overflow'] = true; // default: depending on individual properties\n whiteList['overflow-wrap'] = true; // default: normal\n whiteList['overflow-x'] = true; // default: visible\n whiteList['overflow-y'] = true; // default: visible\n whiteList['position'] = true; // default: static\n whiteList['right'] = true; // default: auto\n whiteList['top'] = true; // default: auto\n whiteList['white-space'] = true; // default: normal\n whiteList['z-index'] = true; // default: auto\n\n return whiteList;\n};\n\n// yfmHtmlBlock additional allowedTags\nconst yfmHtmlBlockAllowedTags = ['link', 'base', 'style'];\n\n// yfmHtmlBlock additional allowedTags\nconst yfmHtmlBlockAllowedAttributes = {\n link: ['rel', 'href'],\n base: ['target'],\n style: [],\n};\n\nexport const getYfmHtmlBlockOptions = (defaultOptions: SanitizeOptions): SanitizeOptions => {\n type AllowedAttributesType = Record<\n string,\n (string | {name: string; multiple?: boolean | undefined; values: string[]})[]\n >;\n const defaultAllowedAttributes = defaultOptions.allowedAttributes as AllowedAttributesType;\n\n return {\n ...defaultOptions,\n allowedAttributes: {\n ...defaultAllowedAttributes,\n ...yfmHtmlBlockAllowedAttributes,\n },\n allowedTags:\n typeof defaultOptions.allowedTags === 'boolean'\n ? defaultOptions.allowedTags\n : [...(defaultOptions.allowedTags ?? []), ...yfmHtmlBlockAllowedTags],\n cssWhiteList: {\n ...defaultOptions.cssWhiteList,\n ...getYfmHtmlBlockWhiteList(),\n },\n };\n};\n\nexport interface GetSanitizeYfmHtmlBlockArgs {\n options: SanitizeOptions;\n sanitize?: (html: string, options?: SanitizeOptions) => string;\n}\nexport const getSanitizeYfmHtmlBlock =\n ({options, sanitize = diplodocSanitize}: GetSanitizeYfmHtmlBlockArgs) =>\n (content: string) =>\n sanitize(content, getYfmHtmlBlockOptions(options));\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isEmptyString } from "../../../../utils/index.js";
|
|
1
2
|
import { nodeTypeFactory } from "../../../../utils/schema.js";
|
|
2
3
|
export var BaseNode;
|
|
3
4
|
(function (BaseNode) {
|
|
@@ -76,15 +77,4 @@ export const BaseSchemaSpecs = (builder, opts) => {
|
|
|
76
77
|
},
|
|
77
78
|
}));
|
|
78
79
|
};
|
|
79
|
-
const isEmptyString = (node) => {
|
|
80
|
-
if (!node.content.size) {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
if (node.childCount === 1 &&
|
|
84
|
-
node.child(0).type.name === 'text' &&
|
|
85
|
-
node.child(0).text?.trim() === '') {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
return false;
|
|
89
|
-
};
|
|
90
80
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/base/BaseSchema/BaseSchemaSpecs/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/base/BaseSchema/BaseSchemaSpecs/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAC,mCAAkB;AAGxC,OAAO,EAAC,eAAe,EAAC,oCAAiC;AAEzD,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,mCAAuB,CAAA;AAC3B,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB;AAED,MAAM,uBAAuB,GAAG,WAAW,CAAC;AAE5C,MAAM,CAAC,MAAM,KAAK,GAAG,eAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAQzD,MAAM,CAAC,MAAM,eAAe,GAA0C,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IACpF,OAAO;SACF,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE;YACF,OAAO,EAAE,QAAQ;SACpB;QACD,MAAM,EAAE,EAAC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,EAAC;QACtE,IAAI,EAAE,GAAG,EAAE;YACP,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC1D,CAAC;KACJ,CAAC,CAAC;SACF,OAAO,CAAC,QAA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SAClB;QACD,MAAM,EAAE,EAAC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAC,EAAC;QAC9D,IAAI,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;YAC1B;;;cAGE;YACF,IAAI,IAAI,CAAC,iBAAiB,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChD,IAAI,aAAa,GAAG,IAAI,CAAC;gBAEzB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC;oBAC7D,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAChD,IACI,WAAW,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;wBAC9B,WAAW,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,EACvC,CAAC;wBACC,aAAa,GAAG,KAAK,CAAC;oBAC1B,CAAC;gBACL,CAAC;gBAED,IAAI,CAAC,aAAa,EAAE,CAAC;oBACjB,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC9B,CAAC;YACL,CAAC;iBAAM,CAAC;gBACJ,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBACzB,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;QACL,CAAC;KACJ,CAAC,CAAC,CAAC;AACZ,CAAC,CAAC","sourcesContent":["import type {NodeSpec} from 'prosemirror-model';\n\nimport {isEmptyString} from 'src/utils';\n\nimport type {ExtensionAuto} from '../../../../core';\nimport {nodeTypeFactory} from '../../../../utils/schema';\n\nexport enum BaseNode {\n Doc = 'doc',\n Text = 'text',\n Paragraph = 'paragraph',\n}\n\nconst paragraphLineNumberAttr = 'data-line';\n\nexport const pType = nodeTypeFactory(BaseNode.Paragraph);\n\nexport type BaseSchemaSpecsOptions = {\n // This cannot be passed through placeholder option of BehaviorPreset because BasePreset initializes first\n paragraphPlaceholder?: NonNullable<NodeSpec['placeholder']>['content'];\n preserveEmptyRows?: boolean;\n};\n\nexport const BaseSchemaSpecs: ExtensionAuto<BaseSchemaSpecsOptions> = (builder, opts) => {\n builder\n .addNode(BaseNode.Doc, () => ({\n spec: {\n content: 'block+',\n },\n fromMd: {tokenSpec: {name: BaseNode.Doc, type: 'block', ignore: true}},\n toMd: () => {\n throw new Error('Unexpected toMd() call on doc node');\n },\n }))\n .addNode(BaseNode.Text, () => ({\n spec: {\n group: 'inline',\n },\n fromMd: {tokenSpec: {name: BaseNode.Text, type: 'node', ignore: true}},\n toMd: (state, node, parent) => {\n const {escapeText} = parent.type.spec;\n state.text(node.text ?? '', escapeText ?? !state.isAutolink);\n },\n }))\n .addNode(BaseNode.Paragraph, () => ({\n spec: {\n attrs: {[paragraphLineNumberAttr]: {default: null}},\n content: 'inline*',\n group: 'block',\n parseDOM: [{tag: 'p'}],\n toDOM(node) {\n const lineNumber = node.attrs[paragraphLineNumberAttr];\n\n return [\n 'p',\n lineNumber === null ? {} : {[paragraphLineNumberAttr]: lineNumber},\n 0,\n ];\n },\n selectable: true,\n placeholder: opts.paragraphPlaceholder\n ? {\n content: opts.paragraphPlaceholder,\n alwaysVisible: false,\n }\n : undefined,\n },\n fromMd: {tokenSpec: {name: BaseNode.Paragraph, type: 'block'}},\n toMd: (state, node, parent) => {\n /*\n An empty line is added only if there is some content in the parent element.\n This is necessary in order to prevent an empty document with empty lines\n */\n if (opts.preserveEmptyRows && isEmptyString(node)) {\n let isParentEmpty = true;\n\n for (let index = 0; index < parent.content.childCount; index++) {\n const parentChild = parent.content.child(index);\n if (\n parentChild.content.size !== 0 ||\n parentChild.type.name !== 'paragraph'\n ) {\n isParentEmpty = false;\n }\n }\n\n if (!isParentEmpty) {\n state.write(' \\n\\n');\n }\n } else {\n state.renderInline(node);\n state.closeBlock(node);\n }\n },\n }));\n};\n"]}
|
|
@@ -8,7 +8,7 @@ import { isNodeSelection, isTextSelection, isWholeSelection } from "../../../uti
|
|
|
8
8
|
import { serializeForClipboard } from "../../../utils/serialize-for-clipboard.js";
|
|
9
9
|
import { BaseNode, pType } from "../../base/BaseSchema/index.js";
|
|
10
10
|
import { isInsideCode } from "./code.js";
|
|
11
|
-
import { DataTransferType, extractTextContentFromHtml, isIosSafariShare } from "./utils.js";
|
|
11
|
+
import { DataTransferType, extractTextContentFromHtml, isIosSafariShare, trimContent } from "./utils.js";
|
|
12
12
|
export const clipboard = ({ logger, textParser, mdParser, serializer, pasteFileHandler, }) => {
|
|
13
13
|
return new Plugin({
|
|
14
14
|
props: {
|
|
@@ -230,6 +230,14 @@ function getCopyContent(state) {
|
|
|
230
230
|
slice = new Slice(slice.content.replaceChild(0, state.schema.node(BaseNode.Paragraph, {}, firstChild.content)), slice.openStart, slice.openStart);
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
+
else {
|
|
234
|
+
// trim empty list items
|
|
235
|
+
const createEmptyParagraph = () => Fragment.from(pType(state.schema).createAndFill());
|
|
236
|
+
const trimmedContent = trimContent(slice.content, createEmptyParagraph);
|
|
237
|
+
if (trimmedContent !== slice.content) {
|
|
238
|
+
slice = new Slice(trimmedContent, 1, 1);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
233
241
|
return slice;
|
|
234
242
|
}
|
|
235
243
|
function isTextSelectionWithinSameTextBlock(sel) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.js","sourceRoot":"../../../../../src","sources":["extensions/behavior/Clipboard/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAA4C,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EAAmB,MAAM,EAAiB,MAAM,mBAAmB,CAAC;AAG3E,OAAO,EAA+B,uBAAuB,EAAC,+BAAsB;AACpF,OAAO,EAAe,YAAY,EAAC,2BAAwB;AAC3D,gCAA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CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,GAAc;IACvC,MAAM,cAAc,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IACpD,MAAM,iBAAiB,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;IACtD,MAAM,cAAc,GAAG,iBAAiB,IAAI,iBAAiB,KAAK,MAAM,CAAC;IACzE,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,kBAAkB,CAAC,EAAC,KAAK,EAAE,GAAG,EAAyC;IAC5E,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import {Fragment, type Node, type ResolvedPos, type Schema, Slice} from 'prosemirror-model';\nimport {type EditorState, Plugin, type Selection} from 'prosemirror-state';\nimport type {EditorView} from 'prosemirror-view';\n\nimport {type Parser, type Serializer, trackTransactionMetrics} from '../../../core';\nimport {type Logger2, globalLogger} from '../../../logger';\nimport '../../../types/spec';\nimport {tryCatch} from '../../../utils/helpers';\nimport {isNodeSelection, isTextSelection, isWholeSelection} from '../../../utils/selection';\nimport {serializeForClipboard} from '../../../utils/serialize-for-clipboard';\nimport {BaseNode, pType} from '../../base/BaseSchema';\n\nimport {isInsideCode} from './code';\nimport {DataTransferType, extractTextContentFromHtml, isIosSafariShare} from './utils';\n\nexport type ClipboardPluginOptions = {\n logger: Logger2.ILogger;\n mdParser: Parser;\n textParser: Parser;\n serializer: Serializer;\n pasteFileHandler?: (file: File) => void;\n};\n\nexport const clipboard = ({\n logger,\n textParser,\n mdParser,\n serializer,\n pasteFileHandler,\n}: ClipboardPluginOptions) => {\n return new Plugin({\n props: {\n handleDOMEvents: {\n copy(view, e) {\n if (!e.clipboardData) return false;\n const result = serializeSelected(view, serializer);\n if (result) {\n e.preventDefault();\n setClipboardData(e.clipboardData, result);\n return true;\n }\n return false;\n },\n cut(view, e) {\n if (!e.clipboardData) return false;\n const result = serializeSelected(view, serializer);\n if (result) {\n e.preventDefault();\n setClipboardData(e.clipboardData, result);\n view.dispatch(\n view.state.tr\n .deleteSelection()\n .scrollIntoView()\n .setMeta('uiEvent', 'cut'),\n );\n return true;\n }\n return false;\n },\n paste(view, e) {\n if (!e.clipboardData) return false;\n\n const pasteLogger = logger.nested({\n domEvent: 'paste',\n dataTypes: e.clipboardData.types,\n });\n\n let data: string;\n let isPasteHandled = false;\n\n if (\n isIosSafariShare(e.clipboardData) &&\n (data = e.clipboardData.getData(DataTransferType.UriList))\n ) {\n const schema: Schema = view.state.schema;\n view.dispatch(\n trackTransactionMetrics(\n view.state.tr.replaceSelection(\n // paste link inline\n new Slice(\n Fragment.from(\n pType(schema).create(null, schema.text(data)),\n ),\n 1,\n 1,\n ),\n ),\n 'paste',\n {clipboardDataFormat: DataTransferType.UriList},\n ),\n );\n pasteLogger.event({\n event: 'paste-uri-list',\n });\n isPasteHandled = true;\n e.preventDefault();\n return true;\n }\n\n if (\n !e.clipboardData.types.includes(DataTransferType.Yfm) &&\n (data = e.clipboardData.getData(DataTransferType.Html))\n ) {\n const textFromHtml = extractTextContentFromHtml(data);\n if (textFromHtml) {\n const res = tryCatch(() => textParser.parse(textFromHtml));\n if (res.success) {\n const docNode = res.result;\n const slice = getSliceFromMarkupFragment(docNode.content);\n view.dispatch(\n trackTransactionMetrics(\n view.state.tr.replaceSelection(slice),\n 'paste',\n {clipboardDataFormat: DataTransferType.Html},\n ),\n );\n pasteLogger.event({\n event: 'paste-parsed-html',\n });\n isPasteHandled = true;\n } else {\n globalLogger.error(res.error);\n pasteLogger.error(res.error, {\n event: 'parse-html',\n });\n console.error(res.error);\n }\n } else return false; // default html pasting\n }\n\n if (\n !isPasteHandled &&\n ((data = e.clipboardData.getData(DataTransferType.Yfm)) ||\n (data = e.clipboardData.getData(DataTransferType.Text)))\n ) {\n let parser: Parser;\n let dataFormat: string;\n if (e.clipboardData.types.includes(DataTransferType.Yfm)) {\n parser = mdParser;\n dataFormat = DataTransferType.Yfm;\n } else {\n parser = textParser;\n dataFormat = DataTransferType.Text;\n }\n const codeType = isInsideCode(view.state);\n if (codeType) {\n const schema: Schema = view.state.schema;\n const insideCodeData = e.clipboardData.getData(DataTransferType.Text);\n\n pasteLogger.event({\n event: 'paste-text-to-code',\n codeType,\n });\n view.dispatch(\n trackTransactionMetrics(\n view.state.tr.replaceSelectionWith(\n schema.text(\n codeType === 'inline'\n ? insideCodeData.trim()\n : insideCodeData,\n ),\n ),\n 'paste',\n {clipboardDataFormat: DataTransferType.Text, code: codeType},\n ),\n );\n isPasteHandled = true;\n } else {\n const res = tryCatch(() => parser.parse(data));\n if (res.success) {\n const docNode = res.result;\n const slice = getSliceFromMarkupFragment(docNode.content);\n pasteLogger.event({\n event: 'paste-parsed-content',\n dataFormat,\n });\n view.dispatch(\n trackTransactionMetrics(\n view.state.tr.replaceSelection(slice),\n 'paste',\n {clipboardDataFormat: dataFormat},\n ),\n );\n isPasteHandled = true;\n } else {\n globalLogger.error(res.error);\n pasteLogger.error(res.error, {\n event: 'paste',\n dataFormat,\n });\n console.error(res.error);\n }\n }\n }\n\n if (e.clipboardData.files.length && pasteFileHandler) {\n pasteLogger.event({\n event: 'paste-files',\n });\n for (const file of Array.from(e.clipboardData.files)) {\n pasteFileHandler(file);\n }\n isPasteHandled = true;\n }\n\n if (isPasteHandled) {\n e.preventDefault();\n return true;\n }\n\n return false;\n },\n },\n },\n });\n};\n\nfunction getSliceFromMarkupFragment(fragment: Fragment) {\n let start = 0;\n let end = 0;\n if (fragment.firstChild?.isTextblock) {\n start = 1;\n if (fragment.childCount === 1) {\n end = 1;\n }\n }\n return new Slice(fragment, start, end);\n}\n\ntype SerializeResult = {\n text: string;\n html?: string;\n markup?: string;\n};\nfunction serializeSelected(view: EditorView, serializer: Serializer): SerializeResult | null {\n const sel = view.state.selection;\n\n if (sel.empty) return null;\n\n if (getSharedDepthNode(sel).type.spec.code) {\n const fragment = sel.content().content;\n return {text: fragment.textBetween(0, fragment.size)};\n }\n\n // FIXME: Verify and use Node instead of Fragment\n const markup = serializer.serialize(getCopyContent(view.state).content as any);\n const {dom, text} = serializeForClipboard(view, sel.content());\n return {markup, text, html: dom.innerHTML};\n}\n\nfunction setClipboardData(data: DataTransfer, result: SerializeResult) {\n data.clearData();\n if (typeof result.markup === 'string') data.setData(DataTransferType.Yfm, result.markup);\n if (typeof result.html === 'string') data.setData(DataTransferType.Html, result.html);\n data.setData(DataTransferType.Text, result.text);\n}\n\nfunction getCopyContent(state: EditorState): Slice {\n const sel = state.selection;\n\n if (isWholeSelection(sel)) {\n return new Slice(state.doc.content, 0, 0);\n }\n\n if (isTextSelectionWithinSameTextBlock(sel)) {\n return new Slice(createFragmentFromInlineSelection(state), 0, 0);\n }\n\n if (isNodeSelection(sel)) {\n const {node} = sel;\n if (node.type.spec.complex) {\n if (node.isTextblock) {\n return new Slice(\n Fragment.from(state.schema.node(BaseNode.Paragraph, {}, node.content)),\n 1,\n 1,\n );\n } else {\n const {complex} = node.type.spec;\n if (complex === 'root') {\n return new Slice(Fragment.from(node), 1, 1);\n } else if (complex === 'leaf') {\n return new Slice(Fragment.from(node.content), 1, 1);\n } else {\n // TODO: handle copy of intermediate complex block node\n }\n }\n } else {\n return new Slice(Fragment.from(node), 1, 1);\n }\n }\n\n let slice = getSelectionContent(sel);\n\n // replace first node with paragraph if needed\n if (\n slice.content.firstChild?.isTextblock &&\n slice.content.firstChild.type.name !== BaseNode.Paragraph\n ) {\n let shouldTransformFirstChildToPara = true;\n const {firstChild} = slice.content;\n\n // if all text selected inside first node, don't replace it with paragraph\n if (firstChild.eq(sel.$from.parent)) {\n shouldTransformFirstChildToPara = false;\n }\n\n if (shouldTransformFirstChildToPara) {\n slice = new Slice(\n slice.content.replaceChild(\n 0,\n state.schema.node(BaseNode.Paragraph, {}, firstChild.content),\n ),\n slice.openStart,\n slice.openStart,\n );\n }\n }\n\n return slice;\n}\n\nfunction isTextSelectionWithinSameTextBlock(sel: Selection) {\n return isTextSelection(sel) && sel.$from.sameParent(sel.$to) && sel.$from.parent.isTextblock;\n}\n\nfunction createFragmentFromInlineSelection(state: EditorState) {\n const sel = state.selection;\n const inlineSlice = state.doc.slice(sel.from, sel.to);\n const isComplexTextblock = Boolean(sel.$from.parent.type.spec.complex);\n const isAllContentSelected = sel.$from.parent.content.eq(inlineSlice.content);\n if (isComplexTextblock || !isAllContentSelected) {\n // copy selected inline content to paragraph if current node is complex\n // or if only part of it's content was selected\n return Fragment.from(state.schema.node(BaseNode.Paragraph, {}, inlineSlice.content));\n }\n return Fragment.from(sel.$from.parent.copy(inlineSlice.content));\n}\n\n/**\n * Like `selection.content()`, but smarter.\n * Copy a structure of complex nodes,\n * e.g. if select part of cut title it creates slice with yfm-cut –> yfm-cut-title -> selected text\n * it works well with simple nodes, but to handle cases as described above, custom logic needed\n */\nfunction getSelectionContent(sel: Selection) {\n const sharedNodeType = getSharedDepthNode(sel).type;\n const sharedNodeComplex = sharedNodeType.spec.complex;\n const includeParents = sharedNodeComplex && sharedNodeComplex !== 'leaf';\n return sel.$from.doc.slice(sel.$from.pos, sel.to, includeParents);\n}\n\nfunction getSharedDepthNode({$from, $to}: {$from: ResolvedPos; $to: ResolvedPos}): Node {\n return $from.node($from.sharedDepth($to.pos));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"clipboard.js","sourceRoot":"../../../../../src","sources":["extensions/behavior/Clipboard/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAA4C,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAC5F,OAAO,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AAClD,CAAC","sourcesContent":["import {Fragment, type Node, type ResolvedPos, type Schema, Slice} from 'prosemirror-model';\nimport {type EditorState, Plugin, type Selection} from 'prosemirror-state';\nimport type {EditorView} from 'prosemirror-view';\n\nimport {type Parser, type Serializer, trackTransactionMetrics} from '../../../core';\nimport {type Logger2, globalLogger} from '../../../logger';\nimport '../../../types/spec';\nimport {tryCatch} from '../../../utils/helpers';\nimport {isNodeSelection, isTextSelection, isWholeSelection} from '../../../utils/selection';\nimport {serializeForClipboard} from '../../../utils/serialize-for-clipboard';\nimport {BaseNode, pType} from '../../base/BaseSchema';\n\nimport {isInsideCode} from './code';\nimport {DataTransferType, extractTextContentFromHtml, isIosSafariShare, trimContent} from './utils';\n\nexport type ClipboardPluginOptions = {\n logger: Logger2.ILogger;\n mdParser: Parser;\n textParser: Parser;\n serializer: Serializer;\n pasteFileHandler?: (file: File) => void;\n};\n\nexport const clipboard = ({\n logger,\n textParser,\n mdParser,\n serializer,\n pasteFileHandler,\n}: ClipboardPluginOptions) => {\n return new Plugin({\n props: {\n handleDOMEvents: {\n copy(view, e) {\n if (!e.clipboardData) return false;\n const result = serializeSelected(view, serializer);\n if (result) {\n e.preventDefault();\n setClipboardData(e.clipboardData, result);\n return true;\n }\n return false;\n },\n cut(view, e) {\n if (!e.clipboardData) return false;\n const result = serializeSelected(view, serializer);\n if (result) {\n e.preventDefault();\n setClipboardData(e.clipboardData, result);\n view.dispatch(\n view.state.tr\n .deleteSelection()\n .scrollIntoView()\n .setMeta('uiEvent', 'cut'),\n );\n return true;\n }\n return false;\n },\n paste(view, e) {\n if (!e.clipboardData) return false;\n\n const pasteLogger = logger.nested({\n domEvent: 'paste',\n dataTypes: e.clipboardData.types,\n });\n\n let data: string;\n let isPasteHandled = false;\n\n if (\n isIosSafariShare(e.clipboardData) &&\n (data = e.clipboardData.getData(DataTransferType.UriList))\n ) {\n const schema: Schema = view.state.schema;\n view.dispatch(\n trackTransactionMetrics(\n view.state.tr.replaceSelection(\n // paste link inline\n new Slice(\n Fragment.from(\n pType(schema).create(null, schema.text(data)),\n ),\n 1,\n 1,\n ),\n ),\n 'paste',\n {clipboardDataFormat: DataTransferType.UriList},\n ),\n );\n pasteLogger.event({\n event: 'paste-uri-list',\n });\n isPasteHandled = true;\n e.preventDefault();\n return true;\n }\n\n if (\n !e.clipboardData.types.includes(DataTransferType.Yfm) &&\n (data = e.clipboardData.getData(DataTransferType.Html))\n ) {\n const textFromHtml = extractTextContentFromHtml(data);\n if (textFromHtml) {\n const res = tryCatch(() => textParser.parse(textFromHtml));\n if (res.success) {\n const docNode = res.result;\n const slice = getSliceFromMarkupFragment(docNode.content);\n view.dispatch(\n trackTransactionMetrics(\n view.state.tr.replaceSelection(slice),\n 'paste',\n {clipboardDataFormat: DataTransferType.Html},\n ),\n );\n pasteLogger.event({\n event: 'paste-parsed-html',\n });\n isPasteHandled = true;\n } else {\n globalLogger.error(res.error);\n pasteLogger.error(res.error, {\n event: 'parse-html',\n });\n console.error(res.error);\n }\n } else return false; // default html pasting\n }\n\n if (\n !isPasteHandled &&\n ((data = e.clipboardData.getData(DataTransferType.Yfm)) ||\n (data = e.clipboardData.getData(DataTransferType.Text)))\n ) {\n let parser: Parser;\n let dataFormat: string;\n if (e.clipboardData.types.includes(DataTransferType.Yfm)) {\n parser = mdParser;\n dataFormat = DataTransferType.Yfm;\n } else {\n parser = textParser;\n dataFormat = DataTransferType.Text;\n }\n const codeType = isInsideCode(view.state);\n if (codeType) {\n const schema: Schema = view.state.schema;\n const insideCodeData = e.clipboardData.getData(DataTransferType.Text);\n\n pasteLogger.event({\n event: 'paste-text-to-code',\n codeType,\n });\n view.dispatch(\n trackTransactionMetrics(\n view.state.tr.replaceSelectionWith(\n schema.text(\n codeType === 'inline'\n ? insideCodeData.trim()\n : insideCodeData,\n ),\n ),\n 'paste',\n {clipboardDataFormat: DataTransferType.Text, code: codeType},\n ),\n );\n isPasteHandled = true;\n } else {\n const res = tryCatch(() => parser.parse(data));\n if (res.success) {\n const docNode = res.result;\n const slice = getSliceFromMarkupFragment(docNode.content);\n pasteLogger.event({\n event: 'paste-parsed-content',\n dataFormat,\n });\n view.dispatch(\n trackTransactionMetrics(\n view.state.tr.replaceSelection(slice),\n 'paste',\n {clipboardDataFormat: dataFormat},\n ),\n );\n isPasteHandled = true;\n } else {\n globalLogger.error(res.error);\n pasteLogger.error(res.error, {\n event: 'paste',\n dataFormat,\n });\n console.error(res.error);\n }\n }\n }\n\n if (e.clipboardData.files.length && pasteFileHandler) {\n pasteLogger.event({\n event: 'paste-files',\n });\n for (const file of Array.from(e.clipboardData.files)) {\n pasteFileHandler(file);\n }\n isPasteHandled = true;\n }\n\n if (isPasteHandled) {\n e.preventDefault();\n return true;\n }\n\n return false;\n },\n },\n },\n });\n};\n\nfunction getSliceFromMarkupFragment(fragment: Fragment) {\n let start = 0;\n let end = 0;\n if (fragment.firstChild?.isTextblock) {\n start = 1;\n if (fragment.childCount === 1) {\n end = 1;\n }\n }\n return new Slice(fragment, start, end);\n}\n\ntype SerializeResult = {\n text: string;\n html?: string;\n markup?: string;\n};\nfunction serializeSelected(view: EditorView, serializer: Serializer): SerializeResult | null {\n const sel = view.state.selection;\n\n if (sel.empty) return null;\n\n if (getSharedDepthNode(sel).type.spec.code) {\n const fragment = sel.content().content;\n return {text: fragment.textBetween(0, fragment.size)};\n }\n\n // FIXME: Verify and use Node instead of Fragment\n const markup = serializer.serialize(getCopyContent(view.state).content as any);\n const {dom, text} = serializeForClipboard(view, sel.content());\n return {markup, text, html: dom.innerHTML};\n}\n\nfunction setClipboardData(data: DataTransfer, result: SerializeResult) {\n data.clearData();\n if (typeof result.markup === 'string') data.setData(DataTransferType.Yfm, result.markup);\n if (typeof result.html === 'string') data.setData(DataTransferType.Html, result.html);\n data.setData(DataTransferType.Text, result.text);\n}\n\nfunction getCopyContent(state: EditorState): Slice {\n const sel = state.selection;\n\n if (isWholeSelection(sel)) {\n return new Slice(state.doc.content, 0, 0);\n }\n\n if (isTextSelectionWithinSameTextBlock(sel)) {\n return new Slice(createFragmentFromInlineSelection(state), 0, 0);\n }\n\n if (isNodeSelection(sel)) {\n const {node} = sel;\n if (node.type.spec.complex) {\n if (node.isTextblock) {\n return new Slice(\n Fragment.from(state.schema.node(BaseNode.Paragraph, {}, node.content)),\n 1,\n 1,\n );\n } else {\n const {complex} = node.type.spec;\n if (complex === 'root') {\n return new Slice(Fragment.from(node), 1, 1);\n } else if (complex === 'leaf') {\n return new Slice(Fragment.from(node.content), 1, 1);\n } else {\n // TODO: handle copy of intermediate complex block node\n }\n }\n } else {\n return new Slice(Fragment.from(node), 1, 1);\n }\n }\n\n let slice = getSelectionContent(sel);\n\n // replace first node with paragraph if needed\n if (\n slice.content.firstChild?.isTextblock &&\n slice.content.firstChild.type.name !== BaseNode.Paragraph\n ) {\n let shouldTransformFirstChildToPara = true;\n const {firstChild} = slice.content;\n\n // if all text selected inside first node, don't replace it with paragraph\n if (firstChild.eq(sel.$from.parent)) {\n shouldTransformFirstChildToPara = false;\n }\n\n if (shouldTransformFirstChildToPara) {\n slice = new Slice(\n slice.content.replaceChild(\n 0,\n state.schema.node(BaseNode.Paragraph, {}, firstChild.content),\n ),\n slice.openStart,\n slice.openStart,\n );\n }\n } else {\n // trim empty list items\n const createEmptyParagraph = () => Fragment.from(pType(state.schema).createAndFill());\n const trimmedContent = trimContent(slice.content, createEmptyParagraph);\n if (trimmedContent !== slice.content) {\n slice = new Slice(trimmedContent, 1, 1);\n }\n }\n\n return slice;\n}\n\nfunction isTextSelectionWithinSameTextBlock(sel: Selection) {\n return isTextSelection(sel) && sel.$from.sameParent(sel.$to) && sel.$from.parent.isTextblock;\n}\n\nfunction createFragmentFromInlineSelection(state: EditorState) {\n const sel = state.selection;\n const inlineSlice = state.doc.slice(sel.from, sel.to);\n const isComplexTextblock = Boolean(sel.$from.parent.type.spec.complex);\n const isAllContentSelected = sel.$from.parent.content.eq(inlineSlice.content);\n if (isComplexTextblock || !isAllContentSelected) {\n // copy selected inline content to paragraph if current node is complex\n // or if only part of it's content was selected\n return Fragment.from(state.schema.node(BaseNode.Paragraph, {}, inlineSlice.content));\n }\n return Fragment.from(sel.$from.parent.copy(inlineSlice.content));\n}\n\n/**\n * Like `selection.content()`, but smarter.\n * Copy a structure of complex nodes,\n * e.g. if select part of cut title it creates slice with yfm-cut –> yfm-cut-title -> selected text\n * it works well with simple nodes, but to handle cases as described above, custom logic needed\n */\nfunction getSelectionContent(sel: Selection) {\n const sharedNodeType = getSharedDepthNode(sel).type;\n const sharedNodeComplex = sharedNodeType.spec.complex;\n const includeParents = sharedNodeComplex && sharedNodeComplex !== 'leaf';\n return sel.$from.doc.slice(sel.$from.pos, sel.to, includeParents);\n}\n\nfunction getSharedDepthNode({$from, $to}: {$from: ResolvedPos; $to: ResolvedPos}): Node {\n return $from.node($from.sharedDepth($to.pos));\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fragment } from 'prosemirror-model';
|
|
1
2
|
/** Сontains all data formats known to us */
|
|
2
3
|
export declare enum DataTransferType {
|
|
3
4
|
Text = "text/plain",
|
|
@@ -13,3 +14,5 @@ export declare function isFilesOnly({ types }: DataTransfer): boolean;
|
|
|
13
14
|
export declare function isFilesFromHtml({ types }: DataTransfer): boolean;
|
|
14
15
|
export declare function isImageFile(file: File): boolean;
|
|
15
16
|
export declare function extractTextContentFromHtml(html: string): string | null;
|
|
17
|
+
export declare function findNotEmptyContentPosses(fragment: Fragment): [number, number, number, number];
|
|
18
|
+
export declare function trimContent(fragment: Fragment, creatEmptyFragment?: () => Fragment): Fragment;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Fragment } from 'prosemirror-model';
|
|
2
|
+
import { isListItemNode, isListNode } from "../../markdown/Lists/utils.js";
|
|
3
|
+
import { isEmptyString } from "../../../utils/index.js";
|
|
1
4
|
/** Сontains all data formats known to us */
|
|
2
5
|
export var DataTransferType;
|
|
3
6
|
(function (DataTransferType) {
|
|
@@ -42,4 +45,44 @@ export function extractTextContentFromHtml(html) {
|
|
|
42
45
|
}
|
|
43
46
|
return null;
|
|
44
47
|
}
|
|
48
|
+
export function findNotEmptyContentPosses(fragment) {
|
|
49
|
+
let firstNodePos = -1;
|
|
50
|
+
let lastNodePos = -1;
|
|
51
|
+
let firstNotEmptyNodePos = -1;
|
|
52
|
+
let lastNotEmptyNodePos = -1;
|
|
53
|
+
fragment.forEach((contentNode, offset) => {
|
|
54
|
+
if (firstNodePos === -1) {
|
|
55
|
+
firstNodePos = offset;
|
|
56
|
+
}
|
|
57
|
+
lastNodePos = offset + contentNode.nodeSize;
|
|
58
|
+
if (!isEmptyString(contentNode)) {
|
|
59
|
+
if (isListNode(contentNode) || isListItemNode(contentNode)) {
|
|
60
|
+
const [start, end] = findNotEmptyContentPosses(contentNode.content);
|
|
61
|
+
if (firstNotEmptyNodePos === -1 && start !== -1) {
|
|
62
|
+
firstNotEmptyNodePos = offset + start;
|
|
63
|
+
}
|
|
64
|
+
if (end !== -1) {
|
|
65
|
+
lastNotEmptyNodePos = offset + end;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
if (firstNotEmptyNodePos === -1) {
|
|
70
|
+
firstNotEmptyNodePos = offset;
|
|
71
|
+
}
|
|
72
|
+
lastNotEmptyNodePos = offset + contentNode.nodeSize;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return [firstNotEmptyNodePos, lastNotEmptyNodePos, firstNodePos, lastNodePos];
|
|
77
|
+
}
|
|
78
|
+
export function trimContent(fragment, creatEmptyFragment) {
|
|
79
|
+
const [notEmptyStart, notEmptyEnd, start, end] = findNotEmptyContentPosses(fragment);
|
|
80
|
+
if (notEmptyStart === start && notEmptyEnd === end) {
|
|
81
|
+
return fragment;
|
|
82
|
+
}
|
|
83
|
+
else if (notEmptyStart === -1 && notEmptyEnd === -1) {
|
|
84
|
+
return creatEmptyFragment ? creatEmptyFragment() : Fragment.empty;
|
|
85
|
+
}
|
|
86
|
+
return fragment.cut(notEmptyStart + 1, notEmptyEnd + 1);
|
|
87
|
+
}
|
|
45
88
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"../../../../../src","sources":["extensions/behavior/Clipboard/utils.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,CAAN,IAAY,gBAQX;AARD,WAAY,gBAAgB;IACxB,uCAAmB,CAAA;IACnB,sCAAkB,CAAA;IAClB,oCAAgB,CAAA;IAChB,oCAAgB,CAAA;IAChB,6CAAyB,CAAA;IACzB,qDAAiC,CAAA;IACjC,mCAAe,CAAA;AACnB,CAAC,EARW,gBAAgB,KAAhB,gBAAgB,QAQ3B;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAC,KAAK,EAAe;IAClD,kDAAkD;IAClD,uDAAuD;IACvD,OAAO,CACH,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC;QACxC,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC;QACtC,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CACzC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAC,KAAK,EAAe;IAC7C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAC,KAAK,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,EAAC,KAAK,EAAe;IACjD,OAAO,CACH,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,KAAK,CAAC;QACtC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CACxC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAU;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACnD,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9C,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC;IAE9F,kGAAkG;IAClG,IACI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAC,EAAE,EAAE;QACrE,OAAO,CACH,CAAC,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,MAAM,CAAC;YAC3C,CAAC,SAAS,CAAC,MAAM;YACjB,UAAU,CAAC,MAAM,KAAK,CAAC;YACvB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAC1E,CAAC;IACN,CAAC,CAAC,EACJ,CAAC;QACC,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,WAAW,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["/** Сontains all data formats known to us */\nexport enum DataTransferType {\n Text = 'text/plain',\n Html = 'text/html',\n Yfm = 'text/yfm', // self\n Rtf = 'text/rtf', // Safari, WebStorm/Intelij\n UriList = 'text/uri-list',\n VSCodeData = 'vscode-editor-data',\n Files = 'Files',\n}\n\nexport function isIosSafariShare({types}: DataTransfer): boolean {\n // if link is copied from ios safari share button,\n // then data transfer only have text/uri-list data type\n return (\n types.includes(DataTransferType.UriList) &&\n !types.includes(DataTransferType.Text) &&\n !types.includes(DataTransferType.Html)\n );\n}\n\nexport function isFilesOnly({types}: DataTransfer): boolean {\n return types.length === 1 && types[0] === DataTransferType.Files;\n}\n\nexport function isFilesFromHtml({types}: DataTransfer): boolean {\n return (\n types.length === 2 &&\n types.includes(DataTransferType.Files) &&\n types.includes(DataTransferType.Html)\n );\n}\n\nexport function isImageFile(file: File): boolean {\n return file.type.startsWith('image/');\n}\n\nexport function extractTextContentFromHtml(html: string) {\n const element = document.createElement('div');\n element.innerHTML = html;\n element.replaceChildren(...Array.from(element.children).filter((v) => v.nodeName !== 'META'));\n\n // Look if all nodes are div or span. That they don't have any classname and have only text child.\n if (\n Array.from(element.children).every(({nodeName, classList, childNodes}) => {\n return (\n (nodeName === 'DIV' || nodeName === 'SPAN') &&\n !classList.length &&\n childNodes.length === 1 &&\n (childNodes[0].nodeName === '#text' || childNodes[0].nodeName === 'BR')\n );\n })\n ) {\n return Array.from(element.children).reduce((a, v) => a + v.textContent + '\\n', '');\n }\n\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"../../../../../src","sources":["extensions/behavior/Clipboard/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,cAAc,EAAE,UAAU,EAAC,sCAA4C;AAC/E,OAAO,EAAC,aAAa,EAAC,gCAAkB;AAExC,4CAA4C;AAC5C,MAAM,CAAN,IAAY,gBAQX;AARD,WAAY,gBAAgB;IACxB,uCAAmB,CAAA;IACnB,sCAAkB,CAAA;IAClB,oCAAgB,CAAA;IAChB,oCAAgB,CAAA;IAChB,6CAAyB,CAAA;IACzB,qDAAiC,CAAA;IACjC,mCAAe,CAAA;AACnB,CAAC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Node} from 'src/extensions/markdown/Lists/utils';\nimport {isEmptyString} from 'src/utils';\n\n/** Сontains all data formats known to us */\nexport enum DataTransferType {\n Text = 'text/plain',\n Html = 'text/html',\n Yfm = 'text/yfm', // self\n Rtf = 'text/rtf', // Safari, WebStorm/Intelij\n UriList = 'text/uri-list',\n VSCodeData = 'vscode-editor-data',\n Files = 'Files',\n}\n\nexport function isIosSafariShare({types}: DataTransfer): boolean {\n // if link is copied from ios safari share button,\n // then data transfer only have text/uri-list data type\n return (\n types.includes(DataTransferType.UriList) &&\n !types.includes(DataTransferType.Text) &&\n !types.includes(DataTransferType.Html)\n );\n}\n\nexport function isFilesOnly({types}: DataTransfer): boolean {\n return types.length === 1 && types[0] === DataTransferType.Files;\n}\n\nexport function isFilesFromHtml({types}: DataTransfer): boolean {\n return (\n types.length === 2 &&\n types.includes(DataTransferType.Files) &&\n types.includes(DataTransferType.Html)\n );\n}\n\nexport function isImageFile(file: File): boolean {\n return file.type.startsWith('image/');\n}\n\nexport function extractTextContentFromHtml(html: string) {\n const element = document.createElement('div');\n element.innerHTML = html;\n element.replaceChildren(...Array.from(element.children).filter((v) => v.nodeName !== 'META'));\n\n // Look if all nodes are div or span. That they don't have any classname and have only text child.\n if (\n Array.from(element.children).every(({nodeName, classList, childNodes}) => {\n return (\n (nodeName === 'DIV' || nodeName === 'SPAN') &&\n !classList.length &&\n childNodes.length === 1 &&\n (childNodes[0].nodeName === '#text' || childNodes[0].nodeName === 'BR')\n );\n })\n ) {\n return Array.from(element.children).reduce((a, v) => a + v.textContent + '\\n', '');\n }\n\n return null;\n}\n\nexport function findNotEmptyContentPosses(fragment: Fragment): [number, number, number, number] {\n let firstNodePos = -1;\n let lastNodePos = -1;\n let firstNotEmptyNodePos = -1;\n let lastNotEmptyNodePos = -1;\n\n fragment.forEach((contentNode, offset) => {\n if (firstNodePos === -1) {\n firstNodePos = offset;\n }\n lastNodePos = offset + contentNode.nodeSize;\n\n if (!isEmptyString(contentNode)) {\n if (isListNode(contentNode) || isListItemNode(contentNode)) {\n const [start, end] = findNotEmptyContentPosses(contentNode.content);\n if (firstNotEmptyNodePos === -1 && start !== -1) {\n firstNotEmptyNodePos = offset + start;\n }\n if (end !== -1) {\n lastNotEmptyNodePos = offset + end;\n }\n } else {\n if (firstNotEmptyNodePos === -1) {\n firstNotEmptyNodePos = offset;\n }\n lastNotEmptyNodePos = offset + contentNode.nodeSize;\n }\n }\n });\n\n return [firstNotEmptyNodePos, lastNotEmptyNodePos, firstNodePos, lastNodePos];\n}\n\nexport function trimContent(fragment: Fragment, creatEmptyFragment?: () => Fragment): Fragment {\n const [notEmptyStart, notEmptyEnd, start, end] = findNotEmptyContentPosses(fragment);\n\n if (notEmptyStart === start && notEmptyEnd === end) {\n return fragment;\n } else if (notEmptyStart === -1 && notEmptyEnd === -1) {\n return creatEmptyFragment ? creatEmptyFragment() : Fragment.empty;\n }\n\n return fragment.cut(notEmptyStart + 1, notEmptyEnd + 1);\n}\n"]}
|
|
@@ -5,6 +5,7 @@ import { actions } from "./actions.js";
|
|
|
5
5
|
import { joinPrevList, toList } from "./commands.js";
|
|
6
6
|
import { ListAction } from "./const.js";
|
|
7
7
|
import { ListsInputRulesExtension } from "./inputrules.js";
|
|
8
|
+
import { collapseListsPlugin } from "./plugins/CollapseListsPlugin.js";
|
|
8
9
|
import { mergeListsPlugin } from "./plugins/MergeListsPlugin.js";
|
|
9
10
|
export { ListNode, ListsAttr, blType, liType, olType } from "./ListsSpecs/index.js";
|
|
10
11
|
export const Lists = (builder, opts) => {
|
|
@@ -30,6 +31,7 @@ export const Lists = (builder, opts) => {
|
|
|
30
31
|
}), builder.Priority.Low);
|
|
31
32
|
builder.use(ListsInputRulesExtension, { bulletListInputRule: opts?.ulInputRules });
|
|
32
33
|
builder.addPlugin(mergeListsPlugin);
|
|
34
|
+
builder.addPlugin(collapseListsPlugin);
|
|
33
35
|
builder
|
|
34
36
|
.addAction(ListAction.ToBulletList, actions.toBulletList)
|
|
35
37
|
.addAction(ListAction.ToOrderedList, actions.toOrderedList)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["extensions/markdown/Lists/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,yBAAyB,CAAC;AAGlF,OAAO,EAAC,aAAa,EAAC,iCAA8B;AAEpD,OAAO,EAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAC,8BAAqB;AAChE,OAAO,EAAC,OAAO,EAAC,qBAAkB;AAClC,OAAO,EAAC,YAAY,EAAE,MAAM,EAAC,sBAAmB;AAChD,OAAO,EAAC,UAAU,EAAC,mBAAgB;AACnC,OAAO,EAAC,wBAAwB,EAA8B,wBAAqB;AACnF,OAAO,EAAC,gBAAgB,EAAC,sCAAmC;AAE5D,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAC,8BAAqB;AAQzE,MAAM,CAAC,MAAM,KAAK,GAAgC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IAChE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAExB,OAAO,CAAC,SAAS,CAAC,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE;QAC3B,MAAM,EAAC,KAAK,EAAE,KAAK,EAAC,GAAG,IAAI,IAAI,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAW,EAAE,CAAC;QAC5B,IAAI,KAAK;YAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACjF,IAAI,KAAK;YAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAElF,OAAO;YACH,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACjC,WAAW,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEzC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAErC,GAAG,QAAQ;SACd,CAAC;IACN,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE1B,OAAO,CAAC,SAAS,CACb,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC;QACX,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,SAAS,EAAE,YAAY;KAC1B,CAAC,EACF,OAAO,CAAC,QAAQ,CAAC,GAAG,CACvB,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,EAAC,mBAAmB,EAAE,IAAI,EAAE,YAAY,EAAC,CAAC,CAAC;IAEjF,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAEpC,OAAO;SACF,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;SACxD,SAAS,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;SAC1D,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;SACxD,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import {liftListItem, sinkListItem, splitListItem} from 'prosemirror-schema-list';\n\nimport type {Action, ExtensionAuto, Keymap} from '../../../core';\nimport {withLogAction} from '../../../utils/keymap';\n\nimport {ListsSpecs, blType, liType, olType} from './ListsSpecs';\nimport {actions} from './actions';\nimport {joinPrevList, toList} from './commands';\nimport {ListAction} from './const';\nimport {ListsInputRulesExtension, type ListsInputRulesOptions} from './inputrules';\nimport {mergeListsPlugin} from './plugins/MergeListsPlugin';\n\nexport {ListNode, ListsAttr, blType, liType, olType} from './ListsSpecs';\n\nexport type ListsOptions = {\n ulKey?: string | null;\n olKey?: string | null;\n ulInputRules?: ListsInputRulesOptions['bulletListInputRule'];\n};\n\nexport const Lists: ExtensionAuto<ListsOptions> = (builder, opts) => {\n builder.use(ListsSpecs);\n\n builder.addKeymap(({schema}) => {\n const {ulKey, olKey} = opts ?? {};\n const bindings: Keymap = {};\n if (ulKey) bindings[ulKey] = withLogAction('bulletList', toList(blType(schema)));\n if (olKey) bindings[olKey] = withLogAction('orderedList', toList(olType(schema)));\n\n return {\n Tab: sinkListItem(liType(schema)),\n 'Shift-Tab': liftListItem(liType(schema)),\n\n 'Mod-[': liftListItem(liType(schema)),\n 'Mod-]': sinkListItem(liType(schema)),\n\n ...bindings,\n };\n }, builder.Priority.High);\n\n builder.addKeymap(\n ({schema}) => ({\n Enter: splitListItem(liType(schema)),\n Backspace: joinPrevList,\n }),\n builder.Priority.Low,\n );\n\n builder.use(ListsInputRulesExtension, {bulletListInputRule: opts?.ulInputRules});\n\n builder.addPlugin(mergeListsPlugin);\n\n builder\n .addAction(ListAction.ToBulletList, actions.toBulletList)\n .addAction(ListAction.ToOrderedList, actions.toOrderedList)\n .addAction(ListAction.SinkListItem, actions.sinkListItem)\n .addAction(ListAction.LiftListItem, actions.liftListItem);\n};\n\ndeclare global {\n namespace WysiwygEditor {\n interface Actions {\n [ListAction.ToBulletList]: Action;\n [ListAction.ToOrderedList]: Action;\n [ListAction.SinkListItem]: Action;\n [ListAction.LiftListItem]: Action;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["extensions/markdown/Lists/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,yBAAyB,CAAC;AAGlF,OAAO,EAAC,aAAa,EAAC,iCAA8B;AAEpD,O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C,GAAG,QAAQ;SACd,CAAC;IACN,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE1B,OAAO,CAAC,SAAS,CACb,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC;QACX,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,SAAS,EAAE,YAAY;KAC1B,CAAC,EACF,OAAO,CAAC,QAAQ,CAAC,GAAG,CACvB,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,EAAC,mBAAmB,EAAE,IAAI,EAAE,YAAY,EAAC,CAAC,CAAC;IAEjF,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAEpC,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAEvC,OAAO;SACF,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;SACxD,SAAS,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;SAC1D,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;SACxD,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import {liftListItem, sinkListItem, splitListItem} from 'prosemirror-schema-list';\n\nimport type {Action, ExtensionAuto, Keymap} from '../../../core';\nimport {withLogAction} from '../../../utils/keymap';\n\nimport {ListsSpecs, blType, liType, olType} from './ListsSpecs';\nimport {actions} from './actions';\nimport {joinPrevList, toList} from './commands';\nimport {ListAction} from './const';\nimport {ListsInputRulesExtension, type ListsInputRulesOptions} from './inputrules';\nimport {collapseListsPlugin} from './plugins/CollapseListsPlugin';\nimport {mergeListsPlugin} from './plugins/MergeListsPlugin';\n\nexport {ListNode, ListsAttr, blType, liType, olType} from './ListsSpecs';\n\nexport type ListsOptions = {\n ulKey?: string | null;\n olKey?: string | null;\n ulInputRules?: ListsInputRulesOptions['bulletListInputRule'];\n};\n\nexport const Lists: ExtensionAuto<ListsOptions> = (builder, opts) => {\n builder.use(ListsSpecs);\n\n builder.addKeymap(({schema}) => {\n const {ulKey, olKey} = opts ?? {};\n const bindings: Keymap = {};\n if (ulKey) bindings[ulKey] = withLogAction('bulletList', toList(blType(schema)));\n if (olKey) bindings[olKey] = withLogAction('orderedList', toList(olType(schema)));\n\n return {\n Tab: sinkListItem(liType(schema)),\n 'Shift-Tab': liftListItem(liType(schema)),\n\n 'Mod-[': liftListItem(liType(schema)),\n 'Mod-]': sinkListItem(liType(schema)),\n\n ...bindings,\n };\n }, builder.Priority.High);\n\n builder.addKeymap(\n ({schema}) => ({\n Enter: splitListItem(liType(schema)),\n Backspace: joinPrevList,\n }),\n builder.Priority.Low,\n );\n\n builder.use(ListsInputRulesExtension, {bulletListInputRule: opts?.ulInputRules});\n\n builder.addPlugin(mergeListsPlugin);\n\n builder.addPlugin(collapseListsPlugin);\n\n builder\n .addAction(ListAction.ToBulletList, actions.toBulletList)\n .addAction(ListAction.ToOrderedList, actions.toOrderedList)\n .addAction(ListAction.SinkListItem, actions.sinkListItem)\n .addAction(ListAction.LiftListItem, actions.liftListItem);\n};\n\ndeclare global {\n namespace WysiwygEditor {\n interface Actions {\n [ListAction.ToBulletList]: Action;\n [ListAction.ToOrderedList]: Action;\n [ListAction.SinkListItem]: Action;\n [ListAction.LiftListItem]: Action;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Plugin, type Transaction } from 'prosemirror-state';
|
|
2
|
+
import { findChildren } from 'prosemirror-utils';
|
|
3
|
+
export declare const collapseListsPlugin: () => Plugin<any>;
|
|
4
|
+
export declare function collapseEmptyListItems(tr: Transaction, nodes: ReturnType<typeof findChildren>): number;
|