roosterjs-content-model-dom 0.23.0 → 0.24.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.
Files changed (118) hide show
  1. package/lib/domToModel/context/createDomToModelContext.js +10 -2
  2. package/lib/domToModel/context/createDomToModelContext.js.map +1 -1
  3. package/lib/domToModel/processors/childProcessor.d.ts +2 -1
  4. package/lib/domToModel/processors/childProcessor.js +6 -5
  5. package/lib/domToModel/processors/childProcessor.js.map +1 -1
  6. package/lib/domToModel/processors/tableProcessor.js +46 -6
  7. package/lib/domToModel/processors/tableProcessor.js.map +1 -1
  8. package/lib/domToModel/processors/textProcessor.js +18 -4
  9. package/lib/domToModel/processors/textProcessor.js.map +1 -1
  10. package/lib/domToModel/utils/addSelectionMarker.d.ts +1 -1
  11. package/lib/domToModel/utils/addSelectionMarker.js +7 -2
  12. package/lib/domToModel/utils/addSelectionMarker.js.map +1 -1
  13. package/lib/domToModel/utils/stackFormat.js +13 -3
  14. package/lib/domToModel/utils/stackFormat.js.map +1 -1
  15. package/lib/formatHandlers/block/textIndentFormatHandler.d.ts +6 -0
  16. package/lib/formatHandlers/block/textIndentFormatHandler.js +20 -0
  17. package/lib/formatHandlers/block/textIndentFormatHandler.js.map +1 -0
  18. package/lib/formatHandlers/common/backgroundColorFormatHandler.js +2 -2
  19. package/lib/formatHandlers/common/backgroundColorFormatHandler.js.map +1 -1
  20. package/lib/formatHandlers/common/borderFormatHandler.js +19 -1
  21. package/lib/formatHandlers/common/borderFormatHandler.js.map +1 -1
  22. package/lib/formatHandlers/defaultFormatHandlers.js +5 -0
  23. package/lib/formatHandlers/defaultFormatHandlers.js.map +1 -1
  24. package/lib/formatHandlers/segment/textColorFormatHandler.js +2 -2
  25. package/lib/formatHandlers/segment/textColorFormatHandler.js.map +1 -1
  26. package/lib/formatHandlers/table/tableSpacingFormatHandler.js +9 -0
  27. package/lib/formatHandlers/table/tableSpacingFormatHandler.js.map +1 -1
  28. package/lib/formatHandlers/utils/color.d.ts +13 -6
  29. package/lib/formatHandlers/utils/color.js +86 -15
  30. package/lib/formatHandlers/utils/color.js.map +1 -1
  31. package/lib/index.d.ts +1 -1
  32. package/lib/index.js +2 -1
  33. package/lib/index.js.map +1 -1
  34. package/lib/modelApi/common/addSegment.js +11 -0
  35. package/lib/modelApi/common/addSegment.js.map +1 -1
  36. package/lib/modelToDom/context/createModelToDomContext.js +10 -2
  37. package/lib/modelToDom/context/createModelToDomContext.js.map +1 -1
  38. package/lib/modelToDom/handlers/handleText.js +1 -0
  39. package/lib/modelToDom/handlers/handleText.js.map +1 -1
  40. package/lib-amd/domToModel/context/createDomToModelContext.js +10 -2
  41. package/lib-amd/domToModel/context/createDomToModelContext.js.map +1 -1
  42. package/lib-amd/domToModel/processors/childProcessor.d.ts +2 -1
  43. package/lib-amd/domToModel/processors/childProcessor.js +6 -5
  44. package/lib-amd/domToModel/processors/childProcessor.js.map +1 -1
  45. package/lib-amd/domToModel/processors/tableProcessor.js +46 -7
  46. package/lib-amd/domToModel/processors/tableProcessor.js.map +1 -1
  47. package/lib-amd/domToModel/processors/textProcessor.js +18 -5
  48. package/lib-amd/domToModel/processors/textProcessor.js.map +1 -1
  49. package/lib-amd/domToModel/utils/addSelectionMarker.d.ts +1 -1
  50. package/lib-amd/domToModel/utils/addSelectionMarker.js +7 -2
  51. package/lib-amd/domToModel/utils/addSelectionMarker.js.map +1 -1
  52. package/lib-amd/domToModel/utils/stackFormat.js +13 -3
  53. package/lib-amd/domToModel/utils/stackFormat.js.map +1 -1
  54. package/lib-amd/formatHandlers/block/textIndentFormatHandler.d.ts +6 -0
  55. package/lib-amd/formatHandlers/block/textIndentFormatHandler.js +22 -0
  56. package/lib-amd/formatHandlers/block/textIndentFormatHandler.js.map +1 -0
  57. package/lib-amd/formatHandlers/common/backgroundColorFormatHandler.js +2 -2
  58. package/lib-amd/formatHandlers/common/backgroundColorFormatHandler.js.map +1 -1
  59. package/lib-amd/formatHandlers/common/borderFormatHandler.js +19 -1
  60. package/lib-amd/formatHandlers/common/borderFormatHandler.js.map +1 -1
  61. package/lib-amd/formatHandlers/defaultFormatHandlers.js +5 -1
  62. package/lib-amd/formatHandlers/defaultFormatHandlers.js.map +1 -1
  63. package/lib-amd/formatHandlers/segment/textColorFormatHandler.js +2 -2
  64. package/lib-amd/formatHandlers/segment/textColorFormatHandler.js.map +1 -1
  65. package/lib-amd/formatHandlers/table/tableSpacingFormatHandler.js +9 -0
  66. package/lib-amd/formatHandlers/table/tableSpacingFormatHandler.js.map +1 -1
  67. package/lib-amd/formatHandlers/utils/color.d.ts +13 -6
  68. package/lib-amd/formatHandlers/utils/color.js +85 -16
  69. package/lib-amd/formatHandlers/utils/color.js.map +1 -1
  70. package/lib-amd/index.d.ts +1 -1
  71. package/lib-amd/index.js +2 -1
  72. package/lib-amd/index.js.map +1 -1
  73. package/lib-amd/modelApi/common/addSegment.js +11 -0
  74. package/lib-amd/modelApi/common/addSegment.js.map +1 -1
  75. package/lib-amd/modelToDom/context/createModelToDomContext.js +10 -2
  76. package/lib-amd/modelToDom/context/createModelToDomContext.js.map +1 -1
  77. package/lib-amd/modelToDom/handlers/handleText.js +1 -0
  78. package/lib-amd/modelToDom/handlers/handleText.js.map +1 -1
  79. package/lib-mjs/domToModel/context/createDomToModelContext.js +10 -2
  80. package/lib-mjs/domToModel/context/createDomToModelContext.js.map +1 -1
  81. package/lib-mjs/domToModel/processors/childProcessor.d.ts +2 -1
  82. package/lib-mjs/domToModel/processors/childProcessor.js +6 -5
  83. package/lib-mjs/domToModel/processors/childProcessor.js.map +1 -1
  84. package/lib-mjs/domToModel/processors/tableProcessor.js +46 -6
  85. package/lib-mjs/domToModel/processors/tableProcessor.js.map +1 -1
  86. package/lib-mjs/domToModel/processors/textProcessor.js +17 -3
  87. package/lib-mjs/domToModel/processors/textProcessor.js.map +1 -1
  88. package/lib-mjs/domToModel/utils/addSelectionMarker.d.ts +1 -1
  89. package/lib-mjs/domToModel/utils/addSelectionMarker.js +7 -2
  90. package/lib-mjs/domToModel/utils/addSelectionMarker.js.map +1 -1
  91. package/lib-mjs/domToModel/utils/stackFormat.js +13 -3
  92. package/lib-mjs/domToModel/utils/stackFormat.js.map +1 -1
  93. package/lib-mjs/formatHandlers/block/textIndentFormatHandler.d.ts +6 -0
  94. package/lib-mjs/formatHandlers/block/textIndentFormatHandler.js +17 -0
  95. package/lib-mjs/formatHandlers/block/textIndentFormatHandler.js.map +1 -0
  96. package/lib-mjs/formatHandlers/common/backgroundColorFormatHandler.js +2 -2
  97. package/lib-mjs/formatHandlers/common/backgroundColorFormatHandler.js.map +1 -1
  98. package/lib-mjs/formatHandlers/common/borderFormatHandler.js +19 -1
  99. package/lib-mjs/formatHandlers/common/borderFormatHandler.js.map +1 -1
  100. package/lib-mjs/formatHandlers/defaultFormatHandlers.js +5 -0
  101. package/lib-mjs/formatHandlers/defaultFormatHandlers.js.map +1 -1
  102. package/lib-mjs/formatHandlers/segment/textColorFormatHandler.js +2 -2
  103. package/lib-mjs/formatHandlers/segment/textColorFormatHandler.js.map +1 -1
  104. package/lib-mjs/formatHandlers/table/tableSpacingFormatHandler.js +9 -0
  105. package/lib-mjs/formatHandlers/table/tableSpacingFormatHandler.js.map +1 -1
  106. package/lib-mjs/formatHandlers/utils/color.d.ts +13 -6
  107. package/lib-mjs/formatHandlers/utils/color.js +83 -13
  108. package/lib-mjs/formatHandlers/utils/color.js.map +1 -1
  109. package/lib-mjs/index.d.ts +1 -1
  110. package/lib-mjs/index.js +1 -1
  111. package/lib-mjs/index.js.map +1 -1
  112. package/lib-mjs/modelApi/common/addSegment.js +11 -0
  113. package/lib-mjs/modelApi/common/addSegment.js.map +1 -1
  114. package/lib-mjs/modelToDom/context/createModelToDomContext.js +10 -2
  115. package/lib-mjs/modelToDom/context/createModelToDomContext.js.map +1 -1
  116. package/lib-mjs/modelToDom/handlers/handleText.js +1 -0
  117. package/lib-mjs/modelToDom/handlers/handleText.js.map +1 -1
  118. package/package.json +2 -2
