roosterjs-content-model-dom 0.10.0 → 0.11.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/domToModel/context/createDomToModelContext.d.ts +3 -1
- package/lib/domToModel/context/createDomToModelContext.js +7 -36
- package/lib/domToModel/context/createDomToModelContext.js.map +1 -1
- package/lib/domToModel/domToContentModel.d.ts +4 -2
- package/lib/domToModel/domToContentModel.js +4 -13
- package/lib/domToModel/domToContentModel.js.map +1 -1
- package/lib/domToModel/processors/childProcessor.js +3 -2
- package/lib/domToModel/processors/childProcessor.js.map +1 -1
- package/lib/domToModel/processors/headingProcessor.js +7 -0
- package/lib/domToModel/processors/headingProcessor.js.map +1 -1
- package/lib/domToModel/processors/imageProcessor.js +2 -1
- package/lib/domToModel/processors/imageProcessor.js.map +1 -1
- package/lib/domToModel/processors/tableProcessor.js +14 -7
- package/lib/domToModel/processors/tableProcessor.js.map +1 -1
- package/lib/domToModel/processors/textProcessor.js +1 -1
- package/lib/domToModel/processors/textProcessor.js.map +1 -1
- package/lib/domToModel/utils/getRegularSelectionOffsets.js +4 -7
- package/lib/domToModel/utils/getRegularSelectionOffsets.js.map +1 -1
- package/lib-amd/domToModel/context/createDomToModelContext.d.ts +3 -1
- package/lib-amd/domToModel/context/createDomToModelContext.js +7 -36
- package/lib-amd/domToModel/context/createDomToModelContext.js.map +1 -1
- package/lib-amd/domToModel/domToContentModel.d.ts +4 -2
- package/lib-amd/domToModel/domToContentModel.js +5 -10
- package/lib-amd/domToModel/domToContentModel.js.map +1 -1
- package/lib-amd/domToModel/processors/childProcessor.js +3 -2
- package/lib-amd/domToModel/processors/childProcessor.js.map +1 -1
- package/lib-amd/domToModel/processors/headingProcessor.js +7 -1
- package/lib-amd/domToModel/processors/headingProcessor.js.map +1 -1
- package/lib-amd/domToModel/processors/imageProcessor.js +2 -1
- package/lib-amd/domToModel/processors/imageProcessor.js.map +1 -1
- package/lib-amd/domToModel/processors/tableProcessor.js +14 -7
- package/lib-amd/domToModel/processors/tableProcessor.js.map +1 -1
- package/lib-amd/domToModel/processors/textProcessor.js +1 -1
- package/lib-amd/domToModel/processors/textProcessor.js.map +1 -1
- package/lib-amd/domToModel/utils/getRegularSelectionOffsets.js +4 -7
- package/lib-amd/domToModel/utils/getRegularSelectionOffsets.js.map +1 -1
- package/lib-mjs/domToModel/context/createDomToModelContext.d.ts +3 -1
- package/lib-mjs/domToModel/context/createDomToModelContext.js +7 -36
- package/lib-mjs/domToModel/context/createDomToModelContext.js.map +1 -1
- package/lib-mjs/domToModel/domToContentModel.d.ts +4 -2
- package/lib-mjs/domToModel/domToContentModel.js +4 -13
- package/lib-mjs/domToModel/domToContentModel.js.map +1 -1
- package/lib-mjs/domToModel/processors/childProcessor.js +3 -2
- package/lib-mjs/domToModel/processors/childProcessor.js.map +1 -1
- package/lib-mjs/domToModel/processors/headingProcessor.js +7 -0
- package/lib-mjs/domToModel/processors/headingProcessor.js.map +1 -1
- package/lib-mjs/domToModel/processors/imageProcessor.js +2 -1
- package/lib-mjs/domToModel/processors/imageProcessor.js.map +1 -1
- package/lib-mjs/domToModel/processors/tableProcessor.js +14 -7
- package/lib-mjs/domToModel/processors/tableProcessor.js.map +1 -1
- package/lib-mjs/domToModel/processors/textProcessor.js +1 -1
- package/lib-mjs/domToModel/processors/textProcessor.js.map +1 -1
- package/lib-mjs/domToModel/utils/getRegularSelectionOffsets.js +4 -7
- package/lib-mjs/domToModel/utils/getRegularSelectionOffsets.js.map +1 -1
- package/package.json +4 -4
- package/lib/formatHandlers/root/rootDirectionFormatHandler.d.ts +0 -6
- package/lib/formatHandlers/root/rootDirectionFormatHandler.js +0 -17
- package/lib/formatHandlers/root/rootDirectionFormatHandler.js.map +0 -1
- package/lib/formatHandlers/root/zoomScaleFormatHandler.d.ts +0 -6
- package/lib/formatHandlers/root/zoomScaleFormatHandler.js +0 -18
- package/lib/formatHandlers/root/zoomScaleFormatHandler.js.map +0 -1
- package/lib-amd/formatHandlers/root/rootDirectionFormatHandler.d.ts +0 -6
- package/lib-amd/formatHandlers/root/rootDirectionFormatHandler.js +0 -19
- package/lib-amd/formatHandlers/root/rootDirectionFormatHandler.js.map +0 -1
- package/lib-amd/formatHandlers/root/zoomScaleFormatHandler.d.ts +0 -6
- package/lib-amd/formatHandlers/root/zoomScaleFormatHandler.js +0 -20
- package/lib-amd/formatHandlers/root/zoomScaleFormatHandler.js.map +0 -1
- package/lib-mjs/formatHandlers/root/rootDirectionFormatHandler.d.ts +0 -6
- package/lib-mjs/formatHandlers/root/rootDirectionFormatHandler.js +0 -14
- package/lib-mjs/formatHandlers/root/rootDirectionFormatHandler.js.map +0 -1
- package/lib-mjs/formatHandlers/root/zoomScaleFormatHandler.d.ts +0 -6
- package/lib-mjs/formatHandlers/root/zoomScaleFormatHandler.js +0 -15
- package/lib-mjs/formatHandlers/root/zoomScaleFormatHandler.js.map +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DomToModelContext, DomToModelOption, EditorContext } from 'roosterjs-content-model-types';
|
|
2
|
+
import { SelectionRangeEx } from 'roosterjs-editor-types';
|
|
2
3
|
/**
|
|
3
4
|
* Create context object form DOM to Content Model conversion
|
|
4
5
|
* @param editorContext Context of editor
|
|
5
6
|
* @param options Options for this context
|
|
7
|
+
* @param selection Selection that already exists in content
|
|
6
8
|
*/
|
|
7
|
-
export declare function createDomToModelContext(editorContext?: EditorContext, options?: DomToModelOption): DomToModelContext;
|
|
9
|
+
export declare function createDomToModelContext(editorContext?: EditorContext, options?: DomToModelOption, selection?: SelectionRangeEx): DomToModelContext;
|
|
@@ -9,9 +9,10 @@ var defaultStyles_1 = require("../../formatHandlers/utils/defaultStyles");
|
|
|
9
9
|
* Create context object form DOM to Content Model conversion
|
|
10
10
|
* @param editorContext Context of editor
|
|
11
11
|
* @param options Options for this context
|
|
12
|
+
* @param selection Selection that already exists in content
|
|
12
13
|
*/
|
|
13
|
-
function createDomToModelContext(editorContext, options) {
|
|
14
|
-
var context = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, editorContext), { blockFormat: {}, segmentFormat: {},
|
|
14
|
+
function createDomToModelContext(editorContext, options, selection) {
|
|
15
|
+
var context = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, editorContext), { blockFormat: {}, segmentFormat: {}, isInSelection: false, listFormat: {
|
|
15
16
|
levels: [],
|
|
16
17
|
threadItemCounts: [],
|
|
17
18
|
}, link: {
|
|
@@ -23,41 +24,11 @@ function createDomToModelContext(editorContext, options) {
|
|
|
23
24
|
format: {},
|
|
24
25
|
tagName: '',
|
|
25
26
|
}, elementProcessors: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, defaultProcessors_1.defaultProcessorMap), ((options === null || options === void 0 ? void 0 : options.processorOverride) || {})), defaultStyles: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, defaultStyles_1.defaultStyleMap), ((options === null || options === void 0 ? void 0 : options.defaultStyleOverride) || {})), formatParsers: (0, defaultFormatHandlers_1.getFormatParsers)(options === null || options === void 0 ? void 0 : options.formatParserOverride, options === null || options === void 0 ? void 0 : options.additionalFormatParsers), defaultElementProcessors: defaultProcessors_1.defaultProcessorMap, defaultFormatParsers: defaultFormatHandlers_1.defaultFormatParsers, allowCacheElement: !(options === null || options === void 0 ? void 0 : options.disableCacheElement) });
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
switch (range === null || range === void 0 ? void 0 : range.type) {
|
|
29
|
-
case 0 /* Normal */:
|
|
30
|
-
var regularRange = range.ranges[0];
|
|
31
|
-
if (regularRange) {
|
|
32
|
-
selectionRoot = regularRange.commonAncestorContainer;
|
|
33
|
-
context.regularSelection = {
|
|
34
|
-
startContainer: regularRange.startContainer,
|
|
35
|
-
startOffset: regularRange.startOffset,
|
|
36
|
-
endContainer: regularRange.endContainer,
|
|
37
|
-
endOffset: regularRange.endOffset,
|
|
38
|
-
isSelectionCollapsed: regularRange.collapsed,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
break;
|
|
42
|
-
case 1 /* TableSelection */:
|
|
43
|
-
if (range.coordinates && range.table) {
|
|
44
|
-
selectionRoot = range.table;
|
|
45
|
-
context.tableSelection = {
|
|
46
|
-
table: range.table,
|
|
47
|
-
firstCell: (0, tslib_1.__assign)({}, range.coordinates.firstCell),
|
|
48
|
-
lastCell: (0, tslib_1.__assign)({}, range.coordinates.lastCell),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
case 2 /* ImageSelection */:
|
|
53
|
-
selectionRoot = range.image;
|
|
54
|
-
context.imageSelection = {
|
|
55
|
-
image: range.image,
|
|
56
|
-
};
|
|
57
|
-
break;
|
|
27
|
+
if (editorContext === null || editorContext === void 0 ? void 0 : editorContext.isRootRtl) {
|
|
28
|
+
context.blockFormat.direction = 'rtl';
|
|
58
29
|
}
|
|
59
|
-
if (
|
|
60
|
-
context.
|
|
30
|
+
if (selection) {
|
|
31
|
+
context.rangeEx = selection;
|
|
61
32
|
}
|
|
62
33
|
return context;
|
|
63
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDomToModelContext.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext.ts"],"names":[],"mappings":";;;;AAAA,oFAAoG;AACpG,yDAA0D;AAC1D,0EAA2E;AAI3E
|
|
1
|
+
{"version":3,"file":"createDomToModelContext.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext.ts"],"names":[],"mappings":";;;;AAAA,oFAAoG;AACpG,yDAA0D;AAC1D,0EAA2E;AAI3E;;;;;GAKG;AACH,SAAgB,uBAAuB,CACnC,aAA6B,EAC7B,OAA0B,EAC1B,SAA4B;IAE5B,IAAM,OAAO,mDACN,aAAa,KAEhB,WAAW,EAAE,EAAE,EACf,aAAa,EAAE,EAAE,EACjB,aAAa,EAAE,KAAK,EAEpB,UAAU,EAAE;YACR,MAAM,EAAE,EAAE;YACV,gBAAgB,EAAE,EAAE;SACvB,EACD,IAAI,EAAE;YACF,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,EAAE;SACd,EACD,IAAI,EAAE;YACF,MAAM,EAAE,EAAE;SACb,EACD,cAAc,EAAE;YACZ,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,EAAE;SACd,EAED,iBAAiB,kDACV,uCAAmB,GACnB,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,KAAI,EAAE,CAAC,GAGzC,aAAa,kDACN,+BAAe,GACf,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,KAAI,EAAE,CAAC,GAG5C,aAAa,EAAE,IAAA,wCAAgB,EAC3B,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAC7B,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,uBAAuB,CACnC,EAED,wBAAwB,EAAE,uCAAmB,EAC7C,oBAAoB,EAAE,4CAAoB,EAC1C,iBAAiB,EAAE,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,CAAA,GACnD,CAAC;IAEF,IAAI,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,SAAS,EAAE;QAC1B,OAAO,CAAC,WAAW,CAAC,SAAS,GAAG,KAAK,CAAC;KACzC;IAED,IAAI,SAAS,EAAE;QACX,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;KAC/B;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAzDD,0DAyDC","sourcesContent":["import { defaultFormatParsers, getFormatParsers } from '../../formatHandlers/defaultFormatHandlers';\nimport { defaultProcessorMap } from './defaultProcessors';\nimport { defaultStyleMap } from '../../formatHandlers/utils/defaultStyles';\nimport { DomToModelContext, DomToModelOption, EditorContext } from 'roosterjs-content-model-types';\nimport { SelectionRangeEx } from 'roosterjs-editor-types';\n\n/**\n * Create context object form DOM to Content Model conversion\n * @param editorContext Context of editor\n * @param options Options for this context\n * @param selection Selection that already exists in content\n */\nexport function createDomToModelContext(\n editorContext?: EditorContext,\n options?: DomToModelOption,\n selection?: SelectionRangeEx\n): DomToModelContext {\n const context: DomToModelContext = {\n ...editorContext,\n\n blockFormat: {},\n segmentFormat: {},\n isInSelection: false,\n\n listFormat: {\n levels: [],\n threadItemCounts: [],\n },\n link: {\n format: {},\n dataset: {},\n },\n code: {\n format: {},\n },\n blockDecorator: {\n format: {},\n tagName: '',\n },\n\n elementProcessors: {\n ...defaultProcessorMap,\n ...(options?.processorOverride || {}),\n },\n\n defaultStyles: {\n ...defaultStyleMap,\n ...(options?.defaultStyleOverride || {}),\n },\n\n formatParsers: getFormatParsers(\n options?.formatParserOverride,\n options?.additionalFormatParsers\n ),\n\n defaultElementProcessors: defaultProcessorMap,\n defaultFormatParsers: defaultFormatParsers,\n allowCacheElement: !options?.disableCacheElement,\n };\n\n if (editorContext?.isRootRtl) {\n context.blockFormat.direction = 'rtl';\n }\n\n if (selection) {\n context.rangeEx = selection;\n }\n\n return context;\n}\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { SelectionRangeEx } from 'roosterjs-editor-types';
|
|
1
2
|
import { ContentModelDocument, DomToModelOption, EditorContext } from 'roosterjs-content-model-types';
|
|
2
3
|
/**
|
|
3
4
|
* Create Content Model from DOM tree in this editor
|
|
4
5
|
* @param root Root element of DOM tree to create Content Model from
|
|
5
|
-
* @param editorContext Context of content model editor
|
|
6
6
|
* @param option The option to customize the behavior of DOM to Content Model conversion
|
|
7
|
+
* @param editorContext Context of content model editor
|
|
8
|
+
* @param selection Existing selection range in editor
|
|
7
9
|
* @returns A ContentModelDocument object that contains all the models created from the give root element
|
|
8
10
|
*/
|
|
9
|
-
export declare function domToContentModel(root: HTMLElement | DocumentFragment, editorContext?: EditorContext,
|
|
11
|
+
export declare function domToContentModel(root: HTMLElement | DocumentFragment, option?: DomToModelOption, editorContext?: EditorContext, selection?: SelectionRangeEx): ContentModelDocument;
|
|
@@ -3,27 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.domToContentModel = void 0;
|
|
4
4
|
var createContentModelDocument_1 = require("../modelApi/creators/createContentModelDocument");
|
|
5
5
|
var createDomToModelContext_1 = require("./context/createDomToModelContext");
|
|
6
|
-
var isNodeOfType_1 = require("../domUtils/isNodeOfType");
|
|
7
6
|
var normalizeContentModel_1 = require("../modelApi/common/normalizeContentModel");
|
|
8
|
-
var parseFormat_1 = require("./utils/parseFormat");
|
|
9
|
-
var rootDirectionFormatHandler_1 = require("../formatHandlers/root/rootDirectionFormatHandler");
|
|
10
|
-
var zoomScaleFormatHandler_1 = require("../formatHandlers/root/zoomScaleFormatHandler");
|
|
11
7
|
/**
|
|
12
8
|
* Create Content Model from DOM tree in this editor
|
|
13
9
|
* @param root Root element of DOM tree to create Content Model from
|
|
14
|
-
* @param editorContext Context of content model editor
|
|
15
10
|
* @param option The option to customize the behavior of DOM to Content Model conversion
|
|
11
|
+
* @param editorContext Context of content model editor
|
|
12
|
+
* @param selection Existing selection range in editor
|
|
16
13
|
* @returns A ContentModelDocument object that contains all the models created from the give root element
|
|
17
14
|
*/
|
|
18
|
-
function domToContentModel(root, editorContext,
|
|
15
|
+
function domToContentModel(root, option, editorContext, selection) {
|
|
19
16
|
var model = (0, createContentModelDocument_1.createContentModelDocument)(editorContext === null || editorContext === void 0 ? void 0 : editorContext.defaultFormat);
|
|
20
|
-
var context = (0, createDomToModelContext_1.createDomToModelContext)(editorContext, option);
|
|
21
|
-
if ((0, isNodeOfType_1.isNodeOfType)(root, 1 /* Element */)) {
|
|
22
|
-
// Need to calculate direction (ltr or rtl), use it as initial value
|
|
23
|
-
(0, parseFormat_1.parseFormat)(root, [rootDirectionFormatHandler_1.rootDirectionFormatHandler.parse], context.blockFormat, context);
|
|
24
|
-
// Need to calculate zoom scale value from root element, use this value to calculate sizes for elements
|
|
25
|
-
(0, parseFormat_1.parseFormat)(root, [zoomScaleFormatHandler_1.zoomScaleFormatHandler.parse], context.zoomScaleFormat, context);
|
|
26
|
-
}
|
|
17
|
+
var context = (0, createDomToModelContext_1.createDomToModelContext)(editorContext, option, selection);
|
|
27
18
|
context.elementProcessors.child(model, root, context);
|
|
28
19
|
(0, normalizeContentModel_1.normalizeContentModel)(model);
|
|
29
20
|
return model;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domToContentModel.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/domToContentModel.ts"],"names":[],"mappings":";;;AAAA,8FAA6F;AAC7F,6EAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"domToContentModel.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/domToContentModel.ts"],"names":[],"mappings":";;;AAAA,8FAA6F;AAC7F,6EAA4E;AAC5E,kFAAiF;AAQjF;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC7B,IAAoC,EACpC,MAAyB,EACzB,aAA6B,EAC7B,SAA4B;IAE5B,IAAM,KAAK,GAAG,IAAA,uDAA0B,EAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,aAAa,CAAC,CAAC;IACvE,IAAM,OAAO,GAAG,IAAA,iDAAuB,EAAC,aAAa,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAE1E,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAEtD,IAAA,6CAAqB,EAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC;AACjB,CAAC;AAdD,8CAcC","sourcesContent":["import { createContentModelDocument } from '../modelApi/creators/createContentModelDocument';\nimport { createDomToModelContext } from './context/createDomToModelContext';\nimport { normalizeContentModel } from '../modelApi/common/normalizeContentModel';\nimport { SelectionRangeEx } from 'roosterjs-editor-types';\nimport {\n ContentModelDocument,\n DomToModelOption,\n EditorContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create Content Model from DOM tree in this editor\n * @param root Root element of DOM tree to create Content Model from\n * @param option The option to customize the behavior of DOM to Content Model conversion\n * @param editorContext Context of content model editor\n * @param selection Existing selection range in editor\n * @returns A ContentModelDocument object that contains all the models created from the give root element\n */\nexport function domToContentModel(\n root: HTMLElement | DocumentFragment,\n option?: DomToModelOption,\n editorContext?: EditorContext,\n selection?: SelectionRangeEx\n): ContentModelDocument {\n const model = createContentModelDocument(editorContext?.defaultFormat);\n const context = createDomToModelContext(editorContext, option, selection);\n\n context.elementProcessors.child(model, root, context);\n\n normalizeContentModel(model);\n\n return model;\n}\n"]}
|
|
@@ -47,12 +47,13 @@ exports.processChildNode = processChildNode;
|
|
|
47
47
|
* @param nodeEndOffset End offset of current regular selection
|
|
48
48
|
*/
|
|
49
49
|
function handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset) {
|
|
50
|
+
var _a;
|
|
50
51
|
if (index == nodeStartOffset) {
|
|
51
52
|
context.isInSelection = true;
|
|
52
53
|
(0, addSelectionMarker_1.addSelectionMarker)(group, context);
|
|
53
54
|
}
|
|
54
|
-
if (index == nodeEndOffset) {
|
|
55
|
-
if (!context.
|
|
55
|
+
if (index == nodeEndOffset && ((_a = context.rangeEx) === null || _a === void 0 ? void 0 : _a.type) == 0 /* Normal */) {
|
|
56
|
+
if (!context.rangeEx.areAllCollapsed) {
|
|
56
57
|
(0, addSelectionMarker_1.addSelectionMarker)(group, context);
|
|
57
58
|
}
|
|
58
59
|
context.isInSelection = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"childProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/childProcessor.ts"],"names":[],"mappings":";;;;AAAA,kEAAiE;AACjE,kFAAiF;AACjF,4DAA2D;AAQ3D;;;;;GAKG;AACI,IAAM,cAAc,GAAiC,UACxD,KAA6B,EAC7B,MAAkB,EAClB,OAA0B;IAEpB,IAAA,KAAA,oBAAmC,IAAA,uDAA0B,EAAC,OAAO,EAAE,MAAM,CAAC,IAAA,EAA7E,eAAe,QAAA,EAAE,aAAa,QAA+C,CAAC;IACrF,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE;QAClE,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC;QAE9E,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAExC,KAAK,EAAE,CAAC;KACX;IAED,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC;AAClF,CAAC,CAAC;AAjBW,QAAA,cAAc,kBAiBzB;AAEF;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC5B,KAA6B,EAC7B,KAAW,EACX,OAA0B;IAE1B,IAAI,IAAA,2BAAY,EAAC,KAAK,kBAAmB,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,MAAM,EAAE;QACxE,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;KAC5D;SAAM,IAAI,IAAA,2BAAY,EAAC,KAAK,eAAgB,EAAE;QAC3C,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;KAC7D;AACL,CAAC;AAVD,4CAUC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAClC,KAAa,EACb,OAA0B,EAC1B,KAA6B,EAC7B,eAAuB,EACvB,aAAqB
|
|
1
|
+
{"version":3,"file":"childProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/childProcessor.ts"],"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B,KAA6B,EAC7B,eAAuB,EACvB,aAAqB;;IAErB,IAAI,KAAK,IAAI,eAAe,EAAE;QAC1B,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;QAE7B,IAAA,uCAAkB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KACtC;IAED,IAAI,KAAK,IAAI,aAAa,IAAI,CAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,IAAI,mBAA8B,EAAE;QAC/E,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,EAAE;YAClC,IAAA,uCAAkB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SACtC;QACD,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC;KACjC;AACL,CAAC;AAnBD,wDAmBC","sourcesContent":["import { addSelectionMarker } from '../utils/addSelectionMarker';\nimport { getRegularSelectionOffsets } from '../utils/getRegularSelectionOffsets';\nimport { isNodeOfType } from '../../domUtils/isNodeOfType';\nimport { NodeType, SelectionRangeTypes } from 'roosterjs-editor-types';\nimport {\n ContentModelBlockGroup,\n DomToModelContext,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for child elements\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n */\nexport const childProcessor: ElementProcessor<ParentNode> = (\n group: ContentModelBlockGroup,\n parent: ParentNode,\n context: DomToModelContext\n) => {\n const [nodeStartOffset, nodeEndOffset] = getRegularSelectionOffsets(context, parent);\n let index = 0;\n\n for (let child = parent.firstChild; child; child = child.nextSibling) {\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);\n\n processChildNode(group, child, context);\n\n index++;\n }\n\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);\n};\n\n/**\n * Helper function for processing child node\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n *\n */\nexport function processChildNode(\n group: ContentModelBlockGroup,\n child: Node,\n context: DomToModelContext\n) {\n if (isNodeOfType(child, NodeType.Element) && child.style.display != 'none') {\n context.elementProcessors.element(group, child, context);\n } else if (isNodeOfType(child, NodeType.Text)) {\n context.elementProcessors['#text'](group, child, context);\n }\n}\n\n/**\n * Helper function to handle regular (range based) selection when process child node\n * @param index Index of current child node in its parent\n * @param context DOM to Content Model context\n * @param group The parent block group\n * @param nodeStartOffset Start offset of current regular selection\n * @param nodeEndOffset End offset of current regular selection\n */\nexport function handleRegularSelection(\n index: number,\n context: DomToModelContext,\n group: ContentModelBlockGroup,\n nodeStartOffset: number,\n nodeEndOffset: number\n) {\n if (index == nodeStartOffset) {\n context.isInSelection = true;\n\n addSelectionMarker(group, context);\n }\n\n if (index == nodeEndOffset && context.rangeEx?.type == SelectionRangeTypes.Normal) {\n if (!context.rangeEx.areAllCollapsed) {\n addSelectionMarker(group, context);\n }\n context.isInSelection = false;\n }\n}\n"]}
|
|
@@ -5,6 +5,7 @@ var addBlock_1 = require("../../modelApi/common/addBlock");
|
|
|
5
5
|
var blockProcessor_1 = require("./blockProcessor");
|
|
6
6
|
var createParagraph_1 = require("../../modelApi/creators/createParagraph");
|
|
7
7
|
var createParagraphDecorator_1 = require("../../modelApi/creators/createParagraphDecorator");
|
|
8
|
+
var roosterjs_editor_dom_1 = require("roosterjs-editor-dom");
|
|
8
9
|
var parseFormat_1 = require("../utils/parseFormat");
|
|
9
10
|
var stackFormat_1 = require("../utils/stackFormat");
|
|
10
11
|
/**
|
|
@@ -14,6 +15,12 @@ var headingProcessor = function (group, element, context) {
|
|
|
14
15
|
(0, stackFormat_1.stackFormat)(context, { segment: 'shallowCloneForBlock', paragraph: 'shallowClone', blockDecorator: 'empty' }, function () {
|
|
15
16
|
var segmentFormat = {};
|
|
16
17
|
(0, parseFormat_1.parseFormat)(element, context.formatParsers.segmentOnBlock, segmentFormat, context);
|
|
18
|
+
// These formats are already declared on heading element, no need to keep them in context.
|
|
19
|
+
// And we should not duplicate them in context, either. Because when we want to turn off header,
|
|
20
|
+
// inner text should not keep those text format from header.
|
|
21
|
+
(0, roosterjs_editor_dom_1.getObjectKeys)(segmentFormat).forEach(function (key) {
|
|
22
|
+
delete context.segmentFormat[key];
|
|
23
|
+
});
|
|
17
24
|
context.blockDecorator = (0, createParagraphDecorator_1.createParagraphDecorator)(element.tagName, segmentFormat);
|
|
18
25
|
(0, blockProcessor_1.blockProcessor)(group, element, context);
|
|
19
26
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headingProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/headingProcessor.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAC1D,mDAAkD;AAElD,2EAA0E;AAC1E,6FAA4F;AAC5F,oDAAmD;AACnD,oDAAmD;AAEnD;;GAEG;AACI,IAAM,gBAAgB,GAAyC,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;IAC1F,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,OAAO,EAAE,EACvF;QACI,IAAM,aAAa,GAA8B,EAAE,CAAC;QAEpD,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QAEnF,OAAO,CAAC,cAAc,GAAG,IAAA,mDAAwB,EAAC,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAElF,IAAA,+BAAc,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC,CACJ,CAAC;IAEF,IAAA,mBAAQ,EAAC,KAAK,EAAE,IAAA,iCAAe,EAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAC/E,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"headingProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/headingProcessor.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAC1D,mDAAkD;AAElD,2EAA0E;AAC1E,6FAA4F;AAC5F,6DAAqD;AACrD,oDAAmD;AACnD,oDAAmD;AAEnD;;GAEG;AACI,IAAM,gBAAgB,GAAyC,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;IAC1F,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,OAAO,EAAE,EACvF;QACI,IAAM,aAAa,GAA8B,EAAE,CAAC;QAEpD,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QAEnF,0FAA0F;QAC1F,gGAAgG;QAChG,4DAA4D;QAC5D,IAAA,oCAAa,EAAC,aAAa,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YACpC,OAAO,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,cAAc,GAAG,IAAA,mDAAwB,EAAC,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAElF,IAAA,+BAAc,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC,CACJ,CAAC;IAEF,IAAA,mBAAQ,EAAC,KAAK,EAAE,IAAA,iCAAe,EAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAC/E,CAAC,CAAC;AAvBW,QAAA,gBAAgB,oBAuB3B","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { blockProcessor } from './blockProcessor';\nimport { ContentModelSegmentFormat, ElementProcessor } from 'roosterjs-content-model-types';\nimport { createParagraph } from '../../modelApi/creators/createParagraph';\nimport { createParagraphDecorator } from '../../modelApi/creators/createParagraphDecorator';\nimport { getObjectKeys } from 'roosterjs-editor-dom';\nimport { parseFormat } from '../utils/parseFormat';\nimport { stackFormat } from '../utils/stackFormat';\n\n/**\n * @internal\n */\nexport const headingProcessor: ElementProcessor<HTMLHeadingElement> = (group, element, context) => {\n stackFormat(\n context,\n { segment: 'shallowCloneForBlock', paragraph: 'shallowClone', blockDecorator: 'empty' },\n () => {\n const segmentFormat: ContentModelSegmentFormat = {};\n\n parseFormat(element, context.formatParsers.segmentOnBlock, segmentFormat, context);\n\n // These formats are already declared on heading element, no need to keep them in context.\n // And we should not duplicate them in context, either. Because when we want to turn off header,\n // inner text should not keep those text format from header.\n getObjectKeys(segmentFormat).forEach(key => {\n delete context.segmentFormat[key];\n });\n\n context.blockDecorator = createParagraphDecorator(element.tagName, segmentFormat);\n\n blockProcessor(group, element, context);\n }\n );\n\n addBlock(group, createParagraph(true /*isImplicit*/, context.blockFormat));\n};\n"]}
|
|
@@ -30,7 +30,8 @@ var imageProcessor = function (group, element, context) {
|
|
|
30
30
|
if (context.isInSelection) {
|
|
31
31
|
image.isSelected = true;
|
|
32
32
|
}
|
|
33
|
-
if (((_a = context.
|
|
33
|
+
if (((_a = context.rangeEx) === null || _a === void 0 ? void 0 : _a.type) == 2 /* ImageSelection */ &&
|
|
34
|
+
context.rangeEx.image == element) {
|
|
34
35
|
image.isSelectedAsImageSelection = true;
|
|
35
36
|
image.isSelected = true;
|
|
36
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/imageProcessor.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AACpE,+DAA8D;AAE9D,mEAAkE;AAClE,oDAAmD;
|
|
1
|
+
{"version":3,"file":"imageProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/imageProcessor.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AACpE,+DAA8D;AAE9D,mEAAkE;AACl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IAAI,OAAO,EAClC;YACE,KAAK,CAAC,0BAA0B,GAAG,IAAI,CAAC;YACxC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;SAC3B;QAED,IAAA,uBAAU,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAlCW,QAAA,cAAc,kBAkCzB","sourcesContent":["import { addDecorators } from '../../modelApi/common/addDecorators';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { ContentModelImageFormat, ElementProcessor } from 'roosterjs-content-model-types';\nimport { createImage } from '../../modelApi/creators/createImage';\nimport { parseFormat } from '../utils/parseFormat';\nimport { SelectionRangeTypes } from 'roosterjs-editor-types';\nimport { stackFormat } from '../utils/stackFormat';\n\n/**\n * @internal\n */\nexport const imageProcessor: ElementProcessor<HTMLImageElement> = (group, element, context) => {\n stackFormat(context, { segment: 'shallowClone' }, () => {\n const imageFormat: ContentModelImageFormat = context.segmentFormat;\n\n parseFormat(element, context.formatParsers.segment, imageFormat, context);\n parseFormat(element, context.formatParsers.image, imageFormat, context);\n parseFormat(element, context.formatParsers.block, context.blockFormat, context);\n\n const image = createImage(element.src, imageFormat);\n const alt = element.alt;\n const title = element.title;\n\n parseFormat(element, context.formatParsers.dataset, image.dataset, context);\n addDecorators(image, context);\n\n if (alt) {\n image.alt = alt;\n }\n if (title) {\n image.title = title;\n }\n if (context.isInSelection) {\n image.isSelected = true;\n }\n if (\n context.rangeEx?.type == SelectionRangeTypes.ImageSelection &&\n context.rangeEx.image == element\n ) {\n image.isSelectedAsImageSelection = true;\n image.isSelected = true;\n }\n\n addSegment(group, image);\n });\n};\n"]}
|
|
@@ -27,10 +27,17 @@ var stackFormat_1 = require("../utils/stackFormat");
|
|
|
27
27
|
*/
|
|
28
28
|
var tableProcessor = function (group, tableElement, context) {
|
|
29
29
|
(0, stackFormat_1.stackFormat)(context, { segment: 'shallowCloneForBlock', paragraph: 'shallowCloneForGroup' }, function () {
|
|
30
|
+
var _a;
|
|
30
31
|
(0, parseFormat_1.parseFormat)(tableElement, context.formatParsers.block, context.blockFormat, context);
|
|
31
32
|
var table = (0, createTable_1.createTable)(tableElement.rows.length, context.blockFormat);
|
|
32
|
-
var _a = context.
|
|
33
|
-
|
|
33
|
+
var tableSelection = ((_a = context.rangeEx) === null || _a === void 0 ? void 0 : _a.type) == 1 /* TableSelection */
|
|
34
|
+
? context.rangeEx
|
|
35
|
+
: null;
|
|
36
|
+
var selectedTable = tableSelection === null || tableSelection === void 0 ? void 0 : tableSelection.table;
|
|
37
|
+
var coordinates = tableSelection === null || tableSelection === void 0 ? void 0 : tableSelection.coordinates;
|
|
38
|
+
var hasTableSelection = selectedTable == tableElement &&
|
|
39
|
+
!!(coordinates === null || coordinates === void 0 ? void 0 : coordinates.firstCell) &&
|
|
40
|
+
!!(coordinates === null || coordinates === void 0 ? void 0 : coordinates.lastCell);
|
|
34
41
|
if (context.allowCacheElement) {
|
|
35
42
|
table.cachedElement = tableElement;
|
|
36
43
|
}
|
|
@@ -41,7 +48,7 @@ var tableProcessor = function (group, tableElement, context) {
|
|
|
41
48
|
(0, addBlock_1.addBlock)(group, table);
|
|
42
49
|
var columnPositions = [0];
|
|
43
50
|
var rowPositions = [0];
|
|
44
|
-
var zoomScale = context.
|
|
51
|
+
var zoomScale = context.zoomScale || 1;
|
|
45
52
|
var _loop_1 = function (row) {
|
|
46
53
|
var tr = tableElement.rows[row];
|
|
47
54
|
var tableRow = table.rows[row];
|
|
@@ -116,10 +123,10 @@ var tableProcessor = function (group, tableElement, context) {
|
|
|
116
123
|
var hasSelectionAfterCell = context.isInSelection;
|
|
117
124
|
if ((hasSelectionBeforeCell && hasSelectionAfterCell) ||
|
|
118
125
|
(hasTableSelection &&
|
|
119
|
-
row >= firstCell.y &&
|
|
120
|
-
row <= lastCell.y &&
|
|
121
|
-
targetCol >= firstCell.x &&
|
|
122
|
-
targetCol <= lastCell.x)) {
|
|
126
|
+
row >= coordinates.firstCell.y &&
|
|
127
|
+
row <= coordinates.lastCell.y &&
|
|
128
|
+
targetCol >= coordinates.firstCell.x &&
|
|
129
|
+
targetCol <= coordinates.lastCell.x)) {
|
|
123
130
|
cell.isSelected = true;
|
|
124
131
|
}
|
|
125
132
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tableProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/tableProcessor.ts"],"names":[],"mappings":";;;;AAAA,2DAA0D;AAC1D,mEAAkE;AAClE,2EAA0E;AAC1E,wEAAuE;AACvE,oDAAmD;AACnD,oDAAmD;AAOnD;;;;;;;;;;;;;;;;GAgBG;AACI,IAAM,cAAc,GAAuC,UAC9D,KAAK,EACL,YAAY,EACZ,OAAO;IAEP,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,sBAAsB,EAAE,EACtE;QACI,IAAA,yBAAW,EAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAErF,IAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QACnE,IAAA,KAAgD,OAAO,CAAC,cAAc,IAAI,EAAE,EAAnE,aAAa,WAAA,EAAE,SAAS,eAAA,EAAE,QAAQ,cAAiC,CAAC;QACnF,IAAM,iBAAiB,GAAG,aAAa,IAAI,YAAY,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,QAAQ,CAAC;QAErF,IAAI,OAAO,CAAC,iBAAiB,EAAE;YAC3B,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC;SACtC;QAED,IAAA,yBAAW,EAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9E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AS,CAAC,CAAC,CAAC,CAAC;YACnC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;SAC1B;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { createTable } from '../../modelApi/creators/createTable';\nimport { createTableCell } from '../../modelApi/creators/createTableCell';\nimport { getBoundingClientRect } from '../utils/getBoundingClientRect';\nimport { parseFormat } from '../utils/parseFormat';\nimport { stackFormat } from '../utils/stackFormat';\nimport {\n ContentModelTableCellFormat,\n DatasetFormat,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for table\n *\n * For Table with merged/splitted cells, HTML uses colSpan and rowSpan attributes to specify how it should be rendered.\n * To make it easier to edit a table, we will use a different way to describe table.\n *\n * 1. For a m * n table (m rows, n columns), we always create a m * n array for the cells.\n * 2. For a regular table cell, it is mapped to one item of this array\n * 3. For a merged/splitted table cell, it will has colSpan/rowSpan value. We also created TableCell model for those spanned\n * cells, and use \"spanLeft\" and \"spanAbove\" to mark its state\n * 4. When edit table, we always edit on this mapped m * n array because it always has an item for each cell\n * 5. When write back to DOM, we create TD/TH elements for those non-spanned cells, and mark its colSpan/rowSpan value according\n * its neighbour cell's spanLeft/spanAbove attribute\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n */\nexport const tableProcessor: ElementProcessor<HTMLTableElement> = (\n group,\n tableElement,\n context\n) => {\n stackFormat(\n context,\n { segment: 'shallowCloneForBlock', paragraph: 'shallowCloneForGroup' },\n () => {\n parseFormat(tableElement, context.formatParsers.block, context.blockFormat, context);\n\n const table = createTable(tableElement.rows.length, context.blockFormat);\n const { table: selectedTable, firstCell, lastCell } = context.tableSelection || {};\n const hasTableSelection = selectedTable == tableElement && !!firstCell && !!lastCell;\n\n if (context.allowCacheElement) {\n table.cachedElement = tableElement;\n }\n\n parseFormat(tableElement, context.formatParsers.table, table.format, context);\n parseFormat(tableElement, context.formatParsers.tableBorder, table.format, context);\n parseFormat(\n tableElement,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n parseFormat(tableElement, context.formatParsers.dataset, table.dataset, context);\n addBlock(group, table);\n\n const columnPositions: number[] = [0];\n const rowPositions: number[] = [0];\n const zoomScale = context.zoomScaleFormat.zoomScale || 1;\n\n for (let row = 0; row < tableElement.rows.length; row++) {\n const tr = tableElement.rows[row];\n const tableRow = table.rows[row];\n\n if (context.allowCacheElement) {\n tableRow.cachedElement = tr;\n }\n\n parseFormat(tr, context.formatParsers.tableRow, tableRow.format, context);\n\n stackFormat(context, { paragraph: 'shallowClone', segment: 'shallowClone' }, () => {\n const parent = tr.parentElement;\n const parentTag = parent?.tagName;\n\n if (\n parent &&\n (parentTag == 'TBODY' || parentTag == 'THEAD' || parentTag == 'TFOOT')\n ) {\n // If there is TBODY around TR, retrieve format from TBODY first, in case some format are declared there\n parseFormat(\n parent,\n context.formatParsers.block,\n context.blockFormat,\n context\n );\n parseFormat(\n parent,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n }\n\n parseFormat(tr, context.formatParsers.block, context.blockFormat, context);\n parseFormat(\n tr,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n\n for (\n let sourceCol = 0, targetCol = 0;\n sourceCol < tr.cells.length;\n sourceCol++\n ) {\n for (; tableRow.cells[targetCol]; targetCol++) {}\n\n const td = tr.cells[sourceCol];\n const hasSelectionBeforeCell = context.isInSelection;\n const colEnd = targetCol + td.colSpan;\n const rowEnd = row + td.rowSpan;\n const needCalcWidth = columnPositions[colEnd] === undefined;\n const needCalcHeight = rowPositions[rowEnd] === undefined;\n\n if (needCalcWidth || needCalcHeight) {\n const rect = getBoundingClientRect(td);\n\n if (rect.width > 0 || rect.height > 0) {\n if (needCalcWidth) {\n columnPositions[colEnd] =\n columnPositions[targetCol] + rect.width / zoomScale;\n }\n\n if (needCalcHeight) {\n rowPositions[rowEnd] =\n rowPositions[row] + rect.height / zoomScale;\n }\n }\n }\n\n stackFormat(\n context,\n { paragraph: 'shallowClone', segment: 'shallowClone' },\n () => {\n parseFormat(\n td,\n context.formatParsers.block,\n context.blockFormat,\n context\n );\n parseFormat(\n td,\n context.formatParsers.segmentOnTableCell,\n context.segmentFormat,\n context\n );\n\n const cellFormat: ContentModelTableCellFormat = {\n ...context.blockFormat,\n };\n const dataset: DatasetFormat = {};\n\n parseFormat(\n td,\n context.formatParsers.tableCell,\n cellFormat,\n context\n );\n parseFormat(\n td,\n context.formatParsers.tableBorder,\n cellFormat,\n context\n );\n parseFormat(td, context.formatParsers.dataset, dataset, context);\n\n for (\n let colSpan = 1;\n colSpan <= td.colSpan;\n colSpan++, targetCol++\n ) {\n for (let rowSpan = 1; rowSpan <= td.rowSpan; rowSpan++) {\n const hasTd = colSpan == 1 && rowSpan == 1;\n const cell = createTableCell(\n colSpan > 1,\n rowSpan > 1,\n td.tagName == 'TH',\n cellFormat\n );\n\n cell.dataset = { ...dataset };\n\n const spannedRow = table.rows[row + rowSpan - 1];\n\n if (spannedRow) {\n spannedRow.cells[targetCol] = cell;\n }\n\n if (hasTd) {\n if (context.allowCacheElement) {\n cell.cachedElement = td;\n }\n\n const { listParent, levels } = context.listFormat;\n\n context.listFormat.listParent = undefined;\n context.listFormat.levels = [];\n\n try {\n context.elementProcessors.child(cell, td, context);\n } finally {\n context.listFormat.listParent = listParent;\n context.listFormat.levels = levels;\n }\n }\n\n const hasSelectionAfterCell = context.isInSelection;\n\n if (\n (hasSelectionBeforeCell && hasSelectionAfterCell) ||\n (hasTableSelection &&\n row >= firstCell.y &&\n row <= lastCell.y &&\n targetCol >= firstCell.x &&\n targetCol <= lastCell.x)\n ) {\n cell.isSelected = true;\n }\n }\n }\n }\n );\n }\n });\n }\n\n table.widths = calcSizes(columnPositions);\n\n const heights = calcSizes(rowPositions);\n\n table.rows.forEach((row, i) => {\n if (heights[i] > 0) {\n row.height = heights[i];\n }\n });\n }\n );\n};\n\nfunction calcSizes(positions: number[]): number[] {\n let result: number[] = [];\n let lastPos = positions[positions.length - 1];\n\n for (let i = positions.length - 2; i >= 0; i--) {\n if (positions[i] === undefined) {\n result[i] = 0;\n } else {\n result[i] = lastPos - positions[i];\n lastPos = positions[i];\n }\n }\n\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tableProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/tableProcessor.ts"],"names":[],"mappings":";;;;AAAA,2DAA0D;AAC1D,mEAAkE;AAClE,2EAA0E;AAC1E,wEAAuE;AACvE,oDAAmD;AAEnD,oDAAmD;AAOnD;;;;;;;;;;;;;;;;GAgBG;AACI,IAAM,cAAc,GAAuC,UAC9D,KAAK,EACL,YAAY,EACZ,OAAO;IAEP,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,sBAAsB,EAAE,EACtE;;QACI,IAAA,yBAAW,EAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAErF,IAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,IAAM,cAAc,GAChB,CAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,IAAI,2BAAsC;YACvD,CAAC,CAAC,OAAO,CAAC,OAAO;YACjB,CAAC,CAAC,IAAI,CAAC;QACf,IAAM,aAAa,GAAG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK,CAAC;QAC5C,IAAM,WAAW,GAAG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,WAAW,CAAC;QAChD,IAAM,iBAAiB,GACnB,aAAa,IAAI,YAAY;YAC7B,CAAC,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,SAAS,CAAA;YACx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S,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE9C,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC5C,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;YAC5B,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;SACjB;aAAM;YACH,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACnC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;SAC1B;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { createTable } from '../../modelApi/creators/createTable';\nimport { createTableCell } from '../../modelApi/creators/createTableCell';\nimport { getBoundingClientRect } from '../utils/getBoundingClientRect';\nimport { parseFormat } from '../utils/parseFormat';\nimport { SelectionRangeTypes } from 'roosterjs-editor-types';\nimport { stackFormat } from '../utils/stackFormat';\nimport {\n ContentModelTableCellFormat,\n DatasetFormat,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for table\n *\n * For Table with merged/splitted cells, HTML uses colSpan and rowSpan attributes to specify how it should be rendered.\n * To make it easier to edit a table, we will use a different way to describe table.\n *\n * 1. For a m * n table (m rows, n columns), we always create a m * n array for the cells.\n * 2. For a regular table cell, it is mapped to one item of this array\n * 3. For a merged/splitted table cell, it will has colSpan/rowSpan value. We also created TableCell model for those spanned\n * cells, and use \"spanLeft\" and \"spanAbove\" to mark its state\n * 4. When edit table, we always edit on this mapped m * n array because it always has an item for each cell\n * 5. When write back to DOM, we create TD/TH elements for those non-spanned cells, and mark its colSpan/rowSpan value according\n * its neighbour cell's spanLeft/spanAbove attribute\n * @param group The parent block group\n * @param parent Parent DOM node to process\n * @param context DOM to Content Model context\n */\nexport const tableProcessor: ElementProcessor<HTMLTableElement> = (\n group,\n tableElement,\n context\n) => {\n stackFormat(\n context,\n { segment: 'shallowCloneForBlock', paragraph: 'shallowCloneForGroup' },\n () => {\n parseFormat(tableElement, context.formatParsers.block, context.blockFormat, context);\n\n const table = createTable(tableElement.rows.length, context.blockFormat);\n const tableSelection =\n context.rangeEx?.type == SelectionRangeTypes.TableSelection\n ? context.rangeEx\n : null;\n const selectedTable = tableSelection?.table;\n const coordinates = tableSelection?.coordinates;\n const hasTableSelection =\n selectedTable == tableElement &&\n !!coordinates?.firstCell &&\n !!coordinates?.lastCell;\n\n if (context.allowCacheElement) {\n table.cachedElement = tableElement;\n }\n\n parseFormat(tableElement, context.formatParsers.table, table.format, context);\n parseFormat(tableElement, context.formatParsers.tableBorder, table.format, context);\n parseFormat(\n tableElement,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n parseFormat(tableElement, context.formatParsers.dataset, table.dataset, context);\n addBlock(group, table);\n\n const columnPositions: number[] = [0];\n const rowPositions: number[] = [0];\n const zoomScale = context.zoomScale || 1;\n\n for (let row = 0; row < tableElement.rows.length; row++) {\n const tr = tableElement.rows[row];\n const tableRow = table.rows[row];\n\n if (context.allowCacheElement) {\n tableRow.cachedElement = tr;\n }\n\n parseFormat(tr, context.formatParsers.tableRow, tableRow.format, context);\n\n stackFormat(context, { paragraph: 'shallowClone', segment: 'shallowClone' }, () => {\n const parent = tr.parentElement;\n const parentTag = parent?.tagName;\n\n if (\n parent &&\n (parentTag == 'TBODY' || parentTag == 'THEAD' || parentTag == 'TFOOT')\n ) {\n // If there is TBODY around TR, retrieve format from TBODY first, in case some format are declared there\n parseFormat(\n parent,\n context.formatParsers.block,\n context.blockFormat,\n context\n );\n parseFormat(\n parent,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n }\n\n parseFormat(tr, context.formatParsers.block, context.blockFormat, context);\n parseFormat(\n tr,\n context.formatParsers.segmentOnBlock,\n context.segmentFormat,\n context\n );\n\n for (\n let sourceCol = 0, targetCol = 0;\n sourceCol < tr.cells.length;\n sourceCol++\n ) {\n for (; tableRow.cells[targetCol]; targetCol++) {}\n\n const td = tr.cells[sourceCol];\n const hasSelectionBeforeCell = context.isInSelection;\n const colEnd = targetCol + td.colSpan;\n const rowEnd = row + td.rowSpan;\n const needCalcWidth = columnPositions[colEnd] === undefined;\n const needCalcHeight = rowPositions[rowEnd] === undefined;\n\n if (needCalcWidth || needCalcHeight) {\n const rect = getBoundingClientRect(td);\n\n if (rect.width > 0 || rect.height > 0) {\n if (needCalcWidth) {\n columnPositions[colEnd] =\n columnPositions[targetCol] + rect.width / zoomScale;\n }\n\n if (needCalcHeight) {\n rowPositions[rowEnd] =\n rowPositions[row] + rect.height / zoomScale;\n }\n }\n }\n\n stackFormat(\n context,\n { paragraph: 'shallowClone', segment: 'shallowClone' },\n () => {\n parseFormat(\n td,\n context.formatParsers.block,\n context.blockFormat,\n context\n );\n parseFormat(\n td,\n context.formatParsers.segmentOnTableCell,\n context.segmentFormat,\n context\n );\n\n const cellFormat: ContentModelTableCellFormat = {\n ...context.blockFormat,\n };\n const dataset: DatasetFormat = {};\n\n parseFormat(\n td,\n context.formatParsers.tableCell,\n cellFormat,\n context\n );\n parseFormat(\n td,\n context.formatParsers.tableBorder,\n cellFormat,\n context\n );\n parseFormat(td, context.formatParsers.dataset, dataset, context);\n\n for (\n let colSpan = 1;\n colSpan <= td.colSpan;\n colSpan++, targetCol++\n ) {\n for (let rowSpan = 1; rowSpan <= td.rowSpan; rowSpan++) {\n const hasTd = colSpan == 1 && rowSpan == 1;\n const cell = createTableCell(\n colSpan > 1,\n rowSpan > 1,\n td.tagName == 'TH',\n cellFormat\n );\n\n cell.dataset = { ...dataset };\n\n const spannedRow = table.rows[row + rowSpan - 1];\n\n if (spannedRow) {\n spannedRow.cells[targetCol] = cell;\n }\n\n if (hasTd) {\n if (context.allowCacheElement) {\n cell.cachedElement = td;\n }\n\n const { listParent, levels } = context.listFormat;\n\n context.listFormat.listParent = undefined;\n context.listFormat.levels = [];\n\n try {\n context.elementProcessors.child(cell, td, context);\n } finally {\n context.listFormat.listParent = listParent;\n context.listFormat.levels = levels;\n }\n }\n\n const hasSelectionAfterCell = context.isInSelection;\n\n if (\n (hasSelectionBeforeCell && hasSelectionAfterCell) ||\n (hasTableSelection &&\n row >= coordinates.firstCell.y &&\n row <= coordinates.lastCell.y &&\n targetCol >= coordinates.firstCell.x &&\n targetCol <= coordinates.lastCell.x)\n ) {\n cell.isSelected = true;\n }\n }\n }\n }\n );\n }\n });\n }\n\n table.widths = calcSizes(columnPositions);\n\n const heights = calcSizes(rowPositions);\n\n table.rows.forEach((row, i) => {\n if (heights[i] > 0) {\n row.height = heights[i];\n }\n });\n }\n );\n};\n\nfunction calcSizes(positions: number[]): number[] {\n let result: number[] = [];\n let lastPos = positions[positions.length - 1];\n\n for (let i = positions.length - 2; i >= 0; i--) {\n if (positions[i] === undefined) {\n result[i] = 0;\n } else {\n result[i] = lastPos - positions[i];\n lastPos = positions[i];\n }\n }\n\n return result;\n}\n"]}
|
|
@@ -24,7 +24,7 @@ var textProcessor = function (group, textNode, context) {
|
|
|
24
24
|
}
|
|
25
25
|
if (txtEndOffset >= 0) {
|
|
26
26
|
addTextSegment(group, txt.substring(0, txtEndOffset), context);
|
|
27
|
-
if (!context.
|
|
27
|
+
if (context.rangeEx && !context.rangeEx.areAllCollapsed) {
|
|
28
28
|
(0, addSelectionMarker_1.addSelectionMarker)(group, context);
|
|
29
29
|
}
|
|
30
30
|
context.isInSelection = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/textProcessor.ts"],"names":[],"mappings":";;;;AAAA,qEAAoE;AACpE,+DAA8D;AAC9D,kEAAiE;AACjE,0DAAyD;
|
|
1
|
+
{"version":3,"file":"textProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-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AAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAC,UAAU,KAAI,EAAE,CAAC,IAAI,CAAC,EAC/E;YACE,IAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;YAE1D,IAAI,OAAO,CAAC,aAAa,EAAE;gBACvB,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC;aAC/B;YAED,IAAA,6BAAa,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAElC,IAAA,uBAAU,EAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;SACrD;KACJ;AACL,CAAC","sourcesContent":["import { addDecorators } from '../../modelApi/common/addDecorators';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { addSelectionMarker } from '../utils/addSelectionMarker';\nimport { areSameFormats } from '../utils/areSameFormats';\nimport { createText } from '../../modelApi/creators/createText';\nimport { getRegularSelectionOffsets } from '../utils/getRegularSelectionOffsets';\nimport { hasSpacesOnly } from '../../domUtils/stringUtil';\nimport {\n ContentModelBlockGroup,\n DomToModelContext,\n ElementProcessor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const textProcessor: ElementProcessor<Text> = (\n group: ContentModelBlockGroup,\n textNode: Text,\n context: DomToModelContext\n) => {\n let txt = textNode.nodeValue || '';\n let [txtStartOffset, txtEndOffset] = getRegularSelectionOffsets(context, textNode);\n\n if (txtStartOffset >= 0) {\n addTextSegment(group, txt.substring(0, txtStartOffset), context);\n context.isInSelection = true;\n\n addSelectionMarker(group, context);\n\n txt = txt.substring(txtStartOffset);\n txtEndOffset -= txtStartOffset;\n }\n\n if (txtEndOffset >= 0) {\n addTextSegment(group, txt.substring(0, txtEndOffset), context);\n\n if (context.rangeEx && !context.rangeEx.areAllCollapsed) {\n addSelectionMarker(group, context);\n }\n\n context.isInSelection = false;\n txt = txt.substring(txtEndOffset);\n }\n\n addTextSegment(group, txt, context);\n};\n\n// When we see these values of white-space style, need to preserve spaces and line-breaks and let browser handle it for us.\nconst WhiteSpaceValuesNeedToHandle = ['pre', 'pre-wrap', 'pre-line', 'break-spaces'];\n\nfunction addTextSegment(group: ContentModelBlockGroup, text: string, context: DomToModelContext) {\n if (text) {\n const lastBlock = group.blocks[group.blocks.length - 1];\n const paragraph = lastBlock?.blockType == 'Paragraph' ? lastBlock : null;\n const lastSegment = paragraph?.segments[paragraph.segments.length - 1];\n\n if (\n lastSegment?.segmentType == 'Text' &&\n !!lastSegment.isSelected == !!context.isInSelection &&\n areSameFormats(lastSegment.format, context.segmentFormat) &&\n areSameFormats(lastSegment.link || {}, context.link.format || {}) &&\n areSameFormats(lastSegment.code || {}, context.code.format || {})\n ) {\n lastSegment.text += text;\n } else if (\n !hasSpacesOnly(text) ||\n paragraph?.segments.length! > 0 ||\n WhiteSpaceValuesNeedToHandle.indexOf(paragraph?.format.whiteSpace || '') >= 0\n ) {\n const textModel = createText(text, context.segmentFormat);\n\n if (context.isInSelection) {\n textModel.isSelected = true;\n }\n\n addDecorators(textModel, context);\n\n addSegment(group, textModel, context.blockFormat);\n }\n }\n}\n"]}
|
|
@@ -9,13 +9,10 @@ exports.getRegularSelectionOffsets = void 0;
|
|
|
9
9
|
* @returns a tuple of start and end offsets. -1 means selection is not directly under the given node
|
|
10
10
|
*/
|
|
11
11
|
function getRegularSelectionOffsets(context, currentContainer) {
|
|
12
|
-
var _a
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var endOffset = ((_b = context.regularSelection) === null || _b === void 0 ? void 0 : _b.endContainer) == currentContainer
|
|
17
|
-
? context.regularSelection.endOffset
|
|
18
|
-
: -1;
|
|
12
|
+
var _a;
|
|
13
|
+
var range = ((_a = context.rangeEx) === null || _a === void 0 ? void 0 : _a.type) == 0 /* Normal */ ? context.rangeEx.ranges[0] : null;
|
|
14
|
+
var startOffset = (range === null || range === void 0 ? void 0 : range.startContainer) == currentContainer ? range.startOffset : -1;
|
|
15
|
+
var endOffset = (range === null || range === void 0 ? void 0 : range.endContainer) == currentContainer ? range.endOffset : -1;
|
|
19
16
|
return [startOffset, endOffset];
|
|
20
17
|
}
|
|
21
18
|
exports.getRegularSelectionOffsets = getRegularSelectionOffsets;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRegularSelectionOffsets.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/utils/getRegularSelectionOffsets.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getRegularSelectionOffsets.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/utils/getRegularSelectionOffsets.ts"],"names":[],"mappings":";;;AAGA;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACtC,OAA0B,EAC1B,gBAAsB;;IAEtB,IAAM,KAAK,GACP,CAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,IAAI,mBAA8B,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3F,IAAI,WAAW,GAAG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,KAAI,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrF,IAAI,SAAS,GAAG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,KAAI,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,SAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhF,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACpC,CAAC;AAXD,gEAWC","sourcesContent":["import { DomToModelContext } from 'roosterjs-content-model-types';\nimport { SelectionRangeTypes } from 'roosterjs-editor-types';\n\n/**\n * Get offset numbers of a regular (range based) selection.\n * If the selection start/end position is not in the given node, it will return -1 for the related value\n * @param context DOM to Content Model context used for retrieve the selection\n * @param currentContainer The container node to check\n * @returns a tuple of start and end offsets. -1 means selection is not directly under the given node\n */\nexport function getRegularSelectionOffsets(\n context: DomToModelContext,\n currentContainer: Node\n): [number, number] {\n const range =\n context.rangeEx?.type == SelectionRangeTypes.Normal ? context.rangeEx.ranges[0] : null;\n\n let startOffset = range?.startContainer == currentContainer ? range.startOffset : -1;\n let endOffset = range?.endContainer == currentContainer ? range.endOffset! : -1;\n\n return [startOffset, endOffset];\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DomToModelContext, DomToModelOption, EditorContext } from 'roosterjs-content-model-types';
|
|
2
|
+
import { SelectionRangeEx } from 'roosterjs-editor-types';
|
|
2
3
|
/**
|
|
3
4
|
* Create context object form DOM to Content Model conversion
|
|
4
5
|
* @param editorContext Context of editor
|
|
5
6
|
* @param options Options for this context
|
|
7
|
+
* @param selection Selection that already exists in content
|
|
6
8
|
*/
|
|
7
|
-
export declare function createDomToModelContext(editorContext?: EditorContext, options?: DomToModelOption): DomToModelContext;
|
|
9
|
+
export declare function createDomToModelContext(editorContext?: EditorContext, options?: DomToModelOption, selection?: SelectionRangeEx): DomToModelContext;
|
|
@@ -6,9 +6,10 @@ define(["require", "exports", "tslib", "../../formatHandlers/defaultFormatHandle
|
|
|
6
6
|
* Create context object form DOM to Content Model conversion
|
|
7
7
|
* @param editorContext Context of editor
|
|
8
8
|
* @param options Options for this context
|
|
9
|
+
* @param selection Selection that already exists in content
|
|
9
10
|
*/
|
|
10
|
-
function createDomToModelContext(editorContext, options) {
|
|
11
|
-
var context = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, editorContext), { blockFormat: {}, segmentFormat: {},
|
|
11
|
+
function createDomToModelContext(editorContext, options, selection) {
|
|
12
|
+
var context = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, editorContext), { blockFormat: {}, segmentFormat: {}, isInSelection: false, listFormat: {
|
|
12
13
|
levels: [],
|
|
13
14
|
threadItemCounts: [],
|
|
14
15
|
}, link: {
|
|
@@ -20,41 +21,11 @@ define(["require", "exports", "tslib", "../../formatHandlers/defaultFormatHandle
|
|
|
20
21
|
format: {},
|
|
21
22
|
tagName: '',
|
|
22
23
|
}, elementProcessors: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, defaultProcessors_1.defaultProcessorMap), ((options === null || options === void 0 ? void 0 : options.processorOverride) || {})), defaultStyles: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, defaultStyles_1.defaultStyleMap), ((options === null || options === void 0 ? void 0 : options.defaultStyleOverride) || {})), formatParsers: (0, defaultFormatHandlers_1.getFormatParsers)(options === null || options === void 0 ? void 0 : options.formatParserOverride, options === null || options === void 0 ? void 0 : options.additionalFormatParsers), defaultElementProcessors: defaultProcessors_1.defaultProcessorMap, defaultFormatParsers: defaultFormatHandlers_1.defaultFormatParsers, allowCacheElement: !(options === null || options === void 0 ? void 0 : options.disableCacheElement) });
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
switch (range === null || range === void 0 ? void 0 : range.type) {
|
|
26
|
-
case 0 /* Normal */:
|
|
27
|
-
var regularRange = range.ranges[0];
|
|
28
|
-
if (regularRange) {
|
|
29
|
-
selectionRoot = regularRange.commonAncestorContainer;
|
|
30
|
-
context.regularSelection = {
|
|
31
|
-
startContainer: regularRange.startContainer,
|
|
32
|
-
startOffset: regularRange.startOffset,
|
|
33
|
-
endContainer: regularRange.endContainer,
|
|
34
|
-
endOffset: regularRange.endOffset,
|
|
35
|
-
isSelectionCollapsed: regularRange.collapsed,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
break;
|
|
39
|
-
case 1 /* TableSelection */:
|
|
40
|
-
if (range.coordinates && range.table) {
|
|
41
|
-
selectionRoot = range.table;
|
|
42
|
-
context.tableSelection = {
|
|
43
|
-
table: range.table,
|
|
44
|
-
firstCell: (0, tslib_1.__assign)({}, range.coordinates.firstCell),
|
|
45
|
-
lastCell: (0, tslib_1.__assign)({}, range.coordinates.lastCell),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
break;
|
|
49
|
-
case 2 /* ImageSelection */:
|
|
50
|
-
selectionRoot = range.image;
|
|
51
|
-
context.imageSelection = {
|
|
52
|
-
image: range.image,
|
|
53
|
-
};
|
|
54
|
-
break;
|
|
24
|
+
if (editorContext === null || editorContext === void 0 ? void 0 : editorContext.isRootRtl) {
|
|
25
|
+
context.blockFormat.direction = 'rtl';
|
|
55
26
|
}
|
|
56
|
-
if (
|
|
57
|
-
context.
|
|
27
|
+
if (selection) {
|
|
28
|
+
context.rangeEx = selection;
|
|
58
29
|
}
|
|
59
30
|
return context;
|
|
60
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDomToModelContext.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext.ts"],"names":[],"mappings":";;;;IAMA
|
|
1
|
+
{"version":3,"file":"createDomToModelContext.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext.ts"],"names":[],"mappings":";;;;IAMA;;;;;OAKG;IACH,SAAgB,uBAAuB,CACnC,aAA6B,EAC7B,OAA0B,EAC1B,SAA4B;QAE5B,IAAM,OAAO,mDACN,aAAa,KAEhB,WAAW,EAAE,EAAE,EACf,aAAa,EAAE,EAAE,EACjB,aAAa,EAAE,KAAK,EAEpB,UAAU,EAAE;gBACR,MAAM,EAAE,EAAE;gBACV,gBAAgB,EAAE,EAAE;aACvB,EACD,IAAI,EAAE;gBACF,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,EAAE;aACd,EACD,IAAI,EAAE;gBACF,MAAM,EAAE,EAAE;aACb,EACD,cAAc,EAAE;gBACZ,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,EAAE;aACd,EAED,iBAAiB,kDACV,uCAAmB,GACnB,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,KAAI,EAAE,CAAC,GAGzC,aAAa,kDACN,+BAAe,GACf,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,KAAI,EAAE,CAAC,GAG5C,aAAa,EAAE,IAAA,wCAAgB,EAC3B,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAC7B,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,uBAAuB,CACnC,EAED,wBAAwB,EAAE,uCAAmB,EAC7C,oBAAoB,EAAE,4CAAoB,EAC1C,iBAAiB,EAAE,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,CAAA,GACnD,CAAC;QAEF,IAAI,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,SAAS,EAAE;YAC1B,OAAO,CAAC,WAAW,CAAC,SAAS,GAAG,KAAK,CAAC;SACzC;QAED,IAAI,SAAS,EAAE;YACX,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;SAC/B;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;IAzDD,0DAyDC","sourcesContent":["import { defaultFormatParsers, getFormatParsers } from '../../formatHandlers/defaultFormatHandlers';\nimport { defaultProcessorMap } from './defaultProcessors';\nimport { defaultStyleMap } from '../../formatHandlers/utils/defaultStyles';\nimport { DomToModelContext, DomToModelOption, EditorContext } from 'roosterjs-content-model-types';\nimport { SelectionRangeEx } from 'roosterjs-editor-types';\n\n/**\n * Create context object form DOM to Content Model conversion\n * @param editorContext Context of editor\n * @param options Options for this context\n * @param selection Selection that already exists in content\n */\nexport function createDomToModelContext(\n editorContext?: EditorContext,\n options?: DomToModelOption,\n selection?: SelectionRangeEx\n): DomToModelContext {\n const context: DomToModelContext = {\n ...editorContext,\n\n blockFormat: {},\n segmentFormat: {},\n isInSelection: false,\n\n listFormat: {\n levels: [],\n threadItemCounts: [],\n },\n link: {\n format: {},\n dataset: {},\n },\n code: {\n format: {},\n },\n blockDecorator: {\n format: {},\n tagName: '',\n },\n\n elementProcessors: {\n ...defaultProcessorMap,\n ...(options?.processorOverride || {}),\n },\n\n defaultStyles: {\n ...defaultStyleMap,\n ...(options?.defaultStyleOverride || {}),\n },\n\n formatParsers: getFormatParsers(\n options?.formatParserOverride,\n options?.additionalFormatParsers\n ),\n\n defaultElementProcessors: defaultProcessorMap,\n defaultFormatParsers: defaultFormatParsers,\n allowCacheElement: !options?.disableCacheElement,\n };\n\n if (editorContext?.isRootRtl) {\n context.blockFormat.direction = 'rtl';\n }\n\n if (selection) {\n context.rangeEx = selection;\n }\n\n return context;\n}\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { SelectionRangeEx } from 'roosterjs-editor-types';
|
|
1
2
|
import { ContentModelDocument, DomToModelOption, EditorContext } from 'roosterjs-content-model-types';
|
|
2
3
|
/**
|
|
3
4
|
* Create Content Model from DOM tree in this editor
|
|
4
5
|
* @param root Root element of DOM tree to create Content Model from
|
|
5
|
-
* @param editorContext Context of content model editor
|
|
6
6
|
* @param option The option to customize the behavior of DOM to Content Model conversion
|
|
7
|
+
* @param editorContext Context of content model editor
|
|
8
|
+
* @param selection Existing selection range in editor
|
|
7
9
|
* @returns A ContentModelDocument object that contains all the models created from the give root element
|
|
8
10
|
*/
|
|
9
|
-
export declare function domToContentModel(root: HTMLElement | DocumentFragment, editorContext?: EditorContext,
|
|
11
|
+
export declare function domToContentModel(root: HTMLElement | DocumentFragment, option?: DomToModelOption, editorContext?: EditorContext, selection?: SelectionRangeEx): ContentModelDocument;
|