Skip to content

Commit

Permalink
Merge branch 'master' into u/jisong/keyboardenter
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Jun 3, 2024
2 parents 21a0bb0 + db8e2da commit fa4c2ff
Show file tree
Hide file tree
Showing 33 changed files with 700 additions and 307 deletions.
3 changes: 3 additions & 0 deletions demo/scripts/controlsV2/mainPane/MainPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ export class MainPane extends React.Component<{}, MainPaneState> {
knownColors={this.knownColors}
disableCache={this.state.initState.disableCache}
announcerStringGetter={getAnnouncingString}
experimentalFeatures={Array.from(
this.state.initState.experimentalFeatures
)}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { emojiReplacements } from './getReplacements';
import { ExperimentalFeature } from 'roosterjs-content-model-types';
import { OptionPaneProps, OptionState, UrlPlaceholder } from './OptionState';
import { OptionsPane } from './OptionsPane';
import { SidePaneElementProps } from '../SidePaneElement';
Expand Down Expand Up @@ -55,6 +56,7 @@ const initialState: OptionState = {
codeFormat: {},
},
customReplacements: emojiReplacements,
experimentalFeatures: new Set<ExperimentalFeature>(['PersistCache']),
};

export class EditorOptionsPlugin extends SidePanePluginImpl<OptionsPane, OptionPaneProps> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from 'react';
import { ExperimentalFeature } from 'roosterjs-content-model-types';
import { OptionState } from './OptionState';

export interface DefaultFormatProps {
state: OptionState;
resetState: (callback: (state: OptionState) => void, resetEditor: boolean) => void;
}

export class ExperimentalFeatures extends React.Component<DefaultFormatProps, {}> {
render() {
return this.renderFeature('PersistCache');
}

private renderFeature(featureName: ExperimentalFeature): JSX.Element {
let checked = this.props.state.experimentalFeatures.has(featureName);

return (
<div>
<input
type="checkbox"
id={featureName}
checked={checked}
onChange={() => this.onFeatureClick(featureName)}
/>
<label htmlFor={featureName}>{featureName}</label>
</div>
);
}

private onFeatureClick = (featureName: ExperimentalFeature) => {
this.props.resetState(state => {
let checkbox = document.getElementById(featureName) as HTMLInputElement;

if (checkbox.checked) {
state.experimentalFeatures.add(featureName);
} else {
state.experimentalFeatures.delete(featureName);
}
}, true);
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AutoFormatOptions, CustomReplace, MarkdownOptions } from 'roosterjs-content-model-plugins';
import type { SidePaneElementProps } from '../SidePaneElement';
import type { ContentModelSegmentFormat } from 'roosterjs-content-model-types';
import type { ContentModelSegmentFormat, ExperimentalFeature } from 'roosterjs-content-model-types';

export interface LegacyPluginList {
imageEdit: boolean;
Expand Down Expand Up @@ -47,6 +47,7 @@ export interface OptionState {
isRtl: boolean;
disableCache: boolean;
applyChangesOnMouseUp: boolean;
experimentalFeatures: Set<ExperimentalFeature>;
}

export interface OptionPaneProps extends OptionState, SidePaneElementProps {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { Code } from './Code';
import { DefaultFormatPane } from './DefaultFormatPane';
import { EditorCode } from './codes/EditorCode';
import { ExperimentalFeatures } from './ExperimentalFeatures';
import { LegacyPlugins, Plugins } from './Plugins';
import { MainPane } from '../../mainPane/MainPane';
import { OptionPaneProps, OptionState } from './OptionState';
Expand Down Expand Up @@ -63,6 +64,12 @@ export class OptionsPane extends React.Component<OptionPaneProps, OptionState> {
</summary>
<LegacyPlugins state={this.state} resetState={this.resetState} />
</details>
<details>
<summary>
<b>Experimental features</b>
</summary>
<ExperimentalFeatures state={this.state} resetState={this.resetState} />
</details>
<div>
<br />
</div>
Expand Down Expand Up @@ -140,6 +147,7 @@ export class OptionsPane extends React.Component<OptionPaneProps, OptionState> {
autoFormatOptions: { ...this.state.autoFormatOptions },
markdownOptions: { ...this.state.markdownOptions },
customReplacements: this.state.customReplacements,
experimentalFeatures: this.state.experimentalFeatures,
};

if (callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function createDomToModelContextForSanitizing(
{
defaultFormat,
...getRootComputedStyleForContext(document),
experimentalFeatures: [],
},
defaultOption,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const createEditorContext: CreateEditorContext = (core, saveIndex) => {
allowCacheElement: true,
domIndexer: saveIndex ? cache.domIndexer : undefined,
zoomScale: domHelper.calculateZoomScale(),
experimentalFeatures: core.experimentalFeatures ?? [],
...getRootComputedStyleForContext(logicalRoot.ownerDocument),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { areSameSelection } from './areSameSelection';
import { createTextMutationObserver } from './textMutationObserver';
import { domIndexerImpl } from './domIndexerImpl';
import { DomIndexerImpl } from './domIndexerImpl';
import { updateCachedSelection } from './updateCachedSelection';
import type {
CachePluginState,
Expand All @@ -26,7 +26,10 @@ class CachePlugin implements PluginWithState<CachePluginState> {
this.state = option.disableCache
? {}
: {
domIndexer: domIndexerImpl,
domIndexer: new DomIndexerImpl(
option.experimentalFeatures &&
option.experimentalFeatures.indexOf('PersistCache') >= 0
),
textMutationObserver: createTextMutationObserver(contentDiv, this.onMutation),
};
}
Expand Down
Loading

0 comments on commit fa4c2ff

Please sign in to comment.