roosterjs-content-model-api 0.22.0 → 0.23.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/modelApi/block/setModelAlignment.d.ts +1 -1
- package/lib/modelApi/block/setModelAlignment.js +13 -3
- package/lib/modelApi/block/setModelAlignment.js.map +1 -1
- package/lib/modelApi/block/setModelDirection.js +20 -3
- package/lib/modelApi/block/setModelDirection.js.map +1 -1
- package/lib/modelApi/common/retrieveModelFormatState.js +5 -3
- package/lib/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
- package/lib/modelApi/selection/adjustTrailingSpaceSelection.js +56 -0
- package/lib/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
- package/lib/publicApi/block/setAlignment.d.ts +1 -1
- package/lib/publicApi/block/setAlignment.js.map +1 -1
- package/lib/publicApi/link/insertLink.js +2 -0
- package/lib/publicApi/link/insertLink.js.map +1 -1
- package/lib/publicApi/segment/toggleUnderline.js +2 -1
- package/lib/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib/publicApi/table/applyTableBorderFormat.js +18 -16
- package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-amd/modelApi/block/setModelAlignment.d.ts +1 -1
- package/lib-amd/modelApi/block/setModelAlignment.js +13 -3
- package/lib-amd/modelApi/block/setModelAlignment.js.map +1 -1
- package/lib-amd/modelApi/block/setModelDirection.js +20 -3
- package/lib-amd/modelApi/block/setModelDirection.js.map +1 -1
- package/lib-amd/modelApi/common/retrieveModelFormatState.js +5 -4
- package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
- package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js +55 -0
- package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
- package/lib-amd/publicApi/block/setAlignment.d.ts +1 -1
- package/lib-amd/publicApi/block/setAlignment.js.map +1 -1
- package/lib-amd/publicApi/link/insertLink.js +2 -1
- package/lib-amd/publicApi/link/insertLink.js.map +1 -1
- package/lib-amd/publicApi/segment/toggleUnderline.js +2 -2
- package/lib-amd/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib-amd/publicApi/table/applyTableBorderFormat.js +18 -16
- package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-mjs/modelApi/block/setModelAlignment.d.ts +1 -1
- package/lib-mjs/modelApi/block/setModelAlignment.js +13 -3
- package/lib-mjs/modelApi/block/setModelAlignment.js.map +1 -1
- package/lib-mjs/modelApi/block/setModelDirection.js +21 -4
- package/lib-mjs/modelApi/block/setModelDirection.js.map +1 -1
- package/lib-mjs/modelApi/common/retrieveModelFormatState.js +5 -3
- package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
- package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js +52 -0
- package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
- package/lib-mjs/publicApi/block/setAlignment.d.ts +1 -1
- package/lib-mjs/publicApi/block/setAlignment.js.map +1 -1
- package/lib-mjs/publicApi/link/insertLink.js +2 -0
- package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
- package/lib-mjs/publicApi/segment/toggleUnderline.js +2 -1
- package/lib-mjs/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js +18 -16
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/package.json +4 -4
|
@@ -2,4 +2,4 @@ import type { ContentModelDocument } from 'roosterjs-content-model-types';
|
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
|
-
export declare function setModelAlignment(model: ContentModelDocument, alignment: 'left' | 'center' | 'right'): boolean;
|
|
5
|
+
export declare function setModelAlignment(model: ContentModelDocument, alignment: 'left' | 'center' | 'right' | 'justify'): boolean;
|
|
@@ -16,6 +16,10 @@ var ResultMap = {
|
|
|
16
16
|
ltr: 'end',
|
|
17
17
|
rtl: 'start',
|
|
18
18
|
},
|
|
19
|
+
justify: {
|
|
20
|
+
ltr: 'justify',
|
|
21
|
+
rtl: 'justify',
|
|
22
|
+
},
|
|
19
23
|
};
|
|
20
24
|
var TableAlignMap = {
|
|
21
25
|
left: {
|
|
@@ -38,13 +42,19 @@ function setModelAlignment(model, alignment) {
|
|
|
38
42
|
var paragraphOrListItemOrTable = (0, roosterjs_content_model_core_1.getOperationalBlocks)(model, ['ListItem'], ['TableCell']);
|
|
39
43
|
paragraphOrListItemOrTable.forEach(function (_a) {
|
|
40
44
|
var block = _a.block;
|
|
41
|
-
var
|
|
42
|
-
if (block.blockType === 'Table') {
|
|
45
|
+
var newAlignment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];
|
|
46
|
+
if (block.blockType === 'Table' && alignment !== 'justify') {
|
|
43
47
|
(0, alignTable_1.alignTable)(block, TableAlignMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr']);
|
|
44
48
|
}
|
|
45
49
|
else if (block) {
|
|
50
|
+
if (block.blockType === 'BlockGroup' && block.blockGroupType === 'ListItem') {
|
|
51
|
+
block.blocks.forEach(function (b) {
|
|
52
|
+
var format = b.format;
|
|
53
|
+
format.textAlign = newAlignment;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
46
56
|
var format = block.format;
|
|
47
|
-
format.textAlign =
|
|
57
|
+
format.textAlign = newAlignment;
|
|
48
58
|
}
|
|
49
59
|
});
|
|
50
60
|
return paragraphOrListItemOrTable.length > 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setModelAlignment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelAlignment.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AACjD,6EAAoE;AAOpE,IAAM,SAAS,GAGX;IACA,IAAI,EAAE;QACF,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,KAAK;KACb;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,QAAQ;QACb,GAAG,EAAE,QAAQ;KAChB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,OAAO;KACf;CACJ,CAAC;AAEF,IAAM,aAAa,GAGf;IACA,IAAI,EAAE;QACF,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,YAAY;KACpB;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,aAAa;QAClB,GAAG,EAAE,aAAa;KACrB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,WAAW;KACnB;CACJ,CAAC;AAEF;;GAEG;AACH,SAAgB,iBAAiB,CAC7B,KAA2B,EAC3B,
|
|
1
|
+
{"version":3,"file":"setModelAlignment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelAlignment.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AACjD,6EAAoE;AAOpE,IAAM,SAAS,GAGX;IACA,IAAI,EAAE;QACF,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,KAAK;KACb;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,QAAQ;QACb,GAAG,EAAE,QAAQ;KAChB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,OAAO;KACf;IACD,OAAO,EAAE;QACL,GAAG,EAAE,SAAS;QACd,GAAG,EAAE,SAAS;KACjB;CACJ,CAAC;AAEF,IAAM,aAAa,GAGf;IACA,IAAI,EAAE;QACF,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,YAAY;KACpB;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,aAAa;QAClB,GAAG,EAAE,aAAa;KACrB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,WAAW;KACnB;CACJ,CAAC;AAEF;;GAEG;AACH,SAAgB,iBAAiB,CAC7B,KAA2B,EAC3B,SAAkD;IAElD,IAAM,0BAA0B,GAAG,IAAA,mDAAoB,EACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,WAAA;QACvC,IAAM,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3F,IAAI,KAAK,CAAC,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,SAAS,EAAE;YACxD,IAAA,uBAAU,EACN,KAAK,EACL,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAC5E,CAAC;SACL;aAAM,IAAI,KAAK,EAAE;YACd,IAAI,KAAK,CAAC,SAAS,KAAK,YAAY,IAAI,KAAK,CAAC,cAAc,KAAK,UAAU,EAAE;gBACzE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,CAAC;oBACV,IAAA,MAAM,GAAK,CAAC,OAAN,CAAO;oBACrB,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;gBACpC,CAAC,CAAC,CAAC;aACN;YACO,IAAA,MAAM,GAAK,KAAK,OAAV,CAAW;YACzB,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;SACnC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,0BAA0B,CAAC,MAAM,GAAG,CAAC,CAAC;AACjD,CAAC;AA9BD,8CA8BC","sourcesContent":["import { alignTable } from '../table/alignTable';\nimport { getOperationalBlocks } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelListItem,\n TableAlignOperation,\n} from 'roosterjs-content-model-types';\n\nconst ResultMap: Record<\n 'left' | 'center' | 'right' | 'justify',\n Record<'ltr' | 'rtl', 'start' | 'center' | 'end' | 'justify'>\n> = {\n left: {\n ltr: 'start',\n rtl: 'end',\n },\n center: {\n ltr: 'center',\n rtl: 'center',\n },\n right: {\n ltr: 'end',\n rtl: 'start',\n },\n justify: {\n ltr: 'justify',\n rtl: 'justify',\n },\n};\n\nconst TableAlignMap: Record<\n 'left' | 'center' | 'right',\n Record<'ltr' | 'rtl', TableAlignOperation>\n> = {\n left: {\n ltr: 'alignLeft',\n rtl: 'alignRight',\n },\n center: {\n ltr: 'alignCenter',\n rtl: 'alignCenter',\n },\n right: {\n ltr: 'alignRight',\n rtl: 'alignLeft',\n },\n};\n\n/**\n * @internal\n */\nexport function setModelAlignment(\n model: ContentModelDocument,\n alignment: 'left' | 'center' | 'right' | 'justify'\n) {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n const newAlignment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];\n if (block.blockType === 'Table' && alignment !== 'justify') {\n alignTable(\n block,\n TableAlignMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr']\n );\n } else if (block) {\n if (block.blockType === 'BlockGroup' && block.blockGroupType === 'ListItem') {\n block.blocks.forEach(b => {\n const { format } = b;\n format.textAlign = newAlignment;\n });\n }\n const { format } = block;\n format.textAlign = newAlignment;\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n"]}
|
|
@@ -20,26 +20,43 @@ function setModelDirection(model, direction) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
else if (block) {
|
|
23
|
-
internalSetDirection(block.format, direction);
|
|
23
|
+
internalSetDirection(block.format, direction, block);
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
return paragraphOrListItemOrTable.length > 0;
|
|
27
27
|
}
|
|
28
28
|
exports.setModelDirection = setModelDirection;
|
|
29
|
-
function internalSetDirection(format, direction) {
|
|
29
|
+
function internalSetDirection(format, direction, block) {
|
|
30
30
|
var wasRtl = format.direction == 'rtl';
|
|
31
31
|
var isRtl = direction == 'rtl';
|
|
32
32
|
if (wasRtl != isRtl) {
|
|
33
33
|
format.direction = direction;
|
|
34
34
|
// Adjust margin when change direction
|
|
35
35
|
// TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here
|
|
36
|
-
// TODO: Do we also need to handle border here?
|
|
37
36
|
var marginLeft = format.marginLeft;
|
|
38
37
|
var paddingLeft = format.paddingLeft;
|
|
39
38
|
setProperty(format, 'marginLeft', format.marginRight);
|
|
40
39
|
setProperty(format, 'marginRight', marginLeft);
|
|
41
40
|
setProperty(format, 'paddingLeft', format.paddingRight);
|
|
42
41
|
setProperty(format, 'paddingRight', paddingLeft);
|
|
42
|
+
// If whole Table direction changed, flip cell side borders
|
|
43
|
+
if (block && block.blockType == 'Table') {
|
|
44
|
+
block.rows.forEach(function (row) {
|
|
45
|
+
row.cells.forEach(function (cell) {
|
|
46
|
+
// Optimise by skipping cells with unchanged borders
|
|
47
|
+
(0, roosterjs_content_model_core_1.updateTableCellMetadata)(cell, function (metadata) {
|
|
48
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.borderOverride) {
|
|
49
|
+
var storeBorderLeft = cell.format.borderLeft;
|
|
50
|
+
setProperty(cell.format, 'borderLeft', cell.format.borderRight);
|
|
51
|
+
setProperty(cell.format, 'borderRight', storeBorderLeft);
|
|
52
|
+
}
|
|
53
|
+
return metadata;
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
// Apply changed borders
|
|
58
|
+
(0, roosterjs_content_model_core_1.applyTableFormat)(block, undefined /* newFormat */, true /* keepCellShade*/);
|
|
59
|
+
}
|
|
43
60
|
}
|
|
44
61
|
}
|
|
45
62
|
function setProperty(format, key, value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":";;;AAAA,+EAA8E;AAC9E,
|
|
1
|
+
{"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":";;;AAAA,+EAA8E;AAC9E,6EAKsC;AAWtC;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAA2B,EAAE,SAAwB;IACnF,IAAM,0BAA0B,GAAG,IAAA,mDAAoB,EACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,WAAA;QACvC,IAAI,IAAA,iDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;YAC7D,IAAM,KAAK,GAAG,IAAA,qDAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAEtD,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;gBACd,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;oBACrB,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;gBACvC,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,EAA7C,CAA6C,CAAC,CAAC;YAChF,CAAC,CAAC,CAAC;SACN;aAAM,IAAI,KAAK,EAAE;YACd,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;SACxD;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,0BAA0B,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EAAE,eAAe,CAAC,CAAC;yBAC5D;wBACD,OAAO,QAAQ,CAAC;oBACpB,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YAEH,wBAAwB;YACxB,IAAA,+CAAgB,EAAC,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;SAC/E;KACJ;AACL,CAAC;AAED,SAAS,WAAW,CAChB,MAAmD,EACnD,GAAwD,EACxD,KAAyB;IAEzB,IAAI,KAAK,EAAE;QACP,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;KACvB;SAAM;QACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACtB;AACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport {\n applyTableFormat,\n getOperationalBlocks,\n isBlockGroupOfType,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n BorderFormat,\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelDocument,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setModelDirection(model: ContentModelDocument, direction: 'ltr' | 'rtl') {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(item => {\n item.levels.forEach(level => {\n level.format.direction = direction;\n });\n\n item.blocks.forEach(block => internalSetDirection(block.format, direction));\n });\n } else if (block) {\n internalSetDirection(block.format, direction, block);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(\n format: ContentModelBlockFormat,\n direction: 'ltr' | 'rtl',\n block?: ContentModelBlock\n) {\n const wasRtl = format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n format.direction = direction;\n\n // Adjust margin when change direction\n // TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n\n // If whole Table direction changed, flip cell side borders\n if (block && block.blockType == 'Table') {\n block.rows.forEach(row => {\n row.cells.forEach(cell => {\n // Optimise by skipping cells with unchanged borders\n updateTableCellMetadata(cell, metadata => {\n if (metadata?.borderOverride) {\n const storeBorderLeft = cell.format.borderLeft;\n setProperty(cell.format, 'borderLeft', cell.format.borderRight);\n setProperty(cell.format, 'borderRight', storeBorderLeft);\n }\n return metadata;\n });\n });\n });\n\n // Apply changed borders\n applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);\n }\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat & BorderFormat,\n key: keyof (MarginFormat & PaddingFormat & BorderFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.retrieveModelFormatState = void 0;
|
|
4
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
4
5
|
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
5
6
|
/**
|
|
6
7
|
* @internal
|
|
@@ -95,7 +96,7 @@ function retrieveSegmentFormat(result, isFirst, mergedFormat) {
|
|
|
95
96
|
mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);
|
|
96
97
|
mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);
|
|
97
98
|
mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);
|
|
98
|
-
mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst);
|
|
99
|
+
mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst, function (val) { return (0, roosterjs_content_model_dom_1.parseValueWithUnit)(val, undefined, 'pt') + 'pt'; });
|
|
99
100
|
mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);
|
|
100
101
|
mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);
|
|
101
102
|
mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);
|
|
@@ -150,13 +151,14 @@ function retrieveImageFormat(image, result) {
|
|
|
150
151
|
borderRadius: format.borderRadius,
|
|
151
152
|
};
|
|
152
153
|
}
|
|
153
|
-
function mergeValue(format, key, newValue, isFirst) {
|
|
154
|
+
function mergeValue(format, key, newValue, isFirst, parseFn) {
|
|
155
|
+
if (parseFn === void 0) { parseFn = function (val) { return val; }; }
|
|
154
156
|
if (isFirst) {
|
|
155
157
|
if (newValue !== undefined) {
|
|
156
158
|
format[key] = newValue;
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
|
-
else if (newValue !== format[key]) {
|
|
161
|
+
else if (parseFn(newValue) !== parseFn(format[key])) {
|
|
160
162
|
delete format[key];
|
|
161
163
|
}
|
|
162
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieveModelFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/common/retrieveModelFormatState.ts"],"names":[],"mappings":";;;AAAA,6EAMsC;AActC;;GAEG;AACH,SAAgB,wBAAwB,CACpC,KAA2B,EAC3B,aAA+C,EAC/C,WAAoC;IAEpC,IAAI,iBAAoD,CAAC;IACzD,IAAI,UAAyC,CAAC;IAC9C,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,cAAc,GAAG,IAAI,CAAC;IAE1B,IAAA,gDAAiB,EACb,KAAK,E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derValues,\n getClosestAncestorBlockGroupIndex,\n isBold,\n iterateSelections,\n updateTableMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelFormatState,\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelImage,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function retrieveModelFormatState(\n model: ContentModelDocument,\n pendingFormat: ContentModelSegmentFormat | null,\n formatState: ContentModelFormatState\n) {\n let firstTableContext: TableSelectionContext | undefined;\n let firstBlock: ContentModelBlock | undefined;\n let isFirst = true;\n let isFirstImage = true;\n let isFirstSegment = true;\n\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n // Structure formats\n retrieveStructureFormat(formatState, path, isFirst);\n\n // Multiple line format\n if (block) {\n if (firstBlock) {\n formatState.isMultilineSelection = true;\n } else {\n firstBlock = block;\n }\n }\n\n if (block?.blockType == 'Paragraph') {\n // Paragraph formats\n retrieveParagraphFormat(formatState, block, isFirst);\n\n // Segment formats\n segments?.forEach(segment => {\n if (isFirstSegment || segment.segmentType != 'SelectionMarker') {\n const modelFormat = Object.assign({}, model.format);\n delete modelFormat?.italic;\n delete modelFormat?.underline;\n delete modelFormat?.fontWeight;\n\n retrieveSegmentFormat(\n formatState,\n isFirst,\n Object.assign(\n {},\n modelFormat,\n block.format,\n block.decorator?.format,\n segment.format,\n segment.code?.format,\n segment.link?.format,\n pendingFormat\n )\n );\n\n mergeValue(formatState, 'isCodeInline', !!segment?.code, isFirst);\n }\n\n // We only care the format of selection marker when it is the first selected segment. This is because when selection marker\n // is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line\n // is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to\n // ignore it\n isFirstSegment = false;\n\n formatState.canUnlink = formatState.canUnlink || !!segment.link;\n formatState.canAddImageAltText =\n formatState.canAddImageAltText ||\n segments.some(segment => segment.segmentType == 'Image');\n\n isFirst = false;\n\n if (segment.segmentType === 'Image') {\n if (isFirstImage) {\n retrieveImageFormat(segment, formatState);\n isFirstImage = false;\n } else {\n formatState.imageFormat = undefined;\n }\n }\n });\n\n isFirst = false;\n }\n\n if (tableContext) {\n if (firstTableContext) {\n const { table, colIndex, rowIndex } = firstTableContext;\n\n // Merge table format\n if (\n tableContext.table == table &&\n (tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)\n ) {\n formatState.canMergeTableCell = true;\n formatState.isMultilineSelection = true;\n }\n } else {\n // Table formats\n retrieveTableFormat(tableContext, formatState);\n firstTableContext = tableContext;\n }\n }\n\n // TODO: Support Code block in format state for Content Model\n },\n {\n includeListFormatHolder: 'never',\n }\n );\n\n if (formatState.fontSize) {\n formatState.fontSize = px2Pt(formatState.fontSize);\n }\n}\n\nfunction retrieveSegmentFormat(\n result: ContentModelFormatState,\n isFirst: boolean,\n mergedFormat: ContentModelSegmentFormat\n) {\n const superOrSubscript = mergedFormat.superOrSubScriptSequence?.split(' ')?.pop();\n\n mergeValue(result, 'isBold', isBold(mergedFormat.fontWeight), isFirst);\n mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);\n mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);\n mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);\n mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);\n mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);\n mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);\n\n mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);\n mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst);\n mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);\n mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);\n mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);\n\n //TODO: handle block owning segments with different line-heights\n mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);\n}\n\nfunction retrieveParagraphFormat(\n result: ContentModelFormatState,\n paragraph: ContentModelParagraph,\n isFirst: boolean\n) {\n const headingLevel = parseInt((paragraph.decorator?.tagName || '').substring(1));\n const validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;\n\n mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);\n mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);\n mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);\n mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);\n mergeValue(result, 'direction', paragraph.format.direction, isFirst);\n}\n\nfunction retrieveStructureFormat(\n result: ContentModelFormatState,\n path: ContentModelBlockGroup[],\n isFirst: boolean\n) {\n const listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], []);\n const containerIndex = getClosestAncestorBlockGroupIndex(path, ['FormatContainer'], []);\n\n if (listItemIndex >= 0) {\n const listItem = path[listItemIndex] as ContentModelListItem;\n const listType = listItem?.levels[listItem.levels.length - 1]?.listType;\n\n mergeValue(result, 'isBullet', listType == 'UL', isFirst);\n mergeValue(result, 'isNumbering', listType == 'OL', isFirst);\n }\n\n mergeValue(\n result,\n 'isBlockQuote',\n containerIndex >= 0 &&\n (path[containerIndex] as ContentModelFormatContainer)?.tagName == 'blockquote',\n isFirst\n );\n}\n\nfunction retrieveTableFormat(tableContext: TableSelectionContext, result: ContentModelFormatState) {\n const tableFormat = updateTableMetadata(tableContext.table);\n\n result.isInTable = true;\n result.tableHasHeader = tableContext.table.rows.some(row =>\n row.cells.some(cell => cell.isHeader)\n );\n\n if (tableFormat) {\n result.tableFormat = tableFormat;\n }\n}\n\nfunction retrieveImageFormat(image: ContentModelImage, result: ContentModelFormatState) {\n const { format } = image;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n result.imageFormat = {\n borderColor,\n borderWidth,\n borderStyle,\n boxShadow: format.boxShadow,\n borderRadius: format.borderRadius,\n };\n}\n\nfunction mergeValue<K extends keyof ContentModelFormatState>(\n format: ContentModelFormatState,\n key: K,\n newValue: ContentModelFormatState[K] | undefined,\n isFirst: boolean\n) {\n if (isFirst) {\n if (newValue !== undefined) {\n format[key] = newValue;\n }\n } else if (newValue !== format[key]) {\n delete format[key];\n }\n}\n\nfunction px2Pt(px: string) {\n if (px && px.indexOf('px') == px.length - 2) {\n // Edge may not handle the floating computing well which causes the calculated value is a little less than actual value\n // So add 0.05 to fix it\n return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';\n }\n return px;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"retrieveModelFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/common/retrieveModelFormatState.ts"],"names":[],"mappings":";;;AAAA,2EAAiE;AACjE,6EAMsC;AActC;;GAEG;AACH,SAAgB,wBAAwB,CACpC,KAA2B,EAC3B,aAA+C,EAC/C,WAAoC;IAEpC,IAAI,iBAAoD,CAAC;IACzD,IAAI,UAAyC,CAAC;IAC9C,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,cAAc,GAAG,IAAI,CAAC;IAE1B,IAAA,gDAAiB,EACb,KAAK,EACL,UAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ;QAChC,oBAAoB;QACpB,uBAAuB,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAEpD,uBAAuB;QACvB,IAAI,KAAK,EAAE;YACP,IAAI,UAAU,EAAE;gBACZ,WAAW,CAAC,oBAAoB,GAAG,IAAI,CAAC;aAC3C;iBAAM;gBACH,UAAU,GAAG,KAAK,CAAC;aACtB;SACJ;QAED,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,W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AC;IAC/D,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;IAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;IAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;IAC1C,MAAM,CAAC,WAAW,GAAG;QACjB,WAAW,aAAA;QACX,WAAW,aAAA;QACX,WAAW,aAAA;QACX,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;KACpC,CAAC;AACN,CAAC;AAED,SAAS,UAAU,CACf,MAA+B,EAC/B,GAAM,EACN,QAAgD,EAChD,OAAgB,EAChB,OAAqF;IAArF,wBAAA,EAAA,oBAA2E,GAAG,IAAI,OAAA,GAAG,EAAH,CAAG;IAErF,IAAI,OAAO,EAAE;QACT,IAAI,QAAQ,KAAK,SAAS,EAAE;YACxB,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;SAC1B;KACJ;SAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;QACnD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACtB;AACL,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACrB,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE;QACzC,uHAAuH;QACvH,wBAAwB;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;KAC9D;IACD,OAAO,EAAE,CAAC;AACd,CAAC","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getClosestAncestorBlockGroupIndex,\n isBold,\n iterateSelections,\n updateTableMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelFormatState,\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelImage,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function retrieveModelFormatState(\n model: ContentModelDocument,\n pendingFormat: ContentModelSegmentFormat | null,\n formatState: ContentModelFormatState\n) {\n let firstTableContext: TableSelectionContext | undefined;\n let firstBlock: ContentModelBlock | undefined;\n let isFirst = true;\n let isFirstImage = true;\n let isFirstSegment = true;\n\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n // Structure formats\n retrieveStructureFormat(formatState, path, isFirst);\n\n // Multiple line format\n if (block) {\n if (firstBlock) {\n formatState.isMultilineSelection = true;\n } else {\n firstBlock = block;\n }\n }\n\n if (block?.blockType == 'Paragraph') {\n // Paragraph formats\n retrieveParagraphFormat(formatState, block, isFirst);\n\n // Segment formats\n segments?.forEach(segment => {\n if (isFirstSegment || segment.segmentType != 'SelectionMarker') {\n const modelFormat = Object.assign({}, model.format);\n delete modelFormat?.italic;\n delete modelFormat?.underline;\n delete modelFormat?.fontWeight;\n\n retrieveSegmentFormat(\n formatState,\n isFirst,\n Object.assign(\n {},\n modelFormat,\n block.format,\n block.decorator?.format,\n segment.format,\n segment.code?.format,\n segment.link?.format,\n pendingFormat\n )\n );\n\n mergeValue(formatState, 'isCodeInline', !!segment?.code, isFirst);\n }\n\n // We only care the format of selection marker when it is the first selected segment. This is because when selection marker\n // is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line\n // is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to\n // ignore it\n isFirstSegment = false;\n\n formatState.canUnlink = formatState.canUnlink || !!segment.link;\n formatState.canAddImageAltText =\n formatState.canAddImageAltText ||\n segments.some(segment => segment.segmentType == 'Image');\n\n isFirst = false;\n\n if (segment.segmentType === 'Image') {\n if (isFirstImage) {\n retrieveImageFormat(segment, formatState);\n isFirstImage = false;\n } else {\n formatState.imageFormat = undefined;\n }\n }\n });\n\n isFirst = false;\n }\n\n if (tableContext) {\n if (firstTableContext) {\n const { table, colIndex, rowIndex } = firstTableContext;\n\n // Merge table format\n if (\n tableContext.table == table &&\n (tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)\n ) {\n formatState.canMergeTableCell = true;\n formatState.isMultilineSelection = true;\n }\n } else {\n // Table formats\n retrieveTableFormat(tableContext, formatState);\n firstTableContext = tableContext;\n }\n }\n\n // TODO: Support Code block in format state for Content Model\n },\n {\n includeListFormatHolder: 'never',\n }\n );\n\n if (formatState.fontSize) {\n formatState.fontSize = px2Pt(formatState.fontSize);\n }\n}\n\nfunction retrieveSegmentFormat(\n result: ContentModelFormatState,\n isFirst: boolean,\n mergedFormat: ContentModelSegmentFormat\n) {\n const superOrSubscript = mergedFormat.superOrSubScriptSequence?.split(' ')?.pop();\n\n mergeValue(result, 'isBold', isBold(mergedFormat.fontWeight), isFirst);\n mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);\n mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);\n mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);\n mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);\n mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);\n mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);\n\n mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);\n mergeValue(\n result,\n 'fontSize',\n mergedFormat.fontSize,\n isFirst,\n val => parseValueWithUnit(val, undefined, 'pt') + 'pt'\n );\n mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);\n mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);\n mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);\n\n //TODO: handle block owning segments with different line-heights\n mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);\n}\n\nfunction retrieveParagraphFormat(\n result: ContentModelFormatState,\n paragraph: ContentModelParagraph,\n isFirst: boolean\n) {\n const headingLevel = parseInt((paragraph.decorator?.tagName || '').substring(1));\n const validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;\n\n mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);\n mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);\n mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);\n mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);\n mergeValue(result, 'direction', paragraph.format.direction, isFirst);\n}\n\nfunction retrieveStructureFormat(\n result: ContentModelFormatState,\n path: ContentModelBlockGroup[],\n isFirst: boolean\n) {\n const listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], []);\n const containerIndex = getClosestAncestorBlockGroupIndex(path, ['FormatContainer'], []);\n\n if (listItemIndex >= 0) {\n const listItem = path[listItemIndex] as ContentModelListItem;\n const listType = listItem?.levels[listItem.levels.length - 1]?.listType;\n\n mergeValue(result, 'isBullet', listType == 'UL', isFirst);\n mergeValue(result, 'isNumbering', listType == 'OL', isFirst);\n }\n\n mergeValue(\n result,\n 'isBlockQuote',\n containerIndex >= 0 &&\n (path[containerIndex] as ContentModelFormatContainer)?.tagName == 'blockquote',\n isFirst\n );\n}\n\nfunction retrieveTableFormat(tableContext: TableSelectionContext, result: ContentModelFormatState) {\n const tableFormat = updateTableMetadata(tableContext.table);\n\n result.isInTable = true;\n result.tableHasHeader = tableContext.table.rows.some(row =>\n row.cells.some(cell => cell.isHeader)\n );\n\n if (tableFormat) {\n result.tableFormat = tableFormat;\n }\n}\n\nfunction retrieveImageFormat(image: ContentModelImage, result: ContentModelFormatState) {\n const { format } = image;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n result.imageFormat = {\n borderColor,\n borderWidth,\n borderStyle,\n boxShadow: format.boxShadow,\n borderRadius: format.borderRadius,\n };\n}\n\nfunction mergeValue<K extends keyof ContentModelFormatState>(\n format: ContentModelFormatState,\n key: K,\n newValue: ContentModelFormatState[K] | undefined,\n isFirst: boolean,\n parseFn: (val: ContentModelFormatState[K]) => ContentModelFormatState[K] = val => val\n) {\n if (isFirst) {\n if (newValue !== undefined) {\n format[key] = newValue;\n }\n } else if (parseFn(newValue) !== parseFn(format[key])) {\n delete format[key];\n }\n}\n\nfunction px2Pt(px: string) {\n if (px && px.indexOf('px') == px.length - 2) {\n // Edge may not handle the floating computing well which causes the calculated value is a little less than actual value\n // So add 0.05 to fix it\n return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';\n }\n return px;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContentModelDocument } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* If a format cannot be applied to be applied to a trailing space, split the trailing space into a separate segment
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare function adjustTrailingSpaceSelection(model: ContentModelDocument): void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adjustTrailingSpaceSelection = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
6
|
+
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
7
|
+
/**
|
|
8
|
+
* If a format cannot be applied to be applied to a trailing space, split the trailing space into a separate segment
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function adjustTrailingSpaceSelection(model) {
|
|
12
|
+
(0, roosterjs_content_model_core_1.iterateSelections)(model, function (_, __, block, segments) {
|
|
13
|
+
if ((block === null || block === void 0 ? void 0 : block.blockType) === 'Paragraph' && segments && segments.length > 0) {
|
|
14
|
+
if (segments.length === 1 &&
|
|
15
|
+
segments[0].segmentType === 'Text' &&
|
|
16
|
+
shouldSplitTrailingSpace(segments[0])) {
|
|
17
|
+
splitTextSegment(block, segments[0]);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
var lastTextSegment = segments[segments.length - 1].segmentType === 'SelectionMarker'
|
|
21
|
+
? segments[segments.length - 2]
|
|
22
|
+
: segments[segments.length - 1];
|
|
23
|
+
if (lastTextSegment &&
|
|
24
|
+
lastTextSegment.segmentType === 'Text' &&
|
|
25
|
+
shouldSplitTrailingSpace(lastTextSegment)) {
|
|
26
|
+
splitTextSegment(block, lastTextSegment);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.adjustTrailingSpaceSelection = adjustTrailingSpaceSelection;
|
|
34
|
+
function shouldSplitTrailingSpace(segment) {
|
|
35
|
+
return segment.isSelected && hasTrailingSpace(segment.text) && !isTrailingSpace(segment.text);
|
|
36
|
+
}
|
|
37
|
+
function hasTrailingSpace(text) {
|
|
38
|
+
return text.trimRight() !== text;
|
|
39
|
+
}
|
|
40
|
+
function isTrailingSpace(text) {
|
|
41
|
+
return text.trimRight().length == 0;
|
|
42
|
+
}
|
|
43
|
+
function splitTextSegment(block, textSegment) {
|
|
44
|
+
var _a;
|
|
45
|
+
var text = textSegment.text.trimRight();
|
|
46
|
+
var trailingSpace = textSegment.text.substring(text.length);
|
|
47
|
+
var newText = (0, roosterjs_content_model_dom_1.createText)(text, textSegment.format, textSegment.link, textSegment.code);
|
|
48
|
+
newText.isSelected = true;
|
|
49
|
+
var trailingSpaceLink = textSegment.link
|
|
50
|
+
? (0, tslib_1.__assign)((0, tslib_1.__assign)({}, textSegment.link), { format: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (_a = textSegment.link) === null || _a === void 0 ? void 0 : _a.format), { underline: false }) }) : undefined;
|
|
51
|
+
var trailingSpaceSegment = (0, roosterjs_content_model_dom_1.createText)(trailingSpace, undefined, trailingSpaceLink, textSegment.code);
|
|
52
|
+
trailingSpaceSegment.isSelected = true;
|
|
53
|
+
var index = block.segments.indexOf(textSegment);
|
|
54
|
+
block.segments.splice(index, 1, newText, trailingSpaceSegment);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=adjustTrailingSpaceSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adjustTrailingSpaceSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/selection/adjustTrailingSpaceSelection.ts"],"names":[],"mappings":";;;;AAAA,2EAAyD;AACzD,6EAAiE;AAOjE;;;GAGG;AACH,SAAgB,4BAA4B,CAAC,KAA2B;IACpE,IAAA,gDAAiB,EAAC,KAAK,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ;QAC5C,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,WAAW,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACrE,IACI,QAAQ,CAAC,MAAM,KAAK,CAAC;gBACrB,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,MAAM;gBAClC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EACvC;gBACE,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;aACxC;iBAAM;gBACH,IAAM,eAAe,GACjB,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,WAAW,KAAK,iBAAiB;oBAC3D,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;oBAC/B,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBACxC,IACI,eAAe;oBACf,eAAe,CAAC,WAAW,KAAK,MAAM;oBACt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AI,CACnB,CAAC;IACF,oBAAoB,CAAC,UAAU,GAAG,IAAI,CAAC;IACvC,IAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAClD,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { createText } from 'roosterjs-content-model-dom';\nimport { iterateSelections } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelText,\n} from 'roosterjs-content-model-types';\n\n/**\n * If a format cannot be applied to be applied to a trailing space, split the trailing space into a separate segment\n * @internal\n */\nexport function adjustTrailingSpaceSelection(model: ContentModelDocument) {\n iterateSelections(model, (_, __, block, segments) => {\n if (block?.blockType === 'Paragraph' && segments && segments.length > 0) {\n if (\n segments.length === 1 &&\n segments[0].segmentType === 'Text' &&\n shouldSplitTrailingSpace(segments[0])\n ) {\n splitTextSegment(block, segments[0]);\n } else {\n const lastTextSegment =\n segments[segments.length - 1].segmentType === 'SelectionMarker'\n ? segments[segments.length - 2]\n : segments[segments.length - 1];\n if (\n lastTextSegment &&\n lastTextSegment.segmentType === 'Text' &&\n shouldSplitTrailingSpace(lastTextSegment)\n ) {\n splitTextSegment(block, lastTextSegment);\n }\n }\n }\n\n return false;\n });\n}\n\nfunction shouldSplitTrailingSpace(segment: ContentModelText) {\n return segment.isSelected && hasTrailingSpace(segment.text) && !isTrailingSpace(segment.text);\n}\n\nfunction hasTrailingSpace(text: string) {\n return text.trimRight() !== text;\n}\n\nfunction isTrailingSpace(text: string) {\n return text.trimRight().length == 0;\n}\n\nfunction splitTextSegment(block: ContentModelParagraph, textSegment: Readonly<ContentModelText>) {\n const text = textSegment.text.trimRight();\n const trailingSpace = textSegment.text.substring(text.length);\n const newText = createText(text, textSegment.format, textSegment.link, textSegment.code);\n newText.isSelected = true;\n const trailingSpaceLink = textSegment.link\n ? {\n ...textSegment.link,\n format: {\n ...textSegment.link?.format,\n underline: false, // Remove underline for trailing space link\n },\n }\n : undefined;\n const trailingSpaceSegment = createText(\n trailingSpace,\n undefined,\n trailingSpaceLink,\n textSegment.code\n );\n trailingSpaceSegment.isSelected = true;\n const index = block.segments.indexOf(textSegment);\n block.segments.splice(index, 1, newText, trailingSpaceSegment);\n}\n"]}
|
|
@@ -4,4 +4,4 @@ import type { IStandaloneEditor } from 'roosterjs-content-model-types';
|
|
|
4
4
|
* @param editor The editor to set alignment
|
|
5
5
|
* @param alignment Alignment value: left, center or right
|
|
6
6
|
*/
|
|
7
|
-
export default function setAlignment(editor: IStandaloneEditor, alignment: 'left' | 'center' | 'right'): void;
|
|
7
|
+
export default function setAlignment(editor: IStandaloneEditor, alignment: 'left' | 'center' | 'right' | 'justify'): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setAlignment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/block/setAlignment.ts"],"names":[],"mappings":";;AAAA,4EAA2E;AAG3E;;;;GAIG;AACH,SAAwB,YAAY,CAChC,MAAyB,EACzB,
|
|
1
|
+
{"version":3,"file":"setAlignment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/block/setAlignment.ts"],"names":[],"mappings":";;AAAA,4EAA2E;AAG3E;;;;GAIG;AACH,SAAwB,YAAY,CAChC,MAAyB,EACzB,SAAkD;IAElD,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CAAC,UAAA,KAAK,IAAI,OAAA,IAAA,qCAAiB,EAAC,KAAK,EAAE,SAAS,CAAC,EAAnC,CAAmC,EAAE;QACpE,OAAO,EAAE,cAAc;KAC1B,CAAC,CAAC;AACP,CAAC;AATD,+BASC","sourcesContent":["import { setModelAlignment } from '../../modelApi/block/setModelAlignment';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Set text alignment of selected paragraphs\n * @param editor The editor to set alignment\n * @param alignment Alignment value: left, center or right\n */\nexport default function setAlignment(\n editor: IStandaloneEditor,\n alignment: 'left' | 'center' | 'right' | 'justify'\n) {\n editor.focus();\n\n editor.formatContentModel(model => setModelAlignment(model, alignment), {\n apiName: 'setAlignment',\n });\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
+
var adjustTrailingSpaceSelection_1 = require("../../modelApi/selection/adjustTrailingSpaceSelection");
|
|
4
5
|
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
5
6
|
var roosterjs_editor_dom_1 = require("roosterjs-editor-dom");
|
|
6
7
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
@@ -62,6 +63,7 @@ function insertLink(editor, link, anchorTitle, displayText, target) {
|
|
|
62
63
|
mergeFormat: 'mergeAll',
|
|
63
64
|
});
|
|
64
65
|
}
|
|
66
|
+
(0, adjustTrailingSpaceSelection_1.adjustTrailingSpaceSelection)(model);
|
|
65
67
|
return segments.length > 0;
|
|
66
68
|
}, {
|
|
67
69
|
changeSource: roosterjs_content_model_core_1.ChangeSource.CreateLink,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";;;AAAA,6EAA6F;AAC7F,6DAAgE;AAEhE,2EAKqC;AAErC,4BAA4B;AAC5B,IAAM,SAAS,GAAG,cAAc,CAAC;AACjC,wCAAwC;AACxC,IAAM,YAAY,GAAG,cAAc,CAAC;AACpC,sDAAsD;AACtD,IAAM,SAAS,GAAG,SAAS,CAAC;AAE5B;;;;;;;;;;;;GAYG;AACH,SAAwB,UAAU,CAC9B,MAAyB,EACzB,IAAY,EACZ,WAAoB,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,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAEpB,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,6FAA6F;IAC7F,mEAAmE;IACnE,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';\nimport { HtmlSanitizer, matchLink } from 'roosterjs-editor-dom';\nimport type { ContentModelLink, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n addLink,\n addSegment,\n createContentModelDocument,\n createText,\n} from 'roosterjs-content-model-dom';\n\n// Regex matching Uri scheme\nconst URI_REGEX = /^[a-zA-Z]+:/i;\n// Regex matching begin of email address\nconst MAILTO_REGEX = /^[\\w.%+-]+@/i;\n// Regex matching begin of ftp, i.e. ftp.microsoft.com\nconst FTP_REGEX = /^ftp\\./i;\n\n/**\n * Insert a hyperlink at cursor.\n * When there is a selection, hyperlink will be applied to the selection,\n * otherwise a hyperlink will be inserted to the cursor position.\n * @param editor Editor object\n * @param link Link address, can be http(s), mailto, notes, file, unc, ftp, news, telnet, gopher, wais.\n * When protocol is not specified, a best matched protocol will be predicted.\n * @param anchorTitle Optional alt text of the link, will be shown when hover on the link\n * @param displayText Optional display text for the link.\n * @param target Optional display target for the link (\"_blank\"|\"_self\"|\"_parent\"|\"_top\"|\"{framename}\")\n * If specified, the display text of link will be replaced with this text.\n * If not specified and there wasn't a link, the link url will be used as display text.\n */\nexport default function insertLink(\n editor: IStandaloneEditor,\n link: string,\n anchorTitle?: string,\n displayText?: string,\n target?: string\n) {\n editor.focus();\n\n const url = (checkXss(link) || '').trim();\n if (url) {\n const linkData = matchLink(url);\n const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);\n const links: ContentModelLink[] = [];\n let anchorNode: Node | undefined;\n\n editor.formatContentModel(\n (model, context) => {\n const segments = getSelectedSegments(model, false /*includingFormatHolder*/);\n const originalText = segments\n .map(x => (x.segmentType == 'Text' ? x.text : ''))\n .join('');\n const text = displayText || originalText || '';\n\n if (\n segments.some(x => x.segmentType != 'SelectionMarker') &&\n originalText == text\n ) {\n segments.forEach(x => {\n const link = createLink(\n linkUrl,\n anchorTitle,\n target,\n x.segmentType == 'Text'\n );\n addLink(x, link);\n if (x.link) {\n links.push(x.link);\n }\n });\n } else if (\n segments.every(x => x.segmentType == 'SelectionMarker') ||\n (!!text && text != originalText)\n ) {\n const segment = createText(text || (linkData ? linkData.originalUrl : url), {\n ...segments[0]?.format,\n ...editor.getPendingFormat(),\n });\n const doc = createContentModelDocument();\n const link = createLink(linkUrl, anchorTitle, target);\n\n addLink(segment, link);\n addSegment(doc, segment);\n\n if (segment.link) {\n links.push(segment.link);\n }\n\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n }\n\n return segments.length > 0;\n },\n {\n changeSource: ChangeSource.CreateLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n apiName: 'insertLink',\n }\n );\n }\n}\n\nconst createLink = (\n url: string,\n anchorTitle?: string,\n target?: string,\n underline: boolean = true\n): ContentModelLink => {\n return {\n dataset: {},\n format: {\n href: url,\n anchorTitle,\n target,\n underline: underline,\n },\n };\n};\n\n// TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.\nfunction applyLinkPrefix(url: string): string {\n if (!url) {\n return url;\n }\n\n // Add link prefix per rule:\n // (a) if the url always starts with a URI scheme, leave it as it is\n // (b) if the url is an email address, xxx@... add mailto: prefix\n // (c) if the url starts with ftp., add ftp:// prefix\n // (d) rest, add http:// prefix\n let prefix = '';\n if (url.search(URI_REGEX) < 0) {\n if (url.search(MAILTO_REGEX) == 0) {\n prefix = 'mailto:';\n } else if (url.search(FTP_REGEX) == 0) {\n prefix = 'ftp://';\n } else {\n // fallback to http://\n prefix = 'http://';\n }\n }\n\n return prefix + url;\n}\n\n// TODO: This is copied from original code. However, ContentModel should be able to filter out malicious\n// attributes later, so no need to use HtmlSanitizer here\nfunction checkXss(link: string): string {\n const sanitizer = new HtmlSanitizer();\n const a = document.createElement('a');\n\n a.href = link || '';\n\n sanitizer.sanitize(a);\n // We use getAttribute because some browsers will try to make the href property a valid link.\n // This has unintended side effects when the link lacks a protocol.\n return a.getAttribute('href') || '';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";;;AAAA,sGAAqG;AACrG,6EAA6F;AAC7F,6DAAgE;AAEhE,2EAKqC;AAErC,4BAA4B;AAC5B,IAAM,SAAS,GAAG,cAAc,CAAC;AACjC,wCAAwC;AACxC,IAAM,YAAY,GAAG,cAAc,CAAC;AACpC,sDAAsD;AACtD,IAAM,SAAS,GAAG,SAAS,CAAC;AAE5B;;;;;;;;;;;;GAYG;AACH,SAAwB,UAAU,CAC9B,MAAyB,EACzB,IAAY,EACZ,WAAoB,EACpB,WAAoB,EACpB,MAAe;IAEf,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,GAAG,EAAE;QACL,IAAM,UAAQ,GAAG,IAAA,gCAAS,EAAC,GAAG,CAAC,CAAC;QAChC,IAAM,SAAO,GAAG,UAAQ,CAAC,CAAC,CAAC,UAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACzE,IAAM,OAAK,GAAuB,EAAE,CAAC;QACrC,IAAI,YAA4B,CAAC;QAEjC,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,QAAQ,GAAG,IAAA,kDAAmB,EAAC,KAAK,EAAE,KAAK,CAAC,yBA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EAAE;QACN,OAAO,GAAG,CAAC;KACd;IAED,4BAA4B;IAC5B,oEAAoE;IACpE,iEAAiE;IACjE,qDAAqD;IACrD,+BAA+B;IAC/B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;QAC3B,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;YAC/B,MAAM,GAAG,SAAS,CAAC;SACtB;aAAM,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YACnC,MAAM,GAAG,QAAQ,CAAC;SACrB;aAAM;YACH,sBAAsB;YACtB,MAAM,GAAG,SAAS,CAAC;SACtB;KACJ;IAED,OAAO,MAAM,GAAG,GAAG,CAAC;AACxB,CAAC;AAED,wGAAwG;AACxG,yDAAyD;AACzD,SAAS,QAAQ,CAAC,IAAY;IAC1B,IAAM,SAAS,GAAG,IAAI,oCAAa,EAAE,CAAC;IACtC,IAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAEtC,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAEpB,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,6FAA6F;IAC7F,mEAAmE;IACnE,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';\nimport { HtmlSanitizer, matchLink } from 'roosterjs-editor-dom';\nimport type { ContentModelLink, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n addLink,\n addSegment,\n createContentModelDocument,\n createText,\n} from 'roosterjs-content-model-dom';\n\n// Regex matching Uri scheme\nconst URI_REGEX = /^[a-zA-Z]+:/i;\n// Regex matching begin of email address\nconst MAILTO_REGEX = /^[\\w.%+-]+@/i;\n// Regex matching begin of ftp, i.e. ftp.microsoft.com\nconst FTP_REGEX = /^ftp\\./i;\n\n/**\n * Insert a hyperlink at cursor.\n * When there is a selection, hyperlink will be applied to the selection,\n * otherwise a hyperlink will be inserted to the cursor position.\n * @param editor Editor object\n * @param link Link address, can be http(s), mailto, notes, file, unc, ftp, news, telnet, gopher, wais.\n * When protocol is not specified, a best matched protocol will be predicted.\n * @param anchorTitle Optional alt text of the link, will be shown when hover on the link\n * @param displayText Optional display text for the link.\n * @param target Optional display target for the link (\"_blank\"|\"_self\"|\"_parent\"|\"_top\"|\"{framename}\")\n * If specified, the display text of link will be replaced with this text.\n * If not specified and there wasn't a link, the link url will be used as display text.\n */\nexport default function insertLink(\n editor: IStandaloneEditor,\n link: string,\n anchorTitle?: string,\n displayText?: string,\n target?: string\n) {\n editor.focus();\n\n const url = (checkXss(link) || '').trim();\n if (url) {\n const linkData = matchLink(url);\n const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);\n const links: ContentModelLink[] = [];\n let anchorNode: Node | undefined;\n\n editor.formatContentModel(\n (model, context) => {\n const segments = getSelectedSegments(model, false /*includingFormatHolder*/);\n const originalText = segments\n .map(x => (x.segmentType == 'Text' ? x.text : ''))\n .join('');\n const text = displayText || originalText || '';\n\n if (\n segments.some(x => x.segmentType != 'SelectionMarker') &&\n originalText == text\n ) {\n segments.forEach(x => {\n const link = createLink(\n linkUrl,\n anchorTitle,\n target,\n x.segmentType == 'Text'\n );\n addLink(x, link);\n if (x.link) {\n links.push(x.link);\n }\n });\n } else if (\n segments.every(x => x.segmentType == 'SelectionMarker') ||\n (!!text && text != originalText)\n ) {\n const segment = createText(text || (linkData ? linkData.originalUrl : url), {\n ...segments[0]?.format,\n ...editor.getPendingFormat(),\n });\n const doc = createContentModelDocument();\n const link = createLink(linkUrl, anchorTitle, target);\n\n addLink(segment, link);\n addSegment(doc, segment);\n\n if (segment.link) {\n links.push(segment.link);\n }\n\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n }\n\n adjustTrailingSpaceSelection(model);\n return segments.length > 0;\n },\n {\n changeSource: ChangeSource.CreateLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n apiName: 'insertLink',\n }\n );\n }\n}\n\nconst createLink = (\n url: string,\n anchorTitle?: string,\n target?: string,\n underline: boolean = true\n): ContentModelLink => {\n return {\n dataset: {},\n format: {\n href: url,\n anchorTitle,\n target,\n underline: underline,\n },\n };\n};\n\n// TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.\nfunction applyLinkPrefix(url: string): string {\n if (!url) {\n return url;\n }\n\n // Add link prefix per rule:\n // (a) if the url always starts with a URI scheme, leave it as it is\n // (b) if the url is an email address, xxx@... add mailto: prefix\n // (c) if the url starts with ftp., add ftp:// prefix\n // (d) rest, add http:// prefix\n let prefix = '';\n if (url.search(URI_REGEX) < 0) {\n if (url.search(MAILTO_REGEX) == 0) {\n prefix = 'mailto:';\n } else if (url.search(FTP_REGEX) == 0) {\n prefix = 'ftp://';\n } else {\n // fallback to http://\n prefix = 'http://';\n }\n }\n\n return prefix + url;\n}\n\n// TODO: This is copied from original code. However, ContentModel should be able to filter out malicious\n// attributes later, so no need to use HtmlSanitizer here\nfunction checkXss(link: string): string {\n const sanitizer = new HtmlSanitizer();\n const a = document.createElement('a');\n\n a.href = link || '';\n\n sanitizer.sanitize(a);\n // We use getAttribute because some browsers will try to make the href property a valid link.\n // This has unintended side effects when the link lacks a protocol.\n return a.getAttribute('href') || '';\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var adjustTrailingSpaceSelection_1 = require("../../modelApi/selection/adjustTrailingSpaceSelection");
|
|
3
4
|
var formatSegmentWithContentModel_1 = require("../utils/formatSegmentWithContentModel");
|
|
4
5
|
/**
|
|
5
6
|
* Toggle underline style
|
|
@@ -12,7 +13,7 @@ function toggleUnderline(editor) {
|
|
|
12
13
|
if (segment === null || segment === void 0 ? void 0 : segment.link) {
|
|
13
14
|
segment.link.format.underline = !!isTurningOn;
|
|
14
15
|
}
|
|
15
|
-
}, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); });
|
|
16
|
+
}, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); }, false /*includingFormatHolder*/, adjustTrailingSpaceSelection_1.adjustTrailingSpaceSelection);
|
|
16
17
|
}
|
|
17
18
|
exports.default = toggleUnderline;
|
|
18
19
|
//# sourceMappingURL=toggleUnderline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":";;AAAA,wFAAuF;AAGvF;;;GAGG;AACH,SAAwB,eAAe,CAAC,MAAyB;IAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;QACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;QAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;YACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;SACjD;IACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,
|
|
1
|
+
{"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":";;AAAA,sGAAqG;AACrG,wFAAuF;AAGvF;;;GAGG;AACH,SAAwB,eAAe,CAAC,MAAyB;IAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;QACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;QAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;YACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;SACjD;IACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,EAC7E,KAAK,CAAC,yBAAyB,EAC/B,2DAA4B,CAC/B,CAAC;AACN,CAAC;AAjBD,kCAiBC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport default function toggleUnderline(editor: IStandaloneEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline,\n false /*includingFormatHolder*/,\n adjustTrailingSpaceSelection\n );\n}\n"]}
|
|
@@ -52,6 +52,8 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
52
52
|
else if (borderColor) {
|
|
53
53
|
borderFormat = borderFormat + " " + borderColor;
|
|
54
54
|
}
|
|
55
|
+
// undefined is treated as Left to Right
|
|
56
|
+
var isRtl = tableModel.format.direction == 'rtl';
|
|
55
57
|
if (sel) {
|
|
56
58
|
var operations = [operation];
|
|
57
59
|
while (operations.length) {
|
|
@@ -84,22 +86,22 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
84
86
|
case 'leftBorders':
|
|
85
87
|
var leftBorder = ['borderLeft'];
|
|
86
88
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
87
|
-
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
89
|
+
var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.lastColumn : sel.firstColumn];
|
|
88
90
|
// Format cells - Left border
|
|
89
91
|
applyBorderFormat(cell, borderFormat, leftBorder);
|
|
90
92
|
}
|
|
91
93
|
// Format perimeter
|
|
92
|
-
perimeter.Left = true;
|
|
94
|
+
isRtl ? (perimeter.Right = true) : (perimeter.Left = true);
|
|
93
95
|
break;
|
|
94
96
|
case 'rightBorders':
|
|
95
97
|
var rightBorder = ['borderRight'];
|
|
96
98
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
97
|
-
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
|
|
99
|
+
var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.firstColumn : sel.lastColumn];
|
|
98
100
|
// Format cells - Right border
|
|
99
101
|
applyBorderFormat(cell, borderFormat, rightBorder);
|
|
100
102
|
}
|
|
101
103
|
// Format perimeter
|
|
102
|
-
perimeter.Right = true;
|
|
104
|
+
isRtl ? (perimeter.Left = true) : (perimeter.Right = true);
|
|
103
105
|
break;
|
|
104
106
|
case 'topBorders':
|
|
105
107
|
var topBorder = ['borderTop'];
|
|
@@ -144,7 +146,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
144
146
|
}
|
|
145
147
|
// Single row selection
|
|
146
148
|
if (singleRow) {
|
|
147
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderRight']);
|
|
149
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderRight']);
|
|
148
150
|
for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
|
|
149
151
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
150
152
|
applyBorderFormat(cell, borderFormat, [
|
|
@@ -152,18 +154,18 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
152
154
|
'borderRight',
|
|
153
155
|
]);
|
|
154
156
|
}
|
|
155
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderLeft']);
|
|
157
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderLeft']);
|
|
156
158
|
break;
|
|
157
159
|
}
|
|
158
160
|
// For multiple rows and columns selections
|
|
159
161
|
// Top left cell
|
|
160
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
|
|
162
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
|
|
161
163
|
// Top right cell
|
|
162
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
|
|
164
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
|
|
163
165
|
// Bottom left cell
|
|
164
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
|
|
166
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
|
|
165
167
|
// Bottom right cell
|
|
166
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
|
|
168
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
|
|
167
169
|
// First row
|
|
168
170
|
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
169
171
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
@@ -188,7 +190,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
188
190
|
applyBorderFormat(cell, borderFormat, [
|
|
189
191
|
'borderTop',
|
|
190
192
|
'borderBottom',
|
|
191
|
-
'borderRight',
|
|
193
|
+
isRtl ? 'borderLeft' : 'borderRight',
|
|
192
194
|
]);
|
|
193
195
|
}
|
|
194
196
|
// Last column
|
|
@@ -197,7 +199,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
197
199
|
applyBorderFormat(cell, borderFormat, [
|
|
198
200
|
'borderTop',
|
|
199
201
|
'borderBottom',
|
|
200
|
-
'borderLeft',
|
|
202
|
+
isRtl ? 'borderRight' : 'borderLeft',
|
|
201
203
|
]);
|
|
202
204
|
}
|
|
203
205
|
// Inner cells
|
|
@@ -219,7 +221,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
223
|
//Format perimeter if necessary or possible
|
|
222
|
-
modifyPerimeter(tableModel, sel, borderFormat, perimeter);
|
|
224
|
+
modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);
|
|
223
225
|
}
|
|
224
226
|
return true;
|
|
225
227
|
}
|
|
@@ -259,7 +261,7 @@ function applyBorderFormat(cell, borderFormat, positions) {
|
|
|
259
261
|
* If borderFormat is empty, the border will be removed
|
|
260
262
|
* @param perimeter Where in the perimeter to apply
|
|
261
263
|
*/
|
|
262
|
-
function modifyPerimeter(tableModel, sel, borderFormat, perimeter) {
|
|
264
|
+
function modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl) {
|
|
263
265
|
// Top of selection
|
|
264
266
|
if (perimeter.Top && sel.firstRow - 1 >= 0) {
|
|
265
267
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
@@ -278,14 +280,14 @@ function modifyPerimeter(tableModel, sel, borderFormat, perimeter) {
|
|
|
278
280
|
if (perimeter.Left && sel.firstColumn - 1 >= 0) {
|
|
279
281
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
280
282
|
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];
|
|
281
|
-
applyBorderFormat(cell, borderFormat, ['borderRight']);
|
|
283
|
+
applyBorderFormat(cell, borderFormat, [isRtl ? 'borderLeft' : 'borderRight']);
|
|
282
284
|
}
|
|
283
285
|
}
|
|
284
286
|
// Right of selection
|
|
285
287
|
if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {
|
|
286
288
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
287
289
|
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];
|
|
288
|
-
applyBorderFormat(cell, borderFormat, ['borderLeft']);
|
|
290
|
+
applyBorderFormat(cell, borderFormat, [isRtl ? 'borderRight' : 'borderLeft']);
|
|
289
291
|
}
|
|
290
292
|
}
|
|
291
293
|
}
|