roosterjs-content-model-dom 9.45.1 → 9.45.2
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/domToModel/processors/formatContainerProcessor.d.ts +4 -0
- package/lib/domToModel/processors/formatContainerProcessor.js +13 -3
- package/lib/domToModel/processors/formatContainerProcessor.js.map +1 -1
- package/lib/domToModel/processors/knownElementProcessor.js +11 -5
- package/lib/domToModel/processors/knownElementProcessor.js.map +1 -1
- package/lib/domToModel/processors/textProcessor.js +1 -1
- package/lib/domToModel/processors/textProcessor.js.map +1 -1
- package/lib/modelApi/editing/applyTableFormat.js +4 -1
- package/lib/modelApi/editing/applyTableFormat.js.map +1 -1
- package/lib/modelApi/editing/setTableCellBackgroundColor.js +22 -23
- package/lib/modelApi/editing/setTableCellBackgroundColor.js.map +1 -1
- package/lib-amd/domToModel/processors/formatContainerProcessor.d.ts +4 -0
- package/lib-amd/domToModel/processors/formatContainerProcessor.js +13 -3
- package/lib-amd/domToModel/processors/formatContainerProcessor.js.map +1 -1
- package/lib-amd/domToModel/processors/knownElementProcessor.js +11 -5
- package/lib-amd/domToModel/processors/knownElementProcessor.js.map +1 -1
- package/lib-amd/domToModel/processors/textProcessor.js +1 -1
- package/lib-amd/domToModel/processors/textProcessor.js.map +1 -1
- package/lib-amd/modelApi/editing/applyTableFormat.js +4 -1
- package/lib-amd/modelApi/editing/applyTableFormat.js.map +1 -1
- package/lib-amd/modelApi/editing/setTableCellBackgroundColor.js +22 -23
- package/lib-amd/modelApi/editing/setTableCellBackgroundColor.js.map +1 -1
- package/lib-mjs/domToModel/processors/formatContainerProcessor.d.ts +4 -0
- package/lib-mjs/domToModel/processors/formatContainerProcessor.js +10 -1
- package/lib-mjs/domToModel/processors/formatContainerProcessor.js.map +1 -1
- package/lib-mjs/domToModel/processors/knownElementProcessor.js +11 -5
- package/lib-mjs/domToModel/processors/knownElementProcessor.js.map +1 -1
- package/lib-mjs/domToModel/processors/textProcessor.js +1 -1
- package/lib-mjs/domToModel/processors/textProcessor.js.map +1 -1
- package/lib-mjs/modelApi/editing/applyTableFormat.js +4 -1
- package/lib-mjs/modelApi/editing/applyTableFormat.js.map +1 -1
- package/lib-mjs/modelApi/editing/setTableCellBackgroundColor.js +22 -23
- package/lib-mjs/modelApi/editing/setTableCellBackgroundColor.js.map +1 -1
- package/package.json +3 -3
|
@@ -12,3 +12,7 @@ export declare const ContextStyles: (keyof (MarginFormat & PaddingFormat))[];
|
|
|
12
12
|
* @param context DOM to Content Model context
|
|
13
13
|
*/
|
|
14
14
|
export declare const formatContainerProcessor: ElementProcessor<HTMLElement>;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare const forceFormatContainerProcessor: ElementProcessor<HTMLElement>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatContainerProcessor = exports.ContextStyles = void 0;
|
|
3
|
+
exports.forceFormatContainerProcessor = exports.formatContainerProcessor = exports.ContextStyles = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var addBlock_1 = require("../../modelApi/common/addBlock");
|
|
6
6
|
var createFormatContainer_1 = require("../../modelApi/creators/createFormatContainer");
|
|
@@ -27,6 +27,17 @@ exports.ContextStyles = [
|
|
|
27
27
|
* @param context DOM to Content Model context
|
|
28
28
|
*/
|
|
29
29
|
var formatContainerProcessor = function (group, element, context) {
|
|
30
|
+
formatContainerProcessorInternal(group, element, context, false /* forceFormatContainer */);
|
|
31
|
+
};
|
|
32
|
+
exports.formatContainerProcessor = formatContainerProcessor;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
var forceFormatContainerProcessor = function (group, element, context) {
|
|
37
|
+
formatContainerProcessorInternal(group, element, context, true /* forceFormatContainer */);
|
|
38
|
+
};
|
|
39
|
+
exports.forceFormatContainerProcessor = forceFormatContainerProcessor;
|
|
40
|
+
var formatContainerProcessorInternal = function (group, element, context, forceFormatContainer) {
|
|
30
41
|
(0, stackFormat_1.stackFormat)(context, { segment: 'shallowCloneForBlock', paragraph: 'shallowClone' }, function () {
|
|
31
42
|
(0, parseFormat_1.parseFormat)(element, context.formatParsers.block, context.blockFormat, context);
|
|
32
43
|
(0, parseFormat_1.parseFormat)(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);
|
|
@@ -44,7 +55,7 @@ var formatContainerProcessor = function (group, element, context) {
|
|
|
44
55
|
if (element.style.fontSize && parseInt(element.style.fontSize) == 0) {
|
|
45
56
|
formatContainer.zeroFontSize = true;
|
|
46
57
|
}
|
|
47
|
-
if (shouldFallbackToParagraph(formatContainer)) {
|
|
58
|
+
if (shouldFallbackToParagraph(formatContainer) && !forceFormatContainer) {
|
|
48
59
|
// For DIV container that only has one paragraph child, container style can be merged into paragraph
|
|
49
60
|
// and no need to have this container
|
|
50
61
|
var paragraph = formatContainer.blocks[0];
|
|
@@ -63,7 +74,6 @@ var formatContainerProcessor = function (group, element, context) {
|
|
|
63
74
|
});
|
|
64
75
|
(0, addBlock_1.addBlock)(group, (0, createParagraph_1.createParagraph)(true /*isImplicit*/, context.blockFormat));
|
|
65
76
|
};
|
|
66
|
-
exports.formatContainerProcessor = formatContainerProcessor;
|
|
67
77
|
function shouldFallbackToParagraph(formatContainer) {
|
|
68
78
|
var firstChild = formatContainer.blocks[0];
|
|
69
79
|
return (formatContainer.tagName == 'div' &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatContainerProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/domToModel/processors/formatContainerProcessor.ts"],"names":[],"mappings":";;;;AAAA,2DAA0D;AAC1D,uFAAsF;AACtF,2EAA0E;AAC1E,4DAA2D;AAC3D,oDAAmD;AACnD,wFAAuF;AACvF,oDAAmD;
|
|
1
|
+
{"version":3,"file":"formatContainerProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/domToModel/processors/formatContainerProcessor.ts"],"names":[],"mappings":";;;;AAAA,2DAA0D;AAC1D,uFAAsF;AACtF,2EAA0E;AAC1E,4DAA2D;AAC3D,oDAAmD;AACnD,wFAAuF;AACvF,oDAAmD;AAYnD;;GAEG;AACU,QAAA,aAAa,GAA6C;IACnE,YAAY;IACZ,aAAa;IACb,aAAa;IACb,cAAc;CACjB,CAAC;AAEF;;;;;;;GAOG;AACI,IAAM,wBAAwB,GAAkC,UACnE,KAAK,EACL,OAAO,EACP,OAAO;IAEP,gCAAgC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAChG,CAAC,CAAC;AANW,QAAA,wBAAwB,4BAMnC;AAEF;;GAEG;AACI,IAAM,6BAA6B,GAAkC,UACxE,KAAK,EACL,OAAO,EACP,OAAO;IAEP,gCAAgC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAC/F,CAAC,CAAC;AANW,QAAA,6BAA6B,iCAMxC;AAEF,IAAM,gCAAgC,GAAG,UACrC,KAA6B,EAC7B,OAAoB,EACpB,OAA0B,EAC1B,oBAA6B;IAE7B,IAAA,yBAAW,EAAC,OAAO,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,cAAc,EAAE,EAAE;QACjF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAChF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAE3F,IAAM,MAAM,6BACL,OAAO,CAAC,WAAW,CACzB,CAAC;QAEF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CA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C,CAAC;SAC9B;aAAM;YACH,IAAA,mBAAQ,EAAC,KAAK,EAAE,eAAe,CAAC,CAAC;SACpC;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,mBAAQ,EAAC,KAAK,EAAE,IAAA,iCAAe,EAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,SAAS,yBAAyB,CAAC,eAA4C;IAC3E,IAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE7C,OAAO,CACH,eAAe,CAAC,OAAO,IAAI,KAAK;QAChC,eAAe,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC;QAClC,UAAU,CAAC,SAAS,IAAI,WAAW;QACnC,UAAU,CAAC,UAAU,CACxB,CAAC;AACN,CAAC","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { createFormatContainer } from '../../modelApi/creators/createFormatContainer';\nimport { createParagraph } from '../../modelApi/creators/createParagraph';\nimport { getDefaultStyle } from '../utils/getDefaultStyle';\nimport { parseFormat } from '../utils/parseFormat';\nimport { setParagraphNotImplicit } from '../../modelApi/block/setParagraphNotImplicit';\nimport { stackFormat } from '../utils/stackFormat';\nimport type {\n ContentModelBlockGroup,\n ContentModelFormatContainer,\n ContentModelFormatContainerFormat,\n ContentModelParagraph,\n DomToModelContext,\n ElementProcessor,\n MarginFormat,\n PaddingFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const ContextStyles: (keyof (MarginFormat & PaddingFormat))[] = [\n 'marginLeft',\n 'marginRight',\n 'paddingLeft',\n 'paddingRight',\n];\n\n/**\n * Content Model Element Processor for format container elements (e.g., blockquote, div)\n * Processes elements that create FormatContainer blocks in the content model.\n * This processor can be used in processorOverride to customize how specific elements are processed.\n * @param group The parent block group\n * @param element The DOM element to process\n * @param context DOM to Content Model context\n */\nexport const formatContainerProcessor: ElementProcessor<HTMLElement> = (\n group,\n element,\n context\n) => {\n formatContainerProcessorInternal(group, element, context, false /* forceFormatContainer */);\n};\n\n/**\n * @internal\n */\nexport const forceFormatContainerProcessor: ElementProcessor<HTMLElement> = (\n group,\n element,\n context\n) => {\n formatContainerProcessorInternal(group, element, context, true /* forceFormatContainer */);\n};\n\nconst formatContainerProcessorInternal = (\n group: ContentModelBlockGroup,\n element: HTMLElement,\n context: DomToModelContext,\n forceFormatContainer: boolean\n) => {\n stackFormat(context, { segment: 'shallowCloneForBlock', paragraph: 'shallowClone' }, () => {\n parseFormat(element, context.formatParsers.block, context.blockFormat, context);\n parseFormat(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);\n\n const format: ContentModelFormatContainerFormat = {\n ...context.blockFormat,\n };\n\n parseFormat(element, context.formatParsers.container, format, context);\n\n const tagName =\n getDefaultStyle(element).display == 'block' ? element.tagName.toLowerCase() : 'div';\n const formatContainer = createFormatContainer(tagName, format);\n\n // It is possible to inherit margin left/right styles from parent DIV or other containers,\n // since we are going into a deeper level of format container now,\n // the container will render these styles so no need to keep them in context format\n ContextStyles.forEach(style => {\n delete context.blockFormat[style];\n });\n\n context.elementProcessors.child(formatContainer, element, context);\n\n if (element.style.fontSize && parseInt(element.style.fontSize) == 0) {\n formatContainer.zeroFontSize = true;\n }\n\n if (shouldFallbackToParagraph(formatContainer) && !forceFormatContainer) {\n // For DIV container that only has one paragraph child, container style can be merged into paragraph\n // and no need to have this container\n const paragraph = formatContainer.blocks[0] as ContentModelParagraph;\n\n if (formatContainer.zeroFontSize) {\n paragraph.segmentFormat = Object.assign({}, paragraph.segmentFormat, {\n fontSize: '0',\n });\n }\n\n Object.assign(paragraph.format, formatContainer.format);\n setParagraphNotImplicit(paragraph);\n addBlock(group, paragraph);\n } else {\n addBlock(group, formatContainer);\n }\n });\n\n addBlock(group, createParagraph(true /*isImplicit*/, context.blockFormat));\n};\n\nfunction shouldFallbackToParagraph(formatContainer: ContentModelFormatContainer) {\n const firstChild = formatContainer.blocks[0];\n\n return (\n formatContainer.tagName == 'div' &&\n formatContainer.blocks.length == 1 &&\n firstChild.blockType == 'Paragraph' &&\n firstChild.isImplicit\n );\n}\n"]}
|
|
@@ -4,12 +4,12 @@ exports.knownElementProcessor = void 0;
|
|
|
4
4
|
var addBlock_1 = require("../../modelApi/common/addBlock");
|
|
5
5
|
var blockProcessor_1 = require("./blockProcessor");
|
|
6
6
|
var createParagraph_1 = require("../../modelApi/creators/createParagraph");
|
|
7
|
-
var formatContainerProcessor_1 = require("./formatContainerProcessor");
|
|
8
7
|
var getDefaultStyle_1 = require("../utils/getDefaultStyle");
|
|
9
8
|
var isBlockElement_1 = require("../utils/isBlockElement");
|
|
10
9
|
var entityUtils_1 = require("../../domUtils/entityUtils");
|
|
11
10
|
var parseFormat_1 = require("../utils/parseFormat");
|
|
12
11
|
var stackFormat_1 = require("../utils/stackFormat");
|
|
12
|
+
var formatContainerProcessor_1 = require("./formatContainerProcessor");
|
|
13
13
|
var FormatContainerTriggerStyles = [
|
|
14
14
|
'marginBottom',
|
|
15
15
|
'marginTop',
|
|
@@ -36,8 +36,12 @@ var SegmentDecoratorTags = ['A', 'CODE'];
|
|
|
36
36
|
*/
|
|
37
37
|
var knownElementProcessor = function (group, element, context) {
|
|
38
38
|
var isBlock = (0, isBlockElement_1.isBlockElement)(element);
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
var isBlockContainer = isBlock || element.style.display == 'inline-block';
|
|
40
|
+
if (isBlockContainer && // For inline-block here, we will also check if it should be represented as Format Container
|
|
41
|
+
shouldForceUseFormatContainer(element, context)) {
|
|
42
|
+
(0, formatContainerProcessor_1.forceFormatContainerProcessor)(group, element, context);
|
|
43
|
+
}
|
|
44
|
+
else if (isBlockContainer && shouldUseFormatContainer(element, context)) {
|
|
41
45
|
(0, formatContainerProcessor_1.formatContainerProcessor)(group, element, context);
|
|
42
46
|
}
|
|
43
47
|
else if ((0, entityUtils_1.isBlockEntityContainer)(element)) {
|
|
@@ -71,6 +75,9 @@ var knownElementProcessor = function (group, element, context) {
|
|
|
71
75
|
}
|
|
72
76
|
};
|
|
73
77
|
exports.knownElementProcessor = knownElementProcessor;
|
|
78
|
+
function shouldForceUseFormatContainer(element, context) {
|
|
79
|
+
return FormatContainerTriggerAttributes.some(function (attr) { return element.hasAttribute(attr); });
|
|
80
|
+
}
|
|
74
81
|
function shouldUseFormatContainer(element, context) {
|
|
75
82
|
// For those tags that we know we should not use format container, just return false
|
|
76
83
|
if (ByPassFormatContainerTags.indexOf(element.tagName) >= 0) {
|
|
@@ -85,8 +92,7 @@ function shouldUseFormatContainer(element, context) {
|
|
|
85
92
|
}
|
|
86
93
|
// For block element with positive value of border width or top/bottom margin/padding,
|
|
87
94
|
// we need to use format container
|
|
88
|
-
if (FormatContainerTriggerStyles.some(function (key) { return parseInt(style[key] || defaultStyle[key] || '') > 0; })
|
|
89
|
-
FormatContainerTriggerAttributes.some(function (attr) { return element.hasAttribute(attr); })) {
|
|
95
|
+
if (FormatContainerTriggerStyles.some(function (key) { return parseInt(style[key] || defaultStyle[key] || '') > 0; })) {
|
|
90
96
|
return true;
|
|
91
97
|
}
|
|
92
98
|
// For margin left/right with value "auto", we need to use format container
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knownElementProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/domToModel/processors/knownElementProcessor.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAC1D,mDAAkD;AAClD,2EAA0E;AAC1E,
|
|
1
|
+
{"version":3,"file":"knownElementProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/domToModel/processors/knownElementProcessor.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAC1D,mDAAkD;AAClD,2EAA0E;AAC1E,4DAA2D;AAC3D,0DAAyD;AACzD,0DAAoE;AACpE,oDAAmD;AACnD,oDAAmD;AACnD,uEAGoC;AAOpC,IAAM,4BAA4B,GAAkC;IAChE,cAAc;IACd,WAAW;IAC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IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { blockProcessor } from './blockProcessor';\nimport { createParagraph } from '../../modelApi/creators/createParagraph';\nimport { getDefaultStyle } from '../utils/getDefaultStyle';\nimport { isBlockElement } from '../utils/isBlockElement';\nimport { isBlockEntityContainer } from '../../domUtils/entityUtils';\nimport { parseFormat } from '../utils/parseFormat';\nimport { stackFormat } from '../utils/stackFormat';\nimport {\n forceFormatContainerProcessor,\n formatContainerProcessor,\n} from './formatContainerProcessor';\nimport type {\n ContentModelSegmentFormat,\n DomToModelContext,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\nconst FormatContainerTriggerStyles: (keyof CSSStyleDeclaration)[] = [\n 'marginBottom',\n 'marginTop',\n 'paddingBottom',\n 'paddingTop',\n 'paddingLeft',\n 'paddingRight',\n 'borderTopWidth',\n 'borderBottomWidth',\n 'borderLeftWidth',\n 'borderRightWidth',\n 'width',\n 'height',\n 'maxWidth',\n 'maxHeight',\n 'minWidth',\n 'minHeight',\n];\nconst FormatContainerTriggerAttributes = ['id'];\nconst ByPassFormatContainerTags = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'P', 'A'];\nconst SegmentDecoratorTags = ['A', 'CODE'];\n\n/**\n * @internal\n */\nexport const knownElementProcessor: ElementProcessor<HTMLElement> = (group, element, context) => {\n const isBlock = isBlockElement(element);\n const isBlockContainer = isBlock || element.style.display == 'inline-block';\n\n if (\n isBlockContainer && // For inline-block here, we will also check if it should be represented as Format Container\n shouldForceUseFormatContainer(element, context)\n ) {\n forceFormatContainerProcessor(group, element, context);\n } else if (isBlockContainer && shouldUseFormatContainer(element, context)) {\n formatContainerProcessor(group, element, context);\n } else if (isBlockEntityContainer(element)) {\n context.elementProcessors.child(group, element, context);\n } else if (isBlock) {\n const decorator = context.blockDecorator.tagName ? context.blockDecorator : undefined;\n const isSegmentDecorator = SegmentDecoratorTags.indexOf(element.tagName) >= 0;\n\n stackFormat(context, { segment: 'shallowCloneForBlock', paragraph: 'shallowClone' }, () => {\n const segmentFormat: ContentModelSegmentFormat = {};\n\n parseFormat(element, context.formatParsers.segmentOnBlock, segmentFormat, context);\n Object.assign(context.segmentFormat, segmentFormat);\n\n blockProcessor(group, element, context, segmentFormat);\n });\n\n if (isBlock && !isSegmentDecorator) {\n addBlock(\n group,\n createParagraph(\n true /*isImplicit*/,\n context.blockFormat,\n undefined /*segmentFormat*/,\n decorator\n )\n );\n }\n } else {\n stackFormat(\n context,\n {\n segment: 'shallowClone',\n paragraph: 'shallowClone',\n link: 'cloneFormat',\n },\n () => {\n parseFormat(element, context.formatParsers.segment, context.segmentFormat, context);\n\n if (context.link.format.href && element.tagName != 'A') {\n parseFormat(\n element,\n context.formatParsers.segmentUnderLink,\n context.link.format,\n context\n );\n }\n\n context.elementProcessors.child(group, element, context);\n }\n );\n }\n};\n\nfunction shouldForceUseFormatContainer(element: HTMLElement, context: DomToModelContext) {\n return FormatContainerTriggerAttributes.some(attr => element.hasAttribute(attr));\n}\n\nfunction shouldUseFormatContainer(element: HTMLElement, context: DomToModelContext) {\n // For those tags that we know we should not use format container, just return false\n if (ByPassFormatContainerTags.indexOf(element.tagName) >= 0) {\n return false;\n }\n\n const style = element.style;\n const defaultStyle = getDefaultStyle(element);\n\n const bgcolor = style.getPropertyValue('background-color');\n\n // For block element with background, we need to use format container\n if (bgcolor && bgcolor != 'transparent') {\n return true;\n }\n\n // For block element with positive value of border width or top/bottom margin/padding,\n // we need to use format container\n if (\n FormatContainerTriggerStyles.some(\n key => parseInt((style[key] as string) || (defaultStyle[key] as string) || '') > 0\n )\n ) {\n return true;\n }\n\n // For margin left/right with value \"auto\", we need to use format container\n if (style.marginLeft == 'auto' || style.marginRight == 'auto') {\n return true;\n }\n\n // For element with \"align\" attribute, we need to use format container\n if (element.getAttribute('align')) {\n return true;\n }\n\n return false;\n}\n"]}
|
|
@@ -11,8 +11,8 @@ var textProcessor = function (group, textNode, context) {
|
|
|
11
11
|
(0, stackFormat_1.stackFormat)(context, { segment: 'shallowClone' }, function () {
|
|
12
12
|
context.formatParsers.text.forEach(function (parser) {
|
|
13
13
|
parser(context.segmentFormat, textNode, context);
|
|
14
|
-
internalTextProcessor(group, textNode, context);
|
|
15
14
|
});
|
|
15
|
+
internalTextProcessor(group, textNode, context);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/domToModel/processors/textProcessor.ts"],"names":[],"mappings":";;;AAAA,yEAAwE;AACxE,oDAAmD;AAQnD;;GAEG;AACI,IAAM,aAAa,GAA2B,UACjD,KAA6B,EAC7B,QAAc,EACd,OAA0B;IAE1B,IAAI,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QACvC,IAAA,yBAAW,EAAC,OAAO,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;YAC9C,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,MAAM;gBACrC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"textProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/domToModel/processors/textProcessor.ts"],"names":[],"mappings":";;;AAAA,yEAAwE;AACxE,oDAAmD;AAQnD;;GAEG;AACI,IAAM,aAAa,GAA2B,UACjD,KAA6B,EAC7B,QAAc,EACd,OAA0B;IAE1B,IAAI,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QACvC,IAAA,yBAAW,EAAC,OAAO,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;YAC9C,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,MAAM;gBACrC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;YACH,qBAAqB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;KACN;SAAM;QACH,qBAAqB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;KACnD;AACL,CAAC,CAAC;AAfW,QAAA,aAAa,iBAexB;AAEF,SAAS,qBAAqB,CAC1B,KAA6B,EAC7B,QAAc,EACd,OAA0B;;IAE1B,IAAM,SAAS,GAAG,IAAA,iCAAe,EAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9D,IAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;IAE/C,OAAO,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEtE,IAAM,WAAW,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAC3D,MAAA,OAAO,CAAC,UAAU,0CAAE,SAAS,CACzB,QAAQ,EACR,SAAS,EACT,WAAW,CAAC,MAAM,CAAC,UAAC,CAAC,IAA4B,OAAA,CAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,WAAW,KAAI,MAAM,EAAxB,CAAwB,CAAC,CAC7E,CAAC;AACN,CAAC","sourcesContent":["import { ensureParagraph } from '../../modelApi/common/ensureParagraph';\nimport { stackFormat } from '../utils/stackFormat';\nimport type {\n ContentModelBlockGroup,\n ContentModelText,\n DomToModelContext,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const textProcessor: ElementProcessor<Text> = (\n group: ContentModelBlockGroup,\n textNode: Text,\n context: DomToModelContext\n) => {\n if (context.formatParsers.text.length > 0) {\n stackFormat(context, { segment: 'shallowClone' }, () => {\n context.formatParsers.text.forEach(parser => {\n parser(context.segmentFormat, textNode, context);\n });\n internalTextProcessor(group, textNode, context);\n });\n } else {\n internalTextProcessor(group, textNode, context);\n }\n};\n\nfunction internalTextProcessor(\n group: ContentModelBlockGroup,\n textNode: Text,\n context: DomToModelContext\n) {\n const paragraph = ensureParagraph(group, context.blockFormat);\n const segmentCount = paragraph.segments.length;\n\n context.elementProcessors.textWithSelection(group, textNode, context);\n\n const newSegments = paragraph.segments.slice(segmentCount);\n context.domIndexer?.onSegment(\n textNode,\n paragraph,\n newSegments.filter((x): x is ContentModelText => x?.segmentType == 'Text')\n );\n}\n"]}
|
|
@@ -223,9 +223,12 @@ function setFirstColumnFormatBorders(rows, format) {
|
|
|
223
223
|
(0, mutate_1.mutateSegment)(block, segment, function (cellSegment) {
|
|
224
224
|
if (format.hasFirstColumn) {
|
|
225
225
|
cellSegment.format.fontWeight = 'bold';
|
|
226
|
+
cell.format.fontWeight = 'bold';
|
|
226
227
|
}
|
|
227
|
-
else if (cellSegment.format.fontWeight == 'bold'
|
|
228
|
+
else if (cellSegment.format.fontWeight == 'bold' &&
|
|
229
|
+
cell.format.fontWeight == 'bold') {
|
|
228
230
|
delete cellSegment.format.fontWeight;
|
|
231
|
+
delete cell.format.fontWeight;
|
|
229
232
|
}
|
|
230
233
|
});
|
|
231
234
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTableFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/modelApi/editing/applyTableFormat.ts"],"names":[],"mappings":";;;;;AAAA,oEAAmE;AACnE,kEAA4F;AAC5F,2CAA8D;AAC9D,6EAA4E;AAC5E,uEAAsE;AACtE,+EAA8E;AAC9E,uEAAsE;AAQtE,IAAM,cAAc,GAAkC;IAClD,cAAc,EAAE,SAAS;IACzB,iBAAiB,EAAE,SAAS;IAC5B,mBAAmB,EAAE,SAAS;IAC9B,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE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AK,CAAC,CAAC;IACrD,MAAM,CAAC,GAAG,CAAC,GAAG,IAAA,iCAAkB,EAAC,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAc;IAC3C,OAAO,CAAC,KAAK,IAAI,KAAK,IAAI,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;AAC/D,CAAC","sourcesContent":["import { BorderKeys } from '../../formatHandlers/utils/borderKeys';\nimport { combineBorderValue, extractBorderValues } from '../../domUtils/style/borderValues';\nimport { mutateBlock, mutateSegment } from '../common/mutate';\nimport { setTableCellBackgroundColor } from './setTableCellBackgroundColor';\nimport { TableBorderFormat } from '../../constants/TableBorderFormat';\nimport { updateTableCellMetadata } from '../metadata/updateTableCellMetadata';\nimport { updateTableMetadata } from '../metadata/updateTableMetadata';\nimport type {\n BorderFormat,\n ReadonlyContentModelTable,\n ShallowMutableContentModelTableRow,\n TableMetadataFormat,\n} from 'roosterjs-content-model-types';\n\nconst DEFAULT_FORMAT: Required<TableMetadataFormat> = {\n topBorderColor: '#ABABAB',\n bottomBorderColor: '#ABABAB',\n verticalBorderColor: '#ABABAB',\n hasHeaderRow: false,\n hasFirstColumn: false,\n hasBandedRows: false,\n hasBandedColumns: false,\n bgColorEven: null,\n bgColorOdd: '#ABABAB20',\n headerRowColor: '#ABABAB',\n tableBorderFormat: TableBorderFormat.Default,\n verticalAlign: null,\n};\n\ntype MetaOverrides = {\n bgColorOverrides: boolean[][];\n vAlignOverrides: boolean[][];\n borderOverrides: boolean[][];\n};\n\n/**\n * Apply table format from table metadata and the passed in new format\n * @param table The table to apply format to\n * @param newFormat @optional New format to apply. When passed, this value will be merged into existing metadata format and default format\n * @param keepCellShade @optional When pass true, table cells with customized shade color will not be overwritten. @default false\n */\nexport function applyTableFormat(\n table: ReadonlyContentModelTable,\n newFormat?: TableMetadataFormat,\n keepCellShade?: boolean\n) {\n const mutableTable = mutateBlock(table);\n const { rows } = mutableTable;\n\n updateTableMetadata(mutableTable, format => {\n const effectiveMetadata = {\n ...DEFAULT_FORMAT,\n ...format,\n ...newFormat,\n };\n\n const metaOverrides: MetaOverrides = updateOverrides(rows, !keepCellShade);\n\n formatCells(rows, effectiveMetadata, metaOverrides);\n setFirstColumnFormatBorders(rows, effectiveMetadata);\n setHeaderRowFormat(rows, effectiveMetadata, metaOverrides);\n\n return effectiveMetadata;\n });\n}\n\nfunction updateOverrides(\n rows: ShallowMutableContentModelTableRow[],\n removeCellShade: boolean\n): MetaOverrides {\n const overrides: MetaOverrides = {\n bgColorOverrides: [],\n vAlignOverrides: [],\n borderOverrides: [],\n };\n\n rows.forEach(row => {\n const bgColorOverrides: boolean[] = [];\n const vAlignOverrides: boolean[] = [];\n const borderOverrides: boolean[] = [];\n\n overrides.bgColorOverrides.push(bgColorOverrides);\n overrides.vAlignOverrides.push(vAlignOverrides);\n overrides.borderOverrides.push(borderOverrides);\n\n row.cells.forEach(cell => {\n updateTableCellMetadata(mutateBlock(cell), metadata => {\n if (metadata && removeCellShade) {\n bgColorOverrides.push(false);\n delete metadata.bgColorOverride;\n } else {\n bgColorOverrides.push(!!metadata?.bgColorOverride);\n }\n vAlignOverrides.push(!!metadata?.vAlignOverride);\n borderOverrides.push(!!metadata?.borderOverride);\n\n return metadata;\n });\n });\n });\n\n return overrides;\n}\n\ntype ShouldUseTransparentBorder = (indexProp: {\n firstRow: boolean;\n lastRow: boolean;\n firstColumn: boolean;\n lastColumn: boolean;\n}) => [boolean, boolean, boolean, boolean];\n\nconst BorderFormatters: Record<number, ShouldUseTransparentBorder | undefined> = {\n [TableBorderFormat.Default]: _ => [false, false, false, false],\n [TableBorderFormat.ListWithSideBorders]: ({ lastColumn, firstColumn }) => [\n false,\n !lastColumn,\n false,\n !firstColumn,\n ],\n [TableBorderFormat.FirstColumnHeaderExternal]: ({\n firstColumn,\n firstRow,\n lastColumn,\n lastRow,\n }) => [\n !firstRow,\n (!lastColumn && !firstColumn) || (firstColumn && firstRow),\n !lastRow && !firstRow,\n !firstColumn,\n ],\n [TableBorderFormat.NoHeaderBorders]: ({ firstRow, firstColumn, lastColumn }) => [\n firstRow,\n firstRow || lastColumn,\n false,\n firstRow || firstColumn,\n ],\n [TableBorderFormat.NoSideBorders]: ({ firstColumn, lastColumn }) => [\n false,\n lastColumn,\n false,\n firstColumn,\n ],\n [TableBorderFormat.EspecialType1]: ({ firstRow, firstColumn }) => [\n firstColumn && !firstRow,\n firstRow,\n firstColumn && !firstRow,\n firstRow && !firstColumn,\n ],\n [TableBorderFormat.EspecialType2]: ({ firstRow, firstColumn }) => [\n !firstRow,\n firstRow || !firstColumn,\n !firstRow,\n !firstColumn,\n ],\n [TableBorderFormat.EspecialType3]: ({ firstColumn, firstRow }) => [\n true,\n firstRow || !firstColumn,\n !firstRow,\n true,\n ],\n [TableBorderFormat.Clear]: () => [true, true, true, true],\n};\n\n/*\n * Apply vertical align, borders, and background color to all cells in the table\n */\nfunction formatCells(\n rows: ShallowMutableContentModelTableRow[],\n format: TableMetadataFormat,\n metaOverrides: MetaOverrides\n) {\n const { hasBandedRows, hasBandedColumns, bgColorOdd, bgColorEven, hasFirstColumn } = format;\n\n rows.forEach((row, rowIndex) => {\n row.cells.forEach((readonlyCell, colIndex) => {\n const cell = mutateBlock(readonlyCell);\n\n // Format Borders\n if (\n !metaOverrides.borderOverrides[rowIndex][colIndex] &&\n typeof format.tableBorderFormat == 'number'\n ) {\n const transparentBorderMatrix = BorderFormatters[format.tableBorderFormat]?.({\n firstRow: rowIndex === 0,\n lastRow: rowIndex === rows.length - 1,\n firstColumn: colIndex === 0,\n lastColumn: colIndex === row.cells.length - 1,\n });\n\n const formatColor = [\n format.topBorderColor,\n format.verticalBorderColor,\n format.bottomBorderColor,\n format.verticalBorderColor,\n ];\n\n transparentBorderMatrix?.forEach((alwaysUseTransparent, i) => {\n const borderColor = (!alwaysUseTransparent && formatColor[i]) || '';\n\n cell.format[BorderKeys[i]] = combineBorderValue({\n style: getBorderStyleFromColor(borderColor),\n width: '1px',\n color: borderColor,\n });\n });\n }\n\n // Format Background Color\n if (!metaOverrides.bgColorOverrides[rowIndex][colIndex]) {\n let color: string | null | undefined;\n if (hasFirstColumn && colIndex == 0 && rowIndex > 0) {\n color = null;\n } else {\n color =\n hasBandedRows || hasBandedColumns\n ? (hasBandedColumns && colIndex % 2 != 0) ||\n (hasBandedRows && rowIndex % 2 != 0)\n ? bgColorOdd\n : bgColorEven\n : bgColorEven; /* bgColorEven is the default color */\n }\n setTableCellBackgroundColor(\n cell,\n color,\n false /*isColorOverride*/,\n true /*applyToSegments*/\n );\n }\n\n // Format Vertical Align\n if (format.verticalAlign && !metaOverrides.vAlignOverrides[rowIndex][colIndex]) {\n cell.format.verticalAlign = format.verticalAlign;\n }\n\n // Format Header\n cell.isHeader = false;\n });\n });\n}\n\n/**\n * Set the first column format borders for the table as well as header property\n * @param rows The rows of the table\n * @param format The table metadata format\n */\nexport function setFirstColumnFormatBorders(\n rows: ShallowMutableContentModelTableRow[],\n format: Partial<TableMetadataFormat>\n) {\n rows.forEach((row, rowIndex) => {\n row.cells.forEach((readonlyCell, cellIndex) => {\n const cell = mutateBlock(readonlyCell);\n\n if (cellIndex === 0) {\n if (rowIndex == 0) {\n cell.isHeader = !!format.hasHeaderRow;\n }\n for (const block of cell.blocks) {\n if (block.blockType == 'Paragraph') {\n for (const segment of block.segments) {\n mutateSegment(block, segment, cellSegment => {\n if (format.hasFirstColumn) {\n cellSegment.format.fontWeight = 'bold';\n } else if (cellSegment.format.fontWeight == 'bold') {\n delete cellSegment.format.fontWeight;\n }\n });\n }\n }\n }\n }\n });\n });\n}\n\nfunction setHeaderRowFormat(\n rows: ShallowMutableContentModelTableRow[],\n format: TableMetadataFormat,\n metaOverrides: MetaOverrides\n) {\n // Exit early if hasHeaderRow is not set\n if (!format.hasHeaderRow) {\n return;\n }\n\n const rowIndex = 0;\n\n rows[rowIndex]?.cells.forEach((readonlyCell, cellIndex) => {\n const cell = mutateBlock(readonlyCell);\n\n cell.isHeader = true;\n cell.format.fontWeight = 'bold';\n\n if (format.headerRowColor) {\n if (!metaOverrides.bgColorOverrides[rowIndex][cellIndex]) {\n setTableCellBackgroundColor(\n cell,\n format.headerRowColor,\n false /*isColorOverride*/,\n true /*applyToSegments*/\n );\n }\n\n setBorderColor(cell.format, 'borderTop', format.headerRowColor);\n setBorderColor(cell.format, 'borderRight', format.headerRowColor);\n setBorderColor(cell.format, 'borderLeft', format.headerRowColor);\n }\n });\n}\n\n/**\n * @param format The cell format to set the border color\n * @param key The border key to set the color\n * @param value The color to set. If not given, it removes the color and sets the style to transparent\n */\nfunction setBorderColor(format: BorderFormat, key: keyof BorderFormat, value?: string) {\n const border = extractBorderValues(format[key]);\n border.color = value || '';\n border.style = getBorderStyleFromColor(border.color);\n format[key] = combineBorderValue(border);\n}\n\nfunction getBorderStyleFromColor(color?: string): string {\n return !color || color == 'transparent' ? 'none' : 'solid';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"applyTableFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/modelApi/editing/applyTableFormat.ts"],"names":[],"mappings":";;;;;AAAA,oEAAmE;AACnE,kEAA4F;AAC5F,2CAA8D;AAC9D,6EAA4E;AAC5E,uEAAsE;AACtE,+EAA8E;AAC9E,uEAAsE;AAQtE,IAAM,cAAc,GAAkC;IAClD,cAAc,EAAE,SAAS;IACzB,iBAAiB,EAAE,SAAS;IAC5B,mBAAmB,EAAE,SAAS;IAC9B,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,KAAK;IACpB,gBAAgB,EAAE,KAAK;IACvB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,WAAW;IACvB,cAAc,EAAE,SAAS;IACzB,iBAAiB,EAAE,qCAAiB,CAAC,OAAO;IAC5C,aAAa,EAAE,IAAI;CACtB,CAAC;AAQF;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC5B,KAAgC,EAChC,SAA+B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CAAC;AAED,SAAS,uBAAuB,CAAC,KAAc;IAC3C,OAAO,CAAC,KAAK,IAAI,KAAK,IAAI,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;AAC/D,CAAC","sourcesContent":["import { BorderKeys } from '../../formatHandlers/utils/borderKeys';\nimport { combineBorderValue, extractBorderValues } from '../../domUtils/style/borderValues';\nimport { mutateBlock, mutateSegment } from '../common/mutate';\nimport { setTableCellBackgroundColor } from './setTableCellBackgroundColor';\nimport { TableBorderFormat } from '../../constants/TableBorderFormat';\nimport { updateTableCellMetadata } from '../metadata/updateTableCellMetadata';\nimport { updateTableMetadata } from '../metadata/updateTableMetadata';\nimport type {\n BorderFormat,\n ReadonlyContentModelTable,\n ShallowMutableContentModelTableRow,\n TableMetadataFormat,\n} from 'roosterjs-content-model-types';\n\nconst DEFAULT_FORMAT: Required<TableMetadataFormat> = {\n topBorderColor: '#ABABAB',\n bottomBorderColor: '#ABABAB',\n verticalBorderColor: '#ABABAB',\n hasHeaderRow: false,\n hasFirstColumn: false,\n hasBandedRows: false,\n hasBandedColumns: false,\n bgColorEven: null,\n bgColorOdd: '#ABABAB20',\n headerRowColor: '#ABABAB',\n tableBorderFormat: TableBorderFormat.Default,\n verticalAlign: null,\n};\n\ntype MetaOverrides = {\n bgColorOverrides: boolean[][];\n vAlignOverrides: boolean[][];\n borderOverrides: boolean[][];\n};\n\n/**\n * Apply table format from table metadata and the passed in new format\n * @param table The table to apply format to\n * @param newFormat @optional New format to apply. When passed, this value will be merged into existing metadata format and default format\n * @param keepCellShade @optional When pass true, table cells with customized shade color will not be overwritten. @default false\n */\nexport function applyTableFormat(\n table: ReadonlyContentModelTable,\n newFormat?: TableMetadataFormat,\n keepCellShade?: boolean\n) {\n const mutableTable = mutateBlock(table);\n const { rows } = mutableTable;\n\n updateTableMetadata(mutableTable, format => {\n const effectiveMetadata = {\n ...DEFAULT_FORMAT,\n ...format,\n ...newFormat,\n };\n\n const metaOverrides: MetaOverrides = updateOverrides(rows, !keepCellShade);\n\n formatCells(rows, effectiveMetadata, metaOverrides);\n setFirstColumnFormatBorders(rows, effectiveMetadata);\n setHeaderRowFormat(rows, effectiveMetadata, metaOverrides);\n\n return effectiveMetadata;\n });\n}\n\nfunction updateOverrides(\n rows: ShallowMutableContentModelTableRow[],\n removeCellShade: boolean\n): MetaOverrides {\n const overrides: MetaOverrides = {\n bgColorOverrides: [],\n vAlignOverrides: [],\n borderOverrides: [],\n };\n\n rows.forEach(row => {\n const bgColorOverrides: boolean[] = [];\n const vAlignOverrides: boolean[] = [];\n const borderOverrides: boolean[] = [];\n\n overrides.bgColorOverrides.push(bgColorOverrides);\n overrides.vAlignOverrides.push(vAlignOverrides);\n overrides.borderOverrides.push(borderOverrides);\n\n row.cells.forEach(cell => {\n updateTableCellMetadata(mutateBlock(cell), metadata => {\n if (metadata && removeCellShade) {\n bgColorOverrides.push(false);\n delete metadata.bgColorOverride;\n } else {\n bgColorOverrides.push(!!metadata?.bgColorOverride);\n }\n vAlignOverrides.push(!!metadata?.vAlignOverride);\n borderOverrides.push(!!metadata?.borderOverride);\n\n return metadata;\n });\n });\n });\n\n return overrides;\n}\n\ntype ShouldUseTransparentBorder = (indexProp: {\n firstRow: boolean;\n lastRow: boolean;\n firstColumn: boolean;\n lastColumn: boolean;\n}) => [boolean, boolean, boolean, boolean];\n\nconst BorderFormatters: Record<number, ShouldUseTransparentBorder | undefined> = {\n [TableBorderFormat.Default]: _ => [false, false, false, false],\n [TableBorderFormat.ListWithSideBorders]: ({ lastColumn, firstColumn }) => [\n false,\n !lastColumn,\n false,\n !firstColumn,\n ],\n [TableBorderFormat.FirstColumnHeaderExternal]: ({\n firstColumn,\n firstRow,\n lastColumn,\n lastRow,\n }) => [\n !firstRow,\n (!lastColumn && !firstColumn) || (firstColumn && firstRow),\n !lastRow && !firstRow,\n !firstColumn,\n ],\n [TableBorderFormat.NoHeaderBorders]: ({ firstRow, firstColumn, lastColumn }) => [\n firstRow,\n firstRow || lastColumn,\n false,\n firstRow || firstColumn,\n ],\n [TableBorderFormat.NoSideBorders]: ({ firstColumn, lastColumn }) => [\n false,\n lastColumn,\n false,\n firstColumn,\n ],\n [TableBorderFormat.EspecialType1]: ({ firstRow, firstColumn }) => [\n firstColumn && !firstRow,\n firstRow,\n firstColumn && !firstRow,\n firstRow && !firstColumn,\n ],\n [TableBorderFormat.EspecialType2]: ({ firstRow, firstColumn }) => [\n !firstRow,\n firstRow || !firstColumn,\n !firstRow,\n !firstColumn,\n ],\n [TableBorderFormat.EspecialType3]: ({ firstColumn, firstRow }) => [\n true,\n firstRow || !firstColumn,\n !firstRow,\n true,\n ],\n [TableBorderFormat.Clear]: () => [true, true, true, true],\n};\n\n/*\n * Apply vertical align, borders, and background color to all cells in the table\n */\nfunction formatCells(\n rows: ShallowMutableContentModelTableRow[],\n format: TableMetadataFormat,\n metaOverrides: MetaOverrides\n) {\n const { hasBandedRows, hasBandedColumns, bgColorOdd, bgColorEven, hasFirstColumn } = format;\n\n rows.forEach((row, rowIndex) => {\n row.cells.forEach((readonlyCell, colIndex) => {\n const cell = mutateBlock(readonlyCell);\n\n // Format Borders\n if (\n !metaOverrides.borderOverrides[rowIndex][colIndex] &&\n typeof format.tableBorderFormat == 'number'\n ) {\n const transparentBorderMatrix = BorderFormatters[format.tableBorderFormat]?.({\n firstRow: rowIndex === 0,\n lastRow: rowIndex === rows.length - 1,\n firstColumn: colIndex === 0,\n lastColumn: colIndex === row.cells.length - 1,\n });\n\n const formatColor = [\n format.topBorderColor,\n format.verticalBorderColor,\n format.bottomBorderColor,\n format.verticalBorderColor,\n ];\n\n transparentBorderMatrix?.forEach((alwaysUseTransparent, i) => {\n const borderColor = (!alwaysUseTransparent && formatColor[i]) || '';\n\n cell.format[BorderKeys[i]] = combineBorderValue({\n style: getBorderStyleFromColor(borderColor),\n width: '1px',\n color: borderColor,\n });\n });\n }\n\n // Format Background Color\n if (!metaOverrides.bgColorOverrides[rowIndex][colIndex]) {\n let color: string | null | undefined;\n if (hasFirstColumn && colIndex == 0 && rowIndex > 0) {\n color = null;\n } else {\n color =\n hasBandedRows || hasBandedColumns\n ? (hasBandedColumns && colIndex % 2 != 0) ||\n (hasBandedRows && rowIndex % 2 != 0)\n ? bgColorOdd\n : bgColorEven\n : bgColorEven; /* bgColorEven is the default color */\n }\n setTableCellBackgroundColor(\n cell,\n color,\n false /*isColorOverride*/,\n true /*applyToSegments*/\n );\n }\n\n // Format Vertical Align\n if (format.verticalAlign && !metaOverrides.vAlignOverrides[rowIndex][colIndex]) {\n cell.format.verticalAlign = format.verticalAlign;\n }\n\n // Format Header\n cell.isHeader = false;\n });\n });\n}\n\n/**\n * Set the first column format borders for the table as well as header property\n * @param rows The rows of the table\n * @param format The table metadata format\n */\nexport function setFirstColumnFormatBorders(\n rows: ShallowMutableContentModelTableRow[],\n format: Partial<TableMetadataFormat>\n) {\n rows.forEach((row, rowIndex) => {\n row.cells.forEach((readonlyCell, cellIndex) => {\n const cell = mutateBlock(readonlyCell);\n\n if (cellIndex === 0) {\n if (rowIndex == 0) {\n cell.isHeader = !!format.hasHeaderRow;\n }\n\n for (const block of cell.blocks) {\n if (block.blockType == 'Paragraph') {\n for (const segment of block.segments) {\n mutateSegment(block, segment, cellSegment => {\n if (format.hasFirstColumn) {\n cellSegment.format.fontWeight = 'bold';\n cell.format.fontWeight = 'bold';\n } else if (\n cellSegment.format.fontWeight == 'bold' &&\n cell.format.fontWeight == 'bold'\n ) {\n delete cellSegment.format.fontWeight;\n delete cell.format.fontWeight;\n }\n });\n }\n }\n }\n }\n });\n });\n}\n\nfunction setHeaderRowFormat(\n rows: ShallowMutableContentModelTableRow[],\n format: TableMetadataFormat,\n metaOverrides: MetaOverrides\n) {\n // Exit early if hasHeaderRow is not set\n if (!format.hasHeaderRow) {\n return;\n }\n\n const rowIndex = 0;\n\n rows[rowIndex]?.cells.forEach((readonlyCell, cellIndex) => {\n const cell = mutateBlock(readonlyCell);\n\n cell.isHeader = true;\n cell.format.fontWeight = 'bold';\n\n if (format.headerRowColor) {\n if (!metaOverrides.bgColorOverrides[rowIndex][cellIndex]) {\n setTableCellBackgroundColor(\n cell,\n format.headerRowColor,\n false /*isColorOverride*/,\n true /*applyToSegments*/\n );\n }\n\n setBorderColor(cell.format, 'borderTop', format.headerRowColor);\n setBorderColor(cell.format, 'borderRight', format.headerRowColor);\n setBorderColor(cell.format, 'borderLeft', format.headerRowColor);\n }\n });\n}\n\n/**\n * @param format The cell format to set the border color\n * @param key The border key to set the color\n * @param value The color to set. If not given, it removes the color and sets the style to transparent\n */\nfunction setBorderColor(format: BorderFormat, key: keyof BorderFormat, value?: string) {\n const border = extractBorderValues(format[key]);\n border.color = value || '';\n border.style = getBorderStyleFromColor(border.color);\n format[key] = combineBorderValue(border);\n}\n\nfunction getBorderStyleFromColor(color?: string): string {\n return !color || color == 'transparent' ? 'none' : 'solid';\n}\n"]}
|
|
@@ -40,7 +40,7 @@ function setTableCellBackgroundColor(cell, color, isColorOverride, applyToSegmen
|
|
|
40
40
|
delete cell.format.textColor;
|
|
41
41
|
}
|
|
42
42
|
if (applyToSegments) {
|
|
43
|
-
setAdaptiveCellColor(cell);
|
|
43
|
+
setAdaptiveCellColor(cell, color);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
@@ -54,34 +54,38 @@ function setTableCellBackgroundColor(cell, color, isColorOverride, applyToSegmen
|
|
|
54
54
|
exports.setTableCellBackgroundColor = setTableCellBackgroundColor;
|
|
55
55
|
function removeAdaptiveCellColor(cell) {
|
|
56
56
|
cell.blocks.forEach(function (readonlyBlock) {
|
|
57
|
-
var _a
|
|
57
|
+
var _a;
|
|
58
58
|
if (readonlyBlock.blockType == 'Paragraph') {
|
|
59
59
|
var block = (0, mutate_1.mutateBlock)(readonlyBlock);
|
|
60
60
|
if (((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor) &&
|
|
61
|
-
|
|
61
|
+
(areSameColor(block.segmentFormat.textColor, White) ||
|
|
62
|
+
areSameColor(block.segmentFormat.textColor, Black))) {
|
|
62
63
|
delete block.segmentFormat.textColor;
|
|
63
64
|
}
|
|
64
65
|
block.segments.forEach(function (segment) {
|
|
65
66
|
if (segment.format.textColor &&
|
|
66
|
-
|
|
67
|
+
(areSameColor(segment.format.textColor, White) ||
|
|
68
|
+
areSameColor(segment.format.textColor, Black))) {
|
|
67
69
|
delete segment.format.textColor;
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
73
|
});
|
|
72
74
|
}
|
|
73
|
-
function setAdaptiveCellColor(cell) {
|
|
75
|
+
function setAdaptiveCellColor(cell, backgroundColor) {
|
|
74
76
|
if (cell.format.textColor) {
|
|
75
77
|
cell.blocks.forEach(function (readonlyBlock) {
|
|
76
78
|
var _a;
|
|
77
79
|
if (readonlyBlock.blockType == 'Paragraph') {
|
|
78
80
|
var block = (0, mutate_1.mutateBlock)(readonlyBlock);
|
|
79
|
-
if (!((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor)
|
|
81
|
+
if (!((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor) ||
|
|
82
|
+
areSameColor(backgroundColor, block.segmentFormat.textColor)) {
|
|
80
83
|
block.segmentFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, block.segmentFormat), { textColor: cell.format.textColor });
|
|
81
84
|
}
|
|
82
85
|
block.segments.forEach(function (segment) {
|
|
83
86
|
var _a;
|
|
84
|
-
if (!((_a = segment.format) === null || _a === void 0 ? void 0 : _a.textColor)
|
|
87
|
+
if (!((_a = segment.format) === null || _a === void 0 ? void 0 : _a.textColor) ||
|
|
88
|
+
areSameColor(backgroundColor, segment.format.textColor)) {
|
|
85
89
|
segment.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, segment.format), { textColor: cell.format.textColor });
|
|
86
90
|
}
|
|
87
91
|
});
|
|
@@ -89,22 +93,6 @@ function setAdaptiveCellColor(cell) {
|
|
|
89
93
|
});
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
|
-
/**
|
|
93
|
-
* If the cell background color is too dark or too bright, and the text color is white or black, we should remove the text color
|
|
94
|
-
* @param textColor the segment or block text color
|
|
95
|
-
* @param cellBackgroundColor the cell background color
|
|
96
|
-
* @returns
|
|
97
|
-
*/
|
|
98
|
-
function shouldRemoveColor(textColor, cellBackgroundColor) {
|
|
99
|
-
var lightness = calculateLightness(cellBackgroundColor);
|
|
100
|
-
if (([White, 'rgb(255,255,255)'].indexOf(textColor) > -1 &&
|
|
101
|
-
(lightness > BRIGHT_COLORS_LIGHTNESS || cellBackgroundColor == '')) ||
|
|
102
|
-
([Black, 'rgb(0,0,0)'].indexOf(textColor) > -1 &&
|
|
103
|
-
(lightness < DARK_COLORS_LIGHTNESS || cellBackgroundColor == ''))) {
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
96
|
function calculateLightness(color) {
|
|
109
97
|
var colorValues = (0, color_1.parseColor)(color);
|
|
110
98
|
// Use the values of r,g,b to calculate the lightness in the HSl representation
|
|
@@ -120,4 +108,15 @@ function calculateLightness(color) {
|
|
|
120
108
|
return 255;
|
|
121
109
|
}
|
|
122
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if two colors are the same by comparing their RGB values
|
|
113
|
+
*/
|
|
114
|
+
function areSameColor(color1, color2) {
|
|
115
|
+
var rgb1 = (0, color_1.parseColor)(color1);
|
|
116
|
+
var rgb2 = (0, color_1.parseColor)(color2);
|
|
117
|
+
if (rgb1 && rgb2) {
|
|
118
|
+
return rgb1[0] === rgb2[0] && rgb1[1] === rgb2[1] && rgb1[2] === rgb2[2];
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
123
122
|
//# sourceMappingURL=setTableCellBackgroundColor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setTableCellBackgroundColor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/modelApi/editing/setTableCellBackgroundColor.ts"],"names":[],"mappings":";;;;AAAA,2CAA+C;AAC/C,0DAA8D;AAC9D,+EAA8E;AAG9E,qFAAqF;AACrF,oEAAoE;AACpE,qEAAqE;AACrE,IAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,IAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,IAAM,KAAK,GAAG,SAAS,CAAC;AACxB,IAAM,KAAK,GAAG,SAAS,CAAC;AAExB;;;;;;GAMG;AACH,SAAgB,2BAA2B,CACvC,IAAyC,EACzC,KAAgC,EAChC,eAAyB,EACzB,eAAyB;IAEzB,IAAI,KAAK,EAAE;QACP,IAAI,CAAC,MAAM,CAAC,eAAe,GAAG,KAAK,CAAC;QAEpC,IAAI,eAAe,EAAE;YACjB,IAAA,iDAAuB,EAAC,IAAI,EAAE,UAAA,QAAQ;gBAClC,QAAQ,GAAG,QAAQ,IAAI,EAAE,CAAC;gBAC1B,QAAQ,CAAC,eAAe,GAAG,IAAI,CAAC;gBAChC,OAAO,QAAQ,CAAC;YACpB,CAAC,CAAC,CAAC;SACN;QAED,IAAM,SAAS,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE5C,IAAI,SAAS,GAAG,qBAAqB,EAAE;YACnC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC;SACjC;aAAM,IAAI,SAAS,GAAG,uBAAuB,EAAE;YAC5C,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC;SACjC;aAAM;YACH,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;SAChC;QAED,IAAI,eAAe,EAAE;YACjB,oBAAoB,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"setTableCellBackgroundColor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/modelApi/editing/setTableCellBackgroundColor.ts"],"names":[],"mappings":";;;;AAAA,2CAA+C;AAC/C,0DAA8D;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EhC,IAAI,IAAI,IAAI,IAAI,EAAE;QACd,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;KAC5E;IACD,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { mutateBlock } from '../common/mutate';\nimport { parseColor } from '../../formatHandlers/utils/color';\nimport { updateTableCellMetadata } from '../metadata/updateTableCellMetadata';\nimport type { ShallowMutableContentModelTableCell } from 'roosterjs-content-model-types';\n\n// Using the HSL (hue, saturation and lightness) representation for RGB color values.\n// If the value of the lightness is less than 20, the color is dark.\n// If the value of the lightness is more than 80, the color is bright\nconst DARK_COLORS_LIGHTNESS = 20;\nconst BRIGHT_COLORS_LIGHTNESS = 80;\nconst White = '#ffffff';\nconst Black = '#000000';\n\n/**\n * Set shade color of table cell\n * @param cell The cell to set shade color to\n * @param color The color to set\n * @param isColorOverride @optional When pass true, it means this shade color is not part of table format, so it can be preserved when apply table format\n * @param applyToSegments @optional When pass true, we will also apply text color from table cell to its child blocks and segments\n */\nexport function setTableCellBackgroundColor(\n cell: ShallowMutableContentModelTableCell,\n color: string | null | undefined,\n isColorOverride?: boolean,\n applyToSegments?: boolean\n) {\n if (color) {\n cell.format.backgroundColor = color;\n\n if (isColorOverride) {\n updateTableCellMetadata(cell, metadata => {\n metadata = metadata || {};\n metadata.bgColorOverride = true;\n return metadata;\n });\n }\n\n const lightness = calculateLightness(color);\n\n if (lightness < DARK_COLORS_LIGHTNESS) {\n cell.format.textColor = White;\n } else if (lightness > BRIGHT_COLORS_LIGHTNESS) {\n cell.format.textColor = Black;\n } else {\n delete cell.format.textColor;\n }\n\n if (applyToSegments) {\n setAdaptiveCellColor(cell, color);\n }\n } else {\n delete cell.format.backgroundColor;\n delete cell.format.textColor;\n if (applyToSegments) {\n removeAdaptiveCellColor(cell);\n }\n }\n}\n\nfunction removeAdaptiveCellColor(cell: ShallowMutableContentModelTableCell) {\n cell.blocks.forEach(readonlyBlock => {\n if (readonlyBlock.blockType == 'Paragraph') {\n const block = mutateBlock(readonlyBlock);\n\n if (\n block.segmentFormat?.textColor &&\n (areSameColor(block.segmentFormat.textColor, White) ||\n areSameColor(block.segmentFormat.textColor, Black))\n ) {\n delete block.segmentFormat.textColor;\n }\n block.segments.forEach(segment => {\n if (\n segment.format.textColor &&\n (areSameColor(segment.format.textColor, White) ||\n areSameColor(segment.format.textColor, Black))\n ) {\n delete segment.format.textColor;\n }\n });\n }\n });\n}\n\nfunction setAdaptiveCellColor(cell: ShallowMutableContentModelTableCell, backgroundColor: string) {\n if (cell.format.textColor) {\n cell.blocks.forEach(readonlyBlock => {\n if (readonlyBlock.blockType == 'Paragraph') {\n const block = mutateBlock(readonlyBlock);\n\n if (\n !block.segmentFormat?.textColor ||\n areSameColor(backgroundColor, block.segmentFormat.textColor)\n ) {\n block.segmentFormat = {\n ...block.segmentFormat,\n textColor: cell.format.textColor,\n };\n }\n block.segments.forEach(segment => {\n if (\n !segment.format?.textColor ||\n areSameColor(backgroundColor, segment.format.textColor)\n ) {\n segment.format = {\n ...segment.format,\n textColor: cell.format.textColor,\n };\n }\n });\n }\n });\n }\n}\n\nfunction calculateLightness(color: string) {\n const colorValues = parseColor(color);\n\n // Use the values of r,g,b to calculate the lightness in the HSl representation\n //First calculate the fraction of the light in each color, since in css the value of r,g,b is in the interval of [0,255], we have\n if (colorValues) {\n const red = colorValues[0] / 255;\n const green = colorValues[1] / 255;\n const blue = colorValues[2] / 255;\n\n //Then the lightness in the HSL representation is the average between maximum fraction of r,g,b and the minimum fraction\n return (Math.max(red, green, blue) + Math.min(red, green, blue)) * 50;\n } else {\n return 255;\n }\n}\n\n/**\n * Check if two colors are the same by comparing their RGB values\n */\nfunction areSameColor(color1: string, color2: string): boolean {\n const rgb1 = parseColor(color1);\n const rgb2 = parseColor(color2);\n\n if (rgb1 && rgb2) {\n return rgb1[0] === rgb2[0] && rgb1[1] === rgb2[1] && rgb1[2] === rgb2[2];\n }\n return false;\n}\n"]}
|
|
@@ -12,3 +12,7 @@ export declare const ContextStyles: (keyof (MarginFormat & PaddingFormat))[];
|
|
|
12
12
|
* @param context DOM to Content Model context
|
|
13
13
|
*/
|
|
14
14
|
export declare const formatContainerProcessor: ElementProcessor<HTMLElement>;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare const forceFormatContainerProcessor: ElementProcessor<HTMLElement>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
define(["require", "exports", "tslib", "../../modelApi/common/addBlock", "../../modelApi/creators/createFormatContainer", "../../modelApi/creators/createParagraph", "../utils/getDefaultStyle", "../utils/parseFormat", "../../modelApi/block/setParagraphNotImplicit", "../utils/stackFormat"], function (require, exports, tslib_1, addBlock_1, createFormatContainer_1, createParagraph_1, getDefaultStyle_1, parseFormat_1, setParagraphNotImplicit_1, stackFormat_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.formatContainerProcessor = exports.ContextStyles = void 0;
|
|
4
|
+
exports.forceFormatContainerProcessor = exports.formatContainerProcessor = exports.ContextStyles = void 0;
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
@@ -20,6 +20,17 @@ define(["require", "exports", "tslib", "../../modelApi/common/addBlock", "../../
|
|
|
20
20
|
* @param context DOM to Content Model context
|
|
21
21
|
*/
|
|
22
22
|
var formatContainerProcessor = function (group, element, context) {
|
|
23
|
+
formatContainerProcessorInternal(group, element, context, false /* forceFormatContainer */);
|
|
24
|
+
};
|
|
25
|
+
exports.formatContainerProcessor = formatContainerProcessor;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
var forceFormatContainerProcessor = function (group, element, context) {
|
|
30
|
+
formatContainerProcessorInternal(group, element, context, true /* forceFormatContainer */);
|
|
31
|
+
};
|
|
32
|
+
exports.forceFormatContainerProcessor = forceFormatContainerProcessor;
|
|
33
|
+
var formatContainerProcessorInternal = function (group, element, context, forceFormatContainer) {
|
|
23
34
|
(0, stackFormat_1.stackFormat)(context, { segment: 'shallowCloneForBlock', paragraph: 'shallowClone' }, function () {
|
|
24
35
|
(0, parseFormat_1.parseFormat)(element, context.formatParsers.block, context.blockFormat, context);
|
|
25
36
|
(0, parseFormat_1.parseFormat)(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);
|
|
@@ -37,7 +48,7 @@ define(["require", "exports", "tslib", "../../modelApi/common/addBlock", "../../
|
|
|
37
48
|
if (element.style.fontSize && parseInt(element.style.fontSize) == 0) {
|
|
38
49
|
formatContainer.zeroFontSize = true;
|
|
39
50
|
}
|
|
40
|
-
if (shouldFallbackToParagraph(formatContainer)) {
|
|
51
|
+
if (shouldFallbackToParagraph(formatContainer) && !forceFormatContainer) {
|
|
41
52
|
// For DIV container that only has one paragraph child, container style can be merged into paragraph
|
|
42
53
|
// and no need to have this container
|
|
43
54
|
var paragraph = formatContainer.blocks[0];
|
|
@@ -56,7 +67,6 @@ define(["require", "exports", "tslib", "../../modelApi/common/addBlock", "../../
|
|
|
56
67
|
});
|
|
57
68
|
(0, addBlock_1.addBlock)(group, (0, createParagraph_1.createParagraph)(true /*isImplicit*/, context.blockFormat));
|
|
58
69
|
};
|
|
59
|
-
exports.formatContainerProcessor = formatContainerProcessor;
|
|
60
70
|
function shouldFallbackToParagraph(formatContainer) {
|
|
61
71
|
var firstChild = formatContainer.blocks[0];
|
|
62
72
|
return (formatContainer.tagName == 'div' &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatContainerProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/domToModel/processors/formatContainerProcessor.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"formatContainerProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-dom/lib/domToModel/processors/formatContainerProcessor.ts"],"names":[],"mappings":";;;;IAkBA;;OAEG;IACU,QAAA,aAAa,GAA6C;QACnE,YAAY;QACZ,aAAa;QACb,aAAa;QACb,cAAc;KACjB,CAAC;IAEF;;;;;;;OAOG;IACI,IAAM,wBAAwB,GAAkC,UACnE,KAAK,EACL,OAAO,EACP,OAAO;QAEP,gCAAgC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAChG,CAAC,CAAC;IANW,QAAA,wBAAwB,4BAMnC;IAEF;;OAEG;IACI,IAAM,6BAA6B,GAAkC,UACxE,KAAK,EACL,OAAO,EACP,OAAO;QAEP,gCAAgC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC/F,CAAC,CAAC;IANW,QAAA,6BAA6B,iCAMxC;IAEF,IAAM,gCAAgC,GAAG,UACrC,KAA6B,EAC7B,OAAoB,EACpB,OAA0B,EAC1B,oBAA6B;QAE7B,IAAA,yBAAW,EAAC,OAAO,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,cAAc,EAAE,EAAE;YACjF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YAChF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;YAE3F,IAAM,MAAM,6BACL,OAAO,CAAC,WAAW,CACzB,CAAC;YAEF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAEvE,IAAM,OAAO,GACT,IAAA,iCAAe,EAAC,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,CAAC,CAAC,CAAC;QAEH,IAAA,mBAAQ,EAAC,KAAK,EAAE,IAAA,iCAAe,EAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAC/E,CAAC,CAAC;IAEF,SAAS,yBAAyB,CAAC,eAA4C;QAC3E,IAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE7C,OAAO,CACH,eAAe,CAAC,OAAO,IAAI,KAAK;YAChC,eAAe,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC;YAClC,UAAU,CAAC,SAAS,IAAI,WAAW;YACnC,UAAU,CAAC,UAAU,CACxB,CAAC;IACN,CAAC","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { createFormatContainer } from '../../modelApi/creators/createFormatContainer';\nimport { createParagraph } from '../../modelApi/creators/createParagraph';\nimport { getDefaultStyle } from '../utils/getDefaultStyle';\nimport { parseFormat } from '../utils/parseFormat';\nimport { setParagraphNotImplicit } from '../../modelApi/block/setParagraphNotImplicit';\nimport { stackFormat } from '../utils/stackFormat';\nimport type {\n ContentModelBlockGroup,\n ContentModelFormatContainer,\n ContentModelFormatContainerFormat,\n ContentModelParagraph,\n DomToModelContext,\n ElementProcessor,\n MarginFormat,\n PaddingFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const ContextStyles: (keyof (MarginFormat & PaddingFormat))[] = [\n 'marginLeft',\n 'marginRight',\n 'paddingLeft',\n 'paddingRight',\n];\n\n/**\n * Content Model Element Processor for format container elements (e.g., blockquote, div)\n * Processes elements that create FormatContainer blocks in the content model.\n * This processor can be used in processorOverride to customize how specific elements are processed.\n * @param group The parent block group\n * @param element The DOM element to process\n * @param context DOM to Content Model context\n */\nexport const formatContainerProcessor: ElementProcessor<HTMLElement> = (\n group,\n element,\n context\n) => {\n formatContainerProcessorInternal(group, element, context, false /* forceFormatContainer */);\n};\n\n/**\n * @internal\n */\nexport const forceFormatContainerProcessor: ElementProcessor<HTMLElement> = (\n group,\n element,\n context\n) => {\n formatContainerProcessorInternal(group, element, context, true /* forceFormatContainer */);\n};\n\nconst formatContainerProcessorInternal = (\n group: ContentModelBlockGroup,\n element: HTMLElement,\n context: DomToModelContext,\n forceFormatContainer: boolean\n) => {\n stackFormat(context, { segment: 'shallowCloneForBlock', paragraph: 'shallowClone' }, () => {\n parseFormat(element, context.formatParsers.block, context.blockFormat, context);\n parseFormat(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);\n\n const format: ContentModelFormatContainerFormat = {\n ...context.blockFormat,\n };\n\n parseFormat(element, context.formatParsers.container, format, context);\n\n const tagName =\n getDefaultStyle(element).display == 'block' ? element.tagName.toLowerCase() : 'div';\n const formatContainer = createFormatContainer(tagName, format);\n\n // It is possible to inherit margin left/right styles from parent DIV or other containers,\n // since we are going into a deeper level of format container now,\n // the container will render these styles so no need to keep them in context format\n ContextStyles.forEach(style => {\n delete context.blockFormat[style];\n });\n\n context.elementProcessors.child(formatContainer, element, context);\n\n if (element.style.fontSize && parseInt(element.style.fontSize) == 0) {\n formatContainer.zeroFontSize = true;\n }\n\n if (shouldFallbackToParagraph(formatContainer) && !forceFormatContainer) {\n // For DIV container that only has one paragraph child, container style can be merged into paragraph\n // and no need to have this container\n const paragraph = formatContainer.blocks[0] as ContentModelParagraph;\n\n if (formatContainer.zeroFontSize) {\n paragraph.segmentFormat = Object.assign({}, paragraph.segmentFormat, {\n fontSize: '0',\n });\n }\n\n Object.assign(paragraph.format, formatContainer.format);\n setParagraphNotImplicit(paragraph);\n addBlock(group, paragraph);\n } else {\n addBlock(group, formatContainer);\n }\n });\n\n addBlock(group, createParagraph(true /*isImplicit*/, context.blockFormat));\n};\n\nfunction shouldFallbackToParagraph(formatContainer: ContentModelFormatContainer) {\n const firstChild = formatContainer.blocks[0];\n\n return (\n formatContainer.tagName == 'div' &&\n formatContainer.blocks.length == 1 &&\n firstChild.blockType == 'Paragraph' &&\n firstChild.isImplicit\n );\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "../../modelApi/common/addBlock", "./blockProcessor", "../../modelApi/creators/createParagraph", "
|
|
1
|
+
define(["require", "exports", "../../modelApi/common/addBlock", "./blockProcessor", "../../modelApi/creators/createParagraph", "../utils/getDefaultStyle", "../utils/isBlockElement", "../../domUtils/entityUtils", "../utils/parseFormat", "../utils/stackFormat", "./formatContainerProcessor"], function (require, exports, addBlock_1, blockProcessor_1, createParagraph_1, getDefaultStyle_1, isBlockElement_1, entityUtils_1, parseFormat_1, stackFormat_1, formatContainerProcessor_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.knownElementProcessor = void 0;
|
|
@@ -28,8 +28,12 @@ define(["require", "exports", "../../modelApi/common/addBlock", "./blockProcesso
|
|
|
28
28
|
*/
|
|
29
29
|
var knownElementProcessor = function (group, element, context) {
|
|
30
30
|
var isBlock = (0, isBlockElement_1.isBlockElement)(element);
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
var isBlockContainer = isBlock || element.style.display == 'inline-block';
|
|
32
|
+
if (isBlockContainer && // For inline-block here, we will also check if it should be represented as Format Container
|
|
33
|
+
shouldForceUseFormatContainer(element, context)) {
|
|
34
|
+
(0, formatContainerProcessor_1.forceFormatContainerProcessor)(group, element, context);
|
|
35
|
+
}
|
|
36
|
+
else if (isBlockContainer && shouldUseFormatContainer(element, context)) {
|
|
33
37
|
(0, formatContainerProcessor_1.formatContainerProcessor)(group, element, context);
|
|
34
38
|
}
|
|
35
39
|
else if ((0, entityUtils_1.isBlockEntityContainer)(element)) {
|
|
@@ -63,6 +67,9 @@ define(["require", "exports", "../../modelApi/common/addBlock", "./blockProcesso
|
|
|
63
67
|
}
|
|
64
68
|
};
|
|
65
69
|
exports.knownElementProcessor = knownElementProcessor;
|
|
70
|
+
function shouldForceUseFormatContainer(element, context) {
|
|
71
|
+
return FormatContainerTriggerAttributes.some(function (attr) { return element.hasAttribute(attr); });
|
|
72
|
+
}
|
|
66
73
|
function shouldUseFormatContainer(element, context) {
|
|
67
74
|
// For those tags that we know we should not use format container, just return false
|
|
68
75
|
if (ByPassFormatContainerTags.indexOf(element.tagName) >= 0) {
|
|
@@ -77,8 +84,7 @@ define(["require", "exports", "../../modelApi/common/addBlock", "./blockProcesso
|
|
|
77
84
|
}
|
|
78
85
|
// For block element with positive value of border width or top/bottom margin/padding,
|
|
79
86
|
// we need to use format container
|
|
80
|
-
if (FormatContainerTriggerStyles.some(function (key) { return parseInt(style[key] || defaultStyle[key] || '') > 0; })
|
|
81
|
-
FormatContainerTriggerAttributes.some(function (attr) { return element.hasAttribute(attr); })) {
|
|
87
|
+
if (FormatContainerTriggerStyles.some(function (key) { return parseInt(style[key] || defaultStyle[key] || '') > 0; })) {
|
|
82
88
|
return true;
|
|
83
89
|
}
|
|
84
90
|
// For margin left/right with value "auto", we need to use format container
|