@xfe-repo/web-components 1.2.1 → 1.2.3

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/index.mjs ADDED
@@ -0,0 +1,834 @@
1
+ // src/Loading/index.tsx
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
10
+ function _array_without_holes(arr) {
11
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
12
+ }
13
+ function _assert_this_initialized(self) {
14
+ if (self === void 0) {
15
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
16
+ }
17
+ return self;
18
+ }
19
+ function _class_call_check(instance, Constructor) {
20
+ if (!(instance instanceof Constructor)) {
21
+ throw new TypeError("Cannot call a class as a function");
22
+ }
23
+ }
24
+ function _defineProperties(target, props) {
25
+ for(var i = 0; i < props.length; i++){
26
+ var descriptor = props[i];
27
+ descriptor.enumerable = descriptor.enumerable || false;
28
+ descriptor.configurable = true;
29
+ if ("value" in descriptor) descriptor.writable = true;
30
+ Object.defineProperty(target, descriptor.key, descriptor);
31
+ }
32
+ }
33
+ function _create_class(Constructor, protoProps, staticProps) {
34
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
35
+ if (staticProps) _defineProperties(Constructor, staticProps);
36
+ return Constructor;
37
+ }
38
+ function _define_property(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+ function _get_prototype_of(o) {
52
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
53
+ return o.__proto__ || Object.getPrototypeOf(o);
54
+ };
55
+ return _get_prototype_of(o);
56
+ }
57
+ function _inherits(subClass, superClass) {
58
+ if (typeof superClass !== "function" && superClass !== null) {
59
+ throw new TypeError("Super expression must either be null or a function");
60
+ }
61
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
62
+ constructor: {
63
+ value: subClass,
64
+ writable: true,
65
+ configurable: true
66
+ }
67
+ });
68
+ if (superClass) _set_prototype_of(subClass, superClass);
69
+ }
70
+ function _iterable_to_array(iter) {
71
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
72
+ }
73
+ function _iterable_to_array_limit(arr, i) {
74
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
75
+ if (_i == null) return;
76
+ var _arr = [];
77
+ var _n = true;
78
+ var _d = false;
79
+ var _s, _e;
80
+ try {
81
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
82
+ _arr.push(_s.value);
83
+ if (i && _arr.length === i) break;
84
+ }
85
+ } catch (err) {
86
+ _d = true;
87
+ _e = err;
88
+ } finally{
89
+ try {
90
+ if (!_n && _i["return"] != null) _i["return"]();
91
+ } finally{
92
+ if (_d) throw _e;
93
+ }
94
+ }
95
+ return _arr;
96
+ }
97
+ function _non_iterable_rest() {
98
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
99
+ }
100
+ function _non_iterable_spread() {
101
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
102
+ }
103
+ function _object_spread(target) {
104
+ for(var i = 1; i < arguments.length; i++){
105
+ var source = arguments[i] != null ? arguments[i] : {};
106
+ var ownKeys = Object.keys(source);
107
+ if (typeof Object.getOwnPropertySymbols === "function") {
108
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
109
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
110
+ }));
111
+ }
112
+ ownKeys.forEach(function(key) {
113
+ _define_property(target, key, source[key]);
114
+ });
115
+ }
116
+ return target;
117
+ }
118
+ function ownKeys(object, enumerableOnly) {
119
+ var keys = Object.keys(object);
120
+ if (Object.getOwnPropertySymbols) {
121
+ var symbols = Object.getOwnPropertySymbols(object);
122
+ if (enumerableOnly) {
123
+ symbols = symbols.filter(function(sym) {
124
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
125
+ });
126
+ }
127
+ keys.push.apply(keys, symbols);
128
+ }
129
+ return keys;
130
+ }
131
+ function _object_spread_props(target, source) {
132
+ source = source != null ? source : {};
133
+ if (Object.getOwnPropertyDescriptors) {
134
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
135
+ } else {
136
+ ownKeys(Object(source)).forEach(function(key) {
137
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
138
+ });
139
+ }
140
+ return target;
141
+ }
142
+ function _object_without_properties(source, excluded) {
143
+ if (source == null) return {};
144
+ var target = _object_without_properties_loose(source, excluded);
145
+ var key, i;
146
+ if (Object.getOwnPropertySymbols) {
147
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
148
+ for(i = 0; i < sourceSymbolKeys.length; i++){
149
+ key = sourceSymbolKeys[i];
150
+ if (excluded.indexOf(key) >= 0) continue;
151
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
152
+ target[key] = source[key];
153
+ }
154
+ }
155
+ return target;
156
+ }
157
+ function _object_without_properties_loose(source, excluded) {
158
+ if (source == null) return {};
159
+ var target = {};
160
+ var sourceKeys = Object.keys(source);
161
+ var key, i;
162
+ for(i = 0; i < sourceKeys.length; i++){
163
+ key = sourceKeys[i];
164
+ if (excluded.indexOf(key) >= 0) continue;
165
+ target[key] = source[key];
166
+ }
167
+ return target;
168
+ }
169
+ function _possible_constructor_return(self, call) {
170
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
171
+ return call;
172
+ }
173
+ return _assert_this_initialized(self);
174
+ }
175
+ function _set_prototype_of(o, p) {
176
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
177
+ o.__proto__ = p;
178
+ return o;
179
+ };
180
+ return _set_prototype_of(o, p);
181
+ }
182
+ function _sliced_to_array(arr, i) {
183
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
184
+ }
185
+ function _to_consumable_array(arr) {
186
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
187
+ }
188
+ function _type_of(obj) {
189
+ "@swc/helpers - typeof";
190
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
191
+ }
192
+ function _unsupported_iterable_to_array(o, minLen) {
193
+ if (!o) return;
194
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
195
+ var n = Object.prototype.toString.call(o).slice(8, -1);
196
+ if (n === "Object" && o.constructor) n = o.constructor.name;
197
+ if (n === "Map" || n === "Set") return Array.from(n);
198
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
199
+ }
200
+ function _is_native_reflect_construct() {
201
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
202
+ if (Reflect.construct.sham) return false;
203
+ if (typeof Proxy === "function") return true;
204
+ try {
205
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
206
+ return true;
207
+ } catch (e) {
208
+ return false;
209
+ }
210
+ }
211
+ function _create_super(Derived) {
212
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
213
+ return function _createSuperInternal() {
214
+ var Super = _get_prototype_of(Derived), result;
215
+ if (hasNativeReflectConstruct) {
216
+ var NewTarget = _get_prototype_of(this).constructor;
217
+ result = Reflect.construct(Super, arguments, NewTarget);
218
+ } else {
219
+ result = Super.apply(this, arguments);
220
+ }
221
+ return _possible_constructor_return(this, result);
222
+ };
223
+ }
224
+ import { PureComponent } from "react";
225
+ // src/Loading/index.module.less
226
+ var index_module_default = {
227
+ loading: "index_module_loading"
228
+ };
229
+ // src/Loading/index.tsx
230
+ import { Spin } from "antd";
231
+ import { jsx } from "react/jsx-runtime";
232
+ var Loading = /*#__PURE__*/ function(PureComponent) {
233
+ "use strict";
234
+ _inherits(Loading, PureComponent);
235
+ var _super = _create_super(Loading);
236
+ function Loading() {
237
+ _class_call_check(this, Loading);
238
+ return _super.apply(this, arguments);
239
+ }
240
+ _create_class(Loading, [
241
+ {
242
+ key: "render",
243
+ value: function render() {
244
+ var loading = this.props.loading;
245
+ if (!loading) return null;
246
+ return /* @__PURE__ */ jsx("div", {
247
+ className: index_module_default.loading,
248
+ children: /* @__PURE__ */ jsx(Spin, {
249
+ spinning: loading,
250
+ delay: 200,
251
+ className: index_module_default.loading_icon
252
+ })
253
+ });
254
+ }
255
+ }
256
+ ]);
257
+ return Loading;
258
+ }(PureComponent);
259
+ // src/MultiWindow/MultiWindow.tsx
260
+ import { memo as memo3, useCallback as useCallback3, useEffect, useMemo as useMemo3, useRef, useState as useState2 } from "react";
261
+ import { microApp, navigateToWithMicroApp } from "@xfe-repo/web-micro";
262
+ import { queryString } from "@xfe-repo/web-utils/tools";
263
+ import classnames from "classnames";
264
+ // src/MultiWindow/MultiWindow.module.less
265
+ var MultiWindow_module_default = {
266
+ multi_window: "MultiWindow_module_multi_window",
267
+ tabs: "MultiWindow_module_tabs",
268
+ search_tabs: "MultiWindow_module_search_tabs",
269
+ operate: "MultiWindow_module_operate",
270
+ search: "MultiWindow_module_search",
271
+ input: "MultiWindow_module_input",
272
+ collection: "MultiWindow_module_collection"
273
+ };
274
+ // src/MultiWindow/MultiWindow.tsx
275
+ import { Button as Button2, ConfigProvider, Popconfirm, Tooltip as Tooltip2 } from "antd";
276
+ import { CloseOutlined, QuestionCircleOutlined, RedoOutlined } from "@ant-design/icons";
277
+ // src/MultiWindow/MultiWindowTabs.tsx
278
+ import React2, { memo, useCallback, useMemo } from "react";
279
+ import { Tabs, Select, Badge } from "antd";
280
+ import { closestCenter, DndContext, PointerSensor, useSensor } from "@dnd-kit/core";
281
+ import { arrayMove, horizontalListSortingStrategy, SortableContext, useSortable } from "@dnd-kit/sortable";
282
+ import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
283
+ import { CSS } from "@dnd-kit/utilities";
284
+ import { jsx as jsx2 } from "react/jsx-runtime";
285
+ import { createElement } from "react";
286
+ var MultiWindowTabs = memo(function(props) {
287
+ var pathKey = props.pathKey, pagePaths = props.pagePaths, className = props.className, onChange = props.onChange, onClose = props.onClose, onSort = props.onSort, onCollectionChange = props.onCollectionChange, sortAutoActive = props.sortAutoActive;
288
+ var sensor = useSensor(PointerSensor, {
289
+ activationConstraint: {
290
+ distance: 10
291
+ }
292
+ });
293
+ var pagePathsHelperData = useMemo(function() {
294
+ var keys = [];
295
+ var map = /* @__PURE__ */ new Map();
296
+ pagePaths.forEach(function(item) {
297
+ keys.push(item.key);
298
+ map.set(item.key, item);
299
+ });
300
+ return {
301
+ keys: keys,
302
+ map: map
303
+ };
304
+ }, [
305
+ pagePaths
306
+ ]);
307
+ var handleEdit = useCallback(function(targetKey, action) {
308
+ if (action === "add") {} else if (action === "remove") {
309
+ onClose === null || onClose === void 0 ? void 0 : onClose(String(targetKey));
310
+ }
311
+ }, [
312
+ onClose
313
+ ]);
314
+ var handleTabChange = useCallback(function(activeKey) {
315
+ onChange === null || onChange === void 0 ? void 0 : onChange(activeKey);
316
+ }, [
317
+ onChange
318
+ ]);
319
+ var onDragStart = useCallback(function(event) {
320
+ var active = event.active;
321
+ sortAutoActive && (onChange === null || onChange === void 0 ? void 0 : onChange(String(active.id)));
322
+ }, [
323
+ onChange,
324
+ sortAutoActive
325
+ ]);
326
+ var onDragEnd = useCallback(function(event) {
327
+ var active = event.active, over = event.over;
328
+ if (active.id === (over === null || over === void 0 ? void 0 : over.id)) return;
329
+ var oldIndex = pagePaths.findIndex(function(i) {
330
+ return i.key === active.id;
331
+ });
332
+ var newIndex = pagePaths.findIndex(function(i) {
333
+ return i.key === (over === null || over === void 0 ? void 0 : over.id);
334
+ });
335
+ var newPagePaths = arrayMove(pagePaths, oldIndex, newIndex);
336
+ onSort === null || onSort === void 0 ? void 0 : onSort(newPagePaths);
337
+ }, [
338
+ pagePaths,
339
+ onSort
340
+ ]);
341
+ var renderTabBar = useCallback(function(tabBarProps, DefaultTabBar) {
342
+ return /* @__PURE__ */ jsx2(DndContext, {
343
+ sensors: [
344
+ sensor
345
+ ],
346
+ onDragStart: onDragStart,
347
+ onDragEnd: onDragEnd,
348
+ collisionDetection: closestCenter,
349
+ modifiers: [
350
+ restrictToHorizontalAxis
351
+ ],
352
+ children: /* @__PURE__ */ jsx2(SortableContext, {
353
+ items: pagePathsHelperData.keys,
354
+ strategy: horizontalListSortingStrategy,
355
+ children: /* @__PURE__ */ jsx2(DefaultTabBar, _object_spread_props(_object_spread({}, tabBarProps), {
356
+ children: function(node) {
357
+ return /* @__PURE__ */ createElement(TabItem, _object_spread_props(_object_spread({}, node.props), {
358
+ key: node.key,
359
+ data: pagePathsHelperData.map.get(String(node.key)),
360
+ onCollectionChange: onCollectionChange,
361
+ isActivated: pathKey === String(node.key)
362
+ }), node);
363
+ }
364
+ }))
365
+ })
366
+ });
367
+ }, [
368
+ pagePathsHelperData,
369
+ onDragStart,
370
+ onDragEnd,
371
+ onCollectionChange,
372
+ sensor
373
+ ]);
374
+ return /* @__PURE__ */ jsx2(Tabs, {
375
+ className: className,
376
+ activeKey: pathKey,
377
+ onChange: handleTabChange,
378
+ onEdit: handleEdit,
379
+ tabPosition: "top",
380
+ type: "editable-card",
381
+ items: pagePaths,
382
+ renderTabBar: renderTabBar,
383
+ hideAdd: true
384
+ });
385
+ });
386
+ var TabItem = memo(function(props) {
387
+ var data = props.data, children = props.children, style = props.style, isActivated = props.isActivated, onCollectionChange = props.onCollectionChange;
388
+ var _useSortable = useSortable({
389
+ id: props["data-node-key"]
390
+ }), attributes = _useSortable.attributes, listeners = _useSortable.listeners, setNodeRef = _useSortable.setNodeRef, transform = _useSortable.transform, transition = _useSortable.transition, isDragging = _useSortable.isDragging;
391
+ var handleCollectionChange = useCallback(function(collectionKey) {
392
+ if (!data) return;
393
+ onCollectionChange === null || onCollectionChange === void 0 ? void 0 : onCollectionChange(data.key, collectionKey);
394
+ }, [
395
+ data
396
+ ]);
397
+ var collectionSelect = useMemo(function() {
398
+ var _data_searchCollection;
399
+ if (!(data === null || data === void 0 ? void 0 : (_data_searchCollection = data.searchCollection) === null || _data_searchCollection === void 0 ? void 0 : _data_searchCollection.length)) return null;
400
+ if (!isActivated) {
401
+ return /* @__PURE__ */ jsx2(Badge, {
402
+ className: MultiWindow_module_default.collection,
403
+ count: data.searchCollection.length,
404
+ color: "var(--ant-color-primary)",
405
+ size: "small"
406
+ }, data.key);
407
+ }
408
+ var options = data.searchCollection.map(function(item) {
409
+ return {
410
+ label: item,
411
+ value: item
412
+ };
413
+ });
414
+ var currentKey = data.searchCollection[0];
415
+ return /* @__PURE__ */ jsx2(Select, {
416
+ className: MultiWindow_module_default.collection,
417
+ options: options,
418
+ value: currentKey,
419
+ onChange: handleCollectionChange,
420
+ size: "small",
421
+ showSearch: true,
422
+ placeholder: "请选择"
423
+ }, data.key);
424
+ }, [
425
+ data,
426
+ isActivated
427
+ ]);
428
+ var childrenWithCollectionSelect = useMemo(function() {
429
+ var innerChildren = children.props.children;
430
+ if (!Array.isArray(innerChildren)) return innerChildren;
431
+ var newChildren = _to_consumable_array(innerChildren);
432
+ newChildren.splice(newChildren.length - 1, 0, collectionSelect);
433
+ return newChildren;
434
+ }, [
435
+ children,
436
+ collectionSelect
437
+ ]);
438
+ return React2.cloneElement(children, _object_spread({
439
+ ref: setNodeRef,
440
+ style: _object_spread_props(_object_spread({}, style), {
441
+ transform: CSS.Translate.toString(transform && _object_spread_props(_object_spread({}, transform), {
442
+ scaleX: 1
443
+ })),
444
+ transition: transition,
445
+ zIndex: isDragging ? 1 : "auto",
446
+ cursor: "pointer"
447
+ }),
448
+ children: childrenWithCollectionSelect
449
+ }, attributes, listeners));
450
+ });
451
+ // src/MultiWindow/MultiWindowSearch.tsx
452
+ import { memo as memo2, useCallback as useCallback2, useMemo as useMemo2, useState } from "react";
453
+ import { Button, Input, Tooltip } from "antd";
454
+ import { SearchOutlined } from "@ant-design/icons";
455
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
456
+ var Search = Input.Search;
457
+ var MultiWindowSearch = memo2(function(props) {
458
+ var onSearch = props.onSearch;
459
+ var _useState = _sliced_to_array(useState(false), 2), showSearch = _useState[0], setShowSearch = _useState[1];
460
+ var _useState1 = _sliced_to_array(useState(""), 2), searchValue = _useState1[0], setSearchValue = _useState1[1];
461
+ var shouldShowSearch = useMemo2(function() {
462
+ return showSearch || searchValue;
463
+ }, [
464
+ showSearch,
465
+ searchValue
466
+ ]);
467
+ var handleShowSearch = useCallback2(function() {
468
+ setShowSearch(true);
469
+ }, []);
470
+ var handleHideSearch = useCallback2(function() {
471
+ setShowSearch(false);
472
+ }, []);
473
+ var handleSearch = useCallback2(function(value) {
474
+ setSearchValue(value);
475
+ onSearch === null || onSearch === void 0 ? void 0 : onSearch(value);
476
+ }, [
477
+ onSearch
478
+ ]);
479
+ return /* @__PURE__ */ jsxs("div", {
480
+ className: MultiWindow_module_default.search,
481
+ onMouseLeave: handleHideSearch,
482
+ onMouseEnter: handleShowSearch,
483
+ children: [
484
+ shouldShowSearch && /* @__PURE__ */ jsx3(Search, {
485
+ className: MultiWindow_module_default.input,
486
+ placeholder: "标签/单号",
487
+ onSearch: handleSearch,
488
+ allowClear: true,
489
+ autoFocus: true
490
+ }),
491
+ !shouldShowSearch && /* @__PURE__ */ jsx3(Tooltip, {
492
+ title: "搜索标签/单号",
493
+ color: "var(--ant-color-primary)",
494
+ mouseEnterDelay: 0.5,
495
+ children: /* @__PURE__ */ jsx3(Button, {
496
+ icon: /* @__PURE__ */ jsx3(SearchOutlined, {}),
497
+ type: "text"
498
+ })
499
+ })
500
+ ]
501
+ });
502
+ });
503
+ // src/MultiWindow/MultiWindow.tsx
504
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
505
+ var MultiWindow = memo3(function(props) {
506
+ var routerPath = props.routerPath, collectionBlackList = props.collectionBlackList, contentRef = props.contentRef, appName = props.appName, theme = props.theme, className = props.className;
507
+ var sessionStoragePagePaths = useMemo3(function() {
508
+ var pagePaths2 = sessionStorage.getItem("pagePaths");
509
+ return pagePaths2 ? JSON.parse(pagePaths2) : [];
510
+ }, []);
511
+ var _useState2 = _sliced_to_array(useState2(sessionStoragePagePaths), 2), pagePaths = _useState2[0], setPagePaths = _useState2[1];
512
+ var _useState21 = _sliced_to_array(useState2([]), 2), searchPagePaths = _useState21[0], setSearchPagePaths = _useState21[1];
513
+ var currentStateRef = useRef({
514
+ pagePaths: pagePaths,
515
+ fullPath: "",
516
+ pathKey: "",
517
+ collectionKey: "",
518
+ searchValue: ""
519
+ });
520
+ var isFromInternalNavigate = useRef(false);
521
+ var handleUpdateSearchPagePaths = useCallback3(function() {
522
+ var searchValue2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
523
+ currentStateRef.current.searchValue = searchValue2;
524
+ if (!searchValue2) return setSearchPagePaths([]);
525
+ var _currentStateRef_current = currentStateRef.current, pagePaths2 = _currentStateRef_current.pagePaths;
526
+ var pagePathsCollection = pagePaths2.map(function(item) {
527
+ var searchCollection = item.searchCollection, key = item.key, label = item.label, other = _object_without_properties(item, [
528
+ "searchCollection",
529
+ "key",
530
+ "label"
531
+ ]);
532
+ if (!(searchCollection === null || searchCollection === void 0 ? void 0 : searchCollection.length)) return item;
533
+ return searchCollection.sort().map(function(collection) {
534
+ return _object_spread_props(_object_spread({}, other), {
535
+ key: "".concat(key, "?").concat(collection),
536
+ fullPath: "".concat(key, "?").concat(collection),
537
+ label: "".concat(label, " (").concat(collection, ")")
538
+ });
539
+ });
540
+ });
541
+ var pagePathsFlat = pagePathsCollection.flat();
542
+ var searchResult = pagePathsFlat.filter(function(item) {
543
+ return item.label.toLowerCase().includes(searchValue2.toLowerCase());
544
+ });
545
+ if (!searchResult.length) {
546
+ var notFoundPagePath = {
547
+ label: "未找到匹配的标签",
548
+ key: "notFound",
549
+ fullPath: "/",
550
+ disabled: true,
551
+ closable: false
552
+ };
553
+ searchResult.push(notFoundPagePath);
554
+ }
555
+ setSearchPagePaths(searchResult);
556
+ }, []);
557
+ var handleUpdatePagePaths = useCallback3(function(newPagePaths) {
558
+ if (newPagePaths.length > 10) newPagePaths = newPagePaths.slice(newPagePaths.length - 10);
559
+ sessionStorage.setItem("pagePaths", JSON.stringify(newPagePaths));
560
+ currentStateRef.current.pagePaths = newPagePaths;
561
+ setPagePaths(newPagePaths);
562
+ if (currentStateRef === null || currentStateRef === void 0 ? void 0 : currentStateRef.current.searchValue) {
563
+ handleUpdateSearchPagePaths(currentStateRef.current.searchValue);
564
+ }
565
+ }, []);
566
+ var handleRouterUpdate = useCallback3(function(fullPath) {
567
+ var currentIsFromInternalRouter = isFromInternalNavigate.current;
568
+ isFromInternalNavigate.current = false;
569
+ if (currentStateRef.current.fullPath === fullPath) return;
570
+ var _fullPath_split = _sliced_to_array(fullPath.split("?"), 2), path = _fullPath_split[0], tmp = _fullPath_split[1], search = tmp === void 0 ? "" : tmp;
571
+ if (!path || path === "/") return;
572
+ var _currentStateRef_current = currentStateRef.current, pathKey2 = _currentStateRef_current.pathKey, prev = _currentStateRef_current.pagePaths;
573
+ var newPagePaths = _to_consumable_array(prev);
574
+ var newPagePath = {
575
+ label: "加载中",
576
+ key: path,
577
+ fullPath: fullPath
578
+ };
579
+ var pagePathIndex = prev.findIndex(function(item) {
580
+ return item.key === path;
581
+ });
582
+ if (pagePathIndex !== -1) {
583
+ var _contentRef_current;
584
+ var prevPagePath = prev[pagePathIndex];
585
+ Object.assign(newPagePath, prevPagePath || {});
586
+ newPagePath.fullPath = fullPath;
587
+ newPagePaths.splice(pagePathIndex, 1);
588
+ if ((prevPagePath === null || prevPagePath === void 0 ? void 0 : prevPagePath.fullPath) !== fullPath) contentRef === null || contentRef === void 0 ? void 0 : (_contentRef_current = contentRef.current) === null || _contentRef_current === void 0 ? void 0 : _contentRef_current.refresh(path);
589
+ }
590
+ var targetPagePathIndex = pagePathIndex === -1 ? newPagePaths.length : pagePathIndex;
591
+ if (!currentIsFromInternalRouter) {
592
+ var currentPathIndex = prev.findIndex(function(item) {
593
+ return item.key === pathKey2;
594
+ });
595
+ if (currentPathIndex !== -1) targetPagePathIndex = currentPathIndex + 1;
596
+ }
597
+ newPagePaths.splice(targetPagePathIndex, 0, newPagePath);
598
+ currentStateRef.current.pathKey = path;
599
+ currentStateRef.current.fullPath = fullPath;
600
+ currentStateRef.current.collectionKey = "";
601
+ var enableCollection = checkCanEnableCollection(path, collectionBlackList);
602
+ if (!enableCollection) {
603
+ newPagePath.searchCollection = [];
604
+ return handleUpdatePagePaths(newPagePaths);
605
+ }
606
+ var collection = newPagePath.searchCollection || [];
607
+ var queryJson = queryString.parse(search);
608
+ if (queryJson.ts) delete queryJson.ts;
609
+ var collectionKey2 = createSearchCollectionKey(search);
610
+ if (!collectionKey2) return handleUpdatePagePaths(newPagePaths);
611
+ var queryIndex = collection.findIndex(function(item) {
612
+ return item === collectionKey2;
613
+ });
614
+ if (queryIndex !== -1) collection.splice(queryIndex, 1);
615
+ collection.unshift(collectionKey2);
616
+ if (collection.length > 10) collection.pop();
617
+ newPagePath.searchCollection = collection;
618
+ currentStateRef.current.collectionKey = "".concat(path, "?").concat(collectionKey2);
619
+ handleUpdatePagePaths(newPagePaths);
620
+ }, []);
621
+ useEffect(function() {
622
+ handleRouterUpdate(routerPath);
623
+ }, [
624
+ routerPath
625
+ ]);
626
+ useEffect(function() {
627
+ var cancelCallback = microApp.router.beforeEach(function(to) {
628
+ var fullPath = to.fullPath;
629
+ handleRouterUpdate(fullPath);
630
+ });
631
+ return function() {
632
+ cancelCallback();
633
+ };
634
+ }, []);
635
+ useEffect(function() {
636
+ var titleEl = document.querySelector("title");
637
+ if (!titleEl) return;
638
+ var titleObserver = new MutationObserver(function(mutations) {
639
+ mutations.forEach(function(mutation) {
640
+ if (mutation.target !== titleEl) return;
641
+ var newTitle = mutation.target.textContent || void 0;
642
+ var _currentStateRef_current = currentStateRef.current, pathKey2 = _currentStateRef_current.pathKey, pagePaths2 = _currentStateRef_current.pagePaths;
643
+ var targetPagePath = pagePaths2.find(function(item) {
644
+ return item.key === pathKey2;
645
+ });
646
+ var pageTitle = newTitle === null || newTitle === void 0 ? void 0 : newTitle.replace(" - ".concat(appName), "");
647
+ if (!targetPagePath || !pageTitle || pageTitle === appName) return;
648
+ targetPagePath.label = pageTitle;
649
+ handleUpdatePagePaths(_to_consumable_array(pagePaths2));
650
+ });
651
+ });
652
+ titleObserver.observe(titleEl, {
653
+ childList: true
654
+ });
655
+ return function() {
656
+ titleObserver.disconnect();
657
+ };
658
+ }, []);
659
+ var handleNavigateTo = useCallback3(function(fullPath) {
660
+ isFromInternalNavigate.current = true;
661
+ navigateToWithMicroApp(fullPath, {
662
+ replace: true,
663
+ state: {
664
+ ts: Date.now()
665
+ }
666
+ });
667
+ }, []);
668
+ var handleTabChange = useCallback3(function(pathKey2) {
669
+ var _pagePaths_find;
670
+ var fullPath = ((_pagePaths_find = pagePaths.find(function(item) {
671
+ return item.key === pathKey2;
672
+ })) === null || _pagePaths_find === void 0 ? void 0 : _pagePaths_find.fullPath) || pathKey2 || "/";
673
+ handleNavigateTo(fullPath);
674
+ }, [
675
+ pagePaths
676
+ ]);
677
+ var handleCollectionChange = useCallback3(function(pathKey2, collectionKey2) {
678
+ var fullPath = "".concat(pathKey2, "?").concat(collectionKey2);
679
+ handleNavigateTo(fullPath);
680
+ }, []);
681
+ var handleRefreshCurrent = useCallback3(function() {
682
+ var _pagePaths_find;
683
+ var _currentStateRef_current = currentStateRef.current, pathKey2 = _currentStateRef_current.pathKey;
684
+ var fullPath = ((_pagePaths_find = pagePaths.find(function(item) {
685
+ return item.key === pathKey2;
686
+ })) === null || _pagePaths_find === void 0 ? void 0 : _pagePaths_find.fullPath) || "/";
687
+ var timestamp = Date.now();
688
+ var pathHasSearch = fullPath.includes("?");
689
+ var pathHasTimestamp = fullPath.includes("ts=");
690
+ var fullPathWithTimestamp;
691
+ if (pathHasSearch) {
692
+ fullPathWithTimestamp = pathHasTimestamp ? fullPath.replace(/ts=\d+/, "ts=".concat(timestamp)) : "".concat(fullPath, "&ts=").concat(timestamp);
693
+ } else {
694
+ fullPathWithTimestamp = "".concat(fullPath, "?ts=").concat(timestamp);
695
+ }
696
+ handleNavigateTo(fullPathWithTimestamp);
697
+ }, [
698
+ pagePaths
699
+ ]);
700
+ var handleClose = useCallback3(function(targetKey) {
701
+ var _contentRef_current, _newPagePaths_, _newPagePaths_index;
702
+ var index = pagePaths.findIndex(function(item) {
703
+ return item.key === targetKey;
704
+ });
705
+ if (index === -1) return;
706
+ var newPagePaths = _to_consumable_array(pagePaths);
707
+ newPagePaths.splice(index, 1);
708
+ handleUpdatePagePaths(newPagePaths);
709
+ contentRef === null || contentRef === void 0 ? void 0 : (_contentRef_current = contentRef.current) === null || _contentRef_current === void 0 ? void 0 : _contentRef_current.destroy(targetKey);
710
+ var _currentStateRef_current = currentStateRef.current, pathKey2 = _currentStateRef_current.pathKey;
711
+ if (targetKey !== pathKey2) return;
712
+ var nextPathKey = ((_newPagePaths_ = newPagePaths[index - 1]) === null || _newPagePaths_ === void 0 ? void 0 : _newPagePaths_.key) || ((_newPagePaths_index = newPagePaths[index]) === null || _newPagePaths_index === void 0 ? void 0 : _newPagePaths_index.key) || "/";
713
+ handleTabChange(nextPathKey);
714
+ }, [
715
+ pagePaths
716
+ ]);
717
+ var handleRemoveOther = useCallback3(function() {
718
+ var _contentRef_current;
719
+ var _currentStateRef_current = currentStateRef.current, pathKey2 = _currentStateRef_current.pathKey;
720
+ var newPagePaths = pagePaths.filter(function(item) {
721
+ return item.key === pathKey2;
722
+ });
723
+ handleUpdatePagePaths(newPagePaths);
724
+ contentRef === null || contentRef === void 0 ? void 0 : (_contentRef_current = contentRef.current) === null || _contentRef_current === void 0 ? void 0 : _contentRef_current.destroyOther(pathKey2);
725
+ }, [
726
+ pagePaths
727
+ ]);
728
+ var handleSortPagePaths = useCallback3(function(newPagePaths) {
729
+ handleUpdatePagePaths(newPagePaths);
730
+ }, [
731
+ pagePaths
732
+ ]);
733
+ var _currentStateRef_current = currentStateRef.current, pathKey = _currentStateRef_current.pathKey, collectionKey = _currentStateRef_current.collectionKey, searchValue = _currentStateRef_current.searchValue;
734
+ return /* @__PURE__ */ jsx4(ConfigProvider, {
735
+ theme: theme,
736
+ children: /* @__PURE__ */ jsxs2("div", {
737
+ className: classnames(MultiWindow_module_default.multi_window, className),
738
+ children: [
739
+ /* @__PURE__ */ jsx4(MultiWindowTabs, {
740
+ className: classnames(MultiWindow_module_default.tabs, !!searchValue && MultiWindow_module_default.search_tabs),
741
+ pathKey: searchValue && collectionKey ? collectionKey : pathKey,
742
+ pagePaths: searchValue ? searchPagePaths : pagePaths,
743
+ onChange: handleTabChange,
744
+ onCollectionChange: handleCollectionChange,
745
+ onClose: handleClose,
746
+ onSort: handleSortPagePaths
747
+ }),
748
+ /* @__PURE__ */ jsxs2("div", {
749
+ className: MultiWindow_module_default.operate,
750
+ children: [
751
+ /* @__PURE__ */ jsx4(MultiWindowSearch, {
752
+ onSearch: handleUpdateSearchPagePaths
753
+ }),
754
+ /* @__PURE__ */ jsx4(Tooltip2, {
755
+ title: "刷新当前页面",
756
+ color: "var(--ant-color-primary)",
757
+ mouseEnterDelay: 0.5,
758
+ children: /* @__PURE__ */ jsx4(Button2, {
759
+ icon: /* @__PURE__ */ jsx4(RedoOutlined, {}),
760
+ type: "text",
761
+ onClick: handleRefreshCurrent
762
+ })
763
+ }),
764
+ /* @__PURE__ */ jsx4(Tooltip2, {
765
+ title: "关闭其他页面",
766
+ color: "var(--ant-color-primary)",
767
+ mouseEnterDelay: 0.5,
768
+ children: /* @__PURE__ */ jsx4(Popconfirm, {
769
+ title: "关闭其他页面",
770
+ icon: /* @__PURE__ */ jsx4(QuestionCircleOutlined, {
771
+ style: {
772
+ color: "red"
773
+ }
774
+ }),
775
+ okText: "确定",
776
+ cancelText: "取消",
777
+ onConfirm: handleRemoveOther,
778
+ children: /* @__PURE__ */ jsx4(Button2, {
779
+ icon: /* @__PURE__ */ jsx4(CloseOutlined, {}),
780
+ type: "text"
781
+ })
782
+ })
783
+ })
784
+ ]
785
+ })
786
+ ]
787
+ })
788
+ });
789
+ });
790
+ var createSearchCollectionKey = function(search) {
791
+ var queryJson = queryString.parse(search);
792
+ if (queryJson.ts) delete queryJson.ts;
793
+ return queryString.stringify(queryJson, {
794
+ sort: function(itemLeft, itemRight) {
795
+ return itemLeft.localeCompare(itemRight);
796
+ }
797
+ });
798
+ };
799
+ var checkCanEnableCollection = function(path) {
800
+ var blackList = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
801
+ var _path_split_pop;
802
+ var isDetailPage = !!((_path_split_pop = path.split("/").pop()) === null || _path_split_pop === void 0 ? void 0 : _path_split_pop.toLowerCase().includes("detail"));
803
+ return isDetailPage && !blackList.some(function(item) {
804
+ return path.includes(item);
805
+ });
806
+ };
807
+ // src/MultiWindow/MultiWindowContents.tsx
808
+ import { memo as memo4, Suspense, useMemo as useMemo4 } from "react";
809
+ import KeepAlive, { useKeepAliveRef } from "keepalive-for-react";
810
+ import { Spin as Spin2 } from "antd";
811
+ import { jsx as jsx5 } from "react/jsx-runtime";
812
+ var useMultiWindowContentsRef = useKeepAliveRef;
813
+ var MultiWindowContents = memo4(function(props) {
814
+ var children = props.children, routerPath = props.routerPath, contentRef = props.contentRef;
815
+ var _useMemo4 = _sliced_to_array(useMemo4(function() {
816
+ return routerPath.split("?");
817
+ }, [
818
+ routerPath
819
+ ]), 1), tmp = _useMemo4[0], pathKey = tmp === void 0 ? "" : tmp;
820
+ return /* @__PURE__ */ jsx5(KeepAlive, {
821
+ transition: true,
822
+ aliveRef: contentRef,
823
+ activeCacheKey: pathKey,
824
+ max: 10,
825
+ maxAliveTime: 60 * 60,
826
+ children: /* @__PURE__ */ jsx5(Suspense, {
827
+ fallback: /* @__PURE__ */ jsx5(Spin2, {
828
+ spinning: true
829
+ }),
830
+ children: children
831
+ })
832
+ });
833
+ });
834
+ export { Loading, MultiWindow, MultiWindowContents, useMultiWindowContentsRef };