Skip to content

Commit

Permalink
Update README.md, add cdn property. (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Nov 25, 2023
1 parent ed361f9 commit 4e1c8d8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 106 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,67 @@ $imageFile = FileProcessing::saveWithReturningFile(
);
```

### Properties of the widget

| Property | Type | Description | Default |
|-----------------------------------------|---------------|----------------------------------------------------------------------------|-----------------------------------------|
| `acceptedFileTypes` | `string` | The accepted file types. Can be mime types or wild cards. | `[]` |
| `allowFileTypeValidation` | `bool` | Whether to allow file type validation. | `true` |
| `allowFileRename` | `bool` | Whether to allow file rename. | `false` |
| `allowFileValidateSize` | `bool` | Whether to allow file size validation. | `true` |
| `allowImageCrop` | `bool` | Whether to allow image crop. | `false` |
| `allowImageExifOrientation` | `bool` | Whether to allow image exif orientation. | `true` |
| `allowImagePreview` | `bool` | Whether to allow image preview. | `true` |
| `allowImageTransform` | `bool` | Whether to allow image transform. | `false` |
| `allowMultiple` | `bool` | Whether to allow multiple files. | `false` |
| `allowpdfPreview` | `bool` | Whether to allow pdf preview. | `false` |
| `cssClass` | `string` | The css class of the widget. | `''` |
| `cdn` | `boolean` | Whether to use the CDN. | `true` |
| `config` | `array` | The config of the widget. | `[]` |
| `fileRename` | `string` | The file rename. | `''` |
| | | use: `fileRenameFunction: (file) => return `my_new_name${file.extension}`; | |
| `fileValidateTypeDetectType` | `string` | The file validate type detect type function. | `''` |
| `fileValidateTypeLabelExpectedTypes` | `string` | The file validate type label expected types. | `''` |
| `imageCropAspectRatio` | `string|null` | The image crop aspect ratio. | `null` |
| `imagePreviewHeight` | `string|null` | The image preview height. | `null` |
| `imagePreviewMarkupShow` | `bool` | Whether to show the image preview markup. | `true` |
| `imagePreviewMaxFileSize` | `string|null` | The image preview max file size. | `null` |
| `imagePreviewMaxHeight` | `int` | The image preview max height. | `256` |
| `imagePreviewMaxInstantPreviewFileSize` | `int` | The image preview max instant preview file size. | `10000000` |
| `imagePreviewMinHeight` | `int` | The image preview min height. | `44` |
| `imagePreviewTransparencyIndicator` | `string!null` | The image preview transparency indicator. | `null` |
| `imageTransformAfterCreateBlob` | `array|null` | The image transform after create blob. | `null` |
| `imageTransformBeforeCreateBlob` | `array|null` | The image transform before create blob. | `null` |
| `imageTransformOutputQuality` | `int|null` | The image transform output quality. | `null` |
| `imageTransformClientTransforms` | `array|null` | The image transform client transforms. | `null` |
| `imageTransformOutputQualityMode` | `string|null` | The image transform output quality mode. | `añways` |
| `imageTransformOutputStripImageHead` | `bool` | The image transform output strip image head. | `true` |
| `imageTransformVariants` | `array|null` | The image transform variants. | `null` |
| `imageTransformVariantsIncludeDefault` | `bool` | The image transform variants include default. | `true` |
| `imageTransformVariantsDefaultName` | `string|null` | The image transform variants default name. | `null` |
| `imageTransformVariantsIncludeOriginal` | `bool` | The image transform variants include original. | `false` |
| `labelIdle` | `string` | The label idle. | `''` |
| `labelMaxFileSize` | `string` | The label max file size. | `''` |
| `labelMaxFileSizeExceeded` | `string` | The label max file size exceeded. | `''` |
| `labelMaxTotalFileSize` | `string` | The label max total file size. | `''` |
| `labelMaxTotalFileSizeExceeded` | `string` | The label max total file size exceeded. | `''` |
| `labelFileTypeNotAllowed` | `string` | The label file type not allowed. | `''` |
| `loadFileDefault` | `string` | The load file default. | `''` |
| `maxFiles` | `int` | The max files. | `1` |
| `maxFileSize` | `string|null` | The max file size. | `null` |
| `maxTotalFileSize` | `string|null` | The max total file size. | `null` |
| `minFileSize` | `string|null` | The min file size. | `null` |
| `pluginDefault` | `array` | The plugins default. | `[` |
| | | | `FilePondPluginFileValidateType,` |
| | | | `FilePondPluginFileValidateSize,` |
| | | | `FilePondPluginFileValidateType,` |
| | | | `FilePondPluginImageExifOrientation,` |
| | | | `FilePondPluginImagePreview,` |
| | | | `]` |
| `pdfPreviewHeight` | `int` | The pdf preview height. | `320` |
| `pdfComponentExtraParams` | `string` | The pdf component extra params. | `toolbar=0&view=fit&page=1` |
| `required` | `bool` | Whether the field is required. | `false` |

### Translation support

The extension supports translation. You can translate the extension into your language,
Expand Down
109 changes: 3 additions & 106 deletions src/FilePond.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,19 @@

final class FilePond extends InputWidget
{
/**
* @var array The accepted file types. Can be mime types or wild cards.
* For instance ['image/*'] will accept all images. ['image/png', 'image/jpeg'] will only accept PNGs and JPEGs.
*/
public array $acceptedFileTypes = [];
/**
* @var bool Whether to allow file type validation.
*/
public bool $allowFileTypeValidation = true;
/**
* @var bool Whether to allow file rename.
*/
public bool $allowFileRename = false;
/**
* @var bool Whether to allow file size validation.
*/
public bool $allowFileValidateSize = true;
/**
* @var bool Whether to allow image crop.
*/
public bool $allowImageCrop = false;
/**
* @var bool Whether to allow image exif orientation.
*/
public bool $allowImageExifOrientation = true;
/**
* @var bool Whether to allow image preview.
*/
public bool $allowImagePreview = true;
/**
* @var bool Whether to allow image transform.
*/
public bool $allowImageTransform = false;
/**
* @var bool Whether to allow multiple file upload.
*/
public bool $allowMultiple = false;
/**
* @var bool Whether to allow PDF preview.
*/
public bool $allowPdfPreview = false;
/**
* @var string The CSS class to add to the root element.
*/
public string $cssClass = '';
/**
* @var array The FilePond configuration.
*/
public bool $cdn = false;
public array $config = [];
/**
* @var string The environment to use.
*/
public string $environment = '';
/**
* @var string The file rename function.
*
* use: `fileRenameFunction: (file) => return `my_new_name${file.extension}`;
*/
public string $fileRename = '';
/**
* @var string The file validate type detect type function.
Expand All @@ -89,23 +44,14 @@ final class FilePond extends InputWidget
* @link https://pqina.nl/filepond/docs/api/plugins/file-validate-type/#custom-type-detection
*/
public string $fileValidateTypeDetectType = '';
/**
* @var string The file validate When message shown to indicate the allowed file types.
*/
public string $fileValidateTypeLabelExpectedTypes = '';
/**
* @var string The aspect ratio of the crop in human-readable format, for example, '1:1' or '16:10'.
*/
public string|null $imageCropAspectRatio = null;
/**
* @var string The image preview height.
*
* Fixed image preview height, overrides min and max preview height.
*/
public string|null $imagePreviewHeight = null;
/**
* @var bool Whether to show the image preview markup.
*/
public bool $imagePreviewMarkupShow = true;
/**
* @var string The image preview max file size.
Expand Down Expand Up @@ -178,9 +124,6 @@ final class FilePond extends InputWidget
* requirements (e.g. resize or crop).
*/
public string $imageTransformOutputQualityMode = 'always';
/**
* @var bool Whether to strip the image head.
*/
public bool $imageTransformOutputStripImageHead = true;
/**
* @var array The image transform variants.
Expand All @@ -206,49 +149,16 @@ final class FilePond extends InputWidget
* Should the transform plugin output the original file.
*/
public bool $imageTransformVariantsIncludeOriginal = false;
/**
* @var string The label to show when there are no files.
*/
public string $labelIdle = '';
/**
* @var string Label for max files size.
*/
public string $labelMaxFileSize = '';
/**
* @var string Label for max file size exceeded.
*/
public string $labelMaxFileSizeExceeded = '';
/**
* @var string Label for max total file size.
*/
public string $labelMaxTotalFileSize = '';
/**
* @var string Label for max total file size exceeded.
*/
public string $labelMaxTotalFileSizeExceeded = '';
/**
* @var string Label for a file type not allowed error.
*/
public string $labelFileTypeNotAllowed = '';
/**
* @var string The default file to load.
*/
public string $loadFileDefault = '';
/**
* @var int The maximum number of files allowed.
*/
public int $maxFiles = 1;
/**
* @var string The maximum file size allowed.
*/
public string|null $maxFileSize = null;
/**
* @var string The maximum total file size allowed.
*/
public string|null $maxTotalFileSize = null;
/**
* @var string The minimum file size allowed.
*/
public string|null $minFileSize = null;
/**
* @phpstan-var string[] The default plugins to load.
Expand All @@ -260,17 +170,8 @@ final class FilePond extends InputWidget
'FilePondPluginImageExifOrientation',
'FilePondPluginImagePreview',
];
/**
* @var int The pdf preview height.
*/
public int $pdfPreviewHeight = 320;
/**
* @var string The pdf component extra params.
*/
public string $pdfComponentExtraParams = 'toolbar=0&view=fit&page=1';
/**
* @var bool Whether the field is required.
*/
public bool $required = false;

private string $id = '';
Expand Down Expand Up @@ -378,12 +279,8 @@ private function registerClientScript(): void
{
$view = $this->getView();

if ($this->environment === '') {
$this->environment = YII_ENV;
}

match ($this->environment) {
'cdn' => FilePondCdnAsset::register($view),
match ($this->cdn) {
true => FilePondCdnAsset::register($view),
default => FilePondAsset::register($view),
};

Expand Down

0 comments on commit 4e1c8d8

Please sign in to comment.