roosterjs-content-model-api 9.42.0 → 9.44.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.
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/modelApi/block/setModelIndentation.js +7 -1
- package/lib/modelApi/block/setModelIndentation.js.map +1 -1
- package/lib/modelApi/link/getLinkUrl.js +4 -1
- package/lib/modelApi/link/getLinkUrl.js.map +1 -1
- package/lib/modelApi/link/promoteLink.d.ts +8 -1
- package/lib/modelApi/link/promoteLink.js +24 -7
- package/lib/modelApi/link/promoteLink.js.map +1 -1
- package/lib/modelApi/list/setListType.js +3 -2
- package/lib/modelApi/list/setListType.js.map +1 -1
- package/lib/publicApi/block/setIndentation.js +0 -4
- package/lib/publicApi/block/setIndentation.js.map +1 -1
- package/lib/publicApi/utils/formatSegmentWithContentModel.js +5 -2
- package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib-amd/index.d.ts +1 -1
- package/lib-amd/index.js +2 -1
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/modelApi/block/setModelIndentation.js +7 -1
- package/lib-amd/modelApi/block/setModelIndentation.js.map +1 -1
- package/lib-amd/modelApi/link/getLinkUrl.js +4 -1
- package/lib-amd/modelApi/link/getLinkUrl.js.map +1 -1
- package/lib-amd/modelApi/link/promoteLink.d.ts +8 -1
- package/lib-amd/modelApi/link/promoteLink.js +24 -7
- package/lib-amd/modelApi/link/promoteLink.js.map +1 -1
- package/lib-amd/modelApi/list/setListType.js +3 -2
- package/lib-amd/modelApi/list/setListType.js.map +1 -1
- package/lib-amd/publicApi/block/setIndentation.js +1 -4
- package/lib-amd/publicApi/block/setIndentation.js.map +1 -1
- package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +5 -2
- package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib-mjs/index.d.ts +1 -1
- package/lib-mjs/index.js +1 -1
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/modelApi/block/setModelIndentation.js +8 -2
- package/lib-mjs/modelApi/block/setModelIndentation.js.map +1 -1
- package/lib-mjs/modelApi/link/getLinkUrl.js +4 -1
- package/lib-mjs/modelApi/link/getLinkUrl.js.map +1 -1
- package/lib-mjs/modelApi/link/promoteLink.d.ts +8 -1
- package/lib-mjs/modelApi/link/promoteLink.js +22 -6
- package/lib-mjs/modelApi/link/promoteLink.js.map +1 -1
- package/lib-mjs/modelApi/list/setListType.js +3 -2
- package/lib-mjs/modelApi/list/setListType.js.map +1 -1
- package/lib-mjs/publicApi/block/setIndentation.js +0 -4
- package/lib-mjs/publicApi/block/setIndentation.js.map +1 -1
- package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +5 -2
- package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export { setModelListStartNumber } from './modelApi/list/setModelListStartNumber
|
|
|
57
57
|
export { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';
|
|
58
58
|
export { setModelIndentation } from './modelApi/block/setModelIndentation';
|
|
59
59
|
export { matchLink } from './modelApi/link/matchLink';
|
|
60
|
-
export { promoteLink } from './modelApi/link/promoteLink';
|
|
60
|
+
export { promoteLink, getPromoteLink } from './modelApi/link/promoteLink';
|
|
61
61
|
export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
|
|
62
62
|
export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
|
|
63
63
|
export { adjustWordSelection } from './modelApi/selection/adjustWordSelection';
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatParagraphWithContentModel = exports.formatImageWithContentModel = exports.formatTableWithContentModel = exports.createEditorContextForEntity = exports.clearSelectedCells = exports.insertTableColumn = exports.insertTableRow = exports.insertEntity = exports.toggleCode = exports.setParagraphMargin = exports.adjustImageSelection = exports.setImageAltText = exports.adjustLinkSelection = exports.removeLink = exports.insertLink = exports.clearFormat = exports.getFormatState = exports.changeImage = exports.setImageBoxShadow = exports.setImageBorder = exports.setSpacing = exports.toggleBlockQuote = exports.setHeadingLevel = exports.setDirection = exports.setAlignment = exports.setIndentation = exports.setListStartNumber = exports.setListStyle = exports.insertImage = exports.splitTextSegment = exports.changeCapitalization = exports.applySegmentFormat = exports.changeFontSize = exports.setTextColor = exports.setFontSize = exports.setFontName = exports.setBackgroundColor = exports.toggleSuperscript = exports.toggleSubscript = exports.toggleStrikethrough = exports.toggleUnderline = exports.toggleItalic = exports.toggleBold = exports.toggleNumbering = exports.toggleBullet = exports.applyTableBorderFormat = exports.editTable = exports.setTableCellShade = exports.formatTable = exports.insertTable = void 0;
|
|
4
|
-
exports.adjustWordSelection = exports.queryContentModelBlocks = exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = exports.formatSegmentWithContentModel = void 0;
|
|
4
|
+
exports.adjustWordSelection = exports.queryContentModelBlocks = exports.getListAnnounceData = exports.getPromoteLink = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = exports.formatSegmentWithContentModel = void 0;
|
|
5
5
|
var insertTable_1 = require("./publicApi/table/insertTable");
|
|
6
6
|
Object.defineProperty(exports, "insertTable", { enumerable: true, get: function () { return insertTable_1.insertTable; } });
|
|
7
7
|
var formatTable_1 = require("./publicApi/table/formatTable");
|
|
@@ -122,6 +122,7 @@ var matchLink_1 = require("./modelApi/link/matchLink");
|
|
|
122
122
|
Object.defineProperty(exports, "matchLink", { enumerable: true, get: function () { return matchLink_1.matchLink; } });
|
|
123
123
|
var promoteLink_1 = require("./modelApi/link/promoteLink");
|
|
124
124
|
Object.defineProperty(exports, "promoteLink", { enumerable: true, get: function () { return promoteLink_1.promoteLink; } });
|
|
125
|
+
Object.defineProperty(exports, "getPromoteLink", { enumerable: true, get: function () { return promoteLink_1.getPromoteLink; } });
|
|
125
126
|
var getListAnnounceData_1 = require("./modelApi/list/getListAnnounceData");
|
|
126
127
|
Object.defineProperty(exports, "getListAnnounceData", { enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } });
|
|
127
128
|
var queryContentModelBlocks_1 = require("./modelApi/common/queryContentModelBlocks");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;AAAA,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,yEAAwE;AAA/D,sHAAA,iBAAiB,OAAA;AAC1B,yDAAwD;AAA/C,sGAAA,SAAS,OAAA;AAClB,mFAAkF;AAAzE,gIAAA,sBAAsB,OAAA;AAC/B,8DAA6D;AAApD,4GAAA,YAAY,OAAA;AACrB,oEAAmE;AAA1D,kHAAA,eAAe,OAAA;AACxB,6DAA4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,iEAAgE;AAAvD,4GAAA,YAAY,OAAA;AACrB,uEAAsE;AAA7D,kHAAA,eAAe,OAAA;AACxB,+EAA8E;AAArE,0HAAA,mBAAmB,OAAA;AAC5B,uEAAsE;AAA7D,kHAAA,eAAe,OAAA;AACxB,2EAA0E;AAAjE,sHAAA,iBAAiB,OAAA;AAC1B,6EAA4E;AAAnE,wHAAA,kBAAkB,OAAA;AAC3B,+DAA8D;AAArD,0GAAA,WAAW,OAAA;AACpB,+DAA8D;AAArD,0GAAA,WAAW,OAAA;AAC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4GAAA,YAAY,OAAA;AACrB,kEAAiE;AAAxD,gHAAA,cAAc,OAAA;AACvB,wEAAuE;AAA9D,sHAAA,iBAAiB,OAAA;AAC1B,0EAAyE;AAAhE,wHAAA,kBAAkB,OAAA;AAE3B,+FAA8F;AAArF,4IAAA,4BAA4B,OAAA;AACrC,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,qGAAoG;AAA3F,kJAAA,+BAA+B,OAAA;AACxC,iGAAgG;AAAvF,8IAAA,6BAA6B,OAAA;AACtC,mHAAkH;AAAzG,gKAAA,sCAAsC,OAAA;AAC/C,yGAAwG;AAA/F,sJAAA,iCAAiC,OAAA;AAE1C,2DAA0D;AAAjD,0GAAA,WAAW,OAAA;AACpB,uEAAsE;AAA7D,sHAAA,iBAAiB,OAAA;AAC1B,mFAAkF;AAAzE,kIAAA,uBAAuB,OAAA;AAChC,uFAAsF;AAA7E,sIAAA,yBAAyB,OAAA;AAClC,4EAA2E;AAAlE,0HAAA,mBAAmB,OAAA;AAC5B,uDAAsD;AAA7C,sGAAA,SAAS,OAAA;AAClB,2DAA0E;AAAjE,0GAAA,WAAW,OAAA;AAAE,6GAAA,cAAc,OAAA;AACpC,2EAA0E;AAAjE,0HAAA,mBAAmB,OAAA;AAC5B,qFAAoF;AAA3E,kIAAA,uBAAuB,OAAA;AAChC,gFAA+E;AAAtE,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink, getPromoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\nexport { adjustWordSelection } from './modelApi/selection/adjustWordSelection';\n"]}
|
|
@@ -103,7 +103,13 @@ function setModelIndentation(model, indentation, length, context) {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
|
-
|
|
106
|
+
if (paragraphOrListItem.length > 0) {
|
|
107
|
+
(0, roosterjs_content_model_dom_1.normalizeContentModel)(model);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
107
113
|
}
|
|
108
114
|
exports.setModelIndentation = setModelIndentation;
|
|
109
115
|
function isSelected(listItem) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/set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ACpD,OAAO,IAAI,CAAC;KACf;SAAM;QACH,OAAO,QAAQ,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { getListAnnounceData } from '../list/getListAnnounceData';\nimport { IndentStepInPixel } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';\nimport {\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n mutateBlock,\n parseValueWithUnit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ContentModelListItem,\n ContentModelListLevel,\n FormatContentModelContext,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ReadonlyContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel,\n context?: FormatContentModelContext\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ReadonlyContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const threadIdx = thread.indexOf(block);\n const previousItem = thread[threadIdx - 1];\n const nextItem = thread[threadIdx + 1];\n const levelLength = block.levels.length;\n const lastLevel = block.levels[levelLength - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format,\n previousItem && previousItem.levels.length > levelLength\n ? previousItem.levels[levelLength].dataset\n : nextItem && nextItem.levels.length > levelLength\n ? nextItem.levels[levelLength].dataset\n : undefined\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n\n if (block.levels.length > 0 && context) {\n context.announceData = getListAnnounceData([block, ...path]);\n }\n }\n } else if (block) {\n let currentBlock: ReadonlyContentModelBlock = block;\n let currentParent: ReadonlyContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = mutateBlock(currentBlock);\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n mutateBlock(currentParent);\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n\nfunction isSelected(listItem: ReadonlyContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ReadonlyContentModelDocument,\n listItem: ReadonlyContentModelListItem,\n parent: ReadonlyContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: Readonly<ContentModelBlockFormat>,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelIndentation.ts"],"names":[],"mappings":";;;;AAAA,+EAA8E;AAC9E,mEAAkE;AAClE,iEAAgE;AAChE,2EAA0E;AAC1E,2EAQqC;AAYrC;;;;;GAKG;AACH,SAAgB,mBAAmB,CAC/B,KAAmC,EACnC,WAAiC,EACjC,MAAkC,EAClC,OAAmC;IADnC,uBAAA,EAAA,SAAiB,qCAAiB;IAGlC,IAAA,uDAA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K,CAAC,EACnB;YACE,IAAM,SAAS,GAAG,IAAA,qDAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7D,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;SAChC;QAED,IAAI,CAAC,IAAA,gDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;YAC9D,OAAO,KAAK,CAAC;SAChB;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,oBAAoB,CACzB,MAAyC,EACzC,QAAiB,EACjB,MAAkC;IAAlC,uBAAA,EAAA,SAAiB,qCAAiB;IAE1B,IAAA,UAAU,GAA6B,MAAM,WAAnC,EAAE,WAAW,GAAgB,MAAM,YAAtB,EAAE,SAAS,GAAK,MAAM,UAAX,CAAY;IACtD,IAAM,KAAK,GAAG,SAAS,IAAI,KAAK,CAAC;IACjC,IAAM,aAAa,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAC3E,IAAI,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;IAEpF,IAAI,QAAQ,IAAI,aAAa,EAAE;QAC3B,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACnE;IAED,IAAI,QAAQ,IAAI,aAAa,EAAE;QAC3B,oDAAoD;QACpD,OAAO,IAAI,CAAC;KACf;SAAM;QACH,OAAO,QAAQ,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { getListAnnounceData } from '../list/getListAnnounceData';\nimport { IndentStepInPixel } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from './splitSelectedParagraphByBr';\nimport {\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n mutateBlock,\n normalizeContentModel,\n parseValueWithUnit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ContentModelListItem,\n ContentModelListLevel,\n FormatContentModelContext,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ReadonlyContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel,\n context?: FormatContentModelContext\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ReadonlyContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const threadIdx = thread.indexOf(block);\n const previousItem = thread[threadIdx - 1];\n const nextItem = thread[threadIdx + 1];\n const levelLength = block.levels.length;\n const lastLevel = block.levels[levelLength - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format,\n previousItem && previousItem.levels.length > levelLength\n ? previousItem.levels[levelLength].dataset\n : nextItem && nextItem.levels.length > levelLength\n ? nextItem.levels[levelLength].dataset\n : undefined\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n\n if (block.levels.length > 0 && context) {\n context.announceData = getListAnnounceData([block, ...path]);\n }\n }\n } else if (block) {\n let currentBlock: ReadonlyContentModelBlock = block;\n let currentParent: ReadonlyContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = mutateBlock(currentBlock);\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n mutateBlock(currentParent);\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n if (paragraphOrListItem.length > 0) {\n normalizeContentModel(model);\n\n return true;\n } else {\n return false;\n }\n}\n\nfunction isSelected(listItem: ReadonlyContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ReadonlyContentModelDocument,\n listItem: ReadonlyContentModelListItem,\n parent: ReadonlyContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: Readonly<ContentModelBlockFormat>,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
|
|
@@ -11,9 +11,12 @@ var MAILTO_REGEX = "(M|m)ailto:" + COMMON_REGEX;
|
|
|
11
11
|
function getLinkUrl(text, autoLinkOptions) {
|
|
12
12
|
var _a;
|
|
13
13
|
var _b = autoLinkOptions !== null && autoLinkOptions !== void 0 ? autoLinkOptions : {}, autoLink = _b.autoLink, autoMailto = _b.autoMailto, autoTel = _b.autoTel;
|
|
14
|
+
var mailtoMatch = matchMailTo(text);
|
|
15
|
+
if (mailtoMatch && !autoMailto) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
14
18
|
var linkMatch = autoLink ? (_a = (0, matchLink_1.matchLink)(text)) === null || _a === void 0 ? void 0 : _a.normalizedUrl : undefined;
|
|
15
19
|
var telMatch = autoTel ? matchTel(text) : undefined;
|
|
16
|
-
var mailtoMatch = autoMailto ? matchMailTo(text) : undefined;
|
|
17
20
|
return linkMatch || telMatch || mailtoMatch;
|
|
18
21
|
}
|
|
19
22
|
exports.getLinkUrl = getLinkUrl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLinkUrl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/getLinkUrl.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAGxC,IAAM,YAAY,GAAG,sBAAwB,CAAC;AAC9C,IAAM,eAAe,GAAG,aAAW,YAAc,CAAC;AAClD,IAAM,YAAY,GAAG,gBAAc,YAAc,CAAC;AAElD;;GAEG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,eAAiC;;IAChE,IAAA,KAAoC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,EAAE,EAAvD,QAAQ,cAAA,EAAE,UAAU,gBAAA,EAAE,OAAO,aAA0B,CAAC;IAChE,IAAM,
|
|
1
|
+
{"version":3,"file":"getLinkUrl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/getLinkUrl.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAGxC,IAAM,YAAY,GAAG,sBAAwB,CAAC;AAC9C,IAAM,eAAe,GAAG,aAAW,YAAc,CAAC;AAClD,IAAM,YAAY,GAAG,gBAAc,YAAc,CAAC;AAElD;;GAEG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,eAAiC;;IAChE,IAAA,KAAoC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,EAAE,EAAvD,QAAQ,cAAA,EAAE,UAAU,gBAAA,EAAE,OAAO,aAA0B,CAAC;IAChE,IAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,WAAW,IAAI,CAAC,UAAU,EAAE;QAC5B,OAAO,SAAS,CAAC;KACpB;IACD,IAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAA,IAAA,qBAAS,EAAC,IAAI,CAAC,0CAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,IAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEtD,OAAO,SAAS,IAAI,QAAQ,IAAI,WAAW,CAAC;AAChD,CAAC;AAVD,gCAUC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC","sourcesContent":["import { matchLink } from './matchLink';\nimport type { AutoLinkOptions } from 'roosterjs-content-model-types';\n\nconst COMMON_REGEX = `[\\s]*[a-zA-Z0-9+][\\s]*`;\nconst TELEPHONE_REGEX = `(T|t)el:${COMMON_REGEX}`;\nconst MAILTO_REGEX = `(M|m)ailto:${COMMON_REGEX}`;\n\n/**\n * @internal\n */\nexport function getLinkUrl(text: string, autoLinkOptions?: AutoLinkOptions): string | undefined {\n const { autoLink, autoMailto, autoTel } = autoLinkOptions ?? {};\n const mailtoMatch = matchMailTo(text);\n if (mailtoMatch && !autoMailto) {\n return undefined;\n }\n const linkMatch = autoLink ? matchLink(text)?.normalizedUrl : undefined;\n const telMatch = autoTel ? matchTel(text) : undefined;\n\n return linkMatch || telMatch || mailtoMatch;\n}\n\nfunction matchTel(text: string) {\n return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n\nfunction matchMailTo(text: string) {\n return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AutoLinkOptions, ContentModelText, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
|
|
1
|
+
import type { AutoLinkOptions, ContentModelText, PromotedLink, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
|
|
4
4
|
* When the whole text segment if of a link, promote the whole segment.
|
|
@@ -11,3 +11,10 @@ import type { AutoLinkOptions, ContentModelText, ShallowMutableContentModelParag
|
|
|
11
11
|
* @returns If a link is promoted, return this segment. Otherwise return null
|
|
12
12
|
*/
|
|
13
13
|
export declare function promoteLink(segment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, autoLinkOptions: AutoLinkOptions): ContentModelText | null;
|
|
14
|
+
/**
|
|
15
|
+
* Verify if the link can be promoted
|
|
16
|
+
* @param segment The text segment to search link text from
|
|
17
|
+
* @param options Options of auto link
|
|
18
|
+
* @returns if a link can be promoted
|
|
19
|
+
*/
|
|
20
|
+
export declare function getPromoteLink(segment: ContentModelText, autoLinkOptions: AutoLinkOptions): PromotedLink | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.promoteLink = void 0;
|
|
3
|
+
exports.getPromoteLink = exports.promoteLink = void 0;
|
|
4
4
|
var getLinkUrl_1 = require("./getLinkUrl");
|
|
5
5
|
var splitTextSegment_1 = require("../../publicApi/segment/splitTextSegment");
|
|
6
6
|
/**
|
|
@@ -18,14 +18,12 @@ function promoteLink(segment, paragraph, autoLinkOptions) {
|
|
|
18
18
|
if (segment.link) {
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (url && link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(url, autoLinkOptions))) {
|
|
25
|
-
var linkSegment = (0, splitTextSegment_1.splitTextSegment)(segment, paragraph, segment.text.length - link.trimLeft().length, segment.text.trimRight().length);
|
|
21
|
+
var promotedLink = getPromoteLink(segment, autoLinkOptions);
|
|
22
|
+
if (promotedLink) {
|
|
23
|
+
var linkSegment = (0, splitTextSegment_1.splitTextSegment)(segment, paragraph, segment.text.length - promotedLink.label.trimLeft().length, segment.text.trimRight().length);
|
|
26
24
|
linkSegment.link = {
|
|
27
25
|
format: {
|
|
28
|
-
href:
|
|
26
|
+
href: promotedLink.href,
|
|
29
27
|
underline: true,
|
|
30
28
|
},
|
|
31
29
|
dataset: {},
|
|
@@ -35,4 +33,23 @@ function promoteLink(segment, paragraph, autoLinkOptions) {
|
|
|
35
33
|
return null;
|
|
36
34
|
}
|
|
37
35
|
exports.promoteLink = promoteLink;
|
|
36
|
+
/**
|
|
37
|
+
* Verify if the link can be promoted
|
|
38
|
+
* @param segment The text segment to search link text from
|
|
39
|
+
* @param options Options of auto link
|
|
40
|
+
* @returns if a link can be promoted
|
|
41
|
+
*/
|
|
42
|
+
function getPromoteLink(segment, autoLinkOptions) {
|
|
43
|
+
var link = segment.text.split(' ').pop();
|
|
44
|
+
var url = link === null || link === void 0 ? void 0 : link.trim();
|
|
45
|
+
var linkUrl = undefined;
|
|
46
|
+
if (url && link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(url, autoLinkOptions))) {
|
|
47
|
+
return {
|
|
48
|
+
label: link,
|
|
49
|
+
href: linkUrl,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
exports.getPromoteLink = getPromoteLink;
|
|
38
55
|
//# sourceMappingURL=promoteLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promoteLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts"],"names":[],"mappings":";;;AAAA,2CAA0C;AAC1C,6EAA4E;
|
|
1
|
+
{"version":3,"file":"promoteLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts"],"names":[],"mappings":";;;AAAA,2CAA0C;AAC1C,6EAA4E;AAQ5E;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CACvB,OAAyB,EACzB,SAA8C,EAC9C,eAAgC;IAEhC,IAAI,OAAO,CAAC,IAAI,EAAE;QACd,OAAO,IAAI,CAAC;KACf;IAED,IAAM,YAAY,GAAG,cAAc,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAE9D,IAAI,YAAY,EAAE;QACd,IAAM,WAAW,GAAG,IAAA,mCAAgB,EAChC,OAAO,EACP,SAAS,EACT,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM,EAC1D,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,CAClC,CAAC;QACF,WAAW,CAAC,IAAI,GAAG;YACf,MAAM,EAAE;gBACJ,IAAI,EAAE,YAAY,CAAC,IAAI;gBACvB,SAAS,EAAE,IAAI;aAClB;YACD,OAAO,EAAE,EAAE;SACd,CAAC;QAEF,OAAO,WAAW,CAAC;KACtB;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AA9BD,kCA8BC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAC1B,OAAyB,EACzB,eAAgC;IAEhC,IAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IAC3C,IAAM,GAAG,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,CAAC;IACzB,IAAI,OAAO,GAAuB,SAAS,CAAC;IAC5C,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,GAAG,IAAA,uBAAU,EAAC,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE;QAC7D,OAAO;YACH,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,OAAO;SAChB,CAAC;KACL;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAdD,wCAcC","sourcesContent":["import { getLinkUrl } from './getLinkUrl';\nimport { splitTextSegment } from '../../publicApi/segment/splitTextSegment';\nimport type {\n AutoLinkOptions,\n ContentModelText,\n PromotedLink,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.\n * When the whole text segment if of a link, promote the whole segment.\n * When the text segment ends with a link format, split the segment and promote the second part\n * When link is in middle of the text segment, no action.\n * This is mainly used for doing auto link when there is a link before cursor\n * @param segment The text segment to search link text from\n * @param paragraph Parent paragraph of the segment\n * @param options Options of auto link\n * @returns If a link is promoted, return this segment. Otherwise return null\n */\nexport function promoteLink(\n segment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n autoLinkOptions: AutoLinkOptions\n): ContentModelText | null {\n if (segment.link) {\n return null;\n }\n\n const promotedLink = getPromoteLink(segment, autoLinkOptions);\n\n if (promotedLink) {\n const linkSegment = splitTextSegment(\n segment,\n paragraph,\n segment.text.length - promotedLink.label.trimLeft().length,\n segment.text.trimRight().length\n );\n linkSegment.link = {\n format: {\n href: promotedLink.href,\n underline: true,\n },\n dataset: {},\n };\n\n return linkSegment;\n }\n\n return null;\n}\n\n/**\n * Verify if the link can be promoted\n * @param segment The text segment to search link text from\n * @param options Options of auto link\n * @returns if a link can be promoted\n */\nexport function getPromoteLink(\n segment: ContentModelText,\n autoLinkOptions: AutoLinkOptions\n): PromotedLink | undefined {\n const link = segment.text.split(' ').pop();\n const url = link?.trim();\n let linkUrl: string | undefined = undefined;\n if (url && link && (linkUrl = getLinkUrl(url, autoLinkOptions))) {\n return {\n label: link,\n href: linkUrl,\n };\n }\n return undefined;\n}\n"]}
|
|
@@ -27,7 +27,8 @@ function setListType(model, listType, removeMargins) {
|
|
|
27
27
|
var _b, _c;
|
|
28
28
|
var block = _a.block, parent = _a.parent;
|
|
29
29
|
if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(block, 'ListItem')) {
|
|
30
|
-
var
|
|
30
|
+
var mutableBlock = (0, roosterjs_content_model_dom_1.mutateBlock)(block);
|
|
31
|
+
var level = mutableBlock.levels.pop();
|
|
31
32
|
if (!alreadyInExpectedType && level) {
|
|
32
33
|
level.listType = listType;
|
|
33
34
|
(0, roosterjs_content_model_dom_1.updateListMetadata)(level, function (metadata) {
|
|
@@ -35,7 +36,7 @@ function setListType(model, listType, removeMargins) {
|
|
|
35
36
|
applyListStyleFromLevel: true,
|
|
36
37
|
});
|
|
37
38
|
});
|
|
38
|
-
|
|
39
|
+
mutableBlock.levels.push(level);
|
|
39
40
|
}
|
|
40
41
|
else if (block.blocks.length == 1) {
|
|
41
42
|
(0, roosterjs_content_model_dom_1.setParagraphNotImplicit)(block.blocks[0]);
|
|
@@ -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;AAUrC;;;;;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,EAAuB,KAAK,EAAE,UAAU,CAAC;YACvD,CAAC,CAAC,CAAA,MAAA,KAAK,CAAC,MAA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A,mDAAqB,EAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AA3HD,kCA2HC;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 ContentModelListItem,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n [] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any\n );\n const alreadyInExpectedType = paragraphOrListItems.every(({ block }) =>\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const level = block.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n block.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n // if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n\n if (index >= 0) {\n if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
|
|
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,G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C,CAAC;IAEH,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AA5HD,kCA4HC;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\n if (index >= 0) {\n if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setIndentation = void 0;
|
|
4
|
-
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
4
|
var setModelIndentation_1 = require("../../modelApi/block/setModelIndentation");
|
|
6
5
|
/**
|
|
7
6
|
* Indent or outdent to selected paragraphs
|
|
@@ -13,9 +12,6 @@ function setIndentation(editor, indentation, length) {
|
|
|
13
12
|
editor.focus();
|
|
14
13
|
editor.formatContentModel(function (model, context) {
|
|
15
14
|
var result = (0, setModelIndentation_1.setModelIndentation)(model, indentation, length);
|
|
16
|
-
if (result) {
|
|
17
|
-
(0, roosterjs_content_model_dom_1.normalizeContentModel)(model);
|
|
18
|
-
}
|
|
19
15
|
context.newPendingFormat = 'preserve';
|
|
20
16
|
return result;
|
|
21
17
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/block/setIndentation.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"setIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/block/setIndentation.ts"],"names":[],"mappings":";;;AAAA,gFAA+E;AAG/E;;;;;GAKG;AACH,SAAgB,cAAc,CAC1B,MAAe,EACf,WAAiC,EACjC,MAAe;IAEf,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAE/D,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAEtC,OAAO,MAAM,CAAC;IAClB,CAAC,EACD;QACI,OAAO,EAAE,gBAAgB;KAC5B,CACJ,CAAC;AACN,CAAC;AAnBD,wCAmBC","sourcesContent":["import { setModelIndentation } from '../../modelApi/block/setModelIndentation';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Indent or outdent to selected paragraphs\n * @param editor The editor to operate on\n * @param indentation Whether indent or outdent\n * @param length The length of pixel to indent/outdent @default 40\n */\nexport function setIndentation(\n editor: IEditor,\n indentation: 'indent' | 'outdent',\n length?: number\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const result = setModelIndentation(model, indentation, length);\n\n context.newPendingFormat = 'preserve';\n\n return result;\n },\n {\n apiName: 'setIndentation',\n }\n );\n}\n"]}
|
|
@@ -33,7 +33,7 @@ function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, seg
|
|
|
33
33
|
var modelsFromEntities = [];
|
|
34
34
|
segmentAndParagraphs.forEach(function (item) {
|
|
35
35
|
if (item[0].segmentType == 'Entity') {
|
|
36
|
-
expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);
|
|
36
|
+
expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities, item[1]);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
formatsAndSegments.push([item[0].format, item[0], item[1]]);
|
|
@@ -78,7 +78,7 @@ function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, seg
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
exports.formatSegmentWithContentModel = formatSegmentWithContentModel;
|
|
81
|
-
function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEntities) {
|
|
81
|
+
function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEntities, paragraph) {
|
|
82
82
|
var _a = entity.entityFormat, id = _a.id, type = _a.entityType, isReadonly = _a.isReadonly;
|
|
83
83
|
if (id && type) {
|
|
84
84
|
var formattableRoots = [];
|
|
@@ -102,6 +102,9 @@ function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEn
|
|
|
102
102
|
modelsFromEntities.push([entity, root, model]);
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
|
+
if (formattableRoots.length > 0) {
|
|
106
|
+
formatsAndSegments.push([entity.format, entity, paragraph]);
|
|
107
|
+
}
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
function writeBackEntities(editor, modelsFromEntities) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;AAAA,oFAAmF;AACnF,+EAA8E;AAC9E,2EAOqC;AAcrC;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAIS;IAET,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,E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mB,EACzB,IAAI,CAAC,UAAU,CAClB,CAAC;gBAEF,UAAU,CAAC,OAAO,CAAC,UAAA,IAAI;oBACnB,kBAAkB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAChE,CAAC,CAAC,CAAC;gBAEH,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aAClD;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AAED,SAAS,iBAAiB,CACtB,MAAe,EACf,kBAAiF;IAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;YAArB,KAAA,0BAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;QAC5C,IAAM,aAAa,GAAG,IAAA,2DAA4B,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,IAAM,iBAAiB,GAAG,IAAA,qDAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzF,IAAA,+CAAiB,EAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\nimport {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormatContentModelContext,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment 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 toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (\n model: ReadonlyContentModelDocument,\n isTurningOff: boolean,\n context: FormatContentModelContext\n ) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model, isTurningOff, context);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;AAAA,oFAAmF;AACnF,+EAA8E;AAC9E,2EAOqC;AAcrC;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAIS;IAET,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;YAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC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AC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAChE,CAAC,CAAC,CAAC;gBAEH,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aAClD;QACL,CAAC,CAAC,CAAC;QACH,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;SAC/D;KACJ;AACL,CAAC;AAED,SAAS,iBAAiB,CACtB,MAAe,EACf,kBAAiF;IAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;YAArB,KAAA,0BAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;QAC5C,IAAM,aAAa,GAAG,IAAA,2DAA4B,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,IAAM,iBAAiB,GAAG,IAAA,qDAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzF,IAAA,+CAAiB,EAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\nimport {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormatContentModelContext,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment 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 toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (\n model: ReadonlyContentModelDocument,\n isTurningOff: boolean,\n context: FormatContentModelContext\n ) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(\n editor,\n item[0],\n formatsAndSegments,\n modelsFromEntities,\n item[1]\n );\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model, isTurningOff, context);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][],\n paragraph: ShallowMutableContentModelParagraph | null\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n if (formattableRoots.length > 0) {\n formatsAndSegments.push([entity.format, entity, paragraph]);\n }\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
|
package/lib-amd/index.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export { setModelListStartNumber } from './modelApi/list/setModelListStartNumber
|
|
|
57
57
|
export { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';
|
|
58
58
|
export { setModelIndentation } from './modelApi/block/setModelIndentation';
|
|
59
59
|
export { matchLink } from './modelApi/link/matchLink';
|
|
60
|
-
export { promoteLink } from './modelApi/link/promoteLink';
|
|
60
|
+
export { promoteLink, getPromoteLink } from './modelApi/link/promoteLink';
|
|
61
61
|
export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
|
|
62
62
|
export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
|
|
63
63
|
export { adjustWordSelection } from './modelApi/selection/adjustWordSelection';
|
package/lib-amd/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/table/formatTable", "./publicApi/table/setTableCellShade", "./publicApi/table/editTable", "./publicApi/table/applyTableBorderFormat", "./publicApi/list/toggleBullet", "./publicApi/list/toggleNumbering", "./publicApi/segment/toggleBold", "./publicApi/segment/toggleItalic", "./publicApi/segment/toggleUnderline", "./publicApi/segment/toggleStrikethrough", "./publicApi/segment/toggleSubscript", "./publicApi/segment/toggleSuperscript", "./publicApi/segment/setBackgroundColor", "./publicApi/segment/setFontName", "./publicApi/segment/setFontSize", "./publicApi/segment/setTextColor", "./publicApi/segment/changeFontSize", "./publicApi/segment/applySegmentFormat", "./publicApi/segment/changeCapitalization", "./publicApi/segment/splitTextSegment", "./publicApi/image/insertImage", "./publicApi/list/setListStyle", "./publicApi/list/setListStartNumber", "./publicApi/block/setIndentation", "./publicApi/block/setAlignment", "./publicApi/block/setDirection", "./publicApi/block/setHeadingLevel", "./publicApi/block/toggleBlockQuote", "./publicApi/block/setSpacing", "./publicApi/image/setImageBorder", "./publicApi/image/setImageBoxShadow", "./publicApi/image/changeImage", "./publicApi/format/getFormatState", "./publicApi/format/clearFormat", "./publicApi/link/insertLink", "./publicApi/link/removeLink", "./publicApi/link/adjustLinkSelection", "./publicApi/image/setImageAltText", "./publicApi/image/adjustImageSelection", "./publicApi/block/setParagraphMargin", "./publicApi/segment/toggleCode", "./publicApi/entity/insertEntity", "./modelApi/table/insertTableRow", "./modelApi/table/insertTableColumn", "./modelApi/table/clearSelectedCells", "./publicApi/utils/createEditorContextForEntity", "./publicApi/utils/formatTableWithContentModel", "./publicApi/utils/formatImageWithContentModel", "./publicApi/utils/formatParagraphWithContentModel", "./publicApi/utils/formatSegmentWithContentModel", "./publicApi/utils/formatTextSegmentBeforeSelectionMarker", "./publicApi/utils/formatInsertPointWithContentModel", "./modelApi/list/setListType", "./modelApi/list/setModelListStyle", "./modelApi/list/setModelListStartNumber", "./modelApi/list/findListItemsInSameThread", "./modelApi/block/setModelIndentation", "./modelApi/link/matchLink", "./modelApi/link/promoteLink", "./modelApi/list/getListAnnounceData", "./modelApi/common/queryContentModelBlocks", "./modelApi/selection/adjustWordSelection"], function (require, exports, insertTable_1, formatTable_1, setTableCellShade_1, editTable_1, applyTableBorderFormat_1, toggleBullet_1, toggleNumbering_1, toggleBold_1, toggleItalic_1, toggleUnderline_1, toggleStrikethrough_1, toggleSubscript_1, toggleSuperscript_1, setBackgroundColor_1, setFontName_1, setFontSize_1, setTextColor_1, changeFontSize_1, applySegmentFormat_1, changeCapitalization_1, splitTextSegment_1, insertImage_1, setListStyle_1, setListStartNumber_1, setIndentation_1, setAlignment_1, setDirection_1, setHeadingLevel_1, toggleBlockQuote_1, setSpacing_1, setImageBorder_1, setImageBoxShadow_1, changeImage_1, getFormatState_1, clearFormat_1, insertLink_1, removeLink_1, adjustLinkSelection_1, setImageAltText_1, adjustImageSelection_1, setParagraphMargin_1, toggleCode_1, insertEntity_1, insertTableRow_1, insertTableColumn_1, clearSelectedCells_1, createEditorContextForEntity_1, formatTableWithContentModel_1, formatImageWithContentModel_1, formatParagraphWithContentModel_1, formatSegmentWithContentModel_1, formatTextSegmentBeforeSelectionMarker_1, formatInsertPointWithContentModel_1, setListType_1, setModelListStyle_1, setModelListStartNumber_1, findListItemsInSameThread_1, setModelIndentation_1, matchLink_1, promoteLink_1, getListAnnounceData_1, queryContentModelBlocks_1, adjustWordSelection_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.adjustWordSelection = exports.queryContentModelBlocks = exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = exports.formatSegmentWithContentModel = exports.formatParagraphWithContentModel = exports.formatImageWithContentModel = exports.formatTableWithContentModel = exports.createEditorContextForEntity = exports.clearSelectedCells = exports.insertTableColumn = exports.insertTableRow = exports.insertEntity = exports.toggleCode = exports.setParagraphMargin = exports.adjustImageSelection = exports.setImageAltText = exports.adjustLinkSelection = exports.removeLink = exports.insertLink = exports.clearFormat = exports.getFormatState = exports.changeImage = exports.setImageBoxShadow = exports.setImageBorder = exports.setSpacing = exports.toggleBlockQuote = exports.setHeadingLevel = exports.setDirection = exports.setAlignment = exports.setIndentation = exports.setListStartNumber = exports.setListStyle = exports.insertImage = exports.splitTextSegment = exports.changeCapitalization = exports.applySegmentFormat = exports.changeFontSize = exports.setTextColor = exports.setFontSize = exports.setFontName = exports.setBackgroundColor = exports.toggleSuperscript = exports.toggleSubscript = exports.toggleStrikethrough = exports.toggleUnderline = exports.toggleItalic = exports.toggleBold = exports.toggleNumbering = exports.toggleBullet = exports.applyTableBorderFormat = exports.editTable = exports.setTableCellShade = exports.formatTable = exports.insertTable = void 0;
|
|
4
|
+
exports.adjustWordSelection = exports.queryContentModelBlocks = exports.getListAnnounceData = exports.getPromoteLink = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = exports.formatSegmentWithContentModel = exports.formatParagraphWithContentModel = exports.formatImageWithContentModel = exports.formatTableWithContentModel = exports.createEditorContextForEntity = exports.clearSelectedCells = exports.insertTableColumn = exports.insertTableRow = exports.insertEntity = exports.toggleCode = exports.setParagraphMargin = exports.adjustImageSelection = exports.setImageAltText = exports.adjustLinkSelection = exports.removeLink = exports.insertLink = exports.clearFormat = exports.getFormatState = exports.changeImage = exports.setImageBoxShadow = exports.setImageBorder = exports.setSpacing = exports.toggleBlockQuote = exports.setHeadingLevel = exports.setDirection = exports.setAlignment = exports.setIndentation = exports.setListStartNumber = exports.setListStyle = exports.insertImage = exports.splitTextSegment = exports.changeCapitalization = exports.applySegmentFormat = exports.changeFontSize = exports.setTextColor = exports.setFontSize = exports.setFontName = exports.setBackgroundColor = exports.toggleSuperscript = exports.toggleSubscript = exports.toggleStrikethrough = exports.toggleUnderline = exports.toggleItalic = exports.toggleBold = exports.toggleNumbering = exports.toggleBullet = exports.applyTableBorderFormat = exports.editTable = exports.setTableCellShade = exports.formatTable = exports.insertTable = void 0;
|
|
5
5
|
Object.defineProperty(exports, "insertTable", { enumerable: true, get: function () { return insertTable_1.insertTable; } });
|
|
6
6
|
Object.defineProperty(exports, "formatTable", { enumerable: true, get: function () { return formatTable_1.formatTable; } });
|
|
7
7
|
Object.defineProperty(exports, "setTableCellShade", { enumerable: true, get: function () { return setTableCellShade_1.setTableCellShade; } });
|
|
@@ -62,6 +62,7 @@ define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/tabl
|
|
|
62
62
|
Object.defineProperty(exports, "setModelIndentation", { enumerable: true, get: function () { return setModelIndentation_1.setModelIndentation; } });
|
|
63
63
|
Object.defineProperty(exports, "matchLink", { enumerable: true, get: function () { return matchLink_1.matchLink; } });
|
|
64
64
|
Object.defineProperty(exports, "promoteLink", { enumerable: true, get: function () { return promoteLink_1.promoteLink; } });
|
|
65
|
+
Object.defineProperty(exports, "getPromoteLink", { enumerable: true, get: function () { return promoteLink_1.getPromoteLink; } });
|
|
65
66
|
Object.defineProperty(exports, "getListAnnounceData", { enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } });
|
|
66
67
|
Object.defineProperty(exports, "queryContentModelBlocks", { enumerable: true, get: function () { return queryContentModelBlocks_1.queryContentModelBlocks; } });
|
|
67
68
|
Object.defineProperty(exports, "adjustWordSelection", { enumerable: true, get: function () { return adjustWordSelection_1.adjustWordSelection; } });
|
package/lib-amd/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,sGAAA,SAAS,OAAA;IACT,gIAAA,sBAAsB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JAAA,iCAAiC,OAAA;IAEjC,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,kIAAA,uBAAuB,OAAA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,OAAA;IACT,0GAAA,WAAW,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,sGAAA,SAAS,OAAA;IACT,gIAAA,sBAAsB,OAAA;IACtB,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAClB,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,wHAAA,kBAAkB,OAAA;IAClB,4HAAA,oBAAoB,OAAA;IACpB,oHAAA,gBAAgB,OAAA;IAChB,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,wHAAA,kBAAkB,OAAA;IAClB,gHAAA,cAAc,OAAA;IACd,4GAAA,YAAY,OAAA;IACZ,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,oHAAA,gBAAgB,OAAA;IAChB,wGAAA,UAAU,OAAA;IACV,gHAAA,cAAc,OAAA;IACd,sHAAA,iBAAiB,OAAA;IACjB,0GAAA,WAAW,OAAA;IACX,gHAAA,cAAc,OAAA;IACd,0GAAA,WAAW,OAAA;IACX,wGAAA,UAAU,OAAA;IACV,wGAAA,UAAU,OAAA;IACV,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,4HAAA,oBAAoB,OAAA;IACpB,wHAAA,kBAAkB,OAAA;IAClB,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAElB,4IAAA,4BAA4B,OAAA;IAC5B,0IAAA,2BAA2B,OAAA;IAC3B,0IAAA,2BAA2B,OAAA;IAC3B,kJAAA,+BAA+B,OAAA;IAC/B,8IAAA,6BAA6B,OAAA;IAC7B,gKAAA,sCAAsC,OAAA;IACtC,sJAAA,iCAAiC,OAAA;IAEjC,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,kIAAA,uBAAuB,OAAA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,OAAA;IACT,0GAAA,WAAW,OAAA;IAAE,6GAAA,cAAc,OAAA;IAC3B,0HAAA,mBAAmB,OAAA;IACnB,kIAAA,uBAAuB,OAAA;IACvB,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink, getPromoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\nexport { adjustWordSelection } from './modelApi/selection/adjustWordSelection';\n"]}
|
|
@@ -98,7 +98,13 @@ define(["require", "exports", "tslib", "../list/findListItemsInSameThread", "../
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
});
|
|
101
|
-
|
|
101
|
+
if (paragraphOrListItem.length > 0) {
|
|
102
|
+
(0, roosterjs_content_model_dom_1.normalizeContentModel)(model);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
102
108
|
}
|
|
103
109
|
exports.setModelIndentation = setModelIndentation;
|
|
104
110
|
function isSelected(listItem) {
|