@hw-component/form 0.0.6-beta-v1 → 0.0.6-beta-v2

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.
@@ -1,3 +1,3 @@
1
1
  import type { HInputProps } from "@/components/Input/modal";
2
- declare const _default: ({ value, onChange, ...props }: HInputProps) => JSX.Element;
2
+ declare const _default: ({ value, onChange, defaultColor, ...props }: HInputProps) => JSX.Element;
3
3
  export default _default;
@@ -23,6 +23,7 @@ import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
23
23
  import _inherits from '@babel/runtime-corejs3/helpers/inherits';
24
24
  import _setPrototypeOf from '@babel/runtime-corejs3/helpers/setPrototypeOf';
25
25
  import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
26
+ import 'core-js/modules/es.string.trim.js';
26
27
  import 'core-js/modules/es.string.starts-with.js';
27
28
  import 'core-js/modules/es.regexp.exec.js';
28
29
  import 'core-js/modules/es.string.match.js';
@@ -34,25 +35,29 @@ import Picker from './Picker.js';
34
35
  import { useMemo } from 'react';
35
36
  import { useClassName } from '../../hooks/index.js';
36
37
 
37
- var _excluded = ["value", "onChange"];
38
+ var _excluded = ["value", "onChange", "defaultColor"];
38
39
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
39
40
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
40
41
  function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { var i = g[name]; if ("number" == typeof i) groups[name] = result[i];else { for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) k++; groups[name] = result[i[k]]; } return groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) { result.groups = buildGroups(result, this); var indices = result.indices; indices && (indices.groups = buildGroups(indices, this)); } return result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { var group = groups[name]; return "$" + (Array.isArray(group) ? group.join("$") : group); })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != _typeof(args[args.length - 1]) && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
