Skip to content

Commit

Permalink
Merge branch 'release/0.4.2-beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelerchian committed Jun 4, 2017
2 parents 1593de6 + 4655ada commit fb39318
Show file tree
Hide file tree
Showing 16 changed files with 47,116 additions and 202 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Caretaker v0.4.1-beta
# Caretaker v0.4.2-beta

A Javascript library for making a new breed of structured HTML5 Form

## What's New in 0.4.1?
## What's New in 0.4.2?

Customizable Request Header.
Customizable Request Header. Image and TextareaHTML extension now separated.

## What is Caretaker?

Expand Down Expand Up @@ -316,6 +316,11 @@ Note: Files uploaded will be put in the array `files`. The main body, which is a

Coming soon. If you're interested, see _[src_extension/caretaker_form_input_image.js](src_extension/caretaker_form_input_image.js)_

## Built-In Extension

- Textarea-html: Edit HTML using Facebook's DraftJS Rich Text Editor
- Image: Upload Image files with preview

## Planned Features

- [x] Extension - Image input
Expand Down
40 changes: 27 additions & 13 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ path.delimiter = "/"

function lookIntoFolder(dir, intendedExtension){
var sources = []
var folderContent = fs.readdirSync( path.resolve(__dirname, dir) )
var folderContent = fs.readdirSync( dir )
folderContent.forEach(function( filename ){
var filepath = "./"+ dir+"/"+ filename
var filepath = dir+"/"+ filename
filepath = filepath.replace(/\\/gi, "/")
var stat = fs.lstatSync( filepath )
if(stat.isFile()){
Expand All @@ -24,14 +24,11 @@ function lookIntoFolder(dir, intendedExtension){
return sources
}

var javascriptSource = lookIntoFolder("src", "js")
var cssSource = lookIntoFolder("src", "css")
var javascriptSource = lookIntoFolder(path.resolve(__dirname, "src"), "js")
var cssSource = lookIntoFolder(path.resolve(__dirname, "src"), "css")

var javascriptExtensionSource = lookIntoFolder("src_extension", "js")
var cssExtensionSource = lookIntoFolder("src_extension", "css")

console.log("Main Files:", javascriptSource, cssSource)
console.log("Extension Files:", javascriptExtensionSource, cssExtensionSource)

gulp.src(javascriptSource)
.pipe(concat('caretaker.js'))
Expand All @@ -41,10 +38,27 @@ gulp.src(cssSource)
.pipe(concat('caretaker.css'))
.pipe(gulp.dest("dist"))

gulp.src(javascriptExtensionSource)
.pipe(concat('caretaker.extension.js'))
.pipe(gulp.dest("dist"))
var extension_path = path.resolve(__dirname, "src_extension")
var extension_folders = fs.readdirSync( extension_path )
console.log("Compiling Extensions: ")
extension_folders.forEach(function(filename){

gulp.src(cssExtensionSource)
.pipe(concat('caretaker.extension.css'))
.pipe(gulp.dest("dist"))
var folderDir = path.resolve(extension_path,filename)
var stat = fs.lstatSync( folderDir )
if(stat.isDirectory()){
var jsFiles = lookIntoFolder( folderDir, "js" )
var cssFiles = lookIntoFolder( folderDir, "css")

console.log("compiling "+filename+" :")
console.log(jsFiles, cssFiles)

gulp.src(jsFiles)
.pipe(concat('caretaker.extension.'+filename+'.js'))
.pipe(gulp.dest("dist/"+filename))

gulp.src(cssFiles)
.pipe(concat('caretaker.extension.'+filename+'.css'))
.pipe(gulp.dest("dist/"+filename))
}
})
console.log("Extensions compiled")
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions dist/image/caretaker.extension.image.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.CaretakerFormInputFilePreview > img{
max-height: 50vh;
height: auto;
width: 100%;
object-fit: contain;
background: #111;
border: 1px solid rgba(0,0,0,0.3);
}

.CaretakerFormInputImage .CaretakerButton{
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
170 changes: 170 additions & 0 deletions dist/image/caretaker.extension.image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
* Explanation: the first parameter 'image'
* will be used when you pass object
*
* {
* type: "image",
* name: "your image",
* ...etcetera etcetera
* }
*
*
*
* I assume you have a good understanding using React to extend the FormInput
*
*/
class CaretakerFormInputImage extends CaretakerFormInputPrototype{

/*
* Extended function
* This is not needed if you are going to return null anyway, but you can change your defaultValue this way.
* This value will be overwritten by your data
*/
getDefaultValue(){
return false
}

/*
* Extended function
* It is called when default value is assigned to this.state.value
* default is "return true" so it's kinda useless on default
*/
loadedValueIsValid(value){
if(value instanceof Caretaker.UploadedFile){
return true
}else if(typeof value == "object" && value && value.link != null){
return true
}else if(value == false){ //don't forget to include your defaultValue
return true
}
return false
}

/**
* Extended function
*/
checkValidity(value){
if(this.isRequired() && value === false){
return ["An image must be selected"]
}
return true
}


/*
* Extended Function
* The parameter is absolutely yours to decide.
* IMPORTANT:
* - this.state.value is an important variable, you must save your value in this variable, if you want this pushed to your whole form value
* - you should remember to call this.updateParent() this handles the value pushing mechanism and the this.setState()
* - don't judge me on the absent of this.setState() function call
*/
onChange(value){
this.state.value = value
this.updateParent()
var setState = this.setState.bind(this)
var onRemove = this.onRemove.bind(this)
Caretaker.Utils.getBase64Async(this.state.value.getOriginalFile(),
function(result){ //OnSuccess
setState({
imageData: result
})
},
function(error){
onRemove()
}
)
}

/*
* Not an extended function
*/
onRemove(){
this.state.value = false
this.state.imageData = null
this.updateParent()
}

/*
* Not an Extended Function
* I assign this function when upload button is pressed so that it will trigger the promptUpload
*/
onWillPrompt(){
// The promptUpload will trigger upload dialog
// This is CaretakerCore function not intended for you to use
Caretaker.UploadedFile.promptUpload( this.onChange.bind(this), this.getProps() )
}

/**
* modifyProps and getRemovedPropKeys is extended function
* This is defaultValue to show you what it contains, no changes in it
*/
getRemovedPropKeys(){
//the keys which will be deleted when passed
return ["value","values","defaultValue"]
}
modifyProps(props){
props.accept = "image/*"
}

/*
* Not an extended function
* My style of coding, don't follow if you don't agree
* Making render function uncluttered
*/
appearanceGetControl(){
//Don't forget to handle all your state
if(this.state.value === false){
var control = []
control.push(React.createElement('button', {className: this.appearanceProtoGetClassName("button","CaretakerButton CaretakerFormInputFilePromptButton") , key:"selectButton", type:"button", onClick: this.onWillPrompt.bind(this)}, "Select Image..."))
if(this.props.placeholder){
control.push(React.createElement('div', {className: this.appearanceProtoGetClassName("div", "CaretakerFormInputFilePreview"), key:"preview"}, (
React.createElement('img', {src:this.props.placeholder, className: this.appearanceProtoGetClassName("img", "CaretakerFormInputFilePreviewImage"), title:"placeholder", alt:"placeholder"})
)))
}
return control

}else if(this.state.value instanceof Caretaker.UploadedFile){
var previewProps = {
title:this.state.value.getName(),
alt:this.state.value.getName(),
className: this.appearanceProtoGetClassName("img", "CaretakerFormInputFilePreviewImage")
}
if(this.state.imageData){
previewProps.src = this.state.imageData
}
return [
React.createElement('button', {className: this.appearanceProtoGetClassName("button", "CaretakerButton CaretakerFormInputFileRemoveButton"), type:"button", key:"removeButton", onClick: this.onRemove.bind(this)}, [React.createElement('i', {className: this.appearanceProtoGetClassName("i", "fa fa-remove"), key:"icon"}),"Remove"]),
React.createElement('button', {className: this.appearanceProtoGetClassName("button", "CaretakerButton CaretakerFormInputFileChangeButton"), type:"button", key:"changeButton", onClick: this.onWillPrompt.bind(this)}, [React.createElement('i',{className: this.appearanceProtoGetClassName("i", "fa fa-edit"), key:"icon"}), "Change..."]),
React.createElement('div', {className: this.appearanceProtoGetClassName("div", "CaretakerFormInputFilePreview"), key:"preview"}, (
React.createElement('img', previewProps)
))
]
}else if(typeof this.state.value == "object"){
var link = this.state.value.link || ""
return [
React.createElement('button', {className: this.appearanceProtoGetClassName("button", "CaretakerButton CaretakerFormInputFileRemoveButton"), type:"button", key:"removeButton", onClick: this.onRemove.bind(this)}, [React.createElement('i', {className: this.appearanceProtoGetClassName("i", "fa fa-remove"), key:"icon"}),"Remove"] ),
React.createElement('button', {className: this.appearanceProtoGetClassName("button", "CaretakerButton CaretakerFormInputFileChangeButton"), type:"button", key:"changeButton", onClick: this.onWillPrompt.bind(this)}, [React.createElement('i',{className: this.appearanceProtoGetClassName("i", "fa fa-edit"), key:"icon"}), "Change..."] ),
React.createElement('div', {className: this.appearanceProtoGetClassName("div","CaretakerFormInputFilePreview"), key:"preview"}, (
React.createElement('img', {src: link, title: link, alt: link, className: this.appearanceProtoGetClassName("img", "CaretakerFormInputFilePreviewImage")})
))
]
}
}

/*
*/
render(){
return React.createElement('div',{className: "CaretakerFormInputImage "+(this.props.name || "")}, this.appearanceGetControl())
}
}

/*
* Install your SpecialInput
* This way:
*/
Caretaker.SpecialInput.register('image',CaretakerFormInputImage)

/*
* Additional Notes: you might want to see CaretakerFormInputPrototype class
*/
Loading

0 comments on commit fb39318

Please sign in to comment.