roosterjs-content-model-api 9.48.0 → 9.50.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.
@@ -78,6 +78,10 @@ function setListType(model, listType, removeMargins) {
78
78
  fontSize: segmentFormat.fontSize,
79
79
  textColor: segmentFormat.textColor,
80
80
  });
81
+ if (removeMargins) {
82
+ newListItem.format.marginBottom = '0px';
83
+ newListItem.format.marginTop = '0px';
84
+ }
81
85
  if (block.blockType == 'Paragraph') {
82
86
  (0, roosterjs_content_model_dom_1.setParagraphNotImplicit)(block);
83
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;AAAA,iEAAoE;AACpE,kFAAiF;AACjF,2EAaqC;AASrC;;;;;GAKG;AACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;IAA9B,8BAAA,EAAA,qBAA8B;IAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;IAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,EAC7C,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,IAAA,gDAAkB,EAA+B,KAAK,EAAE,UAAU,CAAC;YAC/D,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,GAAmC,EAAE,CAAC;IAE3D,oBAAoB,CAAC,OAAO,CAAC,UAAC,EAAiB,EAAE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CAAC;AAlID,kCAkIC;AAED,SAAS,iBAAiB,CAAC,KAAgC;IACvD,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 { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;AAAA,iEAAoE;AACpE,kFAAiF;AACjF,2EAaqC;AASrC;;;;;GAKG;AACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;IAA9B,8BAAA,EAAA,qBAA8B;IAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;IAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,EAC7C,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,IAAA,gDAAkB,EAA+B,KAAK,EAAE,UAAU,CAAC;YAC/D,CAAC,CAAC,CAAA,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CA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AC,OAAO,CACrB,UAAA,CAAC,IAAI,OAAA,CAAC,IAAA,yCAAW,EAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;oBACF,iBAAiB,GAAG,EAAE,CAAC;iBAC1B;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AAvID,kCAuIC;AAED,SAAS,iBAAiB,CAAC,KAAgC;IACvD,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 { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (removeMargins) {\n newListItem.format.marginBottom = '0px';\n newListItem.format.marginTop = '0px';\n }\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * @internal Check if there is XSS attack in the link
3
3
  * @param link The link to be checked
4
- * @returns The safe link, or empty string if there is XSS attack
5
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
4
+ * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack
5
+ * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)
6
+ * and checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
6
7
  * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
7
8
  */
8
9
  export declare function checkXss(link: string): string;
@@ -1,15 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkXss = void 0;
4
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
4
5
  /**
5
6
  * @internal Check if there is XSS attack in the link
6
7
  * @param link The link to be checked
7
- * @returns The safe link, or empty string if there is XSS attack
8
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
8
+ * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack
9
+ * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)
10
+ * and checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
9
11
  * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
10
12
  */
11
13
  function checkXss(link) {
12
- return link.match(/^[^\/]*s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : link;
14
+ // Defense-in-depth: strip invisible Unicode even if already handled elsewhere
15
+ var sanitized = (0, roosterjs_content_model_dom_1.stripInvisibleUnicode)(link);
16
+ return sanitized.match(/^[^\/]*s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : sanitized;
13
17
  }
14
18
  exports.checkXss = checkXss;
15
19
  //# sourceMappingURL=checkXss.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkXss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACvE,CAAC;AAFD,4BAEC","sourcesContent":["/**\n * @internal Check if there is XSS attack in the link\n * @param link The link to be checked\n * @returns The safe link, or empty string if there is XSS attack\n * @remarks This function checks for patterns like s\\nc\\nr\\ni\\np\\nt: to prevent XSS attacks. This may block some valid links,\n * but it is necessary for security reasons. We treat the word \"script\" as safe if there are \"/\" before it.\n */\nexport function checkXss(link: string): string {\n return link.match(/^[^\\/]*s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : link;\n}\n"]}
1
+ {"version":3,"file":"checkXss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AAEpE;;;;;;;GAOG;AACH,SAAgB,QAAQ,CAAC,IAAY;IACjC,8EAA8E;IAC9E,IAAM,SAAS,GAAG,IAAA,mDAAqB,EAAC,IAAI,CAAC,CAAC;IAC9C,OAAO,SAAS,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACjF,CAAC;AAJD,4BAIC","sourcesContent":["import { stripInvisibleUnicode } from 'roosterjs-content-model-dom';\n\n/**\n * @internal Check if there is XSS attack in the link\n * @param link The link to be checked\n * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack\n * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)\n * and checks for patterns like s\\nc\\nr\\ni\\np\\nt: to prevent XSS attacks. This may block some valid links,\n * but it is necessary for security reasons. We treat the word \"script\" as safe if there are \"/\" before it.\n */\nexport function checkXss(link: string): string {\n // Defense-in-depth: strip invisible Unicode even if already handled elsewhere\n const sanitized = stripInvisibleUnicode(link);\n return sanitized.match(/^[^\\/]*s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : sanitized;\n}\n"]}
@@ -12,7 +12,7 @@ var splitSelectedParagraphByBr_1 = require("../../modelApi/block/splitSelectedPa
12
12
  function formatParagraphWithContentModel(editor, apiName, setStyleCallback) {
13
13
  editor.formatContentModel(function (model, context) {
14
14
  (0, splitSelectedParagraphByBr_1.splitSelectedParagraphByBr)(model);
15
- var paragraphs = (0, roosterjs_content_model_dom_1.getSelectedParagraphs)(model, true /*mutate*/);
15
+ var paragraphs = (0, roosterjs_content_model_dom_1.getSelectedParagraphs)(model, true /*mutate*/, false /*removeUnmeaningful*/);
16
16
  paragraphs.forEach(setStyleCallback);
17
17
  context.newPendingFormat = 'preserve';
18
18
  return paragraphs.length > 0;
@@ -1 +1 @@
1
- {"version":3,"file":"formatParagraphWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatParagraphWithContentModel.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AACpE,8FAA6F;AAG7F;;;;;GAKG;AACH,SAAgB,+BAA+B,CAC3C,MAAe,EACf,OAAe,EACf,gBAA0E;IAE1E,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,UAAU,GAAG,IAAA,mDAAqB,EAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAEjE,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACrC,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAEtC,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC,EACD;QACI,OAAO,SAAA;KACV,CACJ,CAAC;AACN,CAAC;AApBD,0EAoBC","sourcesContent":["import { getSelectedParagraphs } from 'roosterjs-content-model-dom';\nimport { splitSelectedParagraphByBr } from '../../modelApi/block/splitSelectedParagraphByBr';\nimport type { IEditor, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected paragraph using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param setStyleCallback The callback to format the paragraph. It will be called with current selected table. If no table is selected, it will not be called.\n */\nexport function formatParagraphWithContentModel(\n editor: IEditor,\n apiName: string,\n setStyleCallback: (paragraph: ShallowMutableContentModelParagraph) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n splitSelectedParagraphByBr(model);\n\n const paragraphs = getSelectedParagraphs(model, true /*mutate*/);\n\n paragraphs.forEach(setStyleCallback);\n context.newPendingFormat = 'preserve';\n\n return paragraphs.length > 0;\n },\n {\n apiName,\n }\n );\n}\n"]}
1
+ {"version":3,"file":"formatParagraphWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatParagraphWithContentModel.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AACpE,8FAA6F;AAG7F;;;;;GAKG;AACH,SAAgB,+BAA+B,CAC3C,MAAe,EACf,OAAe,EACf,gBAA0E;IAE1E,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,UAAU,GAAG,IAAA,mDAAqB,EACpC,KAAK,EACL,IAAI,CAAC,UAAU,EACf,KAAK,CAAC,sBAAsB,CAC/B,CAAC;QAEF,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACrC,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAEtC,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC,EACD;QACI,OAAO,SAAA;KACV,CACJ,CAAC;AACN,CAAC;AAxBD,0EAwBC","sourcesContent":["import { getSelectedParagraphs } from 'roosterjs-content-model-dom';\nimport { splitSelectedParagraphByBr } from '../../modelApi/block/splitSelectedParagraphByBr';\nimport type { IEditor, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected paragraph using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param setStyleCallback The callback to format the paragraph. It will be called with current selected table. If no table is selected, it will not be called.\n */\nexport function formatParagraphWithContentModel(\n editor: IEditor,\n apiName: string,\n setStyleCallback: (paragraph: ShallowMutableContentModelParagraph) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n splitSelectedParagraphByBr(model);\n\n const paragraphs = getSelectedParagraphs(\n model,\n true /*mutate*/,\n false /*removeUnmeaningful*/\n );\n\n paragraphs.forEach(setStyleCallback);\n context.newPendingFormat = 'preserve';\n\n return paragraphs.length > 0;\n },\n {\n apiName,\n }\n );\n}\n"]}
@@ -76,6 +76,10 @@ define(["require", "exports", "../common/adjustIndentation", "../block/splitSele
76
76
  fontSize: segmentFormat.fontSize,
77
77
  textColor: segmentFormat.textColor,
78
78
  });
79
+ if (removeMargins) {
80
+ newListItem.format.marginBottom = '0px';
81
+ newListItem.format.marginTop = '0px';
82
+ }
79
83
  if (block.blockType == 'Paragraph') {
80
84
  (0, roosterjs_content_model_dom_1.setParagraphNotImplicit)(block);
81
85
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;;IAwBA;;;;;OAKG;IACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;QAA9B,8BAAA,EAAA,qBAA8B;QAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,EAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;SACpJ,CAAC;QACF,IAAM,qBAAqB,GAAG,oBAAoB,CAAC,KAAK,CAAC,UAAC,EAAS;;gBAAP,KAAK,WAAA;YAC7D,OAAA,IAAA,gDAAkB,EAA+B,KAAK,EAAE,UAAU,CAAC;gBAC/D,CAAC,CAAC,CAAA,MAAA,KAAK,CAAC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AC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;wBACF,iBAAiB,GAAG,EAAE,CAAC;qBAC1B;iBACJ;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3C,CAAC;IAlID,kCAkIC;IAED,SAAS,iBAAiB,CAAC,KAAgC;QACvD,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK,OAAO;gBACR,OAAO,KAAK,CAAC;YACjB,KAAK,WAAW;gBACZ,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CACvB,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAA3D,CAA2D,CACnE,CAAC;YACN;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;;IAwBA;;;;;OAKG;IACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;QAA9B,8BAAA,EAAA,qBAA8B;QAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,EAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;SAC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C;wBAE1D,IAAI,KAAK,EAAE;4BACP,IAAA,gDAAkB,EAAC,KAAK,EAAE,UAAA,QAAQ;gCAC9B,OAAA,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE;oCACxB,uBAAuB,EAAE,IAAI;iCAChC,CAAC;4BAFF,CAEE,CACL,CAAC;yBACL;qBACJ;yBAAM;wBACH,iBAAiB,CAAC,OAAO,CACrB,UAAA,CAAC,IAAI,OAAA,CAAC,IAAA,yCAAW,EAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;wBACF,iBAAiB,GAAG,EAAE,CAAC;qBAC1B;iBACJ;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3C,CAAC;IAvID,kCAuIC;IAED,SAAS,iBAAiB,CAAC,KAAgC;QACvD,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK,OAAO;gBACR,OAAO,KAAK,CAAC;YACjB,KAAK,WAAW;gBACZ,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CACvB,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAA3D,CAA2D,CACnE,CAAC;YACN;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (removeMargins) {\n newListItem.format.marginBottom = '0px';\n newListItem.format.marginTop = '0px';\n }\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * @internal Check if there is XSS attack in the link
3
3
  * @param link The link to be checked
4
- * @returns The safe link, or empty string if there is XSS attack
5
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
4
+ * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack
5
+ * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)
6
+ * and checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
6
7
  * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
7
8
  */
8
9
  export declare function checkXss(link: string): string;
@@ -1,16 +1,19 @@
1
- define(["require", "exports"], function (require, exports) {
1
+ define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.checkXss = void 0;
5
5
  /**
6
6
  * @internal Check if there is XSS attack in the link
7
7
  * @param link The link to be checked
8
- * @returns The safe link, or empty string if there is XSS attack
9
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
8
+ * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack
9
+ * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)
10
+ * and checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
10
11
  * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
11
12
  */
12
13
  function checkXss(link) {
13
- return link.match(/^[^\/]*s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : link;
14
+ // Defense-in-depth: strip invisible Unicode even if already handled elsewhere
15
+ var sanitized = (0, roosterjs_content_model_dom_1.stripInvisibleUnicode)(link);
16
+ return sanitized.match(/^[^\/]*s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : sanitized;
14
17
  }
15
18
  exports.checkXss = checkXss;
16
19
  });
@@ -1 +1 @@
1
- {"version":3,"file":"checkXss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts"],"names":[],"mappings":";;;;IAAA;;;;;;OAMG;IACH,SAAgB,QAAQ,CAAC,IAAY;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,CAAC;IAFD,4BAEC","sourcesContent":["/**\n * @internal Check if there is XSS attack in the link\n * @param link The link to be checked\n * @returns The safe link, or empty string if there is XSS attack\n * @remarks This function checks for patterns like s\\nc\\nr\\ni\\np\\nt: to prevent XSS attacks. This may block some valid links,\n * but it is necessary for security reasons. We treat the word \"script\" as safe if there are \"/\" before it.\n */\nexport function checkXss(link: string): string {\n return link.match(/^[^\\/]*s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : link;\n}\n"]}
1
+ {"version":3,"file":"checkXss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts"],"names":[],"mappings":";;;;IAEA;;;;;;;OAOG;IACH,SAAgB,QAAQ,CAAC,IAAY;QACjC,8EAA8E;QAC9E,IAAM,SAAS,GAAG,IAAA,mDAAqB,EAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,SAAS,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACjF,CAAC;IAJD,4BAIC","sourcesContent":["import { stripInvisibleUnicode } from 'roosterjs-content-model-dom';\n\n/**\n * @internal Check if there is XSS attack in the link\n * @param link The link to be checked\n * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack\n * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)\n * and checks for patterns like s\\nc\\nr\\ni\\np\\nt: to prevent XSS attacks. This may block some valid links,\n * but it is necessary for security reasons. We treat the word \"script\" as safe if there are \"/\" before it.\n */\nexport function checkXss(link: string): string {\n // Defense-in-depth: strip invisible Unicode even if already handled elsewhere\n const sanitized = stripInvisibleUnicode(link);\n return sanitized.match(/^[^\\/]*s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : sanitized;\n}\n"]}
@@ -11,7 +11,7 @@ define(["require", "exports", "roosterjs-content-model-dom", "../../modelApi/blo
11
11
  function formatParagraphWithContentModel(editor, apiName, setStyleCallback) {
12
12
  editor.formatContentModel(function (model, context) {
13
13
  (0, splitSelectedParagraphByBr_1.splitSelectedParagraphByBr)(model);
14
- var paragraphs = (0, roosterjs_content_model_dom_1.getSelectedParagraphs)(model, true /*mutate*/);
14
+ var paragraphs = (0, roosterjs_content_model_dom_1.getSelectedParagraphs)(model, true /*mutate*/, false /*removeUnmeaningful*/);
15
15
  paragraphs.forEach(setStyleCallback);
16
16
  context.newPendingFormat = 'preserve';
17
17
  return paragraphs.length > 0;
@@ -1 +1 @@
1
- {"version":3,"file":"formatParagraphWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatParagraphWithContentModel.ts"],"names":[],"mappings":";;;;IAIA;;;;;OAKG;IACH,SAAgB,+BAA+B,CAC3C,MAAe,EACf,OAAe,EACf,gBAA0E;QAE1E,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;YAElC,IAAM,UAAU,GAAG,IAAA,mDAAqB,EAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAEjE,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;YACrC,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;YAEtC,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;QACjC,CAAC,EACD;YACI,OAAO,SAAA;SACV,CACJ,CAAC;IACN,CAAC;IApBD,0EAoBC","sourcesContent":["import { getSelectedParagraphs } from 'roosterjs-content-model-dom';\nimport { splitSelectedParagraphByBr } from '../../modelApi/block/splitSelectedParagraphByBr';\nimport type { IEditor, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected paragraph using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param setStyleCallback The callback to format the paragraph. It will be called with current selected table. If no table is selected, it will not be called.\n */\nexport function formatParagraphWithContentModel(\n editor: IEditor,\n apiName: string,\n setStyleCallback: (paragraph: ShallowMutableContentModelParagraph) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n splitSelectedParagraphByBr(model);\n\n const paragraphs = getSelectedParagraphs(model, true /*mutate*/);\n\n paragraphs.forEach(setStyleCallback);\n context.newPendingFormat = 'preserve';\n\n return paragraphs.length > 0;\n },\n {\n apiName,\n }\n );\n}\n"]}
1
+ {"version":3,"file":"formatParagraphWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatParagraphWithContentModel.ts"],"names":[],"mappings":";;;;IAIA;;;;;OAKG;IACH,SAAgB,+BAA+B,CAC3C,MAAe,EACf,OAAe,EACf,gBAA0E;QAE1E,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;YAElC,IAAM,UAAU,GAAG,IAAA,mDAAqB,EACpC,KAAK,EACL,IAAI,CAAC,UAAU,EACf,KAAK,CAAC,sBAAsB,CAC/B,CAAC;YAEF,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;YACrC,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;YAEtC,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;QACjC,CAAC,EACD;YACI,OAAO,SAAA;SACV,CACJ,CAAC;IACN,CAAC;IAxBD,0EAwBC","sourcesContent":["import { getSelectedParagraphs } from 'roosterjs-content-model-dom';\nimport { splitSelectedParagraphByBr } from '../../modelApi/block/splitSelectedParagraphByBr';\nimport type { IEditor, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected paragraph using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param setStyleCallback The callback to format the paragraph. It will be called with current selected table. If no table is selected, it will not be called.\n */\nexport function formatParagraphWithContentModel(\n editor: IEditor,\n apiName: string,\n setStyleCallback: (paragraph: ShallowMutableContentModelParagraph) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n splitSelectedParagraphByBr(model);\n\n const paragraphs = getSelectedParagraphs(\n model,\n true /*mutate*/,\n false /*removeUnmeaningful*/\n );\n\n paragraphs.forEach(setStyleCallback);\n context.newPendingFormat = 'preserve';\n\n return paragraphs.length > 0;\n },\n {\n apiName,\n }\n );\n}\n"]}
@@ -75,6 +75,10 @@ export function setListType(model, listType, removeMargins) {
75
75
  fontSize: segmentFormat.fontSize,
76
76
  textColor: segmentFormat.textColor,
77
77
  });
78
+ if (removeMargins) {
79
+ newListItem.format.marginBottom = '0px';
80
+ newListItem.format.marginTop = '0px';
81
+ }
78
82
  if (block.blockType == 'Paragraph') {
79
83
  setParagraphNotImplicit(block);
80
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EACH,UAAU,EACV,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,GACrB,MAAM,6BAA6B,CA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,IAAI,KAAK,EAAE;wBACP,kBAAkB,CAAC,KAAK,EAAE,UAAA,QAAQ;4BAC9B,OAAA,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE;gCACxB,uBAAuB,EAAE,IAAI;6BAChC,CAAC;wBAFF,CAEE,CACL,CAAC;qBACL;iBACJ;qBAAM;oBACH,iBAAiB,CAAC,OAAO,CACrB,UAAA,CAAC,IAAI,OAAA,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;oBACF,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,KAAgC;IACvD,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 { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/mod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AC,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 { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (removeMargins) {\n newListItem.format.marginBottom = '0px';\n newListItem.format.marginTop = '0px';\n }\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * @internal Check if there is XSS attack in the link
3
3
  * @param link The link to be checked
4
- * @returns The safe link, or empty string if there is XSS attack
5
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
4
+ * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack
5
+ * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)
6
+ * and checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
6
7
  * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
7
8
  */
8
9
  export declare function checkXss(link: string): string;
@@ -1,11 +1,15 @@
1
+ import { stripInvisibleUnicode } from 'roosterjs-content-model-dom';
1
2
  /**
2
3
  * @internal Check if there is XSS attack in the link
3
4
  * @param link The link to be checked
4
- * @returns The safe link, or empty string if there is XSS attack
5
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
5
+ * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack
6
+ * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)
7
+ * and checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
6
8
  * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
7
9
  */
8
10
  export function checkXss(link) {
9
- return link.match(/^[^\/]*s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : link;
11
+ // Defense-in-depth: strip invisible Unicode even if already handled elsewhere
12
+ var sanitized = stripInvisibleUnicode(link);
13
+ return sanitized.match(/^[^\/]*s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : sanitized;
10
14
  }
11
15
  //# sourceMappingURL=checkXss.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkXss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACvE,CAAC","sourcesContent":["/**\n * @internal Check if there is XSS attack in the link\n * @param link The link to be checked\n * @returns The safe link, or empty string if there is XSS attack\n * @remarks This function checks for patterns like s\\nc\\nr\\ni\\np\\nt: to prevent XSS attacks. This may block some valid links,\n * but it is necessary for security reasons. We treat the word \"script\" as safe if there are \"/\" before it.\n */\nexport function checkXss(link: string): string {\n return link.match(/^[^\\/]*s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : link;\n}\n"]}
1
+ {"version":3,"file":"checkXss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACjC,8EAA8E;IAC9E,IAAM,SAAS,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC9C,OAAO,SAAS,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACjF,CAAC","sourcesContent":["import { stripInvisibleUnicode } from 'roosterjs-content-model-dom';\n\n/**\n * @internal Check if there is XSS attack in the link\n * @param link The link to be checked\n * @returns The safe link with invisible Unicode characters stripped, or empty string if there is XSS attack\n * @remarks This function strips invisible Unicode characters (zero-width chars, Unicode Tags, etc.)\n * and checks for patterns like s\\nc\\nr\\ni\\np\\nt: to prevent XSS attacks. This may block some valid links,\n * but it is necessary for security reasons. We treat the word \"script\" as safe if there are \"/\" before it.\n */\nexport function checkXss(link: string): string {\n // Defense-in-depth: strip invisible Unicode even if already handled elsewhere\n const sanitized = stripInvisibleUnicode(link);\n return sanitized.match(/^[^\\/]*s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : sanitized;\n}\n"]}
@@ -9,7 +9,7 @@ import { splitSelectedParagraphByBr } from '../../modelApi/block/splitSelectedPa
9
9
  export function formatParagraphWithContentModel(editor, apiName, setStyleCallback) {
10
10
  editor.formatContentModel(function (model, context) {
11
11
  splitSelectedParagraphByBr(model);
12
- var paragraphs = getSelectedParagraphs(model, true /*mutate*/);
12
+ var paragraphs = getSelectedParagraphs(model, true /*mutate*/, false /*removeUnmeaningful*/);
13
13
  paragraphs.forEach(setStyleCallback);
14
14
  context.newPendingFormat = 'preserve';
15
15
  return paragraphs.length > 0;
@@ -1 +1 @@
1
- {"version":3,"file":"formatParagraphWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatParagraphWithContentModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAC;AAG7F;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAC3C,MAAe,EACf,OAAe,EACf,gBAA0E;IAE1E,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAElC,IAAM,UAAU,GAAG,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAEjE,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACrC,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAEtC,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC,EACD;QACI,OAAO,SAAA;KACV,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { getSelectedParagraphs } from 'roosterjs-content-model-dom';\nimport { splitSelectedParagraphByBr } from '../../modelApi/block/splitSelectedParagraphByBr';\nimport type { IEditor, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected paragraph using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param setStyleCallback The callback to format the paragraph. It will be called with current selected table. If no table is selected, it will not be called.\n */\nexport function formatParagraphWithContentModel(\n editor: IEditor,\n apiName: string,\n setStyleCallback: (paragraph: ShallowMutableContentModelParagraph) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n splitSelectedParagraphByBr(model);\n\n const paragraphs = getSelectedParagraphs(model, true /*mutate*/);\n\n paragraphs.forEach(setStyleCallback);\n context.newPendingFormat = 'preserve';\n\n return paragraphs.length > 0;\n },\n {\n apiName,\n }\n );\n}\n"]}
1
+ {"version":3,"file":"formatParagraphWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatParagraphWithContentModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAC;AAG7F;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAC3C,MAAe,EACf,OAAe,EACf,gBAA0E;IAE1E,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAElC,IAAM,UAAU,GAAG,qBAAqB,CACpC,KAAK,EACL,IAAI,CAAC,UAAU,EACf,KAAK,CAAC,sBAAsB,CAC/B,CAAC;QAEF,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACrC,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAEtC,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC,EACD;QACI,OAAO,SAAA;KACV,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { getSelectedParagraphs } from 'roosterjs-content-model-dom';\nimport { splitSelectedParagraphByBr } from '../../modelApi/block/splitSelectedParagraphByBr';\nimport type { IEditor, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected paragraph using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param setStyleCallback The callback to format the paragraph. It will be called with current selected table. If no table is selected, it will not be called.\n */\nexport function formatParagraphWithContentModel(\n editor: IEditor,\n apiName: string,\n setStyleCallback: (paragraph: ShallowMutableContentModelParagraph) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n splitSelectedParagraphByBr(model);\n\n const paragraphs = getSelectedParagraphs(\n model,\n true /*mutate*/,\n false /*removeUnmeaningful*/\n );\n\n paragraphs.forEach(setStyleCallback);\n context.newPendingFormat = 'preserve';\n\n return paragraphs.length > 0;\n },\n {\n apiName,\n }\n );\n}\n"]}
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "description": "Format API for roosterjs",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "roosterjs-content-model-dom": "^9.48.0",
7
- "roosterjs-content-model-types": "^9.48.0"
6
+ "roosterjs-content-model-dom": "^9.50.0",
7
+ "roosterjs-content-model-types": "^9.50.0"
8
8
  },
9
- "version": "9.48.0",
9
+ "version": "9.50.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",