1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports["default"] = create;
|
9 |
|
10 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
11 |
|
12 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
13 |
|
14 | var _react = _interopRequireDefault(require("react"));
|
15 |
|
16 | var _Icon = _interopRequireDefault(require("./Icon"));
|
17 |
|
18 | var customCache = new Set();
|
19 |
|
20 | function isValidCustomScriptUrl(scriptUrl) {
|
21 | return Boolean(typeof scriptUrl === 'string' && scriptUrl.length && !customCache.has(scriptUrl));
|
22 | }
|
23 |
|
24 | function createScriptUrlElements(scriptUrls) {
|
25 | var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
26 | var currentScriptUrl = scriptUrls[index];
|
27 |
|
28 | if (isValidCustomScriptUrl(currentScriptUrl)) {
|
29 | var script = document.createElement('script');
|
30 | script.setAttribute('src', currentScriptUrl);
|
31 | script.setAttribute('data-namespace', currentScriptUrl);
|
32 |
|
33 | if (scriptUrls.length > index + 1) {
|
34 | script.onload = function () {
|
35 | createScriptUrlElements(scriptUrls, index + 1);
|
36 | };
|
37 |
|
38 | script.onerror = function () {
|
39 | createScriptUrlElements(scriptUrls, index + 1);
|
40 | };
|
41 | }
|
42 |
|
43 | customCache.add(currentScriptUrl);
|
44 | document.body.appendChild(script);
|
45 | }
|
46 | }
|
47 |
|
48 | function create() {
|
49 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
50 | var scriptUrl = options.scriptUrl,
|
51 | _options$extraCommonP = options.extraCommonProps,
|
52 | extraCommonProps = _options$extraCommonP === void 0 ? {} : _options$extraCommonP;
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | if (scriptUrl && typeof document !== 'undefined' && typeof window !== 'undefined' && typeof document.createElement === 'function') {
|
61 | if (Array.isArray(scriptUrl)) {
|
62 |
|
63 | createScriptUrlElements(scriptUrl.reverse());
|
64 | } else {
|
65 | createScriptUrlElements([scriptUrl]);
|
66 | }
|
67 | }
|
68 |
|
69 | var Iconfont = _react["default"].forwardRef(function (props, ref) {
|
70 | var type = props.type,
|
71 | children = props.children,
|
72 | restProps = (0, _objectWithoutProperties2["default"])(props, ["type", "children"]);
|
73 |
|
74 | var content = null;
|
75 |
|
76 | if (props.type) {
|
77 | content = _react["default"].createElement("use", {
|
78 | xlinkHref: "#".concat(type)
|
79 | });
|
80 | }
|
81 |
|
82 | if (children) {
|
83 | content = children;
|
84 | }
|
85 |
|
86 | return _react["default"].createElement(_Icon["default"], (0, _extends2["default"])({}, extraCommonProps, restProps, {
|
87 | ref: ref
|
88 | }), content);
|
89 | });
|
90 |
|
91 | Iconfont.displayName = 'SvgIcon';
|
92 | Iconfont.__C7N_ICON = true;
|
93 | return Iconfont;
|
94 | }
|
95 |
|