roosterjs-content-model-dom 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/domToModel/processors/entityProcessor.js +0 -1
- package/lib/domToModel/processors/entityProcessor.js.map +1 -1
- package/lib/formatHandlers/block/marginFormatHandler.js +0 -16
- package/lib/formatHandlers/block/marginFormatHandler.js.map +1 -1
- package/lib/formatHandlers/utils/parseValueWithUnit.js +4 -2
- package/lib/formatHandlers/utils/parseValueWithUnit.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/modelApi/creators/createEmptyModel.d.ts +6 -0
- package/lib/modelApi/creators/createEmptyModel.js +20 -0
- package/lib/modelApi/creators/createEmptyModel.js.map +1 -0
- package/lib/modelToDom/contentModelToDom.d.ts +2 -3
- package/lib/modelToDom/contentModelToDom.js +2 -3
- package/lib/modelToDom/contentModelToDom.js.map +1 -1
- package/lib-amd/domToModel/processors/entityProcessor.js +0 -1
- package/lib-amd/domToModel/processors/entityProcessor.js.map +1 -1
- package/lib-amd/formatHandlers/block/marginFormatHandler.js +0 -16
- package/lib-amd/formatHandlers/block/marginFormatHandler.js.map +1 -1
- package/lib-amd/formatHandlers/utils/parseValueWithUnit.js +4 -2
- package/lib-amd/formatHandlers/utils/parseValueWithUnit.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/creators/createEmptyModel.d.ts +6 -0
- package/lib-amd/modelApi/creators/createEmptyModel.js +18 -0
- package/lib-amd/modelApi/creators/createEmptyModel.js.map +1 -0
- package/lib-amd/modelToDom/contentModelToDom.d.ts +2 -3
- package/lib-amd/modelToDom/contentModelToDom.js +2 -3
- package/lib-amd/modelToDom/contentModelToDom.js.map +1 -1
- package/lib-mjs/domToModel/processors/entityProcessor.js +0 -1
- package/lib-mjs/domToModel/processors/entityProcessor.js.map +1 -1
- package/lib-mjs/formatHandlers/block/marginFormatHandler.js +0 -16
- package/lib-mjs/formatHandlers/block/marginFormatHandler.js.map +1 -1
- package/lib-mjs/formatHandlers/utils/parseValueWithUnit.js +4 -2
- package/lib-mjs/formatHandlers/utils/parseValueWithUnit.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/creators/createEmptyModel.d.ts +6 -0
- package/lib-mjs/modelApi/creators/createEmptyModel.js +16 -0
- package/lib-mjs/modelApi/creators/createEmptyModel.js.map +1 -0
- package/lib-mjs/modelToDom/contentModelToDom.d.ts +2 -3
- package/lib-mjs/modelToDom/contentModelToDom.js +2 -3
- package/lib-mjs/modelToDom/contentModelToDom.js.map +1 -1
- package/package.json +2 -2
|
@@ -19,7 +19,6 @@ var entityProcessor = function (group, element, context) {
|
|
|
19
19
|
var _a;
|
|
20
20
|
var entityModel = (0, createEntity_1.createEntity)(element, true /*isReadonly*/, context.segmentFormat);
|
|
21
21
|
(0, parseFormat_1.parseFormat)(element, context.formatParsers.entity, entityModel.entityFormat, context);
|
|
22
|
-
// TODO: Need to handle selection for editable entity
|
|
23
22
|
if (context.isInSelection) {
|
|
24
23
|
entityModel.isSelected = true;
|
|
25
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/entityProcessor.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAC1D,+DAA8D;AAC9D,qEAAoE;AACpE,0DAAyD;AACzD,oDAAmD;AACnD,oDAAmD;AAGnD;;;;;GAKG;AACI,IAAM,eAAe,GAAkC,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;IAClF,IAAM,aAAa,GAAG,IAAA,+BAAc,EAAC,OAAO,CAAC,CAAC;IAE9C,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,EACpE;;QACI,IAAM,WAAW,GAAG,IAAA,2BAAY,EAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QAEtF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAEtF,
|
|
1
|
+
{"version":3,"file":"entityProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/entityProcessor.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAC1D,+DAA8D;AAC9D,qEAAoE;AACpE,0DAAyD;AACzD,oDAAmD;AACnD,oDAAmD;AAGnD;;;;;GAKG;AACI,IAAM,eAAe,GAAkC,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;IAClF,IAAM,aAAa,GAAG,IAAA,+BAAc,EAAC,OAAO,CAAC,CAAC;IAE9C,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,EACpE;;QACI,IAAM,WAAW,GAAG,IAAA,2BAAY,EAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QAEtF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAEtF,IAAI,OAAO,CAAC,aAAa,EAAE;YACvB,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC;SACjC;QAED,IAAI,aAAa,EAAE;YACf,IAAA,mBAAQ,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;SAChC;aAAM;YACH,IAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;YACjD,MAAA,OAAO,CAAC,UAAU,0CAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;SACpE;IACL,CAAC,CACJ,CAAC;AACN,CAAC,CAAC;AAvBW,QAAA,eAAe,mBAuB1B","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { createEntity } from '../../modelApi/creators/createEntity';\nimport { isBlockElement } from '../utils/isBlockElement';\nimport { parseFormat } from '../utils/parseFormat';\nimport { stackFormat } from '../utils/stackFormat';\nimport type { ElementProcessor } from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for entity\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 entityProcessor: ElementProcessor<HTMLElement> = (group, element, context) => {\n const isBlockEntity = isBlockElement(element);\n\n stackFormat(\n context,\n { segment: isBlockEntity ? 'empty' : undefined, paragraph: 'empty' },\n () => {\n const entityModel = createEntity(element, true /*isReadonly*/, context.segmentFormat);\n\n parseFormat(element, context.formatParsers.entity, entityModel.entityFormat, context);\n\n if (context.isInSelection) {\n entityModel.isSelected = true;\n }\n\n if (isBlockEntity) {\n addBlock(group, entityModel);\n } else {\n const paragraph = addSegment(group, entityModel);\n context.domIndexer?.onSegment(element, paragraph, [entityModel]);\n }\n }\n );\n};\n"]}
|
|
@@ -32,16 +32,6 @@ exports.marginFormatHandler = {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
-
var marginBlockStart = element.style.marginBlockStart || defaultStyle.marginBlockStart;
|
|
36
|
-
var marginTop = element.style.marginTop || defaultStyle.marginTop;
|
|
37
|
-
if (marginBlockStart && !marginTop) {
|
|
38
|
-
format.marginBlockStart = (0, parseValueWithUnit_1.parseValueWithUnit)(marginBlockStart) + 'px';
|
|
39
|
-
}
|
|
40
|
-
var marginBlockEnd = element.style.marginBlockEnd || defaultStyle.marginBlockEnd;
|
|
41
|
-
var marginBottom = element.style.marginBottom || defaultStyle.marginBottom;
|
|
42
|
-
if (marginBlockEnd && !marginBottom) {
|
|
43
|
-
format.marginBlockEnd = (0, parseValueWithUnit_1.parseValueWithUnit)(marginBlockEnd) + 'px';
|
|
44
|
-
}
|
|
45
35
|
},
|
|
46
36
|
apply: function (format, element, context) {
|
|
47
37
|
MarginKeys.forEach(function (key) {
|
|
@@ -50,12 +40,6 @@ exports.marginFormatHandler = {
|
|
|
50
40
|
element.style[key] = value || '0';
|
|
51
41
|
}
|
|
52
42
|
});
|
|
53
|
-
if (format.marginBlockStart && !format.marginTop) {
|
|
54
|
-
element.style.marginBlockStart = format.marginBlockStart;
|
|
55
|
-
}
|
|
56
|
-
if (format.marginBlockEnd && !format.marginBottom) {
|
|
57
|
-
element.style.marginBlockEnd = format.marginBlockEnd;
|
|
58
|
-
}
|
|
59
43
|
},
|
|
60
44
|
};
|
|
61
45
|
//# sourceMappingURL=marginFormatHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marginFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/block/marginFormatHandler.ts"],"names":[],"mappings":";;;AAAA,kEAAiE;AAIjE,IAAM,UAAU,GAAuD;IACnE,WAAW;IACX,aAAa;IACb,cAAc;IACd,YAAY;CACf,CAAC;AAEF;;GAEG;AACU,QAAA,mBAAmB,GAAgC;IAC5D,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,YAAY;QACpC,UAAU,CAAC,OAAO,CAAC,UAAA,GAAG;YAClB,IAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;YAEtD,IAAI,KAAK,EAAE;gBACP,QAAQ,GAAG,EAAE;oBACT,KAAK,WAAW,CAAC;oBACjB,KAAK,cAAc;wBACf,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;wBACpB,MAAM;oBAEV,KAAK,YAAY,CAAC;oBAClB,KAAK,aAAa;wBACd,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;4BACrB,CAAC,CAAC,IAAA,uCAAkB,EAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC;gCAC9C,IAAA,uCAAkB,EAAC,KAAK,EAAE,OAAO,CAAC;gCAClC,IAAI;4BACN,CAAC,CAAC,KAAK,CAAC;wBACZ,MAAM;iBACb;aACJ;QACL,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"marginFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/block/marginFormatHandler.ts"],"names":[],"mappings":";;;AAAA,kEAAiE;AAIjE,IAAM,UAAU,GAAuD;IACnE,WAAW;IACX,aAAa;IACb,cAAc;IACd,YAAY;CACf,CAAC;AAEF;;GAEG;AACU,QAAA,mBAAmB,GAAgC;IAC5D,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,YAAY;QACpC,UAAU,CAAC,OAAO,CAAC,UAAA,GAAG;YAClB,IAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;YAEtD,IAAI,KAAK,EAAE;gBACP,QAAQ,GAAG,EAAE;oBACT,KAAK,WAAW,CAAC;oBACjB,KAAK,cAAc;wBACf,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;wBACpB,MAAM;oBAEV,KAAK,YAAY,CAAC;oBAClB,KAAK,aAAa;wBACd,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;4BACrB,CAAC,CAAC,IAAA,uCAAkB,EAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC;gCAC9C,IAAA,uCAAkB,EAAC,KAAK,EAAE,OAAO,CAAC;gCAClC,IAAI;4BACN,CAAC,CAAC,KAAK,CAAC;wBACZ,MAAM;iBACb;aACJ;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACD,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO;QAC5B,UAAU,CAAC,OAAO,CAAC,UAAA,GAAG;YAClB,IAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAE1B,IAAI,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;gBACtC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,GAAG,CAAC;aACrC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAC","sourcesContent":["import { parseValueWithUnit } from '../utils/parseValueWithUnit';\nimport type { FormatHandler } from '../FormatHandler';\nimport type { MarginFormat } from 'roosterjs-content-model-types';\n\nconst MarginKeys: (keyof MarginFormat & keyof CSSStyleDeclaration)[] = [\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n];\n\n/**\n * @internal\n */\nexport const marginFormatHandler: FormatHandler<MarginFormat> = {\n parse: (format, element, _, defaultStyle) => {\n MarginKeys.forEach(key => {\n const value = element.style[key] || defaultStyle[key];\n\n if (value) {\n switch (key) {\n case 'marginTop':\n case 'marginBottom':\n format[key] = value;\n break;\n\n case 'marginLeft':\n case 'marginRight':\n format[key] = format[key]\n ? parseValueWithUnit(format[key] || '', element) +\n parseValueWithUnit(value, element) +\n 'px'\n : value;\n break;\n }\n }\n });\n },\n apply: (format, element, context) => {\n MarginKeys.forEach(key => {\n const value = format[key];\n\n if (value != context.implicitFormat[key]) {\n element.style[key] = value || '0';\n }\n });\n },\n};\n"]}
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseValueWithUnit = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var MarginValueRegex = /(-?\d+(\.\d+)?)([a-z]+|%)/;
|
|
6
|
+
// According to https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel, 1in = 96px
|
|
7
|
+
var PixelPerInch = 96;
|
|
6
8
|
/**
|
|
7
9
|
* Parse unit value with its unit
|
|
8
10
|
* @param value The source value to parse
|
|
@@ -34,8 +36,8 @@ function parseValueWithUnit(value, currentSizePxOrElement, resultUnit) {
|
|
|
34
36
|
case '%':
|
|
35
37
|
result = (getFontSize(currentSizePxOrElement) * num) / 100;
|
|
36
38
|
break;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
case 'in':
|
|
40
|
+
result = num * PixelPerInch;
|
|
39
41
|
break;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseValueWithUnit.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/utils/parseValueWithUnit.ts"],"names":[],"mappings":";;;;AAAA,IAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAErD;;;;;GAKG;AACH,SAAgB,kBAAkB,CAC9B,KAAkB,EAClB,sBAA6C,EAC7C,UAA8B;IAF9B,sBAAA,EAAA,UAAkB;IAElB,2BAAA,EAAA,iBAA8B;IAE9B,IAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,IAAI,KAAK,EAAE;QACD,IAAA,KAAA,oBAAwB,KAAK,IAAA,EAA5B,CAAC,QAAA,EAAE,MAAM,QAAA,EAAE,EAAE,QAAA,EAAE,IAAI,QAAS,CAAC;QACpC,IAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QAE/B,QAAQ,IAAI,EAAE;YACV,KAAK,IAAI;gBACL,MAAM,GAAG,GAAG,CAAC;gBACb,MAAM;YACV,KAAK,IAAI;gBACL,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBACrB,MAAM;YACV,KAAK,IAAI,CAAC;YACV,KAAK,KAAK;gBACN,MAAM,GAAG,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC;gBACnD,MAAM;YACV,KAAK,IAAI;gBACL,MAAM,GAAG,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;gBACzD,MAAM;YACV,KAAK,GAAG;gBACJ,MAAM,GAAG,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;gBAC3D,MAAM;YACV;
|
|
1
|
+
{"version":3,"file":"parseValueWithUnit.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/utils/parseValueWithUnit.ts"],"names":[],"mappings":";;;;AAAA,IAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAErD,uFAAuF;AACvF,IAAM,YAAY,GAAG,EAAE,CAAC;AAExB;;;;;GAKG;AACH,SAAgB,kBAAkB,CAC9B,KAAkB,EAClB,sBAA6C,EAC7C,UAA8B;IAF9B,sBAAA,EAAA,UAAkB;IAElB,2BAAA,EAAA,iBAA8B;IAE9B,IAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,IAAI,KAAK,EAAE;QACD,IAAA,KAAA,oBAAwB,KAAK,IAAA,EAA5B,CAAC,QAAA,EAAE,MAAM,QAAA,EAAE,EAAE,QAAA,EAAE,IAAI,QAAS,CAAC;QACpC,IAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QAE/B,QAAQ,IAAI,EAAE;YACV,KAAK,IAAI;gBACL,MAAM,GAAG,GAAG,CAAC;gBACb,MAAM;YACV,KAAK,IAAI;gBACL,MAAM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CAAC,GAAG,IAAI,CAAC;AAC9C,CAAC;AAED,SAAS,MAAM,CAAC,EAAU;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;AAC9C,CAAC","sourcesContent":["const MarginValueRegex = /(-?\\d+(\\.\\d+)?)([a-z]+|%)/;\n\n// According to https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel, 1in = 96px\nconst PixelPerInch = 96;\n\n/**\n * Parse unit value with its unit\n * @param value The source value to parse\n * @param currentSizePxOrElement The source element which has this unit value, or current font size (in px) from context.\n * @param resultUnit Unit for result, can be px or pt. @default px\n */\nexport function parseValueWithUnit(\n value: string = '',\n currentSizePxOrElement?: number | HTMLElement,\n resultUnit: 'px' | 'pt' = 'px'\n): number {\n const match = MarginValueRegex.exec(value);\n let result = 0;\n\n if (match) {\n const [_, numStr, __, unit] = match;\n const num = parseFloat(numStr);\n\n switch (unit) {\n case 'px':\n result = num;\n break;\n case 'pt':\n result = ptToPx(num);\n break;\n case 'em':\n case 'rem':\n result = getFontSize(currentSizePxOrElement) * num;\n break;\n case 'ex':\n result = (getFontSize(currentSizePxOrElement) * num) / 2;\n break;\n case '%':\n result = (getFontSize(currentSizePxOrElement) * num) / 100;\n break;\n case 'in':\n result = num * PixelPerInch;\n break;\n }\n }\n\n if (result > 0 && resultUnit == 'pt') {\n result = pxToPt(result);\n }\n\n return result;\n}\n\nfunction getFontSize(currentSizeOrElement?: number | HTMLElement): number {\n if (typeof currentSizeOrElement === 'undefined') {\n return 0;\n } else if (typeof currentSizeOrElement === 'number') {\n return currentSizeOrElement;\n } else {\n const styleInPt =\n currentSizeOrElement.ownerDocument.defaultView?.getComputedStyle(currentSizeOrElement)\n .fontSize ?? '';\n const floatInPt = parseFloat(styleInPt);\n const floatInPx = ptToPx(floatInPt);\n\n return floatInPx;\n }\n}\n\nfunction ptToPx(pt: number): number {\n return Math.round((pt * 4000) / 3) / 1000;\n}\n\nfunction pxToPt(px: number) {\n return Math.round((px * 3000) / 4) / 1000;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export { createGeneralBlock } from './modelApi/creators/createGeneralBlock';
|
|
|
33
33
|
export { createEntity } from './modelApi/creators/createEntity';
|
|
34
34
|
export { createDivider } from './modelApi/creators/createDivider';
|
|
35
35
|
export { createListLevel } from './modelApi/creators/createListLevel';
|
|
36
|
+
export { createEmptyModel } from './modelApi/creators/createEmptyModel';
|
|
36
37
|
export { addBlock } from './modelApi/common/addBlock';
|
|
37
38
|
export { addCode } from './modelApi/common/addDecorators';
|
|
38
39
|
export { addLink } from './modelApi/common/addDecorators';
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.createModelToDomConfig = exports.createModelToDomContextWithConfig = exports.createModelToDomContext = exports.createDomToModelConfig = exports.createDomToModelContextWithConfig = exports.createDomToModelContext = exports.parseColor = exports.setColor = exports.getColor = exports.DeprecatedColors = exports.BorderKeys = exports.parseValueWithUnit = exports.setParagraphNotImplicit = exports.normalizeSingleSegment = exports.isEmpty = void 0;
|
|
3
|
+
exports.unwrapBlock = exports.isGeneralSegment = exports.normalizeContentModel = exports.addLink = exports.addCode = exports.addBlock = exports.createEmptyModel = exports.createListLevel = exports.createDivider = exports.createEntity = exports.createGeneralBlock = exports.createGeneralSegment = exports.createParagraphDecorator = exports.createContentModelDocument = exports.createImage = exports.createText = exports.createTableCell = exports.createTable = exports.createSelectionMarker = exports.createParagraph = exports.createFormatContainer = exports.createListItem = exports.createBr = exports.isWhiteSpacePreserved = exports.reuseCachedElement = exports.addDelimiters = exports.generateEntityClassNames = exports.parseEntityClassName = exports.getAllEntityWrappers = exports.isEntityElement = exports.wrap = exports.wrapAllChildNodes = exports.moveChildNodes = exports.toArray = exports.getObjectKeys = exports.isElementOfType = exports.isNodeOfType = exports.hasMetadata = exports.updateMetadata = exports.isBlockElement = exports.areSameFormats = exports.parseFormat = exports.getRegularSelectionOffsets = exports.tableProcessor = exports.entityProcessor = exports.processChildNode = exports.handleRegularSelection = exports.childProcessor = exports.contentModelToDom = exports.domToContentModel = void 0;
|
|
4
|
+
exports.createModelToDomConfig = exports.createModelToDomContextWithConfig = exports.createModelToDomContext = exports.createDomToModelConfig = exports.createDomToModelContextWithConfig = exports.createDomToModelContext = exports.parseColor = exports.setColor = exports.getColor = exports.DeprecatedColors = exports.BorderKeys = exports.parseValueWithUnit = exports.setParagraphNotImplicit = exports.normalizeSingleSegment = exports.isEmpty = exports.addSegment = void 0;
|
|
5
5
|
var domToContentModel_1 = require("./domToModel/domToContentModel");
|
|
6
6
|
Object.defineProperty(exports, "domToContentModel", { enumerable: true, get: function () { return domToContentModel_1.domToContentModel; } });
|
|
7
7
|
var contentModelToDom_1 = require("./modelToDom/contentModelToDom");
|
|
@@ -80,6 +80,8 @@ var createDivider_1 = require("./modelApi/creators/createDivider");
|
|
|
80
80
|
Object.defineProperty(exports, "createDivider", { enumerable: true, get: function () { return createDivider_1.createDivider; } });
|
|
81
81
|
var createListLevel_1 = require("./modelApi/creators/createListLevel");
|
|
82
82
|
Object.defineProperty(exports, "createListLevel", { enumerable: true, get: function () { return createListLevel_1.createListLevel; } });
|
|
83
|
+
var createEmptyModel_1 = require("./modelApi/creators/createEmptyModel");
|
|
84
|
+
Object.defineProperty(exports, "createEmptyModel", { enumerable: true, get: function () { return createEmptyModel_1.createEmptyModel; } });
|
|
83
85
|
var addBlock_1 = require("./modelApi/common/addBlock");
|
|
84
86
|
Object.defineProperty(exports, "addBlock", { enumerable: true, get: function () { return addBlock_1.addBlock; } });
|
|
85
87
|
var addDecorators_1 = require("./modelApi/common/addDecorators");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-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AAkF;AAAzE,8HAAA,qBAAqB,OAAA;AAC9B,+DAA8D;AAArD,0GAAA,WAAW,OAAA;AACpB,uEAAsE;AAA7D,kHAAA,eAAe,OAAA;AACxB,6DAA4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,+DAA8D;AAArD,0GAAA,WAAW,OAAA;AACpB,6FAA4F;AAAnF,wIAAA,0BAA0B,OAAA;AACnC,yFAAwF;AAA/E,oIAAA,wBAAwB,OAAA;AACjC,iFAAgF;AAAvE,4HAAA,oBAAoB,OAAA;AAC7B,6EAA4E;AAAnE,wHAAA,kBAAkB,OAAA;AAC3B,iEAAgE;AAAvD,4GAAA,YAAY,OAAA;AACrB,mEAAkE;AAAzD,8GAAA,aAAa,OAAA;AACtB,uEAAsE;AAA7D,kHAAA,eAAe,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-dom/lib/index.ts"],"names":[],"mappings":";;;;AAAA,oEAAmE;AAA1D,sHAAA,iBAAiB,OAAA;AAC1B,oEAAmE;AAA1D,sHAAA,iBAAiB,OAAA;AAE1B,yEAIgD;AAH5C,gHAAA,cAAc,OAAA;AACd,wHAAA,sBAAsB,OAAA;AACtB,kHAAA,gBAAgB,OAAA;AAEpB,2EAA0E;AAAjE,kHAAA,eAAe,OAAA;AACxB,yEAAwE;AAA/D,gHAAA,cAAc,OAAA;AACvB,4FAA2F;AAAlF,wIAAA,0BAA0B,OAAA;AACnC,8DAA6D;AAApD,0GAAA,WAAW,OAAA;AACpB,oEAAmE;AAA1D,gHAAA,cAAc,OAAA;AACvB,oEAAmE;AAA1D,gHAAA,cAAc,OAAA;AAEvB,qEAAiF;AAAxE,gHAAA,cAAc,OAAA;AAAE,6GAAA,WAAW,OAAA;AACpC,wDAAoE;AAA3D,4GAAA,YAAY,OAAA;AACrB,8DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,0DAAyD;AAAhD,8GAAA,aAAa,OAAA;AACtB,8CAAwD;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AAvE,8HAAA,qBAAqB,OAAA;AAC9B,uEAAsE;AAA7D,oHAAA,gBAAgB,OAAA;AACzB,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,2DAA0D;AAAjD,wGAAA,UAAU,OAAA;AACnB,qDAAoD;AAA3C,kGAAA,OAAO,OAAA;AAChB,uEAA4E;AAAnE,0HAAA,sBAAsB,OAAA;AAE/B,oFAAmF;AAA1E,kIAAA,uBAAuB,OAAA;AAEhC,gFAA+E;AAAtE,wHAAA,kBAAkB,OAAA;AAC3B,mFAAyE;AAAhE,iHAAA,UAAU,OAAA;AACnB,sDAAgG;AAAvF,yGAAA,gBAAgB,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,mGAAA,UAAU,OAAA;AAEzD,wFAIsD;AAHlD,kIAAA,uBAAuB,OAAA;AACvB,4IAAA,iCAAiC,OAAA;AACjC,iIAAA,sBAAsB,OAAA;AAE1B,wFAIsD;AAHlD,kIAAA,uBAAuB,OAAA;AACvB,4IAAA,iCAAiC,OAAA;AACjC,iIAAA,sBAAsB,OAAA","sourcesContent":["export { domToContentModel } from './domToModel/domToContentModel';\nexport { contentModelToDom } from './modelToDom/contentModelToDom';\n\nexport {\n childProcessor,\n handleRegularSelection,\n processChildNode,\n} from './domToModel/processors/childProcessor';\nexport { entityProcessor } from './domToModel/processors/entityProcessor';\nexport { tableProcessor } from './domToModel/processors/tableProcessor';\nexport { getRegularSelectionOffsets } from './domToModel/utils/getRegularSelectionOffsets';\nexport { parseFormat } from './domToModel/utils/parseFormat';\nexport { areSameFormats } from './domToModel/utils/areSameFormats';\nexport { isBlockElement } from './domToModel/utils/isBlockElement';\n\nexport { updateMetadata, hasMetadata } from './domUtils/metadata/updateMetadata';\nexport { isNodeOfType, NodeTypeMap } from './domUtils/isNodeOfType';\nexport { isElementOfType } from './domUtils/isElementOfType';\nexport { getObjectKeys } from './domUtils/getObjectKeys';\nexport { default as toArray } from './domUtils/toArray';\nexport { moveChildNodes, wrapAllChildNodes } from './domUtils/moveChildNodes';\nexport { wrap } from './domUtils/wrap';\nexport {\n isEntityElement,\n getAllEntityWrappers,\n parseEntityClassName,\n generateEntityClassNames,\n addDelimiters,\n} from './domUtils/entityUtils';\nexport { reuseCachedElement } from './domUtils/reuseCachedElement';\nexport { isWhiteSpacePreserved } from './domUtils/isWhiteSpacePreserved';\n\nexport { createBr } from './modelApi/creators/createBr';\nexport { createListItem } from './modelApi/creators/createListItem';\nexport { createFormatContainer } from './modelApi/creators/createFormatContainer';\nexport { createParagraph } from './modelApi/creators/createParagraph';\nexport { createSelectionMarker } from './modelApi/creators/createSelectionMarker';\nexport { createTable } from './modelApi/creators/createTable';\nexport { createTableCell } from './modelApi/creators/createTableCell';\nexport { createText } from './modelApi/creators/createText';\nexport { createImage } from './modelApi/creators/createImage';\nexport { createContentModelDocument } from './modelApi/creators/createContentModelDocument';\nexport { createParagraphDecorator } from './modelApi/creators/createParagraphDecorator';\nexport { createGeneralSegment } from './modelApi/creators/createGeneralSegment';\nexport { createGeneralBlock } from './modelApi/creators/createGeneralBlock';\nexport { createEntity } from './modelApi/creators/createEntity';\nexport { createDivider } from './modelApi/creators/createDivider';\nexport { createListLevel } from './modelApi/creators/createListLevel';\nexport { createEmptyModel } from './modelApi/creators/createEmptyModel';\n\nexport { addBlock } from './modelApi/common/addBlock';\nexport { addCode } from './modelApi/common/addDecorators';\nexport { addLink } from './modelApi/common/addDecorators';\n\nexport { normalizeContentModel } from './modelApi/common/normalizeContentModel';\nexport { isGeneralSegment } from './modelApi/common/isGeneralSegment';\nexport { unwrapBlock } from './modelApi/common/unwrapBlock';\nexport { addSegment } from './modelApi/common/addSegment';\nexport { isEmpty } from './modelApi/common/isEmpty';\nexport { normalizeSingleSegment } from './modelApi/common/normalizeSegment';\n\nexport { setParagraphNotImplicit } from './modelApi/block/setParagraphNotImplicit';\n\nexport { parseValueWithUnit } from './formatHandlers/utils/parseValueWithUnit';\nexport { BorderKeys } from './formatHandlers/common/borderFormatHandler';\nexport { DeprecatedColors, getColor, setColor, parseColor } from './formatHandlers/utils/color';\n\nexport {\n createDomToModelContext,\n createDomToModelContextWithConfig,\n createDomToModelConfig,\n} from './domToModel/context/createDomToModelContext';\nexport {\n createModelToDomContext,\n createModelToDomContextWithConfig,\n createModelToDomConfig,\n} from './modelToDom/context/createModelToDomContext';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContentModelDocument, ContentModelSegmentFormat } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* Create an empty Content Model Document with initial empty line and insert point with default format
|
|
4
|
+
* @param format @optional The default format to be applied to this Content Model
|
|
5
|
+
*/
|
|
6
|
+
export declare function createEmptyModel(format?: ContentModelSegmentFormat): ContentModelDocument;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmptyModel = void 0;
|
|
4
|
+
var createBr_1 = require("./createBr");
|
|
5
|
+
var createContentModelDocument_1 = require("./createContentModelDocument");
|
|
6
|
+
var createParagraph_1 = require("./createParagraph");
|
|
7
|
+
var createSelectionMarker_1 = require("./createSelectionMarker");
|
|
8
|
+
/**
|
|
9
|
+
* Create an empty Content Model Document with initial empty line and insert point with default format
|
|
10
|
+
* @param format @optional The default format to be applied to this Content Model
|
|
11
|
+
*/
|
|
12
|
+
function createEmptyModel(format) {
|
|
13
|
+
var model = (0, createContentModelDocument_1.createContentModelDocument)(format);
|
|
14
|
+
var paragraph = (0, createParagraph_1.createParagraph)(false /*isImplicit*/, undefined /*blockFormat*/, format);
|
|
15
|
+
paragraph.segments.push((0, createSelectionMarker_1.createSelectionMarker)(format), (0, createBr_1.createBr)(format));
|
|
16
|
+
model.blocks.push(paragraph);
|
|
17
|
+
return model;
|
|
18
|
+
}
|
|
19
|
+
exports.createEmptyModel = createEmptyModel;
|
|
20
|
+
//# sourceMappingURL=createEmptyModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createEmptyModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/modelApi/creators/createEmptyModel.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AACtC,2EAA0E;AAC1E,qDAAoD;AACpD,iEAAgE;AAMhE;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,MAAkC;IAC/D,IAAM,KAAK,GAAG,IAAA,uDAA0B,EAAC,MAAM,CAAC,CAAC;IACjD,IAAM,SAAS,GAAG,IAAA,iCAAe,EAAC,KAAK,CAAC,cAAc,EAAE,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAE3F,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,6CAAqB,EAAC,MAAM,CAAC,EAAE,IAAA,mBAAQ,EAAC,MAAM,CAAC,CAAC,CAAC;IACzE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC;AACjB,CAAC;AARD,4CAQC","sourcesContent":["import { createBr } from './createBr';\nimport { createContentModelDocument } from './createContentModelDocument';\nimport { createParagraph } from './createParagraph';\nimport { createSelectionMarker } from './createSelectionMarker';\nimport type {\n ContentModelDocument,\n ContentModelSegmentFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create an empty Content Model Document with initial empty line and insert point with default format\n * @param format @optional The default format to be applied to this Content Model\n */\nexport function createEmptyModel(format?: ContentModelSegmentFormat): ContentModelDocument {\n const model = createContentModelDocument(format);\n const paragraph = createParagraph(false /*isImplicit*/, undefined /*blockFormat*/, format);\n\n paragraph.segments.push(createSelectionMarker(format), createBr(format));\n model.blocks.push(paragraph);\n\n return model;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContentModelDocument, DOMSelection, ModelToDomContext
|
|
1
|
+
import type { ContentModelDocument, DOMSelection, ModelToDomContext } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* Create DOM tree fragment from Content Model document
|
|
4
4
|
* @param doc Document object of the target DOM tree
|
|
@@ -7,7 +7,6 @@ import type { ContentModelDocument, DOMSelection, ModelToDomContext, OnNodeCreat
|
|
|
7
7
|
* won't be touched.
|
|
8
8
|
* @param model The content model document to generate DOM tree from
|
|
9
9
|
* @param context The context object for Content Model to DOM conversion
|
|
10
|
-
* @param onNodeCreated Callback invoked when a DOM node is created
|
|
11
10
|
* @returns The selection range created in DOM tree from this model, or null when there is no selection
|
|
12
11
|
*/
|
|
13
|
-
export declare function contentModelToDom(doc: Document, root: Node, model: ContentModelDocument, context: ModelToDomContext
|
|
12
|
+
export declare function contentModelToDom(doc: Document, root: Node, model: ContentModelDocument, context: ModelToDomContext): DOMSelection | null;
|
|
@@ -11,11 +11,9 @@ var isNodeOfType_1 = require("../domUtils/isNodeOfType");
|
|
|
11
11
|
* won't be touched.
|
|
12
12
|
* @param model The content model document to generate DOM tree from
|
|
13
13
|
* @param context The context object for Content Model to DOM conversion
|
|
14
|
-
* @param onNodeCreated Callback invoked when a DOM node is created
|
|
15
14
|
* @returns The selection range created in DOM tree from this model, or null when there is no selection
|
|
16
15
|
*/
|
|
17
|
-
function contentModelToDom(doc, root, model, context
|
|
18
|
-
context.onNodeCreated = onNodeCreated;
|
|
16
|
+
function contentModelToDom(doc, root, model, context) {
|
|
19
17
|
context.modelHandlers.blockGroupChildren(doc, root, model, context);
|
|
20
18
|
var range = extractSelectionRange(doc, context);
|
|
21
19
|
root.normalize();
|
|
@@ -37,6 +35,7 @@ function extractSelectionRange(doc, context) {
|
|
|
37
35
|
return {
|
|
38
36
|
type: 'range',
|
|
39
37
|
range: range,
|
|
38
|
+
isReverted: false,
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
else if (tableSelection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentModelToDom.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-dom/lib/modelToDom/contentModelToDom.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAC1C,yDAAwD;
|
|
1
|
+
{"version":3,"file":"contentModelToDom.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-dom/lib/modelToDom/contentModelToDom.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAC1C,yDAAwD;AAQxD;;;;;;;;;GASG;AACH,SAAgB,iBAAiB,CAC7B,GAAa,EACb,IAAU,EACV,KAA2B,EAC3B,OAA0B;IAE1B,OAAO,CAAC,aAAa,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAEpE,IAAM,KAAK,GAAG,qBAAqB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAElD,IAAI,CAAC,SAAS,EAAE,CAAC;IAEjB,OAAO,KAAK,CAAC;AACjB,CAAC;AAbD,8CAaC;AAED,SAAS,qBAAqB,CAAC,GAAa,EAAE,OAA0B;IAEhE,IAAA,KAGA,OAAO,iBAHyB,EAAZ,KAAK,WAAA,EAAE,GAAG,SAAA,EAC9B,cAAc,GAEd,OAAO,eAFO,EACd,cAAc,GACd,OAAO,eADO,CACN;IAEZ,IAAI,aAA8D,CAAC;IACnE,IAAI,WAA4D,CAAC;IAEjE,IAAI,cAAc,EAAE;QAChB,OAAO,cAAc,CAAC;KACzB;SAAM,IACH,CAAC,aAAa,GAAG,KAAK,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC,WAAW,GAAG,GAAG,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC,EAC1C;QACE,IAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAEhC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9D,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC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AC,EAAE,CAAC;SAChE;aAAM,IAAI,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE;YACnC,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;YAC7C,MAAM,GAAG;gBACL,SAAS,WAAA;gBACT,MAAM,EAAE,IAAA,2BAAY,EAAC,SAAS,EAAE,WAAW,CAAC;oBACxC,CAAC,CAAC,MAAA,MAAA,SAAS,CAAC,SAAS,0CAAE,MAAM,mCAAI,CAAC;oBAClC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM;aACpC,CAAC;SACL;aAAM;YACH,MAAM,GAAG,SAAS,CAAC;SACtB;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import toArray from '../domUtils/toArray';\nimport { isNodeOfType } from '../domUtils/isNodeOfType';\nimport type {\n ContentModelDocument,\n DOMSelection,\n ModelToDomBlockAndSegmentNode,\n ModelToDomContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create DOM tree fragment from Content Model document\n * @param doc Document object of the target DOM tree\n * @param root Target node that will become the container of new DOM tree.\n * When a DOM node with existing node is passed, it will be merged with content model so that unchanged blocks\n * won't be touched.\n * @param model The content model document to generate DOM tree from\n * @param context The context object for Content Model to DOM conversion\n * @returns The selection range created in DOM tree from this model, or null when there is no selection\n */\nexport function contentModelToDom(\n doc: Document,\n root: Node,\n model: ContentModelDocument,\n context: ModelToDomContext\n): DOMSelection | null {\n context.modelHandlers.blockGroupChildren(doc, root, model, context);\n\n const range = extractSelectionRange(doc, context);\n\n root.normalize();\n\n return range;\n}\n\nfunction extractSelectionRange(doc: Document, context: ModelToDomContext): DOMSelection | null {\n const {\n regularSelection: { start, end },\n tableSelection,\n imageSelection,\n } = context;\n\n let startPosition: { container: Node; offset: number } | undefined;\n let endPosition: { container: Node; offset: number } | undefined;\n\n if (imageSelection) {\n return imageSelection;\n } else if (\n (startPosition = start && calcPosition(start)) &&\n (endPosition = end && calcPosition(end))\n ) {\n const range = doc.createRange();\n\n range.setStart(startPosition.container, startPosition.offset);\n range.setEnd(endPosition.container, endPosition.offset);\n\n return {\n type: 'range',\n range,\n isReverted: false,\n };\n } else if (tableSelection) {\n return tableSelection;\n } else {\n return null;\n }\n}\n\nfunction calcPosition(\n pos: ModelToDomBlockAndSegmentNode\n): { container: Node; offset: number } | undefined {\n let result: { container: Node; offset: number } | undefined;\n\n if (pos.block) {\n if (!pos.segment) {\n result = { container: pos.block, offset: 0 };\n } else if (isNodeOfType(pos.segment, 'TEXT_NODE')) {\n result = { container: pos.segment, offset: pos.segment.nodeValue?.length || 0 };\n } else if (pos.segment.parentNode) {\n result = {\n container: pos.segment.parentNode,\n offset:\n toArray(pos.segment.parentNode.childNodes as NodeListOf<Node>).indexOf(\n pos.segment\n ) + 1,\n };\n }\n }\n\n if (result && isNodeOfType(result.container, 'DOCUMENT_FRAGMENT_NODE')) {\n const childNodes = result.container.childNodes;\n\n if (childNodes.length > result.offset) {\n result = { container: childNodes[result.offset], offset: 0 };\n } else if (result.container.lastChild) {\n const container = result.container.lastChild;\n result = {\n container,\n offset: isNodeOfType(container, 'TEXT_NODE')\n ? container.nodeValue?.length ?? 0\n : container.childNodes.length,\n };\n } else {\n result = undefined;\n }\n }\n\n return result;\n}\n"]}
|
|
@@ -14,7 +14,6 @@ define(["require", "exports", "../../modelApi/common/addBlock", "../../modelApi/
|
|
|
14
14
|
var _a;
|
|
15
15
|
var entityModel = (0, createEntity_1.createEntity)(element, true /*isReadonly*/, context.segmentFormat);
|
|
16
16
|
(0, parseFormat_1.parseFormat)(element, context.formatParsers.entity, entityModel.entityFormat, context);
|
|
17
|
-
// TODO: Need to handle selection for editable entity
|
|
18
17
|
if (context.isInSelection) {
|
|
19
18
|
entityModel.isSelected = true;
|
|
20
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/entityProcessor.ts"],"names":[],"mappings":";;;;IAQA;;;;;OAKG;IACI,IAAM,eAAe,GAAkC,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;QAClF,IAAM,aAAa,GAAG,IAAA,+BAAc,EAAC,OAAO,CAAC,CAAC;QAE9C,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,EACpE;;YACI,IAAM,WAAW,GAAG,IAAA,2BAAY,EAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;YAEtF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YAEtF,
|
|
1
|
+
{"version":3,"file":"entityProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/entityProcessor.ts"],"names":[],"mappings":";;;;IAQA;;;;;OAKG;IACI,IAAM,eAAe,GAAkC,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;QAClF,IAAM,aAAa,GAAG,IAAA,+BAAc,EAAC,OAAO,CAAC,CAAC;QAE9C,IAAA,yBAAW,EACP,OAAO,EACP,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,EACpE;;YACI,IAAM,WAAW,GAAG,IAAA,2BAAY,EAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;YAEtF,IAAA,yBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YAEtF,IAAI,OAAO,CAAC,aAAa,EAAE;gBACvB,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC;aACjC;YAED,IAAI,aAAa,EAAE;gBACf,IAAA,mBAAQ,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;aAChC;iBAAM;gBACH,IAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;gBACjD,MAAA,OAAO,CAAC,UAAU,0CAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;aACpE;QACL,CAAC,CACJ,CAAC;IACN,CAAC,CAAC;IAvBW,QAAA,eAAe,mBAuB1B","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { createEntity } from '../../modelApi/creators/createEntity';\nimport { isBlockElement } from '../utils/isBlockElement';\nimport { parseFormat } from '../utils/parseFormat';\nimport { stackFormat } from '../utils/stackFormat';\nimport type { ElementProcessor } from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for entity\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 entityProcessor: ElementProcessor<HTMLElement> = (group, element, context) => {\n const isBlockEntity = isBlockElement(element);\n\n stackFormat(\n context,\n { segment: isBlockEntity ? 'empty' : undefined, paragraph: 'empty' },\n () => {\n const entityModel = createEntity(element, true /*isReadonly*/, context.segmentFormat);\n\n parseFormat(element, context.formatParsers.entity, entityModel.entityFormat, context);\n\n if (context.isInSelection) {\n entityModel.isSelected = true;\n }\n\n if (isBlockEntity) {\n addBlock(group, entityModel);\n } else {\n const paragraph = addSegment(group, entityModel);\n context.domIndexer?.onSegment(element, paragraph, [entityModel]);\n }\n }\n );\n};\n"]}
|
|
@@ -32,16 +32,6 @@ define(["require", "exports", "../utils/parseValueWithUnit"], function (require,
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
-
var marginBlockStart = element.style.marginBlockStart || defaultStyle.marginBlockStart;
|
|
36
|
-
var marginTop = element.style.marginTop || defaultStyle.marginTop;
|
|
37
|
-
if (marginBlockStart && !marginTop) {
|
|
38
|
-
format.marginBlockStart = (0, parseValueWithUnit_1.parseValueWithUnit)(marginBlockStart) + 'px';
|
|
39
|
-
}
|
|
40
|
-
var marginBlockEnd = element.style.marginBlockEnd || defaultStyle.marginBlockEnd;
|
|
41
|
-
var marginBottom = element.style.marginBottom || defaultStyle.marginBottom;
|
|
42
|
-
if (marginBlockEnd && !marginBottom) {
|
|
43
|
-
format.marginBlockEnd = (0, parseValueWithUnit_1.parseValueWithUnit)(marginBlockEnd) + 'px';
|
|
44
|
-
}
|
|
45
35
|
},
|
|
46
36
|
apply: function (format, element, context) {
|
|
47
37
|
MarginKeys.forEach(function (key) {
|
|
@@ -50,12 +40,6 @@ define(["require", "exports", "../utils/parseValueWithUnit"], function (require,
|
|
|
50
40
|
element.style[key] = value || '0';
|
|
51
41
|
}
|
|
52
42
|
});
|
|
53
|
-
if (format.marginBlockStart && !format.marginTop) {
|
|
54
|
-
element.style.marginBlockStart = format.marginBlockStart;
|
|
55
|
-
}
|
|
56
|
-
if (format.marginBlockEnd && !format.marginBottom) {
|
|
57
|
-
element.style.marginBlockEnd = format.marginBlockEnd;
|
|
58
|
-
}
|
|
59
43
|
},
|
|
60
44
|
};
|
|
61
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marginFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/block/marginFormatHandler.ts"],"names":[],"mappings":";;;;IAIA,IAAM,UAAU,GAAuD;QACnE,WAAW;QACX,aAAa;QACb,cAAc;QACd,YAAY;KACf,CAAC;IAEF;;OAEG;IACU,QAAA,mBAAmB,GAAgC;QAC5D,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,YAAY;YACpC,UAAU,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,IAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;gBAEtD,IAAI,KAAK,EAAE;oBACP,QAAQ,GAAG,EAAE;wBACT,KAAK,WAAW,CAAC;wBACjB,KAAK,cAAc;4BACf,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;4BACpB,MAAM;wBAEV,KAAK,YAAY,CAAC;wBAClB,KAAK,aAAa;4BACd,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;gCACrB,CAAC,CAAC,IAAA,uCAAkB,EAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC;oCAC9C,IAAA,uCAAkB,EAAC,KAAK,EAAE,OAAO,CAAC;oCAClC,IAAI;gCACN,CAAC,CAAC,KAAK,CAAC;4BACZ,MAAM;qBACb;iBACJ;YACL,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"marginFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/block/marginFormatHandler.ts"],"names":[],"mappings":";;;;IAIA,IAAM,UAAU,GAAuD;QACnE,WAAW;QACX,aAAa;QACb,cAAc;QACd,YAAY;KACf,CAAC;IAEF;;OAEG;IACU,QAAA,mBAAmB,GAAgC;QAC5D,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,YAAY;YACpC,UAAU,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,IAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;gBAEtD,IAAI,KAAK,EAAE;oBACP,QAAQ,GAAG,EAAE;wBACT,KAAK,WAAW,CAAC;wBACjB,KAAK,cAAc;4BACf,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;4BACpB,MAAM;wBAEV,KAAK,YAAY,CAAC;wBAClB,KAAK,aAAa;4BACd,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;gCACrB,CAAC,CAAC,IAAA,uCAAkB,EAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC;oCAC9C,IAAA,uCAAkB,EAAC,KAAK,EAAE,OAAO,CAAC;oCAClC,IAAI;gCACN,CAAC,CAAC,KAAK,CAAC;4BACZ,MAAM;qBACb;iBACJ;YACL,CAAC,CAAC,CAAC;QACP,CAAC;QACD,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO;YAC5B,UAAU,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,IAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBAE1B,IAAI,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;oBACtC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,GAAG,CAAC;iBACrC;YACL,CAAC,CAAC,CAAC;QACP,CAAC;KACJ,CAAC","sourcesContent":["import { parseValueWithUnit } from '../utils/parseValueWithUnit';\nimport type { FormatHandler } from '../FormatHandler';\nimport type { MarginFormat } from 'roosterjs-content-model-types';\n\nconst MarginKeys: (keyof MarginFormat & keyof CSSStyleDeclaration)[] = [\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n];\n\n/**\n * @internal\n */\nexport const marginFormatHandler: FormatHandler<MarginFormat> = {\n parse: (format, element, _, defaultStyle) => {\n MarginKeys.forEach(key => {\n const value = element.style[key] || defaultStyle[key];\n\n if (value) {\n switch (key) {\n case 'marginTop':\n case 'marginBottom':\n format[key] = value;\n break;\n\n case 'marginLeft':\n case 'marginRight':\n format[key] = format[key]\n ? parseValueWithUnit(format[key] || '', element) +\n parseValueWithUnit(value, element) +\n 'px'\n : value;\n break;\n }\n }\n });\n },\n apply: (format, element, context) => {\n MarginKeys.forEach(key => {\n const value = format[key];\n\n if (value != context.implicitFormat[key]) {\n element.style[key] = value || '0';\n }\n });\n },\n};\n"]}
|
|
@@ -3,6 +3,8 @@ define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.parseValueWithUnit = void 0;
|
|
5
5
|
var MarginValueRegex = /(-?\d+(\.\d+)?)([a-z]+|%)/;
|
|
6
|
+
// According to https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel, 1in = 96px
|
|
7
|
+
var PixelPerInch = 96;
|
|
6
8
|
/**
|
|
7
9
|
* Parse unit value with its unit
|
|
8
10
|
* @param value The source value to parse
|
|
@@ -34,8 +36,8 @@ define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
|
|
|
34
36
|
case '%':
|
|
35
37
|
result = (getFontSize(currentSizePxOrElement) * num) / 100;
|
|
36
38
|
break;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
case 'in':
|
|
40
|
+
result = num * PixelPerInch;
|
|
39
41
|
break;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseValueWithUnit.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/utils/parseValueWithUnit.ts"],"names":[],"mappings":";;;;IAAA,IAAM,gBAAgB,GAAG,2BAA2B,CAAC;IAErD;;;;;OAKG;IACH,SAAgB,kBAAkB,CAC9B,KAAkB,EAClB,sBAA6C,EAC7C,UAA8B;QAF9B,sBAAA,EAAA,UAAkB;QAElB,2BAAA,EAAA,iBAA8B;QAE9B,IAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;QAEf,IAAI,KAAK,EAAE;YACD,IAAA,KAAA,oBAAwB,KAAK,IAAA,EAA5B,CAAC,QAAA,EAAE,MAAM,QAAA,EAAE,EAAE,QAAA,EAAE,IAAI,QAAS,CAAC;YACpC,IAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;YAE/B,QAAQ,IAAI,EAAE;gBACV,KAAK,IAAI;oBACL,MAAM,GAAG,GAAG,CAAC;oBACb,MAAM;gBACV,KAAK,IAAI;oBACL,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;oBACrB,MAAM;gBACV,KAAK,IAAI,CAAC;gBACV,KAAK,KAAK;oBACN,MAAM,GAAG,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC;oBACnD,MAAM;gBACV,KAAK,IAAI;oBACL,MAAM,GAAG,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;oBACzD,MAAM;gBACV,KAAK,GAAG;oBACJ,MAAM,GAAG,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;oBAC3D,MAAM;gBACV;
|
|
1
|
+
{"version":3,"file":"parseValueWithUnit.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/utils/parseValueWithUnit.ts"],"names":[],"mappings":";;;;IAAA,IAAM,gBAAgB,GAAG,2BAA2B,CAAC;IAErD,uFAAuF;IACvF,IAAM,YAAY,GAAG,EAAE,CAAC;IAExB;;;;;OAKG;IACH,SAAgB,kBAAkB,CAC9B,KAAkB,EAClB,sBAA6C,EAC7C,UAA8B;QAF9B,sBAAA,EAAA,UAAkB;QAElB,2BAAA,EAAA,iBAA8B;QAE9B,IAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;QAEf,IAAI,KAAK,EAAE;YACD,IAAA,KAAA,oBAAwB,KAAK,IAAA,EAA5B,CAAC,QAAA,EAAE,MAAM,QAAA,EAAE,EAAE,QAAA,EAAE,IAAI,QAAS,CAAC;YACpC,IAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CA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,CAAC;SACpB;IACL,CAAC;IAED,SAAS,MAAM,CAAC,EAAU;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IAC9C,CAAC;IAED,SAAS,MAAM,CAAC,EAAU;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IAC9C,CAAC","sourcesContent":["const MarginValueRegex = /(-?\\d+(\\.\\d+)?)([a-z]+|%)/;\n\n// According to https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel, 1in = 96px\nconst PixelPerInch = 96;\n\n/**\n * Parse unit value with its unit\n * @param value The source value to parse\n * @param currentSizePxOrElement The source element which has this unit value, or current font size (in px) from context.\n * @param resultUnit Unit for result, can be px or pt. @default px\n */\nexport function parseValueWithUnit(\n value: string = '',\n currentSizePxOrElement?: number | HTMLElement,\n resultUnit: 'px' | 'pt' = 'px'\n): number {\n const match = MarginValueRegex.exec(value);\n let result = 0;\n\n if (match) {\n const [_, numStr, __, unit] = match;\n const num = parseFloat(numStr);\n\n switch (unit) {\n case 'px':\n result = num;\n break;\n case 'pt':\n result = ptToPx(num);\n break;\n case 'em':\n case 'rem':\n result = getFontSize(currentSizePxOrElement) * num;\n break;\n case 'ex':\n result = (getFontSize(currentSizePxOrElement) * num) / 2;\n break;\n case '%':\n result = (getFontSize(currentSizePxOrElement) * num) / 100;\n break;\n case 'in':\n result = num * PixelPerInch;\n break;\n }\n }\n\n if (result > 0 && resultUnit == 'pt') {\n result = pxToPt(result);\n }\n\n return result;\n}\n\nfunction getFontSize(currentSizeOrElement?: number | HTMLElement): number {\n if (typeof currentSizeOrElement === 'undefined') {\n return 0;\n } else if (typeof currentSizeOrElement === 'number') {\n return currentSizeOrElement;\n } else {\n const styleInPt =\n currentSizeOrElement.ownerDocument.defaultView?.getComputedStyle(currentSizeOrElement)\n .fontSize ?? '';\n const floatInPt = parseFloat(styleInPt);\n const floatInPx = ptToPx(floatInPt);\n\n return floatInPx;\n }\n}\n\nfunction ptToPx(pt: number): number {\n return Math.round((pt * 4000) / 3) / 1000;\n}\n\nfunction pxToPt(px: number) {\n return Math.round((px * 3000) / 4) / 1000;\n}\n"]}
|
package/lib-amd/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export { createGeneralBlock } from './modelApi/creators/createGeneralBlock';
|
|
|
33
33
|
export { createEntity } from './modelApi/creators/createEntity';
|
|
34
34
|
export { createDivider } from './modelApi/creators/createDivider';
|
|
35
35
|
export { createListLevel } from './modelApi/creators/createListLevel';
|
|
36
|
+
export { createEmptyModel } from './modelApi/creators/createEmptyModel';
|
|
36
37
|
export { addBlock } from './modelApi/common/addBlock';
|
|
37
38
|
export { addCode } from './modelApi/common/addDecorators';
|
|
38
39
|
export { addLink } from './modelApi/common/addDecorators';
|
package/lib-amd/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
define(["require", "exports", "./domToModel/domToContentModel", "./modelToDom/contentModelToDom", "./domToModel/processors/childProcessor", "./domToModel/processors/entityProcessor", "./domToModel/processors/tableProcessor", "./domToModel/utils/getRegularSelectionOffsets", "./domToModel/utils/parseFormat", "./domToModel/utils/areSameFormats", "./domToModel/utils/isBlockElement", "./domUtils/metadata/updateMetadata", "./domUtils/isNodeOfType", "./domUtils/isElementOfType", "./domUtils/getObjectKeys", "./domUtils/toArray", "./domUtils/moveChildNodes", "./domUtils/wrap", "./domUtils/entityUtils", "./domUtils/reuseCachedElement", "./domUtils/isWhiteSpacePreserved", "./modelApi/creators/createBr", "./modelApi/creators/createListItem", "./modelApi/creators/createFormatContainer", "./modelApi/creators/createParagraph", "./modelApi/creators/createSelectionMarker", "./modelApi/creators/createTable", "./modelApi/creators/createTableCell", "./modelApi/creators/createText", "./modelApi/creators/createImage", "./modelApi/creators/createContentModelDocument", "./modelApi/creators/createParagraphDecorator", "./modelApi/creators/createGeneralSegment", "./modelApi/creators/createGeneralBlock", "./modelApi/creators/createEntity", "./modelApi/creators/createDivider", "./modelApi/creators/createListLevel", "./modelApi/common/addBlock", "./modelApi/common/addDecorators", "./modelApi/common/addDecorators", "./modelApi/common/normalizeContentModel", "./modelApi/common/isGeneralSegment", "./modelApi/common/unwrapBlock", "./modelApi/common/addSegment", "./modelApi/common/isEmpty", "./modelApi/common/normalizeSegment", "./modelApi/block/setParagraphNotImplicit", "./formatHandlers/utils/parseValueWithUnit", "./formatHandlers/common/borderFormatHandler", "./formatHandlers/utils/color", "./domToModel/context/createDomToModelContext", "./modelToDom/context/createModelToDomContext"], function (require, exports, domToContentModel_1, contentModelToDom_1, childProcessor_1, entityProcessor_1, tableProcessor_1, getRegularSelectionOffsets_1, parseFormat_1, areSameFormats_1, isBlockElement_1, updateMetadata_1, isNodeOfType_1, isElementOfType_1, getObjectKeys_1, toArray_1, moveChildNodes_1, wrap_1, entityUtils_1, reuseCachedElement_1, isWhiteSpacePreserved_1, createBr_1, createListItem_1, createFormatContainer_1, createParagraph_1, createSelectionMarker_1, createTable_1, createTableCell_1, createText_1, createImage_1, createContentModelDocument_1, createParagraphDecorator_1, createGeneralSegment_1, createGeneralBlock_1, createEntity_1, createDivider_1, createListLevel_1, addBlock_1, addDecorators_1, addDecorators_2, normalizeContentModel_1, isGeneralSegment_1, unwrapBlock_1, addSegment_1, isEmpty_1, normalizeSegment_1, setParagraphNotImplicit_1, parseValueWithUnit_1, borderFormatHandler_1, color_1, createDomToModelContext_1, createModelToDomContext_1) {
|
|
1
|
+
define(["require", "exports", "./domToModel/domToContentModel", "./modelToDom/contentModelToDom", "./domToModel/processors/childProcessor", "./domToModel/processors/entityProcessor", "./domToModel/processors/tableProcessor", "./domToModel/utils/getRegularSelectionOffsets", "./domToModel/utils/parseFormat", "./domToModel/utils/areSameFormats", "./domToModel/utils/isBlockElement", "./domUtils/metadata/updateMetadata", "./domUtils/isNodeOfType", "./domUtils/isElementOfType", "./domUtils/getObjectKeys", "./domUtils/toArray", "./domUtils/moveChildNodes", "./domUtils/wrap", "./domUtils/entityUtils", "./domUtils/reuseCachedElement", "./domUtils/isWhiteSpacePreserved", "./modelApi/creators/createBr", "./modelApi/creators/createListItem", "./modelApi/creators/createFormatContainer", "./modelApi/creators/createParagraph", "./modelApi/creators/createSelectionMarker", "./modelApi/creators/createTable", "./modelApi/creators/createTableCell", "./modelApi/creators/createText", "./modelApi/creators/createImage", "./modelApi/creators/createContentModelDocument", "./modelApi/creators/createParagraphDecorator", "./modelApi/creators/createGeneralSegment", "./modelApi/creators/createGeneralBlock", "./modelApi/creators/createEntity", "./modelApi/creators/createDivider", "./modelApi/creators/createListLevel", "./modelApi/creators/createEmptyModel", "./modelApi/common/addBlock", "./modelApi/common/addDecorators", "./modelApi/common/addDecorators", "./modelApi/common/normalizeContentModel", "./modelApi/common/isGeneralSegment", "./modelApi/common/unwrapBlock", "./modelApi/common/addSegment", "./modelApi/common/isEmpty", "./modelApi/common/normalizeSegment", "./modelApi/block/setParagraphNotImplicit", "./formatHandlers/utils/parseValueWithUnit", "./formatHandlers/common/borderFormatHandler", "./formatHandlers/utils/color", "./domToModel/context/createDomToModelContext", "./modelToDom/context/createModelToDomContext"], function (require, exports, domToContentModel_1, contentModelToDom_1, childProcessor_1, entityProcessor_1, tableProcessor_1, getRegularSelectionOffsets_1, parseFormat_1, areSameFormats_1, isBlockElement_1, updateMetadata_1, isNodeOfType_1, isElementOfType_1, getObjectKeys_1, toArray_1, moveChildNodes_1, wrap_1, entityUtils_1, reuseCachedElement_1, isWhiteSpacePreserved_1, createBr_1, createListItem_1, createFormatContainer_1, createParagraph_1, createSelectionMarker_1, createTable_1, createTableCell_1, createText_1, createImage_1, createContentModelDocument_1, createParagraphDecorator_1, createGeneralSegment_1, createGeneralBlock_1, createEntity_1, createDivider_1, createListLevel_1, createEmptyModel_1, addBlock_1, addDecorators_1, addDecorators_2, normalizeContentModel_1, isGeneralSegment_1, unwrapBlock_1, addSegment_1, isEmpty_1, normalizeSegment_1, setParagraphNotImplicit_1, parseValueWithUnit_1, borderFormatHandler_1, color_1, createDomToModelContext_1, createModelToDomContext_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.createModelToDomConfig = exports.createModelToDomContextWithConfig = exports.createModelToDomContext = exports.createDomToModelConfig = exports.createDomToModelContextWithConfig = exports.createDomToModelContext = exports.parseColor = exports.setColor = exports.getColor = exports.DeprecatedColors = exports.BorderKeys = exports.parseValueWithUnit = exports.setParagraphNotImplicit = exports.normalizeSingleSegment = exports.isEmpty = exports.addSegment = exports.unwrapBlock = exports.isGeneralSegment = exports.normalizeContentModel = exports.addLink = exports.addCode = exports.addBlock = exports.createListLevel = exports.createDivider = exports.createEntity = exports.createGeneralBlock = exports.createGeneralSegment = exports.createParagraphDecorator = exports.createContentModelDocument = exports.createImage = exports.createText = exports.createTableCell = exports.createTable = exports.createSelectionMarker = exports.createParagraph = exports.createFormatContainer = exports.createListItem = exports.createBr = exports.isWhiteSpacePreserved = exports.reuseCachedElement = exports.addDelimiters = exports.generateEntityClassNames = exports.parseEntityClassName = exports.getAllEntityWrappers = exports.isEntityElement = exports.wrap = exports.wrapAllChildNodes = exports.moveChildNodes = exports.toArray = exports.getObjectKeys = exports.isElementOfType = exports.isNodeOfType = exports.hasMetadata = exports.updateMetadata = exports.isBlockElement = exports.areSameFormats = exports.parseFormat = exports.getRegularSelectionOffsets = exports.tableProcessor = exports.entityProcessor = exports.processChildNode = exports.handleRegularSelection = exports.childProcessor = exports.contentModelToDom = exports.domToContentModel = void 0;
|
|
4
|
+
exports.createModelToDomConfig = exports.createModelToDomContextWithConfig = exports.createModelToDomContext = exports.createDomToModelConfig = exports.createDomToModelContextWithConfig = exports.createDomToModelContext = exports.parseColor = exports.setColor = exports.getColor = exports.DeprecatedColors = exports.BorderKeys = exports.parseValueWithUnit = exports.setParagraphNotImplicit = exports.normalizeSingleSegment = exports.isEmpty = exports.addSegment = exports.unwrapBlock = exports.isGeneralSegment = exports.normalizeContentModel = exports.addLink = exports.addCode = exports.addBlock = exports.createEmptyModel = exports.createListLevel = exports.createDivider = exports.createEntity = exports.createGeneralBlock = exports.createGeneralSegment = exports.createParagraphDecorator = exports.createContentModelDocument = exports.createImage = exports.createText = exports.createTableCell = exports.createTable = exports.createSelectionMarker = exports.createParagraph = exports.createFormatContainer = exports.createListItem = exports.createBr = exports.isWhiteSpacePreserved = exports.reuseCachedElement = exports.addDelimiters = exports.generateEntityClassNames = exports.parseEntityClassName = exports.getAllEntityWrappers = exports.isEntityElement = exports.wrap = exports.wrapAllChildNodes = exports.moveChildNodes = exports.toArray = exports.getObjectKeys = exports.isElementOfType = exports.isNodeOfType = exports.hasMetadata = exports.updateMetadata = exports.isBlockElement = exports.areSameFormats = exports.parseFormat = exports.getRegularSelectionOffsets = exports.tableProcessor = exports.entityProcessor = exports.processChildNode = exports.handleRegularSelection = exports.childProcessor = exports.contentModelToDom = exports.domToContentModel = void 0;
|
|
5
5
|
Object.defineProperty(exports, "domToContentModel", { enumerable: true, get: function () { return domToContentModel_1.domToContentModel; } });
|
|
6
6
|
Object.defineProperty(exports, "contentModelToDom", { enumerable: true, get: function () { return contentModelToDom_1.contentModelToDom; } });
|
|
7
7
|
Object.defineProperty(exports, "childProcessor", { enumerable: true, get: function () { return childProcessor_1.childProcessor; } });
|
|
@@ -45,6 +45,7 @@ define(["require", "exports", "./domToModel/domToContentModel", "./modelToDom/co
|
|
|
45
45
|
Object.defineProperty(exports, "createEntity", { enumerable: true, get: function () { return createEntity_1.createEntity; } });
|
|
46
46
|
Object.defineProperty(exports, "createDivider", { enumerable: true, get: function () { return createDivider_1.createDivider; } });
|
|
47
47
|
Object.defineProperty(exports, "createListLevel", { enumerable: true, get: function () { return createListLevel_1.createListLevel; } });
|
|
48
|
+
Object.defineProperty(exports, "createEmptyModel", { enumerable: true, get: function () { return createEmptyModel_1.createEmptyModel; } });
|
|
48
49
|
Object.defineProperty(exports, "addBlock", { enumerable: true, get: function () { return addBlock_1.addBlock; } });
|
|
49
50
|
Object.defineProperty(exports, "addCode", { enumerable: true, get: function () { return addDecorators_1.addCode; } });
|
|
50
51
|
Object.defineProperty(exports, "addLink", { enumerable: true, get: function () { return addDecorators_2.addLink; } });
|
package/lib-amd/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-dom/lib/index.ts"],"names":[],"mappings":";;;;IAAS,sHAAA,iBAAiB,OAAA;IACjB,sHAAA,iBAAiB,OAAA;IAGtB,gHAAA,cAAc,OAAA;IACd,wHAAA,sBAAsB,OAAA;IACtB,kHAAA,gBAAgB,OAAA;IAEX,kHAAA,eAAe,OAAA;IACf,gHAAA,cAAc,OAAA;IACd,wIAAA,0BAA0B,OAAA;IAC1B,0GAAA,WAAW,OAAA;IACX,gHAAA,cAAc,OAAA;IACd,gHAAA,cAAc,OAAA;IAEd,gHAAA,cAAc,OAAA;IAAE,6GAAA,WAAW,OAAA;IAC3B,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,8GAAA,aAAa,OAAA;IACb,kGAAA,OAAO,OAAW;IAClB,gHAAA,cAAc,OAAA;IAAE,mHAAA,iBAAiB,OAAA;IACjC,4FAAA,IAAI,OAAA;IAET,8GAAA,eAAe,OAAA;IACf,mHAAA,oBAAoB,OAAA;IACpB,mHAAA,oBAAoB,OAAA;IACpB,uHAAA,wBAAwB,OAAA;IACxB,4GAAA,aAAa,OAAA;IAER,wHAAA,kBAAkB,OAAA;IAClB,8HAAA,qBAAqB,OAAA;IAErB,oGAAA,QAAQ,OAAA;IACR,gHAAA,cAAc,OAAA;IACd,8HAAA,qBAAqB,OAAA;IACrB,kHAAA,eAAe,OAAA;IACf,8HAAA,qBAAqB,OAAA;IACrB,0GAAA,WAAW,OAAA;IACX,kHAAA,eAAe,OAAA;IACf,wGAAA,UAAU,OAAA;IACV,0GAAA,WAAW,OAAA;IACX,wIAAA,0BAA0B,OAAA;IAC1B,oIAAA,wBAAwB,OAAA;IACxB,4HAAA,oBAAoB,OAAA;IACpB,wHAAA,kBAAkB,OAAA;IAClB,4GAAA,YAAY,OAAA;IACZ,8GAAA,aAAa,OAAA;IACb,kHAAA,eAAe,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-dom/lib/index.ts"],"names":[],"mappings":";;;;IAAS,sHAAA,iBAAiB,OAAA;IACjB,sHAAA,iBAAiB,OAAA;IAGtB,gHAAA,cAAc,OAAA;IACd,wHAAA,sBAAsB,OAAA;IACtB,kHAAA,gBAAgB,OAAA;IAEX,kHAAA,eAAe,OAAA;IACf,gHAAA,cAAc,OAAA;IACd,wIAAA,0BAA0B,OAAA;IAC1B,0GAAA,WAAW,OAAA;IACX,gHAAA,cAAc,OAAA;IACd,gHAAA,cAAc,OAAA;IAEd,gHAAA,cAAc,OAAA;IAAE,6GAAA,WAAW,OAAA;IAC3B,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,8GAAA,aAAa,OAAA;IACb,kGAAA,OAAO,OAAW;IAClB,gHAAA,cAAc,OAAA;IAAE,mHAAA,iBAAiB,OAAA;IACjC,4FAAA,IAAI,OAAA;IAET,8GAAA,eAAe,OAAA;IACf,mHAAA,oBAAoB,OAAA;IACpB,mHAAA,oBAAoB,OAAA;IACpB,uHAAA,wBAAwB,OAAA;IACxB,4GAAA,aAAa,OAAA;IAER,wHAAA,kBAAkB,OAAA;IAClB,8HAAA,qBAAqB,OAAA;IAErB,oGAAA,QAAQ,OAAA;IACR,gHAAA,cAAc,OAAA;IACd,8HAAA,qBAAqB,OAAA;IACrB,kHAAA,eAAe,OAAA;IACf,8HAAA,qBAAqB,OAAA;IACrB,0GAAA,WAAW,OAAA;IACX,kHAAA,eAAe,OAAA;IACf,wGAAA,UAAU,OAAA;IACV,0GAAA,WAAW,OAAA;IACX,wIAAA,0BAA0B,OAAA;IAC1B,oIAAA,wBAAwB,OAAA;IACxB,4HAAA,oBAAoB,OAAA;IACpB,wHAAA,kBAAkB,OAAA;IAClB,4GAAA,YAAY,OAAA;IACZ,8GAAA,aAAa,OAAA;IACb,kHAAA,eAAe,OAAA;IACf,oHAAA,gBAAgB,OAAA;IAEhB,oGAAA,QAAQ,OAAA;IACR,wGAAA,OAAO,OAAA;IACP,wGAAA,OAAO,OAAA;IAEP,8HAAA,qBAAqB,OAAA;IACrB,oHAAA,gBAAgB,OAAA;IAChB,0GAAA,WAAW,OAAA;IACX,wGAAA,UAAU,OAAA;IACV,kGAAA,OAAO,OAAA;IACP,0HAAA,sBAAsB,OAAA;IAEtB,kIAAA,uBAAuB,OAAA;IAEvB,wHAAA,kBAAkB,OAAA;IAClB,iHAAA,UAAU,OAAA;IACV,yGAAA,gBAAgB,OAAA;IAAE,iGAAA,QAAQ,OAAA;IAAE,iGAAA,QAAQ,OAAA;IAAE,mGAAA,UAAU,OAAA;IAGrD,kIAAA,uBAAuB,OAAA;IACvB,4IAAA,iCAAiC,OAAA;IACjC,iIAAA,sBAAsB,OAAA;IAGtB,kIAAA,uBAAuB,OAAA;IACvB,4IAAA,iCAAiC,OAAA;IACjC,iIAAA,sBAAsB,OAAA","sourcesContent":["export { domToContentModel } from './domToModel/domToContentModel';\nexport { contentModelToDom } from './modelToDom/contentModelToDom';\n\nexport {\n childProcessor,\n handleRegularSelection,\n processChildNode,\n} from './domToModel/processors/childProcessor';\nexport { entityProcessor } from './domToModel/processors/entityProcessor';\nexport { tableProcessor } from './domToModel/processors/tableProcessor';\nexport { getRegularSelectionOffsets } from './domToModel/utils/getRegularSelectionOffsets';\nexport { parseFormat } from './domToModel/utils/parseFormat';\nexport { areSameFormats } from './domToModel/utils/areSameFormats';\nexport { isBlockElement } from './domToModel/utils/isBlockElement';\n\nexport { updateMetadata, hasMetadata } from './domUtils/metadata/updateMetadata';\nexport { isNodeOfType, NodeTypeMap } from './domUtils/isNodeOfType';\nexport { isElementOfType } from './domUtils/isElementOfType';\nexport { getObjectKeys } from './domUtils/getObjectKeys';\nexport { default as toArray } from './domUtils/toArray';\nexport { moveChildNodes, wrapAllChildNodes } from './domUtils/moveChildNodes';\nexport { wrap } from './domUtils/wrap';\nexport {\n isEntityElement,\n getAllEntityWrappers,\n parseEntityClassName,\n generateEntityClassNames,\n addDelimiters,\n} from './domUtils/entityUtils';\nexport { reuseCachedElement } from './domUtils/reuseCachedElement';\nexport { isWhiteSpacePreserved } from './domUtils/isWhiteSpacePreserved';\n\nexport { createBr } from './modelApi/creators/createBr';\nexport { createListItem } from './modelApi/creators/createListItem';\nexport { createFormatContainer } from './modelApi/creators/createFormatContainer';\nexport { createParagraph } from './modelApi/creators/createParagraph';\nexport { createSelectionMarker } from './modelApi/creators/createSelectionMarker';\nexport { createTable } from './modelApi/creators/createTable';\nexport { createTableCell } from './modelApi/creators/createTableCell';\nexport { createText } from './modelApi/creators/createText';\nexport { createImage } from './modelApi/creators/createImage';\nexport { createContentModelDocument } from './modelApi/creators/createContentModelDocument';\nexport { createParagraphDecorator } from './modelApi/creators/createParagraphDecorator';\nexport { createGeneralSegment } from './modelApi/creators/createGeneralSegment';\nexport { createGeneralBlock } from './modelApi/creators/createGeneralBlock';\nexport { createEntity } from './modelApi/creators/createEntity';\nexport { createDivider } from './modelApi/creators/createDivider';\nexport { createListLevel } from './modelApi/creators/createListLevel';\nexport { createEmptyModel } from './modelApi/creators/createEmptyModel';\n\nexport { addBlock } from './modelApi/common/addBlock';\nexport { addCode } from './modelApi/common/addDecorators';\nexport { addLink } from './modelApi/common/addDecorators';\n\nexport { normalizeContentModel } from './modelApi/common/normalizeContentModel';\nexport { isGeneralSegment } from './modelApi/common/isGeneralSegment';\nexport { unwrapBlock } from './modelApi/common/unwrapBlock';\nexport { addSegment } from './modelApi/common/addSegment';\nexport { isEmpty } from './modelApi/common/isEmpty';\nexport { normalizeSingleSegment } from './modelApi/common/normalizeSegment';\n\nexport { setParagraphNotImplicit } from './modelApi/block/setParagraphNotImplicit';\n\nexport { parseValueWithUnit } from './formatHandlers/utils/parseValueWithUnit';\nexport { BorderKeys } from './formatHandlers/common/borderFormatHandler';\nexport { DeprecatedColors, getColor, setColor, parseColor } from './formatHandlers/utils/color';\n\nexport {\n createDomToModelContext,\n createDomToModelContextWithConfig,\n createDomToModelConfig,\n} from './domToModel/context/createDomToModelContext';\nexport {\n createModelToDomContext,\n createModelToDomContextWithConfig,\n createModelToDomConfig,\n} from './modelToDom/context/createModelToDomContext';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContentModelDocument, ContentModelSegmentFormat } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* Create an empty Content Model Document with initial empty line and insert point with default format
|
|
4
|
+
* @param format @optional The default format to be applied to this Content Model
|
|
5
|
+
*/
|
|
6
|
+
export declare function createEmptyModel(format?: ContentModelSegmentFormat): ContentModelDocument;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
define(["require", "exports", "./createBr", "./createContentModelDocument", "./createParagraph", "./createSelectionMarker"], function (require, exports, createBr_1, createContentModelDocument_1, createParagraph_1, createSelectionMarker_1) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createEmptyModel = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Create an empty Content Model Document with initial empty line and insert point with default format
|
|
7
|
+
* @param format @optional The default format to be applied to this Content Model
|
|
8
|
+
*/
|
|
9
|
+
function createEmptyModel(format) {
|
|
10
|
+
var model = (0, createContentModelDocument_1.createContentModelDocument)(format);
|
|
11
|
+
var paragraph = (0, createParagraph_1.createParagraph)(false /*isImplicit*/, undefined /*blockFormat*/, format);
|
|
12
|
+
paragraph.segments.push((0, createSelectionMarker_1.createSelectionMarker)(format), (0, createBr_1.createBr)(format));
|
|
13
|
+
model.blocks.push(paragraph);
|
|
14
|
+
return model;
|
|
15
|
+
}
|
|
16
|
+
exports.createEmptyModel = createEmptyModel;
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=createEmptyModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createEmptyModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/modelApi/creators/createEmptyModel.ts"],"names":[],"mappings":";;;;IASA;;;OAGG;IACH,SAAgB,gBAAgB,CAAC,MAAkC;QAC/D,IAAM,KAAK,GAAG,IAAA,uDAA0B,EAAC,MAAM,CAAC,CAAC;QACjD,IAAM,SAAS,GAAG,IAAA,iCAAe,EAAC,KAAK,CAAC,cAAc,EAAE,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;QAE3F,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,6CAAqB,EAAC,MAAM,CAAC,EAAE,IAAA,mBAAQ,EAAC,MAAM,CAAC,CAAC,CAAC;QACzE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAE7B,OAAO,KAAK,CAAC;IACjB,CAAC;IARD,4CAQC","sourcesContent":["import { createBr } from './createBr';\nimport { createContentModelDocument } from './createContentModelDocument';\nimport { createParagraph } from './createParagraph';\nimport { createSelectionMarker } from './createSelectionMarker';\nimport type {\n ContentModelDocument,\n ContentModelSegmentFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create an empty Content Model Document with initial empty line and insert point with default format\n * @param format @optional The default format to be applied to this Content Model\n */\nexport function createEmptyModel(format?: ContentModelSegmentFormat): ContentModelDocument {\n const model = createContentModelDocument(format);\n const paragraph = createParagraph(false /*isImplicit*/, undefined /*blockFormat*/, format);\n\n paragraph.segments.push(createSelectionMarker(format), createBr(format));\n model.blocks.push(paragraph);\n\n return model;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContentModelDocument, DOMSelection, ModelToDomContext
|
|
1
|
+
import type { ContentModelDocument, DOMSelection, ModelToDomContext } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* Create DOM tree fragment from Content Model document
|
|
4
4
|
* @param doc Document object of the target DOM tree
|
|
@@ -7,7 +7,6 @@ import type { ContentModelDocument, DOMSelection, ModelToDomContext, OnNodeCreat
|
|
|
7
7
|
* won't be touched.
|
|
8
8
|
* @param model The content model document to generate DOM tree from
|
|
9
9
|
* @param context The context object for Content Model to DOM conversion
|
|
10
|
-
* @param onNodeCreated Callback invoked when a DOM node is created
|
|
11
10
|
* @returns The selection range created in DOM tree from this model, or null when there is no selection
|
|
12
11
|
*/
|
|
13
|
-
export declare function contentModelToDom(doc: Document, root: Node, model: ContentModelDocument, context: ModelToDomContext
|
|
12
|
+
export declare function contentModelToDom(doc: Document, root: Node, model: ContentModelDocument, context: ModelToDomContext): DOMSelection | null;
|
|
@@ -10,11 +10,9 @@ define(["require", "exports", "../domUtils/toArray", "../domUtils/isNodeOfType"]
|
|
|
10
10
|
* won't be touched.
|
|
11
11
|
* @param model The content model document to generate DOM tree from
|
|
12
12
|
* @param context The context object for Content Model to DOM conversion
|
|
13
|
-
* @param onNodeCreated Callback invoked when a DOM node is created
|
|
14
13
|
* @returns The selection range created in DOM tree from this model, or null when there is no selection
|
|
15
14
|
*/
|
|
16
|
-
function contentModelToDom(doc, root, model, context
|
|
17
|
-
context.onNodeCreated = onNodeCreated;
|
|
15
|
+
function contentModelToDom(doc, root, model, context) {
|
|
18
16
|
context.modelHandlers.blockGroupChildren(doc, root, model, context);
|
|
19
17
|
var range = extractSelectionRange(doc, context);
|
|
20
18
|
root.normalize();
|
|
@@ -36,6 +34,7 @@ define(["require", "exports", "../domUtils/toArray", "../domUtils/isNodeOfType"]
|
|
|
36
34
|
return {
|
|
37
35
|
type: 'range',
|
|
38
36
|
range: range,
|
|
37
|
+
isReverted: false,
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
40
|
else if (tableSelection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentModelToDom.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-dom/lib/modelToDom/contentModelToDom.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"contentModelToDom.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-dom/lib/modelToDom/contentModelToDom.ts"],"names":[],"mappings":";;;;IASA;;;;;;;;;OASG;IACH,SAAgB,iBAAiB,CAC7B,GAAa,EACb,IAAU,EACV,KAA2B,EAC3B,OAA0B;QAE1B,OAAO,CAAC,aAAa,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAEpE,IAAM,KAAK,GAAG,qBAAqB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAElD,IAAI,CAAC,SAAS,EAAE,CAAC;QAEjB,OAAO,KAAK,CAAC;IACjB,CAAC;IAbD,8CAaC;IAED,SAAS,qBAAqB,CAAC,GAAa,EAAE,OAA0B;QAEhE,IAAA,KAGA,OAAO,iBAHyB,EAAZ,KAAK,WAAA,EAAE,GAAG,SAAA,EAC9B,cAAc,GAEd,OAAO,eAFO,EACd,cAAc,GACd,OAAO,eADO,CACN;QAEZ,IAAI,aAA8D,CAAC;QACnE,IAAI,WAA4D,CAAC;QAEjE,IAAI,cAAc,EAAE;YAChB,OAAO,cAAc,CAAC;SACzB;aAAM,IACH,CAAC,aAAa,GAAG,KAAK,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;YAC9C,CAAC,WAAW,GAAG,GAAG,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC,EAC1C;YACE,IAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;YAEhC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;YAC9D,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM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AC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;aAChE;iBAAM,IAAI,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE;gBACnC,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;gBAC7C,MAAM,GAAG;oBACL,SAAS,WAAA;oBACT,MAAM,EAAE,IAAA,2BAAY,EAAC,SAAS,EAAE,WAAW,CAAC;wBACxC,CAAC,CAAC,MAAA,MAAA,SAAS,CAAC,SAAS,0CAAE,MAAM,mCAAI,CAAC;wBAClC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM;iBACpC,CAAC;aACL;iBAAM;gBACH,MAAM,GAAG,SAAS,CAAC;aACtB;SACJ;QAED,OAAO,MAAM,CAAC;IAClB,CAAC","sourcesContent":["import toArray from '../domUtils/toArray';\nimport { isNodeOfType } from '../domUtils/isNodeOfType';\nimport type {\n ContentModelDocument,\n DOMSelection,\n ModelToDomBlockAndSegmentNode,\n ModelToDomContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create DOM tree fragment from Content Model document\n * @param doc Document object of the target DOM tree\n * @param root Target node that will become the container of new DOM tree.\n * When a DOM node with existing node is passed, it will be merged with content model so that unchanged blocks\n * won't be touched.\n * @param model The content model document to generate DOM tree from\n * @param context The context object for Content Model to DOM conversion\n * @returns The selection range created in DOM tree from this model, or null when there is no selection\n */\nexport function contentModelToDom(\n doc: Document,\n root: Node,\n model: ContentModelDocument,\n context: ModelToDomContext\n): DOMSelection | null {\n context.modelHandlers.blockGroupChildren(doc, root, model, context);\n\n const range = extractSelectionRange(doc, context);\n\n root.normalize();\n\n return range;\n}\n\nfunction extractSelectionRange(doc: Document, context: ModelToDomContext): DOMSelection | null {\n const {\n regularSelection: { start, end },\n tableSelection,\n imageSelection,\n } = context;\n\n let startPosition: { container: Node; offset: number } | undefined;\n let endPosition: { container: Node; offset: number } | undefined;\n\n if (imageSelection) {\n return imageSelection;\n } else if (\n (startPosition = start && calcPosition(start)) &&\n (endPosition = end && calcPosition(end))\n ) {\n const range = doc.createRange();\n\n range.setStart(startPosition.container, startPosition.offset);\n range.setEnd(endPosition.container, endPosition.offset);\n\n return {\n type: 'range',\n range,\n isReverted: false,\n };\n } else if (tableSelection) {\n return tableSelection;\n } else {\n return null;\n }\n}\n\nfunction calcPosition(\n pos: ModelToDomBlockAndSegmentNode\n): { container: Node; offset: number } | undefined {\n let result: { container: Node; offset: number } | undefined;\n\n if (pos.block) {\n if (!pos.segment) {\n result = { container: pos.block, offset: 0 };\n } else if (isNodeOfType(pos.segment, 'TEXT_NODE')) {\n result = { container: pos.segment, offset: pos.segment.nodeValue?.length || 0 };\n } else if (pos.segment.parentNode) {\n result = {\n container: pos.segment.parentNode,\n offset:\n toArray(pos.segment.parentNode.childNodes as NodeListOf<Node>).indexOf(\n pos.segment\n ) + 1,\n };\n }\n }\n\n if (result && isNodeOfType(result.container, 'DOCUMENT_FRAGMENT_NODE')) {\n const childNodes = result.container.childNodes;\n\n if (childNodes.length > result.offset) {\n result = { container: childNodes[result.offset], offset: 0 };\n } else if (result.container.lastChild) {\n const container = result.container.lastChild;\n result = {\n container,\n offset: isNodeOfType(container, 'TEXT_NODE')\n ? container.nodeValue?.length ?? 0\n : container.childNodes.length,\n };\n } else {\n result = undefined;\n }\n }\n\n return result;\n}\n"]}
|
|
@@ -16,7 +16,6 @@ export var entityProcessor = function (group, element, context) {
|
|
|
16
16
|
var _a;
|
|
17
17
|
var entityModel = createEntity(element, true /*isReadonly*/, context.segmentFormat);
|
|
18
18
|
parseFormat(element, context.formatParsers.entity, entityModel.entityFormat, context);
|
|
19
|
-
// TODO: Need to handle selection for editable entity
|
|
20
19
|
if (context.isInSelection) {
|
|
21
20
|
entityModel.isSelected = true;
|
|
22
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/entityProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD;;;;;GAKG;AACH,MAAM,CAAC,IAAM,eAAe,GAAkC,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;IAClF,IAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAE9C,WAAW,CACP,OAAO,EACP,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,EACpE;;QACI,IAAM,WAAW,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QAEtF,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAEtF,
|
|
1
|
+
{"version":3,"file":"entityProcessor.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/entityProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD;;;;;GAKG;AACH,MAAM,CAAC,IAAM,eAAe,GAAkC,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;IAClF,IAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAE9C,WAAW,CACP,OAAO,EACP,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,EACpE;;QACI,IAAM,WAAW,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QAEtF,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAEtF,IAAI,OAAO,CAAC,aAAa,EAAE;YACvB,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC;SACjC;QAED,IAAI,aAAa,EAAE;YACf,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;SAChC;aAAM;YACH,IAAM,SAAS,GAAG,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;YACjD,MAAA,OAAO,CAAC,UAAU,0CAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;SACpE;IACL,CAAC,CACJ,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { addBlock } from '../../modelApi/common/addBlock';\nimport { addSegment } from '../../modelApi/common/addSegment';\nimport { createEntity } from '../../modelApi/creators/createEntity';\nimport { isBlockElement } from '../utils/isBlockElement';\nimport { parseFormat } from '../utils/parseFormat';\nimport { stackFormat } from '../utils/stackFormat';\nimport type { ElementProcessor } from 'roosterjs-content-model-types';\n\n/**\n * Content Model Element Processor for entity\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 entityProcessor: ElementProcessor<HTMLElement> = (group, element, context) => {\n const isBlockEntity = isBlockElement(element);\n\n stackFormat(\n context,\n { segment: isBlockEntity ? 'empty' : undefined, paragraph: 'empty' },\n () => {\n const entityModel = createEntity(element, true /*isReadonly*/, context.segmentFormat);\n\n parseFormat(element, context.formatParsers.entity, entityModel.entityFormat, context);\n\n if (context.isInSelection) {\n entityModel.isSelected = true;\n }\n\n if (isBlockEntity) {\n addBlock(group, entityModel);\n } else {\n const paragraph = addSegment(group, entityModel);\n context.domIndexer?.onSegment(element, paragraph, [entityModel]);\n }\n }\n );\n};\n"]}
|
|
@@ -29,16 +29,6 @@ export var marginFormatHandler = {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
var marginBlockStart = element.style.marginBlockStart || defaultStyle.marginBlockStart;
|
|
33
|
-
var marginTop = element.style.marginTop || defaultStyle.marginTop;
|
|
34
|
-
if (marginBlockStart && !marginTop) {
|
|
35
|
-
format.marginBlockStart = parseValueWithUnit(marginBlockStart) + 'px';
|
|
36
|
-
}
|
|
37
|
-
var marginBlockEnd = element.style.marginBlockEnd || defaultStyle.marginBlockEnd;
|
|
38
|
-
var marginBottom = element.style.marginBottom || defaultStyle.marginBottom;
|
|
39
|
-
if (marginBlockEnd && !marginBottom) {
|
|
40
|
-
format.marginBlockEnd = parseValueWithUnit(marginBlockEnd) + 'px';
|
|
41
|
-
}
|
|
42
32
|
},
|
|
43
33
|
apply: function (format, element, context) {
|
|
44
34
|
MarginKeys.forEach(function (key) {
|
|
@@ -47,12 +37,6 @@ export var marginFormatHandler = {
|
|
|
47
37
|
element.style[key] = value || '0';
|
|
48
38
|
}
|
|
49
39
|
});
|
|
50
|
-
if (format.marginBlockStart && !format.marginTop) {
|
|
51
|
-
element.style.marginBlockStart = format.marginBlockStart;
|
|
52
|
-
}
|
|
53
|
-
if (format.marginBlockEnd && !format.marginBottom) {
|
|
54
|
-
element.style.marginBlockEnd = format.marginBlockEnd;
|
|
55
|
-
}
|
|
56
40
|
},
|
|
57
41
|
};
|
|
58
42
|
//# sourceMappingURL=marginFormatHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marginFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/block/marginFormatHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAIjE,IAAM,UAAU,GAAuD;IACnE,WAAW;IACX,aAAa;IACb,cAAc;IACd,YAAY;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAgC;IAC5D,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,YAAY;QACpC,UAAU,CAAC,OAAO,CAAC,UAAA,GAAG;YAClB,IAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;YAEtD,IAAI,KAAK,EAAE;gBACP,QAAQ,GAAG,EAAE;oBACT,KAAK,WAAW,CAAC;oBACjB,KAAK,cAAc;wBACf,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;wBACpB,MAAM;oBAEV,KAAK,YAAY,CAAC;oBAClB,KAAK,aAAa;wBACd,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;4BACrB,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC;gCAC9C,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC;gCAClC,IAAI;4BACN,CAAC,CAAC,KAAK,CAAC;wBACZ,MAAM;iBACb;aACJ;QACL,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"marginFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/block/marginFormatHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,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Unit';\nimport type { FormatHandler } from '../FormatHandler';\nimport type { MarginFormat } from 'roosterjs-content-model-types';\n\nconst MarginKeys: (keyof MarginFormat & keyof CSSStyleDeclaration)[] = [\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n];\n\n/**\n * @internal\n */\nexport const marginFormatHandler: FormatHandler<MarginFormat> = {\n parse: (format, element, _, defaultStyle) => {\n MarginKeys.forEach(key => {\n const value = element.style[key] || defaultStyle[key];\n\n if (value) {\n switch (key) {\n case 'marginTop':\n case 'marginBottom':\n format[key] = value;\n break;\n\n case 'marginLeft':\n case 'marginRight':\n format[key] = format[key]\n ? parseValueWithUnit(format[key] || '', element) +\n parseValueWithUnit(value, element) +\n 'px'\n : value;\n break;\n }\n }\n });\n },\n apply: (format, element, context) => {\n MarginKeys.forEach(key => {\n const value = format[key];\n\n if (value != context.implicitFormat[key]) {\n element.style[key] = value || '0';\n }\n });\n },\n};\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
2
|
var MarginValueRegex = /(-?\d+(\.\d+)?)([a-z]+|%)/;
|
|
3
|
+
// According to https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel, 1in = 96px
|
|
4
|
+
var PixelPerInch = 96;
|
|
3
5
|
/**
|
|
4
6
|
* Parse unit value with its unit
|
|
5
7
|
* @param value The source value to parse
|
|
@@ -31,8 +33,8 @@ export function parseValueWithUnit(value, currentSizePxOrElement, resultUnit) {
|
|
|
31
33
|
case '%':
|
|
32
34
|
result = (getFontSize(currentSizePxOrElement) * num) / 100;
|
|
33
35
|
break;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
case 'in':
|
|
37
|
+
result = num * PixelPerInch;
|
|
36
38
|
break;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseValueWithUnit.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/utils/parseValueWithUnit.ts"],"names":[],"mappings":";AAAA,IAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAErD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAC9B,KAAkB,EAClB,sBAA6C,EAC7C,UAA8B;IAF9B,sBAAA,EAAA,UAAkB;IAElB,2BAAA,EAAA,iBAA8B;IAE9B,IAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,IAAI,KAAK,EAAE;QACD,IAAA,KAAA,OAAwB,KAAK,IAAA,EAA5B,CAAC,QAAA,EAAE,MAAM,QAAA,EAAE,EAAE,QAAA,EAAE,IAAI,QAAS,CAAC;QACpC,IAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QAE/B,QAAQ,IAAI,EAAE;YACV,KAAK,IAAI;gBACL,MAAM,GAAG,GAAG,CAAC;gBACb,MAAM;YACV,KAAK,IAAI;gBACL,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBACrB,MAAM;YACV,KAAK,IAAI,CAAC;YACV,KAAK,KAAK;gBACN,MAAM,GAAG,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC;gBACnD,MAAM;YACV,KAAK,IAAI;gBACL,MAAM,GAAG,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;gBACzD,MAAM;YACV,KAAK,GAAG;gBACJ,MAAM,GAAG,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;gBAC3D,MAAM;YACV;
|
|
1
|
+
{"version":3,"file":"parseValueWithUnit.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/utils/parseValueWithUnit.ts"],"names":[],"mappings":";AAAA,IAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAErD,uFAAuF;AACvF,I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AW,CAAC,oBAA2C;;IAC5D,IAAI,OAAO,oBAAoB,KAAK,WAAW,EAAE;QAC7C,OAAO,CAAC,CAAC;KACZ;SAAM,IAAI,OAAO,oBAAoB,KAAK,QAAQ,EAAE;QACjD,OAAO,oBAAoB,CAAC;KAC/B;SAAM;QACH,IAAM,SAAS,GACX,MAAA,MAAA,oBAAoB,CAAC,aAAa,CAAC,WAAW,0CAAE,gBAAgB,CAAC,oBAAoB,EAChF,QAAQ,mCAAI,EAAE,CAAC;QACxB,IAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;QACxC,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QAEpC,OAAO,SAAS,CAAC;KACpB;AACL,CAAC;AAED,SAAS,MAAM,CAAC,EAAU;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;AAC9C,CAAC;AAED,SAAS,MAAM,CAAC,EAAU;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;AAC9C,CAAC","sourcesContent":["const MarginValueRegex = /(-?\\d+(\\.\\d+)?)([a-z]+|%)/;\n\n// According to https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel, 1in = 96px\nconst PixelPerInch = 96;\n\n/**\n * Parse unit value with its unit\n * @param value The source value to parse\n * @param currentSizePxOrElement The source element which has this unit value, or current font size (in px) from context.\n * @param resultUnit Unit for result, can be px or pt. @default px\n */\nexport function parseValueWithUnit(\n value: string = '',\n currentSizePxOrElement?: number | HTMLElement,\n resultUnit: 'px' | 'pt' = 'px'\n): number {\n const match = MarginValueRegex.exec(value);\n let result = 0;\n\n if (match) {\n const [_, numStr, __, unit] = match;\n const num = parseFloat(numStr);\n\n switch (unit) {\n case 'px':\n result = num;\n break;\n case 'pt':\n result = ptToPx(num);\n break;\n case 'em':\n case 'rem':\n result = getFontSize(currentSizePxOrElement) * num;\n break;\n case 'ex':\n result = (getFontSize(currentSizePxOrElement) * num) / 2;\n break;\n case '%':\n result = (getFontSize(currentSizePxOrElement) * num) / 100;\n break;\n case 'in':\n result = num * PixelPerInch;\n break;\n }\n }\n\n if (result > 0 && resultUnit == 'pt') {\n result = pxToPt(result);\n }\n\n return result;\n}\n\nfunction getFontSize(currentSizeOrElement?: number | HTMLElement): number {\n if (typeof currentSizeOrElement === 'undefined') {\n return 0;\n } else if (typeof currentSizeOrElement === 'number') {\n return currentSizeOrElement;\n } else {\n const styleInPt =\n currentSizeOrElement.ownerDocument.defaultView?.getComputedStyle(currentSizeOrElement)\n .fontSize ?? '';\n const floatInPt = parseFloat(styleInPt);\n const floatInPx = ptToPx(floatInPt);\n\n return floatInPx;\n }\n}\n\nfunction ptToPx(pt: number): number {\n return Math.round((pt * 4000) / 3) / 1000;\n}\n\nfunction pxToPt(px: number) {\n return Math.round((px * 3000) / 4) / 1000;\n}\n"]}
|
package/lib-mjs/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export { createGeneralBlock } from './modelApi/creators/createGeneralBlock';
|
|
|
33
33
|
export { createEntity } from './modelApi/creators/createEntity';
|
|
34
34
|
export { createDivider } from './modelApi/creators/createDivider';
|
|
35
35
|
export { createListLevel } from './modelApi/creators/createListLevel';
|
|
36
|
+
export { createEmptyModel } from './modelApi/creators/createEmptyModel';
|
|
36
37
|
export { addBlock } from './modelApi/common/addBlock';
|
|
37
38
|
export { addCode } from './modelApi/common/addDecorators';
|
|
38
39
|
export { addLink } from './modelApi/common/addDecorators';
|
package/lib-mjs/index.js
CHANGED
|
@@ -33,6 +33,7 @@ export { createGeneralBlock } from './modelApi/creators/createGeneralBlock';
|
|
|
33
33
|
export { createEntity } from './modelApi/creators/createEntity';
|
|
34
34
|
export { createDivider } from './modelApi/creators/createDivider';
|
|
35
35
|
export { createListLevel } from './modelApi/creators/createListLevel';
|
|
36
|
+
export { createEmptyModel } from './modelApi/creators/createEmptyModel';
|
|
36
37
|
export { addBlock } from './modelApi/common/addBlock';
|
|
37
38
|
export { addCode } from './modelApi/common/addDecorators';
|
|
38
39
|
export { addLink } from './modelApi/common/addDecorators';
|
package/lib-mjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-dom/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EACH,cAAc,EACd,sBAAsB,EACtB,gBAAgB,GACnB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,YAAY,EAAe,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACH,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,aAAa,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-dom/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EACH,cAAc,EACd,sBAAsB,E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C;AACzE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAEhG,OAAO,EACH,uBAAuB,EACvB,iCAAiC,EACjC,sBAAsB,GACzB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACH,uBAAuB,EACvB,iCAAiC,EACjC,sBAAsB,GACzB,MAAM,8CAA8C,CAAC","sourcesContent":["export { domToContentModel } from './domToModel/domToContentModel';\nexport { contentModelToDom } from './modelToDom/contentModelToDom';\n\nexport {\n childProcessor,\n handleRegularSelection,\n processChildNode,\n} from './domToModel/processors/childProcessor';\nexport { entityProcessor } from './domToModel/processors/entityProcessor';\nexport { tableProcessor } from './domToModel/processors/tableProcessor';\nexport { getRegularSelectionOffsets } from './domToModel/utils/getRegularSelectionOffsets';\nexport { parseFormat } from './domToModel/utils/parseFormat';\nexport { areSameFormats } from './domToModel/utils/areSameFormats';\nexport { isBlockElement } from './domToModel/utils/isBlockElement';\n\nexport { updateMetadata, hasMetadata } from './domUtils/metadata/updateMetadata';\nexport { isNodeOfType, NodeTypeMap } from './domUtils/isNodeOfType';\nexport { isElementOfType } from './domUtils/isElementOfType';\nexport { getObjectKeys } from './domUtils/getObjectKeys';\nexport { default as toArray } from './domUtils/toArray';\nexport { moveChildNodes, wrapAllChildNodes } from './domUtils/moveChildNodes';\nexport { wrap } from './domUtils/wrap';\nexport {\n isEntityElement,\n getAllEntityWrappers,\n parseEntityClassName,\n generateEntityClassNames,\n addDelimiters,\n} from './domUtils/entityUtils';\nexport { reuseCachedElement } from './domUtils/reuseCachedElement';\nexport { isWhiteSpacePreserved } from './domUtils/isWhiteSpacePreserved';\n\nexport { createBr } from './modelApi/creators/createBr';\nexport { createListItem } from './modelApi/creators/createListItem';\nexport { createFormatContainer } from './modelApi/creators/createFormatContainer';\nexport { createParagraph } from './modelApi/creators/createParagraph';\nexport { createSelectionMarker } from './modelApi/creators/createSelectionMarker';\nexport { createTable } from './modelApi/creators/createTable';\nexport { createTableCell } from './modelApi/creators/createTableCell';\nexport { createText } from './modelApi/creators/createText';\nexport { createImage } from './modelApi/creators/createImage';\nexport { createContentModelDocument } from './modelApi/creators/createContentModelDocument';\nexport { createParagraphDecorator } from './modelApi/creators/createParagraphDecorator';\nexport { createGeneralSegment } from './modelApi/creators/createGeneralSegment';\nexport { createGeneralBlock } from './modelApi/creators/createGeneralBlock';\nexport { createEntity } from './modelApi/creators/createEntity';\nexport { createDivider } from './modelApi/creators/createDivider';\nexport { createListLevel } from './modelApi/creators/createListLevel';\nexport { createEmptyModel } from './modelApi/creators/createEmptyModel';\n\nexport { addBlock } from './modelApi/common/addBlock';\nexport { addCode } from './modelApi/common/addDecorators';\nexport { addLink } from './modelApi/common/addDecorators';\n\nexport { normalizeContentModel } from './modelApi/common/normalizeContentModel';\nexport { isGeneralSegment } from './modelApi/common/isGeneralSegment';\nexport { unwrapBlock } from './modelApi/common/unwrapBlock';\nexport { addSegment } from './modelApi/common/addSegment';\nexport { isEmpty } from './modelApi/common/isEmpty';\nexport { normalizeSingleSegment } from './modelApi/common/normalizeSegment';\n\nexport { setParagraphNotImplicit } from './modelApi/block/setParagraphNotImplicit';\n\nexport { parseValueWithUnit } from './formatHandlers/utils/parseValueWithUnit';\nexport { BorderKeys } from './formatHandlers/common/borderFormatHandler';\nexport { DeprecatedColors, getColor, setColor, parseColor } from './formatHandlers/utils/color';\n\nexport {\n createDomToModelContext,\n createDomToModelContextWithConfig,\n createDomToModelConfig,\n} from './domToModel/context/createDomToModelContext';\nexport {\n createModelToDomContext,\n createModelToDomContextWithConfig,\n createModelToDomConfig,\n} from './modelToDom/context/createModelToDomContext';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContentModelDocument, ContentModelSegmentFormat } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* Create an empty Content Model Document with initial empty line and insert point with default format
|
|
4
|
+
* @param format @optional The default format to be applied to this Content Model
|
|
5
|
+
*/
|
|
6
|
+
export declare function createEmptyModel(format?: ContentModelSegmentFormat): ContentModelDocument;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createBr } from './createBr';
|
|
2
|
+
import { createContentModelDocument } from './createContentModelDocument';
|
|
3
|
+
import { createParagraph } from './createParagraph';
|
|
4
|
+
import { createSelectionMarker } from './createSelectionMarker';
|
|
5
|
+
/**
|
|
6
|
+
* Create an empty Content Model Document with initial empty line and insert point with default format
|
|
7
|
+
* @param format @optional The default format to be applied to this Content Model
|
|
8
|
+
*/
|
|
9
|
+
export function createEmptyModel(format) {
|
|
10
|
+
var model = createContentModelDocument(format);
|
|
11
|
+
var paragraph = createParagraph(false /*isImplicit*/, undefined /*blockFormat*/, format);
|
|
12
|
+
paragraph.segments.push(createSelectionMarker(format), createBr(format));
|
|
13
|
+
model.blocks.push(paragraph);
|
|
14
|
+
return model;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=createEmptyModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createEmptyModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/modelApi/creators/createEmptyModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAMhE;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkC;IAC/D,IAAM,KAAK,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;IACjD,IAAM,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC,cAAc,EAAE,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAE3F,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACzE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { createBr } from './createBr';\nimport { createContentModelDocument } from './createContentModelDocument';\nimport { createParagraph } from './createParagraph';\nimport { createSelectionMarker } from './createSelectionMarker';\nimport type {\n ContentModelDocument,\n ContentModelSegmentFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create an empty Content Model Document with initial empty line and insert point with default format\n * @param format @optional The default format to be applied to this Content Model\n */\nexport function createEmptyModel(format?: ContentModelSegmentFormat): ContentModelDocument {\n const model = createContentModelDocument(format);\n const paragraph = createParagraph(false /*isImplicit*/, undefined /*blockFormat*/, format);\n\n paragraph.segments.push(createSelectionMarker(format), createBr(format));\n model.blocks.push(paragraph);\n\n return model;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContentModelDocument, DOMSelection, ModelToDomContext
|
|
1
|
+
import type { ContentModelDocument, DOMSelection, ModelToDomContext } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* Create DOM tree fragment from Content Model document
|
|
4
4
|
* @param doc Document object of the target DOM tree
|
|
@@ -7,7 +7,6 @@ import type { ContentModelDocument, DOMSelection, ModelToDomContext, OnNodeCreat
|
|
|
7
7
|
* won't be touched.
|
|
8
8
|
* @param model The content model document to generate DOM tree from
|
|
9
9
|
* @param context The context object for Content Model to DOM conversion
|
|
10
|
-
* @param onNodeCreated Callback invoked when a DOM node is created
|
|
11
10
|
* @returns The selection range created in DOM tree from this model, or null when there is no selection
|
|
12
11
|
*/
|
|
13
|
-
export declare function contentModelToDom(doc: Document, root: Node, model: ContentModelDocument, context: ModelToDomContext
|
|
12
|
+
export declare function contentModelToDom(doc: Document, root: Node, model: ContentModelDocument, context: ModelToDomContext): DOMSelection | null;
|
|
@@ -8,11 +8,9 @@ import { isNodeOfType } from '../domUtils/isNodeOfType';
|
|
|
8
8
|
* won't be touched.
|
|
9
9
|
* @param model The content model document to generate DOM tree from
|
|
10
10
|
* @param context The context object for Content Model to DOM conversion
|
|
11
|
-
* @param onNodeCreated Callback invoked when a DOM node is created
|
|
12
11
|
* @returns The selection range created in DOM tree from this model, or null when there is no selection
|
|
13
12
|
*/
|
|
14
|
-
export function contentModelToDom(doc, root, model, context
|
|
15
|
-
context.onNodeCreated = onNodeCreated;
|
|
13
|
+
export function contentModelToDom(doc, root, model, context) {
|
|
16
14
|
context.modelHandlers.blockGroupChildren(doc, root, model, context);
|
|
17
15
|
var range = extractSelectionRange(doc, context);
|
|
18
16
|
root.normalize();
|
|
@@ -33,6 +31,7 @@ function extractSelectionRange(doc, context) {
|
|
|
33
31
|
return {
|
|
34
32
|
type: 'range',
|
|
35
33
|
range: range,
|
|
34
|
+
isReverted: false,
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
37
|
else if (tableSelection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentModelToDom.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-dom/lib/modelToDom/contentModelToDom.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"contentModelToDom.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-dom/lib/modelToDom/contentModelToDom.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAQxD;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAC7B,GAAa,EACb,IAAU,EACV,KAA2B,EAC3B,OAA0B;IAE1B,OAAO,CAAC,aAAa,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,O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CAAC","sourcesContent":["import toArray from '../domUtils/toArray';\nimport { isNodeOfType } from '../domUtils/isNodeOfType';\nimport type {\n ContentModelDocument,\n DOMSelection,\n ModelToDomBlockAndSegmentNode,\n ModelToDomContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * Create DOM tree fragment from Content Model document\n * @param doc Document object of the target DOM tree\n * @param root Target node that will become the container of new DOM tree.\n * When a DOM node with existing node is passed, it will be merged with content model so that unchanged blocks\n * won't be touched.\n * @param model The content model document to generate DOM tree from\n * @param context The context object for Content Model to DOM conversion\n * @returns The selection range created in DOM tree from this model, or null when there is no selection\n */\nexport function contentModelToDom(\n doc: Document,\n root: Node,\n model: ContentModelDocument,\n context: ModelToDomContext\n): DOMSelection | null {\n context.modelHandlers.blockGroupChildren(doc, root, model, context);\n\n const range = extractSelectionRange(doc, context);\n\n root.normalize();\n\n return range;\n}\n\nfunction extractSelectionRange(doc: Document, context: ModelToDomContext): DOMSelection | null {\n const {\n regularSelection: { start, end },\n tableSelection,\n imageSelection,\n } = context;\n\n let startPosition: { container: Node; offset: number } | undefined;\n let endPosition: { container: Node; offset: number } | undefined;\n\n if (imageSelection) {\n return imageSelection;\n } else if (\n (startPosition = start && calcPosition(start)) &&\n (endPosition = end && calcPosition(end))\n ) {\n const range = doc.createRange();\n\n range.setStart(startPosition.container, startPosition.offset);\n range.setEnd(endPosition.container, endPosition.offset);\n\n return {\n type: 'range',\n range,\n isReverted: false,\n };\n } else if (tableSelection) {\n return tableSelection;\n } else {\n return null;\n }\n}\n\nfunction calcPosition(\n pos: ModelToDomBlockAndSegmentNode\n): { container: Node; offset: number } | undefined {\n let result: { container: Node; offset: number } | undefined;\n\n if (pos.block) {\n if (!pos.segment) {\n result = { container: pos.block, offset: 0 };\n } else if (isNodeOfType(pos.segment, 'TEXT_NODE')) {\n result = { container: pos.segment, offset: pos.segment.nodeValue?.length || 0 };\n } else if (pos.segment.parentNode) {\n result = {\n container: pos.segment.parentNode,\n offset:\n toArray(pos.segment.parentNode.childNodes as NodeListOf<Node>).indexOf(\n pos.segment\n ) + 1,\n };\n }\n }\n\n if (result && isNodeOfType(result.container, 'DOCUMENT_FRAGMENT_NODE')) {\n const childNodes = result.container.childNodes;\n\n if (childNodes.length > result.offset) {\n result = { container: childNodes[result.offset], offset: 0 };\n } else if (result.container.lastChild) {\n const container = result.container.lastChild;\n result = {\n container,\n offset: isNodeOfType(container, 'TEXT_NODE')\n ? container.nodeValue?.length ?? 0\n : container.childNodes.length,\n };\n } else {\n result = undefined;\n }\n }\n\n return result;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"description": "Content Model for roosterjs (Under development)",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.1",
|
|
6
|
-
"roosterjs-content-model-types": "^0.
|
|
6
|
+
"roosterjs-content-model-types": "^0.25.0"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.25.0",
|
|
9
9
|
"main": "./lib/index.js",
|
|
10
10
|
"typings": "./lib/index.d.ts",
|
|
11
11
|
"module": "./lib-mjs/index.js",
|