roosterjs-content-model-api 9.31.0 → 9.33.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 (52) hide show
  1. package/lib/modelApi/block/setModelDirection.d.ts +1 -1
  2. package/lib/modelApi/block/setModelDirection.js +40 -3
  3. package/lib/modelApi/block/setModelDirection.js.map +1 -1
  4. package/lib/modelApi/block/setModelIndentation.js +3 -3
  5. package/lib/modelApi/block/setModelIndentation.js.map +1 -1
  6. package/lib/modelApi/common/adjustIndentation.d.ts +13 -0
  7. package/lib/modelApi/common/adjustIndentation.js +115 -0
  8. package/lib/modelApi/common/adjustIndentation.js.map +1 -0
  9. package/lib/modelApi/list/setListType.js +7 -0
  10. package/lib/modelApi/list/setListType.js.map +1 -1
  11. package/lib/publicApi/block/setDirection.d.ts +2 -2
  12. package/lib/publicApi/block/setDirection.js +1 -1
  13. package/lib/publicApi/block/setDirection.js.map +1 -1
  14. package/lib/publicApi/format/getFormatState.js +1 -1
  15. package/lib/publicApi/format/getFormatState.js.map +1 -1
  16. package/lib/publicApi/table/insertTable.js +2 -0
  17. package/lib/publicApi/table/insertTable.js.map +1 -1
  18. package/lib-amd/modelApi/block/setModelDirection.d.ts +1 -1
  19. package/lib-amd/modelApi/block/setModelDirection.js +40 -3
  20. package/lib-amd/modelApi/block/setModelDirection.js.map +1 -1
  21. package/lib-amd/modelApi/block/setModelIndentation.js +3 -4
  22. package/lib-amd/modelApi/block/setModelIndentation.js.map +1 -1
  23. package/lib-amd/modelApi/common/adjustIndentation.d.ts +13 -0
  24. package/lib-amd/modelApi/common/adjustIndentation.js +115 -0
  25. package/lib-amd/modelApi/common/adjustIndentation.js.map +1 -0
  26. package/lib-amd/modelApi/list/setListType.js +7 -1
  27. package/lib-amd/modelApi/list/setListType.js.map +1 -1
  28. package/lib-amd/publicApi/block/setDirection.d.ts +2 -2
  29. package/lib-amd/publicApi/block/setDirection.js +1 -1
  30. package/lib-amd/publicApi/block/setDirection.js.map +1 -1
  31. package/lib-amd/publicApi/format/getFormatState.js +1 -1
  32. package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
  33. package/lib-amd/publicApi/table/insertTable.js +2 -1
  34. package/lib-amd/publicApi/table/insertTable.js.map +1 -1
  35. package/lib-mjs/modelApi/block/setModelDirection.d.ts +1 -1
  36. package/lib-mjs/modelApi/block/setModelDirection.js +40 -3
  37. package/lib-mjs/modelApi/block/setModelDirection.js.map +1 -1
  38. package/lib-mjs/modelApi/block/setModelIndentation.js +1 -1
  39. package/lib-mjs/modelApi/block/setModelIndentation.js.map +1 -1
  40. package/lib-mjs/modelApi/common/adjustIndentation.d.ts +13 -0
  41. package/lib-mjs/modelApi/common/adjustIndentation.js +110 -0
  42. package/lib-mjs/modelApi/common/adjustIndentation.js.map +1 -0
  43. package/lib-mjs/modelApi/list/setListType.js +7 -0
  44. package/lib-mjs/modelApi/list/setListType.js.map +1 -1
  45. package/lib-mjs/publicApi/block/setDirection.d.ts +2 -2
  46. package/lib-mjs/publicApi/block/setDirection.js +1 -1
  47. package/lib-mjs/publicApi/block/setDirection.js.map +1 -1
  48. package/lib-mjs/publicApi/format/getFormatState.js +1 -1
  49. package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
  50. package/lib-mjs/publicApi/table/insertTable.js +2 -0
  51. package/lib-mjs/publicApi/table/insertTable.js.map +1 -1
  52. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":";;;;IAkBA;;OAEG;IACH,SAAgB,iBAAiB,CAAC,KAAmC,EAAE,SAAwB;QAC3F,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,0BAA0B,GAAG,IAAA,kDAAoB,EACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QAEF,0BAA0B,CAAC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G,CAAC,CAAC;SACtB;IACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';\nimport {\n applyTableFormat,\n getOperationalBlocks,\n isBlockGroupOfType,\n mutateBlock,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n BorderFormat,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setModelDirection(model: ReadonlyContentModelDocument, direction: 'ltr' | 'rtl') {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(readonlyItem => {\n const item = mutateBlock(readonlyItem);\n\n item.levels.forEach(level => {\n level.format.direction = direction;\n });\n\n item.blocks.forEach(block => internalSetDirection(block, direction));\n });\n } else if (block) {\n internalSetDirection(block, direction);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(block: ReadonlyContentModelBlock, direction: 'ltr' | 'rtl') {\n const wasRtl = block.format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n const { format } = mutateBlock(block);\n format.direction = direction;\n\n // Adjust margin when change direction\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n\n // If whole Table direction changed, flip cell side borders\n if (block && block.blockType == 'Table') {\n block.rows.forEach(row => {\n row.cells.forEach(cell => {\n // Optimise by skipping cells with unchanged borders\n updateTableCellMetadata(mutateBlock(cell), metadata => {\n if (metadata?.borderOverride) {\n const storeBorderLeft = cell.format.borderLeft;\n setProperty(cell.format, 'borderLeft', cell.format.borderRight);\n setProperty(cell.format, 'borderRight', storeBorderLeft);\n }\n return metadata;\n });\n });\n });\n\n // Apply changed borders\n applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);\n }\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat & BorderFormat,\n key: keyof (MarginFormat & PaddingFormat & BorderFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n"]}
