Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
chore: release
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Aug 8, 2024
1 parent b6a7ead commit ba66ff9
Show file tree
Hide file tree
Showing 20 changed files with 8,786 additions and 7,003 deletions.
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,40 @@
},
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@minko-fe/eslint-config": "^2.1.2",
"@changesets/cli": "^2.27.7",
"@minko-fe/eslint-config": "^3.3.3",
"@minko-fe/lodash-pro": "latest",
"@minko-fe/tsconfig": "^2.0.7",
"@swc/core": "^1.5.0",
"@testing-library/react": "^14.2.1",
"@minko-fe/tsconfig": "^2.1.0",
"@swc/core": "^1.7.6",
"@testing-library/react": "^14.3.1",
"@types/fs-extra": "^11.0.4",
"@types/node": "^18.19.14",
"@types/node": "^18.19.43",
"@types/prompts": "^2.4.9",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/validate-npm-package-name": "^4.0.2",
"chokidar": "^3.6.0",
"eslint": "^8.56.0",
"eslint": "^9.8.0",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"get-tsconfig": "^4.7.2",
"get-tsconfig": "^4.7.6",
"joycon": "^3.1.1",
"jsdom": "^22.1.0",
"jsonc-simple-parser": "^3.0.0",
"picocolors": "^1.0.0",
"picocolors": "^1.0.1",
"prompts": "^2.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rimraf": "^4.4.1",
"strip-dirs": "^3.0.0",
"taze": "^0.13.3",
"tsup": "^8.0.2",
"taze": "^0.16.3",
"tsup": "^8.2.4",
"tsup-plugin-bundleless": "^0.4.0",
"tsup-plugin-css-legacy": "^0.0.1",
"tsx": "^4.7.0",
"turbo": "^1.12.3",
"typescript": "^5.3.3",
"validate-npm-package-name": "^5.0.0",
"tsx": "^4.17.0",
"turbo": "^1.13.4",
"typescript": "^5.5.4",
"validate-npm-package-name": "^5.0.1",
"vitest": "^0.29.8"
},
"workspaces": [
Expand Down
7 changes: 7 additions & 0 deletions packages/react-component/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @minko-fe/react-component

## 0.2.11

### Patch Changes

- Updated dependencies []:
- @minko-fe/react-hook@0.4.0

## 0.2.10

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-component/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@minko-fe/react-component",
"version": "0.2.10",
"version": "0.2.11",
"description": "react-component",
"type": "module",
"keywords": [
Expand Down
6 changes: 6 additions & 0 deletions packages/react-hook/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @minko-fe/react-hook

## 0.4.0

### Minor Changes

- feat: add more hook

## 0.3.7

### Patch Changes
Expand Down
13 changes: 8 additions & 5 deletions packages/react-hook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@minko-fe/react-hook",
"version": "0.3.7",
"version": "0.4.0",
"description": "react-hook",
"type": "module",
"keywords": [
Expand Down Expand Up @@ -50,13 +50,17 @@
"up": "taze -I -w"
},
"peerDependencies": {
"query-string": ">=7.0.0",
"react": ">=17.0.0",
"react-dom": ">=17.0.0",
"react-router-dom": ">=6.0.0"
},
"peerDependenciesMeta": {
"react-router-dom": {
"optional": true
},
"query-string": {
"optional": true
}
},
"dependencies": {
Expand All @@ -66,9 +70,8 @@
"use-global-style": "^1.0.1"
},
"devDependencies": {
"query-string": "7.1.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0"
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.24.1"
}
}
4 changes: 3 additions & 1 deletion packages/react-hook/src/useEffectOnce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { useEffect, useRef } from 'react'
function useEffectOnce(cb: React.EffectCallback, deps?: React.DependencyList | undefined): void {
const mountRef = useRef(false)
useEffect(() => {
let returnValue
if (mountRef.current === false) {
cb()
returnValue = cb()
mountRef.current = true
}
return returnValue
}, [deps])
}

Expand Down
103 changes: 103 additions & 0 deletions packages/react-hook/src/useImperative/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { isBrowser } from '@minko-fe/lodash-pro'
import { render as ReactRender, unmount as ReactUnmount } from './render'

const destroyFns: Array<() => void> = []

type ConfigUpdate<T> = Partial<T> | ((prev: T) => Partial<T>)

type Config<T = any> = {
/**
* @description 声明式组件
*/
RC: React.FC<T>
keys: {
/**
* 显隐 key
*/
visible: keyof T
/**
* 关闭回调 key
*/
onClosed: keyof T
}
/**
* @description 组件的runtime props
*/
props: Partial<T>
}

/**
* @description 把显隐的声明式tsx转换为命令式
* 如 antd 的 Modal
* 如 vant 的 Dialog
*/
function imperative<T>(config: Config<T>) {
if (!isBrowser()) return null
const {
RC,
keys: { visible: visibleKey, onClosed: onClosedKey },
props,
} = config

const container = document.createDocumentFragment()

let currentProps = { ...props, [visibleKey]: true } as any
let timeoutId: ReturnType<typeof setTimeout>

function destroy() {
for (let i = 0; i < destroyFns.length; i++) {
const fn = destroyFns[i]
if (fn === close) {
destroyFns.splice(i, 1)
break
}
}
ReactUnmount(container)
}

function render(props: any) {
clearTimeout(timeoutId)

timeoutId = setTimeout(() => {
ReactRender(<RC {...props} />, container)
})
}

function close(...args: any[]) {
currentProps = {
...currentProps,
[visibleKey]: false,
[onClosedKey]: () => {
if (typeof props[onClosedKey] === 'function') {
;(props[onClosedKey] as Function)()
}
// @ts-expect-error
destroy.apply(this, args)
},
}
render(currentProps)
}

function update(configUpdate: ConfigUpdate<T>) {
if (typeof configUpdate === 'function') {
currentProps = configUpdate(currentProps)
} else {
currentProps = {
...currentProps,
...configUpdate,
}
}
render(currentProps)
}

render(currentProps)

destroyFns.push(close)

return {
destroy: close,
update,
}
}

export { imperative }
90 changes: 90 additions & 0 deletions packages/react-hook/src/useImperative/render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { type ReactElement } from 'react'
import * as ReactDOM from 'react-dom'
import { version as _reactDomVersion } from 'react-dom'
import { type Root } from 'react-dom/client'

const reactDomVersion = Number((_reactDomVersion || '').split('.')[0])

// 移植自rc-util: https://github.com/react-component/util/blob/master/src/React/render.ts

type CreateRoot = (container: ContainerType) => Root

// Let compiler not to search module usage
const fullClone = {
...ReactDOM,
} as typeof ReactDOM & {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?: {
usingClientEntryPoint?: boolean
}
createRoot?: CreateRoot
}

const { render: reactRender, unmountComponentAtNode } = fullClone

let createRoot: CreateRoot
try {
if (reactDomVersion >= 18 && fullClone.createRoot) {
createRoot = fullClone.createRoot
}
} catch {
// Do nothing;
}

function toggleWarning(skip: boolean) {
const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } = fullClone

if (
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED &&
typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === 'object'
) {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip
}
}

