roosterjs-content-model-api 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/modelApi/block/setModelDirection.js +0 -1
- package/lib/modelApi/block/setModelDirection.js.map +1 -1
- package/lib/modelApi/block/toggleModelBlockQuote.d.ts +1 -1
- package/lib/modelApi/block/toggleModelBlockQuote.js +6 -4
- package/lib/modelApi/block/toggleModelBlockQuote.js.map +1 -1
- package/lib/modelApi/common/retrieveModelFormatState.js +0 -2
- package/lib/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib/modelApi/common/wrapBlock.d.ts +2 -2
- package/lib/modelApi/common/wrapBlock.js +8 -4
- package/lib/modelApi/common/wrapBlock.js.map +1 -1
- package/lib/modelApi/link/matchLink.d.ts +29 -0
- package/lib/modelApi/link/matchLink.js +95 -0
- package/lib/modelApi/link/matchLink.js.map +1 -0
- package/lib/modelApi/list/setListType.d.ts +3 -1
- package/lib/modelApi/list/setListType.js +6 -9
- package/lib/modelApi/list/setListType.js.map +1 -1
- package/lib/publicApi/block/toggleBlockQuote.d.ts +1 -1
- package/lib/publicApi/block/toggleBlockQuote.js +10 -6
- package/lib/publicApi/block/toggleBlockQuote.js.map +1 -1
- package/lib/publicApi/entity/insertEntity.js +6 -10
- package/lib/publicApi/entity/insertEntity.js.map +1 -1
- package/lib/publicApi/format/getFormatState.d.ts +1 -21
- package/lib/publicApi/format/getFormatState.js +1 -69
- package/lib/publicApi/format/getFormatState.js.map +1 -1
- package/lib/publicApi/image/changeImage.js +1 -1
- package/lib/publicApi/image/changeImage.js.map +1 -1
- package/lib/publicApi/link/insertLink.js +3 -12
- package/lib/publicApi/link/insertLink.js.map +1 -1
- package/lib/publicApi/segment/changeCapitalization.js +0 -1
- package/lib/publicApi/segment/changeCapitalization.js.map +1 -1
- package/lib/publicApi/utils/formatSegmentWithContentModel.js +2 -7
- package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib-amd/index.d.ts +1 -0
- package/lib-amd/index.js +3 -2
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/modelApi/block/setModelDirection.js +0 -1
- package/lib-amd/modelApi/block/setModelDirection.js.map +1 -1
- package/lib-amd/modelApi/block/toggleModelBlockQuote.d.ts +1 -1
- package/lib-amd/modelApi/block/toggleModelBlockQuote.js +6 -4
- package/lib-amd/modelApi/block/toggleModelBlockQuote.js.map +1 -1
- package/lib-amd/modelApi/common/retrieveModelFormatState.js +0 -2
- package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib-amd/modelApi/common/wrapBlock.d.ts +2 -2
- package/lib-amd/modelApi/common/wrapBlock.js +8 -4
- package/lib-amd/modelApi/common/wrapBlock.js.map +1 -1
- package/lib-amd/modelApi/link/matchLink.d.ts +29 -0
- package/lib-amd/modelApi/link/matchLink.js +95 -0
- package/lib-amd/modelApi/link/matchLink.js.map +1 -0
- package/lib-amd/modelApi/list/setListType.d.ts +3 -1
- package/lib-amd/modelApi/list/setListType.js +6 -9
- package/lib-amd/modelApi/list/setListType.js.map +1 -1
- package/lib-amd/publicApi/block/toggleBlockQuote.d.ts +1 -1
- package/lib-amd/publicApi/block/toggleBlockQuote.js +10 -6
- package/lib-amd/publicApi/block/toggleBlockQuote.js.map +1 -1
- package/lib-amd/publicApi/entity/insertEntity.js +6 -10
- package/lib-amd/publicApi/entity/insertEntity.js.map +1 -1
- package/lib-amd/publicApi/format/getFormatState.d.ts +1 -21
- package/lib-amd/publicApi/format/getFormatState.js +2 -67
- package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
- package/lib-amd/publicApi/image/changeImage.js +1 -1
- package/lib-amd/publicApi/image/changeImage.js.map +1 -1
- package/lib-amd/publicApi/link/insertLink.js +3 -12
- package/lib-amd/publicApi/link/insertLink.js.map +1 -1
- package/lib-amd/publicApi/segment/changeCapitalization.js +0 -1
- package/lib-amd/publicApi/segment/changeCapitalization.js.map +1 -1
- package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +2 -7
- package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib-mjs/index.d.ts +1 -0
- package/lib-mjs/index.js +1 -0
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/modelApi/block/setModelDirection.js +0 -1
- package/lib-mjs/modelApi/block/setModelDirection.js.map +1 -1
- package/lib-mjs/modelApi/block/toggleModelBlockQuote.d.ts +1 -1
- package/lib-mjs/modelApi/block/toggleModelBlockQuote.js +6 -4
- package/lib-mjs/modelApi/block/toggleModelBlockQuote.js.map +1 -1
- package/lib-mjs/modelApi/common/retrieveModelFormatState.js +0 -2
- package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib-mjs/modelApi/common/wrapBlock.d.ts +2 -2
- package/lib-mjs/modelApi/common/wrapBlock.js +8 -4
- package/lib-mjs/modelApi/common/wrapBlock.js.map +1 -1
- package/lib-mjs/modelApi/link/matchLink.d.ts +29 -0
- package/lib-mjs/modelApi/link/matchLink.js +91 -0
- package/lib-mjs/modelApi/link/matchLink.js.map +1 -0
- package/lib-mjs/modelApi/list/setListType.d.ts +3 -1
- package/lib-mjs/modelApi/list/setListType.js +6 -9
- package/lib-mjs/modelApi/list/setListType.js.map +1 -1
- package/lib-mjs/publicApi/block/toggleBlockQuote.d.ts +1 -1
- package/lib-mjs/publicApi/block/toggleBlockQuote.js +10 -6
- package/lib-mjs/publicApi/block/toggleBlockQuote.js.map +1 -1
- package/lib-mjs/publicApi/entity/insertEntity.js +6 -10
- package/lib-mjs/publicApi/entity/insertEntity.js.map +1 -1
- package/lib-mjs/publicApi/format/getFormatState.d.ts +1 -21
- package/lib-mjs/publicApi/format/getFormatState.js +1 -67
- package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
- package/lib-mjs/publicApi/image/changeImage.js +1 -1
- package/lib-mjs/publicApi/image/changeImage.js.map +1 -1
- package/lib-mjs/publicApi/link/insertLink.js +2 -11
- package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
- package/lib-mjs/publicApi/segment/changeCapitalization.js +0 -1
- package/lib-mjs/publicApi/segment/changeCapitalization.js.map +1 -1
- package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +2 -7
- package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/package.json +4 -6
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var toggleModelBlockQuote_1 = require("../../modelApi/block/toggleModelBlockQuote");
|
|
5
|
-
var
|
|
5
|
+
var DefaultQuoteFormatLtr = {
|
|
6
6
|
borderLeft: '3px solid rgb(200, 200, 200)',
|
|
7
7
|
textColor: 'rgb(102, 102, 102)',
|
|
8
8
|
};
|
|
9
|
+
var DefaultQuoteFormatRtl = {
|
|
10
|
+
borderRight: '3px solid rgb(200, 200, 200)',
|
|
11
|
+
textColor: 'rgb(102, 102, 102)',
|
|
12
|
+
};
|
|
9
13
|
var BuildInQuoteFormat = {
|
|
10
14
|
marginTop: '1em',
|
|
11
15
|
marginBottom: '1em',
|
|
12
16
|
marginLeft: '40px',
|
|
13
17
|
marginRight: '40px',
|
|
14
|
-
paddingLeft: '10px',
|
|
15
18
|
};
|
|
16
19
|
/**
|
|
17
20
|
* Toggle BLOCKQUOTE state of selected paragraphs.
|
|
@@ -20,13 +23,14 @@ var BuildInQuoteFormat = {
|
|
|
20
23
|
* @param editor The editor object to toggle BLOCKQUOTE onto
|
|
21
24
|
* @param quoteFormat @optional Block format for the new quote object
|
|
22
25
|
*/
|
|
23
|
-
function toggleBlockQuote(editor, quoteFormat) {
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
+
function toggleBlockQuote(editor, quoteFormat, quoteFormatRtl) {
|
|
27
|
+
var _a;
|
|
28
|
+
var fullQuoteFormatLtr = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, BuildInQuoteFormat), { paddingLeft: '10px' }), (quoteFormat !== null && quoteFormat !== void 0 ? quoteFormat : DefaultQuoteFormatLtr));
|
|
29
|
+
var fullQuoteFormatRtl = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, BuildInQuoteFormat), { paddingRight: '10px', direction: 'rtl' }), ((_a = quoteFormatRtl !== null && quoteFormatRtl !== void 0 ? quoteFormatRtl : quoteFormat) !== null && _a !== void 0 ? _a : DefaultQuoteFormatRtl));
|
|
26
30
|
editor.focus();
|
|
27
31
|
editor.formatContentModel(function (model, context) {
|
|
28
32
|
context.newPendingFormat = 'preserve';
|
|
29
|
-
return (0, toggleModelBlockQuote_1.toggleModelBlockQuote)(model,
|
|
33
|
+
return (0, toggleModelBlockQuote_1.toggleModelBlockQuote)(model, fullQuoteFormatLtr, fullQuoteFormatRtl);
|
|
30
34
|
}, {
|
|
31
35
|
apiName: 'toggleBlockQuote',
|
|
32
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggleBlockQuote.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/block/toggleBlockQuote.ts"],"names":[],"mappings":";;;AAAA,oFAAmF;AAMnF,IAAM,
|
|
1
|
+
{"version":3,"file":"toggleBlockQuote.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/block/toggleBlockQuote.ts"],"names":[],"mappings":";;;AAAA,oFAAmF;AAMnF,IAAM,qBAAqB,GAAsC;IAC7D,UAAU,EAAE,8BAA8B;IAC1C,SAAS,EAAE,oBAAoB;CAClC,CAAC;AACF,IAAM,qBAAqB,GAAsC;IAC7D,WAAW,EAAE,8BAA8B;IAC3C,SAAS,EAAE,oBAAoB;CAClC,CAAC;AACF,IAAM,kBAAkB,GAAsC;IAC1D,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,KAAK;IACnB,UAAU,EAAE,MAAM;IAClB,WAAW,EAAE,MAAM;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,SAAwB,gBAAgB,CACpC,MAAyB,EACzB,WAA+C,EAC/C,cAAkD;;IAElD,IAAM,kBAAkB,yEACjB,kBAAkB,KACrB,WAAW,EAAE,MAAM,KAChB,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,qBAAqB,CAAC,CAC5C,CAAC;IACF,IAAM,kBAAkB,yEACjB,kBAAkB,KACrB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,KAAK,KACb,CAAC,MAAA,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,WAAW,mCAAI,qBAAqB,CAAC,CAC9D,CAAC;IAEF,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAEtC,OAAO,IAAA,6CAAqB,EAAC,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;IAChF,CAAC,EACD;QACI,OAAO,EAAE,kBAAkB;KAC9B,CACJ,CAAC;AACN,CAAC;AA7BD,mCA6BC","sourcesContent":["import { toggleModelBlockQuote } from '../../modelApi/block/toggleModelBlockQuote';\nimport type {\n ContentModelFormatContainerFormat,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\nconst DefaultQuoteFormatLtr: ContentModelFormatContainerFormat = {\n borderLeft: '3px solid rgb(200, 200, 200)',\n textColor: 'rgb(102, 102, 102)',\n};\nconst DefaultQuoteFormatRtl: ContentModelFormatContainerFormat = {\n borderRight: '3px solid rgb(200, 200, 200)',\n textColor: 'rgb(102, 102, 102)',\n};\nconst BuildInQuoteFormat: ContentModelFormatContainerFormat = {\n marginTop: '1em',\n marginBottom: '1em',\n marginLeft: '40px',\n marginRight: '40px',\n};\n\n/**\n * Toggle BLOCKQUOTE state of selected paragraphs.\n * If any selected paragraph is not under a BLOCKQUOTE, wrap them into a BLOCKQUOTE.\n * Otherwise, unwrap all related BLOCKQUOTEs.\n * @param editor The editor object to toggle BLOCKQUOTE onto\n * @param quoteFormat @optional Block format for the new quote object\n */\nexport default function toggleBlockQuote(\n editor: IStandaloneEditor,\n quoteFormat?: ContentModelFormatContainerFormat,\n quoteFormatRtl?: ContentModelFormatContainerFormat\n) {\n const fullQuoteFormatLtr: ContentModelFormatContainerFormat = {\n ...BuildInQuoteFormat,\n paddingLeft: '10px',\n ...(quoteFormat ?? DefaultQuoteFormatLtr),\n };\n const fullQuoteFormatRtl: ContentModelFormatContainerFormat = {\n ...BuildInQuoteFormat,\n paddingRight: '10px',\n direction: 'rtl',\n ...(quoteFormatRtl ?? quoteFormat ?? DefaultQuoteFormatRtl),\n };\n\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n context.newPendingFormat = 'preserve';\n\n return toggleModelBlockQuote(model, fullQuoteFormatLtr, fullQuoteFormatRtl);\n },\n {\n apiName: 'toggleBlockQuote',\n }\n );\n}\n"]}
|
|
@@ -23,16 +23,12 @@ function insertEntity(editor, type, isBlock, position, options) {
|
|
|
23
23
|
}, {
|
|
24
24
|
selectionOverride: typeof position === 'object' ? position : undefined,
|
|
25
25
|
changeSource: roosterjs_content_model_core_1.ChangeSource.InsertEntity,
|
|
26
|
-
getChangeData: function () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
isReadonly: true,
|
|
33
|
-
};
|
|
34
|
-
return entity;
|
|
35
|
-
},
|
|
26
|
+
getChangeData: function () { return ({
|
|
27
|
+
wrapper: wrapper,
|
|
28
|
+
type: type,
|
|
29
|
+
id: '',
|
|
30
|
+
isReadonly: true,
|
|
31
|
+
}); },
|
|
36
32
|
apiName: 'insertEntity',
|
|
37
33
|
});
|
|
38
34
|
return entityModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertEntity.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/entity/insertEntity.ts"],"names":[],"mappings":";;AAAA,6EAA4D;AAC5D,2EAAkF;AAClF,6EAA4E;
|
|
1
|
+
{"version":3,"file":"insertEntity.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/entity/insertEntity.ts"],"names":[],"mappings":";;AAAA,6EAA4D;AAC5D,2EAAkF;AAClF,6EAA4E;AAS5E,IAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,IAAM,eAAe,GAAG,MAAM,CAAC;AAwC/B,SAAwB,YAAY,CAChC,MAAyB,EACzB,IAAY,EACZ,OAAgB,EAChB,QAA8C,EAC9C,OAA6B;IAEvB,IAAA,KAAsE,OAAO,IAAI,EAAE,EAAjF,WAAW,iBAAA,EAAE,gBAAgB,sBAAA,EAAE,cAAc,oBAAA,EAAE,gBAAgB,sBAAkB,CAAC;IAC1F,IAAM,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;IAC/F,IAAM,OAAO,GAAG,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAEzE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC;IAEtD,IAAI,WAAW,EAAE;QACb,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;KACpC;IAED,IAAM,WAAW,GAAG,IAAA,0CAAY,EAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAE3F,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAA,qCAAiB,EACb,KAAK,EACL,WAAW,EACX,OAAO,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAChD,OAAO,EACP,gBAAgB,EAChB,OAAO,CACV,CAAC;QAEF,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QAC5C,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEtC,OAAO,IAAI,CAAC;IAChB,CAAC,EACD;QACI,iBAAiB,EAAE,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;QACtE,YAAY,EAAE,2CAAY,CAAC,YAAY;QACvC,aAAa,EAAE,cAAM,OAAA,CAAC;YAClB,OAAO,SAAA;YACP,IAAI,MAAA;YACJ,EAAE,EAAE,EAAE;YACN,UAAU,EAAE,IAAI;SACnB,CAAC,EALmB,CAKnB;QACF,OAAO,EAAE,cAAc;KAC1B,CACJ,CAAC;IAEF,OAAO,WAAW,CAAC;AACvB,CAAC;AAnDD,+BAmDC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-core';\nimport { createEntity, normalizeContentModel } from 'roosterjs-content-model-dom';\nimport { insertEntityModel } from '../../modelApi/entity/insertEntityModel';\nimport type {\n ContentModelEntity,\n DOMSelection,\n InsertEntityPosition,\n InsertEntityOptions,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\nconst BlockEntityTag = 'div';\nconst InlineEntityTag = 'span';\n\n/**\n * Insert an entity into editor\n * @param editor The Content Model editor\n * @param type Type of entity\n * @param isBlock True to insert a block entity, false to insert an inline entity\n * @param position Position of the entity to insert. It can be\n * Value of InsertEntityPosition: see InsertEntityPosition\n * selectionRangeEx: Use this range instead of current focus position to insert. After insert, focus will be moved to\n * the beginning of this range (when focusAfterEntity is not set to true) or after the new entity (when focusAfterEntity is set to true)\n * @param options Move options to insert. See InsertEntityOptions\n */\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: boolean,\n position: 'focus' | 'begin' | 'end' | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null;\n\n/**\n * Insert a block entity into editor\n * @param editor The Content Model editor\n * @param type Type of entity\n * @param isBlock Must be true for a block entity\n * @param position Position of the entity to insert. It can be\n * Value of InsertEntityPosition: see InsertEntityPosition\n * selectionRangeEx: Use this range instead of current focus position to insert. After insert, focus will be moved to\n * the beginning of this range (when focusAfterEntity is not set to true) or after the new entity (when focusAfterEntity is set to true)\n * @param options Move options to insert. See InsertEntityOptions\n */\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: true,\n position: InsertEntityPosition | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null;\n\nexport default function insertEntity(\n editor: IStandaloneEditor,\n type: string,\n isBlock: boolean,\n position?: InsertEntityPosition | DOMSelection,\n options?: InsertEntityOptions\n): ContentModelEntity | null {\n const { contentNode, focusAfterEntity, wrapperDisplay, skipUndoSnapshot } = options || {};\n const wrapper = editor.getDocument().createElement(isBlock ? BlockEntityTag : InlineEntityTag);\n const display = wrapperDisplay ?? (isBlock ? undefined : 'inline-block');\n\n wrapper.style.setProperty('display', display || null);\n\n if (contentNode) {\n wrapper.appendChild(contentNode);\n }\n\n const entityModel = createEntity(wrapper, true /*isReadonly*/, undefined /*format*/, type);\n\n editor.formatContentModel(\n (model, context) => {\n insertEntityModel(\n model,\n entityModel,\n typeof position == 'string' ? position : 'focus',\n isBlock,\n focusAfterEntity,\n context\n );\n\n normalizeContentModel(model);\n\n context.skipUndoSnapshot = skipUndoSnapshot;\n context.newEntities.push(entityModel);\n\n return true;\n },\n {\n selectionOverride: typeof position === 'object' ? position : undefined,\n changeSource: ChangeSource.InsertEntity,\n getChangeData: () => ({\n wrapper,\n type,\n id: '',\n isReadonly: true,\n }),\n apiName: 'insertEntity',\n }\n );\n\n return entityModel;\n}\n"]}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
import type { IStandaloneEditor,
|
|
1
|
+
import type { IStandaloneEditor, ContentModelFormatState } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* Get current format state
|
|
4
4
|
* @param editor The editor to get format from
|
|
5
5
|
*/
|
|
6
6
|
export default function getFormatState(editor: IStandaloneEditor): ContentModelFormatState;
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
interface FormatStateContext extends DomToModelContext {
|
|
11
|
-
/**
|
|
12
|
-
* An optional stack of parent elements to process. When provided, the child nodes of current parent element will be ignored,
|
|
13
|
-
* but use the top element in this stack instead in childProcessor.
|
|
14
|
-
*/
|
|
15
|
-
nodeStack?: Node[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
* Export for test only
|
|
20
|
-
* In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create
|
|
21
|
-
* content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.
|
|
22
|
-
* This "reduced" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,
|
|
23
|
-
* then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state
|
|
24
|
-
*/
|
|
25
|
-
export declare function reducedModelChildProcessor(group: ContentModelBlockGroup, parent: ParentNode, context: FormatStateContext): void;
|
|
26
|
-
export {};
|
|
@@ -1,89 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reducedModelChildProcessor = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
6
3
|
var retrieveModelFormatState_1 = require("../../modelApi/common/retrieveModelFormatState");
|
|
7
|
-
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
8
4
|
/**
|
|
9
5
|
* Get current format state
|
|
10
6
|
* @param editor The editor to get format from
|
|
11
7
|
*/
|
|
12
8
|
function getFormatState(editor) {
|
|
13
9
|
var pendingFormat = editor.getPendingFormat();
|
|
14
|
-
var model = editor.
|
|
15
|
-
processorOverride: {
|
|
16
|
-
child: reducedModelChildProcessor,
|
|
17
|
-
},
|
|
18
|
-
});
|
|
10
|
+
var model = editor.getContentModelCopy('reduced');
|
|
19
11
|
var manager = editor.getSnapshotsManager();
|
|
20
12
|
var result = {
|
|
21
13
|
canUndo: manager.hasNewContent || manager.canMove(-1),
|
|
22
14
|
canRedo: manager.canMove(1),
|
|
23
15
|
isDarkMode: editor.isDarkMode(),
|
|
24
|
-
zoomScale: editor.getZoomScale(),
|
|
25
16
|
};
|
|
26
17
|
(0, retrieveModelFormatState_1.retrieveModelFormatState)(model, pendingFormat, result);
|
|
27
18
|
return result;
|
|
28
19
|
}
|
|
29
20
|
exports.default = getFormatState;
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
* Export for test only
|
|
33
|
-
* In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create
|
|
34
|
-
* content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.
|
|
35
|
-
* This "reduced" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,
|
|
36
|
-
* then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state
|
|
37
|
-
*/
|
|
38
|
-
function reducedModelChildProcessor(group, parent, context) {
|
|
39
|
-
if (!context.nodeStack) {
|
|
40
|
-
var selectionRootNode = (0, roosterjs_content_model_core_1.getSelectionRootNode)(context.selection);
|
|
41
|
-
context.nodeStack = selectionRootNode ? createNodeStack(parent, selectionRootNode) : [];
|
|
42
|
-
}
|
|
43
|
-
var stackChild = context.nodeStack.pop();
|
|
44
|
-
if (stackChild) {
|
|
45
|
-
var _a = (0, tslib_1.__read)((0, roosterjs_content_model_dom_1.getRegularSelectionOffsets)(context, parent), 2), nodeStartOffset = _a[0], nodeEndOffset = _a[1];
|
|
46
|
-
// If selection is not on this node, skip getting node index to save some time since we don't need it here
|
|
47
|
-
var index = nodeStartOffset >= 0 || nodeEndOffset >= 0 ? getChildIndex(parent, stackChild) : -1;
|
|
48
|
-
if (index >= 0) {
|
|
49
|
-
(0, roosterjs_content_model_dom_1.handleRegularSelection)(index, context, group, nodeStartOffset, nodeEndOffset);
|
|
50
|
-
}
|
|
51
|
-
(0, roosterjs_content_model_dom_1.processChildNode)(group, stackChild, context);
|
|
52
|
-
if (index >= 0) {
|
|
53
|
-
(0, roosterjs_content_model_dom_1.handleRegularSelection)(index + 1, context, group, nodeStartOffset, nodeEndOffset);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
// No child node from node stack, that means we have reached the deepest node of selection.
|
|
58
|
-
// Now we can use default child processor to perform full sub tree scanning for content model,
|
|
59
|
-
// So that all selected node will be included.
|
|
60
|
-
context.defaultElementProcessors.child(group, parent, context);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.reducedModelChildProcessor = reducedModelChildProcessor;
|
|
64
|
-
function createNodeStack(root, startNode) {
|
|
65
|
-
var result = [];
|
|
66
|
-
var node = startNode;
|
|
67
|
-
while (node && root != node && root.contains(node)) {
|
|
68
|
-
if ((0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE') && node.tagName == 'TABLE') {
|
|
69
|
-
// For table, we can't do a reduced model creation since we need to handle their cells and indexes,
|
|
70
|
-
// so clean up whatever we already have, and just put table into the stack
|
|
71
|
-
result.splice(0, result.length, node);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
result.push(node);
|
|
75
|
-
}
|
|
76
|
-
node = node.parentNode;
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
function getChildIndex(parent, stackChild) {
|
|
81
|
-
var index = 0;
|
|
82
|
-
var child = parent.firstChild;
|
|
83
|
-
while (child && child != stackChild) {
|
|
84
|
-
index++;
|
|
85
|
-
child = child.nextSibling;
|
|
86
|
-
}
|
|
87
|
-
return index;
|
|
88
|
-
}
|
|
89
21
|
//# sourceMappingURL=getFormatState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":";;AAAA,2FAA0F;AAG1F;;;GAGG;AACH,SAAwB,cAAc,CAAC,MAAyB;IAC5D,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAChD,IAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACpD,IAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC;IAC7C,IAAM,MAAM,GAA4B;QACpC,OAAO,EAAE,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACrD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;KAClC,CAAC;IAEF,IAAA,mDAAwB,EAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAEvD,OAAO,MAAM,CAAC;AAClB,CAAC;AAbD,iCAaC","sourcesContent":["import { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState';\nimport type { IStandaloneEditor, ContentModelFormatState } from 'roosterjs-content-model-types';\n\n/**\n * Get current format state\n * @param editor The editor to get format from\n */\nexport default function getFormatState(editor: IStandaloneEditor): ContentModelFormatState {\n const pendingFormat = editor.getPendingFormat();\n const model = editor.getContentModelCopy('reduced');\n const manager = editor.getSnapshotsManager();\n const result: ContentModelFormatState = {\n canUndo: manager.hasNewContent || manager.canMove(-1),\n canRedo: manager.canMove(1),\n isDarkMode: editor.isDarkMode(),\n };\n\n retrieveModelFormatState(model, pendingFormat, result);\n\n return result;\n}\n"]}
|
|
@@ -21,7 +21,7 @@ function changeImage(editor, file) {
|
|
|
21
21
|
image.format.width = '';
|
|
22
22
|
image.format.height = '';
|
|
23
23
|
image.alt = '';
|
|
24
|
-
editor.
|
|
24
|
+
editor.triggerEvent('editImage', {
|
|
25
25
|
image: selection.image,
|
|
26
26
|
previousSrc: previousSrc,
|
|
27
27
|
newSrc: dataUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/changeImage.ts"],"names":[],"mappings":";;AAAA,oFAA+E;
|
|
1
|
+
{"version":3,"file":"changeImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/changeImage.ts"],"names":[],"mappings":";;AAAA,oFAA+E;AAC/E,6EAA6E;AAG7E;;;;GAIG;AACH,SAAwB,WAAW,CAAC,MAAyB,EAAE,IAAU;IACrE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC3C,IAAA,uCAAQ,EAAC,IAAI,EAAE,UAAA,OAAO;QAClB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,OAAO,EAAE;YAChE,IAAA,qCAA2B,EAAC,MAAM,EAAE,aAAa,EAAE,UAAC,KAAwB;;gBACxE,IAAM,WAAW,GAAG,MAAA,MAAA,IAAA,kDAAmB,EAAC,KAAK,CAAC,0CAAE,GAAG,mCAAI,EAAE,CAAC;gBAC1D,IAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC;gBAE9B,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC;gBACpB,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;gBACnB,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;gBACxB,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;gBACzB,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC;gBAEf,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE;oBAC7B,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,WAAW,aAAA;oBACX,MAAM,EAAE,OAAO;oBACf,WAAW,aAAA;iBACd,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAzBD,8BAyBC","sourcesContent":["import formatImageWithContentModel from '../utils/formatImageWithContentModel';\nimport { readFile, updateImageMetadata } from 'roosterjs-content-model-core';\nimport type { ContentModelImage, IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Change the selected image src\n * @param editor The editor instance\n * @param file The image file\n */\nexport default function changeImage(editor: IStandaloneEditor, file: File) {\n editor.focus();\n\n const selection = editor.getDOMSelection();\n readFile(file, dataUrl => {\n if (dataUrl && !editor.isDisposed() && selection?.type === 'image') {\n formatImageWithContentModel(editor, 'changeImage', (image: ContentModelImage) => {\n const originalSrc = updateImageMetadata(image)?.src ?? '';\n const previousSrc = image.src;\n\n image.src = dataUrl;\n image.dataset = {};\n image.format.width = '';\n image.format.height = '';\n image.alt = '';\n\n editor.triggerEvent('editImage', {\n image: selection.image,\n previousSrc,\n newSrc: dataUrl,\n originalSrc,\n });\n });\n }\n });\n}\n"]}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var adjustTrailingSpaceSelection_1 = require("../../modelApi/selection/adjustTrailingSpaceSelection");
|
|
5
5
|
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
6
|
-
var
|
|
6
|
+
var matchLink_1 = require("../../modelApi/link/matchLink");
|
|
7
7
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
8
8
|
// Regex matching Uri scheme
|
|
9
9
|
var URI_REGEX = /^[a-zA-Z]+:/i;
|
|
@@ -28,7 +28,7 @@ function insertLink(editor, link, anchorTitle, displayText, target) {
|
|
|
28
28
|
editor.focus();
|
|
29
29
|
var url = (checkXss(link) || '').trim();
|
|
30
30
|
if (url) {
|
|
31
|
-
var linkData_1 = (0,
|
|
31
|
+
var linkData_1 = (0, matchLink_1.matchLink)(url);
|
|
32
32
|
var linkUrl_1 = linkData_1 ? linkData_1.normalizedUrl : applyLinkPrefix(url);
|
|
33
33
|
var links_1 = [];
|
|
34
34
|
var anchorNode_1;
|
|
@@ -90,7 +90,6 @@ var createLink = function (url, anchorTitle, target, underline) {
|
|
|
90
90
|
},
|
|
91
91
|
};
|
|
92
92
|
};
|
|
93
|
-
// TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.
|
|
94
93
|
function applyLinkPrefix(url) {
|
|
95
94
|
if (!url) {
|
|
96
95
|
return url;
|
|
@@ -115,15 +114,7 @@ function applyLinkPrefix(url) {
|
|
|
115
114
|
}
|
|
116
115
|
return prefix + url;
|
|
117
116
|
}
|
|
118
|
-
// TODO: This is copied from original code. However, ContentModel should be able to filter out malicious
|
|
119
|
-
// attributes later, so no need to use HtmlSanitizer here
|
|
120
117
|
function checkXss(link) {
|
|
121
|
-
|
|
122
|
-
var a = document.createElement('a');
|
|
123
|
-
a.href = link || '';
|
|
124
|
-
sanitizer.sanitize(a);
|
|
125
|
-
// We use getAttribute because some browsers will try to make the href property a valid link.
|
|
126
|
-
// This has unintended side effects when the link lacks a protocol.
|
|
127
|
-
return a.getAttribute('href') || '';
|
|
118
|
+
return link.match(/s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : link;
|
|
128
119
|
}
|
|
129
120
|
//# sourceMappingURL=insertLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roos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AG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YACnC,MAAM,GAAG,QAAQ,CAAC;SACrB;aAAM;YACH,sBAAsB;YACtB,MAAM,GAAG,SAAS,CAAC;SACtB;KACJ;IAED,OAAO,MAAM,GAAG,GAAG,CAAC;AACxB,CAAC;AAED,wGAAwG;AACxG,yDAAyD;AACzD,SAAS,QAAQ,CAAC,IAAY;IAC1B,IAAM,SAAS,GAAG,IAAI,oCAAa,EAAE,CAAC;IACtC,IAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAEtC,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAEpB,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,6FAA6F;IAC7F,mEAAmE;IACnE,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';\nimport { HtmlSanitizer, matchLink } from 'roosterjs-editor-dom';\nimport type { ContentModelLink, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n addLink,\n addSegment,\n createContentModelDocument,\n createText,\n} from 'roosterjs-content-model-dom';\n\n// Regex matching Uri scheme\nconst URI_REGEX = /^[a-zA-Z]+:/i;\n// Regex matching begin of email address\nconst MAILTO_REGEX = /^[\\w.%+-]+@/i;\n// Regex matching begin of ftp, i.e. ftp.microsoft.com\nconst FTP_REGEX = /^ftp\\./i;\n\n/**\n * Insert a hyperlink at cursor.\n * When there is a selection, hyperlink will be applied to the selection,\n * otherwise a hyperlink will be inserted to the cursor position.\n * @param editor Editor object\n * @param link Link address, can be http(s), mailto, notes, file, unc, ftp, news, telnet, gopher, wais.\n * When protocol is not specified, a best matched protocol will be predicted.\n * @param anchorTitle Optional alt text of the link, will be shown when hover on the link\n * @param displayText Optional display text for the link.\n * @param target Optional display target for the link (\"_blank\"|\"_self\"|\"_parent\"|\"_top\"|\"{framename}\")\n * If specified, the display text of link will be replaced with this text.\n * If not specified and there wasn't a link, the link url will be used as display text.\n */\nexport default function insertLink(\n editor: IStandaloneEditor,\n link: string,\n anchorTitle?: string,\n displayText?: string,\n target?: string\n) {\n editor.focus();\n\n const url = (checkXss(link) || '').trim();\n if (url) {\n const linkData = matchLink(url);\n const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);\n const links: ContentModelLink[] = [];\n let anchorNode: Node | undefined;\n\n editor.formatContentModel(\n (model, context) => {\n const segments = getSelectedSegments(model, false /*includingFormatHolder*/);\n const originalText = segments\n .map(x => (x.segmentType == 'Text' ? x.text : ''))\n .join('');\n const text = displayText || originalText || '';\n\n if (\n segments.some(x => x.segmentType != 'SelectionMarker') &&\n originalText == text\n ) {\n segments.forEach(x => {\n const link = createLink(\n linkUrl,\n anchorTitle,\n target,\n x.segmentType == 'Text'\n );\n addLink(x, link);\n if (x.link) {\n links.push(x.link);\n }\n });\n } else if (\n segments.every(x => x.segmentType == 'SelectionMarker') ||\n (!!text && text != originalText)\n ) {\n const segment = createText(text || (linkData ? linkData.originalUrl : url), {\n ...segments[0]?.format,\n ...editor.getPendingFormat(),\n });\n const doc = createContentModelDocument();\n const link = createLink(linkUrl, anchorTitle, target);\n\n addLink(segment, link);\n addSegment(doc, segment);\n\n if (segment.link) {\n links.push(segment.link);\n }\n\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n }\n\n adjustTrailingSpaceSelection(model);\n return segments.length > 0;\n },\n {\n changeSource: ChangeSource.CreateLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n apiName: 'insertLink',\n }\n );\n }\n}\n\nconst createLink = (\n url: string,\n anchorTitle?: string,\n target?: string,\n underline: boolean = true\n): ContentModelLink => {\n return {\n dataset: {},\n format: {\n href: url,\n anchorTitle,\n target,\n underline: underline,\n },\n };\n};\n\n// TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.\nfunction applyLinkPrefix(url: string): string {\n if (!url) {\n return url;\n }\n\n // Add link prefix per rule:\n // (a) if the url always starts with a URI scheme, leave it as it is\n // (b) if the url is an email address, xxx@... add mailto: prefix\n // (c) if the url starts with ftp., add ftp:// prefix\n // (d) rest, add http:// prefix\n let prefix = '';\n if (url.search(URI_REGEX) < 0) {\n if (url.search(MAILTO_REGEX) == 0) {\n prefix = 'mailto:';\n } else if (url.search(FTP_REGEX) == 0) {\n prefix = 'ftp://';\n } else {\n // fallback to http://\n prefix = 'http://';\n }\n }\n\n return prefix + url;\n}\n\n// TODO: This is copied from original code. However, ContentModel should be able to filter out malicious\n// attributes later, so no need to use HtmlSanitizer here\nfunction checkXss(link: string): string {\n const sanitizer = new HtmlSanitizer();\n const a = document.createElement('a');\n\n a.href = link || '';\n\n sanitizer.sanitize(a);\n // We use getAttribute because some browsers will try to make the href property a valid link.\n // This has unintended side effects when the link lacks a protocol.\n return a.getAttribute('href') || '';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";;;AAAA,sGAAqG;AACrG,6EAA6F;AAC7F,2DAA0D;AAE1D,2EAKqC;AAErC,4BAA4B;AAC5B,IAAM,SAAS,GAAG,cAAc,CAAC;AACjC,wCAAwC;AACxC,IAAM,YAAY,GAAG,cAAc,CAAC;AACpC,sDAAsD;AACtD,IAAM,SAAS,GAAG,SAAS,CAAC;AAE5B;;;;;;;;;;;;GAYG;AACH,SAAwB,UAAU,CAC9B,MAAyB,EACzB,IAAY,EACZ,WAAoB,EACpB,WAAoB,EACpB,MAAe;IAEf,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,GAAG,GAAG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rB;YACL,CAAC;YACD,aAAa,EAAE,cAAM,OAAA,YAAU,EAAV,CAAU;YAC/B,OAAO,EAAE,YAAY;SACxB,CACJ,CAAC;KACL;AACL,CAAC;AA9ED,6BA8EC;AAED,IAAM,UAAU,GAAG,UACf,GAAW,EACX,WAAoB,EACpB,MAAe,EACf,SAAyB;IAAzB,0BAAA,EAAA,gBAAyB;IAEzB,OAAO;QACH,OAAO,EAAE,EAAE;QACX,MAAM,EAAE;YACJ,IAAI,EAAE,GAAG;YACT,WAAW,aAAA;YACX,MAAM,QAAA;YACN,SAAS,EAAE,SAAS;SACvB;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,SAAS,eAAe,CAAC,GAAW;IAChC,IAAI,CAAC,GAAG,EAAE;QACN,OAAO,GAAG,CAAC;KACd;IAED,4BAA4B;IAC5B,oEAAoE;IACpE,iEAAiE;IACjE,qDAAqD;IACrD,+BAA+B;IAC/B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;QAC3B,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;YAC/B,MAAM,GAAG,SAAS,CAAC;SACtB;aAAM,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YACnC,MAAM,GAAG,QAAQ,CAAC;SACrB;aAAM;YACH,sBAAsB;YACtB,MAAM,GAAG,SAAS,CAAC;SACtB;KACJ;IAED,OAAO,MAAM,GAAG,GAAG,CAAC;AACxB,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { ChangeSource, getSelectedSegments, mergeModel } from 'roosterjs-content-model-core';\nimport { matchLink } from '../../modelApi/link/matchLink';\nimport type { ContentModelLink, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n addLink,\n addSegment,\n createContentModelDocument,\n createText,\n} from 'roosterjs-content-model-dom';\n\n// Regex matching Uri scheme\nconst URI_REGEX = /^[a-zA-Z]+:/i;\n// Regex matching begin of email address\nconst MAILTO_REGEX = /^[\\w.%+-]+@/i;\n// Regex matching begin of ftp, i.e. ftp.microsoft.com\nconst FTP_REGEX = /^ftp\\./i;\n\n/**\n * Insert a hyperlink at cursor.\n * When there is a selection, hyperlink will be applied to the selection,\n * otherwise a hyperlink will be inserted to the cursor position.\n * @param editor Editor object\n * @param link Link address, can be http(s), mailto, notes, file, unc, ftp, news, telnet, gopher, wais.\n * When protocol is not specified, a best matched protocol will be predicted.\n * @param anchorTitle Optional alt text of the link, will be shown when hover on the link\n * @param displayText Optional display text for the link.\n * @param target Optional display target for the link (\"_blank\"|\"_self\"|\"_parent\"|\"_top\"|\"{framename}\")\n * If specified, the display text of link will be replaced with this text.\n * If not specified and there wasn't a link, the link url will be used as display text.\n */\nexport default function insertLink(\n editor: IStandaloneEditor,\n link: string,\n anchorTitle?: string,\n displayText?: string,\n target?: string\n) {\n editor.focus();\n\n const url = (checkXss(link) || '').trim();\n if (url) {\n const linkData = matchLink(url);\n const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);\n const links: ContentModelLink[] = [];\n let anchorNode: Node | undefined;\n\n editor.formatContentModel(\n (model, context) => {\n const segments = getSelectedSegments(model, false /*includingFormatHolder*/);\n const originalText = segments\n .map(x => (x.segmentType == 'Text' ? x.text : ''))\n .join('');\n const text = displayText || originalText || '';\n\n if (\n segments.some(x => x.segmentType != 'SelectionMarker') &&\n originalText == text\n ) {\n segments.forEach(x => {\n const link = createLink(\n linkUrl,\n anchorTitle,\n target,\n x.segmentType == 'Text'\n );\n addLink(x, link);\n if (x.link) {\n links.push(x.link);\n }\n });\n } else if (\n segments.every(x => x.segmentType == 'SelectionMarker') ||\n (!!text && text != originalText)\n ) {\n const segment = createText(text || (linkData ? linkData.originalUrl : url), {\n ...segments[0]?.format,\n ...editor.getPendingFormat(),\n });\n const doc = createContentModelDocument();\n const link = createLink(linkUrl, anchorTitle, target);\n\n addLink(segment, link);\n addSegment(doc, segment);\n\n if (segment.link) {\n links.push(segment.link);\n }\n\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n }\n\n adjustTrailingSpaceSelection(model);\n return segments.length > 0;\n },\n {\n changeSource: ChangeSource.CreateLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n apiName: 'insertLink',\n }\n );\n }\n}\n\nconst createLink = (\n url: string,\n anchorTitle?: string,\n target?: string,\n underline: boolean = true\n): ContentModelLink => {\n return {\n dataset: {},\n format: {\n href: url,\n anchorTitle,\n target,\n underline: underline,\n },\n };\n};\n\nfunction applyLinkPrefix(url: string): string {\n if (!url) {\n return url;\n }\n\n // Add link prefix per rule:\n // (a) if the url always starts with a URI scheme, leave it as it is\n // (b) if the url is an email address, xxx@... add mailto: prefix\n // (c) if the url starts with ftp., add ftp:// prefix\n // (d) rest, add http:// prefix\n let prefix = '';\n if (url.search(URI_REGEX) < 0) {\n if (url.search(MAILTO_REGEX) == 0) {\n prefix = 'mailto:';\n } else if (url.search(FTP_REGEX) == 0) {\n prefix = 'ftp://';\n } else {\n // fallback to http://\n prefix = 'http://';\n }\n }\n\n return prefix + url;\n}\n\nfunction checkXss(link: string): string {\n return link.match(/s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : link;\n}\n"]}
|
|
@@ -30,7 +30,6 @@ function changeCapitalization(editor, capitalization, language) {
|
|
|
30
30
|
segment.text = wordArray.join(' ');
|
|
31
31
|
break;
|
|
32
32
|
case 'sentence':
|
|
33
|
-
// TODO: Add rules on punctuation for internationalization - TASK 104769
|
|
34
33
|
var punctuationMarks = '[\\.\\!\\?]';
|
|
35
34
|
// Find a match of a word character either:
|
|
36
35
|
// - At the beginning of a string with or without preceding whitespace, for
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeCapitalization.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/segment/changeCapitalization.ts"],"names":[],"mappings":";;AAAA,wFAAuF;AAGvF;;;;;;;GAOG;AACH,SAAwB,oBAAoB,CACxC,MAAyB,EACzB,cAAqE,EACrE,QAAiB;IAEjB,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EAAC,MAAM,EAAE,sBAAsB,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,OAAO;QACzE,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,MAAM,EAAE;YAChC,QAAQ,cAAc,EAAE;gBACpB,KAAK,WAAW;oBACZ,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;oBACxD,MAAM;gBAEV,KAAK,WAAW;oBACZ,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;oBACxD,MAAM;gBAEV,KAAK,YAAY;oBACb,IAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBAEtE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBACvC,SAAS,CAAC,CAAC,CAAC;4BACR,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC;gCAClD,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;qBAC7B;oBAED,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACnC,MAAM;gBAEV,KAAK,UAAU;oBACX,
|
|
1
|
+
{"version":3,"file":"changeCapitalization.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/segment/changeCapitalization.ts"],"names":[],"mappings":";;AAAA,wFAAuF;AAGvF;;;;;;;GAOG;AACH,SAAwB,oBAAoB,CACxC,MAAyB,EACzB,cAAqE,EACrE,QAAiB;IAEjB,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EAAC,MAAM,EAAE,sBAAsB,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,OAAO;QACzE,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,MAAM,EAAE;YAChC,QAAQ,cAAc,EAAE;gBACpB,KAAK,WAAW;oBACZ,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;oBACxD,MAAM;gBAEV,KAAK,WAAW;oBACZ,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;oBACxD,MAAM;gBAEV,KAAK,YAAY;oBACb,IAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBAEtE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBACvC,SAAS,CAAC,CAAC,CAAC;4BACR,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC;gCAClD,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;qBAC7B;oBAED,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACnC,MAAM;gBAEV,KAAK,UAAU;oBACX,IAAM,gBAAgB,GAAG,aAAa,CAAC;oBACvC,2CAA2C;oBAC3C,2EAA2E;oBAC3E,2EAA2E;oBAC3E,uEAAuE;oBACvE,sDAAsD;oBACtD,IAAM,KAAK,GAAG,IAAI,MAAM,CAAC,WAAW,GAAG,gBAAgB,GAAG,SAAS,EAAE,GAAG,CAAC,CAAC;oBAE1E,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI;yBACtB,iBAAiB,CAAC,QAAQ,CAAC;yBAC3B,OAAO,CAAC,KAAK,EAAE,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAjC,CAAiC,CAAC,CAAC;oBAChE,MAAM;aACb;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AA9CD,uCA8CC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Change the capitalization of text in the selection\n * @param editor The editor instance\n * @param capitalization The case option\n * @param language Optional parameter for language string that should comply to \"IETF BCP 47 Tags for\n * Identifying Languages\". For example: 'en' or 'en-US' for English, 'tr' for Turkish.\n * Default is the host environment’s current locale.\n */\nexport default function changeCapitalization(\n editor: IStandaloneEditor,\n capitalization: 'sentence' | 'lowerCase' | 'upperCase' | 'capitalize',\n language?: string\n) {\n editor.focus();\n\n formatSegmentWithContentModel(editor, 'changeCapitalization', (_, __, segment) => {\n if (segment?.segmentType == 'Text') {\n switch (capitalization) {\n case 'lowerCase':\n segment.text = segment.text.toLocaleLowerCase(language);\n break;\n\n case 'upperCase':\n segment.text = segment.text.toLocaleUpperCase(language);\n break;\n\n case 'capitalize':\n const wordArray = segment.text.toLocaleLowerCase(language).split(' ');\n\n for (let i = 0; i < wordArray.length; i++) {\n wordArray[i] =\n wordArray[i].charAt(0).toLocaleUpperCase(language) +\n wordArray[i].slice(1);\n }\n\n segment.text = wordArray.join(' ');\n break;\n\n case 'sentence':\n const punctuationMarks = '[\\\\.\\\\!\\\\?]';\n // Find a match of a word character either:\n // - At the beginning of a string with or without preceding whitespace, for\n // example: ' hello world' and 'hello world' strings would both match 'h'.\n // - Or preceded by a punctuation mark and at least one whitespace, for\n // example 'yes. hello world' would match 'y' and 'h'.\n const regex = new RegExp('^\\\\s*\\\\w|' + punctuationMarks + '\\\\s+\\\\w', 'g');\n\n segment.text = segment.text\n .toLocaleLowerCase(language)\n .replace(regex, match => match.toLocaleUpperCase(language));\n break;\n }\n }\n });\n}\n"]}
|
|
@@ -10,7 +10,6 @@ var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
|
10
10
|
function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, segmentHasStyleCallback, includingFormatHolder, afterFormatCallback) {
|
|
11
11
|
editor.formatContentModel(function (model, context) {
|
|
12
12
|
var segmentAndParagraphs = (0, roosterjs_content_model_core_1.getSelectedSegmentsAndParagraphs)(model, !!includingFormatHolder);
|
|
13
|
-
var pendingFormat = editor.getPendingFormat();
|
|
14
13
|
var isCollapsedSelection = segmentAndParagraphs.length == 1 &&
|
|
15
14
|
segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';
|
|
16
15
|
if (isCollapsedSelection) {
|
|
@@ -20,9 +19,7 @@ function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, seg
|
|
|
20
19
|
isCollapsedSelection = false;
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
|
-
var formatsAndSegments =
|
|
24
|
-
? [[pendingFormat, null, null]]
|
|
25
|
-
: segmentAndParagraphs.map(function (item) { return [item[0].format, item[0], item[1]]; });
|
|
22
|
+
var formatsAndSegments = segmentAndParagraphs.map(function (item) { return [item[0].format, item[0], item[1]]; });
|
|
26
23
|
var isTurningOff = segmentHasStyleCallback
|
|
27
24
|
? formatsAndSegments.every(function (_a) {
|
|
28
25
|
var _b = (0, tslib_1.__read)(_a, 3), format = _b[0], segment = _b[1], paragraph = _b[2];
|
|
@@ -34,10 +31,8 @@ function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, seg
|
|
|
34
31
|
return toggleStyleCallback(format, !isTurningOff, segment, paragraph);
|
|
35
32
|
});
|
|
36
33
|
afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model);
|
|
37
|
-
if (!pendingFormat && isCollapsedSelection) {
|
|
38
|
-
context.newPendingFormat = segmentAndParagraphs[0][0].format;
|
|
39
|
-
}
|
|
40
34
|
if (isCollapsedSelection) {
|
|
35
|
+
context.newPendingFormat = segmentAndParagraphs[0][0].format;
|
|
41
36
|
editor.focus();
|
|
42
37
|
return false;
|
|
43
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;AAAA,oFAAmF;AACnF,6EAAgF;AAQhF;;GAEG;AACH,SAAgB,6BAA6B,CACzC,MAAyB,EACzB,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAA2D;IAE3D,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,IAAA,+DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,CAC1B,CAAC;QACF,
|
|
1
|
+
{"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;AAAA,oFAAmF;AACnF,6EAAgF;AAQhF;;GAEG;AACH,SAAgB,6BAA6B,CACzC,MAAyB,EACzB,OAAe,EACf,mBAKS,EACT,uBA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CAAC,OAAO,CAAC,UAAC,EAA4B;gBAA5B,KAAA,0BAA4B,EAA3B,MAAM,QAAA,EAAE,OAAO,QAAA,EAAE,SAAS,QAAA;YACnD,OAAA,mBAAmB,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,CAAC;QAA9D,CAA8D,CACjE,CAAC;QAEF,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAG,KAAK,CAAC,CAAC;QAE7B,IAAI,oBAAoB,EAAE;YACtB,OAAO,CAAC,gBAAgB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;SAChB;aAAM;YACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;SACxC;IACL,CAAC,EACD;QACI,OAAO,SAAA;KACV,CACJ,CAAC;AACN,CAAC;AAtED,sEAsEC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentFormat,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n/**\n * @internal\n */\nexport function formatSegmentWithContentModel(\n editor: IStandaloneEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length == 1 &&\n segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';\n\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ContentModelSegment | null,\n ContentModelParagraph | null\n ][] = segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) =>\n toggleStyleCallback(format, !isTurningOff, segment, paragraph)\n );\n\n afterFormatCallback?.(model);\n\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n"]}
|
package/lib-amd/index.d.ts
CHANGED
|
@@ -40,3 +40,4 @@ export { default as adjustImageSelection } from './publicApi/image/adjustImageSe
|
|
|
40
40
|
export { default as setParagraphMargin } from './publicApi/block/setParagraphMargin';
|
|
41
41
|
export { default as toggleCode } from './publicApi/segment/toggleCode';
|
|
42
42
|
export { default as insertEntity } from './publicApi/entity/insertEntity';
|
|
43
|
+
export { setListType } from './modelApi/list/setListType';
|
package/lib-amd/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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/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"], 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, 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) {
|
|
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/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/list/setListType"], 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, 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, setListType_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
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.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.setListType = 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.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.default; } });
|
|
6
6
|
Object.defineProperty(exports, "formatTable", { enumerable: true, get: function () { return formatTable_1.default; } });
|
|
7
7
|
Object.defineProperty(exports, "setTableCellShade", { enumerable: true, get: function () { return setTableCellShade_1.default; } });
|
|
@@ -44,5 +44,6 @@ define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/tabl
|
|
|
44
44
|
Object.defineProperty(exports, "setParagraphMargin", { enumerable: true, get: function () { return setParagraphMargin_1.default; } });
|
|
45
45
|
Object.defineProperty(exports, "toggleCode", { enumerable: true, get: function () { return toggleCode_1.default; } });
|
|
46
46
|
Object.defineProperty(exports, "insertEntity", { enumerable: true, get: function () { return insertEntity_1.default; } });
|
|
47
|
+
Object.defineProperty(exports, "setListType", { enumerable: true, get: function () { return setListType_1.setListType; } });
|
|
47
48
|
});
|
|
48
49
|
//# sourceMappingURL=index.js.map
|
package/lib-amd/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,OAAO,OAAe;IACtB,0GAAA,OAAO,OAAe;IACtB,sHAAA,OAAO,OAAqB;IAC5B,sGAAA,OAAO,OAAa;IACpB,gIAAA,OAAO,OAA0B;IACjC,4GAAA,OAAO,OAAgB;IACvB,kHAAA,OAAO,OAAmB;IAC1B,wGAAA,OAAO,OAAc;IACrB,4GAAA,OAAO,OAAgB;IACvB,kHAAA,OAAO,OAAmB;IAC1B,0HAAA,OAAO,OAAuB;IAC9B,kHAAA,OAAO,OAAmB;IAC1B,sHAAA,OAAO,OAAqB;IAC5B,wHAAA,OAAO,OAAsB;IAC7B,0GAAA,OAAO,OAAe;IACtB,0GAAA,OAAO,OAAe;IACtB,4GAAA,OAAO,OAAgB;IACvB,gHAAA,OAAO,OAAkB;IACzB,wHAAA,OAAO,OAAsB;IAC7B,4HAAA,OAAO,OAAwB;IAC/B,0GAAA,OAAO,OAAe;IACtB,4GAAA,OAAO,OAAgB;IACvB,wHAAA,OAAO,OAAsB;IAC7B,gHAAA,OAAO,OAAkB;IACzB,4GAAA,OAAO,OAAgB;IACvB,4GAAA,OAAO,OAAgB;IACvB,kHAAA,OAAO,OAAmB;IAC1B,oHAAA,OAAO,OAAoB;IAC3B,wGAAA,OAAO,OAAc;IACrB,gHAAA,OAAO,OAAkB;IACzB,sHAAA,OAAO,OAAqB;IAC5B,0GAAA,OAAO,OAAe;IACtB,gHAAA,OAAO,OAAkB;IACzB,0GAAA,OAAO,OAAe;IACtB,wGAAA,OAAO,OAAc;IACrB,wGAAA,OAAO,OAAc;IACrB,0HAAA,OAAO,OAAuB;IAC9B,kHAAA,OAAO,OAAmB;IAC1B,4HAAA,OAAO,OAAwB;IAC/B,wHAAA,OAAO,OAAsB;IAC7B,wGAAA,OAAO,OAAc;IACrB,4GAAA,OAAO,OAAgB","sourcesContent":["export { default as insertTable } from './publicApi/table/insertTable';\nexport { default as formatTable } from './publicApi/table/formatTable';\nexport { default as setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { default as editTable } from './publicApi/table/editTable';\nexport { default as applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { default as toggleBullet } from './publicApi/list/toggleBullet';\nexport { default as toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { default as toggleBold } from './publicApi/segment/toggleBold';\nexport { default as toggleItalic } from './publicApi/segment/toggleItalic';\nexport { default as toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { default as toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { default as toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { default as toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { default as setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { default as setFontName } from './publicApi/segment/setFontName';\nexport { default as setFontSize } from './publicApi/segment/setFontSize';\nexport { default as setTextColor } from './publicApi/segment/setTextColor';\nexport { default as changeFontSize } from './publicApi/segment/changeFontSize';\nexport { default as applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { default as changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { default as insertImage } from './publicApi/image/insertImage';\nexport { default as setListStyle } from './publicApi/list/setListStyle';\nexport { default as setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { default as setIndentation } from './publicApi/block/setIndentation';\nexport { default as setAlignment } from './publicApi/block/setAlignment';\nexport { default as setDirection } from './publicApi/block/setDirection';\nexport { default as setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { default as toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { default as setSpacing } from './publicApi/block/setSpacing';\nexport { default as setImageBorder } from './publicApi/image/setImageBorder';\nexport { default as setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { default as changeImage } from './publicApi/image/changeImage';\nexport { default as getFormatState } from './publicApi/format/getFormatState';\nexport { default as clearFormat } from './publicApi/format/clearFormat';\nexport { default as insertLink } from './publicApi/link/insertLink';\nexport { default as removeLink } from './publicApi/link/removeLink';\nexport { default as adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { default as setImageAltText } from './publicApi/image/setImageAltText';\nexport { default as adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { default as setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { default as toggleCode } from './publicApi/segment/toggleCode';\nexport { default as insertEntity } from './publicApi/entity/insertEntity';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,OAAO,OAAe;IACtB,0GAAA,OAAO,OAAe;IACtB,sHAAA,OAAO,OAAqB;IAC5B,sGAAA,OAAO,OAAa;IACpB,gIAAA,OAAO,OAA0B;IACjC,4GAAA,OAAO,OAAgB;IACvB,kHAAA,OAAO,OAAmB;IAC1B,wGAAA,OAAO,OAAc;IACrB,4GAAA,OAAO,OAAgB;IACvB,kHAAA,OAAO,OAAmB;IAC1B,0HAAA,OAAO,OAAuB;IAC9B,kHAAA,OAAO,OAAmB;IAC1B,sHAAA,OAAO,OAAqB;IAC5B,wHAAA,OAAO,OAAsB;IAC7B,0GAAA,OAAO,OAAe;IACtB,0GAAA,OAAO,OAAe;IACtB,4GAAA,OAAO,OAAgB;IACvB,gHAAA,OAAO,OAAkB;IACzB,wHAAA,OAAO,OAAsB;IAC7B,4HAAA,OAAO,OAAwB;IAC/B,0GAAA,OAAO,OAAe;IACtB,4GAAA,OAAO,OAAgB;IACvB,wHAAA,OAAO,OAAsB;IAC7B,gHAAA,OAAO,OAAkB;IACzB,4GAAA,OAAO,OAAgB;IACvB,4GAAA,OAAO,OAAgB;IACvB,kHAAA,OAAO,OAAmB;IAC1B,oHAAA,OAAO,OAAoB;IAC3B,wGAAA,OAAO,OAAc;IACrB,gHAAA,OAAO,OAAkB;IACzB,sHAAA,OAAO,OAAqB;IAC5B,0GAAA,OAAO,OAAe;IACtB,gHAAA,OAAO,OAAkB;IACzB,0GAAA,OAAO,OAAe;IACtB,wGAAA,OAAO,OAAc;IACrB,wGAAA,OAAO,OAAc;IACrB,0HAAA,OAAO,OAAuB;IAC9B,kHAAA,OAAO,OAAmB;IAC1B,4HAAA,OAAO,OAAwB;IAC/B,wHAAA,OAAO,OAAsB;IAC7B,wGAAA,OAAO,OAAc;IACrB,4GAAA,OAAO,OAAgB;IACvB,0GAAA,WAAW,OAAA","sourcesContent":["export { default as insertTable } from './publicApi/table/insertTable';\nexport { default as formatTable } from './publicApi/table/formatTable';\nexport { default as setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { default as editTable } from './publicApi/table/editTable';\nexport { default as applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { default as toggleBullet } from './publicApi/list/toggleBullet';\nexport { default as toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { default as toggleBold } from './publicApi/segment/toggleBold';\nexport { default as toggleItalic } from './publicApi/segment/toggleItalic';\nexport { default as toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { default as toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { default as toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { default as toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { default as setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { default as setFontName } from './publicApi/segment/setFontName';\nexport { default as setFontSize } from './publicApi/segment/setFontSize';\nexport { default as setTextColor } from './publicApi/segment/setTextColor';\nexport { default as changeFontSize } from './publicApi/segment/changeFontSize';\nexport { default as applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { default as changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { default as insertImage } from './publicApi/image/insertImage';\nexport { default as setListStyle } from './publicApi/list/setListStyle';\nexport { default as setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { default as setIndentation } from './publicApi/block/setIndentation';\nexport { default as setAlignment } from './publicApi/block/setAlignment';\nexport { default as setDirection } from './publicApi/block/setDirection';\nexport { default as setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { default as toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { default as setSpacing } from './publicApi/block/setSpacing';\nexport { default as setImageBorder } from './publicApi/image/setImageBorder';\nexport { default as setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { default as changeImage } from './publicApi/image/changeImage';\nexport { default as getFormatState } from './publicApi/format/getFormatState';\nexport { default as clearFormat } from './publicApi/format/clearFormat';\nexport { default as insertLink } from './publicApi/link/insertLink';\nexport { default as removeLink } from './publicApi/link/removeLink';\nexport { default as adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { default as setImageAltText } from './publicApi/image/setImageAltText';\nexport { default as adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { default as setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { default as toggleCode } from './publicApi/segment/toggleCode';\nexport { default as insertEntity } from './publicApi/entity/insertEntity';\nexport { setListType } from './modelApi/list/setListType';\n"]}
|
|
@@ -31,7 +31,6 @@ define(["require", "exports", "../list/findListItemsInSameThread", "roosterjs-co
|
|
|
31
31
|
if (wasRtl != isRtl) {
|
|
32
32
|
format.direction = direction;
|
|
33
33
|
// Adjust margin when change direction
|
|
34
|
-
// TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here
|
|
35
34
|
var marginLeft = format.marginLeft;
|
|
36
35
|
var paddingLeft = format.paddingLeft;
|
|
37
36
|
setProperty(format, 'marginLeft', format.marginRight);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":";;;;IAiBA;;OAEG;IACH,SAAgB,iBAAiB,CAAC,KAA2B,EAAE,SAAwB;QACnF,IAAM,0BAA0B,GAAG,IAAA,mDAAoB,EACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;gBAAP,KAAK,WAAA;YACvC,IAAI,IAAA,iDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAM,KAAK,GAAG,IAAA,qDAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAEtD,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;oBACd,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;wBACrB,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;oBACvC,CAAC,CAAC,CAAC;oBAEH,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,EAA7C,CAA6C,CAAC,CAAC;gBAChF,CAAC,CAAC,CAAC;aACN;iBAAM,IAAI,KAAK,EAAE;gBACd,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;aACxD;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,0BAA0B,CAAC,MAAM,GAAG,CAAC,CAAC;IACjD,CAAC;IAxBD,8CAwBC;IAED,SAAS,oBAAoB,CACzB,MAA+B,EAC/B,SAAwB,EACxB,KAAyB;QAEzB,IAAM,MAAM,GAAG,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC;QACzC,IAAM,KAAK,GAAG,SAAS,IAAI,KAAK,CAAC;QAEjC,IAAI,MAAM,IAAI,KAAK,EAAE;YACjB,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;YAE7B,sCAAsC;YACtC,
|
|
1
|
+
{"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":";;;;IAiBA;;OAEG;IACH,SAAgB,iBAAiB,CAAC,KAA2B,EAAE,SAAwB;QACnF,IAAM,0BAA0B,GAAG,IAAA,mDAAoB,EACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;gBAAP,KAAK,WAAA;YACvC,IAAI,IAAA,iDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAM,KAAK,GAAG,IAAA,qDAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAEtD,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;oBACd,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;wBACrB,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;oBACvC,CAAC,CAAC,CAAC;oBAEH,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,EAA7C,CAA6C,CAAC,CAAC;gBAChF,CAAC,CAAC,CAAC;aACN;iBAAM,IAAI,KAAK,EAAE;gBAC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AE,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;gCAChE,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;6BAC5D;4BACD,OAAO,QAAQ,CAAC;wBACpB,CAAC,CAAC,CAAC;oBACP,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;gBAEH,wBAAwB;gBACxB,IAAA,+CAAgB,EAAC,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;aAC/E;SACJ;IACL,CAAC;IAED,SAAS,WAAW,CAChB,MAAmD,EACnD,GAAwD,EACxD,KAAyB;QAEzB,IAAI,KAAK,EAAE;YACP,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SACvB;aAAM;YACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;SACtB;IACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport {\n applyTableFormat,\n getOperationalBlocks,\n isBlockGroupOfType,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n BorderFormat,\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelDocument,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setModelDirection(model: ContentModelDocument, direction: 'ltr' | 'rtl') {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(item => {\n item.levels.forEach(level => {\n level.format.direction = direction;\n });\n\n item.blocks.forEach(block => internalSetDirection(block.format, direction));\n });\n } else if (block) {\n internalSetDirection(block.format, direction, block);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(\n format: ContentModelBlockFormat,\n direction: 'ltr' | 'rtl',\n block?: ContentModelBlock\n) {\n const wasRtl = format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n format.direction = direction;\n\n // Adjust margin when change direction\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n\n // If whole Table direction changed, flip cell side borders\n if (block && block.blockType == 'Table') {\n block.rows.forEach(row => {\n row.cells.forEach(cell => {\n // Optimise by skipping cells with unchanged borders\n updateTableCellMetadata(cell, metadata => {\n if (metadata?.borderOverride) {\n const storeBorderLeft = cell.format.borderLeft;\n setProperty(cell.format, 'borderLeft', cell.format.borderRight);\n setProperty(cell.format, 'borderRight', storeBorderLeft);\n }\n return metadata;\n });\n });\n });\n\n // Apply changed borders\n applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);\n }\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat & BorderFormat,\n key: keyof (MarginFormat & PaddingFormat & BorderFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n"]}
|
|
@@ -2,4 +2,4 @@ import type { ContentModelDocument, ContentModelFormatContainerFormat } from 'ro
|
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
|
-
export declare function toggleModelBlockQuote(model: ContentModelDocument,
|
|
5
|
+
export declare function toggleModelBlockQuote(model: ContentModelDocument, formatLtr: ContentModelFormatContainerFormat, formatRtl: ContentModelFormatContainerFormat): boolean;
|