1
+ {"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":";;;;IAmBA,4CAA4C;IAC5C,uHAAuH;IACvH,IAAM,cAAc,GAAG,yDAAyD,CAAC;IACjF,IAAM,cAAc,GAAG,0EAA0E,CAAC;IAClG,IAAM,gBAAgB,GAAG,KAAK,CAAC;IAE/B;;OAEG;IACH,SAAgB,iBAAiB,CAC7B,KAAmC,EACnC,SAAiC;QAEjC,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,0BAA0B,GAAG,IAAA,kDAAoB,EACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;gBAAP,KAAK,WAAA;YACvC,IAAI,aAA4B,CAAC;YACjC,IAAI,SAAS,KAAK,MAAM,EAAE;gBACtB,aAAa,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;aACjD;iBAAM;gBACH,aAAa,GAAG,SAAS,CAAC;aAC7B;YACD,IAAI,IAAA,gDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAM,KAAK,GAAG,IAAA,qDAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,CA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MAAM,CACvE,UAAC,GAAG,IAAsC,OAAA,GAAG,CAAC,WAAW,KAAK,MAAM,EAA1B,CAA0B,CACvE,CAAC;YACF,IAAI,SAAS,GACT,iBAAiB,CAAC,MAAM,GAAG,CAAC;gBACxB,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,UAAC,IAAI,EAAE,GAAG,IAAK,OAAA,IAAI,GAAG,GAAG,CAAC,IAAI,EAAf,CAAe,EAAE,EAAE,CAAC;gBAC9D,CAAC,CAAC,SAAS,CAAC;YACpB,IAAI,CAAC,CAAC,SAAS,EAAE;gBACb,eAAe;gBACf,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;gBAElD,oBAAoB;gBACpB,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;gBAEpD,IAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;gBACnD,IAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAEpD,IAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;gBAE7C,OAAO,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;aAC9C;iBAAM;gBACH,OAAO,KAAK,CAAC,CAAC,qCAAqC;aACtD;SACJ;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';\nimport {\n applyTableFormat,\n getOperationalBlocks,\n isBlockGroupOfType,\n mutateBlock,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n BorderFormat,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelText,\n} from 'roosterjs-content-model-types';\n\n// Regexes for character direction detection\n// Strongly typed RTL character ranges. Referenced unicode's DerivedBidiClass.txt, excluding things in the 2 bit range.\nconst RTL_CHAR_REGEX = /[\\u0590-\\u05FF\\u0600-\\u08FF\\uFB1D-\\uFDFF\\uFE70-\\uFEFF]/g;\nconst URL_CHAR_REGEX = /http\\S+|www\\S+|https\\S+|<a\\s+(?:[^>]*?\\s+)?href=([\"']).*?\\1.*?>.*?<\\/a>/g;\nconst WHITESPACE_REGEX = /\\s/g;\n\n/**\n * @internal\n */\nexport function setModelDirection(\n model: ReadonlyContentModelDocument,\n direction: 'ltr' | 'rtl' | 'auto'\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n let calcDirection: 'ltr' | 'rtl';\n if (direction === 'auto') {\n calcDirection = determineTextDirection(block);\n } else {\n calcDirection = direction;\n }\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(readonlyItem => {\n const item = mutateBlock(readonlyItem);\n\n item.levels.forEach(level => {\n level.format.direction = calcDirection;\n });\n\n item.blocks.forEach(block => internalSetDirection(block, calcDirection));\n });\n } else if (block) {\n internalSetDirection(block, calcDirection);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(block: ReadonlyContentModelBlock, direction: 'ltr' | 'rtl') {\n const wasRtl = block.format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n const { format } = mutateBlock(block);\n format.direction = direction;\n\n // Adjust margin when change direction\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n\n // If whole Table direction changed, flip cell side borders\n if (block && block.blockType == 'Table') {\n block.rows.forEach(row => {\n row.cells.forEach(cell => {\n // Optimise by skipping cells with unchanged borders\n updateTableCellMetadata(mutateBlock(cell), metadata => {\n if (metadata?.borderOverride) {\n const storeBorderLeft = cell.format.borderLeft;\n setProperty(cell.format, 'borderLeft', cell.format.borderRight);\n setProperty(cell.format, 'borderRight', storeBorderLeft);\n }\n return metadata;\n });\n });\n });\n\n // Apply changed borders\n applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);\n }\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat & BorderFormat,\n key: keyof (MarginFormat & PaddingFormat & BorderFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n\n// Designed to match browser's 'auto' detection, by scanning over the inner text until it hits a strong LTR/RTL character\nfunction determineTextDirection(block: ReadonlyContentModelBlock): 'ltr' | 'rtl' {\n if (block.blockType === 'Paragraph') {\n const findTextSegements: ReadonlyContentModelText[] = block.segments.filter(\n (seg): seg is ReadonlyContentModelText => seg.segmentType === 'Text'\n );\n let innerText =\n findTextSegements.length > 0\n ? findTextSegements.reduce((prev, seg) => prev + seg.text, '')\n : undefined;\n if (!!innerText) {\n // Remove links\n innerText = innerText.replace(URL_CHAR_REGEX, '');\n\n // Remove whitespace\n innerText = innerText.replace(WHITESPACE_REGEX, '');\n\n const rtlMatches = innerText.match(RTL_CHAR_REGEX);\n const rtlCount = rtlMatches ? rtlMatches.length : 0;\n\n const ltrCount = innerText.length - rtlCount;\n\n return rtlCount > ltrCount ? 'rtl' : 'ltr';\n } else {\n return 'ltr'; // Default to LTR if no text is found\n }\n } else {\n return 'ltr';\n }\n}\n"]}
@@ -1,8 +1,7 @@
1
- define(["require", "exports", "tslib", "../list/findListItemsInSameThread", "../list/getListAnnounceData", "./splitSelectedParagraphByBr", "roosterjs-content-model-dom"], function (require, exports, tslib_1, findListItemsInSameThread_1, getListAnnounceData_1, splitSelectedParagraphByBr_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "tslib", "../list/findListItemsInSameThread", "../list/getListAnnounceData", "../common/adjustIndentation", "./splitSelectedParagraphByBr", "roosterjs-content-model-dom"], function (require, exports, tslib_1, findListItemsInSameThread_1, getListAnnounceData_1, adjustIndentation_1, splitSelectedParagraphByBr_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.setModelIndentation = void 0;
5
- var IndentStepInPixel = 40;
6
5
  /**
7
6
  * @param model The content model to set indentation
8
7
  * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent
@@ -10,7 +9,7 @@ define(["require", "exports", "tslib", "../list/findListItemsInSameThread", "../
10
9
  * Set indentation for selected list items or paragraphs
11
10
  */
12
11
  function setModelIndentation(model, indentation, length, context) {
13
- if (length === void 0) { length = IndentStepInPixel; }
12
+ if (length === void 0) { length = adjustIndentation_1.IndentStepInPixel; }
14
13
  (0, splitSelectedParagraphByBr_1.splitSelectedParagraphByBr)(model);
15
14
  var paragraphOrListItem = (0, roosterjs_content_model_dom_1.getOperationalBlocks)(model, ['ListItem'], ['TableCell']);
16
15
  var isIndent = indentation == 'indent';
@@ -130,7 +129,7 @@ define(["require", "exports", "tslib", "../list/findListItemsInSameThread", "../
130
129
  return false;
131
130
  }
132
131
  function calculateMarginValue(format, isIndent, length) {
133
- if (length === void 0) { length = IndentStepInPixel; }
132
+ if (length === void 0) { length = adjustIndentation_1.IndentStepInPixel; }
134
133
  var marginLeft = format.marginLeft, marginRight = format.marginRight, direction = format.direction;
135
134
  var isRtl = direction == 'rtl';
136
135
  var originalValue = (0, roosterjs_content_model_dom_1.parseValueWithUnit)(isRtl ? marginRight : marginLeft);
@@ -1 +1 @@
1
- {"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelInd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;YACH,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { getListAnnounceData } from '../list/getListAnnounceData';\nimport { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';\nimport {\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n mutateBlock,\n parseValueWithUnit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ContentModelListItem,\n ContentModelListLevel,\n FormatContentModelContext,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n} from 'roosterjs-content-model-types';\n\nconst IndentStepInPixel = 40;\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ReadonlyContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel,\n context?: FormatContentModelContext\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ReadonlyContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const threadIdx = thread.indexOf(block);\n const previousItem = thread[threadIdx - 1];\n const nextItem = thread[threadIdx + 1];\n const levelLength = block.levels.length;\n const lastLevel = block.levels[levelLength - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format,\n previousItem && previousItem.levels.length > levelLength\n ? previousItem.levels[levelLength].dataset\n : nextItem && nextItem.levels.length > levelLength\n ? nextItem.levels[levelLength].dataset\n : undefined\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n\n if (block.levels.length > 0 && context) {\n context.announceData = getListAnnounceData([block, ...path]);\n }\n }\n } else if (block) {\n let currentBlock: ReadonlyContentModelBlock = block;\n let currentParent: ReadonlyContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = mutateBlock(currentBlock);\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n mutateBlock(currentParent);\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n\nfunction isSelected(listItem: ReadonlyContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ReadonlyContentModelDocument,\n listItem: ReadonlyContentModelListItem,\n parent: ReadonlyContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: Readonly<ContentModelBlockFormat>,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
1
+ {"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelIndentation.ts"],"names":[],"mappings":";;;;IAuBA;;;;;OAKG;IACH,SAAgB,mBAAmB,CAC/B,KAAmC,EACnC,WAAiC,EACjC,MAAkC,EAClC,OAAmC;QADnC,uBAAA,EAAA,SAAiB,qCAAiB;QAGlC,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,mBAAmB,GAAG,IAAA,kDAAoB,EAC5C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CA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CAAC,EAAE;gBAC9D,OAAO,KAAK,CAAC;aAChB;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,SAAS,oBAAoB,CACzB,MAAyC,EACzC,QAAiB,EACjB,MAAkC;QAAlC,uBAAA,EAAA,SAAiB,qCAAiB;QAE1B,IAAA,UAAU,GAA6B,MAAM,WAAnC,EAAE,WAAW,GAAgB,MAAM,YAAtB,EAAE,SAAS,GAAK,MAAM,UAAX,CAAY;QACtD,IAAM,KAAK,GAAG,SAAS,IAAI,KAAK,CAAC;QACjC,IAAM,aAAa,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAC3E,IAAI,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;QAEpF,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACnE;QAED,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,oDAAoD;YACpD,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { getListAnnounceData } from '../list/getListAnnounceData';\nimport { IndentStepInPixel } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';\nimport {\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n mutateBlock,\n parseValueWithUnit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ContentModelListItem,\n ContentModelListLevel,\n FormatContentModelContext,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ReadonlyContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel,\n context?: FormatContentModelContext\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ReadonlyContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const threadIdx = thread.indexOf(block);\n const previousItem = thread[threadIdx - 1];\n const nextItem = thread[threadIdx + 1];\n const levelLength = block.levels.length;\n const lastLevel = block.levels[levelLength - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format,\n previousItem && previousItem.levels.length > levelLength\n ? previousItem.levels[levelLength].dataset\n : nextItem && nextItem.levels.length > levelLength\n ? nextItem.levels[levelLength].dataset\n : undefined\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n\n if (block.levels.length > 0 && context) {\n context.announceData = getListAnnounceData([block, ...path]);\n }\n }\n } else if (block) {\n let currentBlock: ReadonlyContentModelBlock = block;\n let currentParent: ReadonlyContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = mutateBlock(currentBlock);\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n mutateBlock(currentParent);\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n\nfunction isSelected(listItem: ReadonlyContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ReadonlyContentModelDocument,\n listItem: ReadonlyContentModelListItem,\n parent: ReadonlyContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: Readonly<ContentModelBlockFormat>,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { ContentModelTable, InsertPoint, ShallowMutableContentModelListItem } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const IndentStepInPixel = 40;
6
+ /**
7
+ * @internal
8
+ */
9
+ export declare function adjustListIndentation(listItem: ShallowMutableContentModelListItem): void;
10
+ /**
11
+ * @internal
12
+ */
13
+ export declare function adjustTableIndentation(insertPoint: InsertPoint, table: ContentModelTable): void;
@@ -0,0 +1,115 @@
1
+ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_dom_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.adjustTableIndentation = exports.adjustListIndentation = exports.IndentStepInPixel = void 0;
5
+ var EN_SPACE = '\u2002';
6
+ var REGULAR_SPACE = '\u0020';
7
+ var NON_BREAK_SPACES = '\u00A0';
8
+ /**
9
+ * @internal
10
+ */
11
+ exports.IndentStepInPixel = 40;
12
+ function countTabsSpaces(text) {
13
+ var spaces = countSpacesBeforeText(text);
14
+ var tabSpaces = Math.floor(spaces / 4);
15
+ return tabSpaces;
16
+ }
17
+ function countSpacesBeforeText(str) {
18
+ var e_1, _a;
19
+ var count = 0;
20
+ try {
21
+ for (var str_1 = (0, tslib_1.__values)(str), str_1_1 = str_1.next(); !str_1_1.done; str_1_1 = str_1.next()) {
22
+ var char = str_1_1.value;
23
+ if (char === EN_SPACE || char === NON_BREAK_SPACES || char == REGULAR_SPACE) {
24
+ count++;
25
+ }
26
+ else {
27
+ break;
28
+ }
29
+ }
30
+ }
31
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
32
+ finally {
33
+ try {
34
+ if (str_1_1 && !str_1_1.done && (_a = str_1.return)) _a.call(str_1);
35
+ }
36
+ finally { if (e_1) throw e_1.error; }
37
+ }
38
+ return count;
39
+ }
40
+ /**
41
+ * @internal
42
+ */
43
+ function adjustListIndentation(listItem) {
44
+ var block = listItem.blocks[0];
45
+ if (block.blockType == 'Paragraph' &&
46
+ block.segments.length > 0 &&
47
+ block.segments[0].segmentType == 'Text') {
48
+ var tabSpaces_1 = countTabsSpaces(block.segments[0].text);
49
+ if (tabSpaces_1 > 0) {
50
+ (0, roosterjs_content_model_dom_1.mutateSegment)(block, block.segments[0], function (textSegment) {
51
+ textSegment.text = textSegment.text.substring(tabSpaces_1 * 4);
52
+ });
53
+ listItem.levels[0].format.marginLeft = tabSpaces_1 * exports.IndentStepInPixel + 'px';
54
+ }
55
+ }
56
+ }
57
+ exports.adjustListIndentation = adjustListIndentation;
58
+ /**
59
+ * @internal
60
+ */
61
+ function adjustTableIndentation(insertPoint, table) {
62
+ var paragraph = insertPoint.paragraph, marker = insertPoint.marker;
63
+ var indentationMargin = getTableIndentation(paragraph);
64
+ if (indentationMargin) {
65
+ insertPoint.paragraph.segments = [marker];
66
+ if (insertPoint.paragraph.format.direction == 'rtl') {
67
+ table.format.marginRight = indentationMargin * exports.IndentStepInPixel + 'px';
68
+ }
69
+ else {
70
+ table.format.marginLeft = indentationMargin * exports.IndentStepInPixel + 'px';
71
+ }
72
+ }
73
+ }
74
+ exports.adjustTableIndentation = adjustTableIndentation;
75
+ var getTableIndentation = function (paragraph) {
76
+ var e_2, _a;
77
+ var tabsNumber = 0;
78
+ var segments = paragraph.segments;
79
+ var isEmptyLine = paragraph.segments.every(function (s) {
80
+ return (s.segmentType == 'Text' && s.text.trim().length == 0) ||
81
+ s.segmentType == 'SelectionMarker' ||
82
+ s.segmentType == 'Br';
83
+ });
84
+ if (!isEmptyLine) {
85
+ return;
86
+ }
87
+ var numberOfSegments = 0;
88
+ try {
89
+ for (var segments_1 = (0, tslib_1.__values)(segments), segments_1_1 = segments_1.next(); !segments_1_1.done; segments_1_1 = segments_1.next()) {
90
+ var seg = segments_1_1.value;
91
+ if (seg.segmentType === 'Text') {
92
+ tabsNumber = tabsNumber + countTabsSpaces(seg.text);
93
+ numberOfSegments++;
94
+ }
95
+ else {
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
101
+ finally {
102
+ try {
103
+ if (segments_1_1 && !segments_1_1.done && (_a = segments_1.return)) _a.call(segments_1);
104
+ }
105
+ finally { if (e_2) throw e_2.error; }
106
+ }
107
+ // Text segments must be >= (total segments - 2) to apply margin.
108
+ // If not, the selection marker is likely between texts segment, so skip margin adjustment.
109
+ if (segments.length - 2 <= numberOfSegments) {
110
+ return tabsNumber;
111
+ }
112
+ return;
113
+ };
114
+ });
115
+ //# sourceMappingURL=adjustIndentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adjustIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/adjustIndentation.ts"],"names":[],"mappings":";;;;IAQA,IAAM,QAAQ,GAAG,QAAQ,CAAC;IAC1B,IAAM,aAAa,GAAG,QAAQ,CAAC;IAC/B,IAAM,gBAAgB,GAAG,QAAQ,CAAC;IAElC;;OAEG;IACU,QAAA,iBAAiB,GAAG,EAAE,CAAC;IAEpC,SAAS,eAAe,CAAC,IAAY;QACjC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,GAAG,qBAAA;gBACV,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,EAAE;oBAC5B,UAAU,GAAG,UAAU,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;oBACpD,gBAAgB,EAAE,CAAC;iBACtB;qBAAM;oBACH,MAAM;iBACT;aACJ;;;;;;;;;QAED,iEAAiE;QACjE,4FAA4F;QAC5F,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,gBAAgB,EAAE;YACzC,OAAO,UAAU,CAAC;SACrB;QAED,OAAO;IACX,CAAC,CAAC","sourcesContent":["import { mutateSegment } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelTable,\n InsertPoint,\n ShallowMutableContentModelListItem,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\nconst EN_SPACE = '\\u2002';\nconst REGULAR_SPACE = '\\u0020';\nconst NON_BREAK_SPACES = '\\u00A0';\n\n/**\n * @internal\n */\nexport const IndentStepInPixel = 40;\n\nfunction countTabsSpaces(text: string) {\n const spaces = countSpacesBeforeText(text);\n const tabSpaces = Math.floor(spaces / 4);\n return tabSpaces;\n}\n\nfunction countSpacesBeforeText(str: string) {\n let count = 0;\n for (const char of str) {\n if (char === EN_SPACE || char === NON_BREAK_SPACES || char == REGULAR_SPACE) {\n count++;\n } else {\n break;\n }\n }\n return count;\n}\n\n/**\n * @internal\n */\nexport function adjustListIndentation(listItem: ShallowMutableContentModelListItem) {\n const block = listItem.blocks[0];\n if (\n block.blockType == 'Paragraph' &&\n block.segments.length > 0 &&\n block.segments[0].segmentType == 'Text'\n ) {\n const tabSpaces = countTabsSpaces(block.segments[0].text);\n\n if (tabSpaces > 0) {\n mutateSegment(block, block.segments[0], textSegment => {\n textSegment.text = textSegment.text.substring(tabSpaces * 4);\n });\n listItem.levels[0].format.marginLeft = tabSpaces * IndentStepInPixel + 'px';\n }\n }\n}\n\n/**\n * @internal\n */\nexport function adjustTableIndentation(insertPoint: InsertPoint, table: ContentModelTable) {\n const { paragraph, marker } = insertPoint;\n const indentationMargin = getTableIndentation(paragraph);\n\n if (indentationMargin) {\n insertPoint.paragraph.segments = [marker];\n if (insertPoint.paragraph.format.direction == 'rtl') {\n table.format.marginRight = indentationMargin * IndentStepInPixel + 'px';\n } else {\n table.format.marginLeft = indentationMargin * IndentStepInPixel + 'px';\n }\n }\n}\n\nconst getTableIndentation = (paragraph: ShallowMutableContentModelParagraph) => {\n let tabsNumber = 0;\n const segments = paragraph.segments;\n\n const isEmptyLine = paragraph.segments.every(\n s =>\n (s.segmentType == 'Text' && s.text.trim().length == 0) ||\n s.segmentType == 'SelectionMarker' ||\n s.segmentType == 'Br'\n );\n\n if (!isEmptyLine) {\n return;\n }\n\n let numberOfSegments = 0;\n for (const seg of segments) {\n if (seg.segmentType === 'Text') {\n tabsNumber = tabsNumber + countTabsSpaces(seg.text);\n numberOfSegments++;\n } else {\n break;\n }\n }\n\n // Text segments must be >= (total segments - 2) to apply margin.\n // If not, the selection marker is likely between texts segment, so skip margin adjustment.\n if (segments.length - 2 <= numberOfSegments) {\n return tabsNumber;\n }\n\n return;\n};\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "../block/splitSelectedParagraphByBr", "roosterjs-content-model-dom"], function (require, exports, splitSelectedParagraphByBr_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "../common/adjustIndentation", "../block/splitSelectedParagraphByBr", "roosterjs-content-model-dom"], function (require, exports, adjustIndentation_1, splitSelectedParagraphByBr_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.setListType = void 0;
@@ -28,6 +28,11 @@ define(["require", "exports", "../block/splitSelectedParagraphByBr", "roosterjs-
28
28
  var level = block.levels.pop();
29
29
  if (!alreadyInExpectedType && level) {
30
30
  level.listType = listType;
31
+ (0, roosterjs_content_model_dom_1.updateListMetadata)(level, function (metadata) {
32
+ return Object.assign({}, metadata, {
33
+ applyListStyleFromLevel: true,
34
+ });
35
+ });
31
36
  block.levels.push(level);
32
37
  }
33
38
  else if (block.blocks.length == 1) {
@@ -71,6 +76,7 @@ define(["require", "exports", "../block/splitSelectedParagraphByBr", "roosterjs-
71
76
  }
72
77
  var mutableBlock = (0, roosterjs_content_model_dom_1.mutateBlock)(block);
73
78
  newListItem.blocks.push(mutableBlock);
79
+ (0, adjustIndentation_1.adjustListIndentation)(newListItem);
74
80
  (0, roosterjs_content_model_dom_1.copyFormat)(newListItem.format, mutableBlock.format, roosterjs_content_model_dom_1.ListFormatsToMove, true /*deleteOriginalFormat*/);
75
81
  (0, roosterjs_content_model_dom_1.copyFormat)(newListItem.format, mutableBlock.format, roosterjs_content_model_dom_1.ListFormatsToKeep);
76
82
  (0, roosterjs_content_model_dom_1.mutateBlock)(parent).blocks.splice(index, 1, newListItem);
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;;IAwBA;;;;;OAKG;IACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;QAA9B,8BAAA,EAAA,qBAA8B;QAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,EAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;SACpJ,CAAC;QACF,IAAM,qBAAqB,GAAG,oBAAoB,CAAC,KAAK,CAAC,UAAC,EAAS;;gBAAP,KAAK,WAAA;YAC7D,OAAA,IAAA,gDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC;gBACvD,CAAC,CAAC,CAAA,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,QAAQ,KAAI,QAAQ;gBAC7D,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA;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AAI,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAA3D,CAA2D,CACnE,CAAC;YACN;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ContentModelListItem,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n [] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any\n );\n const alreadyInExpectedType = paragraphOrListItems.every(({ block }) =>\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const level = block.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n block.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n\n if (index >= 0) {\n if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;;IAyBA;;;;;OAKG;IACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;QAA9B,8BAAA,EAAA,qBAA8B;QAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,EAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;SACpJ,CAAC;QACF,IAAM,qBAAqB,GAAG,oBAAoB,CAAC,KAAK,CAAC,UAAC,EAAS;;gBAAP,KAAK,WAAA;YAC7D,OAAA,IAAA,gDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC;gBACvD,CAAC,CAAC,CAAA,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,QAAQ,KAAI,QAAQ;gBAC7D,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA;SAAA,CACjC,CAAC;QACF,IAAI,iBAAiB,GAAmC,EAAE,CAAC;QAE3D,oBAAoB,CAAC,OAAO,CAAC,UAAC,EAAiB,EAAE,SAAS;;gBAA1B,KAAK,WAAA,EAAE,MAAM,YAAA;YACzC,IAAI,IAAA,gDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;gBAEjC,IAAI,CAAC,qBAAqB,IAAI,KAAK,EAAE;oBACjC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;oBAE1B,IAAA,gDAAkB,EAAC,KAAK,EAAE,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,CAAC,CAAC;wBAEpC,IAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;wBACjD,IAAM,KAAK,GAAG,IAAA,yCAAW,EAAC,WAAW,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;wBAE1D,IAAI,KAAK,EAAE;4BACP,IAAA,gDAAkB,EAAC,KAAK,EAAE,UAAA,QAAQ;gCAC9B,OAAA,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE;oCACxB,uBAAuB,EAAE,IAAI;iCAChC,CAAC;4BAFF,CAEE,CACL,CAAC;yBACL;qBACJ;yBAAM;wBACH,iBAAiB,CAAC,OAAO,CACrB,UAAA,CAAC,IAAI,OAAA,CAAC,IAAA,yCAAW,EAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;wBACF,iBAAiB,GAAG,EAAE,CAAC;qBAC1B;iBACJ;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3C,CAAC;IA3HD,kCA2HC;IAED,SAAS,iBAAiB,CAAC,KAAgC;QACvD,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK,OAAO;gBACR,OAAO,KAAK,CAAC;YACjB,KAAK,WAAW;gBACZ,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CACvB,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAA3D,CAA2D,CACnE,CAAC;YACN;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ContentModelListItem,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n [] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any\n );\n const alreadyInExpectedType = paragraphOrListItems.every(({ block }) =>\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const level = block.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n block.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n\n if (index >= 0) {\n if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
@@ -2,6 +2,6 @@ import type { IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Set text direction of selected paragraphs (Left to right or Right to left)
4
4
  * @param editor The editor to set alignment
5
- * @param direction Direction value: ltr (Left to right) or rtl (Right to left)
5
+ * @param direction Direction value: ltr (Left to right) or rtl (Right to left), or 'auto' (Based on the first characters of the document, set the direction automatically)
6
6
  */
7
- export declare function setDirection(editor: IEditor, direction: 'ltr' | 'rtl'): void;
7
+ export declare function setDirection(editor: IEditor, direction: 'ltr' | 'rtl' | 'auto'): void;
@@ -5,7 +5,7 @@ define(["require", "exports", "../../modelApi/block/setModelDirection"], functio
5
5
  /**
6
6
  * Set text direction of selected paragraphs (Left to right or Right to left)
7
7
  * @param editor The editor to set alignment
8
- * @param direction Direction value: ltr (Left to right) or rtl (Right to left)
8
+ * @param direction Direction value: ltr (Left to right) or rtl (Right to left), or 'auto' (Based on the first characters of the document, set the direction automatically)
9
9
  */
10
10
  function setDirection(editor, direction) {
11
11
  editor.focus();
@@ -1 +1 @@
1
- {"version":3,"file":"setDirection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/block/setDirection.ts"],"names":[],"mappings":";;;;IAGA;;;;OAIG;IACH,SAAgB,YAAY,CAAC,MAAe,EAAE,SAAwB;QAClE,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,CAAC,kBAAkB,CAAC,UAAA,KAAK,IAAI,OAAA,IAAA,qCAAiB,EAAC,KAAK,EAAE,SAAS,CAAC,EAAnC,CAAmC,EAAE;YACpE,OAAO,EAAE,cAAc;SAC1B,CAAC,CAAC;IACP,CAAC;IAND,oCAMC","sourcesContent":["import { setModelDirection } from '../../modelApi/block/setModelDirection';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Set text direction of selected paragraphs (Left to right or Right to left)\n * @param editor The editor to set alignment\n * @param direction Direction value: ltr (Left to right) or rtl (Right to left)\n */\nexport function setDirection(editor: IEditor, direction: 'ltr' | 'rtl') {\n editor.focus();\n\n editor.formatContentModel(model => setModelDirection(model, direction), {\n apiName: 'setDirection',\n });\n}\n"]}
1
+ {"version":3,"file":"setDirection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/block/setDirection.ts"],"names":[],"mappings":";;;;IAGA;;;;OAIG;IACH,SAAgB,YAAY,CAAC,MAAe,EAAE,SAAiC;QAC3E,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,CAAC,kBAAkB,CAAC,UAAA,KAAK,IAAI,OAAA,IAAA,qCAAiB,EAAC,KAAK,EAAE,SAAS,CAAC,EAAnC,CAAmC,EAAE;YACpE,OAAO,EAAE,cAAc;SAC1B,CAAC,CAAC;IACP,CAAC;IAND,oCAMC","sourcesContent":["import { setModelDirection } from '../../modelApi/block/setModelDirection';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Set text direction of selected paragraphs (Left to right or Right to left)\n * @param editor The editor to set alignment\n * @param direction Direction value: ltr (Left to right) or rtl (Right to left), or 'auto' (Based on the first characters of the document, set the direction automatically)\n */\nexport function setDirection(editor: IEditor, direction: 'ltr' | 'rtl' | 'auto') {\n editor.focus();\n\n editor.formatContentModel(model => setModelDirection(model, direction), {\n apiName: 'setDirection',\n });\n}\n"]}
@@ -17,7 +17,7 @@ define(["require", "exports", "../../modelApi/common/reducedModelChildProcessor"
17
17
  isDarkMode: editor.isDarkMode(),
18
18
  };
19
19
  editor.formatContentModel(function (model) {
20
- (0, roosterjs_content_model_dom_1.retrieveModelFormatState)(model, pendingFormat, result, conflictSolution, editor.getDOMHelper());
20
+ (0, roosterjs_content_model_dom_1.retrieveModelFormatState)(model, pendingFormat, result, conflictSolution, editor.getDOMHelper(), editor.isDarkMode(), editor.getColorManager());
21
21
  return false;
22
22
  }, undefined /*options*/, {
23
23
  processorOverride: {
@@ -1 +1 @@
1
- {"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":";;;;IAQA;;;;OAIG;IACH,SAAgB,cAAc,CAC1B,MAAe,EACf,gBAAmD;QAAnD,iCAAA,EAAA,2BAAmD;QAEnD,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAChD,IAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAC7C,IAAM,MAAM,GAA4B;YACpC,OAAO,EAAE,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACrD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;YAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;SAClC,CAAC;QAEF,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;YACD,IAAA,sDAAwB,EACpB,KAAK,EACL,aAAa,EACb,MAAM,EACN,gBAAgB,EAChB,MAAM,CAAC,YAAY,EAAE,CACxB,CAAC;YAEF,OAAO,KAAK,CAAC;QACjB,CAAC,EACD,SAAS,CAAC,WAAW,EACrB;YACI,iBAAiB,EAAE;gBACf,KAAK,EAAE,uDAA0B;aACpC;YACD,eAAe,EAAE,IAAI;SACxB,CACJ,CAAC;QAEF,OAAO,MAAM,CAAC;IAClB,CAAC;IAlCD,wCAkCC","sourcesContent":["import { reducedModelChildProcessor } from '../../modelApi/common/reducedModelChildProcessor';\nimport { retrieveModelFormatState } from 'roosterjs-content-model-dom';\nimport type {\n IEditor,\n ContentModelFormatState,\n ConflictFormatSolution,\n} from 'roosterjs-content-model-types';\n\n/**\n * Get current format state\n * @param editor The editor to get format from\n * @param conflictSolution The strategy for handling format conflicts\n */\nexport function getFormatState(\n editor: IEditor,\n conflictSolution: ConflictFormatSolution = 'remove'\n): ContentModelFormatState {\n const pendingFormat = editor.getPendingFormat();\n const manager = editor.getSnapshotsManager();\n const result: ContentModelFormatState = {\n canUndo: manager.hasNewContent || manager.canMove(-1),\n canRedo: manager.canMove(1),\n isDarkMode: editor.isDarkMode(),\n };\n\n editor.formatContentModel(\n model => {\n retrieveModelFormatState(\n model,\n pendingFormat,\n result,\n conflictSolution,\n editor.getDOMHelper()\n );\n\n return false;\n },\n undefined /*options*/,\n {\n processorOverride: {\n child: reducedModelChildProcessor,\n },\n tryGetFromCache: true,\n }\n );\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":";;;;IAQA;;;;OAIG;IACH,SAAgB,cAAc,CAC1B,MAAe,EACf,gBAAmD;QAAnD,iCAAA,EAAA,2BAAmD;QAEnD,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAChD,IAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAC7C,IAAM,MAAM,GAA4B;YACpC,OAAO,EAAE,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACrD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;YAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;SAClC,CAAC;QAEF,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;YACD,IAAA,sDAAwB,EACpB,KAAK,EACL,aAAa,EACb,MAAM,EACN,gBAAgB,EAChB,MAAM,CAAC,YAAY,EAAE,EACrB,MAAM,CAAC,UAAU,EAAE,EACnB,MAAM,CAAC,eAAe,EAAE,CAC3B,CAAC;YAEF,OAAO,KAAK,CAAC;QACjB,CAAC,EACD,SAAS,CAAC,WAAW,EACrB;YACI,iBAAiB,EAAE;gBACf,KAAK,EAAE,uDAA0B;aACpC;YACD,eAAe,EAAE,IAAI;SACxB,CACJ,CAAC;QAEF,OAAO,MAAM,CAAC;IAClB,CAAC;IApCD,wCAoCC","sourcesContent":["import { reducedModelChildProcessor } from '../../modelApi/common/reducedModelChildProcessor';\nimport { retrieveModelFormatState } from 'roosterjs-content-model-dom';\nimport type {\n IEditor,\n ContentModelFormatState,\n ConflictFormatSolution,\n} from 'roosterjs-content-model-types';\n\n/**\n * Get current format state\n * @param editor The editor to get format from\n * @param conflictSolution The strategy for handling format conflicts\n */\nexport function getFormatState(\n editor: IEditor,\n conflictSolution: ConflictFormatSolution = 'remove'\n): ContentModelFormatState {\n const pendingFormat = editor.getPendingFormat();\n const manager = editor.getSnapshotsManager();\n const result: ContentModelFormatState = {\n canUndo: manager.hasNewContent || manager.canMove(-1),\n canRedo: manager.canMove(1),\n isDarkMode: editor.isDarkMode(),\n };\n\n editor.formatContentModel(\n model => {\n retrieveModelFormatState(\n model,\n pendingFormat,\n result,\n conflictSolution,\n editor.getDOMHelper(),\n editor.isDarkMode(),\n editor.getColorManager()\n );\n\n return false;\n },\n undefined /*options*/,\n {\n processorOverride: {\n child: reducedModelChildProcessor,\n },\n tryGetFromCache: true,\n }\n );\n\n return result;\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "../../modelApi/table/createTableStructure", "roosterjs-content-model-dom"], function (require, exports, createTableStructure_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "../../modelApi/common/adjustIndentation", "../../modelApi/table/createTableStructure", "roosterjs-content-model-dom"], function (require, exports, adjustIndentation_1, createTableStructure_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.insertTable = void 0;
@@ -20,6 +20,7 @@ define(["require", "exports", "../../modelApi/table/createTableStructure", "roos
20
20
  var doc = (0, roosterjs_content_model_dom_1.createContentModelDocument)();
21
21
  var table = (0, createTableStructure_1.createTableStructure)(doc, columns, rows);
22
22
  (0, roosterjs_content_model_dom_1.normalizeTable)(table, editor.getPendingFormat() || insertPosition.marker.format);
23
+ (0, adjustIndentation_1.adjustTableIndentation)(insertPosition, table);
23
24
  // Assign default vertical align
24
25
  format = format || { verticalAlign: 'top' };
25
26
  (0, roosterjs_content_model_dom_1.applyTableFormat)(table, format);
@@ -1 +1 @@
1
- {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;;IAYA;;;;;;;;OAQG;IACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,MAAqC;QAErC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,cAAc,GAAG,IAAA,6CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;YAEvE,IAAI,cAAc,EAAE;gBAChB,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;gBACzC,IAAM,KAAK,GAAG,IAAA,2CAAoB,EAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;gBAEvD,IAAA,4CAAc,EAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBACjF,gCAAgC;gBAChC,MAAM,GAAG,MAAM,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;gBAC5C,IAAA,8CAAgB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAChC,IAAA,wCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;oBAC5B,cAAc,gBAAA;oBACd,WAAW,EAAE,UAAU;iBAC1B,CAAC,CAAC;gBAEH,IAAM,UAAU,GAAG,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;gBAEtD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;oBACtC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;oBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACpC,IAAA,0CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;iBAC/B;gBAED,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,OAAO,EAAE,aAAa;SACzB,CACJ,CAAC;IACN,CAAC;IA1CD,kCA0CC","sourcesContent":["import { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param format (Optional) The table format. If not passed, the default format will be applied:\n * background color: #FFF; border color: #ABABAB\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n format?: Partial<TableMetadataFormat>\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n // Assign default vertical align\n format = format || { verticalAlign: 'top' };\n applyTableFormat(table, format);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;;IAaA;;;;;;;;OAQG;IACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,MAAqC;QAErC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,cAAc,GAAG,IAAA,6CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;YAEvE,IAAI,cAAc,EAAE;gBAChB,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;gBACzC,IAAM,KAAK,GAAG,IAAA,2CAAoB,EAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;gBAEvD,IAAA,4CAAc,EAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAEjF,IAAA,0CAAsB,EAAC,cAAc,EAAE,KAAK,CAAC,CAAC;gBAE9C,gCAAgC;gBAChC,MAAM,GAAG,MAAM,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;gBAC5C,IAAA,8CAAgB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAChC,IAAA,wCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;oBAC5B,cAAc,gBAAA;oBACd,WAAW,EAAE,UAAU;iBAC1B,CAAC,CAAC;gBAEH,IAAM,UAAU,GAAG,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;gBAEtD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;oBACtC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;oBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACpC,IAAA,0CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;iBAC/B;gBAED,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,OAAO,EAAE,aAAa;SACzB,CACJ,CAAC;IACN,CAAC;IA7CD,kCA6CC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param format (Optional) The table format. If not passed, the default format will be applied:\n * background color: #FFF; border color: #ABABAB\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n format?: Partial<TableMetadataFormat>\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n format = format || { verticalAlign: 'top' };\n applyTableFormat(table, format);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
@@ -2,4 +2,4 @@ import type { ReadonlyContentModelDocument } from 'roosterjs-content-model-types
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare function setModelDirection(model: ReadonlyContentModelDocument, direction: 'ltr' | 'rtl'): boolean;
5
+ export declare function setModelDirection(model: ReadonlyContentModelDocument, direction: 'ltr' | 'rtl' | 'auto'): boolean;
@@ -1,6 +1,11 @@
1
1
  import { findListItemsInSameThread } from '../list/findListItemsInSameThread';
2
2
  import { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';
3
3
  import { applyTableFormat, getOperationalBlocks, isBlockGroupOfType, mutateBlock, updateTableCellMetadata, } from 'roosterjs-content-model-dom';
4
+ // Regexes for character direction detection
5
+ // Strongly typed RTL character ranges. Referenced unicode's DerivedBidiClass.txt, excluding things in the 2 bit range.
6
+ var RTL_CHAR_REGEX = /[\u0590-\u05FF\u0600-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/g;
7
+ var URL_CHAR_REGEX = /http\S+|www\S+|https\S+|<a\s+(?:[^>]*?\s+)?href=(["']).*?\1.*?>.*?<\/a>/g;
8
+ var WHITESPACE_REGEX = /\s/g;
4
9
  /**
5
10
  * @internal
6
11
  */
@@ -9,18 +14,25 @@ export function setModelDirection(model, direction) {
9
14
  var paragraphOrListItemOrTable = getOperationalBlocks(model, ['ListItem'], ['TableCell']);
10
15
  paragraphOrListItemOrTable.forEach(function (_a) {
11
16
  var block = _a.block;
17
+ var calcDirection;
18
+ if (direction === 'auto') {
19
+ calcDirection = determineTextDirection(block);
20
+ }
21
+ else {
22
+ calcDirection = direction;
23
+ }
12
24
  if (isBlockGroupOfType(block, 'ListItem')) {
13
25
  var items = findListItemsInSameThread(model, block);
14
26
  items.forEach(function (readonlyItem) {
15
27
  var item = mutateBlock(readonlyItem);
16
28
  item.levels.forEach(function (level) {
17
- level.format.direction = direction;
29
+ level.format.direction = calcDirection;
18
30
  });
19
- item.blocks.forEach(function (block) { return internalSetDirection(block, direction); });
31
+ item.blocks.forEach(function (block) { return internalSetDirection(block, calcDirection); });
20
32
  });
21
33
  }
22
34
  else if (block) {
23
- internalSetDirection(block, direction);
35
+ internalSetDirection(block, calcDirection);
24
36
  }
25
37
  });
26
38
  return paragraphOrListItemOrTable.length > 0;
@@ -66,4 +78,29 @@ function setProperty(format, key, value) {
66
78
  delete format[key];
67
79
  }
68
80
  }
81
+ // Designed to match browser's 'auto' detection, by scanning over the inner text until it hits a strong LTR/RTL character
82
+ function determineTextDirection(block) {
83
+ if (block.blockType === 'Paragraph') {
84
+ var findTextSegements = block.segments.filter(function (seg) { return seg.segmentType === 'Text'; });
85
+ var innerText = findTextSegements.length > 0
86
+ ? findTextSegements.reduce(function (prev, seg) { return prev + seg.text; }, '')
87
+ : undefined;
88
+ if (!!innerText) {
89
+ // Remove links
90
+ innerText = innerText.replace(URL_CHAR_REGEX, '');
91
+ // Remove whitespace
92
+ innerText = innerText.replace(WHITESPACE_REGEX, '');
93
+ var rtlMatches = innerText.match(RTL_CHAR_REGEX);
94
+ var rtlCount = rtlMatches ? rtlMatches.length : 0;
95
+ var ltrCount = innerText.length - rtlCount;
96
+ return rtlCount > ltrCount ? 'rtl' : 'ltr';
97
+ }
98
+ else {
99
+ return 'ltr'; // Default to LTR if no text is found
100
+ }
101
+ }
102
+ else {
103
+ return 'ltr';
104
+ }
105
+ }
69
106
  //# sourceMappingURL=setModelDirection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api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CAAC,CAAC;yBAC5D;wBACD,OAAO,QAAQ,CAAC;oBACpB,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YAEH,wBAAwB;YACxB,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;SAC/E;KACJ;AACL,CAAC;AAED,SAAS,WAAW,CAChB,MAAmD,EACnD,GAAwD,EACxD,KAAyB;IAEzB,IAAI,KAAK,EAAE;QACP,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;KACvB;SAAM;QACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACtB;AACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';\nimport {\n applyTableFormat,\n getOperationalBlocks,\n isBlockGroupOfType,\n mutateBlock,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n BorderFormat,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setModelDirection(model: ReadonlyContentModelDocument, direction: 'ltr' | 'rtl') {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(readonlyItem => {\n const item = mutateBlock(readonlyItem);\n\n item.levels.forEach(level => {\n level.format.direction = direction;\n });\n\n item.blocks.forEach(block => internalSetDirection(block, direction));\n });\n } else if (block) {\n internalSetDirection(block, direction);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(block: ReadonlyContentModelBlock, direction: 'ltr' | 'rtl') {\n const wasRtl = block.format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n const { format } = mutateBlock(block);\n format.direction = direction;\n\n // Adjust margin when change direction\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n\n // If whole Table direction changed, flip cell side borders\n if (block && block.blockType == 'Table') {\n block.rows.forEach(row => {\n row.cells.forEach(cell => {\n // Optimise by skipping cells with unchanged borders\n updateTableCellMetadata(mutateBlock(cell), metadata => {\n if (metadata?.borderOverride) {\n const storeBorderLeft = cell.format.borderLeft;\n setProperty(cell.format, 'borderLeft', cell.format.borderRight);\n setProperty(cell.format, 'borderRight', storeBorderLeft);\n }\n return metadata;\n });\n });\n });\n\n // Apply changed borders\n applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);\n }\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat & BorderFormat,\n key: keyof (MarginFormat & PaddingFormat & BorderFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n"]}
1
+ {"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EACH,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,uBAAuB,GAC1B,MAAM,6BAA6B,CAAC;AAWrC,4CAA4C;AAC5C,uHAAuH;AACvH,IAAM,cAAc,GAAG,yDAAyD,CAAC;AACjF,IAAM,cAAc,GAAG,0EAA0E,CAA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;YAEpD,IAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;YAE7C,OAAO,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;SAC9C;aAAM;YACH,OAAO,KAAK,CAAC,CAAC,qCAAqC;SACtD;KACJ;SAAM;QACH,OAAO,KAAK,CAAC;KAChB;AACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';\nimport {\n applyTableFormat,\n getOperationalBlocks,\n isBlockGroupOfType,\n mutateBlock,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n BorderFormat,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelText,\n} from 'roosterjs-content-model-types';\n\n// Regexes for character direction detection\n// Strongly typed RTL character ranges. Referenced unicode's DerivedBidiClass.txt, excluding things in the 2 bit range.\nconst RTL_CHAR_REGEX = /[\\u0590-\\u05FF\\u0600-\\u08FF\\uFB1D-\\uFDFF\\uFE70-\\uFEFF]/g;\nconst URL_CHAR_REGEX = /http\\S+|www\\S+|https\\S+|<a\\s+(?:[^>]*?\\s+)?href=([\"']).*?\\1.*?>.*?<\\/a>/g;\nconst WHITESPACE_REGEX = /\\s/g;\n\n/**\n * @internal\n */\nexport function setModelDirection(\n model: ReadonlyContentModelDocument,\n direction: 'ltr' | 'rtl' | 'auto'\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n let calcDirection: 'ltr' | 'rtl';\n if (direction === 'auto') {\n calcDirection = determineTextDirection(block);\n } else {\n calcDirection = direction;\n }\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(readonlyItem => {\n const item = mutateBlock(readonlyItem);\n\n item.levels.forEach(level => {\n level.format.direction = calcDirection;\n });\n\n item.blocks.forEach(block => internalSetDirection(block, calcDirection));\n });\n } else if (block) {\n internalSetDirection(block, calcDirection);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(block: ReadonlyContentModelBlock, direction: 'ltr' | 'rtl') {\n const wasRtl = block.format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n const { format } = mutateBlock(block);\n format.direction = direction;\n\n // Adjust margin when change direction\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n\n // If whole Table direction changed, flip cell side borders\n if (block && block.blockType == 'Table') {\n block.rows.forEach(row => {\n row.cells.forEach(cell => {\n // Optimise by skipping cells with unchanged borders\n updateTableCellMetadata(mutateBlock(cell), metadata => {\n if (metadata?.borderOverride) {\n const storeBorderLeft = cell.format.borderLeft;\n setProperty(cell.format, 'borderLeft', cell.format.borderRight);\n setProperty(cell.format, 'borderRight', storeBorderLeft);\n }\n return metadata;\n });\n });\n });\n\n // Apply changed borders\n applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);\n }\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat & BorderFormat,\n key: keyof (MarginFormat & PaddingFormat & BorderFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n\n// Designed to match browser's 'auto' detection, by scanning over the inner text until it hits a strong LTR/RTL character\nfunction determineTextDirection(block: ReadonlyContentModelBlock): 'ltr' | 'rtl' {\n if (block.blockType === 'Paragraph') {\n const findTextSegements: ReadonlyContentModelText[] = block.segments.filter(\n (seg): seg is ReadonlyContentModelText => seg.segmentType === 'Text'\n );\n let innerText =\n findTextSegements.length > 0\n ? findTextSegements.reduce((prev, seg) => prev + seg.text, '')\n : undefined;\n if (!!innerText) {\n // Remove links\n innerText = innerText.replace(URL_CHAR_REGEX, '');\n\n // Remove whitespace\n innerText = innerText.replace(WHITESPACE_REGEX, '');\n\n const rtlMatches = innerText.match(RTL_CHAR_REGEX);\n const rtlCount = rtlMatches ? rtlMatches.length : 0;\n\n const ltrCount = innerText.length - rtlCount;\n\n return rtlCount > ltrCount ? 'rtl' : 'ltr';\n } else {\n return 'ltr'; // Default to LTR if no text is found\n }\n } else {\n return 'ltr';\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import { __read, __spreadArray } from "tslib";
2
2
  import { findListItemsInSameThread } from '../list/findListItemsInSameThread';
3
3
  import { getListAnnounceData } from '../list/getListAnnounceData';
4
+ import { IndentStepInPixel } from '../common/adjustIndentation';
4
5
  import { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';
5
6
  import { createListLevel, getOperationalBlocks, isBlockGroupOfType, mutateBlock, parseValueWithUnit, updateListMetadata, } from 'roosterjs-content-model-dom';
6
- var IndentStepInPixel = 40;
7
7
  /**
8
8
  * @param model The content model to set indentation
9
9
  * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent