Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | 1x 1x 1x 275x 275x 275x 218x 218x 205x 70x 70x 70x 70x 70x 70x 70x 66x 70x 70x 9x 70x | import { updateCache } from '../../corePlugin/cache/updateCache';
import {
cloneModel,
createDomToModelContext,
createDomToModelContextWithConfig,
domToContentModel,
} from 'roosterjs-content-model-dom';
import type { CreateContentModel } from 'roosterjs-content-model-types';
/**
* @internal
* Create Content Model from DOM tree in this editor
* @param core The editor core object
* @param option The option to customize the behavior of DOM to Content Model conversion
* @param selectionOverride When passed, use this selection range instead of current selection in editor
*/
export const createContentModel: CreateContentModel = (core, option, selectionOverride) => {
// Flush all mutations if any, so that we can get an up-to-date Content Model
core.cache.textMutationObserver?.flushMutations();
const tryGetFromCache =
!option || (option.tryGetFromCache && typeof option.recalculateTableSize === 'undefined');
if (!selectionOverride && tryGetFromCache) {
const cachedModel = core.cache.cachedModel;
if (cachedModel) {
// When in shadow edit, use a cloned model so we won't pollute the cached one
return core.lifecycle.shadowEditFragment
? cloneModel(cachedModel, { includeCachedElement: true })
: cachedModel;
}
}
const selection =
selectionOverride == 'none'
? undefined
: selectionOverride || core.api.getDOMSelection(core) || undefined;
const saveIndex = !option && !selectionOverride;
const editorContext = core.api.createEditorContext(core, saveIndex);
editorContext.recalculateTableSize = option?.recalculateTableSize;
const settings = core.environment.domToModelSettings;
const domToModelContext = option
? createDomToModelContext(editorContext, settings.builtIn, settings.customized, option)
: createDomToModelContextWithConfig(settings.calculated, editorContext);
if (selection) {
domToModelContext.selection = selection;
}
const model = domToContentModel(core.logicalRoot, domToModelContext);
if (saveIndex) {
updateCache(core.cache, model, selection);
}
return model;
};
|