@netless/telebox-insider 0.2.25 → 1.0.0-alpha.2

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.
Files changed (52) hide show
  1. package/dist/TeleBox/constants.d.ts +0 -3
  2. package/dist/TeleBox/index.d.ts +118 -97
  3. package/dist/TeleBox/typings.d.ts +42 -55
  4. package/dist/TeleBoxCollector/index.d.ts +25 -29
  5. package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +14 -18
  6. package/dist/TeleBoxManager/constants.d.ts +0 -3
  7. package/dist/TeleBoxManager/index.d.ts +64 -19
  8. package/dist/TeleBoxManager/typings.d.ts +35 -28
  9. package/dist/TeleStage/index.d.ts +21 -0
  10. package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +6 -8
  11. package/dist/TeleTitleBar/typings.d.ts +3 -5
  12. package/dist/index.d.ts +0 -1
  13. package/dist/style.css +1 -1
  14. package/dist/telebox-insider.cjs.js +1 -15
  15. package/dist/telebox-insider.cjs.js.map +1 -1
  16. package/dist/telebox-insider.es.js +1 -15
  17. package/dist/telebox-insider.es.js.map +1 -1
  18. package/dist/utils.d.ts +0 -1
  19. package/package.json +7 -19
  20. package/src/TeleBox/constants.ts +0 -3
  21. package/src/TeleBox/index.ts +500 -690
  22. package/src/TeleBox/style.scss +6 -0
  23. package/src/TeleBox/typings.ts +42 -75
  24. package/src/TeleBoxCollector/index.ts +136 -159
  25. package/src/TeleBoxCollector/style.scss +3 -0
  26. package/src/TeleBoxManager/MaxTitleBar/index.ts +95 -108
  27. package/src/TeleBoxManager/MaxTitleBar/style.scss +3 -1
  28. package/src/TeleBoxManager/constants.ts +0 -3
  29. package/src/TeleBoxManager/index.ts +329 -336
  30. package/src/TeleBoxManager/typings.ts +42 -52
  31. package/src/TeleStage/index.ts +178 -0
  32. package/src/TeleStage/style.scss +49 -0
  33. package/src/TeleTitleBar/DefaultTitleBar/index.ts +48 -61
  34. package/src/TeleTitleBar/DefaultTitleBar/style.scss +7 -0
  35. package/src/TeleTitleBar/typings.ts +3 -9
  36. package/src/index.ts +0 -1
  37. package/src/scss/mixins.scss +7 -0
  38. package/src/utils.ts +0 -6
  39. package/dist/TeleBoxCollector/TeleBoxCollector.stories.d.ts +0 -5
  40. package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.d.ts +0 -7
  41. package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.d.ts +0 -4
  42. package/dist/TeleBoxReact/TeleBox.stories.d.ts +0 -9
  43. package/dist/TeleBoxReact/index.d.ts +0 -17
  44. package/dist/TeleBoxReact/utils.d.ts +0 -2
  45. package/dist/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.d.ts +0 -4
  46. package/src/TeleBoxCollector/TeleBoxCollector.stories.tsx +0 -23
  47. package/src/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.tsx +0 -66
  48. package/src/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.tsx +0 -34
  49. package/src/TeleBoxReact/TeleBox.stories.tsx +0 -74
  50. package/src/TeleBoxReact/index.tsx +0 -175
  51. package/src/TeleBoxReact/utils.ts +0 -14
  52. package/src/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.tsx +0 -15
