forked from yiminghe/dom-align
-
Notifications
You must be signed in to change notification settings - Fork 1
chore: upgrade tech stack #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2ddb69d
upgrade tech stack
yiminghe ebe607a
merge upgsteam
afc163 cae4a36
merge upgsteam
afc163 e68af2c
Merge branch 'main' into yiminghe-master
afc163 a7a23ee
merge upgsteam
afc163 06bbce0
merge upgsteam
afc163 e2fd160
merge upgsteam
afc163 d888dec
Update .github/workflows/ci.yml
afc163 92be6d5
Update .github/workflows/ci.yml
afc163 dd65666
Apply suggestions from code review
afc163 9011afe
Apply suggestions from code review
afc163 d172619
fix tsc
afc163 0bda214
fix tsc
afc163 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| 'use client'; | ||
|
|
||
| import React, { useRef, useEffect } from 'react'; | ||
| import domAlign from '../../src'; | ||
|
|
||
| export default function Overflow() { | ||
| const source = useRef(); | ||
| const target = useRef(); | ||
| const timer = useRef<any>(); | ||
| const align = () => { | ||
| const ret = domAlign(source.current, target.current, { | ||
| points: ['tl', 'bl'], | ||
| overflow: { | ||
| adjustY: 1, | ||
| adjustX: 1, | ||
| }, | ||
| }); | ||
| console.log(ret); | ||
| if (timer.current) { | ||
| clearTimeout(timer.current); | ||
| } | ||
| timer.current = setTimeout(() => { | ||
| document.body.style.overflow = 'hidden'; | ||
| }, 1000); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| if (timer.current) { | ||
| clearTimeout(timer.current); | ||
| } | ||
| document.body.style.overflow = ''; | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div style={{ height: 1000 }}> | ||
| <button ref={target} style={{ position: 'absolute', right: 0, top: 300 }}> | ||
| target | ||
| </button> | ||
|
|
||
| <div style={{ height: 100 }} /> | ||
|
|
||
| <button onClick={align}>align</button> | ||
|
|
||
| <div | ||
| ref={source} | ||
| style={{ | ||
| position: 'absolute', | ||
| width: 100, | ||
| height: 200, | ||
| border: '1px solid red', | ||
| }}> | ||
| oo | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 'use client'; | ||
|
|
||
| import React, { useRef, useEffect } from 'react'; | ||
| import domAlign from '../../src'; | ||
|
|
||
| export default function Fail() { | ||
| const source = useRef(); | ||
| const target = useRef(); | ||
|
|
||
| function align() { | ||
| const ret = domAlign(source.current, target.current, { | ||
| points: ['bl', 'bl'], | ||
| overflow: { | ||
| adjustY: 1, | ||
| }, | ||
| }); | ||
| console.log(ret); | ||
| } | ||
| return ( | ||
| <div style={{ height: 1000 }}> | ||
| <button ref={target}>target</button> | ||
|
|
||
| <div style={{ height: 100 }} /> | ||
|
|
||
| <button onClick={align}>align</button> | ||
|
|
||
| <div | ||
| ref={source} | ||
| style={{ | ||
| position: 'absolute', | ||
| width: 100, | ||
| height: 200, | ||
| border: '1px solid red', | ||
| }}> | ||
| oo | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import Link from 'next/link'; | ||
| import { useMemo } from 'react'; | ||
| import React from 'react'; | ||
| import MarkdownIt from 'markdown-it'; | ||
| import 'github-markdown-css/github-markdown-light.css'; | ||
| // @ts-ignore | ||
| import prism from 'prismjs'; | ||
| import 'prismjs/components/prism-json'; | ||
| import 'prismjs/components/prism-javascript'; | ||
| import 'prismjs/themes/prism.css'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| const readme = fs.readFileSync( | ||
| path.join(process.cwd(), './README.md'), | ||
| 'utf-8', | ||
| ); | ||
| const md = new MarkdownIt({ | ||
| html: true, | ||
| linkify: true, | ||
| typographer: true, | ||
| highlight: function (code, lang) { | ||
| if (prism.languages[lang]) { | ||
| return prism.highlight(code, prism.languages[lang], lang); | ||
| } else { | ||
| return code; | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| export default function Home() { | ||
| const content = useMemo(() => { | ||
| return md.render(readme); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div style={{ width: 1200, margin: 'auto' }}> | ||
| <h2>examples</h2> | ||
| <p> | ||
| <Link href="/simple">simple</Link> | ||
| </p> | ||
| <p> | ||
| <Link href="/body-overflow">body-overflow</Link> | ||
| </p> | ||
| <p> | ||
| <Link href="/fail">fail</Link> | ||
| </p> | ||
| <p> | ||
| <Link href="/point">point</Link> | ||
| </p> | ||
| <p> | ||
| <Link href="/shadow-dom">shadow-dom</Link> | ||
| </p> | ||
| <h2>readme</h2> | ||
| <div | ||
| className="markdown-body" | ||
| dangerouslySetInnerHTML={{ __html: content }}></div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| 'use client'; | ||
|
|
||
| import React, { useRef, useEffect } from 'react'; | ||
| import ReactDOM from 'react-dom/client'; | ||
| import domAlign from '../../src'; | ||
|
|
||
| function Test() { | ||
| const source = useRef(); | ||
| const target = useRef(); | ||
| function align() { | ||
| const ret = domAlign(source.current, target.current, { | ||
| points: ['bl', 'bl'], | ||
| overflow: { | ||
| adjustY: 1, | ||
| }, | ||
| }); | ||
| console.log(ret); | ||
| } | ||
|
|
||
| return ( | ||
| <div style={{ height: 1000 }}> | ||
| <button ref={target}>target</button> | ||
|
|
||
| <div style={{ height: 100 }} /> | ||
|
|
||
| <button onClick={align}>align</button> | ||
|
|
||
| <div | ||
| ref={source} | ||
| style={{ | ||
| position: 'absolute', | ||
| width: 100, | ||
| height: 200, | ||
| border: '1px solid red', | ||
| }}> | ||
| oo | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default function ShadowDom() { | ||
| const source = useRef<HTMLDivElement>(); | ||
|
|
||
| useEffect(() => { | ||
| const shadowRoot = source.current.attachShadow({ mode: 'open' }); | ||
| ReactDOM.createRoot(shadowRoot).render(<Test />); | ||
| }, []); | ||
|
|
||
| return <div ref={source}></div>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| 'use client'; | ||
|
|
||
| import React from 'react'; | ||
| import domAlign from '../../src'; | ||
|
|
||
| function $id(id): any { | ||
| return document.getElementById(id); | ||
| } | ||
|
|
||
| function $val(sel) { | ||
| sel = $id(sel); | ||
| return sel.value; | ||
| } | ||
|
|
||
| function align() { | ||
| domAlign($id('source'), $id('target'), { | ||
| points: [ | ||
| $val('source_align_tb') + $val('source_align_lr'), | ||
| $val('target_align_tb') + $val('target_align_lr'), | ||
| ], | ||
| offset: [$val('offset1'), $val('offset2')], | ||
| targetOffset: [$val('targetOffset1'), $val('targetOffset2')], | ||
| overflow: { | ||
| adjustX: $id('adjustX').checked, | ||
| adjustY: $id('adjustY').checked, | ||
| }, | ||
| useCssRight: $id('useCssRight').checked, | ||
| useCssBottom: $id('useCssBottom').checked, | ||
| useCssTransform: $id('useCssTransform').checked, | ||
|
|
||
| ignoreShake: $id('ignoreShake').checked, | ||
| }); | ||
| } | ||
| export default function Simple() { | ||
| return ( | ||
| <div> | ||
| <h1>dom-align</h1> | ||
|
|
||
| <div> | ||
| source: | ||
| <select id="source_align_tb"> | ||
| <option value="t">t</option> | ||
| <option value="c">c</option> | ||
| <option value="b">b</option> | ||
| </select> | ||
| <select id="source_align_lr"> | ||
| <option value="l">l</option> | ||
| <option value="c">c</option> | ||
| <option value="r">r</option> | ||
| </select> | ||
| target: | ||
| <select id="target_align_tb"> | ||
| <option value="t">t</option> | ||
| <option value="c">c</option> | ||
| <option value="b">b</option> | ||
| </select> | ||
| <select id="target_align_lr"> | ||
| <option value="l">l</option> | ||
| <option value="c">c</option> | ||
| <option value="r">r</option> | ||
| </select> | ||
| offset: [ | ||
| <input type="offset" id="offset1" defaultValue="0" size={3} /> | ||
| , | ||
| <input type="offset" id="offset2" defaultValue="0" size={3} /> | ||
| ] targetOffset: [ | ||
| <input type="offset" id="targetOffset1" defaultValue="0" size={3} /> | ||
| , | ||
| <input type="offset" id="targetOffset2" defaultValue="0" size={3} />] | ||
| overflow: | ||
| <label> | ||
| adjustX: | ||
| <input type="checkbox" id="adjustX" /> | ||
| </label> | ||
| | ||
| <label> | ||
| adjustY: | ||
| <input type="checkbox" id="adjustY" /> | ||
| </label> | ||
| | ||
| <label> | ||
| useCssBottom: | ||
| <input type="checkbox" id="useCssBottom" /> | ||
| </label> | ||
| | ||
| <label> | ||
| useCssRight: | ||
| <input type="checkbox" id="useCssRight" /> | ||
| </label> | ||
| | ||
| <label> | ||
| useCssTransform: | ||
| <input type="checkbox" id="useCssTransform" defaultChecked={false} /> | ||
| </label> | ||
| | ||
| <label> | ||
| ignoreShake: | ||
| <input type="checkbox" id="ignoreShake" /> | ||
| </label> | ||
| | ||
| <button id="align" onClick={align}> | ||
| align | ||
| </button> | ||
| <br /> | ||
| <div | ||
| style={{ | ||
| width: 400, | ||
| height: 400, | ||
| overflow: 'auto', | ||
| border: '1px solid green', | ||
| position: 'relative', | ||
| }}> | ||
| <div | ||
| style={{ | ||
| background: 'yellow', | ||
| width: 240, | ||
| height: 240, | ||
| margin: 50, | ||
| }} | ||
| id="target"> | ||
| target node | ||
| </div> | ||
| <div style={{ width: 1000, height: 1000 }} /> | ||
| <div | ||
| style={{ | ||
| background: 'red', | ||
| width: 80, | ||
| height: 80, | ||
| left: 0, | ||
| top: 0, | ||
| position: 'absolute', | ||
| transition: 'all 0.5s', | ||
| overflowY: 'auto', | ||
| }} | ||
| id="source"> | ||
| source node | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.