Skip to content

Commit

Permalink
Merge pull request #2274 from flyingbee2012/biwu/vb1215
Browse files Browse the repository at this point in the history
Bump up packages-content-model to 0.22.0
  • Loading branch information
flyingbee2012 authored Dec 16, 2023
2 parents ea267e5 + bb332a5 commit 35fd20f
Show file tree
Hide file tree
Showing 217 changed files with 14,406 additions and 2,705 deletions.
20 changes: 15 additions & 5 deletions demo/scripts/controls/ContentModelEditorMainPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import ContentModelFormatStatePlugin from './sidePane/formatState/ContentModelFo
import ContentModelPanePlugin from './sidePane/contentModel/ContentModelPanePlugin';
import ContentModelRibbon from './ribbonButtons/contentModel/ContentModelRibbon';
import ContentModelRooster from './contentModel/editor/ContentModelRooster';
import ContentModelSnapshotPlugin from './sidePane/snapshot/ContentModelSnapshotPlugin';
import getToggleablePlugins from './getToggleablePlugins';
import MainPaneBase, { MainPaneBaseState } from './MainPaneBase';
import SampleEntityPlugin from './sampleEntity/SampleEntityPlugin';
import SidePane from './sidePane/SidePane';
import SnapshotPlugin from './sidePane/snapshot/SnapshotPlugin';
import TitleBar from './titleBar/TitleBar';
import { arrayPush } from 'roosterjs-editor-dom';
import { ContentModelEditPlugin, EntityDelimiterPlugin } from 'roosterjs-content-model-plugins';
import { ContentModelRibbonPlugin } from './ribbonButtons/contentModel/ContentModelRibbonPlugin';
import { ContentModelSegmentFormat } from 'roosterjs-content-model-types';
import { ContentModelSegmentFormat, Snapshot } from 'roosterjs-content-model-types';
import { createEmojiPlugin, createPasteOptionPlugin, RibbonPlugin } from 'roosterjs-react';
import { EditorPlugin } from 'roosterjs-editor-types';
import { EditorPlugin, Snapshots } from 'roosterjs-editor-types';
import { getDarkColor } from 'roosterjs-color-utils';
import { PartialTheme } from '@fluentui/react/lib/Theme';
import { trustedHTMLHandler } from '../utils/trustedHTMLHandler';
Expand Down Expand Up @@ -99,19 +99,29 @@ class ContentModelEditorMainPane extends MainPaneBase<ContentModelMainPaneState>
private contentModelRibbonPlugin: RibbonPlugin;
private pasteOptionPlugin: EditorPlugin;
private emojiPlugin: EditorPlugin;
private snapshotPlugin: ContentModelSnapshotPlugin;
private entityDelimiterPlugin: EntityDelimiterPlugin;
private toggleablePlugins: EditorPlugin[] | null = null;
private formatPainterPlugin: ContentModelFormatPainterPlugin;
private sampleEntityPlugin: SampleEntityPlugin;
private snapshots: Snapshots<Snapshot>;

