stalefish 7.4.5 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/components/panel.mjs +1 -1
- package/components/uploader.mjs +43 -54
- package/package.json +3 -4
package/README.md
CHANGED
package/components/panel.mjs
CHANGED
package/components/uploader.mjs
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { html, css, fieldIsTouched
|
|
2
|
-
import raw from 'nanohtml/raw.js'
|
|
3
|
-
import * as deepDiff from 'deep-object-diff'
|
|
4
|
-
import clone from 'fast-clone'
|
|
1
|
+
import { html, css, fieldIsTouched } from 'halfcab'
|
|
5
2
|
import uploadIcon from './icons/upload.mjs'
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let styles = css`
|
|
4
|
+
const styles = css`
|
|
10
5
|
.uploader {
|
|
11
6
|
margin: 0 10px 0 20px !important;
|
|
12
7
|
position: absolute;
|
|
@@ -81,55 +76,49 @@ let styles = css`
|
|
|
81
76
|
outline: red solid 2px;
|
|
82
77
|
}
|
|
83
78
|
`
|
|
79
|
+
/**
|
|
80
|
+
* Functional uploader component compatible with halfcab's lit-html base.
|
|
81
|
+
* No internal instance caching; simply returns a template.
|
|
82
|
+
*/
|
|
83
|
+
export default function uploader (args) {
|
|
84
|
+
const {
|
|
85
|
+
wrapperStyle,
|
|
86
|
+
holdingPen,
|
|
87
|
+
label,
|
|
88
|
+
property,
|
|
89
|
+
required,
|
|
90
|
+
disabled,
|
|
91
|
+
accept,
|
|
92
|
+
imagePreview,
|
|
93
|
+
disableClear,
|
|
94
|
+
placeholder,
|
|
95
|
+
permanentTopLabel,
|
|
96
|
+
permanentTopPlaceholder,
|
|
97
|
+
textPreview,
|
|
98
|
+
progress,
|
|
99
|
+
onchange,
|
|
100
|
+
onclear
|
|
101
|
+
} = args
|
|
84
102
|
|
|
85
|
-
class
|
|
86
|
-
createElement (args) {
|
|
87
|
-
this.args = clone(args)
|
|
88
|
-
this.onchange = args.onchange
|
|
89
|
-
this.onclear = args.onclear
|
|
90
|
-
let { wrapperStyle, holdingPen, label, property, required, disabled, accept, imagePreview, disableClear, placeholder, permanentTopLabel, permanentTopPlaceholder, textPreview, progress } = args
|
|
91
|
-
|
|
92
|
-
let uploaderEl = html`<input data-gramm="false" ${disabled ? { disabled } : ''} style="${disabled ? 'cursor: not-allowed;' : ''}" class="${styles.uploader} ${fieldIsTouched(holdingPen, property) === true ? styles.touched : ''}" onchange=${this.onchange} type="file" ${required ? { required: 'required' } : ''} ${accept ? { accept } : ''} hidden />`
|
|
103
|
+
const uploaderEl = html`<input data-gramm="false" ${disabled ? { disabled } : ''} style="${disabled ? 'cursor: not-allowed;' : ''}" class="${styles.uploader} ${fieldIsTouched(holdingPen, property) === true ? styles.touched : ''}" onchange=${onchange} type="file" ${required ? { required: 'required' } : ''} ${accept ? { accept } : ''} hidden />`
|
|
93
104
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
<span class="${styles.frame}"
|
|
105
|
+
return html`
|
|
106
|
+
<div ${wrapperStyle ? { class: wrapperStyle } : ''} style="display: inline-block; width: 100%; margin-top: 36px;">
|
|
107
|
+
<label style="width: 100%; text-align: left; position: relative; padding: 0; cursor: pointer;">
|
|
108
|
+
${label ? html`<span class="${styles.label}" style="opacity: ${holdingPen[property] === 0 || holdingPen[property] || (permanentTopPlaceholder || permanentTopLabel) ? 1 : 0};">${label}${required ? ' *' : ''}</span>` : ''}
|
|
109
|
+
<span class="${styles.frame}">
|
|
110
|
+
${!holdingPen[property]
|
|
111
|
+
? html`${placeholder}${required ? ' *' : ''}`
|
|
112
|
+
: !imagePreview
|
|
113
|
+
? (textPreview || holdingPen[property])
|
|
114
|
+
: '\u00A0'}
|
|
115
|
+
${uploaderEl}
|
|
116
|
+
<span style="opacity: 0.6; margin-left: -12px; width: ${progress}%; position: absolute; background-color: #EEE; height: 100%;"></span>
|
|
117
|
+
</span>
|
|
99
118
|
${imagePreview ? html`<img src="${imagePreview}" style="position: absolute; height: 35px; top: -9px; left: 20px; z-index: 30;"/>` : ''}
|
|
100
|
-
|
|
119
|
+
${!disableClear ? html`<div class="${styles.clear}" onclick=${onclear}>clear</div>` : ''}
|
|
101
120
|
<div class="${styles.icon}">${uploadIcon({ colour: '#ccc', width: 28, height: 28 })}</div>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
update (args) {
|
|
108
|
-
let diff = deepDiff.diff(this.args, args)
|
|
109
|
-
Object.keys(diff).forEach(key => {
|
|
110
|
-
if (typeof diff[key] === 'function') {
|
|
111
|
-
this[key] = args[key]
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
return !!Object.keys(diff).find(key => typeof diff[key] !== 'function')
|
|
115
|
-
}
|
|
121
|
+
</label>
|
|
122
|
+
</div>
|
|
123
|
+
`
|
|
116
124
|
}
|
|
117
|
-
|
|
118
|
-
function uploader (args) {
|
|
119
|
-
let instance
|
|
120
|
-
if (args.uniqueKey) {
|
|
121
|
-
let found = cache.get(args.uniqueKey)
|
|
122
|
-
if (found) {
|
|
123
|
-
instance = found
|
|
124
|
-
} else {
|
|
125
|
-
instance = new Uploader()
|
|
126
|
-
cache.set(args.uniqueKey, instance)
|
|
127
|
-
}
|
|
128
|
-
return instance.render(args)
|
|
129
|
-
} else {
|
|
130
|
-
instance = new Uploader()
|
|
131
|
-
return instance.createElement(args)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export default args => uploader(args)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stalefish",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Simple function based component library for halfcab tagged template literals",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "npm run test:lint",
|
|
10
10
|
"test:lint": "standard \"**/*.mjs\"",
|
|
11
|
-
"npm-publish": "npm publish",
|
|
11
|
+
"npm-publish": "npm publish -tag beta",
|
|
12
12
|
"versionbump:fix": "npm version patch --no-git-tag-version",
|
|
13
13
|
"versionbump:feature": "npm version minor --no-git-tag-version",
|
|
14
14
|
"versionbump:breakingchanges": "npm version major --no-git-tag-version"
|
|
@@ -19,10 +19,9 @@
|
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"halfcab",
|
|
22
|
-
"nanohtml",
|
|
23
22
|
"components",
|
|
24
23
|
"css",
|
|
25
|
-
"
|
|
24
|
+
"lit-html"
|
|
26
25
|
],
|
|
27
26
|
"author": "Loren Greenfield",
|
|
28
27
|
"license": "MIT",
|