mirror of
https://github.com/flarum/framework.git
synced 2025-04-25 06:04:04 +08:00
Merge remote-tracking branch 'extensions_embed/REWRITE'
This commit is contained in:
commit
a7107700eb
19
extensions/embed/.editorconfig
Normal file
19
extensions/embed/.editorconfig
Normal file
@ -0,0 +1,19 @@
|
||||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.{diff,md}]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{php,xml,json}]
|
||||
indent_size = 4
|
18
extensions/embed/.gitattributes
vendored
Normal file
18
extensions/embed/.gitattributes
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.gitmodules export-ignore
|
||||
.github export-ignore
|
||||
.travis export-ignore
|
||||
.travis.yml export-ignore
|
||||
.editorconfig export-ignore
|
||||
.styleci.yml export-ignore
|
||||
|
||||
phpunit.xml export-ignore
|
||||
tests export-ignore
|
||||
|
||||
js/dist/* -diff
|
||||
js/dist/* linguist-generated
|
||||
js/dist-typings/* linguist-generated
|
||||
js/yarn.lock -diff
|
||||
|
||||
* text=auto eol=lf
|
15
extensions/embed/.github/workflows/backend.yml
vendored
Normal file
15
extensions/embed/.github/workflows/backend.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
name: Embed PHP
|
||||
|
||||
on: [workflow_dispatch, push, pull_request]
|
||||
|
||||
# The reusable workflow definitions will be moved to the `flarum/framework` repo soon.
|
||||
# This will break your current script.
|
||||
# When this happens, run `flarum-cli audit infra --fix` to update your infrastructure.
|
||||
|
||||
jobs:
|
||||
run:
|
||||
uses: flarum/.github/.github/workflows/REUSABLE_backend.yml@main
|
||||
with:
|
||||
enable_backend_testing: false
|
||||
|
||||
backend_directory: .
|
21
extensions/embed/.github/workflows/frontend.yml
vendored
Normal file
21
extensions/embed/.github/workflows/frontend.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: Embed JS
|
||||
|
||||
on: [workflow_dispatch, push, pull_request]
|
||||
|
||||
# The reusable workflow definitions will be moved to the `flarum/framework` repo soon.
|
||||
# This will break your current script.
|
||||
# When this happens, run `flarum-cli audit infra --fix` to update your infrastructure.
|
||||
|
||||
jobs:
|
||||
run:
|
||||
uses: flarum/.github/.github/workflows/REUSABLE_frontend.yml@main
|
||||
with:
|
||||
enable_bundlewatch: false
|
||||
enable_prettier: true
|
||||
enable_typescript: false
|
||||
|
||||
frontend_directory: ./js
|
||||
main_git_branch: master
|
||||
|
||||
secrets:
|
||||
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
|
12
extensions/embed/.gitignore
vendored
Normal file
12
extensions/embed/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/vendor
|
||||
composer.lock
|
||||
composer.phar
|
||||
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
tests/.phpunit.result.cache
|
||||
/tests/integration/tmp
|
||||
.vagrant
|
||||
.idea/*
|
||||
.vscode
|
||||
js/coverage-ts
|
14
extensions/embed/.styleci.yml
Normal file
14
extensions/embed/.styleci.yml
Normal file
@ -0,0 +1,14 @@
|
||||
preset: recommended
|
||||
|
||||
enabled:
|
||||
- logical_not_operators_with_successor_space
|
||||
|
||||
disabled:
|
||||
- align_double_arrow
|
||||
- blank_line_after_opening_tag
|
||||
- multiline_array_trailing_comma
|
||||
- new_with_braces
|
||||
- phpdoc_align
|
||||
- phpdoc_order
|
||||
- phpdoc_separation
|
||||
- phpdoc_types
|
47
extensions/embed/CHANGELOG.md
Normal file
47
extensions/embed/CHANGELOG.md
Normal file
@ -0,0 +1,47 @@
|
||||
# Changelog
|
||||
|
||||
## [1.2.0](https://github.com/flarum/embed/compare/v1.1.0...v1.2.0)
|
||||
|
||||
No changes.
|
||||
|
||||
## [1.1.0](https://github.com/flarum/embed/compare/v1.0.0...v1.1.0)
|
||||
|
||||
No changes.
|
||||
|
||||
## [1.0.0](https://github.com/flarum/embed/compare/v0.1.0-beta.16...v1.0.0)
|
||||
|
||||
### Changed
|
||||
- Compatibility with Flarum v1.0.0.
|
||||
|
||||
## [0.1.0-beta.16](https://github.com/flarum/embed/compare/v0.1.0-beta.15...v0.1.0-beta.16)
|
||||
|
||||
### Changed
|
||||
- Replaced `app()` helper with `resolve()`.
|
||||
|
||||
## [0.1.0-beta.15](https://github.com/flarum/embed/compare/v0.1.0-beta.14...v0.1.0-beta.15)
|
||||
|
||||
### Changed
|
||||
- Updated composer.json and admin javascript for new admin area.
|
||||
|
||||
## [0.1.0-beta.14](https://github.com/flarum/embed/compare/v0.1.0-beta.13...v0.1.0-beta.14)
|
||||
|
||||
### Changed
|
||||
- Updated mithril to version 2
|
||||
- Updated JS dependencies
|
||||
|
||||
## [0.1.0-beta.13](https://github.com/flarum/embed/compare/v0.1.0-beta.12...v0.1.0-beta.13)
|
||||
|
||||
### Changed
|
||||
- Updated JS dependencies
|
||||
|
||||
## [0.1.0-beta.10](https://github.com/flarum/embed/compare/v0.1.0-beta.9...v0.1.0-beta.10)
|
||||
|
||||
### Fixed
|
||||
- JavaScript code was not compiled (#6)
|
||||
- Icon was not updated for FontAwesome 5 (#6)
|
||||
|
||||
## [0.1.0-beta.9](https://github.com/flarum/embed/compare/v0.1.0-beta.8...v0.1.0-beta.9)
|
||||
|
||||
### Fixed
|
||||
- JS: Vulnerable lodash dependency ([1a1a724](https://github.com/flarum/embed/commit/1a1a72477bfa1eec5da3a09aaf70a5942616d65d))
|
||||
|
22
extensions/embed/LICENSE
Normal file
22
extensions/embed/LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019-2021 Stichting Flarum (Flarum Foundation)
|
||||
Copyright (c) 2014-2019 Toby Zerner (toby.zerner@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
60
extensions/embed/composer.json
Normal file
60
extensions/embed/composer.json
Normal file
@ -0,0 +1,60 @@
|
||||
{
|
||||
"name": "flarum/embed",
|
||||
"description": "Embed Flarum discussions as comments for your blog.",
|
||||
"type": "flarum-extension",
|
||||
"keywords": [
|
||||
"discussion"
|
||||
],
|
||||
"license": "MIT",
|
||||
"support": {
|
||||
"issues": "https://github.com/flarum/core/issues",
|
||||
"source": "https://github.com/flarum/embed",
|
||||
"forum": "https://discuss.flarum.org"
|
||||
},
|
||||
"homepage": "https://flarum.org",
|
||||
"funding": [
|
||||
{
|
||||
"type": "website",
|
||||
"url": "https://flarum.org/donate/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"flarum/core": "^1.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Flarum\\Embed\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
},
|
||||
"flarum-extension": {
|
||||
"title": "Embed",
|
||||
"category": "feature",
|
||||
"icon": {
|
||||
"name": "fas fa-code",
|
||||
"backgroundColor": "#B9D233",
|
||||
"color": "#fff"
|
||||
}
|
||||
},
|
||||
"flarum-cli": {
|
||||
"modules": {
|
||||
"admin": false,
|
||||
"forum": true,
|
||||
"js": true,
|
||||
"jsCommon": false,
|
||||
"css": true,
|
||||
"gitConf": true,
|
||||
"githubActions": true,
|
||||
"prettier": true,
|
||||
"typescript": false,
|
||||
"bundlewatch": false,
|
||||
"backendTesting": false,
|
||||
"editorConfig": true,
|
||||
"styleci": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
extensions/embed/extend.php
Normal file
32
extensions/embed/extend.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Frontend\Document;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
return [
|
||||
(new Extend\Frontend('forum'))
|
||||
->route(
|
||||
'/embed/{id:\d+(?:-[^/]*)?}[/{near:[^/]*}]',
|
||||
'embed.discussion',
|
||||
function (Document $document, Request $request) {
|
||||
// Add the discussion content to the document so that the
|
||||
// payload will be included on the page and the JS app will be
|
||||
// able to render the discussion immediately.
|
||||
resolve(Flarum\Forum\Content\Discussion::class)($document, $request);
|
||||
|
||||
resolve(Flarum\Frontend\Content\Assets::class)->forFrontend('embed')($document, $request);
|
||||
}
|
||||
),
|
||||
|
||||
(new Extend\Frontend('embed'))
|
||||
->js(__DIR__.'/js/dist/forum.js')
|
||||
->css(__DIR__.'/less/forum.less')
|
||||
];
|
9
extensions/embed/js/.gitignore
vendored
Normal file
9
extensions/embed/js/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/sdks
|
||||
!.yarn/versions
|
||||
|
||||
node_modules
|
2
extensions/embed/js/dist/forum.js
generated
vendored
Normal file
2
extensions/embed/js/dist/forum.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
extensions/embed/js/dist/forum.js.map
generated
vendored
Normal file
1
extensions/embed/js/dist/forum.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
extensions/embed/js/forum.js
Normal file
1
extensions/embed/js/forum.js
Normal file
@ -0,0 +1 @@
|
||||
export * from './src/forum';
|
22
extensions/embed/js/package.json
Normal file
22
extensions/embed/js/package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "@flarum/embed",
|
||||
"prettier": "@flarum/prettier-config",
|
||||
"dependencies": {
|
||||
"iframe-resizer": "^4.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.5.1",
|
||||
"flarum-webpack-config": "^2.0.0",
|
||||
"webpack": "^5.65.0",
|
||||
"webpack-cli": "^4.9.1",
|
||||
"@flarum/prettier-config": "^1.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "webpack --mode development --watch",
|
||||
"build": "webpack --mode production",
|
||||
"format": "prettier --write src",
|
||||
"format-check": "prettier --check src",
|
||||
"analyze": "cross-env ANALYZER=true yarn build"
|
||||
}
|
||||
}
|
80
extensions/embed/js/src/forum/index.js
Normal file
80
extensions/embed/js/src/forum/index.js
Normal file
@ -0,0 +1,80 @@
|
||||
import 'iframe-resizer/js/iframeResizer.contentWindow.js';
|
||||
|
||||
import { override, extend } from 'flarum/common/extend';
|
||||
import app from 'flarum/forum/app';
|
||||
import Stream from 'flarum/common/utils/Stream';
|
||||
import ForumApplication from 'flarum/forum/ForumApplication';
|
||||
import Composer from 'flarum/forum/components/Composer';
|
||||
import PostStream from 'flarum/forum/components/PostStream';
|
||||
import ModalManager from 'flarum/common/components/ModalManager';
|
||||
import PostMeta from 'flarum/forum/components/PostMeta';
|
||||
|
||||
import DiscussionPage from 'flarum/forum/components/DiscussionPage';
|
||||
|
||||
extend(ForumApplication.prototype, 'mount', function () {
|
||||
if (m.route.param('hideFirstPost')) {
|
||||
extend(PostStream.prototype, 'view', (vdom) => {
|
||||
if (vdom.children[0].attrs['data-number'] === 1) {
|
||||
vdom.children.splice(0, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
override(m.route.Link, 'view', function (original, vnode) {
|
||||
vnode.attrs.href = vnode.attrs.href.replace('/embed', '/d');
|
||||
vnode.attrs.target = '_blank';
|
||||
// TODO: If href leads to a post within this discussion that we have
|
||||
// already loaded, then scroll to it?
|
||||
return original(vnode);
|
||||
});
|
||||
|
||||
// Trim the /embed prefix off of post permalinks
|
||||
override(PostMeta.prototype, 'getPermalink', (original, post) => {
|
||||
return original(post).replace('/embed', '/d');
|
||||
});
|
||||
|
||||
app.pageInfo = Stream({});
|
||||
|
||||
const reposition = function () {
|
||||
const info = app.pageInfo();
|
||||
this.$().css('top', Math.max(0, info.scrollTop - info.offsetTop));
|
||||
};
|
||||
|
||||
extend(ModalManager.prototype, 'show', reposition);
|
||||
extend(Composer.prototype, 'show', reposition);
|
||||
|
||||
window.iFrameResizer = {
|
||||
readyCallback: function () {
|
||||
window.parentIFrame.getPageInfo(app.pageInfo);
|
||||
},
|
||||
};
|
||||
|
||||
extend(PostStream.prototype, 'goToNumber', function (promise, number) {
|
||||
if (number === 'reply' && 'parentIFrame' in window && app.composer.isFullScreen()) {
|
||||
const itemTop = this.$('.PostStream-item:last').offset().top;
|
||||
window.parentIFrame.scrollToOffset(0, itemTop);
|
||||
}
|
||||
});
|
||||
|
||||
extend(DiscussionPage.prototype, 'sidebarItems', function (items) {
|
||||
items.remove('scrubber');
|
||||
|
||||
const count = this.discussion.replyCount();
|
||||
|
||||
items.add(
|
||||
'replies',
|
||||
<h3>
|
||||
<a route={app.route.discussion(this.discussion).replace('/embed', '/d')}>
|
||||
{count} comment{count == 1 ? '' : 's'}
|
||||
</a>
|
||||
</h3>,
|
||||
100
|
||||
);
|
||||
|
||||
const attrs = items.get('controls').attrs;
|
||||
attrs.className = attrs.className.replace('App-primaryControl', '');
|
||||
});
|
||||
|
||||
app.routes['discussion'] = { path: '/embed/:id', component: DiscussionPage };
|
||||
app.routes['discussion.near'] = { path: '/embed/:id/:near', component: DiscussionPage };
|
1
extensions/embed/js/webpack.config.js
Normal file
1
extensions/embed/js/webpack.config.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('flarum-webpack-config')();
|
2843
extensions/embed/js/yarn.lock
Normal file
2843
extensions/embed/js/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
110
extensions/embed/less/forum.less
Normal file
110
extensions/embed/less/forum.less
Normal file
@ -0,0 +1,110 @@
|
||||
.container {
|
||||
width: auto;
|
||||
padding: 0 20px;
|
||||
|
||||
@media @phone {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
.App {
|
||||
padding-top: 0;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
|
||||
&:before {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.App-content {
|
||||
border-top: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
.Composer {
|
||||
margin-left: 0 !important;
|
||||
margin-right: 0 !important;
|
||||
}
|
||||
.DiscussionHero {
|
||||
display: none;
|
||||
}
|
||||
.DiscussionPage-nav {
|
||||
width: auto;
|
||||
float: none;
|
||||
|
||||
@media @tablet-up {
|
||||
height: 70px;
|
||||
}
|
||||
|
||||
> ul {
|
||||
.header-background();
|
||||
border-bottom: 0;
|
||||
height: auto !important;
|
||||
list-style: none;
|
||||
padding: 15px 0;
|
||||
margin: 0;
|
||||
width: auto;
|
||||
|
||||
@media @phone {
|
||||
position: static;
|
||||
}
|
||||
@media @tablet-up {
|
||||
padding: 15px 15px;
|
||||
|
||||
.scrolled & {
|
||||
.box-shadow(0 2px 6px @shadow-color);
|
||||
}
|
||||
}
|
||||
|
||||
> li {
|
||||
margin: 0 15px 0 0;
|
||||
display: inline-block;
|
||||
}
|
||||
.item-replies {
|
||||
@media @phone {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-weight: normal;
|
||||
margin: 0;
|
||||
|
||||
&, a {
|
||||
color: @muted-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.ButtonGroup {
|
||||
&, .Button {
|
||||
width: auto !important;
|
||||
}
|
||||
.Dropdown-toggle {
|
||||
width: 36px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
.DiscussionPage-stream {
|
||||
margin-right: 0;
|
||||
}
|
||||
.Post-stream {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
@media @phone {
|
||||
.Dropdown .Dropdown-menu {
|
||||
position: absolute;
|
||||
bottom: auto;
|
||||
top: auto;
|
||||
right: auto !important;
|
||||
padding-bottom: 0 !important;
|
||||
.transition(none);
|
||||
|
||||
&.Dropdown-menu--right {
|
||||
left: auto !important;
|
||||
right: 0 !important;
|
||||
}
|
||||
}
|
||||
.Composer:not(.minimized) {
|
||||
height: 400px !important;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user