idea-react 2.0.0-rc.7 → 2.0.0-rc.9
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/ReadMe.md +208 -206
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +47 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/eslint.config.ts +69 -0
- package/package.json +70 -53
- package/source/CodeBlock.tsx +1 -1
- package/source/Dialog.tsx +41 -41
- package/source/Editor.tsx +46 -46
- package/source/EditorHTML.tsx +21 -23
- package/source/HorizontalMarquee/index.module.less +52 -52
- package/source/HorizontalMarquee/index.tsx +67 -65
- package/source/Loading.tsx +21 -21
- package/source/MonthCalendar.tsx +1 -1
- package/source/PageNav.tsx +102 -102
- package/source/Select.tsx +84 -84
- package/source/ShareBox.tsx +99 -99
- package/source/TableSpinner.tsx +24 -24
- package/source/Time.tsx +14 -0
- package/source/TimeDistance.tsx +41 -41
- package/source/Timeline/index.module.less +53 -0
- package/source/Timeline/index.tsx +70 -0
- package/source/TypeEcho.tsx +49 -49
- package/source/UserRank/index.tsx +122 -120
- package/source/VerticalMarquee/index.module.less +43 -43
- package/source/VerticalMarquee/index.tsx +27 -26
- package/source/index.ts +25 -23
- package/tsconfig.build.json +11 -11
- package/tsconfig.json +2 -1
package/source/Loading.tsx
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { FC, HTMLAttributes } from 'react';
|
|
2
|
-
import { Spinner } from 'react-bootstrap';
|
|
3
|
-
|
|
4
|
-
export type LoadingProps = HTMLAttributes<HTMLDivElement>;
|
|
5
|
-
|
|
6
|
-
export const Loading: FC<LoadingProps> = ({
|
|
7
|
-
className = '',
|
|
8
|
-
children = 'Loading...',
|
|
9
|
-
...props
|
|
10
|
-
}) => (
|
|
11
|
-
<div
|
|
12
|
-
className={`fixed-top h-100 w-100 d-flex justify-content-center align-items-center opacity-25 bg-black ${className}`}
|
|
13
|
-
{...props}
|
|
14
|
-
>
|
|
15
|
-
<Spinner animation="border" variant="success" />
|
|
16
|
-
|
|
17
|
-
<span className="ml-3 text-white">{children}</span>
|
|
18
|
-
</div>
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
Loading.displayName = 'Loading';
|
|
1
|
+
import { FC, HTMLAttributes } from 'react';
|
|
2
|
+
import { Spinner } from 'react-bootstrap';
|
|
3
|
+
|
|
4
|
+
export type LoadingProps = HTMLAttributes<HTMLDivElement>;
|
|
5
|
+
|
|
6
|
+
export const Loading: FC<LoadingProps> = ({
|
|
7
|
+
className = '',
|
|
8
|
+
children = 'Loading...',
|
|
9
|
+
...props
|
|
10
|
+
}) => (
|
|
11
|
+
<div
|
|
12
|
+
className={`fixed-top h-100 w-100 d-flex justify-content-center align-items-center opacity-25 bg-black ${className}`}
|
|
13
|
+
{...props}
|
|
14
|
+
>
|
|
15
|
+
<Spinner animation="border" variant="success" />
|
|
16
|
+
|
|
17
|
+
<span className="ml-3 text-white">{children}</span>
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
Loading.displayName = 'Loading';
|
package/source/MonthCalendar.tsx
CHANGED
|
@@ -22,7 +22,7 @@ export interface DateData {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export interface MonthCalendarProps
|
|
25
|
-
extends Omit<TableProps, 'onChange' | 'onSelect'>,
|
|
25
|
+
extends Omit<TableProps, 'variant' | 'onChange' | 'onSelect'>,
|
|
26
26
|
Pick<ButtonProps, 'variant'> {
|
|
27
27
|
locale?: Navigator['language'];
|
|
28
28
|
value?: DateData[];
|
package/source/PageNav.tsx
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { computed, observable } from 'mobx';
|
|
2
|
-
import { observer } from 'mobx-react';
|
|
3
|
-
import { Component } from 'react';
|
|
4
|
-
import { Nav, NavProps } from 'react-bootstrap';
|
|
5
|
-
import { scrollTo, uniqueID } from 'web-utility';
|
|
6
|
-
|
|
7
|
-
const HeadingSelector =
|
|
8
|
-
Array.from(new Array(6), (_, index) => `h${++index}`) + '';
|
|
9
|
-
|
|
10
|
-
type HeadingMeta = Record<'id' | 'text', string> &
|
|
11
|
-
Record<'level' | 'top', number>;
|
|
12
|
-
|
|
13
|
-
export interface PageNavProps extends NavProps {
|
|
14
|
-
depth?: number;
|
|
15
|
-
onItemClick?: (item: HeadingMeta) => any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@observer
|
|
19
|
-
export class PageNav extends Component<PageNavProps> {
|
|
20
|
-
static displayName = 'PageNav';
|
|
21
|
-
|
|
22
|
-
@observable
|
|
23
|
-
accessor list: HeadingMeta[] = [];
|
|
24
|
-
|
|
25
|
-
@observable
|
|
26
|
-
accessor scrollY = 0;
|
|
27
|
-
|
|
28
|
-
@computed
|
|
29
|
-
get currentActiveId() {
|
|
30
|
-
const { list, scrollY } = this;
|
|
31
|
-
const index = list.findIndex(({ top }) => top > scrollY);
|
|
32
|
-
|
|
33
|
-
return list[index - 1]?.id;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
updateScrollY = () => (this.scrollY = window.scrollY);
|
|
37
|
-
|
|
38
|
-
componentDidMount() {
|
|
39
|
-
if (!globalThis.document) return;
|
|
40
|
-
|
|
41
|
-
window.addEventListener('scroll', this.updateScrollY);
|
|
42
|
-
|
|
43
|
-
this.list = Array.from(
|
|
44
|
-
document.querySelectorAll<HTMLHeadingElement>(HeadingSelector),
|
|
45
|
-
element => {
|
|
46
|
-
element.id ||= uniqueID();
|
|
47
|
-
|
|
48
|
-
const { id, tagName, textContent, offsetTop } = element;
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
id,
|
|
52
|
-
level: +tagName[1],
|
|
53
|
-
text: textContent.trim(),
|
|
54
|
-
top: offsetTop
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
componentWillUnmount(): void {
|
|
61
|
-
globalThis.removeEventListener?.('scroll', this.updateScrollY);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
scrollTo = (meta: HeadingMeta) => () => {
|
|
65
|
-
setTimeout(() => scrollTo(`[id="${meta.id}"]`));
|
|
66
|
-
|
|
67
|
-
this.props.onItemClick?.(meta);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
renderLink = ({ id, level, text, top }: HeadingMeta) => {
|
|
71
|
-
const { currentActiveId } = this,
|
|
72
|
-
{ depth = Infinity } = this.props;
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
level <= depth && (
|
|
76
|
-
<Nav.Item key={id} style={{ textIndent: `${level - 1}rem` }}>
|
|
77
|
-
<Nav.Link
|
|
78
|
-
href={`#${id}`}
|
|
79
|
-
active={currentActiveId === id}
|
|
80
|
-
onClick={this.scrollTo({ id, level, text, top })}
|
|
81
|
-
>
|
|
82
|
-
{text}
|
|
83
|
-
</Nav.Link>
|
|
84
|
-
</Nav.Item>
|
|
85
|
-
)
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
render() {
|
|
90
|
-
const { list } = this,
|
|
91
|
-
{ style, variant = 'underline', ...props } = this.props;
|
|
92
|
-
|
|
93
|
-
return (
|
|
94
|
-
<Nav
|
|
95
|
-
{...{ ...props, variant }}
|
|
96
|
-
style={{ flexDirection: 'column', ...style }}
|
|
97
|
-
>
|
|
98
|
-
{list.map(this.renderLink)}
|
|
99
|
-
</Nav>
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
1
|
+
import { computed, observable } from 'mobx';
|
|
2
|
+
import { observer } from 'mobx-react';
|
|
3
|
+
import { Component } from 'react';
|
|
4
|
+
import { Nav, NavProps } from 'react-bootstrap';
|
|
5
|
+
import { scrollTo, uniqueID } from 'web-utility';
|
|
6
|
+
|
|
7
|
+
const HeadingSelector =
|
|
8
|
+
Array.from(new Array(6), (_, index) => `h${++index}`) + '';
|
|
9
|
+
|
|
10
|
+
type HeadingMeta = Record<'id' | 'text', string> &
|
|
11
|
+
Record<'level' | 'top', number>;
|
|
12
|
+
|
|
13
|
+
export interface PageNavProps extends NavProps {
|
|
14
|
+
depth?: number;
|
|
15
|
+
onItemClick?: (item: HeadingMeta) => any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@observer
|
|
19
|
+
export class PageNav extends Component<PageNavProps> {
|
|
20
|
+
static displayName = 'PageNav';
|
|
21
|
+
|
|
22
|
+
@observable
|
|
23
|
+
accessor list: HeadingMeta[] = [];
|
|
24
|
+
|
|
25
|
+
@observable
|
|
26
|
+
accessor scrollY = 0;
|
|
27
|
+
|
|
28
|
+
@computed
|
|
29
|
+
get currentActiveId() {
|
|
30
|
+
const { list, scrollY } = this;
|
|
31
|
+
const index = list.findIndex(({ top }) => top > scrollY);
|
|
32
|
+
|
|
33
|
+
return list[index - 1]?.id;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
updateScrollY = () => (this.scrollY = window.scrollY);
|
|
37
|
+
|
|
38
|
+
componentDidMount() {
|
|
39
|
+
if (!globalThis.document) return;
|
|
40
|
+
|
|
41
|
+
window.addEventListener('scroll', this.updateScrollY);
|
|
42
|
+
|
|
43
|
+
this.list = Array.from(
|
|
44
|
+
document.querySelectorAll<HTMLHeadingElement>(HeadingSelector),
|
|
45
|
+
element => {
|
|
46
|
+
element.id ||= uniqueID();
|
|
47
|
+
|
|
48
|
+
const { id, tagName, textContent, offsetTop } = element;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
id,
|
|
52
|
+
level: +tagName[1],
|
|
53
|
+
text: textContent.trim(),
|
|
54
|
+
top: offsetTop
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
componentWillUnmount(): void {
|
|
61
|
+
globalThis.removeEventListener?.('scroll', this.updateScrollY);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
scrollTo = (meta: HeadingMeta) => () => {
|
|
65
|
+
setTimeout(() => scrollTo(`[id="${meta.id}"]`));
|
|
66
|
+
|
|
67
|
+
this.props.onItemClick?.(meta);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
renderLink = ({ id, level, text, top }: HeadingMeta) => {
|
|
71
|
+
const { currentActiveId } = this,
|
|
72
|
+
{ depth = Infinity } = this.props;
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
level <= depth && (
|
|
76
|
+
<Nav.Item key={id} style={{ textIndent: `${level - 1}rem` }}>
|
|
77
|
+
<Nav.Link
|
|
78
|
+
href={`#${id}`}
|
|
79
|
+
active={currentActiveId === id}
|
|
80
|
+
onClick={this.scrollTo({ id, level, text, top })}
|
|
81
|
+
>
|
|
82
|
+
{text}
|
|
83
|
+
</Nav.Link>
|
|
84
|
+
</Nav.Item>
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
render() {
|
|
90
|
+
const { list } = this,
|
|
91
|
+
{ style, variant = 'underline', ...props } = this.props;
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Nav
|
|
95
|
+
{...{ ...props, variant }}
|
|
96
|
+
style={{ flexDirection: 'column', ...style }}
|
|
97
|
+
>
|
|
98
|
+
{list.map(this.renderLink)}
|
|
99
|
+
</Nav>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
package/source/Select.tsx
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import { FC, isValidElement, ReactElement, ReactNode } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
Dropdown,
|
|
5
|
-
DropdownButtonProps,
|
|
6
|
-
DropdownItemProps
|
|
7
|
-
} from 'react-bootstrap';
|
|
8
|
-
import { makeArray } from 'web-utility';
|
|
9
|
-
|
|
10
|
-
export interface OptionProps extends DropdownItemProps {
|
|
11
|
-
value?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const Option: FC<OptionProps> = ({ value, children, ...props }) => (
|
|
15
|
-
<Dropdown.Item {...props} data-value={value}>
|
|
16
|
-
{children}
|
|
17
|
-
</Dropdown.Item>
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
Option.displayName = 'Option';
|
|
21
|
-
|
|
22
|
-
export interface SelectProps
|
|
23
|
-
extends Omit<OptionProps, 'onChange'>,
|
|
24
|
-
Pick<DropdownButtonProps, 'variant' | 'menuVariant'> {
|
|
25
|
-
onChange?: (value: string) => any;
|
|
26
|
-
valueRender?: (value: string) => ReactNode;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const Select: FC<SelectProps> = ({
|
|
30
|
-
className,
|
|
31
|
-
style,
|
|
32
|
-
variant,
|
|
33
|
-
menuVariant,
|
|
34
|
-
children,
|
|
35
|
-
value,
|
|
36
|
-
onChange,
|
|
37
|
-
valueRender
|
|
38
|
-
}) => {
|
|
39
|
-
const current = (makeArray(children) as ReactNode[])
|
|
40
|
-
.flat(Infinity)
|
|
41
|
-
.find(
|
|
42
|
-
node =>
|
|
43
|
-
isValidElement<OptionProps>(node) &&
|
|
44
|
-
node.type === Option &&
|
|
45
|
-
node.props.value === value
|
|
46
|
-
) as ReactElement<OptionProps, typeof Option>;
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<Dropdown
|
|
50
|
-
onClick={({ target }) => {
|
|
51
|
-
const option = (target as HTMLElement).closest<HTMLElement>(
|
|
52
|
-
'.dropdown-item'
|
|
53
|
-
);
|
|
54
|
-
if (!option) return;
|
|
55
|
-
|
|
56
|
-
const { value } = option.dataset;
|
|
57
|
-
|
|
58
|
-
onChange?.(value);
|
|
59
|
-
}}
|
|
60
|
-
>
|
|
61
|
-
<Dropdown.Toggle
|
|
62
|
-
className={classNames(
|
|
63
|
-
'w-100',
|
|
64
|
-
'd-flex',
|
|
65
|
-
'justify-content-between',
|
|
66
|
-
'align-items-center',
|
|
67
|
-
!variant && 'bg-white text-dark',
|
|
68
|
-
className
|
|
69
|
-
)}
|
|
70
|
-
{...{ style, variant }}
|
|
71
|
-
>
|
|
72
|
-
{valueRender?.(value) || (
|
|
73
|
-
<div className={current?.props.className}>
|
|
74
|
-
{current?.props.children}
|
|
75
|
-
</div>
|
|
76
|
-
)}
|
|
77
|
-
</Dropdown.Toggle>
|
|
78
|
-
|
|
79
|
-
<Dropdown.Menu variant={menuVariant}>{children}</Dropdown.Menu>
|
|
80
|
-
</Dropdown>
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
Select.displayName = 'Select';
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { FC, isValidElement, ReactElement, ReactNode } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
Dropdown,
|
|
5
|
+
DropdownButtonProps,
|
|
6
|
+
DropdownItemProps
|
|
7
|
+
} from 'react-bootstrap';
|
|
8
|
+
import { makeArray } from 'web-utility';
|
|
9
|
+
|
|
10
|
+
export interface OptionProps extends DropdownItemProps {
|
|
11
|
+
value?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Option: FC<OptionProps> = ({ value, children, ...props }) => (
|
|
15
|
+
<Dropdown.Item {...props} data-value={value}>
|
|
16
|
+
{children}
|
|
17
|
+
</Dropdown.Item>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
Option.displayName = 'Option';
|
|
21
|
+
|
|
22
|
+
export interface SelectProps
|
|
23
|
+
extends Omit<OptionProps, 'onChange'>,
|
|
24
|
+
Pick<DropdownButtonProps, 'variant' | 'menuVariant'> {
|
|
25
|
+
onChange?: (value: string) => any;
|
|
26
|
+
valueRender?: (value: string) => ReactNode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Select: FC<SelectProps> = ({
|
|
30
|
+
className,
|
|
31
|
+
style,
|
|
32
|
+
variant,
|
|
33
|
+
menuVariant,
|
|
34
|
+
children,
|
|
35
|
+
value,
|
|
36
|
+
onChange,
|
|
37
|
+
valueRender
|
|
38
|
+
}) => {
|
|
39
|
+
const current = (makeArray(children) as ReactNode[])
|
|
40
|
+
.flat(Infinity)
|
|
41
|
+
.find(
|
|
42
|
+
node =>
|
|
43
|
+
isValidElement<OptionProps>(node) &&
|
|
44
|
+
node.type === Option &&
|
|
45
|
+
node.props.value === value
|
|
46
|
+
) as ReactElement<OptionProps, typeof Option>;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Dropdown
|
|
50
|
+
onClick={({ target }) => {
|
|
51
|
+
const option = (target as HTMLElement).closest<HTMLElement>(
|
|
52
|
+
'.dropdown-item'
|
|
53
|
+
);
|
|
54
|
+
if (!option) return;
|
|
55
|
+
|
|
56
|
+
const { value } = option.dataset;
|
|
57
|
+
|
|
58
|
+
onChange?.(value);
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
<Dropdown.Toggle
|
|
62
|
+
className={classNames(
|
|
63
|
+
'w-100',
|
|
64
|
+
'd-flex',
|
|
65
|
+
'justify-content-between',
|
|
66
|
+
'align-items-center',
|
|
67
|
+
!variant && 'bg-white text-dark',
|
|
68
|
+
className
|
|
69
|
+
)}
|
|
70
|
+
{...{ style, variant }}
|
|
71
|
+
>
|
|
72
|
+
{valueRender?.(value) || (
|
|
73
|
+
<div className={current?.props.className}>
|
|
74
|
+
{current?.props.children}
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
</Dropdown.Toggle>
|
|
78
|
+
|
|
79
|
+
<Dropdown.Menu variant={menuVariant}>{children}</Dropdown.Menu>
|
|
80
|
+
</Dropdown>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
Select.displayName = 'Select';
|
package/source/ShareBox.tsx
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import html2canvas from 'html2canvas';
|
|
2
|
-
import { observable } from 'mobx';
|
|
3
|
-
import { observer } from 'mobx-react';
|
|
4
|
-
import { Component, createRef, HTMLAttributes, MouseEvent } from 'react';
|
|
5
|
-
import { Image } from 'react-bootstrap';
|
|
6
|
-
import { blobOf } from 'web-utility';
|
|
7
|
-
|
|
8
|
-
import { Loading } from './Loading';
|
|
9
|
-
|
|
10
|
-
export async function elementToImage(
|
|
11
|
-
element: HTMLElement,
|
|
12
|
-
type?: string,
|
|
13
|
-
quality?: number
|
|
14
|
-
) {
|
|
15
|
-
const canvas = await html2canvas(element, { useCORS: true });
|
|
16
|
-
|
|
17
|
-
return new Promise<string>((resolve, reject) =>
|
|
18
|
-
canvas.toBlob(
|
|
19
|
-
blob => (blob ? resolve(URL.createObjectURL(blob)) : reject()),
|
|
20
|
-
type,
|
|
21
|
-
quality
|
|
22
|
-
)
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type ShareBoxProps = HTMLAttributes<HTMLDivElement> & ShareData;
|
|
27
|
-
|
|
28
|
-
@observer
|
|
29
|
-
export class ShareBox extends Component<ShareBoxProps> {
|
|
30
|
-
static displayName = 'ShareBox';
|
|
31
|
-
|
|
32
|
-
root = createRef<HTMLDivElement>();
|
|
33
|
-
|
|
34
|
-
@observable
|
|
35
|
-
accessor loading = false;
|
|
36
|
-
|
|
37
|
-
@observable
|
|
38
|
-
accessor imageURI = '';
|
|
39
|
-
|
|
40
|
-
componentDidMount() {
|
|
41
|
-
globalThis.addEventListener?.('resize', this.generateImage);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
componentWillUnmount() {
|
|
45
|
-
globalThis.removeEventListener?.('resize', this.generateImage);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
generateImage = async () => {
|
|
49
|
-
if (this.imageURI) {
|
|
50
|
-
URL.revokeObjectURL(this.imageURI);
|
|
51
|
-
this.imageURI = '';
|
|
52
|
-
}
|
|
53
|
-
this.loading = true;
|
|
54
|
-
this.imageURI = await elementToImage(this.root.current!);
|
|
55
|
-
this.loading = false;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
share = async (event: MouseEvent<HTMLImageElement>) => {
|
|
59
|
-
event.stopPropagation();
|
|
60
|
-
|
|
61
|
-
const image = await blobOf(this.imageURI);
|
|
62
|
-
|
|
63
|
-
const file = new File([image], `${this.props.title}.png`, {
|
|
64
|
-
type: image.type
|
|
65
|
-
});
|
|
66
|
-
await navigator.share?.({ files: [file], ...this.props });
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
render() {
|
|
70
|
-
const { className = '', children, ...props } = this.props,
|
|
71
|
-
{ loading, imageURI } = this;
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<>
|
|
75
|
-
{loading && <Loading />}
|
|
76
|
-
|
|
77
|
-
<div
|
|
78
|
-
{...props}
|
|
79
|
-
ref={this.root}
|
|
80
|
-
className={`position-relative ${className}`}
|
|
81
|
-
onMouseEnter={imageURI ? undefined : this.generateImage}
|
|
82
|
-
onTouchStart={imageURI ? undefined : this.generateImage}
|
|
83
|
-
>
|
|
84
|
-
{children}
|
|
85
|
-
|
|
86
|
-
{imageURI && (
|
|
87
|
-
<Image
|
|
88
|
-
className="position-absolute start-0 top-0 w-100 h-100"
|
|
89
|
-
src={imageURI}
|
|
90
|
-
alt="Share Image"
|
|
91
|
-
fluid
|
|
92
|
-
onClick={this.share}
|
|
93
|
-
/>
|
|
94
|
-
)}
|
|
95
|
-
</div>
|
|
96
|
-
</>
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
import html2canvas from 'html2canvas';
|
|
2
|
+
import { observable } from 'mobx';
|
|
3
|
+
import { observer } from 'mobx-react';
|
|
4
|
+
import { Component, createRef, HTMLAttributes, MouseEvent } from 'react';
|
|
5
|
+
import { Image } from 'react-bootstrap';
|
|
6
|
+
import { blobOf } from 'web-utility';
|
|
7
|
+
|
|
8
|
+
import { Loading } from './Loading';
|
|
9
|
+
|
|
10
|
+
export async function elementToImage(
|
|
11
|
+
element: HTMLElement,
|
|
12
|
+
type?: string,
|
|
13
|
+
quality?: number
|
|
14
|
+
) {
|
|
15
|
+
const canvas = await html2canvas(element, { useCORS: true });
|
|
16
|
+
|
|
17
|
+
return new Promise<string>((resolve, reject) =>
|
|
18
|
+
canvas.toBlob(
|
|
19
|
+
blob => (blob ? resolve(URL.createObjectURL(blob)) : reject()),
|
|
20
|
+
type,
|
|
21
|
+
quality
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ShareBoxProps = HTMLAttributes<HTMLDivElement> & ShareData;
|
|
27
|
+
|
|
28
|
+
@observer
|
|
29
|
+
export class ShareBox extends Component<ShareBoxProps> {
|
|
30
|
+
static displayName = 'ShareBox';
|
|
31
|
+
|
|
32
|
+
root = createRef<HTMLDivElement>();
|
|
33
|
+
|
|
34
|
+
@observable
|
|
35
|
+
accessor loading = false;
|
|
36
|
+
|
|
37
|
+
@observable
|
|
38
|
+
accessor imageURI = '';
|
|
39
|
+
|
|
40
|
+
componentDidMount() {
|
|
41
|
+
globalThis.addEventListener?.('resize', this.generateImage);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
componentWillUnmount() {
|
|
45
|
+
globalThis.removeEventListener?.('resize', this.generateImage);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
generateImage = async () => {
|
|
49
|
+
if (this.imageURI) {
|
|
50
|
+
URL.revokeObjectURL(this.imageURI);
|
|
51
|
+
this.imageURI = '';
|
|
52
|
+
}
|
|
53
|
+
this.loading = true;
|
|
54
|
+
this.imageURI = await elementToImage(this.root.current!);
|
|
55
|
+
this.loading = false;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
share = async (event: MouseEvent<HTMLImageElement>) => {
|
|
59
|
+
event.stopPropagation();
|
|
60
|
+
|
|
61
|
+
const image = await blobOf(this.imageURI);
|
|
62
|
+
|
|
63
|
+
const file = new File([image], `${this.props.title}.png`, {
|
|
64
|
+
type: image.type
|
|
65
|
+
});
|
|
66
|
+
await navigator.share?.({ files: [file], ...this.props });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
render() {
|
|
70
|
+
const { className = '', children, ...props } = this.props,
|
|
71
|
+
{ loading, imageURI } = this;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<>
|
|
75
|
+
{loading && <Loading />}
|
|
76
|
+
|
|
77
|
+
<div
|
|
78
|
+
{...props}
|
|
79
|
+
ref={this.root}
|
|
80
|
+
className={`position-relative ${className}`}
|
|
81
|
+
onMouseEnter={imageURI ? undefined : this.generateImage}
|
|
82
|
+
onTouchStart={imageURI ? undefined : this.generateImage}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
|
|
86
|
+
{imageURI && (
|
|
87
|
+
<Image
|
|
88
|
+
className="position-absolute start-0 top-0 w-100 h-100"
|
|
89
|
+
src={imageURI}
|
|
90
|
+
alt="Share Image"
|
|
91
|
+
fluid
|
|
92
|
+
onClick={this.share}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
</div>
|
|
96
|
+
</>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
package/source/TableSpinner.tsx
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { FC, HTMLAttributes } from 'react';
|
|
2
|
-
import { Spinner, SpinnerProps } from 'react-bootstrap';
|
|
3
|
-
|
|
4
|
-
export interface TableSpinnerProps
|
|
5
|
-
extends HTMLAttributes<HTMLTableRowElement>,
|
|
6
|
-
Pick<SpinnerProps, 'animation' | 'variant' | 'size'> {
|
|
7
|
-
colSpan: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const TableSpinner: FC<TableSpinnerProps> = ({
|
|
11
|
-
animation = 'border',
|
|
12
|
-
variant = 'primary',
|
|
13
|
-
size,
|
|
14
|
-
colSpan,
|
|
15
|
-
...props
|
|
16
|
-
}) => (
|
|
17
|
-
<tr {...props}>
|
|
18
|
-
<td className="text-center p-4" colSpan={colSpan}>
|
|
19
|
-
<Spinner {...{ animation, variant, size }} />
|
|
20
|
-
</td>
|
|
21
|
-
</tr>
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
TableSpinner.displayName = 'TableSpinner';
|
|
1
|
+
import { FC, HTMLAttributes } from 'react';
|
|
2
|
+
import { Spinner, SpinnerProps } from 'react-bootstrap';
|
|
3
|
+
|
|
4
|
+
export interface TableSpinnerProps
|
|
5
|
+
extends HTMLAttributes<HTMLTableRowElement>,
|
|
6
|
+
Pick<SpinnerProps, 'animation' | 'variant' | 'size'> {
|
|
7
|
+
colSpan: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const TableSpinner: FC<TableSpinnerProps> = ({
|
|
11
|
+
animation = 'border',
|
|
12
|
+
variant = 'primary',
|
|
13
|
+
size,
|
|
14
|
+
colSpan,
|
|
15
|
+
...props
|
|
16
|
+
}) => (
|
|
17
|
+
<tr {...props}>
|
|
18
|
+
<td className="text-center p-4" colSpan={colSpan}>
|
|
19
|
+
<Spinner {...{ animation, variant, size }} />
|
|
20
|
+
</td>
|
|
21
|
+
</tr>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
TableSpinner.displayName = 'TableSpinner';
|