41
42
  var ColorInput = (function (_ref) {
42
43
  var value = _ref.value,
43
44
  onChange = _ref.onChange,
45
+ _ref$defaultColor = _ref.defaultColor,
46
+ defaultColor = _ref$defaultColor === void 0 ? "rgba(0,0,0,1)" : _ref$defaultColor,
44
47
  props = _objectWithoutProperties(_ref, _excluded);
45
48
  var classname = useClassName("hw-color-box");
49
+ var inputVal = value === null || value === void 0 ? void 0 : value.trim();
46
50
  var pickerValue = useMemo(function () {
47
- if (typeof value === "string") {
51
+ var matchVal = inputVal || defaultColor;
52
+ if (typeof matchVal === "string") {
48
53
  var _result$groups;
49
- if (value.startsWith("#")) {
50
- return value;
54
+ if (matchVal.startsWith("#")) {
55
+ return matchVal;
51
56
  }
52
57
  var rgbaRegular = /*#__PURE__*/_wrapRegExp(/((rgba\())(.*?)(?=(\)))/, {
53
58
  rgba: 3
54
59
  });
55
- var result = value.match(rgbaRegular);
60
+ var result = matchVal.match(rgbaRegular);
56
61
  if (result !== null && result !== void 0 && (_result$groups = result.groups) !== null && _result$groups !== void 0 && _result$groups.rgba) {
57
62
  var rgbas = result.groups.rgba.split(",");
58
63
  return {
@@ -64,7 +69,7 @@ var ColorInput = (function (_ref) {
64
69
  }
65
70
  }
66
71
  return "";
67
- }, [value]);
72
+ }, [inputVal]);
68
73
  var colorChange = function colorChange(val) {
69
74
  var rgb = val.rgb;
70
75
  var text = "rgba(".concat(rgb.r, ",").concat(rgb.g, ",").concat(rgb.b, ",").concat(rgb.a, ")");
@@ -82,7 +87,7 @@ var ColorInput = (function (_ref) {
82
87
  placement: "topLeft",
83
88
  children: jsx("div", {
84
89
  style: {
85
- backgroundColor: value
90
+ backgroundColor: inputVal || defaultColor
86
91
  },
87
92
  className: classname
88
93
  })
@@ -7,6 +7,7 @@ import type { AddDispatchListenerFn } from "../Form/modal";
7
7
  export interface HInputProps<V = any> extends Omit<InputProps, "onChange" | "value"> {
8
8
  onChange?: (value: V) => void;
9
9
  value?: V;
10
+ defaultColor?: string;
10
11
  }
11
12
  interface ValueNameModal {
12
13
  input?: string;
@@ -1,3 +1,3 @@
1
1
  import type { HInputProps } from "@/components/Input/modal";
2
- declare const _default: ({ value, onChange, ...props }: HInputProps) => JSX.Element;
2
+ declare const _default: ({ value, onChange, defaultColor, ...props }: HInputProps) => JSX.Element;
3
3
  export default _default;
@@ -26,6 +26,7 @@ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
26
26
  var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
27
27
  var _setPrototypeOf = require('@babel/runtime-corejs3/helpers/setPrototypeOf');
28
28
  var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
29
+ require('core-js/modules/es.string.trim.js');
29
30
  require('core-js/modules/es.string.starts-with.js');
30
31
  require('core-js/modules/es.regexp.exec.js');
31
32
  require('core-js/modules/es.string.match.js');
@@ -37,25 +38,29 @@ var Picker = require('./Picker.js');
37
38
  var React = require('react');
38
39
  var index = require('../../hooks/index.js');
39
40
 
40
- var _excluded = ["value", "onChange"];
41
+ var _excluded = ["value", "onChange", "defaultColor"];
41
42
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
42
43
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
43
44
  function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { var i = g[name]; if ("number" == typeof i) groups[name] = result[i];else { for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) k++; groups[name] = result[i[k]]; } return groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) { result.groups = buildGroups(result, this); var indices = result.indices; indices && (indices.groups = buildGroups(indices, this)); } return result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { var group = groups[name]; return "$" + (Array.isArray(group) ? group.join("$") : group); })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != _typeof(args[args.length - 1]) && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
44
45
  var ColorInput = (function (_ref) {
45
46
  var value = _ref.value,
46
47
  onChange = _ref.onChange,
48
+ _ref$defaultColor = _ref.defaultColor,
49
+ defaultColor = _ref$defaultColor === void 0 ? "rgba(0,0,0,1)" : _ref$defaultColor,
47
50
  props = _objectWithoutProperties(_ref, _excluded);
48
51
  var classname = index.useClassName("hw-color-box");
52
+ var inputVal = value === null || value === void 0 ? void 0 : value.trim();
49
53
  var pickerValue = React.useMemo(function () {
50
- if (typeof value === "string") {
54
+ var matchVal = inputVal || defaultColor;
55
+ if (typeof matchVal === "string") {
51
56
  var _result$groups;
52
- if (value.startsWith("#")) {
53
- return value;
57
+ if (matchVal.startsWith("#")) {
58
+ return matchVal;
54
59
  }
55
60
  var rgbaRegular = /*#__PURE__*/_wrapRegExp(/((rgba\())(.*?)(?=(\)))/, {
56
61
  rgba: 3
57
62
  });
58
- var result = value.match(rgbaRegular);
63
+ var result = matchVal.match(rgbaRegular);
59
64
  if (result !== null && result !== void 0 && (_result$groups = result.groups) !== null && _result$groups !== void 0 && _result$groups.rgba) {
60
65
  var rgbas = result.groups.rgba.split(",");
61
66
  return {
@@ -67,7 +72,7 @@ var ColorInput = (function (_ref) {
67
72
  }
68
73
  }
69
74
  return "";
70
- }, [value]);
75
+ }, [inputVal]);
71
76
  var colorChange = function colorChange(val) {
72
77
  var rgb = val.rgb;
73
78
  var text = "rgba(".concat(rgb.r, ",").concat(rgb.g, ",").concat(rgb.b, ",").concat(rgb.a, ")");
@@ -85,7 +90,7 @@ var ColorInput = (function (_ref) {
85
90
  placement: "topLeft",
86
91
  children: jsxRuntime.jsx("div", {
87
92
  style: {
88
- backgroundColor: value
93
+ backgroundColor: inputVal || defaultColor
89
94
  },
90
95
  className: classname
91
96
  })
@@ -7,6 +7,7 @@ import type { AddDispatchListenerFn } from "../Form/modal";
7
7
  export interface HInputProps<V = any> extends Omit<InputProps, "onChange" | "value"> {
8
8
  onChange?: (value: V) => void;
9
9
  value?: V;
10
+ defaultColor?: string;
10
11
  }
11
12
  interface ValueNameModal {
12
13
  input?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "0.0.6-beta-v1",
3
+ "version": "0.0.6-beta-v2",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3,15 +3,17 @@ import { Input, Popover } from "antd";
3
3
  import Picker from "./Picker";
4
4
  import { useMemo } from "react";
5
5
  import { useClassName } from "../../hooks";
6
- export default ({ value, onChange, ...props }: HInputProps) => {
6
+ export default ({ value, onChange,defaultColor="rgba(0,0,0,1)", ...props }: HInputProps) => {
7
7
  const classname = useClassName("hw-color-box");
8
+ const inputVal=value?.trim();
8
9
  const pickerValue = useMemo(() => {
9
- if (typeof value === "string") {
10
- if (value.startsWith("#")) {
11
- return value;
10
+ const matchVal=inputVal||defaultColor;
11
+ if (typeof matchVal === "string") {
12
+ if (matchVal.startsWith("#")) {
13
+ return matchVal;
12
14
  }
13
15
  const rgbaRegular = /((rgba\())(?<rgba>.*?)(?=(\)))/;
14
- const result = value.match(rgbaRegular);
16
+ const result = matchVal.match(rgbaRegular);
15
17
  if (result?.groups?.rgba) {
16
18
  const rgbas = result.groups.rgba.split(",");
17
19
  return {
@@ -23,7 +25,7 @@ export default ({ value, onChange, ...props }: HInputProps) => {
23
25
  }
24
26
  }
25
27
  return "";
26
- }, [value]);
28
+ }, [inputVal]);
27
29
  const colorChange = (val) => {
28
30
  const { rgb } = val;
29
31
  const text = `rgba(${rgb.r},${rgb.g},${rgb.b},${rgb.a})`;
@@ -40,7 +42,7 @@ export default ({ value, onChange, ...props }: HInputProps) => {
40
42
  content={<Picker value={pickerValue} onChange={colorChange} />}
41
43
  placement="topLeft"
42
44
  >
43
- <div style={{ backgroundColor: value }} className={classname} />
45
+ <div style={{ backgroundColor: inputVal||defaultColor }} className={classname} />
44
46
  </Popover>
45
47
  }
46
48
  />
@@ -8,6 +8,7 @@ export interface HInputProps<V = any>
8
8
  extends Omit<InputProps, "onChange" | "value"> {
9
9
  onChange?: (value: V) => void;
10
10
  value?: V;
11
+ defaultColor?:string;
11
12
  }
12
13
 
13
14
  interface ValueNameModal {