@tarojs/components 3.5.5 → 3.5.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/cjs/taro-input-core.cjs.entry.js +24 -3
  2. package/dist/cjs/taro-video-control_3.cjs.entry.js +21 -3
  3. package/dist/collection/components/input/input.js +24 -3
  4. package/dist/collection/components/video/video.js +23 -3
  5. package/dist/collection/utils/json-schema-to-types.js +224 -0
  6. package/dist/esm/taro-input-core.entry.js +24 -3
  7. package/dist/esm/taro-video-control_3.entry.js +21 -3
  8. package/dist/esm-es5/taro-input-core.entry.js +1 -1
  9. package/dist/esm-es5/taro-video-control_3.entry.js +1 -1
  10. package/dist/taro-components/p-0380841f.system.js +1 -1
  11. package/dist/taro-components/p-232ebfae.system.entry.js +1 -0
  12. package/dist/taro-components/{p-7e8943d8.entry.js → p-3744e978.entry.js} +1 -1
  13. package/dist/taro-components/p-56c86512.entry.js +1 -0
  14. package/dist/taro-components/{p-ed8c1bb8.system.entry.js → p-f81a74bb.system.entry.js} +1 -1
  15. package/dist/taro-components/taro-components.esm.js +1 -1
  16. package/dist/types/components/input/input.d.ts +1 -0
  17. package/dist/types/utils/json-schema-to-types.d.ts +25 -0
  18. package/dist-h5/react/components/index.js +5 -5
  19. package/package.json +9 -5
  20. package/types/Ad.d.ts +99 -9
  21. package/types/AdCustom.d.ts +1 -3
  22. package/types/Audio.d.ts +16 -16
  23. package/types/Block.d.ts +0 -2
  24. package/types/Button.d.ts +187 -47
  25. package/types/Camera.d.ts +20 -18
  26. package/types/Canvas.d.ts +52 -13
  27. package/types/Checkbox.d.ts +13 -10
  28. package/types/CheckboxGroup.d.ts +5 -7
  29. package/types/CoverImage.d.ts +44 -5
  30. package/types/CoverView.d.ts +34 -10
  31. package/types/Editor.d.ts +4 -6
  32. package/types/Form.d.ts +23 -7
  33. package/types/FunctionalPageNavigator.d.ts +5 -3
  34. package/types/Icon.d.ts +19 -7
  35. package/types/Image.d.ts +71 -14
  36. package/types/Input.d.ts +44 -33
  37. package/types/Label.d.ts +0 -3
  38. package/types/LivePlayer.d.ts +80 -24
  39. package/types/LivePusher.d.ts +78 -37
  40. package/types/Map.d.ts +208 -66
  41. package/types/MatchMedia.d.ts +8 -10
  42. package/types/MovableArea.d.ts +1 -3
  43. package/types/MovableView.d.ts +88 -30
  44. package/types/NavigationBar.d.ts +0 -2
  45. package/types/Navigator.d.ts +35 -18
  46. package/types/OfficialAccount.d.ts +10 -3
  47. package/types/OpenData.d.ts +35 -6
  48. package/types/PageContainer.d.ts +13 -10
  49. package/types/PageMeta.d.ts +27 -13
  50. package/types/Picker.d.ts +50 -14
  51. package/types/PickerView.d.ts +31 -13
  52. package/types/PickerViewColumn.d.ts +0 -2
  53. package/types/Progress.d.ts +17 -14
  54. package/types/Radio.d.ts +16 -6
  55. package/types/RadioGroup.d.ts +6 -4
  56. package/types/RichText.d.ts +53 -5
  57. package/types/RootPortal.d.ts +2 -1
  58. package/types/ScrollView.d.ts +82 -19
  59. package/types/ShareElement.d.ts +5 -7
  60. package/types/Slider.d.ts +41 -17
  61. package/types/Swiper.d.ts +100 -22
  62. package/types/SwiperItem.d.ts +6 -3
  63. package/types/Switch.d.ts +22 -8
  64. package/types/Text.d.ts +10 -6
  65. package/types/Textarea.d.ts +61 -28
  66. package/types/Video.d.ts +331 -50
  67. package/types/View.d.ts +122 -9
  68. package/types/VoipRoom.d.ts +6 -9
  69. package/types/WebView.d.ts +9 -7
  70. package/types/common.d.ts +1 -1
  71. package/types/index.vue3.d.ts +261 -138
  72. package/dist/taro-components/p-1b356f4d.entry.js +0 -1
  73. package/dist/taro-components/p-a39276ff.system.entry.js +0 -1
