@blocklet/launcher-layout 2.13.69 → 3.0.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.
@@ -1,76 +1,27 @@
1
- import { useState, useEffect, useRef } from 'react';
2
- import styled from '@emotion/styled';
3
- import PropTypes from 'prop-types';
4
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
- function CompactLayout({
6
- children,
7
- bottom,
8
- onBottomFix
9
- }) {
10
- const mainCon = useRef(null);
11
- const childsCon = useRef(null);
12
- const compactCon = useRef(null);
13
- const isFix = useRef(null);
14
- const [scrollMode, setScrollMode] = useState(false);
15
- useEffect(() => {
16
- let inTimer;
17
- const fixSize = () => {
18
- if (inTimer) {
19
- return;
20
- }
21
- inTimer = setTimeout(() => {
22
- if (childsCon.current) {
23
- if (childsCon.current.scrollHeight > mainCon.current.clientHeight - compactCon.current.clientHeight) {
24
- if (isFix.current !== 'fix') {
25
- onBottomFix('fix');
26
- isFix.current = 'fix';
27
- }
28
- setScrollMode(true);
29
- } else {
30
- if (isFix.current !== 'scroll') {
31
- onBottomFix('scroll');
32
- isFix.current = 'scroll';
33
- }
34
- setScrollMode(false);
35
- }
36
- }
37
- inTimer = null;
38
- }, 50);
1
+ import { jsxs as x, jsx as u } from "react/jsx-runtime";
2
+ import { useRef as n, useState as h, useEffect as v } from "react";
3
+ import w from "@emotion/styled";
4
+ import l from "prop-types";
5
+ import y from "lodash/noop";
6
+ function b({ children: m = [], bottom: d, onBottomFix: o = y }) {
7
+ const s = n(null), t = n(null), f = n(null), i = n(null), [p, a] = h(!1);
8
+ return v(() => {
9
+ let e;
10
+ const c = () => {
11
+ e || (e = setTimeout(() => {
12
+ t.current && (t.current.scrollHeight > s.current.clientHeight - f.current.clientHeight ? (i.current !== "fix" && (o("fix"), i.current = "fix"), a(!0)) : (i.current !== "scroll" && (o("scroll"), i.current = "scroll"), a(!1))), e = null;
13
+ }, 50));
39
14
  };
40
- let resizeObs;
41
- if (window.ResizeObserver) {
42
- resizeObs = new ResizeObserver(fixSize);
43
- } else {
44
- window.addEventListener('resize', fixSize);
45
- }
46
- resizeObs.observe(mainCon.current);
47
- resizeObs.observe(childsCon.current);
48
- return () => {
49
- if (resizeObs) {
50
- resizeObs.disconnect();
51
- } else {
52
- window.removeEventListener('resize', fixSize);
53
- }
54
- if (inTimer) {
55
- clearTimeout(inTimer);
56
- }
15
+ let r;
16
+ return window.ResizeObserver ? r = new ResizeObserver(c) : window.addEventListener("resize", c), r.observe(s.current), r.observe(t.current), () => {
17
+ r ? r.disconnect() : window.removeEventListener("resize", c), e && clearTimeout(e);
57
18
  };
58
- }, [onBottomFix]);
59
- return /*#__PURE__*/_jsxs(Container, {
60
- ref: mainCon,
61
- className: `${scrollMode ? 'scroll-mode' : ''}`,
62
- children: [/*#__PURE__*/_jsx("div", {
63
- className: "compact-context",
64
- ref: childsCon,
65
- children: children
66
- }), /*#__PURE__*/_jsx("div", {
67
- className: "fix-container",
68
- ref: compactCon,
69
- children: bottom
70
- })]
71
- });
19
+ }, [o]), /* @__PURE__ */ x(g, { ref: s, className: `${p ? "scroll-mode" : ""}`, children: [
20
+ /* @__PURE__ */ u("div", { className: "compact-context", ref: t, children: m }),
21
+ /* @__PURE__ */ u("div", { className: "fix-container", ref: f, children: d })
22
+ ] });
72
23
  }
73
- const Container = styled.div`
24
+ const g = w.div`
74
25
  display: flex;
75
26
  flex-direction: column;
76
27
  width: 100%;
@@ -102,13 +53,11 @@ const Container = styled.div`
102
53
  }
103
54
  }
104
55
  `;
105
- CompactLayout.propTypes = {
106
- children: PropTypes.any,
107
- bottom: PropTypes.element.isRequired,
108
- onBottomFix: PropTypes.func
56
+ b.propTypes = {
57
+ children: l.any,
58
+ bottom: l.element.isRequired,
59
+ onBottomFix: l.func
109
60
  };
110
- CompactLayout.defaultProps = {
111
- children: [],
112
- onBottomFix: () => {}
61
+ export {
62
+ b as default
113
63
  };
114
- export default CompactLayout;
package/lib/content.js CHANGED
@@ -1,18 +1,13 @@
1
- import styled from '@emotion/styled';
2
- import PropTypes from 'prop-types';
3
- import { jsx as _jsx } from "react/jsx-runtime";
4
- function Content({
5
- children
6
- }) {
7
- return /*#__PURE__*/_jsx(Container, {
8
- children: children
9
- });
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ import n from "@emotion/styled";
3
+ import i from "prop-types";
4
+ function o({ children: t }) {
5
+ return /* @__PURE__ */ e(r, { children: t });
10
6
  }
11
- Content.propTypes = {
12
- children: PropTypes.any.isRequired
7
+ o.propTypes = {
8
+ children: i.any.isRequired
13
9
  };
14
- export default Content;
15
- const Container = styled.div`
10
+ const r = n.div`
16
11
  display: flex;
17
12
  flex-direction: column;
18
13
  height: 100%;
@@ -33,7 +28,7 @@ const Container = styled.div`
33
28
  align-items: center;
34
29
 
35
30
  .toolbar_title {
36
- color: ${props => props.theme.palette.grey['900']};
31
+ color: ${(t) => t.theme.palette.grey[900]};
37
32
  font-size: 16px;
38
33
  }
39
34
  }
@@ -44,7 +39,7 @@ const Container = styled.div`
44
39
  align-items: center;
45
40
 
46
41
  width: 100%;
47
- background: ${props => props.theme.palette.background.paper};
42
+ background: ${(t) => t.theme.palette.background.paper};
48
43
 
49
44
  .create-button {
50
45
  margin-right: 32px;
@@ -55,7 +50,7 @@ const Container = styled.div`
55
50
  margin: 0 8px;
56
51
  }
57
52
 
58
- ${props => props.theme.breakpoints.up('md')} {
53
+ ${(t) => t.theme.breakpoints.up("md")} {
59
54
  padding: 24px;
60
55
  & > button,
61
56
  .button {
@@ -64,9 +59,12 @@ const Container = styled.div`
64
59
  }
65
60
  }
66
61
 
67
- ${props => props.theme.breakpoints.down('md')} {
62
+ ${(t) => t.theme.breakpoints.down("md")} {
68
63
  margin-top: auto;
69
64
  padding: 16px;
70
65
  }
71
66
  }
72
- `;
67
+ `;
68
+ export {
69
+ o as default
70
+ };
@@ -1,137 +1,72 @@
1
- import { createContext, useContext, useEffect, useState } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { jsx as _jsx } from "react/jsx-runtime";
4
- const StepContext = /*#__PURE__*/createContext();
5
- const {
6
- Provider
7
- } = StepContext;
8
- const matchPath = (path, exact, currentPathname = window.location.pathname.replace(/\/$/, '/')) => {
9
- if (!path) {
10
- return false;
11
- }
12
- if (exact) {
13
- return path === currentPathname;
14
- }
15
- return new RegExp(path).test(currentPathname);
16
- };
17
- function StepProvider({
18
- children,
19
- steps,
20
- mode
21
- }) {
22
- const [activeStepKey, setActiveStepKey] = useState('');
23
- if (!activeStepKey && steps.length) {
24
- setActiveStepKey(steps[0].key);
25
- }
26
- const flatSteps = steps.map(item => {
27
- if (item.children) {
28
- return [{
29
- key: item.key,
30
- hasChild: true
31
- }, item.children.map(childItem => {
32
- return {
33
- parentKey: item.key,
34
- key: childItem.key
35
- };
36
- })];
37
- }
38
- return {
39
- key: item.key
40
- };
41
- }).flat(Infinity);
42
- const totalSteps = flatSteps.filter(e => !e.hasChild);
43
-
44
- // 根据 key 获取当前 step 处于的状态;before已超过该步骤;current处于当前步骤;after还未到这个步骤;
45
- const getStepStatus = key => {
46
- let activeParentStepKey;
47
- const activeIndex = flatSteps.findIndex(e => {
48
- if (e.key === activeStepKey) {
49
- activeParentStepKey = e.parentKey;
50
- return true;
51
- }
52
- return false;
53
- });
54
- if (activeParentStepKey === key) {
55
- return 'current';
56
- }
57
- const targetIndex = flatSteps.findIndex(e => e.key === key);
58
- if (targetIndex !== -1) {
59
- if (targetIndex === activeIndex) {
60
- return 'current';
61
- }
62
- if (targetIndex < activeIndex) {
63
- return 'before';
64
- }
1
+ import { jsx as I } from "react/jsx-runtime";
2
+ import { createContext as m, useState as g, useEffect as K, use as C } from "react";
3
+ import p from "prop-types";
4
+ const k = m(), { Provider: w } = k, d = (o, r, i = window.location.pathname.replace(/\/$/, "/")) => o ? r ? o === i : new RegExp(o).test(i) : !1;
5
+ function P({ children: o, steps: r, mode: i = "history" }) {
6
+ const [c, f] = g("");
7
+ !c && r.length && f(r[0].key);
8
+ const y = r.map((e) => e.children ? [
9
+ {
10
+ key: e.key,
11
+ hasChild: !0
12
+ },
13
+ e.children.map((t) => ({ parentKey: e.key, key: t.key }))
14
+ ] : {
15
+ key: e.key
16
+ }).flat(1 / 0), u = y.filter((e) => !e.hasChild), h = (e) => {
17
+ let t;
18
+ const n = y.findIndex((a) => a.key === c ? (t = a.parentKey, !0) : !1);
19
+ if (t === e)
20
+ return "current";
21
+ const l = y.findIndex((a) => a.key === e);
22
+ if (l !== -1) {
23
+ if (l === n)
24
+ return "current";
25
+ if (l < n)
26
+ return "before";
65
27
  }
66
- return 'after';
28
+ return "after";
67
29
  };
68
-
69
- // can use this to set the activeStep by key
70
- function setActiveStepByKey(key) {
71
- setActiveStepKey(key);
30
+ function x(e) {
31
+ f(e);
72
32
  }
73
-
74
- // TODO: setIndex模式很难定位到child step,尽量使用key方式去定位
75
- function setActiveStepByIndex(index) {
76
- if (typeof index === 'function') {
77
- const newIndex = index(totalSteps.findIndex(e => e.key === activeStepKey));
78
- setActiveStepKey(totalSteps[newIndex].key);
79
- } else {
80
- setActiveStepKey(totalSteps[index].key);
81
- }
33
+ function S(e) {
34
+ if (typeof e == "function") {
35
+ const t = e(u.findIndex((n) => n.key === c));
36
+ f(u[t].key);
37
+ } else
38
+ f(u[e].key);
82
39
  }
83
- const activeStep = totalSteps.findIndex(e => e.key === activeStepKey);
84
- useEffect(() => {
85
- if (mode === 'history') {
86
- let stepKey = '';
87
- steps.some(step => {
88
- if (step.children && step.children.length) {
89
- return step.children.some(childStep => {
90
- if (matchPath(childStep.path, childStep.exact)) {
91
- stepKey = childStep.key;
92
- return true;
93
- }
94
- return false;
95
- });
96
- }
97
- if (matchPath(step.path, step.exact)) {
98
- stepKey = step.key;
99
- return true;
100
- }
101
- return false;
102
- });
103
- if (stepKey) {
104
- setActiveStepKey(stepKey);
105
- }
40
+ const s = u.findIndex((e) => e.key === c);
41
+ K(() => {
42
+ if (i === "history") {
43
+ let e = "";
44
+ r.some((t) => t.children && t.children.length ? t.children.some((n) => d(n.path, n.exact) ? (e = n.key, !0) : !1) : d(t.path, t.exact) ? (e = t.key, !0) : !1), e && f(e);
106
45
  }
107
- return () => {};
108
- }, [steps, mode]);
109
- const value = {
110
- steps,
111
- totalStepsCount: totalSteps.length,
112
- getStepStatus,
113
- setActiveStepByKey,
114
- setActiveStepByIndex,
115
- activeStep,
46
+ return () => {
47
+ };
48
+ }, [r, i]);
49
+ const v = {
50
+ steps: r,
51
+ totalStepsCount: u.length,
52
+ getStepStatus: h,
53
+ setActiveStepByKey: x,
54
+ setActiveStepByIndex: S,
55
+ activeStep: s,
116
56
  // judge node can be clicked to back if the mode is 'memory'
117
- canBackToStep: nodeIndex => {
118
- return mode === 'memory' && activeStep !== 0 && nodeIndex < activeStep;
119
- }
57
+ canBackToStep: (e) => i === "memory" && s !== 0 && e < s
120
58
  };
121
- return /*#__PURE__*/_jsx(Provider, {
122
- value: value,
123
- children: children
124
- });
59
+ return /* @__PURE__ */ I(w, { value: v, children: o });
125
60
  }
126
- function useStepContext() {
127
- return useContext(StepContext);
61
+ function T() {
62
+ return C(k);
128
63
  }
129
- StepProvider.propTypes = {
130
- children: PropTypes.any.isRequired,
131
- steps: PropTypes.array.isRequired,
132
- mode: PropTypes.string
64
+ P.propTypes = {
65
+ children: p.any.isRequired,
66
+ steps: p.array.isRequired,
67
+ mode: p.string
133
68
  };
134
- StepProvider.defaultProps = {
135
- mode: 'history'
69
+ export {
70
+ P as StepProvider,
71
+ T as useStepContext
136
72
  };
137
- export { StepProvider, useStepContext };