diff --git a/.eslintrc.js b/.eslintrc.js
deleted file mode 100644
index f6ac4bb..0000000
--- a/.eslintrc.js
+++ /dev/null
@@ -1,11 +0,0 @@
-const base = require('@umijs/fabric/dist/eslint');
-const path = require('path');
-
-module.exports = {
- ...base,
- rules: {
- ...base.rules,
- 'react/no-string-refs': 0,
- 'react/no-deprecated': 0,
- },
-};
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..758659a
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,2 @@
+github: ant-design
+open_collective: ant-design
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 3a3cce5..5e6c7fa 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,11 +1,27 @@
-# To get started with Dependabot version updates, you'll need to specify which
-# package ecosystems to update and where the package manifests are located.
-# Please see the documentation for all configuration options:
-# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
-
version: 2
updates:
- - package-ecosystem: "npm" # See documentation for possible values
- directory: "/" # Location of package manifests
+ - package-ecosystem: npm
+ directory: '/'
+ schedule:
+ interval: weekly
+ day: monday
+ time: '21:00'
+ timezone: Asia/Shanghai
+ open-pull-requests-limit: 10
+ groups:
+ npm-dependencies:
+ patterns:
+ - '*'
+
+ - package-ecosystem: github-actions
+ directory: '/'
schedule:
- interval: "weekly"
+ interval: weekly
+ day: monday
+ time: '21:00'
+ timezone: Asia/Shanghai
+ open-pull-requests-limit: 10
+ groups:
+ github-actions:
+ patterns:
+ - '*'
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
deleted file mode 100644
index f860ff1..0000000
--- a/.github/workflows/ci.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-name: ✅ test
-on: [push, pull_request]
-jobs:
- test:
- uses: react-component/rc-test/.github/workflows/test.yml@main
- secrets: inherit
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
new file mode 100644
index 0000000..54244f7
--- /dev/null
+++ b/.github/workflows/codeql.yml
@@ -0,0 +1,43 @@
+name: 'CodeQL'
+
+on:
+ push:
+ branches: ['main']
+ pull_request:
+ branches: ['main']
+ schedule:
+ - cron: '36 13 * * 3'
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-latest
+ permissions:
+ actions: read
+ contents: read
+ security-events: write
+
+ strategy:
+ fail-fast: false
+ matrix:
+ language: [javascript-typescript]
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e
+ with:
+ languages: ${{ matrix.language }}
+ queries: +security-and-quality
+
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e
+ with:
+ category: '/language:${{ matrix.language }}'
diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml
new file mode 100644
index 0000000..20e282c
--- /dev/null
+++ b/.github/workflows/react-doctor.yml
@@ -0,0 +1,22 @@
+name: React Doctor
+
+on:
+ pull_request:
+ push:
+ branches: [main]
+
+permissions:
+ contents: read
+ pull-requests: write
+ issues: write
+ statuses: write
+
+jobs:
+ react-doctor:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+ - uses: millionco/react-doctor@0b4f4f4bd248a154e64eb508a48347f71154b3f3
diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml
new file mode 100644
index 0000000..18227e7
--- /dev/null
+++ b/.github/workflows/surge-preview.yml
@@ -0,0 +1,52 @@
+name: Surge Preview
+
+on:
+ pull_request:
+
+permissions:
+ contents: read
+ pull-requests: write
+ checks: write
+
+jobs:
+ preview:
+ runs-on: ubuntu-latest
+ concurrency:
+ group: surge-preview-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+ - name: Check Surge token
+ id: surge-token
+ env:
+ SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
+ run: |
+ if [ -n "$SURGE_TOKEN" ]; then
+ echo "enabled=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "enabled=false" >> "$GITHUB_OUTPUT"
+ fi
+ - name: Setup utoo
+ if: ${{ steps.surge-token.outputs.enabled == 'true' }}
+ uses: utooland/setup-utoo@v1
+
+ - name: Build preview
+ if: ${{ steps.surge-token.outputs.enabled == 'true' }}
+ run: |
+ ut install
+ npm run build
+ - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec
+ if: ${{ steps.surge-token.outputs.enabled == 'true' }}
+ env:
+ SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
+ with:
+ surge_token: ${{ env.SURGE_TOKEN }}
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ dist: .doc
+ failOnError: false
+ setCommitStatus: false
+ - name: Skip Surge preview
+ if: ${{ steps.surge-token.outputs.enabled != 'true' }}
+ run: echo "SURGE_TOKEN is not configured; skip Surge preview."
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..ac9a11d
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,16 @@
+name: ✅ test
+
+on:
+ push:
+ branches: [main]
+ pull_request:
+ branches: [main]
+
+permissions:
+ contents: read
+
+jobs:
+ test:
+ uses: react-component/rc-test/.github/workflows/test-utoo.yml@main
+ secrets:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
diff --git a/README.md b/README.md
index 5184461..de6ac56 100644
--- a/README.md
+++ b/README.md
@@ -1,68 +1,78 @@
-# @rc-component/dom-align
-
----
-
-Align source html element with target html element flexibly.
-
-[![NPM version][npm-image]][npm-url]
-[![npm download][download-image]][download-url]
-[![build status][github-actions-image]][github-actions-url]
-[![Codecov][codecov-image]][codecov-url]
-[![bundle size][bundlephobia-image]][bundlephobia-url]
-[![dumi][dumi-image]][dumi-url]
-
-[npm-image]: http://img.shields.io/npm/v/@rc-component/dom-align.svg?style=flat-square
-[npm-url]: http://npmjs.org/package/@rc-component/dom-align
-[travis-image]: https://img.shields.io/travis/react-component/dom-align/main?style=flat-square
-[travis-url]: https://travis-ci.com/react-component/dom-align
-[github-actions-image]: https://github.com/react-component/dom-align/actions/workflows/ci.yml/badge.svg
-[github-actions-url]: https://github.com/react-component/dom-align/actions/workflows/ci.yml
-[codecov-image]: https://img.shields.io/codecov/c/github/react-component/dom-align/main.svg?style=flat-square
-[codecov-url]: https://app.codecov.io/gh/react-component/dom-align
-[david-url]: https://david-dm.org/react-component/dom-align
-[david-image]: https://david-dm.org/react-component/dom-align/status.svg?style=flat-square
-[david-dev-url]: https://david-dm.org/react-component/dom-align?type=dev
-[david-dev-image]: https://david-dm.org/react-component/dom-align/dev-status.svg?style=flat-square
-[download-image]: https://img.shields.io/npm/dm/@rc-component/dom-align.svg?style=flat-square
-[download-url]: https://npmjs.org/package/@rc-component/dom-align
-[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/dom-align
-[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/dom-align
-[dumi-url]: https://github.com/umijs/dumi
-[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square
-
-## Screenshot
-
-
+
Part of the Ant Design ecosystem.
📐 DOM alignment utility for positioning one element against another.
+ + +English | 简体中文
+ +## Highlights + +| Area | Support | +| ------- | ------------------------------------------------------------------ | +| Purpose | DOM alignment utility for positioning one element against another. | +| Package | `@rc-component/dom-align` | +| Release | `@rc-component/np` / `rc-np` | ## Install -[](https://npmjs.org/package/@rc-component/dom-align) - -## Feature - -- support Edge Chrome Firefox -- support align points and offset -- support auto adjust according to visible area +```bash +npm install @rc-component/dom-align +``` ## Usage -```js +```tsx | pure import domAlign from '@rc-component/dom-align'; -// use domAlign -// sourceNode's initial style should be position:absolute;left:-9999px;top:-9999px; +domAlign(sourceNode, targetNode, { + points: ['tl', 'tr'], + offset: [10, 20], + overflow: { adjustX: true, adjustY: true }, +}); +``` + +## API + +| Option | Description | +| --- | --- | +| `points` | Source and target alignment points. | +| `offset` | Source node offset. | +| `targetOffset` | Target node offset. | +| `overflow` | Auto-adjust behavior when the source overflows viewport. | +| `useCssRight` / `useCssBottom` / `useCssTransform` | Choose CSS positioning strategy. | -const alignConfig = { - points: ['tl', 'tr'], // align top left point of sourceNode with top right point of targetNode - offset: [10, 20], // the offset sourceNode by 10px in x and 20px in y, - targetOffset: ['30%', '40%'], // the offset targetNode by 30% of targetNode width in x and 40% of targetNode height in y, - overflow: { adjustX: true, adjustY: true }, // auto adjust position when sourceNode is overflowed -}; +## Development -domAlign(sourceNode, targetNode, alignConfig); +```bash +npm install +npm start +npm test +npm run lint +npm run tsc +npm run compile ``` -## API +The dumi site runs at `http://localhost:8000`. + +## Release + +```bash +npm run prepublishOnly +``` + +The release flow is handled by `@rc-component/np` through the `rc-np` command when the package uses the shared release flow. + +## Detailed API ### void domAlign(source: HTMLElement, target: HTMLElement, alignConfig: Object):Function @@ -125,17 +135,10 @@ domAlign(sourceNode, targetNode, alignConfig); -## Development - -``` -pnpm install -pnpm start -``` - ## Example http://localhost:8000/ ## License -@rc-component/dom-align is released under the MIT license. +@rc-component/dom-align is released under the [MIT](./LICENSE.md) license. diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 0000000..c82f009 --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,77 @@ + + +English | 简体中文
+ +## 亮点 + +| 方向 | 支持 | +| ---- | ------------------------------------------------- | +| 定位 | 用于将一个 DOM 元素相对另一个元素定位的对齐工具。 | +| 包名 | `@rc-component/dom-align` | +| 发布 | `@rc-component/np` / `rc-np` | + +## 安装 + +```bash +npm install @rc-component/dom-align +``` + +## 用法 + +```tsx | pure +import domAlign from '@rc-component/dom-align'; + +domAlign(sourceNode, targetNode, { + points: ['tl', 'tr'], + offset: [10, 20], + overflow: { adjustX: true, adjustY: true }, +}); +``` + +## API + +| 名称 | 说明 | +| -------------------------------------------------- | -------------------------------- | +| `points` | 源节点和目标节点的对齐点。 | +| `offset` | 源节点偏移。 | +| `targetOffset` | 目标节点偏移。 | +| `overflow` | 源节点超出视口时的自动调整行为。 | +| `useCssRight` / `useCssBottom` / `useCssTransform` | 选择 CSS 定位策略。 | + +## 本地开发 + +```bash +npm install +npm start +npm test +npm run lint +npm run tsc +npm run compile +``` + +本地 dumi 站点默认运行在 `http://localhost:8000`. + +## 发布 + +```bash +npm run prepublishOnly +``` + +发布流程通过 `@rc-component/np` 提供的 `rc-np` 命令处理。 + +## 许可证 + +@rc-component/dom-align 基于 [MIT](./LICENSE.md) 协议发布。 diff --git a/app/body-overflow/page.tsx b/app/body-overflow/page.tsx index 9cb0471..19a95f6 100644 --- a/app/body-overflow/page.tsx +++ b/app/body-overflow/page.tsx @@ -4,11 +4,11 @@ import React, { useRef, useEffect } from 'react'; import domAlign from '../../src'; export default function Overflow() { - const source = useRef(); - const target = useRef(); - const timer = useRef