@@ -51,7 +51,7 @@ let Input = class {
51
51
  const inputType = getTrueType(type, confirmType, password);
52
52
  this.onInputExcuted = true;
53
53
  /* 修复 number 类型 maxlength 无效 */
54
- if (inputType === 'number' && value && maxlength <= value.length) {
54
+ if (inputType === 'number' && value && maxlength > -1 && maxlength <= value.length) {
55
55
  value = value.substring(0, maxlength);
56
56
  e.target.value = value;
57
57
  }
@@ -131,6 +131,19 @@ let Input = class {
131
131
  this.isOnComposition = true;
132
132
  }
133
133
  };
134
+ this.handleBeforeinput = (e) => {
135
+ if (!e.data)
136
+ return;
137
+ const isNumber = e.data && /[0-9]/.test(e.data);
138
+ if (this.type === 'number' && !isNumber) {
139
+ e.preventDefault();
140
+ }
141
+ if (this.type === 'digit' && !isNumber) {
142
+ if (e.data !== '.' || (e.data === '.' && e.target.value.indexOf('.') > -1)) {
143
+ e.preventDefault();
144
+ }
145
+ }
146
+ };
134
147
  }
135
148
  watchFocus(newValue, oldValue) {
136
149
  var _a;
@@ -145,7 +158,7 @@ let Input = class {
145
158
  }
146
159
  }
