idea-react 2.0.0-rc.9 → 2.1.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.
- package/ReadMe.md +198 -208
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +62 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +47 -69
- package/source/CodeBlock.tsx +19 -17
- package/source/Countdown.tsx +118 -0
- package/source/Dialog.tsx +41 -41
- package/source/Editor.tsx +46 -46
- package/source/EditorHTML.tsx +16 -21
- package/source/HorizontalMarquee/index.module.less +52 -52
- package/source/HorizontalMarquee/index.tsx +67 -67
- package/source/LiveTSX.tsx +23 -0
- package/source/Loading.tsx +21 -21
- package/source/MonthCalendar.tsx +9 -33
- 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 +15 -14
- package/source/TimeDistance.tsx +41 -41
- package/source/Timeline/index.module.less +53 -53
- package/source/Timeline/index.tsx +3 -13
- package/source/TypeEcho.tsx +49 -49
- package/source/UserRank/index.tsx +108 -122
- package/source/VerticalMarquee/index.module.less +43 -43
- package/source/VerticalMarquee/index.tsx +27 -27
- package/source/ZodiacBar.tsx +51 -0
- package/source/index.ts +28 -25
- package/tsconfig.build.json +11 -11
- package/tsconfig.json +1 -1
- package/eslint.config.ts +0 -69
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "idea-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
5
|
"author": "shiy2008@gmail.com",
|
|
6
6
|
"description": "A React advanced components library based on TypeScript & Bootstrap, built by idea2app remote developers team.",
|
|
@@ -22,92 +22,75 @@
|
|
|
22
22
|
"types": "dist/index.d.ts",
|
|
23
23
|
"main": "dist/index.js",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@editorjs/editorjs": "^2.
|
|
25
|
+
"@editorjs/editorjs": "^2.31.6",
|
|
26
26
|
"@editorjs/paragraph": "^2.11.7",
|
|
27
27
|
"@react-editor-js/core": "^2.1.0",
|
|
28
|
-
"@swc/helpers": "^0.5.
|
|
28
|
+
"@swc/helpers": "^0.5.21",
|
|
29
29
|
"classnames": "^2.5.1",
|
|
30
30
|
"editorjs-html": "^4.0.5",
|
|
31
31
|
"html2canvas": "^1.4.1",
|
|
32
32
|
"iterable-observer": "^1.1.0",
|
|
33
|
-
"lodash": "^4.
|
|
34
|
-
"mobx": "^6.
|
|
35
|
-
"mobx-react": "^9.2.
|
|
36
|
-
"mobx-react-helper": "^0.
|
|
33
|
+
"lodash": "^4.18.1",
|
|
34
|
+
"mobx": "^6.15.0",
|
|
35
|
+
"mobx-react": "^9.2.1",
|
|
36
|
+
"mobx-react-helper": "^0.5.1",
|
|
37
37
|
"prismjs": "^1.30.0",
|
|
38
|
-
"react-bootstrap": "^2.10.
|
|
38
|
+
"react-bootstrap": "^2.10.10",
|
|
39
39
|
"react-editor-js": "^2.1.0",
|
|
40
|
-
"react-element-to-jsx-string": "
|
|
41
|
-
"
|
|
40
|
+
"react-element-to-jsx-string": ">=15",
|
|
41
|
+
"react-live": "^4.1.8",
|
|
42
|
+
"web-utility": "^4.6.5"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"react": ">=16",
|
|
45
46
|
"react-dom": ">=16"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@babel/plugin-proposal-decorators": "^7.
|
|
49
|
-
"@babel/preset-typescript": "^7.
|
|
50
|
-
"@eslint
|
|
51
|
-
"@eslint/js": "^
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@parcel/
|
|
55
|
-
"@parcel/
|
|
56
|
-
"@parcel/
|
|
57
|
-
"@parcel/transformer-
|
|
58
|
-
"@parcel/transformer-mdx": "~2.13.3",
|
|
59
|
-
"@parcel/transformer-typescript-tsc": "~2.14.4",
|
|
60
|
-
"@parcel/transformer-typescript-types": "~2.14.4",
|
|
49
|
+
"@babel/plugin-proposal-decorators": "^7.29.0",
|
|
50
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
51
|
+
"@cspell/eslint-plugin": "^10.0.0",
|
|
52
|
+
"@eslint/js": "^10.0.1",
|
|
53
|
+
"@microsoft/api-extractor": "^7.58.7",
|
|
54
|
+
"@parcel/config-default": "~2.16.4",
|
|
55
|
+
"@parcel/packager-ts": "~2.16.4",
|
|
56
|
+
"@parcel/transformer-less": "2.16.4",
|
|
57
|
+
"@parcel/transformer-typescript-tsc": "~2.16.4",
|
|
58
|
+
"@parcel/transformer-typescript-types": "~2.16.4",
|
|
61
59
|
"@softonus/prettier-plugin-duplicate-remover": "^1.1.2",
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"@storybook/addon-storysource": "^8.6.12",
|
|
68
|
-
"@storybook/blocks": "^8.6.12",
|
|
69
|
-
"@storybook/react": "^8.6.12",
|
|
70
|
-
"@storybook/test": "^8.6.12",
|
|
71
|
-
"@types/lodash": "^4.17.16",
|
|
72
|
-
"@types/node": "^22.14.0",
|
|
73
|
-
"@types/prismjs": "^1.26.5",
|
|
74
|
-
"@types/react": "^19.1.0",
|
|
75
|
-
"@types/react-dom": "^19.1.2",
|
|
60
|
+
"@types/lodash": "^4.17.24",
|
|
61
|
+
"@types/node": "^24.12.2",
|
|
62
|
+
"@types/prismjs": "^1.26.6",
|
|
63
|
+
"@types/react": "^19.2.14",
|
|
64
|
+
"@types/react-dom": "^19.2.3",
|
|
76
65
|
"buffer": "^6.0.3",
|
|
77
|
-
"eslint": "^
|
|
78
|
-
"eslint-config-prettier": "^10.1.
|
|
66
|
+
"eslint": "^10.2.1",
|
|
67
|
+
"eslint-config-prettier": "^10.1.8",
|
|
79
68
|
"eslint-plugin-react": "^7.37.5",
|
|
80
|
-
"eslint-plugin-simple-import-sort": "^
|
|
81
|
-
"globals": "^
|
|
69
|
+
"eslint-plugin-simple-import-sort": "^13.0.0",
|
|
70
|
+
"globals": "^17.5.0",
|
|
82
71
|
"husky": "^9.1.7",
|
|
83
|
-
"jiti": "^2.
|
|
84
|
-
"koapache": "^
|
|
85
|
-
"less": "^4.
|
|
86
|
-
"lint-staged": "^
|
|
87
|
-
"parcel": "~2.
|
|
88
|
-
"postcss": "^8.5.
|
|
89
|
-
"prettier": "^3.
|
|
90
|
-
"prettier-plugin-css-order": "^2.
|
|
72
|
+
"jiti": "^2.6.1",
|
|
73
|
+
"koapache": "^3.0.0",
|
|
74
|
+
"less": "^4.6.4",
|
|
75
|
+
"lint-staged": "^16.4.0",
|
|
76
|
+
"parcel": "~2.16.4",
|
|
77
|
+
"postcss": "^8.5.12",
|
|
78
|
+
"prettier": "^3.8.3",
|
|
79
|
+
"prettier-plugin-css-order": "^2.2.0",
|
|
91
80
|
"process": "^0.11.10",
|
|
92
81
|
"prop-types": "15.8.1",
|
|
93
|
-
"react": "^19.
|
|
94
|
-
"react-dom": "^19.
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"typedoc-plugin-mdn-links": "^5.0.1",
|
|
101
|
-
"typescript": "~5.8.3",
|
|
102
|
-
"typescript-eslint": "^8.29.1"
|
|
82
|
+
"react": "^19.2.5",
|
|
83
|
+
"react-dom": "^19.2.5",
|
|
84
|
+
"rimraf": "^6.1.3",
|
|
85
|
+
"typedoc": "^0.28.19",
|
|
86
|
+
"typedoc-plugin-mdn-links": "^5.1.1",
|
|
87
|
+
"typescript": "~5.9.3",
|
|
88
|
+
"typescript-eslint": "^8.59.1"
|
|
103
89
|
},
|
|
104
90
|
"pnpm": {
|
|
105
91
|
"onlyBuiltDependencies": [
|
|
106
92
|
"@parcel/watcher",
|
|
107
|
-
"@swc/core"
|
|
108
|
-
"esbuild",
|
|
109
|
-
"lmdb",
|
|
110
|
-
"msgpackr-extract"
|
|
93
|
+
"@swc/core"
|
|
111
94
|
]
|
|
112
95
|
},
|
|
113
96
|
"prettier": {
|
|
@@ -115,6 +98,7 @@
|
|
|
115
98
|
"trailingComma": "none",
|
|
116
99
|
"arrowParens": "avoid",
|
|
117
100
|
"tabWidth": 4,
|
|
101
|
+
"printWidth": 100,
|
|
118
102
|
"plugins": [
|
|
119
103
|
"prettier-plugin-css-order",
|
|
120
104
|
"@softonus/prettier-plugin-duplicate-remover"
|
|
@@ -124,9 +108,6 @@
|
|
|
124
108
|
"*.{md,less,json,yml,js,mjs,ts,tsx}": "prettier --write",
|
|
125
109
|
"*.{js,ts,tsx}": "eslint --fix"
|
|
126
110
|
},
|
|
127
|
-
"@parcel/resolver-default": {
|
|
128
|
-
"packageExports": true
|
|
129
|
-
},
|
|
130
111
|
"browserslist": "> 0.5%, last 2 versions, not dead, IE 11",
|
|
131
112
|
"targets": {
|
|
132
113
|
"main": {
|
|
@@ -143,9 +124,6 @@
|
|
|
143
124
|
"start": "npm run pack-docs && npm run pack-preview && web-server docs/ -p 8080 -o",
|
|
144
125
|
"build": "npm run pack-docs && npm run pack-preview && npm run pack-dist && npm run api-extractor",
|
|
145
126
|
"prepublishOnly": "npm test && npm run build",
|
|
146
|
-
"dev:storybook": "storybook dev -p 6006",
|
|
147
|
-
"build:storybook": "storybook build -c .storybook",
|
|
148
|
-
"preview:storybook": "npm run build:storybook && vite preview --outDir storybook-static",
|
|
149
127
|
"preview": "cd preview/ && rimraf ../.parcel-cache dist/ && parcel --open"
|
|
150
128
|
}
|
|
151
129
|
}
|
package/source/CodeBlock.tsx
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isValidElement, PropsWithChildren } from 'react';
|
|
1
|
+
import { FC, HTMLAttributes, isValidElement } from 'react';
|
|
3
2
|
import reactElementToJSXString from 'react-element-to-jsx-string';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
import { highlight, languages } from 'prismjs';
|
|
5
|
+
import 'prismjs/components/prism-javascript';
|
|
6
|
+
import 'prismjs/components/prism-jsx';
|
|
7
|
+
import 'prismjs/components/prism-tsx';
|
|
8
|
+
import 'prismjs/components/prism-typescript';
|
|
6
9
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
export interface CodeBlockProps extends HTMLAttributes<HTMLPreElement> {
|
|
11
|
+
language: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const CodeBlock: FC<CodeBlockProps> = ({ className = '', language, children, ...props }) => {
|
|
15
|
+
const sourceCode =
|
|
16
|
+
typeof children === 'string'
|
|
17
|
+
? children
|
|
18
|
+
: reactElementToJSXString(isValidElement(children) ? children : <>{children}</>);
|
|
19
|
+
const __html = highlight(sourceCode, languages[language], language);
|
|
15
20
|
|
|
16
21
|
return (
|
|
17
|
-
<pre className={`language-${language}`}>
|
|
18
|
-
<code
|
|
19
|
-
dangerouslySetInnerHTML={{ __html }}
|
|
20
|
-
className={`language-${language}`}
|
|
21
|
-
/>
|
|
22
|
+
<pre className={`language-${language} ${className}`} {...props}>
|
|
23
|
+
<code dangerouslySetInnerHTML={{ __html }} className={`language-${language}`} />
|
|
22
24
|
</pre>
|
|
23
25
|
);
|
|
24
|
-
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { computed, observable } from 'mobx';
|
|
2
|
+
import { observer } from 'mobx-react';
|
|
3
|
+
import { ObservedComponent, reaction } from 'mobx-react-helper';
|
|
4
|
+
import { HTMLAttributes } from 'react';
|
|
5
|
+
import { Second, TimeData } from 'web-utility';
|
|
6
|
+
|
|
7
|
+
export interface TimeUnit {
|
|
8
|
+
scale: number;
|
|
9
|
+
label: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface TimeSection {
|
|
13
|
+
value: number;
|
|
14
|
+
label: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CountdownProps extends HTMLAttributes<HTMLOListElement> {
|
|
18
|
+
units: TimeUnit[];
|
|
19
|
+
endTime: TimeData;
|
|
20
|
+
itemClassName?: string;
|
|
21
|
+
onEnd?: (endTime: TimeData) => unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Migrate from https://bootstrap.web-cell.dev/#Calendar/CountDown
|
|
26
|
+
*/
|
|
27
|
+
@observer
|
|
28
|
+
export class Countdown extends ObservedComponent<CountdownProps> {
|
|
29
|
+
static displayName = 'Countdown';
|
|
30
|
+
|
|
31
|
+
@observable
|
|
32
|
+
accessor rest = 0;
|
|
33
|
+
|
|
34
|
+
private timer = 0;
|
|
35
|
+
|
|
36
|
+
get endTimestamp() {
|
|
37
|
+
return +new Date(this.props.endTime || Date.now());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@computed
|
|
41
|
+
get timeSections(): TimeSection[] {
|
|
42
|
+
const { units } = this.observedProps;
|
|
43
|
+
let { rest } = this;
|
|
44
|
+
|
|
45
|
+
return units.reduce((list, { label }, index) => {
|
|
46
|
+
const scale = units
|
|
47
|
+
.slice(index)
|
|
48
|
+
.map(({ scale }) => scale)
|
|
49
|
+
.reduce((sum, scale) => sum * scale, 1);
|
|
50
|
+
|
|
51
|
+
const value = ~~(rest / scale);
|
|
52
|
+
rest -= value * scale;
|
|
53
|
+
|
|
54
|
+
list.push({ value, label });
|
|
55
|
+
return list;
|
|
56
|
+
}, [] as TimeSection[]);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
tick = () => {
|
|
60
|
+
const { onEnd, endTime } = this.props,
|
|
61
|
+
rest = this.endTimestamp - Date.now();
|
|
62
|
+
|
|
63
|
+
if (rest > 0) {
|
|
64
|
+
this.rest = rest;
|
|
65
|
+
} else {
|
|
66
|
+
this.rest = 0;
|
|
67
|
+
this.stop();
|
|
68
|
+
onEnd?.(endTime);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
stop() {
|
|
73
|
+
if (this.timer) {
|
|
74
|
+
window.clearInterval(this.timer);
|
|
75
|
+
this.timer = 0;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
componentDidMount() {
|
|
80
|
+
super.componentDidMount();
|
|
81
|
+
this.initTimer();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@reaction(_this => _this.observedProps.endTime)
|
|
85
|
+
initTimer() {
|
|
86
|
+
this.stop();
|
|
87
|
+
this.tick();
|
|
88
|
+
this.timer = window.setInterval(this.tick, Second);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
componentWillUnmount() {
|
|
92
|
+
super.componentWillUnmount();
|
|
93
|
+
this.stop();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
render() {
|
|
97
|
+
const {
|
|
98
|
+
className = '',
|
|
99
|
+
itemClassName = 'border rounded px-4 py-3 d-flex flex-column justify-content-center align-items-center',
|
|
100
|
+
units: _u,
|
|
101
|
+
endTime: _e,
|
|
102
|
+
onEnd: _o,
|
|
103
|
+
...props
|
|
104
|
+
} = this.props;
|
|
105
|
+
const { timeSections } = this;
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<ol className={`list-unstyled m-0 ${className}`} {...props}>
|
|
109
|
+
{timeSections.map(({ value, label }) => (
|
|
110
|
+
<li key={label} className={itemClassName}>
|
|
111
|
+
<strong>{(value + '').padStart(2, '0')}</strong>
|
|
112
|
+
<span>{label}</span>
|
|
113
|
+
</li>
|
|
114
|
+
))}
|
|
115
|
+
</ol>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
package/source/Dialog.tsx
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { Defer } from 'iterable-observer';
|
|
2
|
-
import { observable } from 'mobx';
|
|
3
|
-
import { observer } from 'mobx-react';
|
|
4
|
-
import { FC } from 'react';
|
|
5
|
-
|
|
6
|
-
export class DialogClose extends Error {
|
|
7
|
-
constructor(message = 'Dialog closed') {
|
|
8
|
-
super(message);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface DialogProps<T = any> {
|
|
13
|
-
defer?: Defer<T>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class Dialog<I extends object = {}, O = any> {
|
|
17
|
-
@observable
|
|
18
|
-
accessor input = {} as I;
|
|
19
|
-
|
|
20
|
-
@observable
|
|
21
|
-
accessor defer: Defer<O> | undefined;
|
|
22
|
-
|
|
23
|
-
Component: FC<I>;
|
|
24
|
-
|
|
25
|
-
constructor(Factory: FC<I & DialogProps<O>>) {
|
|
26
|
-
this.Component = observer(props => (
|
|
27
|
-
<Factory {...props} {...this.input} defer={this.defer} />
|
|
28
|
-
));
|
|
29
|
-
this.Component.displayName = 'DialogComponent';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
open(input?: I) {
|
|
33
|
-
if (input) this.input = input;
|
|
34
|
-
|
|
35
|
-
this.defer = new Defer();
|
|
36
|
-
|
|
37
|
-
this.defer.promise.finally(() => (this.defer = undefined));
|
|
38
|
-
|
|
39
|
-
return this.defer.promise;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
import { Defer } from 'iterable-observer';
|
|
2
|
+
import { observable } from 'mobx';
|
|
3
|
+
import { observer } from 'mobx-react';
|
|
4
|
+
import { FC } from 'react';
|
|
5
|
+
|
|
6
|
+
export class DialogClose extends Error {
|
|
7
|
+
constructor(message = 'Dialog closed') {
|
|
8
|
+
super(message);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DialogProps<T = any> {
|
|
13
|
+
defer?: Defer<T>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Dialog<I extends object = {}, O = any> {
|
|
17
|
+
@observable
|
|
18
|
+
accessor input = {} as I;
|
|
19
|
+
|
|
20
|
+
@observable
|
|
21
|
+
accessor defer: Defer<O> | undefined;
|
|
22
|
+
|
|
23
|
+
Component: FC<I>;
|
|
24
|
+
|
|
25
|
+
constructor(Factory: FC<I & DialogProps<O>>) {
|
|
26
|
+
this.Component = observer(props => (
|
|
27
|
+
<Factory {...props} {...this.input} defer={this.defer} />
|
|
28
|
+
));
|
|
29
|
+
this.Component.displayName = 'DialogComponent';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
open(input?: I) {
|
|
33
|
+
if (input) this.input = input;
|
|
34
|
+
|
|
35
|
+
this.defer = new Defer();
|
|
36
|
+
|
|
37
|
+
this.defer.promise.finally(() => (this.defer = undefined));
|
|
38
|
+
|
|
39
|
+
return this.defer.promise;
|
|
40
|
+
}
|
|
41
|
+
}
|
package/source/Editor.tsx
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { EditorCore, WrapperProps } from '@react-editor-js/core';
|
|
2
|
-
import { observable } from 'mobx';
|
|
3
|
-
import { observer } from 'mobx-react';
|
|
4
|
-
import { Component, InputHTMLAttributes, PropsWithoutRef } from 'react';
|
|
5
|
-
import { createReactEditorJS } from 'react-editor-js';
|
|
6
|
-
|
|
7
|
-
const ReactEditorJS = createReactEditorJS();
|
|
8
|
-
|
|
9
|
-
export type EditorProps = PropsWithoutRef<
|
|
10
|
-
WrapperProps &
|
|
11
|
-
Pick<InputHTMLAttributes<HTMLInputElement>, 'name' | 'required'>
|
|
12
|
-
>;
|
|
13
|
-
|
|
14
|
-
@observer
|
|
15
|
-
export class Editor extends Component<EditorProps> {
|
|
16
|
-
static displayName = 'Editor';
|
|
17
|
-
|
|
18
|
-
private core?: EditorCore;
|
|
19
|
-
|
|
20
|
-
@observable
|
|
21
|
-
accessor innerValue = this.props.defaultValue;
|
|
22
|
-
|
|
23
|
-
save = async () => this.core && (this.innerValue = await this.core.save());
|
|
24
|
-
|
|
25
|
-
render() {
|
|
26
|
-
const { name, required, children, ...editorProps } = this.props,
|
|
27
|
-
{ innerValue } = this;
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<div className="form-control" tabIndex={-1} onBlur={this.save}>
|
|
31
|
-
<input
|
|
32
|
-
hidden
|
|
33
|
-
{...{ name, required }}
|
|
34
|
-
value={JSON.stringify(innerValue)}
|
|
35
|
-
/>
|
|
36
|
-
<ReactEditorJS
|
|
37
|
-
{...editorProps}
|
|
38
|
-
onInitialize={core => {
|
|
39
|
-
this.core = core;
|
|
40
|
-
editorProps.onInitialize?.(core);
|
|
41
|
-
}}
|
|
42
|
-
/>
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
import { EditorCore, WrapperProps } from '@react-editor-js/core';
|
|
2
|
+
import { observable } from 'mobx';
|
|
3
|
+
import { observer } from 'mobx-react';
|
|
4
|
+
import { Component, InputHTMLAttributes, PropsWithoutRef } from 'react';
|
|
5
|
+
import { createReactEditorJS } from 'react-editor-js';
|
|
6
|
+
|
|
7
|
+
const ReactEditorJS = createReactEditorJS();
|
|
8
|
+
|
|
9
|
+
export type EditorProps = PropsWithoutRef<
|
|
10
|
+
WrapperProps &
|
|
11
|
+
Pick<InputHTMLAttributes<HTMLInputElement>, 'name' | 'required'>
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
@observer
|
|
15
|
+
export class Editor extends Component<EditorProps> {
|
|
16
|
+
static displayName = 'Editor';
|
|
17
|
+
|
|
18
|
+
private core?: EditorCore;
|
|
19
|
+
|
|
20
|
+
@observable
|
|
21
|
+
accessor innerValue = this.props.defaultValue;
|
|
22
|
+
|
|
23
|
+
save = async () => this.core && (this.innerValue = await this.core.save());
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
const { name, required, children, ...editorProps } = this.props,
|
|
27
|
+
{ innerValue } = this;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className="form-control" tabIndex={-1} onBlur={this.save}>
|
|
31
|
+
<input
|
|
32
|
+
hidden
|
|
33
|
+
{...{ name, required }}
|
|
34
|
+
value={JSON.stringify(innerValue)}
|
|
35
|
+
/>
|
|
36
|
+
<ReactEditorJS
|
|
37
|
+
{...editorProps}
|
|
38
|
+
onInitialize={core => {
|
|
39
|
+
this.core = core;
|
|
40
|
+
editorProps.onInitialize?.(core);
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/source/EditorHTML.tsx
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import { OutputData } from '@editorjs/editorjs';
|
|
2
|
-
import createParser from 'editorjs-html';
|
|
3
|
-
import { FC,
|
|
4
|
-
|
|
5
|
-
export const parser = createParser({
|
|
6
|
-
link: ({ data: { link } }: Record<string, any>) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
dangerouslySetInnerHTML={{ __html: parser.parse(data) }}
|
|
18
|
-
className={className}
|
|
19
|
-
/>
|
|
20
|
-
);
|
|
21
|
-
EditorHTML.displayName = 'EditorHTML';
|
|
1
|
+
import { OutputData } from '@editorjs/editorjs';
|
|
2
|
+
import createParser from 'editorjs-html';
|
|
3
|
+
import { FC, HTMLAttributes } from 'react';
|
|
4
|
+
|
|
5
|
+
export const parser = createParser({
|
|
6
|
+
link: ({ data: { link } }: Record<string, any>) => `<a href="${link}">${link}</a>`
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export interface EditorHTMLProps extends HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
data: OutputData;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const EditorHTML: FC<EditorHTMLProps> = ({ data, ...props }) => (
|
|
14
|
+
<article {...props} dangerouslySetInnerHTML={{ __html: parser.parse(data) }} />
|
|
15
|
+
);
|
|
16
|
+
EditorHTML.displayName = 'EditorHTML';
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
@keyframes scrollItem {
|
|
2
|
-
0%,
|
|
3
|
-
10% {
|
|
4
|
-
transform: translateX(0);
|
|
5
|
-
}
|
|
6
|
-
90%,
|
|
7
|
-
100% {
|
|
8
|
-
transform: translateX(-100%);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
@keyframes scrollWrap {
|
|
12
|
-
0%,
|
|
13
|
-
10% {
|
|
14
|
-
transform: translateX(0);
|
|
15
|
-
}
|
|
16
|
-
90%,
|
|
17
|
-
100% {
|
|
18
|
-
transform: translateX(100%);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.scrollWrap {
|
|
23
|
-
animation: scrollWrap linear 4s alternate infinite;
|
|
24
|
-
.scrollItem {
|
|
25
|
-
animation: scrollItem linear 4s alternate infinite;
|
|
26
|
-
}
|
|
27
|
-
&:hover {
|
|
28
|
-
animation-play-state: paused;
|
|
29
|
-
.scrollItem {
|
|
30
|
-
animation-play-state: paused;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.scrollHeightWrap {
|
|
36
|
-
--scroll-height: 20px;
|
|
37
|
-
height: var(--scroll-height);
|
|
38
|
-
.scrollContainer {
|
|
39
|
-
transform: translateY(
|
|
40
|
-
calc(calc(-100% + var(--scroll-height) + var(--scroll-height)) * 2)
|
|
41
|
-
);
|
|
42
|
-
max-height: calc(var(--scroll-height) * 3);
|
|
43
|
-
.unScrollItem {
|
|
44
|
-
max-height: calc(var(--scroll-height) * 2);
|
|
45
|
-
line-height: var(--scroll-height);
|
|
46
|
-
}
|
|
47
|
-
.scrollItem {
|
|
48
|
-
height: var(--scroll-height);
|
|
49
|
-
line-height: var(--scroll-height);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
@keyframes scrollItem {
|
|
2
|
+
0%,
|
|
3
|
+
10% {
|
|
4
|
+
transform: translateX(0);
|
|
5
|
+
}
|
|
6
|
+
90%,
|
|
7
|
+
100% {
|
|
8
|
+
transform: translateX(-100%);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
@keyframes scrollWrap {
|
|
12
|
+
0%,
|
|
13
|
+
10% {
|
|
14
|
+
transform: translateX(0);
|
|
15
|
+
}
|
|
16
|
+
90%,
|
|
17
|
+
100% {
|
|
18
|
+
transform: translateX(100%);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.scrollWrap {
|
|
23
|
+
animation: scrollWrap linear 4s alternate infinite;
|
|
24
|
+
.scrollItem {
|
|
25
|
+
animation: scrollItem linear 4s alternate infinite;
|
|
26
|
+
}
|
|
27
|
+
&:hover {
|
|
28
|
+
animation-play-state: paused;
|
|
29
|
+
.scrollItem {
|
|
30
|
+
animation-play-state: paused;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.scrollHeightWrap {
|
|
36
|
+
--scroll-height: 20px;
|
|
37
|
+
height: var(--scroll-height);
|
|
38
|
+
.scrollContainer {
|
|
39
|
+
transform: translateY(
|
|
40
|
+
calc(calc(-100% + var(--scroll-height) + var(--scroll-height)) * 2)
|
|
41
|
+
);
|
|
42
|
+
max-height: calc(var(--scroll-height) * 3);
|
|
43
|
+
.unScrollItem {
|
|
44
|
+
max-height: calc(var(--scroll-height) * 2);
|
|
45
|
+
line-height: var(--scroll-height);
|
|
46
|
+
}
|
|
47
|
+
.scrollItem {
|
|
48
|
+
height: var(--scroll-height);
|
|
49
|
+
line-height: var(--scroll-height);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|