mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-04 14:46:57 -05:00
Load EasyMDE/CodeMirror dynamically, remove RequireEasyMDE (#18069)
This PR makes frontend load EasyMDE/CodeMirror dynamically, and removes `RequireEasyMDE`.
This commit is contained in:
parent
0572c78938
commit
a38ba634a4
@ -254,7 +254,6 @@ func FileHistory(ctx *context.Context) {
|
|||||||
func Diff(ctx *context.Context) {
|
func Diff(ctx *context.Context) {
|
||||||
ctx.Data["PageIsDiff"] = true
|
ctx.Data["PageIsDiff"] = true
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
|
|
||||||
userName := ctx.Repo.Owner.Name
|
userName := ctx.Repo.Owner.Name
|
||||||
|
@ -764,7 +764,6 @@ func CompareDiff(ctx *context.Context) {
|
|||||||
ctx.Data["IsRepoToolbarCommits"] = true
|
ctx.Data["IsRepoToolbarCommits"] = true
|
||||||
ctx.Data["IsDiffCompare"] = true
|
ctx.Data["IsDiffCompare"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
setTemplateIfExists(ctx, pullRequestTemplateKey, nil, pullRequestTemplateCandidates)
|
setTemplateIfExists(ctx, pullRequestTemplateKey, nil, pullRequestTemplateCandidates)
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
upload.AddUploadContext(ctx, "comment")
|
upload.AddUploadContext(ctx, "comment")
|
||||||
|
@ -69,7 +69,6 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
|||||||
ctx.Data["PageIsEdit"] = true
|
ctx.Data["PageIsEdit"] = true
|
||||||
ctx.Data["IsNewFile"] = isNewFile
|
ctx.Data["IsNewFile"] = isNewFile
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
canCommit := renderCommitRights(ctx)
|
canCommit := renderCommitRights(ctx)
|
||||||
|
|
||||||
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
||||||
@ -200,7 +199,6 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
|
|||||||
ctx.Data["PageHasPosted"] = true
|
ctx.Data["PageHasPosted"] = true
|
||||||
ctx.Data["IsNewFile"] = isNewFile
|
ctx.Data["IsNewFile"] = isNewFile
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["TreePath"] = form.TreePath
|
ctx.Data["TreePath"] = form.TreePath
|
||||||
ctx.Data["TreeNames"] = treeNames
|
ctx.Data["TreeNames"] = treeNames
|
||||||
ctx.Data["TreePaths"] = treePaths
|
ctx.Data["TreePaths"] = treePaths
|
||||||
@ -544,7 +542,6 @@ func DeleteFilePost(ctx *context.Context) {
|
|||||||
func UploadFile(ctx *context.Context) {
|
func UploadFile(ctx *context.Context) {
|
||||||
ctx.Data["PageIsUpload"] = true
|
ctx.Data["PageIsUpload"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
upload.AddUploadContext(ctx, "repo")
|
upload.AddUploadContext(ctx, "repo")
|
||||||
canCommit := renderCommitRights(ctx)
|
canCommit := renderCommitRights(ctx)
|
||||||
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
||||||
@ -580,7 +577,6 @@ func UploadFilePost(ctx *context.Context) {
|
|||||||
form := web.GetForm(ctx).(*forms.UploadRepoFileForm)
|
form := web.GetForm(ctx).(*forms.UploadRepoFileForm)
|
||||||
ctx.Data["PageIsUpload"] = true
|
ctx.Data["PageIsUpload"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
upload.AddUploadContext(ctx, "repo")
|
upload.AddUploadContext(ctx, "repo")
|
||||||
canCommit := renderCommitRights(ctx)
|
canCommit := renderCommitRights(ctx)
|
||||||
|
|
||||||
|
@ -789,7 +789,6 @@ func NewIssue(ctx *context.Context) {
|
|||||||
ctx.Data["PageIsIssueList"] = true
|
ctx.Data["PageIsIssueList"] = true
|
||||||
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||||
title := ctx.FormString("title")
|
title := ctx.FormString("title")
|
||||||
@ -962,7 +961,6 @@ func NewIssuePost(ctx *context.Context) {
|
|||||||
ctx.Data["PageIsIssueList"] = true
|
ctx.Data["PageIsIssueList"] = true
|
||||||
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
upload.AddUploadContext(ctx, "comment")
|
upload.AddUploadContext(ctx, "comment")
|
||||||
@ -1147,7 +1145,6 @@ func ViewIssue(ctx *context.Context) {
|
|||||||
|
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects)
|
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects)
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
upload.AddUploadContext(ctx, "comment")
|
upload.AddUploadContext(ctx, "comment")
|
||||||
|
@ -738,7 +738,6 @@ func ViewPullFiles(ctx *context.Context) {
|
|||||||
setCompareContext(ctx, baseCommit, commit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
setCompareContext(ctx, baseCommit, commit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||||
|
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil {
|
if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil {
|
||||||
ctx.ServerError("GetAssignees", err)
|
ctx.ServerError("GetAssignees", err)
|
||||||
@ -1098,7 +1097,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
|
|||||||
ctx.Data["IsDiffCompare"] = true
|
ctx.Data["IsDiffCompare"] = true
|
||||||
ctx.Data["IsRepoToolbarCommits"] = true
|
ctx.Data["IsRepoToolbarCommits"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
|
@ -262,7 +262,6 @@ func LatestRelease(ctx *context.Context) {
|
|||||||
func NewRelease(ctx *context.Context) {
|
func NewRelease(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
|
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
|
||||||
ctx.Data["PageIsReleaseList"] = true
|
ctx.Data["PageIsReleaseList"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
|
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
|
||||||
if tagName := ctx.FormString("tag"); len(tagName) > 0 {
|
if tagName := ctx.FormString("tag"); len(tagName) > 0 {
|
||||||
@ -296,7 +295,6 @@ func NewReleasePost(ctx *context.Context) {
|
|||||||
form := web.GetForm(ctx).(*forms.NewReleaseForm)
|
form := web.GetForm(ctx).(*forms.NewReleaseForm)
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
|
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
|
||||||
ctx.Data["PageIsReleaseList"] = true
|
ctx.Data["PageIsReleaseList"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
@ -415,7 +413,6 @@ func EditRelease(ctx *context.Context) {
|
|||||||
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
|
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
|
||||||
ctx.Data["PageIsReleaseList"] = true
|
ctx.Data["PageIsReleaseList"] = true
|
||||||
ctx.Data["PageIsEditRelease"] = true
|
ctx.Data["PageIsEditRelease"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
upload.AddUploadContext(ctx, "release")
|
upload.AddUploadContext(ctx, "release")
|
||||||
@ -454,7 +451,6 @@ func EditReleasePost(ctx *context.Context) {
|
|||||||
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
|
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
|
||||||
ctx.Data["PageIsReleaseList"] = true
|
ctx.Data["PageIsReleaseList"] = true
|
||||||
ctx.Data["PageIsEditRelease"] = true
|
ctx.Data["PageIsEditRelease"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
|
|
||||||
tagName := ctx.Params("*")
|
tagName := ctx.Params("*")
|
||||||
|
@ -622,7 +622,6 @@ func WikiRaw(ctx *context.Context) {
|
|||||||
func NewWiki(ctx *context.Context) {
|
func NewWiki(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
|
|
||||||
if !ctx.Repo.Repository.HasWiki() {
|
if !ctx.Repo.Repository.HasWiki() {
|
||||||
ctx.Data["title"] = "Home"
|
ctx.Data["title"] = "Home"
|
||||||
@ -639,7 +638,6 @@ func NewWikiPost(ctx *context.Context) {
|
|||||||
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(http.StatusOK, tplWikiNew)
|
ctx.HTML(http.StatusOK, tplWikiNew)
|
||||||
@ -677,7 +675,6 @@ func NewWikiPost(ctx *context.Context) {
|
|||||||
func EditWiki(ctx *context.Context) {
|
func EditWiki(ctx *context.Context) {
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
ctx.Data["PageIsWikiEdit"] = true
|
ctx.Data["PageIsWikiEdit"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
|
|
||||||
if !ctx.Repo.Repository.HasWiki() {
|
if !ctx.Repo.Repository.HasWiki() {
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
||||||
@ -697,7 +694,6 @@ func EditWikiPost(ctx *context.Context) {
|
|||||||
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
ctx.Data["RequireEasyMDE"] = true
|
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(http.StatusOK, tplWikiNew)
|
ctx.HTML(http.StatusOK, tplWikiNew)
|
||||||
|
@ -12,14 +12,6 @@
|
|||||||
{{template "custom/body_outer_post" .}}
|
{{template "custom/body_outer_post" .}}
|
||||||
|
|
||||||
{{template "base/footer_content" .}}
|
{{template "base/footer_content" .}}
|
||||||
{{if .RequireEasyMDE}}
|
|
||||||
<script src="{{AssetUrlPrefix}}/js/easymde.js?v={{MD5 AppVer}}"></script>
|
|
||||||
<script src="{{AssetUrlPrefix}}/vendor/plugins/codemirror/addon/mode/loadmode.js"></script>
|
|
||||||
<script src="{{AssetUrlPrefix}}/vendor/plugins/codemirror/mode/meta.js"></script>
|
|
||||||
<script>
|
|
||||||
CodeMirror.modeURL = '{{AssetUrlPrefix}}/vendor/plugins/codemirror/mode/%N/%N.js';
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
<!-- Third-party libraries -->
|
<!-- Third-party libraries -->
|
||||||
{{if .RequireU2F}}
|
{{if .RequireU2F}}
|
||||||
|
@ -59,9 +59,6 @@
|
|||||||
</script>
|
</script>
|
||||||
<link rel="icon" href="{{AssetUrlPrefix}}/img/logo.svg" type="image/svg+xml">
|
<link rel="icon" href="{{AssetUrlPrefix}}/img/logo.svg" type="image/svg+xml">
|
||||||
<link rel="alternate icon" href="{{AssetUrlPrefix}}/img/favicon.png" type="image/png">
|
<link rel="alternate icon" href="{{AssetUrlPrefix}}/img/favicon.png" type="image/png">
|
||||||
{{if .RequireEasyMDE}}
|
|
||||||
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/easymde.css?v={{MD5 AppVer}}">
|
|
||||||
{{end}}
|
|
||||||
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{MD5 AppVer}}">
|
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{MD5 AppVer}}">
|
||||||
<noscript>
|
<noscript>
|
||||||
<style>
|
<style>
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
import EasyMDE from 'easymde';
|
|
||||||
|
|
||||||
import CodeMirror from 'codemirror/lib/codemirror.js';
|
|
||||||
|
|
||||||
window.EasyMDE = EasyMDE;
|
|
||||||
window.CodeMirror = CodeMirror;
|
|
||||||
|
|
@ -1,11 +1,58 @@
|
|||||||
import attachTribute from '../tribute.js';
|
import attachTribute from '../tribute.js';
|
||||||
|
|
||||||
|
const {appSubUrl} = window.config;
|
||||||
|
|
||||||
|
function loadScript(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const script = document.createElement('script');
|
||||||
|
script.async = true;
|
||||||
|
script.addEventListener('load', () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
script.addEventListener('error', (e) => {
|
||||||
|
reject(e.error);
|
||||||
|
});
|
||||||
|
script.src = url;
|
||||||
|
document.body.appendChild(script);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {EasyMDE}
|
||||||
|
*/
|
||||||
|
export async function importEasyMDE() {
|
||||||
|
// for CodeMirror: the plugins should be loaded dynamically
|
||||||
|
// https://github.com/codemirror/CodeMirror/issues/5484
|
||||||
|
// https://github.com/codemirror/CodeMirror/issues/4838
|
||||||
|
|
||||||
|
const [{default: EasyMDE}, {default: CodeMirror}] = await Promise.all([
|
||||||
|
import(/* webpackChunkName: "easymde" */'easymde'),
|
||||||
|
import(/* webpackChunkName: "codemirror" */'codemirror'),
|
||||||
|
import(/* webpackChunkName: "easymde" */'easymde/dist/easymde.min.css'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// CodeMirror plugins must be loaded by a "Plain browser env"
|
||||||
|
window.CodeMirror = CodeMirror;
|
||||||
|
await Promise.all([
|
||||||
|
loadScript(`${appSubUrl}/assets/vendor/plugins/codemirror/addon/mode/loadmode.js`),
|
||||||
|
loadScript(`${appSubUrl}/assets/vendor/plugins/codemirror/mode/meta.js`),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// the loadmode.js/meta.js would set the modeURL/modeInfo properties, so we check it to make sure our loading works
|
||||||
|
if (!CodeMirror.modeURL || !CodeMirror.modeInfo) {
|
||||||
|
throw new Error('failed to load plugins for CodeMirror');
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.modeURL = `${appSubUrl}/assets/vendor/plugins/codemirror/mode/%N/%N.js`;
|
||||||
|
return EasyMDE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create an EasyMDE editor for comment
|
* create an EasyMDE editor for comment
|
||||||
* @param textarea jQuery or HTMLElement
|
* @param textarea jQuery or HTMLElement
|
||||||
* @returns {null|EasyMDE}
|
* @returns {null|EasyMDE}
|
||||||
*/
|
*/
|
||||||
export function createCommentEasyMDE(textarea) {
|
export async function createCommentEasyMDE(textarea) {
|
||||||
if (textarea instanceof jQuery) {
|
if (textarea instanceof jQuery) {
|
||||||
textarea = textarea[0];
|
textarea = textarea[0];
|
||||||
}
|
}
|
||||||
@ -13,12 +60,13 @@ export function createCommentEasyMDE(textarea) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const easyMDE = new window.EasyMDE({
|
const EasyMDE = await importEasyMDE();
|
||||||
|
const easyMDE = new EasyMDE({
|
||||||
autoDownloadFontAwesome: false,
|
autoDownloadFontAwesome: false,
|
||||||
element: textarea,
|
element: textarea,
|
||||||
forceSync: true,
|
forceSync: true,
|
||||||
renderingConfig: {
|
renderingConfig: {
|
||||||
singleLineBreaks: false
|
singleLineBreaks: false,
|
||||||
},
|
},
|
||||||
indentWithTabs: false,
|
indentWithTabs: false,
|
||||||
tabSize: 4,
|
tabSize: 4,
|
||||||
@ -56,7 +104,7 @@ export function createCommentEasyMDE(textarea) {
|
|||||||
className: 'fa fa-file',
|
className: 'fa fa-file',
|
||||||
title: 'Revert to simple textarea',
|
title: 'Revert to simple textarea',
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
const inputField = easyMDE.codemirror.getInputField();
|
const inputField = easyMDE.codemirror.getInputField();
|
||||||
inputField.classList.add('js-quick-submit');
|
inputField.classList.add('js-quick-submit');
|
||||||
@ -64,7 +112,7 @@ export function createCommentEasyMDE(textarea) {
|
|||||||
Enter: () => {
|
Enter: () => {
|
||||||
const tributeContainer = document.querySelector('.tribute-container');
|
const tributeContainer = document.querySelector('.tribute-container');
|
||||||
if (!tributeContainer || tributeContainer.style.display === 'none') {
|
if (!tributeContainer || tributeContainer.style.display === 'none') {
|
||||||
return CodeMirror.Pass;
|
return window.CodeMirror.Pass;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Backspace: (cm) => {
|
Backspace: (cm) => {
|
||||||
@ -72,7 +120,7 @@ export function createCommentEasyMDE(textarea) {
|
|||||||
cm.getInputField().trigger('input');
|
cm.getInputField().trigger('input');
|
||||||
}
|
}
|
||||||
cm.execCommand('delCharBefore');
|
cm.execCommand('delCharBefore');
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
attachTribute(inputField, {mentions: true, emoji: true});
|
attachTribute(inputField, {mentions: true, emoji: true});
|
||||||
attachEasyMDEToElements(easyMDE);
|
attachEasyMDEToElements(easyMDE);
|
@ -1,6 +1,6 @@
|
|||||||
import {initCompReactionSelector} from './comp/ReactionSelector.js';
|
import {initCompReactionSelector} from './comp/ReactionSelector.js';
|
||||||
import {initRepoIssueContentHistory} from './repo-issue-content.js';
|
import {initRepoIssueContentHistory} from './repo-issue-content.js';
|
||||||
import {validateTextareaNonEmpty} from './comp/CommentEasyMDE.js';
|
import {validateTextareaNonEmpty} from './comp/EasyMDE.js';
|
||||||
const {csrfToken} = window.config;
|
const {csrfToken} = window.config;
|
||||||
|
|
||||||
export function initRepoDiffReviewButton() {
|
export function initRepoDiffReviewButton() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {htmlEscape} from 'escape-goat';
|
import {htmlEscape} from 'escape-goat';
|
||||||
import attachTribute from './tribute.js';
|
import attachTribute from './tribute.js';
|
||||||
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/CommentEasyMDE.js';
|
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
|
||||||
import {initCompImagePaste} from './comp/ImagePaste.js';
|
import {initCompImagePaste} from './comp/ImagePaste.js';
|
||||||
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
||||||
|
|
||||||
@ -439,16 +439,17 @@ export function initRepoPullRequestReview() {
|
|||||||
$(`#show-outdated-${id}`).removeClass('hide');
|
$(`#show-outdated-${id}`).removeClass('hide');
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', 'button.comment-form-reply', function (e) {
|
$(document).on('click', 'button.comment-form-reply', async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
const form = $(this).closest('.comment-code-cloud').find('.comment-form');
|
const form = $(this).closest('.comment-code-cloud').find('.comment-form');
|
||||||
form.removeClass('hide');
|
form.removeClass('hide');
|
||||||
const $textarea = form.find('textarea');
|
const $textarea = form.find('textarea');
|
||||||
let easyMDE = getAttachedEasyMDE($textarea);
|
let easyMDE = getAttachedEasyMDE($textarea);
|
||||||
if (!easyMDE) {
|
if (!easyMDE) {
|
||||||
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
await attachTribute($textarea.get(), {mentions: true, emoji: true});
|
||||||
easyMDE = createCommentEasyMDE($textarea);
|
easyMDE = await createCommentEasyMDE($textarea);
|
||||||
}
|
}
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
easyMDE.codemirror.focus();
|
easyMDE.codemirror.focus();
|
||||||
@ -515,8 +516,8 @@ export function initRepoPullRequestReview() {
|
|||||||
td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed');
|
td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed');
|
||||||
td.find("input[name='path']").val(path);
|
td.find("input[name='path']").val(path);
|
||||||
const $textarea = commentCloud.find('textarea');
|
const $textarea = commentCloud.find('textarea');
|
||||||
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
await attachTribute($textarea.get(), {mentions: true, emoji: true});
|
||||||
const easyMDE = createCommentEasyMDE($textarea);
|
const easyMDE = await createCommentEasyMDE($textarea);
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
easyMDE.codemirror.focus();
|
easyMDE.codemirror.focus();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/CommentEasyMDE.js';
|
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
|
||||||
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
||||||
import {initCompImagePaste, initEasyMDEImagePaste} from './comp/ImagePaste.js';
|
import {initCompImagePaste, initEasyMDEImagePaste} from './comp/ImagePaste.js';
|
||||||
import {
|
import {
|
||||||
@ -256,6 +256,7 @@ export function initRepoCommentForm() {
|
|||||||
|
|
||||||
async function onEditContent(event) {
|
async function onEditContent(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
$(this).closest('.dropdown').find('.menu').toggle('visible');
|
$(this).closest('.dropdown').find('.menu').toggle('visible');
|
||||||
const $segment = $(this).closest('.header').next();
|
const $segment = $(this).closest('.header').next();
|
||||||
const $editContentZone = $segment.find('.edit-content-zone');
|
const $editContentZone = $segment.find('.edit-content-zone');
|
||||||
@ -341,7 +342,7 @@ async function onEditContent(event) {
|
|||||||
$tabMenu.find('.preview.item').attr('data-tab', $editContentZone.data('preview'));
|
$tabMenu.find('.preview.item').attr('data-tab', $editContentZone.data('preview'));
|
||||||
$editContentForm.find('.write').attr('data-tab', $editContentZone.data('write'));
|
$editContentForm.find('.write').attr('data-tab', $editContentZone.data('write'));
|
||||||
$editContentForm.find('.preview').attr('data-tab', $editContentZone.data('preview'));
|
$editContentForm.find('.preview').attr('data-tab', $editContentZone.data('preview'));
|
||||||
easyMDE = createCommentEasyMDE($textarea);
|
easyMDE = await createCommentEasyMDE($textarea);
|
||||||
|
|
||||||
initCompMarkupContentPreviewTab($editContentForm);
|
initCompMarkupContentPreviewTab($editContentForm);
|
||||||
if ($dropzone.length === 1) {
|
if ($dropzone.length === 1) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import attachTribute from './tribute.js';
|
import attachTribute from './tribute.js';
|
||||||
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
||||||
import {initEasyMDEImagePaste} from './comp/ImagePaste.js';
|
import {initEasyMDEImagePaste} from './comp/ImagePaste.js';
|
||||||
import {createCommentEasyMDE} from './comp/CommentEasyMDE.js';
|
import {createCommentEasyMDE} from './comp/EasyMDE.js';
|
||||||
|
|
||||||
export function initRepoRelease() {
|
export function initRepoRelease() {
|
||||||
$(document).on('click', '.remove-rel-attach', function() {
|
$(document).on('click', '.remove-rel-attach', function() {
|
||||||
@ -19,11 +19,13 @@ export function initRepoReleaseEditor() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
const $textarea = $editor.find('textarea');
|
const $textarea = $editor.find('textarea');
|
||||||
attachTribute($textarea.get(), {mentions: false, emoji: true});
|
await attachTribute($textarea.get(), {mentions: false, emoji: true});
|
||||||
const $files = $editor.parent().find('.files');
|
const $files = $editor.parent().find('.files');
|
||||||
const easyMDE = createCommentEasyMDE($textarea);
|
const easyMDE = await createCommentEasyMDE($textarea);
|
||||||
initCompMarkupContentPreviewTab($editor);
|
initCompMarkupContentPreviewTab($editor);
|
||||||
const dropzone = $editor.parent().find('.dropzone')[0];
|
const dropzone = $editor.parent().find('.dropzone')[0];
|
||||||
initEasyMDEImagePaste(easyMDE, dropzone, $files);
|
initEasyMDEImagePaste(easyMDE, dropzone, $files);
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
import {initMarkupContent} from '../markup/content.js';
|
import {initMarkupContent} from '../markup/content.js';
|
||||||
import {attachEasyMDEToElements, validateTextareaNonEmpty} from './comp/CommentEasyMDE.js';
|
import {attachEasyMDEToElements, importEasyMDE, validateTextareaNonEmpty} from './comp/EasyMDE.js';
|
||||||
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
||||||
|
|
||||||
const {csrfToken} = window.config;
|
const {csrfToken} = window.config;
|
||||||
|
|
||||||
export function initRepoWikiForm() {
|
async function initRepoWikiFormEditor() {
|
||||||
const $editArea = $('.repository.wiki textarea#edit_area');
|
const $editArea = $('.repository.wiki textarea#edit_area');
|
||||||
|
if (!$editArea.length) return;
|
||||||
|
|
||||||
let sideBySideChanges = 0;
|
let sideBySideChanges = 0;
|
||||||
let sideBySideTimeout = null;
|
let sideBySideTimeout = null;
|
||||||
let hasEasyMDE = true;
|
let hasEasyMDE = true;
|
||||||
|
|
||||||
if ($editArea.length > 0) {
|
|
||||||
const $form = $('.repository.wiki.new .ui.form');
|
const $form = $('.repository.wiki.new .ui.form');
|
||||||
const easyMDE = new window.EasyMDE({
|
const EasyMDE = await importEasyMDE();
|
||||||
|
const easyMDE = new EasyMDE({
|
||||||
autoDownloadFontAwesome: false,
|
autoDownloadFontAwesome: false,
|
||||||
element: $editArea[0],
|
element: $editArea[0],
|
||||||
forceSync: true,
|
forceSync: true,
|
||||||
@ -182,5 +184,8 @@ export function initRepoWikiForm() {
|
|||||||
sideBySideChanges = 10;
|
sideBySideChanges = 10;
|
||||||
});
|
});
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function initRepoWikiForm() {
|
||||||
|
initRepoWikiFormEditor();
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,6 @@ export default {
|
|||||||
'eventsource.sharedworker': [
|
'eventsource.sharedworker': [
|
||||||
resolve(__dirname, 'web_src/js/features/eventsource.sharedworker.js'),
|
resolve(__dirname, 'web_src/js/features/eventsource.sharedworker.js'),
|
||||||
],
|
],
|
||||||
'easymde': [
|
|
||||||
resolve(__dirname, 'web_src/js/easymde.js'),
|
|
||||||
resolve(__dirname, 'node_modules/easymde/dist/easymde.min.css'),
|
|
||||||
],
|
|
||||||
...themes,
|
...themes,
|
||||||
},
|
},
|
||||||
devtool: false,
|
devtool: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user