roosterjs-content-model-api 0.22.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 (67) hide show
  1. package/lib/modelApi/block/setModelAlignment.d.ts +1 -1
  2. package/lib/modelApi/block/setModelAlignment.js +13 -3
  3. package/lib/modelApi/block/setModelAlignment.js.map +1 -1
  4. package/lib/modelApi/block/setModelDirection.js +20 -3
  5. package/lib/modelApi/block/setModelDirection.js.map +1 -1
  6. package/lib/modelApi/common/retrieveModelFormatState.js +5 -3
  7. package/lib/modelApi/common/retrieveModelFormatState.js.map +1 -1
  8. package/lib/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
  9. package/lib/modelApi/selection/adjustTrailingSpaceSelection.js +56 -0
  10. package/lib/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
  11. package/lib/publicApi/block/setAlignment.d.ts +1 -1
  12. package/lib/publicApi/block/setAlignment.js.map +1 -1
  13. package/lib/publicApi/image/changeImage.js +1 -1
  14. package/lib/publicApi/image/changeImage.js.map +1 -1
  15. package/lib/publicApi/link/insertLink.js +2 -0
  16. package/lib/publicApi/link/insertLink.js.map +1 -1
  17. package/lib/publicApi/segment/toggleUnderline.js +2 -1
  18. package/lib/publicApi/segment/toggleUnderline.js.map +1 -1
  19. package/lib/publicApi/table/applyTableBorderFormat.js +18 -16
  20. package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
  21. package/lib/publicApi/utils/formatSegmentWithContentModel.js +2 -7
  22. package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  23. package/lib-amd/modelApi/block/setModelAlignment.d.ts +1 -1
  24. package/lib-amd/modelApi/block/setModelAlignment.js +13 -3
  25. package/lib-amd/modelApi/block/setModelAlignment.js.map +1 -1
  26. package/lib-amd/modelApi/block/setModelDirection.js +20 -3
  27. package/lib-amd/modelApi/block/setModelDirection.js.map +1 -1
  28. package/lib-amd/modelApi/common/retrieveModelFormatState.js +5 -4
  29. package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +1 -1
  30. package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
  31. package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js +55 -0
  32. package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
  33. package/lib-amd/publicApi/block/setAlignment.d.ts +1 -1
  34. package/lib-amd/publicApi/block/setAlignment.js.map +1 -1
  35. package/lib-amd/publicApi/image/changeImage.js +1 -1
  36. package/lib-amd/publicApi/image/changeImage.js.map +1 -1
  37. package/lib-amd/publicApi/link/insertLink.js +2 -1
  38. package/lib-amd/publicApi/link/insertLink.js.map +1 -1
  39. package/lib-amd/publicApi/segment/toggleUnderline.js +2 -2
  40. package/lib-amd/publicApi/segment/toggleUnderline.js.map +1 -1
  41. package/lib-amd/publicApi/table/applyTableBorderFormat.js +18 -16
  42. package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
  43. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +2 -7
  44. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  45. package/lib-mjs/modelApi/block/setModelAlignment.d.ts +1 -1
  46. package/lib-mjs/modelApi/block/setModelAlignment.js +13 -3
  47. package/lib-mjs/modelApi/block/setModelAlignment.js.map +1 -1
  48. package/lib-mjs/modelApi/block/setModelDirection.js +21 -4
  49. package/lib-mjs/modelApi/block/setModelDirection.js.map +1 -1
  50. package/lib-mjs/modelApi/common/retrieveModelFormatState.js +5 -3
  51. package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +1 -1
  52. package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
  53. package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js +52 -0
  54. package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
  55. package/lib-mjs/publicApi/block/setAlignment.d.ts +1 -1
  56. package/lib-mjs/publicApi/block/setAlignment.js.map +1 -1
  57. package/lib-mjs/publicApi/image/changeImage.js +1 -1
  58. package/lib-mjs/publicApi/image/changeImage.js.map +1 -1
  59. package/lib-mjs/publicApi/link/insertLink.js +2 -0
  60. package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
  61. package/lib-mjs/publicApi/segment/toggleUnderline.js +2 -1
  62. package/lib-mjs/publicApi/segment/toggleUnderline.js.map +1 -1
  63. package/lib-mjs/publicApi/table/applyTableBorderFormat.js +18 -16
  64. package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
  65. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +2 -7
  66. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  67. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";;;IAUA,4BAA4B;IAC5B,IAAM,SAAS,GAAG,cAAc,CAAC;IACjC,wCAAwC;IACxC,IAAM,YAAY,GAAG,cAAc,CAAC;IACpC,sDAAsD;IACtD,IAAM,SAAS,GAAG,SAAS,CAAC;IAE5B;;;;;;;;;;;;OAYG;IACH,SAAwB,UAAU,CAC9B,MAAyB,EACzB,IAAY,EACZ,WAAoB,EACpB,WAAoB,EACpB,MAAe;QAEf,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1C,IAAI,GAAG,EAAE;YACL,IAAM,UAAQ,GAAG,IAAA,gCAAS,EAAC,GAAG,CAAC,CAAC;YAChC,IAAM,SAAO,GAAG,UAAQ,CAAC,CAAC,CAAC,UAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YACzE,IAAM,OAAK,GAAuB,EAAE,CAAC;YACrC,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ACN,SAAS,EAAE,SAAS;aACvB;SACJ,CAAC;IACN,CAAC,CAAC;IAEF,uGAAuG;IACvG,SAAS,eAAe,CAAC,GAAW;QAChC,IAAI,CAAC,GAAG,EAAE;YACN,OAAO,GAAG,CAAC;SACd;QAED,4BAA4B;QAC5B,oEAAoE;QACpE,iEAAiE;QACjE,qDAAqD;QACrD,+BAA+B;QAC/B,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;YAC3B,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;gBAC/B,MAAM,GAAG,SAAS,CAAC;aACtB;iBAAM,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBACnC,MAAM,GAAG,QAAQ,CAAC;aACrB;iBAAM;gBACH,sBAAsB;gBACtB,MAAM,GAAG,SAAS,CAAC;aACtB;SACJ;QAED,OAAO,MAAM,GAAG,GAAG,CAAC;IACxB,CAAC;IAED,wGAAwG;IACxG,yDAAyD;IACzD,SAAS,QAAQ,CAAC,IAAY;QAC1B,IAAM,SAAS,GAAG,IAAI,oCAAa,EAAE,CAAC;QACtC,IAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAEtC,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAEpB,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACtB,6FAA6F;QAC7F,mEAAmE;QACnE,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACxC,CAAC","sourcesContent":["import { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';\nimport { HtmlSanitizer, matchLink } from 'roosterjs-editor-dom';\nimport type { ContentModelLink, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n addLink,\n addSegment,\n createContentModelDocument,\n createText,\n} from 'roosterjs-content-model-dom';\n\n// Regex matching Uri scheme\nconst URI_REGEX = /^[a-zA-Z]+:/i;\n// Regex matching begin of email address\nconst MAILTO_REGEX = /^[\\w.%+-]+@/i;\n// Regex matching begin of ftp, i.e. ftp.microsoft.com\nconst FTP_REGEX = /^ftp\\./i;\n\n/**\n * Insert a hyperlink at cursor.\n * When there is a selection, hyperlink will be applied to the selection,\n * otherwise a hyperlink will be inserted to the cursor position.\n * @param editor Editor object\n * @param link Link address, can be http(s), mailto, notes, file, unc, ftp, news, telnet, gopher, wais.\n * When protocol is not specified, a best matched protocol will be predicted.\n * @param anchorTitle Optional alt text of the link, will be shown when hover on the link\n * @param displayText Optional display text for the link.\n * @param target Optional display target for the link (\"_blank\"|\"_self\"|\"_parent\"|\"_top\"|\"{framename}\")\n * If specified, the display text of link will be replaced with this text.\n * If not specified and there wasn't a link, the link url will be used as display text.\n */\nexport default function insertLink(\n editor: IStandaloneEditor,\n link: string,\n anchorTitle?: string,\n displayText?: string,\n target?: string\n) {\n editor.focus();\n\n const url = (checkXss(link) || '').trim();\n if (url) {\n const linkData = matchLink(url);\n const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);\n const links: ContentModelLink[] = [];\n let anchorNode: Node | undefined;\n\n editor.formatContentModel(\n (model, context) => {\n const segments = getSelectedSegments(model, false /*includingFormatHolder*/);\n const originalText = segments\n .map(x => (x.segmentType == 'Text' ? x.text : ''))\n .join('');\n const text = displayText || originalText || '';\n\n if (\n segments.some(x => x.segmentType != 'SelectionMarker') &&\n originalText == text\n ) {\n segments.forEach(x => {\n const link = createLink(\n linkUrl,\n anchorTitle,\n target,\n x.segmentType == 'Text'\n );\n addLink(x, link);\n if (x.link) {\n links.push(x.link);\n }\n });\n } else if (\n segments.every(x => x.segmentType == 'SelectionMarker') ||\n (!!text && text != originalText)\n ) {\n const segment = createText(text || (linkData ? linkData.originalUrl : url), {\n ...segments[0]?.format,\n ...editor.getPendingFormat(),\n });\n const doc = createContentModelDocument();\n const link = createLink(linkUrl, anchorTitle, target);\n\n addLink(segment, link);\n addSegment(doc, segment);\n\n if (segment.link) {\n links.push(segment.link);\n }\n\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n }\n\n return segments.length > 0;\n },\n {\n changeSource: ChangeSource.CreateLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n apiName: 'insertLink',\n }\n );\n }\n}\n\nconst createLink = (\n url: string,\n anchorTitle?: string,\n target?: string,\n underline: boolean = true\n): ContentModelLink => {\n return {\n dataset: {},\n format: {\n href: url,\n anchorTitle,\n target,\n underline: underline,\n },\n };\n};\n\n// TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.\nfunction applyLinkPrefix(url: string): string {\n if (!url) {\n return url;\n }\n\n // Add link prefix per rule:\n // (a) if the url always starts with a URI scheme, leave it as it is\n // (b) if the url is an email address, xxx@... add mailto: prefix\n // (c) if the url starts with ftp., add ftp:// prefix\n // (d) rest, add http:// prefix\n let prefix = '';\n if (url.search(URI_REGEX) < 0) {\n if (url.search(MAILTO_REGEX) == 0) {\n prefix = 'mailto:';\n } else if (url.search(FTP_REGEX) == 0) {\n prefix = 'ftp://';\n } else {\n // fallback to http://\n prefix = 'http://';\n }\n }\n\n return prefix + url;\n}\n\n// TODO: This is copied from original code. However, ContentModel should be able to filter out malicious\n// attributes later, so no need to use HtmlSanitizer here\nfunction checkXss(link: string): string {\n const sanitizer = new HtmlSanitizer();\n const a = document.createElement('a');\n\n a.href = link || '';\n\n sanitizer.sanitize(a);\n // We use getAttribute because some browsers will try to make the href property a valid link.\n // This has unintended side effects when the link lacks a protocol.\n return a.getAttribute('href') || '';\n}\n"]}
