Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move paste plugin to roosterjs-content-model-plugins package #2192

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/scripts/controls/getToggleablePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BuildInPluginState, { BuildInPluginList, UrlPlaceholder } from './BuildIn
import { Announce } from 'roosterjs-editor-plugins/lib/Announce';
import { AutoFormat } from 'roosterjs-editor-plugins/lib/AutoFormat';
import { ContentEdit } from 'roosterjs-editor-plugins/lib/ContentEdit';
import { ContentModelPastePlugin } from 'roosterjs-content-model-editor';
import { ContentModelPastePlugin } from 'roosterjs-content-model-plugins';
import { CustomReplace as CustomReplacePlugin } from 'roosterjs-editor-plugins/lib/CustomReplace';
import { CutPasteListChain } from 'roosterjs-editor-plugins/lib/CutPasteListChain';
import { EditorPlugin, KnownAnnounceStrings } from 'roosterjs-editor-types';
Expand Down
8 changes: 4 additions & 4 deletions demo/scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
"roosterjs-content-model-editor/lib/*": [
"packages-content-model/roosterjs-content-model-editor/lib/*"
],
"roosterjs-content-model-adapter": [
"packages-content-model/roosterjs-content-model-adapter/lib/index"
"roosterjs-content-model-plugins": [
"packages-content-model/roosterjs-content-model-plugins/lib/index"
],
"roosterjs-content-model-adapter/lib/*": [
"packages-content-model/roosterjs-content-model-adapter/lib/*"
"roosterjs-content-model-plugins/lib/*": [
"packages-content-model/roosterjs-content-model-plugins/lib/*"
],
"roosterjs-react": ["packages-ui/roosterjs-react/lib/index"],
"roosterjs-react/lib/*": ["packages-ui/roosterjs-react/lib/*"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloneModel } from '../../modelApi/common/cloneModel';
import { cloneModel } from '../../publicApi/model/cloneModel';
import type { DOMSelection, DomToModelOption } from 'roosterjs-content-model-types';
import {
createDomToModelContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import paste from '../../publicApi/utils/paste';
import { addRangeToSelection } from '../../domUtils/addRangeToSelection';
import { ChangeSource } from '../../publicTypes/event/ContentModelContentChangedEvent';
import { cloneModel } from '../../modelApi/common/cloneModel';
import { cloneModel } from '../../publicApi/model/cloneModel';
import { ColorTransformDirection, PluginEventType } from 'roosterjs-editor-types';
import { DeleteResult } from '../../modelApi/edit/utils/DeleteSelectionStep';
import { deleteSelection } from '../../modelApi/edit/deleteSelection';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ export { default as setParagraphMargin } from './publicApi/block/setParagraphMar
export { default as toggleCode } from './publicApi/segment/toggleCode';
export { default as paste } from './publicApi/utils/paste';
export { default as insertEntity } from './publicApi/entity/insertEntity';
export { CachedElementHandler, CloneModelOptions, cloneModel } from './publicApi/model/cloneModel';

export { default as ContentModelEditor } from './editor/ContentModelEditor';
export { default as isContentModelEditor } from './editor/isContentModelEditor';
export { default as ContentModelPastePlugin } from './editor/plugins/PastePlugin/ContentModelPastePlugin';

export { default as ContentModelFormatPlugin } from './editor/corePlugins/ContentModelFormatPlugin';
export { default as ContentModelEditPlugin } from './editor/corePlugins/ContentModelEditPlugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ import type {
} from 'roosterjs-content-model-types';

/**
* @internal
* Function type used for cloneModel API to specify how to handle cached element when clone a model
* @param node The cached node
* @param type Type of the node, it can be
* - general: DOM element of ContentModelGeneralSegment or ContentModelGeneralBlock
* - entity: Wrapper element in ContentModelEntity
* - cache: Cached node in other model element that supports cache
*/
export type CachedElementHandler = (
node: HTMLElement,
type: 'general' | 'entity' | 'cache'
) => HTMLElement | undefined;

/**
* @internal
*
* Options for cloneModel API
*/
export interface CloneModelOptions {
Expand All @@ -51,7 +56,9 @@ export interface CloneModelOptions {
}

/**
* @internal
* Clone a content model
* @param model The content model to clone
* @param options @optional Options to specify customize the clone behavior
*/
export function cloneModel(
model: ContentModelDocument,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as cloneModel from '../../../lib/modelApi/common/cloneModel';
import * as cloneModel from '../../../lib/publicApi/model/cloneModel';
import * as createDomToModelContext from 'roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext';
import * as domToContentModel from 'roosterjs-content-model-dom/lib/domToModel/domToContentModel';
import { ContentModelEditorCore } from '../../../lib/publicTypes/ContentModelEditorCore';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as addRangeToSelection from '../../../lib/domUtils/addRangeToSelection';
import * as cloneModelFile from '../../../lib/modelApi/common/cloneModel';
import * as cloneModelFile from '../../../lib/publicApi/model/cloneModel';
import * as contentModelToDomFile from 'roosterjs-content-model-dom/lib/modelToDom/contentModelToDom';
import * as deleteSelectionsFile from '../../../lib/modelApi/edit/deleteSelection';
import * as extractClipboardItemsFile from 'roosterjs-editor-dom/lib/clipboard/extractClipboardItems';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloneModel } from '../../../lib/modelApi/common/cloneModel';
import { cloneModel } from '../../../lib/publicApi/model/cloneModel';
import { ContentModelDocument } from 'roosterjs-content-model-types';
import { createEntity } from 'roosterjs-content-model-dom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import * as addParserF from '../../../lib/editor/plugins/PastePlugin/utils/addParser';
import * as addParserF from '../../../../roosterjs-content-model-plugins/lib/paste/utils/addParser';
import * as domToContentModel from 'roosterjs-content-model-dom/lib/domToModel/domToContentModel';
import * as ExcelF from '../../../lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel';
import * as getPasteSourceF from '../../../lib/editor/plugins/PastePlugin/pasteSourceValidations/getPasteSource';
import * as ExcelF from '../../../../roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel';
import * as getPasteSourceF from '../../../../roosterjs-content-model-plugins/lib/paste/pasteSourceValidations/getPasteSource';
import * as getSelectedSegmentsF from '../../../lib/publicApi/selection/getSelectedSegments';
import * as mergeModelFile from '../../../lib/modelApi/common/mergeModel';
import * as pendingFormatF from '../../../lib/modelApi/format/pendingFormat';
import * as PPT from '../../../lib/editor/plugins/PastePlugin/PowerPoint/processPastedContentFromPowerPoint';
import * as setProcessorF from '../../../lib/editor/plugins/PastePlugin/utils/setProcessor';
import * as WacComponents from '../../../lib/editor/plugins/PastePlugin/WacComponents/processPastedContentWacComponents';
import * as WordDesktopFile from '../../../lib/editor/plugins/PastePlugin/WordDesktop/processPastedContentFromWordDesktop';
import * as PPT from '../../../../roosterjs-content-model-plugins/lib/paste/PowerPoint/processPastedContentFromPowerPoint';
import * as setProcessorF from '../../../../roosterjs-content-model-plugins/lib/paste/utils/setProcessor';
import * as WacComponents from '../../../../roosterjs-content-model-plugins/lib/paste/WacComponents/processPastedContentWacComponents';
import * as WordDesktopFile from '../../../../roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop';
import ContentModelEditor from '../../../lib/editor/ContentModelEditor';
import ContentModelPastePlugin from '../../../lib/editor/plugins/PastePlugin/ContentModelPastePlugin';
import { ContentModelDocument, DomToModelOption } from 'roosterjs-content-model-types';
import { ContentModelPastePlugin } from '../../../../roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin';
import { createContentModelDocument, tableProcessor } from 'roosterjs-content-model-dom';
import { expectEqual, initEditor } from '../../editor/plugins/paste/e2e/testUtils';
import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor';
import {
expectEqual,
initEditor,
} from '../../../../roosterjs-content-model-plugins/test/paste/e2e/testUtils';
import {
ContentModelFormatter,
FormatWithContentModelOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ContentModelPastePlugin } from './paste/ContentModelPastePlugin';
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import { processPastedContentFromExcel } from './Excel/processPastedContentFromE
import { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';
import { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';
import { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';
import type { PasteType } from '../../../publicTypes/parameter/PasteType';
import type ContentModelBeforePasteEvent from '../../../publicTypes/event/ContentModelBeforePasteEvent';
import type {
ContentModelBeforePasteEvent,
IContentModelEditor,
PasteType,
} from 'roosterjs-content-model-editor';
import type {
BorderFormat,
ContentModelBlockFormat,
ContentModelTableCellFormat,
FormatParser,
} from 'roosterjs-content-model-types';
import type { IContentModelEditor } from '../../../publicTypes/IContentModelEditor';
import type {
EditorPlugin,
HtmlSanitizerOptions,
Expand All @@ -43,7 +45,7 @@ const PasteTypeMap: Record<OldPasteType, PasteType> = {
* 4. Content copied from Power Point
* (This class is still under development, and may still be changed in the future with some breaking changes)
*/
export default class ContentModelPastePlugin implements EditorPlugin {
export class ContentModelPastePlugin implements EditorPlugin {
private editor: IContentModelEditor | null = null;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import addParser from '../utils/addParser';
import { isNodeOfType, moveChildNodes } from 'roosterjs-content-model-dom';
import { setProcessor } from '../utils/setProcessor';
import type ContentModelBeforePasteEvent from '../../../../publicTypes/event/ContentModelBeforePasteEvent';
import type { TrustedHTMLHandler } from 'roosterjs-editor-types';
import type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-editor';

const LAST_TD_END_REGEX = /<\/\s*td\s*>((?!<\/\s*tr\s*>)[\s\S])*$/i;
const LAST_TR_END_REGEX = /<\/\s*tr\s*>((?!<\/\s*table\s*>)[\s\S])*$/i;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import addParser from '../utils/addParser';
import { setProcessor } from '../utils/setProcessor';
import type ContentModelBeforePasteEvent from '../../../../publicTypes/event/ContentModelBeforePasteEvent';
import type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-editor';
import type {
ContentModelBlockFormat,
ContentModelBlockGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { moveChildNodes } from 'roosterjs-content-model-dom';
import { processWordComments } from './processWordComments';
import { processWordList } from './processWordLists';
import { setProcessor } from '../utils/setProcessor';
import type ContentModelBeforePasteEvent from '../../../../publicTypes/event/ContentModelBeforePasteEvent';
import type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-editor';
import type {
ContentModelBlockFormat,
ContentModelListItemFormat,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "roosterjs-content-model-plugins",
"description": "Content Model for roosterjs (Under development)",
"dependencies": {
"tslib": "^2.3.1",
"roosterjs-editor-types": "",
"roosterjs-editor-dom": "",
"roosterjs-editor-core": "",
"roosterjs-content-model-editor": "",
"roosterjs-content-model-dom": "",
"roosterjs-content-model-types": ""
},
"version": "0.0.0",
"main": "./lib/index.ts"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as addParser from '../../../lib/editor/plugins/PastePlugin/utils/addParser';
import * as addParser from '../../lib/paste/utils/addParser';
import * as chainSanitizerCallbackFile from 'roosterjs-editor-dom/lib/htmlSanitizer/chainSanitizerCallback';
import * as ExcelFile from '../../../lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel';
import * as getPasteSource from '../../../lib/editor/plugins/PastePlugin/pasteSourceValidations/getPasteSource';
import * as PowerPointFile from '../../../lib/editor/plugins/PastePlugin/PowerPoint/processPastedContentFromPowerPoint';
import * as setProcessor from '../../../lib/editor/plugins/PastePlugin/utils/setProcessor';
import * as WacFile from '../../../lib/editor/plugins/PastePlugin/WacComponents/processPastedContentWacComponents';
import * as WordDesktopFile from '../../../lib/editor/plugins/PastePlugin/WordDesktop/processPastedContentFromWordDesktop';
import ContentModelBeforePasteEvent from '../../../lib/publicTypes/event/ContentModelBeforePasteEvent';
import ContentModelPastePlugin from '../../../lib/editor/plugins/PastePlugin/ContentModelPastePlugin';
import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor';
import { PastePropertyNames } from '../../../lib/editor/plugins/PastePlugin/pasteSourceValidations/constants';
import * as ExcelFile from '../../lib/paste/Excel/processPastedContentFromExcel';
import * as getPasteSource from '../../lib/paste/pasteSourceValidations/getPasteSource';
import * as PowerPointFile from '../../lib/paste/PowerPoint/processPastedContentFromPowerPoint';
import * as setProcessor from '../../lib/paste/utils/setProcessor';
import * as WacFile from '../../lib/paste/WacComponents/processPastedContentWacComponents';
import * as WordDesktopFile from '../../lib/paste/WordDesktop/processPastedContentFromWordDesktop';
import { ContentModelBeforePasteEvent, IContentModelEditor } from 'roosterjs-content-model-editor';
import { ContentModelPastePlugin } from '../../lib/paste/ContentModelPastePlugin';
import { PastePropertyNames } from '../../lib/paste/pasteSourceValidations/constants';
import { PasteType, PluginEventType } from 'roosterjs-editor-types';

const trustedHTMLHandler = <any>'mock';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deprecatedBorderColorParser } from '../../../../lib/editor/plugins/PastePlugin/utils/deprecatedColorParser';
import { deprecatedBorderColorParser } from '../../lib/paste/utils/deprecatedColorParser';

const DeprecatedColors: string[] = [
'activeborder',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as processPastedContentFromExcel from '../../../../../lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel';
import paste from '../../../../../lib/publicApi/utils/paste';
import * as processPastedContentFromExcel from '../../../lib/paste/Excel/processPastedContentFromExcel';
import { ClipboardData } from 'roosterjs-editor-types';
import { expectEqual, initEditor } from './testUtils';
import { IContentModelEditor } from '../../../../../lib/publicTypes/IContentModelEditor';
import { IContentModelEditor, paste } from 'roosterjs-content-model-editor';
import { itChromeOnly } from 'roosterjs-editor-dom/test/DomTestHelper';
import { tableProcessor } from 'roosterjs-content-model-dom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as processPastedContentFromExcel from '../../../../../lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel';
import paste from '../../../../../lib/publicApi/utils/paste';
import * as processPastedContentFromExcel from '../../../lib/paste/Excel/processPastedContentFromExcel';
import { Browser } from 'roosterjs-editor-dom';
import { ClipboardData } from 'roosterjs-editor-types';
import { expectEqual, initEditor } from './testUtils';
import { IContentModelEditor } from '../../../../../lib/publicTypes/IContentModelEditor';
import { IContentModelEditor, paste } from 'roosterjs-content-model-editor';
import { itChromeOnly } from 'roosterjs-editor-dom/test/DomTestHelper';
import { tableProcessor } from 'roosterjs-content-model-dom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as processPastedContentWacComponents from '../../../../../lib/editor/plugins/PastePlugin/WacComponents/processPastedContentWacComponents';
import paste from '../../../../../lib/publicApi/utils/paste';
import * as processPastedContentWacComponents from '../../../lib/paste/WacComponents/processPastedContentWacComponents';
import { ClipboardData } from 'roosterjs-editor-types';
import { DomToModelOption } from 'roosterjs-content-model-types';
import { expectEqual, initEditor } from './testUtils';
import { IContentModelEditor } from '../../../../../lib/publicTypes/IContentModelEditor';
import { IContentModelEditor, paste } from 'roosterjs-content-model-editor';
import { tableProcessor } from 'roosterjs-content-model-dom';

const ID = 'CM_Paste_From_WORD_Online_E2E';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as wordFile from '../../../../../lib/editor/plugins/PastePlugin/WordDesktop/processPastedContentFromWordDesktop';
import paste from '../../../../../lib/publicApi/utils/paste';
import * as wordFile from '../../../lib/paste/WordDesktop/processPastedContentFromWordDesktop';
import { ClipboardData } from 'roosterjs-editor-types';
import { cloneModel } from '../../../../../lib/modelApi/common/cloneModel';
import { cloneModel, IContentModelEditor, paste } from 'roosterjs-content-model-editor';
import { DomToModelOption } from 'roosterjs-content-model-types';
import { expectEqual, initEditor } from './testUtils';
import { IContentModelEditor } from '../../../../../lib/publicTypes/IContentModelEditor';
import { itChromeOnly } from 'roosterjs-editor-dom/test/DomTestHelper';
import { tableProcessor } from 'roosterjs-content-model-dom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as wordFile from '../../../../../lib/editor/plugins/PastePlugin/WordDesktop/processPastedContentFromWordDesktop';
import paste from '../../../../../lib/publicApi/utils/paste';
import * as wordFile from '../../../lib/paste/WordDesktop/processPastedContentFromWordDesktop';
import { ClipboardData } from 'roosterjs-editor-types';
import { DomToModelOption } from 'roosterjs-content-model-types';
import { expectEqual, initEditor } from './testUtils';
import { IContentModelEditor } from '../../../../../lib/publicTypes/IContentModelEditor';
import { IContentModelEditor, paste } from 'roosterjs-content-model-editor';
import { itChromeOnly } from 'roosterjs-editor-dom/test/DomTestHelper';
import { tableProcessor } from 'roosterjs-content-model-dom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ContentModelEditor from '../../../../../lib/editor/ContentModelEditor';
import ContentModelPastePlugin from '../../../../../lib/editor/plugins/PastePlugin/ContentModelPastePlugin';
import { cloneModel } from '../../../../../lib/modelApi/common/cloneModel';
import { ContentModelDocument } from 'roosterjs-content-model-types';
import { ContentModelPastePlugin } from '../../../lib/paste/ContentModelPastePlugin';
import {
ContentModelEditorOptions,
ContentModelEditor,
IContentModelEditor,
} from '../../../../../lib/publicTypes/IContentModelEditor';
cloneModel,
} from 'roosterjs-content-model-editor';

export function initEditor(id: string) {
export function initEditor(id: string): IContentModelEditor {
let node = document.createElement('div');
node.id = id;
document.body.insertBefore(node, document.body.childNodes[0]);
Expand All @@ -26,7 +26,7 @@ export function initEditor(id: string) {

let editor = new ContentModelEditor(node as HTMLDivElement, options);

return editor as IContentModelEditor;
return editor;
}

export function expectEqual(model1: ContentModelDocument, model2: ContentModelDocument) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ContentModelDocument } from 'roosterjs-content-model-types';
import { createBeforePasteEventMock } from './processPastedContentFromWordDesktopTest';
import { parseLink } from '../../../../lib/editor/plugins/PastePlugin/utils/linkParser';
import { parseLink } from '../../lib/paste/utils/linkParser';
import {
contentModelToDom,
createDomToModelContext,
Expand Down
Loading
Loading