@teamias/rex-design 0.1.11 → 0.1.12

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.
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  export declare const context: {
3
3
  domId: string;
4
4
  portals: Record<string, React.ReactPortal>;
5
- update: () => void;
5
+ update: (() => void) | undefined;
6
+ renderCounter: number;
6
7
  };
7
8
  export declare const FileViewerRoot: () => import("react/jsx-runtime").JSX.Element;
@@ -5,21 +5,42 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5
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
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { useStateData } from "../../../hooks";
8
+ import { useDebounceEffect } from 'ahooks';
8
9
  import React from 'react';
9
- import { jsx as _jsx } from "react/jsx-runtime";
10
10
  import { Fragment as _Fragment } from "react/jsx-runtime";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
11
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
13
  export var context = {
13
14
  domId: 'rex-file-viewer-root',
14
15
  portals: {},
15
- update: function update() {}
16
+ update: undefined,
17
+ renderCounter: 0
16
18
  };
17
19
  export var FileViewerRoot = function FileViewerRoot() {
18
20
  var _useStateData = useStateData(function () {
19
- return {};
21
+ return {
22
+ rendering: true
23
+ };
20
24
  }),
21
- update = _useStateData.update;
22
- context.update = update;
25
+ update = _useStateData.update,
26
+ setState = _useStateData.setState,
27
+ state = _useStateData.state;
28
+ if (!context.update) {
29
+ context.update = update;
30
+ }
31
+ useDebounceEffect(function () {
32
+ context.renderCounter += 1;
33
+ if (context.renderCounter > 1) {
34
+ console.warn('FileViewerRoot component can only exist once in the page, please check the code!');
35
+ setState('rendering', false);
36
+ }
37
+ return function () {
38
+ context.renderCounter -= 1;
39
+ };
40
+ }, [], {
41
+ wait: 0
42
+ });
43
+ if (!state.rendering) return /*#__PURE__*/_jsx(_Fragment, {});
23
44
  return /*#__PURE__*/_jsxs(_Fragment, {
24
45
  children: [/*#__PURE__*/_jsx("div", {
25
46
  id: context.domId
@@ -21,6 +21,7 @@ export { FileViewerRoot } from "./file-viewer-root";
21
21
  /** 资源展示 */
22
22
  export var showFileViewer = function showFileViewer(options) {
23
23
  try {
24
+ var _context$update2;
24
25
  var fileType = options.fileType,
25
26
  fileUrl = options.fileUrl,
26
27
  fileName = options.fileName,
@@ -32,12 +33,13 @@ export var showFileViewer = function showFileViewer(options) {
32
33
  fileName: fileName !== null && fileName !== void 0 ? fileName : info.fileName,
33
34
  fileType: fileType !== null && fileType !== void 0 ? fileType : info.fileType,
34
35
  onDestroy: function onDestroy() {
36
+ var _context$update;
35
37
  delete context.portals[key];
36
- context.update();
38
+ (_context$update = context.update) === null || _context$update === void 0 || _context$update.call(context);
37
39
  }
38
40
  })), document.getElementById(context.domId));
39
41
  context.portals[key] = portal;
40
- context.update();
42
+ (_context$update2 = context.update) === null || _context$update2 === void 0 || _context$update2.call(context);
41
43
  } catch (error) {
42
44
  console.error('[showFileViewer]', error);
43
45
  }
@@ -1,11 +1,11 @@
1
- import { downloadResourceFile, FileViewerRoot, previewOrDownloadFile, showFileViewer } from "../../..";
1
+ import { downloadResourceFile, previewOrDownloadFile, RexProConfigProvider, showFileViewer } from "../../..";
2
2
  import { Button, Flex } from 'antd';
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  import { jsxs as _jsxs } from "react/jsx-runtime";
5
- import { Fragment as _Fragment } from "react/jsx-runtime";
6
5
  export default function Demo() {
7
- return /*#__PURE__*/_jsxs(_Fragment, {
8
- children: [/*#__PURE__*/_jsx(FileViewerRoot, {}), /*#__PURE__*/_jsxs(Flex, {
6
+ return /*#__PURE__*/_jsx(RexProConfigProvider, {
7
+ value: {},
8
+ children: /*#__PURE__*/_jsxs(Flex, {
9
9
  vertical: true,
10
10
  gap: 16,
11
11
  children: [/*#__PURE__*/_jsx(Button, {
@@ -56,6 +56,6 @@ export default function Demo() {
56
56
  },
57
57
  children: "[json]\u81EA\u52A8\u8BC6\u522B\u6587\u4EF6, \u8FDB\u884C\u9884\u89C8\u6216\u4E0B\u8F7D"
58
58
  })]
59
- })]
59
+ })
60
60
  });
61
61
  }
@@ -4,9 +4,11 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
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
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
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 { FileViewerRoot } from "../..";
7
8
  import { RawIntlProvider } from 'react-intl';
8
9
  import { defaultApiClient, defaultIntl, RexProConfigContext } from "./rex-pro-config-context";
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
12
  export var RexProConfigProvider = function RexProConfigProvider(_ref) {
11
13
  var _value$intl, _value$apiClient;
12
14
  var value = _ref.value,
@@ -18,9 +20,9 @@ export var RexProConfigProvider = function RexProConfigProvider(_ref) {
18
20
  intl: intl,
19
21
  apiClient: apiClient
20
22
  }),
21
- children: /*#__PURE__*/_jsx(RawIntlProvider, {
23
+ children: /*#__PURE__*/_jsxs(RawIntlProvider, {
22
24
  value: intl,
23
- children: children
25
+ children: [children, /*#__PURE__*/_jsx(FileViewerRoot, {})]
24
26
  })
25
27
  });
26
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamias/rex-design",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",