theme.keycloak.v2.admin.resources.assets.FileUpload-CumNwlWc.js.map Maven / Gradle / Ivy
{"version":3,"file":"FileUpload-CumNwlWc.js","sources":["../../src/components/json-file-upload/patternfly/fileUtils.ts","../../src/components/json-file-upload/patternfly/FileUploadField.tsx","../../src/components/json-file-upload/patternfly/FileUpload.tsx"],"sourcesContent":["export enum fileReaderType {\n text = \"text\",\n dataURL = \"dataURL\",\n}\n\n/**\n * Read a file using the FileReader API, either as a plain text string or as a DataURL string.\n * Returns a promise which will resolve with the file contents as a string or reject with a DOMException.\n *\n * @param {File} fileHandle - File object to read\n * @param {fileReaderType} type - How to read it\n */\nexport function readFile(fileHandle: File, type: fileReaderType) {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n\n reader.onload = () => resolve(reader.result);\n reader.onerror = () => reject(reader.error);\n\n switch (type) {\n case fileReaderType.text:\n reader.readAsText(fileHandle);\n break;\n case fileReaderType.dataURL:\n reader.readAsDataURL(fileHandle);\n break;\n default:\n reject(\"unknown type\");\n }\n });\n}\n","import {\n Button,\n ButtonVariant,\n InputGroup,\n Spinner,\n spinnerSize,\n TextArea,\n TextAreResizeOrientation,\n TextInput,\n InputGroupItem,\n} from \"@patternfly/react-core\";\nimport { css } from \"@patternfly/react-styles\";\nimport styles from \"@patternfly/react-styles/css/components/FileUpload/file-upload\";\nimport { PropsWithChildren } from \"react\";\n\nimport { fileReaderType } from \"./fileUtils\";\n\nexport interface FileUploadFieldProps\n extends Omit, \"value\" | \"onChange\"> {\n /** Unique id for the TextArea, also used to generate ids for accessible labels */\n id: string;\n /** What type of file. Determines what is is expected by `value`\n * (a string for 'text' and 'dataURL', or a File object otherwise). */\n type?: \"text\" | \"dataURL\";\n /** Value of the file's contents\n * (string if text file, File object otherwise) */\n value?: string | File;\n /** Value to be shown in the read-only filename field. */\n filename?: string;\n /** A callback for when the TextArea value changes. */\n onChange?: (\n value: string,\n filename: string,\n event:\n | React.ChangeEvent // User typed in the TextArea\n | React.MouseEvent, // User clicked Clear button\n ) => void;\n /** Additional classes added to the FileUploadField container element. */\n className?: string;\n /** Flag to show if the field is disabled. */\n isDisabled?: boolean;\n /** Flag to show if the field is read only. */\n isReadOnly?: boolean;\n /** Flag to show if a file is being loaded. */\n isLoading?: boolean;\n /** Aria-valuetext for the loading spinner */\n spinnerAriaValueText?: string;\n /** Flag to show if the field is required. */\n isRequired?: boolean;\n /** Value to indicate if the field is modified to show that validation state.\n * If set to success, field will be modified to indicate valid state.\n * If set to error, field will be modified to indicate error state.\n */\n validated?: \"success\" | \"error\" | \"default\";\n /** Aria-label for the TextArea. */\n \"aria-label\"?: string;\n /** Placeholder string to display in the empty filename field */\n filenamePlaceholder?: string;\n /** Aria-label for the read-only filename field */\n filenameAriaLabel?: string;\n /** Text for the Browse button */\n browseButtonText?: string;\n /** Text for the Clear button */\n clearButtonText?: string;\n /** Flag to disable the Clear button */\n isClearButtonDisabled?: boolean;\n /** Flag to hide the built-in preview of the file (where available).\n * If true, you can use children to render an alternate preview. */\n hideDefaultPreview?: boolean;\n /** Flag to allow editing of a text file's contents after it is selected from disk */\n allowEditingUploadedText?: boolean;\n /** Additional children to render after (or instead of) the file preview. */\n children?: React.ReactNode;\n\n // Props available in FileUploadField but not FileUpload:\n\n /** A callback for when the Browse button is clicked. */\n onBrowseButtonClick?: (\n event: React.MouseEvent,\n ) => void;\n /** A callback for when the Clear button is clicked. */\n onClearButtonClick?: (\n event: React.MouseEvent,\n ) => void;\n /** A callback from when the text area is clicked. Can also be set via the onClick property of FileUpload. */\n onTextAreaClick?: (\n event: React.MouseEvent,\n ) => void;\n /** Flag to show if a file is being dragged over the field */\n isDragActive?: boolean;\n /** A reference object to attach to the FileUploadField container element. */\n containerRef?: React.Ref;\n /** Text area text changed */\n onTextChange?: (text: string) => void;\n}\n\nexport const FileUploadField = ({\n id,\n type,\n value = \"\",\n filename = \"\",\n onChange,\n onBrowseButtonClick,\n onClearButtonClick,\n onTextAreaClick,\n onTextChange,\n className = \"\",\n isDisabled = false,\n isReadOnly = false,\n isLoading = false,\n spinnerAriaValueText,\n isRequired = false,\n isDragActive = false,\n validated = \"default\" as \"success\" | \"error\" | \"default\",\n \"aria-label\": ariaLabel = \"File upload\",\n filenamePlaceholder = \"Drag a file here or browse to upload\",\n filenameAriaLabel = filename ? \"Read only filename\" : filenamePlaceholder,\n browseButtonText = \"Browse...\",\n clearButtonText = \"Clear\",\n isClearButtonDisabled = !filename && !value,\n containerRef = null as React.Ref,\n allowEditingUploadedText = false,\n hideDefaultPreview = false,\n children = null,\n\n ...props\n}: PropsWithChildren) => {\n const onTextAreaChange = (\n newValue: string,\n event: React.ChangeEvent,\n ) => {\n onChange?.(newValue, filename, event);\n onTextChange?.(newValue);\n };\n return (\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n {!hideDefaultPreview && type === fileReaderType.text && (\n \n {children}\n \n );\n};\nFileUploadField.displayName = \"FileUploadField\";\n","import { fromEvent } from \"file-selector\";\nimport { PropsWithChildren } from \"react\";\nimport {\n DropEvent,\n DropzoneInputProps,\n DropzoneOptions,\n FileRejection,\n useDropzone,\n} from \"react-dropzone\";\n\nimport { FileUploadField, FileUploadFieldProps } from \"./FileUploadField\";\nimport { fileReaderType, readFile } from \"./fileUtils\";\n\nexport interface FileUploadProps\n extends Omit<\n FileUploadFieldProps,\n | \"children\"\n | \"onBrowseButtonClick\"\n | \"onClearButtonClick\"\n | \"isDragActive\"\n | \"containerRef\"\n > {\n /** Unique id for the TextArea, also used to generate ids for accessible labels. */\n id: string;\n /** What type of file. Determines what is is passed to `onChange` and expected by `value`\n * (a string for 'text' and 'dataURL', or a File object otherwise. */\n type?: \"text\" | \"dataURL\";\n /** Value of the file's contents\n * (string if text file, File object otherwise) */\n value?: string | File;\n /** Value to be shown in the read-only filename field. */\n filename?: string;\n /** @deprecated A callback for when the file contents change. Please instead use onFileInputChange, onTextChange, onDataChange, onClearClick individually. */\n onChange?: (\n value: string | File,\n filename: string,\n event:\n | React.MouseEvent // Clear button was clicked\n | React.ChangeEvent // User typed in the TextArea\n | DropEvent,\n ) => void;\n /** Change event emitted from the hidden \\ field associated with the component */\n onFileInputChange?: (event: DropEvent, file: File) => void;\n /** Callback for clicking on the FileUploadField text area. By default, prevents a click in the text area from opening file dialog. */\n onClick?: (event: React.MouseEvent) => void;\n /** Additional classes added to the FileUpload container element. */\n className?: string;\n /** Flag to show if the field is disabled. */\n isDisabled?: boolean;\n /** Flag to show if the field is read only. */\n isReadOnly?: boolean;\n /** Flag to show if a file is being loaded. */\n isLoading?: boolean;\n /** Aria-valuetext for the loading spinner */\n spinnerAriaValueText?: string;\n /** Flag to show if the field is required. */\n isRequired?: boolean;\n /** Value to indicate if the field is modified to show that validation state.\n * If set to success, field will be modified to indicate valid state.\n * If set to error, field will be modified to indicate error state.\n */\n validated?: \"success\" | \"error\" | \"default\";\n /** Aria-label for the TextArea. */\n \"aria-label\"?: string;\n /** Placeholder string to display in the empty filename field */\n filenamePlaceholder?: string;\n /** Aria-label for the read-only filename field */\n filenameAriaLabel?: string;\n /** Text for the Browse button */\n browseButtonText?: string;\n /** Text for the Clear button */\n clearButtonText?: string;\n /** Flag to hide the built-in preview of the file (where available).\n * If true, you can use children to render an alternate preview. */\n hideDefaultPreview?: boolean;\n /** Flag to allow editing of a text file's contents after it is selected from disk */\n allowEditingUploadedText?: boolean;\n /** Additional children to render after (or instead of) the file preview. */\n children?: React.ReactNode;\n\n // Props available in FileUpload but not FileUploadField:\n\n /** A callback for when a selected file starts loading */\n onReadStarted?: (fileHandle: File) => void;\n /** A callback for when a selected file finishes loading */\n onReadFinished?: (fileHandle: File) => void;\n /** A callback for when the FileReader API fails */\n onReadFailed?: (error: DOMException, fileHandle: File) => void;\n /** Optional extra props to customize react-dropzone. */\n dropzoneProps?: DropzoneOptions;\n /** Clear button was clicked */\n onClearClick?: React.MouseEventHandler;\n /** Text area text changed */\n onTextChange?: (text: string) => void;\n /** On data changed - if type='text' or type='dataURL' and file was loaded it will call this method */\n onDataChange?: (data: string) => void;\n}\n\nexport const FileUpload = ({\n id,\n type,\n value = type === fileReaderType.text || type === fileReaderType.dataURL\n ? \"\"\n : undefined,\n filename = \"\",\n children = null,\n onChange,\n onFileInputChange,\n onReadStarted,\n onReadFinished,\n onReadFailed,\n onClearClick,\n onClick = (event) => event.preventDefault(),\n onTextChange,\n onDataChange,\n dropzoneProps = {},\n ...props\n}: PropsWithChildren) => {\n const onDropAccepted = (acceptedFiles: File[], event: DropEvent) => {\n if (acceptedFiles.length > 0) {\n const fileHandle = acceptedFiles[0];\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (event?.type === \"drop\") {\n onFileInputChange?.(event, fileHandle);\n }\n if (type === fileReaderType.text || type === fileReaderType.dataURL) {\n onChange?.(\"\", fileHandle.name, event); // Show the filename while reading\n onReadStarted?.(fileHandle);\n readFile(fileHandle, type as fileReaderType)\n .then((data) => {\n onReadFinished?.(fileHandle);\n onChange?.(data as string, fileHandle.name, event);\n onDataChange?.(data as string);\n })\n .catch((error: DOMException) => {\n onReadFailed?.(error, fileHandle);\n onReadFinished?.(fileHandle);\n onChange?.(\"\", \"\", event); // Clear the filename field on a failure\n onDataChange?.(\"\");\n });\n } else {\n onChange?.(fileHandle, fileHandle.name, event);\n }\n }\n dropzoneProps.onDropAccepted?.(acceptedFiles, event);\n };\n\n const onDropRejected = (rejectedFiles: FileRejection[], event: DropEvent) => {\n if (rejectedFiles.length > 0) {\n onChange?.(\"\", rejectedFiles[0].file.name, event);\n }\n\n dropzoneProps.onDropRejected?.(rejectedFiles, event);\n };\n\n const onClearButtonClick = (\n event: React.MouseEvent,\n ) => {\n onChange?.(\"\", \"\", event);\n onClearClick?.(event);\n setFileValue(\"\");\n };\n\n const { getRootProps, getInputProps, isDragActive, open, inputRef } =\n useDropzone({\n multiple: false,\n ...dropzoneProps,\n onDropAccepted,\n onDropRejected,\n });\n\n const setFileValue = (filename: string) => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.value = filename;\n };\n\n const oldInputProps = getInputProps();\n const inputProps: DropzoneInputProps = {\n ...oldInputProps,\n onChange: async (e: React.ChangeEvent) => {\n oldInputProps.onChange?.(e);\n const files = await fromEvent(e.nativeEvent);\n if (files.length === 1) {\n onFileInputChange?.(e, files[0] as File);\n }\n },\n };\n\n return (\n event.preventDefault(),\n })}\n tabIndex={undefined} // Omit the unwanted tabIndex from react-dropzone's getRootProps\n id={id}\n type={type}\n filename={filename}\n value={value}\n onChange={onChange}\n isDragActive={isDragActive}\n onBrowseButtonClick={open}\n onClearButtonClick={onClearButtonClick}\n onTextAreaClick={onClick}\n onTextChange={onTextChange}\n onClick={(e) => e.stopPropagation()}\n >\n \n {children}\n \n );\n};\n\nFileUpload.displayName = \"FileUpload\";\n"],"names":["fileReaderType","readFile","fileHandle","type","resolve","reject","reader","FileUploadField","id","value","filename","onChange","onBrowseButtonClick","onClearButtonClick","onTextAreaClick","onTextChange","className","isDisabled","isReadOnly","isLoading","spinnerAriaValueText","isRequired","isDragActive","validated","ariaLabel","filenamePlaceholder","filenameAriaLabel","browseButtonText","clearButtonText","isClearButtonDisabled","containerRef","allowEditingUploadedText","hideDefaultPreview","children","props","onTextAreaChange","newValue","event","jsxs","css","styles","jsx","InputGroup","InputGroupItem","TextInput","Button","ButtonVariant","TextArea","TextAreResizeOrientation","Spinner","spinnerSize","FileUpload","onFileInputChange","onReadStarted","onReadFinished","onReadFailed","onClearClick","onClick","onDataChange","dropzoneProps","onDropAccepted","acceptedFiles","data","error","onDropRejected","rejectedFiles","setFileValue","getRootProps","getInputProps","open","inputRef","useDropzone","oldInputProps","inputProps","files","fromEvent"],"mappings":"0NAAY,IAAAA,GAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,QAAU,UAFAA,IAAAA,GAAA,CAAA,CAAA,EAYI,SAAAC,EAASC,EAAkBC,EAAsB,CAC/D,OAAO,IAAI,QAAQ,CAACC,EAASC,IAAW,CAChC,MAAAC,EAAS,IAAI,WAKnB,OAHAA,EAAO,OAAS,IAAMF,EAAQE,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