@instructure/canvas-rce 5.13.2 → 5.13.5
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 +24 -0
- package/es/bridge/Bridge.js +0 -4
- package/es/defaultTinymceConfig.js +1 -1
- package/es/index.js +2 -0
- package/es/rce/RCE.js +3 -1
- package/es/rce/RCEVariants.js +121 -0
- package/es/rce/RCEWrapper.js +96 -47
- package/es/rce/RCEWrapperProps.js +5 -2
- package/es/rce/StatusBar.js +67 -17
- package/es/rce/plugins/instructure_icon_maker/components/CreateIconMakerForm/Footer.js +1 -0
- package/es/rce/plugins/instructure_icon_maker/components/IconMakerTray.js +6 -1
- package/es/rce/plugins/instructure_rce_external_tools/RceToolWrapper.js +9 -9
- package/es/rce/plugins/instructure_rce_external_tools/components/ExternalToolDialog/ExternalToolDialog.js +25 -3
- package/es/rce/plugins/instructure_rce_external_tools/plugin.js +4 -1
- package/es/rce/plugins/shared/CanvasContentTray.js +6 -158
- package/es/rce/plugins/shared/Filter.js +0 -17
- package/es/rce/plugins/shared/FixedContentTray.js +7 -4
- package/es/rce/plugins/shared/ImageOptionsForm.js +3 -2
- package/es/rce/plugins/shared/Upload/CanvasContentPanel.js +160 -0
- package/es/rce/plugins/shared/Upload/ComputerPanel.js +1 -0
- package/es/rce/plugins/shared/Upload/PanelFilter.js +144 -0
- package/es/rce/plugins/shared/Upload/UploadFile.js +10 -2
- package/es/rce/plugins/shared/Upload/UploadFileModal.js +47 -11
- package/es/rce/plugins/shared/Upload/UsageRightsSelectBox.js +20 -20
- package/es/rce/plugins/shared/Upload/index.js +19 -0
- package/es/rce/plugins/shared/ai_tools/AIResponseModal.js +70 -0
- package/es/rce/plugins/shared/ai_tools/AIToolsTray.js +510 -0
- package/es/rce/plugins/shared/ai_tools/aiicons.js +59 -0
- package/es/rce/plugins/shared/ai_tools/index.js +20 -0
- package/es/rce/plugins/shared/canvasContentUtils.js +190 -0
- package/es/rce/plugins/shared/do-fetch-api-effect/defaultFetchOptions.js +31 -0
- package/es/rce/plugins/shared/do-fetch-api-effect/doFetchApi.js +85 -0
- package/es/rce/plugins/shared/do-fetch-api-effect/get-cookie.js +29 -0
- package/es/rce/plugins/shared/do-fetch-api-effect/index.js +22 -0
- package/es/rce/plugins/shared/do-fetch-api-effect/parse-link-header.js +116 -0
- package/es/rce/plugins/shared/do-fetch-api-effect/query-string-encoding.js +51 -0
- package/es/rce/plugins/shared/useFilterSettings.js +35 -0
- package/es/sidebar/actions/upload.js +5 -2
- package/es/translations/locales/ar.js +64 -1
- package/es/translations/locales/ca.js +65 -2
- package/es/translations/locales/cy.js +64 -1
- package/es/translations/locales/da-x-k12.js +65 -2
- package/es/translations/locales/da.js +65 -2
- package/es/translations/locales/de.js +65 -2
- package/es/translations/locales/el.js +9 -0
- package/es/translations/locales/en-AU-x-unimelb.js +65 -2
- package/es/translations/locales/en-GB-x-ukhe.js +65 -2
- package/es/translations/locales/en.js +65 -2
- package/es/translations/locales/en_AU.js +65 -2
- package/es/translations/locales/en_CA.js +65 -2
- package/es/translations/locales/en_CY.js +65 -2
- package/es/translations/locales/en_GB.js +65 -2
- package/es/translations/locales/es.js +64 -1
- package/es/translations/locales/es_ES.js +64 -1
- package/es/translations/locales/fa_IR.js +9 -0
- package/es/translations/locales/fi.js +64 -1
- package/es/translations/locales/fr.js +65 -2
- package/es/translations/locales/fr_CA.js +65 -2
- package/es/translations/locales/ga.js +62 -2
- package/es/translations/locales/he.js +9 -0
- package/es/translations/locales/hi.js +119 -2
- package/es/translations/locales/ht.js +65 -2
- package/es/translations/locales/hu.js +15 -3
- package/es/translations/locales/hy.js +9 -0
- package/es/translations/locales/id.js +65 -2
- package/es/translations/locales/is.js +65 -2
- package/es/translations/locales/it.js +65 -2
- package/es/translations/locales/ja.js +65 -2
- package/es/translations/locales/ko.js +3 -0
- package/es/translations/locales/mi.js +65 -2
- package/es/translations/locales/ms.js +64 -1
- package/es/translations/locales/nb-x-k12.js +65 -2
- package/es/translations/locales/nb.js +65 -2
- package/es/translations/locales/nl.js +65 -2
- package/es/translations/locales/nn.js +15 -3
- package/es/translations/locales/pl.js +64 -1
- package/es/translations/locales/pt.js +64 -1
- package/es/translations/locales/pt_BR.js +65 -2
- package/es/translations/locales/ru.js +64 -1
- package/es/translations/locales/sl.js +65 -2
- package/es/translations/locales/sv-x-k12.js +65 -2
- package/es/translations/locales/sv.js +65 -2
- package/es/translations/locales/th.js +64 -1
- package/es/translations/locales/tr.js +9 -0
- package/es/translations/locales/uk_UA.js +9 -0
- package/es/translations/locales/vi.js +64 -1
- package/es/translations/locales/zh-Hans.js +64 -1
- package/es/translations/locales/zh-Hant.js +65 -2
- package/es/translations/locales/zh.js +64 -1
- package/es/translations/locales/zh_HK.js +65 -2
- package/es/translations/tinymce/ar_SA.js +4 -0
- package/es/translations/tinymce/bg_BG.js +4 -0
- package/es/translations/tinymce/ca.js +4 -0
- package/es/translations/tinymce/cs.js +4 -0
- package/es/translations/tinymce/cy.js +4 -0
- package/es/translations/tinymce/da.js +4 -0
- package/es/translations/tinymce/de.js +4 -0
- package/es/translations/tinymce/el.js +4 -0
- package/es/translations/tinymce/es.js +4 -0
- package/es/translations/tinymce/fa_IR.js +4 -0
- package/es/translations/tinymce/fr_FR.js +4 -0
- package/es/translations/tinymce/ga.js +4 -0
- package/es/translations/tinymce/he_IL.js +4 -0
- package/es/translations/tinymce/hu_HU.js +4 -0
- package/es/translations/tinymce/hy.js +4 -0
- package/es/translations/tinymce/id.js +4 -0
- package/es/translations/tinymce/it.js +4 -0
- package/es/translations/tinymce/ja.js +4 -0
- package/es/translations/tinymce/ko_KR.js +4 -0
- package/es/translations/tinymce/nb_NO.js +4 -0
- package/es/translations/tinymce/nl.js +4 -0
- package/es/translations/tinymce/pl.js +4 -0
- package/es/translations/tinymce/pt_BR.js +4 -0
- package/es/translations/tinymce/pt_PT.js +4 -0
- package/es/translations/tinymce/ro.js +4 -0
- package/es/translations/tinymce/ru.js +4 -0
- package/es/translations/tinymce/ru_RU.js +5 -1
- package/es/translations/tinymce/sl.js +4 -0
- package/es/translations/tinymce/sr.js +4 -0
- package/es/translations/tinymce/sv_SE.js +4 -0
- package/es/translations/tinymce/th.js +5 -1
- package/es/translations/tinymce/tr_TR.js +4 -0
- package/es/translations/tinymce/uk_UA.js +4 -0
- package/es/translations/tinymce/vi_VN.js +4 -0
- package/es/translations/tinymce/zh_CN.js +4 -0
- package/es/translations/tinymce/zh_TW.js +4 -0
- package/jest/jest-setup.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 - present Instructure, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of Canvas.
|
|
5
|
+
*
|
|
6
|
+
* Canvas is free software: you can redistribute it and/or modify it under
|
|
7
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
8
|
+
* Software Foundation, version 3 of the License.
|
|
9
|
+
*
|
|
10
|
+
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
11
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
12
|
+
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
13
|
+
* details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License along
|
|
16
|
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import React, { Suspense } from 'react';
|
|
19
|
+
import { Spinner } from '@instructure/ui-spinner';
|
|
20
|
+
import formatMessage from '../../../format-message';
|
|
21
|
+
import { ICON_MAKER_ICONS } from '../instructure_icon_maker/svg/constants';
|
|
22
|
+
const thePanels = {
|
|
23
|
+
icon_maker_icons: /*#__PURE__*/React.lazy(() => import('../instructure_icon_maker/components/SavedIconMakerList')),
|
|
24
|
+
links: /*#__PURE__*/React.lazy(() => import('../instructure_links/components/LinksPanel')),
|
|
25
|
+
images: /*#__PURE__*/React.lazy(() => import('../instructure_image/Images')),
|
|
26
|
+
documents: /*#__PURE__*/React.lazy(() => import('../instructure_documents/components/DocumentsPanel')),
|
|
27
|
+
media: /*#__PURE__*/React.lazy(() => import('../instructure_record/MediaPanel')),
|
|
28
|
+
all: /*#__PURE__*/React.lazy(() => import('./RceFileBrowser')),
|
|
29
|
+
unknown: /*#__PURE__*/React.lazy(() => import('./UnknownFileTypePanel'))
|
|
30
|
+
}; // Returns a Suspense wrapped lazy loaded component
|
|
31
|
+
// pulled from useLazy's cache
|
|
32
|
+
|
|
33
|
+
export function DynamicPanel(props) {
|
|
34
|
+
let key = '';
|
|
35
|
+
|
|
36
|
+
if (props.contentType === 'links') {
|
|
37
|
+
key = 'links';
|
|
38
|
+
} else {
|
|
39
|
+
key = props.contentSubtype in thePanels ? props.contentSubtype : 'unknown';
|
|
40
|
+
} // @ts-expect-error
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const Component = thePanels[key];
|
|
44
|
+
return /*#__PURE__*/React.createElement(Suspense, {
|
|
45
|
+
fallback: /*#__PURE__*/React.createElement(Spinner, {
|
|
46
|
+
renderTitle: renderLoading,
|
|
47
|
+
size: "large"
|
|
48
|
+
})
|
|
49
|
+
}, /*#__PURE__*/React.createElement(Component, props));
|
|
50
|
+
}
|
|
51
|
+
export const FILTER_SETTINGS_BY_PLUGIN = {
|
|
52
|
+
user_documents: {
|
|
53
|
+
contextType: 'user',
|
|
54
|
+
contentType: 'user_files',
|
|
55
|
+
contentSubtype: 'documents',
|
|
56
|
+
sortValue: 'date_added',
|
|
57
|
+
sortDir: 'desc',
|
|
58
|
+
searchString: ''
|
|
59
|
+
},
|
|
60
|
+
course_documents: {
|
|
61
|
+
contextType: 'course',
|
|
62
|
+
contentType: 'course_files',
|
|
63
|
+
contentSubtype: 'documents',
|
|
64
|
+
sortValue: 'date_added',
|
|
65
|
+
sortDir: 'desc',
|
|
66
|
+
searchString: ''
|
|
67
|
+
},
|
|
68
|
+
group_documents: {
|
|
69
|
+
contextType: 'group',
|
|
70
|
+
contentType: 'group_files',
|
|
71
|
+
contentSubtype: 'documents',
|
|
72
|
+
sortValue: 'date_added',
|
|
73
|
+
sortDir: 'desc',
|
|
74
|
+
searchString: ''
|
|
75
|
+
},
|
|
76
|
+
user_images: {
|
|
77
|
+
contextType: 'user',
|
|
78
|
+
contentType: 'user_files',
|
|
79
|
+
contentSubtype: 'images',
|
|
80
|
+
sortValue: 'date_added',
|
|
81
|
+
sortDir: 'desc',
|
|
82
|
+
searchString: ''
|
|
83
|
+
},
|
|
84
|
+
course_images: {
|
|
85
|
+
contextType: 'course',
|
|
86
|
+
contentType: 'course_files',
|
|
87
|
+
contentSubtype: 'images',
|
|
88
|
+
sortValue: 'date_added',
|
|
89
|
+
sortDir: 'desc',
|
|
90
|
+
searchString: ''
|
|
91
|
+
},
|
|
92
|
+
group_images: {
|
|
93
|
+
contextType: 'group',
|
|
94
|
+
contentType: 'group_files',
|
|
95
|
+
contentSubtype: 'images',
|
|
96
|
+
sortValue: 'date_added',
|
|
97
|
+
sortDir: 'desc',
|
|
98
|
+
searchString: ''
|
|
99
|
+
},
|
|
100
|
+
user_media: {
|
|
101
|
+
contextType: 'user',
|
|
102
|
+
contentType: 'user_files',
|
|
103
|
+
contentSubtype: 'media',
|
|
104
|
+
sortValue: 'date_added',
|
|
105
|
+
sortDir: 'desc',
|
|
106
|
+
searchString: ''
|
|
107
|
+
},
|
|
108
|
+
course_media: {
|
|
109
|
+
contextType: 'course',
|
|
110
|
+
contentType: 'course_files',
|
|
111
|
+
contentSubtype: 'media',
|
|
112
|
+
sortValue: 'date_added',
|
|
113
|
+
sortDir: 'desc',
|
|
114
|
+
searchString: ''
|
|
115
|
+
},
|
|
116
|
+
group_media: {
|
|
117
|
+
contextType: 'group',
|
|
118
|
+
contentType: 'group_files',
|
|
119
|
+
contentSubtype: 'media',
|
|
120
|
+
sortValue: 'date_added',
|
|
121
|
+
sortDir: 'desc',
|
|
122
|
+
searchString: ''
|
|
123
|
+
},
|
|
124
|
+
course_links: {
|
|
125
|
+
contextType: 'course',
|
|
126
|
+
contentType: 'links',
|
|
127
|
+
contentSubtype: 'all',
|
|
128
|
+
sortValue: 'date_added',
|
|
129
|
+
sortDir: 'desc',
|
|
130
|
+
searchString: ''
|
|
131
|
+
},
|
|
132
|
+
course_link_edit: {
|
|
133
|
+
contextType: 'course',
|
|
134
|
+
contentType: 'links',
|
|
135
|
+
contentSubtype: 'edit',
|
|
136
|
+
sortValue: 'date_added',
|
|
137
|
+
sortDir: 'desc',
|
|
138
|
+
searchString: ''
|
|
139
|
+
},
|
|
140
|
+
group_links: {
|
|
141
|
+
contextType: 'group',
|
|
142
|
+
contentType: 'links',
|
|
143
|
+
contentSubtype: 'all',
|
|
144
|
+
sortValue: 'date_added',
|
|
145
|
+
sortDir: 'desc',
|
|
146
|
+
searchString: ''
|
|
147
|
+
},
|
|
148
|
+
list_icon_maker_icons: {
|
|
149
|
+
contextType: 'course',
|
|
150
|
+
contentType: 'course_files',
|
|
151
|
+
contentSubtype: ICON_MAKER_ICONS,
|
|
152
|
+
sortValue: 'date_added',
|
|
153
|
+
sortDir: 'desc',
|
|
154
|
+
searchString: ''
|
|
155
|
+
},
|
|
156
|
+
all: {
|
|
157
|
+
contextType: 'course',
|
|
158
|
+
contentType: 'course_files',
|
|
159
|
+
contentSubtype: 'all',
|
|
160
|
+
sortValue: 'alphabetical',
|
|
161
|
+
sortDir: 'asc',
|
|
162
|
+
searchString: ''
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
export function isLoading(sprops) {
|
|
166
|
+
var _sprops$collections$a, _sprops$collections$a2, _sprops$collections$d, _sprops$collections$m, _sprops$collections$q, _sprops$collections$w, _sprops$documents$cou, _sprops$documents$use, _sprops$documents$gro, _sprops$media$course, _sprops$media$user, _sprops$media$group, _sprops$all_files;
|
|
167
|
+
|
|
168
|
+
return ((_sprops$collections$a = sprops.collections.announcements) === null || _sprops$collections$a === void 0 ? void 0 : _sprops$collections$a.isLoading) || ((_sprops$collections$a2 = sprops.collections.assignments) === null || _sprops$collections$a2 === void 0 ? void 0 : _sprops$collections$a2.isLoading) || ((_sprops$collections$d = sprops.collections.discussions) === null || _sprops$collections$d === void 0 ? void 0 : _sprops$collections$d.isLoading) || ((_sprops$collections$m = sprops.collections.modules) === null || _sprops$collections$m === void 0 ? void 0 : _sprops$collections$m.isLoading) || ((_sprops$collections$q = sprops.collections.quizzes) === null || _sprops$collections$q === void 0 ? void 0 : _sprops$collections$q.isLoading) || ((_sprops$collections$w = sprops.collections.wikiPages) === null || _sprops$collections$w === void 0 ? void 0 : _sprops$collections$w.isLoading) || ((_sprops$documents$cou = sprops.documents.course) === null || _sprops$documents$cou === void 0 ? void 0 : _sprops$documents$cou.isLoading) || ((_sprops$documents$use = sprops.documents.user) === null || _sprops$documents$use === void 0 ? void 0 : _sprops$documents$use.isLoading) || ((_sprops$documents$gro = sprops.documents.group) === null || _sprops$documents$gro === void 0 ? void 0 : _sprops$documents$gro.isLoading) || ((_sprops$media$course = sprops.media.course) === null || _sprops$media$course === void 0 ? void 0 : _sprops$media$course.isLoading) || ((_sprops$media$user = sprops.media.user) === null || _sprops$media$user === void 0 ? void 0 : _sprops$media$user.isLoading) || ((_sprops$media$group = sprops.media.group) === null || _sprops$media$group === void 0 ? void 0 : _sprops$media$group.isLoading) || ((_sprops$all_files = sprops.all_files) === null || _sprops$all_files === void 0 ? void 0 : _sprops$all_files.isLoading);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function renderLoading() {
|
|
172
|
+
return formatMessage('Loading');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export const UploadCanvasPanelIds = ['user_documents', 'course_documents', 'group_documents', 'user_images', 'course_images', 'group_images', 'user_media', 'course_media', 'group_media', 'course_links', 'group_links', 'list_icon_maker_icons', 'all'];
|
|
176
|
+
export const CanvasPanelTitles = {
|
|
177
|
+
user_documents: formatMessage('User Documents'),
|
|
178
|
+
course_documents: formatMessage('Course Documents'),
|
|
179
|
+
group_documents: formatMessage('Group Documents'),
|
|
180
|
+
user_images: formatMessage('User Images'),
|
|
181
|
+
course_images: formatMessage('Course Images'),
|
|
182
|
+
group_images: formatMessage('Group Images'),
|
|
183
|
+
user_media: formatMessage('User Media'),
|
|
184
|
+
course_media: formatMessage('Course Media'),
|
|
185
|
+
group_media: formatMessage('Group Media'),
|
|
186
|
+
course_links: formatMessage('Course Links'),
|
|
187
|
+
group_links: formatMessage('Group Links'),
|
|
188
|
+
list_icon_maker_icons: formatMessage('Icon Maker Icons'),
|
|
189
|
+
all: formatMessage('All')
|
|
190
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 - present Instructure, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of Canvas.
|
|
5
|
+
*
|
|
6
|
+
* Canvas is free software: you can redistribute it and/or modify it under
|
|
7
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
8
|
+
* Software Foundation, version 3 of the License.
|
|
9
|
+
*
|
|
10
|
+
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
11
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
12
|
+
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
13
|
+
* details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License along
|
|
16
|
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import getCookie from './get-cookie';
|
|
19
|
+
const csrfToken = getCookie('_csrf_token'); // these are duplicated in application_helper.rb#prefetch_xhr
|
|
20
|
+
// because we don't have a good pattern for sharing them yet.
|
|
21
|
+
// If you change these defaults, you should probably cascade that change
|
|
22
|
+
// to that ruby location
|
|
23
|
+
|
|
24
|
+
export const defaultFetchOptions = () => ({
|
|
25
|
+
credentials: 'same-origin',
|
|
26
|
+
headers: {
|
|
27
|
+
Accept: 'application/json+canvas-string-ids, application/json',
|
|
28
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
29
|
+
'X-CSRF-Token': csrfToken
|
|
30
|
+
}
|
|
31
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (C) 2019 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* This file is part of Canvas.
|
|
7
|
+
*
|
|
8
|
+
* Canvas is free software: you can redistribute it and/or modify it under
|
|
9
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
10
|
+
* Software Foundation, version 3 of the License.
|
|
11
|
+
*
|
|
12
|
+
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
13
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
14
|
+
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
15
|
+
* details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Affero General Public License along
|
|
18
|
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
import parseLinkHeader from './parse-link-header';
|
|
21
|
+
import { defaultFetchOptions } from './defaultFetchOptions';
|
|
22
|
+
import { toQueryString } from './query-string-encoding';
|
|
23
|
+
|
|
24
|
+
function constructRelativeUrl(_ref) {
|
|
25
|
+
let {
|
|
26
|
+
path,
|
|
27
|
+
params
|
|
28
|
+
} = _ref;
|
|
29
|
+
const queryString = toQueryString(params);
|
|
30
|
+
if (queryString.length === 0) return path;
|
|
31
|
+
return path + '?' + queryString;
|
|
32
|
+
} // https://fetch.spec.whatwg.org/#requestinit
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// NOTE: we do NOT deep-merge customFetchOptions.headers, they should be passed
|
|
36
|
+
// in the headers arg instead.
|
|
37
|
+
export default async function doFetchApi(_ref2) {
|
|
38
|
+
let {
|
|
39
|
+
path,
|
|
40
|
+
method = 'GET',
|
|
41
|
+
headers = {},
|
|
42
|
+
params = {},
|
|
43
|
+
body,
|
|
44
|
+
fetchOpts = {}
|
|
45
|
+
} = _ref2;
|
|
46
|
+
const finalFetchOptions = { ...defaultFetchOptions()
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (body && typeof body !== 'string') {
|
|
50
|
+
body = JSON.stringify(body);
|
|
51
|
+
finalFetchOptions.headers['Content-Type'] = 'application/json';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Object.assign(finalFetchOptions.headers, headers);
|
|
55
|
+
Object.assign(finalFetchOptions, fetchOpts);
|
|
56
|
+
const url = constructRelativeUrl({
|
|
57
|
+
path,
|
|
58
|
+
params
|
|
59
|
+
});
|
|
60
|
+
const response = await fetch(url, {
|
|
61
|
+
body,
|
|
62
|
+
method,
|
|
63
|
+
...finalFetchOptions,
|
|
64
|
+
credentials: finalFetchOptions.credentials
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
const err = new Error(`doFetchApi received a bad response: ${response.status} ${response.statusText}`);
|
|
69
|
+
Object.assign(err, {
|
|
70
|
+
response
|
|
71
|
+
}); // in case anyone wants to check it for something
|
|
72
|
+
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const linkHeader = response.headers.get('Link');
|
|
77
|
+
const link = linkHeader && parseLinkHeader(linkHeader) || undefined;
|
|
78
|
+
const text = await response.text();
|
|
79
|
+
const json = text.length > 0 ? JSON.parse(text) : undefined;
|
|
80
|
+
return {
|
|
81
|
+
json,
|
|
82
|
+
response,
|
|
83
|
+
link
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 - present Instructure, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of Canvas.
|
|
5
|
+
*
|
|
6
|
+
* Canvas is free software: you can redistribute it and/or modify it under
|
|
7
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
8
|
+
* Software Foundation, version 3 of the License.
|
|
9
|
+
*
|
|
10
|
+
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
11
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
12
|
+
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
13
|
+
* details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License along
|
|
16
|
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A faster alternative to $.cookie for getting a cookie from document.cookie by name
|
|
21
|
+
* see: https://stackoverflow.com/a/25490531/7159335
|
|
22
|
+
* @param {string} cookieName
|
|
23
|
+
* @returns {string} cookie value
|
|
24
|
+
*/
|
|
25
|
+
export default function getCookie(cookieName) {
|
|
26
|
+
const match = document.cookie.match('(^|[^;]+)\\s*' + cookieName + '\\s*=\\s*([^;]+)');
|
|
27
|
+
const first = match === null || match === void 0 ? void 0 : match.pop();
|
|
28
|
+
return first ? decodeURIComponent(first) : undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 - present Instructure, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of Canvas.
|
|
5
|
+
*
|
|
6
|
+
* Canvas is free software: you can redistribute it and/or modify it under
|
|
7
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
8
|
+
* Software Foundation, version 3 of the License.
|
|
9
|
+
*
|
|
10
|
+
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
11
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
12
|
+
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
13
|
+
* details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License along
|
|
16
|
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import doFetchApi from './doFetchApi';
|
|
19
|
+
export * from './get-cookie';
|
|
20
|
+
export * from './parse-link-header';
|
|
21
|
+
export * from './query-string-encoding';
|
|
22
|
+
export default doFetchApi;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2023 - present Instructure, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of Canvas.
|
|
5
|
+
*
|
|
6
|
+
* Canvas is free software: you can redistribute it and/or modify it under
|
|
7
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
8
|
+
* Software Foundation, version 3 of the License.
|
|
9
|
+
*
|
|
10
|
+
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
11
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
12
|
+
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
13
|
+
* details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License along
|
|
16
|
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
// based on https://github.com/thlorenz/parse-link-header/blob/master/index.js (MIT)
|
|
19
|
+
function parseQueryParams(linkUrl) {
|
|
20
|
+
const queryParams = {};
|
|
21
|
+
const urlParts = linkUrl.split('?');
|
|
22
|
+
|
|
23
|
+
if (urlParts.length > 1) {
|
|
24
|
+
urlParts[1].split('&').forEach(param => {
|
|
25
|
+
const [key, value] = param.split('=');
|
|
26
|
+
queryParams[key] = decodeURIComponent(value);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return queryParams;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parseLink(link) {
|
|
34
|
+
try {
|
|
35
|
+
const linkMatch = link.match(/<([^>]*)>\s*(.*)/);
|
|
36
|
+
|
|
37
|
+
if (!linkMatch) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const [, linkUrl, partsString] = linkMatch;
|
|
42
|
+
const parts = partsString.split(';').map(part => part.trim());
|
|
43
|
+
const info = {
|
|
44
|
+
url: linkUrl
|
|
45
|
+
};
|
|
46
|
+
parts.forEach(part => {
|
|
47
|
+
const partMatch = part.match(/(.+)\s*=\s*"?([^"]+)"?/);
|
|
48
|
+
|
|
49
|
+
if (partMatch) {
|
|
50
|
+
const [, key, value] = partMatch;
|
|
51
|
+
info[key.trim()] = value.trim();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return { ...parseQueryParams(linkUrl),
|
|
55
|
+
...info
|
|
56
|
+
};
|
|
57
|
+
} catch (e) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function hasRel(x) {
|
|
63
|
+
return x !== null && 'rel' in x;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function intoRels(acc, x) {
|
|
67
|
+
x.rel.split(/\s+/).forEach(rel => {
|
|
68
|
+
const { ...rest
|
|
69
|
+
} = x;
|
|
70
|
+
|
|
71
|
+
switch (rel) {
|
|
72
|
+
case 'first':
|
|
73
|
+
acc.first = rest;
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case 'prev':
|
|
77
|
+
acc.prev = rest;
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case 'current':
|
|
81
|
+
acc.current = rest;
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case 'next':
|
|
85
|
+
acc.next = rest;
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 'last':
|
|
89
|
+
acc.last = rest;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return acc;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const PARSE_LINK_HEADER_MAXLEN = 2000;
|
|
97
|
+
const PARSE_LINK_HEADER_THROW_ON_MAXLEN_EXCEEDED = process.env.PARSE_LINK_HEADER_THROW_ON_MAXLEN_EXCEEDED != null;
|
|
98
|
+
|
|
99
|
+
function checkHeader(linkHeader) {
|
|
100
|
+
if (!linkHeader) return false;
|
|
101
|
+
|
|
102
|
+
if (linkHeader.length > PARSE_LINK_HEADER_MAXLEN) {
|
|
103
|
+
if (PARSE_LINK_HEADER_THROW_ON_MAXLEN_EXCEEDED) {
|
|
104
|
+
throw new Error(`Input string too long, it should be under ${PARSE_LINK_HEADER_MAXLEN} characters.`);
|
|
105
|
+
} else {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export default function parseLinkHeader(linkHeader) {
|
|
114
|
+
if (!checkHeader(linkHeader)) return null;
|
|
115
|
+
return linkHeader.split(/,\s*(?=<)/).map(parseLink).filter(hasRel).reduce(intoRels, {});
|
|
116
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2017 - present Instructure, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of Canvas.
|
|
5
|
+
*
|
|
6
|
+
* Canvas is free software: you can redistribute it and/or modify it under
|
|
7
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
8
|
+
* Software Foundation, version 3 of the License.
|
|
9
|
+
*
|
|
10
|
+
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
11
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
12
|
+
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
13
|
+
* details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License along
|
|
16
|
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
// toQueryString does what jQuery's .param() does, only without having to bring in
|
|
19
|
+
// all of jQuery.
|
|
20
|
+
// URLSearchParams turns arrays into queries like a=1,2,3
|
|
21
|
+
// But our jQuery makes the older "PHP" style like a[]=1&a[]=2&a[]=3
|
|
22
|
+
// JQuery also magically deals with parameters that are functions, and recursive
|
|
23
|
+
// objects within objects, {a: 1, b: {c: 2, d: 3}, e: 4} => a=1&b[c]=2&b[d]=3&e=4
|
|
24
|
+
// ... so we have to do a lot of massaging with the params object before using it
|
|
25
|
+
// So fun!
|
|
26
|
+
export function toQueryString(params) {
|
|
27
|
+
const paramsWithIndexes = []; // fix up the array/object indexes to match the PHP standard
|
|
28
|
+
|
|
29
|
+
const fixIndexes = elt => [elt[0].replace(/\[\d+\]$/, '[]').replace(/{/g, '[').replace(/}/g, ']'), elt[1]];
|
|
30
|
+
|
|
31
|
+
function serialize(k, elt, suffix) {
|
|
32
|
+
if (elt instanceof Function) {
|
|
33
|
+
paramsWithIndexes.push([k + suffix, elt()]);
|
|
34
|
+
} else if (elt instanceof Array) {
|
|
35
|
+
elt.forEach((k2, i) => serialize(k, k2, `${suffix}[${i}]`));
|
|
36
|
+
} else if (elt instanceof Object) {
|
|
37
|
+
Object.keys(elt).forEach(k2 => serialize(k, elt[k2], `${suffix}{${k2}}`));
|
|
38
|
+
} else if (typeof elt === 'boolean' || typeof elt === 'number') {
|
|
39
|
+
paramsWithIndexes.push([k + suffix, elt.toString()]);
|
|
40
|
+
} else if (typeof elt === 'undefined') {
|
|
41
|
+
paramsWithIndexes.push([k + suffix, 'undefined']);
|
|
42
|
+
} else if (elt === null) {
|
|
43
|
+
paramsWithIndexes.push([k + suffix, 'null']);
|
|
44
|
+
} else if (typeof elt === 'string') {
|
|
45
|
+
paramsWithIndexes.push([k + suffix, elt]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Object.keys(params).forEach(k => serialize(k, params[k], ''));
|
|
50
|
+
return new URLSearchParams(paramsWithIndexes.map(fixIndexes)).toString();
|
|
51
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 - present Instructure, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of Canvas.
|
|
5
|
+
*
|
|
6
|
+
* Canvas is free software: you can redistribute it and/or modify it under
|
|
7
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
8
|
+
* Software Foundation, version 3 of the License.
|
|
9
|
+
*
|
|
10
|
+
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
11
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
12
|
+
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
13
|
+
* details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License along
|
|
16
|
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { useState } from 'react';
|
|
19
|
+
const DEFAULT_FILTER_SETTINGS = {
|
|
20
|
+
contentSubtype: 'all',
|
|
21
|
+
contentType: 'links',
|
|
22
|
+
sortValue: 'date_added',
|
|
23
|
+
searchString: ''
|
|
24
|
+
};
|
|
25
|
+
export function useFilterSettings(default_settings) {
|
|
26
|
+
const [filterSettings, setFilterSettings] = useState(default_settings || DEFAULT_FILTER_SETTINGS);
|
|
27
|
+
|
|
28
|
+
function updateFilterSettings(nextSettings) {
|
|
29
|
+
setFilterSettings({ ...filterSettings,
|
|
30
|
+
...nextSettings
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return [filterSettings, updateFilterSettings];
|
|
35
|
+
}
|
|
@@ -381,9 +381,11 @@ export function uploadToMediaFolder(tabContext, fileMetaProps) {
|
|
|
381
381
|
delete fileMetaProps.domObject.preview; // don't need this anymore
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
dispatch(uploadPreflight(tabContext, { ...fileMetaProps,
|
|
384
|
+
return dispatch(uploadPreflight(tabContext, { ...fileMetaProps,
|
|
385
385
|
bookmark
|
|
386
|
-
}))
|
|
386
|
+
})).then(results => {
|
|
387
|
+
return results;
|
|
388
|
+
});
|
|
387
389
|
}).catch(e => {
|
|
388
390
|
// Get rid of any placeholder that might be there.
|
|
389
391
|
dispatch(removePlaceholdersFor(fileMetaProps.name)); // eslint-disable-next-line no-console
|
|
@@ -540,6 +542,7 @@ export function uploadPreflight(tabContext, fileMetaProps) {
|
|
|
540
542
|
return uploadResult;
|
|
541
543
|
}).then(results => {
|
|
542
544
|
dispatch(allUploadCompleteActions(results, fileMetaProps, contextType));
|
|
545
|
+
return results;
|
|
543
546
|
}).catch(err => {
|
|
544
547
|
// This may or may not be necessary depending on the upload
|
|
545
548
|
dispatch(removePlaceholdersFor(fileMetaProps.name));
|