@chaoswise/ui 2.3.16 → 2.3.17

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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  基于antd3.x根据公司UIUE规范进行二次封装的前端公共组件库,用于统一公司产品风格,提高研发人员开发效率
6
6
 
7
7
  # Features
8
- #### 1. 包含符合UIUE的公共组件
8
+ #### 1. 包含符合UIUE设计规范的公共组件,设计规范和使用规范参考[YXD-用户体验设计平台](https://yunzhihui.feishu.cn/wiki/wikcnkFSNhaqVDdYNNH5K6NNy7f)
9
9
  #### 2. 支持antd全部组件,引用和使用方法参考[antd官方文档](https://3x.ant.design/docs/react/introduce-cn)
10
10
  #### 3. 支持按需加载
11
11
 
@@ -297,14 +297,36 @@ export var cloneChangeDate = function cloneChangeDate(currentDate_0, currentDate
297
297
  cloneCurrentDate_1 = moment();
298
298
  switchInitial = true;
299
299
  } else {
300
- // 非极限时间,但是超过最大的时间边界跨度
301
- // 先将currentDate_0和currentDate_1二者进行相减在这个基础上增加(timeSpanBoundary - 二者相减) / 2 ,左右各增加减少这个数值
302
- var initialTimeDiff = computeTimeDiff([cloneCurrentDate_0, cloneCurrentDate_1], "s");
303
- var needChangeTimeDiff = Math.ceil(initialTimeDiff - timeSpanBoundary) / 2;
304
300
  var clone0 = currentDate_0.clone();
305
301
  var clone1 = currentDate_1.clone();
306
- cloneCurrentDate_0 = clone0.subtract(moment.duration(needChangeTimeDiff, "s"));
307
- cloneCurrentDate_1 = clone1.add(moment.duration(needChangeTimeDiff, "s"));
302
+ var initialTimeDiff = computeTimeDiff([clone0, clone1], "s");
303
+ if (timeSpanBoundary > initialTimeDiff) {
304
+ var needChangeTimeDiff = Math.ceil(timeSpanBoundary - initialTimeDiff) / 2;
305
+ cloneCurrentDate_0 = clone0.subtract(moment.duration(needChangeTimeDiff, "s"));
306
+ cloneCurrentDate_1 = clone1.add(moment.duration(needChangeTimeDiff, "s"));
307
+ // 计算最大值的时间差
308
+ var _maxTimeDiff2 = computeTimeDiff([cloneCurrentDate_1, moment()]);
309
+ if (_maxTimeDiff2 <= 0) {
310
+ // 当前时间已经是极限了
311
+ // 已经是极限直接当前时间向前推进timeSpanBoundary即可
312
+ cloneCurrentDate_0 = moment().subtract(moment.duration(timeSpanBoundary, "s"));
313
+ cloneCurrentDate_1 = moment();
314
+ switchInitial = true;
315
+ }
316
+ } else {
317
+ cloneCurrentDate_1 = clone1.add(moment.duration(timeSpanBoundary, "s"));
318
+ var clone = cloneCurrentDate_1.clone();
319
+ cloneCurrentDate_0 = clone.subtract(moment.duration(timeSpanBoundary, "s"));
320
+ // 计算最大值的时间差
321
+ var _maxTimeDiff3 = computeTimeDiff([cloneCurrentDate_1, moment()]);
322
+ if (_maxTimeDiff3 <= 0) {
323
+ // 当前时间已经是极限了
324
+ // 已经是极限直接当前时间向前推进timeSpanBoundary即可
325
+ cloneCurrentDate_0 = moment().subtract(moment.duration(timeSpanBoundary, "s"));
326
+ cloneCurrentDate_1 = moment();
327
+ switchInitial = true;
328
+ }
329
+ }
308
330
  }