1
+ {"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";;;IAWA,4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M;gBACH,sBAAsB;gBACtB,MAAM,GAAG,SAAS,CAAC;aACtB;SACJ;QAED,OAAO,MAAM,GAAG,GAAG,CAAC;IACxB,CAAC;IAED,wGAAwG;IACxG,yDAAyD;IACzD,SAAS,QAAQ,CAAC,IAAY;QAC1B,IAAM,SAAS,GAAG,IAAI,oCAAa,EAAE,CAAC;QACtC,IAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAEtC,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAEpB,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACtB,6FAA6F;QAC7F,mEAAmE;QACnE,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACxC,CAAC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';\nimport { HtmlSanitizer, matchLink } from 'roosterjs-editor-dom';\nimport type { ContentModelLink, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n addLink,\n addSegment,\n createContentModelDocument,\n createText,\n} from 'roosterjs-content-model-dom';\n\n// Regex matching Uri scheme\nconst URI_REGEX = /^[a-zA-Z]+:/i;\n// Regex matching begin of email address\nconst MAILTO_REGEX = /^[\\w.%+-]+@/i;\n// Regex matching begin of ftp, i.e. ftp.microsoft.com\nconst FTP_REGEX = /^ftp\\./i;\n\n/**\n * Insert a hyperlink at cursor.\n * When there is a selection, hyperlink will be applied to the selection,\n * otherwise a hyperlink will be inserted to the cursor position.\n * @param editor Editor object\n * @param link Link address, can be http(s), mailto, notes, file, unc, ftp, news, telnet, gopher, wais.\n * When protocol is not specified, a best matched protocol will be predicted.\n * @param anchorTitle Optional alt text of the link, will be shown when hover on the link\n * @param displayText Optional display text for the link.\n * @param target Optional display target for the link (\"_blank\"|\"_self\"|\"_parent\"|\"_top\"|\"{framename}\")\n * If specified, the display text of link will be replaced with this text.\n * If not specified and there wasn't a link, the link url will be used as display text.\n */\nexport default function insertLink(\n editor: IStandaloneEditor,\n link: string,\n anchorTitle?: string,\n displayText?: string,\n target?: string\n) {\n editor.focus();\n\n const url = (checkXss(link) || '').trim();\n if (url) {\n const linkData = matchLink(url);\n const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);\n const links: ContentModelLink[] = [];\n let anchorNode: Node | undefined;\n\n editor.formatContentModel(\n (model, context) => {\n const segments = getSelectedSegments(model, false /*includingFormatHolder*/);\n const originalText = segments\n .map(x => (x.segmentType == 'Text' ? x.text : ''))\n .join('');\n const text = displayText || originalText || '';\n\n if (\n segments.some(x => x.segmentType != 'SelectionMarker') &&\n originalText == text\n ) {\n segments.forEach(x => {\n const link = createLink(\n linkUrl,\n anchorTitle,\n target,\n x.segmentType == 'Text'\n );\n addLink(x, link);\n if (x.link) {\n links.push(x.link);\n }\n });\n } else if (\n segments.every(x => x.segmentType == 'SelectionMarker') ||\n (!!text && text != originalText)\n ) {\n const segment = createText(text || (linkData ? linkData.originalUrl : url), {\n ...segments[0]?.format,\n ...editor.getPendingFormat(),\n });\n const doc = createContentModelDocument();\n const link = createLink(linkUrl, anchorTitle, target);\n\n addLink(segment, link);\n addSegment(doc, segment);\n\n if (segment.link) {\n links.push(segment.link);\n }\n\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n }\n\n adjustTrailingSpaceSelection(model);\n return segments.length > 0;\n },\n {\n changeSource: ChangeSource.CreateLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n apiName: 'insertLink',\n }\n );\n }\n}\n\nconst createLink = (\n url: string,\n anchorTitle?: string,\n target?: string,\n underline: boolean = true\n): ContentModelLink => {\n return {\n dataset: {},\n format: {\n href: url,\n anchorTitle,\n target,\n underline: underline,\n },\n };\n};\n\n// TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.\nfunction applyLinkPrefix(url: string): string {\n if (!url) {\n return url;\n }\n\n // Add link prefix per rule:\n // (a) if the url always starts with a URI scheme, leave it as it is\n // (b) if the url is an email address, xxx@... add mailto: prefix\n // (c) if the url starts with ftp., add ftp:// prefix\n // (d) rest, add http:// prefix\n let prefix = '';\n if (url.search(URI_REGEX) < 0) {\n if (url.search(MAILTO_REGEX) == 0) {\n prefix = 'mailto:';\n } else if (url.search(FTP_REGEX) == 0) {\n prefix = 'ftp://';\n } else {\n // fallback to http://\n prefix = 'http://';\n }\n }\n\n return prefix + url;\n}\n\n// TODO: This is copied from original code. However, ContentModel should be able to filter out malicious\n// attributes later, so no need to use HtmlSanitizer here\nfunction checkXss(link: string): string {\n const sanitizer = new HtmlSanitizer();\n const a = document.createElement('a');\n\n a.href = link || '';\n\n sanitizer.sanitize(a);\n // We use getAttribute because some browsers will try to make the href property a valid link.\n // This has unintended side effects when the link lacks a protocol.\n return a.getAttribute('href') || '';\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "../utils/formatSegmentWithContentModel"], function (require, exports, formatSegmentWithContentModel_1) {
1
+ define(["require", "exports", "../../modelApi/selection/adjustTrailingSpaceSelection", "../utils/formatSegmentWithContentModel"], function (require, exports, adjustTrailingSpaceSelection_1, formatSegmentWithContentModel_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  /**
@@ -12,7 +12,7 @@ define(["require", "exports", "../utils/formatSegmentWithContentModel"], functio
12
12
  if (segment === null || segment === void 0 ? void 0 : segment.link) {
13
13
  segment.link.format.underline = !!isTurningOn;
14
14
  }
15
- }, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); });
15
+ }, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); }, false /*includingFormatHolder*/, adjustTrailingSpaceSelection_1.adjustTrailingSpaceSelection);
16
16
  }
