Skip to content

Commit 6b83ccb

Browse files
committed
feat(ui): provide SSR support
1 parent e7331f4 commit 6b83ccb

67 files changed

Lines changed: 2123 additions & 2270 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.stylelintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"files": ["*.scss", "**/*.scss"],
3434
"rules": {
3535
"at-rule-no-unknown": null,
36-
"scss/at-rule-no-unknown": true
36+
"scss/at-rule-no-unknown": true,
37+
"function-no-unknown": null
3738
}
3839
},
3940
{

package.json

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,55 +28,55 @@
2828
"check-update": "yarn upgrade-interactive --latest"
2929
},
3030
"dependencies": {
31-
"core-js": "^3.20.3",
31+
"core-js": "^3.21.0",
3232
"highlight.js": "^11.4.0",
33-
"i18next": "^21.6.7",
33+
"i18next": "^21.6.11",
3434
"immer": "^9.0.12",
3535
"lodash": "^4.17.21",
36-
"marked": "^4.0.10",
36+
"marked": "^4.0.12",
3737
"react": "18.0.0-rc.0",
3838
"react-dom": "18.0.0-rc.0",
39-
"react-i18next": "^11.15.3",
39+
"react-i18next": "^11.15.4",
4040
"react-router-dom": "^6.2.1",
4141
"regenerator-runtime": "^0.13.9",
4242
"rfs": "^9.0.6",
43-
"rxjs": "^7.5.2",
44-
"scrollview-resize": "^1.0.1",
43+
"rxjs": "^7.5.3",
44+
"scrollview-resize": "^1.0.2",
4545
"tslib": "^2.3.1"
4646
},
4747
"devDependencies": {
4848
"@commitlint/cli": "^16.1.0",
4949
"@commitlint/config-conventional": "^16.0.0",
50-
"@nrwl/cli": "^13.4.6",
51-
"@nrwl/cypress": "^13.4.6",
52-
"@nrwl/eslint-plugin-nx": "^13.4.6",
53-
"@nrwl/jest": "^13.4.6",
54-
"@nrwl/linter": "^13.4.6",
55-
"@nrwl/nx-cloud": "13.1.2",
56-
"@nrwl/react": "^13.4.6",
57-
"@nrwl/tao": "^13.4.6",
58-
"@nrwl/web": "^13.4.6",
59-
"@nrwl/workspace": "^13.4.6",
60-
"@testing-library/jest-dom": "^5.16.1",
50+
"@nrwl/cli": "^13.8.0",
51+
"@nrwl/cypress": "^13.8.0",
52+
"@nrwl/eslint-plugin-nx": "^13.8.0",
53+
"@nrwl/jest": "^13.8.0",
54+
"@nrwl/linter": "^13.8.0",
55+
"@nrwl/nx-cloud": "13.1.4",
56+
"@nrwl/react": "^13.8.0",
57+
"@nrwl/tao": "^13.8.0",
58+
"@nrwl/web": "^13.8.0",
59+
"@nrwl/workspace": "^13.8.0",
60+
"@testing-library/jest-dom": "^5.16.2",
6161
"@testing-library/react": "13.0.0-alpha.5",
6262
"@testing-library/react-hooks": "^7.0.2",
6363
"@types/fs-extra": "^9.0.13",
6464
"@types/jest": "^27.4.0",
6565
"@types/lodash": "^4.14.177",
66-
"@types/marked": "^4.0.1",
67-
"@types/node": "^17.0.12",
68-
"@types/react": "^17.0.38",
66+
"@types/marked": "^4.0.2",
67+
"@types/node": "^17.0.16",
68+
"@types/react": "^17.0.39",
6969
"@types/react-dom": "^17.0.11",
70-
"@typescript-eslint/eslint-plugin": "^5.10.1",
71-
"@typescript-eslint/parser": "^5.10.1",
72-
"babel-jest": "^27.4.6",
73-
"cypress": "^9.3.1",
74-
"dotenv": "^14.3.0",
75-
"eslint": "^8.7.0",
70+
"@typescript-eslint/eslint-plugin": "^5.11.0",
71+
"@typescript-eslint/parser": "^5.11.0",
72+
"babel-jest": "^27.5.1",
73+
"cypress": "^9.4.1",
74+
"dotenv": "^16.0.0",
75+
"eslint": "^8.8.0",
7676
"eslint-config-prettier": "^8.3.0",
7777
"eslint-plugin-cypress": "^2.12.1",
7878
"eslint-plugin-import": "^2.25.4",
79-
"eslint-plugin-jsdoc": "^37.6.3",
79+
"eslint-plugin-jsdoc": "^37.8.0",
8080
"eslint-plugin-jsx-a11y": "^6.5.1",
8181
"eslint-plugin-markdown": "^2.2.1",
8282
"eslint-plugin-prettier": "^4.0.0",
@@ -85,23 +85,23 @@
8585
"eslint-plugin-tsdoc": "^0.2.14",
8686
"fs-extra": "^10.0.0",
8787
"husky": "^7.0.4",
88-
"jest": "^27.4.7",
88+
"jest": "^27.5.1",
8989
"postcss-html": "^1.3.0",
9090
"postcss-markdown": "^1.2.0",
9191
"prettier": "^2.5.0",
9292
"react-test-renderer": "^17.0.2",
9393
"rxjs-for-await": "^1.0.0",
94-
"sass": "^1.49.0",
94+
"sass": "^1.49.7",
9595
"standard-version": "^9.3.2",
96-
"stylelint": "^14.3.0",
96+
"stylelint": "^14.4.0",
9797
"stylelint-config-prettier": "^9.0.3",
9898
"stylelint-config-rational-order": "^0.1.2",
9999
"stylelint-config-recommended-scss": "^5.0.2",
100-
"stylelint-config-standard": "^24.0.0",
100+
"stylelint-config-standard": "^25.0.0",
101101
"stylelint-order": "^5.0.0",
102102
"stylelint-scss": "^4.1.0",
103103
"ts-jest": "^27.1.3",
104-
"ts-node": "^10.4.0",
104+
"ts-node": "^10.5.0",
105105
"typescript": "~4.5.5",
106106
"yaml-front-matter": "^4.1.1"
107107
}

