Skip to content

Commit 7668c82

Browse files
committed
chore: breaking changes
1 parent 4bd3740 commit 7668c82

1,597 files changed

Lines changed: 3569 additions & 3953 deletions

File tree

Some content is hidden

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

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"request": "launch",
1212
"args": ["--extensionDevelopmentPath=${workspaceFolder}/dist/packages/vscode-extension"],
1313
"outFiles": ["${workspaceFolder}/dist/packages/vscode-extension/**/*.js"],
14-
"preLaunchTask": "watch:vscode-extension"
14+
"preLaunchTask": "build:vscode-extension"
1515
}
1616
]
1717
}

.vscode/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"label": "watch:vscode-extension",
8-
"type": "npm",
9-
"script": "watch:vscode-extension",
7+
"label": "build:vscode-extension",
8+
"type": "shell",
9+
"command": "yarn nx build vscode-extension --watch",
1010
"problemMatcher": "$tsc-watch",
1111
"isBackground": true,
1212
"presentation": {

nx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"default": {
2424
"runner": "@nrwl/nx-cloud",
2525
"options": {
26-
"cacheableOperations": ["build-base", "build", "lint", "test", "e2e"],
26+
"cacheableOperations": ["build", "lint", "test", "e2e"],
2727
"accessToken": "ZTE4ZjVjMDMtNmJiOS00MmRlLThiMTQtMzczNjlmOGY5MWNhfHJlYWQtd3JpdGU="
2828
}
2929
}

package.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,26 @@
77
"license": "MIT",
88
"scripts": {
99
"build:affected": "nx affected --target=build --parallel=5",
10-
"build:executors": "tsc --project tools/tsconfig.json",
11-
"build:icons": "node ./tools/ui-icons.js",
10+
"build:icons": "ts-node -P ./tools/tsconfig.json ./tools/ui-icons.ts",
1211
"build:vscode-extension": "nx build vscode-extension && cd dist/packages/vscode-extension && yarn install && vsce package --yarn",
13-
"check-update": "yarn upgrade-interactive --latest",
1412
"lint:affected": "nx affected --target=lint --parallel=5",
1513
"lint:style": "stylelint **/*.{css,scss,html,md}",
1614
"lint:style:fix": "yarn lint:style --fix",
1715
"prepare": "husky install && chmod ug+x .husky/*",
1816
"prepublishOnly": "nx run-many --target=build --parallel=5 --exclude=site,vscode-extension",
19-
"prepublish:vscode-extension": "yarn build:vscode-extension",
20-
"publish:vscode-extension": "cd dist/packages/vscode-extension && vsce publish --yarn",
21-
"site:serve": "nx serve site",
22-
"sort-package-json": "npx sort-package-json 'package.json' 'packages/*/package.json'",
17+
"publish:vscode-extension": "yarn build:vscode-extension && cd dist/packages/vscode-extension && vsce publish --yarn",
18+
"serve:site": "nx serve site",
2319
"test:affected": "nx affected --target=test --parallel=5",
24-
"version": "npx prettier lerna.json --write",
25-
"watch:vscode-extension": "nx build vscode-extension --watch"
20+
"util:check-update": "yarn upgrade-interactive --latest",
21+
"util:sort-package-json": "npx sort-package-json 'package.json' 'packages/*/package.json'",
22+
"version": "npx prettier lerna.json --write"
2623
},
27-
"dependencies": {
24+
"devDependencies": {
2825
"@ant-design/icons-svg": "^4.2.1",
2926
"@commitlint/cli": "^17.0.3",
3027
"@commitlint/config-conventional": "^17.0.3",
3128
"@nrwl/cli": "14.5.6",
29+
"@nrwl/cypress": "14.5.6",
3230
"@nrwl/eslint-plugin-nx": "14.5.6",
3331
"@nrwl/jest": "14.5.6",
3432
"@nrwl/linter": "14.5.6",
@@ -50,15 +48,20 @@
5048
"@types/react": "^18.0.17",
5149
"@types/react-dom": "^18.0.6",
5250
"@types/vscode": "^1.70.0",
51+
"@types/yaml-front-matter": "^4.1.0",
5352
"@typescript-eslint/eslint-plugin": "^5.33.0",
5453
"@typescript-eslint/parser": "^5.33.0",
5554
"@vscode/test-electron": "^2.1.5",
55+
"axios": "^0.27.2",
56+
"axios-mock-adapter": "^1.21.2",
5657
"babel-jest": "^27.5.1",
5758
"codesandbox": "^2.2.3",
5859
"core-js": "^3.24.1",
60+
"cypress": "^10.2.0",
5961
"dayjs": "^1.11.5",
6062
"eslint": "^8.22.0",
6163
"eslint-config-prettier": "^8.5.0",
64+
"eslint-plugin-cypress": "^2.10.3",
6265
"eslint-plugin-import": "^2.26.0",
6366
"eslint-plugin-jsdoc": "^39.3.6",
6467
"eslint-plugin-jsx-a11y": "^6.6.1",

packages/hooks/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,5 @@
3232
"publishConfig": {
3333
"access": "public",
3434
"directory": "../../dist/packages/hooks"
35-
},
36-
"title": "DevUI"
35+
}
3736
}

packages/hooks/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "../../node_modules/nx/schemas/project-schema.json",
3-
"sourceRoot": "packages/hooks",
3+
"sourceRoot": "packages/hooks/src",
44
"projectType": "library",
55
"tags": ["scope:shared"],
66
"targets": {
@@ -10,7 +10,7 @@
1010
"options": {
1111
"outputPath": "dist/packages/hooks",
1212
"tsConfig": "packages/hooks/tsconfig.lib.json",
13-
"main": "packages/hooks/index.ts",
13+
"main": "packages/hooks/src/index.ts",
1414
"updateBuildableProjectDepsInPackageJson": false,
1515
"assets": [
1616
{
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { ImmerHook } from './useImmer';
2+
3+
import { freeze, produce } from 'immer';
4+
5+
import { useForceUpdate } from './useForceUpdate';
6+
import { useUnmount } from './useUnmount';
7+
8+
export function createGlobalState<S>(): () => ImmerHook<S | undefined>;
9+
export function createGlobalState<S>(initialValue: S): () => ImmerHook<S>;
10+
export function createGlobalState<S>(initialValue?: S): () => ImmerHook<S | undefined> {
11+
const store = {
12+
state: freeze(typeof initialValue === 'function' ? initialValue() : initialValue, true),
13+
setState(updater: any) {
14+
const prev = store.state;
15+
if (typeof updater === 'function') {
16+
store.state = produce(store.state, updater);
17+
} else {
18+
store.state = freeze(updater);
19+
}
20+
if (!Object.is(store.state, prev)) {
21+
for (const update of store.updates) {
22+
update();
23+
}
24+
}
25+
},
26+
updates: new Set<() => void>(),
27+
};
28+
29+
return () => {
30+
const forceUpdate = useForceUpdate();
31+
if (!store.updates.has(forceUpdate)) {
32+
store.updates.add(forceUpdate);
33+
}
34+
35+
useUnmount(() => {
36+
store.updates.delete(forceUpdate);
37+
});
38+
39+
return [store.state, store.setState];
40+
};
41+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
export { createGlobalState } from './createGlobalState';
12
export { useAsync } from './useAsync';
3+
export { useEvent } from './useEvent';
4+
export { useEventCallback } from './useEventCallback';
25
export { useElement } from './useElement';
6+
export { useEventListener } from './useEventListener';
37
export { useEventNotify } from './useEventNotify';
48
export { useForceUpdate } from './useForceUpdate';
59
export { useForkRef } from './useForkRef';
610
export { useImmer } from './useImmer';
711
export { useLockScroll } from './useLockScroll';
12+
export { useMediaMatch } from './useMediaMatch';
813
export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
14+
export { useLocalStorage } from './useLocalStorage';
915
export { useMount } from './useMount';
16+
export { useResize } from './useResize';
1017
export { useUnmount } from './useUnmount';

packages/hooks/src/useAsync.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { useMemo } from 'react';
2+
3+
import { useUnmount } from './useUnmount';
4+
5+
class AsyncInstance {
6+
protected clearFns = new Set<() => void>();
7+
8+
clearAll() {
9+
for (const clear of this.clearFns) {
10+
clear();
11+
}
12+
}
13+
14+
setTimeout(handler: TimerHandler, timeout?: number) {
15+
const tid = window.setTimeout(handler, timeout);
16+
const clear = () => {
17+
clearTimeout(tid);
18+
};
19+
this.clearFns.add(clear);
20+
21+
return clear;
22+
}
23+
24+
requestAnimationFrame(...args: Parameters<typeof requestAnimationFrame>) {
25+
const tid = requestAnimationFrame(...args);
26+
const clear = () => {
27+
cancelAnimationFrame(tid);
28+
};
29+
this.clearFns.add(clear);
30+
31+
return clear;
32+
}
33+
}
34+
35+
export class Async extends AsyncInstance {
36+
private instances = new Set<AsyncInstance>();
37+
38+
create(): AsyncInstance {
39+
const instance = new AsyncInstance();
40+
this.instances.add(instance);
41+
return instance;
42+
}
43+
44+
override clearAll() {
45+
for (const clear of this.clearFns) {
46+
clear();
47+
}
48+
49+
for (const instance of this.instances) {
50+
instance.clearAll();
51+
}
52+
}
53+
}
54+
55+
export function useAsync(): Async {
56+
const async = useMemo(() => new Async(), []);
57+
58+
useUnmount(() => {
59+
async.clearAll();
60+
});
61+
62+
return async;
63+
}
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
import { isString } from 'lodash';
2-
import { useMemo, useRef } from 'react';
3-
4-
import { SSR_ENV } from '@react-devui/utils';
52

63
import { useForceUpdate } from './useForceUpdate';
74
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
85

96
export type DElementSelector = string | (() => HTMLElement | null);
107

118
export function useElement(selector: DElementSelector): HTMLElement | null {
12-
const rendered = useRef(false);
139
const getEl = () => (isString(selector) ? (document.querySelector(selector) as HTMLElement | null) : selector());
10+
const el = typeof window === 'undefined' ? null : getEl();
1411

15-
const initEl = useMemo(() => {
16-
if (SSR_ENV) {
17-
return null;
18-
} else {
19-
return getEl();
20-
}
21-
// eslint-disable-next-line react-hooks/exhaustive-deps
22-
}, []);
2312
const forceUpdate = useForceUpdate();
2413
useIsomorphicLayoutEffect(() => {
25-
rendered.current = true;
26-
27-
if (getEl() !== initEl) {
14+
if (getEl() !== el) {
2815
forceUpdate();
2916
}
3017
}, []);
3118

32-
return rendered.current ? getEl() : initEl;
19+
return el;
3320
}

0 commit comments

Comments
 (0)