diff --git a/src/plugins/expression_image/kibana.json b/src/plugins/expression_image/kibana.json index 4f4b736d82d1a..7391b17bce779 100755 --- a/src/plugins/expression_image/kibana.json +++ b/src/plugins/expression_image/kibana.json @@ -10,5 +10,6 @@ "server": true, "ui": true, "requiredPlugins": ["expressions", "presentationUtil"], - "optionalPlugins": [] + "optionalPlugins": [], + "requiredBundles": ["kibanaReact"] } diff --git a/src/plugins/expression_image/public/expression_renderers/__stories__/image_renderer.stories.tsx b/src/plugins/expression_image/public/expression_renderers/__stories__/image_renderer.stories.tsx index d75aa1a4263eb..dc54194d5d83f 100644 --- a/src/plugins/expression_image/public/expression_renderers/__stories__/image_renderer.stories.tsx +++ b/src/plugins/expression_image/public/expression_renderers/__stories__/image_renderer.stories.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { Render, waitFor } from '../../../../presentation_util/public/__stories__'; -import { imageRenderer } from '../image_renderer'; +import { getImageRenderer } from '../image_renderer'; import { getElasticLogo } from '../../../../../../src/plugins/presentation_util/common/lib'; import { ImageMode } from '../../../common'; @@ -19,7 +19,7 @@ const Renderer = ({ elasticLogo }: { elasticLogo: string }) => { mode: ImageMode.COVER, }; - return ; + return ; }; storiesOf('renderers/image', module).add( diff --git a/src/plugins/expression_image/public/expression_renderers/image_renderer.tsx b/src/plugins/expression_image/public/expression_renderers/image_renderer.tsx index 3d542a9978a83..a38649f13fb32 100644 --- a/src/plugins/expression_image/public/expression_renderers/image_renderer.tsx +++ b/src/plugins/expression_image/public/expression_renderers/image_renderer.tsx @@ -9,7 +9,11 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions'; import { i18n } from '@kbn/i18n'; -import { getElasticLogo, isValidUrl } from '../../../presentation_util/public'; +import { Observable } from 'rxjs'; +import { CoreTheme } from 'kibana/public'; +import { CoreSetup } from '../../../../core/public'; +import { KibanaThemeProvider } from '../../../kibana_react/public'; +import { getElasticLogo, isValidUrl, defaultTheme$ } from '../../../presentation_util/public'; import { ImageRendererConfig } from '../../common/types'; const strings = { @@ -23,31 +27,41 @@ const strings = { }), }; -export const imageRenderer = (): ExpressionRenderDefinition => ({ - name: 'image', - displayName: strings.getDisplayName(), - help: strings.getHelpDescription(), - reuseDomNode: true, - render: async ( - domNode: HTMLElement, - config: ImageRendererConfig, - handlers: IInterpreterRenderHandlers - ) => { - const { elasticLogo } = await getElasticLogo(); - const dataurl = isValidUrl(config.dataurl ?? '') ? config.dataurl : elasticLogo; +export const getImageRenderer = + (theme$: Observable = defaultTheme$) => + (): ExpressionRenderDefinition => ({ + name: 'image', + displayName: strings.getDisplayName(), + help: strings.getHelpDescription(), + reuseDomNode: true, + render: async ( + domNode: HTMLElement, + config: ImageRendererConfig, + handlers: IInterpreterRenderHandlers + ) => { + const { elasticLogo } = await getElasticLogo(); + const dataurl = isValidUrl(config.dataurl ?? '') ? config.dataurl : elasticLogo; - const style = { - height: '100%', - backgroundImage: `url(${dataurl})`, - backgroundRepeat: 'no-repeat', - backgroundPosition: 'center center', - backgroundSize: config.mode as string, - }; + const style = { + height: '100%', + backgroundImage: `url(${dataurl})`, + backgroundRepeat: 'no-repeat', + backgroundPosition: 'center center', + backgroundSize: config.mode as string, + }; - handlers.onDestroy(() => { - unmountComponentAtNode(domNode); - }); + handlers.onDestroy(() => { + unmountComponentAtNode(domNode); + }); - render(
, domNode, () => handlers.done()); - }, -}); + render( + +
+ , + domNode, + () => handlers.done() + ); + }, + }); + +export const imageRendererFactory = (core: CoreSetup) => getImageRenderer(core.theme.theme$); diff --git a/src/plugins/expression_image/public/expression_renderers/index.ts b/src/plugins/expression_image/public/expression_renderers/index.ts index 96c274f05a7a9..6b4c4b03f7922 100644 --- a/src/plugins/expression_image/public/expression_renderers/index.ts +++ b/src/plugins/expression_image/public/expression_renderers/index.ts @@ -6,8 +6,4 @@ * Side Public License, v 1. */ -import { imageRenderer } from './image_renderer'; - -export const renderers = [imageRenderer]; - -export { imageRenderer }; +export { imageRendererFactory, getImageRenderer } from './image_renderer'; diff --git a/src/plugins/expression_image/public/index.ts b/src/plugins/expression_image/public/index.ts index 661a12e7cf028..c379dd05dc221 100755 --- a/src/plugins/expression_image/public/index.ts +++ b/src/plugins/expression_image/public/index.ts @@ -6,9 +6,6 @@ * Side Public License, v 1. */ -// TODO: https://github.com/elastic/kibana/issues/110893 -/* eslint-disable @kbn/eslint/no_export_all */ - import { ExpressionImagePlugin } from './plugin'; export type { ExpressionImagePluginSetup, ExpressionImagePluginStart } from './plugin'; @@ -17,4 +14,4 @@ export function plugin() { return new ExpressionImagePlugin(); } -export * from './expression_renderers'; +export { imageRendererFactory, getImageRenderer } from './expression_renderers'; diff --git a/src/plugins/expression_image/public/plugin.ts b/src/plugins/expression_image/public/plugin.ts index 6e6c02248642f..ba7e2baded8d8 100755 --- a/src/plugins/expression_image/public/plugin.ts +++ b/src/plugins/expression_image/public/plugin.ts @@ -8,7 +8,7 @@ import { CoreSetup, CoreStart, Plugin } from '../../../core/public'; import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public'; -import { imageRenderer } from './expression_renderers'; +import { imageRendererFactory } from './expression_renderers'; import { imageFunction } from '../common/expression_functions'; interface SetupDeps { @@ -27,7 +27,7 @@ export class ExpressionImagePlugin { public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionImagePluginSetup { expressions.registerFunction(imageFunction); - expressions.registerRenderer(imageRenderer); + expressions.registerRenderer(imageRendererFactory(core)); } public start(core: CoreStart): ExpressionImagePluginStart {} diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts b/x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts index f7012984a2182..9b79c50a92098 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { imageRenderer } from '../../../../../src/plugins/expression_image/public'; +import { imageRendererFactory } from '../../../../../src/plugins/expression_image/public'; import { metricRendererFactory } from '../../../../../src/plugins/expression_metric/public'; import { errorRendererFactory, @@ -18,11 +18,12 @@ import { progressRendererFactory, } from '../../../../../src/plugins/expression_shape/public'; -export const renderFunctions = [imageRenderer]; +export const renderFunctions = []; export const renderFunctionFactories = [ debugRendererFactory, errorRendererFactory, + imageRendererFactory, shapeRendererFactory, progressRendererFactory, revealImageRendererFactory, diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js index 83f8e6f290b41..f8aebc04efe5c 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js @@ -10,7 +10,7 @@ import { pie } from '../canvas_plugin_src/renderers/pie'; import { plot } from '../canvas_plugin_src/renderers/plot'; import { getTableRenderer } from '../canvas_plugin_src/renderers/table'; import { getTextRenderer } from '../canvas_plugin_src/renderers/text'; -import { imageRenderer as image } from '../../../../src/plugins/expression_image/public'; +import { getImageRenderer } from '../../../../src/plugins/expression_image/public'; import { getErrorRenderer, getDebugRenderer, @@ -31,6 +31,7 @@ const renderFunctionsFactories = [ getTableRenderer, getErrorRenderer, getDebugRenderer, + getImageRenderer, getShapeRenderer, getProgressRenderer, getRevealImageRenderer, @@ -43,6 +44,6 @@ const renderFunctionsFactories = [ * a renderer is not listed here, but is used by the Shared Workpad, it will * not render. This includes any plugins. */ -export const renderFunctions = [image, pie, plot, ...renderFunctionsFactories.map(unboxFactory)]; +export const renderFunctions = [pie, plot, ...renderFunctionsFactories.map(unboxFactory)]; export const renderFunctionNames = [...renderFunctions.map((fn) => fn().name)];