Skip to content

Commit 5bb07e3

Browse files
committed
Simplify tests for now
1 parent c36118e commit 5bb07e3

23 files changed

+9807
-11113
lines changed

.babelrc

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
{
22
"presets": [
33
[
4-
"es2015",
4+
"@babel/preset-env",
55
{
66
"modules": false
77
}
88
]
99
],
1010
"env": {
11-
"testing": {
11+
"test": {
1212
"presets": [
13-
["env", {
14-
"targets": {
15-
"browsers": ["last 2 versions", "safari >= 7"]
16-
},
17-
"modules": false
18-
}]
19-
],
20-
"plugins": [
21-
["transform-runtime", {
22-
"polyfill": false,
23-
"regenerator": true
24-
}]
13+
[
14+
"@babel/preset-env"
15+
]
2516
]
2617
}
2718
}

.eslintrc.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

__tests__/VueInputAutowidth.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { shallowMount } from "@vue/test-utils"
2+
import VueInputAutowidth from "../src"
3+
4+
describe("VueTribute", () => {
5+
it("mounts", () => {
6+
const TextInput = {
7+
template: `<input type="text" v-model="text" v-autowidth="{maxWidth: '960px', minWidth: '20px', comfortZone: 0}" />`,
8+
directives: {
9+
autowidth: VueInputAutowidth
10+
},
11+
data() {
12+
return {
13+
text: "Hello World"
14+
}
15+
}
16+
}
17+
const wrapper = shallowMount(TextInput)
18+
19+
expect(wrapper.find('input[type=text]').element.value).toBe("Hello World")
20+
})
21+
})

dist/index.esm.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import 'es6-object-assign/auto';
2+
3+
function checkWidth (el, binding) {
4+
var mirror = document.querySelector(".vue-input-autowidth-mirror-".concat(el.dataset.uuid));
5+
var defaults = {
6+
maxWidth: "none",
7+
minWidth: "none",
8+
comfortZone: 0
9+
};
10+
var options = Object.assign({}, defaults, binding.value);
11+
el.style.maxWidth = options.maxWidth;
12+
el.style.minWidth = options.minWidth;
13+
var val = el.value;
14+
15+
if (!val) {
16+
val = el.placeholder || "";
17+
}
18+
19+
while (mirror.childNodes.length) {
20+
mirror.removeChild(mirror.childNodes[0]);
21+
}
22+
23+
mirror.appendChild(document.createTextNode(val));
24+
var newWidth = mirror.scrollWidth + options.comfortZone + 2;
25+
26+
if (newWidth != el.scrollWidth) {
27+
el.style.width = "".concat(newWidth, "px");
28+
}
29+
}
30+
31+
var directive = {
32+
bind: function bind(el) {
33+
if (el.tagName.toLocaleUpperCase() !== "INPUT") {
34+
throw new Error("v-input-autowidth can only be used on input elements.");
35+
}
36+
37+
el.dataset.uuid = Math.random().toString(36).slice(-5);
38+
el.style.boxSizing = "content-box";
39+
},
40+
inserted: function inserted(el, binding) {
41+
var styles = window.getComputedStyle(el);
42+
el.mirror = document.createElement("span");
43+
Object.assign(el.mirror.style, {
44+
position: "absolute",
45+
top: "0",
46+
left: "0",
47+
visibility: "hidden",
48+
height: "0",
49+
overflow: "scroll",
50+
whiteSpace: "pre",
51+
fontSize: styles.fontSize,
52+
fontFamily: styles.fontFamily,
53+
fontWeight: styles.fontWeight,
54+
fontStyle: styles.fontStyle,
55+
letterSpacing: styles.letterSpacing,
56+
textTransform: styles.textTransform
57+
});
58+
el.mirror.classList.add("vue-input-autowidth-mirror-".concat(el.dataset.uuid));
59+
el.mirror.setAttribute("aria-hidden", "true");
60+
document.body.appendChild(el.mirror);
61+
checkWidth(el, binding);
62+
},
63+
componentUpdated: function componentUpdated(el, binding) {
64+
checkWidth(el, binding);
65+
},
66+
unbind: function unbind(el) {
67+
document.body.removeChild(el.mirror);
68+
}
69+
};
70+
71+
var install = function install(Vue) {
72+
Vue.directive("autowidth", directive);
73+
};
74+
75+
if (typeof window !== "undefined" && window.Vue) {
76+
window.Vue.use(install);
77+
}
78+
79+
directive.install = install;
80+
81+
export default directive;

dist/index.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'use strict';
2+
3+
require('es6-object-assign/auto');
4+
5+
function checkWidth (el, binding) {
6+
var mirror = document.querySelector(".vue-input-autowidth-mirror-".concat(el.dataset.uuid));
7+
var defaults = {
8+
maxWidth: "none",
9+
minWidth: "none",
10+
comfortZone: 0
11+
};
12+
var options = Object.assign({}, defaults, binding.value);
13+
el.style.maxWidth = options.maxWidth;
14+
el.style.minWidth = options.minWidth;
15+
var val = el.value;
16+
17+
if (!val) {
18+
val = el.placeholder || "";
19+
}
20+
21+
while (mirror.childNodes.length) {
22+
mirror.removeChild(mirror.childNodes[0]);
23+
}
24+
25+
mirror.appendChild(document.createTextNode(val));
26+
var newWidth = mirror.scrollWidth + options.comfortZone + 2;
27+
28+
if (newWidth != el.scrollWidth) {
29+
el.style.width = "".concat(newWidth, "px");
30+
}
31+
}
32+
33+
var directive = {
34+
bind: function bind(el) {
35+
if (el.tagName.toLocaleUpperCase() !== "INPUT") {
36+
throw new Error("v-input-autowidth can only be used on input elements.");
37+
}
38+
39+
el.dataset.uuid = Math.random().toString(36).slice(-5);
40+
el.style.boxSizing = "content-box";
41+
},
42+
inserted: function inserted(el, binding) {
43+
var styles = window.getComputedStyle(el);
44+
el.mirror = document.createElement("span");
45+
Object.assign(el.mirror.style, {
46+
position: "absolute",
47+
top: "0",
48+
left: "0",
49+
visibility: "hidden",
50+
height: "0",
51+
overflow: "scroll",
52+
whiteSpace: "pre",
53+
fontSize: styles.fontSize,
54+
fontFamily: styles.fontFamily,
55+
fontWeight: styles.fontWeight,
56+
fontStyle: styles.fontStyle,
57+
letterSpacing: styles.letterSpacing,
58+
textTransform: styles.textTransform
59+
});
60+
el.mirror.classList.add("vue-input-autowidth-mirror-".concat(el.dataset.uuid));
61+
el.mirror.setAttribute("aria-hidden", "true");
62+
document.body.appendChild(el.mirror);
63+
checkWidth(el, binding);
64+
},
65+
componentUpdated: function componentUpdated(el, binding) {
66+
checkWidth(el, binding);
67+
},
68+
unbind: function unbind(el) {
69+
document.body.removeChild(el.mirror);
70+
}
71+
};
72+
73+
var install = function install(Vue) {
74+
Vue.directive("autowidth", directive);
75+
};
76+
77+
if (typeof window !== "undefined" && window.Vue) {
78+
window.Vue.use(install);
79+
}
80+
81+
directive.install = install;
82+
83+
module.exports = directive;

dist/index.umd.js

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3+
typeof define === 'function' && define.amd ? define(factory) :
4+
(global = global || self, global.VueInputAutoWidth = factory());
5+
}(this, function () { 'use strict';
6+
7+
/**
8+
* Code refactored from Mozilla Developer Network:
9+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
10+
*/
11+
12+
function assign(target, firstSource) {
13+
if (target === undefined || target === null) {
14+
throw new TypeError('Cannot convert first argument to object');
15+
}
16+
17+
var to = Object(target);
18+
for (var i = 1; i < arguments.length; i++) {
19+
var nextSource = arguments[i];
20+
if (nextSource === undefined || nextSource === null) {
21+
continue;
22+
}
23+
24+
var keysArray = Object.keys(Object(nextSource));
25+
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
26+
var nextKey = keysArray[nextIndex];
27+
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
28+
if (desc !== undefined && desc.enumerable) {
29+
to[nextKey] = nextSource[nextKey];
30+
}
31+
}
32+
}
33+
return to;
34+
}
35+
36+
function polyfill() {
37+
if (!Object.assign) {
38+
Object.defineProperty(Object, 'assign', {
39+
enumerable: false,
40+
configurable: true,
41+
writable: true,
42+
value: assign
43+
});
44+
}
45+
}
46+
47+
var es6ObjectAssign = {
48+
assign: assign,
49+
polyfill: polyfill
50+
};
51+
52+
es6ObjectAssign.polyfill();
53+
54+
function checkWidth (el, binding) {
55+
var mirror = document.querySelector(".vue-input-autowidth-mirror-".concat(el.dataset.uuid));
56+
var defaults = {
57+
maxWidth: "none",
58+
minWidth: "none",
59+
comfortZone: 0
60+
};
61+
var options = Object.assign({}, defaults, binding.value);
62+
el.style.maxWidth = options.maxWidth;
63+
el.style.minWidth = options.minWidth;
64+
var val = el.value;
65+
66+
if (!val) {
67+
val = el.placeholder || "";
68+
}
69+
70+
while (mirror.childNodes.length) {
71+
mirror.removeChild(mirror.childNodes[0]);
72+
}
73+
74+
mirror.appendChild(document.createTextNode(val));
75+
var newWidth = mirror.scrollWidth + options.comfortZone + 2;
76+
77+
if (newWidth != el.scrollWidth) {
78+
el.style.width = "".concat(newWidth, "px");
79+
}
80+
}
81+
82+
var directive = {
83+
bind: function bind(el) {
84+
if (el.tagName.toLocaleUpperCase() !== "INPUT") {
85+
throw new Error("v-input-autowidth can only be used on input elements.");
86+
}
87+
88+
el.dataset.uuid = Math.random().toString(36).slice(-5);
89+
el.style.boxSizing = "content-box";
90+
},
91+
inserted: function inserted(el, binding) {
92+
var styles = window.getComputedStyle(el);
93+
el.mirror = document.createElement("span");
94+
Object.assign(el.mirror.style, {
95+
position: "absolute",
96+
top: "0",
97+
left: "0",
98+
visibility: "hidden",
99+
height: "0",
100+
overflow: "scroll",
101+
whiteSpace: "pre",
102+
fontSize: styles.fontSize,
103+
fontFamily: styles.fontFamily,
104+
fontWeight: styles.fontWeight,
105+
fontStyle: styles.fontStyle,
106+
letterSpacing: styles.letterSpacing,
107+
textTransform: styles.textTransform
108+
});
109+
el.mirror.classList.add("vue-input-autowidth-mirror-".concat(el.dataset.uuid));
110+
el.mirror.setAttribute("aria-hidden", "true");
111+
document.body.appendChild(el.mirror);
112+
checkWidth(el, binding);
113+
},
114+
componentUpdated: function componentUpdated(el, binding) {
115+
checkWidth(el, binding);
116+
},
117+
unbind: function unbind(el) {
118+
document.body.removeChild(el.mirror);
119+
}
120+
};
121+
122+
var install = function install(Vue) {
123+
Vue.directive("autowidth", directive);
124+
};
125+
126+
if (typeof window !== "undefined" && window.Vue) {
127+
window.Vue.use(install);
128+
}
129+
130+
directive.install = install;
131+
132+
return directive;
133+
134+
}));

dist/index.umd.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.umd.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/dist/assets/css/chunk-vendors.a85fa284.chunk.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)