Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuwoo.choi committed Jun 5, 2018
2 parents eb08433 + 25483cd commit 88805be
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "tui-editor",
"version": "1.2.1",
"version": "1.2.2",
"description": "GFM Markdown Wysiwyg Editor - Productive and Extensible",
"keywords": [
"toast",
Expand Down
21 changes: 14 additions & 7 deletions src/js/extensions/chart/chart.js
Expand Up @@ -51,7 +51,9 @@ const DEFAULT_CHART_OPTIONS = {
minWidth: 0,
maxWidth: Infinity,
minHeight: 0,
maxHeight: Infinity
maxHeight: Infinity,
height: 'auto',
width: 'auto'
};

/**
Expand Down Expand Up @@ -334,8 +336,11 @@ function setDefaultOptions(chartOptions, extensionOptions, chartContainer) {
const {
width: containerWidth
} = chartContainer.getBoundingClientRect();
width = isWidthUndefined ? containerWidth : width;
height = isHeightUndefined ? containerWidth : height;

width = isWidthUndefined ? extensionOptions.width : width;
height = isHeightUndefined ? extensionOptions.height : height;
width = width === 'auto' ? containerWidth : width;
height = height === 'auto' ? containerWidth : height;
}
width = Math.min(extensionOptions.maxWidth, width);
height = Math.min(extensionOptions.maxHeight, height);
Expand Down Expand Up @@ -498,10 +503,12 @@ function _onMDPasteBefore(cm, {source, data: eventData}) {
* chart plugin
* @param {Editor} editor - editor
* @param {Object} options - chart options
* @param {number} options.minWidth - minimum width
* @param {number} options.maxWidth - maximum width
* @param {number} options.minHeight - minimum height
* @param {number} options.maxHeight - maximum height
* @param {number} [options.minWidth=0] - minimum width
* @param {number} [options.maxWidth=0] - maximum width
* @param {number} [options.minHeight=Infinity] - minimum height
* @param {number} [options.maxHeight=Infinity] - maximum height
* @param {number|string} [options.width='auto'] - default height
* @param {number|string} [options.height='auto'] - default height
* @ignore
*/
function chartExtension(editor, options = {}) {
Expand Down
14 changes: 13 additions & 1 deletion test/unit/extensions/chart.spec.js
Expand Up @@ -421,12 +421,24 @@ describe('CodeBlockChart', () => {
expect(chartOptions.chart.height).toBe(0);
});

it('should respect default width/height', () =>{
let chartOptions = setDefaultOptions({
}, {
width: 300,
height: 400
}, container);
expect(chartOptions.chart.width).toBe(300);
expect(chartOptions.chart.height).toBe(400);
});

it('should use width/height from codeblock', () =>{
const extensionOptions = {
minWidth: 300,
minHeight: 400,
maxWidth: 700,
maxHeight: 800
maxHeight: 800,
width: 400,
height: 500
};
let chartOptions = setDefaultOptions({
chart: {
Expand Down

0 comments on commit 88805be

Please sign in to comment.