constructor(props: {}) {
super(props);

this.snapshots = {
snapshots: [],
totalSize: 0,
currentIndex: -1,
autoCompleteIndex: -1,
maxSize: 1e7,
};

this.formatStatePlugin = new ContentModelFormatStatePlugin();
this.editorOptionPlugin = new ContentModelEditorOptionsPlugin();
this.eventViewPlugin = new ContentModelEventViewPlugin();
this.apiPlaygroundPlugin = new ApiPlaygroundPlugin();
this.snapshotPlugin = new SnapshotPlugin();
this.snapshotPlugin = new ContentModelSnapshotPlugin(this.snapshots);
this.contentModelPanePlugin = new ContentModelPanePlugin();
this.contentModelEditPlugin = new ContentModelEditPlugin();
this.contentModelRibbonPlugin = new ContentModelRibbonPlugin();
Expand Down Expand Up @@ -239,7 +249,7 @@ class ContentModelEditorMainPane extends MainPaneBase<ContentModelMainPaneState>
inDarkMode={this.state.isDarkMode}
getDarkColor={getDarkColor}
experimentalFeatures={this.state.initState.experimentalFeatures}
undoMetadataSnapshotService={this.snapshotPlugin.getSnapshotService()}
snapshotsManager={this.snapshotPlugin.getSnapshotsManager()}
trustedHTMLHandler={trustedHTMLHandler}
zoomScale={this.state.scale}
initialContent={this.content}
Expand Down
1 change: 1 addition & 0 deletions demo/scripts/controls/MainPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class MainPane extends MainPaneBase<MainPaneState> {
private emojiPlugin: EditorPlugin;
private toggleablePlugins: EditorPlugin[] | null = null;
private sampleEntityPlugin: SampleEntityPlugin;
private snapshotPlugin: SnapshotPlugin;
private mainWindowButtons: RibbonButton<RibbonStringKeys>[];
private popoutWindowButtons: RibbonButton<RibbonStringKeys>[];

Expand Down
4 changes: 1 addition & 3 deletions demo/scripts/controls/MainPaneBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import BuildInPluginState from './BuildInPluginState';
import SidePane from './sidePane/SidePane';
import SnapshotPlugin from './sidePane/snapshot/SnapshotPlugin';
import { Border } from 'roosterjs-content-model-types';
import { createUpdateContentPlugin, UpdateContentPlugin, UpdateMode } from 'roosterjs-react';
import { EditorPlugin } from 'roosterjs-editor-types';
import { PartialTheme, ThemeProvider } from '@fluentui/react/lib/Theme';
import { registerWindowForCss, unregisterWindowForCss } from '../utils/cssMonitor';
import { trustedHTMLHandler } from '../utils/trustedHTMLHandler';
import { WindowProvider } from '@fluentui/react/lib/WindowProvider';
import { createUpdateContentPlugin, UpdateContentPlugin, UpdateMode } from 'roosterjs-react';

export interface MainPaneBaseState {
showSidePane: boolean;
Expand Down Expand Up @@ -37,7 +36,6 @@ export default abstract class MainPaneBase<T extends MainPaneBaseState> extends

protected sidePane = React.createRef<SidePane>();
protected updateContentPlugin: UpdateContentPlugin;
protected snapshotPlugin: SnapshotPlugin;
protected content: string = '';
protected themeMatch = window.matchMedia?.('(prefers-color-scheme: dark)');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { BlockGroupContentView } from './BlockGroupContentView';
import { ContentModelDocument } from 'roosterjs-content-model-types';
import { ContentModelView } from '../ContentModelView';
import { hasSelectionInBlockGroup } from 'roosterjs-content-model-api';
import { hasSelectionInBlockGroup } from 'roosterjs-content-model-core';

const styles = require('./ContentModelDocumentView.scss');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContentModelView } from '../ContentModelView';
import { DisplayFormatRenderer } from '../format/formatPart/DisplayFormatRenderer';
import { FormatRenderer } from '../format/utils/FormatRenderer';
import { FormatView } from '../format/FormatView';
import { hasSelectionInBlock } from 'roosterjs-content-model-api';
import { hasSelectionInBlock } from 'roosterjs-content-model-core';
import { SegmentFormatView } from '../format/SegmentFormatView';
import { SizeFormatRenderers } from '../format/formatPart/SizeFormatRenderers';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BlockGroupContentView } from './BlockGroupContentView';
import { ContentModelCodeView } from './ContentModelCodeView';
import { ContentModelLinkView } from './ContentModelLinkView';
import { ContentModelView } from '../ContentModelView';
import { hasSelectionInBlock } from 'roosterjs-content-model-api';
import { hasSelectionInBlock } from 'roosterjs-content-model-core';
import { SegmentFormatView } from '../format/SegmentFormatView';
import {
ContentModelGeneralBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FontFamilyFormatRenderer } from '../format/formatPart/FontFamilyFormatR
import { FontSizeFormatRenderer } from '../format/formatPart/FontSizeFormatRenderer';
import { FormatRenderer } from '../format/utils/FormatRenderer';
import { FormatView } from '../format/FormatView';
import { hasSelectionInBlockGroup } from 'roosterjs-content-model-api';
import { hasSelectionInBlockGroup } from 'roosterjs-content-model-core';
import { LineHeightFormatRenderer } from '../format/formatPart/LineHeightFormatRenderer';
import { MarginFormatRenderer } from '../format/formatPart/MarginFormatRenderer';
import { TextAlignFormatRenderer } from '../format/formatPart/TextAlignFormatRenderer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { BlockFormatView } from '../format/BlockFormatView';
import { ContentModelSegmentView } from './ContentModelSegmentView';
import { ContentModelView } from '../ContentModelView';
import { hasSelectionInBlock } from 'roosterjs-content-model-api';
import { hasSelectionInBlock } from 'roosterjs-content-model-core';
import { SegmentFormatView } from '../format/SegmentFormatView';
import { useProperty } from '../../hooks/useProperty';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import { ContentModelView } from '../ContentModelView';
import { DirectionFormatRenderer } from '../format/formatPart/DirectionFormatRenderer';
import { FormatRenderer } from '../format/utils/FormatRenderer';
import { FormatView } from '../format/FormatView';
import { hasSelectionInBlockGroup } from 'roosterjs-content-model-api';
import { hasSelectionInBlockGroup, updateTableCellMetadata } from 'roosterjs-content-model-core';
import { HtmlAlignFormatRenderer } from '../format/formatPart/HtmlAlignFormatRenderer';
import { MetadataView } from '../format/MetadataView';
import { PaddingFormatRenderer } from '../format/formatPart/PaddingFormatRenderer';
import { SizeFormatRenderers } from '../format/formatPart/SizeFormatRenderers';
import { TableCellMetadataFormatRenders } from '../format/formatPart/TableCellMetadataFormatRenders';
import { TextAlignFormatRenderer } from '../format/formatPart/TextAlignFormatRenderer';
import { TextColorFormatRenderer } from '../format/formatPart/TextColorFormatRenderer';
import { updateTableCellMetadata } from 'roosterjs-content-model-core';
import { useProperty } from '../../hooks/useProperty';
import { VerticalAlignFormatRenderer } from '../format/formatPart/VerticalAlignFormatRenderer';
import { WordBreakFormatRenderer } from '../format/formatPart/WordBreakFormatRenderer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContentModelBlockGroupView } from './ContentModelBlockGroupView';
import { ContentModelView } from '../ContentModelView';
import { FormatRenderer } from '../format/utils/FormatRenderer';
import { FormatView } from '../format/FormatView';
import { hasSelectionInBlockGroup } from 'roosterjs-content-model-api';
import { hasSelectionInBlockGroup } from 'roosterjs-content-model-core';
import { useProperty } from '../../hooks/useProperty';

const styles = require('./ContentModelTableRowView.scss');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ContentModelView } from '../ContentModelView';
import { DisplayFormatRenderer } from '../format/formatPart/DisplayFormatRenderer';
import { FormatRenderer } from '../format/utils/FormatRenderer';
import { FormatView } from '../format/FormatView';
import { hasSelectionInBlock } from 'roosterjs-content-model-api';
import { hasSelectionInBlock } from 'roosterjs-content-model-core';
import { IdFormatRenderer } from '../format/formatPart/IdFormatRenderer';
import { MarginFormatRenderer } from '../format/formatPart/MarginFormatRenderer';
import { MetadataView } from '../format/MetadataView';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { ltrButton } from './ltrButton';
import { numberedListButton } from './numberedListButton';
import { pasteButton } from './pasteButton';
import { popout } from '../popout';
import { redoButton } from './redoButton';
import { removeLinkButton } from './removeLinkButton';
import { Ribbon, RibbonButton, RibbonPlugin } from 'roosterjs-react';
import { rtlButton } from './rtlButton';
Expand All @@ -52,6 +53,7 @@ import { tableBorderStyleButton } from './tableBorderStyleButton';
import { tableBorderWidthButton } from './tableBorderWidthButton';
import { textColorButton } from './textColorButton';
import { underlineButton } from './underlineButton';
import { undoButton } from './undoButton';
import { zoom } from '../zoom';
import {
tableAlignCellButton,
Expand Down Expand Up @@ -92,6 +94,8 @@ const buttons = [
codeButton,
ltrButton,
rtlButton,
undoButton,
redoButton,
clearFormatButton,
setBulletedListStyleButton,
setNumberedListStyleButton,
Expand Down
20 changes: 20 additions & 0 deletions demo/scripts/controls/ribbonButtons/contentModel/redoButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { isContentModelEditor } from 'roosterjs-content-model-editor';
import { redo } from 'roosterjs-content-model-core';
import { RedoButtonStringKey, RibbonButton } from 'roosterjs-react';

/**
* @internal
* "Undo" button on the format ribbon
*/
export const redoButton: RibbonButton<RedoButtonStringKey> = {
key: 'buttonNameRedo',
unlocalizedText: 'Redo',
iconName: 'Redo',
isDisabled: formatState => !formatState.canRedo,
onClick: editor => {
if (isContentModelEditor(editor)) {
redo(editor);
}
return true;
},
};
20 changes: 20 additions & 0 deletions demo/scripts/controls/ribbonButtons/contentModel/undoButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { isContentModelEditor } from 'roosterjs-content-model-editor';
import { RibbonButton, UndoButtonStringKey } from 'roosterjs-react';
import { undo } from 'roosterjs-content-model-core';

/**
* @internal
* "Undo" button on the format ribbon
*/
export const undoButton: RibbonButton<UndoButtonStringKey> = {
key: 'buttonNameUndo',
unlocalizedText: 'Undo',
iconName: 'undo',
isDisabled: formatState => !formatState.canUndo,
onClick: editor => {
if (isContentModelEditor(editor)) {
undo(editor);
}
return true;
},
};
144 changes: 144 additions & 0 deletions demo/scripts/controls/sidePane/snapshot/ContentModelSnapshotPane.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import * as React from 'react';
import { EntityState, Snapshot, SnapshotSelection } from 'roosterjs-content-model-types';
import { ModeIndependentColor } from 'roosterjs-editor-types';

const styles = require('./SnapshotPane.scss');

export interface ContentModelSnapshotPaneProps {
onTakeSnapshot: () => Snapshot;
onRestoreSnapshot: (snapshot: Snapshot, triggerContentChangedEvent: boolean) => void;
onMove: (moveStep: number) => void;
}

export interface ContentModelSnapshotPaneState {
snapshots: Snapshot[];
currentIndex: number;
autoCompleteIndex: number;
}

export default class ContentModelSnapshotPane extends React.Component<
ContentModelSnapshotPaneProps,
ContentModelSnapshotPaneState
> {
private html = React.createRef<HTMLTextAreaElement>();
private knownColors = React.createRef<HTMLTextAreaElement>();
private entityStates = React.createRef<HTMLTextAreaElement>();
private isDarkColor = React.createRef<HTMLInputElement>();
private selection = React.createRef<HTMLTextAreaElement>();

constructor(props: ContentModelSnapshotPaneProps) {
super(props);

this.state = {
snapshots: [],
currentIndex: -1,
autoCompleteIndex: -1,
};
}

render() {
return (
<div className={styles.snapshotPane}>
<h3>Undo Snapshots</h3>
<div className={styles.snapshotList}>
{this.state.snapshots.map(this.renderItem)}
</div>
<h3>Selected Snapshot</h3>
<div className={styles.buttons}>
<button onClick={this.takeSnapshot}>{'Take snapshot'}</button>{' '}
<button onClick={this.onClickRestoreSnapshot}>{'Restore snapshot'}</button>
</div>
<div>HTML:</div>
<textarea ref={this.html} className={styles.textarea} spellCheck={false} />
<div>Selection:</div>
<textarea ref={this.selection} className={styles.textarea} spellCheck={false} />
<div>Entity states:</div>
<textarea ref={this.entityStates} className={styles.textarea} spellCheck={false} />
<div>Known colors:</div>
<textarea ref={this.knownColors} className={styles.textarea} spellCheck={false} />
<div>
<input type="checkbox" ref={this.isDarkColor} id="isUndoInDarkColor" />
<label htmlFor="isUndoInDarkColor">Is in dark mode</label>
</div>
</div>
);
}

private onClickRestoreSnapshot = () => {
const html = this.html.current.value;
const selection = this.selection.current.value
? (JSON.parse(this.selection.current.value) as SnapshotSelection)
: undefined;
const knownColors = this.knownColors.current.value
? (JSON.parse(this.knownColors.current.value) as ModeIndependentColor[])
: [];
const entityStates = this.entityStates.current.value
? (JSON.parse(this.entityStates.current.value) as EntityState[])
: undefined;
const isDarkMode = !!this.isDarkColor.current.checked;

this.props.onRestoreSnapshot(
{
html,
knownColors,
entityStates,
isDarkMode,
selection,
},
true
);
};

updateSnapshots(snapshots: Snapshot[], currentIndex: number, autoCompleteIndex: number) {
this.setState({
snapshots,
currentIndex,
autoCompleteIndex,
});
}

snapshotToString(snapshot: Snapshot) {
return (
snapshot.html +
(snapshot.selection ? `<!--${JSON.stringify(snapshot.selection)}-->` : '')
);
}

private takeSnapshot = () => {
const snapshot = this.props.onTakeSnapshot();
this.setSnapshot(snapshot);
};

private setSnapshot = (snapshot: Snapshot) => {
this.html.current.value = snapshot.html;
this.entityStates.current.value = snapshot.entityStates
? JSON.stringify(snapshot.entityStates)
: '';
this.knownColors.current.value = snapshot.knownColors
? JSON.stringify(snapshot.knownColors)
: '';
this.selection.current.value = snapshot.selection ? JSON.stringify(snapshot.selection) : '';
this.isDarkColor.current.checked = !!snapshot.isDarkMode;
};

private renderItem = (snapshot: Snapshot, index: number) => {
let className = '';
if (index == this.state.currentIndex) {
className += ' ' + styles.current;
}
if (index == this.state.autoCompleteIndex) {
className += ' ' + styles.autoComplete;
}

const snapshotStr = this.snapshotToString(snapshot);
return (
<pre
className={className}
key={index}
onClick={() => this.setSnapshot(snapshot)}
onDoubleClick={() => this.props.onMove(index - this.state.currentIndex)}>
{(snapshotStr || '<EMPTY SNAPSHOT>').substring(0, 1000)}
</pre>
);
};
}
Loading

0 comments on commit 35fd20f

Please sign in to comment.