@@ -1,17 +0,0 @@
1
- import { FC } from "react";
2
- import { TeleBoxConfig, TeleBoxState } from "../TeleBox/typings";
3
- export declare type TeleBoxReactProps = TeleBoxConfig & {
4
- onResize?: (event: {
5
- width: number;
6
- height: number;
7
- }) => void;
8
- onMove?: (event: {
9
- x: number;
10
- y: number;
11
- }) => void;
12
- onClose?: () => void;
13
- onFocus?: () => void;
14
- onBlur?: () => void;
15
- onStateChanged?: (state: TeleBoxState) => void;
16
- };
17
- export declare const TeleBoxReact: FC<TeleBoxReactProps>;
@@ -1,2 +0,0 @@
1
- import { useEffect } from "react";
2
- export declare const useUpdateEffect: typeof useEffect;
@@ -1,4 +0,0 @@
1
- import { Meta, Story } from "@storybook/react";
2
- declare const storyMeta: Meta;
3
- export default storyMeta;
4
- export declare const LongTitle: Story;
@@ -1,23 +0,0 @@
1
- import React, { useState } from "react";
2
- import { Meta, Story } from "@storybook/react";
3
- import { TeleBoxCollector, TeleBoxCollectorConfig } from ".";
4
-
5
- const storyMeta: Meta = {
6
- title: "TeleBoxCollector",
7
- };
8
-
9
- export default storyMeta;
10
-
11
- export const Overview: Story<TeleBoxCollectorConfig> = (args) => {
12
- const [collector] = useState(() => new TeleBoxCollector(args));
13
- return <div ref={(dom) => dom && dom.appendChild(collector.render())} />;
14
- };
15
-
16
- Overview.args = {
17
- visible: true,
18
- readonly: false,
19
- };
20
-
21
- Overview.argTypes = {
22
- onClick: { action: "onClick" },
23
- };
@@ -1,66 +0,0 @@
1
- import React from "react";
2
- import { Meta, Story } from "@storybook/react";
3
- import faker from "faker";
4
- import { TELE_BOX_STATE } from "../../TeleBox/constants";
5
- import { MaxTitleBarReact, MaxTitleBarReactProps } from "./MaxTitleBarReact";
6
-
7
- const storyMeta: Meta = {
8
- title: "MaxTitleBar",
9
- component: MaxTitleBarReact,
10
- };
11
-
12
- export default storyMeta;
13
-
14
- const containerRect = {
15
- x: 0,
16
- y: 0,
17
- width: window.innerWidth,
18
- height: window.innerHeight,
19
- };
20
-
21
- export const Overview: Story<MaxTitleBarReactProps> = (props) => (
22
- <MaxTitleBarReact {...props} />
23
- );
24
- Overview.args = {
25
- state: TELE_BOX_STATE.Maximized,
26
- boxes: Array(3)
27
- .fill(0)
28
- .map((_, i) => ({
29
- id: `${i + 1}`,
30
- title: `tab ${i + 1}`,
31
- readonly: faker.datatype.boolean(),
32
- })),
33
- containerRect,
34
- };
35
- Overview.args.focusedBox = Overview.args.boxes![1];
36
-
37
- export const SingleBox: Story<MaxTitleBarReactProps> = (props) => (
38
- <MaxTitleBarReact {...props} />
39
- );
40
- SingleBox.args = {
41
- state: TELE_BOX_STATE.Maximized,
42
- boxes: [
43
- {
44
- id: `1`,
45
- title: faker.commerce.productName(),
46
- readonly: faker.datatype.boolean(),
47
- },
48
- ],
49
- containerRect,
50
- };
51
-
52
- export const BoxOverflows: Story<MaxTitleBarReactProps> = (props) => (
53
- <MaxTitleBarReact {...props} />
54
- );
55
- BoxOverflows.args = {
56
- state: TELE_BOX_STATE.Maximized,
57
- boxes: Array(50)
58
- .fill(0)
59
- .map((_, i) => ({
60
- id: `${i + 1}`,
61
- title: `tab ${i + 1}`,
62
- readonly: faker.datatype.boolean(),
63
- })),
64
- containerRect,
65
- };
66
- BoxOverflows.args.focusedBox = BoxOverflows.args.boxes![3];
@@ -1,34 +0,0 @@
1
- import React, { FC, useEffect, useState } from "react";
2
- import { MaxTitleBar, MaxTitleBarConfig } from ".";
3
-
4
- export type MaxTitleBarReactProps = MaxTitleBarConfig;
5
-
6
- export const MaxTitleBarReact: FC<MaxTitleBarConfig> = (props) => {
7
- const [maxTitleBar] = useState(() => new MaxTitleBar(props));
8
-
9
- useEffect(() => {
10
- if (props.state != null) {
11
- maxTitleBar.setState(props.state);
12
- }
13
- }, [maxTitleBar, props.state]);
14
-
15
- useEffect(() => {
16
- if (props.boxes != null) {
17
- maxTitleBar.setBoxes(props.boxes);
18
- }
19
- }, [maxTitleBar, props.boxes]);
20
-
21
- useEffect(() => {
22
- if (props.containerRect != null) {
23
- maxTitleBar.setContainerRect(props.containerRect);
24
- }
25
- }, [maxTitleBar, props.containerRect]);
26
-
27
- useEffect(() => {
28
- maxTitleBar.focusBox(props.focusedBox);
29
- }, [maxTitleBar, props.focusedBox]);
30
-
31
- return (
32
- <div ref={(node) => node && node.appendChild(maxTitleBar.render())} />
33
- );
34
- };
@@ -1,74 +0,0 @@
1
- import React from "react";
2
- import { Meta, Story } from "@storybook/react";
3
- import faker from "faker";
4
- import { TeleBoxReact, TeleBoxReactProps } from ".";
5
- import { TELE_BOX_STATE } from "../TeleBox/constants";
6
-
7
- const storyMeta: Meta<TeleBoxReactProps> = {
8
- title: "TeleBox",
9
- component: TeleBoxReact,
10
- args: {
11
- title: faker.commerce.productName(),
12
- width: 0.5,
13
- height: 0.5,
14
- minWidth: 0.05,
15
- minHeight: 0.05,
16
- x: 0.1,
17
- y: 0.1,
18
- state: TELE_BOX_STATE.Normal,
19
- readonly: false,
20
- draggable: true,
21
- resizable: true,
22
- },
23
- argTypes: {
24
- width: { control: { type: "range", min: 0, max: 1, step: 0.01 } },
25
- height: { control: { type: "range", min: 0, max: 1, step: 0.01 } },
26
- minWidth: { control: { type: "range", min: 0, max: 1, step: 0.01 } },
27
- minHeight: { control: { type: "range", min: 0, max: 1, step: 0.01 } },
28
- x: { control: { type: "range", min: 0, max: 1, step: 0.01 } },
29
- y: { control: { type: "range", min: 0, max: 1, step: 0.01 } },
30
- fixRatio: { control: { type: "number" } },
31
- },
32
- };
33
-
34
- export default storyMeta;
35
-
36
- export const Overview: Story<TeleBoxReactProps> = (args) => {
37
- return <TeleBoxReact {...args} />;
38
- };
39
-
40
- export const Resizable: Story<TeleBoxReactProps> = (args) => {
41
- return <TeleBoxReact {...args} />;
42
- };
43
-
44
- Resizable.args = {
45
- title: "No Resize",
46
- resizable: false,
47
- };
48
-
49
- export const Draggable: Story<TeleBoxReactProps> = (args) => {
50
- return <TeleBoxReact {...args} />;
51
- };
52
-
53
- Draggable.args = {
54
- title: "No Drag",
55
- draggable: false,
56
- };
57
-
58
- export const FixRatio: Story<TeleBoxReactProps> = (args) => {
59
- return <TeleBoxReact {...args} />;
60
- };
61
-
62
- FixRatio.args = {
63
- title: "Fix Ratio",
64
- fixRatio: true,
65
- };
66
-
67
- export const Readonly: Story<TeleBoxReactProps> = (args) => {
68
- return <TeleBoxReact {...args} />;
69
- };
70
-
71
- Readonly.args = {
72
- title: "Readonly",
73
- readonly: true,
74
- };
@@ -1,175 +0,0 @@
1
- import React, { FC, useState, useEffect } from "react";
2
- import { TeleBox } from "../TeleBox";
3
- import { TeleBoxConfig, TeleBoxState } from "../TeleBox/typings";
4
- import { TELE_BOX_EVENT } from "../TeleBox/constants";
5
- import { useUpdateEffect } from "./utils";
6
-
7
- export type TeleBoxReactProps = TeleBoxConfig & {
8
- onResize?: (event: { width: number; height: number }) => void;
9
- onMove?: (event: { x: number; y: number }) => void;
10
- onClose?: () => void;
11
- onFocus?: () => void;
12
- onBlur?: () => void;
13
- onStateChanged?: (state: TeleBoxState) => void;
14
- };
15
-
16
- export const TeleBoxReact: FC<TeleBoxReactProps> = (props) => {
17
- const [teleBox] = useState(() => new TeleBox(props));
18
-
19
- useUpdateEffect(() => {
20
- if (props.prefersColorScheme != null) {
21
- teleBox.setPrefersColorScheme(props.prefersColorScheme);
22
- }
23
- }, [teleBox, props.prefersColorScheme]);
24
-
25
- useUpdateEffect(() => {
26
- if (props.minWidth != null) {
27
- teleBox.setMinWidth(props.minWidth);
28
- }
29
- }, [teleBox, props.minWidth]);
30
-
31
- useUpdateEffect(() => {
32
- if (props.minHeight != null) {
33
- teleBox.setMinHeight(props.minHeight);
34
- }
35
- }, [teleBox, props.minHeight]);
36
-
37
- useUpdateEffect(() => {
38
- teleBox.resize(
39
- props.width ?? teleBox.width,
40
- props.height ?? teleBox.height,
41
- true
42
- );
43
- }, [teleBox, props.width, props.height]);
44
-
45
- useUpdateEffect(() => {
46
- teleBox.move(props.x ?? teleBox.x, props.y ?? teleBox.y, true);
47
- }, [teleBox, props.x, props.y]);
48
-
49
- useUpdateEffect(() => {
50
- if (props.title != null) {
51
- teleBox.setTitle(props.title);
52
- }
53
- }, [teleBox, props.title]);
54
-
55
- useUpdateEffect(() => {
56
- if (props.visible != null) {
57
- teleBox.setVisible(props.visible);
58
- }
59
- }, [teleBox, props.visible]);
60
-
61
- useUpdateEffect(() => {
62
- if (props.minimized != null) {
63
- teleBox.setMinimized(props.minimized, true);
64
- }
65
- }, [teleBox, props.minimized]);
66
-
67
- useUpdateEffect(() => {
68
- if (props.maximized != null) {
69
- teleBox.setMaximized(props.maximized, true);
70
- }
71
- }, [teleBox, props.maximized]);
72
-
73
- useUpdateEffect(() => {
74
- if (props.state != null) {
75
- teleBox.setState(props.state, true);
76
- }
77
- }, [teleBox, props.state]);
78
-
79
- useUpdateEffect(() => {
80
- if (props.draggable != null) {
81
- teleBox.setDraggable(props.draggable);
82
- }
83
- }, [teleBox, props.draggable]);
84
-
85
- useUpdateEffect(() => {
86
- if (props.resizable != null) {
87
- teleBox.setResizable(props.resizable);
88
- }
89
- }, [teleBox, props.resizable]);
90
-
91
- useUpdateEffect(() => {
92
- if (props.fence != null) {
93
- teleBox.setFence(props.fence);
94
- }
95
- }, [teleBox, props.fence]);
96
-
97
- useUpdateEffect(() => {
98
- if (props.containerRect != null) {
99
- teleBox.setContainerRect(props.containerRect);
100
- }
101
- }, [teleBox, props.containerRect]);
102
-
103
- useUpdateEffect(() => {
104
- if (props.fixRatio != null) {
105
- teleBox.setFixRatio(props.fixRatio);
106
- }
107
- }, [teleBox, props.fixRatio]);
108
-
109
- useEffect(() => {
110
- if (props.onResize) {
111
- teleBox.events.on(TELE_BOX_EVENT.Resize, props.onResize);
112
- return () => {
113
- teleBox.events.off(TELE_BOX_EVENT.Resize, props.onResize);
114
- };
115
- }
116
- return;
117
- }, [teleBox, props.onResize]);
118
-
119
- useEffect(() => {
120
- if (props.onMove) {
121
- teleBox.events.on(TELE_BOX_EVENT.Move, props.onMove);
122
- return () => {
123
- teleBox.events.off(TELE_BOX_EVENT.Move, props.onMove);
124
- };
125
- }
126
- return;
127
- }, [teleBox, props.onMove]);
128
-
129
- useEffect(() => {
130
- if (props.onClose) {
131
- teleBox.events.on(TELE_BOX_EVENT.Close, props.onClose);
132
- return () => {
133
- teleBox.events.off(TELE_BOX_EVENT.Close, props.onClose);
134
- };
135
- }
136
- return;
137
- }, [teleBox, props.onClose]);
138
-
139
- useEffect(() => {
140
- if (props.onFocus) {
141
- teleBox.events.on(TELE_BOX_EVENT.Focus, props.onFocus);
142
- return () => {
143
- teleBox.events.off(TELE_BOX_EVENT.Focus, props.onFocus);
144
- };
145
- }
146
- return;
147
- }, [teleBox, props.onFocus]);
148
-
149
- useEffect(() => {
150
- if (props.onBlur) {
151
- teleBox.events.on(TELE_BOX_EVENT.Blur, props.onBlur);
152
- return () => {
153
- teleBox.events.off(TELE_BOX_EVENT.Blur, props.onBlur);
154
- };
155
- }
156
- return;
157
- }, [teleBox, props.onBlur]);
158
-
159
- useEffect(() => {
160
- if (props.onStateChanged) {
161
- teleBox.events.on(TELE_BOX_EVENT.State, props.onStateChanged);
162
- return () => {
163
- teleBox.events.off(TELE_BOX_EVENT.State, props.onStateChanged);
164
- };
165
- }
166
- return;
167
- }, [teleBox, props.onStateChanged]);
168
-
169
- return (
170
- <div
171
- ref={(node) => node && teleBox.render(node)}
172
- className={teleBox.wrapClassName("box")}
173
- />
174
- );
175
- };
@@ -1,14 +0,0 @@
1
- import { useEffect, useRef } from "react";
2
-
3
- export const useUpdateEffect: typeof useEffect = (effect, deps) => {
4
- const isFirst = useRef(true);
5
-
6
- useEffect(() => {
7
- if (isFirst.current) {
8
- isFirst.current = false;
9
- return;
10
- }
11
- return effect();
12
- // eslint-disable-next-line react-hooks/exhaustive-deps
13
- }, deps);
14
- };
@@ -1,15 +0,0 @@
1
- import React from "react";
2
- import { Meta, Story } from "@storybook/react";
3
- import faker from "faker";
4
- import { TeleBoxReact } from "../../TeleBoxReact";
5
-
6
- const storyMeta: Meta = {
7
- title: "DefaultTitleBar",
8
- component: TeleBoxReact,
9
- };
10
-
11
- export default storyMeta;
12
-
13
- export const LongTitle: Story = () => (
14
- <TeleBoxReact title={faker.lorem.words(50)} />
15
- );