zs_library 0.1.2 → 0.2.0

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.
@@ -0,0 +1,73 @@
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
4
+ import { css, cx } from '@emotion/css';
5
+ import { motion } from 'framer-motion';
6
+ import RcTooltip from 'rc-tooltip';
7
+ import 'rc-tooltip/assets/bootstrap_white.css';
8
+ import React from 'react';
9
+ import ContextMenu from "../ContextMenu";
10
+ import { useSortable } from "../hook";
11
+ import SortableUtils from "../utils";
12
+ export var SortableItemDefaultContent = function SortableItemDefaultContent(props) {
13
+ var data = props.data,
14
+ _props$noLetters = props.noLetters,
15
+ noLetters = _props$noLetters === void 0 ? false : _props$noLetters,
16
+ itemIconBuilder = props.itemIconBuilder;
17
+ var _useSortable = useSortable(),
18
+ contextMenuFuns = _useSortable.contextMenuFuns,
19
+ theme = _useSortable.theme;
20
+ var _SortableUtils$getThe = SortableUtils.getTheme(theme),
21
+ light = _SortableUtils$getThe.light,
22
+ dark = _SortableUtils$getThe.dark;
23
+ var _data$data = data.data,
24
+ itemData = _data$data === void 0 ? {} : _data$data;
25
+ var _ref = itemData,
26
+ name = _ref.name;
27
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(motion.div, {
28
+ className: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 4rem;\n height: 4rem;\n background-color: ", ";\n border-radius: 0.75rem;\n box-shadow: 0 0 0.5rem ", ";\n cursor: pointer;\n position: relative;\n overflow: hidden;\n @media (prefers-color-scheme: dark) {\n background-color: ", ";\n box-shadow: 0 0 0.5rem ", ";\n }\n "])), light.itemIconBackgroundColor, light.itemIconShadowColor, dark.itemIconBackgroundColor, dark.itemIconShadowColor),
29
+ whileTap: {
30
+ scale: 0.9
31
+ }
32
+ }, /*#__PURE__*/React.createElement("div", _extends({
33
+ className: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n color: ", ";\n @media (prefers-color-scheme: dark) {\n color: ", ";\n }\n "])), light.itemNameColor, dark.itemNameColor)
34
+ }, contextMenuFuns(data)), itemIconBuilder === null || itemIconBuilder === void 0 ? void 0 : itemIconBuilder(data))), /*#__PURE__*/React.createElement(motion.p, {
35
+ className: cx(css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n text-align: center;\n margin-top: 0.25rem;\n margin-bottom: 0;\n color: ", ";\n @media (prefers-color-scheme: dark) {\n color: ", ";\n }\n "])), light.itemNameColor, dark.itemNameColor), noLetters && css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n color: transparent;\n "]))))
36
+ }, name));
37
+ };
38
+ var SortableItem = function SortableItem(props) {
39
+ var data = props.data,
40
+ className = props.className,
41
+ itemIndex = props.itemIndex,
42
+ _onClick = props.onClick,
43
+ _props$disabledDrag = props.disabledDrag,
44
+ disabledDrag = _props$disabledDrag === void 0 ? false : _props$disabledDrag,
45
+ children = props.children,
46
+ parentIds = props.parentIds,
47
+ childrenLength = props.childrenLength;
48
+ var _useSortable2 = useSortable(),
49
+ contextMenu = _useSortable2.contextMenu,
50
+ setContextMenu = _useSortable2.setContextMenu;
51
+ return /*#__PURE__*/React.createElement(RcTooltip, {
52
+ placement: "bottom",
53
+ overlayClassName: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n background-color: transparent;\n .rc-tooltip-inner {\n background-color: transparent;\n padding: 0;\n border: none;\n }\n "]))),
54
+ overlay: /*#__PURE__*/React.createElement(ContextMenu, null),
55
+ visible: (contextMenu === null || contextMenu === void 0 ? void 0 : contextMenu.data.id) === data.id,
56
+ onVisibleChange: function onVisibleChange(visible) {
57
+ if (!visible) {
58
+ setContextMenu(null);
59
+ }
60
+ },
61
+ destroyTooltipOnHide: true
62
+ }, /*#__PURE__*/React.createElement(motion.div, {
63
+ "data-id": data.id,
64
+ "data-index": itemIndex,
65
+ "data-parent-ids": parentIds === null || parentIds === void 0 ? void 0 : parentIds.join(','),
66
+ "data-children-length": childrenLength,
67
+ onClick: function onClick() {
68
+ return _onClick === null || _onClick === void 0 ? void 0 : _onClick(data);
69
+ },
70
+ className: cx(disabledDrag && 'drag-disabled', className)
71
+ }, children !== null && children !== void 0 ? children : /*#__PURE__*/React.createElement(SortableItemDefaultContent, props)));
72
+ };
73
+ export default SortableItem;
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import Slider, { Settings } from 'react-slick';
3
+ import 'slick-carousel/slick/slick-theme.css';
4
+ import 'slick-carousel/slick/slick.css';
5
+ import { SortItem } from './types';
6
+ export interface SortableProps<D, C> {
7
+ /**
8
+ * className
9
+ */
10
+ className?: string;
11
+ /**
12
+ * 分页位置
13
+ */
14
+ pagingLocation?: 'top' | 'bottom' | 'left' | 'right';
15
+ /**
16
+ * slider ref
17
+ */
18
+ sliderRef?: React.RefObject<Slider>;
19
+ /**
20
+ * 自定义 slider 配置
21
+ * @see https://react-slick.neostack.com/docs/api
22
+ */
23
+ sliderProps?: Omit<Settings, 'appendDots' | 'customPaging'>;
24
+ /**
25
+ * 是否不显示名称
26
+ */
27
+ noLetters?: boolean;
28
+ /**
29
+ * 点击 item 事件
30
+ */
31
+ onItemClick?: (item: SortItem<D, C>) => void;
32
+ /**
33
+ * 自定义分页点容器
34
+ */
35
+ pagingDotsBuilder?: (dots: React.ReactNode) => React.JSX.Element;
36
+ /**
37
+ * 自定义分页点
38
+ */
39
+ pagingDotBuilder?: (item: SortItem<D, C>, index: number) => React.JSX.Element;
40
+ /**
41
+ * 自定义 item 渲染
42
+ */
43
+ itemBuilder?: (item: SortItem<D, C>) => React.ReactNode;
44
+ /**
45
+ * 自定义 item 图标渲染
46
+ */
47
+ itemIconBuilder?: (item: SortItem<D, C>) => React.ReactNode;
48
+ }
49
+ declare const Sortable: <D, C>(props: SortableProps<D, C>) => React.JSX.Element;
50
+ export default Sortable;
@@ -0,0 +1,164 @@
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
4
+ import { css, cx } from '@emotion/css';
5
+ import React, { useMemo, useRef } from 'react';
6
+ import Slider from 'react-slick';
7
+ import { ReactSortable } from 'react-sortablejs';
8
+ import 'slick-carousel/slick/slick-theme.css';
9
+ import 'slick-carousel/slick/slick.css';
10
+ import SortableGroupItem from "./Items/GroupItem";
11
+ import GroupItemModal from "./Items/Modal/GroupItemModal";
12
+ import ItemInfoModal from "./Items/Modal/InfoModal";
13
+ import SortableItem from "./Items/SortableItem";
14
+ import { useSortable } from "./hook";
15
+ import { ghostClass } from "./style";
16
+ var Sortable = function Sortable(props) {
17
+ var _props$pagingLocation = props.pagingLocation,
18
+ pagingLocation = _props$pagingLocation === void 0 ? 'bottom' : _props$pagingLocation,
19
+ className = props.className,
20
+ pagingDotBuilder = props.pagingDotBuilder,
21
+ pagingDotsBuilder = props.pagingDotsBuilder,
22
+ sliderProps = props.sliderProps,
23
+ _sliderRef = props.sliderRef,
24
+ onItemClick = props.onItemClick,
25
+ noLetters = props.noLetters,
26
+ itemBuilder = props.itemBuilder,
27
+ itemIconBuilder = props.itemIconBuilder;
28
+ var sliderRef = useRef(null);
29
+ var sliderDotsRef = useRef(null);
30
+ var _useSortable = useSortable(),
31
+ list = _useSortable.list,
32
+ _setList = _useSortable.setList,
33
+ setListStatus = _useSortable.setListStatus,
34
+ showInfoItemData = _useSortable.showInfoItemData,
35
+ setShowInfoItemData = _useSortable.setShowInfoItemData,
36
+ openGroupItemData = _useSortable.openGroupItemData,
37
+ setOpenGroupItemData = _useSortable.setOpenGroupItemData,
38
+ setMoveItemId = _useSortable.setMoveItemId,
39
+ setMoveTargetId = _useSortable.setMoveTargetId;
40
+ var paginingLocationCss = useMemo(function () {
41
+ return {
42
+ top: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n .slick-list {\n order: 1;\n }\n .slick-dots {\n position: static;\n }\n "]))),
43
+ bottom: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n .slick-dots {\n position: static;\n }\n "]))),
44
+ left: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n .slick-dots {\n position: absolute;\n width: auto;\n left: 0;\n top: 0;\n bottom: 0;\n transform: translateX(-100%);\n display: flex;\n justify-content: center;\n align-items: center;\n .slick-dots-default {\n flex-direction: column;\n }\n }\n "]))),
45
+ right: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n .slick-dots {\n position: absolute;\n width: auto;\n right: 0;\n top: 0;\n bottom: 0;\n transform: translateX(100%);\n display: flex;\n justify-content: center;\n align-items: center;\n .slick-dots-default {\n flex-direction: column;\n }\n }\n "])))
46
+ }[pagingLocation];
47
+ }, [pagingLocation]);
48
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Slider, _extends({
49
+ arrows: false,
50
+ ref: _sliderRef !== null && _sliderRef !== void 0 ? _sliderRef : sliderRef,
51
+ infinite: false,
52
+ dots: true,
53
+ touchMove: false,
54
+ lazyLoad: "anticipated",
55
+ className: cx(paginingLocationCss, className),
56
+ customPaging: function customPaging(i) {
57
+ var _list$i;
58
+ if (pagingDotBuilder) {
59
+ return pagingDotBuilder(list[i], i);
60
+ }
61
+ return /*#__PURE__*/React.createElement("div", {
62
+ onDragEnter: function onDragEnter() {
63
+ var _current;
64
+ (_current = (_sliderRef !== null && _sliderRef !== void 0 ? _sliderRef : sliderRef).current) === null || _current === void 0 || _current.slickGoTo(i);
65
+ }
66
+ }, (_list$i = list[i]) === null || _list$i === void 0 || (_list$i = _list$i.data) === null || _list$i === void 0 ? void 0 : _list$i.name);
67
+ },
68
+ appendDots: function appendDots(dots) {
69
+ if (pagingDotsBuilder) {
70
+ return pagingDotsBuilder(dots);
71
+ }
72
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("ul", {
73
+ ref: sliderDotsRef,
74
+ className: cx('slick-dots-default', css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n padding: 0.5rem;\n display: inline-flex;\n justify-content: center;\n align-items: center;\n gap: 0.5rem;\n background-color: rgba(0, 0, 0, 0.1);\n border-radius: 0.5rem;\n .slick-active {\n background-color: rgba(0, 0, 0, 0.3);\n color: white;\n padding: 0.25rem;\n border-radius: 0.25rem;\n }\n li {\n margin: 0;\n width: auto;\n height: auto;\n }\n "]))))
75
+ }, dots));
76
+ }
77
+ }, sliderProps), list.map(function (l) {
78
+ var _l$children, _l$children2;
79
+ return /*#__PURE__*/React.createElement("div", {
80
+ key: l.id
81
+ }, /*#__PURE__*/React.createElement(ReactSortable, {
82
+ className: cx(css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n display: grid;\n transition: all 0.3s;\n grid-template-columns: repeat(auto-fill, 96px);\n grid-auto-flow: dense;\n grid-auto-rows: 96px;\n place-items: center;\n justify-content: center;\n align-items: center;\n "])))),
83
+ animation: 150,
84
+ fallbackOnBody: true,
85
+ swapThreshold: 0.65,
86
+ group: "nested",
87
+ list: (_l$children = l.children) !== null && _l$children !== void 0 ? _l$children : [],
88
+ setList: function setList(e) {
89
+ return _setList(e, [l.id]);
90
+ },
91
+ filter: ".drag-disabled",
92
+ onMove: function onMove(e) {
93
+ setListStatus('onMove');
94
+ var dragged = e.dragged,
95
+ related = e.related;
96
+ var draggedData = dragged.dataset;
97
+ var relatedData = related.dataset;
98
+ setMoveTargetId(null);
99
+ // 限制只有一层
100
+ // sortable-group-item 标记为文件夹
101
+ if ((Object.keys(relatedData).length === 0 || relatedData.parentIds) && Number(draggedData.childrenLength) > 0 && related.classList.contains('sortable-group-item')) {
102
+ return false;
103
+ }
104
+ return true;
105
+ },
106
+ onStart: function onStart(e) {
107
+ var dataset = e.item.dataset;
108
+ if (dataset !== null && dataset !== void 0 && dataset.id) {
109
+ setMoveItemId(dataset.id);
110
+ }
111
+ setListStatus('onMove');
112
+ },
113
+ onEnd: function onEnd() {
114
+ setMoveItemId(null);
115
+ setMoveTargetId(null);
116
+ setListStatus(null);
117
+ },
118
+ ghostClass: ghostClass
119
+ }, ((_l$children2 = l.children) !== null && _l$children2 !== void 0 ? _l$children2 : []).map(function (item, index) {
120
+ var el;
121
+ if (itemBuilder) {
122
+ return itemBuilder(item);
123
+ }
124
+ switch (item.type) {
125
+ case 'group':
126
+ case 'app':
127
+ el = /*#__PURE__*/React.createElement(SortableGroupItem, {
128
+ key: item.id,
129
+ data: item,
130
+ itemIndex: index,
131
+ parentIds: [l.id, item.id],
132
+ onClick: onItemClick,
133
+ noLetters: noLetters,
134
+ itemIconBuilder: itemIconBuilder
135
+ });
136
+ break;
137
+ default:
138
+ el = /*#__PURE__*/React.createElement(SortableItem, {
139
+ key: item.id,
140
+ data: item,
141
+ itemIndex: index,
142
+ onClick: onItemClick,
143
+ noLetters: noLetters,
144
+ itemIconBuilder: itemIconBuilder
145
+ });
146
+ break;
147
+ }
148
+ return el;
149
+ })));
150
+ })), /*#__PURE__*/React.createElement(ItemInfoModal, {
151
+ data: showInfoItemData,
152
+ onClose: function onClose() {
153
+ setShowInfoItemData(null);
154
+ }
155
+ }), /*#__PURE__*/React.createElement(GroupItemModal, {
156
+ data: openGroupItemData,
157
+ onClose: function onClose() {
158
+ setOpenGroupItemData(null);
159
+ },
160
+ onItemClick: onItemClick,
161
+ itemIconBuilder: itemIconBuilder
162
+ }));
163
+ };
164
+ export default Sortable;
@@ -0,0 +1,6 @@
1
+ import { SortItemBaseConfig } from './types';
2
+ export declare const appConfig: SortItemBaseConfig;
3
+ export declare const groupConfig: SortItemBaseConfig;
4
+ export declare const configMap: {
5
+ [key: string]: SortItemBaseConfig;
6
+ };
@@ -0,0 +1,16 @@
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
+ // app 类型 config
8
+ export var appConfig = {
9
+ maxRow: 2,
10
+ maxCol: 2
11
+ };
12
+ export var groupConfig = _objectSpread({}, appConfig);
13
+ export var configMap = {
14
+ app: appConfig,
15
+ group: groupConfig
16
+ };
@@ -0,0 +1,49 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { Theme } from './theme';
3
+ import { SortItem } from './types';
4
+ interface ContextMenu {
5
+ rect: DOMRect;
6
+ data: any;
7
+ pageX?: number;
8
+ pageY?: number;
9
+ }
10
+ type ListStatus = 'onMove';
11
+ export interface SortableContextProps {
12
+ list: SortItem[];
13
+ setList: any;
14
+ contextMenu: ContextMenu | null;
15
+ setContextMenu: (e: ContextMenu | null) => void;
16
+ listStatus: ListStatus | null;
17
+ setListStatus: (e: ListStatus | null) => void;
18
+ contextMenuFuns: (data: any) => any;
19
+ hideContextMenu: () => void;
20
+ /** 点击右键菜单信息数据 */
21
+ showInfoItemData: SortItem | null;
22
+ setShowInfoItemData: (e: SortItem | null) => void;
23
+ /** group item 点击打开弹窗数据 */
24
+ openGroupItemData: SortItem | null;
25
+ setOpenGroupItemData: (e: SortItem | null) => void;
26
+ /** 长按事件状态 */
27
+ longPressTriggered: boolean;
28
+ updateItem: (id: string | number, data: any) => void;
29
+ updateItemConfig: (id: string | number, config: any) => void;
30
+ removeItem: (id: string) => void;
31
+ /** 当前移动的元素id */
32
+ moveItemId: string | null;
33
+ setMoveItemId: (e: string | null) => void;
34
+ /** 当前元素将要移动到的元素id */
35
+ moveTargetId: string | number | null;
36
+ setMoveTargetId: (e: string | number | null) => void;
37
+ theme?: Theme;
38
+ }
39
+ export declare const SortableContext: React.Context<SortableContextProps>;
40
+ interface SortableProviderProps<D, C> {
41
+ children: ReactNode;
42
+ list?: SortItem<D, C>[];
43
+ onChange?: (list: SortItem<D, C>[]) => void;
44
+ readonly storageKey?: string;
45
+ readonly theme?: 'light' | 'dark' | Theme;
46
+ enableCaching: boolean;
47
+ }
48
+ export declare const SortableProvider: <D, C>({ children, list: propList, onChange: propOnChange, storageKey, theme: propTheme, enableCaching, }: SortableProviderProps<D, C>) => React.JSX.Element;
49
+ export {};