309
331
  } else {
310
332
  if (_maxTimeDiff <= 0) {
@@ -239,14 +239,17 @@ var CWTable = function CWTable(_ref, ref) {
239
239
  var resetSortDataSource = function resetSortDataSource() {
240
240
  var _dataSource = _toConsumableArray(dataSource);
241
241
  if (frontPagination) {
242
- var current = pageInfo.current;
243
- var pageSize = pageInfo.pageSize;
244
- var total = dataSource.length;
242
+ var _current = pagination.current,
243
+ _pageSize = pagination.pageSize,
244
+ _total = pagination.total;
245
+ var current = _current || pageInfo.current;
246
+ var pageSize = _pageSize || pageInfo.pageSize;
247
+ var total = _total || dataSource.length;
245
248
  _dataSource = _dataSource.slice((current - 1) * pageSize, current * pageSize > total ? total : current * pageSize);
246
249
  }
247
250
  setFinalDataSource(_dataSource);
248
251
  };
249
- useEffect(resetSortDataSource, [frontPagination, pageInfo.current, pageInfo.pageSize, dataSource]);
252
+ useEffect(resetSortDataSource, [frontPagination, pagination, pageInfo.current, pageInfo.pageSize, dataSource]);
250
253
  useEffect(function () {
251
254
  if (!autoHeight) {
252
255
  return;
@@ -652,13 +655,14 @@ var CWTable = function CWTable(_ref, ref) {
652
655
  onShowSizeChange: onShowSizeChange,
653
656
  size: size == 'small' ? 'small' : ''
654
657
  });
655
- if (frontPagination) {
656
- return _objectSpread(_objectSpread({}, common), {}, {
657
- current: pageInfo.current,
658
- pageSize: pageInfo.pageSize,
659
- total: dataSource.length
660
- });
661
- }
658
+ // if (frontPagination) {
659
+ // return {
660
+ // ...common,
661
+ // current: pageInfo.current,
662
+ // pageSize: pageInfo.pageSize,
663
+ // total: dataSource.length,
664
+ // }
665
+ // }
662
666
  return _objectSpread(_objectSpread({}, common), {}, {
663
667
  current: current || pageInfo.current,
664
668
  pageSize: pageSize || pageInfo.pageSize,
@@ -0,0 +1,14 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import * as React from "react";
3
+ var SvgShowIcon = function SvgShowIcon(props) {
4
+ return /*#__PURE__*/React.createElement("svg", _extends({
5
+ xmlns: "http://www.w3.org/2000/svg",
6
+ width: 14,
7
+ height: 14
8
+ }, props), /*#__PURE__*/React.createElement("path", {
9
+ fill: "currentColor",
10
+ fillRule: "evenodd",
11
+ d: "m7.778.922.308.047.036.007a.439.439 0 0 1 .333.277l.02.075.215 1.162c.396.148.768.348 1.111.594l.252.193 1.111-.395a.44.44 0 0 1 .416.068l.064.062.025.029c.408.48.735 1.015.976 1.593l.114.292.012.036c.051.143.025.3-.066.416l-.061.065-.896.765c.028.174.048.35.057.526l.003.11h-.982a3.875 3.875 0 0 0-.02-.266l-.028-.208-.09-.546 1.022-.873a5.208 5.208 0 0 0-.415-.767l-.167-.24-1.27.45-.429-.353a3.844 3.844 0 0 0-.852-.53l-.232-.096-.52-.195-.245-1.326a5.169 5.169 0 0 0-.873-.025l-.29.025-.244 1.328-.518.196a3.814 3.814 0 0 0-.877.472l-.2.153-.429.354-1.277-.454a5.095 5.095 0 0 0-.458.742l-.124.264 1.032.882-.089.547a3.769 3.769 0 0 0-.027 1.038l.027.206.09.547-1.033.882c.117.266.255.523.415.767l.167.239 1.277-.454.43.354c.259.214.543.39.845.529l.23.096.517.198.245 1.33c.182.02.365.03.549.032v.98a6.145 6.145 0 0 1-.705-.044l-.348-.053-.037-.007a.439.439 0 0 1-.332-.277l-.02-.074-.217-1.168a4.754 4.754 0 0 1-1.146-.623l-.207-.161-1.12.398a.44.44 0 0 1-.416-.069l-.064-.061-.025-.03a6.077 6.077 0 0 1-.976-1.592l-.113-.292-.013-.036a.439.439 0 0 1 .066-.417l.062-.064.906-.774a4.786 4.786 0 0 1-.035-1.303l.035-.258-.906-.774a.44.44 0 0 1-.15-.395l.022-.086.013-.036a6.09 6.09 0 0 1 .892-1.64l.197-.245.025-.03a.437.437 0 0 1 .393-.15l.087.021 1.12.398c.325-.268.682-.49 1.063-.664l.29-.12.216-1.168a.438.438 0 0 1 .279-.331l.074-.02.037-.008A6.185 6.185 0 0 1 7.778.922Zm4.833 10.844a.5.5 0 1 1 0 1h-4.5a.5.5 0 1 1 0-1h4.5Zm0-2a.5.5 0 1 1 0 1h-4.5a.5.5 0 1 1 0-1h4.5ZM7 4.457c1.274 0 2.316.99 2.4 2.242l.005.145H8.53a1.522 1.522 0 0 0-.346-.95l-.102-.114A1.52 1.52 0 0 0 7 5.332a1.52 1.52 0 0 0-1.083.448c-.288.29-.448.674-.448 1.083a1.526 1.526 0 0 0 1.38 1.524l.116.005v.877a2.406 2.406 0 0 1-2.366-2.241l-.005-.165A2.406 2.406 0 0 1 7 4.457Zm5.611 3.309a.5.5 0 1 1 0 1h-4.5a.5.5 0 1 1 0-1h4.5Z"
12
+ }));
13
+ };
14
+ export default SvgShowIcon;
@@ -22,8 +22,10 @@ import classnames from "classnames";
22
22
  import PropTypes from "prop-types";
23
23
  import { HTML5Backend } from "react-dnd-html5-backend";
24
24
  import { DndProvider } from "react-dnd";
25
- import "./index.less";
26
25
  import { getLocale } from "./locale";
26
+ import useConfigContext from '../useConfigContext';
27
+ import ShowSvgIcon from './assets/ShowSvgIcon';
28
+ import "./index.less";
27
29
  var CheckboxGroup = _Checkbox.Group;
28
30
  function FilterDropDown(props) {
29
31
  var selectItems = props.selectItems,
@@ -68,6 +70,9 @@ function FilterDropDown(props) {
68
70
  _ConfigProvider$useLo2 = _ConfigProvider$useLo.locale,
69
71
  locale = _ConfigProvider$useLo2 === void 0 ? "zh" : _ConfigProvider$useLo2;
70
72
  var localeObj = getLocale(locale);
73
+ var _useConfigContext = useConfigContext(),
74
+ getPrefixCls = _useConfigContext.getPrefixCls;
75
+ var prefixCls = getPrefixCls();
71
76
  useEffect(function () {
72
77
  document.addEventListener("click", clickBody);
73
78
  return function () {
@@ -199,8 +204,8 @@ function FilterDropDown(props) {
199
204
  onClick: toggoleShow,
200
205
  ref: addRef
201
206
  }, colsFilterTitle ? colsFilterTitle : /*#__PURE__*/React.createElement(_Button, {
202
- icon: "unordered-list"
203
- })), showList && /*#__PURE__*/React.createElement(Fragment, null, isDrag ? /*#__PURE__*/React.createElement(DndProvider, {
207
+ className: "".concat(prefixCls, "-btn-icon-only")
208
+ }, /*#__PURE__*/React.createElement(ShowSvgIcon, null))), showList && /*#__PURE__*/React.createElement(Fragment, null, isDrag ? /*#__PURE__*/React.createElement(DndProvider, {
204
209
  backend: HTML5Backend
205
210
  }, renderDropdown()) : /*#__PURE__*/React.createElement(Fragment, null, renderDropdown())));
206
211
  }
@@ -0,0 +1,22 @@
1
+ import { useEvent } from 'rc-util';
2
+ import * as React from 'react';
3
+ function voidFunc() {}
4
+ var WatermarkContext = /*#__PURE__*/React.createContext({
5
+ add: voidFunc,
6
+ remove: voidFunc
7
+ });
8
+ export function usePanelRef(panelSelector) {
9
+ var watermark = React.useContext(WatermarkContext);
10
+ var panelEleRef = React.useRef();
11
+ var panelRef = useEvent(function (ele) {
12
+ if (ele) {
13
+ var innerContentEle = panelSelector ? ele.querySelector(panelSelector) : ele;
14
+ watermark.add(innerContentEle);
15
+ panelEleRef.current = innerContentEle;
16
+ } else {
17
+ watermark.remove(panelEleRef.current);
18
+ }
19
+ });
20
+ return panelRef;
21
+ }
22
+ export default WatermarkContext;
@@ -0,0 +1,308 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import React, { useEffect } from 'react';
12
+ import { useMutateObserver } from '@rc-component/mutate-observer';
13
+ import classNames from 'classnames';
14
+ import WatermarkContext from './context';
15
+ import useClips, { FontGap } from './useClips';
16
+ import useRafDebounce from './useRafDebounce';
17
+ import useWatermark from './useWatermark';
18
+ import { getPixelRatio, reRendering, verifyIsArrayOfNumberType } from './utils';
19
+ import PropTypes from "prop-types";
20
+ /**
21
+ * Only return `next` when size changed.
22
+ * This is only used for elements compare, not a shallow equal!
23
+ */
24
+ function getSizeDiff(prev, next) {
25
+ return prev.size === next.size ? prev : next;
26
+ }
27
+ var DEFAULT_GAP_X = 100;
28
+ var DEFAULT_GAP_Y = 100;
29
+ var Watermark = function Watermark(props) {
30
+ var _a, _b;
31
+ var _props$zIndex = props.zIndex,
32
+ zIndex = _props$zIndex === void 0 ? 9 : _props$zIndex,
33
+ _props$rotate = props.rotate,
34
+ rotate = _props$rotate === void 0 ? -22 : _props$rotate,
35
+ width = props.width,
36
+ height = props.height,
37
+ image = props.image,
38
+ content = props.content,
39
+ _props$font = props.font,
40
+ font = _props$font === void 0 ? {} : _props$font,
41
+ style = props.style,
42
+ className = props.className,
43
+ rootClassName = props.rootClassName,
44
+ _props$gap = props.gap,
45
+ gap = _props$gap === void 0 ? [DEFAULT_GAP_X, DEFAULT_GAP_Y] : _props$gap,
46
+ offset = props.offset,
47
+ children = props.children,
48
+ _props$inherit = props.inherit,
49
+ inherit = _props$inherit === void 0 ? true : _props$inherit;
50
+ var _font$color = font.color,
51
+ color = _font$color === void 0 ? "rgba(0, 0, 0, 0.15)" : _font$color,
52
+ _font$fontSize = font.fontSize,
53
+ fontSize = _font$fontSize === void 0 ? 16 : _font$fontSize,
54
+ _font$fontWeight = font.fontWeight,
55
+ fontWeight = _font$fontWeight === void 0 ? 'normal' : _font$fontWeight,
56
+ _font$fontStyle = font.fontStyle,
57
+ fontStyle = _font$fontStyle === void 0 ? 'normal' : _font$fontStyle,
58
+ _font$fontFamily = font.fontFamily,
59
+ fontFamily = _font$fontFamily === void 0 ? 'sans-serif' : _font$fontFamily,
60
+ _font$textAlign = font.textAlign,
61
+ textAlign = _font$textAlign === void 0 ? 'center' : _font$textAlign;
62
+ var _gap = _slicedToArray(gap, 2),
63
+ _gap$ = _gap[0],
64
+ gapX = _gap$ === void 0 ? DEFAULT_GAP_X : _gap$,
65
+ _gap$2 = _gap[1],
66
+ gapY = _gap$2 === void 0 ? DEFAULT_GAP_Y : _gap$2;
67
+ var gapXCenter = gapX / 2;
68
+ var gapYCenter = gapY / 2;
69
+ var offsetLeft = (_a = offset === null || offset === void 0 ? void 0 : offset[0]) !== null && _a !== void 0 ? _a : gapXCenter;
70
+ var offsetTop = (_b = offset === null || offset === void 0 ? void 0 : offset[1]) !== null && _b !== void 0 ? _b : gapYCenter;
71
+ var markStyle = React.useMemo(function () {
72
+ var mergedStyle = {
73
+ zIndex: zIndex,
74
+ position: 'absolute',
75
+ left: 0,
76
+ top: 0,
77
+ width: '100%',
78
+ height: '100%',
79
+ pointerEvents: 'none',
80
+ backgroundRepeat: 'repeat'
81
+ };
82
+ /** Calculate the style of the offset */
83
+ var positionLeft = offsetLeft - gapXCenter;
84
+ var positionTop = offsetTop - gapYCenter;
85
+ if (positionLeft > 0) {
86
+ mergedStyle.left = "".concat(positionLeft, "px");
87
+ mergedStyle.width = "calc(100% - ".concat(positionLeft, "px)");
88
+ positionLeft = 0;
89
+ }
90
+ if (positionTop > 0) {
91
+ mergedStyle.top = "".concat(positionTop, "px");
92
+ mergedStyle.height = "calc(100% - ".concat(positionTop, "px)");
93
+ positionTop = 0;
94
+ }
95
+ mergedStyle.backgroundPosition = "".concat(positionLeft, "px ").concat(positionTop, "px");
96
+ return mergedStyle;
97
+ }, [zIndex, offsetLeft, gapXCenter, offsetTop, gapYCenter]);
98
+ var _React$useState = React.useState(),
99
+ _React$useState2 = _slicedToArray(_React$useState, 2),
100
+ container = _React$useState2[0],
101
+ setContainer = _React$useState2[1];
102
+ // Used for nest case like Modal, Drawer
103
+ var _React$useState3 = React.useState(new Set()),
104
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
105
+ subElements = _React$useState4[0],
106
+ setSubElements = _React$useState4[1];
107
+ // Nest elements should also support watermark
108
+ var targetElements = React.useMemo(function () {
109
+ var list = container ? [container] : [];
110
+ return [].concat(list, _toConsumableArray(Array.from(subElements)));
111
+ }, [container, subElements]);
112
+ // ============================ Content =============================
113
+ /**
114
+ * Get the width and height of the watermark. The default values are as follows
115
+ * Image: [120, 64]; Content: It's calculated by content;
116
+ */
117
+ var getMarkSize = function getMarkSize(ctx) {
118
+ var defaultWidth = 120;
119
+ var defaultHeight = 64;
120
+ if (!image && ctx.measureText) {
121
+ ctx.font = "".concat(Number(fontSize), "px ").concat(fontFamily);
122
+ var contents = Array.isArray(content) ? content : [content];
123
+ var sizes = contents.map(function (item) {
124
+ var metrics = ctx.measureText(item);
125
+ return [metrics.width, metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent];
126
+ });
127
+ defaultWidth = Math.ceil(Math.max.apply(Math, _toConsumableArray(sizes.map(function (size) {
128
+ return size[0];
129
+ }))));
130
+ defaultHeight = Math.ceil(Math.max.apply(Math, _toConsumableArray(sizes.map(function (size) {
131
+ return size[1];
132
+ })))) * contents.length + (contents.length - 1) * FontGap;
133
+ }
134
+ return [width !== null && width !== void 0 ? width : defaultWidth, height !== null && height !== void 0 ? height : defaultHeight];
135
+ };
136
+ var getClips = useClips();
137
+ var _React$useState5 = React.useState(null),
138
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
139
+ watermarkInfo = _React$useState6[0],
140
+ setWatermarkInfo = _React$useState6[1];
141
+ // Generate new Watermark content
142
+ var renderWatermark = function renderWatermark() {
143
+ var canvas = document.createElement('canvas');
144
+ var ctx = canvas.getContext('2d');
145
+ if (ctx) {
146
+ var ratio = getPixelRatio();
147
+ var _getMarkSize = getMarkSize(ctx),
148
+ _getMarkSize2 = _slicedToArray(_getMarkSize, 2),
149
+ markWidth = _getMarkSize2[0],
150
+ markHeight = _getMarkSize2[1];
151
+ var drawCanvas = function drawCanvas(drawContent) {
152
+ var _getClips = getClips(drawContent || '', rotate, ratio, markWidth, markHeight, {
153
+ color: color,
154
+ fontSize: fontSize,
155
+ fontStyle: fontStyle,
156
+ fontWeight: fontWeight,
157
+ fontFamily: fontFamily,
158
+ textAlign: textAlign
159
+ }, gapX, gapY),
160
+ _getClips2 = _slicedToArray(_getClips, 2),
161
+ nextClips = _getClips2[0],
162
+ clipWidth = _getClips2[1];
163
+ setWatermarkInfo([nextClips, clipWidth]);
164
+ };
165
+ if (image) {
166
+ var img = new Image();
167
+ img.onload = function () {
168
+ drawCanvas(img);
169
+ };
170
+ img.onerror = function () {
171
+ drawCanvas(content);
172
+ };
173
+ img.crossOrigin = 'anonymous';
174
+ img.referrerPolicy = 'no-referrer';
175
+ img.src = image;
176
+ } else {
177
+ drawCanvas(content);
178
+ }
179
+ }
180
+ };
181
+ var syncWatermark = useRafDebounce(renderWatermark);
182
+ // ============================= Effect =============================
183
+ // Append watermark to the container
184
+ var _useWatermark = useWatermark(markStyle),
185
+ _useWatermark2 = _slicedToArray(_useWatermark, 3),
186
+ appendWatermark = _useWatermark2[0],
187
+ removeWatermark = _useWatermark2[1],
188
+ isWatermarkEle = _useWatermark2[2];
189
+ useEffect(function () {
190
+ if (watermarkInfo) {
191
+ targetElements.forEach(function (holder) {
192
+ appendWatermark(watermarkInfo[0], watermarkInfo[1], holder);
193
+ });
194
+ }
195
+ }, [watermarkInfo, targetElements]);
196
+ // ============================ Observe =============================
197
+ var onMutate = function onMutate(mutations) {
198
+ mutations.forEach(function (mutation) {
199
+ if (reRendering(mutation, isWatermarkEle)) {
200
+ syncWatermark();
201
+ }
202
+ });
203
+ };
204
+ useMutateObserver(targetElements, onMutate);
205
+ useEffect(syncWatermark, [rotate, zIndex, width, height, image, content, color, fontSize, fontWeight, fontStyle, fontFamily, textAlign, gapX, gapY, offsetLeft, offsetTop]);
206
+ // ============================ Context =============================
207
+ var watermarkContext = React.useMemo(function () {
208
+ return {
209
+ add: function add(ele) {
210
+ setSubElements(function (prev) {
211
+ var clone = new Set(prev);
212
+ clone.add(ele);
213
+ return getSizeDiff(prev, clone);
214
+ });
215
+ },
216
+ remove: function remove(ele) {
217
+ removeWatermark(ele);
218
+ setSubElements(function (prev) {
219
+ var clone = new Set(prev);
220
+ clone["delete"](ele);
221
+ return getSizeDiff(prev, clone);
222
+ });
223
+ }
224
+ };
225
+ }, []);
226
+ // ============================= Render =============================
227
+ var childNode = inherit ? /*#__PURE__*/React.createElement(WatermarkContext.Provider, {
228
+ value: watermarkContext
229
+ }, children) : children;
230
+ return /*#__PURE__*/React.createElement("div", {
231
+ ref: setContainer,
232
+ className: classNames(className, rootClassName),
233
+ style: Object.assign({
234
+ position: 'relative'
235
+ }, style)
236
+ }, childNode);
237
+ };
238
+ if (process.env.NODE_ENV !== 'production') {
239
+ Watermark.displayName = 'Watermark';
240
+ }
241
+
242
+ //默认值
243
+ Watermark.defaultProps = {
244
+ width: 120,
245
+ height: 64,
246
+ inherit: true,
247
+ rotate: -20,
248
+ zIndex: 9,
249
+ font: {
250
+ color: 'rgba(0,0,0,.15)',
251
+ fontSize: 16,
252
+ fontFamily: 'sans-serif',
253
+ fontStyle: 'normal'
254
+ },
255
+ gap: [100, 100],
256
+ offset: [50, 50]
257
+ };
258
+
259
+ //Api
260
+ Watermark.propTypes = {
261
+ /**
262
+ * 宽度,水印的宽度,content 的默认值为自身的宽度
263
+ */
264
+ width: PropTypes.number,
265
+ /**
266
+ * 水印的高度,content 的默认值为自身的高度
267
+ */
268
+ height: PropTypes.number,
269
+ /**
270
+ * 是否将水印传导给弹出组件如 Modal、Drawer
271
+ */
272
+ inherit: PropTypes.bool,
273
+ /**
274
+ * 水印绘制时,旋转的角度,单位 °
275
+ */
276
+ rotate: PropTypes.number,
277
+ /**
278
+ * 追加的水印元素的 z-index
279
+ */
280
+ zIndex: PropTypes.number,
281
+ /**
282
+ * 图片源,建议导出 2 倍或 3 倍图,优先级高 (支持 base64 格式)
283
+ */
284
+ image: PropTypes.string,
285
+ /**
286
+ * 水印文字内容
287
+ */
288
+ content: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
289
+ /**
290
+ * 文字样式<br/>
291
+ * color:字体颜色 <br/>
292
+ * fontSize:字体大小 (number) <br/>
293
+ * fontWeight:字体粗细 (normal | light | weight | number) <br/>
294
+ * fontFamily:字体类型 (string)<br/>
295
+ * fontStyle:字体样式 (none | normal | italic | oblique)<br/>
296
+ * textAlign:指定文本对齐方向 <br/>
297
+ */
298
+ font: PropTypes.object,
299
+ /**
300
+ * gap 水印之间的间距
301
+ */
302
+ gap: verifyIsArrayOfNumberType,
303
+ /**
304
+ * 水印距离容器左上角的偏移量,默认为 gap/2
305
+ */
306
+ offset: verifyIsArrayOfNumberType
307
+ };
308
+ export default Watermark;
@@ -0,0 +1,118 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ export var FontGap = 3;
8
+ function prepareCanvas(width, height) {
9
+ var ratio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
10
+ var canvas = document.createElement('canvas');
11
+ var ctx = canvas.getContext('2d');
12
+ var realWidth = width * ratio;
13
+ var realHeight = height * ratio;
14
+ canvas.setAttribute('width', "".concat(realWidth, "px"));
15
+ canvas.setAttribute('height', "".concat(realHeight, "px"));
16
+ ctx.save();
17
+ return [ctx, canvas, realWidth, realHeight];
18
+ }
19
+ /**
20
+ * Get the clips of text content.
21
+ * This is a lazy hook function since SSR no need this
22
+ */
23
+ export default function useClips() {
24
+ // Get single clips
25
+ function getClips(content, rotate, ratio, width, height, font, gapX, gapY) {
26
+ // ================= Text / Image =================
27
+ var _prepareCanvas = prepareCanvas(width, height, ratio),
28
+ _prepareCanvas2 = _slicedToArray(_prepareCanvas, 4),
29
+ ctx = _prepareCanvas2[0],
30
+ canvas = _prepareCanvas2[1],
31
+ contentWidth = _prepareCanvas2[2],
32
+ contentHeight = _prepareCanvas2[3];
33
+ if (content instanceof HTMLImageElement) {
34
+ // Image
35
+ ctx.drawImage(content, 0, 0, contentWidth, contentHeight);
36
+ } else {
37
+ // Text
38
+ var color = font.color,
39
+ fontSize = font.fontSize,
40
+ fontStyle = font.fontStyle,
41
+ fontWeight = font.fontWeight,
42
+ fontFamily = font.fontFamily,
43
+ textAlign = font.textAlign;
44
+ var mergedFontSize = Number(fontSize) * ratio;
45
+ ctx.font = "".concat(fontStyle, " normal ").concat(fontWeight, " ").concat(mergedFontSize, "px/").concat(height, "px ").concat(fontFamily);
46
+ ctx.fillStyle = color;
47
+ ctx.textAlign = textAlign;
48
+ ctx.textBaseline = 'top';
49
+ var contents = Array.isArray(content) ? content : [content];
50
+ contents === null || contents === void 0 ? void 0 : contents.forEach(function (item, index) {
51
+ ctx.fillText(item !== null && item !== void 0 ? item : '', contentWidth / 2, index * (mergedFontSize + FontGap * ratio));
52
+ });
53
+ }
54
+ // ==================== Rotate ====================
55
+ var angle = Math.PI / 180 * Number(rotate);
56
+ var maxSize = Math.max(width, height);
57
+ var _prepareCanvas3 = prepareCanvas(maxSize, maxSize, ratio),
58
+ _prepareCanvas4 = _slicedToArray(_prepareCanvas3, 3),
59
+ rCtx = _prepareCanvas4[0],
60
+ rCanvas = _prepareCanvas4[1],
61
+ realMaxSize = _prepareCanvas4[2];
62
+ // Copy from `ctx` and rotate
63
+ rCtx.translate(realMaxSize / 2, realMaxSize / 2);
64
+ rCtx.rotate(angle);
65
+ if (contentWidth > 0 && contentHeight > 0) {
66
+ rCtx.drawImage(canvas, -contentWidth / 2, -contentHeight / 2);
67
+ }
68
+ // Get boundary of rotated text
69
+ function getRotatePos(x, y) {
70
+ var targetX = x * Math.cos(angle) - y * Math.sin(angle);
71
+ var targetY = x * Math.sin(angle) + y * Math.cos(angle);
72
+ return [targetX, targetY];
73
+ }
74
+ var left = 0;
75
+ var right = 0;
76
+ var top = 0;
77
+ var bottom = 0;
78
+ var halfWidth = contentWidth / 2;
79
+ var halfHeight = contentHeight / 2;
80
+ var points = [[0 - halfWidth, 0 - halfHeight], [0 + halfWidth, 0 - halfHeight], [0 + halfWidth, 0 + halfHeight], [0 - halfWidth, 0 + halfHeight]];
81
+ points.forEach(function (_ref) {
82
+ var _ref2 = _slicedToArray(_ref, 2),
83
+ x = _ref2[0],
84
+ y = _ref2[1];
85
+ var _getRotatePos = getRotatePos(x, y),
86
+ _getRotatePos2 = _slicedToArray(_getRotatePos, 2),
87
+ targetX = _getRotatePos2[0],
88
+ targetY = _getRotatePos2[1];
89
+ left = Math.min(left, targetX);
90
+ right = Math.max(right, targetX);
91
+ top = Math.min(top, targetY);
92
+ bottom = Math.max(bottom, targetY);
93
+ });
94
+ var cutLeft = left + realMaxSize / 2;
95
+ var cutTop = top + realMaxSize / 2;
96
+ var cutWidth = right - left;
97
+ var cutHeight = bottom - top;
98
+ // ================ Fill Alternate ================
99
+ var realGapX = gapX * ratio;
100
+ var realGapY = gapY * ratio;
101
+ var filledWidth = (cutWidth + realGapX) * 2;
102
+ var filledHeight = cutHeight + realGapY;
103
+ var _prepareCanvas5 = prepareCanvas(filledWidth, filledHeight),
104
+ _prepareCanvas6 = _slicedToArray(_prepareCanvas5, 2),
105
+ fCtx = _prepareCanvas6[0],
106
+ fCanvas = _prepareCanvas6[1];
107
+ function drawImg() {
108
+ var targetX = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
109
+ var targetY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
110
+ fCtx.drawImage(rCanvas, cutLeft, cutTop, cutWidth, cutHeight, targetX, targetY, cutWidth, cutHeight);
111
+ }
112
+ drawImg();
113
+ drawImg(cutWidth + realGapX, -cutHeight / 2 - realGapY / 2);
114
+ drawImg(cutWidth + realGapX, +cutHeight / 2 + realGapY / 2);
115
+ return [fCanvas.toDataURL(), filledWidth / ratio, filledHeight / ratio];
116
+ }
117
+ return getClips;
118
+ }
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import raf from 'rc-util/lib/raf';
3
+ import { useEvent } from 'rc-util';
4
+ /**
5
+ * Callback will only execute last one for each raf
6
+ */
7
+ export default function useRafDebounce(callback) {
8
+ var executeRef = React.useRef(false);
9
+ var rafRef = React.useRef();
10
+ var wrapperCallback = useEvent(callback);
11
+ return function () {
12
+ if (executeRef.current) {
13
+ return;
14
+ }
15
+ executeRef.current = true;
16
+ wrapperCallback();
17
+ rafRef.current = raf(function () {
18
+ executeRef.current = false;
19
+ });
20
+ };
21
+ }
@@ -0,0 +1,52 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import * as React from 'react';
8
+ import { getStyleStr } from './utils';
9
+ /**
10
+ * Base size of the canvas, 1 for parallel layout and 2 for alternate layout
11
+ * Only alternate layout is currently supported
12
+ */
13
+ export var BaseSize = 2;
14
+ export var FontGap = 3;
15
+ // Prevent external hidden elements from adding accent styles
16
+ var EmphasizedStyles = {
17
+ visibility: 'visible !important'
18
+ };
19
+ export default function useWatermark(markStyle) {
20
+ var _React$useState = React.useState(function () {
21
+ return new Map();
22
+ }),
23
+ _React$useState2 = _slicedToArray(_React$useState, 1),
24
+ watermarkMap = _React$useState2[0];
25
+ var appendWatermark = function appendWatermark(base64Url, markWidth, container) {
26
+ if (container) {
27
+ if (!watermarkMap.get(container)) {
28
+ var newWatermarkEle = document.createElement('div');
29
+ watermarkMap.set(container, newWatermarkEle);
30
+ }
31
+ var watermarkEle = watermarkMap.get(container);
32
+ watermarkEle.setAttribute('style', getStyleStr(Object.assign(Object.assign(Object.assign({}, markStyle), {
33
+ backgroundImage: "url('".concat(base64Url, "')"),
34
+ backgroundSize: "".concat(Math.floor(markWidth), "px")
35
+ }), EmphasizedStyles)));
36
+ // Prevents using the browser `Hide Element` to hide watermarks
37
+ watermarkEle.removeAttribute('class');
38
+ container.append(watermarkEle);
39
+ }
40
+ };
41
+ var removeWatermark = function removeWatermark(container) {
42
+ var watermarkEle = watermarkMap.get(container);
43
+ if (watermarkEle && container) {
44
+ container.removeChild(watermarkEle);
45
+ }
46
+ watermarkMap["delete"](container);
47
+ };
48
+ var isWatermarkEle = function isWatermarkEle(ele) {
49
+ return Array.from(watermarkMap.values()).includes(ele);
50
+ };
51
+ return [appendWatermark, removeWatermark, isWatermarkEle];
52
+ }
@@ -0,0 +1,42 @@
1
+ /** converting camel-cased strings to be lowercase and link it with Separato */
2
+ export function toLowercaseSeparator(key) {
3
+ return key.replace(/([A-Z])/g, '-$1').toLowerCase();
4
+ }
5
+ export function getStyleStr(style) {
6
+ return Object.keys(style).map(function (key) {
7
+ return "".concat(toLowercaseSeparator(key), ": ").concat(style[key], ";");
8
+ }).join(' ');
9
+ }
10
+ /** Returns the ratio of the device's physical pixel resolution to the css pixel resolution */
11
+ export function getPixelRatio() {
12
+ return window.devicePixelRatio || 1;
13
+ }
14
+ /** Whether to re-render the watermark */
15
+ export var reRendering = function reRendering(mutation, isWatermarkEle) {
16
+ var flag = false;
17
+ // Whether to delete the watermark node
18
+ if (mutation.removedNodes.length) {
19
+ flag = Array.from(mutation.removedNodes).some(function (node) {
20
+ return isWatermarkEle(node);
21
+ });
22
+ }
23
+ // Whether the watermark dom property value has been modified
24
+ if (mutation.type === 'attributes' && isWatermarkEle(mutation.target)) {
25
+ flag = true;
26
+ }
27
+ return flag;
28
+ };
29
+ /**
30
+ * 自定义验证是否是数值类型组成的数组且长度为2
31
+ */
32
+ export var verifyIsArrayOfNumberType = function verifyIsArrayOfNumberType(props, propName, componentName) {
33
+ if (props[propName] && props[propName].length !== 2) {
34
+ return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". Expected an array of length 2."));
35
+ }
36
+ if (props[propName] && !Array.isArray(props[propName])) {
37
+ return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". Expected an array."));
38
+ }
39
+ if (props[propName] && (typeof props[propName][0] !== 'number' || typeof props[propName][1] !== 'number')) {
40
+ return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". Expected an array of numbers."));
41
+ }
42
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaoswise/ui",
3
- "version": "2.3.16",
3
+ "version": "2.3.17",
4
4
  "description": "公共UI库",
5
5
  "keywords": [
6
6
  "ui",
@@ -76,6 +76,7 @@
76
76
  "@formily/antd": "^1.3.17",
77
77
  "@formily/antd-components": "^1.3.17",
78
78
  "@icon-park/react": "^1.4.2",
79
+ "@rc-component/mutate-observer": "^1.1.0",
79
80
  "ant-design-draggable-modal": "0.0.16",
80
81
  "antd": "^3.26.19",
81
82
  "axios": "^0.21.1",
@@ -142,5 +143,5 @@
142
143
  "access": "public"
143
144
  },
144
145
  "license": "MIT",
145
- "gitHead": "3ac90ca01a9631654721a2050fc95678b7975fd5"
146
+ "gitHead": "dbf844ed6b6556903c5aae1176312a47d3c97065"
146
147
  }