147
160
  componentDidLoad() {
148
- var _a, _b, _c;
161
+ var _a, _b, _c, _d, _e;
149
162
  if (this.type === 'file') {
150
163
  this.fileListener = () => {
151
164
  this.onInput.emit();
@@ -155,6 +168,8 @@ let Input = class {
155
168
  else {
156
169
  (_b = this.inputRef) === null || _b === void 0 ? void 0 : _b.addEventListener('compositionstart', this.handleComposition);
157
170
  (_c = this.inputRef) === null || _c === void 0 ? void 0 : _c.addEventListener('compositionend', this.handleComposition);
171
+ (_d = this.inputRef) === null || _d === void 0 ? void 0 : _d.addEventListener('beforeinput', this.handleBeforeinput);
172
+ (_e = this.inputRef) === null || _e === void 0 ? void 0 : _e.addEventListener('textInput', this.handleBeforeinput);
158
173
  }
159
174
  Object.defineProperty(this.el, 'value', {
160
175
  get: () => { var _a; return (_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.value; },
@@ -163,10 +178,16 @@ let Input = class {
163
178
  });
164
179
  }
165
180
  disconnectedCallback() {
166
- var _a;
181
+ var _a, _b, _c, _d, _e;
167
182
  if (this.type === 'file') {
168
183
  (_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.removeEventListener('change', this.fileListener);
169
184
  }
185
+ else {
186
+ (_b = this.inputRef) === null || _b === void 0 ? void 0 : _b.removeEventListener('compositionstart', this.handleComposition);
187
+ (_c = this.inputRef) === null || _c === void 0 ? void 0 : _c.removeEventListener('compositionend', this.handleComposition);
188
+ (_d = this.inputRef) === null || _d === void 0 ? void 0 : _d.removeEventListener('beforeinput', this.handleBeforeinput);
189
+ (_e = this.inputRef) === null || _e === void 0 ? void 0 : _e.removeEventListener('textInput', this.handleBeforeinput);
190
+ }
170
191
  }
171
192
  render() {
172
193
  const { value, type, password, placeholder, autoFocus, disabled, maxlength, confirmType, name, nativeProps } = this;
@@ -28008,6 +28008,9 @@ let Video = class {
28008
28008
  this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
28009
28009
  this.autoplay && this.play();
28010
28010
  });
28011
+ this.hls.on(Hls.Events.ERROR, (_, data) => {
28012
+ this.handleError(data);
28013
+ });
28011
28014
  }
28012
28015
  else if (videoRef.canPlayType('application/vnd.apple.mpegurl')) {
28013
28016
  this.loadNativePlayer();
@@ -28062,9 +28065,24 @@ let Video = class {
28062
28065
  }), 250);
28063
28066
  this.handleError = e => {
28064
28067
  var _a, _b;
28065
- this.onError.emit({
28066
- errMsg: (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message
28067
- });
28068
+ if (this.hls) {
28069
+ switch (e.type) {
28070
+ case Hls.ErrorTypes.NETWORK_ERROR:
28071
+ // try to recover network error
28072
+ this.onError.emit({ errMsg: e.response });
28073
+ this.hls.startLoad();
28074
+ break;
28075
+ case Hls.ErrorTypes.MEDIA_ERROR:
28076
+ this.onError.emit({ errMsg: e.reason || '媒体错误,请重试' });
28077
+ this.hls.recoverMediaError();
28078
+ break;
28079
+ }
28080
+ }
28081
+ else {
28082
+ this.onError.emit({
28083
+ errMsg: (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message,
28084
+ });
28085
+ }
28068
28086
  };
28069
28087
  this.handleDurationChange = () => {
28070
28088
  this._duration = this.videoRef.duration;
@@ -36,7 +36,7 @@ export class Input {
36
36
  const inputType = getTrueType(type, confirmType, password);
37
37
  this.onInputExcuted = true;
38
38
  /* 修复 number 类型 maxlength 无效 */
39
- if (inputType === 'number' && value && maxlength <= value.length) {
39
+ if (inputType === 'number' && value && maxlength > -1 && maxlength <= value.length) {
40
40
  value = value.substring(0, maxlength);
41
41
  e.target.value = value;
42
42
  }
@@ -116,6 +116,19 @@ export class Input {
116
116
  this.isOnComposition = true;
117
117
  }
118
118
  };
119
+ this.handleBeforeinput = (e) => {
120
+ if (!e.data)
121
+ return;
122
+ const isNumber = e.data && /[0-9]/.test(e.data);
123
+ if (this.type === 'number' && !isNumber) {
124
+ e.preventDefault();
125
+ }
126
+ if (this.type === 'digit' && !isNumber) {
127
+ if (e.data !== '.' || (e.data === '.' && e.target.value.indexOf('.') > -1)) {
128
+ e.preventDefault();
129
+ }
130
+ }
131
+ };
119
132
  }
120
133
  watchFocus(newValue, oldValue) {
121
134
  var _a;
@@ -130,7 +143,7 @@ export class Input {
130
143
  }
131
144
  }
132
145
  componentDidLoad() {
133
- var _a, _b, _c;
146
+ var _a, _b, _c, _d, _e;
134
147
  if (this.type === 'file') {
135
148
  this.fileListener = () => {
136
149
  this.onInput.emit();
@@ -140,6 +153,8 @@ export class Input {
140
153
  else {
141
154
  (_b = this.inputRef) === null || _b === void 0 ? void 0 : _b.addEventListener('compositionstart', this.handleComposition);
142
155
  (_c = this.inputRef) === null || _c === void 0 ? void 0 : _c.addEventListener('compositionend', this.handleComposition);
156
+ (_d = this.inputRef) === null || _d === void 0 ? void 0 : _d.addEventListener('beforeinput', this.handleBeforeinput);
157
+ (_e = this.inputRef) === null || _e === void 0 ? void 0 : _e.addEventListener('textInput', this.handleBeforeinput);
143
158
  }
144
159
  Object.defineProperty(this.el, 'value', {
145
160
  get: () => { var _a; return (_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.value; },
@@ -148,10 +163,16 @@ export class Input {
148
163
  });
149
164
  }
150
165
  disconnectedCallback() {
151
- var _a;
166
+ var _a, _b, _c, _d, _e;
152
167
  if (this.type === 'file') {
153
168
  (_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.removeEventListener('change', this.fileListener);
154
169
  }
170
+ else {
171
+ (_b = this.inputRef) === null || _b === void 0 ? void 0 : _b.removeEventListener('compositionstart', this.handleComposition);
172
+ (_c = this.inputRef) === null || _c === void 0 ? void 0 : _c.removeEventListener('compositionend', this.handleComposition);
173
+ (_d = this.inputRef) === null || _d === void 0 ? void 0 : _d.removeEventListener('beforeinput', this.handleBeforeinput);
174
+ (_e = this.inputRef) === null || _e === void 0 ? void 0 : _e.removeEventListener('textInput', this.handleBeforeinput);
175
+ }
155
176
  }
156
177
  render() {
157
178
  const { value, type, password, placeholder, autoFocus, disabled, maxlength, confirmType, name, nativeProps } = this;
@@ -154,6 +154,9 @@ export class Video {
154
154
  this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
155
155
  this.autoplay && this.play();
156
156
  });
157
+ this.hls.on(Hls.Events.ERROR, (_, data) => {
158
+ this.handleError(data);
159
+ });
157
160
  }
158
161
  else if (videoRef.canPlayType('application/vnd.apple.mpegurl')) {
159
162
  this.loadNativePlayer();
@@ -208,9 +211,26 @@ export class Video {
208
211
  }), 250);
209
212
  this.handleError = e => {
210
213
  var _a, _b;
211
- this.onError.emit({
212
- errMsg: (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message
213
- });
214
+ if (this.hls) {
215
+ switch (e.type) {
216
+ case Hls.ErrorTypes.NETWORK_ERROR:
217
+ // try to recover network error
218
+ this.onError.emit({ errMsg: e.response });
219
+ this.hls.startLoad();
220
+ break;
221
+ case Hls.ErrorTypes.MEDIA_ERROR:
222
+ this.onError.emit({ errMsg: e.reason || '媒体错误,请重试' });
223
+ this.hls.recoverMediaError();
224
+ break;
225
+ default:
226
+ break;
227
+ }
228
+ }
229
+ else {
230
+ this.onError.emit({
231
+ errMsg: (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message,
232
+ });
233
+ }
214
234
  };
215
235
  this.handleDurationChange = () => {
216
236
  this._duration = this.videoRef.duration;
@@ -0,0 +1,224 @@
1
+ import generator from '@babel/generator';
2
+ import * as parser from '@babel/parser';
3
+ import traverse from '@babel/traverse';
4
+ import * as t from '@babel/types';
5
+ import * as fs from 'fs';
6
+ import * as humps from 'humps';
7
+ import { flattenDeep, isEmpty, toArray, xorWith } from 'lodash';
8
+ import * as path from 'path';
9
+ import { format as prettify } from 'prettier';
10
+ const MINI_APP_TYPES = ['weapp', 'alipay', 'swan', 'tt', 'qq', 'jd'];
11
+ const OMIT_PROPS = ['generic:simple-component'];
12
+ class GenerateTypes {
13
+ constructor(componentName) {
14
+ this.jsonSchemas = {};
15
+ this.componentName = componentName;
16
+ MINI_APP_TYPES.forEach((type) => {
17
+ try {
18
+ const json = require(`miniapp-types/dist/schema/${type}/${componentName === 'AD' ? 'ad' : humps.decamelize(componentName, { separator: '-' })}.json`);
19
+ if (!json) {
20
+ return;
21
+ }
22
+ if (!this.jsonSchemas[componentName]) {
23
+ this.jsonSchemas[componentName] = {};
24
+ }
25
+ this.jsonSchemas[componentName][type] = json;
26
+ }
27
+ catch (error) {
28
+ // console.log(error)
29
+ if (!this.jsonSchemas[componentName]) {
30
+ this.jsonSchemas[componentName] = {};
31
+ }
32
+ }
33
+ });
34
+ }
35
+ // 获取不存在的属性
36
+ getMissingProps(props) {
37
+ const obj = {};
38
+ const jsonSchema = this.jsonSchemas[this.componentName];
39
+ if (!jsonSchema) {
40
+ return obj;
41
+ }
42
+ Object.keys(this.jsonSchemas[this.componentName]).forEach((key) => {
43
+ const filteredList = xorWith(props[key], Object.keys(this.jsonSchemas[this.componentName][key].properties));
44
+ if (filteredList.length > 0) {
45
+ obj[key] = filteredList.map((item) => item.match(/^bind/) ? humps.camelize(item.replace(/^bind/, 'on')) : item);
46
+ }
47
+ });
48
+ return obj;
49
+ }
50
+ // 转换不存在的属性,便于添加到已有的类型声明中
51
+ convertProps(props) {
52
+ const array = [...new Set(flattenDeep(toArray(props)))];
53
+ const reverseProps = {};
54
+ array.forEach((prop) => {
55
+ reverseProps[prop] = Object.keys(props).filter((key) => props[key].includes(prop));
56
+ });
57
+ return reverseProps;
58
+ }
59
+ updateComment(ast) {
60
+ const componentName = this.componentName;
61
+ const jsonSchemas = this.jsonSchemas[this.componentName];
62
+ const existProps = {};
63
+ traverse(ast, {
64
+ TSInterfaceDeclaration(astPath) {
65
+ if (astPath.node.id.name !== `${componentName}Props`) {
66
+ return;
67
+ }
68
+ astPath.traverse({
69
+ TSPropertySignature(astPath) {
70
+ var _a, _b, _c, _d;
71
+ const { name } = astPath.node.key;
72
+ if (!name) {
73
+ return;
74
+ }
75
+ const supportedPlatforms = [];
76
+ const covertedName = name.match(/^on/)
77
+ ? name.replace(/^on/, 'bind')
78
+ : humps.decamelize(name, { separator: '-' });
79
+ MINI_APP_TYPES.forEach((type) => {
80
+ var _a, _b, _c, _d;
81
+ if ((_a = jsonSchemas[type]) === null || _a === void 0 ? void 0 : _a.properties[name]) {
82
+ if (isEmpty(existProps[type])) {
83
+ existProps[type] = [name];
84
+ }
85
+ (_b = existProps[type]) === null || _b === void 0 ? void 0 : _b.push(name);
86
+ supportedPlatforms.push(type);
87
+ }
88
+ if (name !== covertedName && ((_c = jsonSchemas[type]) === null || _c === void 0 ? void 0 : _c.properties[covertedName])) {
89
+ if (isEmpty(existProps[type])) {
90
+ existProps[type] = [covertedName];
91
+ }
92
+ (_d = existProps[type]) === null || _d === void 0 ? void 0 : _d.push(covertedName);
93
+ supportedPlatforms.push(type);
94
+ }
95
+ });
96
+ if (isEmpty(astPath.node.leadingComments) || !((_b = (_a = astPath.node.leadingComments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value)) {
97
+ return;
98
+ }
99
+ const value = (_d = (_c = astPath.node.leadingComments) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.value;
100
+ // 保留原有 h5 类型
101
+ if (value.toLowerCase().indexOf('h5') > -1) {
102
+ supportedPlatforms.push('h5');
103
+ }
104
+ // 保留原有 rn 类型
105
+ if (value.toLowerCase().indexOf('rn') > -1) {
106
+ supportedPlatforms.push('rn');
107
+ }
108
+ if (isEmpty(supportedPlatforms)) {
109
+ astPath.remove();
110
+ }
111
+ else {
112
+ astPath.node.leadingComments[0].value = value.replace(/@supported .*?\n/, `@supported ${supportedPlatforms.join(', ')}\n`);
113
+ if (value.match(/@deprecated/)) {
114
+ astPath.node.leadingComments[0].value = value.replace(/\* @deprecated.*?\n/, '');
115
+ }
116
+ }
117
+ },
118
+ });
119
+ },
120
+ });
121
+ return {
122
+ existProps,
123
+ ast,
124
+ };
125
+ }
126
+ // 添加不存在的属性
127
+ addProps(ast, props) {
128
+ const componentName = this.componentName;
129
+ const jsonSchemas = this.jsonSchemas[this.componentName];
130
+ traverse(ast, {
131
+ TSInterfaceDeclaration(astPath) {
132
+ if (astPath.node.id.name !== `${componentName}Props`) {
133
+ return;
134
+ }
135
+ const addedProps = [];
136
+ astPath.traverse({
137
+ TSInterfaceBody(astPath) {
138
+ Object.keys(props).forEach((prop) => {
139
+ var _a, _b, _c;
140
+ if (OMIT_PROPS.includes(prop)) {
141
+ return;
142
+ }
143
+ const node = t.cloneNode(astPath.node.body[0]);
144
+ node.key = t.identifier(humps.camelize(prop, { separator: '-' }));
145
+ const platform = props[prop][0];
146
+ const json = jsonSchemas[platform];
147
+ const propSchema = json.properties[prop] || json.properties[prop.replace(/^on/, 'bind')];
148
+ const { type, tsType, enum: enumArray } = propSchema;
149
+ let value;
150
+ if (type === 'string') {
151
+ if (!enumArray) {
152
+ value = t.tsTypeReference(t.identifier(type));
153
+ }
154
+ else {
155
+ value = t.tsUnionType(enumArray.map((item) => t.tsLiteralType(t.stringLiteral(item))));
156
+ }
157
+ }
158
+ else if (type instanceof Array) {
159
+ value = t.tsTypeReference(t.identifier(type.join('|')));
160
+ }
161
+ else if (tsType === '() => void') {
162
+ value = t.tsTypeReference(t.identifier('CommonEventFunction'));
163
+ }
164
+ else {
165
+ value = t.tsTypeReference(t.identifier('string'));
166
+ }
167
+ node.typeAnnotation = t.tsTypeAnnotation(value);
168
+ node.optional = !((_a = json.required) === null || _a === void 0 ? void 0 : _a[prop]) || !((_b = json.required) === null || _b === void 0 ? void 0 : _b[prop.replace(/^on/, 'bind')]);
169
+ if (node.leadingComments) {
170
+ let commentValue = `* ${(_c = propSchema.description) === null || _c === void 0 ? void 0 : _c.replace(/\n/g, '\n * ')} \n`;
171
+ commentValue += `* @supported ${props[prop].join(', ')}\n`;
172
+ const defaultValue = propSchema.defaultValue;
173
+ if (defaultValue) {
174
+ if (defaultValue instanceof Array) {
175
+ commentValue += `* @default ${propSchema.defaultValue.join(',')}\n`;
176
+ }
177
+ else {
178
+ commentValue += `* @default ${propSchema.defaultValue}\n`;
179
+ }
180
+ }
181
+ node.leadingComments[0].value = commentValue;
182
+ }
183
+ astPath.node.body.push(node);
184
+ addedProps.push(prop);
185
+ });
186
+ },
187
+ });
188
+ },
189
+ });
190
+ }
191
+ formatJSDoc(ast) {
192
+ traverse(ast, {
193
+ enter(astPath) {
194
+ if (astPath.node.trailingComments) {
195
+ astPath.node.trailingComments = [];
196
+ }
197
+ },
198
+ });
199
+ }
200
+ exec() {
201
+ const filePath = path.join(process.cwd(), 'types', `${this.componentName}.d.ts`);
202
+ const codeStr = fs.readFileSync(filePath, 'utf8');
203
+ const ast = parser.parse(codeStr, {
204
+ sourceType: 'module',
205
+ strictMode: false,
206
+ plugins: ['typescript'],
207
+ });
208
+ const { existProps } = this.updateComment(ast);
209
+ const missingProps = this.getMissingProps(existProps);
210
+ const props = this.convertProps(missingProps);
211
+ this.addProps(ast, props);
212
+ this.formatJSDoc(ast);
213
+ const result = generator(ast);
214
+ const code = prettify(result.code, { parser: 'typescript', singleQuote: true, semi: false });
215
+ fs.writeFileSync(filePath, code);
216
+ }
217
+ }
218
+ const typesFiles = fs.readdirSync(path.join(process.cwd(), 'types'));
219
+ typesFiles.forEach((fileName) => {
220
+ const componentName = fileName.replace(/\.d\.ts$/, '');
221
+ const generateTypes = new GenerateTypes(componentName);
222
+ generateTypes.exec();
223
+ });
224
+ export default GenerateTypes;
@@ -47,7 +47,7 @@ let Input = class {
47
47
  const inputType = getTrueType(type, confirmType, password);
48
48
  this.onInputExcuted = true;
49
49
  /* 修复 number 类型 maxlength 无效 */
50
- if (inputType === 'number' && value && maxlength <= value.length) {
50
+ if (inputType === 'number' && value && maxlength > -1 && maxlength <= value.length) {
51
51
  value = value.substring(0, maxlength);
52
52
  e.target.value = value;
53
53
  }
@@ -127,6 +127,19 @@ let Input = class {
127
127
  this.isOnComposition = true;
128
128
  }
129
129
  };
130
+ this.handleBeforeinput = (e) => {
131
+ if (!e.data)
132
+ return;
133
+ const isNumber = e.data && /[0-9]/.test(e.data);
134
+ if (this.type === 'number' && !isNumber) {
135
+ e.preventDefault();
136
+ }
137
+ if (this.type === 'digit' && !isNumber) {
138
+ if (e.data !== '.' || (e.data === '.' && e.target.value.indexOf('.') > -1)) {
139
+ e.preventDefault();
140
+ }
141
+ }
142
+ };
130
143
  }
131
144
  watchFocus(newValue, oldValue) {
132
145
  var _a;
@@ -141,7 +154,7 @@ let Input = class {
141
154
  }
142
155
  }
143
156
  componentDidLoad() {
144
- var _a, _b, _c;
157
+ var _a, _b, _c, _d, _e;
145
158
  if (this.type === 'file') {
146
159
  this.fileListener = () => {
147
160
  this.onInput.emit();
@@ -151,6 +164,8 @@ let Input = class {
151
164
  else {
152
165
  (_b = this.inputRef) === null || _b === void 0 ? void 0 : _b.addEventListener('compositionstart', this.handleComposition);
153
166
  (_c = this.inputRef) === null || _c === void 0 ? void 0 : _c.addEventListener('compositionend', this.handleComposition);
167
+ (_d = this.inputRef) === null || _d === void 0 ? void 0 : _d.addEventListener('beforeinput', this.handleBeforeinput);
168
+ (_e = this.inputRef) === null || _e === void 0 ? void 0 : _e.addEventListener('textInput', this.handleBeforeinput);
154
169
  }
155
170
  Object.defineProperty(this.el, 'value', {
156
171
  get: () => { var _a; return (_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.value; },
@@ -159,10 +174,16 @@ let Input = class {
159
174
  });
160
175
  }
161
176
  disconnectedCallback() {
162
- var _a;
177
+ var _a, _b, _c, _d, _e;
163
178
  if (this.type === 'file') {
164
179
  (_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.removeEventListener('change', this.fileListener);
165
180
  }
181
+ else {
182
+ (_b = this.inputRef) === null || _b === void 0 ? void 0 : _b.removeEventListener('compositionstart', this.handleComposition);
183
+ (_c = this.inputRef) === null || _c === void 0 ? void 0 : _c.removeEventListener('compositionend', this.handleComposition);
184
+ (_d = this.inputRef) === null || _d === void 0 ? void 0 : _d.removeEventListener('beforeinput', this.handleBeforeinput);
185
+ (_e = this.inputRef) === null || _e === void 0 ? void 0 : _e.removeEventListener('textInput', this.handleBeforeinput);
186
+ }
166
187
  }
167
188
  render() {
168
189
  const { value, type, password, placeholder, autoFocus, disabled, maxlength, confirmType, name, nativeProps } = this;
@@ -28004,6 +28004,9 @@ let Video = class {
28004
28004
  this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
28005
28005
  this.autoplay && this.play();
28006
28006
  });
28007
+ this.hls.on(Hls.Events.ERROR, (_, data) => {
28008
+ this.handleError(data);
28009
+ });
28007
28010
  }
28008
28011
  else if (videoRef.canPlayType('application/vnd.apple.mpegurl')) {
28009
28012
  this.loadNativePlayer();
@@ -28058,9 +28061,24 @@ let Video = class {
28058
28061
  }), 250);
28059
28062
  this.handleError = e => {
28060
28063
  var _a, _b;
28061
- this.onError.emit({
28062
- errMsg: (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message
28063
- });
28064
+ if (this.hls) {
28065
+ switch (e.type) {
28066
+ case Hls.ErrorTypes.NETWORK_ERROR:
28067
+ // try to recover network error
28068
+ this.onError.emit({ errMsg: e.response });
28069
+ this.hls.startLoad();
28070
+ break;
28071
+ case Hls.ErrorTypes.MEDIA_ERROR:
28072
+ this.onError.emit({ errMsg: e.reason || '媒体错误,请重试' });
28073
+ this.hls.recoverMediaError();
28074
+ break;
28075
+ }
28076
+ }
28077
+ else {
28078
+ this.onError.emit({
28079
+ errMsg: (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message,
28080
+ });
28081
+ }
28064
28082
  };
28065
28083
  this.handleDurationChange = () => {
28066
28084
  this._duration = this.videoRef.duration;
@@ -1 +1 @@
1
- import{r as registerInstance,c as createEvent,h,g as getElement}from"./index-8809c729.js";var indexCss="taro-input-core{display:block}input{display:block;overflow:hidden;height:1.4rem;text-overflow:clip;text-align:inherit;white-space:nowrap}";function getTrueType(e,t,n){if(t==="search")e="search";if(n)e="password";if(typeof e==="undefined"){return"text"}if(!e){throw new Error("unexpected type")}if(e==="digit")e="number";return e}function fixControlledValue(e){return e!==null&&e!==void 0?e:""}var Input=function(){function e(e){var t=this;registerInstance(this,e);this.onInput=createEvent(this,"input",7);this.onPaste=createEvent(this,"paste",7);this.onFocus=createEvent(this,"focus",7);this.onBlur=createEvent(this,"blur",7);this.onConfirm=createEvent(this,"confirm",7);this.onChange=createEvent(this,"change",7);this.onKeyDown=createEvent(this,"keydown",7);this.isOnComposition=false;this.isOnPaste=false;this.onInputExcuted=false;this.password=false;this.disabled=false;this.maxlength=140;this.autoFocus=false;this.confirmType="done";this.nativeProps={};this.handleInput=function(e){e.stopPropagation();var n=t,i=n.type,o=n.maxlength,a=n.confirmType,s=n.password;if(!t.isOnComposition&&!t.onInputExcuted){var u=e.target.value;var r=getTrueType(i,a,s);t.onInputExcuted=true;if(r==="number"&&u&&o<=u.length){u=u.substring(0,o);e.target.value=u}t.value=u;t.onInput.emit({value:u,cursor:u.length});t.onInputExcuted=false}};this.handlePaste=function(e){t.isOnPaste=true;t.onPaste.emit({value:e.target.value})};this.handleFocus=function(e){t.onInputExcuted=false;t.onFocus.emit({value:e.target.value})};this.handleBlur=function(e){t.onBlur.emit({value:e.target.value})};this.handleChange=function(e){e.stopPropagation();t.onChange.emit({value:e.target.value});if(t.isOnPaste){t.isOnPaste=false;t.value=e.target.value;t.onInput.emit({value:e.target.value,cursor:e.target.value.length})}};this.handleKeyDown=function(e){var n=e.target.value;var i=e.keyCode||e.code;t.onInputExcuted=false;e.stopPropagation();t.onKeyDown.emit({value:n,cursor:n.length,keyCode:i});i===13&&t.onConfirm.emit({value:n})};this.handleComposition=function(e){if(!(e.target instanceof HTMLInputElement))return;if(e.type==="compositionend"){t.isOnComposition=false;t.value=e.target.value;t.onInput.emit({value:e.target.value,cursor:e.target.value.length})}else{t.isOnComposition=true}}}e.prototype.watchFocus=function(e,t){var n;if(!t&&e){(n=this.inputRef)===null||n===void 0?void 0:n.focus()}};e.prototype.watchValue=function(e){var t=fixControlledValue(e);if(this.inputRef&&this.inputRef.value!==t){this.inputRef.value=t}};e.prototype.componentDidLoad=function(){var e=this;var t,n,i;if(this.type==="file"){this.fileListener=function(){e.onInput.emit()};(t=this.inputRef)===null||t===void 0?void 0:t.addEventListener("change",this.fileListener)}else{(n=this.inputRef)===null||n===void 0?void 0:n.addEventListener("compositionstart",this.handleComposition);(i=this.inputRef)===null||i===void 0?void 0:i.addEventListener("compositionend",this.handleComposition)}Object.defineProperty(this.el,"value",{get:function(){var t;return(t=e.inputRef)===null||t===void 0?void 0:t.value},set:function(t){return e.value=t},configurable:true})};e.prototype.disconnectedCallback=function(){var e;if(this.type==="file"){(e=this.inputRef)===null||e===void 0?void 0:e.removeEventListener("change",this.fileListener)}};e.prototype.render=function(){var e=this;var t=this,n=t.value,i=t.type,o=t.password,a=t.placeholder,s=t.autoFocus,u=t.disabled,r=t.maxlength,l=t.confirmType,p=t.name,c=t.nativeProps;return h("input",Object.assign({ref:function(t){e.inputRef=t},class:"weui-input",value:fixControlledValue(n),type:getTrueType(i,l,o),placeholder:a,autoFocus:s,disabled:u,maxlength:r,name:p,onInput:this.handleInput,onFocus:this.handleFocus,onBlur:this.handleBlur,onChange:this.handleChange,onKeyDown:this.handleKeyDown,onPaste:this.handlePaste,onCompositionStart:this.handleComposition,onCompositionEnd:this.handleComposition},c))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{autoFocus:["watchFocus"],value:["watchValue"]}},enumerable:false,configurable:true});return e}();Input.style=indexCss;export{Input as taro_input_core};
1
+ import{r as registerInstance,c as createEvent,h,g as getElement}from"./index-8809c729.js";var indexCss="taro-input-core{display:block}input{display:block;overflow:hidden;height:1.4rem;text-overflow:clip;text-align:inherit;white-space:nowrap}";function getTrueType(e,t,n){if(t==="search")e="search";if(n)e="password";if(typeof e==="undefined"){return"text"}if(!e){throw new Error("unexpected type")}if(e==="digit")e="number";return e}function fixControlledValue(e){return e!==null&&e!==void 0?e:""}var Input=function(){function e(e){var t=this;registerInstance(this,e);this.onInput=createEvent(this,"input",7);this.onPaste=createEvent(this,"paste",7);this.onFocus=createEvent(this,"focus",7);this.onBlur=createEvent(this,"blur",7);this.onConfirm=createEvent(this,"confirm",7);this.onChange=createEvent(this,"change",7);this.onKeyDown=createEvent(this,"keydown",7);this.isOnComposition=false;this.isOnPaste=false;this.onInputExcuted=false;this.password=false;this.disabled=false;this.maxlength=140;this.autoFocus=false;this.confirmType="done";this.nativeProps={};this.handleInput=function(e){e.stopPropagation();var n=t,i=n.type,o=n.maxlength,a=n.confirmType,s=n.password;if(!t.isOnComposition&&!t.onInputExcuted){var u=e.target.value;var r=getTrueType(i,a,s);t.onInputExcuted=true;if(r==="number"&&u&&o>-1&&o<=u.length){u=u.substring(0,o);e.target.value=u}t.value=u;t.onInput.emit({value:u,cursor:u.length});t.onInputExcuted=false}};this.handlePaste=function(e){t.isOnPaste=true;t.onPaste.emit({value:e.target.value})};this.handleFocus=function(e){t.onInputExcuted=false;t.onFocus.emit({value:e.target.value})};this.handleBlur=function(e){t.onBlur.emit({value:e.target.value})};this.handleChange=function(e){e.stopPropagation();t.onChange.emit({value:e.target.value});if(t.isOnPaste){t.isOnPaste=false;t.value=e.target.value;t.onInput.emit({value:e.target.value,cursor:e.target.value.length})}};this.handleKeyDown=function(e){var n=e.target.value;var i=e.keyCode||e.code;t.onInputExcuted=false;e.stopPropagation();t.onKeyDown.emit({value:n,cursor:n.length,keyCode:i});i===13&&t.onConfirm.emit({value:n})};this.handleComposition=function(e){if(!(e.target instanceof HTMLInputElement))return;if(e.type==="compositionend"){t.isOnComposition=false;t.value=e.target.value;t.onInput.emit({value:e.target.value,cursor:e.target.value.length})}else{t.isOnComposition=true}};this.handleBeforeinput=function(e){if(!e.data)return;var n=e.data&&/[0-9]/.test(e.data);if(t.type==="number"&&!n){e.preventDefault()}if(t.type==="digit"&&!n){if(e.data!=="."||e.data==="."&&e.target.value.indexOf(".")>-1){e.preventDefault()}}}}e.prototype.watchFocus=function(e,t){var n;if(!t&&e){(n=this.inputRef)===null||n===void 0?void 0:n.focus()}};e.prototype.watchValue=function(e){var t=fixControlledValue(e);if(this.inputRef&&this.inputRef.value!==t){this.inputRef.value=t}};e.prototype.componentDidLoad=function(){var e=this;var t,n,i,o,a;if(this.type==="file"){this.fileListener=function(){e.onInput.emit()};(t=this.inputRef)===null||t===void 0?void 0:t.addEventListener("change",this.fileListener)}else{(n=this.inputRef)===null||n===void 0?void 0:n.addEventListener("compositionstart",this.handleComposition);(i=this.inputRef)===null||i===void 0?void 0:i.addEventListener("compositionend",this.handleComposition);(o=this.inputRef)===null||o===void 0?void 0:o.addEventListener("beforeinput",this.handleBeforeinput);(a=this.inputRef)===null||a===void 0?void 0:a.addEventListener("textInput",this.handleBeforeinput)}Object.defineProperty(this.el,"value",{get:function(){var t;return(t=e.inputRef)===null||t===void 0?void 0:t.value},set:function(t){return e.value=t},configurable:true})};e.prototype.disconnectedCallback=function(){var e,t,n,i,o;if(this.type==="file"){(e=this.inputRef)===null||e===void 0?void 0:e.removeEventListener("change",this.fileListener)}else{(t=this.inputRef)===null||t===void 0?void 0:t.removeEventListener("compositionstart",this.handleComposition);(n=this.inputRef)===null||n===void 0?void 0:n.removeEventListener("compositionend",this.handleComposition);(i=this.inputRef)===null||i===void 0?void 0:i.removeEventListener("beforeinput",this.handleBeforeinput);(o=this.inputRef)===null||o===void 0?void 0:o.removeEventListener("textInput",this.handleBeforeinput)}};e.prototype.render=function(){var e=this;var t=this,n=t.value,i=t.type,o=t.password,a=t.placeholder,s=t.autoFocus,u=t.disabled,r=t.maxlength,l=t.confirmType,p=t.name,d=t.nativeProps;return h("input",Object.assign({ref:function(t){e.inputRef=t},class:"weui-input",value:fixControlledValue(n),type:getTrueType(i,l,o),placeholder:a,autoFocus:s,disabled:u,maxlength:r,name:p,onInput:this.handleInput,onFocus:this.handleFocus,onBlur:this.handleBlur,onChange:this.handleChange,onKeyDown:this.handleKeyDown,onPaste:this.handlePaste,onCompositionStart:this.handleComposition,onCompositionEnd:this.handleComposition},d))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{autoFocus:["watchFocus"],value:["watchValue"]}},enumerable:false,configurable:true});return e}();Input.style=indexCss;export{Input as taro_input_core};