@@ -81,7 +81,7 @@ function buildFormatParsers(overrides, additionalParsersArray) {
81
81
  if (overrides === void 0) { overrides = []; }
82
82
  if (additionalParsersArray === void 0) { additionalParsersArray = []; }
83
83
  var combinedOverrides = Object.assign.apply(Object, (0, tslib_1.__spreadArray)([{}], (0, tslib_1.__read)(overrides), false));
84
- return (0, getObjectKeys_1.getObjectKeys)(defaultFormatHandlers_1.defaultFormatKeysPerCategory).reduce(function (result, key) {
84
+ var result = (0, getObjectKeys_1.getObjectKeys)(defaultFormatHandlers_1.defaultFormatKeysPerCategory).reduce(function (result, key) {
85
85
  var _a;
86
86
  var value = (_a = defaultFormatHandlers_1.defaultFormatKeysPerCategory[key]
87
87
  .map(function (formatKey) {
@@ -92,7 +92,15 @@ function buildFormatParsers(overrides, additionalParsersArray) {
92
92
  .concat.apply(_a, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(additionalParsersArray.map(function (parsers) { var _a; return ((_a = parsers === null || parsers === void 0 ? void 0 : parsers[key]) !== null && _a !== void 0 ? _a : []); })), false));
93
93
  result[key] = value;
94
94
  return result;
95
- }, {});
95
+ }, {
96
+ text: [],
97
+ });
98
+ additionalParsersArray.forEach(function (parsers) {
99
+ if (parsers === null || parsers === void 0 ? void 0 : parsers.text) {
100
+ result.text = result.text.concat(parsers.text);
101
+ }
102
+ });
103
+ return result;
96
104
  }
97
105
  exports.buildFormatParsers = buildFormatParsers;
98
106
  //# sourceMappingURL=createDomToModelContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createDomToModelContext.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext.ts"],"names":[],"mappings":";;;;AAAA,yDAA0D;AAC1D,8DAA6D;AAC7D,oFAGoD;AAepD;;;;GAIG;AACH,SAAgB,uBAAuB,CACnC,aAA6B;IAC7B,iBAA4C;SAA5C,UAA4C,EAA5C,qBAA4C,EAA5C,IAA4C;QAA5C,gCAA4C;;IAE5C,OAAO,iCAAiC,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ACvC,CAAC;AAxBD,gDAwBC","sourcesContent":["import { defaultProcessorMap } from './defaultProcessors';\nimport { getObjectKeys } from '../../domUtils/getObjectKeys';\nimport {\n defaultFormatKeysPerCategory,\n defaultFormatParsers,\n} from '../../formatHandlers/defaultFormatHandlers';\nimport type {\n ContentModelBlockFormat,\n DomToModelContext,\n DomToModelDecoratorContext,\n DomToModelFormatContext,\n DomToModelOption,\n DomToModelSelectionContext,\n DomToModelSettings,\n EditorContext,\n FormatParser,\n FormatParsers,\n FormatParsersPerCategory,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create context object for DOM to Content Model conversion\n * @param editorContext Context of editor\n * @param options Option array to customize the DOM to Model conversion behavior\n */\nexport function createDomToModelContext(\n editorContext?: EditorContext,\n ...options: (DomToModelOption | undefined)[]\n): DomToModelContext {\n return createDomToModelContextWithConfig(createDomToModelConfig(options), editorContext);\n}\n\n/**\n * Create context object for DOM to Content Model conversion with an existing configure\n * @param config A full config object to define how to convert DOM tree to Content Model\n * @param editorContext Context of editor\n */\nexport function createDomToModelContextWithConfig(\n config: DomToModelSettings,\n editorContext?: EditorContext\n) {\n return Object.assign(\n {},\n editorContext,\n createDomToModelSelectionContext(),\n createDomToModelFormatContext(editorContext?.isRootRtl),\n createDomToModelDecoratorContext(),\n config\n );\n}\n\nfunction createDomToModelSelectionContext(): DomToModelSelectionContext {\n return { isInSelection: false };\n}\n\nfunction createDomToModelFormatContext(isRootRtl?: boolean): DomToModelFormatContext {\n const blockFormat: ContentModelBlockFormat = isRootRtl ? { direction: 'rtl' } : {};\n\n return {\n blockFormat,\n segmentFormat: {},\n\n listFormat: {\n levels: [],\n threadItemCounts: [],\n },\n };\n}\n\nfunction createDomToModelDecoratorContext(): DomToModelDecoratorContext {\n return {\n link: {\n format: {},\n dataset: {},\n },\n code: {\n format: {},\n },\n blockDecorator: {\n format: {},\n tagName: '',\n },\n };\n}\n\n/**\n * Create Dom to Content Model Config object\n * @param options All customizations of content model creation\n */\nexport function createDomToModelConfig(\n options: (DomToModelOption | undefined)[]\n): DomToModelSettings {\n return {\n elementProcessors: Object.assign(\n {},\n defaultProcessorMap,\n ...options.map(x => x?.processorOverride)\n ),\n formatParsers: buildFormatParsers(\n options.map(x => x?.formatParserOverride),\n options.map(x => x?.additionalFormatParsers)\n ),\n defaultElementProcessors: defaultProcessorMap,\n defaultFormatParsers,\n };\n}\n\n/**\n * @internal Export for test only\n * Build format parsers used by DOM to Content Model conversion\n * @param override\n * @param additionalParsersArray\n * @returns\n */\nexport function buildFormatParsers(\n overrides: (Partial<FormatParsers> | undefined)[] = [],\n additionalParsersArray: (Partial<FormatParsersPerCategory> | undefined)[] = []\n): FormatParsersPerCategory {\n const combinedOverrides = Object.assign({}, ...overrides);\n\n return getObjectKeys(defaultFormatKeysPerCategory).reduce((result, key) => {\n const value = defaultFormatKeysPerCategory[key]\n .map(\n formatKey =>\n (combinedOverrides[formatKey] === undefined\n ? defaultFormatParsers[formatKey]\n : combinedOverrides[formatKey]) as FormatParser<any>\n )\n .concat(\n ...additionalParsersArray.map(\n parsers => (parsers?.[key] ?? []) as FormatParser<any>[]\n )\n );\n\n result[key] = value;\n\n return result;\n }, {} as FormatParsersPerCategory);\n}\n"]}
1
+ {"version":3,"file":"createDomToModelContext.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext.ts"],"names":[],"mappings":";;;;AAAA,yDAA0D;AAC1D,8DAA6D;AAC7D,oFAGoD;AAgBpD;;;;GAIG;AACH,SAAgB,uBAAuB,CACnC,aAA6B;IAC7B,iBAA4C;SAA5C,UAA4C,EAA5C,qBAA4C,EAA5C,IAA4C;QAA5C,gCAA4C;;IAE5C,OAAO,iCAAiC,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC;AAC7F,CAAC;AALD,0DAKC;AAED;;;;GAIG;AACH,SAAgB,iCAAiC,CAC7C,MAA0B,EAC1B,aAA6B;IAE7B,OAAO,MAAM,C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MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAClD;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC;AArCD,gDAqCC","sourcesContent":["import { defaultProcessorMap } from './defaultProcessors';\nimport { getObjectKeys } from '../../domUtils/getObjectKeys';\nimport {\n defaultFormatKeysPerCategory,\n defaultFormatParsers,\n} from '../../formatHandlers/defaultFormatHandlers';\nimport type {\n ContentModelBlockFormat,\n DomToModelContext,\n DomToModelDecoratorContext,\n DomToModelFormatContext,\n DomToModelOption,\n DomToModelSelectionContext,\n DomToModelSettings,\n EditorContext,\n FormatParser,\n FormatParsers,\n FormatParsersPerCategory,\n TextFormatParser,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create context object for DOM to Content Model conversion\n * @param editorContext Context of editor\n * @param options Option array to customize the DOM to Model conversion behavior\n */\nexport function createDomToModelContext(\n editorContext?: EditorContext,\n ...options: (DomToModelOption | undefined)[]\n): DomToModelContext {\n return createDomToModelContextWithConfig(createDomToModelConfig(options), editorContext);\n}\n\n/**\n * Create context object for DOM to Content Model conversion with an existing configure\n * @param config A full config object to define how to convert DOM tree to Content Model\n * @param editorContext Context of editor\n */\nexport function createDomToModelContextWithConfig(\n config: DomToModelSettings,\n editorContext?: EditorContext\n) {\n return Object.assign(\n {},\n editorContext,\n createDomToModelSelectionContext(),\n createDomToModelFormatContext(editorContext?.isRootRtl),\n createDomToModelDecoratorContext(),\n config\n );\n}\n\nfunction createDomToModelSelectionContext(): DomToModelSelectionContext {\n return { isInSelection: false };\n}\n\nfunction createDomToModelFormatContext(isRootRtl?: boolean): DomToModelFormatContext {\n const blockFormat: ContentModelBlockFormat = isRootRtl ? { direction: 'rtl' } : {};\n\n return {\n blockFormat,\n segmentFormat: {},\n\n listFormat: {\n levels: [],\n threadItemCounts: [],\n },\n };\n}\n\nfunction createDomToModelDecoratorContext(): DomToModelDecoratorContext {\n return {\n link: {\n format: {},\n dataset: {},\n },\n code: {\n format: {},\n },\n blockDecorator: {\n format: {},\n tagName: '',\n },\n };\n}\n\n/**\n * Create Dom to Content Model Config object\n * @param options All customizations of content model creation\n */\nexport function createDomToModelConfig(\n options: (DomToModelOption | undefined)[]\n): DomToModelSettings {\n return {\n elementProcessors: Object.assign(\n {},\n defaultProcessorMap,\n ...options.map(x => x?.processorOverride)\n ),\n formatParsers: buildFormatParsers(\n options.map(x => x?.formatParserOverride),\n options.map(x => x?.additionalFormatParsers)\n ),\n defaultElementProcessors: defaultProcessorMap,\n defaultFormatParsers,\n };\n}\n\n/**\n * @internal Export for test only\n * Build format parsers used by DOM to Content Model conversion\n * @param override\n * @param additionalParsersArray\n * @returns\n */\nexport function buildFormatParsers(\n overrides: (Partial<FormatParsers> | undefined)[] = [],\n additionalParsersArray: (Partial<FormatParsersPerCategory> | undefined)[] = []\n): FormatParsersPerCategory {\n const combinedOverrides = Object.assign({}, ...overrides);\n\n const result = getObjectKeys(defaultFormatKeysPerCategory).reduce(\n (result, key) => {\n const value = defaultFormatKeysPerCategory[key]\n .map(\n formatKey =>\n (combinedOverrides[formatKey] === undefined\n ? defaultFormatParsers[formatKey]\n : combinedOverrides[formatKey]) as FormatParser<any>\n )\n .concat(\n ...additionalParsersArray.map(\n parsers => (parsers?.[key] ?? []) as FormatParser<any>[]\n )\n );\n\n result[key] = value;\n\n return result;\n },\n {\n text: [] as TextFormatParser[],\n } as FormatParsersPerCategory\n );\n\n additionalParsersArray.forEach(parsers => {\n if (parsers?.text) {\n result.text = result.text.concat(parsers.text);\n }\n });\n\n return result;\n}\n"]}
@@ -21,5 +21,6 @@ export declare function processChildNode(group: ContentModelBlockGroup, child: N
21
21
  * @param group The parent block group
22
22
  * @param nodeStartOffset Start offset of current regular selection
23
23
  * @param nodeEndOffset End offset of current regular selection
24
+ * @param container The container node of this selection
24
25
  */
25
- export declare function handleRegularSelection(index: number, context: DomToModelContext, group: ContentModelBlockGroup, nodeStartOffset: number, nodeEndOffset: number): void;
26
+ export declare function handleRegularSelection(index: number, context: DomToModelContext, group: ContentModelBlockGroup, nodeStartOffset: number, nodeEndOffset: number, container?: Node): void;
@@ -15,11 +15,11 @@ var childProcessor = function (group, parent, context) {
15
15
  var _a = (0, tslib_1.__read)((0, getRegularSelectionOffsets_1.getRegularSelectionOffsets)(context, parent), 2), nodeStartOffset = _a[0], nodeEndOffset = _a[1];
16
16
  var index = 0;
17
17
  for (var child = parent.firstChild; child; child = child.nextSibling) {
18
- handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);
18
+ handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset, parent);
19
19
  processChildNode(group, child, context);
20
20
  index++;
21
21
  }
22
- handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);
22
+ handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset, parent);
23
23
  };
24
24
  exports.childProcessor = childProcessor;
25
25
  /**
@@ -45,16 +45,17 @@ exports.processChildNode = processChildNode;
45
45
  * @param group The parent block group
46
46
  * @param nodeStartOffset Start offset of current regular selection
47
47
  * @param nodeEndOffset End offset of current regular selection
48
+ * @param container The container node of this selection
48
49
  */
49
- function handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset) {
50
+ function handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset, container) {
50
51
  var _a;
51
52
  if (index == nodeStartOffset) {
52
53
  context.isInSelection = true;
53
- (0, addSelectionMarker_1.addSelectionMarker)(group, context);
54
+ (0, addSelectionMarker_1.addSelectionMarker)(group, context, container, index);
54
55
  }
55
56
  if (index == nodeEndOffset && ((_a = context.selection) === null || _a === void 0 ? void 0 : _a.type) == 'range') {
56
57
  if (!context.selection.range.collapsed) {
57
- (0, addSelectionMarker_1.addSelectionMarker)(group, context);
58
+ (0, addSelectionMarker_1.addSelectionMarker)(group, context, container, index);
58
59
  }
59
60
  context.isInSelection = false;
60
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"childProcessor.js","sourceRoot":"","sources":["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4CAUC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAClC,KAAa,EACb,OAA0B,EAC1B,KAA6B,EAC7B,eAAuB,EACvB,aAAqB;;IAErB,IAAI,KAAK,IAAI,eAAe,EAAE;QAC1B,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;QAE7B,IAAA,uCAAkB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KACtC;IAED,IAAI,KAAK,IAAI,aAAa,IAAI,CAAA,MAAA,OAAO,CAAC,SAAS,0CAAE,IAAI,KAAI,OAAO,EAAE;QAC9D,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE;YACpC,IAAA,uCAAkB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SACtC;QACD,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC;KACjC;AACL,CAAC;AAnBD,wDAmBC","sourcesContent":["import { addSelectionMarker } from '../utils/addSelectionMarker';\nimport { getRegularSelectionOffsets } from '../utils/getRegularSelectionOffsets';\nimport { isNodeOfType } from '../../domUtils/isNodeOfType';\nimport type {\n ContentModelBlockGroup,\n DomToModelContext,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for child elements\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n */\nexport const childProcessor: ElementProcessor<ParentNode> = (\n group: ContentModelBlockGroup,\n parent: ParentNode,\n context: DomToModelContext\n) => {\n const [nodeStartOffset, nodeEndOffset] = getRegularSelectionOffsets(context, parent);\n let index = 0;\n\n for (let child = parent.firstChild; child; child = child.nextSibling) {\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);\n\n processChildNode(group, child, context);\n\n index++;\n }\n\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);\n};\n\n/**\n * Helper function for processing child node\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n *\n */\nexport function processChildNode(\n group: ContentModelBlockGroup,\n child: Node,\n context: DomToModelContext\n) {\n if (isNodeOfType(child, 'ELEMENT_NODE') && child.style.display != 'none') {\n context.elementProcessors.element(group, child, context);\n } else if (isNodeOfType(child, 'TEXT_NODE')) {\n context.elementProcessors['#text'](group, child, context);\n }\n}\n\n/**\n * Helper function to handle regular (range based) selection when process child node\n * @param index Index of current child node in its parent\n * @param context DOM to Content Model context\n * @param group The parent block group\n * @param nodeStartOffset Start offset of current regular selection\n * @param nodeEndOffset End offset of current regular selection\n */\nexport function handleRegularSelection(\n index: number,\n context: DomToModelContext,\n group: ContentModelBlockGroup,\n nodeStartOffset: number,\n nodeEndOffset: number\n) {\n if (index == nodeStartOffset) {\n context.isInSelection = true;\n\n addSelectionMarker(group, context);\n }\n\n if (index == nodeEndOffset && context.selection?.type == 'range') {\n if (!context.selection.range.collapsed) {\n addSelectionMarker(group, context);\n }\n context.isInSelection = false;\n }\n}\n"]}
1
+ {"version":3,"file":"childProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/childProcessor.ts"],"names":[],"mappings":";;;;AAAA,kEAAiE;AACjE,kFAAiF;AACjF,4DAA2D;AAO3D;;;;;GAKG;AACI,IAAM,cAAc,GAAiC,UACxD,KAA6B,EAC7B,MAAkB,EAClB,OAA0B;IAEpB,IAAA,KAAA,oBAAmC,IAAA,uDAA0B,EAAC,OAAO,EAAE,MAAM,CAAC,IAAA,EAA7E,eAAe,QAAA,EAAE,aAAa,QAA+C,CAAC;IACrF,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE;QAClE,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;QAEtF,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,C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;AACL,CAAC;AApBD,wDAoBC","sourcesContent":["import { addSelectionMarker } from '../utils/addSelectionMarker';\nimport { getRegularSelectionOffsets } from '../utils/getRegularSelectionOffsets';\nimport { isNodeOfType } from '../../domUtils/isNodeOfType';\nimport type {\n ContentModelBlockGroup,\n DomToModelContext,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for child elements\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n */\nexport const childProcessor: ElementProcessor<ParentNode> = (\n group: ContentModelBlockGroup,\n parent: ParentNode,\n context: DomToModelContext\n) => {\n const [nodeStartOffset, nodeEndOffset] = getRegularSelectionOffsets(context, parent);\n let index = 0;\n\n for (let child = parent.firstChild; child; child = child.nextSibling) {\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset, parent);\n\n processChildNode(group, child, context);\n\n index++;\n }\n\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset, parent);\n};\n\n/**\n * Helper function for processing child node\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n *\n */\nexport function processChildNode(\n group: ContentModelBlockGroup,\n child: Node,\n context: DomToModelContext\n) {\n if (isNodeOfType(child, 'ELEMENT_NODE') && child.style.display != 'none') {\n context.elementProcessors.element(group, child, context);\n } else if (isNodeOfType(child, 'TEXT_NODE')) {\n context.elementProcessors['#text'](group, child, context);\n }\n}\n\n/**\n * Helper function to handle regular (range based) selection when process child node\n * @param index Index of current child node in its parent\n * @param context DOM to Content Model context\n * @param group The parent block group\n * @param nodeStartOffset Start offset of current regular selection\n * @param nodeEndOffset End offset of current regular selection\n * @param container The container node of this selection\n */\nexport function handleRegularSelection(\n index: number,\n context: DomToModelContext,\n group: ContentModelBlockGroup,\n nodeStartOffset: number,\n nodeEndOffset: number,\n container?: Node\n) {\n if (index == nodeStartOffset) {\n context.isInSelection = true;\n\n addSelectionMarker(group, context, container, index);\n }\n\n if (index == nodeEndOffset && context.selection?.type == 'range') {\n if (!context.selection.range.collapsed) {\n addSelectionMarker(group, context, container, index);\n }\n context.isInSelection = false;\n }\n}\n"]}
@@ -9,6 +9,7 @@ var getBoundingClientRect_1 = require("../utils/getBoundingClientRect");
9
9
  var isElementOfType_1 = require("../../domUtils/isElementOfType");
10
10
  var isNodeOfType_1 = require("../../domUtils/isNodeOfType");
11
11
  var parseFormat_1 = require("../utils/parseFormat");
12
+ var parseValueWithUnit_1 = require("../../formatHandlers/utils/parseValueWithUnit");
12
13
  var stackFormat_1 = require("../utils/stackFormat");
13
14
  /**
14
15
  * Content Model Element Processor for table
@@ -45,6 +46,7 @@ var tableProcessor = function (group, tableElement, context) {
45
46
  (0, parseFormat_1.parseFormat)(tableElement, context.formatParsers.dataset, table.dataset, context);
46
47
  (0, addBlock_1.addBlock)(group, table);
47
48
  var columnPositions = [0];
49
+ var hasColGroup = processColGroup(tableElement, context, columnPositions);
48
50
  var rowPositions = [0];
49
51
  var zoomScale = context.zoomScale || 1;
50
52
  var _loop_1 = function (row) {
@@ -84,8 +86,9 @@ var tableProcessor = function (group, tableElement, context) {
84
86
  var rect = (0, getBoundingClientRect_1.getBoundingClientRect)(td);
85
87
  if (rect.width > 0 || rect.height > 0) {
86
88
  if (needCalcWidth) {
89
+ var pos = columnPositions[targetCol];
87
90
  columnPositions[colEnd] =
88
- columnPositions[targetCol] + rect.width / zoomScale;
91
+ (typeof pos == 'number' ? pos : 0) + rect.width / zoomScale;
89
92
  }
90
93
  if (needCalcHeight) {
91
94
  rowPositions[rowEnd] =
@@ -111,7 +114,9 @@ var tableProcessor = function (group, tableElement, context) {
111
114
  spannedRow.cells[targetCol] = cell;
112
115
  }
113
116
  if (hasTd) {
114
- if (context.allowCacheElement) {
117
+ // When there is COLGROUP, width on table cell should be ignored, so we should not cache the table cell,
118
+ // and always recreate it when write back using the table formats
119
+ if (context.allowCacheElement && !hasColGroup) {
115
120
  cell.cachedElement = td;
116
121
  }
117
122
  var _a = context.listFormat, listParent = _a.listParent, levels = _a.levels;
@@ -167,16 +172,51 @@ var tableProcessor = function (group, tableElement, context) {
167
172
  exports.tableProcessor = tableProcessor;
168
173
  function calcSizes(positions) {
169
174
  var result = [];
170
- var lastPos = positions[positions.length - 1];
175
+ var lastPos = 0;
176
+ for (var i = positions.length - 1; i >= 0; i--) {
177
+ var pos = positions[i];
178
+ if (typeof pos == 'number') {
179
+ lastPos = pos;
180
+ break;
181
+ }
182
+ }
171
183
  for (var i = positions.length - 2; i >= 0; i--) {
172
- if (positions[i] === undefined) {
184
+ var pos = positions[i];
185
+ if (pos === undefined) {
173
186
  result[i] = 0;
174
187
  }
175
188
  else {
176
- result[i] = lastPos - positions[i];
177
- lastPos = positions[i];
189
+ result[i] = lastPos - pos;
190
+ lastPos = pos;
178
191
  }
179
192
  }
180
193
  return result;
181
194
  }
195
+ function processColGroup(table, context, result) {
196
+ var _a, _b;
197
+ var lastPos = 0;
198
+ var hasColGroup = false;
199
+ for (var child = table.firstChild; child; child = child.nextSibling) {
200
+ if ((0, isNodeOfType_1.isNodeOfType)(child, 'ELEMENT_NODE') && child.tagName == 'COLGROUP') {
201
+ hasColGroup = true;
202
+ for (var col = child.firstChild; col; col = col.nextSibling) {
203
+ if ((0, isNodeOfType_1.isNodeOfType)(col, 'ELEMENT_NODE') && col.tagName == 'COL') {
204
+ var colFormat = {};
205
+ (0, parseFormat_1.parseFormat)(col, context.formatParsers.tableColumn, colFormat, context);
206
+ for (var i = 0; i < parseInt((_a = col.getAttribute('span')) !== null && _a !== void 0 ? _a : '1'); i++) {
207
+ if (colFormat.width === undefined) {
208
+ result.push(undefined);
209
+ }
210
+ else {
211
+ var width = (0, parseValueWithUnit_1.parseValueWithUnit)((_b = colFormat.width) !== null && _b !== void 0 ? _b : '', undefined /*element*/, 'px');
212
+ result.push(width + lastPos);
213
+ lastPos += width;
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+ return hasColGroup;
221
+ }
182
222
  //# sourceMappingURL=tableProcessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tableProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/tableProcessor.ts"],"names":[],"mappings":";;;;AAAA,2DAA0D;AAC1D,mEAAkE;AAClE,2EAA0E;AAC1E,wEAAuE;AACvE,kEAAiE;AACjE,4DAA2D;AAC3D,oDAAmD;AACnD,oDAAmD;AAOnD;;;;;;;;;;;;;;;;GAgBG;AACI,IAAM,cAAc,GAAuC,UAC9D,KAAK,EACL,YAAY,EACZ,OAAO;IAEP,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,sBAAsB,EAAE,EACtE;;QACI,IAAA,yBAAW,EAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAErF,IAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,IAAM,cAAc,GAAG,CAAA,MAAA,OAAO,CAAC,SAAS,0CAAE,IAAI,KAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;QACrF,IAAM,aAAa,GAAG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK,CAAC;QAC5C,IAAM,iBAAiB,GAAG,aAAa,IAAI,YAAY,CAAC;QAExD,IAAI,OAAO,CAAC,iBAAiB,EAAE;YAC3B,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC;SACtC;QAED,MAAA,OAAO,CAAC,UAAU,0CAAE,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAEjD,IAAA,yBAAW,EAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9E,IA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,CAAC,CAAC;QAExC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAC,GAAG,EAAE,CAAC;YACtB,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;gBAChB,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;aAC3B;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CACJ,CAAC;AACN,CAAC,CAAC;AA5OW,QAAA,cAAc,kBA4OzB;AAEF,SAAS,SAAS,CAAC,SAAmB;IAClC,IAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE9C,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC5C,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;YAC5B,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;SACjB;aAAM;YACH,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACnC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;SAC1B;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { createTable } from '../../modelApi/creators/createTable';\nimport { createTableCell } from '../../modelApi/creators/createTableCell';\nimport { getBoundingClientRect } from '../utils/getBoundingClientRect';\nimport { isElementOfType } from '../../domUtils/isElementOfType';\nimport { isNodeOfType } from '../../domUtils/isNodeOfType';\nimport { parseFormat } from '../utils/parseFormat';\nimport { stackFormat } from '../utils/stackFormat';\nimport type {\n ContentModelTableCellFormat,\n DatasetFormat,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for table\n *\n * For Table with merged/splitted cells, HTML uses colSpan and rowSpan attributes to specify how it should be rendered.\n * To make it easier to edit a table, we will use a different way to describe table.\n *\n * 1. For a m * n table (m rows, n columns), we always create a m * n array for the cells.\n * 2. For a regular table cell, it is mapped to one item of this array\n * 3. For a merged/splitted table cell, it will has colSpan/rowSpan value. We also created TableCell model for those spanned\n * cells, and use \"spanLeft\" and \"spanAbove\" to mark its state\n * 4. When edit table, we always edit on this mapped m * n array because it always has an item for each cell\n * 5. When write back to DOM, we create TD/TH elements for those non-spanned cells, and mark its colSpan/rowSpan value according\n * its neighbour cell's spanLeft/spanAbove attribute\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n */\nexport const tableProcessor: ElementProcessor<HTMLTableElement> = (\n group,\n tableElement,\n context\n) => {\n stackFormat(\n context,\n { segment: 'shallowCloneForBlock', paragraph: 'shallowCloneForGroup' },\n () => {\n parseFormat(tableElement, context.formatParsers.block, context.blockFormat, context);\n\n const table = createTable(tableElement.rows.length, context.blockFormat);\n const tableSelection = context.selection?.type == 'table' ? context.selection : null;\n const selectedTable = tableSelection?.table;\n const hasTableSelection = selectedTable == tableElement;\n\n if (context.allowCacheElement) {\n table.cachedElement = tableElement;\n }\n\n context.domIndexer?.onTable(tableElement, table);\n\n parseFormat(tableElement, context.formatParsers.table, table.format, context);\n parseFormat(tableElement, context.formatParsers.tableBorder, table.format, context);\n parseFormat(\n tableElement,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n parseFormat(tableElement, context.formatParsers.dataset, table.dataset, context);\n addBlock(group, table);\n\n const columnPositions: number[] = [0];\n const rowPositions: number[] = [0];\n const zoomScale = context.zoomScale || 1;\n\n for (let row = 0; row < tableElement.rows.length; row++) {\n const tr = tableElement.rows[row];\n const tableRow = table.rows[row];\n\n const tbody = tr.parentNode;\n\n if (\n isNodeOfType(tbody, 'ELEMENT_NODE') &&\n (isElementOfType(tbody, 'tbody') ||\n isElementOfType(tbody, 'thead') ||\n isElementOfType(tbody, 'tfoot'))\n ) {\n parseFormat(tbody, context.formatParsers.tableRow, tableRow.format, context);\n } else if (context.allowCacheElement) {\n tableRow.cachedElement = tr;\n }\n\n parseFormat(tr, context.formatParsers.tableRow, tableRow.format, context);\n\n stackFormat(context, { paragraph: 'shallowClone', segment: 'shallowClone' }, () => {\n const parent = tr.parentElement;\n const parentTag = parent?.tagName;\n\n if (\n parent &&\n (parentTag == 'TBODY' || parentTag == 'THEAD' || parentTag == 'TFOOT')\n ) {\n // If there is TBODY around TR, retrieve format from TBODY first, in case some format are declared there\n parseFormat(\n parent,\n context.formatParsers.block,\n context.blockFormat,\n context\n );\n parseFormat(\n parent,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n }\n\n parseFormat(tr, context.formatParsers.block, context.blockFormat, context);\n parseFormat(\n tr,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n\n for (\n let sourceCol = 0, targetCol = 0;\n sourceCol < tr.cells.length;\n sourceCol++\n ) {\n for (; tableRow.cells[targetCol]; targetCol++) {}\n\n const td = tr.cells[sourceCol];\n const hasSelectionBeforeCell = context.isInSelection;\n const colEnd = targetCol + td.colSpan;\n const rowEnd = row + td.rowSpan;\n const needCalcWidth = columnPositions[colEnd] === undefined;\n const needCalcHeight = rowPositions[rowEnd] === undefined;\n\n if (needCalcWidth || needCalcHeight) {\n const rect = getBoundingClientRect(td);\n\n if (rect.width > 0 || rect.height > 0) {\n if (needCalcWidth) {\n columnPositions[colEnd] =\n columnPositions[targetCol] + rect.width / zoomScale;\n }\n\n if (needCalcHeight) {\n rowPositions[rowEnd] =\n rowPositions[row] + rect.height / zoomScale;\n }\n }\n }\n\n stackFormat(\n context,\n { paragraph: 'shallowClone', segment: 'shallowClone' },\n () => {\n parseFormat(\n td,\n context.formatParsers.block,\n context.blockFormat,\n context\n );\n parseFormat(\n td,\n context.formatParsers.segmentOnTableCell,\n context.segmentFormat,\n context\n );\n\n const cellFormat: ContentModelTableCellFormat = {\n ...context.blockFormat,\n };\n const dataset: DatasetFormat = {};\n\n parseFormat(\n td,\n context.formatParsers.tableCell,\n cellFormat,\n context\n );\n parseFormat(\n td,\n context.formatParsers.tableBorder,\n cellFormat,\n context\n );\n parseFormat(td, context.formatParsers.dataset, dataset, context);\n\n for (\n let colSpan = 1;\n colSpan <= td.colSpan;\n colSpan++, targetCol++\n ) {\n for (let rowSpan = 1; rowSpan <= td.rowSpan; rowSpan++) {\n const hasTd = colSpan == 1 && rowSpan == 1;\n const cell = createTableCell(\n colSpan > 1,\n rowSpan > 1,\n td.tagName == 'TH',\n cellFormat\n );\n\n cell.dataset = { ...dataset };\n\n const spannedRow = table.rows[row + rowSpan - 1];\n\n if (spannedRow) {\n spannedRow.cells[targetCol] = cell;\n }\n\n if (hasTd) {\n if (context.allowCacheElement) {\n cell.cachedElement = td;\n }\n\n const { listParent, levels } = context.listFormat;\n\n context.listFormat.listParent = undefined;\n context.listFormat.levels = [];\n\n try {\n context.elementProcessors.child(cell, td, context);\n } finally {\n context.listFormat.listParent = listParent;\n context.listFormat.levels = levels;\n }\n }\n\n const hasSelectionAfterCell = context.isInSelection;\n\n if (\n (hasSelectionBeforeCell && hasSelectionAfterCell) ||\n (hasTableSelection &&\n tableSelection &&\n row >= tableSelection.firstRow &&\n row <= tableSelection.lastRow &&\n targetCol >= tableSelection.firstColumn &&\n targetCol <= tableSelection.lastColumn)\n ) {\n cell.isSelected = true;\n }\n }\n }\n }\n );\n }\n });\n\n for (let col = 0; col < tableRow.cells.length; col++) {\n if (!tableRow.cells[col]) {\n tableRow.cells[col] = createTableCell(\n false,\n false,\n false,\n context.blockFormat\n );\n }\n }\n }\n\n table.widths = calcSizes(columnPositions);\n\n const heights = calcSizes(rowPositions);\n\n table.rows.forEach((row, i) => {\n if (heights[i] > 0) {\n row.height = heights[i];\n }\n });\n }\n );\n};\n\nfunction calcSizes(positions: number[]): number[] {\n const result: number[] = [];\n let lastPos = positions[positions.length - 1];\n\n for (let i = positions.length - 2; i >= 0; i--) {\n if (positions[i] === undefined) {\n result[i] = 0;\n } else {\n result[i] = lastPos - positions[i];\n lastPos = positions[i];\n }\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"tableProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/tableProcessor.ts"],"names":[],"mappings":";;;;AAAA,2DAA0D;AAC1D,mEAAkE;AAClE,2EAA0E;AAC1E,wEAAuE;AACvE,kEAAiE;AACjE,4DAA2D;AAC3D,oDAAmD;AACnD,oFAAmF;AACnF,oDAAmD;AASnD;;;;;;;;;;;;;;;;GAgBG;AACI,IAAM,cAAc,GAAuC,UAC9D,KAAK,EACL,YAAY,EACZ,OAAO;IAEP,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,sBAAsB,EAAE,EACtE;;QACI,IAAA,yBAAW,EAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAErF,IAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,IAAM,cAAc,GAAG,CAAA,MAAA,OAAO,CAAC,SAAS,0CAAE,IAAI,KAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;QACrF,IAAM,aAAa,GAAG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK,CAAC;QAC5C,IAAM,iBAAiB,GAAG,aAAa,IAAI,YAAY,CAAC;QAExD,IAAI,OAAO,CAAC,iBAAiB,EAAE;YAC3B,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC;SACtC;QAED,MAAA,OAAO,CAAC,UAAU,0CAAE,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAEjD,IAAA,yBAAW,EAAC,YAAY,EAA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,CAAC,WAAW,EACrB,IAAI,CACP,CAAC;4BAEF,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC;4BAC7B,OAAO,IAAI,KAAK,CAAC;yBACpB;qBACJ;iBACJ;aACJ;SACJ;KACJ;IAED,OAAO,WAAW,CAAC;AACvB,CAAC","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { createTable } from '../../modelApi/creators/createTable';\nimport { createTableCell } from '../../modelApi/creators/createTableCell';\nimport { getBoundingClientRect } from '../utils/getBoundingClientRect';\nimport { isElementOfType } from '../../domUtils/isElementOfType';\nimport { isNodeOfType } from '../../domUtils/isNodeOfType';\nimport { parseFormat } from '../utils/parseFormat';\nimport { parseValueWithUnit } from '../../formatHandlers/utils/parseValueWithUnit';\nimport { stackFormat } from '../utils/stackFormat';\nimport type {\n ContentModelTableCellFormat,\n DatasetFormat,\n DomToModelContext,\n ElementProcessor,\n SizeFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for table\n *\n * For Table with merged/splitted cells, HTML uses colSpan and rowSpan attributes to specify how it should be rendered.\n * To make it easier to edit a table, we will use a different way to describe table.\n *\n * 1. For a m * n table (m rows, n columns), we always create a m * n array for the cells.\n * 2. For a regular table cell, it is mapped to one item of this array\n * 3. For a merged/splitted table cell, it will has colSpan/rowSpan value. We also created TableCell model for those spanned\n * cells, and use \"spanLeft\" and \"spanAbove\" to mark its state\n * 4. When edit table, we always edit on this mapped m * n array because it always has an item for each cell\n * 5. When write back to DOM, we create TD/TH elements for those non-spanned cells, and mark its colSpan/rowSpan value according\n * its neighbour cell's spanLeft/spanAbove attribute\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n */\nexport const tableProcessor: ElementProcessor<HTMLTableElement> = (\n group,\n tableElement,\n context\n) => {\n stackFormat(\n context,\n { segment: 'shallowCloneForBlock', paragraph: 'shallowCloneForGroup' },\n () => {\n parseFormat(tableElement, context.formatParsers.block, context.blockFormat, context);\n\n const table = createTable(tableElement.rows.length, context.blockFormat);\n const tableSelection = context.selection?.type == 'table' ? context.selection : null;\n const selectedTable = tableSelection?.table;\n const hasTableSelection = selectedTable == tableElement;\n\n if (context.allowCacheElement) {\n table.cachedElement = tableElement;\n }\n\n context.domIndexer?.onTable(tableElement, table);\n\n parseFormat(tableElement, context.formatParsers.table, table.format, context);\n parseFormat(tableElement, context.formatParsers.tableBorder, table.format, context);\n parseFormat(\n tableElement,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n parseFormat(tableElement, context.formatParsers.dataset, table.dataset, context);\n addBlock(group, table);\n\n const columnPositions: (number | undefined)[] = [0];\n const hasColGroup = processColGroup(tableElement, context, columnPositions);\n const rowPositions: number[] = [0];\n const zoomScale = context.zoomScale || 1;\n\n for (let row = 0; row < tableElement.rows.length; row++) {\n const tr = tableElement.rows[row];\n const tableRow = table.rows[row];\n\n const tbody = tr.parentNode;\n\n if (\n isNodeOfType(tbody, 'ELEMENT_NODE') &&\n (isElementOfType(tbody, 'tbody') ||\n isElementOfType(tbody, 'thead') ||\n isElementOfType(tbody, 'tfoot'))\n ) {\n parseFormat(tbody, context.formatParsers.tableRow, tableRow.format, context);\n } else if (context.allowCacheElement) {\n tableRow.cachedElement = tr;\n }\n\n parseFormat(tr, context.formatParsers.tableRow, tableRow.format, context);\n\n stackFormat(context, { paragraph: 'shallowClone', segment: 'shallowClone' }, () => {\n const parent = tr.parentElement;\n const parentTag = parent?.tagName;\n\n if (\n parent &&\n (parentTag == 'TBODY' || parentTag == 'THEAD' || parentTag == 'TFOOT')\n ) {\n // If there is TBODY around TR, retrieve format from TBODY first, in case some format are declared there\n parseFormat(\n parent,\n context.formatParsers.block,\n context.blockFormat,\n context\n );\n parseFormat(\n parent,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n }\n\n parseFormat(tr, context.formatParsers.block, context.blockFormat, context);\n parseFormat(\n tr,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n\n for (\n let sourceCol = 0, targetCol = 0;\n sourceCol < tr.cells.length;\n sourceCol++\n ) {\n for (; tableRow.cells[targetCol]; targetCol++) {}\n\n const td = tr.cells[sourceCol];\n const hasSelectionBeforeCell = context.isInSelection;\n const colEnd = targetCol + td.colSpan;\n const rowEnd = row + td.rowSpan;\n const needCalcWidth = columnPositions[colEnd] === undefined;\n const needCalcHeight = rowPositions[rowEnd] === undefined;\n\n if (needCalcWidth || needCalcHeight) {\n const rect = getBoundingClientRect(td);\n\n if (rect.width > 0 || rect.height > 0) {\n if (needCalcWidth) {\n const pos = columnPositions[targetCol];\n\n columnPositions[colEnd] =\n (typeof pos == 'number' ? pos : 0) + rect.width / zoomScale;\n }\n\n if (needCalcHeight) {\n rowPositions[rowEnd] =\n rowPositions[row] + rect.height / zoomScale;\n }\n }\n }\n\n stackFormat(\n context,\n { paragraph: 'shallowClone', segment: 'shallowClone' },\n () => {\n parseFormat(\n td,\n context.formatParsers.block,\n context.blockFormat,\n context\n );\n parseFormat(\n td,\n context.formatParsers.segmentOnTableCell,\n context.segmentFormat,\n context\n );\n\n const cellFormat: ContentModelTableCellFormat = {\n ...context.blockFormat,\n };\n const dataset: DatasetFormat = {};\n\n parseFormat(\n td,\n context.formatParsers.tableCell,\n cellFormat,\n context\n );\n parseFormat(\n td,\n context.formatParsers.tableBorder,\n cellFormat,\n context\n );\n parseFormat(td, context.formatParsers.dataset, dataset, context);\n\n for (\n let colSpan = 1;\n colSpan <= td.colSpan;\n colSpan++, targetCol++\n ) {\n for (let rowSpan = 1; rowSpan <= td.rowSpan; rowSpan++) {\n const hasTd = colSpan == 1 && rowSpan == 1;\n const cell = createTableCell(\n colSpan > 1,\n rowSpan > 1,\n td.tagName == 'TH',\n cellFormat\n );\n\n cell.dataset = { ...dataset };\n\n const spannedRow = table.rows[row + rowSpan - 1];\n\n if (spannedRow) {\n spannedRow.cells[targetCol] = cell;\n }\n\n if (hasTd) {\n // When there is COLGROUP, width on table cell should be ignored, so we should not cache the table cell,\n // and always recreate it when write back using the table formats\n if (context.allowCacheElement && !hasColGroup) {\n cell.cachedElement = td;\n }\n\n const { listParent, levels } = context.listFormat;\n\n context.listFormat.listParent = undefined;\n context.listFormat.levels = [];\n\n try {\n context.elementProcessors.child(cell, td, context);\n } finally {\n context.listFormat.listParent = listParent;\n context.listFormat.levels = levels;\n }\n }\n\n const hasSelectionAfterCell = context.isInSelection;\n\n if (\n (hasSelectionBeforeCell && hasSelectionAfterCell) ||\n (hasTableSelection &&\n tableSelection &&\n row >= tableSelection.firstRow &&\n row <= tableSelection.lastRow &&\n targetCol >= tableSelection.firstColumn &&\n targetCol <= tableSelection.lastColumn)\n ) {\n cell.isSelected = true;\n }\n }\n }\n }\n );\n }\n });\n\n for (let col = 0; col < tableRow.cells.length; col++) {\n if (!tableRow.cells[col]) {\n tableRow.cells[col] = createTableCell(\n false,\n false,\n false,\n context.blockFormat\n );\n }\n }\n }\n\n table.widths = calcSizes(columnPositions);\n\n const heights = calcSizes(rowPositions);\n\n table.rows.forEach((row, i) => {\n if (heights[i] > 0) {\n row.height = heights[i];\n }\n });\n }\n );\n};\n\nfunction calcSizes(positions: (number | undefined)[]): number[] {\n const result: number[] = [];\n let lastPos = 0;\n\n for (let i = positions.length - 1; i >= 0; i--) {\n const pos = positions[i];\n\n if (typeof pos == 'number') {\n lastPos = pos;\n break;\n }\n }\n\n for (let i = positions.length - 2; i >= 0; i--) {\n const pos = positions[i];\n if (pos === undefined) {\n result[i] = 0;\n } else {\n result[i] = lastPos - pos;\n lastPos = pos;\n }\n }\n\n return result;\n}\n\nfunction processColGroup(\n table: HTMLElement,\n context: DomToModelContext,\n result: (number | undefined)[]\n): boolean {\n let lastPos = 0;\n let hasColGroup = false;\n\n for (let child = table.firstChild; child; child = child.nextSibling) {\n if (isNodeOfType(child, 'ELEMENT_NODE') && child.tagName == 'COLGROUP') {\n hasColGroup = true;\n\n for (let col = child.firstChild; col; col = col.nextSibling) {\n if (isNodeOfType(col, 'ELEMENT_NODE') && col.tagName == 'COL') {\n const colFormat: SizeFormat = {};\n\n parseFormat(col, context.formatParsers.tableColumn, colFormat, context);\n\n for (let i = 0; i < parseInt(col.getAttribute('span') ?? '1'); i++) {\n if (colFormat.width === undefined) {\n result.push(undefined);\n } else {\n const width = parseValueWithUnit(\n colFormat.width ?? '',\n undefined /*element*/,\n 'px'\n );\n\n result.push(width + lastPos);\n lastPos += width;\n }\n }\n }\n }\n }\n }\n\n return hasColGroup;\n}\n"]}