packages/site/.eslintrc.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
"overrides": [
55
{
66
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7-
"rules": {}
7+
"rules": {
8+
"react-hooks/exhaustive-deps": [
9+
"warn",
10+
{
11+
"additionalHooks": "(useIsomorphicLayoutEffect)"
12+
}
13+
]
14+
}
815
},
916
{
1017
"files": ["*.ts", "*.tsx"],

packages/site/src/app/components/route/RouteArticle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ m -673.67664,1221.6502 -231.2455,-231.24803 55.6165,
9494
{mediaMatch.includes('md') && links.length > 0 && (
9595
<DAnchor className="app-route-article__anchor" dPage=".app-main">
9696
{links.map((link) => (
97-
<DAnchorLink key={link.href} href={link.href} title={link.title}>
97+
<DAnchorLink key={link.href} dAProps={link}>
9898
{link.title}
9999
</DAnchorLink>
100100
))}
@@ -106,7 +106,7 @@ m -673.67664,1221.6502 -231.2455,-231.24803 55.6165,
106106
<div ref={ref} className="app-route-article__anchor-conatiner" style={{ visibility: hidden ? 'hidden' : undefined }}>
107107
<DAnchor dPage=".app-main" dIndicator={DAnchor.LINE_INDICATOR}>
108108
{links.map((link) => (
109-
<DAnchorLink key={link.href} href={link.href} title={link.title} onClick={() => setMenuOpen(false)}>
109+
<DAnchorLink key={link.href} dAProps={link} onClick={() => setMenuOpen(false)}>
110110
{link.title}
111111
</DAnchorLink>
112112
))}

packages/ui/.eslintrc.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
"overrides": [
55
{
66
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7-
"rules": {}
7+
"rules": {
8+
"react-hooks/exhaustive-deps": [
9+
"warn",
10+
{
11+
"additionalHooks": "(useIsomorphicLayoutEffect)"
12+
}
13+
]
14+
}
815
},
916
{
1017
"files": ["*.ts", "*.tsx"],

packages/ui/src/components/drag-drop/Drag.tsx renamed to packages/ui/src/components/_drag-drop/Drag.tsx

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@ import React, { useId, useEffect, useMemo, useState, useRef } from 'react';
33
import ReactDOM from 'react-dom';
44
import { merge } from 'rxjs';
55

6-
import {
7-
useComponentConfig,
8-
useRefSelector,
9-
useThrottle,
10-
useAsync,
11-
usePrefixConfig,
12-
useCustomContext,
13-
useImmer,
14-
useStateBackflow,
15-
} from '../../hooks';
16-
import { generateComponentMate } from '../../utils';
6+
import { useElement, useThrottle, useAsync, usePrefixConfig, useCustomContext, useImmer, useIsomorphicLayoutEffect } from '../../hooks';
177
import { DDropContext } from './Drop';
188

199
export interface DDragProps {
@@ -25,16 +15,13 @@ export interface DDragProps {
2515
onDragEnd?: () => void;
2616
}
2717

28-
const { COMPONENT_NAME } = generateComponentMate('DDrag');
2918
export function DDrag(props: DDragProps) {
30-
const { dId, dPlaceholder, dZIndex, children, onDragStart, onDragEnd } = useComponentConfig(COMPONENT_NAME, props);
19+
const { dId, dPlaceholder, dZIndex, children, onDragStart, onDragEnd } = props;
3120

3221
//#region Context
3322
const dPrefix = usePrefixConfig();
34-
const [
35-
{ updateSelectors, removeSelectors, dropOuter, dropPlaceholder, onDragStart: _onDragStart, onDrag: _onDrag, onDragEnd: _onDragEnd },
36-
dropContext,
37-
] = useCustomContext(DDropContext);
23+
const [{ gUpdateSelectors, gRemoveSelectors, gOuter, gPlaceholder, gOnDragStart, gOnDrag, gOnDragEnd }, dropContext] =
24+
useCustomContext(DDropContext);
3825
//#endregion
3926

4027
const dataRef = useRef<{ dragEl: HTMLElement | null }>({
@@ -52,7 +39,7 @@ export function DDrag(props: DDragProps) {
5239

5340
const inDrop = dropContext !== null;
5441

55-
const placeholderRef = useRefSelector(`[data-${dPrefix}drag-placeholder="${uniqueId}"]`);
42+
const placeholderEl = useElement(`[data-${dPrefix}drag-placeholder="${uniqueId}"]`);
5643

5744
const [containerEl] = useState(() => {
5845
let el = document.getElementById(`${dPrefix}drag-root`);
@@ -64,26 +51,25 @@ export function DDrag(props: DDragProps) {
6451
return el;
6552
});
6653

67-
useStateBackflow(
68-
updateSelectors,
69-
removeSelectors,
70-
dId as string,
71-
`[data-${dPrefix}drag="${uniqueId}"]`,
72-
`[data-${dPrefix}drag-placeholder="${uniqueId}"]`
73-
);
54+
useIsomorphicLayoutEffect(() => {
55+
gUpdateSelectors?.(dId as string, `[data-${dPrefix}drag="${uniqueId}"]`, `[data-${dPrefix}drag-placeholder="${uniqueId}"]`);
56+
return () => {
57+
gRemoveSelectors?.(dId as string);
58+
};
59+
}, [dId, dPrefix, gRemoveSelectors, uniqueId, gUpdateSelectors]);
7460

7561
useEffect(() => {
7662
if (isDragging && isNumber(fixedStyle.top) && isNumber(fixedStyle.left)) {
7763
if (dId) {
78-
_onDrag?.(dId, {
64+
gOnDrag?.(dId, {
7965
width: dragSize.width,
8066
height: dragSize.height,
8167
top: fixedStyle.top,
8268
left: fixedStyle.left,
8369
});
8470
}
8571
}
86-
}, [_onDrag, dId, dragSize.height, dragSize.width, fixedStyle.left, fixedStyle.top, isDragging]);
72+
}, [gOnDrag, dId, dragSize.height, dragSize.width, fixedStyle.left, fixedStyle.top, isDragging]);
8773

8874
useEffect(() => {
8975
const [asyncGroup, asyncId] = asyncCapture.createGroup();
@@ -111,7 +97,7 @@ export function DDrag(props: DDragProps) {
11197
draft.left = window.innerWidth - dragSize.width;
11298
}
11399

114-
draft.cursor = dropOuter ? 'not-allowed' : 'grabbing';
100+
draft.cursor = gOuter ? 'not-allowed' : 'grabbing';
115101
});
116102
};
117103

@@ -162,7 +148,7 @@ export function DDrag(props: DDragProps) {
162148
return () => {
163149
asyncCapture.deleteGroup(asyncId);
164150
};
165-
}, [asyncCapture, dragSize.height, dragSize.width, dropOuter, isDragging, setFixedStyle, throttleByAnimationFrame]);
151+
}, [asyncCapture, dragSize.height, dragSize.width, gOuter, isDragging, setFixedStyle, throttleByAnimationFrame]);
166152

167153
useEffect(() => {
168154
const [asyncGroup, asyncId] = asyncCapture.createGroup();
@@ -178,7 +164,7 @@ export function DDrag(props: DDragProps) {
178164
setIsDragging(false);
179165
if (inDrop) {
180166
setFixedStyle((draft) => {
181-
const rect = placeholderRef.current?.getBoundingClientRect();
167+
const rect = placeholderEl?.getBoundingClientRect();
182168
if (rect) {
183169
draft.top = rect.top;
184170
draft.left = rect.left;
@@ -192,7 +178,7 @@ export function DDrag(props: DDragProps) {
192178
setFixedDrag(false);
193179
setShowPlaceholder(false);
194180
if (dId) {
195-
_onDragEnd?.(dId);
181+
gOnDragEnd?.(dId);
196182
}
197183
onDragEnd?.();
198184
}, 100 + 10);
@@ -212,14 +198,14 @@ export function DDrag(props: DDragProps) {
212198
asyncCapture,
213199
inDrop,
214200
isDragging,
215-
_onDragEnd,
216-
placeholderRef,
201+
gOnDragEnd,
217202
setFixedDrag,
218203
setFixedStyle,
219204
setIsDragging,
220205
setShowPlaceholder,
221206
onDragEnd,
222207
dId,
208+
placeholderEl,
223209
]);
224210

225211
const child = useMemo(() => {
@@ -243,7 +229,7 @@ export function DDrag(props: DDragProps) {
243229

244230
onDragStart?.();
245231
if (dId) {
246-
_onDragStart?.(dId);
232+
gOnDragStart?.(dId);
247233
}
248234

249235
const currentTarget = e.currentTarget as HTMLElement;
@@ -293,11 +279,11 @@ export function DDrag(props: DDragProps) {
293279
setShowPlaceholder,
294280
setFixedDrag,
295281
setIsDragging,
296-
_onDragStart,
282+
gOnDragStart,
297283
]);
298284

299285
const placeholder = useMemo(() => {
300-
const placeholder = (dropPlaceholder ?? dPlaceholder) as React.ReactElement<React.HTMLAttributes<HTMLElement>> | undefined;
286+
const placeholder = (gPlaceholder ?? dPlaceholder) as React.ReactElement<React.HTMLAttributes<HTMLElement>> | undefined;
301287

302288
if (placeholder) {
303289
return React.cloneElement<React.HTMLAttributes<HTMLElement>>(placeholder, {
@@ -312,7 +298,7 @@ export function DDrag(props: DDragProps) {
312298
}
313299

314300
return null;
315-
}, [dPlaceholder, dPrefix, dragSize.height, dragSize.width, dropPlaceholder, uniqueId]);
301+
}, [dPlaceholder, dPrefix, dragSize.height, dragSize.width, gPlaceholder, uniqueId]);
316302

317303
return (
318304
<>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useCustomContext, usePrefixConfig } from '../../hooks';
2+
import { getClassName } from '../../utils';
3+
import { DDropContext } from './Drop';
4+
5+
export type DDragPlaceholderProps = React.HTMLAttributes<HTMLDivElement>;
6+
7+
export function DDragPlaceholder(props: DDragPlaceholderProps) {
8+
const { className, ...restProps } = props;
9+
10+
//#region Context
11+
const dPrefix = usePrefixConfig();
12+
const [{ gDirection }] = useCustomContext(DDropContext);
13+
//#endregion
14+
15+
return (
16+
<div
17+
{...restProps}
18+
className={getClassName(className, `${dPrefix}drag-placeholder`, {
19+
[`${dPrefix}drag-placeholder--horizontal`]: gDirection === 'horizontal',
20+
})}
21+
></div>
22+
);
23+
}

0 commit comments

Comments
 (0)