weex-nuke
Version:
基于 Rax 、Weex 的高性能组件体系 ~~
105 lines (82 loc) • 3.18 kB
JavaScript
/** @jsx createElement */
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.show = show;
exports.hide = hide;
var _rax = require('rax');
var _nukeDom = require('../../Dom/index.js');
var _nukeDom2 = _interopRequireDefault(_nukeDom);
var _nukeEnv = require('../../Env/index.js');
var _picker = require('./picker.js');
var _picker2 = _interopRequireDefault(_picker);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var noop = function noop() {};
var pickerInstance = null;
var container = null;
function show() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var onSelect = arguments[1];
var onCancel = arguments[2];
var onShow = arguments[3];
var onFail = arguments[4];
onSelect = onSelect || noop;
onShow = onShow || noop;
onFail = onFail || noop;
onCancel = onCancel || noop;
var title = options.title,
dataSource = options.dataSource,
selectedKey = options.selectedKey,
locale = options.locale,
_options$maskClosable = options.maskClosable,
maskClosable = _options$maskClosable === undefined ? true : _options$maskClosable,
visible = options.visible,
value = options.value,
content = options.content,
children = options.children,
others = _objectWithoutProperties(options, ['title', 'dataSource', 'selectedKey', 'locale', 'maskClosable', 'visible', 'value', 'content', 'children']);
if (!dataSource || !dataSource[0]) {
onFail({ err: 'empty dataSource' });
return;
}
var attrs = {
title: title,
maskClosable: maskClosable,
dataSource: dataSource,
selectedKey: value || selectedKey,
afterClose: afterCloseCallback,
onCancel: onCancel,
onDone: onSelect
};
if (locale) {
attrs.locale = locale;
}
var picker = (0, _rax.createElement)(_picker2.default, _extends({}, others, attrs));
function afterCloseCallback() {
(0, _rax.unmountComponentAtNode)(container);
document.body.removeChild(container);
pickerInstance = picker = container = null;
}
if (options.container) {
container = (0, _rax.findDOMNode)(options.container);
}
// container = options.container || null;
if (!container) {
container = _nukeDom2.default.createEle('div', { t: 'id', abc: '_nuke_wrap' });
document.body.appendChild(container);
}
(0, _rax.render)(picker, container, function () {
pickerInstance = this;
pickerInstance.wrappedInstance.show();
});
}
function hide() {
if (_nukeEnv.isWeex) {
// native 暂不支持
} else if (pickerInstance) {
pickerInstance.wrappedInstance.hide();
}
}