diff --git a/build/update-locales.sh b/build/update-locales.sh index b7611c0c9a74..596ddfec032b 100755 --- a/build/update-locales.sh +++ b/build/update-locales.sh @@ -1,13 +1,14 @@ -#!/bin/bash +#!/bin/sh -set -e - -SED=sed +# this script runs in alpine image which only has `sh` shell -if [[ $OSTYPE == 'darwin'* ]]; then - # for macOS developers, use "brew install gnu-sed" - SED=gsed +set +e +if sed --version 2>/dev/null | grep -q GNU; then + SED_INPLACE="sed -i" +else + SED_INPLACE="sed -i ''" fi +set -e if [ ! -f ./options/locale/locale_en-US.ini ]; then echo "please run this script in the root directory of the project" @@ -32,7 +33,7 @@ mv ./options/locale/locale_en-US.ini ./options/ # * remove the trailing quote # * unescape the quotes # * eg: key="...\"..." => key=..."... -$SED -i -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ { +$SED_INPLACE -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ { s/^([-.A-Za-z0-9_]+)[ ]*=[ ]*"/\1=/ s/"$// s/\\"/"/g @@ -41,8 +42,8 @@ $SED -i -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ { # * if the escaped line is incomplete like `key="...` or `key=..."`, quote it with backticks # * eg: key="... => key=`"...` # * eg: key=..." => key=`..."` -$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini -$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini +$SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini +$SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini # Remove translation under 25% of en_us baselines=$(wc -l "./options/locale_en-US.ini" | cut -d" " -f1) diff --git a/docs/content/doc/developers/guidelines-frontend.en-us.md b/docs/content/doc/developers/guidelines-frontend.en-us.md index 66d3e83e938c..9ac317f40190 100644 --- a/docs/content/doc/developers/guidelines-frontend.en-us.md +++ b/docs/content/doc/developers/guidelines-frontend.en-us.md @@ -47,6 +47,8 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h 7. Clarify variable types, prefer `elem.disabled = true` instead of `elem.setAttribute('disabled', 'anything')`, prefer `$el.prop('checked', var === 'yes')` instead of `$el.prop('checked', var)`. 8. Use semantic elements, prefer ` + {{else}} - - + + {{end}} {{end}} {{if or (not $.HasComments) $.hidden}} diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index 63cd510221fb..e0ec85f9a6ac 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -1,9 +1,9 @@ {{$file := .file}} {{range $j, $section := $file.Sections}} {{range $k, $line := $section.Lines}} - {{if or $.root.AfterCommitID (ne .GetType 4)}} - - {{if eq .GetType 4}} + + {{if eq .GetType 4}} + {{if $.root.AfterCommitID}} {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} @@ -22,35 +22,38 @@ {{end}} {{else}} - - + {{/* for code file preview page or comment diffs on pull comment pages, do not show the expansion arrows */}} + {{end}} - {{$inlineDiff := $section.GetComputedInlineDiffFor $line $.root.locale -}} - {{if $inlineDiff.EscapeStatus.Escaped}}{{end}} - - {{if eq .GetType 4}} - {{/* - */}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.root.locale}}{{/* - */}} - {{else}} - {{/* - */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/* - */}}{{/* - */}}{{svg "octicon-plus"}}{{/* - */}}{{/* - */}}{{end}}{{/* - */}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.root.locale}}{{/* - */}} - {{end}} - - {{if gt (len $line.Comments) 0}} - - - - {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} - - + {{else}} + + + {{end}} + {{$inlineDiff := $section.GetComputedInlineDiffFor $line $.root.locale -}} + {{if $inlineDiff.EscapeStatus.Escaped}}{{end}} + + {{if eq .GetType 4}} + {{/* + */}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.root.locale}}{{/* + */}} + {{else}} + {{/* + */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/* + */}}{{/* + */}}{{svg "octicon-plus"}}{{/* + */}}{{/* + */}}{{end}}{{/* + */}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.root.locale}}{{/* + */}} {{end}} + + {{if gt (len $line.Comments) 0}} + + + + {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} + + {{end}} {{end}} {{end}} diff --git a/templates/repo/editor/diff_preview.tmpl b/templates/repo/editor/diff_preview.tmpl index e6956648ca8b..e2e922be343c 100644 --- a/templates/repo/editor/diff_preview.tmpl +++ b/templates/repo/editor/diff_preview.tmpl @@ -1,6 +1,6 @@
-
+
{{template "repo/diff/section_unified" dict "file" .File "root" $}} diff --git a/templates/repo/issue/labels/label.tmpl b/templates/repo/issue/labels/label.tmpl index 6e9177aec292..01016281ad3c 100644 --- a/templates/repo/issue/labels/label.tmpl +++ b/templates/repo/issue/labels/label.tmpl @@ -3,5 +3,5 @@ id="label_{{.label.ID}}" href="{{.root.RepoLink}}/{{if or .root.IsPull .root.Issue.IsPull}}pulls{{else}}issues{{end}}?labels={{.label.ID}}"{{/* FIXME: use .root.Issue.Link or create .root.Link */}} > - {{RenderLabel .label}} + {{RenderLabel $.Context .label}} diff --git a/templates/repo/issue/labels/label_list.tmpl b/templates/repo/issue/labels/label_list.tmpl index e8f00fa256ce..2c8ace8d7524 100644 --- a/templates/repo/issue/labels/label_list.tmpl +++ b/templates/repo/issue/labels/label_list.tmpl @@ -31,8 +31,8 @@
  • - {{RenderLabel .}} - {{if .Description}}
    {{.Description | RenderEmoji}}{{end}} + {{RenderLabel $.Context .}} + {{if .Description}}
    {{.Description | RenderEmoji $.Context}}{{end}}
    {{if $.PageIsOrgSettingsLabels}} @@ -70,8 +70,8 @@
  • - {{RenderLabel .}} - {{if .Description}}
    {{.Description | RenderEmoji}}{{end}} + {{RenderLabel $.Context .}} + {{if .Description}}
    {{.Description | RenderEmoji $.Context}}{{end}}
    @@ -232,7 +232,7 @@ {{end}} {{$previousExclusiveScope = $exclusiveScope}}
    - {{if contain $.SelLabelIDs .ID}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel .}} + {{if contain $.SelLabelIDs .ID}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel $.Context .}}
    {{end}} diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index d73fb56fbcef..2918c4359f9d 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -58,7 +58,7 @@ {{.locale.Tr "repo.issues.filter_label_exclude" | Safe}} {{.locale.Tr "repo.issues.filter_label_no_select"}} {{range .Labels}} - {{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if contain $.SelLabelIDs .ID}}{{svg "octicon-check"}}{{end}} {{RenderLabel .}} + {{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if contain $.SelLabelIDs .ID}}{{svg "octicon-check"}}{{end}} {{RenderLabel $.Context .}} {{end}} @@ -162,7 +162,7 @@ diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 1c95dfac3ab6..24c7ac7e4ed4 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -60,8 +60,8 @@
    {{end}} {{$previousExclusiveScope = $exclusiveScope}} - {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} - {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    + {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel $.Context .}} + {{if .Description}}
    {{.Description | RenderEmoji $.Context}}{{end}}
    {{end}}
    @@ -72,8 +72,8 @@
    {{end}} {{$previousExclusiveScope = $exclusiveScope}} - {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} - {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    + {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel $.Context .}} + {{if .Description}}
    {{.Description | RenderEmoji $.Context}}{{end}}
    {{end}} {{else}}
    {{.locale.Tr "repo.issues.new.no_items"}}
    diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 6054e7b86b1c..9f2b7ec2d0cd 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -180,11 +180,11 @@ {{template "shared/user/authorlink" .Poster}} {{if and .AddedLabels (not .RemovedLabels)}} - {{$.locale.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels .AddedLabels $.RepoLink) $createdStr | Safe}} + {{$.locale.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels $.Context .AddedLabels $.RepoLink) $createdStr | Safe}} {{else if and (not .AddedLabels) .RemovedLabels}} - {{$.locale.TrN (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels" (RenderLabels .RemovedLabels $.RepoLink) $createdStr | Safe}} + {{$.locale.TrN (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels" (RenderLabels $.Context .RemovedLabels $.RepoLink) $createdStr | Safe}} {{else}} - {{$.locale.Tr "repo.issues.add_remove_labels" (RenderLabels .AddedLabels $.RepoLink) (RenderLabels .RemovedLabels $.RepoLink) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.add_remove_labels" (RenderLabels $.Context .AddedLabels $.RepoLink) (RenderLabels $.Context .RemovedLabels $.RepoLink) $createdStr | Safe}} {{end}} @@ -231,7 +231,7 @@ {{template "shared/user/avatarlink" Dict "Context" $.Context "user" .Poster}} {{template "shared/user/authorlink" .Poster}} - {{$.locale.Tr "repo.issues.change_title_at" (.OldTitle|RenderEmoji) (.NewTitle|RenderEmoji) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.change_title_at" (.OldTitle|RenderEmoji $.Context) (.NewTitle|RenderEmoji $.Context) $createdStr | Safe}} {{else if eq .Type 11}} @@ -697,6 +697,10 @@ {{else if and (eq .Type 29) (or (gt .CommitsNum 0) .IsForcePush)}} + + {{if and .Issue.IsClosed (gt .ID $.LatestCloseCommentID)}} + {{continue}} + {{end}}
    {{svg "octicon-repo-push"}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 61a6db36aac0..f22873088aac 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -130,8 +130,8 @@
    {{end}} {{$previousExclusiveScope = $exclusiveScope}} - {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} - {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    + {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel $.Context .}} + {{if .Description}}
    {{.Description | RenderEmoji $.Context}}{{end}}
    {{end}}
    {{$previousExclusiveScope := "_no_scope"}} @@ -141,8 +141,8 @@
    {{end}} {{$previousExclusiveScope = $exclusiveScope}} - {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} - {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    + {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel $.Context .}} + {{if .Description}}
    {{.Description | RenderEmoji $.Context}}{{end}}
    {{end}} {{else}}
    {{.locale.Tr "repo.issues.new.no_items"}}
    @@ -487,8 +487,8 @@ {{range .BlockingDependencies}}
    - - #{{.Issue.Index}} {{.Issue.Title | RenderEmoji}} + + #{{.Issue.Index}} {{.Issue.Title | RenderEmoji $.Context}}
    {{.Repository.OwnerName}}/{{.Repository.Name}} @@ -514,8 +514,8 @@ {{range .BlockedByDependencies}}
    - - #{{.Issue.Index}} {{.Issue.Title | RenderEmoji}} + + #{{.Issue.Index}} {{.Issue.Title | RenderEmoji $.Context}}
    {{.Repository.OwnerName}}/{{.Repository.Name}} diff --git a/templates/repo/projects/view.tmpl b/templates/repo/projects/view.tmpl index 1450fdac1c5f..f6bc6e1a42a6 100644 --- a/templates/repo/projects/view.tmpl +++ b/templates/repo/projects/view.tmpl @@ -245,7 +245,7 @@ {{if or .Labels .Assignees}}
    {{range .Labels}} - {{RenderLabel .}} + {{RenderLabel $.Context .}} {{end}}
    {{range .Assignees}} diff --git a/templates/repo/settings/lfs_file_find.tmpl b/templates/repo/settings/lfs_file_find.tmpl index d5983ca1cc8d..81cb6498374a 100644 --- a/templates/repo/settings/lfs_file_find.tmpl +++ b/templates/repo/settings/lfs_file_find.tmpl @@ -19,7 +19,7 @@
  • diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index a43047c79de9..6f3fd0f9167d 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -34,7 +34,7 @@
    - {{RenderEmoji .Title | RenderCodeBlock}} + {{RenderEmoji $.Context .Title | RenderCodeBlock}} {{if .IsPull}} {{if (index $.CommitStatuses .PullRequest.ID)}} {{template "repo/commit_statuses" dict "Status" (index $.CommitLastStatus .PullRequest.ID) "Statuses" (index $.CommitStatuses .PullRequest.ID) "root" $}} @@ -42,7 +42,7 @@ {{end}} {{range .Labels}} - {{RenderLabel .}} + {{RenderLabel $.Context .}} {{end}}
    diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 75a76db570e0..64daf4b2e7c4 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -72,7 +72,7 @@ {{$index := index .GetIssueInfos 0}} {{$.locale.Tr "action.comment_pull" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}} {{else if eq .GetOpType 24}} - {{$linkText := .Content | RenderEmoji}} + {{$linkText := .Content | RenderEmoji $.Context}} {{$.locale.Tr "action.publish_release" (.GetRepoLink|Escape) ((printf "%s/releases/tag/%s" .GetRepoLink .GetTag)|Escape) (.ShortRepoPath|Escape) $linkText | Str2html}} {{else if eq .GetOpType 25}} {{$index := index .GetIssueInfos 0}} @@ -99,20 +99,20 @@
    {{else if eq .GetOpType 6}} - {{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}} + {{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}} {{else if eq .GetOpType 7}} - {{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}} + {{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}} {{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22) (eq .GetOpType 23)}} - {{.GetIssueTitle | RenderEmoji | RenderCodeBlock}} + {{.GetIssueTitle | RenderEmoji $.Context | RenderCodeBlock}} {{$comment := index .GetIssueInfos 1}} - {{if gt (len $comment) 0}}

    {{$comment | RenderEmoji}}

    {{end}} + {{if gt (len $comment) 0}}

    {{$comment | RenderEmoji $.Context}}

    {{end}} {{else if eq .GetOpType 11}}

    {{index .GetIssueInfos 1}}

    {{else if or (eq .GetOpType 12) (eq .GetOpType 13) (eq .GetOpType 14) (eq .GetOpType 15)}} - {{.GetIssueTitle | RenderEmoji | RenderCodeBlock}} + {{.GetIssueTitle | RenderEmoji $.Context | RenderCodeBlock}} {{else if eq .GetOpType 25}}

    {{$.locale.Tr "action.review_dismissed_reason"}}

    -

    {{index .GetIssueInfos 2 | RenderEmoji}}

    +

    {{index .GetIssueInfos 2 | RenderEmoji $.Context}}

    {{end}}

    {{TimeSince .GetCreate $.locale}}

    diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/40/3d76c604cb569323864e06a07b85d466924802 b/tests/gitea-repositories-meta/user2/repo1.git/objects/40/3d76c604cb569323864e06a07b85d466924802 new file mode 100644 index 000000000000..ea0bf76d0cc8 Binary files /dev/null and b/tests/gitea-repositories-meta/user2/repo1.git/objects/40/3d76c604cb569323864e06a07b85d466924802 differ diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/78/fb907e3a3309eae4fe8fef030874cebbf1cd5e b/tests/gitea-repositories-meta/user2/repo1.git/objects/78/fb907e3a3309eae4fe8fef030874cebbf1cd5e new file mode 100644 index 000000000000..6a25f7409b41 Binary files /dev/null and b/tests/gitea-repositories-meta/user2/repo1.git/objects/78/fb907e3a3309eae4fe8fef030874cebbf1cd5e differ diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/f3/fa0f5cc797fc4c02a1b8bec9de4b2072fcdbdf b/tests/gitea-repositories-meta/user2/repo1.git/objects/f3/fa0f5cc797fc4c02a1b8bec9de4b2072fcdbdf new file mode 100644 index 000000000000..9b20f8af3f2d Binary files /dev/null and b/tests/gitea-repositories-meta/user2/repo1.git/objects/f3/fa0f5cc797fc4c02a1b8bec9de4b2072fcdbdf differ diff --git a/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/home-md-img-check b/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/home-md-img-check new file mode 100644 index 000000000000..a254e42921f4 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/home-md-img-check @@ -0,0 +1 @@ +78fb907e3a3309eae4fe8fef030874cebbf1cd5e diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index 3692b11ecabe..7c3eac20cfac 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -256,3 +256,23 @@ func TestViewRepoDirectory(t *testing.T) { assert.Zero(t, repoTopics.Length()) assert.Zero(t, repoSummary.Length()) } + +func TestMarkDownImage(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user2") + + req := NewRequest(t, "GET", "/user2/repo1/src/branch/home-md-img-check") + resp := session.MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + _, exists := htmlDoc.doc.Find(`img[src="/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg"]`).Attr("src") + assert.True(t, exists, "Repo home page markdown image link check failed") + + req = NewRequest(t, "GET", "/user2/repo1/src/branch/home-md-img-check/README.md") + resp = session.MakeRequest(t, req, http.StatusOK) + + htmlDoc = NewHTMLParser(t, resp.Body) + _, exists = htmlDoc.doc.Find(`img[src="/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg"]`).Attr("src") + assert.True(t, exists, "Repo src page markdown image link check failed") +} diff --git a/web_src/js/components/ContextPopup.vue b/web_src/js/components/ContextPopup.vue index 3244034782d6..ad305b23a910 100644 --- a/web_src/js/components/ContextPopup.vue +++ b/web_src/js/components/ContextPopup.vue @@ -87,7 +87,7 @@ export default { } }, mounted() { - this.$refs.root.addEventListener('us-load-context-popup', (e) => { + this.$refs.root.addEventListener('ce-load-context-popup', (e) => { const data = e.detail; if (!this.loading && this.issue === null) { this.load(data); diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index 762067f52388..a5c12c754ece 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -2,7 +2,13 @@
    - {{ run.title }} + + + + +
    + {{ run.title }} +
    @@ -99,6 +105,7 @@ const sfc = { run: { link: '', title: '', + status: '', canCancel: false, canApprove: false, done: false, @@ -327,7 +334,11 @@ export function initRepositoryActionView() { .action-info-summary { font-size: 150%; height: 20px; - padding: 0 10px; + display: flex; + + .action-title { + padding: 0 5px; + } } // ================ diff --git a/web_src/js/features/comp/LabelEdit.js b/web_src/js/features/comp/LabelEdit.js index 313d4068218b..18676d25e6cc 100644 --- a/web_src/js/features/comp/LabelEdit.js +++ b/web_src/js/features/comp/LabelEdit.js @@ -13,6 +13,7 @@ function updateExclusiveLabelEdit(form) { if (isExclusiveScopeName(nameInput.val())) { exclusiveField.removeClass('muted'); + exclusiveField.removeAttr('aria-disabled'); if (exclusiveCheckbox.prop('checked') && exclusiveCheckbox.data('exclusive-warn')) { exclusiveWarning.removeClass('gt-hidden'); } else { @@ -20,6 +21,7 @@ function updateExclusiveLabelEdit(form) { } } else { exclusiveField.addClass('muted'); + exclusiveField.attr('aria-disabled', 'true'); exclusiveWarning.addClass('gt-hidden'); } } diff --git a/web_src/js/features/contextpopup.js b/web_src/js/features/contextpopup.js index 61f71209083c..8e0ef92bd3ae 100644 --- a/web_src/js/features/contextpopup.js +++ b/web_src/js/features/contextpopup.js @@ -31,8 +31,9 @@ export function initContextPopups() { createTippy(this, { content: el, interactive: true, + interactiveBorder: 5, onShow: () => { - el.firstChild.dispatchEvent(new CustomEvent('us-load-context-popup', {detail: {owner, repo, index}})); + el.firstChild.dispatchEvent(new CustomEvent('ce-load-context-popup', {detail: {owner, repo, index}})); } }); }); diff --git a/web_src/js/features/install.js b/web_src/js/features/install.js index 2ba6fe1279e0..23122ca4c383 100644 --- a/web_src/js/features/install.js +++ b/web_src/js/features/install.js @@ -2,10 +2,18 @@ import $ from 'jquery'; import {hideElem, showElem} from '../utils/dom.js'; export function initInstall() { - if ($('.page-content.install').length === 0) { + const $page = $('.page-content.install'); + if ($page.length === 0) { return; } + if ($page.is('.post-install')) { + initPostInstall(); + } else { + initPreInstall(); + } +} +function initPreInstall() { const defaultDbUser = 'gitea'; const defaultDbName = 'gitea'; @@ -40,6 +48,18 @@ export function initInstall() { } // else: for SQLite3, the default path is always prepared by backend code (setting) }).trigger('change'); + const $appUrl = $('#app_url'); + const configAppUrl = $appUrl.val(); + if (configAppUrl.includes('://localhost')) { + $appUrl.val(window.location.href); + } + + const $domain = $('#domain'); + const configDomain = $domain.val().trim(); + if (configDomain === 'localhost') { + $domain.val(window.location.hostname); + } + // TODO: better handling of exclusive relations. $('#offline-mode input').on('change', function () { if ($(this).is(':checked')) { @@ -83,3 +103,20 @@ export function initInstall() { } }); } + +function initPostInstall() { + const el = document.getElementById('goto-user-login'); + if (!el) return; + + const targetUrl = el.getAttribute('href'); + let tid = setInterval(async () => { + try { + const resp = await fetch(targetUrl); + if (tid && resp.status === 200) { + clearInterval(tid); + tid = null; + window.location.href = targetUrl; + } + } catch {} + }, 1000); +} diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index d2559b123707..56ebe4fc991e 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -11,10 +11,8 @@ export function initRepoDiffReviewButton() { const $reviewBox = $('#review-box'); const $counter = $reviewBox.find('.review-comments-counter'); - $(document).on('click', 'button[name="is_review"]', (e) => { + $(document).on('click', 'button[name="pending_review"]', (e) => { const $form = $(e.target).closest('form'); - $form.append(''); - // Watch for the form's submit event. $form.on('submit', () => { const num = parseInt($counter.attr('data-pending-comment-number')) + 1 || 1; @@ -50,7 +48,15 @@ export function initRepoDiffConversationForm() { return; } - const formDataString = String(new URLSearchParams(new FormData($form[0]))); + const formData = new FormData($form[0]); + + // if the form is submitted by a button, append the button's name and value to the form data + const submitter = e.originalEvent?.submitter; + const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit'); + if (isSubmittedByButton && submitter.name) { + formData.append(submitter.name, submitter.value); + } + const formDataString = String(new URLSearchParams(formData)); const $newConversationHolder = $(await $.post($form.attr('action'), formDataString)); const {path, side, idx} = $newConversationHolder.data(); diff --git a/web_src/js/features/repo-editor.js b/web_src/js/features/repo-editor.js index a9d143847db2..b3e9b65f2167 100644 --- a/web_src/js/features/repo-editor.js +++ b/web_src/js/features/repo-editor.js @@ -91,24 +91,27 @@ export function initRepoEditor() { $('#commit-button').text($(this).attr('button_text')); }); + const joinTreePath = ($fileNameEl) => { + const parts = []; + $('.breadcrumb span.section').each(function () { + const element = $(this); + if (element.find('a').length) { + parts.push(element.find('a').text()); + } else { + parts.push(element.text()); + } + }); + if ($fileNameEl.val()) parts.push($fileNameEl.val()); + $('#tree_path').val(parts.join('/')); + }; + const $editFilename = $('#file-name'); - $editFilename.on('keyup', function (e) { - const $section = $('.breadcrumb span.section'); - const $divider = $('.breadcrumb div.divider'); - let value; - let parts; + $editFilename.on('input', function () { + const parts = $(this).val().split('/'); - if (e.keyCode === 8 && getCursorPosition($(this)) === 0 && $section.length > 0) { - value = $section.last().find('a').text(); - $(this).val(value + $(this).val()); - $(this)[0].setSelectionRange(value.length, value.length); - $section.last().remove(); - $divider.last().remove(); - } - if (e.keyCode === 191) { - parts = $(this).val().split('/'); + if (parts.length > 1) { for (let i = 0; i < parts.length; ++i) { - value = parts[i]; + const value = parts[i]; if (i < parts.length - 1) { if (value.length) { $(`${htmlEscape(value)}`).insertBefore($(this)); @@ -117,21 +120,28 @@ export function initRepoEditor() { } else { $(this).val(value); } - $(this)[0].setSelectionRange(0, 0); + this.setSelectionRange(0, 0); } } - parts = []; - $('.breadcrumb span.section').each(function () { - const element = $(this); - if (element.find('a').length) { - parts.push(element.find('a').text()); - } else { - parts.push(element.text()); - } - }); - if ($(this).val()) parts.push($(this).val()); - $('#tree_path').val(parts.join('/')); - }).trigger('keyup'); + + joinTreePath($(this)); + }); + + $editFilename.on('keydown', function (e) { + const $section = $('.breadcrumb span.section'); + + // Jump back to last directory once the filename is empty + if (e.code === 'Backspace' && getCursorPosition($(this)) === 0 && $section.length > 0) { + e.preventDefault(); + const $divider = $('.breadcrumb div.divider'); + const value = $section.last().find('a').text(); + $(this).val(value + $(this).val()); + this.setSelectionRange(value.length, value.length); + $section.last().remove(); + $divider.last().remove(); + joinTreePath($(this)); + } + }); const $editArea = $('.repository.editor textarea#edit_area'); if (!$editArea.length) return; diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 4163fb120e52..41c9dd118f2f 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -535,7 +535,7 @@ export function initRepoPullRequestReview() { const td = ntr.find(`.add-comment-${side}`); let commentCloud = td.find('.comment-code-cloud'); - if (commentCloud.length === 0 && !ntr.find('button[name="is_review"]').length) { + if (commentCloud.length === 0 && !ntr.find('button[name="pending_review"]').length) { const data = await $.get($(this).closest('[data-new-comment-url]').data('new-comment-url')); td.html(data); commentCloud = td.find('.comment-code-cloud'); diff --git a/web_src/js/markup/mermaid.js b/web_src/js/markup/mermaid.js index 60f53d2b341d..b519e2dcdc35 100644 --- a/web_src/js/markup/mermaid.js +++ b/web_src/js/markup/mermaid.js @@ -37,14 +37,10 @@ export async function renderMermaid() { continue; } - let valid; try { - valid = mermaid.parse(source); + await mermaid.parse(source); } catch (err) { displayError(el, err); - } - - if (!valid) { el.closest('pre').classList.remove('is-loading'); continue; } @@ -52,22 +48,25 @@ export async function renderMermaid() { try { // can't use bindFunctions here because we can't cross the iframe boundary. This // means js-based interactions won't work but they aren't intended to work either - mermaid.mermaidAPI.render('mermaid', source, (svgStr) => { - const heightStr = (svgStr.match(/viewBox="(.+?)"/) || ['', ''])[1].split(/\s+/)[3]; - if (!heightStr) return displayError(el, new Error('Could not determine chart height')); - const iframe = document.createElement('iframe'); - iframe.classList.add('markup-render'); - iframe.sandbox = 'allow-scripts'; - iframe.style.height = `${Math.ceil(parseFloat(heightStr))}px`; - iframe.srcdoc = ` ${svgStr}`; - const mermaidBlock = document.createElement('div'); - mermaidBlock.classList.add('mermaid-block'); - mermaidBlock.append(iframe); - const btn = makeCodeCopyButton(); - btn.setAttribute('data-clipboard-text', source); - mermaidBlock.append(btn); - el.closest('pre').replaceWith(mermaidBlock); - }); + const {svg} = await mermaid.render('mermaid', source); + const heightStr = (svg.match(/viewBox="(.+?)"/) || ['', ''])[1].split(/\s+/)[3]; + if (!heightStr) return displayError(el, new Error('Could not determine chart height')); + + const iframe = document.createElement('iframe'); + iframe.classList.add('markup-render'); + iframe.sandbox = 'allow-scripts'; + iframe.style.height = `${Math.ceil(parseFloat(heightStr))}px`; + iframe.srcdoc = ` ${svg}`; + + const mermaidBlock = document.createElement('div'); + mermaidBlock.classList.add('mermaid-block'); + mermaidBlock.append(iframe); + + const btn = makeCodeCopyButton(); + btn.setAttribute('data-clipboard-text', source); + + mermaidBlock.append(btn); + el.closest('pre').replaceWith(mermaidBlock); } catch (err) { displayError(el, err); } diff --git a/web_src/js/webcomponents/README.md b/web_src/js/webcomponents/README.md new file mode 100644 index 000000000000..eabbc24ad1da --- /dev/null +++ b/web_src/js/webcomponents/README.md @@ -0,0 +1,19 @@ +# Web Components + +This `webcomponents` directory contains the source code for the web components used in the Gitea Web UI. + +https://developer.mozilla.org/en-US/docs/Web/Web_Components + +# Guidelines + +* These components are loaded in `` (before DOM body), + so they should have their own dependencies and should be very light, + then they won't affect the page loading time too much. +* If the component is not a public one, it's suggested to have its own `Gitea` or `gitea-` prefix to avoid conflicts. + +# TODO + +There are still some components that are not migrated to web components yet: + +* `` +* `
    - {{.Summary | RenderEmoji}} + {{.Summary | RenderEmoji $.Context}}