Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
novlan1 committed Jun 27, 2024
2 parents 5f47fc7 + 37325f5 commit 9ad0bd9
Show file tree
Hide file tree
Showing 103 changed files with 4,496 additions and 61 deletions.
25 changes: 21 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"copy-to-clipboard": "^3.3.3",
"lodash": "~4.17.15",
"omi": "7.6.7",
"omi-transition": "^0.1.7",
"tailwind-merge": "^2.2.1"
},
"devDependencies": {
Expand Down
26 changes: 25 additions & 1 deletion script/plugin-tdoc/md-to-wc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import esbuild from 'esbuild';
import fs from 'fs';
import matter from 'gray-matter';
import { spawn } from 'node:child_process';
import path from 'path';
// import camelCase from 'camelcase';
// import { compileUsage } from '../../src/_common/docs/compile';

Expand Down Expand Up @@ -80,6 +81,8 @@ export default async function mdToReact(options) {
const tab = signal(query.get('tab') || 'demo');
const tabRef = signal({});
const lastUpdated = tab === 'design' ? ${mdSegment.designDocLastUpdated} : ${mdSegment.lastUpdated};
effect(() => {
tabRef.value?.addEventListener?.('change', (event) => {
tab.value = event.detail;
Expand Down Expand Up @@ -108,11 +111,14 @@ export default async function mdToReact(options) {
<div style={isShow('api')} name="API">
${mdSegment.apiMd}
</div>
<div style={isShow('design')} name="DESIGN">
${mdSegment.designMd}
</div>
</>
) : <div name="DOC" className="${mdSegment.docClass}">${mdSegment.docMd}</div>
}
<div style={{ marginTop: 48 }}>
<td-doc-history time={${mdSegment.lastUpdated}} key={${mdSegment.lastUpdated}}></td-doc-history>
<td-doc-history time={lastUpdated} key={lastUpdated}></td-doc-history>
</div>
</>
)
Expand Down Expand Up @@ -152,6 +158,7 @@ async function customRender({ source, file, md }) {
apiFlag: /#+\s*API/,
docClass: '',
lastUpdated,
designDocLastUpdated: lastUpdated,
...data,
};

Expand Down Expand Up @@ -210,5 +217,22 @@ async function customRender({ source, file, md }) {
`${pageData.toc ? '[toc]\n' : ''}${content.replace(/<!--[\s\S]+?-->/g, '')}`,
).html;
}

// 设计指南内容 不展示 design Tab 则不解析
if (pageData.isComponent && pageData.tdDocTabs.some((item) => item.tab === 'design')) {
const designDocPath = path.resolve(__dirname, `../../src/_common/docs/web/design/${componentName}.md`);

if (fs.existsSync(designDocPath)) {
const designDocLastUpdated =
(await getGitTimestamp(designDocPath)) || Math.round(fs.statSync(designDocPath).mtimeMs);
mdSegment.designDocLastUpdated = designDocLastUpdated;

const designMd = fs.readFileSync(designDocPath, 'utf-8');
mdSegment.designMd = md.render.call(md, `${pageData.toc ? '[toc]\n' : ''}${designMd}`).html;
} else {
console.log(`[vite-plugin-tdoc]: 未找到 ${designDocPath} 文件`);
}
}

return mdSegment;
}
1 change: 0 additions & 1 deletion site/pages/components/appear.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class Appear extends Component {
this.classList.add(item);
this.classList.remove(item);
});
window.refreshDark();
}, 10);
}

Expand Down
50 changes: 50 additions & 0 deletions site/sidebar.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ export default [
],
tag: '',
},
{
title: '布局',
name: 'layout',
type: 'component', // 组件文档
children: [
{
title: 'Divider 分割线',
name: 'divider',
path: '/components/divider',
component: () => import('tdesign-web-components/divider/README.md'),
},
{
title: 'Space 间距',
name: 'space',
path: '/components/space',
component: () => import('tdesign-web-components/space/README.md'),
},
],
tag: '',
},
{
title: '导航',
name: 'navigation',
Expand Down Expand Up @@ -91,6 +111,12 @@ export default [
path: '/components/switch',
component: () => import('tdesign-web-components/switch/README.md'),
},
{
title: 'Textarea 文本框',
name: 'textarea',
path: '/components/textarea',
component: () => import('tdesign-web-components/textarea/README.md'),
},
],
},
{
Expand Down Expand Up @@ -122,6 +148,24 @@ export default [
path: '/components/tag',
// component: () => import('tdesign-web-components/tag/README.md'),
},
{
title: 'Image 图片',
name: 'image',
path: '/components/image',
component: () => import('tdesign-web-components/image/README.md'),
},
{
title: 'Tooltip 文字提示',
name: 'tooltip',
path: '/components/tooltip',
component: () => import('tdesign-web-components/tooltip/README.md'),
},
{
title: 'Loading 加载',
name: 'loading',
path: '/components/loading',
component: () => import('tdesign-web-components/loading/README.md'),
},
],
},
{
Expand All @@ -135,6 +179,12 @@ export default [
path: '/components/message',
// component: () => import('tdesign-web-components/message/README.md'),
},
{
title: 'Popup 弹出层',
name: 'popup',
path: '/components/popup',
component: () => import('tdesign-web-components/popup/README.md'),
},
],
},
];
146 changes: 146 additions & 0 deletions src/_util/dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import raf from 'raf';