17
17
  exports.default = toggleUnderline;
18
18
  });
@@ -1 +1 @@
1
- {"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":";;;IAGA;;;OAGG;IACH,SAAwB,eAAe,CAAC,MAAyB;QAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;YACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;YAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;gBACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;aACjD;QACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,CAChF,CAAC;IACN,CAAC;IAfD,kCAeC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport default function toggleUnderline(editor: IStandaloneEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline\n );\n}\n"]}
1
+ {"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":";;;IAIA;;;OAGG;IACH,SAAwB,eAAe,CAAC,MAAyB;QAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;YACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;YAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;gBACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;aACjD;QACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,EAC7E,KAAK,CAAC,yBAAyB,EAC/B,2DAA4B,CAC/B,CAAC;IACN,CAAC;IAjBD,kCAiBC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport default function toggleUnderline(editor: IStandaloneEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline,\n false /*includingFormatHolder*/,\n adjustTrailingSpaceSelection\n );\n}\n"]}
@@ -50,6 +50,8 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
50
50
  else if (borderColor) {
51
51
  borderFormat = borderFormat + " " + borderColor;
52
52
  }
53
+ // undefined is treated as Left to Right
54
+ var isRtl = tableModel.format.direction == 'rtl';
53
55
  if (sel) {
54
56
  var operations = [operation];
55
57
  while (operations.length) {
@@ -82,22 +84,22 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
82
84
  case 'leftBorders':
83
85
  var leftBorder = ['borderLeft'];
84
86
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
85
- var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
87
+ var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.lastColumn : sel.firstColumn];
86
88
  // Format cells - Left border
87
89
  applyBorderFormat(cell, borderFormat, leftBorder);
88
90
  }
89
91
  // Format perimeter
90
- perimeter.Left = true;
92
+ isRtl ? (perimeter.Right = true) : (perimeter.Left = true);
91
93
  break;
92
94
  case 'rightBorders':
93
95
  var rightBorder = ['borderRight'];
94
96
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
95
- var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
97
+ var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.firstColumn : sel.lastColumn];
96
98
  // Format cells - Right border
97
99
  applyBorderFormat(cell, borderFormat, rightBorder);
98
100
  }
99
101
  // Format perimeter
100
- perimeter.Right = true;
102
+ isRtl ? (perimeter.Left = true) : (perimeter.Right = true);
101
103
  break;
102
104
  case 'topBorders':
103
105
  var topBorder = ['borderTop'];
@@ -142,7 +144,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
142
144
  }
143
145
  // Single row selection
144
146
  if (singleRow) {
145
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderRight']);
147
+ applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderRight']);
146
148
  for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
147
149
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
148
150
  applyBorderFormat(cell, borderFormat, [
@@ -150,18 +152,18 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
150
152
  'borderRight',
151
153
  ]);
152
154
  }
153
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderLeft']);
155
+ applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderLeft']);
154
156
  break;
155
157
  }
156
158
  // For multiple rows and columns selections
157
159
  // Top left cell
158
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
160
+ applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
159
161
  // Top right cell
160
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
162
+ applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
161
163
  // Bottom left cell
162
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
164
+ applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
163
165
  // Bottom right cell
164
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
166
+ applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
165
167
  // First row
166
168
  for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
167
169
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
@@ -186,7 +188,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
186
188
  applyBorderFormat(cell, borderFormat, [
187
189
  'borderTop',
188
190
  'borderBottom',
189
- 'borderRight',
191
+ isRtl ? 'borderLeft' : 'borderRight',
190
192
  ]);
191
193
  }
192
194
  // Last column
