Socket
Socket
Sign inDemoInstall

roosterjs-content-model-core

Package Overview
Dependencies
11
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.20.0 to 0.21.0

lib-amd/constants/BulletListType.d.ts

52

lib-amd/coreApi/formatContentModel.js

@@ -27,4 +27,2 @@ define(["require", "exports", "tslib", "../constants/ChangeSource"], function (require, exports, tslib_1, ChangeSource_1) {

var writeBack = function () {
handleNewEntities(core, context);
handleDeletedEntities(core, context);
handleImages(core, context);

@@ -53,2 +51,13 @@ selection =

},
changedEntities: context.newEntities
.map(function (entity) { return ({
entity: entity,
operation: 'newEntity',
rawEvent: rawEvent,
}); })
.concat(context.deletedEntities.map(function (entry) { return ({
entity: entry.entity,
operation: entry.operation,
rawEvent: rawEvent,
}); })),
};

@@ -66,42 +75,5 @@ core.api.triggerEvent(core, eventData, true /*broadcast*/);

exports.formatContentModel = formatContentModel;
function handleNewEntities(core, context) {
// TODO: Ideally we can trigger NewEntity event here. But to be compatible with original editor code, we don't do it here for now.
// Once Content Model Editor can be standalone, we can change this behavior to move triggering NewEntity event code
// from EntityPlugin to here
if (core.lifecycle.isDarkMode) {
context.newEntities.forEach(function (entity) {
core.api.transformColor(core, entity.wrapper, true /*includeSelf*/, null /*callback*/, 0 /* LightToDark */);
});
}
}
// This is only used for compatibility with old editor
// TODO: Remove this map once we have standalone editor
var EntityOperationMap = {
overwrite: 6 /* Overwrite */,
removeFromEnd: 5 /* RemoveFromEnd */,
removeFromStart: 4 /* RemoveFromStart */,
};
function handleDeletedEntities(core, context) {
context.deletedEntities.forEach(function (_a) {
var _b = _a.entity, wrapper = _b.wrapper, _c = _b.entityFormat, id = _c.id, entityType = _c.entityType, isReadonly = _c.isReadonly, operation = _a.operation;
if (id && entityType) {
// TODO: Revisit this entity parameter for standalone editor, we may just directly pass ContentModelEntity object instead
var entity = {
id: id,
type: entityType,
isReadonly: !!isReadonly,
wrapper: wrapper,
};
core.api.triggerEvent(core, {
eventType: 15 /* EntityOperation */,
entity: entity,
operation: EntityOperationMap[operation],
rawEvent: context.rawEvent,
}, false /*broadcast*/);
}
});
}
function handleImages(core, context) {
if (context.newImages.length > 0) {
var viewport = core.getVisibleViewport();
var viewport = core.api.getVisibleViewport(core);
if (viewport) {

@@ -108,0 +80,0 @@ var left = viewport.left, right = viewport.right;

@@ -24,3 +24,3 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_dom_1) {

else if (selection.type == 'range') {
core.domEvent.selectionRange = selection.range;
core.selection.selectionRange = selection.range;
}

@@ -27,0 +27,0 @@ }

@@ -1,8 +0,8 @@

import type { SwitchShadowEdit } from 'roosterjs-editor-types';
import type { SwitchShadowEdit } from 'roosterjs-content-model-types';
/**
* @internal
* Switch the Shadow Edit mode of editor On/Off
* @param editorCore The EditorCore object
* @param editorCore The StandaloneEditorCore object
* @param isOn True to switch On, False to switch Off
*/
export declare const switchShadowEdit: SwitchShadowEdit;

@@ -1,2 +0,2 @@

define(["require", "exports", "../publicApi/selection/iterateSelections"], function (require, exports, iterateSelections_1) {
define(["require", "exports", "../publicApi/selection/iterateSelections", "roosterjs-content-model-dom"], function (require, exports, iterateSelections_1, roosterjs_content_model_dom_1) {
"use strict";

@@ -8,3 +8,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

* Switch the Shadow Edit mode of editor On/Off
* @param editorCore The EditorCore object
* @param editorCore The StandaloneEditorCore object
* @param isOn True to switch On, False to switch Off

@@ -21,10 +21,8 @@ */

var fragment = core.contentDiv.ownerDocument.createDocumentFragment();
var selectionPath = {
start: [],
end: [],
};
var clonedRoot = core.contentDiv.cloneNode(true /*deep*/);
(0, roosterjs_content_model_dom_1.moveChildNodes)(fragment, clonedRoot);
core.api.triggerEvent(core, {
eventType: 17 /* EnteredShadowEdit */,
fragment: fragment,
selectionPath: selectionPath,
selectionPath: null,
}, false /*broadcast*/);

@@ -36,3 +34,2 @@ // This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event

}
core.lifecycle.shadowEditSelectionPath = selectionPath;
core.lifecycle.shadowEditFragment = fragment;

@@ -42,3 +39,2 @@ }

core.lifecycle.shadowEditFragment = null;
core.lifecycle.shadowEditSelectionPath = null;
core.api.triggerEvent(core, {

@@ -45,0 +41,0 @@ eventType: 18 /* LeavingShadowEdit */,

@@ -1,53 +0,8 @@

import type { ContentModelCachePluginState } from 'roosterjs-content-model-types';
import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelCachePluginState, StandaloneEditorOptions } from 'roosterjs-content-model-types';
import type { PluginWithState } from 'roosterjs-editor-types';
/**
* ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary
*/
export declare class ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {
private state;
private editor;
/**
* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
*/
constructor(state: ContentModelCachePluginState);
/**
* Get name of this plugin
*/
getName(): string;
/**
* The first method that editor will call to a plugin when editor is initializing.
* It will pass in the editor instance, plugin should take this chance to save the
* editor reference so that it can call to any editor method or format API later.
* @param editor The editor object
*/
initialize(editor: IEditor): void;
/**
* The last method that editor will call to a plugin before it is disposed.
* Plugin can take this chance to clear the reference to editor. After this method is
* called, plugin should not call to any editor method since it will result in error.
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): ContentModelCachePluginState;
/**
* Core method for a plugin. Once an event happens in editor, editor will call this
* method of each plugin to handle the event as long as the event is not handled
* exclusively by another plugin.
* @param event The event to handle:
*/
onPluginEvent(event: PluginEvent): void;
private onNativeSelectionChange;
private invalidateCache;
private updateCachedModel;
private shouldClearCache;
}
/**
* @internal
* Create a new instance of ContentModelCachePlugin class.
* This is mostly for unit test
* @param state State of this plugin
* @param option The editor option
*/
export declare function createContentModelCachePlugin(state: ContentModelCachePluginState): ContentModelCachePlugin;
export declare function createContentModelCachePlugin(option: StandaloneEditorOptions): PluginWithState<ContentModelCachePluginState>;

@@ -1,5 +0,5 @@

define(["require", "exports", "./utils/areSameSelection", "../publicApi/domUtils/eventUtils"], function (require, exports, areSameSelection_1, eventUtils_1) {
define(["require", "exports", "./utils/areSameSelection", "./utils/contentModelDomIndexer", "../publicApi/domUtils/eventUtils"], function (require, exports, areSameSelection_1, contentModelDomIndexer_1, eventUtils_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createContentModelCachePlugin = exports.ContentModelCachePlugin = void 0;
exports.createContentModelCachePlugin = void 0;
/**

@@ -11,7 +11,6 @@ * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary

* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
* @param option The editor option
*/
function ContentModelCachePlugin(state) {
function ContentModelCachePlugin(option) {
var _this = this;
this.state = state;
this.editor = null;

@@ -24,3 +23,5 @@ this.onNativeSelectionChange = function () {

};
// TODO: Remove tempState parameter once we have standalone Content Model editor
this.state = {
domIndexer: option.cacheModel ? contentModelDomIndexer_1.contentModelDomIndexer : undefined,
};
}

@@ -159,11 +160,9 @@ /**

}());
exports.ContentModelCachePlugin = ContentModelCachePlugin;
/**
* @internal
* Create a new instance of ContentModelCachePlugin class.
* This is mostly for unit test
* @param state State of this plugin
* @param option The editor option
*/
function createContentModelCachePlugin(state) {
return new ContentModelCachePlugin(state);
function createContentModelCachePlugin(option) {
return new ContentModelCachePlugin(option);
}

@@ -170,0 +169,0 @@ exports.createContentModelCachePlugin = createContentModelCachePlugin;

@@ -1,37 +0,4 @@

import type { OnNodeCreated } from 'roosterjs-content-model-types';
import type { CopyPastePluginState, IEditor, PluginWithState } from 'roosterjs-editor-types';
import type { OnNodeCreated, StandaloneEditorOptions } from 'roosterjs-content-model-types';
import type { CopyPastePluginState, PluginWithState } from 'roosterjs-editor-types';
/**
* Copy and paste plugin for handling onCopy and onPaste event
*/
export declare class ContentModelCopyPastePlugin implements PluginWithState<CopyPastePluginState> {
private state;
private editor;
private disposer;
/**
* Construct a new instance of CopyPastePlugin
* @param options The editor options
*/
constructor(state: CopyPastePluginState);
/**
* Get a friendly name of this plugin
*/
getName(): string;
/**
* Initialize this plugin. This should only be called from Editor
* @param editor Editor instance
*/
initialize(editor: IEditor): void;
/**
* Dispose this plugin
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): CopyPastePluginState;
private onCutCopy;
private onPaste;
private getTempDiv;
}
/**
* @internal

@@ -44,4 +11,4 @@ * Exported only for unit testing

* Create a new instance of ContentModelCopyPastePlugin
* @param state The plugin state object
* @param option The editor option
*/
export declare function createContentModelCopyPastePlugin(state: CopyPastePluginState): ContentModelCopyPastePlugin;
export declare function createContentModelCopyPastePlugin(option: StandaloneEditorOptions): PluginWithState<CopyPastePluginState>;
define(["require", "exports", "tslib", "./utils/addRangeToSelection", "../constants/ChangeSource", "../publicApi/model/cloneModel", "../publicApi/selection/deleteSelection", "roosterjs-editor-dom", "../publicApi/selection/iterateSelections", "../publicApi/model/paste", "roosterjs-content-model-dom"], function (require, exports, tslib_1, addRangeToSelection_1, ChangeSource_1, cloneModel_1, deleteSelection_1, roosterjs_editor_dom_1, iterateSelections_1, paste_1, roosterjs_content_model_dom_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createContentModelCopyPastePlugin = exports.onNodeCreated = exports.ContentModelCopyPastePlugin = void 0;
exports.createContentModelCopyPastePlugin = exports.onNodeCreated = void 0;
/**

@@ -11,7 +11,6 @@ * Copy and paste plugin for handling onCopy and onPaste event

* Construct a new instance of CopyPastePlugin
* @param options The editor options
* @param option The editor option
*/
function ContentModelCopyPastePlugin(state) {
function ContentModelCopyPastePlugin(option) {
var _this = this;
this.state = state;
this.editor = null;

@@ -35,2 +34,5 @@ this.disposer = null;

};
this.state = {
allowedCustomPasteType: option.allowedCustomPasteType || [],
};
}

@@ -174,3 +176,2 @@ /**

}());
exports.ContentModelCopyPastePlugin = ContentModelCopyPastePlugin;
function cleanUpAndRestoreSelection(tempDiv) {

@@ -222,6 +223,6 @@ tempDiv.style.backgroundColor = '';

* Create a new instance of ContentModelCopyPastePlugin
* @param state The plugin state object
* @param option The editor option
*/
function createContentModelCopyPastePlugin(state) {
return new ContentModelCopyPastePlugin(state);
function createContentModelCopyPastePlugin(option) {
return new ContentModelCopyPastePlugin(option);
}

@@ -228,0 +229,0 @@ exports.createContentModelCopyPastePlugin = createContentModelCopyPastePlugin;

@@ -1,59 +0,8 @@

import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelFormatPluginState } from 'roosterjs-content-model-types';
import type { PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelFormatPluginState, StandaloneEditorOptions } from 'roosterjs-content-model-types';
/**
* ContentModelFormat plugins helps editor to do formatting on top of content model.
* This includes:
* 1. Handle pending format changes when selection is collapsed
*/
export declare class ContentModelFormatPlugin implements PluginWithState<ContentModelFormatPluginState> {
private state;
private editor;
private hasDefaultFormat;
/**
* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
*/
constructor(state: ContentModelFormatPluginState);
/**
* Get name of this plugin
*/
getName(): string;
/**
* The first method that editor will call to a plugin when editor is initializing.
* It will pass in the editor instance, plugin should take this chance to save the
* editor reference so that it can call to any editor method or format API later.
* @param editor The editor object
*/
initialize(editor: IEditor): void;
/**
* The last method that editor will call to a plugin before it is disposed.
* Plugin can take this chance to clear the reference to editor. After this method is
* called, plugin should not call to any editor method since it will result in error.
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): ContentModelFormatPluginState;
/**
* Core method for a plugin. Once an event happens in editor, editor will call this
* method of each plugin to handle the event as long as the event is not handled
* exclusively by another plugin.
* @param event The event to handle:
*/
onPluginEvent(event: PluginEvent): void;
private checkAndApplyPendingFormat;
private clearPendingFormat;
/**
* @internal
* Check if this editor can apply pending format
* @param editor The editor to get format from
*/
private canApplyPendingFormat;
}
/**
* @internal
* Create a new instance of ContentModelFormatPlugin.
* This is mostly for unit test
* @param option The editor option
*/
export declare function createContentModelFormatPlugin(state: ContentModelFormatPluginState): ContentModelFormatPlugin;
export declare function createContentModelFormatPlugin(option: StandaloneEditorOptions): PluginWithState<ContentModelFormatPluginState>;

@@ -1,5 +0,5 @@

define(["require", "exports", "./utils/applyDefaultFormat", "./utils/applyPendingFormat", "roosterjs-content-model-dom", "../publicApi/domUtils/eventUtils"], function (require, exports, applyDefaultFormat_1, applyPendingFormat_1, roosterjs_content_model_dom_1, eventUtils_1) {
define(["require", "exports", "tslib", "./utils/applyDefaultFormat", "./utils/applyPendingFormat", "roosterjs-content-model-dom", "../publicApi/domUtils/eventUtils"], function (require, exports, tslib_1, applyDefaultFormat_1, applyPendingFormat_1, roosterjs_content_model_dom_1, eventUtils_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createContentModelFormatPlugin = exports.ContentModelFormatPlugin = void 0;
exports.createContentModelFormatPlugin = void 0;
// During IME input, KeyDown event will have "Process" as key

@@ -25,9 +25,11 @@ var ProcessKey = 'Process';

* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
* @param option The editor option
*/
function ContentModelFormatPlugin(state) {
this.state = state;
function ContentModelFormatPlugin(option) {
this.editor = null;
this.hasDefaultFormat = false;
// TODO: Remove tempState parameter once we have standalone Content Model editor
this.state = {
defaultFormat: (0, tslib_1.__assign)({}, option.defaultSegmentFormat),
pendingFormat: null,
};
}

@@ -135,10 +137,9 @@ /**

}());
exports.ContentModelFormatPlugin = ContentModelFormatPlugin;
/**
* @internal
* Create a new instance of ContentModelFormatPlugin.
* This is mostly for unit test
* @param option The editor option
*/
function createContentModelFormatPlugin(state) {
return new ContentModelFormatPlugin(state);
function createContentModelFormatPlugin(option) {
return new ContentModelFormatPlugin(option);
}

@@ -145,0 +146,0 @@ exports.createContentModelFormatPlugin = createContentModelFormatPlugin;

@@ -6,2 +6,4 @@ export { CachedElementHandler, CloneModelOptions, cloneModel } from './publicApi/model/cloneModel';

export { getClosestAncestorBlockGroupIndex, TypeOfBlockGroup, } from './publicApi/model/getClosestAncestorBlockGroupIndex';
export { isBold } from './publicApi/model/isBold';
export { createModelFromHtml } from './publicApi/model/createModelFromHtml';
export { iterateSelections, IterateSelectionsCallback, IterateSelectionsOption, } from './publicApi/selection/iterateSelections';

@@ -24,8 +26,6 @@ export { getSelectionRootNode } from './publicApi/selection/getSelectionRootNode';

export { updateListMetadata } from './metadata/updateListMetadata';
export { promoteToContentModelEditorCore } from './editor/promoteToContentModelEditorCore';
export { createContentModelEditorCore } from './editor/createContentModelEditorCore';
export { ChangeSource } from './constants/ChangeSource';
export { ContentModelCachePlugin } from './corePlugin/ContentModelCachePlugin';
export { ContentModelCopyPastePlugin } from './corePlugin/ContentModelCopyPastePlugin';
export { ContentModelFormatPlugin } from './corePlugin/ContentModelFormatPlugin';
export { ContentModelTypeInContainerPlugin } from './corePlugin/ContentModelTypeInContainerPlugin';
export { BulletListType } from './constants/BulletListType';
export { NumberingListType } from './constants/NumberingListType';
export { TableBorderFormat } from './constants/TableBorderFormat';
export { createStandaloneEditorCore } from './editor/createStandaloneEditorCore';

@@ -1,5 +0,5 @@

define(["require", "exports", "./publicApi/model/cloneModel", "./publicApi/model/paste", "./publicApi/model/mergeModel", "./publicApi/model/isBlockGroupOfType", "./publicApi/model/getClosestAncestorBlockGroupIndex", "./publicApi/selection/iterateSelections", "./publicApi/selection/getSelectionRootNode", "./publicApi/selection/deleteSelection", "./publicApi/selection/deleteSegment", "./publicApi/selection/deleteBlock", "./publicApi/selection/collectSelections", "./publicApi/selection/setSelection", "./publicApi/table/applyTableFormat", "./publicApi/table/normalizeTable", "./publicApi/table/setTableCellBackgroundColor", "./publicApi/domUtils/eventUtils", "./publicApi/domUtils/borderValues", "./publicApi/domUtils/stringUtil", "./metadata/updateImageMetadata", "./metadata/updateTableCellMetadata", "./metadata/updateTableMetadata", "./metadata/updateListMetadata", "./editor/promoteToContentModelEditorCore", "./editor/createContentModelEditorCore", "./constants/ChangeSource", "./corePlugin/ContentModelCachePlugin", "./corePlugin/ContentModelCopyPastePlugin", "./corePlugin/ContentModelFormatPlugin", "./corePlugin/ContentModelTypeInContainerPlugin"], function (require, exports, cloneModel_1, paste_1, mergeModel_1, isBlockGroupOfType_1, getClosestAncestorBlockGroupIndex_1, iterateSelections_1, getSelectionRootNode_1, deleteSelection_1, deleteSegment_1, deleteBlock_1, collectSelections_1, setSelection_1, applyTableFormat_1, normalizeTable_1, setTableCellBackgroundColor_1, eventUtils_1, borderValues_1, stringUtil_1, updateImageMetadata_1, updateTableCellMetadata_1, updateTableMetadata_1, updateListMetadata_1, promoteToContentModelEditorCore_1, createContentModelEditorCore_1, ChangeSource_1, ContentModelCachePlugin_1, ContentModelCopyPastePlugin_1, ContentModelFormatPlugin_1, ContentModelTypeInContainerPlugin_1) {
define(["require", "exports", "./publicApi/model/cloneModel", "./publicApi/model/paste", "./publicApi/model/mergeModel", "./publicApi/model/isBlockGroupOfType", "./publicApi/model/getClosestAncestorBlockGroupIndex", "./publicApi/model/isBold", "./publicApi/model/createModelFromHtml", "./publicApi/selection/iterateSelections", "./publicApi/selection/getSelectionRootNode", "./publicApi/selection/deleteSelection", "./publicApi/selection/deleteSegment", "./publicApi/selection/deleteBlock", "./publicApi/selection/collectSelections", "./publicApi/selection/setSelection", "./publicApi/table/applyTableFormat", "./publicApi/table/normalizeTable", "./publicApi/table/setTableCellBackgroundColor", "./publicApi/domUtils/eventUtils", "./publicApi/domUtils/borderValues", "./publicApi/domUtils/stringUtil", "./metadata/updateImageMetadata", "./metadata/updateTableCellMetadata", "./metadata/updateTableMetadata", "./metadata/updateListMetadata", "./constants/ChangeSource", "./constants/BulletListType", "./constants/NumberingListType", "./constants/TableBorderFormat", "./editor/createStandaloneEditorCore"], function (require, exports, cloneModel_1, paste_1, mergeModel_1, isBlockGroupOfType_1, getClosestAncestorBlockGroupIndex_1, isBold_1, createModelFromHtml_1, iterateSelections_1, getSelectionRootNode_1, deleteSelection_1, deleteSegment_1, deleteBlock_1, collectSelections_1, setSelection_1, applyTableFormat_1, normalizeTable_1, setTableCellBackgroundColor_1, eventUtils_1, borderValues_1, stringUtil_1, updateImageMetadata_1, updateTableCellMetadata_1, updateTableMetadata_1, updateListMetadata_1, ChangeSource_1, BulletListType_1, NumberingListType_1, TableBorderFormat_1, createStandaloneEditorCore_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentModelTypeInContainerPlugin = exports.ContentModelFormatPlugin = exports.ContentModelCopyPastePlugin = exports.ContentModelCachePlugin = exports.ChangeSource = exports.createContentModelEditorCore = exports.promoteToContentModelEditorCore = exports.updateListMetadata = exports.updateTableMetadata = exports.updateTableCellMetadata = exports.updateImageMetadata = exports.normalizeText = exports.isSpace = exports.isPunctuation = exports.extractBorderValues = exports.combineBorderValue = exports.isModifierKey = exports.isCharacterValue = exports.setTableCellBackgroundColor = exports.normalizeTable = exports.applyTableFormat = exports.setSelection = exports.getSelectedSegmentsAndParagraphs = exports.getSelectedSegments = exports.getSelectedParagraphs = exports.getOperationalBlocks = exports.getFirstSelectedTable = exports.getFirstSelectedListItem = exports.deleteBlock = exports.deleteSegment = exports.deleteSelection = exports.getSelectionRootNode = exports.iterateSelections = exports.getClosestAncestorBlockGroupIndex = exports.isBlockGroupOfType = exports.mergeModel = exports.paste = exports.cloneModel = void 0;
exports.createStandaloneEditorCore = exports.TableBorderFormat = exports.NumberingListType = exports.BulletListType = exports.ChangeSource = exports.updateListMetadata = exports.updateTableMetadata = exports.updateTableCellMetadata = exports.updateImageMetadata = exports.normalizeText = exports.isSpace = exports.isPunctuation = exports.extractBorderValues = exports.combineBorderValue = exports.isModifierKey = exports.isCharacterValue = exports.setTableCellBackgroundColor = exports.normalizeTable = exports.applyTableFormat = exports.setSelection = exports.getSelectedSegmentsAndParagraphs = exports.getSelectedSegments = exports.getSelectedParagraphs = exports.getOperationalBlocks = exports.getFirstSelectedTable = exports.getFirstSelectedListItem = exports.deleteBlock = exports.deleteSegment = exports.deleteSelection = exports.getSelectionRootNode = exports.iterateSelections = exports.createModelFromHtml = exports.isBold = exports.getClosestAncestorBlockGroupIndex = exports.isBlockGroupOfType = exports.mergeModel = exports.paste = exports.cloneModel = void 0;
Object.defineProperty(exports, "cloneModel", { enumerable: true, get: function () { return cloneModel_1.cloneModel; } });

@@ -10,2 +10,4 @@ Object.defineProperty(exports, "paste", { enumerable: true, get: function () { return paste_1.paste; } });

Object.defineProperty(exports, "getClosestAncestorBlockGroupIndex", { enumerable: true, get: function () { return getClosestAncestorBlockGroupIndex_1.getClosestAncestorBlockGroupIndex; } });
Object.defineProperty(exports, "isBold", { enumerable: true, get: function () { return isBold_1.isBold; } });
Object.defineProperty(exports, "createModelFromHtml", { enumerable: true, get: function () { return createModelFromHtml_1.createModelFromHtml; } });
Object.defineProperty(exports, "iterateSelections", { enumerable: true, get: function () { return iterateSelections_1.iterateSelections; } });

@@ -37,10 +39,8 @@ Object.defineProperty(exports, "getSelectionRootNode", { enumerable: true, get: function () { return getSelectionRootNode_1.getSelectionRootNode; } });

Object.defineProperty(exports, "updateListMetadata", { enumerable: true, get: function () { return updateListMetadata_1.updateListMetadata; } });
Object.defineProperty(exports, "promoteToContentModelEditorCore", { enumerable: true, get: function () { return promoteToContentModelEditorCore_1.promoteToContentModelEditorCore; } });
Object.defineProperty(exports, "createContentModelEditorCore", { enumerable: true, get: function () { return createContentModelEditorCore_1.createContentModelEditorCore; } });
Object.defineProperty(exports, "ChangeSource", { enumerable: true, get: function () { return ChangeSource_1.ChangeSource; } });
Object.defineProperty(exports, "ContentModelCachePlugin", { enumerable: true, get: function () { return ContentModelCachePlugin_1.ContentModelCachePlugin; } });
Object.defineProperty(exports, "ContentModelCopyPastePlugin", { enumerable: true, get: function () { return ContentModelCopyPastePlugin_1.ContentModelCopyPastePlugin; } });
Object.defineProperty(exports, "ContentModelFormatPlugin", { enumerable: true, get: function () { return ContentModelFormatPlugin_1.ContentModelFormatPlugin; } });
Object.defineProperty(exports, "ContentModelTypeInContainerPlugin", { enumerable: true, get: function () { return ContentModelTypeInContainerPlugin_1.ContentModelTypeInContainerPlugin; } });
Object.defineProperty(exports, "BulletListType", { enumerable: true, get: function () { return BulletListType_1.BulletListType; } });
Object.defineProperty(exports, "NumberingListType", { enumerable: true, get: function () { return NumberingListType_1.NumberingListType; } });
Object.defineProperty(exports, "TableBorderFormat", { enumerable: true, get: function () { return TableBorderFormat_1.TableBorderFormat; } });
Object.defineProperty(exports, "createStandaloneEditorCore", { enumerable: true, get: function () { return createStandaloneEditorCore_1.createStandaloneEditorCore; } });
});
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

define(["require", "exports", "tslib", "roosterjs-content-model-types", "./definitionCreators", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_types_1, definitionCreators_1, roosterjs_content_model_dom_1) {
define(["require", "exports", "tslib", "../constants/BulletListType", "./definitionCreators", "roosterjs-content-model-dom", "../constants/NumberingListType"], function (require, exports, tslib_1, BulletListType_1, definitionCreators_1, roosterjs_content_model_dom_1, NumberingListType_1) {
"use strict";

@@ -26,33 +26,33 @@ var _a, _b;

var OrderedMap = (_a = {},
_a[roosterjs_content_model_types_1.NumberingListType.Decimal] = 'decimal',
_a[roosterjs_content_model_types_1.NumberingListType.DecimalDash] = '"${Number}- "',
_a[roosterjs_content_model_types_1.NumberingListType.DecimalParenthesis] = '"${Number}) "',
_a[roosterjs_content_model_types_1.NumberingListType.DecimalDoubleParenthesis] = '"(${Number}) "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerAlpha] = 'lower-alpha',
_a[roosterjs_content_model_types_1.NumberingListType.LowerAlphaDash] = '"${LowerAlpha}- "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerAlphaParenthesis] = '"${LowerAlpha}) "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerAlphaDoubleParenthesis] = '"(${LowerAlpha}) "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperAlpha] = 'upper-alpha',
_a[roosterjs_content_model_types_1.NumberingListType.UpperAlphaDash] = '"${UpperAlpha}- "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperAlphaParenthesis] = '"${UpperAlpha}) "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperAlphaDoubleParenthesis] = '"(${UpperAlpha}) "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerRoman] = 'lower-roman',
_a[roosterjs_content_model_types_1.NumberingListType.LowerRomanDash] = '"${LowerRoman}- "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerRomanParenthesis] = '"${LowerRoman}) "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerRomanDoubleParenthesis] = '"(${LowerRoman}) "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperRoman] = 'upper-roman',
_a[roosterjs_content_model_types_1.NumberingListType.UpperRomanDash] = '"${UpperRoman}- "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperRomanParenthesis] = '"${UpperRoman}) "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperRomanDoubleParenthesis] = '"(${UpperRoman}) "',
_a[NumberingListType_1.NumberingListType.Decimal] = 'decimal',
_a[NumberingListType_1.NumberingListType.DecimalDash] = '"${Number}- "',
_a[NumberingListType_1.NumberingListType.DecimalParenthesis] = '"${Number}) "',
_a[NumberingListType_1.NumberingListType.DecimalDoubleParenthesis] = '"(${Number}) "',
_a[NumberingListType_1.NumberingListType.LowerAlpha] = 'lower-alpha',
_a[NumberingListType_1.NumberingListType.LowerAlphaDash] = '"${LowerAlpha}- "',
_a[NumberingListType_1.NumberingListType.LowerAlphaParenthesis] = '"${LowerAlpha}) "',
_a[NumberingListType_1.NumberingListType.LowerAlphaDoubleParenthesis] = '"(${LowerAlpha}) "',
_a[NumberingListType_1.NumberingListType.UpperAlpha] = 'upper-alpha',
_a[NumberingListType_1.NumberingListType.UpperAlphaDash] = '"${UpperAlpha}- "',
_a[NumberingListType_1.NumberingListType.UpperAlphaParenthesis] = '"${UpperAlpha}) "',
_a[NumberingListType_1.NumberingListType.UpperAlphaDoubleParenthesis] = '"(${UpperAlpha}) "',
_a[NumberingListType_1.NumberingListType.LowerRoman] = 'lower-roman',
_a[NumberingListType_1.NumberingListType.LowerRomanDash] = '"${LowerRoman}- "',
_a[NumberingListType_1.NumberingListType.LowerRomanParenthesis] = '"${LowerRoman}) "',
_a[NumberingListType_1.NumberingListType.LowerRomanDoubleParenthesis] = '"(${LowerRoman}) "',
_a[NumberingListType_1.NumberingListType.UpperRoman] = 'upper-roman',
_a[NumberingListType_1.NumberingListType.UpperRomanDash] = '"${UpperRoman}- "',
_a[NumberingListType_1.NumberingListType.UpperRomanParenthesis] = '"${UpperRoman}) "',
_a[NumberingListType_1.NumberingListType.UpperRomanDoubleParenthesis] = '"(${UpperRoman}) "',
_a);
var UnorderedMap = (_b = {},
_b[roosterjs_content_model_types_1.BulletListType.Disc] = 'disc',
_b[roosterjs_content_model_types_1.BulletListType.Square] = '"∎ "',
_b[roosterjs_content_model_types_1.BulletListType.Circle] = 'circle',
_b[roosterjs_content_model_types_1.BulletListType.Dash] = '"- "',
_b[roosterjs_content_model_types_1.BulletListType.LongArrow] = '"➔ "',
_b[roosterjs_content_model_types_1.BulletListType.DoubleLongArrow] = '"➔ "',
_b[roosterjs_content_model_types_1.BulletListType.ShortArrow] = '"➢ "',
_b[roosterjs_content_model_types_1.BulletListType.UnfilledArrow] = '"➪ "',
_b[roosterjs_content_model_types_1.BulletListType.Hyphen] = '"— "',
_b[BulletListType_1.BulletListType.Disc] = 'disc',
_b[BulletListType_1.BulletListType.Square] = '"∎ "',
_b[BulletListType_1.BulletListType.Circle] = 'circle',
_b[BulletListType_1.BulletListType.Dash] = '"- "',
_b[BulletListType_1.BulletListType.LongArrow] = '"➔ "',
_b[BulletListType_1.BulletListType.DoubleLongArrow] = '"➔ "',
_b[BulletListType_1.BulletListType.ShortArrow] = '"➢ "',
_b[BulletListType_1.BulletListType.UnfilledArrow] = '"➪ "',
_b[BulletListType_1.BulletListType.Hyphen] = '"— "',
_b);

@@ -108,4 +108,4 @@ function getOrderedListStyleValue(template, listNumber) {

var listMetadataDefinition = (0, definitionCreators_1.createObjectDefinition)({
orderedStyleType: (0, definitionCreators_1.createNumberDefinition)(true /** isOptional */, undefined /** value **/, roosterjs_content_model_types_1.NumberingListType.Min, roosterjs_content_model_types_1.NumberingListType.Max),
unorderedStyleType: (0, definitionCreators_1.createNumberDefinition)(true /** isOptional */, undefined /** value **/, roosterjs_content_model_types_1.BulletListType.Min, roosterjs_content_model_types_1.BulletListType.Max),
orderedStyleType: (0, definitionCreators_1.createNumberDefinition)(true /** isOptional */, undefined /** value **/, NumberingListType_1.NumberingListType.Min, NumberingListType_1.NumberingListType.Max),
unorderedStyleType: (0, definitionCreators_1.createNumberDefinition)(true /** isOptional */, undefined /** value **/, BulletListType_1.BulletListType.Min, BulletListType_1.BulletListType.Max),
}, true /** isOptional */, true /** allowNull */);

@@ -112,0 +112,0 @@ function shouldApplyToItem(listStyleType) {

@@ -1,2 +0,2 @@

define(["require", "exports", "roosterjs-content-model-types", "roosterjs-content-model-dom", "./definitionCreators"], function (require, exports, roosterjs_content_model_types_1, roosterjs_content_model_dom_1, definitionCreators_1) {
define(["require", "exports", "../constants/TableBorderFormat", "roosterjs-content-model-dom", "./definitionCreators"], function (require, exports, TableBorderFormat_1, roosterjs_content_model_dom_1, definitionCreators_1) {
"use strict";

@@ -18,3 +18,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

bgColorOdd: NullStringDefinition,
tableBorderFormat: (0, definitionCreators_1.createNumberDefinition)(false /** isOptional */, undefined /* value */, roosterjs_content_model_types_1.TableBorderFormat.DEFAULT /* first table border format, TODO: Use Min/Max to specify valid values */, roosterjs_content_model_types_1.TableBorderFormat.CLEAR /* last table border format, , TODO: Use Min/Max to specify valid values */),
tableBorderFormat: (0, definitionCreators_1.createNumberDefinition)(false /** isOptional */, undefined /* value */, TableBorderFormat_1.TableBorderFormat.Min /* first table border format */, TableBorderFormat_1.TableBorderFormat.Max /* last table border format */),
verticalAlign: NullStringDefinition,

@@ -21,0 +21,0 @@ }, false /* isOptional */, true /** allowNull */);

@@ -55,3 +55,3 @@ define(["require", "exports", "tslib", "../../constants/ChangeSource", "../selection/collectSelections", "./mergeModel", "roosterjs-content-model-dom", "roosterjs-editor-dom"], function (require, exports, tslib_1, ChangeSource_1, collectSelections_1, mergeModel_1, roosterjs_content_model_dom_1, roosterjs_editor_dom_1) {

if (originalFormat) {
context.newPendingFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, EmptySegmentFormat), originalFormat); // Use empty format as initial value to clear any other format inherits from pasted content
context.newPendingFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, EmptySegmentFormat), model.format), originalFormat); // Use empty format as initial value to clear any other format inherits from pasted content
}

@@ -92,3 +92,5 @@ return true;

function createBeforePasteEventData(editor, clipboardData, pasteType) {
var _a;
var options = (0, roosterjs_editor_dom_1.createDefaultHtmlSanitizerOptions)();
(_a = options.additionalAllowedCssClasses).push.apply(_a, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(roosterjs_content_model_dom_1.AllowedEntityClasses), false));
// Remove "caret-color" style generated by Safari to make sure caret shows in right color after paste

@@ -95,0 +97,0 @@ options.cssStyleCallbacks['caret-color'] = function () { return false; };

@@ -1,2 +0,2 @@

define(["require", "exports", "tslib", "roosterjs-content-model-dom", "../domUtils/borderValues", "./setTableCellBackgroundColor", "roosterjs-content-model-types", "../../metadata/updateTableCellMetadata", "../../metadata/updateTableMetadata"], function (require, exports, tslib_1, roosterjs_content_model_dom_1, borderValues_1, setTableCellBackgroundColor_1, roosterjs_content_model_types_1, updateTableCellMetadata_1, updateTableMetadata_1) {
define(["require", "exports", "tslib", "roosterjs-content-model-dom", "../domUtils/borderValues", "./setTableCellBackgroundColor", "../../constants/TableBorderFormat", "../../metadata/updateTableCellMetadata", "../../metadata/updateTableMetadata"], function (require, exports, tslib_1, roosterjs_content_model_dom_1, borderValues_1, setTableCellBackgroundColor_1, TableBorderFormat_1, updateTableCellMetadata_1, updateTableMetadata_1) {
"use strict";

@@ -17,3 +17,3 @@ var _a;

headerRowColor: '#ABABAB',
tableBorderFormat: roosterjs_content_model_types_1.TableBorderFormat.DEFAULT,
tableBorderFormat: TableBorderFormat_1.TableBorderFormat.Default,
verticalAlign: null,

@@ -80,4 +80,4 @@ };

var BorderFormatters = (_a = {},
_a[roosterjs_content_model_types_1.TableBorderFormat.DEFAULT] = function (_) { return [false, false, false, false]; },
_a[roosterjs_content_model_types_1.TableBorderFormat.LIST_WITH_SIDE_BORDERS] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.Default] = function (_) { return [false, false, false, false]; },
_a[TableBorderFormat_1.TableBorderFormat.ListWithSideBorders] = function (_a) {
var lastColumn = _a.lastColumn, firstColumn = _a.firstColumn;

@@ -91,3 +91,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.FIRST_COLUMN_HEADER_EXTERNAL] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.FirstColumnHeaderExternal] = function (_a) {
var firstColumn = _a.firstColumn, firstRow = _a.firstRow, lastColumn = _a.lastColumn, lastRow = _a.lastRow;

@@ -101,3 +101,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.NO_HEADER_BORDERS] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.NoHeaderBorders] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn, lastColumn = _a.lastColumn;

@@ -111,3 +111,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.NO_SIDE_BORDERS] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.NoSideBorders] = function (_a) {
var firstColumn = _a.firstColumn, lastColumn = _a.lastColumn;

@@ -121,3 +121,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.ESPECIAL_TYPE_1] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.EspecialType1] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn;

@@ -131,3 +131,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.ESPECIAL_TYPE_2] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.EspecialType2] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn;

@@ -141,3 +141,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.ESPECIAL_TYPE_3] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.EspecialType3] = function (_a) {
var firstColumn = _a.firstColumn, firstRow = _a.firstRow;

@@ -151,3 +151,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.CLEAR] = function () { return [true, true, true, true]; },
_a[TableBorderFormat_1.TableBorderFormat.Clear] = function () { return [true, true, true, true]; },
_a);

@@ -161,5 +161,7 @@ /*

row.cells.forEach(function (cell, colIndex) {
var _a;
// Format Borders
if (!metaOverrides.borderOverrides[rowIndex][colIndex]) {
var transparentBorderMatrix = BorderFormatters[format.tableBorderFormat]({
if (!metaOverrides.borderOverrides[rowIndex][colIndex] &&
typeof format.tableBorderFormat == 'number') {
var transparentBorderMatrix = (_a = BorderFormatters[format.tableBorderFormat]) === null || _a === void 0 ? void 0 : _a.call(BorderFormatters, {
firstRow: rowIndex === 0,

@@ -176,3 +178,3 @@ lastRow: rowIndex === rows.length - 1,

];
transparentBorderMatrix.forEach(function (alwaysUseTransparent, i) {
transparentBorderMatrix === null || transparentBorderMatrix === void 0 ? void 0 : transparentBorderMatrix.forEach(function (alwaysUseTransparent, i) {
var borderColor = (!alwaysUseTransparent && formatColor_1[i]) || '';

@@ -179,0 +181,0 @@ cell.format[roosterjs_content_model_dom_1.BorderKeys[i]] = (0, borderValues_1.combineBorderValue)({

@@ -39,11 +39,4 @@ define(["require", "exports", "tslib", "../../metadata/updateTableCellMetadata"], function (require, exports, tslib_1, updateTableCellMetadata_1) {

}
if (applyToSegments && cell.format.textColor) {
cell.blocks.forEach(function (block) {
if (block.blockType == 'Paragraph') {
block.segmentFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, block.segmentFormat), { textColor: cell.format.textColor });
block.segments.forEach(function (segment) {
segment.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, segment.format), { textColor: cell.format.textColor });
});
}
});
if (applyToSegments) {
setAdaptiveCellColor(cell);
}

@@ -54,2 +47,5 @@ }

delete cell.format.textColor;
if (applyToSegments) {
removeAdaptiveCellColor(cell);
}
}

@@ -59,2 +55,53 @@ delete cell.cachedElement;

exports.setTableCellBackgroundColor = setTableCellBackgroundColor;
function removeAdaptiveCellColor(cell) {
cell.blocks.forEach(function (block) {
var _a, _b;
if (block.blockType == 'Paragraph') {
if (((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor) &&
shouldRemoveColor((_b = block.segmentFormat) === null || _b === void 0 ? void 0 : _b.textColor, cell.format.backgroundColor || '')) {
delete block.segmentFormat.textColor;
}
block.segments.forEach(function (segment) {
if (segment.format.textColor &&
shouldRemoveColor(segment.format.textColor, cell.format.backgroundColor || '')) {
delete segment.format.textColor;
}
});
}
});
}
function setAdaptiveCellColor(cell) {
if (cell.format.textColor) {
cell.blocks.forEach(function (block) {
var _a;
if (block.blockType == 'Paragraph') {
if (!((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor)) {
block.segmentFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, block.segmentFormat), { textColor: cell.format.textColor });
}
block.segments.forEach(function (segment) {
var _a;
if (!((_a = segment.format) === null || _a === void 0 ? void 0 : _a.textColor)) {
segment.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, segment.format), { textColor: cell.format.textColor });
}
});
}
});
}
}
/**
* If the cell background color is too dark or too bright, and the text color is white or black, we should remove the text color
* @param textColor the segment or block text color
* @param cellBackgroundColor the cell background color
* @returns
*/
function shouldRemoveColor(textColor, cellBackgroundColor) {
var lightness = calculateLightness(cellBackgroundColor);
if (([White, 'rgb(255,255,255)'].indexOf(textColor) > -1 &&
(lightness > BRIGHT_COLORS_LIGHTNESS || cellBackgroundColor == '')) ||
([Black, 'rgb(0,0,0)'].indexOf(textColor) > -1 &&
(lightness < DARK_COLORS_LIGHTNESS || cellBackgroundColor == ''))) {
return true;
}
return false;
}
function calculateLightness(color) {

@@ -61,0 +108,0 @@ var colorValues = parseColor(color);

@@ -25,4 +25,2 @@ import { __assign } from "tslib";

var writeBack = function () {
handleNewEntities(core, context);
handleDeletedEntities(core, context);
handleImages(core, context);

@@ -51,2 +49,13 @@ selection =

},
changedEntities: context.newEntities
.map(function (entity) { return ({
entity: entity,
operation: 'newEntity',
rawEvent: rawEvent,
}); })
.concat(context.deletedEntities.map(function (entry) { return ({
entity: entry.entity,
operation: entry.operation,
rawEvent: rawEvent,
}); })),
};

@@ -63,42 +72,5 @@ core.api.triggerEvent(core, eventData, true /*broadcast*/);

};
function handleNewEntities(core, context) {
// TODO: Ideally we can trigger NewEntity event here. But to be compatible with original editor code, we don't do it here for now.
// Once Content Model Editor can be standalone, we can change this behavior to move triggering NewEntity event code
// from EntityPlugin to here
if (core.lifecycle.isDarkMode) {
context.newEntities.forEach(function (entity) {
core.api.transformColor(core, entity.wrapper, true /*includeSelf*/, null /*callback*/, 0 /* LightToDark */);
});
}
}
// This is only used for compatibility with old editor
// TODO: Remove this map once we have standalone editor
var EntityOperationMap = {
overwrite: 6 /* Overwrite */,
removeFromEnd: 5 /* RemoveFromEnd */,
removeFromStart: 4 /* RemoveFromStart */,
};
function handleDeletedEntities(core, context) {
context.deletedEntities.forEach(function (_a) {
var _b = _a.entity, wrapper = _b.wrapper, _c = _b.entityFormat, id = _c.id, entityType = _c.entityType, isReadonly = _c.isReadonly, operation = _a.operation;
if (id && entityType) {
// TODO: Revisit this entity parameter for standalone editor, we may just directly pass ContentModelEntity object instead
var entity = {
id: id,
type: entityType,
isReadonly: !!isReadonly,
wrapper: wrapper,
};
core.api.triggerEvent(core, {
eventType: 15 /* EntityOperation */,
entity: entity,
operation: EntityOperationMap[operation],
rawEvent: context.rawEvent,
}, false /*broadcast*/);
}
});
}
function handleImages(core, context) {
if (context.newImages.length > 0) {
var viewport = core.getVisibleViewport();
var viewport = core.api.getVisibleViewport(core);
if (viewport) {

@@ -105,0 +77,0 @@ var left = viewport.left, right = viewport.right;

@@ -22,3 +22,3 @@ import { __read, __spreadArray } from "tslib";

else if (selection.type == 'range') {
core.domEvent.selectionRange = selection.range;
core.selection.selectionRange = selection.range;
}

@@ -25,0 +25,0 @@ }

@@ -1,8 +0,8 @@

import type { SwitchShadowEdit } from 'roosterjs-editor-types';
import type { SwitchShadowEdit } from 'roosterjs-content-model-types';
/**
* @internal
* Switch the Shadow Edit mode of editor On/Off
* @param editorCore The EditorCore object
* @param editorCore The StandaloneEditorCore object
* @param isOn True to switch On, False to switch Off
*/
export declare const switchShadowEdit: SwitchShadowEdit;
import { iterateSelections } from '../publicApi/selection/iterateSelections';
import { moveChildNodes } from 'roosterjs-content-model-dom';
/**
* @internal
* Switch the Shadow Edit mode of editor On/Off
* @param editorCore The EditorCore object
* @param editorCore The StandaloneEditorCore object
* @param isOn True to switch On, False to switch Off

@@ -17,10 +18,8 @@ */

var fragment = core.contentDiv.ownerDocument.createDocumentFragment();
var selectionPath = {
start: [],
end: [],
};
var clonedRoot = core.contentDiv.cloneNode(true /*deep*/);
moveChildNodes(fragment, clonedRoot);
core.api.triggerEvent(core, {
eventType: 17 /* EnteredShadowEdit */,
fragment: fragment,
selectionPath: selectionPath,
selectionPath: null,
}, false /*broadcast*/);

@@ -32,3 +31,2 @@ // This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event

}
core.lifecycle.shadowEditSelectionPath = selectionPath;
core.lifecycle.shadowEditFragment = fragment;

@@ -38,3 +36,2 @@ }

core.lifecycle.shadowEditFragment = null;
core.lifecycle.shadowEditSelectionPath = null;
core.api.triggerEvent(core, {

@@ -41,0 +38,0 @@ eventType: 18 /* LeavingShadowEdit */,

@@ -1,53 +0,8 @@

import type { ContentModelCachePluginState } from 'roosterjs-content-model-types';
import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelCachePluginState, StandaloneEditorOptions } from 'roosterjs-content-model-types';
import type { PluginWithState } from 'roosterjs-editor-types';
/**
* ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary
*/
export declare class ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {
private state;
private editor;
/**
* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
*/
constructor(state: ContentModelCachePluginState);
/**
* Get name of this plugin
*/
getName(): string;
/**
* The first method that editor will call to a plugin when editor is initializing.
* It will pass in the editor instance, plugin should take this chance to save the
* editor reference so that it can call to any editor method or format API later.
* @param editor The editor object
*/
initialize(editor: IEditor): void;
/**
* The last method that editor will call to a plugin before it is disposed.
* Plugin can take this chance to clear the reference to editor. After this method is
* called, plugin should not call to any editor method since it will result in error.
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): ContentModelCachePluginState;
/**
* Core method for a plugin. Once an event happens in editor, editor will call this
* method of each plugin to handle the event as long as the event is not handled
* exclusively by another plugin.
* @param event The event to handle:
*/
onPluginEvent(event: PluginEvent): void;
private onNativeSelectionChange;
private invalidateCache;
private updateCachedModel;
private shouldClearCache;
}
/**
* @internal
* Create a new instance of ContentModelCachePlugin class.
* This is mostly for unit test
* @param state State of this plugin
* @param option The editor option
*/
export declare function createContentModelCachePlugin(state: ContentModelCachePluginState): ContentModelCachePlugin;
export declare function createContentModelCachePlugin(option: StandaloneEditorOptions): PluginWithState<ContentModelCachePluginState>;
import { areSameSelection } from './utils/areSameSelection';
import { contentModelDomIndexer } from './utils/contentModelDomIndexer';
import { isCharacterValue } from '../publicApi/domUtils/eventUtils';

@@ -9,7 +10,6 @@ /**

* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
* @param option The editor option
*/
function ContentModelCachePlugin(state) {
function ContentModelCachePlugin(option) {
var _this = this;
this.state = state;
this.editor = null;

@@ -22,3 +22,5 @@ this.onNativeSelectionChange = function () {

};
// TODO: Remove tempState parameter once we have standalone Content Model editor
this.state = {
domIndexer: option.cacheModel ? contentModelDomIndexer : undefined,
};
}

@@ -157,12 +159,10 @@ /**

}());
export { ContentModelCachePlugin };
/**
* @internal
* Create a new instance of ContentModelCachePlugin class.
* This is mostly for unit test
* @param state State of this plugin
* @param option The editor option
*/
export function createContentModelCachePlugin(state) {
return new ContentModelCachePlugin(state);
export function createContentModelCachePlugin(option) {
return new ContentModelCachePlugin(option);
}
//# sourceMappingURL=ContentModelCachePlugin.js.map

@@ -1,37 +0,4 @@

import type { OnNodeCreated } from 'roosterjs-content-model-types';
import type { CopyPastePluginState, IEditor, PluginWithState } from 'roosterjs-editor-types';
import type { OnNodeCreated, StandaloneEditorOptions } from 'roosterjs-content-model-types';
import type { CopyPastePluginState, PluginWithState } from 'roosterjs-editor-types';
/**
* Copy and paste plugin for handling onCopy and onPaste event
*/
export declare class ContentModelCopyPastePlugin implements PluginWithState<CopyPastePluginState> {
private state;
private editor;
private disposer;
/**
* Construct a new instance of CopyPastePlugin
* @param options The editor options
*/
constructor(state: CopyPastePluginState);
/**
* Get a friendly name of this plugin
*/
getName(): string;
/**
* Initialize this plugin. This should only be called from Editor
* @param editor Editor instance
*/
initialize(editor: IEditor): void;
/**
* Dispose this plugin
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): CopyPastePluginState;
private onCutCopy;
private onPaste;
private getTempDiv;
}
/**
* @internal

@@ -44,4 +11,4 @@ * Exported only for unit testing

* Create a new instance of ContentModelCopyPastePlugin
* @param state The plugin state object
* @param option The editor option
*/
export declare function createContentModelCopyPastePlugin(state: CopyPastePluginState): ContentModelCopyPastePlugin;
export declare function createContentModelCopyPastePlugin(option: StandaloneEditorOptions): PluginWithState<CopyPastePluginState>;

@@ -16,7 +16,6 @@ import { __assign } from "tslib";

* Construct a new instance of CopyPastePlugin
* @param options The editor options
* @param option The editor option
*/
function ContentModelCopyPastePlugin(state) {
function ContentModelCopyPastePlugin(option) {
var _this = this;
this.state = state;
this.editor = null;

@@ -40,2 +39,5 @@ this.disposer = null;

};
this.state = {
allowedCustomPasteType: option.allowedCustomPasteType || [],
};
}

@@ -179,3 +181,2 @@ /**

}());
export { ContentModelCopyPastePlugin };
function cleanUpAndRestoreSelection(tempDiv) {

@@ -226,7 +227,7 @@ tempDiv.style.backgroundColor = '';

* Create a new instance of ContentModelCopyPastePlugin
* @param state The plugin state object
* @param option The editor option
*/
export function createContentModelCopyPastePlugin(state) {
return new ContentModelCopyPastePlugin(state);
export function createContentModelCopyPastePlugin(option) {
return new ContentModelCopyPastePlugin(option);
}
//# sourceMappingURL=ContentModelCopyPastePlugin.js.map

@@ -1,59 +0,8 @@

import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelFormatPluginState } from 'roosterjs-content-model-types';
import type { PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelFormatPluginState, StandaloneEditorOptions } from 'roosterjs-content-model-types';
/**
* ContentModelFormat plugins helps editor to do formatting on top of content model.
* This includes:
* 1. Handle pending format changes when selection is collapsed
*/
export declare class ContentModelFormatPlugin implements PluginWithState<ContentModelFormatPluginState> {
private state;
private editor;
private hasDefaultFormat;
/**
* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
*/
constructor(state: ContentModelFormatPluginState);
/**
* Get name of this plugin
*/
getName(): string;
/**
* The first method that editor will call to a plugin when editor is initializing.
* It will pass in the editor instance, plugin should take this chance to save the
* editor reference so that it can call to any editor method or format API later.
* @param editor The editor object
*/
initialize(editor: IEditor): void;
/**
* The last method that editor will call to a plugin before it is disposed.
* Plugin can take this chance to clear the reference to editor. After this method is
* called, plugin should not call to any editor method since it will result in error.
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): ContentModelFormatPluginState;
/**
* Core method for a plugin. Once an event happens in editor, editor will call this
* method of each plugin to handle the event as long as the event is not handled
* exclusively by another plugin.
* @param event The event to handle:
*/
onPluginEvent(event: PluginEvent): void;
private checkAndApplyPendingFormat;
private clearPendingFormat;
/**
* @internal
* Check if this editor can apply pending format
* @param editor The editor to get format from
*/
private canApplyPendingFormat;
}
/**
* @internal
* Create a new instance of ContentModelFormatPlugin.
* This is mostly for unit test
* @param option The editor option
*/
export declare function createContentModelFormatPlugin(state: ContentModelFormatPluginState): ContentModelFormatPlugin;
export declare function createContentModelFormatPlugin(option: StandaloneEditorOptions): PluginWithState<ContentModelFormatPluginState>;

@@ -0,1 +1,2 @@

import { __assign } from "tslib";
import { applyDefaultFormat } from './utils/applyDefaultFormat';

@@ -25,9 +26,11 @@ import { applyPendingFormat } from './utils/applyPendingFormat';

* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
* @param option The editor option
*/
function ContentModelFormatPlugin(state) {
this.state = state;
function ContentModelFormatPlugin(option) {
this.editor = null;
this.hasDefaultFormat = false;
// TODO: Remove tempState parameter once we have standalone Content Model editor
this.state = {
defaultFormat: __assign({}, option.defaultSegmentFormat),
pendingFormat: null,
};
}

@@ -135,11 +138,10 @@ /**

}());
export { ContentModelFormatPlugin };
/**
* @internal
* Create a new instance of ContentModelFormatPlugin.
* This is mostly for unit test
* @param option The editor option
*/
export function createContentModelFormatPlugin(state) {
return new ContentModelFormatPlugin(state);
export function createContentModelFormatPlugin(option) {
return new ContentModelFormatPlugin(option);
}
//# sourceMappingURL=ContentModelFormatPlugin.js.map

@@ -6,2 +6,4 @@ export { CachedElementHandler, CloneModelOptions, cloneModel } from './publicApi/model/cloneModel';

export { getClosestAncestorBlockGroupIndex, TypeOfBlockGroup, } from './publicApi/model/getClosestAncestorBlockGroupIndex';
export { isBold } from './publicApi/model/isBold';
export { createModelFromHtml } from './publicApi/model/createModelFromHtml';
export { iterateSelections, IterateSelectionsCallback, IterateSelectionsOption, } from './publicApi/selection/iterateSelections';

@@ -24,8 +26,6 @@ export { getSelectionRootNode } from './publicApi/selection/getSelectionRootNode';

export { updateListMetadata } from './metadata/updateListMetadata';
export { promoteToContentModelEditorCore } from './editor/promoteToContentModelEditorCore';
export { createContentModelEditorCore } from './editor/createContentModelEditorCore';
export { ChangeSource } from './constants/ChangeSource';
export { ContentModelCachePlugin } from './corePlugin/ContentModelCachePlugin';
export { ContentModelCopyPastePlugin } from './corePlugin/ContentModelCopyPastePlugin';
export { ContentModelFormatPlugin } from './corePlugin/ContentModelFormatPlugin';
export { ContentModelTypeInContainerPlugin } from './corePlugin/ContentModelTypeInContainerPlugin';
export { BulletListType } from './constants/BulletListType';
export { NumberingListType } from './constants/NumberingListType';
export { TableBorderFormat } from './constants/TableBorderFormat';
export { createStandaloneEditorCore } from './editor/createStandaloneEditorCore';

@@ -6,2 +6,4 @@ export { cloneModel } from './publicApi/model/cloneModel';

export { getClosestAncestorBlockGroupIndex, } from './publicApi/model/getClosestAncestorBlockGroupIndex';
export { isBold } from './publicApi/model/isBold';
export { createModelFromHtml } from './publicApi/model/createModelFromHtml';
export { iterateSelections, } from './publicApi/selection/iterateSelections';

@@ -24,9 +26,7 @@ export { getSelectionRootNode } from './publicApi/selection/getSelectionRootNode';

export { updateListMetadata } from './metadata/updateListMetadata';
export { promoteToContentModelEditorCore } from './editor/promoteToContentModelEditorCore';
export { createContentModelEditorCore } from './editor/createContentModelEditorCore';
export { ChangeSource } from './constants/ChangeSource';
export { ContentModelCachePlugin } from './corePlugin/ContentModelCachePlugin';
export { ContentModelCopyPastePlugin } from './corePlugin/ContentModelCopyPastePlugin';
export { ContentModelFormatPlugin } from './corePlugin/ContentModelFormatPlugin';
export { ContentModelTypeInContainerPlugin } from './corePlugin/ContentModelTypeInContainerPlugin';
export { BulletListType } from './constants/BulletListType';
export { NumberingListType } from './constants/NumberingListType';
export { TableBorderFormat } from './constants/TableBorderFormat';
export { createStandaloneEditorCore } from './editor/createStandaloneEditorCore';
//# sourceMappingURL=index.js.map
var _a, _b;
import { __values } from "tslib";
import { BulletListType, NumberingListType } from 'roosterjs-content-model-types';
import { BulletListType } from '../constants/BulletListType';
import { createNumberDefinition, createObjectDefinition } from './definitionCreators';
import { getObjectKeys, updateMetadata } from 'roosterjs-content-model-dom';
import { NumberingListType } from '../constants/NumberingListType';
var DefaultOrderedListStyles = ['decimal', 'lower-alpha', 'lower-roman'];

@@ -7,0 +8,0 @@ var DefaultUnorderedListStyles = ['disc', 'circle', 'square'];

@@ -1,2 +0,2 @@

import { TableBorderFormat } from 'roosterjs-content-model-types';
import { TableBorderFormat } from '../constants/TableBorderFormat';
import { updateMetadata } from 'roosterjs-content-model-dom';

@@ -17,3 +17,3 @@ import { createBooleanDefinition, createNumberDefinition, createObjectDefinition, createStringDefinition, } from './definitionCreators';

bgColorOdd: NullStringDefinition,
tableBorderFormat: createNumberDefinition(false /** isOptional */, undefined /* value */, TableBorderFormat.DEFAULT /* first table border format, TODO: Use Min/Max to specify valid values */, TableBorderFormat.CLEAR /* last table border format, , TODO: Use Min/Max to specify valid values */),
tableBorderFormat: createNumberDefinition(false /** isOptional */, undefined /* value */, TableBorderFormat.Min /* first table border format */, TableBorderFormat.Max /* last table border format */),
verticalAlign: NullStringDefinition,

@@ -20,0 +20,0 @@ }, false /* isOptional */, true /** allowNull */);

@@ -1,6 +0,6 @@

import { __assign } from "tslib";
import { __assign, __read, __spreadArray } from "tslib";
import { ChangeSource } from '../../constants/ChangeSource';
import { getSelectedSegments } from '../selection/collectSelections';
import { mergeModel } from './mergeModel';
import { applySegmentFormatToElement, createDomToModelContext, domToContentModel, moveChildNodes, } from 'roosterjs-content-model-dom';
import { AllowedEntityClasses, applySegmentFormatToElement, createDomToModelContext, domToContentModel, moveChildNodes, } from 'roosterjs-content-model-dom';
import { createDefaultHtmlSanitizerOptions, handleImagePaste, handleTextPaste, retrieveMetadataFromClipboard, sanitizePasteContent, } from 'roosterjs-editor-dom';

@@ -57,3 +57,3 @@ // Map new PasteType to old PasteType

if (originalFormat) {
context.newPendingFormat = __assign(__assign({}, EmptySegmentFormat), originalFormat); // Use empty format as initial value to clear any other format inherits from pasted content
context.newPendingFormat = __assign(__assign(__assign({}, EmptySegmentFormat), model.format), originalFormat); // Use empty format as initial value to clear any other format inherits from pasted content
}

@@ -92,3 +92,5 @@ return true;

function createBeforePasteEventData(editor, clipboardData, pasteType) {
var _a;
var options = createDefaultHtmlSanitizerOptions();
(_a = options.additionalAllowedCssClasses).push.apply(_a, __spreadArray([], __read(AllowedEntityClasses), false));
// Remove "caret-color" style generated by Safari to make sure caret shows in right color after paste

@@ -95,0 +97,0 @@ options.cssStyleCallbacks['caret-color'] = function () { return false; };

@@ -6,3 +6,3 @@ var _a;

import { setTableCellBackgroundColor } from './setTableCellBackgroundColor';
import { TableBorderFormat } from 'roosterjs-content-model-types';
import { TableBorderFormat } from '../../constants/TableBorderFormat';
import { updateTableCellMetadata } from '../../metadata/updateTableCellMetadata';

@@ -21,3 +21,3 @@ import { updateTableMetadata } from '../../metadata/updateTableMetadata';

headerRowColor: '#ABABAB',
tableBorderFormat: TableBorderFormat.DEFAULT,
tableBorderFormat: TableBorderFormat.Default,
verticalAlign: null,

@@ -83,4 +83,4 @@ };

var BorderFormatters = (_a = {},
_a[TableBorderFormat.DEFAULT] = function (_) { return [false, false, false, false]; },
_a[TableBorderFormat.LIST_WITH_SIDE_BORDERS] = function (_a) {
_a[TableBorderFormat.Default] = function (_) { return [false, false, false, false]; },
_a[TableBorderFormat.ListWithSideBorders] = function (_a) {
var lastColumn = _a.lastColumn, firstColumn = _a.firstColumn;

@@ -94,3 +94,3 @@ return [

},
_a[TableBorderFormat.FIRST_COLUMN_HEADER_EXTERNAL] = function (_a) {
_a[TableBorderFormat.FirstColumnHeaderExternal] = function (_a) {
var firstColumn = _a.firstColumn, firstRow = _a.firstRow, lastColumn = _a.lastColumn, lastRow = _a.lastRow;

@@ -104,3 +104,3 @@ return [

},
_a[TableBorderFormat.NO_HEADER_BORDERS] = function (_a) {
_a[TableBorderFormat.NoHeaderBorders] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn, lastColumn = _a.lastColumn;

@@ -114,3 +114,3 @@ return [

},
_a[TableBorderFormat.NO_SIDE_BORDERS] = function (_a) {
_a[TableBorderFormat.NoSideBorders] = function (_a) {
var firstColumn = _a.firstColumn, lastColumn = _a.lastColumn;

@@ -124,3 +124,3 @@ return [

},
_a[TableBorderFormat.ESPECIAL_TYPE_1] = function (_a) {
_a[TableBorderFormat.EspecialType1] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn;

@@ -134,3 +134,3 @@ return [

},
_a[TableBorderFormat.ESPECIAL_TYPE_2] = function (_a) {
_a[TableBorderFormat.EspecialType2] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn;

@@ -144,3 +144,3 @@ return [

},
_a[TableBorderFormat.ESPECIAL_TYPE_3] = function (_a) {
_a[TableBorderFormat.EspecialType3] = function (_a) {
var firstColumn = _a.firstColumn, firstRow = _a.firstRow;

@@ -154,3 +154,3 @@ return [

},
_a[TableBorderFormat.CLEAR] = function () { return [true, true, true, true]; },
_a[TableBorderFormat.Clear] = function () { return [true, true, true, true]; },
_a);

@@ -164,5 +164,7 @@ /*

row.cells.forEach(function (cell, colIndex) {
var _a;
// Format Borders
if (!metaOverrides.borderOverrides[rowIndex][colIndex]) {
var transparentBorderMatrix = BorderFormatters[format.tableBorderFormat]({
if (!metaOverrides.borderOverrides[rowIndex][colIndex] &&
typeof format.tableBorderFormat == 'number') {
var transparentBorderMatrix = (_a = BorderFormatters[format.tableBorderFormat]) === null || _a === void 0 ? void 0 : _a.call(BorderFormatters, {
firstRow: rowIndex === 0,

@@ -179,3 +181,3 @@ lastRow: rowIndex === rows.length - 1,

];
transparentBorderMatrix.forEach(function (alwaysUseTransparent, i) {
transparentBorderMatrix === null || transparentBorderMatrix === void 0 ? void 0 : transparentBorderMatrix.forEach(function (alwaysUseTransparent, i) {
var borderColor = (!alwaysUseTransparent && formatColor_1[i]) || '';

@@ -182,0 +184,0 @@ cell.format[BorderKeys[i]] = combineBorderValue({

@@ -37,11 +37,4 @@ import { __assign } from "tslib";

}
if (applyToSegments && cell.format.textColor) {
cell.blocks.forEach(function (block) {
if (block.blockType == 'Paragraph') {
block.segmentFormat = __assign(__assign({}, block.segmentFormat), { textColor: cell.format.textColor });
block.segments.forEach(function (segment) {
segment.format = __assign(__assign({}, segment.format), { textColor: cell.format.textColor });
});
}
});
if (applyToSegments) {
setAdaptiveCellColor(cell);
}

@@ -52,5 +45,59 @@ }

delete cell.format.textColor;
if (applyToSegments) {
removeAdaptiveCellColor(cell);
}
}
delete cell.cachedElement;
}
function removeAdaptiveCellColor(cell) {
cell.blocks.forEach(function (block) {
var _a, _b;
if (block.blockType == 'Paragraph') {
if (((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor) &&
shouldRemoveColor((_b = block.segmentFormat) === null || _b === void 0 ? void 0 : _b.textColor, cell.format.backgroundColor || '')) {
delete block.segmentFormat.textColor;
}
block.segments.forEach(function (segment) {
if (segment.format.textColor &&
shouldRemoveColor(segment.format.textColor, cell.format.backgroundColor || '')) {
delete segment.format.textColor;
}
});
}
});
}
function setAdaptiveCellColor(cell) {
if (cell.format.textColor) {
cell.blocks.forEach(function (block) {
var _a;
if (block.blockType == 'Paragraph') {
if (!((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor)) {
block.segmentFormat = __assign(__assign({}, block.segmentFormat), { textColor: cell.format.textColor });
}
block.segments.forEach(function (segment) {
var _a;
if (!((_a = segment.format) === null || _a === void 0 ? void 0 : _a.textColor)) {
segment.format = __assign(__assign({}, segment.format), { textColor: cell.format.textColor });
}
});
}
});
}
}
/**
* If the cell background color is too dark or too bright, and the text color is white or black, we should remove the text color
* @param textColor the segment or block text color
* @param cellBackgroundColor the cell background color
* @returns
*/
function shouldRemoveColor(textColor, cellBackgroundColor) {
var lightness = calculateLightness(cellBackgroundColor);
if (([White, 'rgb(255,255,255)'].indexOf(textColor) > -1 &&
(lightness > BRIGHT_COLORS_LIGHTNESS || cellBackgroundColor == '')) ||
([Black, 'rgb(0,0,0)'].indexOf(textColor) > -1 &&
(lightness < DARK_COLORS_LIGHTNESS || cellBackgroundColor == ''))) {
return true;
}
return false;
}
function calculateLightness(color) {

@@ -57,0 +104,0 @@ var colorValues = parseColor(color);

@@ -28,4 +28,2 @@ "use strict";

var writeBack = function () {
handleNewEntities(core, context);
handleDeletedEntities(core, context);
handleImages(core, context);

@@ -54,2 +52,13 @@ selection =

},
changedEntities: context.newEntities
.map(function (entity) { return ({
entity: entity,
operation: 'newEntity',
rawEvent: rawEvent,
}); })
.concat(context.deletedEntities.map(function (entry) { return ({
entity: entry.entity,
operation: entry.operation,
rawEvent: rawEvent,
}); })),
};

@@ -67,42 +76,5 @@ core.api.triggerEvent(core, eventData, true /*broadcast*/);

exports.formatContentModel = formatContentModel;
function handleNewEntities(core, context) {
// TODO: Ideally we can trigger NewEntity event here. But to be compatible with original editor code, we don't do it here for now.
// Once Content Model Editor can be standalone, we can change this behavior to move triggering NewEntity event code
// from EntityPlugin to here
if (core.lifecycle.isDarkMode) {
context.newEntities.forEach(function (entity) {
core.api.transformColor(core, entity.wrapper, true /*includeSelf*/, null /*callback*/, 0 /* LightToDark */);
});
}
}
// This is only used for compatibility with old editor
// TODO: Remove this map once we have standalone editor
var EntityOperationMap = {
overwrite: 6 /* Overwrite */,
removeFromEnd: 5 /* RemoveFromEnd */,
removeFromStart: 4 /* RemoveFromStart */,
};
function handleDeletedEntities(core, context) {
context.deletedEntities.forEach(function (_a) {
var _b = _a.entity, wrapper = _b.wrapper, _c = _b.entityFormat, id = _c.id, entityType = _c.entityType, isReadonly = _c.isReadonly, operation = _a.operation;
if (id && entityType) {
// TODO: Revisit this entity parameter for standalone editor, we may just directly pass ContentModelEntity object instead
var entity = {
id: id,
type: entityType,
isReadonly: !!isReadonly,
wrapper: wrapper,
};
core.api.triggerEvent(core, {
eventType: 15 /* EntityOperation */,
entity: entity,
operation: EntityOperationMap[operation],
rawEvent: context.rawEvent,
}, false /*broadcast*/);
}
});
}
function handleImages(core, context) {
if (context.newImages.length > 0) {
var viewport = core.getVisibleViewport();
var viewport = core.api.getVisibleViewport(core);
if (viewport) {

@@ -109,0 +81,0 @@ var left = viewport.left, right = viewport.right;

@@ -25,3 +25,3 @@ "use strict";

else if (selection.type == 'range') {
core.domEvent.selectionRange = selection.range;
core.selection.selectionRange = selection.range;
}

@@ -28,0 +28,0 @@ }

@@ -1,8 +0,8 @@

import type { SwitchShadowEdit } from 'roosterjs-editor-types';
import type { SwitchShadowEdit } from 'roosterjs-content-model-types';
/**
* @internal
* Switch the Shadow Edit mode of editor On/Off
* @param editorCore The EditorCore object
* @param editorCore The StandaloneEditorCore object
* @param isOn True to switch On, False to switch Off
*/
export declare const switchShadowEdit: SwitchShadowEdit;

@@ -5,6 +5,7 @@ "use strict";

var iterateSelections_1 = require("../publicApi/selection/iterateSelections");
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
/**
* @internal
* Switch the Shadow Edit mode of editor On/Off
* @param editorCore The EditorCore object
* @param editorCore The StandaloneEditorCore object
* @param isOn True to switch On, False to switch Off

@@ -21,10 +22,8 @@ */

var fragment = core.contentDiv.ownerDocument.createDocumentFragment();
var selectionPath = {
start: [],
end: [],
};
var clonedRoot = core.contentDiv.cloneNode(true /*deep*/);
(0, roosterjs_content_model_dom_1.moveChildNodes)(fragment, clonedRoot);
core.api.triggerEvent(core, {
eventType: 17 /* EnteredShadowEdit */,
fragment: fragment,
selectionPath: selectionPath,
selectionPath: null,
}, false /*broadcast*/);

@@ -36,3 +35,2 @@ // This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event

}
core.lifecycle.shadowEditSelectionPath = selectionPath;
core.lifecycle.shadowEditFragment = fragment;

@@ -42,3 +40,2 @@ }

core.lifecycle.shadowEditFragment = null;
core.lifecycle.shadowEditSelectionPath = null;
core.api.triggerEvent(core, {

@@ -45,0 +42,0 @@ eventType: 18 /* LeavingShadowEdit */,

@@ -1,53 +0,8 @@

import type { ContentModelCachePluginState } from 'roosterjs-content-model-types';
import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelCachePluginState, StandaloneEditorOptions } from 'roosterjs-content-model-types';
import type { PluginWithState } from 'roosterjs-editor-types';
/**
* ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary
*/
export declare class ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {
private state;
private editor;
/**
* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
*/
constructor(state: ContentModelCachePluginState);
/**
* Get name of this plugin
*/
getName(): string;
/**
* The first method that editor will call to a plugin when editor is initializing.
* It will pass in the editor instance, plugin should take this chance to save the
* editor reference so that it can call to any editor method or format API later.
* @param editor The editor object
*/
initialize(editor: IEditor): void;
/**
* The last method that editor will call to a plugin before it is disposed.
* Plugin can take this chance to clear the reference to editor. After this method is
* called, plugin should not call to any editor method since it will result in error.
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): ContentModelCachePluginState;
/**
* Core method for a plugin. Once an event happens in editor, editor will call this
* method of each plugin to handle the event as long as the event is not handled
* exclusively by another plugin.
* @param event The event to handle:
*/
onPluginEvent(event: PluginEvent): void;
private onNativeSelectionChange;
private invalidateCache;
private updateCachedModel;
private shouldClearCache;
}
/**
* @internal
* Create a new instance of ContentModelCachePlugin class.
* This is mostly for unit test
* @param state State of this plugin
* @param option The editor option
*/
export declare function createContentModelCachePlugin(state: ContentModelCachePluginState): ContentModelCachePlugin;
export declare function createContentModelCachePlugin(option: StandaloneEditorOptions): PluginWithState<ContentModelCachePluginState>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createContentModelCachePlugin = exports.ContentModelCachePlugin = void 0;
exports.createContentModelCachePlugin = void 0;
var areSameSelection_1 = require("./utils/areSameSelection");
var contentModelDomIndexer_1 = require("./utils/contentModelDomIndexer");
var eventUtils_1 = require("../publicApi/domUtils/eventUtils");

@@ -12,7 +13,6 @@ /**

* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
* @param option The editor option
*/
function ContentModelCachePlugin(state) {
function ContentModelCachePlugin(option) {
var _this = this;
this.state = state;
this.editor = null;

@@ -25,3 +25,5 @@ this.onNativeSelectionChange = function () {

};
// TODO: Remove tempState parameter once we have standalone Content Model editor
this.state = {
domIndexer: option.cacheModel ? contentModelDomIndexer_1.contentModelDomIndexer : undefined,
};
}

@@ -160,13 +162,11 @@ /**

}());
exports.ContentModelCachePlugin = ContentModelCachePlugin;
/**
* @internal
* Create a new instance of ContentModelCachePlugin class.
* This is mostly for unit test
* @param state State of this plugin
* @param option The editor option
*/
function createContentModelCachePlugin(state) {
return new ContentModelCachePlugin(state);
function createContentModelCachePlugin(option) {
return new ContentModelCachePlugin(option);
}
exports.createContentModelCachePlugin = createContentModelCachePlugin;
//# sourceMappingURL=ContentModelCachePlugin.js.map

@@ -1,37 +0,4 @@

import type { OnNodeCreated } from 'roosterjs-content-model-types';
import type { CopyPastePluginState, IEditor, PluginWithState } from 'roosterjs-editor-types';
import type { OnNodeCreated, StandaloneEditorOptions } from 'roosterjs-content-model-types';
import type { CopyPastePluginState, PluginWithState } from 'roosterjs-editor-types';
/**
* Copy and paste plugin for handling onCopy and onPaste event
*/
export declare class ContentModelCopyPastePlugin implements PluginWithState<CopyPastePluginState> {
private state;
private editor;
private disposer;
/**
* Construct a new instance of CopyPastePlugin
* @param options The editor options
*/
constructor(state: CopyPastePluginState);
/**
* Get a friendly name of this plugin
*/
getName(): string;
/**
* Initialize this plugin. This should only be called from Editor
* @param editor Editor instance
*/
initialize(editor: IEditor): void;
/**
* Dispose this plugin
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): CopyPastePluginState;
private onCutCopy;
private onPaste;
private getTempDiv;
}
/**
* @internal

@@ -44,4 +11,4 @@ * Exported only for unit testing

* Create a new instance of ContentModelCopyPastePlugin
* @param state The plugin state object
* @param option The editor option
*/
export declare function createContentModelCopyPastePlugin(state: CopyPastePluginState): ContentModelCopyPastePlugin;
export declare function createContentModelCopyPastePlugin(option: StandaloneEditorOptions): PluginWithState<CopyPastePluginState>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createContentModelCopyPastePlugin = exports.onNodeCreated = exports.ContentModelCopyPastePlugin = void 0;
exports.createContentModelCopyPastePlugin = exports.onNodeCreated = void 0;
var tslib_1 = require("tslib");

@@ -19,7 +19,6 @@ var addRangeToSelection_1 = require("./utils/addRangeToSelection");

* Construct a new instance of CopyPastePlugin
* @param options The editor options
* @param option The editor option
*/
function ContentModelCopyPastePlugin(state) {
function ContentModelCopyPastePlugin(option) {
var _this = this;
this.state = state;
this.editor = null;

@@ -43,2 +42,5 @@ this.disposer = null;

};
this.state = {
allowedCustomPasteType: option.allowedCustomPasteType || [],
};
}

@@ -182,3 +184,2 @@ /**

}());
exports.ContentModelCopyPastePlugin = ContentModelCopyPastePlugin;
function cleanUpAndRestoreSelection(tempDiv) {

@@ -230,8 +231,8 @@ tempDiv.style.backgroundColor = '';

* Create a new instance of ContentModelCopyPastePlugin
* @param state The plugin state object
* @param option The editor option
*/
function createContentModelCopyPastePlugin(state) {
return new ContentModelCopyPastePlugin(state);
function createContentModelCopyPastePlugin(option) {
return new ContentModelCopyPastePlugin(option);
}
exports.createContentModelCopyPastePlugin = createContentModelCopyPastePlugin;
//# sourceMappingURL=ContentModelCopyPastePlugin.js.map

@@ -1,59 +0,8 @@

import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelFormatPluginState } from 'roosterjs-content-model-types';
import type { PluginWithState } from 'roosterjs-editor-types';
import type { ContentModelFormatPluginState, StandaloneEditorOptions } from 'roosterjs-content-model-types';
/**
* ContentModelFormat plugins helps editor to do formatting on top of content model.
* This includes:
* 1. Handle pending format changes when selection is collapsed
*/
export declare class ContentModelFormatPlugin implements PluginWithState<ContentModelFormatPluginState> {
private state;
private editor;
private hasDefaultFormat;
/**
* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
*/
constructor(state: ContentModelFormatPluginState);
/**
* Get name of this plugin
*/
getName(): string;
/**
* The first method that editor will call to a plugin when editor is initializing.
* It will pass in the editor instance, plugin should take this chance to save the
* editor reference so that it can call to any editor method or format API later.
* @param editor The editor object
*/
initialize(editor: IEditor): void;
/**
* The last method that editor will call to a plugin before it is disposed.
* Plugin can take this chance to clear the reference to editor. After this method is
* called, plugin should not call to any editor method since it will result in error.
*/
dispose(): void;
/**
* Get plugin state object
*/
getState(): ContentModelFormatPluginState;
/**
* Core method for a plugin. Once an event happens in editor, editor will call this
* method of each plugin to handle the event as long as the event is not handled
* exclusively by another plugin.
* @param event The event to handle:
*/
onPluginEvent(event: PluginEvent): void;
private checkAndApplyPendingFormat;
private clearPendingFormat;
/**
* @internal
* Check if this editor can apply pending format
* @param editor The editor to get format from
*/
private canApplyPendingFormat;
}
/**
* @internal
* Create a new instance of ContentModelFormatPlugin.
* This is mostly for unit test
* @param option The editor option
*/
export declare function createContentModelFormatPlugin(state: ContentModelFormatPluginState): ContentModelFormatPlugin;
export declare function createContentModelFormatPlugin(option: StandaloneEditorOptions): PluginWithState<ContentModelFormatPluginState>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createContentModelFormatPlugin = exports.ContentModelFormatPlugin = void 0;
exports.createContentModelFormatPlugin = void 0;
var tslib_1 = require("tslib");
var applyDefaultFormat_1 = require("./utils/applyDefaultFormat");

@@ -28,9 +29,11 @@ var applyPendingFormat_1 = require("./utils/applyPendingFormat");

* Construct a new instance of ContentModelEditPlugin class
* @param state State of this plugin
* @param option The editor option
*/
function ContentModelFormatPlugin(state) {
this.state = state;
function ContentModelFormatPlugin(option) {
this.editor = null;
this.hasDefaultFormat = false;
// TODO: Remove tempState parameter once we have standalone Content Model editor
this.state = {
defaultFormat: (0, tslib_1.__assign)({}, option.defaultSegmentFormat),
pendingFormat: null,
};
}

@@ -138,12 +141,11 @@ /**

}());
exports.ContentModelFormatPlugin = ContentModelFormatPlugin;
/**
* @internal
* Create a new instance of ContentModelFormatPlugin.
* This is mostly for unit test
* @param option The editor option
*/
function createContentModelFormatPlugin(state) {
return new ContentModelFormatPlugin(state);
function createContentModelFormatPlugin(option) {
return new ContentModelFormatPlugin(option);
}
exports.createContentModelFormatPlugin = createContentModelFormatPlugin;
//# sourceMappingURL=ContentModelFormatPlugin.js.map

@@ -6,2 +6,4 @@ export { CachedElementHandler, CloneModelOptions, cloneModel } from './publicApi/model/cloneModel';

export { getClosestAncestorBlockGroupIndex, TypeOfBlockGroup, } from './publicApi/model/getClosestAncestorBlockGroupIndex';
export { isBold } from './publicApi/model/isBold';
export { createModelFromHtml } from './publicApi/model/createModelFromHtml';
export { iterateSelections, IterateSelectionsCallback, IterateSelectionsOption, } from './publicApi/selection/iterateSelections';

@@ -24,8 +26,6 @@ export { getSelectionRootNode } from './publicApi/selection/getSelectionRootNode';

export { updateListMetadata } from './metadata/updateListMetadata';
export { promoteToContentModelEditorCore } from './editor/promoteToContentModelEditorCore';
export { createContentModelEditorCore } from './editor/createContentModelEditorCore';
export { ChangeSource } from './constants/ChangeSource';
export { ContentModelCachePlugin } from './corePlugin/ContentModelCachePlugin';
export { ContentModelCopyPastePlugin } from './corePlugin/ContentModelCopyPastePlugin';
export { ContentModelFormatPlugin } from './corePlugin/ContentModelFormatPlugin';
export { ContentModelTypeInContainerPlugin } from './corePlugin/ContentModelTypeInContainerPlugin';
export { BulletListType } from './constants/BulletListType';
export { NumberingListType } from './constants/NumberingListType';
export { TableBorderFormat } from './constants/TableBorderFormat';
export { createStandaloneEditorCore } from './editor/createStandaloneEditorCore';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentModelTypeInContainerPlugin = exports.ContentModelFormatPlugin = exports.ContentModelCopyPastePlugin = exports.ContentModelCachePlugin = exports.ChangeSource = exports.createContentModelEditorCore = exports.promoteToContentModelEditorCore = exports.updateListMetadata = exports.updateTableMetadata = exports.updateTableCellMetadata = exports.updateImageMetadata = exports.normalizeText = exports.isSpace = exports.isPunctuation = exports.extractBorderValues = exports.combineBorderValue = exports.isModifierKey = exports.isCharacterValue = exports.setTableCellBackgroundColor = exports.normalizeTable = exports.applyTableFormat = exports.setSelection = exports.getSelectedSegmentsAndParagraphs = exports.getSelectedSegments = exports.getSelectedParagraphs = exports.getOperationalBlocks = exports.getFirstSelectedTable = exports.getFirstSelectedListItem = exports.deleteBlock = exports.deleteSegment = exports.deleteSelection = exports.getSelectionRootNode = exports.iterateSelections = exports.getClosestAncestorBlockGroupIndex = exports.isBlockGroupOfType = exports.mergeModel = exports.paste = exports.cloneModel = void 0;
exports.createStandaloneEditorCore = exports.TableBorderFormat = exports.NumberingListType = exports.BulletListType = exports.ChangeSource = exports.updateListMetadata = exports.updateTableMetadata = exports.updateTableCellMetadata = exports.updateImageMetadata = exports.normalizeText = exports.isSpace = exports.isPunctuation = exports.extractBorderValues = exports.combineBorderValue = exports.isModifierKey = exports.isCharacterValue = exports.setTableCellBackgroundColor = exports.normalizeTable = exports.applyTableFormat = exports.setSelection = exports.getSelectedSegmentsAndParagraphs = exports.getSelectedSegments = exports.getSelectedParagraphs = exports.getOperationalBlocks = exports.getFirstSelectedTable = exports.getFirstSelectedListItem = exports.deleteBlock = exports.deleteSegment = exports.deleteSelection = exports.getSelectionRootNode = exports.iterateSelections = exports.createModelFromHtml = exports.isBold = exports.getClosestAncestorBlockGroupIndex = exports.isBlockGroupOfType = exports.mergeModel = exports.paste = exports.cloneModel = void 0;
var cloneModel_1 = require("./publicApi/model/cloneModel");

@@ -14,2 +14,6 @@ Object.defineProperty(exports, "cloneModel", { enumerable: true, get: function () { return cloneModel_1.cloneModel; } });

Object.defineProperty(exports, "getClosestAncestorBlockGroupIndex", { enumerable: true, get: function () { return getClosestAncestorBlockGroupIndex_1.getClosestAncestorBlockGroupIndex; } });
var isBold_1 = require("./publicApi/model/isBold");
Object.defineProperty(exports, "isBold", { enumerable: true, get: function () { return isBold_1.isBold; } });
var createModelFromHtml_1 = require("./publicApi/model/createModelFromHtml");
Object.defineProperty(exports, "createModelFromHtml", { enumerable: true, get: function () { return createModelFromHtml_1.createModelFromHtml; } });
var iterateSelections_1 = require("./publicApi/selection/iterateSelections");

@@ -58,16 +62,12 @@ Object.defineProperty(exports, "iterateSelections", { enumerable: true, get: function () { return iterateSelections_1.iterateSelections; } });

Object.defineProperty(exports, "updateListMetadata", { enumerable: true, get: function () { return updateListMetadata_1.updateListMetadata; } });
var promoteToContentModelEditorCore_1 = require("./editor/promoteToContentModelEditorCore");
Object.defineProperty(exports, "promoteToContentModelEditorCore", { enumerable: true, get: function () { return promoteToContentModelEditorCore_1.promoteToContentModelEditorCore; } });
var createContentModelEditorCore_1 = require("./editor/createContentModelEditorCore");
Object.defineProperty(exports, "createContentModelEditorCore", { enumerable: true, get: function () { return createContentModelEditorCore_1.createContentModelEditorCore; } });
var ChangeSource_1 = require("./constants/ChangeSource");
Object.defineProperty(exports, "ChangeSource", { enumerable: true, get: function () { return ChangeSource_1.ChangeSource; } });
var ContentModelCachePlugin_1 = require("./corePlugin/ContentModelCachePlugin");
Object.defineProperty(exports, "ContentModelCachePlugin", { enumerable: true, get: function () { return ContentModelCachePlugin_1.ContentModelCachePlugin; } });
var ContentModelCopyPastePlugin_1 = require("./corePlugin/ContentModelCopyPastePlugin");
Object.defineProperty(exports, "ContentModelCopyPastePlugin", { enumerable: true, get: function () { return ContentModelCopyPastePlugin_1.ContentModelCopyPastePlugin; } });
var ContentModelFormatPlugin_1 = require("./corePlugin/ContentModelFormatPlugin");
Object.defineProperty(exports, "ContentModelFormatPlugin", { enumerable: true, get: function () { return ContentModelFormatPlugin_1.ContentModelFormatPlugin; } });
var ContentModelTypeInContainerPlugin_1 = require("./corePlugin/ContentModelTypeInContainerPlugin");
Object.defineProperty(exports, "ContentModelTypeInContainerPlugin", { enumerable: true, get: function () { return ContentModelTypeInContainerPlugin_1.ContentModelTypeInContainerPlugin; } });
var BulletListType_1 = require("./constants/BulletListType");
Object.defineProperty(exports, "BulletListType", { enumerable: true, get: function () { return BulletListType_1.BulletListType; } });
var NumberingListType_1 = require("./constants/NumberingListType");
Object.defineProperty(exports, "NumberingListType", { enumerable: true, get: function () { return NumberingListType_1.NumberingListType; } });
var TableBorderFormat_1 = require("./constants/TableBorderFormat");
Object.defineProperty(exports, "TableBorderFormat", { enumerable: true, get: function () { return TableBorderFormat_1.TableBorderFormat; } });
var createStandaloneEditorCore_1 = require("./editor/createStandaloneEditorCore");
Object.defineProperty(exports, "createStandaloneEditorCore", { enumerable: true, get: function () { return createStandaloneEditorCore_1.createStandaloneEditorCore; } });
//# sourceMappingURL=index.js.map

@@ -6,5 +6,6 @@ "use strict";

var tslib_1 = require("tslib");
var roosterjs_content_model_types_1 = require("roosterjs-content-model-types");
var BulletListType_1 = require("../constants/BulletListType");
var definitionCreators_1 = require("./definitionCreators");
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
var NumberingListType_1 = require("../constants/NumberingListType");
var DefaultOrderedListStyles = ['decimal', 'lower-alpha', 'lower-roman'];

@@ -30,33 +31,33 @@ var DefaultUnorderedListStyles = ['disc', 'circle', 'square'];

var OrderedMap = (_a = {},
_a[roosterjs_content_model_types_1.NumberingListType.Decimal] = 'decimal',
_a[roosterjs_content_model_types_1.NumberingListType.DecimalDash] = '"${Number}- "',
_a[roosterjs_content_model_types_1.NumberingListType.DecimalParenthesis] = '"${Number}) "',
_a[roosterjs_content_model_types_1.NumberingListType.DecimalDoubleParenthesis] = '"(${Number}) "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerAlpha] = 'lower-alpha',
_a[roosterjs_content_model_types_1.NumberingListType.LowerAlphaDash] = '"${LowerAlpha}- "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerAlphaParenthesis] = '"${LowerAlpha}) "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerAlphaDoubleParenthesis] = '"(${LowerAlpha}) "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperAlpha] = 'upper-alpha',
_a[roosterjs_content_model_types_1.NumberingListType.UpperAlphaDash] = '"${UpperAlpha}- "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperAlphaParenthesis] = '"${UpperAlpha}) "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperAlphaDoubleParenthesis] = '"(${UpperAlpha}) "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerRoman] = 'lower-roman',
_a[roosterjs_content_model_types_1.NumberingListType.LowerRomanDash] = '"${LowerRoman}- "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerRomanParenthesis] = '"${LowerRoman}) "',
_a[roosterjs_content_model_types_1.NumberingListType.LowerRomanDoubleParenthesis] = '"(${LowerRoman}) "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperRoman] = 'upper-roman',
_a[roosterjs_content_model_types_1.NumberingListType.UpperRomanDash] = '"${UpperRoman}- "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperRomanParenthesis] = '"${UpperRoman}) "',
_a[roosterjs_content_model_types_1.NumberingListType.UpperRomanDoubleParenthesis] = '"(${UpperRoman}) "',
_a[NumberingListType_1.NumberingListType.Decimal] = 'decimal',
_a[NumberingListType_1.NumberingListType.DecimalDash] = '"${Number}- "',
_a[NumberingListType_1.NumberingListType.DecimalParenthesis] = '"${Number}) "',
_a[NumberingListType_1.NumberingListType.DecimalDoubleParenthesis] = '"(${Number}) "',
_a[NumberingListType_1.NumberingListType.LowerAlpha] = 'lower-alpha',
_a[NumberingListType_1.NumberingListType.LowerAlphaDash] = '"${LowerAlpha}- "',
_a[NumberingListType_1.NumberingListType.LowerAlphaParenthesis] = '"${LowerAlpha}) "',
_a[NumberingListType_1.NumberingListType.LowerAlphaDoubleParenthesis] = '"(${LowerAlpha}) "',
_a[NumberingListType_1.NumberingListType.UpperAlpha] = 'upper-alpha',
_a[NumberingListType_1.NumberingListType.UpperAlphaDash] = '"${UpperAlpha}- "',
_a[NumberingListType_1.NumberingListType.UpperAlphaParenthesis] = '"${UpperAlpha}) "',
_a[NumberingListType_1.NumberingListType.UpperAlphaDoubleParenthesis] = '"(${UpperAlpha}) "',
_a[NumberingListType_1.NumberingListType.LowerRoman] = 'lower-roman',
_a[NumberingListType_1.NumberingListType.LowerRomanDash] = '"${LowerRoman}- "',
_a[NumberingListType_1.NumberingListType.LowerRomanParenthesis] = '"${LowerRoman}) "',
_a[NumberingListType_1.NumberingListType.LowerRomanDoubleParenthesis] = '"(${LowerRoman}) "',
_a[NumberingListType_1.NumberingListType.UpperRoman] = 'upper-roman',
_a[NumberingListType_1.NumberingListType.UpperRomanDash] = '"${UpperRoman}- "',
_a[NumberingListType_1.NumberingListType.UpperRomanParenthesis] = '"${UpperRoman}) "',
_a[NumberingListType_1.NumberingListType.UpperRomanDoubleParenthesis] = '"(${UpperRoman}) "',
_a);
var UnorderedMap = (_b = {},
_b[roosterjs_content_model_types_1.BulletListType.Disc] = 'disc',
_b[roosterjs_content_model_types_1.BulletListType.Square] = '"∎ "',
_b[roosterjs_content_model_types_1.BulletListType.Circle] = 'circle',
_b[roosterjs_content_model_types_1.BulletListType.Dash] = '"- "',
_b[roosterjs_content_model_types_1.BulletListType.LongArrow] = '"➔ "',
_b[roosterjs_content_model_types_1.BulletListType.DoubleLongArrow] = '"➔ "',
_b[roosterjs_content_model_types_1.BulletListType.ShortArrow] = '"➢ "',
_b[roosterjs_content_model_types_1.BulletListType.UnfilledArrow] = '"➪ "',
_b[roosterjs_content_model_types_1.BulletListType.Hyphen] = '"— "',
_b[BulletListType_1.BulletListType.Disc] = 'disc',
_b[BulletListType_1.BulletListType.Square] = '"∎ "',
_b[BulletListType_1.BulletListType.Circle] = 'circle',
_b[BulletListType_1.BulletListType.Dash] = '"- "',
_b[BulletListType_1.BulletListType.LongArrow] = '"➔ "',
_b[BulletListType_1.BulletListType.DoubleLongArrow] = '"➔ "',
_b[BulletListType_1.BulletListType.ShortArrow] = '"➢ "',
_b[BulletListType_1.BulletListType.UnfilledArrow] = '"➪ "',
_b[BulletListType_1.BulletListType.Hyphen] = '"— "',
_b);

@@ -112,4 +113,4 @@ function getOrderedListStyleValue(template, listNumber) {

var listMetadataDefinition = (0, definitionCreators_1.createObjectDefinition)({
orderedStyleType: (0, definitionCreators_1.createNumberDefinition)(true /** isOptional */, undefined /** value **/, roosterjs_content_model_types_1.NumberingListType.Min, roosterjs_content_model_types_1.NumberingListType.Max),
unorderedStyleType: (0, definitionCreators_1.createNumberDefinition)(true /** isOptional */, undefined /** value **/, roosterjs_content_model_types_1.BulletListType.Min, roosterjs_content_model_types_1.BulletListType.Max),
orderedStyleType: (0, definitionCreators_1.createNumberDefinition)(true /** isOptional */, undefined /** value **/, NumberingListType_1.NumberingListType.Min, NumberingListType_1.NumberingListType.Max),
unorderedStyleType: (0, definitionCreators_1.createNumberDefinition)(true /** isOptional */, undefined /** value **/, BulletListType_1.BulletListType.Min, BulletListType_1.BulletListType.Max),
}, true /** isOptional */, true /** allowNull */);

@@ -116,0 +117,0 @@ function shouldApplyToItem(listStyleType) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateTableMetadata = void 0;
var roosterjs_content_model_types_1 = require("roosterjs-content-model-types");
var TableBorderFormat_1 = require("../constants/TableBorderFormat");
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");

@@ -20,3 +20,3 @@ var definitionCreators_1 = require("./definitionCreators");

bgColorOdd: NullStringDefinition,
tableBorderFormat: (0, definitionCreators_1.createNumberDefinition)(false /** isOptional */, undefined /* value */, roosterjs_content_model_types_1.TableBorderFormat.DEFAULT /* first table border format, TODO: Use Min/Max to specify valid values */, roosterjs_content_model_types_1.TableBorderFormat.CLEAR /* last table border format, , TODO: Use Min/Max to specify valid values */),
tableBorderFormat: (0, definitionCreators_1.createNumberDefinition)(false /** isOptional */, undefined /* value */, TableBorderFormat_1.TableBorderFormat.Min /* first table border format */, TableBorderFormat_1.TableBorderFormat.Max /* last table border format */),
verticalAlign: NullStringDefinition,

@@ -23,0 +23,0 @@ }, false /* isOptional */, true /** allowNull */);

@@ -60,3 +60,3 @@ "use strict";

if (originalFormat) {
context.newPendingFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, EmptySegmentFormat), originalFormat); // Use empty format as initial value to clear any other format inherits from pasted content
context.newPendingFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, EmptySegmentFormat), model.format), originalFormat); // Use empty format as initial value to clear any other format inherits from pasted content
}

@@ -97,3 +97,5 @@ return true;

function createBeforePasteEventData(editor, clipboardData, pasteType) {
var _a;
var options = (0, roosterjs_editor_dom_1.createDefaultHtmlSanitizerOptions)();
(_a = options.additionalAllowedCssClasses).push.apply(_a, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(roosterjs_content_model_dom_1.AllowedEntityClasses), false));
// Remove "caret-color" style generated by Safari to make sure caret shows in right color after paste

@@ -100,0 +102,0 @@ options.cssStyleCallbacks['caret-color'] = function () { return false; };

@@ -9,3 +9,3 @@ "use strict";

var setTableCellBackgroundColor_1 = require("./setTableCellBackgroundColor");
var roosterjs_content_model_types_1 = require("roosterjs-content-model-types");
var TableBorderFormat_1 = require("../../constants/TableBorderFormat");
var updateTableCellMetadata_1 = require("../../metadata/updateTableCellMetadata");

@@ -24,3 +24,3 @@ var updateTableMetadata_1 = require("../../metadata/updateTableMetadata");

headerRowColor: '#ABABAB',
tableBorderFormat: roosterjs_content_model_types_1.TableBorderFormat.DEFAULT,
tableBorderFormat: TableBorderFormat_1.TableBorderFormat.Default,
verticalAlign: null,

@@ -87,4 +87,4 @@ };

var BorderFormatters = (_a = {},
_a[roosterjs_content_model_types_1.TableBorderFormat.DEFAULT] = function (_) { return [false, false, false, false]; },
_a[roosterjs_content_model_types_1.TableBorderFormat.LIST_WITH_SIDE_BORDERS] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.Default] = function (_) { return [false, false, false, false]; },
_a[TableBorderFormat_1.TableBorderFormat.ListWithSideBorders] = function (_a) {
var lastColumn = _a.lastColumn, firstColumn = _a.firstColumn;

@@ -98,3 +98,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.FIRST_COLUMN_HEADER_EXTERNAL] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.FirstColumnHeaderExternal] = function (_a) {
var firstColumn = _a.firstColumn, firstRow = _a.firstRow, lastColumn = _a.lastColumn, lastRow = _a.lastRow;

@@ -108,3 +108,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.NO_HEADER_BORDERS] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.NoHeaderBorders] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn, lastColumn = _a.lastColumn;

@@ -118,3 +118,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.NO_SIDE_BORDERS] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.NoSideBorders] = function (_a) {
var firstColumn = _a.firstColumn, lastColumn = _a.lastColumn;

@@ -128,3 +128,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.ESPECIAL_TYPE_1] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.EspecialType1] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn;

@@ -138,3 +138,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.ESPECIAL_TYPE_2] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.EspecialType2] = function (_a) {
var firstRow = _a.firstRow, firstColumn = _a.firstColumn;

@@ -148,3 +148,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.ESPECIAL_TYPE_3] = function (_a) {
_a[TableBorderFormat_1.TableBorderFormat.EspecialType3] = function (_a) {
var firstColumn = _a.firstColumn, firstRow = _a.firstRow;

@@ -158,3 +158,3 @@ return [

},
_a[roosterjs_content_model_types_1.TableBorderFormat.CLEAR] = function () { return [true, true, true, true]; },
_a[TableBorderFormat_1.TableBorderFormat.Clear] = function () { return [true, true, true, true]; },
_a);

@@ -168,5 +168,7 @@ /*

row.cells.forEach(function (cell, colIndex) {
var _a;
// Format Borders
if (!metaOverrides.borderOverrides[rowIndex][colIndex]) {
var transparentBorderMatrix = BorderFormatters[format.tableBorderFormat]({
if (!metaOverrides.borderOverrides[rowIndex][colIndex] &&
typeof format.tableBorderFormat == 'number') {
var transparentBorderMatrix = (_a = BorderFormatters[format.tableBorderFormat]) === null || _a === void 0 ? void 0 : _a.call(BorderFormatters, {
firstRow: rowIndex === 0,

@@ -183,3 +185,3 @@ lastRow: rowIndex === rows.length - 1,

];
transparentBorderMatrix.forEach(function (alwaysUseTransparent, i) {
transparentBorderMatrix === null || transparentBorderMatrix === void 0 ? void 0 : transparentBorderMatrix.forEach(function (alwaysUseTransparent, i) {
var borderColor = (!alwaysUseTransparent && formatColor_1[i]) || '';

@@ -186,0 +188,0 @@ cell.format[roosterjs_content_model_dom_1.BorderKeys[i]] = (0, borderValues_1.combineBorderValue)({

@@ -40,11 +40,4 @@ "use strict";

}
if (applyToSegments && cell.format.textColor) {
cell.blocks.forEach(function (block) {
if (block.blockType == 'Paragraph') {
block.segmentFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, block.segmentFormat), { textColor: cell.format.textColor });
block.segments.forEach(function (segment) {
segment.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, segment.format), { textColor: cell.format.textColor });
});
}
});
if (applyToSegments) {
setAdaptiveCellColor(cell);
}

@@ -55,2 +48,5 @@ }

delete cell.format.textColor;
if (applyToSegments) {
removeAdaptiveCellColor(cell);
}
}

@@ -60,2 +56,53 @@ delete cell.cachedElement;

exports.setTableCellBackgroundColor = setTableCellBackgroundColor;
function removeAdaptiveCellColor(cell) {
cell.blocks.forEach(function (block) {
var _a, _b;
if (block.blockType == 'Paragraph') {
if (((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor) &&
shouldRemoveColor((_b = block.segmentFormat) === null || _b === void 0 ? void 0 : _b.textColor, cell.format.backgroundColor || '')) {
delete block.segmentFormat.textColor;
}
block.segments.forEach(function (segment) {
if (segment.format.textColor &&
shouldRemoveColor(segment.format.textColor, cell.format.backgroundColor || '')) {
delete segment.format.textColor;
}
});
}
});
}
function setAdaptiveCellColor(cell) {
if (cell.format.textColor) {
cell.blocks.forEach(function (block) {
var _a;
if (block.blockType == 'Paragraph') {
if (!((_a = block.segmentFormat) === null || _a === void 0 ? void 0 : _a.textColor)) {
block.segmentFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, block.segmentFormat), { textColor: cell.format.textColor });
}
block.segments.forEach(function (segment) {
var _a;
if (!((_a = segment.format) === null || _a === void 0 ? void 0 : _a.textColor)) {
segment.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, segment.format), { textColor: cell.format.textColor });
}
});
}
});
}
}
/**
* If the cell background color is too dark or too bright, and the text color is white or black, we should remove the text color
* @param textColor the segment or block text color
* @param cellBackgroundColor the cell background color
* @returns
*/
function shouldRemoveColor(textColor, cellBackgroundColor) {
var lightness = calculateLightness(cellBackgroundColor);
if (([White, 'rgb(255,255,255)'].indexOf(textColor) > -1 &&
(lightness > BRIGHT_COLORS_LIGHTNESS || cellBackgroundColor == '')) ||
([Black, 'rgb(0,0,0)'].indexOf(textColor) > -1 &&
(lightness < DARK_COLORS_LIGHTNESS || cellBackgroundColor == ''))) {
return true;
}
return false;
}
function calculateLightness(color) {

@@ -62,0 +109,0 @@ var colorValues = parseColor(color);

@@ -6,9 +6,9 @@ {

"tslib": "^2.3.1",
"color": "^3.0.0",
"roosterjs-editor-types": "^8.59.0",
"roosterjs-editor-dom": "^8.59.0",
"roosterjs-editor-core": "^8.59.0",
"roosterjs-content-model-dom": "^0.20.0",
"roosterjs-content-model-types": "^0.20.0"
"roosterjs-content-model-dom": "^0.21.0",
"roosterjs-content-model-types": "^0.21.0"
},
"version": "0.20.0",
"version": "0.21.0",
"main": "./lib/index.js",

@@ -15,0 +15,0 @@ "typings": "./lib/index.d.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc