Skip to content

Commit 83e5797

Browse files
committed
update
1 parent 3fc2414 commit 83e5797

File tree

10 files changed

+167
-220
lines changed

10 files changed

+167
-220
lines changed

dist/index.common.js

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

dist/index.js

Lines changed: 49 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
(function (global, factory) {
22
if (typeof define === "function" && define.amd) {
3-
define("vxe-table-plugin-renderer", ["exports", "xe-utils"], factory);
3+
define("vxe-table-plugin-renderer", [], factory);
44
} else if (typeof exports !== "undefined") {
5-
factory(exports, require("xe-utils"));
5+
factory();
66
} else {
77
var mod = {
88
exports: {}
99
};
10-
factory(mod.exports, global.XEUtils);
10+
factory();
1111
global.VXETablePluginRenderer = mod.exports.default;
1212
}
13-
})(this, function (_exports, _xeUtils) {
13+
})(this, function () {
1414
"use strict";
1515

16-
Object.defineProperty(_exports, "__esModule", {
17-
value: true
18-
});
19-
_exports["default"] = _exports.VXETablePluginRenderer = void 0;
20-
_xeUtils = _interopRequireDefault(_xeUtils);
16+
exports.__esModule = true;
2117

22-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
18+
var xe_utils_1 = require("xe-utils");
2319

2420
function getCursorPosition(textarea) {
2521
var rangeData = {
@@ -31,23 +27,6 @@
3127
if (textarea.setSelectionRange) {
3228
rangeData.start = textarea.selectionStart;
3329
rangeData.end = textarea.selectionEnd;
34-
rangeData.text = rangeData.start !== rangeData.end ? textarea.value.substring(rangeData.start, rangeData.end) : '';
35-
} else if (document.selection) {
36-
var index = 0;
37-
var range = document.selection.createRange();
38-
var textRange = document.body.createTextRange();
39-
textRange.moveToElementText(textarea);
40-
rangeData.text = range.text;
41-
rangeData.bookmark = range.getBookmark();
42-
43-
for (; textRange.compareEndPoints('StartToStart', range) < 0 && range.moveStart('character', -1) !== 0; index++) {
44-
if (textarea.value.charAt(index) === '\n') {
45-
index++;
46-
}
47-
}
48-
49-
rangeData.start = index;
50-
rangeData.end = rangeData.text.length + rangeData.start;
5130
}
5231

5332
return rangeData;
@@ -57,28 +36,22 @@
5736
if (textarea.setSelectionRange) {
5837
textarea.focus();
5938
textarea.setSelectionRange(rangeData.start, rangeData.end);
60-
} else if (textarea.createTextRange) {
61-
var textRange = textarea.createTextRange();
62-
63-
if (textarea.value.length === rangeData.start) {
64-
textRange.collapse(false);
65-
textRange.select();
66-
} else {
67-
textRange.moveToBookmark(rangeData.bookmark);
68-
textRange.select();
69-
}
7039
}
7140
}
7241

73-
var $text = document.createElement('span');
74-
$text.className = 'x-textarea--resize';
75-
$text.style.visibility = 'hidden';
76-
$text.style.zIndex = '-1';
77-
$text.style.position = 'absolute';
42+
var $text;
43+
44+
if (typeof document !== 'undefined') {
45+
$text = document.createElement('span');
46+
$text.className = 'x-textarea--resize';
47+
$text.style.visibility = 'hidden';
48+
$text.style.zIndex = '-1';
49+
$text.style.position = 'absolute';
50+
}
7851

7952
function autoResizeTextarea(evnt, renderOpts, params) {
80-
var _renderOpts$props = renderOpts.props,
81-
props = _renderOpts$props === void 0 ? {} : _renderOpts$props;
53+
var _a = renderOpts.props,
54+
props = _a === void 0 ? {} : _a;
8255
var $table = params.$table,
8356
column = params.column;
8457
var minWidth = column.renderWidth,
@@ -87,16 +60,16 @@
8760

8861
var maxWidth = props.maxWidth || 600;
8962
var maxHeight = props.maxHeight || 400;
90-
$text.textContent = "".concat(inpElem.value, "\n");
91-
$text.style.maxWidth = "".concat(maxWidth, "px");
63+
$text.textContent = inpElem.value + "\n";
64+
$text.style.maxWidth = maxWidth + "px";
9265

9366
if (!$text.parentNode) {
9467
$table.$el.appendChild($text);
9568
}
9669

9770
var height = Math.min(maxHeight, $text.offsetHeight + 4);
98-
inpElem.style.width = "".concat(Math.min(maxWidth, Math.max(minWidth, $text.offsetWidth + 20)), "px");
99-
inpElem.style.height = "".concat(height < minHeight ? minHeight : height, "px");
71+
inpElem.style.width = Math.min(maxWidth, Math.max(minWidth, $text.offsetWidth + 20)) + "px";
72+
inpElem.style.height = (height < minHeight ? minHeight : height) + "px";
10073
inpElem.style.overflowY = height > maxWidth ? 'auto' : '';
10174
}
10275

@@ -115,7 +88,7 @@
11588
};
11689

11790
if (events) {
118-
_xeUtils["default"].assign(on, _xeUtils["default"].objectMap(events, function (cb) {
91+
xe_utils_1["default"].assign(on, xe_utils_1["default"].objectMap(events, function (cb) {
11992
return function () {
12093
cb.apply(null, [params].concat.apply(params, arguments));
12194
};
@@ -133,11 +106,11 @@
133106
XInput: {
134107
autofocus: '.x-input',
135108
renderEdit: function renderEdit(h, renderOpts, params) {
136-
var _renderOpts$props2 = renderOpts.props,
137-
props = _renderOpts$props2 === void 0 ? {} : _renderOpts$props2,
109+
var _a = renderOpts.props,
110+
props = _a === void 0 ? {} : _a,
138111
attrs = renderOpts.attrs,
139-
_renderOpts$events = renderOpts.events,
140-
events = _renderOpts$events === void 0 ? {} : _renderOpts$events;
112+
_b = renderOpts.events,
113+
events = _b === void 0 ? {} : _b;
141114
var column = params.column;
142115
var model = column.model;
143116
var prefixIcon = props.prefixIcon,
@@ -150,7 +123,7 @@
150123
'is--suffix': props.suffixIcon
151124
}],
152125
style: {
153-
height: "".concat(column.renderHeight - 1, "px")
126+
height: column.renderHeight - 1 + "px"
154127
}
155128
}, [prefixIcon ? h('i', {
156129
"class": ['x-input--prefix', prefixIcon, {
@@ -202,15 +175,15 @@
202175
return [h('div', {
203176
"class": 'x-textarea--wrapper',
204177
style: {
205-
height: "".concat(column.renderHeight - 1, "px")
178+
height: column.renderHeight - 1 + "px"
206179
}
207180
}, [h('textarea', {
208181
"class": 'x-textarea',
209182
attrs: attrs,
210183
domProps: {
211184
value: model.value
212185
},
213-
on: _xeUtils["default"].assign(getEvents(renderOpts, params), {
186+
on: xe_utils_1["default"].assign(getEvents(renderOpts, params), {
214187
cut: autoResizeEvent,
215188
paste: autoResizeEvent,
216189
drop: autoResizeEvent,
@@ -219,21 +192,21 @@
219192
if (evnt.keyCode === 13 && (!$table.keyboardConfig || evnt.altKey)) {
220193
evnt.preventDefault();
221194
evnt.stopPropagation();
222-
var inpElem = evnt.target;
223-
var rangeData = getCursorPosition(inpElem);
224-
var pos = rangeData.end;
225-
var cellValue = inpElem.value;
226-
cellValue = "".concat(cellValue.slice(0, pos), "\n").concat(cellValue.slice(pos, cellValue.length));
227-
inpElem.value = cellValue;
195+
var inpElem_1 = evnt.target;
196+
var rangeData_1 = getCursorPosition(inpElem_1);
197+
var pos_1 = rangeData_1.end;
198+
var cellValue = inpElem_1.value;
199+
cellValue = cellValue.slice(0, pos_1) + "\n" + cellValue.slice(pos_1, cellValue.length);
200+
inpElem_1.value = cellValue;
228201
model.update = true;
229202
model.value = cellValue;
230203
setTimeout(function () {
231-
rangeData.start = rangeData.end = ++pos;
232-
setCursorPosition(inpElem, rangeData);
233-
autoResizeEvent(evnt, renderOpts, params);
204+
rangeData_1.start = rangeData_1.end = ++pos_1;
205+
setCursorPosition(inpElem_1, rangeData_1);
206+
autoResizeEvent(evnt);
234207
});
235208
} else {
236-
autoResizeEvent(evnt, renderOpts, params);
209+
autoResizeEvent(evnt);
237210
}
238211
},
239212
compositionstart: autoResizeEvent,
@@ -247,21 +220,23 @@
247220
column = params.column;
248221
return [h('span', {
249222
"class": 'x-textarea--content'
250-
}, _xeUtils["default"].get(row, column.property))];
223+
}, xe_utils_1["default"].get(row, column.property))];
251224
}
252225
}
253226
};
254-
var VXETablePluginRenderer = {
255-
install: function install(VXETable) {
256-
VXETable.renderer.mixin(renderMap);
227+
/**
228+
* 基于 vxe-table 表格的增强插件,提供一些常用的渲染器
229+
*/
230+
231+
exports.VXETablePluginRenderer = {
232+
install: function install(xtable) {
233+
xtable.renderer.mixin(renderMap);
257234
}
258235
};
259-
_exports.VXETablePluginRenderer = VXETablePluginRenderer;
260236

261237
if (typeof window !== 'undefined' && window.VXETable) {
262-
window.VXETable.use(VXETablePluginRenderer);
238+
window.VXETable.use(exports.VXETablePluginRenderer);
263239
}
264240

265-
var _default = VXETablePluginRenderer;
266-
_exports["default"] = _default;
241+
exports["default"] = exports.VXETablePluginRenderer;
267242
});

dist/index.min.js

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

gulpfile.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const gulp = require('gulp')
2+
const del = require('del')
23
const uglify = require('gulp-uglify')
34
const babel = require('gulp-babel')
45
const rename = require('gulp-rename')
56
const replace = require('gulp-replace')
67
const sass = require('gulp-sass')
78
const cleanCSS = require('gulp-clean-css')
89
const prefixer = require('gulp-autoprefixer')
10+
const sourcemaps = require('gulp-sourcemaps')
11+
const ts = require('gulp-typescript')
912
const pack = require('./package.json')
1013

1114
const exportModuleName = 'VXETablePluginRenderer'
@@ -27,20 +30,28 @@ gulp.task('build_style', function () {
2730
})
2831

2932
gulp.task('build_commonjs', function () {
30-
return gulp.src('index.js')
33+
return gulp.src(['test.ts', 'index.ts'])
34+
.pipe(sourcemaps.init())
35+
.pipe(ts({
36+
noImplicitAny: true
37+
}))
3138
.pipe(babel({
3239
presets: ['@babel/env']
3340
}))
3441
.pipe(rename({
3542
basename: 'index',
3643
extname: '.common.js'
3744
}))
45+
.pipe(sourcemaps.write())
3846
.pipe(gulp.dest('dist'))
3947
})
4048

4149
gulp.task('build_umd', function () {
42-
return gulp.src('index.js')
43-
.pipe(replace(`from 'xe-utils/methods/xe-utils'`, `from 'xe-utils'`))
50+
return gulp.src(['test.ts', 'index.ts'])
51+
.pipe(ts({
52+
noImplicitAny: true
53+
}))
54+
.pipe(replace(`require("xe-utils/methods/xe-utils")`, `require("xe-utils")`))
4455
.pipe(babel({
4556
moduleId: pack.name,
4657
presets: ['@babel/env'],
@@ -61,4 +72,10 @@ gulp.task('build_umd', function () {
6172
.pipe(gulp.dest('dist'))
6273
})
6374

64-
gulp.task('build', gulp.parallel('build_style', 'build_commonjs', 'build_umd'))
75+
gulp.task('clear', () => {
76+
return del([
77+
'dist/test.*'
78+
])
79+
})
80+
81+
gulp.task('build', gulp.series(gulp.parallel('build_commonjs', 'build_umd', 'build_style'), 'clear'))

index.d.ts

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

0 commit comments

Comments
 (0)