-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e4b64b
commit 64f00ea
Showing
48 changed files
with
543 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
// eslint-disable-next-line import/no-commonjs | ||
module.exports = require('@kbn/storybook').defaultConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# expressionRevealImage | ||
|
||
Expression Image plugin adds an `image` renderer to the expression plugin. The renderer will display the given image. | ||
|
||
--- | ||
|
||
## Development | ||
|
||
See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const PLUGIN_ID = 'expressionImage'; | ||
export const PLUGIN_NAME = 'expressionImage'; | ||
|
||
export const CONTEXT = '_context_'; | ||
export const BASE64 = '`base64`'; | ||
export const URL = 'URL'; |
42 changes: 24 additions & 18 deletions
42
...plugin_src/functions/common/image.test.js → ...pression_functions/image_function.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/plugins/expression_image/common/expression_functions/image_function.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { getElasticLogo, resolveWithMissingImage } from '../../../presentation_util/common/lib'; | ||
import { BASE64, URL } from '../constants'; | ||
import { ExpressionImageFunction, ImageMode } from '../types'; | ||
|
||
export const strings = { | ||
help: i18n.translate('expressionImage.functions.imageHelpText', { | ||
defaultMessage: | ||
'Displays an image. Provide an image asset as a {BASE64} data {URL}, or pass in a sub-expression.', | ||
values: { | ||
BASE64, | ||
URL, | ||
}, | ||
}), | ||
args: { | ||
dataurl: i18n.translate('expressionImage.functions.image.args.dataurlHelpText', { | ||
defaultMessage: 'The {https} {URL} or {BASE64} data {URL} of an image.', | ||
values: { | ||
BASE64, | ||
https: 'HTTP(S)', | ||
URL, | ||
}, | ||
}), | ||
mode: i18n.translate('expressionImage.functions.image.args.modeHelpText', { | ||
defaultMessage: | ||
'{contain} shows the entire image, scaled to fit. ' + | ||
'{cover} fills the container with the image, cropping from the sides or bottom as needed. ' + | ||
'{stretch} resizes the height and width of the image to 100% of the container.', | ||
values: { | ||
contain: `\`"${ImageMode.CONTAIN}"\``, | ||
cover: `\`"${ImageMode.COVER}"\``, | ||
stretch: `\`"${ImageMode.STRETCH}"\``, | ||
}, | ||
}), | ||
}, | ||
}; | ||
|
||
const errors = { | ||
invalidImageMode: () => | ||
i18n.translate('expressionImage.functions.image.invalidImageModeErrorMessage', { | ||
defaultMessage: '"mode" must be "{contain}", "{cover}", or "{stretch}"', | ||
values: { | ||
contain: ImageMode.CONTAIN, | ||
cover: ImageMode.COVER, | ||
stretch: ImageMode.STRETCH, | ||
}, | ||
}), | ||
}; | ||
|
||
export const imageFunction: ExpressionImageFunction = () => { | ||
const { help, args: argHelp } = strings; | ||
|
||
return { | ||
name: 'image', | ||
aliases: [], | ||
type: 'image', | ||
inputTypes: ['null'], | ||
help, | ||
args: { | ||
dataurl: { | ||
// This was accepting dataurl, but there was no facility in fn for checking type and handling a dataurl type. | ||
types: ['string', 'null'], | ||
help: argHelp.dataurl, | ||
aliases: ['_', 'url'], | ||
default: null, | ||
}, | ||
mode: { | ||
types: ['string'], | ||
help: argHelp.mode, | ||
default: 'contain', | ||
options: Object.values(ImageMode), | ||
}, | ||
}, | ||
fn: async (input, { dataurl, mode }) => { | ||
if (!mode || !Object.values(ImageMode).includes(mode)) { | ||
throw new Error(errors.invalidImageMode()); | ||
} | ||
|
||
const modeStyle = mode === 'stretch' ? '100% 100%' : mode; | ||
const { elasticLogo } = await getElasticLogo(); | ||
return { | ||
type: 'image', | ||
mode: modeStyle, | ||
dataurl: resolveWithMissingImage(dataurl, elasticLogo) as string, | ||
}; | ||
}, | ||
}; | ||
}; |
13 changes: 13 additions & 0 deletions
13
src/plugins/expression_image/common/expression_functions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { imageFunction } from './image_function'; | ||
|
||
export const functions = [imageFunction]; | ||
|
||
export { imageFunction }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export * from './constants'; | ||
export * from './types'; | ||
export * from './expression_functions'; |
32 changes: 32 additions & 0 deletions
32
src/plugins/expression_image/common/types/expression_functions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { ExpressionFunctionDefinition } from '../../../expressions'; | ||
|
||
export enum ImageMode { | ||
CONTAIN = 'contain', | ||
COVER = 'cover', | ||
STRETCH = 'stretch', | ||
} | ||
|
||
interface Arguments { | ||
dataurl: string | null; | ||
mode: ImageMode | null; | ||
} | ||
|
||
export interface Return { | ||
type: 'image'; | ||
mode: string; | ||
dataurl: string; | ||
} | ||
|
||
export type ExpressionImageFunction = () => ExpressionFunctionDefinition< | ||
'image', | ||
null, | ||
Arguments, | ||
Promise<Return> | ||
>; |
21 changes: 21 additions & 0 deletions
21
src/plugins/expression_image/common/types/expression_renderers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ImageMode } from './expression_functions'; | ||
|
||
export type OriginString = 'bottom' | 'left' | 'top' | 'right'; | ||
|
||
export interface ImageRendererConfig { | ||
dataurl: string | null; | ||
mode: ImageMode | null; | ||
} | ||
|
||
export interface NodeDimensions { | ||
width: number; | ||
height: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
export * from './expression_functions'; | ||
export * from './expression_renderers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/src/plugins/expression_image'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "expressionImage", | ||
"version": "1.0.0", | ||
"kibanaVersion": "kibana", | ||
"server": true, | ||
"ui": true, | ||
"requiredPlugins": ["expressions", "presentationUtil"], | ||
"optionalPlugins": [] | ||
} |
File renamed without changes.
Oops, something went wrong.