Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Jun 6, 2024
1 parent c3a77ab commit 31c48ea
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { defaultGenerateColorKey } from 'roosterjs-content-model-dom';
import type {
DarkColorHandler,
ColorTransformFunction,
Expand Down Expand Up @@ -50,7 +51,7 @@ export function createDarkColorHandler(
root: HTMLElement,
getDarkColor: ColorTransformFunction,
knownColors: Record<string, Colors> = {},
generateColorKey: ColorTransformFunction
generateColorKey: ColorTransformFunction = defaultGenerateColorKey
): DarkColorHandler {
return new DarkColorHandlerImpl(root, getDarkColor, knownColors, generateColorKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createDarkColorHandler } from './DarkColorHandlerImpl';
import { createDOMHelper } from './DOMHelperImpl';
import { createDomToModelSettings, createModelToDomSettings } from './createEditorDefaultSettings';
import { createEditorCorePlugins } from '../../corePlugin/createEditorCorePlugins';
import { generateColorKey } from 'roosterjs-content-model-dom';
import type {
EditorEnvironment,
PluginState,
Expand Down Expand Up @@ -42,7 +41,7 @@ export function createEditorCore(contentDiv: HTMLDivElement, options: EditorOpti
contentDiv,
options.getDarkColor ?? getDarkColorFallback,
options.knownColors,
options.generateColorKey ?? generateColorKey
options.generateColorKey
),
trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler,
domHelper: createDOMHelper(contentDiv),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ describe('createEditorCore', () => {
expect(DarkColorHandlerImpl.createDarkColorHandler).toHaveBeenCalledWith(
mockedDiv,
getDarkColorFallback,
undefined,
undefined
);
});
Expand Down Expand Up @@ -181,6 +182,7 @@ describe('createEditorCore', () => {
expect(DarkColorHandlerImpl.createDarkColorHandler).toHaveBeenCalledWith(
mockedDiv,
mockedGetDarkColor,
undefined,
undefined
);
});
Expand Down Expand Up @@ -214,6 +216,7 @@ describe('createEditorCore', () => {
expect(DarkColorHandlerImpl.createDarkColorHandler).toHaveBeenCalledWith(
mockedDiv,
getDarkColorFallback,
undefined,
undefined
);
});
Expand Down Expand Up @@ -247,6 +250,7 @@ describe('createEditorCore', () => {
expect(DarkColorHandlerImpl.createDarkColorHandler).toHaveBeenCalledWith(
mockedDiv,
getDarkColorFallback,
undefined,
undefined
);
});
Expand Down Expand Up @@ -280,6 +284,7 @@ describe('createEditorCore', () => {
expect(DarkColorHandlerImpl.createDarkColorHandler).toHaveBeenCalledWith(
mockedDiv,
getDarkColorFallback,
undefined,
undefined
);
});
Expand Down Expand Up @@ -313,6 +318,7 @@ describe('createEditorCore', () => {
expect(DarkColorHandlerImpl.createDarkColorHandler).toHaveBeenCalledWith(
mockedDiv,
getDarkColorFallback,
undefined,
undefined
);
});
Expand Down Expand Up @@ -346,6 +352,7 @@ describe('createEditorCore', () => {
expect(DarkColorHandlerImpl.createDarkColorHandler).toHaveBeenCalledWith(
mockedDiv,
getDarkColorFallback,
undefined,
undefined
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function setColor(
* @param lightColor The input light color
* @returns Key of the color
*/
export const generateColorKey: ColorTransformFunction = lightColor => {
export const defaultGenerateColorKey: ColorTransformFunction = lightColor => {
return `${COLOR_VAR_PREFIX}_${lightColor.replace(/[^\d\w]/g, '_')}`;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/roosterjs-content-model-dom/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export {
getColor,
setColor,
parseColor,
generateColorKey,
defaultGenerateColorKey,
} from './formatHandlers/utils/color';

export {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { backgroundColorFormatHandler } from '../../../lib/formatHandlers/common/backgroundColorFormatHandler';
import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext';
import { createModelToDomContext } from '../../../lib/modelToDom/context/createModelToDomContext';
import { DeprecatedColors } from '../../../lib/formatHandlers/utils/color';
import { defaultGenerateColorKey, DeprecatedColors } from '../../../lib/formatHandlers/utils/color';
import { expectHtml } from '../../testUtils';
import {
BackgroundColorFormat,
Expand Down Expand Up @@ -113,6 +113,7 @@ describe('backgroundColorFormatHandler.apply', () => {
context.darkColorHandler = {
updateKnownColor: () => {},
getDarkColor: (lightColor: string) => `var(--darkColor_${lightColor}, ${lightColor})`,
generateColorKey: defaultGenerateColorKey,
} as any;

backgroundColorFormatHandler.apply(format, div, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext';
import { createModelToDomContext } from '../../../lib/modelToDom/context/createModelToDomContext';
import { defaultGenerateColorKey, DeprecatedColors } from '../../../lib';
import { defaultHTMLStyleMap } from '../../../lib/config/defaultHTMLStyleMap';
import { DeprecatedColors } from '../../../lib';
import { expectHtml } from '../../testUtils';
import { textColorFormatHandler } from '../../../lib/formatHandlers/segment/textColorFormatHandler';
import {
Expand Down Expand Up @@ -110,6 +110,7 @@ describe('textColorFormatHandler.apply', () => {
context.darkColorHandler = {
updateKnownColor: () => {},
getDarkColor: (lightColor: string) => `var(--darkColor_${lightColor}, ${lightColor})`,
generateColorKey: defaultGenerateColorKey,
} as any;

format = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Colors, DarkColorHandler } from 'roosterjs-content-model-types';
import { getColor, parseColor, setColor } from '../../../lib/formatHandlers/utils/color';
import {
defaultGenerateColorKey,
getColor,
parseColor,
setColor,
} from '../../../lib/formatHandlers/utils/color';

describe('getColor without darkColorHandler', () => {
it('no color', () => {
Expand Down Expand Up @@ -122,6 +127,7 @@ describe('getColor with darkColorHandler', () => {
getDarkColor: getDarkColorSpy,
updateKnownColor: updateKnownColorSpy,
reset: null!,
generateColorKey: defaultGenerateColorKey,
};
});

Expand Down Expand Up @@ -351,6 +357,7 @@ describe('setColor with darkColorHandler', () => {
getDarkColor: getDarkColorSpy,
updateKnownColor: updateKnownColorSpy,
reset: null!,
generateColorKey: defaultGenerateColorKey,
};
});

Expand Down

0 comments on commit 31c48ea

Please sign in to comment.