209 lines
6.1 KiB
JavaScript
209 lines
6.1 KiB
JavaScript
/*!
|
|
* @form-create/component-elm-select v3.2.0
|
|
* (c) 2018-2024 xaboy
|
|
* Github https://github.com/xaboy/form-create with select
|
|
* Released under the MIT License.
|
|
*/
|
|
(function (global, factory) {
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
|
|
typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
|
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.FcSelect = {}, global.Vue));
|
|
})(this, (function (exports, vue) { 'use strict';
|
|
|
|
function ownKeys(object, enumerableOnly) {
|
|
var keys = Object.keys(object);
|
|
|
|
if (Object.getOwnPropertySymbols) {
|
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
|
|
if (enumerableOnly) {
|
|
symbols = symbols.filter(function (sym) {
|
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
});
|
|
}
|
|
|
|
keys.push.apply(keys, symbols);
|
|
}
|
|
|
|
return keys;
|
|
}
|
|
|
|
function _objectSpread2(target) {
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
|
|
if (i % 2) {
|
|
ownKeys(Object(source), true).forEach(function (key) {
|
|
_defineProperty(target, key, source[key]);
|
|
});
|
|
} else if (Object.getOwnPropertyDescriptors) {
|
|
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
} else {
|
|
ownKeys(Object(source)).forEach(function (key) {
|
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
});
|
|
}
|
|
}
|
|
|
|
return target;
|
|
}
|
|
|
|
function _typeof(obj) {
|
|
"@babel/helpers - typeof";
|
|
|
|
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
_typeof = function (obj) {
|
|
return typeof obj;
|
|
};
|
|
} else {
|
|
_typeof = function (obj) {
|
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
};
|
|
}
|
|
|
|
return _typeof(obj);
|
|
}
|
|
|
|
function _defineProperty(obj, key, value) {
|
|
if (key in obj) {
|
|
Object.defineProperty(obj, key, {
|
|
value: value,
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true
|
|
});
|
|
} else {
|
|
obj[key] = value;
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
function getSlot(slots, exclude) {
|
|
return Object.keys(slots).reduce(function (lst, name) {
|
|
if (!exclude || exclude.indexOf(name) === -1) {
|
|
lst.push(slots[name]);
|
|
}
|
|
|
|
return lst;
|
|
}, []);
|
|
}
|
|
|
|
var is = {
|
|
type: function type(arg, _type) {
|
|
return Object.prototype.toString.call(arg) === '[object ' + _type + ']';
|
|
},
|
|
Undef: function Undef(v) {
|
|
return v === undefined || v === null;
|
|
},
|
|
Element: function Element(arg) {
|
|
return _typeof(arg) === 'object' && arg !== null && arg.nodeType === 1 && !is.Object(arg);
|
|
},
|
|
trueArray: function trueArray(data) {
|
|
return Array.isArray(data) && data.length > 0;
|
|
},
|
|
Function: function Function(v) {
|
|
var type = this.getType(v);
|
|
return type === 'Function' || type === 'AsyncFunction';
|
|
},
|
|
getType: function getType(v) {
|
|
var str = Object.prototype.toString.call(v);
|
|
return /^\[object (.*)\]$/.exec(str)[1];
|
|
},
|
|
empty: function empty(value) {
|
|
if (value === undefined || value === null) {
|
|
return true;
|
|
}
|
|
|
|
if (Array.isArray(value) && Array.isArray(value) && !value.length) {
|
|
return true;
|
|
}
|
|
|
|
return typeof value === 'string' && !value;
|
|
}
|
|
};
|
|
['Date', 'Object', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
|
|
is[t] = function (arg) {
|
|
return is.type(arg, t);
|
|
};
|
|
});
|
|
function hasProperty(rule, k) {
|
|
return {}.hasOwnProperty.call(rule, k);
|
|
}
|
|
|
|
var NAME = 'fcSelect';
|
|
var Select = vue.defineComponent({
|
|
name: NAME,
|
|
inheritAttrs: false,
|
|
props: {
|
|
formCreateInject: Object,
|
|
modelValue: {
|
|
type: [Array, String, Number, Boolean, Object],
|
|
"default": undefined
|
|
},
|
|
type: String
|
|
},
|
|
emits: ['update:modelValue', 'fc.el'],
|
|
setup: function setup(props) {
|
|
var options = vue.toRef(props.formCreateInject, 'options', []);
|
|
var value = vue.toRef(props, 'modelValue');
|
|
|
|
var _options = function _options() {
|
|
return Array.isArray(options.value) ? options.value : [];
|
|
};
|
|
|
|
return {
|
|
options: _options,
|
|
value: value
|
|
};
|
|
},
|
|
render: function render() {
|
|
var _this = this,
|
|
_this$$slots$default,
|
|
_this$$slots;
|
|
|
|
var makeOption = function makeOption(props, index) {
|
|
return vue.createVNode(vue.resolveComponent("ElOption"), vue.mergeProps(props, {
|
|
"key": '' + index + '-' + props.value
|
|
}), null);
|
|
};
|
|
|
|
var makeOptionGroup = function makeOptionGroup(props, index) {
|
|
return vue.createVNode(vue.resolveComponent("ElOptionGroup"), {
|
|
"label": props.label,
|
|
"key": '' + index + '-' + props.label
|
|
}, {
|
|
"default": function _default() {
|
|
return [is.trueArray(props.options) && props.options.map(function (v, index) {
|
|
return makeOption(v, index);
|
|
})];
|
|
}
|
|
});
|
|
};
|
|
|
|
var options = this.options();
|
|
return vue.createVNode(vue.resolveComponent("ElSelect"), vue.mergeProps(this.$attrs, {
|
|
"modelValue": this.value,
|
|
"onUpdate:modelValue": function onUpdateModelValue(v) {
|
|
return _this.$emit('update:modelValue', v);
|
|
},
|
|
"ref": "el"
|
|
}), _objectSpread2({
|
|
"default": function _default() {
|
|
return [options.map(function (props, index) {
|
|
return hasProperty(props || '', 'options') ? makeOptionGroup(props, index) : makeOption(props, index);
|
|
}), (_this$$slots$default = (_this$$slots = _this.$slots)["default"]) === null || _this$$slots$default === void 0 ? void 0 : _this$$slots$default.call(_this$$slots)];
|
|
}
|
|
}, getSlot(this.$slots, ['default'])));
|
|
},
|
|
mounted: function mounted() {
|
|
this.$emit('fc.el', this.$refs.el);
|
|
}
|
|
});
|
|
|
|
exports["default"] = Select;
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
}));
|