// 禁用浏览器默认交互（右键菜单、文本选择、拖拽）。

const isEditableTarget = (target: EventTarget | null) => {
  if (!(target instanceof HTMLElement)) return false;
  if (target.isContentEditable) return true;
  const tag = target.tagName.toLowerCase();
  return tag === 'input' || tag === 'textarea' || tag === 'select';
};

export const disableDefaultBehaviors = () => {
  document.addEventListener(
    'contextmenu',
    (event) => {
      event.preventDefault();
    },
    { capture: true }
  );

  document.addEventListener(
    'selectstart',
    (event) => {
      if (isEditableTarget(event.target)) return;
      event.preventDefault();
    },
    { capture: true }
  );

  document.addEventListener(
    'dragstart',
    (event) => {
      if (isEditableTarget(event.target)) return;
      event.preventDefault();
    },
    { capture: true }
  );
};