import { AttachNode, AttachNodeReturnValue } from '../common';
import { easeInOutCubic, EasingFunction } from './easing';
// 用于判断是否可使用 dom
export const canUseDocument = !!(typeof window !== 'undefined' && window.document && window.document.createElement);

// 获取 css vars
export const getCssVarsValue = (name: string, element?: HTMLElement) => {
if (!canUseDocument) return;

const el = element || document.documentElement;
return getComputedStyle(el).getPropertyValue(name);
};

function isWindow(obj: any) {
return obj && obj === obj.window;
}

type ScrollTarget = HTMLElement | Window | Document;

export function getScroll(target: ScrollTarget, isLeft?: boolean): number {
// node环境或者target为空
if (typeof window === 'undefined' || !target) {
return 0;
}
const method = isLeft ? 'scrollLeft' : 'scrollTop';
let result = 0;
if (isWindow(target)) {
result = (target as Window)[isLeft ? 'pageXOffset' : 'pageYOffset'];
} else if (target instanceof Document) {
result = target.documentElement[method];
} else if (target) {
result = (target as HTMLElement)[method];
}
return result;
}

interface ScrollTopOptions {
container?: ScrollTarget;
duration?: number;
easing?: EasingFunction;
}

export const scrollTo = (target: number, opt: ScrollTopOptions) => {
const { container = window, duration = 450, easing = easeInOutCubic } = opt;
const scrollTop = getScroll(container);
const startTime = Date.now();
return new Promise((res) => {
const fnc = () => {
const timestamp = Date.now();
const time = timestamp - startTime;
const nextScrollTop = easing(Math.min(time, duration), scrollTop, target, duration);
if (isWindow(container)) {
(container as Window).scrollTo(window.pageXOffset, nextScrollTop);
} else if (container instanceof HTMLDocument || container.constructor.name === 'HTMLDocument') {
(container as HTMLDocument).documentElement.scrollTop = nextScrollTop;
} else {
(container as HTMLElement).scrollTop = nextScrollTop;
}
if (time < duration) {
raf(fnc);
} else {
// 由于上面步骤设置了 scrollTop, 滚动事件可能未触发完毕
// 此时应该在下一帧再执行 res
raf(res);
}
};
raf(fnc);
});
};

export function getAttach(attach: AttachNode, triggerNode?: HTMLElement): AttachNodeReturnValue {
if (!canUseDocument) return null;

let el: AttachNodeReturnValue;
if (typeof attach === 'string') {
el = document.querySelector(attach);
}
if (typeof attach === 'function') {
el = attach(triggerNode);
}
if (typeof attach === 'object') {
if ((attach as any) instanceof window.HTMLElement) {
el = attach;
}
}

// fix el in iframe
if (el && el.nodeType === 1) return el;

return document.body;
}

export const addClass = function (el: Element, cls: string) {
if (!el) return;
let curClass = el.className;
const classes = (cls || '').split(' ');

for (let i = 0, j = classes.length; i < j; i++) {
const clsName = classes[i];
if (!clsName) continue;

if (el.classList) {
el.classList.add(clsName);
} else if (!hasClass(el, clsName)) {
curClass += ` ${clsName}`;
}
}
if (!el.classList) {
// eslint-disable-next-line
el.className = curClass;
}
};

const trim = (str: string): string => (str || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');

export const removeClass = function (el: Element, cls: string) {
if (!el || !cls) return;
const classes = cls.split(' ');
let curClass = ` ${el.className} `;

for (let i = 0, j = classes.length; i < j; i++) {
const clsName = classes[i];
if (!clsName) continue;

if (el.classList) {
el.classList.remove(clsName);
} else if (hasClass(el, clsName)) {
curClass = curClass.replace(` ${clsName} `, ' ');
}
}
if (!el.classList) {
// eslint-disable-next-line
el.className = trim(curClass);
}
};

export function hasClass(el: Element, cls: string) {
if (!el || !cls) return false;
if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
if (el.classList) {
return el.classList.contains(cls);
}
return ` ${el.className} `.indexOf(` ${cls} `) > -1;
}
Loading

0 comments on commit 9ad0bd9

Please sign in to comment.