const MARK = '__react_root__'

// ========================== Render ==========================
type ContainerType = (Element | DocumentFragment) & {
[MARK]?: Root
}

function legacyRender(node: ReactElement, container: ContainerType) {
reactRender(node, container)
}

function concurrentRender(node: ReactElement, container: ContainerType) {
toggleWarning(true)
const root = container[MARK] || createRoot(container)
toggleWarning(false)
root.render(node)
container[MARK] = root
}

export function render(node: ReactElement, container: ContainerType) {
if (createRoot as unknown) {
concurrentRender(node, container)
return
}
legacyRender(node, container)
}

// ========================== Unmount =========================
function legacyUnmount(container: ContainerType) {
return unmountComponentAtNode(container)
}

async function concurrentUnmount(container: ContainerType) {
// Delay to unmount to avoid React 18 sync warning
return Promise.resolve().then(() => {
container[MARK]?.unmount()
delete container[MARK]
})
}

export function unmount(container: ContainerType) {
if (createRoot as unknown) {
return concurrentUnmount(container)
}

return legacyUnmount(container)
}
38 changes: 38 additions & 0 deletions packages/react-hook/src/useSteps/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useMemoizedFn } from 'ahooks'
import { useEffect, useState } from 'react'

/**
* @description 在多个步骤中切换。如果当前步骤是最后一个步骤,则下一个步骤将是第一个步骤。
* @param steps 步骤列表
* @param defaultValue 默认步骤
* @param onChange 步骤变化时的回调
*/
export default function useStep<T extends string>(
steps: T[],
{
defaultValue,
onChange,
}: {
defaultValue?: T
onChange?: (step: T) => void
},
) {
const [currentStep, setCurrentStep] = useState(defaultValue || steps[0])

const next = useMemoizedFn(() => {
const currentIndex = steps.indexOf(currentStep)
if (steps.length && currentIndex !== -1) {
if (currentIndex < steps.length - 1) {
setCurrentStep(steps[currentIndex + 1])
} else {
setCurrentStep(steps[0])
}
}
})

useEffect(() => {
onChange?.(currentStep)
}, [currentStep, onChange])

return [currentStep, next] as const
}
Loading

0 comments on commit ba66ff9

Please sign in to comment.