diff options
Diffstat (limited to 'apps/files/src/models')
-rw-r--r-- | apps/files/src/models/Setting.js | 43 | ||||
-rw-r--r-- | apps/files/src/models/Tab.js | 52 |
2 files changed, 50 insertions, 45 deletions
diff --git a/apps/files/src/models/Setting.js b/apps/files/src/models/Setting.js index db276da85af..1db1d818e69 100644 --- a/apps/files/src/models/Setting.js +++ b/apps/files/src/models/Setting.js @@ -1,24 +1,6 @@ /** - * @copyright Copyright (c) 2019 Gary Kim <gary@garykim.dev> - * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com> - * - * @author Gary Kim <gary@garykim.dev> - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ export default class Setting { @@ -27,6 +9,7 @@ export default class Setting { _el _name _open + _order /** * Create a new files app setting @@ -37,12 +20,14 @@ export default class Setting { * @param {Function} component.el function that returns an unmounted dom element to be added * @param {Function} [component.open] callback for when setting is added * @param {Function} [component.close] callback for when setting is closed + * @param {number} [component.order] the order of this setting, lower numbers are shown first */ - constructor(name, { el, open, close }) { + constructor(name, { el, open, close, order }) { this._name = name this._el = el this._open = open this._close = close + this._order = order || 0 if (typeof this._open !== 'function') { this._open = () => {} @@ -51,6 +36,18 @@ export default class Setting { if (typeof this._close !== 'function') { this._close = () => {} } + + if (typeof this._el !== 'function') { + throw new Error('Setting must have an `el` function that returns a DOM element') + } + + if (typeof this._name !== 'string') { + throw new Error('Setting must have a `name` string') + } + + if (typeof this._order !== 'number') { + throw new Error('Setting must have an `order` number') + } } get name() { @@ -69,4 +66,8 @@ export default class Setting { return this._close } + get order() { + return this._order + } + } diff --git a/apps/files/src/models/Tab.js b/apps/files/src/models/Tab.js index 4c41ec5a3b1..b67d51f277f 100644 --- a/apps/files/src/models/Tab.js +++ b/apps/files/src/models/Tab.js @@ -1,31 +1,17 @@ /** - * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com> - * - * @author John Molakvoæ <skjnldsv@protonmail.com> - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ +import DOMPurify from 'dompurify' export default class Tab { _id _name _icon + _iconSvgSanitized _mount + _setIsActive _update _destroy _enabled @@ -37,19 +23,21 @@ export default class Tab { * @param {object} options destructuring object * @param {string} options.id the unique id of this tab * @param {string} options.name the translated tab name - * @param {string} options.icon the vue component + * @param {?string} options.icon the icon css class + * @param {?string} options.iconSvg the icon in svg format * @param {Function} options.mount function to mount the tab + * @param {Function} [options.setIsActive] function to forward the active state of the tab * @param {Function} options.update function to update the tab * @param {Function} options.destroy function to destroy the tab * @param {Function} [options.enabled] define conditions whether this tab is active. Must returns a boolean * @param {Function} [options.scrollBottomReached] executed when the tab is scrolled to the bottom */ - constructor({ id, name, icon, mount, update, destroy, enabled, scrollBottomReached } = {}) { + constructor({ id, name, icon, iconSvg, mount, setIsActive, update, destroy, enabled, scrollBottomReached } = {}) { if (enabled === undefined) { enabled = () => true } if (scrollBottomReached === undefined) { - scrollBottomReached = () => {} + scrollBottomReached = () => { } } // Sanity checks @@ -59,12 +47,15 @@ export default class Tab { if (typeof name !== 'string' || name.trim() === '') { throw new Error('The name argument is not a valid string') } - if (typeof icon !== 'string' || icon.trim() === '') { - throw new Error('The icon argument is not a valid string') + if ((typeof icon !== 'string' || icon.trim() === '') && typeof iconSvg !== 'string') { + throw new Error('Missing valid string for icon or iconSvg argument') } if (typeof mount !== 'function') { throw new Error('The mount argument should be a function') } + if (setIsActive !== undefined && typeof setIsActive !== 'function') { + throw new Error('The setIsActive argument should be a function') + } if (typeof update !== 'function') { throw new Error('The update argument should be a function') } @@ -82,11 +73,16 @@ export default class Tab { this._name = name this._icon = icon this._mount = mount + this._setIsActive = setIsActive this._update = update this._destroy = destroy this._enabled = enabled this._scrollBottomReached = scrollBottomReached + if (typeof iconSvg === 'string') { + this._iconSvgSanitized = DOMPurify.sanitize(iconSvg) + } + } get id() { @@ -101,10 +97,18 @@ export default class Tab { return this._icon } + get iconSvg() { + return this._iconSvgSanitized + } + get mount() { return this._mount } + get setIsActive() { + return this._setIsActive || (() => undefined) + } + get update() { return this._update } |