decap-cms-widget-file 3.4.0 → 3.5.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/CHANGELOG.md +4 -0
- package/dist/decap-cms-widget-file.js +2 -2
- package/dist/decap-cms-widget-file.js.LICENSE.txt +19 -0
- package/dist/decap-cms-widget-file.js.map +1 -1
- package/dist/esm/FilePreview.js +20 -16
- package/dist/esm/withFileControl.js +102 -72
- package/package.json +2 -2
- package/src/FilePreview.js +0 -1
package/dist/esm/FilePreview.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import _styled from "@emotion/styled/base";
|
|
2
2
|
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
|
|
3
|
-
import React from 'react';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
5
4
|
import { List } from 'immutable';
|
|
6
5
|
import { WidgetPreviewContainer } from 'decap-cms-ui-default';
|
|
7
|
-
import { jsx as
|
|
6
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
8
7
|
const FileLink = /*#__PURE__*/_styled(({
|
|
9
8
|
href,
|
|
10
9
|
path
|
|
11
|
-
}) =>
|
|
10
|
+
}) => _jsx("a", {
|
|
12
11
|
href: href,
|
|
13
12
|
rel: "noopener noreferrer",
|
|
14
|
-
target: "_blank"
|
|
15
|
-
|
|
13
|
+
target: "_blank",
|
|
14
|
+
children: path
|
|
15
|
+
}), {
|
|
16
16
|
target: "ecp3s3o0",
|
|
17
17
|
label: "FileLink"
|
|
18
18
|
})(process.env.NODE_ENV === "production" ? {
|
|
@@ -20,7 +20,7 @@ const FileLink = /*#__PURE__*/_styled(({
|
|
|
20
20
|
styles: "display:block"
|
|
21
21
|
} : {
|
|
22
22
|
name: "4zleql",
|
|
23
|
-
styles: "display:block/*# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
23
|
+
styles: "display:block/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9GaWxlUHJldmlldy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFTRSIsImZpbGUiOiIuLi8uLi9zcmMvRmlsZVByZXZpZXcuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgUHJvcFR5cGVzIGZyb20gJ3Byb3AtdHlwZXMnO1xuaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnO1xuaW1wb3J0IHsgTGlzdCB9IGZyb20gJ2ltbXV0YWJsZSc7XG5pbXBvcnQgeyBXaWRnZXRQcmV2aWV3Q29udGFpbmVyIH0gZnJvbSAnZGVjYXAtY21zLXVpLWRlZmF1bHQnO1xuXG5jb25zdCBGaWxlTGluayA9IHN0eWxlZCgoeyBocmVmLCBwYXRoIH0pID0+IChcbiAgPGEgaHJlZj17aHJlZn0gcmVsPVwibm9vcGVuZXIgbm9yZWZlcnJlclwiIHRhcmdldD1cIl9ibGFua1wiPlxuICAgIHtwYXRofVxuICA8L2E+XG4pKWBcbiAgZGlzcGxheTogYmxvY2s7XG5gO1xuXG5mdW5jdGlvbiBGaWxlTGlua0xpc3QoeyB2YWx1ZXMsIGdldEFzc2V0LCBmaWVsZCB9KSB7XG4gIHJldHVybiAoXG4gICAgPGRpdj5cbiAgICAgIHt2YWx1ZXMubWFwKHZhbHVlID0+IChcbiAgICAgICAgPEZpbGVMaW5rIGtleT17dmFsdWV9IHBhdGg9e3ZhbHVlfSBocmVmPXtnZXRBc3NldCh2YWx1ZSwgZmllbGQpfSAvPlxuICAgICAgKSl9XG4gICAgPC9kaXY+XG4gICk7XG59XG5cbmZ1bmN0aW9uIEZpbGVDb250ZW50KHByb3BzKSB7XG4gIGNvbnN0IHsgdmFsdWUsIGdldEFzc2V0LCBmaWVsZCB9ID0gcHJvcHM7XG4gIGlmIChBcnJheS5pc0FycmF5KHZhbHVlKSB8fCBMaXN0LmlzTGlzdCh2YWx1ZSkpIHtcbiAgICByZXR1cm4gPEZpbGVMaW5rTGlzdCB2YWx1ZXM9e3ZhbHVlfSBnZXRBc3NldD17Z2V0QXNzZXR9IGZpZWxkPXtmaWVsZH0gLz47XG4gIH1cbiAgcmV0dXJuIDxGaWxlTGluayBrZXk9e3ZhbHVlfSBwYXRoPXt2YWx1ZX0gaHJlZj17Z2V0QXNzZXQodmFsdWUsIGZpZWxkKX0gLz47XG59XG5cbmZ1bmN0aW9uIEZpbGVQcmV2aWV3KHByb3BzKSB7XG4gIHJldHVybiAoXG4gICAgPFdpZGdldFByZXZpZXdDb250YWluZXI+XG4gICAgICB7cHJvcHMudmFsdWUgPyA8RmlsZUNvbnRlbnQgey4uLnByb3BzfSAvPiA6IG51bGx9XG4gICAgPC9XaWRnZXRQcmV2aWV3Q29udGFpbmVyPlxuICApO1xufVxuXG5GaWxlUHJldmlldy5wcm9wVHlwZXMgPSB7XG4gIGdldEFzc2V0OiBQcm9wVHlwZXMuZnVuYy5pc1JlcXVpcmVkLFxuICB2YWx1ZTogUHJvcFR5cGVzLm5vZGUsXG59O1xuXG5leHBvcnQgZGVmYXVsdCBGaWxlUHJldmlldztcbiJdfQ== */",
|
|
24
24
|
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
25
25
|
});
|
|
26
26
|
function FileLinkList({
|
|
@@ -28,11 +28,12 @@ function FileLinkList({
|
|
|
28
28
|
getAsset,
|
|
29
29
|
field
|
|
30
30
|
}) {
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
return _jsx("div", {
|
|
32
|
+
children: values.map(value => _jsx(FileLink, {
|
|
33
|
+
path: value,
|
|
34
|
+
href: getAsset(value, field)
|
|
35
|
+
}, value))
|
|
36
|
+
});
|
|
36
37
|
}
|
|
37
38
|
function FileContent(props) {
|
|
38
39
|
const {
|
|
@@ -41,20 +42,23 @@ function FileContent(props) {
|
|
|
41
42
|
field
|
|
42
43
|
} = props;
|
|
43
44
|
if (Array.isArray(value) || List.isList(value)) {
|
|
44
|
-
return
|
|
45
|
+
return _jsx(FileLinkList, {
|
|
45
46
|
values: value,
|
|
46
47
|
getAsset: getAsset,
|
|
47
48
|
field: field
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
|
-
return
|
|
51
|
-
key: value,
|
|
51
|
+
return _jsx(FileLink, {
|
|
52
52
|
path: value,
|
|
53
53
|
href: getAsset(value, field)
|
|
54
|
-
});
|
|
54
|
+
}, value);
|
|
55
55
|
}
|
|
56
56
|
function FilePreview(props) {
|
|
57
|
-
return
|
|
57
|
+
return _jsx(WidgetPreviewContainer, {
|
|
58
|
+
children: props.value ? _jsx(FileContent, {
|
|
59
|
+
...props
|
|
60
|
+
}) : null
|
|
61
|
+
});
|
|
58
62
|
}
|
|
59
63
|
FilePreview.propTypes = {
|
|
60
64
|
getAsset: PropTypes.func.isRequired,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _styled from "@emotion/styled/base";
|
|
2
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
2
|
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
|
|
4
3
|
import React, { useEffect, useState } from 'react';
|
|
5
4
|
import PropTypes from 'prop-types';
|
|
@@ -15,7 +14,7 @@ import { DndContext, MouseSensor, TouchSensor, closestCenter, useSensor, useSens
|
|
|
15
14
|
import { SortableContext, useSortable } from '@dnd-kit/sortable';
|
|
16
15
|
import { CSS } from '@dnd-kit/utilities';
|
|
17
16
|
import { restrictToParentElement } from '@dnd-kit/modifiers';
|
|
18
|
-
import { jsx as
|
|
17
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
19
18
|
const MAX_DISPLAY_LENGTH = 50;
|
|
20
19
|
const ImageWrapper = /*#__PURE__*/_styled("div", {
|
|
21
20
|
target: "e1hax4ql7",
|
|
@@ -57,7 +56,7 @@ function Image({
|
|
|
57
56
|
setAsset(null);
|
|
58
57
|
}
|
|
59
58
|
}, [value, field, getAsset]);
|
|
60
|
-
return asset ?
|
|
59
|
+
return asset ? _jsx(StyledImage, {
|
|
61
60
|
role: "presentation",
|
|
62
61
|
src: asset
|
|
63
62
|
}) : null;
|
|
@@ -66,15 +65,17 @@ function SortableImageButtons({
|
|
|
66
65
|
onRemove,
|
|
67
66
|
onReplace
|
|
68
67
|
}) {
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
return _jsxs(SortableImageButtonsWrapper, {
|
|
69
|
+
children: [_jsx(IconButton, {
|
|
70
|
+
size: "small",
|
|
71
|
+
type: "media",
|
|
72
|
+
onClick: onReplace
|
|
73
|
+
}), _jsx(IconButton, {
|
|
74
|
+
size: "small",
|
|
75
|
+
type: "close",
|
|
76
|
+
onClick: onRemove
|
|
77
|
+
})]
|
|
78
|
+
});
|
|
78
79
|
}
|
|
79
80
|
function SortableImage(props) {
|
|
80
81
|
const {
|
|
@@ -97,20 +98,24 @@ function SortableImage(props) {
|
|
|
97
98
|
onRemove,
|
|
98
99
|
onReplace
|
|
99
100
|
} = props;
|
|
100
|
-
return
|
|
101
|
+
return _jsxs("div", {
|
|
101
102
|
ref: setNodeRef,
|
|
102
|
-
style: style
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
style: style,
|
|
104
|
+
...attributes,
|
|
105
|
+
...listeners,
|
|
106
|
+
children: [_jsx(ImageWrapper, {
|
|
107
|
+
sortable: true,
|
|
108
|
+
children: _jsx(Image, {
|
|
109
|
+
value: itemValue,
|
|
110
|
+
field: field,
|
|
111
|
+
getAsset: getAsset
|
|
112
|
+
})
|
|
113
|
+
}), _jsx(SortableImageButtons, {
|
|
114
|
+
item: itemValue,
|
|
115
|
+
onRemove: onRemove,
|
|
116
|
+
onReplace: onReplace
|
|
117
|
+
})]
|
|
118
|
+
});
|
|
114
119
|
}
|
|
115
120
|
var _ref = process.env.NODE_ENV === "production" ? {
|
|
116
121
|
name: "a42x49-SortableMultiImageWrapper",
|
|
@@ -145,26 +150,28 @@ function SortableMultiImageWrapper({
|
|
|
145
150
|
newIndex: items.findIndex(item => item.id === over.id)
|
|
146
151
|
});
|
|
147
152
|
}
|
|
148
|
-
return
|
|
153
|
+
return _jsx("div", {
|
|
149
154
|
// eslint-disable-next-line react/no-unknown-property
|
|
150
|
-
css: _ref
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
155
|
+
css: _ref,
|
|
156
|
+
children: _jsx(DndContext, {
|
|
157
|
+
modifiers: [restrictToParentElement],
|
|
158
|
+
collisionDetection: closestCenter,
|
|
159
|
+
sensors: sensors,
|
|
160
|
+
onDragEnd: handleSortEnd,
|
|
161
|
+
children: _jsx(SortableContext, {
|
|
162
|
+
items: items,
|
|
163
|
+
children: items.map((item, index) => _jsx(SortableImage, {
|
|
164
|
+
id: item.id,
|
|
165
|
+
index: index,
|
|
166
|
+
itemValue: item.value,
|
|
167
|
+
getAsset: getAsset,
|
|
168
|
+
field: field,
|
|
169
|
+
onRemove: onRemoveOne(index),
|
|
170
|
+
onReplace: onReplaceOne(index)
|
|
171
|
+
}, item.id))
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
});
|
|
168
175
|
}
|
|
169
176
|
const FileLink = /*#__PURE__*/_styled("a", {
|
|
170
177
|
target: "e1hax4ql4",
|
|
@@ -394,22 +401,29 @@ export default function withFileControl({
|
|
|
394
401
|
return value;
|
|
395
402
|
}
|
|
396
403
|
const text = `${value.slice(0, size / 2)}\u2026${value.slice(-(size / 2) + 1)}`;
|
|
397
|
-
return
|
|
404
|
+
return _jsx(FileLink, {
|
|
398
405
|
href: value,
|
|
399
406
|
rel: "noopener",
|
|
400
|
-
target: "_blank"
|
|
401
|
-
|
|
407
|
+
target: "_blank",
|
|
408
|
+
children: text
|
|
409
|
+
});
|
|
402
410
|
};
|
|
403
411
|
renderFileLinks = () => {
|
|
404
412
|
const {
|
|
405
413
|
value
|
|
406
414
|
} = this.props;
|
|
407
415
|
if (isMultiple(value)) {
|
|
408
|
-
return
|
|
409
|
-
|
|
410
|
-
|
|
416
|
+
return _jsx(FileLinks, {
|
|
417
|
+
children: _jsx(FileLinkList, {
|
|
418
|
+
children: value.map(val => _jsx("li", {
|
|
419
|
+
children: this.renderFileLink(val)
|
|
420
|
+
}, val))
|
|
421
|
+
})
|
|
422
|
+
});
|
|
411
423
|
}
|
|
412
|
-
return
|
|
424
|
+
return _jsx(FileLinks, {
|
|
425
|
+
children: this.renderFileLink(value)
|
|
426
|
+
});
|
|
413
427
|
};
|
|
414
428
|
renderImages = () => {
|
|
415
429
|
const {
|
|
@@ -419,7 +433,7 @@ export default function withFileControl({
|
|
|
419
433
|
} = this.props;
|
|
420
434
|
const items = valueListToSortableArray(value);
|
|
421
435
|
if (isMultiple(value)) {
|
|
422
|
-
return
|
|
436
|
+
return _jsx(SortableMultiImageWrapper, {
|
|
423
437
|
items: items,
|
|
424
438
|
onSortEnd: this.onSortEnd,
|
|
425
439
|
onRemoveOne: this.onRemoveOne,
|
|
@@ -431,11 +445,13 @@ export default function withFileControl({
|
|
|
431
445
|
lockToContainerEdges: true
|
|
432
446
|
});
|
|
433
447
|
}
|
|
434
|
-
return
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
448
|
+
return _jsx(ImageWrapper, {
|
|
449
|
+
children: _jsx(Image, {
|
|
450
|
+
value: value,
|
|
451
|
+
field: field,
|
|
452
|
+
getAsset: getAsset
|
|
453
|
+
})
|
|
454
|
+
});
|
|
439
455
|
};
|
|
440
456
|
renderSelection = subject => {
|
|
441
457
|
const {
|
|
@@ -443,24 +459,35 @@ export default function withFileControl({
|
|
|
443
459
|
field
|
|
444
460
|
} = this.props;
|
|
445
461
|
const allowsMultiple = this.allowsMultiple();
|
|
446
|
-
return
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
462
|
+
return _jsxs("div", {
|
|
463
|
+
children: [forImage ? this.renderImages() : null, _jsxs("div", {
|
|
464
|
+
children: [forImage ? null : this.renderFileLinks(), _jsx(FileWidgetButton, {
|
|
465
|
+
onClick: this.handleChange,
|
|
466
|
+
children: t(`editor.editorWidgets.${subject}.${this.allowsMultiple() ? 'addMore' : 'chooseDifferent'}`)
|
|
467
|
+
}), field.get('choose_url', true) && !this.allowsMultiple() ? _jsx(FileWidgetButton, {
|
|
468
|
+
onClick: this.handleUrl(subject),
|
|
469
|
+
children: t(`editor.editorWidgets.${subject}.replaceUrl`)
|
|
470
|
+
}) : null, _jsx(FileWidgetButtonRemove, {
|
|
471
|
+
onClick: this.handleRemove,
|
|
472
|
+
children: t(`editor.editorWidgets.${subject}.remove${allowsMultiple ? 'All' : ''}`)
|
|
473
|
+
})]
|
|
474
|
+
})]
|
|
475
|
+
});
|
|
453
476
|
};
|
|
454
477
|
renderNoSelection = subject => {
|
|
455
478
|
const {
|
|
456
479
|
t,
|
|
457
480
|
field
|
|
458
481
|
} = this.props;
|
|
459
|
-
return
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
482
|
+
return _jsxs(_Fragment, {
|
|
483
|
+
children: [_jsx(FileWidgetButton, {
|
|
484
|
+
onClick: this.handleChange,
|
|
485
|
+
children: t(`editor.editorWidgets.${subject}.choose${this.allowsMultiple() ? 'Multiple' : ''}`)
|
|
486
|
+
}), field.get('choose_url', true) ? _jsx(FileWidgetButton, {
|
|
487
|
+
onClick: this.handleUrl(subject),
|
|
488
|
+
children: t(`editor.editorWidgets.${subject}.chooseUrl`)
|
|
489
|
+
}) : null]
|
|
490
|
+
});
|
|
464
491
|
};
|
|
465
492
|
render() {
|
|
466
493
|
const {
|
|
@@ -468,9 +495,12 @@ export default function withFileControl({
|
|
|
468
495
|
classNameWrapper
|
|
469
496
|
} = this.props;
|
|
470
497
|
const subject = forImage ? 'image' : 'file';
|
|
471
|
-
return
|
|
472
|
-
className: classNameWrapper
|
|
473
|
-
|
|
498
|
+
return _jsx("div", {
|
|
499
|
+
className: classNameWrapper,
|
|
500
|
+
children: _jsx("span", {
|
|
501
|
+
children: value ? this.renderSelection(subject) : this.renderNoSelection(subject)
|
|
502
|
+
})
|
|
503
|
+
});
|
|
474
504
|
}
|
|
475
505
|
};
|
|
476
506
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decap-cms-widget-file",
|
|
3
3
|
"description": "Widget for uploading files in Decap CMS.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.5.0",
|
|
5
5
|
"homepage": "https://www.decapcms.org/docs/widgets/#file",
|
|
6
6
|
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-file",
|
|
7
7
|
"bugs": "https://github.com/decaporg/decap-cms/issues",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"react": "^19.1.0",
|
|
39
39
|
"react-immutable-proptypes": "^2.1.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ffe5ab7e61f4e7cb374a413bf9fe55f088d20ba2"
|
|
42
42
|
}
|
package/src/FilePreview.js
CHANGED