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

fix: Markdown editor unregister tooltip plugin #4383

Merged
merged 8 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `getDefaultEuiMarkdownProcessingPlugins` method for better control over `EuiMarkdownEditor`'s toolbar UI ([#4383](https://github.com/elastic/eui/pull/4383))

**Bug fixes**

- Fixed heights of `append` and `prepend` in `EuiComboBox` ([#4410](https://github.com/elastic/eui/pull/4406))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
euiPalettePositive,
euiPaletteWarm,
} from '../../../../src/services/color';
import { getDefaultEuiMarkdownUiPlugins } from '../../../../src/components/markdown_editor';

const paletteData = {
euiPaletteForStatus,
Expand Down Expand Up @@ -261,6 +262,9 @@ exampleParsingList.push(ChartMarkdownParser);
const exampleProcessingList = getDefaultEuiMarkdownProcessingPlugins();
exampleProcessingList[1][1].components.chartDemoPlugin = ChartMarkdownRenderer;

const exampleUiPlugins = getDefaultEuiMarkdownUiPlugins();
exampleUiPlugins.push(chartDemoPlugin);

const initialExample = `## Chart plugin
Notice the toolbar above has a new chart button. Click it to add a chart.
Expand All @@ -286,7 +290,7 @@ export default () => {
value={value}
onChange={setValue}
height={400}
uiPlugins={[chartDemoPlugin]}
uiPlugins={exampleUiPlugins}
parsingPluginList={exampleParsingList}
processingPluginList={exampleProcessingList}
onParse={onParse}
Expand Down
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export {
EuiMarkdownFormat,
getDefaultEuiMarkdownParsingPlugins,
getDefaultEuiMarkdownProcessingPlugins,
getDefaultEuiMarkdownUiPlugins,
} from './markdown_editor';
export { EuiMark } from './mark';

Expand Down
1 change: 1 addition & 0 deletions src/components/markdown_editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export { EuiMarkdownEditor, EuiMarkdownEditorProps } from './markdown_editor';
export {
getDefaultEuiMarkdownParsingPlugins,
getDefaultEuiMarkdownProcessingPlugins,
getDefaultEuiMarkdownUiPlugins,
} from './plugins/markdown_default_plugins';
export { EuiMarkdownContext } from './markdown_context';
export { EuiMarkdownFormat } from './markdown_format';
Expand Down
12 changes: 10 additions & 2 deletions src/components/markdown_editor/markdown_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import * as MarkdownTooltip from './plugins/markdown_tooltip';
import {
defaultParsingPlugins,
defaultProcessingPlugins,
defaultUiPlugins,
} from './plugins/markdown_default_plugins';

import { EuiResizeObserver } from '../observer/resize_observer';
Expand Down Expand Up @@ -193,7 +194,7 @@ export const EuiMarkdownEditor = forwardRef<
autoExpandPreview = true,
parsingPluginList = defaultParsingPlugins,
processingPluginList = defaultProcessingPlugins,
uiPlugins = [],
uiPlugins = defaultUiPlugins,
onParse,
errors = [],
'aria-label': ariaLabel,
Expand All @@ -214,7 +215,14 @@ export const EuiMarkdownEditor = forwardRef<
EuiMarkdownEditorUiPlugin | undefined
>(undefined);

const toolbarPlugins = [MarkdownTooltip.plugin, ...uiPlugins];
const toolbarPlugins = [...uiPlugins];
// @ts-ignore __originatedFromEui is a custom property
if (!uiPlugins.__originatedFromEui) {
toolbarPlugins.unshift(MarkdownTooltip.plugin);
console.warn(
'Deprecation warning: uiPlugins passed to EuiMarkdownEditor does not include the tooltip plugin, which has been added for you. This automatic inclusion has been deprecated and will be removed in the future, see https://github.com/elastic/eui/pull/4383'
);
}

const markdownActions = useMemo(
() => new MarkdownActions(editorId, toolbarPlugins),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ export const getDefaultEuiMarkdownProcessingPlugins = (): [
];

export const defaultProcessingPlugins = getDefaultEuiMarkdownProcessingPlugins();

export const getDefaultEuiMarkdownUiPlugins = () => {
const array = [MarkdownTooltip.plugin];
// @ts-ignore __originatedFromEui is a custom property
array.__originatedFromEui = true;
return array;
};

export const defaultUiPlugins = getDefaultEuiMarkdownUiPlugins();