2023-09-09 01:38:36 -04:00
|
|
|
import { Menu } from '@headlessui/react'
|
|
|
|
import { PropsWithChildren } from 'react'
|
2024-03-08 17:59:14 -05:00
|
|
|
import { faArrowUpRightFromSquare } from '@fortawesome/free-solid-svg-icons'
|
2024-04-15 12:04:17 -04:00
|
|
|
import { ActionIcon } from 'components/ActionIcon'
|
|
|
|
import styles from './KclEditorMenu.module.css'
|
2023-09-09 01:38:36 -04:00
|
|
|
import { useConvertToVariable } from 'hooks/useToolbarGuards'
|
2024-04-15 12:04:17 -04:00
|
|
|
import { editorShortcutMeta } from './KclEditorPane'
|
2023-09-14 20:07:11 -04:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
2024-03-22 16:55:30 +11:00
|
|
|
import { kclManager } from 'lib/singletons'
|
2024-07-23 10:39:35 -04:00
|
|
|
import { openExternalBrowserIfDesktop } from 'lib/openWindow'
|
2023-09-09 01:38:36 -04:00
|
|
|
|
2024-04-15 12:04:17 -04:00
|
|
|
export const KclEditorMenu = ({ children }: PropsWithChildren) => {
|
2023-09-09 01:38:36 -04:00
|
|
|
const { enable: convertToVarEnabled, handleClick: handleConvertToVarClick } =
|
|
|
|
useConvertToVariable()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
<div
|
|
|
|
className="relative"
|
|
|
|
onClick={(e) => {
|
2023-09-18 23:55:14 -04:00
|
|
|
const target = e.target as HTMLElement
|
|
|
|
if (e.eventPhase === 3 && target.closest('a') === null) {
|
2023-09-09 01:38:36 -04:00
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2024-07-17 01:17:53 -04:00
|
|
|
<Menu.Button className="!p-0 !bg-transparent hover:text-primary border-transparent dark:!border-transparent hover:!border-primary dark:hover:!border-chalkboard-70 ui-open:!border-primary dark:ui-open:!border-chalkboard-70 !outline-none">
|
2023-09-09 01:38:36 -04:00
|
|
|
<ActionIcon
|
2024-03-08 17:59:14 -05:00
|
|
|
icon="three-dots"
|
2023-12-06 14:44:13 -05:00
|
|
|
className="p-1"
|
|
|
|
size="sm"
|
2024-07-17 01:17:53 -04:00
|
|
|
bgClassName="bg-transparent dark:bg-transparent"
|
2024-04-05 00:59:02 -04:00
|
|
|
iconClassName={'!text-chalkboard-90 dark:!text-chalkboard-40'}
|
2023-09-09 01:38:36 -04:00
|
|
|
/>
|
|
|
|
</Menu.Button>
|
2024-04-05 00:59:02 -04:00
|
|
|
<Menu.Items className="absolute right-0 left-auto w-72 flex flex-col gap-1 divide-y divide-chalkboard-20 dark:divide-chalkboard-70 align-stretch px-0 py-1 bg-chalkboard-10 dark:bg-chalkboard-100 rounded-sm shadow-lg border border-solid border-chalkboard-20/50 dark:border-chalkboard-80/50">
|
2023-09-09 01:38:36 -04:00
|
|
|
<Menu.Item>
|
2023-10-11 13:36:54 +11:00
|
|
|
<button
|
|
|
|
onClick={() => kclManager.format()}
|
|
|
|
className={styles.button}
|
|
|
|
>
|
2023-09-09 01:38:36 -04:00
|
|
|
<span>Format code</span>
|
|
|
|
<small>{editorShortcutMeta.formatCode.display}</small>
|
|
|
|
</button>
|
|
|
|
</Menu.Item>
|
|
|
|
{convertToVarEnabled && (
|
|
|
|
<Menu.Item>
|
|
|
|
<button
|
2024-05-24 20:54:42 +10:00
|
|
|
onClick={() => handleConvertToVarClick()}
|
2023-09-09 01:38:36 -04:00
|
|
|
className={styles.button}
|
|
|
|
>
|
|
|
|
<span>Convert to Variable</span>
|
|
|
|
<small>{editorShortcutMeta.convertToVariable.display}</small>
|
|
|
|
</button>
|
|
|
|
</Menu.Item>
|
|
|
|
)}
|
2023-09-14 20:07:11 -04:00
|
|
|
<Menu.Item>
|
|
|
|
<a
|
|
|
|
className={styles.button}
|
2024-03-13 15:43:42 -07:00
|
|
|
href="https://zoo.dev/docs/kcl"
|
2023-09-14 20:07:11 -04:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2024-07-23 10:39:35 -04:00
|
|
|
onClick={openExternalBrowserIfDesktop()}
|
2023-09-14 20:07:11 -04:00
|
|
|
>
|
|
|
|
<span>Read the KCL docs</span>
|
|
|
|
<small>
|
2024-04-15 12:04:17 -04:00
|
|
|
zoo.dev
|
2023-09-14 20:07:11 -04:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faArrowUpRightFromSquare}
|
|
|
|
className="ml-1 align-text-top"
|
|
|
|
width={12}
|
|
|
|
/>
|
|
|
|
</small>
|
|
|
|
</a>
|
|
|
|
</Menu.Item>
|
2024-02-06 16:38:06 -07:00
|
|
|
<Menu.Item>
|
|
|
|
<a
|
|
|
|
className={styles.button}
|
2024-03-22 13:25:59 -07:00
|
|
|
href="https://zoo.dev/docs/kcl-samples"
|
2024-02-06 16:38:06 -07:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2024-07-23 10:39:35 -04:00
|
|
|
onClick={openExternalBrowserIfDesktop()}
|
2024-02-06 16:38:06 -07:00
|
|
|
>
|
|
|
|
<span>KCL samples</span>
|
|
|
|
<small>
|
2024-04-15 12:04:17 -04:00
|
|
|
zoo.dev
|
2024-02-06 16:38:06 -07:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faArrowUpRightFromSquare}
|
|
|
|
className="ml-1 align-text-top"
|
|
|
|
width={12}
|
|
|
|
/>
|
|
|
|
</small>
|
|
|
|
</a>
|
|
|
|
</Menu.Item>
|
2023-09-09 01:38:36 -04:00
|
|
|
</Menu.Items>
|
|
|
|
</div>
|
|
|
|
</Menu>
|
|
|
|
)
|
|
|
|
}
|