@@ -195,7 +197,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
195
197
  applyBorderFormat(cell, borderFormat, [
196
198
  'borderTop',
197
199
  'borderBottom',
198
- 'borderLeft',
200
+ isRtl ? 'borderRight' : 'borderLeft',
199
201
  ]);
200
202
  }
201
203
  // Inner cells
@@ -217,7 +219,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
217
219
  }
218
220
  }
219
221
  //Format perimeter if necessary or possible
220
- modifyPerimeter(tableModel, sel, borderFormat, perimeter);
222
+ modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);
221
223
  }
222
224
  return true;
223
225
  }
@@ -257,7 +259,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
257
259
  * If borderFormat is empty, the border will be removed
258
260
  * @param perimeter Where in the perimeter to apply
259
261
  */
260
- function modifyPerimeter(tableModel, sel, borderFormat, perimeter) {
262
+ function modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl) {
261
263
  // Top of selection
262
264
  if (perimeter.Top && sel.firstRow - 1 >= 0) {
263
265
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
@@ -276,14 +278,14 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
276
278
  if (perimeter.Left && sel.firstColumn - 1 >= 0) {
277
279
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
278
280
  var cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];
279
- applyBorderFormat(cell, borderFormat, ['borderRight']);
281
+ applyBorderFormat(cell, borderFormat, [isRtl ? 'borderLeft' : 'borderRight']);
280
282
  }
281
283
  }
282
284
  // Right of selection
283
285
  if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {
284
286
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
285
287
  var cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];
286
- applyBorderFormat(cell, borderFormat, ['borderLeft']);
288
+ applyBorderFormat(cell, borderFormat, [isRtl ? 'borderRight' : 'borderLeft']);
287
289
  }
288
290
  }
289
291
  }
