From 2c6a2b2d70061e52936fa51ca282efeb80a4d1b4 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 20 Jun 2018 13:31:45 +0930 Subject: [PATCH] Webpack (#52) See https://github.com/flarum/core/pull/1367 * Replace gulp with webpack and npm scripts for JS compilation * Set up Travis CI to commit compiled JS * Restructure `js` directory; only one instance of npm, forum/admin are "submodules" * Maintain partial compatibility API (importing from absolute paths) for extensions * Restructure `less` directory --- extensions/tags/.deploy.enc | Bin 0 -> 3248 bytes extensions/tags/.gitattributes | 2 +- extensions/tags/.gitignore | 2 +- extensions/tags/.travis.yml | 15 + extensions/tags/bootstrap.php | 14 +- extensions/tags/js/admin.js | 11 + extensions/tags/js/admin/Gulpfile.js | 13 - extensions/tags/js/admin/bower.json | 6 - extensions/tags/js/admin/dist/extension.js | 1406 ----- extensions/tags/js/admin/package.json | 7 - extensions/tags/js/admin/src/main.js | 16 - extensions/tags/js/dist/admin.js | 2 + extensions/tags/js/dist/admin.js.map | 1 + extensions/tags/js/dist/forum.js | 2 + extensions/tags/js/dist/forum.js.map | 1 + extensions/tags/js/forum.js | 11 + extensions/tags/js/forum/Gulpfile.js | 10 - extensions/tags/js/forum/dist/extension.js | 1370 ----- extensions/tags/js/forum/package.json | 7 - extensions/tags/js/package-lock.json | 4708 +++++++++++++++++ extensions/tags/js/package.json | 14 + .../admin}/addTagChangePermission.js | 0 .../src => src/admin}/addTagPermission.js | 0 .../admin}/addTagsHomePageOption.js | 0 .../{admin/src => src/admin}/addTagsPane.js | 2 +- .../admin}/addTagsPermissionScope.js | 6 +- extensions/tags/js/src/admin/compat.js | 21 + .../admin}/components/EditTagModal.js | 2 +- .../admin}/components/TagSettingsModal.js | 0 .../src => src/admin}/components/TagsPage.js | 10 +- extensions/tags/js/src/admin/index.js | 16 + extensions/tags/js/src/common/compat.js | 13 + .../js/{lib => src/common}/helpers/tagIcon.js | 0 .../{lib => src/common}/helpers/tagLabel.js | 0 .../{lib => src/common}/helpers/tagsLabel.js | 4 +- extensions/tags/js/src/common/index.js | 0 .../tags/js/{lib => src/common}/models/Tag.js | 0 .../js/{lib => src/common}/utils/sortTags.js | 0 .../src => src/forum}/addTagComposer.js | 4 +- .../{forum/src => src/forum}/addTagControl.js | 2 +- .../{forum/src => src/forum}/addTagFilter.js | 2 +- .../{forum/src => src/forum}/addTagLabels.js | 4 +- .../js/{forum/src => src/forum}/addTagList.js | 6 +- extensions/tags/js/src/forum/compat.js | 25 + .../forum}/components/DiscussionTaggedPost.js | 2 +- .../forum}/components/TagDiscussionModal.js | 6 +- .../src => src/forum}/components/TagHero.js | 0 .../forum}/components/TagLinkButton.js | 2 +- .../src => src/forum}/components/TagsPage.js | 4 +- .../{forum/src/main.js => src/forum/index.js} | 23 +- extensions/tags/js/webpack.config.js | 3 + extensions/tags/less/admin.less | 11 + extensions/tags/less/admin/extension.less | 11 - .../tags/less/{lib => common}/TagIcon.less | 0 .../tags/less/{lib => common}/TagLabel.less | 0 .../less/{forum/extension.less => forum.less} | 10 +- extensions/tags/scripts/compile.sh | 27 - 57 files changed, 4913 insertions(+), 2921 deletions(-) create mode 100644 extensions/tags/.deploy.enc create mode 100644 extensions/tags/.travis.yml create mode 100644 extensions/tags/js/admin.js delete mode 100644 extensions/tags/js/admin/Gulpfile.js delete mode 100644 extensions/tags/js/admin/bower.json delete mode 100644 extensions/tags/js/admin/dist/extension.js delete mode 100644 extensions/tags/js/admin/package.json delete mode 100644 extensions/tags/js/admin/src/main.js create mode 100644 extensions/tags/js/dist/admin.js create mode 100644 extensions/tags/js/dist/admin.js.map create mode 100644 extensions/tags/js/dist/forum.js create mode 100644 extensions/tags/js/dist/forum.js.map create mode 100644 extensions/tags/js/forum.js delete mode 100644 extensions/tags/js/forum/Gulpfile.js delete mode 100644 extensions/tags/js/forum/dist/extension.js delete mode 100644 extensions/tags/js/forum/package.json create mode 100644 extensions/tags/js/package-lock.json create mode 100644 extensions/tags/js/package.json rename extensions/tags/js/{admin/src => src/admin}/addTagChangePermission.js (100%) rename extensions/tags/js/{admin/src => src/admin}/addTagPermission.js (100%) rename extensions/tags/js/{admin/src => src/admin}/addTagsHomePageOption.js (100%) rename extensions/tags/js/{admin/src => src/admin}/addTagsPane.js (92%) rename extensions/tags/js/{admin/src => src/admin}/addTagsPermissionScope.js (93%) create mode 100644 extensions/tags/js/src/admin/compat.js rename extensions/tags/js/{admin/src => src/admin}/components/EditTagModal.js (98%) rename extensions/tags/js/{admin/src => src/admin}/components/TagSettingsModal.js (100%) rename extensions/tags/js/{admin/src => src/admin}/components/TagsPage.js (95%) create mode 100644 extensions/tags/js/src/admin/index.js create mode 100644 extensions/tags/js/src/common/compat.js rename extensions/tags/js/{lib => src/common}/helpers/tagIcon.js (100%) rename extensions/tags/js/{lib => src/common}/helpers/tagLabel.js (100%) rename extensions/tags/js/{lib => src/common}/helpers/tagsLabel.js (81%) create mode 100644 extensions/tags/js/src/common/index.js rename extensions/tags/js/{lib => src/common}/models/Tag.js (100%) rename extensions/tags/js/{lib => src/common}/utils/sortTags.js (100%) rename extensions/tags/js/{forum/src => src/forum}/addTagComposer.js (94%) rename extensions/tags/js/{forum/src => src/forum}/addTagControl.js (89%) rename extensions/tags/js/{forum/src => src/forum}/addTagFilter.js (96%) rename extensions/tags/js/{forum/src => src/forum}/addTagLabels.js (93%) rename extensions/tags/js/{forum/src => src/forum}/addTagList.js (90%) create mode 100644 extensions/tags/js/src/forum/compat.js rename extensions/tags/js/{forum/src => src/forum}/components/DiscussionTaggedPost.js (96%) rename extensions/tags/js/{forum/src => src/forum}/components/TagDiscussionModal.js (98%) rename extensions/tags/js/{forum/src => src/forum}/components/TagHero.js (100%) rename extensions/tags/js/{forum/src => src/forum}/components/TagLinkButton.js (94%) rename extensions/tags/js/{forum/src => src/forum}/components/TagsPage.js (96%) rename extensions/tags/js/{forum/src/main.js => src/forum/index.js} (57%) create mode 100755 extensions/tags/js/webpack.config.js create mode 100644 extensions/tags/less/admin.less delete mode 100644 extensions/tags/less/admin/extension.less rename extensions/tags/less/{lib => common}/TagIcon.less (100%) rename extensions/tags/less/{lib => common}/TagLabel.less (100%) rename extensions/tags/less/{forum/extension.less => forum.less} (89%) delete mode 100755 extensions/tags/scripts/compile.sh diff --git a/extensions/tags/.deploy.enc b/extensions/tags/.deploy.enc new file mode 100644 index 0000000000000000000000000000000000000000..9c1e20f47579ad43a261ebb24f0ffd318e67bfd9 GIT binary patch literal 3248 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.'/js/forum/dist/extension.js') - ->asset(__DIR__.'/less/forum/extension.less') - ->bootstrapper('flarum/tags/main'), + ->js(__DIR__.'/js/dist/forum.js') + ->asset(__DIR__.'/less/forum.less'), + (new Extend\Assets('admin')) - ->asset(__DIR__.'/js/admin/dist/extension.js') - ->asset(__DIR__.'/less/admin/extension.less') - ->bootstrapper('flarum/tags/main'), + ->js(__DIR__.'/js/dist/admin.js') + ->asset(__DIR__.'/less/admin.less'), + (new Extend\Routes('forum')) ->get('/t/{slug}', 'tag', FrontendController::class) ->get('/tags', 'tags', FrontendController::class), + (new Extend\Routes('api')) ->get('/tags', 'tags.index', Controller\ListTagsController::class) ->post('/tags', 'tags.create', Controller\CreateTagController::class) ->post('/tags/order', 'tags.order', Controller\OrderTagsController::class) ->patch('/tags/{id}', 'tags.update', Controller\UpdateTagController::class) ->delete('/tags/{id}', 'tags.delete', Controller\DeleteTagController::class), + function (Dispatcher $events) { $events->subscribe(Listener\AddDiscussionTagsRelationship::class); $events->subscribe(Listener\AddForumTagsRelationship::class); diff --git a/extensions/tags/js/admin.js b/extensions/tags/js/admin.js new file mode 100644 index 000000000..fd107337a --- /dev/null +++ b/extensions/tags/js/admin.js @@ -0,0 +1,11 @@ +/* + * This file is part of Flarum. + * + * (c) Toby Zerner + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +export * from './src/common'; +export * from './src/admin'; diff --git a/extensions/tags/js/admin/Gulpfile.js b/extensions/tags/js/admin/Gulpfile.js deleted file mode 100644 index 4dbce6348..000000000 --- a/extensions/tags/js/admin/Gulpfile.js +++ /dev/null @@ -1,13 +0,0 @@ -var gulp = require('flarum-gulp'); - -gulp({ - files: [ - 'bower_components/html.sortable/dist/html.sortable.js' - ], - modules: { - 'flarum/tags': [ - '../lib/**/*.js', - 'src/**/*.js' - ] - } -}); diff --git a/extensions/tags/js/admin/bower.json b/extensions/tags/js/admin/bower.json deleted file mode 100644 index 306c90a5d..000000000 --- a/extensions/tags/js/admin/bower.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "flarum-tags-admin", - "devDependencies": { - "html.sortable": "^0.2.9" - } -} diff --git a/extensions/tags/js/admin/dist/extension.js b/extensions/tags/js/admin/dist/extension.js deleted file mode 100644 index 71d3ea328..000000000 --- a/extensions/tags/js/admin/dist/extension.js +++ /dev/null @@ -1,1406 +0,0 @@ -;(function(root, factory) { - if (typeof define === 'function' && define.amd) { - define(['jquery'], factory); - } else if (typeof exports === 'object') { - module.exports = factory(require('jquery')); - } else { - root.sortable = factory(root.jQuery); - } -}(this, function($) { -/* - * HTML5 Sortable jQuery Plugin - * https://github.com/voidberg/html5sortable - * - * Original code copyright 2012 Ali Farhadi. - * This version is mantained by Alexandru Badiu & Lukas Oppermann - * - * - * Released under the MIT license. - */ -'use strict'; -/* - * variables global to the plugin - */ -var dragging; -var draggingHeight; -var placeholders = $(); -var sortables = []; -/* - * remove event handlers from items - * @param [jquery Collection] items - * @info event.h5s (jquery way of namespacing events, to bind multiple handlers to the event) - */ -var _removeItemEvents = function(items) { - items.off('dragstart.h5s'); - items.off('dragend.h5s'); - items.off('selectstart.h5s'); - items.off('dragover.h5s'); - items.off('dragenter.h5s'); - items.off('drop.h5s'); -}; -/* - * remove event handlers from sortable - * @param [jquery Collection] sortable - * @info event.h5s (jquery way of namespacing events, to bind multiple handlers to the event) - */ -var _removeSortableEvents = function(sortable) { - sortable.off('dragover.h5s'); - sortable.off('dragenter.h5s'); - sortable.off('drop.h5s'); -}; -/* - * attache ghost to dataTransfer object - * @param [event] original event - * @param [object] ghost-object with item, x and y coordinates - */ -var _attachGhost = function(event, ghost) { - // this needs to be set for HTML5 drag & drop to work - event.dataTransfer.effectAllowed = 'move'; - event.dataTransfer.setData('text', ''); - - // check if setDragImage method is available - if (event.dataTransfer.setDragImage) { - event.dataTransfer.setDragImage(ghost.item, ghost.x, ghost.y); - } -}; -/** - * _addGhostPos clones the dragged item and adds it as a Ghost item - * @param [object] event - the event fired when dragstart is triggered - * @param [object] ghost - .item = node, draggedItem = jQuery collection - */ -var _addGhostPos = function(e, ghost) { - if (!ghost.x) { - ghost.x = parseInt(e.pageX - ghost.draggedItem.offset().left); - } - if (!ghost.y) { - ghost.y = parseInt(e.pageY - ghost.draggedItem.offset().top); - } - return ghost; -}; -/** - * _makeGhost decides which way to make a ghost and passes it to attachGhost - * @param [jQuery selection] $draggedItem - the item that the user drags - */ -var _makeGhost = function($draggedItem) { - return { - item: $draggedItem[0], - draggedItem: $draggedItem - }; -}; -/** - * _getGhost constructs ghost and attaches it to dataTransfer - * @param [event] event - the original drag event object - * @param [jQuery selection] $draggedItem - the item that the user drags - * @param [object] ghostOpt - the ghost options - */ -// TODO: could $draggedItem be replaced by event.target in all instances -var _getGhost = function(event, $draggedItem) { - // add ghost item & draggedItem to ghost object - var ghost = _makeGhost($draggedItem); - // attach ghost position - ghost = _addGhostPos(event, ghost); - // attach ghost to dataTransfer - _attachGhost(event, ghost); -}; -/* - * return options if not set on sortable already - * @param [object] soptions - * @param [object] options - */ -var _getOptions = function(soptions, options) { - if (typeof soptions === 'undefined') { - return options; - } - return soptions; -}; -/* - * remove data from sortable - * @param [jquery Collection] a single sortable - */ -var _removeSortableData = function(sortable) { - sortable.removeData('opts'); - sortable.removeData('connectWith'); - sortable.removeData('items'); - sortable.removeAttr('aria-dropeffect'); -}; -/* - * remove data from items - * @param [jquery Collection] items - */ -var _removeItemData = function(items) { - items.removeAttr('aria-grabbed'); - items.removeAttr('draggable'); - items.removeAttr('role'); -}; -/* - * check if two lists are connected - * @param [jquery Collection] items - */ -var _listsConnected = function(curList, destList) { - if (curList[0] === destList[0]) { - return true; - } - if (curList.data('connectWith') !== undefined) { - return curList.data('connectWith') === destList.data('connectWith'); - } - return false; -}; -/* - * destroy the sortable - * @param [jquery Collection] a single sortable - */ -var _destroySortable = function(sortable) { - var opts = sortable.data('opts') || {}; - var items = sortable.children(opts.items); - var handles = opts.handle ? items.find(opts.handle) : items; - // remove event handlers & data from sortable - _removeSortableEvents(sortable); - _removeSortableData(sortable); - // remove event handlers & data from items - handles.off('mousedown.h5s'); - _removeItemEvents(items); - _removeItemData(items); -}; -/* - * enable the sortable - * @param [jquery Collection] a single sortable - */ -var _enableSortable = function(sortable) { - var opts = sortable.data('opts'); - var items = sortable.children(opts.items); - var handles = opts.handle ? items.find(opts.handle) : items; - sortable.attr('aria-dropeffect', 'move'); - handles.attr('draggable', 'true'); - // IE FIX for ghost - // can be disabled as it has the side effect that other events - // (e.g. click) will be ignored - if (typeof document.createElement('span').dragDrop === 'function' && !opts.disableIEFix) { - handles.on('mousedown.h5s', function() { - if (items.index(this) !== -1) { - this.dragDrop(); - } else { - $(this).parents(opts.items)[0].dragDrop(); - } - }); - } -}; -/* - * disable the sortable - * @param [jquery Collection] a single sortable - */ -var _disableSortable = function(sortable) { - var opts = sortable.data('opts'); - var items = sortable.children(opts.items); - var handles = opts.handle ? items.find(opts.handle) : items; - sortable.attr('aria-dropeffect', 'none'); - handles.attr('draggable', false); - handles.off('mousedown.h5s'); -}; -/* - * reload the sortable - * @param [jquery Collection] a single sortable - * @description events need to be removed to not be double bound - */ -var _reloadSortable = function(sortable) { - var opts = sortable.data('opts'); - var items = sortable.children(opts.items); - var handles = opts.handle ? items.find(opts.handle) : items; - // remove event handlers from items - _removeItemEvents(items); - handles.off('mousedown.h5s'); - // remove event handlers from sortable - _removeSortableEvents(sortable); -}; -/* - * public sortable object - * @param [object|string] options|method - */ -var sortable = function(selector, options) { - - var $sortables = $(selector); - var method = String(options); - - options = $.extend({ - connectWith: false, - placeholder: null, - // dragImage can be null or a jQuery element - dragImage: null, - disableIEFix: false, - placeholderClass: 'sortable-placeholder', - draggingClass: 'sortable-dragging' - }, options); - - /* TODO: maxstatements should be 25, fix and remove line below */ - /*jshint maxstatements:false */ - return $sortables.each(function() { - - var $sortable = $(this); - - if (/enable|disable|destroy/.test(method)) { - sortable[method]($sortable); - return; - } - - // get options & set options on sortable - options = _getOptions($sortable.data('opts'), options); - $sortable.data('opts', options); - // reset sortable - _reloadSortable($sortable); - // initialize - var items = $sortable.children(options.items); - var index; - var startParent; - var newParent; - var placeholder = (options.placeholder === null) ? $('<' + (/^ul|ol$/i.test(this.tagName) ? 'li' : 'div') + ' class="' + options.placeholderClass + '"/>') : $(options.placeholder).addClass(options.placeholderClass); - - // setup sortable ids - if (!$sortable.attr('data-sortable-id')) { - var id = sortables.length; - sortables[id] = $sortable; - $sortable.attr('data-sortable-id', id); - items.attr('data-item-sortable-id', id); - } - - $sortable.data('items', options.items); - placeholders = placeholders.add(placeholder); - if (options.connectWith) { - $sortable.data('connectWith', options.connectWith); - } - - _enableSortable($sortable); - items.attr('role', 'option'); - items.attr('aria-grabbed', 'false'); - - // Handle drag events on draggable items - items.on('dragstart.h5s', function(e) { - e.stopImmediatePropagation(); - - if (options.dragImage) { - _attachGhost(e.originalEvent, { - item: options.dragImage, - x: 0, - y: 0 - }); - console.log('WARNING: dragImage option is deprecated' + - ' and will be removed in the future!'); - } else { - // add transparent clone or other ghost to cursor - _getGhost(e.originalEvent, $(this), options.dragImage); - } - // cache selsection & add attr for dragging - dragging = $(this); - dragging.addClass(options.draggingClass); - dragging.attr('aria-grabbed', 'true'); - // grab values - index = dragging.index(); - draggingHeight = dragging.height(); - startParent = $(this).parent(); - // trigger sortstar update - dragging.parent().triggerHandler('sortstart', { - item: dragging, - startparent: startParent - }); - }); - // Handle drag events on draggable items - items.on('dragend.h5s', function() { - if (!dragging) { - return; - } - // remove dragging attributes and show item - dragging.removeClass(options.draggingClass); - dragging.attr('aria-grabbed', 'false'); - dragging.show(); - - placeholders.detach(); - newParent = $(this).parent(); - dragging.parent().triggerHandler('sortstop', { - item: dragging, - startparent: startParent, - }); - if (index !== dragging.index() || - startParent.get(0) !== newParent.get(0)) { - dragging.parent().triggerHandler('sortupdate', { - item: dragging, - index: newParent.children(newParent.data('items')).index(dragging), - oldindex: items.index(dragging), - elementIndex: dragging.index(), - oldElementIndex: index, - startparent: startParent, - endparent: newParent - }); - } - dragging = null; - draggingHeight = null; - }); - // Handle drop event on sortable & placeholder - // TODO: REMOVE placeholder????? - $(this).add([placeholder]).on('drop.h5s', function(e) { - if (!_listsConnected($sortable, $(dragging).parent())) { - return; - } - - e.stopPropagation(); - placeholders.filter(':visible').after(dragging); - dragging.trigger('dragend.h5s'); - return false; - }); - - // Handle dragover and dragenter events on draggable items - // TODO: REMOVE placeholder????? - items.add([this, placeholder]).on('dragover.h5s dragenter.h5s', function(e) { - if (!_listsConnected($sortable, $(dragging).parent())) { - return; - } - - e.preventDefault(); - e.originalEvent.dataTransfer.dropEffect = 'move'; - if (items.is(this)) { - var thisHeight = $(this).height(); - if (options.forcePlaceholderSize) { - placeholder.height(draggingHeight); - } - - // Check if $(this) is bigger than the draggable. If it is, we have to define a dead zone to prevent flickering - if (thisHeight > draggingHeight) { - // Dead zone? - var deadZone = thisHeight - draggingHeight; - var offsetTop = $(this).offset().top; - if (placeholder.index() < $(this).index() && - e.originalEvent.pageY < offsetTop + deadZone) { - return false; - } - if (placeholder.index() > $(this).index() && - e.originalEvent.pageY > offsetTop + thisHeight - deadZone) { - return false; - } - } - - dragging.hide(); - if (placeholder.index() < $(this).index()) { - $(this).after(placeholder); - } else { - $(this).before(placeholder); - } - placeholders.not(placeholder).detach(); - } else { - if (!placeholders.is(this) && !$(this).children(options.items).length) { - placeholders.detach(); - $(this).append(placeholder); - } - } - return false; - }); - }); -}; - -sortable.destroy = function(sortable) { - _destroySortable(sortable); -}; - -sortable.enable = function(sortable) { - _enableSortable(sortable); -}; - -sortable.disable = function(sortable) { - _disableSortable(sortable); -}; - -$.fn.sortable = function(options) { - return sortable(this, options); -}; - -return sortable; -})); -; -'use strict'; - -System.register('flarum/tags/addTagChangePermission', ['flarum/extend', 'flarum/components/PermissionGrid', 'flarum/components/SettingDropdown'], function (_export, _context) { - "use strict"; - - var extend, PermissionGrid, SettingDropdown; - - _export('default', function () { - extend(PermissionGrid.prototype, 'startItems', function (items) { - items.add('allowTagChange', { - icon: 'tag', - label: app.translator.trans('flarum-tags.admin.permissions.allow_edit_tags_label'), - setting: function setting() { - var minutes = parseInt(app.data.settings.allow_tag_change, 10); - - return SettingDropdown.component({ - defaultLabel: minutes ? app.translator.transChoice('core.admin.permissions_controls.allow_some_minutes_button', minutes, { count: minutes }) : app.translator.trans('core.admin.permissions_controls.allow_indefinitely_button'), - key: 'allow_tag_change', - options: [{ value: '-1', label: app.translator.trans('core.admin.permissions_controls.allow_indefinitely_button') }, { value: '10', label: app.translator.trans('core.admin.permissions_controls.allow_ten_minutes_button') }, { value: 'reply', label: app.translator.trans('core.admin.permissions_controls.allow_until_reply_button') }] - }); - } - }, 90); - }); - }); - - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - }, function (_flarumComponentsPermissionGrid) { - PermissionGrid = _flarumComponentsPermissionGrid.default; - }, function (_flarumComponentsSettingDropdown) { - SettingDropdown = _flarumComponentsSettingDropdown.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('flarum/tags/addTagPermission', ['flarum/extend', 'flarum/components/PermissionGrid'], function (_export, _context) { - "use strict"; - - var extend, PermissionGrid; - - _export('default', function () { - extend(PermissionGrid.prototype, 'moderateItems', function (items) { - items.add('tag', { - icon: 'tag', - label: app.translator.trans('flarum-tags.admin.permissions.tag_discussions_label'), - permission: 'discussion.tag' - }, 95); - }); - }); - - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - }, function (_flarumComponentsPermissionGrid) { - PermissionGrid = _flarumComponentsPermissionGrid.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('flarum/tags/addTagsHomePageOption', ['flarum/extend', 'flarum/components/BasicsPage'], function (_export, _context) { - "use strict"; - - var extend, BasicsPage; - - _export('default', function () { - extend(BasicsPage.prototype, 'homePageItems', function (items) { - items.add('tags', { - path: '/tags', - label: app.translator.trans('flarum-tags.admin.basics.tags_label') - }); - }); - }); - - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - }, function (_flarumComponentsBasicsPage) { - BasicsPage = _flarumComponentsBasicsPage.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('flarum/tags/addTagsPane', ['flarum/extend', 'flarum/components/AdminNav', 'flarum/components/AdminLinkButton', 'flarum/tags/components/TagsPage'], function (_export, _context) { - "use strict"; - - var extend, AdminNav, AdminLinkButton, TagsPage; - - _export('default', function () { - app.routes.tags = { path: '/tags', component: TagsPage.component() }; - - app.extensionSettings['flarum-tags'] = function () { - return m.route(app.route('tags')); - }; - - extend(AdminNav.prototype, 'items', function (items) { - items.add('tags', AdminLinkButton.component({ - href: app.route('tags'), - icon: 'tags', - children: app.translator.trans('flarum-tags.admin.nav.tags_button'), - description: app.translator.trans('flarum-tags.admin.nav.tags_text') - })); - }); - }); - - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - }, function (_flarumComponentsAdminNav) { - AdminNav = _flarumComponentsAdminNav.default; - }, function (_flarumComponentsAdminLinkButton) { - AdminLinkButton = _flarumComponentsAdminLinkButton.default; - }, function (_flarumTagsComponentsTagsPage) { - TagsPage = _flarumTagsComponentsTagsPage.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('flarum/tags/addTagsPermissionScope', ['flarum/extend', 'flarum/components/PermissionGrid', 'flarum/components/PermissionDropdown', 'flarum/components/Dropdown', 'flarum/components/Button', 'flarum/tags/helpers/tagLabel', 'flarum/tags/helpers/tagIcon', 'flarum/tags/utils/sortTags'], function (_export, _context) { - "use strict"; - - var extend, override, PermissionGrid, PermissionDropdown, Dropdown, Button, tagLabel, tagIcon, sortTags; - - _export('default', function () { - override(app, 'getRequiredPermissions', function (original, permission) { - var tagPrefix = permission.match(/^tag\d+\./); - - if (tagPrefix) { - var globalPermission = permission.substr(tagPrefix[0].length); - - var required = original(globalPermission); - - return required.map(function (required) { - return tagPrefix[0] + required; - }); - } - - return original(permission); - }); - - extend(PermissionGrid.prototype, 'scopeItems', function (items) { - sortTags(app.store.all('tags')).filter(function (tag) { - return tag.isRestricted(); - }).forEach(function (tag) { - return items.add('tag' + tag.id(), { - label: tagLabel(tag), - onremove: function onremove() { - return tag.save({ isRestricted: false }); - }, - render: function render(item) { - if (item.permission === 'viewDiscussions' || item.permission === 'startDiscussion' || item.permission && item.permission.indexOf('discussion.') === 0) { - return PermissionDropdown.component({ - permission: 'tag' + tag.id() + '.' + item.permission, - allowGuest: item.allowGuest - }); - } - - return ''; - } - }); - }); - }); - - extend(PermissionGrid.prototype, 'scopeControlItems', function (items) { - var tags = sortTags(app.store.all('tags').filter(function (tag) { - return !tag.isRestricted(); - })); - - if (tags.length) { - items.add('tag', Dropdown.component({ - className: 'Dropdown--restrictByTag', - buttonClassName: 'Button Button--text', - label: app.translator.trans('flarum-tags.admin.permissions.restrict_by_tag_heading'), - icon: 'plus', - caretIcon: null, - children: tags.map(function (tag) { - return Button.component({ - icon: true, - children: [tagIcon(tag, { className: 'Button-icon' }), ' ', tag.name()], - onclick: function onclick() { - return tag.save({ isRestricted: true }); - } - }); - }) - })); - } - }); - }); - - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - override = _flarumExtend.override; - }, function (_flarumComponentsPermissionGrid) { - PermissionGrid = _flarumComponentsPermissionGrid.default; - }, function (_flarumComponentsPermissionDropdown) { - PermissionDropdown = _flarumComponentsPermissionDropdown.default; - }, function (_flarumComponentsDropdown) { - Dropdown = _flarumComponentsDropdown.default; - }, function (_flarumComponentsButton) { - Button = _flarumComponentsButton.default; - }, function (_flarumTagsHelpersTagLabel) { - tagLabel = _flarumTagsHelpersTagLabel.default; - }, function (_flarumTagsHelpersTagIcon) { - tagIcon = _flarumTagsHelpersTagIcon.default; - }, function (_flarumTagsUtilsSortTags) { - sortTags = _flarumTagsUtilsSortTags.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('flarum/tags/components/EditTagModal', ['flarum/components/Modal', 'flarum/components/Button', 'flarum/utils/string', 'flarum/tags/helpers/tagLabel'], function (_export, _context) { - "use strict"; - - var Modal, Button, slug, tagLabel, EditTagModal; - return { - setters: [function (_flarumComponentsModal) { - Modal = _flarumComponentsModal.default; - }, function (_flarumComponentsButton) { - Button = _flarumComponentsButton.default; - }, function (_flarumUtilsString) { - slug = _flarumUtilsString.slug; - }, function (_flarumTagsHelpersTagLabel) { - tagLabel = _flarumTagsHelpersTagLabel.default; - }], - execute: function () { - EditTagModal = function (_Modal) { - babelHelpers.inherits(EditTagModal, _Modal); - - function EditTagModal() { - babelHelpers.classCallCheck(this, EditTagModal); - return babelHelpers.possibleConstructorReturn(this, (EditTagModal.__proto__ || Object.getPrototypeOf(EditTagModal)).apply(this, arguments)); - } - - babelHelpers.createClass(EditTagModal, [{ - key: 'init', - value: function init() { - babelHelpers.get(EditTagModal.prototype.__proto__ || Object.getPrototypeOf(EditTagModal.prototype), 'init', this).call(this); - - this.tag = this.props.tag || app.store.createRecord('tags'); - - this.name = m.prop(this.tag.name() || ''); - this.slug = m.prop(this.tag.slug() || ''); - this.description = m.prop(this.tag.description() || ''); - this.color = m.prop(this.tag.color() || ''); - this.isHidden = m.prop(this.tag.isHidden() || false); - } - }, { - key: 'className', - value: function className() { - return 'EditTagModal Modal--small'; - } - }, { - key: 'title', - value: function title() { - return this.name() ? tagLabel({ - name: this.name, - color: this.color - }) : app.translator.trans('flarum-tags.admin.edit_tag.title'); - } - }, { - key: 'content', - value: function content() { - var _this2 = this; - - return m( - 'div', - { className: 'Modal-body' }, - m( - 'div', - { className: 'Form' }, - m( - 'div', - { className: 'Form-group' }, - m( - 'label', - null, - app.translator.trans('flarum-tags.admin.edit_tag.name_label') - ), - m('input', { className: 'FormControl', placeholder: app.translator.trans('flarum-tags.admin.edit_tag.name_placeholder'), value: this.name(), oninput: function oninput(e) { - _this2.name(e.target.value); - _this2.slug(slug(e.target.value)); - } }) - ), - m( - 'div', - { className: 'Form-group' }, - m( - 'label', - null, - app.translator.trans('flarum-tags.admin.edit_tag.slug_label') - ), - m('input', { className: 'FormControl', value: this.slug(), oninput: m.withAttr('value', this.slug) }) - ), - m( - 'div', - { className: 'Form-group' }, - m( - 'label', - null, - app.translator.trans('flarum-tags.admin.edit_tag.description_label') - ), - m('textarea', { className: 'FormControl', value: this.description(), oninput: m.withAttr('value', this.description) }) - ), - m( - 'div', - { className: 'Form-group' }, - m( - 'label', - null, - app.translator.trans('flarum-tags.admin.edit_tag.color_label') - ), - m('input', { className: 'FormControl', placeholder: '#aaaaaa', value: this.color(), oninput: m.withAttr('value', this.color) }) - ), - m( - 'div', - { className: 'Form-group' }, - m( - 'div', - null, - m( - 'label', - { className: 'checkbox' }, - m('input', { type: 'checkbox', value: '1', checked: this.isHidden(), onchange: m.withAttr('checked', this.isHidden) }), - app.translator.trans('flarum-tags.admin.edit_tag.hide_label') - ) - ) - ), - m( - 'div', - { className: 'Form-group' }, - Button.component({ - type: 'submit', - className: 'Button Button--primary EditTagModal-save', - loading: this.loading, - children: app.translator.trans('flarum-tags.admin.edit_tag.submit_button') - }), - this.tag.exists ? m( - 'button', - { type: 'button', className: 'Button EditTagModal-delete', onclick: this.delete.bind(this) }, - app.translator.trans('flarum-tags.admin.edit_tag.delete_tag_button') - ) : '' - ) - ) - ); - } - }, { - key: 'submitData', - value: function submitData() { - return { - name: this.name(), - slug: this.slug(), - description: this.description(), - color: this.color(), - isHidden: this.isHidden() - }; - } - }, { - key: 'onsubmit', - value: function onsubmit(e) { - var _this3 = this; - - e.preventDefault(); - - this.loading = true; - - this.tag.save(this.submitData()).then(function () { - return _this3.hide(); - }, function (response) { - _this3.loading = false; - _this3.handleErrors(response); - }); - } - }, { - key: 'delete', - value: function _delete() { - var _this4 = this; - - if (confirm(app.translator.trans('flarum-tags.admin.edit_tag.delete_tag_confirmation'))) { - var children = app.store.all('tags').filter(function (tag) { - return tag.parent() === _this4.tag; - }); - - this.tag.delete().then(function () { - children.forEach(function (tag) { - return tag.pushData({ - attributes: { isChild: false }, - relationships: { parent: null } - }); - }); - m.redraw(); - }); - - this.hide(); - } - } - }]); - return EditTagModal; - }(Modal); - - _export('default', EditTagModal); - } - }; -});; -'use strict'; - -System.register('flarum/tags/components/TagSettingsModal', ['flarum/components/SettingsModal'], function (_export, _context) { - "use strict"; - - var SettingsModal, TagSettingsModal; - return { - setters: [function (_flarumComponentsSettingsModal) { - SettingsModal = _flarumComponentsSettingsModal.default; - }], - execute: function () { - TagSettingsModal = function (_SettingsModal) { - babelHelpers.inherits(TagSettingsModal, _SettingsModal); - - function TagSettingsModal() { - babelHelpers.classCallCheck(this, TagSettingsModal); - return babelHelpers.possibleConstructorReturn(this, (TagSettingsModal.__proto__ || Object.getPrototypeOf(TagSettingsModal)).apply(this, arguments)); - } - - babelHelpers.createClass(TagSettingsModal, [{ - key: 'setMinTags', - value: function setMinTags(minTags, maxTags, value) { - minTags(value); - maxTags(Math.max(value, maxTags())); - } - }, { - key: 'className', - value: function className() { - return 'TagSettingsModal Modal--small'; - } - }, { - key: 'title', - value: function title() { - return app.translator.trans('flarum-tags.admin.tag_settings.title'); - } - }, { - key: 'form', - value: function form() { - var minPrimaryTags = this.setting('flarum-tags.min_primary_tags', 0); - var maxPrimaryTags = this.setting('flarum-tags.max_primary_tags', 0); - - var minSecondaryTags = this.setting('flarum-tags.min_secondary_tags', 0); - var maxSecondaryTags = this.setting('flarum-tags.max_secondary_tags', 0); - - return [m( - 'div', - { className: 'Form-group' }, - m( - 'label', - null, - app.translator.trans('flarum-tags.admin.tag_settings.required_primary_heading') - ), - m( - 'div', - { className: 'helpText' }, - app.translator.trans('flarum-tags.admin.tag_settings.required_primary_text') - ), - m( - 'div', - { className: 'TagSettingsModal-rangeInput' }, - m('input', { className: 'FormControl', - type: 'number', - min: '0', - value: minPrimaryTags(), - oninput: m.withAttr('value', this.setMinTags.bind(this, minPrimaryTags, maxPrimaryTags)) }), - app.translator.trans('flarum-tags.admin.tag_settings.range_separator_text'), - m('input', { className: 'FormControl', - type: 'number', - min: minPrimaryTags(), - bidi: maxPrimaryTags }) - ) - ), m( - 'div', - { className: 'Form-group' }, - m( - 'label', - null, - app.translator.trans('flarum-tags.admin.tag_settings.required_secondary_heading') - ), - m( - 'div', - { className: 'helpText' }, - app.translator.trans('flarum-tags.admin.tag_settings.required_secondary_text') - ), - m( - 'div', - { className: 'TagSettingsModal-rangeInput' }, - m('input', { className: 'FormControl', - type: 'number', - min: '0', - value: minSecondaryTags(), - oninput: m.withAttr('value', this.setMinTags.bind(this, minSecondaryTags, maxSecondaryTags)) }), - app.translator.trans('flarum-tags.admin.tag_settings.range_separator_text'), - m('input', { className: 'FormControl', - type: 'number', - min: minSecondaryTags(), - bidi: maxSecondaryTags }) - ) - )]; - } - }]); - return TagSettingsModal; - }(SettingsModal); - - _export('default', TagSettingsModal); - } - }; -});; -'use strict'; - -System.register('flarum/tags/components/TagsPage', ['flarum/components/Page', 'flarum/components/Button', 'flarum/tags/components/EditTagModal', 'flarum/tags/components/TagSettingsModal', 'flarum/tags/helpers/tagIcon', 'flarum/tags/utils/sortTags'], function (_export, _context) { - "use strict"; - - var Page, Button, EditTagModal, TagSettingsModal, tagIcon, sortTags, TagsPage; - - - function tagItem(tag) { - return m( - 'li', - { 'data-id': tag.id(), style: { color: tag.color() } }, - m( - 'div', - { className: 'TagListItem-info' }, - tagIcon(tag), - m( - 'span', - { className: 'TagListItem-name' }, - tag.name() - ), - Button.component({ - className: 'Button Button--link', - icon: 'pencil', - onclick: function onclick() { - return app.modal.show(new EditTagModal({ tag: tag })); - } - }) - ), - !tag.isChild() && tag.position() !== null ? m( - 'ol', - { className: 'TagListItem-children' }, - sortTags(app.store.all('tags')).filter(function (child) { - return child.parent() === tag; - }).map(tagItem) - ) : '' - ); - } - - return { - setters: [function (_flarumComponentsPage) { - Page = _flarumComponentsPage.default; - }, function (_flarumComponentsButton) { - Button = _flarumComponentsButton.default; - }, function (_flarumTagsComponentsEditTagModal) { - EditTagModal = _flarumTagsComponentsEditTagModal.default; - }, function (_flarumTagsComponentsTagSettingsModal) { - TagSettingsModal = _flarumTagsComponentsTagSettingsModal.default; - }, function (_flarumTagsHelpersTagIcon) { - tagIcon = _flarumTagsHelpersTagIcon.default; - }, function (_flarumTagsUtilsSortTags) { - sortTags = _flarumTagsUtilsSortTags.default; - }], - execute: function () { - TagsPage = function (_Page) { - babelHelpers.inherits(TagsPage, _Page); - - function TagsPage() { - babelHelpers.classCallCheck(this, TagsPage); - return babelHelpers.possibleConstructorReturn(this, (TagsPage.__proto__ || Object.getPrototypeOf(TagsPage)).apply(this, arguments)); - } - - babelHelpers.createClass(TagsPage, [{ - key: 'view', - value: function view() { - return m( - 'div', - { className: 'TagsPage' }, - m( - 'div', - { className: 'TagsPage-header' }, - m( - 'div', - { className: 'container' }, - m( - 'p', - null, - app.translator.trans('flarum-tags.admin.tags.about_tags_text') - ), - Button.component({ - className: 'Button Button--primary', - icon: 'plus', - children: app.translator.trans('flarum-tags.admin.tags.create_tag_button'), - onclick: function onclick() { - return app.modal.show(new EditTagModal()); - } - }), - Button.component({ - className: 'Button', - children: app.translator.trans('flarum-tags.admin.tags.settings_button'), - onclick: function onclick() { - return app.modal.show(new TagSettingsModal()); - } - }) - ) - ), - m( - 'div', - { className: 'TagsPage-list' }, - m( - 'div', - { className: 'container' }, - m( - 'div', - { className: 'TagGroup' }, - m( - 'label', - null, - app.translator.trans('flarum-tags.admin.tags.primary_heading') - ), - m( - 'ol', - { className: 'TagList TagList--primary' }, - sortTags(app.store.all('tags')).filter(function (tag) { - return tag.position() !== null && !tag.isChild(); - }).map(tagItem) - ) - ), - m( - 'div', - { className: 'TagGroup' }, - m( - 'label', - null, - app.translator.trans('flarum-tags.admin.tags.secondary_heading') - ), - m( - 'ul', - { className: 'TagList' }, - app.store.all('tags').filter(function (tag) { - return tag.position() === null; - }).sort(function (a, b) { - return a.name().localeCompare(b.name()); - }).map(tagItem) - ) - ) - ) - ) - ); - } - }, { - key: 'config', - value: function config() { - var _this2 = this; - - this.$('ol, ul').sortable({ connectWith: 'primary' }).on('sortupdate', function (e, ui) { - // If we've moved a tag from 'primary' to 'secondary', then we'll update - // its attributes in our local store so that when we redraw the change - // will be made. - if (ui.startparent.is('ol') && ui.endparent.is('ul')) { - app.store.getById('tags', ui.item.data('id')).pushData({ - attributes: { - position: null, - isChild: false - }, - relationships: { parent: null } - }); - } - - // Construct an array of primary tag IDs and their children, in the same - // order that they have been arranged in. - var order = _this2.$('.TagList--primary > li').map(function () { - return { - id: $(this).data('id'), - children: $(this).find('li').map(function () { - return $(this).data('id'); - }).get() - }; - }).get(); - - // Now that we have an accurate representation of the order which the - // primary tags are in, we will update the tag attributes in our local - // store to reflect this order. - order.forEach(function (tag, i) { - var parent = app.store.getById('tags', tag.id); - parent.pushData({ - attributes: { - position: i, - isChild: false - }, - relationships: { parent: null } - }); - - tag.children.forEach(function (child, j) { - app.store.getById('tags', child).pushData({ - attributes: { - position: j, - isChild: true - }, - relationships: { parent: parent } - }); - }); - }); - - app.request({ - url: app.forum.attribute('apiUrl') + '/tags/order', - method: 'POST', - data: { order: order } - }); - - // A diff redraw won't work here, because sortable has mucked around - // with the DOM which will confuse Mithril's diffing algorithm. Instead - // we force a full reconstruction of the DOM. - m.redraw.strategy('all'); - m.redraw(); - }); - } - }]); - return TagsPage; - }(Page); - - _export('default', TagsPage); - } - }; -});; -'use strict'; - -System.register('flarum/tags/helpers/tagIcon', [], function (_export, _context) { - "use strict"; - - function tagIcon(tag) { - var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - - attrs.className = 'icon TagIcon ' + (attrs.className || ''); - - if (tag) { - attrs.style = attrs.style || {}; - attrs.style.backgroundColor = tag.color(); - } else { - attrs.className += ' untagged'; - } - - return m('span', attrs); - } - - _export('default', tagIcon); - - return { - setters: [], - execute: function () {} - }; -});; -'use strict'; - -System.register('flarum/tags/helpers/tagLabel', ['flarum/utils/extract'], function (_export, _context) { - "use strict"; - - var extract; - function tagLabel(tag) { - var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - - attrs.style = attrs.style || {}; - attrs.className = 'TagLabel ' + (attrs.className || ''); - - var link = extract(attrs, 'link'); - - if (tag) { - var color = tag.color(); - if (color) { - attrs.style.backgroundColor = attrs.style.color = color; - attrs.className += ' colored'; - } - - if (link) { - attrs.title = tag.description() || ''; - attrs.href = app.route('tag', { tags: tag.slug() }); - attrs.config = m.route; - } - } else { - attrs.className += ' untagged'; - } - - return m(link ? 'a' : 'span', attrs, m( - 'span', - { className: 'TagLabel-text' }, - tag ? tag.name() : app.translator.trans('flarum-tags.lib.deleted_tag_text') - )); - } - - _export('default', tagLabel); - - return { - setters: [function (_flarumUtilsExtract) { - extract = _flarumUtilsExtract.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('flarum/tags/helpers/tagsLabel', ['flarum/utils/extract', 'flarum/tags/helpers/tagLabel', 'flarum/tags/utils/sortTags'], function (_export, _context) { - "use strict"; - - var extract, tagLabel, sortTags; - function tagsLabel(tags) { - var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - - var children = []; - var link = extract(attrs, 'link'); - - attrs.className = 'TagsLabel ' + (attrs.className || ''); - - if (tags) { - sortTags(tags).forEach(function (tag) { - if (tag || tags.length === 1) { - children.push(tagLabel(tag, { link: link })); - } - }); - } else { - children.push(tagLabel()); - } - - return m( - 'span', - attrs, - children - ); - } - - _export('default', tagsLabel); - - return { - setters: [function (_flarumUtilsExtract) { - extract = _flarumUtilsExtract.default; - }, function (_flarumTagsHelpersTagLabel) { - tagLabel = _flarumTagsHelpersTagLabel.default; - }, function (_flarumTagsUtilsSortTags) { - sortTags = _flarumTagsUtilsSortTags.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('flarum/tags/main', ['flarum/tags/models/Tag', 'flarum/tags/addTagsPermissionScope', 'flarum/tags/addTagPermission', 'flarum/tags/addTagsPane', 'flarum/tags/addTagsHomePageOption', 'flarum/tags/addTagChangePermission'], function (_export, _context) { - "use strict"; - - var Tag, addTagsPermissionScope, addTagPermission, addTagsPane, addTagsHomePageOption, addTagChangePermission; - return { - setters: [function (_flarumTagsModelsTag) { - Tag = _flarumTagsModelsTag.default; - }, function (_flarumTagsAddTagsPermissionScope) { - addTagsPermissionScope = _flarumTagsAddTagsPermissionScope.default; - }, function (_flarumTagsAddTagPermission) { - addTagPermission = _flarumTagsAddTagPermission.default; - }, function (_flarumTagsAddTagsPane) { - addTagsPane = _flarumTagsAddTagsPane.default; - }, function (_flarumTagsAddTagsHomePageOption) { - addTagsHomePageOption = _flarumTagsAddTagsHomePageOption.default; - }, function (_flarumTagsAddTagChangePermission) { - addTagChangePermission = _flarumTagsAddTagChangePermission.default; - }], - execute: function () { - - app.initializers.add('flarum-tags', function (app) { - app.store.models.tags = Tag; - - addTagsPermissionScope(); - addTagPermission(); - addTagsPane(); - addTagsHomePageOption(); - addTagChangePermission(); - }); - } - }; -});; -'use strict'; - -System.register('flarum/tags/models/Tag', ['flarum/Model', 'flarum/utils/mixin', 'flarum/utils/computed'], function (_export, _context) { - "use strict"; - - var Model, mixin, computed, Tag; - return { - setters: [function (_flarumModel) { - Model = _flarumModel.default; - }, function (_flarumUtilsMixin) { - mixin = _flarumUtilsMixin.default; - }, function (_flarumUtilsComputed) { - computed = _flarumUtilsComputed.default; - }], - execute: function () { - Tag = function (_mixin) { - babelHelpers.inherits(Tag, _mixin); - - function Tag() { - babelHelpers.classCallCheck(this, Tag); - return babelHelpers.possibleConstructorReturn(this, (Tag.__proto__ || Object.getPrototypeOf(Tag)).apply(this, arguments)); - } - - return Tag; - }(mixin(Model, { - name: Model.attribute('name'), - slug: Model.attribute('slug'), - description: Model.attribute('description'), - - color: Model.attribute('color'), - backgroundUrl: Model.attribute('backgroundUrl'), - backgroundMode: Model.attribute('backgroundMode'), - - position: Model.attribute('position'), - parent: Model.hasOne('parent'), - defaultSort: Model.attribute('defaultSort'), - isChild: Model.attribute('isChild'), - isHidden: Model.attribute('isHidden'), - - discussionsCount: Model.attribute('discussionsCount'), - lastTime: Model.attribute('lastTime', Model.transformDate), - lastDiscussion: Model.hasOne('lastDiscussion'), - - isRestricted: Model.attribute('isRestricted'), - canStartDiscussion: Model.attribute('canStartDiscussion'), - canAddToDiscussion: Model.attribute('canAddToDiscussion'), - - isPrimary: computed('position', 'parent', function (position, parent) { - return position !== null && parent === false; - }) - })); - - _export('default', Tag); - } - }; -});; -"use strict"; - -System.register("flarum/tags/utils/sortTags", [], function (_export, _context) { - "use strict"; - - function sortTags(tags) { - return tags.slice(0).sort(function (a, b) { - var aPos = a.position(); - var bPos = b.position(); - - // If they're both secondary tags, sort them by their discussions count, - // descending. - if (aPos === null && bPos === null) return b.discussionsCount() - a.discussionsCount(); - - // If just one is a secondary tag, then the primary tag should - // come first. - if (bPos === null) return -1; - if (aPos === null) return 1; - - // If we've made it this far, we know they're both primary tags. So we'll - // need to see if they have parents. - var aParent = a.parent(); - var bParent = b.parent(); - - // If they both have the same parent, then their positions are local, - // so we can compare them directly. - if (aParent === bParent) return aPos - bPos; - - // If they are both child tags, then we will compare the positions of their - // parents. - else if (aParent && bParent) return aParent.position() - bParent.position(); - - // If we are comparing a child tag with its parent, then we let the parent - // come first. If we are comparing an unrelated parent/child, then we - // compare both of the parents. - else if (aParent) return aParent === b ? 1 : aParent.position() - bPos;else if (bParent) return bParent === a ? -1 : aPos - bParent.position(); - - return 0; - }); - } - - _export("default", sortTags); - - return { - setters: [], - execute: function () {} - }; -}); \ No newline at end of file diff --git a/extensions/tags/js/admin/package.json b/extensions/tags/js/admin/package.json deleted file mode 100644 index 19a7865d9..000000000 --- a/extensions/tags/js/admin/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "private": true, - "devDependencies": { - "gulp": "^3.9.1", - "flarum-gulp": "^0.2.0" - } -} diff --git a/extensions/tags/js/admin/src/main.js b/extensions/tags/js/admin/src/main.js deleted file mode 100644 index 1847c517b..000000000 --- a/extensions/tags/js/admin/src/main.js +++ /dev/null @@ -1,16 +0,0 @@ -import Tag from 'flarum/tags/models/Tag'; -import addTagsPermissionScope from 'flarum/tags/addTagsPermissionScope'; -import addTagPermission from 'flarum/tags/addTagPermission'; -import addTagsPane from 'flarum/tags/addTagsPane'; -import addTagsHomePageOption from 'flarum/tags/addTagsHomePageOption'; -import addTagChangePermission from 'flarum/tags/addTagChangePermission'; - -app.initializers.add('flarum-tags', app => { - app.store.models.tags = Tag; - - addTagsPermissionScope(); - addTagPermission(); - addTagsPane(); - addTagsHomePageOption(); - addTagChangePermission(); -}); diff --git a/extensions/tags/js/dist/admin.js b/extensions/tags/js/dist/admin.js new file mode 100644 index 000000000..2901a8138 --- /dev/null +++ b/extensions/tags/js/dist/admin.js @@ -0,0 +1,2 @@ +module.exports=function(t){var n={};function a(e){if(n[e])return n[e].exports;var r=n[e]={i:e,l:!1,exports:{}};return t[e].call(r.exports,r,r.exports,a),r.l=!0,r.exports}return a.m=t,a.c=n,a.d=function(t,n,e){a.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},a.t=function(t,n){if(1&n&&(t=a(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(a.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var r in t)a.d(e,r,function(n){return t[n]}.bind(null,r));return e},a.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(n,"a",n),n},a.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},a.p="",a(a.s=84)}([function(t,n){t.exports=flarum.core.compat.Model},function(t,n){t.exports=flarum.core.compat.extend},function(t,n,a){"use strict";a.d(n,"a",function(){return o});var e=a(30),r=a.n(e);function o(t,n){t.prototype=r()(n.prototype),t.prototype.constructor=t,t.__proto__=n}},function(t,n,a){"use strict";function e(t){return t.slice(0).sort(function(t,n){var a=t.position(),e=n.position();if(null===a&&null===e)return n.discussionsCount()-t.discussionsCount();if(null===e)return-1;if(null===a)return 1;var r=t.parent(),o=n.parent();return r===o?a-e:r&&o?r.position()-o.position():r?r===n?1:r.position()-e:o?o===t?-1:a-o.position():0})}a.d(n,"a",function(){return e})},,function(t,n,a){"use strict";a.d(n,"a",function(){return o});var e=a(13),r=a.n(e);function o(t,n){void 0===n&&(n={}),n.style=n.style||{},n.className="TagLabel "+(n.className||"");var a=r()(n,"link");if(t){var e=t.color();e&&(n.style.backgroundColor=n.style.color=e,n.className+=" colored"),a&&(n.title=t.description()||"",n.href=app.route("tag",{tags:t.slug()}),n.config=m.route)}else n.className+=" untagged";return m(a?"a":"span",n,m("span",{className:"TagLabel-text"},t?t.name():app.translator.trans("flarum-tags.lib.deleted_tag_text")))}},function(t,n){t.exports=flarum.core.compat["components/Button"]},function(t,n,a){"use strict";function e(t,n){return void 0===n&&(n={}),n.className="icon TagIcon "+(n.className||""),t?(n.style=n.style||{},n.style.backgroundColor=t.color()):n.className+=" untagged",m("span",n)}a.d(n,"a",function(){return e})},function(t,n,a){t.exports=!a(16)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,n){var a=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=a)},function(t,n){var a=t.exports={version:"2.5.7"};"number"==typeof __e&&(__e=a)},function(t,n){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,n,a){var e=a(11);t.exports=function(t){if(!e(t))throw TypeError(t+" is not an object!");return t}},function(t,n){t.exports=flarum.core.compat["utils/extract"]},function(t,n,a){"use strict";a.d(n,"a",function(){return c});var e=a(2),r=a(0),o=a.n(r),i=a(29),s=a.n(i),u=a(28),l=a.n(u),c=function(t){function n(){return t.apply(this,arguments)||this}return Object(e.a)(n,t),n}(s()(o.a,{name:o.a.attribute("name"),slug:o.a.attribute("slug"),description:o.a.attribute("description"),color:o.a.attribute("color"),backgroundUrl:o.a.attribute("backgroundUrl"),backgroundMode:o.a.attribute("backgroundMode"),position:o.a.attribute("position"),parent:o.a.hasOne("parent"),defaultSort:o.a.attribute("defaultSort"),isChild:o.a.attribute("isChild"),isHidden:o.a.attribute("isHidden"),discussionsCount:o.a.attribute("discussionsCount"),lastTime:o.a.attribute("lastTime",o.a.transformDate),lastDiscussion:o.a.hasOne("lastDiscussion"),isRestricted:o.a.attribute("isRestricted"),canStartDiscussion:o.a.attribute("canStartDiscussion"),canAddToDiscussion:o.a.attribute("canAddToDiscussion"),isPrimary:l()("position","parent",function(t,n){return null!==t&&!1===n})}))},function(t,n){t.exports=flarum.core.compat["components/PermissionGrid"]},function(t,n){t.exports=function(t){try{return!!t()}catch(t){return!0}}},,function(t,n){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,n,a){var e=a(45)("keys"),r=a(43);t.exports=function(t){return e[t]||(e[t]=r(t))}},function(t,n){var a=Math.ceil,e=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?e:a)(t)}},function(t,n,a){var e=a(33),r=a(32);t.exports=function(t){return e(r(t))}},function(t,n){var a={}.hasOwnProperty;t.exports=function(t,n){return a.call(t,n)}},function(t,n,a){var e=a(11),r=a(9).document,o=e(r)&&e(r.createElement);t.exports=function(t){return o?r.createElement(t):{}}},function(t,n,a){var e=a(12),r=a(53),o=a(52),i=Object.defineProperty;n.f=a(8)?Object.defineProperty:function(t,n,a){if(e(t),n=o(n,!0),e(a),r)try{return i(t,n,a)}catch(t){}if("get"in a||"set"in a)throw TypeError("Accessors not supported!");return"value"in a&&(t[n]=a.value),t}},function(t,n){},function(t,n){t.exports=flarum.core.compat["components/Modal"]},function(t,n){t.exports=flarum.core.compat["components/Page"]},function(t,n){t.exports=flarum.core.compat["utils/computed"]},function(t,n){t.exports=flarum.core.compat["utils/mixin"]},function(t,n,a){t.exports=a(42)},,function(t,n){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,n,a){var e=a(49);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==e(t)?t.split(""):Object(t)}},function(t,n,a){var e=a(50),r=a(18);t.exports=Object.keys||function(t){return e(t,r)}},function(t,n,a){var e=a(9),r=a(10),o=a(56),i=a(54),s=a(22),u=function(t,n,a){var l,c,p,d=t&u.F,f=t&u.G,m=t&u.S,g=t&u.P,h=t&u.B,v=t&u.W,b=f?r:r[n]||(r[n]={}),y=b.prototype,_=f?e:m?e[n]:(e[n]||{}).prototype;for(l in f&&(a=n),a)(c=!d&&_&&void 0!==_[l])&&s(b,l)||(p=c?_[l]:a[l],b[l]=f&&"function"!=typeof _[l]?a[l]:h&&c?o(p,e):v&&_[l]==p?function(t){var n=function(n,a,e){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(n);case 2:return new t(n,a)}return new t(n,a,e)}return t.apply(this,arguments)};return n.prototype=t.prototype,n}(p):g&&"function"==typeof p?o(Function.call,p):p,g&&((b.virtual||(b.virtual={}))[l]=p,t&u.R&&y&&!y[l]&&i(y,l,p)))};u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,t.exports=u},,,function(t,n,a){var e=a(9).document;t.exports=e&&e.documentElement},function(t,n,a){var e=a(24),r=a(12),o=a(34);t.exports=a(8)?Object.defineProperties:function(t,n){r(t);for(var a,i=o(n),s=i.length,u=0;s>u;)e.f(t,a=i[u++],n[a]);return t}},function(t,n,a){var e=a(12),r=a(39),o=a(18),i=a(19)("IE_PROTO"),s=function(){},u=function(){var t,n=a(23)("iframe"),e=o.length;for(n.style.display="none",a(38).appendChild(n),n.src="javascript:",(t=n.contentWindow.document).open(),t.write("