From 116b014c556d33a9faf45d70978126447f67ce55 Mon Sep 17 00:00:00 2001 From: Jamie Peabody Date: Sun, 9 Jun 2024 22:19:10 +0100 Subject: [PATCH] feat: Allows height to be not explicit height, e.g. 'inherit' or '100%' --- src/diff-view.js | 15 +++++++++------ src/mergely.js | 4 +++- webpack.prod.js | 4 ++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/diff-view.js b/src/diff-view.js index e4524ca..9507d80 100644 --- a/src/diff-view.js +++ b/src/diff-view.js @@ -65,7 +65,6 @@ CodeMirrorDiffView.prototype.unbind = function() { this.el.removeChild(this.el.lastChild); } if (this._origEl) { - this.el.style = this._origEl.style; this.el.className = this._origEl.className; } this._unbound = true; @@ -257,16 +256,17 @@ CodeMirrorDiffView.prototype.resize = function() { CodeMirrorDiffView.prototype.bind = function(container) { this.trace('api#bind', container); - this._origEl = { - style: container.style, - className: container.className - }; const el = dom.getMergelyContainer({ clazz: container.className }); const computedStyle = window.getComputedStyle(container); - if (!computedStyle.height || computedStyle.height === '0px') { + if (!el.style.height + && (!computedStyle.height || computedStyle.height === '0px') + ) { throw new Error( `The element "${container.id}" requires an explicit height`); } + this._origEl = { + className: container.className + }; this.id = `${container.id}`; this.lhsId = `${container.id}-lhs`; this.rhsId = `${container.id}-rhs`; @@ -753,6 +753,9 @@ CodeMirrorDiffView.prototype._set_top_offset = function (side) { // this is the distance from the top of the screen to the top of the // content of the first codemirror editor const topnode = this._queryElement('.CodeMirror-measure'); + if (!topnode.offsetParent) { + return false; + } const top_offset = topnode.offsetParent.offsetTop + 4; // restore editor's scroll position diff --git a/src/mergely.js b/src/mergely.js index 2d64cb0..1d027be 100644 --- a/src/mergely.js +++ b/src/mergely.js @@ -46,7 +46,9 @@ class Mergely { } const computedStyle = window.getComputedStyle(element); - if (!computedStyle.height || computedStyle.height === '0px') { + if (!element.style.height + && (!computedStyle.height || computedStyle.height === '0px') + ) { throw new Error( `The element "${selector}" requires an explicit height`); } diff --git a/webpack.prod.js b/webpack.prod.js index 2d9aee9..9e80849 100644 --- a/webpack.prod.js +++ b/webpack.prod.js @@ -15,6 +15,10 @@ module.exports = (mode) => { ...webpackDevConfig.output, path: path.join(__dirname, 'lib'), filename: './[name].js', + library: { + name: 'mergely', + type: 'umd', + } }, optimization: { minimize: true,