mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 14:20:47 +08:00
Repo maintenance (#30)
* Bump deps; add TS support; use Prettier * Format * Update js/package.json Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update lockfile Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
parent
3e962c5e0f
commit
3e3fa6535d
6731
extensions/sticky/js/package-lock.json
generated
6731
extensions/sticky/js/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -1,13 +1,21 @@
|
||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "@flarum/sticky",
|
"name": "@flarum/sticky",
|
||||||
|
"prettier": "@flarum/prettier-config",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"flarum-webpack-config": "0.1.0-beta.10",
|
"flarum-webpack-config": "^1.0.0",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.46.0",
|
||||||
"webpack-cli": "^3.3.11"
|
"webpack-cli": "^4.7.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "webpack --mode development --watch",
|
"dev": "webpack --mode development --watch",
|
||||||
"build": "webpack --mode production"
|
"build": "webpack --mode production",
|
||||||
|
"format": "prettier --write src",
|
||||||
|
"format-check": "prettier --check src"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@flarum/prettier-config": "^1.0.0",
|
||||||
|
"flarum-tsconfig": "^1.0.0",
|
||||||
|
"prettier": "^2.3.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import app from 'flarum/app';
|
import app from 'flarum/app';
|
||||||
|
|
||||||
app.initializers.add('flarum-sticky', () => {
|
app.initializers.add('flarum-sticky', () => {
|
||||||
app.extensionData
|
app.extensionData.for('flarum-sticky').registerPermission(
|
||||||
.for('flarum-sticky')
|
{
|
||||||
.registerPermission({
|
|
||||||
icon: 'fas fa-thumbtack',
|
icon: 'fas fa-thumbtack',
|
||||||
label: app.translator.trans('flarum-sticky.admin.permissions.sticky_discussions_label'),
|
label: app.translator.trans('flarum-sticky.admin.permissions.sticky_discussions_label'),
|
||||||
permission: 'discussion.sticky'
|
permission: 'discussion.sticky',
|
||||||
}, 'moderate', 95);
|
},
|
||||||
|
'moderate',
|
||||||
|
95
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,13 +3,17 @@ import Discussion from 'flarum/models/Discussion';
|
||||||
import Badge from 'flarum/components/Badge';
|
import Badge from 'flarum/components/Badge';
|
||||||
|
|
||||||
export default function addStickyBadge() {
|
export default function addStickyBadge() {
|
||||||
extend(Discussion.prototype, 'badges', function(badges) {
|
extend(Discussion.prototype, 'badges', function (badges) {
|
||||||
if (this.isSticky()) {
|
if (this.isSticky()) {
|
||||||
badges.add('sticky', Badge.component({
|
badges.add(
|
||||||
|
'sticky',
|
||||||
|
Badge.component({
|
||||||
type: 'sticky',
|
type: 'sticky',
|
||||||
label: app.translator.trans('flarum-sticky.forum.badge.sticky_tooltip'),
|
label: app.translator.trans('flarum-sticky.forum.badge.sticky_tooltip'),
|
||||||
icon: 'fas fa-thumbtack'
|
icon: 'fas fa-thumbtack',
|
||||||
}), 10);
|
}),
|
||||||
|
10
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,27 @@ import DiscussionPage from 'flarum/components/DiscussionPage';
|
||||||
import Button from 'flarum/components/Button';
|
import Button from 'flarum/components/Button';
|
||||||
|
|
||||||
export default function addStickyControl() {
|
export default function addStickyControl() {
|
||||||
extend(DiscussionControls, 'moderationControls', function(items, discussion) {
|
extend(DiscussionControls, 'moderationControls', function (items, discussion) {
|
||||||
if (discussion.canSticky()) {
|
if (discussion.canSticky()) {
|
||||||
items.add('sticky', Button.component({
|
items.add(
|
||||||
|
'sticky',
|
||||||
|
Button.component(
|
||||||
|
{
|
||||||
icon: 'fas fa-thumbtack',
|
icon: 'fas fa-thumbtack',
|
||||||
onclick: this.stickyAction.bind(discussion)
|
onclick: this.stickyAction.bind(discussion),
|
||||||
}, app.translator.trans(discussion.isSticky() ? 'flarum-sticky.forum.discussion_controls.unsticky_button' : 'flarum-sticky.forum.discussion_controls.sticky_button')));
|
},
|
||||||
|
app.translator.trans(
|
||||||
|
discussion.isSticky()
|
||||||
|
? 'flarum-sticky.forum.discussion_controls.unsticky_button'
|
||||||
|
: 'flarum-sticky.forum.discussion_controls.sticky_button'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
DiscussionControls.stickyAction = function() {
|
DiscussionControls.stickyAction = function () {
|
||||||
this.save({isSticky: !this.isSticky()}).then(() => {
|
this.save({ isSticky: !this.isSticky() }).then(() => {
|
||||||
if (app.current.matches(DiscussionPage)) {
|
if (app.current.matches(DiscussionPage)) {
|
||||||
app.current.get('stream').update();
|
app.current.get('stream').update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,13 @@ import IndexPage from 'flarum/components/IndexPage';
|
||||||
import { truncate } from 'flarum/utils/string';
|
import { truncate } from 'flarum/utils/string';
|
||||||
|
|
||||||
export default function addStickyControl() {
|
export default function addStickyControl() {
|
||||||
extend(DiscussionListState.prototype, 'requestParams', function(params) {
|
extend(DiscussionListState.prototype, 'requestParams', function (params) {
|
||||||
if (app.current.matches(IndexPage) || app.current.matches(DiscussionPage)) {
|
if (app.current.matches(IndexPage) || app.current.matches(DiscussionPage)) {
|
||||||
params.include.push('firstPost');
|
params.include.push('firstPost');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
extend(DiscussionListItem.prototype, 'infoItems', function(items) {
|
extend(DiscussionListItem.prototype, 'infoItems', function (items) {
|
||||||
const discussion = this.attrs.discussion;
|
const discussion = this.attrs.discussion;
|
||||||
|
|
||||||
if (discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) {
|
if (discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) {
|
||||||
|
|
|
@ -19,4 +19,3 @@ app.initializers.add('flarum-sticky', () => {
|
||||||
addStickyExcerpt();
|
addStickyExcerpt();
|
||||||
addStickyClass();
|
addStickyClass();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
14
extensions/sticky/js/tsconfig.json
Normal file
14
extensions/sticky/js/tsconfig.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
// Use Flarum's tsconfig as a starting point
|
||||||
|
"extends": "flarum-tsconfig",
|
||||||
|
// This will match all .ts, .tsx, .d.ts, .js, .jsx files
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"compilerOptions": {
|
||||||
|
// This will output typings to `dist-typings`
|
||||||
|
"declarationDir": "./dist-typings",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user