Skip to content

Commit

Permalink
feat(uitls): 只是自定义dsl与dom el的关联关系函数
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Aug 30, 2024
1 parent 34bc458 commit 26efbee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/design/src/Popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const popoverVisible = ref(false);
const visibleWatch = watch(
() => props.visible,
(visible) => {
console.log(visible);
if (typeof visible === 'undefined') {
nextTick(() => {
visibleWatch();
Expand Down
27 changes: 21 additions & 6 deletions packages/utils/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,26 @@ export const calcValueByFontsize = (doc: Document | undefined, value: number) =>
return value;
};

export const getIdFromEl = () => (el?: HTMLElement | SVGElement | null) => el?.dataset?.tmagicId;

export const getElById = () => (doc?: Document, id?: string | number) =>
doc?.querySelector(`[data-tmagic-id=${id}]`) as HTMLElement;
const dslDomRelateConfig = {
getIdFromEl: (el?: HTMLElement | SVGElement | null) => el?.dataset?.tmagicId,
getElById: (doc?: Document, id?: string | number) => doc?.querySelector(`[data-tmagic-id="${id}"]`) as HTMLElement,
setIdToEl: (el: HTMLElement | SVGElement, id: string | number) => {
el.dataset.tmagicId = `${id}`;
},
};

export const setIdToEl = () => (el: HTMLElement | SVGElement, id: string | number) => {
el.dataset.tmagicId = `${id}`;
export const setDslDomRelateConfig = <
K extends keyof typeof dslDomRelateConfig,
T extends (typeof dslDomRelateConfig)[K],
>(
name: K,
value: T,
) => {
dslDomRelateConfig[name] = value;
};

export const getIdFromEl = () => dslDomRelateConfig.getIdFromEl;

export const getElById = () => dslDomRelateConfig.getElById;

export const setIdToEl = () => dslDomRelateConfig.setIdToEl;

0 comments on commit 26efbee

Please sign in to comment.