@@ -1 +1 @@
1
- {"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";;;IAkCA;;;;;OAKG;IACH,SAAwB,sBAAsB,CAC1C,MAAyB,EACzB,MAAc,EACd,SAA2B;QAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;YACK,IAAA,KAAA,oBAAe,IAAA,oDAAqB,EAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;YAElD,IAAI,UAAU,EAAE;gBACZ,IAAM,GAAG,GAAG,IAAA,+CAAgB,EAAC,UAAU,CAAC,CAAC;gBACzC,IAAM,SAAS,GAAc;oBACzB,GAAG,EAAE,KAAK;oBACV,MAAM,EAAE,KAAK;oBACb,IAAI,EAAE,KAAK;oBACX,KAAK,EAAE,KAAK;iBACf,CAAC;gBAEF,mDAAmD;gBACnD,IAAI,YAAY,GAAG,EAAE,CAAC;gBACtB,IAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;gBACzB,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,KAAK,GAAY,MAAM,MAAlB,EAAE,KAAK,GAAK,MAAM,MAAX,CAAY;gBACvC,IAAM,eAAe,GAAG,IAAA,kDAAm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,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;gBAClE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;aAC1D;SACJ;QACD,qBAAqB;QACrB,IAAI,SAAS,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;YACzE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;gBACjE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;aACzD;SACJ;IACL,CAAC","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getFirstSelectedTable,\n getSelectedCells,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n IStandaloneEditor,\n Border,\n ContentModelTable,\n ContentModelTableCell,\n BorderOperations,\n TableSelectionCoordinates,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Border positions\n */\ntype BorderPositions = 'borderTop' | 'borderBottom' | 'borderLeft' | 'borderRight';\n\n/**\n * @internal\n * Perimeter of the table selection\n * Used to determine where to apply border to the cells adjacent to the selection.\n */\ntype Perimeter = {\n Top: boolean;\n Bottom: boolean;\n Left: boolean;\n Right: boolean;\n};\n\n/**\n * Operations to apply border\n * @param editor The editor instance\n * @param border The border to apply\n * @param operation The operation to apply\n */\nexport default function applyTableBorderFormat(\n editor: IStandaloneEditor,\n border: Border,\n operation: BorderOperations\n) {\n editor.formatContentModel(\n model => {\n const [tableModel] = getFirstSelectedTable(model);\n\n if (tableModel) {\n const sel = getSelectedCells(tableModel);\n const perimeter: Perimeter = {\n Top: false,\n Bottom: false,\n Left: false,\n Right: false,\n };\n\n // Create border format with table format as backup\n let borderFormat = '';\n const format = tableModel.format;\n const { width, style, color } = border;\n const extractedBorder = extractBorderValues(format.borderTop);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n\n if (sel) {\n const operations: BorderOperations[] = [operation];\n while (operations.length) {\n switch (operations.pop()) {\n case 'noBorders':\n // Do All borders but with empty border format\n borderFormat = '';\n operations.push('allBorders');\n break;\n case 'allBorders':\n const allBorders: BorderPositions[] = [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[colIndex];\n // Format cells - All borders\n applyBorderFormat(cell, borderFormat, allBorders);\n }\n }\n\n // Format perimeter\n perimeter.Top = true;\n perimeter.Bottom = true;\n perimeter.Left = true;\n perimeter.Right = true;\n break;\n case 'leftBorders':\n const leftBorder: BorderPositions[] = ['borderLeft'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn];\n // Format cells - Left border\n applyBorderFormat(cell, borderFormat, leftBorder);\n }\n\n // Format perimeter\n perimeter.Left = true;\n break;\n case 'rightBorders':\n const rightBorder: BorderPositions[] = ['borderRight'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn];\n // Format cells - Right border\n applyBorderFormat(cell, borderFormat, rightBorder);\n }\n\n // Format perimeter\n perimeter.Right = true;\n break;\n case 'topBorders':\n const topBorder: BorderPositions[] = ['borderTop'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n // Format cells - Top border\n applyBorderFormat(cell, borderFormat, topBorder);\n }\n\n // Format perimeter\n perimeter.Top = true;\n break;\n case 'bottomBorders':\n const bottomBorder: BorderPositions[] = ['borderBottom'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n // Format cells - Bottom border\n applyBorderFormat(cell, borderFormat, bottomBorder);\n }\n\n // Format perimeter\n perimeter.Bottom = true;\n break;\n case 'insideBorders':\n // Format cells - Inside borders\n const singleCol = sel.lastColumn == sel.firstColumn;\n const singleRow = sel.lastRow == sel.firstRow;\n // Single cell selection\n if (singleCol && singleRow) {\n break;\n }\n // Single column selection\n if (singleCol) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderBottom']\n );\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex <= sel.lastRow - 1;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n borderFormat,\n ['borderTop']\n );\n break;\n }\n // Single row selection\n if (singleRow) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderRight']\n );\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex <= sel.lastColumn - 1;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderLeft',\n 'borderRight',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.lastColumn],\n borderFormat,\n ['borderLeft']\n );\n break;\n }\n\n // For multiple rows and columns selections\n // Top left cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.lastColumn],\n borderFormat,\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n borderFormat,\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.lastColumn],\n borderFormat,\n ['borderTop', 'borderLeft']\n );\n // First row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // Last row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // First column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n 'borderRight',\n ]);\n }\n // Last column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n ]);\n }\n // Inner cells\n sel.firstColumn++;\n sel.firstRow++;\n sel.lastColumn--;\n sel.lastRow--;\n operations.push('allBorders');\n break;\n case 'outsideBorders':\n // Format cells - Outside borders\n operations.push('topBorders');\n operations.push('bottomBorders');\n operations.push('leftBorders');\n operations.push('rightBorders');\n break;\n default:\n break;\n }\n }\n\n //Format perimeter if necessary or possible\n modifyPerimeter(tableModel, sel, borderFormat, perimeter);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'tableBorder',\n }\n );\n}\n\n/**\n * @internal\n * Apply border format to a cell\n * @param cell The cell to apply border format\n * @param borderFormat The border format to apply\n * @param positions The positions to apply\n */\nfunction applyBorderFormat(\n cell: ContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n positions.forEach(pos => {\n cell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(cell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n\n // Cell was modified, so delete cached element\n delete cell.cachedElement;\n}\n\n/**\n * @internal\n * Modify the perimeter of the table selection\n * @param tableModel The table model\n * @param sel The table selection\n * @param borderFormat The border format to apply\n * If borderFormat is empty, the border will be removed\n * @param perimeter Where in the perimeter to apply\n */\nfunction modifyPerimeter(\n tableModel: ContentModelTable,\n sel: TableSelectionCoordinates,\n borderFormat: string,\n perimeter: Perimeter\n) {\n // Top of selection\n if (perimeter.Top && sel.firstRow - 1 >= 0) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderBottom']);\n }\n }\n // Bottom of selection\n if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderTop']);\n }\n }\n // Left of selection\n if (perimeter.Left && sel.firstColumn - 1 >= 0) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];\n applyBorderFormat(cell, borderFormat, ['borderRight']);\n }\n }\n // Right of selection\n if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];\n applyBorderFormat(cell, borderFormat, ['borderLeft']);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";;;IAkCA;;;;;OAKG;IACH,SAAwB,sBAAsB,CAC1C,MAAyB,EACzB,MAAc,EACd,SAA2B;QAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;YACK,IAAA,KAAA,oBAAe,IAAA,oDAAqB,EAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;YAElD,IAAI,UAAU,EAAE;gBACZ,IAAM,GAAG,GAAG,IAAA,+CAAgB,EAAC,UAAU,CAAC,CAAC;gBACzC,IAAM,SAAS,GAAc;oBACzB,GAAG,EAAE,KAAK;oBACV,MAAM,EAAE,KAAK;oBACb,IAAI,EAAE,KAAK;oBACX,KAAK,EAAE,KAAK;iBACf,CAAC;gBAEF,mDAAmD;gBACnD,IAAI,YAAY,GAAG,EAAE,CAAC;gBACtB,IAAM,MAAM,GAAG,UAAU,CAAC,MAA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AY,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;aACjF;SACJ;QACD,qBAAqB;QACrB,IAAI,SAAS,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;YACzE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;gBACjE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;aACjF;SACJ;IACL,CAAC","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getFirstSelectedTable,\n getSelectedCells,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n IStandaloneEditor,\n Border,\n ContentModelTable,\n ContentModelTableCell,\n BorderOperations,\n TableSelectionCoordinates,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Border positions\n */\ntype BorderPositions = 'borderTop' | 'borderBottom' | 'borderLeft' | 'borderRight';\n\n/**\n * @internal\n * Perimeter of the table selection\n * Used to determine where to apply border to the cells adjacent to the selection.\n */\ntype Perimeter = {\n Top: boolean;\n Bottom: boolean;\n Left: boolean;\n Right: boolean;\n};\n\n/**\n * Operations to apply border\n * @param editor The editor instance\n * @param border The border to apply\n * @param operation The operation to apply\n */\nexport default function applyTableBorderFormat(\n editor: IStandaloneEditor,\n border: Border,\n operation: BorderOperations\n) {\n editor.formatContentModel(\n model => {\n const [tableModel] = getFirstSelectedTable(model);\n\n if (tableModel) {\n const sel = getSelectedCells(tableModel);\n const perimeter: Perimeter = {\n Top: false,\n Bottom: false,\n Left: false,\n Right: false,\n };\n\n // Create border format with table format as backup\n let borderFormat = '';\n const format = tableModel.format;\n const { width, style, color } = border;\n const extractedBorder = extractBorderValues(format.borderTop);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n\n // undefined is treated as Left to Right\n const isRtl = tableModel.format.direction == 'rtl';\n\n if (sel) {\n const operations: BorderOperations[] = [operation];\n while (operations.length) {\n switch (operations.pop()) {\n case 'noBorders':\n // Do All borders but with empty border format\n borderFormat = '';\n operations.push('allBorders');\n break;\n case 'allBorders':\n const allBorders: BorderPositions[] = [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[colIndex];\n // Format cells - All borders\n applyBorderFormat(cell, borderFormat, allBorders);\n }\n }\n\n // Format perimeter\n perimeter.Top = true;\n perimeter.Bottom = true;\n perimeter.Left = true;\n perimeter.Right = true;\n break;\n case 'leftBorders':\n const leftBorder: BorderPositions[] = ['borderLeft'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ];\n // Format cells - Left border\n applyBorderFormat(cell, borderFormat, leftBorder);\n }\n\n // Format perimeter\n isRtl ? (perimeter.Right = true) : (perimeter.Left = true);\n break;\n case 'rightBorders':\n const rightBorder: BorderPositions[] = ['borderRight'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ];\n // Format cells - Right border\n applyBorderFormat(cell, borderFormat, rightBorder);\n }\n\n // Format perimeter\n isRtl ? (perimeter.Left = true) : (perimeter.Right = true);\n break;\n case 'topBorders':\n const topBorder: BorderPositions[] = ['borderTop'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n // Format cells - Top border\n applyBorderFormat(cell, borderFormat, topBorder);\n }\n\n // Format perimeter\n perimeter.Top = true;\n break;\n case 'bottomBorders':\n const bottomBorder: BorderPositions[] = ['borderBottom'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n // Format cells - Bottom border\n applyBorderFormat(cell, borderFormat, bottomBorder);\n }\n\n // Format perimeter\n perimeter.Bottom = true;\n break;\n case 'insideBorders':\n // Format cells - Inside borders\n const singleCol = sel.lastColumn == sel.firstColumn;\n const singleRow = sel.lastRow == sel.firstRow;\n // Single cell selection\n if (singleCol && singleRow) {\n break;\n }\n // Single column selection\n if (singleCol) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderBottom']\n );\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex <= sel.lastRow - 1;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n borderFormat,\n ['borderTop']\n );\n break;\n }\n // Single row selection\n if (singleRow) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderRight']\n );\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex <= sel.lastColumn - 1;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderLeft',\n 'borderRight',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderLeft']\n );\n break;\n }\n\n // For multiple rows and columns selections\n // Top left cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderTop', 'borderLeft']\n );\n // First row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // Last row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // First column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n isRtl ? 'borderLeft' : 'borderRight',\n ]);\n }\n // Last column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n isRtl ? 'borderRight' : 'borderLeft',\n ]);\n }\n // Inner cells\n sel.firstColumn++;\n sel.firstRow++;\n sel.lastColumn--;\n sel.lastRow--;\n operations.push('allBorders');\n break;\n case 'outsideBorders':\n // Format cells - Outside borders\n operations.push('topBorders');\n operations.push('bottomBorders');\n operations.push('leftBorders');\n operations.push('rightBorders');\n break;\n default:\n break;\n }\n }\n\n //Format perimeter if necessary or possible\n modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'tableBorder',\n }\n );\n}\n\n/**\n * @internal\n * Apply border format to a cell\n * @param cell The cell to apply border format\n * @param borderFormat The border format to apply\n * @param positions The positions to apply\n */\nfunction applyBorderFormat(\n cell: ContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n positions.forEach(pos => {\n cell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(cell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n\n // Cell was modified, so delete cached element\n delete cell.cachedElement;\n}\n\n/**\n * @internal\n * Modify the perimeter of the table selection\n * @param tableModel The table model\n * @param sel The table selection\n * @param borderFormat The border format to apply\n * If borderFormat is empty, the border will be removed\n * @param perimeter Where in the perimeter to apply\n */\nfunction modifyPerimeter(\n tableModel: ContentModelTable,\n sel: TableSelectionCoordinates,\n borderFormat: string,\n perimeter: Perimeter,\n isRtl: boolean\n) {\n // Top of selection\n if (perimeter.Top && sel.firstRow - 1 >= 0) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderBottom']);\n }\n }\n // Bottom of selection\n if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderTop']);\n }\n }\n // Left of selection\n if (perimeter.Left && sel.firstColumn - 1 >= 0) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];\n applyBorderFormat(cell, borderFormat, [isRtl ? 'borderLeft' : 'borderRight']);\n }\n }\n // Right of selection\n if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];\n applyBorderFormat(cell, borderFormat, [isRtl ? 'borderRight' : 'borderLeft']);\n }\n }\n}\n"]}
@@ -8,7 +8,6 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
8
8
  function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, segmentHasStyleCallback, includingFormatHolder, afterFormatCallback) {
9
9
  editor.formatContentModel(function (model, context) {
10
10
  var segmentAndParagraphs = (0, roosterjs_content_model_core_1.getSelectedSegmentsAndParagraphs)(model, !!includingFormatHolder);
11
- var pendingFormat = editor.getPendingFormat();
12
11
  var isCollapsedSelection = segmentAndParagraphs.length == 1 &&
13
12
  segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';
14
13
  if (isCollapsedSelection) {
@@ -18,9 +17,7 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
18
17
  isCollapsedSelection = false;
19
18
  }
20
19
  }
21
- var formatsAndSegments = pendingFormat
22
- ? [[pendingFormat, null, null]]
23
- : segmentAndParagraphs.map(function (item) { return [item[0].format, item[0], item[1]]; });
20
+ var formatsAndSegments = segmentAndParagraphs.map(function (item) { return [item[0].format, item[0], item[1]]; });
24
21
  var isTurningOff = segmentHasStyleCallback
25
22
  ? formatsAndSegments.every(function (_a) {
26
23
  var _b = (0, tslib_1.__read)(_a, 3), format = _b[0], segment = _b[1], paragraph = _b[2];
@@ -32,10 +29,8 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
32
29
  return toggleStyleCallback(format, !isTurningOff, segment, paragraph);
33
30
  });
34
31
  afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model);
35
- if (!pendingFormat && isCollapsedSelection) {
36
- context.newPendingFormat = segmentAndParagraphs[0][0].format;
37
- }
38
32
  if (isCollapsedSelection) {
33
+ context.newPendingFormat = segmentAndParagraphs[0][0].format;
39
34
  editor.focus();
40
35
  return false;
41
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;IASA;;OAEG;IACH,SAAgB,6BAA6B,CACzC,MAAyB,EACzB,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAA2D;QAE3D,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAI,oBAAoB,GAAG,IAAA,+DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,CAC1B,CAAC;YACF,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAChD,IAAI,oBAAoB,GACpB,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AAS,QAAA;gBACnD,OAAA,mBAAmB,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,CAAC;YAA9D,CAA8D,CACjE,CAAC;YAEF,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAG,KAAK,CAAC,CAAC;YAE7B,IAAI,CAAC,aAAa,IAAI,oBAAoB,EAAE;gBACxC,OAAO,CAAC,gBAAgB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;aAChE;YAED,IAAI,oBAAoB,EAAE;gBACtB,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;aAChB;iBAAM;gBACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;aACxC;QACL,CAAC,EACD;YACI,OAAO,SAAA;SACV,CACJ,CAAC;IACN,CAAC;IA5ED,sEA4EC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentFormat,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n/**\n * @internal\n */\nexport function formatSegmentWithContentModel(\n editor: IStandaloneEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder\n );\n const pendingFormat = editor.getPendingFormat();\n let isCollapsedSelection =\n segmentAndParagraphs.length == 1 &&\n segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';\n\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ContentModelSegment | null,\n ContentModelParagraph | null\n ][] = pendingFormat\n ? [[pendingFormat, null, null]]\n : segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) =>\n toggleStyleCallback(format, !isTurningOff, segment, paragraph)\n );\n\n afterFormatCallback?.(model);\n\n if (!pendingFormat && isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n }\n\n if (isCollapsedSelection) {\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n"]}
1
+ {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;IASA;;OAEG;IACH,SAAgB,6BAA6B,CACzC,MAAyB,EACzB,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAA2D;QAE3D,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAI,oBAAoB,GAAG,IAAA,+DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,CAC1B,CAAC;YACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;gBAChC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI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AI,oBAAoB,EAAE;gBACtB,OAAO,CAAC,gBAAgB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;aAChB;iBAAM;gBACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;aACxC;QACL,CAAC,EACD;YACI,OAAO,SAAA;SACV,CACJ,CAAC;IACN,CAAC;IAtED,sEAsEC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentFormat,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n/**\n * @internal\n */\nexport function formatSegmentWithContentModel(\n editor: IStandaloneEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length == 1 &&\n segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';\n\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ContentModelSegment | null,\n ContentModelParagraph | null\n ][] = segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) =>\n toggleStyleCallback(format, !isTurningOff, segment, paragraph)\n );\n\n afterFormatCallback?.(model);\n\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n"]}
@@ -2,4 +2,4 @@ import type { ContentModelDocument } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare function setModelAlignment(model: ContentModelDocument, alignment: 'left' | 'center' | 'right'): boolean;
5
+ export declare function setModelAlignment(model: ContentModelDocument, alignment: 'left' | 'center' | 'right' | 'justify'): boolean;
@@ -13,6 +13,10 @@ var ResultMap = {
13
13
  ltr: 'end',
14
14
  rtl: 'start',
15
15
  },
16
+ justify: {
17
+ ltr: 'justify',
18
+ rtl: 'justify',
19
+ },
16
20
  };
17
21
  var TableAlignMap = {
18
22
  left: {
@@ -35,13 +39,19 @@ export function setModelAlignment(model, alignment) {
35
39
  var paragraphOrListItemOrTable = getOperationalBlocks(model, ['ListItem'], ['TableCell']);
36
40
  paragraphOrListItemOrTable.forEach(function (_a) {
37
41
  var block = _a.block;
38
- var newAligment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];
39
- if (block.blockType === 'Table') {
42
+ var newAlignment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];
43
+ if (block.blockType === 'Table' && alignment !== 'justify') {
40
44
  alignTable(block, TableAlignMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr']);
41
45
  }
42
46
  else if (block) {
47
+ if (block.blockType === 'BlockGroup' && block.blockGroupType === 'ListItem') {
48
+ block.blocks.forEach(function (b) {
49
+ var format = b.format;
50
+ format.textAlign = newAlignment;
51
+ });
52
+ }
43
53
  var format = block.format;
44
- format.textAlign = newAligment;
54
+ format.textAlign = newAlignment;
45
55
  }
46
56
  });
47
57
  return paragraphOrListItemOrTable.length > 0;
@@ -1 +1 @@
1
- {"version":3,"file":"setModelAlignment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelAlignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAOpE,IAAM,SAAS,GAGX;IACA,IAAI,EAAE;QACF,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,KAAK;KACb;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,QAAQ;QACb,GAAG,EAAE,QAAQ;KAChB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,OAAO;KACf;CACJ,CAAC;AAEF,IAAM,aAAa,GAGf;IACA,IAAI,EAAE;QACF,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,YAAY;KACpB;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,aAAa;QAClB,GAAG,EAAE,aAAa;KACrB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,WAAW;KACnB;CACJ,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAA2B,EAC3B,SAAsC;IAEtC,IAAM,0BAA0B,GAAG,oBAAoB,CACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,WAAA;QACvC,IAAM,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC1F,IAAI,KAAK,CAAC,SAAS,KAAK,OAAO,EAAE;YAC7B,UAAU,CACN,KAAK,EACL,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAC5E,CAAC;SACL;aAAM,IAAI,KAAK,EAAE;YACN,IAAA,MAAM,GAAK,KAAK,OAAV,CAAW;YACzB,MAAM,CAAC,SAAS,GAAG,WAAW,CAAC;SAClC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,0BAA0B,CAAC,MAAM,GAAG,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { alignTable } from '../table/alignTable';\nimport { getOperationalBlocks } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelListItem,\n TableAlignOperation,\n} from 'roosterjs-content-model-types';\n\nconst ResultMap: Record<\n 'left' | 'center' | 'right',\n Record<'ltr' | 'rtl', 'start' | 'center' | 'end'>\n> = {\n left: {\n ltr: 'start',\n rtl: 'end',\n },\n center: {\n ltr: 'center',\n rtl: 'center',\n },\n right: {\n ltr: 'end',\n rtl: 'start',\n },\n};\n\nconst TableAlignMap: Record<\n 'left' | 'center' | 'right',\n Record<'ltr' | 'rtl', TableAlignOperation>\n> = {\n left: {\n ltr: 'alignLeft',\n rtl: 'alignRight',\n },\n center: {\n ltr: 'alignCenter',\n rtl: 'alignCenter',\n },\n right: {\n ltr: 'alignRight',\n rtl: 'alignLeft',\n },\n};\n\n/**\n * @internal\n */\nexport function setModelAlignment(\n model: ContentModelDocument,\n alignment: 'left' | 'center' | 'right'\n) {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n const newAligment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];\n if (block.blockType === 'Table') {\n alignTable(\n block,\n TableAlignMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr']\n );\n } else if (block) {\n const { format } = block;\n format.textAlign = newAligment;\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n"]}
1
+ {"version":3,"file":"setModelAlignment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelAlignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAOpE,IAAM,SAAS,GAGX;IACA,IAAI,EAAE;QACF,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,KAAK;KACb;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,QAAQ;QACb,GAAG,EAAE,QAAQ;KAChB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,OAAO;KACf;IACD,OAAO,EAAE;QACL,GAAG,EAAE,SAAS;QACd,GAAG,EAAE,SAAS;KACjB;CACJ,CAAC;AAEF,IAAM,aAAa,GAGf;IACA,IAAI,EAAE;QACF,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,YAAY;KACpB;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,aAAa;QAClB,GAAG,EAAE,aAAa;KACrB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,WAAW;KACnB;CACJ,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAA2B,EAC3B,SAAkD;IAElD,IAAM,0BAA0B,GAAG,oBAAoB,CACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,WAAA;QACvC,IAAM,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3F,IAAI,KAAK,CAAC,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,SAAS,EAAE;YACxD,UAAU,CACN,KAAK,EACL,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAC5E,CAAC;SACL;aAAM,IAAI,KAAK,EAAE;YACd,IAAI,KAAK,CAAC,SAAS,KAAK,YAAY,IAAI,KAAK,CAAC,cAAc,KAAK,UAAU,EAAE;gBACzE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,CAAC;oBACV,IAAA,MAAM,GAAK,CAAC,OAAN,CAAO;oBACrB,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;gBACpC,CAAC,CAAC,CAAC;aACN;YACO,IAAA,MAAM,GAAK,KAAK,OAAV,CAAW;YACzB,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;SACnC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,0BAA0B,CAAC,MAAM,GAAG,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { alignTable } from '../table/alignTable';\nimport { getOperationalBlocks } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelListItem,\n TableAlignOperation,\n} from 'roosterjs-content-model-types';\n\nconst ResultMap: Record<\n 'left' | 'center' | 'right' | 'justify',\n Record<'ltr' | 'rtl', 'start' | 'center' | 'end' | 'justify'>\n> = {\n left: {\n ltr: 'start',\n rtl: 'end',\n },\n center: {\n ltr: 'center',\n rtl: 'center',\n },\n right: {\n ltr: 'end',\n rtl: 'start',\n },\n justify: {\n ltr: 'justify',\n rtl: 'justify',\n },\n};\n\nconst TableAlignMap: Record<\n 'left' | 'center' | 'right',\n Record<'ltr' | 'rtl', TableAlignOperation>\n> = {\n left: {\n ltr: 'alignLeft',\n rtl: 'alignRight',\n },\n center: {\n ltr: 'alignCenter',\n rtl: 'alignCenter',\n },\n right: {\n ltr: 'alignRight',\n rtl: 'alignLeft',\n },\n};\n\n/**\n * @internal\n */\nexport function setModelAlignment(\n model: ContentModelDocument,\n alignment: 'left' | 'center' | 'right' | 'justify'\n) {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n const newAlignment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];\n if (block.blockType === 'Table' && alignment !== 'justify') {\n alignTable(\n block,\n TableAlignMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr']\n );\n } else if (block) {\n if (block.blockType === 'BlockGroup' && block.blockGroupType === 'ListItem') {\n block.blocks.forEach(b => {\n const { format } = b;\n format.textAlign = newAlignment;\n });\n }\n const { format } = block;\n format.textAlign = newAlignment;\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { findListItemsInSameThread } from '../list/findListItemsInSameThread';
2
- import { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';
2
+ import { applyTableFormat, getOperationalBlocks, isBlockGroupOfType, updateTableCellMetadata, } from 'roosterjs-content-model-core';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -17,25 +17,42 @@ export function setModelDirection(model, direction) {
17
17
  });
18
18
  }
19
19
  else if (block) {
20
- internalSetDirection(block.format, direction);
20
+ internalSetDirection(block.format, direction, block);
21
21
  }
22
22
  });
23
23
  return paragraphOrListItemOrTable.length > 0;
24
24
  }
25
- function internalSetDirection(format, direction) {
25
+ function internalSetDirection(format, direction, block) {
26
26
  var wasRtl = format.direction == 'rtl';
27
27
  var isRtl = direction == 'rtl';
28
28
  if (wasRtl != isRtl) {
29
29
  format.direction = direction;
30
30
  // Adjust margin when change direction
31
31
  // TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here
32
- // TODO: Do we also need to handle border here?
33
32
  var marginLeft = format.marginLeft;
34
33
  var paddingLeft = format.paddingLeft;
35
34
  setProperty(format, 'marginLeft', format.marginRight);
36
35
  setProperty(format, 'marginRight', marginLeft);
37
36
  setProperty(format, 'paddingLeft', format.paddingRight);
38
37
  setProperty(format, 'paddingRight', paddingLeft);
38
+ // If whole Table direction changed, flip cell side borders
39
+ if (block && block.blockType == 'Table') {
40
+ block.rows.forEach(function (row) {
41
+ row.cells.forEach(function (cell) {
42
+ // Optimise by skipping cells with unchanged borders
43
+ updateTableCellMetadata(cell, function (metadata) {
44
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.borderOverride) {
45
+ var storeBorderLeft = cell.format.borderLeft;
46
+ setProperty(cell.format, 'borderLeft', cell.format.borderRight);
47
+ setProperty(cell.format, 'borderRight', storeBorderLeft);
48
+ }
49
+ return metadata;
50
+ });
51
+ });
52
+ });
53
+ // Apply changed borders
54
+ applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);
55
+ }
39
56
  }
40
57
  }
41
58
  function setProperty(format, key, value) {
@@ -1 +1 @@
1
- {"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AASxF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA2B,EAAE,SAAwB;IACnF,IAAM,0BAA0B,GAAG,oBAAoB,CACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,W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AAC,CAAC;QACxD,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC;KACpD;AACL,CAAC;AAED,SAAS,WAAW,CAChB,MAAoC,EACpC,GAAyC,EACzC,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 { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport type {\n ContentModelBlockFormat,\n ContentModelDocument,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setModelDirection(model: ContentModelDocument, direction: 'ltr' | 'rtl') {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(item => {\n item.levels.forEach(level => {\n level.format.direction = direction;\n });\n\n item.blocks.forEach(block => internalSetDirection(block.format, direction));\n });\n } else if (block) {\n internalSetDirection(block.format, direction);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(format: ContentModelBlockFormat, direction: 'ltr' | 'rtl') {\n const wasRtl = format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n format.direction = direction;\n\n // Adjust margin when change direction\n // TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here\n // TODO: Do we also need to handle border here?\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat,\n key: keyof (MarginFormat & PaddingFormat),\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-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EACH,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,GAC1B,MAAM,8BAA8B,CAAC;AAWtC;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA2B,EAAE,SAAwB;IACnF,IAAM,0BAA0B,GAAG,oBAAoB,CACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,WAAA;QACvC,IAAI,kBAAkB,CAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;YAC7D,IAAM,KAAK,GAAG,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAEtD,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;gBACd,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;oBACrB,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;gBACvC,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,EAA7C,CAA6C,CAAC,CAAC;YAChF,CAAC,CAAC,CAAC;SACN;aAAM,IAAI,KAAK,EAAE;YACd,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC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AAC,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,eAAe,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 {\n applyTableFormat,\n getOperationalBlocks,\n isBlockGroupOfType,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n BorderFormat,\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelDocument,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setModelDirection(model: ContentModelDocument, direction: 'ltr' | 'rtl') {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(item => {\n item.levels.forEach(level => {\n level.format.direction = direction;\n });\n\n item.blocks.forEach(block => internalSetDirection(block.format, direction));\n });\n } else if (block) {\n internalSetDirection(block.format, direction, block);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(\n format: ContentModelBlockFormat,\n direction: 'ltr' | 'rtl',\n block?: ContentModelBlock\n) {\n const wasRtl = format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n format.direction = direction;\n\n // Adjust margin when change direction\n // TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n\n // If whole Table direction changed, flip cell side borders\n if (block && block.blockType == 'Table') {\n block.rows.forEach(row => {\n row.cells.forEach(cell => {\n // Optimise by skipping cells with unchanged borders\n updateTableCellMetadata(cell, metadata => {\n if (metadata?.borderOverride) {\n const storeBorderLeft = cell.format.borderLeft;\n setProperty(cell.format, 'borderLeft', cell.format.borderRight);\n setProperty(cell.format, 'borderRight', storeBorderLeft);\n }\n return metadata;\n });\n });\n });\n\n // Apply changed borders\n applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);\n }\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat & BorderFormat,\n key: keyof (MarginFormat & PaddingFormat & BorderFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { parseValueWithUnit } from 'roosterjs-content-model-dom';
1
2
  import { extractBorderValues, getClosestAncestorBlockGroupIndex, isBold, iterateSelections, updateTableMetadata, } from 'roosterjs-content-model-core';
2
3
  /**
3
4
  * @internal
@@ -91,7 +92,7 @@ function retrieveSegmentFormat(result, isFirst, mergedFormat) {
91
92
  mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);
92
93
  mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);
93
94
  mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);
94
- mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst);
95
+ mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst, function (val) { return parseValueWithUnit(val, undefined, 'pt') + 'pt'; });
95
96
  mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);
96
97
  mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);
97
98
  mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);
@@ -146,13 +147,14 @@ function retrieveImageFormat(image, result) {
146
147
  borderRadius: format.borderRadius,
147
148
  };
148
149
  }
149
- function mergeValue(format, key, newValue, isFirst) {
150
+ function mergeValue(format, key, newValue, isFirst, parseFn) {
151
+ if (parseFn === void 0) { parseFn = function (val) { return val; }; }
150
152
  if (isFirst) {
151
153
  if (newValue !== undefined) {
152
154
  format[key] = newValue;
153
155
  }
154
156
  }
155
- else if (newValue !== format[key]) {
157
+ else if (parseFn(newValue) !== parseFn(format[key])) {
156
158
  delete format[key];
157
159
  }
158
160
  }