Skip to content

Commit

Permalink
add beforePrepareOutput hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rikschennink committed Dec 14, 2020
1 parent 6bcfe7e commit 2c4e4fb
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.25.0

- Add `beforePrepareOutput` hook to intercept and prevent preparing a new output file.


## 4.24.0

- Add action info to internal `SHOULD_PREPARE_OUTPUT` call
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.24.0
* FilePond 4.25.0
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down
24 changes: 20 additions & 4 deletions dist/filepond.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.24.0
* FilePond 4.25.0
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -2011,6 +2011,7 @@ const defaultOptions = {
beforeDropFile: [null, Type.FUNCTION],
beforeAddFile: [null, Type.FUNCTION],
beforeRemoveFile: [null, Type.FUNCTION],
beforePrepareOutput: [null, Type.FUNCTION],

// styles
stylePanelLayout: [null, Type.STRING], // null 'integrated', 'compact', 'circle'
Expand Down Expand Up @@ -4195,9 +4196,16 @@ const actions = (dispatch, query, state) => ({
query,
action
}).then(shouldPrepareOutput => {
if (!shouldPrepareOutput) {
return;
}
// plugins determined the output data should be prepared (or not), can be adjusted with beforePrepareOutput hook
const beforePrepareOutput = query('GET_BEFORE_PREPARE_OUTPUT');
if (beforePrepareOutput)
shouldPrepareOutput = beforePrepareOutput(
item,
shouldPrepareOutput
);

if (!shouldPrepareOutput) return;

dispatch(
'REQUEST_PREPARE_OUTPUT',
{
Expand Down Expand Up @@ -4540,6 +4548,14 @@ const actions = (dispatch, query, state) => ({
// means we'll do this and wait for idle state
applyFilterChain('SHOULD_PREPARE_OUTPUT', false, { item, query }).then(
shouldPrepareOutput => {
// plugins determined the output data should be prepared (or not), can be adjusted with beforePrepareOutput hook
const beforePrepareOutput = query('GET_BEFORE_PREPARE_OUTPUT');
if (beforePrepareOutput)
shouldPrepareOutput = beforePrepareOutput(
item,
shouldPrepareOutput
);

const loadComplete = () => {
dispatch('COMPLETE_LOAD_ITEM', {
query: id,
Expand Down
4 changes: 2 additions & 2 deletions dist/filepond.esm.min.js

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions dist/filepond.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.24.0
* FilePond 4.25.0
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -4051,6 +4051,7 @@
beforeDropFile: [null, Type.FUNCTION],
beforeAddFile: [null, Type.FUNCTION],
beforeRemoveFile: [null, Type.FUNCTION],
beforePrepareOutput: [null, Type.FUNCTION],

// styles
stylePanelLayout: [null, Type.STRING], // null 'integrated', 'compact', 'circle'
Expand Down Expand Up @@ -6630,9 +6631,16 @@
query: query,
action: action
}).then(function(shouldPrepareOutput) {
if (!shouldPrepareOutput) {
return;
}
// plugins determined the output data should be prepared (or not), can be adjusted with beforePrepareOutput hook
var beforePrepareOutput = query('GET_BEFORE_PREPARE_OUTPUT');
if (beforePrepareOutput)
shouldPrepareOutput = beforePrepareOutput(
item,
shouldPrepareOutput
);

if (!shouldPrepareOutput) return;

dispatch(
'REQUEST_PREPARE_OUTPUT',
{
Expand Down Expand Up @@ -6998,6 +7006,14 @@
item: item,
query: query
}).then(function(shouldPrepareOutput) {
// plugins determined the output data should be prepared (or not), can be adjusted with beforePrepareOutput hook
var beforePrepareOutput = query('GET_BEFORE_PREPARE_OUTPUT');
if (beforePrepareOutput)
shouldPrepareOutput = beforePrepareOutput(
item,
shouldPrepareOutput
);

var loadComplete = function loadComplete() {
dispatch('COMPLETE_LOAD_ITEM', {
query: id,
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/filepond.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filepond",
"version": "4.24.0",
"version": "4.25.0",
"description": "FilePond, Where files go to stretch their bits.",
"license": "MIT",
"author": {
Expand Down
14 changes: 11 additions & 3 deletions src/js/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ export const actions = (dispatch, query, state) => ({
// should we update the output data
applyFilterChain('SHOULD_PREPARE_OUTPUT', false, { item, query, action })
.then(shouldPrepareOutput => {
if (!shouldPrepareOutput) {
return;
}

// plugins determined the output data should be prepared (or not), can be adjusted with beforePrepareOutput hook
const beforePrepareOutput = query('GET_BEFORE_PREPARE_OUTPUT');
if (beforePrepareOutput) shouldPrepareOutput = beforePrepareOutput(item, shouldPrepareOutput);

if (!shouldPrepareOutput) return;

dispatch('REQUEST_PREPARE_OUTPUT', {
query: id,
item,
Expand Down Expand Up @@ -475,6 +479,10 @@ export const actions = (dispatch, query, state) => ({
applyFilterChain('SHOULD_PREPARE_OUTPUT', false, { item, query })
.then(shouldPrepareOutput => {

// plugins determined the output data should be prepared (or not), can be adjusted with beforePrepareOutput hook
const beforePrepareOutput = query('GET_BEFORE_PREPARE_OUTPUT');
if (beforePrepareOutput) shouldPrepareOutput = beforePrepareOutput(item, shouldPrepareOutput);

const loadComplete = () => {

dispatch('COMPLETE_LOAD_ITEM', {
Expand Down
1 change: 1 addition & 0 deletions src/js/app/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const defaultOptions = {
beforeDropFile: [null, Type.FUNCTION],
beforeAddFile: [null, Type.FUNCTION],
beforeRemoveFile: [null, Type.FUNCTION],
beforePrepareOutput: [null, Type.FUNCTION],

// styles
stylePanelLayout: [null, Type.STRING], // null 'integrated', 'compact', 'circle'
Expand Down

0 comments on commit 2c4e4fb

Please sign in to comment.