Skip to content

Commit

Permalink
Port demo site 1: Move Content Model pane files (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Mar 4, 2024
1 parent a67d54c commit 2d9d5f0
Show file tree
Hide file tree
Showing 90 changed files with 147 additions and 149 deletions.
6 changes: 3 additions & 3 deletions demo/scripts/controls/ContentModelEditorMainPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ContentModelFormatPainterPlugin from './contentModel/plugins/ContentModel
import ContentModelFormatStatePlugin from './sidePane/formatState/ContentModelFormatStatePlugin';
import ContentModelPanePlugin from './sidePane/contentModel/ContentModelPanePlugin';
import ContentModelRibbonButton from './ribbonButtons/contentModel/ContentModelRibbonButton';
import ContentModelRooster from './contentModel/editor/ContentModelRooster';
import ContentModelSnapshotPlugin from './sidePane/snapshot/ContentModelSnapshotPlugin';
import getToggleablePlugins from './getToggleablePlugins';
import MainPaneBase, { MainPaneBaseState } from './MainPaneBase';
Expand All @@ -29,6 +28,7 @@ import { clearFormatButton } from './ribbonButtons/contentModel/clearFormatButto
import { codeButton } from './ribbonButtons/contentModel/codeButton';
import { ContentModelRibbon } from './ribbonButtons/contentModel/ContentModelRibbon';
import { ContentModelRibbonPlugin } from './ribbonButtons/contentModel/ContentModelRibbonPlugin';
import { ContentModelSegmentFormat, IEditor, Snapshots } from 'roosterjs-content-model-types';
import { createEmojiPlugin, createPasteOptionPlugin } from 'roosterjs-react';
import { darkMode } from './ribbonButtons/contentModel/darkMode';
import { decreaseFontSizeButton } from './ribbonButtons/contentModel/decreaseFontSizeButton';
Expand Down Expand Up @@ -60,6 +60,7 @@ import { pasteButton } from './ribbonButtons/contentModel/pasteButton';
import { popout } from './ribbonButtons/contentModel/popout';
import { redoButton } from './ribbonButtons/contentModel/redoButton';
import { removeLinkButton } from './ribbonButtons/contentModel/removeLinkButton';
import { Rooster } from '../controlsV2/roosterjsReact/rooster/component/Rooster';
import { rtlButton } from './ribbonButtons/contentModel/rtlButton';
import { setBulletedListStyleButton } from './ribbonButtons/contentModel/setBulletedListStyleButton';
import { setHeadingLevelButton } from './ribbonButtons/contentModel/setHeadingLevelButton';
Expand All @@ -79,7 +80,6 @@ import { trustedHTMLHandler } from '../utils/trustedHTMLHandler';
import { underlineButton } from './ribbonButtons/contentModel/underlineButton';
import { undoButton } from './ribbonButtons/contentModel/undoButton';
import { zoom } from './ribbonButtons/contentModel/zoom';
import { ContentModelSegmentFormat, IEditor, Snapshots } from 'roosterjs-content-model-types';
import {
AutoFormatPlugin,
EditPlugin,
Expand Down Expand Up @@ -377,7 +377,7 @@ class ContentModelEditorMainPane extends MainPaneBase<ContentModelMainPaneState>
<div className={styles.editorContainer} id="EditorContainer">
<div style={editorStyles}>
{this.state.editorCreator && (
<ContentModelRooster
<Rooster
id={MainPaneBase.editorDivId}
className={styles.editor}
legacyPlugins={allPlugins}
Expand Down
4 changes: 2 additions & 2 deletions demo/scripts/controls/StandaloneEditorMainPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ContentModelFormatPainterPlugin from './contentModel/plugins/ContentModel
import ContentModelFormatStatePlugin from './sidePane/formatState/ContentModelFormatStatePlugin';
import ContentModelPanePlugin from './sidePane/contentModel/ContentModelPanePlugin';
import ContentModelRibbonButton from './ribbonButtons/contentModel/ContentModelRibbonButton';
import ContentModelRooster from './contentModel/editor/ContentModelRooster';
import ContentModelSnapshotPlugin from './sidePane/snapshot/ContentModelSnapshotPlugin';
import MainPaneBase, { MainPaneBaseState } from './MainPaneBase';
import RibbonPlugin from './ribbonButtons/contentModel/RibbonPlugin';
Expand Down Expand Up @@ -55,6 +54,7 @@ import { pasteButton } from './ribbonButtons/contentModel/pasteButton';
import { popout } from './ribbonButtons/contentModel/popout';
import { redoButton } from './ribbonButtons/contentModel/redoButton';
import { removeLinkButton } from './ribbonButtons/contentModel/removeLinkButton';
import { Rooster } from '../controlsV2/roosterjsReact/rooster/component/Rooster';
import { rtlButton } from './ribbonButtons/contentModel/rtlButton';
import { setBulletedListStyleButton } from './ribbonButtons/contentModel/setBulletedListStyleButton';
import { setHeadingLevelButton } from './ribbonButtons/contentModel/setHeadingLevelButton';
Expand Down Expand Up @@ -348,7 +348,7 @@ class ContentModelEditorMainPane extends MainPaneBase<ContentModelMainPaneState>
<div className={styles.editorContainer} id="EditorContainer">
<div style={editorStyles}>
{this.state.editorCreator && (
<ContentModelRooster
<Rooster
id={MainPaneBase.editorDivId}
className={styles.editor}
plugins={[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import ContentModelRibbonButton from '../../ribbonButtons/contentModel/ContentModelRibbonButton';
import { ContentModelDocument } from 'roosterjs-content-model-types';
import { ContentModelDocumentView } from '../../contentModel/components/model/ContentModelDocumentView';
import { ContentModelDocumentView } from '../../../controlsV2/sidePane/contentModel/components/model/ContentModelDocumentView';
import { ContentModelRibbon } from '../../ribbonButtons/contentModel/ContentModelRibbon';
import { ContentModelRibbonPlugin } from '../../ribbonButtons/contentModel/ContentModelRibbonPlugin';
import { exportButton } from './buttons/exportButton';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import type { EditorPlugin as LegacyEditorPlugin } from 'roosterjs-editor-types'
/**
* Properties for Rooster react component
*/
export interface ContentModelRoosterProps
extends EditorAdapterOptions,
React.HTMLAttributes<HTMLDivElement> {
export interface RoosterProps extends EditorAdapterOptions, React.HTMLAttributes<HTMLDivElement> {
/**
* Creator function used for creating the instance of roosterjs editor.
* Use this callback when you have your own sub class of roosterjs Editor or force trigging a reset of editor
Expand All @@ -30,7 +28,7 @@ export interface ContentModelRoosterProps
* @param props Properties of this component
* @returns The react component
*/
export default function ContentModelRooster(props: ContentModelRoosterProps) {
export function Rooster(props: RoosterProps) {
const editorDiv = React.useRef<HTMLDivElement>(null);
const editor = React.useRef<IEditor | null>(null);
const theme = useTheme();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createTextFormatRenderer } from '../utils/createTextFormatRenderer';
import { WordBreakFormat } from 'roosterjs-content-model-types';

export const WordBreakFormatRenderer = createTextFormatRenderer<WordBreakFormat>(
'Word break',
format => format.wordBreak,
(format, value) => (format.wordBreak = value)
);
import { createTextFormatRenderer } from '../utils/createTextFormatRenderer';
import { WordBreakFormat } from 'roosterjs-content-model-types';

export const WordBreakFormatRenderer = createTextFormatRenderer<WordBreakFormat>(
'Word break',
format => format.wordBreak,
(format, value) => (format.wordBreak = value)
);
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
import * as React from 'react';
import { BackgroundColorFormatRenderer } from '../format/formatPart/BackgroundColorFormatRenderer';
import { BlockGroupContentView } from './BlockGroupContentView';
import { BorderBoxFormatRenderer } from '../format/formatPart/BorderBoxFormatRenderer';
import { BorderFormatRenderers } from '../format/formatPart/BorderFormatRenderers';
import { ContentModelTableCell, ContentModelTableCellFormat } from 'roosterjs-content-model-types';
import { ContentModelView } from '../ContentModelView';
import { DirectionFormatRenderer } from '../format/formatPart/DirectionFormatRenderer';
import { FormatRenderer } from '../format/utils/FormatRenderer';
import { FormatView } from '../format/FormatView';
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 { useProperty } from '../../hooks/useProperty';
import { VerticalAlignFormatRenderer } from '../format/formatPart/VerticalAlignFormatRenderer';
import { WordBreakFormatRenderer } from '../format/formatPart/WordBreakFormatRenderer';

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

const TableCellFormatRenderers: FormatRenderer<ContentModelTableCellFormat>[] = [
...BorderFormatRenderers,
DirectionFormatRenderer,
TextAlignFormatRenderer,
HtmlAlignFormatRenderer,
BorderBoxFormatRenderer,
BackgroundColorFormatRenderer,
PaddingFormatRenderer,
VerticalAlignFormatRenderer,
WordBreakFormatRenderer,
TextColorFormatRenderer,
...SizeFormatRenderers,
];

export function ContentModelTableCellView(props: { cell: ContentModelTableCell }) {
const { cell } = props;
const checkboxHeader = React.useRef<HTMLInputElement>(null);
const checkboxSpanLeft = React.useRef<HTMLInputElement>(null);
const checkboxSpanAbove = React.useRef<HTMLInputElement>(null);
const [isHeader, setIsHeader] = useProperty(cell.isHeader);
const [spanLeft, setSpanLeft] = useProperty(cell.spanLeft);
const [spanAbove, setSpanAbove] = useProperty(cell.spanAbove);

const onHeaderChanged = React.useCallback(() => {
const value = checkboxHeader.current.checked;
cell.isHeader = value;
setIsHeader(value);
}, [cell, setIsHeader]);

const onSpanLeftChanged = React.useCallback(() => {
const value = checkboxSpanLeft.current.checked;
cell.spanLeft = value;
setSpanLeft(value);
}, [cell, setSpanLeft]);

const onSpanAboveChanged = React.useCallback(() => {
const value = checkboxSpanAbove.current.checked;
cell.spanAbove = value;
setSpanAbove(value);
}, [cell, setSpanAbove]);

const getContent = React.useCallback(() => {
return (
<>
<div>
<input
type="checkbox"
checked={isHeader}
ref={checkboxHeader}
onChange={onHeaderChanged}
/>
Header
</div>
<div>
<input
type="checkbox"
checked={spanLeft}
ref={checkboxSpanLeft}
onChange={onSpanLeftChanged}
/>
Span Left
</div>
<div>
<input
type="checkbox"
checked={spanAbove}
ref={checkboxSpanAbove}
onChange={onSpanAboveChanged}
/>
Span Above
</div>
<BlockGroupContentView group={cell} />
</>
);
}, [cell, isHeader, spanAbove, spanLeft]);

const getMetadata = React.useCallback(() => {
return (
<MetadataView
model={cell}
renderers={TableCellMetadataFormatRenders}
updater={updateTableCellMetadata}
/>
);
}, [cell]);

const getFormat = React.useCallback(() => {
return <FormatView format={cell.format} renderers={TableCellFormatRenderers} />;
}, [cell.format]);

const subTitle =
cell.spanAbove && cell.spanLeft ? '↖' : cell.spanLeft ? '←' : cell.spanAbove ? '↑' : '';

return (
<ContentModelView
title={isHeader ? 'TableCellHeader' : 'TableCell'}
subTitle={subTitle}
className={styles.modelTableCell}
hasSelection={hasSelectionInBlockGroup(cell)}
isSelected={cell.isSelected}
jsonSource={cell}
getContent={getContent}
getFormat={getFormat}
getMetadata={getMetadata}
/>
);
}
import * as React from 'react';
import { BackgroundColorFormatRenderer } from '../format/formatPart/BackgroundColorFormatRenderer';
import { BlockGroupContentView } from './BlockGroupContentView';
import { BorderBoxFormatRenderer } from '../format/formatPart/BorderBoxFormatRenderer';
import { BorderFormatRenderers } from '../format/formatPart/BorderFormatRenderers';
import { ContentModelTableCell, ContentModelTableCellFormat } from 'roosterjs-content-model-types';
import { ContentModelView } from '../ContentModelView';
import { DirectionFormatRenderer } from '../format/formatPart/DirectionFormatRenderer';
import { FormatRenderer } from '../format/utils/FormatRenderer';
import { FormatView } from '../format/FormatView';
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 { useProperty } from '../../hooks/useProperty';
import { VerticalAlignFormatRenderer } from '../format/formatPart/VerticalAlignFormatRenderer';
import { WordBreakFormatRenderer } from '../format/formatPart/WordBreakFormatRenderer';

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

const TableCellFormatRenderers: FormatRenderer<ContentModelTableCellFormat>[] = [
...BorderFormatRenderers,
DirectionFormatRenderer,
TextAlignFormatRenderer,
HtmlAlignFormatRenderer,
BorderBoxFormatRenderer,
BackgroundColorFormatRenderer,
PaddingFormatRenderer,
VerticalAlignFormatRenderer,
WordBreakFormatRenderer,
TextColorFormatRenderer,
...SizeFormatRenderers,
];

export function ContentModelTableCellView(props: { cell: ContentModelTableCell }) {
const { cell } = props;
const checkboxHeader = React.useRef<HTMLInputElement>(null);
const checkboxSpanLeft = React.useRef<HTMLInputElement>(null);
const checkboxSpanAbove = React.useRef<HTMLInputElement>(null);
const [isHeader, setIsHeader] = useProperty(cell.isHeader);
const [spanLeft, setSpanLeft] = useProperty(cell.spanLeft);
const [spanAbove, setSpanAbove] = useProperty(cell.spanAbove);

const onHeaderChanged = React.useCallback(() => {
const value = checkboxHeader.current.checked;
cell.isHeader = value;
setIsHeader(value);
}, [cell, setIsHeader]);

const onSpanLeftChanged = React.useCallback(() => {
const value = checkboxSpanLeft.current.checked;
cell.spanLeft = value;
setSpanLeft(value);
}, [cell, setSpanLeft]);

const onSpanAboveChanged = React.useCallback(() => {
const value = checkboxSpanAbove.current.checked;
cell.spanAbove = value;
setSpanAbove(value);
}, [cell, setSpanAbove]);

const getContent = React.useCallback(() => {
return (
<>
<div>
<input
type="checkbox"
checked={isHeader}
ref={checkboxHeader}
onChange={onHeaderChanged}
/>
Header
</div>
<div>
<input
type="checkbox"
checked={spanLeft}
ref={checkboxSpanLeft}
onChange={onSpanLeftChanged}
/>
Span Left
</div>
<div>
<input
type="checkbox"
checked={spanAbove}
ref={checkboxSpanAbove}
onChange={onSpanAboveChanged}
/>
Span Above
</div>
<BlockGroupContentView group={cell} />
</>
);
}, [cell, isHeader, spanAbove, spanLeft]);

const getMetadata = React.useCallback(() => {
return (
<MetadataView
model={cell}
renderers={TableCellMetadataFormatRenders}
updater={updateTableCellMetadata}
/>
);
}, [cell]);

const getFormat = React.useCallback(() => {
return <FormatView format={cell.format} renderers={TableCellFormatRenderers} />;
}, [cell.format]);

const subTitle =
cell.spanAbove && cell.spanLeft ? '↖' : cell.spanLeft ? '←' : cell.spanAbove ? '↑' : '';

return (
<ContentModelView
title={isHeader ? 'TableCellHeader' : 'TableCell'}
subTitle={subTitle}
className={styles.modelTableCell}
hasSelection={hasSelectionInBlockGroup(cell)}
isSelected={cell.isSelected}
jsonSource={cell}
getContent={getContent}
getFormat={getFormat}
getMetadata={getMetadata}
/>
);
}

0 comments on commit 2d9d5f0

Please sign in to comment.