@@ -9,10 +9,25 @@ var ensureParagraph_1 = require("../../modelApi/common/ensureParagraph");
9
9
  var getRegularSelectionOffsets_1 = require("../utils/getRegularSelectionOffsets");
10
10
  var hasSpacesOnly_1 = require("../../modelApi/common/hasSpacesOnly");
11
11
  var isWhiteSpacePreserved_1 = require("../../domUtils/isWhiteSpacePreserved");
12
+ var stackFormat_1 = require("../utils/stackFormat");
12
13
  /**
13
14
  * @internal
14
15
  */
15
16
  var textProcessor = function (group, textNode, context) {
17
+ if (context.formatParsers.text.length > 0) {
18
+ (0, stackFormat_1.stackFormat)(context, { segment: 'shallowClone' }, function () {
19
+ context.formatParsers.text.forEach(function (parser) {
20
+ parser(context.segmentFormat, textNode, context);
21
+ internalTextProcessor(group, textNode, context);
22
+ });
23
+ });
24
+ }
25
+ else {
26
+ internalTextProcessor(group, textNode, context);
27
+ }
28
+ };
29
+ exports.textProcessor = textProcessor;
30
+ function internalTextProcessor(group, textNode, context) {
16
31
  var _a;
17
32
  var txt = textNode.nodeValue || '';
18
33
  var offsets = (0, getRegularSelectionOffsets_1.getRegularSelectionOffsets)(context, textNode);
@@ -24,7 +39,7 @@ var textProcessor = function (group, textNode, context) {
24
39
  var subText = txt.substring(0, txtStartOffset);
25
40
  segments.push(addTextSegment(group, subText, paragraph, context));
26
41
  context.isInSelection = true;
27
- (0, addSelectionMarker_1.addSelectionMarker)(group, context);
42
+ (0, addSelectionMarker_1.addSelectionMarker)(group, context, textNode, txtStartOffset);
28
43
  txt = txt.substring(txtStartOffset);
29
44
  txtEndOffset -= txtStartOffset;
30
45
  }
@@ -33,15 +48,14 @@ var textProcessor = function (group, textNode, context) {
33
48
  segments.push(addTextSegment(group, subText, paragraph, context));
34
49
  if (context.selection &&
35
50
  (context.selection.type != 'range' || !context.selection.range.collapsed)) {
36
- (0, addSelectionMarker_1.addSelectionMarker)(group, context);
51
+ (0, addSelectionMarker_1.addSelectionMarker)(group, context, textNode, offsets[1]); // Must use offsets[1] here as the unchanged offset value, cannot use txtEndOffset since it has been modified
37
52
  }
38
53
  context.isInSelection = false;
39
54
  txt = txt.substring(txtEndOffset);
40
55
  }
41
56
  segments.push(addTextSegment(group, txt, paragraph, context));
42
57
  (_a = context.domIndexer) === null || _a === void 0 ? void 0 : _a.onSegment(textNode, paragraph, segments.filter(function (x) { return !!x; }));
43
- };
44
- exports.textProcessor = textProcessor;
58
+ }
45
59
  function addTextSegment(group, text, paragraph, context) {
46
60
  var _a;
47
61
  var textModel;
@@ -1 +1 @@
1
- {"version":3,"file":"textProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/textProcessor.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AACpE,+DAA8D;AAC9D,kEAAiE;AACjE,iEAAgE;AAChE,yEAAwE;AACxE,kFAAiF;AACjF,qEAAoE;AACpE,8EAA6E;AAS7E;;GAEG;AACI,IAAM,aAAa,GAA2B,UACjD,KAA6B,EAC7B,QAAc,EACd,OAA0B;;IAE1B,IAAI,GAAG,GAAG,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC;IACnC,IAAM,OAAO,GAAG,IAAA,uDAA0B,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC9D,IAAM,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAClC,IAAI,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAM,QAAQ,GAAqC,EAAE,CAAC;IACtD,IAAM,SAA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AAC,IAA4B,OAAA,CAAC,CAAC,CAAC,EAAH,CAAG,CAAC,CACrD,CAAC;AACN,CAAC,CAAC;AA5CW,QAAA,aAAa,iBA4CxB;AAEF,SAAS,cAAc,CACnB,KAA6B,EAC7B,IAAY,EACZ,SAAgC,EAChC,OAA0B;;IAE1B,IAAI,SAAuC,CAAC;IAE5C,IAAI,IAAI,EAAE;QACN,IACI,CAAC,IAAA,6BAAa,EAAC,IAAI,CAAC;YACpB,CAAC,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAC,MAAM,mCAAI,CAAC,CAAC,GAAG,CAAC;YACrC,IAAA,6CAAqB,EAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAC,UAAU,CAAC,EACrD;YACE,SAAS,GAAG,IAAA,uBAAU,EAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;YAEpD,IAAI,OAAO,CAAC,aAAa,EAAE;gBACvB,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC;aAC/B;YAED,IAAA,6BAAa,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAElC,IAAA,uBAAU,EAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;SACrD;KACJ;IAED,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["import { addDecorators } from '../../modelApi/common/addDecorators';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { addSelectionMarker } from '../utils/addSelectionMarker';\nimport { createText } from '../../modelApi/creators/createText';\nimport { ensureParagraph } from '../../modelApi/common/ensureParagraph';\nimport { getRegularSelectionOffsets } from '../utils/getRegularSelectionOffsets';\nimport { hasSpacesOnly } from '../../modelApi/common/hasSpacesOnly';\nimport { isWhiteSpacePreserved } from '../../domUtils/isWhiteSpacePreserved';\nimport type {\n ContentModelBlockGroup,\n ContentModelParagraph,\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 let txt = textNode.nodeValue || '';\n const offsets = getRegularSelectionOffsets(context, textNode);\n const txtStartOffset = offsets[0];\n let txtEndOffset = offsets[1];\n const segments: (ContentModelText | undefined)[] = [];\n const paragraph = ensureParagraph(group, context.blockFormat);\n\n if (txtStartOffset >= 0) {\n const subText = txt.substring(0, txtStartOffset);\n segments.push(addTextSegment(group, subText, paragraph, context));\n context.isInSelection = true;\n\n addSelectionMarker(group, context);\n\n txt = txt.substring(txtStartOffset);\n txtEndOffset -= txtStartOffset;\n }\n\n if (txtEndOffset >= 0) {\n const subText = txt.substring(0, txtEndOffset);\n segments.push(addTextSegment(group, subText, paragraph, context));\n\n if (\n context.selection &&\n (context.selection.type != 'range' || !context.selection.range.collapsed)\n ) {\n addSelectionMarker(group, context);\n }\n\n context.isInSelection = false;\n txt = txt.substring(txtEndOffset);\n }\n\n segments.push(addTextSegment(group, txt, paragraph, context));\n context.domIndexer?.onSegment(\n textNode,\n paragraph,\n segments.filter((x): x is ContentModelText => !!x)\n );\n};\n\nfunction addTextSegment(\n group: ContentModelBlockGroup,\n text: string,\n paragraph: ContentModelParagraph,\n context: DomToModelContext\n): ContentModelText | undefined {\n let textModel: ContentModelText | undefined;\n\n if (text) {\n if (\n !hasSpacesOnly(text) ||\n (paragraph?.segments.length ?? 0) > 0 ||\n isWhiteSpacePreserved(paragraph?.format.whiteSpace)\n ) {\n textModel = createText(text, context.segmentFormat);\n\n if (context.isInSelection) {\n textModel.isSelected = true;\n }\n\n addDecorators(textModel, context);\n\n addSegment(group, textModel, context.blockFormat);\n }\n }\n\n return textModel;\n}\n"]}
1
+ {"version":3,"file":"textProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/textProcessor.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AACpE,+DAA8D;AAC9D,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AAc,CACnB,KAA6B,EAC7B,IAAY,EACZ,SAAgC,EAChC,OAA0B;;IAE1B,IAAI,SAAuC,CAAC;IAE5C,IAAI,IAAI,EAAE;QACN,IACI,CAAC,IAAA,6BAAa,EAAC,IAAI,CAAC;YACpB,CAAC,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAC,MAAM,mCAAI,CAAC,CAAC,GAAG,CAAC;YACrC,IAAA,6CAAqB,EAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAC,UAAU,CAAC,EACrD;YACE,SAAS,GAAG,IAAA,uBAAU,EAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;YAEpD,IAAI,OAAO,CAAC,aAAa,EAAE;gBACvB,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC;aAC/B;YAED,IAAA,6BAAa,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAElC,IAAA,uBAAU,EAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;SACrD;KACJ;IAED,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["import { addDecorators } from '../../modelApi/common/addDecorators';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { addSelectionMarker } from '../utils/addSelectionMarker';\nimport { createText } from '../../modelApi/creators/createText';\nimport { ensureParagraph } from '../../modelApi/common/ensureParagraph';\nimport { getRegularSelectionOffsets } from '../utils/getRegularSelectionOffsets';\nimport { hasSpacesOnly } from '../../modelApi/common/hasSpacesOnly';\nimport { isWhiteSpacePreserved } from '../../domUtils/isWhiteSpacePreserved';\nimport { stackFormat } from '../utils/stackFormat';\nimport type {\n ContentModelBlockGroup,\n ContentModelParagraph,\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 internalTextProcessor(group, textNode, context);\n });\n });\n } else {\n internalTextProcessor(group, textNode, context);\n }\n};\n\nfunction internalTextProcessor(\n group: ContentModelBlockGroup,\n textNode: Text,\n context: DomToModelContext\n) {\n let txt = textNode.nodeValue || '';\n const offsets = getRegularSelectionOffsets(context, textNode);\n const txtStartOffset = offsets[0];\n let txtEndOffset = offsets[1];\n const segments: (ContentModelText | undefined)[] = [];\n const paragraph = ensureParagraph(group, context.blockFormat);\n\n if (txtStartOffset >= 0) {\n const subText = txt.substring(0, txtStartOffset);\n segments.push(addTextSegment(group, subText, paragraph, context));\n context.isInSelection = true;\n\n addSelectionMarker(group, context, textNode, txtStartOffset);\n\n txt = txt.substring(txtStartOffset);\n txtEndOffset -= txtStartOffset;\n }\n\n if (txtEndOffset >= 0) {\n const subText = txt.substring(0, txtEndOffset);\n segments.push(addTextSegment(group, subText, paragraph, context));\n\n if (\n context.selection &&\n (context.selection.type != 'range' || !context.selection.range.collapsed)\n ) {\n addSelectionMarker(group, context, textNode, offsets[1]); // Must use offsets[1] here as the unchanged offset value, cannot use txtEndOffset since it has been modified\n }\n\n context.isInSelection = false;\n txt = txt.substring(txtEndOffset);\n }\n\n segments.push(addTextSegment(group, txt, paragraph, context));\n context.domIndexer?.onSegment(\n textNode,\n paragraph,\n segments.filter((x): x is ContentModelText => !!x)\n );\n}\n\nfunction addTextSegment(\n group: ContentModelBlockGroup,\n text: string,\n paragraph: ContentModelParagraph,\n context: DomToModelContext\n): ContentModelText | undefined {\n let textModel: ContentModelText | undefined;\n\n if (text) {\n if (\n !hasSpacesOnly(text) ||\n (paragraph?.segments.length ?? 0) > 0 ||\n isWhiteSpacePreserved(paragraph?.format.whiteSpace)\n ) {\n textModel = createText(text, context.segmentFormat);\n\n if (context.isInSelection) {\n textModel.isSelected = true;\n }\n\n addDecorators(textModel, context);\n\n addSegment(group, textModel, context.blockFormat);\n }\n }\n\n return textModel;\n}\n"]}
@@ -2,4 +2,4 @@ import type { ContentModelBlockGroup, DomToModelContext } from 'roosterjs-conten
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare function addSelectionMarker(group: ContentModelBlockGroup, context: DomToModelContext): void;
5
+ export declare function addSelectionMarker(group: ContentModelBlockGroup, context: DomToModelContext, container?: Node, offset?: number): void;
@@ -8,8 +8,13 @@ var createSelectionMarker_1 = require("../../modelApi/creators/createSelectionMa
8
8
  /**
9
9
  * @internal
10
10
  */
11
- function addSelectionMarker(group, context) {
12
- var segmentFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, context.defaultFormat), context.segmentFormat);
11
+ function addSelectionMarker(group, context, container, offset) {
12
+ var pendingFormat = context.pendingFormat &&
13
+ context.pendingFormat.posContainer === container &&
14
+ context.pendingFormat.posOffset === offset
15
+ ? context.pendingFormat.format
16
+ : undefined;
17
+ var segmentFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, context.defaultFormat), context.segmentFormat), pendingFormat);
13
18
  var marker = (0, createSelectionMarker_1.createSelectionMarker)(segmentFormat);
14
19
  (0, addDecorators_1.addDecorators)(marker, context);
15
20
  (0, addSegment_1.addSegment)(group, marker, context.blockFormat, segmentFormat);
@@ -1 +1 @@
1
- {"version":3,"file":"addSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/utils/addSelectionMarker.ts"],"names":[],"mappings":";;;;AAAA,qEAAoE;AACpE,+DAA8D;AAC9D,uFAAsF;AAGtF;;GAEG;AACH,SAAgB,kBAAkB,CAAC,KAA6B,EAAE,OAA0B;IACxF,IAAM,aAAa,mDACZ,OAAO,CAAC,aAAa,GACrB,OAAO,CAAC,aAAa,CAC3B,CAAC;IACF,IAAM,MAAM,GAAG,IAAA,6CAAqB,EAAC,aAAa,CAAC,CAAC;IAEpD,IAAA,6BAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE/B,IAAA,uBAAU,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AAClE,CAAC;AAVD,gDAUC","sourcesContent":["import { addDecorators } from '../../modelApi/common/addDecorators';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { createSelectionMarker } from '../../modelApi/creators/createSelectionMarker';\nimport type { ContentModelBlockGroup, DomToModelContext } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function addSelectionMarker(group: ContentModelBlockGroup, context: DomToModelContext) {\n const segmentFormat = {\n ...context.defaultFormat,\n ...context.segmentFormat,\n };\n const marker = createSelectionMarker(segmentFormat);\n\n addDecorators(marker, context);\n\n addSegment(group, marker, context.blockFormat, segmentFormat);\n}\n"]}
1
+ {"version":3,"file":"addSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/utils/addSelectionMarker.ts"],"names":[],"mappings":";;;;AAAA,qEAAoE;AACpE,+DAA8D;AAC9D,uFAAsF;AAGtF;;GAEG;AACH,SAAgB,kBAAkB,CAC9B,KAA6B,EAC7B,OAA0B,EAC1B,SAAgB,EAChB,MAAe;IAEf,IAAM,aAAa,GACf,OAAO,CAAC,aAAa;QACrB,OAAO,CAAC,aAAa,CAAC,YAAY,KAAK,SAAS;QAChD,OAAO,CAAC,aAAa,CAAC,SAAS,KAAK,MAAM;QACtC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM;QAC9B,CAAC,CAAC,SAAS,CAAC;IACpB,IAAM,aAAa,yEACZ,OAAO,CAAC,aAAa,GACrB,OAAO,CAAC,aAAa,GACrB,aAAa,CACnB,CAAC;IACF,IAAM,MAAM,GAAG,IAAA,6CAAqB,EAAC,aAAa,CAAC,CAAC;IAEpD,IAAA,6BAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE/B,IAAA,uBAAU,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AAClE,CAAC;AAtBD,gDAsBC","sourcesContent":["import { addDecorators } from '../../modelApi/common/addDecorators';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { createSelectionMarker } from '../../modelApi/creators/createSelectionMarker';\nimport type { ContentModelBlockGroup, DomToModelContext } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function addSelectionMarker(\n group: ContentModelBlockGroup,\n context: DomToModelContext,\n container?: Node,\n offset?: number\n) {\n const pendingFormat =\n context.pendingFormat &&\n context.pendingFormat.posContainer === container &&\n context.pendingFormat.posOffset === offset\n ? context.pendingFormat.format\n : undefined;\n const segmentFormat = {\n ...context.defaultFormat,\n ...context.segmentFormat,\n ...pendingFormat,\n };\n const marker = createSelectionMarker(segmentFormat);\n\n addDecorators(marker, context);\n\n addSegment(group, marker, context.blockFormat, segmentFormat);\n}\n"]}
@@ -10,7 +10,9 @@ var getObjectKeys_1 = require("../../domUtils/getObjectKeys");
10
10
  // line 1 <---------------------------- in red here
