roosterjs-content-model-api 0.24.0 → 0.25.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 (94) hide show
  1. package/lib/index.d.ts +1 -0
  2. package/lib/index.js +3 -1
  3. package/lib/index.js.map +1 -1
  4. package/lib/modelApi/block/setModelDirection.js +0 -1
  5. package/lib/modelApi/block/setModelDirection.js.map +1 -1
  6. package/lib/modelApi/block/toggleModelBlockQuote.d.ts +1 -1
  7. package/lib/modelApi/block/toggleModelBlockQuote.js +6 -4
  8. package/lib/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  9. package/lib/modelApi/common/retrieveModelFormatState.js +0 -2
  10. package/lib/modelApi/common/retrieveModelFormatState.js.map +1 -1
  11. package/lib/modelApi/common/wrapBlock.d.ts +2 -2
  12. package/lib/modelApi/common/wrapBlock.js +8 -4
  13. package/lib/modelApi/common/wrapBlock.js.map +1 -1
  14. package/lib/modelApi/link/matchLink.d.ts +29 -0
  15. package/lib/modelApi/link/matchLink.js +95 -0
  16. package/lib/modelApi/link/matchLink.js.map +1 -0
  17. package/lib/modelApi/list/setListType.d.ts +3 -1
  18. package/lib/modelApi/list/setListType.js +6 -9
  19. package/lib/modelApi/list/setListType.js.map +1 -1
  20. package/lib/publicApi/block/toggleBlockQuote.d.ts +1 -1
  21. package/lib/publicApi/block/toggleBlockQuote.js +10 -6
  22. package/lib/publicApi/block/toggleBlockQuote.js.map +1 -1
  23. package/lib/publicApi/entity/insertEntity.js +6 -10
  24. package/lib/publicApi/entity/insertEntity.js.map +1 -1
  25. package/lib/publicApi/format/getFormatState.d.ts +1 -21
  26. package/lib/publicApi/format/getFormatState.js +1 -69
  27. package/lib/publicApi/format/getFormatState.js.map +1 -1
  28. package/lib/publicApi/link/insertLink.js +3 -12
  29. package/lib/publicApi/link/insertLink.js.map +1 -1
  30. package/lib/publicApi/segment/changeCapitalization.js +0 -1
  31. package/lib/publicApi/segment/changeCapitalization.js.map +1 -1
  32. package/lib-amd/index.d.ts +1 -0
  33. package/lib-amd/index.js +3 -2
  34. package/lib-amd/index.js.map +1 -1
  35. package/lib-amd/modelApi/block/setModelDirection.js +0 -1
  36. package/lib-amd/modelApi/block/setModelDirection.js.map +1 -1
  37. package/lib-amd/modelApi/block/toggleModelBlockQuote.d.ts +1 -1
  38. package/lib-amd/modelApi/block/toggleModelBlockQuote.js +6 -4
  39. package/lib-amd/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  40. package/lib-amd/modelApi/common/retrieveModelFormatState.js +0 -2
  41. package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +1 -1
  42. package/lib-amd/modelApi/common/wrapBlock.d.ts +2 -2
  43. package/lib-amd/modelApi/common/wrapBlock.js +8 -4
  44. package/lib-amd/modelApi/common/wrapBlock.js.map +1 -1
  45. package/lib-amd/modelApi/link/matchLink.d.ts +29 -0
  46. package/lib-amd/modelApi/link/matchLink.js +95 -0
  47. package/lib-amd/modelApi/link/matchLink.js.map +1 -0
  48. package/lib-amd/modelApi/list/setListType.d.ts +3 -1
  49. package/lib-amd/modelApi/list/setListType.js +6 -9
  50. package/lib-amd/modelApi/list/setListType.js.map +1 -1
  51. package/lib-amd/publicApi/block/toggleBlockQuote.d.ts +1 -1
  52. package/lib-amd/publicApi/block/toggleBlockQuote.js +10 -6
  53. package/lib-amd/publicApi/block/toggleBlockQuote.js.map +1 -1
  54. package/lib-amd/publicApi/entity/insertEntity.js +6 -10
  55. package/lib-amd/publicApi/entity/insertEntity.js.map +1 -1
  56. package/lib-amd/publicApi/format/getFormatState.d.ts +1 -21
  57. package/lib-amd/publicApi/format/getFormatState.js +2 -67
  58. package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
  59. package/lib-amd/publicApi/link/insertLink.js +3 -12
  60. package/lib-amd/publicApi/link/insertLink.js.map +1 -1
  61. package/lib-amd/publicApi/segment/changeCapitalization.js +0 -1
  62. package/lib-amd/publicApi/segment/changeCapitalization.js.map +1 -1
  63. package/lib-mjs/index.d.ts +1 -0
  64. package/lib-mjs/index.js +1 -0
  65. package/lib-mjs/index.js.map +1 -1
  66. package/lib-mjs/modelApi/block/setModelDirection.js +0 -1
  67. package/lib-mjs/modelApi/block/setModelDirection.js.map +1 -1
  68. package/lib-mjs/modelApi/block/toggleModelBlockQuote.d.ts +1 -1
  69. package/lib-mjs/modelApi/block/toggleModelBlockQuote.js +6 -4
  70. package/lib-mjs/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  71. package/lib-mjs/modelApi/common/retrieveModelFormatState.js +0 -2
  72. package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +1 -1
  73. package/lib-mjs/modelApi/common/wrapBlock.d.ts +2 -2
  74. package/lib-mjs/modelApi/common/wrapBlock.js +8 -4
  75. package/lib-mjs/modelApi/common/wrapBlock.js.map +1 -1
  76. package/lib-mjs/modelApi/link/matchLink.d.ts +29 -0
  77. package/lib-mjs/modelApi/link/matchLink.js +91 -0
  78. package/lib-mjs/modelApi/link/matchLink.js.map +1 -0
  79. package/lib-mjs/modelApi/list/setListType.d.ts +3 -1
  80. package/lib-mjs/modelApi/list/setListType.js +6 -9
  81. package/lib-mjs/modelApi/list/setListType.js.map +1 -1
  82. package/lib-mjs/publicApi/block/toggleBlockQuote.d.ts +1 -1
  83. package/lib-mjs/publicApi/block/toggleBlockQuote.js +10 -6
  84. package/lib-mjs/publicApi/block/toggleBlockQuote.js.map +1 -1
  85. package/lib-mjs/publicApi/entity/insertEntity.js +6 -10
  86. package/lib-mjs/publicApi/entity/insertEntity.js.map +1 -1
  87. package/lib-mjs/publicApi/format/getFormatState.d.ts +1 -21
  88. package/lib-mjs/publicApi/format/getFormatState.js +1 -67
  89. package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
  90. package/lib-mjs/publicApi/link/insertLink.js +2 -11
  91. package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
  92. package/lib-mjs/publicApi/segment/changeCapitalization.js +0 -1
  93. package/lib-mjs/publicApi/segment/changeCapitalization.js.map +1 -1
  94. package/package.json +4 -6
