mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-23 21:06:22 +08:00
fix: add prefer-dom-node-append rule (#5108)
This commit is contained in:
@@ -208,6 +208,7 @@ const config = {
|
|||||||
'unicorn/no-unnecessary-await': 'error',
|
'unicorn/no-unnecessary-await': 'error',
|
||||||
'unicorn/no-useless-fallback-in-spread': 'error',
|
'unicorn/no-useless-fallback-in-spread': 'error',
|
||||||
'unicorn/prefer-dom-node-dataset': 'error',
|
'unicorn/prefer-dom-node-dataset': 'error',
|
||||||
|
'unicorn/prefer-dom-node-append': 'error',
|
||||||
'sonarjs/no-all-duplicated-branches': 'error',
|
'sonarjs/no-all-duplicated-branches': 'error',
|
||||||
'sonarjs/no-element-overwrite': 'error',
|
'sonarjs/no-element-overwrite': 'error',
|
||||||
'sonarjs/no-empty-collection': 'error',
|
'sonarjs/no-empty-collection': 'error',
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const RootBlockHub = () => {
|
|||||||
if (div.hasChildNodes()) {
|
if (div.hasChildNodes()) {
|
||||||
div.removeChild(div.firstChild as ChildNode);
|
div.removeChild(div.firstChild as ChildNode);
|
||||||
}
|
}
|
||||||
div.appendChild(blockHub);
|
div.append(blockHub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [blockHub]);
|
}, [blockHub]);
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ const BlockSuiteEditorImpl = ({
|
|||||||
if (!container) {
|
if (!container) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
container.appendChild(editor);
|
container.append(editor);
|
||||||
return () => {
|
return () => {
|
||||||
container.removeChild(editor);
|
container.removeChild(editor);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export const playCheckAnimation = async (refElement: Element) => {
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
`;
|
`;
|
||||||
refElement.appendChild(sparkingEl);
|
refElement.append(sparkingEl);
|
||||||
|
|
||||||
await sparkingEl.animate(
|
await sparkingEl.animate(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ const createToastContainer = (portal?: HTMLElement) => {
|
|||||||
data-testid="affine-toast-container"
|
data-testid="affine-toast-container"
|
||||||
></div>`;
|
></div>`;
|
||||||
const element = htmlToElement<HTMLDivElement>(template);
|
const element = htmlToElement<HTMLDivElement>(template);
|
||||||
portal.appendChild(element);
|
portal.append(element);
|
||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ const createAndShowNewToast = (
|
|||||||
const toastElement = htmlToElement<HTMLDivElement>(toastTemplate);
|
const toastElement = htmlToElement<HTMLDivElement>(toastTemplate);
|
||||||
// message is not trusted
|
// message is not trusted
|
||||||
toastElement.textContent = message;
|
toastElement.textContent = message;
|
||||||
ToastContainer.appendChild(toastElement);
|
ToastContainer.append(toastElement);
|
||||||
logger.debug(`toast with message: "${message}"`);
|
logger.debug(`toast with message: "${message}"`);
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent('affine-toast:emit', { detail: message })
|
new CustomEvent('affine-toast:emit', { detail: message })
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ export async function bootstrapPluginSystem(
|
|||||||
const style = document.createElement('style');
|
const style = document.createElement('style');
|
||||||
style.setAttribute('plugin-id', pluginName);
|
style.setAttribute('plugin-id', pluginName);
|
||||||
style.textContent = text;
|
style.textContent = text;
|
||||||
document.head.appendChild(style);
|
document.head.append(style);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ const EditorWrapper = memo(function EditorWrapper({
|
|||||||
div.setAttribute('plugin-id', id);
|
div.setAttribute('plugin-id', id);
|
||||||
const cleanup = editorItem(div, editor);
|
const cleanup = editorItem(div, editor);
|
||||||
assertExists(parent);
|
assertExists(parent);
|
||||||
document.body.appendChild(div);
|
document.body.append(div);
|
||||||
return () => {
|
return () => {
|
||||||
cleanup();
|
cleanup();
|
||||||
document.body.removeChild(div);
|
document.body.removeChild(div);
|
||||||
@@ -235,7 +235,7 @@ const PluginContentAdapter = memo<PluginContentAdapterProps>(
|
|||||||
}
|
}
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
const cleanup = windowItem(div);
|
const cleanup = windowItem(div);
|
||||||
root.appendChild(div);
|
root.append(div);
|
||||||
if (abortController.signal.aborted) {
|
if (abortController.signal.aborted) {
|
||||||
cleanup();
|
cleanup();
|
||||||
root.removeChild(div);
|
root.removeChild(div);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export const PluginHeader = () => {
|
|||||||
div.setAttribute('plugin-id', pluginName);
|
div.setAttribute('plugin-id', pluginName);
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
const cleanup = create(div);
|
const cleanup = create(div);
|
||||||
root.appendChild(div);
|
root.append(div);
|
||||||
addCleanup(pluginName, () => {
|
addCleanup(pluginName, () => {
|
||||||
pluginsRef.current = pluginsRef.current.filter(
|
pluginsRef.current = pluginsRef.current.filter(
|
||||||
name => name !== pluginName
|
name => name !== pluginName
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ const ImagePreviewModalImpl = (
|
|||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = downloadUrl;
|
a.href = downloadUrl;
|
||||||
a.download = block.id ?? 'image';
|
a.download = block.id ?? 'image';
|
||||||
document.body.appendChild(a);
|
document.body.append(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ const Outline = () => {
|
|||||||
ref={useCallback((container: HTMLDivElement | null) => {
|
ref={useCallback((container: HTMLDivElement | null) => {
|
||||||
if (container) {
|
if (container) {
|
||||||
assertExists(tocPanelRef.current);
|
assertExists(tocPanelRef.current);
|
||||||
container.appendChild(tocPanelRef.current);
|
container.append(tocPanelRef.current);
|
||||||
}
|
}
|
||||||
}, [])}
|
}, [])}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user