11
11
  // <div>line 2</div> <---------------------- not in red here
12
12
  // </span>
13
- var SkippedStylesForBlock = ['backgroundColor'];
13
+ var SkippedStylesForBlockOnSegmentOnSegment = [
14
+ 'backgroundColor',
15
+ ];
14
16
  var SkippedStylesForTable = [
15
17
  'marginLeft',
16
18
  'marginRight',
@@ -99,13 +101,21 @@ function stackFormatInternal(format, processType) {
99
101
  var result_1 = (0, tslib_1.__assign)({}, format);
100
102
  (0, getObjectKeys_1.getObjectKeys)(format).forEach(function (key) {
101
103
  if ((processType == 'shallowCloneForBlock' &&
102
- SkippedStylesForBlock.indexOf(key) >=
103
- 0) ||
104
+ SkippedStylesForBlockOnSegmentOnSegment.indexOf(key) >= 0) ||
104
105
  (processType == 'shallowCloneForGroup' &&
105
106
  SkippedStylesForTable.indexOf(key) >= 0)) {
106
107
  delete result_1[key];
107
108
  }
108
109
  });
110
+ if (processType == 'shallowClone' || processType == 'shallowCloneForGroup') {
111
+ var blockFormat = format;
112
+ // For a new paragraph, if current text indent is already applied to previous block in the same level,
113
+ // we need to ignore it according to browser rendering behavior
114
+ if (blockFormat.textIndent) {
115
+ delete result_1.isTextIndentApplied;
116
+ blockFormat.isTextIndentApplied = true;
117
+ }
118
+ }
109
119
  return result_1;
110
120
  }
