Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

antd-mini

Package Overview
Dependencies
Maintainers
4
Versions
213
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antd-mini - npm Package Compare versions

Comparing version 2.30.2 to 2.31.0

52

compiled/wechat/src/Checkbox/CheckboxGroup/index.js

@@ -10,20 +10,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

};
import { useEvent } from 'functional-mini/component';
import { mountComponent } from '../../_util/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
import { useMixState } from '../../_util/hooks/useMixState';
import { CheckboxGroupFunctionalProps } from './props';
var CheckboxGroup = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (value) {
return {
valid: true,
value: value || [],
};
},
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (args, e) {
if (props.disabled) {
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { CheckboxGroupDefaultProps } from './props';
import mixinValue from '../../mixins/value';
Component(CheckboxGroupDefaultProps, {
onChange: function (args, e) {
if (getValueFromProps(this, 'disabled')) {
return;

@@ -33,5 +21,5 @@ }

event = args;
var currentValue = value;
var currentValue = this.getValue();
var index = event.currentTarget.dataset.index;
var selectValue = props.options[index].value;
var selectValue = getValueFromProps(this, 'options')[index].value;
if (currentValue.indexOf(selectValue) > -1) {

@@ -43,11 +31,17 @@ currentValue = currentValue.filter(function (v) { return v !== selectValue; });

}
if (!isControlled) {
update(currentValue);
if (!this.isControlled()) {
this.update(currentValue);
}
triggerEvent('change', currentValue, e);
});
return {
mixin: { value: value },
};
};
mountComponent(CheckboxGroup, CheckboxGroupFunctionalProps);
triggerEvent(this, 'change', currentValue, e);
},
}, null, [
mixinValue({
transformValue: function (val) {
var value = val || [];
return {
needUpdate: true,
value: value,
};
},
}),
]);
export var CheckboxGroupDefaultProps = {
options: [],
position: 'vertical',
defaultValue: [],
};
export var CheckboxGroupFunctionalProps = {
value: null,

@@ -8,0 +3,0 @@ defaultValue: [],

@@ -1,30 +0,17 @@

import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
var Checkbox = function (props) {
var _a = useMixState(props.defaultChecked, {
value: props.checked,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
var newValue = !value;
if (!isControlled) {
update(newValue);
import { CheckboxDefaultProps } from './props';
import { Component, triggerEvent } from '../_util/simply';
import mixinValue from '../mixins/value';
Component(CheckboxDefaultProps, {
onChange: function (e) {
var value = !this.getValue();
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', newValue, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(Checkbox, {
value: null,
checked: null,
defaultChecked: null,
disabled: false,
color: '',
});
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

@@ -1,1 +0,7 @@

export var CheckboxDefaultProps = {};
export var CheckboxDefaultProps = {
value: null,
checked: null,
defaultChecked: null,
disabled: false,
color: '',
};

@@ -1,7 +0,7 @@

import { Component, triggerEvent } from '../../_util/simply';
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { ChecklistItemDefaultProps } from './props';
Component(ChecklistItemDefaultProps, {
onChecklistItemClick: function () {
triggerEvent(this, 'change', this.properties.item);
}
triggerEvent(this, 'change', getValueFromProps(this, 'item'));
},
});

@@ -10,24 +10,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

};
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useHandleCustomEvent } from '../_util/hooks/useHandleCustomEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { ChecklistFunctionalProps, } from './props';
var Checkbox = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (val) {
var value = val || [];
return {
valid: true,
value: value,
};
},
}), state = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEventValues = useComponentEvent(props).triggerEventValues;
useHandleCustomEvent('onChange', function (item) {
var multiple = props.multiple, options = props.options;
var value = item.value;
import { Component, triggerEventValues, getValueFromProps, } from '../_util/simply';
import { ChecklistDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(ChecklistDefaultProps, {
onChange: function (item) {
var _a = getValueFromProps(this, [
'multiple',
'options',
]), multiple = _a[0], options = _a[1];
var value;
value = item.detail.value;
if (multiple) {
var currentValue_1 = state;
var currentValue_1 = this.getValue();
if (currentValue_1.indexOf(value) > -1) {

@@ -39,6 +30,6 @@ currentValue_1 = currentValue_1.filter(function (v) { return v !== value; });

}
if (!isControlled) {
update(currentValue_1);
if (!this.isControlled()) {
this.update(currentValue_1);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
currentValue_1,

@@ -49,6 +40,6 @@ options.filter(function (v) { return currentValue_1.indexOf(v.value) > -1; }),

else {
if (!isControlled) {
update(value);
if (!this.isControlled()) {
this.update(value);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
value,

@@ -58,9 +49,13 @@ options.find(function (v) { return v.value === value; }),

}
});
return {
mixin: {
value: state,
},
}, null, [
mixinValue({
transformValue: function (val) {
var value = val || [];
return {
needUpdate: true,
value: value,
};
},
};
};
mountComponent(Checkbox, ChecklistFunctionalProps);
}),
]);
export var ChecklistDefaultProps = {
multiple: false,
options: [],
};
export var ChecklistFunctionalProps = {
value: null,
defaultValue: null,
options: [],
multiple: false,
options: [],
};

@@ -0,1 +1,12 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -46,44 +57,47 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
import { useRef, useState } from 'functional-mini/compat';
import { useEffect, useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useInstanceBoundingClientRect } from '../_util/hooks/useInstanceBoundingClientRect';
import { useComponentUpdateEffect } from '../_util/hooks/useLayoutEffect';
import { useMixState } from '../_util/hooks/useMixState';
import { CollapseFunctionalProps } from './props';
import { useEvent as useStableCallback } from '../_util/hooks/useEvent';
var Collapse = function (props) {
var _a = useState([]), contentHeight = _a[0], setContentHeight = _a[1];
var _b = useState(false), hasChange = _b[0], setHasChange = _b[1];
var taskQueueRef = useRef();
var previousValueRef = useRef([]);
var _c = useMixState(props.defaultCurrent, {
value: props.current,
postState: function (val) {
var current = __spreadArray([], (val || []), true);
var items = props.items;
current = current.filter(function (item) {
if (!items[item] || items[item].disabled) {
return false;
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { CollapseDefaultProps } from './props';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
import createValue from '../mixins/value';
Component(CollapseDefaultProps, {
getInstance: function () {
if (this.$id) {
return my;
}
return this;
},
getBoundingClientRectWithBuilder: function (builder) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, getInstanceBoundingClientRect(this.getInstance(), builder(this.$id ? "-".concat(this.$id) : ''))];
case 1: return [2 /*return*/, _a.sent()];
}
return true;
});
if (props.accordion) {
current = current.length > 0 ? [current[0]] : [];
});
},
formatCurrent: function (val, props) {
var current = __spreadArray([], (val || []), true);
var items = props.items;
current = current.filter(function (item) {
if (!items[item] || items[item].disabled) {
return false;
}
return {
valid: true,
value: __spreadArray([], current, true),
};
},
}), value = _c[0], _d = _c[1], isControlled = _d.isControlled, update = _d.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
return true;
});
if (props.accordion) {
current = current.length > 0 ? [current[0]] : [];
}
return __spreadArray([], current, true);
},
onChange: function (e) {
var itemIndex = parseInt(e.currentTarget.dataset.index, 10);
if (props.items[itemIndex] && props.items[itemIndex].disabled) {
var _a = getValueFromProps(this, [
'items',
'accordion',
]), items = _a[0], accordion = _a[1];
if (items[itemIndex] && items[itemIndex].disabled) {
return;
}
var arr = value;
var arr = this.getValue();
var current = __spreadArray([], arr, true);

@@ -95,3 +109,3 @@ var index = current.indexOf(itemIndex);

else {
if (props.accordion) {
if (accordion) {
current = [itemIndex];

@@ -104,78 +118,111 @@ }

}
if (!isControlled) {
update(current);
if (!this.isControlled()) {
this.update(current);
}
triggerEvent('change', current);
});
var getBoundingClientRectWithBuilder = useInstanceBoundingClientRect().getBoundingClientRectWithBuilder;
var updateContentHeight = useStableCallback(function (prevCurrent, nextCurrent) { return __awaiter(void 0, void 0, void 0, function () {
var prevCurrentArray, nextCurrentArray, expandArray, closeArray, newContentHeight;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
prevCurrentArray = prevCurrent;
nextCurrentArray = nextCurrent;
expandArray = [];
closeArray = [];
nextCurrentArray.forEach(function (item) {
if (prevCurrentArray.indexOf(item) < 0) {
expandArray.push(item);
triggerEvent(this, 'change', current, e);
},
updateContentHeight: function (prevCurrent, nextCurrent) {
return __awaiter(this, void 0, void 0, function () {
var prevCurrentArray, nextCurrentArray, expandArray, closeArray, items, contentHeight;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
prevCurrentArray = prevCurrent;
nextCurrentArray = nextCurrent;
expandArray = [];
closeArray = [];
nextCurrentArray.forEach(function (item) {
if (prevCurrentArray.indexOf(item) < 0) {
expandArray.push(item);
}
});
prevCurrentArray.forEach(function (item) {
if (nextCurrentArray.indexOf(item) < 0) {
closeArray.push(item);
}
});
items = getValueFromProps(this, 'items');
return [4 /*yield*/, Promise.all(items.map(function (item, index) { return __awaiter(_this, void 0, void 0, function () {
var height;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(expandArray.indexOf(index) >= 0 ||
closeArray.indexOf(index) >= 0)) return [3 /*break*/, 2];
return [4 /*yield*/, this.getBoundingClientRectWithBuilder(function (id) { return ".ant-collapse-item-content".concat(id, "-").concat(index); })];
case 1:
height = (_a.sent()).height;
return [2 /*return*/, "".concat(height, "px")];
case 2: return [2 /*return*/, this.data.contentHeight[index]];
}
});
}); }))];
case 1:
contentHeight = _a.sent();
if (closeArray.length === 0) {
this.setData({
contentHeight: contentHeight,
});
}
});
prevCurrentArray.forEach(function (item) {
if (nextCurrentArray.indexOf(item) < 0) {
closeArray.push(item);
}
});
return [4 /*yield*/, Promise.all(props.items.map(function (item, index) { return __awaiter(void 0, void 0, void 0, function () {
var height;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(expandArray.indexOf(index) >= 0 ||
closeArray.indexOf(index) >= 0)) return [3 /*break*/, 2];
return [4 /*yield*/, getBoundingClientRectWithBuilder(function (id) { return ".ant-collapse-item-content".concat(id, "-").concat(index); })];
case 1:
height = (_a.sent()).height;
return [2 /*return*/, "".concat(height, "px")];
case 2: return [2 /*return*/, contentHeight[index]];
}
else {
this.setData({
contentHeight: contentHeight,
});
}); }))];
case 1:
newContentHeight = _a.sent();
if (closeArray.length === 0) {
setContentHeight(newContentHeight);
}
else {
setContentHeight(newContentHeight);
taskQueueRef.current = function () {
setTimeout(function () {
setContentHeight(function (contentHeight) {
return contentHeight.map(function (item, index) {
if (closeArray.indexOf(index) >= 0) {
return '0px';
}
return item;
});
contentHeight = contentHeight.map(function (item, index) {
if (closeArray.indexOf(index) >= 0) {
return '0px';
}
return item;
});
_this.setData({
contentHeight: contentHeight,
});
}, 10);
};
}
return [2 /*return*/];
}
}
return [2 /*return*/];
}
});
});
}); });
useEffect(function () {
if (taskQueueRef.current) {
var task = taskQueueRef.current;
taskQueueRef.current = null;
if (typeof task === 'function') {
task();
},
resetContentHeight: function (e) {
var index = parseInt(e.currentTarget.dataset.index, 10);
if (this.getValue().indexOf(index) < 0) {
return;
}
var contentHeight = __spreadArray([], this.data.contentHeight, true);
contentHeight[index] = '';
this.setData({
contentHeight: contentHeight,
});
},
}, {
contentHeight: [],
hasChange: false,
}, [
createValue({
valueKey: 'current',
defaultValueKey: 'defaultCurrent',
transformValue: function (current, extra) {
var value = this.formatCurrent(current, extra ? extra.nextProps : getValueFromProps(this));
return {
needUpdate: true,
value: value,
};
},
}),
], {
observers: {
'**': function (data) {
var prevData = this._prevData || this.data;
this._prevData = __assign({}, data);
if (prevData.items !== data.items || !this.isEqualValue(prevData)) {
this.updateContentHeight(this.getValue(prevData), this.getValue());
}
}
});
useEffect(function () {
var current = value;
var contentHeight = props.items.map(function (item, index) {
},
},
attached: function () {
var current = this.getValue();
var contentHeight = this.properties.items.map(function (item, index) {
if (current.indexOf(index) >= 0) {

@@ -186,30 +233,8 @@ return '';

});
setContentHeight(contentHeight);
setHasChange(true);
previousValueRef.current = value;
}, []);
useComponentUpdateEffect(function () {
var previous = previousValueRef.current;
previousValueRef.current = value;
updateContentHeight(previous, value);
}, [props.items, JSON.stringify(value)]);
useEvent('resetContentHeight', function (e) {
var index = parseInt(e.currentTarget.dataset.index, 10);
if (value.indexOf(index) < 0) {
return;
}
setContentHeight(function (oldContentHeight) {
var newContentHeight = __spreadArray([], oldContentHeight, true);
newContentHeight[index] = '';
return newContentHeight;
this.setData({
hasChange: true,
contentHeight: contentHeight,
});
});
return {
contentHeight: contentHeight,
hasChange: hasChange,
mixin: {
value: value,
},
};
};
mountComponent(Collapse, CollapseFunctionalProps);
this._prevData = this.data;
},
});

@@ -1,3 +0,2 @@

export var CollapseDefaultProps = {};
export var CollapseFunctionalProps = {
export var CollapseDefaultProps = {
current: null,

@@ -4,0 +3,0 @@ defaultCurrent: [],

@@ -24,5 +24,5 @@ var __assign = (this && this.__assign) || function () {

import { FormItemFunctionalProps } from '../FormItem/props';
import { CheckboxGroupFunctionalProps, } from '../../Checkbox/CheckboxGroup/props';
import { CheckboxGroupDefaultProps, } from '../../Checkbox/CheckboxGroup/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var position = CheckboxGroupFunctionalProps.position, rest = __rest(CheckboxGroupFunctionalProps, ["position"]);
var position = CheckboxGroupDefaultProps.position, rest = __rest(CheckboxGroupDefaultProps, ["position"]);
export var FormCheckboxGroupDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { checkboxPosition: 'horizontal' });

@@ -24,5 +24,5 @@ var __assign = (this && this.__assign) || function () {

import { FormItemFunctionalProps } from '../FormItem/props';
import { UploaderFunctionalProps, } from '../../ImageUpload/props';
import { UploaderDefaultProps, } from '../../ImageUpload/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var defaultFileList = UploaderFunctionalProps.defaultFileList, rest = __rest(UploaderFunctionalProps, ["defaultFileList"]);
var defaultFileList = UploaderDefaultProps.defaultFileList, rest = __rest(UploaderDefaultProps, ["defaultFileList"]);
export var FormImageUploadDefaultProps = __assign(__assign({}, FormItemFunctionalProps), rest);

@@ -24,5 +24,5 @@ var __assign = (this && this.__assign) || function () {

import { FormItemFunctionalProps } from '../FormItem/props';
import { RadioGroupFunctionalProps, } from '../../Radio/RadioGroup/props';
import { RadioGroupDefaultProps, } from '../../Radio/RadioGroup/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var value = RadioGroupFunctionalProps.value, defaultValue = RadioGroupFunctionalProps.defaultValue, position = RadioGroupFunctionalProps.position, name = RadioGroupFunctionalProps.name, rest = __rest(RadioGroupFunctionalProps, ["value", "defaultValue", "position", "name"]);
var value = RadioGroupDefaultProps.value, defaultValue = RadioGroupDefaultProps.defaultValue, position = RadioGroupDefaultProps.position, name = RadioGroupDefaultProps.name, rest = __rest(RadioGroupDefaultProps, ["value", "defaultValue", "position", "name"]);
export var FormRadioGroupDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { radioPosition: 'horizontal' });

@@ -24,5 +24,5 @@ var __assign = (this && this.__assign) || function () {

import { FormItemFunctionalProps } from '../FormItem/props';
import { RateFunctionalProps } from '../../Rate/props';
import { RateDefaultProps } from '../../Rate/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var defaultValue = RateFunctionalProps.defaultValue, rest = __rest(RateFunctionalProps, ["defaultValue"]);
var defaultValue = RateDefaultProps.defaultValue, rest = __rest(RateDefaultProps, ["defaultValue"]);
export var FormRateDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { rateClassName: '', rateStyle: '' });

@@ -13,3 +13,3 @@ var __assign = (this && this.__assign) || function () {

import { FormItemFunctionalProps } from '../FormItem/props';
import { SelectorFunctionalProps } from '../../Selector/props';
export var FormSelectorDefaultProps = __assign(__assign({}, FormItemFunctionalProps), SelectorFunctionalProps);
import { SelectorDefaultProps } from '../../Selector/props';
export var FormSelectorDefaultProps = __assign(__assign({}, FormItemFunctionalProps), SelectorDefaultProps);

@@ -24,5 +24,5 @@ var __assign = (this && this.__assign) || function () {

import { FormItemFunctionalProps } from '../FormItem/props';
import { SwitchFunctionalProps } from '../../Switch/props';
import { SwitchDefaultProps } from '../../Switch/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var checked = SwitchFunctionalProps.checked, defaultChecked = SwitchFunctionalProps.defaultChecked, rest = __rest(SwitchFunctionalProps, ["checked", "defaultChecked"]);
var checked = SwitchDefaultProps.checked, defaultChecked = SwitchDefaultProps.defaultChecked, rest = __rest(SwitchDefaultProps, ["checked", "defaultChecked"]);
export var FormSwitchDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { switchClassName: '', switchStyle: '' });

@@ -24,3 +24,3 @@ ---

<Icon />
<Icon></Icon>

@@ -27,0 +27,0 @@ ## 代码示例

@@ -57,73 +57,109 @@ var __assign = (this && this.__assign) || function () {

};
import { useEvent, useRef } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { triggerRefEvent } from '../_util/hooks/useReportRef';
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { UploaderDefaultProps } from './props';
import { chooseImage } from '../_util/jsapi/choose-image';
import { UploaderFunctionalProps, } from './props';
import { useId } from 'functional-mini/compat';
/**
* 获取一个内部使用的 uid
* 每次获取时自增
*/
var useCounter = function () {
var counterRef = useRef(0);
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
var prefix = useId() + '-' + Date.now();
return {
getCount: function () {
counterRef.current = counterRef.current + 1;
return "".concat(prefix, "-").concat(counterRef.current);
},
};
};
var ImageUpload = function (props) {
var getCount = useCounter().getCount;
var _a = useMixState(props.defaultFileList, {
value: props.fileList,
postState: function (fileList) {
return {
valid: true,
value: (fileList || []).map(function (item) {
var file = __assign({}, item);
if (typeof item.url === 'undefined') {
file.url = '';
}
if (typeof item.uid === 'undefined') {
file.uid = getCount();
}
if (typeof item.status === 'undefined') {
file.status = 'done';
}
return file;
}),
};
},
}), fileList = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update, triggerUpdater = _b.triggerUpdater;
triggerRefEvent();
var triggerEvent = useComponentEvent(props).triggerEvent;
function uploadFile(localFile) {
import createValue from '../mixins/value';
Component(UploaderDefaultProps, {
chooseImage: function () {
return __awaiter(this, void 0, void 0, function () {
var onUpload, uid, url, err_1;
var _a, onBeforeUpload, onUpload, fileList, _b, maxCount, sourceType, localFileList, chooseImageRes, err_1, beforeUploadRes, err_2, tasks;
var _this = this;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = getValueFromProps(this, [
'onBeforeUpload',
'onUpload',
]), onBeforeUpload = _a[0], onUpload = _a[1];
if (!onUpload) {
throw new Error('need props onUpload');
}
fileList = this.getValue();
_b = getValueFromProps(this, [
'maxCount',
'sourceType',
]), maxCount = _b[0], sourceType = _b[1];
_c.label = 1;
case 1:
_c.trys.push([1, 3, , 4]);
return [4 /*yield*/, chooseImage({
count: typeof maxCount === 'undefined'
? Infinity
: maxCount - fileList.length,
sourceType: sourceType,
})];
case 2:
chooseImageRes = _c.sent();
localFileList = (chooseImageRes.tempFiles ||
chooseImageRes.tempFilePaths ||
chooseImageRes.apFilePaths ||
chooseImageRes.filePaths ||
[])
.map(function (item) {
if (typeof item === 'string') {
return {
path: item,
};
}
if (item.path) {
return {
path: item.path,
size: item.size,
};
}
})
.filter(function (item) { return !!item; });
return [3 /*break*/, 4];
case 3:
err_1 = _c.sent();
triggerEvent(this, 'chooseImageError', err_1);
return [2 /*return*/];
case 4:
if (!onBeforeUpload) return [3 /*break*/, 8];
_c.label = 5;
case 5:
_c.trys.push([5, 7, , 8]);
return [4 /*yield*/, onBeforeUpload(localFileList)];
case 6:
beforeUploadRes = _c.sent();
if (beforeUploadRes === false) {
return [2 /*return*/];
}
if (Array.isArray(beforeUploadRes)) {
localFileList = beforeUploadRes;
}
return [3 /*break*/, 8];
case 7:
err_2 = _c.sent();
return [2 /*return*/];
case 8:
tasks = localFileList.map(function (file) { return _this.uploadFile(file); });
return [4 /*yield*/, Promise.all(tasks)];
case 9:
_c.sent();
return [2 /*return*/];
}
});
});
},
uploadFile: function (localFile) {
return __awaiter(this, void 0, void 0, function () {
var onUpload, uid, tempFileList, url, err_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
onUpload = props.onUpload;
uid = getCount();
triggerUpdater(function (oldFiles) {
var tempFileList = __spreadArray(__spreadArray([], oldFiles, true), [
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-expect-error
path: localFile.path,
size: localFile.size,
uid: uid,
status: 'uploading',
},
], false);
triggerEvent('change', tempFileList);
return tempFileList;
});
onUpload = getValueFromProps(this, 'onUpload');
uid = this.getCount();
tempFileList = __spreadArray(__spreadArray([], this.getValue(), true), [
{
path: localFile.path,
size: localFile.size,
uid: uid,
status: 'uploading',
},
], false);
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
_a.label = 1;

@@ -136,3 +172,3 @@ case 1:

if (typeof url !== 'string' || !url) {
updateFile(uid, {
this.updateFile(uid, {
status: 'error',

@@ -142,3 +178,3 @@ });

}
updateFile(uid, {
this.updateFile(uid, {
status: 'done',

@@ -149,4 +185,4 @@ url: url,

case 3:
err_1 = _a.sent();
updateFile(uid, {
err_3 = _a.sent();
this.updateFile(uid, {
status: 'error',

@@ -159,133 +195,106 @@ });

});
}
function updateFile(uid, file) {
},
updateFile: function (uid, file) {
var fileList = this.getValue();
var tempFileList = fileList.map(function (item) {
if (item.uid === uid) {
return __assign(__assign({}, item), file);
}
return item;
});
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
},
onRemove: function (e) {
return __awaiter(this, void 0, void 0, function () {
var fileList, onRemove, uid, file, result, tempFileList;
return __generator(this, function (_a) {
triggerUpdater(function (old) {
var tempFileList = old.map(function (item) {
if (item.uid === uid) {
return __assign(__assign({}, item), file);
switch (_a.label) {
case 0:
fileList = this.getValue();
onRemove = getValueFromProps(this, 'onRemove');
uid = e.currentTarget.dataset.uid;
file = fileList.find(function (item) { return item.uid === uid; });
if (!onRemove) return [3 /*break*/, 2];
return [4 /*yield*/, onRemove(file)];
case 1:
result = _a.sent();
if (result === false) {
return [2 /*return*/];
}
return item;
});
triggerEvent('change', tempFileList);
return tempFileList;
});
return [2 /*return*/];
_a.label = 2;
case 2:
tempFileList = fileList.filter(function (item) { return item.uid !== uid; });
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
return [2 /*return*/];
}
});
});
}
useEvent('chooseImage', function () { return __awaiter(void 0, void 0, void 0, function () {
var onBeforeUpload, onUpload, maxCount, sourceType, localFileList, chooseImageRes, err_2, beforeUploadRes, err_3, tasks;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
onBeforeUpload = props.onBeforeUpload, onUpload = props.onUpload, maxCount = props.maxCount, sourceType = props.sourceType;
if (!onUpload || typeof onUpload !== 'function') {
throw new Error('need props onUpload');
},
onPreview: function (e) {
var uid = e.currentTarget.dataset.uid;
var fileList = this.getValue();
var file = fileList.find(function (item) { return item.uid === uid; });
triggerEvent(this, 'preview', file);
},
updateShowUploadButton: function () {
var maxCount = getValueFromProps(this, 'maxCount');
this.setData({
showUploadButton: !maxCount || this.getValue().length < maxCount,
});
},
count: 0,
getCount: function () {
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
this.count = (this.count || 0) + 1;
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
var id = this.id;
var prefix = id + '-' + Date.now();
return "".concat(prefix, "-").concat(this.count);
},
}, null, [
createValue({
defaultValueKey: 'defaultFileList',
valueKey: 'fileList',
transformValue: function (fileList) {
var _this = this;
if (fileList === void 0) { fileList = []; }
return {
needUpdate: true,
value: fileList.map(function (item) {
var file = __assign({}, item);
if (typeof item.url === 'undefined') {
file.url = '';
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, chooseImage({
count: typeof maxCount === 'undefined'
? Infinity
: maxCount - fileList.length,
sourceType: sourceType,
})];
case 2:
chooseImageRes = _a.sent();
localFileList = (chooseImageRes.tempFiles ||
chooseImageRes.tempFilePaths ||
chooseImageRes.apFilePaths ||
chooseImageRes.filePaths ||
[])
.map(function (item) {
if (typeof item === 'string') {
return {
path: item,
};
}
if (item.path) {
return {
path: item.path,
size: item.size,
};
}
})
.filter(function (item) { return !!item; });
return [3 /*break*/, 4];
case 3:
err_2 = _a.sent();
triggerEvent('chooseImageError', err_2);
return [2 /*return*/];
case 4:
if (!(onBeforeUpload && typeof onBeforeUpload === 'function')) return [3 /*break*/, 8];
_a.label = 5;
case 5:
_a.trys.push([5, 7, , 8]);
return [4 /*yield*/, onBeforeUpload(localFileList)];
case 6:
beforeUploadRes = _a.sent();
if (beforeUploadRes === false) {
return [2 /*return*/];
if (typeof item.uid === 'undefined') {
file.uid = _this.getCount();
}
if (Array.isArray(beforeUploadRes)) {
localFileList = beforeUploadRes;
if (typeof item.status === 'undefined') {
file.status = 'done';
}
return [3 /*break*/, 8];
case 7:
err_3 = _a.sent();
return [2 /*return*/];
case 8:
tasks = localFileList.map(function (file) { return uploadFile(file); });
return [4 /*yield*/, Promise.all(tasks)];
case 9:
_a.sent();
return [2 /*return*/];
return file;
}),
};
},
}),
], {
attached: function () {
this.triggerEvent('ref', this);
this.updateShowUploadButton();
this._prevData = this.data;
},
observers: {
'**': function (data) {
var prevData = this._prevData || this.data;
this._prevData = __assign({}, data);
if (!this.isEqualValue(prevData)) {
this.updateShowUploadButton();
}
});
}); });
useEvent('onRemove', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var uid, file, result, tempFileList;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
uid = e.currentTarget.dataset.uid;
file = fileList.find(function (item) { return item.uid === uid; });
if (!(props.onRemove && typeof props.onRemove === 'function')) return [3 /*break*/, 2];
return [4 /*yield*/, props.onRemove(file)];
case 1:
result = _a.sent();
if (result === false) {
return [2 /*return*/];
}
_a.label = 2;
case 2:
tempFileList = fileList.filter(function (item) { return item.uid !== uid; });
if (!isControlled) {
update(tempFileList);
}
triggerEvent('change', tempFileList);
return [2 /*return*/];
}
});
}); });
useEvent('onPreview', function (e) {
var uid = e.currentTarget.dataset.uid;
var file = fileList.find(function (item) { return item.uid === uid; });
triggerEvent('preview', file);
});
useEvent('update', function (e) {
if (isControlled) {
return;
}
update(e);
});
return {
mixin: {
value: fileList,
},
};
};
mountComponent(ImageUpload, UploaderFunctionalProps);
},
});
export var UploaderDefaultProps = {
defaultFileList: [],
imageMode: 'scaleToFill',
sourceType: ['camera', 'album'],
};
export var UploaderFunctionalProps = {
defaultFileList: [],
fileList: null,

@@ -16,3 +11,3 @@ maxCount: null,

uploadingText: '上传中',
uploadfailedText: '上传失败'
uploadfailedText: '上传失败',
};

@@ -135,3 +135,3 @@ function getColumnValue(columnItem) {

var selectedIndex = [];
var value = realValue;
var value = realValue || [];
if (sinefileRef.current) {

@@ -138,0 +138,0 @@ value = [realValue];

@@ -1,33 +0,20 @@

import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
var Radio = function (props) {
var _a = useMixState(props.defaultChecked, {
value: props.checked,
}), radioValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('handleTap', function (e) {
import { Component, triggerEvent } from '../_util/simply';
import { RadioDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(RadioDefaultProps, {
handleTap: function (e) {
// 只能从 false -> true
if (radioValue) {
if (this.getValue()) {
return;
}
if (!isControlled) {
update(true);
if (!this.isControlled()) {
this.update(true);
}
triggerEvent('change', true, e);
});
return {
mixin: {
value: radioValue,
},
};
};
mountComponent(Radio, {
value: null,
defaultChecked: null,
color: '',
checked: null,
disabled: false,
});
triggerEvent(this, 'change', true, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

@@ -1,1 +0,7 @@

export var RadioDefaultProps = {};
export var RadioDefaultProps = {
value: null,
defaultChecked: null,
color: '',
checked: null,
disabled: false,
};

@@ -1,25 +0,16 @@

import { RadioGroupFunctionalProps } from './props';
import { mountComponent } from '../../_util/component';
import { useMixState } from '../../_util/hooks/useMixState';
import { useEvent } from 'functional-mini/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
var RadioGroup = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
var index = e.currentTarget.dataset.index;
var value = props.options[index].value;
if (!isControlled) {
update(value);
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { RadioGroupDefaultProps } from './props';
import mixinValue from '../../mixins/value';
Component(RadioGroupDefaultProps, {
onChange: function (_, e) {
var event;
event = _;
var index = event.currentTarget.dataset.index;
var options = getValueFromProps(this, 'options');
var value = options[index].value;
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', value, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(RadioGroup, RadioGroupFunctionalProps);
triggerEvent(this, 'change', value, event);
},
}, null, [mixinValue()]);
export var RadioGroupDefaultProps = {
options: [],
position: 'vertical',
};
export var RadioGroupFunctionalProps = {
value: null,

@@ -7,0 +3,0 @@ defaultValue: null,

@@ -48,45 +48,27 @@ var __assign = (this && this.__assign) || function () {

};
import { useComponent, useEvent, useRef, useState, } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { RateDefaultProps } from './props';
import createValue from '../mixins/value';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
import { RateFunctionalProps } from './props';
var Rate = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (value) {
if (props.allowHalf) {
return {
valid: true,
value: value % 0.5 !== 0 ? Math.round(value) : value,
};
}
return {
valid: true,
value: Math.ceil(value),
};
},
}), rateValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
var _c = useState(null), displayValue = _c[0], setDisplayValue = _c[1];
var ref = useRef(null);
var instance = useComponent();
function getInstance() {
if (instance.$id) {
Component(RateDefaultProps, {
getInstance: function () {
if (this.$id) {
return my;
}
return instance;
}
function getRate(clientX) {
return this;
},
getRate: function (clientX) {
return __awaiter(this, void 0, void 0, function () {
var gutter, count, _a, left, width, halfRateWidth, num, halfRateCount, val, rate;
return __generator(this, function (_b) {
switch (_b.label) {
var _a, gutter, count, allowHalf, _b, left, width, halfRateWidth, num, halfRateCount, val, rate;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
gutter = props.gutter, count = props.count;
return [4 /*yield*/, getInstanceBoundingClientRect(getInstance(), "#ant-rate-container".concat(instance.$id ? "-".concat(instance.$id) : ''))];
_a = getValueFromProps(this, [
'gutter',
'count',
'allowHalf',
]), gutter = _a[0], count = _a[1], allowHalf = _a[2];
return [4 /*yield*/, getInstanceBoundingClientRect(this.getInstance(), "#ant-rate-container".concat(this.$id ? "-".concat(this.$id) : ''))];
case 1:
_a = _b.sent(), left = _a.left, width = _a.width;
_b = _c.sent(), left = _b.left, width = _b.width;
halfRateWidth = (width - (count - 1) * gutter) / count / 2;

@@ -97,3 +79,4 @@ num = clientX - left;

while (true) {
val = halfRateWidth * halfRateCount + gutter * Math.floor(halfRateCount / 2);
val = halfRateWidth * halfRateCount +
gutter * Math.floor(halfRateCount / 2);
if (halfRateCount >= count * 2 || num <= val) {

@@ -104,3 +87,3 @@ break;

}
rate = props.allowHalf
rate = allowHalf
? halfRateCount * 0.5

@@ -112,86 +95,103 @@ : Math.ceil(halfRateCount * 0.5);

});
}
useEvent('handleStarTap', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var _a, clientX, x, clickX, rate;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (props.readonly) {
},
handleStarTap: function (e) {
return __awaiter(this, void 0, void 0, function () {
var _a, readonly, allowClear, _b, clientX, x, clickX, rateValue, rate;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = getValueFromProps(this, [
'readonly',
'allowClear',
]), readonly = _a[0], allowClear = _a[1];
if (readonly) {
return [2 /*return*/];
}
_b = e.detail, clientX = _b.clientX, x = _b.x;
clickX = typeof x === 'number' ? x : clientX;
rateValue = this.getValue();
return [4 /*yield*/, this.getRate(clickX)];
case 1:
rate = _c.sent();
if (rateValue === rate && allowClear) {
rate = 0;
}
if (!this.isControlled()) {
this.update(rate);
}
if (rateValue !== rate) {
triggerEvent(this, 'change', rate);
}
return [2 /*return*/];
}
_a = e.detail, clientX = _a.clientX, x = _a.x;
clickX = typeof x === 'number' ? x : clientX;
return [4 /*yield*/, getRate(clickX)];
case 1:
rate = _b.sent();
if (rateValue === rate && props.allowClear) {
rate = 0;
}
if (!isControlled) {
update(rate);
}
if (rateValue !== rate) {
triggerEvent('change', rate);
}
return [2 /*return*/];
}
}
});
});
}); });
useEvent('handleStarMove', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var touches, clientX, rate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (props.readonly) {
return [2 /*return*/];
}
touches = e.touches;
clientX = touches[0].clientX;
if (!ref.current) {
ref.current = {
originalRate: rateValue,
};
}
return [4 /*yield*/, getRate(clientX)];
case 1:
rate = _a.sent();
if (ref.current) {
ref.current = __assign(__assign({}, ref.current), { currentRate: rate });
if (isControlled) {
setDisplayValue(rate);
},
handleStarMove: function (e) {
return __awaiter(this, void 0, void 0, function () {
var readonly, touches, clientX, rate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
readonly = getValueFromProps(this, ['readonly'])[0];
if (readonly) {
return [2 /*return*/];
}
else {
update(rate);
touches = e.touches;
clientX = touches[0].clientX;
if (!this.moveRate) {
this.moveRate = {
originalRate: this.getValue(),
};
}
}
return [2 /*return*/];
}
return [4 /*yield*/, this.getRate(clientX)];
case 1:
rate = _a.sent();
if (this.moveRate) {
this.moveRate = __assign(__assign({}, this.moveRate), { currentRate: rate });
if (this.isControlled()) {
this.setData({ displayValue: rate });
}
else {
this.update(rate);
}
}
return [2 /*return*/];
}
});
});
}); });
useEvent('handleStarMoveEnd', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, currentRate, originalRate;
return __generator(this, function (_b) {
if (props.readonly) {
return [2 /*return*/];
},
handleStarMoveEnd: function () {
var readonly = getValueFromProps(this, 'readonly');
if (readonly) {
return;
}
if (!this.moveRate) {
return;
}
var _a = this.moveRate, currentRate = _a.currentRate, originalRate = _a.originalRate;
this.moveRate = null;
if (this.isControlled()) {
this.setData({ displayValue: null });
}
if (currentRate !== originalRate) {
triggerEvent(this, 'change', currentRate);
}
},
}, { displayValue: null }, [
createValue({
transformValue: function (value) {
var allowHalf = getValueFromProps(this, 'allowHalf');
if (allowHalf) {
return {
needUpdate: true,
value: value % 0.5 !== 0 ? Math.round(value) : value,
};
}
if (!ref.current) {
return [2 /*return*/];
}
_a = ref.current, currentRate = _a.currentRate, originalRate = _a.originalRate;
ref.current = null;
if (isControlled) {
setDisplayValue(null);
}
if (currentRate !== originalRate) {
triggerEvent('change', currentRate);
}
return [2 /*return*/];
});
}); });
return {
mixin: {
value: displayValue !== null ? displayValue : rateValue,
return {
needUpdate: true,
value: Math.ceil(value),
};
},
};
};
mountComponent(Rate, RateFunctionalProps);
}),
]);
export var RateDefaultProps = {
count: 5,
gutter: 4,
allowClear: true,
};
export var RateFunctionalProps = {
value: null,

@@ -8,0 +3,0 @@ defaultValue: null,

@@ -10,25 +10,24 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

};
import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { SelectorFunctionalProps } from './props';
var Selector = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
}), selectorValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEventValues = useComponentEvent(props).triggerEventValues;
useEvent('onChange', function (e) {
import { Component, triggerEventValues, getValueFromProps, } from '../_util/simply';
import { SelectorDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(SelectorDefaultProps, {
onChange: function (e) {
var _a = e.currentTarget.dataset, disabled = _a.disabled, value = _a.value;
var multiple = props.multiple, options = props.options, maxSelectedCount = props.maxSelectedCount, minSelectedCount = props.minSelectedCount;
if (disabled || props.disabled) {
var _b = getValueFromProps(this, [
'multiple',
'options',
'maxSelectedCount',
'minSelectedCount',
'disabled',
]), multiple = _b[0], options = _b[1], maxSelectedCount = _b[2], minSelectedCount = _b[3], disabledFromProps = _b[4];
if (disabled || disabledFromProps) {
return;
}
if (multiple) {
var currentValue_1 = selectorValue || [];
var currentValue_1 = this.getValue() || [];
if (currentValue_1.indexOf(value) > -1) {
if (typeof minSelectedCount === 'number' &&
currentValue_1.length <= minSelectedCount) {
triggerEventValues('selectMin', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMin', [value, options.find(function (v) { return v.value === value; })], e);
return;

@@ -41,3 +40,3 @@ }

currentValue_1.length >= maxSelectedCount) {
triggerEventValues('selectMax', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMax', [value, options.find(function (v) { return v.value === value; })], e);
return;

@@ -47,6 +46,6 @@ }

}
if (!isControlled) {
update(currentValue_1);
if (!this.isControlled()) {
this.update(currentValue_1);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
currentValue_1,

@@ -57,26 +56,20 @@ options.filter(function (v) { return currentValue_1.indexOf(v.value) > -1; }),

else {
if (value === selectorValue) {
if (value === this.getValue()) {
if (minSelectedCount === 1) {
triggerEventValues('selectMin', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMin', [value, options.find(function (v) { return v.value === value; })], e);
return;
}
if (!isControlled) {
update(undefined);
if (!this.isControlled()) {
this.update(undefined);
}
triggerEventValues('change', [undefined, undefined], e);
triggerEventValues(this, 'change', [undefined, undefined], e);
}
else {
if (!isControlled) {
update(value);
if (!this.isControlled()) {
this.update(value);
}
triggerEventValues('change', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'change', [value, options.find(function (v) { return v.value === value; })], e);
}
}
});
return {
mixin: {
value: selectorValue,
},
};
};
mountComponent(Selector, SelectorFunctionalProps);
},
}, null, [mixinValue()]);
export var SelectorDefaultProps = {
multiple: false,
disabled: false,
};
export var SelectorFunctionalProps = {
value: null,

@@ -7,0 +3,0 @@ defaultValue: null,

@@ -1,22 +0,17 @@

import { mountComponent } from '../_util/component';
import { useMergedState, hasValue } from '../_util/hooks/useMergedState';
import { SwitchFunctionalProps } from './props';
import { useEvent } from 'functional-mini/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
var Switch = function (props) {
var _a = useMergedState(props.defaultChecked, {
value: props.checked,
}), value = _a[0], updateValue = _a[1];
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
var newValue = !value;
if (!hasValue(props.checked)) {
updateValue(newValue);
import { Component, triggerEvent } from '../_util/simply';
import { SwitchDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(SwitchDefaultProps, {
onChange: function (e) {
var value = !this.getValue();
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', newValue, e);
});
return {
mixin: { value: value },
};
};
mountComponent(Switch, SwitchFunctionalProps);
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);
export var SwitchDefaultProps = {
size: 'medium',
};
export var SwitchFunctionalProps = {
checked: null,

@@ -6,0 +3,0 @@ loading: false,

@@ -1,27 +0,20 @@

import { useEvent } from 'functional-mini/component';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { TabBarFunctionalProps } from './props';
var TabBar = function (props) {
var _a = useMixState(props.defaultCurrent, {
value: props.current,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
import { TabBarDefaultProps } from './props';
import { Component, triggerEvent } from '../_util/simply';
import mixinValue from '../mixins/value';
Component(TabBarDefaultProps, {
onChange: function (e) {
var index = e.currentTarget.dataset.index;
if (index === value) {
if (index === this.getValue()) {
return;
}
if (!isControlled) {
update(index);
if (!this.isControlled()) {
this.update(index);
}
triggerEvent('change', index, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(TabBar, TabBarFunctionalProps);
triggerEvent(this, 'change', index, e);
},
}, null, [
mixinValue({
valueKey: 'current',
defaultValueKey: 'defaultCurrent',
}),
]);
export var TabBarDefaultProps = {
items: [],
defaultCurrent: 0,
};
export var TabBarFunctionalProps = {
items: [],
current: null,

@@ -8,0 +4,0 @@ defaultCurrent: 0,

import { __spreadArray } from "tslib";
import { useEvent } from 'functional-mini/component';
import { mountComponent } from '../../_util/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
import { useMixState } from '../../_util/hooks/useMixState';
import { CheckboxGroupFunctionalProps } from './props';
var CheckboxGroup = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (value) {
return {
valid: true,
value: value || [],
};
},
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (args, e) {
if (props.disabled) {
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { CheckboxGroupDefaultProps } from './props';
import mixinValue from '../../mixins/value';
Component(CheckboxGroupDefaultProps, {
onChange: function (args, e) {
if (getValueFromProps(this, 'disabled')) {
return;

@@ -24,5 +12,5 @@ }

event = e;
var currentValue = value;
var currentValue = this.getValue();
var index = event.currentTarget.dataset.index;
var selectValue = props.options[index].value;
var selectValue = getValueFromProps(this, 'options')[index].value;
if (currentValue.indexOf(selectValue) > -1) {

@@ -34,11 +22,17 @@ currentValue = currentValue.filter(function (v) { return v !== selectValue; });

}
if (!isControlled) {
update(currentValue);
if (!this.isControlled()) {
this.update(currentValue);
}
triggerEvent('change', currentValue, e);
});
return {
mixin: { value: value },
};
};
mountComponent(CheckboxGroup, CheckboxGroupFunctionalProps);
triggerEvent(this, 'change', currentValue, e);
},
}, null, [
mixinValue({
transformValue: function (val) {
var value = val || [];
return {
needUpdate: true,
value: value,
};
},
}),
]);

@@ -16,2 +16,1 @@ import { IBaseProps } from '../../_util/base';

export declare const CheckboxGroupDefaultProps: Partial<ICheckboxGroupProps>;
export declare const CheckboxGroupFunctionalProps: Partial<ICheckboxGroupProps>;
export var CheckboxGroupDefaultProps = {
options: [],
position: 'vertical',
defaultValue: [],
};
export var CheckboxGroupFunctionalProps = {
value: null,

@@ -8,0 +3,0 @@ defaultValue: [],

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};

@@ -1,30 +0,17 @@

import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
var Checkbox = function (props) {
var _a = useMixState(props.defaultChecked, {
value: props.checked,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
var newValue = !value;
if (!isControlled) {
update(newValue);
import { CheckboxDefaultProps } from './props';
import { Component, triggerEvent } from '../_util/simply';
import mixinValue from '../mixins/value';
Component(CheckboxDefaultProps, {
onChange: function (e) {
var value = !this.getValue();
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', newValue, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(Checkbox, {
value: null,
checked: null,
defaultChecked: null,
disabled: false,
color: '',
});
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

@@ -1,1 +0,7 @@

export var CheckboxDefaultProps = {};
export var CheckboxDefaultProps = {
value: null,
checked: null,
defaultChecked: null,
disabled: false,
color: '',
};

@@ -1,7 +0,7 @@

import { Component, triggerEvent } from '../../_util/simply';
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { ChecklistItemDefaultProps } from './props';
Component(ChecklistItemDefaultProps, {
onChecklistItemClick: function () {
triggerEvent(this, 'change', this.props.item);
}
triggerEvent(this, 'change', getValueFromProps(this, 'item'));
},
});
import { __spreadArray } from "tslib";
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useHandleCustomEvent } from '../_util/hooks/useHandleCustomEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { ChecklistFunctionalProps, } from './props';
var Checkbox = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (val) {
var value = val || [];
return {
valid: true,
value: value,
};
},
}), state = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEventValues = useComponentEvent(props).triggerEventValues;
useHandleCustomEvent('onChange', function (item) {
var multiple = props.multiple, options = props.options;
var value = item.value;
import { Component, triggerEventValues, getValueFromProps, } from '../_util/simply';
import { ChecklistDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(ChecklistDefaultProps, {
onChange: function (item) {
var _a = getValueFromProps(this, [
'multiple',
'options',
]), multiple = _a[0], options = _a[1];
var value;
value = item.value;
if (multiple) {
var currentValue_1 = state;
var currentValue_1 = this.getValue();
if (currentValue_1.indexOf(value) > -1) {

@@ -30,6 +21,6 @@ currentValue_1 = currentValue_1.filter(function (v) { return v !== value; });

}
if (!isControlled) {
update(currentValue_1);
if (!this.isControlled()) {
this.update(currentValue_1);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
currentValue_1,

@@ -40,6 +31,6 @@ options.filter(function (v) { return currentValue_1.indexOf(v.value) > -1; }),

else {
if (!isControlled) {
update(value);
if (!this.isControlled()) {
this.update(value);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
value,

@@ -49,9 +40,13 @@ options.find(function (v) { return v.value === value; }),

}
});
return {
mixin: {
value: state,
},
}, null, [
mixinValue({
transformValue: function (val) {
var value = val || [];
return {
needUpdate: true,
value: value,
};
},
};
};
mountComponent(Checkbox, ChecklistFunctionalProps);
}),
]);

@@ -49,2 +49,1 @@ import { IBaseProps } from '../_util/base';

export declare const ChecklistDefaultProps: Partial<IChecklistProps>;
export declare const ChecklistFunctionalProps: Partial<IChecklistProps>;
export var ChecklistDefaultProps = {
multiple: false,
options: [],
};
export var ChecklistFunctionalProps = {
value: null,
defaultValue: null,
options: [],
multiple: false,
options: [],
};

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};
import { __awaiter, __generator, __spreadArray } from "tslib";
import { useRef, useState } from 'functional-mini/compat';
import { useEffect, useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useInstanceBoundingClientRect } from '../_util/hooks/useInstanceBoundingClientRect';
import { useComponentUpdateEffect } from '../_util/hooks/useLayoutEffect';
import { useMixState } from '../_util/hooks/useMixState';
import { CollapseFunctionalProps } from './props';
import { useEvent as useStableCallback } from '../_util/hooks/useEvent';
var Collapse = function (props) {
var _a = useState([]), contentHeight = _a[0], setContentHeight = _a[1];
var _b = useState(false), hasChange = _b[0], setHasChange = _b[1];
var taskQueueRef = useRef();
var previousValueRef = useRef([]);
var _c = useMixState(props.defaultCurrent, {
value: props.current,
postState: function (val) {
var current = __spreadArray([], (val || []), true);
var items = props.items;
current = current.filter(function (item) {
if (!items[item] || items[item].disabled) {
return false;
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { CollapseDefaultProps } from './props';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
import createValue from '../mixins/value';
Component(CollapseDefaultProps, {
getInstance: function () {
if (this.$id) {
return my;
}
return this;
},
getBoundingClientRectWithBuilder: function (builder) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, getInstanceBoundingClientRect(this.getInstance(), builder(this.$id ? "-".concat(this.$id) : ''))];
case 1: return [2 /*return*/, _a.sent()];
}
return true;
});
if (props.accordion) {
current = current.length > 0 ? [current[0]] : [];
});
},
formatCurrent: function (val, props) {
var current = __spreadArray([], (val || []), true);
var items = props.items;
current = current.filter(function (item) {
if (!items[item] || items[item].disabled) {
return false;
}
return {
valid: true,
value: __spreadArray([], current, true),
};
},
}), value = _c[0], _d = _c[1], isControlled = _d.isControlled, update = _d.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
return true;
});
if (props.accordion) {
current = current.length > 0 ? [current[0]] : [];
}
return __spreadArray([], current, true);
},
onChange: function (e) {
var itemIndex = parseInt(e.currentTarget.dataset.index, 10);
if (props.items[itemIndex] && props.items[itemIndex].disabled) {
var _a = getValueFromProps(this, [
'items',
'accordion',
]), items = _a[0], accordion = _a[1];
if (items[itemIndex] && items[itemIndex].disabled) {
return;
}
var arr = value;
var arr = this.getValue();
var current = __spreadArray([], arr, true);

@@ -50,3 +53,3 @@ var index = current.indexOf(itemIndex);

else {
if (props.accordion) {
if (accordion) {
current = [itemIndex];

@@ -59,78 +62,109 @@ }

}
if (!isControlled) {
update(current);
if (!this.isControlled()) {
this.update(current);
}
triggerEvent('change', current);
});
var getBoundingClientRectWithBuilder = useInstanceBoundingClientRect().getBoundingClientRectWithBuilder;
var updateContentHeight = useStableCallback(function (prevCurrent, nextCurrent) { return __awaiter(void 0, void 0, void 0, function () {
var prevCurrentArray, nextCurrentArray, expandArray, closeArray, newContentHeight;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
prevCurrentArray = prevCurrent;
nextCurrentArray = nextCurrent;
expandArray = [];
closeArray = [];
nextCurrentArray.forEach(function (item) {
if (prevCurrentArray.indexOf(item) < 0) {
expandArray.push(item);
triggerEvent(this, 'change', current, e);
},
updateContentHeight: function (prevCurrent, nextCurrent) {
return __awaiter(this, void 0, void 0, function () {
var prevCurrentArray, nextCurrentArray, expandArray, closeArray, items, contentHeight;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
prevCurrentArray = prevCurrent;
nextCurrentArray = nextCurrent;
expandArray = [];
closeArray = [];
nextCurrentArray.forEach(function (item) {
if (prevCurrentArray.indexOf(item) < 0) {
expandArray.push(item);
}
});
prevCurrentArray.forEach(function (item) {
if (nextCurrentArray.indexOf(item) < 0) {
closeArray.push(item);
}
});
items = getValueFromProps(this, 'items');
return [4 /*yield*/, Promise.all(items.map(function (item, index) { return __awaiter(_this, void 0, void 0, function () {
var height;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(expandArray.indexOf(index) >= 0 ||
closeArray.indexOf(index) >= 0)) return [3 /*break*/, 2];
return [4 /*yield*/, this.getBoundingClientRectWithBuilder(function (id) { return ".ant-collapse-item-content".concat(id, "-").concat(index); })];
case 1:
height = (_a.sent()).height;
return [2 /*return*/, "".concat(height, "px")];
case 2: return [2 /*return*/, this.data.contentHeight[index]];
}
});
}); }))];
case 1:
contentHeight = _a.sent();
if (closeArray.length === 0) {
this.setData({
contentHeight: contentHeight,
});
}
});
prevCurrentArray.forEach(function (item) {
if (nextCurrentArray.indexOf(item) < 0) {
closeArray.push(item);
}
});
return [4 /*yield*/, Promise.all(props.items.map(function (item, index) { return __awaiter(void 0, void 0, void 0, function () {
var height;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(expandArray.indexOf(index) >= 0 ||
closeArray.indexOf(index) >= 0)) return [3 /*break*/, 2];
return [4 /*yield*/, getBoundingClientRectWithBuilder(function (id) { return ".ant-collapse-item-content".concat(id, "-").concat(index); })];
case 1:
height = (_a.sent()).height;
return [2 /*return*/, "".concat(height, "px")];
case 2: return [2 /*return*/, contentHeight[index]];
}
else {
this.setData({
contentHeight: contentHeight,
});
}); }))];
case 1:
newContentHeight = _a.sent();
if (closeArray.length === 0) {
setContentHeight(newContentHeight);
}
else {
setContentHeight(newContentHeight);
taskQueueRef.current = function () {
setTimeout(function () {
setContentHeight(function (contentHeight) {
return contentHeight.map(function (item, index) {
if (closeArray.indexOf(index) >= 0) {
return '0px';
}
return item;
});
contentHeight = contentHeight.map(function (item, index) {
if (closeArray.indexOf(index) >= 0) {
return '0px';
}
return item;
});
_this.setData({
contentHeight: contentHeight,
});
}, 10);
};
}
return [2 /*return*/];
}
}
return [2 /*return*/];
}
});
});
}); });
useEffect(function () {
if (taskQueueRef.current) {
var task = taskQueueRef.current;
taskQueueRef.current = null;
if (typeof task === 'function') {
task();
}
},
resetContentHeight: function (e) {
var index = parseInt(e.currentTarget.dataset.index, 10);
if (this.getValue().indexOf(index) < 0) {
return;
}
});
useEffect(function () {
var current = value;
var contentHeight = props.items.map(function (item, index) {
var contentHeight = __spreadArray([], this.data.contentHeight, true);
contentHeight[index] = '';
this.setData({
contentHeight: contentHeight,
});
},
}, {
contentHeight: [],
hasChange: false,
}, [
createValue({
valueKey: 'current',
defaultValueKey: 'defaultCurrent',
transformValue: function (current, extra) {
var value = this.formatCurrent(current, extra ? extra.nextProps : getValueFromProps(this));
return {
needUpdate: true,
value: value,
};
},
}),
], {
didUpdate: function (prevProps, prevData) {
console.log(prevProps.items !== this.props.items, !this.isEqualValue(prevData));
if (prevProps.items !== this.props.items ||
!this.isEqualValue(prevData)) {
this.updateContentHeight(this.getValue(prevData), this.getValue());
}
},
didMount: function () {
var current = this.getValue();
var contentHeight = this.props.items.map(function (item, index) {
if (current.indexOf(index) >= 0) {

@@ -141,30 +175,7 @@ return '';

});
setContentHeight(contentHeight);
setHasChange(true);
previousValueRef.current = value;
}, []);
useComponentUpdateEffect(function () {
var previous = previousValueRef.current;
previousValueRef.current = value;
updateContentHeight(previous, value);
}, [props.items, JSON.stringify(value)]);
useEvent('resetContentHeight', function (e) {
var index = parseInt(e.currentTarget.dataset.index, 10);
if (value.indexOf(index) < 0) {
return;
}
setContentHeight(function (oldContentHeight) {
var newContentHeight = __spreadArray([], oldContentHeight, true);
newContentHeight[index] = '';
return newContentHeight;
this.setData({
hasChange: true,
contentHeight: contentHeight,
});
});
return {
contentHeight: contentHeight,
hasChange: hasChange,
mixin: {
value: value,
},
};
};
mountComponent(Collapse, CollapseFunctionalProps);
},
});

@@ -35,2 +35,1 @@ import { IBaseProps } from '../_util/base';

export declare const CollapseDefaultProps: ICollapseProps;
export declare const CollapseFunctionalProps: ICollapseProps;

@@ -1,3 +0,2 @@

export var CollapseDefaultProps = {};
export var CollapseFunctionalProps = {
export var CollapseDefaultProps = {
current: null,

@@ -4,0 +3,0 @@ defaultCurrent: [],

import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { CheckboxGroupFunctionalProps, } from '../../Checkbox/CheckboxGroup/props';
import { CheckboxGroupDefaultProps, } from '../../Checkbox/CheckboxGroup/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var position = CheckboxGroupFunctionalProps.position, rest = __rest(CheckboxGroupFunctionalProps, ["position"]);
var position = CheckboxGroupDefaultProps.position, rest = __rest(CheckboxGroupDefaultProps, ["position"]);
export var FormCheckboxGroupDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { checkboxPosition: 'horizontal' });
import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { UploaderFunctionalProps, } from '../../ImageUpload/props';
import { UploaderDefaultProps, } from '../../ImageUpload/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var defaultFileList = UploaderFunctionalProps.defaultFileList, rest = __rest(UploaderFunctionalProps, ["defaultFileList"]);
var defaultFileList = UploaderDefaultProps.defaultFileList, rest = __rest(UploaderDefaultProps, ["defaultFileList"]);
export var FormImageUploadDefaultProps = __assign(__assign({}, FormItemFunctionalProps), rest);
import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { RadioGroupFunctionalProps, } from '../../Radio/RadioGroup/props';
import { RadioGroupDefaultProps, } from '../../Radio/RadioGroup/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var value = RadioGroupFunctionalProps.value, defaultValue = RadioGroupFunctionalProps.defaultValue, position = RadioGroupFunctionalProps.position, name = RadioGroupFunctionalProps.name, rest = __rest(RadioGroupFunctionalProps, ["value", "defaultValue", "position", "name"]);
var value = RadioGroupDefaultProps.value, defaultValue = RadioGroupDefaultProps.defaultValue, position = RadioGroupDefaultProps.position, name = RadioGroupDefaultProps.name, rest = __rest(RadioGroupDefaultProps, ["value", "defaultValue", "position", "name"]);
export var FormRadioGroupDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { radioPosition: 'horizontal' });
import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { RateFunctionalProps } from '../../Rate/props';
import { RateDefaultProps } from '../../Rate/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var defaultValue = RateFunctionalProps.defaultValue, rest = __rest(RateFunctionalProps, ["defaultValue"]);
var defaultValue = RateDefaultProps.defaultValue, rest = __rest(RateDefaultProps, ["defaultValue"]);
export var FormRateDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { rateClassName: '', rateStyle: '' });
import { __assign } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { SelectorFunctionalProps } from '../../Selector/props';
export var FormSelectorDefaultProps = __assign(__assign({}, FormItemFunctionalProps), SelectorFunctionalProps);
import { SelectorDefaultProps } from '../../Selector/props';
export var FormSelectorDefaultProps = __assign(__assign({}, FormItemFunctionalProps), SelectorDefaultProps);
import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { SwitchFunctionalProps } from '../../Switch/props';
import { SwitchDefaultProps } from '../../Switch/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var checked = SwitchFunctionalProps.checked, defaultChecked = SwitchFunctionalProps.defaultChecked, rest = __rest(SwitchFunctionalProps, ["checked", "defaultChecked"]);
var checked = SwitchDefaultProps.checked, defaultChecked = SwitchDefaultProps.defaultChecked, rest = __rest(SwitchDefaultProps, ["checked", "defaultChecked"]);
export var FormSwitchDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { switchClassName: '', switchStyle: '' });

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};
import { __assign, __awaiter, __generator, __spreadArray } from "tslib";
import { useEvent, useRef } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { triggerRefEvent } from '../_util/hooks/useReportRef';
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { UploaderDefaultProps } from './props';
import { chooseImage } from '../_util/jsapi/choose-image';
import { UploaderFunctionalProps, } from './props';
import { useId } from 'functional-mini/compat';
/**
* 获取一个内部使用的 uid
* 每次获取时自增
*/
var useCounter = function () {
var counterRef = useRef(0);
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
var prefix = useId() + '-' + Date.now();
return {
getCount: function () {
counterRef.current = counterRef.current + 1;
return "".concat(prefix, "-").concat(counterRef.current);
},
};
};
var ImageUpload = function (props) {
var getCount = useCounter().getCount;
var _a = useMixState(props.defaultFileList, {
value: props.fileList,
postState: function (fileList) {
return {
valid: true,
value: (fileList || []).map(function (item) {
var file = __assign({}, item);
if (typeof item.url === 'undefined') {
file.url = '';
}
if (typeof item.uid === 'undefined') {
file.uid = getCount();
}
if (typeof item.status === 'undefined') {
file.status = 'done';
}
return file;
}),
};
},
}), fileList = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update, triggerUpdater = _b.triggerUpdater;
triggerRefEvent();
var triggerEvent = useComponentEvent(props).triggerEvent;
function uploadFile(localFile) {
import createValue from '../mixins/value';
Component(UploaderDefaultProps, {
chooseImage: function () {
return __awaiter(this, void 0, void 0, function () {
var onUpload, uid, url, err_1;
var _a, onBeforeUpload, onUpload, fileList, _b, maxCount, sourceType, localFileList, chooseImageRes, err_1, beforeUploadRes, err_2, tasks;
var _this = this;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = getValueFromProps(this, [
'onBeforeUpload',
'onUpload',
]), onBeforeUpload = _a[0], onUpload = _a[1];
if (!onUpload) {
throw new Error('need props onUpload');
}
fileList = this.getValue();
_b = getValueFromProps(this, [
'maxCount',
'sourceType',
]), maxCount = _b[0], sourceType = _b[1];
_c.label = 1;
case 1:
_c.trys.push([1, 3, , 4]);
return [4 /*yield*/, chooseImage({
count: typeof maxCount === 'undefined'
? Infinity
: maxCount - fileList.length,
sourceType: sourceType,
})];
case 2:
chooseImageRes = _c.sent();
localFileList = (chooseImageRes.tempFiles ||
chooseImageRes.tempFilePaths ||
chooseImageRes.apFilePaths ||
chooseImageRes.filePaths ||
[])
.map(function (item) {
if (typeof item === 'string') {
return {
path: item,
};
}
if (item.path) {
return {
path: item.path,
size: item.size,
};
}
})
.filter(function (item) { return !!item; });
return [3 /*break*/, 4];
case 3:
err_1 = _c.sent();
triggerEvent(this, 'chooseImageError', err_1);
return [2 /*return*/];
case 4:
if (!onBeforeUpload) return [3 /*break*/, 8];
_c.label = 5;
case 5:
_c.trys.push([5, 7, , 8]);
return [4 /*yield*/, onBeforeUpload(localFileList)];
case 6:
beforeUploadRes = _c.sent();
if (beforeUploadRes === false) {
return [2 /*return*/];
}
if (Array.isArray(beforeUploadRes)) {
localFileList = beforeUploadRes;
}
return [3 /*break*/, 8];
case 7:
err_2 = _c.sent();
return [2 /*return*/];
case 8:
tasks = localFileList.map(function (file) { return _this.uploadFile(file); });
return [4 /*yield*/, Promise.all(tasks)];
case 9:
_c.sent();
return [2 /*return*/];
}
});
});
},
uploadFile: function (localFile) {
return __awaiter(this, void 0, void 0, function () {
var onUpload, uid, tempFileList, url, err_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
onUpload = props.onUpload;
uid = getCount();
triggerUpdater(function (oldFiles) {
var tempFileList = __spreadArray(__spreadArray([], oldFiles, true), [
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-expect-error
path: localFile.path,
size: localFile.size,
uid: uid,
status: 'uploading',
},
], false);
triggerEvent('change', tempFileList);
return tempFileList;
});
onUpload = getValueFromProps(this, 'onUpload');
uid = this.getCount();
tempFileList = __spreadArray(__spreadArray([], this.getValue(), true), [
{
path: localFile.path,
size: localFile.size,
uid: uid,
status: 'uploading',
},
], false);
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
_a.label = 1;

@@ -80,3 +116,3 @@ case 1:

if (typeof url !== 'string' || !url) {
updateFile(uid, {
this.updateFile(uid, {
status: 'error',

@@ -86,3 +122,3 @@ });

}
updateFile(uid, {
this.updateFile(uid, {
status: 'done',

@@ -93,4 +129,4 @@ url: url,

case 3:
err_1 = _a.sent();
updateFile(uid, {
err_3 = _a.sent();
this.updateFile(uid, {
status: 'error',

@@ -103,133 +139,101 @@ });

});
}
function updateFile(uid, file) {
},
updateFile: function (uid, file) {
var fileList = this.getValue();
var tempFileList = fileList.map(function (item) {
if (item.uid === uid) {
return __assign(__assign({}, item), file);
}
return item;
});
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
},
onRemove: function (e) {
return __awaiter(this, void 0, void 0, function () {
var fileList, onRemove, uid, file, result, tempFileList;
return __generator(this, function (_a) {
triggerUpdater(function (old) {
var tempFileList = old.map(function (item) {
if (item.uid === uid) {
return __assign(__assign({}, item), file);
switch (_a.label) {
case 0:
fileList = this.getValue();
onRemove = getValueFromProps(this, 'onRemove');
uid = e.currentTarget.dataset.uid;
file = fileList.find(function (item) { return item.uid === uid; });
if (!onRemove) return [3 /*break*/, 2];
return [4 /*yield*/, onRemove(file)];
case 1:
result = _a.sent();
if (result === false) {
return [2 /*return*/];
}
return item;
});
triggerEvent('change', tempFileList);
return tempFileList;
});
return [2 /*return*/];
_a.label = 2;
case 2:
tempFileList = fileList.filter(function (item) { return item.uid !== uid; });
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
return [2 /*return*/];
}
});
});
}
useEvent('chooseImage', function () { return __awaiter(void 0, void 0, void 0, function () {
var onBeforeUpload, onUpload, maxCount, sourceType, localFileList, chooseImageRes, err_2, beforeUploadRes, err_3, tasks;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
onBeforeUpload = props.onBeforeUpload, onUpload = props.onUpload, maxCount = props.maxCount, sourceType = props.sourceType;
if (!onUpload || typeof onUpload !== 'function') {
throw new Error('need props onUpload');
},
onPreview: function (e) {
var uid = e.currentTarget.dataset.uid;
var fileList = this.getValue();
var file = fileList.find(function (item) { return item.uid === uid; });
triggerEvent(this, 'preview', file);
},
updateShowUploadButton: function () {
var maxCount = getValueFromProps(this, 'maxCount');
this.setData({
showUploadButton: !maxCount || this.getValue().length < maxCount,
});
},
count: 0,
getCount: function () {
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
this.count = (this.count || 0) + 1;
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
var id = this.id;
id = this.$id;
var prefix = id + '-' + Date.now();
return "".concat(prefix, "-").concat(this.count);
},
}, null, [
createValue({
defaultValueKey: 'defaultFileList',
valueKey: 'fileList',
transformValue: function (fileList) {
var _this = this;
if (fileList === void 0) { fileList = []; }
return {
needUpdate: true,
value: fileList.map(function (item) {
var file = __assign({}, item);
if (typeof item.url === 'undefined') {
file.url = '';
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, chooseImage({
count: typeof maxCount === 'undefined'
? Infinity
: maxCount - fileList.length,
sourceType: sourceType,
})];
case 2:
chooseImageRes = _a.sent();
localFileList = (chooseImageRes.tempFiles ||
chooseImageRes.tempFilePaths ||
chooseImageRes.apFilePaths ||
chooseImageRes.filePaths ||
[])
.map(function (item) {
if (typeof item === 'string') {
return {
path: item,
};
}
if (item.path) {
return {
path: item.path,
size: item.size,
};
}
})
.filter(function (item) { return !!item; });
return [3 /*break*/, 4];
case 3:
err_2 = _a.sent();
triggerEvent('chooseImageError', err_2);
return [2 /*return*/];
case 4:
if (!(onBeforeUpload && typeof onBeforeUpload === 'function')) return [3 /*break*/, 8];
_a.label = 5;
case 5:
_a.trys.push([5, 7, , 8]);
return [4 /*yield*/, onBeforeUpload(localFileList)];
case 6:
beforeUploadRes = _a.sent();
if (beforeUploadRes === false) {
return [2 /*return*/];
if (typeof item.uid === 'undefined') {
file.uid = _this.getCount();
}
if (Array.isArray(beforeUploadRes)) {
localFileList = beforeUploadRes;
if (typeof item.status === 'undefined') {
file.status = 'done';
}
return [3 /*break*/, 8];
case 7:
err_3 = _a.sent();
return [2 /*return*/];
case 8:
tasks = localFileList.map(function (file) { return uploadFile(file); });
return [4 /*yield*/, Promise.all(tasks)];
case 9:
_a.sent();
return [2 /*return*/];
}
});
}); });
useEvent('onRemove', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var uid, file, result, tempFileList;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
uid = e.currentTarget.dataset.uid;
file = fileList.find(function (item) { return item.uid === uid; });
if (!(props.onRemove && typeof props.onRemove === 'function')) return [3 /*break*/, 2];
return [4 /*yield*/, props.onRemove(file)];
case 1:
result = _a.sent();
if (result === false) {
return [2 /*return*/];
}
_a.label = 2;
case 2:
tempFileList = fileList.filter(function (item) { return item.uid !== uid; });
if (!isControlled) {
update(tempFileList);
}
triggerEvent('change', tempFileList);
return [2 /*return*/];
}
});
}); });
useEvent('onPreview', function (e) {
var uid = e.currentTarget.dataset.uid;
var file = fileList.find(function (item) { return item.uid === uid; });
triggerEvent('preview', file);
});
useEvent('update', function (e) {
if (isControlled) {
return;
return file;
}),
};
},
}),
], {
didMount: function () {
this.updateShowUploadButton();
},
didUpdate: function (prevProps, prevData) {
if (!this.isEqualValue(prevData)) {
this.updateShowUploadButton();
}
update(e);
});
return {
mixin: {
value: fileList,
},
};
};
mountComponent(ImageUpload, UploaderFunctionalProps);
},
});

@@ -75,8 +75,7 @@ import { IBaseProps } from '../_util/base';

/**
* @description 上传失败文案
* @default "上传失败"
*/
* @description 上传失败文案
* @default "上传失败"
*/
uploadfailedText?: string;
}
export declare const UploaderDefaultProps: Partial<IUploaderProps>;
export declare const UploaderFunctionalProps: Partial<IUploaderProps>;
export var UploaderDefaultProps = {
defaultFileList: [],
imageMode: 'scaleToFill',
sourceType: ['camera', 'album'],
};
export var UploaderFunctionalProps = {
defaultFileList: [],
fileList: null,

@@ -16,3 +11,3 @@ maxCount: null,

uploadingText: '上传中',
uploadfailedText: '上传失败'
uploadfailedText: '上传失败',
};

@@ -135,3 +135,3 @@ function getColumnValue(columnItem) {

var selectedIndex = [];
var value = realValue;
var value = realValue || [];
if (sinefileRef.current) {

@@ -138,0 +138,0 @@ value = [realValue];

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};

@@ -1,30 +0,17 @@

import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
var Radio = function (props) {
var _a = useMixState(props.defaultChecked, {
value: props.checked,
}), radioValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
import { Component, triggerEvent } from '../_util/simply';
import { RadioDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(RadioDefaultProps, {
onChange: function (e) {
var value = e.detail.value;
if (!isControlled) {
update(value);
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', value, e);
});
return {
mixin: {
value: radioValue,
},
};
};
mountComponent(Radio, {
value: null,
defaultChecked: null,
color: '',
checked: null,
disabled: false,
});
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

@@ -1,1 +0,7 @@

export var RadioDefaultProps = {};
export var RadioDefaultProps = {
value: null,
defaultChecked: null,
color: '',
checked: null,
disabled: false,
};

@@ -1,25 +0,16 @@

import { RadioGroupFunctionalProps } from './props';
import { mountComponent } from '../../_util/component';
import { useMixState } from '../../_util/hooks/useMixState';
import { useEvent } from 'functional-mini/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
var RadioGroup = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (_, e) {
var index = e.currentTarget.dataset.index;
var value = props.options[index].value;
if (!isControlled) {
update(value);
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { RadioGroupDefaultProps } from './props';
import mixinValue from '../../mixins/value';
Component(RadioGroupDefaultProps, {
onChange: function (_, e) {
var event;
event = e;
var index = event.currentTarget.dataset.index;
var options = getValueFromProps(this, 'options');
var value = options[index].value;
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', value, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(RadioGroup, RadioGroupFunctionalProps);
triggerEvent(this, 'change', value, event);
},
}, null, [mixinValue()]);

@@ -18,2 +18,1 @@ import { IBaseProps } from '../../_util/base';

export declare const RadioGroupDefaultProps: Partial<IRadioGroupProps>;
export declare const RadioGroupFunctionalProps: Partial<IRadioGroupProps>;
export var RadioGroupDefaultProps = {
options: [],
position: 'vertical',
};
export var RadioGroupFunctionalProps = {
value: null,

@@ -7,0 +3,0 @@ defaultValue: null,

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};
import { __assign, __awaiter, __generator } from "tslib";
import { useComponent, useEvent, useRef, useState, } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { RateDefaultProps } from './props';
import createValue from '../mixins/value';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
import { RateFunctionalProps } from './props';
var Rate = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (value) {
if (props.allowHalf) {
return {
valid: true,
value: value % 0.5 !== 0 ? Math.round(value) : value,
};
}
return {
valid: true,
value: Math.ceil(value),
};
},
}), rateValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
var _c = useState(null), displayValue = _c[0], setDisplayValue = _c[1];
var ref = useRef(null);
var instance = useComponent();
function getInstance() {
if (instance.$id) {
Component(RateDefaultProps, {
getInstance: function () {
if (this.$id) {
return my;
}
return instance;
}
function getRate(clientX) {
return this;
},
getRate: function (clientX) {
return __awaiter(this, void 0, void 0, function () {
var gutter, count, _a, left, width, halfRateWidth, num, halfRateCount, val, rate;
return __generator(this, function (_b) {
switch (_b.label) {
var _a, gutter, count, allowHalf, _b, left, width, halfRateWidth, num, halfRateCount, val, rate;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
gutter = props.gutter, count = props.count;
return [4 /*yield*/, getInstanceBoundingClientRect(getInstance(), "#ant-rate-container".concat(instance.$id ? "-".concat(instance.$id) : ''))];
_a = getValueFromProps(this, [
'gutter',
'count',
'allowHalf',
]), gutter = _a[0], count = _a[1], allowHalf = _a[2];
return [4 /*yield*/, getInstanceBoundingClientRect(this.getInstance(), "#ant-rate-container".concat(this.$id ? "-".concat(this.$id) : ''))];
case 1:
_a = _b.sent(), left = _a.left, width = _a.width;
_b = _c.sent(), left = _b.left, width = _b.width;
halfRateWidth = (width - (count - 1) * gutter) / count / 2;

@@ -50,3 +32,4 @@ num = clientX - left;

while (true) {
val = halfRateWidth * halfRateCount + gutter * Math.floor(halfRateCount / 2);
val = halfRateWidth * halfRateCount +
gutter * Math.floor(halfRateCount / 2);
if (halfRateCount >= count * 2 || num <= val) {

@@ -57,3 +40,3 @@ break;

}
rate = props.allowHalf
rate = allowHalf
? halfRateCount * 0.5

@@ -65,86 +48,103 @@ : Math.ceil(halfRateCount * 0.5);

});
}
useEvent('handleStarTap', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var _a, clientX, x, clickX, rate;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (props.readonly) {
},
handleStarTap: function (e) {
return __awaiter(this, void 0, void 0, function () {
var _a, readonly, allowClear, _b, clientX, x, clickX, rateValue, rate;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = getValueFromProps(this, [
'readonly',
'allowClear',
]), readonly = _a[0], allowClear = _a[1];
if (readonly) {
return [2 /*return*/];
}
_b = e.detail, clientX = _b.clientX, x = _b.x;
clickX = typeof x === 'number' ? x : clientX;
rateValue = this.getValue();
return [4 /*yield*/, this.getRate(clickX)];
case 1:
rate = _c.sent();
if (rateValue === rate && allowClear) {
rate = 0;
}
if (!this.isControlled()) {
this.update(rate);
}
if (rateValue !== rate) {
triggerEvent(this, 'change', rate);
}
return [2 /*return*/];
}
_a = e.detail, clientX = _a.clientX, x = _a.x;
clickX = typeof x === 'number' ? x : clientX;
return [4 /*yield*/, getRate(clickX)];
case 1:
rate = _b.sent();
if (rateValue === rate && props.allowClear) {
rate = 0;
}
if (!isControlled) {
update(rate);
}
if (rateValue !== rate) {
triggerEvent('change', rate);
}
return [2 /*return*/];
}
}
});
});
}); });
useEvent('handleStarMove', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var touches, clientX, rate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (props.readonly) {
return [2 /*return*/];
}
touches = e.touches;
clientX = touches[0].clientX;
if (!ref.current) {
ref.current = {
originalRate: rateValue,
};
}
return [4 /*yield*/, getRate(clientX)];
case 1:
rate = _a.sent();
if (ref.current) {
ref.current = __assign(__assign({}, ref.current), { currentRate: rate });
if (isControlled) {
setDisplayValue(rate);
},
handleStarMove: function (e) {
return __awaiter(this, void 0, void 0, function () {
var readonly, touches, clientX, rate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
readonly = getValueFromProps(this, ['readonly'])[0];
if (readonly) {
return [2 /*return*/];
}
else {
update(rate);
touches = e.touches;
clientX = touches[0].clientX;
if (!this.moveRate) {
this.moveRate = {
originalRate: this.getValue(),
};
}
}
return [2 /*return*/];
}
return [4 /*yield*/, this.getRate(clientX)];
case 1:
rate = _a.sent();
if (this.moveRate) {
this.moveRate = __assign(__assign({}, this.moveRate), { currentRate: rate });
if (this.isControlled()) {
this.setData({ displayValue: rate });
}
else {
this.update(rate);
}
}
return [2 /*return*/];
}
});
});
}); });
useEvent('handleStarMoveEnd', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, currentRate, originalRate;
return __generator(this, function (_b) {
if (props.readonly) {
return [2 /*return*/];
},
handleStarMoveEnd: function () {
var readonly = getValueFromProps(this, 'readonly');
if (readonly) {
return;
}
if (!this.moveRate) {
return;
}
var _a = this.moveRate, currentRate = _a.currentRate, originalRate = _a.originalRate;
this.moveRate = null;
if (this.isControlled()) {
this.setData({ displayValue: null });
}
if (currentRate !== originalRate) {
triggerEvent(this, 'change', currentRate);
}
},
}, { displayValue: null }, [
createValue({
transformValue: function (value) {
var allowHalf = getValueFromProps(this, 'allowHalf');
if (allowHalf) {
return {
needUpdate: true,
value: value % 0.5 !== 0 ? Math.round(value) : value,
};
}
if (!ref.current) {
return [2 /*return*/];
}
_a = ref.current, currentRate = _a.currentRate, originalRate = _a.originalRate;
ref.current = null;
if (isControlled) {
setDisplayValue(null);
}
if (currentRate !== originalRate) {
triggerEvent('change', currentRate);
}
return [2 /*return*/];
});
}); });
return {
mixin: {
value: displayValue !== null ? displayValue : rateValue,
return {
needUpdate: true,
value: Math.ceil(value),
};
},
};
};
mountComponent(Rate, RateFunctionalProps);
}),
]);

@@ -45,2 +45,1 @@ import { IBaseProps } from '../_util/base';

export declare const RateDefaultProps: Partial<IRateProps>;
export declare const RateFunctionalProps: Partial<IRateProps>;
export var RateDefaultProps = {
count: 5,
gutter: 4,
allowClear: true,
};
export var RateFunctionalProps = {
value: null,

@@ -8,0 +3,0 @@ defaultValue: null,

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};
import { __spreadArray } from "tslib";
import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { SelectorFunctionalProps } from './props';
var Selector = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
}), selectorValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEventValues = useComponentEvent(props).triggerEventValues;
useEvent('onChange', function (e) {
import { Component, triggerEventValues, getValueFromProps, } from '../_util/simply';
import { SelectorDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(SelectorDefaultProps, {
onChange: function (e) {
var _a = e.currentTarget.dataset, disabled = _a.disabled, value = _a.value;
var multiple = props.multiple, options = props.options, maxSelectedCount = props.maxSelectedCount, minSelectedCount = props.minSelectedCount;
if (disabled || props.disabled) {
var _b = getValueFromProps(this, [
'multiple',
'options',
'maxSelectedCount',
'minSelectedCount',
'disabled',
]), multiple = _b[0], options = _b[1], maxSelectedCount = _b[2], minSelectedCount = _b[3], disabledFromProps = _b[4];
if (disabled || disabledFromProps) {
return;
}
if (multiple) {
var currentValue_1 = selectorValue || [];
var currentValue_1 = this.getValue() || [];
if (currentValue_1.indexOf(value) > -1) {
if (typeof minSelectedCount === 'number' &&
currentValue_1.length <= minSelectedCount) {
triggerEventValues('selectMin', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMin', [value, options.find(function (v) { return v.value === value; })], e);
return;

@@ -32,3 +31,3 @@ }

currentValue_1.length >= maxSelectedCount) {
triggerEventValues('selectMax', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMax', [value, options.find(function (v) { return v.value === value; })], e);
return;

@@ -38,6 +37,6 @@ }

}
if (!isControlled) {
update(currentValue_1);
if (!this.isControlled()) {
this.update(currentValue_1);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
currentValue_1,

@@ -48,26 +47,20 @@ options.filter(function (v) { return currentValue_1.indexOf(v.value) > -1; }),

else {
if (value === selectorValue) {
if (value === this.getValue()) {
if (minSelectedCount === 1) {
triggerEventValues('selectMin', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMin', [value, options.find(function (v) { return v.value === value; })], e);
return;
}
if (!isControlled) {
update(undefined);
if (!this.isControlled()) {
this.update(undefined);
}
triggerEventValues('change', [undefined, undefined], e);
triggerEventValues(this, 'change', [undefined, undefined], e);
}
else {
if (!isControlled) {
update(value);
if (!this.isControlled()) {
this.update(value);
}
triggerEventValues('change', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'change', [value, options.find(function (v) { return v.value === value; })], e);
}
}
});
return {
mixin: {
value: selectorValue,
},
};
};
mountComponent(Selector, SelectorFunctionalProps);
},
}, null, [mixinValue()]);

@@ -70,2 +70,1 @@ import { IBaseProps } from '../_util/base';

export declare const SelectorDefaultProps: Partial<ISelectorProps>;
export declare const SelectorFunctionalProps: Partial<ISelectorProps>;
export var SelectorDefaultProps = {
multiple: false,
disabled: false,
};
export var SelectorFunctionalProps = {
value: null,

@@ -7,0 +3,0 @@ defaultValue: null,

@@ -1,22 +0,17 @@

import { mountComponent } from '../_util/component';
import { useMergedState, hasValue } from '../_util/hooks/useMergedState';
import { SwitchFunctionalProps } from './props';
import { useEvent } from 'functional-mini/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
var Switch = function (props) {
var _a = useMergedState(props.defaultChecked, {
value: props.checked,
}), value = _a[0], updateValue = _a[1];
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
var newValue = !value;
if (!hasValue(props.checked)) {
updateValue(newValue);
import { Component, triggerEvent } from '../_util/simply';
import { SwitchDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(SwitchDefaultProps, {
onChange: function (e) {
var value = !this.getValue();
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', newValue, e);
});
return {
mixin: { value: value },
};
};
mountComponent(Switch, SwitchFunctionalProps);
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

@@ -45,2 +45,1 @@ import { IBaseProps } from '../_util/base';

export declare const SwitchDefaultProps: Partial<ISwitchProps>;
export declare const SwitchFunctionalProps: Partial<ISwitchProps>;
export var SwitchDefaultProps = {
size: 'medium',
};
export var SwitchFunctionalProps = {
checked: null,

@@ -6,0 +3,0 @@ loading: false,

@@ -1,27 +0,20 @@

import { useEvent } from 'functional-mini/component';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { TabBarFunctionalProps } from './props';
var TabBar = function (props) {
var _a = useMixState(props.defaultCurrent, {
value: props.current,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
import { TabBarDefaultProps } from './props';
import { Component, triggerEvent } from '../_util/simply';
import mixinValue from '../mixins/value';
Component(TabBarDefaultProps, {
onChange: function (e) {
var index = e.currentTarget.dataset.index;
if (index === value) {
if (index === this.getValue()) {
return;
}
if (!isControlled) {
update(index);
if (!this.isControlled()) {
this.update(index);
}
triggerEvent('change', index, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(TabBar, TabBarFunctionalProps);
triggerEvent(this, 'change', index, e);
},
}, null, [
mixinValue({
valueKey: 'current',
defaultValueKey: 'defaultCurrent',
}),
]);

@@ -56,2 +56,1 @@ import { IBaseProps } from '../_util/base';

export declare const TabBarDefaultProps: Partial<ITabBarProps>;
export declare const TabBarFunctionalProps: Partial<ITabBarProps>;
export var TabBarDefaultProps = {
items: [],
defaultCurrent: 0,
};
export var TabBarFunctionalProps = {
items: [],
current: null,

@@ -8,0 +4,0 @@ defaultCurrent: 0,

import { __spreadArray } from "tslib";
import { useEvent } from 'functional-mini/component';
import { mountComponent } from '../../_util/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
import { useMixState } from '../../_util/hooks/useMixState';
import { CheckboxGroupFunctionalProps } from './props';
var CheckboxGroup = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (value) {
return {
valid: true,
value: value || [],
};
},
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (args, e) {
if (props.disabled) {
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { CheckboxGroupDefaultProps } from './props';
import mixinValue from '../../mixins/value';
Component(CheckboxGroupDefaultProps, {
onChange: function (args, e) {
if (getValueFromProps(this, 'disabled')) {
return;

@@ -24,5 +12,5 @@ }

event = e;
var currentValue = value;
var currentValue = this.getValue();
var index = event.currentTarget.dataset.index;
var selectValue = props.options[index].value;
var selectValue = getValueFromProps(this, 'options')[index].value;
if (currentValue.indexOf(selectValue) > -1) {

@@ -34,11 +22,17 @@ currentValue = currentValue.filter(function (v) { return v !== selectValue; });

}
if (!isControlled) {
update(currentValue);
if (!this.isControlled()) {
this.update(currentValue);
}
triggerEvent('change', currentValue, e);
});
return {
mixin: { value: value },
};
};
mountComponent(CheckboxGroup, CheckboxGroupFunctionalProps);
triggerEvent(this, 'change', currentValue, e);
},
}, null, [
mixinValue({
transformValue: function (val) {
var value = val || [];
return {
needUpdate: true,
value: value,
};
},
}),
]);

@@ -16,2 +16,1 @@ import { IBaseProps } from '../../_util/base';

export declare const CheckboxGroupDefaultProps: Partial<ICheckboxGroupProps>;
export declare const CheckboxGroupFunctionalProps: Partial<ICheckboxGroupProps>;
export var CheckboxGroupDefaultProps = {
options: [],
position: 'vertical',
defaultValue: [],
};
export var CheckboxGroupFunctionalProps = {
value: null,

@@ -8,0 +3,0 @@ defaultValue: [],

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};

@@ -1,30 +0,17 @@

import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
var Checkbox = function (props) {
var _a = useMixState(props.defaultChecked, {
value: props.checked,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
var newValue = !value;
if (!isControlled) {
update(newValue);
import { CheckboxDefaultProps } from './props';
import { Component, triggerEvent } from '../_util/simply';
import mixinValue from '../mixins/value';
Component(CheckboxDefaultProps, {
onChange: function (e) {
var value = !this.getValue();
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', newValue, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(Checkbox, {
value: null,
checked: null,
defaultChecked: null,
disabled: false,
color: '',
});
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

@@ -1,1 +0,7 @@

export var CheckboxDefaultProps = {};
export var CheckboxDefaultProps = {
value: null,
checked: null,
defaultChecked: null,
disabled: false,
color: '',
};

@@ -1,7 +0,7 @@

import { Component, triggerEvent } from '../../_util/simply';
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { ChecklistItemDefaultProps } from './props';
Component(ChecklistItemDefaultProps, {
onChecklistItemClick: function () {
triggerEvent(this, 'change', this.props.item);
}
triggerEvent(this, 'change', getValueFromProps(this, 'item'));
},
});
import { __spreadArray } from "tslib";
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useHandleCustomEvent } from '../_util/hooks/useHandleCustomEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { ChecklistFunctionalProps, } from './props';
var Checkbox = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (val) {
var value = val || [];
return {
valid: true,
value: value,
};
},
}), state = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEventValues = useComponentEvent(props).triggerEventValues;
useHandleCustomEvent('onChange', function (item) {
var multiple = props.multiple, options = props.options;
var value = item.value;
import { Component, triggerEventValues, getValueFromProps, } from '../_util/simply';
import { ChecklistDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(ChecklistDefaultProps, {
onChange: function (item) {
var _a = getValueFromProps(this, [
'multiple',
'options',
]), multiple = _a[0], options = _a[1];
var value;
value = item.value;
if (multiple) {
var currentValue_1 = state;
var currentValue_1 = this.getValue();
if (currentValue_1.indexOf(value) > -1) {

@@ -30,6 +21,6 @@ currentValue_1 = currentValue_1.filter(function (v) { return v !== value; });

}
if (!isControlled) {
update(currentValue_1);
if (!this.isControlled()) {
this.update(currentValue_1);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
currentValue_1,

@@ -40,6 +31,6 @@ options.filter(function (v) { return currentValue_1.indexOf(v.value) > -1; }),

else {
if (!isControlled) {
update(value);
if (!this.isControlled()) {
this.update(value);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
value,

@@ -49,9 +40,13 @@ options.find(function (v) { return v.value === value; }),

}
});
return {
mixin: {
value: state,
},
}, null, [
mixinValue({
transformValue: function (val) {
var value = val || [];
return {
needUpdate: true,
value: value,
};
},
};
};
mountComponent(Checkbox, ChecklistFunctionalProps);
}),
]);

@@ -49,2 +49,1 @@ import { IBaseProps } from '../_util/base';

export declare const ChecklistDefaultProps: Partial<IChecklistProps>;
export declare const ChecklistFunctionalProps: Partial<IChecklistProps>;
export var ChecklistDefaultProps = {
multiple: false,
options: [],
};
export var ChecklistFunctionalProps = {
value: null,
defaultValue: null,
options: [],
multiple: false,
options: [],
};

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};
import { __awaiter, __generator, __spreadArray } from "tslib";
import { useRef, useState } from 'functional-mini/compat';
import { useEffect, useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useInstanceBoundingClientRect } from '../_util/hooks/useInstanceBoundingClientRect';
import { useComponentUpdateEffect } from '../_util/hooks/useLayoutEffect';
import { useMixState } from '../_util/hooks/useMixState';
import { CollapseFunctionalProps } from './props';
import { useEvent as useStableCallback } from '../_util/hooks/useEvent';
var Collapse = function (props) {
var _a = useState([]), contentHeight = _a[0], setContentHeight = _a[1];
var _b = useState(false), hasChange = _b[0], setHasChange = _b[1];
var taskQueueRef = useRef();
var previousValueRef = useRef([]);
var _c = useMixState(props.defaultCurrent, {
value: props.current,
postState: function (val) {
var current = __spreadArray([], (val || []), true);
var items = props.items;
current = current.filter(function (item) {
if (!items[item] || items[item].disabled) {
return false;
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { CollapseDefaultProps } from './props';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
import createValue from '../mixins/value';
Component(CollapseDefaultProps, {
getInstance: function () {
if (this.$id) {
return my;
}
return this;
},
getBoundingClientRectWithBuilder: function (builder) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, getInstanceBoundingClientRect(this.getInstance(), builder(this.$id ? "-".concat(this.$id) : ''))];
case 1: return [2 /*return*/, _a.sent()];
}
return true;
});
if (props.accordion) {
current = current.length > 0 ? [current[0]] : [];
});
},
formatCurrent: function (val, props) {
var current = __spreadArray([], (val || []), true);
var items = props.items;
current = current.filter(function (item) {
if (!items[item] || items[item].disabled) {
return false;
}
return {
valid: true,
value: __spreadArray([], current, true),
};
},
}), value = _c[0], _d = _c[1], isControlled = _d.isControlled, update = _d.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
return true;
});
if (props.accordion) {
current = current.length > 0 ? [current[0]] : [];
}
return __spreadArray([], current, true);
},
onChange: function (e) {
var itemIndex = parseInt(e.currentTarget.dataset.index, 10);
if (props.items[itemIndex] && props.items[itemIndex].disabled) {
var _a = getValueFromProps(this, [
'items',
'accordion',
]), items = _a[0], accordion = _a[1];
if (items[itemIndex] && items[itemIndex].disabled) {
return;
}
var arr = value;
var arr = this.getValue();
var current = __spreadArray([], arr, true);

@@ -50,3 +53,3 @@ var index = current.indexOf(itemIndex);

else {
if (props.accordion) {
if (accordion) {
current = [itemIndex];

@@ -59,78 +62,109 @@ }

}
if (!isControlled) {
update(current);
if (!this.isControlled()) {
this.update(current);
}
triggerEvent('change', current);
});
var getBoundingClientRectWithBuilder = useInstanceBoundingClientRect().getBoundingClientRectWithBuilder;
var updateContentHeight = useStableCallback(function (prevCurrent, nextCurrent) { return __awaiter(void 0, void 0, void 0, function () {
var prevCurrentArray, nextCurrentArray, expandArray, closeArray, newContentHeight;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
prevCurrentArray = prevCurrent;
nextCurrentArray = nextCurrent;
expandArray = [];
closeArray = [];
nextCurrentArray.forEach(function (item) {
if (prevCurrentArray.indexOf(item) < 0) {
expandArray.push(item);
triggerEvent(this, 'change', current, e);
},
updateContentHeight: function (prevCurrent, nextCurrent) {
return __awaiter(this, void 0, void 0, function () {
var prevCurrentArray, nextCurrentArray, expandArray, closeArray, items, contentHeight;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
prevCurrentArray = prevCurrent;
nextCurrentArray = nextCurrent;
expandArray = [];
closeArray = [];
nextCurrentArray.forEach(function (item) {
if (prevCurrentArray.indexOf(item) < 0) {
expandArray.push(item);
}
});
prevCurrentArray.forEach(function (item) {
if (nextCurrentArray.indexOf(item) < 0) {
closeArray.push(item);
}
});
items = getValueFromProps(this, 'items');
return [4 /*yield*/, Promise.all(items.map(function (item, index) { return __awaiter(_this, void 0, void 0, function () {
var height;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(expandArray.indexOf(index) >= 0 ||
closeArray.indexOf(index) >= 0)) return [3 /*break*/, 2];
return [4 /*yield*/, this.getBoundingClientRectWithBuilder(function (id) { return ".ant-collapse-item-content".concat(id, "-").concat(index); })];
case 1:
height = (_a.sent()).height;
return [2 /*return*/, "".concat(height, "px")];
case 2: return [2 /*return*/, this.data.contentHeight[index]];
}
});
}); }))];
case 1:
contentHeight = _a.sent();
if (closeArray.length === 0) {
this.setData({
contentHeight: contentHeight,
});
}
});
prevCurrentArray.forEach(function (item) {
if (nextCurrentArray.indexOf(item) < 0) {
closeArray.push(item);
}
});
return [4 /*yield*/, Promise.all(props.items.map(function (item, index) { return __awaiter(void 0, void 0, void 0, function () {
var height;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(expandArray.indexOf(index) >= 0 ||
closeArray.indexOf(index) >= 0)) return [3 /*break*/, 2];
return [4 /*yield*/, getBoundingClientRectWithBuilder(function (id) { return ".ant-collapse-item-content".concat(id, "-").concat(index); })];
case 1:
height = (_a.sent()).height;
return [2 /*return*/, "".concat(height, "px")];
case 2: return [2 /*return*/, contentHeight[index]];
}
else {
this.setData({
contentHeight: contentHeight,
});
}); }))];
case 1:
newContentHeight = _a.sent();
if (closeArray.length === 0) {
setContentHeight(newContentHeight);
}
else {
setContentHeight(newContentHeight);
taskQueueRef.current = function () {
setTimeout(function () {
setContentHeight(function (contentHeight) {
return contentHeight.map(function (item, index) {
if (closeArray.indexOf(index) >= 0) {
return '0px';
}
return item;
});
contentHeight = contentHeight.map(function (item, index) {
if (closeArray.indexOf(index) >= 0) {
return '0px';
}
return item;
});
_this.setData({
contentHeight: contentHeight,
});
}, 10);
};
}
return [2 /*return*/];
}
}
return [2 /*return*/];
}
});
});
}); });
useEffect(function () {
if (taskQueueRef.current) {
var task = taskQueueRef.current;
taskQueueRef.current = null;
if (typeof task === 'function') {
task();
}
},
resetContentHeight: function (e) {
var index = parseInt(e.currentTarget.dataset.index, 10);
if (this.getValue().indexOf(index) < 0) {
return;
}
});
useEffect(function () {
var current = value;
var contentHeight = props.items.map(function (item, index) {
var contentHeight = __spreadArray([], this.data.contentHeight, true);
contentHeight[index] = '';
this.setData({
contentHeight: contentHeight,
});
},
}, {
contentHeight: [],
hasChange: false,
}, [
createValue({
valueKey: 'current',
defaultValueKey: 'defaultCurrent',
transformValue: function (current, extra) {
var value = this.formatCurrent(current, extra ? extra.nextProps : getValueFromProps(this));
return {
needUpdate: true,
value: value,
};
},
}),
], {
didUpdate: function (prevProps, prevData) {
console.log(prevProps.items !== this.props.items, !this.isEqualValue(prevData));
if (prevProps.items !== this.props.items ||
!this.isEqualValue(prevData)) {
this.updateContentHeight(this.getValue(prevData), this.getValue());
}
},
didMount: function () {
var current = this.getValue();
var contentHeight = this.props.items.map(function (item, index) {
if (current.indexOf(index) >= 0) {

@@ -141,30 +175,7 @@ return '';

});
setContentHeight(contentHeight);
setHasChange(true);
previousValueRef.current = value;
}, []);
useComponentUpdateEffect(function () {
var previous = previousValueRef.current;
previousValueRef.current = value;
updateContentHeight(previous, value);
}, [props.items, JSON.stringify(value)]);
useEvent('resetContentHeight', function (e) {
var index = parseInt(e.currentTarget.dataset.index, 10);
if (value.indexOf(index) < 0) {
return;
}
setContentHeight(function (oldContentHeight) {
var newContentHeight = __spreadArray([], oldContentHeight, true);
newContentHeight[index] = '';
return newContentHeight;
this.setData({
hasChange: true,
contentHeight: contentHeight,
});
});
return {
contentHeight: contentHeight,
hasChange: hasChange,
mixin: {
value: value,
},
};
};
mountComponent(Collapse, CollapseFunctionalProps);
},
});

@@ -35,2 +35,1 @@ import { IBaseProps } from '../_util/base';

export declare const CollapseDefaultProps: ICollapseProps;
export declare const CollapseFunctionalProps: ICollapseProps;

@@ -1,3 +0,2 @@

export var CollapseDefaultProps = {};
export var CollapseFunctionalProps = {
export var CollapseDefaultProps = {
current: null,

@@ -4,0 +3,0 @@ defaultCurrent: [],

import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { CheckboxGroupFunctionalProps, } from '../../Checkbox/CheckboxGroup/props';
import { CheckboxGroupDefaultProps, } from '../../Checkbox/CheckboxGroup/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var position = CheckboxGroupFunctionalProps.position, rest = __rest(CheckboxGroupFunctionalProps, ["position"]);
var position = CheckboxGroupDefaultProps.position, rest = __rest(CheckboxGroupDefaultProps, ["position"]);
export var FormCheckboxGroupDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { checkboxPosition: 'horizontal' });
import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { UploaderFunctionalProps, } from '../../ImageUpload/props';
import { UploaderDefaultProps, } from '../../ImageUpload/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var defaultFileList = UploaderFunctionalProps.defaultFileList, rest = __rest(UploaderFunctionalProps, ["defaultFileList"]);
var defaultFileList = UploaderDefaultProps.defaultFileList, rest = __rest(UploaderDefaultProps, ["defaultFileList"]);
export var FormImageUploadDefaultProps = __assign(__assign({}, FormItemFunctionalProps), rest);
import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { RadioGroupFunctionalProps, } from '../../Radio/RadioGroup/props';
import { RadioGroupDefaultProps, } from '../../Radio/RadioGroup/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var value = RadioGroupFunctionalProps.value, defaultValue = RadioGroupFunctionalProps.defaultValue, position = RadioGroupFunctionalProps.position, name = RadioGroupFunctionalProps.name, rest = __rest(RadioGroupFunctionalProps, ["value", "defaultValue", "position", "name"]);
var value = RadioGroupDefaultProps.value, defaultValue = RadioGroupDefaultProps.defaultValue, position = RadioGroupDefaultProps.position, name = RadioGroupDefaultProps.name, rest = __rest(RadioGroupDefaultProps, ["value", "defaultValue", "position", "name"]);
export var FormRadioGroupDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { radioPosition: 'horizontal' });
import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { RateFunctionalProps } from '../../Rate/props';
import { RateDefaultProps } from '../../Rate/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var defaultValue = RateFunctionalProps.defaultValue, rest = __rest(RateFunctionalProps, ["defaultValue"]);
var defaultValue = RateDefaultProps.defaultValue, rest = __rest(RateDefaultProps, ["defaultValue"]);
export var FormRateDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { rateClassName: '', rateStyle: '' });
import { __assign } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { SelectorFunctionalProps } from '../../Selector/props';
export var FormSelectorDefaultProps = __assign(__assign({}, FormItemFunctionalProps), SelectorFunctionalProps);
import { SelectorDefaultProps } from '../../Selector/props';
export var FormSelectorDefaultProps = __assign(__assign({}, FormItemFunctionalProps), SelectorDefaultProps);
import { __assign, __rest } from "tslib";
import { FormItemFunctionalProps } from '../FormItem/props';
import { SwitchFunctionalProps } from '../../Switch/props';
import { SwitchDefaultProps } from '../../Switch/props';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var checked = SwitchFunctionalProps.checked, defaultChecked = SwitchFunctionalProps.defaultChecked, rest = __rest(SwitchFunctionalProps, ["checked", "defaultChecked"]);
var checked = SwitchDefaultProps.checked, defaultChecked = SwitchDefaultProps.defaultChecked, rest = __rest(SwitchDefaultProps, ["checked", "defaultChecked"]);
export var FormSwitchDefaultProps = __assign(__assign(__assign({}, FormItemFunctionalProps), rest), { switchClassName: '', switchStyle: '' });

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};
import { __assign, __awaiter, __generator, __spreadArray } from "tslib";
import { useEvent, useRef } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { triggerRefEvent } from '../_util/hooks/useReportRef';
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { UploaderDefaultProps } from './props';
import { chooseImage } from '../_util/jsapi/choose-image';
import { UploaderFunctionalProps, } from './props';
import { useId } from 'functional-mini/compat';
/**
* 获取一个内部使用的 uid
* 每次获取时自增
*/
var useCounter = function () {
var counterRef = useRef(0);
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
var prefix = useId() + '-' + Date.now();
return {
getCount: function () {
counterRef.current = counterRef.current + 1;
return "".concat(prefix, "-").concat(counterRef.current);
},
};
};
var ImageUpload = function (props) {
var getCount = useCounter().getCount;
var _a = useMixState(props.defaultFileList, {
value: props.fileList,
postState: function (fileList) {
return {
valid: true,
value: (fileList || []).map(function (item) {
var file = __assign({}, item);
if (typeof item.url === 'undefined') {
file.url = '';
}
if (typeof item.uid === 'undefined') {
file.uid = getCount();
}
if (typeof item.status === 'undefined') {
file.status = 'done';
}
return file;
}),
};
},
}), fileList = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update, triggerUpdater = _b.triggerUpdater;
triggerRefEvent();
var triggerEvent = useComponentEvent(props).triggerEvent;
function uploadFile(localFile) {
import createValue from '../mixins/value';
Component(UploaderDefaultProps, {
chooseImage: function () {
return __awaiter(this, void 0, void 0, function () {
var onUpload, uid, url, err_1;
var _a, onBeforeUpload, onUpload, fileList, _b, maxCount, sourceType, localFileList, chooseImageRes, err_1, beforeUploadRes, err_2, tasks;
var _this = this;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = getValueFromProps(this, [
'onBeforeUpload',
'onUpload',
]), onBeforeUpload = _a[0], onUpload = _a[1];
if (!onUpload) {
throw new Error('need props onUpload');
}
fileList = this.getValue();
_b = getValueFromProps(this, [
'maxCount',
'sourceType',
]), maxCount = _b[0], sourceType = _b[1];
_c.label = 1;
case 1:
_c.trys.push([1, 3, , 4]);
return [4 /*yield*/, chooseImage({
count: typeof maxCount === 'undefined'
? Infinity
: maxCount - fileList.length,
sourceType: sourceType,
})];
case 2:
chooseImageRes = _c.sent();
localFileList = (chooseImageRes.tempFiles ||
chooseImageRes.tempFilePaths ||
chooseImageRes.apFilePaths ||
chooseImageRes.filePaths ||
[])
.map(function (item) {
if (typeof item === 'string') {
return {
path: item,
};
}
if (item.path) {
return {
path: item.path,
size: item.size,
};
}
})
.filter(function (item) { return !!item; });
return [3 /*break*/, 4];
case 3:
err_1 = _c.sent();
triggerEvent(this, 'chooseImageError', err_1);
return [2 /*return*/];
case 4:
if (!onBeforeUpload) return [3 /*break*/, 8];
_c.label = 5;
case 5:
_c.trys.push([5, 7, , 8]);
return [4 /*yield*/, onBeforeUpload(localFileList)];
case 6:
beforeUploadRes = _c.sent();
if (beforeUploadRes === false) {
return [2 /*return*/];
}
if (Array.isArray(beforeUploadRes)) {
localFileList = beforeUploadRes;
}
return [3 /*break*/, 8];
case 7:
err_2 = _c.sent();
return [2 /*return*/];
case 8:
tasks = localFileList.map(function (file) { return _this.uploadFile(file); });
return [4 /*yield*/, Promise.all(tasks)];
case 9:
_c.sent();
return [2 /*return*/];
}
});
});
},
uploadFile: function (localFile) {
return __awaiter(this, void 0, void 0, function () {
var onUpload, uid, tempFileList, url, err_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
onUpload = props.onUpload;
uid = getCount();
triggerUpdater(function (oldFiles) {
var tempFileList = __spreadArray(__spreadArray([], oldFiles, true), [
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-expect-error
path: localFile.path,
size: localFile.size,
uid: uid,
status: 'uploading',
},
], false);
triggerEvent('change', tempFileList);
return tempFileList;
});
onUpload = getValueFromProps(this, 'onUpload');
uid = this.getCount();
tempFileList = __spreadArray(__spreadArray([], this.getValue(), true), [
{
path: localFile.path,
size: localFile.size,
uid: uid,
status: 'uploading',
},
], false);
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
_a.label = 1;

@@ -80,3 +116,3 @@ case 1:

if (typeof url !== 'string' || !url) {
updateFile(uid, {
this.updateFile(uid, {
status: 'error',

@@ -86,3 +122,3 @@ });

}
updateFile(uid, {
this.updateFile(uid, {
status: 'done',

@@ -93,4 +129,4 @@ url: url,

case 3:
err_1 = _a.sent();
updateFile(uid, {
err_3 = _a.sent();
this.updateFile(uid, {
status: 'error',

@@ -103,133 +139,101 @@ });

});
}
function updateFile(uid, file) {
},
updateFile: function (uid, file) {
var fileList = this.getValue();
var tempFileList = fileList.map(function (item) {
if (item.uid === uid) {
return __assign(__assign({}, item), file);
}
return item;
});
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
},
onRemove: function (e) {
return __awaiter(this, void 0, void 0, function () {
var fileList, onRemove, uid, file, result, tempFileList;
return __generator(this, function (_a) {
triggerUpdater(function (old) {
var tempFileList = old.map(function (item) {
if (item.uid === uid) {
return __assign(__assign({}, item), file);
switch (_a.label) {
case 0:
fileList = this.getValue();
onRemove = getValueFromProps(this, 'onRemove');
uid = e.currentTarget.dataset.uid;
file = fileList.find(function (item) { return item.uid === uid; });
if (!onRemove) return [3 /*break*/, 2];
return [4 /*yield*/, onRemove(file)];
case 1:
result = _a.sent();
if (result === false) {
return [2 /*return*/];
}
return item;
});
triggerEvent('change', tempFileList);
return tempFileList;
});
return [2 /*return*/];
_a.label = 2;
case 2:
tempFileList = fileList.filter(function (item) { return item.uid !== uid; });
if (!this.isControlled()) {
this.update(tempFileList);
}
triggerEvent(this, 'change', tempFileList);
return [2 /*return*/];
}
});
});
}
useEvent('chooseImage', function () { return __awaiter(void 0, void 0, void 0, function () {
var onBeforeUpload, onUpload, maxCount, sourceType, localFileList, chooseImageRes, err_2, beforeUploadRes, err_3, tasks;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
onBeforeUpload = props.onBeforeUpload, onUpload = props.onUpload, maxCount = props.maxCount, sourceType = props.sourceType;
if (!onUpload || typeof onUpload !== 'function') {
throw new Error('need props onUpload');
},
onPreview: function (e) {
var uid = e.currentTarget.dataset.uid;
var fileList = this.getValue();
var file = fileList.find(function (item) { return item.uid === uid; });
triggerEvent(this, 'preview', file);
},
updateShowUploadButton: function () {
var maxCount = getValueFromProps(this, 'maxCount');
this.setData({
showUploadButton: !maxCount || this.getValue().length < maxCount,
});
},
count: 0,
getCount: function () {
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
this.count = (this.count || 0) + 1;
// 使用 Date.now() 与 useId 作为前缀,防止每次前缀都相同
var id = this.id;
id = this.$id;
var prefix = id + '-' + Date.now();
return "".concat(prefix, "-").concat(this.count);
},
}, null, [
createValue({
defaultValueKey: 'defaultFileList',
valueKey: 'fileList',
transformValue: function (fileList) {
var _this = this;
if (fileList === void 0) { fileList = []; }
return {
needUpdate: true,
value: fileList.map(function (item) {
var file = __assign({}, item);
if (typeof item.url === 'undefined') {
file.url = '';
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, chooseImage({
count: typeof maxCount === 'undefined'
? Infinity
: maxCount - fileList.length,
sourceType: sourceType,
})];
case 2:
chooseImageRes = _a.sent();
localFileList = (chooseImageRes.tempFiles ||
chooseImageRes.tempFilePaths ||
chooseImageRes.apFilePaths ||
chooseImageRes.filePaths ||
[])
.map(function (item) {
if (typeof item === 'string') {
return {
path: item,
};
}
if (item.path) {
return {
path: item.path,
size: item.size,
};
}
})
.filter(function (item) { return !!item; });
return [3 /*break*/, 4];
case 3:
err_2 = _a.sent();
triggerEvent('chooseImageError', err_2);
return [2 /*return*/];
case 4:
if (!(onBeforeUpload && typeof onBeforeUpload === 'function')) return [3 /*break*/, 8];
_a.label = 5;
case 5:
_a.trys.push([5, 7, , 8]);
return [4 /*yield*/, onBeforeUpload(localFileList)];
case 6:
beforeUploadRes = _a.sent();
if (beforeUploadRes === false) {
return [2 /*return*/];
if (typeof item.uid === 'undefined') {
file.uid = _this.getCount();
}
if (Array.isArray(beforeUploadRes)) {
localFileList = beforeUploadRes;
if (typeof item.status === 'undefined') {
file.status = 'done';
}
return [3 /*break*/, 8];
case 7:
err_3 = _a.sent();
return [2 /*return*/];
case 8:
tasks = localFileList.map(function (file) { return uploadFile(file); });
return [4 /*yield*/, Promise.all(tasks)];
case 9:
_a.sent();
return [2 /*return*/];
}
});
}); });
useEvent('onRemove', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var uid, file, result, tempFileList;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
uid = e.currentTarget.dataset.uid;
file = fileList.find(function (item) { return item.uid === uid; });
if (!(props.onRemove && typeof props.onRemove === 'function')) return [3 /*break*/, 2];
return [4 /*yield*/, props.onRemove(file)];
case 1:
result = _a.sent();
if (result === false) {
return [2 /*return*/];
}
_a.label = 2;
case 2:
tempFileList = fileList.filter(function (item) { return item.uid !== uid; });
if (!isControlled) {
update(tempFileList);
}
triggerEvent('change', tempFileList);
return [2 /*return*/];
}
});
}); });
useEvent('onPreview', function (e) {
var uid = e.currentTarget.dataset.uid;
var file = fileList.find(function (item) { return item.uid === uid; });
triggerEvent('preview', file);
});
useEvent('update', function (e) {
if (isControlled) {
return;
return file;
}),
};
},
}),
], {
didMount: function () {
this.updateShowUploadButton();
},
didUpdate: function (prevProps, prevData) {
if (!this.isEqualValue(prevData)) {
this.updateShowUploadButton();
}
update(e);
});
return {
mixin: {
value: fileList,
},
};
};
mountComponent(ImageUpload, UploaderFunctionalProps);
},
});

@@ -75,8 +75,7 @@ import { IBaseProps } from '../_util/base';

/**
* @description 上传失败文案
* @default "上传失败"
*/
* @description 上传失败文案
* @default "上传失败"
*/
uploadfailedText?: string;
}
export declare const UploaderDefaultProps: Partial<IUploaderProps>;
export declare const UploaderFunctionalProps: Partial<IUploaderProps>;
export var UploaderDefaultProps = {
defaultFileList: [],
imageMode: 'scaleToFill',
sourceType: ['camera', 'album'],
};
export var UploaderFunctionalProps = {
defaultFileList: [],
fileList: null,

@@ -16,3 +11,3 @@ maxCount: null,

uploadingText: '上传中',
uploadfailedText: '上传失败'
uploadfailedText: '上传失败',
};

@@ -135,3 +135,3 @@ function getColumnValue(columnItem) {

var selectedIndex = [];
var value = realValue;
var value = realValue || [];
if (sinefileRef.current) {

@@ -138,0 +138,0 @@ value = [realValue];

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};

@@ -1,30 +0,17 @@

import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
var Radio = function (props) {
var _a = useMixState(props.defaultChecked, {
value: props.checked,
}), radioValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
import { Component, triggerEvent } from '../_util/simply';
import { RadioDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(RadioDefaultProps, {
onChange: function (e) {
var value = e.detail.value;
if (!isControlled) {
update(value);
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', value, e);
});
return {
mixin: {
value: radioValue,
},
};
};
mountComponent(Radio, {
value: null,
defaultChecked: null,
color: '',
checked: null,
disabled: false,
});
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

@@ -1,1 +0,7 @@

export var RadioDefaultProps = {};
export var RadioDefaultProps = {
value: null,
defaultChecked: null,
color: '',
checked: null,
disabled: false,
};

@@ -1,25 +0,16 @@

import { RadioGroupFunctionalProps } from './props';
import { mountComponent } from '../../_util/component';
import { useMixState } from '../../_util/hooks/useMixState';
import { useEvent } from 'functional-mini/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
var RadioGroup = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (_, e) {
var index = e.currentTarget.dataset.index;
var value = props.options[index].value;
if (!isControlled) {
update(value);
import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
import { RadioGroupDefaultProps } from './props';
import mixinValue from '../../mixins/value';
Component(RadioGroupDefaultProps, {
onChange: function (_, e) {
var event;
event = e;
var index = event.currentTarget.dataset.index;
var options = getValueFromProps(this, 'options');
var value = options[index].value;
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', value, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(RadioGroup, RadioGroupFunctionalProps);
triggerEvent(this, 'change', value, event);
},
}, null, [mixinValue()]);

@@ -18,2 +18,1 @@ import { IBaseProps } from '../../_util/base';

export declare const RadioGroupDefaultProps: Partial<IRadioGroupProps>;
export declare const RadioGroupFunctionalProps: Partial<IRadioGroupProps>;
export var RadioGroupDefaultProps = {
options: [],
position: 'vertical',
};
export var RadioGroupFunctionalProps = {
value: null,

@@ -7,0 +3,0 @@ defaultValue: null,

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};
import { __assign, __awaiter, __generator } from "tslib";
import { useComponent, useEvent, useRef, useState, } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { RateDefaultProps } from './props';
import createValue from '../mixins/value';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
import { RateFunctionalProps } from './props';
var Rate = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
postState: function (value) {
if (props.allowHalf) {
return {
valid: true,
value: value % 0.5 !== 0 ? Math.round(value) : value,
};
}
return {
valid: true,
value: Math.ceil(value),
};
},
}), rateValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
var _c = useState(null), displayValue = _c[0], setDisplayValue = _c[1];
var ref = useRef(null);
var instance = useComponent();
function getInstance() {
if (instance.$id) {
Component(RateDefaultProps, {
getInstance: function () {
if (this.$id) {
return my;
}
return instance;
}
function getRate(clientX) {
return this;
},
getRate: function (clientX) {
return __awaiter(this, void 0, void 0, function () {
var gutter, count, _a, left, width, halfRateWidth, num, halfRateCount, val, rate;
return __generator(this, function (_b) {
switch (_b.label) {
var _a, gutter, count, allowHalf, _b, left, width, halfRateWidth, num, halfRateCount, val, rate;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
gutter = props.gutter, count = props.count;
return [4 /*yield*/, getInstanceBoundingClientRect(getInstance(), "#ant-rate-container".concat(instance.$id ? "-".concat(instance.$id) : ''))];
_a = getValueFromProps(this, [
'gutter',
'count',
'allowHalf',
]), gutter = _a[0], count = _a[1], allowHalf = _a[2];
return [4 /*yield*/, getInstanceBoundingClientRect(this.getInstance(), "#ant-rate-container".concat(this.$id ? "-".concat(this.$id) : ''))];
case 1:
_a = _b.sent(), left = _a.left, width = _a.width;
_b = _c.sent(), left = _b.left, width = _b.width;
halfRateWidth = (width - (count - 1) * gutter) / count / 2;

@@ -50,3 +32,4 @@ num = clientX - left;

while (true) {
val = halfRateWidth * halfRateCount + gutter * Math.floor(halfRateCount / 2);
val = halfRateWidth * halfRateCount +
gutter * Math.floor(halfRateCount / 2);
if (halfRateCount >= count * 2 || num <= val) {

@@ -57,3 +40,3 @@ break;

}
rate = props.allowHalf
rate = allowHalf
? halfRateCount * 0.5

@@ -65,86 +48,103 @@ : Math.ceil(halfRateCount * 0.5);

});
}
useEvent('handleStarTap', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var _a, clientX, x, clickX, rate;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (props.readonly) {
},
handleStarTap: function (e) {
return __awaiter(this, void 0, void 0, function () {
var _a, readonly, allowClear, _b, clientX, x, clickX, rateValue, rate;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = getValueFromProps(this, [
'readonly',
'allowClear',
]), readonly = _a[0], allowClear = _a[1];
if (readonly) {
return [2 /*return*/];
}
_b = e.detail, clientX = _b.clientX, x = _b.x;
clickX = typeof x === 'number' ? x : clientX;
rateValue = this.getValue();
return [4 /*yield*/, this.getRate(clickX)];
case 1:
rate = _c.sent();
if (rateValue === rate && allowClear) {
rate = 0;
}
if (!this.isControlled()) {
this.update(rate);
}
if (rateValue !== rate) {
triggerEvent(this, 'change', rate);
}
return [2 /*return*/];
}
_a = e.detail, clientX = _a.clientX, x = _a.x;
clickX = typeof x === 'number' ? x : clientX;
return [4 /*yield*/, getRate(clickX)];
case 1:
rate = _b.sent();
if (rateValue === rate && props.allowClear) {
rate = 0;
}
if (!isControlled) {
update(rate);
}
if (rateValue !== rate) {
triggerEvent('change', rate);
}
return [2 /*return*/];
}
}
});
});
}); });
useEvent('handleStarMove', function (e) { return __awaiter(void 0, void 0, void 0, function () {
var touches, clientX, rate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (props.readonly) {
return [2 /*return*/];
}
touches = e.touches;
clientX = touches[0].clientX;
if (!ref.current) {
ref.current = {
originalRate: rateValue,
};
}
return [4 /*yield*/, getRate(clientX)];
case 1:
rate = _a.sent();
if (ref.current) {
ref.current = __assign(__assign({}, ref.current), { currentRate: rate });
if (isControlled) {
setDisplayValue(rate);
},
handleStarMove: function (e) {
return __awaiter(this, void 0, void 0, function () {
var readonly, touches, clientX, rate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
readonly = getValueFromProps(this, ['readonly'])[0];
if (readonly) {
return [2 /*return*/];
}
else {
update(rate);
touches = e.touches;
clientX = touches[0].clientX;
if (!this.moveRate) {
this.moveRate = {
originalRate: this.getValue(),
};
}
}
return [2 /*return*/];
}
return [4 /*yield*/, this.getRate(clientX)];
case 1:
rate = _a.sent();
if (this.moveRate) {
this.moveRate = __assign(__assign({}, this.moveRate), { currentRate: rate });
if (this.isControlled()) {
this.setData({ displayValue: rate });
}
else {
this.update(rate);
}
}
return [2 /*return*/];
}
});
});
}); });
useEvent('handleStarMoveEnd', function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, currentRate, originalRate;
return __generator(this, function (_b) {
if (props.readonly) {
return [2 /*return*/];
},
handleStarMoveEnd: function () {
var readonly = getValueFromProps(this, 'readonly');
if (readonly) {
return;
}
if (!this.moveRate) {
return;
}
var _a = this.moveRate, currentRate = _a.currentRate, originalRate = _a.originalRate;
this.moveRate = null;
if (this.isControlled()) {
this.setData({ displayValue: null });
}
if (currentRate !== originalRate) {
triggerEvent(this, 'change', currentRate);
}
},
}, { displayValue: null }, [
createValue({
transformValue: function (value) {
var allowHalf = getValueFromProps(this, 'allowHalf');
if (allowHalf) {
return {
needUpdate: true,
value: value % 0.5 !== 0 ? Math.round(value) : value,
};
}
if (!ref.current) {
return [2 /*return*/];
}
_a = ref.current, currentRate = _a.currentRate, originalRate = _a.originalRate;
ref.current = null;
if (isControlled) {
setDisplayValue(null);
}
if (currentRate !== originalRate) {
triggerEvent('change', currentRate);
}
return [2 /*return*/];
});
}); });
return {
mixin: {
value: displayValue !== null ? displayValue : rateValue,
return {
needUpdate: true,
value: Math.ceil(value),
};
},
};
};
mountComponent(Rate, RateFunctionalProps);
}),
]);

@@ -45,2 +45,1 @@ import { IBaseProps } from '../_util/base';

export declare const RateDefaultProps: Partial<IRateProps>;
export declare const RateFunctionalProps: Partial<IRateProps>;
export var RateDefaultProps = {
count: 5,
gutter: 4,
allowClear: true,
};
export var RateFunctionalProps = {
value: null,

@@ -8,0 +3,0 @@ defaultValue: null,

@@ -1,1 +0,1 @@

import '../_util/assert-component2';
export {};
import { __spreadArray } from "tslib";
import { useEvent } from 'functional-mini/component';
import '../_util/assert-component2';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { SelectorFunctionalProps } from './props';
var Selector = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
}), selectorValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEventValues = useComponentEvent(props).triggerEventValues;
useEvent('onChange', function (e) {
import { Component, triggerEventValues, getValueFromProps, } from '../_util/simply';
import { SelectorDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(SelectorDefaultProps, {
onChange: function (e) {
var _a = e.currentTarget.dataset, disabled = _a.disabled, value = _a.value;
var multiple = props.multiple, options = props.options, maxSelectedCount = props.maxSelectedCount, minSelectedCount = props.minSelectedCount;
if (disabled || props.disabled) {
var _b = getValueFromProps(this, [
'multiple',
'options',
'maxSelectedCount',
'minSelectedCount',
'disabled',
]), multiple = _b[0], options = _b[1], maxSelectedCount = _b[2], minSelectedCount = _b[3], disabledFromProps = _b[4];
if (disabled || disabledFromProps) {
return;
}
if (multiple) {
var currentValue_1 = selectorValue || [];
var currentValue_1 = this.getValue() || [];
if (currentValue_1.indexOf(value) > -1) {
if (typeof minSelectedCount === 'number' &&
currentValue_1.length <= minSelectedCount) {
triggerEventValues('selectMin', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMin', [value, options.find(function (v) { return v.value === value; })], e);
return;

@@ -32,3 +31,3 @@ }

currentValue_1.length >= maxSelectedCount) {
triggerEventValues('selectMax', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMax', [value, options.find(function (v) { return v.value === value; })], e);
return;

@@ -38,6 +37,6 @@ }

}
if (!isControlled) {
update(currentValue_1);
if (!this.isControlled()) {
this.update(currentValue_1);
}
triggerEventValues('change', [
triggerEventValues(this, 'change', [
currentValue_1,

@@ -48,26 +47,20 @@ options.filter(function (v) { return currentValue_1.indexOf(v.value) > -1; }),

else {
if (value === selectorValue) {
if (value === this.getValue()) {
if (minSelectedCount === 1) {
triggerEventValues('selectMin', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'selectMin', [value, options.find(function (v) { return v.value === value; })], e);
return;
}
if (!isControlled) {
update(undefined);
if (!this.isControlled()) {
this.update(undefined);
}
triggerEventValues('change', [undefined, undefined], e);
triggerEventValues(this, 'change', [undefined, undefined], e);
}
else {
if (!isControlled) {
update(value);
if (!this.isControlled()) {
this.update(value);
}
triggerEventValues('change', [value, options.find(function (v) { return v.value === value; })], e);
triggerEventValues(this, 'change', [value, options.find(function (v) { return v.value === value; })], e);
}
}
});
return {
mixin: {
value: selectorValue,
},
};
};
mountComponent(Selector, SelectorFunctionalProps);
},
}, null, [mixinValue()]);

@@ -70,2 +70,1 @@ import { IBaseProps } from '../_util/base';

export declare const SelectorDefaultProps: Partial<ISelectorProps>;
export declare const SelectorFunctionalProps: Partial<ISelectorProps>;
export var SelectorDefaultProps = {
multiple: false,
disabled: false,
};
export var SelectorFunctionalProps = {
value: null,

@@ -7,0 +3,0 @@ defaultValue: null,

@@ -1,22 +0,17 @@

import { mountComponent } from '../_util/component';
import { useMergedState, hasValue } from '../_util/hooks/useMergedState';
import { SwitchFunctionalProps } from './props';
import { useEvent } from 'functional-mini/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
var Switch = function (props) {
var _a = useMergedState(props.defaultChecked, {
value: props.checked,
}), value = _a[0], updateValue = _a[1];
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
var newValue = !value;
if (!hasValue(props.checked)) {
updateValue(newValue);
import { Component, triggerEvent } from '../_util/simply';
import { SwitchDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(SwitchDefaultProps, {
onChange: function (e) {
var value = !this.getValue();
if (!this.isControlled()) {
this.update(value);
}
triggerEvent('change', newValue, e);
});
return {
mixin: { value: value },
};
};
mountComponent(Switch, SwitchFunctionalProps);
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

@@ -45,2 +45,1 @@ import { IBaseProps } from '../_util/base';

export declare const SwitchDefaultProps: Partial<ISwitchProps>;
export declare const SwitchFunctionalProps: Partial<ISwitchProps>;
export var SwitchDefaultProps = {
size: 'medium',
};
export var SwitchFunctionalProps = {
checked: null,

@@ -6,0 +3,0 @@ loading: false,

@@ -1,27 +0,20 @@

import { useEvent } from 'functional-mini/component';
import { mountComponent } from '../_util/component';
import { useComponentEvent } from '../_util/hooks/useComponentEvent';
import { useMixState } from '../_util/hooks/useMixState';
import { TabBarFunctionalProps } from './props';
var TabBar = function (props) {
var _a = useMixState(props.defaultCurrent, {
value: props.current,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
import { TabBarDefaultProps } from './props';
import { Component, triggerEvent } from '../_util/simply';
import mixinValue from '../mixins/value';
Component(TabBarDefaultProps, {
onChange: function (e) {
var index = e.currentTarget.dataset.index;
if (index === value) {
if (index === this.getValue()) {
return;
}
if (!isControlled) {
update(index);
if (!this.isControlled()) {
this.update(index);
}
triggerEvent('change', index, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(TabBar, TabBarFunctionalProps);
triggerEvent(this, 'change', index, e);
},
}, null, [
mixinValue({
valueKey: 'current',
defaultValueKey: 'defaultCurrent',
}),
]);

@@ -56,2 +56,1 @@ import { IBaseProps } from '../_util/base';

export declare const TabBarDefaultProps: Partial<ITabBarProps>;
export declare const TabBarFunctionalProps: Partial<ITabBarProps>;
export var TabBarDefaultProps = {
items: [],
defaultCurrent: 0,
};
export var TabBarFunctionalProps = {
items: [],
current: null,

@@ -8,0 +4,0 @@ defaultCurrent: 0,

{
"name": "antd-mini",
"version": "2.30.2",
"version": "2.31.0",
"description": "antd-mini 是支付宝小程序 UI 组件库,遵循 Ant Design 规范。",

@@ -5,0 +5,0 @@ "miniprogram": "compiled/wechat/src",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc