diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index a7276e8..60b6485 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -5,22 +5,56 @@ on: branches: [main, master] pull_request: branches: [main, master] + types: [opened, reopened, synchronize, closed] + delete: release: types: [published] workflow_dispatch: name: pkgdown +permissions: + contents: write + pull-requests: write # comment the preview URL + +env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + jobs: + # PR preview domain (--pr-.surge.sh), shared by the jobs below. + preview: + runs-on: ubuntu-latest + outputs: + domain: ${{ steps.domain.outputs.domain }} + steps: + - id: domain + env: + GH_TOKEN: ${{ github.token }} + REF: ${{ github.event.ref }} + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + num="${{ github.event.pull_request.number }}" + elif [ "${{ github.event_name }}" = "delete" ]; then + num=$(gh pr list --repo "${{ github.repository }}" --state all \ + --head "$REF" --json number --jq '.[0].number // empty') + fi + if [ -n "$num" ]; then + name=$(echo "${{ github.repository }}-pr-$num" | + tr 'A-Z' 'a-z' | tr -c 'a-z0-9\n' '-') + echo "domain=$name.surge.sh" >> "$GITHUB_OUTPUT" + fi + pkgdown: + needs: preview + # Skip closed PRs and branch deletions (see teardown). + if: github.event_name != 'delete' && github.event.action != 'closed' runs-on: ubuntu-latest # Only restrict concurrency for non-PR jobs concurrency: group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - permissions: - contents: write + PREVIEW_DOMAIN: ${{ needs.preview.outputs.domain }} steps: - uses: actions/checkout@v4 @@ -39,6 +73,27 @@ jobs: run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) shell: Rscript {0} + # Fork PRs cannot read the secret or comment, so skip them. + - name: Deploy PR preview to surge + if: >- + github.event_name == 'pull_request' && env.SURGE_TOKEN != '' && + github.event.pull_request.head.repo.full_name == github.repository + run: | + npm install -g surge + surge ./docs "$PREVIEW_DOMAIN" + + - name: Comment preview URL + if: >- + github.event_name == 'pull_request' && env.SURGE_TOKEN != '' && + github.event.pull_request.head.repo.full_name == github.repository + uses: marocchino/sticky-pull-request-comment@v3 + with: + header: surge-preview + message: | + Site preview: https://${{ env.PREVIEW_DOMAIN }} + + Updates on every push; removed when this PR closes. + - name: Deploy to GitHub pages 🚀 if: github.event_name != 'pull_request' uses: JamesIves/github-pages-deploy-action@v4.5.0 @@ -46,3 +101,20 @@ jobs: clean: false branch: gh-pages folder: docs + + # Remove a PR preview. Branch deletion is the main trigger (deleting at merge + # cancels `closed` runs); `closed` covers kept branches. Idempotent. + teardown: + needs: preview + if: >- + github.event.action == 'closed' || + (github.event_name == 'delete' && github.event.ref_type == 'branch') + runs-on: ubuntu-latest + env: + PREVIEW_DOMAIN: ${{ needs.preview.outputs.domain }} + steps: + - name: Teardown preview + if: env.SURGE_TOKEN != '' && env.PREVIEW_DOMAIN != '' + run: | + npm install -g surge + surge teardown "$PREVIEW_DOMAIN" || true diff --git a/R/ae_forestly.R b/R/ae_forestly.R index a9baddf..4ad4021 100644 --- a/R/ae_forestly.R +++ b/R/ae_forestly.R @@ -38,9 +38,9 @@ #' @param max_page A numeric value of max page number shown in the table. #' @param download_button A logical value to display download button. #' @param width Table container width, a number (interpreted as pixels) or any -#' CSS width value. If `NULL` (default), the table takes its natural width; a -#' value fixes the container width. Either way the width is capped at the -#' viewport, and a wider table scrolls inside rather than widening the page. +#' CSS width value. If `NULL` (default), the container fills its parent; a +#' value fixes the container width. A wider table scrolls inside rather than +#' widening the page, and the container can be resized by dragging its corner. #' #' @section Searching and filtering: #' The interactive table has a search box for each column (and, in the @@ -459,9 +459,8 @@ ae_forestly <- function(outdata, # forestly-ae on lt's container scopes cell styles and sizes the table (see # inst/css/forestly-widgets.css); per-column widths from format_lt_forestly() kept. built$x <- lt::lt_wrap(built$x, class = "forestly-ae") - # A user-specified width fixes the container (still capped at the viewport by - # the `.forestly-ae` CSS, so a wide table scrolls inside rather than widening - # the page). A number is pixels. + # A user-specified width fixes the container; a wider table scrolls inside + # rather than widening the page. A number is pixels. if (!is.null(width)) { width <- if (is.numeric(width)) paste0(width, "px") else width built$x <- lt::lt_wrap(built$x, style = paste0("width:", width)) diff --git a/inst/css/forestly-widgets.css b/inst/css/forestly-widgets.css index 1234ee2..b24b24d 100644 --- a/inst/css/forestly-widgets.css +++ b/inst/css/forestly-widgets.css @@ -1,12 +1,7 @@ .forestly-ae { - /* Natural table width, centered (margin-left:50% + translateX back half its - width), capped below the viewport so a wider table breaks out of a narrow - parent yet still scrolls inside `.lt-wrap` rather than adding a page - scrollbar. 40px slack ~ scrollbar + gutter; CSS can't read the real width. */ - width: max-content; - max-width: calc(100vw - 40px); - margin-left: 50%; - transform: translateX(-50%); + /* Parent's width by default (a wider table scrolls inside `.lt-wrap`); the + user can drag the corner to resize. */ + resize: horizontal; /* One line per body-data cell, clipped with an ellipsis, full text on hover; skip figure (svg) cells. Header (thead), footer (tfoot) and drill-down diff --git a/man/ae_forestly.Rd b/man/ae_forestly.Rd index 9e61657..dbf29a2 100644 --- a/man/ae_forestly.Rd +++ b/man/ae_forestly.Rd @@ -47,9 +47,9 @@ If only one value is provided, it will be used as the maximum and minimum will b \item{download_button}{A logical value to display download button.} \item{width}{Table container width, a number (interpreted as pixels) or any -CSS width value. If \code{NULL} (default), the table takes its natural width; a -value fixes the container width. Either way the width is capped at the -viewport, and a wider table scrolls inside rather than widening the page.} +CSS width value. If \code{NULL} (default), the container fills its parent; a +value fixes the container width. A wider table scrolls inside rather than +widening the page, and the container can be resized by dragging its corner.} } \value{ An AE forest plot saved as a \code{shiny.tag.list} object. diff --git a/pkgdown/extra.css b/pkgdown/extra.css index c80dbc1..3a16467 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -44,4 +44,9 @@ footer { position: relative; top: 0; } -} \ No newline at end of file +} +/* Bootstrap sets `display: block` on tables; restore it for the forest table + so it sizes as a normal table inside `.lt-wrap`. */ +.forestly-ae table { + display: table; +}