111
121
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stackFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/utils/stackFormat.ts"],"names":[],"mappings":";;;;AAAA,8DAA6D;AAsB7D,kGAAkG;AAClG,4DAA4D;AAC5D,OAAO;AACP,uCAAuC;AACvC,2DAA2D;AAC3D,+DAA+D;AAC/D,UAAU;AACV,IAAM,qBAAqB,GAAwC,CAAC,iBAAiB,CAAC,CAAC;AACvF,IAAM,qBAAqB,GAAsC;IAC7D,YAAY;IACZ,aAAa;IACb,aAAa;IACb,cAAc;CACjB,CAAC;AAEF;;GAEG;AACH,SAAgB,WAAW,CACvB,OAA0B,EAC1B,OAA2B,EAC3B,QAAoB;IAGhB,IAAA,aAAa,GAKb,OAAO,cALM,EACb,WAAW,GAIX,OAAO,YAJI,EACL,UAAU,GAGhB,OAAO,KAHS,EACV,UAAU,GAEhB,OAAO,KAFS,EACA,eAAe,GAC/B,OAAO,eADwB,CACvB;IACJ,IAAA,OAAO,GAA4C,OAAO,QAAnD,EAAE,SAAS,GAAiC,OAAO,UAAxC,EAAE,IAAI,GAA2B,OAAO,KAAlC,EAAE,IAAI,GAAqB,OAAO,KAA5B,EAAE,cAAc,GAAK,OAAO,eAAZ,CAAa;IAEnE,IAAI;QACA,OAAO,CAAC,aAAa,GAAG,mBAAmB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACpE,OAAO,CAAC,WAAW,GAAG,mBAAmB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,GAAG,iBAAiB,CAAC,UAAU,EA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AAO;YACR,OAAO;gBACH,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,EAAE;aACd,CAAC;QACN;YACI,OAAO,MAAM,CAAC;KACrB;AACL,CAAC;AAED,SAAS,mBAAmB,CACxB,MAAS,EACT,WAAwF;IAExF,QAAQ,WAAW,EAAE;QACjB,KAAK,OAAO;YACR,OAAO,EAAE,CAAC;QAEd,KAAK,SAAS;YACV,OAAO,MAAM,CAAC;QAElB;YACI,IAAM,QAAM,6BAAQ,MAAM,CAAE,CAAC;YAE7B,IAAA,6BAAa,EAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;gBAC7B,IACI,CAAC,WAAW,IAAI,sBAAsB;oBAClC,qBAAqB,CAAC,OAAO,CAAC,GAAsC,CAAC;wBACjE,CAAC,CAAC;oBACV,CAAC,WAAW,IAAI,sBAAsB;wBAClC,qBAAqB,CAAC,OAAO,CAAC,GAAoC,CAAC,IAAI,CAAC,CAAC,EAC/E;oBACE,OAAO,QAAM,CAAC,GAAG,CAAC,CAAC;iBACtB;YACL,CAAC,CAAC,CAAC;YAEH,OAAO,QAAM,CAAC;KACrB;AACL,CAAC","sourcesContent":["import { getObjectKeys } from '../../domUtils/getObjectKeys';\nimport type {\n ContentModelBlockFormat,\n ContentModelCode,\n ContentModelFormatBase,\n ContentModelLink,\n ContentModelParagraphDecorator,\n ContentModelSegmentFormat,\n DomToModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport interface StackFormatOptions {\n segment?: 'shallowClone' | 'shallowCloneForBlock' | 'empty';\n paragraph?: 'shallowClone' | 'shallowCloneForGroup' | 'empty';\n blockDecorator?: 'empty';\n link?: 'linkDefault' | 'cloneFormat' | 'empty';\n code?: 'codeDefault' | 'empty';\n}\n\n// Some styles, such as background color, won't be inherited by block element if it was originally\n// declared from an inline element. So we need to skip them.\n// e.g.\n// <span style=\"background-color: red\">\n// line 1 <---------------------------- in red here\n// <div>line 2</div> <---------------------- not in red here\n// </span>\nconst SkippedStylesForBlock: (keyof ContentModelSegmentFormat)[] = ['backgroundColor'];\nconst SkippedStylesForTable: (keyof ContentModelBlockFormat)[] = [\n 'marginLeft',\n 'marginRight',\n 'paddingLeft',\n 'paddingRight',\n];\n\n/**\n * @internal\n */\nexport function stackFormat(\n context: DomToModelContext,\n options: StackFormatOptions,\n callback: () => void\n) {\n const {\n segmentFormat,\n blockFormat,\n link: linkFormat,\n code: codeFormat,\n blockDecorator: decoratorFormat,\n } = context;\n const { segment, paragraph, link, code, blockDecorator } = options;\n\n try {\n context.segmentFormat = stackFormatInternal(segmentFormat, segment);\n context.blockFormat = stackFormatInternal(blockFormat, paragraph);\n context.link = stackLinkInternal(linkFormat, link);\n context.code = stackCodeInternal(codeFormat, code);\n context.blockDecorator = stackDecoratorInternal(decoratorFormat, blockDecorator);\n\n callback();\n } finally {\n context.segmentFormat = segmentFormat;\n context.blockFormat = blockFormat;\n context.link = linkFormat;\n context.code = codeFormat;\n context.blockDecorator = decoratorFormat;\n }\n}\n\nfunction stackLinkInternal(\n linkFormat: ContentModelLink,\n link?: 'linkDefault' | 'cloneFormat' | 'empty'\n) {\n switch (link) {\n case 'linkDefault':\n return {\n format: {\n underline: true,\n },\n dataset: {},\n };\n\n case 'empty':\n return {\n format: {},\n dataset: {},\n };\n\n case 'cloneFormat':\n default:\n return {\n dataset: linkFormat.dataset,\n format: { ...linkFormat.format },\n };\n }\n}\n\nfunction stackCodeInternal(codeFormat: ContentModelCode, code?: 'codeDefault' | 'empty') {\n switch (code) {\n case 'codeDefault':\n return {\n format: {\n fontFamily: 'monospace',\n },\n };\n case 'empty':\n return {\n format: {},\n };\n default:\n return codeFormat;\n }\n}\n\nfunction stackDecoratorInternal(\n format: ContentModelParagraphDecorator,\n decorator?: 'decoratorDefault' | 'empty'\n) {\n switch (decorator) {\n case 'empty':\n return {\n format: {},\n tagName: '',\n };\n default:\n return format;\n }\n}\n\nfunction stackFormatInternal<T extends ContentModelFormatBase>(\n format: T,\n processType?: 'shallowClone' | 'shallowCloneForBlock' | 'shallowCloneForGroup' | 'empty'\n): T | {} {\n switch (processType) {\n case 'empty':\n return {};\n\n case undefined:\n return format;\n\n default:\n const result = { ...format };\n\n getObjectKeys(format).forEach(key => {\n if (\n (processType == 'shallowCloneForBlock' &&\n SkippedStylesForBlock.indexOf(key as keyof ContentModelSegmentFormat) >=\n 0) ||\n (processType == 'shallowCloneForGroup' &&\n SkippedStylesForTable.indexOf(key as keyof ContentModelBlockFormat) >= 0)\n ) {\n delete result[key];\n }\n });\n\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"stackFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/utils/stackFormat.ts"],"names":[],"mappings":";;;;AAAA,8DAA6D;AAsB7D,kGAAkG;AAClG,4DAA4D;AAC5D,OAAO;AACP,uCAAuC;AACvC,2DAA2D;AAC3D,+DAA+D;AAC/D,UAAU;AACV,IAAM,uCAAuC,GAAwC;IACjF,iBAAiB;CACpB,CAAC;AACF,IAAM,qBAAqB,GAAsC;IAC7D,YAAY;IACZ,aAAa;IACb,aAAa;IACb,cAAc;CACjB,CAAC;AAEF;;GAEG;AACH,SAAgB,WAAW,CACvB,OAA0B,EAC1B,OAA2B,EAC3B,QAAoB;IAGhB,IAAA,aAAa,GAKb,OAAO,cALM,EACb,WAAW,GAIX,OAAO,YAJI,EACL,UAAU,GAGhB,OAAO,KAHS,EACV,UAAU,GAEhB,OAAO,KAFS,EACA,eAAe,GAC/B,OAAO,eADwB,CACvB;IACJ,IAAA,OAAO,GAA4C,OAAO,QAAnD,EAAE,SAAS,GAAiC,OAAO,UAAxC,EAAE,IAAI,GAA2B,OAAO,KAAlC,EAAE,IAAI,GAAqB,OAAO,KAA5B,EAAE,cAAc,GAAK,OAAO,eAAZ,CAAa;IAEnE,IAAI;QACA,OAAO,CAAC,aAAa,GAAG,mBAAmB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACpE,OAAO,CAAC,WA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CAAC;KACzB;AACL,CAAC;AAED,SAAS,sBAAsB,CAC3B,MAAsC,EACtC,SAAwC;IAExC,QAAQ,SAAS,EAAE;QACf,KAAK,OAAO;YACR,OAAO;gBACH,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,EAAE;aACd,CAAC;QACN;YACI,OAAO,MAAM,CAAC;KACrB;AACL,CAAC;AAED,SAAS,mBAAmB,CACxB,MAAS,EACT,WAAwF;IAExF,QAAQ,WAAW,EAAE;QACjB,KAAK,OAAO;YACR,OAAO,EAAE,CAAC;QAEd,KAAK,SAAS;YACV,OAAO,MAAM,CAAC;QAElB;YACI,IAAM,QAAM,6BAAQ,MAAM,CAAE,CAAC;YAE7B,IAAA,6BAAa,EAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;gBAC7B,IACI,CAAC,WAAW,IAAI,sBAAsB;oBAClC,uCAAuC,CAAC,OAAO,CAC3C,GAAsC,CACzC,IAAI,CAAC,CAAC;oBACX,CAAC,WAAW,IAAI,sBAAsB;wBAClC,qBAAqB,CAAC,OAAO,CAAC,GAAoC,CAAC,IAAI,CAAC,CAAC,EAC/E;oBACE,OAAO,QAAM,CAAC,GAAG,CAAC,CAAC;iBACtB;YACL,CAAC,CAAC,CAAC;YAEH,IAAI,WAAW,IAAI,cAAc,IAAI,WAAW,IAAI,sBAAsB,EAAE;gBACxE,IAAM,WAAW,GAAG,MAAiC,CAAC;gBAEtD,sGAAsG;gBACtG,+DAA+D;gBAC/D,IAAI,WAAW,CAAC,UAAU,EAAE;oBACxB,OAAQ,QAAkC,CAAC,mBAAmB,CAAC;oBAC/D,WAAW,CAAC,mBAAmB,GAAG,IAAI,CAAC;iBAC1C;aACJ;YAED,OAAO,QAAM,CAAC;KACrB;AACL,CAAC","sourcesContent":["import { getObjectKeys } from '../../domUtils/getObjectKeys';\nimport type {\n ContentModelBlockFormat,\n ContentModelCode,\n ContentModelFormatBase,\n ContentModelLink,\n ContentModelParagraphDecorator,\n ContentModelSegmentFormat,\n DomToModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport interface StackFormatOptions {\n segment?: 'shallowClone' | 'shallowCloneForBlock' | 'empty';\n paragraph?: 'shallowClone' | 'shallowCloneForGroup' | 'empty';\n blockDecorator?: 'empty';\n link?: 'linkDefault' | 'cloneFormat' | 'empty';\n code?: 'codeDefault' | 'empty';\n}\n\n// Some styles, such as background color, won't be inherited by block element if it was originally\n// declared from an inline element. So we need to skip them.\n// e.g.\n// <span style=\"background-color: red\">\n// line 1 <---------------------------- in red here\n// <div>line 2</div> <---------------------- not in red here\n// </span>\nconst SkippedStylesForBlockOnSegmentOnSegment: (keyof ContentModelSegmentFormat)[] = [\n 'backgroundColor',\n];\nconst SkippedStylesForTable: (keyof ContentModelBlockFormat)[] = [\n 'marginLeft',\n 'marginRight',\n 'paddingLeft',\n 'paddingRight',\n];\n\n/**\n * @internal\n */\nexport function stackFormat(\n context: DomToModelContext,\n options: StackFormatOptions,\n callback: () => void\n) {\n const {\n segmentFormat,\n blockFormat,\n link: linkFormat,\n code: codeFormat,\n blockDecorator: decoratorFormat,\n } = context;\n const { segment, paragraph, link, code, blockDecorator } = options;\n\n try {\n context.segmentFormat = stackFormatInternal(segmentFormat, segment);\n context.blockFormat = stackFormatInternal(blockFormat, paragraph);\n context.link = stackLinkInternal(linkFormat, link);\n context.code = stackCodeInternal(codeFormat, code);\n context.blockDecorator = stackDecoratorInternal(decoratorFormat, blockDecorator);\n\n callback();\n } finally {\n context.segmentFormat = segmentFormat;\n context.blockFormat = blockFormat;\n context.link = linkFormat;\n context.code = codeFormat;\n context.blockDecorator = decoratorFormat;\n }\n}\n\nfunction stackLinkInternal(\n linkFormat: ContentModelLink,\n link?: 'linkDefault' | 'cloneFormat' | 'empty'\n) {\n switch (link) {\n case 'linkDefault':\n return {\n format: {\n underline: true,\n },\n dataset: {},\n };\n\n case 'empty':\n return {\n format: {},\n dataset: {},\n };\n\n case 'cloneFormat':\n default:\n return {\n dataset: linkFormat.dataset,\n format: { ...linkFormat.format },\n };\n }\n}\n\nfunction stackCodeInternal(codeFormat: ContentModelCode, code?: 'codeDefault' | 'empty') {\n switch (code) {\n case 'codeDefault':\n return {\n format: {\n fontFamily: 'monospace',\n },\n };\n case 'empty':\n return {\n format: {},\n };\n default:\n return codeFormat;\n }\n}\n\nfunction stackDecoratorInternal(\n format: ContentModelParagraphDecorator,\n decorator?: 'decoratorDefault' | 'empty'\n) {\n switch (decorator) {\n case 'empty':\n return {\n format: {},\n tagName: '',\n };\n default:\n return format;\n }\n}\n\nfunction stackFormatInternal<T extends ContentModelFormatBase>(\n format: T,\n processType?: 'shallowClone' | 'shallowCloneForBlock' | 'shallowCloneForGroup' | 'empty'\n): T | {} {\n switch (processType) {\n case 'empty':\n return {};\n\n case undefined:\n return format;\n\n default:\n const result = { ...format };\n\n getObjectKeys(format).forEach(key => {\n if (\n (processType == 'shallowCloneForBlock' &&\n SkippedStylesForBlockOnSegmentOnSegment.indexOf(\n key as keyof ContentModelSegmentFormat\n ) >= 0) ||\n (processType == 'shallowCloneForGroup' &&\n SkippedStylesForTable.indexOf(key as keyof ContentModelBlockFormat) >= 0)\n ) {\n delete result[key];\n }\n });\n\n if (processType == 'shallowClone' || processType == 'shallowCloneForGroup') {\n const blockFormat = format as ContentModelBlockFormat;\n\n // For a new paragraph, if current text indent is already applied to previous block in the same level,\n // we need to ignore it according to browser rendering behavior\n if (blockFormat.textIndent) {\n delete (result as ContentModelBlockFormat).isTextIndentApplied;\n blockFormat.isTextIndentApplied = true;\n }\n }\n\n return result;\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { FormatHandler } from '../FormatHandler';
2
+ import type { TextIndentFormat } from 'roosterjs-content-model-types';
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare const textIndentFormatHandler: FormatHandler<TextIndentFormat>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.textIndentFormatHandler = void 0;
4
+ /**
5
+ * @internal
6
+ */
7
+ exports.textIndentFormatHandler = {
8
+ parse: function (format, element) {
9
+ var textIndent = element.style.textIndent;
10
+ if (textIndent) {
11
+ format.textIndent = textIndent;
12
+ }
13
+ },
14
+ apply: function (format, element) {
15
+ if (format.textIndent) {
16
+ element.style.textIndent = format.textIndent;
17
+ }
18
+ },
19
+ };
20
+ //# sourceMappingURL=textIndentFormatHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textIndentFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/block/textIndentFormatHandler.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACU,QAAA,uBAAuB,GAAoC;IACpE,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO;QACnB,IAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC;QAE5C,IAAI,UAAU,EAAE;YACZ,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC;SAClC;IACL,CAAC;IACD,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO;QACnB,IAAI,MAAM,CAAC,UAAU,EAAE;YACnB,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;SAChD;IACL,CAAC;CACJ,CAAC","sourcesContent":["import type { FormatHandler } from '../FormatHandler';\nimport type { TextIndentFormat } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const textIndentFormatHandler: FormatHandler<TextIndentFormat> = {\n parse: (format, element) => {\n const textIndent = element.style.textIndent;\n\n if (textIndent) {\n format.textIndent = textIndent;\n }\n },\n apply: (format, element) => {\n if (format.textIndent) {\n element.style.textIndent = format.textIndent;\n }\n },\n};\n"]}
@@ -8,14 +8,14 @@ var shouldSetValue_1 = require("../utils/shouldSetValue");
8
8
  */
9
9
  exports.backgroundColorFormatHandler = {
10
10
  parse: function (format, element, context, defaultStyle) {
11
- var backgroundColor = (0, color_1.getColor)(element, true /*isBackground*/, context.darkColorHandler, !!context.isDarkMode) || defaultStyle.backgroundColor;
11
+ var backgroundColor = (0, color_1.getColor)(element, true /*isBackground*/, !!context.isDarkMode, context.darkColorHandler) || defaultStyle.backgroundColor;
12
12
  if ((0, shouldSetValue_1.shouldSetValue)(backgroundColor, 'transparent', undefined /*existingValue*/, defaultStyle.backgroundColor)) {
13
13
  format.backgroundColor = backgroundColor;
14
14
  }
15
15
  },
16
16
  apply: function (format, element, context) {
17
17
  if (format.backgroundColor) {
18
- (0, color_1.setColor)(element, format.backgroundColor, true /*isBackground*/, context.darkColorHandler, !!context.isDarkMode);
18
+ (0, color_1.setColor)(element, format.backgroundColor, true /*isBackground*/, !!context.isDarkMode, context.darkColorHandler);
19
19
  }
20
20
  },
21
21
  };
@@ -1 +1 @@
1
- {"version":3,"file":"backgroundColorFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/common/backgroundColorFormatHandler.ts"],"names":[],"mappings":";;;AAAA,wCAAoD;AACpD,0DAAyD;AAIzD;;GAEG;AACU,QAAA,4BAA4B,GAAyC;IAC9E,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY;QAC1C,IAAM,eAAe,GACjB,IAAA,gBAAQ,EACJ,OAAO,EACP,IAAI,CAAC,gBAAgB,EACrB,OAAO,CAAC,gBAAgB,EACxB,CAAC,CAAC,OAAO,CAAC,UAAU,CACvB,IAAI,YAAY,CAAC,eAAe,CAAC;QAEtC,IACI,IAAA,+BAAc,EACV,eAAe,EACf,aAAa,EACb,SAAS,CAAC,iBAAiB,EAC3B,YAAY,CAAC,eAAe,CAC/B,EACH;YACE,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;SAC5C;IACL,CAAC;IACD,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO;QAC5B,IAAI,MAAM,CAAC,eAAe,EAAE;YACxB,IAAA,gBAAQ,EACJ,OAAO,EACP,MAAM,CAAC,eAAe,EACtB,IAAI,CAAC,gBAAgB,EACrB,OAAO,CAAC,gBAAgB,EACxB,CAAC,CAAC,OAAO,CAAC,UAAU,CACvB,CAAC;SACL;IACL,CAAC;CACJ,CAAC","sourcesContent":["import { getColor, setColor } from '../utils/color';\nimport { shouldSetValue } from '../utils/shouldSetValue';\nimport type { BackgroundColorFormat } from 'roosterjs-content-model-types';\nimport type { FormatHandler } from '../FormatHandler';\n\n/**\n * @internal\n */\nexport const backgroundColorFormatHandler: FormatHandler<BackgroundColorFormat> = {\n parse: (format, element, context, defaultStyle) => {\n const backgroundColor =\n getColor(\n element,\n true /*isBackground*/,\n context.darkColorHandler,\n !!context.isDarkMode\n ) || defaultStyle.backgroundColor;\n\n if (\n shouldSetValue(\n backgroundColor,\n 'transparent',\n undefined /*existingValue*/,\n defaultStyle.backgroundColor\n )\n ) {\n format.backgroundColor = backgroundColor;\n }\n },\n apply: (format, element, context) => {\n if (format.backgroundColor) {\n setColor(\n element,\n format.backgroundColor,\n true /*isBackground*/,\n context.darkColorHandler,\n !!context.isDarkMode\n );\n }\n },\n};\n"]}
1
+ {"version":3,"file":"backgroundColorFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/common/backgroundColorFormatHandler.ts"],"names":[],"mappings":";;;AAAA,wCAAoD;AACpD,0DAAyD;AAIzD;;GAEG;AACU,QAAA,4BAA4B,GAAyC;IAC9E,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY;QAC1C,IAAM,eAAe,GACjB,IAAA,gBAAQ,EACJ,OAAO,EACP,IAAI,CAAC,gBAAgB,EACrB,CAAC,CAAC,OAAO,CAAC,UAAU,EACpB,OAAO,CAAC,gBAAgB,CAC3B,IAAI,YAAY,CAAC,eAAe,CAAC;QAEtC,IACI,IAAA,+BAAc,EACV,eAAe,EACf,aAAa,EACb,SAAS,CAAC,iBAAiB,EAC3B,YAAY,CAAC,eAAe,CAC/B,EACH;YACE,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;SAC5C;IACL,CAAC;IACD,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO;QAC5B,IAAI,MAAM,CAAC,eAAe,EAAE;YACxB,IAAA,gBAAQ,EACJ,OAAO,EACP,MAAM,CAAC,eAAe,EACtB,IAAI,CAAC,gBAAgB,EACrB,CAAC,CAAC,OAAO,CAAC,UAAU,EACpB,OAAO,CAAC,gBAAgB,CAC3B,CAAC;SACL;IACL,CAAC;CACJ,CAAC","sourcesContent":["import { getColor, setColor } from '../utils/color';\nimport { shouldSetValue } from '../utils/shouldSetValue';\nimport type { BackgroundColorFormat } from 'roosterjs-content-model-types';\nimport type { FormatHandler } from '../FormatHandler';\n\n/**\n * @internal\n */\nexport const backgroundColorFormatHandler: FormatHandler<BackgroundColorFormat> = {\n parse: (format, element, context, defaultStyle) => {\n const backgroundColor =\n getColor(\n element,\n true /*isBackground*/,\n !!context.isDarkMode,\n context.darkColorHandler\n ) || defaultStyle.backgroundColor;\n\n if (\n shouldSetValue(\n backgroundColor,\n 'transparent',\n undefined /*existingValue*/,\n defaultStyle.backgroundColor\n )\n ) {\n format.backgroundColor = backgroundColor;\n }\n },\n apply: (format, element, context) => {\n if (format.backgroundColor) {\n setColor(\n element,\n format.backgroundColor,\n true /*isBackground*/,\n !!context.isDarkMode,\n context.darkColorHandler\n );\n }\n },\n};\n"]}