Skip to content

Commit

Permalink
fix: Markdown editor unregister tooltip plugin (#4383)
Browse files Browse the repository at this point in the history
* fix: Markdown editor unregister tooltip plugin

Issue number 4239
Ability to unregister the tooltip plugin added
Updated the editor example doc to show how to use it

* fix:Markdown tooltip unregister

Added the ability to unregsiter inbuilt UI plugins
Addresses issue 4239

Signed-off-by: k-kumar-01 <[email protected]>

* fix:Markdown ToolTip Plugin

Default UI Plugins initialized
Warning added on injecting tooltip plugin

Signed-off-by: k-kumar-01 <[email protected]>

* Changelog & updated markdown plugins example

Co-authored-by: Chandler Prall <[email protected]>
  • Loading branch information
K-Kumar-01 and chandlerprall authored Jan 26, 2021
1 parent 09b95c4 commit 34500b7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
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();

0 comments on commit 34500b7

Please sign in to comment.