native-document 1.0.190 → 1.0.192
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/CHANGELOG.md +1 -1
- package/docs/components/form/file-field.md +11 -11
- package/docs/components/form/image-field.md +5 -5
- package/docs/components/form-fields.md +1 -1
- package/package.json +1 -1
- package/src/components/form/field/types/FileField.js +18 -8
- package/src/components/form/field/types/file-field-mode/FileImagePreviewMode.js +275 -0
- package/src/components/form/index.js +2 -2
- package/src/components/form/types/fields/FileField.d.ts +3 -3
- package/src/components/form/types/fields/FileImagePreviewMode.d.ts +57 -0
- package/src/components/index.d.ts +1 -1
- package/src/core/data/ObservableObject.js +13 -0
- package/src/fetch/NativeFetch.js +5 -2
- package/src/ui/components/form/fields/NumberFieldRender.js +3 -5
- package/src/ui/components/form/file-upload-mode/FileImagePreviewModeRender.js +162 -0
- package/src/ui/components/form/file-upload-mode/{file-avatar-mode.css → file-image-preview-mode.css} +54 -23
- package/src/ui/components/form/index.js +1 -1
- package/types/observable.d.ts +1 -1
- package/src/components/form/field/types/file-field-mode/FileAvatarMode.js +0 -183
- package/src/components/form/types/fields/FileAvatarMode.d.ts +0 -46
- package/src/ui/components/form/file-upload-mode/FileAvatarModeRender.js +0 -143
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import {Div, Input, Span, Img, Button, Switch} from '../../../../../elements';
|
|
2
|
-
import { $ } from '../../../../core/data/Observable';
|
|
3
|
-
|
|
4
|
-
import './file-avatar-mode.css';
|
|
5
|
-
|
|
6
|
-
export default function FileAvatarModeRender($desc, modeInstance) {
|
|
7
|
-
const {$files, fieldDesc, fieldInstance} = $desc.$context;
|
|
8
|
-
const $preview = $(null);
|
|
9
|
-
|
|
10
|
-
const input = buildInput(fieldDesc, fieldInstance, $files, $preview);
|
|
11
|
-
|
|
12
|
-
const variant = $desc.variant || 'hover-overlay';
|
|
13
|
-
|
|
14
|
-
const avatar = buildAvatar($desc, $preview);
|
|
15
|
-
|
|
16
|
-
fieldInstance.onReset(() => $preview.set(null));
|
|
17
|
-
|
|
18
|
-
if(variant === 'hover-overlay') {
|
|
19
|
-
return buildHoverOverlay($desc, avatar, input, $files, modeInstance);
|
|
20
|
-
}
|
|
21
|
-
if(variant === 'corner-badge') {
|
|
22
|
-
return buildCornerBadge($desc, avatar, input, $files, modeInstance);
|
|
23
|
-
}
|
|
24
|
-
if(variant === 'action-buttons') {
|
|
25
|
-
return buildActionButtons($desc, avatar, input, $files, modeInstance, fieldInstance);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return avatar;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const buildInput = (fieldDesc, fieldInstance, $files, $preview) => {
|
|
32
|
-
const input = Input({
|
|
33
|
-
class: 'field-file-input',
|
|
34
|
-
type: 'file',
|
|
35
|
-
name: fieldDesc.name,
|
|
36
|
-
id: fieldDesc.id || fieldDesc.name,
|
|
37
|
-
accept: fieldDesc.accept || 'image/*',
|
|
38
|
-
disabled: fieldDesc.disabled,
|
|
39
|
-
style: {display: 'none'},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
fieldInstance.$input = input;
|
|
43
|
-
|
|
44
|
-
input.nd.onChange((e) => {
|
|
45
|
-
const file = e.target.files?.[0];
|
|
46
|
-
if(!file) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
fieldInstance.reset();
|
|
51
|
-
fieldInstance.addFile(file);
|
|
52
|
-
$preview.set(URL.createObjectURL(file));
|
|
53
|
-
|
|
54
|
-
input.value = '';
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return input;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const buildShapeClass = (defaultClass, $desc) => ({
|
|
62
|
-
[defaultClass]: true,
|
|
63
|
-
'is-circle': ($desc.shape || 'circle') === 'circle',
|
|
64
|
-
'is-square': ($desc.shape || 'circle') === 'square',
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const buildAvatar = ($desc, $preview) => {
|
|
68
|
-
const size = $desc.size || 100;
|
|
69
|
-
const shape = $desc.shape || 'circle';
|
|
70
|
-
const radius = shape === 'circle' ? '50%' : '12px';
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const previewImg = () => Img($preview, {
|
|
74
|
-
class: 'file-avatar-img',
|
|
75
|
-
alt: 'Avatar',
|
|
76
|
-
});
|
|
77
|
-
const placeholder = () => Div({class: 'file-avatar-placeholder'}, [
|
|
78
|
-
Span({class: 'file-avatar-placeholder-icon'}, $desc.placeholderIcon),
|
|
79
|
-
]);
|
|
80
|
-
|
|
81
|
-
return Div({
|
|
82
|
-
class: buildShapeClass('file-avatar', $desc),
|
|
83
|
-
style: { width: size + 'px', height: size + 'px' },
|
|
84
|
-
}, Switch($preview, previewImg, placeholder));
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const buildHoverOverlay = ($desc, avatar, input, $files, modeInstance) => {
|
|
88
|
-
let overlay = null;
|
|
89
|
-
if($desc.renderOverlay) {
|
|
90
|
-
overlay = $desc.renderOverlay(avatar, $desc, modeInstance);
|
|
91
|
-
} else {
|
|
92
|
-
overlay = Div({class: 'file-avatar-overlay'}, [
|
|
93
|
-
Span({class: 'file-avatar-overlay-icon'}, $desc.overlayIcon || $desc.editImageIcon),
|
|
94
|
-
]);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const wrapper = Div({
|
|
98
|
-
class: buildShapeClass('file-avatar-wrapper is-hover-overlay', $desc),
|
|
99
|
-
}, [avatar, overlay]);
|
|
100
|
-
|
|
101
|
-
wrapper.nd.onClick(() => input.click());
|
|
102
|
-
|
|
103
|
-
return Div({}, [input, wrapper]);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const buildCornerBadge = ($desc, avatar, input) => {
|
|
107
|
-
const badge = Div({class: 'file-avatar-badge'}, $desc.editImageIcon);
|
|
108
|
-
badge.nd.onClick(() => input.click());
|
|
109
|
-
|
|
110
|
-
return Div({}, [
|
|
111
|
-
input,
|
|
112
|
-
Div({
|
|
113
|
-
class: buildShapeClass('file-avatar-wrapper is-corner-badge', $desc),
|
|
114
|
-
}, [avatar, badge]),
|
|
115
|
-
]);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const buildActionButtons = ($desc, avatar, input, $files, modeInstance, fieldInstance) => {
|
|
119
|
-
if($desc.renderActions) {
|
|
120
|
-
return $desc.renderActions($desc, avatar, () => input.click(), () => removeAvatar($files, modeInstance, fieldInstance), modeInstance);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const changeBtn = Button({class: 'file-avatar-btn is-change'}, $desc.changeLabel);
|
|
124
|
-
changeBtn.nd.onClick(() => input.click());
|
|
125
|
-
|
|
126
|
-
const removeBtn = Button({class: 'file-avatar-btn is-remove'}, $desc.removeLabel);
|
|
127
|
-
removeBtn.nd.onClick(() => removeAvatar($files, modeInstance, fieldInstance));
|
|
128
|
-
|
|
129
|
-
return Div({class: 'file-avatar-action-wrapper'}, [
|
|
130
|
-
input,
|
|
131
|
-
avatar,
|
|
132
|
-
Div({class: 'file-avatar-actions'}, [changeBtn, removeBtn]),
|
|
133
|
-
]);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const removeAvatar = ($files, modeInstance, fieldInstance) => {
|
|
137
|
-
const item = $files.val()?.[0];
|
|
138
|
-
fieldInstance.reset();
|
|
139
|
-
if(item) {
|
|
140
|
-
modeInstance.emit('remove', item);
|
|
141
|
-
item.emit('remove', item);
|
|
142
|
-
}
|
|
143
|
-
};
|