Skip to content

Commit f9d017a

Browse files
committed
feat(pat contentbrowser): configurable accepted mimetypes for uploads. pat-tinymce uses this to ensure only 'image/*' mimetypes in image modal.
1 parent c5e4526 commit f9d017a

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

src/pat/contentbrowser/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Show a widget to select items in an offcanvas miller-column browser.
3232
| separator | string | ',' | Select2 option. String which separates multiple items. |
3333
| upload | boolean | false | Allow file and image uploads from within the related items widget. |
3434
| uploadAddImmediately | boolean | true | Add uploaded item(s) immediately to the selected items field. |
35+
| uploadAcceptedMimetypes | string | | Define accepted mimetypes of files to be uploaded.For example "image/*" accepts only images |
3536
| recentlyUsed | boolean | false | Show the recently used items dropdown. |
3637
| recentlyUsedKey | integer | | Storage key for saving the recently used items. This is generated with fieldname and username in the patternoptions. |
3738
| recentlyUsedMaxItems | integer | 20 | Maximum items to keep in recently used list. 0: no restriction. |

src/pat/contentbrowser/contentbrowser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ parser.addArgument("recently-used-max-items");
4646
parser.addArgument("b-size");
4747
parser.addArgument("upload");
4848
parser.addArgument("upload-add-immediately");
49+
parser.addArgument("upload-accepted-mimetypes");
4950
parser.addArgument("sort-on");
5051
parser.addArgument("sort-order");
5152

src/pat/contentbrowser/src/App.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
export let fieldId;
3434
export let upload;
3535
export let uploadAddImmediately = true;
36+
export let uploadAcceptedMimetypes;
3637
export let favorites;
3738
export let recentlyUsed;
3839
export let recentlyUsedKey;
@@ -100,6 +101,7 @@
100101
fieldId: fieldId,
101102
uploadEnabled: upload,
102103
uploadAddImmediately: uploadAddImmediately,
104+
uploadAcceptedMimetypes: uploadAcceptedMimetypes,
103105
favorites: favorites,
104106
recentlyUsed: recentlyUsed,
105107
recentlyUsedKey: recentlyUsedKey,

src/pat/contentbrowser/src/ContentBrowser.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
hiddenInputContainer: ".upload-wrapper",
8888
maxFiles:
8989
$config.maximumSelectionSize > 0 ? $config.maximumSelectionSize : null,
90+
acceptedFiles: $config.uploadAcceptedMimetypes,
9091
success: (fileupload, obj) => {
9192
if ($config.maximumSelectionSize == 1) {
9293
// remove currently selected item and save the uid of the uploaded item

src/pat/tinymce/js/links.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const LinkType = Base.extend({
5050
"data-val": this.value(),
5151
};
5252
},
53-
updateRelatedItems: function () {},
53+
updateRelatedItems: function () { },
5454
});
5555

5656
const ExternalLink = LinkType.extend({
@@ -94,20 +94,25 @@ const InternalLink = LinkType.extend({
9494
return this.el.querySelector("input");
9595
},
9696

97-
createContentBrowser: async function () {
97+
contentBrowserOptions: function () {
9898
const options = {
9999
selection: [],
100100
...this.linkModal.options?.relatedItems,
101101
};
102102
options["maximum-selection-size"] = 1;
103103
// enable upload in ContentBrowser instead of separate tab
104104
options["upload"] = 1;
105-
const inputEl = this.getEl();
106105
const element = this.tiny.selection.getNode();
107106
const linkType = this.tiny.dom.getAttrib(element, "data-linktype");
108107
if (linkType === "internal" || linkType === "image") {
109108
options.selection.push(this.tiny.dom.getAttrib(element, "data-val"));
110109
}
110+
return options;
111+
},
112+
113+
createContentBrowser: async function () {
114+
const inputEl = this.getEl();
115+
const options = this.contentBrowserOptions();
111116
const ContentBrowser = (await import("../../contentbrowser/contentbrowser"))
112117
.default;
113118
this.contentBrowserPattern = new ContentBrowser(inputEl, options);
@@ -125,6 +130,13 @@ const InternalLink = LinkType.extend({
125130
const ImageLink = InternalLink.extend({
126131
name: "imagelinktype",
127132
trigger: ".pat-imagelinktype-dummy",
133+
134+
contentBrowserOptions: function () {
135+
const options = InternalLink.prototype.contentBrowserOptions.call(this);
136+
options["uploadAcceptedMimetypes"] = "image/*";
137+
return options;
138+
},
139+
128140
toUrl: function () {
129141
const value = this.value();
130142
return this.tinypattern.generateImageUrl(

0 commit comments

Comments
 (0)