@@ -0,0 +1,91 @@
1
+ import { __values } from "tslib";
2
+ import { getObjectKeys } from 'roosterjs-content-model-dom';
3
+ // http exclude matching regex
4
+ // invalid URL example (in particular on IE and Edge):
5
+ // - http://www.bing.com%00, %00 before ? (question mark) is considered invalid. IE/Edge throws invalid argument exception
6
+ // - http://www.bing.com%1, %1 is invalid
7
+ // - http://www.bing.com%g, %g is invalid (IE and Edge expects a two hex value after a %)
8
+ // - http://www.bing.com%, % as ending is invalid (IE and Edge expects a two hex value after a %)
9
+ // All above % cases if they're after ? (question mark) is then considered valid again
10
+ // Similar for @, it needs to be after / (forward slash), or ? (question mark). Otherwise IE/Edge will throw security exception
11
+ // - http://www.bing.com@name, @name before ? (question mark) is considered invalid
12
+ // - http://www.bing.com/@name, is valid sine it is after / (forward slash)
13
+ // - http://www.bing.com?@name, is also valid since it is after ? (question mark)
14
+ // The regex below is essentially a break down of:
15
+ // ^[^?]+%[^0-9a-f]+ => to exclude URL like www.bing.com%%
16
+ // ^[^?]+%[0-9a-f][^0-9a-f]+ => to exclude URL like www.bing.com%1
17
+ // ^[^?]+%00 => to exclude URL like www.bing.com%00
18
+ // ^[^?]+%$ => to exclude URL like www.bing.com%
19
+ // ^https?:\/\/[^?\/]+@ => to exclude URL like http://www.bing.com@name
20
+ // ^www\.[^?\/]+@ => to exclude URL like www.bing.com@name
21
+ // , => to exclude url like www.bing,,com
22
+ var httpExcludeRegEx = /^[^?]+%[^0-9a-f]+|^[^?]+%[0-9a-f][^0-9a-f]+|^[^?]+%00|^[^?]+%$|^https?:\/\/[^?\/]+@|^www\.[^?\/]+@/i;
23
+ // via https://tools.ietf.org/html/rfc1035 Page 7
24
+ var labelRegEx = '[a-z0-9](?:[a-z0-9-]*[a-z0-9])?'; // We're using case insensitive regexps below so don't bother including A-Z
25
+ var domainNameRegEx = "(?:" + labelRegEx + "\\.)*" + labelRegEx;
26
+ var domainPortRegEx = domainNameRegEx + "(?:\\:[0-9]+)?";
27
+ var domainPortWithUrlRegEx = domainPortRegEx + "(?:[\\/\\?]\\S*)?";
28
+ var linkMatchRules = {
29
+ http: {
30
+ match: new RegExp("^(?:microsoft-edge:)?http:\\/\\/" + domainPortWithUrlRegEx + "|www\\." + domainPortWithUrlRegEx, 'i'),
31
+ except: httpExcludeRegEx,
32
+ normalizeUrl: function (url) {
33
+ return new RegExp('^(?:microsoft-edge:)?http:\\/\\/', 'i').test(url) ? url : 'http://' + url;
34
+ },
35
+ },
36
+ https: {
37
+ match: new RegExp("^(?:microsoft-edge:)?https:\\/\\/" + domainPortWithUrlRegEx, 'i'),
38
+ except: httpExcludeRegEx,
39
+ },
40
+ mailto: { match: new RegExp('^mailto:\\S+@\\S+\\.\\S+', 'i') },
41
+ notes: { match: new RegExp('^notes:\\/\\/\\S+', 'i') },
42
+ file: { match: new RegExp('^file:\\/\\/\\/?\\S+', 'i') },
43
+ unc: { match: new RegExp('^\\\\\\\\\\S+', 'i') },
44
+ ftp: {
45
+ match: new RegExp("^ftp:\\/\\/" + domainPortWithUrlRegEx + "|ftp\\." + domainPortWithUrlRegEx, 'i'),
46
+ normalizeUrl: function (url) { return (new RegExp('^ftp:\\/\\/', 'i').test(url) ? url : 'ftp://' + url); },
47
+ },
48
+ news: { match: new RegExp("^news:(\\/\\/)?" + domainPortWithUrlRegEx, 'i') },
49
+ telnet: { match: new RegExp("^telnet:(\\/\\/)?" + domainPortWithUrlRegEx, 'i') },
50
+ gopher: { match: new RegExp("^gopher:\\/\\/" + domainPortWithUrlRegEx, 'i') },
51
+ wais: { match: new RegExp("^wais:(\\/\\/)?" + domainPortWithUrlRegEx, 'i') },
52
+ };
53
+ /**
54
+ * @internal
55
+ * Try to match a given string with link match rules, return matched link
56
+ * @param url Input url to match
57
+ * @param option Link match option, exact or partial. If it is exact match, we need
58
+ * to check the length of matched link and url
59
+ * @param rules Optional link match rules, if not passed, only the default link match
60
+ * rules will be applied
61
+ * @returns The matched link data, or null if no match found.
62
+ * The link data includes an original url and a normalized url
63
+ */
64
+ export function matchLink(url) {
65
+ var e_1, _a;
66
+ if (url) {
67
+ try {
68
+ for (var _b = __values(getObjectKeys(linkMatchRules)), _c = _b.next(); !_c.done; _c = _b.next()) {
69
+ var schema = _c.value;
70
+ var rule = linkMatchRules[schema];
71
+ var matches = url.match(rule.match);
72
+ if (matches && matches[0] == url && (!rule.except || !rule.except.test(url))) {
73
+ return {
74
+ scheme: schema,
75
+ originalUrl: url,
76
+ normalizedUrl: rule.normalizeUrl ? rule.normalizeUrl(url) : url,
77
+ };
78
+ }
79
+ }
80
+ }
81
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
82
+ finally {
83
+ try {
84
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
85
+ }
86
+ finally { if (e_1) throw e_1.error; }
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+ //# sourceMappingURL=matchLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/link/matchLink.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AA4B5D,8BAA8B;AAC9B,sDAAsD;AACtD,0HAA0H;AAC1H,yCAAyC;AACzC,yFAAyF;AACzF,iGAAiG;AACjG,sFAAsF;AACtF,+HAA+H;AAC/H,mFAAmF;AACnF,2EAA2E;AAC3E,iFAAiF;AACjF,kDAAkD;AAClD,0DAA0D;AAC1D,kEAAkE;AAClE,mDAAmD;AACnD,gDAAgD;AAChD,uEAAuE;AACvE,0DAA0D;AAC1D,yCAAyC;AACzC,IAAM,gBAAgB,GAAG,qGAAqG,CAAC;AAE/H,iDAAiD;AACjD,IAAM,UAAU,GAAG,iCAAiC,CAAC,CAAC,2EAA2E;AACjI,IAAM,eAAe,GAAG,QAAM,UAAU,aAAQ,UAAY,CAAC;AAC7D,IAAM,eAAe,GAAM,eAAe,mBAAgB,CAA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AAwB,EAAE,GAAG,CAAC,EAAE;IAC5E,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,sBAAoB,sBAAwB,EAAE,GAAG,CAAC,EAAE;IAChF,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,mBAAiB,sBAAwB,EAAE,GAAG,CAAC,EAAE;IAC7E,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,oBAAkB,sBAAwB,EAAE,GAAG,CAAC,EAAE;CAC/E,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;;IACjC,IAAI,GAAG,EAAE;;YACL,KAAqB,IAAA,KAAA,SAAA,aAAa,CAAC,cAAc,CAAC,CAAA,gBAAA,4BAAE;gBAA/C,IAAM,MAAM,WAAA;gBACb,IAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;gBACpC,IAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACtC,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;oBAC1E,OAAO;wBACH,MAAM,EAAE,MAAM;wBACd,WAAW,EAAE,GAAG;wBAChB,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG;qBAClE,CAAC;iBACL;aACJ;;;;;;;;;KACJ;IAED,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { getObjectKeys } from 'roosterjs-content-model-dom';\n\n/**\n * @internal\n */\nexport interface LinkData {\n /**\n * Schema of a hyperlink\n */\n scheme: string;\n\n /**\n * Original url of a hyperlink\n */\n originalUrl: string;\n\n /**\n * Normalized url of a hyperlink\n */\n normalizedUrl: string;\n}\n\ninterface LinkMatchRule {\n match: RegExp;\n except?: RegExp;\n normalizeUrl?: (url: string) => string;\n}\n\n// http exclude matching regex\n// invalid URL example (in particular on IE and Edge):\n// - http://www.bing.com%00, %00 before ? (question mark) is considered invalid. IE/Edge throws invalid argument exception\n// - http://www.bing.com%1, %1 is invalid\n// - http://www.bing.com%g, %g is invalid (IE and Edge expects a two hex value after a %)\n// - http://www.bing.com%, % as ending is invalid (IE and Edge expects a two hex value after a %)\n// All above % cases if they're after ? (question mark) is then considered valid again\n// Similar for @, it needs to be after / (forward slash), or ? (question mark). Otherwise IE/Edge will throw security exception\n// - http://www.bing.com@name, @name before ? (question mark) is considered invalid\n// - http://www.bing.com/@name, is valid sine it is after / (forward slash)\n// - http://www.bing.com?@name, is also valid since it is after ? (question mark)\n// The regex below is essentially a break down of:\n// ^[^?]+%[^0-9a-f]+ => to exclude URL like www.bing.com%%\n// ^[^?]+%[0-9a-f][^0-9a-f]+ => to exclude URL like www.bing.com%1\n// ^[^?]+%00 => to exclude URL like www.bing.com%00\n// ^[^?]+%$ => to exclude URL like www.bing.com%\n// ^https?:\\/\\/[^?\\/]+@ => to exclude URL like http://www.bing.com@name\n// ^www\\.[^?\\/]+@ => to exclude URL like www.bing.com@name\n// , => to exclude url like www.bing,,com\nconst httpExcludeRegEx = /^[^?]+%[^0-9a-f]+|^[^?]+%[0-9a-f][^0-9a-f]+|^[^?]+%00|^[^?]+%$|^https?:\\/\\/[^?\\/]+@|^www\\.[^?\\/]+@/i;\n\n// via https://tools.ietf.org/html/rfc1035 Page 7\nconst labelRegEx = '[a-z0-9](?:[a-z0-9-]*[a-z0-9])?'; // We're using case insensitive regexps below so don't bother including A-Z\nconst domainNameRegEx = `(?:${labelRegEx}\\\\.)*${labelRegEx}`;\nconst domainPortRegEx = `${domainNameRegEx}(?:\\\\:[0-9]+)?`;\nconst domainPortWithUrlRegEx = `${domainPortRegEx}(?:[\\\\/\\\\?]\\\\S*)?`;\n\nconst linkMatchRules: Record<string, LinkMatchRule> = {\n http: {\n match: new RegExp(\n `^(?:microsoft-edge:)?http:\\\\/\\\\/${domainPortWithUrlRegEx}|www\\\\.${domainPortWithUrlRegEx}`,\n 'i'\n ),\n except: httpExcludeRegEx,\n normalizeUrl: url =>\n new RegExp('^(?:microsoft-edge:)?http:\\\\/\\\\/', 'i').test(url) ? url : 'http://' + url,\n },\n https: {\n match: new RegExp(`^(?:microsoft-edge:)?https:\\\\/\\\\/${domainPortWithUrlRegEx}`, 'i'),\n except: httpExcludeRegEx,\n },\n mailto: { match: new RegExp('^mailto:\\\\S+@\\\\S+\\\\.\\\\S+', 'i') },\n notes: { match: new RegExp('^notes:\\\\/\\\\/\\\\S+', 'i') },\n file: { match: new RegExp('^file:\\\\/\\\\/\\\\/?\\\\S+', 'i') },\n unc: { match: new RegExp('^\\\\\\\\\\\\\\\\\\\\S+', 'i') },\n ftp: {\n match: new RegExp(\n `^ftp:\\\\/\\\\/${domainPortWithUrlRegEx}|ftp\\\\.${domainPortWithUrlRegEx}`,\n 'i'\n ),\n normalizeUrl: url => (new RegExp('^ftp:\\\\/\\\\/', 'i').test(url) ? url : 'ftp://' + url),\n },\n news: { match: new RegExp(`^news:(\\\\/\\\\/)?${domainPortWithUrlRegEx}`, 'i') },\n telnet: { match: new RegExp(`^telnet:(\\\\/\\\\/)?${domainPortWithUrlRegEx}`, 'i') },\n gopher: { match: new RegExp(`^gopher:\\\\/\\\\/${domainPortWithUrlRegEx}`, 'i') },\n wais: { match: new RegExp(`^wais:(\\\\/\\\\/)?${domainPortWithUrlRegEx}`, 'i') },\n};\n\n/**\n * @internal\n * Try to match a given string with link match rules, return matched link\n * @param url Input url to match\n * @param option Link match option, exact or partial. If it is exact match, we need\n * to check the length of matched link and url\n * @param rules Optional link match rules, if not passed, only the default link match\n * rules will be applied\n * @returns The matched link data, or null if no match found.\n * The link data includes an original url and a normalized url\n */\nexport function matchLink(url: string): LinkData | null {\n if (url) {\n for (const schema of getObjectKeys(linkMatchRules)) {\n const rule = linkMatchRules[schema];\n const matches = url.match(rule.match);\n if (matches && matches[0] == url && (!rule.except || !rule.except.test(url))) {\n return {\n scheme: schema,\n originalUrl: url,\n normalizedUrl: rule.normalizeUrl ? rule.normalizeUrl(url) : url,\n };\n }\n }\n }\n\n return null;\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { ContentModelDocument } from 'roosterjs-content-model-types';
2
2
  /**
3
- * @internal
3
+ * Set a list type to content model
4
+ * @param model the model document
5
+ * @param listType the list type OL | UL
4
6
  */
5
7
  export declare function setListType(model: ContentModelDocument, listType: 'OL' | 'UL'): boolean;
@@ -1,7 +1,9 @@
1
1
  import { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';
2
2
  import { createListItem, createListLevel, normalizeContentModel, setParagraphNotImplicit, } from 'roosterjs-content-model-dom';
3
3
  /**
4
- * @internal
4
+ * Set a list type to content model
5
+ * @param model the model document
6
+ * @param listType the list type OL | UL
5
7
  */
6
8
  export function setListType(model, listType) {
7
9
  var paragraphOrListItems = getOperationalBlocks(model, ['ListItem'], [] // 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
@@ -14,7 +16,6 @@ export function setListType(model, listType) {
14
16
  : shouldIgnoreBlock(block);
15
17
  });
16
18
  var existingListItems = [];
17
- var hasIgnoredParagraphBefore = false;
18
19
  paragraphOrListItems.forEach(function (_a, itemIndex) {
19
20
  var _b, _c;
20
21
  var block = _a.block, parent = _a.parent;
@@ -58,9 +59,8 @@ export function setListType(model, listType) {
58
59
  : 1,
59
60
  direction: block.format.direction,
60
61
  textAlign: block.format.textAlign,
61
- marginTop: hasIgnoredParagraphBefore ? '0' : undefined,
62
- marginBlockEnd: '0px',
63
- marginBlockStart: '0px',
62
+ marginTop: '0px',
63
+ marginBottom: '0px',
64
64
  }),
65
65
  ],
66
66
  // For list bullet, we only want to carry over these formats from segments:
@@ -69,8 +69,6 @@ export function setListType(model, listType) {
69
69
  fontSize: segmentFormat.fontSize,
70
70
  textColor: segmentFormat.textColor,
71
71
  });
72
- // Since there is only one paragraph under the list item, no need to keep its paragraph element (DIV).
73
- // TODO: Do we need to keep the CSS styles applied to original DIV?
74
72
  if (block.blockType == 'Paragraph') {
75
73
  block.isImplicit = true;
76
74
  }
@@ -90,8 +88,7 @@ export function setListType(model, listType) {
90
88
  existingListItems.push(newListItem);
91
89
  }
92
90
  else {
93
- hasIgnoredParagraphBefore = true;
94
- existingListItems.forEach(function (x) { return (x.levels[0].format.marginBottom = '0'); });
91
+ existingListItems.forEach(function (x) { return (x.levels[0].format.marginBottom = '0px'); });
95
92
  existingListItems = [];
96
93
  }
97
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACxF,OAAO,EACH,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,uBAAuB,GAC1B,MAAM,6BAA6B,CAAC;AAOrC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAA2B,EAAE,QAAqB;IAC1E,IAAM,oBAAoB,GAAG,oBAAoB,CAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;KACpJ,CAAC;IACF,IAAM,qBAAqB,GAAG,oBAAoB,CAAC,KAAK,CAAC,UAAC,EAAS;;YAAP,KAAK,WAAA;QAC7D,OAAA,kBAAkB,CAAuB,KAAK,EAAE,UAAU,CAAC;YACvD,CAAC,CAAC,CAAA,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,QAAQ,KAAI,QAAQ;YAC7D,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA;KAAA,CACjC,CAAC;IACF,IAAI,iBAAiB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AW;YACZ,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;QACN;YACI,OAAO,IAAI,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport {\n createListItem,\n createListLevel,\n normalizeContentModel,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelDocument,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setListType(model: ContentModelDocument, listType: 'OL' | 'UL') {\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: ContentModelListItem[] = [];\n let hasIgnoredParagraphBefore = false;\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 if (block.format.marginLeft) {\n x.format.marginLeft = block.format.marginLeft;\n }\n\n if (block.format.marginRight) {\n x.format.marginRight = block.format.marginRight;\n }\n\n if (block.format.textAlign) {\n x.format.textAlign = block.format.textAlign;\n }\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 = 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 marginTop: hasIgnoredParagraphBefore ? '0' : undefined,\n marginBlockEnd: '0px',\n marginBlockStart: '0px',\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 // Since there is only one paragraph under the list item, no need to keep its paragraph element (DIV).\n // TODO: Do we need to keep the CSS styles applied to original DIV?\n if (block.blockType == 'Paragraph') {\n block.isImplicit = true;\n }\n\n newListItem.blocks.push(block);\n\n if (block.format.marginRight) {\n newListItem.format.marginRight = block.format.marginRight;\n block.format.marginRight = undefined;\n }\n if (block.format.marginLeft) {\n newListItem.format.marginLeft = block.format.marginLeft;\n block.format.marginLeft = undefined;\n }\n\n if (block.format.textAlign) {\n newListItem.format.textAlign = block.format.textAlign;\n }\n\n parent.blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n } else {\n hasIgnoredParagraphBefore = true;\n\n existingListItems.forEach(x => (x.levels[0].format.marginBottom = '0'));\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ContentModelBlock) {\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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,KAAK,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;oBAC5C,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;iBACvC;qBAAM;oBACH,iBAAiB,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAzC,CAAyC,CAAC,CAAC;oBAC1E,iBAAiB,GAAG,EAAE,CAAC;iBAC1B;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAwB;IAC/C,QAAQ,KAAK,CAAC,SAAS,EAAE;QACrB,KAAK,OAAO;YACR,OAAO,KAAK,CAAC;QACjB,KAAK,WAAW;YACZ,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;QACN;YACI,OAAO,IAAI,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport {\n createListItem,\n createListLevel,\n normalizeContentModel,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelDocument,\n ContentModelListItem,\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 */\nexport function setListType(model: ContentModelDocument, listType: 'OL' | 'UL') {\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: ContentModelListItem[] = [];\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 if (block.format.marginLeft) {\n x.format.marginLeft = block.format.marginLeft;\n }\n\n if (block.format.marginRight) {\n x.format.marginRight = block.format.marginRight;\n }\n\n if (block.format.textAlign) {\n x.format.textAlign = block.format.textAlign;\n }\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 = 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 marginTop: '0px',\n marginBottom: '0px',\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 block.isImplicit = true;\n }\n\n newListItem.blocks.push(block);\n\n if (block.format.marginRight) {\n newListItem.format.marginRight = block.format.marginRight;\n block.format.marginRight = undefined;\n }\n if (block.format.marginLeft) {\n newListItem.format.marginLeft = block.format.marginLeft;\n block.format.marginLeft = undefined;\n }\n\n if (block.format.textAlign) {\n newListItem.format.textAlign = block.format.textAlign;\n }\n\n parent.blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n } else {\n existingListItems.forEach(x => (x.levels[0].format.marginBottom = '0px'));\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ContentModelBlock) {\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"]}
@@ -6,4 +6,4 @@ import type { ContentModelFormatContainerFormat, IStandaloneEditor } from 'roost
6
6
  * @param editor The editor object to toggle BLOCKQUOTE onto
7
7
  * @param quoteFormat @optional Block format for the new quote object
8
8
  */
9
- export default function toggleBlockQuote(editor: IStandaloneEditor, quoteFormat?: ContentModelFormatContainerFormat): void;
9
+ export default function toggleBlockQuote(editor: IStandaloneEditor, quoteFormat?: ContentModelFormatContainerFormat, quoteFormatRtl?: ContentModelFormatContainerFormat): void;
@@ -1,15 +1,18 @@
1
1
  import { __assign } from "tslib";
2
2
  import { toggleModelBlockQuote } from '../../modelApi/block/toggleModelBlockQuote';
3
- var DefaultQuoteFormat = {
3
+ var DefaultQuoteFormatLtr = {
4
4
  borderLeft: '3px solid rgb(200, 200, 200)',
5
5
  textColor: 'rgb(102, 102, 102)',
6
6
  };
7
+ var DefaultQuoteFormatRtl = {
8
+ borderRight: '3px solid rgb(200, 200, 200)',
9
+ textColor: 'rgb(102, 102, 102)',
10
+ };
7
11
  var BuildInQuoteFormat = {
8
12
  marginTop: '1em',
9
13
  marginBottom: '1em',
10
14
  marginLeft: '40px',
11
15
  marginRight: '40px',
12
- paddingLeft: '10px',
13
16
  };
14
17
  /**
15
18
  * Toggle BLOCKQUOTE state of selected paragraphs.
@@ -18,13 +21,14 @@ var BuildInQuoteFormat = {
18
21
  * @param editor The editor object to toggle BLOCKQUOTE onto
19
22
  * @param quoteFormat @optional Block format for the new quote object
20
23
  */
21
- export default function toggleBlockQuote(editor, quoteFormat) {
22
- if (quoteFormat === void 0) { quoteFormat = DefaultQuoteFormat; }
23
- var fullQuoteFormat = __assign(__assign({}, BuildInQuoteFormat), quoteFormat);
24
+ export default function toggleBlockQuote(editor, quoteFormat, quoteFormatRtl) {
25
+ var _a;
26
+ var fullQuoteFormatLtr = __assign(__assign(__assign({}, BuildInQuoteFormat), { paddingLeft: '10px' }), (quoteFormat !== null && quoteFormat !== void 0 ? quoteFormat : DefaultQuoteFormatLtr));
27
+ var fullQuoteFormatRtl = __assign(__assign(__assign({}, BuildInQuoteFormat), { paddingRight: '10px', direction: 'rtl' }), ((_a = quoteFormatRtl !== null && quoteFormatRtl !== void 0 ? quoteFormatRtl : quoteFormat) !== null && _a !== void 0 ? _a : DefaultQuoteFormatRtl));
24
28
  editor.focus();
25
29
  editor.formatContentModel(function (model, context) {
26
30
  context.newPendingFormat = 'preserve';
27
- return toggleModelBlockQuote(model, fullQuoteFormat);
31
+ return toggleModelBlockQuote(model, fullQuoteFormatLtr, fullQuoteFormatRtl);
28
32
  }, {
29
33
  apiName: 'toggleBlockQuote',
30
34
  });
@@ -1 +1 @@
1
- {"version":3,"file":"toggleBlockQuote.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/block/toggleBlockQuote.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAMnF,IAAM,kBAAkB,GAAsC;IAC1D,UAAU,EAAE,8BAA8B;IAC1C,SAAS,EAAE,oBAAoB;CAClC,CAAC;AACF,IAAM,kBAAkB,GAAsC;IAC1D,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,KAAK;IACnB,UAAU,EAAE,MAAM;IAClB,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,MAAM;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACpC,MAAyB,EACzB,WAAmE;IAAnE,4BAAA,EAAA,gCAAmE;IAEnE,IAAM,eAAe,yBACd,kBAAkB,GAClB,WAAW,CACjB,CAAC;IAEF,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAEtC,OAAO,qBAAqB,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;IACzD,CAAC,EACD;QACI,OAAO,EAAE,kBAAkB;KAC9B,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { toggleModelBlockQuote } from '../../modelApi/block/toggleModelBlockQuote';\nimport type {\n ContentModelFormatContainerFormat,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\nconst DefaultQuoteFormat: ContentModelFormatContainerFormat = {\n borderLeft: '3px solid rgb(200, 200, 200)', // TODO: Support RTL\n textColor: 'rgb(102, 102, 102)',\n};\nconst BuildInQuoteFormat: ContentModelFormatContainerFormat = {\n marginTop: '1em',\n marginBottom: '1em',\n marginLeft: '40px',\n marginRight: '40px',\n paddingLeft: '10px',\n};\n\n/**\n * Toggle BLOCKQUOTE state of selected paragraphs.\n * If any selected paragraph is not under a BLOCKQUOTE, wrap them into a BLOCKQUOTE.\n * Otherwise, unwrap all related BLOCKQUOTEs.\n * @param editor The editor object to toggle BLOCKQUOTE onto\n * @param quoteFormat @optional Block format for the new quote object\n */\nexport default function toggleBlockQuote(\n editor: IStandaloneEditor,\n quoteFormat: ContentModelFormatContainerFormat = DefaultQuoteFormat\n) {\n const fullQuoteFormat = {\n ...BuildInQuoteFormat,\n ...quoteFormat,\n };\n\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n context.newPendingFormat = 'preserve';\n\n return toggleModelBlockQuote(model, fullQuoteFormat);\n },\n {\n apiName: 'toggleBlockQuote',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"toggleBlockQuote.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/block/toggleBlockQuote.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAMnF,IAAM,qBAAqB,GAAsC;IAC7D,UAAU,EAAE,8BAA8B;IAC1C,SAAS,EAAE,oBAAoB;CAClC,CAAC;AACF,IAAM,qBAAqB,GAAsC;IAC7D,WAAW,EAAE,8BAA8B;IAC3C,SAAS,EAAE,oBAAoB;CAClC,CAAC;AACF,IAAM,kBAAkB,GAAsC;IAC1D,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,KAAK;IACnB,UAAU,EAAE,MAAM;IAClB,WAAW,EAAE,MAAM;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACpC,MAAyB,EACzB,WAA+C,EAC/C,cAAkD;;IAElD,IAAM,kBAAkB,kCACjB,kBAAkB,KACrB,WAAW,EAAE,MAAM,KAChB,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,qBAAqB,CAAC,CAC5C,CAAC;IACF,IAAM,kBAAkB,kCACjB,kBAAkB,KACrB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,KAAK,KACb,CAAC,MAAA,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,WAAW,mCAAI,qBAAqB,CAAC,CAC9D,CAAC;IAEF,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAEtC,OAAO,qBAAqB,CAAC,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;IAChF,CAAC,EACD;QACI,OAAO,EAAE,kBAAkB;KAC9B,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { toggleModelBlockQuote } from '../../modelApi/block/toggleModelBlockQuote';\nimport type {\n ContentModelFormatContainerFormat,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\nconst DefaultQuoteFormatLtr: ContentModelFormatContainerFormat = {\n borderLeft: '3px solid rgb(200, 200, 200)',\n textColor: 'rgb(102, 102, 102)',\n};\nconst DefaultQuoteFormatRtl: ContentModelFormatContainerFormat = {\n borderRight: '3px solid rgb(200, 200, 200)',\n textColor: 'rgb(102, 102, 102)',\n};\nconst BuildInQuoteFormat: ContentModelFormatContainerFormat = {\n marginTop: '1em',\n marginBottom: '1em',\n marginLeft: '40px',\n marginRight: '40px',\n};\n\n/**\n * Toggle BLOCKQUOTE state of selected paragraphs.\n * If any selected paragraph is not under a BLOCKQUOTE, wrap them into a BLOCKQUOTE.\n * Otherwise, unwrap all related BLOCKQUOTEs.\n * @param editor The editor object to toggle BLOCKQUOTE onto\n * @param quoteFormat @optional Block format for the new quote object\n */\nexport default function toggleBlockQuote(\n editor: IStandaloneEditor,\n quoteFormat?: ContentModelFormatContainerFormat,\n quoteFormatRtl?: ContentModelFormatContainerFormat\n) {\n const fullQuoteFormatLtr: ContentModelFormatContainerFormat = {\n ...BuildInQuoteFormat,\n paddingLeft: '10px',\n ...(quoteFormat ?? DefaultQuoteFormatLtr),\n };\n const fullQuoteFormatRtl: ContentModelFormatContainerFormat = {\n ...BuildInQuoteFormat,\n paddingRight: '10px',\n direction: 'rtl',\n ...(quoteFormatRtl ?? quoteFormat ?? DefaultQuoteFormatRtl),\n };\n\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n context.newPendingFormat = 'preserve';\n\n return toggleModelBlockQuote(model, fullQuoteFormatLtr, fullQuoteFormatRtl);\n },\n {\n apiName: 'toggleBlockQuote',\n }\n );\n}\n"]}
@@ -21,16 +21,12 @@ export default function insertEntity(editor, type, isBlock, position, options) {
21
21
  }, {
22
22
  selectionOverride: typeof position === 'object' ? position : undefined,
23
23
  changeSource: ChangeSource.InsertEntity,
24
- getChangeData: function () {
25
- // TODO: Remove this entity when we have standalone editor
26
- var entity = {
27
- wrapper: wrapper,
28
- type: type,
29
- id: '',
30
- isReadonly: true,
31
- };
32
- return entity;
33
- },
24
+ getChangeData: function () { return ({
25
+ wrapper: wrapper,
26
+ type: type,
27
+ id: '',
28
+ isReadonly: true,
29
+ }); },
34
30
  apiName: 'insertEntity',
35
31
  });
36
32
  return entityModel;
@@ -1 +1 @@
1
- {"version":3,"file":"insertEntity.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/entity/insertEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAU5E,IAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,IAAM,eAAe,GAAG,MAAM,CAAC;AAwC/B,MAAM,CAAC,OAAO,UAAU,YAAY,CAChC,MAAyB,EACzB,IAAY,EACZ,OAAgB,EAChB,QAA8C,EAC9C,OAA6B;IAEvB,IAAA,KAAsE,OAAO,IAAI,EAAE,EAAjF,WAAW,iBAAA,EAAE,gBAAgB,sBAAA,EAAE,cAAc,oBAAA,EAAE,gBAAgB,sBAAkB,CAAC;IAC1F,IAAM,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;IAC/F,IAAM,OAAO,GAAG,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAEzE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC;IAEtD,IAAI,WAAW,EAAE;QACb,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;KACpC;IAED,IAAM,WAAW,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAE3F,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,iBAAiB,CACb,KAAK,EACL,WAAW,EACX,OAAO,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAChD,OAAO,EACP,gBAAgB,EAChB,OAAO,CACV,CAAC;QAEF,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QAC5C,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEtC,OAAO,IAAI,CAAC;IAChB,CAAC,EACD;QACI,iBAAiB,EAAE,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;QACtE,YAAY,EAAE,YAAY,CAAC,YAAY;QACvC,aAAa,EAAE;YACX,0DAA0D;YAC1D,IAAM,MAAM,GAAW;gBACnB,OAAO,SAAA;gBACP,IAAI,MAAA;gBACJ,EAAE,EAAE,EAAE;gBACN,UAAU,EAAE,IAAI;aACnB,CAAC;YAEF,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,OAAO,EAAE,cAAc;KAC1B,CACJ,CAAC;IAEF,OAAO,WAAW,CAAC;AACvB,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-core';\nimport { createEntity, normalizeContentModel } from 'roosterjs-content-model-dom';\nimport { insertEntityModel } from '../../modelApi/entity/insertEntityModel';\nimport type {\n ContentModelEntity,\n DOMSelection,\n InsertEntityPosition,\n InsertEntityOptions,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\nimport type { Entity } from 'roosterjs-editor-types';\n\nconst BlockEntityTag = 'div';\nconst InlineEntityTag = 'span';\n\n/**\n * Insert an entity into editor\n * @param editor The Content Model editor\n * @param type Type of entity\n * @param isBlock True to insert a block entity, false to insert an inline entity\n * @param position Position of the entity to insert. It can be\n * Value of InsertEntityPosition: see InsertEntityPosition\n * selectionRangeEx: Use this range instead of current focus position to insert. After insert, focus will be moved to\n * the beginning of this range (when focusAfterEntity is not set to true) or after the new entity (when focusAfterEntity is set to true)\n * @param options Move options to insert. See InsertEntityOptions\n */\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: boolean,\n position: 'focus' | 'begin' | 'end' | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null;\n\n/**\n * Insert a block entity into editor\n * @param editor The Content Model editor\n * @param type Type of entity\n * @param isBlock Must be true for a block entity\n * @param position Position of the entity to insert. It can be\n * Value of InsertEntityPosition: see InsertEntityPosition\n * selectionRangeEx: Use this range instead of current focus position to insert. After insert, focus will be moved to\n * the beginning of this range (when focusAfterEntity is not set to true) or after the new entity (when focusAfterEntity is set to true)\n * @param options Move options to insert. See InsertEntityOptions\n */\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: true,\n position: InsertEntityPosition | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null;\n\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: boolean,\n position?: InsertEntityPosition | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null {\n const { contentNode, focusAfterEntity, wrapperDisplay, skipUndoSnapshot } = options || {};\n const wrapper = editor.getDocument().createElement(isBlock ? BlockEntityTag : InlineEntityTag);\n const display = wrapperDisplay ?? (isBlock ? undefined : 'inline-block');\n\n wrapper.style.setProperty('display', display || null);\n\n if (contentNode) {\n wrapper.appendChild(contentNode);\n }\n\n const entityModel = createEntity(wrapper, true /*isReadonly*/, undefined /*format*/, type);\n\n editor.formatContentModel(\n (model, context) => {\n insertEntityModel(\n model,\n entityModel,\n typeof position == 'string' ? position : 'focus',\n isBlock,\n focusAfterEntity,\n context\n );\n\n normalizeContentModel(model);\n\n context.skipUndoSnapshot = skipUndoSnapshot;\n context.newEntities.push(entityModel);\n\n return true;\n },\n {\n selectionOverride: typeof position === 'object' ? position : undefined,\n changeSource: ChangeSource.InsertEntity,\n getChangeData: () => {\n // TODO: Remove this entity when we have standalone editor\n const entity: Entity = {\n wrapper,\n type,\n id: '',\n isReadonly: true,\n };\n\n return entity;\n },\n apiName: 'insertEntity',\n }\n );\n\n return entityModel;\n}\n"]}
1
+ {"version":3,"file":"insertEntity.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/entity/insertEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAS5E,IAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,IAAM,eAAe,GAAG,MAAM,CAAC;AAwC/B,MAAM,CAAC,OAAO,UAAU,YAAY,CAChC,MAAyB,EACzB,IAAY,EACZ,OAAgB,EAChB,QAA8C,EAC9C,OAA6B;IAEvB,IAAA,KAAsE,OAAO,IAAI,EAAE,EAAjF,WAAW,iBAAA,EAAE,gBAAgB,sBAAA,EAAE,cAAc,oBAAA,EAAE,gBAAgB,sBAAkB,CAAC;IAC1F,IAAM,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;IAC/F,IAAM,OAAO,GAAG,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAEzE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC;IAEtD,IAAI,WAAW,EAAE;QACb,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;KACpC;IAED,IAAM,WAAW,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAE3F,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,iBAAiB,CACb,KAAK,EACL,WAAW,EACX,OAAO,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAChD,OAAO,EACP,gBAAgB,EAChB,OAAO,CACV,CAAC;QAEF,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QAC5C,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEtC,OAAO,IAAI,CAAC;IAChB,CAAC,EACD;QACI,iBAAiB,EAAE,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;QACtE,YAAY,EAAE,YAAY,CAAC,YAAY;QACvC,aAAa,EAAE,cAAM,OAAA,CAAC;YAClB,OAAO,SAAA;YACP,IAAI,MAAA;YACJ,EAAE,EAAE,EAAE;YACN,UAAU,EAAE,IAAI;SACnB,CAAC,EALmB,CAKnB;QACF,OAAO,EAAE,cAAc;KAC1B,CACJ,CAAC;IAEF,OAAO,WAAW,CAAC;AACvB,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-core';\nimport { createEntity, normalizeContentModel } from 'roosterjs-content-model-dom';\nimport { insertEntityModel } from '../../modelApi/entity/insertEntityModel';\nimport type {\n ContentModelEntity,\n DOMSelection,\n InsertEntityPosition,\n InsertEntityOptions,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\nconst BlockEntityTag = 'div';\nconst InlineEntityTag = 'span';\n\n/**\n * Insert an entity into editor\n * @param editor The Content Model editor\n * @param type Type of entity\n * @param isBlock True to insert a block entity, false to insert an inline entity\n * @param position Position of the entity to insert. It can be\n * Value of InsertEntityPosition: see InsertEntityPosition\n * selectionRangeEx: Use this range instead of current focus position to insert. After insert, focus will be moved to\n * the beginning of this range (when focusAfterEntity is not set to true) or after the new entity (when focusAfterEntity is set to true)\n * @param options Move options to insert. See InsertEntityOptions\n */\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: boolean,\n position: 'focus' | 'begin' | 'end' | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null;\n\n/**\n * Insert a block entity into editor\n * @param editor The Content Model editor\n * @param type Type of entity\n * @param isBlock Must be true for a block entity\n * @param position Position of the entity to insert. It can be\n * Value of InsertEntityPosition: see InsertEntityPosition\n * selectionRangeEx: Use this range instead of current focus position to insert. After insert, focus will be moved to\n * the beginning of this range (when focusAfterEntity is not set to true) or after the new entity (when focusAfterEntity is set to true)\n * @param options Move options to insert. See InsertEntityOptions\n */\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: true,\n position: InsertEntityPosition | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null;\n\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: boolean,\n position?: InsertEntityPosition | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null {\n const { contentNode, focusAfterEntity, wrapperDisplay, skipUndoSnapshot } = options || {};\n const wrapper = editor.getDocument().createElement(isBlock ? BlockEntityTag : InlineEntityTag);\n const display = wrapperDisplay ?? (isBlock ? undefined : 'inline-block');\n\n wrapper.style.setProperty('display', display || null);\n\n if (contentNode) {\n wrapper.appendChild(contentNode);\n }\n\n const entityModel = createEntity(wrapper, true /*isReadonly*/, undefined /*format*/, type);\n\n editor.formatContentModel(\n (model, context) => {\n insertEntityModel(\n model,\n entityModel,\n typeof position == 'string' ? position : 'focus',\n isBlock,\n focusAfterEntity,\n context\n );\n\n normalizeContentModel(model);\n\n context.skipUndoSnapshot = skipUndoSnapshot;\n context.newEntities.push(entityModel);\n\n return true;\n },\n {\n selectionOverride: typeof position === 'object' ? position : undefined,\n changeSource: ChangeSource.InsertEntity,\n getChangeData: () => ({\n wrapper,\n type,\n id: '',\n isReadonly: true,\n }),\n apiName: 'insertEntity',\n }\n );\n\n return entityModel;\n}\n"]}
@@ -1,26 +1,6 @@
1
- import type { IStandaloneEditor, ContentModelBlockGroup, ContentModelFormatState, DomToModelContext } from 'roosterjs-content-model-types';
1
+ import type { IStandaloneEditor, ContentModelFormatState } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Get current format state
4
4
  * @param editor The editor to get format from
5
5
  */
6
6
  export default function getFormatState(editor: IStandaloneEditor): ContentModelFormatState;
7
- /**
8
- * @internal
9
- */
10
- interface FormatStateContext extends DomToModelContext {
11
- /**
12
- * An optional stack of parent elements to process. When provided, the child nodes of current parent element will be ignored,
13
- * but use the top element in this stack instead in childProcessor.
14
- */
15
- nodeStack?: Node[];
16
- }
17
- /**
18
- * @internal
19
- * Export for test only
20
- * In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create
21
- * content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.
22
- * This "reduced" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,
23
- * then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state
24
- */
25
- export declare function reducedModelChildProcessor(group: ContentModelBlockGroup, parent: ParentNode, context: FormatStateContext): void;
26
- export {};
@@ -1,84 +1,18 @@
1
- import { __read } from "tslib";
2
- import { getSelectionRootNode } from 'roosterjs-content-model-core';
3
1
  import { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState';
4
- import { getRegularSelectionOffsets, handleRegularSelection, isNodeOfType, processChildNode, } from 'roosterjs-content-model-dom';
5
2
  /**
6
3
  * Get current format state
7
4
  * @param editor The editor to get format from
8
5
  */
9
6
  export default function getFormatState(editor) {
10
7
  var pendingFormat = editor.getPendingFormat();
11
- var model = editor.createContentModel({
12
- processorOverride: {
13
- child: reducedModelChildProcessor,
14
- },
15
- });
8
+ var model = editor.getContentModelCopy('reduced');
16
9
  var manager = editor.getSnapshotsManager();
17
10
  var result = {
18
11
  canUndo: manager.hasNewContent || manager.canMove(-1),
19
12
  canRedo: manager.canMove(1),
20
13
  isDarkMode: editor.isDarkMode(),
21
- zoomScale: editor.getZoomScale(),
22
14
  };
23
15
  retrieveModelFormatState(model, pendingFormat, result);
24
16
  return result;
25
17
  }
26
- /**
27
- * @internal
28
- * Export for test only
29
- * In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create
30
- * content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.
31
- * This "reduced" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,
32
- * then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state
33
- */
34
- export function reducedModelChildProcessor(group, parent, context) {
35
- if (!context.nodeStack) {
36
- var selectionRootNode = getSelectionRootNode(context.selection);
37
- context.nodeStack = selectionRootNode ? createNodeStack(parent, selectionRootNode) : [];
38
- }
39
- var stackChild = context.nodeStack.pop();
40
- if (stackChild) {
41
- var _a = __read(getRegularSelectionOffsets(context, parent), 2), nodeStartOffset = _a[0], nodeEndOffset = _a[1];
42
- // If selection is not on this node, skip getting node index to save some time since we don't need it here
43
- var index = nodeStartOffset >= 0 || nodeEndOffset >= 0 ? getChildIndex(parent, stackChild) : -1;
44
- if (index >= 0) {
45
- handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);
46
- }
47
- processChildNode(group, stackChild, context);
48
- if (index >= 0) {
49
- handleRegularSelection(index + 1, context, group, nodeStartOffset, nodeEndOffset);
50
- }
51
- }
52
- else {
53
- // No child node from node stack, that means we have reached the deepest node of selection.
54
- // Now we can use default child processor to perform full sub tree scanning for content model,
55
- // So that all selected node will be included.
56
- context.defaultElementProcessors.child(group, parent, context);
57
- }
58
- }
59
- function createNodeStack(root, startNode) {
60
- var result = [];
61
- var node = startNode;
62
- while (node && root != node && root.contains(node)) {
63
- if (isNodeOfType(node, 'ELEMENT_NODE') && node.tagName == 'TABLE') {
64
- // For table, we can't do a reduced model creation since we need to handle their cells and indexes,
65
- // so clean up whatever we already have, and just put table into the stack
66
- result.splice(0, result.length, node);
67
- }
68
- else {
69
- result.push(node);
70
- }
71
- node = node.parentNode;
72
- }
73
- return result;
74
- }
75
- function getChildIndex(parent, stackChild) {
76
- var index = 0;
77
- var child = parent.firstChild;
78
- while (child && child != stackChild) {
79
- index++;
80
- child = child.nextSibling;
81
- }
82
- return index;
83
- }
84
18
  //# sourceMappingURL=getFormatState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAQ1F,OAAO,EACH,0BAA0B,EAC1B,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,GACnB,MAAM,6BAA6B,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,MAAyB;IAC5D,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAChD,IAAM,KAAK,GAAG,MAAM,CAAC,kBAAkB,CAAC;QACpC,iBAAiB,EAAE;YACf,KAAK,EAAE,0BAA0B;SACpC;KACJ,CAAC,CAAC;IACH,IAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC;IAC7C,IAAM,MAAM,GAA4B;QACpC,OAAO,EAAE,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACrD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC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CAAC;SACrF;KACJ;SAAM;QACH,2FAA2F;QAC3F,8FAA8F;QAC9F,8CAA8C;QAC9C,OAAO,CAAC,wBAAwB,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;KAClE;AACL,CAAC;AAED,SAAS,eAAe,CAAC,IAAU,EAAE,SAAe;IAChD,IAAM,MAAM,GAAW,EAAE,CAAC;IAC1B,IAAI,IAAI,GAAgB,SAAS,CAAC;IAElC,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAChD,IAAI,YAAY,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,EAAE;YAC/D,mGAAmG;YACnG,0EAA0E;YAC1E,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SACzC;aAAM;YACH,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACrB;QAED,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;KAC1B;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,aAAa,CAAC,MAAkB,EAAE,UAAgB;IACvD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC;IAE9B,OAAO,KAAK,IAAI,KAAK,IAAI,UAAU,EAAE;QACjC,KAAK,EAAE,CAAC;QACR,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC;KAC7B;IACD,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { getSelectionRootNode } from 'roosterjs-content-model-core';\nimport { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState';\nimport type {\n IStandaloneEditor,\n ContentModelBlockGroup,\n ContentModelFormatState,\n DomToModelContext,\n} from 'roosterjs-content-model-types';\n\nimport {\n getRegularSelectionOffsets,\n handleRegularSelection,\n isNodeOfType,\n processChildNode,\n} from 'roosterjs-content-model-dom';\n\n/**\n * Get current format state\n * @param editor The editor to get format from\n */\nexport default function getFormatState(editor: IStandaloneEditor): ContentModelFormatState {\n const pendingFormat = editor.getPendingFormat();\n const model = editor.createContentModel({\n processorOverride: {\n child: reducedModelChildProcessor,\n },\n });\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 zoomScale: editor.getZoomScale(),\n };\n\n retrieveModelFormatState(model, pendingFormat, result);\n\n return result;\n}\n\n/**\n * @internal\n */\ninterface FormatStateContext extends DomToModelContext {\n /**\n * An optional stack of parent elements to process. When provided, the child nodes of current parent element will be ignored,\n * but use the top element in this stack instead in childProcessor.\n */\n nodeStack?: Node[];\n}\n\n/**\n * @internal\n * Export for test only\n * In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create\n * content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.\n * This \"reduced\" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,\n * then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state\n */\nexport function reducedModelChildProcessor(\n group: ContentModelBlockGroup,\n parent: ParentNode,\n context: FormatStateContext\n) {\n if (!context.nodeStack) {\n const selectionRootNode = getSelectionRootNode(context.selection);\n context.nodeStack = selectionRootNode ? createNodeStack(parent, selectionRootNode) : [];\n }\n\n const stackChild = context.nodeStack.pop();\n\n if (stackChild) {\n const [nodeStartOffset, nodeEndOffset] = getRegularSelectionOffsets(context, parent);\n\n // If selection is not on this node, skip getting node index to save some time since we don't need it here\n const index =\n nodeStartOffset >= 0 || nodeEndOffset >= 0 ? getChildIndex(parent, stackChild) : -1;\n\n if (index >= 0) {\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);\n }\n\n processChildNode(group, stackChild, context);\n\n if (index >= 0) {\n handleRegularSelection(index + 1, context, group, nodeStartOffset, nodeEndOffset);\n }\n } else {\n // No child node from node stack, that means we have reached the deepest node of selection.\n // Now we can use default child processor to perform full sub tree scanning for content model,\n // So that all selected node will be included.\n context.defaultElementProcessors.child(group, parent, context);\n }\n}\n\nfunction createNodeStack(root: Node, startNode: Node): Node[] {\n const result: Node[] = [];\n let node: Node | null = startNode;\n\n while (node && root != node && root.contains(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && node.tagName == 'TABLE') {\n // For table, we can't do a reduced model creation since we need to handle their cells and indexes,\n // so clean up whatever we already have, and just put table into the stack\n result.splice(0, result.length, node);\n } else {\n result.push(node);\n }\n\n node = node.parentNode;\n }\n\n return result;\n}\n\nfunction getChildIndex(parent: ParentNode, stackChild: Node) {\n let index = 0;\n let child = parent.firstChild;\n\n while (child && child != stackChild) {\n index++;\n child = child.nextSibling;\n }\n return index;\n}\n"]}
1
+ {"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAG1F;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,MAAyB;IAC5D,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAChD,IAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACpD,IAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC;IAC7C,IAAM,MAAM,GAA4B;QACpC,OAAO,EAAE,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACrD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;KAClC,CAAC;IAEF,wBAAwB,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAEvD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState';\nimport type { IStandaloneEditor, ContentModelFormatState } from 'roosterjs-content-model-types';\n\n/**\n * Get current format state\n * @param editor The editor to get format from\n */\nexport default function getFormatState(editor: IStandaloneEditor): ContentModelFormatState {\n const pendingFormat = editor.getPendingFormat();\n const model = editor.getContentModelCopy('reduced');\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 retrieveModelFormatState(model, pendingFormat, result);\n\n return result;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { __assign } from "tslib";
2
2
  import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';
3
3
  import { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';
4
- import { HtmlSanitizer, matchLink } from 'roosterjs-editor-dom';
4
+ import { matchLink } from '../../modelApi/link/matchLink';
5
5
  import { addLink, addSegment, createContentModelDocument, createText, } from 'roosterjs-content-model-dom';
6
6
  // Regex matching Uri scheme
7
7
  var URI_REGEX = /^[a-zA-Z]+:/i;
@@ -87,7 +87,6 @@ var createLink = function (url, anchorTitle, target, underline) {
87
87
  },
88
88
  };
89
89
  };
90
- // TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.
91
90
  function applyLinkPrefix(url) {
92
91
  if (!url) {
93
92
  return url;
@@ -112,15 +111,7 @@ function applyLinkPrefix(url) {
112
111
  }
113
112
  return prefix + url;
114
113
  }
115
- // TODO: This is copied from original code. However, ContentModel should be able to filter out malicious
116
- // attributes later, so no need to use HtmlSanitizer here
117
114
  function checkXss(link) {
118
- var sanitizer = new HtmlSanitizer();
119
- var a = document.createElement('a');
120
- a.href = link || '';
121
- sanitizer.sanitize(a);
122
- // We use getAttribute because some browsers will try to make the href property a valid link.
123
- // This has unintended side effects when the link lacks a protocol.
124
- return a.getAttribute('href') || '';
115
+ return link.match(/s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : link;
125
116
  }
126
117
  //# sourceMappingURL=insertLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uDAAuD,CAAC;AACrG,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EACH,OAAO,EACP,UAAU,EACV,0BAA0B,EAC1B,UAAU,GACb,MAAM,6BAA6B,CAAC;AAErC,4BAA4B;AAC5B,IAAM,SAAS,GAAG,cAAc,CAAC;AACjC,wCAAwC;AACxC,IAAM,YAAY,GAAG,cAAc,CAAC;AACpC,sDAAsD;AACtD,IAAM,SAAS,GAAG,SAAS,CAAC;AAE5B;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAC9B,MAAyB,EACzB,IAAY,EACZ,WAAoB,EACpB,WAAoB,EACpB,MAAe;IAEf,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,GAAG,EAAE;QACL,IAAM,UAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAChC,IAAM,SAAO,GAAG,UAAQ,CAAC,CAAC,CAAC,UAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACzE,IAAM,OAAK,GAAuB,EAAE,CAAC;QACrC,IAAI,YAA4B,CAAC;QAEjC,MAAM,CAAC,kBAAkB,CAC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GAAW;IAChC,IAAI,CAAC,GAAG,EAAE;QACN,OAAO,GAAG,CAAC;KACd;IAED,4BAA4B;IAC5B,oEAAoE;IACpE,iEAAiE;IACjE,qDAAqD;IACrD,+BAA+B;IAC/B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;QAC3B,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;YAC/B,MAAM,GAAG,SAAS,CAAC;SACtB;aAAM,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YACnC,MAAM,GAAG,QAAQ,CAAC;SACrB;aAAM;YACH,sBAAsB;YACtB,MAAM,GAAG,SAAS,CAAC;SACtB;KACJ;IAED,OAAO,MAAM,GAAG,GAAG,CAAC;AACxB,CAAC;AAED,wGAAwG;AACxG,yDAAyD;AACzD,SAAS,QAAQ,CAAC,IAAY;IAC1B,IAAM,SAAS,GAAG,IAAI,aAAa,EAAE,CAAC;IACtC,IAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAEtC,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAEpB,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,6FAA6F;IAC7F,mEAAmE;IACnE,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';\nimport { HtmlSanitizer, matchLink } from 'roosterjs-editor-dom';\nimport type { ContentModelLink, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n addLink,\n addSegment,\n createContentModelDocument,\n createText,\n} from 'roosterjs-content-model-dom';\n\n// Regex matching Uri scheme\nconst URI_REGEX = /^[a-zA-Z]+:/i;\n// Regex matching begin of email address\nconst MAILTO_REGEX = /^[\\w.%+-]+@/i;\n// Regex matching begin of ftp, i.e. ftp.microsoft.com\nconst FTP_REGEX = /^ftp\\./i;\n\n/**\n * Insert a hyperlink at cursor.\n * When there is a selection, hyperlink will be applied to the selection,\n * otherwise a hyperlink will be inserted to the cursor position.\n * @param editor Editor object\n * @param link Link address, can be http(s), mailto, notes, file, unc, ftp, news, telnet, gopher, wais.\n * When protocol is not specified, a best matched protocol will be predicted.\n * @param anchorTitle Optional alt text of the link, will be shown when hover on the link\n * @param displayText Optional display text for the link.\n * @param target Optional display target for the link (\"_blank\"|\"_self\"|\"_parent\"|\"_top\"|\"{framename}\")\n * If specified, the display text of link will be replaced with this text.\n * If not specified and there wasn't a link, the link url will be used as display text.\n */\nexport default function insertLink(\n editor: IStandaloneEditor,\n link: string,\n anchorTitle?: string,\n displayText?: string,\n target?: string\n) {\n editor.focus();\n\n const url = (checkXss(link) || '').trim();\n if (url) {\n const linkData = matchLink(url);\n const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);\n const links: ContentModelLink[] = [];\n let anchorNode: Node | undefined;\n\n editor.formatContentModel(\n (model, context) => {\n const segments = getSelectedSegments(model, false /*includingFormatHolder*/);\n const originalText = segments\n .map(x => (x.segmentType == 'Text' ? x.text : ''))\n .join('');\n const text = displayText || originalText || '';\n\n if (\n segments.some(x => x.segmentType != 'SelectionMarker') &&\n originalText == text\n ) {\n segments.forEach(x => {\n const link = createLink(\n linkUrl,\n anchorTitle,\n target,\n x.segmentType == 'Text'\n );\n addLink(x, link);\n if (x.link) {\n links.push(x.link);\n }\n });\n } else if (\n segments.every(x => x.segmentType == 'SelectionMarker') ||\n (!!text && text != originalText)\n ) {\n const segment = createText(text || (linkData ? linkData.originalUrl : url), {\n ...segments[0]?.format,\n ...editor.getPendingFormat(),\n });\n const doc = createContentModelDocument();\n const link = createLink(linkUrl, anchorTitle, target);\n\n addLink(segment, link);\n addSegment(doc, segment);\n\n if (segment.link) {\n links.push(segment.link);\n }\n\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n }\n\n adjustTrailingSpaceSelection(model);\n return segments.length > 0;\n },\n {\n changeSource: ChangeSource.CreateLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n apiName: 'insertLink',\n }\n );\n }\n}\n\nconst createLink = (\n url: string,\n anchorTitle?: string,\n target?: string,\n underline: boolean = true\n): ContentModelLink => {\n return {\n dataset: {},\n format: {\n href: url,\n anchorTitle,\n target,\n underline: underline,\n },\n };\n};\n\n// TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.\nfunction applyLinkPrefix(url: string): string {\n if (!url) {\n return url;\n }\n\n // Add link prefix per rule:\n // (a) if the url always starts with a URI scheme, leave it as it is\n // (b) if the url is an email address, xxx@... add mailto: prefix\n // (c) if the url starts with ftp., add ftp:// prefix\n // (d) rest, add http:// prefix\n let prefix = '';\n if (url.search(URI_REGEX) < 0) {\n if (url.search(MAILTO_REGEX) == 0) {\n prefix = 'mailto:';\n } else if (url.search(FTP_REGEX) == 0) {\n prefix = 'ftp://';\n } else {\n // fallback to http://\n prefix = 'http://';\n }\n }\n\n return prefix + url;\n}\n\n// TODO: This is copied from original code. However, ContentModel should be able to filter out malicious\n// attributes later, so no need to use HtmlSanitizer here\nfunction checkXss(link: string): string {\n const sanitizer = new HtmlSanitizer();\n const a = document.createElement('a');\n\n a.href = link || '';\n\n sanitizer.sanitize(a);\n // We use getAttribute because some browsers will try to make the href property a valid link.\n // This has unintended side effects when the link lacks a protocol.\n return a.getAttribute('href') || '';\n}\n"]}
1
+ {"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,4BAA4B,EAAE,M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/B,MAAM,GAAG,SAAS,CAAC;SACtB;aAAM,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YACnC,MAAM,GAAG,QAAQ,CAAC;SACrB;aAAM;YACH,sBAAsB;YACtB,MAAM,GAAG,SAAS,CAAC;SACtB;KACJ;IAED,OAAO,MAAM,GAAG,GAAG,CAAC;AACxB,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';\nimport { matchLink } from '../../modelApi/link/matchLink';\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\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\nfunction checkXss(link: string): string {\n return link.match(/s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : link;\n}\n"]}
@@ -28,7 +28,6 @@ export default function changeCapitalization(editor, capitalization, language) {
28
28
  segment.text = wordArray.join(' ');
29
29
  break;
30
30
  case 'sentence':
31
- // TODO: Add rules on punctuation for internationalization - TASK 104769
32
31
  var punctuationMarks = '[\\.\\!\\?]';
33
32
  // Find a match of a word character either:
34
33
  // - At the beginning of a string with or without preceding whitespace, for
@@ -1 +1 @@
1
- {"version":3,"file":"changeCapitalization.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/segment/changeCapitalization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAGvF;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CACxC,MAAyB,EACzB,cAAqE,EACrE,QAAiB;IAEjB,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,6BAA6B,CAAC,MAAM,EAAE,sBAAsB,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,OAAO;QACzE,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,MAAM,EAAE;YAChC,QAAQ,cAAc,EAAE;gBACpB,KAAK,WAAW;oBACZ,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;oBACxD,MAAM;gBAEV,KAAK,WAAW;oBACZ,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;oBACxD,MAAM;gBAEV,KAAK,YAAY;oBACb,IAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBAEtE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBACvC,SAAS,CAAC,CAAC,CAAC;4BACR,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC;gCAClD,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;qBAC7B;oBAED,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACnC,MAAM;gBAEV,KAAK,UAAU;oBACX,wEAAwE;oBACxE,IAAM,gBAAgB,GAAG,aAAa,CAAC;oBACvC,2CAA2C;oBAC3C,2EAA2E;oBAC3E,2EAA2E;oBAC3E,uEAAuE;oBACvE,sDAAsD;oBACtD,IAAM,KAAK,GAAG,IAAI,MAAM,CAAC,WAAW,GAAG,gBAAgB,GAAG,SAAS,EAAE,GAAG,CAAC,CAAC;oBAE1E,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI;yBACtB,iBAAiB,CAAC,QAAQ,CAAC;yBAC3B,OAAO,CAAC,KAAK,EAAE,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAjC,CAAiC,CAAC,CAAC;oBAChE,MAAM;aACb;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Change the capitalization of text in the selection\n * @param editor The editor instance\n * @param capitalization The case option\n * @param language Optional parameter for language string that should comply to \"IETF BCP 47 Tags for\n * Identifying Languages\". For example: 'en' or 'en-US' for English, 'tr' for Turkish.\n * Default is the host environment’s current locale.\n */\nexport default function changeCapitalization(\n editor: IStandaloneEditor,\n capitalization: 'sentence' | 'lowerCase' | 'upperCase' | 'capitalize',\n language?: string\n) {\n editor.focus();\n\n formatSegmentWithContentModel(editor, 'changeCapitalization', (_, __, segment) => {\n if (segment?.segmentType == 'Text') {\n switch (capitalization) {\n case 'lowerCase':\n segment.text = segment.text.toLocaleLowerCase(language);\n break;\n\n case 'upperCase':\n segment.text = segment.text.toLocaleUpperCase(language);\n break;\n\n case 'capitalize':\n const wordArray = segment.text.toLocaleLowerCase(language).split(' ');\n\n for (let i = 0; i < wordArray.length; i++) {\n wordArray[i] =\n wordArray[i].charAt(0).toLocaleUpperCase(language) +\n wordArray[i].slice(1);\n }\n\n segment.text = wordArray.join(' ');\n break;\n\n case 'sentence':\n // TODO: Add rules on punctuation for internationalization - TASK 104769\n const punctuationMarks = '[\\\\.\\\\!\\\\?]';\n // Find a match of a word character either:\n // - At the beginning of a string with or without preceding whitespace, for\n // example: ' hello world' and 'hello world' strings would both match 'h'.\n // - Or preceded by a punctuation mark and at least one whitespace, for\n // example 'yes. hello world' would match 'y' and 'h'.\n const regex = new RegExp('^\\\\s*\\\\w|' + punctuationMarks + '\\\\s+\\\\w', 'g');\n\n segment.text = segment.text\n .toLocaleLowerCase(language)\n .replace(regex, match => match.toLocaleUpperCase(language));\n break;\n }\n }\n });\n}\n"]}
1
+ {"version":3,"file":"changeCapitalization.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/segment/changeCapitalization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAGvF;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CACxC,MAAyB,EACzB,cAAqE,EACrE,QAAiB;I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AAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI;yBACtB,iBAAiB,CAAC,QAAQ,CAAC;yBAC3B,OAAO,CAAC,KAAK,EAAE,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAjC,CAAiC,CAAC,CAAC;oBAChE,MAAM;aACb;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Change the capitalization of text in the selection\n * @param editor The editor instance\n * @param capitalization The case option\n * @param language Optional parameter for language string that should comply to \"IETF BCP 47 Tags for\n * Identifying Languages\". For example: 'en' or 'en-US' for English, 'tr' for Turkish.\n * Default is the host environment’s current locale.\n */\nexport default function changeCapitalization(\n editor: IStandaloneEditor,\n capitalization: 'sentence' | 'lowerCase' | 'upperCase' | 'capitalize',\n language?: string\n) {\n editor.focus();\n\n formatSegmentWithContentModel(editor, 'changeCapitalization', (_, __, segment) => {\n if (segment?.segmentType == 'Text') {\n switch (capitalization) {\n case 'lowerCase':\n segment.text = segment.text.toLocaleLowerCase(language);\n break;\n\n case 'upperCase':\n segment.text = segment.text.toLocaleUpperCase(language);\n break;\n\n case 'capitalize':\n const wordArray = segment.text.toLocaleLowerCase(language).split(' ');\n\n for (let i = 0; i < wordArray.length; i++) {\n wordArray[i] =\n wordArray[i].charAt(0).toLocaleUpperCase(language) +\n wordArray[i].slice(1);\n }\n\n segment.text = wordArray.join(' ');\n break;\n\n case 'sentence':\n const punctuationMarks = '[\\\\.\\\\!\\\\?]';\n // Find a match of a word character either:\n // - At the beginning of a string with or without preceding whitespace, for\n // example: ' hello world' and 'hello world' strings would both match 'h'.\n // - Or preceded by a punctuation mark and at least one whitespace, for\n // example 'yes. hello world' would match 'y' and 'h'.\n const regex = new RegExp('^\\\\s*\\\\w|' + punctuationMarks + '\\\\s+\\\\w', 'g');\n\n segment.text = segment.text\n .toLocaleLowerCase(language)\n .replace(regex, match => match.toLocaleUpperCase(language));\n break;\n }\n }\n });\n}\n"]}