{
  "version": 3,
  "sources": ["../../../../src/lib/ui/components/EmbedDialog.tsx"],
  "sourcesContent": ["import { defineMessages, track, useEditor } from '@tldraw/editor'\nimport { useRef, useState } from 'react'\nimport {\n\tTLEmbedDefinition,\n\tisCustomEmbedDefinition,\n\tisDefaultEmbedDefinitionType,\n} from '../../defaultEmbedDefinitions'\nimport { TLEmbedResult } from '../../utils/embeds/embeds'\nimport { useAssetUrls } from '../context/asset-urls'\nimport { TLUiDialogProps } from '../context/dialogs'\nimport { useGetEmbedDefinition } from '../hooks/useGetEmbedDefinition'\nimport { useGetEmbedDefinitions } from '../hooks/useGetEmbedDefinitions'\nimport { untranslated, useTranslation } from '../hooks/useTranslation/useTranslation'\nimport { TldrawUiButton } from './primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonLabel } from './primitives/Button/TldrawUiButtonLabel'\nimport {\n\tTldrawUiDialogBody,\n\tTldrawUiDialogCloseButton,\n\tTldrawUiDialogFooter,\n\tTldrawUiDialogHeader,\n\tTldrawUiDialogTitle,\n} from './primitives/TldrawUiDialog'\nimport { TldrawUiInput } from './primitives/TldrawUiInput'\n\nconst messages = defineMessages({\n\tembedDialogBack: { id: 'embed-dialog.back', defaultMessage: 'Back' },\n\tembedDialogCancel: { id: 'embed-dialog.cancel', defaultMessage: 'Cancel' },\n\tembedDialogCreate: { id: 'embed-dialog.create', defaultMessage: 'Create' },\n\tembedDialogInstruction: {\n\t\tid: 'embed-dialog.instruction',\n\t\tdefaultMessage: 'Paste in the site\u2019s URL to create the embed.',\n\t},\n\tembedDialogInvalidUrl: {\n\t\tid: 'embed-dialog.invalid-url',\n\t\tdefaultMessage: 'We could not create an embed from that URL.',\n\t},\n\tembedDialogLearnMore: { id: 'embed-dialog.learn-more', defaultMessage: 'Learn more' },\n\tembedDialogTitle: { id: 'embed-dialog.title', defaultMessage: 'Insert embed' },\n\tembedDialogUrl: { id: 'embed-dialog.url', defaultMessage: 'URL' },\n})\n\nexport const EmbedDialog = track(function EmbedDialog({ onClose }: TLUiDialogProps) {\n\tconst editor = useEditor()\n\tconst msg = useTranslation()\n\tconst assetUrls = useAssetUrls()\n\n\t// The embed definition for the user's selected embed (set by the user clicking on an embed in stage 1)\n\tconst [embedDefinition, setEmbedDefinition] = useState<null | TLEmbedDefinition>(null)\n\n\t// The URL that the user has typed into (in stage 2)\n\tconst [url, setUrl] = useState<string>('')\n\n\t// The embed info for the user's selected embed (based on the URL they've entered in stage 2)\n\tconst [embedInfoForUrl, setEmbedInfoForUrl] = useState<null | TLEmbedResult>(null)\n\n\t// Should we show the \"invalid URL\" error message?\n\tconst [showError, setShowError] = useState(false)\n\tconst rShowErrorTimeout = useRef<any>(-1)\n\n\tconst definitions = useGetEmbedDefinitions()\n\tconst getEmbedDefinition = useGetEmbedDefinition()\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiDialogHeader>\n\t\t\t\t<TldrawUiDialogTitle>\n\t\t\t\t\t{embedDefinition\n\t\t\t\t\t\t? `${msg(messages.embedDialogTitle)} \u2014 ${embedDefinition.title}`\n\t\t\t\t\t\t: msg(messages.embedDialogTitle)}\n\t\t\t\t</TldrawUiDialogTitle>\n\t\t\t\t<TldrawUiDialogCloseButton />\n\t\t\t</TldrawUiDialogHeader>\n\t\t\t{embedDefinition ? (\n\t\t\t\t<>\n\t\t\t\t\t<TldrawUiDialogBody className=\"tlui-embed-dialog__enter\">\n\t\t\t\t\t\t<TldrawUiInput\n\t\t\t\t\t\t\tclassName=\"tlui-embed-dialog__input\"\n\t\t\t\t\t\t\tlabel={messages.embedDialogUrl.id}\n\t\t\t\t\t\t\tplaceholder=\"https://example.com\"\n\t\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\t\tonValueChange={(value) => {\n\t\t\t\t\t\t\t\t// Set the url that the user has typed into the input\n\t\t\t\t\t\t\t\tsetUrl(value)\n\n\t\t\t\t\t\t\t\t// Set the embed info to either the embed info for the URL (if\n\t\t\t\t\t\t\t\t// that embed info can be found and of a type that matches the\n\t\t\t\t\t\t\t\t// user's selected definition type)\n\t\t\t\t\t\t\t\tconst embedInfo = getEmbedDefinition(value)\n\t\t\t\t\t\t\t\tsetEmbedInfoForUrl(\n\t\t\t\t\t\t\t\t\tembedInfo && embedInfo.definition.type === embedDefinition.type ? embedInfo : null\n\t\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\t\t// We want to hide the error when the user enters text,\n\t\t\t\t\t\t\t\t// and then show an error after a short delay if the user\n\t\t\t\t\t\t\t\t// has not yet entered a valid URL.\n\t\t\t\t\t\t\t\tsetShowError(false)\n\t\t\t\t\t\t\t\tclearTimeout(rShowErrorTimeout.current)\n\n\t\t\t\t\t\t\t\trShowErrorTimeout.current = editor.timers.setTimeout(\n\t\t\t\t\t\t\t\t\t() => setShowError(!embedInfo),\n\t\t\t\t\t\t\t\t\t320\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{url === '' ? (\n\t\t\t\t\t\t\t<div className=\"tlui-embed-dialog__instruction\">\n\t\t\t\t\t\t\t\t<span>{msg(messages.embedDialogInstruction)}</span>{' '}\n\t\t\t\t\t\t\t\t{embedDefinition.instructionLink && (\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t<a\n\t\t\t\t\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t\t\t\t\t\trel=\"noopener noreferrer\"\n\t\t\t\t\t\t\t\t\t\t\thref={embedDefinition.instructionLink}\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"tlui-embed-dialog__instruction__link\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{msg(messages.embedDialogLearnMore)}\n\t\t\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\t\t\t.\n\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<div className=\"tlui-embed-dialog__warning\">\n\t\t\t\t\t\t\t\t{showError ? msg(messages.embedDialogInvalidUrl) : '\\xa0'}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</TldrawUiDialogBody>\n\t\t\t\t\t<TldrawUiDialogFooter className=\"tlui-dialog__footer__actions\">\n\t\t\t\t\t\t<TldrawUiButton\n\t\t\t\t\t\t\ttype=\"normal\"\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetEmbedDefinition(null)\n\t\t\t\t\t\t\t\tsetEmbedInfoForUrl(null)\n\t\t\t\t\t\t\t\tsetUrl('')\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<TldrawUiButtonLabel>{msg(messages.embedDialogBack)}</TldrawUiButtonLabel>\n\t\t\t\t\t\t</TldrawUiButton>\n\t\t\t\t\t\t<div className=\"tlui-embed__spacer\" />\n\t\t\t\t\t\t<TldrawUiButton type=\"normal\" onClick={onClose}>\n\t\t\t\t\t\t\t<TldrawUiButtonLabel>{msg(messages.embedDialogCancel)}</TldrawUiButtonLabel>\n\t\t\t\t\t\t</TldrawUiButton>\n\t\t\t\t\t\t<TldrawUiButton\n\t\t\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\t\t\tdisabled={!embedInfoForUrl}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tif (!embedInfoForUrl) return\n\n\t\t\t\t\t\t\t\teditor.putExternalContent({\n\t\t\t\t\t\t\t\t\ttype: 'embed',\n\t\t\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t\t\tpoint: editor.getViewportPageBounds().center,\n\t\t\t\t\t\t\t\t\tembed: embedInfoForUrl.definition,\n\t\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\t\tonClose()\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<TldrawUiButtonLabel>{msg(messages.embedDialogCreate)}</TldrawUiButtonLabel>\n\t\t\t\t\t\t</TldrawUiButton>\n\t\t\t\t\t</TldrawUiDialogFooter>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t<TldrawUiDialogBody className=\"tlui-embed-dialog__list\">\n\t\t\t\t\t{definitions.map((def) => {\n\t\t\t\t\t\tconst icon = isDefaultEmbedDefinitionType(def.type)\n\t\t\t\t\t\t\t? assetUrls.embedIcons[def.type]\n\t\t\t\t\t\t\t: isCustomEmbedDefinition(def)\n\t\t\t\t\t\t\t\t? def.icon\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TldrawUiButton type=\"menu\" key={def.type} onClick={() => setEmbedDefinition(def)}>\n\t\t\t\t\t\t\t\t<TldrawUiButtonLabel>{untranslated(def.title)}</TldrawUiButtonLabel>\n\t\t\t\t\t\t\t\t{icon && (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tclassName=\"tlui-embed-dialog__item__image\"\n\t\t\t\t\t\t\t\t\t\tstyle={{ backgroundImage: `url(${icon})` }}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</TldrawUiButton>\n\t\t\t\t\t\t)\n\t\t\t\t\t})}\n\t\t\t\t</TldrawUiDialogBody>\n\t\t\t)}\n\t\t</>\n\t)\n})\n"],
  "mappings": "AAgEG,SA4CM,UA3CL,KADD;AAhEH,SAAS,gBAAgB,OAAO,iBAAiB;AACjD,SAAS,QAAQ,gBAAgB;AACjC;AAAA,EAEC;AAAA,EACA;AAAA,OACM;AAEP,SAAS,oBAAoB;AAE7B,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AACvC,SAAS,cAAc,sBAAsB;AAC7C,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,qBAAqB;AAE9B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