import { CSSResultGroup } from 'lit'; import { default as PairboElement } from '../../internal/pairbo-element.js'; import { default as PboButton } from '../button/button.component.js'; import { default as PboFakeLoading } from '../fake-loading/fake-loading.component.js'; /** * @summary Short summary of the component's intended use. * @status experimental * * @dependency pbo-example * * @event pbo-event-name - Emitted as an example. * * @slot - The default slot. * @slot example - An example slot. * * @csspart base - The component's base wrapper. * * @cssproperty --example - An example CSS custom property. */ export default class PboHandwrittenForm extends PairboElement { static styles: CSSResultGroup; static dependencies: { "pbo-button": typeof PboButton; "pbo-fake-loading": typeof PboFakeLoading; }; /** The editing handwritten card */ card: Card | null; /** * The form data for the handwritten form * Only need the submit logic, the status and error handling is done in the wrapper function */ submitHandwrittenForm: SubmitHandwrittenForm; /** * The function to get the processed image * Only need to logic to post the image and return the processed image URL * The status and error handling is done in the wrapper function */ getProcessedImg: GetProcessedImg; onClose: () => void; /** The loading state when submitting the form */ isSubmitLoading: boolean; ctaPrimaryLabel: string; uploadButtonLabel: string; /** The disabled state when submitting the form */ isSubmitDisabled: boolean; imageInput: HTMLInputElement; handwrittenForm: HTMLFormElement; uploadButton: PboButton; saveButton: PboButton; reuploadButton: PboButton; /** * The error state during the processing image, this is handled by the component. * No need to handle the error in the original function */ isProcessingError: boolean; submitError: string; /** * The state of the image processing, this is handled by the component. * No need to handle the loading state in the original function */ isImageProcessing: boolean; /** * The source image file, this is the image that the user uploads * When the source image changes `handleSourceImgChange` will called * and getting the processed image */ sourceImg: File | null; /** * The processed image object * - `masked_img`: is in the format of `data:image/png;base64,...` * - `uid`: is for the image ID returned from the server */ processedImg: { uid: string | null; masked_img: string | null; }; /** * The dimensions of the handwritten image * - `top`: The top position of the image in pixels * - `left`: The left position of the image in pixels * - `width`: The width of the image in pixels * - `height`: The height of the image in pixels * - `cardHeight`: The height of the card in pixels, this is to convert the pixel into inches * - `cardWidth`: The width of the card in pixels, this is to convert the pixel into inches * @memberof PboHandwrittenForm */ handwrittenDimensions: { top: number | null; left: number | null; width: number | null; height: number | null; cardHeight: number | null; cardWidth: number | null; }; /** * Shows the file picker for the handwritten image input * The file input is hidden and this method is called when the user clicks the upload button */ showPicker(): void; /** * Sets the buttons' disabled state * @param disable - Whether to disable the buttons */ setButtonsDisabled(disable: boolean): void; /** * Sets the buttons' error state * * This will change the button variant to danger and update the button text * @param error - Whether to set the buttons in error state */ setButtonsError(error: boolean): void; /** * Sets the buttons' loading state * @param loading - Whether to set the buttons in loading state */ setButtonsLoading(loading: boolean): void; /** * When the submit loading state changes, update the buttons' loading state * * This is to indicate that the form is being submitted */ handleSubmitLoadingChange(): void; handleSubmitDisabledChange(): void; handleProcessingErrorChange(): void; /** * When the source image changes, reset the processed file URL, * and emit `pbo-handwritten-form-change` event with loading state. * * The `pbo-handwritten-form-change-change` event is for: * - Indicating that the image is being processed * - Focusing the main image to the preview image in the `handwritten-canvas` component */ handleSourceImgChange(oldFile: File | null, newFile: File | null): void; /** * When the processed image URL changes, emit an event with the new processed file URL. * * It's basically to passing the processed image to the `handwritten-canvas` component */ handleProcessImageChange(oldFileUrl: string | null, newFileUrl: string | null): void; /** * When the image processing state changes, update the buttons' disabled and loading states. */ handleImageProcessingChange(): void; /** * formData getter * * The formData is the data that will be submitted to the server. Please note that the length metrics are in the inches. */ get formData(): HandwrittenFormData; /** * Sets the dimensions of the handwritten image * * Pixel based */ setDimensions(dimensions: { top: number | null; left: number | null; width: number | null; height: number | null; cardHeight: number | null; cardWidth: number | null; }): void; /** * When the processed image changes, emit an event with the new processed file URL. * This is to notify the parent component that the processed image is ready */ handleProcessedImgChange(): void; handleFileChange(e: Event): Promise; handleSubmit(e: Event): Promise; render(): import('lit-html').TemplateResult<1>; }