roosterjs-content-model-plugins 9.6.0 → 9.7.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/lib/autoFormat/hyphen/transformHyphen.js +3 -3
- package/lib/autoFormat/hyphen/transformHyphen.js.map +1 -1
- package/lib/autoFormat/link/createLink.js +7 -2
- package/lib/autoFormat/link/createLink.js.map +1 -1
- package/lib/autoFormat/link/createLinkAfterSpace.js +1 -2
- package/lib/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib/autoFormat/numbers/transformFraction.js +2 -2
- package/lib/autoFormat/numbers/transformFraction.js.map +1 -1
- package/lib/autoFormat/numbers/transformOrdinals.js +2 -2
- package/lib/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib/edit/EditPlugin.d.ts +15 -0
- package/lib/edit/EditPlugin.js +14 -2
- package/lib/edit/EditPlugin.js.map +1 -1
- package/lib/imageEdit/ImageEditPlugin.d.ts +11 -5
- package/lib/imageEdit/ImageEditPlugin.js +209 -103
- package/lib/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib/imageEdit/types/ImageAndParagraph.d.ts +8 -0
- package/lib/imageEdit/types/ImageAndParagraph.js +3 -0
- package/lib/imageEdit/types/ImageAndParagraph.js.map +1 -0
- package/lib/imageEdit/types/ImageEditOptions.d.ts +1 -1
- package/lib/imageEdit/types/ImageEditOptions.js.map +1 -1
- package/lib/imageEdit/utils/applyChange.js +4 -8
- package/lib/imageEdit/utils/applyChange.js.map +1 -1
- package/lib/imageEdit/utils/createImageWrapper.d.ts +1 -1
- package/lib/imageEdit/utils/createImageWrapper.js +10 -6
- package/lib/imageEdit/utils/createImageWrapper.js.map +1 -1
- package/lib/imageEdit/utils/findEditingImage.d.ts +6 -0
- package/lib/imageEdit/utils/findEditingImage.js +43 -0
- package/lib/imageEdit/utils/findEditingImage.js.map +1 -0
- package/lib/imageEdit/utils/getSelectedImage.d.ts +6 -0
- package/lib/imageEdit/utils/getSelectedImage.js +21 -0
- package/lib/imageEdit/utils/getSelectedImage.js.map +1 -0
- package/lib/imageEdit/utils/updateImageEditInfo.d.ts +1 -1
- package/lib/imageEdit/utils/updateImageEditInfo.js +10 -6
- package/lib/imageEdit/utils/updateImageEditInfo.js.map +1 -1
- package/lib/imageEdit/utils/updateWrapper.js +2 -2
- package/lib/imageEdit/utils/updateWrapper.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/lib/markdown/utils/setFormat.js +1 -2
- package/lib/markdown/utils/setFormat.js.map +1 -1
- package/lib/picker/getQueryString.js +2 -2
- package/lib/picker/getQueryString.js.map +1 -1
- package/lib/tableEdit/editors/TableEditor.js +4 -2
- package/lib/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib/tableEdit/editors/features/TableMover.d.ts +2 -2
- package/lib/tableEdit/editors/features/TableMover.js +4 -4
- package/lib/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib/watermark/WatermarkPlugin.d.ts +2 -0
- package/lib/watermark/WatermarkPlugin.js +24 -4
- package/lib/watermark/WatermarkPlugin.js.map +1 -1
- package/lib-amd/autoFormat/hyphen/transformHyphen.js +3 -3
- package/lib-amd/autoFormat/hyphen/transformHyphen.js.map +1 -1
- package/lib-amd/autoFormat/link/createLink.js +7 -2
- package/lib-amd/autoFormat/link/createLink.js.map +1 -1
- package/lib-amd/autoFormat/link/createLinkAfterSpace.js +2 -2
- package/lib-amd/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib-amd/autoFormat/numbers/transformFraction.js +2 -2
- package/lib-amd/autoFormat/numbers/transformFraction.js.map +1 -1
- package/lib-amd/autoFormat/numbers/transformOrdinals.js +2 -2
- package/lib-amd/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib-amd/edit/EditPlugin.d.ts +15 -0
- package/lib-amd/edit/EditPlugin.js +14 -2
- package/lib-amd/edit/EditPlugin.js.map +1 -1
- package/lib-amd/imageEdit/ImageEditPlugin.d.ts +11 -5
- package/lib-amd/imageEdit/ImageEditPlugin.js +208 -104
- package/lib-amd/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib-amd/imageEdit/types/ImageAndParagraph.d.ts +8 -0
- package/lib-amd/imageEdit/types/ImageAndParagraph.js +5 -0
- package/lib-amd/imageEdit/types/ImageAndParagraph.js.map +1 -0
- package/lib-amd/imageEdit/types/ImageEditOptions.d.ts +1 -1
- package/lib-amd/imageEdit/types/ImageEditOptions.js.map +1 -1
- package/lib-amd/imageEdit/utils/applyChange.js +4 -8
- package/lib-amd/imageEdit/utils/applyChange.js.map +1 -1
- package/lib-amd/imageEdit/utils/createImageWrapper.d.ts +1 -1
- package/lib-amd/imageEdit/utils/createImageWrapper.js +10 -7
- package/lib-amd/imageEdit/utils/createImageWrapper.js.map +1 -1
- package/lib-amd/imageEdit/utils/findEditingImage.d.ts +6 -0
- package/lib-amd/imageEdit/utils/findEditingImage.js +45 -0
- package/lib-amd/imageEdit/utils/findEditingImage.js.map +1 -0
- package/lib-amd/imageEdit/utils/getSelectedImage.d.ts +6 -0
- package/lib-amd/imageEdit/utils/getSelectedImage.js +22 -0
- package/lib-amd/imageEdit/utils/getSelectedImage.js.map +1 -0
- package/lib-amd/imageEdit/utils/updateImageEditInfo.d.ts +1 -1
- package/lib-amd/imageEdit/utils/updateImageEditInfo.js +10 -6
- package/lib-amd/imageEdit/utils/updateImageEditInfo.js.map +1 -1
- package/lib-amd/imageEdit/utils/updateWrapper.js +2 -2
- package/lib-amd/imageEdit/utils/updateWrapper.js.map +1 -1
- package/lib-amd/index.d.ts +1 -1
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/markdown/utils/setFormat.js +2 -2
- package/lib-amd/markdown/utils/setFormat.js.map +1 -1
- package/lib-amd/picker/getQueryString.js +2 -2
- package/lib-amd/picker/getQueryString.js.map +1 -1
- package/lib-amd/tableEdit/editors/TableEditor.js +4 -2
- package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableMover.d.ts +2 -2
- package/lib-amd/tableEdit/editors/features/TableMover.js +4 -4
- package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-amd/watermark/WatermarkPlugin.d.ts +2 -0
- package/lib-amd/watermark/WatermarkPlugin.js +24 -5
- package/lib-amd/watermark/WatermarkPlugin.js.map +1 -1
- package/lib-mjs/autoFormat/hyphen/transformHyphen.js +1 -1
- package/lib-mjs/autoFormat/hyphen/transformHyphen.js.map +1 -1
- package/lib-mjs/autoFormat/link/createLink.js +7 -2
- package/lib-mjs/autoFormat/link/createLink.js.map +1 -1
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.js +1 -2
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib-mjs/autoFormat/numbers/transformFraction.js +1 -1
- package/lib-mjs/autoFormat/numbers/transformFraction.js.map +1 -1
- package/lib-mjs/autoFormat/numbers/transformOrdinals.js +1 -1
- package/lib-mjs/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib-mjs/edit/EditPlugin.d.ts +15 -0
- package/lib-mjs/edit/EditPlugin.js +14 -2
- package/lib-mjs/edit/EditPlugin.js.map +1 -1
- package/lib-mjs/imageEdit/ImageEditPlugin.d.ts +11 -5
- package/lib-mjs/imageEdit/ImageEditPlugin.js +211 -105
- package/lib-mjs/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib-mjs/imageEdit/types/ImageAndParagraph.d.ts +8 -0
- package/lib-mjs/imageEdit/types/ImageAndParagraph.js +2 -0
- package/lib-mjs/imageEdit/types/ImageAndParagraph.js.map +1 -0
- package/lib-mjs/imageEdit/types/ImageEditOptions.d.ts +1 -1
- package/lib-mjs/imageEdit/types/ImageEditOptions.js.map +1 -1
- package/lib-mjs/imageEdit/utils/applyChange.js +5 -9
- package/lib-mjs/imageEdit/utils/applyChange.js.map +1 -1
- package/lib-mjs/imageEdit/utils/createImageWrapper.d.ts +1 -1
- package/lib-mjs/imageEdit/utils/createImageWrapper.js +10 -6
- package/lib-mjs/imageEdit/utils/createImageWrapper.js.map +1 -1
- package/lib-mjs/imageEdit/utils/findEditingImage.d.ts +6 -0
- package/lib-mjs/imageEdit/utils/findEditingImage.js +39 -0
- package/lib-mjs/imageEdit/utils/findEditingImage.js.map +1 -0
- package/lib-mjs/imageEdit/utils/getSelectedImage.d.ts +6 -0
- package/lib-mjs/imageEdit/utils/getSelectedImage.js +17 -0
- package/lib-mjs/imageEdit/utils/getSelectedImage.js.map +1 -0
- package/lib-mjs/imageEdit/utils/updateImageEditInfo.d.ts +1 -1
- package/lib-mjs/imageEdit/utils/updateImageEditInfo.js +11 -7
- package/lib-mjs/imageEdit/utils/updateImageEditInfo.js.map +1 -1
- package/lib-mjs/imageEdit/utils/updateWrapper.js +2 -2
- package/lib-mjs/imageEdit/utils/updateWrapper.js.map +1 -1
- package/lib-mjs/index.d.ts +1 -1
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/markdown/utils/setFormat.js +1 -2
- package/lib-mjs/markdown/utils/setFormat.js.map +1 -1
- package/lib-mjs/picker/getQueryString.js +1 -1
- package/lib-mjs/picker/getQueryString.js.map +1 -1
- package/lib-mjs/tableEdit/editors/TableEditor.js +4 -2
- package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +2 -2
- package/lib-mjs/tableEdit/editors/features/TableMover.js +4 -4
- package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-mjs/watermark/WatermarkPlugin.d.ts +2 -0
- package/lib-mjs/watermark/WatermarkPlugin.js +25 -5
- package/lib-mjs/watermark/WatermarkPlugin.js.map +1 -1
- package/package.json +5 -5
- package/lib/imageEdit/utils/getSelectedContentModelImage.d.ts +0 -5
- package/lib/imageEdit/utils/getSelectedContentModelImage.js +0 -16
- package/lib/imageEdit/utils/getSelectedContentModelImage.js.map +0 -1
- package/lib/pluginUtils/splitTextSegment.d.ts +0 -5
- package/lib/pluginUtils/splitTextSegment.js +0 -26
- package/lib/pluginUtils/splitTextSegment.js.map +0 -1
- package/lib-amd/imageEdit/utils/getSelectedContentModelImage.d.ts +0 -5
- package/lib-amd/imageEdit/utils/getSelectedContentModelImage.js +0 -17
- package/lib-amd/imageEdit/utils/getSelectedContentModelImage.js.map +0 -1
- package/lib-amd/pluginUtils/splitTextSegment.d.ts +0 -5
- package/lib-amd/pluginUtils/splitTextSegment.js +0 -26
- package/lib-amd/pluginUtils/splitTextSegment.js.map +0 -1
- package/lib-mjs/imageEdit/utils/getSelectedContentModelImage.d.ts +0 -5
- package/lib-mjs/imageEdit/utils/getSelectedContentModelImage.js +0 -12
- package/lib-mjs/imageEdit/utils/getSelectedContentModelImage.js.map +0 -1
- package/lib-mjs/pluginUtils/splitTextSegment.d.ts +0 -5
- package/lib-mjs/pluginUtils/splitTextSegment.js +0 -22
- package/lib-mjs/pluginUtils/splitTextSegment.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformHyphen = void 0;
|
|
4
|
-
var
|
|
4
|
+
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
@@ -10,7 +10,7 @@ function transformHyphen(previousSegment, paragraph, context) {
|
|
|
10
10
|
var dashes = segments[segments.length - 2];
|
|
11
11
|
if (dashes === '--') {
|
|
12
12
|
var textIndex = previousSegment.text.lastIndexOf('--');
|
|
13
|
-
var textSegment = (0,
|
|
13
|
+
var textSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, textIndex, textIndex + 2);
|
|
14
14
|
textSegment.text = textSegment.text.replace('--', '—');
|
|
15
15
|
context.canUndoByBackspace = true;
|
|
16
16
|
return true;
|
|
@@ -20,7 +20,7 @@ function transformHyphen(previousSegment, paragraph, context) {
|
|
|
20
20
|
var hasDashes = text && (text === null || text === void 0 ? void 0 : text.indexOf('--')) > -1;
|
|
21
21
|
if (hasDashes && text.trim() !== '--') {
|
|
22
22
|
var textIndex = previousSegment.text.indexOf(text);
|
|
23
|
-
var textSegment = (0,
|
|
23
|
+
var textSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, textIndex, textIndex + text.length - 1);
|
|
24
24
|
var textLength = textSegment.text.length;
|
|
25
25
|
if (textSegment.text[0] !== '-' && textSegment.text[textLength - 1] !== '-') {
|
|
26
26
|
textSegment.text = textSegment.text.replace('--', '—');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformHyphen.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/hyphen/transformHyphen.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"transformHyphen.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/hyphen/transformHyphen.ts"],"names":[],"mappings":";;;AAAA,2EAA+D;AAO/D;;GAEG;AACH,SAAgB,eAAe,CAC3B,eAAiC,EACjC,SAA8C,EAC9C,OAAkC;IAElC,IAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjD,IAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,IAAI,MAAM,KAAK,IAAI,EAAE;QACjB,IAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACzD,IAAM,WAAW,GAAG,IAAA,8CAAgB,EAAC,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;QAE3F,WAAW,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACvD,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAClC,OAAO,IAAI,CAAC;KACf;SAAM;QACH,IAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAM,SAAS,GAAG,IAAI,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAC,IAAI,CAAC,IAAG,CAAC,CAAC,CAAC;QACnD,IAAI,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;YACnC,IAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrD,IAAM,WAAW,GAAG,IAAA,8CAAgB,EAChC,eAAe,EACf,SAAS,EACT,SAAS,EACT,SAAS,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAC9B,CAAC;YAEF,IAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;YAC3C,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;gBACzE,WAAW,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;gBACvD,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;gBAClC,OAAO,IAAI,CAAC;aACf;SACJ;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAnCD,0CAmCC","sourcesContent":["import { splitTextSegment } from 'roosterjs-content-model-api';\nimport type {\n ContentModelText,\n FormatContentModelContext,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function transformHyphen(\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const segments = previousSegment.text.split(' ');\n const dashes = segments[segments.length - 2];\n if (dashes === '--') {\n const textIndex = previousSegment.text.lastIndexOf('--');\n const textSegment = splitTextSegment(previousSegment, paragraph, textIndex, textIndex + 2);\n\n textSegment.text = textSegment.text.replace('--', '—');\n context.canUndoByBackspace = true;\n return true;\n } else {\n const text = segments.pop();\n const hasDashes = text && text?.indexOf('--') > -1;\n if (hasDashes && text.trim() !== '--') {\n const textIndex = previousSegment.text.indexOf(text);\n const textSegment = splitTextSegment(\n previousSegment,\n paragraph,\n textIndex,\n textIndex + text.length - 1\n );\n\n const textLength = textSegment.text.length;\n if (textSegment.text[0] !== '-' && textSegment.text[textLength - 1] !== '-') {\n textSegment.text = textSegment.text.replace('--', '—');\n context.canUndoByBackspace = true;\n return true;\n }\n }\n }\n return false;\n}\n"]}
|
|
@@ -8,8 +8,10 @@ var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
|
8
8
|
*/
|
|
9
9
|
function createLink(editor) {
|
|
10
10
|
var anchorNode = null;
|
|
11
|
+
var links = [];
|
|
11
12
|
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (_model, linkSegment, _paragraph) {
|
|
12
13
|
if (linkSegment.link) {
|
|
14
|
+
links.push(linkSegment.link);
|
|
13
15
|
return true;
|
|
14
16
|
}
|
|
15
17
|
var linkData = null;
|
|
@@ -21,13 +23,16 @@ function createLink(editor) {
|
|
|
21
23
|
},
|
|
22
24
|
dataset: {},
|
|
23
25
|
});
|
|
26
|
+
if (linkSegment.link) {
|
|
27
|
+
links.push(linkSegment.link);
|
|
28
|
+
}
|
|
24
29
|
return true;
|
|
25
30
|
}
|
|
26
31
|
return false;
|
|
27
32
|
}, {
|
|
28
33
|
changeSource: roosterjs_content_model_dom_1.ChangeSource.AutoLink,
|
|
29
|
-
onNodeCreated: function (
|
|
30
|
-
if (!anchorNode) {
|
|
34
|
+
onNodeCreated: function (modelElement, node) {
|
|
35
|
+
if (!anchorNode && links.indexOf(modelElement) >= 0) {
|
|
31
36
|
anchorNode = node;
|
|
32
37
|
}
|
|
33
38
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AACpE,2EAAgG;AAGhG;;GAEG;AACH,SAAgB,UAAU,CAAC,MAAe;IACtC,IAAI,UAAU,GAAgB,IAAI,CAAC;IACnC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;QAC5B,IAAI,WAAW,CAAC,IAAI,EAAE;YAClB,OAAO,IAAI,CAAC;SACf;QACD,IAAI,QAAQ,GAAoB,IAAI,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAA,uCAAS,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE;YAC/D,IAAA,qCAAO,EAAC,WAAW,EAAE;gBACjB,MAAM,EAAE;oBACJ,IAAI,EAAE,QAAQ,CAAC,aAAa;oBAC5B,SAAS,EAAE,IAAI;iBAClB;gBACD,OAAO,EAAE,EAAE;aACd,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;SACf;QAED,OAAO,KAAK,CAAC;IACjB,CAAC,EACD;QACI,YAAY,EAAE,0CAAY,CAAC,QAAQ;QACnC,aAAa,EAAE,UAAC,
|
|
1
|
+
{"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AACpE,2EAAgG;AAGhG;;GAEG;AACH,SAAgB,UAAU,CAAC,MAAe;IACtC,IAAI,UAAU,GAAgB,IAAI,CAAC;IACnC,IAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;QAC5B,IAAI,WAAW,CAAC,IAAI,EAAE;YAClB,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC;SACf;QACD,IAAI,QAAQ,GAAoB,IAAI,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAA,uCAAS,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE;YAC/D,IAAA,qCAAO,EAAC,WAAW,EAAE;gBACjB,MAAM,EAAE;oBACJ,IAAI,EAAE,QAAQ,CAAC,aAAa;oBAC5B,SAAS,EAAE,IAAI;iBAClB;gBACD,OAAO,EAAE,EAAE;aACd,CAAC,CAAC;YACH,IAAI,WAAW,CAAC,IAAI,EAAE;gBAClB,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;aAChC;YACD,OAAO,IAAI,CAAC;SACf;QAED,OAAO,KAAK,CAAC;IACjB,CAAC,EACD;QACI,YAAY,EAAE,0CAAY,CAAC,QAAQ;QACnC,aAAa,EAAE,UAAC,YAAY,EAAE,IAAI;YAC9B,IAAI,CAAC,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,YAAgC,CAAC,IAAI,CAAC,EAAE;gBACrE,UAAU,GAAG,IAAI,CAAC;aACrB;QACL,CAAC;QACD,aAAa,EAAE,cAAM,OAAA,UAAU,EAAV,CAAU;KAClC,CACJ,CAAC;AACN,CAAC;AArCD,gCAqCC","sourcesContent":["import { addLink, ChangeSource } from 'roosterjs-content-model-dom';\nimport { formatTextSegmentBeforeSelectionMarker, matchLink } from 'roosterjs-content-model-api';\nimport type { ContentModelLink, IEditor, LinkData } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function createLink(editor: IEditor) {\n let anchorNode: Node | null = null;\n const links: ContentModelLink[] = [];\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, linkSegment, _paragraph) => {\n if (linkSegment.link) {\n links.push(linkSegment.link);\n return true;\n }\n let linkData: LinkData | null = null;\n if (!linkSegment.link && (linkData = matchLink(linkSegment.text))) {\n addLink(linkSegment, {\n format: {\n href: linkData.normalizedUrl,\n underline: true,\n },\n dataset: {},\n });\n if (linkSegment.link) {\n links.push(linkSegment.link);\n }\n return true;\n }\n\n return false;\n },\n {\n changeSource: ChangeSource.AutoLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n }\n );\n}\n"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLinkAfterSpace = void 0;
|
|
4
4
|
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
5
|
-
var splitTextSegment_1 = require("../../pluginUtils/splitTextSegment");
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
@@ -11,7 +10,7 @@ function createLinkAfterSpace(previousSegment, paragraph, context) {
|
|
|
11
10
|
var url = link === null || link === void 0 ? void 0 : link.trim();
|
|
12
11
|
var linkData = null;
|
|
13
12
|
if (url && link && (linkData = (0, roosterjs_content_model_api_1.matchLink)(url))) {
|
|
14
|
-
var linkSegment = (0,
|
|
13
|
+
var linkSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - link.trimLeft().length, previousSegment.text.trimRight().length);
|
|
15
14
|
linkSegment.link = {
|
|
16
15
|
format: {
|
|
17
16
|
href: linkData.normalizedUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLinkAfterSpace.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLinkAfterSpace.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"createLinkAfterSpace.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLinkAfterSpace.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAQ1E;;GAEG;AACH,SAAgB,oBAAoB,CAChC,eAAiC,EACjC,SAA8C,EAC9C,OAAkC;IAElC,IAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACnD,IAAM,GAAG,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,CAAC;IACzB,IAAI,QAAQ,GAAoB,IAAI,CAAC;IACrC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAA,uCAAS,EAAC,GAAG,CAAC,CAAC,EAAE;QAC5C,IAAM,WAAW,GAAG,IAAA,8CAAgB,EAChC,eAAe,EACf,SAAS,EACT,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,EACpD,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,CAC1C,CAAC;QACF,WAAW,CAAC,IAAI,GAAG;YACf,MAAM,EAAE;gBACJ,IAAI,EAAE,QAAQ,CAAC,aAAa;gBAC5B,SAAS,EAAE,IAAI;aAClB;YACD,OAAO,EAAE,EAAE;SACd,CAAC;QAEF,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAElC,OAAO,IAAI,CAAC;KACf;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AA5BD,oDA4BC","sourcesContent":["import { matchLink, splitTextSegment } from 'roosterjs-content-model-api';\nimport type {\n ContentModelText,\n FormatContentModelContext,\n LinkData,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function createLinkAfterSpace(\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n) {\n const link = previousSegment.text.split(' ').pop();\n const url = link?.trim();\n let linkData: LinkData | null = null;\n if (url && link && (linkData = matchLink(url))) {\n const linkSegment = splitTextSegment(\n previousSegment,\n paragraph,\n previousSegment.text.length - link.trimLeft().length,\n previousSegment.text.trimRight().length\n );\n linkSegment.link = {\n format: {\n href: linkData.normalizedUrl,\n underline: true,\n },\n dataset: {},\n };\n\n context.canUndoByBackspace = true;\n\n return true;\n }\n return false;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformFraction = void 0;
|
|
4
|
-
var
|
|
4
|
+
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
5
5
|
var FRACTIONS = new Map([
|
|
6
6
|
['1/2', '½'],
|
|
7
7
|
['1/4', '¼'],
|
|
@@ -17,7 +17,7 @@ function transformFraction(previousSegment, paragraph, context) {
|
|
|
17
17
|
if (fraction && text) {
|
|
18
18
|
var textLength = previousSegment.text.length - 1;
|
|
19
19
|
var textIndex = textLength - fraction.length;
|
|
20
|
-
var textSegment = (0,
|
|
20
|
+
var textSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, textIndex, textLength);
|
|
21
21
|
textSegment.text = text;
|
|
22
22
|
context.canUndoByBackspace = true;
|
|
23
23
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformFraction.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformFraction.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"transformFraction.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformFraction.ts"],"names":[],"mappings":";;;AAAA,2EAA+D;AAO/D,IAAM,SAAS,GAAwB,IAAI,GAAG,CAAiB;IAC3D,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,GAAG,CAAC;CACf,CAAC,CAAC;AAEH;;GAEG;AACH,SAAgB,iBAAiB,CAC7B,eAAiC,EACjC,SAA8C,EAC9C,OAAkC;;IAElC,IAAM,QAAQ,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;IAC/D,IAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE5D,IAAI,QAAQ,IAAI,IAAI,EAAE;QAClB,IAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACnD,IAAM,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC/C,IAAM,WAAW,GAAG,IAAA,8CAAgB,EAAC,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QACxF,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC;QAExB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAClC,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAnBD,8CAmBC","sourcesContent":["import { splitTextSegment } from 'roosterjs-content-model-api';\nimport type {\n ContentModelText,\n FormatContentModelContext,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\nconst FRACTIONS: Map<string, string> = new Map<string, string>([\n ['1/2', '½'],\n ['1/4', '¼'],\n ['3/4', '¾'],\n]);\n\n/**\n * @internal\n */\nexport function transformFraction(\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const fraction = previousSegment.text.split(' ').pop()?.trim();\n const text = fraction ? FRACTIONS.get(fraction) : undefined;\n\n if (fraction && text) {\n const textLength = previousSegment.text.length - 1;\n const textIndex = textLength - fraction.length;\n const textSegment = splitTextSegment(previousSegment, paragraph, textIndex, textLength);\n textSegment.text = text;\n\n context.canUndoByBackspace = true;\n return true;\n }\n\n return false;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformOrdinals = void 0;
|
|
4
|
-
var
|
|
4
|
+
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
5
5
|
var getOrdinal = function (value) {
|
|
6
6
|
var ORDINALS = {
|
|
7
7
|
1: 'st',
|
|
@@ -20,7 +20,7 @@ function transformOrdinals(previousSegment, paragraph, context) {
|
|
|
20
20
|
var ordinal = value.substring(value.length - 2);
|
|
21
21
|
var ordinalValue = parseInt(value);
|
|
22
22
|
if (ordinalValue && getOrdinal(ordinalValue) === ordinal) {
|
|
23
|
-
var ordinalSegment = (0,
|
|
23
|
+
var ordinalSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - 3, previousSegment.text.length - 1);
|
|
24
24
|
ordinalSegment.format.superOrSubScriptSequence = 'super';
|
|
25
25
|
context.canUndoByBackspace = true;
|
|
26
26
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":";;;AAAA,2EAA+D;AAO/D,IAAM,UAAU,GAAG,UAAC,KAAa;IAC7B,IAAM,QAAQ,GAA2B;QACrC,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;KACV,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC,CAAC;AAEF;;GAEG;AACH,SAAgB,iBAAiB,CAC7B,eAAiC,EACjC,SAA8C,EAC9C,OAAkC;;IAElC,IAAM,KAAK,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;IAC5D,IAAI,KAAK,EAAE;QACP,IAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAClD,IAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,OAAO,EAAE;YACtD,IAAM,cAAc,GAAG,IAAA,8CAAgB,EACnC,eAAe,EACf,SAAS,EACT,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAC/B,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAClC,CAAC;YAEF,cAAc,CAAC,MAAM,CAAC,wBAAwB,GAAG,OAAO,CAAC;YACzD,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAClC,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAvBD,8CAuBC","sourcesContent":["import { splitTextSegment } from 'roosterjs-content-model-api';\nimport type {\n ContentModelText,\n FormatContentModelContext,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\nconst getOrdinal = (value: number) => {\n const ORDINALS: Record<number, string> = {\n 1: 'st',\n 2: 'nd',\n 3: 'rd',\n };\n return ORDINALS[value] || 'th';\n};\n\n/**\n * @internal\n */\nexport function transformOrdinals(\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const value = previousSegment.text.split(' ').pop()?.trim();\n if (value) {\n const ordinal = value.substring(value.length - 2);\n const ordinalValue = parseInt(value);\n if (ordinalValue && getOrdinal(ordinalValue) === ordinal) {\n const ordinalSegment = splitTextSegment(\n previousSegment,\n paragraph,\n previousSegment.text.length - 3,\n previousSegment.text.length - 1\n );\n\n ordinalSegment.format.superOrSubScriptSequence = 'super';\n context.canUndoByBackspace = true;\n return true;\n }\n }\n return false;\n}\n"]}
|
package/lib/edit/EditPlugin.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* Options to customize the keyboard handling behavior of Edit plugin
|
|
4
|
+
*/
|
|
5
|
+
export declare type EditOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to handle Tab key in keyboard. @default true
|
|
8
|
+
*/
|
|
9
|
+
handleTabKey?: boolean;
|
|
10
|
+
};
|
|
2
11
|
/**
|
|
3
12
|
* Edit plugins helps editor to do editing operation on top of content model.
|
|
4
13
|
* This includes:
|
|
@@ -7,11 +16,17 @@ import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model
|
|
|
7
16
|
* 3. Tab Key
|
|
8
17
|
*/
|
|
9
18
|
export declare class EditPlugin implements EditorPlugin {
|
|
19
|
+
private options;
|
|
10
20
|
private editor;
|
|
11
21
|
private disposer;
|
|
12
22
|
private shouldHandleNextInputEvent;
|
|
13
23
|
private selectionAfterDelete;
|
|
14
24
|
private handleNormalEnter;
|
|
25
|
+
/**
|
|
26
|
+
* @param options An optional parameter that takes in an object of type EditOptions, which includes the following properties:
|
|
27
|
+
* handleTabKey: A boolean that enables or disables Tab key handling. Defaults to true.
|
|
28
|
+
*/
|
|
29
|
+
constructor(options?: EditOptions);
|
|
15
30
|
/**
|
|
16
31
|
* Get name of this plugin
|
|
17
32
|
*/
|
package/lib/edit/EditPlugin.js
CHANGED
|
@@ -8,6 +8,9 @@ var keyboardTab_1 = require("./keyboardTab");
|
|
|
8
8
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
9
9
|
var BACKSPACE_KEY = 8;
|
|
10
10
|
var DELETE_KEY = 46;
|
|
11
|
+
var DefaultOptions = {
|
|
12
|
+
handleTabKey: true,
|
|
13
|
+
};
|
|
11
14
|
/**
|
|
12
15
|
* Edit plugins helps editor to do editing operation on top of content model.
|
|
13
16
|
* This includes:
|
|
@@ -16,7 +19,13 @@ var DELETE_KEY = 46;
|
|
|
16
19
|
* 3. Tab Key
|
|
17
20
|
*/
|
|
18
21
|
var EditPlugin = /** @class */ (function () {
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* @param options An optional parameter that takes in an object of type EditOptions, which includes the following properties:
|
|
24
|
+
* handleTabKey: A boolean that enables or disables Tab key handling. Defaults to true.
|
|
25
|
+
*/
|
|
26
|
+
function EditPlugin(options) {
|
|
27
|
+
if (options === void 0) { options = DefaultOptions; }
|
|
28
|
+
this.options = options;
|
|
20
29
|
this.editor = null;
|
|
21
30
|
this.disposer = null;
|
|
22
31
|
this.shouldHandleNextInputEvent = false;
|
|
@@ -89,6 +98,7 @@ var EditPlugin = /** @class */ (function () {
|
|
|
89
98
|
*/
|
|
90
99
|
EditPlugin.prototype.willHandleEventExclusively = function (event) {
|
|
91
100
|
if (this.editor &&
|
|
101
|
+
this.options.handleTabKey &&
|
|
92
102
|
event.eventType == 'keyDown' &&
|
|
93
103
|
event.rawEvent.key == 'Tab' &&
|
|
94
104
|
!event.rawEvent.shiftKey) {
|
|
@@ -130,7 +140,9 @@ var EditPlugin = /** @class */ (function () {
|
|
|
130
140
|
}
|
|
131
141
|
break;
|
|
132
142
|
case 'Tab':
|
|
133
|
-
(
|
|
143
|
+
if (this.options.handleTabKey) {
|
|
144
|
+
(0, keyboardTab_1.keyboardTab)(editor, rawEvent);
|
|
145
|
+
}
|
|
134
146
|
break;
|
|
135
147
|
case 'Unidentified':
|
|
136
148
|
if (editor.getEnvironment().isAndroid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;A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gFAAgF;QAChF,uGAAuG;QACvG,IACI,CAAC,IAAI,CAAC,0BAA0B;YAChC,CAAC,CAAC,QAAQ,YAAY,UAAU,CAAC;YACjC,QAAQ,CAAC,gBAAgB,EAC3B;YACE,OAAO;SACV;QACD,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAC;QAExC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,QAAQ,QAAQ,CAAC,SAAS,EAAE;YACxB,KAAK,uBAAuB;gBACxB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;oBACzB,GAAG,EAAE,WAAW;oBAChB,OAAO,EAAE,aAAa;oBACtB,KAAK,EAAE,aAAa;iBACvB,CAAC,CACL,CAAC;gBACF,MAAM;YACV,KAAK,sBAAsB;gBACvB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;oBACzB,GAAG,EAAE,QAAQ;oBACb,OAAO,EAAE,UAAU;oBACnB,KAAK,EAAE,UAAU;iBACpB,CAAC,CACL,CAAC;gBACF,MAAM;SACb;QAED,IAAI,OAAO,EAAE;YACT,QAAQ,CAAC,cAAc,EAAE,CAAC;YAE1B,sEAAsE;YACtE,oDAAoD;YACpD,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;SACxD;IACL,CAAC;IACL,iBAAC;AAAD,CAAC,AA9LD,IA8LC;AA9LY,gCAAU","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardEnter } from './keyboardEnter';\nimport { keyboardInput } from './keyboardInput';\nimport { keyboardTab } from './keyboardTab';\nimport { parseTableCells } from 'roosterjs-content-model-dom';\nimport type {\n DOMSelection,\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n\n/**\n * Edit plugins helps editor to do editing operation on top of content model.\n * This includes:\n * 1. Delete Key\n * 2. Backspace Key\n * 3. Tab Key\n */\nexport class EditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private disposer: (() => void) | null = null;\n private shouldHandleNextInputEvent = false;\n private selectionAfterDelete: DOMSelection | null = null;\n private handleNormalEnter = false;\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Edit';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.handleNormalEnter = this.editor.isExperimentalFeatureEnabled('PersistCache');\n\n if (editor.getEnvironment().isAndroid) {\n this.disposer = this.editor.attachDomEvent({\n beforeinput: {\n beforeDispatch: e => this.handleBeforeInputEvent(editor, e),\n },\n });\n }\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n this.disposer?.();\n this.disposer = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'keyUp':\n if (this.selectionAfterDelete) {\n this.editor.setDOMSelection(this.selectionAfterDelete);\n this.selectionAfterDelete = null;\n }\n break;\n }\n }\n }\n\n /**\n * Check if the plugin should handle the given event exclusively.\n * Handle an event exclusively means other plugin will not receive this event in\n * onPluginEvent method.\n * If two plugins will return true in willHandleEventExclusively() for the same event,\n * the final result depends on the order of the plugins are added into editor\n * @param event The event to check:\n */\n willHandleEventExclusively(event: PluginEvent) {\n if (\n this.editor &&\n event.eventType == 'keyDown' &&\n event.rawEvent.key == 'Tab' &&\n !event.rawEvent.shiftKey\n ) {\n const selection = this.editor.getDOMSelection();\n const startContainer =\n selection?.type == 'range' && selection.range.collapsed\n ? selection.range.startContainer\n : null;\n const table = startContainer\n ? this.editor.getDOMHelper().findClosestElementAncestor(startContainer, 'table')\n : null;\n const parsedTable = table && parseTableCells(table);\n\n if (parsedTable) {\n const lastRow = parsedTable[parsedTable.length - 1];\n const lastCell = lastRow && lastRow[lastRow.length - 1];\n\n if (typeof lastCell == 'object' && lastCell.contains(startContainer)) {\n // When TAB in the last cell of a table, we will generate new table row, so prevent other plugins handling this event\n // e.g. SelectionPlugin will move the focus out of table, which is conflict with this behavior\n return true;\n }\n }\n }\n\n return false;\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n keyboardDelete(editor, rawEvent);\n break;\n\n case 'Delete':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n // And leave it to browser when shift key is pressed so that browser will trigger cut event\n if (!event.rawEvent.shiftKey) {\n keyboardDelete(editor, rawEvent);\n }\n break;\n\n case 'Tab':\n keyboardTab(editor, rawEvent);\n break;\n case 'Unidentified':\n if (editor.getEnvironment().isAndroid) {\n this.shouldHandleNextInputEvent = true;\n }\n break;\n\n case 'Enter':\n keyboardEnter(editor, rawEvent, this.handleNormalEnter);\n break;\n\n default:\n keyboardInput(editor, rawEvent);\n break;\n }\n }\n }\n\n private handleBeforeInputEvent(editor: IEditor, rawEvent: Event) {\n // Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key\n // Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic\n if (\n !this.shouldHandleNextInputEvent ||\n !(rawEvent instanceof InputEvent) ||\n rawEvent.defaultPrevented\n ) {\n return;\n }\n this.shouldHandleNextInputEvent = false;\n\n let handled = false;\n switch (rawEvent.inputType) {\n case 'deleteContentBackward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Backspace',\n keyCode: BACKSPACE_KEY,\n which: BACKSPACE_KEY,\n })\n );\n break;\n case 'deleteContentForward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Delete',\n keyCode: DELETE_KEY,\n which: DELETE_KEY,\n })\n );\n break;\n }\n\n if (handled) {\n rawEvent.preventDefault();\n\n // Restore the selection on keyup event to avoid the cursor jump issue\n // See: https://issues.chromium.org/issues/330596261\n this.selectionAfterDelete = editor.getDOMSelection();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,iDAAgD;AAChD,iDAAgD;AAChD,6CAA4C;AAC5C,2EAA8D;AAmB9D,IAAM,aAAa,GAAG,CAAC,CAAC;AACxB,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB,IAAM,cAAc,GAAyB;IACzC,YAAY,EAAE,IAAI;CACrB,CAAC;AAEF;;;;;;GAMG;AACH;IAOI;;;OAGG;IACH,oBAAoB,OAAqC;QAArC,wBAAA,EAAA,wBAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;QAVjD,WAAM,GAAmB,IAAI,CAAC;QAC9B,aAAQ,GAAwB,IAAI,CAAC;QACrC,+BAA0B,GAAG,KAAK,CAAC;QACnC,yBAAoB,GAAwB,IAAI,CAAC;QACjD,sBAAiB,GAAG,KAAK,CAAC;IAM0B,CAAC;IAE7D;;OAEG;IACH,4BAAO,GAAP;QACI,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,+BAAU,GAAV,UAAW,MAAe;QAA1B,iBAWC;QAVG,IAAI,CAAC,MAAM,G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E,aAAa;oBACtB,KAAK,EAAE,aAAa;iBACvB,CAAC,CACL,CAAC;gBACF,MAAM;YACV,KAAK,sBAAsB;gBACvB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;oBACzB,GAAG,EAAE,QAAQ;oBACb,OAAO,EAAE,UAAU;oBACnB,KAAK,EAAE,UAAU;iBACpB,CAAC,CACL,CAAC;gBACF,MAAM;SACb;QAED,IAAI,OAAO,EAAE;YACT,QAAQ,CAAC,cAAc,EAAE,CAAC;YAE1B,sEAAsE;YACtE,oDAAoD;YACpD,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;SACxD;IACL,CAAC;IACL,iBAAC;AAAD,CAAC,AAvMD,IAuMC;AAvMY,gCAAU","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardEnter } from './keyboardEnter';\nimport { keyboardInput } from './keyboardInput';\nimport { keyboardTab } from './keyboardTab';\nimport { parseTableCells } from 'roosterjs-content-model-dom';\nimport type {\n DOMSelection,\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the keyboard handling behavior of Edit plugin\n */\nexport type EditOptions = {\n /**\n * Whether to handle Tab key in keyboard. @default true\n */\n handleTabKey?: boolean;\n};\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n\nconst DefaultOptions: Partial<EditOptions> = {\n handleTabKey: true,\n};\n\n/**\n * Edit plugins helps editor to do editing operation on top of content model.\n * This includes:\n * 1. Delete Key\n * 2. Backspace Key\n * 3. Tab Key\n */\nexport class EditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private disposer: (() => void) | null = null;\n private shouldHandleNextInputEvent = false;\n private selectionAfterDelete: DOMSelection | null = null;\n private handleNormalEnter = false;\n\n /**\n * @param options An optional parameter that takes in an object of type EditOptions, which includes the following properties:\n * handleTabKey: A boolean that enables or disables Tab key handling. Defaults to true.\n */\n constructor(private options: EditOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Edit';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.handleNormalEnter = this.editor.isExperimentalFeatureEnabled('PersistCache');\n\n if (editor.getEnvironment().isAndroid) {\n this.disposer = this.editor.attachDomEvent({\n beforeinput: {\n beforeDispatch: e => this.handleBeforeInputEvent(editor, e),\n },\n });\n }\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n this.disposer?.();\n this.disposer = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'keyUp':\n if (this.selectionAfterDelete) {\n this.editor.setDOMSelection(this.selectionAfterDelete);\n this.selectionAfterDelete = null;\n }\n break;\n }\n }\n }\n\n /**\n * Check if the plugin should handle the given event exclusively.\n * Handle an event exclusively means other plugin will not receive this event in\n * onPluginEvent method.\n * If two plugins will return true in willHandleEventExclusively() for the same event,\n * the final result depends on the order of the plugins are added into editor\n * @param event The event to check:\n */\n willHandleEventExclusively(event: PluginEvent) {\n if (\n this.editor &&\n this.options.handleTabKey &&\n event.eventType == 'keyDown' &&\n event.rawEvent.key == 'Tab' &&\n !event.rawEvent.shiftKey\n ) {\n const selection = this.editor.getDOMSelection();\n const startContainer =\n selection?.type == 'range' && selection.range.collapsed\n ? selection.range.startContainer\n : null;\n const table = startContainer\n ? this.editor.getDOMHelper().findClosestElementAncestor(startContainer, 'table')\n : null;\n const parsedTable = table && parseTableCells(table);\n\n if (parsedTable) {\n const lastRow = parsedTable[parsedTable.length - 1];\n const lastCell = lastRow && lastRow[lastRow.length - 1];\n\n if (typeof lastCell == 'object' && lastCell.contains(startContainer)) {\n // When TAB in the last cell of a table, we will generate new table row, so prevent other plugins handling this event\n // e.g. SelectionPlugin will move the focus out of table, which is conflict with this behavior\n return true;\n }\n }\n }\n\n return false;\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n keyboardDelete(editor, rawEvent);\n break;\n\n case 'Delete':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n // And leave it to browser when shift key is pressed so that browser will trigger cut event\n if (!event.rawEvent.shiftKey) {\n keyboardDelete(editor, rawEvent);\n }\n break;\n\n case 'Tab':\n if (this.options.handleTabKey) {\n keyboardTab(editor, rawEvent);\n }\n break;\n case 'Unidentified':\n if (editor.getEnvironment().isAndroid) {\n this.shouldHandleNextInputEvent = true;\n }\n break;\n\n case 'Enter':\n keyboardEnter(editor, rawEvent, this.handleNormalEnter);\n break;\n\n default:\n keyboardInput(editor, rawEvent);\n break;\n }\n }\n }\n\n private handleBeforeInputEvent(editor: IEditor, rawEvent: Event) {\n // Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key\n // Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic\n if (\n !this.shouldHandleNextInputEvent ||\n !(rawEvent instanceof InputEvent) ||\n rawEvent.defaultPrevented\n ) {\n return;\n }\n this.shouldHandleNextInputEvent = false;\n\n let handled = false;\n switch (rawEvent.inputType) {\n case 'deleteContentBackward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Backspace',\n keyCode: BACKSPACE_KEY,\n which: BACKSPACE_KEY,\n })\n );\n break;\n case 'deleteContentForward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Delete',\n keyCode: DELETE_KEY,\n which: DELETE_KEY,\n })\n );\n break;\n }\n\n if (handled) {\n rawEvent.preventDefault();\n\n // Restore the selection on keyup event to avoid the cursor jump issue\n // See: https://issues.chromium.org/issues/330596261\n this.selectionAfterDelete = editor.getDOMSelection();\n }\n }\n}\n"]}
|
|
@@ -12,7 +12,7 @@ export declare class ImageEditPlugin implements ImageEditor, EditorPlugin {
|
|
|
12
12
|
protected editor: IEditor | null;
|
|
13
13
|
private shadowSpan;
|
|
14
14
|
private selectedImage;
|
|
15
|
-
wrapper: HTMLSpanElement | null;
|
|
15
|
+
protected wrapper: HTMLSpanElement | null;
|
|
16
16
|
private imageEditInfo;
|
|
17
17
|
private imageHTMLOptions;
|
|
18
18
|
private dndHelpers;
|
|
@@ -25,6 +25,7 @@ export declare class ImageEditPlugin implements ImageEditor, EditorPlugin {
|
|
|
25
25
|
private croppers;
|
|
26
26
|
private zoomScale;
|
|
27
27
|
private disposer;
|
|
28
|
+
protected isEditing: boolean;
|
|
28
29
|
constructor(options?: ImageEditOptions);
|
|
29
30
|
/**
|
|
30
31
|
* Get name of this plugin
|
|
@@ -49,18 +50,23 @@ export declare class ImageEditPlugin implements ImageEditor, EditorPlugin {
|
|
|
49
50
|
* exclusively by another plugin.
|
|
50
51
|
* @param event The event to handle:
|
|
51
52
|
*/
|
|
52
|
-
onPluginEvent(
|
|
53
|
+
onPluginEvent(event: PluginEvent): void;
|
|
54
|
+
private isImageSelection;
|
|
55
|
+
private mouseUpHandler;
|
|
56
|
+
private selectBeforeEditingImage;
|
|
57
|
+
private keyDownHandler;
|
|
58
|
+
private applyFormatWithContentModel;
|
|
53
59
|
private startEditing;
|
|
54
|
-
startRotateAndResize(editor: IEditor, image: HTMLImageElement
|
|
60
|
+
startRotateAndResize(editor: IEditor, image: HTMLImageElement): void;
|
|
55
61
|
private updateRotateHandleState;
|
|
56
62
|
isOperationAllowed(operation: ImageEditOperation): boolean;
|
|
57
63
|
canRegenerateImage(image: HTMLImageElement): boolean;
|
|
64
|
+
private startCropMode;
|
|
58
65
|
cropImage(): void;
|
|
59
66
|
private editImage;
|
|
60
67
|
private cleanInfo;
|
|
61
|
-
private formatImageWithContentModel;
|
|
62
68
|
private removeImageWrapper;
|
|
63
69
|
flipImage(direction: 'horizontal' | 'vertical'): void;
|
|
64
70
|
rotateImage(angleRad: number): void;
|
|
65
|
-
|
|
71
|
+
get isEditingImage(): boolean;
|
|
66
72
|
}
|