@medialane/ui 0.396.0 → 0.397.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/account/input-otp.d.cts +2 -2
- package/dist/components/account/input-otp.d.ts +2 -2
- package/dist/components/alert.d.cts +1 -1
- package/dist/components/alert.d.ts +1 -1
- package/dist/components/badge.d.cts +1 -1
- package/dist/components/badge.d.ts +1 -1
- package/dist/components/button.d.cts +2 -2
- package/dist/components/button.d.ts +2 -2
- package/dist/components/drop/create/asset-editor.cjs +14 -4
- package/dist/components/drop/create/asset-editor.cjs.map +1 -1
- package/dist/components/drop/create/asset-editor.js +14 -4
- package/dist/components/drop/create/asset-editor.js.map +1 -1
- package/dist/components/fast-mint/asset-form-parts.cjs +8 -43
- package/dist/components/fast-mint/asset-form-parts.cjs.map +1 -1
- package/dist/components/fast-mint/asset-form-parts.d.cts +5 -10
- package/dist/components/fast-mint/asset-form-parts.d.ts +5 -10
- package/dist/components/fast-mint/asset-form-parts.js +8 -42
- package/dist/components/fast-mint/asset-form-parts.js.map +1 -1
- package/dist/components/fast-mint/dropzone.cjs +1 -0
- package/dist/components/fast-mint/dropzone.cjs.map +1 -1
- package/dist/components/fast-mint/dropzone.js +1 -0
- package/dist/components/fast-mint/dropzone.js.map +1 -1
- package/dist/components/fast-mint/fast-mint.cjs +47 -45
- package/dist/components/fast-mint/fast-mint.cjs.map +1 -1
- package/dist/components/fast-mint/fast-mint.js +48 -46
- package/dist/components/fast-mint/fast-mint.js.map +1 -1
- package/dist/components/image-upload-field.cjs +140 -0
- package/dist/components/image-upload-field.cjs.map +1 -0
- package/dist/components/image-upload-field.d.cts +19 -0
- package/dist/components/image-upload-field.d.ts +19 -0
- package/dist/components/image-upload-field.js +106 -0
- package/dist/components/image-upload-field.js.map +1 -0
- package/dist/components/launchpad/coin-create.cjs +11 -54
- package/dist/components/launchpad/coin-create.cjs.map +1 -1
- package/dist/components/launchpad/coin-create.js +12 -55
- package/dist/components/launchpad/coin-create.js.map +1 -1
- package/dist/components/launchpad/collection-create-form.cjs +18 -76
- package/dist/components/launchpad/collection-create-form.cjs.map +1 -1
- package/dist/components/launchpad/collection-create-form.js +18 -76
- package/dist/components/launchpad/collection-create-form.js.map +1 -1
- package/dist/components/launchpad/edition-mint-fields.cjs +12 -87
- package/dist/components/launchpad/edition-mint-fields.cjs.map +1 -1
- package/dist/components/launchpad/edition-mint-fields.d.cts +4 -8
- package/dist/components/launchpad/edition-mint-fields.d.ts +4 -8
- package/dist/components/launchpad/edition-mint-fields.js +14 -79
- package/dist/components/launchpad/edition-mint-fields.js.map +1 -1
- package/dist/components/launchpad/edition-mint-schema.d.cts +6 -6
- package/dist/components/launchpad/edition-mint-schema.d.ts +6 -6
- package/dist/components/launchpad/edition-mint.cjs +21 -39
- package/dist/components/launchpad/edition-mint.cjs.map +1 -1
- package/dist/components/launchpad/edition-mint.js +21 -39
- package/dist/components/launchpad/edition-mint.js.map +1 -1
- package/dist/components/launchpad/pop-create-fields.cjs +14 -91
- package/dist/components/launchpad/pop-create-fields.cjs.map +1 -1
- package/dist/components/launchpad/pop-create-fields.d.cts +4 -8
- package/dist/components/launchpad/pop-create-fields.d.ts +4 -8
- package/dist/components/launchpad/pop-create-fields.js +14 -83
- package/dist/components/launchpad/pop-create-fields.js.map +1 -1
- package/dist/components/launchpad/pop-create.cjs +20 -32
- package/dist/components/launchpad/pop-create.cjs.map +1 -1
- package/dist/components/launchpad/pop-create.js +20 -32
- package/dist/components/launchpad/pop-create.js.map +1 -1
- package/dist/components/launchpad/remix-mint.cjs +15 -52
- package/dist/components/launchpad/remix-mint.cjs.map +1 -1
- package/dist/components/launchpad/remix-mint.js +16 -53
- package/dist/components/launchpad/remix-mint.js.map +1 -1
- package/dist/components/launchpad/single-edition-mint.cjs +11 -72
- package/dist/components/launchpad/single-edition-mint.cjs.map +1 -1
- package/dist/components/launchpad/single-edition-mint.js +12 -73
- package/dist/components/launchpad/single-edition-mint.js.map +1 -1
- package/dist/components/launchpad/tier-mint-form.cjs +14 -60
- package/dist/components/launchpad/tier-mint-form.cjs.map +1 -1
- package/dist/components/launchpad/tier-mint-form.js +15 -61
- package/dist/components/launchpad/tier-mint-form.js.map +1 -1
- package/dist/components/launchpad/tier-mint-presets.cjs +0 -4
- package/dist/components/launchpad/tier-mint-presets.cjs.map +1 -1
- package/dist/components/launchpad/tier-mint-presets.d.cts +0 -2
- package/dist/components/launchpad/tier-mint-presets.d.ts +0 -2
- package/dist/components/launchpad/tier-mint-presets.js +0 -4
- package/dist/components/launchpad/tier-mint-presets.js.map +1 -1
- package/dist/i18n/catalog/pt.cjs +3 -7
- package/dist/i18n/catalog/pt.cjs.map +1 -1
- package/dist/i18n/catalog/pt.js +3 -7
- package/dist/i18n/catalog/pt.js.map +1 -1
- package/dist/index.cjs +9 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/ipfs-upload.cjs +3 -7
- package/dist/utils/ipfs-upload.cjs.map +1 -1
- package/dist/utils/ipfs-upload.d.cts +1 -3
- package/dist/utils/ipfs-upload.d.ts +1 -3
- package/dist/utils/ipfs-upload.js +3 -7
- package/dist/utils/ipfs-upload.js.map +1 -1
- package/dist/utils/use-file-upload.cjs +105 -0
- package/dist/utils/use-file-upload.cjs.map +1 -0
- package/dist/utils/use-file-upload.d.cts +26 -0
- package/dist/utils/use-file-upload.d.ts +26 -0
- package/dist/utils/use-file-upload.js +81 -0
- package/dist/utils/use-file-upload.js.map +1 -0
- package/dist/utils/use-image-upload.cjs +56 -0
- package/dist/utils/use-image-upload.cjs.map +1 -0
- package/dist/utils/use-image-upload.d.cts +19 -0
- package/dist/utils/use-image-upload.d.ts +19 -0
- package/dist/utils/use-image-upload.js +32 -0
- package/dist/utils/use-image-upload.js.map +1 -0
- package/package.json +1 -1
- package/dist/components/fast-mint/use-ipfs-upload.cjs +0 -64
- package/dist/components/fast-mint/use-ipfs-upload.cjs.map +0 -1
- package/dist/components/fast-mint/use-ipfs-upload.d.cts +0 -9
- package/dist/components/fast-mint/use-ipfs-upload.d.ts +0 -9
- package/dist/components/fast-mint/use-ipfs-upload.js +0 -40
- package/dist/components/fast-mint/use-ipfs-upload.js.map +0 -1
- package/dist/utils/use-launchpad-image-upload.cjs +0 -103
- package/dist/utils/use-launchpad-image-upload.cjs.map +0 -1
- package/dist/utils/use-launchpad-image-upload.d.cts +0 -21
- package/dist/utils/use-launchpad-image-upload.d.ts +0 -21
- package/dist/utils/use-launchpad-image-upload.js +0 -79
- package/dist/utils/use-launchpad-image-upload.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/fast-mint/fast-mint.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { useForm } from \"react-hook-form\";\nimport { Loader2 } from \"lucide-react\";\nimport { profileHref } from \"@medialane/sdk\";\nimport { describeError } from \"../../utils/describe-error.js\";\nimport { uploadError } from \"../../utils/upload-limits.js\";\nimport { uploadFileToIpfs, type SignedUploadKind } from \"../../utils/ipfs-upload.js\";\nimport { invalidatePortfolioCache } from \"../../utils/portfolio-cache.js\";\nimport type { IPType } from \"../../data/ip.js\";\nimport { Input } from \"../input.js\";\nimport { Textarea } from \"../textarea.js\";\nimport { MedialaneCollectionCard } from \"../medialane-collection-card.js\";\nimport { Dialog, DialogContent, DialogDescription, DialogTitle } from \"../dialog.js\";\nimport type { MetadataField } from \"../ip-type-fields.js\";\nimport { Dropzone } from \"./dropzone.js\";\nimport { SuccessView } from \"./success-view.js\";\nimport { CoverUpload, FormatPicker, MediaRow } from \"./asset-form-parts.js\";\nimport { PartialCreateError, type StepInfo } from \"./create-then-add.js\";\nimport { FORMATS, getFormat, initialFormatStates } from \"./formats/registry.js\";\nimport type { FormatResult, FormatShared, MintFormat } from \"./formats/types.js\";\nimport { DEFAULT_VALUES, type FormValues } from \"./form.js\";\nimport { IP_TYPE_BY_KIND, MEDIA_ROUTE_MIME_TYPES, detectMediaKind } from \"./media-kind.js\";\nimport { isWebLink } from \"../../utils/launchpad-rules.js\";\nimport { useIpfsUpload } from \"./use-ipfs-upload.js\";\nimport { useNewCollectionDraft } from \"./use-new-collection-draft.js\";\nimport type { FastMintProps, MediaKind } from \"./types.js\";\nimport { useT } from \"../../i18n/provider.js\";\nimport { ActionButton } from \"../action-button.js\";\n\nexport function FastMint(props: FastMintProps) {\n const t = useT();\n const {\n presentation = \"inline\", open = true, onClose, mediaKindLock, onMinted,\n collections, refetchCollections,\n hasWallet, walletAddress, onRequireWallet, connectLabel, getUploadToken, getSigner,\n client,\n } = props;\n\n const [status, setStatus] = useState<\"idle\" | \"minting\" | \"success\" | \"error\">(\"idle\");\n const [errorMsg, setErrorMsg] = useState<string | null>(null);\n const [step, setStep] = useState<StepInfo | null>(null);\n\n const media = useIpfsUpload();\n const feature = useIpfsUpload();\n const [mediaFile, setMediaFile] = useState<File | null>(null);\n const [mediaKind, setMediaKind] = useState<MediaKind>(\"image\");\n const mediaInputRef = useRef<HTMLInputElement>(null);\n const featureInputRef = useRef<HTMLInputElement>(null);\n\n const [formatKey, setFormatKey] = useState<MintFormat>(\"single\");\n const [formatStates, setFormatStates] = useState(initialFormatStates);\n const [resume, setResume] = useState<{ format: MintFormat; destination: unknown } | null>(null);\n const [result, setResult] = useState<FormatResult | null>(null);\n\n const [ipType, setIpType] = useState<IPType>(\"NFT\");\n const templateFieldsRef = useRef<MetadataField[]>([]);\n\n const form = useForm<FormValues>({ defaultValues: DEFAULT_VALUES });\n const name = form.watch(\"name\");\n const description = form.watch(\"description\");\n const draft = useNewCollectionDraft(name, description);\n\n useEffect(() => {\n if (walletAddress && !form.getValues(\"external_url\")) {\n form.setValue(\"external_url\", `https://medialane.io/account/${walletAddress}`);\n }\n }, [walletAddress, form]);\n\n const format = getFormat(formatKey);\n const formatState = formatStates[formatKey];\n const updateFormat = (patch: object) =>\n setFormatStates((states) => ({ ...states, [formatKey]: { ...(states[formatKey] as object), ...patch } }));\n\n const uploadFile = async (file: File, kind: SignedUploadKind) => {\n const token = await getUploadToken();\n if (!token) throw new Error(\"Sign in first\");\n return (await uploadFileToIpfs(client.api, file, kind)).uri;\n };\n\n const handleMediaSelect = async (file: File) => {\n const kind = detectMediaKind(file.type);\n if (!kind) {\n setErrorMsg(\"Use a supported media file.\");\n return;\n }\n if (mediaKindLock && kind !== mediaKindLock) {\n setErrorMsg(`Please upload a${mediaKindLock === \"image\" ? \"n\" : \"\"} ${mediaKindLock}.`);\n return;\n }\n const route = MEDIA_ROUTE_MIME_TYPES.has(file.type) ? \"media\" : \"document\";\n const fileError = uploadError(file, route);\n if (fileError) {\n setErrorMsg(fileError);\n return;\n }\n setMediaFile(file);\n setMediaKind(kind);\n setIpType(IP_TYPE_BY_KIND[kind]);\n await media.start(file, (f) => uploadFile(f, route), setErrorMsg);\n };\n\n const clearMedia = () => {\n setMediaFile(null);\n media.clear();\n if (mediaInputRef.current) mediaInputRef.current.value = \"\";\n };\n\n const image = mediaKind === \"image\" ? media.uri : feature.uri;\n const previewImage = mediaKind === \"image\" ? media.preview : feature.preview;\n\n const shared: FormatShared | null = media.uri && image && mediaFile\n ? {\n form, draft, collections,\n walletAddress: walletAddress ?? \"\",\n mediaKind, mediaUri: media.uri, mediaName: mediaFile.name, image, previewImage,\n ipType, onIpTypeChange: setIpType, templateFieldsRef,\n uploadDocument: (file) => uploadFile(file, \"document\"),\n }\n : null;\n\n const ready = !!shared && !media.uploading && !feature.uploading && name.trim().length > 0 && format.isReady(shared, formatState);\n\n const onSubmit = async () => {\n if (!hasWallet) { onRequireWallet(); return; }\n if (!shared || !walletAddress) return;\n const link = form.getValues(\"external_url\");\n if (!isWebLink(link)) {\n setErrorMsg(\"External link must start with http:// or https://\");\n setStatus(\"error\");\n return;\n }\n\n setStatus(\"minting\");\n setErrorMsg(null);\n setStep(null);\n\n try {\n const outcome = await format.submit(shared, formatState, {\n client,\n signer: await getSigner(),\n getUploadToken,\n resume: resume?.format === formatKey ? resume.destination : null,\n onStep: setStep,\n });\n setResult(outcome);\n setResume(null);\n setStatus(\"success\");\n invalidatePortfolioCache(walletAddress);\n if (outcome.asset) onMinted?.(outcome.asset);\n void refetchCollections().catch(() => {});\n } catch (err) {\n if (err instanceof PartialCreateError) {\n setResume({ format: formatKey, destination: err.destination });\n setErrorMsg(`${err.message} ${describeError(err.reason).message} Press the button again to finish.`);\n } else {\n setErrorMsg(describeError(err).message);\n }\n setStatus(\"error\");\n }\n };\n\n const resetAll = () => {\n setStatus(\"idle\");\n setErrorMsg(null);\n setStep(null);\n setResult(null);\n setResume(null);\n form.reset();\n clearMedia();\n feature.clear();\n setFormatStates(initialFormatStates());\n draft.reset();\n templateFieldsRef.current = [];\n };\n\n const busy = status === \"minting\";\n\n const wrap = (node: React.ReactNode) => {\n if (presentation !== \"dialog\") return node;\n return (\n <Dialog open={open} onOpenChange={(next) => { if (!next) onClose?.(); }}>\n <DialogContent className=\"gap-0 p-6 sm:max-w-2xl sm:p-8\">\n <DialogTitle className=\"sr-only\">{t(\"Create\")}</DialogTitle>\n <DialogDescription className=\"sr-only\">{t(\"Publish media as an asset.\")}</DialogDescription>\n {node}\n </DialogContent>\n </Dialog>\n );\n };\n\n if (status === \"success\" && result) {\n return wrap(\n <SuccessView presentation={presentation} previewImage={previewImage} result={result} onPublishAnother={resetAll} />\n );\n }\n\n if (!mediaFile) {\n return wrap(\n <Dropzone\n mediaKindLock={mediaKindLock}\n presentation={presentation}\n hasWallet={hasWallet}\n onRequireWallet={onRequireWallet}\n connectLabel={connectLabel}\n onFileSelected={handleMediaSelect}\n />\n );\n }\n\n const submitBlocked = !ready || busy || !hasWallet;\n const buttonLabel = busy\n ? `${step?.label ?? \"Working\"}…${step && step.total > 1 ? ` (${step.index} of ${step.total})` : \"\"}`\n : t(format.submitLabel(formatState));\n\n return wrap(\n <section className=\"space-y-6\">\n <MediaRow\n file={mediaFile}\n kind={mediaKind}\n preview={media.preview}\n uri={media.uri}\n uploading={media.uploading}\n ipType={ipType}\n inputRef={mediaInputRef}\n onSelect={handleMediaSelect}\n />\n\n {media.uri && (\n <div className=\"grid grid-cols-1 lg:grid-cols-[1fr_320px] gap-8 items-start\">\n <div className=\"space-y-5\">\n <FormatPicker formats={FORMATS} value={formatKey} onChange={setFormatKey} />\n\n <div className=\"space-y-2\">\n <label className=\"text-sm font-medium\">{t(\"Title *\")}</label>\n <Input\n value={name}\n onChange={(e) => form.setValue(\"name\", e.target.value)}\n placeholder={t(\"My Creative Work\")}\n />\n </div>\n\n <div className=\"space-y-2\">\n <label className=\"text-sm font-medium\">{t(\"Description\")}</label>\n <Textarea\n value={description}\n onChange={(e) => form.setValue(\"description\", e.target.value)}\n placeholder={t(\"The story behind the work…\")}\n rows={3}\n />\n </div>\n\n <div className=\"space-y-2\">\n <label className=\"text-sm font-medium\">{t(\"External link\")} <span className=\"text-muted-foreground font-normal\">{t(\"(optional)\")}</span></label>\n <Input\n value={form.watch(\"external_url\")}\n onChange={(e) => form.setValue(\"external_url\", e.target.value)}\n placeholder={t(\"https://yourwebsite.com\")}\n />\n </div>\n\n {mediaKind !== \"image\" && (\n <CoverUpload\n preview={feature.preview}\n uploading={feature.uploading}\n inputRef={featureInputRef}\n onSelect={(file) => void feature.start(file, (f) => uploadFile(f, \"image\"), setErrorMsg)}\n />\n )}\n\n {shared && <format.Fields shared={shared} state={formatState} update={updateFormat} />}\n\n {status === \"error\" && errorMsg && <p className=\"text-xs text-destructive\">{errorMsg}</p>}\n\n <ActionButton solid big type=\"button\" disabled={submitBlocked} onClick={() => void onSubmit()} className=\"w-full\">\n {busy && <Loader2 className=\"h-4 w-4 animate-spin\" />}\n {buttonLabel}\n </ActionButton>\n <p className=\"text-xs text-center text-muted-foreground\">\n {t(\"Zero platform fees to mint.\")}\n </p>\n </div>\n\n <div className=\"order-first lg:order-last lg:sticky lg:top-20 max-w-[260px] mx-auto w-full lg:max-w-none lg:mx-0\">\n <MedialaneCollectionCard\n image={previewImage}\n name={name}\n collection={shared ? format.previewLabel(shared, formatState) : undefined}\n creator={walletAddress ? `${walletAddress.slice(0, 6)}…${walletAddress.slice(-4)}` : undefined}\n creatorHref={walletAddress ? profileHref({ address: walletAddress }) : undefined}\n />\n </div>\n </div>\n )}\n </section>\n );\n}\n"],"mappings":";AAuLQ,SACE,KADF;AArLR,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,wBAA+C;AACxD,SAAS,gCAAgC;AAEzC,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,QAAQ,eAAe,mBAAmB,mBAAmB;AAEtE,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,aAAa,cAAc,gBAAgB;AACpD,SAAS,0BAAyC;AAClD,SAAS,SAAS,WAAW,2BAA2B;AAExD,SAAS,sBAAuC;AAChD,SAAS,iBAAiB,wBAAwB,uBAAuB;AACzE,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,SAAS,YAAY;AACrB,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAAsB;AAC7C,QAAM,IAAI,KAAK;AACf,QAAM;AAAA,IACJ,eAAe;AAAA,IAAU,OAAO;AAAA,IAAM;AAAA,IAAS;AAAA,IAAe;AAAA,IAC9D;AAAA,IAAa;AAAA,IACb;AAAA,IAAW;AAAA,IAAe;AAAA,IAAiB;AAAA,IAAc;AAAA,IAAgB;AAAA,IACzE;AAAA,EACF,IAAI;AAEJ,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAmD,MAAM;AACrF,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AAC5D,QAAM,CAAC,MAAM,OAAO,IAAI,SAA0B,IAAI;AAEtD,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WAAW,WAAW,YAAY,oBAAC,OAAE,WAAU,4BAA4B,oBAAS;AAAA,UAErF,qBAAC,gBAAa,OAAK,MAAC,KAAG,MAAC,MAAK,UAAS,UAAU,eAAe,SAAS,MAAM,KAAK,SAAS,GAAG,WAAU,UACtG;AAAA,oBAAQ,oBAAC,WAAQ,WAAU,wBAAuB;AAAA,YAClD;AAAA,aACH;AAAA,UACA,oBAAC,OAAE,WAAU,6CACV,YAAE,6BAA6B,GAClC;AAAA,WACF;AAAA,QAEA,oBAAC,SAAI,WAAU,oGACb;AAAA,UAAC;AAAA;AAAA,YACC,OAAO;AAAA,YACP;AAAA,YACA,YAAY,SAAS,OAAO,aAAa,QAAQ,WAAW,IAAI;AAAA,YAChE,SAAS,gBAAgB,GAAG,cAAc,MAAM,GAAG,CAAC,CAAC,SAAI,cAAc,MAAM,EAAE,CAAC,KAAK;AAAA,YACrF,aAAa,gBAAgB,YAAY,EAAE,SAAS,cAAc,CAAC,IAAI;AAAA;AAAA,QACzE,GACF;AAAA,SACF;AAAA,OAEJ;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/fast-mint/fast-mint.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { useForm } from \"react-hook-form\";\nimport { Loader2 } from \"lucide-react\";\nimport { profileHref } from \"@medialane/sdk\";\nimport { describeError } from \"../../utils/describe-error.js\";\nimport { uploadError } from \"../../utils/upload-limits.js\";\nimport { uploadFileToIpfs, type SignedUploadKind } from \"../../utils/ipfs-upload.js\";\nimport { invalidatePortfolioCache } from \"../../utils/portfolio-cache.js\";\nimport type { IPType } from \"../../data/ip.js\";\nimport { Input } from \"../input.js\";\nimport { Textarea } from \"../textarea.js\";\nimport { MedialaneCollectionCard } from \"../medialane-collection-card.js\";\nimport { Dialog, DialogContent, DialogDescription, DialogTitle } from \"../dialog.js\";\nimport type { MetadataField } from \"../ip-type-fields.js\";\nimport { Dropzone } from \"./dropzone.js\";\nimport { SuccessView } from \"./success-view.js\";\nimport { FormatPicker, MediaRow } from \"./asset-form-parts.js\";\nimport { PartialCreateError, type StepInfo } from \"./create-then-add.js\";\nimport { FORMATS, getFormat, initialFormatStates } from \"./formats/registry.js\";\nimport type { FormatResult, FormatShared, MintFormat } from \"./formats/types.js\";\nimport { DEFAULT_VALUES, type FormValues } from \"./form.js\";\nimport { IP_TYPE_BY_KIND, MEDIA_ROUTE_MIME_TYPES, detectMediaKind } from \"./media-kind.js\";\nimport { isWebLink } from \"../../utils/launchpad-rules.js\";\nimport { useFileUpload } from \"../../utils/use-file-upload.js\";\nimport { ImageUploadField } from \"../image-upload-field.js\";\nimport { useNewCollectionDraft } from \"./use-new-collection-draft.js\";\nimport type { FastMintProps, MediaKind } from \"./types.js\";\nimport { useT } from \"../../i18n/provider.js\";\nimport { msg } from \"../../i18n/translate.js\";\nimport { ActionButton } from \"../action-button.js\";\n\nexport function FastMint(props: FastMintProps) {\n const t = useT();\n const {\n presentation = \"inline\", open = true, onClose, mediaKindLock, onMinted,\n collections, refetchCollections,\n hasWallet, walletAddress, onRequireWallet, connectLabel, getUploadToken, getSigner,\n client,\n } = props;\n\n const [status, setStatus] = useState<\"idle\" | \"minting\" | \"success\" | \"error\">(\"idle\");\n const [errorMsg, setErrorMsg] = useState<string | null>(null);\n const [step, setStep] = useState<StepInfo | null>(null);\n\n const [mediaKind, setMediaKind] = useState<MediaKind>(\"image\");\n\n const [formatKey, setFormatKey] = useState<MintFormat>(\"single\");\n const [formatStates, setFormatStates] = useState(initialFormatStates);\n const [resume, setResume] = useState<{ format: MintFormat; destination: unknown } | null>(null);\n const [result, setResult] = useState<FormatResult | null>(null);\n\n const [ipType, setIpType] = useState<IPType>(\"NFT\");\n const templateFieldsRef = useRef<MetadataField[]>([]);\n\n const form = useForm<FormValues>({ defaultValues: DEFAULT_VALUES });\n const name = form.watch(\"name\");\n const description = form.watch(\"description\");\n const draft = useNewCollectionDraft(name, description);\n\n useEffect(() => {\n if (walletAddress && !form.getValues(\"external_url\")) {\n form.setValue(\"external_url\", `https://medialane.io/account/${walletAddress}`);\n }\n }, [walletAddress, form]);\n\n const format = getFormat(formatKey);\n const formatState = formatStates[formatKey];\n const updateFormat = (patch: object) =>\n setFormatStates((states) => ({ ...states, [formatKey]: { ...(states[formatKey] as object), ...patch } }));\n\n const uploadFile = async (file: File, kind: SignedUploadKind) => {\n const token = await getUploadToken();\n if (!token) throw new Error(\"Sign in first\");\n return (await uploadFileToIpfs(client.api, file, kind)).uri;\n };\n\n const routeFor = (file: File) => (MEDIA_ROUTE_MIME_TYPES.has(file.type) ? \"media\" : \"document\");\n\n const mediaProblem = (file: File) => {\n const kind = detectMediaKind(file.type);\n if (!kind) return msg(\"Use a supported media file.\");\n if (mediaKindLock && kind !== mediaKindLock) {\n return mediaKindLock === \"image\" ? msg(\"Please upload an image.\") : `Please upload a ${mediaKindLock}.`;\n }\n return uploadError(file, routeFor(file));\n };\n\n const media = useFileUpload({\n validate: mediaProblem,\n upload: (file) => uploadFile(file, routeFor(file)),\n failureMessage: msg(\"Upload failed\"),\n });\n const feature = useFileUpload({\n validate: (file) => uploadError(file, \"image\"),\n upload: (file) => uploadFile(file, \"image\"),\n failureMessage: msg(\"Upload failed\"),\n });\n const mediaFile = media.status !== \"failed\" || media.canRetry ? media.file : null;\n\n const handleMediaSelect = (file: File) => {\n const kind = detectMediaKind(file.type);\n if (kind && !mediaProblem(file)) {\n setMediaKind(kind);\n setIpType(IP_TYPE_BY_KIND[kind]);\n }\n void media.select(file);\n };\n\n const image = mediaKind === \"image\" ? media.uri : feature.uri;\n const previewImage = mediaKind === \"image\" ? media.preview : feature.preview;\n\n const shared: FormatShared | null = media.uri && image && mediaFile\n ? {\n form, draft, collections,\n walletAddress: walletAddress ?? \"\",\n mediaKind, mediaUri: media.uri, mediaName: mediaFile.name, image, previewImage,\n ipType, onIpTypeChange: setIpType, templateFieldsRef,\n uploadDocument: (file) => uploadFile(file, \"document\"),\n }\n : null;\n\n const ready = !!shared && !media.uploading && !feature.uploading && name.trim().length > 0 && format.isReady(shared, formatState);\n\n const onSubmit = async () => {\n if (!hasWallet) { onRequireWallet(); return; }\n if (!shared || !walletAddress) return;\n const link = form.getValues(\"external_url\");\n if (!isWebLink(link)) {\n setErrorMsg(\"External link must start with http:// or https://\");\n setStatus(\"error\");\n return;\n }\n\n setStatus(\"minting\");\n setErrorMsg(null);\n setStep(null);\n\n try {\n const outcome = await format.submit(shared, formatState, {\n client,\n signer: await getSigner(),\n getUploadToken,\n resume: resume?.format === formatKey ? resume.destination : null,\n onStep: setStep,\n });\n setResult(outcome);\n setResume(null);\n setStatus(\"success\");\n invalidatePortfolioCache(walletAddress);\n if (outcome.asset) onMinted?.(outcome.asset);\n void refetchCollections().catch(() => {});\n } catch (err) {\n if (err instanceof PartialCreateError) {\n setResume({ format: formatKey, destination: err.destination });\n setErrorMsg(`${err.message} ${describeError(err.reason).message} Press the button again to finish.`);\n } else {\n setErrorMsg(describeError(err).message);\n }\n setStatus(\"error\");\n }\n };\n\n const resetAll = () => {\n setStatus(\"idle\");\n setErrorMsg(null);\n setStep(null);\n setResult(null);\n setResume(null);\n form.reset();\n media.clear();\n feature.clear();\n setFormatStates(initialFormatStates());\n draft.reset();\n templateFieldsRef.current = [];\n };\n\n const busy = status === \"minting\";\n\n const wrap = (node: React.ReactNode) => {\n if (presentation !== \"dialog\") return node;\n return (\n <Dialog open={open} onOpenChange={(next) => { if (!next) onClose?.(); }}>\n <DialogContent className=\"gap-0 p-6 sm:max-w-2xl sm:p-8\">\n <DialogTitle className=\"sr-only\">{t(\"Create\")}</DialogTitle>\n <DialogDescription className=\"sr-only\">{t(\"Publish media as an asset.\")}</DialogDescription>\n {node}\n </DialogContent>\n </Dialog>\n );\n };\n\n if (status === \"success\" && result) {\n return wrap(\n <SuccessView presentation={presentation} previewImage={previewImage} result={result} onPublishAnother={resetAll} />\n );\n }\n\n if (!mediaFile) {\n return wrap(\n <div className=\"space-y-3\">\n <Dropzone\n mediaKindLock={mediaKindLock}\n presentation={presentation}\n hasWallet={hasWallet}\n onRequireWallet={onRequireWallet}\n connectLabel={connectLabel}\n onFileSelected={handleMediaSelect}\n />\n {media.error && <p role=\"alert\" className=\"text-center text-sm text-destructive\">{media.error}</p>}\n </div>\n );\n }\n\n const submitBlocked = !ready || busy || !hasWallet;\n const buttonLabel = busy\n ? `${step?.label ?? \"Working\"}…${step && step.total > 1 ? ` (${step.index} of ${step.total})` : \"\"}`\n : t(format.submitLabel(formatState));\n\n return wrap(\n <section className=\"space-y-6\">\n <MediaRow\n file={mediaFile}\n kind={mediaKind}\n preview={media.preview}\n uri={media.uri}\n uploading={media.uploading}\n ipType={ipType}\n error={media.error}\n onRetry={() => void media.retry()}\n onSelect={handleMediaSelect}\n />\n\n {media.uri && (\n <div className=\"grid grid-cols-1 lg:grid-cols-[1fr_320px] gap-8 items-start\">\n <div className=\"space-y-5\">\n <FormatPicker formats={FORMATS} value={formatKey} onChange={setFormatKey} />\n\n <div className=\"space-y-2\">\n <label className=\"text-sm font-medium\">{t(\"Title *\")}</label>\n <Input\n value={name}\n onChange={(e) => form.setValue(\"name\", e.target.value)}\n placeholder={t(\"My Creative Work\")}\n />\n </div>\n\n <div className=\"space-y-2\">\n <label className=\"text-sm font-medium\">{t(\"Description\")}</label>\n <Textarea\n value={description}\n onChange={(e) => form.setValue(\"description\", e.target.value)}\n placeholder={t(\"The story behind the work…\")}\n rows={3}\n />\n </div>\n\n <div className=\"space-y-2\">\n <label className=\"text-sm font-medium\">{t(\"External link\")} <span className=\"text-muted-foreground font-normal\">{t(\"(optional)\")}</span></label>\n <Input\n value={form.watch(\"external_url\")}\n onChange={(e) => form.setValue(\"external_url\", e.target.value)}\n placeholder={t(\"https://yourwebsite.com\")}\n />\n </div>\n\n {mediaKind !== \"image\" && (\n <ImageUploadField\n upload={feature}\n label={t(\"Upload a cover image for your asset *\")}\n hint={t(\"Cover art for previews.\")}\n />\n )}\n\n {shared && <format.Fields shared={shared} state={formatState} update={updateFormat} />}\n\n {status === \"error\" && errorMsg && <p className=\"text-xs text-destructive\">{errorMsg}</p>}\n\n <ActionButton solid big type=\"button\" disabled={submitBlocked} onClick={() => void onSubmit()} className=\"w-full\">\n {busy && <Loader2 className=\"h-4 w-4 animate-spin\" />}\n {buttonLabel}\n </ActionButton>\n <p className=\"text-xs text-center text-muted-foreground\">\n {t(\"Zero platform fees to mint.\")}\n </p>\n </div>\n\n <div className=\"order-first lg:order-last lg:sticky lg:top-20 max-w-[260px] mx-auto w-full lg:max-w-none lg:mx-0\">\n <MedialaneCollectionCard\n image={previewImage}\n name={name}\n collection={shared ? format.previewLabel(shared, formatState) : undefined}\n creator={walletAddress ? `${walletAddress.slice(0, 6)}…${walletAddress.slice(-4)}` : undefined}\n creatorHref={walletAddress ? profileHref({ address: walletAddress }) : undefined}\n />\n </div>\n </div>\n )}\n </section>\n );\n}\n"],"mappings":";AAwLQ,SACE,KADF;AAtLR,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,wBAA+C;AACxD,SAAS,gCAAgC;AAEzC,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,QAAQ,eAAe,mBAAmB,mBAAmB;AAEtE,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,cAAc,gBAAgB;AACvC,SAAS,0BAAyC;AAClD,SAAS,SAAS,WAAW,2BAA2B;AAExD,SAAS,sBAAuC;AAChD,SAAS,iBAAiB,wBAAwB,uBAAuB;AACzE,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AAEtC,SAAS,YAAY;AACrB,SAAS,WAAW;AACpB,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAAsB;AAC7C,QAAM,IAAI,KA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AAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var image_upload_field_exports = {};
|
|
31
|
+
__export(image_upload_field_exports, {
|
|
32
|
+
ImageUploadField: () => ImageUploadField
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(image_upload_field_exports);
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_lucide_react = require("lucide-react");
|
|
38
|
+
var import_image = __toESM(require("./image.js"), 1);
|
|
39
|
+
var import_button = require("./button.js");
|
|
40
|
+
var import_upload_limits = require("../utils/upload-limits.js");
|
|
41
|
+
var import_cn = require("../utils/cn.js");
|
|
42
|
+
var import_provider = require("../i18n/provider.js");
|
|
43
|
+
function ImageUploadField({ upload, label, ariaLabel, alt = "", required, optional, hint, buttonLabel, round, currentImage }) {
|
|
44
|
+
const t = (0, import_provider.useT)();
|
|
45
|
+
const inputRef = (0, import_react.useRef)(null);
|
|
46
|
+
const { status, error, uploading } = upload;
|
|
47
|
+
const failed = status === "failed" || !!error;
|
|
48
|
+
const shown = upload.file ? upload.preview : currentImage;
|
|
49
|
+
const hasImage = !!upload.file || !!currentImage;
|
|
50
|
+
const name = typeof label === "string" ? label : ariaLabel ?? t("Upload image");
|
|
51
|
+
const open = () => inputRef.current?.click();
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
53
|
+
"div",
|
|
54
|
+
{
|
|
55
|
+
ref: upload.fieldRef,
|
|
56
|
+
role: "group",
|
|
57
|
+
"aria-label": name,
|
|
58
|
+
tabIndex: -1,
|
|
59
|
+
"data-status": status,
|
|
60
|
+
className: "space-y-2 outline-none",
|
|
61
|
+
children: [
|
|
62
|
+
label ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "text-sm font-medium", children: [
|
|
63
|
+
label,
|
|
64
|
+
required ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-destructive", children: " *" }) : null,
|
|
65
|
+
optional ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "text-muted-foreground font-normal", children: [
|
|
66
|
+
" ",
|
|
67
|
+
t("(optional)")
|
|
68
|
+
] }) : null
|
|
69
|
+
] }) : null,
|
|
70
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-4", children: [
|
|
71
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
72
|
+
"button",
|
|
73
|
+
{
|
|
74
|
+
type: "button",
|
|
75
|
+
onClick: open,
|
|
76
|
+
disabled: uploading,
|
|
77
|
+
"aria-label": name,
|
|
78
|
+
className: (0, import_cn.cn)(
|
|
79
|
+
"relative flex h-24 w-24 shrink-0 items-center justify-center overflow-hidden border-2 border-dashed bg-muted transition-colors",
|
|
80
|
+
round ? "rounded-full" : "rounded-2xl",
|
|
81
|
+
failed ? "border-destructive" : "border-border hover:border-primary/50"
|
|
82
|
+
),
|
|
83
|
+
children: [
|
|
84
|
+
shown ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.default, { src: shown, alt, fill: true, unoptimized: true, className: (0, import_cn.cn)("object-cover", failed && "opacity-30") }) : failed ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ImagePlus, { className: "h-6 w-6 text-muted-foreground" }),
|
|
85
|
+
uploading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "absolute inset-0 flex items-center justify-center bg-background/70", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Loader2, { className: "h-4 w-4 animate-spin" }) }) : null,
|
|
86
|
+
failed ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.AlertCircle, { className: "relative h-7 w-7 text-destructive" }) : null
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
),
|
|
90
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "min-w-0 space-y-1.5", children: [
|
|
91
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
92
|
+
"input",
|
|
93
|
+
{
|
|
94
|
+
ref: inputRef,
|
|
95
|
+
type: "file",
|
|
96
|
+
accept: (0, import_upload_limits.acceptFor)("image"),
|
|
97
|
+
className: "hidden",
|
|
98
|
+
onChange: (event) => {
|
|
99
|
+
const file = event.target.files?.[0];
|
|
100
|
+
event.target.value = "";
|
|
101
|
+
if (file) void upload.select(file);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
106
|
+
upload.canRetry ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_button.Button, { type: "button", size: "sm", onClick: () => void upload.retry(), children: [
|
|
107
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.RotateCw, { className: "mr-1.5 h-3.5 w-3.5" }),
|
|
108
|
+
t("Retry")
|
|
109
|
+
] }) : null,
|
|
110
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { type: "button", variant: "soft", size: "sm", disabled: uploading, onClick: open, children: uploading ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
111
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Loader2, { className: "mr-1.5 h-3.5 w-3.5 animate-spin" }),
|
|
112
|
+
t("Uploading\u2026")
|
|
113
|
+
] }) : hasImage ? t("Change") : buttonLabel ?? t("Upload image") })
|
|
114
|
+
] }),
|
|
115
|
+
hasImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
116
|
+
"button",
|
|
117
|
+
{
|
|
118
|
+
type: "button",
|
|
119
|
+
onClick: upload.clear,
|
|
120
|
+
className: "flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-destructive",
|
|
121
|
+
children: [
|
|
122
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.X, { className: "h-3 w-3" }),
|
|
123
|
+
" ",
|
|
124
|
+
t("Remove")
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
) : null,
|
|
128
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", className: "text-sm text-destructive", children: error }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-xs text-muted-foreground", children: status === "uploaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-primary", children: t("\u2713 Uploaded") }) : t("Image files") }),
|
|
129
|
+
hint ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-xs text-muted-foreground", children: hint }) : null
|
|
130
|
+
] })
|
|
131
|
+
] })
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
+
0 && (module.exports = {
|
|
138
|
+
ImageUploadField
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=image-upload-field.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/image-upload-field.tsx"],"sourcesContent":["\"use client\";\n\nimport { useRef, type ReactNode } from \"react\";\nimport { AlertCircle, ImagePlus, Loader2, RotateCw, X } from \"lucide-react\";\nimport Image from \"./image.js\";\nimport { Button } from \"./button.js\";\nimport { acceptFor } from \"../utils/upload-limits.js\";\nimport { cn } from \"../utils/cn.js\";\nimport type { FileUpload } from \"../utils/use-file-upload.js\";\nimport { useT } from \"../i18n/provider.js\";\n\nexport interface ImageUploadFieldProps {\n upload: FileUpload;\n label?: ReactNode;\n ariaLabel?: string;\n alt?: string;\n required?: boolean;\n optional?: boolean;\n hint?: ReactNode;\n buttonLabel?: string;\n round?: boolean;\n currentImage?: string | null;\n}\n\nexport function ImageUploadField({ upload, label, ariaLabel, alt = \"\", required, optional, hint, buttonLabel, round, currentImage }: ImageUploadFieldProps) {\n const t = useT();\n const inputRef = useRef<HTMLInputElement>(null);\n const { status, error, uploading } = upload;\n const failed = status === \"failed\" || !!error;\n const shown = upload.file ? upload.preview : currentImage;\n const hasImage = !!upload.file || !!currentImage;\n const name = typeof label === \"string\" ? label : ariaLabel ?? t(\"Upload image\");\n const open = () => inputRef.current?.click();\n\n return (\n <div\n ref={upload.fieldRef}\n role=\"group\"\n aria-label={name}\n tabIndex={-1}\n data-status={status}\n className=\"space-y-2 outline-none\"\n >\n {label ? (\n <p className=\"text-sm font-medium\">\n {label}\n {required ? <span className=\"text-destructive\"> *</span> : null}\n {optional ? <span className=\"text-muted-foreground font-normal\"> {t(\"(optional)\")}</span> : null}\n </p>\n ) : null}\n\n <div className=\"flex items-center gap-4\">\n <button\n type=\"button\"\n onClick={open}\n disabled={uploading}\n aria-label={name}\n className={cn(\n \"relative flex h-24 w-24 shrink-0 items-center justify-center overflow-hidden border-2 border-dashed bg-muted transition-colors\",\n round ? \"rounded-full\" : \"rounded-2xl\",\n failed ? \"border-destructive\" : \"border-border hover:border-primary/50\",\n )}\n >\n {shown ? (\n <Image src={shown} alt={alt} fill unoptimized className={cn(\"object-cover\", failed && \"opacity-30\")} />\n ) : failed ? null : (\n <ImagePlus className=\"h-6 w-6 text-muted-foreground\" />\n )}\n {uploading ? (\n <span className=\"absolute inset-0 flex items-center justify-center bg-background/70\">\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n </span>\n ) : null}\n {failed ? <AlertCircle className=\"relative h-7 w-7 text-destructive\" /> : null}\n </button>\n\n <div className=\"min-w-0 space-y-1.5\">\n <input\n ref={inputRef}\n type=\"file\"\n accept={acceptFor(\"image\")}\n className=\"hidden\"\n onChange={(event) => {\n const file = event.target.files?.[0];\n event.target.value = \"\";\n if (file) void upload.select(file);\n }}\n />\n <div className=\"flex flex-wrap items-center gap-2\">\n {upload.canRetry ? (\n <Button type=\"button\" size=\"sm\" onClick={() => void upload.retry()}>\n <RotateCw className=\"mr-1.5 h-3.5 w-3.5\" />\n {t(\"Retry\")}\n </Button>\n ) : null}\n <Button type=\"button\" variant=\"soft\" size=\"sm\" disabled={uploading} onClick={open}>\n {uploading ? (\n <>\n <Loader2 className=\"mr-1.5 h-3.5 w-3.5 animate-spin\" />\n {t(\"Uploading…\")}\n </>\n ) : hasImage ? t(\"Change\") : buttonLabel ?? t(\"Upload image\")}\n </Button>\n </div>\n {hasImage ? (\n <button\n type=\"button\"\n onClick={upload.clear}\n className=\"flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-destructive\"\n >\n <X className=\"h-3 w-3\" /> {t(\"Remove\")}\n </button>\n ) : null}\n {error ? (\n <p role=\"alert\" className=\"text-sm text-destructive\">{error}</p>\n ) : (\n <p className=\"text-xs text-muted-foreground\">\n {status === \"uploaded\" ? <span className=\"text-primary\">{t(\"✓ Uploaded\")}</span> : t(\"Image files\")}\n </p>\n )}\n {hint ? <p className=\"text-xs text-muted-foreground\">{hint}</p> : null}\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8CsB;AA5CtB,mBAAuC;AACvC,0BAA6D;AAC7D,mBAAkB;AAClB,oBAAuB;AACvB,2BAA0B;AAC1B,gBAAmB;AAEnB,sBAAqB;AAed,SAAS,iBAAiB,EAAE,QAAQ,OAAO,WAAW,MAAM,IAAI,UAAU,UAAU,MAAM,aAAa,OAAO,aAAa,GAA0B;AAC1J,QAAM,QAAI,sBAAK;AACf,QAAM,eAAW,qBAAyB,IAAI;AAC9C,QAAM,EAAE,QAAQ,OAAO,UAAU,IAAI;AACrC,QAAM,SAAS,WAAW,YAAY,CAAC,CAAC;AACxC,QAAM,QAAQ,OAAO,OAAO,OAAO,UAAU;AAC7C,QAAM,WAAW,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC;AACpC,QAAM,OAAO,OAAO,UAAU,WAAW,QAAQ,aAAa,EAAE,cAAc;AAC9E,QAAM,OAAO,MAAM,SAAS,SAAS,MAAM;AAE3C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK,OAAO;AAAA,MACZ,MAAK;AAAA,MACL,cAAY;AAAA,MACZ,UAAU;AAAA,MACV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AK,SAAS,MAAM,KAAK,OAAO,MAAM,GAC/D;AAAA,4DAAC,gCAAS,WAAU,sBAAqB;AAAA,gBACxC,EAAE,OAAO;AAAA,iBACZ,IACE;AAAA,cACJ,4CAAC,wBAAO,MAAK,UAAS,SAAQ,QAAO,MAAK,MAAK,UAAU,WAAW,SAAS,MAC1E,sBACC,4EACE;AAAA,4DAAC,+BAAQ,WAAU,mCAAkC;AAAA,gBACpD,EAAE,iBAAY;AAAA,iBACjB,IACE,WAAW,EAAE,QAAQ,IAAI,eAAe,EAAE,cAAc,GAC9D;AAAA,eACF;AAAA,YACC,WACC;AAAA,cAAC;AAAA;AAAA,gBACC,MAAK;AAAA,gBACL,SAAS,OAAO;AAAA,gBAChB,WAAU;AAAA,gBAEV;AAAA,8DAAC,yBAAE,WAAU,WAAU;AAAA,kBAAE;AAAA,kBAAE,EAAE,QAAQ;AAAA;AAAA;AAAA,YACvC,IACE;AAAA,YACH,QACC,4CAAC,OAAE,MAAK,SAAQ,WAAU,4BAA4B,iBAAM,IAE5D,4CAAC,OAAE,WAAU,iCACV,qBAAW,aAAa,4CAAC,UAAK,WAAU,gBAAgB,YAAE,iBAAY,GAAE,IAAU,EAAE,aAAa,GACpG;AAAA,YAED,OAAO,4CAAC,OAAE,WAAU,iCAAiC,gBAAK,IAAO;AAAA,aACpE;AAAA,WACF;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["Image"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { FileUpload } from '../utils/use-file-upload.cjs';
|
|
4
|
+
|
|
5
|
+
interface ImageUploadFieldProps {
|
|
6
|
+
upload: FileUpload;
|
|
7
|
+
label?: ReactNode;
|
|
8
|
+
ariaLabel?: string;
|
|
9
|
+
alt?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
optional?: boolean;
|
|
12
|
+
hint?: ReactNode;
|
|
13
|
+
buttonLabel?: string;
|
|
14
|
+
round?: boolean;
|
|
15
|
+
currentImage?: string | null;
|
|
16
|
+
}
|
|
17
|
+
declare function ImageUploadField({ upload, label, ariaLabel, alt, required, optional, hint, buttonLabel, round, currentImage }: ImageUploadFieldProps): react_jsx_runtime.JSX.Element;
|
|
18
|
+
|
|
19
|
+
export { ImageUploadField, type ImageUploadFieldProps };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { FileUpload } from '../utils/use-file-upload.js';
|
|
4
|
+
|
|
5
|
+
interface ImageUploadFieldProps {
|
|
6
|
+
upload: FileUpload;
|
|
7
|
+
label?: ReactNode;
|
|
8
|
+
ariaLabel?: string;
|
|
9
|
+
alt?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
optional?: boolean;
|
|
12
|
+
hint?: ReactNode;
|
|
13
|
+
buttonLabel?: string;
|
|
14
|
+
round?: boolean;
|
|
15
|
+
currentImage?: string | null;
|
|
16
|
+
}
|
|
17
|
+
declare function ImageUploadField({ upload, label, ariaLabel, alt, required, optional, hint, buttonLabel, round, currentImage }: ImageUploadFieldProps): react_jsx_runtime.JSX.Element;
|
|
18
|
+
|
|
19
|
+
export { ImageUploadField, type ImageUploadFieldProps };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { AlertCircle, ImagePlus, Loader2, RotateCw, X } from "lucide-react";
|
|
5
|
+
import Image from "./image.js";
|
|
6
|
+
import { Button } from "./button.js";
|
|
7
|
+
import { acceptFor } from "../utils/upload-limits.js";
|
|
8
|
+
import { cn } from "../utils/cn.js";
|
|
9
|
+
import { useT } from "../i18n/provider.js";
|
|
10
|
+
function ImageUploadField({ upload, label, ariaLabel, alt = "", required, optional, hint, buttonLabel, round, currentImage }) {
|
|
11
|
+
const t = useT();
|
|
12
|
+
const inputRef = useRef(null);
|
|
13
|
+
const { status, error, uploading } = upload;
|
|
14
|
+
const failed = status === "failed" || !!error;
|
|
15
|
+
const shown = upload.file ? upload.preview : currentImage;
|
|
16
|
+
const hasImage = !!upload.file || !!currentImage;
|
|
17
|
+
const name = typeof label === "string" ? label : ariaLabel ?? t("Upload image");
|
|
18
|
+
const open = () => inputRef.current?.click();
|
|
19
|
+
return /* @__PURE__ */ jsxs(
|
|
20
|
+
"div",
|
|
21
|
+
{
|
|
22
|
+
ref: upload.fieldRef,
|
|
23
|
+
role: "group",
|
|
24
|
+
"aria-label": name,
|
|
25
|
+
tabIndex: -1,
|
|
26
|
+
"data-status": status,
|
|
27
|
+
className: "space-y-2 outline-none",
|
|
28
|
+
children: [
|
|
29
|
+
label ? /* @__PURE__ */ jsxs("p", { className: "text-sm font-medium", children: [
|
|
30
|
+
label,
|
|
31
|
+
required ? /* @__PURE__ */ jsx("span", { className: "text-destructive", children: " *" }) : null,
|
|
32
|
+
optional ? /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground font-normal", children: [
|
|
33
|
+
" ",
|
|
34
|
+
t("(optional)")
|
|
35
|
+
] }) : null
|
|
36
|
+
] }) : null,
|
|
37
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
|
|
38
|
+
/* @__PURE__ */ jsxs(
|
|
39
|
+
"button",
|
|
40
|
+
{
|
|
41
|
+
type: "button",
|
|
42
|
+
onClick: open,
|
|
43
|
+
disabled: uploading,
|
|
44
|
+
"aria-label": name,
|
|
45
|
+
className: cn(
|
|
46
|
+
"relative flex h-24 w-24 shrink-0 items-center justify-center overflow-hidden border-2 border-dashed bg-muted transition-colors",
|
|
47
|
+
round ? "rounded-full" : "rounded-2xl",
|
|
48
|
+
failed ? "border-destructive" : "border-border hover:border-primary/50"
|
|
49
|
+
),
|
|
50
|
+
children: [
|
|
51
|
+
shown ? /* @__PURE__ */ jsx(Image, { src: shown, alt, fill: true, unoptimized: true, className: cn("object-cover", failed && "opacity-30") }) : failed ? null : /* @__PURE__ */ jsx(ImagePlus, { className: "h-6 w-6 text-muted-foreground" }),
|
|
52
|
+
uploading ? /* @__PURE__ */ jsx("span", { className: "absolute inset-0 flex items-center justify-center bg-background/70", children: /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }) }) : null,
|
|
53
|
+
failed ? /* @__PURE__ */ jsx(AlertCircle, { className: "relative h-7 w-7 text-destructive" }) : null
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
),
|
|
57
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 space-y-1.5", children: [
|
|
58
|
+
/* @__PURE__ */ jsx(
|
|
59
|
+
"input",
|
|
60
|
+
{
|
|
61
|
+
ref: inputRef,
|
|
62
|
+
type: "file",
|
|
63
|
+
accept: acceptFor("image"),
|
|
64
|
+
className: "hidden",
|
|
65
|
+
onChange: (event) => {
|
|
66
|
+
const file = event.target.files?.[0];
|
|
67
|
+
event.target.value = "";
|
|
68
|
+
if (file) void upload.select(file);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
73
|
+
upload.canRetry ? /* @__PURE__ */ jsxs(Button, { type: "button", size: "sm", onClick: () => void upload.retry(), children: [
|
|
74
|
+
/* @__PURE__ */ jsx(RotateCw, { className: "mr-1.5 h-3.5 w-3.5" }),
|
|
75
|
+
t("Retry")
|
|
76
|
+
] }) : null,
|
|
77
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "soft", size: "sm", disabled: uploading, onClick: open, children: uploading ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
78
|
+
/* @__PURE__ */ jsx(Loader2, { className: "mr-1.5 h-3.5 w-3.5 animate-spin" }),
|
|
79
|
+
t("Uploading\u2026")
|
|
80
|
+
] }) : hasImage ? t("Change") : buttonLabel ?? t("Upload image") })
|
|
81
|
+
] }),
|
|
82
|
+
hasImage ? /* @__PURE__ */ jsxs(
|
|
83
|
+
"button",
|
|
84
|
+
{
|
|
85
|
+
type: "button",
|
|
86
|
+
onClick: upload.clear,
|
|
87
|
+
className: "flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-destructive",
|
|
88
|
+
children: [
|
|
89
|
+
/* @__PURE__ */ jsx(X, { className: "h-3 w-3" }),
|
|
90
|
+
" ",
|
|
91
|
+
t("Remove")
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
) : null,
|
|
95
|
+
error ? /* @__PURE__ */ jsx("p", { role: "alert", className: "text-sm text-destructive", children: error }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: status === "uploaded" ? /* @__PURE__ */ jsx("span", { className: "text-primary", children: t("\u2713 Uploaded") }) : t("Image files") }),
|
|
96
|
+
hint ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: hint }) : null
|
|
97
|
+
] })
|
|
98
|
+
] })
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
ImageUploadField
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=image-upload-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/image-upload-field.tsx"],"sourcesContent":["\"use client\";\n\nimport { useRef, type ReactNode } from \"react\";\nimport { AlertCircle, ImagePlus, Loader2, RotateCw, X } from \"lucide-react\";\nimport Image from \"./image.js\";\nimport { Button } from \"./button.js\";\nimport { acceptFor } from \"../utils/upload-limits.js\";\nimport { cn } from \"../utils/cn.js\";\nimport type { FileUpload } from \"../utils/use-file-upload.js\";\nimport { useT } from \"../i18n/provider.js\";\n\nexport interface ImageUploadFieldProps {\n upload: FileUpload;\n label?: ReactNode;\n ariaLabel?: string;\n alt?: string;\n required?: boolean;\n optional?: boolean;\n hint?: ReactNode;\n buttonLabel?: string;\n round?: boolean;\n currentImage?: string | null;\n}\n\nexport function ImageUploadField({ upload, label, ariaLabel, alt = \"\", required, optional, hint, buttonLabel, round, currentImage }: ImageUploadFieldProps) {\n const t = useT();\n const inputRef = useRef<HTMLInputElement>(null);\n const { status, error, uploading } = upload;\n const failed = status === \"failed\" || !!error;\n const shown = upload.file ? upload.preview : currentImage;\n const hasImage = !!upload.file || !!currentImage;\n const name = typeof label === \"string\" ? label : ariaLabel ?? t(\"Upload image\");\n const open = () => inputRef.current?.click();\n\n return (\n <div\n ref={upload.fieldRef}\n role=\"group\"\n aria-label={name}\n tabIndex={-1}\n data-status={status}\n className=\"space-y-2 outline-none\"\n >\n {label ? (\n <p className=\"text-sm font-medium\">\n {label}\n {required ? <span className=\"text-destructive\"> *</span> : null}\n {optional ? <span className=\"text-muted-foreground font-normal\"> {t(\"(optional)\")}</span> : null}\n </p>\n ) : null}\n\n <div className=\"flex items-center gap-4\">\n <button\n type=\"button\"\n onClick={open}\n disabled={uploading}\n aria-label={name}\n className={cn(\n \"relative flex h-24 w-24 shrink-0 items-center justify-center overflow-hidden border-2 border-dashed bg-muted transition-colors\",\n round ? \"rounded-full\" : \"rounded-2xl\",\n failed ? \"border-destructive\" : \"border-border hover:border-primary/50\",\n )}\n >\n {shown ? (\n <Image src={shown} alt={alt} fill unoptimized className={cn(\"object-cover\", failed && \"opacity-30\")} />\n ) : failed ? null : (\n <ImagePlus className=\"h-6 w-6 text-muted-foreground\" />\n )}\n {uploading ? (\n <span className=\"absolute inset-0 flex items-center justify-center bg-background/70\">\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n </span>\n ) : null}\n {failed ? <AlertCircle className=\"relative h-7 w-7 text-destructive\" /> : null}\n </button>\n\n <div className=\"min-w-0 space-y-1.5\">\n <input\n ref={inputRef}\n type=\"file\"\n accept={acceptFor(\"image\")}\n className=\"hidden\"\n onChange={(event) => {\n const file = event.target.files?.[0];\n event.target.value = \"\";\n if (file) void upload.select(file);\n }}\n />\n <div className=\"flex flex-wrap items-center gap-2\">\n {upload.canRetry ? (\n <Button type=\"button\" size=\"sm\" onClick={() => void upload.retry()}>\n <RotateCw className=\"mr-1.5 h-3.5 w-3.5\" />\n {t(\"Retry\")}\n </Button>\n ) : null}\n <Button type=\"button\" variant=\"soft\" size=\"sm\" disabled={uploading} onClick={open}>\n {uploading ? (\n <>\n <Loader2 className=\"mr-1.5 h-3.5 w-3.5 animate-spin\" />\n {t(\"Uploading…\")}\n </>\n ) : hasImage ? t(\"Change\") : buttonLabel ?? t(\"Upload image\")}\n </Button>\n </div>\n {hasImage ? (\n <button\n type=\"button\"\n onClick={upload.clear}\n className=\"flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-destructive\"\n >\n <X className=\"h-3 w-3\" /> {t(\"Remove\")}\n </button>\n ) : null}\n {error ? (\n <p role=\"alert\" className=\"text-sm text-destructive\">{error}</p>\n ) : (\n <p className=\"text-xs text-muted-foreground\">\n {status === \"uploaded\" ? <span className=\"text-primary\">{t(\"✓ Uploaded\")}</span> : t(\"Image files\")}\n </p>\n )}\n {hint ? <p className=\"text-xs text-muted-foreground\">{hint}</p> : null}\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";AA8CsB,SAmDN,UAnDM,KACA,YADA;AA5CtB,SAAS,cAA8B;AACvC,SAAS,aAAa,WAAW,SAAS,UAAU,SAAS;AAC7D,OAAO,WAAW;AAClB,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AAEnB,SAAS,YAAY;AAed,SAAS,iBAAiB,EAAE,QAAQ,OAAO,WAAW,MAAM,IAAI,UAAU,UAAU,MAAM,aAAa,OAAO,aAAa,GAA0B;AAC1J,QAAM,IAAI,KAAK;AACf,QAAM,WAAW,OAAyB,IAAI;AAC9C,QAAM,EAAE,QAAQ,OAAO,UAAU,IAAI;AACrC,QAAM,SAAS,WAAW,YAAY,CAAC,CAAC;AACxC,QAAM,QAAQ,OAAO,OAAO,OAAO,UAAU;AA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ACV,UAAU,CAAC,UAAU;AACnB,wBAAM,OAAO,MAAM,OAAO,QAAQ,CAAC;AACnC,wBAAM,OAAO,QAAQ;AACrB,sBAAI,KAAM,MAAK,OAAO,OAAO,IAAI;AAAA,gBACnC;AAAA;AAAA,YACF;AAAA,YACA,qBAAC,SAAI,WAAU,qCACZ;AAAA,qBAAO,WACN,qBAAC,UAAO,MAAK,UAAS,MAAK,MAAK,SAAS,MAAM,KAAK,OAAO,MAAM,GAC/D;AAAA,oCAAC,YAAS,WAAU,sBAAqB;AAAA,gBACxC,EAAE,OAAO;AAAA,iBACZ,IACE;AAAA,cACJ,oBAAC,UAAO,MAAK,UAAS,SAAQ,QAAO,MAAK,MAAK,UAAU,WAAW,SAAS,MAC1E,sBACC,iCACE;AAAA,oCAAC,WAAQ,WAAU,mCAAkC;AAAA,gBACpD,EAAE,iBAAY;AAAA,iBACjB,IACE,WAAW,EAAE,QAAQ,IAAI,eAAe,EAAE,cAAc,GAC9D;AAAA,eACF;AAAA,YACC,WACC;AAAA,cAAC;AAAA;AAAA,gBACC,MAAK;AAAA,gBACL,SAAS,OAAO;AAAA,gBAChB,WAAU;AAAA,gBAEV;AAAA,sCAAC,KAAE,WAAU,WAAU;AAAA,kBAAE;AAAA,kBAAE,EAAE,QAAQ;AAAA;AAAA;AAAA,YACvC,IACE;AAAA,YACH,QACC,oBAAC,OAAE,MAAK,SAAQ,WAAU,4BAA4B,iBAAM,IAE5D,oBAAC,OAAE,WAAU,iCACV,qBAAW,aAAa,oBAAC,UAAK,WAAU,gBAAgB,YAAE,iBAAY,GAAE,IAAU,EAAE,aAAa,GACpG;AAAA,YAED,OAAO,oBAAC,OAAE,WAAU,iCAAiC,gBAAK,IAAO;AAAA,aACpE;AAAA,WACF;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -36,9 +36,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
36
36
|
var import_react = require("react");
|
|
37
37
|
var import_lucide_react = require("lucide-react");
|
|
38
38
|
var import_sdk = require("@medialane/sdk");
|
|
39
|
-
var import_upload_limits = require("../../utils/upload-limits.js");
|
|
40
39
|
var import_starknet = require("@medialane/sdk/starknet");
|
|
41
|
-
var import_image = __toESM(require("../image.js"), 1);
|
|
42
40
|
var import_link = __toESM(require("../link.js"), 1);
|
|
43
41
|
var import_input = require("../input.js");
|
|
44
42
|
var import_label = require("../label.js");
|
|
@@ -56,7 +54,8 @@ var import_cn = require("../../utils/cn.js");
|
|
|
56
54
|
var import_launchpad_defaults = require("../../utils/launchpad-defaults.js");
|
|
57
55
|
var import_run_intent_calls = require("../../utils/run-intent-calls.js");
|
|
58
56
|
var import_use_transaction = require("../../utils/use-transaction.js");
|
|
59
|
-
var
|
|
57
|
+
var import_use_image_upload = require("../../utils/use-image-upload.js");
|
|
58
|
+
var import_image_upload_field = require("../image-upload-field.js");
|
|
60
59
|
var import_use_erc20_balance = require("../../utils/media-wallet/use-erc20-balance.js");
|
|
61
60
|
var import_provider = require("../../i18n/provider.js");
|
|
62
61
|
var import_use_format = require("../../i18n/use-format.js");
|
|
@@ -82,8 +81,7 @@ function CoinCreate({ aside, tradeHref }) {
|
|
|
82
81
|
const [teamPct, setTeamPct] = (0, import_react.useState)(5);
|
|
83
82
|
const [coinAddress, setCoinAddress] = (0, import_react.useState)(null);
|
|
84
83
|
const [profileStatus, setProfileStatus] = (0, import_react.useState)("idle");
|
|
85
|
-
const upload = (0,
|
|
86
|
-
const { imagePreview, imageUri, imageUploading, uploadError, uploadSuccess, fileInputRef, handleImageSelect, clearImage } = upload;
|
|
84
|
+
const upload = (0, import_use_image_upload.useImageUpload)();
|
|
87
85
|
const quoteToken = (0, import_sdk.getTokenBySymbol)(quote);
|
|
88
86
|
const { rawBalance } = (0, import_use_erc20_balance.useTokenBalance)(quote, walletAddress ?? null);
|
|
89
87
|
const priceNum = Number(price);
|
|
@@ -115,12 +113,12 @@ function CoinCreate({ aside, tradeHref }) {
|
|
|
115
113
|
};
|
|
116
114
|
}, [supply, priceNum, teamPct, quoteToken.decimals]);
|
|
117
115
|
const insufficient = preview != null && rawBalance != null && rawBalance < preview.buybackRaw;
|
|
118
|
-
const canLaunch = identityValid && economicsValid && preview != null && teamPct > 0 && !insufficient && !
|
|
116
|
+
const canLaunch = identityValid && economicsValid && preview != null && teamPct > 0 && !insufficient && !upload.uploading;
|
|
119
117
|
const previewData = {
|
|
120
118
|
name,
|
|
121
119
|
symbol,
|
|
122
120
|
description,
|
|
123
|
-
imageUrl:
|
|
121
|
+
imageUrl: upload.preview,
|
|
124
122
|
supplyHuman: economicsValid && supply ? Number(supply) : null,
|
|
125
123
|
price: priceErr ? import_starknet.SUGGESTED_DEFAULT_PRICE : priceNum,
|
|
126
124
|
quoteSymbol: quote,
|
|
@@ -128,6 +126,7 @@ function CoinCreate({ aside, tradeHref }) {
|
|
|
128
126
|
};
|
|
129
127
|
const handleLaunchClick = () => {
|
|
130
128
|
if (!canLaunch || !walletAddress || !preview) return;
|
|
129
|
+
if (!upload.confirm()) return;
|
|
131
130
|
const owner = (0, import_sdk.normalizeAddress)("STARKNET", walletAddress);
|
|
132
131
|
const supplyRaw = (0, import_starknet.coinToRaw)(BigInt(supply));
|
|
133
132
|
const teamRaw = (0, import_starknet.teamCoinsRaw)(supplyRaw, teamPct);
|
|
@@ -158,9 +157,9 @@ function CoinCreate({ aside, tradeHref }) {
|
|
|
158
157
|
await api.coins.sync(address, owner).catch(() => {
|
|
159
158
|
});
|
|
160
159
|
setCoinAddress(address);
|
|
161
|
-
if (
|
|
160
|
+
if (upload.uri || description) {
|
|
162
161
|
setProfileStatus("saving");
|
|
163
|
-
await api.collections.updateProfile(address, { ...
|
|
162
|
+
await api.collections.updateProfile(address, { ...upload.uri ? { image: upload.uri } : {}, ...description ? { description } : {} }).then(() => setProfileStatus("saved")).catch(() => setProfileStatus("failed"));
|
|
164
163
|
}
|
|
165
164
|
});
|
|
166
165
|
};
|
|
@@ -175,7 +174,7 @@ function CoinCreate({ aside, tradeHref }) {
|
|
|
175
174
|
setSupply("");
|
|
176
175
|
setPrice(String(import_starknet.SUGGESTED_DEFAULT_PRICE));
|
|
177
176
|
setTeamPct(5);
|
|
178
|
-
|
|
177
|
+
upload.clear();
|
|
179
178
|
};
|
|
180
179
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
181
180
|
import_wallet_required.WalletRequired,
|
|
@@ -189,7 +188,7 @@ function CoinCreate({ aside, tradeHref }) {
|
|
|
189
188
|
import_transaction_success.TransactionSuccess,
|
|
190
189
|
{
|
|
191
190
|
name: name || "Your coin",
|
|
192
|
-
image:
|
|
191
|
+
image: upload.preview,
|
|
193
192
|
title: t("Coin launched"),
|
|
194
193
|
description: t("The supply is fixed and the liquidity is locked."),
|
|
195
194
|
actions: [
|
|
@@ -221,49 +220,7 @@ function CoinCreate({ aside, tradeHref }) {
|
|
|
221
220
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-7", children: [
|
|
222
221
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "space-y-4", children: [
|
|
223
222
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { className: "text-lg font-bold", children: t("Give it a face") }) }),
|
|
224
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
225
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_label.Label, { children: t("Coin image") }),
|
|
226
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-4", children: [
|
|
227
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
228
|
-
"button",
|
|
229
|
-
{
|
|
230
|
-
type: "button",
|
|
231
|
-
onClick: () => fileInputRef.current?.click(),
|
|
232
|
-
className: "relative h-24 w-24 shrink-0 rounded-full overflow-hidden border border-dashed border-border bg-muted/20 flex items-center justify-center",
|
|
233
|
-
children: [
|
|
234
|
-
imagePreview ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.default, { src: imagePreview, alt: t("Coin"), fill: true, unoptimized: true, className: "object-cover" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ImagePlus, { className: "h-6 w-6 text-muted-foreground" }),
|
|
235
|
-
imageUploading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "absolute inset-0 bg-background/70 flex items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Loader2, { className: "h-4 w-4 animate-spin text-primary" }) })
|
|
236
|
-
]
|
|
237
|
-
}
|
|
238
|
-
),
|
|
239
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-1 text-xs text-muted-foreground", children: [
|
|
240
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("Image files") }),
|
|
241
|
-
imagePreview && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", onClick: clearImage, className: "inline-flex items-center gap-1 text-muted-foreground active:text-foreground", children: [
|
|
242
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.X, { className: "h-3 w-3" }),
|
|
243
|
-
" ",
|
|
244
|
-
t("Remove")
|
|
245
|
-
] }),
|
|
246
|
-
uploadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-destructive", children: uploadError }),
|
|
247
|
-
uploadSuccess && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "text-brand-blue", children: [
|
|
248
|
-
"\u2713 ",
|
|
249
|
-
uploadSuccess
|
|
250
|
-
] })
|
|
251
|
-
] }),
|
|
252
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
253
|
-
"input",
|
|
254
|
-
{
|
|
255
|
-
ref: fileInputRef,
|
|
256
|
-
type: "file",
|
|
257
|
-
accept: (0, import_upload_limits.acceptFor)("image"),
|
|
258
|
-
className: "hidden",
|
|
259
|
-
onChange: (e) => {
|
|
260
|
-
const f = e.target.files?.[0];
|
|
261
|
-
if (f) void handleImageSelect(f);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
)
|
|
265
|
-
] })
|
|
266
|
-
] }),
|
|
223
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image_upload_field.ImageUploadField, { upload, label: t("Coin image"), alt: t("Coin"), round: true }),
|
|
267
224
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "grid gap-4 sm:grid-cols-2", children: [
|
|
268
225
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-1.5", children: [
|
|
269
226
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_label.Label, { htmlFor: "name", children: t("Name") }),
|