@teamias/rex-design 0.0.37 → 0.0.39
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/dist/components/base-table/base-table.d.ts +5 -1
- package/dist/components/data-cell/demo/index.js +16 -3
- package/dist/components/data-cell/modules/cellItemMap.js +41 -19
- package/dist/components/data-cell/types.d.ts +1 -1
- package/dist/components/file-viewer/core/file-viewer-container.d.ts +3 -0
- package/dist/components/file-viewer/core/file-viewer-container.js +186 -0
- package/dist/components/file-viewer/core/file-viewer-root.d.ts +7 -0
- package/dist/components/file-viewer/core/file-viewer-root.js +35 -0
- package/dist/components/file-viewer/core/index.d.ts +3 -0
- package/dist/components/file-viewer/core/index.js +22 -0
- package/dist/components/file-viewer/demo/Demo.d.ts +1 -0
- package/dist/components/file-viewer/demo/Demo.js +26 -0
- package/dist/components/file-viewer/index.d.ts +5 -0
- package/dist/components/file-viewer/index.js +7 -0
- package/dist/components/file-viewer/style.d.ts +2 -0
- package/dist/components/file-viewer/style.js +5 -0
- package/dist/components/file-viewer/types.d.ts +14 -0
- package/dist/components/file-viewer/types.js +1 -0
- package/dist/components/file-viewer/utils/index.d.ts +11 -0
- package/dist/components/file-viewer/utils/index.js +101 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/package.json +6 -2
|
@@ -33,8 +33,12 @@ export interface IBaseTableProps<T extends object = object> extends Omit<TRawTab
|
|
|
33
33
|
useDataCellConfig?: boolean;
|
|
34
34
|
/** dataCell 组件配置项, 通过这种方式来配置单元格内容,简化bff层的逻辑 */
|
|
35
35
|
dataCellConfig?: TDataCellConfig;
|
|
36
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* @desc dataCell组件中的点击回调
|
|
38
|
+
* @deprecated 请使用 onDataCellClickV2
|
|
39
|
+
*/
|
|
37
40
|
onDataCellClick?: (item: IDataCellItem, dataIndex: string, record: T, index: number) => void;
|
|
41
|
+
/** dataCell组件中的点击回调 */
|
|
38
42
|
onDataCellClickV2?: (data: {
|
|
39
43
|
item: IDataCellItem;
|
|
40
44
|
subItem?: Exclude<TGroupV2['props'], undefined>['items'][number];
|
|
@@ -4,7 +4,12 @@ import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
4
4
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
export default (function () {
|
|
6
6
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
7
|
-
children: [/*#__PURE__*/_jsx(
|
|
7
|
+
children: [/*#__PURE__*/_jsx("a", {
|
|
8
|
+
href: "http://baidu.com",
|
|
9
|
+
target: "_blank",
|
|
10
|
+
rel: "noreferrer",
|
|
11
|
+
children: "baidu"
|
|
12
|
+
}), /*#__PURE__*/_jsx(DataCell, {
|
|
8
13
|
items: [{
|
|
9
14
|
type: 'text',
|
|
10
15
|
props: {
|
|
@@ -26,8 +31,16 @@ export default (function () {
|
|
|
26
31
|
}, {
|
|
27
32
|
type: 'link',
|
|
28
33
|
props: {
|
|
29
|
-
label: '
|
|
30
|
-
value: 'http://'
|
|
34
|
+
label: 'link-baidu-blank',
|
|
35
|
+
value: 'http://baidu.com'
|
|
36
|
+
// urlTarget: '_self',
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
type: 'link',
|
|
40
|
+
props: {
|
|
41
|
+
label: 'link-baidu-self',
|
|
42
|
+
value: 'http://baidu.com',
|
|
43
|
+
urlTarget: '_self'
|
|
31
44
|
}
|
|
32
45
|
}, {
|
|
33
46
|
type: 'icon',
|
|
@@ -13,6 +13,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
13
13
|
import { Icons, MediaViewer } from "../../..";
|
|
14
14
|
import { Tag, Tooltip, Typography } from 'antd';
|
|
15
15
|
import React from 'react';
|
|
16
|
+
import { Navigate } from 'react-router';
|
|
16
17
|
import { DataCell } from "../data-cell";
|
|
17
18
|
import { DataCellRowText, DataCellRowTextLabel, DataCellRowTextValue } from "../style";
|
|
18
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -26,7 +27,6 @@ var isEmpty = function isEmpty(val) {
|
|
|
26
27
|
|
|
27
28
|
/** 动作块渲染 */
|
|
28
29
|
var actionRender = function actionRender(item, action, node, click) {
|
|
29
|
-
var _item$urlTarget;
|
|
30
30
|
var tooltipBox = function tooltipBox(content) {
|
|
31
31
|
if (item.tooltip) {
|
|
32
32
|
return /*#__PURE__*/_jsx(Tooltip, {
|
|
@@ -43,15 +43,9 @@ var actionRender = function actionRender(item, action, node, click) {
|
|
|
43
43
|
}
|
|
44
44
|
return content;
|
|
45
45
|
};
|
|
46
|
-
if (action === 'default') {
|
|
47
|
-
return tooltipBox( /*#__PURE__*/_jsx("span", {
|
|
48
|
-
style: item.style,
|
|
49
|
-
children: node
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
/** 创建自定义 node */
|
|
48
|
+
var createCustomNode = function createCustomNode() {
|
|
55
49
|
return tooltipBox( /*#__PURE__*/_jsx("a", {
|
|
56
50
|
href: "void",
|
|
57
51
|
style: item.style,
|
|
@@ -61,21 +55,49 @@ var actionRender = function actionRender(item, action, node, click) {
|
|
|
61
55
|
},
|
|
62
56
|
children: node
|
|
63
57
|
}));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** 创建 link node */
|
|
61
|
+
var createLinkNode = function createLinkNode() {
|
|
62
|
+
var _item$urlTarget;
|
|
63
|
+
var target = (_item$urlTarget = item.urlTarget) !== null && _item$urlTarget !== void 0 ? _item$urlTarget : '_blank';
|
|
64
|
+
return tooltipBox( /*#__PURE__*/_jsx("a", {
|
|
65
|
+
style: item.style,
|
|
66
|
+
href: target === '_blank' ? item.value : 'void',
|
|
67
|
+
target: target,
|
|
68
|
+
rel: "noreferrer",
|
|
69
|
+
onClick: function onClick(e) {
|
|
70
|
+
if (target !== '_blank') {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
try {
|
|
73
|
+
Navigate({
|
|
74
|
+
to: item.value || '',
|
|
75
|
+
replace: false
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
window.location.href = item.value || '';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
children: node
|
|
83
|
+
}));
|
|
84
|
+
};
|
|
85
|
+
if (action === 'default') {
|
|
86
|
+
return tooltipBox( /*#__PURE__*/_jsx("span", {
|
|
87
|
+
style: item.style,
|
|
88
|
+
children: node
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 自定义
|
|
93
|
+
if (action === 'custom') {
|
|
94
|
+
return createCustomNode();
|
|
64
95
|
}
|
|
65
96
|
|
|
66
97
|
// TODO: 窗口-未实现
|
|
67
|
-
// if (action === 'modal') {
|
|
68
|
-
// return <a href="javascript:void;" onClick={() => click?.()}>{node}</a>
|
|
69
|
-
// }
|
|
70
98
|
|
|
71
99
|
// 默认url
|
|
72
|
-
return
|
|
73
|
-
style: item.style,
|
|
74
|
-
href: item.value,
|
|
75
|
-
target: (_item$urlTarget = item.urlTarget) !== null && _item$urlTarget !== void 0 ? _item$urlTarget : '_blank',
|
|
76
|
-
rel: "noreferrer",
|
|
77
|
-
children: node
|
|
78
|
-
}));
|
|
100
|
+
return createLinkNode();
|
|
79
101
|
};
|
|
80
102
|
export var cellItemMap = {
|
|
81
103
|
/** 文本块 */
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _excluded = ["fileUrl", "fileName", "fileType", "onDestroy"];
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
10
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
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."); }
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
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; } }
|
|
16
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
18
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
19
|
+
import { useStateData } from "../../../hooks";
|
|
20
|
+
import { DownloadOutlined } from '@ant-design/icons';
|
|
21
|
+
import { FloatButton, Modal, Spin } from 'antd';
|
|
22
|
+
import { sleep } from 'radash';
|
|
23
|
+
import { useEffect, useState } from 'react';
|
|
24
|
+
import QuickPinchZoom, { make3dTransformValue } from 'react-quick-pinch-zoom';
|
|
25
|
+
import { ContainerBox } from "../style";
|
|
26
|
+
import { getFileTypeBySuffix, loadImagePreviewer, loadPdfPreviewer } from "../utils";
|
|
27
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
29
|
+
export var FileViewerContainer = function FileViewerContainer(_ref) {
|
|
30
|
+
var fileUrl = _ref.fileUrl,
|
|
31
|
+
fileName = _ref.fileName,
|
|
32
|
+
fileType = _ref.fileType,
|
|
33
|
+
onDestroy = _ref.onDestroy,
|
|
34
|
+
modalProps = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
+
var _useStateData = useStateData(function () {
|
|
36
|
+
return {
|
|
37
|
+
open: true,
|
|
38
|
+
domId: 'viewer-container-' + Date.now(),
|
|
39
|
+
loading: false,
|
|
40
|
+
error: '',
|
|
41
|
+
download: undefined,
|
|
42
|
+
destroy: undefined
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
state = _useStateData.state,
|
|
46
|
+
setState = _useStateData.setState;
|
|
47
|
+
var _useState = useState(function () {
|
|
48
|
+
var _ref2;
|
|
49
|
+
var obj = new URL(fileUrl);
|
|
50
|
+
var pathname = obj.pathname;
|
|
51
|
+
// console.log('obj', obj);
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
fileName: decodeURIComponent((_ref2 = fileName !== null && fileName !== void 0 ? fileName : pathname.split('/').pop()) !== null && _ref2 !== void 0 ? _ref2 : ''),
|
|
55
|
+
fileType: fileType !== null && fileType !== void 0 ? fileType : getFileTypeBySuffix(pathname)
|
|
56
|
+
};
|
|
57
|
+
}),
|
|
58
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
59
|
+
config = _useState2[0];
|
|
60
|
+
var zoomUpdate = function zoomUpdate(_ref3) {
|
|
61
|
+
var x = _ref3.x,
|
|
62
|
+
y = _ref3.y,
|
|
63
|
+
scale = _ref3.scale;
|
|
64
|
+
var value = make3dTransformValue({
|
|
65
|
+
x: x,
|
|
66
|
+
y: y,
|
|
67
|
+
scale: scale
|
|
68
|
+
});
|
|
69
|
+
// console.log(value);
|
|
70
|
+
document.getElementById(state.domId).style.setProperty('transform', value);
|
|
71
|
+
};
|
|
72
|
+
var pdfRun = /*#__PURE__*/function () {
|
|
73
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
74
|
+
var pdfPreviewer;
|
|
75
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
76
|
+
while (1) switch (_context.prev = _context.next) {
|
|
77
|
+
case 0:
|
|
78
|
+
setState('loading', true);
|
|
79
|
+
_context.prev = 1;
|
|
80
|
+
_context.next = 4;
|
|
81
|
+
return sleep(200);
|
|
82
|
+
case 4:
|
|
83
|
+
_context.next = 6;
|
|
84
|
+
return loadPdfPreviewer(state.domId, fileUrl);
|
|
85
|
+
case 6:
|
|
86
|
+
pdfPreviewer = _context.sent;
|
|
87
|
+
state.download = function () {
|
|
88
|
+
return pdfPreviewer.save(config.fileName);
|
|
89
|
+
};
|
|
90
|
+
state.destroy = function () {
|
|
91
|
+
return pdfPreviewer.destroy();
|
|
92
|
+
};
|
|
93
|
+
_context.next = 14;
|
|
94
|
+
break;
|
|
95
|
+
case 11:
|
|
96
|
+
_context.prev = 11;
|
|
97
|
+
_context.t0 = _context["catch"](1);
|
|
98
|
+
setState('error', _context.t0.toString());
|
|
99
|
+
case 14:
|
|
100
|
+
setState('loading', false);
|
|
101
|
+
case 15:
|
|
102
|
+
case "end":
|
|
103
|
+
return _context.stop();
|
|
104
|
+
}
|
|
105
|
+
}, _callee, null, [[1, 11]]);
|
|
106
|
+
}));
|
|
107
|
+
return function pdfRun() {
|
|
108
|
+
return _ref4.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
}();
|
|
111
|
+
var imageRun = /*#__PURE__*/function () {
|
|
112
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
113
|
+
var imgPreviewer;
|
|
114
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
115
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
116
|
+
case 0:
|
|
117
|
+
setState('loading', true);
|
|
118
|
+
_context2.prev = 1;
|
|
119
|
+
_context2.next = 4;
|
|
120
|
+
return loadImagePreviewer(state.domId, fileUrl);
|
|
121
|
+
case 4:
|
|
122
|
+
imgPreviewer = _context2.sent;
|
|
123
|
+
state.download = function () {
|
|
124
|
+
return imgPreviewer.save(config.fileName);
|
|
125
|
+
};
|
|
126
|
+
_context2.next = 11;
|
|
127
|
+
break;
|
|
128
|
+
case 8:
|
|
129
|
+
_context2.prev = 8;
|
|
130
|
+
_context2.t0 = _context2["catch"](1);
|
|
131
|
+
setState('error', _context2.t0.toString());
|
|
132
|
+
case 11:
|
|
133
|
+
setState('loading', false);
|
|
134
|
+
case 12:
|
|
135
|
+
case "end":
|
|
136
|
+
return _context2.stop();
|
|
137
|
+
}
|
|
138
|
+
}, _callee2, null, [[1, 8]]);
|
|
139
|
+
}));
|
|
140
|
+
return function imageRun() {
|
|
141
|
+
return _ref5.apply(this, arguments);
|
|
142
|
+
};
|
|
143
|
+
}();
|
|
144
|
+
useEffect(function () {
|
|
145
|
+
// console.log(config);
|
|
146
|
+
|
|
147
|
+
if (config.fileType === 'pdf') {
|
|
148
|
+
pdfRun();
|
|
149
|
+
} else if (config.fileType === 'image') {
|
|
150
|
+
imageRun();
|
|
151
|
+
}
|
|
152
|
+
return function () {
|
|
153
|
+
var _state$destroy;
|
|
154
|
+
(_state$destroy = state.destroy) === null || _state$destroy === void 0 || _state$destroy.call(state);
|
|
155
|
+
};
|
|
156
|
+
}, []);
|
|
157
|
+
return /*#__PURE__*/_jsx(Modal, _objectSpread(_objectSpread({}, modalProps), {}, {
|
|
158
|
+
open: state.open,
|
|
159
|
+
onCancel: function onCancel() {
|
|
160
|
+
return setState('open', false);
|
|
161
|
+
},
|
|
162
|
+
footer: null,
|
|
163
|
+
centered: true,
|
|
164
|
+
width: "90vw",
|
|
165
|
+
afterOpenChange: function afterOpenChange(open) {
|
|
166
|
+
if (!open) {
|
|
167
|
+
onDestroy();
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
children: /*#__PURE__*/_jsxs(Spin, {
|
|
171
|
+
spinning: state.loading,
|
|
172
|
+
tip: "\u6587\u4EF6\u52A0\u8F7D\u4E2D...",
|
|
173
|
+
children: [/*#__PURE__*/_jsx(ContainerBox, {
|
|
174
|
+
children: /*#__PURE__*/_jsx(QuickPinchZoom, {
|
|
175
|
+
onUpdate: zoomUpdate,
|
|
176
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
177
|
+
id: state.domId
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
}), state.download && /*#__PURE__*/_jsx(FloatButton, {
|
|
181
|
+
icon: /*#__PURE__*/_jsx(DownloadOutlined, {}),
|
|
182
|
+
onClick: state.download
|
|
183
|
+
})]
|
|
184
|
+
})
|
|
185
|
+
}));
|
|
186
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { useStateData } from "../../../hooks";
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
export var context = {
|
|
13
|
+
domId: 'rex-file-viewer-root',
|
|
14
|
+
portals: {},
|
|
15
|
+
update: function update() {}
|
|
16
|
+
};
|
|
17
|
+
export var FileViewerRoot = function FileViewerRoot() {
|
|
18
|
+
var _useStateData = useStateData(function () {
|
|
19
|
+
return {};
|
|
20
|
+
}),
|
|
21
|
+
update = _useStateData.update;
|
|
22
|
+
context.update = update;
|
|
23
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
24
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
25
|
+
id: context.domId
|
|
26
|
+
}), Object.entries(context.portals).map(function (_ref) {
|
|
27
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
28
|
+
key = _ref2[0],
|
|
29
|
+
portal = _ref2[1];
|
|
30
|
+
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
31
|
+
children: portal
|
|
32
|
+
}, key);
|
|
33
|
+
})]
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { createPortal } from 'react-dom';
|
|
8
|
+
import { FileViewerContainer } from "./file-viewer-container";
|
|
9
|
+
import { context } from "./file-viewer-root";
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
export { FileViewerRoot } from "./file-viewer-root";
|
|
12
|
+
export var showFileViewer = function showFileViewer(options) {
|
|
13
|
+
var key = "file-viewer-".concat(Date.now());
|
|
14
|
+
var portal = /*#__PURE__*/createPortal( /*#__PURE__*/_jsx(FileViewerContainer, _objectSpread(_objectSpread({}, options), {}, {
|
|
15
|
+
onDestroy: function onDestroy() {
|
|
16
|
+
delete context.portals[key];
|
|
17
|
+
context.update();
|
|
18
|
+
}
|
|
19
|
+
})), document.getElementById(context.domId));
|
|
20
|
+
context.portals[key] = portal;
|
|
21
|
+
context.update();
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function Demo(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FileViewerRoot, showFileViewer } from "../../..";
|
|
2
|
+
import { Button, Space } from 'antd';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
6
|
+
export default function Demo() {
|
|
7
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
8
|
+
children: [/*#__PURE__*/_jsx(FileViewerRoot, {}), /*#__PURE__*/_jsxs(Space.Compact, {
|
|
9
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
10
|
+
onClick: function onClick() {
|
|
11
|
+
return showFileViewer({
|
|
12
|
+
fileUrl: 'https://zzzz-zkp.oss-cn-shenzhen.aliyuncs.com/%E5%85%A5%E8%81%8C%E5%BD%95%E7%94%A8%E9%80%9A%E7%9F%A5.pdf'
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
children: "pdf"
|
|
16
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
17
|
+
onClick: function onClick() {
|
|
18
|
+
return showFileViewer({
|
|
19
|
+
fileUrl: 'https://zzzz-zkp.oss-cn-shenzhen.aliyuncs.com/badge%20%281%29.png'
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
children: "image"
|
|
23
|
+
})]
|
|
24
|
+
})]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export { FileViewerRoot, showFileViewer } from "./core";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export var FakeFileViewer = function FakeFileViewer() {
|
|
6
|
+
return /*#__PURE__*/_jsx(_Fragment, {});
|
|
7
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ContainerBox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GetProps, Modal } from 'antd';
|
|
2
|
+
export interface IFileViewerOptions extends ModalProps {
|
|
3
|
+
/** 文件路径,注意文件跨域问题 */
|
|
4
|
+
fileUrl: string;
|
|
5
|
+
/** 文件名称 */
|
|
6
|
+
fileName?: string;
|
|
7
|
+
/** 文件类型 */
|
|
8
|
+
fileType?: 'pdf' | 'image';
|
|
9
|
+
}
|
|
10
|
+
export interface IFileViewerContainerProps extends IFileViewerOptions {
|
|
11
|
+
onDestroy: () => void;
|
|
12
|
+
}
|
|
13
|
+
type ModalProps = Omit<GetProps<typeof Modal>, 'open' | 'onCancel' | 'footer' | 'centered' | 'width' | 'afterOpenChange'>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JsPdfPreview } from '@js-preview/pdf';
|
|
2
|
+
/** 加载 pdf */
|
|
3
|
+
export declare const loadPdfPreviewer: (domId: string, fileUrl: string) => Promise<JsPdfPreview>;
|
|
4
|
+
/** 加载 image */
|
|
5
|
+
export declare const loadImagePreviewer: (domId: string, fileUrl: string) => Promise<{
|
|
6
|
+
save: (fileName: string) => void;
|
|
7
|
+
}>;
|
|
8
|
+
/** 匹配图片类型 为 image */
|
|
9
|
+
export declare const isImageType: (fileType: string) => boolean;
|
|
10
|
+
/** 根据文件后缀,返回文件类型 */
|
|
11
|
+
export declare const getFileTypeBySuffix: (fileName: string) => "image" | "unknown" | "pdf";
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
/** 加载 pdf */
|
|
6
|
+
export var loadPdfPreviewer = /*#__PURE__*/function () {
|
|
7
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(domId, fileUrl) {
|
|
8
|
+
var _yield$import, jsPreviewPdf;
|
|
9
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
10
|
+
while (1) switch (_context.prev = _context.next) {
|
|
11
|
+
case 0:
|
|
12
|
+
_context.next = 2;
|
|
13
|
+
return import('@js-preview/pdf');
|
|
14
|
+
case 2:
|
|
15
|
+
_yield$import = _context.sent;
|
|
16
|
+
jsPreviewPdf = _yield$import.default;
|
|
17
|
+
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
18
|
+
var myPdfPreviewer = jsPreviewPdf.init(document.getElementById(domId), {
|
|
19
|
+
onError: function onError(e) {
|
|
20
|
+
// console.log('发生错误', e);
|
|
21
|
+
reject(e);
|
|
22
|
+
},
|
|
23
|
+
onRendered: function onRendered() {
|
|
24
|
+
// console.log('渲染完成');
|
|
25
|
+
resolve(myPdfPreviewer);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
myPdfPreviewer.preview(fileUrl);
|
|
29
|
+
}));
|
|
30
|
+
case 5:
|
|
31
|
+
case "end":
|
|
32
|
+
return _context.stop();
|
|
33
|
+
}
|
|
34
|
+
}, _callee);
|
|
35
|
+
}));
|
|
36
|
+
return function loadPdfPreviewer(_x, _x2) {
|
|
37
|
+
return _ref.apply(this, arguments);
|
|
38
|
+
};
|
|
39
|
+
}();
|
|
40
|
+
|
|
41
|
+
/** 加载 image */
|
|
42
|
+
export var loadImagePreviewer = /*#__PURE__*/function () {
|
|
43
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(domId, fileUrl) {
|
|
44
|
+
var container, img, obj;
|
|
45
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
46
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
47
|
+
case 0:
|
|
48
|
+
container = document.getElementById(domId);
|
|
49
|
+
img = document.createElement('img');
|
|
50
|
+
img.src = fileUrl;
|
|
51
|
+
img.style.maxWidth = '100%';
|
|
52
|
+
img.style.height = '100%';
|
|
53
|
+
img.style.objectFit = 'contain';
|
|
54
|
+
img.style.display = 'block';
|
|
55
|
+
img.style.margin = 'auto';
|
|
56
|
+
container.appendChild(img);
|
|
57
|
+
obj = {
|
|
58
|
+
save: function save(fileName) {
|
|
59
|
+
var link = document.createElement('a');
|
|
60
|
+
link.href = fileUrl;
|
|
61
|
+
link.download = fileName;
|
|
62
|
+
document.body.appendChild(link);
|
|
63
|
+
link.click();
|
|
64
|
+
document.body.removeChild(link);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return _context2.abrupt("return", new Promise(function (rel, rej) {
|
|
68
|
+
img.onload = function () {
|
|
69
|
+
// 图片加载完成
|
|
70
|
+
rel(obj);
|
|
71
|
+
};
|
|
72
|
+
img.onerror = function (e) {
|
|
73
|
+
// console.error('图片加载失败', e);
|
|
74
|
+
rej(e);
|
|
75
|
+
};
|
|
76
|
+
}));
|
|
77
|
+
case 11:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context2.stop();
|
|
80
|
+
}
|
|
81
|
+
}, _callee2);
|
|
82
|
+
}));
|
|
83
|
+
return function loadImagePreviewer(_x3, _x4) {
|
|
84
|
+
return _ref2.apply(this, arguments);
|
|
85
|
+
};
|
|
86
|
+
}();
|
|
87
|
+
|
|
88
|
+
/** 匹配图片类型 为 image */
|
|
89
|
+
export var isImageType = function isImageType(fileType) {
|
|
90
|
+
return ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'svg'].includes(fileType.toLowerCase());
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** 根据文件后缀,返回文件类型 */
|
|
94
|
+
export var getFileTypeBySuffix = function getFileTypeBySuffix(fileName) {
|
|
95
|
+
var _fileName$split$pop;
|
|
96
|
+
var suffix = (_fileName$split$pop = fileName.split('.').pop()) === null || _fileName$split$pop === void 0 ? void 0 : _fileName$split$pop.toLowerCase();
|
|
97
|
+
if (!suffix) return 'unknown';
|
|
98
|
+
if (suffix === 'pdf') return 'pdf';
|
|
99
|
+
if (isImageType(suffix)) return 'image';
|
|
100
|
+
return 'unknown';
|
|
101
|
+
};
|
package/dist/components/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamias/rex-design",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"description": "A react library developed with dumi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"@ant-design/pro-components": "^2.8.10",
|
|
53
53
|
"@ant-design/pro-form": "^2.32.0",
|
|
54
54
|
"@iconify/react": "^6.0.0",
|
|
55
|
+
"@js-preview/pdf": "^2.0.10",
|
|
55
56
|
"@tiptap/core": "^2.12.0",
|
|
56
57
|
"@tiptap/extension-bullet-list": "2.12.0",
|
|
57
58
|
"@tiptap/extension-color": "^2.12.0",
|
|
@@ -76,6 +77,8 @@
|
|
|
76
77
|
"radash": "^12.1.1",
|
|
77
78
|
"rc-virtual-list": "^3.19.1",
|
|
78
79
|
"react-intl": "^7.1.11",
|
|
80
|
+
"react-quick-pinch-zoom": "^5.1.1",
|
|
81
|
+
"react-router": "6",
|
|
79
82
|
"styled-components": "^6.1.19"
|
|
80
83
|
},
|
|
81
84
|
"devDependencies": {
|
|
@@ -107,7 +110,8 @@
|
|
|
107
110
|
"antd": ">=5.0.0",
|
|
108
111
|
"react": ">=16.9.0",
|
|
109
112
|
"react-dom": ">=16.9.0",
|
|
110
|
-
"react-intl": ">=3.0.0"
|
|
113
|
+
"react-intl": ">=3.0.0",
|
|
114
|
+
"react-router": ">=6.0.0"
|
|
111
115
|
},
|
|
112
116
|
"publishConfig": {
|
|
113
117
|
"access": "public"
|